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 interface code to Mesa
35 ****************************************************************************/
37 //#include <windows.h>
38 #include "dglcontext.h"
46 #include "extensions.h"
52 #include "texformat.h"
56 #include "swrast_setup/swrast_setup.h"
57 #include "swrast_setup/ss_context.h"
59 #include "tnl/t_context.h"
60 #include "tnl/t_pipeline.h"
62 extern BOOL
dglSwapBuffers(HDC hDC
);
64 // HACK: Hack the _33 member of the OpenGL perspective projection matrix
65 const float _fPersp_33
= 1.6f
;
67 //---------------------------------------------------------------------------
69 //---------------------------------------------------------------------------
71 void _gld_mesa_warning(
75 // Intercept Mesa's internal warning mechanism
76 gldLogPrintf(GLDLOG_WARN
, "Mesa warning: %s", str
);
79 //---------------------------------------------------------------------------
85 // Intercept Mesa's internal fatal-message mechanism
86 gldLogPrintf(GLDLOG_CRITICAL
, "Mesa FATAL: %s", str
);
88 // Mesa calls abort(0) here.
93 //---------------------------------------------------------------------------
95 D3DSTENCILOP
_gldConvertStencilOp(
98 // Used by Stencil: pass, fail and zfail
102 return D3DSTENCILOP_KEEP
;
104 return D3DSTENCILOP_ZERO
;
106 return D3DSTENCILOP_REPLACE
;
108 return D3DSTENCILOP_INCRSAT
;
110 return D3DSTENCILOP_DECRSAT
;
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
;
120 gldLogMessage(GLDLOG_ERROR
, "_gldConvertStencilOp: Unknown StencilOp\n");
123 return D3DSTENCILOP_KEEP
;
126 //---------------------------------------------------------------------------
128 D3DCMPFUNC
_gldConvertCompareFunc(
131 // Used for Alpha func, depth func and stencil func.
141 return D3DCMP_LESSEQUAL
;
143 return D3DCMP_GREATER
;
145 return D3DCMP_NOTEQUAL
;
147 return D3DCMP_GREATEREQUAL
;
149 return D3DCMP_ALWAYS
;
153 gldLogMessage(GLDLOG_ERROR
, "_gldConvertCompareFunc: Unknown CompareFunc\n");
156 return D3DCMP_ALWAYS
;
159 //---------------------------------------------------------------------------
161 D3DBLEND
_gldConvertBlendFunc(
167 return D3DBLEND_ZERO
;
171 return D3DBLEND_DESTCOLOR
;
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
;
179 return D3DBLEND_SRCALPHA
;
180 case GL_ONE_MINUS_SRC_ALPHA
:
181 return D3DBLEND_INVSRCALPHA
;
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
;
191 gldLogMessage(GLDLOG_ERROR
, "_gldConvertBlendFunc: Unknown BlendFunc\n");
197 //---------------------------------------------------------------------------
199 //---------------------------------------------------------------------------
205 gldLogMessage(GLDLOG_ERROR
, "gld_Noop called!\n");
209 //---------------------------------------------------------------------------
216 // gldLogMessage(GLDLOG_ERROR, "ctx->Driver.Error called!\n");
220 //---------------------------------------------------------------------------
221 // Required Mesa functions
222 //---------------------------------------------------------------------------
224 static GLboolean
gld_set_draw_buffer_DX8(
229 if ((mode
==GL_FRONT_LEFT
) || (mode
== GL_BACK_LEFT
)) {
237 //---------------------------------------------------------------------------
239 static void gld_set_read_buffer_DX8(
241 GLframebuffer
*buffer
,
244 /* separate read buffer not supported */
246 ASSERT(buffer == ctx->DrawBuffer);
247 ASSERT(mode == GL_FRONT_LEFT);
251 //---------------------------------------------------------------------------
262 GLD_context
*gldCtx
= GLD_GET_CONTEXT(ctx
);
263 GLD_driver_dx8
*gld
= GLD_GET_DX8_DRIVER(gldCtx
);
269 D3DRECT d3dClearRect
;
272 const GLuint
*colorMask
= (GLuint
*) &ctx
->Color
.ColorMask
;
277 if (mask
& (DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
)) {
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]);
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
298 dwFlags
|= D3DCLEAR_ZBUFFER
;
299 Z
= ctx
->Depth
.Clear
;
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
308 dwFlags
|= D3DCLEAR_STENCIL
;
309 Stencil
= ctx
->Stencil
.Clear
;
313 // Some apps do really weird things with the rect, such as Quake3.
314 if ((x
< 0) || (y
< 0) || (width
<= 0) || (height
<= 0)) {
319 // Calculate clear subrect
321 d3dClearRect
.y1
= gldCtx
->dwHeight
- (y
+ height
);
322 d3dClearRect
.x2
= x
+ width
;
323 d3dClearRect
.y2
= d3dClearRect
.y1
+ height
;
326 // dwFlags will be zero if there's nothing to clear
331 all
? NULL
: &d3dClearRect
,
336 if (mask
& DD_ACCUM_BIT
) {
337 // Clear accumulation buffer
341 //---------------------------------------------------------------------------
343 // Mesa 5: Parameter change
344 static void gld_buffer_size_DX8(
350 // GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
352 *width
= fb
->Width
; // gldCtx->dwWidth;
353 *height
= fb
->Height
; // gldCtx->dwHeight;
356 //---------------------------------------------------------------------------
358 static void gld_Finish_DX8(
363 //---------------------------------------------------------------------------
365 static void gld_Flush_DX8(
368 GLD_context
*gld
= GLD_GET_CONTEXT(ctx
);
370 // TODO: Detect apps that glFlush() then SwapBuffers() ?
372 if (gld
->EmulateSingle
) {
373 // Emulating a single-buffered context.
374 // [Direct3D doesn't allow rendering to front buffer]
375 dglSwapBuffers(gld
->hDC
);
379 //---------------------------------------------------------------------------
381 void gld_NEW_STENCIL(
384 GLD_context
*gldCtx
= GLD_GET_CONTEXT(ctx
);
385 GLD_driver_dx8
*gld
= GLD_GET_DX8_DRIVER(gldCtx
);
387 // Two-sided stencil. New for Mesa 5
388 const GLuint uiFace
= 0UL;
390 struct gl_stencil_attrib
*pStencil
= &ctx
->Stencil
;
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
])));
404 //---------------------------------------------------------------------------
409 GLD_context
*gldCtx
= GLD_GET_CONTEXT(ctx
);
410 GLD_driver_dx8
*gld
= GLD_GET_DX8_DRIVER(gldCtx
);
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
));
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
));
429 if (ctx
->Color
.ColorMask
[0]) dwFlags
|= D3DCOLORWRITEENABLE_RED
;
430 if (ctx
->Color
.ColorMask
[1]) dwFlags
|= D3DCOLORWRITEENABLE_GREEN
;
431 if (ctx
->Color
.ColorMask
[2]) dwFlags
|= D3DCOLORWRITEENABLE_BLUE
;
432 if (ctx
->Color
.ColorMask
[3]) dwFlags
|= D3DCOLORWRITEENABLE_ALPHA
;
433 _GLD_DX8_DEV(SetRenderState(gld
->pDev
, D3DRS_COLORWRITEENABLE
, dwFlags
));
436 //---------------------------------------------------------------------------
441 GLD_context
*gldCtx
= GLD_GET_CONTEXT(ctx
);
442 GLD_driver_dx8
*gld
= GLD_GET_DX8_DRIVER(gldCtx
);
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
));
449 //---------------------------------------------------------------------------
451 void gld_NEW_POLYGON(
454 GLD_context
*gldCtx
= GLD_GET_CONTEXT(ctx
);
455 GLD_driver_dx8
*gld
= GLD_GET_DX8_DRIVER(gldCtx
);
457 D3DFILLMODE d3dFillMode
= D3DFILL_SOLID
;
458 D3DCULL d3dCullMode
= D3DCULL_NONE
;
462 switch (ctx
->Polygon
.FrontMode
) {
464 d3dFillMode
= D3DFILL_POINT
;
467 d3dFillMode
= D3DFILL_WIREFRAME
;
470 d3dFillMode
= D3DFILL_SOLID
;
473 _GLD_DX8_DEV(SetRenderState(gld
->pDev
, D3DRS_FILLMODE
, d3dFillMode
));
475 if (ctx
->Polygon
.CullFlag
) {
476 switch (ctx
->Polygon
.CullFaceMode
) {
478 if (ctx
->Polygon
.FrontFace
== GL_CCW
)
479 d3dCullMode
= D3DCULL_CW
;
481 d3dCullMode
= D3DCULL_CCW
;
484 if (ctx
->Polygon
.FrontFace
== GL_CCW
)
485 d3dCullMode
= D3DCULL_CCW
;
487 d3dCullMode
= D3DCULL_CW
;
489 case GL_FRONT_AND_BACK
:
490 d3dCullMode
= D3DCULL_NONE
;
496 d3dCullMode
= D3DCULL_NONE
;
498 // d3dCullMode = D3DCULL_NONE; // TODO: DEBUGGING
499 _GLD_DX8_DEV(SetRenderState(gld
->pDev
, D3DRS_CULLMODE
, d3dCullMode
));
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
;
509 iOffset
= 0; // D3D can't push away
511 _GLD_DX8_DEV(SetRenderState(gld
->pDev
, D3DRS_ZBIAS
, iOffset
));
514 //---------------------------------------------------------------------------
519 GLD_context
*gldCtx
= GLD_GET_CONTEXT(ctx
);
520 GLD_driver_dx8
*gld
= GLD_GET_DX8_DRIVER(gldCtx
);
522 D3DCOLOR d3dFogColour
;
523 D3DFOGMODE d3dFogMode
= D3DFOG_LINEAR
;
525 // TODO: Fog is calculated seperately in the Mesa pipeline
526 _GLD_DX8_DEV(SetRenderState(gld
->pDev
, D3DRS_FOGENABLE
, FALSE
));
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
538 d3dFogColour
= D3DCOLOR_COLORVALUE( ctx
->Fog
.Color
[0],
542 _GLD_DX8_DEV(SetRenderState(gld
->pDev
, D3DRS_FOGCOLOR
, d3dFogColour
));
545 _GLD_DX8_DEV(SetRenderState(gld
->pDev
, D3DRS_FOGDENSITY
, *((DWORD
*) (&ctx
->Fog
.Density
))));
548 _GLD_DX8_DEV(SetRenderState(gld
->pDev
, D3DRS_FOGSTART
, *((DWORD
*) (&ctx
->Fog
.Start
))));
551 _GLD_DX8_DEV(SetRenderState(gld
->pDev
, D3DRS_FOGEND
, *((DWORD
*) (&ctx
->Fog
.End
))));
554 switch (ctx
->Fog
.Mode
) {
556 d3dFogMode
= D3DFOG_LINEAR
;
559 d3dFogMode
= D3DFOG_EXP
;
562 d3dFogMode
= D3DFOG_EXP2
;
565 _GLD_DX8_DEV(SetRenderState(gld
->pDev
, D3DRS_FOGTABLEMODE
, d3dFogMode
));
566 _GLD_DX8_DEV(SetRenderState(gld
->pDev
, D3DRS_FOGVERTEXMODE
, D3DFOG_NONE
));
569 //---------------------------------------------------------------------------
574 GLD_context
*gldCtx
= GLD_GET_CONTEXT(ctx
);
575 GLD_driver_dx8
*gld
= GLD_GET_DX8_DRIVER(gldCtx
);
576 DWORD dwSpecularEnable
;
579 _GLD_DX8_DEV(SetRenderState(gld
->pDev
, D3DRS_SHADEMODE
, (ctx
->Light
.ShadeModel
== GL_SMOOTH
) ? D3DSHADE_GOURAUD
: D3DSHADE_FLAT
));
581 // Separate specular colour
582 if (ctx
->Light
.Enabled
)
583 dwSpecularEnable
= (ctx
->_TriangleCaps
& DD_SEPARATE_SPECULAR
) ? TRUE
: FALSE
;
585 dwSpecularEnable
= FALSE
;
586 _GLD_DX8_DEV(SetRenderState(gld
->pDev
, D3DRS_SPECULARENABLE
, dwSpecularEnable
));
589 //---------------------------------------------------------------------------
591 void gld_NEW_MODELVIEW(
594 GLD_context
*gldCtx
= GLD_GET_CONTEXT(ctx
);
595 GLD_driver_dx8
*gld
= GLD_GET_DX8_DRIVER(gldCtx
);
598 //GLfloat *pM = ctx->ModelView.m;
599 // Mesa5: Model-view is now a stack
600 GLfloat
*pM
= ctx
->ModelviewMatrixStack
.Top
->m
;
618 gld
->matModelView
= m
;
621 //---------------------------------------------------------------------------
623 void gld_NEW_PROJECTION(
626 GLD_context
*gldCtx
= GLD_GET_CONTEXT(ctx
);
627 GLD_driver_dx8
*gld
= GLD_GET_DX8_DRIVER(gldCtx
);
630 //GLfloat *pM = ctx->ProjectionMatrix.m;
631 // Mesa 5: Now a stack
632 GLfloat
*pM
= ctx
->ProjectionMatrixStack
.Top
->m
;
645 m
._33
= pM
[10] / _fPersp_33
; // / 1.6f;
650 m
._43
= pM
[14] / 2.0f
;
653 gld
->matProjection
= m
;
656 //---------------------------------------------------------------------------
658 void gldFrustumHook_DX8(
666 GET_CURRENT_CONTEXT(ctx);
667 GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
668 GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx);
670 // Pass values on to Mesa first (in case we mess with them)
671 _mesa_Frustum(left, right, bottom, top, nearval, farval);
673 _fPersp_33 = farval / (nearval - farval);
675 // ddlogPrintf(GLDLOG_SYSTEM, "Frustum: %f", farval/nearval);
678 //---------------------------------------------------------------------------
680 void gldOrthoHook_DX8(
688 GET_CURRENT_CONTEXT(ctx);
689 GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
690 GLD_driver_dx8 *gld = GLD_GET_DX8_DRIVER(gldCtx);
692 // Pass values on to Mesa first (in case we mess with them)
693 _mesa_Ortho(left, right, bottom, top, nearval, farval);
697 // ddlogPrintf(GLDLOG_SYSTEM, "Ortho: %f", farval/nearval);
700 //---------------------------------------------------------------------------
702 void gld_NEW_VIEWPORT(
705 GLD_context
*gldCtx
= GLD_GET_CONTEXT(ctx
);
706 GLD_driver_dx8
*gld
= GLD_GET_DX8_DRIVER(gldCtx
);
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
;
719 d3dvp
.MinZ
= ctx
->Viewport
.Far
;
720 d3dvp
.MaxZ
= ctx
->Viewport
.Near
;
722 /* x = ctx->Viewport.X;
724 w = ctx->Viewport.Width;
725 h = ctx->Viewport.Height;
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;
734 d3dvp.Y = gldCtx->dwHeight - (y + h);
737 _GLD_DX8_DEV(SetViewport(gld
->pDev
, &d3dvp
));
739 // gld->fFlipWindowY = (float)gldCtx->dwHeight;
742 //---------------------------------------------------------------------------
744 __inline BOOL
_gldAnyEvalEnabled(
747 struct gl_eval_attrib
*eval
= &ctx
->Eval
;
749 if ((eval
->AutoNormal
) ||
750 (eval
->Map1Color4
) ||
752 (eval
->Map1Normal
) ||
753 (eval
->Map1TextureCoord1
) ||
754 (eval
->Map1TextureCoord2
) ||
755 (eval
->Map1TextureCoord3
) ||
756 (eval
->Map1TextureCoord4
) ||
757 (eval
->Map1Vertex3
) ||
758 (eval
->Map1Vertex4
) ||
759 (eval
->Map2Color4
) ||
761 (eval
->Map2Normal
) ||
762 (eval
->Map2TextureCoord1
) ||
763 (eval
->Map2TextureCoord2
) ||
764 (eval
->Map2TextureCoord3
) ||
765 (eval
->Map2TextureCoord4
) ||
766 (eval
->Map2Vertex3
) ||
774 //---------------------------------------------------------------------------
776 BOOL
_gldChooseInternalPipeline(
780 // return TRUE; // DEBUGGING: ALWAYS USE MESA
781 // return FALSE; // DEBUGGING: ALWAYS USE D3D
783 if ((glb
.dwTnL
== GLDS_TNL_MESA
) || (gld
->bHasHWTnL
== FALSE
))
785 gld
->PipelineUsage
.qwMesa
.QuadPart
++;
786 return TRUE
; // Force Mesa TnL
789 if ((ctx
->Light
.Enabled
) ||
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
798 gld
->PipelineUsage
.qwMesa
.QuadPart
++;
802 gld
->PipelineUsage
.qwD3DFVF
.QuadPart
++;
805 /* // Force Mesa pipeline?
806 if (glb.dwTnL == GLDS_TNL_MESA) {
807 gld->PipelineUsage.dwMesa.QuadPart++;
808 return GLD_PIPELINE_MESA;
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;
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) {
823 gld->PipelineUsage.dwD3D2SVS.QuadPart++;
824 return GLD_PIPELINE_D3D_VS_TWOSIDE;
827 gld->PipelineUsage.dwMesa.QuadPart++;
828 return GLD_PIPELINE_MESA;
832 // Must be D3D fixed-function pipeline
833 gld->PipelineUsage.dwD3DFVF.QuadPart++;
834 return GLD_PIPELINE_D3D_FVF;
838 //---------------------------------------------------------------------------
840 void gld_update_state_DX8(
844 GLD_context
*gldCtx
= GLD_GET_CONTEXT(ctx
);
845 GLD_driver_dx8
*gld
= GLD_GET_DX8_DRIVER(gldCtx
);
846 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
849 if (!gld
|| !gld
->pDev
)
852 _swsetup_InvalidateState( ctx
, new_state
);
853 _vbo_InvalidateState( ctx
, new_state
);
854 _tnl_InvalidateState( ctx
, new_state
);
856 // SetupIndex will be used in the pipelines for choosing setup function
857 if ((ctx
->_TriangleCaps
& (DD_TRI_LIGHT_TWOSIDE
| DD_SEPARATE_SPECULAR
)) ||
860 if (ctx
->_TriangleCaps
& DD_FLATSHADE
)
861 gld
->iSetupFunc
= GLD_SI_FLAT_EXTRAS
;
863 gld
->iSetupFunc
= GLD_SI_SMOOTH_EXTRAS
;
865 if (ctx
->_TriangleCaps
& DD_FLATSHADE
)
866 gld
->iSetupFunc
= GLD_SI_FLAT
; // Setup flat shade + texture
868 gld
->iSetupFunc
= GLD_SI_SMOOTH
; // Setup smooth shade + texture
871 gld
->bUseMesaTnL
= _gldChooseInternalPipeline(ctx
, gld
);
872 if (gld
->bUseMesaTnL
) {
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
));
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));
884 _GLD_DX8_DEV(SetRenderState(gld
->pDev
, D3DRS_SOFTWAREVERTEXPROCESSING
, !gld
->bHasHWTnL
));
885 _GLD_DX8_DEV(SetVertexShader(gld
->pDev
, gldPB
->dwFVF
));
889 #define _GLD_TEST_STATE(a) \
890 if (new_state & (a)) { \
895 #define _GLD_TEST_STATE_DX8(a) \
896 if (new_state & (a)) { \
901 #define _GLD_IGNORE_STATE(a) new_state &= ~(a);
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
);
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
);
921 _GLD_IGNORE_STATE(_NEW_TRANSFORM
);
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);
944 #define _GLD_TEST_UNHANDLED_STATE(a) \
945 if (new_state & (a)) { \
946 gldLogMessage(GLDLOG_ERROR, "Unhandled " #a "\n"); \
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
966 #undef _GLD_TEST_STATE
969 //---------------------------------------------------------------------------
971 //---------------------------------------------------------------------------
973 void gld_Viewport_DX8(
980 GLD_context
*gldCtx
= GLD_GET_CONTEXT(ctx
);
981 GLD_driver_dx8
*gld
= GLD_GET_DX8_DRIVER(gldCtx
);
985 if (!gld
|| !gld
->pDev
)
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))
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
);
1001 ddlogPrintf(GLDLOG_SYSTEM
, ">> Viewport x=%d y=%d w=%d h=%d", x
,y
,w
,h
);
1004 // ** D3D viewport must not be outside the render target surface **
1005 // Sanity check the GL viewport dimensions
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
;
1015 d3dvp
.Y
= gldCtx
->dwHeight
- (y
+ h
);
1018 if (ctx
->Viewport
.Near
<= ctx
->Viewport
.Far
) {
1019 d3dvp
.MinZ
= ctx
->Viewport
.Near
;
1020 d3dvp
.MaxZ
= ctx
->Viewport
.Far
;
1022 d3dvp
.MinZ
= ctx
->Viewport
.Far
;
1023 d3dvp
.MaxZ
= ctx
->Viewport
.Near
;
1027 // d3dvp.MinZ = 0.0f;
1028 // d3dvp.MaxZ = 1.0f;
1030 _GLD_DX8_DEV(SetViewport(gld
->pDev
, &d3dvp
));
1034 //---------------------------------------------------------------------------
1036 extern BOOL
dglWglResizeBuffers(GLcontext
*ctx
, BOOL bDefaultDriver
);
1038 // Mesa 5: Parameter change
1039 void gldResizeBuffers_DX8(
1043 GET_CURRENT_CONTEXT(ctx
);
1044 dglWglResizeBuffers(ctx
, TRUE
);
1047 //---------------------------------------------------------------------------
1049 // This is only for debugging.
1050 // To use, plug into ctx->Driver.Enable pointer below.
1057 sprintf(buf
, "Enable: %s (%s)\n", _mesa_lookup_enum_by_nr(e
), b
?"TRUE":"FALSE");
1058 ddlogMessage(DDLOG_SYSTEM
, buf
);
1061 //---------------------------------------------------------------------------
1062 // Driver pointer setup
1063 //---------------------------------------------------------------------------
1065 extern const GLubyte
* _gldGetStringGeneric(GLcontext
*, GLenum
);
1067 void gldSetupDriverPointers_DX8(
1070 GLD_context
*gldCtx
= GLD_GET_CONTEXT(ctx
);
1071 GLD_driver_dx8
*gld
= GLD_GET_DX8_DRIVER(gldCtx
);
1073 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
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
;
1085 // Hardware accumulation buffer
1086 ctx
->Driver
.Accum
= NULL
; // TODO: gld_Accum;
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
;
1095 ctx
->Driver
.ResizeBuffers
= gldResizeBuffers_DX8
;
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
;
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
;
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
;
1119 // Imaging functionality
1120 ctx
->Driver
.CopyColorTable
= NULL
;
1121 ctx
->Driver
.CopyColorSubTable
= NULL
;
1122 ctx
->Driver
.CopyConvolutionFilter1D
= NULL
;
1123 ctx
->Driver
.CopyConvolutionFilter2D
= NULL
;
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
;
1163 _swsetup_Wakeup(ctx
);
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
;
1170 // Hook into glFrustum() and glOrtho()
1171 // ctx->Exec->Frustum = gldFrustumHook_DX8;
1172 // ctx->Exec->Ortho = gldOrthoHook_DX8;
1176 //---------------------------------------------------------------------------