コード例 #1
0
ファイル: api_arrayelt.c プロジェクト: austriancoder/mesa-1
/**
 * Make a list of per-vertex functions to call for each glArrayElement call.
 * These functions access the array data (i.e. glVertex, glColor, glNormal,
 * etc).
 * Note: this may be called during display list construction.
 */
static void
_ae_update_state(struct gl_context *ctx)
{
   AEcontext *actx = AE_CONTEXT(ctx);
   AEarray *aa = actx->arrays;  /* non-indexed arrays (ex: glNormal) */
   AEattrib *at = actx->attribs;  /* indexed arrays (ex: glMultiTexCoord) */
   GLuint i;
   struct gl_vertex_array_object *vao = ctx->Array.VAO;

   actx->nr_vbos = 0;

   /* conventional vertex arrays */
   if (vao->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled) {
      aa->array = &vao->VertexAttrib[VERT_ATTRIB_COLOR_INDEX];
      aa->binding = &vao->VertexBinding[aa->array->VertexBinding];
      aa->offset = IndexFuncs[TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->binding->BufferObj);
      aa++;
   }

   if (vao->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled) {
      aa->array = &vao->VertexAttrib[VERT_ATTRIB_EDGEFLAG];
      aa->binding = &vao->VertexBinding[aa->array->VertexBinding];
      aa->offset = _gloffset_EdgeFlagv;
      check_vbo(actx, aa->binding->BufferObj);
      aa++;
   }

   if (vao->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled) {
      aa->array = &vao->VertexAttrib[VERT_ATTRIB_NORMAL];
      aa->binding = &vao->VertexBinding[aa->array->VertexBinding];
      aa->offset = NormalFuncs[TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->binding->BufferObj);
      aa++;
   }

   if (vao->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled) {
      aa->array = &vao->VertexAttrib[VERT_ATTRIB_COLOR0];
      aa->binding = &vao->VertexBinding[aa->array->VertexBinding];
      aa->offset = ColorFuncs[aa->array->Size-3][TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->binding->BufferObj);
      aa++;
   }

   if (vao->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled) {
      aa->array = &vao->VertexAttrib[VERT_ATTRIB_COLOR1];
      aa->binding = &vao->VertexBinding[aa->array->VertexBinding];
      aa->offset = SecondaryColorFuncs[TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->binding->BufferObj);
      aa++;
   }

   if (vao->VertexAttrib[VERT_ATTRIB_FOG].Enabled) {
      aa->array = &vao->VertexAttrib[VERT_ATTRIB_FOG];
      aa->binding = &vao->VertexBinding[aa->array->VertexBinding];
      aa->offset = FogCoordFuncs[TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->binding->BufferObj);
      aa++;
   }

   for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
      struct gl_vertex_attrib_array *attribArray =
         &vao->VertexAttrib[VERT_ATTRIB_TEX(i)];
      if (attribArray->Enabled) {
         /* NOTE: we use generic glVertexAttribNV functions here.
          * If we ever remove GL_NV_vertex_program this will have to change.
          */
         at->array = attribArray;
         at->binding = &vao->VertexBinding[attribArray->VertexBinding];
         ASSERT(!at->array->Normalized);
         at->func = AttribFuncsNV[at->array->Normalized]
                                 [at->array->Size-1]
                                 [TYPE_IDX(at->array->Type)];
         at->index = VERT_ATTRIB_TEX0 + i;
	 check_vbo(actx, at->binding->BufferObj);
         at++;
      }
   }

   /* generic vertex attribute arrays */
   for (i = 1; i < VERT_ATTRIB_GENERIC_MAX; i++) {  /* skip zero! */
      struct gl_vertex_attrib_array *attribArray =
         &vao->VertexAttrib[VERT_ATTRIB_GENERIC(i)];
      if (attribArray->Enabled) {
         GLint intOrNorm;
         at->array = attribArray;
         at->binding = &vao->VertexBinding[attribArray->VertexBinding];
         /* Note: we can't grab the _glapi_Dispatch->VertexAttrib1fvNV
          * function pointer here (for float arrays) since the pointer may
          * change from one execution of _ae_ArrayElement() to
          * the next.  Doing so caused UT to break.
          */
         if (at->array->Integer)
            intOrNorm = 2;
         else if (at->array->Normalized)
            intOrNorm = 1;
         else
            intOrNorm = 0;

         at->func = AttribFuncsARB[intOrNorm]
            [at->array->Size-1]
            [TYPE_IDX(at->array->Type)];

         at->index = i;
	 check_vbo(actx, at->binding->BufferObj);
         at++;
      }
   }

   /* finally, vertex position */
   if (vao->VertexAttrib[VERT_ATTRIB_GENERIC0].Enabled) {
      /* Use glVertex(v) instead of glVertexAttrib(0, v) to be sure it's
       * issued as the last (provoking) attribute).
       */
      aa->array = &vao->VertexAttrib[VERT_ATTRIB_GENERIC0];
      aa->binding = &vao->VertexBinding[aa->array->VertexBinding];
      assert(aa->array->Size >= 2); /* XXX fix someday? */
      aa->offset = VertexFuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->binding->BufferObj);
      aa++;
   }
   else if (vao->VertexAttrib[VERT_ATTRIB_POS].Enabled) {
      aa->array = &vao->VertexAttrib[VERT_ATTRIB_POS];
      aa->binding = &vao->VertexBinding[aa->array->VertexBinding];
      aa->offset = VertexFuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->binding->BufferObj);
      aa++;
   }

   check_vbo(actx, vao->IndexBufferObj);

   ASSERT(at - actx->attribs <= VERT_ATTRIB_MAX);
   ASSERT(aa - actx->arrays < 32);
   at->func = NULL;  /* terminate the list */
   aa->offset = -1;  /* terminate the list */

   actx->NewState = 0;
}
コード例 #2
0
ファイル: api_arrayelt.c プロジェクト: Starlink/mesa
/**
 * Make a list of per-vertex functions to call for each glArrayElement call.
 * These functions access the array data (i.e. glVertex, glColor, glNormal,
 * etc).
 * Note: this may be called during display list construction.
 */
