OpenGL Occlusion Culling?

I'm making a 3D game with JOGL. I expect to have a world layout like Minecraft, with a lot of cube-like models. That means I can skip faces that touch each other (occlusion culling) to speed up drawing. I want to be able to remove the indices for specific models to make this work. But, I'm using VAOs, which are not meant to be modified or read from the CPU once written. Is there a way to do this? Using JOGL GLJPanel with VAOs and Shaders. Code in comments bc I am running out of space.
4 Replies
JavaBot
JavaBot10mo ago
This post has been reserved for your question.
Hey @The Typhothanian! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
The Typhothanian
The TyphothanianOP10mo ago
Here's GLJPanel draw code:
@Override
public void display(GLAutoDrawable drawable) {
requestFocusInWindow();

GL3 gl = drawable.getGL().getGL3();
gl.glClearColor(0, 0, 0, 0);
gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
gl.glUseProgram(shader.program);

shader.setUniform(gl, "proj", Matrices.perspective(pos, rot, 90, 0.1, 5000, aspectRatio));

for (Map.Entry<Model, List<Entity>> entry : entities.entrySet()) {
entry.getKey().bind(gl);
shader.setUniform(gl, "sampler", entry.getKey().texture);

gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST); // nearest neighbor stuff
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST);

int[] vbo = new int[1];

gl.glGenBuffers(1, vbo, 0);
gl.glBindBuffer(gl.GL_ARRAY_BUFFER, vbo[0]);

FloatBuffer fb = FloatBuffer.allocate(entry.getValue().size() * 3);

for (Entity entity : entry.getValue()) {
fb.put(entity.pos);
}

// give each drawn model the position of itself
gl.glBufferData(gl.GL_ARRAY_BUFFER, (long) entry.getValue().size() * Float.BYTES * 3, fb.flip(), gl.GL_STATIC_DRAW);
gl.glVertexAttribPointer(2, 3, gl.GL_FLOAT, false, 0, 0);
gl.glEnableVertexAttribArray(2);
gl.glVertexAttribDivisor(2, 1);

gl.glDrawElementsInstanced(entry.getKey().type[0], entry.getKey().vertexCount[0], gl.GL_UNSIGNED_INT, 0, entry.getValue().size()); // one draw call per model for efficiency

gl.glDeleteBuffers(1, vbo, 0);

Model.unbind(gl);
}
}
@Override
public void display(GLAutoDrawable drawable) {
requestFocusInWindow();

GL3 gl = drawable.getGL().getGL3();
gl.glClearColor(0, 0, 0, 0);
gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
gl.glUseProgram(shader.program);

shader.setUniform(gl, "proj", Matrices.perspective(pos, rot, 90, 0.1, 5000, aspectRatio));

for (Map.Entry<Model, List<Entity>> entry : entities.entrySet()) {
entry.getKey().bind(gl);
shader.setUniform(gl, "sampler", entry.getKey().texture);

gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST); // nearest neighbor stuff
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST);

int[] vbo = new int[1];

gl.glGenBuffers(1, vbo, 0);
gl.glBindBuffer(gl.GL_ARRAY_BUFFER, vbo[0]);

FloatBuffer fb = FloatBuffer.allocate(entry.getValue().size() * 3);

for (Entity entity : entry.getValue()) {
fb.put(entity.pos);
}

// give each drawn model the position of itself
gl.glBufferData(gl.GL_ARRAY_BUFFER, (long) entry.getValue().size() * Float.BYTES * 3, fb.flip(), gl.GL_STATIC_DRAW);
gl.glVertexAttribPointer(2, 3, gl.GL_FLOAT, false, 0, 0);
gl.glEnableVertexAttribArray(2);
gl.glVertexAttribDivisor(2, 1);

gl.glDrawElementsInstanced(entry.getKey().type[0], entry.getKey().vertexCount[0], gl.GL_UNSIGNED_INT, 0, entry.getValue().size()); // one draw call per model for efficiency

gl.glDeleteBuffers(1, vbo, 0);

Model.unbind(gl);
}
}
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
JavaBot
JavaBot10mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server