0

I have some Cg Vertex shader and want to get the compiled binary from it to cache.

The way I load the Cg vertex is using glProgramStringARB, the problem with that is that I can't retrieve any value from glGetProgramiv and glGetProgramBinary.

Here is a example code of what I'm doing:

CGprogram program = cgCreateProgram(context, CG_SOURCE, source, ...);
const char* programARB = static_cast<char*>(cgGetProgramString(program,
  CG_COMPILED_PROGRAM));
GLuint id;
glGenProgramsARB(1, id);
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, id);
glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
  static_cast<GLsizei>(strlen(programARB)), programARB);
GLint length = -10;
glGetProgramiv(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_BINARY_LENGTH, &lenght);
printf("LENGTH: %d\n", length);

I initialized length with -10 just to see if the variable would change with glGetProgramiv call, but I always get the -10 as result.

Sassa
  • 1,673
  • 2
  • 16
  • 30

1 Answers1

1

the problem with that is that I can't retrieve any value from glGetProgramiv and glGetProgramBinary.

Of course you can't. You're confusing ARB_vertex_program with GLSL programs. They're not the same thing.

glGetProgramiv takes a GLSL program object (among other things). Odds are good that OpenGL is giving you a GL_INVALID_VALUE error, since the first argument is almost certainly not a valid program object created by glCreateProgram.

You can't get a program binary for an ARB_vertex_program. You would need to compile your Cg shader to GLSL, then use the standard GLSL compile/link process, and get the binary from that.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982