HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavaMinor

Vertex Buffer Object (VBO) multi-class implementation

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
multivboverteximplementationobjectclassbuffer

Problem

I'm hoping someone could look through this code for my Chunk, Mesh and ChunkManager classes and tell me what I need to do to improve.

For some reason, when I wrote it in NetBeans and transferred it to Eclipse it deleted all my comments.

I especially don't understand the buffer system. Can I use backbuffers in OpenGL?

Chunk class:

```
public class Chunk
{
public static final int X_CHUNK_SIZE = 16;
public static final int Y_CHUNK_SIZE = 64;
public static final int Z_CHUNK_SIZE = 16;

public int chunkXNumber;
public int chunkZNumber;

private Mesh mesh;
private Shader shader;
private Material material;
private Texture texture;
private Transform transform;

private boolean chunkUpdateNeeded;

private ArrayList indiceList = new ArrayList();

private Block [][][] blocks = new Block[X_CHUNK_SIZE][Y_CHUNK_SIZE][Z_CHUNK_SIZE];

public Chunk(int chunkXNumber, int chunkZNumber)
{
this.chunkXNumber = chunkXNumber;
this.chunkZNumber = chunkZNumber;

createBlocks(chunkXNumber, chunkZNumber);

boolean[][][] blocksActive = getActiveBlocks();

texture = new Texture("terrain.png");
material = new Material(texture, new Vector3f(1.0f, 1.0f, 1.0f));
transform = new Transform();
//shader = BasicShader.getInstance();
shader = BasicShader.getInstance();

generateChunk(blocksActive);

}

private void generateChunk(boolean[][][] blocksActive)
{
Vertex[] allVertices = createVertices(blocksActive);

int[] indices = new int[indiceList.size()];

for(int i = 0; i .52)
{
if(yVal >= 38)
{
material = 0;
}

else
{
material = 1;
}
}

else
{
if(yVal >= 8)
{
material = 0;
}

else if(yVal > -12 && yVal vertexList = new

Solution

Ok so I actually asked this question a while ago and since I've since figured it out I figured I would go ahead and answer it.

Firstly my issue was not caused by some singular defect in my code or poorly written line but moreso by a culmination of poorly written code as a whole and the specific language I was using.

I'll address the issue that was causing me the most grief first, Garbage collection. Due to the fact that I was using java and creating millions of voxels on the screen at a time from the start I was constantly plagued by issues with garbage collection. Initially the game would play smoothly and then just freeze for 5-10 seconds consistently. I alleviated this problem by switching to Java's concurrent garbage collection system. Although this removed the stop the world aspect of garbage collection it was now replaced with a more constant less severe lag. Full disclosure, I never actually resolved this problem and instead opted to port my entire engine into c++ where the problem doesn't exist in any form.

The second issue was with the way I was handling Geometry creation. I initially didn't use VAO's mostly due to naivety. After switching to VAO's my performance definitely saw a significant increase. But honestly I believe the lag issues I was experiencing can be attributed to the geometry generation itself. Looking back I was culling very few of the vertices that existed in my scene. This combined with overall bad engine design and constant lag from GC really slowed my game down.

Context

StackExchange Code Review Q#34061, answer score: 3

Revisions (0)

No revisions yet.