aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/webgl2renderingcontext.rs68
-rw-r--r--components/script/dom/webglprogram.rs5
-rw-r--r--components/script/dom/webglrenderingcontext.rs6
-rw-r--r--components/script/dom/webidls/WebGL2RenderingContext.webidl2
4 files changed, 79 insertions, 2 deletions
diff --git a/components/script/dom/webgl2renderingcontext.rs b/components/script/dom/webgl2renderingcontext.rs
index 8ae05c05363..54c0da20333 100644
--- a/components/script/dom/webgl2renderingcontext.rs
+++ b/components/script/dom/webgl2renderingcontext.rs
@@ -189,6 +189,48 @@ impl WebGL2RenderingContext {
self.base.current_vao_webgl2()
}
+ pub fn validate_uniform_block_for_draw(&self) {
+ let program = match self.base.current_program() {
+ Some(program) => program,
+ None => return,
+ };
+ for uniform_block in program.active_uniform_blocks().iter() {
+ let data_size = uniform_block.size as usize;
+ for block in program.active_uniforms().iter() {
+ let index = match block.bind_index {
+ Some(index) => index,
+ None => continue,
+ };
+ let indexed = &self.indexed_uniform_buffer_bindings[index as usize];
+ let buffer = match indexed.buffer.get() {
+ Some(buffer) => buffer,
+ None => {
+ self.base.webgl_error(InvalidOperation);
+ return;
+ },
+ };
+ if indexed.size.get() == 0 {
+ if data_size > buffer.capacity() {
+ self.base.webgl_error(InvalidOperation);
+ return;
+ }
+ } else {
+ let start = indexed.start.get() as usize;
+ let mut size = indexed.size.get() as usize;
+ if start >= size {
+ self.base.webgl_error(InvalidOperation);
+ return;
+ }
+ size -= start;
+ if data_size > size {
+ self.base.webgl_error(InvalidOperation);
+ return;
+ }
+ }
+ }
+ }
+ }
+
pub fn base_context(&self) -> DomRoot<WebGLRenderingContext> {
DomRoot::from_ref(&*self.base)
}
@@ -1527,11 +1569,13 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
/// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.11
fn DrawArrays(&self, mode: u32, first: i32, count: i32) {
+ self.validate_uniform_block_for_draw();
self.base.DrawArrays(mode, first, count)
}
/// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.11
fn DrawElements(&self, mode: u32, count: i32, type_: u32, offset: i64) {
+ self.validate_uniform_block_for_draw();
self.base.DrawElements(mode, count, type_, offset)
}
@@ -2776,6 +2820,7 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
/// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.9
fn DrawArraysInstanced(&self, mode: u32, first: i32, count: i32, primcount: i32) {
+ self.validate_uniform_block_for_draw();
handle_potential_webgl_error!(
self.base,
self.base
@@ -2792,6 +2837,7 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
offset: i64,
primcount: i32,
) {
+ self.validate_uniform_block_for_draw();
handle_potential_webgl_error!(
self.base,
self.base
@@ -2800,6 +2846,28 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
}
/// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.9
+ fn DrawRangeElements(
+ &self,
+ mode: u32,
+ start: u32,
+ end: u32,
+ count: i32,
+ type_: u32,
+ offset: i64,
+ ) {
+ if end < start {
+ self.base.webgl_error(InvalidValue);
+ return;
+ }
+ self.validate_uniform_block_for_draw();
+ handle_potential_webgl_error!(
+ self.base,
+ self.base
+ .draw_elements_instanced(mode, count, type_, offset, 1)
+ )
+ }
+
+ /// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.9
fn VertexAttribDivisor(&self, index: u32, divisor: u32) {
self.base.vertex_attrib_divisor(index, divisor);
}
diff --git a/components/script/dom/webglprogram.rs b/components/script/dom/webglprogram.rs
index d3a726c1e11..78542e7497b 100644
--- a/components/script/dom/webglprogram.rs
+++ b/components/script/dom/webglprogram.rs
@@ -572,6 +572,11 @@ impl WebGLProgram {
return Err(WebGLError::InvalidValue);
}
+ let mut active_uniforms = self.active_uniforms.borrow_mut();
+ if active_uniforms.len() > block_binding as usize {
+ active_uniforms[block_binding as usize].bind_index = Some(block_binding);
+ }
+
self.upcast::<WebGLObject>()
.context()
.send_command(WebGLCommand::UniformBlockBinding(
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs
index 5f95618aa05..33000497abf 100644
--- a/components/script/dom/webglrenderingcontext.rs
+++ b/components/script/dom/webglrenderingcontext.rs
@@ -960,7 +960,11 @@ impl WebGLRenderingContext {
let type_size = match type_ {
constants::UNSIGNED_BYTE => 1,
constants::UNSIGNED_SHORT => 2,
- constants::UNSIGNED_INT if self.extension_manager.is_element_index_uint_enabled() => 4,
+ constants::UNSIGNED_INT => match self.webgl_version() {
+ WebGLVersion::WebGL1 if self.extension_manager.is_element_index_uint_enabled() => 4,
+ WebGLVersion::WebGL2 => 4,
+ _ => return Err(InvalidEnum),
+ },
_ => return Err(InvalidEnum),
};
if offset % type_size != 0 {
diff --git a/components/script/dom/webidls/WebGL2RenderingContext.webidl b/components/script/dom/webidls/WebGL2RenderingContext.webidl
index dca86da39fe..a05142da935 100644
--- a/components/script/dom/webidls/WebGL2RenderingContext.webidl
+++ b/components/script/dom/webidls/WebGL2RenderingContext.webidl
@@ -461,7 +461,7 @@ interface mixin WebGL2RenderingContextBase
void vertexAttribDivisor(GLuint index, GLuint divisor);
void drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount);
void drawElementsInstanced(GLenum mode, GLsizei count, GLenum type, GLintptr offset, GLsizei instanceCount);
- // void drawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, GLintptr offset);
+ void drawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, GLintptr offset);
/* Reading back pixels */
// WebGL1: