diff --git a/.gitignore b/.gitignore index 042d5c7..eb64e0d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ build/* perf.data* *.rdc test_renderer +resources/shaders/compiled/** diff --git a/resources/shaders/compiled/rect.frag.spv b/resources/shaders/compiled/rect.frag.spv deleted file mode 100644 index 3cc8f05..0000000 Binary files a/resources/shaders/compiled/rect.frag.spv and /dev/null differ diff --git a/resources/shaders/compiled/rect.vert.spv b/resources/shaders/compiled/rect.vert.spv deleted file mode 100644 index 439d76d..0000000 Binary files a/resources/shaders/compiled/rect.vert.spv and /dev/null differ diff --git a/resources/shaders/source/rect.vert.glsl b/resources/shaders/source/rect.vert.glsl index abe367a..0fab590 100644 --- a/resources/shaders/source/rect.vert.glsl +++ b/resources/shaders/source/rect.vert.glsl @@ -5,21 +5,24 @@ layout(set = 1, binding = 0) uniform Viewport { ivec2 off; }; -layout(location = 0) in vec2 position; -layout(location = 1) in vec2 uv; +layout(location = 0) in ivec2 position; +layout(location = 1) in ivec2 uv; layout(location = 2) in ivec4 color; layout(location = 0) out vec4 col; void main() { - //vec2 shift = vec2(0); + // per vertex shift vec2 shift; shift.x = float(off.x) / view.x; shift.y = -(float(off.y) / view.y); - vec2 pos = position + shift; + // vertex position + vec2 pos; + pos.x = float(position.x)*2.0 / view.x - 1.0; + pos.y = -(float(position.y)*2.0 / view.y - 1.0); - gl_Position = vec4(pos.x, pos.y, 0.0, 1.0); + gl_Position = vec4(pos+shift, 0.0, 1.0); col = vec4(color) / 255.0; } diff --git a/src/renderer.c3 b/src/renderer.c3 index 99f10a5..a62c9c6 100644 --- a/src/renderer.c3 +++ b/src/renderer.c3 @@ -51,10 +51,10 @@ struct Renderer { // how each vertex is represented in the gpu struct Vertex @packed { struct pos { - float x, y; + short x, y; } struct uv { - float u, v; + short u, v; } struct col { // FIXME: this is shit union { @@ -321,13 +321,13 @@ fn void Renderer.create_pipeline(&self, String shader_name, PipelineType type) { // at location zero there is the position of the vertex .location = 0, .buffer_slot = 0, // only one buffer so always slot zero - .format = GPU_VERTEXELEMENTFORMAT_FLOAT2, + .format = GPU_VERTEXELEMENTFORMAT_SHORT2, .offset = Vertex.pos.offsetof, }, { // at location one there are the uv coordinates .location = 1, .buffer_slot = 0, - .format = GPU_VERTEXELEMENTFORMAT_FLOAT2, + .format = GPU_VERTEXELEMENTFORMAT_SHORT2, .offset = Vertex.uv.offsetof, }, { // at location two there is the color @@ -500,12 +500,6 @@ fn void Renderer.update_texture(&self, String name, char[] pixels, ushort width, } -macro void Vertex.norm(&p, float w, float h) -{ - p.pos.x = p.pos.x * 2.0 / w - 1.0; - p.pos.y = -(p.pos.y * 2.0 / h - 1.0); -} - // an highly inefficient way to draw a single quad, no batching, per-quad upload fn void Renderer.draw_rect(&self, short x, short y, short w, short h, uint color, String shader_name) { @@ -541,15 +535,11 @@ fn void Renderer.draw_rect(&self, short x, short y, short w, short h, uint color * +-------------+ * v2 v3 */ - quad.vertices.v1 = {.pos = {.x = x, .y = y}, .col.u = color}; - quad.vertices.v2 = {.pos = {.x = x, .y = (float)y+h}, .col.u = color}; - quad.vertices.v3 = {.pos = {.x = (float)x+w, .y = (float)y+h}, .col.u = color}; - quad.vertices.v4 = {.pos = {.x = (float)x+w, .y = y}, .col.u = color}; + quad.vertices.v1 = {.pos = {.x = x, .y = y}, .col.u = color}; + quad.vertices.v2 = {.pos = {.x = x, .y = y+h}, .col.u = color}; + quad.vertices.v3 = {.pos = {.x = x+w, .y = y+h}, .col.u = color}; + quad.vertices.v4 = {.pos = {.x = x+w, .y = y}, .col.u = color}; - quad.vertices.v1.norm(640.0, 480.0); - quad.vertices.v2.norm(640.0, 480.0); - quad.vertices.v3.norm(640.0, 480.0); - quad.vertices.v4.norm(640.0, 480.0); // triangle 1 quad.indices.i1 = 0; // v1