ctx->NewDriverState |= new_driver_state;
}
+static struct gl_program*
+lookup_or_create_program(GLuint id, GLenum target, const char* caller)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_program* newProg;
+
+ if (id == 0) {
+ /* Bind a default program */
+ if (target == GL_VERTEX_PROGRAM_ARB)
+ newProg = ctx->Shared->DefaultVertexProgram;
+ else
+ newProg = ctx->Shared->DefaultFragmentProgram;
+ }
+ else {
+ /* Bind a user program */
+ newProg = _mesa_lookup_program(ctx, id);
+ if (!newProg || newProg == &_mesa_DummyProgram) {
+ /* allocate a new program now */
+ newProg = ctx->Driver.NewProgram(ctx, target, id, true);
+ if (!newProg) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", caller);
+ return NULL;
+ }
+ _mesa_HashInsert(ctx->Shared->Programs, id, newProg);
+ }
+ else if (newProg->Target != target) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "%s(target mismatch)", caller);
+ return NULL;
+ }
+ }
+ return newProg;
+}
+
/**
* Bind a program (make it current)
* \note Called from the GL API dispatcher by both glBindProgramNV
* NOTE: binding to a non-existant program is not an error.
* That's supposed to be caught in glBegin.
*/
- if (id == 0) {
- /* Bind a default program */
- newProg = NULL;
- if (target == GL_VERTEX_PROGRAM_ARB)
- newProg = ctx->Shared->DefaultVertexProgram;
- else
- newProg = ctx->Shared->DefaultFragmentProgram;
- }
- else {
- /* Bind a user program */
- newProg = _mesa_lookup_program(ctx, id);
- if (!newProg || newProg == &_mesa_DummyProgram) {
- /* allocate a new program now */
- newProg = ctx->Driver.NewProgram(ctx, target, id, true);
- if (!newProg) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindProgramARB");
- return;
- }
- _mesa_HashInsert(ctx->Shared->Programs, id, newProg);
- }
- else if (newProg->Target != target) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glBindProgramARB(target mismatch)");
- return;
- }
- }
+ newProg = lookup_or_create_program(id, target, "glBindProgram");
+ if (!newProg)
+ return;
/** All error checking is complete now **/
return GL_FALSE;
}
-static GLboolean
-get_local_param_pointer(struct gl_context *ctx, const char *func,
- GLenum target, GLuint index, GLfloat **param)
+static struct gl_program*
+get_current_program(struct gl_context* ctx, GLenum target, const char* caller)
{
- struct gl_program *prog;
- GLuint maxParams;
-
if (target == GL_VERTEX_PROGRAM_ARB
&& ctx->Extensions.ARB_vertex_program) {
- prog = ctx->VertexProgram.Current;
- maxParams = ctx->Const.Program[MESA_SHADER_VERTEX].MaxLocalParams;
+ return ctx->VertexProgram.Current;
}
else if (target == GL_FRAGMENT_PROGRAM_ARB
&& ctx->Extensions.ARB_fragment_program) {
- prog = ctx->FragmentProgram.Current;
- maxParams = ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxLocalParams;
+ return ctx->FragmentProgram.Current;
}
else {
_mesa_error(ctx, GL_INVALID_ENUM,
- "%s(target)", func);
- return GL_FALSE;
+ "%s(target)", caller);
+ return NULL;
+ }
+}
+
+static GLboolean
+get_local_param_pointer(struct gl_context *ctx, const char *func,
+ struct gl_program* prog, GLenum target,
+ GLuint index, GLfloat **param)
+{
+ GLuint maxParams;
+
+ if (target == GL_VERTEX_PROGRAM_ARB) {
+ maxParams = ctx->Const.Program[MESA_SHADER_VERTEX].MaxLocalParams;
+ } else {
+ maxParams = ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxLocalParams;
}
if (index >= maxParams) {
}
}
-void GLAPIENTRY
-_mesa_ProgramStringARB(GLenum target, GLenum format, GLsizei len,
+static void
+set_program_string(struct gl_program *prog, GLenum target, GLenum format, GLsizei len,
const GLvoid *string)
{
- struct gl_program *prog;
bool failed;
GET_CURRENT_CONTEXT(ctx);
#endif /* ENABLE_SHADER_CACHE */
if (target == GL_VERTEX_PROGRAM_ARB && ctx->Extensions.ARB_vertex_program) {
- prog = ctx->VertexProgram.Current;
_mesa_parse_arb_vertex_program(ctx, target, string, len, prog);
}
else if (target == GL_FRAGMENT_PROGRAM_ARB
&& ctx->Extensions.ARB_fragment_program) {
- prog = ctx->FragmentProgram.Current;
_mesa_parse_arb_fragment_program(ctx, target, string, len, prog);
}
else {
}
}
+void GLAPIENTRY
+_mesa_ProgramStringARB(GLenum target, GLenum format, GLsizei len,
+ const GLvoid *string)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ if (target == GL_VERTEX_PROGRAM_ARB && ctx->Extensions.ARB_vertex_program) {
+ set_program_string(ctx->VertexProgram.Current, target, format, len, string);
+ }
+ else if (target == GL_FRAGMENT_PROGRAM_ARB
+ && ctx->Extensions.ARB_fragment_program) {
+ set_program_string(ctx->FragmentProgram.Current, target, format, len, string);
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glProgramStringARB(target)");
+ return;
+ }
+}
+
+void GLAPIENTRY
+_mesa_NamedProgramStringEXT(GLuint program, GLenum target, GLenum format, GLsizei len,
+ const GLvoid *string)
+{
+ struct gl_program* prog = lookup_or_create_program(program, target, "glNamedProgramStringEXT");
+
+ if (!prog) {
+ return;
+ }
+ set_program_string(prog, target, format, len, string);
+}
+
/**
* Set a program env parameter register.
{
GET_CURRENT_CONTEXT(ctx);
GLfloat *param;
+ struct gl_program* prog = get_current_program(ctx, target, "glProgramLocalParameterARB");
+ if (!prog) {
+ return;
+ }
flush_vertices_for_program_constants(ctx, target);
if (get_local_param_pointer(ctx, "glProgramLocalParameterARB",
- target, index, ¶m)) {
+ prog, target, index, ¶m)) {
+ assert(index < MAX_PROGRAM_LOCAL_PARAMS);
+ ASSIGN_4V(param, x, y, z, w);
+ }
+}
+
+void GLAPIENTRY
+_mesa_NamedProgramLocalParameter4fEXT(GLuint program, GLenum target, GLuint index,
+ GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLfloat *param;
+ struct gl_program* prog = lookup_or_create_program(program, target,
+ "glNamedProgramLocalParameter4fEXT");
+
+ if (!prog) {
+ return;
+ }
+
+ if ((target == GL_VERTEX_PROGRAM_ARB && prog == ctx->VertexProgram.Current) ||
+ (target == GL_FRAGMENT_PROGRAM_ARB && prog == ctx->FragmentProgram.Current)) {
+ flush_vertices_for_program_constants(ctx, target);
+ }
+
+ if (get_local_param_pointer(ctx, "glNamedProgramLocalParameter4fEXT",
+ prog, target, index, ¶m)) {
assert(index < MAX_PROGRAM_LOCAL_PARAMS);
ASSIGN_4V(param, x, y, z, w);
}
}
+void GLAPIENTRY
+_mesa_NamedProgramLocalParameter4fvEXT(GLuint program, GLenum target, GLuint index,
+ const GLfloat *params)
+{
+ _mesa_NamedProgramLocalParameter4fEXT(program, target, index, params[0],
+ params[1], params[2], params[3]);
+}
+
+
void GLAPIENTRY
_mesa_ProgramLocalParameters4fvEXT(GLenum target, GLuint index, GLsizei count,
const GLfloat *params)
{
GET_CURRENT_CONTEXT(ctx);
GLfloat *dest;
+ struct gl_program* prog = get_current_program(ctx, target, "glProgramLocalParameters4fv");
+ if (!prog) {
+ return;
+ }
flush_vertices_for_program_constants(ctx, target);
}
if (get_local_param_pointer(ctx, "glProgramLocalParameters4fvEXT",
- target, index, &dest)) {
+ prog, target, index, &dest)) {
GLuint maxParams = target == GL_FRAGMENT_PROGRAM_ARB ?
ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxLocalParams :
ctx->Const.Program[MESA_SHADER_VERTEX].MaxLocalParams;
}
+void GLAPIENTRY
+_mesa_NamedProgramLocalParameter4dEXT(GLuint program, GLenum target, GLuint index,
+ GLdouble x, GLdouble y,
+ GLdouble z, GLdouble w)
+{
+ _mesa_NamedProgramLocalParameter4fEXT(program, target, index, (GLfloat) x, (GLfloat) y,
+ (GLfloat) z, (GLfloat) w);
+}
+
+
void GLAPIENTRY
_mesa_ProgramLocalParameter4dvARB(GLenum target, GLuint index,
const GLdouble *params)
}
+void GLAPIENTRY
+_mesa_NamedProgramLocalParameter4dvEXT(GLuint program, GLenum target, GLuint index,
+ const GLdouble *params)
+{
+ _mesa_NamedProgramLocalParameter4fEXT(program, target, index,
+ (GLfloat) params[0], (GLfloat) params[1],
+ (GLfloat) params[2], (GLfloat) params[3]);
+}
+
+
void GLAPIENTRY
_mesa_GetProgramLocalParameterfvARB(GLenum target, GLuint index,
GLfloat *params)
{
GLfloat *param;
GET_CURRENT_CONTEXT(ctx);
+ struct gl_program* prog = get_current_program(ctx, target, "glGetProgramLocalParameterfvARB");
+ if (!prog) {
+ return;
+ }
if (get_local_param_pointer(ctx, "glProgramLocalParameters4fvEXT",
- target, index, ¶m)) {
+ prog, target, index, ¶m)) {
+ COPY_4V(params, param);
+ }
+}
+
+
+void GLAPIENTRY
+_mesa_GetNamedProgramLocalParameterfvEXT(GLuint program, GLenum target, GLuint index,
+ GLfloat *params)
+{
+ GLfloat *param;
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_program* prog = lookup_or_create_program(program, target,
+ "glGetNamedProgramLocalParameterfvEXT");
+ if (!prog) {
+ return;
+ }
+
+ if (get_local_param_pointer(ctx, "glGetNamedProgramLocalParameterfvEXT",
+ prog, target, index, ¶m)) {
COPY_4V(params, param);
}
}
{
GLfloat *param;
GET_CURRENT_CONTEXT(ctx);
+ struct gl_program* prog = get_current_program(ctx, target, "glGetProgramLocalParameterdvARB");
+ if (!prog) {
+ return;
+ }
if (get_local_param_pointer(ctx, "glProgramLocalParameters4fvEXT",
- target, index, ¶m)) {
+ prog, target, index, ¶m)) {
COPY_4V(params, param);
}
}
void GLAPIENTRY
-_mesa_GetProgramivARB(GLenum target, GLenum pname, GLint *params)
+_mesa_GetNamedProgramLocalParameterdvEXT(GLuint program, GLenum target, GLuint index,
+ GLdouble *params)
+{
+ GLfloat *param;
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_program* prog = lookup_or_create_program(program, target,
+ "glGetNamedProgramLocalParameterdvEXT");
+ if (!prog) {
+ return;
+ }
+
+ if (get_local_param_pointer(ctx, "glGetNamedProgramLocalParameterdvEXT",
+ prog, target, index, ¶m)) {
+ COPY_4V(params, param);
+ }
+}
+
+
+static void
+get_program_iv(struct gl_program *prog, GLenum target, GLenum pname,
+ GLint *params)
{
const struct gl_program_constants *limits;
- struct gl_program *prog;
+
GET_CURRENT_CONTEXT(ctx);
- if (target == GL_VERTEX_PROGRAM_ARB
- && ctx->Extensions.ARB_vertex_program) {
- prog = ctx->VertexProgram.Current;
+ if (target == GL_VERTEX_PROGRAM_ARB) {
limits = &ctx->Const.Program[MESA_SHADER_VERTEX];
}
- else if (target == GL_FRAGMENT_PROGRAM_ARB
- && ctx->Extensions.ARB_fragment_program) {
- prog = ctx->FragmentProgram.Current;
- limits = &ctx->Const.Program[MESA_SHADER_FRAGMENT];
- }
else {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramivARB(target)");
- return;
+ limits = &ctx->Const.Program[MESA_SHADER_FRAGMENT];
}
assert(prog);
}
+void GLAPIENTRY
+_mesa_GetProgramivARB(GLenum target, GLenum pname, GLint *params)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_program* prog = get_current_program(ctx, target,
+ "glGetProgramivARB");
+ if (!prog) {
+ return;
+ }
+ get_program_iv(prog, target, pname, params);
+}
+
+void GLAPIENTRY
+_mesa_GetNamedProgramivEXT(GLuint program, GLenum target, GLenum pname,
+ GLint *params)
+{
+ struct gl_program* prog;
+ if (pname == GL_PROGRAM_BINDING_ARB) {
+ return _mesa_GetProgramivARB(target, pname, params);
+ }
+ prog = lookup_or_create_program(program, target,
+ "glGetNamedProgramivEXT");
+ if (!prog) {
+ return;
+ }
+ get_program_iv(prog, target, pname, params);
+}
+
+
void GLAPIENTRY
_mesa_GetProgramStringARB(GLenum target, GLenum pname, GLvoid *string)
{
else
*dst = '\0';
}
+
+
+void GLAPIENTRY
+_mesa_GetNamedProgramStringEXT(GLuint program, GLenum target,
+ GLenum pname, GLvoid *string) {
+ char *dst = (char *) string;
+ GET_CURRENT_CONTEXT(ctx);
+ struct gl_program* prog = lookup_or_create_program(program, target,
+ "glGetNamedProgramStringEXT");
+ if (!prog)
+ return;
+
+ if (pname != GL_PROGRAM_STRING_ARB) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetNamedProgramStringEXT(pname)");
+ return;
+ }
+
+ if (prog->String)
+ memcpy(dst, prog->String, strlen((char *) prog->String));
+ else
+ *dst = '\0';
+}
OPCODE_COMPRESSED_MULTITEX_SUB_IMAGE_1D,
OPCODE_COMPRESSED_MULTITEX_SUB_IMAGE_2D,
OPCODE_COMPRESSED_MULTITEX_SUB_IMAGE_3D,
+ OPCODE_NAMED_PROGRAM_STRING,
+ OPCODE_NAMED_PROGRAM_LOCAL_PARAMETER,
/* The following three are meta instructions */
OPCODE_ERROR, /* raise compiled-in error */
case OPCODE_COMPRESSED_MULTITEX_IMAGE_3D:
free(get_pointer(&n[10]));
break;
-
+ case OPCODE_NAMED_PROGRAM_STRING:
+ free(get_pointer(&n[5]));
+ break;
case OPCODE_CONTINUE:
n = (Node *) get_pointer(&n[1]);
free(block);
}
+static void GLAPIENTRY
+save_NamedProgramStringEXT(GLuint program, GLenum target, GLenum format, GLsizei len,
+ const GLvoid * string)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+
+ n = alloc_instruction(ctx, OPCODE_NAMED_PROGRAM_STRING, 4 + POINTER_DWORDS);
+ if (n) {
+ GLubyte *programCopy = malloc(len);
+ if (!programCopy) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glNamedProgramStringEXT");
+ return;
+ }
+ memcpy(programCopy, string, len);
+ n[1].ui = program;
+ n[2].e = target;
+ n[3].e = format;
+ n[4].i = len;
+ save_pointer(&n[5], programCopy);
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_NamedProgramStringEXT(ctx->Exec, (program, target, format, len, string));
+ }
+}
+
+
+static void GLAPIENTRY
+save_NamedProgramLocalParameter4fEXT(GLuint program, GLenum target, GLuint index,
+ GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ Node *n;
+ ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+ n = alloc_instruction(ctx, OPCODE_NAMED_PROGRAM_LOCAL_PARAMETER, 7);
+ if (n) {
+ n[1].ui = program;
+ n[2].e = target;
+ n[3].ui = index;
+ n[4].f = x;
+ n[5].f = y;
+ n[6].f = z;
+ n[7].f = w;
+ }
+ if (ctx->ExecuteFlag) {
+ CALL_NamedProgramLocalParameter4fEXT(ctx->Exec, (program, target, index, x, y, z, w));
+ }
+}
+
+
+static void GLAPIENTRY
+save_NamedProgramLocalParameter4fvEXT(GLuint program, GLenum target, GLuint index,
+ const GLfloat *params)
+{
+ save_NamedProgramLocalParameter4fEXT(program, target, index, params[0],
+ params[1], params[2], params[3]);
+}
+
+
+static void GLAPIENTRY
+save_NamedProgramLocalParameter4dEXT(GLuint program, GLenum target, GLuint index,
+ GLdouble x, GLdouble y,
+ GLdouble z, GLdouble w)
+{
+ save_NamedProgramLocalParameter4fEXT(program, target, index, (GLfloat) x,
+ (GLfloat) y, (GLfloat) z, (GLfloat) w);
+}
+
+
+static void GLAPIENTRY
+save_NamedProgramLocalParameter4dvEXT(GLuint program, GLenum target, GLuint index,
+ const GLdouble *params)
+{
+ save_NamedProgramLocalParameter4fEXT(program, target, index, (GLfloat) params[0],
+ (GLfloat) params[1], (GLfloat) params[2],
+ (GLfloat) params[3]);
+}
+
+
/**
* Save an error-generating command into display list.
*
n[9].i, n[10].e, n[11].i,
get_pointer(&n[12])));
break;
+ case OPCODE_NAMED_PROGRAM_STRING:
+ CALL_NamedProgramStringEXT(ctx->Exec,
+ (n[1].ui, n[2].e, n[3].e, n[4].i,
+ get_pointer(&n[5])));
+ break;
+ case OPCODE_NAMED_PROGRAM_LOCAL_PARAMETER:
+ CALL_NamedProgramLocalParameter4fEXT(ctx->Exec,
+ (n[1].ui, n[2].e, n[3].ui, n[4].f,
+ n[5].f, n[6].f, n[7].f));
+ break;
case OPCODE_CONTINUE:
n = (Node *) get_pointer(&n[1]);
SET_CompressedMultiTexSubImage1DEXT(table, save_CompressedMultiTexSubImage1DEXT);
SET_CompressedMultiTexSubImage2DEXT(table, save_CompressedMultiTexSubImage2DEXT);
SET_CompressedMultiTexSubImage3DEXT(table, save_CompressedMultiTexSubImage3DEXT);
+ SET_NamedProgramStringEXT(table, save_NamedProgramStringEXT);
+ SET_NamedProgramLocalParameter4dEXT(table, save_NamedProgramLocalParameter4dEXT);
+ SET_NamedProgramLocalParameter4dvEXT(table, save_NamedProgramLocalParameter4dvEXT);
+ SET_NamedProgramLocalParameter4fEXT(table, save_NamedProgramLocalParameter4fEXT);
+ SET_NamedProgramLocalParameter4fvEXT(table, save_NamedProgramLocalParameter4fvEXT);
}
{ "glDisableClientStateIndexedEXT", 12, -1 },
{ "glGetPointerIndexedvEXT", 12, -1 },
/* GL_EXT_direct_state_access - ARB_vertex_program */
- //{ "glNamedProgramStringEXT", 10, -1 },
- //{ "glNamedProgramLocalParameter4dEXT", 10, -1 },
- //{ "glNamedProgramLocalParameter4dvEXT", 10, -1 },
- //{ "glNamedProgramLocalParameter4fEXT", 10, -1 },
- //{ "glNamedProgramLocalParameter4fvEXT", 10, -1 },
- //{ "glGetNamedProgramLocalParameter4dvEXT", 10, -1 },
- //{ "glGetNamedProgramLocalParameter4fvEXT", 10, -1 },
- //{ "glGetNamedProgramivEXT", 10, -1 },
- //{ "glGetNamedProgramStringEXT", 10, -1 },
+ { "glNamedProgramStringEXT", 10, -1 },
+ { "glNamedProgramLocalParameter4dEXT", 10, -1 },
+ { "glNamedProgramLocalParameter4dvEXT", 10, -1 },
+ { "glNamedProgramLocalParameter4fEXT", 10, -1 },
+ { "glNamedProgramLocalParameter4fvEXT", 10, -1 },
+ { "glGetNamedProgramLocalParameterdvEXT", 10, -1 },
+ { "glGetNamedProgramLocalParameterfvEXT", 10, -1 },
+ { "glGetNamedProgramivEXT", 10, -1 },
+ { "glGetNamedProgramStringEXT", 10, -1 },
/* GL_EXT_direct_state_access - GL 1.3 */
{ "glCompressedTextureImage1DEXT", 13, -1 },
{ "glCompressedTextureImage2DEXT", 13, -1 },
{ "glGetNamedBufferPointervEXT", 15, -1 },
{ "glGetNamedBufferSubDataEXT", 15, -1 },
/* GL_EXT_direct_state_access - GL 2.0 */
- //{ "glProgramUniform1iEXT", 20, -1 },
+ // { "glProgramUniform1iEXT", 20, -1 },
//{ "glProgramUniform1ivEXT", 20, -1 },
//{ "glProgramUniform1fEXT", 20, -1 },
//{ "glProgramUniform1fvEXT", 20, -1 },