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:
authorJason Wilkins <Jason.A.Wilkins@gmail.com>2014-07-04 20:57:20 +0400
committerJason Wilkins <Jason.A.Wilkins@gmail.com>2014-07-04 20:57:20 +0400
commit361ab2ff2e9f8fc15449f52790ea2a2025972cd5 (patch)
treed2e49b5b65ef47ba3fc425c7d4000c0594274fbe
parentc39f6c49b7f2c164920a2c3af5436ba13ab28400 (diff)
OpenGL Extension Shims
A few things are going on with these "shims": * OpenGL 2.0 and GLEW_ARB_shader_objects are subtly different. * Some extensions come in ARB and OES flavors. * GenerateMipmaps needs a workaround on ATI. * gpu_buffer_start_update and gpu_buffer_finish_update make usage of buffer objects a bit more abstract Any use of a shimmed function directly without the shim is caught by GPU_deprecated.h There are also some other changes that are not related to shims that came along for the ride.
-rw-r--r--intern/ghost/intern/GHOST_ContextCGL.mm5
-rw-r--r--source/blender/gpu/GPU_deprecated.h225
-rw-r--r--source/blender/gpu/GPU_extensions.h8
-rw-r--r--source/blender/gpu/intern/gpu_buffers.c256
-rw-r--r--source/blender/gpu/intern/gpu_codegen.c4
-rw-r--r--source/blender/gpu/intern/gpu_common.c8
-rw-r--r--source/blender/gpu/intern/gpu_common_intern.h10
-rw-r--r--source/blender/gpu/intern/gpu_draw.c92
-rw-r--r--source/blender/gpu/intern/gpu_extensions.c1195
-rw-r--r--source/blender/gpu/intern/gpu_immediate_gl.c4
-rw-r--r--source/blender/gpu/intern/gpu_init_exit.c4
11 files changed, 1346 insertions, 465 deletions
diff --git a/intern/ghost/intern/GHOST_ContextCGL.mm b/intern/ghost/intern/GHOST_ContextCGL.mm
index 12837a6e50c..ad5424b7038 100644
--- a/intern/ghost/intern/GHOST_ContextCGL.mm
+++ b/intern/ghost/intern/GHOST_ContextCGL.mm
@@ -154,11 +154,6 @@ GHOST_TSuccess GHOST_ContextCGL::activateDrawingContext()
activateGLEW();
- // Disable AA by default
- // XXX jwilkins: shouldn't this be somewhere else?
- if (m_numOfAASamples > 0)
- glDisable(GL_MULTISAMPLE_ARB);
-
[pool drain];
return GHOST_kSuccess;
}
diff --git a/source/blender/gpu/GPU_deprecated.h b/source/blender/gpu/GPU_deprecated.h
index 50ac28c337c..9438b4fab82 100644
--- a/source/blender/gpu/GPU_deprecated.h
+++ b/source/blender/gpu/GPU_deprecated.h
@@ -32,6 +32,231 @@
* \ingroup gpu
*/
+#undef glAttachShader
+#define glAttachShader USE_SHIM_gpu_glAttachShader
+#undef glCompileShader
+#define glCompileShader USE_SHIM_gpu_glCompileShader
+#undef glCreateProgram
+#define glCreateProgram USE_SHIM_gpu_glCreateProgram
+#undef glCreateShader
+#define glCreateShader USE_SHIM_gpu_glCreateShader
+#undef glDeleteShader
+#define glDeleteShader USE_SHIM_gpu_glDeleteShader
+#undef glGetProgramInfoLog
+#define glGetProgramInfoLog USE_SHIM_gpu_glGetProgramInfoLog
+#undef glGetShaderiv
+#define glGetShaderiv USE_SHIM_gpu_glGetShaderiv
+#undef glGetShaderInfoLog
+#define glGetShaderInfoLog USE_SHIM_gpu_glGetShaderInfoLog
+#undef glGetUniformLocation
+#define glGetUniformLocation USE_SHIM_gpu_glGetUniformLocation
+#undef glLinkProgram
+#define glLinkProgram USE_SHIM_gpu_glLinkProgram
+#undef glShaderSource
+#define glShaderSource USE_SHIM_gpu_glShaderSource
+#undef glUniform1i
+#define glUniform1i USE_SHIM_gpu_glUniform1i
+#undef glUniform1f
+#define glUniform1f USE_SHIM_gpu_glUniform1f
+#undef glUniform1iv
+#define glUniform1iv USE_SHIM_gpu_glUniform1iv
+#undef glUniform2iv
+#define glUniform2iv USE_SHIM_gpu_glUniform2iv
+#undef glUniform3iv
+#define glUniform3iv USE_SHIM_gpu_glUniform3iv
+#undef glUniform4iv
+#define glUniform4iv USE_SHIM_gpu_glUniform4iv
+#undef glUniform1fv
+#define glUniform1fv USE_SHIM_gpu_glUniform1fv
+#undef glUniform2fv
+#define glUniform2fv USE_SHIM_gpu_glUniform2fv
+#undef glUniform3fv
+#define glUniform3fv USE_SHIM_gpu_glUniform3fv
+#undef glUniform4fv
+#define glUniform4fv USE_SHIM_gpu_glUniform4fv
+#undef glUniformMatrix3fv
+#define glUniformMatrix3fv USE_SHIM_gpu_glUniformMatrix3fv
+#undef glUniformMatrix4fv
+#define glUniformMatrix4fv USE_SHIM_gpu_glUniformMatrix4fv
+#undef glUseProgram
+#define glUseProgram USE_SHIM_gpu_glUseProgram
+#undef glValidateProgram
+#define glValidateProgram USE_SHIM_gpu_glValidateProgram
+
+#undef glAttachObjectARB
+#define glAttachObjectARB USE_SHIM_gpu_glAttachObject
+#undef glCompileShader
+#define glCompileShader USE_SHIM_gpu_glCompileShader
+#undef glCreateProgramObjectARB
+#define glCreateProgramObjectARB USE_SHIM_gpu_glCreateProgram
+#undef glCreateShaderObjectARB
+#define glCreateShaderObjectARB USE_SHIM_gpu_glCreateShader
+#undef glDeleteObjectARB
+#define glDeleteObjectARB USE_SHIM_gpu_glDeleteShader_or_gpu_glDeleteProgram
+#undef glGetInfoLogARB
+#define glGetInfoLogARB USE_SHIM_gpu_glGetProgramInfoLog_or_gpu_glGetShaderInfoLog
+#undef glGetObjectParameterivARB
+#define glGetObjectParameterivARB USE_SHIM_gpu_glGetShaderiv
+#undef glGetUniformLocationARB
+#define glGetUniformLocationARB USE_SHIM_gpu_glGetUniformLocation
+#undef glLinkProgramARB
+#define glLinkProgramARB USE_SHIM_gpu_glLinkProgram
+#undef glShaderSourceARB
+#define glShaderSourceARB USE_SHIM_gpu_glShaderSource
+#undef glUniform1iARB
+#define glUniform1iARB USE_SHIM_gpu_glUniform1i
+#undef glUniform1fARB
+#define glUniform1fARB USE_SHIM_gpu_glUniform1f
+#undef glUniform1ivARB
+#define glUniform1ivARB USE_SHIM_gpu_glUniform1iv
+#undef glUniform2ivARB
+#define glUniform2ivARB USE_SHIM_gpu_glUniform2iv
+#undef glUniform3ivARB
+#define glUniform3ivARB USE_SHIM_gpu_glUniform3iv
+#undef glUniform4ivARB
+#define glUniform4ivARB USE_SHIM_gpu_glUniform4iv
+#undef glUniform1fvARB
+#define glUniform1fvARB USE_SHIM_gpu_glUniform1fv
+#undef glUniform2fvARB
+#define glUniform2fvARB USE_SHIM_gpu_glUniform2fv
+#undef glUniform3fvARB
+#define glUniform3fvARB USE_SHIM_gpu_glUniform3fv
+#undef glUniform4fvARB
+#define glUniform4fvARB USE_SHIM_gpu_glUniform4fv
+#undef glUniformMatrix3fvARB
+#define glUniformMatrix3fvARB USE_SHIM_gpu_glUniformMatrix3fv
+#undef glUniformMatrix4fvARB
+#define glUniformMatrix4fvARB USE_SHIM_gpu_glUniformMatrix4fv
+#undef glUseProgramObjectARB
+#define glUseProgramObjectARB USE_SHIM_gpu_glUseProgram
+#undef glValidateProgramARB
+#define glValidateProgramARB USE_SHIM_gpu_glValidateProgram
+
+#undef glBindAttribLocation
+#define glBindAttribLocation USE_SHIM_gpu_glBindAttribLocation
+#undef glGetAttribLocation
+#define glGetAttribLocation USE_SHIM_gpu_glGetAttribLocation
+
+#undef glBindAttribLocationARB
+#define glBindAttribLocationARB USE_SHIM_gpu_glBindAttribLocation
+#undef glGetAttribLocationARB
+#define glGetAttribLocationARB USE_SHIM_gpu_glGetAttribLocation
+
+#undef glDeleteProgram
+#define glDeleteProgram USE_SHIM_gpu_glDeleteProgram
+#undef glDisableVertexAttribArray
+#define glDisableVertexAttribArray USE_SHIM_gpu_glDisableVertexAttribArray
+#undef glEnableVertexAttribArray
+#define glEnableVertexAttribArray USE_SHIM_gpu_glEnableVertexAttribArray
+#undef glGetProgramiv
+#define glGetProgramiv USE_SHIM_gpu_glGetProgramiv
+#undef glVertexAttribPointer
+#define glVertexAttribPointer USE_SHIM_gpu_glVertexAttribPointer
+
+//#undef glDeleteObjectARB
+//#define glDeleteObjectARB USE_SHIM_gpu_glDeleteShader_or_gpu_glDeleteProgram
+#undef glDisableVertexAttribArrayARB
+#define glDisableVertexAttribArrayARB USE_SHIM_gpu_glDisableVertexAttribArray
+#undef glEnableVertexAttribArrayARB
+#define glEnableVertexAttribArrayARB USE_SHIM_gpu_glEnableVertexAttribArray
+#undef glGetProgramivARB
+#define glGetProgramiv USE_SHIM_gpu_glGetProgramiv
+#undef glVertexAttribPointerARB
+#define glVertexAttribPointerARB USE_SHIM_gpu_glVertexAttribPointer
+
+#undef glBindBuffer
+#define glBindBuffer USE_SHIM_gpu_glBindBuffer
+#undef glBufferData
+#define glBufferData USE_SHIM_gpu_glBufferData
+#undef glBufferSubData
+#define glBufferSubData USE_SHIM_gpu_glBufferSubData
+#undef glDeleteBuffers
+#define glDeleteBuffers USE_SHIM_gpu_glDeleteBuffers
+#undef glGenBuffers
+#define glGenBuffers USE_SHIM_gpu_glGenBuffers
+
+#undef glBindBufferARB
+#define glBindBufferARB USE_SHIM_gpu_glBindBuffer
+#undef glBufferDataARB
+#define glBufferDataARB USE_SHIM_gpu_glBufferData
+#undef glBufferSubDataARB
+#define glBufferSubDataARB USE_SHIM_gpu_glBufferSubData
+#undef glDeleteBuffersARB
+#define glDeleteBuffersARB USE_SHIM_gpu_glDeleteBuffers
+#undef glGenBuffersARB
+#define glGenBuffersARB USE_SHIM_gpu_glGenBuffers
+
+#undef glMapBuffer
+#define glMapBuffer USE_SHIM_gpu_glMapBuffer
+#undef glUnmapBuffer
+#define glUnmapBuffer USE_SHIM_gpu_glUnmapBuffer
+
+#undef glMapBufferARB
+#define glMapBufferARB USE_SHIM_gpu_glMapBuffer
+#undef glUnmapBufferARB
+#define glUnmapBufferARB USE_SHIM_gpu_glUnmapBuffer
+
+#undef glMapBufferOES
+#define glMapBufferOES USE_SHIM_gpu_glMapBuffer
+#undef glUnmapBufferOES
+#define glUnmapBufferOES USE_SHIM_gpu_glUnmapBuffer
+
+#undef glBindFramebuffer
+#define glBindFramebuffer USE_SHIM_gpu_glBindFramebuffer
+#undef glCheckFramebufferStatus
+#define glCheckFramebufferStatus USE_SHIM_gpu_glCheckFramebufferStatus
+#undef glDeleteFramebuffers
+#define glDeleteFramebuffers USE_SHIM_gpu_glDeleteFramebuffers
+#undef glFramebufferTexture2D
+#define glFramebufferTexture2D USE_SHIM_gpu_glFramebufferTexture2D
+#undef glGenFramebuffers
+#define glGenFramebuffers USE_SHIM_gpu_glGenFramebuffers
+
+#undef glBindFramebufferEXT
+#define glBindFramebufferEXT USE_SHIM_gpu_glBindFramebuffer
+#undef glCheckFramebufferStatusEXT
+#define glCheckFramebufferStatusEXT USE_SHIM_gpu_glCheckFramebufferStatus
+#undef glDeleteFramebuffersEXT
+#define glDeleteFramebuffersEXT USE_SHIM_gpu_glDeleteFramebuffers
+#undef glFramebufferTexture2DEXT
+#define glFramebufferTexture2DEXT USE_SHIM_gpu_glFramebufferTexture2D
+#undef glGenFramebuffersEXT
+#define glGenFramebuffersEXT USE_SHIM_gpu_glGenFramebuffers
+
+#undef glBindFramebufferOES
+#define glBindFramebufferOES USE_SHIM_gpu_glBindFramebuffer
+#undef glCheckFramebufferStatusOES
+#define glCheckFramebufferStatusOES USE_SHIM_gpu_glCheckFramebufferStatus
+#undef glDeleteFramebuffersOES
+#define glDeleteFramebuffersOES USE_SHIM_gpu_glDeleteFramebuffers
+#undef glFramebufferTexture2DOES
+#define glFramebufferTexture2DOES USE_SHIM_gpu_glFramebufferTexture2D
+#undef glGenFramebuffersOES
+#define glGenFramebuffersOES USE_SHIM_gpu_glGenFramebuffers
+
+#undef glBindVertexArray
+#define glBindVertexArray USE_SHIM_gpu_glBindVertexArray
+#undef glDeleteVertexArrays
+#define glDeleteVertexArrays USE_SHIM_gpu_glDeleteVertexArrays
+#undef glGenVertexArrays
+#define glGenVertexArrays USE_SHIM_gpu_glGenVertexArrays
+
+#undef glBindVertexArrayOES
+#define glBindVertexArrayOES USE_SHIM_gpu_glBindVertexArray
+#undef glDeleteVertexArraysOES
+#define glDeleteVertexArraysOES USE_SHIM_gpu_glDeleteVertexArrays
+#undef glGenVertexArraysOES
+#define glGenVertexArraysOES USE_SHIM_gpu_glGenVertexArrays
+
+#undef glGenerateMipmap
+#define glGenerateMipmap USE_SHIM_gpu_glGenerateMipmap
+
+#undef glGenerateMipmapEXT
+#define glGenerateMipmapEXT USE_SHIM_gpu_glGenerateMipmapEXT
+
+#undef glGenerateMipmapOES
+#define glGenerateMipmapOES USE_SHIM_gpu_glGenerateMipmapOES
+
#if 0
#undef glBegin
#define glBegin DO_NOT_USE_glBegin
diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h
index cc1aa9d7b11..3124da21ee3 100644
--- a/source/blender/gpu/GPU_extensions.h
+++ b/source/blender/gpu/GPU_extensions.h
@@ -59,7 +59,7 @@ typedef struct GPUShader GPUShader;
/* GPU extensions support */
void GPU_extensions_disable(void);
-int GPU_print_error(const char *str);
+bool GPU_print_error(const char *str);
int GPU_glsl_support(void);
int GPU_non_power_of_two_support(void);
@@ -147,7 +147,7 @@ unsigned char *GPU_texture_dup_pixels(const GPUTexture *tex, size_t *count_out);
* be called before rendering to the window framebuffer again */
GPUFrameBuffer *GPU_framebuffer_create(void);
-int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, char err_out[256]);
+bool GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, char err_out[256]);
void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, GPUTexture *tex);
void GPU_framebuffer_texture_bind(GPUFrameBuffer *fb, GPUTexture *tex, int w, int h);
void GPU_framebuffer_texture_unbind(GPUFrameBuffer *fb, GPUTexture *tex);
@@ -172,13 +172,13 @@ int GPU_offscreen_height(GPUOffScreen *ofs);
* - only for fragment shaders now
* - must call texture bind before setting a texture as uniform! */
-GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, const char *libcode, const char *defines);
+GPUShader *GPU_shader_create(const char* nickname, const char *vertexcode, const char *fragcode, const char *libcode, const char *defines);
+
void GPU_shader_free(GPUShader *shader);
void GPU_shader_bind(GPUShader *shader);
void GPU_shader_unbind(void);
-int GPU_shader_get_attrib(GPUShader *shader, const char *name);
int GPU_shader_get_uniform(GPUShader *shader, const char *name);
void GPU_shader_uniform_vector(GPUShader *shader, int location, int length,
int arraysize, float *value);
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index 88d126941e4..e6bac9afdfb 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -32,32 +32,40 @@
* with fall-back to vertex arrays.
*/
-#include <limits.h>
-#include <stddef.h>
-#include <string.h>
+/* my interface */
+#include "GPU_buffers.h"
-#include "MEM_guardedalloc.h"
+/* internal */
+#include "intern/gpu_extensions_intern.h"
-#include "BLI_bitmap.h"
-#include "BLI_math.h"
-#include "BLI_utildefines.h"
-#include "BLI_ghash.h"
-#include "BLI_threads.h"
+/* my library */
+#include "GPU_draw.h"
+#include "GPU_glew.h"
-#include "DNA_meshdata_types.h"
+/* external */
#include "BKE_ccg.h"
#include "BKE_DerivedMesh.h"
#include "BKE_paint.h"
#include "BKE_pbvh.h"
+#include "BLI_bitmap.h"
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
+#include "BLI_ghash.h"
+#include "BLI_threads.h"
+
+#include "bmesh.h"
+
+#include "DNA_meshdata_types.h"
#include "DNA_userdef_types.h"
-#include "GPU_buffers.h"
-#include "GPU_draw.h"
-#include "GPU_glew.h"
+#include "MEM_guardedalloc.h"
-#include "bmesh.h"
+/* standard */
+#include <limits.h>
+#include <stddef.h>
+#include <string.h>
typedef enum {
GPU_BUFFER_VERTEX_STATE = 1,
@@ -153,7 +161,7 @@ static void gpu_buffer_pool_delete_last(GPUBufferPool *pool)
/* delete the buffer's data */
if (useVBOs)
- glDeleteBuffersARB(1, &last->id);
+ gpu_glDeleteBuffers(1, &last->id);
else
MEM_freeN(last->pointer);
@@ -188,7 +196,7 @@ static void gpu_buffer_pool_free_unused(GPUBufferPool *pool)
while (pool->totbuf)
gpu_buffer_pool_delete_last(pool);
- glDeleteBuffersARB(pool->totpbvhbufids, pool->pbvhbufids);
+ gpu_glDeleteBuffers(pool->totpbvhbufids, pool->pbvhbufids);
pool->totpbvhbufids = 0;
BLI_mutex_unlock(&buffer_mutex);
@@ -277,14 +285,14 @@ static GPUBuffer *gpu_buffer_alloc_intern(int size)
if (useVBOs == 1) {
/* create a new VBO and initialize it to the requested
* size */
- glGenBuffersARB(1, &buf->id);
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, buf->id);
- glBufferDataARB(GL_ARRAY_BUFFER_ARB, size, NULL, GL_STATIC_DRAW_ARB);
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
+ gpu_glGenBuffers(1, &buf->id);
+ gpu_glBindBuffer(GL_ARRAY_BUFFER, buf->id);
+ gpu_glBufferData(GL_ARRAY_BUFFER, size, NULL, GL_STATIC_DRAW);
+ gpu_glBindBuffer(GL_ARRAY_BUFFER, 0);
}
else {
buf->pointer = MEM_mallocN(size, "GPUBuffer.pointer");
-
+
/* purpose of this seems to be dealing with
* out-of-memory errors? looks a bit iffy to me
* though, at least on Linux I expect malloc() would
@@ -348,8 +356,8 @@ static void gpu_buffer_free_intern(GPUBuffer *buffer)
* buffer, so increase pool size */
if (pool->maxsize == pool->totbuf) {
pool->maxsize += MAX_FREE_GPU_BUFFERS;
- pool->buffers = MEM_reallocN(pool->buffers,
- sizeof(GPUBuffer *) * pool->maxsize);
+ pool->buffers = (GPUBuffer**)MEM_reallocN(pool->buffers,
+ sizeof(GPUBuffer *) * pool->maxsize);
}
}
@@ -610,7 +618,7 @@ static GPUBuffer *gpu_buffer_setup(DerivedMesh *dm, GPUDrawObject *object,
}
mat_orig_to_new = MEM_mallocN(sizeof(*mat_orig_to_new) * dm->totmat,
- "GPU_buffer_setup.mat_orig_to_new");
+ "GPU_buffer_setup.mat_orig_to_new");
cur_index_per_mat = MEM_mallocN(sizeof(int) * object->totmaterial,
"GPU_buffer_setup.cur_index_per_mat");
for (i = 0; i < object->totmaterial; i++) {
@@ -628,11 +636,11 @@ static GPUBuffer *gpu_buffer_setup(DerivedMesh *dm, GPUDrawObject *object,
while (!success) {
/* bind the buffer and discard previous data,
* avoids stalling gpu */
- glBindBufferARB(target, buffer->id);
- glBufferDataARB(target, buffer->size, NULL, GL_STATIC_DRAW_ARB);
+ gpu_glBindBuffer(target, buffer->id);
+ gpu_glBufferData(target, buffer->size, NULL, GL_STATIC_DRAW);
/* attempt to map the buffer */
- if (!(varray = glMapBufferARB(target, GL_WRITE_ONLY_ARB))) {
+ if (!(varray = gpu_glMapBuffer(target, GL_WRITE_ONLY))) {
/* failed to map the buffer; delete it */
gpu_buffer_free_intern(buffer);
gpu_buffer_pool_delete_last(pool);
@@ -666,10 +674,10 @@ static GPUBuffer *gpu_buffer_setup(DerivedMesh *dm, GPUDrawObject *object,
/* glUnmapBuffer returns GL_FALSE if
* the data store is corrupted; retry
* in that case */
- uploaded = glUnmapBufferARB(target);
+ uploaded = gpu_glUnmapBuffer(target);
}
}
- glBindBufferARB(target, 0);
+ gpu_glBindBuffer(target, 0);
}
else {
/* VBO not supported, use vertex array fallback */
@@ -814,7 +822,7 @@ static void GPU_buffer_copy_uv(DerivedMesh *dm, float *varray, int *index, int *
if (!(mtface = DM_get_tessface_data_layer(dm, CD_MTFACE)))
return;
f = dm->getTessFaceArray(dm);
-
+
totface = dm->getNumTessFaces(dm);
for (i = 0; i < totface; i++, f++) {
start = index[mat_orig_to_new[f->mat_nr]];
@@ -935,12 +943,12 @@ typedef struct {
} GPUBufferTypeSettings;
const GPUBufferTypeSettings gpu_buffer_type_settings[] = {
- {GPU_buffer_copy_vertex, GL_ARRAY_BUFFER_ARB, 3},
- {GPU_buffer_copy_normal, GL_ARRAY_BUFFER_ARB, 3},
- {GPU_buffer_copy_mcol, GL_ARRAY_BUFFER_ARB, 3},
- {GPU_buffer_copy_uv, GL_ARRAY_BUFFER_ARB, 2},
- {GPU_buffer_copy_edge, GL_ELEMENT_ARRAY_BUFFER_ARB, 2},
- {GPU_buffer_copy_uvedge, GL_ELEMENT_ARRAY_BUFFER_ARB, 4}
+ {GPU_buffer_copy_vertex, GL_ARRAY_BUFFER, 3},
+ {GPU_buffer_copy_normal, GL_ARRAY_BUFFER, 3},
+ {GPU_buffer_copy_mcol, GL_ARRAY_BUFFER, 3},
+ {GPU_buffer_copy_uv, GL_ARRAY_BUFFER, 2},
+ {GPU_buffer_copy_edge, GL_ELEMENT_ARRAY_BUFFER, 2},
+ {GPU_buffer_copy_uvedge, GL_ELEMENT_ARRAY_BUFFER, 4},
};
/* get the GPUDrawObject buffer associated with a type */
@@ -1039,13 +1047,13 @@ void GPU_vertex_setup(DerivedMesh *dm)
glEnableClientState(GL_VERTEX_ARRAY);
if (useVBOs) {
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, dm->drawObject->points->id);
+ gpu_glBindBuffer(GL_ARRAY_BUFFER, dm->drawObject->points->id);
glVertexPointer(3, GL_FLOAT, 0, 0);
}
else {
glVertexPointer(3, GL_FLOAT, 0, dm->drawObject->points->pointer);
}
-
+
GLStates |= GPU_BUFFER_VERTEX_STATE;
}
@@ -1056,7 +1064,7 @@ void GPU_normal_setup(DerivedMesh *dm)
glEnableClientState(GL_NORMAL_ARRAY);
if (useVBOs) {
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, dm->drawObject->normals->id);
+ gpu_glBindBuffer(GL_ARRAY_BUFFER, dm->drawObject->normals->id);
glNormalPointer(GL_FLOAT, 0, 0);
}
else {
@@ -1073,7 +1081,7 @@ void GPU_uv_setup(DerivedMesh *dm)
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
if (useVBOs) {
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, dm->drawObject->uv->id);
+ gpu_glBindBuffer(GL_ARRAY_BUFFER, dm->drawObject->uv->id);
glTexCoordPointer(2, GL_FLOAT, 0, 0);
}
else {
@@ -1110,7 +1118,7 @@ void GPU_color_setup(DerivedMesh *dm, int colType)
glEnableClientState(GL_COLOR_ARRAY);
if (useVBOs) {
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, dm->drawObject->colors->id);
+ gpu_glBindBuffer(GL_ARRAY_BUFFER, dm->drawObject->colors->id);
glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0);
}
else {
@@ -1130,17 +1138,17 @@ void GPU_edge_setup(DerivedMesh *dm)
glEnableClientState(GL_VERTEX_ARRAY);
if (useVBOs) {
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, dm->drawObject->points->id);
+ gpu_glBindBuffer(GL_ARRAY_BUFFER, dm->drawObject->points->id);
glVertexPointer(3, GL_FLOAT, 0, 0);
}
else {
glVertexPointer(3, GL_FLOAT, 0, dm->drawObject->points->pointer);
}
-
+
GLStates |= GPU_BUFFER_VERTEX_STATE;
if (useVBOs)
- glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, dm->drawObject->edges->id);
+ gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dm->drawObject->edges->id);
GLStates |= GPU_BUFFER_ELEMENT_STATE;
}
@@ -1152,7 +1160,7 @@ void GPU_uvedge_setup(DerivedMesh *dm)
glEnableClientState(GL_VERTEX_ARRAY);
if (useVBOs) {
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, dm->drawObject->uvedges->id);
+ gpu_glBindBuffer(GL_ARRAY_BUFFER, dm->drawObject->uvedges->id);
glVertexPointer(2, GL_FLOAT, 0, 0);
}
else {
@@ -1200,7 +1208,7 @@ void GPU_interleaved_attrib_setup(GPUBuffer *buffer, GPUAttrib data[], int numda
for (i = 0; i < MAX_GPU_ATTRIB_DATA; i++) {
if (attribData[i].index != -1) {
- glDisableVertexAttribArrayARB(attribData[i].index);
+ gpu_glDisableVertexAttribArray(attribData[i].index);
}
else
break;
@@ -1208,10 +1216,10 @@ void GPU_interleaved_attrib_setup(GPUBuffer *buffer, GPUAttrib data[], int numda
elementsize = GPU_attrib_element_size(data, numdata);
if (useVBOs) {
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer->id);
+ gpu_glBindBuffer(GL_ARRAY_BUFFER, buffer->id);
for (i = 0; i < numdata; i++) {
- glEnableVertexAttribArrayARB(data[i].index);
- glVertexAttribPointerARB(data[i].index, data[i].size, data[i].type,
+ gpu_glEnableVertexAttribArray(data[i].index);
+ gpu_glVertexAttribPointer(data[i].index, data[i].size, data[i].type,
GL_FALSE, elementsize, (void *)offset);
offset += data[i].size * GPU_typesize(data[i].type);
@@ -1223,8 +1231,8 @@ void GPU_interleaved_attrib_setup(GPUBuffer *buffer, GPUAttrib data[], int numda
}
else {
for (i = 0; i < numdata; i++) {
- glEnableVertexAttribArrayARB(data[i].index);
- glVertexAttribPointerARB(data[i].index, data[i].size, data[i].type,
+ gpu_glEnableVertexAttribArray(data[i].index);
+ gpu_glVertexAttribPointer(data[i].index, data[i].size, data[i].type,
GL_FALSE, elementsize, (char *)buffer->pointer + offset);
offset += data[i].size * GPU_typesize(data[i].type);
}
@@ -1246,7 +1254,7 @@ void GPU_buffer_unbind(void)
glDisableClientState(GL_COLOR_ARRAY);
if (GLStates & GPU_BUFFER_ELEMENT_STATE) {
if (useVBOs) {
- glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
+ gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
}
GLStates &= ~(GPU_BUFFER_VERTEX_STATE | GPU_BUFFER_NORMAL_STATE |
@@ -1255,14 +1263,14 @@ void GPU_buffer_unbind(void)
for (i = 0; i < MAX_GPU_ATTRIB_DATA; i++) {
if (attribData[i].index != -1) {
- glDisableVertexAttribArrayARB(attribData[i].index);
+ gpu_glDisableVertexAttribArray(attribData[i].index);
}
else
break;
}
if (useVBOs)
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
+ gpu_glBindBuffer(GL_ARRAY_BUFFER, 0);
}
void GPU_color_switch(int mode)
@@ -1300,8 +1308,8 @@ void *GPU_buffer_lock(GPUBuffer *buffer)
return 0;
if (useVBOs) {
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer->id);
- varray = glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
+ gpu_glBindBuffer(GL_ARRAY_BUFFER, buffer->id);
+ varray = gpu_glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
return varray;
}
else {
@@ -1317,10 +1325,10 @@ void *GPU_buffer_lock_stream(GPUBuffer *buffer)
return 0;
if (useVBOs) {
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer->id);
+ gpu_glBindBuffer(GL_ARRAY_BUFFER, buffer->id);
/* discard previous data, avoid stalling gpu */
- glBufferDataARB(GL_ARRAY_BUFFER_ARB, buffer->size, 0, GL_STREAM_DRAW_ARB);
- varray = glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
+ gpu_glBufferData(GL_ARRAY_BUFFER, buffer->size, 0, GL_STREAM_DRAW);
+ varray = gpu_glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
return varray;
}
else {
@@ -1334,9 +1342,9 @@ void GPU_buffer_unlock(GPUBuffer *buffer)
if (buffer) {
/* note: this operation can fail, could return
* an error code from this function? */
- glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
+ gpu_glUnmapBuffer(GL_ARRAY_BUFFER);
}
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
+ gpu_glBindBuffer(GL_ARRAY_BUFFER, 0);
}
}
@@ -1511,12 +1519,12 @@ void GPU_update_mesh_pbvh_buffers(GPU_PBVH_Buffers *buffers, MVert *mvert,
copy_v4_v4(buffers->diffuse_color, diffuse_color);
/* Build VBO */
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->vert_buf);
- glBufferDataARB(GL_ARRAY_BUFFER_ARB,
+ gpu_glBindBuffer(GL_ARRAY_BUFFER, buffers->vert_buf);
+ gpu_glBufferData(GL_ARRAY_BUFFER,
sizeof(VertexBufferFormat) * totelem,
- NULL, GL_STATIC_DRAW_ARB);
+ NULL, GL_STATIC_DRAW);
- vert_data = glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
+ vert_data = gpu_glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
if (vert_data) {
/* Vertex data is shared if smooth-shaded, but separate
@@ -1610,14 +1618,14 @@ void GPU_update_mesh_pbvh_buffers(GPU_PBVH_Buffers *buffers, MVert *mvert,
}
}
- glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
+ gpu_glUnmapBuffer(GL_ARRAY_BUFFER);
}
else {
- glDeleteBuffersARB(1, &buffers->vert_buf);
+ gpu_glDeleteBuffers(1, &buffers->vert_buf);
buffers->vert_buf = 0;
}
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
+ gpu_glBindBuffer(GL_ARRAY_BUFFER, 0);
}
buffers->mvert = mvert;
@@ -1660,16 +1668,16 @@ GPU_PBVH_Buffers *GPU_build_mesh_pbvh_buffers(int (*face_vert_indices)[4],
* shading requires separate vertex normals so an index buffer is
* can't be used there. */
if (gpu_vbo_enabled() && buffers->smooth)
- glGenBuffersARB(1, &buffers->index_buf);
+ gpu_glGenBuffers(1, &buffers->index_buf);
if (buffers->index_buf) {
/* Generate index buffer object */
- glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, buffers->index_buf);
- glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
- sizeof(unsigned short) * tottri * 3, NULL, GL_STATIC_DRAW_ARB);
+ gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers->index_buf);
+ gpu_glBufferData(GL_ELEMENT_ARRAY_BUFFER,
+ sizeof(unsigned short) * tottri * 3, NULL, GL_STATIC_DRAW);
/* Fill the triangle buffer */
- tri_data = glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
+ tri_data = gpu_glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
if (tri_data) {
for (i = 0; i < totface; ++i) {
const MFace *f = mface + face_indices[i];
@@ -1693,18 +1701,18 @@ GPU_PBVH_Buffers *GPU_build_mesh_pbvh_buffers(int (*face_vert_indices)[4],
v[2] = 2;
}
}
- glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB);
+ gpu_glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
}
else {
- glDeleteBuffersARB(1, &buffers->index_buf);
+ gpu_glDeleteBuffers(1, &buffers->index_buf);
buffers->index_buf = 0;
}
- glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
+ gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
if (gpu_vbo_enabled() && (buffers->index_buf || !buffers->smooth))
- glGenBuffersARB(1, &buffers->vert_buf);
+ gpu_glGenBuffers(1, &buffers->vert_buf);
buffers->tot_tri = tottri;
@@ -1742,11 +1750,11 @@ void GPU_update_grid_pbvh_buffers(GPU_PBVH_Buffers *buffers, CCGElem **grids,
copy_v4_v4(buffers->diffuse_color, diffuse_color);
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->vert_buf);
- glBufferDataARB(GL_ARRAY_BUFFER_ARB,
+ gpu_glBindBuffer(GL_ARRAY_BUFFER, buffers->vert_buf);
+ gpu_glBufferData(GL_ARRAY_BUFFER,
sizeof(VertexBufferFormat) * totvert,
- NULL, GL_STATIC_DRAW_ARB);
- vert_data = glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
+ NULL, GL_STATIC_DRAW);
+ vert_data = gpu_glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
if (vert_data) {
for (i = 0; i < totgrid; ++i) {
VertexBufferFormat *vd = vert_data;
@@ -1807,13 +1815,13 @@ void GPU_update_grid_pbvh_buffers(GPU_PBVH_Buffers *buffers, CCGElem **grids,
vert_data += key->grid_area;
}
- glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
+ gpu_glUnmapBuffer(GL_ARRAY_BUFFER);
}
else {
- glDeleteBuffersARB(1, &buffers->vert_buf);
+ gpu_glDeleteBuffers(1, &buffers->vert_buf);
buffers->vert_buf = 0;
}
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
+ gpu_glBindBuffer(GL_ARRAY_BUFFER, 0);
}
buffers->grids = grids;
@@ -1835,13 +1843,13 @@ void GPU_update_grid_pbvh_buffers(GPU_PBVH_Buffers *buffers, CCGElem **grids,
int offset = 0; \
int i, j, k; \
\
- glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, \
+ gpu_glBufferData(GL_ELEMENT_ARRAY_BUFFER, \
sizeof(type_) * (tot_quad_) * 6, NULL, \
- GL_STATIC_DRAW_ARB); \
+ GL_STATIC_DRAW); \
\
/* Fill the buffer */ \
- tri_data = glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, \
- GL_WRITE_ONLY_ARB); \
+ tri_data = gpu_glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, \
+ GL_WRITE_ONLY); \
if (tri_data) { \
for (i = 0; i < totgrid; ++i) { \
BLI_bitmap *gh = NULL; \
@@ -1868,10 +1876,10 @@ void GPU_update_grid_pbvh_buffers(GPU_PBVH_Buffers *buffers, CCGElem **grids,
\
offset += gridsize * gridsize; \
} \
- glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB); \
+ gpu_glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER); \
} \
else { \
- glDeleteBuffersARB(1, &(buffer_)); \
+ gpu_glDeleteBuffers(1, &(buffer_)); \
(buffer_) = 0; \
} \
} (void)0
@@ -1893,7 +1901,7 @@ static GLuint gpu_get_grid_buffer(int gridsize, GLenum *index_type, unsigned *to
* return an invalid handle */
if (!gpu_vbo_enabled()) {
if (buffer)
- glDeleteBuffersARB(1, &buffer);
+ gpu_glDeleteBuffers(1, &buffer);
return 0;
}
@@ -1905,11 +1913,11 @@ static GLuint gpu_get_grid_buffer(int gridsize, GLenum *index_type, unsigned *to
}
/* Build new VBO */
- glGenBuffersARB(1, &buffer);
+ gpu_glGenBuffers(1, &buffer);
if (buffer) {
*totquad = (gridsize - 1) * (gridsize - 1);
- glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, buffer);
+ gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer);
if (gridsize * gridsize < USHRT_MAX) {
*index_type = GL_UNSIGNED_SHORT;
@@ -1920,7 +1928,7 @@ static GLuint gpu_get_grid_buffer(int gridsize, GLenum *index_type, unsigned *to
FILL_QUAD_BUFFER(unsigned int, *totquad, buffer);
}
- glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
+ gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
prev_gridsize = gridsize;
@@ -1956,11 +1964,11 @@ GPU_PBVH_Buffers *GPU_build_grid_pbvh_buffers(int *grid_indices, int totgrid,
}
else if (GLEW_ARB_vertex_buffer_object && !(U.gameflags & USER_DISABLE_VBO)) {
/* Build new VBO */
- glGenBuffersARB(1, &buffers->index_buf);
+ gpu_glGenBuffers(1, &buffers->index_buf);
if (buffers->index_buf) {
buffers->tot_quad = totquad;
- glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, buffers->index_buf);
+ gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers->index_buf);
if (totgrid * gridsize * gridsize < USHRT_MAX) {
buffers->index_type = GL_UNSIGNED_SHORT;
@@ -1971,7 +1979,7 @@ GPU_PBVH_Buffers *GPU_build_grid_pbvh_buffers(int *grid_indices, int totgrid,
FILL_QUAD_BUFFER(unsigned int, totquad, buffers->index_buf);
}
- glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
+ gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
buffers->has_hidden = 1;
@@ -1979,7 +1987,7 @@ GPU_PBVH_Buffers *GPU_build_grid_pbvh_buffers(int *grid_indices, int totgrid,
/* Build coord/normal VBO */
if (buffers->index_buf)
- glGenBuffersARB(1, &buffers->vert_buf);
+ gpu_glGenBuffers(1, &buffers->vert_buf);
return buffers;
}
@@ -2111,13 +2119,13 @@ void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers,
copy_v4_v4(buffers->diffuse_color, diffuse_color);
/* Initialize vertex buffer */
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->vert_buf);
- glBufferDataARB(GL_ARRAY_BUFFER_ARB,
+ gpu_glBindBuffer(GL_ARRAY_BUFFER, buffers->vert_buf);
+ gpu_glBufferData(GL_ARRAY_BUFFER,
sizeof(VertexBufferFormat) * totvert,
- NULL, GL_STATIC_DRAW_ARB);
+ NULL, GL_STATIC_DRAW);
/* Fill vertex buffer */
- vert_data = glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
+ vert_data = gpu_glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
if (vert_data) {
int v_index = 0;
@@ -2175,14 +2183,14 @@ void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers,
buffers->tot_tri = tottri;
}
- glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
+ gpu_glUnmapBuffer(GL_ARRAY_BUFFER);
/* gpu_bmesh_vert_to_buffer_copy sets dirty index values */
bm->elem_index_dirty |= BM_VERT;
}
else {
/* Memory map failed */
- glDeleteBuffersARB(1, &buffers->vert_buf);
+ gpu_glDeleteBuffers(1, &buffers->vert_buf);
buffers->vert_buf = 0;
return;
}
@@ -2191,15 +2199,15 @@ void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers,
const int use_short = (maxvert < USHRT_MAX);
/* Initialize triangle index buffer */
- glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, buffers->index_buf);
- glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
+ gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers->index_buf);
+ gpu_glBufferData(GL_ELEMENT_ARRAY_BUFFER,
(use_short ?
sizeof(unsigned short) :
sizeof(unsigned int)) * 3 * tottri,
- NULL, GL_STATIC_DRAW_ARB);
+ NULL, GL_STATIC_DRAW);
/* Fill triangle index buffer */
- tri_data = glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
+ tri_data = gpu_glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
if (tri_data) {
GSetIterator gs_iter;
@@ -2229,7 +2237,7 @@ void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers,
}
}
- glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB);
+ gpu_glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
buffers->tot_tri = tottri;
buffers->index_type = (use_short ?
@@ -2238,7 +2246,7 @@ void GPU_update_bmesh_pbvh_buffers(GPU_PBVH_Buffers *buffers,
}
else {
/* Memory map failed */
- glDeleteBuffersARB(1, &buffers->index_buf);
+ gpu_glDeleteBuffers(1, &buffers->index_buf);
buffers->index_buf = 0;
}
}
@@ -2250,8 +2258,8 @@ GPU_PBVH_Buffers *GPU_build_bmesh_pbvh_buffers(int smooth_shading)
buffers = MEM_callocN(sizeof(GPU_PBVH_Buffers), "GPU_Buffers");
if (smooth_shading)
- glGenBuffersARB(1, &buffers->index_buf);
- glGenBuffersARB(1, &buffers->vert_buf);
+ gpu_glGenBuffers(1, &buffers->index_buf);
+ gpu_glGenBuffers(1, &buffers->vert_buf);
buffers->use_bmesh = true;
buffers->smooth = smooth_shading;
buffers->show_diffuse_color = false;
@@ -2321,7 +2329,7 @@ static void gpu_draw_buffers_legacy_mesh(GPU_PBVH_Buffers *buffers)
fmask /= 3.0f;
gpu_color_from_mask_set(fmask, diffuse_color);
}
-
+
for (j = 0; j < S; j++)
glVertex3fv(mvert[fv[j]].co);
}
@@ -2359,8 +2367,8 @@ static void gpu_draw_buffers_legacy_grids(GPU_PBVH_Buffers *buffers)
/* TODO: could use strips with hiding as well */
if (gh) {
- glBegin(GL_QUADS);
-
+ glBegin(GL_QUADS); // XXX jwilkins: replace with pairs of triangles
+
for (y = 0; y < gridsize - 1; y++) {
for (x = 0; x < gridsize - 1; x++) {
CCGElem *e[4] = {
@@ -2406,7 +2414,7 @@ static void gpu_draw_buffers_legacy_grids(GPU_PBVH_Buffers *buffers)
}
else if (buffers->smooth) {
for (y = 0; y < gridsize - 1; y++) {
- glBegin(GL_QUAD_STRIP);
+ glBegin(GL_TRIANGLE_STRIP); // XXX jwilkins: was QUAD_STRIP, only difference should be which vertex is used for flat shading(?)
for (x = 0; x < gridsize; x++) {
CCGElem *a = CCG_grid_elem(key, grid, x, y);
CCGElem *b = CCG_grid_elem(key, grid, x, y + 1);
@@ -2427,7 +2435,7 @@ static void gpu_draw_buffers_legacy_grids(GPU_PBVH_Buffers *buffers)
}
else {
for (y = 0; y < gridsize - 1; y++) {
- glBegin(GL_QUAD_STRIP);
+ glBegin(GL_TRIANGLE_STRIP); // XXX jwilkins: was QUAD_STRIP, only difference should be which vertex is used for flat shading(?)
for (x = 0; x < gridsize; x++) {
CCGElem *a = CCG_grid_elem(key, grid, x, y);
CCGElem *b = CCG_grid_elem(key, grid, x, y + 1);
@@ -2493,10 +2501,10 @@ void GPU_draw_pbvh_buffers(GPU_PBVH_Buffers *buffers, DMSetMaterial setMaterial,
gpu_colors_enable(VBO_ENABLED);
}
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->vert_buf);
+ gpu_glBindBuffer(GL_ARRAY_BUFFER, buffers->vert_buf);
if (buffers->index_buf)
- glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, buffers->index_buf);
+ gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers->index_buf);
if (wireframe)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
@@ -2536,9 +2544,9 @@ void GPU_draw_pbvh_buffers(GPU_PBVH_Buffers *buffers, DMSetMaterial setMaterial,
if (wireframe)
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
+ gpu_glBindBuffer(GL_ARRAY_BUFFER, 0);
if (buffers->index_buf)
- glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
+ gpu_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glDisableClientState(GL_VERTEX_ARRAY);
if (!wireframe) {
@@ -2609,10 +2617,10 @@ static void gpu_pbvh_buffer_free_intern(GLuint id)
/* free the buffers immediately if we are on main thread */
if (BLI_thread_is_main()) {
- glDeleteBuffersARB(1, &id);
+ gpu_glDeleteBuffers(1, &id);
if (pool->totpbvhbufids > 0) {
- glDeleteBuffersARB(pool->totpbvhbufids, pool->pbvhbufids);
+ gpu_glDeleteBuffers(pool->totpbvhbufids, pool->pbvhbufids);
pool->totpbvhbufids = 0;
}
return;
@@ -2695,7 +2703,7 @@ void GPU_init_draw_pbvh_BB(void)
glDisable(GL_LIGHTING);
glDisable(GL_COLOR_MATERIAL);
glEnable(GL_BLEND);
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
+ gpu_glBindBuffer(GL_ARRAY_BUFFER, 0);
}
void GPU_end_draw_pbvh_BB(void)
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c
index 359f23b6631..0440215c774 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -1413,7 +1413,7 @@ GPUPass *GPU_generate_pass(ListBase *nodes, GPUNodeLink *outlink, GPUVertexAttri
/* generate code and compile with opengl */
fragmentcode = code_generate_fragment(nodes, outlink->output, name);
vertexcode = code_generate_vertex(nodes);
- shader = GPU_shader_create(vertexcode, fragmentcode, glsl_material_library, NULL);
+ shader = GPU_shader_create(__func__, vertexcode, fragmentcode, glsl_material_library, NULL);
/* failed? */
if (!shader) {
@@ -1424,7 +1424,7 @@ GPUPass *GPU_generate_pass(ListBase *nodes, GPUNodeLink *outlink, GPUVertexAttri
}
/* create pass */
- pass = (GPUPass*)MEM_callocN(sizeof(GPUPass), "GPUPass");
+ pass = (GPUPass*)MEM_callocN(sizeof(GPUPass), __func__);
pass->output = outlink->output;
pass->shader = shader;
diff --git a/source/blender/gpu/intern/gpu_common.c b/source/blender/gpu/intern/gpu_common.c
index eeecd2024b8..338c5eee133 100644
--- a/source/blender/gpu/intern/gpu_common.c
+++ b/source/blender/gpu/intern/gpu_common.c
@@ -119,9 +119,9 @@ void gpu_common_get_symbols(GPUcommon* common, GPUShader* gpushader)
int i;
/* Attributes */
- common->vertex = GPU_shader_get_attrib(gpushader, "b_Vertex");
- common->color = GPU_shader_get_attrib(gpushader, "b_Color");
- common->normal = GPU_shader_get_attrib(gpushader, "b_Normal");
+ common->vertex = GPU_shader_get_attribute(gpushader, "b_Vertex");
+ common->color = GPU_shader_get_attribute(gpushader, "b_Color");
+ common->normal = GPU_shader_get_attribute(gpushader, "b_Normal");
/* Transformation */
common->modelview_matrix = GPU_shader_get_uniform(gpushader, "b_ModelViewMatrix");
@@ -135,7 +135,7 @@ void gpu_common_get_symbols(GPUcommon* common, GPUShader* gpushader)
char symbol[100];
sprintf(symbol, "b_MultiTexCoord%d", i);
- common->multi_texcoord[i] = GPU_shader_get_attrib(gpushader, symbol);
+ common->multi_texcoord[i] = GPU_shader_get_attribute(gpushader, symbol);
sprintf(symbol, "b_TextureMatrix[%d]", i);
common->texture_matrix[i] = GPU_shader_get_uniform(gpushader, symbol);
diff --git a/source/blender/gpu/intern/gpu_common_intern.h b/source/blender/gpu/intern/gpu_common_intern.h
index 26e17ddab6a..3f42c491ccf 100644
--- a/source/blender/gpu/intern/gpu_common_intern.h
+++ b/source/blender/gpu/intern/gpu_common_intern.h
@@ -49,11 +49,11 @@ struct DynStr;
/* GPUShader */
struct GPUShader {
- unsigned int object; /* handle for full shader */
- unsigned int vertex; /* handle for vertex shader */
- unsigned int fragment; /* handle for fragment shader */
- unsigned int lib; /* handle for library shader */
- int totattrib; /* total number of attributes */
+ GLuint object; /* handle for full shader */
+ GLuint vertex; /* handle for vertex shader */
+ GLuint fragment; /* handle for fragment shader */
+ GLuint lib; /* handle for library shader */
+ int totattrib; /* total number of attributes */
};
diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c
index 294124f1be5..30d593a514a 100644
--- a/source/blender/gpu/intern/gpu_draw.c
+++ b/source/blender/gpu/intern/gpu_draw.c
@@ -36,7 +36,28 @@
* and abstract them away from the rest a bit.
*/
-#include <string.h>
+/* my interface */
+#include "GPU_draw.h"
+
+/* internal */
+#include "intern/gpu_profile.h"
+#include "intern/gpu_extensions_intern.h"
+//#include "intern/gpu_raster_intern.h"
+
+/* my library */
+//#include "GPU_colors.h"
+//#include "GPU_common.h"
+#include "GPU_buffers.h"
+#include "GPU_extensions.h"
+//#include "GPU_lighting.h"
+#include "GPU_material.h"
+//#include "GPU_basic.h"
+//#include "GPU_immediate.h"
+//#include "GPU_matrix.h"
+//#include "GPU_state_latch.h"
+//#include "GPU_blender_aspect.h"
+
+/* external */
#include "BLI_blenlib.h"
#include "BLI_linklist.h"
@@ -69,16 +90,15 @@
#include "BKE_scene.h"
#include "BKE_DerivedMesh.h"
-#include "GPU_buffers.h"
-#include "GPU_draw.h"
-#include "GPU_extensions.h"
-#include "GPU_glew.h"
-#include "GPU_material.h"
-
#include "PIL_time.h"
#include "smoke_API.h"
+/* standard */
+
+#include <string.h>
+
+
extern Material defmaterial; /* from material.c */
/* Text Rendering */
@@ -260,25 +280,6 @@ void GPU_set_gpu_mipmapping(int gpu_mipmap)
}
}
-static void gpu_generate_mipmap(GLenum target)
-{
- const bool is_ati = GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY);
- int target_enabled = 0;
-
- /* work around bug in ATI driver, need to have GL_TEXTURE_2D enabled
- * http://www.opengl.org/wiki/Common_Mistakes#Automatic_mipmap_generation */
- if (is_ati) {
- target_enabled = glIsEnabled(target);
- if (!target_enabled)
- glEnable(target);
- }
-
- glGenerateMipmapEXT(target);
-
- if (is_ati && !target_enabled)
- glDisable(target);
-}
-
void GPU_set_mipmap(int mipmap)
{
if (GTS.domipmap != (mipmap != 0)) {
@@ -733,7 +734,7 @@ void GPU_create_gl_tex(unsigned int *bind, unsigned int *pix, float *frect, int
else
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, rectw, recth, 0, GL_RGBA, GL_UNSIGNED_BYTE, pix);
- gpu_generate_mipmap(GL_TEXTURE_2D);
+ gpu_glGenerateMipmap(GL_TEXTURE_2D);
}
else {
if (use_high_bit_depth)
@@ -1005,7 +1006,7 @@ static bool GPU_check_scaled_image(ImBuf *ibuf, Image *ima, float *frect, int x,
}
if (GPU_get_mipmap()) {
- gpu_generate_mipmap(GL_TEXTURE_2D);
+ gpu_glGenerateMipmap(GL_TEXTURE_2D);
}
else {
ima->tpageflag &= ~IMA_MIPMAP_COMPLETE;
@@ -1062,7 +1063,7 @@ void GPU_paint_update_image(Image *ima, int x, int y, int w, int h)
/* we have already accounted for the case where GTS.gpu_mipmap is false
* so we will be using GPU mipmap generation here */
if (GPU_get_mipmap()) {
- gpu_generate_mipmap(GL_TEXTURE_2D);
+ gpu_glGenerateMipmap(GL_TEXTURE_2D);
}
else {
ima->tpageflag &= ~IMA_MIPMAP_COMPLETE;
@@ -1095,7 +1096,7 @@ void GPU_paint_update_image(Image *ima, int x, int y, int w, int h)
/* see comment above as to why we are using gpu mipmap generation here */
if (GPU_get_mipmap()) {
- gpu_generate_mipmap(GL_TEXTURE_2D);
+ gpu_glGenerateMipmap(GL_TEXTURE_2D);
}
else {
ima->tpageflag &= ~IMA_MIPMAP_COMPLETE;
@@ -1889,14 +1890,14 @@ void GPU_state_init(void)
int a, x, y;
GLubyte pat[32*32];
const GLubyte *patc= pat;
-
+
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_specular);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 35);
GPU_default_lights();
-
+
glDepthFunc(GL_LEQUAL);
/* scaling matrices */
glEnable(GL_NORMALIZE);
@@ -1940,7 +1941,7 @@ void GPU_state_init(void)
else pat[a++]= 0x22;
}
}
-
+
glPolygonStipple(patc);
glMatrixMode(GL_TEXTURE);
@@ -1951,7 +1952,26 @@ void GPU_state_init(void)
glCullFace(GL_BACK);
glDisable(GL_CULL_FACE);
- /* calling this makes drawing very slow when AA is not set up in ghost
- * on Linux/NVIDIA. */
- // glDisable(GL_MULTISAMPLE);
+ /* MULTISAMPLE is enabled by GL by default, but Blender needs to disable it by default
+ it will be enabled only by drawing code that needs it
+ apparently however, doing that makes drawing very slow when AA is not set up in GHOST on Linux/NVIDIA
+ so, let's check for that and leave it enabled in that case */
+ if (GLEW_VERSION_1_3 || GLEW_ARB_multisample) {
+ bool disable_ok = true;
+
+ if (GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_UNIX, GPU_DRIVER_ANY)) {
+ int samples = 0;
+ glGetIntegerv(GL_SAMPLES, &samples);
+
+ if (samples == 0)
+ disable_ok = false; // AA not set up, so it isn't OK to disable
+ }
+
+ if (disable_ok)
+ glDisable(GL_MULTISAMPLE);
+ }
+
+ /* make sure double side isn't used by default and only getting enabled in places where it's
+ * really needed to prevent different unexpected behaviors like with intel gme965 card (sergey) */
+ glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
}
diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c
index e16f2f46466..217baba5d69 100644
--- a/source/blender/gpu/intern/gpu_extensions.c
+++ b/source/blender/gpu/intern/gpu_extensions.c
@@ -20,7 +20,7 @@
*
* The Original Code is: all of this file.
*
- * Contributor(s): Brecht Van Lommel.
+ * Contributor(s): Brecht Van Lommel, Jason Wilkins.
*
* ***** END GPL LICENSE BLOCK *****
*/
@@ -32,30 +32,52 @@
* with checks for drivers and GPU support.
*/
+#define GPU_MANGLE_DEPRECATED 0
-#include "DNA_image_types.h"
+/* my interface */
+#define GPU_FUNC_INTERN
+#include "intern/gpu_extensions_intern.h"
+
+/* internal */
+#include "intern/gpu_codegen.h"
+#include "intern/gpu_profile.h"
+#include "intern/gpu_common_intern.h"
-#include "MEM_guardedalloc.h"
+/* my library */
+//#include "GPU_basic.h"
+#include "GPU_draw.h"
+//#include "GPU_font.h"
+//#include "GPU_pixels.h"
+//#include "GPU_raster.h"
+#include "GPU_safety.h"
+//#include "GPU_matrix.h"
+//#include "GPU_aspect.h"
+//#include "GPU_blender_aspect.h"
+//#include "GPU_immediate.h"
+#include "GPU_utility.h"
+//#include "GPU_state_latch.h"
+
+/* external */
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
#include "BLI_math_base.h"
+#ifdef WIN32
+#include "BLI_winstuff.h"
+#endif
+
#include "BKE_global.h"
-#include "GPU_draw.h"
-#include "GPU_extensions.h"
-#include "GPU_glew.h"
+#include "DNA_image_types.h"
-#include "gpu_codegen.h"
+#include "MEM_guardedalloc.h"
+/* standard*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#ifdef WIN32
-# include "BLI_winstuff.h"
-#endif
/* Extensions support */
@@ -84,11 +106,12 @@ static struct GPUGlobal {
GLint maxtexsize;
GLint maxtextures;
GLuint currentfb;
- int glslsupport;
- int extdisabled;
- int colordepth;
- int npotdisabled; /* ATI 3xx-5xx (and more) chipsets support NPoT partially (== not enough) */
- int dlistsdisabled; /* Legacy ATI driver does not support display lists well */
+ GLboolean glslsupport;
+ GLboolean framebuffersupport;
+ GLboolean extdisabled;
+ GLint colordepth;
+ GLboolean npotdisabled; /* ATI 3xx-5xx (and more) chipsets support NPoT partially (== not enough) */
+ GLboolean dlistsdisabled; /* Legacy ATI driver does not support display lists well */
GPUDeviceType device;
GPUOSType os;
GPUDriverType driver;
@@ -96,7 +119,7 @@ static struct GPUGlobal {
GPUTexture *invalid_tex_1D; /* texture used in place of invalid textures (not loaded correctly, missing) */
GPUTexture *invalid_tex_2D;
GPUTexture *invalid_tex_3D;
-} GG = {1, 0};
+} GG;
/* GPU Types */
@@ -109,7 +132,7 @@ int GPU_type_matches(GPUDeviceType device, GPUOSType os, GPUDriverType driver)
void GPU_extensions_disable(void)
{
- GG.extdisabled = 1;
+ GG.extdisabled = GL_TRUE;
}
int GPU_max_texture_size(void)
@@ -117,31 +140,73 @@ int GPU_max_texture_size(void)
return GG.maxtexsize;
}
+
+/*
+Computes the maximum number of textures 'n' that
+can be referenced by ActiveTexture(TEXTURE0+n-1)
+
+This is for any use of ActiveTexture.
+
+Individual limits, such as for the multitexture extension, gl_TexCoord,
+vertex shaders, fragment shader, etc. will each have different limits.
+*/
+static GLint get_max_textures(void)
+{
+ GLint maxTextureUnits;
+ GLint maxTextureCoords;
+ GLint maxCombinedTextureImageUnits;
+
+ /* There has to be at least one texture so count that here */
+ maxTextureUnits = 1;
+
+#if !defined(GLEW_ES_ONLY)
+ if (GPU_PROFILE_COMPAT && (GLEW_VERSION_1_3 || GLEW_ARB_multitexture)) {
+ /* Multitexture typically supports only 2 or 4 texture stages even on modern hardware. */
+ glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxTextureUnits);
+ }
+#endif
+
+ /* Set to zero here in case they do not get set later */
+ maxTextureCoords = 0;
+ maxCombinedTextureImageUnits = 0;
+
+ if (GLEW_VERSION_2_0 || GLEW_ES_VERSION_2_0 || GLEW_ARB_fragment_program) {
+#if !defined(GLEW_ES_ONLY)
+ if (GPU_PROFILE_COMPAT) {
+ /* size of gl_TexCoord array in GLSL */
+ glGetIntegerv(GL_MAX_TEXTURE_COORDS, &maxTextureCoords);
+ }
+#endif
+
+ /* Number of textures accessible by vertex, fragment, and geometry shaders combined. */
+ /* Individually the limits for each of those programmable units may be smaller. */
+ glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxCombinedTextureImageUnits);
+ }
+
+ return MAX3(maxTextureUnits, maxTextureCoords, maxCombinedTextureImageUnits);
+}
+
+int GPU_max_textures(void)
+{
+ return GG.maxtextures;
+}
+
+static void shim_init(void);
+
void gpu_extensions_init(void)
{
GLint r, g, b;
const char *vendor, *renderer;
- gpu_codegen_init();
+ GPU_CHECK_NO_ERROR();
- /* glewIsSupported("GL_VERSION_2_0") */
+ shim_init();
- if (GLEW_ARB_multitexture)
- glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &GG.maxtextures);
+ GG.maxtextures = get_max_textures();
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &GG.maxtexsize);
- GG.glslsupport = 1;
- if (!GLEW_ARB_multitexture) GG.glslsupport = 0;
- if (!GLEW_ARB_vertex_shader) GG.glslsupport = 0;
- if (!GLEW_ARB_fragment_shader) GG.glslsupport = 0;
-
- glGetIntegerv(GL_RED_BITS, &r);
- glGetIntegerv(GL_GREEN_BITS, &g);
- glGetIntegerv(GL_BLUE_BITS, &b);
- GG.colordepth = r+g+b; /* assumes same depth for RGB */
-
- vendor = (const char *)glGetString(GL_VENDOR);
+ vendor = (const char *)glGetString(GL_VENDOR);
renderer = (const char *)glGetString(GL_RENDERER);
if (strstr(vendor, "ATI")) {
@@ -192,24 +257,20 @@ void gpu_extensions_init(void)
/* This list is close enough to those using the legacy driver which
* has a bug with display lists and glVertexAttrib
*/
- if (strstr(renderer, "R3") || strstr(renderer, "RV3") ||
- strstr(renderer, "R4") || strstr(renderer, "RV4") ||
- strstr(renderer, "RS4") || strstr(renderer, "RC4") ||
- strstr(renderer, "R5") || strstr(renderer, "RV5") ||
- strstr(renderer, "RS600") || strstr(renderer, "RS690") ||
- strstr(renderer, "RS740") || strstr(renderer, "X1") ||
- strstr(renderer, "X2") || strstr(renderer, "Radeon 9") ||
+ if (strstr(renderer, "R3") || strstr(renderer, "RV3") ||
+ strstr(renderer, "R4") || strstr(renderer, "RV4") ||
+ strstr(renderer, "RS4") || strstr(renderer, "RC4") ||
+ strstr(renderer, "R5") || strstr(renderer, "RV5") ||
+ strstr(renderer, "RS600") || strstr(renderer, "RS690") ||
+ strstr(renderer, "RS740") || strstr(renderer, "X1") ||
+ strstr(renderer, "X2") || strstr(renderer, "Radeon 9") ||
strstr(renderer, "RADEON 9"))
{
- GG.npotdisabled = 1;
- GG.dlistsdisabled = 1;
+ GG.npotdisabled = GL_TRUE;
+ GG.dlistsdisabled = GL_TRUE;
}
}
- /* make sure double side isn't used by default and only getting enabled in places where it's
- * really needed to prevent different unexpected behaviors like with intel gme965 card (sergey) */
- glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
-
#ifdef _WIN32
GG.os = GPU_OS_WIN;
#elif defined(__APPLE__)
@@ -218,14 +279,39 @@ void gpu_extensions_init(void)
GG.os = GPU_OS_UNIX;
#endif
+ if (GPU_PROFILE_CORE) {
+#if defined(WITH_GL_PROFILE_CORE)
+ if (!GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY)) {
+ glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, GL_BACK, GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE, &r);
+ glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, GL_BACK, GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE, &g);
+ glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, GL_BACK, GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE, &b);
+ }
+ else {
+ r=g=b=8;// XXX jwilkins: above code seems like it should work but doesn't due to driver bug(?) will probably need to forward this from ghost
+ }
+#endif
+ }
+ else
+ {
+#if defined(WITH_GL_PROFILE_COMPAT) || defined(WITH_GL_PROFILE_ES20)
+ glGetIntegerv(GL_RED_BITS, &r);
+ glGetIntegerv(GL_GREEN_BITS, &g);
+ glGetIntegerv(GL_BLUE_BITS, &b);
+#endif
+ }
+
+ GG.colordepth = r+g+b; /* assumes same depth for RGB */
GPU_invalid_tex_init();
+
+ GPU_CHECK_NO_ERROR();
}
void gpu_extensions_exit(void)
{
- gpu_codegen_exit();
+ GPU_CHECK_NO_ERROR();
GPU_invalid_tex_free();
+ GPU_CHECK_NO_ERROR();
}
int GPU_glsl_support(void)
@@ -235,10 +321,7 @@ int GPU_glsl_support(void)
int GPU_non_power_of_two_support(void)
{
- if (GG.npotdisabled)
- return 0;
-
- return GLEW_ARB_texture_non_power_of_two;
+ return GG.npotdisabled ? 0 : GLEW_ARB_texture_non_power_of_two;
}
int GPU_display_list_support(void)
@@ -251,18 +334,18 @@ int GPU_color_depth(void)
return GG.colordepth;
}
-int GPU_print_error(const char *str)
+bool GPU_print_error(const char *str)
{
GLenum errCode;
if (G.debug & G_DEBUG) {
if ((errCode = glGetError()) != GL_NO_ERROR) {
- fprintf(stderr, "%s opengl error: %s\n", str, gluErrorString(errCode));
- return 1;
+ fprintf(stderr, "%s: OpenGL Error: %s\n", str, gpuErrorString(errCode));
+ return true;
}
}
- return 0;
+ return false;
}
static void GPU_print_framebuffer_error(GLenum status, char err_out[256])
@@ -270,30 +353,30 @@ static void GPU_print_framebuffer_error(GLenum status, char err_out[256])
const char *err= "unknown";
switch (status) {
- case GL_FRAMEBUFFER_COMPLETE_EXT:
+ case GL_FRAMEBUFFER_COMPLETE:
break;
case GL_INVALID_OPERATION:
err= "Invalid operation";
break;
- case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
+ case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
err= "Incomplete attachment";
break;
- case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
+ case GL_FRAMEBUFFER_UNSUPPORTED:
err= "Unsupported framebuffer format";
break;
- case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
+ case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
err= "Missing attachment";
break;
- case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
+ case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
err= "Attached images must have same dimensions";
break;
- case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
+ case GL_FRAMEBUFFER_INCOMPLETE_FORMATS:
err= "Attached images must have same format";
break;
- case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
+ case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
err= "Missing draw buffer";
break;
- case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
+ case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
err= "Missing read buffer";
break;
}
@@ -311,15 +394,21 @@ static void GPU_print_framebuffer_error(GLenum status, char err_out[256])
/* GPUTexture */
struct GPUTexture {
- int w, h; /* width/height */
- int number; /* number for multitexture binding */
- int refcount; /* reference count */
- GLenum target; /* GL_TEXTURE_* */
- GLuint bindcode; /* opengl identifier for texture */
- int fromblender; /* we got the texture from Blender */
-
- GPUFrameBuffer *fb; /* GPUFramebuffer this texture is attached to */
- int depth; /* is a depth texture? */
+ int w, h; // width/height
+ int number; // number for multitexture binding
+ int refcount; // reference count
+ GLenum target; // GL_TEXTURE_*
+ GLuint bindcode; // OpenGL identifier for texture
+ int fromblender; // we got the texture from Blender
+
+ GPUFrameBuffer *fb; // GPUFramebuffer this texture is attached to
+ int depth; // is a depth texture?
+
+#if !defined(GLEW_NO_ES)
+ // XXX jwilkins: for saving original data for shader export in ES
+ GLuint pixels_w, pixels_h;
+ GLvoid* pixels;
+#endif
};
static unsigned char *GPU_texture_convert_pixels(int length, float *fpixels)
@@ -330,7 +419,7 @@ static unsigned char *GPU_texture_convert_pixels(int length, float *fpixels)
len = 4*length;
fp = fpixels;
- p = pixels = MEM_callocN(sizeof(unsigned char)*len, "GPUTexturePixels");
+ p = pixels = (unsigned char*)MEM_callocN(sizeof(unsigned char)*len, "GPUTexturePixels");
for (a=0; a<len; a++, p++, fp++)
*p = FTOCHAR((*fp));
@@ -338,9 +427,9 @@ static unsigned char *GPU_texture_convert_pixels(int length, float *fpixels)
return pixels;
}
-static void GPU_glTexSubImageEmpty(GLenum target, GLenum format, int x, int y, int w, int h)
+static void tex_sub_image_empty(GLenum target, GLenum format, int x, int y, int w, int h)
{
- void *pixels = MEM_callocN(sizeof(char)*4*w*h, "GPUTextureEmptyPixels");
+ void *pixels = MEM_callocN(sizeof(char)*4*w*h, "tex_sub_image_empty");
if (target == GL_TEXTURE_1D)
glTexSubImage1D(target, 0, x, w, format, GL_UNSIGNED_BYTE, pixels);
@@ -412,7 +501,7 @@ static GPUTexture *GPU_texture_create_nD(int w, int h, int n, float *fpixels, in
pixels ? pixels : fpixels);
if (tex->w > w)
- GPU_glTexSubImageEmpty(tex->target, format, w, 0,
+ tex_sub_image_empty(tex->target, format, w, 0,
tex->w-w, 1);
}
}
@@ -425,9 +514,9 @@ static GPUTexture *GPU_texture_create_nD(int w, int h, int n, float *fpixels, in
format, type, pixels ? pixels : fpixels);
if (tex->w > w)
- GPU_glTexSubImageEmpty(tex->target, format, w, 0, tex->w-w, tex->h);
+ tex_sub_image_empty(tex->target, format, w, 0, tex->w-w, tex->h);
if (tex->h > h)
- GPU_glTexSubImageEmpty(tex->target, format, 0, h, w, tex->h-h);
+ tex_sub_image_empty(tex->target, format, 0, h, w, tex->h-h);
}
}
@@ -577,7 +666,8 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, bool is_data,
ima->gputexture= tex;
if (!glIsTexture(tex->bindcode)) {
- GPU_print_error("Blender Texture Not Loaded");
+ if (G.debug & G_DEBUG)
+ fprintf(stderr, "Blender Texture Not Loaded");
}
else {
glBindTexture(GL_TEXTURE_2D, tex->bindcode);
@@ -676,18 +766,23 @@ GPUTexture *GPU_texture_create_depth(int w, int h, char err_out[256])
*/
GPUTexture *GPU_texture_create_vsm_shadow_map(int size, char err_out[256])
{
- GPUTexture *tex = GPU_texture_create_nD(size, size, 2, NULL, 0, err_out);
+ if (GLEW_ARB_texture_rg || (GLEW_EXT_texture_rg && GLEW_EXT_texture_storage)) {
+ GPUTexture *tex = GPU_texture_create_nD(size, size, 2, NULL, 0, err_out);
- if (tex) {
- /* Now we tweak some of the settings */
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RG32F, size, size, 0, GL_RG, GL_FLOAT, NULL);
+ if (tex) {
+ /* Now we tweak some of the settings */
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RG32F, size, size, 0, GL_RG, GL_FLOAT, NULL);
- GPU_texture_unbind(tex);
- }
+ GPU_texture_unbind(tex);
+ }
- return tex;
+ return tex;
+ }
+ else {
+ return NULL;
+ }
}
void GPU_invalid_tex_init(void)
@@ -838,10 +933,8 @@ unsigned char* GPU_texture_dup_pixels(const GPUTexture *tex, size_t* count)
memcpy(texpixels, tex->pixels, 4*(*count));
#else
{
- //gpuBindTexture(GL_TEXTURE_2D, GPU_texture_opengl_bindcode(tex));
glBindTexture(GL_TEXTURE_2D, GPU_texture_opengl_bindcode(tex));
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, texpixels);
- //gpuBindTexture(GL_TEXTURE_2D, 0); /* restore default */
glBindTexture(GL_TEXTURE_2D, 0); /* restore default */
}
#endif
@@ -859,39 +952,47 @@ struct GPUFrameBuffer {
GPUFrameBuffer *GPU_framebuffer_create(void)
{
+ if (GG.extdisabled || !GG.framebuffersupport)
+ return NULL;
+
GPUFrameBuffer *fb;
- if (!GLEW_EXT_framebuffer_object)
- return NULL;
-
- fb= MEM_callocN(sizeof(GPUFrameBuffer), "GPUFrameBuffer");
- glGenFramebuffersEXT(1, &fb->object);
+ fb = (GPUFrameBuffer*)MEM_callocN(sizeof(GPUFrameBuffer), "GPUFrameBuffer");
+ gpu_glGenFramebuffers(1, &fb->object);
if (!fb->object) {
- fprintf(stderr, "GPUFFrameBuffer: framebuffer gen failed. %d\n",
- (int)glGetError());
+ fprintf(
+ stderr,
+ "GPU_framebuffer_create: framebuffer gen failed. %s\n",
+ gpuErrorString(glGetError()));
+
GPU_framebuffer_free(fb);
+
return NULL;
}
-
- return fb;
+ else {
+ return fb;
+ }
}
-int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, char err_out[256])
+bool GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, char err_out[256])
{
GLenum status;
GLenum attachment;
GLenum error;
+ if (GG.extdisabled)
+ return false;
+
if (tex->depth)
- attachment = GL_DEPTH_ATTACHMENT_EXT;
+ attachment = GL_DEPTH_ATTACHMENT;
else
- attachment = GL_COLOR_ATTACHMENT0_EXT;
+ attachment = GL_COLOR_ATTACHMENT0;
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb->object);
+ gpu_glBindFramebuffer(GL_FRAMEBUFFER, fb->object);
GG.currentfb = fb->object;
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment,
+ gpu_glFramebufferTexture2D(GL_FRAMEBUFFER, attachment,
tex->target, tex->bindcode, 0);
error = glGetError();
@@ -899,24 +1000,26 @@ int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, char err
if (error == GL_INVALID_OPERATION) {
GPU_framebuffer_restore();
GPU_print_framebuffer_error(error, err_out);
- return 0;
+ return false;
}
+#if !defined(GLEW_ES_ONLY) // XXX jwilkins: i think ES20 can only access COLOR_ATTACHMENT0 anyway
if (tex->depth) {
glDrawBuffer(GL_NONE);
- glReadBuffer(GL_NONE);
+ glReadBuffer(GL_NONE); // XXX jwilkins: this is an invalid value!
}
else {
- glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
- glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
+ glDrawBuffer(GL_COLOR_ATTACHMENT0);
+ glReadBuffer(GL_COLOR_ATTACHMENT0);
}
+#endif
- status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
+ status = gpu_glCheckFramebufferStatus(GL_FRAMEBUFFER);
- if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+ if (status != GL_FRAMEBUFFER_COMPLETE) {
GPU_framebuffer_restore();
GPU_print_framebuffer_error(status, err_out);
- return 0;
+ return false;
}
if (tex->depth)
@@ -926,44 +1029,59 @@ int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, char err
tex->fb= fb;
- return 1;
+ return true;
}
void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, GPUTexture *tex)
{
GLenum attachment;
+ if (GG.extdisabled)
+ return;
+
if (!tex->fb)
return;
if (GG.currentfb != tex->fb->object) {
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, tex->fb->object);
+ gpu_glBindFramebuffer(GL_FRAMEBUFFER, tex->fb->object);
GG.currentfb = tex->fb->object;
}
if (tex->depth) {
fb->depthtex = NULL;
- attachment = GL_DEPTH_ATTACHMENT_EXT;
+ attachment = GL_DEPTH_ATTACHMENT;
}
else {
fb->colortex = NULL;
- attachment = GL_COLOR_ATTACHMENT0_EXT;
+ attachment = GL_COLOR_ATTACHMENT0;
}
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment,
+ gpu_glFramebufferTexture2D(GL_FRAMEBUFFER, attachment,
tex->target, 0, 0);
tex->fb = NULL;
}
+#if GPU_SAFETY
+static bool in_framebuffer_texture_bind = false;
+#endif
+
void GPU_framebuffer_texture_bind(GPUFrameBuffer *UNUSED(fb), GPUTexture *tex, int w, int h)
{
+#if GPU_SAFETY
+ GPU_ASSERT(!in_frambuffer_texture_bind);
+ in_framebuffer_texture_bind = true;
+#endif
+
+ if (GG.extdisabled)
+ return;
+
/* push attributes */
glPushAttrib(GL_ENABLE_BIT | GL_VIEWPORT_BIT);
glDisable(GL_SCISSOR_TEST);
/* bind framebuffer */
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, tex->fb->object);
+ gpu_glBindFramebuffer(GL_FRAMEBUFFER_EXT, tex->fb->object);
/* push matrices and set default viewport and matrix */
glViewport(0, 0, w, h);
@@ -977,6 +1095,14 @@ void GPU_framebuffer_texture_bind(GPUFrameBuffer *UNUSED(fb), GPUTexture *tex, i
void GPU_framebuffer_texture_unbind(GPUFrameBuffer *UNUSED(fb), GPUTexture *UNUSED(tex))
{
+#if GPU_SAFETY
+ GPU_ASSERT(!in_frambuffer_texture_bind);
+ in_framebuffer_texture_bind = true;
+#endif
+
+ if (GG.extdisabled)
+ return;
+
/* restore matrix */
glMatrixMode(GL_PROJECTION);
glPopMatrix();
@@ -990,16 +1116,19 @@ void GPU_framebuffer_texture_unbind(GPUFrameBuffer *UNUSED(fb), GPUTexture *UNUS
void GPU_framebuffer_free(GPUFrameBuffer *fb)
{
+ if (GG.extdisabled)
+ return;
+
if (fb->depthtex)
GPU_framebuffer_texture_detach(fb, fb->depthtex);
if (fb->colortex)
GPU_framebuffer_texture_detach(fb, fb->colortex);
if (fb->object) {
- glDeleteFramebuffersEXT(1, &fb->object);
+ gpu_glDeleteFramebuffers(1, &fb->object);
if (GG.currentfb == fb->object) {
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+ gpu_glBindFramebuffer(GL_FRAMEBUFFER, 0);
GG.currentfb = 0;
}
}
@@ -1009,73 +1138,76 @@ void GPU_framebuffer_free(GPUFrameBuffer *fb)
void GPU_framebuffer_restore(void)
{
- if (GG.currentfb != 0) {
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+ if (!GG.extdisabled && GG.currentfb != 0) {
+ gpu_glBindFramebuffer(GL_FRAMEBUFFER, 0);
GG.currentfb = 0;
}
}
void GPU_framebuffer_blur(GPUFrameBuffer *fb, GPUTexture *tex, GPUFrameBuffer *blurfb, GPUTexture *blurtex)
{
- float scaleh[2] = {1.0f/GPU_texture_opengl_width(blurtex), 0.0f};
- float scalev[2] = {0.0f, 1.0f/GPU_texture_opengl_height(tex)};
-
- GPUShader *blur_shader = GPU_shader_get_builtin_shader(GPU_SHADER_SEP_GAUSSIAN_BLUR);
- int scale_uniform, texture_source_uniform;
-
- if (!blur_shader)
- return;
-
- scale_uniform = GPU_shader_get_uniform(blur_shader, "ScaleU");
- texture_source_uniform = GPU_shader_get_uniform(blur_shader, "textureSource");
-
- /* Blurring horizontally */
-
- /* We do the bind ourselves rather than using GPU_framebuffer_texture_bind() to avoid
- * pushing unnecessary matrices onto the OpenGL stack. */
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, blurfb->object);
-
- GPU_shader_bind(blur_shader);
- GPU_shader_uniform_vector(blur_shader, scale_uniform, 2, 1, (float *)scaleh);
- GPU_shader_uniform_texture(blur_shader, texture_source_uniform, tex);
- glViewport(0, 0, GPU_texture_opengl_width(blurtex), GPU_texture_opengl_height(blurtex));
+ if (!GG.extdisabled) {
+ float scaleh[2] = {1.0f/GPU_texture_opengl_width(blurtex), 0.0f};
+ float scalev[2] = {0.0f, 1.0f/GPU_texture_opengl_height(tex)};
- /* Peparing to draw quad */
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
+ GPUShader *blur_shader = GPU_shader_get_builtin_shader(GPU_SHADER_SEP_GAUSSIAN_BLUR);
+ int scale_uniform, texture_source_uniform;
- glDisable(GL_DEPTH_TEST);
- GPU_texture_bind(tex, 0);
+ if (!blur_shader)
+ return;
- /* Drawing quad */
- glBegin(GL_QUADS);
- glTexCoord2d(0, 0); glVertex2f(1, 1);
- glTexCoord2d(1, 0); glVertex2f(-1, 1);
- glTexCoord2d(1, 1); glVertex2f(-1, -1);
- glTexCoord2d(0, 1); glVertex2f(1, -1);
- glEnd();
+ scale_uniform = GPU_shader_get_uniform(blur_shader, "ScaleU");
+ texture_source_uniform = GPU_shader_get_uniform(blur_shader, "textureSource");
+
+ /* Blurring horizontally */
+
+ /* We do the bind ourselves rather than using GPU_framebuffer_texture_bind() to avoid
+ * pushing unnecessary matrices onto the OpenGL stack. */
+ gpu_glBindFramebuffer(GL_FRAMEBUFFER, blurfb->object);
+
+ GPU_shader_bind(blur_shader);
+ GPU_shader_uniform_vector(blur_shader, scale_uniform, 2, 1, (float *)scaleh);
+ GPU_shader_uniform_texture(blur_shader, texture_source_uniform, tex);
+ glViewport(0, 0, GPU_texture_opengl_width(blurtex), GPU_texture_opengl_height(blurtex));
+
+ /* Peparing to draw quad */
+ glMatrixMode(GL_TEXTURE);
+ glLoadIdentity();
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glMatrixMode(GL_MODELVIEW); // make sure last current matrix is MODELVIEW
+ glLoadIdentity();
+
+ glDisable(GL_DEPTH_TEST);
+
+ GPU_texture_bind(tex, 0);
+
+ /* Drawing quad */
+ glBegin(GL_TRIANGLE_FAN);
+ glTexCoord2d(0, 0); glVertex2f( 1, 1);
+ glTexCoord2d(1, 0); glVertex2f(-1, 1);
+ glTexCoord2d(1, 1); glVertex2f(-1, -1);
+ glTexCoord2d(0, 1); glVertex2f( 1, -1);
+ glEnd();
- /* Blurring vertically */
+ /* Blurring vertically */
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb->object);
- glViewport(0, 0, GPU_texture_opengl_width(tex), GPU_texture_opengl_height(tex));
- GPU_shader_uniform_vector(blur_shader, scale_uniform, 2, 1, (float *)scalev);
- GPU_shader_uniform_texture(blur_shader, texture_source_uniform, blurtex);
- GPU_texture_bind(blurtex, 0);
+ gpu_glBindFramebuffer(GL_FRAMEBUFFER, fb->object);
+ glViewport(0, 0, GPU_texture_opengl_width(tex), GPU_texture_opengl_height(tex));
+ GPU_shader_uniform_vector(blur_shader, scale_uniform, 2, 1, (float *)scalev);
+ GPU_shader_uniform_texture(blur_shader, texture_source_uniform, blurtex);
+ GPU_texture_bind(blurtex, 0);
- glBegin(GL_QUADS);
- glTexCoord2d(0, 0); glVertex2f(1, 1);
- glTexCoord2d(1, 0); glVertex2f(-1, 1);
- glTexCoord2d(1, 1); glVertex2f(-1, -1);
- glTexCoord2d(0, 1); glVertex2f(1, -1);
- glEnd();
+ glBegin(GL_TRIANGLE_FAN);
+ glTexCoord2d(0, 0); glVertex2f( 1, 1);
+ glTexCoord2d(1, 0); glVertex2f(-1, 1);
+ glTexCoord2d(1, 1); glVertex2f(-1, -1);
+ glTexCoord2d(0, 1); glVertex2f( 1, -1);
+ glEnd();
- GPU_shader_unbind();
+ GPU_shader_unbind();
+ }
}
/* GPUOffScreen */
@@ -1094,7 +1226,7 @@ GPUOffScreen *GPU_offscreen_create(int width, int height, char err_out[256])
{
GPUOffScreen *ofs;
- ofs= MEM_callocN(sizeof(GPUOffScreen), "GPUOffScreen");
+ ofs= (GPUOffScreen*)MEM_callocN(sizeof(GPUOffScreen), "GPUOffScreen");
ofs->w= width;
ofs->h= height;
@@ -1171,36 +1303,79 @@ int GPU_offscreen_height(GPUOffScreen *ofs)
return ofs->h;
}
-/* GPUShader */
+static void shader_print_log(GLuint object, GLboolean is_program, const char* nickname, const char* kind)
+{
+ char* log;
+ GLint log_size = 0;
-struct GPUShader {
- GLhandleARB object; /* handle for full shader */
- GLhandleARB vertex; /* handle for vertex shader */
- GLhandleARB fragment; /* handle for fragment shader */
- GLhandleARB lib; /* handle for libment shader */
- int totattrib; /* total number of attributes */
-};
+ GPU_CHECK_NO_ERROR();
-static void shader_print_errors(const char *task, char *log, const char *code)
-{
- const char *c, *pos, *end = code + strlen(code);
- int line = 1;
+ if (is_program)
+ gpu_glGetProgramiv(object, GL_INFO_LOG_LENGTH, &log_size);
+ else
+ gpu_glGetShaderiv(object, GL_INFO_LOG_LENGTH, &log_size);
- fprintf(stderr, "GPUShader: %s error:\n", task);
+ if (log_size > 0) {
+ log = (char*)MEM_mallocN(log_size, "shader_print_log");
+
+ if (is_program)
+ gpu_glGetProgramInfoLog(object, log_size, NULL, log);
+ else
+ gpu_glGetShaderInfoLog(object, log_size, NULL, log);
+
+ if (is_program)
+ fprintf(stderr, "Linker Info Log:\n%s\n", log);
+ else
+ fprintf(stderr, "%s Shader: %s\nShader Info Log:\n%s\n", kind, nickname, log);
+
+ MEM_freeN(log);
+ }
+
+ GPU_CHECK_NO_ERROR();
+}
+
+static void shader_print_errors(GLuint object, GLboolean is_program, const char* nickname, const char *kind, const char **code, int code_count)
+{
+ int total_line = 1;
if (G.debug & G_DEBUG) {
- c = code;
- while ((c < end) && (pos = strchr(c, '\n'))) {
- fprintf(stderr, "%2d ", line);
- fwrite(c, (pos+1)-c, 1, stderr);
- c = pos+1;
- line++;
- }
+ int i = 0;
+
+ fprintf(stderr, "Source Code: %s\n", nickname);
+
+ for (i = 0; i < code_count; i++) {
+ const char *c= code[i];
+ const char *pos;
+ const char *end = code[i] + strlen(code[i]);
+ int line = 1;
- fprintf(stderr, "%s", c);
+ while ((c < end) && (pos = strchr(c, '\n'))) {
+ fprintf(stderr, "%d:%3d:%3d: ", i, line, total_line);
+ fwrite(c, (pos+1)-c, 1, stderr);
+ c = pos+1;
+ line++;
+ total_line++;
+ }
+
+ fprintf(stderr, "%s", c);
+ }
}
- fprintf(stderr, "%s\n", log);
+ shader_print_log(object, is_program, nickname, kind);
+}
+
+static bool print_status(GLuint object, GLboolean is_program, const char* nickname, const char* kind, const char** code, int code_count)
+{
+ GLint status;
+
+ if (is_program)
+ gpu_glGetProgramiv(object, GL_LINK_STATUS, &status);
+ else
+ gpu_glGetShaderiv (object, GL_COMPILE_STATUS, &status);
+
+ shader_print_errors(object, is_program, nickname, kind, code, code_count);
+
+ return status;
}
static const char *gpu_shader_standard_extensions(void)
@@ -1228,23 +1403,53 @@ static const char *gpu_shader_standard_defines(void)
return "";
}
-GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, const char *libcode, const char *defines)
+GPUShader *GPU_shader_create(const char* nickname, const char *vertexcode, const char *fragcode, const char *libcode, const char *defines)
{
GLint status;
- GLcharARB log[5000];
- GLsizei length = 0;
GPUShader *shader;
+#if 0
+ int i;
- if (!GLEW_ARB_vertex_shader || !GLEW_ARB_fragment_shader)
+ /* XXX jwilkins: not sure if this belongs here. */
+ /* This would not really be needed except that ATI cards seem to
+ have a bug where they don't recognize VertexAttrib when the attribute location is 0 */
+ static struct AttribMap {
+ const GLchar* name;
+ GLuint index;
+ } attrib_map[] = {
+ { "b_Vertex", 1 },
+ { "b_Color", 2 },
+ { "b_Normal", 3 },
+ { "b_MultiTexCoord0", 4 },
+ { "b_MultiTexCoord1", 5 },
+ { "b_MultiTexCoord2", 6 },
+ { "b_MultiTexCoord3", 7 },
+ { "b_MultiTexCoord4", 8 },
+ { "b_MultiTexCoord5", 9 },
+ { "b_MultiTexCoord6", 10 },
+ { "b_MultiTexCoord7", 11 },
+ };
+#endif
+
+ if (GG.extdisabled || !GG.glslsupport) {
return NULL;
+ }
- shader = MEM_callocN(sizeof(GPUShader), "GPUShader");
+ shader = (GPUShader*)MEM_callocN(sizeof(GPUShader), "GPUShader");
if (vertexcode)
- shader->vertex = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
+ shader->vertex = gpu_glCreateShader(GL_VERTEX_SHADER);
+
if (fragcode)
- shader->fragment = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
- shader->object = glCreateProgramObjectARB();
+ shader->fragment = gpu_glCreateShader(GL_FRAGMENT_SHADER);
+
+ shader->object = gpu_glCreateProgram();
+
+#if 0
+ /* bind common attribute locations. has to be done before program is linked */
+ for (i = 0; i < sizeof(attrib_map)/sizeof(struct AttribMap); i++)
+ gpu_glBindAttribLocation(shader->object, attrib_map[i].index, attrib_map[i].name);
+#endif
if (!shader->object ||
(vertexcode && !shader->vertex) ||
@@ -1262,19 +1467,15 @@ GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, const
source[num_source++] = gpu_shader_standard_extensions();
source[num_source++] = gpu_shader_standard_defines();
- if (defines) source[num_source++] = defines;
+ if (defines) source[num_source++] = defines;
if (vertexcode) source[num_source++] = vertexcode;
- glAttachObjectARB(shader->object, shader->vertex);
- glShaderSourceARB(shader->vertex, num_source, source, NULL);
-
- glCompileShaderARB(shader->vertex);
- glGetObjectParameterivARB(shader->vertex, GL_OBJECT_COMPILE_STATUS_ARB, &status);
+ gpu_glAttachShader(shader->object, shader->vertex);
+ gpu_glShaderSource(shader->vertex, num_source, source, NULL);
- if (!status) {
- glGetInfoLogARB(shader->vertex, sizeof(log), &length, log);
- shader_print_errors("compile", log, vertexcode);
+ gpu_glCompileShader(shader->vertex);
+ if (!print_status(shader->vertex, GL_FALSE, nickname, "Vertex", source, num_source)) {
GPU_shader_free(shader);
return NULL;
}
@@ -1287,20 +1488,16 @@ GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, const
source[num_source++] = gpu_shader_standard_extensions();
source[num_source++] = gpu_shader_standard_defines();
- if (defines) source[num_source++] = defines;
- if (libcode) source[num_source++] = libcode;
+ if (defines) source[num_source++] = defines;
+ if (libcode) source[num_source++] = libcode;
if (fragcode) source[num_source++] = fragcode;
- glAttachObjectARB(shader->object, shader->fragment);
- glShaderSourceARB(shader->fragment, num_source, source, NULL);
-
- glCompileShaderARB(shader->fragment);
- glGetObjectParameterivARB(shader->fragment, GL_OBJECT_COMPILE_STATUS_ARB, &status);
+ gpu_glAttachShader(shader->object, shader->fragment);
+ gpu_glShaderSource(shader->fragment, num_source, source, NULL);
- if (!status) {
- glGetInfoLogARB(shader->fragment, sizeof(log), &length, log);
- shader_print_errors("compile", log, fragcode);
+ gpu_glCompileShader(shader->fragment);
+ if (!print_status(shader->fragment, GL_FALSE, nickname, "Fragment", source, num_source)) {
GPU_shader_free(shader);
return NULL;
}
@@ -1308,17 +1505,13 @@ GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, const
#if 0
if (lib && lib->lib)
- glAttachObjectARB(shader->object, lib->lib);
+ gpuAttachShader(shader->object, lib->lib);
#endif
- glLinkProgramARB(shader->object);
- glGetObjectParameterivARB(shader->object, GL_OBJECT_LINK_STATUS_ARB, &status);
- if (!status) {
- glGetInfoLogARB(shader->object, sizeof(log), &length, log);
- if (fragcode) shader_print_errors("linking", log, fragcode);
- else if (vertexcode) shader_print_errors("linking", log, vertexcode);
- else if (libcode) shader_print_errors("linking", log, libcode);
+ gpu_glLinkProgram(shader->object);
+ gpu_glGetProgramiv(shader->object, GL_LINK_STATUS, &status);
+ if (!print_status(shader->object, GL_TRUE, nickname, NULL, NULL, 0)) {
GPU_shader_free(shader);
return NULL;
}
@@ -1330,11 +1523,10 @@ GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, const
GPUShader *GPU_shader_create_lib(const char *code)
{
GLint status;
- GLcharARB log[5000];
GLsizei length = 0;
GPUShader *shader;
- if (!GLEW_ARB_vertex_shader || !GLEW_ARB_fragment_shader)
+ if (GG.extdisabled || !GLEW_ARB_vertex_shader || !GLEW_ARB_fragment_shader)
return NULL;
shader = MEM_callocN(sizeof(GPUShader), "GPUShader");
@@ -1353,8 +1545,7 @@ GPUShader *GPU_shader_create_lib(const char *code)
glGetObjectParameterivARB(shader->lib, GL_OBJECT_COMPILE_STATUS_ARB, &status);
if (!status) {
- glGetInfoLogARB(shader->lib, sizeof(log), &length, log);
- shader_print_errors("compile", log, code);
+ shader_print_errors(shader->lib, GL_FALSE, "compile", (const char**)&code, 1);
GPU_shader_free(shader);
return NULL;
@@ -1366,60 +1557,76 @@ GPUShader *GPU_shader_create_lib(const char *code)
void GPU_shader_bind(GPUShader *shader)
{
+ if (GG.extdisabled)
+ return;
+
GPU_print_error("Pre Shader Bind");
- glUseProgramObjectARB(shader->object);
+ gpu_glUseProgram(shader->object);
GPU_print_error("Post Shader Bind");
}
void GPU_shader_unbind(void)
{
+ if (GG.extdisabled)
+ return;
+
GPU_print_error("Pre Shader Unbind");
- glUseProgramObjectARB(0);
+ gpu_glUseProgram(0);
GPU_print_error("Post Shader Unbind");
}
void GPU_shader_free(GPUShader *shader)
{
+ if (GG.extdisabled)
+ return;
+ if (shader == NULL)
+ return;
if (shader->lib)
- glDeleteObjectARB(shader->lib);
+ gpu_glDeleteShader(shader->lib);
if (shader->vertex)
- glDeleteObjectARB(shader->vertex);
+ gpu_glDeleteShader(shader->vertex);
if (shader->fragment)
- glDeleteObjectARB(shader->fragment);
+ gpu_glDeleteShader(shader->fragment);
if (shader->object)
- glDeleteObjectARB(shader->object);
+ gpu_glDeleteProgram(shader->object);
MEM_freeN(shader);
}
int GPU_shader_get_uniform(GPUShader *shader, const char *name)
{
- return glGetUniformLocationARB(shader->object, name);
+ return GG.extdisabled ? -1 : gpu_glGetUniformLocation(shader->object, name);
}
void GPU_shader_uniform_vector(GPUShader *UNUSED(shader), int location, int length, int arraysize, float *value)
{
+ if (GG.extdisabled)
+ return;
+
if (location == -1)
return;
GPU_print_error("Pre Uniform Vector");
- if (length == 1) glUniform1fvARB(location, arraysize, value);
- else if (length == 2) glUniform2fvARB(location, arraysize, value);
- else if (length == 3) glUniform3fvARB(location, arraysize, value);
- else if (length == 4) glUniform4fvARB(location, arraysize, value);
- else if (length == 9) glUniformMatrix3fvARB(location, arraysize, 0, value);
- else if (length == 16) glUniformMatrix4fvARB(location, arraysize, 0, value);
+ if (length == 1) gpu_glUniform1fv (location, arraysize, value);
+ else if (length == 2) gpu_glUniform2fv (location, arraysize, value);
+ else if (length == 3) gpu_glUniform3fv (location, arraysize, value);
+ else if (length == 4) gpu_glUniform4fv (location, arraysize, value);
+ else if (length == 9) gpu_glUniformMatrix3fv(location, arraysize, 0, value);
+ else if (length == 16) gpu_glUniformMatrix4fv(location, arraysize, 0, value);
GPU_print_error("Post Uniform Vector");
}
void GPU_shader_uniform_int(GPUShader *UNUSED(shader), int location, int value)
{
+ if (GG.extdisabled)
+ return;
+
if (location == -1)
return;
GPU_print_error("Pre Uniform Int");
- glUniform1iARB(location, value);
+ gpu_glUniform1i(location, value);
GPU_print_error("Post Uniform Int");
}
@@ -1427,11 +1634,14 @@ void GPU_shader_uniform_texture(GPUShader *UNUSED(shader), int location, GPUText
{
GLenum arbnumber;
- if (tex->number >= GG.maxtextures) {
- GPU_print_error("Not enough texture slots.");
+ if (GG.extdisabled)
+ return;
+
+ if (tex->number >= GG.maxtextures && (G.debug & G_DEBUG)) {
+ fprintf(stderr, "Not enough texture slots.");
return;
}
-
+
if (tex->number == -1)
return;
@@ -1440,16 +1650,22 @@ void GPU_shader_uniform_texture(GPUShader *UNUSED(shader), int location, GPUText
GPU_print_error("Pre Uniform Texture");
- arbnumber = (GLenum)((GLuint)GL_TEXTURE0_ARB + tex->number);
+ arbnumber = (GLenum)((GLuint)GL_TEXTURE0 + tex->number);
+
+ if (tex->number != 0)
+ glActiveTexture(arbnumber);
- if (tex->number != 0) glActiveTextureARB(arbnumber);
if (tex->bindcode != 0)
glBindTexture(tex->target, tex->bindcode);
else
GPU_invalid_tex_bind(tex->target);
- glUniform1iARB(location, tex->number);
+
+ gpu_glUniform1i(location, tex->number);
+
glEnable(tex->target);
- if (tex->number != 0) glActiveTextureARB(GL_TEXTURE0_ARB);
+
+ if (tex->number != 0)
+ glActiveTexture(GL_TEXTURE0);
GPU_print_error("Post Uniform Texture");
}
@@ -1457,11 +1673,12 @@ void GPU_shader_uniform_texture(GPUShader *UNUSED(shader), int location, GPUText
int GPU_shader_get_attribute(GPUShader *shader, const char *name)
{
int index;
-
- GPU_print_error("Pre Get Attribute");
- index = glGetAttribLocationARB(shader->object, name);
+ if (GG.extdisabled)
+ return -1;
+ GPU_print_error("Pre Get Attribute");
+ index = gpu_glGetAttribLocation(shader->object, name);
GPU_print_error("Post Get Attribute");
return index;
@@ -1474,12 +1691,12 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
switch (shader) {
case GPU_SHADER_VSM_STORE:
if (!GG.shaders.vsm_store)
- GG.shaders.vsm_store = GPU_shader_create(datatoc_gpu_shader_vsm_store_vert_glsl, datatoc_gpu_shader_vsm_store_frag_glsl, NULL, NULL);
+ GG.shaders.vsm_store = GPU_shader_create("Built-in VSM", datatoc_gpu_shader_vsm_store_vert_glsl, datatoc_gpu_shader_vsm_store_frag_glsl, NULL, NULL);
retval = GG.shaders.vsm_store;
break;
case GPU_SHADER_SEP_GAUSSIAN_BLUR:
if (!GG.shaders.sep_gaussian_blur)
- GG.shaders.sep_gaussian_blur = GPU_shader_create(datatoc_gpu_shader_sep_gaussian_blur_vert_glsl, datatoc_gpu_shader_sep_gaussian_blur_frag_glsl, NULL, NULL);
+ GG.shaders.sep_gaussian_blur = GPU_shader_create("Built-in Guassian Blur", datatoc_gpu_shader_sep_gaussian_blur_vert_glsl, datatoc_gpu_shader_sep_gaussian_blur_frag_glsl, NULL, NULL);
retval = GG.shaders.sep_gaussian_blur;
break;
}
@@ -1503,7 +1720,6 @@ void GPU_shader_free_builtin_shaders(void)
}
}
-#if 0
/* GPUPixelBuffer */
typedef struct GPUPixelBuffer {
@@ -1517,7 +1733,7 @@ typedef struct GPUPixelBuffer {
void GPU_pixelbuffer_free(GPUPixelBuffer *pb)
{
if (pb->bindcode[0])
- glDeleteBuffersARB(pb->numbuffers, pb->bindcode);
+ gpu_glDeleteBuffers(pb->numbuffers, pb->bindcode);
MEM_freeN(pb);
}
@@ -1525,15 +1741,15 @@ GPUPixelBuffer *gpu_pixelbuffer_create(int x, int y, int halffloat, int numbuffe
{
GPUPixelBuffer *pb;
- if (!GLEW_ARB_multitexture || !GLEW_EXT_pixel_buffer_object)
+ if (GG.extdisabled || !GLEW_ARB_multitexture || !GLEW_EXT_pixel_buffer_object)
return NULL;
- pb = MEM_callocN(sizeof(GPUPixelBuffer), "GPUPBO");
+ pb = (GPUPixelBuffer*)MEM_callocN(sizeof(GPUPixelBuffer), "GPUPBO");
pb->datasize = x*y*4*((halffloat)? 16: 8);
pb->numbuffers = numbuffers;
pb->halffloat = halffloat;
- glGenBuffersARB(pb->numbuffers, pb->bindcode);
+ gpu_glGenBuffers(pb->numbuffers, pb->bindcode);
if (!pb->bindcode[0]) {
fprintf(stderr, "GPUPixelBuffer allocation failed\n");
@@ -1549,53 +1765,53 @@ void GPU_pixelbuffer_texture(GPUTexture *tex, GPUPixelBuffer *pb)
void *pixels;
int i;
- glBindTexture(GL_TEXTURE_RECTANGLE_EXT, tex->bindcode);
+ glBindTexture(GL_TEXTURE_RECTANGLE, tex->bindcode);
for (i = 0; i < pb->numbuffers; i++) {
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, pb->bindcode[pb->current]);
- glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_EXT, pb->datasize, NULL,
- GL_STREAM_DRAW_ARB);
+ gpu_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pb->bindcode[pb->current]);
+ gpu_glBufferData(GL_PIXEL_UNPACK_BUFFER, pb->datasize, NULL, GL_STREAM_DRAW);
- pixels = glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, GL_WRITE_ONLY);
+ pixels = gpu_glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
/*memcpy(pixels, _oImage.data(), pb->datasize);*/
- if (!glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT)) {
+ if (!gpu_glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER)) {
fprintf(stderr, "Could not unmap opengl PBO\n");
break;
}
}
- glBindTexture(GL_TEXTURE_RECTANGLE_EXT, 0);
+ glBindTexture(GL_TEXTURE_RECTANGLE, 0);
}
-static int pixelbuffer_map_into_gpu(GLuint bindcode)
+static bool pixelbuffer_map_into_gpu(GLuint bindcode)
{
void *pixels;
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, bindcode);
- pixels = glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, GL_WRITE_ONLY);
+ gpu_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, bindcode);
+ pixels = gpu_glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
/* do stuff in pixels */
- if (!glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT)) {
+ if (!gpu_glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER)) {
fprintf(stderr, "Could not unmap opengl PBO\n");
- return 0;
+ return false;
+ }
+ else {
+ return true;
}
-
- return 1;
}
static void pixelbuffer_copy_to_texture(GPUTexture *tex, GPUPixelBuffer *pb, GLuint bindcode)
{
GLenum type = (pb->halffloat)? GL_HALF_FLOAT_NV: GL_UNSIGNED_BYTE;
- glBindTexture(GL_TEXTURE_RECTANGLE_EXT, tex->bindcode);
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, bindcode);
+ glBindTexture(GL_TEXTURE_RECTANGLE, tex->bindcode);
+ gpu_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, bindcode);
- glTexSubImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0, tex->w, tex->h,
+ glTexSubImage2D(GL_TEXTURE_RECTANGLE, 0, 0, 0, tex->w, tex->h,
GL_RGBA, type, NULL);
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);
- glBindTexture(GL_TEXTURE_RECTANGLE_EXT, 0);
+ gpu_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
+ glBindTexture(GL_TEXTURE_RECTANGLE, 0);
}
void GPU_pixelbuffer_async_to_gpu(GPUTexture *tex, GPUPixelBuffer *pb)
@@ -1614,5 +1830,418 @@ void GPU_pixelbuffer_async_to_gpu(GPUTexture *tex, GPUPixelBuffer *pb)
pixelbuffer_copy_to_texture(tex, pb, pb->bindcode[pb->current]);
}
}
+
+#if GPU_SAFETY
+
+#define GPU_CHECK_INVALID_PNAME(symbol) \
+ { \
+ GLboolean paramOK; \
+ GPU_SAFE_RETURN(pname != (symbol), paramOK,); \
+ }
+
+#else
+
+#define GPU_CHECK_INVALID_PNAME(symbol)
+
+#endif
+
+
+#if !defined(GLEW_ES_ONLY)
+static void GLAPIENTRY check_glGetObjectParameterivARB(GLuint shader, GLuint pname, GLint *params)
+{
+ GPU_CHECK_INVALID_PNAME(GL_SHADER_TYPE);
+
+ glGetObjectParameterivARB(shader, pname, params);
+}
+#endif
+
+static void GLAPIENTRY check_glGetShaderiv(GLuint shader, GLuint pname, GLint *params)
+{
+ GPU_CHECK_INVALID_PNAME(GL_SHADER_TYPE);
+
+ glGetShaderiv(shader, pname, params);
+}
+
+static GLboolean init_shader_objects(void)
+{
+ if (GLEW_VERSION_2_0 || GLEW_ES_VERSION_2_0) {
+ gpu_glAttachShader = glAttachShader;
+ gpu_glCompileShader = glCompileShader;
+ gpu_glCreateProgram = glCreateProgram;
+ gpu_glCreateShader = glCreateShader;
+ gpu_glDeleteShader = glDeleteShader;
+ gpu_glGetProgramInfoLog = glGetProgramInfoLog;
+ gpu_glGetShaderiv = check_glGetShaderiv;
+ gpu_glGetShaderInfoLog = glGetShaderInfoLog;
+ gpu_glGetUniformLocation = glGetUniformLocation;
+ gpu_glLinkProgram = glLinkProgram;
+ gpu_glShaderSource = glShaderSource;
+ gpu_glUniform1i = glUniform1i;
+ gpu_glUniform1f = glUniform1f;
+ gpu_glUniform1iv = glUniform1iv;
+ gpu_glUniform2iv = glUniform2iv;
+ gpu_glUniform3iv = glUniform3iv;
+ gpu_glUniform4iv = glUniform4iv;
+ gpu_glUniform1fv = glUniform1fv;
+ gpu_glUniform2fv = glUniform2fv;
+ gpu_glUniform3fv = glUniform3fv;
+ gpu_glUniform4fv = glUniform4fv;
+ gpu_glUniformMatrix3fv = glUniformMatrix3fv;
+ gpu_glUniformMatrix4fv = glUniformMatrix4fv;
+ gpu_glUseProgram = glUseProgram;
+ gpu_glValidateProgram = glValidateProgram;
+
+ return GL_TRUE;
+ }
+
+#if !defined(GLEW_ES_ONLY)
+ if (GLEW_ARB_shader_objects) {
+ gpu_glAttachShader = glAttachObjectARB;
+ gpu_glCompileShader = glCompileShaderARB;
+ gpu_glCreateProgram = glCreateProgramObjectARB;
+ gpu_glCreateShader = glCreateShaderObjectARB;
+ gpu_glDeleteShader = glDeleteObjectARB;
+ gpu_glGetProgramInfoLog = glGetInfoLogARB;
+ gpu_glGetShaderiv = check_glGetObjectParameterivARB;
+ gpu_glGetShaderInfoLog = glGetInfoLogARB;
+ gpu_glGetUniformLocation = glGetUniformLocationARB;
+ gpu_glLinkProgram = glLinkProgramARB;
+ gpu_glShaderSource = glShaderSourceARB;
+ gpu_glUniform1i = glUniform1iARB;
+ gpu_glUniform1f = glUniform1fARB;
+ gpu_glUniform1iv = glUniform1ivARB;
+ gpu_glUniform2iv = glUniform2ivARB;
+ gpu_glUniform3iv = glUniform3ivARB;
+ gpu_glUniform4iv = glUniform4ivARB;
+ gpu_glUniform1fv = glUniform1fvARB;
+ gpu_glUniform2fv = glUniform2fvARB;
+ gpu_glUniform3fv = glUniform3fvARB;
+ gpu_glUniform4fv = glUniform4fvARB;
+ gpu_glUniformMatrix3fv = glUniformMatrix3fvARB;
+ gpu_glUniformMatrix4fv = glUniformMatrix4fvARB;
+ gpu_glUseProgram = glUseProgramObjectARB;
+ gpu_glValidateProgram = glValidateProgramARB;
+
+ return GL_TRUE;
+ }
+#endif
+
+ return GL_FALSE;
+}
+
+static GLboolean init_vertex_shader(void)
+{
+ if (GLEW_VERSION_2_0 || GLEW_ES_VERSION_2_0) {
+ gpu_glGetAttribLocation = glGetAttribLocation;
+ gpu_glBindAttribLocation = glBindAttribLocation;
+
+ return GL_TRUE;
+ }
+
+#if !defined(GLEW_ES_ONLY)
+ if (GLEW_ARB_vertex_shader) {
+ gpu_glBindAttribLocation = (void (GLAPIENTRY*)(GLuint,GLuint,const GLchar*))glBindAttribLocationARB;
+ gpu_glGetAttribLocation = glGetAttribLocationARB;
+
+ return GL_TRUE;
+ }
+#endif
+
+ return GL_FALSE;
+}
+
+#if !defined(GLEW_ES_ONLY)
+static void GLAPIENTRY check_glGetProgramivARB(GLuint shader, GLuint pname, GLint *params)
+{
+ GPU_CHECK_INVALID_PNAME(GL_ACTIVE_ATTRIBUTES);
+ GPU_CHECK_INVALID_PNAME(GL_ACTIVE_ATTRIBUTE_MAX_LENGTH);
+
+ glGetProgramivARB(shader, pname, params);
+}
+#endif
+
+static void GLAPIENTRY check_glGetProgramiv(GLuint shader, GLuint pname, GLint *params)
+{
+ GPU_CHECK_INVALID_PNAME(GL_ACTIVE_ATTRIBUTES);
+ GPU_CHECK_INVALID_PNAME(GL_ACTIVE_ATTRIBUTE_MAX_LENGTH);
+
+ glGetProgramiv(shader, pname, params);
+}
+
+static GLboolean init_vertex_program(void)
+{
+ if (GLEW_VERSION_2_0 || GLEW_ES_VERSION_2_0) {
+ gpu_glDeleteProgram = glDeleteProgram;
+ gpu_glDisableVertexAttribArray = glDisableVertexAttribArray;
+ gpu_glEnableVertexAttribArray = glEnableVertexAttribArray;
+ gpu_glGetProgramiv = check_glGetProgramiv;
+ gpu_glVertexAttribPointer = glVertexAttribPointer;
+
+ return GL_TRUE;
+ }
+
+#if !defined(GLEW_ES_ONLY)
+ if (GLEW_ARB_vertex_program) {
+ gpu_glDeleteProgram = glDeleteObjectARB;
+ gpu_glDisableVertexAttribArray = glDisableVertexAttribArrayARB;
+ gpu_glEnableVertexAttribArray = glEnableVertexAttribArrayARB;
+ gpu_glGetProgramiv = check_glGetProgramivARB;
+ gpu_glVertexAttribPointer = glVertexAttribPointerARB;
+
+ return GL_TRUE;
+ }
+#endif
+
+ return GL_FALSE;
+}
+
+static void init_buffers(void)
+{
+ if (GLEW_VERSION_1_5 || GLEW_ES_VERSION_2_0) {
+ gpu_glBindBuffer = glBindBuffer;
+ gpu_glBufferData = glBufferData;
+ gpu_glBufferSubData = glBufferSubData;
+ gpu_glDeleteBuffers = glDeleteBuffers;
+ gpu_glGenBuffers = glGenBuffers;
+
+ return;
+ }
+
+#if !defined(GLEW_ES_ONLY)
+ if (GLEW_ARB_vertex_buffer_object) {
+ gpu_glBindBuffer = glBindBufferARB;
+ gpu_glBufferData = glBufferDataARB;
+ gpu_glBufferSubData = glBufferSubDataARB;
+ gpu_glDeleteBuffers = glDeleteBuffersARB;
+ gpu_glGenBuffers = glGenBuffersARB;
+
+ return;
+ }
+#endif
+}
+
+static void init_mapbuffer(void)
+{
+#if !defined(GLEW_ES_ONLY)
+ if (GLEW_VERSION_1_5) {
+ gpu_glMapBuffer = glMapBuffer;
+ gpu_glUnmapBuffer = glUnmapBuffer;
+
+ return;
+ }
+
+ if (GLEW_ARB_vertex_buffer_object) {
+ gpu_glMapBuffer = glMapBufferARB;
+ gpu_glUnmapBuffer = glUnmapBufferARB;
+
+ return;
+ }
+#endif
+
+#if !defined(GLEW_NO_ES)
+ if (GLEW_OES_mapbuffer) {
+ gpu_glMapBuffer = glMapBufferOES;
+ gpu_glUnmapBuffer = glUnmapBufferOES;
+
+ return;
+ }
+#endif
+}
+
+static GLboolean init_framebuffer_object(void)
+{
+ if (GLEW_VERSION_3_0 || GLEW_ES_VERSION_2_0 || GLEW_ARB_framebuffer_object) {
+ gpu_glGenFramebuffers = glGenFramebuffers;
+ gpu_glBindFramebuffer = glBindFramebuffer;
+ gpu_glDeleteFramebuffers = glDeleteFramebuffers;
+ gpu_glFramebufferTexture2D = glFramebufferTexture2D;
+ gpu_glCheckFramebufferStatus = glCheckFramebufferStatus;
+
+ return GL_TRUE;
+ }
+
+#if !defined(GLEW_ES_ONLY)
+ if (GLEW_EXT_framebuffer_object) {
+ gpu_glGenFramebuffers = glGenFramebuffersEXT;
+ gpu_glBindFramebuffer = glBindFramebufferEXT;
+ gpu_glDeleteFramebuffers = glDeleteFramebuffersEXT;
+ gpu_glFramebufferTexture2D = glFramebufferTexture2DEXT;
+ gpu_glCheckFramebufferStatus = glCheckFramebufferStatusEXT;
+
+ return GL_TRUE;
+ }
#endif
+#if !defined(GLEW_NO_ES)
+ if (GLEW_OES_framebuffer_object) {
+ gpu_glGenFramebuffers = glGenFramebuffersOES;
+ gpu_glBindFramebuffer = glBindFramebufferOES;
+ gpu_glDeleteFramebuffers = glDeleteFramebuffersOES;
+ gpu_glFramebufferTexture2D = glFramebufferTexture2DOES;
+ gpu_glCheckFramebufferStatus = glCheckFramebufferStatusOES;
+
+ return GL_TRUE;
+ }
+#endif
+
+ return GL_FALSE;
+}
+
+static void init_vertex_arrays(void)
+{
+#if !defined(GLEW_ES_ONLY)
+ if (GLEW_VERSION_3_0 || GLEW_ARB_vertex_array_object) {
+ gpu_glGenVertexArrays = glGenVertexArrays;
+ gpu_glBindVertexArray = glBindVertexArray;
+ gpu_glDeleteVertexArrays = glDeleteVertexArrays;
+
+ return;
+ }
+#endif
+
+#if !defined(GLEW_NO_ES)
+ if (GLEW_OES_vertex_array_object) {
+ gpu_glGenVertexArrays = glGenVertexArraysOES;
+ gpu_glBindVertexArray = glBindVertexArrayOES;
+ gpu_glDeleteVertexArrays = glDeleteVertexArraysOES;
+
+ return;
+ }
+#endif
+}
+
+static GPUFUNC void (GLAPIENTRY* _GenerateMipmap)(GLenum target);
+
+static void init_generate_mipmap(void)
+{
+#if !defined(GLEW_ES_ONLY)
+ if (GLEW_VERSION_3_0 || GLEW_ARB_framebuffer_object) {
+ _GenerateMipmap = glGenerateMipmap;
+ return;
+ }
+
+ if (GLEW_EXT_framebuffer_object) {
+ _GenerateMipmap = glGenerateMipmapEXT;
+ return;
+ }
+#endif
+
+#if !defined(GLEW_NO_ES)
+ if (GLEW_OES_framebuffer_object) {
+ _GenerateMipmap = glGenerateMipmapOES;
+ }
+#endif
+}
+
+void gpu_glGenerateMipmap(GLenum target)
+{
+ GLboolean workaround;
+
+ /* Work around bug in ATI driver, need to have GL_TEXTURE_2D enabled.
+ * http://www.opengl.org/wiki/Common_Mistakes#Automatic_mipmap_generation */
+ if (GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY)) {
+ workaround = !glIsEnabled(target);
+
+ if (workaround) {
+ glEnable(target);
+ }
+ }
+ else {
+ workaround = GL_FALSE;
+ }
+
+ _GenerateMipmap(target);
+
+ if (workaround) {
+ glDisable(target);
+ }
+}
+
+static void* gpu_buffer_start_update_dummy(GLenum UNUSED(target), void* data)
+{
+ GPU_ASSERT(data != NULL);
+ return data;
+}
+
+static void* gpu_buffer_start_update_copy(GLenum UNUSED(target), void* data)
+{
+ GPU_ASSERT(data != NULL);
+ return data;
+}
+
+static void* gpu_buffer_start_update_map(GLenum target, void* UNUSED(data))
+{
+ void* mappedData;
+ GPU_ASSERT(UNUSED_data == NULL);
+ mappedData = gpu_glMapBuffer(target, GL_WRITE_ONLY);
+ GPU_CHECK_NO_ERROR();
+ return mappedData;
+}
+
+static void gpu_buffer_finish_update_dummy(GLenum UNUSED(target), GLsizeiptr UNUSED(dataSize), const GLvoid* UNUSED(data))
+{
+ GPU_ASSERT(UNUSED_data != NULL);
+}
+
+static void gpu_buffer_finish_update_copy(GLenum target, GLsizeiptr dataSize, const GLvoid* data)
+{
+ GPU_ASSERT(data != NULL);
+ gpu_glBufferSubData(target, 0, dataSize, data);
+ GPU_CHECK_NO_ERROR();
+}
+
+static void gpu_buffer_finish_update_map(GLenum target, GLsizeiptr UNUSED(dataSize), const GLvoid* UNUSED(data))
+{
+ GPU_ASSERT(UNUSED_data != NULL);
+ gpu_glUnmapBuffer(target);
+ GPU_CHECK_NO_ERROR();
+}
+
+
+
+static void shim_init(void)
+{
+ if (!GG.extdisabled) {
+ GG.glslsupport = true;
+
+ if (!init_shader_objects())
+ GG.glslsupport = false;
+
+ if (!init_vertex_shader())
+ GG.glslsupport = false;
+
+ if (!init_vertex_program())
+ GG.glslsupport = false;
+
+ if (!(GLEW_ARB_multitexture || GLEW_VERSION_1_3 || GLEW_ES_VERSION_2_0)) // Note: This should mean only the non-deprecated parts of the multitexture extension
+ GG.glslsupport = false;
+
+ GG.framebuffersupport = init_framebuffer_object();
+
+ init_vertex_arrays();
+ init_buffers();
+ init_mapbuffer();
+
+ if (GLEW_VERSION_1_5 || GLEW_OES_mapbuffer || GLEW_ARB_vertex_buffer_object) {
+ gpu_buffer_start_update = gpu_buffer_start_update_map;
+ gpu_buffer_finish_update = gpu_buffer_finish_update_map;
+ }
+ else if (GLEW_ES_VERSION_2_0) {
+ gpu_buffer_start_update = gpu_buffer_start_update_copy;
+ gpu_buffer_finish_update = gpu_buffer_finish_update_copy;
+ }
+ else {
+ gpu_buffer_start_update = gpu_buffer_start_update_dummy;
+ gpu_buffer_finish_update = gpu_buffer_finish_update_dummy;
+ }
+
+ init_generate_mipmap();
+ }
+ else {
+ GG.glslsupport = false;
+ GG.framebuffersupport = false;
+
+ gpu_buffer_start_update = gpu_buffer_start_update_dummy;
+ gpu_buffer_finish_update = gpu_buffer_finish_update_dummy;
+ }
+}
diff --git a/source/blender/gpu/intern/gpu_immediate_gl.c b/source/blender/gpu/intern/gpu_immediate_gl.c
index 56b34de04f0..9ff22786566 100644
--- a/source/blender/gpu/intern/gpu_immediate_gl.c
+++ b/source/blender/gpu/intern/gpu_immediate_gl.c
@@ -563,7 +563,7 @@ void gpu_unlock_buffer_gl(void)
bufferDataGLSL* bufferData = (bufferDataGLSL*)(GPU_IMMEDIATE->bufferData);
if (bufferData->vao != 0)
- glBindVertexArray(0);
+ gpu_glBindVertexArray(0);
else
unsetup();
}
@@ -719,7 +719,7 @@ void gpu_commit_samplers(void)
if (common) {
GPU_CHECK_NO_ERROR();
- glUniform1iv(
+ gpu_glUniform1iv(
common->sampler[0],
GPU_IMMEDIATE->format.samplerCount,
GPU_IMMEDIATE->format.samplerMap);
diff --git a/source/blender/gpu/intern/gpu_init_exit.c b/source/blender/gpu/intern/gpu_init_exit.c
index 673b9e9acb7..6f9ed227653 100644
--- a/source/blender/gpu/intern/gpu_init_exit.c
+++ b/source/blender/gpu/intern/gpu_init_exit.c
@@ -80,7 +80,9 @@ void GPU_init(void)
gpu_basic_init();
gpu_blender_aspect_init();
gpu_clipping_init();
+#endif
gpu_codegen_init();
+#if 0
gpu_common_init();
gpu_font_init();
gpu_immediate_init();
@@ -129,7 +131,9 @@ void GPU_exit(void)
gpu_immediate_exit();
gpu_font_exit();
gpu_common_exit();
+#endif
gpu_codegen_exit();
+#if 0
gpu_clipping_exit();
gpu_blender_aspect_exit();
gpu_basic_exit();