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 js::context::JSContext;
7use script_bindings::reflector::{Reflector, reflect_dom_object_with_cx};
8use servo_canvas_traits::webgl::WebGLVersion;
9
10use super::{WebGLExtension, WebGLExtensionSpec, WebGLExtensions};
11use crate::dom::bindings::codegen::Bindings::OESVertexArrayObjectBinding::{
12    OESVertexArrayObjectConstants, OESVertexArrayObjectMethods,
13};
14use crate::dom::bindings::reflector::DomGlobal;
15use crate::dom::bindings::root::{Dom, DomRoot};
16use crate::dom::webgl::webglrenderingcontext::WebGLRenderingContext;
17use crate::dom::webgl::webglvertexarrayobjectoes::WebGLVertexArrayObjectOES;
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(
37        &self,
38        cx: &mut JSContext,
39    ) -> Option<DomRoot<WebGLVertexArrayObjectOES>> {
40        self.ctx.create_vertex_array(cx)
41    }
42
43    /// <https://www.khronos.org/registry/webgl/extensions/OES_vertex_array_object/>
44    fn DeleteVertexArrayOES(&self, cx: &mut JSContext, vao: Option<&WebGLVertexArrayObjectOES>) {
45        self.ctx.delete_vertex_array(cx, vao);
46    }
47
48    /// <https://www.khronos.org/registry/webgl/extensions/OES_vertex_array_object/>
49    fn IsVertexArrayOES(&self, vao: Option<&WebGLVertexArrayObjectOES>) -> bool {
50        self.ctx.is_vertex_array(vao)
51    }
52
53    /// <https://www.khronos.org/registry/webgl/extensions/OES_vertex_array_object/>
54    fn BindVertexArrayOES(&self, vao: Option<&WebGLVertexArrayObjectOES>) {
55        self.ctx.bind_vertex_array(vao);
56    }
57}
58
59impl WebGLExtension for OESVertexArrayObject {
60    type Extension = OESVertexArrayObject;
61    fn new(cx: &mut JSContext, ctx: &WebGLRenderingContext) -> DomRoot<OESVertexArrayObject> {
62        reflect_dom_object_with_cx(
63            Box::new(OESVertexArrayObject::new_inherited(ctx)),
64            &*ctx.global(),
65            cx,
66        )
67    }
68
69    fn spec() -> WebGLExtensionSpec {
70        WebGLExtensionSpec::Specific(WebGLVersion::WebGL1)
71    }
72
73    fn is_supported(ext: &WebGLExtensions) -> bool {
74        ext.supports_any_gl_extension(&[
75            "GL_OES_vertex_array_object",
76            "GL_ARB_vertex_array_object",
77            "GL_APPLE_vertex_array_object",
78        ])
79    }
80
81    fn enable(ext: &WebGLExtensions) {
82        ext.enable_get_parameter_name(OESVertexArrayObjectConstants::VERTEX_ARRAY_BINDING_OES);
83    }
84
85    fn name() -> &'static str {
86        "OES_vertex_array_object"
87    }
88}