소스 검색

started directx 11 support

Nicolas Cannasse 8 년 전
부모
커밋
379598bb6a

+ 16 - 1
hl.sln

@@ -1,7 +1,7 @@
 
 Microsoft Visual Studio Solution File, Format Version 12.00
 # Visual Studio 14
-VisualStudioVersion = 14.0.24720.0
+VisualStudioVersion = 14.0.25123.0
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sdl", "libs\sdl\sdl.vcxproj", "{12049F27-EA26-4A33-ADF8-E542C4167C00}"
 	ProjectSection(ProjectDependencies) = postProject
@@ -47,6 +47,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "uv", "libs\uv\uv.vcxproj",
 		{C6213FBF-BC2B-4235-A827-84A60E848C52} = {C6213FBF-BC2B-4235-A827-84A60E848C52}
 	EndProjectSection
 EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dx11", "libs\directx\directx.vcxproj", "{EC79BC9F-9947-4BCC-92F9-14F90CDE4B04}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Win32 = Debug|Win32
@@ -153,6 +155,18 @@ Global
 		{76E4DB00-8114-4B96-BA76-39D800F8D5EE}.ReleaseVS2013|Win32.Build.0 = ReleaseVS2013|Win32
 		{76E4DB00-8114-4B96-BA76-39D800F8D5EE}.ReleaseVS2013|x64.ActiveCfg = ReleaseVS2013|x64
 		{76E4DB00-8114-4B96-BA76-39D800F8D5EE}.ReleaseVS2013|x64.Build.0 = ReleaseVS2013|x64
+		{EC79BC9F-9947-4BCC-92F9-14F90CDE4B04}.Debug|Win32.ActiveCfg = Debug|Win32
+		{EC79BC9F-9947-4BCC-92F9-14F90CDE4B04}.Debug|Win32.Build.0 = Debug|Win32
+		{EC79BC9F-9947-4BCC-92F9-14F90CDE4B04}.Debug|x64.ActiveCfg = Debug|x64
+		{EC79BC9F-9947-4BCC-92F9-14F90CDE4B04}.Debug|x64.Build.0 = Debug|x64
+		{EC79BC9F-9947-4BCC-92F9-14F90CDE4B04}.Release|Win32.ActiveCfg = Release|Win32
+		{EC79BC9F-9947-4BCC-92F9-14F90CDE4B04}.Release|Win32.Build.0 = Release|Win32
+		{EC79BC9F-9947-4BCC-92F9-14F90CDE4B04}.Release|x64.ActiveCfg = Release|x64
+		{EC79BC9F-9947-4BCC-92F9-14F90CDE4B04}.Release|x64.Build.0 = Release|x64
+		{EC79BC9F-9947-4BCC-92F9-14F90CDE4B04}.ReleaseVS2013|Win32.ActiveCfg = ReleaseVS2013|Win32
+		{EC79BC9F-9947-4BCC-92F9-14F90CDE4B04}.ReleaseVS2013|Win32.Build.0 = ReleaseVS2013|Win32
+		{EC79BC9F-9947-4BCC-92F9-14F90CDE4B04}.ReleaseVS2013|x64.ActiveCfg = ReleaseVS2013|x64
+		{EC79BC9F-9947-4BCC-92F9-14F90CDE4B04}.ReleaseVS2013|x64.Build.0 = ReleaseVS2013|x64
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -164,5 +178,6 @@ Global
 		{43AAD9DB-4708-46B6-AAE8-A5DB95A0B573} = {0EC4330B-6B61-45F8-B297-CA7097AFFD98}
 		{F4D939D6-88D6-4FF2-874A-7BECF75A01C2} = {0EC4330B-6B61-45F8-B297-CA7097AFFD98}
 		{76E4DB00-8114-4B96-BA76-39D800F8D5EE} = {0EC4330B-6B61-45F8-B297-CA7097AFFD98}
+		{EC79BC9F-9947-4BCC-92F9-14F90CDE4B04} = {0EC4330B-6B61-45F8-B297-CA7097AFFD98}
 	EndGlobalSection
 EndGlobal

+ 90 - 0
libs/directx/directx.cpp

