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
10 * Copyright 2009 Henri Verbeet for CodeWeavers
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/port.h"
30 #include "wined3d_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(d3d_draw);
37 /* GL locking is done by the caller */
38 static void drawStridedFast(const struct wined3d_gl_info *gl_info, GLenum primitive_type, UINT count, UINT idx_size,
39 const void *idx_data, UINT start_idx, INT base_vertex_index)
43 GLenum idxtype = idx_size == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
44 if (gl_info->supported[ARB_DRAW_ELEMENTS_BASE_VERTEX])
46 GL_EXTCALL(glDrawElementsBaseVertex(primitive_type, count, idxtype,
47 (const char *)idx_data + (idx_size * start_idx), base_vertex_index));
48 checkGLcall("glDrawElementsBaseVertex");
52 gl_info->gl_ops.gl.p_glDrawElements(primitive_type, count,
53 idxtype, (const char *)idx_data + (idx_size * start_idx));
54 checkGLcall("glDrawElements");
59 gl_info->gl_ops.gl.p_glDrawArrays(primitive_type, start_idx, count);
60 checkGLcall("glDrawArrays");
65 * Actually draw using the supplied information.
66 * Slower GL version which extracts info about each vertex in turn
69 /* GL locking is done by the caller */
70 static void drawStridedSlow(const struct wined3d_device *device, const struct wined3d_context *context,
71 const struct wined3d_stream_info *si, UINT NumVertexes, GLenum glPrimType,
72 const void *idxData, UINT idxSize, UINT startIdx)
74 unsigned int textureNo = 0;
75 const WORD *pIdxBufS = NULL;
76 const DWORD *pIdxBufL = NULL;
78 const struct wined3d_state *state = &device->stateBlock->state;
79 LONG SkipnStrides = startIdx;
80 BOOL pixelShader = use_ps(state);
81 BOOL specular_fog = FALSE;
82 const BYTE *texCoords[WINED3DDP_MAXTEXCOORD];
83 const BYTE *diffuse = NULL, *specular = NULL, *normal = NULL, *position = NULL;
84 const struct wined3d_gl_info *gl_info = context->gl_info;
85 UINT texture_stages = gl_info->limits.texture_stages;
86 const struct wined3d_stream_info_element *element;
87 UINT num_untracked_materials;
90 TRACE("Using slow vertex array code\n");
92 /* Variable Initialization */
95 /* Immediate mode drawing can't make use of indices in a vbo - get the
96 * data from the index buffer. If the index buffer has no vbo (not
97 * supported or other reason), or with user pointer drawing idxData
98 * will be non-NULL. */
100 idxData = buffer_get_sysmem(state->index_buffer, gl_info);
102 if (idxSize == 2) pIdxBufS = idxData;
103 else pIdxBufL = idxData;
104 } else if (idxData) {
105 ERR("non-NULL idxData with 0 idxSize, this should never happen\n");
109 /* Start drawing in GL */
110 gl_info->gl_ops.gl.p_glBegin(glPrimType);
112 if (si->use_map & (1 << WINED3D_FFP_POSITION))
114 element = &si->elements[WINED3D_FFP_POSITION];
115 position = element->data.addr;
118 if (si->use_map & (1 << WINED3D_FFP_NORMAL))
120 element = &si->elements[WINED3D_FFP_NORMAL];
121 normal = element->data.addr;
125 gl_info->gl_ops.gl.p_glNormal3f(0, 0, 0);
128 num_untracked_materials = context->num_untracked_materials;
129 if (si->use_map & (1 << WINED3D_FFP_DIFFUSE))
131 element = &si->elements[WINED3D_FFP_DIFFUSE];
132 diffuse = element->data.addr;
134 if (num_untracked_materials && element->format->id != WINED3DFMT_B8G8R8A8_UNORM)
135 FIXME("Implement diffuse color tracking from %s\n", debug_d3dformat(element->format->id));
139 gl_info->gl_ops.gl.p_glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
142 if (si->use_map & (1 << WINED3D_FFP_SPECULAR))
144 element = &si->elements[WINED3D_FFP_SPECULAR];
145 specular = element->data.addr;
147 /* special case where the fog density is stored in the specular alpha channel */
148 if (state->render_states[WINED3D_RS_FOGENABLE]
149 && (state->render_states[WINED3D_RS_FOGVERTEXMODE] == WINED3D_FOG_NONE
150 || si->elements[WINED3D_FFP_POSITION].format->id == WINED3DFMT_R32G32B32A32_FLOAT)
151 && state->render_states[WINED3D_RS_FOGTABLEMODE] == WINED3D_FOG_NONE)
153 if (gl_info->supported[EXT_FOG_COORD])
155 if (element->format->id == WINED3DFMT_B8G8R8A8_UNORM) specular_fog = TRUE;
156 else FIXME("Implement fog coordinates from %s\n", debug_d3dformat(element->format->id));
164 /* TODO: Use the fog table code from old ddraw */
165 FIXME("Implement fog for transformed vertices in software\n");
171 else if (gl_info->supported[EXT_SECONDARY_COLOR])
173 GL_EXTCALL(glSecondaryColor3fEXT)(0, 0, 0);
176 for (textureNo = 0; textureNo < texture_stages; ++textureNo)
178 int coordIdx = state->texture_states[textureNo][WINED3D_TSS_TEXCOORD_INDEX];
179 DWORD texture_idx = device->texUnitMap[textureNo];
181 if (!gl_info->supported[ARB_MULTITEXTURE] && textureNo > 0)
183 FIXME("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
187 if (!pixelShader && !state->textures[textureNo]) continue;
189 if (texture_idx == WINED3D_UNMAPPED_STAGE) continue;
193 TRACE("tex: %d - Skip tex coords, as being system generated\n", textureNo);
196 else if (coordIdx < 0)
198 FIXME("tex: %d - Coord index %d is less than zero, expect a crash.\n", textureNo, coordIdx);
202 if (si->use_map & (1 << (WINED3D_FFP_TEXCOORD0 + coordIdx)))
204 element = &si->elements[WINED3D_FFP_TEXCOORD0 + coordIdx];
205 texCoords[coordIdx] = element->data.addr;
206 tex_mask |= (1 << textureNo);
210 TRACE("tex: %d - Skipping tex coords, as no data supplied\n", textureNo);
211 if (gl_info->supported[ARB_MULTITEXTURE])
212 GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB + texture_idx, 0, 0, 0, 1));
214 gl_info->gl_ops.gl.p_glTexCoord4f(0, 0, 0, 1);
218 /* We shouldn't start this function if any VBO is involved. Should I put a safety check here?
219 * Guess it's not necessary(we crash then anyway) and would only eat CPU time
222 /* For each primitive */
223 for (vx_index = 0; vx_index < NumVertexes; ++vx_index) {
224 UINT texture, tmp_tex_mask;
225 /* Blending data and Point sizes are not supported by this function. They are not supported by the fixed
226 * function pipeline at all. A Fixme for them is printed after decoding the vertex declaration
229 /* For indexed data, we need to go a few more strides in */
232 /* Indexed so work out the number of strides to skip */
234 SkipnStrides = pIdxBufS[startIdx + vx_index] + state->base_vertex_index;
236 SkipnStrides = pIdxBufL[startIdx + vx_index] + state->base_vertex_index;
239 tmp_tex_mask = tex_mask;
240 for (texture = 0; tmp_tex_mask; tmp_tex_mask >>= 1, ++texture)
246 if (!(tmp_tex_mask & 1)) continue;
248 coord_idx = state->texture_states[texture][WINED3D_TSS_TEXCOORD_INDEX];
249 ptr = texCoords[coord_idx] + (SkipnStrides * si->elements[WINED3D_FFP_TEXCOORD0 + coord_idx].stride);
251 texture_idx = device->texUnitMap[texture];
252 multi_texcoord_funcs[si->elements[WINED3D_FFP_TEXCOORD0 + coord_idx].format->emit_idx](
253 GL_TEXTURE0_ARB + texture_idx, ptr);
256 /* Diffuse -------------------------------- */
258 const void *ptrToCoords = diffuse + SkipnStrides * si->elements[WINED3D_FFP_DIFFUSE].stride;
260 diffuse_funcs[si->elements[WINED3D_FFP_DIFFUSE].format->emit_idx](ptrToCoords);
261 if (num_untracked_materials)
263 DWORD diffuseColor = ((const DWORD *)ptrToCoords)[0];
267 color[0] = D3DCOLOR_B_R(diffuseColor) / 255.0f;
268 color[1] = D3DCOLOR_B_G(diffuseColor) / 255.0f;
269 color[2] = D3DCOLOR_B_B(diffuseColor) / 255.0f;
270 color[3] = D3DCOLOR_B_A(diffuseColor) / 255.0f;
272 for (i = 0; i < num_untracked_materials; ++i)
274 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, context->untracked_materials[i], color);
279 /* Specular ------------------------------- */
281 const void *ptrToCoords = specular + SkipnStrides * si->elements[WINED3D_FFP_SPECULAR].stride;
283 specular_funcs[si->elements[WINED3D_FFP_SPECULAR].format->emit_idx](ptrToCoords);
287 DWORD specularColor = *(const DWORD *)ptrToCoords;
288 GL_EXTCALL(glFogCoordfEXT((float) (specularColor >> 24)));
292 /* Normal -------------------------------- */
295 const void *ptrToCoords = normal + SkipnStrides * si->elements[WINED3D_FFP_NORMAL].stride;
296 normal_funcs[si->elements[WINED3D_FFP_NORMAL].format->emit_idx](ptrToCoords);
299 /* Position -------------------------------- */
301 const void *ptrToCoords = position + SkipnStrides * si->elements[WINED3D_FFP_POSITION].stride;
302 position_funcs[si->elements[WINED3D_FFP_POSITION].format->emit_idx](ptrToCoords);
305 /* For non indexed mode, step onto next parts */
306 if (!idxData) ++SkipnStrides;
309 gl_info->gl_ops.gl.p_glEnd();
310 checkGLcall("glEnd and previous calls");
313 /* GL locking is done by the caller */
314 static inline void send_attribute(const struct wined3d_gl_info *gl_info,
315 enum wined3d_format_id format, const UINT index, const void *ptr)
319 case WINED3DFMT_R32_FLOAT:
320 GL_EXTCALL(glVertexAttrib1fvARB(index, ptr));
322 case WINED3DFMT_R32G32_FLOAT:
323 GL_EXTCALL(glVertexAttrib2fvARB(index, ptr));
325 case WINED3DFMT_R32G32B32_FLOAT:
326 GL_EXTCALL(glVertexAttrib3fvARB(index, ptr));
328 case WINED3DFMT_R32G32B32A32_FLOAT:
329 GL_EXTCALL(glVertexAttrib4fvARB(index, ptr));
332 case WINED3DFMT_R8G8B8A8_UINT:
333 GL_EXTCALL(glVertexAttrib4ubvARB(index, ptr));
335 case WINED3DFMT_B8G8R8A8_UNORM:
336 if (gl_info->supported[ARB_VERTEX_ARRAY_BGRA])
338 const DWORD *src = ptr;
339 DWORD c = *src & 0xff00ff00;
340 c |= (*src & 0xff0000) >> 16;
341 c |= (*src & 0xff) << 16;
342 GL_EXTCALL(glVertexAttrib4NubvARB(index, (GLubyte *)&c));
345 /* else fallthrough */
346 case WINED3DFMT_R8G8B8A8_UNORM:
347 GL_EXTCALL(glVertexAttrib4NubvARB(index, ptr));
350 case WINED3DFMT_R16G16_SINT:
351 GL_EXTCALL(glVertexAttrib4svARB(index, ptr));
353 case WINED3DFMT_R16G16B16A16_SINT:
354 GL_EXTCALL(glVertexAttrib4svARB(index, ptr));
357 case WINED3DFMT_R16G16_SNORM:
359 GLshort s[4] = {((const GLshort *)ptr)[0], ((const GLshort *)ptr)[1], 0, 1};
360 GL_EXTCALL(glVertexAttrib4NsvARB(index, s));
363 case WINED3DFMT_R16G16_UNORM:
365 GLushort s[4] = {((const GLushort *)ptr)[0], ((const GLushort *)ptr)[1], 0, 1};
366 GL_EXTCALL(glVertexAttrib4NusvARB(index, s));
369 case WINED3DFMT_R16G16B16A16_SNORM:
370 GL_EXTCALL(glVertexAttrib4NsvARB(index, ptr));
372 case WINED3DFMT_R16G16B16A16_UNORM:
373 GL_EXTCALL(glVertexAttrib4NusvARB(index, ptr));
376 case WINED3DFMT_R10G10B10A2_UINT:
377 FIXME("Unsure about WINED3DDECLTYPE_UDEC3\n");
378 /*glVertexAttrib3usvARB(instancedData[j], (GLushort *) ptr); Does not exist */
380 case WINED3DFMT_R10G10B10A2_SNORM:
381 FIXME("Unsure about WINED3DDECLTYPE_DEC3N\n");
382 /*glVertexAttrib3NusvARB(instancedData[j], (GLushort *) ptr); Does not exist */
385 case WINED3DFMT_R16G16_FLOAT:
386 /* Are those 16 bit floats. C doesn't have a 16 bit float type. I could read the single bits and calculate a 4
387 * byte float according to the IEEE standard
389 if (gl_info->supported[NV_HALF_FLOAT] && gl_info->supported[NV_VERTEX_PROGRAM])
391 /* Not supported by GL_ARB_half_float_vertex */
392 GL_EXTCALL(glVertexAttrib2hvNV(index, ptr));
396 float x = float_16_to_32(((const unsigned short *)ptr) + 0);
397 float y = float_16_to_32(((const unsigned short *)ptr) + 1);
398 GL_EXTCALL(glVertexAttrib2fARB(index, x, y));
401 case WINED3DFMT_R16G16B16A16_FLOAT:
402 if (gl_info->supported[NV_HALF_FLOAT] && gl_info->supported[NV_VERTEX_PROGRAM])
404 /* Not supported by GL_ARB_half_float_vertex */
405 GL_EXTCALL(glVertexAttrib4hvNV(index, ptr));
409 float x = float_16_to_32(((const unsigned short *)ptr) + 0);
410 float y = float_16_to_32(((const unsigned short *)ptr) + 1);
411 float z = float_16_to_32(((const unsigned short *)ptr) + 2);
412 float w = float_16_to_32(((const unsigned short *)ptr) + 3);
413 GL_EXTCALL(glVertexAttrib4fARB(index, x, y, z, w));
418 ERR("Unexpected attribute format: %s\n", debug_d3dformat(format));
423 /* GL locking is done by the caller */
424 static void drawStridedSlowVs(const struct wined3d_gl_info *gl_info, const struct wined3d_state *state,
425 const struct wined3d_stream_info *si, UINT numberOfVertices, GLenum glPrimitiveType,
426 const void *idxData, UINT idxSize, UINT startIdx)
428 LONG SkipnStrides = startIdx + state->load_base_vertex_index;
429 const DWORD *pIdxBufL = NULL;
430 const WORD *pIdxBufS = NULL;
437 /* Immediate mode drawing can't make use of indices in a vbo - get the
438 * data from the index buffer. If the index buffer has no vbo (not
439 * supported or other reason), or with user pointer drawing idxData
440 * will be non-NULL. */
442 idxData = buffer_get_sysmem(state->index_buffer, gl_info);
444 if (idxSize == 2) pIdxBufS = idxData;
445 else pIdxBufL = idxData;
446 } else if (idxData) {
447 ERR("non-NULL idxData with 0 idxSize, this should never happen\n");
451 /* Start drawing in GL */
452 gl_info->gl_ops.gl.p_glBegin(glPrimitiveType);
454 for (vx_index = 0; vx_index < numberOfVertices; ++vx_index)
458 /* Indexed so work out the number of strides to skip */
460 SkipnStrides = pIdxBufS[startIdx + vx_index] + state->load_base_vertex_index;
462 SkipnStrides = pIdxBufL[startIdx + vx_index] + state->load_base_vertex_index;
465 for (i = MAX_ATTRIBS - 1; i >= 0; i--)
467 if (!(si->use_map & (1 << i))) continue;
469 ptr = si->elements[i].data.addr + si->elements[i].stride * SkipnStrides;
471 send_attribute(gl_info, si->elements[i].format->id, i, ptr);
476 gl_info->gl_ops.gl.p_glEnd();
479 /* GL locking is done by the caller */
480 static void drawStridedInstanced(const struct wined3d_gl_info *gl_info, const struct wined3d_state *state,
481 const struct wined3d_stream_info *si, UINT numberOfVertices, GLenum glPrimitiveType,
482 const void *idxData, UINT idxSize, UINT startIdx, UINT base_vertex_index)
484 UINT numInstances = 0, i;
485 int numInstancedAttribs = 0, j;
486 UINT instancedData[sizeof(si->elements) / sizeof(*si->elements) /* 16 */];
487 GLenum idxtype = idxSize == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
491 /* This is a nasty thing. MSDN says no hardware supports that and apps have to use software vertex processing.
492 * We don't support this for now
494 * Shouldn't be too hard to support with opengl, in theory just call glDrawArrays instead of drawElements.
495 * But the StreamSourceFreq value has a different meaning in that situation.
497 FIXME("Non-indexed instanced drawing is not supported\n");
501 /* First, figure out how many instances we have to draw */
502 for (i = 0; i < MAX_STREAMS; ++i)
504 /* Look at the streams and take the first one which matches */
505 if (state->streams[i].buffer
506 && ((state->streams[i].flags & WINED3DSTREAMSOURCE_INSTANCEDATA)
507 || (state->streams[i].flags & WINED3DSTREAMSOURCE_INDEXEDDATA)))
509 /* Use the specified number of instances from the first matched
510 * stream. A streamFreq of 0 (with INSTANCEDATA or INDEXEDDATA)
511 * is handled as 1. See d3d9/tests/visual.c-> stream_test(). */
512 numInstances = state->streams[i].frequency ? state->streams[i].frequency : 1;
517 for (i = 0; i < sizeof(si->elements) / sizeof(*si->elements); ++i)
519 if (!(si->use_map & (1 << i))) continue;
521 if (state->streams[si->elements[i].stream_idx].flags & WINED3DSTREAMSOURCE_INSTANCEDATA)
523 instancedData[numInstancedAttribs] = i;
524 numInstancedAttribs++;
528 /* now draw numInstances instances :-) */
529 for(i = 0; i < numInstances; i++) {
530 /* Specify the instanced attributes using immediate mode calls */
531 for(j = 0; j < numInstancedAttribs; j++) {
532 const BYTE *ptr = si->elements[instancedData[j]].data.addr
533 + si->elements[instancedData[j]].stride * i;
534 if (si->elements[instancedData[j]].data.buffer_object)
536 struct wined3d_buffer *vb = state->streams[si->elements[instancedData[j]].stream_idx].buffer;
537 ptr += (ULONG_PTR)buffer_get_sysmem(vb, gl_info);
540 send_attribute(gl_info, si->elements[instancedData[j]].format->id, instancedData[j], ptr);
543 if (gl_info->supported[ARB_DRAW_ELEMENTS_BASE_VERTEX])
545 GL_EXTCALL(glDrawElementsBaseVertex(glPrimitiveType, numberOfVertices, idxtype,
546 (const char *)idxData+(idxSize * startIdx), base_vertex_index));
547 checkGLcall("glDrawElementsBaseVertex");
551 gl_info->gl_ops.gl.p_glDrawElements(glPrimitiveType, numberOfVertices, idxtype,
552 (const char *)idxData + (idxSize * startIdx));
553 checkGLcall("glDrawElements");
558 static void remove_vbos(const struct wined3d_gl_info *gl_info,
559 const struct wined3d_state *state, struct wined3d_stream_info *s)
563 for (i = 0; i < (sizeof(s->elements) / sizeof(*s->elements)); ++i)
565 struct wined3d_stream_info_element *e;
567 if (!(s->use_map & (1 << i))) continue;
570 if (e->data.buffer_object)
572 struct wined3d_buffer *vb = state->streams[e->stream_idx].buffer;
573 e->data.buffer_object = 0;
574 e->data.addr = (BYTE *)((ULONG_PTR)e->data.addr + (ULONG_PTR)buffer_get_sysmem(vb, gl_info));
579 /* Routine common to the draw primitive and draw indexed primitive routines */
580 void drawPrimitive(struct wined3d_device *device, UINT index_count, UINT StartIdx, BOOL indexed, const void *idxData)
582 const struct wined3d_state *state = &device->stateBlock->state;
583 struct wined3d_event_query *ib_query = NULL;
584 const struct wined3d_gl_info *gl_info;
585 struct wined3d_context *context;
588 if (!index_count) return;
590 if (state->render_states[WINED3D_RS_COLORWRITEENABLE])
592 /* Invalidate the back buffer memory so LockRect will read it the next time */
593 for (i = 0; i < device->adapter->gl_info.limits.buffers; ++i)
595 struct wined3d_surface *target = device->fb.render_targets[i];
598 surface_load_location(target, target->draw_binding, NULL);
599 surface_modify_location(target, target->draw_binding, TRUE);
604 /* Signals other modules that a drawing is in progress and the stateblock finalized */
605 device->isInDraw = TRUE;
607 context = context_acquire(device, device->fb.render_targets[0]);
610 context_release(context);
611 WARN("Invalid context, skipping draw.\n");
614 gl_info = context->gl_info;
616 if (device->fb.depth_stencil)
618 /* Note that this depends on the context_acquire() call above to set
619 * context->render_offscreen properly. We don't currently take the
620 * Z-compare function into account, but we could skip loading the
621 * depthstencil for D3DCMP_NEVER and D3DCMP_ALWAYS as well. Also note
622 * that we never copy the stencil data.*/
623 DWORD location = context->render_offscreen ? device->fb.depth_stencil->draw_binding : SFLAG_INDRAWABLE;
624 if (state->render_states[WINED3D_RS_ZWRITEENABLE] || state->render_states[WINED3D_RS_ZENABLE])
626 struct wined3d_surface *ds = device->fb.depth_stencil;
627 RECT current_rect, draw_rect, r;
629 if (!context->render_offscreen && ds != device->onscreen_depth_stencil)
630 device_switch_onscreen_ds(device, context, ds);
632 if (ds->flags & location)
633 SetRect(¤t_rect, 0, 0, ds->ds_current_size.cx, ds->ds_current_size.cy);
635 SetRectEmpty(¤t_rect);
637 wined3d_get_draw_rect(state, &draw_rect);
639 IntersectRect(&r, &draw_rect, ¤t_rect);
640 if (!EqualRect(&r, &draw_rect))
641 surface_load_ds_location(ds, context, location);
645 if (!context_apply_draw_state(context, device))
647 context_release(context);
648 WARN("Unable to apply draw state, skipping draw.\n");
652 if (device->fb.depth_stencil && state->render_states[WINED3D_RS_ZWRITEENABLE])
654 struct wined3d_surface *ds = device->fb.depth_stencil;
655 DWORD location = context->render_offscreen ? ds->draw_binding : SFLAG_INDRAWABLE;
657 surface_modify_ds_location(ds, location, ds->ds_current_size.cx, ds->ds_current_size.cy);
660 if ((!gl_info->supported[WINED3D_GL_VERSION_2_0]
661 || !gl_info->supported[NV_POINT_SPRITE])
662 && context->render_offscreen
663 && state->render_states[WINED3D_RS_POINTSPRITEENABLE]
664 && state->gl_primitive_type == GL_POINTS)
666 FIXME("Point sprite coordinate origin switching not supported.\n");
669 /* Ok, we will be updating the screen from here onwards so grab the lock */
672 GLenum glPrimType = state->gl_primitive_type;
673 INT base_vertex_index = state->base_vertex_index;
674 BOOL emulation = FALSE;
675 const struct wined3d_stream_info *stream_info = &device->strided_streams;
676 struct wined3d_stream_info stridedlcl;
681 if (!state->user_stream)
683 struct wined3d_buffer *index_buffer = state->index_buffer;
684 if (!index_buffer->buffer_object || !stream_info->all_vbo)
685 idxData = index_buffer->resource.allocatedMemory;
688 ib_query = index_buffer->query;
693 if (state->index_format == WINED3DFMT_R16_UINT)
701 if (!stream_info->position_transformed && context->num_untracked_materials
702 && state->render_states[WINED3D_RS_LIGHTING])
706 FIXME("Using software emulation because not all material properties could be tracked\n");
709 TRACE("Using software emulation because not all material properties could be tracked\n");
713 else if (context->fog_coord && state->render_states[WINED3D_RS_FOGENABLE])
715 /* Either write a pipeline replacement shader or convert the specular alpha from unsigned byte
716 * to a float in the vertex buffer
720 FIXME("Using software emulation because manual fog coordinates are provided\n");
723 TRACE("Using software emulation because manual fog coordinates are provided\n");
729 stream_info = &stridedlcl;
730 memcpy(&stridedlcl, &device->strided_streams, sizeof(stridedlcl));
731 remove_vbos(gl_info, state, &stridedlcl);
735 if (device->useDrawStridedSlow || emulation)
737 /* Immediate mode drawing */
742 FIXME("Using immediate mode with vertex shaders for half float emulation\n");
745 TRACE("Using immediate mode with vertex shaders for half float emulation\n");
747 drawStridedSlowVs(gl_info, state, stream_info,
748 index_count, glPrimType, idxData, idx_size, StartIdx);
752 drawStridedSlow(device, context, stream_info, index_count,
753 glPrimType, idxData, idx_size, StartIdx);
756 else if (device->instancedDraw)
758 /* Instancing emulation with mixing immediate mode and arrays */
759 drawStridedInstanced(gl_info, state, stream_info,
760 index_count, glPrimType, idxData, idx_size, StartIdx, base_vertex_index);
764 drawStridedFast(gl_info, glPrimType, index_count, idx_size, idxData, StartIdx, base_vertex_index);
768 /* Finished updating the screen, restore lock */
772 wined3d_event_query_issue(ib_query, device);
773 for (i = 0; i < device->num_buffer_queries; ++i)
775 wined3d_event_query_issue(device->buffer_queries[i], device);
778 if (wined3d_settings.strict_draw_ordering)
779 gl_info->gl_ops.gl.p_glFlush(); /* Flush to ensure ordering across contexts. */
781 context_release(context);
783 TRACE("Done all gl drawing\n");
785 /* Control goes back to the device, stateblock values may change again */
786 device->isInDraw = FALSE;
789 static void normalize_normal(float *n) {
790 float length = n[0] * n[0] + n[1] * n[1] + n[2] * n[2];
791 if (length == 0.0f) return;
792 length = sqrtf(length);
793 n[0] = n[0] / length;
794 n[1] = n[1] / length;
795 n[2] = n[2] / length;
798 /* Tesselates a high order rectangular patch into single triangles using gl evaluators
800 * The problem is that OpenGL does not offer a direct way to return the tesselated primitives,
801 * and they can't be sent off for rendering directly either. Tesselating is slow, so we want
802 * to cache the patches in a vertex buffer. But more importantly, gl can't bind generated
803 * attributes to numbered shader attributes, so we have to store them and rebind them as needed
806 * To read back, the opengl feedback mode is used. This creates a problem because we want
807 * untransformed, unlit vertices, but feedback runs everything through transform and lighting.
808 * Thus disable lighting and set identity matrices to get unmodified colors and positions.
809 * To overcome clipping find the biggest x, y and z values of the vertices in the patch and scale
810 * them to [-1.0;+1.0] and set the viewport up to scale them back.
812 * Normals are more tricky: Draw white vertices with 3 directional lights, and calculate the
813 * resulting colors back to the normals.
815 * NOTE: This function activates a context for blitting, modifies matrices & viewport, but
816 * does not restore it because normally a draw follows immediately afterwards. The caller is
817 * responsible of taking care that either the gl states are restored, or the context activated
818 * for drawing to reset the lastWasBlit flag.
820 HRESULT tesselate_rectpatch(struct wined3d_device *This, struct wined3d_rect_patch *patch)
822 unsigned int i, j, num_quads, out_vertex_size, buffer_size, d3d_out_vertex_size;
823 const struct wined3d_rect_patch_info *info = &patch->rect_patch_info;
824 float max_x = 0.0f, max_y = 0.0f, max_z = 0.0f, neg_z = 0.0f;
825 struct wined3d_state *state = &This->stateBlock->state;
826 struct wined3d_stream_info stream_info;
827 struct wined3d_stream_info_element *e;
828 const struct wined3d_gl_info *gl_info;
829 struct wined3d_context *context;
830 struct wined3d_shader *vs;
833 GLenum feedback_type;
836 /* Simply activate the context for blitting. This disables all the things we don't want and
837 * takes care of dirtifying. Dirtifying is preferred over pushing / popping, since drawing the
838 * patch (as opposed to normal draws) will most likely need different changes anyway. */
839 context = context_acquire(This, NULL);
840 gl_info = context->gl_info;
841 context_apply_blit_state(context, This);
843 /* First, locate the position data. This is provided in a vertex buffer in
844 * the stateblock. Beware of VBOs. */
845 vs = state->vertex_shader;
846 state->vertex_shader = NULL;
847 device_stream_info_from_declaration(This, &stream_info);
848 state->vertex_shader = vs;
850 e = &stream_info.elements[WINED3D_FFP_POSITION];
851 if (e->data.buffer_object)
853 struct wined3d_buffer *vb = state->streams[e->stream_idx].buffer;
854 e->data.addr = (BYTE *)((ULONG_PTR)e->data.addr + (ULONG_PTR)buffer_get_sysmem(vb, context->gl_info));
856 vtxStride = e->stride;
858 + vtxStride * info->stride * info->start_vertex_offset_height
859 + vtxStride * info->start_vertex_offset_width;
861 /* Not entirely sure about what happens with transformed vertices */
862 if (stream_info.position_transformed) FIXME("Transformed position in rectpatch generation\n");
864 if(vtxStride % sizeof(GLfloat)) {
865 /* glMap2f reads vertex sizes in GLfloats, the d3d stride is in bytes.
866 * I don't see how the stride could not be a multiple of 4, but make sure
869 ERR("Vertex stride is not a multiple of sizeof(GLfloat)\n");
871 if (info->basis != WINED3D_BASIS_BEZIER)
872 FIXME("Basis is %s, how to handle this?\n", debug_d3dbasis(info->basis));
873 if (info->degree != WINED3D_DEGREE_CUBIC)
874 FIXME("Degree is %s, how to handle this?\n", debug_d3ddegree(info->degree));
876 /* First, get the boundary cube of the input data */
877 for (j = 0; j < info->height; ++j)
879 for (i = 0; i < info->width; ++i)
881 const float *v = (const float *)(data + vtxStride * i + vtxStride * info->stride * j);
882 if(fabs(v[0]) > max_x) max_x = fabsf(v[0]);
883 if(fabs(v[1]) > max_y) max_y = fabsf(v[1]);
884 if(fabs(v[2]) > max_z) max_z = fabsf(v[2]);
885 if(v[2] < neg_z) neg_z = v[2];
889 /* This needs some improvements in the vertex decl code */
890 FIXME("Cannot find data to generate. Only generating position and normals\n");
891 patch->has_normals = TRUE;
892 patch->has_texcoords = FALSE;
896 gl_info->gl_ops.gl.p_glMatrixMode(GL_PROJECTION);
897 checkGLcall("glMatrixMode(GL_PROJECTION)");
898 gl_info->gl_ops.gl.p_glLoadIdentity();
899 checkGLcall("glLoadIdentity()");
900 gl_info->gl_ops.gl.p_glScalef(1.0f / (max_x), 1.0f / (max_y), max_z == 0.0f ? 1.0f : 1.0f / (2.0f * max_z));
901 gl_info->gl_ops.gl.p_glTranslatef(0.0f, 0.0f, 0.5f);
902 checkGLcall("glScalef");
903 gl_info->gl_ops.gl.p_glViewport(-max_x, -max_y, 2 * (max_x), 2 * (max_y));
904 checkGLcall("glViewport");
906 /* Some states to take care of. If we're in wireframe opengl will produce lines, and confuse
907 * our feedback buffer parser
909 gl_info->gl_ops.gl.p_glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
910 checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)");
911 context_invalidate_state(context, STATE_RENDER(WINED3D_RS_FILLMODE));
912 if (patch->has_normals)
914 static const GLfloat black[] = {0.0f, 0.0f, 0.0f, 0.0f};
915 static const GLfloat red[] = {1.0f, 0.0f, 0.0f, 0.0f};
916 static const GLfloat green[] = {0.0f, 1.0f, 0.0f, 0.0f};
917 static const GLfloat blue[] = {0.0f, 0.0f, 1.0f, 0.0f};
918 static const GLfloat white[] = {1.0f, 1.0f, 1.0f, 1.0f};
919 gl_info->gl_ops.gl.p_glEnable(GL_LIGHTING);
920 checkGLcall("glEnable(GL_LIGHTING)");
921 gl_info->gl_ops.gl.p_glLightModelfv(GL_LIGHT_MODEL_AMBIENT, black);
922 checkGLcall("glLightModel for MODEL_AMBIENT");
923 context_invalidate_state(context, STATE_RENDER(WINED3D_RS_AMBIENT));
925 for (i = 3; i < context->gl_info->limits.lights; ++i)
927 gl_info->gl_ops.gl.p_glDisable(GL_LIGHT0 + i);
928 checkGLcall("glDisable(GL_LIGHT0 + i)");
929 context_invalidate_state(context, STATE_ACTIVELIGHT(i));
932 context_invalidate_state(context, STATE_ACTIVELIGHT(0));
933 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0, GL_DIFFUSE, red);
934 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0, GL_SPECULAR, black);
935 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0, GL_AMBIENT, black);
936 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0, GL_POSITION, red);
937 gl_info->gl_ops.gl.p_glEnable(GL_LIGHT0);
938 checkGLcall("Setting up light 1");
939 context_invalidate_state(context, STATE_ACTIVELIGHT(1));
940 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT1, GL_DIFFUSE, green);
941 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT1, GL_SPECULAR, black);
942 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT1, GL_AMBIENT, black);
943 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT1, GL_POSITION, green);
944 gl_info->gl_ops.gl.p_glEnable(GL_LIGHT1);
945 checkGLcall("Setting up light 2");
946 context_invalidate_state(context, STATE_ACTIVELIGHT(2));
947 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT2, GL_DIFFUSE, blue);
948 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT2, GL_SPECULAR, black);
949 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT2, GL_AMBIENT, black);
950 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT2, GL_POSITION, blue);
951 gl_info->gl_ops.gl.p_glEnable(GL_LIGHT2);
952 checkGLcall("Setting up light 3");
954 context_invalidate_state(context, STATE_MATERIAL);
955 context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORVERTEX));
956 gl_info->gl_ops.gl.p_glDisable(GL_COLOR_MATERIAL);
957 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, black);
958 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black);
959 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, white);
960 checkGLcall("Setting up materials");
963 /* Enable the needed maps.
964 * GL_MAP2_VERTEX_3 is needed for positional data.
965 * GL_AUTO_NORMAL to generate normals from the position. Do not use GL_MAP2_NORMAL.
966 * GL_MAP2_TEXTURE_COORD_4 for texture coords
968 num_quads = ceilf(patch->numSegs[0]) * ceilf(patch->numSegs[1]);
969 out_vertex_size = 3 /* position */;
970 d3d_out_vertex_size = 3;
971 gl_info->gl_ops.gl.p_glEnable(GL_MAP2_VERTEX_3);
972 if (patch->has_normals && patch->has_texcoords)
974 FIXME("Texcoords not handled yet\n");
975 feedback_type = GL_3D_COLOR_TEXTURE;
976 out_vertex_size += 8;
977 d3d_out_vertex_size += 7;
978 gl_info->gl_ops.gl.p_glEnable(GL_AUTO_NORMAL);
979 gl_info->gl_ops.gl.p_glEnable(GL_MAP2_TEXTURE_COORD_4);
981 else if (patch->has_texcoords)
983 FIXME("Texcoords not handled yet\n");
984 feedback_type = GL_3D_COLOR_TEXTURE;
985 out_vertex_size += 7;
986 d3d_out_vertex_size += 4;
987 gl_info->gl_ops.gl.p_glEnable(GL_MAP2_TEXTURE_COORD_4);
989 else if (patch->has_normals)
991 feedback_type = GL_3D_COLOR;
992 out_vertex_size += 4;
993 d3d_out_vertex_size += 3;
994 gl_info->gl_ops.gl.p_glEnable(GL_AUTO_NORMAL);
998 feedback_type = GL_3D;
1000 checkGLcall("glEnable vertex attrib generation");
1002 buffer_size = num_quads * out_vertex_size * 2 /* triangle list */ * 3 /* verts per tri */
1003 + 4 * num_quads /* 2 triangle markers per quad + num verts in tri */;
1004 feedbuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, buffer_size * sizeof(float) * 8);
1006 gl_info->gl_ops.gl.p_glMap2f(GL_MAP2_VERTEX_3,
1007 0.0f, 1.0f, vtxStride / sizeof(float), info->width,
1008 0.0f, 1.0f, info->stride * vtxStride / sizeof(float), info->height,
1009 (const GLfloat *)data);
1010 checkGLcall("glMap2f");
1011 if (patch->has_texcoords)
1013 gl_info->gl_ops.gl.p_glMap2f(GL_MAP2_TEXTURE_COORD_4,
1014 0.0f, 1.0f, vtxStride / sizeof(float), info->width,
1015 0.0f, 1.0f, info->stride * vtxStride / sizeof(float), info->height,
1016 (const GLfloat *)data);
1017 checkGLcall("glMap2f");
1019 gl_info->gl_ops.gl.p_glMapGrid2f(ceilf(patch->numSegs[0]), 0.0f, 1.0f, ceilf(patch->numSegs[1]), 0.0f, 1.0f);
1020 checkGLcall("glMapGrid2f");
1022 gl_info->gl_ops.gl.p_glFeedbackBuffer(buffer_size * 2, feedback_type, feedbuffer);
1023 checkGLcall("glFeedbackBuffer");
1024 gl_info->gl_ops.gl.p_glRenderMode(GL_FEEDBACK);
1026 gl_info->gl_ops.gl.p_glEvalMesh2(GL_FILL, 0, ceilf(patch->numSegs[0]), 0, ceilf(patch->numSegs[1]));
1027 checkGLcall("glEvalMesh2");
1029 i = gl_info->gl_ops.gl.p_glRenderMode(GL_RENDER);
1033 ERR("Feedback failed. Expected %d elements back\n", buffer_size);
1034 HeapFree(GetProcessHeap(), 0, feedbuffer);
1035 context_release(context);
1036 return WINED3DERR_DRIVERINTERNALERROR;
1037 } else if(i != buffer_size) {
1039 ERR("Unexpected amount of elements returned. Expected %d, got %d\n", buffer_size, i);
1040 HeapFree(GetProcessHeap(), 0, feedbuffer);
1041 context_release(context);
1042 return WINED3DERR_DRIVERINTERNALERROR;
1044 TRACE("Got %d elements as expected\n", i);
1047 HeapFree(GetProcessHeap(), 0, patch->mem);
1048 patch->mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, num_quads * 6 * d3d_out_vertex_size * sizeof(float) * 8);
1050 for(j = 0; j < buffer_size; j += (3 /* num verts */ * out_vertex_size + 2 /* tri marker */)) {
1051 if(feedbuffer[j] != GL_POLYGON_TOKEN) {
1052 ERR("Unexpected token: %f\n", feedbuffer[j]);
1055 if(feedbuffer[j + 1] != 3) {
1056 ERR("Unexpected polygon: %f corners\n", feedbuffer[j + 1]);
1059 /* Somehow there are different ideas about back / front facing, so fix up the
1062 patch->mem[i + 0] = feedbuffer[j + out_vertex_size * 2 + 2]; /* x, triangle 2 */
1063 patch->mem[i + 1] = feedbuffer[j + out_vertex_size * 2 + 3]; /* y, triangle 2 */
1064 patch->mem[i + 2] = (feedbuffer[j + out_vertex_size * 2 + 4] - 0.5f) * 4.0f * max_z; /* z, triangle 3 */
1065 if(patch->has_normals) {
1066 patch->mem[i + 3] = feedbuffer[j + out_vertex_size * 2 + 5];
1067 patch->mem[i + 4] = feedbuffer[j + out_vertex_size * 2 + 6];
1068 patch->mem[i + 5] = feedbuffer[j + out_vertex_size * 2 + 7];
1070 i += d3d_out_vertex_size;
1072 patch->mem[i + 0] = feedbuffer[j + out_vertex_size * 1 + 2]; /* x, triangle 2 */
1073 patch->mem[i + 1] = feedbuffer[j + out_vertex_size * 1 + 3]; /* y, triangle 2 */
1074 patch->mem[i + 2] = (feedbuffer[j + out_vertex_size * 1 + 4] - 0.5f) * 4.0f * max_z; /* z, triangle 2 */
1075 if(patch->has_normals) {
1076 patch->mem[i + 3] = feedbuffer[j + out_vertex_size * 1 + 5];
1077 patch->mem[i + 4] = feedbuffer[j + out_vertex_size * 1 + 6];
1078 patch->mem[i + 5] = feedbuffer[j + out_vertex_size * 1 + 7];
1080 i += d3d_out_vertex_size;
1082 patch->mem[i + 0] = feedbuffer[j + out_vertex_size * 0 + 2]; /* x, triangle 1 */
1083 patch->mem[i + 1] = feedbuffer[j + out_vertex_size * 0 + 3]; /* y, triangle 1 */
1084 patch->mem[i + 2] = (feedbuffer[j + out_vertex_size * 0 + 4] - 0.5f) * 4.0f * max_z; /* z, triangle 1 */
1085 if(patch->has_normals) {
1086 patch->mem[i + 3] = feedbuffer[j + out_vertex_size * 0 + 5];
1087 patch->mem[i + 4] = feedbuffer[j + out_vertex_size * 0 + 6];
1088 patch->mem[i + 5] = feedbuffer[j + out_vertex_size * 0 + 7];
1090 i += d3d_out_vertex_size;
1093 if(patch->has_normals) {
1094 /* Now do the same with reverse light directions */
1095 static const GLfloat x[] = {-1.0f, 0.0f, 0.0f, 0.0f};
1096 static const GLfloat y[] = { 0.0f, -1.0f, 0.0f, 0.0f};
1097 static const GLfloat z[] = { 0.0f, 0.0f, -1.0f, 0.0f};
1098 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0, GL_POSITION, x);
1099 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT1, GL_POSITION, y);
1100 gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT2, GL_POSITION, z);
1101 checkGLcall("Setting up reverse light directions");
1103 gl_info->gl_ops.gl.p_glRenderMode(GL_FEEDBACK);
1104 checkGLcall("glRenderMode(GL_FEEDBACK)");
1105 gl_info->gl_ops.gl.p_glEvalMesh2(GL_FILL, 0, ceilf(patch->numSegs[0]), 0, ceilf(patch->numSegs[1]));
1106 checkGLcall("glEvalMesh2");
1107 i = gl_info->gl_ops.gl.p_glRenderMode(GL_RENDER);
1108 checkGLcall("glRenderMode(GL_RENDER)");
1111 for(j = 0; j < buffer_size; j += (3 /* num verts */ * out_vertex_size + 2 /* tri marker */)) {
1112 if(feedbuffer[j] != GL_POLYGON_TOKEN) {
1113 ERR("Unexpected token: %f\n", feedbuffer[j]);
1116 if(feedbuffer[j + 1] != 3) {
1117 ERR("Unexpected polygon: %f corners\n", feedbuffer[j + 1]);
1120 if(patch->mem[i + 3] == 0.0f)
1121 patch->mem[i + 3] = -feedbuffer[j + out_vertex_size * 2 + 5];
1122 if(patch->mem[i + 4] == 0.0f)
1123 patch->mem[i + 4] = -feedbuffer[j + out_vertex_size * 2 + 6];
1124 if(patch->mem[i + 5] == 0.0f)
1125 patch->mem[i + 5] = -feedbuffer[j + out_vertex_size * 2 + 7];
1126 normalize_normal(patch->mem + i + 3);
1127 i += d3d_out_vertex_size;
1129 if(patch->mem[i + 3] == 0.0f)
1130 patch->mem[i + 3] = -feedbuffer[j + out_vertex_size * 1 + 5];
1131 if(patch->mem[i + 4] == 0.0f)
1132 patch->mem[i + 4] = -feedbuffer[j + out_vertex_size * 1 + 6];
1133 if(patch->mem[i + 5] == 0.0f)
1134 patch->mem[i + 5] = -feedbuffer[j + out_vertex_size * 1 + 7];
1135 normalize_normal(patch->mem + i + 3);
1136 i += d3d_out_vertex_size;
1138 if(patch->mem[i + 3] == 0.0f)
1139 patch->mem[i + 3] = -feedbuffer[j + out_vertex_size * 0 + 5];
1140 if(patch->mem[i + 4] == 0.0f)
1141 patch->mem[i + 4] = -feedbuffer[j + out_vertex_size * 0 + 6];
1142 if(patch->mem[i + 5] == 0.0f)
1143 patch->mem[i + 5] = -feedbuffer[j + out_vertex_size * 0 + 7];
1144 normalize_normal(patch->mem + i + 3);
1145 i += d3d_out_vertex_size;
1149 gl_info->gl_ops.gl.p_glDisable(GL_MAP2_VERTEX_3);
1150 gl_info->gl_ops.gl.p_glDisable(GL_AUTO_NORMAL);
1151 gl_info->gl_ops.gl.p_glDisable(GL_MAP2_NORMAL);
1152 gl_info->gl_ops.gl.p_glDisable(GL_MAP2_TEXTURE_COORD_4);
1153 checkGLcall("glDisable vertex attrib generation");
1156 context_release(context);
1158 HeapFree(GetProcessHeap(), 0, feedbuffer);
1160 vtxStride = 3 * sizeof(float);
1161 if(patch->has_normals) {
1162 vtxStride += 3 * sizeof(float);
1164 if(patch->has_texcoords) {
1165 vtxStride += 4 * sizeof(float);
1167 memset(&patch->strided, 0, sizeof(patch->strided));
1168 patch->strided.position.format = WINED3DFMT_R32G32B32_FLOAT;
1169 patch->strided.position.data = (BYTE *)patch->mem;
1170 patch->strided.position.stride = vtxStride;
1172 if (patch->has_normals)
1174 patch->strided.normal.format = WINED3DFMT_R32G32B32_FLOAT;
1175 patch->strided.normal.data = (BYTE *)patch->mem + 3 * sizeof(float) /* pos */;
1176 patch->strided.normal.stride = vtxStride;
1178 if (patch->has_texcoords)
1180 patch->strided.tex_coords[0].format = WINED3DFMT_R32G32B32A32_FLOAT;
1181 patch->strided.tex_coords[0].data = (BYTE *)patch->mem + 3 * sizeof(float) /* pos */;
1182 if (patch->has_normals)
1183 patch->strided.tex_coords[0].data += 3 * sizeof(float);
1184 patch->strided.tex_coords[0].stride = vtxStride;