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 static void drawStridedFast(IWineD3DDevice
*iface
, GLenum primitive_type
,
36 UINT min_vertex_idx
, UINT max_vertex_idx
, UINT count
, UINT idx_size
,
37 const void *idx_data
, UINT start_idx
)
39 IWineD3DDeviceImpl
*This
= (IWineD3DDeviceImpl
*)iface
;
43 TRACE("(%p) : glElements(%x, %d, %d, ...)\n", This
, primitive_type
, count
, min_vertex_idx
);
46 glDrawElements(primitive_type
, count
,
47 idx_size
== 2 ? GL_UNSIGNED_SHORT
: GL_UNSIGNED_INT
,
48 (const char *)idx_data
+ (idx_size
* start_idx
));
49 checkGLcall("glDrawElements");
51 glDrawRangeElements(primitive_type
, min_vertex_idx
, max_vertex_idx
, count
,
52 idx_size
== 2 ? GL_UNSIGNED_SHORT
: GL_UNSIGNED_INT
,
53 (const char *)idx_data
+ (idx_size
* start_idx
));
54 checkGLcall("glDrawRangeElements");
59 TRACE("(%p) : glDrawArrays(%#x, %d, %d)\n", This
, primitive_type
, start_idx
, count
);
61 glDrawArrays(primitive_type
, start_idx
, count
);
62 checkGLcall("glDrawArrays");
67 * Actually draw using the supplied information.
68 * Slower GL version which extracts info about each vertex in turn
71 static void drawStridedSlow(IWineD3DDevice
*iface
, const struct wined3d_stream_info
*si
, UINT NumVertexes
,
72 GLenum glPrimType
, const void *idxData
, UINT idxSize
, UINT minIndex
, UINT startIdx
)
74 unsigned int textureNo
= 0;
75 const WORD
*pIdxBufS
= NULL
;
76 const DWORD
*pIdxBufL
= NULL
;
78 IWineD3DDeviceImpl
*This
= (IWineD3DDeviceImpl
*)iface
;
79 const UINT
*streamOffset
= This
->stateBlock
->streamOffset
;
80 long SkipnStrides
= startIdx
+ This
->stateBlock
->loadBaseVertexIndex
;
81 BOOL pixelShader
= use_ps(This
->stateBlock
);
82 BOOL specular_fog
= FALSE
;
83 UINT texture_stages
= GL_LIMITS(texture_stages
);
84 const BYTE
*texCoords
[WINED3DDP_MAXTEXCOORD
];
85 const BYTE
*diffuse
= NULL
, *specular
= NULL
, *normal
= NULL
, *position
= NULL
;
86 const struct wined3d_stream_info_element
*element
;
89 TRACE("Using slow vertex array code\n");
91 /* Variable Initialization */
93 /* Immediate mode drawing can't make use of indices in a vbo - get the data from the index buffer.
94 * If the index buffer has no vbo(not supported or other reason), or with user pointer drawing
95 * idxData will be != NULL
98 idxData
= ((IWineD3DIndexBufferImpl
*) This
->stateBlock
->pIndexData
)->resource
.allocatedMemory
;
101 if (idxSize
== 2) pIdxBufS
= idxData
;
102 else pIdxBufL
= idxData
;
103 } else if (idxData
) {
104 ERR("non-NULL idxData with 0 idxSize, this should never happen\n");
108 /* Start drawing in GL */
109 VTRACE(("glBegin(%x)\n", glPrimType
));
112 element
= &si
->elements
[WINED3D_FFP_POSITION
];
113 if (element
->data
) position
= element
->data
+ streamOffset
[element
->stream_idx
];
115 element
= &si
->elements
[WINED3D_FFP_NORMAL
];
116 if (element
->data
) normal
= element
->data
+ streamOffset
[element
->stream_idx
];
117 else glNormal3f(0, 0, 0);
119 element
= &si
->elements
[WINED3D_FFP_DIFFUSE
];
120 if (element
->data
) diffuse
= element
->data
+ streamOffset
[element
->stream_idx
];
121 else glColor4f(1.0f
, 1.0f
, 1.0f
, 1.0f
);
122 if (This
->activeContext
->num_untracked_materials
&& element
->d3d_type
!= WINED3DDECLTYPE_D3DCOLOR
)
123 FIXME("Implement diffuse color tracking from %s\n", debug_d3ddecltype(element
->d3d_type
));
125 element
= &si
->elements
[WINED3D_FFP_SPECULAR
];
128 specular
= element
->data
+ streamOffset
[element
->stream_idx
];
130 /* special case where the fog density is stored in the specular alpha channel */
131 if (This
->stateBlock
->renderState
[WINED3DRS_FOGENABLE
]
132 && (This
->stateBlock
->renderState
[WINED3DRS_FOGVERTEXMODE
] == WINED3DFOG_NONE
133 || si
->elements
[WINED3D_FFP_POSITION
].d3d_type
== WINED3DDECLTYPE_FLOAT4
)
134 && This
->stateBlock
->renderState
[WINED3DRS_FOGTABLEMODE
] == WINED3DFOG_NONE
)
136 if (GL_SUPPORT(EXT_FOG_COORD
))
138 if (element
->d3d_type
== WINED3DDECLTYPE_D3DCOLOR
) specular_fog
= TRUE
;
139 else FIXME("Implement fog coordinates from %s\n", debug_d3ddecltype(element
->d3d_type
));
147 /* TODO: Use the fog table code from old ddraw */
148 FIXME("Implement fog for transformed vertices in software\n");
154 else if (GL_SUPPORT(EXT_SECONDARY_COLOR
))
156 GL_EXTCALL(glSecondaryColor3fEXT
)(0, 0, 0);
159 for (textureNo
= 0; textureNo
< texture_stages
; ++textureNo
)
161 int coordIdx
= This
->stateBlock
->textureState
[textureNo
][WINED3DTSS_TEXCOORDINDEX
];
162 int texture_idx
= This
->texUnitMap
[textureNo
];
164 if (!GL_SUPPORT(ARB_MULTITEXTURE
) && textureNo
> 0)
166 FIXME("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
170 if (!pixelShader
&& !This
->stateBlock
->textures
[textureNo
]) continue;
172 if (texture_idx
== -1) continue;
176 TRACE("tex: %d - Skip tex coords, as being system generated\n", textureNo
);
179 else if (coordIdx
< 0)
181 FIXME("tex: %d - Coord index %d is less than zero, expect a crash.\n", textureNo
, coordIdx
);
185 element
= &si
->elements
[WINED3D_FFP_TEXCOORD0
+ coordIdx
];
188 texCoords
[coordIdx
] = element
->data
+ streamOffset
[element
->stream_idx
];
189 tex_mask
|= (1 << textureNo
);
193 TRACE("tex: %d - Skipping tex coords, as no data supplied\n", textureNo
);
194 if (GL_SUPPORT(ARB_MULTITEXTURE
))
195 GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB
+ texture_idx
, 0, 0, 0, 1));
197 glTexCoord4f(0, 0, 0, 1);
201 /* We shouldn't start this function if any VBO is involved. Should I put a safety check here?
202 * Guess it's not necessary(we crash then anyway) and would only eat CPU time
205 /* For each primitive */
206 for (vx_index
= 0; vx_index
< NumVertexes
; ++vx_index
) {
207 UINT texture
, tmp_tex_mask
;
208 /* Blending data and Point sizes are not supported by this function. They are not supported by the fixed
209 * function pipeline at all. A Fixme for them is printed after decoding the vertex declaration
212 /* For indexed data, we need to go a few more strides in */
213 if (idxData
!= NULL
) {
215 /* Indexed so work out the number of strides to skip */
217 VTRACE(("Idx for vertex %u = %u\n", vx_index
, pIdxBufS
[startIdx
+vx_index
]));
218 SkipnStrides
= pIdxBufS
[startIdx
+ vx_index
] + This
->stateBlock
->loadBaseVertexIndex
;
220 VTRACE(("Idx for vertex %u = %u\n", vx_index
, pIdxBufL
[startIdx
+vx_index
]));
221 SkipnStrides
= pIdxBufL
[startIdx
+ vx_index
] + This
->stateBlock
->loadBaseVertexIndex
;
225 tmp_tex_mask
= tex_mask
;
226 for (texture
= 0; tmp_tex_mask
; tmp_tex_mask
>>= 1, ++texture
)
232 if (!(tmp_tex_mask
& 1)) continue;
234 coord_idx
= This
->stateBlock
->textureState
[texture
][WINED3DTSS_TEXCOORDINDEX
];
235 ptr
= texCoords
[coord_idx
] + (SkipnStrides
* si
->elements
[WINED3D_FFP_TEXCOORD0
+ coord_idx
].stride
);
237 texture_idx
= This
->texUnitMap
[texture
];
238 multi_texcoord_funcs
[si
->elements
[WINED3D_FFP_TEXCOORD0
+ coord_idx
].d3d_type
](
239 GL_TEXTURE0_ARB
+ texture_idx
, ptr
);
242 /* Diffuse -------------------------------- */
244 const void *ptrToCoords
= diffuse
+ SkipnStrides
* si
->elements
[WINED3D_FFP_DIFFUSE
].stride
;
246 diffuse_funcs
[si
->elements
[WINED3D_FFP_DIFFUSE
].d3d_type
](ptrToCoords
);
247 if(This
->activeContext
->num_untracked_materials
) {
248 DWORD diffuseColor
= ((const DWORD
*)ptrToCoords
)[0];
252 color
[0] = D3DCOLOR_B_R(diffuseColor
) / 255.0;
253 color
[1] = D3DCOLOR_B_G(diffuseColor
) / 255.0;
254 color
[2] = D3DCOLOR_B_B(diffuseColor
) / 255.0;
255 color
[3] = D3DCOLOR_B_A(diffuseColor
) / 255.0;
257 for(i
= 0; i
< This
->activeContext
->num_untracked_materials
; i
++) {
258 glMaterialfv(GL_FRONT_AND_BACK
, This
->activeContext
->untracked_materials
[i
], color
);
263 /* Specular ------------------------------- */
265 const void *ptrToCoords
= specular
+ SkipnStrides
* si
->elements
[WINED3D_FFP_SPECULAR
].stride
;
267 specular_funcs
[si
->elements
[WINED3D_FFP_SPECULAR
].d3d_type
](ptrToCoords
);
271 DWORD specularColor
= *(const DWORD
*)ptrToCoords
;
272 GL_EXTCALL(glFogCoordfEXT(specularColor
>> 24));
276 /* Normal -------------------------------- */
277 if (normal
!= NULL
) {
278 const void *ptrToCoords
= normal
+ SkipnStrides
* si
->elements
[WINED3D_FFP_NORMAL
].stride
;
279 normal_funcs
[si
->elements
[WINED3D_FFP_NORMAL
].d3d_type
](ptrToCoords
);
282 /* Position -------------------------------- */
284 const void *ptrToCoords
= position
+ SkipnStrides
* si
->elements
[WINED3D_FFP_POSITION
].stride
;
285 position_funcs
[si
->elements
[WINED3D_FFP_POSITION
].d3d_type
](ptrToCoords
);
288 /* For non indexed mode, step onto next parts */
289 if (idxData
== NULL
) {
295 checkGLcall("glEnd and previous calls");
298 static inline void send_attribute(IWineD3DDeviceImpl
*This
, const DWORD type
, const UINT index
, const void *ptr
) {
300 case WINED3DDECLTYPE_FLOAT1
:
301 GL_EXTCALL(glVertexAttrib1fvARB(index
, ptr
));
303 case WINED3DDECLTYPE_FLOAT2
:
304 GL_EXTCALL(glVertexAttrib2fvARB(index
, ptr
));
306 case WINED3DDECLTYPE_FLOAT3
:
307 GL_EXTCALL(glVertexAttrib3fvARB(index
, ptr
));
309 case WINED3DDECLTYPE_FLOAT4
:
310 GL_EXTCALL(glVertexAttrib4fvARB(index
, ptr
));
313 case WINED3DDECLTYPE_UBYTE4
:
314 GL_EXTCALL(glVertexAttrib4ubvARB(index
, ptr
));
316 case WINED3DDECLTYPE_D3DCOLOR
:
317 if (GL_SUPPORT(EXT_VERTEX_ARRAY_BGRA
))
319 const DWORD
*src
= ptr
;
320 DWORD c
= *src
& 0xff00ff00;
321 c
|= (*src
& 0xff0000) >> 16;
322 c
|= (*src
& 0xff) << 16;
323 GL_EXTCALL(glVertexAttrib4NubvARB(index
, (GLubyte
*)&c
));
326 /* else fallthrough */
327 case WINED3DDECLTYPE_UBYTE4N
:
328 GL_EXTCALL(glVertexAttrib4NubvARB(index
, ptr
));
331 case WINED3DDECLTYPE_SHORT2
:
332 GL_EXTCALL(glVertexAttrib4svARB(index
, ptr
));
334 case WINED3DDECLTYPE_SHORT4
:
335 GL_EXTCALL(glVertexAttrib4svARB(index
, ptr
));
338 case WINED3DDECLTYPE_SHORT2N
:
340 GLshort s
[4] = {((const GLshort
*)ptr
)[0], ((const GLshort
*)ptr
)[1], 0, 1};
341 GL_EXTCALL(glVertexAttrib4NsvARB(index
, s
));
344 case WINED3DDECLTYPE_USHORT2N
:
346 GLushort s
[4] = {((const GLushort
*)ptr
)[0], ((const GLushort
*)ptr
)[1], 0, 1};
347 GL_EXTCALL(glVertexAttrib4NusvARB(index
, s
));
350 case WINED3DDECLTYPE_SHORT4N
:
351 GL_EXTCALL(glVertexAttrib4NsvARB(index
, ptr
));
353 case WINED3DDECLTYPE_USHORT4N
:
354 GL_EXTCALL(glVertexAttrib4NusvARB(index
, ptr
));
357 case WINED3DDECLTYPE_UDEC3
:
358 FIXME("Unsure about WINED3DDECLTYPE_UDEC3\n");
359 /*glVertexAttrib3usvARB(instancedData[j], (GLushort *) ptr); Does not exist */
361 case WINED3DDECLTYPE_DEC3N
:
362 FIXME("Unsure about WINED3DDECLTYPE_DEC3N\n");
363 /*glVertexAttrib3NusvARB(instancedData[j], (GLushort *) ptr); Does not exist */
366 case WINED3DDECLTYPE_FLOAT16_2
:
367 /* Are those 16 bit floats. C doesn't have a 16 bit float type. I could read the single bits and calculate a 4
368 * byte float according to the IEEE standard
370 if (GL_SUPPORT(NV_HALF_FLOAT
)) {
371 GL_EXTCALL(glVertexAttrib2hvNV(index
, ptr
));
373 float x
= float_16_to_32(((const unsigned short *)ptr
) + 0);
374 float y
= float_16_to_32(((const unsigned short *)ptr
) + 1);
375 GL_EXTCALL(glVertexAttrib2fARB(index
, x
, y
));
378 case WINED3DDECLTYPE_FLOAT16_4
:
379 if (GL_SUPPORT(NV_HALF_FLOAT
)) {
380 GL_EXTCALL(glVertexAttrib4hvNV(index
, ptr
));
382 float x
= float_16_to_32(((const unsigned short *)ptr
) + 0);
383 float y
= float_16_to_32(((const unsigned short *)ptr
) + 1);
384 float z
= float_16_to_32(((const unsigned short *)ptr
) + 2);
385 float w
= float_16_to_32(((const unsigned short *)ptr
) + 3);
386 GL_EXTCALL(glVertexAttrib4fARB(index
, x
, y
, z
, w
));
390 case WINED3DDECLTYPE_UNUSED
:
392 ERR("Unexpected attribute declaration: %d\n", type
);
397 static void drawStridedSlowVs(IWineD3DDevice
*iface
, const struct wined3d_stream_info
*si
, UINT numberOfVertices
,
398 GLenum glPrimitiveType
, const void *idxData
, UINT idxSize
, UINT minIndex
, UINT startIdx
)
400 IWineD3DDeviceImpl
*This
= (IWineD3DDeviceImpl
*) iface
;
401 long SkipnStrides
= startIdx
+ This
->stateBlock
->loadBaseVertexIndex
;
402 const WORD
*pIdxBufS
= NULL
;
403 const DWORD
*pIdxBufL
= NULL
;
406 IWineD3DStateBlockImpl
*stateblock
= This
->stateBlock
;
410 /* Immediate mode drawing can't make use of indices in a vbo - get the data from the index buffer.
411 * If the index buffer has no vbo(not supported or other reason), or with user pointer drawing
412 * idxData will be != NULL
414 if(idxData
== NULL
) {
415 idxData
= ((IWineD3DIndexBufferImpl
*) stateblock
->pIndexData
)->resource
.allocatedMemory
;
418 if (idxSize
== 2) pIdxBufS
= idxData
;
419 else pIdxBufL
= idxData
;
420 } else if (idxData
) {
421 ERR("non-NULL idxData with 0 idxSize, this should never happen\n");
425 /* Start drawing in GL */
426 VTRACE(("glBegin(%x)\n", glPrimitiveType
));
427 glBegin(glPrimitiveType
);
429 for (vx_index
= 0; vx_index
< numberOfVertices
; ++vx_index
) {
430 if (idxData
!= NULL
) {
432 /* Indexed so work out the number of strides to skip */
434 VTRACE(("Idx for vertex %d = %d\n", vx_index
, pIdxBufS
[startIdx
+vx_index
]));
435 SkipnStrides
= pIdxBufS
[startIdx
+ vx_index
] + stateblock
->loadBaseVertexIndex
;
437 VTRACE(("Idx for vertex %d = %d\n", vx_index
, pIdxBufL
[startIdx
+vx_index
]));
438 SkipnStrides
= pIdxBufL
[startIdx
+ vx_index
] + stateblock
->loadBaseVertexIndex
;
442 for(i
= MAX_ATTRIBS
- 1; i
>= 0; i
--) {
443 if(!si
->elements
[i
].data
) continue;
445 ptr
= si
->elements
[i
].data
+
446 si
->elements
[i
].stride
* SkipnStrides
+
447 stateblock
->streamOffset
[si
->elements
[i
].stream_idx
];
449 send_attribute(This
, si
->elements
[i
].d3d_type
, i
, ptr
);
457 static inline void drawStridedInstanced(IWineD3DDevice
*iface
, const struct wined3d_stream_info
*si
,
458 UINT numberOfVertices
, GLenum glPrimitiveType
, const void *idxData
, UINT idxSize
, UINT minIndex
,
461 UINT numInstances
= 0, i
;
462 int numInstancedAttribs
= 0, j
;
463 UINT instancedData
[sizeof(si
->elements
) / sizeof(*si
->elements
) /* 16 */];
464 IWineD3DDeviceImpl
*This
= (IWineD3DDeviceImpl
*) iface
;
465 IWineD3DStateBlockImpl
*stateblock
= This
->stateBlock
;
468 /* This is a nasty thing. MSDN says no hardware supports that and apps have to use software vertex processing.
469 * We don't support this for now
471 * Shouldn't be too hard to support with opengl, in theory just call glDrawArrays instead of drawElements.
472 * But the StreamSourceFreq value has a different meaning in that situation.
474 FIXME("Non-indexed instanced drawing is not supported\n");
478 TRACE("(%p) : glElements(%x, %d, %d, ...)\n", This
, glPrimitiveType
, numberOfVertices
, minIndex
);
480 /* First, figure out how many instances we have to draw */
481 for(i
= 0; i
< MAX_STREAMS
; i
++) {
482 /* Look at the streams and take the first one which matches */
483 if(((stateblock
->streamFlags
[i
] & WINED3DSTREAMSOURCE_INSTANCEDATA
) || (stateblock
->streamFlags
[i
] & WINED3DSTREAMSOURCE_INDEXEDDATA
)) && stateblock
->streamSource
[i
]) {
484 /* D3D9 could set streamFreq 0 with (INSTANCEDATA or INDEXEDDATA) and then it is handled as 1. See d3d9/tests/visual.c-> stream_test() */
485 if(stateblock
->streamFreq
[i
] == 0){
488 numInstances
= stateblock
->streamFreq
[i
]; /* use the specified number of instances from the first matched stream. See d3d9/tests/visual.c-> stream_test() */
490 break; /* break, because only the first suitable value is interesting */
494 for (i
= 0; i
< sizeof(si
->elements
) / sizeof(*si
->elements
); ++i
)
496 if (stateblock
->streamFlags
[si
->elements
[i
].stream_idx
] & WINED3DSTREAMSOURCE_INSTANCEDATA
)
498 instancedData
[numInstancedAttribs
] = i
;
499 numInstancedAttribs
++;
503 /* now draw numInstances instances :-) */
504 for(i
= 0; i
< numInstances
; i
++) {
505 /* Specify the instanced attributes using immediate mode calls */
506 for(j
= 0; j
< numInstancedAttribs
; j
++) {
507 const BYTE
*ptr
= si
->elements
[instancedData
[j
]].data
+
508 si
->elements
[instancedData
[j
]].stride
* i
+
509 stateblock
->streamOffset
[si
->elements
[instancedData
[j
]].stream_idx
];
510 if (si
->elements
[instancedData
[j
]].buffer_object
)
512 struct wined3d_buffer
*vb
=
513 (struct wined3d_buffer
*)stateblock
->streamSource
[si
->elements
[instancedData
[j
]].stream_idx
];
514 ptr
+= (long) vb
->resource
.allocatedMemory
;
517 send_attribute(This
, si
->elements
[instancedData
[j
]].d3d_type
, instancedData
[j
], ptr
);
520 glDrawElements(glPrimitiveType
, numberOfVertices
, idxSize
== 2 ? GL_UNSIGNED_SHORT
: GL_UNSIGNED_INT
,
521 (const char *)idxData
+(idxSize
* startIdx
));
522 checkGLcall("glDrawElements");
526 static inline void remove_vbos(IWineD3DDeviceImpl
*This
, struct wined3d_stream_info
*s
)
530 for (i
= 0; i
< (sizeof(s
->elements
) / sizeof(*s
->elements
)); ++i
)
532 struct wined3d_stream_info_element
*e
= &s
->elements
[i
];
533 if (e
->buffer_object
)
535 struct wined3d_buffer
*vb
= (struct wined3d_buffer
*)This
->stateBlock
->streamSource
[e
->stream_idx
];
536 e
->buffer_object
= 0;
537 e
->data
= (BYTE
*)((unsigned long)e
->data
+ (unsigned long)vb
->resource
.allocatedMemory
);
542 /* Routine common to the draw primitive and draw indexed primitive routines */
543 void drawPrimitive(IWineD3DDevice
*iface
, UINT index_count
, UINT numberOfVertices
,
544 UINT StartIdx
, UINT idxSize
, const void *idxData
, UINT minIndex
)
547 IWineD3DDeviceImpl
*This
= (IWineD3DDeviceImpl
*)iface
;
548 IWineD3DSurfaceImpl
*target
;
551 if (!index_count
) return;
553 /* Invalidate the back buffer memory so LockRect will read it the next time */
554 for(i
= 0; i
< GL_LIMITS(buffers
); i
++) {
555 target
= (IWineD3DSurfaceImpl
*) This
->render_targets
[i
];
557 IWineD3DSurface_LoadLocation((IWineD3DSurface
*) target
, SFLAG_INDRAWABLE
, NULL
);
558 IWineD3DSurface_ModifyLocation((IWineD3DSurface
*) target
, SFLAG_INDRAWABLE
, TRUE
);
562 /* Signals other modules that a drawing is in progress and the stateblock finalized */
563 This
->isInDraw
= TRUE
;
565 ActivateContext(This
, This
->render_targets
[0], CTXUSAGE_DRAWPRIM
);
567 if (This
->stencilBufferTarget
) {
568 /* Note that this depends on the ActivateContext call above to set
569 * This->render_offscreen properly */
570 DWORD location
= This
->render_offscreen
? SFLAG_DS_OFFSCREEN
: SFLAG_DS_ONSCREEN
;
571 surface_load_ds_location(This
->stencilBufferTarget
, location
);
572 surface_modify_ds_location(This
->stencilBufferTarget
, location
);
575 /* Ok, we will be updating the screen from here onwards so grab the lock */
578 GLenum glPrimType
= This
->stateBlock
->gl_primitive_type
;
579 BOOL emulation
= FALSE
;
580 const struct wined3d_stream_info
*stream_info
= &This
->strided_streams
;
581 struct wined3d_stream_info stridedlcl
;
583 if (!numberOfVertices
) numberOfVertices
= index_count
;
585 if (!use_vs(This
->stateBlock
))
587 if (!This
->strided_streams
.position_transformed
&& This
->activeContext
->num_untracked_materials
588 && This
->stateBlock
->renderState
[WINED3DRS_LIGHTING
])
592 FIXME("Using software emulation because not all material properties could be tracked\n");
595 TRACE("Using software emulation because not all material properties could be tracked\n");
599 else if(This
->activeContext
->fog_coord
&& This
->stateBlock
->renderState
[WINED3DRS_FOGENABLE
]) {
600 /* Either write a pipeline replacement shader or convert the specular alpha from unsigned byte
601 * to a float in the vertex buffer
605 FIXME("Using software emulation because manual fog coordinates are provided\n");
608 TRACE("Using software emulation because manual fog coordinates are provided\n");
614 stream_info
= &stridedlcl
;
615 memcpy(&stridedlcl
, &This
->strided_streams
, sizeof(stridedlcl
));
616 remove_vbos(This
, &stridedlcl
);
620 if (This
->useDrawStridedSlow
|| emulation
) {
621 /* Immediate mode drawing */
622 if (use_vs(This
->stateBlock
))
626 FIXME("Using immediate mode with vertex shaders for half float emulation\n");
629 TRACE("Using immediate mode with vertex shaders for half float emulation\n");
631 drawStridedSlowVs(iface
, stream_info
, index_count
, glPrimType
, idxData
, idxSize
, minIndex
, StartIdx
);
633 drawStridedSlow(iface
, stream_info
, index_count
, glPrimType
, idxData
, idxSize
, minIndex
, StartIdx
);
635 } else if(This
->instancedDraw
) {
636 /* Instancing emulation with mixing immediate mode and arrays */
637 drawStridedInstanced(iface
, &This
->strided_streams
, index_count
,
638 glPrimType
, idxData
, idxSize
, minIndex
, StartIdx
);
640 drawStridedFast(iface
, glPrimType
, minIndex
, minIndex
+ numberOfVertices
- 1,
641 index_count
, idxSize
, idxData
, StartIdx
);
645 /* Finished updating the screen, restore lock */
647 TRACE("Done all gl drawing\n");
650 #ifdef SHOW_FRAME_MAKEUP
652 static long int primCounter
= 0;
653 /* NOTE: set primCounter to the value reported by drawprim
654 before you want to to write frame makeup to /tmp */
655 if (primCounter
>= 0) {
656 WINED3DLOCKED_RECT r
;
658 IWineD3DSurface_LockRect(This
->render_targets
[0], &r
, NULL
, WINED3DLOCK_READONLY
);
659 sprintf(buffer
, "/tmp/backbuffer_%ld.tga", primCounter
);
660 TRACE("Saving screenshot %s\n", buffer
);
661 IWineD3DSurface_SaveSnapshot(This
->render_targets
[0], buffer
);
662 IWineD3DSurface_UnlockRect(This
->render_targets
[0]);
664 #ifdef SHOW_TEXTURE_MAKEUP
666 IWineD3DSurface
*pSur
;
668 for (textureNo
= 0; textureNo
< MAX_COMBINED_SAMPLERS
; ++textureNo
) {
669 if (This
->stateBlock
->textures
[textureNo
] != NULL
) {
670 sprintf(buffer
, "/tmp/texture_%p_%ld_%d.tga", This
->stateBlock
->textures
[textureNo
], primCounter
, textureNo
);
671 TRACE("Saving texture %s\n", buffer
);
672 if (IWineD3DBaseTexture_GetType(This
->stateBlock
->textures
[textureNo
]) == WINED3DRTYPE_TEXTURE
) {
673 IWineD3DTexture_GetSurfaceLevel(This
->stateBlock
->textures
[textureNo
], 0, &pSur
);
674 IWineD3DSurface_SaveSnapshot(pSur
, buffer
);
675 IWineD3DSurface_Release(pSur
);
677 FIXME("base Texture isn't of type texture %d\n", IWineD3DBaseTexture_GetType(This
->stateBlock
->textures
[textureNo
]));
684 TRACE("drawprim #%ld\n", primCounter
);
689 /* Control goes back to the device, stateblock values may change again */
690 This
->isInDraw
= FALSE
;
693 static void normalize_normal(float *n
) {
694 float length
= n
[0] * n
[0] + n
[1] * n
[1] + n
[2] * n
[2];
695 if(length
== 0.0) return;
696 length
= sqrt(length
);
697 n
[0] = n
[0] / length
;
698 n
[1] = n
[1] / length
;
699 n
[2] = n
[2] / length
;
702 /* Tesselates a high order rectangular patch into single triangles using gl evaluators
704 * The problem is that OpenGL does not offer a direct way to return the tesselated primitives,
705 * and they can't be sent off for rendering directly either. Tesselating is slow, so we want
706 * to cache the patches in a vertex buffer. But more importantly, gl can't bind generated
707 * attributes to numbered shader attributes, so we have to store them and rebind them as needed
710 * To read back, the opengl feedback mode is used. This creates a problem because we want
711 * untransformed, unlit vertices, but feedback runs everything through transform and lighting.
712 * Thus disable lighting and set identity matrices to get unmodified colors and positions.
713 * To overcome clipping find the biggest x, y and z values of the vertices in the patch and scale
714 * them to [-1.0;+1.0] and set the viewport up to scale them back.
716 * Normals are more tricky: Draw white vertices with 3 directional lights, and calculate the
717 * resulting colors back to the normals.
719 * NOTE: This function activates a context for blitting, modifies matrices & viewport, but
720 * does not restore it because normally a draw follows immediately afterwards. The caller is
721 * responsible of taking care that either the gl states are restored, or the context activated
722 * for drawing to reset the lastWasBlit flag.
724 HRESULT
tesselate_rectpatch(IWineD3DDeviceImpl
*This
,
725 struct WineD3DRectPatch
*patch
) {
726 unsigned int i
, j
, num_quads
, out_vertex_size
, buffer_size
, d3d_out_vertex_size
;
727 float max_x
= 0.0, max_y
= 0.0, max_z
= 0.0, neg_z
= 0.0;
728 struct wined3d_stream_info stream_info
;
729 struct wined3d_stream_info_element
*e
;
731 const WINED3DRECTPATCH_INFO
*info
= &patch
->RectPatchInfo
;
733 GLenum feedback_type
;
736 /* First, locate the position data. This is provided in a vertex buffer in the stateblock.
739 device_stream_info_from_declaration(This
, FALSE
, &stream_info
, NULL
);
741 e
= &stream_info
.elements
[WINED3D_FFP_POSITION
];
742 if (e
->buffer_object
)
744 struct wined3d_buffer
*vb
;
745 vb
= (struct wined3d_buffer
*)This
->stateBlock
->streamSource
[e
->stream_idx
];
746 e
->data
= (BYTE
*)((unsigned long)e
->data
+ (unsigned long)vb
->resource
.allocatedMemory
);
748 vtxStride
= e
->stride
;
750 vtxStride
* info
->Stride
* info
->StartVertexOffsetHeight
+
751 vtxStride
* info
->StartVertexOffsetWidth
;
753 /* Not entirely sure about what happens with transformed vertices */
754 if (stream_info
.position_transformed
) FIXME("Transformed position in rectpatch generation\n");
756 if(vtxStride
% sizeof(GLfloat
)) {
757 /* glMap2f reads vertex sizes in GLfloats, the d3d stride is in bytes.
758 * I don't see how the stride could not be a multiple of 4, but make sure
761 ERR("Vertex stride is not a multiple of sizeof(GLfloat)\n");
763 if(info
->Basis
!= WINED3DBASIS_BEZIER
) {
764 FIXME("Basis is %s, how to handle this?\n", debug_d3dbasis(info
->Basis
));
766 if(info
->Degree
!= WINED3DDEGREE_CUBIC
) {
767 FIXME("Degree is %s, how to handle this?\n", debug_d3ddegree(info
->Degree
));
770 /* First, get the boundary cube of the input data */
771 for(j
= 0; j
< info
->Height
; j
++) {
772 for(i
= 0; i
< info
->Width
; i
++) {
773 const float *v
= (const float *)(data
+ vtxStride
* i
+ vtxStride
* info
->Stride
* j
);
774 if(fabs(v
[0]) > max_x
) max_x
= fabs(v
[0]);
775 if(fabs(v
[1]) > max_y
) max_y
= fabs(v
[1]);
776 if(fabs(v
[2]) > max_z
) max_z
= fabs(v
[2]);
777 if(v
[2] < neg_z
) neg_z
= v
[2];
781 /* This needs some improvements in the vertex decl code */
782 FIXME("Cannot find data to generate. Only generating position and normals\n");
783 patch
->has_normals
= TRUE
;
784 patch
->has_texcoords
= FALSE
;
786 /* Simply activate the context for blitting. This disables all the things we don't want and
787 * takes care of dirtifying. Dirtifying is preferred over pushing / popping, since drawing the
788 * patch (as opposed to normal draws) will most likely need different changes anyway
790 ActivateContext(This
, This
->lastActiveRenderTarget
, CTXUSAGE_BLIT
);
793 glMatrixMode(GL_PROJECTION
);
794 checkGLcall("glMatrixMode(GL_PROJECTION)");
796 checkGLcall("glLoadIndentity()");
797 glScalef(1 / (max_x
) , 1 / (max_y
), max_z
== 0 ? 1 : 1 / ( 2 * max_z
));
798 glTranslatef(0, 0, 0.5);
799 checkGLcall("glScalef");
800 glViewport(-max_x
, -max_y
, 2 * (max_x
), 2 * (max_y
));
801 checkGLcall("glViewport");
803 /* Some states to take care of. If we're in wireframe opengl will produce lines, and confuse
804 * our feedback buffer parser
806 glPolygonMode(GL_FRONT_AND_BACK
, GL_FILL
);
807 checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)");
808 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_RENDER(WINED3DRS_FILLMODE
));
809 if(patch
->has_normals
) {
810 static const GLfloat black
[] = {0, 0, 0, 0};
811 static const GLfloat red
[] = {1, 0, 0, 0};
812 static const GLfloat green
[] = {0, 1, 0, 0};
813 static const GLfloat blue
[] = {0, 0, 1, 0};
814 static const GLfloat white
[] = {1, 1, 1, 1};
815 glEnable(GL_LIGHTING
);
816 checkGLcall("glEnable(GL_LIGHTING)");
817 glLightModelfv(GL_LIGHT_MODEL_AMBIENT
, black
);
818 checkGLcall("glLightModel for MODEL_AMBIENT");
819 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_RENDER(WINED3DRS_AMBIENT
));
821 for(i
= 3; i
< GL_LIMITS(lights
); i
++) {
822 glDisable(GL_LIGHT0
+ i
);
823 checkGLcall("glDisable(GL_LIGHT0 + i)");
824 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_ACTIVELIGHT(i
));
827 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_ACTIVELIGHT(0));
828 glLightfv(GL_LIGHT0
, GL_DIFFUSE
, red
);
829 glLightfv(GL_LIGHT0
, GL_SPECULAR
, black
);
830 glLightfv(GL_LIGHT0
, GL_AMBIENT
, black
);
831 glLightfv(GL_LIGHT0
, GL_POSITION
, red
);
833 checkGLcall("Setting up light 1\n");
834 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_ACTIVELIGHT(1));
835 glLightfv(GL_LIGHT1
, GL_DIFFUSE
, green
);
836 glLightfv(GL_LIGHT1
, GL_SPECULAR
, black
);
837 glLightfv(GL_LIGHT1
, GL_AMBIENT
, black
);
838 glLightfv(GL_LIGHT1
, GL_POSITION
, green
);
840 checkGLcall("Setting up light 2\n");
841 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_ACTIVELIGHT(2));
842 glLightfv(GL_LIGHT2
, GL_DIFFUSE
, blue
);
843 glLightfv(GL_LIGHT2
, GL_SPECULAR
, black
);
844 glLightfv(GL_LIGHT2
, GL_AMBIENT
, black
);
845 glLightfv(GL_LIGHT2
, GL_POSITION
, blue
);
847 checkGLcall("Setting up light 3\n");
849 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_MATERIAL
);
850 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_RENDER(WINED3DRS_COLORVERTEX
));
851 glDisable(GL_COLOR_MATERIAL
);
852 glMaterialfv(GL_FRONT_AND_BACK
, GL_EMISSION
, black
);
853 glMaterialfv(GL_FRONT_AND_BACK
, GL_SPECULAR
, black
);
854 glMaterialfv(GL_FRONT_AND_BACK
, GL_DIFFUSE
, white
);
855 checkGLcall("Setting up materials\n");
858 /* Enable the needed maps.
859 * GL_MAP2_VERTEX_3 is needed for positional data.
860 * GL_AUTO_NORMAL to generate normals from the position. Do not use GL_MAP2_NORMAL.
861 * GL_MAP2_TEXTURE_COORD_4 for texture coords
863 num_quads
= ceilf(patch
->numSegs
[0]) * ceilf(patch
->numSegs
[1]);
864 out_vertex_size
= 3 /* position */;
865 d3d_out_vertex_size
= 3;
866 glEnable(GL_MAP2_VERTEX_3
);
867 if(patch
->has_normals
&& patch
->has_texcoords
) {
868 FIXME("Texcoords not handled yet\n");
869 feedback_type
= GL_3D_COLOR_TEXTURE
;
870 out_vertex_size
+= 8;
871 d3d_out_vertex_size
+= 7;
872 glEnable(GL_AUTO_NORMAL
);
873 glEnable(GL_MAP2_TEXTURE_COORD_4
);
874 } else if(patch
->has_texcoords
) {
875 FIXME("Texcoords not handled yet\n");
876 feedback_type
= GL_3D_COLOR_TEXTURE
;
877 out_vertex_size
+= 7;
878 d3d_out_vertex_size
+= 4;
879 glEnable(GL_MAP2_TEXTURE_COORD_4
);
880 } else if(patch
->has_normals
) {
881 feedback_type
= GL_3D_COLOR
;
882 out_vertex_size
+= 4;
883 d3d_out_vertex_size
+= 3;
884 glEnable(GL_AUTO_NORMAL
);
886 feedback_type
= GL_3D
;
888 checkGLcall("glEnable vertex attrib generation");
890 buffer_size
= num_quads
* out_vertex_size
* 2 /* triangle list */ * 3 /* verts per tri */
891 + 4 * num_quads
/* 2 triangle markers per quad + num verts in tri */;
892 feedbuffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, buffer_size
* sizeof(float) * 8);
894 glMap2f(GL_MAP2_VERTEX_3
,
895 0, 1, vtxStride
/ sizeof(float), info
->Width
,
896 0, 1, info
->Stride
* vtxStride
/ sizeof(float), info
->Height
,
897 (const GLfloat
*)data
);
898 checkGLcall("glMap2f");
899 if(patch
->has_texcoords
) {
900 glMap2f(GL_MAP2_TEXTURE_COORD_4
,
901 0, 1, vtxStride
/ sizeof(float), info
->Width
,
902 0, 1, info
->Stride
* vtxStride
/ sizeof(float), info
->Height
,
903 (const GLfloat
*)data
);
904 checkGLcall("glMap2f");
906 glMapGrid2f(ceilf(patch
->numSegs
[0]), 0.0, 1.0, ceilf(patch
->numSegs
[1]), 0.0, 1.0);
907 checkGLcall("glMapGrid2f");
909 glFeedbackBuffer(buffer_size
* 2, feedback_type
, feedbuffer
);
910 checkGLcall("glFeedbackBuffer");
911 glRenderMode(GL_FEEDBACK
);
913 glEvalMesh2(GL_FILL
, 0, ceilf(patch
->numSegs
[0]), 0, ceilf(patch
->numSegs
[1]));
914 checkGLcall("glEvalMesh2\n");
916 i
= glRenderMode(GL_RENDER
);
919 ERR("Feedback failed. Expected %d elements back\n", buffer_size
);
921 HeapFree(GetProcessHeap(), 0, feedbuffer
);
922 return WINED3DERR_DRIVERINTERNALERROR
;
923 } else if(i
!= buffer_size
) {
925 ERR("Unexpected amount of elements returned. Expected %d, got %d\n", buffer_size
, i
);
927 HeapFree(GetProcessHeap(), 0, feedbuffer
);
928 return WINED3DERR_DRIVERINTERNALERROR
;
930 TRACE("Got %d elements as expected\n", i
);
933 HeapFree(GetProcessHeap(), 0, patch
->mem
);
934 patch
->mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, num_quads
* 6 * d3d_out_vertex_size
* sizeof(float) * 8);
936 for(j
= 0; j
< buffer_size
; j
+= (3 /* num verts */ * out_vertex_size
+ 2 /* tri marker */)) {
937 if(feedbuffer
[j
] != GL_POLYGON_TOKEN
) {
938 ERR("Unexpected token: %f\n", feedbuffer
[j
]);
941 if(feedbuffer
[j
+ 1] != 3) {
942 ERR("Unexpected polygon: %f corners\n", feedbuffer
[j
+ 1]);
945 /* Somehow there are different ideas about back / front facing, so fix up the
948 patch
->mem
[i
+ 0] = feedbuffer
[j
+ out_vertex_size
* 2 + 2]; /* x, triangle 2 */
949 patch
->mem
[i
+ 1] = feedbuffer
[j
+ out_vertex_size
* 2 + 3]; /* y, triangle 2 */
950 patch
->mem
[i
+ 2] = (feedbuffer
[j
+ out_vertex_size
* 2 + 4] - 0.5) * 4 * max_z
; /* z, triangle 3 */
951 if(patch
->has_normals
) {
952 patch
->mem
[i
+ 3] = feedbuffer
[j
+ out_vertex_size
* 2 + 5];
953 patch
->mem
[i
+ 4] = feedbuffer
[j
+ out_vertex_size
* 2 + 6];
954 patch
->mem
[i
+ 5] = feedbuffer
[j
+ out_vertex_size
* 2 + 7];
956 i
+= d3d_out_vertex_size
;
958 patch
->mem
[i
+ 0] = feedbuffer
[j
+ out_vertex_size
* 1 + 2]; /* x, triangle 2 */
959 patch
->mem
[i
+ 1] = feedbuffer
[j
+ out_vertex_size
* 1 + 3]; /* y, triangle 2 */
960 patch
->mem
[i
+ 2] = (feedbuffer
[j
+ out_vertex_size
* 1 + 4] - 0.5) * 4 * max_z
; /* z, triangle 2 */
961 if(patch
->has_normals
) {
962 patch
->mem
[i
+ 3] = feedbuffer
[j
+ out_vertex_size
* 1 + 5];
963 patch
->mem
[i
+ 4] = feedbuffer
[j
+ out_vertex_size
* 1 + 6];
964 patch
->mem
[i
+ 5] = feedbuffer
[j
+ out_vertex_size
* 1 + 7];
966 i
+= d3d_out_vertex_size
;
968 patch
->mem
[i
+ 0] = feedbuffer
[j
+ out_vertex_size
* 0 + 2]; /* x, triangle 1 */
969 patch
->mem
[i
+ 1] = feedbuffer
[j
+ out_vertex_size
* 0 + 3]; /* y, triangle 1 */
970 patch
->mem
[i
+ 2] = (feedbuffer
[j
+ out_vertex_size
* 0 + 4] - 0.5) * 4 * max_z
; /* z, triangle 1 */
971 if(patch
->has_normals
) {
972 patch
->mem
[i
+ 3] = feedbuffer
[j
+ out_vertex_size
* 0 + 5];
973 patch
->mem
[i
+ 4] = feedbuffer
[j
+ out_vertex_size
* 0 + 6];
974 patch
->mem
[i
+ 5] = feedbuffer
[j
+ out_vertex_size
* 0 + 7];
976 i
+= d3d_out_vertex_size
;
979 if(patch
->has_normals
) {
980 /* Now do the same with reverse light directions */
981 static const GLfloat x
[] = {-1, 0, 0, 0};
982 static const GLfloat y
[] = { 0, -1, 0, 0};
983 static const GLfloat z
[] = { 0, 0, -1, 0};
984 glLightfv(GL_LIGHT0
, GL_POSITION
, x
);
985 glLightfv(GL_LIGHT1
, GL_POSITION
, y
);
986 glLightfv(GL_LIGHT2
, GL_POSITION
, z
);
987 checkGLcall("Setting up reverse light directions\n");
989 glRenderMode(GL_FEEDBACK
);
990 checkGLcall("glRenderMode(GL_FEEDBACK)");
991 glEvalMesh2(GL_FILL
, 0, ceilf(patch
->numSegs
[0]), 0, ceilf(patch
->numSegs
[1]));
992 checkGLcall("glEvalMesh2\n");
993 i
= glRenderMode(GL_RENDER
);
994 checkGLcall("glRenderMode(GL_RENDER)");
997 for(j
= 0; j
< buffer_size
; j
+= (3 /* num verts */ * out_vertex_size
+ 2 /* tri marker */)) {
998 if(feedbuffer
[j
] != GL_POLYGON_TOKEN
) {
999 ERR("Unexpected token: %f\n", feedbuffer
[j
]);
1002 if(feedbuffer
[j
+ 1] != 3) {
1003 ERR("Unexpected polygon: %f corners\n", feedbuffer
[j
+ 1]);
1006 if(patch
->mem
[i
+ 3] == 0.0)
1007 patch
->mem
[i
+ 3] = -feedbuffer
[j
+ out_vertex_size
* 2 + 5];
1008 if(patch
->mem
[i
+ 4] == 0.0)
1009 patch
->mem
[i
+ 4] = -feedbuffer
[j
+ out_vertex_size
* 2 + 6];
1010 if(patch
->mem
[i
+ 5] == 0.0)
1011 patch
->mem
[i
+ 5] = -feedbuffer
[j
+ out_vertex_size
* 2 + 7];
1012 normalize_normal(patch
->mem
+ i
+ 3);
1013 i
+= d3d_out_vertex_size
;
1015 if(patch
->mem
[i
+ 3] == 0.0)
1016 patch
->mem
[i
+ 3] = -feedbuffer
[j
+ out_vertex_size
* 1 + 5];
1017 if(patch
->mem
[i
+ 4] == 0.0)
1018 patch
->mem
[i
+ 4] = -feedbuffer
[j
+ out_vertex_size
* 1 + 6];
1019 if(patch
->mem
[i
+ 5] == 0.0)
1020 patch
->mem
[i
+ 5] = -feedbuffer
[j
+ out_vertex_size
* 1 + 7];
1021 normalize_normal(patch
->mem
+ i
+ 3);
1022 i
+= d3d_out_vertex_size
;
1024 if(patch
->mem
[i
+ 3] == 0.0)
1025 patch
->mem
[i
+ 3] = -feedbuffer
[j
+ out_vertex_size
* 0 + 5];
1026 if(patch
->mem
[i
+ 4] == 0.0)
1027 patch
->mem
[i
+ 4] = -feedbuffer
[j
+ out_vertex_size
* 0 + 6];
1028 if(patch
->mem
[i
+ 5] == 0.0)
1029 patch
->mem
[i
+ 5] = -feedbuffer
[j
+ out_vertex_size
* 0 + 7];
1030 normalize_normal(patch
->mem
+ i
+ 3);
1031 i
+= d3d_out_vertex_size
;
1035 glDisable(GL_MAP2_VERTEX_3
);
1036 glDisable(GL_AUTO_NORMAL
);
1037 glDisable(GL_MAP2_NORMAL
);
1038 glDisable(GL_MAP2_TEXTURE_COORD_4
);
1039 checkGLcall("glDisable vertex attrib generation");
1042 HeapFree(GetProcessHeap(), 0, feedbuffer
);
1044 vtxStride
= 3 * sizeof(float);
1045 if(patch
->has_normals
) {
1046 vtxStride
+= 3 * sizeof(float);
1048 if(patch
->has_texcoords
) {
1049 vtxStride
+= 4 * sizeof(float);
1051 memset(&patch
->strided
, 0, sizeof(&patch
->strided
));
1052 patch
->strided
.position
.dwType
= WINED3DDECLTYPE_FLOAT3
;
1053 patch
->strided
.position
.lpData
= (BYTE
*) patch
->mem
;
1054 patch
->strided
.position
.dwStride
= vtxStride
;
1056 if(patch
->has_normals
) {
1057 patch
->strided
.normal
.dwType
= WINED3DDECLTYPE_FLOAT3
;
1058 patch
->strided
.normal
.lpData
= (BYTE
*) patch
->mem
+ 3 * sizeof(float) /* pos */;
1059 patch
->strided
.normal
.dwStride
= vtxStride
;
1061 if(patch
->has_texcoords
) {
1062 patch
->strided
.texCoords
[0].dwType
= WINED3DDECLTYPE_FLOAT4
;
1063 patch
->strided
.texCoords
[0].lpData
= (BYTE
*) patch
->mem
+ 3 * sizeof(float) /* pos */;
1064 if(patch
->has_normals
) {
1065 patch
->strided
.texCoords
[0].lpData
+= 3 * sizeof(float);
1067 patch
->strided
.texCoords
[0].dwStride
= vtxStride
;