@@ -0,0 +1,90 @@
+#define HL_NAME(n) directx_##n
+#include <hl.h>
+
+#include <dxgi.h>
+#include <d3dcommon.h>
+#include <d3d11.h>
+#include <DirectXMath.h>
+
+#define INIT_ERROR __LINE__
+#define CHECK(call) if( (call) != S_OK ) return INIT_ERROR
+
+typedef struct {
+	IDXGIFactory *factory;
+	ID3D11Device *device;
+	ID3D11DeviceContext *context;
+	IDXGISwapChain *swapchain;
+	ID3D11RenderTargetView *renderTarget;
+	D3D_FEATURE_LEVEL feature;
+	int init_flags;
+} dx_driver;
+
+static dx_driver *driver = NULL;
+
+HL_PRIM dx_driver *HL_NAME(dx_create)( HWND window, int flags ) {
+	DWORD result;
+	static D3D_FEATURE_LEVEL levels[] = {
+		D3D_FEATURE_LEVEL_11_1,
+		D3D_FEATURE_LEVEL_11_0,
+		D3D_FEATURE_LEVEL_10_1,
+		D3D_FEATURE_LEVEL_10_0,
+		D3D_FEATURE_LEVEL_9_3,
+		D3D_FEATURE_LEVEL_9_2,
+		D3D_FEATURE_LEVEL_9_1,
+	};
+	dx_driver *d = (dx_driver*)hl_gc_alloc_noptr(sizeof(dx_driver));
+	ZeroMemory(d,sizeof(dx_driver));
+
+	d->init_flags = flags;
+	result = D3D11CreateDevice(NULL,D3D_DRIVER_TYPE_HARDWARE,NULL,flags,levels,7,D3D11_SDK_VERSION,&d->device,&d->feature,&d->context);
+	if( result == E_INVALIDARG ) // most likely no DX11.1 support, try again
+		result = D3D11CreateDevice(NULL,D3D_DRIVER_TYPE_HARDWARE,NULL,flags,NULL,0,D3D11_SDK_VERSION,&d->device,&d->feature,&d->context);
+	if( result != S_OK )
+		return NULL;
+
+	// create the SwapChain
+	DXGI_SWAP_CHAIN_DESC desc;
+	RECT r;
+	GetClientRect(window,&r);
+	ZeroMemory(&desc,sizeof(desc));
+	desc.BufferDesc.Width = r.right;
+	desc.BufferDesc.Height = r.bottom;
+	desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
+	desc.SampleDesc.Count = 1; // NO AA for now
+	desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
+	desc.BufferCount = 1;
+	desc.Windowed = true;
+	desc.OutputWindow = window;
+	if( CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&d->factory) != S_OK )
+		return NULL;
+	if( d->factory->CreateSwapChain(d->device,&desc,&d->swapchain) != S_OK )
+		return NULL;
+
+	// create the backbuffer
+	ID3D11Texture2D *backBuffer;
+	if( d->swapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBuffer) != S_OK )
+		return NULL;
+	if( d->device->CreateRenderTargetView(backBuffer, NULL, &d->renderTarget) != S_OK )
+		return NULL;
+	backBuffer->Release();
+	driver = d;
+	return d;
+}
+
+HL_PRIM void HL_NAME(dx_clear_color)( double r, double g, double b, double a ) {
+	float color[4];
+	color[0] = (float)r;
+	color[1] = (float)g;
+	color[2] = (float)b;
+	color[3] = (float)a;
+	driver->context->ClearRenderTargetView(driver->renderTarget,color);
+}
+
+HL_PRIM void HL_NAME(dx_present)() {
+	driver->swapchain->Present(0,0);
+}
+
+#define _DRIVER _ABSTRACT(dx_driver)
+DEFINE_PRIM(_DRIVER, dx_create, _ABSTRACT(dx_window) _I32);
+DEFINE_PRIM(_VOID, dx_clear_color, _F64 _F64 _F64 _F64);
+DEFINE_PRIM(_VOID, dx_present, _NO_ARG);

+ 246 - 0
libs/directx/directx.vcxproj

