Skip to main content

script/dom/webgl/extensions/ext/
oesvertexarrayobject.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use dom_struct::dom_struct;
6use script_bindings::reflector::{Reflector, reflect_dom_object};
7use servo_canvas_traits::webgl::WebGLVersion;
8
9use super::{WebGLExtension, WebGLExtensionSpec, WebGLExtensions};
10use crate::dom::bindings::codegen::Bindings::OESVertexArrayObjectBinding::{
11    OESVertexArrayObjectConstants, OESVertexArrayObjectMethods,
12};
13use crate::dom::bindings::reflector::DomGlobal;
14use crate::dom::bindings::root::{Dom, DomRoot};
15use crate::dom::webgl::webglrenderingcontext::WebGLRenderingContext;
16use crate::dom::webgl::webglvertexarrayobjectoes::WebGLVertexArrayObjectOES;
17use crate::script_runtime::CanGc;
18
19#[dom_struct]
20pub(crate) struct OESVertexArrayObject {
21    reflector_: Reflector,
22    ctx: Dom<WebGLRenderingContext>,
23}
24
25impl OESVertexArrayObject {
26    fn new_inherited(ctx: &WebGLRenderingContext) -> OESVertexArrayObject {
27        Self {
28            reflector_: Reflector::new(),
29            ctx: Dom::from_ref(ctx),
30        }
31    }
32}
33
34impl OESVertexArrayObjectMethods<crate::DomTypeHolder> for OESVertexArrayObject {
35    /// <https://www.khronos.org/registry/webgl/extensions/OES_vertex_array_object/>
36    fn CreateVertexArrayOES(&self) -> Option<DomRoot<WebGLVertexArrayObjectOES>> {
37        self.ctx.create_vertex_array()
38    }
39
40    /// <https://www.khronos.org/registry/webgl/extensions/OES_vertex_array_object/>
41    fn DeleteVertexArrayOES(&self, vao: Option<&WebGLVertexArrayObjectOES>) {
42        self.ctx.delete_vertex_array(vao);
43    }
44
45    /// <https://www.khronos.org/registry/webgl/extensions/OES_vertex_array_object/>
46    fn IsVertexArrayOES(&self, vao: Option<&WebGLVertexArrayObjectOES>) -> bool {
47        self.ctx.is_vertex_array(vao)
48    }
49
50    /// <https://www.khronos.org/registry/webgl/extensions/OES_vertex_array_object/>
51    fn BindVertexArrayOES(&self, vao: Option<&WebGLVertexArrayObjectOES>) {
52        self.ctx.bind_vertex_array(vao);
53    }
54}
55
56impl WebGLExtension for OESVertexArrayObject {
57    type Extension = OESVertexArrayObject;
58    fn new(ctx: &WebGLRenderingContext, can_gc: CanGc) -> DomRoot<OESVertexArrayObject> {
59        reflect_dom_object(
60            Box::new(OESVertexArrayObject::new_inherited(ctx)),
61            &*ctx.global(),
62            can_gc,
63        )
64    }
65
66    fn spec() -> WebGLExtensionSpec {
67        WebGLExtensionSpec::Specific(WebGLVersion::WebGL1)
68    }
69
70    fn is_supported(ext: &WebGLExtensions) -> bool {
71        ext.supports_any_gl_extension(&[
72            "GL_OES_vertex_array_object",
73            "GL_ARB_vertex_array_object",
74            "GL_APPLE_vertex_array_object",
75        ])
76    }
77
78    fn enable(ext: &WebGLExtensions) {
79        ext.enable_get_parameter_name(OESVertexArrayObjectConstants::VERTEX_ARRAY_BINDING_OES);
80    }
81
82    fn name() -> &'static str {
83        "OES_vertex_array_object"
84    }
85}