Sign in to follow this  

GLSL/Cg - How do I bind uniform variables to a vertex buffer ?

This topic is 3718 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, first of all i apologize if this question was already answered, because it is rather basic. Unfortunately i couldn't find much information on this. My questions concerns what is know in the DX world, as "flexible vertex structure". How do I bind uniform variables to values, which reside in a vertex buffer ? For GLSL I know of the GLUniform command to modify uniform variables. Unfortunately this is an immediate mode command. I am searching for something similar to GLNormalPointer or GLVertexPointer. GLUniformPointer does unfortunately not exist. In short - how do I setup something like this: struct Vertex { float vx,vy,vz; //Position float nx,ny,nz; //Normal float custom; //Custom parameter for crazy effect :) float u1, v1; //Texcoords /Bumpmap etc . . float u5,v5; }; using VertexBuffers ? How would I do this with GLSL/Cg ? Thank you a lot! Frederick

Share this post


Link to post
Share on other sites
The short version is; you don't.

Uniforms are used for per object/primative data and shouldn't be changed all that often. What you want is to bind vertex attributes, using one of the related function (glVertexAttrib for immediate mode and glVertexAttribPointer for vertex arrays).

Share this post


Link to post
Share on other sites
Thank´s phantom!

I equipped myself with the OpenGL Spec and read the Lighthouse tutorials in detail and found the missing bits.

I was not aware of the distinction between uniforms and attributes.

Uniform properties are constant per primitive, and attribute are constant per vertex.

OpenGL is a bit confusing to the beginner, one does never know when an API feature is deprecated or not =) But I am getting it. Looking forward to 3.0.

Thanks to all,
Frederick

Share this post


Link to post
Share on other sites
At the hardware level it's actually possible to pack uniform parameters into vertex buffers but high level APIs like Direct3D and OpenGL won't let you. The idea is to create a vertex buffer with one element and a stride of 0. However, in OpenGL, if you specify a stride of 0 it will automatically change it to the size of the element. In D3D it will give you an error, I believe. So to fix this, you can just make a large vertex buffer and fill it with the same constant. Or, listen to phantom and don't do this.

Share this post


Link to post
Share on other sites

This topic is 3718 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this