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
27 #include "wined3d_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(d3d_draw
);
30 #define GLINFO_LOCATION This->adapter->gl_info
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
;
44 TRACE("(%p) : glElements(%x, %d, %d, ...)\n", This
, primitive_type
, count
, min_vertex_idx
);
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");
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");
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
;
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
;
91 TRACE("Using slow vertex array code\n");
93 /* Variable Initialization */
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
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");
110 /* Start drawing in GL */
111 VTRACE(("glBegin(%x)\n", 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
];
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
));
149 /* TODO: Use the fog table code from old ddraw */
150 FIXME("Implement fog for transformed vertices in software\n");
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");
172 if (!pixelShader
&& !This
->stateBlock
->textures
[textureNo
]) continue;
174 if (texture_idx
== -1) continue;
178 TRACE("tex: %d - Skip tex coords, as being system generated\n", textureNo
);
181 else if (coordIdx
< 0)
183 FIXME("tex: %d - Coord index %d is less than zero, expect a crash.\n", textureNo
, coordIdx
);
187 element
= &si
->elements
[WINED3D_FFP_TEXCOORD0
+ coordIdx
];
190 texCoords
[coordIdx
] = element
->data
+ streamOffset
[element
->stream_idx
];
191 tex_mask
|= (1 << textureNo
);
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));
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 */
219 VTRACE(("Idx for vertex %u = %u\n", vx_index
, pIdxBufS
[startIdx
+vx_index
]));
220 SkipnStrides
= pIdxBufS
[startIdx
+ vx_index
] + This
->stateBlock
->loadBaseVertexIndex
;
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
)
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 -------------------------------- */
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];
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 ------------------------------- */
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
);
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 -------------------------------- */
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
) {
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
)
305 case WINED3DFMT_R32_FLOAT
:
306 GL_EXTCALL(glVertexAttrib1fvARB(index
, ptr
));
308 case WINED3DFMT_R32G32_FLOAT
:
309 GL_EXTCALL(glVertexAttrib2fvARB(index
, ptr
));
311 case WINED3DFMT_R32G32B32_FLOAT
:
312 GL_EXTCALL(glVertexAttrib3fvARB(index
, ptr
));
314 case WINED3DFMT_R32G32B32A32_FLOAT
:
315 GL_EXTCALL(glVertexAttrib4fvARB(index
, ptr
));
318 case WINED3DFMT_R8G8B8A8_UINT
:
319 GL_EXTCALL(glVertexAttrib4ubvARB(index
, ptr
));
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
));
331 /* else fallthrough */
332 case WINED3DFMT_R8G8B8A8_UNORM
:
333 GL_EXTCALL(glVertexAttrib4NubvARB(index
, ptr
));
336 case WINED3DFMT_R16G16_SINT
:
337 GL_EXTCALL(glVertexAttrib4svARB(index
, ptr
));
339 case WINED3DFMT_R16G16B16A16_SINT
:
340 GL_EXTCALL(glVertexAttrib4svARB(index
, ptr
));
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
));
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
));
355 case WINED3DFMT_R16G16B16A16_SNORM
:
356 GL_EXTCALL(glVertexAttrib4NsvARB(index
, ptr
));
358 case WINED3DFMT_R16G16B16A16_UNORM
:
359 GL_EXTCALL(glVertexAttrib4NusvARB(index
, ptr
));
362 case WINED3DFMT_R10G10B10A2_UINT
:
363 FIXME("Unsure about WINED3DDECLTYPE_UDEC3\n");
364 /*glVertexAttrib3usvARB(instancedData[j], (GLushort *) ptr); Does not exist */
366 case WINED3DFMT_R10G10B10A2_SNORM
:
367 FIXME("Unsure about WINED3DDECLTYPE_DEC3N\n");
368 /*glVertexAttrib3NusvARB(instancedData[j], (GLushort *) ptr); Does not exist */
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
));
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
));
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
));
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
));
398 ERR("Unexpected attribute format: %s\n", debug_d3dformat(format
));
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
;
413 IWineD3DStateBlockImpl
*stateblock
= This
->stateBlock
;
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");
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 */
441 VTRACE(("Idx for vertex %d = %d\n", vx_index
, pIdxBufS
[startIdx
+vx_index
]));
442 SkipnStrides
= pIdxBufS
[startIdx
+ vx_index
] + stateblock
->loadBaseVertexIndex
;
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
);
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
,
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
;
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");
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){
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
)
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
;
559 if (!index_count
) return;
561 /* Invalidate the back buffer memory so LockRect will read it the next time */
562 for(i
= 0; i
< GL_LIMITS(buffers
); i
++) {
563 target
= (IWineD3DSurfaceImpl
*) This
->render_targets
[i
];
565 IWineD3DSurface_LoadLocation((IWineD3DSurface
*) target
, SFLAG_INDRAWABLE
, NULL
);
566 IWineD3DSurface_ModifyLocation((IWineD3DSurface
*) target
, SFLAG_INDRAWABLE
, TRUE
);
570 /* Signals other modules that a drawing is in progress and the stateblock finalized */
571 This
->isInDraw
= TRUE
;
573 ActivateContext(This
, This
->render_targets
[0], CTXUSAGE_DRAWPRIM
);
575 if (This
->stencilBufferTarget
) {
576 /* Note that this depends on the ActivateContext call above to set
577 * This->render_offscreen properly */
578 DWORD location
= This
->render_offscreen
? SFLAG_DS_OFFSCREEN
: SFLAG_DS_ONSCREEN
;
579 surface_load_ds_location(This
->stencilBufferTarget
, location
);
580 surface_modify_ds_location(This
->stencilBufferTarget
, location
);
583 /* Ok, we will be updating the screen from here onwards so grab the lock */
586 GLenum glPrimType
= This
->stateBlock
->gl_primitive_type
;
587 BOOL emulation
= FALSE
;
588 const struct wined3d_stream_info
*stream_info
= &This
->strided_streams
;
589 struct wined3d_stream_info stridedlcl
;
591 if (!numberOfVertices
) numberOfVertices
= index_count
;
593 if (!use_vs(This
->stateBlock
))
595 if (!This
->strided_streams
.position_transformed
&& This
->activeContext
->num_untracked_materials
596 && This
->stateBlock
->renderState
[WINED3DRS_LIGHTING
])
600 FIXME("Using software emulation because not all material properties could be tracked\n");
603 TRACE("Using software emulation because not all material properties could be tracked\n");
607 else if(This
->activeContext
->fog_coord
&& This
->stateBlock
->renderState
[WINED3DRS_FOGENABLE
]) {
608 /* Either write a pipeline replacement shader or convert the specular alpha from unsigned byte
609 * to a float in the vertex buffer
613 FIXME("Using software emulation because manual fog coordinates are provided\n");
616 TRACE("Using software emulation because manual fog coordinates are provided\n");
622 stream_info
= &stridedlcl
;
623 memcpy(&stridedlcl
, &This
->strided_streams
, sizeof(stridedlcl
));
624 remove_vbos(This
, &stridedlcl
);
628 if (This
->useDrawStridedSlow
|| emulation
) {
629 /* Immediate mode drawing */
630 if (use_vs(This
->stateBlock
))
634 FIXME("Using immediate mode with vertex shaders for half float emulation\n");
637 TRACE("Using immediate mode with vertex shaders for half float emulation\n");
639 drawStridedSlowVs(iface
, stream_info
, index_count
, glPrimType
, idxData
, idxSize
, minIndex
, StartIdx
);
641 drawStridedSlow(iface
, stream_info
, index_count
, glPrimType
, idxData
, idxSize
, minIndex
, StartIdx
);
643 } else if(This
->instancedDraw
) {
644 /* Instancing emulation with mixing immediate mode and arrays */
645 drawStridedInstanced(iface
, &This
->strided_streams
, index_count
,
646 glPrimType
, idxData
, idxSize
, minIndex
, StartIdx
);
648 drawStridedFast(iface
, glPrimType
, minIndex
, minIndex
+ numberOfVertices
- 1,
649 index_count
, idxSize
, idxData
, StartIdx
);
653 /* Finished updating the screen, restore lock */
655 TRACE("Done all gl drawing\n");
658 #ifdef SHOW_FRAME_MAKEUP
660 static long int primCounter
= 0;
661 /* NOTE: set primCounter to the value reported by drawprim
662 before you want to to write frame makeup to /tmp */
663 if (primCounter
>= 0) {
664 WINED3DLOCKED_RECT r
;
666 IWineD3DSurface_LockRect(This
->render_targets
[0], &r
, NULL
, WINED3DLOCK_READONLY
);
667 sprintf(buffer
, "/tmp/backbuffer_%ld.tga", primCounter
);
668 TRACE("Saving screenshot %s\n", buffer
);
669 IWineD3DSurface_SaveSnapshot(This
->render_targets
[0], buffer
);
670 IWineD3DSurface_UnlockRect(This
->render_targets
[0]);
672 #ifdef SHOW_TEXTURE_MAKEUP
674 IWineD3DSurface
*pSur
;
676 for (textureNo
= 0; textureNo
< MAX_COMBINED_SAMPLERS
; ++textureNo
) {
677 if (This
->stateBlock
->textures
[textureNo
] != NULL
) {
678 sprintf(buffer
, "/tmp/texture_%p_%ld_%d.tga", This
->stateBlock
->textures
[textureNo
], primCounter
, textureNo
);
679 TRACE("Saving texture %s\n", buffer
);
680 if (IWineD3DBaseTexture_GetType(This
->stateBlock
->textures
[textureNo
]) == WINED3DRTYPE_TEXTURE
) {
681 IWineD3DTexture_GetSurfaceLevel(This
->stateBlock
->textures
[textureNo
], 0, &pSur
);
682 IWineD3DSurface_SaveSnapshot(pSur
, buffer
);
683 IWineD3DSurface_Release(pSur
);
685 FIXME("base Texture isn't of type texture %d\n", IWineD3DBaseTexture_GetType(This
->stateBlock
->textures
[textureNo
]));
692 TRACE("drawprim #%ld\n", primCounter
);
697 /* Control goes back to the device, stateblock values may change again */
698 This
->isInDraw
= FALSE
;
701 static void normalize_normal(float *n
) {
702 float length
= n
[0] * n
[0] + n
[1] * n
[1] + n
[2] * n
[2];
703 if(length
== 0.0) return;
704 length
= sqrt(length
);
705 n
[0] = n
[0] / length
;
706 n
[1] = n
[1] / length
;
707 n
[2] = n
[2] / length
;
710 /* Tesselates a high order rectangular patch into single triangles using gl evaluators
712 * The problem is that OpenGL does not offer a direct way to return the tesselated primitives,
713 * and they can't be sent off for rendering directly either. Tesselating is slow, so we want
714 * to cache the patches in a vertex buffer. But more importantly, gl can't bind generated
715 * attributes to numbered shader attributes, so we have to store them and rebind them as needed
718 * To read back, the opengl feedback mode is used. This creates a problem because we want
719 * untransformed, unlit vertices, but feedback runs everything through transform and lighting.
720 * Thus disable lighting and set identity matrices to get unmodified colors and positions.
721 * To overcome clipping find the biggest x, y and z values of the vertices in the patch and scale
722 * them to [-1.0;+1.0] and set the viewport up to scale them back.
724 * Normals are more tricky: Draw white vertices with 3 directional lights, and calculate the
725 * resulting colors back to the normals.
727 * NOTE: This function activates a context for blitting, modifies matrices & viewport, but
728 * does not restore it because normally a draw follows immediately afterwards. The caller is
729 * responsible of taking care that either the gl states are restored, or the context activated
730 * for drawing to reset the lastWasBlit flag.
732 HRESULT
tesselate_rectpatch(IWineD3DDeviceImpl
*This
,
733 struct WineD3DRectPatch
*patch
) {
734 unsigned int i
, j
, num_quads
, out_vertex_size
, buffer_size
, d3d_out_vertex_size
;
735 float max_x
= 0.0, max_y
= 0.0, max_z
= 0.0, neg_z
= 0.0;
736 struct wined3d_stream_info stream_info
;
737 struct wined3d_stream_info_element
*e
;
739 const WINED3DRECTPATCH_INFO
*info
= &patch
->RectPatchInfo
;
741 GLenum feedback_type
;
744 /* First, locate the position data. This is provided in a vertex buffer in the stateblock.
747 device_stream_info_from_declaration(This
, FALSE
, &stream_info
, NULL
);
749 e
= &stream_info
.elements
[WINED3D_FFP_POSITION
];
750 if (e
->buffer_object
)
752 struct wined3d_buffer
*vb
;
753 vb
= (struct wined3d_buffer
*)This
->stateBlock
->streamSource
[e
->stream_idx
];
754 e
->data
= (BYTE
*)((unsigned long)e
->data
+ (unsigned long)buffer_get_sysmem(vb
));
756 vtxStride
= e
->stride
;
758 vtxStride
* info
->Stride
* info
->StartVertexOffsetHeight
+
759 vtxStride
* info
->StartVertexOffsetWidth
;
761 /* Not entirely sure about what happens with transformed vertices */
762 if (stream_info
.position_transformed
) FIXME("Transformed position in rectpatch generation\n");
764 if(vtxStride
% sizeof(GLfloat
)) {
765 /* glMap2f reads vertex sizes in GLfloats, the d3d stride is in bytes.
766 * I don't see how the stride could not be a multiple of 4, but make sure
769 ERR("Vertex stride is not a multiple of sizeof(GLfloat)\n");
771 if(info
->Basis
!= WINED3DBASIS_BEZIER
) {
772 FIXME("Basis is %s, how to handle this?\n", debug_d3dbasis(info
->Basis
));
774 if(info
->Degree
!= WINED3DDEGREE_CUBIC
) {
775 FIXME("Degree is %s, how to handle this?\n", debug_d3ddegree(info
->Degree
));
778 /* First, get the boundary cube of the input data */
779 for(j
= 0; j
< info
->Height
; j
++) {
780 for(i
= 0; i
< info
->Width
; i
++) {
781 const float *v
= (const float *)(data
+ vtxStride
* i
+ vtxStride
* info
->Stride
* j
);
782 if(fabs(v
[0]) > max_x
) max_x
= fabs(v
[0]);
783 if(fabs(v
[1]) > max_y
) max_y
= fabs(v
[1]);
784 if(fabs(v
[2]) > max_z
) max_z
= fabs(v
[2]);
785 if(v
[2] < neg_z
) neg_z
= v
[2];
789 /* This needs some improvements in the vertex decl code */
790 FIXME("Cannot find data to generate. Only generating position and normals\n");
791 patch
->has_normals
= TRUE
;
792 patch
->has_texcoords
= FALSE
;
794 /* Simply activate the context for blitting. This disables all the things we don't want and
795 * takes care of dirtifying. Dirtifying is preferred over pushing / popping, since drawing the
796 * patch (as opposed to normal draws) will most likely need different changes anyway
798 ActivateContext(This
, This
->lastActiveRenderTarget
, CTXUSAGE_BLIT
);
801 glMatrixMode(GL_PROJECTION
);
802 checkGLcall("glMatrixMode(GL_PROJECTION)");
804 checkGLcall("glLoadIndentity()");
805 glScalef(1 / (max_x
) , 1 / (max_y
), max_z
== 0 ? 1 : 1 / ( 2 * max_z
));
806 glTranslatef(0, 0, 0.5);
807 checkGLcall("glScalef");
808 glViewport(-max_x
, -max_y
, 2 * (max_x
), 2 * (max_y
));
809 checkGLcall("glViewport");
811 /* Some states to take care of. If we're in wireframe opengl will produce lines, and confuse
812 * our feedback buffer parser
814 glPolygonMode(GL_FRONT_AND_BACK
, GL_FILL
);
815 checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)");
816 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_RENDER(WINED3DRS_FILLMODE
));
817 if(patch
->has_normals
) {
818 static const GLfloat black
[] = {0, 0, 0, 0};
819 static const GLfloat red
[] = {1, 0, 0, 0};
820 static const GLfloat green
[] = {0, 1, 0, 0};
821 static const GLfloat blue
[] = {0, 0, 1, 0};
822 static const GLfloat white
[] = {1, 1, 1, 1};
823 glEnable(GL_LIGHTING
);
824 checkGLcall("glEnable(GL_LIGHTING)");
825 glLightModelfv(GL_LIGHT_MODEL_AMBIENT
, black
);
826 checkGLcall("glLightModel for MODEL_AMBIENT");
827 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_RENDER(WINED3DRS_AMBIENT
));
829 for(i
= 3; i
< GL_LIMITS(lights
); i
++) {
830 glDisable(GL_LIGHT0
+ i
);
831 checkGLcall("glDisable(GL_LIGHT0 + i)");
832 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_ACTIVELIGHT(i
));
835 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_ACTIVELIGHT(0));
836 glLightfv(GL_LIGHT0
, GL_DIFFUSE
, red
);
837 glLightfv(GL_LIGHT0
, GL_SPECULAR
, black
);
838 glLightfv(GL_LIGHT0
, GL_AMBIENT
, black
);
839 glLightfv(GL_LIGHT0
, GL_POSITION
, red
);
841 checkGLcall("Setting up light 1\n");
842 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_ACTIVELIGHT(1));
843 glLightfv(GL_LIGHT1
, GL_DIFFUSE
, green
);
844 glLightfv(GL_LIGHT1
, GL_SPECULAR
, black
);
845 glLightfv(GL_LIGHT1
, GL_AMBIENT
, black
);
846 glLightfv(GL_LIGHT1
, GL_POSITION
, green
);
848 checkGLcall("Setting up light 2\n");
849 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_ACTIVELIGHT(2));
850 glLightfv(GL_LIGHT2
, GL_DIFFUSE
, blue
);
851 glLightfv(GL_LIGHT2
, GL_SPECULAR
, black
);
852 glLightfv(GL_LIGHT2
, GL_AMBIENT
, black
);
853 glLightfv(GL_LIGHT2
, GL_POSITION
, blue
);
855 checkGLcall("Setting up light 3\n");
857 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_MATERIAL
);
858 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_RENDER(WINED3DRS_COLORVERTEX
));
859 glDisable(GL_COLOR_MATERIAL
);
860 glMaterialfv(GL_FRONT_AND_BACK
, GL_EMISSION
, black
);
861 glMaterialfv(GL_FRONT_AND_BACK
, GL_SPECULAR
, black
);
862 glMaterialfv(GL_FRONT_AND_BACK
, GL_DIFFUSE
, white
);
863 checkGLcall("Setting up materials\n");
866 /* Enable the needed maps.
867 * GL_MAP2_VERTEX_3 is needed for positional data.
868 * GL_AUTO_NORMAL to generate normals from the position. Do not use GL_MAP2_NORMAL.
869 * GL_MAP2_TEXTURE_COORD_4 for texture coords
871 num_quads
= ceilf(patch
->numSegs
[0]) * ceilf(patch
->numSegs
[1]);
872 out_vertex_size
= 3 /* position */;
873 d3d_out_vertex_size
= 3;
874 glEnable(GL_MAP2_VERTEX_3
);
875 if(patch
->has_normals
&& patch
->has_texcoords
) {
876 FIXME("Texcoords not handled yet\n");
877 feedback_type
= GL_3D_COLOR_TEXTURE
;
878 out_vertex_size
+= 8;
879 d3d_out_vertex_size
+= 7;
880 glEnable(GL_AUTO_NORMAL
);
881 glEnable(GL_MAP2_TEXTURE_COORD_4
);
882 } else if(patch
->has_texcoords
) {
883 FIXME("Texcoords not handled yet\n");
884 feedback_type
= GL_3D_COLOR_TEXTURE
;
885 out_vertex_size
+= 7;
886 d3d_out_vertex_size
+= 4;
887 glEnable(GL_MAP2_TEXTURE_COORD_4
);
888 } else if(patch
->has_normals
) {
889 feedback_type
= GL_3D_COLOR
;
890 out_vertex_size
+= 4;
891 d3d_out_vertex_size
+= 3;
892 glEnable(GL_AUTO_NORMAL
);
894 feedback_type
= GL_3D
;
896 checkGLcall("glEnable vertex attrib generation");
898 buffer_size
= num_quads
* out_vertex_size
* 2 /* triangle list */ * 3 /* verts per tri */
899 + 4 * num_quads
/* 2 triangle markers per quad + num verts in tri */;
900 feedbuffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, buffer_size
* sizeof(float) * 8);
902 glMap2f(GL_MAP2_VERTEX_3
,
903 0, 1, vtxStride
/ sizeof(float), info
->Width
,
904 0, 1, info
->Stride
* vtxStride
/ sizeof(float), info
->Height
,
905 (const GLfloat
*)data
);
906 checkGLcall("glMap2f");
907 if(patch
->has_texcoords
) {
908 glMap2f(GL_MAP2_TEXTURE_COORD_4
,
909 0, 1, vtxStride
/ sizeof(float), info
->Width
,
910 0, 1, info
->Stride
* vtxStride
/ sizeof(float), info
->Height
,
911 (const GLfloat
*)data
);
912 checkGLcall("glMap2f");
914 glMapGrid2f(ceilf(patch
->numSegs
[0]), 0.0, 1.0, ceilf(patch
->numSegs
[1]), 0.0, 1.0);
915 checkGLcall("glMapGrid2f");
917 glFeedbackBuffer(buffer_size
* 2, feedback_type
, feedbuffer
);
918 checkGLcall("glFeedbackBuffer");
919 glRenderMode(GL_FEEDBACK
);
921 glEvalMesh2(GL_FILL
, 0, ceilf(patch
->numSegs
[0]), 0, ceilf(patch
->numSegs
[1]));
922 checkGLcall("glEvalMesh2\n");
924 i
= glRenderMode(GL_RENDER
);
927 ERR("Feedback failed. Expected %d elements back\n", buffer_size
);
929 HeapFree(GetProcessHeap(), 0, feedbuffer
);
930 return WINED3DERR_DRIVERINTERNALERROR
;
931 } else if(i
!= buffer_size
) {
933 ERR("Unexpected amount of elements returned. Expected %d, got %d\n", buffer_size
, i
);
935 HeapFree(GetProcessHeap(), 0, feedbuffer
);
936 return WINED3DERR_DRIVERINTERNALERROR
;
938 TRACE("Got %d elements as expected\n", i
);
941 HeapFree(GetProcessHeap(), 0, patch
->mem
);
942 patch
->mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, num_quads
* 6 * d3d_out_vertex_size
* sizeof(float) * 8);
944 for(j
= 0; j
< buffer_size
; j
+= (3 /* num verts */ * out_vertex_size
+ 2 /* tri marker */)) {
945 if(feedbuffer
[j
] != GL_POLYGON_TOKEN
) {
946 ERR("Unexpected token: %f\n", feedbuffer
[j
]);
949 if(feedbuffer
[j
+ 1] != 3) {
950 ERR("Unexpected polygon: %f corners\n", feedbuffer
[j
+ 1]);
953 /* Somehow there are different ideas about back / front facing, so fix up the
956 patch
->mem
[i
+ 0] = feedbuffer
[j
+ out_vertex_size
* 2 + 2]; /* x, triangle 2 */
957 patch
->mem
[i
+ 1] = feedbuffer
[j
+ out_vertex_size
* 2 + 3]; /* y, triangle 2 */
958 patch
->mem
[i
+ 2] = (feedbuffer
[j
+ out_vertex_size
* 2 + 4] - 0.5) * 4 * max_z
; /* z, triangle 3 */
959 if(patch
->has_normals
) {
960 patch
->mem
[i
+ 3] = feedbuffer
[j
+ out_vertex_size
* 2 + 5];
961 patch
->mem
[i
+ 4] = feedbuffer
[j
+ out_vertex_size
* 2 + 6];
962 patch
->mem
[i
+ 5] = feedbuffer
[j
+ out_vertex_size
* 2 + 7];
964 i
+= d3d_out_vertex_size
;
966 patch
->mem
[i
+ 0] = feedbuffer
[j
+ out_vertex_size
* 1 + 2]; /* x, triangle 2 */
967 patch
->mem
[i
+ 1] = feedbuffer
[j
+ out_vertex_size
* 1 + 3]; /* y, triangle 2 */
968 patch
->mem
[i
+ 2] = (feedbuffer
[j
+ out_vertex_size
* 1 + 4] - 0.5) * 4 * max_z
; /* z, triangle 2 */
969 if(patch
->has_normals
) {
970 patch
->mem
[i
+ 3] = feedbuffer
[j
+ out_vertex_size
* 1 + 5];
971 patch
->mem
[i
+ 4] = feedbuffer
[j
+ out_vertex_size
* 1 + 6];
972 patch
->mem
[i
+ 5] = feedbuffer
[j
+ out_vertex_size
* 1 + 7];
974 i
+= d3d_out_vertex_size
;
976 patch
->mem
[i
+ 0] = feedbuffer
[j
+ out_vertex_size
* 0 + 2]; /* x, triangle 1 */
977 patch
->mem
[i
+ 1] = feedbuffer
[j
+ out_vertex_size
* 0 + 3]; /* y, triangle 1 */
978 patch
->mem
[i
+ 2] = (feedbuffer
[j
+ out_vertex_size
* 0 + 4] - 0.5) * 4 * max_z
; /* z, triangle 1 */
979 if(patch
->has_normals
) {
980 patch
->mem
[i
+ 3] = feedbuffer
[j
+ out_vertex_size
* 0 + 5];
981 patch
->mem
[i
+ 4] = feedbuffer
[j
+ out_vertex_size
* 0 + 6];
982 patch
->mem
[i
+ 5] = feedbuffer
[j
+ out_vertex_size
* 0 + 7];
984 i
+= d3d_out_vertex_size
;
987 if(patch
->has_normals
) {
988 /* Now do the same with reverse light directions */
989 static const GLfloat x
[] = {-1, 0, 0, 0};
990 static const GLfloat y
[] = { 0, -1, 0, 0};
991 static const GLfloat z
[] = { 0, 0, -1, 0};
992 glLightfv(GL_LIGHT0
, GL_POSITION
, x
);
993 glLightfv(GL_LIGHT1
, GL_POSITION
, y
);
994 glLightfv(GL_LIGHT2
, GL_POSITION
, z
);
995 checkGLcall("Setting up reverse light directions\n");
997 glRenderMode(GL_FEEDBACK
);
998 checkGLcall("glRenderMode(GL_FEEDBACK)");
999 glEvalMesh2(GL_FILL
, 0, ceilf(patch
->numSegs
[0]), 0, ceilf(patch
->numSegs
[1]));
1000 checkGLcall("glEvalMesh2\n");
1001 i
= glRenderMode(GL_RENDER
);
1002 checkGLcall("glRenderMode(GL_RENDER)");
1005 for(j
= 0; j
< buffer_size
; j
+= (3 /* num verts */ * out_vertex_size
+ 2 /* tri marker */)) {
1006 if(feedbuffer
[j
] != GL_POLYGON_TOKEN
) {
1007 ERR("Unexpected token: %f\n", feedbuffer
[j
]);
1010 if(feedbuffer
[j
+ 1] != 3) {
1011 ERR("Unexpected polygon: %f corners\n", feedbuffer
[j
+ 1]);
1014 if(patch
->mem
[i
+ 3] == 0.0)
1015 patch
->mem
[i
+ 3] = -feedbuffer
[j
+ out_vertex_size
* 2 + 5];
1016 if(patch
->mem
[i
+ 4] == 0.0)
1017 patch
->mem
[i
+ 4] = -feedbuffer
[j
+ out_vertex_size
* 2 + 6];
1018 if(patch
->mem
[i
+ 5] == 0.0)
1019 patch
->mem
[i
+ 5] = -feedbuffer
[j
+ out_vertex_size
* 2 + 7];
1020 normalize_normal(patch
->mem
+ i
+ 3);
1021 i
+= d3d_out_vertex_size
;
1023 if(patch
->mem
[i
+ 3] == 0.0)
1024 patch
->mem
[i
+ 3] = -feedbuffer
[j
+ out_vertex_size
* 1 + 5];
1025 if(patch
->mem
[i
+ 4] == 0.0)
1026 patch
->mem
[i
+ 4] = -feedbuffer
[j
+ out_vertex_size
* 1 + 6];
1027 if(patch
->mem
[i
+ 5] == 0.0)
1028 patch
->mem
[i
+ 5] = -feedbuffer
[j
+ out_vertex_size
* 1 + 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
* 0 + 5];
1034 if(patch
->mem
[i
+ 4] == 0.0)
1035 patch
->mem
[i
+ 4] = -feedbuffer
[j
+ out_vertex_size
* 0 + 6];
1036 if(patch
->mem
[i
+ 5] == 0.0)
1037 patch
->mem
[i
+ 5] = -feedbuffer
[j
+ out_vertex_size
* 0 + 7];
1038 normalize_normal(patch
->mem
+ i
+ 3);
1039 i
+= d3d_out_vertex_size
;
1043 glDisable(GL_MAP2_VERTEX_3
);
1044 glDisable(GL_AUTO_NORMAL
);
1045 glDisable(GL_MAP2_NORMAL
);
1046 glDisable(GL_MAP2_TEXTURE_COORD_4
);
1047 checkGLcall("glDisable vertex attrib generation");
1050 HeapFree(GetProcessHeap(), 0, feedbuffer
);
1052 vtxStride
= 3 * sizeof(float);
1053 if(patch
->has_normals
) {
1054 vtxStride
+= 3 * sizeof(float);
1056 if(patch
->has_texcoords
) {
1057 vtxStride
+= 4 * sizeof(float);
1059 memset(&patch
->strided
, 0, sizeof(&patch
->strided
));
1060 patch
->strided
.position
.format
= WINED3DFMT_R32G32B32_FLOAT
;
1061 patch
->strided
.position
.lpData
= (BYTE
*) patch
->mem
;
1062 patch
->strided
.position
.dwStride
= vtxStride
;
1064 if(patch
->has_normals
) {
1065 patch
->strided
.normal
.format
= WINED3DFMT_R32G32B32_FLOAT
;
1066 patch
->strided
.normal
.lpData
= (BYTE
*) patch
->mem
+ 3 * sizeof(float) /* pos */;
1067 patch
->strided
.normal
.dwStride
= vtxStride
;
1069 if(patch
->has_texcoords
) {
1070 patch
->strided
.texCoords
[0].format
= WINED3DFMT_R32G32B32A32_FLOAT
;
1071 patch
->strided
.texCoords
[0].lpData
= (BYTE
*) patch
->mem
+ 3 * sizeof(float) /* pos */;
1072 if(patch
->has_normals
) {
1073 patch
->strided
.texCoords
[0].lpData
+= 3 * sizeof(float);
1075 patch
->strided
.texCoords
[0].dwStride
= vtxStride
;