Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (534)
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  
  Updating VBOs  (Read 259 times)
0 Members and 1 Guest are viewing this topic.
Offline mproncace

Senior Newbie


Medals: 1



« Posted 2013-09-03 02:01:24 »

I've been playing around with VBOs a lot today (mostly because a game I'm working on necessitates it), and while I have a basic idea of how glBufferSubData() and glMapBuffer() work, I'm not quite sure of how to implement them. My game is essentially a Terraria clone, and the primary VBO contains data about the blocks in the world. The world is divided into "chunks" which are 16x128 blocks large. When the player modifies a block in a chunk, that chunk is updated. Up until now, I've been doing this by storing each chunk's vertex data to its own array in a HashMap and updating each array as needed. This also means I have to splice them together into a single array, which causes a minor lag spike. But, I digress. I'd be set to go with the two aforementioned methods, except that some blocks are sometimes null. When a player places a block in a chunk, its number of vertices increases. Therefore, it wouldn't suffice to simply replace the existing data for the chunk in the VBO, as it would cause the game to crash due to a lack of allocated memory for the vertices. My first thought as to preventing this would be to allocate enough memory for 16 times 128 times four vertices (the number of vertices which would exist in a chunk if every block were filled in). But, I'm not entirely sure as to how to accomplish this. Would anyone mind pointing me in the right direction? Smiley
Offline quew8

JGO Coder


Medals: 29



« Reply #1 - Posted 2013-09-03 17:46:11 »

If you're going down that road. Firstly you should have one VBO containing all vertex data for a generic chunk. Then have an IBO specific to each chunk which contains which blocks are where. Change the transformation matrix to position each chunk in the right place (or just have a uniform x-offset in your shader if you aren't doing any other model transforms). Secondly than single VBO should only be (16 + 1) * (128 + 1) since each vertex is shared between 4 blocks and there is no point having the same data 4 times now you are using IBOs.

Now, technicals aside. To create a VBO of a specific side, pass in a Buffer of that size. It doesn't have to be full or in fact used at all. Then you can use, as you said, glBufferSubData() or glMapBuffer() / glUnmapBuffer() to fill in the gaps as it were. All you have to do is store how many blocks you have and where they are in the IBO. Ideally you would bunch them all together and draw a whole chunk with one OpenGL call, but then you would need to move the whole buffer down once you deleted the first block. Certainly fill up empty slots from the bottom and try to group together draw calls into one.

Now I think about it, that was quite technical.
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.

pw (35 views)
2014-07-24 01:59:36

Riven (33 views)
2014-07-23 21:16:32

Riven (21 views)
2014-07-23 21:07:15

Riven (24 views)
2014-07-23 20:56:16

ctomni231 (55 views)
2014-07-18 06:55:21

Zero Volt (47 views)
2014-07-17 23:47:54

danieldean (38 views)
2014-07-17 23:41:23

MustardPeter (43 views)
2014-07-16 23:30:00

Cero (59 views)
2014-07-16 00:42:17

Riven (56 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!