Selaa lähdekoodia

a bit more work on directx

Nicolas Cannasse 8 vuotta sitten
vanhempi
commit
2b0abe614d

+ 34 - 4
libs/directx/directx.cpp

@@ -10,7 +10,6 @@
 #define CHECK(call) if( (call) != S_OK ) return INIT_ERROR
 
 typedef struct {
-	IDXGIFactory *factory;
 	ID3D11Device *device;
 	ID3D11DeviceContext *context;
 	IDXGISwapChain *swapchain;
@@ -20,6 +19,13 @@ typedef struct {
 } dx_driver;
 
 static dx_driver *driver = NULL;
+static IDXGIFactory *factory = NULL;
+
+static IDXGIFactory *GetDXGI() {
+	if( factory == NULL && CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory) != S_OK )
+		hl_error("Failed to init DXGI");
+	return factory;
+}
 
 HL_PRIM dx_driver *HL_NAME(dx_create)( HWND window, int flags ) {
 	DWORD result;
@@ -55,9 +61,7 @@ HL_PRIM dx_driver *HL_NAME(dx_create)( HWND window, int flags ) {
 	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 )
+	if( GetDXGI()->CreateSwapChain(d->device,&desc,&d->swapchain) != S_OK )
 		return NULL;
 
 	// create the backbuffer
@@ -84,7 +88,33 @@ HL_PRIM void HL_NAME(dx_present)() {
 	driver->swapchain->Present(0,0);
 }
 
+HL_PRIM int HL_NAME(dx_get_screen_width)() {
+	return GetSystemMetrics(SM_CXSCREEN);
+}
+
+HL_PRIM int HL_NAME(dx_get_screen_height)() {
+	return GetSystemMetrics(SM_CYSCREEN);
+}
+
+HL_PRIM const uchar *HL_NAME(dx_get_device_name)() {
+	IDXGIAdapter *adapter;
+	DXGI_ADAPTER_DESC desc;
+	if( GetDXGI()->EnumAdapters(0,&adapter) != S_OK || adapter->GetDesc(&desc) != S_OK )
+		return USTR("Unknown");
+	adapter->Release();
+	return (uchar*)hl_copy_bytes((vbyte*)desc.Description,(ustrlen((uchar*)desc.Description)+1)*2);
+}
+
+HL_PRIM double HL_NAME(dx_get_supported_version)() {
+	if( driver == NULL ) return 0.;
+	return (driver->feature >> 12) + ((driver->feature & 0xFFF) / 2560.);
+}
+
 #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);
+DEFINE_PRIM(_I32, dx_get_screen_width, _NO_ARG);
+DEFINE_PRIM(_I32, dx_get_screen_height, _NO_ARG);
+DEFINE_PRIM(_BYTES, dx_get_device_name, _NO_ARG);
+DEFINE_PRIM(_F64, dx_get_supported_version, _NO_ARG);

+ 5 - 5
libs/directx/directx.vcxproj

@@ -163,7 +163,7 @@
     <Link>
       <SubSystem>Windows</SubSystem>
       <GenerateDebugInformation>true</GenerateDebugInformation>
-      <AdditionalDependencies>libhl.lib;user32.lib;gdi32.lib</AdditionalDependencies>
+      <AdditionalDependencies>libhl.lib;user32.lib;gdi32.lib;d3d11.lib;dxgi.lib</AdditionalDependencies>
     </Link>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -182,7 +182,7 @@
       <OptimizeReferences>true</OptimizeReferences>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <OutputFile>../../$(Configuration)/$(TargetName).hdll</OutputFile>
-      <AdditionalDependencies>libhl.lib</AdditionalDependencies>
+      <AdditionalDependencies>libhl.lib;user32.lib;gdi32.lib;d3d11.lib;dxgi.lib</AdditionalDependencies>
     </Link>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseVS2013|Win32'">
@@ -201,7 +201,7 @@
       <OptimizeReferences>true</OptimizeReferences>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <OutputFile>../../$(Configuration)/$(TargetName).hdll</OutputFile>
-      <AdditionalDependencies>libhl.lib</AdditionalDependencies>
+      <AdditionalDependencies>libhl.lib;user32.lib;gdi32.lib;d3d11.lib;dxgi.lib</AdditionalDependencies>
     </Link>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@@ -219,7 +219,7 @@
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <OptimizeReferences>true</OptimizeReferences>
       <GenerateDebugInformation>true</GenerateDebugInformation>
-      <AdditionalDependencies>libhl.lib</AdditionalDependencies>
+      <AdditionalDependencies>libhl.lib;user32.lib;gdi32.lib;d3d11.lib;dxgi.lib</AdditionalDependencies>
     </Link>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseVS2013|x64'">
@@ -237,7 +237,7 @@
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <OptimizeReferences>true</OptimizeReferences>
       <GenerateDebugInformation>true</GenerateDebugInformation>
-      <AdditionalDependencies>libhl.lib</AdditionalDependencies>
+      <AdditionalDependencies>libhl.lib;user32.lib;gdi32.lib;d3d11.lib;dxgi.lib</AdditionalDependencies>
     </Link>
   </ItemDefinitionGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

+ 51 - 0
libs/directx/dx/Cursor.hx

@@ -0,0 +1,51 @@
+package dx;
+
+private typedef CursorPtr = hl.Abstract<"dx_cursor">;
+
+@:enum abstract CursorKind(Int) {
+	var Arrow = 0;
+    var IBeam = 1;
+    var Wait = 2;
+    var CrossHair = 3;
+    var WaitArrow = 4;
+    var SizeNWSE = 5;
+    var SizeNESW = 6;
+    var SizeWE = 7;
+    var SizeNS = 8;
+    var SizeALL = 9;
+    var No = 10;
+    var Hand = 11;
+}
+
+//@:hlNative("dx")
+abstract Cursor(CursorPtr) {
+
+	//@:hlNative("dx", "cursor_create_system")
+	public static function createSystem( kind : CursorKind ) : Cursor {
+		return null;
+	}
+
+	public function free() {
+		freeCursor(this);
+	}
+
+	public function set() {
+		setCursor(this);
+	}
+
+	//@:hlNative("dx", "show_cursor")
+	public static function show( v : Bool ) {
+	}
+
+	//@:hlNative("dx", "set_cursor")
+	static function setCursor( k : CursorPtr ) {
+	}
+
+	static function createSystemCursor( kind : CursorKind ) : CursorPtr {
+		return null;
+	}
+
+	static function freeCursor( ptr : CursorPtr ) {
+	}
+
+}

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

@@ -30,7 +30,25 @@ class Driver {
 	public static function present() {
 	}
 
+	public static function getDeviceName() {
+		return @:privateAccess String.fromUCS2(dxGetDeviceName());
+	}
+
+	public static function getScreenWidth() {
+		return 0;
+	}
+
+	public static function getScreenHeight() {
+		return 0;
+	}
+
+	public static function getSupportedVersion() : Float {
+		return 0.;
+	}
+
 	@:hlNative("directx","dx_create")
 	static function dxCreate( win : hl.Abstract < "dx_window" > , flags : Int ) : DriverInstance { return null; }
+	@:hlNative("directx","dx_get_device_name")
+	static function dxGetDeviceName() : hl.Bytes { return null; }
 
 }

+ 10 - 0
libs/directx/haxelib.json

@@ -0,0 +1,10 @@
+{
+	"name" : "hldx",
+	"url" : "https://github.com/HaxeFoundation/hl/tree/master/libs/directx",
+	"license" : "BSD",
+	"contributors" : ["ncannasse"],
+	"description" : "DirectX support for Haxe/HL.",
+	"version" : "1.0.0",
+	"releasenote" : "",
+	"dependencies": { "hlopenal" : "" }
+}