2001-12-14 02:50:01 +00:00
|
|
|
/*
|
|
|
|
* Mesa 3-D graphics library
|
2006-02-13 11:23:36 +00:00
|
|
|
* Version: 6.5
|
2001-12-14 02:50:01 +00:00
|
|
|
*
|
2006-02-13 11:23:36 +00:00
|
|
|
* Copyright (C) 1999-2006 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 "api_noop.h"
|
|
|
|
#include "colormac.h"
|
|
|
|
#include "context.h"
|
|
|
|
#include "dlist.h"
|
|
|
|
#include "hash.h"
|
|
|
|
#include "light.h"
|
|
|
|
#include "macros.h"
|
2002-10-24 23:57:19 +00:00
|
|
|
#include "imports.h"
|
2001-12-14 02:50:01 +00:00
|
|
|
#include "simple_list.h"
|
|
|
|
#include "mtypes.h"
|
2005-11-05 17:10:45 +00:00
|
|
|
#include "program_instruction.h"
|
2003-01-14 04:55:45 +00:00
|
|
|
#include "nvvertexec.h"
|
|
|
|
#include "nvprogram.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. */
|
2002-01-06 03:54:12 +00:00
|
|
|
GLvector4f attribs[15];
|
|
|
|
|
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))
|
|
|
|
|
|
|
|
|
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;
|
2003-01-14 04:55:45 +00:00
|
|
|
struct vertex_program *program = ctx->VertexProgram.Current;
|
2002-04-04 18:25:40 +00:00
|
|
|
GLuint i;
|
2001-12-14 02:50:01 +00:00
|
|
|
|
2006-03-21 10:37:40 +00:00
|
|
|
if (ctx->ShaderObjects._VertexShaderPresent)
|
2006-02-13 11:23:36 +00:00
|
|
|
return GL_TRUE;
|
|
|
|
|
2005-06-09 14:55:34 +00:00
|
|
|
if (!ctx->VertexProgram._Enabled ||
|
|
|
|
!program->IsNVProgram)
|
2005-04-22 12:51:19 +00:00
|
|
|
return GL_TRUE;
|
|
|
|
|
2004-04-21 18:09:14 +00:00
|
|
|
/* load program parameter registers (they're read-only) */
|
|
|
|
_mesa_init_vp_per_primitive_registers(ctx);
|
2001-12-14 02:50:01 +00:00
|
|
|
|
|
|
|
for (i = 0; i < VB->Count; i++) {
|
|
|
|
GLuint attr;
|
|
|
|
|
2004-04-21 18:09:14 +00:00
|
|
|
_mesa_init_vp_per_vertex_registers(ctx);
|
|
|
|
|
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);
|
2005-03-02 18:57:01 +00:00
|
|
|
COPY_CLEAN_4V(ctx->VertexProgram.Inputs[attr], size, data);
|
2003-11-24 15:23:18 +00:00
|
|
|
}
|
2001-12-14 02:50:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* execute the program */
|
2002-01-06 20:39:03 +00:00
|
|
|
ASSERT(program);
|
2003-01-14 04:55:45 +00:00
|
|
|
_mesa_exec_vertex_program(ctx, program);
|
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) {
|
2003-08-17 17:11:50 +00:00
|
|
|
ctx->VertexProgram.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) {
|
2003-08-17 17:11:50 +00:00
|
|
|
ctx->VertexProgram.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 */
|
|
|
|
/* XXX (optimize) could use a conditional and smaller loop limit here */
|
|
|
|
for (attr = 0; attr < 15; attr++) {
|
2003-08-17 17:11:50 +00:00
|
|
|
COPY_4V(store->attribs[attr].data[i],
|
|
|
|
ctx->VertexProgram.Outputs[attr]);
|
2002-01-06 03:54:12 +00:00
|
|
|
}
|
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];
|
|
|
|
VB->PointSizePtr = &store->attribs[VERT_RESULT_PSIZ];
|
2004-01-05 09:43:42 +00:00
|
|
|
|
|
|
|
VB->AttribPtr[VERT_ATTRIB_COLOR0] = VB->ColorPtr[0];
|
|
|
|
VB->AttribPtr[VERT_ATTRIB_COLOR1] = VB->SecondaryColorPtr[0];
|
|
|
|
VB->AttribPtr[VERT_ATTRIB_FOG] = VB->FogCoordPtr;
|
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++) {
|
2004-01-05 09:43:42 +00:00
|
|
|
VB->AttribPtr[VERT_ATTRIB_TEX0+i] = VB->TexCoordPtr[i] =
|
|
|
|
&store->attribs[VERT_RESULT_TEX0 + i];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-14 02:50:01 +00:00
|
|
|
|
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-06-13 03:29:02 +00:00
|
|
|
/* XXX change '15' to a named constant */
|
2003-04-07 23:07:50 +00:00
|
|
|
for (i = 0; i < 15; 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
};
|