2004-12-09 12:42:34 +01:00
|
|
|
/*
|
|
|
|
* WINED3D draw functions
|
|
|
|
*
|
|
|
|
* Copyright 2002-2004 Jason Edmeades
|
|
|
|
* Copyright 2002-2004 Raphael Junqueira
|
2005-07-13 16:15:54 +02:00
|
|
|
* Copyright 2004 Christian Costa
|
2005-07-11 16:25:54 +02:00
|
|
|
* Copyright 2005 Oliver Stieber
|
2008-08-21 18:23:32 +02:00
|
|
|
* Copyright 2006, 2008 Henri Verbeet
|
2008-10-18 19:21:20 +02:00
|
|
|
* Copyright 2007-2008 Stefan Dösinger for CodeWeavers
|
2009-09-10 16:57:16 +02:00
|
|
|
* Copyright 2009 Henri Verbeet for CodeWeavers
|
2004-12-09 12:42:34 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-12-09 12:42:34 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2012-05-30 16:14:56 +02:00
|
|
|
#include "wine/port.h"
|
|
|
|
|
2004-12-09 12:42:34 +01:00
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
2005-07-07 22:45:39 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d_draw);
|
2013-04-17 08:47:59 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(d3d_perf);
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2005-09-27 12:49:59 +02:00
|
|
|
#include <stdio.h>
|
2007-12-17 18:18:19 +01:00
|
|
|
#include <math.h>
|
2005-09-27 12:49:59 +02:00
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2011-06-11 16:18:45 +02:00
|
|
|
static void drawStridedFast(const struct wined3d_gl_info *gl_info, GLenum primitive_type, UINT count, UINT idx_size,
|
2012-11-26 22:52:41 +01:00
|
|
|
const void *idx_data, UINT start_idx, INT base_vertex_index, UINT start_instance, UINT instance_count)
|
2009-01-07 09:00:55 +01:00
|
|
|
{
|
2009-01-08 10:19:16 +01:00
|
|
|
if (idx_size)
|
|
|
|
{
|
2011-06-11 16:18:45 +02:00
|
|
|
GLenum idxtype = idx_size == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
|
2012-11-26 22:52:41 +01:00
|
|
|
if (instance_count)
|
|
|
|
{
|
2015-02-27 13:18:22 +01:00
|
|
|
if (start_instance)
|
|
|
|
FIXME("Start instance (%u) not supported.\n", start_instance);
|
|
|
|
if (gl_info->supported[ARB_DRAW_ELEMENTS_BASE_VERTEX])
|
2012-11-26 22:52:41 +01:00
|
|
|
{
|
2015-02-27 13:18:22 +01:00
|
|
|
GL_EXTCALL(glDrawElementsInstancedBaseVertex(primitive_type, count, idxtype,
|
|
|
|
(const char *)idx_data + (idx_size * start_idx), instance_count, base_vertex_index));
|
|
|
|
checkGLcall("glDrawElementsInstancedBaseVertex");
|
2012-11-26 22:52:41 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-02-27 13:18:22 +01:00
|
|
|
GL_EXTCALL(glDrawElementsInstanced(primitive_type, count, idxtype,
|
|
|
|
(const char *)idx_data + (idx_size * start_idx), instance_count));
|
|
|
|
checkGLcall("glDrawElementsInstanced");
|
2012-11-26 22:52:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (gl_info->supported[ARB_DRAW_ELEMENTS_BASE_VERTEX])
|
2011-06-11 16:18:45 +02:00
|
|
|
{
|
|
|
|
GL_EXTCALL(glDrawElementsBaseVertex(primitive_type, count, idxtype,
|
|
|
|
(const char *)idx_data + (idx_size * start_idx), base_vertex_index));
|
|
|
|
checkGLcall("glDrawElementsBaseVertex");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDrawElements(primitive_type, count,
|
2011-06-11 16:18:45 +02:00
|
|
|
idxtype, (const char *)idx_data + (idx_size * start_idx));
|
|
|
|
checkGLcall("glDrawElements");
|
|
|
|
}
|
2009-01-08 10:19:16 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-03-24 09:38:26 +01:00
|
|
|
if (instance_count)
|
|
|
|
{
|
|
|
|
if (start_instance)
|
|
|
|
FIXME("Start instance (%u) not supported.\n", start_instance);
|
|
|
|
GL_EXTCALL(glDrawArraysInstanced(primitive_type, start_idx, count, instance_count));
|
|
|
|
checkGLcall("glDrawArraysInstanced");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glDrawArrays(primitive_type, start_idx, count);
|
|
|
|
checkGLcall("glDrawArrays");
|
|
|
|
}
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-13 16:15:54 +02:00
|
|
|
/*
|
2004-12-09 12:42:34 +01:00
|
|
|
* Actually draw using the supplied information.
|
|
|
|
* Slower GL version which extracts info about each vertex in turn
|
|
|
|
*/
|
2007-01-02 21:07:39 +01:00
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2013-09-09 15:15:36 +02:00
|
|
|
static void drawStridedSlow(const struct wined3d_device *device, struct wined3d_context *context,
|
2009-08-07 08:51:19 +02:00
|
|
|
const struct wined3d_stream_info *si, UINT NumVertexes, GLenum glPrimType,
|
2009-09-10 16:57:16 +02:00
|
|
|
const void *idxData, UINT idxSize, UINT startIdx)
|
2008-11-28 15:30:12 +01:00
|
|
|
{
|
2015-12-24 05:56:58 +01:00
|
|
|
unsigned int textureNo;
|
2007-04-06 14:22:14 +02:00
|
|
|
const WORD *pIdxBufS = NULL;
|
|
|
|
const DWORD *pIdxBufL = NULL;
|
2009-03-05 12:30:42 +01:00
|
|
|
UINT vx_index;
|
2013-08-27 08:44:59 +02:00
|
|
|
const struct wined3d_state *state = &device->state;
|
2011-06-18 00:43:06 +02:00
|
|
|
LONG SkipnStrides = startIdx;
|
2010-09-28 12:00:24 +02:00
|
|
|
BOOL pixelShader = use_ps(state);
|
2008-12-04 17:41:30 +01:00
|
|
|
BOOL specular_fog = FALSE;
|
2008-11-28 15:30:12 +01:00
|
|
|
const BYTE *texCoords[WINED3DDP_MAXTEXCOORD];
|
|
|
|
const BYTE *diffuse = NULL, *specular = NULL, *normal = NULL, *position = NULL;
|
2009-10-29 10:37:11 +01:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2013-04-25 15:20:30 +02:00
|
|
|
const struct wined3d_d3d_info *d3d_info = context->d3d_info;
|
2013-08-19 10:50:51 +02:00
|
|
|
const struct wined3d_ffp_attrib_ops *ops = &d3d_info->ffp_attrib_ops;
|
2013-04-25 15:20:30 +02:00
|
|
|
UINT texture_stages = d3d_info->limits.ffp_blend_stages;
|
2009-03-27 10:25:55 +01:00
|
|
|
const struct wined3d_stream_info_element *element;
|
2009-06-22 10:15:58 +02:00
|
|
|
UINT num_untracked_materials;
|
2008-12-04 17:41:30 +01:00
|
|
|
DWORD tex_mask = 0;
|
2007-01-17 00:06:34 +01:00
|
|
|
|
2013-04-17 08:47:59 +02:00
|
|
|
TRACE_(d3d_perf)("Using slow vertex array code\n");
|
2004-12-09 12:42:34 +01:00
|
|
|
|
|
|
|
/* Variable Initialization */
|
2010-05-21 09:35:24 +02:00
|
|
|
if (idxSize)
|
|
|
|
{
|
|
|
|
/* Immediate mode drawing can't make use of indices in a vbo - get the
|
|
|
|
* data from the index buffer. If the index buffer has no vbo (not
|
|
|
|
* supported or other reason), or with user pointer drawing idxData
|
|
|
|
* will be non-NULL. */
|
|
|
|
if (!idxData)
|
2013-09-09 15:15:36 +02:00
|
|
|
idxData = buffer_get_sysmem(state->index_buffer, context);
|
2007-02-19 15:25:32 +01:00
|
|
|
|
2009-01-20 10:00:20 +01:00
|
|
|
if (idxSize == 2) pIdxBufS = idxData;
|
|
|
|
else pIdxBufL = idxData;
|
2008-10-07 16:01:01 +02:00
|
|
|
} else if (idxData) {
|
|
|
|
ERR("non-NULL idxData with 0 idxSize, this should never happen\n");
|
|
|
|
return;
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
|
2008-12-04 17:41:30 +01:00
|
|
|
/* Start drawing in GL */
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBegin(glPrimType);
|
2008-12-04 17:41:30 +01:00
|
|
|
|
2015-08-26 12:46:47 +02:00
|
|
|
if (si->use_map & (1u << WINED3D_FFP_POSITION))
|
2009-08-25 08:17:10 +02:00
|
|
|
{
|
|
|
|
element = &si->elements[WINED3D_FFP_POSITION];
|
2011-07-15 01:14:50 +02:00
|
|
|
position = element->data.addr;
|
2009-08-25 08:17:10 +02:00
|
|
|
}
|
2008-12-04 17:41:30 +01:00
|
|
|
|
2015-08-26 12:46:47 +02:00
|
|
|
if (si->use_map & (1u << WINED3D_FFP_NORMAL))
|
2009-08-25 08:17:10 +02:00
|
|
|
{
|
|
|
|
element = &si->elements[WINED3D_FFP_NORMAL];
|
2011-07-15 01:14:50 +02:00
|
|
|
normal = element->data.addr;
|
2009-08-25 08:17:10 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glNormal3f(0, 0, 0);
|
2009-08-25 08:17:10 +02:00
|
|
|
}
|
2008-12-04 17:41:30 +01:00
|
|
|
|
2009-08-30 22:35:00 +02:00
|
|
|
num_untracked_materials = context->num_untracked_materials;
|
2015-08-26 12:46:47 +02:00
|
|
|
if (si->use_map & (1u << WINED3D_FFP_DIFFUSE))
|
2009-08-25 08:17:10 +02:00
|
|
|
{
|
|
|
|
element = &si->elements[WINED3D_FFP_DIFFUSE];
|
2011-07-15 01:14:50 +02:00
|
|
|
diffuse = element->data.addr;
|
2009-08-30 22:35:00 +02:00
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
if (num_untracked_materials && element->format->id != WINED3DFMT_B8G8R8A8_UNORM)
|
|
|
|
FIXME("Implement diffuse color tracking from %s\n", debug_d3dformat(element->format->id));
|
2009-08-25 08:17:10 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
2009-08-25 08:17:10 +02:00
|
|
|
}
|
2008-12-04 17:41:30 +01:00
|
|
|
|
2015-08-26 12:46:47 +02:00
|
|
|
if (si->use_map & (1u << WINED3D_FFP_SPECULAR))
|
2008-12-04 17:41:30 +01:00
|
|
|
{
|
2009-08-25 08:17:10 +02:00
|
|
|
element = &si->elements[WINED3D_FFP_SPECULAR];
|
2011-07-15 01:14:50 +02:00
|
|
|
specular = element->data.addr;
|
2007-01-17 00:06:34 +01:00
|
|
|
|
2008-12-04 17:41:30 +01:00
|
|
|
/* special case where the fog density is stored in the specular alpha channel */
|
2011-12-19 21:00:09 +01:00
|
|
|
if (state->render_states[WINED3D_RS_FOGENABLE]
|
2011-12-21 21:35:00 +01:00
|
|
|
&& (state->render_states[WINED3D_RS_FOGVERTEXMODE] == WINED3D_FOG_NONE
|
2010-08-30 20:29:49 +02:00
|
|
|
|| si->elements[WINED3D_FFP_POSITION].format->id == WINED3DFMT_R32G32B32A32_FLOAT)
|
2011-12-21 21:35:00 +01:00
|
|
|
&& state->render_states[WINED3D_RS_FOGTABLEMODE] == WINED3D_FOG_NONE)
|
2008-12-04 17:41:30 +01:00
|
|
|
{
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[EXT_FOG_COORD])
|
2008-12-04 17:41:30 +01:00
|
|
|
{
|
2010-08-30 20:29:49 +02:00
|
|
|
if (element->format->id == WINED3DFMT_B8G8R8A8_UNORM) specular_fog = TRUE;
|
|
|
|
else FIXME("Implement fog coordinates from %s\n", debug_d3dformat(element->format->id));
|
2008-12-04 17:41:30 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static BOOL warned;
|
|
|
|
|
|
|
|
if (!warned)
|
|
|
|
{
|
|
|
|
/* TODO: Use the fog table code from old ddraw */
|
|
|
|
FIXME("Implement fog for transformed vertices in software\n");
|
|
|
|
warned = TRUE;
|
|
|
|
}
|
2007-12-19 17:10:02 +01:00
|
|
|
}
|
|
|
|
}
|
2008-12-04 17:41:30 +01:00
|
|
|
}
|
2009-10-29 10:37:11 +01:00
|
|
|
else if (gl_info->supported[EXT_SECONDARY_COLOR])
|
2008-12-04 17:41:30 +01:00
|
|
|
{
|
|
|
|
GL_EXTCALL(glSecondaryColor3fEXT)(0, 0, 0);
|
2007-12-19 17:10:02 +01:00
|
|
|
}
|
|
|
|
|
2008-12-04 17:41:30 +01:00
|
|
|
for (textureNo = 0; textureNo < texture_stages; ++textureNo)
|
|
|
|
{
|
2012-01-09 22:16:51 +01:00
|
|
|
int coordIdx = state->texture_states[textureNo][WINED3D_TSS_TEXCOORD_INDEX];
|
2013-09-16 12:43:18 +02:00
|
|
|
DWORD texture_idx = context->tex_unit_map[textureNo];
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2009-10-29 10:37:11 +01:00
|
|
|
if (!gl_info->supported[ARB_MULTITEXTURE] && textureNo > 0)
|
2008-12-04 17:41:30 +01:00
|
|
|
{
|
|
|
|
FIXME("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-09-28 12:00:24 +02:00
|
|
|
if (!pixelShader && !state->textures[textureNo]) continue;
|
2008-12-04 17:41:30 +01:00
|
|
|
|
2009-08-17 09:39:07 +02:00
|
|
|
if (texture_idx == WINED3D_UNMAPPED_STAGE) continue;
|
2008-12-04 17:41:30 +01:00
|
|
|
|
|
|
|
if (coordIdx > 7)
|
|
|
|
{
|
|
|
|
TRACE("tex: %d - Skip tex coords, as being system generated\n", textureNo);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (coordIdx < 0)
|
|
|
|
{
|
|
|
|
FIXME("tex: %d - Coord index %d is less than zero, expect a crash.\n", textureNo, coordIdx);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-08-26 12:46:47 +02:00
|
|
|
if (si->use_map & (1u << (WINED3D_FFP_TEXCOORD0 + coordIdx)))
|
2008-12-04 17:41:30 +01:00
|
|
|
{
|
2009-08-25 08:17:10 +02:00
|
|
|
element = &si->elements[WINED3D_FFP_TEXCOORD0 + coordIdx];
|
2011-07-15 01:14:50 +02:00
|
|
|
texCoords[coordIdx] = element->data.addr;
|
2015-08-26 12:46:47 +02:00
|
|
|
tex_mask |= (1u << textureNo);
|
2008-12-04 17:41:30 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("tex: %d - Skipping tex coords, as no data supplied\n", textureNo);
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[ARB_MULTITEXTURE])
|
2008-12-04 17:41:30 +01:00
|
|
|
GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB + texture_idx, 0, 0, 0, 1));
|
|
|
|
else
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexCoord4f(0, 0, 0, 1);
|
2007-01-16 23:43:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-21 15:01:38 +02:00
|
|
|
/* We shouldn't start this function if any VBO is involved. Should I put a safety check here?
|
|
|
|
* Guess it's not necessary(we crash then anyway) and would only eat CPU time
|
|
|
|
*/
|
|
|
|
|
2004-12-09 12:42:34 +01:00
|
|
|
/* For each primitive */
|
2005-07-30 21:06:14 +02:00
|
|
|
for (vx_index = 0; vx_index < NumVertexes; ++vx_index) {
|
2008-12-04 17:41:30 +01:00
|
|
|
UINT texture, tmp_tex_mask;
|
2007-01-16 23:43:28 +01:00
|
|
|
/* Blending data and Point sizes are not supported by this function. They are not supported by the fixed
|
|
|
|
* function pipeline at all. A Fixme for them is printed after decoding the vertex declaration
|
|
|
|
*/
|
|
|
|
|
2004-12-09 12:42:34 +01:00
|
|
|
/* For indexed data, we need to go a few more strides in */
|
2010-09-14 13:38:39 +02:00
|
|
|
if (idxData)
|
|
|
|
{
|
2004-12-09 12:42:34 +01:00
|
|
|
/* Indexed so work out the number of strides to skip */
|
2010-03-17 21:59:53 +01:00
|
|
|
if (idxSize == 2)
|
2011-06-18 00:43:06 +02:00
|
|
|
SkipnStrides = pIdxBufS[startIdx + vx_index] + state->base_vertex_index;
|
2010-03-17 21:59:53 +01:00
|
|
|
else
|
2011-06-18 00:43:06 +02:00
|
|
|
SkipnStrides = pIdxBufL[startIdx + vx_index] + state->base_vertex_index;
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
|
2008-12-04 17:41:30 +01:00
|
|
|
tmp_tex_mask = tex_mask;
|
|
|
|
for (texture = 0; tmp_tex_mask; tmp_tex_mask >>= 1, ++texture)
|
|
|
|
{
|
|
|
|
int coord_idx;
|
|
|
|
const void *ptr;
|
2009-08-17 09:39:07 +02:00
|
|
|
DWORD texture_idx;
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2008-12-04 17:41:30 +01:00
|
|
|
if (!(tmp_tex_mask & 1)) continue;
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2012-01-09 22:16:51 +01:00
|
|
|
coord_idx = state->texture_states[texture][WINED3D_TSS_TEXCOORD_INDEX];
|
2009-03-27 10:25:55 +01:00
|
|
|
ptr = texCoords[coord_idx] + (SkipnStrides * si->elements[WINED3D_FFP_TEXCOORD0 + coord_idx].stride);
|
2008-09-24 15:56:48 +02:00
|
|
|
|
2013-09-16 12:43:18 +02:00
|
|
|
texture_idx = context->tex_unit_map[texture];
|
2013-08-19 10:50:51 +02:00
|
|
|
ops->texcoord[si->elements[WINED3D_FFP_TEXCOORD0 + coord_idx].format->emit_idx](
|
2009-03-27 10:25:55 +01:00
|
|
|
GL_TEXTURE0_ARB + texture_idx, ptr);
|
2008-12-04 17:41:30 +01:00
|
|
|
}
|
2004-12-09 12:42:34 +01:00
|
|
|
|
|
|
|
/* Diffuse -------------------------------- */
|
2013-08-19 10:50:51 +02:00
|
|
|
if (diffuse)
|
|
|
|
{
|
2009-03-27 10:25:55 +01:00
|
|
|
const void *ptrToCoords = diffuse + SkipnStrides * si->elements[WINED3D_FFP_DIFFUSE].stride;
|
2013-08-19 10:50:51 +02:00
|
|
|
ops->diffuse[si->elements[WINED3D_FFP_DIFFUSE].format->emit_idx](ptrToCoords);
|
2007-06-20 14:36:32 +02:00
|
|
|
|
2009-06-22 10:15:58 +02:00
|
|
|
if (num_untracked_materials)
|
|
|
|
{
|
2008-11-28 15:30:12 +01:00
|
|
|
DWORD diffuseColor = ((const DWORD *)ptrToCoords)[0];
|
2007-06-20 14:36:32 +02:00
|
|
|
unsigned char i;
|
|
|
|
float color[4];
|
2007-12-19 17:10:02 +01:00
|
|
|
|
2009-07-07 11:08:01 +02:00
|
|
|
color[0] = D3DCOLOR_B_R(diffuseColor) / 255.0f;
|
|
|
|
color[1] = D3DCOLOR_B_G(diffuseColor) / 255.0f;
|
|
|
|
color[2] = D3DCOLOR_B_B(diffuseColor) / 255.0f;
|
|
|
|
color[3] = D3DCOLOR_B_A(diffuseColor) / 255.0f;
|
2007-06-20 14:36:32 +02:00
|
|
|
|
2009-06-22 10:15:58 +02:00
|
|
|
for (i = 0; i < num_untracked_materials; ++i)
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, context->untracked_materials[i], color);
|
2007-06-20 14:36:32 +02:00
|
|
|
}
|
|
|
|
}
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Specular ------------------------------- */
|
2013-08-19 10:50:51 +02:00
|
|
|
if (specular)
|
|
|
|
{
|
2009-03-27 10:25:55 +01:00
|
|
|
const void *ptrToCoords = specular + SkipnStrides * si->elements[WINED3D_FFP_SPECULAR].stride;
|
2013-08-19 10:50:51 +02:00
|
|
|
ops->specular[si->elements[WINED3D_FFP_SPECULAR].format->emit_idx](ptrToCoords);
|
2008-12-04 17:41:30 +01:00
|
|
|
|
|
|
|
if (specular_fog)
|
|
|
|
{
|
|
|
|
DWORD specularColor = *(const DWORD *)ptrToCoords;
|
2011-05-12 18:05:27 +02:00
|
|
|
GL_EXTCALL(glFogCoordfEXT((float) (specularColor >> 24)));
|
2008-12-04 17:41:30 +01:00
|
|
|
}
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Normal -------------------------------- */
|
2010-09-14 13:38:39 +02:00
|
|
|
if (normal)
|
|
|
|
{
|
2009-03-27 10:25:55 +01:00
|
|
|
const void *ptrToCoords = normal + SkipnStrides * si->elements[WINED3D_FFP_NORMAL].stride;
|
2013-08-19 10:50:51 +02:00
|
|
|
ops->normal[si->elements[WINED3D_FFP_NORMAL].format->emit_idx](ptrToCoords);
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2004-12-09 12:42:34 +01:00
|
|
|
/* Position -------------------------------- */
|
2013-08-19 10:50:51 +02:00
|
|
|
if (position)
|
|
|
|
{
|
2009-03-27 10:25:55 +01:00
|
|
|
const void *ptrToCoords = position + SkipnStrides * si->elements[WINED3D_FFP_POSITION].stride;
|
2013-08-19 10:50:51 +02:00
|
|
|
ops->position[si->elements[WINED3D_FFP_POSITION].format->emit_idx](ptrToCoords);
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* For non indexed mode, step onto next parts */
|
2010-09-14 13:38:39 +02:00
|
|
|
if (!idxData) ++SkipnStrides;
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glEnd();
|
2004-12-09 12:42:34 +01:00
|
|
|
checkGLcall("glEnd and previous calls");
|
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2010-09-30 11:44:28 +02:00
|
|
|
static inline void send_attribute(const struct wined3d_gl_info *gl_info,
|
2010-08-23 18:28:10 +02:00
|
|
|
enum wined3d_format_id format, const UINT index, const void *ptr)
|
2009-03-27 10:25:56 +01:00
|
|
|
{
|
|
|
|
switch(format)
|
|
|
|
{
|
|
|
|
case WINED3DFMT_R32_FLOAT:
|
2015-01-22 17:41:42 +01:00
|
|
|
GL_EXTCALL(glVertexAttrib1fv(index, ptr));
|
2007-12-17 18:18:19 +01:00
|
|
|
break;
|
2009-03-27 10:25:56 +01:00
|
|
|
case WINED3DFMT_R32G32_FLOAT:
|
2015-01-22 17:41:42 +01:00
|
|
|
GL_EXTCALL(glVertexAttrib2fv(index, ptr));
|
2007-12-17 18:18:19 +01:00
|
|
|
break;
|
2009-03-27 10:25:56 +01:00
|
|
|
case WINED3DFMT_R32G32B32_FLOAT:
|
2015-01-22 17:41:42 +01:00
|
|
|
GL_EXTCALL(glVertexAttrib3fv(index, ptr));
|
2007-12-17 18:18:19 +01:00
|
|
|
break;
|
2009-03-27 10:25:56 +01:00
|
|
|
case WINED3DFMT_R32G32B32A32_FLOAT:
|
2015-01-22 17:41:42 +01:00
|
|
|
GL_EXTCALL(glVertexAttrib4fv(index, ptr));
|
2007-12-17 18:18:19 +01:00
|
|
|
break;
|
|
|
|
|
2009-03-27 10:25:56 +01:00
|
|
|
case WINED3DFMT_R8G8B8A8_UINT:
|
2015-01-22 17:41:42 +01:00
|
|
|
GL_EXTCALL(glVertexAttrib4ubv(index, ptr));
|
2007-12-17 18:18:19 +01:00
|
|
|
break;
|
2009-09-25 13:31:49 +02:00
|
|
|
case WINED3DFMT_B8G8R8A8_UNORM:
|
2010-01-25 19:51:31 +01:00
|
|
|
if (gl_info->supported[ARB_VERTEX_ARRAY_BGRA])
|
2009-01-23 10:22:33 +01:00
|
|
|
{
|
|
|
|
const DWORD *src = ptr;
|
2015-08-26 12:46:47 +02:00
|
|
|
DWORD c = *src & 0xff00ff00u;
|
|
|
|
c |= (*src & 0xff0000u) >> 16;
|
|
|
|
c |= (*src & 0xffu) << 16;
|
2015-01-22 17:41:42 +01:00
|
|
|
GL_EXTCALL(glVertexAttrib4Nubv(index, (GLubyte *)&c));
|
2009-01-23 10:22:33 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* else fallthrough */
|
2009-03-27 10:25:56 +01:00
|
|
|
case WINED3DFMT_R8G8B8A8_UNORM:
|
2015-01-22 17:41:42 +01:00
|
|
|
GL_EXTCALL(glVertexAttrib4Nubv(index, ptr));
|
2007-12-17 18:18:19 +01:00
|
|
|
break;
|
|
|
|
|
2009-03-27 10:25:56 +01:00
|
|
|
case WINED3DFMT_R16G16_SINT:
|
2015-01-22 17:41:42 +01:00
|
|
|
GL_EXTCALL(glVertexAttrib2sv(index, ptr));
|
2007-12-17 18:18:19 +01:00
|
|
|
break;
|
2009-03-27 10:25:56 +01:00
|
|
|
case WINED3DFMT_R16G16B16A16_SINT:
|
2015-01-22 17:41:42 +01:00
|
|
|
GL_EXTCALL(glVertexAttrib4sv(index, ptr));
|
2007-12-17 18:18:19 +01:00
|
|
|
break;
|
|
|
|
|
2009-03-27 10:25:56 +01:00
|
|
|
case WINED3DFMT_R16G16_SNORM:
|
2007-12-17 18:18:19 +01:00
|
|
|
{
|
2008-11-25 11:57:39 +01:00
|
|
|
GLshort s[4] = {((const GLshort *)ptr)[0], ((const GLshort *)ptr)[1], 0, 1};
|
2015-01-22 17:41:42 +01:00
|
|
|
GL_EXTCALL(glVertexAttrib4Nsv(index, s));
|
2007-12-17 18:18:19 +01:00
|
|
|
break;
|
|
|
|
}
|
2009-03-27 10:25:56 +01:00
|
|
|
case WINED3DFMT_R16G16_UNORM:
|
2007-12-17 18:18:19 +01:00
|
|
|
{
|
2008-11-25 11:57:39 +01:00
|
|
|
GLushort s[4] = {((const GLushort *)ptr)[0], ((const GLushort *)ptr)[1], 0, 1};
|
2015-01-22 17:41:42 +01:00
|
|
|
GL_EXTCALL(glVertexAttrib4Nusv(index, s));
|
2007-12-17 18:18:19 +01:00
|
|
|
break;
|
|
|
|
}
|
2009-03-27 10:25:56 +01:00
|
|
|
case WINED3DFMT_R16G16B16A16_SNORM:
|
2015-01-22 17:41:42 +01:00
|
|
|
GL_EXTCALL(glVertexAttrib4Nsv(index, ptr));
|
2007-12-17 18:18:19 +01:00
|
|
|
break;
|
2009-03-27 10:25:56 +01:00
|
|
|
case WINED3DFMT_R16G16B16A16_UNORM:
|
2015-01-22 17:41:42 +01:00
|
|
|
GL_EXTCALL(glVertexAttrib4Nusv(index, ptr));
|
2007-12-17 18:18:19 +01:00
|
|
|
break;
|
|
|
|
|
2009-03-27 10:25:56 +01:00
|
|
|
case WINED3DFMT_R10G10B10A2_UINT:
|
2007-12-17 18:18:19 +01:00
|
|
|
FIXME("Unsure about WINED3DDECLTYPE_UDEC3\n");
|
|
|
|
/*glVertexAttrib3usvARB(instancedData[j], (GLushort *) ptr); Does not exist */
|
|
|
|
break;
|
2009-03-27 10:25:56 +01:00
|
|
|
case WINED3DFMT_R10G10B10A2_SNORM:
|
2007-12-17 18:18:19 +01:00
|
|
|
FIXME("Unsure about WINED3DDECLTYPE_DEC3N\n");
|
|
|
|
/*glVertexAttrib3NusvARB(instancedData[j], (GLushort *) ptr); Does not exist */
|
|
|
|
break;
|
|
|
|
|
2009-03-27 10:25:56 +01:00
|
|
|
case WINED3DFMT_R16G16_FLOAT:
|
2007-12-17 18:18:19 +01:00
|
|
|
/* Are those 16 bit floats. C doesn't have a 16 bit float type. I could read the single bits and calculate a 4
|
|
|
|
* byte float according to the IEEE standard
|
|
|
|
*/
|
2011-12-08 21:04:02 +01:00
|
|
|
if (gl_info->supported[NV_HALF_FLOAT] && gl_info->supported[NV_VERTEX_PROGRAM])
|
2009-10-29 10:37:11 +01:00
|
|
|
{
|
2009-04-06 19:07:51 +02:00
|
|
|
/* Not supported by GL_ARB_half_float_vertex */
|
2009-01-20 10:00:20 +01:00
|
|
|
GL_EXTCALL(glVertexAttrib2hvNV(index, ptr));
|
2009-10-29 10:37:11 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-25 11:57:39 +01:00
|
|
|
float x = float_16_to_32(((const unsigned short *)ptr) + 0);
|
|
|
|
float y = float_16_to_32(((const unsigned short *)ptr) + 1);
|
2015-01-22 17:41:42 +01:00
|
|
|
GL_EXTCALL(glVertexAttrib2f(index, x, y));
|
2007-12-17 18:18:19 +01:00
|
|
|
}
|
|
|
|
break;
|
2009-03-27 10:25:56 +01:00
|
|
|
case WINED3DFMT_R16G16B16A16_FLOAT:
|
2011-12-08 21:04:02 +01:00
|
|
|
if (gl_info->supported[NV_HALF_FLOAT] && gl_info->supported[NV_VERTEX_PROGRAM])
|
2009-10-29 10:37:11 +01:00
|
|
|
{
|
2009-04-06 19:07:51 +02:00
|
|
|
/* Not supported by GL_ARB_half_float_vertex */
|
2009-01-20 10:00:20 +01:00
|
|
|
GL_EXTCALL(glVertexAttrib4hvNV(index, ptr));
|
2009-10-29 10:37:11 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-25 11:57:39 +01:00
|
|
|
float x = float_16_to_32(((const unsigned short *)ptr) + 0);
|
|
|
|
float y = float_16_to_32(((const unsigned short *)ptr) + 1);
|
|
|
|
float z = float_16_to_32(((const unsigned short *)ptr) + 2);
|
|
|
|
float w = float_16_to_32(((const unsigned short *)ptr) + 3);
|
2015-01-22 17:41:42 +01:00
|
|
|
GL_EXTCALL(glVertexAttrib4f(index, x, y, z, w));
|
2007-12-17 18:18:19 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-03-27 10:25:56 +01:00
|
|
|
ERR("Unexpected attribute format: %s\n", debug_d3dformat(format));
|
2007-12-17 18:18:19 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2013-09-09 15:15:36 +02:00
|
|
|
static void drawStridedSlowVs(struct wined3d_context *context, const struct wined3d_state *state,
|
2010-09-30 11:44:30 +02:00
|
|
|
const struct wined3d_stream_info *si, UINT numberOfVertices, GLenum glPrimitiveType,
|
|
|
|
const void *idxData, UINT idxSize, UINT startIdx)
|
2008-11-28 15:30:12 +01:00
|
|
|
{
|
2013-09-09 15:15:36 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2010-09-30 11:44:30 +02:00
|
|
|
LONG SkipnStrides = startIdx + state->load_base_vertex_index;
|
2010-09-20 19:41:24 +02:00
|
|
|
const DWORD *pIdxBufL = NULL;
|
|
|
|
const WORD *pIdxBufS = NULL;
|
2009-03-05 12:30:42 +01:00
|
|
|
UINT vx_index;
|
2007-12-17 18:18:19 +01:00
|
|
|
int i;
|
2008-11-28 15:30:12 +01:00
|
|
|
const BYTE *ptr;
|
2007-12-17 18:18:19 +01:00
|
|
|
|
2010-05-21 09:35:24 +02:00
|
|
|
if (idxSize)
|
|
|
|
{
|
|
|
|
/* Immediate mode drawing can't make use of indices in a vbo - get the
|
|
|
|
* data from the index buffer. If the index buffer has no vbo (not
|
|
|
|
* supported or other reason), or with user pointer drawing idxData
|
|
|
|
* will be non-NULL. */
|
|
|
|
if (!idxData)
|
2013-09-09 15:15:36 +02:00
|
|
|
idxData = buffer_get_sysmem(state->index_buffer, context);
|
2007-12-17 18:18:19 +01:00
|
|
|
|
2009-01-20 10:00:20 +01:00
|
|
|
if (idxSize == 2) pIdxBufS = idxData;
|
|
|
|
else pIdxBufL = idxData;
|
2008-10-30 17:38:56 +01:00
|
|
|
} else if (idxData) {
|
|
|
|
ERR("non-NULL idxData with 0 idxSize, this should never happen\n");
|
|
|
|
return;
|
2007-12-17 18:18:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Start drawing in GL */
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glBegin(glPrimitiveType);
|
2007-12-17 18:18:19 +01:00
|
|
|
|
2010-09-14 13:38:39 +02:00
|
|
|
for (vx_index = 0; vx_index < numberOfVertices; ++vx_index)
|
|
|
|
{
|
|
|
|
if (idxData)
|
|
|
|
{
|
2007-12-17 18:18:19 +01:00
|
|
|
/* Indexed so work out the number of strides to skip */
|
2010-03-17 21:59:53 +01:00
|
|
|
if (idxSize == 2)
|
2010-09-30 11:44:30 +02:00
|
|
|
SkipnStrides = pIdxBufS[startIdx + vx_index] + state->load_base_vertex_index;
|
2010-03-17 21:59:53 +01:00
|
|
|
else
|
2010-09-30 11:44:30 +02:00
|
|
|
SkipnStrides = pIdxBufL[startIdx + vx_index] + state->load_base_vertex_index;
|
2007-12-17 18:18:19 +01:00
|
|
|
}
|
|
|
|
|
2009-08-24 09:27:54 +02:00
|
|
|
for (i = MAX_ATTRIBS - 1; i >= 0; i--)
|
|
|
|
{
|
2015-08-26 12:46:47 +02:00
|
|
|
if (!(si->use_map & (1u << i))) continue;
|
2007-12-17 18:18:19 +01:00
|
|
|
|
2011-07-15 01:14:50 +02:00
|
|
|
ptr = si->elements[i].data.addr + si->elements[i].stride * SkipnStrides;
|
2007-12-17 18:18:19 +01:00
|
|
|
|
2010-09-30 11:44:28 +02:00
|
|
|
send_attribute(gl_info, si->elements[i].format->id, i, ptr);
|
2007-12-17 18:18:19 +01:00
|
|
|
}
|
2007-12-19 16:28:14 +01:00
|
|
|
SkipnStrides++;
|
2007-12-17 18:18:19 +01:00
|
|
|
}
|
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glEnd();
|
2007-12-17 18:18:19 +01:00
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2013-09-09 15:15:36 +02:00
|
|
|
static void drawStridedInstanced(struct wined3d_context *context, const struct wined3d_state *state,
|
2010-10-01 12:25:46 +02:00
|
|
|
const struct wined3d_stream_info *si, UINT numberOfVertices, GLenum glPrimitiveType,
|
2012-12-02 18:53:19 +01:00
|
|
|
const void *idxData, UINT idxSize, UINT startIdx, UINT base_vertex_index, UINT instance_count)
|
2008-11-28 15:30:12 +01:00
|
|
|
{
|
2013-09-09 15:15:36 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2008-11-26 21:37:28 +01:00
|
|
|
int numInstancedAttribs = 0, j;
|
2009-03-27 10:25:55 +01:00
|
|
|
UINT instancedData[sizeof(si->elements) / sizeof(*si->elements) /* 16 */];
|
2011-06-11 16:18:45 +02:00
|
|
|
GLenum idxtype = idxSize == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
|
2012-12-02 18:53:19 +01:00
|
|
|
UINT i;
|
2007-02-14 17:56:29 +01:00
|
|
|
|
2010-09-14 13:38:39 +02:00
|
|
|
if (!idxSize)
|
|
|
|
{
|
2007-02-14 17:56:29 +01:00
|
|
|
/* This is a nasty thing. MSDN says no hardware supports that and apps have to use software vertex processing.
|
|
|
|
* We don't support this for now
|
|
|
|
*
|
|
|
|
* Shouldn't be too hard to support with opengl, in theory just call glDrawArrays instead of drawElements.
|
|
|
|
* But the StreamSourceFreq value has a different meaning in that situation.
|
|
|
|
*/
|
|
|
|
FIXME("Non-indexed instanced drawing is not supported\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-27 10:25:55 +01:00
|
|
|
for (i = 0; i < sizeof(si->elements) / sizeof(*si->elements); ++i)
|
|
|
|
{
|
2015-08-26 12:46:47 +02:00
|
|
|
if (!(si->use_map & (1u << i))) continue;
|
2009-08-27 10:04:52 +02:00
|
|
|
|
2010-10-01 12:25:46 +02:00
|
|
|
if (state->streams[si->elements[i].stream_idx].flags & WINED3DSTREAMSOURCE_INSTANCEDATA)
|
2009-03-27 10:25:55 +01:00
|
|
|
{
|
2007-02-14 17:56:29 +01:00
|
|
|
instancedData[numInstancedAttribs] = i;
|
|
|
|
numInstancedAttribs++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-02 18:53:19 +01:00
|
|
|
for (i = 0; i < instance_count; ++i)
|
|
|
|
{
|
2007-02-14 17:56:29 +01:00
|
|
|
/* Specify the instanced attributes using immediate mode calls */
|
|
|
|
for(j = 0; j < numInstancedAttribs; j++) {
|
2011-07-11 01:06:46 +02:00
|
|
|
const BYTE *ptr = si->elements[instancedData[j]].data.addr
|
2011-07-15 01:14:50 +02:00
|
|
|
+ si->elements[instancedData[j]].stride * i;
|
2011-07-11 01:06:46 +02:00
|
|
|
if (si->elements[instancedData[j]].data.buffer_object)
|
2009-03-27 10:25:55 +01:00
|
|
|
{
|
2010-10-01 12:25:46 +02:00
|
|
|
struct wined3d_buffer *vb = state->streams[si->elements[instancedData[j]].stream_idx].buffer;
|
2013-09-09 15:15:36 +02:00
|
|
|
ptr += (ULONG_PTR)buffer_get_sysmem(vb, context);
|
2007-02-14 17:56:29 +01:00
|
|
|
}
|
|
|
|
|
2010-09-30 11:44:28 +02:00
|
|
|
send_attribute(gl_info, si->elements[instancedData[j]].format->id, instancedData[j], ptr);
|
2007-02-14 17:56:29 +01:00
|
|
|
}
|
|
|
|
|
2011-06-11 16:18:45 +02:00
|
|
|
if (gl_info->supported[ARB_DRAW_ELEMENTS_BASE_VERTEX])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glDrawElementsBaseVertex(glPrimitiveType, numberOfVertices, idxtype,
|
|
|
|
(const char *)idxData+(idxSize * startIdx), base_vertex_index));
|
|
|
|
checkGLcall("glDrawElementsBaseVertex");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDrawElements(glPrimitiveType, numberOfVertices, idxtype,
|
|
|
|
(const char *)idxData + (idxSize * startIdx));
|
2011-06-11 16:18:45 +02:00
|
|
|
checkGLcall("glDrawElements");
|
|
|
|
}
|
2007-02-14 17:56:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-09 15:15:36 +02:00
|
|
|
static void remove_vbos(struct wined3d_context *context,
|
2010-10-01 12:25:47 +02:00
|
|
|
const struct wined3d_state *state, struct wined3d_stream_info *s)
|
2009-03-27 10:25:55 +01:00
|
|
|
{
|
2009-03-26 10:43:40 +01:00
|
|
|
unsigned int i;
|
2007-08-23 17:35:10 +02:00
|
|
|
|
2009-03-27 10:25:55 +01:00
|
|
|
for (i = 0; i < (sizeof(s->elements) / sizeof(*s->elements)); ++i)
|
2009-03-26 10:43:40 +01:00
|
|
|
{
|
2009-08-26 10:18:07 +02:00
|
|
|
struct wined3d_stream_info_element *e;
|
|
|
|
|
2015-08-26 12:46:47 +02:00
|
|
|
if (!(s->use_map & (1u << i))) continue;
|
2009-08-26 10:18:07 +02:00
|
|
|
|
|
|
|
e = &s->elements[i];
|
2011-07-11 01:06:46 +02:00
|
|
|
if (e->data.buffer_object)
|
2009-03-26 10:43:40 +01:00
|
|
|
{
|
2010-10-01 12:25:47 +02:00
|
|
|
struct wined3d_buffer *vb = state->streams[e->stream_idx].buffer;
|
2011-07-11 01:06:46 +02:00
|
|
|
e->data.buffer_object = 0;
|
2013-09-09 15:15:36 +02:00
|
|
|
e->data.addr = (BYTE *)((ULONG_PTR)e->data.addr + (ULONG_PTR)buffer_get_sysmem(vb, context));
|
2007-08-23 17:35:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-09 12:42:34 +01:00
|
|
|
/* Routine common to the draw primitive and draw indexed primitive routines */
|
2012-11-26 22:52:41 +01:00
|
|
|
void draw_primitive(struct wined3d_device *device, UINT start_idx, UINT index_count,
|
2013-04-10 13:39:46 +02:00
|
|
|
UINT start_instance, UINT instance_count, BOOL indexed)
|
2009-01-07 09:00:55 +01:00
|
|
|
{
|
2013-08-27 08:44:59 +02:00
|
|
|
const struct wined3d_state *state = &device->state;
|
2013-01-03 11:56:26 +01:00
|
|
|
const struct wined3d_stream_info *stream_info;
|
2012-08-20 08:12:09 +02:00
|
|
|
struct wined3d_event_query *ib_query = NULL;
|
2013-01-03 11:56:26 +01:00
|
|
|
struct wined3d_stream_info si_emulated;
|
2012-07-24 11:32:27 +02:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2009-08-03 08:06:51 +02:00
|
|
|
struct wined3d_context *context;
|
2013-01-03 11:56:26 +01:00
|
|
|
BOOL emulation = FALSE;
|
2013-04-10 13:39:46 +02:00
|
|
|
const void *idx_data = NULL;
|
2013-01-03 11:56:26 +01:00
|
|
|
UINT idx_size = 0;
|
2008-11-26 21:37:28 +01:00
|
|
|
unsigned int i;
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2009-03-05 12:30:42 +01:00
|
|
|
if (!index_count) return;
|
2008-03-23 13:53:45 +01:00
|
|
|
|
2015-10-15 22:41:12 +02:00
|
|
|
context = context_acquire(device, wined3d_rendertarget_view_get_surface(device->fb.render_targets[0]));
|
|
|
|
if (!context->valid)
|
|
|
|
{
|
|
|
|
context_release(context);
|
|
|
|
WARN("Invalid context, skipping draw.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gl_info = context->gl_info;
|
|
|
|
|
2015-10-28 15:29:17 +01:00
|
|
|
for (i = 0; i < device->adapter->gl_info.limits.buffers; ++i)
|
2009-06-19 11:04:31 +02:00
|
|
|
{
|
2015-10-28 15:29:17 +01:00
|
|
|
struct wined3d_surface *target = wined3d_rendertarget_view_get_surface(device->fb.render_targets[i]);
|
|
|
|
if (target && target->resource.format->id != WINED3DFMT_NULL)
|
2009-06-19 11:04:31 +02:00
|
|
|
{
|
2015-10-28 15:29:17 +01:00
|
|
|
if (state->render_states[WINED3D_RS_COLORWRITEENABLE])
|
2009-06-19 11:04:31 +02:00
|
|
|
{
|
2015-10-15 22:41:12 +02:00
|
|
|
surface_load_location(target, context, target->container->resource.draw_binding);
|
2014-08-20 13:20:01 +02:00
|
|
|
surface_invalidate_location(target, ~target->container->resource.draw_binding);
|
2009-06-19 11:04:31 +02:00
|
|
|
}
|
2015-10-28 15:29:17 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
wined3d_surface_prepare(target, context, target->container->resource.draw_binding);
|
|
|
|
}
|
2006-06-04 16:42:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-18 22:30:15 +02:00
|
|
|
if (device->fb.depth_stencil)
|
2010-04-19 20:47:01 +02:00
|
|
|
{
|
2009-10-28 11:00:11 +01:00
|
|
|
/* Note that this depends on the context_acquire() call above to set
|
2010-11-29 23:08:38 +01:00
|
|
|
* context->render_offscreen properly. We don't currently take the
|
2009-06-17 10:19:52 +02:00
|
|
|
* Z-compare function into account, but we could skip loading the
|
|
|
|
* depthstencil for D3DCMP_NEVER and D3DCMP_ALWAYS as well. Also note
|
|
|
|
* that we never copy the stencil data.*/
|
2014-08-22 12:32:01 +02:00
|
|
|
DWORD location = context->render_offscreen ? device->fb.depth_stencil->resource->draw_binding
|
2014-08-20 13:20:01 +02:00
|
|
|
: WINED3D_LOCATION_DRAWABLE;
|
2015-10-28 15:29:17 +01:00
|
|
|
struct wined3d_surface *ds = wined3d_rendertarget_view_get_surface(device->fb.depth_stencil);
|
|
|
|
|
2011-12-19 21:00:09 +01:00
|
|
|
if (state->render_states[WINED3D_RS_ZWRITEENABLE] || state->render_states[WINED3D_RS_ZENABLE])
|
2010-04-20 22:38:41 +02:00
|
|
|
{
|
2010-04-29 00:08:59 +02:00
|
|
|
RECT current_rect, draw_rect, r;
|
|
|
|
|
2012-01-09 15:52:44 +01:00
|
|
|
if (!context->render_offscreen && ds != device->onscreen_depth_stencil)
|
2010-11-29 23:08:38 +01:00
|
|
|
device_switch_onscreen_ds(device, context, ds);
|
2010-04-29 00:08:59 +02:00
|
|
|
|
2014-01-17 13:27:15 +01:00
|
|
|
if (ds->locations & location)
|
2010-11-29 23:08:38 +01:00
|
|
|
SetRect(¤t_rect, 0, 0, ds->ds_current_size.cx, ds->ds_current_size.cy);
|
2010-04-29 00:08:59 +02:00
|
|
|
else
|
|
|
|
SetRectEmpty(¤t_rect);
|
|
|
|
|
2011-07-05 22:30:57 +02:00
|
|
|
wined3d_get_draw_rect(state, &draw_rect);
|
2010-04-29 00:08:59 +02:00
|
|
|
|
|
|
|
IntersectRect(&r, &draw_rect, ¤t_rect);
|
|
|
|
if (!EqualRect(&r, &draw_rect))
|
2010-11-29 23:08:38 +01:00
|
|
|
surface_load_ds_location(ds, context, location);
|
2015-10-28 15:29:17 +01:00
|
|
|
else
|
|
|
|
wined3d_surface_prepare(ds, context, location);
|
2010-04-20 22:38:41 +02:00
|
|
|
}
|
2015-10-28 15:29:17 +01:00
|
|
|
else
|
|
|
|
wined3d_surface_prepare(ds, context, location);
|
2008-08-21 18:23:32 +02:00
|
|
|
}
|
|
|
|
|
2011-07-31 17:33:40 +02:00
|
|
|
if (!context_apply_draw_state(context, device))
|
|
|
|
{
|
|
|
|
context_release(context);
|
|
|
|
WARN("Unable to apply draw state, skipping draw.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-12 17:05:19 +01:00
|
|
|
if (device->fb.depth_stencil && state->render_states[WINED3D_RS_ZWRITEENABLE])
|
|
|
|
{
|
2014-08-22 12:32:01 +02:00
|
|
|
struct wined3d_surface *ds = wined3d_rendertarget_view_get_surface(device->fb.depth_stencil);
|
2014-08-20 13:20:01 +02:00
|
|
|
DWORD location = context->render_offscreen ? ds->container->resource.draw_binding : WINED3D_LOCATION_DRAWABLE;
|
2012-01-12 17:05:19 +01:00
|
|
|
|
|
|
|
surface_modify_ds_location(ds, location, ds->ds_current_size.cx, ds->ds_current_size.cy);
|
|
|
|
}
|
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
if ((!gl_info->supported[WINED3D_GL_VERSION_2_0]
|
|
|
|
|| !gl_info->supported[NV_POINT_SPRITE])
|
2010-07-16 18:39:06 +02:00
|
|
|
&& context->render_offscreen
|
2011-12-19 21:00:09 +01:00
|
|
|
&& state->render_states[WINED3D_RS_POINTSPRITEENABLE]
|
2010-09-28 12:00:23 +02:00
|
|
|
&& state->gl_primitive_type == GL_POINTS)
|
2010-06-11 16:05:23 +02:00
|
|
|
{
|
|
|
|
FIXME("Point sprite coordinate origin switching not supported.\n");
|
|
|
|
}
|
|
|
|
|
2013-09-12 12:23:29 +02:00
|
|
|
stream_info = &context->stream_info;
|
2013-09-16 12:43:20 +02:00
|
|
|
if (context->instance_count)
|
|
|
|
instance_count = context->instance_count;
|
2012-12-02 18:53:20 +01:00
|
|
|
|
2013-01-03 11:56:26 +01:00
|
|
|
if (indexed)
|
|
|
|
{
|
2013-01-24 00:39:13 +01:00
|
|
|
struct wined3d_buffer *index_buffer = state->index_buffer;
|
|
|
|
if (!index_buffer->buffer_object || !stream_info->all_vbo)
|
2014-01-15 22:02:15 +01:00
|
|
|
idx_data = index_buffer->resource.heap_memory;
|
2013-01-24 00:39:13 +01:00
|
|
|
else
|
2012-05-01 20:25:28 +02:00
|
|
|
{
|
2013-01-24 00:39:13 +01:00
|
|
|
ib_query = index_buffer->query;
|
|
|
|
idx_data = NULL;
|
2013-01-03 11:56:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (state->index_format == WINED3DFMT_R16_UINT)
|
|
|
|
idx_size = 2;
|
|
|
|
else
|
|
|
|
idx_size = 4;
|
|
|
|
}
|
2012-05-01 20:25:28 +02:00
|
|
|
|
2013-01-03 11:56:26 +01:00
|
|
|
if (!use_vs(state))
|
|
|
|
{
|
|
|
|
if (!stream_info->position_transformed && context->num_untracked_materials
|
|
|
|
&& state->render_states[WINED3D_RS_LIGHTING])
|
|
|
|
{
|
|
|
|
static BOOL warned;
|
|
|
|
|
|
|
|
if (!warned++)
|
|
|
|
FIXME("Using software emulation because not all material properties could be tracked.\n");
|
2012-05-01 20:25:28 +02:00
|
|
|
else
|
2013-04-17 08:47:59 +02:00
|
|
|
WARN_(d3d_perf)("Using software emulation because not all material properties could be tracked.\n");
|
2013-01-03 11:56:26 +01:00
|
|
|
emulation = TRUE;
|
2012-05-01 20:25:28 +02:00
|
|
|
}
|
2013-01-03 11:56:26 +01:00
|
|
|
else if (context->fog_coord && state->render_states[WINED3D_RS_FOGENABLE])
|
2008-12-30 14:56:49 +01:00
|
|
|
{
|
2013-01-03 11:56:26 +01:00
|
|
|
static BOOL warned;
|
2007-08-14 02:31:10 +02:00
|
|
|
|
2013-01-03 11:56:26 +01:00
|
|
|
/* Either write a pipeline replacement shader or convert the
|
|
|
|
* specular alpha from unsigned byte to a float in the vertex
|
|
|
|
* buffer. */
|
|
|
|
if (!warned++)
|
|
|
|
FIXME("Using software emulation because manual fog coordinates are provided.\n");
|
|
|
|
else
|
2013-04-17 08:47:59 +02:00
|
|
|
WARN_(d3d_perf)("Using software emulation because manual fog coordinates are provided.\n");
|
2013-01-03 11:56:26 +01:00
|
|
|
emulation = TRUE;
|
2007-06-20 14:36:32 +02:00
|
|
|
}
|
|
|
|
|
2013-01-03 11:56:26 +01:00
|
|
|
if (emulation)
|
2010-09-28 12:00:23 +02:00
|
|
|
{
|
2013-09-12 12:23:29 +02:00
|
|
|
si_emulated = context->stream_info;
|
2013-09-09 15:15:36 +02:00
|
|
|
remove_vbos(context, state, &si_emulated);
|
2013-01-03 11:56:26 +01:00
|
|
|
stream_info = &si_emulated;
|
2010-10-01 12:25:46 +02:00
|
|
|
}
|
2013-01-03 11:56:26 +01:00
|
|
|
}
|
|
|
|
|
2013-09-12 12:23:29 +02:00
|
|
|
if (context->use_immediate_mode_draw || emulation)
|
2013-01-03 11:56:26 +01:00
|
|
|
{
|
|
|
|
/* Immediate mode drawing. */
|
|
|
|
if (use_vs(state))
|
2010-10-01 12:25:46 +02:00
|
|
|
{
|
2013-01-03 11:56:26 +01:00
|
|
|
static BOOL warned;
|
|
|
|
|
|
|
|
if (!warned++)
|
|
|
|
FIXME("Using immediate mode with vertex shaders for half float emulation.\n");
|
|
|
|
else
|
2013-04-17 08:47:59 +02:00
|
|
|
WARN_(d3d_perf)("Using immediate mode with vertex shaders for half float emulation.\n");
|
2013-01-03 11:56:26 +01:00
|
|
|
|
2013-09-09 15:15:36 +02:00
|
|
|
drawStridedSlowVs(context, state, stream_info, index_count,
|
2013-01-03 11:56:26 +01:00
|
|
|
state->gl_primitive_type, idx_data, idx_size, start_idx);
|
2010-10-01 12:25:46 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-11 23:13:42 +02:00
|
|
|
if (context->d3d_info->ffp_generic_attributes)
|
|
|
|
drawStridedSlowVs(context, state, stream_info, index_count,
|
2013-01-03 11:56:26 +01:00
|
|
|
state->gl_primitive_type, idx_data, idx_size, start_idx);
|
2015-06-11 23:13:42 +02:00
|
|
|
else
|
|
|
|
drawStridedSlow(device, context, stream_info, index_count,
|
|
|
|
state->gl_primitive_type, idx_data, idx_size, start_idx);
|
2007-02-14 17:56:29 +01:00
|
|
|
}
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
2013-01-03 11:56:26 +01:00
|
|
|
else if (!gl_info->supported[ARB_INSTANCED_ARRAYS] && instance_count)
|
|
|
|
{
|
|
|
|
/* Instancing emulation by mixing immediate mode and arrays. */
|
2013-09-09 15:15:36 +02:00
|
|
|
drawStridedInstanced(context, state, stream_info, index_count, state->gl_primitive_type,
|
2013-01-03 11:56:26 +01:00
|
|
|
idx_data, idx_size, start_idx, state->base_vertex_index, instance_count);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
drawStridedFast(gl_info, state->gl_primitive_type, index_count, idx_size, idx_data,
|
|
|
|
start_idx, state->base_vertex_index, start_instance, instance_count);
|
|
|
|
}
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2012-08-20 08:12:09 +02:00
|
|
|
if (ib_query)
|
|
|
|
wined3d_event_query_issue(ib_query, device);
|
2013-09-12 12:23:29 +02:00
|
|
|
for (i = 0; i < context->num_buffer_queries; ++i)
|
2010-03-21 13:26:36 +01:00
|
|
|
{
|
2013-09-12 12:23:29 +02:00
|
|
|
wined3d_event_query_issue(context->buffer_queries[i], device);
|
2010-03-21 13:26:36 +01:00
|
|
|
}
|
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
if (wined3d_settings.strict_draw_ordering)
|
|
|
|
gl_info->gl_ops.gl.p_glFlush(); /* Flush to ensure ordering across contexts. */
|
2010-01-27 20:19:40 +01:00
|
|
|
|
2009-10-28 11:00:11 +01:00
|
|
|
context_release(context);
|
|
|
|
|
2004-12-09 12:42:34 +01:00
|
|
|
TRACE("Done all gl drawing\n");
|
|
|
|
}
|