Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: Voxel engine optimalisation

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    17

    Voxel engine optimalisation

    Hi all,

    For the last few days I have worked on my first OpenGL test project. It's a simple voxel engine in Java with the LWJGL library. I used chunks, just like Minecraft. Those chunks are 16*16*128. When I load the world, I loop over all the blocks in a chunk, creating a VBO with the coordinates, normal coordinates and texture coordinates of every single chunk. Now, when I render 1 chunk of 16*16*128, I get around 250 FPS (Yes, this renders actually all the cubes inside the chunk so 16*16*128 = 32768 quads). However, when I try to render 4 chunks, it already dropped to 40 FPS. What would be the best way to increase my FPS?

    Thanks!

  2. #2
    Junior Member Regular Contributor Kopelrativ's Avatar
    Join Date
    Apr 2011
    Posts
    214
    Quote Originally Posted by Basaaa View Post
    Hi all,

    For the last few days I have worked on my first OpenGL test project. It's a simple voxel engine in Java with the LWJGL library. I used chunks, just like Minecraft. Those chunks are 16*16*128. When I load the world, I loop over all the blocks in a chunk, creating a VBO with the coordinates, normal coordinates and texture coordinates of every single chunk. Now, when I render 1 chunk of 16*16*128, I get around 250 FPS (Yes, this renders actually all the cubes inside the chunk so 16*16*128 = 32768 quads). However, when I try to render 4 chunks, it already dropped to 40 FPS. What would be the best way to increase my FPS?

    Thanks!
    You should use a transformation phase. Transform from a chunk data into a list of visible surfaces. For example, it is no use to draw quads from cubes facing in a direction where there is another solid material.

    Getting a good FPS from voxel based data is a challenge. You are going to need a lot of optimization and special hacks, depending on the number of chunks you want to show.

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    17
    Thank you for your answer. I'm gonna try to implement a few optimalisations.
    Another quick question: can I remove faces in a VBO with glBufferSubData?

  4. #4
    Junior Member Regular Contributor Kopelrativ's Avatar
    Join Date
    Apr 2011
    Posts
    214
    Quote Originally Posted by Basaaa View Post
    Thank you for your answer. I'm gonna try to implement a few optimalisations.
    Another quick question: can I remove faces in a VBO with glBufferSubData?
    You can't remove data with glBufferSubData, you can only replace one set of data with another set.

  5. #5
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    17
    Hmm, I'm now switching the code from quads to triangles, but I simply can't get it to work.

    Here is my vertex buffer:

    Code :
    private float[] buffer_data {
    0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
    1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
    0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f };

    And here I draw it:
    Code :
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo_id);
     
    GL11.glVertexPointer(3, GL_FLOAT, 24, 0);
    GL11.glNormalPointer(GL_FLOAT, 24, 0);
    GL11.glTexCoordPointer(2, GL_FLOAT, 24, 0);
     
    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, tmp_buffer_array.length / 8);

    However, I get a triangle on the z axis (pointing towards me), and the texture coordinates aren't working. Anything wrong with the float array or drawing code? Quads work fine. What could be the problem here?

  6. #6
    Intern Contributor uwi2k2's Avatar
    Join Date
    Mar 2011
    Posts
    98
    hi,

    Code :
    GL11.glVertexPointer(3, GL_FLOAT, 24, 0);
    GL11.glNormalPointer(GL_FLOAT, 24, 0);
    GL11.glTexCoordPointer(2, GL_FLOAT, 24, 0);

    glNormalPointer(GL_FLOAT, 24, 0); << missing first parameter..
    and - looks like you are missing the propper offset and stride for the glNormalPointer, glTexCoordPointer they are not starting with the 1 elementin your buffer data. so the last parameter needs to be 24, and 48 i would guss ..

    cu
    uwi
    uwi2k2 - OpenGL Trainer: www.opengl-trainer.com
    ---------------------------------------------------------
    Free Programming Helpline: www.programming-hotline.com
    ---------------------------------------------------------
    A Friday Night Programmer: www.uwiworld.net

  7. #7
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    17
    Thank you for your reply.

    Is seems that I actually am not missing an argument in glNormalPointer, as this works fine with quads. Also, could you explain how the last parameter works? (pointer_buffer_offset). I still can't get it to work properly.

    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •