2 * WINED3D draw functions
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2002-2004 Raphael Junqueira
6 * Copyright 2004 Christian Costa
7 * Copyright 2005 Oliver Stieber
8 * Copyright 2006 Henri Verbeet
9 * Copyright 2007 Stefan Dösinger for CodeWeavers
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wined3d_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(d3d_draw
);
30 #define GLINFO_LOCATION This->adapter->gl_info
35 extern IWineD3DVertexShaderImpl
* VertexShaders
[64];
36 extern IWineD3DVertexDeclarationImpl
* VertexShaderDeclarations
[64];
37 extern IWineD3DPixelShaderImpl
* PixelShaders
[64];
39 #undef GL_VERSION_1_4 /* To be fixed, caused by mesa headers */
42 /* Issues the glBegin call for gl given the primitive type and count */
43 static DWORD
primitiveToGl(WINED3DPRIMITIVETYPE PrimitiveType
,
47 DWORD NumVertexes
= NumPrimitives
;
49 switch (PrimitiveType
) {
50 case WINED3DPT_POINTLIST
:
52 *primType
= GL_POINTS
;
53 NumVertexes
= NumPrimitives
;
56 case WINED3DPT_LINELIST
:
59 NumVertexes
= NumPrimitives
* 2;
62 case WINED3DPT_LINESTRIP
:
63 TRACE("LINE_STRIP\n");
64 *primType
= GL_LINE_STRIP
;
65 NumVertexes
= NumPrimitives
+ 1;
68 case WINED3DPT_TRIANGLELIST
:
70 *primType
= GL_TRIANGLES
;
71 NumVertexes
= NumPrimitives
* 3;
74 case WINED3DPT_TRIANGLESTRIP
:
75 TRACE("TRIANGLE_STRIP\n");
76 *primType
= GL_TRIANGLE_STRIP
;
77 NumVertexes
= NumPrimitives
+ 2;
80 case WINED3DPT_TRIANGLEFAN
:
81 TRACE("TRIANGLE_FAN\n");
82 *primType
= GL_TRIANGLE_FAN
;
83 NumVertexes
= NumPrimitives
+ 2;
87 FIXME("Unhandled primitive\n");
88 *primType
= GL_POINTS
;
94 static BOOL
fixed_get_input(
95 BYTE usage
, BYTE usage_idx
,
96 unsigned int* regnum
) {
100 /* Those positions must have the order in the
101 * named part of the strided data */
103 if ((usage
== WINED3DDECLUSAGE_POSITION
|| usage
== WINED3DDECLUSAGE_POSITIONT
) && usage_idx
== 0)
105 else if (usage
== WINED3DDECLUSAGE_BLENDWEIGHT
&& usage_idx
== 0)
107 else if (usage
== WINED3DDECLUSAGE_BLENDINDICES
&& usage_idx
== 0)
109 else if (usage
== WINED3DDECLUSAGE_NORMAL
&& usage_idx
== 0)
111 else if (usage
== WINED3DDECLUSAGE_PSIZE
&& usage_idx
== 0)
113 else if (usage
== WINED3DDECLUSAGE_COLOR
&& usage_idx
== 0)
115 else if (usage
== WINED3DDECLUSAGE_COLOR
&& usage_idx
== 1)
117 else if (usage
== WINED3DDECLUSAGE_TEXCOORD
&& usage_idx
< WINED3DDP_MAXTEXCOORD
)
118 *regnum
= 7 + usage_idx
;
119 else if ((usage
== WINED3DDECLUSAGE_POSITION
|| usage
== WINED3DDECLUSAGE_POSITIONT
) && usage_idx
== 1)
120 *regnum
= 7 + WINED3DDP_MAXTEXCOORD
;
121 else if (usage
== WINED3DDECLUSAGE_NORMAL
&& usage_idx
== 1)
122 *regnum
= 8 + WINED3DDP_MAXTEXCOORD
;
123 else if (usage
== WINED3DDECLUSAGE_TANGENT
&& usage_idx
== 0)
124 *regnum
= 9 + WINED3DDP_MAXTEXCOORD
;
125 else if (usage
== WINED3DDECLUSAGE_BINORMAL
&& usage_idx
== 0)
126 *regnum
= 10 + WINED3DDP_MAXTEXCOORD
;
127 else if (usage
== WINED3DDECLUSAGE_TESSFACTOR
&& usage_idx
== 0)
128 *regnum
= 11 + WINED3DDP_MAXTEXCOORD
;
129 else if (usage
== WINED3DDECLUSAGE_FOG
&& usage_idx
== 0)
130 *regnum
= 12 + WINED3DDP_MAXTEXCOORD
;
131 else if (usage
== WINED3DDECLUSAGE_DEPTH
&& usage_idx
== 0)
132 *regnum
= 13 + WINED3DDP_MAXTEXCOORD
;
133 else if (usage
== WINED3DDECLUSAGE_SAMPLE
&& usage_idx
== 0)
134 *regnum
= 14 + WINED3DDP_MAXTEXCOORD
;
137 FIXME("Unsupported input stream [usage=%s, usage_idx=%u]\n",
138 debug_d3ddeclusage(usage
), usage_idx
);
144 void primitiveDeclarationConvertToStridedData(
145 IWineD3DDevice
*iface
,
146 BOOL useVertexShaderFunction
,
147 WineDirect3DVertexStridedData
*strided
,
150 /* We need to deal with frequency data!*/
153 IWineD3DDeviceImpl
*This
= (IWineD3DDeviceImpl
*)iface
;
154 IWineD3DVertexDeclarationImpl
* vertexDeclaration
= (IWineD3DVertexDeclarationImpl
*)This
->stateBlock
->vertexDecl
;
156 WINED3DVERTEXELEMENT
*element
;
159 DWORD numPreloadStreams
= This
->stateBlock
->streamIsUP
? 0 : vertexDeclaration
->num_streams
;
160 DWORD
*streams
= vertexDeclaration
->streams
;
162 /* Check for transformed vertices, disable vertex shader if present */
163 strided
->u
.s
.position_transformed
= vertexDeclaration
->position_transformed
;
164 if(vertexDeclaration
->position_transformed
) {
165 useVertexShaderFunction
= FALSE
;
168 /* Translate the declaration into strided data */
169 for (i
= 0 ; i
< vertexDeclaration
->declarationWNumElements
- 1; ++i
) {
174 element
= vertexDeclaration
->pDeclarationWine
+ i
;
175 TRACE("%p Element %p (%d of %d)\n", vertexDeclaration
->pDeclarationWine
,
176 element
, i
+ 1, vertexDeclaration
->declarationWNumElements
- 1);
178 if (This
->stateBlock
->streamSource
[element
->Stream
] == NULL
)
181 if (This
->stateBlock
->streamIsUP
) {
182 TRACE("Stream is up %d, %p\n", element
->Stream
, This
->stateBlock
->streamSource
[element
->Stream
]);
184 data
= (BYTE
*)This
->stateBlock
->streamSource
[element
->Stream
];
186 TRACE("Stream isn't up %d, %p\n", element
->Stream
, This
->stateBlock
->streamSource
[element
->Stream
]);
187 data
= IWineD3DVertexBufferImpl_GetMemory(This
->stateBlock
->streamSource
[element
->Stream
], 0, &streamVBO
);
189 if( streamVBO
!= 0) *fixup
= TRUE
;
190 else if(*fixup
&& !useVertexShaderFunction
&&
191 (element
->Usage
== WINED3DDECLUSAGE_COLOR
||
192 element
->Usage
== WINED3DDECLUSAGE_POSITIONT
)) {
193 /* This may be bad with the fixed function pipeline */
194 FIXME("Missing vbo streams with unfixed colors or transformed position, expect problems\n");
198 stride
= This
->stateBlock
->streamStride
[element
->Stream
];
199 data
+= element
->Offset
;
202 TRACE("Offset %d Stream %d UsageIndex %d\n", element
->Offset
, element
->Stream
, element
->UsageIndex
);
204 if (useVertexShaderFunction
)
205 stride_used
= vshader_get_input(This
->stateBlock
->vertexShader
,
206 element
->Usage
, element
->UsageIndex
, &idx
);
208 stride_used
= fixed_get_input(element
->Usage
, element
->UsageIndex
, &idx
);
211 TRACE("Loaded %s array %u [usage=%s, usage_idx=%u, "
212 "stream=%u, offset=%u, stride=%u, type=%s, VBO=%u]\n",
213 useVertexShaderFunction
? "shader": "fixed function", idx
,
214 debug_d3ddeclusage(element
->Usage
), element
->UsageIndex
,
215 element
->Stream
, element
->Offset
, stride
, debug_d3ddecltype(element
->Type
), streamVBO
);
217 strided
->u
.input
[idx
].lpData
= data
;
218 strided
->u
.input
[idx
].dwType
= element
->Type
;
219 strided
->u
.input
[idx
].dwStride
= stride
;
220 strided
->u
.input
[idx
].VBO
= streamVBO
;
221 strided
->u
.input
[idx
].streamNo
= element
->Stream
;
224 /* Now call PreLoad on all the vertex buffers. In the very rare case
225 * that the buffers stopps converting PreLoad will dirtify the VDECL again.
226 * The vertex buffer can now use the strided structure in the device instead of finding its
229 * NULL streams won't be recorded in the array, UP streams won't be either. A stream is only
232 for(i
=0; i
< numPreloadStreams
; i
++) {
233 IWineD3DVertexBuffer_PreLoad(This
->stateBlock
->streamSource
[streams
[i
]]);
237 static void drawStridedFast(IWineD3DDevice
*iface
,UINT numberOfVertices
, GLenum glPrimitiveType
,
238 const void *idxData
, short idxSize
, ULONG minIndex
, ULONG startIdx
, ULONG startVertex
) {
239 IWineD3DDeviceImpl
*This
= (IWineD3DDeviceImpl
*)iface
;
241 if (idxSize
!= 0 /* This crashes sometimes!*/) {
242 TRACE("(%p) : glElements(%x, %d, %d, ...)\n", This
, glPrimitiveType
, numberOfVertices
, minIndex
);
243 idxData
= idxData
== (void *)-1 ? NULL
: idxData
;
245 glDrawElements(glPrimitiveType
, numberOfVertices
, idxSize
== 2 ? GL_UNSIGNED_SHORT
: GL_UNSIGNED_INT
,
246 (const char *)idxData
+(idxSize
* startIdx
));
247 checkGLcall("glDrawElements");
248 #else /* using drawRangeElements may be faster */
250 glDrawRangeElements(glPrimitiveType
, minIndex
, minIndex
+ numberOfVertices
- 1, numberOfVertices
,
251 idxSize
== 2 ? GL_UNSIGNED_SHORT
: GL_UNSIGNED_INT
,
252 (const char *)idxData
+(idxSize
* startIdx
));
253 checkGLcall("glDrawRangeElements");
258 /* Note first is now zero as we shuffled along earlier */
259 TRACE("(%p) : glDrawArrays(%x, 0, %d)\n", This
, glPrimitiveType
, numberOfVertices
);
260 glDrawArrays(glPrimitiveType
, startVertex
, numberOfVertices
);
261 checkGLcall("glDrawArrays");
269 * Actually draw using the supplied information.
270 * Slower GL version which extracts info about each vertex in turn
273 static void drawStridedSlow(IWineD3DDevice
*iface
, WineDirect3DVertexStridedData
*sd
,
274 UINT NumVertexes
, GLenum glPrimType
,
275 const void *idxData
, short idxSize
, ULONG minIndex
, ULONG startIdx
, ULONG startVertex
) {
277 unsigned int textureNo
= 0;
278 const WORD
*pIdxBufS
= NULL
;
279 const DWORD
*pIdxBufL
= NULL
;
281 float x
= 0.0f
, y
= 0.0f
, z
= 0.0f
; /* x,y,z coordinates */
282 float rhw
= 0.0f
; /* rhw */
283 DWORD diffuseColor
= 0xFFFFFFFF; /* Diffuse Color */
284 DWORD specularColor
= 0; /* Specular Color */
285 IWineD3DDeviceImpl
*This
= (IWineD3DDeviceImpl
*)iface
;
286 UINT
*streamOffset
= This
->stateBlock
->streamOffset
;
287 DWORD SkipnStrides
= startVertex
+ This
->stateBlock
->loadBaseVertexIndex
;
289 BYTE
*texCoords
[WINED3DDP_MAXTEXCOORD
];
290 BYTE
*diffuse
= NULL
, *specular
= NULL
, *normal
= NULL
, *position
= NULL
;
292 TRACE("Using slow vertex array code\n");
294 /* Variable Initialization */
296 /* Immediate mode drawing can't make use of indices in a vbo - get the data from the index buffer.
297 * If the index buffer has no vbo(not supported or other reason), or with user pointer drawing
298 * idxData will be != NULL
300 if(idxData
== NULL
) {
301 idxData
= ((IWineD3DIndexBufferImpl
*) This
->stateBlock
->pIndexData
)->resource
.allocatedMemory
;
304 if (idxSize
== 2) pIdxBufS
= (const WORD
*) idxData
;
305 else pIdxBufL
= (const DWORD
*) idxData
;
308 /* Adding the stream offset once is cheaper than doing it every iteration. Do not modify the strided data, it is a pointer
309 * to the strided Data in the device and might be needed intact on the next draw
311 for (textureNo
= 0; textureNo
< GL_LIMITS(texture_stages
); ++textureNo
) {
312 if(sd
->u
.s
.texCoords
[textureNo
].lpData
) {
313 texCoords
[textureNo
] = sd
->u
.s
.texCoords
[textureNo
].lpData
+ streamOffset
[sd
->u
.s
.texCoords
[textureNo
].streamNo
];
315 texCoords
[textureNo
] = NULL
;
318 if(sd
->u
.s
.diffuse
.lpData
) {
319 diffuse
= sd
->u
.s
.diffuse
.lpData
+ streamOffset
[sd
->u
.s
.diffuse
.streamNo
];
321 if(sd
->u
.s
.specular
.lpData
) {
322 specular
= sd
->u
.s
.specular
.lpData
+ streamOffset
[sd
->u
.s
.specular
.streamNo
];
324 if(sd
->u
.s
.normal
.lpData
) {
325 normal
= sd
->u
.s
.normal
.lpData
+ streamOffset
[sd
->u
.s
.normal
.streamNo
];
327 if(sd
->u
.s
.position
.lpData
) {
328 position
= sd
->u
.s
.position
.lpData
+ streamOffset
[sd
->u
.s
.position
.streamNo
];
331 /* Start drawing in GL */
332 VTRACE(("glBegin(%x)\n", glPrimType
));
335 /* Default settings for data that is not passed */
336 if (sd
->u
.s
.normal
.lpData
== NULL
) {
339 if(sd
->u
.s
.diffuse
.lpData
== NULL
) {
340 glColor4f(1.0f
, 1.0f
, 1.0f
, 1.0f
);
342 if(sd
->u
.s
.specular
.lpData
== NULL
) {
343 if (GL_SUPPORT(EXT_SECONDARY_COLOR
)) {
344 GL_EXTCALL(glSecondaryColor3fEXT
)(0, 0, 0);
348 /* We shouldn't start this function if any VBO is involved. Should I put a safety check here?
349 * Guess it's not necessary(we crash then anyway) and would only eat CPU time
352 /* For each primitive */
353 for (vx_index
= 0; vx_index
< NumVertexes
; ++vx_index
) {
355 /* Initialize diffuse color */
356 diffuseColor
= 0xFFFFFFFF;
358 /* Blending data and Point sizes are not supported by this function. They are not supported by the fixed
359 * function pipeline at all. A Fixme for them is printed after decoding the vertex declaration
362 /* For indexed data, we need to go a few more strides in */
363 if (idxData
!= NULL
) {
365 /* Indexed so work out the number of strides to skip */
367 VTRACE(("Idx for vertex %d = %d\n", vx_index
, pIdxBufS
[startIdx
+vx_index
]));
368 SkipnStrides
= pIdxBufS
[startIdx
+ vx_index
] + This
->stateBlock
->loadBaseVertexIndex
;
370 VTRACE(("Idx for vertex %d = %d\n", vx_index
, pIdxBufL
[startIdx
+vx_index
]));
371 SkipnStrides
= pIdxBufL
[startIdx
+ vx_index
] + This
->stateBlock
->loadBaseVertexIndex
;
375 /* Texture coords --------------------------- */
376 for (textureNo
= 0; textureNo
< GL_LIMITS(texture_stages
); ++textureNo
) {
378 if (!GL_SUPPORT(ARB_MULTITEXTURE
) && textureNo
> 0) {
379 FIXME("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
383 /* Query tex coords */
384 if (This
->stateBlock
->textures
[textureNo
] != NULL
) {
386 int coordIdx
= This
->stateBlock
->textureState
[textureNo
][WINED3DTSS_TEXCOORDINDEX
];
387 float *ptrToCoords
= NULL
;
388 float s
= 0.0, t
= 0.0, r
= 0.0, q
= 0.0;
391 VTRACE(("tex: %d - Skip tex coords, as being system generated\n", textureNo
));
393 } else if (coordIdx
< 0) {
394 FIXME("tex: %d - Coord index %d is less than zero, expect a crash.\n", textureNo
, coordIdx
);
398 ptrToCoords
= (float *)(texCoords
[coordIdx
] + (SkipnStrides
* sd
->u
.s
.texCoords
[coordIdx
].dwStride
));
399 if (texCoords
[coordIdx
] == NULL
) {
400 TRACE("tex: %d - Skipping tex coords, as no data supplied\n", textureNo
);
403 int texture_idx
= This
->texUnitMap
[textureNo
];
404 int coordsToUse
= sd
->u
.s
.texCoords
[coordIdx
].dwType
+ 1; /* 0 == WINED3DDECLTYPE_FLOAT1 etc */
406 if (texture_idx
== -1) continue;
408 /* The coords to supply depend completely on the fvf / vertex shader */
409 switch (coordsToUse
) {
410 case 4: q
= ptrToCoords
[3]; /* drop through */
411 case 3: r
= ptrToCoords
[2]; /* drop through */
412 case 2: t
= ptrToCoords
[1]; /* drop through */
413 case 1: s
= ptrToCoords
[0];
416 /* Projected is more 'fun' - Move the last coord to the 'q'
417 parameter (see comments under WINED3DTSS_TEXTURETRANSFORMFLAGS */
418 if ((This
->stateBlock
->textureState
[textureNo
][WINED3DTSS_TEXTURETRANSFORMFLAGS
] != WINED3DTTFF_DISABLE
) &&
419 (This
->stateBlock
->textureState
[textureNo
][WINED3DTSS_TEXTURETRANSFORMFLAGS
] & WINED3DTTFF_PROJECTED
)) {
421 if (This
->stateBlock
->textureState
[textureNo
][WINED3DTSS_TEXTURETRANSFORMFLAGS
] & WINED3DTTFF_PROJECTED
) {
422 switch (coordsToUse
) {
423 case 0: /* Drop Through */
425 FIXME("WINED3DTTFF_PROJECTED but only zero or one coordinate?\n");
437 case 4: /* Nop here */
440 FIXME("Unexpected WINED3DTSS_TEXTURETRANSFORMFLAGS value of %d\n",
441 This
->stateBlock
->textureState
[textureNo
][WINED3DTSS_TEXTURETRANSFORMFLAGS
] & WINED3DTTFF_PROJECTED
);
446 switch (coordsToUse
) { /* Supply the provided texture coords */
447 case WINED3DTTFF_COUNT1
:
448 VTRACE(("tex:%d, s=%f\n", textureNo
, s
));
449 if (GL_SUPPORT(ARB_MULTITEXTURE
)) {
450 GL_EXTCALL(glMultiTexCoord1fARB(GL_TEXTURE0_ARB
+ texture_idx
, s
));
455 case WINED3DTTFF_COUNT2
:
456 VTRACE(("tex:%d, s=%f, t=%f\n", textureNo
, s
, t
));
457 if (GL_SUPPORT(ARB_MULTITEXTURE
)) {
458 GL_EXTCALL(glMultiTexCoord2fARB(GL_TEXTURE0_ARB
+ texture_idx
, s
, t
));
463 case WINED3DTTFF_COUNT3
:
464 VTRACE(("tex:%d, s=%f, t=%f, r=%f\n", textureNo
, s
, t
, r
));
465 if (GL_SUPPORT(ARB_MULTITEXTURE
)) {
466 GL_EXTCALL(glMultiTexCoord3fARB(GL_TEXTURE0_ARB
+ texture_idx
, s
, t
, r
));
468 glTexCoord3f(s
, t
, r
);
471 case WINED3DTTFF_COUNT4
:
472 VTRACE(("tex:%d, s=%f, t=%f, r=%f, q=%f\n", textureNo
, s
, t
, r
, q
));
473 if (GL_SUPPORT(ARB_MULTITEXTURE
)) {
474 GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB
+ texture_idx
, s
, t
, r
, q
));
476 glTexCoord4f(s
, t
, r
, q
);
480 FIXME("Should not get here as coordsToUse is two bits only (%x)!\n", coordsToUse
);
484 } /* End of textures */
486 /* Diffuse -------------------------------- */
488 DWORD
*ptrToCoords
= (DWORD
*)(diffuse
+ (SkipnStrides
* sd
->u
.s
.diffuse
.dwStride
));
489 diffuseColor
= ptrToCoords
[0];
490 VTRACE(("diffuseColor=%lx\n", diffuseColor
));
492 glColor4ub(D3DCOLOR_B_R(diffuseColor
),
493 D3DCOLOR_B_G(diffuseColor
),
494 D3DCOLOR_B_B(diffuseColor
),
495 D3DCOLOR_B_A(diffuseColor
));
496 VTRACE(("glColor4ub: r,g,b,a=%lu,%lu,%lu,%lu\n",
497 D3DCOLOR_B_R(diffuseColor
),
498 D3DCOLOR_B_G(diffuseColor
),
499 D3DCOLOR_B_B(diffuseColor
),
500 D3DCOLOR_B_A(diffuseColor
)));
502 if(This
->activeContext
->num_untracked_materials
) {
505 color
[0] = D3DCOLOR_B_R(diffuseColor
) / 255.0;
506 color
[1] = D3DCOLOR_B_G(diffuseColor
) / 255.0;
507 color
[2] = D3DCOLOR_B_B(diffuseColor
) / 255.0;
508 color
[3] = D3DCOLOR_B_A(diffuseColor
) / 255.0;
510 for(i
= 0; i
< This
->activeContext
->num_untracked_materials
; i
++) {
511 glMaterialfv(GL_FRONT_AND_BACK
, This
->activeContext
->untracked_materials
[i
], color
);
516 /* Specular ------------------------------- */
518 DWORD
*ptrToCoords
= (DWORD
*)(specular
+ (SkipnStrides
* sd
->u
.s
.specular
.dwStride
));
519 specularColor
= ptrToCoords
[0];
520 VTRACE(("specularColor=%lx\n", specularColor
));
522 /* special case where the fog density is stored in the specular alpha channel */
523 if(This
->stateBlock
->renderState
[WINED3DRS_FOGENABLE
] &&
524 (This
->stateBlock
->renderState
[WINED3DRS_FOGVERTEXMODE
] == WINED3DFOG_NONE
|| sd
->u
.s
.position
.dwType
== WINED3DDECLTYPE_FLOAT4
)&&
525 This
->stateBlock
->renderState
[WINED3DRS_FOGTABLEMODE
] == WINED3DFOG_NONE
) {
526 if(GL_SUPPORT(EXT_FOG_COORD
)) {
527 GL_EXTCALL(glFogCoordfEXT(specularColor
>> 24));
529 static BOOL warned
= FALSE
;
531 /* TODO: Use the fog table code from old ddraw */
532 FIXME("Implement fog for transformed vertices in software\n");
538 VTRACE(("glSecondaryColor4ub: r,g,b=%lu,%lu,%lu\n",
539 D3DCOLOR_B_R(specularColor
),
540 D3DCOLOR_B_G(specularColor
),
541 D3DCOLOR_B_B(specularColor
)));
542 if (GL_SUPPORT(EXT_SECONDARY_COLOR
)) {
543 GL_EXTCALL(glSecondaryColor3ubEXT
)(
544 D3DCOLOR_B_R(specularColor
),
545 D3DCOLOR_B_G(specularColor
),
546 D3DCOLOR_B_B(specularColor
));
548 /* Do not worry if specular colour missing and disable request */
549 VTRACE(("Specular color extensions not supplied\n"));
553 /* Normal -------------------------------- */
554 if (normal
!= NULL
) {
555 float *ptrToCoords
= (float *)(normal
+ (SkipnStrides
* sd
->u
.s
.normal
.dwStride
));
557 VTRACE(("glNormal:nx,ny,nz=%f,%f,%f\n", ptrToCoords
[0], ptrToCoords
[1], ptrToCoords
[2]));
558 glNormal3f(ptrToCoords
[0], ptrToCoords
[1], ptrToCoords
[2]);
561 /* Position -------------------------------- */
563 float *ptrToCoords
= (float *)(position
+ (SkipnStrides
* sd
->u
.s
.position
.dwStride
));
568 VTRACE(("x,y,z=%f,%f,%f\n", x
,y
,z
));
570 /* RHW follows, only if transformed, ie 4 floats were provided */
571 if (sd
->u
.s
.position_transformed
) {
572 rhw
= ptrToCoords
[3];
573 VTRACE(("rhw=%f\n", rhw
));
576 if (1.0f
== rhw
|| ((rhw
< eps
) && (rhw
> -eps
))) {
577 VTRACE(("Vertex: glVertex:x,y,z=%f,%f,%f\n", x
,y
,z
));
580 GLfloat w
= 1.0 / rhw
;
581 VTRACE(("Vertex: glVertex:x,y,z=%f,%f,%f / rhw=%f\n", x
,y
,z
,rhw
));
582 glVertex4f(x
*w
, y
*w
, z
*w
, w
);
586 /* For non indexed mode, step onto next parts */
587 if (idxData
== NULL
) {
593 checkGLcall("glEnd and previous calls");
596 static void depth_blt(IWineD3DDevice
*iface
, GLuint texture
) {
597 IWineD3DDeviceImpl
*This
= (IWineD3DDeviceImpl
*)iface
;
598 GLint old_binding
= 0;
600 glPushAttrib(GL_ENABLE_BIT
| GL_DEPTH_BUFFER_BIT
| GL_COLOR_BUFFER_BIT
);
602 glDisable(GL_CULL_FACE
);
604 glDisable(GL_ALPHA_TEST
);
605 glDisable(GL_SCISSOR_TEST
);
606 glDisable(GL_STENCIL_TEST
);
607 glEnable(GL_DEPTH_TEST
);
608 glDepthFunc(GL_ALWAYS
);
609 glBlendFunc(GL_ZERO
, GL_ONE
);
611 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB
));
612 glGetIntegerv(GL_TEXTURE_BINDING_2D
, &old_binding
);
613 glBindTexture(GL_TEXTURE_2D
, texture
);
614 glEnable(GL_TEXTURE_2D
);
616 This
->shader_backend
->shader_select_depth_blt(iface
);
618 glBegin(GL_TRIANGLE_STRIP
);
619 glVertex2f(-1.0f
, -1.0f
);
620 glVertex2f(1.0f
, -1.0f
);
621 glVertex2f(-1.0f
, 1.0f
);
622 glVertex2f(1.0f
, 1.0f
);
625 glBindTexture(GL_TEXTURE_2D
, old_binding
);
629 /* Reselect the old shaders. There doesn't seem to be any glPushAttrib bit for arb shaders,
630 * and this seems easier and more efficient than providing the shader backend with a private
631 * storage to read and restore the old shader settings
633 This
->shader_backend
->shader_select(iface
, use_ps(This
), use_vs(This
));
636 static void depth_copy(IWineD3DDevice
*iface
) {
637 IWineD3DDeviceImpl
*This
= (IWineD3DDeviceImpl
*)iface
;
638 IWineD3DSurfaceImpl
*depth_stencil
= (IWineD3DSurfaceImpl
*)This
->depthStencilBuffer
;
640 /* Only copy the depth buffer if there is one. */
641 if (!depth_stencil
) return;
643 /* TODO: Make this work for modes other than FBO */
644 if (wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
) return;
646 if (depth_stencil
->current_renderbuffer
) {
647 FIXME("Not supported with fixed up depth stencil\n");
651 if (This
->render_offscreen
) {
652 static GLuint tmp_texture
= 0;
653 GLint old_binding
= 0;
655 TRACE("Copying onscreen depth buffer to offscreen surface\n");
658 glGenTextures(1, &tmp_texture
);
661 /* Note that we use depth_blt here as well, rather than glCopyTexImage2D
662 * directly on the FBO texture. That's because we need to flip. */
663 GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0));
664 glGetIntegerv(GL_TEXTURE_BINDING_2D
, &old_binding
);
665 glBindTexture(GL_TEXTURE_2D
, tmp_texture
);
666 glCopyTexImage2D(depth_stencil
->glDescription
.target
,
667 depth_stencil
->glDescription
.level
,
668 depth_stencil
->glDescription
.glFormatInternal
,
671 depth_stencil
->currentDesc
.Width
,
672 depth_stencil
->currentDesc
.Height
,
674 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
675 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
676 glTexParameteri(GL_TEXTURE_2D
, GL_DEPTH_TEXTURE_MODE_ARB
, GL_LUMINANCE
);
677 glBindTexture(GL_TEXTURE_2D
, old_binding
);
679 GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, This
->fbo
));
680 checkGLcall("glBindFramebuffer()");
681 depth_blt(iface
, tmp_texture
);
682 checkGLcall("depth_blt");
684 TRACE("Copying offscreen surface to onscreen depth buffer\n");
686 GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0));
687 checkGLcall("glBindFramebuffer()");
688 depth_blt(iface
, depth_stencil
->glDescription
.textureName
);
689 checkGLcall("depth_blt");
693 static inline void drawStridedInstanced(IWineD3DDevice
*iface
, WineDirect3DVertexStridedData
*sd
, UINT numberOfVertices
,
694 GLenum glPrimitiveType
, const void *idxData
, short idxSize
, ULONG minIndex
,
695 ULONG startIdx
, ULONG startVertex
) {
696 UINT numInstances
= 0;
697 int numInstancedAttribs
= 0, i
, j
;
698 UINT instancedData
[sizeof(sd
->u
.input
) / sizeof(sd
->u
.input
[0]) /* 16 */];
699 IWineD3DDeviceImpl
*This
= (IWineD3DDeviceImpl
*) iface
;
700 IWineD3DStateBlockImpl
*stateblock
= This
->stateBlock
;
703 /* This is a nasty thing. MSDN says no hardware supports that and apps have to use software vertex processing.
704 * We don't support this for now
706 * Shouldn't be too hard to support with opengl, in theory just call glDrawArrays instead of drawElements.
707 * But the StreamSourceFreq value has a different meaning in that situation.
709 FIXME("Non-indexed instanced drawing is not supported\n");
713 TRACE("(%p) : glElements(%x, %d, %d, ...)\n", This
, glPrimitiveType
, numberOfVertices
, minIndex
);
714 idxData
= idxData
== (void *)-1 ? NULL
: idxData
;
716 /* First, figure out how many instances we have to draw */
717 for(i
= 0; i
< MAX_STREAMS
; i
++) {
718 /* Look at all non-instanced streams */
719 if(!(stateblock
->streamFlags
[i
] & WINED3DSTREAMSOURCE_INSTANCEDATA
) &&
720 stateblock
->streamSource
[i
]) {
721 int inst
= stateblock
->streamFreq
[i
];
723 if(numInstances
&& inst
!= numInstances
) {
724 ERR("Two streams specify a different number of instances. Got %d, new is %d\n", numInstances
, inst
);
730 for(i
= 0; i
< sizeof(sd
->u
.input
) / sizeof(sd
->u
.input
[0]); i
++) {
731 if(stateblock
->streamFlags
[sd
->u
.input
[i
].streamNo
] & WINED3DSTREAMSOURCE_INSTANCEDATA
) {
732 instancedData
[numInstancedAttribs
] = i
;
733 numInstancedAttribs
++;
737 /* now draw numInstances instances :-) */
738 for(i
= 0; i
< numInstances
; i
++) {
739 /* Specify the instanced attributes using immediate mode calls */
740 for(j
= 0; j
< numInstancedAttribs
; j
++) {
741 BYTE
*ptr
= sd
->u
.input
[instancedData
[j
]].lpData
+
742 sd
->u
.input
[instancedData
[j
]].dwStride
* i
+
743 stateblock
->streamOffset
[sd
->u
.input
[instancedData
[j
]].streamNo
];
744 if(sd
->u
.input
[instancedData
[j
]].VBO
) {
745 IWineD3DVertexBufferImpl
*vb
= (IWineD3DVertexBufferImpl
*) stateblock
->streamSource
[sd
->u
.input
[instancedData
[j
]].streamNo
];
746 ptr
+= (long) vb
->resource
.allocatedMemory
;
749 switch(sd
->u
.input
[instancedData
[j
]].dwType
) {
750 case WINED3DDECLTYPE_FLOAT1
:
751 GL_EXTCALL(glVertexAttrib1fvARB(instancedData
[j
], (float *) ptr
));
753 case WINED3DDECLTYPE_FLOAT2
:
754 GL_EXTCALL(glVertexAttrib2fvARB(instancedData
[j
], (float *) ptr
));
756 case WINED3DDECLTYPE_FLOAT3
:
757 GL_EXTCALL(glVertexAttrib3fvARB(instancedData
[j
], (float *) ptr
));
759 case WINED3DDECLTYPE_FLOAT4
:
760 GL_EXTCALL(glVertexAttrib4fvARB(instancedData
[j
], (float *) ptr
));
763 case WINED3DDECLTYPE_UBYTE4
:
764 GL_EXTCALL(glVertexAttrib4ubvARB(instancedData
[j
], ptr
));
766 case WINED3DDECLTYPE_UBYTE4N
:
767 case WINED3DDECLTYPE_D3DCOLOR
:
768 GL_EXTCALL(glVertexAttrib4NubvARB(instancedData
[j
], ptr
));
771 case WINED3DDECLTYPE_SHORT2
:
772 GL_EXTCALL(glVertexAttrib4svARB(instancedData
[j
], (GLshort
*) ptr
));
774 case WINED3DDECLTYPE_SHORT4
:
775 GL_EXTCALL(glVertexAttrib4svARB(instancedData
[j
], (GLshort
*) ptr
));
778 case WINED3DDECLTYPE_SHORT2N
:
780 GLshort s
[4] = {((short *) ptr
)[0], ((short *) ptr
)[1], 0, 1};
781 GL_EXTCALL(glVertexAttrib4NsvARB(instancedData
[j
], s
));
784 case WINED3DDECLTYPE_USHORT2N
:
786 GLushort s
[4] = {((unsigned short *) ptr
)[0], ((unsigned short *) ptr
)[1], 0, 1};
787 GL_EXTCALL(glVertexAttrib4NusvARB(instancedData
[j
], s
));
790 case WINED3DDECLTYPE_SHORT4N
:
791 GL_EXTCALL(glVertexAttrib4NsvARB(instancedData
[j
], (GLshort
*) ptr
));
793 case WINED3DDECLTYPE_USHORT4N
:
794 GL_EXTCALL(glVertexAttrib4NusvARB(instancedData
[j
], (GLushort
*) ptr
));
797 case WINED3DDECLTYPE_UDEC3
:
798 FIXME("Unsure about WINED3DDECLTYPE_UDEC3\n");
799 /*glVertexAttrib3usvARB(instancedData[j], (GLushort *) ptr); Does not exist */
801 case WINED3DDECLTYPE_DEC3N
:
802 FIXME("Unsure about WINED3DDECLTYPE_DEC3N\n");
803 /*glVertexAttrib3NusvARB(instancedData[j], (GLushort *) ptr); Does not exist */
806 case WINED3DDECLTYPE_FLOAT16_2
:
807 /* Are those 16 bit floats. C doesn't have a 16 bit float type. I could read the single bits and calculate a 4
808 * byte float according to the IEEE standard
810 if (GL_SUPPORT(NV_HALF_FLOAT
)) {
811 GL_EXTCALL(glVertexAttrib2hvNV(instancedData
[j
], (GLhalfNV
*)ptr
));
813 FIXME("Unsupported WINED3DDECLTYPE_FLOAT16_2\n");
816 case WINED3DDECLTYPE_FLOAT16_4
:
817 if (GL_SUPPORT(NV_HALF_FLOAT
)) {
818 GL_EXTCALL(glVertexAttrib4hvNV(instancedData
[j
], (GLhalfNV
*)ptr
));
820 FIXME("Unsupported WINED3DDECLTYPE_FLOAT16_4\n");
824 case WINED3DDECLTYPE_UNUSED
:
826 ERR("Unexpected declaration in instanced attributes\n");
831 glDrawElements(glPrimitiveType
, numberOfVertices
, idxSize
== 2 ? GL_UNSIGNED_SHORT
: GL_UNSIGNED_INT
,
832 (const char *)idxData
+(idxSize
* startIdx
));
833 checkGLcall("glDrawElements");
841 void blt_to_drawable(IWineD3DDeviceImpl
*This
, IWineD3DSurfaceImpl
*surface
) {
842 struct coords coords
[4];
845 /* TODO: This could be supported for lazy unlocking */
846 if(!(surface
->Flags
& SFLAG_INTEXTURE
)) {
847 /* It is ok at init to be nowhere */
848 if(!(surface
->Flags
& SFLAG_INSYSMEM
)) {
849 ERR("Blitting surfaces from sysmem not supported yet\n");
854 ActivateContext(This
, This
->render_targets
[0], CTXUSAGE_BLIT
);
857 if(surface
->glDescription
.target
== GL_TEXTURE_2D
) {
858 glBindTexture(GL_TEXTURE_2D
, surface
->glDescription
.textureName
);
859 checkGLcall("GL_TEXTURE_2D, This->glDescription.textureName)");
861 coords
[0].x
= 0; coords
[0].y
= 0; coords
[0].z
= 0;
862 coords
[1].x
= 0; coords
[1].y
= 1; coords
[1].z
= 0;
863 coords
[2].x
= 1; coords
[2].y
= 1; coords
[2].z
= 0;
864 coords
[3].x
= 1; coords
[3].y
= 0; coords
[3].z
= 0;
868 /* Must be a cube map */
869 glDisable(GL_TEXTURE_2D
);
870 checkGLcall("glDisable(GL_TEXTURE_2D)");
871 glEnable(GL_TEXTURE_CUBE_MAP_ARB
);
872 checkGLcall("glEnable(surface->glDescription.target)");
873 glBindTexture(GL_TEXTURE_CUBE_MAP_ARB
, surface
->glDescription
.textureName
);
874 checkGLcall("GL_TEXTURE_CUBE_MAP_ARB, This->glDescription.textureName)");
876 switch(surface
->glDescription
.target
) {
877 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
878 coords
[0].x
= 1; coords
[0].y
= -1; coords
[0].z
= 1;
879 coords
[1].x
= 1; coords
[1].y
= 1; coords
[1].z
= 1;
880 coords
[2].x
= 1; coords
[2].y
= 1; coords
[2].z
= -1;
881 coords
[3].x
= 1; coords
[3].y
= -1; coords
[3].z
= -1;
884 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
885 coords
[0].x
= -1; coords
[0].y
= -1; coords
[0].z
= 1;
886 coords
[1].x
= -1; coords
[1].y
= 1; coords
[1].z
= 1;
887 coords
[2].x
= -1; coords
[2].y
= 1; coords
[2].z
= -1;
888 coords
[3].x
= -1; coords
[3].y
= -1; coords
[3].z
= -1;
891 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
892 coords
[0].x
= -1; coords
[0].y
= 1; coords
[0].z
= 1;
893 coords
[1].x
= 1; coords
[1].y
= 1; coords
[1].z
= 1;
894 coords
[2].x
= 1; coords
[2].y
= 1; coords
[2].z
= -1;
895 coords
[3].x
= -1; coords
[3].y
= 1; coords
[3].z
= -1;
898 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
899 coords
[0].x
= -1; coords
[0].y
= -1; coords
[0].z
= 1;
900 coords
[1].x
= 1; coords
[1].y
= -1; coords
[1].z
= 1;
901 coords
[2].x
= 1; coords
[2].y
= -1; coords
[2].z
= -1;
902 coords
[3].x
= -1; coords
[3].y
= -1; coords
[3].z
= -1;
905 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
906 coords
[0].x
= -1; coords
[0].y
= -1; coords
[0].z
= 1;
907 coords
[1].x
= 1; coords
[1].y
= -1; coords
[1].z
= 1;
908 coords
[2].x
= 1; coords
[2].y
= -1; coords
[2].z
= 1;
909 coords
[3].x
= -1; coords
[3].y
= -1; coords
[3].z
= 1;
912 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
913 coords
[0].x
= -1; coords
[0].y
= -1; coords
[0].z
= -1;
914 coords
[1].x
= 1; coords
[1].y
= -1; coords
[1].z
= -1;
915 coords
[2].x
= 1; coords
[2].y
= -1; coords
[2].z
= -1;
916 coords
[3].x
= -1; coords
[3].y
= -1; coords
[3].z
= -1;
919 ERR("Unexpected texture target\n");
927 if(This
->render_offscreen
) {
928 coords
[0].y
= coords
[0].y
== 1 ? low_coord
: 1;
929 coords
[1].y
= coords
[1].y
== 1 ? low_coord
: 1;
930 coords
[2].y
= coords
[2].y
== 1 ? low_coord
: 1;
931 coords
[3].y
= coords
[3].y
== 1 ? low_coord
: 1;
935 glTexCoord3iv((GLint
*) &coords
[0]);
938 glTexCoord3iv((GLint
*) &coords
[1]);
939 glVertex2i(0, surface
->pow2Height
);
941 glTexCoord3iv((GLint
*) &coords
[2]);
942 glVertex2i(surface
->pow2Width
, surface
->pow2Height
);
944 glTexCoord3iv((GLint
*) &coords
[3]);
945 glVertex2i(surface
->pow2Width
, 0);
947 checkGLcall("glEnd");
949 if(surface
->glDescription
.target
!= GL_TEXTURE_2D
) {
950 glEnable(GL_TEXTURE_2D
);
951 checkGLcall("glEnable(GL_TEXTURE_2D)");
952 glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
953 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
958 /* Routine common to the draw primitive and draw indexed primitive routines */
959 void drawPrimitive(IWineD3DDevice
*iface
,
963 long StartVertexIndex
,
964 UINT numberOfVertices
,
970 IWineD3DDeviceImpl
*This
= (IWineD3DDeviceImpl
*)iface
;
971 IWineD3DSwapChain
*swapchain
;
972 IWineD3DBaseTexture
*texture
= NULL
;
973 IWineD3DSurfaceImpl
*target
;
976 /* Signals other modules that a drawing is in progress and the stateblock finalized */
977 This
->isInDraw
= TRUE
;
979 /* Invalidate the back buffer memory so LockRect will read it the next time */
980 for(i
= 0; i
< GL_LIMITS(buffers
); i
++) {
981 target
= (IWineD3DSurfaceImpl
*) This
->render_targets
[i
];
983 /* TODO: Only do all that if we're going to change anything
984 * Texture container dirtification does not work quite right yet
986 if(target
/*&& target->Flags & (SFLAG_INTEXTURE | SFLAG_INSYSMEM)*/) {
991 IWineD3DSurface_GetContainer((IWineD3DSurface
*) target
, &IID_IWineD3DSwapChain
, (void **)&swapchain
);
993 /* Need the surface in the drawable! */
994 if(!(target
->Flags
& SFLAG_INDRAWABLE
) && (swapchain
|| wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
)) {
995 blt_to_drawable(This
, target
);
999 /* Onscreen target. Invalidate system memory copy and texture copy */
1000 target
->Flags
&= ~(SFLAG_INSYSMEM
| SFLAG_INTEXTURE
);
1001 target
->Flags
|= SFLAG_INDRAWABLE
;
1002 IWineD3DSwapChain_Release(swapchain
);
1003 } else if(wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
) {
1004 /* Non-FBO target: Invalidate system copy, texture copy and dirtify the container */
1005 IWineD3DSurface_GetContainer((IWineD3DSurface
*) target
, &IID_IWineD3DBaseTexture
, (void **)&texture
);
1008 IWineD3DBaseTexture_SetDirty(texture
, TRUE
);
1009 IWineD3DTexture_Release(texture
);
1012 target
->Flags
&= ~(SFLAG_INSYSMEM
| SFLAG_INTEXTURE
);
1013 target
->Flags
|= SFLAG_INDRAWABLE
;
1015 /* FBO offscreen target. Invalidate system memory copy */
1016 target
->Flags
&= ~SFLAG_INSYSMEM
;
1019 /* Must be an fbo render target */
1020 target
->Flags
&= ~SFLAG_INSYSMEM
;
1021 target
->Flags
|= SFLAG_INTEXTURE
;
1026 /* Ok, we will be updating the screen from here onwards so grab the lock */
1028 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
) {
1030 apply_fbo_state(iface
);
1034 ActivateContext(This
, This
->render_targets
[0], CTXUSAGE_DRAWPRIM
);
1037 if (This
->depth_copy_state
== WINED3D_DCS_COPY
) {
1040 This
->depth_copy_state
= WINED3D_DCS_INITIAL
;
1044 BOOL emulation
= FALSE
;
1045 WineDirect3DVertexStridedData
*strided
= &This
->strided_streams
;
1046 WineDirect3DVertexStridedData stridedlcl
;
1047 /* Ok, Work out which primitive is requested and how many vertexes that
1049 UINT calculatedNumberOfindices
= primitiveToGl(PrimitiveType
, NumPrimitives
, &glPrimType
);
1050 if (numberOfVertices
== 0 )
1051 numberOfVertices
= calculatedNumberOfindices
;
1054 if(!This
->strided_streams
.u
.s
.position_transformed
&& This
->activeContext
->num_untracked_materials
&&
1055 This
->stateBlock
->renderState
[WINED3DRS_LIGHTING
]) {
1056 FIXME("Using software emulation because not all material properties could be tracked\n");
1059 else if(This
->activeContext
->fog_coord
&& This
->stateBlock
->renderState
[WINED3DRS_FOGENABLE
]) {
1060 /* Either write a pipeline replacement shader or convert the specular alpha from unsigned byte
1061 * to a float in the vertex buffer
1063 FIXME("Using software emulation because manual fog coordinates are provided\n");
1068 IWineD3DVertexBufferImpl
*vb
;
1070 strided
= &stridedlcl
;
1071 memcpy(&stridedlcl
, &This
->strided_streams
, sizeof(stridedlcl
));
1073 #define FIXVBO(type) \
1074 if(stridedlcl.u.s.type.VBO) { \
1075 vb = (IWineD3DVertexBufferImpl *) This->stateBlock->streamSource[stridedlcl.u.s.type.streamNo]; \
1076 stridedlcl.u.s.type.VBO = 0; \
1077 stridedlcl.u.s.type.lpData = (BYTE *) ((unsigned long) stridedlcl.u.s.type.lpData + (unsigned long) vb->resource.allocatedMemory); \
1080 FIXVBO(blendWeights
);
1081 FIXVBO(blendMatrixIndices
);
1086 for(i
= 0; i
< WINED3DDP_MAXTEXCOORD
; i
++) FIXVBO(texCoords
[i
]);
1099 if (This
->useDrawStridedSlow
|| emulation
) {
1100 /* Immediate mode drawing */
1101 drawStridedSlow(iface
, strided
, calculatedNumberOfindices
,
1102 glPrimType
, idxData
, idxSize
, minIndex
, StartIdx
, StartVertexIndex
);
1103 } else if(This
->instancedDraw
) {
1104 /* Instancing emulation with mixing immediate mode and arrays */
1105 drawStridedInstanced(iface
, &This
->strided_streams
, calculatedNumberOfindices
, glPrimType
,
1106 idxData
, idxSize
, minIndex
, StartIdx
, StartVertexIndex
);
1108 /* Simple array draw call */
1109 drawStridedFast(iface
, calculatedNumberOfindices
, glPrimType
,
1110 idxData
, idxSize
, minIndex
, StartIdx
, StartVertexIndex
);
1114 /* Finshed updating the screen, restore lock */
1116 TRACE("Done all gl drawing\n");
1119 #ifdef SHOW_FRAME_MAKEUP
1121 static long int primCounter
= 0;
1122 /* NOTE: set primCounter to the value reported by drawprim
1123 before you want to to write frame makeup to /tmp */
1124 if (primCounter
>= 0) {
1125 WINED3DLOCKED_RECT r
;
1127 IWineD3DSurface_LockRect(This
->renderTarget
, &r
, NULL
, WINED3DLOCK_READONLY
);
1128 sprintf(buffer
, "/tmp/backbuffer_%d.tga", primCounter
);
1129 TRACE("Saving screenshot %s\n", buffer
);
1130 IWineD3DSurface_SaveSnapshot(This
->renderTarget
, buffer
);
1131 IWineD3DSurface_UnlockRect(This
->renderTarget
);
1133 #ifdef SHOW_TEXTURE_MAKEUP
1135 IWineD3DSurface
*pSur
;
1137 for (textureNo
= 0; textureNo
< MAX_COMBINED_SAMPLERS
; ++textureNo
) {
1138 if (This
->stateBlock
->textures
[textureNo
] != NULL
) {
1139 sprintf(buffer
, "/tmp/texture_%p_%d_%d.tga", This
->stateBlock
->textures
[textureNo
], primCounter
, textureNo
);
1140 TRACE("Saving texture %s\n", buffer
);
1141 if (IWineD3DBaseTexture_GetType(This
->stateBlock
->textures
[textureNo
]) == WINED3DRTYPE_TEXTURE
) {
1142 IWineD3DTexture_GetSurfaceLevel((IWineD3DTexture
*)This
->stateBlock
->textures
[textureNo
], 0, &pSur
);
1143 IWineD3DSurface_SaveSnapshot(pSur
, buffer
);
1144 IWineD3DSurface_Release(pSur
);
1146 FIXME("base Texture isn't of type texture %d\n", IWineD3DBaseTexture_GetType(This
->stateBlock
->textures
[textureNo
]));
1153 TRACE("drawprim #%d\n", primCounter
);
1158 /* Control goes back to the device, stateblock values may change again */
1159 This
->isInDraw
= FALSE
;
1162 static void normalize_normal(float *n
) {
1163 float length
= n
[0] * n
[0] + n
[1] * n
[1] + n
[2] * n
[2];
1164 if(length
== 0.0) return;
1165 length
= sqrt(length
);
1166 n
[0] = n
[0] / length
;
1167 n
[1] = n
[1] / length
;
1168 n
[2] = n
[2] / length
;
1171 /* Tesselates a high order rectangular patch into single triangles using gl evaluators
1173 * The problem is that OpenGL does not offer a direct way to return the tesselated primitives,
1174 * and they can't be sent off for rendering directly either. Tesselating is slow, so we want
1175 * to chache the patches in a vertex buffer. But more importantly, gl can't bind generated
1176 * attributes to numbered shader attributes, so we have to store them and rebind them as needed
1179 * To read back, the opengl feedback mode is used. This creates a proplem because we want
1180 * untransformed, unlit vertices, but feedback runs everything through transform and lighting.
1181 * Thus disable lighting and set identity matrices to get unmodified colors and positions.
1182 * To overcome clipping find the biggest x, y and z values of the vertices in the patch and scale
1183 * them to [-1.0;+1.0] and set the viewport up to scale them back.
1185 * Normals are more tricky: Draw white vertices with 3 directional lights, and calculate the
1186 * resulting colors back to the normals.
1188 * NOTE: This function activates a context for blitting, modifies matrices & viewport, but
1189 * does not restore it because normally a draw follows immediately afterwards. The caller is
1190 * responsible of taking care that either the gl states are restored, or the context activated
1191 * for drawing to reset the lastWasBlit flag.
1193 HRESULT
tesselate_rectpatch(IWineD3DDeviceImpl
*This
,
1194 struct WineD3DRectPatch
*patch
) {
1195 unsigned int i
, j
, num_quads
, out_vertex_size
, buffer_size
, d3d_out_vertex_size
;
1196 float max_x
= 0.0, max_y
= 0.0, max_z
= 0.0, neg_z
= 0.0;
1197 WineDirect3DVertexStridedData strided
;
1199 WINED3DRECTPATCH_INFO
*info
= &patch
->RectPatchInfo
;
1201 GLenum feedback_type
;
1202 GLfloat
*feedbuffer
;
1204 /* First, locate the position data. This is provided in a vertex buffer in the stateblock.
1207 memset(&strided
, 0, sizeof(strided
));
1208 primitiveDeclarationConvertToStridedData((IWineD3DDevice
*) This
, FALSE
, &strided
, NULL
);
1209 if(strided
.u
.s
.position
.VBO
) {
1210 IWineD3DVertexBufferImpl
*vb
;
1211 vb
= (IWineD3DVertexBufferImpl
*) This
->stateBlock
->streamSource
[strided
.u
.s
.position
.streamNo
];
1212 strided
.u
.s
.position
.lpData
= (BYTE
*) ((unsigned long) strided
.u
.s
.position
.lpData
+
1213 (unsigned long) vb
->resource
.allocatedMemory
);
1215 vtxStride
= strided
.u
.s
.position
.dwStride
;
1216 data
= strided
.u
.s
.position
.lpData
+
1217 vtxStride
* info
->Stride
* info
->StartVertexOffsetHeight
+
1218 vtxStride
* info
->StartVertexOffsetWidth
;
1220 /* Not entirely sure about what happens with transformed vertices */
1221 if(strided
.u
.s
.position_transformed
) {
1222 FIXME("Transformed position in rectpatch generation\n");
1224 if(vtxStride
% sizeof(GLfloat
)) {
1225 /* glMap2f reads vertex sizes in GLfloats, the d3d stride is in bytes.
1226 * I don't see how the stride could not be a multiple of 4, but make sure
1229 ERR("Vertex stride is not a multiple of sizeof(GLfloat)\n");
1231 if(info
->Basis
!= WINED3DBASIS_BEZIER
) {
1232 FIXME("Basis is %s, how to handle this?\n", debug_d3dbasis(info
->Basis
));
1234 if(info
->Degree
!= WINED3DDEGREE_CUBIC
) {
1235 FIXME("Degree is %s, how to handle this?\n", debug_d3ddegree(info
->Degree
));
1238 /* First, get the boundary cube of the input data */
1239 for(j
= 0; j
< info
->Height
; j
++) {
1240 for(i
= 0; i
< info
->Width
; i
++) {
1241 float *v
= (float *) (data
+ vtxStride
* i
+ vtxStride
* info
->Stride
* j
);
1242 if(fabs(v
[0]) > max_x
) max_x
= fabs(v
[0]);
1243 if(fabs(v
[1]) > max_y
) max_y
= fabs(v
[1]);
1244 if(fabs(v
[2]) > max_z
) max_z
= fabs(v
[2]);
1245 if(v
[2] < neg_z
) neg_z
= v
[2];
1249 /* This needs some improvements in the vertex decl code */
1250 FIXME("Cannot find data to generate. Only generating position and normals\n");
1251 patch
->has_normals
= TRUE
;
1252 patch
->has_texcoords
= FALSE
;
1254 /* Simply activate the context for blitting. This disables all the things we don't want and
1255 * takes care of dirtifying. Dirtifying is preferred over pushing / popping, since drawing the
1256 * patch (as opposed to normal draws) will most likely need different changes anyway
1258 ActivateContext(This
, This
->lastActiveRenderTarget
, CTXUSAGE_BLIT
);
1261 glMatrixMode(GL_PROJECTION
);
1262 checkGLcall("glMatrixMode(GL_PROJECTION)");
1264 checkGLcall("glLoadIndentity()");
1265 glScalef(1 / (max_x
) , 1 / (max_y
), max_z
== 0 ? 1 : 1 / ( 2 * max_z
));
1266 glTranslatef(0, 0, 0.5);
1267 checkGLcall("glScalef");
1268 glViewport(-max_x
, -max_y
, 2 * (max_x
), 2 * (max_y
));
1269 checkGLcall("glViewport");
1271 /* Some states to take care of. If we're in wireframe opengl will produce lines, and confuse
1272 * our feedback buffer parser
1274 glPolygonMode(GL_FRONT_AND_BACK
, GL_FILL
);
1275 checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)");
1276 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_RENDER(WINED3DRS_FILLMODE
));
1277 if(patch
->has_normals
) {
1278 float black
[4] = {0, 0, 0, 0};
1279 float red
[4] = {1, 0, 0, 0};
1280 float green
[4] = {0, 1, 0, 0};
1281 float blue
[4] = {0, 0, 1, 0};
1282 float white
[4] = {1, 1, 1, 1};
1283 glEnable(GL_LIGHTING
);
1284 checkGLcall("glEnable(GL_LIGHTING)");
1285 glLightModelfv(GL_LIGHT_MODEL_AMBIENT
, black
);
1286 checkGLcall("glLightModel for MODEL_AMBIENT");
1287 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_RENDER(WINED3DRS_AMBIENT
));
1289 for(i
= 3; i
< GL_LIMITS(lights
); i
++) {
1290 glDisable(GL_LIGHT0
+ i
);
1291 checkGLcall("glDisable(GL_LIGHT0 + i)");
1292 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_ACTIVELIGHT(i
));
1295 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_ACTIVELIGHT(0));
1296 glLightfv(GL_LIGHT0
, GL_DIFFUSE
, red
);
1297 glLightfv(GL_LIGHT0
, GL_SPECULAR
, black
);
1298 glLightfv(GL_LIGHT0
, GL_AMBIENT
, black
);
1299 glLightfv(GL_LIGHT0
, GL_POSITION
, red
);
1300 glEnable(GL_LIGHT0
);
1301 checkGLcall("Setting up light 1\n");
1302 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_ACTIVELIGHT(1));
1303 glLightfv(GL_LIGHT1
, GL_DIFFUSE
, green
);
1304 glLightfv(GL_LIGHT1
, GL_SPECULAR
, black
);
1305 glLightfv(GL_LIGHT1
, GL_AMBIENT
, black
);
1306 glLightfv(GL_LIGHT1
, GL_POSITION
, green
);
1307 glEnable(GL_LIGHT1
);
1308 checkGLcall("Setting up light 2\n");
1309 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_ACTIVELIGHT(2));
1310 glLightfv(GL_LIGHT2
, GL_DIFFUSE
, blue
);
1311 glLightfv(GL_LIGHT2
, GL_SPECULAR
, black
);
1312 glLightfv(GL_LIGHT2
, GL_AMBIENT
, black
);
1313 glLightfv(GL_LIGHT2
, GL_POSITION
, blue
);
1314 glEnable(GL_LIGHT2
);
1315 checkGLcall("Setting up light 3\n");
1317 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_MATERIAL
);
1318 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_RENDER(WINED3DRS_COLORVERTEX
));
1319 glDisable(GL_COLOR_MATERIAL
);
1320 glMaterialfv(GL_FRONT_AND_BACK
, GL_EMISSION
, black
);
1321 glMaterialfv(GL_FRONT_AND_BACK
, GL_SPECULAR
, black
);
1322 glMaterialfv(GL_FRONT_AND_BACK
, GL_DIFFUSE
, white
);
1323 checkGLcall("Setting up materials\n");
1326 /* Enable the needed maps.
1327 * GL_MAP2_VERTEX_3 is needed for positional data.
1328 * GL_AUTO_NORMAL to generate normals from the position. Do not use GL_MAP2_NORMAL.
1329 * GL_MAP2_TEXTURE_COORD_4 for texture coords
1331 num_quads
= ceilf(patch
->numSegs
[0]) * ceilf(patch
->numSegs
[1]);
1332 out_vertex_size
= 3 /* position */;
1333 d3d_out_vertex_size
= 3;
1334 glEnable(GL_MAP2_VERTEX_3
);
1335 if(patch
->has_normals
&& patch
->has_texcoords
) {
1336 FIXME("Texcoords not handled yet\n");
1337 feedback_type
= GL_3D_COLOR_TEXTURE
;
1338 out_vertex_size
+= 8;
1339 d3d_out_vertex_size
+= 7;
1340 glEnable(GL_AUTO_NORMAL
);
1341 glEnable(GL_MAP2_TEXTURE_COORD_4
);
1342 } else if(patch
->has_texcoords
) {
1343 FIXME("Texcoords not handled yet\n");
1344 feedback_type
= GL_3D_COLOR_TEXTURE
;
1345 out_vertex_size
+= 7;
1346 d3d_out_vertex_size
+= 4;
1347 glEnable(GL_MAP2_TEXTURE_COORD_4
);
1348 } else if(patch
->has_normals
) {
1349 feedback_type
= GL_3D_COLOR
;
1350 out_vertex_size
+= 4;
1351 d3d_out_vertex_size
+= 3;
1352 glEnable(GL_AUTO_NORMAL
);
1354 feedback_type
= GL_3D
;
1356 checkGLcall("glEnable vertex attrib generation");
1358 buffer_size
= num_quads
* out_vertex_size
* 2 /* triangle list */ * 3 /* verts per tri */
1359 + 4 * num_quads
/* 2 triangle markers per quad + num verts in tri */;
1360 feedbuffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, buffer_size
* sizeof(float) * 8);
1362 glMap2f(GL_MAP2_VERTEX_3
,
1363 0, 1, vtxStride
/ sizeof(float), info
->Width
,
1364 0, 1, info
->Stride
* vtxStride
/ sizeof(float), info
->Height
,
1366 checkGLcall("glMap2f");
1367 if(patch
->has_texcoords
) {
1368 glMap2f(GL_MAP2_TEXTURE_COORD_4
,
1369 0, 1, vtxStride
/ sizeof(float), info
->Width
,
1370 0, 1, info
->Stride
* vtxStride
/ sizeof(float), info
->Height
,
1372 checkGLcall("glMap2f");
1374 glMapGrid2f(ceilf(patch
->numSegs
[0]), 0.0, 1.0, ceilf(patch
->numSegs
[1]), 0.0, 1.0);
1375 checkGLcall("glMapGrid2f");
1377 glFeedbackBuffer(buffer_size
* 2, feedback_type
, feedbuffer
);
1378 checkGLcall("glFeedbackBuffer");
1379 glRenderMode(GL_FEEDBACK
);
1381 glEvalMesh2(GL_FILL
, 0, ceilf(patch
->numSegs
[0]), 0, ceilf(patch
->numSegs
[1]));
1382 checkGLcall("glEvalMesh2\n");
1384 i
= glRenderMode(GL_RENDER
);
1386 ERR("Feedback failed. Expected %d elements back\n", buffer_size
);
1388 HeapFree(GetProcessHeap(), 0, feedbuffer
);
1389 return WINED3DERR_DRIVERINTERNALERROR
;
1390 } else if(i
!= buffer_size
) {
1391 ERR("Unexpected amount of elements returned. Expected %d, got %d\n", buffer_size
, i
);
1393 HeapFree(GetProcessHeap(), 0, feedbuffer
);
1394 return WINED3DERR_DRIVERINTERNALERROR
;
1396 TRACE("Got %d elements as expected\n", i
);
1399 HeapFree(GetProcessHeap(), 0, patch
->mem
);
1400 patch
->mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, num_quads
* 6 * d3d_out_vertex_size
* sizeof(float) * 8);
1402 for(j
= 0; j
< buffer_size
; j
+= (3 /* num verts */ * out_vertex_size
+ 2 /* tri marker */)) {
1403 if(feedbuffer
[j
] != GL_POLYGON_TOKEN
) {
1404 ERR("Unexpected token: %f\n", feedbuffer
[j
]);
1407 if(feedbuffer
[j
+ 1] != 3) {
1408 ERR("Unexpected polygon: %f corners\n", feedbuffer
[j
+ 1]);
1411 /* Somehow there are different ideas about back / front facing, so fix up the
1414 patch
->mem
[i
+ 0] = feedbuffer
[j
+ out_vertex_size
* 2 + 2]; /* x, triangle 2 */
1415 patch
->mem
[i
+ 1] = feedbuffer
[j
+ out_vertex_size
* 2 + 3]; /* y, triangle 2 */
1416 patch
->mem
[i
+ 2] = (feedbuffer
[j
+ out_vertex_size
* 2 + 4] - 0.5) * 4 * max_z
; /* z, triangle 3 */
1417 if(patch
->has_normals
) {
1418 patch
->mem
[i
+ 3] = feedbuffer
[j
+ out_vertex_size
* 2 + 5];
1419 patch
->mem
[i
+ 4] = feedbuffer
[j
+ out_vertex_size
* 2 + 6];
1420 patch
->mem
[i
+ 5] = feedbuffer
[j
+ out_vertex_size
* 2 + 7];
1422 i
+= d3d_out_vertex_size
;
1424 patch
->mem
[i
+ 0] = feedbuffer
[j
+ out_vertex_size
* 1 + 2]; /* x, triangle 2 */
1425 patch
->mem
[i
+ 1] = feedbuffer
[j
+ out_vertex_size
* 1 + 3]; /* y, triangle 2 */
1426 patch
->mem
[i
+ 2] = (feedbuffer
[j
+ out_vertex_size
* 1 + 4] - 0.5) * 4 * max_z
; /* z, triangle 2 */
1427 if(patch
->has_normals
) {
1428 patch
->mem
[i
+ 3] = feedbuffer
[j
+ out_vertex_size
* 1 + 5];
1429 patch
->mem
[i
+ 4] = feedbuffer
[j
+ out_vertex_size
* 1 + 6];
1430 patch
->mem
[i
+ 5] = feedbuffer
[j
+ out_vertex_size
* 1 + 7];
1432 i
+= d3d_out_vertex_size
;
1434 patch
->mem
[i
+ 0] = feedbuffer
[j
+ out_vertex_size
* 0 + 2]; /* x, triangle 1 */
1435 patch
->mem
[i
+ 1] = feedbuffer
[j
+ out_vertex_size
* 0 + 3]; /* y, triangle 1 */
1436 patch
->mem
[i
+ 2] = (feedbuffer
[j
+ out_vertex_size
* 0 + 4] - 0.5) * 4 * max_z
; /* z, triangle 1 */
1437 if(patch
->has_normals
) {
1438 patch
->mem
[i
+ 3] = feedbuffer
[j
+ out_vertex_size
* 0 + 5];
1439 patch
->mem
[i
+ 4] = feedbuffer
[j
+ out_vertex_size
* 0 + 6];
1440 patch
->mem
[i
+ 5] = feedbuffer
[j
+ out_vertex_size
* 0 + 7];
1442 i
+= d3d_out_vertex_size
;
1445 if(patch
->has_normals
) {
1446 /* Now do the same with reverse light directions */
1447 float x
[4] = {-1, 0, 0, 0};
1448 float y
[4] = { 0, -1, 0, 0};
1449 float z
[4] = { 0, 0, -1, 0};
1450 glLightfv(GL_LIGHT0
, GL_POSITION
, x
);
1451 glLightfv(GL_LIGHT1
, GL_POSITION
, y
);
1452 glLightfv(GL_LIGHT2
, GL_POSITION
, z
);
1453 checkGLcall("Setting up reverse light directions\n");
1455 glRenderMode(GL_FEEDBACK
);
1456 checkGLcall("glRenderMode(GL_FEEDBACK)");
1457 glEvalMesh2(GL_FILL
, 0, ceilf(patch
->numSegs
[0]), 0, ceilf(patch
->numSegs
[1]));
1458 checkGLcall("glEvalMesh2\n");
1459 i
= glRenderMode(GL_RENDER
);
1460 checkGLcall("glRenderMode(GL_RENDER)");
1463 for(j
= 0; j
< buffer_size
; j
+= (3 /* num verts */ * out_vertex_size
+ 2 /* tri marker */)) {
1464 if(feedbuffer
[j
] != GL_POLYGON_TOKEN
) {
1465 ERR("Unexpected token: %f\n", feedbuffer
[j
]);
1468 if(feedbuffer
[j
+ 1] != 3) {
1469 ERR("Unexpected polygon: %f corners\n", feedbuffer
[j
+ 1]);
1472 if(patch
->mem
[i
+ 3] == 0.0)
1473 patch
->mem
[i
+ 3] = -feedbuffer
[j
+ out_vertex_size
* 2 + 5];
1474 if(patch
->mem
[i
+ 4] == 0.0)
1475 patch
->mem
[i
+ 4] = -feedbuffer
[j
+ out_vertex_size
* 2 + 6];
1476 if(patch
->mem
[i
+ 5] == 0.0)
1477 patch
->mem
[i
+ 5] = -feedbuffer
[j
+ out_vertex_size
* 2 + 7];
1478 normalize_normal(patch
->mem
+ i
+ 3);
1479 i
+= d3d_out_vertex_size
;
1481 if(patch
->mem
[i
+ 3] == 0.0)
1482 patch
->mem
[i
+ 3] = -feedbuffer
[j
+ out_vertex_size
* 1 + 5];
1483 if(patch
->mem
[i
+ 4] == 0.0)
1484 patch
->mem
[i
+ 4] = -feedbuffer
[j
+ out_vertex_size
* 1 + 6];
1485 if(patch
->mem
[i
+ 5] == 0.0)
1486 patch
->mem
[i
+ 5] = -feedbuffer
[j
+ out_vertex_size
* 1 + 7];
1487 normalize_normal(patch
->mem
+ i
+ 3);
1488 i
+= d3d_out_vertex_size
;
1490 if(patch
->mem
[i
+ 3] == 0.0)
1491 patch
->mem
[i
+ 3] = -feedbuffer
[j
+ out_vertex_size
* 0 + 5];
1492 if(patch
->mem
[i
+ 4] == 0.0)
1493 patch
->mem
[i
+ 4] = -feedbuffer
[j
+ out_vertex_size
* 0 + 6];
1494 if(patch
->mem
[i
+ 5] == 0.0)
1495 patch
->mem
[i
+ 5] = -feedbuffer
[j
+ out_vertex_size
* 0 + 7];
1496 normalize_normal(patch
->mem
+ i
+ 3);
1497 i
+= d3d_out_vertex_size
;
1501 glDisable(GL_MAP2_VERTEX_3
);
1502 glDisable(GL_AUTO_NORMAL
);
1503 glDisable(GL_MAP2_NORMAL
);
1504 glDisable(GL_MAP2_TEXTURE_COORD_4
);
1505 checkGLcall("glDisable vertex attrib generation");
1508 HeapFree(GetProcessHeap(), 0, feedbuffer
);
1510 vtxStride
= 3 * sizeof(float);
1511 if(patch
->has_normals
) {
1512 vtxStride
+= 3 * sizeof(float);
1514 if(patch
->has_texcoords
) {
1515 vtxStride
+= 4 * sizeof(float);
1517 memset(&patch
->strided
, 0, sizeof(&patch
->strided
));
1518 patch
->strided
.u
.s
.position
.lpData
= (BYTE
*) patch
->mem
;
1519 patch
->strided
.u
.s
.position
.dwStride
= vtxStride
;
1520 patch
->strided
.u
.s
.position
.dwType
= WINED3DDECLTYPE_FLOAT3
;
1521 patch
->strided
.u
.s
.position
.streamNo
= 255;
1523 if(patch
->has_normals
) {
1524 patch
->strided
.u
.s
.normal
.lpData
= (BYTE
*) patch
->mem
+ 3 * sizeof(float) /* pos */;
1525 patch
->strided
.u
.s
.normal
.dwStride
= vtxStride
;
1526 patch
->strided
.u
.s
.normal
.dwType
= WINED3DDECLTYPE_FLOAT3
;
1527 patch
->strided
.u
.s
.normal
.streamNo
= 255;
1529 if(patch
->has_texcoords
) {
1530 patch
->strided
.u
.s
.texCoords
[0].lpData
= (BYTE
*) patch
->mem
+ 3 * sizeof(float) /* pos */;
1531 if(patch
->has_normals
) {
1532 patch
->strided
.u
.s
.texCoords
[0].lpData
+= 3 * sizeof(float);
1534 patch
->strided
.u
.s
.texCoords
[0].dwStride
= vtxStride
;
1535 patch
->strided
.u
.s
.texCoords
[0].dwType
= WINED3DDECLTYPE_FLOAT4
;
1536 /* MAX_STREAMS index points to an unused element in stateblock->streamOffsets which
1537 * always remains set to 0. Windows uses stream 255 here, but this is not visible to the
1540 patch
->strided
.u
.s
.texCoords
[0].streamNo
= MAX_STREAMS
;