Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (683)
Games in Android Showcase (196)
games submitted by our members
Games in WIP (750)
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  
  VBOs versus no VBOs - is this JOGL code right?  (Read 1777 times)
0 Members and 1 Guest are viewing this topic.
Offline ags1

JGO Kernel

Medals: 314
Projects: 7

Make code not war!

« Posted 2012-07-13 20:46:17 »

Is this code right - it draws lots of stuff, either using VBOs or not using VBOs if they are not available:


        for (int i = 0; i < (layers * layers); i++) {
          gl.glTranslatef(0.0f, 0.0f, 0.01f);
         if (JoglRunner.vboAvailable(gl)) {
            gl.glBindBuffer(GL.GL_ARRAY_BUFFER, VBO[0]);
            gl.glVertexPointer(3, GL.GL_FLOAT, 0, 0);
            gl.glBindBuffer(GL.GL_ARRAY_BUFFER, VBO[1]);
            gl.glColorPointer(4, GL.GL_FLOAT, 0, 0);
            gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 20000);
         } else {
            gl.glVertexPointer(3, GL.GL_FLOAT, 0, vertexBuffer);
            gl.glColorPointer(4, GL.GL_FLOAT, 0, colorBuffer);
            gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 20000);

I'm bothered by the call to enable client state that I sem to need before using a VBO - it doesn't make sense to me - I am trying to avoid client state.

Offline gouessej
« Reply #1 - Posted 2012-07-13 21:33:59 »


It seems correct but I don't know the source code of JoglRunner.vboAvailable(GL). In the alpha version of TUER, I put this kind of code into separate class to avoid performing such tests each time I use some vertices during the display. Don't forget that VBOs can be static or dynamic, you can use an "hint" to indicate that you're going to change their content often or not. Static VBOs are faster on graphics cards with a correct support of this feature.

Edit.: you should have posted that into the JOGL section.

Offline ags1

JGO Kernel

Medals: 314
Projects: 7

Make code not war!

« Reply #2 - Posted 2012-07-13 22:07:12 »

Thanks. You make a good point about vboAvailable() - I can make that method more efficient.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd

« JGO Bitwise Duke »

Medals: 807
Projects: 4
Exp: 8 years

« Reply #3 - Posted 2012-07-13 22:30:48 »

You can't get away from the client state. OpenGL has to be told which attributes it should read from the VBO/pointer and which ones it should just use the current attribute set by glColor(), glTexCoord(), etc. You don't always have texture coordinates, you don't always have normals, you don't always have per vertex colors, so glEnableClientState() defines which ones you're actually sending. If you use shaders and have custom attributes you use glEnableVertexAttribArray(attributeLocation) instead, but it works in the same way. You could use VAOs to hold your client state though.

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

orrenravid (154 views)
2016-07-16 03:57:23

theagentd (222 views)
2016-07-11 14:28:54

Hydroque (305 views)
2016-07-06 05:56:57

Hydroque (455 views)
2016-07-03 08:52:54

GrandCastle (341 views)
2016-07-01 09:13:47

GrandCastle (333 views)
2016-07-01 09:09:45

CopyableCougar4 (387 views)
2016-06-25 16:56:52

Hydroque (370 views)
2016-06-22 02:17:53

SwampChicken (338 views)
2016-06-20 13:22:57

SwampChicken (289 views)
2016-06-20 13:22:49
Making a Dynamic Plugin System
by Hydroque
2016-06-25 00:13:25

Java Data structures
by BinaryMonkL
2016-06-13 21:22:09

Java Data structures
by BinaryMonkL
2016-06-13 21:20:42

FPS Camera Tutorial
by Hydroque
2016-05-22 05:40:58

Website offering 3D Models specifically for games for free
by vusman
2016-05-18 17:23:09

Website offering 3D Models specifically for games for free
by vusman
2016-05-09 08:50:56

Website offering 3D Models specifically for games for free
by vusman
2016-05-06 11:10:21

Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17 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!