Skip to content

Commit

Permalink
Draw selection quad without vertex source
Browse files Browse the repository at this point in the history
  • Loading branch information
httpdigest committed Mar 17, 2021
1 parent 44a7a59 commit 0c3b5c4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
7 changes: 3 additions & 4 deletions res/org/lwjgl/demo/game/voxelgame/selection.vs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ layout(std140) uniform Uniforms {
mat4 mvp;
};

layout(location=0) in vec2 quad;

out vec2 quad_out;

void main(void) {
quad_out = (quad + vec2(1.0)) * 0.5;
gl_Position = mvp * vec4(quad, 0.0, 1.0);
vec2 vertex = vec2(-1.0) + vec2(float((gl_VertexID & 1) <<1), float(gl_VertexID & 2));
quad_out = (vertex + vec2(1.0)) * 0.5;
gl_Position = mvp * vec4(vertex, 0.0, 1.0);
}
23 changes: 6 additions & 17 deletions src/org/lwjgl/demo/game/VoxelGameGL.java
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ public boolean removeEldestEntry(Map.Entry<Vector2i, VoxelField> eldest) {
private int collectDrawCallsProgram;

/* Resources for drawing the "selection" quad */
private int selectionVao;
private int nullVao;
private int selectionProgram;
private int selectionProgramUboBlockIndex;
private int selectionProgramUbo;
Expand Down Expand Up @@ -1285,21 +1285,10 @@ private void createFramebufferObject() {
}

/**
* Create the VAO for rendering the selection rectangle, which will be used for both highlighting
* the selected voxel faces as well as for rendering the cursor at the center of the screen.
* Create an empty VAO.
*/
private void createSelectionVao() {
selectionVao = glGenVertexArrays();
glBindVertexArray(selectionVao);
int vbo = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vbo);
try (MemoryStack stack = stackPush()) {
glBufferData(GL_ARRAY_BUFFER, stack.floats(1, -1, 1, 1, -1, -1, -1, 1), GL_STATIC_DRAW);
}
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0L);
glBindVertexArray(0);
glDeleteBuffers(vbo);
private void createNullVao() {
nullVao = glGenVertexArrays();
}

private void createBoundingBoxesVao() {
Expand Down Expand Up @@ -3605,7 +3594,7 @@ private void preDrawSelectionState() {
glEnable(GL_BLEND);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(useInverseDepth ? 1 : -1, useInverseDepth ? 1 : -1);
glBindVertexArray(selectionVao);
glBindVertexArray(nullVao);
glUseProgram(selectionProgram);
}

Expand Down Expand Up @@ -3730,7 +3719,7 @@ private void run() throws InterruptedException {
configureGlobalGlState();
createSelectionProgram();
createSelectionProgramUbo();
createSelectionVao();
createNullVao();
createMaterials();
createMultiDrawIndirectBuffer();
createChunkInfoBuffers();
Expand Down

0 comments on commit 0c3b5c4

Please sign in to comment.