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