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
);
35 /* GL locking is done by the caller */
36 static void drawStridedFast(const struct wined3d_gl_info
*gl_info
, GLenum primitive_type
, UINT count
, UINT idx_size
,
37 const void *idx_data
, UINT start_idx
, INT base_vertex_index
)
41 GLenum idxtype
= idx_size
== 2 ? GL_UNSIGNED_SHORT
: GL_UNSIGNED_INT
;
42 if (gl_info
->supported
[ARB_DRAW_ELEMENTS_BASE_VERTEX
])
44 GL_EXTCALL(glDrawElementsBaseVertex(primitive_type
, count
, idxtype
,
45 (const char *)idx_data
+ (idx_size
* start_idx
), base_vertex_index
));
46 checkGLcall("glDrawElementsBaseVertex");
50 glDrawElements(primitive_type
, count
,
51 idxtype
, (const char *)idx_data
+ (idx_size
* start_idx
));
52 checkGLcall("glDrawElements");
57 glDrawArrays(primitive_type
, start_idx
, count
);
58 checkGLcall("glDrawArrays");
63 * Actually draw using the supplied information.
64 * Slower GL version which extracts info about each vertex in turn
67 /* GL locking is done by the caller */
68 static void drawStridedSlow(const struct wined3d_device
*device
, const struct wined3d_context
*context
,
69 const struct wined3d_stream_info
*si
, UINT NumVertexes
, GLenum glPrimType
,
70 const void *idxData
, UINT idxSize
, UINT startIdx
)
72 unsigned int textureNo
= 0;
73 const WORD
*pIdxBufS
= NULL
;
74 const DWORD
*pIdxBufL
= NULL
;
76 const struct wined3d_state
*state
= &device
->stateBlock
->state
;
77 LONG SkipnStrides
= startIdx
;
78 BOOL pixelShader
= use_ps(state
);
79 BOOL specular_fog
= FALSE
;
80 const BYTE
*texCoords
[WINED3DDP_MAXTEXCOORD
];
81 const BYTE
*diffuse
= NULL
, *specular
= NULL
, *normal
= NULL
, *position
= NULL
;
82 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
83 UINT texture_stages
= gl_info
->limits
.texture_stages
;
84 const struct wined3d_stream_info_element
*element
;
85 UINT num_untracked_materials
;
88 TRACE("Using slow vertex array code\n");
90 /* Variable Initialization */
93 /* Immediate mode drawing can't make use of indices in a vbo - get the
94 * data from the index buffer. If the index buffer has no vbo (not
95 * supported or other reason), or with user pointer drawing idxData
96 * will be non-NULL. */
98 idxData
= buffer_get_sysmem(state
->index_buffer
, gl_info
);
100 if (idxSize
== 2) pIdxBufS
= idxData
;
101 else pIdxBufL
= idxData
;
102 } else if (idxData
) {
103 ERR("non-NULL idxData with 0 idxSize, this should never happen\n");
107 /* Start drawing in GL */
110 if (si
->use_map
& (1 << WINED3D_FFP_POSITION
))
112 element
= &si
->elements
[WINED3D_FFP_POSITION
];
113 position
= element
->data
.addr
;
116 if (si
->use_map
& (1 << WINED3D_FFP_NORMAL
))
118 element
= &si
->elements
[WINED3D_FFP_NORMAL
];
119 normal
= element
->data
.addr
;
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
.addr
;
132 if (num_untracked_materials
&& element
->format
->id
!= WINED3DFMT_B8G8R8A8_UNORM
)
133 FIXME("Implement diffuse color tracking from %s\n", debug_d3dformat(element
->format
->id
));
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
.addr
;
145 /* special case where the fog density is stored in the specular alpha channel */
146 if (state
->render_states
[WINED3D_RS_FOGENABLE
]
147 && (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
] == WINED3D_FOG_NONE
148 || si
->elements
[WINED3D_FFP_POSITION
].format
->id
== WINED3DFMT_R32G32B32A32_FLOAT
)
149 && state
->render_states
[WINED3D_RS_FOGTABLEMODE
] == WINED3D_FOG_NONE
)
151 if (gl_info
->supported
[EXT_FOG_COORD
])
153 if (element
->format
->id
== WINED3DFMT_B8G8R8A8_UNORM
) specular_fog
= TRUE
;
154 else FIXME("Implement fog coordinates from %s\n", debug_d3dformat(element
->format
->id
));
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
= state
->texture_states
[textureNo
][WINED3D_TSS_TEXCOORD_INDEX
];
177 DWORD texture_idx
= device
->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
&& !state
->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
.addr
;
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 */
230 /* Indexed so work out the number of strides to skip */
232 SkipnStrides
= pIdxBufS
[startIdx
+ vx_index
] + state
->base_vertex_index
;
234 SkipnStrides
= pIdxBufL
[startIdx
+ vx_index
] + state
->base_vertex_index
;
237 tmp_tex_mask
= tex_mask
;
238 for (texture
= 0; tmp_tex_mask
; tmp_tex_mask
>>= 1, ++texture
)
244 if (!(tmp_tex_mask
& 1)) continue;
246 coord_idx
= state
->texture_states
[texture
][WINED3D_TSS_TEXCOORD_INDEX
];
247 ptr
= texCoords
[coord_idx
] + (SkipnStrides
* si
->elements
[WINED3D_FFP_TEXCOORD0
+ coord_idx
].stride
);
249 texture_idx
= device
->texUnitMap
[texture
];
250 multi_texcoord_funcs
[si
->elements
[WINED3D_FFP_TEXCOORD0
+ coord_idx
].format
->emit_idx
](
251 GL_TEXTURE0_ARB
+ texture_idx
, ptr
);
254 /* Diffuse -------------------------------- */
256 const void *ptrToCoords
= diffuse
+ SkipnStrides
* si
->elements
[WINED3D_FFP_DIFFUSE
].stride
;
258 diffuse_funcs
[si
->elements
[WINED3D_FFP_DIFFUSE
].format
->emit_idx
](ptrToCoords
);
259 if (num_untracked_materials
)
261 DWORD diffuseColor
= ((const DWORD
*)ptrToCoords
)[0];
265 color
[0] = D3DCOLOR_B_R(diffuseColor
) / 255.0f
;
266 color
[1] = D3DCOLOR_B_G(diffuseColor
) / 255.0f
;
267 color
[2] = D3DCOLOR_B_B(diffuseColor
) / 255.0f
;
268 color
[3] = D3DCOLOR_B_A(diffuseColor
) / 255.0f
;
270 for (i
= 0; i
< num_untracked_materials
; ++i
)
272 glMaterialfv(GL_FRONT_AND_BACK
, context
->untracked_materials
[i
], color
);
277 /* Specular ------------------------------- */
279 const void *ptrToCoords
= specular
+ SkipnStrides
* si
->elements
[WINED3D_FFP_SPECULAR
].stride
;
281 specular_funcs
[si
->elements
[WINED3D_FFP_SPECULAR
].format
->emit_idx
](ptrToCoords
);
285 DWORD specularColor
= *(const DWORD
*)ptrToCoords
;
286 GL_EXTCALL(glFogCoordfEXT((float) (specularColor
>> 24)));
290 /* Normal -------------------------------- */
293 const void *ptrToCoords
= normal
+ SkipnStrides
* si
->elements
[WINED3D_FFP_NORMAL
].stride
;
294 normal_funcs
[si
->elements
[WINED3D_FFP_NORMAL
].format
->emit_idx
](ptrToCoords
);
297 /* Position -------------------------------- */
299 const void *ptrToCoords
= position
+ SkipnStrides
* si
->elements
[WINED3D_FFP_POSITION
].stride
;
300 position_funcs
[si
->elements
[WINED3D_FFP_POSITION
].format
->emit_idx
](ptrToCoords
);
303 /* For non indexed mode, step onto next parts */
304 if (!idxData
) ++SkipnStrides
;
308 checkGLcall("glEnd and previous calls");
311 /* GL locking is done by the caller */
312 static inline void send_attribute(const struct wined3d_gl_info
*gl_info
,
313 enum wined3d_format_id format
, const UINT index
, const void *ptr
)
317 case WINED3DFMT_R32_FLOAT
:
318 GL_EXTCALL(glVertexAttrib1fvARB(index
, ptr
));
320 case WINED3DFMT_R32G32_FLOAT
:
321 GL_EXTCALL(glVertexAttrib2fvARB(index
, ptr
));
323 case WINED3DFMT_R32G32B32_FLOAT
:
324 GL_EXTCALL(glVertexAttrib3fvARB(index
, ptr
));
326 case WINED3DFMT_R32G32B32A32_FLOAT
:
327 GL_EXTCALL(glVertexAttrib4fvARB(index
, ptr
));
330 case WINED3DFMT_R8G8B8A8_UINT
:
331 GL_EXTCALL(glVertexAttrib4ubvARB(index
, ptr
));
333 case WINED3DFMT_B8G8R8A8_UNORM
:
334 if (gl_info
->supported
[ARB_VERTEX_ARRAY_BGRA
])
336 const DWORD
*src
= ptr
;
337 DWORD c
= *src
& 0xff00ff00;
338 c
|= (*src
& 0xff0000) >> 16;
339 c
|= (*src
& 0xff) << 16;
340 GL_EXTCALL(glVertexAttrib4NubvARB(index
, (GLubyte
*)&c
));
343 /* else fallthrough */
344 case WINED3DFMT_R8G8B8A8_UNORM
:
345 GL_EXTCALL(glVertexAttrib4NubvARB(index
, ptr
));
348 case WINED3DFMT_R16G16_SINT
:
349 GL_EXTCALL(glVertexAttrib4svARB(index
, ptr
));
351 case WINED3DFMT_R16G16B16A16_SINT
:
352 GL_EXTCALL(glVertexAttrib4svARB(index
, ptr
));
355 case WINED3DFMT_R16G16_SNORM
:
357 GLshort s
[4] = {((const GLshort
*)ptr
)[0], ((const GLshort
*)ptr
)[1], 0, 1};
358 GL_EXTCALL(glVertexAttrib4NsvARB(index
, s
));
361 case WINED3DFMT_R16G16_UNORM
:
363 GLushort s
[4] = {((const GLushort
*)ptr
)[0], ((const GLushort
*)ptr
)[1], 0, 1};
364 GL_EXTCALL(glVertexAttrib4NusvARB(index
, s
));
367 case WINED3DFMT_R16G16B16A16_SNORM
:
368 GL_EXTCALL(glVertexAttrib4NsvARB(index
, ptr
));
370 case WINED3DFMT_R16G16B16A16_UNORM
:
371 GL_EXTCALL(glVertexAttrib4NusvARB(index
, ptr
));
374 case WINED3DFMT_R10G10B10A2_UINT
:
375 FIXME("Unsure about WINED3DDECLTYPE_UDEC3\n");
376 /*glVertexAttrib3usvARB(instancedData[j], (GLushort *) ptr); Does not exist */
378 case WINED3DFMT_R10G10B10A2_SNORM
:
379 FIXME("Unsure about WINED3DDECLTYPE_DEC3N\n");
380 /*glVertexAttrib3NusvARB(instancedData[j], (GLushort *) ptr); Does not exist */
383 case WINED3DFMT_R16G16_FLOAT
:
384 /* Are those 16 bit floats. C doesn't have a 16 bit float type. I could read the single bits and calculate a 4
385 * byte float according to the IEEE standard
387 if (gl_info
->supported
[NV_HALF_FLOAT
] && gl_info
->supported
[NV_VERTEX_PROGRAM
])
389 /* Not supported by GL_ARB_half_float_vertex */
390 GL_EXTCALL(glVertexAttrib2hvNV(index
, ptr
));
394 float x
= float_16_to_32(((const unsigned short *)ptr
) + 0);
395 float y
= float_16_to_32(((const unsigned short *)ptr
) + 1);
396 GL_EXTCALL(glVertexAttrib2fARB(index
, x
, y
));
399 case WINED3DFMT_R16G16B16A16_FLOAT
:
400 if (gl_info
->supported
[NV_HALF_FLOAT
] && gl_info
->supported
[NV_VERTEX_PROGRAM
])
402 /* Not supported by GL_ARB_half_float_vertex */
403 GL_EXTCALL(glVertexAttrib4hvNV(index
, ptr
));
407 float x
= float_16_to_32(((const unsigned short *)ptr
) + 0);
408 float y
= float_16_to_32(((const unsigned short *)ptr
) + 1);
409 float z
= float_16_to_32(((const unsigned short *)ptr
) + 2);
410 float w
= float_16_to_32(((const unsigned short *)ptr
) + 3);
411 GL_EXTCALL(glVertexAttrib4fARB(index
, x
, y
, z
, w
));
416 ERR("Unexpected attribute format: %s\n", debug_d3dformat(format
));
421 /* GL locking is done by the caller */
422 static void drawStridedSlowVs(const struct wined3d_gl_info
*gl_info
, const struct wined3d_state
*state
,
423 const struct wined3d_stream_info
*si
, UINT numberOfVertices
, GLenum glPrimitiveType
,
424 const void *idxData
, UINT idxSize
, UINT startIdx
)
426 LONG SkipnStrides
= startIdx
+ state
->load_base_vertex_index
;
427 const DWORD
*pIdxBufL
= NULL
;
428 const WORD
*pIdxBufS
= NULL
;
435 /* Immediate mode drawing can't make use of indices in a vbo - get the
436 * data from the index buffer. If the index buffer has no vbo (not
437 * supported or other reason), or with user pointer drawing idxData
438 * will be non-NULL. */
440 idxData
= buffer_get_sysmem(state
->index_buffer
, gl_info
);
442 if (idxSize
== 2) pIdxBufS
= idxData
;
443 else pIdxBufL
= idxData
;
444 } else if (idxData
) {
445 ERR("non-NULL idxData with 0 idxSize, this should never happen\n");
449 /* Start drawing in GL */
450 glBegin(glPrimitiveType
);
452 for (vx_index
= 0; vx_index
< numberOfVertices
; ++vx_index
)
456 /* Indexed so work out the number of strides to skip */
458 SkipnStrides
= pIdxBufS
[startIdx
+ vx_index
] + state
->load_base_vertex_index
;
460 SkipnStrides
= pIdxBufL
[startIdx
+ vx_index
] + state
->load_base_vertex_index
;
463 for (i
= MAX_ATTRIBS
- 1; i
>= 0; i
--)
465 if (!(si
->use_map
& (1 << i
))) continue;
467 ptr
= si
->elements
[i
].data
.addr
+ si
->elements
[i
].stride
* SkipnStrides
;
469 send_attribute(gl_info
, si
->elements
[i
].format
->id
, i
, ptr
);
477 /* GL locking is done by the caller */
478 static void drawStridedInstanced(const struct wined3d_gl_info
*gl_info
, const struct wined3d_state
*state
,
479 const struct wined3d_stream_info
*si
, UINT numberOfVertices
, GLenum glPrimitiveType
,
480 const void *idxData
, UINT idxSize
, UINT startIdx
, UINT base_vertex_index
)
482 UINT numInstances
= 0, i
;
483 int numInstancedAttribs
= 0, j
;
484 UINT instancedData
[sizeof(si
->elements
) / sizeof(*si
->elements
) /* 16 */];
485 GLenum idxtype
= idxSize
== 2 ? GL_UNSIGNED_SHORT
: GL_UNSIGNED_INT
;
489 /* This is a nasty thing. MSDN says no hardware supports that and apps have to use software vertex processing.
490 * We don't support this for now
492 * Shouldn't be too hard to support with opengl, in theory just call glDrawArrays instead of drawElements.
493 * But the StreamSourceFreq value has a different meaning in that situation.
495 FIXME("Non-indexed instanced drawing is not supported\n");
499 /* First, figure out how many instances we have to draw */
500 for (i
= 0; i
< MAX_STREAMS
; ++i
)
502 /* Look at the streams and take the first one which matches */
503 if (state
->streams
[i
].buffer
504 && ((state
->streams
[i
].flags
& WINED3DSTREAMSOURCE_INSTANCEDATA
)
505 || (state
->streams
[i
].flags
& WINED3DSTREAMSOURCE_INDEXEDDATA
)))
507 /* Use the specified number of instances from the first matched
508 * stream. A streamFreq of 0 (with INSTANCEDATA or INDEXEDDATA)
509 * is handled as 1. See d3d9/tests/visual.c-> stream_test(). */
510 numInstances
= state
->streams
[i
].frequency
? state
->streams
[i
].frequency
: 1;
515 for (i
= 0; i
< sizeof(si
->elements
) / sizeof(*si
->elements
); ++i
)
517 if (!(si
->use_map
& (1 << i
))) continue;
519 if (state
->streams
[si
->elements
[i
].stream_idx
].flags
& WINED3DSTREAMSOURCE_INSTANCEDATA
)
521 instancedData
[numInstancedAttribs
] = i
;
522 numInstancedAttribs
++;
526 /* now draw numInstances instances :-) */
527 for(i
= 0; i
< numInstances
; i
++) {
528 /* Specify the instanced attributes using immediate mode calls */
529 for(j
= 0; j
< numInstancedAttribs
; j
++) {
530 const BYTE
*ptr
= si
->elements
[instancedData
[j
]].data
.addr
531 + si
->elements
[instancedData
[j
]].stride
* i
;
532 if (si
->elements
[instancedData
[j
]].data
.buffer_object
)
534 struct wined3d_buffer
*vb
= state
->streams
[si
->elements
[instancedData
[j
]].stream_idx
].buffer
;
535 ptr
+= (ULONG_PTR
)buffer_get_sysmem(vb
, gl_info
);
538 send_attribute(gl_info
, si
->elements
[instancedData
[j
]].format
->id
, instancedData
[j
], ptr
);
541 if (gl_info
->supported
[ARB_DRAW_ELEMENTS_BASE_VERTEX
])
543 GL_EXTCALL(glDrawElementsBaseVertex(glPrimitiveType
, numberOfVertices
, idxtype
,
544 (const char *)idxData
+(idxSize
* startIdx
), base_vertex_index
));
545 checkGLcall("glDrawElementsBaseVertex");
549 glDrawElements(glPrimitiveType
, numberOfVertices
, idxtype
,
550 (const char *)idxData
+(idxSize
* startIdx
));
551 checkGLcall("glDrawElements");
556 static void remove_vbos(const struct wined3d_gl_info
*gl_info
,
557 const struct wined3d_state
*state
, struct wined3d_stream_info
*s
)
561 for (i
= 0; i
< (sizeof(s
->elements
) / sizeof(*s
->elements
)); ++i
)
563 struct wined3d_stream_info_element
*e
;
565 if (!(s
->use_map
& (1 << i
))) continue;
568 if (e
->data
.buffer_object
)
570 struct wined3d_buffer
*vb
= state
->streams
[e
->stream_idx
].buffer
;
571 e
->data
.buffer_object
= 0;
572 e
->data
.addr
= (BYTE
*)((ULONG_PTR
)e
->data
.addr
+ (ULONG_PTR
)buffer_get_sysmem(vb
, gl_info
));
577 /* Routine common to the draw primitive and draw indexed primitive routines */
578 void drawPrimitive(struct wined3d_device
*device
, UINT index_count
, UINT StartIdx
, BOOL indexed
, const void *idxData
)
580 const struct wined3d_state
*state
= &device
->stateBlock
->state
;
581 struct wined3d_context
*context
;
584 if (!index_count
) return;
586 if (state
->render_states
[WINED3D_RS_COLORWRITEENABLE
])
588 /* Invalidate the back buffer memory so LockRect will read it the next time */
589 for (i
= 0; i
< device
->adapter
->gl_info
.limits
.buffers
; ++i
)
591 struct wined3d_surface
*target
= device
->fb
.render_targets
[i
];
594 surface_load_location(target
, target
->draw_binding
, NULL
);
595 surface_modify_location(target
, target
->draw_binding
, TRUE
);
600 /* Signals other modules that a drawing is in progress and the stateblock finalized */
601 device
->isInDraw
= TRUE
;
603 context
= context_acquire(device
, device
->fb
.render_targets
[0]);
606 context_release(context
);
607 WARN("Invalid context, skipping draw.\n");
611 if (device
->fb
.depth_stencil
)
613 /* Note that this depends on the context_acquire() call above to set
614 * context->render_offscreen properly. We don't currently take the
615 * Z-compare function into account, but we could skip loading the
616 * depthstencil for D3DCMP_NEVER and D3DCMP_ALWAYS as well. Also note
617 * that we never copy the stencil data.*/
618 DWORD location
= context
->render_offscreen
? device
->fb
.depth_stencil
->draw_binding
: SFLAG_INDRAWABLE
;
619 if (state
->render_states
[WINED3D_RS_ZWRITEENABLE
] || state
->render_states
[WINED3D_RS_ZENABLE
])
621 struct wined3d_surface
*ds
= device
->fb
.depth_stencil
;
622 RECT current_rect
, draw_rect
, r
;
624 if (!context
->render_offscreen
&& ds
!= device
->onscreen_depth_stencil
)
625 device_switch_onscreen_ds(device
, context
, ds
);
627 if (ds
->flags
& location
)
628 SetRect(¤t_rect
, 0, 0, ds
->ds_current_size
.cx
, ds
->ds_current_size
.cy
);
630 SetRectEmpty(¤t_rect
);
632 wined3d_get_draw_rect(state
, &draw_rect
);
634 IntersectRect(&r
, &draw_rect
, ¤t_rect
);
635 if (!EqualRect(&r
, &draw_rect
))
636 surface_load_ds_location(ds
, context
, location
);
640 if (!context_apply_draw_state(context
, device
))
642 context_release(context
);
643 WARN("Unable to apply draw state, skipping draw.\n");
647 if (device
->fb
.depth_stencil
&& state
->render_states
[WINED3D_RS_ZWRITEENABLE
])
649 struct wined3d_surface
*ds
= device
->fb
.depth_stencil
;
650 DWORD location
= context
->render_offscreen
? ds
->draw_binding
: SFLAG_INDRAWABLE
;
652 surface_modify_ds_location(ds
, location
, ds
->ds_current_size
.cx
, ds
->ds_current_size
.cy
);
655 if ((!context
->gl_info
->supported
[WINED3D_GL_VERSION_2_0
]
656 || (!glPointParameteri
&& !context
->gl_info
->supported
[NV_POINT_SPRITE
]))
657 && context
->render_offscreen
658 && state
->render_states
[WINED3D_RS_POINTSPRITEENABLE
]
659 && state
->gl_primitive_type
== GL_POINTS
)
661 FIXME("Point sprite coordinate origin switching not supported.\n");
664 /* Ok, we will be updating the screen from here onwards so grab the lock */
667 GLenum glPrimType
= state
->gl_primitive_type
;
668 INT base_vertex_index
= state
->base_vertex_index
;
669 BOOL emulation
= FALSE
;
670 const struct wined3d_stream_info
*stream_info
= &device
->strided_streams
;
671 struct wined3d_stream_info stridedlcl
;
676 if (!state
->user_stream
)
678 struct wined3d_buffer
*index_buffer
= state
->index_buffer
;
679 if (!index_buffer
->buffer_object
|| !stream_info
->all_vbo
)
680 idxData
= index_buffer
->resource
.allocatedMemory
;
685 if (state
->index_format
== WINED3DFMT_R16_UINT
)
693 if (!stream_info
->position_transformed
&& context
->num_untracked_materials
694 && state
->render_states
[WINED3D_RS_LIGHTING
])
698 FIXME("Using software emulation because not all material properties could be tracked\n");
701 TRACE("Using software emulation because not all material properties could be tracked\n");
705 else if (context
->fog_coord
&& state
->render_states
[WINED3D_RS_FOGENABLE
])
707 /* Either write a pipeline replacement shader or convert the specular alpha from unsigned byte
708 * to a float in the vertex buffer
712 FIXME("Using software emulation because manual fog coordinates are provided\n");
715 TRACE("Using software emulation because manual fog coordinates are provided\n");
721 stream_info
= &stridedlcl
;
722 memcpy(&stridedlcl
, &device
->strided_streams
, sizeof(stridedlcl
));
723 remove_vbos(context
->gl_info
, state
, &stridedlcl
);
727 if (device
->useDrawStridedSlow
|| emulation
)
729 /* Immediate mode drawing */
734 FIXME("Using immediate mode with vertex shaders for half float emulation\n");
737 TRACE("Using immediate mode with vertex shaders for half float emulation\n");
739 drawStridedSlowVs(context
->gl_info
, state
, stream_info
,
740 index_count
, glPrimType
, idxData
, idx_size
, StartIdx
);
744 drawStridedSlow(device
, context
, stream_info
, index_count
,
745 glPrimType
, idxData
, idx_size
, StartIdx
);
748 else if (device
->instancedDraw
)
750 /* Instancing emulation with mixing immediate mode and arrays */
751 drawStridedInstanced(context
->gl_info
, state
, stream_info
,
752 index_count
, glPrimType
, idxData
, idx_size
, StartIdx
, base_vertex_index
);
756 drawStridedFast(context
->gl_info
, glPrimType
, index_count
, idx_size
, idxData
, StartIdx
, base_vertex_index
);
760 /* Finished updating the screen, restore lock */
763 for(i
= 0; i
< device
->num_buffer_queries
; ++i
)
765 wined3d_event_query_issue(device
->buffer_queries
[i
], device
);
768 if (wined3d_settings
.strict_draw_ordering
) wglFlush(); /* Flush to ensure ordering across contexts. */
770 context_release(context
);
772 TRACE("Done all gl drawing\n");
774 /* Control goes back to the device, stateblock values may change again */
775 device
->isInDraw
= FALSE
;
778 static void normalize_normal(float *n
) {
779 float length
= n
[0] * n
[0] + n
[1] * n
[1] + n
[2] * n
[2];
780 if (length
== 0.0f
) return;
781 length
= sqrtf(length
);
782 n
[0] = n
[0] / length
;
783 n
[1] = n
[1] / length
;
784 n
[2] = n
[2] / length
;
787 /* Tesselates a high order rectangular patch into single triangles using gl evaluators
789 * The problem is that OpenGL does not offer a direct way to return the tesselated primitives,
790 * and they can't be sent off for rendering directly either. Tesselating is slow, so we want
791 * to cache the patches in a vertex buffer. But more importantly, gl can't bind generated
792 * attributes to numbered shader attributes, so we have to store them and rebind them as needed
795 * To read back, the opengl feedback mode is used. This creates a problem because we want
796 * untransformed, unlit vertices, but feedback runs everything through transform and lighting.
797 * Thus disable lighting and set identity matrices to get unmodified colors and positions.
798 * To overcome clipping find the biggest x, y and z values of the vertices in the patch and scale
799 * them to [-1.0;+1.0] and set the viewport up to scale them back.
801 * Normals are more tricky: Draw white vertices with 3 directional lights, and calculate the
802 * resulting colors back to the normals.
804 * NOTE: This function activates a context for blitting, modifies matrices & viewport, but
805 * does not restore it because normally a draw follows immediately afterwards. The caller is
806 * responsible of taking care that either the gl states are restored, or the context activated
807 * for drawing to reset the lastWasBlit flag.
809 HRESULT
tesselate_rectpatch(struct wined3d_device
*This
, struct wined3d_rect_patch
*patch
)
811 unsigned int i
, j
, num_quads
, out_vertex_size
, buffer_size
, d3d_out_vertex_size
;
812 const struct wined3d_rect_patch_info
*info
= &patch
->rect_patch_info
;
813 float max_x
= 0.0f
, max_y
= 0.0f
, max_z
= 0.0f
, neg_z
= 0.0f
;
814 struct wined3d_state
*state
= &This
->stateBlock
->state
;
815 struct wined3d_stream_info stream_info
;
816 struct wined3d_stream_info_element
*e
;
817 struct wined3d_context
*context
;
818 struct wined3d_shader
*vs
;
821 GLenum feedback_type
;
824 /* Simply activate the context for blitting. This disables all the things we don't want and
825 * takes care of dirtifying. Dirtifying is preferred over pushing / popping, since drawing the
826 * patch (as opposed to normal draws) will most likely need different changes anyway. */
827 context
= context_acquire(This
, NULL
);
828 context_apply_blit_state(context
, This
);
830 /* First, locate the position data. This is provided in a vertex buffer in
831 * the stateblock. Beware of VBOs. */
832 vs
= state
->vertex_shader
;
833 state
->vertex_shader
= NULL
;
834 device_stream_info_from_declaration(This
, &stream_info
);
835 state
->vertex_shader
= vs
;
837 e
= &stream_info
.elements
[WINED3D_FFP_POSITION
];
838 if (e
->data
.buffer_object
)
840 struct wined3d_buffer
*vb
= state
->streams
[e
->stream_idx
].buffer
;
841 e
->data
.addr
= (BYTE
*)((ULONG_PTR
)e
->data
.addr
+ (ULONG_PTR
)buffer_get_sysmem(vb
, context
->gl_info
));
843 vtxStride
= e
->stride
;
845 + vtxStride
* info
->stride
* info
->start_vertex_offset_height
846 + vtxStride
* info
->start_vertex_offset_width
;
848 /* Not entirely sure about what happens with transformed vertices */
849 if (stream_info
.position_transformed
) FIXME("Transformed position in rectpatch generation\n");
851 if(vtxStride
% sizeof(GLfloat
)) {
852 /* glMap2f reads vertex sizes in GLfloats, the d3d stride is in bytes.
853 * I don't see how the stride could not be a multiple of 4, but make sure
856 ERR("Vertex stride is not a multiple of sizeof(GLfloat)\n");
858 if (info
->basis
!= WINED3D_BASIS_BEZIER
)
859 FIXME("Basis is %s, how to handle this?\n", debug_d3dbasis(info
->basis
));
860 if (info
->degree
!= WINED3D_DEGREE_CUBIC
)
861 FIXME("Degree is %s, how to handle this?\n", debug_d3ddegree(info
->degree
));
863 /* First, get the boundary cube of the input data */
864 for (j
= 0; j
< info
->height
; ++j
)
866 for (i
= 0; i
< info
->width
; ++i
)
868 const float *v
= (const float *)(data
+ vtxStride
* i
+ vtxStride
* info
->stride
* j
);
869 if(fabs(v
[0]) > max_x
) max_x
= fabsf(v
[0]);
870 if(fabs(v
[1]) > max_y
) max_y
= fabsf(v
[1]);
871 if(fabs(v
[2]) > max_z
) max_z
= fabsf(v
[2]);
872 if(v
[2] < neg_z
) neg_z
= v
[2];
876 /* This needs some improvements in the vertex decl code */
877 FIXME("Cannot find data to generate. Only generating position and normals\n");
878 patch
->has_normals
= TRUE
;
879 patch
->has_texcoords
= FALSE
;
883 glMatrixMode(GL_PROJECTION
);
884 checkGLcall("glMatrixMode(GL_PROJECTION)");
886 checkGLcall("glLoadIdentity()");
887 glScalef(1.0f
/ (max_x
), 1.0f
/ (max_y
), max_z
== 0.0f
? 1.0f
: 1.0f
/ (2.0f
* max_z
));
888 glTranslatef(0.0f
, 0.0f
, 0.5f
);
889 checkGLcall("glScalef");
890 glViewport(-max_x
, -max_y
, 2 * (max_x
), 2 * (max_y
));
891 checkGLcall("glViewport");
893 /* Some states to take care of. If we're in wireframe opengl will produce lines, and confuse
894 * our feedback buffer parser
896 glPolygonMode(GL_FRONT_AND_BACK
, GL_FILL
);
897 checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)");
898 context_invalidate_state(context
, STATE_RENDER(WINED3D_RS_FILLMODE
));
899 if (patch
->has_normals
)
901 static const GLfloat black
[] = {0.0f
, 0.0f
, 0.0f
, 0.0f
};
902 static const GLfloat red
[] = {1.0f
, 0.0f
, 0.0f
, 0.0f
};
903 static const GLfloat green
[] = {0.0f
, 1.0f
, 0.0f
, 0.0f
};
904 static const GLfloat blue
[] = {0.0f
, 0.0f
, 1.0f
, 0.0f
};
905 static const GLfloat white
[] = {1.0f
, 1.0f
, 1.0f
, 1.0f
};
906 glEnable(GL_LIGHTING
);
907 checkGLcall("glEnable(GL_LIGHTING)");
908 glLightModelfv(GL_LIGHT_MODEL_AMBIENT
, black
);
909 checkGLcall("glLightModel for MODEL_AMBIENT");
910 context_invalidate_state(context
, STATE_RENDER(WINED3D_RS_AMBIENT
));
912 for (i
= 3; i
< context
->gl_info
->limits
.lights
; ++i
)
914 glDisable(GL_LIGHT0
+ i
);
915 checkGLcall("glDisable(GL_LIGHT0 + i)");
916 context_invalidate_state(context
, STATE_ACTIVELIGHT(i
));
919 context_invalidate_state(context
, STATE_ACTIVELIGHT(0));
920 glLightfv(GL_LIGHT0
, GL_DIFFUSE
, red
);
921 glLightfv(GL_LIGHT0
, GL_SPECULAR
, black
);
922 glLightfv(GL_LIGHT0
, GL_AMBIENT
, black
);
923 glLightfv(GL_LIGHT0
, GL_POSITION
, red
);
925 checkGLcall("Setting up light 1");
926 context_invalidate_state(context
, STATE_ACTIVELIGHT(1));
927 glLightfv(GL_LIGHT1
, GL_DIFFUSE
, green
);
928 glLightfv(GL_LIGHT1
, GL_SPECULAR
, black
);
929 glLightfv(GL_LIGHT1
, GL_AMBIENT
, black
);
930 glLightfv(GL_LIGHT1
, GL_POSITION
, green
);
932 checkGLcall("Setting up light 2");
933 context_invalidate_state(context
, STATE_ACTIVELIGHT(2));
934 glLightfv(GL_LIGHT2
, GL_DIFFUSE
, blue
);
935 glLightfv(GL_LIGHT2
, GL_SPECULAR
, black
);
936 glLightfv(GL_LIGHT2
, GL_AMBIENT
, black
);
937 glLightfv(GL_LIGHT2
, GL_POSITION
, blue
);
939 checkGLcall("Setting up light 3");
941 context_invalidate_state(context
, STATE_MATERIAL
);
942 context_invalidate_state(context
, STATE_RENDER(WINED3D_RS_COLORVERTEX
));
943 glDisable(GL_COLOR_MATERIAL
);
944 glMaterialfv(GL_FRONT_AND_BACK
, GL_EMISSION
, black
);
945 glMaterialfv(GL_FRONT_AND_BACK
, GL_SPECULAR
, black
);
946 glMaterialfv(GL_FRONT_AND_BACK
, GL_DIFFUSE
, white
);
947 checkGLcall("Setting up materials");
950 /* Enable the needed maps.
951 * GL_MAP2_VERTEX_3 is needed for positional data.
952 * GL_AUTO_NORMAL to generate normals from the position. Do not use GL_MAP2_NORMAL.
953 * GL_MAP2_TEXTURE_COORD_4 for texture coords
955 num_quads
= ceilf(patch
->numSegs
[0]) * ceilf(patch
->numSegs
[1]);
956 out_vertex_size
= 3 /* position */;
957 d3d_out_vertex_size
= 3;
958 glEnable(GL_MAP2_VERTEX_3
);
959 if(patch
->has_normals
&& patch
->has_texcoords
) {
960 FIXME("Texcoords not handled yet\n");
961 feedback_type
= GL_3D_COLOR_TEXTURE
;
962 out_vertex_size
+= 8;
963 d3d_out_vertex_size
+= 7;
964 glEnable(GL_AUTO_NORMAL
);
965 glEnable(GL_MAP2_TEXTURE_COORD_4
);
966 } else if(patch
->has_texcoords
) {
967 FIXME("Texcoords not handled yet\n");
968 feedback_type
= GL_3D_COLOR_TEXTURE
;
969 out_vertex_size
+= 7;
970 d3d_out_vertex_size
+= 4;
971 glEnable(GL_MAP2_TEXTURE_COORD_4
);
972 } else if(patch
->has_normals
) {
973 feedback_type
= GL_3D_COLOR
;
974 out_vertex_size
+= 4;
975 d3d_out_vertex_size
+= 3;
976 glEnable(GL_AUTO_NORMAL
);
978 feedback_type
= GL_3D
;
980 checkGLcall("glEnable vertex attrib generation");
982 buffer_size
= num_quads
* out_vertex_size
* 2 /* triangle list */ * 3 /* verts per tri */
983 + 4 * num_quads
/* 2 triangle markers per quad + num verts in tri */;
984 feedbuffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, buffer_size
* sizeof(float) * 8);
986 glMap2f(GL_MAP2_VERTEX_3
,
987 0.0f
, 1.0f
, vtxStride
/ sizeof(float), info
->width
,
988 0.0f
, 1.0f
, info
->stride
* vtxStride
/ sizeof(float), info
->height
,
989 (const GLfloat
*)data
);
990 checkGLcall("glMap2f");
991 if (patch
->has_texcoords
)
993 glMap2f(GL_MAP2_TEXTURE_COORD_4
,
994 0.0f
, 1.0f
, vtxStride
/ sizeof(float), info
->width
,
995 0.0f
, 1.0f
, info
->stride
* vtxStride
/ sizeof(float), info
->height
,
996 (const GLfloat
*)data
);
997 checkGLcall("glMap2f");
999 glMapGrid2f(ceilf(patch
->numSegs
[0]), 0.0f
, 1.0f
, ceilf(patch
->numSegs
[1]), 0.0f
, 1.0f
);
1000 checkGLcall("glMapGrid2f");
1002 glFeedbackBuffer(buffer_size
* 2, feedback_type
, feedbuffer
);
1003 checkGLcall("glFeedbackBuffer");
1004 glRenderMode(GL_FEEDBACK
);
1006 glEvalMesh2(GL_FILL
, 0, ceilf(patch
->numSegs
[0]), 0, ceilf(patch
->numSegs
[1]));
1007 checkGLcall("glEvalMesh2");
1009 i
= glRenderMode(GL_RENDER
);
1012 ERR("Feedback failed. Expected %d elements back\n", buffer_size
);
1013 HeapFree(GetProcessHeap(), 0, feedbuffer
);
1014 context_release(context
);
1015 return WINED3DERR_DRIVERINTERNALERROR
;
1016 } else if(i
!= buffer_size
) {
1018 ERR("Unexpected amount of elements returned. Expected %d, got %d\n", buffer_size
, i
);
1019 HeapFree(GetProcessHeap(), 0, feedbuffer
);
1020 context_release(context
);
1021 return WINED3DERR_DRIVERINTERNALERROR
;
1023 TRACE("Got %d elements as expected\n", i
);
1026 HeapFree(GetProcessHeap(), 0, patch
->mem
);
1027 patch
->mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, num_quads
* 6 * d3d_out_vertex_size
* sizeof(float) * 8);
1029 for(j
= 0; j
< buffer_size
; j
+= (3 /* num verts */ * out_vertex_size
+ 2 /* tri marker */)) {
1030 if(feedbuffer
[j
] != GL_POLYGON_TOKEN
) {
1031 ERR("Unexpected token: %f\n", feedbuffer
[j
]);
1034 if(feedbuffer
[j
+ 1] != 3) {
1035 ERR("Unexpected polygon: %f corners\n", feedbuffer
[j
+ 1]);
1038 /* Somehow there are different ideas about back / front facing, so fix up the
1041 patch
->mem
[i
+ 0] = feedbuffer
[j
+ out_vertex_size
* 2 + 2]; /* x, triangle 2 */
1042 patch
->mem
[i
+ 1] = feedbuffer
[j
+ out_vertex_size
* 2 + 3]; /* y, triangle 2 */
1043 patch
->mem
[i
+ 2] = (feedbuffer
[j
+ out_vertex_size
* 2 + 4] - 0.5f
) * 4.0f
* max_z
; /* z, triangle 3 */
1044 if(patch
->has_normals
) {
1045 patch
->mem
[i
+ 3] = feedbuffer
[j
+ out_vertex_size
* 2 + 5];
1046 patch
->mem
[i
+ 4] = feedbuffer
[j
+ out_vertex_size
* 2 + 6];
1047 patch
->mem
[i
+ 5] = feedbuffer
[j
+ out_vertex_size
* 2 + 7];
1049 i
+= d3d_out_vertex_size
;
1051 patch
->mem
[i
+ 0] = feedbuffer
[j
+ out_vertex_size
* 1 + 2]; /* x, triangle 2 */
1052 patch
->mem
[i
+ 1] = feedbuffer
[j
+ out_vertex_size
* 1 + 3]; /* y, triangle 2 */
1053 patch
->mem
[i
+ 2] = (feedbuffer
[j
+ out_vertex_size
* 1 + 4] - 0.5f
) * 4.0f
* max_z
; /* z, triangle 2 */
1054 if(patch
->has_normals
) {
1055 patch
->mem
[i
+ 3] = feedbuffer
[j
+ out_vertex_size
* 1 + 5];
1056 patch
->mem
[i
+ 4] = feedbuffer
[j
+ out_vertex_size
* 1 + 6];
1057 patch
->mem
[i
+ 5] = feedbuffer
[j
+ out_vertex_size
* 1 + 7];
1059 i
+= d3d_out_vertex_size
;
1061 patch
->mem
[i
+ 0] = feedbuffer
[j
+ out_vertex_size
* 0 + 2]; /* x, triangle 1 */
1062 patch
->mem
[i
+ 1] = feedbuffer
[j
+ out_vertex_size
* 0 + 3]; /* y, triangle 1 */
1063 patch
->mem
[i
+ 2] = (feedbuffer
[j
+ out_vertex_size
* 0 + 4] - 0.5f
) * 4.0f
* max_z
; /* z, triangle 1 */
1064 if(patch
->has_normals
) {
1065 patch
->mem
[i
+ 3] = feedbuffer
[j
+ out_vertex_size
* 0 + 5];
1066 patch
->mem
[i
+ 4] = feedbuffer
[j
+ out_vertex_size
* 0 + 6];
1067 patch
->mem
[i
+ 5] = feedbuffer
[j
+ out_vertex_size
* 0 + 7];
1069 i
+= d3d_out_vertex_size
;
1072 if(patch
->has_normals
) {
1073 /* Now do the same with reverse light directions */
1074 static const GLfloat x
[] = {-1.0f
, 0.0f
, 0.0f
, 0.0f
};
1075 static const GLfloat y
[] = { 0.0f
, -1.0f
, 0.0f
, 0.0f
};
1076 static const GLfloat z
[] = { 0.0f
, 0.0f
, -1.0f
, 0.0f
};
1077 glLightfv(GL_LIGHT0
, GL_POSITION
, x
);
1078 glLightfv(GL_LIGHT1
, GL_POSITION
, y
);
1079 glLightfv(GL_LIGHT2
, GL_POSITION
, z
);
1080 checkGLcall("Setting up reverse light directions");
1082 glRenderMode(GL_FEEDBACK
);
1083 checkGLcall("glRenderMode(GL_FEEDBACK)");
1084 glEvalMesh2(GL_FILL
, 0, ceilf(patch
->numSegs
[0]), 0, ceilf(patch
->numSegs
[1]));
1085 checkGLcall("glEvalMesh2");
1086 i
= glRenderMode(GL_RENDER
);
1087 checkGLcall("glRenderMode(GL_RENDER)");
1090 for(j
= 0; j
< buffer_size
; j
+= (3 /* num verts */ * out_vertex_size
+ 2 /* tri marker */)) {
1091 if(feedbuffer
[j
] != GL_POLYGON_TOKEN
) {
1092 ERR("Unexpected token: %f\n", feedbuffer
[j
]);
1095 if(feedbuffer
[j
+ 1] != 3) {
1096 ERR("Unexpected polygon: %f corners\n", feedbuffer
[j
+ 1]);
1099 if(patch
->mem
[i
+ 3] == 0.0f
)
1100 patch
->mem
[i
+ 3] = -feedbuffer
[j
+ out_vertex_size
* 2 + 5];
1101 if(patch
->mem
[i
+ 4] == 0.0f
)
1102 patch
->mem
[i
+ 4] = -feedbuffer
[j
+ out_vertex_size
* 2 + 6];
1103 if(patch
->mem
[i
+ 5] == 0.0f
)
1104 patch
->mem
[i
+ 5] = -feedbuffer
[j
+ out_vertex_size
* 2 + 7];
1105 normalize_normal(patch
->mem
+ i
+ 3);
1106 i
+= d3d_out_vertex_size
;
1108 if(patch
->mem
[i
+ 3] == 0.0f
)
1109 patch
->mem
[i
+ 3] = -feedbuffer
[j
+ out_vertex_size
* 1 + 5];
1110 if(patch
->mem
[i
+ 4] == 0.0f
)
1111 patch
->mem
[i
+ 4] = -feedbuffer
[j
+ out_vertex_size
* 1 + 6];
1112 if(patch
->mem
[i
+ 5] == 0.0f
)
1113 patch
->mem
[i
+ 5] = -feedbuffer
[j
+ out_vertex_size
* 1 + 7];
1114 normalize_normal(patch
->mem
+ i
+ 3);
1115 i
+= d3d_out_vertex_size
;
1117 if(patch
->mem
[i
+ 3] == 0.0f
)
1118 patch
->mem
[i
+ 3] = -feedbuffer
[j
+ out_vertex_size
* 0 + 5];
1119 if(patch
->mem
[i
+ 4] == 0.0f
)
1120 patch
->mem
[i
+ 4] = -feedbuffer
[j
+ out_vertex_size
* 0 + 6];
1121 if(patch
->mem
[i
+ 5] == 0.0f
)
1122 patch
->mem
[i
+ 5] = -feedbuffer
[j
+ out_vertex_size
* 0 + 7];
1123 normalize_normal(patch
->mem
+ i
+ 3);
1124 i
+= d3d_out_vertex_size
;
1128 glDisable(GL_MAP2_VERTEX_3
);
1129 glDisable(GL_AUTO_NORMAL
);
1130 glDisable(GL_MAP2_NORMAL
);
1131 glDisable(GL_MAP2_TEXTURE_COORD_4
);
1132 checkGLcall("glDisable vertex attrib generation");
1135 context_release(context
);
1137 HeapFree(GetProcessHeap(), 0, feedbuffer
);
1139 vtxStride
= 3 * sizeof(float);
1140 if(patch
->has_normals
) {
1141 vtxStride
+= 3 * sizeof(float);
1143 if(patch
->has_texcoords
) {
1144 vtxStride
+= 4 * sizeof(float);
1146 memset(&patch
->strided
, 0, sizeof(patch
->strided
));
1147 patch
->strided
.position
.format
= WINED3DFMT_R32G32B32_FLOAT
;
1148 patch
->strided
.position
.data
= (BYTE
*)patch
->mem
;
1149 patch
->strided
.position
.stride
= vtxStride
;
1151 if (patch
->has_normals
)
1153 patch
->strided
.normal
.format
= WINED3DFMT_R32G32B32_FLOAT
;
1154 patch
->strided
.normal
.data
= (BYTE
*)patch
->mem
+ 3 * sizeof(float) /* pos */;
1155 patch
->strided
.normal
.stride
= vtxStride
;
1157 if (patch
->has_texcoords
)
1159 patch
->strided
.tex_coords
[0].format
= WINED3DFMT_R32G32B32A32_FLOAT
;
1160 patch
->strided
.tex_coords
[0].data
= (BYTE
*)patch
->mem
+ 3 * sizeof(float) /* pos */;
1161 if (patch
->has_normals
)
1162 patch
->strided
.tex_coords
[0].data
+= 3 * sizeof(float);
1163 patch
->strided
.tex_coords
[0].stride
= vtxStride
;