Revision: 48334
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48334
Author:   alexk
Date:     2012-06-27 14:35:56 +0000 (Wed, 27 Jun 2012)
Log Message:
-----------
ARB/EXT are very simular to standard functions.
OpenGL ES support only standard functions.
Therefore we have gpu** which automaticly chooses between gl** and gl**ARB
We use standard enums and gpu functions automaticly translates to ARB enums to 
call gl**ARB.
GLSL and some Framebuffer functions are added.

Modified Paths:
--------------
    branches/soc-2012-swiss_cheese/source/blender/gpu/CMakeLists.txt
    branches/soc-2012-swiss_cheese/source/blender/gpu/GPU_extensions.h
    branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_extensions.c

Added Paths:
-----------
    branches/soc-2012-swiss_cheese/source/blender/gpu/GPU_functions.h
    branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_functions.c

Modified: branches/soc-2012-swiss_cheese/source/blender/gpu/CMakeLists.txt
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/gpu/CMakeLists.txt    
2012-06-27 14:01:58 UTC (rev 48333)
+++ branches/soc-2012-swiss_cheese/source/blender/gpu/CMakeLists.txt    
2012-06-27 14:35:56 UTC (rev 48334)
@@ -57,6 +57,10 @@
        intern/gpu_material.c
        intern/gpu_matrix.c
        intern/gpu_primitives.c
+       #intern/gpu_object.c
+       #intern/gpu_object_gles.c
+       #intern/gpu_object_gl11.c
+       intern/gpu_functions.c
        
        shaders/gpu_shader_material.glsl.c
        shaders/gpu_shader_vertex.glsl.c
@@ -74,12 +78,16 @@
        GPU_matrix.h
        GPU_lighting.h
        GPU_primitives.h
+       #GPU_object.h
+       GPU_functions.h
 
        intern/gpu_codegen.h
        intern/gpu_deprecated.h
        intern/gpu_immediate.h
        intern/gpu_immediate_inline.h
        intern/gpu_immediate_internal.h
+       intern/gpu_object_gles.h
+       intern/gpu_object_gl11.h
        intern/gpu_primitives_inline.h
 )
 

Modified: branches/soc-2012-swiss_cheese/source/blender/gpu/GPU_extensions.h
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/gpu/GPU_extensions.h  
2012-06-27 14:01:58 UTC (rev 48333)
+++ branches/soc-2012-swiss_cheese/source/blender/gpu/GPU_extensions.h  
2012-06-27 14:35:56 UTC (rev 48334)
@@ -32,10 +32,36 @@
 #ifndef __GPU_EXTENSIONS_H__
 #define __GPU_EXTENSIONS_H__
 
+
+
+extern unsigned int GPU_ext_config ;
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+
+
+
+#define GPU_EXT_GLSL (1<<0)
+#define GPU_EXT_GLSL_ENABLED (GPU_ext_config & GPU_EXT_GLSL)
+#define GPU_EXT_GLSL_VERTEX (1<<1)
+#define GPU_EXT_GLSL_VERTEX_ENABLED (GPU_ext_config & GPU_EXT_GLSL_VERTEX)
+#define GPU_EXT_GLSL_FRAGMENT (1<<2)
+#define GPU_EXT_GLSL_FRAGMENT_ENABLED (GPU_ext_config & GPU_EXT_GLSL_FRAGMENT)
+#define GPU_EXT_FRAMEBUFFERS (1<<3)
+#define GPU_EXT_FRAMEBUFFERS_ENABLED (GPU_ext_config & GPU_EXT_FRAMEBUFFERS)
+
+/* 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 libment shader */
+       int totattrib;                  /* total number of attributes */
+};
+
 struct Image;
 struct ImageUser;
 

Added: branches/soc-2012-swiss_cheese/source/blender/gpu/GPU_functions.h
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/gpu/GPU_functions.h           
                (rev 0)
