1 /*===========================================================================*/
3 /* Mesa-3.0 DirectX 6 Driver */
7 /* http://www.altsoftware.com/ */
9 /* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */
10 /*===========================================================================*/
26 static void SetRenderStates( GLcontext
*ctx
);
27 static void DebugRenderStates( GLcontext
*ctx
, BOOL bForce
);
29 static void RenderPointsVB( GLcontext
*ctx
, GLuint start
, GLuint end
);
30 static void RenderTriangleVB( GLcontext
*ctx
, GLuint start
, GLuint end
);
31 static void RenderTriangleFanVB( GLcontext
*ctx
, GLuint start
, GLuint end
);
32 static void RenderTriangleStripVB( GLcontext
*ctx
, GLuint start
, GLuint end
);
33 static void RenderQuadVB( GLcontext
*ctx
, GLuint start
, GLuint end
);
34 static void RenderQuad( GLcontext
*ctx
, GLuint v1
, GLuint v2
, GLuint v3
, GLuint v4
, GLuint pv
);
35 void RenderOneTriangle( GLcontext
*ctx
, GLuint v1
, GLuint v2
, GLuint v3
, GLuint pv
);
36 void RenderOneLine( GLcontext
*ctx
, GLuint v1
, GLuint v2
, GLuint pv
);
38 /* I went with a D3D vertex buffer that is 6 times that of the Mesa one */
39 /* instead of having the D3D one flush when its full. This way Mesa will*/
40 /* handle all the flushing. I need x6 as points can use 4 vertex each. */
41 D3DTLVERTEX D3DTLVertices
[ (VB_MAX
*6) ];
42 GLuint VList
[VB_SIZE
];
43 /*===========================================================================*/
44 /* Compute Z offsets for a polygon with plane defined by (A,B,C,D) */
45 /* D is not needed. TODO: Currently we are calculating this but not using it.*/
46 /*===========================================================================*/
48 /*===========================================================================*/
49 static void OffsetPolygon( GLcontext
*ctx
, GLfloat a
, GLfloat b
, GLfloat c
)
56 DPF(( DBG_FUNC
, "OffsetPolygon();" ));
58 if ( (c
< 0.001F
) && (c
> - 0.001F
) )
60 /* Prevents underflow problems. */
61 ctx
->PointZoffset
= 0.0F
;
62 ctx
->LineZoffset
= 0.0F
;
63 ctx
->PolygonZoffset
= 0.0F
;
73 m
= MAX2( ac
, bc
); /* m = sqrt( ac*ac + bc*bc ); */
75 offset
= (m
* ctx
->Polygon
.OffsetFactor
+ ctx
->Polygon
.OffsetUnits
);
76 ctx
->PointZoffset
= ctx
->Polygon
.OffsetPoint
? offset
: 0.0F
;
77 ctx
->LineZoffset
= ctx
->Polygon
.OffsetLine
? offset
: 0.0F
;
78 ctx
->PolygonZoffset
= ctx
->Polygon
.OffsetFill
? offset
: 0.0F
;
81 DPF(( DBG_PRIM_INFO
, "OffsetPolygon: %f", offset
));
83 /*===========================================================================*/
84 /* Compute signed area of the n-sided polgyon specified by vertices */
85 /* vb->Win[] and vertex list vlist[]. */
86 /* A clockwise polygon will return a negative area. A counter-clockwise */
87 /* polygon will return a positive area. I have changed this function to */
88 /* actually calculate twice the area as its faster and still gives the sign. */
89 /*===========================================================================*/
90 /* RETURN: signed area of the polgon. */
91 /*===========================================================================*/
92 static GLfloat
PolygonArea( const struct vertex_buffer
*vb
, GLuint n
, const GLuint vlist
[] )
97 DPF(( DBG_FUNC
, "PolygonArea();" ));
100 #define j1 vlist[(i+1)%n]
101 #define x0 vb->Win[j0][0]
102 #define y0 vb->Win[j0][1]
103 #define x1 vb->Win[j1][0]
104 #define y1 vb->Win[j1][1]
106 /* area = sum of trapezoids */
107 for( i
= 0, area
= 0.0; i
< n
; i
++ )
108 area
+= ((x0
- x1
) * (y0
+ y1
)); /* Note: no divide by two here! */
117 // TODO: I don't see the point or * 0.5 as we just want the sign...
120 /*===========================================================================*/
121 /* Render a polygon that needs clipping on at least one vertex. The function*/
122 /* will first clip the polygon to any user clipping planes then clip to the */
123 /* viewing volume. The final polygon will be draw as single triangles that */
124 /* first need minor proccessing (culling, offset, etc) before we draw the */
125 /* polygon as a fan. NOTE: the fan is draw as single triangles as its not */
126 /* formed sequentaly in the VB but is in the vlist[]. */
127 /*===========================================================================*/
129 /*===========================================================================*/
130 static void RenderClippedPolygon( GLcontext
*ctx
, GLuint n
, GLuint vlist
[] )
132 struct vertex_buffer
*VB
= ctx
->VB
;
133 GLfloat (*win
)[3] = VB
->Win
,
134 *proj
= ctx
->ProjectionMatrix
,
142 DPF(( DBG_FUNC
, "RenderClippedPolygon();" ));
144 DPF(( DBG_PRIM_INFO
, "RenderClippedtPolygon( %d )", n
));
146 /* Which vertex dictates the color when flat shading. */
147 pv
= (ctx
->Primitive
==GL_POLYGON
) ? vlist
[0] : vlist
[n
-1];
149 /* Clipping may introduce new vertices. New vertices will be stored in */
150 /* the vertex buffer arrays starting with location VB->Free. After we've*/
151 /* rendered the polygon, these extra vertices can be overwritten. */
154 /* Clip against user clipping planes in eye coord space. */
155 if ( ctx
->Transform
.AnyClip
)
157 n
= gl_userclip_polygon( ctx
, n
, vlist
);
161 /* Transform vertices from eye to clip coordinates: clip = Proj * eye */
162 for( index
= 0; index
< n
; index
++ )
164 TRANSFORM_POINT( VB
->Clip
[vlist
[index
]], proj
, VB
->Eye
[vlist
[index
]] );
168 /* Clip against view volume in clip coord space */
169 n
= gl_viewclip_polygon( ctx
, n
, vlist
);
173 /* Transform new vertices from clip to ndc to window coords. */
174 /* ndc = clip / W window = viewport_mapping(ndc) */
175 /* Note that window Z values are scaled to the range of integer */
176 /* depth buffer values. */
178 /* Only need to compute window coords for new vertices */
179 for( index
= VB_MAX
; index
< VB
->Free
; index
++ )
181 if ( VB
->Clip
[index
][3] != 0.0F
)
183 wInv
= 1.0F
/ VB
->Clip
[index
][3];
185 win
[index
][0] = VB
->Clip
[index
][0] * wInv
* ctx
->Viewport
.Sx
+ ctx
->Viewport
.Tx
;
186 win
[index
][1] = VB
->Clip
[index
][1] * wInv
* ctx
->Viewport
.Sy
+ ctx
->Viewport
.Ty
;
187 win
[index
][2] = VB
->Clip
[index
][2] * wInv
* ctx
->Viewport
.Sz
+ ctx
->Viewport
.Tz
;
191 /* Can't divide by zero, so... */
192 win
[index
][0] = win
[index
][1] = win
[index
][2] = 0.0F
;
196 /* Draw filled polygon as a triangle fan */
197 for( index
= 2; index
< n
; index
++ )
199 /* Compute orientation of triangle */
200 ex
= win
[vlist
[index
-1]][0] - win
[vlist
[0]][0];
201 ey
= win
[vlist
[index
-1]][1] - win
[vlist
[0]][1];
202 fx
= win
[vlist
[index
]][0] - win
[vlist
[0]][0];
203 fy
= win
[vlist
[index
]][1] - win
[vlist
[0]][1];
204 c
= (ex
* fy
) - (ey
* fx
);
206 /* polygon is perpindicular to view plane, don't draw it */
207 if ( (c
== 0.0F
) && !ctx
->Polygon
.Unfilled
)
210 /* Backface culling. */
211 facing
= (c
< 0.0F
) ^ ctx
->Polygon
.FrontBit
;
212 if ( (facing
+ 1) & ctx
->Polygon
.CullBits
)
215 if ( ctx
->IndirectTriangles
& DD_TRI_LIGHT_TWOSIDE
)
220 VB
->Color
= VB
->Bcolor
;
221 VB
->Specular
= VB
->Bspec
;
225 /* use front color */
226 VB
->Color
= VB
->Fcolor
;
227 VB
->Specular
= VB
->Fspec
;
231 if ( ctx
->IndirectTriangles
& DD_TRI_OFFSET
)
233 /* finish computing plane equation of polygon, compute offset */
234 GLfloat fz
= win
[vlist
[index
]][2] - win
[vlist
[0]][2];
235 GLfloat ez
= win
[vlist
[index
-1]][2] - win
[vlist
[0]][2];
236 GLfloat a
= (ey
* fz
) - (ez
* fy
);
237 GLfloat b
= (ez
* fx
) - (ex
* fz
);
238 OffsetPolygon( ctx
, a
, b
, c
);
240 RenderOneTriangle( ctx
, vlist
[0], vlist
[index
-1], vlist
[index
], pv
);
243 /*===========================================================================*/
244 /* This function gets called when either the vertex buffer is full or glEnd */
245 /* has been called. If the we aren't in rendering mode (FEEDBACK) then I */
246 /* pass the vertex buffer back to Mesa to deal with by returning FALSE. */
247 /* If I can render the primitive types in the buffer directly then I will */
248 /* return TRUE after I render the vertex buffer and reset the vertex buffer. */
250 /* TODO: I don't handle the special case of when the vertex buffer is full */
251 /* and we have a primitive that bounds this buffer and the next one to */
252 /* come. I'm not sure right now if Mesa handles this for me... */
253 /*===========================================================================*/
254 /* RETURN: TRUE, FALSE. */
255 /*===========================================================================*/
256 GLboolean
RenderVertexBuffer( GLcontext
*ctx
, GLboolean allDone
)
258 struct vertex_buffer
*VB
= ctx
->VB
;
262 DPF(( DBG_FUNC
, "RenderVertexBuffer();" ));
264 /* We only need to hook actual tri's that need rendering. */
265 if ( ctx
->RenderMode
!= GL_RENDER
)
267 // (ctx->Visual->AccumBits > 0) )
268 // (ctx->Visual->StencilBits > 0) )
269 DPF(( DBG_PRIM_INFO
, "Passing VB back to Mesa" ));
273 /* I'm going to set the states here so that all functions will */
274 /* be assured to have the right states. If Mesa's vertex bufefr */
275 /* function calls one of my primitive functions (TRI,POINT,LINE) */
276 /* it will need the right states. So instead of doing it in the */
277 /* primitive function I will always do it here at risk of some */
278 /* slow down to some cases... */
279 SetRenderStates( ctx
);
281 switch( ctx
->Primitive
)
284 DPF(( DBG_PRIM_INFO
, "GL_POINTS( %d )", VB
->Count
));
285 RenderPointsVB( ctx
, 0, VB
->Count
);
291 /* Not supported functions yet so pass back that we failed to */
292 /* render the vertex buffer and Mesa will have to do it. */
293 DPF(( DBG_PRIM_INFO
, "GL_LINE_?( %d )", VB
->Count
));
299 DPF(( DBG_PRIM_WARN
, "GL_TRIANGLES( %d )", VB
->Count
));
303 DPF(( DBG_PRIM_INFO
, "GL_TRIANGLES( %d )", VB
->Count
));
304 RenderTriangleVB( ctx
, 0, VB
->Count
);
307 case GL_TRIANGLE_STRIP
:
310 DPF(( DBG_PRIM_WARN
, "GL_TRIANGLE_STRIP( %d )", VB
->Count
));
314 DPF(( DBG_PRIM_INFO
, "GL_TRIANGLE_STRIP( %d )", VB
->Count
));
315 RenderTriangleStripVB( ctx
, 0, VB
->Count
);
318 case GL_TRIANGLE_FAN
:
321 DPF(( DBG_PRIM_WARN
, "GL_TRIANGLE_FAN( %d )", VB
->Count
));
325 DPF(( DBG_PRIM_INFO
, "GL_TRIANGLE_FAN( %d )", VB
->Count
));
326 RenderTriangleFanVB( ctx
, 0, VB
->Count
);
332 DPF(( DBG_PRIM_WARN
, "GL_QUADS( %d )", VB
->Count
));
336 DPF(( DBG_PRIM_INFO
, "GL_QUADS( %d )", VB
->Count
));
337 RenderQuadVB( ctx
, 0, VB
->Count
);
343 DPF(( DBG_PRIM_WARN
, "GL_QUAD_STRIP( %d )", VB
->Count
));
347 DPF(( DBG_PRIM_INFO
, "GL_QUAD_STRIP( %d )", VB
->Count
));
349 if ( VB
->ClipOrMask
)
351 for( index
= 3; index
< VB
->Count
; index
+= 2 )
353 if ( VB
->ClipMask
[index
-3] & VB
->ClipMask
[index
-2] & VB
->ClipMask
[index
-1] & VB
->ClipMask
[index
] & CLIP_ALL_BITS
)
355 /* All points clipped by common plane */
356 DPF(( DBG_PRIM_WARN
, "GL_QUAD_STRIP( %d )", VB
->Count
));
359 else if ( VB
->ClipMask
[index
-3] | VB
->ClipMask
[index
-2] | VB
->ClipMask
[index
-1] | VB
->ClipMask
[index
] )
361 vlist
[0] = index
- 3;
362 vlist
[1] = index
- 2;
364 vlist
[3] = index
- 1;
365 RenderClippedPolygon( ctx
, 4, vlist
);
369 RenderQuad( ctx
, (index
-3), (index
-2), index
, (index
-1), index
);
375 /* No clipping needed */
376 for( index
= 3; index
< VB
->Count
; index
+= 2 )
377 RenderQuad( ctx
, (index
-3), (index
-2), index
, (index
-1), index
);
384 DPF(( DBG_PRIM_WARN
, "GL_POLYGON( %d )", VB
->Count
));
388 DPF(( DBG_PRIM_INFO
, "GL_POLYGON( %d )", VB
->Count
));
390 /* All points clipped by common plane, draw nothing */
391 if ( !(VB
->ClipAndMask
& CLIP_ALL_BITS
) )
392 RenderTriangleFanVB( ctx
, 0, VB
->Count
);
396 /* should never get here */
397 _mesa_problem( ctx
, "invalid mode in gl_render_vb" );
400 DPF(( DBG_PRIM_INFO
, "ResetVB" ));
402 /* We return TRUE to indicate we rendered the VB. */
403 gl_reset_vb( ctx
, allDone
);
406 /*===========================================================================*/
407 /* This function will render the current vertex buffer as triangles. The */
408 /* buffer has to be able to be rendered directly. This means that we are */
409 /* filled, no offsets, no culling and one sided rendering. Also we must be */
410 /* in render mode of course. */
411 /* First I will fill the global D3D vertice buffer. Next I will set all the*/
412 /* states for D3D based on the current OGL state. Finally I pass the D3D VB */
413 /* to the wrapper that call DrawPrimitives. */
414 /*===========================================================================*/
416 /*===========================================================================*/
417 static void RenderTriangleVB( GLcontext
*ctx
, GLuint start
, GLuint end
)
419 D3DMESACONTEXT
*pContext
= (D3DMESACONTEXT
*)ctx
->DriverCtx
;
420 struct vertex_buffer
*VB
= ctx
->VB
;
423 height
= (pContext
->pShared
->rectW
.bottom
- pContext
->pShared
->rectW
.top
);
429 DPF(( DBG_FUNC
, "RenderTriangleVB" ));
431 if ( !VB
->ClipOrMask
)
433 DPF(( DBG_PRIM_INFO
, "DirectTriangles( %d )", (end
-start
) ));
434 for( index
= start
, cVertex
= 0; index
< end
; )
436 dwPVColor
= (VB
->Color
[(index
+2)][3]<<24) | (VB
->Color
[(index
+2)][0]<<16) | (VB
->Color
[(index
+2)][1]<<8) | VB
->Color
[(index
+2)][2];
438 /*=====================================*/
439 /* Populate the the triangle vertices. */
440 /*=====================================*/
441 D3DTLVertices
[cVertex
].sx
= D3DVAL( VB
->Win
[index
][0] );
442 D3DTLVertices
[cVertex
].sy
= D3DVAL( (height
- VB
->Win
[index
][1]) );
443 D3DTLVertices
[cVertex
].sz
= D3DVAL( VB
->Win
[index
][2] );
444 D3DTLVertices
[cVertex
].tu
= D3DVAL( VB
->TexCoord
[index
][0] );
445 D3DTLVertices
[cVertex
].tv
= D3DVAL( VB
->TexCoord
[index
][1] );
446 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[index
][3]) );
447 D3DTLVertices
[cVertex
++].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ?
449 (VB
->Color
[index
][3]<<24) | (VB
->Color
[index
][0]<<16) | (VB
->Color
[index
][1]<<8) | VB
->Color
[index
][2];
452 D3DTLVertices
[cVertex
].sx
= D3DVAL( VB
->Win
[index
][0] );
453 D3DTLVertices
[cVertex
].sy
= D3DVAL( (height
- VB
->Win
[index
][1]) );
454 D3DTLVertices
[cVertex
].sz
= D3DVAL( VB
->Win
[index
][2] );
455 D3DTLVertices
[cVertex
].tu
= D3DVAL( VB
->TexCoord
[index
][0] );
456 D3DTLVertices
[cVertex
].tv
= D3DVAL( VB
->TexCoord
[index
][1] );
457 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[index
][3]) );
458 D3DTLVertices
[cVertex
++].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ?
460 (VB
->Color
[index
][3]<<24) | (VB
->Color
[index
][0]<<16) | (VB
->Color
[index
][1]<<8) | VB
->Color
[index
][2];
463 D3DTLVertices
[cVertex
].sx
= D3DVAL( VB
->Win
[index
][0] );
464 D3DTLVertices
[cVertex
].sy
= D3DVAL( (height
- VB
->Win
[index
][1]) );
465 D3DTLVertices
[cVertex
].sz
= D3DVAL( VB
->Win
[index
][2] );
466 D3DTLVertices
[cVertex
].tu
= D3DVAL( VB
->TexCoord
[index
][0] );
467 D3DTLVertices
[cVertex
].tv
= D3DVAL( VB
->TexCoord
[index
][1] );
468 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[index
][3]) );
469 D3DTLVertices
[cVertex
++].color
= dwPVColor
;
479 for( index
= start
, cVertex
= 0; index
< end
; index
+= 3 )
481 if ( VB
->ClipMask
[v1
] & VB
->ClipMask
[v2
] & VB
->ClipMask
[v3
] & CLIP_ALL_BITS
)
485 else if ( VB
->ClipMask
[v1
] | VB
->ClipMask
[v2
] | VB
->ClipMask
[v3
] )
490 RenderClippedPolygon( ctx
, 3, VList
);
494 /* Compute orientation of triangle */
495 ex
= VB
->Win
[v2
][0] - VB
->Win
[v1
][0];
496 ey
= VB
->Win
[v2
][1] - VB
->Win
[v1
][1];
497 fx
= VB
->Win
[v3
][0] - VB
->Win
[v1
][0];
498 fy
= VB
->Win
[v3
][1] - VB
->Win
[v1
][1];
499 c
= (ex
* fy
) - (ey
* fx
);
501 /* polygon is perpindicular to view plane, don't draw it */
502 if ( (c
== 0.0F
) && !ctx
->Polygon
.Unfilled
)
505 /* Backface culling. */
506 facing
= (c
< 0.0F
) ^ ctx
->Polygon
.FrontBit
;
507 if ( (facing
+ 1) & ctx
->Polygon
.CullBits
)
510 if ( ctx
->IndirectTriangles
& DD_TRI_LIGHT_TWOSIDE
)
515 VB
->Color
= VB
->Bcolor
;
516 VB
->Specular
= VB
->Bspec
;
520 /* use front color */
521 VB
->Color
= VB
->Fcolor
;
522 VB
->Specular
= VB
->Fspec
;
526 if ( ctx
->IndirectTriangles
& DD_TRI_OFFSET
)
528 /* Finish computing plane equation of polygon, compute offset */
529 GLfloat fz
= VB
->Win
[v3
][2] - VB
->Win
[v1
][2];
530 GLfloat ez
= VB
->Win
[v2
][2] - VB
->Win
[v1
][2];
531 GLfloat a
= (ey
* fz
) - (ez
* fy
);
532 GLfloat b
= (ez
* fx
) - (ex
* fz
);
533 OffsetPolygon( ctx
, a
, b
, c
);
536 /*=====================================*/
537 /* Populate the the triangle vertices. */
538 /*=====================================*/
539 /* Solve the prevoking vertex color as we need it for the 3rd triangle and flat shading. */
540 dwPVColor
= (VB
->Color
[v3
][3]<<24) | (VB
->Color
[v3
][0]<<16) | (VB
->Color
[v3
][1]<<8) | VB
->Color
[v3
][2];
542 D3DTLVertices
[cVertex
].sx
= D3DVAL( VB
->Win
[v1
][0] );
543 D3DTLVertices
[cVertex
].sy
= D3DVAL( (height
- VB
->Win
[v1
][1]) );
544 D3DTLVertices
[cVertex
].sz
= D3DVAL( (VB
->Win
[v1
][2] + ctx
->PolygonZoffset
) );
545 D3DTLVertices
[cVertex
].tu
= D3DVAL( VB
->TexCoord
[v1
][0] );
546 D3DTLVertices
[cVertex
].tv
= D3DVAL( VB
->TexCoord
[v1
][1] );
547 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[v1
][3]) );
548 D3DTLVertices
[cVertex
++].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ?
550 (VB
->Color
[v1
][3]<<24) | (VB
->Color
[v1
][0]<<16) | (VB
->Color
[v1
][1]<<8) | VB
->Color
[v1
][2];
552 D3DTLVertices
[cVertex
].sx
= D3DVAL( VB
->Win
[v2
][0] );
553 D3DTLVertices
[cVertex
].sy
= D3DVAL( (height
- VB
->Win
[v2
][1]) );
554 D3DTLVertices
[cVertex
].sz
= D3DVAL( (VB
->Win
[v2
][2] + ctx
->PolygonZoffset
) );
555 D3DTLVertices
[cVertex
].tu
= D3DVAL( VB
->TexCoord
[v2
][0] );
556 D3DTLVertices
[cVertex
].tv
= D3DVAL( VB
->TexCoord
[v2
][1] );
557 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[v2
][3]) );
558 D3DTLVertices
[cVertex
++].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ?
560 (VB
->Color
[v2
][3]<<24) | (VB
->Color
[v2
][0]<<16) | (VB
->Color
[v2
][1]<<8) | VB
->Color
[v2
][2];
562 D3DTLVertices
[cVertex
].sx
= D3DVAL( VB
->Win
[v3
][0] );
563 D3DTLVertices
[cVertex
].sy
= D3DVAL( (height
- VB
->Win
[v3
][1]) );
564 D3DTLVertices
[cVertex
].sz
= D3DVAL( (VB
->Win
[v3
][2] + ctx
->PolygonZoffset
) );
565 D3DTLVertices
[cVertex
].tu
= D3DVAL( VB
->TexCoord
[v3
][0] );
566 D3DTLVertices
[cVertex
].tv
= D3DVAL( VB
->TexCoord
[v3
][1] );
567 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[v3
][3]) );
568 D3DTLVertices
[cVertex
++].color
= dwPVColor
;
575 /* Render the converted vertex buffer. */
577 DrawPrimitiveHAL( pContext
->pShared
, D3DPT_TRIANGLELIST
, &D3DTLVertices
[0], cVertex
);
579 /*===========================================================================*/
580 /* This function will render the current vertex buffer as a triangle fan. */
581 /* The buffer has to be able to be rendered directly. This means that we are*/
582 /* filled, no offsets, no culling and one sided rendering. Also we must be */
583 /* in render mode of course. */
584 /* First I will fill the global D3D vertice buffer. Next I will set all the*/
585 /* states for D3D based on the current OGL state. Finally I pass the D3D VB */
586 /* to the wrapper that call DrawPrimitives. */
587 /*===========================================================================*/
589 /*===========================================================================*/
590 static void RenderTriangleFanVB( GLcontext
*ctx
, GLuint start
, GLuint end
)
592 D3DMESACONTEXT
*pContext
= (D3DMESACONTEXT
*)ctx
->DriverCtx
;
593 struct vertex_buffer
*VB
= ctx
->VB
;
596 height
= (pContext
->pShared
->rectW
.bottom
- pContext
->pShared
->rectW
.top
);
602 DPF(( DBG_FUNC
, "RenderTriangleFanVB();" ));
604 /* Special case that we can blast the fan without culling, offset, etc... */
605 if ( !VB
->ClipOrMask
&& (ctx
->Light
.ShadeModel
!= GL_FLAT
) )
607 DPF(( DBG_PRIM_INFO
, "DirectTriangles( %d )", (end
-start
) ));
609 /* Seed the the fan. */
610 D3DTLVertices
[0].sx
= D3DVAL( VB
->Win
[start
][0] );
611 D3DTLVertices
[0].sy
= D3DVAL( (height
- VB
->Win
[start
][1]) );
612 D3DTLVertices
[0].sz
= D3DVAL( VB
->Win
[start
][2] );
613 D3DTLVertices
[0].tu
= D3DVAL( VB
->TexCoord
[start
][0] );
614 D3DTLVertices
[0].tv
= D3DVAL( VB
->TexCoord
[start
][1] );
615 D3DTLVertices
[0].rhw
= D3DVAL( (1.0 / VB
->Clip
[start
][3]) );
616 D3DTLVertices
[0].color
= (VB
->Color
[start
][3]<<24) | (VB
->Color
[start
][0]<<16) | (VB
->Color
[start
][1]<<8) | VB
->Color
[start
][2];
618 /* Seed the the fan. */
619 D3DTLVertices
[1].sx
= D3DVAL( VB
->Win
[(start
+1)][0] );
620 D3DTLVertices
[1].sy
= D3DVAL( (height
- VB
->Win
[(start
+1)][1]) );
621 D3DTLVertices
[1].sz
= D3DVAL( VB
->Win
[(start
+1)][2] );
622 D3DTLVertices
[1].tu
= D3DVAL( VB
->TexCoord
[(start
+1)][0] );
623 D3DTLVertices
[1].tv
= D3DVAL( VB
->TexCoord
[(start
+1)][1] );
624 D3DTLVertices
[1].rhw
= D3DVAL( (1.0 / VB
->Clip
[(start
+1)][3]) );
625 D3DTLVertices
[1].color
= (VB
->Color
[(start
+1)][3]<<24) | (VB
->Color
[(start
+1)][0]<<16) | (VB
->Color
[(start
+1)][1]<<8) | VB
->Color
[(start
+1)][2];
627 for( index
= (start
+2), cVertex
= 2; index
< end
; index
++, cVertex
++ )
629 /*=================================*/
630 /* Add the next vertex to the fan. */
631 /*=================================*/
632 D3DTLVertices
[cVertex
].sx
= D3DVAL( VB
->Win
[index
][0] );
633 D3DTLVertices
[cVertex
].sy
= D3DVAL( (height
- VB
->Win
[index
][1]) );
634 D3DTLVertices
[cVertex
].sz
= D3DVAL( VB
->Win
[index
][2] );
635 D3DTLVertices
[cVertex
].tu
= D3DVAL( VB
->TexCoord
[index
][0] );
636 D3DTLVertices
[cVertex
].tv
= D3DVAL( VB
->TexCoord
[index
][1] );
637 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[index
][3]) );
638 D3DTLVertices
[cVertex
].color
= (VB
->Color
[index
][3]<<24) | (VB
->Color
[index
][0]<<16) | (VB
->Color
[index
][1]<<8) | VB
->Color
[index
][2];
641 /* Render the converted vertex buffer. */
643 DrawPrimitiveHAL( pContext
->pShared
, D3DPT_TRIANGLEFAN
, &D3DTLVertices
[0], cVertex
);
651 for( index
= (start
+2), cVertex
= 0; index
< end
; index
++ )
653 if ( VB
->ClipOrMask
)
655 /* All points clipped by common plane */
656 if ( VB
->ClipMask
[v1
] & VB
->ClipMask
[v2
] & VB
->ClipMask
[v3
] & CLIP_ALL_BITS
)
660 else if ( VB
->ClipMask
[v1
] | VB
->ClipMask
[v2
] | VB
->ClipMask
[v3
] )
665 RenderClippedPolygon( ctx
, 3, VList
);
670 /* Compute orientation of triangle */
671 ex
= VB
->Win
[v2
][0] - VB
->Win
[v1
][0];
672 ey
= VB
->Win
[v2
][1] - VB
->Win
[v1
][1];
673 fx
= VB
->Win
[v3
][0] - VB
->Win
[v1
][0];
674 fy
= VB
->Win
[v3
][1] - VB
->Win
[v1
][1];
675 c
= (ex
* fy
) - (ey
* fx
);
677 /* polygon is perpindicular to view plane, don't draw it */
678 if ( (c
== 0.0F
) && !ctx
->Polygon
.Unfilled
)
681 /* Backface culling. */
682 facing
= (c
< 0.0F
) ^ ctx
->Polygon
.FrontBit
;
683 if ( (facing
+ 1) & ctx
->Polygon
.CullBits
)
686 if ( ctx
->IndirectTriangles
& DD_TRI_OFFSET
)
688 /* Finish computing plane equation of polygon, compute offset */
689 GLfloat fz
= VB
->Win
[v3
][2] - VB
->Win
[v1
][2];
690 GLfloat ez
= VB
->Win
[v2
][2] - VB
->Win
[v1
][2];
691 GLfloat a
= (ey
* fz
) - (ez
* fy
);
692 GLfloat b
= (ez
* fx
) - (ex
* fz
);
693 OffsetPolygon( ctx
, a
, b
, c
);
696 /*=====================================*/
697 /* Populate the the triangle vertices. */
698 /*=====================================*/
699 dwPVColor
= (VB
->Color
[v3
][3]<<24) | (VB
->Color
[v3
][0]<<16) | (VB
->Color
[v3
][1]<<8) | VB
->Color
[v3
][2];
701 D3DTLVertices
[cVertex
].sx
= D3DVAL( VB
->Win
[v1
][0] );
702 D3DTLVertices
[cVertex
].sy
= D3DVAL( (height
- VB
->Win
[v1
][1]) );
703 D3DTLVertices
[cVertex
].sz
= D3DVAL( (VB
->Win
[v1
][2] + ctx
->PolygonZoffset
) );
704 D3DTLVertices
[cVertex
].tu
= D3DVAL( VB
->TexCoord
[v1
][0] );
705 D3DTLVertices
[cVertex
].tv
= D3DVAL( VB
->TexCoord
[v1
][1] );
706 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[v1
][3]) );
707 D3DTLVertices
[cVertex
++].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ? dwPVColor
:
708 (VB
->Color
[v1
][3]<<24) | (VB
->Color
[v1
][0]<<16) | (VB
->Color
[v1
][1]<<8) | VB
->Color
[v1
][2];
710 D3DTLVertices
[cVertex
].sx
= D3DVAL( VB
->Win
[v2
][0] );
711 D3DTLVertices
[cVertex
].sy
= D3DVAL( (height
- VB
->Win
[v2
][1]) );
712 D3DTLVertices
[cVertex
].sz
= D3DVAL( (VB
->Win
[v2
][2] + ctx
->PolygonZoffset
) );
713 D3DTLVertices
[cVertex
].tu
= D3DVAL( VB
->TexCoord
[v2
][0] );
714 D3DTLVertices
[cVertex
].tv
= D3DVAL( VB
->TexCoord
[v2
][1] );
715 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[v2
][3]) );
716 D3DTLVertices
[cVertex
++].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ? dwPVColor
:
717 (VB
->Color
[v2
][3]<<24) | (VB
->Color
[v2
][0]<<16) | (VB
->Color
[v2
][1]<<8) | VB
->Color
[v2
][2];
719 D3DTLVertices
[cVertex
].sx
= D3DVAL( VB
->Win
[v3
][0] );
720 D3DTLVertices
[cVertex
].sy
= D3DVAL( (height
- VB
->Win
[v3
][1]) );
721 D3DTLVertices
[cVertex
].sz
= D3DVAL( (VB
->Win
[v3
][2] + ctx
->PolygonZoffset
) );
722 D3DTLVertices
[cVertex
].tu
= D3DVAL( VB
->TexCoord
[v3
][0] );
723 D3DTLVertices
[cVertex
].tv
= D3DVAL( VB
->TexCoord
[v3
][1] );
724 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[v3
][3]) );
725 D3DTLVertices
[cVertex
++].color
= dwPVColor
;
728 /* Render the converted vertex buffer. */
730 DrawPrimitiveHAL( pContext
->pShared
, D3DPT_TRIANGLELIST
, &D3DTLVertices
[0], cVertex
);
736 /*===========================================================================*/
737 /* This function will render the current vertex buffer as a triangle strip. */
738 /* The buffer has to be able to be rendered directly. This means that we are*/
739 /* filled, no offsets, no culling and one sided rendering. Also we must be */
740 /* in render mode of course. */
741 /* First I will fill the global D3D vertice buffer. Next I will set all the*/
742 /* states for D3D based on the current OGL state. Finally I pass the D3D VB */
743 /* to the wrapper that call DrawPrimitives. */
744 /*===========================================================================*/
746 /*===========================================================================*/
747 static void RenderTriangleStripVB( GLcontext
*ctx
, GLuint start
, GLuint end
)
749 D3DMESACONTEXT
*pContext
= (D3DMESACONTEXT
*)ctx
->DriverCtx
;
750 struct vertex_buffer
*VB
= ctx
->VB
;
754 height
= (pContext
->pShared
->rectW
.bottom
- pContext
->pShared
->rectW
.top
);
760 DPF(( DBG_FUNC
, "RenderTriangleStripVB();" ));
762 /* Special case that we can blast the fan without culling, offset, etc... */
763 if ( !VB
->ClipOrMask
&& (ctx
->Light
.ShadeModel
!= GL_FLAT
) )
765 DPF(( DBG_PRIM_PROFILE
, "DirectTriangles" ));
767 /* Seed the the strip. */
768 D3DTLVertices
[0].sx
= D3DVAL( VB
->Win
[start
][0] );
769 D3DTLVertices
[0].sy
= D3DVAL( (height
- VB
->Win
[start
][1]) );
770 D3DTLVertices
[0].sz
= D3DVAL( VB
->Win
[start
][2] );
771 D3DTLVertices
[0].tu
= D3DVAL( VB
->TexCoord
[start
][0] );
772 D3DTLVertices
[0].tv
= D3DVAL( VB
->TexCoord
[start
][1] );
773 D3DTLVertices
[0].rhw
= D3DVAL( (1.0 / VB
->Clip
[start
][3]) );
774 D3DTLVertices
[0].color
= (VB
->Color
[start
][3]<<24) | (VB
->Color
[start
][0]<<16) | (VB
->Color
[start
][1]<<8) | VB
->Color
[start
][2];
776 /* Seed the the strip. */
777 D3DTLVertices
[1].sx
= D3DVAL( VB
->Win
[(start
+1)][0] );
778 D3DTLVertices
[1].sy
= D3DVAL( (height
- VB
->Win
[(start
+1)][1]) );
779 D3DTLVertices
[1].sz
= D3DVAL( VB
->Win
[(start
+1)][2] );
780 D3DTLVertices
[1].tu
= D3DVAL( VB
->TexCoord
[(start
+1)][0] );
781 D3DTLVertices
[1].tv
= D3DVAL( VB
->TexCoord
[(start
+1)][1] );
782 D3DTLVertices
[1].rhw
= D3DVAL( (1.0 / VB
->Clip
[(start
+1)][3]) );
783 D3DTLVertices
[1].color
= (VB
->Color
[(start
+1)][3]<<24) | (VB
->Color
[(start
+1)][0]<<16) | (VB
->Color
[(start
+1)][1]<<8) | VB
->Color
[(start
+1)][2];
785 for( index
= (start
+2), cVertex
= 2; index
< end
; index
++, cVertex
++ )
787 /*===================================*/
788 /* Add the next vertex to the strip. */
789 /*===================================*/
790 D3DTLVertices
[cVertex
].sx
= D3DVAL( VB
->Win
[index
][0] );
791 D3DTLVertices
[cVertex
].sy
= D3DVAL( (height
- VB
->Win
[index
][1]) );
792 D3DTLVertices
[cVertex
].sz
= D3DVAL( VB
->Win
[index
][2] );
793 D3DTLVertices
[cVertex
].tu
= D3DVAL( VB
->TexCoord
[index
][0] );
794 D3DTLVertices
[cVertex
].tv
= D3DVAL( VB
->TexCoord
[index
][1] );
795 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[index
][3]) );
796 D3DTLVertices
[cVertex
].color
= (VB
->Color
[index
][3]<<24) | (VB
->Color
[index
][0]<<16) | (VB
->Color
[index
][1]<<8) | VB
->Color
[index
][2];
799 /* Render the converted vertex buffer. */
801 DrawPrimitiveHAL( pContext
->pShared
, D3DPT_TRIANGLESTRIP
, &D3DTLVertices
[0], cVertex
);
805 for( index
= (start
+2); index
< end
; index
++ )
807 /* We need to switch order so that winding won't be a problem. */
821 /* All vertices clipped by common plane */
822 if ( VB
->ClipMask
[v1
] & VB
->ClipMask
[v2
] & VB
->ClipMask
[v3
] & CLIP_ALL_BITS
)
825 /* Check if any vertices need clipping. */
826 if ( VB
->ClipMask
[v1
] | VB
->ClipMask
[v2
] | VB
->ClipMask
[v3
] )
831 RenderClippedPolygon( ctx
, 3, VList
);
835 /* Compute orientation of triangle */
836 ex
= VB
->Win
[v2
][0] - VB
->Win
[v1
][0];
837 ey
= VB
->Win
[v2
][1] - VB
->Win
[v1
][1];
838 fx
= VB
->Win
[v3
][0] - VB
->Win
[v1
][0];
839 fy
= VB
->Win
[v3
][1] - VB
->Win
[v1
][1];
840 c
= (ex
* fy
) - (ey
* fx
);
842 /* Polygon is perpindicular to view plane, don't draw it */
843 if ( (c
== 0.0F
) && !ctx
->Polygon
.Unfilled
)
846 /* Backface culling. */
847 facing
= (c
< 0.0F
) ^ ctx
->Polygon
.FrontBit
;
848 if ( (facing
+ 1) & ctx
->Polygon
.CullBits
)
851 /* Need right color if we have two sided lighting. */
852 if ( ctx
->IndirectTriangles
& DD_TRI_LIGHT_TWOSIDE
)
857 VB
->Color
= VB
->Bcolor
;
858 VB
->Specular
= VB
->Bspec
;
862 /* use front color */
863 VB
->Color
= VB
->Fcolor
;
864 VB
->Specular
= VB
->Fspec
;
868 if ( ctx
->IndirectTriangles
& DD_TRI_OFFSET
)
870 /* Finish computing plane equation of polygon, compute offset */
871 GLfloat fz
= VB
->Win
[v3
][2] - VB
->Win
[v1
][2];
872 GLfloat ez
= VB
->Win
[v2
][2] - VB
->Win
[v1
][2];
873 GLfloat a
= (ey
* fz
) - (ez
* fy
);
874 GLfloat b
= (ez
* fx
) - (ex
* fz
);
875 OffsetPolygon( ctx
, a
, b
, c
);
877 /*=====================================*/
878 /* Populate the the triangle vertices. */
879 /*=====================================*/
881 /* Solve the prevoking vertex color as we need it for the 3rd triangle and flat shading. */
882 dwPVColor
= (VB
->Color
[v3
][3]<<24) | (VB
->Color
[v3
][0]<<16) | (VB
->Color
[v3
][1]<<8) | VB
->Color
[v3
][2];
884 D3DTLVertices
[cVertex
].sx
= D3DVAL( VB
->Win
[v1
][0] );
885 D3DTLVertices
[cVertex
].sy
= D3DVAL( (height
- VB
->Win
[v1
][1]) );
886 D3DTLVertices
[cVertex
].sz
= D3DVAL( (VB
->Win
[v1
][2] + ctx
->PolygonZoffset
) );
887 D3DTLVertices
[cVertex
].tu
= D3DVAL( VB
->TexCoord
[v1
][0] );
888 D3DTLVertices
[cVertex
].tv
= D3DVAL( VB
->TexCoord
[v1
][1] );
889 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[v1
][3]) );
890 D3DTLVertices
[cVertex
++].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ?
892 (VB
->Color
[v1
][3]<<24) | (VB
->Color
[v1
][0]<<16) | (VB
->Color
[v1
][1]<<8) | VB
->Color
[v1
][2];
894 D3DTLVertices
[cVertex
].sx
= D3DVAL( VB
->Win
[v2
][0] );
895 D3DTLVertices
[cVertex
].sy
= D3DVAL( (height
- VB
->Win
[v2
][1]) );
896 D3DTLVertices
[cVertex
].sz
= D3DVAL( (VB
->Win
[v2
][2] + ctx
->PolygonZoffset
) );
897 D3DTLVertices
[cVertex
].tu
= D3DVAL( VB
->TexCoord
[v2
][0] );
898 D3DTLVertices
[cVertex
].tv
= D3DVAL( VB
->TexCoord
[v2
][1] );
899 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[v2
][3]) );
900 D3DTLVertices
[cVertex
++].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ?
902 (VB
->Color
[v2
][3]<<24) | (VB
->Color
[v2
][0]<<16) | (VB
->Color
[v2
][1]<<8) | VB
->Color
[v2
][2];
904 D3DTLVertices
[cVertex
].sx
= D3DVAL( VB
->Win
[v3
][0] );
905 D3DTLVertices
[cVertex
].sy
= D3DVAL( (height
- VB
->Win
[v3
][1]) );
906 D3DTLVertices
[cVertex
].sz
= D3DVAL( (VB
->Win
[v3
][2] + ctx
->PolygonZoffset
) );
907 D3DTLVertices
[cVertex
].tu
= D3DVAL( VB
->TexCoord
[v3
][0] );
908 D3DTLVertices
[cVertex
].tv
= D3DVAL( VB
->TexCoord
[v3
][1] );
909 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[v3
][3]) );
910 D3DTLVertices
[cVertex
++].color
= dwPVColor
;
914 /* Render the converted vertex buffer. */
916 DrawPrimitiveHAL( pContext
->pShared
, D3DPT_TRIANGLELIST
, &D3DTLVertices
[0], cVertex
);
919 /*===========================================================================*/
920 /* This function will render the current vertex buffer as Quads. The buffer*/
921 /* has to be able to be rendered directly. This means that we are filled, no*/
922 /* offsets, no culling and one sided rendering. Also we must be in render */
923 /* mode of cource. */
924 /* First I will fill the global D3D vertice buffer. Next I will set all the*/
925 /* states for D3D based on the current OGL state. Finally I pass the D3D VB */
926 /* to the wrapper that call DrawPrimitives. */
927 /*===========================================================================*/
929 /*===========================================================================*/
930 static void RenderQuadVB( GLcontext
*ctx
, GLuint start
, GLuint end
)
932 D3DMESACONTEXT
*pContext
= (D3DMESACONTEXT
*)ctx
->DriverCtx
;
933 struct vertex_buffer
*VB
= ctx
->VB
;
936 height
= (pContext
->pShared
->rectW
.bottom
- pContext
->pShared
->rectW
.top
);
940 GLuint facing
; /* 0=front, 1=back */
942 DPF(( DBG_FUNC
, "RenderQuadVB();" ));
949 if ( !VB
->ClipOrMask
)
951 DPF(( DBG_PRIM_PROFILE
, "DirectTriangles" ));
953 for( cVertex
= 0, index
= start
; index
< end
; index
+= 4 )
955 if ( ctx
->Light
.ShadeModel
== GL_FLAT
)
956 dwPVColor
= (VB
->Color
[v4
][3]<<24) | (VB
->Color
[v4
][0]<<16) | (VB
->Color
[v4
][1]<<8) | VB
->Color
[v4
][2];
958 /*=====================================*/
959 /* Populate the the triangle vertices. */
960 /*=====================================*/
961 D3DTLVertices
[cVertex
].sx
= D3DVAL( VB
->Win
[v1
][0] );
962 D3DTLVertices
[cVertex
].sy
= D3DVAL( (height
- VB
->Win
[v1
][1]) );
963 D3DTLVertices
[cVertex
].sz
= D3DVAL( VB
->Win
[v1
][2] );
964 D3DTLVertices
[cVertex
].tu
= D3DVAL( VB
->TexCoord
[v1
][0] );
965 D3DTLVertices
[cVertex
].tv
= D3DVAL( VB
->TexCoord
[v1
][1] );
966 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[v1
][3]) );
967 D3DTLVertices
[cVertex
++].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ?
969 (VB
->Color
[v1
][3]<<24) | (VB
->Color
[v1
][0]<<16) | (VB
->Color
[v1
][1]<<8) | VB
->Color
[v1
][2];
971 D3DTLVertices
[cVertex
].sx
= D3DVAL( VB
->Win
[v2
][0] );
972 D3DTLVertices
[cVertex
].sy
= D3DVAL( (height
- VB
->Win
[v2
][1]) );
973 D3DTLVertices
[cVertex
].sz
= D3DVAL( VB
->Win
[v2
][2] );
974 D3DTLVertices
[cVertex
].tu
= D3DVAL( VB
->TexCoord
[v2
][0] );
975 D3DTLVertices
[cVertex
].tv
= D3DVAL( VB
->TexCoord
[v2
][1] );
976 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[v2
][3]) );
977 D3DTLVertices
[cVertex
++].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ?
979 (VB
->Color
[v2
][3]<<24) | (VB
->Color
[v2
][0]<<16) | (VB
->Color
[v2
][1]<<8) | VB
->Color
[v2
][2];
981 D3DTLVertices
[cVertex
].sx
= D3DVAL( VB
->Win
[v3
][0] );
982 D3DTLVertices
[cVertex
].sy
= D3DVAL( (height
- VB
->Win
[v3
][1]) );
983 D3DTLVertices
[cVertex
].sz
= D3DVAL( VB
->Win
[v3
][2] );
984 D3DTLVertices
[cVertex
].tu
= D3DVAL( VB
->TexCoord
[v3
][0] );
985 D3DTLVertices
[cVertex
].tv
= D3DVAL( VB
->TexCoord
[v3
][1] );
986 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[v3
][3]) );
987 D3DTLVertices
[cVertex
++].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ?
989 (VB
->Color
[v3
][3]<<24) | (VB
->Color
[v3
][0]<<16) | (VB
->Color
[v3
][1]<<8) | VB
->Color
[v3
][2];
991 D3DTLVertices
[cVertex
].sx
= D3DVAL( VB
->Win
[v1
][0] );
992 D3DTLVertices
[cVertex
].sy
= D3DVAL( (height
- VB
->Win
[v1
][1]) );
993 D3DTLVertices
[cVertex
].sz
= D3DVAL( VB
->Win
[v1
][2] );
994 D3DTLVertices
[cVertex
].tu
= D3DVAL( VB
->TexCoord
[v1
][0] );
995 D3DTLVertices
[cVertex
].tv
= D3DVAL( VB
->TexCoord
[v1
][1] );
996 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[v1
][3]) );
997 D3DTLVertices
[cVertex
++].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ?
999 (VB
->Color
[v1
][3]<<24) | (VB
->Color
[v1
][0]<<16) | (VB
->Color
[v1
][1]<<8) | VB
->Color
[v1
][2];
1001 D3DTLVertices
[cVertex
].sx
= D3DVAL( VB
->Win
[v3
][0] );
1002 D3DTLVertices
[cVertex
].sy
= D3DVAL( (height
- VB
->Win
[v3
][1]) );
1003 D3DTLVertices
[cVertex
].sz
= D3DVAL( VB
->Win
[v3
][2] );
1004 D3DTLVertices
[cVertex
].tu
= D3DVAL( VB
->TexCoord
[v3
][0] );
1005 D3DTLVertices
[cVertex
].tv
= D3DVAL( VB
->TexCoord
[v3
][1] );
1006 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[v3
][3]) );
1007 D3DTLVertices
[cVertex
++].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ?
1009 (VB
->Color
[v3
][3]<<24) | (VB
->Color
[v3
][0]<<16) | (VB
->Color
[v3
][1]<<8) | VB
->Color
[v3
][2];
1011 D3DTLVertices
[cVertex
].sx
= D3DVAL( VB
->Win
[v4
][0] );
1012 D3DTLVertices
[cVertex
].sy
= D3DVAL( (height
- VB
->Win
[v4
][1]) );
1013 D3DTLVertices
[cVertex
].sz
= D3DVAL( VB
->Win
[v4
][2] );
1014 D3DTLVertices
[cVertex
].tu
= D3DVAL( VB
->TexCoord
[v4
][0] );
1015 D3DTLVertices
[cVertex
].tv
= D3DVAL( VB
->TexCoord
[v4
][1] );
1016 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[v4
][3]) );
1017 D3DTLVertices
[cVertex
++].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ?
1019 (VB
->Color
[v4
][3]<<24) | (VB
->Color
[v4
][0]<<16) | (VB
->Color
[v4
][1]<<8) | VB
->Color
[v4
][2];
1024 for( cVertex
= 0, index
= start
; index
< end
; index
+= 4 )
1026 if ( VB
->ClipMask
[v1
] & VB
->ClipMask
[v2
] & VB
->ClipMask
[v3
] & VB
->ClipMask
[v4
] & CLIP_ALL_BITS
)
1030 else if ( VB
->ClipMask
[v1
] | VB
->ClipMask
[v2
] | VB
->ClipMask
[v3
] | VB
->ClipMask
[v4
] )
1036 RenderClippedPolygon( ctx
, 4, VList
);
1040 /* Compute orientation of triangle */
1041 ex
= VB
->Win
[v2
][0] - VB
->Win
[v1
][0];
1042 ey
= VB
->Win
[v2
][1] - VB
->Win
[v1
][1];
1043 fx
= VB
->Win
[v3
][0] - VB
->Win
[v1
][0];
1044 fy
= VB
->Win
[v3
][1] - VB
->Win
[v1
][1];
1045 c
= (ex
* fy
) - (ey
* fx
);
1047 /* polygon is perpindicular to view plane, don't draw it */
1048 if ( (c
== 0.0F
) && !ctx
->Polygon
.Unfilled
)
1051 /* Backface culling. */
1052 facing
= (c
< 0.0F
) ^ ctx
->Polygon
.FrontBit
;
1053 if ( (facing
+ 1) & ctx
->Polygon
.CullBits
)
1056 if ( ctx
->IndirectTriangles
& DD_TRI_LIGHT_TWOSIDE
)
1060 /* use back color */
1061 VB
->Color
= VB
->Bcolor
;
1062 VB
->Specular
= VB
->Bspec
;
1066 /* use front color */
1067 VB
->Color
= VB
->Fcolor
;
1068 VB
->Specular
= VB
->Fspec
;
1072 if ( ctx
->IndirectTriangles
& DD_TRI_OFFSET
)
1074 /* Finish computing plane equation of polygon, compute offset */
1075 GLfloat fz
= VB
->Win
[v3
][2] - VB
->Win
[v1
][2];
1076 GLfloat ez
= VB
->Win
[v2
][2] - VB
->Win
[v1
][2];
1077 GLfloat a
= (ey
* fz
) - (ez
* fy
);
1078 GLfloat b
= (ez
* fx
) - (ex
* fz
);
1079 OffsetPolygon( ctx
, a
, b
, c
);
1082 if ( ctx
->Light
.ShadeModel
== GL_FLAT
)
1083 dwPVColor
= (VB
->Color
[v4
][3]<<24) | (VB
->Color
[v4
][0]<<16) | (VB
->Color
[v4
][1]<<8) | VB
->Color
[v4
][2];
1085 /*=====================================*/
1086 /* Populate the the triangle vertices. */
1087 /*=====================================*/
1088 D3DTLVertices
[cVertex
].sx
= D3DVAL( VB
->Win
[v1
][0] );
1089 D3DTLVertices
[cVertex
].sy
= D3DVAL( (height
- VB
->Win
[v1
][1]) );
1090 D3DTLVertices
[cVertex
].sz
= D3DVAL( (VB
->Win
[v1
][2] + ctx
->PolygonZoffset
) );
1091 D3DTLVertices
[cVertex
].tu
= D3DVAL( VB
->TexCoord
[v1
][0] );
1092 D3DTLVertices
[cVertex
].tv
= D3DVAL( VB
->TexCoord
[v1
][1] );
1093 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[v1
][3]) );
1094 D3DTLVertices
[cVertex
++].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ?
1096 (VB
->Color
[v1
][3]<<24) | (VB
->Color
[v1
][0]<<16) | (VB
->Color
[v1
][1]<<8) | VB
->Color
[v1
][2];
1098 D3DTLVertices
[cVertex
].sx
= D3DVAL( VB
->Win
[v2
][0] );
1099 D3DTLVertices
[cVertex
].sy
= D3DVAL( (height
- VB
->Win
[v2
][1]) );
1100 D3DTLVertices
[cVertex
].sz
= D3DVAL( (VB
->Win
[v2
][2] + ctx
->PolygonZoffset
) );
1101 D3DTLVertices
[cVertex
].tu
= D3DVAL( VB
->TexCoord
[v2
][0] );
1102 D3DTLVertices
[cVertex
].tv
= D3DVAL( VB
->TexCoord
[v2
][1] );
1103 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[v2
][3]) );
1104 D3DTLVertices
[cVertex
++].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ?
1106 (VB
->Color
[v2
][3]<<24) | (VB
->Color
[v2
][0]<<16) | (VB
->Color
[v2
][1]<<8) | VB
->Color
[v2
][2];
1108 D3DTLVertices
[cVertex
].sx
= D3DVAL( VB
->Win
[v3
][0] );
1109 D3DTLVertices
[cVertex
].sy
= D3DVAL( (height
- VB
->Win
[v3
][1]) );
1110 D3DTLVertices
[cVertex
].sz
= D3DVAL( (VB
->Win
[v3
][2] + ctx
->PolygonZoffset
) );
1111 D3DTLVertices
[cVertex
].tu
= D3DVAL( VB
->TexCoord
[v3
][0] );
1112 D3DTLVertices
[cVertex
].tv
= D3DVAL( VB
->TexCoord
[v3
][1] );
1113 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[v3
][3]) );
1114 D3DTLVertices
[cVertex
++].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ?
1116 (VB
->Color
[v3
][3]<<24) | (VB
->Color
[v3
][0]<<16) | (VB
->Color
[v3
][1]<<8) | VB
->Color
[v3
][2];
1118 D3DTLVertices
[cVertex
].sx
= D3DVAL( VB
->Win
[v1
][0] );
1119 D3DTLVertices
[cVertex
].sy
= D3DVAL( (height
- VB
->Win
[v1
][1]) );
1120 D3DTLVertices
[cVertex
].sz
= D3DVAL( (VB
->Win
[v1
][2] + ctx
->PolygonZoffset
) );
1121 D3DTLVertices
[cVertex
].tu
= D3DVAL( VB
->TexCoord
[v1
][0] );
1122 D3DTLVertices
[cVertex
].tv
= D3DVAL( VB
->TexCoord
[v1
][1] );
1123 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[v1
][3]) );
1124 D3DTLVertices
[cVertex
++].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ?
1126 (VB
->Color
[v1
][3]<<24) | (VB
->Color
[v1
][0]<<16) | (VB
->Color
[v1
][1]<<8) | VB
->Color
[v1
][2];
1128 D3DTLVertices
[cVertex
].sx
= D3DVAL( VB
->Win
[v3
][0] );
1129 D3DTLVertices
[cVertex
].sy
= D3DVAL( (height
- VB
->Win
[v3
][1]) );
1130 D3DTLVertices
[cVertex
].sz
= D3DVAL( (VB
->Win
[v3
][2] + ctx
->PolygonZoffset
) );
1131 D3DTLVertices
[cVertex
].tu
= D3DVAL( VB
->TexCoord
[v3
][0] );
1132 D3DTLVertices
[cVertex
].tv
= D3DVAL( VB
->TexCoord
[v3
][1] );
1133 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[v3
][3]) );
1134 D3DTLVertices
[cVertex
++].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ?
1136 (VB
->Color
[v3
][3]<<24) | (VB
->Color
[v3
][0]<<16) | (VB
->Color
[v3
][1]<<8) | VB
->Color
[v3
][2];
1138 D3DTLVertices
[cVertex
].sx
= D3DVAL( VB
->Win
[v4
][0] );
1139 D3DTLVertices
[cVertex
].sy
= D3DVAL( (height
- VB
->Win
[v4
][1]) );
1140 D3DTLVertices
[cVertex
].sz
= D3DVAL( (VB
->Win
[v4
][2] + ctx
->PolygonZoffset
) );
1141 D3DTLVertices
[cVertex
].tu
= D3DVAL( VB
->TexCoord
[v4
][0] );
1142 D3DTLVertices
[cVertex
].tv
= D3DVAL( VB
->TexCoord
[v4
][1] );
1143 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[v4
][3]) );
1144 D3DTLVertices
[cVertex
++].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ?
1146 (VB
->Color
[v4
][3]<<24) | (VB
->Color
[v4
][0]<<16) | (VB
->Color
[v4
][1]<<8) | VB
->Color
[v4
][2];
1155 /* Render the converted vertex buffer. */
1157 DrawPrimitiveHAL( pContext
->pShared
, D3DPT_TRIANGLELIST
, &D3DTLVertices
[0], cVertex
);
1159 /*===========================================================================*/
1161 /*===========================================================================*/
1162 /* RETURN: TRUE, FALSE. */
1163 /*===========================================================================*/
1164 static void RenderQuad( GLcontext
*ctx
, GLuint v1
, GLuint v2
, GLuint v3
, GLuint v4
, GLuint pv
)
1166 D3DMESACONTEXT
*pContext
= (D3DMESACONTEXT
*)ctx
->DriverCtx
;
1167 struct vertex_buffer
*VB
= ctx
->VB
;
1168 int height
= (pContext
->pShared
->rectW
.bottom
- pContext
->pShared
->rectW
.top
);
1172 GLuint facing
; /* 0=front, 1=back */
1173 static D3DTLVERTEX TLVertices
[6];
1175 DPF(( DBG_FUNC
, "RenderQuad" ));
1176 DPF(( DBG_PRIM_INFO
, "RenderQuad( 1 )" ));
1178 /* Compute orientation of triangle */
1179 ex
= VB
->Win
[v2
][0] - VB
->Win
[v1
][0];
1180 ey
= VB
->Win
[v2
][1] - VB
->Win
[v1
][1];
1181 fx
= VB
->Win
[v3
][0] - VB
->Win
[v1
][0];
1182 fy
= VB
->Win
[v3
][1] - VB
->Win
[v1
][1];
1183 c
= (ex
* fy
) - (ey
* fx
);
1185 /* polygon is perpindicular to view plane, don't draw it */
1186 if ( (c
== 0.0F
) && !ctx
->Polygon
.Unfilled
)
1189 /* Backface culling. */
1190 facing
= (c
< 0.0F
) ^ ctx
->Polygon
.FrontBit
;
1191 if ( (facing
+ 1) & ctx
->Polygon
.CullBits
)
1194 if ( ctx
->IndirectTriangles
& DD_TRI_LIGHT_TWOSIDE
)
1198 /* use back color */
1199 VB
->Color
= VB
->Bcolor
;
1200 VB
->Specular
= VB
->Bspec
;
1204 /* use front color */
1205 VB
->Color
= VB
->Fcolor
;
1206 VB
->Specular
= VB
->Fspec
;
1210 if ( ctx
->IndirectTriangles
& DD_TRI_OFFSET
)
1212 /* Finish computing plane equation of polygon, compute offset */
1213 GLfloat fz
= VB
->Win
[v3
][2] - VB
->Win
[v1
][2];
1214 GLfloat ez
= VB
->Win
[v2
][2] - VB
->Win
[v1
][2];
1215 GLfloat a
= (ey
* fz
) - (ez
* fy
);
1216 GLfloat b
= (ez
* fx
) - (ex
* fz
);
1217 OffsetPolygon( ctx
, a
, b
, c
);
1220 if ( ctx
->Light
.ShadeModel
== GL_FLAT
)
1221 dwPVColor
= (VB
->Color
[pv
][3]<<24) | (VB
->Color
[pv
][0]<<16) | (VB
->Color
[pv
][1]<<8) | VB
->Color
[pv
][2];
1223 /*=====================================*/
1224 /* Populate the the triangle vertices. */
1225 /*=====================================*/
1226 TLVertices
[0].sx
= D3DVAL( VB
->Win
[v1
][0] );
1227 TLVertices
[0].sy
= D3DVAL( (height
- VB
->Win
[v1
][1]) );
1228 TLVertices
[0].sz
= D3DVAL( (VB
->Win
[v1
][2] + ctx
->PolygonZoffset
) );
1229 TLVertices
[0].tu
= D3DVAL( VB
->TexCoord
[v1
][0] );
1230 TLVertices
[0].tv
= D3DVAL( VB
->TexCoord
[v1
][1] );
1231 TLVertices
[0].rhw
= D3DVAL( (1.0 / VB
->Clip
[v1
][3]) );
1232 TLVertices
[0].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ? dwPVColor
:
1233 (VB
->Color
[v1
][3]<<24) | (VB
->Color
[v1
][0]<<16) | (VB
->Color
[v1
][1]<<8) | VB
->Color
[v1
][2];
1235 TLVertices
[1].sx
= D3DVAL( VB
->Win
[v2
][0] );
1236 TLVertices
[1].sy
= D3DVAL( (height
- VB
->Win
[v2
][1]) );
1237 TLVertices
[1].sz
= D3DVAL( (VB
->Win
[v2
][2] + ctx
->PolygonZoffset
) );
1238 TLVertices
[1].tu
= D3DVAL( VB
->TexCoord
[v2
][0] );
1239 TLVertices
[1].tv
= D3DVAL( VB
->TexCoord
[v2
][1] );
1240 TLVertices
[1].rhw
= D3DVAL( (1.0 / VB
->Clip
[v2
][3]) );
1241 TLVertices
[1].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ? dwPVColor
:
1242 (VB
->Color
[v2
][3]<<24) | (VB
->Color
[v2
][0]<<16) | (VB
->Color
[v2
][1]<<8) | VB
->Color
[v2
][2];
1244 TLVertices
[2].sx
= D3DVAL( VB
->Win
[v3
][0] );
1245 TLVertices
[2].sy
= D3DVAL( (height
- VB
->Win
[v3
][1]) );
1246 TLVertices
[2].sz
= D3DVAL( (VB
->Win
[v3
][2] + ctx
->PolygonZoffset
) );
1247 TLVertices
[2].tu
= D3DVAL( VB
->TexCoord
[v3
][0] );
1248 TLVertices
[2].tv
= D3DVAL( VB
->TexCoord
[v3
][1] );
1249 TLVertices
[2].rhw
= D3DVAL( (1.0 / VB
->Clip
[v3
][3]) );
1250 TLVertices
[2].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ? dwPVColor
:
1251 (VB
->Color
[v3
][3]<<24) | (VB
->Color
[v3
][0]<<16) | (VB
->Color
[v3
][1]<<8) | VB
->Color
[v3
][2];
1253 TLVertices
[3].sx
= D3DVAL( VB
->Win
[v3
][0] );
1254 TLVertices
[3].sy
= D3DVAL( (height
- VB
->Win
[v3
][1]) );
1255 TLVertices
[3].sz
= D3DVAL( (VB
->Win
[v3
][2] + ctx
->PolygonZoffset
) );
1256 TLVertices
[3].tu
= D3DVAL( VB
->TexCoord
[v3
][0] );
1257 TLVertices
[3].tv
= D3DVAL( VB
->TexCoord
[v3
][1] );
1258 TLVertices
[3].rhw
= D3DVAL( (1.0 / VB
->Clip
[v3
][3]) );
1259 TLVertices
[3].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ? dwPVColor
:
1260 (VB
->Color
[v3
][3]<<24) | (VB
->Color
[v3
][0]<<16) | (VB
->Color
[v3
][1]<<8) | VB
->Color
[v3
][2];
1262 TLVertices
[4].sx
= D3DVAL( VB
->Win
[v4
][0] );
1263 TLVertices
[4].sy
= D3DVAL( (height
- VB
->Win
[v4
][1]) );
1264 TLVertices
[4].sz
= D3DVAL( (VB
->Win
[v4
][2] + ctx
->PolygonZoffset
) );
1265 TLVertices
[4].tu
= D3DVAL( VB
->TexCoord
[v4
][0] );
1266 TLVertices
[4].tv
= D3DVAL( VB
->TexCoord
[v4
][1] );
1267 TLVertices
[4].rhw
= D3DVAL( (1.0 / VB
->Clip
[v4
][3]) );
1268 TLVertices
[4].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ? dwPVColor
:
1269 (VB
->Color
[v4
][3]<<24) | (VB
->Color
[v4
][0]<<16) | (VB
->Color
[v4
][1]<<8) | VB
->Color
[v4
][2];
1271 TLVertices
[5].sx
= D3DVAL( VB
->Win
[v1
][0] );
1272 TLVertices
[5].sy
= D3DVAL( (height
- VB
->Win
[v1
][1]) );
1273 TLVertices
[5].sz
= D3DVAL( (VB
->Win
[v1
][2] + ctx
->PolygonZoffset
) );
1274 TLVertices
[5].tu
= D3DVAL( VB
->TexCoord
[v1
][0] );
1275 TLVertices
[5].tv
= D3DVAL( VB
->TexCoord
[v1
][1] );
1276 TLVertices
[5].rhw
= D3DVAL( (1.0 / VB
->Clip
[v1
][3]) );
1277 TLVertices
[5].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ? dwPVColor
:
1278 (VB
->Color
[v1
][3]<<24) | (VB
->Color
[v1
][0]<<16) | (VB
->Color
[v1
][1]<<8) | VB
->Color
[v1
][2];
1280 /* Draw the two triangles. */
1281 DrawPrimitiveHAL( pContext
->pShared
, D3DPT_TRIANGLELIST
, &TLVertices
[0], 6 );
1283 /*===========================================================================*/
1285 /*===========================================================================*/
1286 /* RETURN: TRUE, FALSE. */
1287 /*===========================================================================*/
1288 void RenderOneTriangle( GLcontext
*ctx
, GLuint v1
, GLuint v2
, GLuint v3
, GLuint pv
)
1290 D3DMESACONTEXT
*pContext
= (D3DMESACONTEXT
*)ctx
->DriverCtx
;
1291 struct vertex_buffer
*VB
= ctx
->VB
;
1292 int height
= (pContext
->pShared
->rectW
.bottom
- pContext
->pShared
->rectW
.top
);
1294 static D3DTLVERTEX TLVertices
[3];
1296 DPF(( DBG_FUNC
, "RenderOneTriangle" ));
1297 DPF(( DBG_PRIM_INFO
, "RenderTriangle( 1 )" ));
1299 /*=====================================*/
1300 /* Populate the the triangle vertices. */
1301 /*=====================================*/
1302 if ( ctx
->Light
.ShadeModel
== GL_FLAT
)
1303 dwPVColor
= (VB
->Color
[pv
][3]<<24) | (VB
->Color
[pv
][0]<<16) | (VB
->Color
[pv
][1]<<8) | VB
->Color
[pv
][2];
1305 TLVertices
[0].sx
= D3DVAL( VB
->Win
[v1
][0] );
1306 TLVertices
[0].sy
= D3DVAL( (height
- VB
->Win
[v1
][1]) );
1307 TLVertices
[0].sz
= D3DVAL( (VB
->Win
[v1
][2] + ctx
->PolygonZoffset
) );
1308 TLVertices
[0].tu
= D3DVAL( VB
->TexCoord
[v1
][0] );
1309 TLVertices
[0].tv
= D3DVAL( VB
->TexCoord
[v1
][1] );
1310 TLVertices
[0].rhw
= D3DVAL( (1.0 / VB
->Clip
[v1
][3]) );
1311 TLVertices
[0].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ? dwPVColor
:
1312 (VB
->Color
[v1
][3]<<24) | (VB
->Color
[v1
][0]<<16) | (VB
->Color
[v1
][1]<<8) | VB
->Color
[v1
][2];
1313 DPF(( DBG_PRIM_INFO
, "V1 -> x:%f y:%f z:%f c:%x",
1317 TLVertices
[0].color
));
1319 TLVertices
[1].sx
= D3DVAL( VB
->Win
[v2
][0] );
1320 TLVertices
[1].sy
= D3DVAL( (height
- VB
->Win
[v2
][1]) );
1321 TLVertices
[1].sz
= D3DVAL( (VB
->Win
[v2
][2] + ctx
->PolygonZoffset
) );
1322 TLVertices
[1].tu
= D3DVAL( VB
->TexCoord
[v2
][0] );
1323 TLVertices
[1].tv
= D3DVAL( VB
->TexCoord
[v2
][1] );
1324 TLVertices
[1].rhw
= D3DVAL( (1.0 / VB
->Clip
[v2
][3]) );
1325 TLVertices
[1].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ? dwPVColor
:
1326 (VB
->Color
[v2
][3]<<24) | (VB
->Color
[v2
][0]<<16) | (VB
->Color
[v2
][1]<<8) | VB
->Color
[v2
][2];
1327 DPF(( DBG_PRIM_INFO
, "V2 -> x:%f y:%f z:%f c:%x",
1331 TLVertices
[1].color
));
1333 TLVertices
[2].sx
= D3DVAL( VB
->Win
[v3
][0] );
1334 TLVertices
[2].sy
= D3DVAL( (height
- VB
->Win
[v3
][1]) );
1335 TLVertices
[2].sz
= D3DVAL( (VB
->Win
[v3
][2] + ctx
->PolygonZoffset
) );
1336 TLVertices
[2].tu
= D3DVAL( VB
->TexCoord
[v3
][0] );
1337 TLVertices
[2].tv
= D3DVAL( VB
->TexCoord
[v3
][1] );
1338 TLVertices
[2].rhw
= D3DVAL( (1.0 / VB
->Clip
[v3
][3]) );
1339 TLVertices
[2].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ? dwPVColor
:
1340 (VB
->Color
[v3
][3]<<24) | (VB
->Color
[v3
][0]<<16) | (VB
->Color
[v3
][1]<<8) | VB
->Color
[v3
][2];
1341 DPF(( DBG_PRIM_INFO
, "V3 -> x:%f y:%f z:%f c:%x",
1345 TLVertices
[2].color
));
1347 /* Draw the triangle. */
1348 DrawPrimitiveHAL( pContext
->pShared
, D3DPT_TRIANGLELIST
, &TLVertices
[0], 3 );
1350 /*===========================================================================*/
1352 /*===========================================================================*/
1353 /* RETURN: TRUE, FALSE. */
1354 /*===========================================================================*/
1355 void RenderOneLine( GLcontext
*ctx
, GLuint v1
, GLuint v2
, GLuint pv
)
1357 D3DMESACONTEXT
*pContext
= (D3DMESACONTEXT
*)ctx
->DriverCtx
;
1358 struct vertex_buffer
*VB
= ctx
->VB
;
1359 int height
= (pContext
->pShared
->rectW
.bottom
- pContext
->pShared
->rectW
.top
);
1361 static D3DTLVERTEX TLVertices
[2];
1363 DPF(( DBG_FUNC
, "RenderOneLine" ));
1364 DPF(( DBG_PRIM_INFO
, "RenderLine( 1 )" ));
1366 if ( VB
->MonoColor
)
1367 dwPVColor
= (pContext
->aCurrent
<<24) | (pContext
->rCurrent
<<16) | (pContext
->gCurrent
<<8) | pContext
->bCurrent
;
1369 dwPVColor
= (VB
->Color
[pv
][3]<<24) | (VB
->Color
[pv
][0]<<16) | (VB
->Color
[pv
][1]<<8) | VB
->Color
[pv
][2];
1371 TLVertices
[0].sx
= D3DVAL( VB
->Win
[v1
][0] );
1372 TLVertices
[0].sy
= D3DVAL( (height
- VB
->Win
[v1
][1]) );
1373 TLVertices
[0].sz
= D3DVAL( (VB
->Win
[v1
][2] + ctx
->LineZoffset
) );
1374 TLVertices
[0].tu
= D3DVAL( VB
->TexCoord
[v1
][0] );
1375 TLVertices
[0].tv
= D3DVAL( VB
->TexCoord
[v1
][1] );
1376 TLVertices
[0].rhw
= D3DVAL( (1.0 / VB
->Clip
[v1
][3]) );
1377 TLVertices
[0].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ? dwPVColor
:
1378 (VB
->Color
[v1
][3]<<24) | (VB
->Color
[v1
][0]<<16) | (VB
->Color
[v1
][1]<<8) | VB
->Color
[v1
][2];
1380 TLVertices
[1].sx
= D3DVAL( VB
->Win
[v2
][0] );
1381 TLVertices
[1].sy
= D3DVAL( (height
- VB
->Win
[v2
][1]) );
1382 TLVertices
[1].sz
= D3DVAL( (VB
->Win
[v2
][2] + ctx
->LineZoffset
) );
1383 TLVertices
[1].tu
= D3DVAL( VB
->TexCoord
[v2
][0] );
1384 TLVertices
[1].tv
= D3DVAL( VB
->TexCoord
[v2
][1] );
1385 TLVertices
[1].rhw
= D3DVAL( (1.0 / VB
->Clip
[v2
][3]) );
1386 TLVertices
[1].color
= (ctx
->Light
.ShadeModel
== GL_FLAT
) ? dwPVColor
:
1387 (VB
->Color
[v2
][3]<<24) | (VB
->Color
[v2
][0]<<16) | (VB
->Color
[v2
][1]<<8) | VB
->Color
[v2
][2];
1389 /* Draw line from (x0,y0) to (x1,y1) with current pixel color/index */
1390 DrawPrimitiveHAL( pContext
->pShared
, D3DPT_LINELIST
, &TLVertices
[0], 2 );
1392 /*===========================================================================*/
1393 /* This function was written to convert points into triangles. I did this */
1394 /* as all card accelerate triangles and most drivers do this anyway. In hind*/
1395 /* thought this might be a bad idea as some cards do better. */
1396 /*===========================================================================*/
1398 /*===========================================================================*/
1399 static void RenderPointsVB( GLcontext
*ctx
, GLuint start
, GLuint end
)
1401 D3DMESACONTEXT
*pContext
= (D3DMESACONTEXT
*)ctx
->DriverCtx
;
1402 struct vertex_buffer
*VB
= ctx
->VB
;
1403 struct pixel_buffer
*PB
= ctx
->PB
;
1409 height
= (pContext
->pShared
->rectW
.bottom
- pContext
->pShared
->rectW
.top
);
1412 DPF(( DBG_FUNC
, "RenderPointsVB();" ));
1414 radius
= CLAMP( ctx
->Point
.Size
, MIN_POINT_SIZE
, MAX_POINT_SIZE
) * 0.5F
;
1416 for( index
= start
, cVertex
= 0; index
<= end
; index
++ )
1418 if ( VB
->ClipMask
[index
] == 0 )
1420 xmin
= D3DVAL( VB
->Win
[index
][0] - radius
);
1421 xmax
= D3DVAL( VB
->Win
[index
][0] + radius
);
1422 ymin
= D3DVAL( height
- VB
->Win
[index
][1] - radius
);
1423 ymax
= D3DVAL( height
- VB
->Win
[index
][1] + radius
);
1424 z
= D3DVAL( (VB
->Win
[index
][2] + ctx
->PointZoffset
) );
1426 dwPVColor
= (VB
->Color
[index
][3]<<24) |
1427 (VB
->Color
[index
][0]<<16) |
1428 (VB
->Color
[index
][1]<<8) |
1429 VB
->Color
[index
][2];
1431 D3DTLVertices
[cVertex
].sx
= xmin
;
1432 D3DTLVertices
[cVertex
].sy
= ymax
;
1433 D3DTLVertices
[cVertex
].sz
= z
;
1434 D3DTLVertices
[cVertex
].tu
= 0.0;
1435 D3DTLVertices
[cVertex
].tv
= 0.0;
1436 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[index
][3]) );
1437 D3DTLVertices
[cVertex
++].color
= dwPVColor
;
1439 D3DTLVertices
[cVertex
].sx
= xmin
;
1440 D3DTLVertices
[cVertex
].sy
= ymin
;
1441 D3DTLVertices
[cVertex
].sz
= z
;
1442 D3DTLVertices
[cVertex
].tu
= 0.0;
1443 D3DTLVertices
[cVertex
].tv
= 0.0;
1444 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[index
][3]) );
1445 D3DTLVertices
[cVertex
++].color
= dwPVColor
;
1447 D3DTLVertices
[cVertex
].sx
= xmax
;
1448 D3DTLVertices
[cVertex
].sy
= ymin
;
1449 D3DTLVertices
[cVertex
].sz
= z
;
1450 D3DTLVertices
[cVertex
].tu
= 0.0;
1451 D3DTLVertices
[cVertex
].tv
= 0.0;
1452 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[index
][3]) );
1453 D3DTLVertices
[cVertex
++].color
= dwPVColor
;
1455 D3DTLVertices
[cVertex
].sx
= xmax
;
1456 D3DTLVertices
[cVertex
].sy
= ymin
;
1457 D3DTLVertices
[cVertex
].sz
= z
;
1458 D3DTLVertices
[cVertex
].tu
= 0.0;
1459 D3DTLVertices
[cVertex
].tv
= 0.0;
1460 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[index
][3]) );
1461 D3DTLVertices
[cVertex
++].color
= dwPVColor
;
1463 D3DTLVertices
[cVertex
].sx
= xmax
;
1464 D3DTLVertices
[cVertex
].sy
= ymax
;
1465 D3DTLVertices
[cVertex
].sz
= z
;
1466 D3DTLVertices
[cVertex
].tu
= 0.0;
1467 D3DTLVertices
[cVertex
].tv
= 0.0;
1468 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[index
][3]) );
1469 D3DTLVertices
[cVertex
++].color
= dwPVColor
;
1471 D3DTLVertices
[cVertex
].sx
= xmin
;
1472 D3DTLVertices
[cVertex
].sy
= ymax
;
1473 D3DTLVertices
[cVertex
].sz
= z
;
1474 D3DTLVertices
[cVertex
].tu
= 0.0;
1475 D3DTLVertices
[cVertex
].tv
= 0.0;
1476 D3DTLVertices
[cVertex
].rhw
= D3DVAL( (1.0 / VB
->Clip
[index
][3]) );
1477 D3DTLVertices
[cVertex
++].color
= dwPVColor
;
1481 /* Render the converted vertex buffer. */
1483 DrawPrimitiveHAL( pContext
->pShared
, D3DPT_TRIANGLELIST
, &D3DTLVertices
[0], cVertex
);
1485 /*===========================================================================*/
1486 /* This gets call before we render any primitives so that the current OGL */
1487 /* states will be mapped the D3D context. I'm still not sure how D3D works */
1488 /* but I'm finding that it doesn't act like a state machine as OGL is. It */
1489 /* looks like the state gets set back to the defaults after a DrawPrimitives */
1490 /* or an EndScene. Also I set states that are the default even though this */
1491 /* is redundant as the defaults seem screwed up. */
1492 /* TODO: make a batch call. */
1493 /*===========================================================================*/
1495 /*===========================================================================*/
1496 static void SetRenderStates( GLcontext
*ctx
)
1498 D3DMESACONTEXT
*pContext
= (D3DMESACONTEXT
*)ctx
->DriverCtx
;
1500 static BOOL bTexture
= FALSE
;
1501 static int texName
= -1;
1503 DPF(( DBG_FUNC
, "SetRenderStates();" ));
1505 if ( g_DBGMask
& DBG_STATES
)
1506 DebugRenderStates( ctx
, FALSE
);
1508 SetStateHAL( pContext
->pShared
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
1509 SetStateHAL( pContext
->pShared
, D3DRENDERSTATE_DITHERENABLE
, (ctx
->Color
.DitherFlag
) ? TRUE
: FALSE
);
1511 /*================================================*/
1512 /* Check too see if there are new TEXTURE states. */
1513 /*================================================*/
1514 if ( ctx
->Texture
._EnabledUnits
)
1516 switch( ctx
->Texture
.Set
[ctx
->Texture
.CurrentSet
].EnvMode
)
1519 if ( ctx
->Texture
.Set
[ctx
->Texture
.CurrentSet
].Current
->Image
[0][0]->Format
== GL_RGBA
)
1520 dwFunc
= pContext
->pShared
->dwTexFunc
[d3dtblend_modulatealpha
];
1522 dwFunc
= pContext
->pShared
->dwTexFunc
[d3dtblend_modulate
];
1526 dwFunc
= pContext
->pShared
->dwTexFunc
[d3dtblend_decalalpha
];
1530 dwFunc
= pContext
->pShared
->dwTexFunc
[d3dtblend_decal
];
1534 if ( ctx
->Texture
.Set
[ctx
->Texture
.CurrentSet
].Current
->Image
[0][0]->Format
== GL_RGBA
)
1535 dwFunc
= pContext
->pShared
->dwTexFunc
[d3dtblend_decalalpha
];
1537 dwFunc
= pContext
->pShared
->dwTexFunc
[d3dtblend_decal
];
1540 SetStateHAL( pContext
->pShared
, D3DRENDERSTATE_TEXTUREMAPBLEND
, dwFunc
);
1542 switch( ctx
->Texture
.Set
[ctx
->Texture
.CurrentSet
].Current
->MagFilter
)
1545 dwFunc
= D3DFILTER_NEAREST
;
1548 dwFunc
= D3DFILTER_LINEAR
;
1550 case GL_NEAREST_MIPMAP_NEAREST
:
1551 dwFunc
= D3DFILTER_MIPNEAREST
;
1553 case GL_LINEAR_MIPMAP_NEAREST
:
1554 dwFunc
= D3DFILTER_LINEARMIPNEAREST
;
1556 case GL_NEAREST_MIPMAP_LINEAR
:
1557 dwFunc
= D3DFILTER_MIPLINEAR
;
1559 case GL_LINEAR_MIPMAP_LINEAR
:
1560 dwFunc
= D3DFILTER_LINEARMIPLINEAR
;
1563 SetStateHAL( pContext
->pShared
, D3DRENDERSTATE_TEXTUREMAG
, dwFunc
);
1565 switch( ctx
->Texture
.Set
[ctx
->Texture
.CurrentSet
].Current
->MinFilter
)
1568 dwFunc
= D3DFILTER_NEAREST
;
1571 dwFunc
= D3DFILTER_LINEAR
;
1573 case GL_NEAREST_MIPMAP_NEAREST
:
1574 dwFunc
= D3DFILTER_MIPNEAREST
;
1576 case GL_LINEAR_MIPMAP_NEAREST
:
1577 dwFunc
= D3DFILTER_LINEARMIPNEAREST
;
1579 case GL_NEAREST_MIPMAP_LINEAR
:
1580 dwFunc
= D3DFILTER_MIPLINEAR
;
1582 case GL_LINEAR_MIPMAP_LINEAR
:
1583 dwFunc
= D3DFILTER_LINEARMIPLINEAR
;
1586 SetStateHAL( pContext
->pShared
, D3DRENDERSTATE_TEXTUREMIN
, dwFunc
);
1588 /* Another hack to cut down on redundant texture binding. */
1589 // if ( texName != ctx->Texture.Set[ctx->Texture.CurrentSet].Current->Name )
1591 texName
= ctx
->Texture
.Set
[ctx
->Texture
.CurrentSet
].Current
->Name
;
1592 CreateTMgrHAL( pContext
->pShared
,
1595 ctx
->Texture
.Set
[ctx
->Texture
.CurrentSet
].Current
->Image
[0][0]->Format
,
1597 ctx
->Texture
.Set
[ctx
->Texture
.CurrentSet
].Current
->Image
[0][0]->Width
,
1598 ctx
->Texture
.Set
[ctx
->Texture
.CurrentSet
].Current
->Image
[0][0]->Height
,
1600 (void *)ctx
->Texture
.Set
[ctx
->Texture
.CurrentSet
].Current
->Image
[0][0]->Data
);
1606 /* This is nasty but should cut down on the number of redundant calls. */
1607 if ( bTexture
== TRUE
)
1609 DisableTMgrHAL( pContext
->pShared
);
1614 /*===============================================*/
1615 /* Check too see if there are new RASTER states. */
1616 /*===============================================*/
1618 // TODO: no concept of front & back.
1619 switch( ctx
->Polygon
.FrontMode
)
1622 SetStateHAL( pContext
->pShared
, D3DRENDERSTATE_FILLMODE
, D3DFILL_POINT
);
1625 SetStateHAL( pContext
->pShared
, D3DRENDERSTATE_FILLMODE
, D3DFILL_WIREFRAME
);
1628 SetStateHAL( pContext
->pShared
, D3DRENDERSTATE_FILLMODE
, D3DFILL_SOLID
);
1635 if ( ctx
->Depth
.Test
== GL_TRUE
)
1637 switch( ctx
->Depth
.Func
)
1640 dwFunc
= D3DCMP_NEVER
;
1643 dwFunc
= D3DCMP_LESS
;
1646 dwFunc
= D3DCMP_GREATEREQUAL
;
1649 dwFunc
= D3DCMP_LESSEQUAL
;
1652 dwFunc
= D3DCMP_GREATER
;
1655 dwFunc
= D3DCMP_NOTEQUAL
;
1658 dwFunc
= D3DCMP_EQUAL
;
1661 dwFunc
= D3DCMP_ALWAYS
;
1664 SetStateHAL( pContext
->pShared
, D3DRENDERSTATE_ZFUNC
, dwFunc
);
1665 SetStateHAL( pContext
->pShared
, D3DRENDERSTATE_ZENABLE
, TRUE
);
1669 SetStateHAL( pContext
->pShared
, D3DRENDERSTATE_ZENABLE
, FALSE
);
1672 /*******************/
1673 /* Z-Write Enable. */
1674 /*******************/
1675 SetStateHAL( pContext
->pShared
, D3DRENDERSTATE_ZWRITEENABLE
, (ctx
->Depth
.Mask
== GL_TRUE
) ? TRUE
: FALSE
);
1680 if ( ctx
->Color
.AlphaEnabled
== GL_TRUE
)
1682 switch( ctx
->Color
.AlphaFunc
)
1685 dwFunc
= D3DCMP_NEVER
;
1688 dwFunc
= D3DCMP_LESS
;
1691 dwFunc
= D3DCMP_GREATEREQUAL
;
1694 dwFunc
= D3DCMP_LESSEQUAL
;
1697 dwFunc
= D3DCMP_GREATER
;
1700 dwFunc
= D3DCMP_NOTEQUAL
;
1703 dwFunc
= D3DCMP_EQUAL
;
1706 dwFunc
= D3DCMP_ALWAYS
;
1709 SetStateHAL( pContext
->pShared
, D3DRENDERSTATE_ALPHAFUNC
, dwFunc
);
1710 SetStateHAL( pContext
->pShared
, D3DRENDERSTATE_ALPHATESTENABLE
, TRUE
);
1714 SetStateHAL( pContext
->pShared
, D3DRENDERSTATE_ALPHATESTENABLE
, FALSE
);
1720 if ( ctx
->Color
.BlendEnabled
== GL_TRUE
)
1722 switch( ctx
->Color
.BlendSrc
)
1725 dwFunc
= pContext
->pShared
->dwSrcBlendCaps
[s_zero
];
1728 dwFunc
= pContext
->pShared
->dwSrcBlendCaps
[s_one
];
1731 dwFunc
= pContext
->pShared
->dwSrcBlendCaps
[s_dst_color
];
1733 case GL_ONE_MINUS_DST_COLOR
:
1734 dwFunc
= pContext
->pShared
->dwSrcBlendCaps
[s_one_minus_dst_color
];
1737 dwFunc
= pContext
->pShared
->dwSrcBlendCaps
[s_src_alpha
];
1739 case GL_ONE_MINUS_SRC_ALPHA
:
1740 dwFunc
= pContext
->pShared
->dwSrcBlendCaps
[s_one_minus_src_alpha
];
1743 dwFunc
= pContext
->pShared
->dwSrcBlendCaps
[s_dst_alpha
];
1745 case GL_ONE_MINUS_DST_ALPHA
:
1746 dwFunc
= pContext
->pShared
->dwSrcBlendCaps
[s_one_minus_dst_alpha
];
1748 case GL_SRC_ALPHA_SATURATE
:
1749 dwFunc
= pContext
->pShared
->dwSrcBlendCaps
[s_src_alpha_saturate
];
1751 case GL_CONSTANT_COLOR
:
1752 dwFunc
= pContext
->pShared
->dwSrcBlendCaps
[s_constant_color
];
1754 case GL_ONE_MINUS_CONSTANT_COLOR
:
1755 dwFunc
= pContext
->pShared
->dwSrcBlendCaps
[s_one_minus_constant_color
];
1757 case GL_CONSTANT_ALPHA
:
1758 dwFunc
= pContext
->pShared
->dwSrcBlendCaps
[s_constant_alpha
];
1760 case GL_ONE_MINUS_CONSTANT_ALPHA
:
1761 dwFunc
= pContext
->pShared
->dwSrcBlendCaps
[s_one_minus_constant_alpha
];
1764 SetStateHAL( pContext
->pShared
, D3DRENDERSTATE_SRCBLEND
, dwFunc
);
1766 switch( ctx
->Color
.BlendDst
)
1769 dwFunc
= pContext
->pShared
->dwDestBlendCaps
[d_zero
];
1772 dwFunc
= pContext
->pShared
->dwDestBlendCaps
[d_one
];
1775 dwFunc
= pContext
->pShared
->dwDestBlendCaps
[d_src_color
];
1777 case GL_ONE_MINUS_SRC_COLOR
:
1778 dwFunc
= pContext
->pShared
->dwDestBlendCaps
[d_one_minus_src_color
];
1781 dwFunc
= pContext
->pShared
->dwDestBlendCaps
[d_src_alpha
];
1783 case GL_ONE_MINUS_SRC_ALPHA
:
1784 dwFunc
= pContext
->pShared
->dwDestBlendCaps
[d_one_minus_src_alpha
];
1787 dwFunc
= pContext
->pShared
->dwDestBlendCaps
[d_dst_alpha
];
1789 case GL_ONE_MINUS_DST_ALPHA
:
1790 dwFunc
= pContext
->pShared
->dwDestBlendCaps
[d_one_minus_dst_alpha
];
1792 case GL_CONSTANT_COLOR
:
1793 dwFunc
= pContext
->pShared
->dwDestBlendCaps
[d_constant_color
];
1795 case GL_ONE_MINUS_CONSTANT_COLOR
:
1796 dwFunc
= pContext
->pShared
->dwDestBlendCaps
[d_one_minus_constant_color
];
1798 case GL_CONSTANT_ALPHA
:
1799 dwFunc
= pContext
->pShared
->dwDestBlendCaps
[d_constant_alpha
];
1801 case GL_ONE_MINUS_CONSTANT_ALPHA
:
1802 dwFunc
= pContext
->pShared
->dwDestBlendCaps
[d_one_minus_constant_alpha
];
1805 SetStateHAL( pContext
->pShared
, D3DRENDERSTATE_DESTBLEND
, dwFunc
);
1806 SetStateHAL( pContext
->pShared
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
1810 SetStateHAL( pContext
->pShared
, D3DRENDERSTATE_ALPHABLENDENABLE
, FALSE
);
1813 /*===========================================================================*/
1814 /* If this function is called it will track the changes to the current */
1815 /* states that I'm setting in Direct3D. I did this so that the DPF's would */
1816 /* be under control! */
1817 /*===========================================================================*/
1819 /*===========================================================================*/
1820 static void DebugRenderStates( GLcontext
*ctx
, BOOL bForce
)
1822 D3DMESACONTEXT
*pContext
= (D3DMESACONTEXT
*)ctx
->DriverCtx
;
1824 static int dither
= -1,
1840 /* Force a displayed update of all current states. */
1843 dither
= texture
= textName
= textEnv
= textMin
= textMag
= -1;
1844 polyMode
= depthTest
= depthFunc
= depthMask
= -1;
1845 alphaTest
= alphaFunc
= blend
= blendSrc
= blendDest
= -1;
1848 if ( dither
!= ctx
->Color
.DitherFlag
)
1850 dither
= ctx
->Color
.DitherFlag
;
1851 DPF(( 0, "\tDither\t\t%s", (dither
) ? "ENABLED" : "--------" ));
1853 if ( depthTest
!= ctx
->Depth
.Test
)
1855 depthTest
= ctx
->Depth
.Test
;
1856 DPF(( 0, "\tDepth Test\t%s", (depthTest
) ? "ENABLED" : "--------" ));
1858 if ( alphaTest
!= ctx
->Color
.AlphaEnabled
)
1860 alphaTest
= ctx
->Color
.AlphaEnabled
;
1862 DPF(( 0, "\tAlpha Test\t%s", (alphaTest
) ? "ENABLED" : "--------" ));
1864 if ( blend
!= ctx
->Color
.BlendEnabled
)
1866 blend
= ctx
->Color
.BlendEnabled
;
1868 DPF(( 0, "\tBlending\t%s", (blend
) ? "ENABLED" : "--------" ));
1871 /*================================================*/
1872 /* Check too see if there are new TEXTURE states. */
1873 /*================================================*/
1874 if ( texture
!= ctx
->Texture
._EnabledUnits
)
1876 texture
= ctx
->Texture
._EnabledUnits
;
1877 DPF(( 0, "\tTexture\t\t%s", (texture
) ? "ENABLED" : "--------" ));
1880 if ( ctx
->Texture
.Set
[ctx
->Texture
.CurrentSet
].Current
)
1882 if ( ctx
->Texture
.Set
[ctx
->Texture
.CurrentSet
].Current
->Name
!= textName
)
1884 textName
= ctx
->Texture
.Set
[ctx
->Texture
.CurrentSet
].Current
->Name
;
1885 DPF(( 0, "\tTexture Name:\t%d", textName
));
1886 DPF(( 0, "\tTexture Format:\t%s",
1887 (ctx
->Texture
.Set
[ctx
->Texture
.CurrentSet
].Current
->Image
[0][0]->Format
== GL_RGBA
) ?
1888 "GL_RGBA" : "GLRGB" ));
1891 if ( textEnv
!= ctx
->Texture
.Set
[ctx
->Texture
.CurrentSet
].EnvMode
)
1893 textEnv
= ctx
->Texture
.Set
[ctx
->Texture
.CurrentSet
].EnvMode
;
1898 DPF(( 0, "\tTexture\tMode\tGL_MODULATE" ));
1901 DPF(( 0, "\tTexture\tMode\tGL_BLEND" ));
1904 DPF(( 0, "\tTexture\tMode\tGL_REPLACE" ));
1907 DPF(( 0, "\tTexture\tMode\tGL_DECAL" ));
1912 if ( textMag
!= ctx
->Texture
.Set
[ctx
->Texture
.CurrentSet
].Current
->MagFilter
)
1914 textMag
= ctx
->Texture
.Set
[ctx
->Texture
.CurrentSet
].Current
->MagFilter
;
1919 DPF(( 0, "\tTexture MAG\tGL_NEAREST" ));
1922 DPF(( 0, "\tTexture MAG\tGL_LINEAR" ));
1924 case GL_NEAREST_MIPMAP_NEAREST
:
1925 DPF(( 0, "\tTexture MAG\tGL_NEAREST_MIPMAP_NEAREST" ));
1927 case GL_LINEAR_MIPMAP_NEAREST
:
1928 DPF(( 0, "\tTexture MAG\tGL_LINEAR_MIPMAP_NEAREST" ));
1930 case GL_NEAREST_MIPMAP_LINEAR
:
1931 DPF(( 0, "\tTexture MAG\tGL_NEAREST_MIPMAP_LINEAR" ));
1933 case GL_LINEAR_MIPMAP_LINEAR
:
1934 DPF(( 0, "\tTexture MAG\tGL_LINEAR_MIPMAP_LINEAR" ));
1939 if ( textMin
!= ctx
->Texture
.Set
[ctx
->Texture
.CurrentSet
].Current
->MinFilter
)
1941 textMin
= ctx
->Texture
.Set
[ctx
->Texture
.CurrentSet
].Current
->MinFilter
;
1946 DPF(( 0, "\tTexture MIN\tGL_NEAREST" ));
1949 DPF(( 0, "\tTexture MIN\tGL_LINEAR" ));
1951 case GL_NEAREST_MIPMAP_NEAREST
:
1952 DPF(( 0, "\tTexture MIN\tGL_NEAREST_MIPMAP_NEAREST" ));
1954 case GL_LINEAR_MIPMAP_NEAREST
:
1955 DPF(( 0, "\tTexture MIN\tGL_LINEAR_MIPMAP_NEAREST" ));
1957 case GL_NEAREST_MIPMAP_LINEAR
:
1958 DPF(( 0, "\tTexture MIN\tGL_LINEAR_MIPMAP_LINEAR" ));
1960 case GL_LINEAR_MIPMAP_LINEAR
:
1961 DPF(( 0, "\tTexture MIN\tGL_LINEAR_MIPMAP_LINEAR" ));
1967 if ( ctx
->Polygon
.FrontMode
!= polyMode
)
1969 polyMode
= ctx
->Polygon
.FrontMode
;
1974 DPF(( 0, "\tMode\t\tGL_POINT" ));
1977 DPF(( 0, "\tMode\t\tGL_LINE" ));
1980 DPF(( 0, "\tMode\t\tGL_FILL" ));
1985 if ( depthFunc
!= ctx
->Depth
.Func
)
1987 depthFunc
= ctx
->Depth
.Func
;
1992 DPF(( 0, "\tDepth Func\tGL_NEVER" ));
1995 DPF(( 0, "\tDepth Func\tGL_LESS" ));
1998 DPF(( 0, "\tDepth Func\tGL_GEQUAL" ));
2001 DPF(( 0, "\tDepth Func\tGL_LEQUAL" ));
2004 DPF(( 0, "\tDepth Func\tGL_GREATER" ));
2007 DPF(( 0, "\tDepth Func\tGL_NOTEQUAL" ));
2010 DPF(( 0, "\tDepth Func\tGL_EQUAL" ));
2013 DPF(( 0, "\tDepth Func\tGL_ALWAYS" ));
2018 if ( depthMask
!= ctx
->Depth
.Mask
)
2020 depthMask
= ctx
->Depth
.Mask
;
2021 DPF(( 0, "\tZWrite\t\t%s", (depthMask
) ? "ENABLED" : "--------" ));
2024 if ( alphaFunc
!= ctx
->Color
.AlphaFunc
)
2026 alphaFunc
= ctx
->Color
.AlphaFunc
;
2031 DPF(( 0, "\tAlpha Func\tGL_NEVER" ));
2034 DPF(( 0, "\tAlpha Func\tGL_LESS" ));
2037 DPF(( 0, "\tAlpha Func\tGL_GEQUAL" ));
2040 DPF(( 0, "\tAlpha Func\tGL_LEQUAL" ));
2043 DPF(( 0, "\tAlpha Func\tGL_GREATER" ));
2046 DPF(( 0, "\tAlpha Func\tGL_NOTEQUAL" ));
2049 DPF(( 0, "\tAlpha Func\tGL_EQUAL" ));
2052 DPF(( 0, "\tAlpha Func\tGL_ALWAYS" ));
2057 if ( blendSrc
!= ctx
->Color
.BlendSrc
)
2059 blendSrc
= ctx
->Color
.BlendSrc
;
2064 DPF(( 0, "\tSRC Blend\tGL_ZERO" ));
2067 DPF(( 0, "\tSRC Blend\tGL_ONE" ));
2070 DPF(( 0, "\tSRC Blend\tGL_DST_COLOR" ));
2072 case GL_ONE_MINUS_DST_COLOR
:
2073 DPF(( 0, "\tSRC Blend\tGL_ONE_MINUS_DST_COLOR" ));
2076 DPF(( 0, "\tSRC Blend\tGL_SRC_ALPHA" ));
2078 case GL_ONE_MINUS_SRC_ALPHA
:
2079 DPF(( 0, "\tSRC Blend\tGL_MINUS_SRC_ALPHA" ));
2082 DPF(( 0, "\tSRC Blend\tGL_DST_ALPHA" ));
2084 case GL_ONE_MINUS_DST_ALPHA
:
2085 DPF(( 0, "\tSRC Blend\tGL_ONE_MINUS_DST_ALPHA" ));
2087 case GL_SRC_ALPHA_SATURATE
:
2088 DPF(( 0, "\tSRC Blend\tGL_SRC_ALPHA_SATURATE" ));
2090 case GL_CONSTANT_COLOR
:
2091 DPF(( 0, "\tSRC Blend\tGL_CONSTANT_COLOR" ));
2093 case GL_ONE_MINUS_CONSTANT_COLOR
:
2094 DPF(( 0, "\tSRC Blend\tGL_ONE_MINUS_CONSTANT_COLOR" ));
2096 case GL_CONSTANT_ALPHA
:
2097 DPF(( 0, "\tSRC Blend\tGL_CONSTANT_ALPHA" ));
2099 case GL_ONE_MINUS_CONSTANT_ALPHA
:
2100 DPF(( 0, "\tSRC Blend\tGL_ONE_MINUS_CONSTANT_ALPHA" ));
2105 if ( blendDest
!= ctx
->Color
.BlendDst
)
2107 blendDest
= ctx
->Color
.BlendDst
;
2112 DPF(( 0, "\tDST Blend\tGL_ZERO" ));
2115 DPF(( 0, "\tDST Blend\tGL_ONE" ));
2118 DPF(( 0, "\tDST Blend\tGL_SRC_COLOR" ));
2120 case GL_ONE_MINUS_SRC_COLOR
:
2121 DPF(( 0, "\tDST Blend\tGL_ONE_MINUS_SRC_COLOR" ));
2124 DPF(( 0, "\tDST Blend\tGL_SRC_ALPHA" ));
2126 case GL_ONE_MINUS_SRC_ALPHA
:
2127 DPF(( 0, "\tDST Blend\tGL_ONE_MINUS_SRC_ALPHA" ));
2130 DPF(( 0, "\tDST Blend\tGL_DST_ALPHA" ));
2132 case GL_ONE_MINUS_DST_ALPHA
:
2133 DPF(( 0, "\tDST Blend\tGL_ONE_MINUS_DST_ALPHA" ));
2135 case GL_CONSTANT_COLOR
:
2136 DPF(( 0, "\tDST Blend\tGL_CONSTANT_COLOR" ));
2138 case GL_ONE_MINUS_CONSTANT_COLOR
:
2139 DPF(( 0, "\tDST Blend\tGL_ONE_MINUS_CONSTANT_COLOR" ));
2141 case GL_CONSTANT_ALPHA
:
2142 DPF(( 0, "\tDST Blend\tGL_CONSTANT_ALPHA" ));
2144 case GL_ONE_MINUS_CONSTANT_ALPHA
:
2145 DPF(( 0, "\tDST Blend\tGL_ONE_MINUS_CONSTANT_ALPHA" ));