commit 4f7956bbd714c05077299eef813b346a98a62194
parent b7cf2b0c3ce416219e63d307c1365a44fa326039
Author: Brian Swetland <swetland@frotz.net>
Date: Sat, 9 Feb 2013 04:53:10 -0800
multiplatform: make win32 happy again
Diffstat:
4 files changed, 82 insertions(+), 20 deletions(-)
diff --git a/common/dxapp.cc b/common/dxapp.cc
@@ -549,6 +549,56 @@ int App::createTextureRGBA(Texture2D *tex, void *data, unsigned tw, unsigned th,
return 0;
}
+int App::initConfig(InputConfiguration *ic, VertexShader *vs, PixelShader *ps) {
+ ic->vs = vs;
+ ic->ps = ps;
+ return 0;
+};
+void App::useConfig(InputConfiguration *_ic) {
+ int i;
+ ic = _ic;
+ ID3D10Buffer *buf[16];
+ ID3D10ShaderResourceView *srv[16];
+
+ device->PSSetShader(ic->ps->ps);
+ device->VSSetShader(ic->vs->vs);
+ device->IASetInputLayout(ic->vs->layout);
+ for (i = 0; i < ic->vcount; i++)
+ buf[i] = ic->vbuf[i]->buf;
+ device->IASetVertexBuffers(0, ic->vcount, buf, ic->vstride, ic->voffset);
+ for (i = 0; i < ic->ucount; i++)
+ buf[i] = ic->ubuf[i]->buf;
+ device->VSSetConstantBuffers(0, ic->ucount, buf);
+ if (ic->tcount) {
+ for (i = 0; i < ic->tcount; i++)
+ srv[i] = ic->tex[i]->srv;
+ device->PSSetShaderResources(0, ic->tcount, srv);
+ }
+ if (ic->ibuf)
+ device->IASetIndexBuffer(ic->ibuf->buf, DXGI_FORMAT_R16_UINT, 0);
+}
+
+void App::useBuffer(VertexBuffer *vb, int slot, UINT stride, UINT offset) {
+ ic->vbuf[slot] = vb;
+ ic->vstride[slot] = stride;
+ ic->voffset[slot] = offset;
+ if (slot >= ic->vcount)
+ ic->vcount = slot + 1;
+}
+void App::useBuffer(IndexBuffer *ib) {
+ ic->ibuf = ib;
+}
+void App::useBuffer(UniformBuffer *ub, int slot) {
+ ic->ubuf[slot] = ub;
+ if (slot >= ic->ucount)
+ ic->ucount = slot + 1;
+}
+void App::useTexture(Texture2D *tex, int slot) {
+ ic->tex[slot] = tex;
+ if (slot >= ic->tcount)
+ ic->tcount = slot + 1;
+}
+
int _create_buffer(ID3D10Device *device, D3D10_BIND_FLAG flag,
void *data, int sz, ID3D10Buffer **buf) {
HRESULT hr;
diff --git a/common/dxapp.h b/common/dxapp.h
@@ -106,6 +106,27 @@ struct IndexBuffer {
~IndexBuffer() { if (buf) buf->Release(); };
};
+struct InputConfiguration {
+ VertexShader *vs;
+ PixelShader *ps;
+
+ IndexBuffer *ibuf;
+ VertexBuffer *vbuf[16];
+ unsigned vstride[16];
+ unsigned voffset[16];
+ UniformBuffer *ubuf[16];
+ Texture2D *tex[16];
+
+ int vcount;
+ int ucount;
+ int tcount;
+
+ InputConfiguration() : vs(NULL), ps(NULL), vcount(0), ucount(0), tcount(0), ibuf(NULL) {
+ memset(vbuf, 0, sizeof(vbuf));
+ memset(ubuf, 0, sizeof(ubuf));
+ }
+};
+
class App {
public:
App();
@@ -136,6 +157,7 @@ public:
int loadTextureRGBA(Texture2D *tex, const char *fn, int genmips);
int createTextureRGBA(Texture2D *tex, void *data, unsigned w, unsigned h, int genmips);
+ int initConfig(InputConfiguration *ic, VertexShader *vs, PixelShader *ps);
int initBuffer(VertexBuffer *vb, void *data, int sz);
int initBuffer(IndexBuffer *ib, void *data, int sz);
int initBuffer(UniformBuffer *ub, void *data, int sz);
@@ -150,23 +172,11 @@ public:
device->UpdateSubresource(ub->buf, 0, NULL, data, 0, 0);
}
- void useShaders(PixelShader *ps, VertexShader *vs) {
- device->PSSetShader(ps->ps);
- device->VSSetShader(vs->vs);
- device->IASetInputLayout(vs->layout);
- }
- void useBuffer(VertexBuffer *vb, int slot, UINT stride, UINT offset) {
- device->IASetVertexBuffers(slot, 1, &vb->buf, &stride, &offset);
- }
- void useBuffer(IndexBuffer *ib) {
- device->IASetIndexBuffer(ib->buf, DXGI_FORMAT_R16_UINT, 0);
- }
- void useBuffer(UniformBuffer *ub, int slot) {
- device->VSSetConstantBuffers(slot, 1, &ub->buf);
- }
- void useTexture(Texture2D *tex, int slot) {
- device->PSSetShaderResources(slot, 1, &tex->srv);
- }
+ void useConfig(InputConfiguration *ic);
+ void useBuffer(VertexBuffer *vb, int slot, UINT stride, UINT offset);
+ void useBuffer(IndexBuffer *ib);
+ void useBuffer(UniformBuffer *ub, int slot);
+ void useTexture(Texture2D *tex, int slot);
void drawIndexedInstanced(unsigned numindices, unsigned numinstances) {
device->DrawIndexedInstanced(numindices, numinstances, 0, 0, 0);
}
@@ -196,6 +206,7 @@ protected:
ID3D10DepthStencilState *dsDepthDisabled;
private:
+ InputConfiguration *ic;
LPDIRECTINPUT8 dinput;
LPDIRECTINPUTDEVICE8 dkeyboard;
LPDIRECTINPUTDEVICE8 dmouse;
diff --git a/hello/hello.cc b/hello/hello.cc
@@ -177,9 +177,8 @@ void TestApp::render(void) {
if (keystate[DIK_D]) { nx += 0.01; update = 1; }
if (keystate[DIK_W]) { ny -= 0.01; update = 1; }
if (keystate[DIK_S]) { ny += 0.01; update = 1; }
-
if (keystate[DIK_P]) {
- loadShader(&ps, "HelloPS."SL);
+ loadShader(&ps, "SimplePS."SL);
loadShader(&vs, "SimpleVS."SL, obj_layout,
sizeof(obj_layout) / sizeof(obj_layout[0]));
}
diff --git a/hello/hello.vcxproj b/hello/hello.vcxproj
@@ -93,6 +93,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\common\app.h" />
+ <ClInclude Include="..\common\dxapp.h" />
<ClInclude Include="..\common\matrix.h" />
<ClInclude Include="..\common\util.h" />
<ClInclude Include="..\common\textgrid.h" />
@@ -128,4 +129,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
-</Project>
+</Project>
+\ No newline at end of file