@@ -0,0 +1,246 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="ReleaseVS2013|Win32">
+      <Configuration>ReleaseVS2013</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="ReleaseVS2013|x64">
+      <Configuration>ReleaseVS2013</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="directx.cpp" />
+    <ClCompile Include="window.c" />
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{EC79BC9F-9947-4BCC-92F9-14F90CDE4B04}</ProjectGuid>
+    <Keyword>Win32Proj</Keyword>
+    <RootNamespace>directx</RootNamespace>
+    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseVS2013|Win32'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v120</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v140</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseVS2013|x64'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v120</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="Shared">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseVS2013|Win32'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseVS2013|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <LinkIncremental>true</LinkIncremental>
+    <TargetExt>.hdll</TargetExt>
+    <LibraryPath>$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86;../../$(Configuration)</LibraryPath>
+    <IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);../../src</IncludePath>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <LinkIncremental>true</LinkIncremental>
+    <TargetExt>.hdll</TargetExt>
+    <LibraryPath>$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64;../../x64/$(Configuration)</LibraryPath>
+    <IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);../../src</IncludePath>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <LinkIncremental>false</LinkIncremental>
+    <TargetExt>.hdll</TargetExt>
+    <LibraryPath>$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86;../../$(Configuration)</LibraryPath>
+    <IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);../../src</IncludePath>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseVS2013|Win32'">
+    <LinkIncremental>false</LinkIncremental>
+    <TargetExt>.hdll</TargetExt>
+    <LibraryPath>$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86;../../$(Configuration)</LibraryPath>
+    <IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);../../src</IncludePath>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <LinkIncremental>false</LinkIncremental>
+    <TargetExt>.hdll</TargetExt>
+    <LibraryPath>$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64;../../x64/$(Configuration)</LibraryPath>
+    <IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);../../src</IncludePath>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseVS2013|x64'">
+    <LinkIncremental>false</LinkIncremental>
+    <TargetExt>.hdll</TargetExt>
+    <LibraryPath>$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64;../../x64/$(Configuration)</LibraryPath>
+    <IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);../../src</IncludePath>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;DIRECTX_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <OutputFile>../../$(Configuration)/$(TargetName).hdll</OutputFile>
+      <AdditionalDependencies>libhl.lib;user32.lib;gdi32.lib;d3d11.lib;dxgi.lib</AdditionalDependencies>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>_DEBUG;_WINDOWS;_USRDLL;DIRECTX_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>libhl.lib;user32.lib;gdi32.lib</AdditionalDependencies>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;DIRECTX_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <OutputFile>../../$(Configuration)/$(TargetName).hdll</OutputFile>
+      <AdditionalDependencies>libhl.lib</AdditionalDependencies>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseVS2013|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;DIRECTX_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <OutputFile>../../$(Configuration)/$(TargetName).hdll</OutputFile>
+      <AdditionalDependencies>libhl.lib</AdditionalDependencies>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>NDEBUG;_WINDOWS;_USRDLL;DIRECTX_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>libhl.lib</AdditionalDependencies>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseVS2013|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>NDEBUG;_WINDOWS;_USRDLL;DIRECTX_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>libhl.lib</AdditionalDependencies>
+    </Link>
+  </ItemDefinitionGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>

+ 7 - 0
libs/directx/directx.vcxproj.filters

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <ClCompile Include="window.c" />
+    <ClCompile Include="directx.cpp" />
+  </ItemGroup>
+</Project>

+ 36 - 0
libs/directx/dx/Driver.hx

@@ -0,0 +1,36 @@
+package dx;
+
+enum DriverInitFlag {
+	SingleThread;
+	DebugLayer;
+	SwitchToRef;
+	PreventInternalThreadingOptimizations;
+	Unused1;
+	BgraSupport;
+	Debuggable;
+	PreventAlteringLayerSettingsFromRegistry;
+	DisableGpuTimeout;
+	Unused2;
+	Unused3;
+	VideoSupport;
+}
+
+typedef DriverInstance = hl.Abstract<"dx_driver">;
+
+@:hlNative("directx","dx_")
+class Driver {
+
+	public static function create( win : Window, ?flags : haxe.EnumFlags<DriverInitFlag> ) {
+		return dxCreate(@:privateAccess win.win, flags == null ? 0 : flags.toInt());
+	}
+
+	public static function clearColor( r : Float, g : Float, b : Float, a : Float ) {
+	}
+
+	public static function present() {
+	}
+
+	@:hlNative("directx","dx_create")
+	static function dxCreate( win : hl.Abstract < "dx_window" > , flags : Int ) : DriverInstance { return null; }
+
+}

+ 45 - 0
libs/directx/dx/Event.hx

