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:
authorMike Erwin <significant.bit@gmail.com>2016-08-07 07:02:09 +0300
committerMike Erwin <significant.bit@gmail.com>2016-08-07 08:05:49 +0300
commit0ea8430549374efd3092b6f28913a5f60e574296 (patch)
treeb75db29a549b4f521e02fd0b9f58e8febd0fc4b9 /source/blender/gpu/intern/gpu_immediate.c
parente7f9614f079ff3d6c2dfdfa38aa51b3c556096cf (diff)
Gawain: legacy Mac VBO workarounds
glMapBufferRange is a wonderful function that doesn’t exist on GL < 3.0. Use the APPLE_flush_buffer_range extension on Mac. It offers several of glMapBufferRange’s benefits. Use older “black arts” method to orphan VBOs when we are done with them. In modern OpenGL this behavior is more obvious. Add APPLE_flush_buffer_range to Mac requirements. Every GPU is supported. T49012
Diffstat (limited to 'source/blender/gpu/intern/gpu_immediate.c')
-rw-r--r--source/blender/gpu/intern/gpu_immediate.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/source/blender/gpu/intern/gpu_immediate.c b/source/blender/gpu/intern/gpu_immediate.c
index 3d7250bf7e8..80e7877ade0 100644
--- a/source/blender/gpu/intern/gpu_immediate.c
+++ b/source/blender/gpu/intern/gpu_immediate.c
@@ -22,7 +22,9 @@
#include <stdio.h>
#endif
-#if defined(__APPLE__) && defined(WITH_GL_PROFILE_COMPAT)
+#define APPLE_LEGACY (defined(__APPLE__) && defined(WITH_GL_PROFILE_COMPAT))
+
+#if APPLE_LEGACY
#undef glGenVertexArrays
#define glGenVertexArrays glGenVertexArraysAPPLE
@@ -210,6 +212,11 @@ void immInit()
glBindBuffer(GL_ARRAY_BUFFER, imm.vbo_id);
glBufferData(GL_ARRAY_BUFFER, IMM_BUFFER_SIZE, NULL, GL_DYNAMIC_DRAW);
+#if APPLE_LEGACY
+ glBufferParameteriAPPLE(GL_ARRAY_BUFFER, GL_BUFFER_SERIALIZED_MODIFY_APPLE, GL_FALSE);
+ glBufferParameteriAPPLE(GL_ARRAY_BUFFER, GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE);
+#endif
+
imm.primitive = GL_NONE;
glBindBuffer(GL_ARRAY_BUFFER, 0);
@@ -285,15 +292,23 @@ void immBegin(GLenum primitive, unsigned vertex_ct)
else
{
// orphan this buffer & start with a fresh one
+#if APPLE_LEGACY
+ glBufferData(GL_ARRAY_BUFFER, IMM_BUFFER_SIZE, NULL, GL_DYNAMIC_DRAW);
+#else
glMapBufferRange(GL_ARRAY_BUFFER, 0, IMM_BUFFER_SIZE, GL_MAP_INVALIDATE_BUFFER_BIT);
// glInvalidateBufferData(imm.vbo_id); // VERSION >= 4.3 || ARB_invalidate_subdata
+#endif
imm.buffer_offset = 0;
}
// printf("mapping %u to %u\n", imm.buffer_offset, imm.buffer_offset + bytes_needed - 1);
+#if APPLE_LEGACY
+ imm.buffer_data = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY) + imm.buffer_offset;
+#else
imm.buffer_data = glMapBufferRange(GL_ARRAY_BUFFER, imm.buffer_offset, bytes_needed, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
+#endif
#if TRUST_NO_ONE
assert(imm.buffer_data != NULL);
@@ -310,6 +325,11 @@ void immEnd()
assert(imm.vertex_idx == imm.vertex_ct); // with all vertices defined
#endif
+#if APPLE_LEGACY
+ // tell OpenGL what range was modified so it doesn't copy the whole buffer
+ glFlushMappedBufferRangeAPPLE(GL_ARRAY_BUFFER, imm.buffer_offset, imm.buffer_bytes_mapped);
+// printf("flushing %u to %u\n", imm.buffer_offset, imm.buffer_offset + imm.buffer_bytes_mapped - 1);
+#endif
glUnmapBuffer(GL_ARRAY_BUFFER);
// set up VAO -- can be done during Begin or End really