Make some WebGL parameters non-optional (fixes #8753)

Those parameters aren't optional in the current spec.

The test element-array-buffer-delete-recreate.html now fails because we don't
actually implement gl.getParameter(gl.CURRENT_PROGRAM).
This commit is contained in:
Anthony Ramine 2018-03-21 12:23:42 +01:00
parent 3229c62282
commit f532e79dc1
6 changed files with 133 additions and 171 deletions

View file

@ -16,7 +16,7 @@ use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderi
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextMethods;
use dom::bindings::codegen::UnionTypes::ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement;
use dom::bindings::conversions::{ConversionResult, FromJSValConvertible, ToJSValConvertible};
use dom::bindings::error::{Error, Fallible};
use dom::bindings::error::{Error, ErrorResult, Fallible};
use dom::bindings::inheritance::Castable;
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
use dom::bindings::root::{Dom, DomRoot, LayoutDom, MutNullableDom};
@ -763,14 +763,10 @@ impl WebGLRenderingContext {
}
}
fn get_image_pixels(&self,
source: Option<ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement>)
-> ImagePixelResult {
let source = match source {
Some(s) => s,
None => return Err(()),
};
fn get_image_pixels(
&self,
source: ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement,
) -> ImagePixelResult {
// NOTE: Getting the pixels probably can be short-circuited if some
// parameter is invalid.
//
@ -1965,10 +1961,8 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn CompileShader(&self, shader: Option<&WebGLShader>) {
if let Some(shader) = shader {
shader.compile(self.webgl_version, self.glsl_version, &self.extension_manager)
}
fn CompileShader(&self, shader: &WebGLShader) {
shader.compile(self.webgl_version, self.glsl_version, &self.extension_manager)
}
// TODO(emilio): Probably in the future we should keep track of the
@ -2244,23 +2238,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
fn GetActiveUniform(&self, program: Option<&WebGLProgram>, index: u32) -> Option<DomRoot<WebGLActiveInfo>> {
let program = match program {
Some(program) => program,
None => {
// Reasons to generate InvalidValue error
// From the GLES 2.0 spec
//
// "INVALID_VALUE is generated if index is greater than or equal
// to the number of active uniform variables in program"
//
// A null program has no uniforms so any index is always greater than the active uniforms
// WebGl conformance expects error with null programs. Check tests in get-active-test.html
self.webgl_error(InvalidValue);
return None;
}
};
fn GetActiveUniform(&self, program: &WebGLProgram, index: u32) -> Option<DomRoot<WebGLActiveInfo>> {
match program.get_active_uniform(index) {
Ok(ret) => Some(ret),
Err(e) => {
@ -2271,23 +2249,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
fn GetActiveAttrib(&self, program: Option<&WebGLProgram>, index: u32) -> Option<DomRoot<WebGLActiveInfo>> {
let program = match program {
Some(program) => program,
None => {
// Reasons to generate InvalidValue error
// From the GLES 2.0 spec
//
// "INVALID_VALUE is generated if index is greater than or equal
// to the number of active attribute variables in program"
//
// A null program has no attributes so any index is always greater than the active uniforms
// WebGl conformance expects error with null programs. Check tests in get-active-test.html
self.webgl_error(InvalidValue);
return None;
}
};
fn GetActiveAttrib(&self, program: &WebGLProgram, index: u32) -> Option<DomRoot<WebGLActiveInfo>> {
match program.get_active_attrib(index) {
Ok(ret) => Some(ret),
Err(e) => {
@ -2298,12 +2260,8 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
fn GetAttribLocation(&self, program: Option<&WebGLProgram>, name: DOMString) -> i32 {
if let Some(program) = program {
handle_potential_webgl_error!(self, program.get_attrib_location(name), None).unwrap_or(-1)
} else {
-1
}
fn GetAttribLocation(&self, program: &WebGLProgram, name: DOMString) -> i32 {
handle_potential_webgl_error!(self, program.get_attrib_location(name), None).unwrap_or(-1)
}
#[allow(unsafe_code)]
@ -2394,61 +2352,48 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn GetProgramInfoLog(&self, program: Option<&WebGLProgram>) -> Option<DOMString> {
if let Some(program) = program {
match program.get_info_log() {
Ok(value) => Some(DOMString::from(value)),
Err(e) => {
self.webgl_error(e);
None
}
fn GetProgramInfoLog(&self, program: &WebGLProgram) -> Option<DOMString> {
match program.get_info_log() {
Ok(value) => Some(DOMString::from(value)),
Err(e) => {
self.webgl_error(e);
None
}
} else {
self.webgl_error(WebGLError::InvalidValue);
None
}
}
#[allow(unsafe_code)]
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
unsafe fn GetProgramParameter(&self, _: *mut JSContext, program: Option<&WebGLProgram>, param_id: u32) -> JSVal {
if let Some(program) = program {
match handle_potential_webgl_error!(self, program.parameter(param_id), WebGLParameter::Invalid) {
WebGLParameter::Int(val) => Int32Value(val),
WebGLParameter::Bool(val) => BooleanValue(val),
WebGLParameter::String(_) => panic!("Program parameter should not be string"),
WebGLParameter::Float(_) => panic!("Program parameter should not be float"),
WebGLParameter::FloatArray(_) => {
panic!("Program paramenter should not be float array")
}
WebGLParameter::Invalid => NullValue(),
unsafe fn GetProgramParameter(&self, _: *mut JSContext, program: &WebGLProgram, param_id: u32) -> JSVal {
match handle_potential_webgl_error!(self, program.parameter(param_id), WebGLParameter::Invalid) {
WebGLParameter::Int(val) => Int32Value(val),
WebGLParameter::Bool(val) => BooleanValue(val),
WebGLParameter::String(_) => panic!("Program parameter should not be string"),
WebGLParameter::Float(_) => panic!("Program parameter should not be float"),
WebGLParameter::FloatArray(_) => {
panic!("Program paramenter should not be float array")
}
} else {
NullValue()
WebGLParameter::Invalid => NullValue(),
}
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn GetShaderInfoLog(&self, shader: Option<&WebGLShader>) -> Option<DOMString> {
shader.and_then(|s| s.info_log()).map(DOMString::from)
fn GetShaderInfoLog(&self, shader: &WebGLShader) -> Option<DOMString> {
shader.info_log().map(DOMString::from)
}
#[allow(unsafe_code)]
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
unsafe fn GetShaderParameter(&self, _: *mut JSContext, shader: Option<&WebGLShader>, param_id: u32) -> JSVal {
if let Some(shader) = shader {
match handle_potential_webgl_error!(self, shader.parameter(param_id), WebGLParameter::Invalid) {
WebGLParameter::Int(val) => Int32Value(val),
WebGLParameter::Bool(val) => BooleanValue(val),
WebGLParameter::String(_) => panic!("Shader parameter should not be string"),
WebGLParameter::Float(_) => panic!("Shader parameter should not be float"),
WebGLParameter::FloatArray(_) => {
panic!("Shader paramenter should not be float array")
}
WebGLParameter::Invalid => NullValue(),
unsafe fn GetShaderParameter(&self, _: *mut JSContext, shader: &WebGLShader, param_id: u32) -> JSVal {
match handle_potential_webgl_error!(self, shader.parameter(param_id), WebGLParameter::Invalid) {
WebGLParameter::Int(val) => Int32Value(val),
WebGLParameter::Bool(val) => BooleanValue(val),
WebGLParameter::String(_) => panic!("Shader parameter should not be string"),
WebGLParameter::Float(_) => panic!("Shader parameter should not be float"),
WebGLParameter::FloatArray(_) => {
panic!("Shader paramenter should not be float array")
}
} else {
NullValue()
WebGLParameter::Invalid => NullValue(),
}
}
@ -2481,12 +2426,13 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
fn GetUniformLocation(&self,
program: Option<&WebGLProgram>,
name: DOMString) -> Option<DomRoot<WebGLUniformLocation>> {
program.and_then(|p| {
handle_potential_webgl_error!(self, p.get_uniform_location(name), None)
.map(|location| WebGLUniformLocation::new(self.global().as_window(), location, p.id()))
fn GetUniformLocation(
&self,
program: &WebGLProgram,
name: DOMString,
) -> Option<DomRoot<WebGLUniformLocation>> {
handle_potential_webgl_error!(self, program.get_uniform_location(name), None).map(|location| {
WebGLUniformLocation::new(self.global().as_window(), location, program.id())
})
}
@ -2863,15 +2809,13 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn ShaderSource(&self, shader: Option<&WebGLShader>, source: DOMString) {
if let Some(shader) = shader {
shader.set_source(source)
}
fn ShaderSource(&self, shader: &WebGLShader, source: DOMString) {
shader.set_source(source)
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn GetShaderSource(&self, shader: Option<&WebGLShader>) -> Option<DOMString> {
shader.and_then(|s| s.source())
fn GetShaderSource(&self, shader: &WebGLShader) -> Option<DOMString> {
shader.source()
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
@ -3162,11 +3106,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn ValidateProgram(&self, program: Option<&WebGLProgram>) {
if let Some(program) = program {
if let Err(e) = program.validate() {
self.webgl_error(e);
}
fn ValidateProgram(&self, program: &WebGLProgram) {
if let Err(e) = program.validate() {
self.webgl_error(e);
}
}
@ -3376,13 +3318,15 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
fn TexImage2D_(&self,
target: u32,
level: i32,
internal_format: u32,
format: u32,
data_type: u32,
source: Option<ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement>) -> Fallible<()> {
fn TexImage2D_(
&self,
target: u32,
level: i32,
internal_format: u32,
format: u32,
data_type: u32,
source: ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement,
) -> ErrorResult {
if !self.extension_manager.is_tex_type_enabled(data_type) {
return Ok(self.webgl_error(InvalidEnum));
}
@ -3537,15 +3481,16 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
fn TexSubImage2D_(&self,
target: u32,
level: i32,
xoffset: i32,
yoffset: i32,
format: u32,
data_type: u32,
source: Option<ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement>)
-> Fallible<()> {
fn TexSubImage2D_(
&self,
target: u32,
level: i32,
xoffset: i32,
yoffset: i32,
format: u32,
data_type: u32,
source: ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement,
) -> ErrorResult {
let (pixels, size, premultiplied) = match self.get_image_pixels(source) {
Ok((pixels, size, premultiplied)) => (pixels, size, premultiplied),
Err(_) => return Ok(()),