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_DX7(
229
if ((mode==GL_FRONT_LEFT) || (mode == GL_BACK_LEFT)) {
237
//---------------------------------------------------------------------------
239
static void gld_set_read_buffer_DX7(
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_dx7 *gld = GLD_GET_DX7_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
// D3D7 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_DX7(
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_DX7(
363
//---------------------------------------------------------------------------
365
static void gld_Flush_DX7(
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_dx7 *gld = GLD_GET_DX7_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_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_STENCILENABLE, pStencil->Enabled ? TRUE : FALSE));
393
if (pStencil->Enabled) {
394
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_STENCILFUNC, _gldConvertCompareFunc(pStencil->Function[uiFace])));
395
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_STENCILREF, pStencil->Ref[uiFace]));
396
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_STENCILMASK, pStencil->ValueMask[uiFace]));
397
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_STENCILWRITEMASK, pStencil->WriteMask[uiFace]));
398
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_STENCILFAIL, _gldConvertStencilOp(pStencil->FailFunc[uiFace])));
399
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_STENCILZFAIL, _gldConvertStencilOp(pStencil->ZFailFunc[uiFace])));
400
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_STENCILPASS, _gldConvertStencilOp(pStencil->ZPassFunc[uiFace])));
404
//---------------------------------------------------------------------------
409
GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
410
GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx);
417
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_ALPHAFUNC, _gldConvertCompareFunc(ctx->Color.AlphaFunc)));
418
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_ALPHAREF, (DWORD)ctx->Color.AlphaRef));
419
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_ALPHATESTENABLE, ctx->Color.AlphaEnabled));
422
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_ALPHABLENDENABLE, ctx->Color.BlendEnabled));
423
src = _gldConvertBlendFunc(ctx->Color.BlendSrcRGB, GL_ONE);
424
dest = _gldConvertBlendFunc(ctx->Color.BlendDstRGB, GL_ZERO);
425
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_SRCBLEND, src));
426
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_DESTBLEND, dest));
429
// Color mask - unsupported by DX7
430
if (ctx->Color.ColorMask[0]) dwFlags |= D3DCOLORWRITEENABLE_RED;
431
if (ctx->Color.ColorMask[1]) dwFlags |= D3DCOLORWRITEENABLE_GREEN;
432
if (ctx->Color.ColorMask[2]) dwFlags |= D3DCOLORWRITEENABLE_BLUE;
433
if (ctx->Color.ColorMask[3]) dwFlags |= D3DCOLORWRITEENABLE_ALPHA;
434
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_COLORWRITEENABLE, dwFlags));
438
//---------------------------------------------------------------------------
443
GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
444
GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx);
446
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_ZENABLE, ctx->Depth.Test ? D3DZB_TRUE : D3DZB_FALSE));
447
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_ZFUNC, _gldConvertCompareFunc(ctx->Depth.Func)));
448
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_ZWRITEENABLE, ctx->Depth.Mask ? TRUE : FALSE));
451
//---------------------------------------------------------------------------
453
void gld_NEW_POLYGON(
456
GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
457
GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx);
459
D3DFILLMODE d3dFillMode = D3DFILL_SOLID;
460
D3DCULL d3dCullMode = D3DCULL_NONE;
464
switch (ctx->Polygon.FrontMode) {
466
d3dFillMode = D3DFILL_POINT;
469
d3dFillMode = D3DFILL_WIREFRAME;
472
d3dFillMode = D3DFILL_SOLID;
475
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FILLMODE, d3dFillMode));
477
if (ctx->Polygon.CullFlag) {
478
switch (ctx->Polygon.CullFaceMode) {
480
if (ctx->Polygon.FrontFace == GL_CCW)
481
d3dCullMode = D3DCULL_CW;
483
d3dCullMode = D3DCULL_CCW;
486
if (ctx->Polygon.FrontFace == GL_CCW)
487
d3dCullMode = D3DCULL_CCW;
489
d3dCullMode = D3DCULL_CW;
491
case GL_FRONT_AND_BACK:
492
d3dCullMode = D3DCULL_NONE;
498
d3dCullMode = D3DCULL_NONE;
500
// d3dCullMode = D3DCULL_NONE; // TODO: DEBUGGING
501
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_CULLMODE, d3dCullMode));
504
// ZBIAS ranges from 0 to 16 and can only move towards the viewer
505
// Mesa5: ctx->Polygon._OffsetAny removed
506
if (ctx->Polygon.OffsetFill) {
507
iOffset = (int)ctx->Polygon.OffsetUnits;
511
iOffset = 0; // D3D can't push away
513
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_ZBIAS, iOffset));
516
//---------------------------------------------------------------------------
521
GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
522
GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx);
524
D3DCOLOR d3dFogColour;
525
D3DFOGMODE d3dFogMode = D3DFOG_LINEAR;
527
// TODO: Fog is calculated seperately in the Mesa pipeline
528
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGENABLE, FALSE));
532
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGENABLE, ctx->Fog.Enabled));
533
if (!ctx->Fog.Enabled) {
534
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGTABLEMODE, D3DFOG_NONE));
535
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGVERTEXMODE, D3DFOG_NONE));
536
return; // If disabled, don't bother setting any fog state
540
d3dFogColour = D3DCOLOR_COLORVALUE( ctx->Fog.Color[0],
544
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGCOLOR, d3dFogColour));
547
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGDENSITY, *((DWORD*) (&ctx->Fog.Density))));
550
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGSTART, *((DWORD*) (&ctx->Fog.Start))));
553
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGEND, *((DWORD*) (&ctx->Fog.End))));
556
switch (ctx->Fog.Mode) {
558
d3dFogMode = D3DFOG_LINEAR;
561
d3dFogMode = D3DFOG_EXP;
564
d3dFogMode = D3DFOG_EXP2;
567
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGTABLEMODE, d3dFogMode));
568
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_FOGVERTEXMODE, D3DFOG_NONE));
571
//---------------------------------------------------------------------------
576
GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
577
GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx);
578
DWORD dwSpecularEnable;
581
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_SHADEMODE, (ctx->Light.ShadeModel == GL_SMOOTH) ? D3DSHADE_GOURAUD : D3DSHADE_FLAT));
583
// Separate specular colour
584
if (ctx->Light.Enabled)
585
dwSpecularEnable = (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) ? TRUE: FALSE;
587
dwSpecularEnable = FALSE;
588
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_SPECULARENABLE, dwSpecularEnable));
591
//---------------------------------------------------------------------------
593
void gld_NEW_MODELVIEW(
596
GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
597
GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx);
600
//GLfloat *pM = ctx->ModelView.m;
601
// Mesa5: Model-view is now a stack
602
GLfloat *pM = ctx->ModelviewMatrixStack.Top->m;
636
gld->matModelView = m;
639
//---------------------------------------------------------------------------
641
void gld_NEW_PROJECTION(
644
GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
645
GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx);
648
//GLfloat *pM = ctx->ProjectionMatrix.m;
649
// Mesa 5: Now a stack
650
GLfloat *pM = ctx->ProjectionMatrixStack.Top->m;
663
m._33 = pM[10] / _fPersp_33; // / 1.6f;
668
m._43 = pM[14] / 2.0f;
671
gld->matProjection = m;
674
//---------------------------------------------------------------------------
676
void gldFrustumHook_DX7(
684
GET_CURRENT_CONTEXT(ctx);
685
GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
686
GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx);
688
// Pass values on to Mesa first (in case we mess with them)
689
_mesa_Frustum(left, right, bottom, top, nearval, farval);
691
_fPersp_33 = farval / (nearval - farval);
693
// ddlogPrintf(GLDLOG_SYSTEM, "Frustum: %f", farval/nearval);
696
//---------------------------------------------------------------------------
698
void gldOrthoHook_DX7(
706
GET_CURRENT_CONTEXT(ctx);
707
GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
708
GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx);
710
// Pass values on to Mesa first (in case we mess with them)
711
_mesa_Ortho(left, right, bottom, top, nearval, farval);
715
// ddlogPrintf(GLDLOG_SYSTEM, "Ortho: %f", farval/nearval);
718
//---------------------------------------------------------------------------
720
void gld_NEW_VIEWPORT(
723
GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
724
GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx);
731
_GLD_DX7_DEV(GetViewport(gld->pDev, &d3dvp));
732
// D3D can't do Quake1/Quake2 z-trick
733
if (ctx->Viewport.Near <= ctx->Viewport.Far) {
734
d3dvp.dvMinZ = ctx->Viewport.Near;
735
d3dvp.dvMaxZ = ctx->Viewport.Far;
737
d3dvp.dvMinZ = ctx->Viewport.Far;
738
d3dvp.dvMaxZ = ctx->Viewport.Near;
740
/* x = ctx->Viewport.X;
742
w = ctx->Viewport.Width;
743
h = ctx->Viewport.Height;
746
if (w > gldCtx->dwWidth) w = gldCtx->dwWidth;
747
if (h > gldCtx->dwHeight) h = gldCtx->dwHeight;
748
// Ditto for D3D viewport dimensions
749
if (w+x > gldCtx->dwWidth) w = gldCtx->dwWidth-x;
750
if (h+y > gldCtx->dwHeight) h = gldCtx->dwHeight-y;
752
d3dvp.Y = gldCtx->dwHeight - (y + h);
755
_GLD_DX7_DEV(SetViewport(gld->pDev, &d3dvp));
757
// gld->fFlipWindowY = (float)gldCtx->dwHeight;
760
//---------------------------------------------------------------------------
762
__inline BOOL _gldAnyEvalEnabled(
765
struct gl_eval_attrib *eval = &ctx->Eval;
767
if ((eval->AutoNormal) ||
768
(eval->Map1Color4) ||
770
(eval->Map1Normal) ||
771
(eval->Map1TextureCoord1) ||
772
(eval->Map1TextureCoord2) ||
773
(eval->Map1TextureCoord3) ||
774
(eval->Map1TextureCoord4) ||
775
(eval->Map1Vertex3) ||
776
(eval->Map1Vertex4) ||
777
(eval->Map2Color4) ||
779
(eval->Map2Normal) ||
780
(eval->Map2TextureCoord1) ||
781
(eval->Map2TextureCoord2) ||
782
(eval->Map2TextureCoord3) ||
783
(eval->Map2TextureCoord4) ||
784
(eval->Map2Vertex3) ||
792
//---------------------------------------------------------------------------
794
BOOL _gldChooseInternalPipeline(
798
// return TRUE; // DEBUGGING: ALWAYS USE MESA
799
// return FALSE; // DEBUGGING: ALWAYS USE D3D
801
if ((glb.dwTnL == GLDS_TNL_MESA) || (gld->bHasHWTnL == FALSE))
803
gld->PipelineUsage.qwMesa.QuadPart++;
804
return TRUE; // Force Mesa TnL
807
if ((ctx->Light.Enabled) ||
809
(ctx->Texture._TexGenEnabled) ||
810
(ctx->Texture._TexMatEnabled) ||
811
// (ctx->Transform._AnyClip) ||
812
(ctx->Scissor.Enabled) ||
813
_gldAnyEvalEnabled(ctx) // Put this last so we can early-out
816
gld->PipelineUsage.qwMesa.QuadPart++;
820
gld->PipelineUsage.qwD3DFVF.QuadPart++;
823
/* // Force Mesa pipeline?
824
if (glb.dwTnL == GLDS_TNL_MESA) {
825
gld->PipelineUsage.dwMesa.QuadPart++;
826
return GLD_PIPELINE_MESA;
829
// Test for functionality not exposed in the D3D pathways
830
if ((ctx->Texture._GenFlags)) {
831
gld->PipelineUsage.dwMesa.QuadPart++;
832
return GLD_PIPELINE_MESA;
835
// Now decide if vertex shader can be used.
836
// If two sided lighting is enabled then we must either
837
// use Mesa TnL or the vertex shader
838
if (ctx->_TriangleCaps & DD_TRI_LIGHT_TWOSIDE) {
839
if (gld->VStwosidelight.hShader && !ctx->Fog.Enabled) {
841
gld->PipelineUsage.dwD3D2SVS.QuadPart++;
842
return GLD_PIPELINE_D3D_VS_TWOSIDE;
845
gld->PipelineUsage.dwMesa.QuadPart++;
846
return GLD_PIPELINE_MESA;
850
// Must be D3D fixed-function pipeline
851
gld->PipelineUsage.dwD3DFVF.QuadPart++;
852
return GLD_PIPELINE_D3D_FVF;
856
//---------------------------------------------------------------------------
858
void gld_update_state_DX7(
862
GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
863
GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx);
864
TNLcontext *tnl = TNL_CONTEXT(ctx);
867
if (!gld || !gld->pDev)
870
_swsetup_InvalidateState( ctx, new_state );
871
_vbo_InvalidateState( ctx, new_state );
872
_tnl_InvalidateState( ctx, new_state );
874
// SetupIndex will be used in the pipelines for choosing setup function
875
if ((ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE | DD_SEPARATE_SPECULAR)) ||
878
if (ctx->_TriangleCaps & DD_FLATSHADE)
879
gld->iSetupFunc = GLD_SI_FLAT_EXTRAS;
881
gld->iSetupFunc = GLD_SI_SMOOTH_EXTRAS;
883
if (ctx->_TriangleCaps & DD_FLATSHADE)
884
gld->iSetupFunc = GLD_SI_FLAT; // Setup flat shade + texture
886
gld->iSetupFunc = GLD_SI_SMOOTH; // Setup smooth shade + texture
889
gld->bUseMesaTnL = _gldChooseInternalPipeline(ctx, gld);
890
if (gld->bUseMesaTnL) {
892
// DX7 Does not implement D3DRS_SOFTWAREVERTEXPROCESSING
893
// _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_SOFTWAREVERTEXPROCESSING, TRUE));
894
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_CLIPPING, FALSE));
895
// _GLD_DX7_DEV(SetVertexShader(gld->pDev, gldPB->dwFVF));
898
_GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_CLIPPING, TRUE));
899
// if (gld->TnLPipeline == GLD_PIPELINE_D3D_VS_TWOSIDE) {
900
// _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_SOFTWAREVERTEXPROCESSING, !gld->VStwosidelight.bHardware));
901
// _GLD_DX7_DEV(SetVertexShader(gld->pDev, gld->VStwosidelight.hShader));
903
// DX7 Does not implement D3DRS_SOFTWAREVERTEXPROCESSING
904
// _GLD_DX7_DEV(SetRenderState(gld->pDev, D3DRENDERSTATE_SOFTWAREVERTEXPROCESSING, !gld->bHasHWTnL));
905
// _GLD_DX7_DEV(SetVertexShader(gld->pDev, gldPB->dwFVF));
909
#define _GLD_TEST_STATE(a) \
910
if (new_state & (a)) { \
915
#define _GLD_TEST_STATE_DX7(a) \
916
if (new_state & (a)) { \
921
#define _GLD_IGNORE_STATE(a) new_state &= ~(a);
923
// if (!gld->bUseMesaTnL) {
924
// Not required if Mesa is doing the TnL.
925
// Problem: If gld->bUseMesaTnL is TRUE when these are signaled,
926
// then we'll miss updating the D3D TnL pipeline.
927
// Therefore, don't test for gld->bUseMesaTnL
928
_GLD_TEST_STATE(_NEW_MODELVIEW);
929
_GLD_TEST_STATE(_NEW_PROJECTION);
932
_GLD_TEST_STATE_DX7(_NEW_TEXTURE); // extern, so guard with _DX7
933
_GLD_TEST_STATE(_NEW_COLOR);
934
_GLD_TEST_STATE(_NEW_DEPTH);
935
_GLD_TEST_STATE(_NEW_POLYGON);
936
_GLD_TEST_STATE(_NEW_STENCIL);
937
_GLD_TEST_STATE(_NEW_FOG);
938
_GLD_TEST_STATE(_NEW_LIGHT);
939
_GLD_TEST_STATE(_NEW_VIEWPORT);
941
_GLD_IGNORE_STATE(_NEW_TRANSFORM);
944
// Stubs for future use.
945
/* _GLD_TEST_STATE(_NEW_TEXTURE_MATRIX);
946
_GLD_TEST_STATE(_NEW_COLOR_MATRIX);
947
_GLD_TEST_STATE(_NEW_ACCUM);
948
_GLD_TEST_STATE(_NEW_EVAL);
949
_GLD_TEST_STATE(_NEW_HINT);
950
_GLD_TEST_STATE(_NEW_LINE);
951
_GLD_TEST_STATE(_NEW_PIXEL);
952
_GLD_TEST_STATE(_NEW_POINT);
953
_GLD_TEST_STATE(_NEW_POLYGONSTIPPLE);
954
_GLD_TEST_STATE(_NEW_SCISSOR);
955
_GLD_TEST_STATE(_NEW_PACKUNPACK);
956
_GLD_TEST_STATE(_NEW_ARRAY);
957
_GLD_TEST_STATE(_NEW_RENDERMODE);
958
_GLD_TEST_STATE(_NEW_BUFFERS);
959
_GLD_TEST_STATE(_NEW_MULTISAMPLE);
964
#define _GLD_TEST_UNHANDLED_STATE(a) \
965
if (new_state & (a)) { \
966
gldLogMessage(GLDLOG_ERROR, "Unhandled " #a "\n"); \
968
_GLD_TEST_UNHANDLED_STATE(_NEW_TEXTURE_MATRIX);
969
_GLD_TEST_UNHANDLED_STATE(_NEW_COLOR_MATRIX);
970
_GLD_TEST_UNHANDLED_STATE(_NEW_ACCUM);
971
_GLD_TEST_UNHANDLED_STATE(_NEW_EVAL);
972
_GLD_TEST_UNHANDLED_STATE(_NEW_HINT);
973
_GLD_TEST_UNHANDLED_STATE(_NEW_LINE);
974
_GLD_TEST_UNHANDLED_STATE(_NEW_PIXEL);
975
_GLD_TEST_UNHANDLED_STATE(_NEW_POINT);
976
_GLD_TEST_UNHANDLED_STATE(_NEW_POLYGONSTIPPLE);
977
_GLD_TEST_UNHANDLED_STATE(_NEW_SCISSOR);
978
_GLD_TEST_UNHANDLED_STATE(_NEW_PACKUNPACK);
979
_GLD_TEST_UNHANDLED_STATE(_NEW_ARRAY);
980
_GLD_TEST_UNHANDLED_STATE(_NEW_RENDERMODE);
981
_GLD_TEST_UNHANDLED_STATE(_NEW_BUFFERS);
982
_GLD_TEST_UNHANDLED_STATE(_NEW_MULTISAMPLE);
983
#undef _GLD_UNHANDLED_STATE
986
#undef _GLD_TEST_STATE
989
//---------------------------------------------------------------------------
991
//---------------------------------------------------------------------------
993
void gld_Viewport_DX7(
1000
GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
1001
GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx);
1005
if (!gld || !gld->pDev)
1008
// This is a hack. When the app is minimized, Mesa passes
1009
// w=1 and h=1 for viewport dimensions. Without this test
1010
// we get a GPF in gld_wgl_resize_buffers().
1011
if ((w==1) && (h==1))
1014
// Call ResizeBuffersMESA. This function will early-out
1015
// if no resize is needed.
1016
//ctx->Driver.ResizeBuffersMESA(ctx);
1017
// Mesa 5: Changed parameters
1018
ctx->Driver.ResizeBuffers(gldCtx->glBuffer);
1021
ddlogPrintf(GLDLOG_SYSTEM, ">> Viewport x=%d y=%d w=%d h=%d", x,y,w,h);
1024
// ** D3D viewport must not be outside the render target surface **
1025
// Sanity check the GL viewport dimensions
1028
if (w > gldCtx->dwWidth) w = gldCtx->dwWidth;
1029
if (h > gldCtx->dwHeight) h = gldCtx->dwHeight;
1030
// Ditto for D3D viewport dimensions
1031
if (w+x > gldCtx->dwWidth) w = gldCtx->dwWidth-x;
1032
if (h+y > gldCtx->dwHeight) h = gldCtx->dwHeight-y;
1035
d3dvp.dwY = gldCtx->dwHeight - (y + h);
1038
if (ctx->Viewport.Near <= ctx->Viewport.Far) {
1039
d3dvp.dvMinZ = ctx->Viewport.Near;
1040
d3dvp.dvMaxZ = ctx->Viewport.Far;
1042
d3dvp.dvMinZ = ctx->Viewport.Far;
1043
d3dvp.dvMaxZ = ctx->Viewport.Near;
1047
// d3dvp.MinZ = 0.0f;
1048
// d3dvp.MaxZ = 1.0f;
1050
_GLD_DX7_DEV(SetViewport(gld->pDev, &d3dvp));
1054
//---------------------------------------------------------------------------
1056
extern BOOL dglWglResizeBuffers(GLcontext *ctx, BOOL bDefaultDriver);
1058
// Mesa 5: Parameter change
1059
void gldResizeBuffers_DX7(
1063
GET_CURRENT_CONTEXT(ctx);
1064
dglWglResizeBuffers(ctx, TRUE);
1067
//---------------------------------------------------------------------------
1069
// This is only for debugging.
1070
// To use, plug into ctx->Driver.Enable pointer below.
1077
sprintf(buf, "Enable: %s (%s)\n", _mesa_lookup_enum_by_nr(e), b?"TRUE":"FALSE");
1078
ddlogMessage(DDLOG_SYSTEM, buf);
1081
//---------------------------------------------------------------------------
1082
// Driver pointer setup
1083
//---------------------------------------------------------------------------
1085
extern const GLubyte* _gldGetStringGeneric(GLcontext*, GLenum);
1087
void gldSetupDriverPointers_DX7(
1090
GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
1091
GLD_driver_dx7 *gld = GLD_GET_DX7_DRIVER(gldCtx);
1093
TNLcontext *tnl = TNL_CONTEXT(ctx);
1095
// Mandatory functions
1096
ctx->Driver.GetString = _gldGetStringGeneric;
1097
ctx->Driver.UpdateState = gld_update_state_DX7;
1098
ctx->Driver.Clear = gld_Clear_DX7;
1099
ctx->Driver.DrawBuffer = gld_set_draw_buffer_DX7;
1100
ctx->Driver.GetBufferSize = gld_buffer_size_DX7;
1101
ctx->Driver.Finish = gld_Finish_DX7;
1102
ctx->Driver.Flush = gld_Flush_DX7;
1103
ctx->Driver.Error = gld_Error_DX7;
1105
// Hardware accumulation buffer
1106
ctx->Driver.Accum = NULL; // TODO: gld_Accum;
1109
ctx->Driver.CopyPixels = gld_CopyPixels_DX7;
1110
ctx->Driver.DrawPixels = gld_DrawPixels_DX7;
1111
ctx->Driver.ReadPixels = gld_ReadPixels_DX7;
1112
ctx->Driver.Bitmap = gld_Bitmap_DX7;
1115
ctx->Driver.ResizeBuffers = gldResizeBuffers_DX7;
1117
// Texture image functions
1118
ctx->Driver.ChooseTextureFormat = gld_ChooseTextureFormat_DX7;
1119
ctx->Driver.TexImage1D = gld_TexImage1D_DX7;
1120
ctx->Driver.TexImage2D = gld_TexImage2D_DX7;
1121
ctx->Driver.TexImage3D = _mesa_store_teximage3d;
1122
ctx->Driver.TexSubImage1D = gld_TexSubImage1D_DX7;
1123
ctx->Driver.TexSubImage2D = gld_TexSubImage2D_DX7;
1124
ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d;
1126
ctx->Driver.CopyTexImage1D = gldCopyTexImage1D_DX7; //NULL;
1127
ctx->Driver.CopyTexImage2D = gldCopyTexImage2D_DX7; //NULL;
1128
ctx->Driver.CopyTexSubImage1D = gldCopyTexSubImage1D_DX7; //NULL;
1129
ctx->Driver.CopyTexSubImage2D = gldCopyTexSubImage2D_DX7; //NULL;
1130
ctx->Driver.CopyTexSubImage3D = gldCopyTexSubImage3D_DX7;
1131
ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage;
1133
// Texture object functions
1134
ctx->Driver.BindTexture = NULL;
1135
ctx->Driver.NewTextureObject = NULL; // Not yet implemented by Mesa!;
1136
ctx->Driver.DeleteTexture = gld_DeleteTexture_DX7;
1137
ctx->Driver.PrioritizeTexture = NULL;
1139
// Imaging functionality
1140
ctx->Driver.CopyColorTable = NULL;
1141
ctx->Driver.CopyColorSubTable = NULL;
1142
ctx->Driver.CopyConvolutionFilter1D = NULL;
1143
ctx->Driver.CopyConvolutionFilter2D = NULL;
1145
// State changing functions
1146
ctx->Driver.AlphaFunc = NULL; //gld_AlphaFunc;
1147
ctx->Driver.BlendFuncSeparate = NULL; //gld_BlendFunc;
1148
ctx->Driver.ClearColor = NULL; //gld_ClearColor;
1149
ctx->Driver.ClearDepth = NULL; //gld_ClearDepth;
1150
ctx->Driver.ClearStencil = NULL; //gld_ClearStencil;
1151
ctx->Driver.ColorMask = NULL; //gld_ColorMask;
1152
ctx->Driver.CullFace = NULL; //gld_CullFace;
1153
ctx->Driver.ClipPlane = NULL; //gld_ClipPlane;
1154
ctx->Driver.FrontFace = NULL; //gld_FrontFace;
1155
ctx->Driver.DepthFunc = NULL; //gld_DepthFunc;
1156
ctx->Driver.DepthMask = NULL; //gld_DepthMask;
1157
ctx->Driver.DepthRange = NULL;
1158
ctx->Driver.Enable = NULL; //gld_Enable;
1159
ctx->Driver.Fogfv = NULL; //gld_Fogfv;
1160
ctx->Driver.Hint = NULL; //gld_Hint;
1161
ctx->Driver.Lightfv = NULL; //gld_Lightfv;
1162
ctx->Driver.LightModelfv = NULL; //gld_LightModelfv;
1163
ctx->Driver.LineStipple = NULL; //gld_LineStipple;
1164
ctx->Driver.LineWidth = NULL; //gld_LineWidth;
1165
ctx->Driver.LogicOpcode = NULL; //gld_LogicOpcode;
1166
ctx->Driver.PointParameterfv = NULL; //gld_PointParameterfv;
1167
ctx->Driver.PointSize = NULL; //gld_PointSize;
1168
ctx->Driver.PolygonMode = NULL; //gld_PolygonMode;
1169
ctx->Driver.PolygonOffset = NULL; //gld_PolygonOffset;
1170
ctx->Driver.PolygonStipple = NULL; //gld_PolygonStipple;
1171
ctx->Driver.RenderMode = NULL; //gld_RenderMode;
1172
ctx->Driver.Scissor = NULL; //gld_Scissor;
1173
ctx->Driver.ShadeModel = NULL; //gld_ShadeModel;
1174
ctx->Driver.StencilFunc = NULL; //gld_StencilFunc;
1175
ctx->Driver.StencilMask = NULL; //gld_StencilMask;
1176
ctx->Driver.StencilOp = NULL; //gld_StencilOp;
1177
ctx->Driver.TexGen = NULL; //gld_TexGen;
1178
ctx->Driver.TexEnv = NULL;
1179
ctx->Driver.TexParameter = NULL;
1180
ctx->Driver.TextureMatrix = NULL; //gld_TextureMatrix;
1181
ctx->Driver.Viewport = gld_Viewport_DX7;
1183
_swsetup_Wakeup(ctx);
1185
tnl->Driver.RunPipeline = _tnl_run_pipeline;
1186
tnl->Driver.Render.ResetLineStipple = gld_ResetLineStipple_DX7;
1187
tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon;
1188
tnl->Driver.Render.ClippedLine = _tnl_RenderClippedLine;
1190
// Hook into glFrustum() and glOrtho()
1191
// ctx->Exec->Frustum = gldFrustumHook_DX7;
1192
// ctx->Exec->Ortho = gldOrthoHook_DX7;
1196
//---------------------------------------------------------------------------