View Full Version : Drawing Quads multiple times per frame
08-04-2012, 12:17 PM
Using modern OpenGL (4.2) what is the best way for me to draw a quad multiple times with different positions and textures?
I currently have a render class which, when initialized creates a program, shaders a VBO etc. Then a Render functions which creates an mvp based on input and binds the textures and uniforms and such then draws with glDrawArrays.
Is there a way to render the same set of vertices like this or do I need to create a VBO and everything else for every single object.
The reason I want to do this is I am making a 2D game and all the objects are exactly the same when it comes to vertices.
08-04-2012, 11:56 PM
you can use this one object over and over again.
the only thing that you need to change is the 'mvp' as this one positions the Quad.
set first mvp
set second mvp position
set third mvp position
08-05-2012, 12:49 AM
Thanks, I have got it to work.
Can I ask another question though. If using draw array's instanced can I pass a dynamic array of matrices to the shader or does it need to be determined at compile time? If it can how can I do so?
Thanks so much
08-05-2012, 01:03 AM
i am not shure if i got you right here , but:
you may be able to pass a array of matrixs to the shader, BUT the shader only processes one of you quads every time.
so the array won´t help.
you should always send one array of vertex and its matrix ( and color, etc ) though the rendering pipeline.
than change the matrix and send the next one ...
what you are trying to do here is somthing a geometry shader may do ...
08-05-2012, 01:10 AM
Oh well ok. I have heard that passing an array of matrix uniforms into a vertex array and then assigning each one to an instanced based on its instanceID. Can this not be done without a geometry shader
08-05-2012, 01:18 AM
yes it can be done ... the question is just, if this is the propper way for your code.
it somehow taking the long and hard road instead of taking the freeway :-)
08-05-2012, 05:42 AM
Instancing is good if it helps you avoid a large number of GL calls. If you are just rendering 100 quads with different textures, it doesn't sound like a performance win. Even 12 year old GPU can handle that.
In your case, you can make use of GL_TEXTURE_2D_ARRAY and have a flag to sample from the layer that you desire.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.