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: GLDirect fastpath pipeline stage
35 ****************************************************************************/
37 //---------------------------------------------------------------------------
39 //#include "../GLDirect.h"
40 //#include "../gld_log.h"
41 //#include "gld_dx8.h"
43 #include "dglcontext.h"
47 //---------------------------------------------------------------------------
56 #include "math/m_matrix.h"
57 #include "math/m_xform.h"
59 #include "tnl/t_pipeline.h"
61 //---------------------------------------------------------------------------
63 __inline
void _gldSetVertexShaderConstants(
67 D3DXMATRIX mat
, matView
, matProj
;
70 // Mesa 5: Altered to a Stack
71 //pM = ctx->ModelView.m;
72 pM
= ctx
->ModelviewMatrixStack
.Top
->m
;
90 // Mesa 5: Altered to a Stack
91 //pM = ctx->ProjectionMatrix.m;
92 pM
= ctx
->ProjectionMatrixStack
.Top
->m
;
103 matProj
._33
= pM
[10];
104 matProj
._34
= pM
[11];
105 matProj
._41
= pM
[12];
106 matProj
._42
= pM
[13];
107 matProj
._43
= pM
[14];
108 matProj
._44
= pM
[15];
110 D3DXMatrixMultiply( &mat
, &matView
, &matProj
);
111 D3DXMatrixTranspose( &mat
, &mat
);
113 _GLD_DX8_DEV(SetVertexShaderConstant(gld
->pDev
, 0, &mat
, 4));
116 //---------------------------------------------------------------------------
118 static GLboolean
gld_d3d_render_stage_run(
120 struct gl_pipeline_stage
*stage
)
122 GLD_context
*gldCtx
= GLD_GET_CONTEXT(ctx
);
123 GLD_driver_dx8
*gld
= GLD_GET_DX8_DRIVER(gldCtx
);
126 struct vertex_buffer
*VB
;
128 tnl_render_func
*tab
;
130 GLD_pb_dx8
*gldPB
= &gld
->PB3d
;
132 static int count = 0;
137 // The "check" function should disable this stage,
138 // but we'll test gld->bUseMesaTnL anyway.
139 if (gld
->bUseMesaTnL
) {
140 // Do nothing in this stage, but continue pipeline
144 tnl
= TNL_CONTEXT(ctx
);
146 new_inputs
= stage
->changed_inputs
;
149 tnl
->Driver
.Render
.Start( ctx
);
152 // For debugging: Useful to see if an app passes colour data in
153 // an unusual format.
154 switch (VB
->ColorPtr
[0]->Type
) {
156 ddlogMessage(GLDLOG_SYSTEM
, "ColorPtr: GL_FLOAT\n");
158 case GL_UNSIGNED_BYTE
:
159 ddlogMessage(GLDLOG_SYSTEM
, "ColorPtr: GL_UNSIGNED_BYTE\n");
162 ddlogMessage(GLDLOG_SYSTEM
, "ColorPtr: *?*\n");
167 tnl
->Driver
.Render
.Points
= gld_Points3D_DX8
;
168 if (ctx
->_TriangleCaps
& DD_FLATSHADE
) {
169 tnl
->Driver
.Render
.Line
= gld_Line3DFlat_DX8
;
170 tnl
->Driver
.Render
.Triangle
= gld_Triangle3DFlat_DX8
;
171 tnl
->Driver
.Render
.Quad
= gld_Quad3DFlat_DX8
;
173 tnl
->Driver
.Render
.Line
= gld_Line3DSmooth_DX8
;
174 tnl
->Driver
.Render
.Triangle
= gld_Triangle3DSmooth_DX8
;
175 tnl
->Driver
.Render
.Quad
= gld_Quad3DSmooth_DX8
;
178 _GLD_DX8_VB(Lock(gldPB
->pVB
, 0, 0, &gldPB
->pPoints
, D3DLOCK_DISCARD
));
179 gldPB
->nPoints
= gldPB
->nLines
= gldPB
->nTriangles
= 0;
180 // Allocate primitive pointers
181 // gldPB->pPoints is always first
182 gldPB
->pLines
= gldPB
->pPoints
+ (gldPB
->dwStride
* gldPB
->iFirstLine
);
183 gldPB
->pTriangles
= gldPB
->pPoints
+ (gldPB
->dwStride
* gldPB
->iFirstTriangle
);
185 ASSERT(tnl
->Driver
.Render
.BuildVertices
);
186 ASSERT(tnl
->Driver
.Render
.PrimitiveNotify
);
187 ASSERT(tnl
->Driver
.Render
.Points
);
188 ASSERT(tnl
->Driver
.Render
.Line
);
189 ASSERT(tnl
->Driver
.Render
.Triangle
);
190 ASSERT(tnl
->Driver
.Render
.Quad
);
191 ASSERT(tnl
->Driver
.Render
.ResetLineStipple
);
192 ASSERT(tnl
->Driver
.Render
.Interp
);
193 ASSERT(tnl
->Driver
.Render
.CopyPV
);
194 ASSERT(tnl
->Driver
.Render
.ClippedLine
);
195 ASSERT(tnl
->Driver
.Render
.ClippedPolygon
);
196 ASSERT(tnl
->Driver
.Render
.Finish
);
198 tab
= (VB
->Elts
? tnl
->Driver
.Render
.PrimTabElts
: tnl
->Driver
.Render
.PrimTabVerts
);
201 GLuint i
, length
, flags
= 0;
202 for (i
= 0 ; !(flags
& PRIM_LAST
) ; i
+= length
)
204 flags
= VB
->Primitive
[i
];
205 length
= VB
->PrimitiveLength
[i
];
206 ASSERT(length
|| (flags
& PRIM_LAST
));
207 ASSERT((flags
& PRIM_MODE_MASK
) <= GL_POLYGON
+1);
209 tab
[flags
& PRIM_MODE_MASK
]( ctx
, i
, i
+ length
, flags
);
211 } while (tnl
->Driver
.Render
.Multipass
&&
212 tnl
->Driver
.Render
.Multipass( ctx
, ++pass
));
214 _GLD_DX8_VB(Unlock(gldPB
->pVB
));
216 _GLD_DX8_DEV(SetStreamSource(gld
->pDev
, 0, gldPB
->pVB
, gldPB
->dwStride
));
218 _GLD_DX8_DEV(SetTransform(gld
->pDev
, D3DTS_PROJECTION
, &gld
->matProjection
));
219 _GLD_DX8_DEV(SetTransform(gld
->pDev
, D3DTS_WORLD
, &gld
->matModelView
));
221 if (gldPB
->nPoints
) {
222 _GLD_DX8_DEV(DrawPrimitive(gld
->pDev
, D3DPT_POINTLIST
, 0, gldPB
->nPoints
));
227 _GLD_DX8_DEV(DrawPrimitive(gld
->pDev
, D3DPT_LINELIST
, gldPB
->iFirstLine
, gldPB
->nLines
));
231 if (gldPB
->nTriangles
) {
232 _GLD_DX8_DEV(DrawPrimitive(gld
->pDev
, D3DPT_TRIANGLELIST
, gldPB
->iFirstTriangle
, gldPB
->nTriangles
));
233 gldPB
->nTriangles
= 0;
236 return GL_FALSE
; /* finished the pipe */
239 //---------------------------------------------------------------------------
241 static void gld_d3d_render_stage_check(
243 struct gl_pipeline_stage
*stage
)
245 GLD_context
*gldCtx
= GLD_GET_CONTEXT(ctx
);
246 GLD_driver_dx8
*gld
= GLD_GET_DX8_DRIVER(gldCtx
);
247 // Is this thread safe?
248 stage
->active
= (gld
->bUseMesaTnL
) ? GL_FALSE
: GL_TRUE
;
252 //---------------------------------------------------------------------------
254 static void gld_d3d_render_stage_dtr( struct gl_pipeline_stage
*stage
)
258 //---------------------------------------------------------------------------
260 const struct gl_pipeline_stage _gld_d3d_render_stage
=
262 "gld_d3d_render_stage",
264 _DD_NEW_SEPARATE_SPECULAR
|
270 _DD_NEW_TRI_UNFILLED
|
271 _NEW_RENDERMODE
), /* re-check (new inputs, interp function) */
272 0, /* re-run (always runs) */
273 GL_TRUE
, /* active */
274 0, 0, /* inputs (set in check_render), outputs */
275 0, 0, /* changed_inputs, private */
276 gld_d3d_render_stage_dtr
, /* destructor */
277 gld_d3d_render_stage_check
, /* check */
278 gld_d3d_render_stage_run
/* run */
281 //---------------------------------------------------------------------------