summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drivers/gles2/rasterizer_canvas_gles2.cpp14
-rw-r--r--drivers/gles2/rasterizer_storage_gles2.cpp7
-rw-r--r--drivers/gles2/rasterizer_storage_gles2.h2
3 files changed, 20 insertions, 3 deletions
diff --git a/drivers/gles2/rasterizer_canvas_gles2.cpp b/drivers/gles2/rasterizer_canvas_gles2.cpp
index e6ec6fb4fd..047eaaf0ac 100644
--- a/drivers/gles2/rasterizer_canvas_gles2.cpp
+++ b/drivers/gles2/rasterizer_canvas_gles2.cpp
@@ -317,9 +317,17 @@ void RasterizerCanvasGLES2::_draw_polygon(const int *p_indices, int p_index_coun
}
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.polygon_index_buffer);
- glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(int) * p_index_count, p_indices);
-
- glDrawElements(GL_TRIANGLES, p_index_count, GL_UNSIGNED_INT, 0);
+ if (storage->config.support_32_bits_indices) { //should check for
+ glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(int) * p_index_count, p_indices);
+ glDrawElements(GL_TRIANGLES, p_index_count, GL_UNSIGNED_INT, 0);
+ } else {
+ uint16_t *index16 = (uint16_t *)alloca(sizeof(uint16_t) * p_index_count);
+ for (int i = 0; i < p_index_count; i++) {
+ index16[i] = uint16_t(p_indices[i]);
+ }
+ glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(uint16_t) * p_index_count, index16);
+ glDrawElements(GL_TRIANGLES, p_index_count, GL_UNSIGNED_SHORT, 0);
+ }
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/gles2/rasterizer_storage_gles2.cpp
index af698f3988..0622a353df 100644
--- a/drivers/gles2/rasterizer_storage_gles2.cpp
+++ b/drivers/gles2/rasterizer_storage_gles2.cpp
@@ -4658,6 +4658,13 @@ void RasterizerStorageGLES2::initialize() {
#else
config.use_rgba_2d_shadows = !(config.float_texture_supported && config.extensions.has("GL_EXT_texture_rg"));
#endif
+
+#ifdef GLES_OVER_GL
+ config.support_32_bits_indices = true;
+#else
+ config.support_32_bits_indices = config.extensions.has("GL_OES_element_index_uint");
+#endif
+
frame.count = 0;
frame.delta = 0;
frame.current_rt = NULL;
diff --git a/drivers/gles2/rasterizer_storage_gles2.h b/drivers/gles2/rasterizer_storage_gles2.h
index 6f3ea25cc9..ae14aaa9c0 100644
--- a/drivers/gles2/rasterizer_storage_gles2.h
+++ b/drivers/gles2/rasterizer_storage_gles2.h
@@ -78,6 +78,8 @@ public:
bool force_vertex_shading;
bool use_rgba_2d_shadows;
+
+ bool support_32_bits_indices;
} config;
struct Resources {