forked from mirrors/gecko-dev
This improves the encapsulation and consistency in our WebGL
implementation.
Also allows to implement new methods such as `getShaderSource()`.
It will also allow us to use `delete()` in the destructors of them (note
that we will probably want to keep track of them from the context before).
Some concerns:
**Trait method repetition**:
I'm aware that the traits `WebGL{Buffer,Renderbuffer,Framebuffer,Texture}Helpers` are basically the same, but `delete()` and `id()` methods are everywhere. I've thought something like:
```rust
pub trait WebGLIdentifiable {
type WebGLId; // id is sometimes i32 (see WebGLUniformLocation)
fn id(&self) -> Self::WebGLId;
}
pub trait WebGLBindable {
fn bind(&self);
}
pub trait WebGLDeletable {
fn delete(&self);
}
```
But I'd want to know your opinion first.
**`renderer` repetition**:
Thought of moving the field: `renderer: Sender<CanvasMsg>` to `WebGLObject`, but I think it makes it way more complicated to read, and also a bit unnecessary, at least IMO (`WebGLObject` will never interact with the field directly). It would also mean that all `WebGLObject`s should have one, which is true at this moment, but maybe not with WebGL 2, for example.
Source-Repo: https://github.com/servo/servo
Source-Revision: 0f8095b950dd144497919cfea65a1f154ed3ae9a
38 lines
1.1 KiB
Rust
38 lines
1.1 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl
|
|
use dom::bindings::codegen::Bindings::WebGLUniformLocationBinding;
|
|
use dom::bindings::global::GlobalRef;
|
|
use dom::bindings::js::Root;
|
|
use dom::bindings::utils::{Reflector,reflect_dom_object};
|
|
|
|
#[dom_struct]
|
|
pub struct WebGLUniformLocation {
|
|
reflector_: Reflector,
|
|
id: i32,
|
|
}
|
|
|
|
impl WebGLUniformLocation {
|
|
fn new_inherited(id: i32) -> WebGLUniformLocation {
|
|
WebGLUniformLocation {
|
|
reflector_: Reflector::new(),
|
|
id: id,
|
|
}
|
|
}
|
|
|
|
pub fn new(global: GlobalRef, id: i32) -> Root<WebGLUniformLocation> {
|
|
reflect_dom_object(box WebGLUniformLocation::new_inherited(id), global, WebGLUniformLocationBinding::Wrap)
|
|
}
|
|
}
|
|
|
|
pub trait WebGLUniformLocationHelpers {
|
|
fn id(self) -> i32;
|
|
}
|
|
|
|
impl<'a> WebGLUniformLocationHelpers for &'a WebGLUniformLocation {
|
|
fn id(self) -> i32 {
|
|
self.id
|
|
}
|
|
}
|