dxtest2

changeset 0:6ed01ded71d8 tip

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 23 Jun 2013 04:23:13 +0300
parents
children
files .hgignore dxtest2.sln dxtest2.vcxproj dxtest2.vcxproj.filters src/main.cc src/mesh.cc src/mesh.h src/shader.h
diffstat 8 files changed, 338 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/.hgignore	Sun Jun 23 04:23:13 2013 +0300
     1.3 @@ -0,0 +1,8 @@
     1.4 +\.swp$
     1.5 +\.o$
     1.6 +\.d$
     1.7 +\.sdf$
     1.8 +\.suo$
     1.9 +\.user$
    1.10 +Debug/
    1.11 +Release/
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/dxtest2.sln	Sun Jun 23 04:23:13 2013 +0300
     2.3 @@ -0,0 +1,20 @@
     2.4 +
     2.5 +Microsoft Visual Studio Solution File, Format Version 12.00
     2.6 +# Visual Studio 2012
     2.7 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dxtest2", "dxtest2.vcxproj", "{E1E84AA6-720A-4151-A96E-15D91EDE535C}"
     2.8 +EndProject
     2.9 +Global
    2.10 +	GlobalSection(SolutionConfigurationPlatforms) = preSolution
    2.11 +		Debug|Win32 = Debug|Win32
    2.12 +		Release|Win32 = Release|Win32
    2.13 +	EndGlobalSection
    2.14 +	GlobalSection(ProjectConfigurationPlatforms) = postSolution
    2.15 +		{E1E84AA6-720A-4151-A96E-15D91EDE535C}.Debug|Win32.ActiveCfg = Debug|Win32
    2.16 +		{E1E84AA6-720A-4151-A96E-15D91EDE535C}.Debug|Win32.Build.0 = Debug|Win32
    2.17 +		{E1E84AA6-720A-4151-A96E-15D91EDE535C}.Release|Win32.ActiveCfg = Release|Win32
    2.18 +		{E1E84AA6-720A-4151-A96E-15D91EDE535C}.Release|Win32.Build.0 = Release|Win32
    2.19 +	EndGlobalSection
    2.20 +	GlobalSection(SolutionProperties) = preSolution
    2.21 +		HideSolutionNode = FALSE
    2.22 +	EndGlobalSection
    2.23 +EndGlobal
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/dxtest2.vcxproj	Sun Jun 23 04:23:13 2013 +0300
     3.3 @@ -0,0 +1,93 @@
     3.4 +<?xml version="1.0" encoding="utf-8"?>
     3.5 +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     3.6 +  <ItemGroup Label="ProjectConfigurations">
     3.7 +    <ProjectConfiguration Include="Debug|Win32">
     3.8 +      <Configuration>Debug</Configuration>
     3.9 +      <Platform>Win32</Platform>
    3.10 +    </ProjectConfiguration>
    3.11 +    <ProjectConfiguration Include="Release|Win32">
    3.12 +      <Configuration>Release</Configuration>
    3.13 +      <Platform>Win32</Platform>
    3.14 +    </ProjectConfiguration>
    3.15 +  </ItemGroup>
    3.16 +  <PropertyGroup Label="Globals">
    3.17 +    <ProjectGuid>{E1E84AA6-720A-4151-A96E-15D91EDE535C}</ProjectGuid>
    3.18 +    <Keyword>Win32Proj</Keyword>
    3.19 +    <RootNamespace>dxtest2</RootNamespace>
    3.20 +  </PropertyGroup>
    3.21 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
    3.22 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    3.23 +    <ConfigurationType>Application</ConfigurationType>
    3.24 +    <UseDebugLibraries>true</UseDebugLibraries>
    3.25 +    <PlatformToolset>v110</PlatformToolset>
    3.26 +    <CharacterSet>MultiByte</CharacterSet>
    3.27 +  </PropertyGroup>
    3.28 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    3.29 +    <ConfigurationType>Application</ConfigurationType>
    3.30 +    <UseDebugLibraries>false</UseDebugLibraries>
    3.31 +    <PlatformToolset>v110</PlatformToolset>
    3.32 +    <WholeProgramOptimization>true</WholeProgramOptimization>
    3.33 +    <CharacterSet>MultiByte</CharacterSet>
    3.34 +  </PropertyGroup>
    3.35 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
    3.36 +  <ImportGroup Label="ExtensionSettings">
    3.37 +  </ImportGroup>
    3.38 +  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    3.39 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    3.40 +  </ImportGroup>
    3.41 +  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    3.42 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    3.43 +  </ImportGroup>
    3.44 +  <PropertyGroup Label="UserMacros" />
    3.45 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    3.46 +    <LinkIncremental>true</LinkIncremental>
    3.47 +    <LibraryPath>C:\Users\nuclear\code\dxtest2\$(Configuration);$(LibraryPath)</LibraryPath>
    3.48 +    <IncludePath>C:\Users\nuclear\code\d3dut\include;$(IncludePath)</IncludePath>
    3.49 +  </PropertyGroup>
    3.50 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    3.51 +    <LinkIncremental>false</LinkIncremental>
    3.52 +    <LibraryPath>C:\Users\nuclear\code\dxtest2\$(Configuration);$(LibraryPath)</LibraryPath>
    3.53 +    <IncludePath>C:\Users\nuclear\code\d3dut\include;$(IncludePath)</IncludePath>
    3.54 +  </PropertyGroup>
    3.55 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    3.56 +    <ClCompile>
    3.57 +      <PrecompiledHeader>
    3.58 +      </PrecompiledHeader>
    3.59 +      <WarningLevel>Level3</WarningLevel>
    3.60 +      <Optimization>Disabled</Optimization>
    3.61 +      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    3.62 +    </ClCompile>
    3.63 +    <Link>
    3.64 +      <SubSystem>Console</SubSystem>
    3.65 +      <GenerateDebugInformation>true</GenerateDebugInformation>
    3.66 +    </Link>
    3.67 +  </ItemDefinitionGroup>
    3.68 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    3.69 +    <ClCompile>
    3.70 +      <WarningLevel>Level3</WarningLevel>
    3.71 +      <PrecompiledHeader>
    3.72 +      </PrecompiledHeader>
    3.73 +      <Optimization>MaxSpeed</Optimization>
    3.74 +      <FunctionLevelLinking>true</FunctionLevelLinking>
    3.75 +      <IntrinsicFunctions>true</IntrinsicFunctions>
    3.76 +      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    3.77 +    </ClCompile>
    3.78 +    <Link>
    3.79 +      <SubSystem>Console</SubSystem>
    3.80 +      <GenerateDebugInformation>true</GenerateDebugInformation>
    3.81 +      <EnableCOMDATFolding>true</EnableCOMDATFolding>
    3.82 +      <OptimizeReferences>true</OptimizeReferences>
    3.83 +    </Link>
    3.84 +  </ItemDefinitionGroup>
    3.85 +  <ItemGroup>
    3.86 +    <ClCompile Include="src\main.cc" />
    3.87 +    <ClCompile Include="src\mesh.cc" />
    3.88 +  </ItemGroup>
    3.89 +  <ItemGroup>
    3.90 +    <ClInclude Include="src\mesh.h" />
    3.91 +    <ClInclude Include="src\shader.h" />
    3.92 +  </ItemGroup>
    3.93 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
    3.94 +  <ImportGroup Label="ExtensionTargets">
    3.95 +  </ImportGroup>
    3.96 +</Project>
    3.97 \ No newline at end of file
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/dxtest2.vcxproj.filters	Sun Jun 23 04:23:13 2013 +0300
     4.3 @@ -0,0 +1,33 @@
     4.4 +<?xml version="1.0" encoding="utf-8"?>
     4.5 +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     4.6 +  <ItemGroup>
     4.7 +    <Filter Include="Source Files">
     4.8 +      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
     4.9 +      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
    4.10 +    </Filter>
    4.11 +    <Filter Include="Header Files">
    4.12 +      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
    4.13 +      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
    4.14 +    </Filter>
    4.15 +    <Filter Include="Resource Files">
    4.16 +      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
    4.17 +      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
    4.18 +    </Filter>
    4.19 +  </ItemGroup>
    4.20 +  <ItemGroup>
    4.21 +    <ClCompile Include="src\main.cc">
    4.22 +      <Filter>Source Files</Filter>
    4.23 +    </ClCompile>
    4.24 +    <ClCompile Include="src\mesh.cc">
    4.25 +      <Filter>Source Files</Filter>
    4.26 +    </ClCompile>
    4.27 +  </ItemGroup>
    4.28 +  <ItemGroup>
    4.29 +    <ClInclude Include="src\mesh.h">
    4.30 +      <Filter>Header Files</Filter>
    4.31 +    </ClInclude>
    4.32 +    <ClInclude Include="src\shader.h">
    4.33 +      <Filter>Header Files</Filter>
    4.34 +    </ClInclude>
    4.35 +  </ItemGroup>
    4.36 +</Project>
    4.37 \ No newline at end of file
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/main.cc	Sun Jun 23 04:23:13 2013 +0300
     5.3 @@ -0,0 +1,13 @@
     5.4 +#include <stdio.h>
     5.5 +#include <d3dut.h>
     5.6 +#include "mesh.h"
     5.7 +
     5.8 +int main(int argc, char **argv)
     5.9 +{
    5.10 +	d3dut_init(&argc, argv);
    5.11 +	d3dut_init_window_size(800, 600);
    5.12 +	d3dut_init_display_mode(D3DUT_RGB | D3DUT_DEPTH | D3DUT_DOUBLE);
    5.13 +	d3dut_create_window("Direct3D 11 - test 2");
    5.14 +
    5.15 +
    5.16 +}
    5.17 \ No newline at end of file
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/mesh.cc	Sun Jun 23 04:23:13 2013 +0300
     6.3 @@ -0,0 +1,110 @@
     6.4 +#include <d3dut.h>
     6.5 +#include "mesh.h"
     6.6 +
     6.7 +
     6.8 +/*static ID3D11InputLayout *vertex_layout;
     6.9 +
    6.10 +static ID3D11InputLayout *create_vertex_layout()
    6.11 +{
    6.12 +	static const D3D11_INPUT_ELEMENT_DESC elem_desc[] = {
    6.13 +		{"position", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, offsetof(Vertex, pos), D3D11_INPUT_PER_VERTEX_DATA, 0},
    6.14 +		{"normal", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, offsetof(Vertex, normal), D3D11_INPUT_PER_VERTEX_DATA, 0},
    6.15 +		{"texcoord", 0, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(Vertex, texcoord), D3D11_INPUT_PER_VERTEX_DATA, 0}
    6.16 +	};
    6.17 +	static const int num_elem = sizeof elem_desc / sizeof *elem_desc;
    6.18 +
    6.19 +	if(d3dut_dev->CreateInputLayout(elem_desc, num_elem, 
    6.20 +}*/
    6.21 +
    6.22 +
    6.23 +Mesh::Mesh()
    6.24 +{
    6.25 +	vbuf = 0;
    6.26 +	cur_norm = Vector3(0, 1, 0);
    6.27 +}
    6.28 +
    6.29 +Mesh::~Mesh()
    6.30 +{
    6.31 +	if(vbuf) {
    6.32 +		vbuf->Release();
    6.33 +	}
    6.34 +}
    6.35 +
    6.36 +void Mesh::clear()
    6.37 +{
    6.38 +	invalidate_vbuffer();
    6.39 +	verts.clear();
    6.40 +}
    6.41 +
    6.42 +void Mesh::normal(float x, float y, float z)
    6.43 +{
    6.44 +	cur_norm.x = x;
    6.45 +	cur_norm.y = y;
    6.46 +	cur_norm.z = z;
    6.47 +}
    6.48 +
    6.49 +void Mesh::texcoord(float u, float v)
    6.50 +{
    6.51 +	cur_texcoord.x = u;
    6.52 +	cur_texcoord.y = v;
    6.53 +}
    6.54 +
    6.55 +void Mesh::vertex(float x, float y, float z)
    6.56 +{
    6.57 +	Vertex v;
    6.58 +	v.pos = Vector3(x, y, z);
    6.59 +	v.normal = cur_norm;
    6.60 +	v.texcoord = cur_texcoord;
    6.61 +	verts.push_back(v);
    6.62 +
    6.63 +	invalidate_vbuffer();
    6.64 +}
    6.65 +
    6.66 +
    6.67 +void Mesh::draw() const
    6.68 +{
    6.69 +	((Mesh*)this)->update_vbuffer();
    6.70 +
    6.71 +	unsigned int stride = sizeof(Vertex);
    6.72 +	unsigned int offset = 0;
    6.73 +	d3dut_ctx->IASetVertexBuffers(0, 1, &vbuf, &stride, &offset);
    6.74 +	d3dut_ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
    6.75 +
    6.76 +	d3dut_ctx->Draw(verts.size(), 0);
    6.77 +}
    6.78 +
    6.79 +
    6.80 +bool Mesh::update_vbuffer()
    6.81 +{
    6.82 +	if(vbuf) {
    6.83 +		return true;
    6.84 +	}
    6.85 +
    6.86 +	if(verts.empty()) {
    6.87 +		return false;
    6.88 +	}
    6.89 +
    6.90 +	D3D11_BUFFER_DESC bufdesc;
    6.91 +	memset(&bufdesc, 0, sizeof bufdesc);
    6.92 +	bufdesc.Usage = D3D11_USAGE_DEFAULT;
    6.93 +	bufdesc.ByteWidth = verts.size() * sizeof(Vertex);
    6.94 +	bufdesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    6.95 +
    6.96 +	D3D11_SUBRESOURCE_DATA subres;
    6.97 +	memset(&subres, 0, sizeof subres);
    6.98 +	subres.pSysMem = &verts[0];
    6.99 +
   6.100 +	if(d3dut_dev->CreateBuffer(&bufdesc, &subres, &vbuf) != 0) {
   6.101 +		fprintf(stderr, "failed to create vertex buffer\n");
   6.102 +		return false;
   6.103 +	}
   6.104 +	return true;
   6.105 +}
   6.106 +
   6.107 +void Mesh::invalidate_vbuffer()
   6.108 +{
   6.109 +	if(vbuf) {
   6.110 +		vbuf->Release();
   6.111 +		vbuf = 0;
   6.112 +	}
   6.113 +}
   6.114 \ No newline at end of file
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/mesh.h	Sun Jun 23 04:23:13 2013 +0300
     7.3 @@ -0,0 +1,37 @@
     7.4 +#ifndef MESH_H_
     7.5 +#define MESH_H_
     7.6 +
     7.7 +#include <vector>
     7.8 +#include <vmath/vmath.h>
     7.9 +#include <d3d11.h>
    7.10 +
    7.11 +struct Vertex {
    7.12 +	Vector3 pos, normal;
    7.13 +	Vector2 texcoord;
    7.14 +};
    7.15 +
    7.16 +class Mesh {
    7.17 +private:
    7.18 +	Vector3 cur_norm;
    7.19 +	Vector2 cur_texcoord;
    7.20 +
    7.21 +	std::vector<Vertex> verts;
    7.22 +	ID3D11Buffer *vbuf;
    7.23 +
    7.24 +	bool update_vbuffer();
    7.25 +	void invalidate_vbuffer();
    7.26 +
    7.27 +public:
    7.28 +	Mesh();
    7.29 +	~Mesh();
    7.30 +
    7.31 +	void clear();
    7.32 +
    7.33 +	void normal(float x, float y, float z);
    7.34 +	void texcoord(float u, float v);
    7.35 +	void vertex(float x, float y, float z);
    7.36 +
    7.37 +	void draw() const;
    7.38 +};
    7.39 +
    7.40 +#endif	// MESH_H_
    7.41 \ No newline at end of file
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/shader.h	Sun Jun 23 04:23:13 2013 +0300
     8.3 @@ -0,0 +1,24 @@
     8.4 +#ifndef SHADER_H_
     8.5 +#define SHADER_H_
     8.6 +
     8.7 +#include <d3dut.h>
     8.8 +
     8.9 +class Shader;
    8.10 +
    8.11 +class ShaderInput {
    8.12 +};
    8.13 +
    8.14 +class Shader {
    8.15 +private:
    8.16 +	ID3DBlob *bin;
    8.17 +
    8.18 +public:
    8.19 +	Shader();
    8.20 +	virtual ~Shader();
    8.21 +
    8.22 +	virtual bool load(const char *fname);
    8.23 +
    8.24 +	ID3DBlob *get_binary() const;
    8.25 +};
    8.26 +
    8.27 +#endif	// SHADER_H_
    8.28 \ No newline at end of file