Enable texture sampling for vertex programs/shaders.

This is a bit of a hack for now because the tnl module is using the swrast
module to fetch texels.  The texture fetch/filter code should probably be
moved into the main/ module since it doesn't really depend upon other
swrast code.
This commit is contained in:
Brian
2007-04-17 15:56:46 -06:00
parent d2d86a3f0b
commit 04bda46739
4 changed files with 70 additions and 20 deletions

View File

@@ -25,12 +25,13 @@
/**
* \file tnl/t_vb_program.c
* \brief Pipeline stage for executing NVIDIA vertex programs.
* \brief Pipeline stage for executing vertex programs.
* \author Brian Paul, Keith Whitwell
*/
#include "glheader.h"
#include "colormac.h"
#include "context.h"
#include "macros.h"
#include "imports.h"
@@ -42,6 +43,32 @@
#include "t_context.h"
#include "t_pipeline.h"
#include "swrast/s_context.h"
#include "swrast/s_texfilter.h"
/**
* XXX the texture sampling code in this module is a bit of a hack.
* The texture sampling code is in swrast, though it doesn't have any
* real dependencies on the rest of swrast. It should probably be
* moved into main/ someday.
*/
static void
vp_fetch_texel(GLcontext *ctx, const GLfloat texcoord[4], GLfloat lambda,
GLuint unit, GLfloat color[4])
{
GLchan rgba[4];
SWcontext *swrast = SWRAST_CONTEXT(ctx);
/* XXX use a float-valued TextureSample routine here!!! */
swrast->TextureSample[unit](ctx, ctx->Texture.Unit[unit]._Current,
1, (const GLfloat (*)[4]) texcoord,
&lambda, &rgba);
color[0] = CHAN_TO_FLOAT(rgba[0]);
color[1] = CHAN_TO_FLOAT(rgba[1]);
color[2] = CHAN_TO_FLOAT(rgba[2]);
color[3] = CHAN_TO_FLOAT(rgba[3]);
}
/**
@@ -107,6 +134,9 @@ init_machine(GLcontext *ctx, struct gl_program_machine *machine)
/* init call stack */
machine->StackDepth = 0;
machine->FetchTexelLod = vp_fetch_texel;
machine->FetchTexelDeriv = NULL; /* not used by vertex programs */
}
@@ -216,19 +246,14 @@ run_vp( GLcontext *ctx, struct tnl_pipeline_stage *stage )
GLuint outputs[VERT_RESULT_MAX], numOutputs;
GLuint i, j;
#define FORCE_PROG_EXECUTE_C 1
#if FORCE_PROG_EXECUTE_C
if (!program)
return GL_TRUE;
#else
if (!program || !program->IsNVProgram)
return GL_TRUE;
#endif
if (program->IsNVProgram) {
_mesa_load_tracked_matrices(ctx);
}
else {
/* ARB program or vertex shader */
_mesa_load_state_parameters(ctx, program->Base.Parameters);
}
@@ -380,8 +405,8 @@ run_vp( GLcontext *ctx, struct tnl_pipeline_stage *stage )
* Called the first time stage->run is called. In effect, don't
* allocate data until the first time the stage is run.
*/
static GLboolean init_vp( GLcontext *ctx,
struct tnl_pipeline_stage *stage )
static GLboolean
init_vp(GLcontext *ctx, struct tnl_pipeline_stage *stage)
{
TNLcontext *tnl = TNL_CONTEXT(ctx);
struct vertex_buffer *VB = &(tnl->vb);
@@ -411,7 +436,8 @@ static GLboolean init_vp( GLcontext *ctx,
/**
* Destructor for this pipeline stage.
*/
static void dtr( struct tnl_pipeline_stage *stage )
static void
dtr(struct tnl_pipeline_stage *stage)
{
struct vp_stage_data *store = VP_STAGE_DATA(stage);
@@ -432,6 +458,16 @@ static void dtr( struct tnl_pipeline_stage *stage )
}
static void
validate_vp_stage(GLcontext *ctx, struct tnl_pipeline_stage *stage)
{
if (ctx->VertexProgram._Current) {
_swrast_update_texture_samplers(ctx);
}
}
/**
* Public description of this pipeline stage.
*/
@@ -441,6 +477,6 @@ const struct tnl_pipeline_stage _tnl_vertex_program_stage =
NULL, /* private_data */
init_vp, /* create */
dtr, /* destroy */
NULL, /* validate */
validate_vp_stage, /* validate */
run_vp /* run -- initially set to ctr */
};