push 390edd058cbebc9f7cb21f639a52f5acd36a8bf3
[wine/hacks.git] / dlls / wined3d / drawprim.c
blobc644aa20d32041f364d62719a8912532cb0296b1
1 /*
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, 2008 Henri Verbeet
9 * Copyright 2007-2008 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
26 #include "config.h"
27 #include "wined3d_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(d3d_draw);
30 #define GLINFO_LOCATION This->adapter->gl_info
32 #include <stdio.h>
33 #include <math.h>
35 /* GL locking is done by the caller */
36 static void drawStridedFast(IWineD3DDevice *iface, GLenum primitive_type,
37 UINT min_vertex_idx, UINT max_vertex_idx, UINT count, UINT idx_size,
38 const void *idx_data, UINT start_idx)
40 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
42 if (idx_size)
44 TRACE("(%p) : glElements(%x, %d, %d, ...)\n", This, primitive_type, count, min_vertex_idx);
46 #if 1
47 glDrawElements(primitive_type, count,
48 idx_size == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT,
49 (const char *)idx_data + (idx_size * start_idx));
50 checkGLcall("glDrawElements");
51 #else
52 glDrawRangeElements(primitive_type, min_vertex_idx, max_vertex_idx, count,
53 idx_size == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT,
54 (const char *)idx_data + (idx_size * start_idx));
55 checkGLcall("glDrawRangeElements");
56 #endif
58 else
60 TRACE("(%p) : glDrawArrays(%#x, %d, %d)\n", This, primitive_type, start_idx, count);
62 glDrawArrays(primitive_type, start_idx, count);
63 checkGLcall("glDrawArrays");
68 * Actually draw using the supplied information.
69 * Slower GL version which extracts info about each vertex in turn
72 /* GL locking is done by the caller */
73 static void drawStridedSlow(IWineD3DDevice *iface, const struct wined3d_stream_info *si, UINT NumVertexes,
74 GLenum glPrimType, const void *idxData, UINT idxSize, UINT minIndex, UINT startIdx)
76 unsigned int textureNo = 0;
77 const WORD *pIdxBufS = NULL;
78 const DWORD *pIdxBufL = NULL;
79 UINT vx_index;
80 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
81 const UINT *streamOffset = This->stateBlock->streamOffset;
82 long SkipnStrides = startIdx + This->stateBlock->loadBaseVertexIndex;
83 BOOL pixelShader = use_ps(This->stateBlock);
84 BOOL specular_fog = FALSE;
85 UINT texture_stages = GL_LIMITS(texture_stages);
86 const BYTE *texCoords[WINED3DDP_MAXTEXCOORD];
87 const BYTE *diffuse = NULL, *specular = NULL, *normal = NULL, *position = NULL;
88 const struct wined3d_stream_info_element *element;
89 DWORD tex_mask = 0;
91 TRACE("Using slow vertex array code\n");
93 /* Variable Initialization */
94 if (idxSize != 0) {
95 /* Immediate mode drawing can't make use of indices in a vbo - get the data from the index buffer.
96 * If the index buffer has no vbo(not supported or other reason), or with user pointer drawing
97 * idxData will be != NULL
99 if(idxData == NULL) {
100 idxData = buffer_get_sysmem((struct wined3d_buffer *) This->stateBlock->pIndexData);
103 if (idxSize == 2) pIdxBufS = idxData;
104 else pIdxBufL = idxData;
105 } else if (idxData) {
106 ERR("non-NULL idxData with 0 idxSize, this should never happen\n");
107 return;
110 /* Start drawing in GL */
111 VTRACE(("glBegin(%x)\n", glPrimType));
112 glBegin(glPrimType);
114 element = &si->elements[WINED3D_FFP_POSITION];
115 if (element->data) position = element->data + streamOffset[element->stream_idx];
117 element = &si->elements[WINED3D_FFP_NORMAL];
118 if (element->data) normal = element->data + streamOffset[element->stream_idx];
119 else glNormal3f(0, 0, 0);
121 element = &si->elements[WINED3D_FFP_DIFFUSE];
122 if (element->data) diffuse = element->data + streamOffset[element->stream_idx];
123 else glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
124 if (This->activeContext->num_untracked_materials && element->format_desc->format != WINED3DFMT_A8R8G8B8)
125 FIXME("Implement diffuse color tracking from %s\n", debug_d3dformat(element->format_desc->format));
127 element = &si->elements[WINED3D_FFP_SPECULAR];
128 if (element->data)
130 specular = element->data + streamOffset[element->stream_idx];
132 /* special case where the fog density is stored in the specular alpha channel */
133 if (This->stateBlock->renderState[WINED3DRS_FOGENABLE]
134 && (This->stateBlock->renderState[WINED3DRS_FOGVERTEXMODE] == WINED3DFOG_NONE
135 || si->elements[WINED3D_FFP_POSITION].format_desc->format == WINED3DFMT_R32G32B32A32_FLOAT)
136 && This->stateBlock->renderState[WINED3DRS_FOGTABLEMODE] == WINED3DFOG_NONE)
138 if (GL_SUPPORT(EXT_FOG_COORD))
140 if (element->format_desc->format == WINED3DFMT_A8R8G8B8) specular_fog = TRUE;
141 else FIXME("Implement fog coordinates from %s\n", debug_d3dformat(element->format_desc->format));
143 else
145 static BOOL warned;
147 if (!warned)
149 /* TODO: Use the fog table code from old ddraw */
150 FIXME("Implement fog for transformed vertices in software\n");
151 warned = TRUE;
156 else if (GL_SUPPORT(EXT_SECONDARY_COLOR))
158 GL_EXTCALL(glSecondaryColor3fEXT)(0, 0, 0);
161 for (textureNo = 0; textureNo < texture_stages; ++textureNo)
163 int coordIdx = This->stateBlock->textureState[textureNo][WINED3DTSS_TEXCOORDINDEX];
164 int texture_idx = This->texUnitMap[textureNo];
166 if (!GL_SUPPORT(ARB_MULTITEXTURE) && textureNo > 0)
168 FIXME("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
169 continue;
172 if (!pixelShader && !This->stateBlock->textures[textureNo]) continue;
174 if (texture_idx == -1) continue;
176 if (coordIdx > 7)
178 TRACE("tex: %d - Skip tex coords, as being system generated\n", textureNo);
179 continue;
181 else if (coordIdx < 0)
183 FIXME("tex: %d - Coord index %d is less than zero, expect a crash.\n", textureNo, coordIdx);
184 continue;
187 element = &si->elements[WINED3D_FFP_TEXCOORD0 + coordIdx];
188 if (element->data)
190 texCoords[coordIdx] = element->data + streamOffset[element->stream_idx];
191 tex_mask |= (1 << textureNo);
193 else
195 TRACE("tex: %d - Skipping tex coords, as no data supplied\n", textureNo);
196 if (GL_SUPPORT(ARB_MULTITEXTURE))
197 GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB + texture_idx, 0, 0, 0, 1));
198 else
199 glTexCoord4f(0, 0, 0, 1);
203 /* We shouldn't start this function if any VBO is involved. Should I put a safety check here?
204 * Guess it's not necessary(we crash then anyway) and would only eat CPU time
207 /* For each primitive */
208 for (vx_index = 0; vx_index < NumVertexes; ++vx_index) {
209 UINT texture, tmp_tex_mask;
210 /* Blending data and Point sizes are not supported by this function. They are not supported by the fixed
211 * function pipeline at all. A Fixme for them is printed after decoding the vertex declaration
214 /* For indexed data, we need to go a few more strides in */
215 if (idxData != NULL) {
217 /* Indexed so work out the number of strides to skip */
218 if (idxSize == 2) {
219 VTRACE(("Idx for vertex %u = %u\n", vx_index, pIdxBufS[startIdx+vx_index]));
220 SkipnStrides = pIdxBufS[startIdx + vx_index] + This->stateBlock->loadBaseVertexIndex;
221 } else {
222 VTRACE(("Idx for vertex %u = %u\n", vx_index, pIdxBufL[startIdx+vx_index]));
223 SkipnStrides = pIdxBufL[startIdx + vx_index] + This->stateBlock->loadBaseVertexIndex;
227 tmp_tex_mask = tex_mask;
228 for (texture = 0; tmp_tex_mask; tmp_tex_mask >>= 1, ++texture)
230 int coord_idx;
231 const void *ptr;
232 int texture_idx;
234 if (!(tmp_tex_mask & 1)) continue;
236 coord_idx = This->stateBlock->textureState[texture][WINED3DTSS_TEXCOORDINDEX];
237 ptr = texCoords[coord_idx] + (SkipnStrides * si->elements[WINED3D_FFP_TEXCOORD0 + coord_idx].stride);
239 texture_idx = This->texUnitMap[texture];
240 multi_texcoord_funcs[si->elements[WINED3D_FFP_TEXCOORD0 + coord_idx].format_desc->emit_idx](
241 GL_TEXTURE0_ARB + texture_idx, ptr);
244 /* Diffuse -------------------------------- */
245 if (diffuse) {
246 const void *ptrToCoords = diffuse + SkipnStrides * si->elements[WINED3D_FFP_DIFFUSE].stride;
248 diffuse_funcs[si->elements[WINED3D_FFP_DIFFUSE].format_desc->emit_idx](ptrToCoords);
249 if(This->activeContext->num_untracked_materials) {
250 DWORD diffuseColor = ((const DWORD *)ptrToCoords)[0];
251 unsigned char i;
252 float color[4];
254 color[0] = D3DCOLOR_B_R(diffuseColor) / 255.0;
255 color[1] = D3DCOLOR_B_G(diffuseColor) / 255.0;
256 color[2] = D3DCOLOR_B_B(diffuseColor) / 255.0;
257 color[3] = D3DCOLOR_B_A(diffuseColor) / 255.0;
259 for(i = 0; i < This->activeContext->num_untracked_materials; i++) {
260 glMaterialfv(GL_FRONT_AND_BACK, This->activeContext->untracked_materials[i], color);
265 /* Specular ------------------------------- */
266 if (specular) {
267 const void *ptrToCoords = specular + SkipnStrides * si->elements[WINED3D_FFP_SPECULAR].stride;
269 specular_funcs[si->elements[WINED3D_FFP_SPECULAR].format_desc->emit_idx](ptrToCoords);
271 if (specular_fog)
273 DWORD specularColor = *(const DWORD *)ptrToCoords;
274 GL_EXTCALL(glFogCoordfEXT(specularColor >> 24));
278 /* Normal -------------------------------- */
279 if (normal != NULL) {
280 const void *ptrToCoords = normal + SkipnStrides * si->elements[WINED3D_FFP_NORMAL].stride;
281 normal_funcs[si->elements[WINED3D_FFP_NORMAL].format_desc->emit_idx](ptrToCoords);
284 /* Position -------------------------------- */
285 if (position) {
286 const void *ptrToCoords = position + SkipnStrides * si->elements[WINED3D_FFP_POSITION].stride;
287 position_funcs[si->elements[WINED3D_FFP_POSITION].format_desc->emit_idx](ptrToCoords);
290 /* For non indexed mode, step onto next parts */
291 if (idxData == NULL) {
292 ++SkipnStrides;
296 glEnd();
297 checkGLcall("glEnd and previous calls");
300 /* GL locking is done by the caller */
301 static inline void send_attribute(IWineD3DDeviceImpl *This, WINED3DFORMAT format, const UINT index, const void *ptr)
303 switch(format)
305 case WINED3DFMT_R32_FLOAT:
306 GL_EXTCALL(glVertexAttrib1fvARB(index, ptr));
307 break;
308 case WINED3DFMT_R32G32_FLOAT:
309 GL_EXTCALL(glVertexAttrib2fvARB(index, ptr));
310 break;
311 case WINED3DFMT_R32G32B32_FLOAT:
312 GL_EXTCALL(glVertexAttrib3fvARB(index, ptr));
313 break;
314 case WINED3DFMT_R32G32B32A32_FLOAT:
315 GL_EXTCALL(glVertexAttrib4fvARB(index, ptr));
316 break;
318 case WINED3DFMT_R8G8B8A8_UINT:
319 GL_EXTCALL(glVertexAttrib4ubvARB(index, ptr));
320 break;
321 case WINED3DFMT_A8R8G8B8:
322 if (GL_SUPPORT(EXT_VERTEX_ARRAY_BGRA))
324 const DWORD *src = ptr;
325 DWORD c = *src & 0xff00ff00;
326 c |= (*src & 0xff0000) >> 16;
327 c |= (*src & 0xff) << 16;
328 GL_EXTCALL(glVertexAttrib4NubvARB(index, (GLubyte *)&c));
329 break;
331 /* else fallthrough */
332 case WINED3DFMT_R8G8B8A8_UNORM:
333 GL_EXTCALL(glVertexAttrib4NubvARB(index, ptr));
334 break;
336 case WINED3DFMT_R16G16_SINT:
337 GL_EXTCALL(glVertexAttrib4svARB(index, ptr));
338 break;
339 case WINED3DFMT_R16G16B16A16_SINT:
340 GL_EXTCALL(glVertexAttrib4svARB(index, ptr));
341 break;
343 case WINED3DFMT_R16G16_SNORM:
345 GLshort s[4] = {((const GLshort *)ptr)[0], ((const GLshort *)ptr)[1], 0, 1};
346 GL_EXTCALL(glVertexAttrib4NsvARB(index, s));
347 break;
349 case WINED3DFMT_R16G16_UNORM:
351 GLushort s[4] = {((const GLushort *)ptr)[0], ((const GLushort *)ptr)[1], 0, 1};
352 GL_EXTCALL(glVertexAttrib4NusvARB(index, s));
353 break;
355 case WINED3DFMT_R16G16B16A16_SNORM:
356 GL_EXTCALL(glVertexAttrib4NsvARB(index, ptr));
357 break;
358 case WINED3DFMT_R16G16B16A16_UNORM:
359 GL_EXTCALL(glVertexAttrib4NusvARB(index, ptr));
360 break;
362 case WINED3DFMT_R10G10B10A2_UINT:
363 FIXME("Unsure about WINED3DDECLTYPE_UDEC3\n");
364 /*glVertexAttrib3usvARB(instancedData[j], (GLushort *) ptr); Does not exist */
365 break;
366 case WINED3DFMT_R10G10B10A2_SNORM:
367 FIXME("Unsure about WINED3DDECLTYPE_DEC3N\n");
368 /*glVertexAttrib3NusvARB(instancedData[j], (GLushort *) ptr); Does not exist */
369 break;
371 case WINED3DFMT_R16G16_FLOAT:
372 /* Are those 16 bit floats. C doesn't have a 16 bit float type. I could read the single bits and calculate a 4
373 * byte float according to the IEEE standard
375 if (GL_SUPPORT(NV_HALF_FLOAT)) {
376 /* Not supported by GL_ARB_half_float_vertex */
377 GL_EXTCALL(glVertexAttrib2hvNV(index, ptr));
378 } else {
379 float x = float_16_to_32(((const unsigned short *)ptr) + 0);
380 float y = float_16_to_32(((const unsigned short *)ptr) + 1);
381 GL_EXTCALL(glVertexAttrib2fARB(index, x, y));
383 break;
384 case WINED3DFMT_R16G16B16A16_FLOAT:
385 if (GL_SUPPORT(NV_HALF_FLOAT)) {
386 /* Not supported by GL_ARB_half_float_vertex */
387 GL_EXTCALL(glVertexAttrib4hvNV(index, ptr));
388 } else {
389 float x = float_16_to_32(((const unsigned short *)ptr) + 0);
390 float y = float_16_to_32(((const unsigned short *)ptr) + 1);
391 float z = float_16_to_32(((const unsigned short *)ptr) + 2);
392 float w = float_16_to_32(((const unsigned short *)ptr) + 3);
393 GL_EXTCALL(glVertexAttrib4fARB(index, x, y, z, w));
395 break;
397 default:
398 ERR("Unexpected attribute format: %s\n", debug_d3dformat(format));
399 break;
403 /* GL locking is done by the caller */
404 static void drawStridedSlowVs(IWineD3DDevice *iface, const struct wined3d_stream_info *si, UINT numberOfVertices,
405 GLenum glPrimitiveType, const void *idxData, UINT idxSize, UINT minIndex, UINT startIdx)
407 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
408 long SkipnStrides = startIdx + This->stateBlock->loadBaseVertexIndex;
409 const WORD *pIdxBufS = NULL;
410 const DWORD *pIdxBufL = NULL;
411 UINT vx_index;
412 int i;
413 IWineD3DStateBlockImpl *stateblock = This->stateBlock;
414 const BYTE *ptr;
416 if (idxSize != 0) {
417 /* Immediate mode drawing can't make use of indices in a vbo - get the data from the index buffer.
418 * If the index buffer has no vbo(not supported or other reason), or with user pointer drawing
419 * idxData will be != NULL
421 if(idxData == NULL) {
422 idxData = buffer_get_sysmem((struct wined3d_buffer *) This->stateBlock->pIndexData);
425 if (idxSize == 2) pIdxBufS = idxData;
426 else pIdxBufL = idxData;
427 } else if (idxData) {
428 ERR("non-NULL idxData with 0 idxSize, this should never happen\n");
429 return;
432 /* Start drawing in GL */
433 VTRACE(("glBegin(%x)\n", glPrimitiveType));
434 glBegin(glPrimitiveType);
436 for (vx_index = 0; vx_index < numberOfVertices; ++vx_index) {
437 if (idxData != NULL) {
439 /* Indexed so work out the number of strides to skip */
440 if (idxSize == 2) {
441 VTRACE(("Idx for vertex %d = %d\n", vx_index, pIdxBufS[startIdx+vx_index]));
442 SkipnStrides = pIdxBufS[startIdx + vx_index] + stateblock->loadBaseVertexIndex;
443 } else {
444 VTRACE(("Idx for vertex %d = %d\n", vx_index, pIdxBufL[startIdx+vx_index]));
445 SkipnStrides = pIdxBufL[startIdx + vx_index] + stateblock->loadBaseVertexIndex;
449 for(i = MAX_ATTRIBS - 1; i >= 0; i--) {
450 if(!si->elements[i].data) continue;
452 ptr = si->elements[i].data +
453 si->elements[i].stride * SkipnStrides +
454 stateblock->streamOffset[si->elements[i].stream_idx];
456 send_attribute(This, si->elements[i].format_desc->format, i, ptr);
458 SkipnStrides++;
461 glEnd();
464 /* GL locking is done by the caller */
465 static inline void drawStridedInstanced(IWineD3DDevice *iface, const struct wined3d_stream_info *si,
466 UINT numberOfVertices, GLenum glPrimitiveType, const void *idxData, UINT idxSize, UINT minIndex,
467 UINT startIdx)
469 UINT numInstances = 0, i;
470 int numInstancedAttribs = 0, j;
471 UINT instancedData[sizeof(si->elements) / sizeof(*si->elements) /* 16 */];
472 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
473 IWineD3DStateBlockImpl *stateblock = This->stateBlock;
475 if (idxSize == 0) {
476 /* This is a nasty thing. MSDN says no hardware supports that and apps have to use software vertex processing.
477 * We don't support this for now
479 * Shouldn't be too hard to support with opengl, in theory just call glDrawArrays instead of drawElements.
480 * But the StreamSourceFreq value has a different meaning in that situation.
482 FIXME("Non-indexed instanced drawing is not supported\n");
483 return;
486 TRACE("(%p) : glElements(%x, %d, %d, ...)\n", This, glPrimitiveType, numberOfVertices, minIndex);
488 /* First, figure out how many instances we have to draw */
489 for(i = 0; i < MAX_STREAMS; i++) {
490 /* Look at the streams and take the first one which matches */
491 if(((stateblock->streamFlags[i] & WINED3DSTREAMSOURCE_INSTANCEDATA) || (stateblock->streamFlags[i] & WINED3DSTREAMSOURCE_INDEXEDDATA)) && stateblock->streamSource[i]) {
492 /* D3D9 could set streamFreq 0 with (INSTANCEDATA or INDEXEDDATA) and then it is handled as 1. See d3d9/tests/visual.c-> stream_test() */
493 if(stateblock->streamFreq[i] == 0){
494 numInstances = 1;
495 } else {
496 numInstances = stateblock->streamFreq[i]; /* use the specified number of instances from the first matched stream. See d3d9/tests/visual.c-> stream_test() */
498 break; /* break, because only the first suitable value is interesting */
502 for (i = 0; i < sizeof(si->elements) / sizeof(*si->elements); ++i)
504 if (stateblock->streamFlags[si->elements[i].stream_idx] & WINED3DSTREAMSOURCE_INSTANCEDATA)
506 instancedData[numInstancedAttribs] = i;
507 numInstancedAttribs++;
511 /* now draw numInstances instances :-) */
512 for(i = 0; i < numInstances; i++) {
513 /* Specify the instanced attributes using immediate mode calls */
514 for(j = 0; j < numInstancedAttribs; j++) {
515 const BYTE *ptr = si->elements[instancedData[j]].data +
516 si->elements[instancedData[j]].stride * i +
517 stateblock->streamOffset[si->elements[instancedData[j]].stream_idx];
518 if (si->elements[instancedData[j]].buffer_object)
520 struct wined3d_buffer *vb =
521 (struct wined3d_buffer *)stateblock->streamSource[si->elements[instancedData[j]].stream_idx];
522 ptr += (long) buffer_get_sysmem(vb);
525 send_attribute(This, si->elements[instancedData[j]].format_desc->format, instancedData[j], ptr);
528 glDrawElements(glPrimitiveType, numberOfVertices, idxSize == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT,
529 (const char *)idxData+(idxSize * startIdx));
530 checkGLcall("glDrawElements");
534 static inline void remove_vbos(IWineD3DDeviceImpl *This, struct wined3d_stream_info *s)
536 unsigned int i;
538 for (i = 0; i < (sizeof(s->elements) / sizeof(*s->elements)); ++i)
540 struct wined3d_stream_info_element *e = &s->elements[i];
541 if (e->buffer_object)
543 struct wined3d_buffer *vb = (struct wined3d_buffer *)This->stateBlock->streamSource[e->stream_idx];
544 e->buffer_object = 0;
545 e->data = (BYTE *)((unsigned long)e->data + (unsigned long)buffer_get_sysmem(vb));
550 /* Routine common to the draw primitive and draw indexed primitive routines */
551 void drawPrimitive(IWineD3DDevice *iface, UINT index_count, UINT numberOfVertices,
552 UINT StartIdx, UINT idxSize, const void *idxData, UINT minIndex)
555 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
556 IWineD3DSurfaceImpl *target;
557 unsigned int i;
559 if (!index_count) return;
561 if (This->stateBlock->renderState[WINED3DRS_COLORWRITEENABLE])
563 /* Invalidate the back buffer memory so LockRect will read it the next time */
564 for (i = 0; i < GL_LIMITS(buffers); ++i)
566 target = (IWineD3DSurfaceImpl *)This->render_targets[i];
567 if (target)
569 IWineD3DSurface_LoadLocation((IWineD3DSurface *)target, SFLAG_INDRAWABLE, NULL);
570 IWineD3DSurface_ModifyLocation((IWineD3DSurface *)target, SFLAG_INDRAWABLE, TRUE);
575 /* Signals other modules that a drawing is in progress and the stateblock finalized */
576 This->isInDraw = TRUE;
578 ActivateContext(This, This->render_targets[0], CTXUSAGE_DRAWPRIM);
580 if (This->stencilBufferTarget) {
581 /* Note that this depends on the ActivateContext call above to set
582 * This->render_offscreen properly. We don't currently take the
583 * Z-compare function into account, but we could skip loading the
584 * depthstencil for D3DCMP_NEVER and D3DCMP_ALWAYS as well. Also note
585 * that we never copy the stencil data.*/
586 DWORD location = This->render_offscreen ? SFLAG_DS_OFFSCREEN : SFLAG_DS_ONSCREEN;
587 if (This->stateBlock->renderState[WINED3DRS_ZWRITEENABLE]
588 || This->stateBlock->renderState[WINED3DRS_ZENABLE])
589 surface_load_ds_location(This->stencilBufferTarget, location);
590 if (This->stateBlock->renderState[WINED3DRS_ZWRITEENABLE])
591 surface_modify_ds_location(This->stencilBufferTarget, location);
594 /* Ok, we will be updating the screen from here onwards so grab the lock */
595 ENTER_GL();
597 GLenum glPrimType = This->stateBlock->gl_primitive_type;
598 BOOL emulation = FALSE;
599 const struct wined3d_stream_info *stream_info = &This->strided_streams;
600 struct wined3d_stream_info stridedlcl;
602 if (!numberOfVertices) numberOfVertices = index_count;
604 if (!use_vs(This->stateBlock))
606 if (!This->strided_streams.position_transformed && This->activeContext->num_untracked_materials
607 && This->stateBlock->renderState[WINED3DRS_LIGHTING])
609 static BOOL warned;
610 if (!warned) {
611 FIXME("Using software emulation because not all material properties could be tracked\n");
612 warned = TRUE;
613 } else {
614 TRACE("Using software emulation because not all material properties could be tracked\n");
616 emulation = TRUE;
618 else if(This->activeContext->fog_coord && This->stateBlock->renderState[WINED3DRS_FOGENABLE]) {
619 /* Either write a pipeline replacement shader or convert the specular alpha from unsigned byte
620 * to a float in the vertex buffer
622 static BOOL warned;
623 if (!warned) {
624 FIXME("Using software emulation because manual fog coordinates are provided\n");
625 warned = TRUE;
626 } else {
627 TRACE("Using software emulation because manual fog coordinates are provided\n");
629 emulation = TRUE;
632 if(emulation) {
633 stream_info = &stridedlcl;
634 memcpy(&stridedlcl, &This->strided_streams, sizeof(stridedlcl));
635 remove_vbos(This, &stridedlcl);
639 if (This->useDrawStridedSlow || emulation) {
640 /* Immediate mode drawing */
641 if (use_vs(This->stateBlock))
643 static BOOL warned;
644 if (!warned) {
645 FIXME("Using immediate mode with vertex shaders for half float emulation\n");
646 warned = TRUE;
647 } else {
648 TRACE("Using immediate mode with vertex shaders for half float emulation\n");
650 drawStridedSlowVs(iface, stream_info, index_count, glPrimType, idxData, idxSize, minIndex, StartIdx);
651 } else {
652 drawStridedSlow(iface, stream_info, index_count, glPrimType, idxData, idxSize, minIndex, StartIdx);
654 } else if(This->instancedDraw) {
655 /* Instancing emulation with mixing immediate mode and arrays */
656 drawStridedInstanced(iface, &This->strided_streams, index_count,
657 glPrimType, idxData, idxSize, minIndex, StartIdx);
658 } else {
659 drawStridedFast(iface, glPrimType, minIndex, minIndex + numberOfVertices - 1,
660 index_count, idxSize, idxData, StartIdx);
664 /* Finished updating the screen, restore lock */
665 LEAVE_GL();
666 TRACE("Done all gl drawing\n");
668 /* Diagnostics */
669 #ifdef SHOW_FRAME_MAKEUP
671 static long int primCounter = 0;
672 /* NOTE: set primCounter to the value reported by drawprim
673 before you want to to write frame makeup to /tmp */
674 if (primCounter >= 0) {
675 WINED3DLOCKED_RECT r;
676 char buffer[80];
677 IWineD3DSurface_LockRect(This->render_targets[0], &r, NULL, WINED3DLOCK_READONLY);
678 sprintf(buffer, "/tmp/backbuffer_%ld.tga", primCounter);
679 TRACE("Saving screenshot %s\n", buffer);
680 IWineD3DSurface_SaveSnapshot(This->render_targets[0], buffer);
681 IWineD3DSurface_UnlockRect(This->render_targets[0]);
683 #ifdef SHOW_TEXTURE_MAKEUP
685 IWineD3DSurface *pSur;
686 int textureNo;
687 for (textureNo = 0; textureNo < MAX_COMBINED_SAMPLERS; ++textureNo) {
688 if (This->stateBlock->textures[textureNo] != NULL) {
689 sprintf(buffer, "/tmp/texture_%p_%ld_%d.tga", This->stateBlock->textures[textureNo], primCounter, textureNo);
690 TRACE("Saving texture %s\n", buffer);
691 if (IWineD3DBaseTexture_GetType(This->stateBlock->textures[textureNo]) == WINED3DRTYPE_TEXTURE) {
692 IWineD3DTexture_GetSurfaceLevel(This->stateBlock->textures[textureNo], 0, &pSur);
693 IWineD3DSurface_SaveSnapshot(pSur, buffer);
694 IWineD3DSurface_Release(pSur);
695 } else {
696 FIXME("base Texture isn't of type texture %d\n", IWineD3DBaseTexture_GetType(This->stateBlock->textures[textureNo]));
701 #endif
703 TRACE("drawprim #%ld\n", primCounter);
704 ++primCounter;
706 #endif
708 /* Control goes back to the device, stateblock values may change again */
709 This->isInDraw = FALSE;
712 static void normalize_normal(float *n) {
713 float length = n[0] * n[0] + n[1] * n[1] + n[2] * n[2];
714 if(length == 0.0) return;
715 length = sqrt(length);
716 n[0] = n[0] / length;
717 n[1] = n[1] / length;
718 n[2] = n[2] / length;
721 /* Tesselates a high order rectangular patch into single triangles using gl evaluators
723 * The problem is that OpenGL does not offer a direct way to return the tesselated primitives,
724 * and they can't be sent off for rendering directly either. Tesselating is slow, so we want
725 * to cache the patches in a vertex buffer. But more importantly, gl can't bind generated
726 * attributes to numbered shader attributes, so we have to store them and rebind them as needed
727 * in drawprim.
729 * To read back, the opengl feedback mode is used. This creates a problem because we want
730 * untransformed, unlit vertices, but feedback runs everything through transform and lighting.
731 * Thus disable lighting and set identity matrices to get unmodified colors and positions.
732 * To overcome clipping find the biggest x, y and z values of the vertices in the patch and scale
733 * them to [-1.0;+1.0] and set the viewport up to scale them back.
735 * Normals are more tricky: Draw white vertices with 3 directional lights, and calculate the
736 * resulting colors back to the normals.
738 * NOTE: This function activates a context for blitting, modifies matrices & viewport, but
739 * does not restore it because normally a draw follows immediately afterwards. The caller is
740 * responsible of taking care that either the gl states are restored, or the context activated
741 * for drawing to reset the lastWasBlit flag.
743 HRESULT tesselate_rectpatch(IWineD3DDeviceImpl *This,
744 struct WineD3DRectPatch *patch) {
745 unsigned int i, j, num_quads, out_vertex_size, buffer_size, d3d_out_vertex_size;
746 float max_x = 0.0, max_y = 0.0, max_z = 0.0, neg_z = 0.0;
747 struct wined3d_stream_info stream_info;
748 struct wined3d_stream_info_element *e;
749 const BYTE *data;
750 const WINED3DRECTPATCH_INFO *info = &patch->RectPatchInfo;
751 DWORD vtxStride;
752 GLenum feedback_type;
753 GLfloat *feedbuffer;
755 /* First, locate the position data. This is provided in a vertex buffer in the stateblock.
756 * Beware of vbos
758 device_stream_info_from_declaration(This, FALSE, &stream_info, NULL);
760 e = &stream_info.elements[WINED3D_FFP_POSITION];
761 if (e->buffer_object)
763 struct wined3d_buffer *vb;
764 vb = (struct wined3d_buffer *)This->stateBlock->streamSource[e->stream_idx];
765 e->data = (BYTE *)((unsigned long)e->data + (unsigned long)buffer_get_sysmem(vb));
767 vtxStride = e->stride;
768 data = e->data +
769 vtxStride * info->Stride * info->StartVertexOffsetHeight +
770 vtxStride * info->StartVertexOffsetWidth;
772 /* Not entirely sure about what happens with transformed vertices */
773 if (stream_info.position_transformed) FIXME("Transformed position in rectpatch generation\n");
775 if(vtxStride % sizeof(GLfloat)) {
776 /* glMap2f reads vertex sizes in GLfloats, the d3d stride is in bytes.
777 * I don't see how the stride could not be a multiple of 4, but make sure
778 * to check it
780 ERR("Vertex stride is not a multiple of sizeof(GLfloat)\n");
782 if(info->Basis != WINED3DBASIS_BEZIER) {
783 FIXME("Basis is %s, how to handle this?\n", debug_d3dbasis(info->Basis));
785 if(info->Degree != WINED3DDEGREE_CUBIC) {
786 FIXME("Degree is %s, how to handle this?\n", debug_d3ddegree(info->Degree));
789 /* First, get the boundary cube of the input data */
790 for(j = 0; j < info->Height; j++) {
791 for(i = 0; i < info->Width; i++) {
792 const float *v = (const float *)(data + vtxStride * i + vtxStride * info->Stride * j);
793 if(fabs(v[0]) > max_x) max_x = fabs(v[0]);
794 if(fabs(v[1]) > max_y) max_y = fabs(v[1]);
795 if(fabs(v[2]) > max_z) max_z = fabs(v[2]);
796 if(v[2] < neg_z) neg_z = v[2];
800 /* This needs some improvements in the vertex decl code */
801 FIXME("Cannot find data to generate. Only generating position and normals\n");
802 patch->has_normals = TRUE;
803 patch->has_texcoords = FALSE;
805 /* Simply activate the context for blitting. This disables all the things we don't want and
806 * takes care of dirtifying. Dirtifying is preferred over pushing / popping, since drawing the
807 * patch (as opposed to normal draws) will most likely need different changes anyway
809 ActivateContext(This, This->lastActiveRenderTarget, CTXUSAGE_BLIT);
810 ENTER_GL();
812 glMatrixMode(GL_PROJECTION);
813 checkGLcall("glMatrixMode(GL_PROJECTION)");
814 glLoadIdentity();
815 checkGLcall("glLoadIndentity()");
816 glScalef(1 / (max_x) , 1 / (max_y), max_z == 0 ? 1 : 1 / ( 2 * max_z));
817 glTranslatef(0, 0, 0.5);
818 checkGLcall("glScalef");
819 glViewport(-max_x, -max_y, 2 * (max_x), 2 * (max_y));
820 checkGLcall("glViewport");
822 /* Some states to take care of. If we're in wireframe opengl will produce lines, and confuse
823 * our feedback buffer parser
825 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
826 checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)");
827 IWineD3DDeviceImpl_MarkStateDirty(This, STATE_RENDER(WINED3DRS_FILLMODE));
828 if(patch->has_normals) {
829 static const GLfloat black[] = {0, 0, 0, 0};
830 static const GLfloat red[] = {1, 0, 0, 0};
831 static const GLfloat green[] = {0, 1, 0, 0};
832 static const GLfloat blue[] = {0, 0, 1, 0};
833 static const GLfloat white[] = {1, 1, 1, 1};
834 glEnable(GL_LIGHTING);
835 checkGLcall("glEnable(GL_LIGHTING)");
836 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, black);
837 checkGLcall("glLightModel for MODEL_AMBIENT");
838 IWineD3DDeviceImpl_MarkStateDirty(This, STATE_RENDER(WINED3DRS_AMBIENT));
840 for(i = 3; i < GL_LIMITS(lights); i++) {
841 glDisable(GL_LIGHT0 + i);
842 checkGLcall("glDisable(GL_LIGHT0 + i)");
843 IWineD3DDeviceImpl_MarkStateDirty(This, STATE_ACTIVELIGHT(i));
846 IWineD3DDeviceImpl_MarkStateDirty(This, STATE_ACTIVELIGHT(0));
847 glLightfv(GL_LIGHT0, GL_DIFFUSE, red);
848 glLightfv(GL_LIGHT0, GL_SPECULAR, black);
849 glLightfv(GL_LIGHT0, GL_AMBIENT, black);
850 glLightfv(GL_LIGHT0, GL_POSITION, red);
851 glEnable(GL_LIGHT0);
852 checkGLcall("Setting up light 1\n");
853 IWineD3DDeviceImpl_MarkStateDirty(This, STATE_ACTIVELIGHT(1));
854 glLightfv(GL_LIGHT1, GL_DIFFUSE, green);
855 glLightfv(GL_LIGHT1, GL_SPECULAR, black);
856 glLightfv(GL_LIGHT1, GL_AMBIENT, black);
857 glLightfv(GL_LIGHT1, GL_POSITION, green);
858 glEnable(GL_LIGHT1);
859 checkGLcall("Setting up light 2\n");
860 IWineD3DDeviceImpl_MarkStateDirty(This, STATE_ACTIVELIGHT(2));
861 glLightfv(GL_LIGHT2, GL_DIFFUSE, blue);
862 glLightfv(GL_LIGHT2, GL_SPECULAR, black);
863 glLightfv(GL_LIGHT2, GL_AMBIENT, black);
864 glLightfv(GL_LIGHT2, GL_POSITION, blue);
865 glEnable(GL_LIGHT2);
866 checkGLcall("Setting up light 3\n");
868 IWineD3DDeviceImpl_MarkStateDirty(This, STATE_MATERIAL);
869 IWineD3DDeviceImpl_MarkStateDirty(This, STATE_RENDER(WINED3DRS_COLORVERTEX));
870 glDisable(GL_COLOR_MATERIAL);
871 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, black);
872 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black);
873 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, white);
874 checkGLcall("Setting up materials\n");
877 /* Enable the needed maps.
878 * GL_MAP2_VERTEX_3 is needed for positional data.
879 * GL_AUTO_NORMAL to generate normals from the position. Do not use GL_MAP2_NORMAL.
880 * GL_MAP2_TEXTURE_COORD_4 for texture coords
882 num_quads = ceilf(patch->numSegs[0]) * ceilf(patch->numSegs[1]);
883 out_vertex_size = 3 /* position */;
884 d3d_out_vertex_size = 3;
885 glEnable(GL_MAP2_VERTEX_3);
886 if(patch->has_normals && patch->has_texcoords) {
887 FIXME("Texcoords not handled yet\n");
888 feedback_type = GL_3D_COLOR_TEXTURE;
889 out_vertex_size += 8;
890 d3d_out_vertex_size += 7;
891 glEnable(GL_AUTO_NORMAL);
892 glEnable(GL_MAP2_TEXTURE_COORD_4);
893 } else if(patch->has_texcoords) {
894 FIXME("Texcoords not handled yet\n");
895 feedback_type = GL_3D_COLOR_TEXTURE;
896 out_vertex_size += 7;
897 d3d_out_vertex_size += 4;
898 glEnable(GL_MAP2_TEXTURE_COORD_4);
899 } else if(patch->has_normals) {
900 feedback_type = GL_3D_COLOR;
901 out_vertex_size += 4;
902 d3d_out_vertex_size += 3;
903 glEnable(GL_AUTO_NORMAL);
904 } else {
905 feedback_type = GL_3D;
907 checkGLcall("glEnable vertex attrib generation");
909 buffer_size = num_quads * out_vertex_size * 2 /* triangle list */ * 3 /* verts per tri */
910 + 4 * num_quads /* 2 triangle markers per quad + num verts in tri */;
911 feedbuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, buffer_size * sizeof(float) * 8);
913 glMap2f(GL_MAP2_VERTEX_3,
914 0, 1, vtxStride / sizeof(float), info->Width,
915 0, 1, info->Stride * vtxStride / sizeof(float), info->Height,
916 (const GLfloat *)data);
917 checkGLcall("glMap2f");
918 if(patch->has_texcoords) {
919 glMap2f(GL_MAP2_TEXTURE_COORD_4,
920 0, 1, vtxStride / sizeof(float), info->Width,
921 0, 1, info->Stride * vtxStride / sizeof(float), info->Height,
922 (const GLfloat *)data);
923 checkGLcall("glMap2f");
925 glMapGrid2f(ceilf(patch->numSegs[0]), 0.0, 1.0, ceilf(patch->numSegs[1]), 0.0, 1.0);
926 checkGLcall("glMapGrid2f");
928 glFeedbackBuffer(buffer_size * 2, feedback_type, feedbuffer);
929 checkGLcall("glFeedbackBuffer");
930 glRenderMode(GL_FEEDBACK);
932 glEvalMesh2(GL_FILL, 0, ceilf(patch->numSegs[0]), 0, ceilf(patch->numSegs[1]));
933 checkGLcall("glEvalMesh2\n");
935 i = glRenderMode(GL_RENDER);
936 if(i == -1) {
937 LEAVE_GL();
938 ERR("Feedback failed. Expected %d elements back\n", buffer_size);
939 HeapFree(GetProcessHeap(), 0, feedbuffer);
940 return WINED3DERR_DRIVERINTERNALERROR;
941 } else if(i != buffer_size) {
942 LEAVE_GL();
943 ERR("Unexpected amount of elements returned. Expected %d, got %d\n", buffer_size, i);
944 HeapFree(GetProcessHeap(), 0, feedbuffer);
945 return WINED3DERR_DRIVERINTERNALERROR;
946 } else {
947 TRACE("Got %d elements as expected\n", i);
950 HeapFree(GetProcessHeap(), 0, patch->mem);
951 patch->mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, num_quads * 6 * d3d_out_vertex_size * sizeof(float) * 8);
952 i = 0;
953 for(j = 0; j < buffer_size; j += (3 /* num verts */ * out_vertex_size + 2 /* tri marker */)) {
954 if(feedbuffer[j] != GL_POLYGON_TOKEN) {
955 ERR("Unexpected token: %f\n", feedbuffer[j]);
956 continue;
958 if(feedbuffer[j + 1] != 3) {
959 ERR("Unexpected polygon: %f corners\n", feedbuffer[j + 1]);
960 continue;
962 /* Somehow there are different ideas about back / front facing, so fix up the
963 * vertex order
965 patch->mem[i + 0] = feedbuffer[j + out_vertex_size * 2 + 2]; /* x, triangle 2 */
966 patch->mem[i + 1] = feedbuffer[j + out_vertex_size * 2 + 3]; /* y, triangle 2 */
967 patch->mem[i + 2] = (feedbuffer[j + out_vertex_size * 2 + 4] - 0.5) * 4 * max_z; /* z, triangle 3 */
968 if(patch->has_normals) {
969 patch->mem[i + 3] = feedbuffer[j + out_vertex_size * 2 + 5];
970 patch->mem[i + 4] = feedbuffer[j + out_vertex_size * 2 + 6];
971 patch->mem[i + 5] = feedbuffer[j + out_vertex_size * 2 + 7];
973 i += d3d_out_vertex_size;
975 patch->mem[i + 0] = feedbuffer[j + out_vertex_size * 1 + 2]; /* x, triangle 2 */
976 patch->mem[i + 1] = feedbuffer[j + out_vertex_size * 1 + 3]; /* y, triangle 2 */
977 patch->mem[i + 2] = (feedbuffer[j + out_vertex_size * 1 + 4] - 0.5) * 4 * max_z; /* z, triangle 2 */
978 if(patch->has_normals) {
979 patch->mem[i + 3] = feedbuffer[j + out_vertex_size * 1 + 5];
980 patch->mem[i + 4] = feedbuffer[j + out_vertex_size * 1 + 6];
981 patch->mem[i + 5] = feedbuffer[j + out_vertex_size * 1 + 7];
983 i += d3d_out_vertex_size;
985 patch->mem[i + 0] = feedbuffer[j + out_vertex_size * 0 + 2]; /* x, triangle 1 */
986 patch->mem[i + 1] = feedbuffer[j + out_vertex_size * 0 + 3]; /* y, triangle 1 */
987 patch->mem[i + 2] = (feedbuffer[j + out_vertex_size * 0 + 4] - 0.5) * 4 * max_z; /* z, triangle 1 */
988 if(patch->has_normals) {
989 patch->mem[i + 3] = feedbuffer[j + out_vertex_size * 0 + 5];
990 patch->mem[i + 4] = feedbuffer[j + out_vertex_size * 0 + 6];
991 patch->mem[i + 5] = feedbuffer[j + out_vertex_size * 0 + 7];
993 i += d3d_out_vertex_size;
996 if(patch->has_normals) {
997 /* Now do the same with reverse light directions */
998 static const GLfloat x[] = {-1, 0, 0, 0};
999 static const GLfloat y[] = { 0, -1, 0, 0};
1000 static const GLfloat z[] = { 0, 0, -1, 0};
1001 glLightfv(GL_LIGHT0, GL_POSITION, x);
1002 glLightfv(GL_LIGHT1, GL_POSITION, y);
1003 glLightfv(GL_LIGHT2, GL_POSITION, z);
1004 checkGLcall("Setting up reverse light directions\n");
1006 glRenderMode(GL_FEEDBACK);
1007 checkGLcall("glRenderMode(GL_FEEDBACK)");
1008 glEvalMesh2(GL_FILL, 0, ceilf(patch->numSegs[0]), 0, ceilf(patch->numSegs[1]));
1009 checkGLcall("glEvalMesh2\n");
1010 i = glRenderMode(GL_RENDER);
1011 checkGLcall("glRenderMode(GL_RENDER)");
1013 i = 0;
1014 for(j = 0; j < buffer_size; j += (3 /* num verts */ * out_vertex_size + 2 /* tri marker */)) {
1015 if(feedbuffer[j] != GL_POLYGON_TOKEN) {
1016 ERR("Unexpected token: %f\n", feedbuffer[j]);
1017 continue;
1019 if(feedbuffer[j + 1] != 3) {
1020 ERR("Unexpected polygon: %f corners\n", feedbuffer[j + 1]);
1021 continue;
1023 if(patch->mem[i + 3] == 0.0)
1024 patch->mem[i + 3] = -feedbuffer[j + out_vertex_size * 2 + 5];
1025 if(patch->mem[i + 4] == 0.0)
1026 patch->mem[i + 4] = -feedbuffer[j + out_vertex_size * 2 + 6];
1027 if(patch->mem[i + 5] == 0.0)
1028 patch->mem[i + 5] = -feedbuffer[j + out_vertex_size * 2 + 7];
1029 normalize_normal(patch->mem + i + 3);
1030 i += d3d_out_vertex_size;
1032 if(patch->mem[i + 3] == 0.0)
1033 patch->mem[i + 3] = -feedbuffer[j + out_vertex_size * 1 + 5];
1034 if(patch->mem[i + 4] == 0.0)
1035 patch->mem[i + 4] = -feedbuffer[j + out_vertex_size * 1 + 6];
1036 if(patch->mem[i + 5] == 0.0)
1037 patch->mem[i + 5] = -feedbuffer[j + out_vertex_size * 1 + 7];
1038 normalize_normal(patch->mem + i + 3);
1039 i += d3d_out_vertex_size;
1041 if(patch->mem[i + 3] == 0.0)
1042 patch->mem[i + 3] = -feedbuffer[j + out_vertex_size * 0 + 5];
1043 if(patch->mem[i + 4] == 0.0)
1044 patch->mem[i + 4] = -feedbuffer[j + out_vertex_size * 0 + 6];
1045 if(patch->mem[i + 5] == 0.0)
1046 patch->mem[i + 5] = -feedbuffer[j + out_vertex_size * 0 + 7];
1047 normalize_normal(patch->mem + i + 3);
1048 i += d3d_out_vertex_size;
1052 glDisable(GL_MAP2_VERTEX_3);
1053 glDisable(GL_AUTO_NORMAL);
1054 glDisable(GL_MAP2_NORMAL);
1055 glDisable(GL_MAP2_TEXTURE_COORD_4);
1056 checkGLcall("glDisable vertex attrib generation");
1057 LEAVE_GL();
1059 HeapFree(GetProcessHeap(), 0, feedbuffer);
1061 vtxStride = 3 * sizeof(float);
1062 if(patch->has_normals) {
1063 vtxStride += 3 * sizeof(float);
1065 if(patch->has_texcoords) {
1066 vtxStride += 4 * sizeof(float);
1068 memset(&patch->strided, 0, sizeof(&patch->strided));
1069 patch->strided.position.format = WINED3DFMT_R32G32B32_FLOAT;
1070 patch->strided.position.lpData = (BYTE *) patch->mem;
1071 patch->strided.position.dwStride = vtxStride;
1073 if(patch->has_normals) {
1074 patch->strided.normal.format = WINED3DFMT_R32G32B32_FLOAT;
1075 patch->strided.normal.lpData = (BYTE *) patch->mem + 3 * sizeof(float) /* pos */;
1076 patch->strided.normal.dwStride = vtxStride;
1078 if(patch->has_texcoords) {
1079 patch->strided.texCoords[0].format = WINED3DFMT_R32G32B32A32_FLOAT;
1080 patch->strided.texCoords[0].lpData = (BYTE *) patch->mem + 3 * sizeof(float) /* pos */;
1081 if(patch->has_normals) {
1082 patch->strided.texCoords[0].lpData += 3 * sizeof(float);
1084 patch->strided.texCoords[0].dwStride = vtxStride;
1087 return WINED3D_OK;