Get vertex buffer bound to vertex array - c++

I'm writing an OpenGL application, and the problem I'm facing now is as follows:
Let us say I have a Vertex Array, with its ID. However, I do not have its bound vertex buffer ID at hand. I am in need of the Buffer ID for an operation. SO, is it possible to retrieve current buffer binding from vertex array?
Note that I have come across glGetIntegerv, however I think it only retrieves current buffer binding, NOT vertex array binding

Let us say I have a Vertex Array, with its ID. However, I do not have its bound vertex buffer ID at hand.
In a well-behaved application, that should not be possible. It was your application that put that buffer into that VAO. Therefore, you should already know what buffer is attached to it. It's a question you don't need to ask.
However, if you have no other choice but to ask OpenGL a question that you ought to know the answer to, you must first bind the VAO to the context. If you're not using the separate attribute format API, then you can use glGetVertexAttribiv with GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, specifying the attribute index you're interested in querying. If you want to use the separate attribute format API, you need to use glGetIntegeri_v with GL_VERTEX_BINDING_BUFFER, specifying the binding index to query.
If you're using DSA (which requires using the separate attribute format), then you can use glGetVertexArrayIndexediv, with GL_VERTEX_BINDING_BUFFER and the appropriate binding index.

Related

Open GL Shader Storage Buffer Objects to replace Vertex Attributes

I basically got the same question as the guy who asked here:
Dynamically sized arrays in OpenGL ES vertex shader; used for blend shapes/morph targets .
Especially his last unanswered question bothers me too.
So I also want to use an arbitrary number of blendshapes for each mesh I'm processing. At the moment I'm using a fixed number and treat the shapes as vertex attribute. The advantage here is that I always have the relevant data for the current vertex availiable. Now, if I want to use an arbitrary number of shapes, I figured I'd use SSBOs since their clue is exactly what I want: Dynamically sized data.
However SSBOs are, as far as I understand it, static and for each processed vertex in the shader I have the blendshape data for the whole mesh availiable. That means I would have to introduce some kind of counter and try to pick the correct data piece out of my SSBO for each vertex.
Is this understanding correct?
I'm really not sure whether this is the optimal solution, maybe you can give me some hints.
Yes your understanding is correct.
You can use gl_VertexID or just pass some 'vertex number' as attribute to know what data to load in your SSBO for the particular vertex you're processing.

Custom Vertex Attributes GLSL

I want to make a couple of vec4 vertex attributes in my shaders. I've done quite a bit of googling, but I can't seem to find consistent information for specifically what I want to do.
My goal here is to move skinning to the GPU, so I need a list of bones and weights per vertex, hence why I want to use vertex attributes. I have 2 arrays of floats that represent this data. Basically this:
weightsBuffer = new float[vSize*4];
indexesBuffer = new int[vSize*4];
The part that I can't consistently find is how to upload these and use them in the shader. To be clear, I don't want to upload all the position, normal and texture coordinate data, I'm already using display lists and have decided to keep using them for a few reasons that aren't relevant. How can I create the buffers and bind them properly so I can use them?
Thanks.
Binding your bone weights and indices is no different of a process than binding your position data. Assuming the data is generated properly in your buffers, you use glBindAttribLocation to bind the attribute index in your vertex stream to your shader variable, and glVertexAttribPointer to define your vertex array (and don't forget glEnableVertexAttribArray).
The exact code may vary, depending on whether you're using VAOs and VBOs (or just client buffers). If you want a more specific answer, you should provide your code and shader.

Buffer binding using OpenGL and GLSL

I wonder if there is a way to bind a Texture Buffer (TBO) Object directly on a certain range of data like it's possible to do using Uniform Buffer object (UBO -> glBindBufferRange).
Actually, I store my matrices within a TBO and to recover each of them within my vertex shader I need to send an 'GLUint' offset as Uniform variable. So, I wonder if it's possible to make a "kind of glBindBufferRange" applied on my TBO. This way I won't need to send each time for each vertex shader the offset where my matrices are stored.
I did a lot of researches on the subject and I did not found any concluding information (just glTexBufferRange but this function does not seem to be used for this purpose...).
Thanks a lot in advance for your help!

How to pass to a vertex-shader dynamic data that should apply for all vertices?

I've a simple program that draws an object, and I want its position to ultimately respond to user-input.
I've tried to create a buffer object with just 2 GLfloats to hold the position and pass it in location 1, and learned that it only affects the first vertex (which actually makes sense, now that I think about it).
I've thought about using uniforms but it doesn't seem to be the correct way either (I've read that changing them can be slow).
What's the approach to this in OpenGL 3/4?
You can achieve this either by using uniforms or vertex attributes. I would suggest using a vertex attribute in the event that you ever want the vertices to have a unique value per-vertex. You can achieve that simply by supplying a vertex pointer instead of a constant vertex attribute.
The following command applies a constant value to every instance of a vertex attribute:
glVertexAttrib{1|2|3|4}f[v] (...)

What exactly does glEnableVertexAttribArray do?

I was reading: Dissecting Display, Chapter 1. Hello, Triangle!.
What exactly does glEnableVertexAttribArray do? I think it enables the use of a given VBO, but I am not sure.
I thought that is what glEnableClientState(GL_VERTEX_ARRAY) did.
I have been reading: Dissecting Display, Chapter 1. Hello, Triangle!.
Then please read the next page; I explain exactly what it does there ;)
If I may quote myself:
We assigned the attribute index of the position attribute to 0 in the vertex shader, so the call to glEnableVertexAttribArray(0) enables the attribute index for the position attribute. [...] If the attribute is not enabled, it will not be used during rendering.
It's similar to a vertex array but stores additional extra values for each point rather than it's coordinates. You might want to store a temperature, density, signal strength at each point in a modelling app for example, or perhaps a damage value for a game
There is another way to specify data for a vertex attribute, the non-array way:
khronos: glVertexAttrib
In this way, we specify data for only one vertex, this data will be replicated for all vertices.
To use non-array data, call glDisableVertexAttribArray.
To use array data, call glEnableVertexAttribArray.