2001-12-14 02:50:01 +00:00
|
|
|
/*
|
|
|
|
* Mesa 3-D graphics library
|
2007-02-22 16:07:17 -07:00
|
|
|
* Version: 6.5.3
|
2001-12-14 02:50:01 +00:00
|
|
|
*
|
2007-02-22 16:07:17 -07:00
|
|
|
* Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
|
2001-12-14 02:50:01 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2002-01-22 14:35:16 +00:00
|
|
|
/**
|
|
|
|
* \file tnl/t_vb_program.c
|
2003-01-14 04:55:45 +00:00
|
|
|
* \brief Pipeline stage for executing NVIDIA vertex programs.
|
2002-01-22 14:35:16 +00:00
|
|
|
* \author Brian Paul, Keith Whitwell
|
2001-12-14 02:50:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "glheader.h"
|
|
|
|
#include "context.h"
|
|
|
|
#include "macros.h"
|
2002-10-24 23:57:19 +00:00
|
|
|
#include "imports.h"
|
2006-12-15 10:08:59 -07:00
|
|
|
#include "prog_instruction.h"
|
|
|
|
#include "prog_statevars.h"
|
2007-02-22 16:07:17 -07:00
|
|
|
#include "prog_execute.h"
|
2001-12-14 02:50:01 +00:00
|
|
|
|
2007-02-23 13:38:37 -07:00
|
|
|
#include "tnl.h"
|
2001-12-14 02:50:01 +00:00
|
|
|
#include "t_context.h"
|
|
|
|
#include "t_pipeline.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-01-22 14:35:16 +00:00
|
|
|
/*!
|
|
|
|
* Private storage for the vertex program pipeline stage.
|
|
|
|
*/
|
2001-12-14 02:50:01 +00:00
|
|
|
struct vp_stage_data {
|
2002-01-22 14:35:16 +00:00
|
|
|
/** The results of running the vertex program go into these arrays. */
|
2006-12-13 14:58:13 -07:00
|
|
|
GLvector4f attribs[VERT_RESULT_MAX];
|
2002-01-06 03:54:12 +00:00
|
|
|
|
2002-01-22 14:35:16 +00:00
|
|
|
GLvector4f ndcCoords; /**< normalized device coords */
|
|
|
|
GLubyte *clipmask; /**< clip flags */
|
|
|
|
GLubyte ormask, andmask; /**< for clipping */
|
2001-12-14 02:50:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define VP_STAGE_DATA(stage) ((struct vp_stage_data *)(stage->privatePtr))
|
|
|
|
|
|
|
|
|
2007-02-22 16:07:17 -07:00
|
|
|
/**
|
|
|
|
* Initialize virtual machine state prior to executing vertex program.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
init_machine(GLcontext *ctx, struct gl_program_machine *machine)
|
|
|
|
{
|
|
|
|
/* Input registers get initialized from the current vertex attribs */
|
|
|
|
MEMCPY(machine->VertAttribs, ctx->Current.Attrib,
|
|
|
|
MAX_VERTEX_PROGRAM_ATTRIBS * 4 * sizeof(GLfloat));
|
|
|
|
|
|
|
|
if (ctx->VertexProgram.Current->IsNVProgram) {
|
|
|
|
GLuint i;
|
|
|
|
/* Output/result regs are initialized to [0,0,0,1] */
|
|
|
|
for (i = 0; i < MAX_NV_VERTEX_PROGRAM_OUTPUTS; i++) {
|
|
|
|
ASSIGN_4V(machine->Outputs[i], 0.0F, 0.0F, 0.0F, 1.0F);
|
|
|
|
}
|
|
|
|
/* Temp regs are initialized to [0,0,0,0] */
|
|
|
|
for (i = 0; i < MAX_NV_VERTEX_PROGRAM_TEMPS; i++) {
|
|
|
|
ASSIGN_4V(machine->Temporaries[i], 0.0F, 0.0F, 0.0F, 0.0F);
|
|
|
|
}
|
|
|
|
for (i = 0; i < MAX_VERTEX_PROGRAM_ADDRESS_REGS; i++) {
|
|
|
|
ASSIGN_4V(machine->AddressReg[i], 0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* init condition codes */
|
|
|
|
machine->CondCodes[0] = COND_EQ;
|
|
|
|
machine->CondCodes[1] = COND_EQ;
|
|
|
|
machine->CondCodes[2] = COND_EQ;
|
|
|
|
machine->CondCodes[3] = COND_EQ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy the 16 elements of a matrix into four consecutive program
|
|
|
|
* registers starting at 'pos'.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
load_matrix(GLfloat registers[][4], GLuint pos, const GLfloat mat[16])
|
|
|
|
{
|
|
|
|
GLuint i;
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
registers[pos + i][0] = mat[0 + i];
|
|
|
|
registers[pos + i][1] = mat[4 + i];
|
|
|
|
registers[pos + i][2] = mat[8 + i];
|
|
|
|
registers[pos + i][3] = mat[12 + i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* As above, but transpose the matrix.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
load_transpose_matrix(GLfloat registers[][4], GLuint pos,
|
|
|
|
const GLfloat mat[16])
|
|
|
|
{
|
|
|
|
MEMCPY(registers[pos], mat, 16 * sizeof(GLfloat));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2007-02-23 13:38:37 -07:00
|
|
|
* Load current vertex program's parameter registers with tracked
|
|
|
|
* matrices (if NV program). This only needs to be done per
|
|
|
|
* glBegin/glEnd, not per-vertex.
|
2007-02-22 16:07:17 -07:00
|
|
|
*/
|
2007-02-23 13:38:37 -07:00
|
|
|
void
|
|
|
|
_mesa_load_tracked_matrices(GLcontext *ctx)
|
2007-02-22 16:07:17 -07:00
|
|
|
{
|
|
|
|
GLuint i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_NV_VERTEX_PROGRAM_PARAMS / 4; i++) {
|
|
|
|
/* point 'mat' at source matrix */
|
|
|
|
GLmatrix *mat;
|
|
|
|
if (ctx->VertexProgram.TrackMatrix[i] == GL_MODELVIEW) {
|
|
|
|
mat = ctx->ModelviewMatrixStack.Top;
|
|
|
|
}
|
|
|
|
else if (ctx->VertexProgram.TrackMatrix[i] == GL_PROJECTION) {
|
|
|
|
mat = ctx->ProjectionMatrixStack.Top;
|
|
|
|
}
|
|
|
|
else if (ctx->VertexProgram.TrackMatrix[i] == GL_TEXTURE) {
|
|
|
|
mat = ctx->TextureMatrixStack[ctx->Texture.CurrentUnit].Top;
|
|
|
|
}
|
|
|
|
else if (ctx->VertexProgram.TrackMatrix[i] == GL_COLOR) {
|
|
|
|
mat = ctx->ColorMatrixStack.Top;
|
|
|
|
}
|
|
|
|
else if (ctx->VertexProgram.TrackMatrix[i]==GL_MODELVIEW_PROJECTION_NV) {
|
|
|
|
/* XXX verify the combined matrix is up to date */
|
|
|
|
mat = &ctx->_ModelProjectMatrix;
|
|
|
|
}
|
|
|
|
else if (ctx->VertexProgram.TrackMatrix[i] >= GL_MATRIX0_NV &&
|
|
|
|
ctx->VertexProgram.TrackMatrix[i] <= GL_MATRIX7_NV) {
|
|
|
|
GLuint n = ctx->VertexProgram.TrackMatrix[i] - GL_MATRIX0_NV;
|
|
|
|
ASSERT(n < MAX_PROGRAM_MATRICES);
|
|
|
|
mat = ctx->ProgramMatrixStack[n].Top;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* no matrix is tracked, but we leave the register values as-is */
|
|
|
|
assert(ctx->VertexProgram.TrackMatrix[i] == GL_NONE);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-02-23 13:38:37 -07:00
|
|
|
/* load the matrix values into sequential registers */
|
2007-02-22 16:07:17 -07:00
|
|
|
if (ctx->VertexProgram.TrackMatrixTransform[i] == GL_IDENTITY_NV) {
|
|
|
|
load_matrix(ctx->VertexProgram.Parameters, i*4, mat->m);
|
|
|
|
}
|
|
|
|
else if (ctx->VertexProgram.TrackMatrixTransform[i] == GL_INVERSE_NV) {
|
|
|
|
_math_matrix_analyse(mat); /* update the inverse */
|
|
|
|
ASSERT(!_math_matrix_is_dirty(mat));
|
|
|
|
load_matrix(ctx->VertexProgram.Parameters, i*4, mat->inv);
|
|
|
|
}
|
|
|
|
else if (ctx->VertexProgram.TrackMatrixTransform[i] == GL_TRANSPOSE_NV) {
|
|
|
|
load_transpose_matrix(ctx->VertexProgram.Parameters, i*4, mat->m);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
assert(ctx->VertexProgram.TrackMatrixTransform[i]
|
|
|
|
== GL_INVERSE_TRANSPOSE_NV);
|
|
|
|
_math_matrix_analyse(mat); /* update the inverse */
|
|
|
|
ASSERT(!_math_matrix_is_dirty(mat));
|
|
|
|
load_transpose_matrix(ctx->VertexProgram.Parameters, i*4, mat->inv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-22 14:35:16 +00:00
|
|
|
/**
|
|
|
|
* This function executes vertex programs
|
|
|
|
*/
|
2004-04-21 18:09:14 +00:00
|
|
|
static GLboolean
|
|
|
|
run_vp( GLcontext *ctx, struct tnl_pipeline_stage *stage )
|
2001-12-14 02:50:01 +00:00
|
|
|
{
|
|
|
|
TNLcontext *tnl = TNL_CONTEXT(ctx);
|
|
|
|
struct vp_stage_data *store = VP_STAGE_DATA(stage);
|
|
|
|
struct vertex_buffer *VB = &tnl->vb;
|
2006-12-13 14:58:13 -07:00
|
|
|
struct gl_vertex_program *program = ctx->VertexProgram._Current;
|
2007-02-22 16:07:17 -07:00
|
|
|
struct gl_program_machine machine;
|
2007-02-25 17:29:00 -07:00
|
|
|
GLuint outputs[VERT_RESULT_MAX], numOutputs;
|
|
|
|
GLuint i, j;
|
2001-12-14 02:50:01 +00:00
|
|
|
|
2007-02-24 11:16:58 -07:00
|
|
|
#define FORCE_PROG_EXECUTE_C 1
|
2007-02-22 16:07:17 -07:00
|
|
|
#if FORCE_PROG_EXECUTE_C
|
|
|
|
if (!program)
|
|
|
|
return GL_TRUE;
|
|
|
|
#else
|
2006-12-13 14:58:13 -07:00
|
|
|
if (!program || !program->IsNVProgram)
|
2006-02-13 11:23:36 +00:00
|
|
|
return GL_TRUE;
|
2007-02-22 16:07:17 -07:00
|
|
|
#endif
|
2006-02-13 11:23:36 +00:00
|
|
|
|
2007-02-22 16:07:17 -07:00
|
|
|
if (ctx->VertexProgram.Current->IsNVProgram) {
|
2007-02-23 13:38:37 -07:00
|
|
|
_mesa_load_tracked_matrices(ctx);
|
2007-02-22 16:07:17 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
_mesa_load_state_parameters(ctx, program->Base.Parameters);
|
|
|
|
}
|
2001-12-14 02:50:01 +00:00
|
|
|
|
2007-02-25 17:29:00 -07:00
|
|
|
numOutputs = 0;
|
|
|
|
for (i = 0; i < VERT_RESULT_MAX; i++) {
|
|
|
|
if (program->Base.OutputsWritten & (1 << i)) {
|
|
|
|
outputs[numOutputs++] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-14 02:50:01 +00:00
|
|
|
for (i = 0; i < VB->Count; i++) {
|
|
|
|
GLuint attr;
|
|
|
|
|
2007-02-22 16:07:17 -07:00
|
|
|
init_machine(ctx, &machine);
|
2004-04-21 18:09:14 +00:00
|
|
|
|
2001-12-15 22:31:23 +00:00
|
|
|
#if 0
|
2001-12-14 02:50:01 +00:00
|
|
|
printf("Input %d: %f, %f, %f, %f\n", i,
|
|
|
|
VB->AttribPtr[0]->data[i][0],
|
|
|
|
VB->AttribPtr[0]->data[i][1],
|
|
|
|
VB->AttribPtr[0]->data[i][2],
|
|
|
|
VB->AttribPtr[0]->data[i][3]);
|
|
|
|
printf(" color: %f, %f, %f, %f\n",
|
|
|
|
VB->AttribPtr[3]->data[i][0],
|
|
|
|
VB->AttribPtr[3]->data[i][1],
|
|
|
|
VB->AttribPtr[3]->data[i][2],
|
|
|
|
VB->AttribPtr[3]->data[i][3]);
|
2001-12-15 02:13:32 +00:00
|
|
|
printf(" normal: %f, %f, %f, %f\n",
|
|
|
|
VB->AttribPtr[2]->data[i][0],
|
|
|
|
VB->AttribPtr[2]->data[i][1],
|
|
|
|
VB->AttribPtr[2]->data[i][2],
|
|
|
|
VB->AttribPtr[2]->data[i][3]);
|
2001-12-15 22:31:23 +00:00
|
|
|
#endif
|
2001-12-14 02:50:01 +00:00
|
|
|
|
2003-11-24 15:23:18 +00:00
|
|
|
/* the vertex array case */
|
|
|
|
for (attr = 0; attr < VERT_ATTRIB_MAX; attr++) {
|
2005-11-12 17:53:14 +00:00
|
|
|
if (program->Base.InputsRead & (1 << attr)) {
|
2003-11-24 15:23:18 +00:00
|
|
|
const GLubyte *ptr = (const GLubyte*) VB->AttribPtr[attr]->data;
|
|
|
|
const GLuint size = VB->AttribPtr[attr]->size;
|
|
|
|
const GLuint stride = VB->AttribPtr[attr]->stride;
|
|
|
|
const GLfloat *data = (GLfloat *) (ptr + stride * i);
|
2007-02-25 12:47:25 -07:00
|
|
|
COPY_CLEAN_4V(machine.VertAttribs[attr], size, data);
|
2003-11-24 15:23:18 +00:00
|
|
|
}
|
2001-12-14 02:50:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* execute the program */
|
2007-02-22 16:07:17 -07:00
|
|
|
_mesa_execute_program(ctx, &program->Base, program->Base.NumInstructions,
|
|
|
|
&machine, 0);
|
2002-08-08 16:55:56 +00:00
|
|
|
|
|
|
|
/* Fixup fog an point size results if needed */
|
|
|
|
if (ctx->Fog.Enabled &&
|
2005-11-12 17:53:14 +00:00
|
|
|
(program->Base.OutputsWritten & (1 << VERT_RESULT_FOGC)) == 0) {
|
2006-10-30 00:12:05 +00:00
|
|
|
machine.Outputs[VERT_RESULT_FOGC][0] = 1.0;
|
2002-08-08 16:55:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ctx->VertexProgram.PointSizeEnabled &&
|
2005-11-12 17:53:14 +00:00
|
|
|
(program->Base.OutputsWritten & (1 << VERT_RESULT_PSIZ)) == 0) {
|
2006-10-30 00:12:05 +00:00
|
|
|
machine.Outputs[VERT_RESULT_PSIZ][0] = ctx->Point.Size;
|
2002-08-08 16:55:56 +00:00
|
|
|
}
|
|
|
|
|
2002-01-06 03:54:12 +00:00
|
|
|
/* copy the output registers into the VB->attribs arrays */
|
2007-02-25 17:29:00 -07:00
|
|
|
for (j = 0; j < numOutputs; j++) {
|
|
|
|
const GLuint attr = outputs[j];
|
|
|
|
COPY_4V(store->attribs[attr].data[i], machine.Outputs[attr]);
|
2002-01-06 03:54:12 +00:00
|
|
|
}
|
2006-12-13 14:58:13 -07:00
|
|
|
#if 0
|
|
|
|
printf("HPOS: %f %f %f %f\n",
|
|
|
|
machine.Outputs[0][0],
|
|
|
|
machine.Outputs[0][1],
|
|
|
|
machine.Outputs[0][2],
|
|
|
|
machine.Outputs[0][3]);
|
|
|
|
#endif
|
2001-12-14 02:50:01 +00:00
|
|
|
}
|
|
|
|
|
2002-01-06 03:54:12 +00:00
|
|
|
/* Setup the VB pointers so that the next pipeline stages get
|
|
|
|
* their data from the right place (the program output arrays).
|
|
|
|
*/
|
|
|
|
VB->ClipPtr = &store->attribs[VERT_RESULT_HPOS];
|
2001-12-15 22:31:23 +00:00
|
|
|
VB->ClipPtr->size = 4;
|
|
|
|
VB->ClipPtr->count = VB->Count;
|
2003-11-24 15:23:18 +00:00
|
|
|
VB->ColorPtr[0] = &store->attribs[VERT_RESULT_COL0];
|
|
|
|
VB->ColorPtr[1] = &store->attribs[VERT_RESULT_BFC0];
|
|
|
|
VB->SecondaryColorPtr[0] = &store->attribs[VERT_RESULT_COL1];
|
|
|
|
VB->SecondaryColorPtr[1] = &store->attribs[VERT_RESULT_BFC1];
|
2002-01-06 03:54:12 +00:00
|
|
|
VB->FogCoordPtr = &store->attribs[VERT_RESULT_FOGC];
|
2004-01-05 09:43:42 +00:00
|
|
|
|
2006-06-14 04:05:17 +00:00
|
|
|
VB->AttribPtr[VERT_ATTRIB_COLOR0] = &store->attribs[VERT_RESULT_COL0];
|
|
|
|
VB->AttribPtr[VERT_ATTRIB_COLOR1] = &store->attribs[VERT_RESULT_COL1];
|
|
|
|
VB->AttribPtr[VERT_ATTRIB_FOG] = &store->attribs[VERT_RESULT_FOGC];
|
2004-01-05 15:24:53 +00:00
|
|
|
VB->AttribPtr[_TNL_ATTRIB_POINTSIZE] = &store->attribs[VERT_RESULT_PSIZ];
|
2004-01-05 09:43:42 +00:00
|
|
|
|
2006-04-14 02:20:18 +00:00
|
|
|
for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
|
2006-06-14 04:05:17 +00:00
|
|
|
VB->TexCoordPtr[i] =
|
|
|
|
VB->AttribPtr[_TNL_ATTRIB_TEX0 + i]
|
|
|
|
= &store->attribs[VERT_RESULT_TEX0 + i];
|
2004-01-05 09:43:42 +00:00
|
|
|
}
|
|
|
|
|
2007-02-22 16:07:17 -07:00
|
|
|
for (i = 0; i < ctx->Const.MaxVarying; i++) {
|
|
|
|
if (program->Base.OutputsWritten & (1 << (VERT_RESULT_VAR0 + i))) {
|
|
|
|
/* Note: varying results get put into the generic attributes */
|
|
|
|
VB->AttribPtr[VERT_ATTRIB_GENERIC0+i]
|
|
|
|
= &store->attribs[VERT_RESULT_VAR0 + i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-15 22:31:23 +00:00
|
|
|
/* Cliptest and perspective divide. Clip functions must clear
|
|
|
|
* the clipmask.
|
2001-12-14 02:50:01 +00:00
|
|
|
*/
|
2001-12-15 22:31:23 +00:00
|
|
|
store->ormask = 0;
|
2006-04-06 22:11:57 +00:00
|
|
|
store->andmask = CLIP_FRUSTUM_BITS;
|
2001-12-14 02:50:01 +00:00
|
|
|
|
2001-12-18 04:06:44 +00:00
|
|
|
if (tnl->NeedNdcCoords) {
|
|
|
|
VB->NdcPtr =
|
2001-12-15 22:31:23 +00:00
|
|
|
_mesa_clip_tab[VB->ClipPtr->size]( VB->ClipPtr,
|
|
|
|
&store->ndcCoords,
|
|
|
|
store->clipmask,
|
|
|
|
&store->ormask,
|
|
|
|
&store->andmask );
|
|
|
|
}
|
|
|
|
else {
|
2005-02-10 10:57:22 +00:00
|
|
|
VB->NdcPtr = NULL;
|
2001-12-15 22:31:23 +00:00
|
|
|
_mesa_clip_np_tab[VB->ClipPtr->size]( VB->ClipPtr,
|
2005-02-10 10:57:22 +00:00
|
|
|
NULL,
|
2001-12-15 22:31:23 +00:00
|
|
|
store->clipmask,
|
|
|
|
&store->ormask,
|
|
|
|
&store->andmask );
|
2001-12-14 02:50:01 +00:00
|
|
|
}
|
|
|
|
|
2001-12-15 22:31:23 +00:00
|
|
|
if (store->andmask) /* All vertices are outside the frustum */
|
|
|
|
return GL_FALSE;
|
2001-12-14 02:50:01 +00:00
|
|
|
|
2001-12-15 22:31:23 +00:00
|
|
|
|
|
|
|
/* This is where we'd do clip testing against the user-defined
|
|
|
|
* clipping planes, but they're not supported by vertex programs.
|
2001-12-14 02:50:01 +00:00
|
|
|
*/
|
2001-12-15 22:31:23 +00:00
|
|
|
|
|
|
|
VB->ClipOrMask = store->ormask;
|
|
|
|
VB->ClipMask = store->clipmask;
|
|
|
|
|
2001-12-14 02:50:01 +00:00
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-22 14:35:16 +00:00
|
|
|
/**
|
|
|
|
* Called the first time stage->run is called. In effect, don't
|
2001-12-14 02:50:01 +00:00
|
|
|
* allocate data until the first time the stage is run.
|
|
|
|
*/
|
2005-04-22 12:51:19 +00:00
|
|
|
static GLboolean init_vp( GLcontext *ctx,
|
|
|
|
struct tnl_pipeline_stage *stage )
|
2001-12-14 02:50:01 +00:00
|
|
|
{
|
|
|
|
TNLcontext *tnl = TNL_CONTEXT(ctx);
|
|
|
|
struct vertex_buffer *VB = &(tnl->vb);
|
|
|
|
struct vp_stage_data *store;
|
|
|
|
const GLuint size = VB->Size;
|
|
|
|
GLuint i;
|
|
|
|
|
|
|
|
stage->privatePtr = MALLOC(sizeof(*store));
|
|
|
|
store = VP_STAGE_DATA(stage);
|
|
|
|
if (!store)
|
|
|
|
return GL_FALSE;
|
|
|
|
|
2002-01-06 03:54:12 +00:00
|
|
|
/* Allocate arrays of vertex output values */
|
2006-12-13 14:58:13 -07:00
|
|
|
for (i = 0; i < VERT_RESULT_MAX; i++) {
|
2002-01-06 03:54:12 +00:00
|
|
|
_mesa_vector4f_alloc( &store->attribs[i], 0, size, 32 );
|
2003-04-07 23:07:50 +00:00
|
|
|
store->attribs[i].size = 4;
|
|
|
|
}
|
2002-01-06 03:54:12 +00:00
|
|
|
|
|
|
|
/* a few other misc allocations */
|
2001-12-15 22:31:23 +00:00
|
|
|
_mesa_vector4f_alloc( &store->ndcCoords, 0, size, 32 );
|
|
|
|
store->clipmask = (GLubyte *) ALIGN_MALLOC(sizeof(GLubyte)*size, 32 );
|
2001-12-14 02:50:01 +00:00
|
|
|
|
2005-04-22 12:51:19 +00:00
|
|
|
return GL_TRUE;
|
2001-12-14 02:50:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-22 14:35:16 +00:00
|
|
|
/**
|
|
|
|
* Destructor for this pipeline stage.
|
|
|
|
*/
|
2003-11-24 15:23:18 +00:00
|
|
|
static void dtr( struct tnl_pipeline_stage *stage )
|
2001-12-14 02:50:01 +00:00
|
|
|
{
|
|
|
|
struct vp_stage_data *store = VP_STAGE_DATA(stage);
|
|
|
|
|
|
|
|
if (store) {
|
|
|
|
GLuint i;
|
2002-01-06 03:54:12 +00:00
|
|
|
|
|
|
|
/* free the vertex program result arrays */
|
2005-04-22 12:51:19 +00:00
|
|
|
for (i = 0; i < VERT_RESULT_MAX; i++)
|
2002-01-06 03:54:12 +00:00
|
|
|
_mesa_vector4f_free( &store->attribs[i] );
|
|
|
|
|
|
|
|
/* free misc arrays */
|
2001-12-15 22:31:23 +00:00
|
|
|
_mesa_vector4f_free( &store->ndcCoords );
|
|
|
|
ALIGN_FREE( store->clipmask );
|
2001-12-14 02:50:01 +00:00
|
|
|
|
|
|
|
FREE( store );
|
2005-02-10 10:57:22 +00:00
|
|
|
stage->privatePtr = NULL;
|
2001-12-14 02:50:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-22 16:07:17 -07:00
|
|
|
|
2002-01-22 14:35:16 +00:00
|
|
|
/**
|
|
|
|
* Public description of this pipeline stage.
|
|
|
|
*/
|
2003-11-24 15:23:18 +00:00
|
|
|
const struct tnl_pipeline_stage _tnl_vertex_program_stage =
|
2001-12-14 02:50:01 +00:00
|
|
|
{
|
|
|
|
"vertex-program",
|
|
|
|
NULL, /* private_data */
|
2005-04-22 12:51:19 +00:00
|
|
|
init_vp, /* create */
|
2001-12-14 02:50:01 +00:00
|
|
|
dtr, /* destroy */
|
2005-04-22 12:51:19 +00:00
|
|
|
NULL, /* validate */
|
|
|
|
run_vp /* run -- initially set to ctr */
|
2001-12-14 02:50:01 +00:00
|
|
|
};
|