-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
Added Fn's to work with any kind of WebGl2RenderingContext
source.
#101
base: master
Are you sure you want to change the base?
Changes from 2 commits
76a11d6
1cb400d
3c8f295
f536196
c7e70c9
ff92545
252d9ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -497,6 +497,25 @@ impl WebCanvasElement | |
) | ||
} | ||
|
||
pub fn get_webgl2_context_from_callback<V, CB>( | ||
viewport_size_pixels: V, | ||
cb: CB | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason to pass a callback here, rather than just passing the E.g. the signature could be: pub fn use_existing_webgl2_context(
viewport_size_pixels: impl Into<UVec2>,
context: web_sys::WebGl2RenderingContext
) -> Result<GLRenderer, BacktraceError<GLRendererCreationError>>
{ ... } There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No particular reason. Will change it. |
||
) -> Result<GLRenderer, BacktraceError<GLRendererCreationError>> | ||
where | ||
V: Into<UVec2>, | ||
CB: FnOnce() -> web_sys::WebGl2RenderingContext | ||
{ | ||
let viewport_size_pixels = viewport_size_pixels.into(); | ||
|
||
let gl_context = glow::Context::from_webgl2_context(cb()); | ||
|
||
GLRenderer::new_with_gl_backend( | ||
viewport_size_pixels, | ||
Rc::new(GLBackendGlow::new(gl_context)), | ||
GLVersion::WebGL2_0 | ||
) | ||
} | ||
|
||
#[cfg(feature = "windowing")] | ||
pub fn set_buffer_dimensions(&self, size: &UVec2) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This creates a public dependency on the
web_sys
crate. Would it be possible to create a new feature for this inCargo.toml
please?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why public? i see that on wasm32 target arch this dep is included with WebGl2RenderingContext feature . So it is working only on wasm32.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I was unclear. I meant that this exposes
WebGl2RenderingContext
in the public Speedy2D API, which forces us to continue depending onweb-sys
in the future (to avoid breaking the code of existing Speedy2D users). If we ever want to replaceweb-sys
with another library, we'd have to release a breaking v3.0.0 update.I'm okay with this, as long as the
use_existing_webgl2_context
API is gated behind a feature. For example:Then the
use_existing_webgl2_context
function will only be enabled ifweb-sys-features
is set.