static void _ae_update_state( GLcontext *ctx )
{
   AEcontext *actx = AE_CONTEXT(ctx);
   AEarray *aa = actx->arrays;
   AEattrib *at = actx->attribs;
   GLuint i;

   actx->nr_vbos = 0;

   /* conventional vertex arrays */
  if (ctx->Array.ArrayObj->Index.Enabled) {
      aa->array = &ctx->Array.ArrayObj->Index;
      aa->offset = IndexFuncs[TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->array->BufferObj);
      aa++;
   }
   if (ctx->Array.ArrayObj->EdgeFlag.Enabled) {
      aa->array = &ctx->Array.ArrayObj->EdgeFlag;
      aa->offset = _gloffset_EdgeFlagv;
      check_vbo(actx, aa->array->BufferObj);
      aa++;
   }
   if (ctx->Array.ArrayObj->Normal.Enabled) {
      aa->array = &ctx->Array.ArrayObj->Normal;
      aa->offset = NormalFuncs[TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->array->BufferObj);
      aa++;
   }
   if (ctx->Array.ArrayObj->Color.Enabled) {
      aa->array = &ctx->Array.ArrayObj->Color;
      aa->offset = ColorFuncs[aa->array->Size-3][TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->array->BufferObj);
      aa++;
   }
   if (ctx->Array.ArrayObj->SecondaryColor.Enabled) {
      aa->array = &ctx->Array.ArrayObj->SecondaryColor;
      aa->offset = SecondaryColorFuncs[TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->array->BufferObj);
      aa++;
   }
   if (ctx->Array.ArrayObj->FogCoord.Enabled) {
      aa->array = &ctx->Array.ArrayObj->FogCoord;
      aa->offset = FogCoordFuncs[TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->array->BufferObj);
      aa++;
   }
   for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
      struct gl_client_array *attribArray = &ctx->Array.ArrayObj->TexCoord[i];
      if (attribArray->Enabled) {
         /* NOTE: we use generic glVertexAttribNV functions here.
          * If we ever remove GL_NV_vertex_program this will have to change.
          */
         at->array = attribArray;
         ASSERT(!at->array->Normalized);
         at->func = AttribFuncsNV[at->array->Normalized]
                                 [at->array->Size-1]
                                 [TYPE_IDX(at->array->Type)];
         at->index = VERT_ATTRIB_TEX0 + i;
	 check_vbo(actx, at->array->BufferObj);
         at++;
      }
   }

   /* generic vertex attribute arrays */   
   for (i = 1; i < VERT_ATTRIB_MAX; i++) {  /* skip zero! */
      struct gl_client_array *attribArray = &ctx->Array.ArrayObj->VertexAttrib[i];
      if (attribArray->Enabled) {
         at->array = attribArray;
         /* Note: we can't grab the _glapi_Dispatch->VertexAttrib1fvNV
          * function pointer here (for float arrays) since the pointer may
          * change from one execution of _ae_loopback_array_elt() to
          * the next.  Doing so caused UT to break.
          */
         if (ctx->VertexProgram._Enabled
             && ctx->VertexProgram.Current->IsNVProgram) {
            at->func = AttribFuncsNV[at->array->Normalized]
                                    [at->array->Size-1]
                                    [TYPE_IDX(at->array->Type)];
         }
         else {
            at->func = AttribFuncsARB[at->array->Normalized]
                                     [at->array->Size-1]
                                     [TYPE_IDX(at->array->Type)];
         }
         at->index = i;
	 check_vbo(actx, at->array->BufferObj);
         at++;
      }
   }

   /* finally, vertex position */
   if (ctx->Array.ArrayObj->VertexAttrib[0].Enabled) {
      /* Use glVertex(v) instead of glVertexAttrib(0, v) to be sure it's
       * issued as the last (provoking) attribute).
       */
      aa->array = &ctx->Array.ArrayObj->VertexAttrib[0];
      assert(aa->array->Size >= 2); /* XXX fix someday? */
      aa->offset = VertexFuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->array->BufferObj);
      aa++;
   }
   else if (ctx->Array.ArrayObj->Vertex.Enabled) {
      aa->array = &ctx->Array.ArrayObj->Vertex;
      aa->offset = VertexFuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
      check_vbo(actx, aa->array->BufferObj);
      aa++;
   }

   check_vbo(actx, ctx->Array.ElementArrayBufferObj);

   ASSERT(at - actx->attribs <= VERT_ATTRIB_MAX);
   ASSERT(aa - actx->arrays < 32);
   at->func = NULL;  /* terminate the list */
   aa->offset = -1;  /* terminate the list */

   actx->NewState = 0;
}