Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (756)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
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  
  Libgdx - Speed up render of many polygon regions  (Read 7696 times)
0 Members and 1 Guest are viewing this topic.
Offline Visher

Junior Newbie





« Posted 2014-07-12 12:35:17 »

Hi guys, I have a question:

how can I speed up render of 1800 polygon regions, containing 6000 vertices? Currently I'm using frustum culling, and polygon regions are stored in quad tree, so I'm querying polygons from quad tree in viewbox.

I'm not fully into OpenGL, I heard something about VBO and caching objects in GPU memory, but don't know where to start and how to use this for my purposes. Can anyone teach me?

Render loop for Textured Polygons (it's my wrapper for PolygonRegion with AABB) looks like that:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
getTexturedPolygons().execute(qTreeBox, new QuadTree.Executor<TexturedPolygon>() {
    @Override
   
   // for each TexturedPolygon in viewbox
    public void execute(double x, double y, TexturedPolygon texturedPolygon) {
        if (camera.frustum.boundsInFrustum(texturedPolygon.getAABB())) {
            polygonSpriteBatch.draw(texturedPolygon.getPolygonRegion(), 0, 0);
        }
    }
});


The result is textured terrain. Here are bounds of each triangle:
Offline Nate

« JGO Bitwise Duke »


Medals: 167
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #1 - Posted 2014-07-13 04:46:39 »

SpriteCache uses a VBO and could serve as an example. SpriteCache caches geometry in a VBO (via Mesh) for any number of textures, keeps track of the offsets and allows you to reference that geometry by an ID. When you draw, you give the ID and the geometry is drawn from the VBO, without needing to be sent to the GPU again. Similar to SpriteBatch, SpriteCache caches quads. There is no PolygonSpriteCache, but you could write one. Getting the array indexes, etc exactly right was a bit tricky. Smiley PolygonSpriteCache would make a nice contribution to libgdx, but it may be easier for your scenario to use Mesh directly.

Beyond using the VBO, you'll need to determine what geometry to cache. Usually you'd choose the geometry on screen, plus some buffer around that. Only when the camera moves far enough would you need to re-cache your geometry. You want to cache enough that re-caches don't happen too often, but not so much that a re-cache takes too long. OrthoCachedTiledMapRenderer could serve as an example, it does this for a tile map using SpriteCache.

Offline Visher

Junior Newbie





« Reply #2 - Posted 2014-07-14 10:34:04 »

SpriteCache uses a VBO and could serve as an example. SpriteCache caches geometry in a VBO (via Mesh) for any number of textures, keeps track of the offsets and allows you to reference that geometry by an ID. When you draw, you give the ID and the geometry is drawn from the VBO, without needing to be sent to the GPU again. Similar to SpriteBatch, SpriteCache caches quads. There is no PolygonSpriteCache, but you could write one. Getting the array indexes, etc exactly right was a bit tricky. Smiley PolygonSpriteCache would make a nice contribution to libgdx, but it may be easier for your scenario to use Mesh directly.

Beyond using the VBO, you'll need to determine what geometry to cache. Usually you'd choose the geometry on screen, plus some buffer around that. Only when the camera moves far enough would you need to re-cache your geometry. You want to cache enough that re-caches don't happen too often, but not so much that a re-cache takes too long. OrthoCachedTiledMapRenderer could serve as an example, it does this for a tile map using SpriteCache.

Thanks Nate, I just finished creating meshes and I'm using it to render my terrain. FPS didn't changed on my PC, but on my Android phone it changed from unstable 43-52 to stable 60.
Also, I didn't implemented any culling etc, mesh containing whole scene (which is ~5 times larger than visible area) is rendered every frame.

Thanks for your response, now I think that I understand everything.

P.S. should I divide scene into e.g. 10 meshes and do culling? Can you predict FPS gain after implementing it? I'm asking because I cut my scene to 1/5 of it's size and FPS didn't changed.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Nate

« JGO Bitwise Duke »


Medals: 167
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #3 - Posted 2014-07-14 11:42:10 »

Your fps is capped at 60 on Android so maybe you just can't see improvements. No idea what they might be though. OpenGL will do culling and you aren't sending the geometry every frame, so you make OpenGL's culling faster by caching less. There may be a bigger difference if you draw from many textures.

Pages: [1]
  ignore  |  Print  
 
 

 
DesertCoockie (53 views)
2018-05-13 18:23:11

nelsongames (84 views)
2018-04-24 18:15:36

nelsongames (75 views)
2018-04-24 18:14:32

ivj94 (760 views)
2018-03-24 14:47:39

ivj94 (88 views)
2018-03-24 14:46:31

ivj94 (644 views)
2018-03-24 14:43:53

Solater (103 views)
2018-03-17 05:04:08

nelsongames (185 views)
2018-03-05 17:56:34

Gornova (427 views)
2018-03-02 22:15:33

buddyBro (1087 views)
2018-02-28 16:59:18
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
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!