Add arbshader stage.
authorMichal Krol <mjkrol@gmail.org>
Wed, 15 Feb 2006 11:06:00 +0000 (11:06 +0000)
committerMichal Krol <mjkrol@gmail.org>
Wed, 15 Feb 2006 11:06:00 +0000 (11:06 +0000)
src/mesa/swrast/s_arbshader.c [new file with mode: 0644]
src/mesa/swrast/s_arbshader.h [new file with mode: 0644]
src/mesa/swrast/s_span.c

diff --git a/src/mesa/swrast/s_arbshader.c b/src/mesa/swrast/s_arbshader.c
new file mode 100644 (file)
index 0000000..7cea59e
--- /dev/null
@@ -0,0 +1,117 @@
+/*\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 "context.h"\r
+#include "colormac.h"\r
+#include "s_arbshader.h"\r
+#include "s_context.h"\r
+#include "shaderobjects.h"\r
+\r
+int _slang_fetch_vec4_f (struct gl2_fragment_shader_intf **, const char *, GLfloat *,\r
+       GLuint, int);\r
+int _slang_fetch_discard (struct gl2_fragment_shader_intf **, GLboolean *);\r
+void exec_fragment_shader (struct gl2_fragment_shader_intf **);\r
+\r
+static void fetch_input_vec4 (const char *name, GLfloat *vec, GLuint index,\r
+       struct gl2_fragment_shader_intf **fs)\r
+{\r
+       _slang_fetch_vec4_f (fs, name, vec, index, 1);\r
+}\r
+\r
+static void fetch_output_vec4 (const char *name, GLfloat *vec, GLuint index,\r
+       struct gl2_fragment_shader_intf **fs)\r
+{\r
+       _slang_fetch_vec4_f (fs, name, vec, index, 0);\r
+}\r
+\r
+void _swrast_exec_arbshader (GLcontext *ctx, struct sw_span *span)\r
+{\r
+       struct gl2_program_intf **prog;\r
+       struct gl2_fragment_shader_intf **fs = NULL;\r
+       GLuint count, i;\r
+\r
+       prog = ctx->ShaderObjects.CurrentProgram;\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_FRAGMENT_SHADER);\r
+               (**obj)._unknown.Release ((struct gl2_unknown_intf **) obj);\r
+               if (unk != NULL)\r
+               {\r
+                       fs = (struct gl2_fragment_shader_intf **) unk;\r
+                       break;\r
+               }\r
+       }\r
+       if (fs == NULL)\r
+               return;\r
+\r
+       for (i = span->start; i < span->end; i++)\r
+       {\r
+               GLfloat vec[4];\r
+               GLuint j;\r
+               GLboolean kill;\r
+\r
+               vec[0] = (GLfloat) span->x + i;\r
+               vec[1] = (GLfloat) span->y;\r
+               vec[2] = (GLfloat) span->array->z[i] / ctx->DrawBuffer->_DepthMaxF;\r
+               vec[3] = span->w + span->dwdx * i;\r
+               fetch_input_vec4 ("gl_FragCoord", vec, 0, fs);\r
+               vec[0] = CHAN_TO_FLOAT(span->array->rgba[i][RCOMP]);\r
+               vec[1] = CHAN_TO_FLOAT(span->array->rgba[i][GCOMP]);\r
+               vec[2] = CHAN_TO_FLOAT(span->array->rgba[i][BCOMP]);\r
+               vec[3] = CHAN_TO_FLOAT(span->array->rgba[i][ACOMP]);\r
+               fetch_input_vec4 ("gl_Color", vec, 0, fs);\r
+               for (j = 0; j < ctx->Const.MaxTextureCoordUnits; j++)\r
+               {\r
+                       vec[0] = span->array->texcoords[j][i][0];\r
+                       vec[1] = span->array->texcoords[j][i][1];\r
+                       vec[2] = span->array->texcoords[j][i][2];\r
+                       vec[3] = span->array->texcoords[j][i][3];\r
+                       fetch_input_vec4 ("gl_TexCoord", vec, j, fs);\r
+               }\r
+\r
+               exec_fragment_shader (fs);\r
+\r
+               _slang_fetch_discard (fs, &kill);\r
+               if (kill)\r
+               {\r
+                       span->array->mask[i] = GL_FALSE;\r
+            span->writeAll = GL_FALSE;\r
+               }\r
+               fetch_output_vec4 ("gl_FragColor", vec, 0, fs);\r
+               UNCLAMPED_FLOAT_TO_CHAN(span->array->rgba[i][RCOMP], vec[0]);\r
+               UNCLAMPED_FLOAT_TO_CHAN(span->array->rgba[i][GCOMP], vec[1]);\r
+               UNCLAMPED_FLOAT_TO_CHAN(span->array->rgba[i][BCOMP], vec[2]);\r
+               UNCLAMPED_FLOAT_TO_CHAN(span->array->rgba[i][ACOMP], vec[3]);\r
+       }\r
+}\r
+\r
diff --git a/src/mesa/swrast/s_arbshader.h b/src/mesa/swrast/s_arbshader.h
new file mode 100644 (file)
index 0000000..7a99ad7
--- /dev/null
@@ -0,0 +1,34 @@
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version:  6.5\r
+ *\r
+ * Copyright (C) 2006  David Airlie   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
+ * DAVID AIRLIE 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
+\r
+\r
+#ifndef S_ARBSHADER_H\r
+#define S_ARBSHADER_H\r
+\r
+#include "s_context.h"\r
+\r
+extern void _swrast_exec_arbshader (GLcontext *ctx, struct sw_span *span);\r
+\r
+#endif\r
+\r
index 681d4eb..91556ca 100644 (file)
@@ -2,7 +2,7 @@
  * Mesa 3-D graphics library
  * Version:  6.5
  *
- * Copyright (C) 1999-2005  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -37,7 +37,8 @@
 #include "imports.h"
 
 #include "s_atifragshader.h"
-#include "s_alpha.h"
+#include "s_alpha.h"\r
+#include "s_arbshader.h"
 #include "s_blend.h"
 #include "s_context.h"
 #include "s_depth.h"
@@ -1154,8 +1155,13 @@ _swrast_write_rgba_span( GLcontext *ctx, struct sw_span *span)
       if (span->interpMask & SPAN_FOG)
          interpolate_fog(ctx, span);
 
-      /* Compute fragment colors with fragment program or texture lookups */
-      if (ctx->FragmentProgram._Active) {
+      /* Compute fragment colors with fragment program or texture lookups */\r
+      if (ctx->ShaderObjects.CurrentProgram != NULL) {\r
+         if (span->interpMask & SPAN_Z)\r
+            _swrast_span_interpolate_z (ctx, span);\r
+         _swrast_exec_arbshader (ctx, span);\r
+      }
+      else if (ctx->FragmentProgram._Active) {
          /* frag prog may need Z values */
          if (span->interpMask & SPAN_Z)
             _swrast_span_interpolate_z(ctx, span);
@@ -1232,7 +1238,12 @@ _swrast_write_rgba_span( GLcontext *ctx, struct sw_span *span)
       if (span->interpMask & SPAN_FOG)
          interpolate_fog(ctx, span);
 
-      if (ctx->FragmentProgram._Active)
+      if (ctx->ShaderObjects.CurrentProgram != NULL) {\r
+         if (span->interpMask & SPAN_Z)\r
+            _swrast_span_interpolate_z (ctx, span);\r
+         _swrast_exec_arbshader (ctx, span);\r
+      }\r
+      else if (ctx->FragmentProgram._Active)
          _swrast_exec_fragment_program( ctx, span );
       else if (ctx->ATIFragmentShader._Enabled)
          _swrast_exec_fragment_shader( ctx, span );