-
Notifications
You must be signed in to change notification settings - Fork 178
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
Conversation
/// | ||
/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext) | ||
// https://html.spec.whatwg.org/#webglrenderingcontext | ||
pub struct WebGLRenderingContext(Reference); |
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.
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! { |
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 needs to be updated to the newest master
where this macro was replaced by #[derive(ReferenceType)]
|
||
reference_boilerplate! { | ||
WebGLRenderingContext, | ||
instanceof WebGLRenderingContext |
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.
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) { |
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.
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) { |
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 should take an enum as an argument instead of having the COLOR_BUFFER_BIT
hardcoded.
@nialna I have implemented an automatic generator for these bindings: brendanzab/gl-rs#447 Example bindings for stdweb: |
@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. |
@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. |
@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. |
@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. |
That makes sens! Thanks for explaining :-) |
Is there any work still being done on this? How does this compare to the WebGl example? |
First time writing Rust, sorry if I did something wrong
WebGLRenderingContext
with two functions as proof of conceptRenderingContext
file (and I would advise moving the 2d context out of that file too)Also added .idea files to
.gitignore
to not commit project files.