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