@@ -0,0 +1,45 @@
+package dx;
+
+@:keep class Event {
+	public var type : EventType;
+	public var mouseX : Int;
+	public var mouseY : Int;
+	public var button : Int;
+	public var wheelDelta : Int;
+	public var state : WindowStateChange;
+	public var keyCode : Int;
+	public var keyRepeat : Bool;
+	public var controller : Int;
+	public var value : Int;
+	public function new() {
+	}
+}
+
+@:enum abstract EventType(Int) {
+	var Quit		= 0;
+	var MouseMove	= 1;
+	var MouseLeave	= 2;
+	var MouseDown	= 3;
+	var MouseUp		= 4;
+	var MouseWheel	= 5;
+	var WindowState	= 6;
+	var KeyDown		= 7;
+	var KeyUp		= 8;
+	var TextInput	= 9;
+}
+
+@:enum abstract WindowStateChange(Int) {
+	var Show	= 0;
+	var Hide	= 1;
+	var Expose	= 2;
+	var Move	= 3;
+	var Resize	= 4;
+	var Minimize= 5;
+	var Maximize= 6;
+	var Restore	= 7;
+	var Enter	= 8;
+	var Leave	= 9;
+	var Focus	= 10;
+	var Blur	= 11;
+	var Close 	= 12;
+}

+ 112 - 0
libs/directx/dx/Loop.hx

@@ -0,0 +1,112 @@
+package dx;
+
+class Loop {
+
+	static var sentinel : hl.UI.Sentinel;
+	static var dismissErrors = false;
+
+	public static var defaultEventHandler : Event -> Void;
+
+	/**
+		Prevent the program from reporting timeout infinite loop.
+	**/
+	public static function tick() {
+		sentinel.tick();
+	}
+
+	//@:hlNative TODO !
+	static function eventLoop( e : Event ) return false;
+
+	public static function processEvents() {
+		var event = new Event();
+		while( true ) {
+			if( !eventLoop(event) )
+				break;
+			if( event.type == Quit )
+				return false;
+			defaultEventHandler(event);
+		}
+		return true;
+	}
+
+	public static function run( callb : Void -> Void, ?onEvent : Event -> Void ) {
+		var event = new Event();
+		if( onEvent == null ) onEvent = defaultEventHandler;
+		while( true ) {
+			// process windows message
+			while( true ) {
+				switch( hl.UI.loop(false) ) {
+				case NoMessage:
+					break;
+				case HandledMessage:
+					continue;
+				case Quit:
+					return;
+				}
+			}
+			// retreive captured events
+			while( true ) {
+				if( !eventLoop(event) )
+					break;
+				if( event.type == Quit )
+					return;
+				if( onEvent != null ) {
+					try {
+						onEvent(event);
+					} catch( e : Dynamic ) {
+						reportError(e);
+					}
+				}
+			}
+			// callback our events handlers
+			try {
+				callb();
+			} catch( e : Dynamic ) {
+				reportError(e);
+			}
+			tick();
+        }
+	}
+
+	public dynamic static function reportError( e : Dynamic ) {
+
+		var stack = haxe.CallStack.toString(haxe.CallStack.exceptionStack());
+		var err = try Std.string(e) catch( _ : Dynamic ) "????";
+		Sys.println(err + stack);
+
+		if( dismissErrors )
+			return;
+
+		var f = new hl.UI.WinLog("Uncaught Exception", 500, 400);
+		f.setTextContent(err+"\n"+stack);
+		var but = new hl.UI.Button(f, "Continue");
+		but.onClick = function() {
+			hl.UI.stopLoop();
+		};
+
+		var but = new hl.UI.Button(f, "Dismiss all");
+		but.onClick = function() {
+			dismissErrors = true;
+			hl.UI.stopLoop();
+		};
+
+		var but = new hl.UI.Button(f, "Exit");
+		but.onClick = function() {
+			Sys.exit(0);
+		};
+
+		while( hl.UI.loop(true) != Quit )
+			tick();
+		f.destroy();
+	}
+
+	static function onTimeout() {
+		throw "Program timeout (infinite loop?)";
+	}
+
+	static function __init__() {
+		hl.Api.setErrorHandler(function(e) reportError(e));
+		sentinel = new hl.UI.Sentinel(30,onTimeout);
+	}
+
+}

+ 120 - 0
libs/directx/dx/Window.hx

