I find it quite confusing when searching the Internet for how to do things.=
There are too many out-of-date tutorials. The OpenGL documentation is very=
terse, not explaining much. For example, glGenBuffers describes how to cre=
ate buffers. But not a word what a buffer is, and what the idea is with it.
I could buy a book, but I am too lazy for that. It is like Internet, do you=
know if it is up-to-date?
Anyway, the following is how I understand vertex and fragment shaders shoul=
d be used if you want to get good performance. Any comments are welcome:
1. Uniform variables are used for data that you update once per frame or ob=
ject. Typical examples are transformation matrixes, typically updated with =
glUniformMatrix4fv().
2. Attrib variables are updated automatically once per vertex or pixel.
3. Attrib variables for the fragment shader are normally (always?) updated =
from output from the vertext shader.
4. Data to be sent to the vertex shader attrib variables can be done using =
glGenBuffers()+glBindBuffer()+glBufferData(). This will immediately transfe=
r the data to the graphics card.
5. The content layout of buffer data in step 4 can be defined with glVertex=
AttribPointer().
6. Step 4 and 5 can all be done in the initalization phase, for many buffer=
s.
7. Drawing is finally done, every frame, by updating transformation matrice=
s, calling glBindBuffer(), and then glDrawArrays().
8. Now and then, buffer content has to be updated if there are changes in t=
he drawn "world".
Is this a strategy that would work? I think I got it working somewhat, but =
there are bugs and side effects so I am not sure.
Is this the "state of the art" on how to do things with OpenGL?
I see that there are glGenVertexArrays(), but, again, no information what t=
hey do and why.
|
|
0
|
|
|
|
Reply
|
Lars
|
3/20/2011 5:58:49 PM |
|
On Mar 20, 6:58=A0pm, Lars <lars.pen...@gmail.com> wrote:
>
> Anyway, the following is how I understand vertex
> and fragment shaders should be used if you want to
> get good performance. Any comments are welcome:
>
There's many reasons to use shaders but I don't
think "performance" is one of them...
> 1. Uniform variables are used for data that you update once per frame or =
object. Typical examples are transformation matrixes, typically updated wit=
h glUniformMatrix4fv().
> 2. Attrib variables are updated automatically once per vertex or pixel.
> 3. Attrib variables for the fragment shader are normally (always?) update=
d from output from the vertext shader.
> 4. Data to be sent to the vertex shader attrib variables
> can be done using glGenBuffers()+glBindBuffer()+glBufferData().
OTOH vertex buffers are necessary to get top
performance. Also use indexed triangles with
16-bit indices. Batches of vertices with
about 512 triangles in each is best (bigger
buffers aren't faster and they tie up the
graphics card and bring down the multi-
tasking performance of the entire machine)
> Is this a strategy that would work?
Yes.
> Is this the "state of the art" on how to do things with OpenGL?
>
Yes.
> I see that there are glGenVertexArrays(), but, again, no
> information what they do and why.
I don't know what you're looking at but every extension
is documented/discussed on opengl.org
http://www.opengl.org/registry/specs/ARB/vertex_array_object.txt
"This extension introduces named vertex array objects
which encapsulate vertex array state on the client
side."
http://www.opengl.org/registry/specs/ARB/vertex_buffer_object.txt
"This extension defines an interface that allows
various types of data (especially vertex array data)
to be cached in high-performance graphics memory
on the server"
Short answer: Use glGenBuffers()
|
|
0
|
|
|
|
Reply
|
fungus
|
3/20/2011 6:20:08 PM
|
|
On Sun, 20 Mar 2011 10:58:49 -0700, Lars wrote:
> I find it quite confusing when searching the Internet for how to do
> things. There are too many out-of-date tutorials. The OpenGL
> documentation is very terse, not explaining much. For example,
> glGenBuffers describes how to create buffers. But not a word what a
> buffer is, and what the idea is with it.
It's a block of memory, with the caveat that it may be video memory,
meaning that you can't just obtain a pointer to it and assume that
updating the memory will automatically affect subsequent operations.
Specifically, you either have to copy data to/from the buffer with e.g.
glBufferSubData(), or you have to map the buffer with glMapBuffer(), with
the caveat that you have to unmap the buffer before allowing OpenGL to use
its contents.
Any operation which uses "bulk" data can obtain that data either from
application memory or from a buffer. Using a buffer means that the data
doesn't have to be copied from system memory to video memory each time.
> Anyway, the following is how I understand vertex and fragment shaders
> should be used if you want to get good performance.
You seem to have a reasonable understanding of the situation.
> 7. Drawing is finally done, every frame, by updating transformation
> matrices, calling glBindBuffer(), and then glDrawArrays().
Recent versions of OpenGL have many variations on glDrawArrays(), allowing
for more to be done with a single call.
> 8. Now and then, buffer content has to be updated if there are changes
> in the drawn "world".
Right. But by moving computation into shaders, it's possible to minimise
the amount of data which is sent to the video card. E.g. if you're using
skeletal animation, you can send the "joint" transformations to the card
and have the vertex shader calculate the transformed positions, rather
than having the application animate the mesh and sending the entire
transformed mesh to the card.
> Is this the "state of the art" on how to do things with OpenGL?
That's the general idea. The "art" is in pushing as much as possible onto
the GPU, so that the application doesn't need to send vast amounts of data
over the bus each frame.
> I see that there are glGenVertexArrays(), but, again, no information
> what they do and why.
Roughly, a vertex array object (VAO) encapsulates a set of vertex
attribute arrays, so that you can switch between sets of attribute arrays
with a single glBindVertexArray() call, rather than having to use multiple
glVertexAttribPointer() calls.
|
|
0
|
|
|
|
Reply
|
Nobody
|
3/21/2011 1:49:54 AM
|
|
|
2 Replies
244 Views
(page loaded in 0.048 seconds)
|