Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2019-05-29 01:08:10 +0300
committerClément Foucault <foucault.clem@gmail.com>2019-05-30 14:42:21 +0300
commit77f5210f22332b3594fabe08bee5809fc8333dba (patch)
tree82f8fbba7d762d30363a40eb9d41f0df828d7586 /source/blender/gpu/intern/gpu_batch.c
parentdc0c490b7601b4dced13be6a9877f68ee9712736 (diff)
GPU: Remove GPU_INDEX_U8
This type of indices is not natively supported on modern GPU and gives warning on some implementation. The memory savings it provides is also quite minimal and unlikely to be visible on nowadays hardware. This remove some uneeded struct members and makes primitive restart always enabled by default. This can be broken by addons if they are not careful enough but many other states have this problem. Also leverage GL_PRIMITIVE_RESTART_FIXED_INDEX if ARB_ES3_compatibility is supported. This removes all API calls to change restart index depending on indices length.
Diffstat (limited to 'source/blender/gpu/intern/gpu_batch.c')
-rw-r--r--source/blender/gpu/intern/gpu_batch.c40
1 files changed, 12 insertions, 28 deletions
diff --git a/source/blender/gpu/intern/gpu_batch.c b/source/blender/gpu/intern/gpu_batch.c
index d1cfd5c337d..fb2a87fc8d1 100644
--- a/source/blender/gpu/intern/gpu_batch.c
+++ b/source/blender/gpu/intern/gpu_batch.c
@@ -545,36 +545,26 @@ void GPU_batch_uniform_mat4(GPUBatch *batch, const char *name, const float data[
glUniformMatrix4fv(uniform->location, 1, GL_FALSE, (const float *)data);
}
-static void primitive_restart_enable(const GPUIndexBuf *el)
+static void primitive_restart_index(const GPUIndexBuf *el)
{
- // TODO(fclem) Replace by GL_PRIMITIVE_RESTART_FIXED_INDEX when we have ogl 4.3
- glEnable(GL_PRIMITIVE_RESTART);
- GLuint restart_index = (GLuint)0xFFFFFFFF;
-
#if GPU_TRACK_INDEX_RANGE
- if (el->index_type == GPU_INDEX_U8) {
- restart_index = (GLuint)0xFF;
- }
- else if (el->index_type == GPU_INDEX_U16) {
- restart_index = (GLuint)0xFFFF;
+ /* Can be removed if GL 4.3 is available. */
+ if (!GLEW_ARB_ES3_compatibility) {
+ /* Stay sync with GPU_state_init(). */
+ static int last_type = GPU_INDEX_U32;
+ if (el->index_type != last_type) {
+ GLuint restart_index = (el->index_type == GPU_INDEX_U16) ? (GLuint)0xFFFF :
+ (GLuint)0xFFFFFFFF;
+ glPrimitiveRestartIndex(restart_index);
+ }
}
#endif
-
- glPrimitiveRestartIndex(restart_index);
-}
-
-static void primitive_restart_disable(void)
-{
- glDisable(GL_PRIMITIVE_RESTART);
}
static void *elem_offset(const GPUIndexBuf *el, int v_first)
{
#if GPU_TRACK_INDEX_RANGE
- if (el->index_type == GPU_INDEX_U8) {
- return (GLubyte *)0 + v_first;
- }
- else if (el->index_type == GPU_INDEX_U16) {
+ if (el->index_type == GPU_INDEX_U16) {
return (GLushort *)0 + v_first;
}
#endif
@@ -641,9 +631,7 @@ void GPU_batch_draw_advanced(GPUBatch *batch, int v_first, int v_count, int i_fi
#endif
void *v_first_ofs = elem_offset(el, v_first);
- if (el->use_prim_restart) {
- primitive_restart_enable(el);
- }
+ primitive_restart_index(el);
if (GLEW_ARB_base_instance) {
glDrawElementsInstancedBaseVertexBaseInstance(
@@ -653,10 +641,6 @@ void GPU_batch_draw_advanced(GPUBatch *batch, int v_first, int v_count, int i_fi
glDrawElementsInstancedBaseVertex(
batch->gl_prim_type, v_count, index_type, v_first_ofs, i_count, base_index);
}
-
- if (el->use_prim_restart) {
- primitive_restart_disable();
- }
}
else {
if (GLEW_ARB_base_instance) {