Skip to content

Commit

Permalink
gles: unflip the rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Sep 27, 2024
1 parent a036f81 commit e522753
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 44 deletions.
22 changes: 1 addition & 21 deletions blade-graphics/src/gles/egl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,28 +543,8 @@ impl ContextInner {
.swap_interval(self.egl.display, sc.swap_interval)
.unwrap();

let gl = &self.glow;
unsafe {
gl.disable(glow::SCISSOR_TEST);
gl.color_mask(true, true, true, true);
gl.bind_framebuffer(glow::DRAW_FRAMEBUFFER, None);
gl.bind_framebuffer(glow::READ_FRAMEBUFFER, Some(wsi.framebuf));
// Note the Y-flipping here. GL's presentation is not flipped,
// but main rendering is. Therefore, we Y-flip the output positions
// in the shader, and also this blit.
gl.blit_framebuffer(
0,
sc.extent.height as i32,
sc.extent.width as i32,
0,
0,
0,
sc.extent.width as i32,
sc.extent.height as i32,
glow::COLOR_BUFFER_BIT,
glow::NEAREST,
);
gl.bind_framebuffer(glow::READ_FRAMEBUFFER, None);
super::present_blit(&self.glow, wsi.framebuf, sc.extent);
}

self.egl
Expand Down
22 changes: 22 additions & 0 deletions blade-graphics/src/gles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,3 +560,25 @@ fn map_compare_func(fun: crate::CompareFunction) -> u32 {
Cf::Always => glow::ALWAYS,
}
}

unsafe fn present_blit(gl: &glow::Context, source: glow::Framebuffer, size: crate::Extent) {
use glow::HasContext as _;

gl.disable(glow::SCISSOR_TEST);
gl.color_mask(true, true, true, true);
gl.bind_framebuffer(glow::DRAW_FRAMEBUFFER, None);
gl.bind_framebuffer(glow::READ_FRAMEBUFFER, Some(source));
gl.blit_framebuffer(
0,
0,
size.width as i32,
size.height as i32,
0,
0,
size.width as i32,
size.height as i32,
glow::COLOR_BUFFER_BIT,
glow::NEAREST,
);
gl.bind_framebuffer(glow::READ_FRAMEBUFFER, None);
}
2 changes: 1 addition & 1 deletion blade-graphics/src/gles/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl super::Context {
version: if force_explicit_bindings { 320 } else { 300 },
is_webgl: cfg!(target_arch = "wasm32"),
},
writer_flags: extra_flags | glsl::WriterFlags::ADJUST_COORDINATE_SPACE,
writer_flags: extra_flags,
binding_map: Default::default(),
zero_initialize_workgroup_memory: false,
};
Expand Down
23 changes: 1 addition & 22 deletions blade-graphics/src/gles/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,29 +142,8 @@ impl Context {

pub(super) fn present(&self) {
let sc = &self.swapchain;
let size = sc.extent.get();
let gl = &self.glow;
unsafe {
gl.disable(glow::SCISSOR_TEST);
gl.color_mask(true, true, true, true);
gl.bind_framebuffer(glow::DRAW_FRAMEBUFFER, None);
gl.bind_framebuffer(glow::READ_FRAMEBUFFER, Some(sc.framebuf));
// Note the Y-flipping here. GL's presentation is not flipped,
// but main rendering is. Therefore, we Y-flip the output positions
// in the shader, and also this blit.
gl.blit_framebuffer(
0,
size.height as i32,
size.width as i32,
0,
0,
0,
size.width as i32,
size.height as i32,
glow::COLOR_BUFFER_BIT,
glow::NEAREST,
);
gl.bind_framebuffer(glow::READ_FRAMEBUFFER, None);
super::present_blit(&self.glow, sc.framebuf, sc.extent.get());
}
}
}

0 comments on commit e522753

Please sign in to comment.