View Full Version : glBindAttribLocation with Cg

07-20-2009, 11:11 AM
How can I use glBindAttribLocation with Cg? The function expects uint-type value, not CGprogram

Ilian Dinev
07-20-2009, 11:15 AM
You generally specify the attrib-slot inside the shader

(this is Cg-style GLSL)

attribute vec4 inPos : ATTR0;
attribute vec3 inN : ATTR1;

07-20-2009, 02:40 PM
Wow. I didn't expect that simply putting these ATTRx would work. No I have something like this:

struct VS_INPUT
float4 position: POSITION: ATTR0;
float3 normal: NORMAL: ATTR2;
float2 texCoord0: TEXCOORD0: ATTR8;

And this works nicely for OGL and D3D :)

07-20-2009, 04:04 PM
Oh no... I thought this would work for D3D yet VS30 doesn't recognize semantic ATTR*... :( Does anyone know a way make this work without using preprocessor? I need one Cg shader that would work for VS30, PS30 and ARB/GLSL profiles

Ilian Dinev
07-20-2009, 04:19 PM
Cg could be problematic in GLSL profile, afaik. (from what I've read on this board, and the Cg->GLSL converted code I've seen cgc.exe produces)
But for DX, ARB and NVx0 profiles instead of ATTRx you'd better use the :POSITION, :NORMAL, :TEXCOORDx semantics. The downside is that you'll have to use the glVertexPointer/glNormalPointer/etc instead of glVertexAttribPointer .

Cg can be a mess with ATi cards via OpenGL; but at least it'll work nicely for those cards via DX.

07-20-2009, 05:53 PM
Yes... I thought that Cg would be a good idea for shaders but now I see it's hard to handle OGL+Cg+ATI. In my future engine I'll surely use explicitly GLSL and HLSL instead of Cg. By now I shall use glVertexPointer/glNormalPointer/etc. I've made some small test-application and so far it works with both NVidia and ATI (at least on two GPUs I've tested). Hope that when I switch from ARB to GLSL none of the new problems arrive...
Again, thanks for your contribution.