Skip to main content

script/dom/webgl/
webglvertexarrayobjectoes.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::cell::Ref;
8use script_bindings::reflector::reflect_dom_object;
9use servo_canvas_traits::webgl::{ActiveAttribInfo, WebGLResult, WebGLVertexArrayId};
10
11use crate::dom::bindings::reflector::DomGlobal;
12use crate::dom::bindings::root::{DomRoot, MutNullableDom};
13use crate::dom::webgl::vertexarrayobject::{
14    VertexArrayObject, VertexAttribData, VertexAttribPointerKind,
15};
16use crate::dom::webgl::webglbuffer::WebGLBuffer;
17use crate::dom::webgl::webglobject::WebGLObject;
18use crate::dom::webgl::webglrenderingcontext::{Operation, WebGLRenderingContext};
19
20#[dom_struct]
21pub(crate) struct WebGLVertexArrayObjectOES {
22    webgl_object_: WebGLObject,
23    array_object: VertexArrayObject,
24}
25
26impl WebGLVertexArrayObjectOES {
27    fn new_inherited(context: &WebGLRenderingContext, id: Option<WebGLVertexArrayId>) -> Self {
28        Self {
29            webgl_object_: WebGLObject::new_inherited(context),
30            array_object: VertexArrayObject::new(context, id),
31        }
32    }
33
34    pub(crate) fn new(
35        cx: &mut JSContext,
36        context: &WebGLRenderingContext,
37        id: Option<WebGLVertexArrayId>,
38    ) -> DomRoot<Self> {
39        reflect_dom_object(
40            cx,
41            Box::new(WebGLVertexArrayObjectOES::new_inherited(context, id)),
42            &*context.global(),
43        )
44    }
45
46    pub(crate) fn id(&self) -> Option<WebGLVertexArrayId> {
47        self.array_object.id()
48    }
49
50    pub(crate) fn is_deleted(&self) -> bool {
51        self.array_object.is_deleted()
52    }
53
54    pub(crate) fn delete(&self, operation_fallibility: Operation) {
55        self.array_object.delete(operation_fallibility);
56    }
57
58    pub(crate) fn ever_bound(&self) -> bool {
59        self.array_object.ever_bound()
60    }
61
62    pub(crate) fn set_ever_bound(&self) {
63        self.array_object.set_ever_bound();
64    }
65
66    pub(crate) fn element_array_buffer(&self) -> &MutNullableDom<WebGLBuffer> {
67        self.array_object.element_array_buffer()
68    }
69
70    pub(crate) fn get_vertex_attrib(&self, index: u32) -> Option<Ref<'_, VertexAttribData>> {
71        self.array_object.get_vertex_attrib(index)
72    }
73
74    pub(crate) fn set_vertex_attrib_type(&self, index: u32, type_: u32) {
75        self.array_object.set_vertex_attrib_type(index, type_);
76    }
77
78    pub(crate) fn vertex_attrib_pointer(
79        &self,
80        index: u32,
81        size: i32,
82        type_: u32,
83        stride: i32,
84        offset: i64,
85        kind: VertexAttribPointerKind,
86    ) -> WebGLResult<()> {
87        self.array_object
88            .vertex_attrib_pointer(index, size, type_, stride, offset, kind)
89    }
90
91    pub(crate) fn vertex_attrib_divisor(&self, index: u32, value: u32) {
92        self.array_object.vertex_attrib_divisor(index, value);
93    }
94
95    pub(crate) fn enabled_vertex_attrib_array(&self, index: u32, value: bool) {
96        self.array_object.enabled_vertex_attrib_array(index, value);
97    }
98
99    pub(crate) fn unbind_buffer(&self, buffer: &WebGLBuffer) {
100        self.array_object.unbind_buffer(buffer);
101    }
102
103    pub(crate) fn validate_for_draw(
104        &self,
105        required_len: u32,
106        instance_count: u32,
107        active_attribs: &[ActiveAttribInfo],
108    ) -> WebGLResult<()> {
109        self.array_object
110            .validate_for_draw(required_len, instance_count, active_attribs)
111    }
112}