Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
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 1403 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 »

Hello,

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:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
    public void Draw(){
        if(isempty){ return; }

        terrainshader.Enable();
        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()));
       
        glBegin(GL_QUADS);
            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);
        glEnd();
    }


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:
https://github.com/mattdesl/lwjgl-basics/blob/master/src/mdesl/graphics/SpriteBatch.java

There is some info on sprite batching here:
https://github.com/mattdesl/lwjgl-basics/wiki/Sprite-Batching

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

https://github.com/mattdesl/lwjgl-basics/wiki/Textures
https://github.com/mattdesl/lwjgl-basics/wiki/Shaders
https://github.com/mattdesl/lwjgl-basics/wiki/LibGDX-Meshes
https://github.com/mattdesl/lwjgl-basics/wiki/Custom-Sprite-Batcher-in-LibGDX


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:
1  
2  
3  
4  
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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Mr.CodeIt (10 views)
2014-12-23 03:34:11

rwatson462 (38 views)
2014-12-15 09:26:44

Mr.CodeIt (31 views)
2014-12-14 19:50:38

BurntPizza (62 views)
2014-12-09 22:41:13

BurntPizza (99 views)
2014-12-08 04:46:31

JscottyBieshaar (60 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (77 views)
2014-11-29 21:32:03

toopeicgaming1999 (138 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org 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‑gaming.org
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!