Commit 52c6abb4 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Resolve the instance count for instanced arrays in load_numbered_arrays().

parent ff11a32f
......@@ -494,12 +494,12 @@ static void drawStridedSlowVs(const struct wined3d_gl_info *gl_info, const struc
/* GL locking is done by the caller */
static void drawStridedInstanced(const struct wined3d_gl_info *gl_info, const struct wined3d_state *state,
const struct wined3d_stream_info *si, UINT numberOfVertices, GLenum glPrimitiveType,
const void *idxData, UINT idxSize, UINT startIdx, UINT base_vertex_index)
const void *idxData, UINT idxSize, UINT startIdx, UINT base_vertex_index, UINT instance_count)
{
UINT numInstances = 0, i;
int numInstancedAttribs = 0, j;
UINT instancedData[sizeof(si->elements) / sizeof(*si->elements) /* 16 */];
GLenum idxtype = idxSize == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
UINT i;
if (!idxSize)
{
......@@ -513,22 +513,6 @@ static void drawStridedInstanced(const struct wined3d_gl_info *gl_info, const st
return;
}
/* First, figure out how many instances we have to draw */
for (i = 0; i < MAX_STREAMS; ++i)
{
/* Look at the streams and take the first one which matches */
if (state->streams[i].buffer
&& ((state->streams[i].flags & WINED3DSTREAMSOURCE_INSTANCEDATA)
|| (state->streams[i].flags & WINED3DSTREAMSOURCE_INDEXEDDATA)))
{
/* Use the specified number of instances from the first matched
* stream. A streamFreq of 0 (with INSTANCEDATA or INDEXEDDATA)
* is handled as 1. See d3d9/tests/visual.c-> stream_test(). */
numInstances = state->streams[i].frequency ? state->streams[i].frequency : 1;
break;
}
}
for (i = 0; i < sizeof(si->elements) / sizeof(*si->elements); ++i)
{
if (!(si->use_map & (1 << i))) continue;
......@@ -540,8 +524,8 @@ static void drawStridedInstanced(const struct wined3d_gl_info *gl_info, const st
}
}
/* now draw numInstances instances :-) */
for(i = 0; i < numInstances; i++) {
for (i = 0; i < instance_count; ++i)
{
/* Specify the instanced attributes using immediate mode calls */
for(j = 0; j < numInstancedAttribs; j++) {
const BYTE *ptr = si->elements[instancedData[j]].data.addr
......@@ -769,11 +753,11 @@ void draw_primitive(struct wined3d_device *device, UINT start_idx, UINT index_co
glPrimType, idx_data, idx_size, start_idx);
}
}
else if (device->instancedDraw)
else if (device->instance_count)
{
/* Instancing emulation with mixing immediate mode and arrays */
drawStridedInstanced(gl_info, state, stream_info, index_count,
glPrimType, idx_data, idx_size, start_idx, base_vertex_index);
drawStridedInstanced(gl_info, state, stream_info, index_count, glPrimType,
idx_data, idx_size, start_idx, base_vertex_index, device->instance_count);
}
else
{
......
......@@ -4126,7 +4126,7 @@ static void load_numbered_arrays(struct wined3d_context *context,
int i;
/* Default to no instancing */
device->instancedDraw = FALSE;
device->instance_count = 0;
for (i = 0; i < MAX_ATTRIBS; i++)
{
......@@ -4146,8 +4146,9 @@ static void load_numbered_arrays(struct wined3d_context *context,
/* Do not load instance data. It will be specified using glTexCoord by drawprim */
if (stream->flags & WINED3DSTREAMSOURCE_INSTANCEDATA)
{
if (!device->instance_count)
device->instance_count = state->streams[0].frequency ? state->streams[0].frequency : 1;
if (context->numbered_array_mask & (1 << i)) unload_numbered_array(context, i);
device->instancedDraw = TRUE;
continue;
}
......@@ -4290,7 +4291,7 @@ static void load_vertex_data(const struct wined3d_context *context,
TRACE("Using fast vertex array code\n");
/* This is fixed function pipeline only, and the fixed function pipeline doesn't do instancing */
device->instancedDraw = FALSE;
device->instance_count = 0;
/* Blend Data ---------------------------------------------- */
if ((si->use_map & (1 << WINED3D_FFP_BLENDWEIGHT))
......
......@@ -1724,6 +1724,7 @@ struct wined3d_device
UINT vs_version, gs_version, ps_version;
DWORD d3d_vshader_constantF, d3d_pshader_constantF; /* Advertised d3d caps, not GL ones */
DWORD vs_clipping;
UINT instance_count;
WORD view_ident : 1; /* true iff view matrix is identity */
WORD vertexBlendUsed : 1; /* To avoid needless setting of the blend matrices */
......@@ -1734,9 +1735,8 @@ struct wined3d_device
WORD inScene : 1; /* A flag to check for proper BeginScene / EndScene call pairs */
WORD softwareVertexProcessing : 1; /* process vertex shaders using software or hardware */
WORD useDrawStridedSlow : 1;
WORD instancedDraw : 1;
WORD filter_messages : 1;
WORD padding : 5;
WORD padding : 6;
BYTE fixed_function_usage_map; /* MAX_TEXTURES, 8 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment