From 1835e2f5baa376eab95c760951fcc6a3612aa6cd Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Sun, 2 Dec 2012 18:53:20 +0100 Subject: [PATCH] wined3d: Add support for ARB_instanced_arrays. --- dlls/wined3d/directx.c | 1 + dlls/wined3d/drawprim.c | 7 +++++-- dlls/wined3d/state.c | 20 +++++++++++++++++--- dlls/wined3d/wined3d_gl.h | 3 +++ 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c index ccfcf4b0df..8d75045e6b 100644 --- a/dlls/wined3d/directx.c +++ b/dlls/wined3d/directx.c @@ -105,6 +105,7 @@ static const struct wined3d_extension_map gl_extension_map[] = {"GL_ARB_geometry_shader4", ARB_GEOMETRY_SHADER4 }, {"GL_ARB_half_float_pixel", ARB_HALF_FLOAT_PIXEL }, {"GL_ARB_half_float_vertex", ARB_HALF_FLOAT_VERTEX }, + {"GL_ARB_instanced_arrays", ARB_INSTANCED_ARRAYS, }, {"GL_ARB_map_buffer_alignment", ARB_MAP_BUFFER_ALIGNMENT }, {"GL_ARB_map_buffer_range", ARB_MAP_BUFFER_RANGE }, {"GL_ARB_multisample", ARB_MULTISAMPLE }, /* needs GLX_ARB_MULTISAMPLE as well */ diff --git a/dlls/wined3d/drawprim.c b/dlls/wined3d/drawprim.c index 9443877faa..61f3f8bbf0 100644 --- a/dlls/wined3d/drawprim.c +++ b/dlls/wined3d/drawprim.c @@ -676,6 +676,9 @@ void draw_primitive(struct wined3d_device *device, UINT start_idx, UINT index_co struct wined3d_stream_info stridedlcl; UINT idx_size = 0; + if (device->instance_count) + instance_count = device->instance_count; + if (indexed) { if (!state->user_stream) @@ -753,11 +756,11 @@ void draw_primitive(struct wined3d_device *device, UINT start_idx, UINT index_co glPrimType, idx_data, idx_size, start_idx); } } - else if (device->instance_count) + else if (!gl_info->supported[ARB_INSTANCED_ARRAYS] && 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, device->instance_count); + idx_data, idx_size, start_idx, base_vertex_index, instance_count); } else { diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c index 6f0c4f2f50..d0445c9e42 100644 --- a/dlls/wined3d/state.c +++ b/dlls/wined3d/state.c @@ -4101,6 +4101,8 @@ static inline void unload_numbered_array(struct wined3d_context *context, int i) GL_EXTCALL(glDisableVertexAttribArrayARB(i)); checkGLcall("glDisableVertexAttribArrayARB(reg)"); + if (gl_info->supported[ARB_INSTANCED_ARRAYS]) + GL_EXTCALL(glVertexAttribDivisorARB(i, 0)); context->numbered_array_mask &= ~(1 << i); } @@ -4143,13 +4145,25 @@ static void load_numbered_arrays(struct wined3d_context *context, stream = &state->streams[stream_info->elements[i].stream_idx]; - /* 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); - continue; + + if (!gl_info->supported[ARB_INSTANCED_ARRAYS]) + { + /* Unload instanced arrays, they will be loaded using + * immediate mode instead. */ + if (context->numbered_array_mask & (1 << i)) + unload_numbered_array(context, i); + continue; + } + + GL_EXTCALL(glVertexAttribDivisorARB(i, 1)); + } + else if (gl_info->supported[ARB_INSTANCED_ARRAYS]) + { + GL_EXTCALL(glVertexAttribDivisorARB(i, 0)); } TRACE_(d3d_shader)("Loading array %u [VBO=%u]\n", i, stream_info->elements[i].data.buffer_object); diff --git a/dlls/wined3d/wined3d_gl.h b/dlls/wined3d/wined3d_gl.h index fc0a68c075..06b527467e 100644 --- a/dlls/wined3d/wined3d_gl.h +++ b/dlls/wined3d/wined3d_gl.h @@ -57,6 +57,7 @@ enum wined3d_gl_extension ARB_GEOMETRY_SHADER4, ARB_HALF_FLOAT_PIXEL, ARB_HALF_FLOAT_VERTEX, + ARB_INSTANCED_ARRAYS, ARB_MAP_BUFFER_ALIGNMENT, ARB_MAP_BUFFER_RANGE, ARB_MULTISAMPLE, @@ -214,6 +215,8 @@ enum wined3d_gl_extension USE_GL_FUNC(glFramebufferTextureFaceARB) \ USE_GL_FUNC(glFramebufferTextureLayerARB) \ USE_GL_FUNC(glProgramParameteriARB) \ + /* GL_ARB_instanced_arrays */ \ + USE_GL_FUNC(glVertexAttribDivisorARB) \ /* GL_ARB_map_buffer_range */ \ USE_GL_FUNC(glFlushMappedBufferRange) \ USE_GL_FUNC(glMapBufferRange) \