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 "wined3d_private.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(d3d_draw
);
31 #define GLINFO_LOCATION This->adapter->gl_info
36 /* GL locking is done by the caller */
37 static void drawStridedFast(IWineD3DDevice
*iface
, GLenum primitive_type
,
38 UINT count
, UINT idx_size
, const void *idx_data
, UINT start_idx
)
40 IWineD3DDeviceImpl
*This
= (IWineD3DDeviceImpl
*)iface
;
44 TRACE("(%p) : glElements(%x, %d, ...)\n", This
, primitive_type
, count
);
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");
53 TRACE("(%p) : glDrawArrays(%#x, %d, %d)\n", This
, primitive_type
, start_idx
, count
);
55 glDrawArrays(primitive_type
, start_idx
, count
);
56 checkGLcall("glDrawArrays");
61 * Actually draw using the supplied information.
62 * Slower GL version which extracts info about each vertex in turn
65 /* GL locking is done by the caller */
66 static void drawStridedSlow(IWineD3DDevice
*iface
, const struct wined3d_context
*context
,
67 const struct wined3d_stream_info
*si
, UINT NumVertexes
, GLenum glPrimType
,
68 const void *idxData
, UINT idxSize
, UINT startIdx
)
70 unsigned int textureNo
= 0;
71 const WORD
*pIdxBufS
= NULL
;
72 const DWORD
*pIdxBufL
= NULL
;
74 IWineD3DDeviceImpl
*This
= (IWineD3DDeviceImpl
*)iface
;
75 const UINT
*streamOffset
= This
->stateBlock
->streamOffset
;
76 long SkipnStrides
= startIdx
+ This
->stateBlock
->loadBaseVertexIndex
;
77 BOOL pixelShader
= use_ps(This
->stateBlock
);
78 BOOL specular_fog
= FALSE
;
79 const BYTE
*texCoords
[WINED3DDP_MAXTEXCOORD
];
80 const BYTE
*diffuse
= NULL
, *specular
= NULL
, *normal
= NULL
, *position
= NULL
;
81 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
82 UINT texture_stages
= gl_info
->limits
.texture_stages
;
83 const struct wined3d_stream_info_element
*element
;
84 UINT num_untracked_materials
;
87 TRACE("Using slow vertex array code\n");
89 /* Variable Initialization */
91 /* Immediate mode drawing can't make use of indices in a vbo - get the data from the index buffer.
92 * If the index buffer has no vbo(not supported or other reason), or with user pointer drawing
93 * idxData will be != NULL
96 idxData
= buffer_get_sysmem((struct wined3d_buffer
*) This
->stateBlock
->pIndexData
);
99 if (idxSize
== 2) pIdxBufS
= idxData
;
100 else pIdxBufL
= idxData
;
101 } else if (idxData
) {
102 ERR("non-NULL idxData with 0 idxSize, this should never happen\n");
106 /* Start drawing in GL */
107 VTRACE(("glBegin(%x)\n", glPrimType
));
110 if (si
->use_map
& (1 << WINED3D_FFP_POSITION
))
112 element
= &si
->elements
[WINED3D_FFP_POSITION
];
113 position
= element
->data
+ streamOffset
[element
->stream_idx
];
116 if (si
->use_map
& (1 << WINED3D_FFP_NORMAL
))
118 element
= &si
->elements
[WINED3D_FFP_NORMAL
];
119 normal
= element
->data
+ streamOffset
[element
->stream_idx
];
126 num_untracked_materials
= context
->num_untracked_materials
;
127 if (si
->use_map
& (1 << WINED3D_FFP_DIFFUSE
))
129 element
= &si
->elements
[WINED3D_FFP_DIFFUSE
];
130 diffuse
= element
->data
+ streamOffset
[element
->stream_idx
];
132 if (num_untracked_materials
&& element
->format_desc
->format
!= WINED3DFMT_B8G8R8A8_UNORM
)
133 FIXME("Implement diffuse color tracking from %s\n", debug_d3dformat(element
->format_desc
->format
));
137 glColor4f(1.0f
, 1.0f
, 1.0f
, 1.0f
);
140 if (si
->use_map
& (1 << WINED3D_FFP_SPECULAR
))
142 element
= &si
->elements
[WINED3D_FFP_SPECULAR
];
143 specular
= element
->data
+ streamOffset
[element
->stream_idx
];
145 /* special case where the fog density is stored in the specular alpha channel */
146 if (This
->stateBlock
->renderState
[WINED3DRS_FOGENABLE
]
147 && (This
->stateBlock
->renderState
[WINED3DRS_FOGVERTEXMODE
] == WINED3DFOG_NONE
148 || si
->elements
[WINED3D_FFP_POSITION
].format_desc
->format
== WINED3DFMT_R32G32B32A32_FLOAT
)
149 && This
->stateBlock
->renderState
[WINED3DRS_FOGTABLEMODE
] == WINED3DFOG_NONE
)
151 if (gl_info
->supported
[EXT_FOG_COORD
])
153 if (element
->format_desc
->format
== WINED3DFMT_B8G8R8A8_UNORM
) specular_fog
= TRUE
;
154 else FIXME("Implement fog coordinates from %s\n", debug_d3dformat(element
->format_desc
->format
));
162 /* TODO: Use the fog table code from old ddraw */
163 FIXME("Implement fog for transformed vertices in software\n");
169 else if (gl_info
->supported
[EXT_SECONDARY_COLOR
])
171 GL_EXTCALL(glSecondaryColor3fEXT
)(0, 0, 0);
174 for (textureNo
= 0; textureNo
< texture_stages
; ++textureNo
)
176 int coordIdx
= This
->stateBlock
->textureState
[textureNo
][WINED3DTSS_TEXCOORDINDEX
];
177 DWORD texture_idx
= This
->texUnitMap
[textureNo
];
179 if (!gl_info
->supported
[ARB_MULTITEXTURE
] && textureNo
> 0)
181 FIXME("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
185 if (!pixelShader
&& !This
->stateBlock
->textures
[textureNo
]) continue;
187 if (texture_idx
== WINED3D_UNMAPPED_STAGE
) continue;
191 TRACE("tex: %d - Skip tex coords, as being system generated\n", textureNo
);
194 else if (coordIdx
< 0)
196 FIXME("tex: %d - Coord index %d is less than zero, expect a crash.\n", textureNo
, coordIdx
);
200 if (si
->use_map
& (1 << (WINED3D_FFP_TEXCOORD0
+ coordIdx
)))
202 element
= &si
->elements
[WINED3D_FFP_TEXCOORD0
+ coordIdx
];
203 texCoords
[coordIdx
] = element
->data
+ streamOffset
[element
->stream_idx
];
204 tex_mask
|= (1 << textureNo
);
208 TRACE("tex: %d - Skipping tex coords, as no data supplied\n", textureNo
);
209 if (gl_info
->supported
[ARB_MULTITEXTURE
])
210 GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB
+ texture_idx
, 0, 0, 0, 1));
212 glTexCoord4f(0, 0, 0, 1);
216 /* We shouldn't start this function if any VBO is involved. Should I put a safety check here?
217 * Guess it's not necessary(we crash then anyway) and would only eat CPU time
220 /* For each primitive */
221 for (vx_index
= 0; vx_index
< NumVertexes
; ++vx_index
) {
222 UINT texture
, tmp_tex_mask
;
223 /* Blending data and Point sizes are not supported by this function. They are not supported by the fixed
224 * function pipeline at all. A Fixme for them is printed after decoding the vertex declaration
227 /* For indexed data, we need to go a few more strides in */
228 if (idxData
!= NULL
) {
230 /* Indexed so work out the number of strides to skip */
232 VTRACE(("Idx for vertex %u = %u\n", vx_index
, pIdxBufS
[startIdx
+vx_index
]));
233 SkipnStrides
= pIdxBufS
[startIdx
+ vx_index
] + This
->stateBlock
->loadBaseVertexIndex
;
235 VTRACE(("Idx for vertex %u = %u\n", vx_index
, pIdxBufL
[startIdx
+vx_index
]));
236 SkipnStrides
= pIdxBufL
[startIdx
+ vx_index
] + This
->stateBlock
->loadBaseVertexIndex
;
240 tmp_tex_mask
= tex_mask
;
241 for (texture
= 0; tmp_tex_mask
; tmp_tex_mask
>>= 1, ++texture
)
247 if (!(tmp_tex_mask
& 1)) continue;
249 coord_idx
= This
->stateBlock
->textureState
[texture
][WINED3DTSS_TEXCOORDINDEX
];
250 ptr
= texCoords
[coord_idx
] + (SkipnStrides
* si
->elements
[WINED3D_FFP_TEXCOORD0
+ coord_idx
].stride
);
252 texture_idx
= This
->texUnitMap
[texture
];
253 multi_texcoord_funcs
[si
->elements
[WINED3D_FFP_TEXCOORD0
+ coord_idx
].format_desc
->emit_idx
](
254 GL_TEXTURE0_ARB
+ texture_idx
, ptr
);
257 /* Diffuse -------------------------------- */
259 const void *ptrToCoords
= diffuse
+ SkipnStrides
* si
->elements
[WINED3D_FFP_DIFFUSE
].stride
;
261 diffuse_funcs
[si
->elements
[WINED3D_FFP_DIFFUSE
].format_desc
->emit_idx
](ptrToCoords
);
262 if (num_untracked_materials
)
264 DWORD diffuseColor
= ((const DWORD
*)ptrToCoords
)[0];
268 color
[0] = D3DCOLOR_B_R(diffuseColor
) / 255.0f
;
269 color
[1] = D3DCOLOR_B_G(diffuseColor
) / 255.0f
;
270 color
[2] = D3DCOLOR_B_B(diffuseColor
) / 255.0f
;
271 color
[3] = D3DCOLOR_B_A(diffuseColor
) / 255.0f
;
273 for (i
= 0; i
< num_untracked_materials
; ++i
)
275 glMaterialfv(GL_FRONT_AND_BACK
, context
->untracked_materials
[i
], color
);
280 /* Specular ------------------------------- */
282 const void *ptrToCoords
= specular
+ SkipnStrides
* si
->elements
[WINED3D_FFP_SPECULAR
].stride
;
284 specular_funcs
[si
->elements
[WINED3D_FFP_SPECULAR
].format_desc
->emit_idx
](ptrToCoords
);
288 DWORD specularColor
= *(const DWORD
*)ptrToCoords
;
289 GL_EXTCALL(glFogCoordfEXT(specularColor
>> 24));
293 /* Normal -------------------------------- */
294 if (normal
!= NULL
) {
295 const void *ptrToCoords
= normal
+ SkipnStrides
* si
->elements
[WINED3D_FFP_NORMAL
].stride
;
296 normal_funcs
[si
->elements
[WINED3D_FFP_NORMAL
].format_desc
->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_desc
->emit_idx
](ptrToCoords
);
305 /* For non indexed mode, step onto next parts */
306 if (idxData
== NULL
) {
312 checkGLcall("glEnd and previous calls");
315 /* GL locking is done by the caller */
316 static inline void send_attribute(IWineD3DDeviceImpl
*This
, WINED3DFORMAT format
, const UINT index
, const void *ptr
)
318 const struct wined3d_gl_info
*gl_info
= &This
->adapter
->gl_info
;
322 case WINED3DFMT_R32_FLOAT
:
323 GL_EXTCALL(glVertexAttrib1fvARB(index
, ptr
));
325 case WINED3DFMT_R32G32_FLOAT
:
326 GL_EXTCALL(glVertexAttrib2fvARB(index
, ptr
));
328 case WINED3DFMT_R32G32B32_FLOAT
:
329 GL_EXTCALL(glVertexAttrib3fvARB(index
, ptr
));
331 case WINED3DFMT_R32G32B32A32_FLOAT
:
332 GL_EXTCALL(glVertexAttrib4fvARB(index
, ptr
));
335 case WINED3DFMT_R8G8B8A8_UINT
:
336 GL_EXTCALL(glVertexAttrib4ubvARB(index
, ptr
));
338 case WINED3DFMT_B8G8R8A8_UNORM
:
339 if (gl_info
->supported
[EXT_VERTEX_ARRAY_BGRA
])
341 const DWORD
*src
= ptr
;
342 DWORD c
= *src
& 0xff00ff00;
343 c
|= (*src
& 0xff0000) >> 16;
344 c
|= (*src
& 0xff) << 16;
345 GL_EXTCALL(glVertexAttrib4NubvARB(index
, (GLubyte
*)&c
));
348 /* else fallthrough */
349 case WINED3DFMT_R8G8B8A8_UNORM
:
350 GL_EXTCALL(glVertexAttrib4NubvARB(index
, ptr
));
353 case WINED3DFMT_R16G16_SINT
:
354 GL_EXTCALL(glVertexAttrib4svARB(index
, ptr
));
356 case WINED3DFMT_R16G16B16A16_SINT
:
357 GL_EXTCALL(glVertexAttrib4svARB(index
, ptr
));
360 case WINED3DFMT_R16G16_SNORM
:
362 GLshort s
[4] = {((const GLshort
*)ptr
)[0], ((const GLshort
*)ptr
)[1], 0, 1};
363 GL_EXTCALL(glVertexAttrib4NsvARB(index
, s
));
366 case WINED3DFMT_R16G16_UNORM
:
368 GLushort s
[4] = {((const GLushort
*)ptr
)[0], ((const GLushort
*)ptr
)[1], 0, 1};
369 GL_EXTCALL(glVertexAttrib4NusvARB(index
, s
));
372 case WINED3DFMT_R16G16B16A16_SNORM
:
373 GL_EXTCALL(glVertexAttrib4NsvARB(index
, ptr
));
375 case WINED3DFMT_R16G16B16A16_UNORM
:
376 GL_EXTCALL(glVertexAttrib4NusvARB(index
, ptr
));
379 case WINED3DFMT_R10G10B10A2_UINT
:
380 FIXME("Unsure about WINED3DDECLTYPE_UDEC3\n");
381 /*glVertexAttrib3usvARB(instancedData[j], (GLushort *) ptr); Does not exist */
383 case WINED3DFMT_R10G10B10A2_SNORM
:
384 FIXME("Unsure about WINED3DDECLTYPE_DEC3N\n");
385 /*glVertexAttrib3NusvARB(instancedData[j], (GLushort *) ptr); Does not exist */
388 case WINED3DFMT_R16G16_FLOAT
:
389 /* Are those 16 bit floats. C doesn't have a 16 bit float type. I could read the single bits and calculate a 4
390 * byte float according to the IEEE standard
392 if (gl_info
->supported
[NV_HALF_FLOAT
])
394 /* Not supported by GL_ARB_half_float_vertex */
395 GL_EXTCALL(glVertexAttrib2hvNV(index
, ptr
));
399 float x
= float_16_to_32(((const unsigned short *)ptr
) + 0);
400 float y
= float_16_to_32(((const unsigned short *)ptr
) + 1);
401 GL_EXTCALL(glVertexAttrib2fARB(index
, x
, y
));
404 case WINED3DFMT_R16G16B16A16_FLOAT
:
405 if (gl_info
->supported
[NV_HALF_FLOAT
])
407 /* Not supported by GL_ARB_half_float_vertex */
408 GL_EXTCALL(glVertexAttrib4hvNV(index
, ptr
));
412 float x
= float_16_to_32(((const unsigned short *)ptr
) + 0);
413 float y
= float_16_to_32(((const unsigned short *)ptr
) + 1);
414 float z
= float_16_to_32(((const unsigned short *)ptr
) + 2);
415 float w
= float_16_to_32(((const unsigned short *)ptr
) + 3);
416 GL_EXTCALL(glVertexAttrib4fARB(index
, x
, y
, z
, w
));
421 ERR("Unexpected attribute format: %s\n", debug_d3dformat(format
));
426 /* GL locking is done by the caller */
427 static void drawStridedSlowVs(IWineD3DDevice
*iface
, const struct wined3d_stream_info
*si
, UINT numberOfVertices
,
428 GLenum glPrimitiveType
, const void *idxData
, UINT idxSize
, UINT startIdx
)
430 IWineD3DDeviceImpl
*This
= (IWineD3DDeviceImpl
*) iface
;
431 long SkipnStrides
= startIdx
+ This
->stateBlock
->loadBaseVertexIndex
;
432 const WORD
*pIdxBufS
= NULL
;
433 const DWORD
*pIdxBufL
= NULL
;
436 IWineD3DStateBlockImpl
*stateblock
= This
->stateBlock
;
440 /* Immediate mode drawing can't make use of indices in a vbo - get the data from the index buffer.
441 * If the index buffer has no vbo(not supported or other reason), or with user pointer drawing
442 * idxData will be != NULL
444 if(idxData
== NULL
) {
445 idxData
= buffer_get_sysmem((struct wined3d_buffer
*) This
->stateBlock
->pIndexData
);
448 if (idxSize
== 2) pIdxBufS
= idxData
;
449 else pIdxBufL
= idxData
;
450 } else if (idxData
) {
451 ERR("non-NULL idxData with 0 idxSize, this should never happen\n");
455 /* Start drawing in GL */
456 VTRACE(("glBegin(%x)\n", glPrimitiveType
));
457 glBegin(glPrimitiveType
);
459 for (vx_index
= 0; vx_index
< numberOfVertices
; ++vx_index
) {
460 if (idxData
!= NULL
) {
462 /* Indexed so work out the number of strides to skip */
464 VTRACE(("Idx for vertex %d = %d\n", vx_index
, pIdxBufS
[startIdx
+vx_index
]));
465 SkipnStrides
= pIdxBufS
[startIdx
+ vx_index
] + stateblock
->loadBaseVertexIndex
;
467 VTRACE(("Idx for vertex %d = %d\n", vx_index
, pIdxBufL
[startIdx
+vx_index
]));
468 SkipnStrides
= pIdxBufL
[startIdx
+ vx_index
] + stateblock
->loadBaseVertexIndex
;
472 for (i
= MAX_ATTRIBS
- 1; i
>= 0; i
--)
474 if (!(si
->use_map
& (1 << i
))) continue;
476 ptr
= si
->elements
[i
].data
+
477 si
->elements
[i
].stride
* SkipnStrides
+
478 stateblock
->streamOffset
[si
->elements
[i
].stream_idx
];
480 send_attribute(This
, si
->elements
[i
].format_desc
->format
, i
, ptr
);
488 /* GL locking is done by the caller */
489 static inline void drawStridedInstanced(IWineD3DDevice
*iface
, const struct wined3d_stream_info
*si
,
490 UINT numberOfVertices
, GLenum glPrimitiveType
, const void *idxData
, UINT idxSize
,
493 UINT numInstances
= 0, i
;
494 int numInstancedAttribs
= 0, j
;
495 UINT instancedData
[sizeof(si
->elements
) / sizeof(*si
->elements
) /* 16 */];
496 IWineD3DDeviceImpl
*This
= (IWineD3DDeviceImpl
*) iface
;
497 IWineD3DStateBlockImpl
*stateblock
= This
->stateBlock
;
500 /* This is a nasty thing. MSDN says no hardware supports that and apps have to use software vertex processing.
501 * We don't support this for now
503 * Shouldn't be too hard to support with opengl, in theory just call glDrawArrays instead of drawElements.
504 * But the StreamSourceFreq value has a different meaning in that situation.
506 FIXME("Non-indexed instanced drawing is not supported\n");
510 TRACE("(%p) : glElements(%x, %d, ...)\n", This
, glPrimitiveType
, numberOfVertices
);
512 /* First, figure out how many instances we have to draw */
513 for(i
= 0; i
< MAX_STREAMS
; i
++) {
514 /* Look at the streams and take the first one which matches */
515 if(((stateblock
->streamFlags
[i
] & WINED3DSTREAMSOURCE_INSTANCEDATA
) || (stateblock
->streamFlags
[i
] & WINED3DSTREAMSOURCE_INDEXEDDATA
)) && stateblock
->streamSource
[i
]) {
516 /* D3D9 could set streamFreq 0 with (INSTANCEDATA or INDEXEDDATA) and then it is handled as 1. See d3d9/tests/visual.c-> stream_test() */
517 if(stateblock
->streamFreq
[i
] == 0){
520 numInstances
= stateblock
->streamFreq
[i
]; /* use the specified number of instances from the first matched stream. See d3d9/tests/visual.c-> stream_test() */
522 break; /* break, because only the first suitable value is interesting */
526 for (i
= 0; i
< sizeof(si
->elements
) / sizeof(*si
->elements
); ++i
)
528 if (!(si
->use_map
& (1 << i
))) continue;
530 if (stateblock
->streamFlags
[si
->elements
[i
].stream_idx
] & WINED3DSTREAMSOURCE_INSTANCEDATA
)
532 instancedData
[numInstancedAttribs
] = i
;
533 numInstancedAttribs
++;
537 /* now draw numInstances instances :-) */
538 for(i
= 0; i
< numInstances
; i
++) {
539 /* Specify the instanced attributes using immediate mode calls */
540 for(j
= 0; j
< numInstancedAttribs
; j
++) {
541 const BYTE
*ptr
= si
->elements
[instancedData
[j
]].data
+
542 si
->elements
[instancedData
[j
]].stride
* i
+
543 stateblock
->streamOffset
[si
->elements
[instancedData
[j
]].stream_idx
];
544 if (si
->elements
[instancedData
[j
]].buffer_object
)
546 struct wined3d_buffer
*vb
=
547 (struct wined3d_buffer
*)stateblock
->streamSource
[si
->elements
[instancedData
[j
]].stream_idx
];
548 ptr
+= (long) buffer_get_sysmem(vb
);
551 send_attribute(This
, si
->elements
[instancedData
[j
]].format_desc
->format
, instancedData
[j
], ptr
);
554 glDrawElements(glPrimitiveType
, numberOfVertices
, idxSize
== 2 ? GL_UNSIGNED_SHORT
: GL_UNSIGNED_INT
,
555 (const char *)idxData
+(idxSize
* startIdx
));
556 checkGLcall("glDrawElements");
560 static inline void remove_vbos(IWineD3DDeviceImpl
*This
, struct wined3d_stream_info
*s
)
564 for (i
= 0; i
< (sizeof(s
->elements
) / sizeof(*s
->elements
)); ++i
)
566 struct wined3d_stream_info_element
*e
;
568 if (!(s
->use_map
& (1 << i
))) continue;
571 if (e
->buffer_object
)
573 struct wined3d_buffer
*vb
= (struct wined3d_buffer
*)This
->stateBlock
->streamSource
[e
->stream_idx
];
574 e
->buffer_object
= 0;
575 e
->data
= (BYTE
*)((unsigned long)e
->data
+ (unsigned long)buffer_get_sysmem(vb
));
580 /* Routine common to the draw primitive and draw indexed primitive routines */
581 void drawPrimitive(IWineD3DDevice
*iface
, UINT index_count
, UINT StartIdx
, UINT idxSize
, const void *idxData
)
584 IWineD3DDeviceImpl
*This
= (IWineD3DDeviceImpl
*)iface
;
585 IWineD3DSurfaceImpl
*target
;
586 struct wined3d_context
*context
;
589 if (!index_count
) return;
591 if (This
->stateBlock
->renderState
[WINED3DRS_COLORWRITEENABLE
])
593 /* Invalidate the back buffer memory so LockRect will read it the next time */
594 for (i
= 0; i
< This
->adapter
->gl_info
.limits
.buffers
; ++i
)
596 target
= (IWineD3DSurfaceImpl
*)This
->render_targets
[i
];
599 IWineD3DSurface_LoadLocation((IWineD3DSurface
*)target
, SFLAG_INDRAWABLE
, NULL
);
600 IWineD3DSurface_ModifyLocation((IWineD3DSurface
*)target
, SFLAG_INDRAWABLE
, TRUE
);
605 /* Signals other modules that a drawing is in progress and the stateblock finalized */
606 This
->isInDraw
= TRUE
;
608 context
= context_acquire(This
, This
->render_targets
[0], CTXUSAGE_DRAWPRIM
);
610 if (This
->stencilBufferTarget
) {
611 /* Note that this depends on the context_acquire() call above to set
612 * This->render_offscreen properly. We don't currently take the
613 * Z-compare function into account, but we could skip loading the
614 * depthstencil for D3DCMP_NEVER and D3DCMP_ALWAYS as well. Also note
615 * that we never copy the stencil data.*/
616 DWORD location
= context
->render_offscreen
? SFLAG_DS_OFFSCREEN
: SFLAG_DS_ONSCREEN
;
617 if (This
->stateBlock
->renderState
[WINED3DRS_ZWRITEENABLE
]
618 || This
->stateBlock
->renderState
[WINED3DRS_ZENABLE
])
619 surface_load_ds_location(This
->stencilBufferTarget
, context
, location
);
620 if (This
->stateBlock
->renderState
[WINED3DRS_ZWRITEENABLE
])
621 surface_modify_ds_location(This
->stencilBufferTarget
, location
);
624 /* Ok, we will be updating the screen from here onwards so grab the lock */
627 GLenum glPrimType
= This
->stateBlock
->gl_primitive_type
;
628 BOOL emulation
= FALSE
;
629 const struct wined3d_stream_info
*stream_info
= &This
->strided_streams
;
630 struct wined3d_stream_info stridedlcl
;
632 if (!use_vs(This
->stateBlock
))
634 if (!This
->strided_streams
.position_transformed
&& context
->num_untracked_materials
635 && This
->stateBlock
->renderState
[WINED3DRS_LIGHTING
])
639 FIXME("Using software emulation because not all material properties could be tracked\n");
642 TRACE("Using software emulation because not all material properties could be tracked\n");
646 else if (context
->fog_coord
&& This
->stateBlock
->renderState
[WINED3DRS_FOGENABLE
])
648 /* Either write a pipeline replacement shader or convert the specular alpha from unsigned byte
649 * to a float in the vertex buffer
653 FIXME("Using software emulation because manual fog coordinates are provided\n");
656 TRACE("Using software emulation because manual fog coordinates are provided\n");
662 stream_info
= &stridedlcl
;
663 memcpy(&stridedlcl
, &This
->strided_streams
, sizeof(stridedlcl
));
664 remove_vbos(This
, &stridedlcl
);
668 if (This
->useDrawStridedSlow
|| emulation
) {
669 /* Immediate mode drawing */
670 if (use_vs(This
->stateBlock
))
674 FIXME("Using immediate mode with vertex shaders for half float emulation\n");
677 TRACE("Using immediate mode with vertex shaders for half float emulation\n");
679 drawStridedSlowVs(iface
, stream_info
, index_count
, glPrimType
, idxData
, idxSize
, StartIdx
);
681 drawStridedSlow(iface
, context
, stream_info
, index_count
,
682 glPrimType
, idxData
, idxSize
, StartIdx
);
684 } else if(This
->instancedDraw
) {
685 /* Instancing emulation with mixing immediate mode and arrays */
686 drawStridedInstanced(iface
, &This
->strided_streams
, index_count
,
687 glPrimType
, idxData
, idxSize
, StartIdx
);
689 drawStridedFast(iface
, glPrimType
, index_count
, idxSize
, idxData
, StartIdx
);
693 /* Finished updating the screen, restore lock */
695 context_release(context
);
697 TRACE("Done all gl drawing\n");
700 #ifdef SHOW_FRAME_MAKEUP
702 static long int primCounter
= 0;
703 /* NOTE: set primCounter to the value reported by drawprim
704 before you want to to write frame makeup to /tmp */
705 if (primCounter
>= 0) {
706 WINED3DLOCKED_RECT r
;
708 IWineD3DSurface_LockRect(This
->render_targets
[0], &r
, NULL
, WINED3DLOCK_READONLY
);
709 sprintf(buffer
, "/tmp/backbuffer_%ld.tga", primCounter
);
710 TRACE("Saving screenshot %s\n", buffer
);
711 IWineD3DSurface_SaveSnapshot(This
->render_targets
[0], buffer
);
712 IWineD3DSurface_UnlockRect(This
->render_targets
[0]);
714 #ifdef SHOW_TEXTURE_MAKEUP
716 IWineD3DSurface
*pSur
;
718 for (textureNo
= 0; textureNo
< MAX_COMBINED_SAMPLERS
; ++textureNo
) {
719 if (This
->stateBlock
->textures
[textureNo
] != NULL
) {
720 sprintf(buffer
, "/tmp/texture_%p_%ld_%d.tga", This
->stateBlock
->textures
[textureNo
], primCounter
, textureNo
);
721 TRACE("Saving texture %s\n", buffer
);
722 if (IWineD3DBaseTexture_GetType(This
->stateBlock
->textures
[textureNo
]) == WINED3DRTYPE_TEXTURE
) {
723 IWineD3DTexture_GetSurfaceLevel(This
->stateBlock
->textures
[textureNo
], 0, &pSur
);
724 IWineD3DSurface_SaveSnapshot(pSur
, buffer
);
725 IWineD3DSurface_Release(pSur
);
727 FIXME("base Texture isn't of type texture %d\n", IWineD3DBaseTexture_GetType(This
->stateBlock
->textures
[textureNo
]));
734 TRACE("drawprim #%ld\n", primCounter
);
739 /* Control goes back to the device, stateblock values may change again */
740 This
->isInDraw
= FALSE
;
743 static void normalize_normal(float *n
) {
744 float length
= n
[0] * n
[0] + n
[1] * n
[1] + n
[2] * n
[2];
745 if (length
== 0.0f
) return;
746 length
= sqrt(length
);
747 n
[0] = n
[0] / length
;
748 n
[1] = n
[1] / length
;
749 n
[2] = n
[2] / length
;
752 /* Tesselates a high order rectangular patch into single triangles using gl evaluators
754 * The problem is that OpenGL does not offer a direct way to return the tesselated primitives,
755 * and they can't be sent off for rendering directly either. Tesselating is slow, so we want
756 * to cache the patches in a vertex buffer. But more importantly, gl can't bind generated
757 * attributes to numbered shader attributes, so we have to store them and rebind them as needed
760 * To read back, the opengl feedback mode is used. This creates a problem because we want
761 * untransformed, unlit vertices, but feedback runs everything through transform and lighting.
762 * Thus disable lighting and set identity matrices to get unmodified colors and positions.
763 * To overcome clipping find the biggest x, y and z values of the vertices in the patch and scale
764 * them to [-1.0;+1.0] and set the viewport up to scale them back.
766 * Normals are more tricky: Draw white vertices with 3 directional lights, and calculate the
767 * resulting colors back to the normals.
769 * NOTE: This function activates a context for blitting, modifies matrices & viewport, but
770 * does not restore it because normally a draw follows immediately afterwards. The caller is
771 * responsible of taking care that either the gl states are restored, or the context activated
772 * for drawing to reset the lastWasBlit flag.
774 HRESULT
tesselate_rectpatch(IWineD3DDeviceImpl
*This
,
775 struct WineD3DRectPatch
*patch
) {
776 unsigned int i
, j
, num_quads
, out_vertex_size
, buffer_size
, d3d_out_vertex_size
;
777 float max_x
= 0.0f
, max_y
= 0.0f
, max_z
= 0.0f
, neg_z
= 0.0f
;
778 struct wined3d_stream_info stream_info
;
779 struct wined3d_stream_info_element
*e
;
780 struct wined3d_context
*context
;
782 const WINED3DRECTPATCH_INFO
*info
= &patch
->RectPatchInfo
;
784 GLenum feedback_type
;
787 /* Simply activate the context for blitting. This disables all the things we don't want and
788 * takes care of dirtifying. Dirtifying is preferred over pushing / popping, since drawing the
789 * patch (as opposed to normal draws) will most likely need different changes anyway. */
790 context
= context_acquire(This
, NULL
, CTXUSAGE_BLIT
);
792 /* First, locate the position data. This is provided in a vertex buffer in the stateblock.
795 device_stream_info_from_declaration(This
, FALSE
, &stream_info
, NULL
);
797 e
= &stream_info
.elements
[WINED3D_FFP_POSITION
];
798 if (e
->buffer_object
)
800 struct wined3d_buffer
*vb
;
801 vb
= (struct wined3d_buffer
*)This
->stateBlock
->streamSource
[e
->stream_idx
];
802 e
->data
= (BYTE
*)((unsigned long)e
->data
+ (unsigned long)buffer_get_sysmem(vb
));
804 vtxStride
= e
->stride
;
806 vtxStride
* info
->Stride
* info
->StartVertexOffsetHeight
+
807 vtxStride
* info
->StartVertexOffsetWidth
;
809 /* Not entirely sure about what happens with transformed vertices */
810 if (stream_info
.position_transformed
) FIXME("Transformed position in rectpatch generation\n");
812 if(vtxStride
% sizeof(GLfloat
)) {
813 /* glMap2f reads vertex sizes in GLfloats, the d3d stride is in bytes.
814 * I don't see how the stride could not be a multiple of 4, but make sure
817 ERR("Vertex stride is not a multiple of sizeof(GLfloat)\n");
819 if(info
->Basis
!= WINED3DBASIS_BEZIER
) {
820 FIXME("Basis is %s, how to handle this?\n", debug_d3dbasis(info
->Basis
));
822 if(info
->Degree
!= WINED3DDEGREE_CUBIC
) {
823 FIXME("Degree is %s, how to handle this?\n", debug_d3ddegree(info
->Degree
));
826 /* First, get the boundary cube of the input data */
827 for(j
= 0; j
< info
->Height
; j
++) {
828 for(i
= 0; i
< info
->Width
; i
++) {
829 const float *v
= (const float *)(data
+ vtxStride
* i
+ vtxStride
* info
->Stride
* j
);
830 if(fabs(v
[0]) > max_x
) max_x
= fabs(v
[0]);
831 if(fabs(v
[1]) > max_y
) max_y
= fabs(v
[1]);
832 if(fabs(v
[2]) > max_z
) max_z
= fabs(v
[2]);
833 if(v
[2] < neg_z
) neg_z
= v
[2];
837 /* This needs some improvements in the vertex decl code */
838 FIXME("Cannot find data to generate. Only generating position and normals\n");
839 patch
->has_normals
= TRUE
;
840 patch
->has_texcoords
= FALSE
;
844 glMatrixMode(GL_PROJECTION
);
845 checkGLcall("glMatrixMode(GL_PROJECTION)");
847 checkGLcall("glLoadIndentity()");
848 glScalef(1.0f
/ (max_x
), 1.0f
/ (max_y
), max_z
== 0.0f
? 1.0f
: 1.0f
/ (2.0f
* max_z
));
849 glTranslatef(0.0f
, 0.0f
, 0.5f
);
850 checkGLcall("glScalef");
851 glViewport(-max_x
, -max_y
, 2 * (max_x
), 2 * (max_y
));
852 checkGLcall("glViewport");
854 /* Some states to take care of. If we're in wireframe opengl will produce lines, and confuse
855 * our feedback buffer parser
857 glPolygonMode(GL_FRONT_AND_BACK
, GL_FILL
);
858 checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)");
859 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_RENDER(WINED3DRS_FILLMODE
));
860 if(patch
->has_normals
) {
861 static const GLfloat black
[] = {0.0f
, 0.0f
, 0.0f
, 0.0f
};
862 static const GLfloat red
[] = {1.0f
, 0.0f
, 0.0f
, 0.0f
};
863 static const GLfloat green
[] = {0.0f
, 1.0f
, 0.0f
, 0.0f
};
864 static const GLfloat blue
[] = {0.0f
, 0.0f
, 1.0f
, 0.0f
};
865 static const GLfloat white
[] = {1.0f
, 1.0f
, 1.0f
, 1.0f
};
866 glEnable(GL_LIGHTING
);
867 checkGLcall("glEnable(GL_LIGHTING)");
868 glLightModelfv(GL_LIGHT_MODEL_AMBIENT
, black
);
869 checkGLcall("glLightModel for MODEL_AMBIENT");
870 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_RENDER(WINED3DRS_AMBIENT
));
872 for (i
= 3; i
< context
->gl_info
->limits
.lights
; ++i
)
874 glDisable(GL_LIGHT0
+ i
);
875 checkGLcall("glDisable(GL_LIGHT0 + i)");
876 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_ACTIVELIGHT(i
));
879 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_ACTIVELIGHT(0));
880 glLightfv(GL_LIGHT0
, GL_DIFFUSE
, red
);
881 glLightfv(GL_LIGHT0
, GL_SPECULAR
, black
);
882 glLightfv(GL_LIGHT0
, GL_AMBIENT
, black
);
883 glLightfv(GL_LIGHT0
, GL_POSITION
, red
);
885 checkGLcall("Setting up light 1");
886 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_ACTIVELIGHT(1));
887 glLightfv(GL_LIGHT1
, GL_DIFFUSE
, green
);
888 glLightfv(GL_LIGHT1
, GL_SPECULAR
, black
);
889 glLightfv(GL_LIGHT1
, GL_AMBIENT
, black
);
890 glLightfv(GL_LIGHT1
, GL_POSITION
, green
);
892 checkGLcall("Setting up light 2");
893 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_ACTIVELIGHT(2));
894 glLightfv(GL_LIGHT2
, GL_DIFFUSE
, blue
);
895 glLightfv(GL_LIGHT2
, GL_SPECULAR
, black
);
896 glLightfv(GL_LIGHT2
, GL_AMBIENT
, black
);
897 glLightfv(GL_LIGHT2
, GL_POSITION
, blue
);
899 checkGLcall("Setting up light 3");
901 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_MATERIAL
);
902 IWineD3DDeviceImpl_MarkStateDirty(This
, STATE_RENDER(WINED3DRS_COLORVERTEX
));
903 glDisable(GL_COLOR_MATERIAL
);
904 glMaterialfv(GL_FRONT_AND_BACK
, GL_EMISSION
, black
);
905 glMaterialfv(GL_FRONT_AND_BACK
, GL_SPECULAR
, black
);
906 glMaterialfv(GL_FRONT_AND_BACK
, GL_DIFFUSE
, white
);
907 checkGLcall("Setting up materials");
910 /* Enable the needed maps.
911 * GL_MAP2_VERTEX_3 is needed for positional data.
912 * GL_AUTO_NORMAL to generate normals from the position. Do not use GL_MAP2_NORMAL.
913 * GL_MAP2_TEXTURE_COORD_4 for texture coords
915 num_quads
= ceilf(patch
->numSegs
[0]) * ceilf(patch
->numSegs
[1]);
916 out_vertex_size
= 3 /* position */;
917 d3d_out_vertex_size
= 3;
918 glEnable(GL_MAP2_VERTEX_3
);
919 if(patch
->has_normals
&& patch
->has_texcoords
) {
920 FIXME("Texcoords not handled yet\n");
921 feedback_type
= GL_3D_COLOR_TEXTURE
;
922 out_vertex_size
+= 8;
923 d3d_out_vertex_size
+= 7;
924 glEnable(GL_AUTO_NORMAL
);
925 glEnable(GL_MAP2_TEXTURE_COORD_4
);
926 } else if(patch
->has_texcoords
) {
927 FIXME("Texcoords not handled yet\n");
928 feedback_type
= GL_3D_COLOR_TEXTURE
;
929 out_vertex_size
+= 7;
930 d3d_out_vertex_size
+= 4;
931 glEnable(GL_MAP2_TEXTURE_COORD_4
);
932 } else if(patch
->has_normals
) {
933 feedback_type
= GL_3D_COLOR
;
934 out_vertex_size
+= 4;
935 d3d_out_vertex_size
+= 3;
936 glEnable(GL_AUTO_NORMAL
);
938 feedback_type
= GL_3D
;
940 checkGLcall("glEnable vertex attrib generation");
942 buffer_size
= num_quads
* out_vertex_size
* 2 /* triangle list */ * 3 /* verts per tri */
943 + 4 * num_quads
/* 2 triangle markers per quad + num verts in tri */;
944 feedbuffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, buffer_size
* sizeof(float) * 8);
946 glMap2f(GL_MAP2_VERTEX_3
,
947 0.0f
, 1.0f
, vtxStride
/ sizeof(float), info
->Width
,
948 0.0f
, 1.0f
, info
->Stride
* vtxStride
/ sizeof(float), info
->Height
,
949 (const GLfloat
*)data
);
950 checkGLcall("glMap2f");
951 if(patch
->has_texcoords
) {
952 glMap2f(GL_MAP2_TEXTURE_COORD_4
,
953 0.0f
, 1.0f
, vtxStride
/ sizeof(float), info
->Width
,
954 0.0f
, 1.0f
, info
->Stride
* vtxStride
/ sizeof(float), info
->Height
,
955 (const GLfloat
*)data
);
956 checkGLcall("glMap2f");
958 glMapGrid2f(ceilf(patch
->numSegs
[0]), 0.0f
, 1.0f
, ceilf(patch
->numSegs
[1]), 0.0f
, 1.0f
);
959 checkGLcall("glMapGrid2f");
961 glFeedbackBuffer(buffer_size
* 2, feedback_type
, feedbuffer
);
962 checkGLcall("glFeedbackBuffer");
963 glRenderMode(GL_FEEDBACK
);
965 glEvalMesh2(GL_FILL
, 0, ceilf(patch
->numSegs
[0]), 0, ceilf(patch
->numSegs
[1]));
966 checkGLcall("glEvalMesh2");
968 i
= glRenderMode(GL_RENDER
);
971 ERR("Feedback failed. Expected %d elements back\n", buffer_size
);
972 HeapFree(GetProcessHeap(), 0, feedbuffer
);
973 context_release(context
);
974 return WINED3DERR_DRIVERINTERNALERROR
;
975 } else if(i
!= buffer_size
) {
977 ERR("Unexpected amount of elements returned. Expected %d, got %d\n", buffer_size
, i
);
978 HeapFree(GetProcessHeap(), 0, feedbuffer
);
979 context_release(context
);
980 return WINED3DERR_DRIVERINTERNALERROR
;
982 TRACE("Got %d elements as expected\n", i
);
985 HeapFree(GetProcessHeap(), 0, patch
->mem
);
986 patch
->mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, num_quads
* 6 * d3d_out_vertex_size
* sizeof(float) * 8);
988 for(j
= 0; j
< buffer_size
; j
+= (3 /* num verts */ * out_vertex_size
+ 2 /* tri marker */)) {
989 if(feedbuffer
[j
] != GL_POLYGON_TOKEN
) {
990 ERR("Unexpected token: %f\n", feedbuffer
[j
]);
993 if(feedbuffer
[j
+ 1] != 3) {
994 ERR("Unexpected polygon: %f corners\n", feedbuffer
[j
+ 1]);
997 /* Somehow there are different ideas about back / front facing, so fix up the
1000 patch
->mem
[i
+ 0] = feedbuffer
[j
+ out_vertex_size
* 2 + 2]; /* x, triangle 2 */
1001 patch
->mem
[i
+ 1] = feedbuffer
[j
+ out_vertex_size
* 2 + 3]; /* y, triangle 2 */
1002 patch
->mem
[i
+ 2] = (feedbuffer
[j
+ out_vertex_size
* 2 + 4] - 0.5f
) * 4.0f
* max_z
; /* z, triangle 3 */
1003 if(patch
->has_normals
) {
1004 patch
->mem
[i
+ 3] = feedbuffer
[j
+ out_vertex_size
* 2 + 5];
1005 patch
->mem
[i
+ 4] = feedbuffer
[j
+ out_vertex_size
* 2 + 6];
1006 patch
->mem
[i
+ 5] = feedbuffer
[j
+ out_vertex_size
* 2 + 7];
1008 i
+= d3d_out_vertex_size
;
1010 patch
->mem
[i
+ 0] = feedbuffer
[j
+ out_vertex_size
* 1 + 2]; /* x, triangle 2 */
1011 patch
->mem
[i
+ 1] = feedbuffer
[j
+ out_vertex_size
* 1 + 3]; /* y, triangle 2 */
1012 patch
->mem
[i
+ 2] = (feedbuffer
[j
+ out_vertex_size
* 1 + 4] - 0.5f
) * 4.0f
* max_z
; /* z, triangle 2 */
1013 if(patch
->has_normals
) {
1014 patch
->mem
[i
+ 3] = feedbuffer
[j
+ out_vertex_size
* 1 + 5];
1015 patch
->mem
[i
+ 4] = feedbuffer
[j
+ out_vertex_size
* 1 + 6];
1016 patch
->mem
[i
+ 5] = feedbuffer
[j
+ out_vertex_size
* 1 + 7];
1018 i
+= d3d_out_vertex_size
;
1020 patch
->mem
[i
+ 0] = feedbuffer
[j
+ out_vertex_size
* 0 + 2]; /* x, triangle 1 */
1021 patch
->mem
[i
+ 1] = feedbuffer
[j
+ out_vertex_size
* 0 + 3]; /* y, triangle 1 */
1022 patch
->mem
[i
+ 2] = (feedbuffer
[j
+ out_vertex_size
* 0 + 4] - 0.5f
) * 4.0f
* max_z
; /* z, triangle 1 */
1023 if(patch
->has_normals
) {
1024 patch
->mem
[i
+ 3] = feedbuffer
[j
+ out_vertex_size
* 0 + 5];
1025 patch
->mem
[i
+ 4] = feedbuffer
[j
+ out_vertex_size
* 0 + 6];
1026 patch
->mem
[i
+ 5] = feedbuffer
[j
+ out_vertex_size
* 0 + 7];
1028 i
+= d3d_out_vertex_size
;
1031 if(patch
->has_normals
) {
1032 /* Now do the same with reverse light directions */
1033 static const GLfloat x
[] = {-1.0f
, 0.0f
, 0.0f
, 0.0f
};
1034 static const GLfloat y
[] = { 0.0f
, -1.0f
, 0.0f
, 0.0f
};
1035 static const GLfloat z
[] = { 0.0f
, 0.0f
, -1.0f
, 0.0f
};
1036 glLightfv(GL_LIGHT0
, GL_POSITION
, x
);
1037 glLightfv(GL_LIGHT1
, GL_POSITION
, y
);
1038 glLightfv(GL_LIGHT2
, GL_POSITION
, z
);
1039 checkGLcall("Setting up reverse light directions");
1041 glRenderMode(GL_FEEDBACK
);
1042 checkGLcall("glRenderMode(GL_FEEDBACK)");
1043 glEvalMesh2(GL_FILL
, 0, ceilf(patch
->numSegs
[0]), 0, ceilf(patch
->numSegs
[1]));
1044 checkGLcall("glEvalMesh2");
1045 i
= glRenderMode(GL_RENDER
);
1046 checkGLcall("glRenderMode(GL_RENDER)");
1049 for(j
= 0; j
< buffer_size
; j
+= (3 /* num verts */ * out_vertex_size
+ 2 /* tri marker */)) {
1050 if(feedbuffer
[j
] != GL_POLYGON_TOKEN
) {
1051 ERR("Unexpected token: %f\n", feedbuffer
[j
]);
1054 if(feedbuffer
[j
+ 1] != 3) {
1055 ERR("Unexpected polygon: %f corners\n", feedbuffer
[j
+ 1]);
1058 if(patch
->mem
[i
+ 3] == 0.0f
)
1059 patch
->mem
[i
+ 3] = -feedbuffer
[j
+ out_vertex_size
* 2 + 5];
1060 if(patch
->mem
[i
+ 4] == 0.0f
)
1061 patch
->mem
[i
+ 4] = -feedbuffer
[j
+ out_vertex_size
* 2 + 6];
1062 if(patch
->mem
[i
+ 5] == 0.0f
)
1063 patch
->mem
[i
+ 5] = -feedbuffer
[j
+ out_vertex_size
* 2 + 7];
1064 normalize_normal(patch
->mem
+ i
+ 3);
1065 i
+= d3d_out_vertex_size
;
1067 if(patch
->mem
[i
+ 3] == 0.0f
)
1068 patch
->mem
[i
+ 3] = -feedbuffer
[j
+ out_vertex_size
* 1 + 5];
1069 if(patch
->mem
[i
+ 4] == 0.0f
)
1070 patch
->mem
[i
+ 4] = -feedbuffer
[j
+ out_vertex_size
* 1 + 6];
1071 if(patch
->mem
[i
+ 5] == 0.0f
)
1072 patch
->mem
[i
+ 5] = -feedbuffer
[j
+ out_vertex_size
* 1 + 7];
1073 normalize_normal(patch
->mem
+ i
+ 3);
1074 i
+= d3d_out_vertex_size
;
1076 if(patch
->mem
[i
+ 3] == 0.0f
)
1077 patch
->mem
[i
+ 3] = -feedbuffer
[j
+ out_vertex_size
* 0 + 5];
1078 if(patch
->mem
[i
+ 4] == 0.0f
)
1079 patch
->mem
[i
+ 4] = -feedbuffer
[j
+ out_vertex_size
* 0 + 6];
1080 if(patch
->mem
[i
+ 5] == 0.0f
)
1081 patch
->mem
[i
+ 5] = -feedbuffer
[j
+ out_vertex_size
* 0 + 7];
1082 normalize_normal(patch
->mem
+ i
+ 3);
1083 i
+= d3d_out_vertex_size
;
1087 glDisable(GL_MAP2_VERTEX_3
);
1088 glDisable(GL_AUTO_NORMAL
);
1089 glDisable(GL_MAP2_NORMAL
);
1090 glDisable(GL_MAP2_TEXTURE_COORD_4
);
1091 checkGLcall("glDisable vertex attrib generation");
1094 context_release(context
);
1096 HeapFree(GetProcessHeap(), 0, feedbuffer
);
1098 vtxStride
= 3 * sizeof(float);
1099 if(patch
->has_normals
) {
1100 vtxStride
+= 3 * sizeof(float);
1102 if(patch
->has_texcoords
) {
1103 vtxStride
+= 4 * sizeof(float);
1105 memset(&patch
->strided
, 0, sizeof(&patch
->strided
));
1106 patch
->strided
.position
.format
= WINED3DFMT_R32G32B32_FLOAT
;
1107 patch
->strided
.position
.lpData
= (BYTE
*) patch
->mem
;
1108 patch
->strided
.position
.dwStride
= vtxStride
;
1110 if(patch
->has_normals
) {
1111 patch
->strided
.normal
.format
= WINED3DFMT_R32G32B32_FLOAT
;
1112 patch
->strided
.normal
.lpData
= (BYTE
*) patch
->mem
+ 3 * sizeof(float) /* pos */;
1113 patch
->strided
.normal
.dwStride
= vtxStride
;
1115 if(patch
->has_texcoords
) {
1116 patch
->strided
.texCoords
[0].format
= WINED3DFMT_R32G32B32A32_FLOAT
;
1117 patch
->strided
.texCoords
[0].lpData
= (BYTE
*) patch
->mem
+ 3 * sizeof(float) /* pos */;
1118 if(patch
->has_normals
) {
1119 patch
->strided
.texCoords
[0].lpData
+= 3 * sizeof(float);
1121 patch
->strided
.texCoords
[0].dwStride
= vtxStride
;