+++ branches/soc-2012-swiss_cheese/source/blender/gpu/GPU_functions.h   
2012-06-27 14:35:56 UTC (rev 48334)
@@ -0,0 +1,59 @@
+
+
+#ifdef GPU_INTERN_FUNC
+#define GPUFUNC
+#else
+#define GPUFUNC extern
+#endif 
+
+
+GPUFUNC unsigned int (*gpuCreateShader)(unsigned int shaderType);
+GPUFUNC void (*gpuAttachShader)(       unsigned int program, unsigned int 
shader);
+GPUFUNC void (*gpuShaderSource)(unsigned int shader, int count, const char ** 
string, const int * length);
+GPUFUNC void (*gpuCompileShader)(unsigned int shader);
+GPUFUNC void (*gpuGetShaderiv)(unsigned int shader, unsigned int pname, int 
*params);
+GPUFUNC void (*gpuGetShaderInfoLog)(unsigned int shader, int maxLength, int 
*length, char *infoLog);
+
+GPUFUNC unsigned int (*gpuCreateProgram)(void);
+GPUFUNC void (*gpuLinkProgram)(unsigned int program);
+GPUFUNC void (*gpuGetProgramiv)(unsigned int shader, unsigned int pname, int 
*params);
+GPUFUNC void (*gpuGetProgramInfoLog)(unsigned int shader, int maxLength, int 
*length, char *infoLog);
+
+
+GPUFUNC void (*gpuUniform1i)(int location, int v0);
+
+GPUFUNC void (*gpuUniform1fv)(int location, int count, const float * value);
+GPUFUNC void (*gpuUniform2fv)(int location, int count, const float * value);
+GPUFUNC void (*gpuUniform3fv)(int location, int count, const float * value);
+GPUFUNC void (*gpuUniform4fv)(int location, int count, const float * value);
+GPUFUNC void (*gpuUniformMatrix3fv)(int location, int count, unsigned char 
transpose, const float * value);
+GPUFUNC void (*gpuUniformMatrix4fv)(int location, int count, unsigned char 
transpose, const float * value);
+
+GPUFUNC int (*gpuGetAttribLocation)(unsigned int program, const char *name);
+GPUFUNC int (*gpuGetUniformLocation)(unsigned int program, const char * name);
+
+
+GPUFUNC void (*gpuUseProgram)(unsigned int program);
+GPUFUNC void (*gpuDeleteShader)(unsigned int shader);
+GPUFUNC void (*gpuDeleteProgram)(unsigned int program);
+
+
+
+GPUFUNC void (*gpuGenFramebuffers)(int m, unsigned int * ids);
+GPUFUNC void (*gpuBindFramebuffer)(unsigned int target, unsigned int 
framebuffer);
+GPUFUNC void (*gpuDeleteFramebuffers)(int n, const unsigned int * 
framebuffers);
+
+
+
+
+
+
+#ifdef __cplusplus
+extern "C" { 
+#endif
+
+void GPU_func_comp_init(void);
+
+#ifdef __cplusplus
+}
+#endif

Modified: 
branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_extensions.c
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_extensions.c   
2012-06-27 14:01:58 UTC (rev 48333)
+++ branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_extensions.c   
2012-06-27 14:35:56 UTC (rev 48334)
@@ -29,6 +29,9 @@
  *  \ingroup gpu
  */
 
+#ifdef GLES
+#include <GLES2/gl2.h>
+#endif
 
 #include <GL/glew.h>
 
@@ -38,6 +41,7 @@
 
 #include "BKE_global.h"
 
+#include <sys/time.h>
 
 #include "BLI_blenlib.h"
 #include "BLI_utildefines.h"
@@ -47,6 +51,7 @@
 #include "GPU_extensions.h"
 #include "gpu_codegen.h"
 #include "GPU_compatibility.h"
+#include <GPU_functions.h>
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -73,6 +78,7 @@
 extern char datatoc_gpu_shader_vsm_store_frag_glsl[];
 extern char datatoc_gpu_shader_sep_gaussian_blur_vert_glsl[];
 extern char datatoc_gpu_shader_sep_gaussian_blur_frag_glsl[];
+unsigned int GPU_ext_config ;
 
 typedef struct GPUShaders {
        GPUShader *vsm_store;
@@ -112,24 +118,38 @@
 {
        GLint r, g, b;
        const char *vendor, *renderer;
+       int bdepth = -1;
 
+
        /* can't avoid calling this multiple times, see 
wm_window_add_ghostwindow */
        if (gpu_extensions_init) return;
        gpu_extensions_init= 1;
 
        glewInit();
+       GPU_func_comp_init();
        GPU_codegen_init();
 
        /* glewIsSupported("GL_VERSION_2_0") */
-
+#include REAL_GL_MODE
        if (GLEW_ARB_multitexture)
-               glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &GG.maxtextures);
-
+               glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &GG.maxtextures);
+       /* GL_MAX_TEXTURE_IMAGE_UNITS == GL_MAX_TEXTURE_IMAGE_UNITS_ARB */
+       
        GG.glslsupport = 1;
+#ifndef GLES
        if (!GLEW_ARB_multitexture) GG.glslsupport = 0;
        if (!GLEW_ARB_vertex_shader) GG.glslsupport = 0;
        if (!GLEW_ARB_fragment_shader) GG.glslsupport = 0;
+       if (GLEW_VERSION_2_0) GG.glslsupport = 1;
+       if (GLEW_EXT_framebuffer_object || GLEW_VERSION_3_0) GPU_ext_config |= 
GPU_EXT_FRAMEBUFFERS;
+#else 
+       GPU_ext_config |= GPU_EXT_FRAMEBUFFERS;
+#endif
 
