# HG changeset patch # User John Tsiombikas # Date 1371950593 -10800 # Node ID 6ed01ded71d8381afa552dbf6cae980bee011bfc initial commit diff -r 000000000000 -r 6ed01ded71d8 .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Sun Jun 23 04:23:13 2013 +0300 @@ -0,0 +1,8 @@ +\.swp$ +\.o$ +\.d$ +\.sdf$ +\.suo$ +\.user$ +Debug/ +Release/ diff -r 000000000000 -r 6ed01ded71d8 dxtest2.sln --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dxtest2.sln Sun Jun 23 04:23:13 2013 +0300 @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dxtest2", "dxtest2.vcxproj", "{E1E84AA6-720A-4151-A96E-15D91EDE535C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E1E84AA6-720A-4151-A96E-15D91EDE535C}.Debug|Win32.ActiveCfg = Debug|Win32 + {E1E84AA6-720A-4151-A96E-15D91EDE535C}.Debug|Win32.Build.0 = Debug|Win32 + {E1E84AA6-720A-4151-A96E-15D91EDE535C}.Release|Win32.ActiveCfg = Release|Win32 + {E1E84AA6-720A-4151-A96E-15D91EDE535C}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff -r 000000000000 -r 6ed01ded71d8 dxtest2.vcxproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dxtest2.vcxproj Sun Jun 23 04:23:13 2013 +0300 @@ -0,0 +1,93 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {E1E84AA6-720A-4151-A96E-15D91EDE535C} + Win32Proj + dxtest2 + + + + Application + true + v110 + MultiByte + + + Application + false + v110 + true + MultiByte + + + + + + + + + + + + + true + C:\Users\nuclear\code\dxtest2\$(Configuration);$(LibraryPath) + C:\Users\nuclear\code\d3dut\include;$(IncludePath) + + + false + C:\Users\nuclear\code\dxtest2\$(Configuration);$(LibraryPath) + C:\Users\nuclear\code\d3dut\include;$(IncludePath) + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + true + true + + + + + + + + + + + + + + \ No newline at end of file diff -r 000000000000 -r 6ed01ded71d8 dxtest2.vcxproj.filters --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dxtest2.vcxproj.filters Sun Jun 23 04:23:13 2013 +0300 @@ -0,0 +1,33 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + \ No newline at end of file diff -r 000000000000 -r 6ed01ded71d8 src/main.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main.cc Sun Jun 23 04:23:13 2013 +0300 @@ -0,0 +1,13 @@ +#include +#include +#include "mesh.h" + +int main(int argc, char **argv) +{ + d3dut_init(&argc, argv); + d3dut_init_window_size(800, 600); + d3dut_init_display_mode(D3DUT_RGB | D3DUT_DEPTH | D3DUT_DOUBLE); + d3dut_create_window("Direct3D 11 - test 2"); + + +} \ No newline at end of file diff -r 000000000000 -r 6ed01ded71d8 src/mesh.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/mesh.cc Sun Jun 23 04:23:13 2013 +0300 @@ -0,0 +1,110 @@ +#include +#include "mesh.h" + + +/*static ID3D11InputLayout *vertex_layout; + +static ID3D11InputLayout *create_vertex_layout() +{ + static const D3D11_INPUT_ELEMENT_DESC elem_desc[] = { + {"position", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, offsetof(Vertex, pos), D3D11_INPUT_PER_VERTEX_DATA, 0}, + {"normal", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, offsetof(Vertex, normal), D3D11_INPUT_PER_VERTEX_DATA, 0}, + {"texcoord", 0, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(Vertex, texcoord), D3D11_INPUT_PER_VERTEX_DATA, 0} + }; + static const int num_elem = sizeof elem_desc / sizeof *elem_desc; + + if(d3dut_dev->CreateInputLayout(elem_desc, num_elem, +}*/ + + +Mesh::Mesh() +{ + vbuf = 0; + cur_norm = Vector3(0, 1, 0); +} + +Mesh::~Mesh() +{ + if(vbuf) { + vbuf->Release(); + } +} + +void Mesh::clear() +{ + invalidate_vbuffer(); + verts.clear(); +} + +void Mesh::normal(float x, float y, float z) +{ + cur_norm.x = x; + cur_norm.y = y; + cur_norm.z = z; +} + +void Mesh::texcoord(float u, float v) +{ + cur_texcoord.x = u; + cur_texcoord.y = v; +} + +void Mesh::vertex(float x, float y, float z) +{ + Vertex v; + v.pos = Vector3(x, y, z); + v.normal = cur_norm; + v.texcoord = cur_texcoord; + verts.push_back(v); + + invalidate_vbuffer(); +} + + +void Mesh::draw() const +{ + ((Mesh*)this)->update_vbuffer(); + + unsigned int stride = sizeof(Vertex); + unsigned int offset = 0; + d3dut_ctx->IASetVertexBuffers(0, 1, &vbuf, &stride, &offset); + d3dut_ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + + d3dut_ctx->Draw(verts.size(), 0); +} + + +bool Mesh::update_vbuffer() +{ + if(vbuf) { + return true; + } + + if(verts.empty()) { + return false; + } + + D3D11_BUFFER_DESC bufdesc; + memset(&bufdesc, 0, sizeof bufdesc); + bufdesc.Usage = D3D11_USAGE_DEFAULT; + bufdesc.ByteWidth = verts.size() * sizeof(Vertex); + bufdesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; + + D3D11_SUBRESOURCE_DATA subres; + memset(&subres, 0, sizeof subres); + subres.pSysMem = &verts[0]; + + if(d3dut_dev->CreateBuffer(&bufdesc, &subres, &vbuf) != 0) { + fprintf(stderr, "failed to create vertex buffer\n"); + return false; + } + return true; +} + +void Mesh::invalidate_vbuffer() +{ + if(vbuf) { + vbuf->Release(); + vbuf = 0; + } +} \ No newline at end of file diff -r 000000000000 -r 6ed01ded71d8 src/mesh.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/mesh.h Sun Jun 23 04:23:13 2013 +0300 @@ -0,0 +1,37 @@ +#ifndef MESH_H_ +#define MESH_H_ + +#include +#include +#include + +struct Vertex { + Vector3 pos, normal; + Vector2 texcoord; +}; + +class Mesh { +private: + Vector3 cur_norm; + Vector2 cur_texcoord; + + std::vector verts; + ID3D11Buffer *vbuf; + + bool update_vbuffer(); + void invalidate_vbuffer(); + +public: + Mesh(); + ~Mesh(); + + void clear(); + + void normal(float x, float y, float z); + void texcoord(float u, float v); + void vertex(float x, float y, float z); + + void draw() const; +}; + +#endif // MESH_H_ \ No newline at end of file diff -r 000000000000 -r 6ed01ded71d8 src/shader.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/shader.h Sun Jun 23 04:23:13 2013 +0300 @@ -0,0 +1,24 @@ +#ifndef SHADER_H_ +#define SHADER_H_ + +#include + +class Shader; + +class ShaderInput { +}; + +class Shader { +private: + ID3DBlob *bin; + +public: + Shader(); + virtual ~Shader(); + + virtual bool load(const char *fname); + + ID3DBlob *get_binary() const; +}; + +#endif // SHADER_H_ \ No newline at end of file