mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
webgl: implement getError
This commit is contained in:
parent
42bd43a696
commit
9b306aced6
4 changed files with 28 additions and 5 deletions
|
@ -129,8 +129,9 @@ pub enum CanvasWebGLMsg {
|
||||||
DrawingBufferHeight(Sender<i32>),
|
DrawingBufferHeight(Sender<i32>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Copy, PartialEq)]
|
||||||
pub enum WebGLError {
|
pub enum WebGLError {
|
||||||
|
NoError,
|
||||||
InvalidEnum,
|
InvalidEnum,
|
||||||
InvalidOperation,
|
InvalidOperation,
|
||||||
InvalidValue,
|
InvalidValue,
|
||||||
|
|
|
@ -36,6 +36,7 @@ use script_task::ScriptChan;
|
||||||
|
|
||||||
use canvas_traits::{CanvasGradientStop, LinearGradientStyle, RadialGradientStyle};
|
use canvas_traits::{CanvasGradientStop, LinearGradientStyle, RadialGradientStyle};
|
||||||
use canvas_traits::{LineCapStyle, LineJoinStyle, CompositionOrBlending, RepetitionStyle};
|
use canvas_traits::{LineCapStyle, LineJoinStyle, CompositionOrBlending, RepetitionStyle};
|
||||||
|
use canvas_traits::WebGLError;
|
||||||
use cssparser::RGBA;
|
use cssparser::RGBA;
|
||||||
use encoding::types::EncodingRef;
|
use encoding::types::EncodingRef;
|
||||||
use euclid::matrix2d::Matrix2D;
|
use euclid::matrix2d::Matrix2D;
|
||||||
|
@ -297,6 +298,7 @@ no_jsmanaged_fields!(StorageType);
|
||||||
no_jsmanaged_fields!(CanvasGradientStop, LinearGradientStyle, RadialGradientStyle);
|
no_jsmanaged_fields!(CanvasGradientStop, LinearGradientStyle, RadialGradientStyle);
|
||||||
no_jsmanaged_fields!(LineCapStyle, LineJoinStyle, CompositionOrBlending);
|
no_jsmanaged_fields!(LineCapStyle, LineJoinStyle, CompositionOrBlending);
|
||||||
no_jsmanaged_fields!(RepetitionStyle);
|
no_jsmanaged_fields!(RepetitionStyle);
|
||||||
|
no_jsmanaged_fields!(WebGLError);
|
||||||
|
|
||||||
impl JSTraceable for Box<ScriptChan+Send> {
|
impl JSTraceable for Box<ScriptChan+Send> {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -26,6 +26,7 @@ use euclid::size::Size2D;
|
||||||
use js::jsapi::{JSContext, JSObject, RootedValue};
|
use js::jsapi::{JSContext, JSObject, RootedValue};
|
||||||
use js::jsapi::{JS_GetFloat32ArrayData, JS_GetObjectAsArrayBufferView};
|
use js::jsapi::{JS_GetFloat32ArrayData, JS_GetObjectAsArrayBufferView};
|
||||||
use js::jsval::{JSVal, UndefinedValue, NullValue, Int32Value, BooleanValue};
|
use js::jsval::{JSVal, UndefinedValue, NullValue, Int32Value, BooleanValue};
|
||||||
|
use std::cell::Cell;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
|
@ -53,6 +54,7 @@ pub struct WebGLRenderingContext {
|
||||||
global: GlobalField,
|
global: GlobalField,
|
||||||
renderer: Sender<CanvasMsg>,
|
renderer: Sender<CanvasMsg>,
|
||||||
canvas: JS<HTMLCanvasElement>,
|
canvas: JS<HTMLCanvasElement>,
|
||||||
|
last_error: Cell<WebGLError>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WebGLRenderingContext {
|
impl WebGLRenderingContext {
|
||||||
|
@ -67,6 +69,7 @@ impl WebGLRenderingContext {
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
global: GlobalField::from_rooted(&global),
|
global: GlobalField::from_rooted(&global),
|
||||||
renderer: chan,
|
renderer: chan,
|
||||||
|
last_error: Cell::new(WebGLError::NoError),
|
||||||
canvas: JS::from_ref(canvas),
|
canvas: JS::from_ref(canvas),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -129,6 +132,20 @@ impl<'a> WebGLRenderingContextMethods for &'a WebGLRenderingContext {
|
||||||
rval.ptr
|
rval.ptr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
|
||||||
|
fn GetError(self) -> u32 {
|
||||||
|
let error_code = match self.last_error.get() {
|
||||||
|
WebGLError::NoError => constants::NO_ERROR,
|
||||||
|
WebGLError::InvalidEnum => constants::INVALID_ENUM,
|
||||||
|
WebGLError::InvalidValue => constants::INVALID_VALUE,
|
||||||
|
WebGLError::InvalidOperation => constants::INVALID_OPERATION,
|
||||||
|
WebGLError::OutOfMemory => constants::OUT_OF_MEMORY,
|
||||||
|
WebGLError::ContextLost => constants::CONTEXT_LOST_WEBGL,
|
||||||
|
};
|
||||||
|
self.last_error.set(WebGLError::NoError);
|
||||||
|
error_code
|
||||||
|
}
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.2
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.2
|
||||||
fn GetContextAttributes(self) -> Option<WebGLContextAttributes> {
|
fn GetContextAttributes(self) -> Option<WebGLContextAttributes> {
|
||||||
let (sender, receiver) = channel();
|
let (sender, receiver) = channel();
|
||||||
|
@ -482,9 +499,12 @@ pub trait WebGLRenderingContextHelpers {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> WebGLRenderingContextHelpers for &'a WebGLRenderingContext {
|
impl<'a> WebGLRenderingContextHelpers for &'a WebGLRenderingContext {
|
||||||
fn handle_webgl_error(&self, _: WebGLError) {
|
fn handle_webgl_error(&self, err: WebGLError) {
|
||||||
debug!("WebGL error received");
|
// If an error has been detected no further errors must be
|
||||||
// ignore for now
|
// recorded until `getError` has been called
|
||||||
|
if self.last_error.get() == WebGLError::NoError {
|
||||||
|
self.last_error.set(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -558,7 +558,7 @@ interface WebGLRenderingContextBase
|
||||||
//any getBufferParameter(GLenum target, GLenum pname);
|
//any getBufferParameter(GLenum target, GLenum pname);
|
||||||
any getParameter(GLenum pname);
|
any getParameter(GLenum pname);
|
||||||
|
|
||||||
//[WebGLHandlesContextLoss] GLenum getError();
|
[WebGLHandlesContextLoss] GLenum getError();
|
||||||
|
|
||||||
//any getFramebufferAttachmentParameter(GLenum target, GLenum attachment,
|
//any getFramebufferAttachmentParameter(GLenum target, GLenum attachment,
|
||||||
// GLenum pname);
|
// GLenum pname);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue