/*
* Mesa 3-D graphics library
- * Version: 6.2
+ * Version: 6.5.2
*
- * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
#include "imports.h"
#include "macros.h"
#include "mtypes.h"
-#include "program.h"
#include "nvfragparse.h"
-#include "nvfragprog.h"
+#include "program.h"
+#include "prog_parameter.h"
+#include "prog_instruction.h"
+#include "prog_statevars.h"
#include "nvvertparse.h"
-#include "nvvertprog.h"
+#include "atifragshader.h"
+
/**********************************************************************/
/* A pointer to this dummy program is put into the hash table when
* glGenPrograms is called.
*/
-struct program _mesa_DummyProgram;
+struct gl_program _mesa_DummyProgram;
/**
ctx->VertexProgram.Enabled = GL_FALSE;
ctx->VertexProgram.PointSizeEnabled = GL_FALSE;
ctx->VertexProgram.TwoSideEnabled = GL_FALSE;
- ctx->VertexProgram.Current = (struct vertex_program *) ctx->Shared->DefaultVertexProgram;
+ ctx->VertexProgram.Current = (struct gl_vertex_program *) ctx->Shared->DefaultVertexProgram;
assert(ctx->VertexProgram.Current);
ctx->VertexProgram.Current->Base.RefCount++;
for (i = 0; i < MAX_NV_VERTEX_PROGRAM_PARAMS / 4; i++) {
#if FEATURE_NV_fragment_program || FEATURE_ARB_fragment_program
ctx->FragmentProgram.Enabled = GL_FALSE;
- ctx->FragmentProgram.Current = (struct fragment_program *) ctx->Shared->DefaultFragmentProgram;
+ ctx->FragmentProgram.Current = (struct gl_fragment_program *) ctx->Shared->DefaultFragmentProgram;
assert(ctx->FragmentProgram.Current);
ctx->FragmentProgram.Current->Base.RefCount++;
#endif
+ /* XXX probably move this stuff */
#if FEATURE_ATI_fragment_shader
ctx->ATIFragmentShader.Enabled = GL_FALSE;
ctx->ATIFragmentShader.Current = (struct ati_fragment_shader *) ctx->Shared->DefaultFragmentShader;
assert(ctx->ATIFragmentShader.Current);
- ctx->ATIFragmentShader.Current->Base.RefCount++;
+ ctx->ATIFragmentShader.Current->RefCount++;
#endif
}
void
_mesa_free_program_data(GLcontext *ctx)
{
-#if FEATURE_NV_vertex_program
+#if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program
if (ctx->VertexProgram.Current) {
ctx->VertexProgram.Current->Base.RefCount--;
if (ctx->VertexProgram.Current->Base.RefCount <= 0)
ctx->Driver.DeleteProgram(ctx, &(ctx->VertexProgram.Current->Base));
}
#endif
-#if FEATURE_NV_fragment_program
+#if FEATURE_NV_fragment_program || FEATURE_ARB_fragment_program
if (ctx->FragmentProgram.Current) {
ctx->FragmentProgram.Current->Base.RefCount--;
if (ctx->FragmentProgram.Current->Base.RefCount <= 0)
ctx->Driver.DeleteProgram(ctx, &(ctx->FragmentProgram.Current->Base));
}
#endif
+ /* XXX probably move this stuff */
#if FEATURE_ATI_fragment_shader
if (ctx->ATIFragmentShader.Current) {
- ctx->ATIFragmentShader.Current->Base.RefCount--;
- if (ctx->ATIFragmentShader.Current->Base.RefCount <= 0)
- ctx->Driver.DeleteProgram(ctx, &(ctx->ATIFragmentShader.Current->Base));
+ ctx->ATIFragmentShader.Current->RefCount--;
+ if (ctx->ATIFragmentShader.Current->RefCount <= 0) {
+ _mesa_free(ctx->ATIFragmentShader.Current);
+ }
}
#endif
_mesa_free((void *) ctx->Program.ErrorString);
/**
* Initialize a new vertex/fragment program object.
*/
-static struct program *
-_mesa_init_program_struct( GLcontext *ctx, struct program *prog,
+static struct gl_program *
+_mesa_init_program_struct( GLcontext *ctx, struct gl_program *prog,
GLenum target, GLuint id)
{
(void) ctx;
if (prog) {
+ _mesa_bzero(prog, sizeof(*prog));
prog->Id = id;
prog->Target = target;
prog->Resident = GL_TRUE;
prog->RefCount = 1;
+ prog->Format = GL_PROGRAM_FORMAT_ASCII_ARB;
}
return prog;
/**
* Initialize a new fragment program object.
*/
-struct program *
-_mesa_init_fragment_program( GLcontext *ctx, struct fragment_program *prog,
+struct gl_program *
+_mesa_init_fragment_program( GLcontext *ctx, struct gl_fragment_program *prog,
GLenum target, GLuint id)
{
if (prog)
/**
* Initialize a new vertex program object.
*/
-struct program *
-_mesa_init_vertex_program( GLcontext *ctx, struct vertex_program *prog,
+struct gl_program *
+_mesa_init_vertex_program( GLcontext *ctx, struct gl_vertex_program *prog,
GLenum target, GLuint id)
{
if (prog)
return NULL;
}
-/**
- * Initialize a new ATI fragment shader object.
- */
-struct program *
-_mesa_init_ati_fragment_shader( GLcontext *ctx,
- struct ati_fragment_shader *prog,
- GLenum target, GLuint id )
-{
- if (prog)
- return _mesa_init_program_struct( ctx, &prog->Base, target, id );
- else
- return NULL;
-}
-
-
/**
* Allocate and initialize a new fragment/vertex program object but
* \param target program target/type
* \return pointer to new program object
*/
-struct program *
+struct gl_program *
_mesa_new_program(GLcontext *ctx, GLenum target, GLuint id)
{
switch (target) {
case GL_VERTEX_PROGRAM_ARB: /* == GL_VERTEX_PROGRAM_NV */
- return _mesa_init_vertex_program( ctx, CALLOC_STRUCT(vertex_program),
- target, id );
+ return _mesa_init_vertex_program(ctx, CALLOC_STRUCT(gl_vertex_program),
+ target, id );
case GL_FRAGMENT_PROGRAM_NV:
case GL_FRAGMENT_PROGRAM_ARB:
- return _mesa_init_fragment_program( ctx, CALLOC_STRUCT(fragment_program),
- target, id );
- case GL_FRAGMENT_SHADER_ATI:
- return _mesa_init_ati_fragment_shader( ctx, CALLOC_STRUCT(ati_fragment_shader),
- target, id );
-
+ return _mesa_init_fragment_program(ctx,
+ CALLOC_STRUCT(gl_fragment_program),
+ target, id );
default:
_mesa_problem(ctx, "bad target in _mesa_new_program");
return NULL;
* by a device driver function.
*/
void
-_mesa_delete_program(GLcontext *ctx, struct program *prog)
+_mesa_delete_program(GLcontext *ctx, struct gl_program *prog)
{
(void) ctx;
ASSERT(prog);
+ if (prog == &_mesa_DummyProgram)
+ return;
+
if (prog->String)
_mesa_free(prog->String);
- if (prog->Target == GL_VERTEX_PROGRAM_NV ||
- prog->Target == GL_VERTEX_STATE_PROGRAM_NV) {
- struct vertex_program *vprog = (struct vertex_program *) prog;
- if (vprog->Instructions) {
- GLuint i;
- for (i = 0; i < vprog->Base.NumInstructions; i++) {
- if (vprog->Instructions[i].Data)
- _mesa_free(vprog->Instructions[i].Data);
- }
- _mesa_free(vprog->Instructions);
- }
- if (vprog->Parameters)
- _mesa_free_parameter_list(vprog->Parameters);
- }
- else if (prog->Target == GL_FRAGMENT_PROGRAM_NV ||
- prog->Target == GL_FRAGMENT_PROGRAM_ARB) {
- struct fragment_program *fprog = (struct fragment_program *) prog;
- if (fprog->Instructions) {
- GLuint i;
- for (i = 0; i < fprog->Base.NumInstructions; i++) {
- if (fprog->Instructions[i].Data)
- _mesa_free(fprog->Instructions[i].Data);
- }
- _mesa_free(fprog->Instructions);
+
+ if (prog->Instructions) {
+ GLuint i;
+ for (i = 0; i < prog->NumInstructions; i++) {
+ if (prog->Instructions[i].Data)
+ _mesa_free(prog->Instructions[i].Data);
}
- if (fprog->Parameters)
- _mesa_free_parameter_list(fprog->Parameters);
+ _mesa_free(prog->Instructions);
}
- else if (prog->Target == GL_FRAGMENT_SHADER_ATI) {
- struct ati_fragment_shader *atifs = (struct ati_fragment_shader *)prog;
- if (atifs->Instructions)
- _mesa_free(atifs->Instructions);
- }
-
- _mesa_free(prog);
-}
-
-
-/**********************************************************************/
-/* Program parameter functions */
-/**********************************************************************/
-
-struct program_parameter_list *
-_mesa_new_parameter_list(void)
-{
- return (struct program_parameter_list *)
- _mesa_calloc(sizeof(struct program_parameter_list));
-}
-
-
-/**
- * Free a parameter list and all its parameters
- */
-void
-_mesa_free_parameter_list(struct program_parameter_list *paramList)
-{
- _mesa_free_parameters(paramList);
- _mesa_free(paramList);
-}
-
-
-/**
- * Free all the parameters in the given list, but don't free the
- * paramList structure itself.
- */
-void
-_mesa_free_parameters(struct program_parameter_list *paramList)
-{
- GLuint i;
- for (i = 0; i < paramList->NumParameters; i++) {
- _mesa_free((void *) paramList->Parameters[i].Name);
+ if (prog->Parameters) {
+ _mesa_free_parameter_list(prog->Parameters);
}
- _mesa_free(paramList->Parameters);
- paramList->NumParameters = 0;
- paramList->Parameters = NULL;
-}
-
-/**
- * Helper function used by the functions below.
- */
-static GLint
-add_parameter(struct program_parameter_list *paramList,
- const char *name, const GLfloat values[4],
- enum parameter_type type)
-{
- const GLuint n = paramList->NumParameters;
-
- paramList->Parameters = (struct program_parameter *)
- _mesa_realloc(paramList->Parameters,
- n * sizeof(struct program_parameter),
- (n + 1) * sizeof(struct program_parameter));
- if (!paramList->Parameters) {
- /* out of memory */
- paramList->NumParameters = 0;
- return -1;
- }
- else {
- paramList->NumParameters = n + 1;
- paramList->Parameters[n].Name = _mesa_strdup(name);
- paramList->Parameters[n].Type = type;
- if (values)
- COPY_4V(paramList->Parameters[n].Values, values);
- return (GLint) n;
+ if (prog->Varying) {
+ _mesa_free_parameter_list(prog->Varying);
}
-}
+ /* XXX this is a little ugly */
+ if (prog->Target == GL_VERTEX_PROGRAM_ARB) {
+ struct gl_vertex_program *vprog = (struct gl_vertex_program *) prog;
+ if (vprog->TnlData)
+ _mesa_free(vprog->TnlData);
+ }
-/**
- * Add a new named program parameter (Ex: NV_fragment_program DEFINE statement)
- * \return index of the new entry in the parameter list
- */
-GLint
-_mesa_add_named_parameter(struct program_parameter_list *paramList,
- const char *name, const GLfloat values[4])
-{
- return add_parameter(paramList, name, values, NAMED_PARAMETER);
-}
-
-
-/**
- * Add a new unnamed constant to the parameter list.
- * \param paramList - the parameter list
- * \param values - four float values
- * \return index of the new parameter.
- */
-GLint
-_mesa_add_named_constant(struct program_parameter_list *paramList,
- const char *name, const GLfloat values[4])
-{
- return add_parameter(paramList, name, values, CONSTANT);
-}
-
-
-/**
- * Add a new unnamed constant to the parameter list.
- * \param paramList - the parameter list
- * \param values - four float values
- * \return index of the new parameter.
- */
-GLint
-_mesa_add_unnamed_constant(struct program_parameter_list *paramList,
- const GLfloat values[4])
-{
- /* generate a new dummy name */
- static GLuint n = 0;
- char name[20];
- _mesa_sprintf(name, "constant%d", n);
- n++;
- /* store it */
- return add_parameter(paramList, name, values, CONSTANT);
-}
-
-
-/**
- * Add a new state reference to the parameter list.
- * \param paramList - the parameter list
- * \param state - an array of 6 state tokens
- *
- * \return index of the new parameter.
- */
-GLint
-_mesa_add_state_reference(struct program_parameter_list *paramList,
- GLint *stateTokens)
-{
- /* XXX Should we parse <stateString> here and produce the parameter's
- * list of STATE_* tokens here, or in the parser?
- */
- GLint a, idx;
-
- idx = add_parameter(paramList, "Some State", NULL, STATE);
-
- for (a=0; a<6; a++)
- paramList->Parameters[idx].StateIndexes[a] = (enum state_index) stateTokens[a];
-
- return idx;
+ _mesa_free(prog);
}
/**
- * Lookup a parameter value by name in the given parameter list.
- * \return pointer to the float[4] values.
+ * Return the gl_program object for a given ID.
+ * Basically just a wrapper for _mesa_HashLookup() to avoid a lot of
+ * casts elsewhere.
*/
-GLfloat *
-_mesa_lookup_parameter_value(struct program_parameter_list *paramList,
- GLsizei nameLen, const char *name)
+struct gl_program *
+_mesa_lookup_program(GLcontext *ctx, GLuint id)
{
- GLuint i;
-
- if (!paramList)
+ if (id)
+ return (struct gl_program *) _mesa_HashLookup(ctx->Shared->Programs, id);
+ else
return NULL;
-
- if (nameLen == -1) {
- /* name is null-terminated */
- for (i = 0; i < paramList->NumParameters; i++) {
- if (_mesa_strcmp(paramList->Parameters[i].Name, name) == 0)
- return paramList->Parameters[i].Values;
- }
- }
- else {
- /* name is not null-terminated, use nameLen */
- for (i = 0; i < paramList->NumParameters; i++) {
- if (_mesa_strncmp(paramList->Parameters[i].Name, name, nameLen) == 0
- && _mesa_strlen(paramList->Parameters[i].Name) == (size_t)nameLen)
- return paramList->Parameters[i].Values;
- }
- }
- return NULL;
}
/**
- * Lookup a parameter index by name in the given parameter list.
- * \return index of parameter in the list.
+ * Return a copy of a program.
+ * XXX Problem here if the program object is actually OO-derivation
+ * made by a device driver.
*/
-GLint
-_mesa_lookup_parameter_index(struct program_parameter_list *paramList,
- GLsizei nameLen, const char *name)
+struct gl_program *
+_mesa_clone_program(GLcontext *ctx, const struct gl_program *prog)
{
- GLint i;
+ struct gl_program *clone;
- if (!paramList)
- return -1;
+ clone = _mesa_new_program(ctx, prog->Target, prog->Id);
+ if (!clone)
+ return NULL;
- if (nameLen == -1) {
- /* name is null-terminated */
- for (i = 0; i < (GLint) paramList->NumParameters; i++) {
- if (_mesa_strcmp(paramList->Parameters[i].Name, name) == 0)
- return i;
- }
- }
- else {
- /* name is not null-terminated, use nameLen */
- for (i = 0; i < (GLint) paramList->NumParameters; i++) {
- if (_mesa_strncmp(paramList->Parameters[i].Name, name, nameLen) == 0
- && _mesa_strlen(paramList->Parameters[i].Name) == (size_t)nameLen)
- return i;
- }
+ assert(clone->Target == prog->Target);
+ clone->String = (GLubyte *) _mesa_strdup((char *) prog->String);
+ clone->RefCount = 1;
+ clone->Format = prog->Format;
+ clone->Instructions = _mesa_alloc_instructions(prog->NumInstructions);
+ if (!clone->Instructions) {
+ _mesa_delete_program(ctx, clone);
+ return NULL;
}
- return -1;
-}
-
-
-/**
- * Use the list of tokens in the state[] array to find global GL state
- * and return it in <value>. Usually, four values are returned in <value>
- * but matrix queries may return as many as 16 values.
- * This function is used for ARB vertex/fragment programs.
- * The program parser will produce the state[] values.
- */
-static void
-_mesa_fetch_state(GLcontext *ctx, const enum state_index state[],
- GLfloat *value)
-{
- switch (state[0]) {
- case STATE_MATERIAL:
- {
- /* state[1] is either 0=front or 1=back side */
- const GLuint face = (GLuint) state[1];
- /* state[2] is the material attribute */
- switch (state[2]) {
- case STATE_AMBIENT:
- if (face == 0)
- COPY_4V(value, ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_AMBIENT]);
- else
- COPY_4V(value, ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_AMBIENT]);
- return;
- case STATE_DIFFUSE:
- if (face == 0)
- COPY_4V(value, ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE]);
- else
- COPY_4V(value, ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE]);
- return;
- case STATE_SPECULAR:
- if (face == 0)
- COPY_4V(value, ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_SPECULAR]);
- else
- COPY_4V(value, ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_SPECULAR]);
- return;
- case STATE_EMISSION:
- if (face == 0)
- COPY_4V(value, ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_EMISSION]);
- else
- COPY_4V(value, ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_EMISSION]);
- return;
- case STATE_SHININESS:
- if (face == 0)
- value[0] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_SHININESS][0];
- else
- value[0] = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_SHININESS][0];
- value[1] = 0.0F;
- value[2] = 0.0F;
- value[3] = 1.0F;
- return;
- default:
- _mesa_problem(ctx, "Invalid material state in fetch_state");
- return;
- }
- }
- case STATE_LIGHT:
- {
- /* state[1] is the light number */
- const GLuint ln = (GLuint) state[1];
- /* state[2] is the light attribute */
- switch (state[2]) {
- case STATE_AMBIENT:
- COPY_4V(value, ctx->Light.Light[ln].Ambient);
- return;
- case STATE_DIFFUSE:
- COPY_4V(value, ctx->Light.Light[ln].Diffuse);
- return;
- case STATE_SPECULAR:
- COPY_4V(value, ctx->Light.Light[ln].Specular);
- return;
- case STATE_POSITION:
- COPY_4V(value, ctx->Light.Light[ln].EyePosition);
- return;
- case STATE_ATTENUATION:
- value[0] = ctx->Light.Light[ln].ConstantAttenuation;
- value[1] = ctx->Light.Light[ln].LinearAttenuation;
- value[2] = ctx->Light.Light[ln].QuadraticAttenuation;
- value[3] = ctx->Light.Light[ln].SpotExponent;
- return;
- case STATE_SPOT_DIRECTION:
- COPY_4V(value, ctx->Light.Light[ln].EyeDirection);
- return;
- case STATE_HALF:
- {
- GLfloat eye_z[] = {0, 0, 1};
-
- /* Compute infinite half angle vector:
- * half-vector = light_position + (0, 0, 1)
- * and then normalize. w = 0
- *
- * light.EyePosition.w should be 0 for infinite lights.
- */
- ADD_3V(value, eye_z, ctx->Light.Light[ln].EyePosition);
- NORMALIZE_3FV(value);
- value[3] = 0;
- }
- return;
- default:
- _mesa_problem(ctx, "Invalid light state in fetch_state");
- return;
- }
- }
- case STATE_LIGHTMODEL_AMBIENT:
- COPY_4V(value, ctx->Light.Model.Ambient);
- return;
- case STATE_LIGHTMODEL_SCENECOLOR:
- if (state[1] == 0) {
- /* front */
- GLint i;
- for (i = 0; i < 3; i++) {
- value[i] = ctx->Light.Model.Ambient[i]
- * ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_AMBIENT][i]
- + ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_EMISSION][i];
- }
- value[3] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3];
- }
- else {
- /* back */
- GLint i;
- for (i = 0; i < 3; i++) {
- value[i] = ctx->Light.Model.Ambient[i]
- * ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_AMBIENT][i]
- + ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_EMISSION][i];
- }
- value[3] = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3];
- }
- return;
- case STATE_LIGHTPROD:
+ memcpy(clone->Instructions, prog->Instructions,
+ prog->NumInstructions * sizeof(struct prog_instruction));
+ clone->InputsRead = prog->InputsRead;
+ clone->OutputsWritten = prog->OutputsWritten;
+ memcpy(clone->TexturesUsed, prog->TexturesUsed, sizeof(prog->TexturesUsed));
+
+ if (prog->Parameters)
+ clone->Parameters = _mesa_clone_parameter_list(prog->Parameters);
+ memcpy(clone->LocalParams, prog->LocalParams, sizeof(clone->LocalParams));
+ if (prog->Varying)
+ clone->Varying = _mesa_clone_parameter_list(prog->Varying);
+ if (prog->Attributes)
+ clone->Attributes = _mesa_clone_parameter_list(prog->Attributes);
+ memcpy(clone->LocalParams, prog->LocalParams, sizeof(clone->LocalParams));
+ clone->NumInstructions = prog->NumInstructions;
+ clone->NumTemporaries = prog->NumTemporaries;
+ clone->NumParameters = prog->NumParameters;
+ clone->NumAttributes = prog->NumAttributes;
+ clone->NumAddressRegs = prog->NumAddressRegs;
+ clone->NumNativeInstructions = prog->NumNativeInstructions;
+ clone->NumNativeTemporaries = prog->NumNativeTemporaries;
+ clone->NumNativeParameters = prog->NumNativeParameters;
+ clone->NumNativeAttributes = prog->NumNativeAttributes;
+ clone->NumNativeAddressRegs = prog->NumNativeAddressRegs;
+ clone->NumAluInstructions = prog->NumAluInstructions;
+ clone->NumTexInstructions = prog->NumTexInstructions;
+ clone->NumTexIndirections = prog->NumTexIndirections;
+ clone->NumNativeAluInstructions = prog->NumNativeAluInstructions;
+ clone->NumNativeTexInstructions = prog->NumNativeTexInstructions;
+ clone->NumNativeTexIndirections = prog->NumNativeTexIndirections;
+
+ switch (prog->Target) {
+ case GL_VERTEX_PROGRAM_ARB:
{
- const GLuint ln = (GLuint) state[1];
- const GLuint face = (GLuint) state[2];
- GLint i;
- ASSERT(face == 0 || face == 1);
- switch (state[3]) {
- case STATE_AMBIENT:
- for (i = 0; i < 3; i++) {
- value[i] = ctx->Light.Light[ln].Ambient[i] *
- ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_AMBIENT+face][i];
- }
- /* [3] = material alpha */
- value[3] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE+face][3];
- return;
- case STATE_DIFFUSE:
- for (i = 0; i < 3; i++) {
- value[i] = ctx->Light.Light[ln].Diffuse[i] *
- ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE+face][i];
- }
- /* [3] = material alpha */
- value[3] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE+face][3];
- return;
- case STATE_SPECULAR:
- for (i = 0; i < 3; i++) {
- value[i] = ctx->Light.Light[ln].Specular[i] *
- ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_SPECULAR+face][i];
- }
- /* [3] = material alpha */
- value[3] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE+face][3];
- return;
- default:
- _mesa_problem(ctx, "Invalid lightprod state in fetch_state");
- return;
- }
+ const struct gl_vertex_program *vp
+ = (const struct gl_vertex_program *) prog;
+ struct gl_vertex_program *vpc = (struct gl_vertex_program *) clone;
+ vpc->IsPositionInvariant = vp->IsPositionInvariant;
}
- case STATE_TEXGEN:
- {
- /* state[1] is the texture unit */
- const GLuint unit = (GLuint) state[1];
- /* state[2] is the texgen attribute */
- switch (state[2]) {
- case STATE_TEXGEN_EYE_S:
- COPY_4V(value, ctx->Texture.Unit[unit].EyePlaneS);
- return;
- case STATE_TEXGEN_EYE_T:
- COPY_4V(value, ctx->Texture.Unit[unit].EyePlaneT);
- return;
- case STATE_TEXGEN_EYE_R:
- COPY_4V(value, ctx->Texture.Unit[unit].EyePlaneR);
- return;
- case STATE_TEXGEN_EYE_Q:
- COPY_4V(value, ctx->Texture.Unit[unit].EyePlaneQ);
- return;
- case STATE_TEXGEN_OBJECT_S:
- COPY_4V(value, ctx->Texture.Unit[unit].ObjectPlaneS);
- return;
- case STATE_TEXGEN_OBJECT_T:
- COPY_4V(value, ctx->Texture.Unit[unit].ObjectPlaneT);
- return;
- case STATE_TEXGEN_OBJECT_R:
- COPY_4V(value, ctx->Texture.Unit[unit].ObjectPlaneR);
- return;
- case STATE_TEXGEN_OBJECT_Q:
- COPY_4V(value, ctx->Texture.Unit[unit].ObjectPlaneQ);
- return;
- default:
- _mesa_problem(ctx, "Invalid texgen state in fetch_state");
- return;
- }
- }
- case STATE_TEXENV_COLOR:
- {
- /* state[1] is the texture unit */
- const GLuint unit = (GLuint) state[1];
- COPY_4V(value, ctx->Texture.Unit[unit].EnvColor);
- }
- return;
- case STATE_FOG_COLOR:
- COPY_4V(value, ctx->Fog.Color);
- return;
- case STATE_FOG_PARAMS:
- value[0] = ctx->Fog.Density;
- value[1] = ctx->Fog.Start;
- value[2] = ctx->Fog.End;
- value[3] = 1.0F / (ctx->Fog.End - ctx->Fog.Start);
- return;
- case STATE_CLIPPLANE:
- {
- const GLuint plane = (GLuint) state[1];
- COPY_4V(value, ctx->Transform.EyeUserPlane[plane]);
- }
- return;
- case STATE_POINT_SIZE:
- value[0] = ctx->Point.Size;
- value[1] = ctx->Point.MinSize;
- value[2] = ctx->Point.MaxSize;
- value[3] = ctx->Point.Threshold;
- return;
- case STATE_POINT_ATTENUATION:
- value[0] = ctx->Point.Params[0];
- value[1] = ctx->Point.Params[1];
- value[2] = ctx->Point.Params[2];
- value[3] = 1.0F;
- return;
- case STATE_MATRIX:
- {
- /* state[1] = modelview, projection, texture, etc. */
- /* state[2] = which texture matrix or program matrix */
- /* state[3] = first column to fetch */
- /* state[4] = last column to fetch */
- /* state[5] = transpose, inverse or invtrans */
-
- const GLmatrix *matrix;
- const enum state_index mat = state[1];
- const GLuint index = (GLuint) state[2];
- const GLuint first = (GLuint) state[3];
- const GLuint last = (GLuint) state[4];
- const enum state_index modifier = state[5];
- const GLfloat *m;
- GLuint row, i;
- if (mat == STATE_MODELVIEW) {
- matrix = ctx->ModelviewMatrixStack.Top;
- }
- else if (mat == STATE_PROJECTION) {
- matrix = ctx->ProjectionMatrixStack.Top;
- }
- else if (mat == STATE_MVP) {
- matrix = &ctx->_ModelProjectMatrix;
- }
- else if (mat == STATE_TEXTURE) {
- matrix = ctx->TextureMatrixStack[index].Top;
- }
- else if (mat == STATE_PROGRAM) {
- matrix = ctx->ProgramMatrixStack[index].Top;
- }
- else {
- _mesa_problem(ctx, "Bad matrix name in _mesa_fetch_state()");
- return;
- }
- if (modifier == STATE_MATRIX_INVERSE ||
- modifier == STATE_MATRIX_INVTRANS) {
- /* Be sure inverse is up to date:
- */
- _math_matrix_analyse( matrix );
- m = matrix->inv;
- }
- else {
- m = matrix->m;
- }
- if (modifier == STATE_MATRIX_TRANSPOSE ||
- modifier == STATE_MATRIX_INVTRANS) {
- for (i = 0, row = first; row <= last; row++) {
- value[i++] = m[row * 4 + 0];
- value[i++] = m[row * 4 + 1];
- value[i++] = m[row * 4 + 2];
- value[i++] = m[row * 4 + 3];
- }
- }
- else {
- for (i = 0, row = first; row <= last; row++) {
- value[i++] = m[row + 0];
- value[i++] = m[row + 4];
- value[i++] = m[row + 8];
- value[i++] = m[row + 12];
- }
- }
- }
- return;
- case STATE_DEPTH_RANGE:
- value[0] = ctx->Viewport.Near; /* near */
- value[1] = ctx->Viewport.Far; /* far */
- value[2] = ctx->Viewport.Far - ctx->Viewport.Near; /* far - near */
- value[3] = 0;
- return;
- case STATE_FRAGMENT_PROGRAM:
- {
- /* state[1] = {STATE_ENV, STATE_LOCAL} */
- /* state[2] = parameter index */
- const int idx = (int) state[2];
- switch (state[1]) {
- case STATE_ENV:
- COPY_4V(value, ctx->FragmentProgram.Parameters[idx]);
- break;
- case STATE_LOCAL:
- COPY_4V(value, ctx->FragmentProgram.Current->Base.LocalParams[idx]);
- break;
- default:
- _mesa_problem(ctx, "Bad state switch in _mesa_fetch_state()");
- return;
- }
- }
- return;
-
- case STATE_VERTEX_PROGRAM:
+ break;
+ case GL_FRAGMENT_PROGRAM_ARB:
{
- /* state[1] = {STATE_ENV, STATE_LOCAL} */
- /* state[2] = parameter index */
- const int idx = (int) state[2];
- switch (state[1]) {
- case STATE_ENV:
- COPY_4V(value, ctx->VertexProgram.Parameters[idx]);
- break;
- case STATE_LOCAL:
- COPY_4V(value, ctx->VertexProgram.Current->Base.LocalParams[idx]);
- break;
- default:
- _mesa_problem(ctx, "Bad state switch in _mesa_fetch_state()");
- return;
- }
+ const struct gl_fragment_program *fp
+ = (const struct gl_fragment_program *) prog;
+ struct gl_fragment_program *fpc = (struct gl_fragment_program *) clone;
+ fpc->FogOption = fp->FogOption;
+ fpc->UsesKill = fp->UsesKill;
}
- return;
+ break;
default:
- _mesa_problem(ctx, "Invalid state in _mesa_fetch_state");
- return;
+ _mesa_problem(NULL, "Unexpected target in _mesa_clone_program");
}
+
+ return clone;
}
+
/**
- * Loop over all the parameters in a parameter list. If the parameter
- * is a GL state reference, look up the current value of that state
- * variable and put it into the parameter's Value[4] array.
- * This would be called at glBegin time when using a fragment program.
+ * Mixing ARB and NV vertex/fragment programs can be tricky.
+ * Note: GL_VERTEX_PROGRAM_ARB == GL_VERTEX_PROGRAM_NV
+ * but, GL_FRAGMENT_PROGRAM_ARB != GL_FRAGMENT_PROGRAM_NV
+ * The two different fragment program targets are supposed to be compatible
+ * to some extent (see GL_ARB_fragment_program spec).
+ * This function does the compatibility check.
*/
-void
-_mesa_load_state_parameters(GLcontext *ctx,
- struct program_parameter_list *paramList)
+static GLboolean
+compatible_program_targets(GLenum t1, GLenum t2)
{
- GLuint i;
-
- if (!paramList)
- return;
-
- for (i = 0; i < paramList->NumParameters; i++) {
- if (paramList->Parameters[i].Type == STATE) {
- _mesa_fetch_state(ctx, paramList->Parameters[i].StateIndexes,
- paramList->Parameters[i].Values);
- }
- }
+ if (t1 == t2)
+ return GL_TRUE;
+ if (t1 == GL_FRAGMENT_PROGRAM_ARB && t2 == GL_FRAGMENT_PROGRAM_NV)
+ return GL_TRUE;
+ if (t1 == GL_FRAGMENT_PROGRAM_NV && t2 == GL_FRAGMENT_PROGRAM_ARB)
+ return GL_TRUE;
+ return GL_FALSE;
}
void GLAPIENTRY
_mesa_BindProgram(GLenum target, GLuint id)
{
- struct program *prog;
+ struct gl_program *curProg, *newProg;
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END(ctx);
FLUSH_VERTICES(ctx, _NEW_PROGRAM);
- if ((target == GL_VERTEX_PROGRAM_NV
- && ctx->Extensions.NV_vertex_program) ||
- (target == GL_VERTEX_PROGRAM_ARB
- && ctx->Extensions.ARB_vertex_program)) {
- /*** Vertex program binding ***/
- struct vertex_program *curProg = ctx->VertexProgram.Current;
- if (curProg->Base.Id == id) {
- /* binding same program - no change */
- return;
- }
- if (curProg->Base.Id != 0) {
- /* decrement refcount on previously bound vertex program */
- curProg->Base.RefCount--;
- /* and delete if refcount goes below one */
- if (curProg->Base.RefCount <= 0) {
- /* the program ID was already removed from the hash table */
- ctx->Driver.DeleteProgram(ctx, &(curProg->Base));
- }
- }
+ /* Error-check target and get curProg */
+ if ((target == GL_VERTEX_PROGRAM_ARB) && /* == GL_VERTEX_PROGRAM_NV */
+ (ctx->Extensions.NV_vertex_program ||
+ ctx->Extensions.ARB_vertex_program)) {
+ curProg = &ctx->VertexProgram.Current->Base;
}
else if ((target == GL_FRAGMENT_PROGRAM_NV
&& ctx->Extensions.NV_fragment_program) ||
(target == GL_FRAGMENT_PROGRAM_ARB
&& ctx->Extensions.ARB_fragment_program)) {
- /*** Fragment program binding ***/
- struct fragment_program *curProg = ctx->FragmentProgram.Current;
- if (curProg->Base.Id == id) {
- /* binding same program - no change */
- return;
- }
- if (curProg->Base.Id != 0) {
- /* decrement refcount on previously bound fragment program */
- curProg->Base.RefCount--;
- /* and delete if refcount goes below one */
- if (curProg->Base.RefCount <= 0) {
- /* the program ID was already removed from the hash table */
- ctx->Driver.DeleteProgram(ctx, &(curProg->Base));
- }
- }
+ curProg = &ctx->FragmentProgram.Current->Base;
}
else {
_mesa_error(ctx, GL_INVALID_ENUM, "glBindProgramNV/ARB(target)");
return;
}
- /* NOTE: binding to a non-existant program is not an error.
+ /*
+ * Get pointer to new program to bind.
+ * NOTE: binding to a non-existant program is not an error.
* That's supposed to be caught in glBegin.
*/
if (id == 0) {
- /* Bind default program */
- prog = NULL;
- if (target == GL_VERTEX_PROGRAM_NV || target == GL_VERTEX_PROGRAM_ARB)
- prog = ctx->Shared->DefaultVertexProgram;
+ /* Bind a default program */
+ newProg = NULL;
+ if (target == GL_VERTEX_PROGRAM_ARB) /* == GL_VERTEX_PROGRAM_NV */
+ newProg = ctx->Shared->DefaultVertexProgram;
else
- prog = ctx->Shared->DefaultFragmentProgram;
+ newProg = ctx->Shared->DefaultFragmentProgram;
}
else {
- /* Bind user program */
- prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, id);
- if (!prog || prog == &_mesa_DummyProgram) {
+ /* Bind a user program */
+ newProg = _mesa_lookup_program(ctx, id);
+ if (!newProg || newProg == &_mesa_DummyProgram) {
/* allocate a new program now */
- prog = ctx->Driver.NewProgram(ctx, target, id);
- if (!prog) {
+ newProg = ctx->Driver.NewProgram(ctx, target, id);
+ if (!newProg) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindProgramNV/ARB");
return;
}
- _mesa_HashInsert(ctx->Shared->Programs, id, prog);
+ _mesa_HashInsert(ctx->Shared->Programs, id, newProg);
}
- else if (prog->Target != target) {
+ else if (!compatible_program_targets(newProg->Target, target)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"glBindProgramNV/ARB(target mismatch)");
return;
}
}
- /* bind now */
- if (target == GL_VERTEX_PROGRAM_NV || target == GL_VERTEX_PROGRAM_ARB) {
- ctx->VertexProgram.Current = (struct vertex_program *) prog;
+ /** All error checking is complete now **/
+
+ if (curProg->Id == id) {
+ /* binding same program - no change */
+ return;
}
- else if (target == GL_FRAGMENT_PROGRAM_NV || target == GL_FRAGMENT_PROGRAM_ARB) {
- ctx->FragmentProgram.Current = (struct fragment_program *) prog;
+
+ /* unbind/delete oldProg */
+ if (curProg->Id != 0) {
+ /* decrement refcount on previously bound fragment program */
+ curProg->RefCount--;
+ /* and delete if refcount goes below one */
+ if (curProg->RefCount <= 0) {
+ /* the program ID was already removed from the hash table */
+ ctx->Driver.DeleteProgram(ctx, curProg);
+ }
}
+ /* bind newProg */
+ if (target == GL_VERTEX_PROGRAM_ARB) { /* == GL_VERTEX_PROGRAM_NV */
+ ctx->VertexProgram.Current = (struct gl_vertex_program *) newProg;
+ }
+ else if (target == GL_FRAGMENT_PROGRAM_NV ||
+ target == GL_FRAGMENT_PROGRAM_ARB) {
+ ctx->FragmentProgram.Current = (struct gl_fragment_program *) newProg;
+ }
+ newProg->RefCount++;
+
/* Never null pointers */
ASSERT(ctx->VertexProgram.Current);
ASSERT(ctx->FragmentProgram.Current);
- if (prog)
- prog->RefCount++;
-
if (ctx->Driver.BindProgram)
- ctx->Driver.BindProgram(ctx, target, prog);
+ ctx->Driver.BindProgram(ctx, target, newProg);
}
for (i = 0; i < n; i++) {
if (ids[i] != 0) {
- struct program *prog = (struct program *)
- _mesa_HashLookup(ctx->Shared->Programs, ids[i]);
+ struct gl_program *prog = _mesa_lookup_program(ctx, ids[i]);
if (prog == &_mesa_DummyProgram) {
_mesa_HashRemove(ctx->Shared->Programs, ids[i]);
}
else if (prog) {
/* Unbind program if necessary */
- if (prog->Target == GL_VERTEX_PROGRAM_NV ||
+ if (prog->Target == GL_VERTEX_PROGRAM_ARB || /* == GL_VERTEX_PROGRAM_NV */
prog->Target == GL_VERTEX_STATE_PROGRAM_NV) {
if (ctx->VertexProgram.Current &&
ctx->VertexProgram.Current->Base.Id == ids[i]) {
}
-/**
- * Determine if id names a vertex or fragment program.
- * \note Not compiled into display lists.
- * \note Called from both glIsProgramNV and glIsProgramARB.
- * \param id is the program identifier
- * \return GL_TRUE if id is a program, else GL_FALSE.
- */
-GLboolean GLAPIENTRY
-_mesa_IsProgram(GLuint id)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
-
- if (id == 0)
- return GL_FALSE;
-
- if (_mesa_HashLookup(ctx->Shared->Programs, id))
- return GL_TRUE;
- else
- return GL_FALSE;
-}
-
-
-
/**********************************************************************/
/* GL_MESA_program_debug extension */
/**********************************************************************/
reg[len] = 0;
switch (target) {
- case GL_VERTEX_PROGRAM_NV:
+ case GL_VERTEX_PROGRAM_ARB: /* == GL_VERTEX_PROGRAM_NV */
if (!ctx->Extensions.ARB_vertex_program &&
!ctx->Extensions.NV_vertex_program) {
_mesa_error(ctx, GL_INVALID_ENUM,
if (reg[0] == 'R') {
/* Temp register */
GLint i = _mesa_atoi(reg + 1);
- if (i >= (GLint)ctx->Const.MaxVertexProgramTemps) {
+ if (i >= (GLint)ctx->Const.VertexProgram.MaxTemps) {
_mesa_error(ctx, GL_INVALID_VALUE,
"glGetProgramRegisterfvMESA(registerName)");
return;
}
- COPY_4V(v, ctx->VertexProgram.Temporaries[i]);
+#if 0 /* FIX ME */
+ ctx->Driver.GetVertexProgramRegister(ctx, PROGRAM_TEMPORARY, i, v);
+#endif
}
else if (reg[0] == 'v' && reg[1] == '[') {
/* Vertex Input attribute */
GLuint i;
- for (i = 0; i < ctx->Const.MaxVertexProgramAttribs; i++) {
+ for (i = 0; i < ctx->Const.VertexProgram.MaxAttribs; i++) {
const char *name = _mesa_nv_vertex_input_register_name(i);
char number[10];
- sprintf(number, "%d", i);
+ _mesa_sprintf(number, "%d", i);
if (_mesa_strncmp(reg + 2, name, 4) == 0 ||
_mesa_strncmp(reg + 2, number, _mesa_strlen(number)) == 0) {
- COPY_4V(v, ctx->VertexProgram.Inputs[i]);
+#if 0 /* FIX ME */
+ ctx->Driver.GetVertexProgramRegister(ctx, PROGRAM_INPUT,
+ i, v);
+#endif
return;
}
}
if (reg[0] == 'R') {
/* Temp register */
GLint i = _mesa_atoi(reg + 1);
- if (i >= (GLint)ctx->Const.MaxFragmentProgramTemps) {
+ if (i >= (GLint)ctx->Const.FragmentProgram.MaxTemps) {
_mesa_error(ctx, GL_INVALID_VALUE,
"glGetProgramRegisterfvMESA(registerName)");
return;
}
- COPY_4V(v, ctx->FragmentProgram.Machine.Temporaries[i]);
+ ctx->Driver.GetFragmentProgramRegister(ctx, PROGRAM_TEMPORARY,
+ i, v);
}
else if (reg[0] == 'f' && reg[1] == '[') {
/* Fragment input attribute */
GLuint i;
- for (i = 0; i < ctx->Const.MaxFragmentProgramAttribs; i++) {
+ for (i = 0; i < ctx->Const.FragmentProgram.MaxAttribs; i++) {
const char *name = _mesa_nv_fragment_input_register_name(i);
if (_mesa_strncmp(reg + 2, name, 4) == 0) {
- COPY_4V(v, ctx->FragmentProgram.Machine.Inputs[i]);
+ ctx->Driver.GetFragmentProgramRegister(ctx,
+ PROGRAM_INPUT, i, v);
return;
}
}
}
else if (_mesa_strcmp(reg, "o[COLR]") == 0) {
/* Fragment output color */
- COPY_4V(v, ctx->FragmentProgram.Machine.Outputs[FRAG_OUTPUT_COLR]);
+ ctx->Driver.GetFragmentProgramRegister(ctx, PROGRAM_OUTPUT,
+ FRAG_RESULT_COLR, v);
}
else if (_mesa_strcmp(reg, "o[COLH]") == 0) {
/* Fragment output color */
- COPY_4V(v, ctx->FragmentProgram.Machine.Outputs[FRAG_OUTPUT_COLH]);
+ ctx->Driver.GetFragmentProgramRegister(ctx, PROGRAM_OUTPUT,
+ FRAG_RESULT_COLH, v);
}
else if (_mesa_strcmp(reg, "o[DEPR]") == 0) {
/* Fragment output depth */
- COPY_4V(v, ctx->FragmentProgram.Machine.Outputs[FRAG_OUTPUT_DEPR]);
+ ctx->Driver.GetFragmentProgramRegister(ctx, PROGRAM_OUTPUT,
+ FRAG_RESULT_DEPR, v);
}
else {
/* try user-defined identifiers */
const GLfloat *value = _mesa_lookup_parameter_value(
- ctx->FragmentProgram.Current->Parameters, -1, reg);
+ ctx->FragmentProgram.Current->Base.Parameters, -1, reg);
if (value) {
COPY_4V(v, value);
}
"glGetProgramRegisterfvMESA(target)");
return;
}
-
}