1 /****************************************************************************
3 * Mesa 3-D graphics library
4 * Direct3D Driver Interface
6 * ========================================================================
8 * Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved.
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
25 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 * ======================================================================
31 * Environment: Windows 9x/2000/XP/XBox (Win32)
33 * Description: Driver functions and interfaces
35 ****************************************************************************/
38 #define WIN32_LEAN_AND_MEAN
41 #include "gld_driver.h"
46 #include "common_x86_asm.h"
48 //---------------------------------------------------------------------------
50 static char *szDriverError
= "Driver used before initialisation!";
52 // This holds our dynamically created OpenGL renderer string.
53 // 256 chars should be plenty - remember that some apps display this.
54 static char _gldRendererString
[256];
56 static char *szVendor
= "SciTech Software, Inc.";
58 //---------------------------------------------------------------------------
60 extern BOOL
gldGetDXErrorString_DX(HRESULT hr
, char *buf
, int nBufSize
);
62 extern BOOL
gldCreateDrawable_MesaSW(DGL_ctx
*ctx
, BOOL bPersistantInterface
, BOOL bPersistantBuffers
);
63 extern BOOL
gldResizeDrawable_MesaSW(DGL_ctx
*ctx
, BOOL bDefaultDriver
, BOOL bPersistantInterface
, BOOL bPersistantBuffers
);
64 extern BOOL
gldDestroyDrawable_MesaSW(DGL_ctx
*ctx
);
65 extern BOOL
gldCreatePrivateGlobals_MesaSW(void);
66 extern BOOL
gldDestroyPrivateGlobals_MesaSW(void);
67 extern BOOL
gldBuildPixelformatList_MesaSW(void);
68 extern BOOL
gldInitialiseMesa_MesaSW(DGL_ctx
*ctx
);
69 extern BOOL
gldSwapBuffers_MesaSW(DGL_ctx
*ctx
, HDC hDC
, HWND hWnd
);
70 extern PROC
gldGetProcAddress_MesaSW(LPCSTR a
);
71 extern BOOL
gldGetDisplayMode_MesaSW(DGL_ctx
*ctx
, GLD_displayMode
*glddm
);
73 extern BOOL
gldCreateDrawable_DX(DGL_ctx
*ctx
, BOOL bPersistantInterface
, BOOL bPersistantBuffers
);
74 extern BOOL
gldResizeDrawable_DX(DGL_ctx
*ctx
, BOOL bDefaultDriver
, BOOL bPersistantInterface
, BOOL bPersistantBuffers
);
75 extern BOOL
gldDestroyDrawable_DX(DGL_ctx
*ctx
);
76 extern BOOL
gldCreatePrivateGlobals_DX(void);
77 extern BOOL
gldDestroyPrivateGlobals_DX(void);
78 extern BOOL
gldBuildPixelformatList_DX(void);
79 extern BOOL
gldInitialiseMesa_DX(DGL_ctx
*ctx
);
80 extern BOOL
gldSwapBuffers_DX(DGL_ctx
*ctx
, HDC hDC
, HWND hWnd
);
81 extern PROC
gldGetProcAddress_DX(LPCSTR a
);
82 extern BOOL
gldGetDisplayMode_DX(DGL_ctx
*ctx
, GLD_displayMode
*glddm
);
84 //---------------------------------------------------------------------------
85 // NOP functions. Called if proper driver functions are not set.
86 //---------------------------------------------------------------------------
88 static BOOL
_gldDriverError(void)
90 ddlogMessage(DDLOG_CRITICAL
, szDriverError
);
94 //---------------------------------------------------------------------------
96 static BOOL
_GetDXErrorString_ERROR(
101 return _gldDriverError();
104 //---------------------------------------------------------------------------
106 static BOOL
_CreateDrawable_ERROR(
108 BOOL bPersistantInterface
,
109 BOOL bPersistantBuffers
)
111 return _gldDriverError();
114 //---------------------------------------------------------------------------
116 static BOOL
_ResizeDrawable_ERROR(
119 BOOL bPersistantInterface
,
120 BOOL bPersistantBuffers
)
122 return _gldDriverError();
125 //---------------------------------------------------------------------------
127 static BOOL
_DestroyDrawable_ERROR(
130 return _gldDriverError();
133 //---------------------------------------------------------------------------
135 static BOOL
_CreatePrivateGlobals_ERROR(void)
137 return _gldDriverError();
140 //---------------------------------------------------------------------------
142 static BOOL
_DestroyPrivateGlobals_ERROR(void)
144 return _gldDriverError();
147 //---------------------------------------------------------------------------
149 static BOOL
_BuildPixelformatList_ERROR(void)
151 return _gldDriverError();
154 //---------------------------------------------------------------------------
157 static BOOL
_InitialiseMesa_ERROR(
160 return _gldDriverError();
163 //---------------------------------------------------------------------------
165 static BOOL
_SwapBuffers_ERROR(
170 return _gldDriverError();
173 //---------------------------------------------------------------------------
175 static PROC
_GetProcAddress_ERROR(
182 //---------------------------------------------------------------------------
184 static BOOL
_GetDisplayMode_ERROR(
186 GLD_displayMode
*glddm
)
188 return _gldDriverError();
191 //---------------------------------------------------------------------------
192 // Functions useful to all drivers
193 //---------------------------------------------------------------------------
195 const GLubyte
* _gldGetStringGeneric(
204 sprintf(_gldRendererString
, "GLDirect 4.0 %s%s%s%s (%s %s)",
205 _mesa_x86_cpu_features
? "/x86" : "",
206 cpu_has_mmx
? "/MMX" : "",
207 cpu_has_3dnow
? "/3DNow!" : "",
208 cpu_has_xmm
? "/SSE" : "",
210 return (const GLubyte
*) _gldRendererString
;
212 return (const GLubyte
*) szVendor
;
218 //---------------------------------------------------------------------------
219 // Global driver function pointers, initially set to functions that
220 // will report an error when called.
221 //---------------------------------------------------------------------------
223 GLD_driver _gldDriver
= {
224 _GetDXErrorString_ERROR
,
225 _CreateDrawable_ERROR
,
226 _ResizeDrawable_ERROR
,
227 _DestroyDrawable_ERROR
,
228 _CreatePrivateGlobals_ERROR
,
229 _DestroyPrivateGlobals_ERROR
,
230 _BuildPixelformatList_ERROR
,
231 _InitialiseMesa_ERROR
,
233 _GetProcAddress_ERROR
,
234 _GetDisplayMode_ERROR
237 //---------------------------------------------------------------------------
238 // Init function. Should be called as soon as regkeys/ini-settings are read.
239 //---------------------------------------------------------------------------
241 BOOL
gldInitDriverPointers(
244 _gldDriver
.GetDXErrorString
= gldGetDXErrorString_DX
;
246 if (dwDriver
== GLDS_DRIVER_MESA_SW
) {
247 // Mesa Software driver
248 _gldDriver
.CreateDrawable
= gldCreateDrawable_MesaSW
;
249 _gldDriver
.ResizeDrawable
= gldResizeDrawable_MesaSW
;
250 _gldDriver
.DestroyDrawable
= gldDestroyDrawable_MesaSW
;
251 _gldDriver
.CreatePrivateGlobals
= gldCreatePrivateGlobals_MesaSW
;
252 _gldDriver
.DestroyPrivateGlobals
= gldDestroyPrivateGlobals_MesaSW
;
253 _gldDriver
.BuildPixelformatList
= gldBuildPixelformatList_MesaSW
;
254 _gldDriver
.InitialiseMesa
= gldInitialiseMesa_MesaSW
;
255 _gldDriver
.SwapBuffers
= gldSwapBuffers_MesaSW
;
256 _gldDriver
.wglGetProcAddress
= gldGetProcAddress_MesaSW
;
257 _gldDriver
.GetDisplayMode
= gldGetDisplayMode_MesaSW
;
261 if ((dwDriver
== GLDS_DRIVER_REF
) || (dwDriver
== GLDS_DRIVER_HAL
)) {
262 // Direct3D driver, either HW or SW
263 _gldDriver
.CreateDrawable
= gldCreateDrawable_DX
;
264 _gldDriver
.ResizeDrawable
= gldResizeDrawable_DX
;
265 _gldDriver
.DestroyDrawable
= gldDestroyDrawable_DX
;
266 _gldDriver
.CreatePrivateGlobals
= gldCreatePrivateGlobals_DX
;
267 _gldDriver
.DestroyPrivateGlobals
= gldDestroyPrivateGlobals_DX
;
268 _gldDriver
.BuildPixelformatList
= gldBuildPixelformatList_DX
;
269 _gldDriver
.InitialiseMesa
= gldInitialiseMesa_DX
;
270 _gldDriver
.SwapBuffers
= gldSwapBuffers_DX
;
271 _gldDriver
.wglGetProcAddress
= gldGetProcAddress_DX
;
272 _gldDriver
.GetDisplayMode
= gldGetDisplayMode_DX
;
279 //---------------------------------------------------------------------------