Merge branch 'mesa_7_7_branch'
[mesa.git] / src / mesa / drivers / windows / gldirect / dx8 / gld_driver_dx8.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 interface code to Mesa
34 *
35 ****************************************************************************/
36
37 //#include <windows.h>
38 #include "dglcontext.h"
39 #include "ddlog.h"
40 #include "gld_dx8.h"
41
42 #include "glheader.h"
43 #include "context.h"
44 #include "colormac.h"
45 #include "depth.h"
46 #include "extensions.h"
47 #include "macros.h"
48 #include "matrix.h"
49 // #include "mem.h"
50 //#include "mmath.h"
51 #include "mtypes.h"
52 #include "texformat.h"
53 #include "teximage.h"
54 #include "texstore.h"
55 #include "vbo/vbo.h"
56 #include "swrast_setup/swrast_setup.h"
57 #include "swrast_setup/ss_context.h"
58 #include "tnl/tnl.h"
59 #include "tnl/t_context.h"
60 #include "tnl/t_pipeline.h"
61
62 extern BOOL dglSwapBuffers(HDC hDC);
63
64 // HACK: Hack the _33 member of the OpenGL perspective projection matrix
65 const float _fPersp_33 = 1.6f;
66
67 //---------------------------------------------------------------------------
68 // Internal functions
69 //---------------------------------------------------------------------------
70
71 void _gld_mesa_warning(
72 __GLcontext *gc,
73 char *str)
74 {
75 // Intercept Mesa's internal warning mechanism
76 gldLogPrintf(GLDLOG_WARN, "Mesa warning: %s", str);
77 }
78
79 //---------------------------------------------------------------------------
80
81 void _gld_mesa_fatal(
82 __GLcontext *gc,
83 char *str)
84 {
85 // Intercept Mesa's internal fatal-message mechanism
86 gldLogPrintf(GLDLOG_CRITICAL, "Mesa FATAL: %s", str);
87
88 // Mesa calls abort(0) here.
89 ddlogClose();
90 exit(0);
91 }
92
93 //---------------------------------------------------------------------------
94
95 D3DSTENCILOP _gldConvertStencilOp(
96 GLenum StencilOp)
97 {
98 // Used by Stencil: pass, fail and zfail
99
100 switch (StencilOp) {
101 case GL_KEEP:
102 return D3DSTENCILOP_KEEP;
103 case GL_ZERO:
104 return D3DSTENCILOP_ZERO;
105 case GL_REPLACE:
106 return D3DSTENCILOP_REPLACE;
107 case GL_INCR:
108 return D3DSTENCILOP_INCRSAT;
109 case GL_DECR:
110 return D3DSTENCILOP_DECRSAT;
111 case GL_INVERT:
112 return D3DSTENCILOP_INVERT;
113 case GL_INCR_WRAP_EXT: // GL_EXT_stencil_wrap
114 return D3DSTENCILOP_INCR;
115 case GL_DECR_WRAP_EXT: // GL_EXT_stencil_wrap
116 return D3DSTENCILOP_DECR;
117 }
118
119 #ifdef _DEBUG
120 gldLogMessage(GLDLOG_ERROR, "_gldConvertStencilOp: Unknown StencilOp\n");
121 #endif
122
123 return D3DSTENCILOP_KEEP;
124 }
125
126 //---------------------------------------------------------------------------
127
128 D3DCMPFUNC _gldConvertCompareFunc(
129 GLenum CmpFunc)
130 {
131 // Used for Alpha func, depth func and stencil func.
132
133 switch (CmpFunc) {
134 case GL_NEVER:
135 return D3DCMP_NEVER;
136 case GL_LESS:
137 return D3DCMP_LESS;
138 case GL_EQUAL:
139 return D3DCMP_EQUAL;
140 case GL_LEQUAL:
141 return D3DCMP_LESSEQUAL;
142 case GL_GREATER:
143 return D3DCMP_GREATER;
144 case GL_NOTEQUAL:
145 return D3DCMP_NOTEQUAL;
146 case GL_GEQUAL:
147 return D3DCMP_GREATEREQUAL;
148 case GL_ALWAYS:
149 return D3DCMP_ALWAYS;
150 };
151
152 #ifdef _DEBUG
153 gldLogMessage(GLDLOG_ERROR, "_gldConvertCompareFunc: Unknown CompareFunc\n");
154 #endif
155
156 return D3DCMP_ALWAYS;
157 }
158
159 //---------------------------------------------------------------------------
160
161 D3DBLEND _gldConvertBlendFunc(
162 GLenum blend,
163 GLenum DefaultBlend)
164 {
165 switch (blend) {
166 case GL_ZERO:
167 return D3DBLEND_ZERO;
168 case GL_ONE:
169 return D3DBLEND_ONE;
170 case GL_DST_COLOR:
171 return D3DBLEND_DESTCOLOR;
172 case GL_SRC_COLOR:
173 return D3DBLEND_SRCCOLOR;
174 case GL_ONE_MINUS_DST_COLOR:
175 return D3DBLEND_INVDESTCOLOR;
176 case GL_ONE_MINUS_SRC_COLOR:
177 return D3DBLEND_INVSRCCOLOR;
178 case GL_SRC_ALPHA:
179 return D3DBLEND_SRCALPHA;
180 case GL_ONE_MINUS_SRC_ALPHA:
181 return D3DBLEND_INVSRCALPHA;
182 case GL_DST_ALPHA:
183 return D3DBLEND_DESTALPHA;
184 case GL_ONE_MINUS_DST_ALPHA:
185 return D3DBLEND_INVDESTALPHA;
186 case GL_SRC_ALPHA_SATURATE:
187 return D3DBLEND_SRCALPHASAT;
188 }
189
190 #ifdef _DEBUG
191 gldLogMessage(GLDLOG_ERROR, "_gldConvertBlendFunc: Unknown BlendFunc\n");
192 #endif
193
194 return DefaultBlend;
195 }
196
197 //---------------------------------------------------------------------------
198 // Misc. functions
199 //---------------------------------------------------------------------------
200
201 void gld_Noop_DX8(
202 GLcontext *ctx)
203 {
204 #ifdef _DEBUG
205 gldLogMessage(GLDLOG_ERROR, "gld_Noop called!\n");
206 #endif
207 }
208
209 //---------------------------------------------------------------------------
210
211 void gld_Error_DX8(
212 GLcontext *ctx)
213 {
214 #ifdef _DEBUG
215 // Quite useless.
216 // gldLogMessage(GLDLOG_ERROR, "ctx->Driver.Error called!\n");
217 #endif
218 }
219
220 //---------------------------------------------------------------------------
221 // Required Mesa functions
222 //---------------------------------------------------------------------------
223
224 static GLboolean gld_set_draw_buffer_DX8(
225 GLcontext *ctx,
226 GLenum mode)
227 {
228 (void) ctx;
229 if ((mode==GL_FRONT_LEFT) || (mode == GL_BACK_LEFT)) {
230 return GL_TRUE;
231 }
232 else {
233 return GL_FALSE;
234 }
235 }
236
237 //---------------------------------------------------------------------------
238
239 static void gld_set_read_buffer_DX8(
240 GLcontext *ctx,
241 GLframebuffer *buffer,
242 GLenum mode)
243 {
244 /* separate read buffer not supported */
245 /*
246 ASSERT(buffer == ctx->DrawBuffer);
247 ASSERT(mode == GL_FRONT_LEFT);
248 */
249 }
250
251 //---------------------------------------------------------------------------
252
253 void gld_Clear_DX8(
254 GLcontext *ctx,
255 GLbitfield mask,
256 GLboolean all,
257 GLint x,
258 GLint y,
259 GLint width,
260 GLint height)
261 {
262 GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
263 GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx);
264
265 DWORD dwFlags = 0;
266 D3DCOLOR Color = 0;
267 float Z = 0.0f;
268 DWORD Stencil = 0;
269 D3DRECT d3dClearRect;
270
271 // TODO: Colourmask
272 const GLuint *colorMask = (GLuint *) &ctx->Color.ColorMask[0];
273
274 if (!gld->pDev)
275 return;
276
277 if (mask & (DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT)) {
278 GLubyte col[4];
279 CLAMPED_FLOAT_TO_UBYTE(col[0], ctx->Color.ClearColor[0]);
280 CLAMPED_FLOAT_TO_UBYTE(col[1], ctx->Color.ClearColor[1]);
281 CLAMPED_FLOAT_TO_UBYTE(col[2], ctx->Color.ClearColor[2]);
282 CLAMPED_FLOAT_TO_UBYTE(col[3], ctx->Color.ClearColor[3]);
283 dwFlags |= D3DCLEAR_TARGET;
284 Color = D3DCOLOR_RGBA(col[0], col[1], col[2], col[3]);
285 // ctx->Color.ClearColor[1],
286 // ctx->Color.ClearColor[2],
287 // ctx->Color.ClearColor[3]);
288 }
289
290 if (mask & DD_DEPTH_BIT) {
291 // D3D8 will fail the Clear call if we try and clear a
292 // depth buffer and we haven't created one.
293 // Also, some apps try and clear a depth buffer,
294 // when a depth buffer hasn't been requested by the app.
295 if (ctx->Visual.depthBits == 0) {
296 mask &= ~DD_DEPTH_BIT; // Remove depth bit from mask
297 } else {
298 dwFlags |= D3DCLEAR_ZBUFFER;
299 Z = ctx->Depth.Clear;
300 }
301 }
302
303 if (mask & DD_STENCIL_BIT) {
304 if (ctx->Visual.stencilBits == 0) {
305 // No stencil bits in depth buffer
306 mask &= ~DD_STENCIL_BIT; // Remove stencil bit from mask
307 } else {
308 dwFlags |= D3DCLEAR_STENCIL;
309 Stencil = ctx->Stencil.Clear;
310 }
311 }
312
313 // Some apps do really weird things with the rect, such as Quake3.
314 if ((x < 0) || (y < 0) || (width <= 0) || (height <= 0)) {
315 all = GL_TRUE;
316 }
317
318 if (!all) {
319 // Calculate clear subrect
320 d3dClearRect.x1 = x;
321 d3dClearRect.y1 = gldCtx->dwHeight - (y + height);
322 d3dClearRect.x2 = x + width;
323 d3dClearRect.y2 = d3dClearRect.y1 + height;
324 }
325
326 // dwFlags will be zero if there's nothing to clear
327 if (dwFlags) {
328 _GLD_DX8_DEV(Clear(
329 gld->pDev,
330 all ? 0 : 1,
331 all ? NULL : &d3dClearRect,
332 dwFlags,
333 Color, Z, Stencil));
334 }
335
336 if (mask & DD_ACCUM_BIT) {
337 // Clear accumulation buffer
338 }
339 }
340
341 //---------------------------------------------------------------------------
342
343 // Mesa 5: Parameter change
344 static void gld_buffer_size_DX8(
345 // GLcontext *ctx,
346 GLframebuffer *fb,
347 GLuint *width,
348 GLuint *height)
349 {
350 // GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
351
352 *width = fb->Width; // gldCtx->dwWidth;
353 *height = fb->Height; // gldCtx->dwHeight;
354 }
355
356 //---------------------------------------------------------------------------
357
358 static void gld_Finish_DX8(
359 GLcontext *ctx)
360 {
361 }
362
363 //---------------------------------------------------------------------------
364
365 static void gld_Flush_DX8(
366 GLcontext *ctx)
367 {
368 GLD_context *gld = GLD_GET_CONTEXT(ctx);
369
370 // TODO: Detect apps that glFlush() then SwapBuffers() ?
371
372 if (gld->EmulateSingle) {
373 // Emulating a single-buffered context.
374 // [Direct3D doesn't allow rendering to front buffer]
375 dglSwapBuffers(gld->hDC);
376 }
377 }
378
379 //---------------------------------------------------------------------------
380
381 void gld_NEW_STENCIL(
382 GLcontext *ctx)
383 {
384 GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
385 GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx);
386
387 // Two-sided stencil. New for Mesa 5
388 const GLuint uiFace = 0UL;
389
390 struct gl_stencil_attrib *pStencil = &ctx->Stencil;
391
392 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_STENCILENABLE, pStencil->Enabled ? TRUE : FALSE));
393 if (pStencil->Enabled) {
394 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_STENCILFUNC, _gldConvertCompareFunc(pStencil->Function[uiFace])));
395 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_STENCILREF, pStencil->Ref[uiFace]));
396 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_STENCILMASK, pStencil->ValueMask[uiFace]));
397 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_STENCILWRITEMASK, pStencil->WriteMask[uiFace]));
398 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_STENCILFAIL, _gldConvertStencilOp(pStencil->FailFunc[uiFace])));
399 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_STENCILZFAIL, _gldConvertStencilOp(pStencil->ZFailFunc[uiFace])));
400 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_STENCILPASS, _gldConvertStencilOp(pStencil->ZPassFunc[uiFace])));
401 }
402 }
403
404 //---------------------------------------------------------------------------
405
406 void gld_NEW_COLOR(
407 GLcontext *ctx)
408 {
409 GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
410 GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx);
411
412 DWORD dwFlags = 0;
413 D3DBLEND src;
414 D3DBLEND dest;
415
416 // Alpha func
417 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_ALPHAFUNC, _gldConvertCompareFunc(ctx->Color.AlphaFunc)));
418 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_ALPHAREF, (DWORD)ctx->Color.AlphaRef));
419 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_ALPHATESTENABLE, ctx->Color.AlphaEnabled));
420
421 // Blend func
422 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_ALPHABLENDENABLE, ctx->Color.BlendEnabled));
423 src = _gldConvertBlendFunc(ctx->Color.BlendSrcRGB, GL_ONE);
424 dest = _gldConvertBlendFunc(ctx->Color.BlendDstRGB, GL_ZERO);
425 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_SRCBLEND, src));
426 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_DESTBLEND, dest));
427
428 // Color mask
429 if (ctx->Color.ColorMask[0][0]) dwFlags |= D3DCOLORWRITEENABLE_RED;
430 if (ctx->Color.ColorMask[0][1]) dwFlags |= D3DCOLORWRITEENABLE_GREEN;
431 if (ctx->Color.ColorMask[0][2]) dwFlags |= D3DCOLORWRITEENABLE_BLUE;
432 if (ctx->Color.ColorMask[0][3]) dwFlags |= D3DCOLORWRITEENABLE_ALPHA;
433 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_COLORWRITEENABLE, dwFlags));
434 }
435
436 //---------------------------------------------------------------------------
437
438 void gld_NEW_DEPTH(
439 GLcontext *ctx)
440 {
441 GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
442 GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx);
443
444 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_ZENABLE, ctx->Depth.Test ? D3DZB_TRUE : D3DZB_FALSE));
445 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_ZFUNC, _gldConvertCompareFunc(ctx->Depth.Func)));
446 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_ZWRITEENABLE, ctx->Depth.Mask ? TRUE : FALSE));
447 }
448
449 //---------------------------------------------------------------------------
450
451 void gld_NEW_POLYGON(
452 GLcontext *ctx)
453 {
454 GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
455 GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx);
456
457 D3DFILLMODE d3dFillMode = D3DFILL_SOLID;
458 D3DCULL d3dCullMode = D3DCULL_NONE;
459 int iOffset = 0;
460
461 // Fillmode
462 switch (ctx->Polygon.FrontMode) {
463 case GL_POINT:
464 d3dFillMode = D3DFILL_POINT;
465 break;
466 case GL_LINE:
467 d3dFillMode = D3DFILL_WIREFRAME;
468 break;
469 case GL_FILL:
470 d3dFillMode = D3DFILL_SOLID;
471 break;
472 }
473 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FILLMODE, d3dFillMode));
474
475 if (ctx->Polygon.CullFlag) {
476 switch (ctx->Polygon.CullFaceMode) {
477 case GL_BACK:
478 if (ctx->Polygon.FrontFace == GL_CCW)
479 d3dCullMode = D3DCULL_CW;
480 else
481 d3dCullMode = D3DCULL_CCW;
482 break;
483 case GL_FRONT:
484 if (ctx->Polygon.FrontFace == GL_CCW)
485 d3dCullMode = D3DCULL_CCW;
486 else
487 d3dCullMode = D3DCULL_CW;
488 break;
489 case GL_FRONT_AND_BACK:
490 d3dCullMode = D3DCULL_NONE;
491 break;
492 default:
493 break;
494 }
495 } else {
496 d3dCullMode = D3DCULL_NONE;
497 }
498 // d3dCullMode = D3DCULL_NONE; // TODO: DEBUGGING
499 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_CULLMODE, d3dCullMode));
500
501 // Polygon offset
502 // ZBIAS ranges from 0 to 16 and can only move towards the viewer
503 // Mesa5: ctx->Polygon._OffsetAny removed
504 if (ctx->Polygon.OffsetFill) {
505 iOffset = (int)ctx->Polygon.OffsetUnits;
506 if (iOffset < 0)
507 iOffset = -iOffset;
508 else
509 iOffset = 0; // D3D can't push away
510 }
511 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_ZBIAS, iOffset));
512 }
513
514 //---------------------------------------------------------------------------
515
516 void gld_NEW_FOG(
517 GLcontext *ctx)
518 {
519 GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
520 GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx);
521
522 D3DCOLOR d3dFogColour;
523 D3DFOGMODE d3dFogMode = D3DFOG_LINEAR;
524
525 // TODO: Fog is calculated seperately in the Mesa pipeline
526 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGENABLE, FALSE));
527 return;
528
529 // Fog enable
530 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGENABLE, ctx->Fog.Enabled));
531 if (!ctx->Fog.Enabled) {
532 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGTABLEMODE, D3DFOG_NONE));
533 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGVERTEXMODE, D3DFOG_NONE));
534 return; // If disabled, don't bother setting any fog state
535 }
536
537 // Fog colour
538 d3dFogColour = D3DCOLOR_COLORVALUE( ctx->Fog.Color[0],
539 ctx->Fog.Color[1],
540 ctx->Fog.Color[2],
541 ctx->Fog.Color[3]);
542 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGCOLOR, d3dFogColour));
543
544 // Fog density
545 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGDENSITY, *((DWORD*) (&ctx->Fog.Density))));
546
547 // Fog start
548 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGSTART, *((DWORD*) (&ctx->Fog.Start))));
549
550 // Fog end
551 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGEND, *((DWORD*) (&ctx->Fog.End))));
552
553 // Fog mode
554 switch (ctx->Fog.Mode) {
555 case GL_LINEAR:
556 d3dFogMode = D3DFOG_LINEAR;
557 break;
558 case GL_EXP:
559 d3dFogMode = D3DFOG_EXP;
560 break;
561 case GL_EXP2:
562 d3dFogMode = D3DFOG_EXP2;
563 break;
564 }
565 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGTABLEMODE, d3dFogMode));
566 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_FOGVERTEXMODE, D3DFOG_NONE));
567 }
568
569 //---------------------------------------------------------------------------
570
571 void gld_NEW_LIGHT(
572 GLcontext *ctx)
573 {
574 GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
575 GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx);
576 DWORD dwSpecularEnable;
577
578 // Shademode
579 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_SHADEMODE, (ctx->Light.ShadeModel == GL_SMOOTH) ? D3DSHADE_GOURAUD : D3DSHADE_FLAT));
580
581 // Separate specular colour
582 if (ctx->Light.Enabled)
583 dwSpecularEnable = (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) ? TRUE: FALSE;
584 else
585 dwSpecularEnable = FALSE;
586 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_SPECULARENABLE, dwSpecularEnable));
587 }
588
589 //---------------------------------------------------------------------------
590
591 void gld_NEW_MODELVIEW(
592 GLcontext *ctx)
593 {
594 GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
595 GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx);
596
597 D3DMATRIX m;
598 //GLfloat *pM = ctx->ModelView.m;
599 // Mesa5: Model-view is now a stack
600 GLfloat *pM = ctx->ModelviewMatrixStack.Top->m;
601 m._11 = pM[0];
602 m._12 = pM[1];
603 m._13 = pM[2];
604 m._14 = pM[3];
605 m._21 = pM[4];
606 m._22 = pM[5];
607 m._23 = pM[6];
608 m._24 = pM[7];
609 m._31 = pM[8];
610 m._32 = pM[9];
611 m._33 = pM[10];
612 m._34 = pM[11];
613 m._41 = pM[12];
614 m._42 = pM[13];
615 m._43 = pM[14];
616 m._44 = pM[15];
617
618 gld->matModelView = m;
619 }
620
621 //---------------------------------------------------------------------------
622
623 void gld_NEW_PROJECTION(
624 GLcontext *ctx)
625 {
626 GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
627 GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx);
628
629 D3DMATRIX m;
630 //GLfloat *pM = ctx->ProjectionMatrix.m;
631 // Mesa 5: Now a stack
632 GLfloat *pM = ctx->ProjectionMatrixStack.Top->m;
633 m._11 = pM[0];
634 m._12 = pM[1];
635 m._13 = pM[2];
636 m._14 = pM[3];
637
638 m._21 = pM[4];
639 m._22 = pM[5];
640 m._23 = pM[6];
641 m._24 = pM[7];
642
643 m._31 = pM[8];
644 m._32 = pM[9];
645 m._33 = pM[10] / _fPersp_33; // / 1.6f;
646 m._34 = pM[11];
647
648 m._41 = pM[12];
649 m._42 = pM[13];
650 m._43 = pM[14] / 2.0f;
651 m._44 = pM[15];
652
653 gld->matProjection = m;
654 }
655
656 //---------------------------------------------------------------------------
657 /*
658 void gldFrustumHook_DX8(
659 GLdouble left,
660 GLdouble right,
661 GLdouble bottom,
662 GLdouble top,
663 GLdouble nearval,
664 GLdouble farval)
665 {
666 GET_CURRENT_CONTEXT(ctx);
667 GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
668 GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx);
669
670 // Pass values on to Mesa first (in case we mess with them)
671 _mesa_Frustum(left, right, bottom, top, nearval, farval);
672
673 _fPersp_33 = farval / (nearval - farval);
674
675 // ddlogPrintf(GLDLOG_SYSTEM, "Frustum: %f", farval/nearval);
676 }
677
678 //---------------------------------------------------------------------------
679
680 void gldOrthoHook_DX8(
681 GLdouble left,
682 GLdouble right,
683 GLdouble bottom,
684 GLdouble top,
685 GLdouble nearval,
686 GLdouble farval)
687 {
688 GET_CURRENT_CONTEXT(ctx);
689 GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
690 GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx);
691
692 // Pass values on to Mesa first (in case we mess with them)
693 _mesa_Ortho(left, right, bottom, top, nearval, farval);
694
695 _fPersp_33 = 1.6f;
696
697 // ddlogPrintf(GLDLOG_SYSTEM, "Ortho: %f", farval/nearval);
698 }
699 */
700 //---------------------------------------------------------------------------
701
702 void gld_NEW_VIEWPORT(
703 GLcontext *ctx)
704 {
705 GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
706 GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx);
707
708 D3DVIEWPORT8 d3dvp;
709 // GLint x, y;
710 // GLsizei w, h;
711
712 // Set depth range
713 _GLD_DX8_DEV(GetViewport(gld->pDev, &d3dvp));
714 // D3D can't do Quake1/Quake2 z-trick
715 if (ctx->Viewport.Near <= ctx->Viewport.Far) {
716 d3dvp.MinZ = ctx->Viewport.Near;
717 d3dvp.MaxZ = ctx->Viewport.Far;
718 } else {
719 d3dvp.MinZ = ctx->Viewport.Far;
720 d3dvp.MaxZ = ctx->Viewport.Near;
721 }
722 /* x = ctx->Viewport.X;
723 y = ctx->Viewport.Y;
724 w = ctx->Viewport.Width;
725 h = ctx->Viewport.Height;
726 if (x < 0) x = 0;
727 if (y < 0) y = 0;
728 if (w > gldCtx->dwWidth) w = gldCtx->dwWidth;
729 if (h > gldCtx->dwHeight) h = gldCtx->dwHeight;
730 // Ditto for D3D viewport dimensions
731 if (w+x > gldCtx->dwWidth) w = gldCtx->dwWidth-x;
732 if (h+y > gldCtx->dwHeight) h = gldCtx->dwHeight-y;
733 d3dvp.X = x;
734 d3dvp.Y = gldCtx->dwHeight - (y + h);
735 d3dvp.Width = w;
736 d3dvp.Height = h;*/
737 _GLD_DX8_DEV(SetViewport(gld->pDev, &d3dvp));
738
739 // gld->fFlipWindowY = (float)gldCtx->dwHeight;
740 }
741
742 //---------------------------------------------------------------------------
743
744 __inline BOOL _gldAnyEvalEnabled(
745 GLcontext *ctx)
746 {
747 struct gl_eval_attrib *eval = &ctx->Eval;
748
749 if ((eval->AutoNormal) ||
750 (eval->Map1Color4) ||
751 (eval->Map1Index) ||
752 (eval->Map1Normal) ||
753 (eval->Map1TextureCoord1) ||
754 (eval->Map1TextureCoord2) ||
755 (eval->Map1TextureCoord3) ||
756 (eval->Map1TextureCoord4) ||
757 (eval->Map1Vertex3) ||
758 (eval->Map1Vertex4) ||
759 (eval->Map2Color4) ||
760 (eval->Map2Index) ||
761 (eval->Map2Normal) ||
762 (eval->Map2TextureCoord1) ||
763 (eval->Map2TextureCoord2) ||
764 (eval->Map2TextureCoord3) ||
765 (eval->Map2TextureCoord4) ||
766 (eval->Map2Vertex3) ||
767 (eval->Map2Vertex4)
768 )
769 return TRUE;
770
771 return FALSE;
772 }
773
774 //---------------------------------------------------------------------------
775
776 BOOL _gldChooseInternalPipeline(
777 GLcontext *ctx,
778 GLD_driver_dx8 *gld)
779 {
780 // return TRUE; // DEBUGGING: ALWAYS USE MESA
781 // return FALSE; // DEBUGGING: ALWAYS USE D3D
782
783 if ((glb.dwTnL == GLDS_TNL_MESA) || (gld->bHasHWTnL == FALSE))
784 {
785 gld->PipelineUsage.qwMesa.QuadPart++;
786 return TRUE; // Force Mesa TnL
787 }
788
789 if ((ctx->Light.Enabled) ||
790 (1) ||
791 (ctx->Texture._TexGenEnabled) ||
792 (ctx->Texture._TexMatEnabled) ||
793 // (ctx->Transform._AnyClip) ||
794 (ctx->Scissor.Enabled) ||
795 _gldAnyEvalEnabled(ctx) // Put this last so we can early-out
796 )
797 {
798 gld->PipelineUsage.qwMesa.QuadPart++;
799 return TRUE;
800 }
801
802 gld->PipelineUsage.qwD3DFVF.QuadPart++;
803 return FALSE;
804
805 /* // Force Mesa pipeline?
806 if (glb.dwTnL == GLDS_TNL_MESA) {
807 gld->PipelineUsage.dwMesa.QuadPart++;
808 return GLD_PIPELINE_MESA;
809 }
810
811 // Test for functionality not exposed in the D3D pathways
812 if ((ctx->Texture._GenFlags)) {
813 gld->PipelineUsage.dwMesa.QuadPart++;
814 return GLD_PIPELINE_MESA;
815 }
816
817 // Now decide if vertex shader can be used.
818 // If two sided lighting is enabled then we must either
819 // use Mesa TnL or the vertex shader
820 if (ctx->_TriangleCaps & DD_TRI_LIGHT_TWOSIDE) {
821 if (gld->VStwosidelight.hShader && !ctx->Fog.Enabled) {
822 // Use Vertex Shader
823 gld->PipelineUsage.dwD3D2SVS.QuadPart++;
824 return GLD_PIPELINE_D3D_VS_TWOSIDE;
825 } else {
826 // Use Mesa TnL
827 gld->PipelineUsage.dwMesa.QuadPart++;
828 return GLD_PIPELINE_MESA;
829 }
830 }
831
832 // Must be D3D fixed-function pipeline
833 gld->PipelineUsage.dwD3DFVF.QuadPart++;
834 return GLD_PIPELINE_D3D_FVF;
835 */
836 }
837
838 //---------------------------------------------------------------------------
839
840 void gld_update_state_DX8(
841 GLcontext *ctx,
842 GLuint new_state)
843 {
844 GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
845 GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx);
846 TNLcontext *tnl = TNL_CONTEXT(ctx);
847 GLD_pb_dx8 *gldPB;
848
849 if (!gld || !gld->pDev)
850 return;
851
852 _swsetup_InvalidateState( ctx, new_state );
853 _vbo_InvalidateState( ctx, new_state );
854 _tnl_InvalidateState( ctx, new_state );
855
856 // SetupIndex will be used in the pipelines for choosing setup function
857 if ((ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE | DD_SEPARATE_SPECULAR)) ||
858 (ctx->Fog.Enabled))
859 {
860 if (ctx->_TriangleCaps & DD_FLATSHADE)
861 gld->iSetupFunc = GLD_SI_FLAT_EXTRAS;
862 else
863 gld->iSetupFunc = GLD_SI_SMOOTH_EXTRAS;
864 } else {
865 if (ctx->_TriangleCaps & DD_FLATSHADE)
866 gld->iSetupFunc = GLD_SI_FLAT; // Setup flat shade + texture
867 else
868 gld->iSetupFunc = GLD_SI_SMOOTH; // Setup smooth shade + texture
869 }
870
871 gld->bUseMesaTnL = _gldChooseInternalPipeline(ctx, gld);
872 if (gld->bUseMesaTnL) {
873 gldPB = &gld->PB2d;
874 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, TRUE));
875 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_CLIPPING, FALSE));
876 _GLD_DX8_DEV(SetVertexShader(gld->pDev, gldPB->dwFVF));
877 } else {
878 gldPB = &gld->PB3d;
879 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_CLIPPING, TRUE));
880 // if (gld->TnLPipeline == GLD_PIPELINE_D3D_VS_TWOSIDE) {
881 // _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, !gld->VStwosidelight.bHardware));
882 // _GLD_DX8_DEV(SetVertexShader(gld->pDev, gld->VStwosidelight.hShader));
883 // } else {
884 _GLD_DX8_DEV(SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, !gld->bHasHWTnL));
885 _GLD_DX8_DEV(SetVertexShader(gld->pDev, gldPB->dwFVF));
886 // }
887 }
888
889 #define _GLD_TEST_STATE(a) \
890 if (new_state & (a)) { \
891 gld##a(ctx); \
892 new_state &= ~(a); \
893 }
894
895 #define _GLD_TEST_STATE_DX8(a) \
896 if (new_state & (a)) { \
897 gld##a##_DX8(ctx); \
898 new_state &= ~(a); \
899 }
900
901 #define _GLD_IGNORE_STATE(a) new_state &= ~(a);
902
903 // if (!gld->bUseMesaTnL) {
904 // Not required if Mesa is doing the TnL.
905 // Problem: If gld->bUseMesaTnL is TRUE when these are signaled,
906 // then we'll miss updating the D3D TnL pipeline.
907 // Therefore, don't test for gld->bUseMesaTnL
908 _GLD_TEST_STATE(_NEW_MODELVIEW);
909 _GLD_TEST_STATE(_NEW_PROJECTION);
910 // }
911
912 _GLD_TEST_STATE_DX8(_NEW_TEXTURE); // extern, so guard with _DX8
913 _GLD_TEST_STATE(_NEW_COLOR);
914 _GLD_TEST_STATE(_NEW_DEPTH);
915 _GLD_TEST_STATE(_NEW_POLYGON);
916 _GLD_TEST_STATE(_NEW_STENCIL);
917 _GLD_TEST_STATE(_NEW_FOG);
918 _GLD_TEST_STATE(_NEW_LIGHT);
919 _GLD_TEST_STATE(_NEW_VIEWPORT);
920
921 _GLD_IGNORE_STATE(_NEW_TRANSFORM);
922
923
924 // Stubs for future use.
925 /* _GLD_TEST_STATE(_NEW_TEXTURE_MATRIX);
926 _GLD_TEST_STATE(_NEW_COLOR_MATRIX);
927 _GLD_TEST_STATE(_NEW_ACCUM);
928 _GLD_TEST_STATE(_NEW_EVAL);
929 _GLD_TEST_STATE(_NEW_HINT);
930 _GLD_TEST_STATE(_NEW_LINE);
931 _GLD_TEST_STATE(_NEW_PIXEL);
932 _GLD_TEST_STATE(_NEW_POINT);
933 _GLD_TEST_STATE(_NEW_POLYGONSTIPPLE);
934 _GLD_TEST_STATE(_NEW_SCISSOR);
935 _GLD_TEST_STATE(_NEW_PACKUNPACK);
936 _GLD_TEST_STATE(_NEW_ARRAY);
937 _GLD_TEST_STATE(_NEW_RENDERMODE);
938 _GLD_TEST_STATE(_NEW_BUFFERS);
939 _GLD_TEST_STATE(_NEW_MULTISAMPLE);
940 */
941
942 // For debugging.
943 #if 0
944 #define _GLD_TEST_UNHANDLED_STATE(a) \
945 if (new_state & (a)) { \
946 gldLogMessage(GLDLOG_ERROR, "Unhandled " #a "\n"); \
947 }
948 _GLD_TEST_UNHANDLED_STATE(_NEW_TEXTURE_MATRIX);
949 _GLD_TEST_UNHANDLED_STATE(_NEW_COLOR_MATRIX);
950 _GLD_TEST_UNHANDLED_STATE(_NEW_ACCUM);
951 _GLD_TEST_UNHANDLED_STATE(_NEW_EVAL);
952 _GLD_TEST_UNHANDLED_STATE(_NEW_HINT);
953 _GLD_TEST_UNHANDLED_STATE(_NEW_LINE);
954 _GLD_TEST_UNHANDLED_STATE(_NEW_PIXEL);
955 _GLD_TEST_UNHANDLED_STATE(_NEW_POINT);
956 _GLD_TEST_UNHANDLED_STATE(_NEW_POLYGONSTIPPLE);
957 _GLD_TEST_UNHANDLED_STATE(_NEW_SCISSOR);
958 _GLD_TEST_UNHANDLED_STATE(_NEW_PACKUNPACK);
959 _GLD_TEST_UNHANDLED_STATE(_NEW_ARRAY);
960 _GLD_TEST_UNHANDLED_STATE(_NEW_RENDERMODE);
961 _GLD_TEST_UNHANDLED_STATE(_NEW_BUFFERS);
962 _GLD_TEST_UNHANDLED_STATE(_NEW_MULTISAMPLE);
963 #undef _GLD_UNHANDLED_STATE
964 #endif
965
966 #undef _GLD_TEST_STATE
967 }
968
969 //---------------------------------------------------------------------------
970 // Viewport
971 //---------------------------------------------------------------------------
972
973 void gld_Viewport_DX8(
974 GLcontext *ctx,
975 GLint x,
976 GLint y,
977 GLsizei w,
978 GLsizei h)
979 {
980 GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
981 GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx);
982
983 D3DVIEWPORT8 d3dvp;
984
985 if (!gld || !gld->pDev)
986 return;
987
988 // This is a hack. When the app is minimized, Mesa passes
989 // w=1 and h=1 for viewport dimensions. Without this test
990 // we get a GPF in gld_wgl_resize_buffers().
991 if ((w==1) && (h==1))
992 return;
993
994 // Call ResizeBuffersMESA. This function will early-out
995 // if no resize is needed.
996 //ctx->Driver.ResizeBuffersMESA(ctx);
997 // Mesa 5: Changed parameters
998 ctx->Driver.ResizeBuffers(gldCtx->glBuffer);
999
1000 #if 0
1001 ddlogPrintf(GLDLOG_SYSTEM, ">> Viewport x=%d y=%d w=%d h=%d", x,y,w,h);
1002 #endif
1003
1004 // ** D3D viewport must not be outside the render target surface **
1005 // Sanity check the GL viewport dimensions
1006 if (x < 0) x = 0;
1007 if (y < 0) y = 0;
1008 if (w > gldCtx->dwWidth) w = gldCtx->dwWidth;
1009 if (h > gldCtx->dwHeight) h = gldCtx->dwHeight;
1010 // Ditto for D3D viewport dimensions
1011 if (w+x > gldCtx->dwWidth) w = gldCtx->dwWidth-x;
1012 if (h+y > gldCtx->dwHeight) h = gldCtx->dwHeight-y;
1013
1014 d3dvp.X = x;
1015 d3dvp.Y = gldCtx->dwHeight - (y + h);
1016 d3dvp.Width = w;
1017 d3dvp.Height = h;
1018 if (ctx->Viewport.Near <= ctx->Viewport.Far) {
1019 d3dvp.MinZ = ctx->Viewport.Near;
1020 d3dvp.MaxZ = ctx->Viewport.Far;
1021 } else {
1022 d3dvp.MinZ = ctx->Viewport.Far;
1023 d3dvp.MaxZ = ctx->Viewport.Near;
1024 }
1025
1026 // TODO: DEBUGGING
1027 // d3dvp.MinZ = 0.0f;
1028 // d3dvp.MaxZ = 1.0f;
1029
1030 _GLD_DX8_DEV(SetViewport(gld->pDev, &d3dvp));
1031
1032 }
1033
1034 //---------------------------------------------------------------------------
1035
1036 extern BOOL dglWglResizeBuffers(GLcontext *ctx, BOOL bDefaultDriver);
1037
1038 // Mesa 5: Parameter change
1039 void gldResizeBuffers_DX8(
1040 // GLcontext *ctx)
1041 GLframebuffer *fb)
1042 {
1043 GET_CURRENT_CONTEXT(ctx);
1044 dglWglResizeBuffers(ctx, TRUE);
1045 }
1046
1047 //---------------------------------------------------------------------------
1048 #ifdef _DEBUG
1049 // This is only for debugging.
1050 // To use, plug into ctx->Driver.Enable pointer below.
1051 void gld_Enable(
1052 GLcontext *ctx,
1053 GLenum e,
1054 GLboolean b)
1055 {
1056 char buf[1024];
1057 sprintf(buf, "Enable: %s (%s)\n", _mesa_lookup_enum_by_nr(e), b?"TRUE":"FALSE");
1058 ddlogMessage(DDLOG_SYSTEM, buf);
1059 }
1060 #endif
1061 //---------------------------------------------------------------------------
1062 // Driver pointer setup
1063 //---------------------------------------------------------------------------
1064
1065 extern const GLubyte* _gldGetStringGeneric(GLcontext*, GLenum);
1066
1067 void gldSetupDriverPointers_DX8(
1068 GLcontext *ctx)
1069 {
1070 GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
1071 GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx);
1072
1073 TNLcontext *tnl = TNL_CONTEXT(ctx);
1074
1075 // Mandatory functions
1076 ctx->Driver.GetString = _gldGetStringGeneric;
1077 ctx->Driver.UpdateState = gld_update_state_DX8;
1078 ctx->Driver.Clear = gld_Clear_DX8;
1079 ctx->Driver.DrawBuffer = gld_set_draw_buffer_DX8;
1080 ctx->Driver.GetBufferSize = gld_buffer_size_DX8;
1081 ctx->Driver.Finish = gld_Finish_DX8;
1082 ctx->Driver.Flush = gld_Flush_DX8;
1083 ctx->Driver.Error = gld_Error_DX8;
1084
1085 // Hardware accumulation buffer
1086 ctx->Driver.Accum = NULL; // TODO: gld_Accum;
1087
1088 // Bitmap functions
1089 ctx->Driver.CopyPixels = gld_CopyPixels_DX8;
1090 ctx->Driver.DrawPixels = gld_DrawPixels_DX8;
1091 ctx->Driver.ReadPixels = gld_ReadPixels_DX8;
1092 ctx->Driver.Bitmap = gld_Bitmap_DX8;
1093
1094 // Buffer resize
1095 ctx->Driver.ResizeBuffers = gldResizeBuffers_DX8;
1096
1097 // Texture image functions
1098 ctx->Driver.ChooseTextureFormat = gld_ChooseTextureFormat_DX8;
1099 ctx->Driver.TexImage1D = gld_TexImage1D_DX8;
1100 ctx->Driver.TexImage2D = gld_TexImage2D_DX8;
1101 ctx->Driver.TexImage3D = _mesa_store_teximage3d;
1102 ctx->Driver.TexSubImage1D = gld_TexSubImage1D_DX8;
1103 ctx->Driver.TexSubImage2D = gld_TexSubImage2D_DX8;
1104 ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d;
1105
1106 ctx->Driver.CopyTexImage1D = gldCopyTexImage1D_DX8; //NULL;
1107 ctx->Driver.CopyTexImage2D = gldCopyTexImage2D_DX8; //NULL;
1108 ctx->Driver.CopyTexSubImage1D = gldCopyTexSubImage1D_DX8; //NULL;
1109 ctx->Driver.CopyTexSubImage2D = gldCopyTexSubImage2D_DX8; //NULL;
1110 ctx->Driver.CopyTexSubImage3D = gldCopyTexSubImage3D_DX8;
1111 ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage;
1112
1113 // Texture object functions
1114 ctx->Driver.BindTexture = NULL;
1115 ctx->Driver.NewTextureObject = NULL; // Not yet implemented by Mesa!;
1116 ctx->Driver.DeleteTexture = gld_DeleteTexture_DX8;
1117 ctx->Driver.PrioritizeTexture = NULL;
1118
1119 // Imaging functionality
1120 ctx->Driver.CopyColorTable = NULL;
1121 ctx->Driver.CopyColorSubTable = NULL;
1122 ctx->Driver.CopyConvolutionFilter1D = NULL;
1123 ctx->Driver.CopyConvolutionFilter2D = NULL;
1124
1125 // State changing functions
1126 ctx->Driver.AlphaFunc = NULL; //gld_AlphaFunc;
1127 ctx->Driver.BlendFuncSeparate = NULL; //gld_BlendFunc;
1128 ctx->Driver.ClearColor = NULL; //gld_ClearColor;
1129 ctx->Driver.ClearDepth = NULL; //gld_ClearDepth;
1130 ctx->Driver.ClearStencil = NULL; //gld_ClearStencil;
1131 ctx->Driver.ColorMask = NULL; //gld_ColorMask;
1132 ctx->Driver.CullFace = NULL; //gld_CullFace;
1133 ctx->Driver.ClipPlane = NULL; //gld_ClipPlane;
1134 ctx->Driver.FrontFace = NULL; //gld_FrontFace;
1135 ctx->Driver.DepthFunc = NULL; //gld_DepthFunc;
1136 ctx->Driver.DepthMask = NULL; //gld_DepthMask;
1137 ctx->Driver.DepthRange = NULL;
1138 ctx->Driver.Enable = NULL; //gld_Enable;
1139 ctx->Driver.Fogfv = NULL; //gld_Fogfv;
1140 ctx->Driver.Hint = NULL; //gld_Hint;
1141 ctx->Driver.Lightfv = NULL; //gld_Lightfv;
1142 ctx->Driver.LightModelfv = NULL; //gld_LightModelfv;
1143 ctx->Driver.LineStipple = NULL; //gld_LineStipple;
1144 ctx->Driver.LineWidth = NULL; //gld_LineWidth;
1145 ctx->Driver.LogicOpcode = NULL; //gld_LogicOpcode;
1146 ctx->Driver.PointParameterfv = NULL; //gld_PointParameterfv;
1147 ctx->Driver.PointSize = NULL; //gld_PointSize;
1148 ctx->Driver.PolygonMode = NULL; //gld_PolygonMode;
1149 ctx->Driver.PolygonOffset = NULL; //gld_PolygonOffset;
1150 ctx->Driver.PolygonStipple = NULL; //gld_PolygonStipple;
1151 ctx->Driver.RenderMode = NULL; //gld_RenderMode;
1152 ctx->Driver.Scissor = NULL; //gld_Scissor;
1153 ctx->Driver.ShadeModel = NULL; //gld_ShadeModel;
1154 ctx->Driver.StencilFunc = NULL; //gld_StencilFunc;
1155 ctx->Driver.StencilMask = NULL; //gld_StencilMask;
1156 ctx->Driver.StencilOp = NULL; //gld_StencilOp;
1157 ctx->Driver.TexGen = NULL; //gld_TexGen;
1158 ctx->Driver.TexEnv = NULL;
1159 ctx->Driver.TexParameter = NULL;
1160 ctx->Driver.TextureMatrix = NULL; //gld_TextureMatrix;
1161 ctx->Driver.Viewport = gld_Viewport_DX8;
1162
1163 _swsetup_Wakeup(ctx);
1164
1165 tnl->Driver.RunPipeline = _tnl_run_pipeline;
1166 tnl->Driver.Render.ResetLineStipple = gld_ResetLineStipple_DX8;
1167 tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon;
1168 tnl->Driver.Render.ClippedLine = _tnl_RenderClippedLine;
1169
1170 // Hook into glFrustum() and glOrtho()
1171 // ctx->Exec->Frustum = gldFrustumHook_DX8;
1172 // ctx->Exec->Ortho = gldOrthoHook_DX8;
1173
1174 }
1175
1176 //---------------------------------------------------------------------------