Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gles: unflip the rendering #180

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
}
Loading