Merge commit 'origin/master' into gallium-0.2
[mesa.git] / src / gallium / auxiliary / draw / draw_pipe_aaline.c
index 6dc20f2c90a95412cfeb1d4eceefa992a8703fde..20841bb5d69b0abda50c61354e803f399ad72cb0 100644 (file)
  */
 
 
-#include "pipe/p_util.h"
 #include "pipe/p_inlines.h"
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
 #include "pipe/p_shader_tokens.h"
+#include "util/u_math.h"
+#include "util/u_memory.h"
 
-#include "tgsi/util/tgsi_transform.h"
-#include "tgsi/util/tgsi_dump.h"
+#include "tgsi/tgsi_transform.h"
+#include "tgsi/tgsi_dump.h"
 
 #include "draw_context.h"
 #include "draw_private.h"
@@ -78,6 +79,8 @@ struct aaline_stage
 
    /** For AA lines, this is the vertex attrib slot for the new texcoords */
    uint tex_slot;
+   /** position, not necessarily output zero */
+   uint pos_slot;
 
    void *sampler_cso;
    struct pipe_texture *texture;
@@ -141,18 +144,18 @@ aa_transform_decl(struct tgsi_transform_context *ctx,
    if (decl->Declaration.File == TGSI_FILE_OUTPUT &&
        decl->Semantic.SemanticName == TGSI_SEMANTIC_COLOR &&
        decl->Semantic.SemanticIndex == 0) {
-      aactx->colorOutput = decl->u.DeclarationRange.First;
+      aactx->colorOutput = decl->DeclarationRange.First;
    }
    else if (decl->Declaration.File == TGSI_FILE_SAMPLER) {
       uint i;
-      for (i = decl->u.DeclarationRange.First;
-           i <= decl->u.DeclarationRange.Last; i++) {
+      for (i = decl->DeclarationRange.First;
+           i <= decl->DeclarationRange.Last; i++) {
          aactx->samplersUsed |= 1 << i;
       }
    }
    else if (decl->Declaration.File == TGSI_FILE_INPUT) {
-      if ((int) decl->u.DeclarationRange.Last > aactx->maxInput)
-         aactx->maxInput = decl->u.DeclarationRange.Last;
+      if ((int) decl->DeclarationRange.Last > aactx->maxInput)
+         aactx->maxInput = decl->DeclarationRange.Last;
       if (decl->Semantic.SemanticName == TGSI_SEMANTIC_GENERIC &&
            (int) decl->Semantic.SemanticIndex > aactx->maxGeneric) {
          aactx->maxGeneric = decl->Semantic.SemanticIndex;
@@ -160,8 +163,8 @@ aa_transform_decl(struct tgsi_transform_context *ctx,
    }
    else if (decl->Declaration.File == TGSI_FILE_TEMPORARY) {
       uint i;
-      for (i = decl->u.DeclarationRange.First;
-           i <= decl->u.DeclarationRange.Last; i++) {
+      for (i = decl->DeclarationRange.First;
+           i <= decl->DeclarationRange.Last; i++) {
          aactx->tempsUsed |= (1 << i);
       }
    }
@@ -225,34 +228,33 @@ aa_transform_inst(struct tgsi_transform_context *ctx,
       /* declare new generic input/texcoord */
       decl = tgsi_default_full_declaration();
       decl.Declaration.File = TGSI_FILE_INPUT;
+      /* XXX this could be linear... */
+      decl.Declaration.Interpolate = TGSI_INTERPOLATE_PERSPECTIVE;
       decl.Declaration.Semantic = 1;
       decl.Semantic.SemanticName = TGSI_SEMANTIC_GENERIC;
       decl.Semantic.SemanticIndex = aactx->maxGeneric + 1;
-      decl.Declaration.Interpolate = 1;
-      /* XXX this could be linear... */
-      decl.Interpolation.Interpolate = TGSI_INTERPOLATE_PERSPECTIVE;
-      decl.u.DeclarationRange.First = 
-      decl.u.DeclarationRange.Last = aactx->maxInput + 1;
+      decl.DeclarationRange.First = 
+      decl.DeclarationRange.Last = aactx->maxInput + 1;
       ctx->emit_declaration(ctx, &decl);
 
       /* declare new sampler */
       decl = tgsi_default_full_declaration();
       decl.Declaration.File = TGSI_FILE_SAMPLER;
-      decl.u.DeclarationRange.First = 
-      decl.u.DeclarationRange.Last = aactx->freeSampler;
+      decl.DeclarationRange.First = 
+      decl.DeclarationRange.Last = aactx->freeSampler;
       ctx->emit_declaration(ctx, &decl);
 
       /* declare new temp regs */
       decl = tgsi_default_full_declaration();
       decl.Declaration.File = TGSI_FILE_TEMPORARY;
-      decl.u.DeclarationRange.First = 
-      decl.u.DeclarationRange.Last = aactx->texTemp;
+      decl.DeclarationRange.First = 
+      decl.DeclarationRange.Last = aactx->texTemp;
       ctx->emit_declaration(ctx, &decl);
 
       decl = tgsi_default_full_declaration();
       decl.Declaration.File = TGSI_FILE_TEMPORARY;
-      decl.u.DeclarationRange.First = 
-      decl.u.DeclarationRange.Last = aactx->colorTemp;
+      decl.DeclarationRange.First = 
+      decl.DeclarationRange.Last = aactx->colorTemp;
       ctx->emit_declaration(ctx, &decl);
 
       aactx->firstInstruction = FALSE;
@@ -397,7 +399,7 @@ aaline_create_texture(struct aaline_stage *aaline)
    texTemp.width[0] = 1 << MAX_TEXTURE_LEVEL;
    texTemp.height[0] = 1 << MAX_TEXTURE_LEVEL;
    texTemp.depth[0] = 1;
-   texTemp.cpp = 1;
+   pf_get_block(texTemp.format, &texTemp.block);
 
    aaline->texture = screen->texture_create(screen, &texTemp);
    if (!aaline->texture)
@@ -438,7 +440,7 @@ aaline_create_texture(struct aaline_stage *aaline)
             else {
                d = 255;
             }
-            data[i * surface->pitch + j] = d;
+            data[i * surface->stride + j] = d;
          }
       }
 
@@ -521,9 +523,10 @@ aaline_line(struct draw_stage *stage, struct prim_header *header)
    struct prim_header tri;
    struct vertex_header *v[8];
    uint texPos = aaline->tex_slot;
+   uint posPos = aaline->pos_slot;
    float *pos, *tex;
-   float dx = header->v[1]->data[0][0] - header->v[0]->data[0][0];
-   float dy = header->v[1]->data[0][1] - header->v[0]->data[0][1];
+   float dx = header->v[1]->data[posPos][0] - header->v[0]->data[posPos][0];
+   float dy = header->v[1]->data[posPos][1] - header->v[0]->data[posPos][1];
    double a = atan2(dy, dx);
    float c_a = (float) cos(a), s_a = (float) sin(a);
    uint i;
@@ -550,35 +553,35 @@ aaline_line(struct draw_stage *stage, struct prim_header *header)
     */
 
    /* new verts */
-   pos = v[0]->data[0];
+   pos = v[0]->data[posPos];
    pos[0] += (-dx * c_a -  dy * s_a);
    pos[1] += (-dx * s_a +  dy * c_a);
 
-   pos = v[1]->data[0];
+   pos = v[1]->data[posPos];
    pos[0] += (-dx * c_a - -dy * s_a);
    pos[1] += (-dx * s_a + -dy * c_a);
 
-   pos = v[2]->data[0];
+   pos = v[2]->data[posPos];
    pos[0] += ( dx * c_a -  dy * s_a);
    pos[1] += ( dx * s_a +  dy * c_a);
 
-   pos = v[3]->data[0];
+   pos = v[3]->data[posPos];
    pos[0] += ( dx * c_a - -dy * s_a);
    pos[1] += ( dx * s_a + -dy * c_a);
 
-   pos = v[4]->data[0];
+   pos = v[4]->data[posPos];
    pos[0] += (-dx * c_a -  dy * s_a);
    pos[1] += (-dx * s_a +  dy * c_a);
 
-   pos = v[5]->data[0];
+   pos = v[5]->data[posPos];
    pos[0] += (-dx * c_a - -dy * s_a);
    pos[1] += (-dx * s_a + -dy * c_a);
 
-   pos = v[6]->data[0];
+   pos = v[6]->data[posPos];
    pos[0] += ( dx * c_a -  dy * s_a);
    pos[1] += ( dx * s_a +  dy * c_a);
 
-   pos = v[7]->data[0];
+   pos = v[7]->data[posPos];
    pos[0] += ( dx * c_a - -dy * s_a);
    pos[1] += ( dx * s_a + -dy * c_a);
 
@@ -653,8 +656,8 @@ aaline_first_line(struct draw_stage *stage, struct prim_header *header)
    }
 
    /* update vertex attrib info */
-   aaline->tex_slot = draw->num_vs_outputs;
-   assert(aaline->tex_slot > 0); /* output[0] is vertex pos */
+   aaline->tex_slot = draw->vs.num_vs_outputs;
+   aaline->pos_slot = draw->vs.position_output;
 
    /* advertise the extra post-transformed vertex attribute */
    draw->extra_vp_outputs.semantic_name = TGSI_SEMANTIC_GENERIC;
@@ -715,6 +718,11 @@ static void
 aaline_destroy(struct draw_stage *stage)
 {
    struct aaline_stage *aaline = aaline_stage(stage);
+   uint i;
+
+   for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
+      pipe_texture_reference(&aaline->state.texture[i], NULL);
+   }
 
    if (aaline->sampler_cso)
       aaline->pipe->delete_sampler_state(aaline->pipe, aaline->sampler_cso);
@@ -838,6 +846,9 @@ aaline_set_sampler_textures(struct pipe_context *pipe,
    for (i = 0; i < num; i++) {
       pipe_texture_reference(&aaline->state.texture[i], texture[i]);
    }
+   for ( ; i < PIPE_MAX_SAMPLERS; i++) {
+      pipe_texture_reference(&aaline->state.texture[i], NULL);
+   }
    aaline->num_textures = num;
 
    /* pass-through */