[Mesa-dev] [PATCH 03/10] mesa: add PIPE_SHADER_* like constants and conversions to/from enums

Luca Barbieri luca at luca-barbieri.com
Sun Sep 5 18:30:45 PDT 2010


This includes tessellation shaders.
---
 src/mesa/main/mtypes.h     |   17 +++++++++++++++++
 src/mesa/main/shaderobj.h  |   39 +++++++++++++++++++++++++++++++++++++++
 src/mesa/program/program.h |   38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 94 insertions(+), 0 deletions(-)

diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 4c1ec5c..d2d7b10 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -41,6 +41,23 @@
 #include "math/m_matrix.h"	/* GLmatrix */
 #include "main/simple_list.h"	/* struct simple_node */
 
+/* TODO: remove these once the headers have GL_NV_tessellation_program5 */
+#ifndef GL_TESS_CONTROL_PROGRAM_NV
+#define GL_TESS_CONTROL_PROGRAM_NV 0x891E
+#endif
+
+#ifndef GL_TESS_EVALUATION_PROGRAM_NV
+#define GL_TESS_EVALUATION_PROGRAM_NV 0x891F
+#endif
+
+/* Shader stages */
+#define MESA_SHADER_VERTEX   0
+#define MESA_SHADER_FRAGMENT 1
+#define MESA_SHADER_GEOMETRY 2
+#define MESA_SHADER_TESSCTRL 3
+#define MESA_SHADER_TESSEVAL 4
+#define MESA_SHADER_TYPES    5
+
 /**
  * Color channel data type.
  */
diff --git a/src/mesa/main/shaderobj.h b/src/mesa/main/shaderobj.h
index 4800046..791b423 100644
--- a/src/mesa/main/shaderobj.h
+++ b/src/mesa/main/shaderobj.h
@@ -96,6 +96,45 @@ _mesa_init_shader_state(GLcontext *ctx);
 extern void
 _mesa_free_shader_state(GLcontext *ctx);
 
+/* keep these in the same order as TGSI_PROCESSOR_* */
+
+static INLINE GLuint
+_mesa_shader_type_to_index(GLenum v)
+{
+   switch(v)
+   {
+   case GL_VERTEX_SHADER:
+      return MESA_SHADER_VERTEX;
+   case GL_FRAGMENT_SHADER:
+      return MESA_SHADER_FRAGMENT;
+   case GL_GEOMETRY_SHADER:
+      return MESA_SHADER_GEOMETRY;
+   case GL_TESS_CONTROL_SHADER:
+      return MESA_SHADER_TESSCTRL;
+   case GL_TESS_EVALUATION_SHADER:
+      return MESA_SHADER_TESSEVAL;
+   default:
+      ASSERT(0);
+      return ~0;
+   }
+}
+
+static INLINE GLenum
+_mesa_shader_index_to_type(GLuint i)
+{
+   GLenum enums[MESA_SHADER_TYPES] = {
+         GL_VERTEX_SHADER,
+         GL_FRAGMENT_SHADER,
+         GL_GEOMETRY_SHADER ,
+         GL_TESS_CONTROL_SHADER,
+         GL_TESS_EVALUATION_SHADER
+   };
+   if(i >= MESA_SHADER_TYPES)
+      return 0;
+   else
+      return enums[i];
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/mesa/program/program.h b/src/mesa/program/program.h
index 286573d..a5fbb39 100644
--- a/src/mesa/program/program.h
+++ b/src/mesa/program/program.h
@@ -167,5 +167,43 @@ _mesa_find_free_register(const GLboolean used[],
 extern void
 _mesa_postprocess_program(GLcontext *ctx, struct gl_program *prog);
 
+/* keep these in the same order as TGSI_PROCESSOR_* */
+
+static INLINE GLuint
+_mesa_program_target_to_index(GLenum v)
+{
+   switch(v)
+   {
+   case GL_VERTEX_PROGRAM_ARB:
+      return MESA_SHADER_VERTEX;
+   case GL_FRAGMENT_PROGRAM_ARB:
+      return MESA_SHADER_FRAGMENT;
+   case GL_GEOMETRY_PROGRAM_NV:
+      return MESA_SHADER_GEOMETRY;
+   case GL_TESS_CONTROL_PROGRAM_NV:
+      return MESA_SHADER_TESSCTRL;
+   case GL_TESS_EVALUATION_PROGRAM_NV:
+      return MESA_SHADER_TESSEVAL;
+   default:
+      ASSERT(0);
+      return ~0;
+   }
+}
+
+static INLINE GLenum
+_mesa_program_index_to_target(GLuint i)
+{
+   GLenum enums[MESA_SHADER_TYPES] = {
+         GL_VERTEX_PROGRAM_ARB,
+         GL_FRAGMENT_PROGRAM_ARB,
+         GL_GEOMETRY_PROGRAM_NV,
+         GL_TESS_CONTROL_PROGRAM_NV,
+         GL_TESS_EVALUATION_PROGRAM_NV
+   };
+   if(i >= MESA_SHADER_TYPES)
+      return 0;
+   else
+      return enums[i];
+}
 
 #endif /* PROGRAM_H */
-- 
1.7.0.4



More information about the mesa-dev mailing list