summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2010-10-11 15:21:17 -0700
committerIan Romanick <[email protected]>2010-10-13 15:35:18 -0700
commit5cb24c4a75cd0b45bb332721c3d0e5a1f928b6f4 (patch)
tree707a362844154f254be46beea9e757dfb8dc8a4f
parentbabe20b9d188ed94a5ecab30d829dd3f4ad728b5 (diff)
mesa: Refactor validation of shader targets
Actually validate that the implementation supports the particular shader target as well. Previously if a driver only supported vertex shaders, for example, glCreateShaderObjectARB would gladly create a fragment shader. NOTE: this is a candidate for the 7.9 branch.
-rw-r--r--src/mesa/main/shaderapi.c43
1 files changed, 33 insertions, 10 deletions
diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
index 9a2a42e50e4..c90e5b74cb6 100644
--- a/src/mesa/main/shaderapi.c
+++ b/src/mesa/main/shaderapi.c
@@ -47,7 +47,7 @@
#include "program/prog_parameter.h"
#include "program/prog_uniform.h"
#include "talloc.h"
-
+#include <stdbool.h>
/** Define this to enable shader substitution (see below) */
#define SHADER_SUBST 0
@@ -202,6 +202,35 @@ _mesa_copy_string(GLchar *dst, GLsizei maxLength,
/**
+ * Confirm that the a shader type is valid and supported by the implementation
+ *
+ * \param ctx Current GL context
+ * \param type Shader target
+ *
+ */
+static bool
+validate_shader_target(const struct gl_context *ctx, GLenum type)
+{
+ switch (type) {
+#if FEATURE_ARB_fragment_shader
+ case GL_FRAGMENT_SHADER:
+ return ctx->Extensions.ARB_fragment_shader;
+#endif
+#if FEATURE_ARB_vertex_shader
+ case GL_VERTEX_SHADER:
+ return ctx->Extensions.ARB_vertex_shader;
+#endif
+#if FEATURE_ARB_geometry_shader4
+ case GL_GEOMETRY_SHADER_ARB:
+ return ctx->Extensions.ARB_geometry_shader4;
+#endif
+ default:
+ return false;
+ }
+}
+
+
+/**
* Find the length of the longest transform feedback varying name
* which was specified with glTransformFeedbackVaryings().
*/
@@ -376,19 +405,13 @@ create_shader(struct gl_context *ctx, GLenum type)
struct gl_shader *sh;
GLuint name;
- name = _mesa_HashFindFreeKeyBlock(ctx->Shared->ShaderObjects, 1);
-
- switch (type) {
- case GL_FRAGMENT_SHADER:
- case GL_VERTEX_SHADER:
- case GL_GEOMETRY_SHADER_ARB:
- sh = ctx->Driver.NewShader(ctx, name, type);
- break;
- default:
+ if (!validate_shader_target(ctx, type)) {
_mesa_error(ctx, GL_INVALID_ENUM, "CreateShader(type)");
return 0;
}
+ name = _mesa_HashFindFreeKeyBlock(ctx->Shared->ShaderObjects, 1);
+ sh = ctx->Driver.NewShader(ctx, name, type);
_mesa_HashInsert(ctx->Shared->ShaderObjects, name, sh);
return name;