summaryrefslogtreecommitdiff
path: root/src/mesa/main/nvprogram.c
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>2003-01-14 04:55:45 +0000
committerBrian Paul <brian.paul@tungstengraphics.com>2003-01-14 04:55:45 +0000
commit610d59981a9f43fefe29b34ef19c184d28e2bef5 (patch)
tree6bac42c2fd25b19ed35260538c6d945de8d699d8 /src/mesa/main/nvprogram.c
parentcf01d97dc3e23af067dd9633a2bfa61a6a794ce6 (diff)
First batch of code for GL_NV_fragment_program.
Re-org of some GL_NV_vertex_program code. Replace MAX_TEXTURE_UNITS with MAX_TEXTURE_COORD_UNITS and MAX_TEXTURE_IMAGE_UNITS.
Diffstat (limited to 'src/mesa/main/nvprogram.c')
-rw-r--r--src/mesa/main/nvprogram.c1182
1 files changed, 1182 insertions, 0 deletions
diff --git a/src/mesa/main/nvprogram.c b/src/mesa/main/nvprogram.c
new file mode 100644
index 0000000000..87a1a17241
--- /dev/null
+++ b/src/mesa/main/nvprogram.c
@@ -0,0 +1,1182 @@
+/* $Id: nvprogram.c,v 1.1 2003/01/14 04:55:46 brianp Exp $ */
+
+/*
+ * Mesa 3-D graphics library
+ * Version: 5.1
+ *
+ * Copyright (C) 1999-2003 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"),
+ * 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.
+ */
+
+/**
+ * \file nvprogram.c
+ * \brief NVIDIA vertex/fragment program state management functions.
+ * \author Brian Paul
+ */
+
+
+#include "glheader.h"
+#include "context.h"
+#include "hash.h"
+#include "imports.h"
+#include "macros.h"
+#include "mtypes.h"
+#include "nvfragparse.h"
+#include "nvfragprog.h"
+#include "nvvertexec.h"
+#include "nvvertparse.h"
+#include "nvvertprog.h"
+#include "nvprogram.h"
+
+
+
+/**
+ * Set the vertex/fragment program error state (position and error string).
+ * This is generally called from within the parsers.
+ */
+void
+_mesa_set_program_error(GLcontext *ctx, GLint pos, const char *string)
+{
+ ctx->Program.ErrorPos = pos;
+ _mesa_free((void *) ctx->Program.ErrorString);
+ if (!string)
+ string = "";
+ ctx->Program.ErrorString = _mesa_strdup(string);
+}
+
+
+/**
+ * Delete a program and remove it from the hash table, ignoring the
+ * reference count.
+ * \note Called from the GL API dispatcher.
+ */
+void
+_mesa_delete_program(GLcontext *ctx, GLuint id)
+{
+ struct program *prog = (struct program *)
+ _mesa_HashLookup(ctx->Shared->Programs, id);
+
+ if (prog) {
+ if (prog->String)
+ 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)
+ FREE(vprog->Instructions);
+ }
+ else if (prog->Target == GL_FRAGMENT_PROGRAM_NV) {
+ struct fragment_program *fprog = (struct fragment_program *) prog;
+ if (fprog->Instructions)
+ FREE(fprog->Instructions);
+ }
+ _mesa_HashRemove(ctx->Shared->Programs, id);
+ FREE(prog);
+ }
+}
+
+
+/**
+ * Bind a program (make it current)
+ * \note Called from the GL API dispatcher.
+ */
+void
+_mesa_BindProgramNV(GLenum target, GLuint id)
+{
+ struct program *prog;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (target == GL_VERTEX_PROGRAM_NV) {
+ if (ctx->VertexProgram.Current &&
+ ctx->VertexProgram.Current->Base.Id == id)
+ return;
+ /* decrement refcount on previously bound vertex program */
+ if (ctx->VertexProgram.Current) {
+ ctx->VertexProgram.Current->Base.RefCount--;
+ /* and delete if refcount goes below one */
+ if (ctx->VertexProgram.Current->Base.RefCount <= 0)
+ _mesa_delete_program(ctx, ctx->VertexProgram.Current->Base.Id);
+ }
+ }
+ else if (target == GL_FRAGMENT_PROGRAM_NV) {
+ if (ctx->FragmentProgram.Current &&
+ ctx->FragmentProgram.Current->Base.Id == id)
+ return;
+ /* decrement refcount on previously bound fragment program */
+ if (ctx->FragmentProgram.Current) {
+ ctx->FragmentProgram.Current->Base.RefCount--;
+ /* and delete if refcount goes below one */
+ if (ctx->FragmentProgram.Current->Base.RefCount <= 0)
+ _mesa_delete_program(ctx, ctx->FragmentProgram.Current->Base.Id);
+ }
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glBindProgramNV");
+ return;
+ }
+
+ /* NOTE: binding to a non-existant program is not an error.
+ * That's supposed to be caught in glBegin.
+ */
+ prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, id);
+
+ if (!prog && id > 0){
+ /* allocate new program */
+ if (target == GL_VERTEX_PROGRAM_NV) {
+ struct vertex_program *vprog = CALLOC_STRUCT(vertex_program);
+ if (!vprog) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindProgramNV");
+ return;
+ }
+ prog = &(vprog->Base);
+ }
+ else if (target == GL_FRAGMENT_PROGRAM_NV) {
+ struct fragment_program *fprog = CALLOC_STRUCT(fragment_program);
+ if (!fprog) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindProgramNV");
+ return;
+ }
+ prog = &(fprog->Base);
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glBindProgramNV(target)");
+ return;
+ }
+ prog->Id = id;
+ prog->Target = target;
+ prog->Resident = GL_TRUE;
+ prog->RefCount = 1;
+ _mesa_HashInsert(ctx->Shared->Programs, id, prog);
+ }
+
+ /* bind now */
+ if (target == GL_VERTEX_PROGRAM_NV) {
+ ctx->VertexProgram.Current = (struct vertex_program *) prog;
+ }
+ else if (target == GL_FRAGMENT_PROGRAM_NV) {
+ ctx->FragmentProgram.Current = (struct fragment_program *) prog;
+ }
+
+ if (prog)
+ prog->RefCount++;
+}
+
+
+/**
+ * Delete a list of programs.
+ * \note Not compiled into display lists.
+ * \note Called from the GL API dispatcher.
+ */
+void
+_mesa_DeleteProgramsNV(GLsizei n, const GLuint *ids)
+{
+ GLint i;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (n < 0) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glDeleteProgramsNV" );
+ return;
+ }
+
+ for (i = 0; i < n; i++) {
+ if (ids[i] != 0) {
+ struct program *prog = (struct program *)
+ _mesa_HashLookup(ctx->Shared->Programs, ids[i]);
+ if (prog) {
+ if (prog->Target == GL_VERTEX_PROGRAM_NV ||
+ prog->Target == GL_VERTEX_STATE_PROGRAM_NV) {
+ if (ctx->VertexProgram.Current &&
+ ctx->VertexProgram.Current->Base.Id == ids[i]) {
+ /* unbind this currently bound program */
+ _mesa_BindProgramNV(prog->Target, 0);
+ }
+ }
+ else if (prog->Target == GL_FRAGMENT_PROGRAM_NV) {
+ if (ctx->FragmentProgram.Current &&
+ ctx->FragmentProgram.Current->Base.Id == ids[i]) {
+ /* unbind this currently bound program */
+ _mesa_BindProgramNV(prog->Target, 0);
+ }
+ }
+ else {
+ _mesa_problem(ctx, "bad target in glDeleteProgramsNV");
+ return;
+ }
+ prog->RefCount--;
+ if (prog->RefCount <= 0) {
+ _mesa_delete_program(ctx, ids[i]);
+ }
+ }
+ }
+ }
+}
+
+
+/**
+ * Execute a vertex state program.
+ * \note Called from the GL API dispatcher.
+ */
+void
+_mesa_ExecuteProgramNV(GLenum target, GLuint id, const GLfloat *params)
+{
+ struct vertex_program *vprog;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (target != GL_VERTEX_STATE_PROGRAM_NV) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glExecuteProgramNV");
+ return;
+ }
+
+ vprog = (struct vertex_program *)
+ _mesa_HashLookup(ctx->Shared->Programs, id);
+
+ if (!vprog || vprog->Base.Target != GL_VERTEX_STATE_PROGRAM_NV) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glExecuteProgramNV");
+ return;
+ }
+
+ _mesa_init_vp_registers(ctx);
+ _mesa_init_tracked_matrices(ctx);
+ COPY_4V(ctx->VertexProgram.Machine.Registers[VP_INPUT_REG_START], params);
+ _mesa_exec_vertex_program(ctx, vprog);
+}
+
+
+/**
+ * Generate a list of new program identifiers.
+ * \note Not compiled into display lists.
+ * \note Called from the GL API dispatcher.
+ */
+void
+_mesa_GenProgramsNV(GLsizei n, GLuint *ids)
+{
+ GLuint first;
+ GLuint i;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (n < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glGenProgramsNV");
+ return;
+ }
+
+ if (!ids)
+ return;
+
+ first = _mesa_HashFindFreeKeyBlock(ctx->Shared->Programs, n);
+
+ for (i = 0; i < (GLuint) n; i++) {
+ const int bytes = MAX2(sizeof(struct vertex_program),
+ sizeof(struct fragment_program));
+ struct program *prog = (struct program *) CALLOC(bytes);
+ if (!prog) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGenProgramsNV");
+ return;
+ }
+ prog->RefCount = 1;
+ prog->Id = first + i;
+ _mesa_HashInsert(ctx->Shared->Programs, first + i, prog);
+ }
+
+ /* Return the program names */
+ for (i = 0; i < (GLuint) n; i++) {
+ ids[i] = first + i;
+ }
+}
+
+
+/**
+ * Determine if a set of programs is resident in hardware.
+ * \note Not compiled into display lists.
+ * \note Called from the GL API dispatcher.
+ */
+GLboolean _mesa_AreProgramsResidentNV(GLsizei n, const GLuint *ids,
+ GLboolean *residences)
+{
+ GLint i;
+ GLboolean retVal = GL_TRUE;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
+
+ if (n < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glAreProgramsResidentNV(n)");
+ return GL_FALSE;
+ }
+
+ for (i = 0; i < n; i++) {
+ struct program *prog;
+
+ if (ids[i] == 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glAreProgramsResidentNV(id=0)");
+ return GL_FALSE;
+ }
+
+ prog = (struct program *)
+ _mesa_HashLookup(ctx->Shared->Programs, ids[i]);
+ if (!prog) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glAreProgramsResidentNV(id)");
+ return GL_FALSE;
+ }
+
+ if (!prog->Resident) {
+ retVal = GL_FALSE;
+ break;
+ }
+ }
+
+ /* only write to residences if returning false! */
+ if (retVal == GL_FALSE) {
+ for (i = 0; i < n; i++) {
+ const struct program *prog = (const struct program *)
+ _mesa_HashLookup(ctx->Shared->Programs, ids[i]);
+ residences[i] = prog->Resident;
+ }
+ }
+
+ return retVal;
+}
+
+
+/**
+ * Request that a set of programs be resident in hardware.
+ * \note Called from the GL API dispatcher.
+ */
+void
+_mesa_RequestResidentProgramsNV(GLsizei n, const GLuint *ids)
+{
+ GLint i;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (n < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glRequestResidentProgramsNV(n)");
+ return;
+ }
+
+ /* just error checking for now */
+ for (i = 0; i < n; i++) {
+ struct program *prog;
+
+ if (ids[i] == 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glRequestResidentProgramsNV(id)");
+ return;
+ }
+
+ prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, ids[i]);
+
+ if (!prog) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glRequestResidentProgramsNV(id)");
+ return;
+ }
+
+ prog->Resident = GL_TRUE;
+ }
+}
+
+
+/**
+ * Get a program parameter register.
+ * \note Not compiled into display lists.
+ * \note Called from the GL API dispatcher.
+ */
+void
+_mesa_GetProgramParameterfvNV(GLenum target, GLuint index,
+ GLenum pname, GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (target == GL_VERTEX_PROGRAM_NV) {
+ if (pname == GL_PROGRAM_PARAMETER_NV) {
+ if (index < MAX_NV_VERTEX_PROGRAM_PARAMS) {
+ index += VP_PROG_REG_START;
+ COPY_4V(params, ctx->VertexProgram.Machine.Registers[index]);
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glGetProgramParameterfvNV(index)");
+ return;
+ }
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramParameterfvNV(pname)");
+ return;
+ }
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramParameterfvNV(target)");
+ return;
+ }
+}
+
+
+/**
+ * Get a program parameter register.
+ * \note Not compiled into display lists.
+ * \note Called from the GL API dispatcher.
+ */
+void
+_mesa_GetProgramParameterdvNV(GLenum target, GLuint index,
+ GLenum pname, GLdouble *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (target == GL_VERTEX_PROGRAM_NV) {
+ if (pname == GL_PROGRAM_PARAMETER_NV) {
+ if (index < MAX_NV_VERTEX_PROGRAM_PARAMS) {
+ index += VP_PROG_REG_START;
+ COPY_4V(params, ctx->VertexProgram.Machine.Registers[index]);
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glGetProgramParameterdvNV(index)");
+ return;
+ }
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramParameterdvNV(pname)");
+ return;
+ }
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramParameterdvNV(target)");
+ return;
+ }
+}
+
+
+/**
+ * Get a program attribute.
+ * \note Not compiled into display lists.
+ * \note Called from the GL API dispatcher.
+ */
+void
+_mesa_GetProgramivNV(GLuint id, GLenum pname, GLint *params)
+{
+ struct program *prog;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, id);
+ if (!prog) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glGetProgramivNV");
+ return;
+ }
+
+ switch (pname) {
+ case GL_PROGRAM_TARGET_NV:
+ *params = prog->Target;
+ return;
+ case GL_PROGRAM_LENGTH_NV:
+ *params = prog->String ? _mesa_strlen((char *) prog->String) : 0;
+ return;
+ case GL_PROGRAM_RESIDENT_NV:
+ *params = prog->Resident;
+ return;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramivNV(pname)");
+ return;
+ }
+}
+
+
+/**
+ * Get the program source code.
+ * \note Not compiled into display lists.
+ * \note Called from the GL API dispatcher.
+ */
+void
+_mesa_GetProgramStringNV(GLuint id, GLenum pname, GLubyte *program)
+{
+ struct program *prog;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (pname != GL_PROGRAM_STRING_NV) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramivNV(pname)");
+ return;
+ }
+
+ prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, id);
+ if (!prog) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glGetProgramivNV");
+ return;
+ }
+
+ if (prog->String) {
+ MEMCPY(program, prog->String, _mesa_strlen((char *) prog->String));
+ }
+ else {
+ program[0] = 0;
+ }
+}
+
+
+/**
+ * Get matrix tracking information.
+ * \note Not compiled into display lists.
+ * \note Called from the GL API dispatcher.
+ */
+void
+_mesa_GetTrackMatrixivNV(GLenum target, GLuint address,
+ GLenum pname, GLint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (target == GL_VERTEX_PROGRAM_NV) {
+ GLuint i;
+
+ if ((address & 0x3) || address >= MAX_NV_VERTEX_PROGRAM_PARAMS) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glGetTrackMatrixivNV(address)");
+ return;
+ }
+
+ i = address / 4;
+
+ switch (pname) {
+ case GL_TRACK_MATRIX_NV:
+ params[0] = (GLint) ctx->VertexProgram.TrackMatrix[i];
+ return;
+ case GL_TRACK_MATRIX_TRANSFORM_NV:
+ params[0] = (GLint) ctx->VertexProgram.TrackMatrixTransform[i];
+ return;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetTrackMatrixivNV");
+ return;
+ }
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetTrackMatrixivNV");
+ return;
+ }
+}
+
+
+/**
+ * Get a vertex (or vertex array) attribute.
+ * \note Not compiled into display lists.
+ * \note Called from the GL API dispatcher.
+ */
+void
+_mesa_GetVertexAttribdvNV(GLuint index, GLenum pname, GLdouble *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (index == 0 || index >= VP_NUM_INPUT_REGS) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribdvNV(index)");
+ return;
+ }
+
+ switch (pname) {
+ case GL_ATTRIB_ARRAY_SIZE_NV:
+ params[0] = ctx->Array.VertexAttrib[index].Size;
+ break;
+ case GL_ATTRIB_ARRAY_STRIDE_NV:
+ params[0] = ctx->Array.VertexAttrib[index].Stride;
+ break;
+ case GL_ATTRIB_ARRAY_TYPE_NV:
+ params[0] = ctx->Array.VertexAttrib[index].Type;
+ break;
+ case GL_CURRENT_ATTRIB_NV:
+ COPY_4V(params, ctx->Current.Attrib[index]);
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribdvNV");
+ return;
+ }
+}
+
+/**
+ * Get a vertex (or vertex array) attribute.
+ * \note Not compiled into display lists.
+ * \note Called from the GL API dispatcher.
+ */
+void
+_mesa_GetVertexAttribfvNV(GLuint index, GLenum pname, GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (index == 0 || index >= VP_NUM_INPUT_REGS) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribdvNV(index)");
+ return;
+ }
+
+ switch (pname) {
+ case GL_ATTRIB_ARRAY_SIZE_NV:
+ params[0] = (GLfloat) ctx->Array.VertexAttrib[index].Size;
+ break;
+ case GL_ATTRIB_ARRAY_STRIDE_NV:
+ params[0] = (GLfloat) ctx->Array.VertexAttrib[index].Stride;
+ break;
+ case GL_ATTRIB_ARRAY_TYPE_NV:
+ params[0] = (GLfloat) ctx->Array.VertexAttrib[index].Type;
+ break;
+ case GL_CURRENT_ATTRIB_NV:
+ COPY_4V(params, ctx->Current.Attrib[index]);
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribdvNV");
+ return;
+ }
+}
+
+/**
+ * Get a vertex (or vertex array) attribute.
+ * \note Not compiled into display lists.
+ * \note Called from the GL API dispatcher.
+ */
+void
+_mesa_GetVertexAttribivNV(GLuint index, GLenum pname, GLint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (index == 0 || index >= VP_NUM_INPUT_REGS) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribdvNV(index)");
+ return;
+ }
+
+ switch (pname) {
+ case GL_ATTRIB_ARRAY_SIZE_NV:
+ params[0] = ctx->Array.VertexAttrib[index].Size;
+ break;
+ case GL_ATTRIB_ARRAY_STRIDE_NV:
+ params[0] = ctx->Array.VertexAttrib[index].Stride;
+ break;
+ case GL_ATTRIB_ARRAY_TYPE_NV:
+ params[0] = ctx->Array.VertexAttrib[index].Type;
+ break;
+ case GL_CURRENT_ATTRIB_NV:
+ COPY_4V_CAST(params, ctx->Current.Attrib[index], GLint);
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribdvNV");
+ return;
+ }
+}
+
+
+/**
+ * Get a vertex array attribute pointer.
+ * \note Not compiled into display lists.
+ * \note Called from the GL API dispatcher.
+ */
+void
+_mesa_GetVertexAttribPointervNV(GLuint index, GLenum pname, GLvoid **pointer)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (index >= MAX_NV_VERTEX_PROGRAM_INPUTS) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerNV(index)");
+ return;
+ }
+
+ if (pname != GL_ATTRIB_ARRAY_POINTER_NV) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerNV(pname)");
+ return;
+ }
+
+ *pointer = ctx->Array.VertexAttrib[index].Ptr;;
+}
+
+
+/**
+ * Determine if id names a program.
+ * \note Not compiled into display lists.
+ * \note Called from the GL API dispatcher.
+ * \param id is the program identifier
+ * \return GL_TRUE if id is a program, else GL_FALSE.
+ */
+GLboolean _mesa_IsProgramNV(GLuint id)
+{
+ struct program *prog;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
+
+ if (id == 0)
+ return GL_FALSE;
+
+ prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, id);
+ if (prog && prog->Target)
+ return GL_TRUE;
+ else
+ return GL_FALSE;
+}
+
+
+/**
+ * Load a program.
+ * \note Called from the GL API dispatcher.
+ */
+void
+_mesa_LoadProgramNV(GLenum target, GLuint id, GLsizei len,
+ const GLubyte *program)
+{
+ struct program *prog;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (id == 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glLoadProgramNV(id)");
+ return;
+ }
+
+ prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, id);
+
+ if (prog && prog->Target != 0 && prog->Target != target) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glLoadProgramNV(target)");
+ return;
+ }
+
+ /* Reset error pos and string */
+ _mesa_set_program_error(ctx, -1, NULL);
+
+ if (target == GL_VERTEX_PROGRAM_NV ||
+ target == GL_VERTEX_STATE_PROGRAM_NV) {
+ struct vertex_program *vprog = (struct vertex_program *) prog;
+ if (!vprog) {
+ vprog = CALLOC_STRUCT(vertex_program);
+ if (!vprog) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glLoadProgramNV");
+ return;
+ }
+ vprog->Base.RefCount = 1;
+ vprog->Base.Resident = GL_TRUE;
+ _mesa_HashInsert(ctx->Shared->Programs, id, vprog);
+ }
+ _mesa_parse_nv_vertex_program(ctx, target, program, len, vprog);
+ }
+ else if (target == GL_FRAGMENT_PROGRAM_NV) {
+ struct fragment_program *fprog = (struct fragment_program *) prog;
+ if (!fprog) {
+ fprog = CALLOC_STRUCT(fragment_program);
+ if (!fprog) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glLoadProgramNV");
+ return;
+ }
+ fprog->Base.RefCount = 1;
+ fprog->Base.Resident = GL_TRUE;
+ _mesa_HashInsert(ctx->Shared->Programs, id, fprog);
+ }
+ _mesa_parse_nv_fragment_program(ctx, target, program, len, fprog);
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM, "LoadProgramNV(target)");
+ }
+}
+
+
+
+/**
+ * Set a program parameter register.
+ * \note Called from the GL API dispatcher.
+ */
+void
+_mesa_ProgramParameter4dNV(GLenum target, GLuint index,
+ GLdouble x, GLdouble y, GLdouble z, GLdouble w)
+{
+ _mesa_ProgramParameter4fNV(target, index, x, y, z, w);
+}
+
+
+/**
+ * Set a program parameter register.
+ * \note Called from the GL API dispatcher.
+ */
+void
+_mesa_ProgramParameter4dvNV(GLenum target, GLuint index,
+ const GLdouble *params)
+{
+ _mesa_ProgramParameter4fNV(target, index,
+ params[0], params[1], params[2], params[3]);
+}
+
+
+/**
+ * Set a program parameter register.
+ * \note Called from the GL API dispatcher.
+ */
+void
+_mesa_ProgramParameter4fNV(GLenum target, GLuint index,
+ GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (target == GL_VERTEX_PROGRAM_NV) {
+ if (index < MAX_NV_VERTEX_PROGRAM_PARAMS) {
+ index += VP_PROG_REG_START;
+ ASSIGN_4V(ctx->VertexProgram.Machine.Registers[index], x, y, z, w);
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glProgramParameterrNV(index)");
+ return;
+ }
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glProgramParameterrNV");
+ return;
+ }
+}
+
+
+/**
+ * Set a program parameter register.
+ * \note Called from the GL API dispatcher.
+ */
+void
+_mesa_ProgramParameter4fvNV(GLenum target, GLuint index,
+ const GLfloat *params)
+{
+ _mesa_ProgramParameter4fNV(target, index,
+ params[0], params[1], params[2], params[3]);
+}
+
+
+
+/**
+ * Set a sequence of program parameter registers.
+ * \note Called from the GL API dispatcher.
+ */
+void
+_mesa_ProgramParameters4dvNV(GLenum target, GLuint index,
+ GLuint num, const GLdouble *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (target == GL_VERTEX_PROGRAM_NV) {
+ GLuint i;
+ if (index + num > MAX_NV_VERTEX_PROGRAM_PARAMS) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glProgramParameters4dvNV");
+ return;
+ }
+ index += VP_PROG_REG_START;
+ for (i = 0; i < num; i++) {
+ COPY_4V_CAST(ctx->VertexProgram.Machine.Registers[index + i],
+ params, GLfloat);
+ params += 4;
+ };
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glProgramParameters4dvNV");
+ return;
+ }
+}
+
+
+/**
+ * Set a sequence of program parameter registers.
+ * \note Called from the GL API dispatcher.
+ */
+void
+_mesa_ProgramParameters4fvNV(GLenum target, GLuint index,
+ GLuint num, const GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (target == GL_VERTEX_PROGRAM_NV) {
+ GLuint i;
+ if (index + num > MAX_NV_VERTEX_PROGRAM_PARAMS) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glProgramParameters4fvNV");
+ return;
+ }
+ index += VP_PROG_REG_START;
+ for (i = 0; i < num; i++) {
+ COPY_4V(ctx->VertexProgram.Machine.Registers[index + i], params);
+ params += 4;
+ };
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glProgramParameters4fvNV");
+ return;
+ }
+}
+
+
+
+/**
+ * Setup tracking of matrices into program parameter registers.
+ * \note Called from the GL API dispatcher.
+ */
+void
+_mesa_TrackMatrixNV(GLenum target, GLuint address,
+ GLenum matrix, GLenum transform)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (target == GL_VERTEX_PROGRAM_NV) {
+ if (address & 0x3) {
+ /* addr must be multiple of four */
+ _mesa_error(ctx, GL_INVALID_VALUE, "glTrackMatrixNV(address)");
+ return;
+ }
+
+ switch (matrix) {
+ case GL_NONE:
+ case GL_MODELVIEW:
+ case GL_PROJECTION:
+ case GL_TEXTURE:
+ case GL_COLOR:
+ case GL_MODELVIEW_PROJECTION_NV:
+ case GL_MATRIX0_NV:
+ case GL_MATRIX1_NV:
+ case GL_MATRIX2_NV:
+ case GL_MATRIX3_NV:
+ case GL_MATRIX4_NV:
+ case GL_MATRIX5_NV:
+ case GL_MATRIX6_NV:
+ case GL_MATRIX7_NV:
+ /* OK, fallthrough */
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glTrackMatrixNV(matrix)");
+ return;
+ }
+
+ switch (transform) {
+ case GL_IDENTITY_NV:
+ case GL_INVERSE_NV:
+ case GL_TRANSPOSE_NV:
+ case GL_INVERSE_TRANSPOSE_NV:
+ /* OK, fallthrough */
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glTrackMatrixNV(transform)");
+ return;
+ }
+
+ ctx->VertexProgram.TrackMatrix[address / 4] = matrix;
+ ctx->VertexProgram.TrackMatrixTransform[address / 4] = transform;
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glTrackMatrixNV(target)");
+ return;
+ }
+}
+
+
+static GLfloat *
+lookup_program_parameter(struct fragment_program *fprog,
+ GLsizei len, const GLubyte *name)
+{
+ return NULL;
+}
+
+
+void
+glProgramNamedParameter4fNV(GLuint id, GLsizei len, const GLubyte *name,
+ GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ struct program *prog;
+ GLfloat *p;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, id);
+ if (!prog || prog->Target != GL_FRAGMENT_PROGRAM_NV) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glProgramNamedParameterNV");
+ return;
+ }
+
+ if (len <= 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glProgramNamedParameterNV");
+ return;
+ }
+
+ p = lookup_program_parameter((struct fragment_program *) prog, len, name);
+ if (!p) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glProgramNamedParameterNV");
+ return;
+ }
+
+ p[0] = x;
+ p[1] = y;
+ p[2] = z;
+ p[3] = w;
+}
+
+
+void
+glProgramNamedParameter4fvNV(GLuint id, GLsizei len, const GLubyte *name,
+ const float v[])
+{
+ glProgramNamedParameter4fNV(id, len, name, v[0], v[1], v[2], v[3]);
+}
+
+
+void
+glProgramNamedParameter4dNV(GLuint id, GLsizei len, const GLubyte *name,
+ GLdouble x, GLdouble y, GLdouble z, GLdouble w)
+{
+ glProgramNamedParameter4fNV(id, len, name, x, y, z, w);
+}
+
+
+void
+glProgramNamedParameter4dvNV(GLuint id, GLsizei len, const GLubyte *name,
+ const double v[])
+{
+ glProgramNamedParameter4fNV(id, len, name, v[0], v[1], v[2], v[3]);
+}
+
+
+void
+glGetProgramNamedParameterfvNV(GLuint id, GLsizei len, const GLubyte *name,
+ GLfloat *params)
+{
+ struct program *prog;
+ const GLfloat *p;
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, id);
+ if (!prog || prog->Target != GL_FRAGMENT_PROGRAM_NV) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glGetProgramNamedParameterNV");
+ return;
+ }
+
+ if (len <= 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramNamedParameterNV");
+ return;
+ }
+
+ p = lookup_program_parameter((struct fragment_program *) prog, len, name);
+ if (!p) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramNamedParameterNV");
+ return;
+ }
+
+ params[0] = p[0];
+ params[1] = p[1];
+ params[2] = p[2];
+ params[3] = p[3];
+}
+
+
+void
+glGetProgramNamedParameterdvNV(GLuint id, GLsizei len, const GLubyte *name,
+ GLdouble *params)
+{
+ GLfloat floatParams[4];
+ glGetProgramNamedParameterfvNV(id, len, name, floatParams);
+ COPY_4V(params, floatParams);
+}
+
+
+void
+glProgramLocalParameter4fARB(GLenum target, GLuint index,
+ GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (target == GL_FRAGMENT_PROGRAM_NV) {
+ struct fragment_program *fprog = ctx->FragmentProgram.Current;
+ if (!fprog) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glProgramLocalParameterARB");
+ return;
+ }
+ if (index >= MAX_NV_FRAGMENT_PROGRAM_PARAMS) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameterARB");
+ return;
+ }
+ fprog->LocalParams[index][0] = x;
+ fprog->LocalParams[index][1] = y;
+ fprog->LocalParams[index][2] = z;
+ fprog->LocalParams[index][3] = w;
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glProgramLocalParameterARB");
+ return;
+ }
+}
+
+
+void
+glProgramLocalParameter4fvARB(GLenum target, GLuint index,
+ const GLfloat *params)
+{
+ glProgramLocalParameter4fARB(target, index, params[0], params[1],
+ params[2], params[3]);
+}
+
+
+void
+glProgramLocalParameter4dARB(GLenum target, GLuint index,
+ GLdouble x, GLdouble y, GLdouble z, GLdouble w)
+{
+ glProgramLocalParameter4fARB(target, index, x, y, z, w);
+}
+
+
+void
+glProgramLocalParameter4dvARB(GLenum target, GLuint index,
+ const GLdouble *params)
+{
+ glProgramLocalParameter4fARB(target, index, params[0], params[1],
+ params[2], params[3]);
+}
+
+
+void
+glGetProgramLocalParameterfvARB(GLenum target, GLuint index, GLfloat *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (target == GL_FRAGMENT_PROGRAM_NV) {
+ struct fragment_program *fprog = ctx->FragmentProgram.Current;
+ if (!fprog) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramLocalParameterARB");
+ return;
+ }
+ if (index >= MAX_NV_FRAGMENT_PROGRAM_PARAMS) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramLocalParameterARB");
+ return;
+ }
+ params[0] = fprog->LocalParams[index][0];
+ params[1] = fprog->LocalParams[index][1];
+ params[2] = fprog->LocalParams[index][2];
+ params[3] = fprog->LocalParams[index][3];
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramLocalParameterARB");
+ return;
+ }
+}
+
+
+void
+glGetProgramLocalParameterdvARB(GLenum target, GLuint index, GLdouble *params)
+{
+ GLfloat floatParams[4];
+ glGetProgramLocalParameterfvARB(target, index, floatParams);
+ COPY_4V(params, floatParams);
+}