Jump to content
  • Advertisement
Sign in to follow this  
Frederick

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

This topic is 3934 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!