Disable custom 3D painting example in the egui demo app for Es100 (#1945)
Closes https://github.com/emilk/egui/issues/1944
This commit is contained in:
parent
97ce103209
commit
bd5250f85d
|
|
@ -1259,6 +1259,7 @@ dependencies = [
|
||||||
"poll-promise",
|
"poll-promise",
|
||||||
"pollster",
|
"pollster",
|
||||||
"serde",
|
"serde",
|
||||||
|
"tracing",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
"tracing-wasm",
|
"tracing-wasm",
|
||||||
"wgpu",
|
"wgpu",
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ screen_reader = [
|
||||||
"tts",
|
"tts",
|
||||||
]
|
]
|
||||||
|
|
||||||
## Use [`wgpu`](https://docs.rs/wgpu) for painting (via [`egui_wgpu`](https://github.com/emilk/egui/tree/master/crates/egui_wgpu)).
|
## Use [`wgpu`](https://docs.rs/wgpu) for painting (via [`egui-wgpu`](https://github.com/emilk/egui/tree/master/crates/egui-wgpu)).
|
||||||
## This overrides the `glow` feature.
|
## This overrides the `glow` feature.
|
||||||
wgpu = ["dep:wgpu", "egui-wgpu"]
|
wgpu = ["dep:wgpu", "egui-wgpu"]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ chrono = { version = "0.4", features = ["js-sys", "wasmbind"] }
|
||||||
eframe = { version = "0.19.0", path = "../eframe", default-features = false }
|
eframe = { version = "0.19.0", path = "../eframe", default-features = false }
|
||||||
egui = { version = "0.19.0", path = "../egui", features = ["extra_debug_asserts"] }
|
egui = { version = "0.19.0", path = "../egui", features = ["extra_debug_asserts"] }
|
||||||
egui_demo_lib = { version = "0.19.0", path = "../egui_demo_lib", features = ["chrono"] }
|
egui_demo_lib = { version = "0.19.0", path = "../egui_demo_lib", features = ["chrono"] }
|
||||||
|
tracing = "0.1"
|
||||||
|
|
||||||
# Optional dependencies:
|
# Optional dependencies:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,13 +11,12 @@ pub struct Custom3d {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Custom3d {
|
impl Custom3d {
|
||||||
pub fn new<'a>(cc: &'a eframe::CreationContext<'a>) -> Self {
|
pub fn new<'a>(cc: &'a eframe::CreationContext<'a>) -> Option<Self> {
|
||||||
Self {
|
let gl = cc.gl.as_ref()?;
|
||||||
rotating_triangle: Arc::new(Mutex::new(RotatingTriangle::new(
|
Some(Self {
|
||||||
cc.gl.as_ref().expect("GL Enabled"),
|
rotating_triangle: Arc::new(Mutex::new(RotatingTriangle::new(gl)?)),
|
||||||
))),
|
|
||||||
angle: 0.0,
|
angle: 0.0,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,18 +80,22 @@ struct RotatingTriangle {
|
||||||
|
|
||||||
#[allow(unsafe_code)] // we need unsafe code to use glow
|
#[allow(unsafe_code)] // we need unsafe code to use glow
|
||||||
impl RotatingTriangle {
|
impl RotatingTriangle {
|
||||||
fn new(gl: &glow::Context) -> Self {
|
fn new(gl: &glow::Context) -> Option<Self> {
|
||||||
use glow::HasContext as _;
|
use glow::HasContext as _;
|
||||||
|
|
||||||
let shader_version = if cfg!(target_arch = "wasm32") {
|
let shader_version = egui_glow::ShaderVersion::get(gl);
|
||||||
"#version 300 es"
|
|
||||||
} else {
|
|
||||||
"#version 330"
|
|
||||||
};
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let program = gl.create_program().expect("Cannot create program");
|
let program = gl.create_program().expect("Cannot create program");
|
||||||
|
|
||||||
|
if !shader_version.is_new_shader_interface() {
|
||||||
|
tracing::warn!(
|
||||||
|
"Custom 3D painting hasn't been ported to {:?}",
|
||||||
|
shader_version
|
||||||
|
);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
let (vertex_shader_source, fragment_shader_source) = (
|
let (vertex_shader_source, fragment_shader_source) = (
|
||||||
r#"
|
r#"
|
||||||
const vec2 verts[3] = vec2[3](
|
const vec2 verts[3] = vec2[3](
|
||||||
|
|
@ -134,10 +137,20 @@ impl RotatingTriangle {
|
||||||
let shader = gl
|
let shader = gl
|
||||||
.create_shader(*shader_type)
|
.create_shader(*shader_type)
|
||||||
.expect("Cannot create shader");
|
.expect("Cannot create shader");
|
||||||
gl.shader_source(shader, &format!("{}\n{}", shader_version, shader_source));
|
gl.shader_source(
|
||||||
|
shader,
|
||||||
|
&format!(
|
||||||
|
"{}\n{}",
|
||||||
|
shader_version.version_declaration(),
|
||||||
|
shader_source
|
||||||
|
),
|
||||||
|
);
|
||||||
gl.compile_shader(shader);
|
gl.compile_shader(shader);
|
||||||
if !gl.get_shader_compile_status(shader) {
|
if !gl.get_shader_compile_status(shader) {
|
||||||
panic!("{}", gl.get_shader_info_log(shader));
|
panic!(
|
||||||
|
"Failed to compile custom_3d_glow: {}",
|
||||||
|
gl.get_shader_info_log(shader)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
gl.attach_shader(program, shader);
|
gl.attach_shader(program, shader);
|
||||||
shader
|
shader
|
||||||
|
|
@ -158,10 +171,10 @@ impl RotatingTriangle {
|
||||||
.create_vertex_array()
|
.create_vertex_array()
|
||||||
.expect("Cannot create vertex array");
|
.expect("Cannot create vertex array");
|
||||||
|
|
||||||
Self {
|
Some(Self {
|
||||||
program,
|
program,
|
||||||
vertex_array,
|
vertex_array,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,10 @@ pub struct Custom3d {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Custom3d {
|
impl Custom3d {
|
||||||
pub fn new<'a>(cc: &'a eframe::CreationContext<'a>) -> Self {
|
pub fn new<'a>(cc: &'a eframe::CreationContext<'a>) -> Option<Self> {
|
||||||
// Get the WGPU render state from the eframe creation context. This can also be retrieved
|
// Get the WGPU render state from the eframe creation context. This can also be retrieved
|
||||||
// from `eframe::Frame` when you don't have a `CreationContext` available.
|
// from `eframe::Frame` when you don't have a `CreationContext` available.
|
||||||
let wgpu_render_state = cc.wgpu_render_state.as_ref().expect("WGPU enabled");
|
let wgpu_render_state = cc.wgpu_render_state.as_ref()?;
|
||||||
|
|
||||||
let device = &wgpu_render_state.device;
|
let device = &wgpu_render_state.device;
|
||||||
|
|
||||||
|
|
@ -91,7 +91,7 @@ impl Custom3d {
|
||||||
uniform_buffer,
|
uniform_buffer,
|
||||||
});
|
});
|
||||||
|
|
||||||
Self { angle: 0.0 }
|
Some(Self { angle: 0.0 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ pub struct WrapApp {
|
||||||
state: State,
|
state: State,
|
||||||
|
|
||||||
#[cfg(any(feature = "glow", feature = "wgpu"))]
|
#[cfg(any(feature = "glow", feature = "wgpu"))]
|
||||||
custom3d: crate::apps::Custom3d,
|
custom3d: Option<crate::apps::Custom3d>,
|
||||||
|
|
||||||
dropped_files: Vec<egui::DroppedFile>,
|
dropped_files: Vec<egui::DroppedFile>,
|
||||||
}
|
}
|
||||||
|
|
@ -148,11 +148,13 @@ impl WrapApp {
|
||||||
];
|
];
|
||||||
|
|
||||||
#[cfg(any(feature = "glow", feature = "wgpu"))]
|
#[cfg(any(feature = "glow", feature = "wgpu"))]
|
||||||
vec.push((
|
if let Some(custom3d) = &mut self.custom3d {
|
||||||
"🔺 3D painting",
|
vec.push((
|
||||||
"custom3d",
|
"🔺 3D painting",
|
||||||
&mut self.custom3d as &mut dyn eframe::App,
|
"custom3d",
|
||||||
));
|
custom3d as &mut dyn eframe::App,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
vec.push((
|
vec.push((
|
||||||
"🎨 Color test",
|
"🎨 Color test",
|
||||||
|
|
@ -219,7 +221,9 @@ impl eframe::App for WrapApp {
|
||||||
|
|
||||||
#[cfg(feature = "glow")]
|
#[cfg(feature = "glow")]
|
||||||
fn on_exit(&mut self, gl: Option<&glow::Context>) {
|
fn on_exit(&mut self, gl: Option<&glow::Context>) {
|
||||||
self.custom3d.on_exit(gl);
|
if let Some(custom3d) = &mut self.custom3d {
|
||||||
|
custom3d.on_exit(gl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ mod post_process;
|
||||||
mod shader_version;
|
mod shader_version;
|
||||||
mod vao;
|
mod vao;
|
||||||
|
|
||||||
|
pub use shader_version::ShaderVersion;
|
||||||
|
|
||||||
#[cfg(all(not(target_arch = "wasm32"), feature = "winit"))]
|
#[cfg(all(not(target_arch = "wasm32"), feature = "winit"))]
|
||||||
pub mod winit;
|
pub mod winit;
|
||||||
#[cfg(all(not(target_arch = "wasm32"), feature = "winit"))]
|
#[cfg(all(not(target_arch = "wasm32"), feature = "winit"))]
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ impl Painter {
|
||||||
|
|
||||||
let shader_version = ShaderVersion::get(&gl);
|
let shader_version = ShaderVersion::get(&gl);
|
||||||
let is_webgl_1 = shader_version == ShaderVersion::Es100;
|
let is_webgl_1 = shader_version == ShaderVersion::Es100;
|
||||||
let header = shader_version.version();
|
let header = shader_version.version_declaration();
|
||||||
tracing::debug!("Shader header: {:?}.", header);
|
tracing::debug!("Shader header: {:?}.", header);
|
||||||
let srgb_support = gl.supported_extensions().contains("EXT_sRGB");
|
let srgb_support = gl.supported_extensions().contains("EXT_sRGB");
|
||||||
|
|
||||||
|
|
@ -155,7 +155,11 @@ impl Painter {
|
||||||
"{}\n{}\n{}\n{}",
|
"{}\n{}\n{}\n{}",
|
||||||
header,
|
header,
|
||||||
shader_prefix,
|
shader_prefix,
|
||||||
shader_version.is_new_shader_interface(),
|
if shader_version.is_new_shader_interface() {
|
||||||
|
"#define NEW_SHADER_INTERFACE\n"
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
},
|
||||||
VERT_SRC
|
VERT_SRC
|
||||||
),
|
),
|
||||||
)?;
|
)?;
|
||||||
|
|
@ -167,7 +171,11 @@ impl Painter {
|
||||||
header,
|
header,
|
||||||
shader_prefix,
|
shader_prefix,
|
||||||
srgb_support_define,
|
srgb_support_define,
|
||||||
shader_version.is_new_shader_interface(),
|
if shader_version.is_new_shader_interface() {
|
||||||
|
"#define NEW_SHADER_INTERFACE\n"
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
},
|
||||||
FRAG_SRC
|
FRAG_SRC
|
||||||
),
|
),
|
||||||
)?;
|
)?;
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,10 @@
|
||||||
|
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
|
||||||
|
/// Helper for parsing and interpreting the OpenGL shader version.
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(crate) enum ShaderVersion {
|
pub enum ShaderVersion {
|
||||||
Gl120,
|
Gl120,
|
||||||
Gl140,
|
Gl140,
|
||||||
Es100,
|
Es100,
|
||||||
|
|
@ -12,7 +13,7 @@ pub(crate) enum ShaderVersion {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ShaderVersion {
|
impl ShaderVersion {
|
||||||
pub(crate) fn get(gl: &glow::Context) -> Self {
|
pub fn get(gl: &glow::Context) -> Self {
|
||||||
use glow::HasContext as _;
|
use glow::HasContext as _;
|
||||||
let shading_lang_string =
|
let shading_lang_string =
|
||||||
unsafe { gl.get_parameter_string(glow::SHADING_LANGUAGE_VERSION) };
|
unsafe { gl.get_parameter_string(glow::SHADING_LANGUAGE_VERSION) };
|
||||||
|
|
@ -52,7 +53,8 @@ impl ShaderVersion {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn version(&self) -> &'static str {
|
/// Goes on top of the shader.
|
||||||
|
pub fn version_declaration(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Self::Gl120 => "#version 120\n",
|
Self::Gl120 => "#version 120\n",
|
||||||
Self::Gl140 => "#version 140\n",
|
Self::Gl140 => "#version 140\n",
|
||||||
|
|
@ -61,10 +63,11 @@ impl ShaderVersion {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn is_new_shader_interface(&self) -> &'static str {
|
/// If true, use `in/out`. If `false`, use `varying` and `gl_FragColor`.
|
||||||
|
pub fn is_new_shader_interface(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
ShaderVersion::Es300 | ShaderVersion::Gl140 => "#define NEW_SHADER_INTERFACE\n",
|
Self::Gl120 | Self::Es100 => false,
|
||||||
_ => "",
|
Self::Es300 | Self::Gl140 => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue