PDA

View Full Version : sending normals and vertex data to the vertex shader using gldrawelements()



a-sylum
01-18-2015, 07:15 AM
hi there,
i am trying to write a .obj loader. the most convenient way to do this would be to setup up 2 indexing buffers for 2 different sets of vertex data but internet research has led me to believe this is not possible. my questions are is this possible? And if it is how would i go about doing this? and if not, can it be done with one gldrawelements call? if not that what would be the best way to get the result i want?
thanks alot

Alfonse Reinheart
01-18-2015, 08:21 AM
my questions are is this possible?

Broadly speaking, no.

More specifically speaking, yes, but it requires far more work than you should bother with.


And if it is how would i go about doing this?

If you can't be bothered to use mesh loading tools (https://www.opengl.org/wiki/Portal:Development_Tools#Mesh_Loaders) like the Open Asset Importer (http://assimp.sourceforge.net/) and must writer your own, and you can't be bothered to do the splitting yourself, then you could do what you're wanting by accessing your vertex and index data directly in your shader.

What I mean is that you have vertex and index data in buffer objects. You then hand those buffer objects to the shader via Buffer Textures (https://www.opengl.org/wiki/Buffer_Texture), Image Load/Store (https://www.opengl.org/wiki/Image_Load_Store), or Shader Storage Buffers (https://www.opengl.org/wiki/Shader_Storage_Buffer_Object). Your vertex shader must now use gl_VertexID (https://www.opengl.org/wiki/Vertex_Shader#Other_inputs) input to fetch indices from your index buffers, then use those indices to fetch the attributes from the vertex buffers.

Of course, you lose all automatic vertex formatting features of vertex attributes (https://www.opengl.org/wiki/Vertex_Specification#Vertex_format). So if you want to use packed vertex data, or use half-float attributes, you'll have to manually unpack it in the shader. You'll also lose the use of the post-T&L cache (https://www.opengl.org/wiki/Post_Transform_Cache) (since you must use non-indexed rendering, as far as the pipeline is concerned), though your memory fetches will at least use their own caches.

a-sylum
01-18-2015, 08:41 AM
great ill check out open asset importer, (sounds easier :))

a-sylum
01-18-2015, 11:48 AM
also one last question, can you use one indexing buffer to index into and draw from multiple vertex buffers? also, tiny question, what do i call what i describe as vertex buffers? is it vertex array objects?

Alfonse Reinheart
01-18-2015, 01:05 PM
also one last question, can you use one indexing buffer to index into and draw from multiple vertex buffers?

Yes. You shouldn't need to unless you have specific needs, but yes you can. Just bind a different buffer to GL_VERTER_ARRAY (https://www.opengl.org/wiki/Vertex_Specification#Vertex_Buffer_Object) before calling glVertexAttribPointer for the attributes that come from that buffer.

Or if you are able, use separate format specification (https://www.opengl.org/wiki/Vertex_Specification#Separate_attribute_format), which makes the format and the source buffers entirely separate.


also, tiny question, what do i call what i describe as vertex buffers? is it vertex array objects?

No. A vertex array object (https://www.opengl.org/wiki/Vertex_Specification#Vertex_Array_Object) is a container object that references buffer objects.

Buffer objects (https://www.opengl.org/wiki/Buffer Object) are called buffer objects. You could call them "vertex buffers" or "vertex buffer objects", but that suggests that they can only be used for that. Buffer objects are like pointers to memory; you can use them anywhere, for any purpose, so long as they contain data that the consuming function can work with. You can take a buffer object and use transform feedback (https://www.opengl.org/wiki/Transform Feedback) to write to it, then use the same buffer as source data for vertex attributes.

mhagain
01-18-2015, 05:28 PM
This really should become a FAQ or Wiki entry as it's something that there are enough questions about already.

Alfonse Reinheart
01-18-2015, 05:46 PM
There is a FAQ entry on this. (https://www.opengl.org/wiki/FAQ#Multi_indexed_rendering) On the Wiki. Even the Wiki's article on Vertex Specification makes this clear (https://www.opengl.org/wiki/Vertex_Specification#Theory). The problem is finding it. Because there are literally dozens of different ways to ask it, no search engine will return the right answer for them.

And that doesn't even cover the general uselessness of FAQ pages. People generally feel better about having a FAQ than users do in using it. Also, the more extensive the FAQ is, the more likely that it will have such a high signal-to-noise ratio that it's effectively impossible to find useful information. And all it takes for a FAQ to be considered useless and thus ignored by a person, is for it to fail them. Once.