I see, I think I know what you mean by you might not be able to use it eheh, I've tried use it and I can't return the binary code, the reason I think is because the use of the Cg, I tried some examples here using GLSL directily and it works, the problem is that I think the Shader code generator for OpenGL on dolphin generate Cg code instead of GLSL, I'm right?
If there is some way to generate GLSL I think it will be pretty easy to get the binary from it..
Here is some code of what I'm trying to do to grab the binary length needed for glGetProgramBinary, the -10 is just to see if the glGetProgramiv changed it, but it always remain -10, maybe I'm just doing it wrong?
Code:
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);
About the ARB output, I've tried some naive benchmarks here with the emulator and it indeed helps the perfomance caching it, if there is no possibility to grab the binary code, I will try caching the ARB instead.
What does glGetError say?
Also, try that before the call to glProgramString:
Code:
glProgramParameteri(id, PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);
glGetError returns me GL_INVALID_VALUE.
I've already tried the glProgramParameteri(id, PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE) call, but it doesn't affect the error, but I've to add an GL_ to the PROGRAM_BINARY_RETRIEVABLE_HINT to my compiler find it, don't think this changes anything though.
The glGetProgram documentation says this about the error:
Quote:GL_INVALID_VALUE is generated if program is not a value generated by OpenGL.
I'm getting the program ID with vs.glprogid.
Actually, I'm getting the same error from the glProgramParameteri call too
Code:
glGenProgramsARB(1, id);
This should be &id...
Moving that topic to the Development forum, it's not really a support thread.
Ah, sorry about that, actually this code snippet I pasted here was a sample code of the actual just to make things more clear, so i misspelled it, in the actual code I have the & before the id on the glGenProgramsARB.
Let me ask something, the generated code from GenerateVertexShaderCode(components, API_OPENGL); is Cg or GLSL code?
I'm asking it because I thought it was Cg, but when running this code:
Code:
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
GLint sourceLength = strlen(pstrprogram);
glShaderSourceARB(vertexShader, 1, &pstrprogram, &sourceLength);
glCompileShaderARB(vertexShader);
GLint compiled = -10;
glGetObjectParameterivARB(vertexShader, GL_COMPILE_STATUS, &compiled);
if (compiled)
printf("COMPILED: %d\n", compiled);
GLint program = glCreateProgram();
glAttachShader(program, vertexShader);
glLinkProgram(program);
It compile fines, it just fails on glLinkProgram.
The vertex shader probably has some undefined references or something like that... try to display the program info log?
There you go, the log of some shader it tried to link (at least I think it is when linking, because glGetObjectParameterivARB(vertexShader, GL_COMPILE_STATUS, &compiled); tells me it compiled fine:
Code:
compiler_log:
Vertex info
-----------
0(2) : warning C7506: OpenGL does not define the global type float4
0(2) : warning C7552: OpenGL does not allow usage of keyword 'typedef'
0(3) : warning C7552: OpenGL does not allow usage of keyword 'typedef'
0(4) : warning C7552: OpenGL does not allow usage of keyword 'typedef'
0(5) : warning C7552: OpenGL does not allow usage of keyword 'typedef'
0(6) : warning C7552: OpenGL does not allow usage of keyword 'typedef'
0(7) : warning C7552: OpenGL does not allow usage of keyword 'typedef'
0(8) : warning C7552: OpenGL does not allow usage of keyword 'typedef'
0(9) : warning C7552: OpenGL does not allow usage of keyword 'typedef'
0(10) : warning C7552: OpenGL does not allow usage of keyword 'typedef'
0(11) : warning C7552: OpenGL does not allow usage of keyword 'typedef'
0(13) : warning C7557: OpenGL does not allow Cg-style semantics
0(14) : warning C7557: OpenGL does not allow Cg-style semantics
0(15) : warning C7557: OpenGL does not allow Cg-style semantics
0(16) : warning C7506: OpenGL does not define the global type float3
0(16) : warning C7557: OpenGL does not allow Cg-style semantics
0(17) : warning C7557: OpenGL does not allow Cg-style semantics
0(19) : warning C7557: OpenGL does not allow Cg-style semantics
0(20) : warning C7557: OpenGL does not allow Cg-style semantics
0(21) : warning C7557: OpenGL does not allow Cg-style semantics
0(22) : warning C7557: OpenGL does not allow Cg-style semantics
0(23) : warning C7557: OpenGL does not allow Cg-style semantics
0(24) : warning C7557: OpenGL does not allow Cg-style semantics
0(25) : warning C7557: OpenGL does not allow Cg-style semantics
0(26) : warning C7557: OpenGL does not allow Cg-style semantics
0(27) : warning C7557: OpenGL does not allow Cg-style semantics
0(29) : warning C7506: OpenGL does not define the global type float2
0(29) : warning C7557: OpenGL does not allow Cg-style semantics
0(30) : warning C7557: OpenGL does not allow Cg-style semantics
0(28) : warning C7527: OpenGL requires main to take no parameters
0(28) : warning C7530: OpenGL requires main to return void
0(32) : warning C7502: OpenGL does not allow type suffix 'f' on constant literals
0(33) : warning C7502: OpenGL does not allow type suffix 'f' on constant literals
0(33) : warning C7502: OpenGL does not allow type suffix 'f' on constant literals
0(33) : warning C7502: OpenGL does not allow type suffix 'f' on constant literals
0(38) : warning C7502: OpenGL does not allow type suffix 'f' on constant literals
0(38) : warning C7502: OpenGL does not allow type suffix 'f' on constant literals
0(38) : warning C7502: OpenGL does not allow type suffix 'f' on constant literals
0(38) : warning C7502: OpenGL does not allow type suffix 'f' on constant literals
0(40) : warning C7502: OpenGL does not allow type suffix 'f' on constant literals
0(40) : warning C7502: OpenGL does not allow type suffix 'f' on constant literals
0(40) : warning C7502: OpenGL does not allow type suffix 'f' on constant literals
0(40) : warning C7502: OpenGL does not allow type suffix 'f' on constant literals
0(42) : warning C7502: OpenGL does not allow type suffix 'f' on constant literals
0(42) : warning C7502: OpenGL does not allow type suffix 'f' on constant literals
0(42) : warning C7502: OpenGL does not allow type suffix 'f' on constant literals
0(42) : warning C7502: OpenGL does not allow type suffix 'f' on constant literals
0(43) : warning C7502: OpenGL does not allow type suffix 'f' on constant literals
0(43) : warning C7502: OpenGL does not allow type suffix 'f' on constant literals
0(51) : warning C7502: OpenGL does not allow type suffix 'f' on constant literals
0(52) : warning C7502: OpenGL does not allow type suffix 'f' on constant literals
0(52) : warning C7502: OpenGL does not allow type suffix 'f' on constant literals
(0) : error C5145: must write to gl_Position
I can paste here the actual shader code if you want
I don't really understand what you're trying to do... Dolphin is using Cg for a reason, if we could simply compile the shaders as GLSL we would have removed that dependency a long time ago. Compiling the Cg code with glShaderSource will obviously not work.
Well, as I said in the beginning of the thread, I'm very new to OpenGL and Cg stuff, so I really just trying to understand what the OpenGL backend do with trial and error, what I understand is that the emulator generates some Cg code, that code is sent to a CgProgram, this code is converted (compiled?) to ARB, and finally a glProgramARB is created from it..
What I don't know is if this ARB code is then compiled to a binary that is used later, if so, I want to retrieve this binary and save it in disk like is done in the DirectX backend, and that is what I'm trying to do with glGetProgramBinary...
If it is not possible for some reason, then I will try cache the ARB code which will give some perfomance boost anyway, but I really want try to find some way to get the binary code of the vertex shader for cache as the lack of this feature is the only reason the emulator lags to me (did some profiling and found that every time the game lags is because some vertex shader is compiling).