Refactored d3d9 a bit
[reactos.git] / reactos / dll / directx / d3d9 / d3d9.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS ReactX
4 * FILE: dll/directx/d3d9/d3d9.c
5 * PURPOSE: d3d9.dll implementation
6 * PROGRAMERS: Magnus Olsen <greatlrd (at) reactos (dot) org>
7 * Gregor Brunmar <gregor (dot) brunmar (at) home (dot) se>
8 */
9
10 #include <d3d9.h>
11 #include "d3d9_helpers.h"
12 #include "d3d9_create.h"
13
14 #include <debug.h>
15
16 #define DEBUG_MESSAGE_BUFFER_SIZE 512
17
18 typedef IDirect3D9* (WINAPI *LPDIRECT3DCREATE9)(UINT);
19
20 static LPCSTR D3dError_WrongSdkVersion =
21 "D3D ERROR: D3D header version mismatch.\n"
22 "The application was compiled against and will only work with "
23 "D3D_SDK_VERSION (%d), but the currently installed runtime is "
24 "version (%d).\n"
25 "Recompile the application against the appropriate SDK for the installed runtime.\n"
26 "\n";
27
28 HRESULT Direct3DShaderValidatorCreate9(void)
29 {
30 UNIMPLEMENTED
31 return 0;
32 }
33
34 HRESULT PSGPError(void)
35 {
36 UNIMPLEMENTED
37 return 0;
38 }
39
40 HRESULT PSGPSampleTexture(void)
41 {
42 UNIMPLEMENTED
43 return 0;
44 }
45
46 HRESULT DebugSetLevel(void)
47 {
48 UNIMPLEMENTED
49 return 0;
50 }
51
52 HRESULT DebugSetMute(DWORD dw1)
53 {
54 UNIMPLEMENTED
55 return 0;
56 }
57
58 IDirect3D9* WINAPI Direct3DCreate9(UINT SDKVersion)
59 {
60 HINSTANCE hDebugDll;
61 DWORD LoadDebugDll;
62 DWORD LoadDebugDllSize;
63 LPDIRECT3D9 D3D9Obj = 0;
64 LPDIRECT3DCREATE9 DebugDirect3DCreate9 = 0;
65 CHAR DebugMessageBuffer[DEBUG_MESSAGE_BUFFER_SIZE];
66 UINT NoDebugSDKVersion = SDKVersion & ~DX_D3D9_DEBUG;
67
68 UNIMPLEMENTED
69
70 LoadDebugDllSize = sizeof(LoadDebugDll);
71 if (ReadRegistryValue(REG_DWORD, "LoadDebugRuntime", (LPBYTE)&LoadDebugDll, &LoadDebugDllSize))
72 {
73 if (0 != LoadDebugDll)
74 {
75 hDebugDll = LoadLibrary("d3d9d.dll");
76
77 if (0 != hDebugDll)
78 {
79 DebugDirect3DCreate9 = (LPDIRECT3DCREATE9)GetProcAddress(hDebugDll, "Direct3DCreate9");
80
81 return DebugDirect3DCreate9(SDKVersion);
82 }
83 }
84 }
85
86 if (NoDebugSDKVersion != D3D_SDK_VERSION && NoDebugSDKVersion != D3D9b_SDK_VERSION)
87 {
88 if (SDKVersion & DX_D3D9_DEBUG)
89 {
90 FormatDebugString(DebugMessageBuffer, DEBUG_MESSAGE_BUFFER_SIZE, D3dError_WrongSdkVersion, NoDebugSDKVersion, D3D_SDK_VERSION);
91 OutputDebugStringA(DebugMessageBuffer);
92 }
93
94 return NULL;
95 }
96
97 CreateD3D9(&D3D9Obj);
98
99 return D3D9Obj;
100 }
101
102 BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
103 {
104 switch (ul_reason_for_call)
105 {
106 case DLL_PROCESS_ATTACH:
107 case DLL_THREAD_ATTACH:
108 case DLL_THREAD_DETACH:
109 case DLL_PROCESS_DETACH:
110 break;
111 }
112
113 return TRUE;
114 }