2 * WINED3D draw functions
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2002-2004 Raphael Junqueira
6 * Copyright 2004 Christian Costa
7 * Copyright 2005 Oliver Stieber
8 * Copyright 2006, 2008 Henri Verbeet
9 * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
10 * Copyright 2009 Henri Verbeet for CodeWeavers
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/port.h"
30 #include "wined3d_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(d3d_draw
);
37 /* Context activation is done by the caller. */
38 static void drawStridedFast(const struct wined3d_gl_info
*gl_info
, GLenum primitive_type
, UINT count
, UINT idx_size
,
39 const void *idx_data
, UINT start_idx
, INT base_vertex_index
, UINT start_instance
, UINT instance_count
)
43 GLenum idxtype
= idx_size
== 2 ? GL_UNSIGNED_SHORT
: GL_UNSIGNED_INT
;
46 if (!gl_info
->supported
[ARB_DRAW_INSTANCED
])
48 FIXME("Instanced drawing not supported.\n");
53 FIXME("Start instance (%u) not supported.\n", start_instance
);
54 GL_EXTCALL(glDrawElementsInstancedBaseVertex(primitive_type
, count
, idxtype
,
55 (const char *)idx_data
+ (idx_size
* start_idx
), instance_count
, base_vertex_index
));
56 checkGLcall("glDrawElementsInstancedBaseVertex");
59 else if (gl_info
->supported
[ARB_DRAW_ELEMENTS_BASE_VERTEX
])
61 GL_EXTCALL(glDrawElementsBaseVertex(primitive_type
, count
, idxtype
,
62 (const char *)idx_data
+ (idx_size
* start_idx
), base_vertex_index
));
63 checkGLcall("glDrawElementsBaseVertex");
67 gl_info
->gl_ops
.gl
.p_glDrawElements(primitive_type
, count
,
68 idxtype
, (const char *)idx_data
+ (idx_size
* start_idx
));
69 checkGLcall("glDrawElements");
74 gl_info
->gl_ops
.gl
.p_glDrawArrays(primitive_type
, start_idx
, count
);
75 checkGLcall("glDrawArrays");
80 * Actually draw using the supplied information.
81 * Slower GL version which extracts info about each vertex in turn
84 /* Context activation is done by the caller. */
85 static void drawStridedSlow(const struct wined3d_device
*device
, const struct wined3d_context
*context
,
86 const struct wined3d_stream_info
*si
, UINT NumVertexes
, GLenum glPrimType
,
87 const void *idxData
, UINT idxSize
, UINT startIdx
)
89 unsigned int textureNo
= 0;
90 const WORD
*pIdxBufS
= NULL
;
91 const DWORD
*pIdxBufL
= NULL
;
93 const struct wined3d_state
*state
= &device
->stateBlock
->state
;
94 LONG SkipnStrides
= startIdx
;
95 BOOL pixelShader
= use_ps(state
);
96 BOOL specular_fog
= FALSE
;
97 const BYTE
*texCoords
[WINED3DDP_MAXTEXCOORD
];
98 const BYTE
*diffuse
= NULL
, *specular
= NULL
, *normal
= NULL
, *position
= NULL
;
99 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
100 UINT texture_stages
= gl_info
->limits
.texture_stages
;
101 const struct wined3d_stream_info_element
*element
;
102 UINT num_untracked_materials
;
105 TRACE("Using slow vertex array code\n");
107 /* Variable Initialization */
110 /* Immediate mode drawing can't make use of indices in a vbo - get the
111 * data from the index buffer. If the index buffer has no vbo (not
112 * supported or other reason), or with user pointer drawing idxData
113 * will be non-NULL. */
115 idxData
= buffer_get_sysmem(state
->index_buffer
, gl_info
);
117 if (idxSize
== 2) pIdxBufS
= idxData
;
118 else pIdxBufL
= idxData
;
119 } else if (idxData
) {
120 ERR("non-NULL idxData with 0 idxSize, this should never happen\n");
124 /* Start drawing in GL */
125 gl_info
->gl_ops
.gl
.p_glBegin(glPrimType
);
127 if (si
->use_map
& (1 << WINED3D_FFP_POSITION
))
129 element
= &si
->elements
[WINED3D_FFP_POSITION
];
130 position
= element
->data
.addr
;
133 if (si
->use_map
& (1 << WINED3D_FFP_NORMAL
))
135 element
= &si
->elements
[WINED3D_FFP_NORMAL
];
136 normal
= element
->data
.addr
;
140 gl_info
->gl_ops
.gl
.p_glNormal3f(0, 0, 0);
143 num_untracked_materials
= context
->num_untracked_materials
;
144 if (si
->use_map
& (1 << WINED3D_FFP_DIFFUSE
))
146 element
= &si
->elements
[WINED3D_FFP_DIFFUSE
];
147 diffuse
= element
->data
.addr
;
149 if (num_untracked_materials
&& element
->format
->id
!= WINED3DFMT_B8G8R8A8_UNORM
)
150 FIXME("Implement diffuse color tracking from %s\n", debug_d3dformat(element
->format
->id
));
154 gl_info
->gl_ops
.gl
.p_glColor4f(1.0f
, 1.0f
, 1.0f
, 1.0f
);
157 if (si
->use_map
& (1 << WINED3D_FFP_SPECULAR
))
159 element
= &si
->elements
[WINED3D_FFP_SPECULAR
];
160 specular
= element
->data
.addr
;
162 /* special case where the fog density is stored in the specular alpha channel */
163 if (state
->render_states
[WINED3D_RS_FOGENABLE
]
164 && (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
] == WINED3D_FOG_NONE
165 || si
->elements
[WINED3D_FFP_POSITION
].format
->id
== WINED3DFMT_R32G32B32A32_FLOAT
)
166 && state
->render_states
[WINED3D_RS_FOGTABLEMODE
] == WINED3D_FOG_NONE
)
168 if (gl_info
->supported
[EXT_FOG_COORD
])
170 if (element
->format
->id
== WINED3DFMT_B8G8R8A8_UNORM
) specular_fog
= TRUE
;
171 else FIXME("Implement fog coordinates from %s\n", debug_d3dformat(element
->format
->id
));
179 /* TODO: Use the fog table code from old ddraw */
180 FIXME("Implement fog for transformed vertices in software\n");
186 else if (gl_info
->supported
[EXT_SECONDARY_COLOR
])
188 GL_EXTCALL(glSecondaryColor3fEXT
)(0, 0, 0);
191 for (textureNo
= 0; textureNo
< texture_stages
; ++textureNo
)
193 int coordIdx
= state
->texture_states
[textureNo
][WINED3D_TSS_TEXCOORD_INDEX
];
194 DWORD texture_idx
= device
->texUnitMap
[textureNo
];
196 if (!gl_info
->supported
[ARB_MULTITEXTURE
] && textureNo
> 0)
198 FIXME("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
202 if (!pixelShader
&& !state
->textures
[textureNo
]) continue;
204 if (texture_idx
== WINED3D_UNMAPPED_STAGE
) continue;
208 TRACE("tex: %d - Skip tex coords, as being system generated\n", textureNo
);
211 else if (coordIdx
< 0)
213 FIXME("tex: %d - Coord index %d is less than zero, expect a crash.\n", textureNo
, coordIdx
);
217 if (si
->use_map
& (1 << (WINED3D_FFP_TEXCOORD0
+ coordIdx
)))
219 element
= &si
->elements
[WINED3D_FFP_TEXCOORD0
+ coordIdx
];
220 texCoords
[coordIdx
] = element
->data
.addr
;
221 tex_mask
|= (1 << textureNo
);
225 TRACE("tex: %d - Skipping tex coords, as no data supplied\n", textureNo
);
226 if (gl_info
->supported
[ARB_MULTITEXTURE
])
227 GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB
+ texture_idx
, 0, 0, 0, 1));
229 gl_info
->gl_ops
.gl
.p_glTexCoord4f(0, 0, 0, 1);
233 /* We shouldn't start this function if any VBO is involved. Should I put a safety check here?
234 * Guess it's not necessary(we crash then anyway) and would only eat CPU time
237 /* For each primitive */
238 for (vx_index
= 0; vx_index
< NumVertexes
; ++vx_index
) {
239 UINT texture
, tmp_tex_mask
;
240 /* Blending data and Point sizes are not supported by this function. They are not supported by the fixed
241 * function pipeline at all. A Fixme for them is printed after decoding the vertex declaration
244 /* For indexed data, we need to go a few more strides in */
247 /* Indexed so work out the number of strides to skip */
249 SkipnStrides
= pIdxBufS
[startIdx
+ vx_index
] + state
->base_vertex_index
;
251 SkipnStrides
= pIdxBufL
[startIdx
+ vx_index
] + state
->base_vertex_index
;
254 tmp_tex_mask
= tex_mask
;
255 for (texture
= 0; tmp_tex_mask
; tmp_tex_mask
>>= 1, ++texture
)
261 if (!(tmp_tex_mask
& 1)) continue;
263 coord_idx
= state
->texture_states
[texture
][WINED3D_TSS_TEXCOORD_INDEX
];
264 ptr
= texCoords
[coord_idx
] + (SkipnStrides
* si
->elements
[WINED3D_FFP_TEXCOORD0
+ coord_idx
].stride
);
266 texture_idx
= device
->texUnitMap
[texture
];
267 multi_texcoord_funcs
[si
->elements
[WINED3D_FFP_TEXCOORD0
+ coord_idx
].format
->emit_idx
](
268 GL_TEXTURE0_ARB
+ texture_idx
, ptr
);
271 /* Diffuse -------------------------------- */
273 const void *ptrToCoords
= diffuse
+ SkipnStrides
* si
->elements
[WINED3D_FFP_DIFFUSE
].stride
;
275 diffuse_funcs
[si
->elements
[WINED3D_FFP_DIFFUSE
].format
->emit_idx
](ptrToCoords
);
276 if (num_untracked_materials
)
278 DWORD diffuseColor
= ((const DWORD
*)ptrToCoords
)[0];
282 color
[0] = D3DCOLOR_B_R(diffuseColor
) / 255.0f
;
283 color
[1] = D3DCOLOR_B_G(diffuseColor
) / 255.0f
;
284 color
[2] = D3DCOLOR_B_B(diffuseColor
) / 255.0f
;
285 color
[3] = D3DCOLOR_B_A(diffuseColor
) / 255.0f
;
287 for (i
= 0; i
< num_untracked_materials
; ++i
)
289 gl_info
->gl_ops
.gl
.p_glMaterialfv(GL_FRONT_AND_BACK
, context
->untracked_materials
[i
], color
);
294 /* Specular ------------------------------- */
296 const void *ptrToCoords
= specular
+ SkipnStrides
* si
->elements
[WINED3D_FFP_SPECULAR
].stride
;
298 specular_funcs
[si
->elements
[WINED3D_FFP_SPECULAR
].format
->emit_idx
](ptrToCoords
);
302 DWORD specularColor
= *(const DWORD
*)ptrToCoords
;
303 GL_EXTCALL(glFogCoordfEXT((float) (specularColor
>> 24)));
307 /* Normal -------------------------------- */
310 const void *ptrToCoords
= normal
+ SkipnStrides
* si
->elements
[WINED3D_FFP_NORMAL
].stride
;
311 normal_funcs
[si
->elements
[WINED3D_FFP_NORMAL
].format
->emit_idx
](ptrToCoords
);
314 /* Position -------------------------------- */
316 const void *ptrToCoords
= position
+ SkipnStrides
* si
->elements
[WINED3D_FFP_POSITION
].stride
;
317 position_funcs
[si
->elements
[WINED3D_FFP_POSITION
].format
->emit_idx
](ptrToCoords
);
320 /* For non indexed mode, step onto next parts */
321 if (!idxData
) ++SkipnStrides
;
324 gl_info
->gl_ops
.gl
.p_glEnd();
325 checkGLcall("glEnd and previous calls");
328 /* Context activation is done by the caller. */
329 static inline void send_attribute(const struct wined3d_gl_info
*gl_info
,
330 enum wined3d_format_id format
, const UINT index
, const void *ptr
)
334 case WINED3DFMT_R32_FLOAT
:
335 GL_EXTCALL(glVertexAttrib1fvARB(index
, ptr
));
337 case WINED3DFMT_R32G32_FLOAT
:
338 GL_EXTCALL(glVertexAttrib2fvARB(index
, ptr
));
340 case WINED3DFMT_R32G32B32_FLOAT
:
341 GL_EXTCALL(glVertexAttrib3fvARB(index
, ptr
));
343 case WINED3DFMT_R32G32B32A32_FLOAT
:
344 GL_EXTCALL(glVertexAttrib4fvARB(index
, ptr
));
347 case WINED3DFMT_R8G8B8A8_UINT
:
348 GL_EXTCALL(glVertexAttrib4ubvARB(index
, ptr
));
350 case WINED3DFMT_B8G8R8A8_UNORM
:
351 if (gl_info
->supported
[ARB_VERTEX_ARRAY_BGRA
])
353 const DWORD
*src
= ptr
;
354 DWORD c
= *src
& 0xff00ff00;
355 c
|= (*src
& 0xff0000) >> 16;
356 c
|= (*src
& 0xff) << 16;
357 GL_EXTCALL(glVertexAttrib4NubvARB(index
, (GLubyte
*)&c
));
360 /* else fallthrough */
361 case WINED3DFMT_R8G8B8A8_UNORM
:
362 GL_EXTCALL(glVertexAttrib4NubvARB(index
, ptr
));
365 case WINED3DFMT_R16G16_SINT
:
366 GL_EXTCALL(glVertexAttrib4svARB(index
, ptr
));
368 case WINED3DFMT_R16G16B16A16_SINT
:
369 GL_EXTCALL(glVertexAttrib4svARB(index
, ptr
));
372 case WINED3DFMT_R16G16_SNORM
:
374 GLshort s
[4] = {((const GLshort
*)ptr
)[0], ((const GLshort
*)ptr
)[1], 0, 1};
375 GL_EXTCALL(glVertexAttrib4NsvARB(index
, s
));
378 case WINED3DFMT_R16G16_UNORM
:
380 GLushort s
[4] = {((const GLushort
*)ptr
)[0], ((const GLushort
*)ptr
)[1], 0, 1};
381 GL_EXTCALL(glVertexAttrib4NusvARB(index
, s
));
384 case WINED3DFMT_R16G16B16A16_SNORM
:
385 GL_EXTCALL(glVertexAttrib4NsvARB(index
, ptr
));
387 case WINED3DFMT_R16G16B16A16_UNORM
:
388 GL_EXTCALL(glVertexAttrib4NusvARB(index
, ptr
));
391 case WINED3DFMT_R10G10B10A2_UINT
:
392 FIXME("Unsure about WINED3DDECLTYPE_UDEC3\n");
393 /*glVertexAttrib3usvARB(instancedData[j], (GLushort *) ptr); Does not exist */
395 case WINED3DFMT_R10G10B10A2_SNORM
:
396 FIXME("Unsure about WINED3DDECLTYPE_DEC3N\n");
397 /*glVertexAttrib3NusvARB(instancedData[j], (GLushort *) ptr); Does not exist */
400 case WINED3DFMT_R16G16_FLOAT
:
401 /* Are those 16 bit floats. C doesn't have a 16 bit float type. I could read the single bits and calculate a 4
402 * byte float according to the IEEE standard
404 if (gl_info
->supported
[NV_HALF_FLOAT
] && gl_info
->supported
[NV_VERTEX_PROGRAM
])
406 /* Not supported by GL_ARB_half_float_vertex */
407 GL_EXTCALL(glVertexAttrib2hvNV(index
, ptr
));
411 float x
= float_16_to_32(((const unsigned short *)ptr
) + 0);
412 float y
= float_16_to_32(((const unsigned short *)ptr
) + 1);
413 GL_EXTCALL(glVertexAttrib2fARB(index
, x
, y
));
416 case WINED3DFMT_R16G16B16A16_FLOAT
:
417 if (gl_info
->supported
[NV_HALF_FLOAT
] && gl_info
->supported
[NV_VERTEX_PROGRAM
])
419 /* Not supported by GL_ARB_half_float_vertex */
420 GL_EXTCALL(glVertexAttrib4hvNV(index
, ptr
));
424 float x
= float_16_to_32(((const unsigned short *)ptr
) + 0);
425 float y
= float_16_to_32(((const unsigned short *)ptr
) + 1);
426 float z
= float_16_to_32(((const unsigned short *)ptr
) + 2);
427 float w
= float_16_to_32(((const unsigned short *)ptr
) + 3);
428 GL_EXTCALL(glVertexAttrib4fARB(index
, x
, y
, z
, w
));
433 ERR("Unexpected attribute format: %s\n", debug_d3dformat(format
));
438 /* Context activation is done by the caller. */
439 static void drawStridedSlowVs(const struct wined3d_gl_info
*gl_info
, const struct wined3d_state
*state
,
440 const struct wined3d_stream_info
*si
, UINT numberOfVertices
, GLenum glPrimitiveType
,
441 const void *idxData
, UINT idxSize
, UINT startIdx
)
443 LONG SkipnStrides
= startIdx
+ state
->load_base_vertex_index
;
444 const DWORD
*pIdxBufL
= NULL
;
445 const WORD
*pIdxBufS
= NULL
;
452 /* Immediate mode drawing can't make use of indices in a vbo - get the
453 * data from the index buffer. If the index buffer has no vbo (not
454 * supported or other reason), or with user pointer drawing idxData
455 * will be non-NULL. */
457 idxData
= buffer_get_sysmem(state
->index_buffer
, gl_info
);
459 if (idxSize
== 2) pIdxBufS
= idxData
;
460 else pIdxBufL
= idxData
;
461 } else if (idxData
) {
462 ERR("non-NULL idxData with 0 idxSize, this should never happen\n");
466 /* Start drawing in GL */
467 gl_info
->gl_ops
.gl
.p_glBegin(glPrimitiveType
);
469 for (vx_index
= 0; vx_index
< numberOfVertices
; ++vx_index
)
473 /* Indexed so work out the number of strides to skip */
475 SkipnStrides
= pIdxBufS
[startIdx
+ vx_index
] + state
->load_base_vertex_index
;
477 SkipnStrides
= pIdxBufL
[startIdx
+ vx_index
] + state
->load_base_vertex_index
;
480 for (i
= MAX_ATTRIBS
- 1; i
>= 0; i
--)
482 if (!(si
->use_map
& (1 << i
))) continue;
484 ptr
= si
->elements
[i
].data
.addr
+ si
->elements
[i
].stride
* SkipnStrides
;
486 send_attribute(gl_info
, si
->elements
[i
].format
->id
, i
, ptr
);
491 gl_info
->gl_ops
.gl
.p_glEnd();
494 /* Context activation is done by the caller. */
495 static void drawStridedInstanced(const struct wined3d_gl_info
*gl_info
, const struct wined3d_state
*state
,
496 const struct wined3d_stream_info
*si
, UINT numberOfVertices
, GLenum glPrimitiveType
,
497 const void *idxData
, UINT idxSize
, UINT startIdx
, UINT base_vertex_index
, UINT instance_count
)
499 int numInstancedAttribs
= 0, j
;
500 UINT instancedData
[sizeof(si
->elements
) / sizeof(*si
->elements
) /* 16 */];
501 GLenum idxtype
= idxSize
== 2 ? GL_UNSIGNED_SHORT
: GL_UNSIGNED_INT
;
506 /* This is a nasty thing. MSDN says no hardware supports that and apps have to use software vertex processing.
507 * We don't support this for now
509 * Shouldn't be too hard to support with opengl, in theory just call glDrawArrays instead of drawElements.
510 * But the StreamSourceFreq value has a different meaning in that situation.
512 FIXME("Non-indexed instanced drawing is not supported\n");
516 for (i
= 0; i
< sizeof(si
->elements
) / sizeof(*si
->elements
); ++i
)
518 if (!(si
->use_map
& (1 << i
))) continue;
520 if (state
->streams
[si
->elements
[i
].stream_idx
].flags
& WINED3DSTREAMSOURCE_INSTANCEDATA
)
522 instancedData
[numInstancedAttribs
] = i
;
523 numInstancedAttribs
++;
527 for (i
= 0; i
< instance_count
; ++i
)
529 /* Specify the instanced attributes using immediate mode calls */
530 for(j
= 0; j
< numInstancedAttribs
; j
++) {
531 const BYTE
*ptr
= si
->elements
[instancedData
[j
]].data
.addr
532 + si
->elements
[instancedData
[j
]].stride
* i
;
533 if (si
->elements
[instancedData
[j
]].data
.buffer_object
)
535 struct wined3d_buffer
*vb
= state
->streams
[si
->elements
[instancedData
[j
]].stream_idx
].buffer
;
536 ptr
+= (ULONG_PTR
)buffer_get_sysmem(vb
, gl_info
);
539 send_attribute(gl_info
, si
->elements
[instancedData
[j
]].format
->id
, instancedData
[j
], ptr
);
542 if (gl_info
->supported
[ARB_DRAW_ELEMENTS_BASE_VERTEX
])
544 GL_EXTCALL(glDrawElementsBaseVertex(glPrimitiveType
, numberOfVertices
, idxtype
,
545 (const char *)idxData
+(idxSize
* startIdx
), base_vertex_index
));
546 checkGLcall("glDrawElementsBaseVertex");
550 gl_info
->gl_ops
.gl
.p_glDrawElements(glPrimitiveType
, numberOfVertices
, idxtype
,
551 (const char *)idxData
+ (idxSize
* startIdx
));
552 checkGLcall("glDrawElements");
557 static void remove_vbos(const struct wined3d_gl_info
*gl_info
,
558 const struct wined3d_state
*state
, struct wined3d_stream_info
*s
)
562 for (i
= 0; i
< (sizeof(s
->elements
) / sizeof(*s
->elements
)); ++i
)
564 struct wined3d_stream_info_element
*e
;
566 if (!(s
->use_map
& (1 << i
))) continue;
569 if (e
->data
.buffer_object
)
571 struct wined3d_buffer
*vb
= state
->streams
[e
->stream_idx
].buffer
;
572 e
->data
.buffer_object
= 0;
573 e
->data
.addr
= (BYTE
*)((ULONG_PTR
)e
->data
.addr
+ (ULONG_PTR
)buffer_get_sysmem(vb
, gl_info
));
578 /* Routine common to the draw primitive and draw indexed primitive routines */
579 void draw_primitive(struct wined3d_device
*device
, UINT start_idx
, UINT index_count
,
580 UINT start_instance
, UINT instance_count
, BOOL indexed
, const void *idx_data
)
582 const struct wined3d_state
*state
= &device
->stateBlock
->state
;
583 const struct wined3d_stream_info
*stream_info
;
584 struct wined3d_event_query
*ib_query
= NULL
;
585 struct wined3d_stream_info si_emulated
;
586 const struct wined3d_gl_info
*gl_info
;
587 struct wined3d_context
*context
;
588 BOOL emulation
= FALSE
;
592 if (!index_count
) return;
594 if (state
->render_states
[WINED3D_RS_COLORWRITEENABLE
])
596 /* Invalidate the back buffer memory so LockRect will read it the next time */
597 for (i
= 0; i
< device
->adapter
->gl_info
.limits
.buffers
; ++i
)
599 struct wined3d_surface
*target
= device
->fb
.render_targets
[i
];
602 surface_load_location(target
, target
->draw_binding
, NULL
);
603 surface_modify_location(target
, target
->draw_binding
, TRUE
);
608 /* Signals other modules that a drawing is in progress and the stateblock finalized */
609 device
->isInDraw
= TRUE
;
611 context
= context_acquire(device
, device
->fb
.render_targets
[0]);
614 context_release(context
);
615 WARN("Invalid context, skipping draw.\n");
618 gl_info
= context
->gl_info
;
620 if (device
->fb
.depth_stencil
)
622 /* Note that this depends on the context_acquire() call above to set
623 * context->render_offscreen properly. We don't currently take the
624 * Z-compare function into account, but we could skip loading the
625 * depthstencil for D3DCMP_NEVER and D3DCMP_ALWAYS as well. Also note
626 * that we never copy the stencil data.*/
627 DWORD location
= context
->render_offscreen
? device
->fb
.depth_stencil
->draw_binding
: SFLAG_INDRAWABLE
;
628 if (state
->render_states
[WINED3D_RS_ZWRITEENABLE
] || state
->render_states
[WINED3D_RS_ZENABLE
])
630 struct wined3d_surface
*ds
= device
->fb
.depth_stencil
;
631 RECT current_rect
, draw_rect
, r
;
633 if (!context
->render_offscreen
&& ds
!= device
->onscreen_depth_stencil
)
634 device_switch_onscreen_ds(device
, context
, ds
);
636 if (ds
->flags
& location
)
637 SetRect(¤t_rect
, 0, 0, ds
->ds_current_size
.cx
, ds
->ds_current_size
.cy
);
639 SetRectEmpty(¤t_rect
);
641 wined3d_get_draw_rect(state
, &draw_rect
);
643 IntersectRect(&r
, &draw_rect
, ¤t_rect
);
644 if (!EqualRect(&r
, &draw_rect
))
645 surface_load_ds_location(ds
, context
, location
);
649 if (!context_apply_draw_state(context
, device
))
651 context_release(context
);
652 WARN("Unable to apply draw state, skipping draw.\n");
656 if (device
->fb
.depth_stencil
&& state
->render_states
[WINED3D_RS_ZWRITEENABLE
])
658 struct wined3d_surface
*ds
= device
->fb
.depth_stencil
;
659 DWORD location
= context
->render_offscreen
? ds
->draw_binding
: SFLAG_INDRAWABLE
;
661 surface_modify_ds_location(ds
, location
, ds
->ds_current_size
.cx
, ds
->ds_current_size
.cy
);
664 if ((!gl_info
->supported
[WINED3D_GL_VERSION_2_0
]
665 || !gl_info
->supported
[NV_POINT_SPRITE
])
666 && context
->render_offscreen
667 && state
->render_states
[WINED3D_RS_POINTSPRITEENABLE
]
668 && state
->gl_primitive_type
== GL_POINTS
)
670 FIXME("Point sprite coordinate origin switching not supported.\n");
673 stream_info
= &device
->strided_streams
;
674 if (device
->instance_count
)
675 instance_count
= device
->instance_count
;
679 if (!state
->user_stream
)
681 struct wined3d_buffer
*index_buffer
= state
->index_buffer
;
682 if (!index_buffer
->buffer_object
|| !stream_info
->all_vbo
)
683 idx_data
= index_buffer
->resource
.allocatedMemory
;
686 ib_query
= index_buffer
->query
;
691 if (state
->index_format
== WINED3DFMT_R16_UINT
)
699 if (!stream_info
->position_transformed
&& context
->num_untracked_materials
700 && state
->render_states
[WINED3D_RS_LIGHTING
])
705 FIXME("Using software emulation because not all material properties could be tracked.\n");
707 WARN("Using software emulation because not all material properties could be tracked.\n");
710 else if (context
->fog_coord
&& state
->render_states
[WINED3D_RS_FOGENABLE
])
714 /* Either write a pipeline replacement shader or convert the
715 * specular alpha from unsigned byte to a float in the vertex
718 FIXME("Using software emulation because manual fog coordinates are provided.\n");
720 WARN("Using software emulation because manual fog coordinates are provided.\n");
726 si_emulated
= device
->strided_streams
;
727 remove_vbos(gl_info
, state
, &si_emulated
);
728 stream_info
= &si_emulated
;
732 if (device
->useDrawStridedSlow
|| emulation
)
734 /* Immediate mode drawing. */
740 FIXME("Using immediate mode with vertex shaders for half float emulation.\n");
742 WARN("Using immediate mode with vertex shaders for half float emulation.\n");
744 drawStridedSlowVs(gl_info
, state
, stream_info
, index_count
,
745 state
->gl_primitive_type
, idx_data
, idx_size
, start_idx
);
749 drawStridedSlow(device
, context
, stream_info
, index_count
,
750 state
->gl_primitive_type
, idx_data
, idx_size
, start_idx
);
753 else if (!gl_info
->supported
[ARB_INSTANCED_ARRAYS
] && instance_count
)
755 /* Instancing emulation by mixing immediate mode and arrays. */
756 drawStridedInstanced(gl_info
, state
, stream_info
, index_count
, state
->gl_primitive_type
,
757 idx_data
, idx_size
, start_idx
, state
->base_vertex_index
, instance_count
);
761 drawStridedFast(gl_info
, state
->gl_primitive_type
, index_count
, idx_size
, idx_data
,
762 start_idx
, state
->base_vertex_index
, start_instance
, instance_count
);
766 wined3d_event_query_issue(ib_query
, device
);
767 for (i
= 0; i
< device
->num_buffer_queries
; ++i
)
769 wined3d_event_query_issue(device
->buffer_queries
[i
], device
);
772 if (wined3d_settings
.strict_draw_ordering
)
773 gl_info
->gl_ops
.gl
.p_glFlush(); /* Flush to ensure ordering across contexts. */
775 context_release(context
);
777 TRACE("Done all gl drawing\n");
779 /* Control goes back to the device, stateblock values may change again */
780 device
->isInDraw
= FALSE
;
783 static void normalize_normal(float *n
) {
784 float length
= n
[0] * n
[0] + n
[1] * n
[1] + n
[2] * n
[2];
785 if (length
== 0.0f
) return;
786 length
= sqrtf(length
);
787 n
[0] = n
[0] / length
;
788 n
[1] = n
[1] / length
;
789 n
[2] = n
[2] / length
;
792 /* Tesselates a high order rectangular patch into single triangles using gl evaluators
794 * The problem is that OpenGL does not offer a direct way to return the tesselated primitives,
795 * and they can't be sent off for rendering directly either. Tesselating is slow, so we want
796 * to cache the patches in a vertex buffer. But more importantly, gl can't bind generated
797 * attributes to numbered shader attributes, so we have to store them and rebind them as needed
800 * To read back, the opengl feedback mode is used. This creates a problem because we want
801 * untransformed, unlit vertices, but feedback runs everything through transform and lighting.
802 * Thus disable lighting and set identity matrices to get unmodified colors and positions.
803 * To overcome clipping find the biggest x, y and z values of the vertices in the patch and scale
804 * them to [-1.0;+1.0] and set the viewport up to scale them back.
806 * Normals are more tricky: Draw white vertices with 3 directional lights, and calculate the
807 * resulting colors back to the normals.
809 * NOTE: This function activates a context for blitting, modifies matrices & viewport, but
810 * does not restore it because normally a draw follows immediately afterwards. The caller is
811 * responsible of taking care that either the gl states are restored, or the context activated
812 * for drawing to reset the lastWasBlit flag.
814 HRESULT
tesselate_rectpatch(struct wined3d_device
*This
, struct wined3d_rect_patch
*patch
)
816 unsigned int i
, j
, num_quads
, out_vertex_size
, buffer_size
, d3d_out_vertex_size
;
817 const struct wined3d_rect_patch_info
*info
= &patch
->rect_patch_info
;
818 float max_x
= 0.0f
, max_y
= 0.0f
, max_z
= 0.0f
, neg_z
= 0.0f
;
819 struct wined3d_state
*state
= &This
->stateBlock
->state
;
820 struct wined3d_stream_info stream_info
;
821 struct wined3d_stream_info_element
*e
;
822 const struct wined3d_gl_info
*gl_info
;
823 struct wined3d_context
*context
;
824 struct wined3d_shader
*vs
;
827 GLenum feedback_type
;
830 /* Simply activate the context for blitting. This disables all the things we don't want and
831 * takes care of dirtifying. Dirtifying is preferred over pushing / popping, since drawing the
832 * patch (as opposed to normal draws) will most likely need different changes anyway. */
833 context
= context_acquire(This
, NULL
);
834 gl_info
= context
->gl_info
;
835 context_apply_blit_state(context
, This
);
837 /* First, locate the position data. This is provided in a vertex buffer in
838 * the stateblock. Beware of VBOs. */
839 vs
= state
->vertex_shader
;
840 state
->vertex_shader
= NULL
;
841 device_stream_info_from_declaration(This
, &stream_info
);
842 state
->vertex_shader
= vs
;
844 e
= &stream_info
.elements
[WINED3D_FFP_POSITION
];
845 if (e
->data
.buffer_object
)
847 struct wined3d_buffer
*vb
= state
->streams
[e
->stream_idx
].buffer
;
848 e
->data
.addr
= (BYTE
*)((ULONG_PTR
)e
->data
.addr
+ (ULONG_PTR
)buffer_get_sysmem(vb
, context
->gl_info
));
850 vtxStride
= e
->stride
;
852 + vtxStride
* info
->stride
* info
->start_vertex_offset_height
853 + vtxStride
* info
->start_vertex_offset_width
;
855 /* Not entirely sure about what happens with transformed vertices */
856 if (stream_info
.position_transformed
) FIXME("Transformed position in rectpatch generation\n");
858 if(vtxStride
% sizeof(GLfloat
)) {
859 /* glMap2f reads vertex sizes in GLfloats, the d3d stride is in bytes.
860 * I don't see how the stride could not be a multiple of 4, but make sure
863 ERR("Vertex stride is not a multiple of sizeof(GLfloat)\n");
865 if (info
->basis
!= WINED3D_BASIS_BEZIER
)
866 FIXME("Basis is %s, how to handle this?\n", debug_d3dbasis(info
->basis
));
867 if (info
->degree
!= WINED3D_DEGREE_CUBIC
)
868 FIXME("Degree is %s, how to handle this?\n", debug_d3ddegree(info
->degree
));
870 /* First, get the boundary cube of the input data */
871 for (j
= 0; j
< info
->height
; ++j
)
873 for (i
= 0; i
< info
->width
; ++i
)
875 const float *v
= (const float *)(data
+ vtxStride
* i
+ vtxStride
* info
->stride
* j
);
876 if(fabs(v
[0]) > max_x
) max_x
= fabsf(v
[0]);
877 if(fabs(v
[1]) > max_y
) max_y
= fabsf(v
[1]);
878 if(fabs(v
[2]) > max_z
) max_z
= fabsf(v
[2]);
879 if(v
[2] < neg_z
) neg_z
= v
[2];
883 /* This needs some improvements in the vertex decl code */
884 FIXME("Cannot find data to generate. Only generating position and normals\n");
885 patch
->has_normals
= TRUE
;
886 patch
->has_texcoords
= FALSE
;
888 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_PROJECTION
);
889 checkGLcall("glMatrixMode(GL_PROJECTION)");
890 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
891 checkGLcall("glLoadIdentity()");
892 gl_info
->gl_ops
.gl
.p_glScalef(1.0f
/ (max_x
), 1.0f
/ (max_y
), max_z
== 0.0f
? 1.0f
: 1.0f
/ (2.0f
* max_z
));
893 gl_info
->gl_ops
.gl
.p_glTranslatef(0.0f
, 0.0f
, 0.5f
);
894 checkGLcall("glScalef");
895 gl_info
->gl_ops
.gl
.p_glViewport(-max_x
, -max_y
, 2 * (max_x
), 2 * (max_y
));
896 checkGLcall("glViewport");
898 /* Some states to take care of. If we're in wireframe opengl will produce lines, and confuse
899 * our feedback buffer parser
901 gl_info
->gl_ops
.gl
.p_glPolygonMode(GL_FRONT_AND_BACK
, GL_FILL
);
902 checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)");
903 context_invalidate_state(context
, STATE_RENDER(WINED3D_RS_FILLMODE
));
904 if (patch
->has_normals
)
906 static const GLfloat black
[] = {0.0f
, 0.0f
, 0.0f
, 0.0f
};
907 static const GLfloat red
[] = {1.0f
, 0.0f
, 0.0f
, 0.0f
};
908 static const GLfloat green
[] = {0.0f
, 1.0f
, 0.0f
, 0.0f
};
909 static const GLfloat blue
[] = {0.0f
, 0.0f
, 1.0f
, 0.0f
};
910 static const GLfloat white
[] = {1.0f
, 1.0f
, 1.0f
, 1.0f
};
911 gl_info
->gl_ops
.gl
.p_glEnable(GL_LIGHTING
);
912 checkGLcall("glEnable(GL_LIGHTING)");
913 gl_info
->gl_ops
.gl
.p_glLightModelfv(GL_LIGHT_MODEL_AMBIENT
, black
);
914 checkGLcall("glLightModel for MODEL_AMBIENT");
915 context_invalidate_state(context
, STATE_RENDER(WINED3D_RS_AMBIENT
));
917 for (i
= 3; i
< context
->gl_info
->limits
.lights
; ++i
)
919 gl_info
->gl_ops
.gl
.p_glDisable(GL_LIGHT0
+ i
);
920 checkGLcall("glDisable(GL_LIGHT0 + i)");
921 context_invalidate_state(context
, STATE_ACTIVELIGHT(i
));
924 context_invalidate_state(context
, STATE_ACTIVELIGHT(0));
925 gl_info
->gl_ops
.gl
.p_glLightfv(GL_LIGHT0
, GL_DIFFUSE
, red
);
926 gl_info
->gl_ops
.gl
.p_glLightfv(GL_LIGHT0
, GL_SPECULAR
, black
);
927 gl_info
->gl_ops
.gl
.p_glLightfv(GL_LIGHT0
, GL_AMBIENT
, black
);
928 gl_info
->gl_ops
.gl
.p_glLightfv(GL_LIGHT0
, GL_POSITION
, red
);
929 gl_info
->gl_ops
.gl
.p_glEnable(GL_LIGHT0
);
930 checkGLcall("Setting up light 1");
931 context_invalidate_state(context
, STATE_ACTIVELIGHT(1));
932 gl_info
->gl_ops
.gl
.p_glLightfv(GL_LIGHT1
, GL_DIFFUSE
, green
);
933 gl_info
->gl_ops
.gl
.p_glLightfv(GL_LIGHT1
, GL_SPECULAR
, black
);
934 gl_info
->gl_ops
.gl
.p_glLightfv(GL_LIGHT1
, GL_AMBIENT
, black
);
935 gl_info
->gl_ops
.gl
.p_glLightfv(GL_LIGHT1
, GL_POSITION
, green
);
936 gl_info
->gl_ops
.gl
.p_glEnable(GL_LIGHT1
);
937 checkGLcall("Setting up light 2");
938 context_invalidate_state(context
, STATE_ACTIVELIGHT(2));
939 gl_info
->gl_ops
.gl
.p_glLightfv(GL_LIGHT2
, GL_DIFFUSE
, blue
);
940 gl_info
->gl_ops
.gl
.p_glLightfv(GL_LIGHT2
, GL_SPECULAR
, black
);
941 gl_info
->gl_ops
.gl
.p_glLightfv(GL_LIGHT2
, GL_AMBIENT
, black
);
942 gl_info
->gl_ops
.gl
.p_glLightfv(GL_LIGHT2
, GL_POSITION
, blue
);
943 gl_info
->gl_ops
.gl
.p_glEnable(GL_LIGHT2
);
944 checkGLcall("Setting up light 3");
946 context_invalidate_state(context
, STATE_MATERIAL
);
947 context_invalidate_state(context
, STATE_RENDER(WINED3D_RS_COLORVERTEX
));
948 gl_info
->gl_ops
.gl
.p_glDisable(GL_COLOR_MATERIAL
);
949 gl_info
->gl_ops
.gl
.p_glMaterialfv(GL_FRONT_AND_BACK
, GL_EMISSION
, black
);
950 gl_info
->gl_ops
.gl
.p_glMaterialfv(GL_FRONT_AND_BACK
, GL_SPECULAR
, black
);
951 gl_info
->gl_ops
.gl
.p_glMaterialfv(GL_FRONT_AND_BACK
, GL_DIFFUSE
, white
);
952 checkGLcall("Setting up materials");
955 /* Enable the needed maps.
956 * GL_MAP2_VERTEX_3 is needed for positional data.
957 * GL_AUTO_NORMAL to generate normals from the position. Do not use GL_MAP2_NORMAL.
958 * GL_MAP2_TEXTURE_COORD_4 for texture coords
960 num_quads
= ceilf(patch
->numSegs
[0]) * ceilf(patch
->numSegs
[1]);
961 out_vertex_size
= 3 /* position */;
962 d3d_out_vertex_size
= 3;
963 gl_info
->gl_ops
.gl
.p_glEnable(GL_MAP2_VERTEX_3
);
964 if (patch
->has_normals
&& patch
->has_texcoords
)
966 FIXME("Texcoords not handled yet\n");
967 feedback_type
= GL_3D_COLOR_TEXTURE
;
968 out_vertex_size
+= 8;
969 d3d_out_vertex_size
+= 7;
970 gl_info
->gl_ops
.gl
.p_glEnable(GL_AUTO_NORMAL
);
971 gl_info
->gl_ops
.gl
.p_glEnable(GL_MAP2_TEXTURE_COORD_4
);
973 else if (patch
->has_texcoords
)
975 FIXME("Texcoords not handled yet\n");
976 feedback_type
= GL_3D_COLOR_TEXTURE
;
977 out_vertex_size
+= 7;
978 d3d_out_vertex_size
+= 4;
979 gl_info
->gl_ops
.gl
.p_glEnable(GL_MAP2_TEXTURE_COORD_4
);
981 else if (patch
->has_normals
)
983 feedback_type
= GL_3D_COLOR
;
984 out_vertex_size
+= 4;
985 d3d_out_vertex_size
+= 3;
986 gl_info
->gl_ops
.gl
.p_glEnable(GL_AUTO_NORMAL
);
990 feedback_type
= GL_3D
;
992 checkGLcall("glEnable vertex attrib generation");
994 buffer_size
= num_quads
* out_vertex_size
* 2 /* triangle list */ * 3 /* verts per tri */
995 + 4 * num_quads
/* 2 triangle markers per quad + num verts in tri */;
996 feedbuffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, buffer_size
* sizeof(float) * 8);
998 gl_info
->gl_ops
.gl
.p_glMap2f(GL_MAP2_VERTEX_3
,
999 0.0f
, 1.0f
, vtxStride
/ sizeof(float), info
->width
,
1000 0.0f
, 1.0f
, info
->stride
* vtxStride
/ sizeof(float), info
->height
,
1001 (const GLfloat
*)data
);
1002 checkGLcall("glMap2f");
1003 if (patch
->has_texcoords
)
1005 gl_info
->gl_ops
.gl
.p_glMap2f(GL_MAP2_TEXTURE_COORD_4
,
1006 0.0f
, 1.0f
, vtxStride
/ sizeof(float), info
->width
,
1007 0.0f
, 1.0f
, info
->stride
* vtxStride
/ sizeof(float), info
->height
,
1008 (const GLfloat
*)data
);
1009 checkGLcall("glMap2f");
1011 gl_info
->gl_ops
.gl
.p_glMapGrid2f(ceilf(patch
->numSegs
[0]), 0.0f
, 1.0f
, ceilf(patch
->numSegs
[1]), 0.0f
, 1.0f
);
1012 checkGLcall("glMapGrid2f");
1014 gl_info
->gl_ops
.gl
.p_glFeedbackBuffer(buffer_size
* 2, feedback_type
, feedbuffer
);
1015 checkGLcall("glFeedbackBuffer");
1016 gl_info
->gl_ops
.gl
.p_glRenderMode(GL_FEEDBACK
);
1018 gl_info
->gl_ops
.gl
.p_glEvalMesh2(GL_FILL
, 0, ceilf(patch
->numSegs
[0]), 0, ceilf(patch
->numSegs
[1]));
1019 checkGLcall("glEvalMesh2");
1021 i
= gl_info
->gl_ops
.gl
.p_glRenderMode(GL_RENDER
);
1024 ERR("Feedback failed. Expected %d elements back\n", buffer_size
);
1025 HeapFree(GetProcessHeap(), 0, feedbuffer
);
1026 context_release(context
);
1027 return WINED3DERR_DRIVERINTERNALERROR
;
1029 else if (i
!= buffer_size
)
1031 ERR("Unexpected amount of elements returned. Expected %d, got %d\n", buffer_size
, i
);
1032 HeapFree(GetProcessHeap(), 0, feedbuffer
);
1033 context_release(context
);
1034 return WINED3DERR_DRIVERINTERNALERROR
;
1038 TRACE("Got %d elements as expected\n", i
);
1041 HeapFree(GetProcessHeap(), 0, patch
->mem
);
1042 patch
->mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, num_quads
* 6 * d3d_out_vertex_size
* sizeof(float) * 8);
1044 for(j
= 0; j
< buffer_size
; j
+= (3 /* num verts */ * out_vertex_size
+ 2 /* tri marker */)) {
1045 if(feedbuffer
[j
] != GL_POLYGON_TOKEN
) {
1046 ERR("Unexpected token: %f\n", feedbuffer
[j
]);
1049 if(feedbuffer
[j
+ 1] != 3) {
1050 ERR("Unexpected polygon: %f corners\n", feedbuffer
[j
+ 1]);
1053 /* Somehow there are different ideas about back / front facing, so fix up the
1056 patch
->mem
[i
+ 0] = feedbuffer
[j
+ out_vertex_size
* 2 + 2]; /* x, triangle 2 */
1057 patch
->mem
[i
+ 1] = feedbuffer
[j
+ out_vertex_size
* 2 + 3]; /* y, triangle 2 */
1058 patch
->mem
[i
+ 2] = (feedbuffer
[j
+ out_vertex_size
* 2 + 4] - 0.5f
) * 4.0f
* max_z
; /* z, triangle 3 */
1059 if(patch
->has_normals
) {
1060 patch
->mem
[i
+ 3] = feedbuffer
[j
+ out_vertex_size
* 2 + 5];
1061 patch
->mem
[i
+ 4] = feedbuffer
[j
+ out_vertex_size
* 2 + 6];
1062 patch
->mem
[i
+ 5] = feedbuffer
[j
+ out_vertex_size
* 2 + 7];
1064 i
+= d3d_out_vertex_size
;
1066 patch
->mem
[i
+ 0] = feedbuffer
[j
+ out_vertex_size
* 1 + 2]; /* x, triangle 2 */
1067 patch
->mem
[i
+ 1] = feedbuffer
[j
+ out_vertex_size
* 1 + 3]; /* y, triangle 2 */
1068 patch
->mem
[i
+ 2] = (feedbuffer
[j
+ out_vertex_size
* 1 + 4] - 0.5f
) * 4.0f
* max_z
; /* z, triangle 2 */
1069 if(patch
->has_normals
) {
1070 patch
->mem
[i
+ 3] = feedbuffer
[j
+ out_vertex_size
* 1 + 5];
1071 patch
->mem
[i
+ 4] = feedbuffer
[j
+ out_vertex_size
* 1 + 6];
1072 patch
->mem
[i
+ 5] = feedbuffer
[j
+ out_vertex_size
* 1 + 7];
1074 i
+= d3d_out_vertex_size
;
1076 patch
->mem
[i
+ 0] = feedbuffer
[j
+ out_vertex_size
* 0 + 2]; /* x, triangle 1 */
1077 patch
->mem
[i
+ 1] = feedbuffer
[j
+ out_vertex_size
* 0 + 3]; /* y, triangle 1 */
1078 patch
->mem
[i
+ 2] = (feedbuffer
[j
+ out_vertex_size
* 0 + 4] - 0.5f
) * 4.0f
* max_z
; /* z, triangle 1 */
1079 if(patch
->has_normals
) {
1080 patch
->mem
[i
+ 3] = feedbuffer
[j
+ out_vertex_size
* 0 + 5];
1081 patch
->mem
[i
+ 4] = feedbuffer
[j
+ out_vertex_size
* 0 + 6];
1082 patch
->mem
[i
+ 5] = feedbuffer
[j
+ out_vertex_size
* 0 + 7];
1084 i
+= d3d_out_vertex_size
;
1087 if(patch
->has_normals
) {
1088 /* Now do the same with reverse light directions */
1089 static const GLfloat x
[] = {-1.0f
, 0.0f
, 0.0f
, 0.0f
};
1090 static const GLfloat y
[] = { 0.0f
, -1.0f
, 0.0f
, 0.0f
};
1091 static const GLfloat z
[] = { 0.0f
, 0.0f
, -1.0f
, 0.0f
};
1092 gl_info
->gl_ops
.gl
.p_glLightfv(GL_LIGHT0
, GL_POSITION
, x
);
1093 gl_info
->gl_ops
.gl
.p_glLightfv(GL_LIGHT1
, GL_POSITION
, y
);
1094 gl_info
->gl_ops
.gl
.p_glLightfv(GL_LIGHT2
, GL_POSITION
, z
);
1095 checkGLcall("Setting up reverse light directions");
1097 gl_info
->gl_ops
.gl
.p_glRenderMode(GL_FEEDBACK
);
1098 checkGLcall("glRenderMode(GL_FEEDBACK)");
1099 gl_info
->gl_ops
.gl
.p_glEvalMesh2(GL_FILL
, 0, ceilf(patch
->numSegs
[0]), 0, ceilf(patch
->numSegs
[1]));
1100 checkGLcall("glEvalMesh2");
1101 i
= gl_info
->gl_ops
.gl
.p_glRenderMode(GL_RENDER
);
1102 checkGLcall("glRenderMode(GL_RENDER)");
1105 for(j
= 0; j
< buffer_size
; j
+= (3 /* num verts */ * out_vertex_size
+ 2 /* tri marker */)) {
1106 if(feedbuffer
[j
] != GL_POLYGON_TOKEN
) {
1107 ERR("Unexpected token: %f\n", feedbuffer
[j
]);
1110 if(feedbuffer
[j
+ 1] != 3) {
1111 ERR("Unexpected polygon: %f corners\n", feedbuffer
[j
+ 1]);
1114 if(patch
->mem
[i
+ 3] == 0.0f
)
1115 patch
->mem
[i
+ 3] = -feedbuffer
[j
+ out_vertex_size
* 2 + 5];
1116 if(patch
->mem
[i
+ 4] == 0.0f
)
1117 patch
->mem
[i
+ 4] = -feedbuffer
[j
+ out_vertex_size
* 2 + 6];
1118 if(patch
->mem
[i
+ 5] == 0.0f
)
1119 patch
->mem
[i
+ 5] = -feedbuffer
[j
+ out_vertex_size
* 2 + 7];
1120 normalize_normal(patch
->mem
+ i
+ 3);
1121 i
+= d3d_out_vertex_size
;
1123 if(patch
->mem
[i
+ 3] == 0.0f
)
1124 patch
->mem
[i
+ 3] = -feedbuffer
[j
+ out_vertex_size
* 1 + 5];
1125 if(patch
->mem
[i
+ 4] == 0.0f
)
1126 patch
->mem
[i
+ 4] = -feedbuffer
[j
+ out_vertex_size
* 1 + 6];
1127 if(patch
->mem
[i
+ 5] == 0.0f
)
1128 patch
->mem
[i
+ 5] = -feedbuffer
[j
+ out_vertex_size
* 1 + 7];
1129 normalize_normal(patch
->mem
+ i
+ 3);
1130 i
+= d3d_out_vertex_size
;
1132 if(patch
->mem
[i
+ 3] == 0.0f
)
1133 patch
->mem
[i
+ 3] = -feedbuffer
[j
+ out_vertex_size
* 0 + 5];
1134 if(patch
->mem
[i
+ 4] == 0.0f
)
1135 patch
->mem
[i
+ 4] = -feedbuffer
[j
+ out_vertex_size
* 0 + 6];
1136 if(patch
->mem
[i
+ 5] == 0.0f
)
1137 patch
->mem
[i
+ 5] = -feedbuffer
[j
+ out_vertex_size
* 0 + 7];
1138 normalize_normal(patch
->mem
+ i
+ 3);
1139 i
+= d3d_out_vertex_size
;
1143 gl_info
->gl_ops
.gl
.p_glDisable(GL_MAP2_VERTEX_3
);
1144 gl_info
->gl_ops
.gl
.p_glDisable(GL_AUTO_NORMAL
);
1145 gl_info
->gl_ops
.gl
.p_glDisable(GL_MAP2_NORMAL
);
1146 gl_info
->gl_ops
.gl
.p_glDisable(GL_MAP2_TEXTURE_COORD_4
);
1147 checkGLcall("glDisable vertex attrib generation");
1149 context_release(context
);
1151 HeapFree(GetProcessHeap(), 0, feedbuffer
);
1153 vtxStride
= 3 * sizeof(float);
1154 if(patch
->has_normals
) {
1155 vtxStride
+= 3 * sizeof(float);
1157 if(patch
->has_texcoords
) {
1158 vtxStride
+= 4 * sizeof(float);
1160 memset(&patch
->strided
, 0, sizeof(patch
->strided
));
1161 patch
->strided
.position
.format
= WINED3DFMT_R32G32B32_FLOAT
;
1162 patch
->strided
.position
.data
= (BYTE
*)patch
->mem
;
1163 patch
->strided
.position
.stride
= vtxStride
;
1165 if (patch
->has_normals
)
1167 patch
->strided
.normal
.format
= WINED3DFMT_R32G32B32_FLOAT
;
1168 patch
->strided
.normal
.data
= (BYTE
*)patch
->mem
+ 3 * sizeof(float) /* pos */;
1169 patch
->strided
.normal
.stride
= vtxStride
;
1171 if (patch
->has_texcoords
)
1173 patch
->strided
.tex_coords
[0].format
= WINED3DFMT_R32G32B32A32_FLOAT
;
1174 patch
->strided
.tex_coords
[0].data
= (BYTE
*)patch
->mem
+ 3 * sizeof(float) /* pos */;
1175 if (patch
->has_normals
)
1176 patch
->strided
.tex_coords
[0].data
+= 3 * sizeof(float);
1177 patch
->strided
.tex_coords
[0].stride
= vtxStride
;