[Mesa-dev] [PATCH 8/9] mesa: add Uniform Buffer Object API implementation

vlj vljn at ovi.com
Fri Sep 23 06:53:13 PDT 2011


---
 src/mesa/main/bufferobj.c |    2 +
 src/mesa/main/uniforms.c  |   99 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 101 insertions(+), 0 deletions(-)

diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index c453f9c..794cde5 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -98,6 +98,8 @@ get_buffer_target(struct gl_context *ctx, GLenum target)
          return &ctx->Texture.BufferObject;
       }
       break;
+   case GL_UNIFORM_BUFFER:
+      return &ctx->Uniform_Buffer_Object.UniformObj;
    default:
       return NULL;
    }
diff --git a/src/mesa/main/uniforms.c b/src/mesa/main/uniforms.c
index fe1ce6d..b923aef 100644
--- a/src/mesa/main/uniforms.c
+++ b/src/mesa/main/uniforms.c
@@ -1064,6 +1064,76 @@ _mesa_uniform_matrix(struct gl_context *ctx, struct gl_shader_program *shProg,
    uniform->Initialized = GL_TRUE;
 }
 
+#include <main/hash.h>
+
+void _mesa_query_ubo_general(struct gl_context *ctx, struct gl_shader_program *shProg,GLint ubo_index,GLenum query, int* data)
+{
+    if(ubo_index > shProg->ubo_count || ubo_index < 0)
+        _mesa_error(ctx, GL_INVALID_VALUE, "glGetActiveUniformBlock(uniformBlockIndex)");
+
+    struct ubo current_ubo = *(shProg->UniformBufferObjects[ubo_index]);
+
+    switch(query)
+    {
+    case GL_UNIFORM_BLOCK_BINDING:
+        *data = current_ubo.bound_buffer;
+        break;
+    case GL_UNIFORM_BLOCK_DATA_SIZE:
+        *data = 0;
+       break;
+    case GL_UNIFORM_BLOCK_NAME_LENGTH:
+        *data = strlen(current_ubo.name);
+        break;
+    case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
+        *data = current_ubo.number_of_variables;
+        break;
+    case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
+    case GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER:
+    case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
+        *data = 0;
+        break;
+    default:
+        break;
+    }
+}
+
+GLint _mesa_get_ubo_id_from_name(struct gl_context *ctx, struct gl_shader_program *shProg,const char* name)
+{
+   GLint id;
+   //id = _mesa_HashLookup(shProg->name_to_id,name);
+   return id;
+}
+
+void _mesa_get_ubo_name(struct gl_context *ctx, struct gl_shader_program *shProg,GLint index,GLsizei bufsize,GLsizei* length,char* buffer)
+{
+   if(index >= shProg->ubo_count || index < 0) {
+       _mesa_error(ctx, GL_INVALID_VALUE, "GetActiveUniformBlockName(uniformBlockIndex)");
+       return;
+   }
+
+   struct ubo current_ubo = *(shProg->UniformBufferObjects[index]);
+   GLsizei temp_length = strlen(current_ubo.name);
+   if(bufsize - 1 < temp_length) {
+      _mesa_error(ctx, GL_INVALID_VALUE, "GetActiveUniformBlockName(bufSize)");
+      return;
+   }
+
+   memcpy(buffer,current_ubo.name,temp_length);
+   buffer[temp_length] = '\0';
+   if(length != NULL)
+      *length = temp_length;
+}
+
+void _mesa_link_buffer_uniform(struct gl_context* ctx,struct gl_shader_program *shProg, GLint ubo_index, GLint buffer_index)
+{
+   if(ubo_index > shProg->ubo_count || ubo_index < 0)
+       _mesa_error(ctx, GL_INVALID_VALUE, "UniformBlockBinding(uniformBlockIndex)");
+
+   FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS);
+
+   shProg->UniformBufferObjects[ubo_index]->bound_buffer = buffer_index;
+}
+
 
 void GLAPIENTRY
 _mesa_Uniform1fARB(GLint location, GLfloat v0)
@@ -1453,6 +1523,35 @@ _mesa_GetActiveUniformARB(GLhandleARB program, GLuint index,
 }
 
 
+GLuint get_indice(struct gl_shader_program* prog, const char* name)
+{
+
+   for(int k = 0;k < prog->Uniforms->Size; k++)
+   {
+      struct gl_uniform* current_uniform = &(prog->Uniforms->Uniforms[k]);
+      printf("current uniform:%s\n",current_uniform->Name);
+      if(strcmp(name,current_uniform->Name)==0)
+      {
+         return k;
+      }
+   }
+   return GL_INVALID_INDEX;
+}
+
+/* Note : location and index are the same */
+void GLAPIENTRY
+_mesa_GetUniformIndices(GLint program,GLsizei number_of_variables,const char** names, GLuint* indices)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   struct gl_shader_program *shProg =
+      _mesa_lookup_shader_program_err(ctx, program, "GetUniformIndices");
+   for(unsigned i=0;i<number_of_variables;i++)
+   {
+      indices[i] = get_indice(shProg,names[i]);
+   }
+}
+
 /**
  * Plug in shader uniform-related functions into API dispatch table.
  */
-- 
1.7.6.3



More information about the mesa-dev mailing list