changed the pipeline to use 16 bit int as coords
thank you renderdoc for making me feel less stupid
This commit is contained in:
parent
712ce50631
commit
24bc2c67bc
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ build/*
|
||||
perf.data*
|
||||
*.rdc
|
||||
test_renderer
|
||||
resources/shaders/compiled/**
|
||||
|
Binary file not shown.
Binary file not shown.
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user