Some code cleanup following https://github.com/emilk/egui/pull/888
This commit is contained in:
parent
008a971e73
commit
b5cb2b2c0d
8 changed files with 54 additions and 44 deletions
|
@ -37,7 +37,7 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui_w
|
|||
* [EmbersArc](https://github.com/EmbersArc): ([#766](https://github.com/emilk/egui/pull/766)).
|
||||
* [mankinskin](https://github.com/mankinskin) ([#543](https://github.com/emilk/egui/pull/543))
|
||||
* [sumibi-yakitori](https://github.com/sumibi-yakitori) ([#830](https://github.com/emilk/egui/pull/830))
|
||||
* [t18b219k](https://github.com/t18b219k): ([#868](https://github.com/emilk/egui/pull/868)).
|
||||
* [t18b219k](https://github.com/t18b219k): ([#868](https://github.com/emilk/egui/pull/868), [#888](https://github.com/emilk/egui/pull/888)).
|
||||
|
||||
|
||||
## 0.15.0 - 2021-10-24 - Syntax highlighting and hscroll
|
||||
|
|
|
@ -185,10 +185,10 @@ impl VAO {
|
|||
}
|
||||
|
||||
/// If returned true no need to emulate vao
|
||||
pub(crate) unsafe fn support_vao(gl: &glow::Context) -> bool {
|
||||
pub(crate) fn supports_vao(gl: &glow::Context) -> bool {
|
||||
let web_sig = "WebGL ";
|
||||
let es_sig = "OpenGL ES ";
|
||||
let version_string = gl.get_parameter_string(glow::VERSION);
|
||||
let version_string = unsafe { gl.get_parameter_string(glow::VERSION) };
|
||||
if let Some(pos) = version_string.rfind(web_sig) {
|
||||
let version_str = &version_string[pos + web_sig.len()..];
|
||||
glow_debug_print(format!(
|
||||
|
|
|
@ -61,9 +61,10 @@ impl Painter {
|
|||
/// Create painter.
|
||||
///
|
||||
/// Set `pp_fb_extent` to the framebuffer size to enable `sRGB` support on OpenGL ES and WebGL.
|
||||
/// Set `shader_prefix` if you want to turn on shader workaround e.g. `"#define EPIPHANY_WORKAROUND\n"`.
|
||||
///
|
||||
/// this fix [Everything is super dark in epiphany](https://github.com/emilk/egui/issues/794)
|
||||
/// Set `shader_prefix` if you want to turn on shader workaround e.g. `"#define APPLY_BRIGHTENING_GAMMA\n"`
|
||||
/// (see <https://github.com/emilk/egui/issues/794>).
|
||||
///
|
||||
/// # Errors
|
||||
/// will return `Err` below cases
|
||||
/// * failed to compile shader
|
||||
|
@ -74,7 +75,7 @@ impl Painter {
|
|||
pp_fb_extent: Option<[i32; 2]>,
|
||||
shader_prefix: &str,
|
||||
) -> Result<Painter, String> {
|
||||
let support_vao = unsafe { crate::misc_util::support_vao(gl) };
|
||||
let support_vao = crate::misc_util::supports_vao(gl);
|
||||
let shader_version = ShaderVersion::get(gl);
|
||||
let is_webgl_1 = shader_version == ShaderVersion::Es100;
|
||||
let header = shader_version.version();
|
||||
|
|
|
@ -18,9 +18,9 @@ vec4 srgba_from_linear(vec4 rgba) {
|
|||
void main() {
|
||||
gl_FragColor = texture2D(u_sampler, v_tc);
|
||||
|
||||
gl_FragColor = srgba_from_linear(gl_FragColor) / 255.;
|
||||
#ifdef WEBKITGTK_WORKAROUND
|
||||
//this is better than double apply
|
||||
gl_FragColor = srgba_from_linear(gl_FragColor) / 255.0;
|
||||
|
||||
#ifdef APPLY_BRIGHTENING_GAMMA
|
||||
gl_FragColor = vec4(pow(gl_FragColor.rgb, vec3(1.0/2.2)), gl_FragColor.a);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ All notable changes to the `egui_web` integration will be noted in this file.
|
|||
|
||||
|
||||
## Unreleased
|
||||
* Fix [dark rendering in epiphany](https://github.com/emilk/egui/issues/794) for WebGL1 and glow based painter ([#888](https://github.com/emilk/egui/pull/888/)).
|
||||
* Fix [dark rendering in WebKitGTK](https://github.com/emilk/egui/issues/794) ([#888](https://github.com/emilk/egui/pull/888/)).
|
||||
* Add feature `glow` to switch to a [`glow`](https://github.com/grovesNL/glow) based painter ([#868](https://github.com/emilk/egui/pull/868)).
|
||||
|
||||
## 0.15.0 - 2021-10-24
|
||||
|
|
|
@ -19,29 +19,17 @@ pub(crate) struct WrappedGlowPainter {
|
|||
impl WrappedGlowPainter {
|
||||
pub fn new(canvas_id: &str) -> Self {
|
||||
let canvas = canvas_element_or_die(canvas_id);
|
||||
// detect WebKitGTK
|
||||
//WebKitGTK currently support only webgl,so request webgl context.
|
||||
// WebKitGTK use WebKit default unmasked vendor and renderer
|
||||
// but safari use same vendor and renderer
|
||||
// so exclude "Mac OS X" user-agent.
|
||||
let gl = canvas
|
||||
.get_context("webgl")
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.dyn_into::<WebGlRenderingContext>()
|
||||
.unwrap();
|
||||
let user_agent = web_sys::window().unwrap().navigator().user_agent().unwrap();
|
||||
let webkit_gtk_wr = if !user_agent.contains("Mac OS X")
|
||||
&& crate::webgl1::detect_safari_and_webkit_gtk(&gl)
|
||||
{
|
||||
"#define WEBKITGTK_WORKAROUND"
|
||||
|
||||
let shader_prefix = if requires_brightening(&canvas) {
|
||||
crate::console_log("Enabling webkitGTK brightening workaround");
|
||||
"#define APPLY_BRIGHTENING_GAMMA"
|
||||
} else {
|
||||
""
|
||||
};
|
||||
|
||||
let gl_ctx = init_glow_context_from_canvas(&canvas);
|
||||
let dimension = [canvas.width() as i32, canvas.height() as i32];
|
||||
let painter = egui_glow::Painter::new(&gl_ctx, Some(dimension), webkit_gtk_wr)
|
||||
let painter = egui_glow::Painter::new(&gl_ctx, Some(dimension), shader_prefix)
|
||||
.map_err(|error| {
|
||||
console_error(format!(
|
||||
"some error occurred in initializing glow painter\n {}",
|
||||
|
@ -58,6 +46,26 @@ impl WrappedGlowPainter {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn requires_brightening(canvas: &web_sys::HtmlCanvasElement) -> bool {
|
||||
// See https://github.com/emilk/egui/issues/794
|
||||
|
||||
// detect WebKitGTK
|
||||
|
||||
// WebKitGTK currently support only webgl,so request webgl context.
|
||||
// WebKitGTK use WebKit default unmasked vendor and renderer
|
||||
// but safari use same vendor and renderer
|
||||
// so exclude "Mac OS X" user-agent.
|
||||
let gl = canvas
|
||||
.get_context("webgl")
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.dyn_into::<WebGlRenderingContext>()
|
||||
.unwrap();
|
||||
let user_agent = web_sys::window().unwrap().navigator().user_agent().unwrap();
|
||||
crate::webgl1::is_safari_and_webkit_gtk(&gl) && !user_agent.contains("Mac OS X")
|
||||
}
|
||||
|
||||
impl crate::Painter for WrappedGlowPainter {
|
||||
fn as_tex_allocator(&mut self) -> &mut dyn TextureAllocator {
|
||||
&mut self.painter
|
||||
|
|
|
@ -18,9 +18,9 @@ vec4 srgba_from_linear(vec4 rgba) {
|
|||
void main() {
|
||||
gl_FragColor = texture2D(u_sampler, v_tc);
|
||||
|
||||
gl_FragColor = srgba_from_linear(gl_FragColor) / 255.;
|
||||
#ifdef WEBKITGTK_WORKAROUND
|
||||
//this is better than double apply
|
||||
gl_FragColor = srgba_from_linear(gl_FragColor) / 255.0;
|
||||
|
||||
#ifdef APPLY_BRIGHTENING_GAMMA
|
||||
gl_FragColor = vec4(pow(gl_FragColor.rgb, vec3(1.0/2.2)), gl_FragColor.a);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ use {
|
|||
},
|
||||
};
|
||||
|
||||
use crate::console_log;
|
||||
use egui::{
|
||||
emath::vec2,
|
||||
epaint::{Color32, Texture},
|
||||
|
@ -556,6 +555,13 @@ struct PostProcess {
|
|||
program: WebGlProgram,
|
||||
}
|
||||
|
||||
fn requires_brightening(gl: &web_sys::WebGlRenderingContext) -> bool {
|
||||
// See https://github.com/emilk/egui/issues/794
|
||||
|
||||
let user_agent = web_sys::window().unwrap().navigator().user_agent().unwrap();
|
||||
crate::webgl1::is_safari_and_webkit_gtk(gl) && !user_agent.contains("Mac OS X")
|
||||
}
|
||||
|
||||
impl PostProcess {
|
||||
fn new(gl: Gl, width: i32, height: i32) -> Result<PostProcess, JsValue> {
|
||||
let fbo = gl
|
||||
|
@ -592,14 +598,10 @@ impl PostProcess {
|
|||
|
||||
gl.bind_texture(Gl::TEXTURE_2D, None);
|
||||
gl.bind_framebuffer(Gl::FRAMEBUFFER, None);
|
||||
// detect WebKitGTK
|
||||
// WebKitGTK use WebKit default unmasked vendor and renderer
|
||||
// but safari use same vendor and renderer
|
||||
// so exclude "Mac OS X " user-agent.
|
||||
let user_agent = web_sys::window().unwrap().navigator().user_agent().unwrap();
|
||||
let webkit_gtk_wr = if !user_agent.contains("Mac OS X") && detect_safari_and_webkit_gtk(&gl)
|
||||
{
|
||||
"#define WEBKITGTK_WORKAROUND"
|
||||
|
||||
let shader_prefix = if requires_brightening(&gl) {
|
||||
crate::console_log("Enabling webkitGTK brightening workaround");
|
||||
"#define APPLY_BRIGHTENING_GAMMA"
|
||||
} else {
|
||||
""
|
||||
};
|
||||
|
@ -614,7 +616,7 @@ impl PostProcess {
|
|||
Gl::FRAGMENT_SHADER,
|
||||
&format!(
|
||||
"{}{}",
|
||||
webkit_gtk_wr,
|
||||
shader_prefix,
|
||||
include_str!("shader/post_fragment_100es.glsl")
|
||||
),
|
||||
)?;
|
||||
|
@ -774,7 +776,7 @@ fn link_program<'a, T: IntoIterator<Item = &'a WebGlShader>>(
|
|||
/// If we detect safari or webkitGTK returns true.
|
||||
///
|
||||
/// This function used to avoid displaying linear color with `sRGB` supported systems.
|
||||
pub(crate) fn detect_safari_and_webkit_gtk(gl: &web_sys::WebGlRenderingContext) -> bool {
|
||||
pub(crate) fn is_safari_and_webkit_gtk(gl: &web_sys::WebGlRenderingContext) -> bool {
|
||||
if gl
|
||||
.get_extension("WEBGL_debug_renderer_info")
|
||||
.unwrap()
|
||||
|
@ -784,7 +786,6 @@ pub(crate) fn detect_safari_and_webkit_gtk(gl: &web_sys::WebGlRenderingContext)
|
|||
.get_parameter(WebglDebugRendererInfo::UNMASKED_RENDERER_WEBGL)
|
||||
.unwrap();
|
||||
if renderer.as_string().unwrap().contains("Apple") {
|
||||
console_log("Enabling webkitGTK workaround");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue