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

Added WebGL Rendering Context #110

Closed
wants to merge 1 commit into from
Closed

Conversation

liana-p
Copy link
Contributor

@liana-p liana-p commented Feb 10, 2018

First time writing Rust, sorry if I did something wrong

  • Added basic WebGLRenderingContext with two functions as proof of concept
  • It's in a separate file to not pollute the RenderingContext file (and I would advise moving the 2d context out of that file too)
  • Added an example similar to the canvas one (it just draws a color on screen)

Also added .idea files to .gitignore to not commit project files.

@liana-p liana-p changed the title Added WebGL Renderer Added WebGL Rendering Context Feb 10, 2018
///
/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext)
// https://html.spec.whatwg.org/#webglrenderingcontext
pub struct WebGLRenderingContext(Reference);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be consistent with the convention we've picked in the rest of the library this should be named WebGlRenderingContext (lowercase L)

// https://html.spec.whatwg.org/#webglrenderingcontext
pub struct WebGLRenderingContext(Reference);

reference_boilerplate! {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be updated to the newest master where this macro was replaced by #[derive(ReferenceType)]


reference_boilerplate! {
WebGLRenderingContext,
instanceof WebGLRenderingContext
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, we use spaces everywhere instead of tabs. (:

/// The values are clamped between 0 and 1.
///
/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/clearColor)
pub fn clear_color(&self, red: f64, green: f64, blue: f64, alpha: f64) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add link to the IDL entry in the specs (just as for our other APIs.)

/// The WebGLRenderingContext.clear() method of the WebGL API clears buffers to preset values.
///
/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/clear)
pub fn clear(&self) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should take an enum as an argument instead of having the COLOR_BUFFER_BIT hardcoded.

@Diggsey
Copy link
Contributor

Diggsey commented Feb 26, 2018

@nialna I have implemented an automatic generator for these bindings: brendanzab/gl-rs#447

Example bindings for stdweb:
https://gist.github.com/Diggsey/c8a4cb93c7d5643d20203401ead178a7

@NeverGivinUp
Copy link

@Diggsey I havn't really read it, just skimmed over it. So please excuse any unwarranted criticism.

It seems like the generator outputs Rust code but stays very close to the C feel. Is this a technical limitation or a design decision?

For instance, there are a lot of const GLenum declarations, wheren GLenum is just a renamed u32 -- as it is in the C-oriented JavaScript. They could be broken into groups of related enums, that turn to GLenum only when serialized to JavaScript.
Also, JavaScript uses the C-oriented GLintptr type that marks it as a platform-specific type for pointer arithmetics. I wonder if there is a rustier solution.

@Diggsey
Copy link
Contributor

Diggsey commented Feb 26, 2018

@NeverGivinUp the bindings are intended to be a thin wrapper around the javascript WebGL API. In fact I'd rather move in the opposite direction from what you are suggesting: towards an API that is more compatible with the OpenGL C api, so that it is easier to implement a WebGL backend for eg. gfx.

@NeverGivinUp
Copy link

@Diggsey I'm glad it's a design decision.

Would you kindly elaborate on the ease of implementation you have in mind? The closer it is to the C-api, the easier it might be to implement for experienced C programmers. But why would they implement something in Rust anyway? Considering Rust offers zero-cost abstraction and better type safety, wouldn't it be better to make full use of that and gain more self-documenting and more idiomatic code?

Again, I don't mean to criticize. I would like to understand your design rationale, though.

@Diggsey
Copy link
Contributor

Diggsey commented Feb 26, 2018

@NeverGivinUp most people do not use raw OpenGL calls directly, and those that do would probably prefer to use a fully type-safe wrapper like "glium". To that end, it would be better to add support for WebGL to glium/gfx/etc. rather than trying to duplicate the work from those projects here.

@NeverGivinUp
Copy link

That makes sens! Thanks for explaining :-)

@Thomspoon
Copy link

Is there any work still being done on this? How does this compare to the WebGl example?

@liana-p liana-p closed this Aug 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants