Merge branch 'mesa_7_7_branch'
[mesa.git] / src / mesa / drivers / windows / gldirect / dx9 / gld_primitive_dx9.c
1 /****************************************************************************
2 *
3 * Mesa 3-D graphics library
4 * Direct3D Driver Interface
5 *
6 * ========================================================================
7 *
8 * Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved.
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
25 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * SOFTWARE.
27 *
28 * ======================================================================
29 *
30 * Language: ANSI C
31 * Environment: Windows 9x/2000/XP/XBox (Win32)
32 *
33 * Description: Primitive (points/lines/tris/quads) rendering
34 *
35 ****************************************************************************/
36
37 //#include "../GLDirect.h"
38
39 //#include "gld_dx8.h"
40
41 #include "dglcontext.h"
42 #include "ddlog.h"
43 #include "gld_dx9.h"
44
45 #include "glheader.h"
46 #include "context.h"
47 #include "colormac.h"
48 #include "depth.h"
49 #include "extensions.h"
50 #include "macros.h"
51 #include "matrix.h"
52 // #include "mem.h"
53 //#include "mmath.h"
54 #include "mtypes.h"
55 #include "texformat.h"
56 #include "texstore.h"
57 #include "vbo/vbo.h"
58 #include "swrast/swrast.h"
59 #include "swrast_setup/swrast_setup.h"
60 #include "swrast_setup/ss_context.h"
61 #include "swrast/s_context.h"
62 #include "swrast/s_depth.h"
63 #include "swrast/s_lines.h"
64 #include "swrast/s_triangle.h"
65 #include "swrast/s_trispan.h"
66 #include "tnl/tnl.h"
67 #include "tnl/t_context.h"
68 #include "tnl/t_pipeline.h"
69
70 // Disable compiler complaints about unreferenced local variables
71 #pragma warning (disable:4101)
72
73 //---------------------------------------------------------------------------
74 // Helper defines for primitives
75 //---------------------------------------------------------------------------
76
77 //static const float ooZ = 1.0f / 65536.0f; // One over Z
78
79 #define GLD_COLOUR (D3DCOLOR_RGBA(swv->color[0], swv->color[1], swv->color[2], swv->color[3]))
80 #define GLD_SPECULAR (D3DCOLOR_RGBA(swv->specular[0], swv->specular[1], swv->specular[2], swv->specular[3]))
81 #define GLD_FLIP_Y(y) (gldCtx->dwHeight - (y))
82
83 //---------------------------------------------------------------------------
84 // 2D vertex setup
85 //---------------------------------------------------------------------------
86
87 #define GLD_SETUP_2D_VARS_POINTS \
88 GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \
89 GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); \
90 GLD_2D_VERTEX *pV = (GLD_2D_VERTEX*)gld->PB2d.pPoints; \
91 SScontext *ss = SWSETUP_CONTEXT(ctx); \
92 SWvertex *swv; \
93 DWORD dwSpecularColour; \
94 DWORD dwFlatColour
95
96 #define GLD_SETUP_2D_VARS_LINES \
97 GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \
98 GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); \
99 GLD_2D_VERTEX *pV = (GLD_2D_VERTEX*)gld->PB2d.pLines; \
100 SScontext *ss = SWSETUP_CONTEXT(ctx); \
101 SWvertex *swv; \
102 DWORD dwSpecularColour; \
103 DWORD dwFlatColour
104
105 #define GLD_SETUP_2D_VARS_TRIANGLES \
106 BOOL bFog = ctx->Fog.Enabled; \
107 GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \
108 GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); \
109 GLD_2D_VERTEX *pV = (GLD_2D_VERTEX*)gld->PB2d.pTriangles; \
110 SScontext *ss = SWSETUP_CONTEXT(ctx); \
111 SWvertex *swv; \
112 DWORD dwSpecularColour; \
113 DWORD dwFlatColour; \
114 GLuint facing = 0; \
115 struct vertex_buffer *VB; \
116 GLchan (*vbcolor)[4]; \
117 GLchan (*vbspec)[4]
118
119 #define GLD_SETUP_GET_SWVERT(s) \
120 swv = &ss->verts[##s]
121
122 #define GLD_SETUP_2D_VERTEX \
123 pV->x = swv->win[0]; \
124 pV->y = GLD_FLIP_Y(swv->win[1]); \
125 pV->rhw = swv->win[3]
126
127 #define GLD_SETUP_SMOOTH_COLOUR \
128 pV->diffuse = GLD_COLOUR
129
130 #define GLD_SETUP_GET_FLAT_COLOUR \
131 dwFlatColour = GLD_COLOUR
132 #define GLD_SETUP_GET_FLAT_FOG_COLOUR \
133 dwFlatColour = _gldComputeFog(ctx, swv)
134
135 #define GLD_SETUP_USE_FLAT_COLOUR \
136 pV->diffuse = dwFlatColour
137
138 #define GLD_SETUP_GET_FLAT_SPECULAR \
139 dwSpecularColour= GLD_SPECULAR
140
141 #define GLD_SETUP_USE_FLAT_SPECULAR \
142 pV->specular = dwSpecularColour
143
144 #define GLD_SETUP_DEPTH \
145 pV->sz = swv->win[2] / ctx->DepthMaxF
146 // pV->z = swv->win[2] * ooZ;
147
148 #define GLD_SETUP_SPECULAR \
149 pV->specular = GLD_SPECULAR
150
151 #define GLD_SETUP_FOG \
152 pV->diffuse = _gldComputeFog(ctx, swv)
153
154 #define GLD_SETUP_TEX0 \
155 pV->t0_u = swv->texcoord[0][0]; \
156 pV->t0_v = swv->texcoord[0][1]
157
158 #define GLD_SETUP_TEX1 \
159 pV->t1_u = swv->texcoord[1][0]; \
160 pV->t1_v = swv->texcoord[1][1]
161
162 #define GLD_SETUP_LIGHTING(v) \
163 if (facing == 1) { \
164 pV->diffuse = D3DCOLOR_RGBA(vbcolor[##v][0], vbcolor[##v][1], vbcolor[##v][2], vbcolor[##v][3]); \
165 if (vbspec) { \
166 pV->specular = D3DCOLOR_RGBA(vbspec[##v][0], vbspec[##v][1], vbspec[##v][2], vbspec[##v][3]); \
167 } \
168 } else { \
169 if (bFog) \
170 GLD_SETUP_FOG; \
171 else \
172 GLD_SETUP_SMOOTH_COLOUR; \
173 GLD_SETUP_SPECULAR; \
174 }
175
176 #define GLD_SETUP_GET_FLAT_LIGHTING(v) \
177 if (facing == 1) { \
178 dwFlatColour = D3DCOLOR_RGBA(vbcolor[##v][0], vbcolor[##v][1], vbcolor[##v][2], vbcolor[##v][3]); \
179 if (vbspec) { \
180 dwSpecularColour = D3DCOLOR_RGBA(vbspec[##v][0], vbspec[##v][1], vbspec[##v][2], vbspec[##v][3]); \
181 } \
182 }
183
184 #define GLD_SETUP_TWOSIDED_LIGHTING \
185 /* Two-sided lighting */ \
186 if (ctx->_TriangleCaps & DD_TRI_LIGHT_TWOSIDE) { \
187 SWvertex *verts = SWSETUP_CONTEXT(ctx)->verts; \
188 SWvertex *v[3]; \
189 GLfloat ex,ey,fx,fy,cc; \
190 /* Get vars for later */ \
191 VB = &TNL_CONTEXT(ctx)->vb; \
192 vbcolor = (GLchan (*)[4])VB->BackfaceColorPtr->data; \
193 if (VB->BackfaceSecondaryColorPtr) { \
194 vbspec = (GLchan (*)[4])VB->BackfaceSecondaryColorPtr->data; \
195 } else { \
196 vbspec = NULL; \
197 } \
198 v[0] = &verts[v0]; \
199 v[1] = &verts[v1]; \
200 v[2] = &verts[v2]; \
201 ex = v[0]->win[0] - v[2]->win[0]; \
202 ey = v[0]->win[1] - v[2]->win[1]; \
203 fx = v[1]->win[0] - v[2]->win[0]; \
204 fy = v[1]->win[1] - v[2]->win[1]; \
205 cc = ex*fy - ey*fx; \
206 facing = (cc < 0.0) ^ ctx->Polygon._FrontBit; \
207 }
208
209 //---------------------------------------------------------------------------
210 // 3D vertex setup
211 //---------------------------------------------------------------------------
212
213 #define GLD_SETUP_3D_VARS_POINTS \
214 GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \
215 GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); \
216 GLD_3D_VERTEX *pV = (GLD_3D_VERTEX*)gld->PB3d.pPoints; \
217 TNLcontext *tnl = TNL_CONTEXT(ctx); \
218 struct vertex_buffer *VB = &tnl->vb; \
219 GLfloat (*p4f)[4]; \
220 GLfloat (*tc)[4]; \
221 DWORD dwColor;
222
223 #define GLD_SETUP_3D_VARS_LINES \
224 GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \
225 GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); \
226 GLD_3D_VERTEX *pV = (GLD_3D_VERTEX*)gld->PB3d.pLines; \
227 TNLcontext *tnl = TNL_CONTEXT(ctx); \
228 struct vertex_buffer *VB = &tnl->vb; \
229 GLfloat (*p4f)[4]; \
230 GLfloat (*tc)[4]; \
231 DWORD dwColor;
232
233 #define GLD_SETUP_3D_VARS_TRIANGLES \
234 GLD_context *gldCtx = GLD_GET_CONTEXT(ctx); \
235 GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx); \
236 GLD_3D_VERTEX *pV = (GLD_3D_VERTEX*)gld->PB3d.pTriangles; \
237 TNLcontext *tnl = TNL_CONTEXT(ctx); \
238 struct vertex_buffer *VB = &tnl->vb; \
239 GLfloat (*p4f)[4]; \
240 GLfloat (*tc)[4]; \
241 DWORD dwColor;
242
243 #define GLD_SETUP_3D_VERTEX(v) \
244 p4f = VB->AttribPtr[_TNL_ATTRIB_POS]->data; \
245 pV->Position.x = p4f[##v][0]; \
246 pV->Position.y = p4f[##v][1]; \
247 pV->Position.z = p4f[##v][2];
248
249 #define GLD_SETUP_SMOOTH_COLOUR_3D(v) \
250 p4f = (GLfloat (*)[4])VB->AttribPtr[_TNL_ATTRIB_COLOR0]->data; \
251 pV->Diffuse = D3DCOLOR_COLORVALUE(p4f[##v][0], p4f[##v][1], p4f[##v][2], p4f[##v][3]);
252
253
254 #define GLD_SETUP_GET_FLAT_COLOUR_3D(v) \
255 p4f = (GLfloat (*)[4])VB->AttribPtr[_TNL_ATTRIB_COLOR00]->data; \
256 dwColor = D3DCOLOR_COLORVALUE(p4f[##v][0], p4f[##v][1], p4f[##v][2], p4f[##v][3]);
257
258 #define GLD_SETUP_USE_FLAT_COLOUR_3D \
259 pV->Diffuse = dwColor;
260
261 #define GLD_SETUP_TEX0_3D(v) \
262 if (VB->AttribPtr[_TNL_ATTRIB_TEX0]) { \
263 tc = VB->AttribPtr[_TNL_ATTRIB_TEX0]->data; \
264 pV->TexUnit0.x = tc[##v][0]; \
265 pV->TexUnit0.y = tc[##v][1]; \
266 }
267
268 #define GLD_SETUP_TEX1_3D(v) \
269 if (VB->AttribPtr[_TNL_ATTRIB_TEX1]) { \
270 tc = VB->AttribPtr[_TNL_ATTRIB_TEX1]->data; \
271 pV->TexUnit1.x = tc[##v][0]; \
272 pV->TexUnit1.y = tc[##v][1]; \
273 }
274
275 //---------------------------------------------------------------------------
276 // Helper functions
277 //---------------------------------------------------------------------------
278
279 __inline DWORD _gldComputeFog(
280 GLcontext *ctx,
281 SWvertex *swv)
282 {
283 // Full fog calculation.
284 // Based on Mesa code.
285
286 GLchan rFog, gFog, bFog;
287 GLchan fR, fG, fB;
288 const GLfloat f = swv->fog;
289 const GLfloat g = 1.0 - f;
290
291 UNCLAMPED_FLOAT_TO_CHAN(rFog, ctx->Fog.Color[RCOMP]);
292 UNCLAMPED_FLOAT_TO_CHAN(gFog, ctx->Fog.Color[GCOMP]);
293 UNCLAMPED_FLOAT_TO_CHAN(bFog, ctx->Fog.Color[BCOMP]);
294 fR = f * swv->color[0] + g * rFog;
295 fG = f * swv->color[1] + g * gFog;
296 fB = f * swv->color[2] + g * bFog;
297 return D3DCOLOR_RGBA(fR, fG, fB, swv->color[3]);
298 }
299
300 //---------------------------------------------------------------------------
301
302 void gld_ResetLineStipple_DX9(
303 GLcontext *ctx)
304 {
305 // TODO: Fake stipple with a 32x32 texture.
306 }
307
308 //---------------------------------------------------------------------------
309 // 2D (post-transformed) primitives
310 //---------------------------------------------------------------------------
311
312 void gld_Points2D_DX9(
313 GLcontext *ctx,
314 GLuint first,
315 GLuint last)
316 {
317 GLD_SETUP_2D_VARS_POINTS;
318
319 unsigned i;
320 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
321
322 // _Size is already clamped to MaxPointSize and MinPointSize
323 IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_POINTSIZE, *((DWORD*)&ctx->Point._Size));
324
325 if (VB->Elts) {
326 for (i=first; i<last; i++, pV++) {
327 if (VB->ClipMask[VB->Elts[i]] == 0) {
328 // _swrast_Point( ctx, &verts[VB->Elts[i]] );
329 GLD_SETUP_GET_SWVERT(VB->Elts[i]);
330 GLD_SETUP_2D_VERTEX;
331 GLD_SETUP_SMOOTH_COLOUR;
332 GLD_SETUP_DEPTH;
333 GLD_SETUP_SPECULAR;
334 GLD_SETUP_TEX0;
335 GLD_SETUP_TEX1;
336 }
337 }
338 } else {
339 GLD_SETUP_GET_SWVERT(first);
340 for (i=first; i<last; i++, swv++, pV++) {
341 if (VB->ClipMask[i] == 0) {
342 // _swrast_Point( ctx, &verts[i] );
343 GLD_SETUP_2D_VERTEX;
344 GLD_SETUP_SMOOTH_COLOUR;
345 GLD_SETUP_DEPTH;
346 GLD_SETUP_SPECULAR;
347 GLD_SETUP_TEX0;
348 GLD_SETUP_TEX1;
349 }
350 }
351 }
352
353 gld->PB2d.pPoints = (BYTE*)pV;
354 gld->PB2d.nPoints += (last-first);
355 }
356
357 //---------------------------------------------------------------------------
358
359 void gld_Line2DFlat_DX9(
360 GLcontext *ctx,
361 GLuint v0,
362 GLuint v1)
363 {
364 GLD_SETUP_2D_VARS_LINES;
365
366 GLD_SETUP_GET_SWVERT(v1);
367 GLD_SETUP_2D_VERTEX;
368 GLD_SETUP_DEPTH;
369 GLD_SETUP_TEX0;
370 GLD_SETUP_TEX1;
371 GLD_SETUP_GET_FLAT_COLOUR;
372 GLD_SETUP_USE_FLAT_COLOUR;
373 GLD_SETUP_GET_FLAT_SPECULAR;
374 GLD_SETUP_USE_FLAT_SPECULAR;
375 pV++;
376
377 GLD_SETUP_GET_SWVERT(v0);
378 GLD_SETUP_2D_VERTEX;
379 GLD_SETUP_DEPTH;
380 GLD_SETUP_TEX0;
381 GLD_SETUP_TEX1;
382 GLD_SETUP_USE_FLAT_COLOUR;
383 GLD_SETUP_USE_FLAT_SPECULAR;
384 pV++;
385
386 gld->PB2d.pLines = (BYTE*)pV;
387 gld->PB2d.nLines++;
388 }
389
390 //---------------------------------------------------------------------------
391
392 void gld_Line2DSmooth_DX9(
393 GLcontext *ctx,
394 GLuint v0,
395 GLuint v1)
396 {
397 GLD_SETUP_2D_VARS_LINES;
398
399 GLD_SETUP_GET_SWVERT(v0);
400 GLD_SETUP_2D_VERTEX;
401 GLD_SETUP_SMOOTH_COLOUR;
402 GLD_SETUP_DEPTH;
403 GLD_SETUP_SPECULAR;
404 GLD_SETUP_TEX0;
405 GLD_SETUP_TEX1;
406 pV++;
407
408 GLD_SETUP_GET_SWVERT(v1);
409 GLD_SETUP_2D_VERTEX;
410 GLD_SETUP_SMOOTH_COLOUR;
411 GLD_SETUP_SPECULAR;
412 GLD_SETUP_DEPTH;
413 GLD_SETUP_TEX0;
414 GLD_SETUP_TEX1;
415 pV++;
416
417 gld->PB2d.pLines = (BYTE*)pV;
418 gld->PB2d.nLines++;
419 }
420
421 //---------------------------------------------------------------------------
422
423 void gld_Triangle2DFlat_DX9(
424 GLcontext *ctx,
425 GLuint v0,
426 GLuint v1,
427 GLuint v2)
428 {
429 GLD_SETUP_2D_VARS_TRIANGLES;
430
431 GLD_SETUP_GET_SWVERT(v2);
432 GLD_SETUP_2D_VERTEX;
433 GLD_SETUP_DEPTH;
434 GLD_SETUP_TEX0;
435 GLD_SETUP_TEX1;
436 GLD_SETUP_GET_FLAT_COLOUR;
437 GLD_SETUP_USE_FLAT_COLOUR;
438 pV++;;
439
440 GLD_SETUP_GET_SWVERT(v0);
441 GLD_SETUP_2D_VERTEX;
442 GLD_SETUP_DEPTH;
443 GLD_SETUP_TEX0;
444 GLD_SETUP_TEX1;
445 GLD_SETUP_USE_FLAT_COLOUR;
446 pV++;
447
448 GLD_SETUP_GET_SWVERT(v1);
449 GLD_SETUP_2D_VERTEX;
450 GLD_SETUP_DEPTH;
451 GLD_SETUP_TEX0;
452 GLD_SETUP_TEX1;
453 GLD_SETUP_USE_FLAT_COLOUR;
454 pV++;
455
456 gld->PB2d.pTriangles = (BYTE*)pV;
457 gld->PB2d.nTriangles++;
458 }
459
460 //---------------------------------------------------------------------------
461
462 void gld_Triangle2DSmooth_DX9(
463 GLcontext *ctx,
464 GLuint v0,
465 GLuint v1,
466 GLuint v2)
467 {
468
469 GLD_SETUP_2D_VARS_TRIANGLES;
470
471 GLD_SETUP_GET_SWVERT(v0);
472 GLD_SETUP_2D_VERTEX;
473 GLD_SETUP_SMOOTH_COLOUR;
474 GLD_SETUP_DEPTH;
475 GLD_SETUP_TEX0;
476 GLD_SETUP_TEX1;
477 pV++;
478
479 GLD_SETUP_GET_SWVERT(v1);
480 GLD_SETUP_2D_VERTEX;
481 GLD_SETUP_SMOOTH_COLOUR;
482 GLD_SETUP_DEPTH;
483 GLD_SETUP_TEX0;
484 GLD_SETUP_TEX1;
485 pV++;
486
487 GLD_SETUP_GET_SWVERT(v2);
488 GLD_SETUP_2D_VERTEX;
489 GLD_SETUP_SMOOTH_COLOUR;
490 GLD_SETUP_DEPTH;
491 GLD_SETUP_TEX0;
492 GLD_SETUP_TEX1;
493 pV++;
494
495 gld->PB2d.pTriangles = (BYTE*)pV;
496 gld->PB2d.nTriangles++;
497 }
498
499 //---------------------------------------------------------------------------
500
501 void gld_Triangle2DFlatExtras_DX9(
502 GLcontext *ctx,
503 GLuint v0,
504 GLuint v1,
505 GLuint v2)
506 {
507 GLD_SETUP_2D_VARS_TRIANGLES;
508
509 GLD_SETUP_TWOSIDED_LIGHTING(v2);
510
511 GLD_SETUP_GET_SWVERT(v2);
512 GLD_SETUP_2D_VERTEX;
513 GLD_SETUP_DEPTH;
514 GLD_SETUP_TEX0;
515 GLD_SETUP_TEX1;
516 if (bFog)
517 GLD_SETUP_GET_FLAT_FOG_COLOUR;
518 else
519 GLD_SETUP_GET_FLAT_COLOUR;
520 GLD_SETUP_GET_FLAT_SPECULAR;
521 GLD_SETUP_GET_FLAT_LIGHTING(v2);
522 GLD_SETUP_USE_FLAT_COLOUR;
523 GLD_SETUP_USE_FLAT_SPECULAR;
524 pV++;
525
526 GLD_SETUP_GET_SWVERT(v0);
527 GLD_SETUP_2D_VERTEX;
528 GLD_SETUP_DEPTH;
529 GLD_SETUP_TEX0;
530 GLD_SETUP_TEX1;
531 GLD_SETUP_USE_FLAT_COLOUR;
532 GLD_SETUP_USE_FLAT_SPECULAR;
533 pV++;
534
535 GLD_SETUP_GET_SWVERT(v1);
536 GLD_SETUP_2D_VERTEX;
537 GLD_SETUP_DEPTH;
538 GLD_SETUP_TEX0;
539 GLD_SETUP_TEX1;
540 GLD_SETUP_USE_FLAT_COLOUR;
541 GLD_SETUP_USE_FLAT_SPECULAR;
542 pV++;
543
544 gld->PB2d.pTriangles = (BYTE*)pV;
545 gld->PB2d.nTriangles++;
546 }
547
548 //---------------------------------------------------------------------------
549
550 void gld_Triangle2DSmoothExtras_DX9(
551 GLcontext *ctx,
552 GLuint v0,
553 GLuint v1,
554 GLuint v2)
555 {
556 GLD_SETUP_2D_VARS_TRIANGLES;
557
558 GLD_SETUP_TWOSIDED_LIGHTING(v0);
559
560 GLD_SETUP_GET_SWVERT(v0);
561 GLD_SETUP_2D_VERTEX;
562 GLD_SETUP_DEPTH;
563 GLD_SETUP_TEX0;
564 GLD_SETUP_TEX1;
565 GLD_SETUP_LIGHTING(v0);
566 pV++;
567
568 GLD_SETUP_GET_SWVERT(v1);
569 GLD_SETUP_2D_VERTEX;
570 GLD_SETUP_DEPTH;
571 GLD_SETUP_TEX0;
572 GLD_SETUP_TEX1;
573 GLD_SETUP_LIGHTING(v1);
574 pV++;
575
576 GLD_SETUP_GET_SWVERT(v2);
577 GLD_SETUP_2D_VERTEX;
578 GLD_SETUP_DEPTH;
579 GLD_SETUP_TEX0;
580 GLD_SETUP_TEX1;
581 GLD_SETUP_LIGHTING(v2);
582 pV++;
583
584 gld->PB2d.pTriangles = (BYTE*)pV;
585 gld->PB2d.nTriangles++;
586 }
587
588 //---------------------------------------------------------------------------
589
590 void gld_Quad2DFlat_DX9(
591 GLcontext *ctx,
592 GLuint v0,
593 GLuint v1,
594 GLuint v2,
595 GLuint v3)
596 {
597 GLD_SETUP_2D_VARS_TRIANGLES;
598
599 GLD_SETUP_GET_SWVERT(v3);
600 GLD_SETUP_2D_VERTEX;
601 GLD_SETUP_DEPTH;
602 GLD_SETUP_TEX0;
603 GLD_SETUP_TEX1;
604 GLD_SETUP_GET_FLAT_COLOUR;
605 GLD_SETUP_USE_FLAT_COLOUR;
606 pV++;
607
608 GLD_SETUP_GET_SWVERT(v0);
609 GLD_SETUP_2D_VERTEX;
610 GLD_SETUP_DEPTH;
611 GLD_SETUP_TEX0;
612 GLD_SETUP_TEX1;
613 GLD_SETUP_USE_FLAT_COLOUR;
614 pV++;
615
616 GLD_SETUP_GET_SWVERT(v1);
617 GLD_SETUP_2D_VERTEX;
618 GLD_SETUP_DEPTH;
619 GLD_SETUP_TEX0;
620 GLD_SETUP_TEX1;
621 GLD_SETUP_USE_FLAT_COLOUR;
622 pV++;
623
624 GLD_SETUP_GET_SWVERT(v1);
625 GLD_SETUP_2D_VERTEX;
626 GLD_SETUP_DEPTH;
627 GLD_SETUP_TEX0;
628 GLD_SETUP_TEX1;
629 GLD_SETUP_USE_FLAT_COLOUR;
630 pV++;
631
632 GLD_SETUP_GET_SWVERT(v2);
633 GLD_SETUP_2D_VERTEX;
634 GLD_SETUP_DEPTH;
635 GLD_SETUP_TEX0;
636 GLD_SETUP_TEX1;
637 GLD_SETUP_USE_FLAT_COLOUR;
638 pV++;
639
640 GLD_SETUP_GET_SWVERT(v3);
641 GLD_SETUP_2D_VERTEX;
642 GLD_SETUP_DEPTH;
643 GLD_SETUP_TEX0;
644 GLD_SETUP_TEX1;
645 GLD_SETUP_USE_FLAT_COLOUR;
646 pV++;
647
648 gld->PB2d.pTriangles = (BYTE*)pV;
649 gld->PB2d.nTriangles += 2;
650 }
651
652 //---------------------------------------------------------------------------
653
654 void gld_Quad2DSmooth_DX9(
655 GLcontext *ctx,
656 GLuint v0,
657 GLuint v1,
658 GLuint v2,
659 GLuint v3)
660 {
661 GLD_SETUP_2D_VARS_TRIANGLES;
662
663 GLD_SETUP_GET_SWVERT(v0);
664 GLD_SETUP_2D_VERTEX;
665 GLD_SETUP_SMOOTH_COLOUR;
666 GLD_SETUP_DEPTH;
667 GLD_SETUP_TEX0;
668 GLD_SETUP_TEX1;
669 pV++;
670
671 GLD_SETUP_GET_SWVERT(v1);
672 GLD_SETUP_2D_VERTEX;
673 GLD_SETUP_SMOOTH_COLOUR;
674 GLD_SETUP_DEPTH;
675 GLD_SETUP_TEX0;
676 GLD_SETUP_TEX1;
677 pV++;
678
679 GLD_SETUP_GET_SWVERT(v2);
680 GLD_SETUP_2D_VERTEX;
681 GLD_SETUP_SMOOTH_COLOUR;
682 GLD_SETUP_DEPTH;
683 GLD_SETUP_TEX0;
684 GLD_SETUP_TEX1;
685 pV++;
686
687 GLD_SETUP_GET_SWVERT(v2);
688 GLD_SETUP_2D_VERTEX;
689 GLD_SETUP_SMOOTH_COLOUR;
690 GLD_SETUP_DEPTH;
691 GLD_SETUP_TEX0;
692 GLD_SETUP_TEX1;
693 pV++;
694
695 GLD_SETUP_GET_SWVERT(v3);
696 GLD_SETUP_2D_VERTEX;
697 GLD_SETUP_SMOOTH_COLOUR;
698 GLD_SETUP_DEPTH;
699 GLD_SETUP_TEX0;
700 GLD_SETUP_TEX1;
701 pV++;
702
703 GLD_SETUP_GET_SWVERT(v0);
704 GLD_SETUP_2D_VERTEX;
705 GLD_SETUP_SMOOTH_COLOUR;
706 GLD_SETUP_DEPTH;
707 GLD_SETUP_TEX0;
708 GLD_SETUP_TEX1;
709 pV++;
710
711 gld->PB2d.pTriangles = (BYTE*)pV;
712 gld->PB2d.nTriangles += 2;
713 }
714
715 //---------------------------------------------------------------------------
716
717 void gld_Quad2DFlatExtras_DX9(
718 GLcontext *ctx,
719 GLuint v0,
720 GLuint v1,
721 GLuint v2,
722 GLuint v3)
723 {
724 GLD_SETUP_2D_VARS_TRIANGLES;
725
726 GLD_SETUP_TWOSIDED_LIGHTING(v3);
727
728 GLD_SETUP_GET_SWVERT(v3);
729 GLD_SETUP_2D_VERTEX;
730 GLD_SETUP_DEPTH;
731 GLD_SETUP_TEX0;
732 GLD_SETUP_TEX1;
733 if (bFog)
734 GLD_SETUP_GET_FLAT_FOG_COLOUR;
735 else
736 GLD_SETUP_GET_FLAT_COLOUR;
737 GLD_SETUP_GET_FLAT_SPECULAR;
738 GLD_SETUP_GET_FLAT_LIGHTING(v3);
739 GLD_SETUP_USE_FLAT_COLOUR;
740 GLD_SETUP_USE_FLAT_SPECULAR;
741 pV++;
742
743 GLD_SETUP_GET_SWVERT(v0);
744 GLD_SETUP_2D_VERTEX;
745 GLD_SETUP_DEPTH;
746 GLD_SETUP_TEX0;
747 GLD_SETUP_TEX1;
748 GLD_SETUP_USE_FLAT_COLOUR;
749 GLD_SETUP_USE_FLAT_SPECULAR;
750 pV++;
751
752 GLD_SETUP_GET_SWVERT(v1);
753 GLD_SETUP_2D_VERTEX;
754 GLD_SETUP_DEPTH;
755 GLD_SETUP_TEX0;
756 GLD_SETUP_TEX1;
757 GLD_SETUP_USE_FLAT_COLOUR;
758 GLD_SETUP_USE_FLAT_SPECULAR;
759 pV++;
760
761 GLD_SETUP_GET_SWVERT(v1);
762 GLD_SETUP_2D_VERTEX;
763 GLD_SETUP_DEPTH;
764 GLD_SETUP_TEX0;
765 GLD_SETUP_TEX1;
766 GLD_SETUP_USE_FLAT_COLOUR;
767 GLD_SETUP_USE_FLAT_SPECULAR;
768 pV++;
769
770 GLD_SETUP_GET_SWVERT(v2);
771 GLD_SETUP_2D_VERTEX;
772 GLD_SETUP_DEPTH;
773 GLD_SETUP_TEX0;
774 GLD_SETUP_TEX1;
775 GLD_SETUP_USE_FLAT_COLOUR;
776 GLD_SETUP_USE_FLAT_SPECULAR;
777 pV++;
778
779 GLD_SETUP_GET_SWVERT(v3);
780 GLD_SETUP_2D_VERTEX;
781 GLD_SETUP_DEPTH;
782 GLD_SETUP_TEX0;
783 GLD_SETUP_TEX1;
784 GLD_SETUP_USE_FLAT_COLOUR;
785 GLD_SETUP_USE_FLAT_SPECULAR;
786 pV++;
787
788 gld->PB2d.pTriangles = (BYTE*)pV;
789 gld->PB2d.nTriangles += 2;
790 }
791
792 //---------------------------------------------------------------------------
793
794 void gld_Quad2DSmoothExtras_DX9(
795 GLcontext *ctx,
796 GLuint v0,
797 GLuint v1,
798 GLuint v2,
799 GLuint v3)
800 {
801 GLD_SETUP_2D_VARS_TRIANGLES;
802
803 GLD_SETUP_TWOSIDED_LIGHTING(v0);
804
805 GLD_SETUP_GET_SWVERT(v0);
806 GLD_SETUP_2D_VERTEX;
807 GLD_SETUP_DEPTH;
808 GLD_SETUP_TEX0;
809 GLD_SETUP_TEX1;
810 GLD_SETUP_LIGHTING(v0);
811 pV++;
812
813 GLD_SETUP_GET_SWVERT(v1);
814 GLD_SETUP_2D_VERTEX;
815 GLD_SETUP_DEPTH;
816 GLD_SETUP_TEX0;
817 GLD_SETUP_TEX1;
818 GLD_SETUP_LIGHTING(v1);
819 pV++;
820
821 GLD_SETUP_GET_SWVERT(v2);
822 GLD_SETUP_2D_VERTEX;
823 GLD_SETUP_DEPTH;
824 GLD_SETUP_TEX0;
825 GLD_SETUP_TEX1;
826 GLD_SETUP_LIGHTING(v2);
827 pV++;
828
829 GLD_SETUP_GET_SWVERT(v2);
830 GLD_SETUP_2D_VERTEX;
831 GLD_SETUP_DEPTH;
832 GLD_SETUP_TEX0;
833 GLD_SETUP_TEX1;
834 GLD_SETUP_LIGHTING(v2);
835 pV++;
836
837 GLD_SETUP_GET_SWVERT(v3);
838 GLD_SETUP_2D_VERTEX;
839 GLD_SETUP_DEPTH;
840 GLD_SETUP_TEX0;
841 GLD_SETUP_TEX1;
842 GLD_SETUP_LIGHTING(v3);
843 pV++;
844
845 GLD_SETUP_GET_SWVERT(v0);
846 GLD_SETUP_2D_VERTEX;
847 GLD_SETUP_DEPTH;
848 GLD_SETUP_TEX0;
849 GLD_SETUP_TEX1;
850 GLD_SETUP_LIGHTING(v0);
851 pV++;
852
853 gld->PB2d.pTriangles = (BYTE*)pV;
854 gld->PB2d.nTriangles += 2;
855 }
856
857 //---------------------------------------------------------------------------
858 // 3D (pre-transformed) primitives
859 //---------------------------------------------------------------------------
860
861 void gld_Points3D_DX9(
862 GLcontext *ctx,
863 GLuint first,
864 GLuint last)
865 {
866 GLD_SETUP_3D_VARS_POINTS
867
868 unsigned i;
869 // struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
870
871 // _Size is already clamped to MaxPointSize and MinPointSize
872 IDirect3DDevice9_SetRenderState(gld->pDev, D3DRS_POINTSIZE, *((DWORD*)&ctx->Point._Size));
873
874 if (VB->Elts) {
875 for (i=first; i<last; i++, pV++) {
876 if (VB->ClipMask[VB->Elts[i]] == 0) {
877 // _swrast_Point( ctx, &verts[VB->Elts[i]] );
878 // GLD_SETUP_GET_SWVERT(VB->Elts[i]);
879 GLD_SETUP_3D_VERTEX(VB->Elts[i])
880 GLD_SETUP_SMOOTH_COLOUR_3D(i)
881 GLD_SETUP_TEX0_3D(i)
882 GLD_SETUP_TEX1_3D(i)
883 }
884 }
885 } else {
886 // GLD_SETUP_GET_SWVERT(first);
887 for (i=first; i<last; i++, pV++) {
888 if (VB->ClipMask[i] == 0) {
889 // _swrast_Point( ctx, &verts[i] );
890 GLD_SETUP_3D_VERTEX(i)
891 GLD_SETUP_SMOOTH_COLOUR_3D(i)
892 GLD_SETUP_TEX0_3D(i)
893 GLD_SETUP_TEX1_3D(i)
894 }
895 }
896 }
897 /*
898 for (i=first; i<last; i++, pV++) {
899 GLD_SETUP_3D_VERTEX(i)
900 GLD_SETUP_SMOOTH_COLOUR_3D(i)
901 GLD_SETUP_TEX0_3D(i)
902 GLD_SETUP_TEX1_3D(i)
903 }
904 */
905 gld->PB3d.pPoints = (BYTE*)pV;
906 gld->PB3d.nPoints += (last-first);
907 }
908
909 //---------------------------------------------------------------------------
910 // Line functions
911 //---------------------------------------------------------------------------
912
913 void gld_Line3DFlat_DX9(
914 GLcontext *ctx,
915 GLuint v0,
916 GLuint v1)
917 {
918 GLD_SETUP_3D_VARS_LINES
919
920 GLD_SETUP_3D_VERTEX(v1)
921 GLD_SETUP_GET_FLAT_COLOUR_3D(v1)
922 GLD_SETUP_USE_FLAT_COLOUR_3D
923 GLD_SETUP_TEX0_3D(v1)
924 GLD_SETUP_TEX1_3D(v1)
925 pV++;
926
927 GLD_SETUP_3D_VERTEX(v0)
928 GLD_SETUP_USE_FLAT_COLOUR_3D
929 GLD_SETUP_TEX0_3D(v0)
930 GLD_SETUP_TEX1_3D(v0)
931 pV++;
932
933 gld->PB3d.pLines = (BYTE*)pV;
934 gld->PB3d.nLines++;
935 }
936
937 //---------------------------------------------------------------------------
938
939 void gld_Line3DSmooth_DX9(
940 GLcontext *ctx,
941 GLuint v0,
942 GLuint v1)
943 {
944 GLD_SETUP_3D_VARS_LINES
945
946 GLD_SETUP_3D_VERTEX(v1)
947 GLD_SETUP_SMOOTH_COLOUR_3D(v1)
948 GLD_SETUP_TEX0_3D(v1)
949 GLD_SETUP_TEX1_3D(v1)
950 pV++;
951
952 GLD_SETUP_3D_VERTEX(v0)
953 GLD_SETUP_SMOOTH_COLOUR_3D(v0)
954 GLD_SETUP_TEX0_3D(v0)
955 GLD_SETUP_TEX1_3D(v0)
956 pV++;
957
958 gld->PB3d.pLines = (BYTE*)pV;
959 gld->PB3d.nLines++;
960 }
961
962 //---------------------------------------------------------------------------
963 // Triangle functions
964 //---------------------------------------------------------------------------
965
966 void gld_Triangle3DFlat_DX9(
967 GLcontext *ctx,
968 GLuint v0,
969 GLuint v1,
970 GLuint v2)
971 {
972 GLD_SETUP_3D_VARS_TRIANGLES
973
974 GLD_SETUP_3D_VERTEX(v2)
975 GLD_SETUP_TEX0_3D(v2)
976 GLD_SETUP_TEX1_3D(v2)
977 GLD_SETUP_GET_FLAT_COLOUR_3D(v2)
978 GLD_SETUP_USE_FLAT_COLOUR_3D
979 pV++;
980
981 GLD_SETUP_3D_VERTEX(v0)
982 GLD_SETUP_TEX0_3D(v0)
983 GLD_SETUP_TEX1_3D(v0)
984 GLD_SETUP_USE_FLAT_COLOUR_3D
985 pV++;
986
987 GLD_SETUP_3D_VERTEX(v1)
988 GLD_SETUP_TEX0_3D(v1)
989 GLD_SETUP_TEX1_3D(v1)
990 GLD_SETUP_USE_FLAT_COLOUR_3D
991 pV++;
992
993 gld->PB3d.pTriangles = (BYTE*)pV;
994 gld->PB3d.nTriangles++;
995 }
996
997 //---------------------------------------------------------------------------
998
999 void gld_Triangle3DSmooth_DX9(
1000 GLcontext *ctx,
1001 GLuint v0,
1002 GLuint v1,
1003 GLuint v2)
1004 {
1005 GLD_SETUP_3D_VARS_TRIANGLES
1006
1007 GLD_SETUP_3D_VERTEX(v0)
1008 GLD_SETUP_SMOOTH_COLOUR_3D(v0)
1009 GLD_SETUP_TEX0_3D(v0)
1010 GLD_SETUP_TEX1_3D(v0)
1011 pV++;
1012
1013 GLD_SETUP_3D_VERTEX(v1)
1014 GLD_SETUP_SMOOTH_COLOUR_3D(v1)
1015 GLD_SETUP_TEX0_3D(v1)
1016 GLD_SETUP_TEX1_3D(v1)
1017 pV++;
1018
1019 GLD_SETUP_3D_VERTEX(v2)
1020 GLD_SETUP_SMOOTH_COLOUR_3D(v2)
1021 GLD_SETUP_TEX0_3D(v2)
1022 GLD_SETUP_TEX1_3D(v2)
1023 pV++;
1024
1025 gld->PB3d.pTriangles = (BYTE*)pV;
1026 gld->PB3d.nTriangles++;
1027 }
1028
1029 //---------------------------------------------------------------------------
1030 // Quad functions
1031 //---------------------------------------------------------------------------
1032
1033 void gld_Quad3DFlat_DX9(
1034 GLcontext *ctx,
1035 GLuint v0,
1036 GLuint v1,
1037 GLuint v2,
1038 GLuint v3)
1039 {
1040 GLD_SETUP_3D_VARS_TRIANGLES
1041
1042 GLD_SETUP_3D_VERTEX(v3)
1043 GLD_SETUP_GET_FLAT_COLOUR_3D(v3)
1044 GLD_SETUP_USE_FLAT_COLOUR_3D
1045 GLD_SETUP_TEX0_3D(v3)
1046 GLD_SETUP_TEX1_3D(v3)
1047 pV++;
1048
1049 GLD_SETUP_3D_VERTEX(v0)
1050 GLD_SETUP_USE_FLAT_COLOUR_3D
1051 GLD_SETUP_TEX0_3D(v0)
1052 GLD_SETUP_TEX1_3D(v0)
1053 pV++;
1054
1055 GLD_SETUP_3D_VERTEX(v1)
1056 GLD_SETUP_USE_FLAT_COLOUR_3D
1057 GLD_SETUP_TEX0_3D(v1)
1058 GLD_SETUP_TEX1_3D(v1)
1059 pV++;
1060
1061 GLD_SETUP_3D_VERTEX(v1)
1062 GLD_SETUP_USE_FLAT_COLOUR_3D
1063 GLD_SETUP_TEX0_3D(v1)
1064 GLD_SETUP_TEX1_3D(v1)
1065 pV++;
1066
1067 GLD_SETUP_3D_VERTEX(v2)
1068 GLD_SETUP_USE_FLAT_COLOUR_3D
1069 GLD_SETUP_TEX0_3D(v2)
1070 GLD_SETUP_TEX1_3D(v2)
1071 pV++;
1072
1073 GLD_SETUP_3D_VERTEX(v3)
1074 GLD_SETUP_USE_FLAT_COLOUR_3D
1075 GLD_SETUP_TEX0_3D(v3)
1076 GLD_SETUP_TEX1_3D(v3)
1077 pV++;
1078
1079 gld->PB3d.pTriangles = (BYTE*)pV;
1080 gld->PB3d.nTriangles += 2;
1081 }
1082
1083 //---------------------------------------------------------------------------
1084
1085 void gld_Quad3DSmooth_DX9(
1086 GLcontext *ctx,
1087 GLuint v0,
1088 GLuint v1,
1089 GLuint v2,
1090 GLuint v3)
1091 {
1092 GLD_SETUP_3D_VARS_TRIANGLES
1093
1094 GLD_SETUP_3D_VERTEX(v0)
1095 GLD_SETUP_SMOOTH_COLOUR_3D(v0)
1096 GLD_SETUP_TEX0_3D(v0)
1097 GLD_SETUP_TEX1_3D(v0)
1098 pV++;
1099
1100 GLD_SETUP_3D_VERTEX(v1)
1101 GLD_SETUP_SMOOTH_COLOUR_3D(v1)
1102 GLD_SETUP_TEX0_3D(v1)
1103 GLD_SETUP_TEX1_3D(v1)
1104 pV++;
1105
1106 GLD_SETUP_3D_VERTEX(v2)
1107 GLD_SETUP_SMOOTH_COLOUR_3D(v2)
1108 GLD_SETUP_TEX0_3D(v2)
1109 GLD_SETUP_TEX1_3D(v2)
1110 pV++;
1111
1112 GLD_SETUP_3D_VERTEX(v2)
1113 GLD_SETUP_SMOOTH_COLOUR_3D(v2)
1114 GLD_SETUP_TEX0_3D(v2)
1115 GLD_SETUP_TEX1_3D(v2)
1116 pV++;
1117
1118 GLD_SETUP_3D_VERTEX(v3)
1119 GLD_SETUP_SMOOTH_COLOUR_3D(v3)
1120 GLD_SETUP_TEX0_3D(v3)
1121 GLD_SETUP_TEX1_3D(v3)
1122 pV++;
1123
1124 GLD_SETUP_3D_VERTEX(v0)
1125 GLD_SETUP_SMOOTH_COLOUR_3D(v0)
1126 GLD_SETUP_TEX0_3D(v0)
1127 GLD_SETUP_TEX1_3D(v0)
1128 pV++;
1129
1130 gld->PB3d.pTriangles = (BYTE*)pV;
1131 gld->PB3d.nTriangles += 2;
1132 }
1133
1134 //---------------------------------------------------------------------------
1135 // Vertex setup for two-sided-lighting vertex shader
1136 //---------------------------------------------------------------------------
1137
1138 /*
1139
1140 void gld_Points2DTwoside_DX9(GLcontext *ctx, GLuint first, GLuint last)
1141 {
1142 // NOTE: Two-sided lighting does not apply to Points
1143 }
1144
1145 //---------------------------------------------------------------------------
1146
1147 void gld_Line2DFlatTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1)
1148 {
1149 // NOTE: Two-sided lighting does not apply to Lines
1150 }
1151
1152 //---------------------------------------------------------------------------
1153
1154 void gld_Line2DSmoothTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1)
1155 {
1156 // NOTE: Two-sided lighting does not apply to Lines
1157 }
1158
1159 //---------------------------------------------------------------------------
1160
1161 void gld_Triangle2DFlatTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2)
1162 {
1163 }
1164
1165 //---------------------------------------------------------------------------
1166
1167 void gld_Triangle2DSmoothTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2)
1168 {
1169 GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
1170 GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx);
1171 GLD_TWOSIDED_VERTEX *pV = (GLD_TWOSIDED_VERTEX*)gld->PBtwosidelight.pTriangles;
1172 SScontext *ss = SWSETUP_CONTEXT(ctx);
1173 SWvertex *swv;
1174 DWORD dwSpecularColour;
1175 DWORD dwFlatColour;
1176 GLuint facing = 0;
1177 struct vertex_buffer *VB;
1178 GLchan (*vbcolor)[4];
1179 GLchan (*vbspec)[4];
1180
1181 // Reciprocal of DepthMax
1182 const float ooDepthMax = 1.0f / ctx->DepthMaxF;
1183
1184 // 1st vert
1185 swv = &ss->verts[v0];
1186 pV->Position.x = swv->win[0];
1187 pV->Position.y = GLD_FLIP_Y(swv->win[1]);
1188 pV->Position.z = swv->win[2] * ooDepthMax;
1189 pV->Position.w = swv->win[3];
1190 pV->TexUnit0.x = swv->texcoord[0][0];
1191 pV->TexUnit0.y = swv->texcoord[0][1];
1192 pV->TexUnit1.x = swv->texcoord[1][0];
1193 pV->TexUnit1.y = swv->texcoord[1][1];
1194 pV->FrontDiffuse = GLD_COLOUR;
1195 pV->FrontSpecular = GLD_SPECULAR;
1196 pV++;
1197
1198 // 2nd vert
1199 swv = &ss->verts[v1];
1200 pV->Position.x = swv->win[0];
1201 pV->Position.y = GLD_FLIP_Y(swv->win[1]);
1202 pV->Position.z = swv->win[2] * ooDepthMax;
1203 pV->Position.w = swv->win[3];
1204 pV->TexUnit0.x = swv->texcoord[0][0];
1205 pV->TexUnit0.y = swv->texcoord[0][1];
1206 pV->TexUnit1.x = swv->texcoord[1][0];
1207 pV->TexUnit1.y = swv->texcoord[1][1];
1208 pV->FrontDiffuse = GLD_COLOUR;
1209 pV->FrontSpecular = GLD_SPECULAR;
1210 pV++;
1211
1212 // 3rd vert
1213 swv = &ss->verts[v2];
1214 pV->Position.x = swv->win[0];
1215 pV->Position.y = GLD_FLIP_Y(swv->win[1]);
1216 pV->Position.z = swv->win[2] * ooDepthMax;
1217 pV->Position.w = swv->win[3];
1218 pV->TexUnit0.x = swv->texcoord[0][0];
1219 pV->TexUnit0.y = swv->texcoord[0][1];
1220 pV->TexUnit1.x = swv->texcoord[1][0];
1221 pV->TexUnit1.y = swv->texcoord[1][1];
1222 pV->FrontDiffuse = GLD_COLOUR;
1223 pV->FrontSpecular = GLD_SPECULAR;
1224 pV++;
1225
1226 gld->PBtwosidelight.pTriangles = (BYTE*)pV;
1227 gld->PBtwosidelight.nTriangles++;
1228 }
1229
1230 //---------------------------------------------------------------------------
1231
1232 void gld_Quad2DFlatTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
1233 {
1234 GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
1235 GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx);
1236 GLD_TWOSIDED_VERTEX *pV = (GLD_TWOSIDED_VERTEX*)gld->PBtwosidelight.pTriangles;
1237 SScontext *ss = SWSETUP_CONTEXT(ctx);
1238 SWvertex *swv;
1239 DWORD dwSpecularColour;
1240 DWORD dwFlatColour;
1241 GLuint facing = 0;
1242 struct vertex_buffer *VB;
1243 GLchan (*vbcolor)[4];
1244 GLchan (*vbspec)[4];
1245
1246 // Reciprocal of DepthMax
1247 const float ooDepthMax = 1.0f / ctx->DepthMaxF;
1248
1249 // 1st vert
1250 swv = &ss->verts[v0];
1251 pV->Position.x = swv->win[0];
1252 pV->Position.y = GLD_FLIP_Y(swv->win[1]);
1253 pV->Position.z = swv->win[2] * ooDepthMax;
1254 pV->Position.w = swv->win[3];
1255 pV->TexUnit0.x = swv->texcoord[0][0];
1256 pV->TexUnit0.y = swv->texcoord[0][1];
1257 pV->TexUnit1.x = swv->texcoord[1][0];
1258 pV->TexUnit1.y = swv->texcoord[1][1];
1259 pV->FrontDiffuse = GLD_COLOUR;
1260 pV->FrontSpecular = GLD_SPECULAR;
1261 pV++;
1262
1263 // 2nd vert
1264 swv = &ss->verts[v1];
1265 pV->Position.x = swv->win[0];
1266 pV->Position.y = GLD_FLIP_Y(swv->win[1]);
1267 pV->Position.z = swv->win[2] * ooDepthMax;
1268 pV->Position.w = swv->win[3];
1269 pV->TexUnit0.x = swv->texcoord[0][0];
1270 pV->TexUnit0.y = swv->texcoord[0][1];
1271 pV->TexUnit1.x = swv->texcoord[1][0];
1272 pV->TexUnit1.y = swv->texcoord[1][1];
1273 pV->FrontDiffuse = GLD_COLOUR;
1274 pV->FrontSpecular = GLD_SPECULAR;
1275 pV++;
1276
1277 // 3rd vert
1278 swv = &ss->verts[v2];
1279 pV->Position.x = swv->win[0];
1280 pV->Position.y = GLD_FLIP_Y(swv->win[1]);
1281 pV->Position.z = swv->win[2] * ooDepthMax;
1282 pV->Position.w = swv->win[3];
1283 pV->TexUnit0.x = swv->texcoord[0][0];
1284 pV->TexUnit0.y = swv->texcoord[0][1];
1285 pV->TexUnit1.x = swv->texcoord[1][0];
1286 pV->TexUnit1.y = swv->texcoord[1][1];
1287 pV->FrontDiffuse = GLD_COLOUR;
1288 pV->FrontSpecular = GLD_SPECULAR;
1289 pV++;
1290
1291 // 4th vert
1292 swv = &ss->verts[v2];
1293 pV->Position.x = swv->win[0];
1294 pV->Position.y = GLD_FLIP_Y(swv->win[1]);
1295 pV->Position.z = swv->win[2] * ooDepthMax;
1296 pV->Position.w = swv->win[3];
1297 pV->TexUnit0.x = swv->texcoord[0][0];
1298 pV->TexUnit0.y = swv->texcoord[0][1];
1299 pV->TexUnit1.x = swv->texcoord[1][0];
1300 pV->TexUnit1.y = swv->texcoord[1][1];
1301 pV->FrontDiffuse = GLD_COLOUR;
1302 pV->FrontSpecular = GLD_SPECULAR;
1303 pV++;
1304
1305 // 5th vert
1306 swv = &ss->verts[v3];
1307 pV->Position.x = swv->win[0];
1308 pV->Position.y = GLD_FLIP_Y(swv->win[1]);
1309 pV->Position.z = swv->win[2] * ooDepthMax;
1310 pV->Position.w = swv->win[3];
1311 pV->TexUnit0.x = swv->texcoord[0][0];
1312 pV->TexUnit0.y = swv->texcoord[0][1];
1313 pV->TexUnit1.x = swv->texcoord[1][0];
1314 pV->TexUnit1.y = swv->texcoord[1][1];
1315 pV->FrontDiffuse = GLD_COLOUR;
1316 pV->FrontSpecular = GLD_SPECULAR;
1317 pV++;
1318
1319 // 6th vert
1320 swv = &ss->verts[v0];
1321 pV->Position.x = swv->win[0];
1322 pV->Position.y = GLD_FLIP_Y(swv->win[1]);
1323 pV->Position.z = swv->win[2] * ooDepthMax;
1324 pV->Position.w = swv->win[3];
1325 pV->TexUnit0.x = swv->texcoord[0][0];
1326 pV->TexUnit0.y = swv->texcoord[0][1];
1327 pV->TexUnit1.x = swv->texcoord[1][0];
1328 pV->TexUnit1.y = swv->texcoord[1][1];
1329 pV->FrontDiffuse = GLD_COLOUR;
1330 pV->FrontSpecular = GLD_SPECULAR;
1331 pV++;
1332
1333 gld->PBtwosidelight.pTriangles = (BYTE*)pV;
1334 gld->PBtwosidelight.nTriangles += 2;
1335 }
1336
1337 //---------------------------------------------------------------------------
1338
1339 void gld_Quad2DSmoothTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
1340 {
1341 GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
1342 GLD_driver_dx9 *gld = GLD_GET_DX9_DRIVER(gldCtx);
1343 GLD_TWOSIDED_VERTEX *pV = (GLD_TWOSIDED_VERTEX*)gld->PBtwosidelight.pTriangles;
1344 SScontext *ss = SWSETUP_CONTEXT(ctx);
1345 SWvertex *swv;
1346 DWORD dwSpecularColour;
1347 DWORD dwFlatColour;
1348 GLuint facing = 0;
1349 struct vertex_buffer *VB;
1350 GLchan (*vbcolor)[4];
1351 GLchan (*vbspec)[4];
1352
1353 // Reciprocal of DepthMax
1354 const float ooDepthMax = 1.0f / ctx->DepthMaxF;
1355
1356 // 1st vert
1357 swv = &ss->verts[v0];
1358 pV->Position.x = swv->win[0];
1359 pV->Position.y = GLD_FLIP_Y(swv->win[1]);
1360 pV->Position.z = swv->win[2] * ooDepthMax;
1361 pV->Position.w = swv->win[3];
1362 pV->TexUnit0.x = swv->texcoord[0][0];
1363 pV->TexUnit0.y = swv->texcoord[0][1];
1364 pV->TexUnit1.x = swv->texcoord[1][0];
1365 pV->TexUnit1.y = swv->texcoord[1][1];
1366 pV->FrontDiffuse = GLD_COLOUR;
1367 pV->FrontSpecular = GLD_SPECULAR;
1368 pV++;
1369
1370 // 2nd vert
1371 swv = &ss->verts[v1];
1372 pV->Position.x = swv->win[0];
1373 pV->Position.y = GLD_FLIP_Y(swv->win[1]);
1374 pV->Position.z = swv->win[2] * ooDepthMax;
1375 pV->Position.w = swv->win[3];
1376 pV->TexUnit0.x = swv->texcoord[0][0];
1377 pV->TexUnit0.y = swv->texcoord[0][1];
1378 pV->TexUnit1.x = swv->texcoord[1][0];
1379 pV->TexUnit1.y = swv->texcoord[1][1];
1380 pV->FrontDiffuse = GLD_COLOUR;
1381 pV->FrontSpecular = GLD_SPECULAR;
1382 pV++;
1383
1384 // 3rd vert
1385 swv = &ss->verts[v2];
1386 pV->Position.x = swv->win[0];
1387 pV->Position.y = GLD_FLIP_Y(swv->win[1]);
1388 pV->Position.z = swv->win[2] * ooDepthMax;
1389 pV->Position.w = swv->win[3];
1390 pV->TexUnit0.x = swv->texcoord[0][0];
1391 pV->TexUnit0.y = swv->texcoord[0][1];
1392 pV->TexUnit1.x = swv->texcoord[1][0];
1393 pV->TexUnit1.y = swv->texcoord[1][1];
1394 pV->FrontDiffuse = GLD_COLOUR;
1395 pV->FrontSpecular = GLD_SPECULAR;
1396 pV++;
1397
1398 // 4th vert
1399 swv = &ss->verts[v2];
1400 pV->Position.x = swv->win[0];
1401 pV->Position.y = GLD_FLIP_Y(swv->win[1]);
1402 pV->Position.z = swv->win[2] * ooDepthMax;
1403 pV->Position.w = swv->win[3];
1404 pV->TexUnit0.x = swv->texcoord[0][0];
1405 pV->TexUnit0.y = swv->texcoord[0][1];
1406 pV->TexUnit1.x = swv->texcoord[1][0];
1407 pV->TexUnit1.y = swv->texcoord[1][1];
1408 pV->FrontDiffuse = GLD_COLOUR;
1409 pV->FrontSpecular = GLD_SPECULAR;
1410 pV++;
1411
1412 // 5th vert
1413 swv = &ss->verts[v3];
1414 pV->Position.x = swv->win[0];
1415 pV->Position.y = GLD_FLIP_Y(swv->win[1]);
1416 pV->Position.z = swv->win[2] * ooDepthMax;
1417 pV->Position.w = swv->win[3];
1418 pV->TexUnit0.x = swv->texcoord[0][0];
1419 pV->TexUnit0.y = swv->texcoord[0][1];
1420 pV->TexUnit1.x = swv->texcoord[1][0];
1421 pV->TexUnit1.y = swv->texcoord[1][1];
1422 pV->FrontDiffuse = GLD_COLOUR;
1423 pV->FrontSpecular = GLD_SPECULAR;
1424 pV++;
1425
1426 // 6th vert
1427 swv = &ss->verts[v0];
1428 pV->Position.x = swv->win[0];
1429 pV->Position.y = GLD_FLIP_Y(swv->win[1]);
1430 pV->Position.z = swv->win[2] * ooDepthMax;
1431 pV->Position.w = swv->win[3];
1432 pV->TexUnit0.x = swv->texcoord[0][0];
1433 pV->TexUnit0.y = swv->texcoord[0][1];
1434 pV->TexUnit1.x = swv->texcoord[1][0];
1435 pV->TexUnit1.y = swv->texcoord[1][1];
1436 pV->FrontDiffuse = GLD_COLOUR;
1437 pV->FrontSpecular = GLD_SPECULAR;
1438 pV++;
1439
1440 gld->PBtwosidelight.pTriangles = (BYTE*)pV;
1441 gld->PBtwosidelight.nTriangles += 2;
1442 }
1443
1444 //---------------------------------------------------------------------------
1445
1446 */