d3dut

changeset 0:ecc040281dc9

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 22 Jun 2013 10:11:39 +0300
parents
children 242535442d04
files .hgignore d3dut.sln d3dut.vcxproj d3dut.vcxproj.filters example/example.vcxproj example/example.vcxproj.filters example/shader.hlsl example/src/example.cc include/d3dut.h src/d3dut.cc src/logmsg.cc src/logmsg.h src/win.cc src/win.h
diffstat 14 files changed, 1239 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/.hgignore	Sat Jun 22 10:11:39 2013 +0300
     1.3 @@ -0,0 +1,10 @@
     1.4 +\.o$
     1.5 +\.swp$
     1.6 +\.exe$
     1.7 +\.lib$
     1.8 +\.dll$
     1.9 +Debug$
    1.10 +Release$
    1.11 +\.user$
    1.12 +\.sdf$
    1.13 +\.suo$
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/d3dut.sln	Sat Jun 22 10:11:39 2013 +0300
     2.3 @@ -0,0 +1,29 @@
     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}") = "d3dut", "d3dut.vcxproj", "{0F0AE967-A4DD-4DB5-B191-5EA35701BA95}"
     2.8 +EndProject
     2.9 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example", "example\example.vcxproj", "{6B237CAC-3616-46E8-B62F-4A4CC26AD117}"
    2.10 +	ProjectSection(ProjectDependencies) = postProject
    2.11 +		{0F0AE967-A4DD-4DB5-B191-5EA35701BA95} = {0F0AE967-A4DD-4DB5-B191-5EA35701BA95}
    2.12 +	EndProjectSection
    2.13 +EndProject
    2.14 +Global
    2.15 +	GlobalSection(SolutionConfigurationPlatforms) = preSolution
    2.16 +		Debug|Win32 = Debug|Win32
    2.17 +		Release|Win32 = Release|Win32
    2.18 +	EndGlobalSection
    2.19 +	GlobalSection(ProjectConfigurationPlatforms) = postSolution
    2.20 +		{0F0AE967-A4DD-4DB5-B191-5EA35701BA95}.Debug|Win32.ActiveCfg = Debug|Win32
    2.21 +		{0F0AE967-A4DD-4DB5-B191-5EA35701BA95}.Debug|Win32.Build.0 = Debug|Win32
    2.22 +		{0F0AE967-A4DD-4DB5-B191-5EA35701BA95}.Release|Win32.ActiveCfg = Release|Win32
    2.23 +		{0F0AE967-A4DD-4DB5-B191-5EA35701BA95}.Release|Win32.Build.0 = Release|Win32
    2.24 +		{6B237CAC-3616-46E8-B62F-4A4CC26AD117}.Debug|Win32.ActiveCfg = Debug|Win32
    2.25 +		{6B237CAC-3616-46E8-B62F-4A4CC26AD117}.Debug|Win32.Build.0 = Debug|Win32
    2.26 +		{6B237CAC-3616-46E8-B62F-4A4CC26AD117}.Release|Win32.ActiveCfg = Release|Win32
    2.27 +		{6B237CAC-3616-46E8-B62F-4A4CC26AD117}.Release|Win32.Build.0 = Release|Win32
    2.28 +	EndGlobalSection
    2.29 +	GlobalSection(SolutionProperties) = preSolution
    2.30 +		HideSolutionNode = FALSE
    2.31 +	EndGlobalSection
    2.32 +EndGlobal
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/d3dut.vcxproj	Sat Jun 22 10:11:39 2013 +0300
     3.3 @@ -0,0 +1,95 @@
     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>{0F0AE967-A4DD-4DB5-B191-5EA35701BA95}</ProjectGuid>
    3.18 +    <Keyword>Win32Proj</Keyword>
    3.19 +    <RootNamespace>d3dut</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>DynamicLibrary</ConfigurationType>
    3.24 +    <UseDebugLibraries>true</UseDebugLibraries>
    3.25 +    <PlatformToolset>v100</PlatformToolset>
    3.26 +    <CharacterSet>MultiByte</CharacterSet>
    3.27 +  </PropertyGroup>
    3.28 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    3.29 +    <ConfigurationType>DynamicLibrary</ConfigurationType>
    3.30 +    <UseDebugLibraries>false</UseDebugLibraries>
    3.31 +    <PlatformToolset>v100</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>false</LinkIncremental>
    3.47 +  </PropertyGroup>
    3.48 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    3.49 +    <LinkIncremental>false</LinkIncremental>
    3.50 +  </PropertyGroup>
    3.51 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    3.52 +    <ClCompile>
    3.53 +      <PrecompiledHeader>
    3.54 +      </PrecompiledHeader>
    3.55 +      <WarningLevel>Level3</WarningLevel>
    3.56 +      <Optimization>Disabled</Optimization>
    3.57 +      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;D3DUT_EXPORTS;D3DUT_IMPLEMENTATION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    3.58 +      <AdditionalIncludeDirectories>$(ProjectDir)\include</AdditionalIncludeDirectories>
    3.59 +    </ClCompile>
    3.60 +    <Link>
    3.61 +      <SubSystem>Windows</SubSystem>
    3.62 +      <GenerateDebugInformation>true</GenerateDebugInformation>
    3.63 +      <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
    3.64 +    </Link>
    3.65 +  </ItemDefinitionGroup>
    3.66 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    3.67 +    <ClCompile>
    3.68 +      <WarningLevel>Level3</WarningLevel>
    3.69 +      <PrecompiledHeader>
    3.70 +      </PrecompiledHeader>
    3.71 +      <Optimization>MaxSpeed</Optimization>
    3.72 +      <FunctionLevelLinking>true</FunctionLevelLinking>
    3.73 +      <IntrinsicFunctions>true</IntrinsicFunctions>
    3.74 +      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;D3DUT_EXPORTS;D3DUT_IMPLEMENTATION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    3.75 +      <AdditionalIncludeDirectories>$(ProjectDir)\include</AdditionalIncludeDirectories>
    3.76 +    </ClCompile>
    3.77 +    <Link>
    3.78 +      <SubSystem>Windows</SubSystem>
    3.79 +      <GenerateDebugInformation>true</GenerateDebugInformation>
    3.80 +      <EnableCOMDATFolding>true</EnableCOMDATFolding>
    3.81 +      <OptimizeReferences>true</OptimizeReferences>
    3.82 +      <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
    3.83 +    </Link>
    3.84 +  </ItemDefinitionGroup>
    3.85 +  <ItemGroup>
    3.86 +    <ClInclude Include="include\d3dut.h" />
    3.87 +    <ClInclude Include="src\logmsg.h" />
    3.88 +    <ClInclude Include="src\win.h" />
    3.89 +  </ItemGroup>
    3.90 +  <ItemGroup>
    3.91 +    <ClCompile Include="src\d3dut.cc" />
    3.92 +    <ClCompile Include="src\logmsg.cc" />
    3.93 +    <ClCompile Include="src\win.cc" />
    3.94 +  </ItemGroup>
    3.95 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
    3.96 +  <ImportGroup Label="ExtensionTargets">
    3.97 +  </ImportGroup>
    3.98 +</Project>
    3.99 \ No newline at end of file
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/d3dut.vcxproj.filters	Sat Jun 22 10:11:39 2013 +0300
     4.3 @@ -0,0 +1,39 @@
     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 +    <ClInclude Include="include\d3dut.h">
    4.22 +      <Filter>Header Files</Filter>
    4.23 +    </ClInclude>
    4.24 +    <ClInclude Include="src\win.h">
    4.25 +      <Filter>Header Files</Filter>
    4.26 +    </ClInclude>
    4.27 +    <ClInclude Include="src\logmsg.h">
    4.28 +      <Filter>Header Files</Filter>
    4.29 +    </ClInclude>
    4.30 +  </ItemGroup>
    4.31 +  <ItemGroup>
    4.32 +    <ClCompile Include="src\d3dut.cc">
    4.33 +      <Filter>Source Files</Filter>
    4.34 +    </ClCompile>
    4.35 +    <ClCompile Include="src\win.cc">
    4.36 +      <Filter>Source Files</Filter>
    4.37 +    </ClCompile>
    4.38 +    <ClCompile Include="src\logmsg.cc">
    4.39 +      <Filter>Source Files</Filter>
    4.40 +    </ClCompile>
    4.41 +  </ItemGroup>
    4.42 +</Project>
    4.43 \ No newline at end of file
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/example/example.vcxproj	Sat Jun 22 10:11:39 2013 +0300
     5.3 @@ -0,0 +1,95 @@
     5.4 +<?xml version="1.0" encoding="utf-8"?>
     5.5 +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     5.6 +  <ItemGroup Label="ProjectConfigurations">
     5.7 +    <ProjectConfiguration Include="Debug|Win32">
     5.8 +      <Configuration>Debug</Configuration>
     5.9 +      <Platform>Win32</Platform>
    5.10 +    </ProjectConfiguration>
    5.11 +    <ProjectConfiguration Include="Release|Win32">
    5.12 +      <Configuration>Release</Configuration>
    5.13 +      <Platform>Win32</Platform>
    5.14 +    </ProjectConfiguration>
    5.15 +  </ItemGroup>
    5.16 +  <PropertyGroup Label="Globals">
    5.17 +    <ProjectGuid>{6B237CAC-3616-46E8-B62F-4A4CC26AD117}</ProjectGuid>
    5.18 +    <Keyword>Win32Proj</Keyword>
    5.19 +    <RootNamespace>example</RootNamespace>
    5.20 +  </PropertyGroup>
    5.21 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
    5.22 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    5.23 +    <ConfigurationType>Application</ConfigurationType>
    5.24 +    <UseDebugLibraries>true</UseDebugLibraries>
    5.25 +    <PlatformToolset>v100</PlatformToolset>
    5.26 +    <CharacterSet>MultiByte</CharacterSet>
    5.27 +  </PropertyGroup>
    5.28 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    5.29 +    <ConfigurationType>Application</ConfigurationType>
    5.30 +    <UseDebugLibraries>false</UseDebugLibraries>
    5.31 +    <PlatformToolset>v100</PlatformToolset>
    5.32 +    <WholeProgramOptimization>true</WholeProgramOptimization>
    5.33 +    <CharacterSet>MultiByte</CharacterSet>
    5.34 +  </PropertyGroup>
    5.35 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
    5.36 +  <ImportGroup Label="ExtensionSettings">
    5.37 +  </ImportGroup>
    5.38 +  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    5.39 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    5.40 +  </ImportGroup>
    5.41 +  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    5.42 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    5.43 +  </ImportGroup>
    5.44 +  <PropertyGroup Label="UserMacros" />
    5.45 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    5.46 +    <LinkIncremental>false</LinkIncremental>
    5.47 +    <ExecutablePath>$(SolutionDir)\$(Configuration);$(ExecutablePath)</ExecutablePath>
    5.48 +  </PropertyGroup>
    5.49 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    5.50 +    <LinkIncremental>false</LinkIncremental>
    5.51 +    <ExecutablePath>$(SolutionDir)\$(Configuration);$(ExecutablePath)</ExecutablePath>
    5.52 +  </PropertyGroup>
    5.53 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    5.54 +    <ClCompile>
    5.55 +      <PrecompiledHeader>
    5.56 +      </PrecompiledHeader>
    5.57 +      <WarningLevel>Level3</WarningLevel>
    5.58 +      <Optimization>Disabled</Optimization>
    5.59 +      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    5.60 +      <AdditionalIncludeDirectories>$(SolutionDir)\include</AdditionalIncludeDirectories>
    5.61 +    </ClCompile>
    5.62 +    <Link>
    5.63 +      <SubSystem>Console</SubSystem>
    5.64 +      <GenerateDebugInformation>true</GenerateDebugInformation>
    5.65 +      <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
    5.66 +      <AdditionalLibraryDirectories>$(SolutionDir)\$(Configuration)</AdditionalLibraryDirectories>
    5.67 +    </Link>
    5.68 +  </ItemDefinitionGroup>
    5.69 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    5.70 +    <ClCompile>
    5.71 +      <WarningLevel>Level3</WarningLevel>
    5.72 +      <PrecompiledHeader>
    5.73 +      </PrecompiledHeader>
    5.74 +      <Optimization>MaxSpeed</Optimization>
    5.75 +      <FunctionLevelLinking>true</FunctionLevelLinking>
    5.76 +      <IntrinsicFunctions>true</IntrinsicFunctions>
    5.77 +      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    5.78 +      <AdditionalIncludeDirectories>$(SolutionDir)\include</AdditionalIncludeDirectories>
    5.79 +    </ClCompile>
    5.80 +    <Link>
    5.81 +      <SubSystem>Console</SubSystem>
    5.82 +      <GenerateDebugInformation>true</GenerateDebugInformation>
    5.83 +      <EnableCOMDATFolding>true</EnableCOMDATFolding>
    5.84 +      <OptimizeReferences>true</OptimizeReferences>
    5.85 +      <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
    5.86 +      <AdditionalLibraryDirectories>$(SolutionDir)\$(Configuration)</AdditionalLibraryDirectories>
    5.87 +    </Link>
    5.88 +  </ItemDefinitionGroup>
    5.89 +  <ItemGroup>
    5.90 +    <ClCompile Include="src\example.cc" />
    5.91 +  </ItemGroup>
    5.92 +  <ItemGroup>
    5.93 +    <None Include="shader.hlsl" />
    5.94 +  </ItemGroup>
    5.95 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
    5.96 +  <ImportGroup Label="ExtensionTargets">
    5.97 +  </ImportGroup>
    5.98 +</Project>
    5.99 \ No newline at end of file
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/example/example.vcxproj.filters	Sat Jun 22 10:11:39 2013 +0300
     6.3 @@ -0,0 +1,30 @@
     6.4 +<?xml version="1.0" encoding="utf-8"?>
     6.5 +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     6.6 +  <ItemGroup>
     6.7 +    <Filter Include="Source Files">
     6.8 +      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
     6.9 +      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
    6.10 +    </Filter>
    6.11 +    <Filter Include="Header Files">
    6.12 +      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
    6.13 +      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
    6.14 +    </Filter>
    6.15 +    <Filter Include="Resource Files">
    6.16 +      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
    6.17 +      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
    6.18 +    </Filter>
    6.19 +    <Filter Include="shaders">
    6.20 +      <UniqueIdentifier>{3c0a494b-a31b-4938-9d51-78e7cbed4e2c}</UniqueIdentifier>
    6.21 +    </Filter>
    6.22 +  </ItemGroup>
    6.23 +  <ItemGroup>
    6.24 +    <ClCompile Include="src\example.cc">
    6.25 +      <Filter>Source Files</Filter>
    6.26 +    </ClCompile>
    6.27 +  </ItemGroup>
    6.28 +  <ItemGroup>
    6.29 +    <None Include="shader.hlsl">
    6.30 +      <Filter>shaders</Filter>
    6.31 +    </None>
    6.32 +  </ItemGroup>
    6.33 +</Project>
    6.34 \ No newline at end of file
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/example/shader.hlsl	Sat Jun 22 10:11:39 2013 +0300
     7.3 @@ -0,0 +1,31 @@
     7.4 +cbuffer RenderState : register(b0) {
     7.5 +	matrix modelview_matrix : packoffset(c0);
     7.6 +	matrix projection_matrix : packoffset(c4);
     7.7 +};
     7.8 +
     7.9 +struct VSInput {
    7.10 +	float4 pos : POSITION;
    7.11 +	float4 color : COLOR;
    7.12 +};
    7.13 +
    7.14 +struct VSOutput {
    7.15 +	float4 pos : SV_POSITION;
    7.16 +	float4 color : COLOR0;
    7.17 +};
    7.18 +
    7.19 +VSOutput vertex_main(VSInput input)
    7.20 +{
    7.21 +	VSOutput res;
    7.22 +
    7.23 +	float4 vpos = mul(input.pos, modelview_matrix);
    7.24 +
    7.25 +	res.pos = mul(vpos, projection_matrix);
    7.26 +	res.color = input.color;
    7.27 +	return res;
    7.28 +}
    7.29 +
    7.30 +
    7.31 +float4 pixel_main(VSOutput input) : SV_TARGET
    7.32 +{
    7.33 +	return input.color;
    7.34 +}
    7.35 \ No newline at end of file
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/example/src/example.cc	Sat Jun 22 10:11:39 2013 +0300
     8.3 @@ -0,0 +1,234 @@
     8.4 +#include <stdio.h>
     8.5 +#include <stddef.h>
     8.6 +#include <math.h>
     8.7 +#include "d3dut.h"
     8.8 +
     8.9 +struct Vertex {
    8.10 +	float pos[3];
    8.11 +	float color[4];
    8.12 +};
    8.13 +
    8.14 +struct RenderState {
    8.15 +	float modelview[16];
    8.16 +	float projection[16];
    8.17 +};
    8.18 +
    8.19 +static bool init();
    8.20 +static void cleanup();
    8.21 +static void display();
    8.22 +static void reshape(int x, int y);
    8.23 +static void keyb(unsigned char key, int x, int y);
    8.24 +
    8.25 +static int width, height;
    8.26 +
    8.27 +static ID3D11InputLayout *vertex_layout;
    8.28 +static ID3D11VertexShader *vsdr;
    8.29 +static ID3D11PixelShader *psdr;
    8.30 +static ID3D11Buffer *vbuf;
    8.31 +static ID3D11Buffer *rstate_buf;
    8.32 +
    8.33 +static RenderState rstate;
    8.34 +
    8.35 +int main(int argc, char **argv)
    8.36 +{
    8.37 +	d3dut_init(&argc, argv);
    8.38 +	d3dut_init_window_size(800, 600);
    8.39 +	d3dut_init_display_mode(D3DUT_RGB | D3DUT_DEPTH | D3DUT_DOUBLE);
    8.40 +	d3dut_create_window("d3dut example");
    8.41 +
    8.42 +	d3dut_display_func(display);
    8.43 +	d3dut_idle_func(d3dut_post_redisplay);
    8.44 +	d3dut_reshape_func(reshape);
    8.45 +	d3dut_keyboard_func(keyb);
    8.46 +
    8.47 +	if(!init()) {
    8.48 +		return 1;
    8.49 +	}
    8.50 +	atexit(cleanup);
    8.51 +
    8.52 +	d3dut_main_loop();
    8.53 +	return 0;
    8.54 +}
    8.55 +
    8.56 +static bool init()
    8.57 +{
    8.58 +	unsigned int sdrflags = 0;//D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_DEBUG;
    8.59 +
    8.60 +	ID3DBlob *vsbuf, *psbuf, *msgblob = 0;
    8.61 +	if(D3DX11CompileFromFile("shader.hlsl", 0, 0, "vertex_main", "vs_4_0", sdrflags, 0, 0, &vsbuf, &msgblob, 0) != 0) {
    8.62 +		fprintf(stderr, "failed to load vertex shader\n");
    8.63 +		if(msgblob && msgblob->GetBufferSize() > 0) {
    8.64 +			fprintf(stderr, "Vertex Shader:\n%s\n", (char*)msgblob->GetBufferPointer());
    8.65 +		}
    8.66 +		return false;
    8.67 +	}
    8.68 +	if(D3DX11CompileFromFile("shader.hlsl", 0, 0, "pixel_main", "ps_4_0", sdrflags, 0, 0, &psbuf, &msgblob, 0) != 0) {
    8.69 +		fprintf(stderr, "failed to load pixel shader\n");
    8.70 +		if(msgblob && msgblob->GetBufferSize() > 0) {
    8.71 +			fprintf(stderr, "Pixel Shader:\n%s\n", (char*)msgblob->GetBufferPointer());
    8.72 +		}
    8.73 +		return false;
    8.74 +	}
    8.75 +
    8.76 +	if(d3dut_dev->CreateVertexShader(vsbuf->GetBufferPointer(), vsbuf->GetBufferSize(), 0, &vsdr) != 0) {
    8.77 +		fprintf(stderr, "failed to create vertex shader\n");
    8.78 +		return false;
    8.79 +	}
    8.80 +	if(d3dut_dev->CreatePixelShader(psbuf->GetBufferPointer(), psbuf->GetBufferSize(), 0, &psdr) != 0) {
    8.81 +		fprintf(stderr, "failed to create pixel shader\n");
    8.82 +		return false;
    8.83 +	}
    8.84 +
    8.85 +	D3D11_INPUT_ELEMENT_DESC elem_desc[2];
    8.86 +	elem_desc[0].SemanticName = "position";
    8.87 +	elem_desc[0].SemanticIndex = 0;
    8.88 +	elem_desc[0].Format = DXGI_FORMAT_R32G32B32_FLOAT;
    8.89 +	elem_desc[0].InputSlot = 0;
    8.90 +	elem_desc[0].AlignedByteOffset = 0;
    8.91 +	elem_desc[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
    8.92 +	elem_desc[0].InstanceDataStepRate = 0;
    8.93 +
    8.94 +	elem_desc[1].SemanticName = "color";
    8.95 +	elem_desc[1].SemanticIndex = 0;
    8.96 +	elem_desc[1].Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
    8.97 +	elem_desc[1].InputSlot = 0;
    8.98 +	elem_desc[1].AlignedByteOffset = offsetof(Vertex, color);
    8.99 +	elem_desc[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
   8.100 +	elem_desc[1].InstanceDataStepRate = 0;
   8.101 +
   8.102 +	if(d3dut_dev->CreateInputLayout(elem_desc, 2, vsbuf->GetBufferPointer(), vsbuf->GetBufferSize(), &vertex_layout) != 0) {
   8.103 +		fprintf(stderr, "failed to create vertex layout\n");
   8.104 +		return 0;
   8.105 +	}
   8.106 +	vsbuf->Release();
   8.107 +	psbuf->Release();
   8.108 +
   8.109 +	// --- create vertex buffer ---
   8.110 +	Vertex varr[] = {
   8.111 +		{{-0.6, -0.4, 0}, {1, 0, 0, 1}},
   8.112 +		{{0.0, 0.6, 0}, {0, 1, 0, 1}},
   8.113 +		{{0.6, -0.4, 0}, {0, 0, 1, 1}}
   8.114 +	};
   8.115 +
   8.116 +	D3D11_BUFFER_DESC buf_desc;
   8.117 +	memset(&buf_desc, 0, sizeof buf_desc);
   8.118 +	buf_desc.Usage = D3D11_USAGE_DEFAULT;
   8.119 +	buf_desc.ByteWidth = sizeof varr;
   8.120 +	buf_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
   8.121 +
   8.122 +	D3D11_SUBRESOURCE_DATA subdata;
   8.123 +	memset(&subdata, 0, sizeof subdata);
   8.124 +	subdata.pSysMem = varr;
   8.125 +	if(d3dut_dev->CreateBuffer(&buf_desc, &subdata, &vbuf) != 0) {
   8.126 +		fprintf(stderr, "failed to create vertex buffer\n");
   8.127 +		return false;
   8.128 +	}
   8.129 +
   8.130 +	// render state buffer
   8.131 +	memset(&buf_desc, 0, sizeof buf_desc);
   8.132 +	buf_desc.Usage = D3D11_USAGE_DEFAULT;
   8.133 +	buf_desc.ByteWidth = sizeof(RenderState);
   8.134 +	buf_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
   8.135 +
   8.136 +	memset(&subdata, 0, sizeof subdata);
   8.137 +	subdata.pSysMem = &rstate;
   8.138 +	if(d3dut_dev->CreateBuffer(&buf_desc, &subdata, &rstate_buf) != 0) {
   8.139 +		fprintf(stderr, "failed to create render state buffer\n");
   8.140 +		return false;
   8.141 +	}
   8.142 +
   8.143 +	return true;
   8.144 +}
   8.145 +
   8.146 +static void cleanup()
   8.147 +{
   8.148 +	vbuf->Release();
   8.149 +	rstate_buf->Release();
   8.150 +	vsdr->Release();
   8.151 +	psdr->Release();
   8.152 +	vertex_layout->Release();
   8.153 +}
   8.154 +
   8.155 +static void set_identity(float *mat)
   8.156 +{
   8.157 +	mat[0] = mat[5] = mat[10] = mat[15] = 1.0;
   8.158 +	mat[1] = mat[2] = mat[3] = mat[4] = mat[6] = mat[7] = mat[8] = mat[9] = mat[11] = mat[12] = mat[13] = mat[14] = 0.0;
   8.159 +}
   8.160 +
   8.161 +static void set_rotation_z(float *mat, float angle)
   8.162 +{
   8.163 +	set_identity(mat);
   8.164 +
   8.165 +	mat[0] = cos(angle);
   8.166 +	mat[1] = -sin(angle);
   8.167 +	mat[4] = sin(angle);
   8.168 +	mat[5] = cos(angle);
   8.169 +}
   8.170 +
   8.171 +static void set_ortho(float *mat, float aspect)
   8.172 +{
   8.173 +	set_identity(mat);
   8.174 +	mat[0] = 1.0 / aspect;
   8.175 +}
   8.176 +
   8.177 +static void display()
   8.178 +{
   8.179 +	unsigned int msec = timeGetTime();
   8.180 +
   8.181 +	float fbcolor[] = {0.2f, 0.2f, 0.2f, 1.0f};
   8.182 +	d3dut_ctx->ClearRenderTargetView(d3dut_rtview, fbcolor);
   8.183 +
   8.184 +	// set render state constant buffer data
   8.185 +	set_ortho(rstate.projection, (float)width / (float)height);
   8.186 +	set_rotation_z(rstate.modelview, msec / 1000.0);
   8.187 +
   8.188 +	d3dut_ctx->UpdateSubresource(rstate_buf, 0, 0, &rstate, 0, 0);
   8.189 +	d3dut_ctx->VSSetConstantBuffers(0, 1, &rstate_buf);
   8.190 +
   8.191 +
   8.192 +	unsigned int stride = sizeof(Vertex);
   8.193 +	unsigned int offset = 0;
   8.194 +	d3dut_ctx->IASetVertexBuffers(0, 1, &vbuf, &stride, &offset);
   8.195 +	d3dut_ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
   8.196 +	d3dut_ctx->IASetInputLayout(vertex_layout);
   8.197 +
   8.198 +	d3dut_ctx->VSSetShader(vsdr, 0, 0);
   8.199 +	d3dut_ctx->PSSetShader(psdr, 0, 0);
   8.200 +
   8.201 +	d3dut_ctx->Draw(3, 0);
   8.202 +
   8.203 +	d3dut_swap_buffers();
   8.204 +}
   8.205 +
   8.206 +static void reshape(int x, int y)
   8.207 +{
   8.208 +	width = x;
   8.209 +	height = y;
   8.210 +
   8.211 +	D3D11_VIEWPORT vp;
   8.212 +	vp.Width = (float)x;
   8.213 +	vp.Height = (float)y;
   8.214 +	vp.MinDepth = 0;
   8.215 +	vp.MaxDepth = 1;
   8.216 +	vp.TopLeftX = 0;
   8.217 +	vp.TopLeftY = 0;
   8.218 +	d3dut_ctx->RSSetViewports(1, &vp);
   8.219 +
   8.220 +	// TODO probably we also need to resize render targets or whatever...
   8.221 +}
   8.222 +
   8.223 +static void keyb(unsigned char key, int x, int y)
   8.224 +{
   8.225 +	switch(key) {
   8.226 +	case 27:
   8.227 +		exit(0);
   8.228 +
   8.229 +	case ' ':
   8.230 +		{
   8.231 +			static bool anim = true;
   8.232 +			anim = !anim;
   8.233 +			d3dut_idle_func(anim ? d3dut_post_redisplay : 0);
   8.234 +		}
   8.235 +		break;
   8.236 +	}
   8.237 +}
   8.238 \ No newline at end of file
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/include/d3dut.h	Sat Jun 22 10:11:39 2013 +0300
     9.3 @@ -0,0 +1,95 @@
     9.4 +#ifndef D3DUT_H_
     9.5 +#define D3DUT_H_
     9.6 +
     9.7 +#ifdef _MSC_VER
     9.8 +#pragma comment(lib, "d3d11.lib")
     9.9 +#pragma comment(lib, "d3dx11.lib")
    9.10 +#pragma comment(lib, "winmm.lib")
    9.11 +
    9.12 +#ifndef D3DUT_IMPLEMENTATION
    9.13 +#pragma comment(lib, "d3dut.lib")
    9.14 +#endif
    9.15 +#endif
    9.16 +
    9.17 +#ifdef D3DUT_IMPLEMENTATION
    9.18 +#define D3DUTAPI	__declspec(dllexport)
    9.19 +#else
    9.20 +#define D3DUTAPI	__declspec(dllimport)
    9.21 +#endif
    9.22 +
    9.23 +#include <d3d11.h>
    9.24 +#include <d3dx11.h>
    9.25 +
    9.26 +#define D3DUT_RGB			0
    9.27 +#define D3DUT_RGBA			0
    9.28 +#define D3DUT_SINGLE		0
    9.29 +
    9.30 +#define D3DUT_DOUBLE		1
    9.31 +#define D3DUT_DEPTH			2
    9.32 +#define D3DUT_STENCIL		4
    9.33 +#define D3DUT_STEREO		8
    9.34 +#define D3DUT_MULTISAMPLE	16
    9.35 +
    9.36 +enum {
    9.37 +	D3DUT_WINDOW_WIDTH,
    9.38 +	D3DUT_WINDOW_HEIGHT,
    9.39 +	D3DUT_ELAPSED_TIME
    9.40 +};
    9.41 +
    9.42 +enum {
    9.43 +	D3DUT_LEFT_BUTTON,
    9.44 +	D3DUT_MIDDLE_BUTTON,
    9.45 +	D3DUT_RIGHT_BUTTON,
    9.46 +
    9.47 +	D3DUT_WHEELDOWN_BUTTON,
    9.48 +	D3DUT_WHEELUP_BUTTON
    9.49 +};
    9.50 +
    9.51 +enum {D3DUT_DOWN = 0, D3DUT_UP = 1};
    9.52 +
    9.53 +typedef void (*D3DUT_DisplayFunc)();
    9.54 +typedef void (*D3DUT_IdleFunc)();
    9.55 +typedef void (*D3DUT_ReshapeFunc)(int, int);
    9.56 +typedef void (*D3DUT_KeyboardFunc)(unsigned char, int, int);
    9.57 +typedef void (*D3DUT_KeyboardUpFunc)(unsigned char, int, int);
    9.58 +typedef void (*D3DUT_SpecialFunc)(int, int, int);
    9.59 +typedef void (*D3DUT_SpecialUpFunc)(int, int, int);
    9.60 +typedef void (*D3DUT_MouseFunc)(int, int, int, int);
    9.61 +typedef void (*D3DUT_MotionFunc)(int, int);
    9.62 +typedef void (*D3DUT_PassiveMotionFunc)(int, int);
    9.63 +
    9.64 +extern D3DUTAPI ID3D11Device *d3dut_dev;
    9.65 +extern D3DUTAPI ID3D11DeviceContext *d3dut_ctx;
    9.66 +extern D3DUTAPI ID3D11RenderTargetView *d3dut_rtview;
    9.67 +
    9.68 +void D3DUTAPI d3dut_init(int *argc, char **argv);
    9.69 +void D3DUTAPI d3dut_init_display_mode(unsigned int dmflags);
    9.70 +void D3DUTAPI d3dut_init_window_size(int xsz, int ysz);
    9.71 +
    9.72 +int D3DUTAPI d3dut_create_window(const char *title);
    9.73 +void D3DUTAPI d3dut_destroy_window(int win);
    9.74 +void D3DUTAPI d3dut_set_window(int idx);
    9.75 +int D3DUTAPI d3dut_get_window();
    9.76 +
    9.77 +void D3DUTAPI d3dut_display_func(D3DUT_DisplayFunc func);
    9.78 +void D3DUTAPI d3dut_idle_func(D3DUT_IdleFunc func);
    9.79 +void D3DUTAPI d3dut_reshape_func(D3DUT_ReshapeFunc func);
    9.80 +void D3DUTAPI d3dut_keyboard_func(D3DUT_KeyboardFunc func);
    9.81 +void D3DUTAPI d3dut_keyboard_up_func(D3DUT_KeyboardUpFunc func);
    9.82 +void D3DUTAPI d3dut_special_func(D3DUT_SpecialFunc func);
    9.83 +void D3DUTAPI d3dut_special_up_func(D3DUT_SpecialUpFunc func);
    9.84 +void D3DUTAPI d3dut_mouse_func(D3DUT_MouseFunc func);
    9.85 +void D3DUTAPI d3dut_motion_func(D3DUT_MotionFunc func);
    9.86 +void D3DUTAPI d3dut_passive_motion_func(D3DUT_PassiveMotionFunc func);
    9.87 +
    9.88 +void D3DUTAPI d3dut_post_redisplay();
    9.89 +void D3DUTAPI d3dut_swap_buffers();
    9.90 +
    9.91 +void D3DUTAPI d3dut_main_loop();
    9.92 +
    9.93 +int D3DUTAPI d3dut_get(unsigned int what);
    9.94 +
    9.95 +void D3DUTAPI d3dut_solid_sphere(double radius, int slices, int stacks);
    9.96 +// TODO ... more stuff
    9.97 +
    9.98 +#endif	// D3DUT_H_
    9.99 \ No newline at end of file
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/d3dut.cc	Sat Jun 22 10:11:39 2013 +0300
    10.3 @@ -0,0 +1,255 @@
    10.4 +#include <stdio.h>
    10.5 +#include <stdlib.h>
    10.6 +#include <vector>
    10.7 +#include "d3dut.h"
    10.8 +#include "win.h"
    10.9 +#include "logmsg.h"
   10.10 +
   10.11 +static void d3dut_cleanup();
   10.12 +
   10.13 +D3DUTAPI ID3D11Device *d3dut_dev;
   10.14 +D3DUTAPI ID3D11DeviceContext *d3dut_ctx;
   10.15 +D3DUTAPI ID3D11RenderTargetView *d3dut_rtview;
   10.16 +
   10.17 +static int init_xsz = 640;
   10.18 +static int init_ysz = 480;
   10.19 +static int init_dmflags = 0;
   10.20 +
   10.21 +static long init_time = -1;
   10.22 +
   10.23 +static D3DUT_IdleFunc idle_func;
   10.24 +
   10.25 +void D3DUTAPI d3dut_init(int *argc, char **argv)
   10.26 +{
   10.27 +	if(init_time >= 0) {
   10.28 +		warning("already initialized!\n");
   10.29 +		return;
   10.30 +	}
   10.31 +
   10.32 +	WNDCLASS wclass;
   10.33 +	memset(&wclass, 0, sizeof wclass);
   10.34 +	wclass.hInstance = GetModuleHandle(0);
   10.35 +	wclass.lpfnWndProc = win_handle_event;
   10.36 +	wclass.lpszClassName = WINCLASSNAME;
   10.37 +	wclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
   10.38 +	wclass.hIcon = LoadIcon(0, IDI_APPLICATION);
   10.39 +	wclass.hCursor = LoadCursor(0, IDC_ARROW);
   10.40 +	wclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
   10.41 +	RegisterClass(&wclass);
   10.42 +
   10.43 +	// create D3D device
   10.44 +	D3D_FEATURE_LEVEL feature_level[] = {
   10.45 +		D3D_FEATURE_LEVEL_11_0,
   10.46 +		D3D_FEATURE_LEVEL_10_1,
   10.47 +		D3D_FEATURE_LEVEL_10_0
   10.48 +	};
   10.49 +	if(D3D11CreateDevice(0, D3D_DRIVER_TYPE_HARDWARE, 0, 0, feature_level, 3, D3D11_SDK_VERSION,
   10.50 +			&d3dut_dev, 0, &d3dut_ctx) != 0) {
   10.51 +		fatal_error("failed to create D3D11 device\n");
   10.52 +	}
   10.53 +	atexit(d3dut_cleanup);
   10.54 +
   10.55 +	init_time = timeGetTime();
   10.56 +}
   10.57 +
   10.58 +static void d3dut_cleanup()
   10.59 +{
   10.60 +	for(size_t i=0; i<windows.size(); i++) {
   10.61 +		if(windows[i]) {
   10.62 +			destroy_window(i);
   10.63 +		}
   10.64 +	}
   10.65 +	windows.clear();
   10.66 +
   10.67 +	if(d3dut_dev) {
   10.68 +		d3dut_dev->Release();
   10.69 +		d3dut_dev = 0;
   10.70 +	}
   10.71 +	if(d3dut_ctx) {
   10.72 +		d3dut_ctx->Release();
   10.73 +		d3dut_ctx = 0;
   10.74 +	}
   10.75 +	d3dut_rtview = 0;
   10.76 +
   10.77 +	UnregisterClass(WINCLASSNAME, GetModuleHandle(0));
   10.78 +	init_time = -1;
   10.79 +}
   10.80 +
   10.81 +void D3DUTAPI d3dut_init_display_mode(unsigned int dmflags)
   10.82 +{
   10.83 +	init_dmflags = dmflags;
   10.84 +}
   10.85 +
   10.86 +void D3DUTAPI d3dut_init_window_size(int xsz, int ysz)
   10.87 +{
   10.88 +	init_xsz = xsz;
   10.89 +	init_ysz = ysz;
   10.90 +}
   10.91 +
   10.92 +
   10.93 +int D3DUTAPI d3dut_create_window(const char *title)
   10.94 +{
   10.95 +	return create_window(title, init_xsz, init_ysz, init_dmflags);
   10.96 +}
   10.97 +
   10.98 +void D3DUTAPI d3dut_destroy_window(int win)
   10.99 +{
  10.100 +	destroy_window(win);
  10.101 +}
  10.102 +
  10.103 +void D3DUTAPI d3dut_set_window(int idx)
  10.104 +{
  10.105 +	set_active_win(idx);
  10.106 +}
  10.107 +
  10.108 +int D3DUTAPI d3dut_get_window()
  10.109 +{
  10.110 +	return get_active_win();
  10.111 +}
  10.112 +
  10.113 +void D3DUTAPI d3dut_display_func(D3DUT_DisplayFunc func)
  10.114 +{
  10.115 +	Window *win = get_window();
  10.116 +	win->display_func = func;
  10.117 +}
  10.118 +
  10.119 +void D3DUTAPI d3dut_idle_func(D3DUT_IdleFunc func)
  10.120 +{
  10.121 +	idle_func = func;
  10.122 +}
  10.123 +
  10.124 +void D3DUTAPI d3dut_reshape_func(D3DUT_ReshapeFunc func)
  10.125 +{
  10.126 +	Window *win = get_window();
  10.127 +	win->reshape_func = func;
  10.128 +}
  10.129 +
  10.130 +void D3DUTAPI d3dut_keyboard_func(D3DUT_KeyboardFunc func)
  10.131 +{
  10.132 +	Window *win = get_window();
  10.133 +	win->keyboard_func = func;
  10.134 +}
  10.135 +
  10.136 +void D3DUTAPI d3dut_keyboard_up_func(D3DUT_KeyboardUpFunc func)
  10.137 +{
  10.138 +	Window *win = get_window();
  10.139 +	win->keyboard_up_func = func;
  10.140 +}
  10.141 +
  10.142 +void D3DUTAPI d3dut_special_func(D3DUT_SpecialFunc func)
  10.143 +{
  10.144 +	Window *win = get_window();
  10.145 +	win->special_func = func;
  10.146 +}
  10.147 +
  10.148 +void D3DUTAPI d3dut_special_up_func(D3DUT_SpecialUpFunc func)
  10.149 +{
  10.150 +	Window *win = get_window();
  10.151 +	win->special_up_func = func;
  10.152 +}
  10.153 +
  10.154 +void D3DUTAPI d3dut_mouse_func(D3DUT_MouseFunc func)
  10.155 +{
  10.156 +	Window *win = get_window();
  10.157 +	win->mouse_func = func;
  10.158 +}
  10.159 +
  10.160 +void D3DUTAPI d3dut_motion_func(D3DUT_MotionFunc func)
  10.161 +{
  10.162 +	Window *win = get_window();
  10.163 +	win->motion_func = func;
  10.164 +}
  10.165 +
  10.166 +void D3DUTAPI d3dut_passive_motion_func(D3DUT_PassiveMotionFunc func)
  10.167 +{
  10.168 +	Window *win = get_window();
  10.169 +	win->passive_motion_func = func;
  10.170 +}
  10.171 +
  10.172 +
  10.173 +void D3DUTAPI d3dut_post_redisplay()
  10.174 +{
  10.175 +	Window *win = get_window();
  10.176 +	win->must_redisplay = true;
  10.177 +}
  10.178 +
  10.179 +void D3DUTAPI d3dut_swap_buffers()
  10.180 +{
  10.181 +	Window *win = get_window();
  10.182 +	win->swap->Present(0, 0);
  10.183 +}
  10.184 +
  10.185 +void D3DUTAPI d3dut_main_loop()
  10.186 +{
  10.187 +	MSG msg;
  10.188 +
  10.189 +	for(;;) {
  10.190 +		bool must_redisplay = false;
  10.191 +		for(size_t i=0; i<windows.size(); i++) {
  10.192 +			Window *win = windows[i];
  10.193 +			if(win->changed_size && win->reshape_func) {
  10.194 +				win->changed_size = false;
  10.195 +				set_active_win(i);
  10.196 +				win->reshape_func(win->width, win->height);
  10.197 +			}
  10.198 +			if(win->must_redisplay) {
  10.199 +				must_redisplay = true;
  10.200 +			}
  10.201 +		}
  10.202 +
  10.203 +		if(idle_func || must_redisplay) {
  10.204 +			while(PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
  10.205 +				TranslateMessage(&msg);
  10.206 +				DispatchMessage(&msg);
  10.207 +				if(msg.message == WM_QUIT) {
  10.208 +					return;
  10.209 +				}
  10.210 +			}
  10.211 +
  10.212 +			if(idle_func) { // checking again because a handler might have set this to 0
  10.213 +				idle_func();
  10.214 +			}
  10.215 +		} else {
  10.216 +			if(!GetMessage(&msg, 0, 0, 0)) {
  10.217 +				return;
  10.218 +			}
  10.219 +			TranslateMessage(&msg);
  10.220 +			DispatchMessage(&msg);
  10.221 +		}
  10.222 +
  10.223 +		for(size_t i=0; i<windows.size(); i++) {
  10.224 +			Window *win = windows[i];
  10.225 +			if(win->must_redisplay && win->display_func) {
  10.226 +				win->must_redisplay = false;
  10.227 +				set_active_win(i);
  10.228 +				win->display_func();
  10.229 +				ValidateRect(win->win, 0);
  10.230 +			}
  10.231 +		}
  10.232 +	}
  10.233 +}
  10.234 +
  10.235 +
  10.236 +int D3DUTAPI d3dut_get(unsigned int what)
  10.237 +{
  10.238 +	Window *win = get_window();
  10.239 +
  10.240 +	switch(what) {
  10.241 +	case D3DUT_WINDOW_WIDTH:
  10.242 +		return win->width;
  10.243 +	case D3DUT_WINDOW_HEIGHT:
  10.244 +		return win->height;
  10.245 +
  10.246 +	case D3DUT_ELAPSED_TIME:
  10.247 +		return (long)timeGetTime() - init_time;
  10.248 +
  10.249 +	default:
  10.250 +		break;
  10.251 +	}
  10.252 +	return 0;
  10.253 +}
  10.254 +
  10.255 +
  10.256 +void D3DUTAPI d3dut_solid_sphere(double radius, int slices, int stacks)
  10.257 +{
  10.258 +}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/logmsg.cc	Sat Jun 22 10:11:39 2013 +0300
    11.3 @@ -0,0 +1,26 @@
    11.4 +#include <stdio.h>
    11.5 +#include <stdlib.h>
    11.6 +#include <stdarg.h>
    11.7 +#include "logmsg.h"
    11.8 +
    11.9 +void fatal_error(const char *fmt, ...)
   11.10 +{
   11.11 +	fputs("D3DUT FATAL ERROR: ", stderr);
   11.12 +
   11.13 +	va_list ap;
   11.14 +	va_start(ap, fmt);
   11.15 +	vfprintf(stderr, fmt, ap);
   11.16 +	va_end(ap);
   11.17 +
   11.18 +	abort();
   11.19 +}
   11.20 +
   11.21 +void warning(const char *fmt, ...)
   11.22 +{
   11.23 +	fputs("D3DUT WARNING: ", stderr);
   11.24 +
   11.25 +	va_list ap;
   11.26 +	va_start(ap, fmt);
   11.27 +	vfprintf(stderr, fmt, ap);
   11.28 +	va_end(ap);
   11.29 +}
   11.30 \ No newline at end of file
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/logmsg.h	Sat Jun 22 10:11:39 2013 +0300
    12.3 @@ -0,0 +1,7 @@
    12.4 +#ifndef LOGMSG_H_
    12.5 +#define LOGMSG_H_
    12.6 +
    12.7 +void fatal_error(const char *fmt, ...);
    12.8 +void warning(const char *fmt, ...);
    12.9 +
   12.10 +#endif	// LOGMSG_H_
   12.11 \ No newline at end of file
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/win.cc	Sat Jun 22 10:11:39 2013 +0300
    13.3 @@ -0,0 +1,251 @@
    13.4 +#include <dxgi.h>
    13.5 +#include "d3dut.h"
    13.6 +#include "win.h"
    13.7 +#include "logmsg.h"
    13.8 +
    13.9 +std::vector<Window*> windows;
   13.10 +int active_win = -1;
   13.11 +
   13.12 +int create_window(const char *title, int xsz, int ysz, unsigned int dmflags)
   13.13 +{
   13.14 +	IDXGIDevice *dxgidev;
   13.15 +	if(d3dut_dev->QueryInterface(__uuidof(IDXGIDevice), (void**)&dxgidev) != 0) {
   13.16 +		fatal_error("failed to get IDXGIDevice interface\n");
   13.17 +		return 0;
   13.18 +	}
   13.19 +	IDXGIAdapter *adapter;
   13.20 +	if(dxgidev->GetParent(__uuidof(IDXGIAdapter), (void**)&adapter) != 0) {
   13.21 +		fatal_error("failed to get IDXGIAdapter pointer\n");
   13.22 +		return 0;
   13.23 +	}
   13.24 +	IDXGIFactory *dxgi_factory;
   13.25 +	if(adapter->GetParent(__uuidof(IDXGIFactory), (void**)&dxgi_factory) != 0) {
   13.26 +		fatal_error("failed to get IDXGIFactory pointer\n");
   13.27 +		return 0;
   13.28 +	}
   13.29 +	adapter->Release();
   13.30 +	dxgidev->Release();
   13.31 +
   13.32 +	Window *win = new Window;
   13.33 +	memset(win, 0, sizeof *win);
   13.34 +	win->must_redisplay = true;
   13.35 +	win->changed_size = true;
   13.36 +	win->width = xsz;
   13.37 +	win->height = ysz;
   13.38 +
   13.39 +	int xpos = (GetSystemMetrics(SM_CXSCREEN) - xsz) / 2;
   13.40 +	int ypos = (GetSystemMetrics(SM_CYSCREEN) - ysz) / 2;
   13.41 +	win->win = CreateWindow(WINCLASSNAME, title, WS_OVERLAPPEDWINDOW, xpos, ypos, xsz, ysz, 0, 0, GetModuleHandle(0), 0);
   13.42 +	if(!win->win) {
   13.43 +		fprintf(stderr, "failed to create window: %s\n", title);
   13.44 +		return 0;
   13.45 +	}
   13.46 +	ShowWindow(win->win, SW_SHOW);
   13.47 +
   13.48 +	unsigned int nsamples = 1;
   13.49 +	unsigned int quality = 0;
   13.50 +	if(dmflags & D3DUT_MULTISAMPLE) {
   13.51 +		nsamples = D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT;
   13.52 +		d3dut_dev->CheckMultisampleQualityLevels(DXGI_FORMAT_R8G8B8A8_UNORM, nsamples, &quality);
   13.53 +	}
   13.54 +
   13.55 +	DXGI_SWAP_CHAIN_DESC sd;
   13.56 +	memset(&sd, 0, sizeof sd);
   13.57 +	sd.OutputWindow = win->win;
   13.58 +	sd.BufferDesc.Width = xsz;
   13.59 +	sd.BufferDesc.Height = ysz;
   13.60 +	sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
   13.61 +	//sd.Stereo = (dmflags & D3DUT_STEREO) ? 1 : 0;
   13.62 +	sd.BufferDesc.RefreshRate.Numerator = 60;
   13.63 +	sd.BufferDesc.RefreshRate.Denominator = 1;
   13.64 +	sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
   13.65 +	sd.BufferCount = (dmflags & D3DUT_DOUBLE) ? 1 : 0;
   13.66 +	sd.SampleDesc.Count = nsamples;
   13.67 +	sd.SampleDesc.Quality = quality;
   13.68 +	sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
   13.69 +	sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
   13.70 +	sd.Windowed = 1;
   13.71 +
   13.72 +	if(dxgi_factory->CreateSwapChain(d3dut_dev, &sd, &win->swap) != 0) {
   13.73 +		warning("failed to create swap chain\n");
   13.74 +		return 0;
   13.75 +	}
   13.76 +	dxgi_factory->Release();
   13.77 +
   13.78 +	ID3D11Texture2D *rtex;
   13.79 +	if(win->swap->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&rtex) != 0) {
   13.80 +		warning("failed to get default render target texture\n");
   13.81 +		return 0;
   13.82 +	}
   13.83 +	if(d3dut_dev->CreateRenderTargetView(rtex, 0, &win->rtarg_view) != 0) {
   13.84 +		warning("failed to create render target view\n");
   13.85 +		rtex->Release();
   13.86 +		return 0;
   13.87 +	}
   13.88 +	rtex->Release();
   13.89 +	d3dut_ctx->OMSetRenderTargets(1, &win->rtarg_view, 0);
   13.90 +
   13.91 +	int idx = (int)windows.size();
   13.92 +	windows.push_back(win);
   13.93 +	set_active_win(idx);
   13.94 +	return idx;
   13.95 +}
   13.96 +
   13.97 +void destroy_window(int idx)
   13.98 +{
   13.99 +	if(idx < 0 || idx >= (int)windows.size()) {
  13.100 +		warning("destroy_window: invalid index: %d\n", idx);
  13.101 +		return;
  13.102 +	}
  13.103 +
  13.104 +	Window *win = windows[idx];
  13.105 +	if(win) {
  13.106 +		DestroyWindow(win->win);
  13.107 +		win->rtarg_view->Release();
  13.108 +		win->swap->Release();
  13.109 +		delete win;
  13.110 +		windows[idx] = 0;
  13.111 +	}
  13.112 +}
  13.113 +
  13.114 +void set_active_win(int idx)
  13.115 +{
  13.116 +	if(idx < 0 || idx >= (int)windows.size()) {
  13.117 +		warning("set_active_win: invalid window: %d\n", idx);
  13.118 +		return;
  13.119 +	}
  13.120 +	d3dut_rtview = windows[idx]->rtarg_view;
  13.121 +	active_win = idx;
  13.122 +}
  13.123 +
  13.124 +int get_active_win()
  13.125 +{
  13.126 +	return active_win;
  13.127 +}
  13.128 +
  13.129 +Window *get_window(int idx)
  13.130 +{
  13.131 +	if(idx < 0) {
  13.132 +		idx = active_win;
  13.133 +	}
  13.134 +	if(idx < 0 || idx >= (int)windows.size()) {
  13.135 +		return 0;
  13.136 +	}
  13.137 +	return windows[idx];
  13.138 +}
  13.139 +
  13.140 +static int find_window(HWND syswin)
  13.141 +{
  13.142 +	for(size_t i=0; i<windows.size(); i++) {
  13.143 +		if(windows[i]->win == syswin) {
  13.144 +			return i;
  13.145 +		}
  13.146 +	}
  13.147 +	return -1;
  13.148 +}
  13.149 +
  13.150 +static void mouse_handler(Window *win, int bn, bool pressed);
  13.151 +
  13.152 +long CALLBACK win_handle_event(HWND syswin, unsigned int msg, unsigned int wparam, long lparam)
  13.153 +{
  13.154 +	Window *win = 0;
  13.155 +	int winid = find_window(syswin);
  13.156 +	if(winid != -1) {
  13.157 +		set_active_win(winid);
  13.158 +		win = get_window();
  13.159 +	}
  13.160 +
  13.161 +	switch(msg) {
  13.162 +	case WM_PAINT:
  13.163 +		win->must_redisplay = true;
  13.164 +		ValidateRect(win->win, 0);
  13.165 +		break;
  13.166 +
  13.167 +	case WM_CLOSE:
  13.168 +		destroy_window(winid);
  13.169 +		break;
  13.170 +
  13.171 +	case WM_SIZE:
  13.172 +		win->width = LOWORD(lparam);
  13.173 +		win->height = HIWORD(lparam);
  13.174 +		win->changed_size = true;
  13.175 +		break;
  13.176 +
  13.177 +	case WM_KEYDOWN:
  13.178 +		if(wparam < 256) {
  13.179 +			if(win->keyboard_func) {
  13.180 +				win->keyboard_func(wparam, win->mousex, win->mousey);
  13.181 +			}
  13.182 +		} else {
  13.183 +			if(win->special_func) {
  13.184 +				win->special_func(wparam, win->mousex, win->mousey);
  13.185 +			}
  13.186 +		}
  13.187 +		break;
  13.188 +
  13.189 +	case WM_KEYUP:
  13.190 +		if(wparam < 256) {
  13.191 +			if(win->keyboard_up_func) {
  13.192 +				win->keyboard_up_func(wparam, win->mousex, win->mousey);
  13.193 +			}
  13.194 +		} else {
  13.195 +			if(win->special_up_func) {
  13.196 +				win->special_up_func(wparam, win->mousex, win->mousey);
  13.197 +			}
  13.198 +		}
  13.199 +		break;
  13.200 +
  13.201 +	case WM_MOUSEMOVE:
  13.202 +		win->mousex = LOWORD(lparam);
  13.203 +		win->mousey = HIWORD(lparam);
  13.204 +
  13.205 +		if(wparam & (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON)) {
  13.206 +			if(win->motion_func) {
  13.207 +				win->motion_func(win->mousex, win->mousey);
  13.208 +			}
  13.209 +		} else {
  13.210 +			if(win->passive_motion_func) {
  13.211 +				win->passive_motion_func(win->mousex, win->mousey);
  13.212 +			}
  13.213 +		}
  13.214 +		break;
  13.215 +
  13.216 +	case WM_LBUTTONDOWN:
  13.217 +		mouse_handler(win, D3DUT_LEFT_BUTTON, true);
  13.218 +		break;
  13.219 +	case WM_RBUTTONDOWN:
  13.220 +		mouse_handler(win, D3DUT_RIGHT_BUTTON, true);
  13.221 +		break;
  13.222 +	case WM_MBUTTONDOWN:
  13.223 +		mouse_handler(win, D3DUT_MIDDLE_BUTTON, true);
  13.224 +		break;
  13.225 +	case WM_LBUTTONUP:
  13.226 +		mouse_handler(win, D3DUT_LEFT_BUTTON, false);
  13.227 +		break;
  13.228 +	case WM_RBUTTONUP:
  13.229 +		mouse_handler(win, D3DUT_RIGHT_BUTTON, false);
  13.230 +		break;
  13.231 +	case WM_MBUTTONUP:
  13.232 +		mouse_handler(win, D3DUT_MIDDLE_BUTTON, false);
  13.233 +		break;
  13.234 +
  13.235 +	case WM_MOUSEWHEEL:
  13.236 +		{
  13.237 +			int delta = GET_WHEEL_DELTA_WPARAM(wparam);
  13.238 +			mouse_handler(win, delta < 0 ? D3DUT_WHEELDOWN_BUTTON : D3DUT_WHEELUP_BUTTON, true);
  13.239 +		}
  13.240 +		break;
  13.241 +
  13.242 +	default:
  13.243 +		return DefWindowProc(syswin, msg, wparam, lparam);
  13.244 +	}
  13.245 +
  13.246 +	return 0;
  13.247 +}
  13.248 +
  13.249 +static void mouse_handler(Window *win, int bn, bool pressed)
  13.250 +{
  13.251 +	if(win->mouse_func) {
  13.252 +		win->mouse_func(bn, pressed ? D3DUT_DOWN : D3DUT_UP, win->mousex, win->mousey);
  13.253 +	}
  13.254 +}
  13.255 \ No newline at end of file
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/src/win.h	Sat Jun 22 10:11:39 2013 +0300
    14.3 @@ -0,0 +1,42 @@
    14.4 +#ifndef D3DUT_WIN_H_
    14.5 +#define D3DUT_WIN_H_
    14.6 +
    14.7 +#include <vector>
    14.8 +#include <d3d11.h>
    14.9 +
   14.10 +#define WINCLASSNAME	"d3dutwindow"
   14.11 +
   14.12 +struct Window {
   14.13 +	HWND win;
   14.14 +	int width, height;
   14.15 +
   14.16 +	IDXGISwapChain *swap;
   14.17 +	ID3D11RenderTargetView *rtarg_view;
   14.18 +
   14.19 +	bool must_redisplay, changed_size;
   14.20 +	int mousex, mousey;
   14.21 +
   14.22 +	D3DUT_DisplayFunc display_func;
   14.23 +	D3DUT_ReshapeFunc reshape_func;
   14.24 +	D3DUT_KeyboardFunc keyboard_func;
   14.25 +	D3DUT_KeyboardUpFunc keyboard_up_func;
   14.26 +	D3DUT_SpecialFunc special_func;
   14.27 +	D3DUT_SpecialUpFunc special_up_func;
   14.28 +	D3DUT_MouseFunc mouse_func;
   14.29 +	D3DUT_MotionFunc motion_func;
   14.30 +	D3DUT_PassiveMotionFunc passive_motion_func;
   14.31 +};
   14.32 +
   14.33 +extern std::vector<Window*> windows;
   14.34 +
   14.35 +int create_window(const char *title, int xsz, int ysz, unsigned int dmflags);
   14.36 +void destroy_window(int idx);
   14.37 +
   14.38 +void set_active_win(int idx);
   14.39 +int get_active_win();
   14.40 +
   14.41 +Window *get_window(int idx = -1);
   14.42 +
   14.43 +long CALLBACK win_handle_event(HWND syswin, unsigned int msg, unsigned int wparam, long lparam);
   14.44 +
   14.45 +#endif	// D3DUT_WIN_H_
   14.46 \ No newline at end of file