[Mesa-dev] [PATCH 1/4] mesa: add support for ARB_blend_func_extended
Dave Airlie
airlied at gmail.com
Mon Mar 26 11:14:01 PDT 2012
From: Dave Airlie <airlied at redhat.com>
Add implementations of the two API functions,
Add a new strings to uint mapping for index bindings
Add the blending mode validation for SRC1 + SRC_ALPHA_SATURATE
Add get for MAX_DUAL_SOURCE_DRAW_BUFFERS
The GLSL patch will setup the indices.
Signed-off-by: Dave Airlie <airlied at redhat.com>
---
src/mesa/main/blend.c | 11 ++++
src/mesa/main/get.c | 3 +
src/mesa/main/mtypes.h | 4 ++
src/mesa/main/shader_query.cpp | 103 ++++++++++++++++++++++++++++++++++------
src/mesa/main/shaderapi.c | 3 +
src/mesa/main/shaderapi.h | 7 +++
src/mesa/main/shaderobj.c | 6 ++
7 files changed, 122 insertions(+), 15 deletions(-)
diff --git a/src/mesa/main/blend.c b/src/mesa/main/blend.c
index 09acdf5..bc446ed 100644
--- a/src/mesa/main/blend.c
+++ b/src/mesa/main/blend.c
@@ -63,6 +63,11 @@ legal_src_factor(const struct gl_context *ctx, GLenum factor)
case GL_CONSTANT_ALPHA:
case GL_ONE_MINUS_CONSTANT_ALPHA:
return GL_TRUE;
+ case GL_SRC1_COLOR:
+ case GL_SRC1_ALPHA:
+ case GL_ONE_MINUS_SRC1_COLOR:
+ case GL_ONE_MINUS_SRC1_ALPHA:
+ return ctx->Extensions.ARB_blend_func_extended;
default:
return GL_FALSE;
}
@@ -93,6 +98,12 @@ legal_dst_factor(const struct gl_context *ctx, GLenum factor)
case GL_CONSTANT_ALPHA:
case GL_ONE_MINUS_CONSTANT_ALPHA:
return GL_TRUE;
+ case GL_SRC_ALPHA_SATURATE:
+ case GL_SRC1_COLOR:
+ case GL_SRC1_ALPHA:
+ case GL_ONE_MINUS_SRC1_COLOR:
+ case GL_ONE_MINUS_SRC1_ALPHA:
+ return ctx->Extensions.ARB_blend_func_extended;
default:
return GL_FALSE;
}
diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c
index 9a5ca53..55dc205 100644
--- a/src/mesa/main/get.c
+++ b/src/mesa/main/get.c
@@ -333,6 +333,7 @@ EXTRA_EXT(ARB_copy_buffer);
EXTRA_EXT(EXT_framebuffer_sRGB);
EXTRA_EXT(ARB_texture_buffer_object);
EXTRA_EXT(OES_EGL_image_external);
+EXTRA_EXT(ARB_blend_func_extended);
static const int
extra_ARB_vertex_program_ARB_fragment_program_NV_vertex_program[] = {
@@ -1304,6 +1305,8 @@ static const struct value_desc values[] = {
{ GL_MAX_DEBUG_LOGGED_MESSAGES_ARB, CONST(MAX_DEBUG_LOGGED_MESSAGES), NO_EXTRA },
{ GL_MAX_DEBUG_MESSAGE_LENGTH_ARB, CONST(MAX_DEBUG_MESSAGE_LENGTH), NO_EXTRA },
+ { GL_MAX_DUAL_SOURCE_DRAW_BUFFERS, CONTEXT_INT(Const.MaxDualSourceDrawBuffers), extra_ARB_blend_func_extended },
+
#endif /* FEATURE_GL */
};
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 0072e11..841ab6b 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2265,6 +2265,7 @@ struct gl_shader_program
* and they are \b not the values returned by \c glGetFragDataLocation.
*/
struct string_to_uint_map *FragDataBindings;
+ struct string_to_uint_map *FragDataIndexBindings;
/**
* Transform feedback varyings last specified by
@@ -2816,6 +2817,9 @@ struct gl_constants
/* GL_ARB_robustness */
GLenum ResetStrategy;
+ /* GL_ARB_blend_func_extended */
+ GLuint MaxDualSourceDrawBuffers;
+
/**
* Whether the implementation strips out and ignores texture borders.
*
diff --git a/src/mesa/main/shader_query.cpp b/src/mesa/main/shader_query.cpp
index 8ab1812..f39c452 100644
--- a/src/mesa/main/shader_query.cpp
+++ b/src/mesa/main/shader_query.cpp
@@ -239,10 +239,73 @@ void GLAPIENTRY
_mesa_BindFragDataLocation(GLuint program, GLuint colorNumber,
const GLchar *name)
{
+ _mesa_BindFragDataLocationIndexed(program, colorNumber, 0, name);
+}
+
+GLint GLAPIENTRY
+_mesa_GetFragDataLocation(GLuint program, const GLchar *name)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_shader_program *const shProg =
+ _mesa_lookup_shader_program_err(ctx, program, "glGetFragDataLocation");
+
+ if (!shProg) {
+ return -1;
+ }
+
+ if (!shProg->LinkStatus) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetFragDataLocation(program not linked)");
+ return -1;
+ }
+
+ if (!name)
+ return -1;
+
+ if (strncmp(name, "gl_", 3) == 0) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glGetFragDataLocation(illegal name)");
+ return -1;
+ }
+
+ /* Not having a fragment shader is not an error.
+ */
+ if (shProg->_LinkedShaders[MESA_SHADER_FRAGMENT] == NULL)
+ return -1;
+
+ exec_list *ir = shProg->_LinkedShaders[MESA_SHADER_FRAGMENT]->ir;
+ foreach_list(node, ir) {
+ const ir_variable *const var = ((ir_instruction *) node)->as_variable();
+
+ /* The extra check against FRAG_RESULT_DATA0 is because
+ * glGetFragDataLocation cannot be used on "conventional" attributes.
+ *
+ * From page 95 of the OpenGL 3.0 spec:
+ *
+ * "If name is not an active attribute, if name is a conventional
+ * attribute, or if an error occurs, -1 will be returned."
+ */
+ if (var == NULL
+ || var->mode != ir_var_out
+ || var->location == -1
+ || var->location < FRAG_RESULT_DATA0)
+ continue;
+
+ if (strcmp(var->name, name) == 0)
+ return var->location - FRAG_RESULT_DATA0;
+ }
+
+ return -1;
+}
+
+void GLAPIENTRY
+_mesa_BindFragDataLocationIndexed(GLuint program, GLuint colorNumber,
+ GLuint index, const GLchar *name)
+{
GET_CURRENT_CONTEXT(ctx);
struct gl_shader_program *const shProg =
- _mesa_lookup_shader_program_err(ctx, program, "glBindFragDataLocation");
+ _mesa_lookup_shader_program_err(ctx, program, "glBindFragDataLocationIndexed");
if (!shProg)
return;
@@ -250,13 +313,22 @@ _mesa_BindFragDataLocation(GLuint program, GLuint colorNumber,
return;
if (strncmp(name, "gl_", 3) == 0) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glBindFragDataLocation(illegal name)");
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glBindFragDataLocationIndexed(illegal name)");
+ return;
+ }
+
+ if (index > 1) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glBindFragDataLocationIndexed(index)");
+ return;
+ }
+
+ if (index == 0 && colorNumber >= ctx->Const.MaxDrawBuffers) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glBindFragDataLocationIndexed(colorNumber)");
return;
}
- if (colorNumber >= ctx->Const.MaxDrawBuffers) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glBindFragDataLocation(index)");
+ if (index == 1 && colorNumber >= ctx->Const.MaxDualSourceDrawBuffers) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glBindFragDataLocationIndexed(colorNumber)");
return;
}
@@ -265,19 +337,20 @@ _mesa_BindFragDataLocation(GLuint program, GLuint colorNumber,
* between built-in attributes and user-defined attributes.
*/
shProg->FragDataBindings->put(colorNumber + FRAG_RESULT_DATA0, name);
-
+ shProg->FragDataIndexBindings->put(index, name);
/*
* Note that this binding won't go into effect until
* glLinkProgram is called again.
*/
+
}
GLint GLAPIENTRY
-_mesa_GetFragDataLocation(GLuint program, const GLchar *name)
+_mesa_GetFragDataIndex(GLuint program, const GLchar *name)
{
GET_CURRENT_CONTEXT(ctx);
struct gl_shader_program *const shProg =
- _mesa_lookup_shader_program_err(ctx, program, "glGetFragDataLocation");
+ _mesa_lookup_shader_program_err(ctx, program, "glGetFragDataIndex");
if (!shProg) {
return -1;
@@ -285,7 +358,7 @@ _mesa_GetFragDataLocation(GLuint program, const GLchar *name)
if (!shProg->LinkStatus) {
_mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetFragDataLocation(program not linked)");
+ "glGetFragDataIndex(program not linked)");
return -1;
}
@@ -294,7 +367,7 @@ _mesa_GetFragDataLocation(GLuint program, const GLchar *name)
if (strncmp(name, "gl_", 3) == 0) {
_mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetFragDataLocation(illegal name)");
+ "glGetFragDataIndex(illegal name)");
return -1;
}
@@ -316,13 +389,13 @@ _mesa_GetFragDataLocation(GLuint program, const GLchar *name)
* attribute, or if an error occurs, -1 will be returned."
*/
if (var == NULL
- || var->mode != ir_var_out
- || var->location == -1
- || var->location < FRAG_RESULT_DATA0)
- continue;
+ || var->mode != ir_var_out
+ || var->location == -1
+ || var->location < FRAG_RESULT_DATA0)
+ continue;
if (strcmp(var->name, name) == 0)
- return var->location - FRAG_RESULT_DATA0;
+ return var->index;
}
return -1;
diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
index 0e655a0..e0f20b6 100644
--- a/src/mesa/main/shaderapi.c
+++ b/src/mesa/main/shaderapi.c
@@ -1748,6 +1748,9 @@ _mesa_init_shader_dispatch(struct _glapi_table *exec)
SET_ReleaseShaderCompiler(exec, _mesa_ReleaseShaderCompiler);
SET_GetShaderPrecisionFormat(exec, _mesa_GetShaderPrecisionFormat);
+ /* GL_ARB_blend_func_extended */
+ SET_BindFragDataLocationIndexed(exec, _mesa_BindFragDataLocationIndexed);
+ SET_GetFragDataIndex(exec, _mesa_GetFragDataIndex);
#endif /* FEATURE_GL */
}
diff --git a/src/mesa/main/shaderapi.h b/src/mesa/main/shaderapi.h
index 0ffebdb..4886959 100644
--- a/src/mesa/main/shaderapi.h
+++ b/src/mesa/main/shaderapi.h
@@ -86,6 +86,9 @@ _mesa_GetAttachedObjectsARB(GLhandleARB, GLsizei, GLsizei *, GLhandleARB *);
extern GLint GLAPIENTRY
_mesa_GetFragDataLocation(GLuint program, const GLchar *name);
+extern GLint GLAPIENTRY
+_mesa_GetFragDataIndex(GLuint program, const GLchar *name);
+
extern GLhandleARB GLAPIENTRY
_mesa_GetHandleARB(GLenum pname);
@@ -128,6 +131,10 @@ _mesa_BindFragDataLocation(GLuint program, GLuint colorNumber,
const GLchar *name);
extern void GLAPIENTRY
+_mesa_BindFragDataLocationIndexed(GLuint program, GLuint colorNumber,
+ GLuint index, const GLchar *name);
+
+extern void GLAPIENTRY
_mesa_GetActiveAttribARB(GLhandleARB, GLuint, GLsizei, GLsizei *, GLint *,
GLenum *, GLcharARB *);
diff --git a/src/mesa/main/shaderobj.c b/src/mesa/main/shaderobj.c
index 36f208d..7eb6f0b 100644
--- a/src/mesa/main/shaderobj.c
+++ b/src/mesa/main/shaderobj.c
@@ -242,6 +242,7 @@ _mesa_init_shader_program(struct gl_context *ctx, struct gl_shader_program *prog
prog->AttributeBindings = string_to_uint_map_ctor();
prog->FragDataBindings = string_to_uint_map_ctor();
+ prog->FragDataIndexBindings = string_to_uint_map_ctor();
#if FEATURE_ARB_geometry_shader4
prog->Geom.VerticesOut = 0;
@@ -319,6 +320,11 @@ _mesa_free_shader_program_data(struct gl_context *ctx,
shProg->FragDataBindings = NULL;
}
+ if (shProg->FragDataIndexBindings) {
+ string_to_uint_map_dtor(shProg->FragDataIndexBindings);
+ shProg->FragDataIndexBindings = NULL;
+ }
+
/* detach shaders */
for (i = 0; i < shProg->NumShaders; i++) {
_mesa_reference_shader(ctx, &shProg->Shaders[i], NULL);
--
1.7.7.6
More information about the mesa-dev
mailing list