@@ -0,0 +1,120 @@
+package dx;
+import haxe.EntryPoint;
+
+private typedef WinPtr = hl.Abstract<"dx_window">;
+
+@:enum abstract DisplayMode(Int) {
+	var Windowed = 0;
+	var Fullscreen = 1;
+	/**
+		Fullscreen not exclusive.
+	**/
+	var Borderless = 2;
+	var FullscreenResize = 3;
+}
+
+@:hlNative("directx")
+class Window {
+
+	static var windows : Array<Window> = [];
+
+	var win : WinPtr;
+	public var title(default, set) : String;
+	public var vsync(default, set) : Bool;
+	public var width(get, never) : Int;
+	public var height(get, never) : Int;
+	public var displayMode(default, set) : DisplayMode;
+
+	public function new( title : String, width : Int, height : Int ) {
+		win = winCreate(width, height);
+		this.title = title;
+		windows.push(this);
+		vsync = true;
+	}
+
+	function set_title(name:String) {
+		winSetTitle(win, @:privateAccess name.bytes);
+		return title = name;
+	}
+
+	function set_displayMode(mode) {
+		if( mode == displayMode )
+			return mode;
+		if( winSetFullscreen(win, cast mode) )
+			displayMode = mode;
+		return displayMode;
+	}
+
+	public function resize( width : Int, height : Int ) {
+		winSetSize(win, width, height);
+	}
+
+	function get_width() {
+		var w = 0;
+		winGetSize(win, w, null);
+		return w;
+	}
+
+	function get_height() {
+		var h = 0;
+		winGetSize(win, null, h);
+		return h;
+	}
+
+	function set_vsync(v) {
+		winSetVsync(win,v);
+		return vsync = v;
+	}
+
+	public function present() {
+		winSwapWindow(win);
+	}
+
+	public function destroy() {
+		winDestroy(win);
+		win = null;
+		windows.remove(this);
+	}
+
+	public function maximize() {
+		winResize(win, 0);
+	}
+
+	public function minimize() {
+		winResize(win, 1);
+	}
+
+	public function restore() {
+		winResize(win, 2);
+	}
+
+	static function winCreate( width : Int, height : Int ) : WinPtr {
+		return null;
+	}
+
+	static function winSetTitle( win : WinPtr, title : hl.Bytes ) {
+	}
+
+	static function winSwapWindow( win : WinPtr ) {
+	}
+
+	static function winSetFullscreen( win : WinPtr, mode : DisplayMode ) {
+		return false;
+	}
+
+	static function winSetSize( win : WinPtr, width : Int, height : Int ) {
+	}
+
+	static function winResize( win : WinPtr, mode : Int ) {
+	}
+
+	static function winGetSize( win : WinPtr, width : hl.Ref<Int>, height : hl.Ref<Int> ) {
+	}
+
+	static function winDestroy( win : WinPtr ) {
+	}
+
+	static function winSetVsync( win : WinPtr, b : Bool ) {
+	}
+
+}

+ 77 - 0
libs/directx/haxe/EntryPoint.hx

@@ -0,0 +1,77 @@
+package haxe;
+
+private class Lock {
+	public function new() {
+	}
+	public inline function release() {
+	}
+	public inline function wait( ?t : Float ) {
+	}
+}
+private class Mutex {
+	public function new() {
+	}
+	public inline function acquire() {
+	}
+	public inline function release() {
+	}
+}
+private class Thread {
+	public static function create( f : Void -> Void ) {
+		f();
+	}
+}
+
+class EntryPoint {
+
+	static var sleepLock = new Lock();
+	static var mutex = new Mutex();
+	static var pending = new Array<Void->Void>();
+
+	public static var threadCount(default,null) : Int = 0;
+
+	public static function wakeup() {
+		#if sys
+		sleepLock.release();
+		#end
+	}
+
+	public static function runInMainThread( f : Void -> Void ) {
+		mutex.acquire();
+		pending.push(f);
+		mutex.release();
+		wakeup();
+	}
+
+	public static function addThread( f : Void -> Void ) {
+		mutex.acquire();
+		threadCount++;
+		mutex.release();
+		Thread.create(function() {
+			f();
+			mutex.acquire();
+			threadCount--;
+			if( threadCount == 0 ) wakeup();
+			mutex.release();
+		});
+	}
+
+	static function processEvents() : Float {
+		// flush all pending calls
+		while( true ) {
+			mutex.acquire();
+			var f = pending.shift();
+			mutex.release();
+			if( f == null ) break;
+			f();
+		}
+		if( !MainLoop.hasEvents() && threadCount == 0 )
+			return -1;
+		return @:privateAccess MainLoop.tick();
+	}
+
+	@:keep public static function run() @:privateAccess {
+		dx.Loop.run(processEvents);
+	}
+
+}

+ 116 - 0
libs/directx/window.c

