Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (804)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (868)
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  
  How to rerender a VBO?  (Read 2602 times)
0 Members and 1 Guest are viewing this topic.
Offline sci4me

Junior Devvie


Medals: 1



« Posted 2016-01-17 21:06:16 »

So I'm writing a voxel game. So, if a block changes in a chunk, I need to rerender that chunk's VBO with the new data. How do I do this?
Offline hwinwuzhere
« Reply #1 - Posted 2016-01-17 21:14:49 »

Not really a direct answer to your question, but I certainly do suggest you take a peek at Thinmatrix's tutorials where he explains the use of VBOs and writes you basically the sample code needed.  Pointing

There are two kinds of people in this world: Those who can extrapolate from incomplete data,
Offline sci4me

Junior Devvie


Medals: 1



« Reply #2 - Posted 2016-01-18 01:13:02 »

I appreciate the tutorials and am sure they'll be helpful, but I still need to know how to rerender a VBO...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd
« Reply #3 - Posted 2016-01-18 01:47:53 »

glBufferData() reallocates the VBO.

Myomyomyo.
Offline sci4me

Junior Devvie


Medals: 1



« Reply #4 - Posted 2016-01-18 02:00:22 »

Ok and a quick related question: when I want to draw my VBO I am doing glEnableClientState, drawing it, and doing glDisableClientState. Is there any reason to do it this way or can I just do glEnableClientState at the start of my program and leave it enabled?
Offline theagentd
« Reply #5 - Posted 2016-01-18 04:03:37 »

glEnableClientState() makes OpenGL attempt to read data from a VBO. If you at any point draw something with immediate mode, or don't have a valid buffer for an attribute anymore or read out of bounds, you can crash the entire program. Example:

1. Draw model 1 with 100 vertices, each with 3D positions, texture coordinates and normals. glDisableClientState() is not called afterwards.
2. Draw model 2 with 5000 vertices, each with only 3D positions and texture coordinates. Potential for a crash here as the previous glNormalPointer() points to the buffer of model 1 and it's left enabled, meaning that the driver will read out of bounds of the VBO, potentially randomly crashing the JVM.

Making sure to always disable state you're not using anymore is a good idea.

The best solution is to keep track of the state of everything and only change it when it actually needs to be changed, as OpenGL commands have a lot of overhead. In the example above, you'd want to avoid disabling and enabling attributes inbetween drawing model 1 and 2. You'd realize that position and texture coordinates are already enabled and only disable normals (1 call), instead of disabling all 3 of them and enabling position and texcoords again (5 calls). This is probably overkill though unless you're drawing a crapload of models each frame.

Myomyomyo.
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (583 views)
2019-09-04 15:33:17

hadezbladez (5517 views)
2018-11-16 13:46:03

hadezbladez (2405 views)
2018-11-16 13:41:33

hadezbladez (5779 views)
2018-11-16 13:35:35

hadezbladez (1226 views)
2018-11-16 13:32:03

EgonOlsen (4664 views)
2018-06-10 19:43:48

EgonOlsen (5684 views)
2018-06-10 19:43:44

EgonOlsen (3199 views)
2018-06-10 19:43:20

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

nelsongames (5116 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08
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!