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 stride
= This
->stateBlock
->streamStride
[element
->Stream
];
182 if (This
->stateBlock
->streamIsUP
) {
183 TRACE("Stream is up %d, %p\n", element
->Stream
, This
->stateBlock
->streamSource
[element
->Stream
]);
185 data
= (BYTE
*)This
->stateBlock
->streamSource
[element
->Stream
];
187 TRACE("Stream isn't up %d, %p\n", element
->Stream
, This
->stateBlock
->streamSource
[element
->Stream
]);
188 data
= IWineD3DVertexBufferImpl_GetMemory(This
->stateBlock
->streamSource
[element
->Stream
], 0, &streamVBO
);
190 /* Can't use vbo's if the base vertex index is negative. OpenGL doesn't accept negative offsets
191 * (or rather offsets bigger than the vbo, because the pointer is unsigned), so use system memory
192 * sources. In most sane cases the pointer - offset will still be > 0, otherwise it will wrap
193 * around to some big value. Hope that with the indices, the driver wraps it back internally. If
194 * not, drawStridedSlow is needed, including a vertex buffer path.
196 if(This
->stateBlock
->loadBaseVertexIndex
< 0) {
197 WARN("loadBaseVertexIndex is < 0 (%d), not using vbos\n", This
->stateBlock
->loadBaseVertexIndex
);
199 data
= ((IWineD3DVertexBufferImpl
*) This
->stateBlock
->streamSource
[element
->Stream
])->resource
.allocatedMemory
;
200 if(data
+ This
->stateBlock
->loadBaseVertexIndex
* stride
< 0) {
201 FIXME("System memory vertex data load offset is negative!\n");
206 if( streamVBO
!= 0) *fixup
= TRUE
;
207 else if(*fixup
&& !useVertexShaderFunction
&&
208 (element
->Usage
== WINED3DDECLUSAGE_COLOR
||
209 element
->Usage
== WINED3DDECLUSAGE_POSITIONT
)) {
210 /* This may be bad with the fixed function pipeline */
211 FIXME("Missing vbo streams with unfixed colors or transformed position, expect problems\n");
215 data
+= element
->Offset
;
218 TRACE("Offset %d Stream %d UsageIndex %d\n", element
->Offset
, element
->Stream
, element
->UsageIndex
);
220 if (useVertexShaderFunction
)
221 stride_used
= vshader_get_input(This
->stateBlock
->vertexShader
,
222 element
->Usage
, element
->UsageIndex
, &idx
);
224 stride_used
= fixed_get_input(element
->Usage
, element
->UsageIndex
, &idx
);
227 TRACE("Loaded %s array %u [usage=%s, usage_idx=%u, "
228 "stream=%u, offset=%u, stride=%u, type=%s, VBO=%u]\n",
229 useVertexShaderFunction
? "shader": "fixed function", idx
,
230 debug_d3ddeclusage(element
->Usage
), element
->UsageIndex
,
231 element
->Stream
, element
->Offset
, stride
, debug_d3ddecltype(element
->Type
), streamVBO
);
233 strided
->u
.input
[idx
].lpData
= data
;
234 strided
->u
.input
[idx
].dwType
= element
->Type
;
235 strided
->u
.input
[idx
].dwStride
= stride
;
236 strided
->u
.input
[idx
].VBO
= streamVBO
;
237 strided
->u
.input
[idx
].streamNo
= element
->Stream
;
240 /* Now call PreLoad on all the vertex buffers. In the very rare case
241 * that the buffers stopps converting PreLoad will dirtify the VDECL again.
242 * The vertex buffer can now use the strided structure in the device instead of finding its
245 * NULL streams won't be recorded in the array, UP streams won't be either. A stream is only
248 for(i
=0; i
< numPreloadStreams
; i
++) {
249 IWineD3DVertexBuffer_PreLoad(This
->stateBlock
->streamSource
[streams
[i
]]);
253 static void drawStridedFast(IWineD3DDevice
*iface
,UINT numberOfVertices
, GLenum glPrimitiveType
,
254 const void *idxData
, short idxSize
, ULONG minIndex
, ULONG startIdx
, ULONG startVertex
) {
255 IWineD3DDeviceImpl
*This
= (IWineD3DDeviceImpl
*)iface
;
257 if (idxSize
!= 0 /* This crashes sometimes!*/) {
258 TRACE("(%p) : glElements(%x, %d, %d, ...)\n", This
, glPrimitiveType
, numberOfVertices
, minIndex
);
259 idxData
= idxData
== (void *)-1 ? NULL
: idxData
;
261 glDrawElements(glPrimitiveType
, numberOfVertices
, idxSize
== 2 ? GL_UNSIGNED_SHORT
: GL_UNSIGNED_INT
,
262 (const char *)idxData
+(idxSize
* startIdx
));
263 checkGLcall("glDrawElements");
264 #else /* using drawRangeElements may be faster */
266 glDrawRangeElements(glPrimitiveType
, minIndex
, minIndex
+ numberOfVertices
- 1, numberOfVertices
,
267 idxSize
== 2 ? GL_UNSIGNED_SHORT
: GL_UNSIGNED_INT
,
268 (const char *)idxData
+(idxSize
* startIdx
));
269 checkGLcall("glDrawRangeElements");
274 /* Note first is now zero as we shuffled along earlier */
275 TRACE("(%p) : glDrawArrays(%x, 0, %d)\n", This
, glPrimitiveType
, numberOfVertices
);
276 glDrawArrays(glPrimitiveType
, startVertex
, numberOfVertices
);
277 checkGLcall("glDrawArrays");
285 * Actually draw using the supplied information.
286 * Slower GL version which extracts info about each vertex in turn
289 static void drawStridedSlow(IWineD3DDevice
*iface
, WineDirect3DVertexStridedData
*sd
,
290 UINT NumVertexes
, GLenum glPrimType
,
291 const void *idxData
, short idxSize
, ULONG minIndex
, ULONG startIdx
, ULONG startVertex
) {
293 unsigned int textureNo
= 0;
294 const WORD
*pIdxBufS
= NULL
;
295 const DWORD
*pIdxBufL
= NULL
;
297 float x
= 0.0f
, y
= 0.0f
, z
= 0.0f
; /* x,y,z coordinates */
298 float rhw
= 0.0f
; /* rhw */
299 DWORD diffuseColor
= 0xFFFFFFFF; /* Diffuse Color */
300 DWORD specularColor
= 0; /* Specular Color */
301 IWineD3DDeviceImpl
*This
= (IWineD3DDeviceImpl
*)iface
;
302 UINT
*streamOffset
= This
->stateBlock
->streamOffset
;
303 long SkipnStrides
= startVertex
+ This
->stateBlock
->loadBaseVertexIndex
;
305 BYTE
*texCoords
[WINED3DDP_MAXTEXCOORD
];
306 BYTE
*diffuse
= NULL
, *specular
= NULL
, *normal
= NULL
, *position
= NULL
;
308 TRACE("Using slow vertex array code\n");
310 /* Variable Initialization */
312 /* Immediate mode drawing can't make use of indices in a vbo - get the data from the index buffer.
313 * If the index buffer has no vbo(not supported or other reason), or with user pointer drawing
314 * idxData will be != NULL
316 if(idxData
== NULL
) {
317 idxData
= ((IWineD3DIndexBufferImpl
*) This
->stateBlock
->pIndexData
)->resource
.allocatedMemory
;
320 if (idxSize
== 2) pIdxBufS
= (const WORD
*) idxData
;
321 else pIdxBufL
= (const DWORD
*) idxData
;
324 /* Adding the stream offset once is cheaper than doing it every iteration. Do not modify the strided data, it is a pointer
325 * to the strided Data in the device and might be needed intact on the next draw
327 for (textureNo
= 0; textureNo
< GL_LIMITS(texture_stages
); ++textureNo
) {
328 if(sd
->u
.s
.texCoords
[textureNo
].lpData
) {
329 texCoords
[textureNo
] = sd
->u
.s
.texCoords
[textureNo
].lpData
+ streamOffset
[sd
->u
.s
.texCoords
[textureNo
].streamNo
];
331 texCoords
[textureNo
] = NULL
;
334 if(sd
->u
.s
.diffuse
.lpData
) {
335 diffuse
= sd
->u
.s
.diffuse
.lpData
+ streamOffset
[sd
->u
.s
.diffuse
.streamNo
];
337 if(sd
->u
.s
.specular
.lpData
) {
338 specular
= sd
->u
.s
.specular
.lpData
+ streamOffset
[sd
->u
.s
.specular
.streamNo
];
340 if(sd
->u
.s
.normal
.lpData
) {
341 normal
= sd
->u
.s
.normal
.lpData
+ streamOffset
[sd
->u
.s
.normal
.streamNo
];
343 if(sd
->u
.s
.position
.lpData
) {
344 position
= sd
->u
.s
.position
.lpData
+ streamOffset
[sd
->u
.s
.position
.streamNo
];
347 /* Start drawing in GL */
348 VTRACE(("glBegin(%x)\n", glPrimType
));
351 /* Default settings for data that is not passed */
352 if (sd
->u
.s
.normal
.lpData
== NULL
) {
355 if(sd
->u
.s
.diffuse
.lpData
== NULL
) {
356 glColor4f(1.0f
, 1.0f
, 1.0f
, 1.0f
);
358 if(sd
->u
.s
.specular
.lpData
== NULL
) {
359 if (GL_SUPPORT(EXT_SECONDARY_COLOR
)) {
360 GL_EXTCALL(glSecondaryColor3fEXT
)(0, 0, 0);
364 /* We shouldn't start this function if any VBO is involved. Should I put a safety check here?
365 * Guess it's not necessary(we crash then anyway) and would only eat CPU time
368 /* For each primitive */
369 for (vx_index
= 0; vx_index
< NumVertexes
; ++vx_index
) {
371 /* Initialize diffuse color */
372 diffuseColor
= 0xFFFFFFFF;
374 /* Blending data and Point sizes are not supported by this function. They are not supported by the fixed
375 * function pipeline at all. A Fixme for them is printed after decoding the vertex declaration
378 /* For indexed data, we need to go a few more strides in */
379 if (idxData
!= NULL
) {
381 /* Indexed so work out the number of strides to skip */
383 VTRACE(("Idx for vertex %d = %d\n", vx_index
, pIdxBufS
[startIdx
+vx_index
]));
384 SkipnStrides
= pIdxBufS
[startIdx
+ vx_index
] + This
->stateBlock
->loadBaseVertexIndex
;
386 VTRACE(("Idx for vertex %d = %d\n", vx_index
, pIdxBufL
[startIdx
+vx_index
]));
387 SkipnStrides
= pIdxBufL
[startIdx
+ vx_index
] + This
->stateBlock
->loadBaseVertexIndex
;
391 /* Texture coords --------------------------- */
392 for (textureNo
= 0; textureNo
< GL_LIMITS(texture_stages
); ++textureNo
) {
394 if (!GL_SUPPORT(ARB_MULTITEXTURE
) && textureNo
> 0) {
395 FIXME("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
399 /* Query tex coords */
400 if (This
->stateBlock
->textures
[textureNo
] != NULL
) {
402 int coordIdx
= This
->stateBlock
->textureState
[textureNo
][WINED3DTSS_TEXCOORDINDEX
];
403 float *ptrToCoords
= NULL
;
404 float s
= 0.0, t
= 0.0, r
= 0.0, q
= 0.0;
407 VTRACE(("tex: %d - Skip tex coords, as being system generated\n", textureNo
));
409 } else if (coordIdx
< 0) {
410 FIXME("tex: %d - Coord index %d is less than zero, expect a crash.\n", textureNo
, coordIdx
);
414 ptrToCoords
= (float *)(texCoords
[coordIdx
] + (SkipnStrides
* sd
->u
.s
.texCoords
[coordIdx
].dwStride
));
415 if (texCoords
[coordIdx
] == NULL
) {
416 TRACE("tex: %d - Skipping tex coords, as no data supplied\n", textureNo
);
417 glTexCoord4f(0, 0, 0, 1);
420 int texture_idx
= This
->texUnitMap
[textureNo
];
421 int coordsToUse
= sd
->u
.s
.texCoords
[coordIdx
].dwType
+ 1; /* 0 == WINED3DDECLTYPE_FLOAT1 etc */
423 if (texture_idx
== -1) continue;
425 /* The coords to supply depend completely on the fvf / vertex shader */
426 switch (coordsToUse
) {
427 case 4: q
= ptrToCoords
[3]; /* drop through */
428 case 3: r
= ptrToCoords
[2]; /* drop through */
429 case 2: t
= ptrToCoords
[1]; /* drop through */
430 case 1: s
= ptrToCoords
[0];
433 /* Projected is more 'fun' - Move the last coord to the 'q'
434 parameter (see comments under WINED3DTSS_TEXTURETRANSFORMFLAGS */
435 if ((This
->stateBlock
->textureState
[textureNo
][WINED3DTSS_TEXTURETRANSFORMFLAGS
] != WINED3DTTFF_DISABLE
) &&
436 (This
->stateBlock
->textureState
[textureNo
][WINED3DTSS_TEXTURETRANSFORMFLAGS
] & WINED3DTTFF_PROJECTED
)) {
438 if (This
->stateBlock
->textureState
[textureNo
][WINED3DTSS_TEXTURETRANSFORMFLAGS
] & WINED3DTTFF_PROJECTED
) {
439 switch (coordsToUse
) {
440 case 0: /* Drop Through */
442 FIXME("WINED3DTTFF_PROJECTED but only zero or one coordinate?\n");
454 case 4: /* Nop here */
457 FIXME("Unexpected WINED3DTSS_TEXTURETRANSFORMFLAGS value of %d\n",
458 This
->stateBlock
->textureState
[textureNo
][WINED3DTSS_TEXTURETRANSFORMFLAGS
] & WINED3DTTFF_PROJECTED
);
463 switch (coordsToUse
) { /* Supply the provided texture coords */
464 case WINED3DTTFF_COUNT1
:
465 VTRACE(("tex:%d, s=%f\n", textureNo
, s
));
466 if (GL_SUPPORT(ARB_MULTITEXTURE
)) {
467 GL_EXTCALL(glMultiTexCoord1fARB(GL_TEXTURE0_ARB
+ texture_idx
, s
));
472 case WINED3DTTFF_COUNT2
:
473 VTRACE(("tex:%d, s=%f, t=%f\n", textureNo
, s
, t
));
474 if (GL_SUPPORT(ARB_MULTITEXTURE
)) {
475 GL_EXTCALL(glMultiTexCoord2fARB(GL_TEXTURE0_ARB
+ texture_idx
, s
, t
));
480 case WINED3DTTFF_COUNT3
:
481 VTRACE(("tex:%d, s=%f, t=%f, r=%f\n", textureNo
, s
, t
, r
));
482 if (GL_SUPPORT(ARB_MULTITEXTURE
)) {
483 GL_EXTCALL(glMultiTexCoord3fARB(GL_TEXTURE0_ARB
+ texture_idx
, s
, t
, r
));
485 glTexCoord3f(s
, t
, r
);
488 case WINED3DTTFF_COUNT4
:
489 VTRACE(("tex:%d, s=%f, t=%f, r=%f, q=%f\n", textureNo
, s
, t
, r
, q
));
490 if (GL_SUPPORT(ARB_MULTITEXTURE
)) {
491 GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB
+ texture_idx
, s
, t
, r
, q
));
493 glTexCoord4f(s
, t
, r
, q
);
497 FIXME("Should not get here as coordsToUse is two bits only (%x)!\n", coordsToUse
);
501 } /* End of textures */
503 /* Diffuse -------------------------------- */
505 DWORD
*ptrToCoords
= (DWORD
*)(diffuse
+ (SkipnStrides
* sd
->u
.s
.diffuse
.dwStride
));
506 diffuseColor
= ptrToCoords
[0];
507 VTRACE(("diffuseColor=%lx\n", diffuseColor
));
509 glColor4ub(D3DCOLOR_B_R(diffuseColor
),
510 D3DCOLOR_B_G(diffuseColor
),
511 D3DCOLOR_B_B(diffuseColor
),
512 D3DCOLOR_B_A(diffuseColor
));
513 VTRACE(("glColor4ub: r,g,b,a=%lu,%lu,%lu,%lu\n",
514 D3DCOLOR_B_R(diffuseColor
),
515 D3DCOLOR_B_G(diffuseColor
),
516 D3DCOLOR_B_B(diffuseColor
),
517 D3DCOLOR_B_A(diffuseColor
)));
519 if(This
->activeContext
->num_untracked_materials
) {
522 color
[0] = D3DCOLOR_B_R(diffuseColor
) / 255.0;
523 color
[1] = D3DCOLOR_B_G(diffuseColor
) / 255.0;
524 color
[2] = D3DCOLOR_B_B(diffuseColor
) / 255.0;
525 color
[3] = D3DCOLOR_B_A(diffuseColor
) / 255.0;
527 for(i
= 0; i
< This
->activeContext
->num_untracked_materials
; i
++) {
528 glMaterialfv(GL_FRONT_AND_BACK
, This
->activeContext
->untracked_materials
[i
], color
);
533 /* Specular ------------------------------- */
535 DWORD
*ptrToCoords
= (DWORD
*)(specular
+ (SkipnStrides
* sd
->u
.s
.specular
.dwStride
));
536 specularColor
= ptrToCoords
[0];
537 VTRACE(("specularColor=%lx\n", specularColor
));
539 /* special case where the fog density is stored in the specular alpha channel */
540 if(This
->stateBlock
->renderState
[WINED3DRS_FOGENABLE
] &&
541 (This
->stateBlock
->renderState
[WINED3DRS_FOGVERTEXMODE
] == WINED3DFOG_NONE
|| sd
->u
.s
.position
.dwType
== WINED3DDECLTYPE_FLOAT4
)&&
542 This
->stateBlock
->renderState
[WINED3DRS_FOGTABLEMODE
] == WINED3DFOG_NONE
) {
543 if(GL_SUPPORT(EXT_FOG_COORD
)) {
544 GL_EXTCALL(glFogCoordfEXT(specularColor
>> 24));
546 static BOOL warned
= FALSE
;
548 /* TODO: Use the fog table code from old ddraw */
549 FIXME("Implement fog for transformed vertices in software\n");
555 VTRACE(("glSecondaryColor4ub: r,g,b=%lu,%lu,%lu\n",
556 D3DCOLOR_B_R(specularColor
),
557 D3DCOLOR_B_G(specularColor
),
558 D3DCOLOR_B_B(specularColor
)));
559 if (GL_SUPPORT(EXT_SECONDARY_COLOR
)) {
560 GL_EXTCALL(glSecondaryColor3ubEXT
)(
561 D3DCOLOR_B_R(specularColor
),
562 D3DCOLOR_B_G(specularColor
),
563 D3DCOLOR_B_B(specularColor
));
565 /* Do not worry if specular colour missing and disable request */
566 VTRACE(("Specular color extensions not supplied\n"));
570 /* Normal -------------------------------- */
571 if (normal
!= NULL
) {
572 float *ptrToCoords
= (float *)(normal
+ (SkipnStrides
* sd
->u
.s
.normal
.dwStride
));
574 VTRACE(("glNormal:nx,ny,nz=%f,%f,%f\n", ptrToCoords
[0], ptrToCoords
[1], ptrToCoords
[2]));
575 glNormal3f(ptrToCoords
[0], ptrToCoords
[1], ptrToCoords
[2]);
578 /* Position -------------------------------- */
580 float *ptrToCoords
= (float *)(position
+ (SkipnStrides
* sd
->u
.s
.position
.dwStride
));
585 VTRACE(("x,y,z=%f,%f,%f\n", x
,y
,z
));
587 /* RHW follows, only if transformed, ie 4 floats were provided */
588 if (sd
->u
.s
.position_transformed
) {
589 rhw
= ptrToCoords
[3];
590 VTRACE(("rhw=%f\n", rhw
));
593 if (1.0f
== rhw
|| ((rhw
< eps
) && (rhw
> -eps
))) {
594 VTRACE(("Vertex: glVertex:x,y,z=%f,%f,%f\n", x
,y
,z
));
597 GLfloat w
= 1.0 / rhw
;
598 VTRACE(("Vertex: glVertex:x,y,z=%f,%f,%f / rhw=%f\n", x
,y
,z
,rhw
));
599 glVertex4f(x
*w
, y
*w
, z
*w
, w
);
603 /* For non indexed mode, step onto next parts */
604 if (idxData
== NULL
) {
610 checkGLcall("glEnd and previous calls");
613 static void depth_blt(IWineD3DDevice
*iface
, GLuint texture
) {
614 IWineD3DDeviceImpl
*This
= (IWineD3DDeviceImpl
*)iface
;
615 GLint old_binding
= 0;
617 glPushAttrib(GL_ENABLE_BIT
| GL_DEPTH_BUFFER_BIT
| GL_COLOR_BUFFER_BIT
);
619 glDisable(GL_CULL_FACE
);
621 glDisable(GL_ALPHA_TEST
);
622 glDisable(GL_SCISSOR_TEST
);
623 glDisable(GL_STENCIL_TEST
);
624 glEnable(GL_DEPTH_TEST
);
625 glDepthFunc(GL_ALWAYS
);
626 glBlendFunc(GL_ZERO
, GL_ONE
);
628 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB
));
629 glGetIntegerv(GL_TEXTURE_BINDING_2D
, &old_binding
);
630 glBindTexture(GL_TEXTURE_2D
, texture
);
631 glEnable(GL_TEXTURE_2D
);
633 This
->shader_backend
->shader_select_depth_blt(iface
);
635 glBegin(GL_TRIANGLE_STRIP
);
636 glVertex2f(-1.0f
, -1.0f
);
637 glVertex2f(1.0f
, -1.0f
);
638 glVertex2f(-1.0f
, 1.0f
);
639 glVertex2f(1.0f
, 1.0f
);
642 glBindTexture(GL_TEXTURE_2D
, old_binding
);
646 /* Reselect the old shaders. There doesn't seem to be any glPushAttrib bit for arb shaders,
647 * and this seems easier and more efficient than providing the shader backend with a private
648 * storage to read and restore the old shader settings
650 This
->shader_backend
->shader_select(iface
, use_ps(This
), use_vs(This
));
653 static void depth_copy(IWineD3DDevice
*iface
) {
654 IWineD3DDeviceImpl
*This
= (IWineD3DDeviceImpl
*)iface
;
655 IWineD3DSurfaceImpl
*depth_stencil
= (IWineD3DSurfaceImpl
*)This
->depthStencilBuffer
;
657 /* Only copy the depth buffer if there is one. */
658 if (!depth_stencil
) return;
660 /* TODO: Make this work for modes other than FBO */
661 if (wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
) return;
663 if (depth_stencil
->current_renderbuffer
) {
664 FIXME("Not supported with fixed up depth stencil\n");
668 if (This
->render_offscreen
) {
669 static GLuint tmp_texture
= 0;
670 GLint old_binding
= 0;
672 TRACE("Copying onscreen depth buffer to offscreen surface\n");
675 glGenTextures(1, &tmp_texture
);
678 /* Note that we use depth_blt here as well, rather than glCopyTexImage2D
679 * directly on the FBO texture. That's because we need to flip. */
680 GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0));
681 glGetIntegerv(GL_TEXTURE_BINDING_2D
, &old_binding
);
682 glBindTexture(GL_TEXTURE_2D
, tmp_texture
);
683 glCopyTexImage2D(depth_stencil
->glDescription
.target
,
684 depth_stencil
->glDescription
.level
,
685 depth_stencil
->glDescription
.glFormatInternal
,
688 depth_stencil
->currentDesc
.Width
,
689 depth_stencil
->currentDesc
.Height
,
691 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
692 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
693 glTexParameteri(GL_TEXTURE_2D
, GL_DEPTH_TEXTURE_MODE_ARB
, GL_LUMINANCE
);
694 glBindTexture(GL_TEXTURE_2D
, old_binding
);
696 GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, This
->fbo
));
697 checkGLcall("glBindFramebuffer()");
698 depth_blt(iface
, tmp_texture
);
699 checkGLcall("depth_blt");
701 TRACE("Copying offscreen surface to onscreen depth buffer\n");
703 GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 0));
704 checkGLcall("glBindFramebuffer()");
705 depth_blt(iface
, depth_stencil
->glDescription
.textureName
);
706 checkGLcall("depth_blt");
710 static inline void drawStridedInstanced(IWineD3DDevice
*iface
, WineDirect3DVertexStridedData
*sd
, UINT numberOfVertices
,
711 GLenum glPrimitiveType
, const void *idxData
, short idxSize
, ULONG minIndex
,
712 ULONG startIdx
, ULONG startVertex
) {
713 UINT numInstances
= 0;
714 int numInstancedAttribs
= 0, i
, j
;
715 UINT instancedData
[sizeof(sd
->u
.input
) / sizeof(sd
->u
.input
[0]) /* 16 */];
716 IWineD3DDeviceImpl
*This
= (IWineD3DDeviceImpl
*) iface
;
717 IWineD3DStateBlockImpl
*stateblock
= This
->stateBlock
;
720 /* This is a nasty thing. MSDN says no hardware supports that and apps have to use software vertex processing.
721 * We don't support this for now
723 * Shouldn't be too hard to support with opengl, in theory just call glDrawArrays instead of drawElements.
724 * But the StreamSourceFreq value has a different meaning in that situation.
726 FIXME("Non-indexed instanced drawing is not supported\n");
730 TRACE("(%p) : glElements(%x, %d, %d, ...)\n", This
, glPrimitiveType
, numberOfVertices
, minIndex
);
731 idxData
= idxData
== (void *)-1 ? NULL
: idxData
;
733 /* First, figure out how many instances we have to draw */
734 for(i
= 0; i
< MAX_STREAMS
; i
++) {
735 /* Look at all non-instanced streams */
736 if(!(stateblock
->streamFlags
[i
] & WINED3DSTREAMSOURCE_INSTANCEDATA
) &&
737 stateblock
->streamSource
[i
]) {
738 int inst
= stateblock
->streamFreq
[i
];
740 if(numInstances
&& inst
!= numInstances
) {
741 ERR("Two streams specify a different number of instances. Got %d, new is %d\n", numInstances
, inst
);
747 for(i
= 0; i
< sizeof(sd
->u
.input
) / sizeof(sd
->u
.input
[0]); i
++) {
748 if(stateblock
->streamFlags
[sd
->u
.input
[i
].streamNo
] & WINED3DSTREAMSOURCE_INSTANCEDATA
) {
749 instancedData
[numInstancedAttribs
] = i
;
750 numInstancedAttribs
++;
754 /* now draw numInstances instances :-) */
755 for(i
= 0; i
< numInstances
; i
++) {
756 /* Specify the instanced attributes using immediate mode calls */
757 for(j
= 0; j
< numInstancedAttribs
; j
++) {
758 BYTE
*ptr
= sd
->u
.input
[instancedData
[j
]].lpData
+
759 sd
->u
.input
[instancedData
[j
]].dwStride
* i
+
760 stateblock
->streamOffset
[sd
->u
.input
[instancedData
[j
]].streamNo
];
761 if(sd
->u
.input
[instancedData
[j
]].VBO
) {
762 IWineD3DVertexBufferImpl
*vb
= (IWineD3DVertexBufferImpl
*) stateblock
->streamSource
[sd
->u
.input
[instancedData
[j
]].streamNo
];
763 ptr
+= (long) vb
->resource
.allocatedMemory
;
766 switch(sd
->u
.input
[instancedData
[j
]].dwType
) {
767 case WINED3DDECLTYPE_FLOAT1
:
768 GL_EXTCALL(glVertexAttrib1fvARB(instancedData
[j
], (float *) ptr
));
770 case WINED3DDECLTYPE_FLOAT2
:
771 GL_EXTCALL(glVertexAttrib2fvARB(instancedData
[j
], (float *) ptr
));
773 case WINED3DDECLTYPE_FLOAT3
:
774 GL_EXTCALL(glVertexAttrib3fvARB(instancedData
[j
], (float *) ptr
));
776 case WINED3DDECLTYPE_FLOAT4
:
777 GL_EXTCALL(glVertexAttrib4fvARB(instancedData
[j
], (float *) ptr
));
780 case WINED3DDECLTYPE_UBYTE4
:
781 GL_EXTCALL(glVertexAttrib4ubvARB(instancedData
[j
], ptr
));
783 case WINED3DDECLTYPE_UBYTE4N
:
784 case WINED3DDECLTYPE_D3DCOLOR
:
785 GL_EXTCALL(glVertexAttrib4NubvARB(instancedData
[j
], ptr
));
788 case WINED3DDECLTYPE_SHORT2
:
789 GL_EXTCALL(glVertexAttrib4svARB(instancedData
[j
], (GLshort
*) ptr
));
791 case WINED3DDECLTYPE_SHORT4
:
792 GL_EXTCALL(glVertexAttrib4svARB(instancedData
[j
], (GLshort
*) ptr
));
795 case WINED3DDECLTYPE_SHORT2N
:
797 GLshort s
[4] = {((short *) ptr
)[0], ((short *) ptr
)[1], 0, 1};
798 GL_EXTCALL(glVertexAttrib4NsvARB(instancedData
[j
], s
));
801 case WINED3DDECLTYPE_USHORT2N
:
803 GLushort s
[4] = {((unsigned short *) ptr
)[0], ((unsigned short *) ptr
)[1], 0, 1};
804 GL_EXTCALL(glVertexAttrib4NusvARB(instancedData
[j
], s
));
807 case WINED3DDECLTYPE_SHORT4N
:
808 GL_EXTCALL(glVertexAttrib4NsvARB(instancedData
[j
], (GLshort
*) ptr
));
810 case WINED3DDECLTYPE_USHORT4N
:
811 GL_EXTCALL(glVertexAttrib4NusvARB(instancedData
[j
], (GLushort
*) ptr
));
814 case WINED3DDECLTYPE_UDEC3
:
815 FIXME("Unsure about WINED3DDECLTYPE_UDEC3\n");
816 /*glVertexAttrib3usvARB(instancedData[j], (GLushort *) ptr); Does not exist */
818 case WINED3DDECLTYPE_DEC3N
:
819 FIXME("Unsure about WINED3DDECLTYPE_DEC3N\n");
820 /*glVertexAttrib3NusvARB(instancedData[j], (GLushort *) ptr); Does not exist */
823 case WINED3DDECLTYPE_FLOAT16_2
:
824 /* Are those 16 bit floats. C doesn't have a 16 bit float type. I could read the single bits and calculate a 4
825 * byte float according to the IEEE standard
827 if (GL_SUPPORT(NV_HALF_FLOAT
)) {
828 GL_EXTCALL(glVertexAttrib2hvNV(instancedData
[j
], (GLhalfNV
*)ptr
));
830 FIXME("Unsupported WINED3DDECLTYPE_FLOAT16_2\n");
833 case WINED3DDECLTYPE_FLOAT16_4
:
834 if (GL_SUPPORT(NV_HALF_FLOAT
)) {
835 GL_EXTCALL(glVertexAttrib4hvNV(instancedData
[j
], (GLhalfNV
*)ptr
));
837 FIXME("Unsupported WINED3DDECLTYPE_FLOAT16_4\n");
841 case WINED3DDECLTYPE_UNUSED
:
843 ERR("Unexpected declaration in instanced attributes\n");
848 glDrawElements(glPrimitiveType
, numberOfVertices
, idxSize
== 2 ? GL_UNSIGNED_SHORT
: GL_UNSIGNED_INT
,
849 (const char *)idxData
+(idxSize
* startIdx
));
850 checkGLcall("glDrawElements");
858 void blt_to_drawable(IWineD3DDeviceImpl
*This
, IWineD3DSurfaceImpl
*surface
) {
859 struct coords coords
[4];
862 /* TODO: This could be supported for lazy unlocking */
863 if(!(surface
->Flags
& SFLAG_INTEXTURE
)) {
864 /* It is ok at init to be nowhere */
865 if(!(surface
->Flags
& SFLAG_INSYSMEM
)) {
866 ERR("Blitting surfaces from sysmem not supported yet\n");
871 ActivateContext(This
, This
->render_targets
[0], CTXUSAGE_BLIT
);
874 if(surface
->glDescription
.target
== GL_TEXTURE_2D
) {
875 glBindTexture(GL_TEXTURE_2D
, surface
->glDescription
.textureName
);
876 checkGLcall("GL_TEXTURE_2D, This->glDescription.textureName)");
878 coords
[0].x
= 0; coords
[0].y
= 0; coords
[0].z
= 0;
879 coords
[1].x
= 0; coords
[1].y
= 1; coords
[1].z
= 0;
880 coords
[2].x
= 1; coords
[2].y
= 1; coords
[2].z
= 0;
881 coords
[3].x
= 1; coords
[3].y
= 0; coords
[3].z
= 0;
885 /* Must be a cube map */
886 glDisable(GL_TEXTURE_2D
);
887 checkGLcall("glDisable(GL_TEXTURE_2D)");
888 glEnable(GL_TEXTURE_CUBE_MAP_ARB
);
889 checkGLcall("glEnable(surface->glDescription.target)");
890 glBindTexture(GL_TEXTURE_CUBE_MAP_ARB
, surface
->glDescription
.textureName
);
891 checkGLcall("GL_TEXTURE_CUBE_MAP_ARB, This->glDescription.textureName)");
893 switch(surface
->glDescription
.target
) {
894 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
895 coords
[0].x
= 1; coords
[0].y
= -1; coords
[0].z
= 1;
896 coords
[1].x
= 1; coords
[1].y
= 1; coords
[1].z
= 1;
897 coords
[2].x
= 1; coords
[2].y
= 1; coords
[2].z
= -1;
898 coords
[3].x
= 1; coords
[3].y
= -1; coords
[3].z
= -1;
901 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
902 coords
[0].x
= -1; coords
[0].y
= -1; coords
[0].z
= 1;
903 coords
[1].x
= -1; coords
[1].y
= 1; coords
[1].z
= 1;
904 coords
[2].x
= -1; coords
[2].y
= 1; coords
[2].z
= -1;
905 coords
[3].x
= -1; coords
[3].y
= -1; coords
[3].z
= -1;
908 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
909 coords
[0].x
= -1; coords
[0].y
= 1; coords
[0].z
= 1;
910 coords
[1].x
= 1; coords
[1].y
= 1; coords
[1].z
= 1;
911 coords
[2].x
= 1; coords
[2].y
= 1; coords
[2].z
= -1;
912 coords
[3].x
= -1; coords
[3].y
= 1; coords
[3].z
= -1;
915 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
916 coords
[0].x
= -1; coords
[0].y
= -1; coords
[0].z
= 1;
917 coords
[1].x
= 1; coords
[1].y
= -1; coords
[1].z
= 1;
918 coords
[2].x
= 1; coords
[2].y
= -1; coords
[2].z
= -1;
919 coords
[3].x
= -1; coords
[3].y
= -1; coords
[3].z
= -1;
922 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
923 coords
[0].x
= -1; coords
[0].y
= -1; coords
[0].z
= 1;
924 coords
[1].x
= 1; coords
[1].y
= -1; coords
[1].z
= 1;
925 coords
[2].x
= 1; coords
[2].y
= -1; coords
[2].z
= 1;
926 coords
[3].x
= -1; coords
[3].y
= -1; coords
[3].z
= 1;
929 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
930 coords
[0].x
= -1; coords
[0].y
= -1; coords
[0].z
= -1;
931 coords
[1].x
= 1; coords
[1].y
= -1; coords
[1].z
= -1;
932 coords
[2].x
= 1; coords
[2].y
= -1; coords
[2].z
= -1;
933 coords
[3].x
= -1; coords
[3].y
= -1; coords
[3].z
= -1;
936 ERR("Unexpected texture target\n");
944 if(This
->render_offscreen
) {
945 coords
[0].y
= coords
[0].y
== 1 ? low_coord
: 1;
946 coords
[1].y
= coords
[1].y
== 1 ? low_coord
: 1;
947 coords
[2].y
= coords
[2].y
== 1 ? low_coord
: 1;
948 coords
[3].y
= coords
[3].y
== 1 ? low_coord
: 1;
952 glTexCoord3iv((GLint
*) &coords
[0]);
955 glTexCoord3iv((GLint
*) &coords
[1]);
956 glVertex2i(0, surface
->pow2Height
);
958 glTexCoord3iv((GLint
*) &coords
[2]);
959 glVertex2i(surface
->pow2Width
, surface
->pow2Height
);
961 glTexCoord3iv((GLint
*) &coords
[3]);
962 glVertex2i(surface
->pow2Width
, 0);
964 checkGLcall("glEnd");
966 if(surface
->glDescription
.target
!= GL_TEXTURE_2D
) {
967 glEnable(GL_TEXTURE_2D
);
968 checkGLcall("glEnable(GL_TEXTURE_2D)");
969 glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
970 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
975 /* Routine common to the draw primitive and draw indexed primitive routines */
976 void drawPrimitive(IWineD3DDevice
*iface
,
980 long StartVertexIndex
,
981 UINT numberOfVertices
,
987 IWineD3DDeviceImpl
*This
= (IWineD3DDeviceImpl
*)iface
;
988 IWineD3DSwapChain
*swapchain
;
989 IWineD3DBaseTexture
*texture
= NULL
;
990 IWineD3DSurfaceImpl
*target
;
993 /* Signals other modules that a drawing is in progress and the stateblock finalized */
994 This
->isInDraw
= TRUE
;
996 /* Invalidate the back buffer memory so LockRect will read it the next time */
997 for(i
= 0; i
< GL_LIMITS(buffers
); i
++) {
998 target
= (IWineD3DSurfaceImpl
*) This
->render_targets
[i
];
1000 /* TODO: Only do all that if we're going to change anything
1001 * Texture container dirtification does not work quite right yet
1003 if(target
/*&& target->Flags & (SFLAG_INTEXTURE | SFLAG_INSYSMEM)*/) {
1008 IWineD3DSurface_GetContainer((IWineD3DSurface
*) target
, &IID_IWineD3DSwapChain
, (void **)&swapchain
);
1010 /* Need the surface in the drawable! */
1011 if(!(target
->Flags
& SFLAG_INDRAWABLE
) && (swapchain
|| wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
)) {
1012 blt_to_drawable(This
, target
);
1016 /* Onscreen target. Invalidate system memory copy and texture copy */
1017 target
->Flags
&= ~(SFLAG_INSYSMEM
| SFLAG_INTEXTURE
);
1018 target
->Flags
|= SFLAG_INDRAWABLE
;
1019 IWineD3DSwapChain_Release(swapchain
);
1020 } else if(wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
) {
1021 /* Non-FBO target: Invalidate system copy, texture copy and dirtify the container */
1022 IWineD3DSurface_GetContainer((IWineD3DSurface
*) target
, &IID_IWineD3DBaseTexture
, (void **)&texture
);
1025 IWineD3DBaseTexture_SetDirty(texture
, TRUE
);
1026 IWineD3DTexture_Release(texture
);
1029 target
->Flags
&= ~(SFLAG_INSYSMEM
| SFLAG_INTEXTURE
);
1030 target
->Flags
|= SFLAG_INDRAWABLE
;
1032 /* FBO offscreen target. Invalidate system memory copy */
1033 target
->Flags
&= ~SFLAG_INSYSMEM
;
1036 /* Must be an fbo render target */
1037 target
->Flags
&= ~SFLAG_INSYSMEM
;
1038 target
->Flags
|= SFLAG_INTEXTURE
;
1043 /* Ok, we will be updating the screen from here onwards so grab the lock */
1045 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
) {
1047 apply_fbo_state(iface
);
1051 ActivateContext(This
, This
->render_targets
[0], CTXUSAGE_DRAWPRIM
);
1054 if (This
->depth_copy_state
== WINED3D_DCS_COPY
) {
1057 This
->depth_copy_state
= WINED3D_DCS_INITIAL
;
1061 BOOL emulation
= FALSE
;
1062 WineDirect3DVertexStridedData
*strided
= &This
->strided_streams
;
1063 WineDirect3DVertexStridedData stridedlcl
;
1064 /* Ok, Work out which primitive is requested and how many vertexes that
1066 UINT calculatedNumberOfindices
= primitiveToGl(PrimitiveType
, NumPrimitives
, &glPrimType
);
1067 if (numberOfVertices
== 0 )
1068 numberOfVertices
= calculatedNumberOfindices
;
1071 if(!This
->strided_streams
.u
.s
.position_transformed
&& This
->activeContext
->num_untracked_materials
&&
1072 This
->stateBlock
->renderState
[WINED3DRS_LIGHTING
]) {
1073 FIXME("Using software emulation because not all material properties could be tracked\n");
1076 else if(This
->activeContext
->fog_coord
&& This
->stateBlock
->renderState
[WINED3DRS_FOGENABLE
]) {
1077 /* Either write a pipeline replacement shader or convert the specular alpha from unsigned byte
1078 * to a float in the vertex buffer
1080 FIXME("Using software emulation because manual fog coordinates are provided\n");
1085 IWineD3DVertexBufferImpl
*vb
;
1087 strided
= &stridedlcl
;
1088 memcpy(&stridedlcl
, &This
->strided_streams
, sizeof(stridedlcl
));
1090 #define FIXVBO(type) \
1091 if(stridedlcl.u.s.type.VBO) { \
1092 vb = (IWineD3DVertexBufferImpl *) This->stateBlock->streamSource[stridedlcl.u.s.type.streamNo]; \
1093 stridedlcl.u.s.type.VBO = 0; \
1094 stridedlcl.u.s.type.lpData = (BYTE *) ((unsigned long) stridedlcl.u.s.type.lpData + (unsigned long) vb->resource.allocatedMemory); \
1097 FIXVBO(blendWeights
);
1098 FIXVBO(blendMatrixIndices
);
1103 for(i
= 0; i
< WINED3DDP_MAXTEXCOORD
; i
++) FIXVBO(texCoords
[i
]);
1116 if (This
->useDrawStridedSlow
|| emulation
) {
1117 /* Immediate mode drawing */
1118 drawStridedSlow(iface
, strided
, calculatedNumberOfindices
,
1119 glPrimType
, idxData
, idxSize
, minIndex
, StartIdx
, StartVertexIndex
);
1120 } else if(This
->instancedDraw
) {
1121 /* Instancing emulation with mixing immediate mode and arrays */
1122 drawStridedInstanced(iface
, &This
->strided_streams
, calculatedNumberOfindices
, glPrimType
,
1123 idxData
, idxSize
, minIndex
, StartIdx
, StartVertexIndex
);
1125 /* Simple array draw call */
1126 drawStridedFast(iface
, calculatedNumberOfindices
, glPrimType
,
1127 idxData
, idxSize
, minIndex
, StartIdx
, StartVertexIndex
);
1131 /* Finshed updating the screen, restore lock */
1133 TRACE("Done all gl drawing\n");
1136 #ifdef SHOW_FRAME_MAKEUP
1138 static long int primCounter
= 0;
1139 /* NOTE: set primCounter to the value reported by drawprim
1140 before you want to to write frame makeup to /tmp */
1141 if (primCounter
>= 0) {
1142 WINED3DLOCKED_RECT r
;
1144 IWineD3DSurface_LockRect(This
->renderTarget
, &r
, NULL
, WINED3DLOCK_READONLY
);
1145 sprintf(buffer
, "/tmp/backbuffer_%d.tga", primCounter
);
1146 TRACE("Saving screenshot %s\n", buffer
);
1147 IWineD3DSurface_SaveSnapshot(This
->renderTarget
, buffer
);
1148 IWineD3DSurface_UnlockRect(This
->renderTarget
);
1150 #ifdef SHOW_TEXTURE_MAKEUP
1152 IWineD3DSurface
*pSur
;
1154 for (textureNo
= 0; textureNo
< MAX_COMBINED_SAMPLERS
; ++textureNo
) {
1155 if (This
->stateBlock
->textures
[textureNo
] != NULL
) {
1156 sprintf(buffer
, "/tmp/texture_%p_%d_%d.tga", This
->stateBlock
->textures
[textureNo
], primCounter
, textureNo
);
1157 TRACE("Saving texture %s\n", buffer
);
1158 if (IWineD3DBaseTexture_GetType(This
->stateBlock
->textures
[textureNo
]) == WINED3DRTYPE_TEXTURE
) {
1159 IWineD3DTexture_GetSurfaceLevel((IWineD3DTexture
*)This
->stateBlock
->textures
[textureNo
], 0, &pSur
);
1160 IWineD3DSurface_SaveSnapshot(pSur
, buffer
);
1161 IWineD3DSurface_Release(pSur
);
1163 FIXME("base Texture isn't of type texture %d\n", IWineD3DBaseTexture_GetType(This
->stateBlock
->textures
[textureNo
]));
1170 TRACE("drawprim #%d\n", primCounter
);
1175 /* Control goes back to the device, stateblock values may change again */
1176 This
->isInDraw
= FALSE
;
1179 static void normalize_normal(float *n
) {
1180 float length
= n
[0] * n
[0] + n
[1] * n
[1] + n
[2] * n
[2];
1181 if(length
== 0.0) return;
1182 length
= sqrt(length
);
1183 n
[0] = n
[0] / length
;
1184 n
[1] = n
[1] / length
;
1185 n
[2] = n
[2] / length
;
1188 /* Tesselates a high order rectangular patch into single triangles using gl evaluators
1190 * The problem is that OpenGL does not offer a direct way to return the tesselated primitives,
1191 * and they can't be sent off for rendering directly either. Tesselating is slow, so we want
1192 * to chache the patches in a vertex buffer. But more importantly, gl can't bind generated
1193 * attributes to numbered shader attributes, so we have to store them and rebind them as needed
1196 * To read back, the opengl feedback mode is used. This creates a proplem because we want
1197 * untransformed, unlit vertices, but feedback runs everything through transform and lighting.
1198 * Thus disable lighting and set identity matrices to get unmodified colors and positions.
1199 * To overcome clipping find the biggest x, y and z values of the vertices in the patch and scale
1200 * them to [-1.0;+1.0] and set the viewport up to scale them back.
1202 * Normals are more tricky: Draw white vertices with 3 directional lights, and calculate the
1203 * resulting colors back to the normals.
1205 * NOTE: This function activates a context for blitting, modifies matrices & viewport, but
1206 * does not restore it because normally a draw follows immediately afterwards. The caller is
1207 * responsible of taking care that either the gl states are restored, or the context activated
1208 * for drawing to reset the lastWasBlit flag.
1210 HRESULT
tesselate_rectpatch(IWineD3DDeviceImpl
*This
,
1211 struct WineD3DRectPatch
*patch
) {
1212 unsigned int i
, j
, num_quads
, out_vertex_size
, buffer_size
, d3d_out_vertex_size
;
1213 float max_x
= 0.0, max_y
= 0.0, max_z
= 0.0, neg_z
= 0.0;
1214 WineDirect3DVertexStridedData strided
;
1216 WINED3DRECTPATCH_INFO
*info
= &patch
->RectPatchInfo
;
1218 GLenum feedback_type
;
1219 GLfloat
*feedbuffer
;
1221 /* First, locate the position data. This is provided in a vertex buffer in the stateblock.
1224 memset(&strided
, 0, sizeof(strided
));
1225 primitiveDeclarationConvertToStridedData((IWineD3DDevice
*) This
, FALSE
, &strided
, NULL
);
1226 if(strided
.u
.s
.position
.VBO
) {
1227 IWineD3DVertexBufferImpl
*vb
;
1228 vb
= (IWineD3DVertexBufferImpl
*) This
->stateBlock
->streamSource
[strided
.u
.s
.position
.streamNo
];
1229 strided
.u
.s
.position
.lpData
= (BYTE
*) ((unsigned long) strided
.u
.s
.position
.lpData
+
1230 (unsigned long) vb
->resource
.allocatedMemory
);
1232 vtxStride
= strided
.u
.s
.position
.dwStride
;
1233 data
= strided
.u
.s
.position
.lpData
+
1234 vtxStride
* info
->Stride
* info
->StartVertexOffsetHeight
+
1235 vtxStride
* info
->StartVertexOffsetWidth
;
1237 /* Not entirely sure about what happens with transformed vertices */
1238 if(strided
.u
.s
.position_transformed
) {
1239 FIXME("Transformed position in rectpatch generation\n");
1241 if(vtxStride
% sizeof(GLfloat
)) {
1242 /* glMap2f reads vertex sizes in GLfloats, the d3d stride is in bytes.
1243 * I don't see how the stride could not be a multiple of 4, but make sure
1246 ERR("Vertex stride is not a multiple of sizeof(GLfloat)\n");
1248 if(info
->Basis
!= WINED3DBASIS_BEZIER
) {
1249 FIXME("Basis is %s, how to handle this?\n", debug_d3dbasis(info
->Basis
));
1251 if(info
->Degree
!= WINED3DDEGREE_CUBIC
) {
1252 FIXME("Degree is %s, how to handle this?\n", debug_d3ddegree(info
->Degree
));
1255 /* First, get the boundary cube of the input data */
1256 for(j
= 0; j
< info
->Height
; j
++) {
1257 for(i
= 0; i
< info
->Width
; i
++) {
1258 float *v
= (float *) (data
+ vtxStride
* i
+ vtxStride
* info
->Stride
* j
);
1259 if(fabs(v
[0]) > max_x
) max_x
= fabs(v
[0]);
1260 if(fabs(v
[1]) > max_y
) max_y
= fabs(v
[1]);
1261 if(fabs(v
[2]) > max_z
) max_z
= fabs(v
[2]);
1262 if(v
[2] < neg_z
) neg_z
= v
[2];
1266 /* This needs some improvements in the vertex decl code */
1267 FIXME("Cannot find data to generate. Only generating position and normals\n");
1268 patch
->has_normals
= TRUE
;
1269 patch
->has_texcoords
= FALSE
;
1271 /* Simply activate the context for blitting. This disables all the things we don't want and
1272 * takes care of dirtifying. Dirtifying is preferred over pushing / popping, since drawing the
1273 * patch (as opposed to normal draws) will most likely need different changes anyway
1275 ActivateContext(This
, This
->lastActiveRenderTarget
, CTXUSAGE_BLIT
);
1278 glMatrixMode(GL_PROJECTION
);
1279 checkGLcall("glMatrixMode(GL_PROJECTION)");
1281 checkGLcall("glLoadIndentity()");
1282 glScalef(1 / (max_x
) , 1 / (max_y
), max_z
== 0 ? 1 : 1 / ( 2 * max_z
));
1283 glTranslatef(0, 0, 0.5);
1284 checkGLcall("glScalef");
1285 glViewport(-max_x
, -max_y
, 2 * (max_x
), 2 * (max_y
));
1286 checkGLcall("glViewport");
1288 /* Some states to take care of. If we're in wireframe opengl will produce lines, and confuse
1289 * our feedback buffer parser
1291 glPolygonMode(GL_FRONT_AND_BACK
, GL_FILL
);
1292 checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)");
1293 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_RENDER(WINED3DRS_FILLMODE
));
1294 if(patch
->has_normals
) {
1295 float black
[4] = {0, 0, 0, 0};
1296 float red
[4] = {1, 0, 0, 0};
1297 float green
[4] = {0, 1, 0, 0};
1298 float blue
[4] = {0, 0, 1, 0};
1299 float white
[4] = {1, 1, 1, 1};
1300 glEnable(GL_LIGHTING
);
1301 checkGLcall("glEnable(GL_LIGHTING)");
1302 glLightModelfv(GL_LIGHT_MODEL_AMBIENT
, black
);
1303 checkGLcall("glLightModel for MODEL_AMBIENT");
1304 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_RENDER(WINED3DRS_AMBIENT
));
1306 for(i
= 3; i
< GL_LIMITS(lights
); i
++) {
1307 glDisable(GL_LIGHT0
+ i
);
1308 checkGLcall("glDisable(GL_LIGHT0 + i)");
1309 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_ACTIVELIGHT(i
));
1312 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_ACTIVELIGHT(0));
1313 glLightfv(GL_LIGHT0
, GL_DIFFUSE
, red
);
1314 glLightfv(GL_LIGHT0
, GL_SPECULAR
, black
);
1315 glLightfv(GL_LIGHT0
, GL_AMBIENT
, black
);
1316 glLightfv(GL_LIGHT0
, GL_POSITION
, red
);
1317 glEnable(GL_LIGHT0
);
1318 checkGLcall("Setting up light 1\n");
1319 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_ACTIVELIGHT(1));
1320 glLightfv(GL_LIGHT1
, GL_DIFFUSE
, green
);
1321 glLightfv(GL_LIGHT1
, GL_SPECULAR
, black
);
1322 glLightfv(GL_LIGHT1
, GL_AMBIENT
, black
);
1323 glLightfv(GL_LIGHT1
, GL_POSITION
, green
);
1324 glEnable(GL_LIGHT1
);
1325 checkGLcall("Setting up light 2\n");
1326 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_ACTIVELIGHT(2));
1327 glLightfv(GL_LIGHT2
, GL_DIFFUSE
, blue
);
1328 glLightfv(GL_LIGHT2
, GL_SPECULAR
, black
);
1329 glLightfv(GL_LIGHT2
, GL_AMBIENT
, black
);
1330 glLightfv(GL_LIGHT2
, GL_POSITION
, blue
);
1331 glEnable(GL_LIGHT2
);
1332 checkGLcall("Setting up light 3\n");
1334 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_MATERIAL
);
1335 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_RENDER(WINED3DRS_COLORVERTEX
));
1336 glDisable(GL_COLOR_MATERIAL
);
1337 glMaterialfv(GL_FRONT_AND_BACK
, GL_EMISSION
, black
);
1338 glMaterialfv(GL_FRONT_AND_BACK
, GL_SPECULAR
, black
);
1339 glMaterialfv(GL_FRONT_AND_BACK
, GL_DIFFUSE
, white
);
1340 checkGLcall("Setting up materials\n");
1343 /* Enable the needed maps.
1344 * GL_MAP2_VERTEX_3 is needed for positional data.
1345 * GL_AUTO_NORMAL to generate normals from the position. Do not use GL_MAP2_NORMAL.
1346 * GL_MAP2_TEXTURE_COORD_4 for texture coords
1348 num_quads
= ceilf(patch
->numSegs
[0]) * ceilf(patch
->numSegs
[1]);
1349 out_vertex_size
= 3 /* position */;
1350 d3d_out_vertex_size
= 3;
1351 glEnable(GL_MAP2_VERTEX_3
);
1352 if(patch
->has_normals
&& patch
->has_texcoords
) {
1353 FIXME("Texcoords not handled yet\n");
1354 feedback_type
= GL_3D_COLOR_TEXTURE
;
1355 out_vertex_size
+= 8;
1356 d3d_out_vertex_size
+= 7;
1357 glEnable(GL_AUTO_NORMAL
);
1358 glEnable(GL_MAP2_TEXTURE_COORD_4
);
1359 } else if(patch
->has_texcoords
) {
1360 FIXME("Texcoords not handled yet\n");
1361 feedback_type
= GL_3D_COLOR_TEXTURE
;
1362 out_vertex_size
+= 7;
1363 d3d_out_vertex_size
+= 4;
1364 glEnable(GL_MAP2_TEXTURE_COORD_4
);
1365 } else if(patch
->has_normals
) {
1366 feedback_type
= GL_3D_COLOR
;
1367 out_vertex_size
+= 4;
1368 d3d_out_vertex_size
+= 3;
1369 glEnable(GL_AUTO_NORMAL
);
1371 feedback_type
= GL_3D
;
1373 checkGLcall("glEnable vertex attrib generation");
1375 buffer_size
= num_quads
* out_vertex_size
* 2 /* triangle list */ * 3 /* verts per tri */
1376 + 4 * num_quads
/* 2 triangle markers per quad + num verts in tri */;
1377 feedbuffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, buffer_size
* sizeof(float) * 8);
1379 glMap2f(GL_MAP2_VERTEX_3
,
1380 0, 1, vtxStride
/ sizeof(float), info
->Width
,
1381 0, 1, info
->Stride
* vtxStride
/ sizeof(float), info
->Height
,
1383 checkGLcall("glMap2f");
1384 if(patch
->has_texcoords
) {
1385 glMap2f(GL_MAP2_TEXTURE_COORD_4
,
1386 0, 1, vtxStride
/ sizeof(float), info
->Width
,
1387 0, 1, info
->Stride
* vtxStride
/ sizeof(float), info
->Height
,
1389 checkGLcall("glMap2f");
1391 glMapGrid2f(ceilf(patch
->numSegs
[0]), 0.0, 1.0, ceilf(patch
->numSegs
[1]), 0.0, 1.0);
1392 checkGLcall("glMapGrid2f");
1394 glFeedbackBuffer(buffer_size
* 2, feedback_type
, feedbuffer
);
1395 checkGLcall("glFeedbackBuffer");
1396 glRenderMode(GL_FEEDBACK
);
1398 glEvalMesh2(GL_FILL
, 0, ceilf(patch
->numSegs
[0]), 0, ceilf(patch
->numSegs
[1]));
1399 checkGLcall("glEvalMesh2\n");
1401 i
= glRenderMode(GL_RENDER
);
1403 ERR("Feedback failed. Expected %d elements back\n", buffer_size
);
1405 HeapFree(GetProcessHeap(), 0, feedbuffer
);
1406 return WINED3DERR_DRIVERINTERNALERROR
;
1407 } else if(i
!= buffer_size
) {
1408 ERR("Unexpected amount of elements returned. Expected %d, got %d\n", buffer_size
, i
);
1410 HeapFree(GetProcessHeap(), 0, feedbuffer
);
1411 return WINED3DERR_DRIVERINTERNALERROR
;
1413 TRACE("Got %d elements as expected\n", i
);
1416 HeapFree(GetProcessHeap(), 0, patch
->mem
);
1417 patch
->mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, num_quads
* 6 * d3d_out_vertex_size
* sizeof(float) * 8);
1419 for(j
= 0; j
< buffer_size
; j
+= (3 /* num verts */ * out_vertex_size
+ 2 /* tri marker */)) {
1420 if(feedbuffer
[j
] != GL_POLYGON_TOKEN
) {
1421 ERR("Unexpected token: %f\n", feedbuffer
[j
]);
1424 if(feedbuffer
[j
+ 1] != 3) {
1425 ERR("Unexpected polygon: %f corners\n", feedbuffer
[j
+ 1]);
1428 /* Somehow there are different ideas about back / front facing, so fix up the
1431 patch
->mem
[i
+ 0] = feedbuffer
[j
+ out_vertex_size
* 2 + 2]; /* x, triangle 2 */
1432 patch
->mem
[i
+ 1] = feedbuffer
[j
+ out_vertex_size
* 2 + 3]; /* y, triangle 2 */
1433 patch
->mem
[i
+ 2] = (feedbuffer
[j
+ out_vertex_size
* 2 + 4] - 0.5) * 4 * max_z
; /* z, triangle 3 */
1434 if(patch
->has_normals
) {
1435 patch
->mem
[i
+ 3] = feedbuffer
[j
+ out_vertex_size
* 2 + 5];
1436 patch
->mem
[i
+ 4] = feedbuffer
[j
+ out_vertex_size
* 2 + 6];
1437 patch
->mem
[i
+ 5] = feedbuffer
[j
+ out_vertex_size
* 2 + 7];
1439 i
+= d3d_out_vertex_size
;
1441 patch
->mem
[i
+ 0] = feedbuffer
[j
+ out_vertex_size
* 1 + 2]; /* x, triangle 2 */
1442 patch
->mem
[i
+ 1] = feedbuffer
[j
+ out_vertex_size
* 1 + 3]; /* y, triangle 2 */
1443 patch
->mem
[i
+ 2] = (feedbuffer
[j
+ out_vertex_size
* 1 + 4] - 0.5) * 4 * max_z
; /* z, triangle 2 */
1444 if(patch
->has_normals
) {
1445 patch
->mem
[i
+ 3] = feedbuffer
[j
+ out_vertex_size
* 1 + 5];
1446 patch
->mem
[i
+ 4] = feedbuffer
[j
+ out_vertex_size
* 1 + 6];
1447 patch
->mem
[i
+ 5] = feedbuffer
[j
+ out_vertex_size
* 1 + 7];
1449 i
+= d3d_out_vertex_size
;
1451 patch
->mem
[i
+ 0] = feedbuffer
[j
+ out_vertex_size
* 0 + 2]; /* x, triangle 1 */
1452 patch
->mem
[i
+ 1] = feedbuffer
[j
+ out_vertex_size
* 0 + 3]; /* y, triangle 1 */
1453 patch
->mem
[i
+ 2] = (feedbuffer
[j
+ out_vertex_size
* 0 + 4] - 0.5) * 4 * max_z
; /* z, triangle 1 */
1454 if(patch
->has_normals
) {
1455 patch
->mem
[i
+ 3] = feedbuffer
[j
+ out_vertex_size
* 0 + 5];
1456 patch
->mem
[i
+ 4] = feedbuffer
[j
+ out_vertex_size
* 0 + 6];
1457 patch
->mem
[i
+ 5] = feedbuffer
[j
+ out_vertex_size
* 0 + 7];
1459 i
+= d3d_out_vertex_size
;
1462 if(patch
->has_normals
) {
1463 /* Now do the same with reverse light directions */
1464 float x
[4] = {-1, 0, 0, 0};
1465 float y
[4] = { 0, -1, 0, 0};
1466 float z
[4] = { 0, 0, -1, 0};
1467 glLightfv(GL_LIGHT0
, GL_POSITION
, x
);
1468 glLightfv(GL_LIGHT1
, GL_POSITION
, y
);
1469 glLightfv(GL_LIGHT2
, GL_POSITION
, z
);
1470 checkGLcall("Setting up reverse light directions\n");
1472 glRenderMode(GL_FEEDBACK
);
1473 checkGLcall("glRenderMode(GL_FEEDBACK)");
1474 glEvalMesh2(GL_FILL
, 0, ceilf(patch
->numSegs
[0]), 0, ceilf(patch
->numSegs
[1]));
1475 checkGLcall("glEvalMesh2\n");
1476 i
= glRenderMode(GL_RENDER
);
1477 checkGLcall("glRenderMode(GL_RENDER)");
1480 for(j
= 0; j
< buffer_size
; j
+= (3 /* num verts */ * out_vertex_size
+ 2 /* tri marker */)) {
1481 if(feedbuffer
[j
] != GL_POLYGON_TOKEN
) {
1482 ERR("Unexpected token: %f\n", feedbuffer
[j
]);
1485 if(feedbuffer
[j
+ 1] != 3) {
1486 ERR("Unexpected polygon: %f corners\n", feedbuffer
[j
+ 1]);
1489 if(patch
->mem
[i
+ 3] == 0.0)
1490 patch
->mem
[i
+ 3] = -feedbuffer
[j
+ out_vertex_size
* 2 + 5];
1491 if(patch
->mem
[i
+ 4] == 0.0)
1492 patch
->mem
[i
+ 4] = -feedbuffer
[j
+ out_vertex_size
* 2 + 6];
1493 if(patch
->mem
[i
+ 5] == 0.0)
1494 patch
->mem
[i
+ 5] = -feedbuffer
[j
+ out_vertex_size
* 2 + 7];
1495 normalize_normal(patch
->mem
+ i
+ 3);
1496 i
+= d3d_out_vertex_size
;
1498 if(patch
->mem
[i
+ 3] == 0.0)
1499 patch
->mem
[i
+ 3] = -feedbuffer
[j
+ out_vertex_size
* 1 + 5];
1500 if(patch
->mem
[i
+ 4] == 0.0)
1501 patch
->mem
[i
+ 4] = -feedbuffer
[j
+ out_vertex_size
* 1 + 6];
1502 if(patch
->mem
[i
+ 5] == 0.0)
1503 patch
->mem
[i
+ 5] = -feedbuffer
[j
+ out_vertex_size
* 1 + 7];
1504 normalize_normal(patch
->mem
+ i
+ 3);
1505 i
+= d3d_out_vertex_size
;
1507 if(patch
->mem
[i
+ 3] == 0.0)
1508 patch
->mem
[i
+ 3] = -feedbuffer
[j
+ out_vertex_size
* 0 + 5];
1509 if(patch
->mem
[i
+ 4] == 0.0)
1510 patch
->mem
[i
+ 4] = -feedbuffer
[j
+ out_vertex_size
* 0 + 6];
1511 if(patch
->mem
[i
+ 5] == 0.0)
1512 patch
->mem
[i
+ 5] = -feedbuffer
[j
+ out_vertex_size
* 0 + 7];
1513 normalize_normal(patch
->mem
+ i
+ 3);
1514 i
+= d3d_out_vertex_size
;
1518 glDisable(GL_MAP2_VERTEX_3
);
1519 glDisable(GL_AUTO_NORMAL
);
1520 glDisable(GL_MAP2_NORMAL
);
1521 glDisable(GL_MAP2_TEXTURE_COORD_4
);
1522 checkGLcall("glDisable vertex attrib generation");
1525 HeapFree(GetProcessHeap(), 0, feedbuffer
);
1527 vtxStride
= 3 * sizeof(float);
1528 if(patch
->has_normals
) {
1529 vtxStride
+= 3 * sizeof(float);
1531 if(patch
->has_texcoords
) {
1532 vtxStride
+= 4 * sizeof(float);
1534 memset(&patch
->strided
, 0, sizeof(&patch
->strided
));
1535 patch
->strided
.u
.s
.position
.lpData
= (BYTE
*) patch
->mem
;
1536 patch
->strided
.u
.s
.position
.dwStride
= vtxStride
;
1537 patch
->strided
.u
.s
.position
.dwType
= WINED3DDECLTYPE_FLOAT3
;
1538 patch
->strided
.u
.s
.position
.streamNo
= 255;
1540 if(patch
->has_normals
) {
1541 patch
->strided
.u
.s
.normal
.lpData
= (BYTE
*) patch
->mem
+ 3 * sizeof(float) /* pos */;
1542 patch
->strided
.u
.s
.normal
.dwStride
= vtxStride
;
1543 patch
->strided
.u
.s
.normal
.dwType
= WINED3DDECLTYPE_FLOAT3
;
1544 patch
->strided
.u
.s
.normal
.streamNo
= 255;
1546 if(patch
->has_texcoords
) {
1547 patch
->strided
.u
.s
.texCoords
[0].lpData
= (BYTE
*) patch
->mem
+ 3 * sizeof(float) /* pos */;
1548 if(patch
->has_normals
) {
1549 patch
->strided
.u
.s
.texCoords
[0].lpData
+= 3 * sizeof(float);
1551 patch
->strided
.u
.s
.texCoords
[0].dwStride
= vtxStride
;
1552 patch
->strided
.u
.s
.texCoords
[0].dwType
= WINED3DDECLTYPE_FLOAT4
;
1553 /* MAX_STREAMS index points to an unused element in stateblock->streamOffsets which
1554 * always remains set to 0. Windows uses stream 255 here, but this is not visible to the
1557 patch
->strided
.u
.s
.texCoords
[0].streamNo
= MAX_STREAMS
;