@@ -0,0 +1,116 @@
+#define HL_NAME(n) directx_##n
+#include <hl.h>
+
+typedef struct HWND__ dx_window;
+
+static LRESULT CALLBACK WndProc( HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam ) {
+	switch(umsg) {
+	case WM_DESTROY:
+		PostQuitMessage(0);
+		return 0;
+	default:
+		return DefWindowProc(hwnd, umsg, wparam, lparam);
+	}
+}
+
+HL_PRIM dx_window *HL_NAME(win_create)( int width, int height ) {
+	static bool wnd_class_reg = false;
+	if( !wnd_class_reg ) {
+		WNDCLASSEX wc;
+		wc.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
+		wc.lpfnWndProc   = WndProc;
+		wc.cbClsExtra    = 0;
+		wc.cbWndExtra    = 0;
+		wc.hInstance     = GetModuleHandle(NULL);
+		wc.hIcon		 = LoadIcon(NULL, IDI_WINLOGO);
+		wc.hIconSm       = wc.hIcon;
+		wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
+		wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
+		wc.lpszMenuName  = NULL;
+		wc.lpszClassName = USTR("HL_WIN");
+		wc.cbSize        = sizeof(WNDCLASSEX);
+		RegisterClassEx(&wc);
+	}
+
+	RECT r;
+	DWORD style = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
+	r.left = r.top = 0;
+	r.right = width;
+	r.bottom = height;
+	AdjustWindowRect(&r,style,false);
+	dx_window *win = CreateWindowEx(WS_EX_APPWINDOW, USTR("HL_WIN"), USTR(""), style, CW_USEDEFAULT, CW_USEDEFAULT, r.right - r.left, r.bottom - r.top, NULL, NULL, GetModuleHandle(NULL), NULL);
+	ShowWindow(win, SW_SHOW);
+	SetForegroundWindow(win);
+	SetFocus(win);
+	return win;
+}
+
+HL_PRIM void HL_NAME(win_set_title)(dx_window *win, vbyte *title) {
+	SetWindowText(win,(LPCWSTR)title);
+}
+
+HL_PRIM void HL_NAME(win_set_size)(dx_window *win, int width, int height) {
+	RECT r;
+	GetWindowRect(win,&r);
+	r.left = r.top = 0;
+	r.right = width;
+	r.bottom = height;
+	AdjustWindowRectEx(&r,GetWindowLong(win,GWL_STYLE),GetMenu(win) != NULL,GetWindowLong(win,GWL_EXSTYLE));
+	SetWindowPos(win,NULL,0,0,r.right - r.left,r.bottom - r.top,SWP_NOMOVE|SWP_NOOWNERZORDER);
+}
+
+HL_PRIM void HL_NAME(win_get_size)(dx_window *win, int *width, int *height) {
+	RECT r;
+	GetClientRect(win,&r);
+	*width = r.right;
+	*height = r.bottom;
+}
+
+HL_PRIM void HL_NAME(win_resize)(dx_window *win, int mode) {
+	switch( mode ) {
+	case 0:
+		ShowWindow(win, SW_MAXIMIZE);
+		break;
+	case 1:
+		ShowWindow(win, SW_MINIMIZE);
+		break;
+	case 2:
+		ShowWindow(win, SW_RESTORE);
+		break;
+	default:
+		break;
+	}
+}
+
+
+HL_PRIM bool HL_NAME(win_set_fullscreen)(dx_window *win, int mode) {
+	switch( mode ) {
+	case 0: // WINDOWED
+	case 1: // FULLSCREEN
+	case 2: // BORDERLESS
+		;
+	}
+	return false;
+}
+
+HL_PRIM void HL_NAME(win_swap_window)(dx_window *win) {
+}
+
+HL_PRIM void HL_NAME(win_destroy)(dx_window *win) {
+	DestroyWindow(win);
+}
+
+HL_PRIM void HL_NAME(win_set_vsync)(dx_window *win, bool vsync) {
+}
+
+#define TWIN _ABSTRACT(dx_window)
+DEFINE_PRIM(TWIN, win_create, _I32 _I32);
+DEFINE_PRIM(_BOOL, win_set_fullscreen, TWIN _I32);
+DEFINE_PRIM(_VOID, win_resize, TWIN _I32);
+DEFINE_PRIM(_VOID, win_set_title, TWIN _BYTES);
+DEFINE_PRIM(_VOID, win_set_size, TWIN _I32 _I32);
+DEFINE_PRIM(_VOID, win_get_size, TWIN _REF(_I32) _REF(_I32));
+DEFINE_PRIM(_VOID, win_swap_window, TWIN);
+DEFINE_PRIM(_VOID, win_destroy, TWIN);
+DEFINE_PRIM(_VOID, win_set_vsync, TWIN _BOOL);
+