-
-
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?
Conversation
src/web.rs
Outdated
@@ -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 comment
The 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 web_sys::WebGl2RenderingContext
directly?
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 comment
The reason will be displayed to describe this comment to others. Learn more.
No particular reason. Will change it.
src/lib.rs
Outdated
) -> Result<Self, BacktraceError<GLRendererCreationError>> | ||
where | ||
V: Into<UVec2>, | ||
S: FnOnce() -> WebGl2RenderingContext |
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 in Cargo.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 on web-sys
in the future (to avoid breaking the code of existing Speedy2D users). If we ever want to replace web-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:
[features]
default = ["windowing", "image-loading"]
windowing = ["glutin"]
image-loading = ["image"]
web-sys-features = []
#[cfg(any(feature = "web-sys-features", doc, doctest))]
pub fn use_existing_webgl2_context(
...
Then the use_existing_webgl2_context
function will only be enabled if web-sys-features
is set.
Thank you for this! I've left a couple of comments. Also the tests and docs don't seem to build at the moment. |
/// The parameter `viewport_size_pixels` should be set to | ||
/// the initial canvas size, however this can be changed later using | ||
/// [GLRenderer:: set_viewport_size_pixels()]. | ||
#[cfg(target_arch = "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.
I hope this is Ok. I am not sure why this does not compile with doc
and doctest
also, bc web-sys
dep has this options in cargo.toml
.
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.
I think the issue was this:
#[cfg(target_arch = "wasm32")]
use web_sys::WebGl2RenderingContext;
The WebGl2RenderingContext
was imported for wasm32 but not doc/doctest. If you make the cfg
next to use
match the cfg
on the function, it should hopefully work.
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.
(or, just use the full namespace web_sys::WebGl2RenderingContext
directly as you've done now, and re-add doc
and doctest
to the function cfg
)
No description provided.