Skip to content

Commit

Permalink
vulkanize: make all lines 3D
Browse files Browse the repository at this point in the history
The only 2D lines were the crosshair, which is trivial to make 3D. Doing
so helps resource reuse in vulkan so crosshairs and wireframe boxes can
use the same pipeline.
  • Loading branch information
pow2clk committed Jun 19, 2019
1 parent ec8faf2 commit eece721
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
11 changes: 5 additions & 6 deletions src/glrenderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,21 +297,20 @@ static void draw_triangles_2d(Buffer buffer, int count) {
glBindBuffer(GL_ARRAY_BUFFER, 0);
} // draw_triangles_2d()

// Draw lines consisting of <count> 2D or 3D vertices with <components> components
// Draw lines consisting of <count> 3D vertices
// taken from vertex buffer <buffer> at <width> pixels wide.
// Intended for use rendering 3D highlights or 2D UI elements
// The expected components are 2D or 3D position coords and 2D tex coords
// The expected components are 3D position coords and 2D tex coords
// The <buffer> is bound and used for vertex attribs
// and pointers specified. <components> determines how many attribs there are
// depending on whether the lines are 2D or 3D <count> is used for the number of
// and pointers specified. <count> is used for the number of
// vertices in the draw call. Everything is unbound before exit.
void draw_lines(Buffer buffer, int components, int count, float width) {
void draw_lines(Buffer buffer, int count, float width) {
glLineWidth(width);
glEnable(GL_COLOR_LOGIC_OP);
glBindBuffer(GL_ARRAY_BUFFER, buffer->id);
glEnableVertexAttribArray(0);
glVertexAttribPointer(
0, components, GL_FLOAT, GL_FALSE, 0, 0);
0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_LINES, 0, count);
glDisableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
Expand Down
8 changes: 4 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ Buffer gen_crosshair_buffer() {
int y = g->height / 2;
int p = 10 * g->scale;
float data[] = {
x, y - p, x, y + p,
x - p, y, x + p, y
x, y - p, 0, x, y + p, 0,
x - p, y, 0, x + p, y, 0
};
return gen_buffer(sizeof(data), data);
} // gen_crosshair_buffer()
Expand Down Expand Up @@ -1687,7 +1687,7 @@ void render_wireframe(Pipeline pipeline, Uniform uniform, Player *player, Buffer
ubo_body.matrix, g->width, g->height,
s->x - hx, s->y - hy, s->z - hz, s->rx, s->ry, g->fov, g->ortho, g->render_radius);
bind_pipeline(pipeline, uniform, sizeof(ubo_body), &ubo_body);
draw_lines(buffer, 3, 24, 1.0);
draw_lines(buffer, 24, 1.0);
}
} // render_wireframe()

Expand All @@ -1697,7 +1697,7 @@ void render_crosshairs(Pipeline pipeline, Uniform uniform, Buffer buffer) {
MatUbo ubo_body;
set_matrix_2d(ubo_body.matrix, g->width, g->height);
bind_pipeline(pipeline, uniform, sizeof(ubo_body), &ubo_body);
draw_lines(buffer, 2, 4, 4 * g->scale);
draw_lines(buffer, 4, 4 * g->scale);
}

// Render the 3D UI element representing the chunk that will be placed
Expand Down
4 changes: 2 additions & 2 deletions src/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ Buffer gen_faces(int components, int faces, float *data);
// Update <buffer> with <faces> quads with vertex attributes
// consisting of <components> attributes using <data>
void update_faces(Buffer buffer, int components, int faces, float *data);
// Draw lines consisting of <count> 2D or 3D vertices with <components> components
// Draw lines consisting of <count> 3D vertices
// taken from vertex buffer <buffer> at <width> pixels
void draw_lines(Buffer buffer, int components, int count, float width);
void draw_lines(Buffer buffer, int count, float width);
// Draw landscape chunk using vertex buffer <buffer> consisting of <faces> quads
void draw_chunk(Buffer buffer, int faces);
// Draw UI placement option represented by vertex buffer <buffer>
Expand Down

0 comments on commit eece721

Please sign in to comment.