Merge branch 'lp-offset-twoside'
[mesa.git] / src / mesa / swrast / s_fragprog.c
index 77a77f0bcbb0e838bb1b6d646985ca72c734333c..e391043f4d9976014aa6143d83f9279931f5efef 100644 (file)
 
 #include "main/glheader.h"
 #include "main/colormac.h"
-#include "main/context.h"
-#include "main/texstate.h"
-#include "shader/prog_instruction.h"
+#include "program/prog_instruction.h"
 
+#include "s_context.h"
 #include "s_fragprog.h"
 #include "s_span.h"
 
@@ -63,7 +62,7 @@ swizzle_texel(const GLfloat texel[4], GLfloat colorOut[4], GLuint swizzle)
  * Called via machine->FetchTexelLod()
  */
 static void
-fetch_texel_lod( GLcontext *ctx, const GLfloat texcoord[4], GLfloat lambda,
+fetch_texel_lod( struct gl_context *ctx, const GLfloat texcoord[4], GLfloat lambda,
                  GLuint unit, GLfloat color[4] )
 {
    const struct gl_texture_object *texObj = ctx->Texture.Unit[unit]._Current;
@@ -93,7 +92,7 @@ fetch_texel_lod( GLcontext *ctx, const GLfloat texcoord[4], GLfloat lambda,
  *                 otherwise zero.
  */
 static void
-fetch_texel_deriv( GLcontext *ctx, const GLfloat texcoord[4],
+fetch_texel_deriv( struct gl_context *ctx, const GLfloat texcoord[4],
                    const GLfloat texdx[4], const GLfloat texdy[4],
                    GLfloat lodBias, GLuint unit, GLfloat color[4] )
 {
@@ -141,14 +140,23 @@ fetch_texel_deriv( GLcontext *ctx, const GLfloat texcoord[4],
  * \param col  which element (column) of the span we'll operate on
  */
 static void
-init_machine(GLcontext *ctx, struct gl_program_machine *machine,
+init_machine(struct gl_context *ctx, struct gl_program_machine *machine,
              const struct gl_fragment_program *program,
              const SWspan *span, GLuint col)
 {
+   GLfloat *wpos = span->array->attribs[FRAG_ATTRIB_WPOS][col];
+
    if (program->Base.Target == GL_FRAGMENT_PROGRAM_NV) {
       /* Clear temporary registers (undefined for ARB_f_p) */
-      _mesa_bzero(machine->Temporaries,
-                  MAX_PROGRAM_TEMPS * 4 * sizeof(GLfloat));
+      memset(machine->Temporaries, 0, MAX_PROGRAM_TEMPS * 4 * sizeof(GLfloat));
+   }
+
+   /* ARB_fragment_coord_conventions */
+   if (program->OriginUpperLeft)
+      wpos[1] = ctx->DrawBuffer->Height - 1 - wpos[1];
+   if (!program->PixelCenterInteger) {
+      wpos[0] += 0.5F;
+      wpos[1] += 0.5F;
    }
 
    /* Setup pointer to input attributes */
@@ -161,9 +169,9 @@ init_machine(GLcontext *ctx, struct gl_program_machine *machine,
    machine->Samplers = program->Base.SamplerUnits;
 
    /* if running a GLSL program (not ARB_fragment_program) */
-   if (ctx->Shader.CurrentProgram) {
+   if (ctx->Shader.CurrentFragmentProgram) {
       /* Store front/back facing value */
-      machine->Attribs[FRAG_ATTRIB_FACE][col][0] = 1.0 - span->facing;
+      machine->Attribs[FRAG_ATTRIB_FACE][col][0] = 1.0F - span->facing;
    }
 
    machine->CurElement = col;
@@ -186,11 +194,11 @@ init_machine(GLcontext *ctx, struct gl_program_machine *machine,
  * Run fragment program on the pixels in span from 'start' to 'end' - 1.
  */
 static void
-run_program(GLcontext *ctx, SWspan *span, GLuint start, GLuint end)
+run_program(struct gl_context *ctx, SWspan *span, GLuint start, GLuint end)
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
    const struct gl_fragment_program *program = ctx->FragmentProgram._Current;
-   const GLbitfield outputsWritten = program->Base.OutputsWritten;
+   const GLbitfield64 outputsWritten = program->Base.OutputsWritten;
    struct gl_program_machine *machine = &swrast->FragProgMachine;
    GLuint i;
 
@@ -201,7 +209,7 @@ run_program(GLcontext *ctx, SWspan *span, GLuint start, GLuint end)
          if (_mesa_execute_program(ctx, &program->Base, machine)) {
 
             /* Store result color */
-            if (outputsWritten & (1 << FRAG_RESULT_COLOR)) {
+           if (outputsWritten & BITFIELD64_BIT(FRAG_RESULT_COLOR)) {
                COPY_4V(span->array->attribs[FRAG_ATTRIB_COL0][i],
                        machine->Outputs[FRAG_RESULT_COLOR]);
             }
@@ -212,7 +220,7 @@ run_program(GLcontext *ctx, SWspan *span, GLuint start, GLuint end)
                 */
                GLuint buf;
                for (buf = 0; buf < ctx->DrawBuffer->_NumColorDrawBuffers; buf++) {
-                  if (outputsWritten & (1 << (FRAG_RESULT_DATA0 + buf))) {
+                  if (outputsWritten & BITFIELD64_BIT(FRAG_RESULT_DATA0 + buf)) {
                      COPY_4V(span->array->attribs[FRAG_ATTRIB_COL0 + buf][i],
                              machine->Outputs[FRAG_RESULT_DATA0 + buf]);
                   }
@@ -220,7 +228,7 @@ run_program(GLcontext *ctx, SWspan *span, GLuint start, GLuint end)
             }
 
             /* Store result depth/z */
-            if (outputsWritten & (1 << FRAG_RESULT_DEPTH)) {
+            if (outputsWritten & BITFIELD64_BIT(FRAG_RESULT_DEPTH)) {
                const GLfloat depth = machine->Outputs[FRAG_RESULT_DEPTH][2];
                if (depth <= 0.0)
                   span->array->z[i] = 0;
@@ -245,7 +253,7 @@ run_program(GLcontext *ctx, SWspan *span, GLuint start, GLuint end)
  * in the given span.
  */
 void
-_swrast_exec_fragment_program( GLcontext *ctx, SWspan *span )
+_swrast_exec_fragment_program( struct gl_context *ctx, SWspan *span )
 {
    const struct gl_fragment_program *program = ctx->FragmentProgram._Current;
 
@@ -256,12 +264,12 @@ _swrast_exec_fragment_program( GLcontext *ctx, SWspan *span )
 
    run_program(ctx, span, 0, span->end);
 
-   if (program->Base.OutputsWritten & (1 << FRAG_RESULT_COLOR)) {
+   if (program->Base.OutputsWritten & BITFIELD64_BIT(FRAG_RESULT_COLOR)) {
       span->interpMask &= ~SPAN_RGBA;
       span->arrayMask |= SPAN_RGBA;
    }
 
-   if (program->Base.OutputsWritten & (1 << FRAG_RESULT_DEPTH)) {
+   if (program->Base.OutputsWritten & BITFIELD64_BIT(FRAG_RESULT_DEPTH)) {
       span->interpMask &= ~SPAN_Z;
       span->arrayMask |= SPAN_Z;
    }