Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / mesa / drivers / windows / gldirect / gld_driver.c
1 /****************************************************************************
2 *
3 *                        Mesa 3-D graphics library
4 *                        Direct3D Driver Interface
5 *
6 *  ========================================================================
7 *
8 *   Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved.
9 *
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:
16 *
17 *   The above copyright notice and this permission notice shall be included
18 *   in all copies or substantial portions of the Software.
19 *
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
26 *   SOFTWARE.
27 *
28 *  ======================================================================
29 *
30 * Language:     ANSI C
31 * Environment:  Windows 9x/2000/XP/XBox (Win32)
32 *
33 * Description:  Driver functions and interfaces
34 *
35 ****************************************************************************/
36
37 #define STRICT
38 #define WIN32_LEAN_AND_MEAN
39 #include <windows.h>
40
41 #include "gld_driver.h"
42 #include "ddlog.h"
43 #include "glheader.h"
44
45 // For glGetString().
46 #include "common_x86_asm.h"
47
48 //---------------------------------------------------------------------------
49
50 static char *szDriverError = "Driver used before initialisation!";
51
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];
55
56 static char *szVendor = "SciTech Software, Inc.";
57
58 //---------------------------------------------------------------------------
59
60 extern BOOL gldGetDXErrorString_DX(HRESULT hr, char *buf, int nBufSize);
61
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);
72
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);
83
84 //---------------------------------------------------------------------------
85 // NOP functions. Called if proper driver functions are not set.
86 //---------------------------------------------------------------------------
87
88 static BOOL _gldDriverError(void)
89 {
90         ddlogMessage(DDLOG_CRITICAL, szDriverError);
91         return FALSE;
92 }
93
94 //---------------------------------------------------------------------------
95
96 static BOOL _GetDXErrorString_ERROR(
97         HRESULT hr,
98         char *buf,
99         int nBufSize)
100 {
101         return _gldDriverError();
102 }
103
104 //---------------------------------------------------------------------------
105
106 static BOOL _CreateDrawable_ERROR(
107         DGL_ctx *ctx,
108         BOOL bPersistantInterface,
109         BOOL bPersistantBuffers)
110 {
111         return _gldDriverError();
112 }
113
114 //---------------------------------------------------------------------------
115
116 static BOOL _ResizeDrawable_ERROR(
117         DGL_ctx *ctx,
118         BOOL bDefaultDriver,
119         BOOL bPersistantInterface,
120         BOOL bPersistantBuffers)
121 {
122         return _gldDriverError();
123 }
124
125 //---------------------------------------------------------------------------
126
127 static BOOL _DestroyDrawable_ERROR(
128         DGL_ctx *ctx)
129 {
130         return _gldDriverError();
131 }
132
133 //---------------------------------------------------------------------------
134
135 static BOOL _CreatePrivateGlobals_ERROR(void)
136 {
137         return _gldDriverError();
138 }
139
140 //---------------------------------------------------------------------------
141
142 static BOOL _DestroyPrivateGlobals_ERROR(void)
143 {
144         return _gldDriverError();
145 }
146
147 //---------------------------------------------------------------------------
148
149 static BOOL _BuildPixelformatList_ERROR(void)
150 {
151         return _gldDriverError();
152 }
153
154 //---------------------------------------------------------------------------
155
156
157 static BOOL _InitialiseMesa_ERROR(
158         DGL_ctx *ctx)
159 {
160         return _gldDriverError();
161 }
162
163 //---------------------------------------------------------------------------
164
165 static BOOL     _SwapBuffers_ERROR(
166         DGL_ctx *ctx,
167         HDC hDC,
168         HWND hWnd)
169 {
170         return _gldDriverError();
171 }
172
173 //---------------------------------------------------------------------------
174
175 static PROC _GetProcAddress_ERROR(
176         LPCSTR a)
177 {
178         _gldDriverError();
179         return NULL;
180 }
181
182 //---------------------------------------------------------------------------
183
184 static BOOL     _GetDisplayMode_ERROR(
185         DGL_ctx *ctx,
186         GLD_displayMode *glddm)
187 {
188         return _gldDriverError();
189 }
190
191 //---------------------------------------------------------------------------
192 // Functions useful to all drivers
193 //---------------------------------------------------------------------------
194
195 const GLubyte* _gldGetStringGeneric(
196         struct gl_context *ctx,
197         GLenum name)
198 {
199         if (!ctx)
200                 return NULL;
201
202         switch (name) {
203         case GL_RENDERER:
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"                : "",
209                         __DATE__, __TIME__);
210                 return (const GLubyte *) _gldRendererString;
211         case GL_VENDOR:
212                 return (const GLubyte *) szVendor;
213         default:
214                 return NULL;
215         }
216 }
217
218 //---------------------------------------------------------------------------
219 // Global driver function pointers, initially set to functions that
220 // will report an error when called.
221 //---------------------------------------------------------------------------
222
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,
232         _SwapBuffers_ERROR,
233         _GetProcAddress_ERROR,
234         _GetDisplayMode_ERROR
235 };
236
237 //---------------------------------------------------------------------------
238 // Init function. Should be called as soon as regkeys/ini-settings are read.
239 //---------------------------------------------------------------------------
240
241 BOOL gldInitDriverPointers(
242         DWORD dwDriver)
243 {
244         _gldDriver.GetDXErrorString     = gldGetDXErrorString_DX;
245
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;
258                 return TRUE;
259         }
260         
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;
273                 return TRUE;
274         };
275
276         return FALSE;
277 }
278
279 //---------------------------------------------------------------------------