In Direct3D, when we specify the input to vertex shader using D3D11_INPUT_ELEMENT_DESC and when we call IASetVertexBuffers, we have to specify 'the input slot(s)'. What exactly are these input slots, and what is the OpenGL equivalent? These input slots don't seem to be the same thing as 'locations' specified via layout(location = K) in GLSL and the first argument to glVertexAttribPointer.
A vertex input comes from an array of values stored in a buffer. The SemanticIndex identifies where that input goes in the shader. The InputSlot defines which buffer provides the data for that attribute. Buffers aren't bound to semantic indices; they're bound to input slots.
See, D3D has two arrays of things: an array of semantics (which match semantics defined in the shader) and an array of input slots. Each semantic you use has an INPUT_DESC structure for it, which specifies (among other things) the mapping from a semantic to the input slots that feeds it. Vertex buffers are bound to input slots. Any inputs which use those slots will pull their data from the same buffer. A particular input can have an offset for how its vertex data is accessed; this allows for interleaving vertex data.
OpenGL 4.3/ARB_separate_attrib_format provides similar concepts with glVertexAttribFormat and glVertexAttribBinding. The former specifies what attribute location the vertex data goes to. The latter specifies which buffer binding index will feed that attribute. Buffers are bound to buffer binding indices with glBindVertexBuffer(s).
When using the older glBindBuffer(GL_ARRAY_BUFFER)/glVertexAttribPointer APIs, the buffer binding index and the attribute location index are effectively the same. But this is a poor API and if you don't have to support older GL versions, I'd advise you to use the newer stuff.
Related
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.
I have two Entities to be rendered with the same VkPipeline, the problem is that they have different VkDescriptorSetLayout (The first entities uses Dynamic Uniform Buffers, the second only standard Uniform Buffers);
How to pass both VkDescriptorSetLayout to the graphics pipeline, and then bind the correct one during the creation of the command buffer?
With a single VkDescriptorSetLayout, I just pass it to VkPipelineLayoutCreateInfo.pSetLayouts, and then call VkCmdBindDescriptorSet with that VkPipelineLayout.
But with two VkDescriptorSetLayouts, how to correctly bind them to the VkPipelineLayout, and then how to choose the one I want during command buffering?
The first entities uses Dynamic Uniform Buffers, the second only standard Uniform Buffers
Then they do not have the same VkPipeline. Whether a uniform buffer is dynamic or not is part of the pipeline, since it is part of the layout of that pipeline's descriptor sets.
Pipelines can have multiple descriptor sets, but each set represents a collection of resources, all of which the pipeline can access at the same time. In your shader code, this is what layout(set = #, binding = #) means; a uniform block in the shader refers to a specific descriptor within a specific set index. And it will always refer to that specific descriptor within that specific set index. And whether that specific descriptor within that specific set is dynamic or not is a part of the VkDescritorSetLayout used by the VkPipelineLayout used to construct the VkPipeline object.
A specific descriptor set within a pipeline layout cannot have two sets. That doesn't make sense.
To do what you want requires creating two separate, distinct VkPipeline objects. One can be a derivative of the other, so as to hint to the implementation that changes between them won't be particularly big. But you need two pipelines.
But really, it'd probably be better to just have one pipeline that always using dynamic uniform buffers.
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.
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] (...)
For the other buffers there are functions like:
glVertexArrayVertexAttribOffsetEXT(
this->handle, // vao handle
vbo.getHandle(), // vbo handle
index, // specifies the index of the generic vertex attribute to be modified.
size, // number of components per generic vertex attribute
vbo.getType(), // specifies the data type of each component in the array
normalized, // specifies whether fixed-point data values should be normalized
stride, // specifies the byte offset between consecutive generic vertex attributes
offset // specifies a pointer to the first component of the first generic vertex attribute in the array
);
But i can't find a method for binding the element buffer to the vao. Or am i missing something there?
PS: does it make sense to add vertex-array-object and direct-state-access tags?
You can't find it because it's not part of it.
The DSA extension was designed prior to VAO being part of GL3.0, and modified later on to interact with it. I would not be surprised it's a hole in the specification. Feel free to contact the specification owner (listed at the top of the extension)