Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (604)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (652)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Drawing only one quad (what to use?)  (Read 1820 times)
0 Members and 1 Guest are viewing this topic.
Offline RobinB

JGO Ninja

Medals: 44
Projects: 1
Exp: 3 years

Spacegame in progress

« Posted 2013-09-02 18:43:19 »


This question is bothering me over a long time, so im deciding to seek your advise.
Currently im creating a game where im drawing all terrain to a single texture, where i only need to draw one quad each chunk.
Even translations are done in the shader, so its really the same quad all the time.

What would be the best method to draw only one quad (multiple times a frame), that never changes.
Since its just 2 rectangles, im puzzled about the most performant method, since vertexbuffers got some overhead, its making it slow with just one quad.
Now im thinking about using displaylists, but im afraid these are depricated.

So what would be the fastest way to draw one quad (with textcoords)?
The SAME quad is used 10 - 30 times each frame.

Offline davedes
« Reply #1 - Posted 2013-09-02 19:47:42 »

Use static VBOs for vertex data that doesn't change often (e.g. position, color) and a dynamic VBO for anything you need to send to the shader per frame (e.g. texcoords). Put all 10-30 quads into the same VBO to improve batching.

The overhead is negligible for such a small amount of vertices. You don't need to do anything fancy like transform feedback, geom shaders, or instanced rendering.

I'm curious how you plan to render all your terrain with a single quad? Can you show an image of what you mean?

Offline RobinB

JGO Ninja

Medals: 44
Projects: 1
Exp: 3 years

Spacegame in progress

« Reply #2 - Posted 2013-09-02 19:53:03 »

The point is,  i have only one quad wich i draw 10-30 times.

Currently im using this code to draw an chunk:
    public void Draw(){
        if(isempty){ return; }

        terrainshader.activeTexture("terrain", 0, terrain);
        terrainshader.activeTexture("mask", 1, mask);
        terrainshader.setVar("clampscreen", Panel.getRect());
        terrainshader.setVar("directoutput", Debugger.ShadeTerrain() ? 1 : 0);
        terrainshader.setVar("screenoffset", new Vector2f(Panel.getX()+parent.getX(), Panel.getY() + parent.getY()));
            glTexCoord2f(0, 0);
            glVertex2f(0, 0);
            glTexCoord2f(0, 1);
            glVertex2f(0, Chunk.SIZE);
            glTexCoord2f(1, 1);
            glVertex2f(Chunk.SIZE, Chunk.SIZE);
            glTexCoord2f(1, 0);
            glVertex2f(Chunk.SIZE, 0);

This is just test code, so i need to convert this "glBegin(GL_QUADS); ... glEnd();" to some real rendering code now.
As you can see only one quad is used for all chunks.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #3 - Posted 2013-09-02 19:58:48 »

Read up on sprite batching. LibGDX has one which you can get inspired by, or see lwjgl-basics:

There is some info on sprite batching here:

These pages might also be relevant, since a sprite batcher pulls together many aspects of OpenGL and graphics programming (shaders, textures, VBOs, etc).

Basically the point is to minimize the number of times you are changing states, and batch as many vertices as you can into the same GL draw call. This means you should sort all of your quads so they aren't causing a lot of texture switches, or use sprite sheets where possible. Also, you should try using vertex attributes instead of uniforms (i.e. "setVar" it looks like) where possible, if the data is changing per-quad.

At the end of the day, if you are only rendering 30 quads it doesn't matter. You could stick with immediate mode and still get decent performance.

Offline RobinB

JGO Ninja

Medals: 44
Projects: 1
Exp: 3 years

Spacegame in progress

« Reply #4 - Posted 2013-09-02 20:16:15 »

Thank you, but sprite batching does a lot of other stuff im not looking for.
I have one texture every chunk, so each draw call needs another texture to be bound to the shader.

Ill try to explain my loop:
for(int i = 0; i < 10; i++){
 - Bind Texture
 - Draw quad

If i can draw these with only one batch (bind an texture to every quad), please tell me.

About perfomance, im having this issue with multiple objects (like with  drawing framebuffers), when im profiling the application, glBegin is way to high in that list Smiley.
Offline davedes
« Reply #5 - Posted 2013-09-02 22:24:11 »

Why does each chunk need its own texture? What's wrong with texture atlases? Most desktops support at least 4k textures these days.

If you are targeting new desktops you can use GL_TEXTURE_2D_ARRAY.

Offline RobinB

JGO Ninja

Medals: 44
Projects: 1
Exp: 3 years

Spacegame in progress

« Reply #6 - Posted 2013-09-02 22:32:19 »

Because each chunk has textures of 512x512 px.
These textures are actually TBO's to buffer terrain data (Using GL_RG8).
Packing multiple textures tougether, would create a slowdown at the updates (updates currently requires to reupload the buffer data).

Thanks for GL_TEXTURE_2D_ARRAY, maybe i could use this one.
Offline RobinB

JGO Ninja

Medals: 44
Projects: 1
Exp: 3 years

Spacegame in progress

« Reply #7 - Posted 2013-09-02 22:42:36 »

An image for clarification (raster is drawn using gl_lines, therefore the ms each frame is very high):

Red layer is used for masking, green layer for texture index (because texture index is < 15, almost no green is visible).
The raster is the quadtree used for colissions.
The coordinates are at the left top of each chunk.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

SHC (23 views)
2015-08-01 03:58:20

Jesse (19 views)
2015-07-29 04:35:27

Riven (39 views)
2015-07-27 16:38:00

Riven (21 views)
2015-07-27 15:35:20

Riven (24 views)
2015-07-27 12:26:13

Riven (14 views)
2015-07-27 12:23:39

BurntPizza (35 views)
2015-07-25 00:14:37

BurntPizza (46 views)
2015-07-24 22:06:39

BurntPizza (28 views)
2015-07-24 06:06:53

NoxInc (36 views)
2015-07-22 22:16:53
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!