PDA

View Full Version : ARB_vertex_program string building syntax



Glossifah
09-24-2002, 08:47 AM
Is this a valid string to hand to glProgramStringARB:




char * vtx_prog_str = "!!ARBvp1.0\
ATTRIB pos = vertex.position;\
TEMP result, temp;\
PARAM mat[4] = { state.matrix.modelview };\
DP4 result.w, pos, mat[3];\
DP4 result.x, pos, mat[0];\
DP4 result.y, pos, mat[1];\
DP4 result.z, pos, mat[2];\
RCP temp.w, result.w;\
MUL result, result, temp.w;\
END";


I finally had some time to play with the extension, but the string assembly is giving me ails. Any suggestions would be much appreciated.

Asgard
09-24-2002, 08:54 AM
The last MUL is incorrect. You can't read from an output register.

Asgard
09-24-2002, 08:57 AM
Also you can query PROGRAM_ERROR_POSITION_ARB and PROGRAM_ERROR_STRING_ARB to get a hint of what's wrong...doesn't work all the time though, because sometimes you get very cryptic error messages...but then again, that might evolve in future driver releases.

PH
09-24-2002, 08:58 AM
The program is fine, the problem is you haven't written any vertex position. Either do that, or use invariant programs.

secnuop
09-24-2002, 09:07 AM
Actually, the biggest problem is that 'result' is a keyword, so you'll need another name for your TEMP register. I think this example was added to the ARB_vertex_program issues list before 'result' was made a keyword and the example wasn't ever updated.

The last MUL is fine, since both operands are TEMP registers.

[edit - spelling]


[This message has been edited by secnuop (edited 09-24-2002).]

Asgard
09-24-2002, 10:59 AM
The last MUL is fine, since both operands are TEMP registers.

True, my mistake. Didn't see he was declaring it with a TEMP statement before _and_ I didn't even notice that he didn't write to result.position or something....ah well, guess I should drink a cup of coffee to wake up before posting http://www.opengl.org/discussion_boards/ubb/smile.gif



[This message has been edited by Asgard (edited 09-24-2002).]

pbrown
09-24-2002, 08:29 PM
The problem with this code is that "result" is not a valid variable name. "result" is also used for program result bindings (i.e., "result.position" holds the transformed vertex position, "result.color" the final color, and so on). We reserved it to simplify parsing.

As Asgard points out earlier, query VERTEX_PROGRAM_ERROR_POSITION_ARB and VERTEX_PROGRAM_ERROR_STRING_ARB.

The cryptic error string on the NVIDIA implementation should say "reserved keyword", and the error position should point to the beginning of "result".


My little programs usually do something like:

query errorPos;
if (errorPos != -1) {
int i;
query errorString;
printf("Error: %s\n", errorString);
for (i = 0; i < errorPos; i++) {
putch(string[i]);
}
printf("***");
for (; i < stringLen; i++) {
putch(string[i]);
}
printf("\n");
}

Pat (ARB_vertex_program spec editor)

[This message has been edited by pbrown (edited 09-24-2002).]

Glossifah
09-25-2002, 05:57 AM
My apologies for not posting earlier. I actually got this working (at least without errors in the syntax) yesterday afternoon.




char * vtx_prog_str = "!!ARBvp1.0\
ATTRIB iPos = vertex.position;\
PARAM mat[4] = {state.matrix.modelview};\
OUTPUT oPos = result.position;\
DP4 oPos.x, mat[0], iPos;\
DP4 oPos.y, mat[1], iPos;\
DP4 oPos.z, mat[2], iPos;\
DP4 oPos.w, mat[3], iPos;\
END";


Thanks for the assistance!

NitroGL
09-25-2002, 07:31 AM
You can also write directly to the results.

eg:



char * vtx_prog_str = "!!ARBvp1.0\
PARAM mat[4] = {state.matrix.modelview};\
DP4 result.x, mat[0], vertex.position;\
DP4 result.y, mat[1], vertex.position;\
DP4 result.z, mat[2], vertex.position;\
DP4 result.w, mat[3], vertex.position;\
END";


Now weather or not there are preformance issues with doing that, I don't know. But it does work (at least it does on my 9700).

Asgard
09-25-2002, 08:02 AM
Originally posted by NitroGL:
Now weather or not there are preformance issues with doing that, I don't know.

There are no performance issues, except that maybe the parsing of the string will take a couple of microseconds longer ;-)
The OUTPUT statement simply aliases user-defined names with result registers and has no impact on the program execution on the GPU.

Also your program won't compile as it has to be result.position.x (or some other result register) and not just result.x.

[edit - typos]


[This message has been edited by Asgard (edited 09-25-2002).]

Glossifah
09-25-2002, 08:41 AM
Asgard,

I'm getting an invalid constant error on a line where I'm trying to grab and store the half vector, like so:



PARAM halfDir = {state.light[0].half};\


Disregard. Found it. Corrected the error. Shouldn't have used {} brackets. Woops. http://www.opengl.org/discussion_boards/ubb/smile.gif

TIA

[This message has been edited by Glossifah (edited 09-25-2002).]

NitroGL
09-25-2002, 09:42 AM
Originally posted by Asgard:
Also your program won't compile as it has to be result.position.x (or some other result register) and not just result.x.

Oops, didn't catch that. http://www.opengl.org/discussion_boards/ubb/smile.gif
Guess that's what I get for only sleeping 6 hours...

davepermen
09-25-2002, 10:45 AM
6 hours? _THAT_LONG_ ?! thats not good, really!

NitroGL
09-25-2002, 11:22 AM
Haven't had my Code Red fix yet today either...