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