renderer2d work
This commit is contained in:
parent
3ea92c4618
commit
5c8abf1a7d
|
@ -3,20 +3,45 @@
|
||||||
<Objective-C>
|
<Objective-C>
|
||||||
<option name="HEADER_GUARD_STYLE_PATTERN" value="GUARD_${UUID}" />
|
<option name="HEADER_GUARD_STYLE_PATTERN" value="GUARD_${UUID}" />
|
||||||
</Objective-C>
|
</Objective-C>
|
||||||
<clangFormatSettings>
|
<Objective-C-extensions>
|
||||||
<option name="ENABLED" value="true" />
|
<rules>
|
||||||
</clangFormatSettings>
|
<rule entity="NAMESPACE" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
<files>
|
<rule entity="MACRO" visibility="ANY" specifier="ANY" prefix="" style="SCREAMING_SNAKE_CASE" suffix="" />
|
||||||
<extensions>
|
<rule entity="CLASS" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
<pair source="c" header="h" fileNamingConvention="SNAKE_CASE" />
|
<rule entity="STRUCT" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
<pair source="cu" header="cuh" fileNamingConvention="NONE" />
|
<rule entity="ENUM" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
<pair source="ixx" header="" fileNamingConvention="NONE" />
|
<rule entity="ENUMERATOR" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
<pair source="mxx" header="" fileNamingConvention="NONE" />
|
<rule entity="TYPEDEF" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
<pair source="cppm" header="" fileNamingConvention="NONE" />
|
<rule entity="UNION" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
<pair source="ccm" header="" fileNamingConvention="NONE" />
|
<rule entity="CLASS_MEMBER_FUNCTION" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
<pair source="cxxm" header="" fileNamingConvention="NONE" />
|
<rule entity="STRUCT_MEMBER_FUNCTION" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
<pair source="c++m" header="" fileNamingConvention="NONE" />
|
<rule entity="CLASS_MEMBER_FIELD" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
</extensions>
|
<rule entity="STRUCT_MEMBER_FIELD" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
</files>
|
<rule entity="GLOBAL_FUNCTION" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
|
<rule entity="GLOBAL_VARIABLE" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
|
<rule entity="PARAMETER" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
|
<rule entity="LOCAL_VARIABLE" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
|
</rules>
|
||||||
|
</Objective-C-extensions>
|
||||||
|
<Objective-C-extensions>
|
||||||
|
<rules>
|
||||||
|
<rule entity="NAMESPACE" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
|
<rule entity="MACRO" visibility="ANY" specifier="ANY" prefix="" style="SCREAMING_SNAKE_CASE" suffix="" />
|
||||||
|
<rule entity="CLASS" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
|
<rule entity="STRUCT" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
|
<rule entity="ENUM" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
|
<rule entity="ENUMERATOR" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
|
<rule entity="TYPEDEF" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
|
<rule entity="UNION" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
|
<rule entity="CLASS_MEMBER_FUNCTION" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
|
<rule entity="STRUCT_MEMBER_FUNCTION" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
|
<rule entity="CLASS_MEMBER_FIELD" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
|
<rule entity="STRUCT_MEMBER_FIELD" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
|
<rule entity="GLOBAL_FUNCTION" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
|
<rule entity="GLOBAL_VARIABLE" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
|
<rule entity="PARAMETER" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
|
<rule entity="LOCAL_VARIABLE" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
|
</rules>
|
||||||
|
</Objective-C-extensions>
|
||||||
</code_scheme>
|
</code_scheme>
|
||||||
</component>
|
</component>
|
|
@ -1,5 +1,5 @@
|
||||||
<component name="ProjectCodeStyleConfiguration">
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
<state>
|
<state>
|
||||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||||
</state>
|
</state>
|
||||||
</component>
|
</component>
|
|
@ -2,12 +2,19 @@
|
||||||
#define GUARD_2B56918289975E8AA8711D6E080ED4B9
|
#define GUARD_2B56918289975E8AA8711D6E080ED4B9
|
||||||
|
|
||||||
#include "shader.h"
|
#include "shader.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include "vec2f.h"
|
||||||
|
#include "vec4f.h"
|
||||||
|
#include "vertex_buffer.h"
|
||||||
|
|
||||||
struct sw_renderer;
|
struct sw_renderer;
|
||||||
|
|
||||||
struct sw_renderer2d {
|
struct sw_renderer2d {
|
||||||
struct sw_shaderprogram shader;
|
struct sw_shaderprogram shader;
|
||||||
struct sw_renderer *renderer;
|
struct sw_renderer *renderer;
|
||||||
|
struct sw_vertex_buffer *vertex_buffer;
|
||||||
|
struct sw_vec4f color;
|
||||||
|
u32 vao, vbo;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sw_renderer2d *sw_renderer2d_create();
|
struct sw_renderer2d *sw_renderer2d_create();
|
||||||
|
@ -22,6 +29,17 @@ struct sw_renderer2d *sw_renderer2d_create();
|
||||||
- draw "sprite" (quad of same size as texture)
|
- draw "sprite" (quad of same size as texture)
|
||||||
- draw line
|
- draw line
|
||||||
- transform matrix stack
|
- transform matrix stack
|
||||||
|
- coordinate style, match pixel coordinates, vs 1.f full vertical range
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
void sw_renderer2d_draw_quad(
|
||||||
|
struct sw_renderer2d *renderer,
|
||||||
|
struct sw_vec2f a,
|
||||||
|
struct sw_vec2f b,
|
||||||
|
struct sw_vec2f c,
|
||||||
|
struct sw_vec2f d
|
||||||
|
);
|
||||||
|
|
||||||
|
void sw_renderer2d_set_color(struct sw_renderer2d *ren, struct sw_vec4f color);
|
||||||
|
|
||||||
#endif /* GUARD_2B56918289975E8AA8711D6E080ED4B9 */
|
#endif /* GUARD_2B56918289975E8AA8711D6E080ED4B9 */
|
||||||
|
|
|
@ -11,10 +11,14 @@ struct sw_vertex_buffer {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sw_vertex_buffer *sw_vertex_buffer_create(u32 elem_size);
|
struct sw_vertex_buffer *sw_vertex_buffer_create(u32 elem_size);
|
||||||
|
|
||||||
void sw_vertex_buffer_destroy(struct sw_vertex_buffer *vb);
|
void sw_vertex_buffer_destroy(struct sw_vertex_buffer *vb);
|
||||||
|
|
||||||
/* copies elem data */
|
/* copies elem data */
|
||||||
void sw_vertex_buffer_add(struct sw_vertex_buffer *vb, void *elem);
|
void sw_vertex_buffer_add(struct sw_vertex_buffer *vb, void *elem);
|
||||||
|
|
||||||
void sw_vertex_buffer_clear(struct sw_vertex_buffer *vb);
|
void sw_vertex_buffer_clear(struct sw_vertex_buffer *vb);
|
||||||
|
|
||||||
|
void sw_vertex_buffer_send(struct sw_vertex_buffer *vb);
|
||||||
|
|
||||||
#endif /* GUARD_B3E8DB670A75ACCB1082192FB0485037 */
|
#endif /* GUARD_B3E8DB670A75ACCB1082192FB0485037 */
|
||||||
|
|
20
src/gsa.c
20
src/gsa.c
|
@ -10,7 +10,9 @@
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
#include <gl/gl.h>
|
#include <gl/gl.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define GSA_NOMAIN
|
#define GSA_NOMAIN
|
||||||
|
|
||||||
#include "gsa.h"
|
#include "gsa.h"
|
||||||
#include "gsa_input.h"
|
#include "gsa_input.h"
|
||||||
|
|
||||||
|
@ -34,6 +36,7 @@ static u32 tex;
|
||||||
#define GSA_LOOP_STACK_SIZE 16
|
#define GSA_LOOP_STACK_SIZE 16
|
||||||
|
|
||||||
static bool (*loop_stack[GSA_LOOP_STACK_SIZE])();
|
static bool (*loop_stack[GSA_LOOP_STACK_SIZE])();
|
||||||
|
|
||||||
static i8 loop_stack_i;
|
static i8 loop_stack_i;
|
||||||
|
|
||||||
static struct sw_vertex_buffer *vertex_buffer;
|
static struct sw_vertex_buffer *vertex_buffer;
|
||||||
|
@ -70,7 +73,12 @@ int gsa_main(int argc, char *argv[]) {
|
||||||
frag_data = sw_skip_get_string(sw_skip_self, "gsa_frag.glsl");
|
frag_data = sw_skip_get_string(sw_skip_self, "gsa_frag.glsl");
|
||||||
vert_data = sw_skip_get_string(sw_skip_self, "gsa_vert.glsl");
|
vert_data = sw_skip_get_string(sw_skip_self, "gsa_vert.glsl");
|
||||||
program =
|
program =
|
||||||
sw_shaderprogram_create((u8 *)vert_data, 0, (u8 *)frag_data, 0, false);
|
sw_shaderprogram_create((u8 *) vert_data,
|
||||||
|
0,
|
||||||
|
(u8 *) frag_data,
|
||||||
|
0,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
memcpy(palette, gfx->palette, sizeof(gfx->palette));
|
memcpy(palette, gfx->palette, sizeof(gfx->palette));
|
||||||
glGenTextures(1, &tex);
|
glGenTextures(1, &tex);
|
||||||
|
@ -113,7 +121,8 @@ int gsa_main(int argc, char *argv[]) {
|
||||||
(void *) (2 * sizeof(float))
|
(void *) (2 * sizeof(float))
|
||||||
);
|
);
|
||||||
glEnableVertexAttribArray(glGetAttribLocation(program._program, "pos"));
|
glEnableVertexAttribArray(glGetAttribLocation(program._program, "pos"));
|
||||||
glEnableVertexAttribArray(glGetAttribLocation(program._program, "tex_coord")
|
glEnableVertexAttribArray(
|
||||||
|
glGetAttribLocation(program._program, "tex_coord")
|
||||||
);
|
);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
|
|
||||||
|
@ -246,12 +255,7 @@ static void gsa_tick() {
|
||||||
glUniform4fv(
|
glUniform4fv(
|
||||||
glGetUniformLocation(program._program, "palette"), 256, palette_gl
|
glGetUniformLocation(program._program, "palette"), 256, palette_gl
|
||||||
);
|
);
|
||||||
glBufferData(
|
sw_vertex_buffer_send(vertex_buffer);
|
||||||
GL_ARRAY_BUFFER,
|
|
||||||
(i64)(sizeof(struct render_vert) * vertex_buffer->elem_count),
|
|
||||||
vertex_buffer->data,
|
|
||||||
GL_DYNAMIC_DRAW
|
|
||||||
);
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, (i32) vertex_buffer->elem_count);
|
glDrawArrays(GL_TRIANGLES, 0, (i32) vertex_buffer->elem_count);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
/* glEnd(); */
|
/* glEnd(); */
|
||||||
|
|
|
@ -8,10 +8,12 @@
|
||||||
#include "gl.h"
|
#include "gl.h"
|
||||||
|
|
||||||
struct vert {
|
struct vert {
|
||||||
f32 x, y, z;
|
struct sw_vec2f pos;
|
||||||
|
struct sw_vec4f color;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void r_enter(struct sw_window *win, void *data);
|
static void r_enter(struct sw_window *win, void *data);
|
||||||
|
|
||||||
static void r_exit(struct sw_window *win, void *data);
|
static void r_exit(struct sw_window *win, void *data);
|
||||||
|
|
||||||
struct sw_renderer2d *sw_renderer2d_create() {
|
struct sw_renderer2d *sw_renderer2d_create() {
|
||||||
|
@ -25,28 +27,84 @@ struct sw_renderer2d *sw_renderer2d_create() {
|
||||||
vert = sw_skip_get_string(sw_skip_self, "renderer2d_vert.glsl");
|
vert = sw_skip_get_string(sw_skip_self, "renderer2d_vert.glsl");
|
||||||
|
|
||||||
ren->shader = sw_shaderprogram_create((u8 *) vert, 0, (u8 *) frag, 0, 0);
|
ren->shader = sw_shaderprogram_create((u8 *) vert, 0, (u8 *) frag, 0, 0);
|
||||||
|
ren->vertex_buffer = sw_vertex_buffer_create(sizeof(struct vert));
|
||||||
|
ren->color = sw_vec4f(1.f, 1.f, 1.f, 1.f);
|
||||||
|
|
||||||
|
glGenVertexArrays(1, &ren->vao);
|
||||||
|
glBindVertexArray(ren->vao);
|
||||||
|
|
||||||
|
glGenBuffers(1, &ren->vbo);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, ren->vbo);
|
||||||
|
|
||||||
|
/* todo: vertex attrib thingies */
|
||||||
|
glVertexAttribPointer(
|
||||||
|
0, 2, GL_FLOAT, GL_FALSE, sizeof(struct vert), 0
|
||||||
|
);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
|
glBindVertexArray(0);
|
||||||
|
|
||||||
return ren;
|
return ren;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sw_renderer2d_draw_quad(
|
||||||
|
struct sw_renderer2d *ren,
|
||||||
|
struct sw_vec2f a,
|
||||||
|
struct sw_vec2f b,
|
||||||
|
struct sw_vec2f c,
|
||||||
|
struct sw_vec2f d
|
||||||
|
) {
|
||||||
|
struct vert vert;
|
||||||
|
|
||||||
|
vert.color = ren->color;
|
||||||
|
|
||||||
|
vert.pos = a;
|
||||||
|
sw_vertex_buffer_add(ren->vertex_buffer, &vert);
|
||||||
|
|
||||||
|
vert.pos = b;
|
||||||
|
sw_vertex_buffer_add(ren->vertex_buffer, &vert);
|
||||||
|
|
||||||
|
vert.pos = c;
|
||||||
|
sw_vertex_buffer_add(ren->vertex_buffer, &vert);
|
||||||
|
|
||||||
|
vert.pos = b;
|
||||||
|
sw_vertex_buffer_add(ren->vertex_buffer, &vert);
|
||||||
|
|
||||||
|
vert.pos = d;
|
||||||
|
sw_vertex_buffer_add(ren->vertex_buffer, &vert);
|
||||||
|
|
||||||
|
vert.pos = c;
|
||||||
|
sw_vertex_buffer_add(ren->vertex_buffer, &vert);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sw_renderer2d_set_color(struct sw_renderer2d *ren, struct sw_vec4f color) {
|
||||||
|
ren->color = color;
|
||||||
|
}
|
||||||
|
|
||||||
static void r_enter(struct sw_window *win, void *data) {
|
static void r_enter(struct sw_window *win, void *data) {
|
||||||
struct sw_renderer2d *ren;
|
struct sw_renderer2d *ren;
|
||||||
|
|
||||||
(void) win;
|
(void) win;
|
||||||
|
|
||||||
ren = data;
|
ren = data;
|
||||||
|
sw_vertex_buffer_clear(ren->vertex_buffer);
|
||||||
|
|
||||||
|
sw_renderer2d_draw_quad(
|
||||||
|
ren,
|
||||||
|
sw_vec2f(-0.5f, -0.5f),
|
||||||
|
sw_vec2f(0.5f, -0.5f),
|
||||||
|
sw_vec2f(-0.5f, 0.5f),
|
||||||
|
sw_vec2f(0.5f, 0.5f));
|
||||||
|
|
||||||
|
glBindVertexArray(ren->vao);
|
||||||
sw_shaderprogram_use(ren->shader);
|
sw_shaderprogram_use(ren->shader);
|
||||||
|
sw_vertex_buffer_send(ren->vertex_buffer);
|
||||||
glBegin(GL_TRIANGLES);
|
glDrawArrays(GL_TRIANGLES, 0, (i32) ren->vertex_buffer->elem_count);
|
||||||
|
glBindVertexArray(0);
|
||||||
glVertex2i(0, 0);
|
|
||||||
glVertex2i(1, 0);
|
|
||||||
glVertex2i(0, 1);
|
|
||||||
|
|
||||||
glEnd();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void r_exit(struct sw_window *win, void *data) {
|
static void r_exit(struct sw_window *win, void *data) {
|
||||||
(void) win;
|
(void) win;
|
||||||
(void) data;
|
(void) data;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#version 460
|
#version 460
|
||||||
|
|
||||||
layout(location = 0) in vec3 pos;
|
layout(location = 0) in vec2 pos;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = vec4(pos, 1.0);
|
gl_Position = vec4(pos, 0.0, 1.0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "vertex_buffer.h"
|
#include "vertex_buffer.h"
|
||||||
|
|
||||||
#include "skunkworks.h"
|
#include "skunkworks.h"
|
||||||
|
#include "gl.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -41,3 +42,12 @@ void sw_vertex_buffer_clear(struct sw_vertex_buffer *vb) {
|
||||||
/* keep capacity */
|
/* keep capacity */
|
||||||
vb->elem_count = 0;
|
vb->elem_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sw_vertex_buffer_send(struct sw_vertex_buffer *vb) {
|
||||||
|
glBufferData(
|
||||||
|
GL_ARRAY_BUFFER,
|
||||||
|
vb->elem_size * vb->elem_count,
|
||||||
|
vb->data,
|
||||||
|
GL_DYNAMIC_DRAW
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
prefix=C:/Program Files (x86)/glew
|
prefix=C:/Program Files (x86)/skunkworks_c
|
||||||
exec_prefix=${prefix}
|
exec_prefix=${prefix}
|
||||||
libdir=C:/Program Files (x86)/glew/lib
|
libdir=C:/Program Files (x86)/skunkworks_c/lib
|
||||||
includedir=${prefix}/include
|
includedir=${prefix}/include
|
||||||
|
|
||||||
Name: glew
|
Name: glew
|
||||||
|
|
Loading…
Reference in New Issue