--- /dev/null
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version: 6.5\r
+ *\r
+ * Copyright (C) 2006 Brian Paul All Rights Reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ *\r
+ * Authors:\r
+ * Michal Krol\r
+ */\r
+\r
+#include "glheader.h"\r
+#include "imports.h"\r
+#include "macros.h"\r
+#include "shaderobjects.h"\r
+#include "t_pipeline.h"\r
+#include "slang_utility.h"\r
+\r
+typedef struct\r
+{\r
+ GLvector4f outputs[VERT_RESULT_MAX];\r
+ GLvector4f ndc_coords;\r
+ GLubyte *clipmask;\r
+ GLubyte ormask;\r
+ GLubyte andmask;\r
+} arbvs_stage_data;\r
+\r
+#define ARBVS_STAGE_DATA(stage) ((arbvs_stage_data *) stage->privatePtr)\r
+\r
+static GLboolean construct_arb_vertex_shader (GLcontext *ctx, struct tnl_pipeline_stage *stage)\r
+{\r
+ TNLcontext *tnl = TNL_CONTEXT(ctx);\r
+ struct vertex_buffer *vb = &tnl->vb;\r
+ arbvs_stage_data *store;\r
+ GLuint size = vb->Size;\r
+ GLuint i;\r
+\r
+ stage->privatePtr = _mesa_malloc (sizeof (arbvs_stage_data));\r
+ store = ARBVS_STAGE_DATA(stage);\r
+ if (store == NULL)\r
+ return GL_FALSE;\r
+\r
+ for (i = 0; i < VERT_RESULT_MAX; i++)\r
+ {\r
+ _mesa_vector4f_alloc (&store->outputs[i], 0, size, 32);\r
+ store->outputs[i].size = 4;\r
+ }\r
+ _mesa_vector4f_alloc (&store->ndc_coords, 0, size, 32);\r
+ store->clipmask = (GLubyte *) ALIGN_MALLOC (size, 32);\r
+\r
+ return GL_TRUE;\r
+}\r
+\r
+static void destruct_arb_vertex_shader (struct tnl_pipeline_stage *stage)\r
+{\r
+ arbvs_stage_data *store = ARBVS_STAGE_DATA(stage);\r
+\r
+ if (store != NULL)\r
+ {\r
+ GLuint i;\r
+\r
+ for (i = 0; i < VERT_RESULT_MAX; i++)\r
+ _mesa_vector4f_free (&store->outputs[i]);\r
+ _mesa_vector4f_free (&store->ndc_coords);\r
+ ALIGN_FREE (store->clipmask);\r
+\r
+ _mesa_free (store);\r
+ stage->privatePtr = NULL;\r
+ }\r
+}\r
+\r
+static void validate_arb_vertex_shader (GLcontext *ctx, struct tnl_pipeline_stage *stage)\r
+{\r
+}\r
+\r
+/* XXX */\r
+extern void exec_vertex_shader (struct gl2_vertex_shader_intf **vs);\r
+extern int _slang_fetch_float (struct gl2_vertex_shader_intf **, const char *, GLfloat *, int);\r
+extern int _slang_fetch_vec3 (struct gl2_vertex_shader_intf **, const char *, GLfloat *, int);\r
+extern int _slang_fetch_vec4 (struct gl2_vertex_shader_intf **, const char *, GLfloat *, GLuint, int);\r
+extern int _slang_fetch_mat4 (struct gl2_vertex_shader_intf **, const char *, GLfloat *, GLuint, int);\r
+\r
+static void fetch_input_float (const char *name, GLuint attr, GLuint i, struct vertex_buffer *vb,\r
+ struct gl2_vertex_shader_intf **vs)\r
+{\r
+ const GLubyte *ptr = (const GLubyte *) vb->AttribPtr[attr]->data;\r
+ const GLuint size = vb->AttribPtr[attr]->size;\r
+ const GLuint stride = vb->AttribPtr[attr]->stride;\r
+ const GLfloat *data = (const GLfloat *) (ptr + stride * i);\r
+ float vec[1];\r
+\r
+ vec[0] = data[0];\r
+ _slang_fetch_float (vs, name, vec, 1);\r
+}\r
+\r
+static void fetch_input_vec3 (const char *name, GLuint attr, GLuint i, struct vertex_buffer *vb,\r
+ struct gl2_vertex_shader_intf **vs)\r
+{\r
+ const GLubyte *ptr = (const GLubyte *) vb->AttribPtr[attr]->data;\r
+ const GLuint size = vb->AttribPtr[attr]->size;\r
+ const GLuint stride = vb->AttribPtr[attr]->stride;\r
+ const GLfloat *data = (const GLfloat *) (ptr + stride * i);\r
+ float vec[3];\r
+\r
+ vec[0] = data[0];\r
+ vec[1] = data[1];\r
+ vec[2] = data[2];\r
+ _slang_fetch_vec3 (vs, name, vec, 1);\r
+}\r
+\r
+static void fetch_input_vec4 (const char *name, GLuint attr, GLuint i, struct vertex_buffer *vb,\r
+ struct gl2_vertex_shader_intf **vs)\r
+{\r
+ const GLubyte *ptr = (const GLubyte *) vb->AttribPtr[attr]->data;\r
+ const GLuint size = vb->AttribPtr[attr]->size;\r
+ const GLuint stride = vb->AttribPtr[attr]->stride;\r
+ const GLfloat *data = (const GLfloat *) (ptr + stride * i);\r
+ float vec[4];\r
+\r
+ switch (size)\r
+ {\r
+ case 2:\r
+ vec[0] = data[0];\r
+ vec[1] = data[1];\r
+ vec[2] = 0.0f;\r
+ vec[3] = 1.0f;\r
+ break;\r
+ case 3:\r
+ vec[0] = data[0];\r
+ vec[1] = data[1];\r
+ vec[2] = data[2];\r
+ vec[3] = 1.0f;\r
+ break;\r
+ case 4:\r
+ vec[0] = data[0];\r
+ vec[1] = data[1];\r
+ vec[2] = data[2];\r
+ vec[3] = data[3];\r
+ break;\r
+ }\r
+ _slang_fetch_vec4 (vs, name, vec, 0, 1);\r
+}\r
+\r
+static void fetch_output_float (const char *name, GLuint attr, GLuint i, arbvs_stage_data *store,\r
+ struct gl2_vertex_shader_intf **vs)\r
+{\r
+ float vec[1];\r
+\r
+ _slang_fetch_float (vs, name, vec, 0);\r
+ _mesa_memcpy (&store->outputs[attr].data[i], vec, 4);\r
+}\r
+\r
+static void fetch_output_vec4 (const char *name, GLuint attr, GLuint i, GLuint index,\r
+ arbvs_stage_data *store, struct gl2_vertex_shader_intf **vs)\r
+{\r
+ float vec[4];\r
+\r
+ _slang_fetch_vec4 (vs, name, vec, index, 0);\r
+ _mesa_memcpy (&store->outputs[attr].data[i], vec, 16);\r
+}\r
+\r
+static void fetch_uniform_mat4 (const char *name, const GLmatrix *matrix, GLuint index,\r
+ struct gl2_vertex_shader_intf **vs)\r
+{\r
+ _slang_fetch_mat4 (vs, name, matrix->m, index, 1);\r
+}\r
+\r
+static GLboolean run_arb_vertex_shader (GLcontext *ctx, struct tnl_pipeline_stage *stage)\r
+{\r
+ TNLcontext *tnl = TNL_CONTEXT(ctx);\r
+ struct vertex_buffer *vb = &tnl->vb;\r
+ arbvs_stage_data *store = ARBVS_STAGE_DATA(stage);\r
+ struct gl2_program_intf **prog;\r
+ struct gl2_vertex_shader_intf **vs = NULL;\r
+ GLsizei count, i, j;\r
+\r
+ prog = ctx->ShaderObjects.CurrentProgram;\r
+ if (prog == NULL)\r
+ return GL_TRUE;\r
+\r
+ count = (**prog)._container.GetAttachedCount ((struct gl2_container_intf **) prog);\r
+ for (i = 0; i < count; i++)\r
+ {\r
+ struct gl2_generic_intf **obj;\r
+ struct gl2_unknown_intf **unk;\r
+\r
+ obj = (**prog)._container.GetAttached ((struct gl2_container_intf **) prog, i);\r
+ unk = (**obj)._unknown.QueryInterface ((struct gl2_unknown_intf **) obj, UIID_VERTEX_SHADER);\r
+ (**obj)._unknown.Release ((struct gl2_unknown_intf **) obj);\r
+ if (unk != NULL)\r
+ {\r
+ vs = (struct gl2_vertex_shader_intf **) unk;\r
+ break;\r
+ }\r
+ }\r
+ if (vs == NULL)\r
+ return GL_TRUE;\r
+\r
+ fetch_uniform_mat4 ("gl_ModelViewMatrix", ctx->ModelviewMatrixStack.Top, 0, vs);\r
+ fetch_uniform_mat4 ("gl_ProjectionMatrix", ctx->ProjectionMatrixStack.Top, 0, vs);\r
+ fetch_uniform_mat4 ("gl_ModelViewProjectionMatrix", &ctx->_ModelProjectMatrix, 0, vs);\r
+ for (j = 0; j < 8; j++)\r
+ fetch_uniform_mat4 ("gl_TextureMatrix", ctx->TextureMatrixStack[j].Top, j, vs);\r
+ /* XXX: fetch uniform mat3 gl_NormalMatrix */\r
+ /* XXX: fetch uniform mat4 gl_ModelViewMatrixInverse */\r
+ /* XXX: fetch uniform mat4 gl_ProjectionMatrixInverse */\r
+ /* XXX: fetch uniform mat4 gl_ModelViewProjectionMatrixInverse */\r
+ /* XXX: fetch uniform mat4 gl_TextureMatrixInverse */\r
+ /* XXX: fetch uniform mat4 gl_ModelViewMatrixTranspose */\r
+ /* XXX: fetch uniform mat4 gl_ProjectionMatrixTranspose */\r
+ /* XXX: fetch uniform mat4 gl_ModelViewProjectionMatrixTranspose */\r
+ /* XXX: fetch uniform mat4 gl_TextureMatrixTranspose */\r
+ /* XXX: fetch uniform mat4 gl_ModelViewMatrixInverseTranspose */\r
+ /* XXX: fetch uniform mat4 gl_ProjectionMatrixInverseTranspose */\r
+ /* XXX: fetch uniform mat4 gl_ModelViewProjectionMatrixInverseTranspose */\r
+ /* XXX: fetch uniform mat4 gl_TextureMatrixInverseTranspose */\r
+ /* XXX: fetch uniform float gl_NormalScale */\r
+ /* XXX: fetch uniform mat4 gl_ClipPlane */\r
+ /* XXX: fetch uniform mat4 gl_TextureEnvColor */\r
+ /* XXX: fetch uniform mat4 gl_EyePlaneS */\r
+ /* XXX: fetch uniform mat4 gl_EyePlaneT */\r
+ /* XXX: fetch uniform mat4 gl_EyePlaneR */\r
+ /* XXX: fetch uniform mat4 gl_EyePlaneQ */\r
+ /* XXX: fetch uniform mat4 gl_ObjectPlaneS */\r
+ /* XXX: fetch uniform mat4 gl_ObjectPlaneT */\r
+ /* XXX: fetch uniform mat4 gl_ObjectPlaneR */\r
+ /* XXX: fetch uniform mat4 gl_ObjectPlaneQ */\r
+\r
+ for (i = 0; i < vb->Count; i++)\r
+ {\r
+ fetch_input_vec4 ("gl_Vertex", _TNL_ATTRIB_POS, i, vb, vs);\r
+ fetch_input_vec3 ("gl_Normal", _TNL_ATTRIB_NORMAL, i, vb, vs);\r
+ fetch_input_vec4 ("gl_Color", _TNL_ATTRIB_COLOR0, i, vb, vs);\r
+ fetch_input_vec4 ("gl_SecondaryColor", _TNL_ATTRIB_COLOR1, i, vb, vs);\r
+ fetch_input_float ("gl_FogCoord", _TNL_ATTRIB_FOG, i, vb, vs);\r
+ fetch_input_vec4 ("gl_MultiTexCoord0", _TNL_ATTRIB_TEX0, i, vb, vs);\r
+ fetch_input_vec4 ("gl_MultiTexCoord1", _TNL_ATTRIB_TEX1, i, vb, vs);\r
+ fetch_input_vec4 ("gl_MultiTexCoord2", _TNL_ATTRIB_TEX2, i, vb, vs);\r
+ fetch_input_vec4 ("gl_MultiTexCoord3", _TNL_ATTRIB_TEX3, i, vb, vs);\r
+ fetch_input_vec4 ("gl_MultiTexCoord4", _TNL_ATTRIB_TEX4, i, vb, vs);\r
+ fetch_input_vec4 ("gl_MultiTexCoord5", _TNL_ATTRIB_TEX5, i, vb, vs);\r
+ fetch_input_vec4 ("gl_MultiTexCoord6", _TNL_ATTRIB_TEX6, i, vb, vs);\r
+ fetch_input_vec4 ("gl_MultiTexCoord7", _TNL_ATTRIB_TEX7, i, vb, vs);\r
+\r
+ exec_vertex_shader (vs);\r
+\r
+ fetch_output_vec4 ("gl_Position", VERT_RESULT_HPOS, i, 0, store, vs);\r
+ fetch_output_vec4 ("gl_FrontColor", VERT_RESULT_COL0, i, 0, store, vs);\r
+ fetch_output_vec4 ("gl_FrontSecondaryColor", VERT_RESULT_COL1, i, 0, store, vs);\r
+ fetch_output_float ("gl_FogFragCoord", VERT_RESULT_FOGC, i, store, vs);\r
+ for (j = 0; j < 8; j++)\r
+ fetch_output_vec4 ("gl_TexCoord", VERT_RESULT_TEX0 + j, i, j, store, vs);\r
+ fetch_output_float ("gl_PointSize", VERT_RESULT_PSIZ, i, store, vs);\r
+ fetch_output_vec4 ("gl_BackColor", VERT_RESULT_BFC0, i, 0, store, vs);\r
+ fetch_output_vec4 ("gl_BackSecondaryColor", VERT_RESULT_BFC1, i, 0, store, vs);\r
+ /* XXX: fetch output gl_ClipVertex */\r
+ }\r
+\r
+ (**vs)._shader._generic._unknown.Release ((struct gl2_unknown_intf **) vs);\r
+\r
+ vb->ClipPtr = &store->outputs[VERT_RESULT_HPOS];\r
+ vb->ClipPtr->count = vb->Count;\r
+ vb->ColorPtr[0] = &store->outputs[VERT_RESULT_COL0];\r
+ vb->SecondaryColorPtr[0] = &store->outputs[VERT_RESULT_COL1];\r
+ for (i = 0; i < ctx->Const.MaxTextureUnits; i++)\r
+ vb->TexCoordPtr[i] = &store->outputs[VERT_RESULT_TEX0 + i];\r
+ vb->ColorPtr[1] = &store->outputs[VERT_RESULT_BFC0];\r
+ vb->SecondaryColorPtr[1] = &store->outputs[VERT_RESULT_BFC1];\r
+ vb->FogCoordPtr = &store->outputs[VERT_RESULT_FOGC];\r
+ vb->PointSizePtr = &store->outputs[VERT_RESULT_PSIZ];\r
+\r
+ vb->AttribPtr[VERT_ATTRIB_COLOR0] = vb->ColorPtr[0];\r
+ vb->AttribPtr[VERT_ATTRIB_COLOR1] = vb->SecondaryColorPtr[0];\r
+ vb->AttribPtr[VERT_ATTRIB_FOG] = vb->FogCoordPtr;\r
+ for (i = 0; i < ctx->Const.MaxTextureUnits; i++)\r
+ vb->AttribPtr[VERT_ATTRIB_TEX0 + i] = vb->TexCoordPtr[i];\r
+ vb->AttribPtr[_TNL_ATTRIB_POINTSIZE] = &store->outputs[VERT_RESULT_PSIZ];\r
+\r
+ store->ormask = 0;\r
+ store->andmask = CLIP_ALL_BITS;\r
+\r
+ if (tnl->NeedNdcCoords)\r
+ {\r
+ vb->NdcPtr = _mesa_clip_tab[vb->ClipPtr->size] (vb->ClipPtr, &store->ndc_coords,\r
+ store->clipmask, &store->ormask, &store->andmask);\r
+ }\r
+ else\r
+ {\r
+ vb->NdcPtr = NULL;\r
+ _mesa_clip_np_tab[vb->ClipPtr->size] (vb->ClipPtr, NULL, store->clipmask, &store->ormask,\r
+ &store->andmask);\r
+ }\r
+\r
+ if (store->andmask)\r
+ return GL_FALSE;\r
+\r
+ vb->ClipAndMask = store->andmask;\r
+ vb->ClipOrMask = store->ormask;\r
+ vb->ClipMask = store->clipmask;\r
+\r
+ return GL_TRUE;\r
+}\r
+\r
+const struct tnl_pipeline_stage _tnl_arb_vertex_shader_stage = {\r
+ "ARB_vertex_shader",\r
+ NULL,\r
+ construct_arb_vertex_shader,\r
+ destruct_arb_vertex_shader,\r
+ validate_arb_vertex_shader,\r
+ run_arb_vertex_shader\r
+};\r
+\r