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);
|
2016-06-21 10:32:43 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(d3d);
|
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. */
|
2016-04-06 19:12:06 +02:00
|
|
|
static void draw_primitive_arrays(struct wined3d_context *context, const struct wined3d_state *state,
|
2016-06-21 10:32:44 +02:00
|
|
|
const void *idx_data, unsigned int idx_size, int base_vertex_idx, unsigned int start_idx,
|
|
|
|
unsigned int count, unsigned int start_instance, unsigned int instance_count)
|
2009-01-07 09:00:55 +01:00
|
|
|
{
|
2016-04-06 19:12:06 +02:00
|
|
|
const struct wined3d_ffp_attrib_ops *ops = &context->d3d_info->ffp_attrib_ops;
|
|
|
|
GLenum idx_type = idx_size == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
|
|
|
|
const struct wined3d_stream_info *si = &context->stream_info;
|
|
|
|
unsigned int instanced_elements[ARRAY_SIZE(si->elements)];
|
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
|
|
|
unsigned int instanced_element_count = 0;
|
|
|
|
unsigned int i, j;
|
|
|
|
|
|
|
|
if (!instance_count)
|
2009-01-08 10:19:16 +01:00
|
|
|
{
|
2016-04-06 19:12:06 +02:00
|
|
|
if (!idx_size)
|
2012-11-26 22:52:41 +01:00
|
|
|
{
|
2016-04-06 19:12:06 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDrawArrays(state->gl_primitive_type, start_idx, count);
|
|
|
|
checkGLcall("glDrawArrays");
|
|
|
|
return;
|
2012-11-26 22:52:41 +01:00
|
|
|
}
|
2016-04-06 19:12:06 +02:00
|
|
|
|
|
|
|
if (gl_info->supported[ARB_DRAW_ELEMENTS_BASE_VERTEX])
|
2011-06-11 16:18:45 +02:00
|
|
|
{
|
2016-04-06 19:12:06 +02:00
|
|
|
GL_EXTCALL(glDrawElementsBaseVertex(state->gl_primitive_type, count, idx_type,
|
2016-06-21 10:32:44 +02:00
|
|
|
(const char *)idx_data + (idx_size * start_idx), base_vertex_idx));
|
2011-06-11 16:18:45 +02:00
|
|
|
checkGLcall("glDrawElementsBaseVertex");
|
2016-04-06 19:12:06 +02:00
|
|
|
return;
|
2011-06-11 16:18:45 +02:00
|
|
|
}
|
2016-04-06 19:12:06 +02:00
|
|
|
|
|
|
|
gl_info->gl_ops.gl.p_glDrawElements(state->gl_primitive_type, count,
|
|
|
|
idx_type, (const char *)idx_data + (idx_size * start_idx));
|
|
|
|
checkGLcall("glDrawElements");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (start_instance)
|
|
|
|
FIXME("Start instance (%u) not supported.\n", start_instance);
|
|
|
|
|
|
|
|
if (gl_info->supported[ARB_INSTANCED_ARRAYS])
|
|
|
|
{
|
|
|
|
if (!idx_size)
|
2011-06-11 16:18:45 +02:00
|
|
|
{
|
2016-04-06 19:12:06 +02:00
|
|
|
GL_EXTCALL(glDrawArraysInstanced(state->gl_primitive_type, start_idx, count, instance_count));
|
|
|
|
checkGLcall("glDrawArraysInstanced");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gl_info->supported[ARB_DRAW_ELEMENTS_BASE_VERTEX])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glDrawElementsInstancedBaseVertex(state->gl_primitive_type, count, idx_type,
|
2016-06-21 10:32:44 +02:00
|
|
|
(const char *)idx_data + (idx_size * start_idx), instance_count, base_vertex_idx));
|
2016-04-06 19:12:06 +02:00
|
|
|
checkGLcall("glDrawElementsInstancedBaseVertex");
|
|
|
|
return;
|
2011-06-11 16:18:45 +02:00
|
|
|
}
|
2016-04-06 19:12:06 +02:00
|
|
|
|
|
|
|
GL_EXTCALL(glDrawElementsInstanced(state->gl_primitive_type, count, idx_type,
|
|
|
|
(const char *)idx_data + (idx_size * start_idx), instance_count));
|
|
|
|
checkGLcall("glDrawElementsInstanced");
|
|
|
|
return;
|
2009-01-08 10:19:16 +01:00
|
|
|
}
|
2016-04-06 19:12:06 +02:00
|
|
|
|
|
|
|
/* Instancing emulation by mixing immediate mode and arrays. */
|
|
|
|
|
|
|
|
/* This is a nasty thing. MSDN says no hardware supports this and
|
|
|
|
* applications 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 stream fequency value
|
|
|
|
* has a different meaning in that situation. */
|
|
|
|
if (!idx_size)
|
2009-01-08 10:19:16 +01:00
|
|
|
{
|
2016-04-06 19:12:06 +02:00
|
|
|
FIXME("Non-indexed instanced drawing is not supported\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(si->elements); ++i)
|
|
|
|
{
|
|
|
|
if (!(si->use_map & (1u << i)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (state->streams[si->elements[i].stream_idx].flags & WINED3DSTREAMSOURCE_INSTANCEDATA)
|
|
|
|
instanced_elements[instanced_element_count++] = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < instance_count; ++i)
|
|
|
|
{
|
|
|
|
/* Specify the instanced attributes using immediate mode calls. */
|
|
|
|
for (j = 0; j < instanced_element_count; ++j)
|
2015-03-24 09:38:26 +01:00
|
|
|
{
|
2016-04-06 19:12:06 +02:00
|
|
|
const struct wined3d_stream_info_element *element;
|
|
|
|
unsigned int element_idx;
|
|
|
|
const BYTE *ptr;
|
|
|
|
|
|
|
|
element_idx = instanced_elements[j];
|
|
|
|
element = &si->elements[element_idx];
|
|
|
|
ptr = element->data.addr + element->stride * i;
|
|
|
|
if (element->data.buffer_object)
|
2016-10-16 21:46:47 +02:00
|
|
|
ptr += (ULONG_PTR)wined3d_buffer_load_sysmem(state->streams[element->stream_idx].buffer, context);
|
2016-04-06 19:12:06 +02:00
|
|
|
ops->generic[element->format->emit_idx](element_idx, ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gl_info->supported[ARB_DRAW_ELEMENTS_BASE_VERTEX])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glDrawElementsBaseVertex(state->gl_primitive_type, count, idx_type,
|
2016-06-21 10:32:44 +02:00
|
|
|
(const char *)idx_data + (idx_size * start_idx), base_vertex_idx));
|
2016-04-06 19:12:06 +02:00
|
|
|
checkGLcall("glDrawElementsBaseVertex");
|
2015-03-24 09:38:26 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-06 19:12:06 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDrawElements(state->gl_primitive_type, count, idx_type,
|
|
|
|
(const char *)idx_data + (idx_size * start_idx));
|
|
|
|
checkGLcall("glDrawElements");
|
2015-03-24 09:38:26 +01:00
|
|
|
}
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-06 19:12:05 +02:00
|
|
|
static unsigned int get_stride_idx(const void *idx_data, unsigned int idx_size,
|
|
|
|
unsigned int base_vertex_idx, unsigned int start_idx, unsigned int vertex_idx)
|
|
|
|
{
|
|
|
|
if (!idx_data)
|
|
|
|
return start_idx + vertex_idx;
|
|
|
|
if (idx_size == 2)
|
|
|
|
return ((const WORD *)idx_data)[start_idx + vertex_idx] + base_vertex_idx;
|
|
|
|
return ((const DWORD *)idx_data)[start_idx + vertex_idx] + base_vertex_idx;
|
|
|
|
}
|
2007-01-02 21:07:39 +01:00
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2016-04-06 19:12:05 +02:00
|
|
|
static void draw_primitive_immediate_mode(struct wined3d_context *context, const struct wined3d_state *state,
|
2016-06-21 10:32:44 +02:00
|
|
|
const struct wined3d_stream_info *si, const void *idx_data, unsigned int idx_size,
|
|
|
|
int base_vertex_idx, unsigned int start_idx, unsigned int vertex_count, unsigned int instance_count)
|
2008-11-28 15:30:12 +01:00
|
|
|
{
|
2016-04-06 19:12:05 +02:00
|
|
|
const BYTE *position = NULL, *normal = NULL, *diffuse = NULL, *specular = NULL;
|
2013-04-25 15:20:30 +02:00
|
|
|
const struct wined3d_d3d_info *d3d_info = context->d3d_info;
|
2016-04-06 19:12:05 +02:00
|
|
|
unsigned int coord_idx, stride_idx, texture_idx, vertex_idx;
|
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2009-03-27 10:25:55 +01:00
|
|
|
const struct wined3d_stream_info_element *element;
|
2016-04-06 19:12:05 +02:00
|
|
|
const BYTE *tex_coords[WINED3DDP_MAXTEXCOORD];
|
|
|
|
unsigned int texture_unit, texture_stages;
|
|
|
|
const struct wined3d_ffp_attrib_ops *ops;
|
|
|
|
unsigned int untracked_material_count;
|
|
|
|
unsigned int tex_mask = 0;
|
|
|
|
BOOL specular_fog = FALSE;
|
|
|
|
BOOL ps = use_ps(state);
|
|
|
|
const void *ptr;
|
|
|
|
|
|
|
|
static unsigned int once;
|
|
|
|
|
|
|
|
if (!once++)
|
|
|
|
FIXME_(d3d_perf)("Drawing using immediate mode.\n");
|
|
|
|
else
|
|
|
|
WARN_(d3d_perf)("Drawing using immediate mode.\n");
|
2007-01-17 00:06:34 +01:00
|
|
|
|
2016-04-06 19:12:05 +02:00
|
|
|
if (!idx_size && idx_data)
|
|
|
|
ERR("Non-NULL idx_data with 0 idx_size, this should never happen.\n");
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2016-04-06 19:12:05 +02:00
|
|
|
if (instance_count)
|
|
|
|
FIXME("Instancing not implemented.\n");
|
|
|
|
|
2016-10-24 11:57:27 +02:00
|
|
|
/* Immediate mode drawing can't make use of indices in a VBO - get the
|
|
|
|
* data from the index buffer. */
|
|
|
|
if (idx_size)
|
|
|
|
idx_data = wined3d_buffer_load_sysmem(state->index_buffer, context) + state->index_offset;
|
2016-04-06 19:12:05 +02:00
|
|
|
|
|
|
|
ops = &d3d_info->ffp_attrib_ops;
|
|
|
|
|
|
|
|
gl_info->gl_ops.gl.p_glBegin(state->gl_primitive_type);
|
|
|
|
|
|
|
|
if (use_vs(state) || d3d_info->ffp_generic_attributes)
|
2010-05-21 09:35:24 +02:00
|
|
|
{
|
2016-04-06 19:12:05 +02:00
|
|
|
for (vertex_idx = 0; vertex_idx < vertex_count; ++vertex_idx)
|
|
|
|
{
|
|
|
|
unsigned int use_map = si->use_map;
|
|
|
|
unsigned int element_idx;
|
|
|
|
|
2016-06-21 10:32:44 +02:00
|
|
|
stride_idx = get_stride_idx(idx_data, idx_size, base_vertex_idx, start_idx, vertex_idx);
|
2016-05-17 14:01:54 +02:00
|
|
|
for (element_idx = MAX_ATTRIBS - 1; use_map; use_map &= ~(1u << element_idx), --element_idx)
|
2016-04-06 19:12:05 +02:00
|
|
|
{
|
2016-05-17 14:01:54 +02:00
|
|
|
if (!(use_map & 1u << element_idx))
|
2016-04-06 19:12:05 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
ptr = si->elements[element_idx].data.addr + si->elements[element_idx].stride * stride_idx;
|
|
|
|
ops->generic[si->elements[element_idx].format->emit_idx](element_idx, ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gl_info->gl_ops.gl.p_glEnd();
|
2008-10-07 16:01:01 +02:00
|
|
|
return;
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
|
2015-08-26 12:46:47 +02:00
|
|
|
if (si->use_map & (1u << WINED3D_FFP_POSITION))
|
2016-04-06 19:12:05 +02:00
|
|
|
position = si->elements[WINED3D_FFP_POSITION].data.addr;
|
2008-12-04 17:41:30 +01:00
|
|
|
|
2015-08-26 12:46:47 +02:00
|
|
|
if (si->use_map & (1u << WINED3D_FFP_NORMAL))
|
2016-04-06 19:12:05 +02:00
|
|
|
normal = si->elements[WINED3D_FFP_NORMAL].data.addr;
|
2009-08-25 08:17:10 +02:00
|
|
|
else
|
2016-04-06 19:12:05 +02:00
|
|
|
gl_info->gl_ops.gl.p_glNormal3f(0.0f, 0.0f, 0.0f);
|
2008-12-04 17:41:30 +01:00
|
|
|
|
2016-04-06 19:12:05 +02:00
|
|
|
untracked_material_count = 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
|
|
|
|
2016-04-06 19:12:05 +02:00
|
|
|
if (untracked_material_count && 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
|
|
|
|
2016-04-06 19:12:05 +02: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
|
|
|
{
|
2016-04-06 19:12:05 +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
|
|
|
|
{
|
2016-04-06 19:12:05 +02:00
|
|
|
static unsigned int once;
|
2008-12-04 17:41:30 +01:00
|
|
|
|
2016-04-06 19:12:05 +02:00
|
|
|
if (!once++)
|
|
|
|
FIXME("Implement fog for transformed vertices in software.\n");
|
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
|
|
|
{
|
2016-04-06 19:12:05 +02:00
|
|
|
GL_EXTCALL(glSecondaryColor3fEXT)(0.0f, 0.0f, 0.0f);
|
2007-12-19 17:10:02 +01:00
|
|
|
}
|
|
|
|
|
2016-04-06 19:12:05 +02:00
|
|
|
texture_stages = d3d_info->limits.ffp_blend_stages;
|
|
|
|
for (texture_idx = 0; texture_idx < texture_stages; ++texture_idx)
|
2008-12-04 17:41:30 +01:00
|
|
|
{
|
2016-04-06 19:12:05 +02:00
|
|
|
if (!gl_info->supported[ARB_MULTITEXTURE] && texture_idx > 0)
|
2008-12-04 17:41:30 +01:00
|
|
|
{
|
2016-04-06 19:12:05 +02:00
|
|
|
FIXME("Program using multiple concurrent textures which this OpenGL implementation doesn't support.\n");
|
2008-12-04 17:41:30 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-04-06 19:12:05 +02:00
|
|
|
if (!ps && !state->textures[texture_idx])
|
|
|
|
continue;
|
2008-12-04 17:41:30 +01:00
|
|
|
|
2016-04-06 19:12:05 +02:00
|
|
|
texture_unit = context->tex_unit_map[texture_idx];
|
|
|
|
if (texture_unit == WINED3D_UNMAPPED_STAGE)
|
2008-12-04 17:41:30 +01:00
|
|
|
continue;
|
2016-04-06 19:12:05 +02:00
|
|
|
|
|
|
|
coord_idx = state->texture_states[texture_idx][WINED3D_TSS_TEXCOORD_INDEX];
|
|
|
|
if (coord_idx > 7)
|
2008-12-04 17:41:30 +01:00
|
|
|
{
|
2016-04-06 19:12:05 +02:00
|
|
|
TRACE("Skipping generated coordinates (%#x) for texture %u.\n", coord_idx, texture_idx);
|
2008-12-04 17:41:30 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-04-06 19:12:05 +02:00
|
|
|
if (si->use_map & (1u << (WINED3D_FFP_TEXCOORD0 + coord_idx)))
|
2008-12-04 17:41:30 +01:00
|
|
|
{
|
2016-04-06 19:12:05 +02:00
|
|
|
tex_coords[coord_idx] = si->elements[WINED3D_FFP_TEXCOORD0 + coord_idx].data.addr;
|
|
|
|
tex_mask |= (1u << texture_idx);
|
2008-12-04 17:41:30 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-06 19:12:05 +02:00
|
|
|
TRACE("Setting default coordinates for texture %u.\n", texture_idx);
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[ARB_MULTITEXTURE])
|
2016-04-06 19:12:05 +02:00
|
|
|
GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB + texture_unit, 0.0f, 0.0f, 0.0f, 1.0f));
|
2008-12-04 17:41:30 +01:00
|
|
|
else
|
2016-04-06 19:12:05 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexCoord4f(0.0f, 0.0f, 0.0f, 1.0f);
|
2007-01-16 23:43:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-06 19:12:05 +02: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. */
|
|
|
|
for (vertex_idx = 0; vertex_idx < vertex_count; ++vertex_idx)
|
|
|
|
{
|
|
|
|
unsigned int tmp_tex_mask;
|
2006-06-21 15:01:38 +02:00
|
|
|
|
2016-06-21 10:32:44 +02:00
|
|
|
stride_idx = get_stride_idx(idx_data, idx_size, base_vertex_idx, start_idx, vertex_idx);
|
2007-01-16 23:43:28 +01:00
|
|
|
|
2016-04-06 19:12:05 +02:00
|
|
|
if (normal)
|
2008-12-04 17:41:30 +01:00
|
|
|
{
|
2016-04-06 19:12:05 +02:00
|
|
|
ptr = normal + stride_idx * si->elements[WINED3D_FFP_NORMAL].stride;
|
|
|
|
ops->normal[si->elements[WINED3D_FFP_NORMAL].format->emit_idx](ptr);
|
2008-12-04 17:41:30 +01:00
|
|
|
}
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2013-08-19 10:50:51 +02:00
|
|
|
if (diffuse)
|
|
|
|
{
|
2016-04-06 19:12:05 +02:00
|
|
|
ptr = diffuse + stride_idx * si->elements[WINED3D_FFP_DIFFUSE].stride;
|
|
|
|
ops->diffuse[si->elements[WINED3D_FFP_DIFFUSE].format->emit_idx](ptr);
|
2007-06-20 14:36:32 +02:00
|
|
|
|
2016-04-06 19:12:05 +02:00
|
|
|
if (untracked_material_count)
|
2009-06-22 10:15:58 +02:00
|
|
|
{
|
2016-03-08 15:51:13 +01:00
|
|
|
struct wined3d_color color;
|
2016-04-06 19:12:05 +02:00
|
|
|
unsigned int i;
|
2007-12-19 17:10:02 +01:00
|
|
|
|
2016-04-06 19:12:05 +02:00
|
|
|
wined3d_color_from_d3dcolor(&color, *(const DWORD *)ptr);
|
|
|
|
for (i = 0; i < untracked_material_count; ++i)
|
2009-06-22 10:15:58 +02:00
|
|
|
{
|
2016-03-08 15:51:13 +01:00
|
|
|
gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, context->untracked_materials[i], &color.r);
|
2007-06-20 14:36:32 +02:00
|
|
|
}
|
|
|
|
}
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
|
2013-08-19 10:50:51 +02:00
|
|
|
if (specular)
|
|
|
|
{
|
2016-04-06 19:12:05 +02:00
|
|
|
ptr = specular + stride_idx * si->elements[WINED3D_FFP_SPECULAR].stride;
|
|
|
|
ops->specular[si->elements[WINED3D_FFP_SPECULAR].format->emit_idx](ptr);
|
2008-12-04 17:41:30 +01:00
|
|
|
|
|
|
|
if (specular_fog)
|
2016-04-06 19:12:05 +02:00
|
|
|
GL_EXTCALL(glFogCoordfEXT((float)(*(const DWORD *)ptr >> 24)));
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
|
|
|
|
2016-04-06 19:12:05 +02:00
|
|
|
tmp_tex_mask = tex_mask;
|
|
|
|
for (texture_idx = 0; tmp_tex_mask; tmp_tex_mask >>= 1, ++texture_idx)
|
2010-09-14 13:38:39 +02:00
|
|
|
{
|
2016-04-06 19:12:05 +02:00
|
|
|
if (!(tmp_tex_mask & 1))
|
|
|
|
continue;
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2016-04-06 19:12:05 +02:00
|
|
|
coord_idx = state->texture_states[texture_idx][WINED3D_TSS_TEXCOORD_INDEX];
|
|
|
|
ptr = tex_coords[coord_idx] + (stride_idx * si->elements[WINED3D_FFP_TEXCOORD0 + coord_idx].stride);
|
|
|
|
ops->texcoord[si->elements[WINED3D_FFP_TEXCOORD0 + coord_idx].format->emit_idx](
|
|
|
|
GL_TEXTURE0_ARB + context->tex_unit_map[texture_idx], ptr);
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
2016-05-17 14:01:54 +02:00
|
|
|
|
|
|
|
if (position)
|
|
|
|
{
|
|
|
|
ptr = position + stride_idx * si->elements[WINED3D_FFP_POSITION].stride;
|
|
|
|
ops->position[si->elements[WINED3D_FFP_POSITION].format->emit_idx](ptr);
|
|
|
|
}
|
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");
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2016-10-24 11:57:26 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(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;
|
|
|
|
|
2016-10-24 11:57:26 +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;
|
2016-10-24 11:57:26 +02:00
|
|
|
e->data.addr += (ULONG_PTR)wined3d_buffer_load_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 */
|
2016-04-13 19:09:56 +02:00
|
|
|
void draw_primitive(struct wined3d_device *device, const struct wined3d_state *state,
|
2016-06-21 10:32:44 +02:00
|
|
|
int base_vertex_idx, unsigned int start_idx, unsigned int index_count,
|
|
|
|
unsigned int start_instance, unsigned int instance_count, BOOL indexed)
|
2009-01-07 09:00:55 +01:00
|
|
|
{
|
2016-04-13 19:09:56 +02:00
|
|
|
const struct wined3d_fb_state *fb = state->fb;
|
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;
|
2017-01-24 22:15:25 +01:00
|
|
|
struct wined3d_rendertarget_view *dsv, *rtv;
|
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;
|
2016-06-02 11:14:13 +02:00
|
|
|
unsigned int i, idx_size = 0;
|
2013-04-10 13:39:46 +02:00
|
|
|
const void *idx_data = NULL;
|
2016-06-02 11:14:13 +02:00
|
|
|
BOOL emulation = FALSE;
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2016-06-02 11:14:13 +02:00
|
|
|
if (!index_count)
|
|
|
|
return;
|
2008-03-23 13:53:45 +01:00
|
|
|
|
2017-01-24 22:15:25 +01:00
|
|
|
if (!(rtv = fb->render_targets[0]))
|
|
|
|
rtv = fb->depth_stencil;
|
2017-02-15 14:17:15 +01:00
|
|
|
context = context_acquire(device, wined3d_texture_from_resource(rtv->resource), rtv->sub_resource_idx);
|
2015-10-15 22:41:12 +02:00
|
|
|
if (!context->valid)
|
|
|
|
{
|
|
|
|
context_release(context);
|
|
|
|
WARN("Invalid context, skipping draw.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gl_info = context->gl_info;
|
|
|
|
|
2016-04-13 19:09:56 +02:00
|
|
|
for (i = 0; i < gl_info->limits.buffers; ++i)
|
2009-06-19 11:04:31 +02:00
|
|
|
{
|
2016-08-02 12:26:32 +02:00
|
|
|
struct wined3d_texture *rt;
|
2016-03-06 20:59:48 +01:00
|
|
|
|
2017-01-24 22:15:25 +01:00
|
|
|
if (!(rtv = fb->render_targets[i]) || rtv->format->id == WINED3DFMT_NULL)
|
2016-08-02 12:26:32 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
rt = wined3d_texture_from_resource(rtv->resource);
|
|
|
|
if (state->render_states[WINED3D_RS_COLORWRITEENABLE])
|
2009-06-19 11:04:31 +02:00
|
|
|
{
|
2016-08-02 12:26:32 +02:00
|
|
|
wined3d_texture_load_location(rt, rtv->sub_resource_idx, context, rtv->resource->draw_binding);
|
|
|
|
wined3d_texture_invalidate_location(rt, rtv->sub_resource_idx, ~rtv->resource->draw_binding);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wined3d_texture_prepare_location(rt, rtv->sub_resource_idx, context, rtv->resource->draw_binding);
|
2006-06-04 16:42:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-21 17:05:10 +02:00
|
|
|
if ((dsv = 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.*/
|
2016-04-21 17:05:10 +02:00
|
|
|
DWORD location = context->render_offscreen ? dsv->resource->draw_binding : WINED3D_LOCATION_DRAWABLE;
|
|
|
|
struct wined3d_surface *ds = wined3d_rendertarget_view_get_surface(dsv);
|
2015-10-28 15:29:17 +01:00
|
|
|
|
2011-12-19 21:00:09 +01:00
|
|
|
if (state->render_states[WINED3D_RS_ZWRITEENABLE] || state->render_states[WINED3D_RS_ZENABLE])
|
2017-01-26 13:25:18 +01:00
|
|
|
wined3d_texture_load_location(ds->container, dsv->sub_resource_idx, context, location);
|
2015-10-28 15:29:17 +01:00
|
|
|
else
|
2016-04-21 17:05:10 +02:00
|
|
|
wined3d_texture_prepare_location(ds->container, dsv->sub_resource_idx, context, location);
|
2008-08-21 18:23:32 +02:00
|
|
|
}
|
|
|
|
|
2016-04-14 19:32:50 +02:00
|
|
|
if (!context_apply_draw_state(context, device, state))
|
2011-07-31 17:33:40 +02:00
|
|
|
{
|
|
|
|
context_release(context);
|
|
|
|
WARN("Unable to apply draw state, skipping draw.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-26 13:25:19 +01:00
|
|
|
if (dsv && state->render_states[WINED3D_RS_ZWRITEENABLE])
|
2012-01-12 17:05:19 +01:00
|
|
|
{
|
2017-01-26 13:25:19 +01:00
|
|
|
struct wined3d_surface *ds = wined3d_rendertarget_view_get_surface(dsv);
|
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
|
|
|
|
2017-01-26 13:25:19 +01:00
|
|
|
wined3d_texture_validate_location(ds->container, dsv->sub_resource_idx, location);
|
|
|
|
wined3d_texture_invalidate_location(ds->container, dsv->sub_resource_idx, ~location);
|
2012-01-12 17:05:19 +01:00
|
|
|
}
|
|
|
|
|
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)
|
2016-06-02 11:14:13 +02:00
|
|
|
{
|
2014-01-15 22:02:15 +01:00
|
|
|
idx_data = index_buffer->resource.heap_memory;
|
2016-06-02 11:14:13 +02:00
|
|
|
}
|
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
|
|
|
}
|
2016-06-02 11:14:13 +02:00
|
|
|
idx_data = (const BYTE *)idx_data + state->index_offset;
|
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)
|
2016-06-21 10:32:44 +02:00
|
|
|
draw_primitive_immediate_mode(context, state, stream_info, idx_data,
|
|
|
|
idx_size, base_vertex_idx, start_idx, index_count, instance_count);
|
2013-01-03 11:56:26 +01:00
|
|
|
else
|
2016-06-21 10:32:44 +02:00
|
|
|
draw_primitive_arrays(context, state, idx_data, idx_size, base_vertex_idx,
|
|
|
|
start_idx, index_count, start_instance, instance_count);
|
2004-12-09 12:42:34 +01:00
|
|
|
|
2016-11-23 14:36:10 +01:00
|
|
|
if (context->uses_uavs)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glMemoryBarrier(GL_ALL_BARRIER_BITS));
|
|
|
|
checkGLcall("glMemoryBarrier");
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
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);
|
|
|
|
|
2016-06-02 11:14:13 +02:00
|
|
|
TRACE("Done all gl drawing.\n");
|
2004-12-09 12:42:34 +01:00
|
|
|
}
|
2017-02-02 12:43:40 +01:00
|
|
|
|
|
|
|
void dispatch_compute(struct wined3d_device *device, const struct wined3d_state *state,
|
|
|
|
unsigned int group_count_x, unsigned int group_count_y, unsigned int group_count_z)
|
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info;
|
|
|
|
struct wined3d_context *context;
|
|
|
|
|
2017-02-15 14:17:15 +01:00
|
|
|
context = context_acquire(device, NULL, 0);
|
2017-02-02 12:43:40 +01:00
|
|
|
if (!context->valid)
|
|
|
|
{
|
|
|
|
context_release(context);
|
|
|
|
WARN("Invalid context, skipping dispatch.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gl_info = context->gl_info;
|
|
|
|
|
|
|
|
if (!gl_info->supported[ARB_COMPUTE_SHADER])
|
|
|
|
{
|
|
|
|
context_release(context);
|
|
|
|
FIXME("OpenGL implementation does not support compute shaders.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
context_apply_compute_state(context, device, state);
|
|
|
|
|
|
|
|
if (!state->shader[WINED3D_SHADER_TYPE_COMPUTE])
|
|
|
|
{
|
|
|
|
context_release(context);
|
|
|
|
WARN("No compute shader bound, skipping dispatch.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GL_EXTCALL(glDispatchCompute(group_count_x, group_count_y, group_count_z));
|
|
|
|
checkGLcall("glDispatchCompute");
|
|
|
|
|
|
|
|
GL_EXTCALL(glMemoryBarrier(GL_ALL_BARRIER_BITS));
|
|
|
|
checkGLcall("glMemoryBarrier");
|
|
|
|
|
|
|
|
if (wined3d_settings.strict_draw_ordering)
|
|
|
|
gl_info->gl_ops.gl.p_glFlush(); /* Flush to ensure ordering across contexts. */
|
|
|
|
|
|
|
|
context_release(context);
|
|
|
|
}
|