[Mesa-dev] [PATCH 8/9] mesa: add Uniform Buffer Object API implementation
v2:Move implementation to ubo.cpp and ubo.h as suggested by Brian Paul --- src/mesa/main/api_exec.c |2 + src/mesa/main/bufferobj.c| 11 + src/mesa/main/ubo.c | 268 ++ src/mesa/main/ubo.cpp| 263 + src/mesa/main/ubo.h | 33 +++ src/mesa/sources.mak |1 + src/mesa/state_tracker/st_cb_bufferobjects.c |6 +- 7 files changed, 583 insertions(+), 1 deletions(-) create mode 100644 src/mesa/main/ubo.c create mode 100644 src/mesa/main/ubo.cpp create mode 100644 src/mesa/main/ubo.h diff --git a/src/mesa/main/api_exec.c b/src/mesa/main/api_exec.c index e0bf90d..c908719 100644 --- a/src/mesa/main/api_exec.c +++ b/src/mesa/main/api_exec.c @@ -102,6 +102,7 @@ #if FEATURE_ARB_shader_objects #include "shaderapi.h" #include "uniforms.h" +#include "ubo.h" #endif #include "syncobj.h" #include "main/dispatch.h" @@ -307,6 +308,7 @@ _mesa_create_exec_table(void) #if FEATURE_ARB_shader_objects _mesa_init_shader_dispatch(exec); _mesa_init_shader_uniform_dispatch(exec); + _mesa_init_shader_uniform_buffer_objects(exec); #endif /* 2. GL_EXT_blend_color */ diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index b7e59e8..d74b78c 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->UniformBufferObject.UniformObj; default: return NULL; } @@ -734,6 +736,10 @@ _mesa_BindBufferBase(GLenum target, GLuint index, GLuint buffer) break; #endif +#if FEATURE_ARB_uniform_buffer_object + case GL_UNIFORM_BUFFER: + break; +#endif default: _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferBase(target)"); break; @@ -756,6 +762,11 @@ _mesa_BindBufferBase(GLenum target, GLuint index, GLuint buffer) _mesa_bind_buffer_range_for_transform_feedback(ctx, index, bufObj, 0, size); break; #endif +#if FEATURE_ARB_uniform_buffer_object + case GL_UNIFORM_BUFFER: + ctx->UniformBufferObject.BindingPoint[index] = bufObj; + break; +#endif default: /* should not go here */ break; } diff --git a/src/mesa/main/ubo.c b/src/mesa/main/ubo.c new file mode 100644 index 000..1e31df8 --- /dev/null +++ b/src/mesa/main/ubo.c @@ -0,0 +1,268 @@ +/* + * Mesa 3-D graphics library + * + * Copyright (C) 2004-2011 Brian Paul All Rights Reserved. + * Copyright (C) 2009-2011 VMware, Inc. All Rights Reserved. + * Copyright © 2010-2011 Intel Corporation + * Copyright (C) 2011 Vincent Lejeune. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * API implementation of GL_ARB_uniform_buffer_object. + * + * Every uniform (in an UBO or not) is given an index that identifies it when + * calling one of these functions. Strictly speaking, such an index doesn't + * need to match location for classic uniform ; others drivers however use this + * approach so we're also matching them for compatibility purpose. + */ + +#include +#include "main/glheader.h" +#include "main/context.h" +#include "main/dispatch.h" +#include "main/image.h" +#include "main/mfeatures.h" +#include "main/mtypes.h" +#include "main/shaderapi.h" +#include "main/shaderobj.h" +#include "main/uniforms.h" +#include "main/hash.h" +#include "program/prog_parameter.h" +#include "program/prog_statevars.h" +#include "program/prog_uniform.h" +#include "program/prog_instruction.h" +#include "main/ubo.h" +#include "main/bufferobj.h" + +static void +get_ubo_info (struct gl_context *ctx, + struct gl_shader_program *shProg, GLint ubo_index, + GLenum query, int *data) +{ + if (ubo_index > shProg->UBOCount ||
Re: [Mesa-dev] [PATCH 8/9] mesa: add Uniform Buffer Object API implementation
On 10/16/2011 04:37 PM, vlj wrote: --- src/mesa/main/bufferobj.c |2 + src/mesa/main/uniforms.c | 187 + src/mesa/main/uniforms.h | 15 3 files changed, 204 insertions(+), 0 deletions(-) diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index c453f9c..cddb0b4 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->UniformBufferObject.UniformObj; We should have an extension check here as with some of the other cases: case GL_UNIFORM_BUFFER: if (ctx->Extensions.ARB_uniform_buffer_object) return &ctx->UniformBufferObject.UniformObj; } default: return NULL; } diff --git a/src/mesa/main/uniforms.c b/src/mesa/main/uniforms.c index fe1ce6d..253e5cf 100644 --- a/src/mesa/main/uniforms.c +++ b/src/mesa/main/uniforms.c I'm thinking this new code should go into a new file (ubo.c) because uniforms.c is rather large already and on the surface it doesn't look like there's a lot of code sharing with what's in uniforms.c @@ -45,12 +45,14 @@ #include "main/shaderapi.h" #include "main/shaderobj.h" #include "main/uniforms.h" +#include "main/hash.h" #include "program/prog_parameter.h" #include "program/prog_statevars.h" #include "program/prog_uniform.h" #include "program/prog_instruction.h" + static GLenum base_uniform_type(GLenum type) { @@ -1064,6 +1066,121 @@ _mesa_uniform_matrix(struct gl_context *ctx, struct gl_shader_program *shProg, uniform->Initialized = GL_TRUE; } +static 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->UBOCount || ubo_index< 0) + _mesa_error(ctx, GL_INVALID_VALUE, "glGetActiveUniformBlock(uniformBlockIndex)"); 'return' after generating the error. + + struct ubo current_ubo = *(shProg->UniformBufferObject[ubo_index]); + + switch(query) + { + case GL_UNIFORM_BLOCK_BINDING: + *data = current_ubo.BoundBuffer; + 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.NumberOfVariables; + 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; I suspect we should generate a GL_INVALID_ENUM error for the default case here. + } +} + +/** + * TODO : Switch to hash table + */ +static GLuint +getIndices(const struct gl_shader_program* prog, const char* name) get_indices(const struct gl_shader_program *prog, const char *name) +{ + unsigned i,k; + for (k = 0; k< prog->Uniforms->Size; k++) + { + struct gl_uniform* current_uniform =&(prog->Uniforms->Uniforms[k]); + if(strcmp(name,current_uniform->Name)==0) + { + return k; + } + } + for (i = 0;i< prog->UBOVariableCount; i++) + { + struct UBOVariableInfo* var = prog->IndexedUniformsInUBO[i]; + if(strcmp(name,var->Name)==0) + { + return i + prog->Uniforms->Size; + } + } + return GL_INVALID_INDEX; +} + +static 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->UBOCount || index< 0) { + _mesa_error(ctx, GL_INVALID_VALUE, "GetActiveUniformBlockName(uniformBlockIndex)"); + return; + } + + struct ubo current_ubo = *(shProg->UniformBufferObject[index]); + GLsizei temp_length = strlen(current_ubo.Name); We need to put declarations before code so we can compile with MSVC. So put these var decls at the top of the function. + 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; +} + +static void +_mesa_link_buffer_uniform(struct gl_context* ctx,struct gl_shader_program *shProg, GLint ubo_index, + GLint buffer_index) +{ + if(ubo_index> shProg->UBOCount || ubo_index< 0) + _mesa_error(ctx, GL_INVALID_VALUE, "UniformBlockBinding(uniformBlockIndex)"); + + FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS); + + shProg->UniformBufferObject[ubo_index]->BoundBuffer = buffer_index; +} + +static +GLint GetLoneUniformInfo(struct gl_shader_program* sh, GLuint index, GLenum pname) { + uint n = sh->Uniforms->
[Mesa-dev] [PATCH 8/9] mesa: add Uniform Buffer Object API implementation
--- src/mesa/main/bufferobj.c |2 + src/mesa/main/uniforms.c | 187 + src/mesa/main/uniforms.h | 15 3 files changed, 204 insertions(+), 0 deletions(-) diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index c453f9c..cddb0b4 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->UniformBufferObject.UniformObj; default: return NULL; } diff --git a/src/mesa/main/uniforms.c b/src/mesa/main/uniforms.c index fe1ce6d..253e5cf 100644 --- a/src/mesa/main/uniforms.c +++ b/src/mesa/main/uniforms.c @@ -45,12 +45,14 @@ #include "main/shaderapi.h" #include "main/shaderobj.h" #include "main/uniforms.h" +#include "main/hash.h" #include "program/prog_parameter.h" #include "program/prog_statevars.h" #include "program/prog_uniform.h" #include "program/prog_instruction.h" + static GLenum base_uniform_type(GLenum type) { @@ -1064,6 +1066,121 @@ _mesa_uniform_matrix(struct gl_context *ctx, struct gl_shader_program *shProg, uniform->Initialized = GL_TRUE; } +static 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->UBOCount || ubo_index < 0) + _mesa_error(ctx, GL_INVALID_VALUE, "glGetActiveUniformBlock(uniformBlockIndex)"); + + struct ubo current_ubo = *(shProg->UniformBufferObject[ubo_index]); + + switch(query) + { + case GL_UNIFORM_BLOCK_BINDING: + *data = current_ubo.BoundBuffer; + 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.NumberOfVariables; + 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; + } +} + +/** + * TODO : Switch to hash table + */ +static GLuint +getIndices(const struct gl_shader_program* prog, const char* name) +{ + unsigned i,k; + for (k = 0; k < prog->Uniforms->Size; k++) + { + struct gl_uniform* current_uniform = &(prog->Uniforms->Uniforms[k]); + if(strcmp(name,current_uniform->Name)==0) + { + return k; + } + } + for (i = 0;i < prog->UBOVariableCount; i++) + { + struct UBOVariableInfo* var = prog->IndexedUniformsInUBO[i]; + if(strcmp(name,var->Name)==0) + { + return i + prog->Uniforms->Size; + } + } + return GL_INVALID_INDEX; +} + +static 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->UBOCount || index < 0) { + _mesa_error(ctx, GL_INVALID_VALUE, "GetActiveUniformBlockName(uniformBlockIndex)"); + return; + } + + struct ubo current_ubo = *(shProg->UniformBufferObject[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; +} + +static void +_mesa_link_buffer_uniform(struct gl_context* ctx,struct gl_shader_program *shProg, GLint ubo_index, + GLint buffer_index) +{ + if(ubo_index > shProg->UBOCount || ubo_index < 0) + _mesa_error(ctx, GL_INVALID_VALUE, "UniformBlockBinding(uniformBlockIndex)"); + + FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS); + + shProg->UniformBufferObject[ubo_index]->BoundBuffer = buffer_index; +} + +static +GLint GetLoneUniformInfo(struct gl_shader_program* sh, GLuint index, GLenum pname) { + uint n = sh->Uniforms->Size; + if(index >= n) { + struct UBOVariableInfo *var = sh->IndexedUniformsInUBO[index - n]; + switch(pname) { + case GL_UNIFORM_TYPE: + return var->Type; + case GL_UNIFORM_SIZE: + case GL_UNIFORM_BLOCK_NAME_LENGTH: + case GL_UNIFORM_BLOCK_INDEX: + return var->UBO->Index; + case GL_UNIFORM_OFFSET: + return var->Offset; + case GL_UNIFORM_ARRAY_STRIDE: + case GL_UNIFORM_MATRIX_STRIDE: + return var->Stride; + case GL_UNIFORM_IS_ROW_MAJOR: + return sh->UniformBufferObject[var->UBO->Index]->MatrixLayout == rowmajor; + } + } +} void GLAPIENTRY _mesa_Uniform1fARB(GLint location, GLfloat v0) @@ -1452,6 +1569,69 @@ _mesa_GetActiveUniformARB(GLhandleARB program, GLuint index,
Re: [Mesa-dev] [PATCH 8/9] mesa: add Uniform Buffer Object API implementation
On 09/23/2011 07:53 AM, vlj wrote: --- 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 + +void _mesa_query_ubo_general(struct gl_context *ctx, struct gl_shader_program *shProg,GLint ubo_index,GLenum query, int* data) If a function is non-static, it should be prototyped in the corresponding header file. +{ +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)"); We should return after recording an error. The indentation looks incorrect. + + 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) Is this function used outside of this file? If not, declare it as static. It also looks like the parameters can be const-qualified. +{ + + 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); Left-over debug code. + 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 Move declaration of 'i' before the loop. + { + indices[i] = get_indice(shProg,names[i]); + } +} + /** * Plug in shader uniform-related functions into API dispatch table. */ ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 8/9] mesa: add Uniform Buffer Object API implementation
--- 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 + +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;ihttp://lists.freedesktop.org/mailman/listinfo/mesa-dev