Skip to content
Permalink
Browse files

renderer: *slightly* more consistent coordinate system; it's still a …

…god-damn mess though
  • Loading branch information...
Akaricchi committed May 12, 2019
1 parent 4c0359e commit bfb3941cf3c0da95f477f253d9d4b5721100eb9e
@@ -31,7 +31,11 @@ float min3(vec3 c) {
vec2 uv_to_region(vec4 region, vec2 uv) {
return vec2(
mix(region.x, region.x + region.z, uv.x),
#ifdef NATIVE_ORIGIN_BOTTOMLEFT
1.0 - mix(region.y, region.y + region.w, 1.0 - uv.y)
#else
mix(region.y, region.y + region.w, uv.y)
#endif
);
}

@@ -321,6 +321,26 @@ static void gl33_apply_capability(RendererCapability cap, bool value) {
}
}

static void transform_viewport_origin(Framebuffer *fb, FloatRect *vp) {
int fb_height = 0;

if(fb == NULL) {
SDL_Window *win = SDL_GL_GetCurrentWindow();
assume(win != NULL);
SDL_GL_GetDrawableSize(win, NULL, &fb_height);
} else {
for(FramebufferAttachment a = FRAMEBUFFER_ATTACH_COLOR0; a < FRAMEBUFFER_MAX_ATTACHMENTS; ++a) {
if(fb->attachments[a] != NULL) {
fb_height = fb->attachments[a]->params.height;
break;
}
}
}

assert(fb_height > 0);
vp->y = fb_height - vp->y - vp->h;
}

static inline FloatRect* get_framebuffer_viewport(Framebuffer *fb) {
if(fb == NULL) {
return &R.viewport.default_framebuffer;
@@ -964,11 +984,13 @@ static Framebuffer *gl33_framebuffer_current(void) {
}

static void gl33_framebuffer_viewport(Framebuffer *fb, FloatRect vp) {
transform_viewport_origin(fb, &vp);
memcpy(get_framebuffer_viewport(fb), &vp, sizeof(vp));
}

static void gl33_framebuffer_viewport_current(Framebuffer *fb, FloatRect *out_rect) {
*out_rect = *get_framebuffer_viewport(fb);
transform_viewport_origin(fb, out_rect);
}

static void gl33_shader(ShaderProgram *prog) {
@@ -352,7 +352,7 @@ void gl33_texture_fill_region(Texture *tex, uint mipmap, uint x, uint y, const P

glTexSubImage2D(
GL_TEXTURE_2D, mipmap,
x, y, pix.width, pix.height,
x, tex->params.height - y - pix.height, pix.width, pix.height,
fmt->gl_fmt,
fmt->gl_type,
pix.data.untyped
@@ -133,11 +133,6 @@ void* load_sprite_end(void *opaque, const char *path, uint flags) {
}
}

// FIXME: is there a better way?
if(r_supports(RFEAT_TEXTURE_BOTTOMLEFT_ORIGIN)) {
spr->tex_area.y = tex_h_flt - spr->tex_area.y - spr->tex_area.h;
}

free(basename);
return spr;
}
@@ -487,6 +487,11 @@ void begin_draw_texture(FloatRect dest, FloatRect frag, Texture *tex) {
float s = frag.w/tw;
float t = frag.h/th;

if(r_supports(RFEAT_TEXTURE_BOTTOMLEFT_ORIGIN)) {
// FIXME: please somehow abstract this shit away!
frag.y = th - frag.y - frag.h;
}

if(s != 1 || t != 1 || frag.x || frag.y) {
draw_texture_state.texture_matrix_tainted = true;

0 comments on commit bfb3941

Please sign in to comment.
You can’t perform that action at this time.