+
+       if(GG.glslsupport)
+               GPU_ext_config |= GPU_EXT_GLSL | GPU_EXT_GLSL_FRAGMENT | 
GPU_EXT_GLSL_VERTEX;
+
        glGetIntegerv(GL_RED_BITS, &r);
        glGetIntegerv(GL_GREEN_BITS, &g);
        glGetIntegerv(GL_BLUE_BITS, &b);
@@ -137,6 +157,7 @@
 
        vendor = (const char*)glGetString(GL_VENDOR);
        renderer = (const char*)glGetString(GL_RENDERER);
+#include FAKE_GL_MODE
 
        if (strstr(vendor, "ATI")) {
                GG.device = GPU_DEVICE_ATI;
@@ -236,14 +257,14 @@
 int GPU_print_error(const char *str)
 {
        GLenum errCode;
-
+#include REAL_GL_MODE
        if (G.debug & G_DEBUG) {
                if ((errCode = glGetError()) != GL_NO_ERROR) {
                        fprintf(stderr, "%s opengl error: %s\n", str, 
gpuErrorString(errCode));
                        return 1;
                }
        }
-
+#include FAKE_GL_MODE
        return 0;
 }
 
@@ -527,7 +548,7 @@
 {
        GPUTexture *tex;
        GLint w, h, border, lastbindcode, bindcode;
-
+#include REAL_GL_MODE
        glGetIntegerv(GL_TEXTURE_BINDING_2D, &lastbindcode);
 
        GPU_update_image_time(ima, time);
@@ -558,6 +579,8 @@
        }
        else {
                glBindTexture(GL_TEXTURE_2D, tex->bindcode);
+               
+               #include FAKE_GL_MODE
                glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, 
&w);
                glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, 
&h);
                glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_BORDER, 
&border);
@@ -565,9 +588,9 @@
                tex->w = w - border;
                tex->h = h - border;
        }
-
+#include REAL_GL_MODE
        glBindTexture(GL_TEXTURE_2D, lastbindcode);
-
+#include FAKE_GL_MODE
        return tex;
 }
 
@@ -724,16 +747,16 @@
        GPUTexture *colortex;
        GPUTexture *depthtex;
 };
-
+#include REAL_GL_MODE
 GPUFrameBuffer *GPU_framebuffer_create(void)
 {
        GPUFrameBuffer *fb;
 
-       if (!GLEW_EXT_framebuffer_object)
+       if (!GPU_EXT_FRAMEBUFFERS)
                return NULL;
        
        fb= MEM_callocN(sizeof(GPUFrameBuffer), "GPUFrameBuffer");
-       glGenFramebuffersEXT(1, &fb->object);
+       gpuGenFramebuffers(1, &fb->object);
 
        if (!fb->object) {
                fprintf(stderr, "GPUFFrameBuffer: framebuffer gen failed. %s\n",
@@ -744,7 +767,7 @@
 
        return fb;
 }
-
+#include FAKE_GL_MODE
 int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, char 
err_out[256])
 {
        GLenum status;
@@ -850,7 +873,7 @@
        glPopAttrib();
        glEnable(GL_SCISSOR_TEST);
 }
-
+#include REAL_GL_MODE
 void GPU_framebuffer_free(GPUFrameBuffer *fb)
 {
        if (fb->depthtex)
@@ -859,17 +882,17 @@
                GPU_framebuffer_texture_detach(fb, fb->colortex);
 
        if (fb->object) {
-               glDeleteFramebuffersEXT(1, &fb->object);
+               gpuDeleteFramebuffers(1, &fb->object);
 
                if (GG.currentfb == fb->object) {
-                       glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+                       gpuBindFramebuffer(GL_FRAMEBUFFER, 0);
                        GG.currentfb = 0;
                }
        }
 
        MEM_freeN(fb);
 }
-
+#include FAKE_GL_MODE
 void GPU_framebuffer_restore(void)
 {
        if (GG.currentfb != 0) {
@@ -1026,16 +1049,6 @@
        glReadPixels(0, 0, ofs->w, ofs->h, GL_RGBA, type, pixels);
 }
 
-/* GPUShader */
-
-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 */
-};
-
 static void shader_print_errors(const char *task, char *log, const char *code)
 {
        const char *c, *pos, *end = code + strlen(code);
@@ -1057,26 +1070,27 @@
 
        fprintf(stderr, "%s\n", log);
 }
-
 GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, 
/*GPUShader *lib,*/ const char *libcode)
 {
        GLint status;
-       GLcharARB log[5000];
+       char log[5000];
        const char *fragsource[2];
        GLsizei length = 0;
        GLint count;
        GPUShader *shader;
 
+#ifndef GLES
        if (!GLEW_ARB_vertex_shader || !GLEW_ARB_fragment_shader)
                return NULL;
+#endif
 

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to