summaryrefslogtreecommitdiff
path: root/src/mesa/shader/slang/slang_simplify.c
diff options
context:
space:
mode:
authorBrian <brian@yutani.localnet.net>2007-02-02 12:01:29 -0700
committerBrian <brian@yutani.localnet.net>2007-02-02 12:01:29 -0700
commit70570d41996a3754be973ffdc34cd3ae4267878d (patch)
tree309e8ba0bf5525f31a81f627be7cc4dc2be3521e /src/mesa/shader/slang/slang_simplify.c
parent5c2174778360bd493573951d378e29f7097abf5b (diff)
Move guts of slang_lookup_constant() into a new function in slang_simplify.c
Diffstat (limited to 'src/mesa/shader/slang/slang_simplify.c')
-rw-r--r--src/mesa/shader/slang/slang_simplify.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/mesa/shader/slang/slang_simplify.c b/src/mesa/shader/slang/slang_simplify.c
index c71313a7bb..19e627489f 100644
--- a/src/mesa/shader/slang/slang_simplify.c
+++ b/src/mesa/shader/slang/slang_simplify.c
@@ -30,12 +30,57 @@
#include "imports.h"
#include "macros.h"
+#include "get.h"
#include "slang_compile.h"
#include "slang_codegen.h"
#include "slang_simplify.h"
#include "slang_print.h"
+
+
+/**
+ * Lookup the value of named constant, such as gl_MaxLights.
+ * \return value of constant, or -1 if unknown
+ */
+GLint
+_slang_lookup_constant(const char *name)
+{
+ struct constant_info {
+ const char *Name;
+ const GLenum Token;
+ };
+ static const struct constant_info info[] = {
+ { "gl_MaxClipPlanes", GL_MAX_CLIP_PLANES },
+ { "gl_MaxCombinedTextureImageUnits", GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS },
+ { "gl_MaxDrawBuffers", GL_MAX_DRAW_BUFFERS },
+ { "gl_MaxFragmentUniformComponents", GL_MAX_FRAGMENT_UNIFORM_COMPONENTS },
+ { "gl_MaxLights", GL_MAX_LIGHTS },
+ { "gl_MaxTextureUnits", GL_MAX_TEXTURE_UNITS },
+ { "gl_MaxTextureCoords", GL_MAX_TEXTURE_COORDS },
+ { "gl_MaxVertexAttribs", GL_MAX_VERTEX_ATTRIBS },
+ { "gl_MaxVertexUniformComponents", GL_MAX_VERTEX_UNIFORM_COMPONENTS },
+ { "gl_MaxVaryingFloats", GL_MAX_VARYING_FLOATS },
+ { "gl_MaxVertexTextureImageUnits", GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS },
+ { "gl_MaxTextureImageUnits", GL_MAX_TEXTURE_IMAGE_UNITS },
+ { NULL, 0 }
+ };
+ GLuint i;
+
+ for (i = 0; info[i].Name; i++) {
+ if (strcmp(info[i].Name, name) == 0) {
+ /* found */
+ GLint value = -1.0;
+ _mesa_GetIntegerv(info[i].Token, &value);
+ ASSERT(value >= 0); /* sanity check that glGetFloatv worked */
+ return value;
+ }
+ }
+ return -1;
+}
+
+
+
/**
* Recursively traverse an AST tree, applying simplifications wherever
* possible.
@@ -52,6 +97,19 @@ _slang_simplify(slang_operation *oper,
GLboolean isBool[4];
GLuint i, n;
+ if (oper->type == slang_oper_identifier) {
+ /* see if it's a named constant */
+ GLint value = _slang_lookup_constant((char *) oper->a_id);
+ if (value >= 0) {
+ oper->literal[0] =
+ oper->literal[1] =
+ oper->literal[2] =
+ oper->literal[3] = value;
+ oper->type = slang_oper_literal_int;
+ return;
+ }
+ }
+
/* first, simplify children */
for (i = 0; i < oper->num_children; i++) {
_slang_simplify(&oper->children[i], space, atoms);