glsl2: Add a constructor for _mesa_glsl_parse_state
authorIan Romanick <ian.d.romanick@intel.com>
Sun, 18 Jul 2010 22:59:43 +0000 (15:59 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Wed, 21 Jul 2010 00:48:24 +0000 (17:48 -0700)
Coming changes to the handling of built-in functions necessitate this.

src/glsl/Makefile
src/glsl/glsl_parser_extras.cpp
src/glsl/glsl_parser_extras.h
src/mesa/shader/ir_to_mesa.cpp

index 7bf95fbfc2d0998fa6e6301f01b43c882ea2ec12..2b040377b0ca724b2913d4cedf4e9b08dd9bae34 100644 (file)
@@ -93,6 +93,7 @@ INCLUDES = \
        -I../mesa \
        -I../mapi \
        -I../mesa/shader \
+       -I../../include \
        $(LIBRARY_INCLUDES)
 
 ALL_SOURCES = \
index cb7b6d36a2d883be5d7deb5524ad80b1ab3e004a..bcf2579733de9cf284a6bdf166f31e42a7a30a49 100644 (file)
@@ -34,6 +34,47 @@ extern "C" {
 #include "glsl_parser_extras.h"
 #include "glsl_parser.h"
 
+_mesa_glsl_parse_state::_mesa_glsl_parse_state(struct __GLcontextRec *ctx,
+                                              GLenum target, void *mem_ctx)
+{
+   switch (target) {
+   case GL_VERTEX_SHADER:   this->target = vertex_shader; break;
+   case GL_FRAGMENT_SHADER: this->target = fragment_shader; break;
+   case GL_GEOMETRY_SHADER: this->target = geometry_shader; break;
+   }
+
+   this->scanner = NULL;
+   this->translation_unit.make_empty();
+   this->symbols = new(mem_ctx) glsl_symbol_table;
+   this->info_log = talloc_strdup(mem_ctx, "");
+   this->error = false;
+   this->loop_or_switch_nesting = NULL;
+   this->ARB_texture_rectangle_enable = true;
+
+   if (ctx != NULL) {
+      this->extensions = &ctx->Extensions;
+
+      this->Const.MaxLights = ctx->Const.MaxLights;
+      this->Const.MaxClipPlanes = ctx->Const.MaxClipPlanes;
+      this->Const.MaxTextureUnits = ctx->Const.MaxTextureUnits;
+      this->Const.MaxTextureCoords = ctx->Const.MaxTextureCoordUnits;
+      this->Const.MaxVertexAttribs = ctx->Const.VertexProgram.MaxAttribs;
+      this->Const.MaxVertexUniformComponents = ctx->Const.VertexProgram.MaxUniformComponents;
+      this->Const.MaxVaryingFloats = ctx->Const.MaxVarying * 4;
+      this->Const.MaxVertexTextureImageUnits = ctx->Const.MaxVertexTextureImageUnits;
+      this->Const.MaxCombinedTextureImageUnits = ctx->Const.MaxCombinedTextureImageUnits;
+      this->Const.MaxTextureImageUnits = ctx->Const.MaxTextureImageUnits;
+      this->Const.MaxFragmentUniformComponents = ctx->Const.FragmentProgram.MaxUniformComponents;
+
+      this->Const.MaxDrawBuffers = ctx->Const.MaxDrawBuffers;
+   } else {
+      static struct gl_extensions null_extensions;
+
+      memset(&null_extensions, 0, sizeof(null_extensions));
+      this->extensions = &null_extensions;
+   }
+}
+
 const char *
 _mesa_glsl_shader_target_name(enum _mesa_glsl_parser_targets target)
 {
index fed6e8c823f030cb5eb9e810cc962c8e61453bee..e2efbd9ac9fcfa10dedb1c13407c4b77dda54d44 100644 (file)
@@ -35,7 +35,29 @@ enum _mesa_glsl_parser_targets {
    ir_shader
 };
 
+struct __GLcontextRec;
+
 struct _mesa_glsl_parse_state {
+   _mesa_glsl_parse_state(struct __GLcontextRec *ctx, GLenum target,
+                         void *mem_ctx);
+
+   /* Callers of this talloc-based new need not call delete. It's
+    * easier to just talloc_free 'ctx' (or any of its ancestors). */
+   static void* operator new(size_t size, void *ctx)
+   {
+      void *mem = talloc_zero_size(ctx, size);
+      assert(mem != NULL);
+
+      return mem;
+   }
+
+   /* If the user *does* call delete, that's OK, we will just
+    * talloc_free in that case. */
+   static void operator delete(void *mem)
+   {
+      talloc_free(mem);
+   }
+
    void *scanner;
    exec_list translation_unit;
    glsl_symbol_table *symbols;
index 7cc469f3a726d81f94412a2b4072a1f64a3d4ee4..1a9b0e3948195977cbf36f9ad2b03e3adfb7873e 100644 (file)
@@ -2155,38 +2155,8 @@ steal_memory(ir_instruction *ir, void *new_ctx)
 void
 _mesa_glsl_compile_shader(GLcontext *ctx, struct gl_shader *shader)
 {
-   struct _mesa_glsl_parse_state *state;
-
-   state = talloc_zero(shader, struct _mesa_glsl_parse_state);
-   switch (shader->Type) {
-   case GL_VERTEX_SHADER:   state->target = vertex_shader; break;
-   case GL_FRAGMENT_SHADER: state->target = fragment_shader; break;
-   case GL_GEOMETRY_SHADER: state->target = geometry_shader; break;
-   }
-
-   state->scanner = NULL;
-   state->translation_unit.make_empty();
-   state->symbols = new(shader) glsl_symbol_table;
-   state->info_log = talloc_strdup(shader, "");
-   state->error = false;
-   state->loop_or_switch_nesting = NULL;
-   state->ARB_texture_rectangle_enable = true;
-
-   state->extensions = &ctx->Extensions;
-
-   state->Const.MaxLights = ctx->Const.MaxLights;
-   state->Const.MaxClipPlanes = ctx->Const.MaxClipPlanes;
-   state->Const.MaxTextureUnits = ctx->Const.MaxTextureUnits;
-   state->Const.MaxTextureCoords = ctx->Const.MaxTextureCoordUnits;
-   state->Const.MaxVertexAttribs = ctx->Const.VertexProgram.MaxAttribs;
-   state->Const.MaxVertexUniformComponents = ctx->Const.VertexProgram.MaxUniformComponents;
-   state->Const.MaxVaryingFloats = ctx->Const.MaxVarying * 4;
-   state->Const.MaxVertexTextureImageUnits = ctx->Const.MaxVertexTextureImageUnits;
-   state->Const.MaxCombinedTextureImageUnits = ctx->Const.MaxCombinedTextureImageUnits;
-   state->Const.MaxTextureImageUnits = ctx->Const.MaxTextureImageUnits;
-   state->Const.MaxFragmentUniformComponents = ctx->Const.FragmentProgram.MaxUniformComponents;
-
-   state->Const.MaxDrawBuffers = ctx->Const.MaxDrawBuffers;
+   struct _mesa_glsl_parse_state *state =
+      new(shader) _mesa_glsl_parse_state(ctx, shader->Type, shader);
 
    const char *source = shader->Source;
    state->error = preprocess(state, &source, &state->info_log,