aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/webglvertexarrayobject.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2020-03-13 11:40:43 -0400
committerGitHub <noreply@github.com>2020-03-13 11:40:43 -0400
commit13a349603d986f969f522a676f356702aa69d5ac (patch)
tree179012d890cf4105b5c87adebe67385daf9ecbf2 /components/script/dom/webglvertexarrayobject.rs
parent63a5807540892a3b0bf6ce5e27de23ca1a1b127b (diff)
parent1b4a3d8987077ce003ab0755b33663bda7f31935 (diff)
downloadservo-13a349603d986f969f522a676f356702aa69d5ac.tar.gz
servo-13a349603d986f969f522a676f356702aa69d5ac.zip
Auto merge of #25959 - jdm:webgl_vertex_array, r=jdm
Add VertexArrayObject support for WebGL2 The implementation was already in place for OpenGL ES. My approach with this patch is to add support for WebGL2 by sharing the implementation between the WebGL2 and GLES. Sadly I couldn't manage to place the WebGL2 and OpenGL ES variant to the same slot in `WebGLRenderingContext`, therefore I had to do same code duplication. Fixes #25956. <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] There are tests for these changes <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Diffstat (limited to 'components/script/dom/webglvertexarrayobject.rs')
-rw-r--r--components/script/dom/webglvertexarrayobject.rs100
1 files changed, 100 insertions, 0 deletions
diff --git a/components/script/dom/webglvertexarrayobject.rs b/components/script/dom/webglvertexarrayobject.rs
new file mode 100644
index 00000000000..48355d05557
--- /dev/null
+++ b/components/script/dom/webglvertexarrayobject.rs
@@ -0,0 +1,100 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+
+use crate::dom::bindings::cell::Ref;
+use crate::dom::bindings::codegen::Bindings::WebGLVertexArrayObjectBinding;
+use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
+use crate::dom::bindings::root::{DomRoot, MutNullableDom};
+use crate::dom::vertexarrayobject::{VertexArrayObject, VertexAttribData};
+use crate::dom::webglbuffer::WebGLBuffer;
+use crate::dom::webglobject::WebGLObject;
+use crate::dom::webglrenderingcontext::WebGLRenderingContext;
+use canvas_traits::webgl::{ActiveAttribInfo, WebGLResult, WebGLVertexArrayId};
+use dom_struct::dom_struct;
+
+#[dom_struct]
+pub struct WebGLVertexArrayObject {
+ webgl_object_: WebGLObject,
+ array_object: VertexArrayObject,
+}
+
+impl WebGLVertexArrayObject {
+ fn new_inherited(context: &WebGLRenderingContext, id: Option<WebGLVertexArrayId>) -> Self {
+ Self {
+ webgl_object_: WebGLObject::new_inherited(context),
+ array_object: VertexArrayObject::new(context, id),
+ }
+ }
+
+ pub fn new(context: &WebGLRenderingContext, id: Option<WebGLVertexArrayId>) -> DomRoot<Self> {
+ reflect_dom_object(
+ Box::new(WebGLVertexArrayObject::new_inherited(context, id)),
+ &*context.global(),
+ WebGLVertexArrayObjectBinding::Wrap,
+ )
+ }
+
+ pub fn id(&self) -> Option<WebGLVertexArrayId> {
+ self.array_object.id()
+ }
+
+ pub fn is_deleted(&self) -> bool {
+ self.array_object.is_deleted()
+ }
+
+ pub fn delete(&self, fallible: bool) {
+ self.array_object.delete(fallible);
+ }
+
+ pub fn ever_bound(&self) -> bool {
+ self.array_object.ever_bound()
+ }
+
+ pub fn set_ever_bound(&self) {
+ self.array_object.set_ever_bound();
+ }
+
+ pub fn element_array_buffer(&self) -> &MutNullableDom<WebGLBuffer> {
+ self.array_object.element_array_buffer()
+ }
+
+ pub fn get_vertex_attrib(&self, index: u32) -> Option<Ref<VertexAttribData>> {
+ self.array_object.get_vertex_attrib(index)
+ }
+
+ pub fn vertex_attrib_pointer(
+ &self,
+ index: u32,
+ size: i32,
+ type_: u32,
+ normalized: bool,
+ stride: i32,
+ offset: i64,
+ ) -> WebGLResult<()> {
+ self.array_object
+ .vertex_attrib_pointer(index, size, type_, normalized, stride, offset)
+ }
+
+ pub fn vertex_attrib_divisor(&self, index: u32, value: u32) {
+ self.array_object.vertex_attrib_divisor(index, value);
+ }
+
+ pub fn enabled_vertex_attrib_array(&self, index: u32, value: bool) {
+ self.array_object.enabled_vertex_attrib_array(index, value);
+ }
+
+ pub fn unbind_buffer(&self, buffer: &WebGLBuffer) {
+ self.array_object.unbind_buffer(buffer);
+ }
+
+ pub fn validate_for_draw(
+ &self,
+ required_len: u32,
+ instance_count: u32,
+ active_attribs: &[ActiveAttribInfo],
+ ) -> WebGLResult<()> {
+ self.array_object
+ .validate_for_draw(required_len, instance_count, active_attribs)
+ }
+}