-// Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
+/* Copyright (C) 2021-2022 Harry Godden (hgn) - All Rights Reserved */
-SHADER_DEFINE( vg_line_shader,
+#ifdef VG_3D
+ typedef v3f line_co;
+#else
+ typedef v2f line_co;
+#endif
- // VERTEX
+SHADER_DEFINE( vg_line_shader,
+#ifdef VG_3D
+ "uniform mat4 uPv;"
+ "layout (location=0) in vec3 a_co;"
+#else
+ "uniform mat3 uPv;"
"layout (location=0) in vec2 a_co;"
+#endif
"layout (location=1) in vec4 a_colour;"
- "uniform mat3 uPv;"
""
"out vec4 s_colour;"
""
"void main()"
"{"
+#ifdef VG_3D
+ " vec4 vert_pos = uPv * vec4( a_co, 1.0 );"
+#else
" vec4 vert_pos = vec4( uPv * vec3( a_co, 1.0 ), 1.0 );"
+#endif
" s_colour = a_colour;"
" gl_Position = vert_pos;"
"}",
{
struct vg_lines_vert
{
+#ifdef VG_3D
+ v3f co;
+#else
v2f co;
+#endif
+
u32 colour;
}
*buffer;
free( vg_lines.buffer );
}
-static void vg_lines_drawall(float* projection)
+static void vg_lines_drawall( float* projection )
{
SHADER_USE( vg_line_shader );
- glUniformMatrix3fv( SHADER_UNIFORM( vg_line_shader, "uPv" ), 1, GL_FALSE, projection );
-
+
+#ifdef VG_3D
+ glUniformMatrix4fv
+#else
+ glUniformMatrix3fv
+#endif
+ ( SHADER_UNIFORM( vg_line_shader, "uPv" ), 1, GL_FALSE, projection );
+
glBindVertexArray( vg_lines.vao );
glBindBuffer( GL_ARRAY_BUFFER, vg_lines.vbo );
- glBufferSubData( GL_ARRAY_BUFFER, 0, vg_lines.draw_idx * sizeof(struct vg_lines_vert), vg_lines.buffer );
+ glBufferSubData( GL_ARRAY_BUFFER, 0, vg_lines.draw_idx *
+ sizeof(struct vg_lines_vert), vg_lines.buffer );
+
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glBlendEquation( GL_FUNC_ADD );
vg_lines.draw_idx = 0;
}
-static void vg_line2( v2f from, v2f to, u32 fc, u32 tc )
+static void vg_line2( line_co from, line_co to, u32 fc, u32 tc )
{
- struct vg_lines_vert *v = vg_lines.buffer + vg_lines.draw_idx;
+ struct vg_lines_vert *v = &vg_lines.buffer[vg_lines.draw_idx];
+
+#ifdef VG_3D
+ v3_copy( from, v[0].co );
+ v3_copy( to, v[1].co );
+#else
v2_copy( from, v[0].co );
v2_copy( to, v[1].co );
+#endif
+
v[0].colour = fc;
v[1].colour = tc;
vg_lines.draw_idx += 2;
}
-static void vg_line( v2f from, v2f to, u32 colour )
+static void vg_line( line_co from, line_co to, u32 colour )
{
vg_line2( from, to, colour, colour );
}
-static void vg_line_box( v2f min, v2f max, u32 colour )
+static void vg_line_box( line_co min, line_co max, u32 colour )
{
+#ifdef VG_3D
+ /* TODO... */
+#else
vg_line( min, (v2f){min[0],max[1]}, colour );
vg_line( (v2f){min[0],max[1]}, max, colour );
vg_line( max, (v2f){max[0],min[1]}, colour );
vg_line( (v2f){max[0],min[1]}, min, colour );
+#endif
}