Ejemplo n.º 1
0
/**
 * Prepare to render a vertex buffer.
 * Called via tnl->Driver.Render.Start.
 */
static void
_swsetup_RenderStart( struct gl_context *ctx )
{
   SScontext *swsetup = SWSETUP_CONTEXT(ctx);
   TNLcontext *tnl = TNL_CONTEXT(ctx);
   struct vertex_buffer *VB = &tnl->vb;

   if (swsetup->NewState & _SWSETUP_NEW_RENDERINDEX) {
      _swsetup_choose_trifuncs(ctx);
   }

   if (swsetup->NewState & _NEW_PROGRAM) {
      swsetup->last_index_bitset = 0;
   }

   swsetup->NewState = 0;

   /* This will change if drawing unfilled tris */
   _swrast_SetFacing(ctx, 0);

   _swrast_render_start(ctx);

   /* Important */
   VB->AttribPtr[VERT_ATTRIB_POS] = VB->NdcPtr;

   setup_vertex_format(ctx);
}
Ejemplo n.º 2
0
/*
 * Render a triangle respecting cull and shade model.
 */
static void _swsetup_render_tri(struct gl_context *ctx,
                                GLuint e0,
                                GLuint e1,
                                GLuint e2,
                                GLuint facing,
                                swsetup_edge_render_prim_tri render)
{
   SScontext *swsetup = SWSETUP_CONTEXT(ctx);
   struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
   GLubyte *ef = VB->EdgeFlag;
   SWvertex *verts = swsetup->verts;
   SWvertex *v0 = &verts[e0];
   SWvertex *v1 = &verts[e1];
   SWvertex *v2 = &verts[e2];

   /* cull testing */
   if (ctx->Polygon.CullFlag) {
      if (facing == 1 && ctx->Polygon.CullFaceMode != GL_FRONT)
         return;
      if (facing == 0 && ctx->Polygon.CullFaceMode != GL_BACK)
         return;
   }

   _swrast_SetFacing(ctx, facing);

   if (ctx->Light.ShadeModel == GL_FLAT) {
      GLchan c[2][4];
      GLfloat s[2][4];

      /* save colors/indexes for v0, v1 vertices */
      COPY_CHAN4(c[0], v0->color);
      COPY_CHAN4(c[1], v1->color);
      COPY_4V(s[0], v0->attrib[FRAG_ATTRIB_COL1]);
      COPY_4V(s[1], v1->attrib[FRAG_ATTRIB_COL1]);

      /* copy v2 color/indexes to v0, v1 indexes */
      COPY_CHAN4(v0->color, v2->color);
      COPY_CHAN4(v1->color, v2->color);
      COPY_4V(v0->attrib[FRAG_ATTRIB_COL1], v2->attrib[FRAG_ATTRIB_COL1]);
      COPY_4V(v1->attrib[FRAG_ATTRIB_COL1], v2->attrib[FRAG_ATTRIB_COL1]);

      render(ctx, ef, e0, e1, e2, v0, v1, v2);

      COPY_CHAN4(v0->color, c[0]);
      COPY_CHAN4(v1->color, c[1]);
      COPY_4V(v0->attrib[FRAG_ATTRIB_COL1], s[0]);
      COPY_4V(v1->attrib[FRAG_ATTRIB_COL1], s[1]);
   }
   else {
      render(ctx, ef, e0, e1, e2, v0, v1, v2);
   }
}