mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
webgl: implement getError
This commit is contained in:
parent
42bd43a696
commit
9b306aced6
4 changed files with 28 additions and 5 deletions
|
@ -36,6 +36,7 @@ use script_task::ScriptChan;
|
|||
|
||||
use canvas_traits::{CanvasGradientStop, LinearGradientStyle, RadialGradientStyle};
|
||||
use canvas_traits::{LineCapStyle, LineJoinStyle, CompositionOrBlending, RepetitionStyle};
|
||||
use canvas_traits::WebGLError;
|
||||
use cssparser::RGBA;
|
||||
use encoding::types::EncodingRef;
|
||||
use euclid::matrix2d::Matrix2D;
|
||||
|
@ -297,6 +298,7 @@ no_jsmanaged_fields!(StorageType);
|
|||
no_jsmanaged_fields!(CanvasGradientStop, LinearGradientStyle, RadialGradientStyle);
|
||||
no_jsmanaged_fields!(LineCapStyle, LineJoinStyle, CompositionOrBlending);
|
||||
no_jsmanaged_fields!(RepetitionStyle);
|
||||
no_jsmanaged_fields!(WebGLError);
|
||||
|
||||
impl JSTraceable for Box<ScriptChan+Send> {
|
||||
#[inline]
|
||||
|
|
|
@ -26,6 +26,7 @@ use euclid::size::Size2D;
|
|||
use js::jsapi::{JSContext, JSObject, RootedValue};
|
||||
use js::jsapi::{JS_GetFloat32ArrayData, JS_GetObjectAsArrayBufferView};
|
||||
use js::jsval::{JSVal, UndefinedValue, NullValue, Int32Value, BooleanValue};
|
||||
use std::cell::Cell;
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
use std::slice;
|
||||
|
@ -53,6 +54,7 @@ pub struct WebGLRenderingContext {
|
|||
global: GlobalField,
|
||||
renderer: Sender<CanvasMsg>,
|
||||
canvas: JS<HTMLCanvasElement>,
|
||||
last_error: Cell<WebGLError>,
|
||||
}
|
||||
|
||||
impl WebGLRenderingContext {
|
||||
|
@ -67,6 +69,7 @@ impl WebGLRenderingContext {
|
|||
reflector_: Reflector::new(),
|
||||
global: GlobalField::from_rooted(&global),
|
||||
renderer: chan,
|
||||
last_error: Cell::new(WebGLError::NoError),
|
||||
canvas: JS::from_ref(canvas),
|
||||
})
|
||||
}
|
||||
|
@ -129,6 +132,20 @@ impl<'a> WebGLRenderingContextMethods for &'a WebGLRenderingContext {
|
|||
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
|
||||
fn GetContextAttributes(self) -> Option<WebGLContextAttributes> {
|
||||
let (sender, receiver) = channel();
|
||||
|
@ -482,9 +499,12 @@ pub trait WebGLRenderingContextHelpers {
|
|||
}
|
||||
|
||||
impl<'a> WebGLRenderingContextHelpers for &'a WebGLRenderingContext {
|
||||
fn handle_webgl_error(&self, _: WebGLError) {
|
||||
debug!("WebGL error received");
|
||||
// ignore for now
|
||||
fn handle_webgl_error(&self, err: WebGLError) {
|
||||
// If an error has been detected no further errors must be
|
||||
// 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 getParameter(GLenum pname);
|
||||
|
||||
//[WebGLHandlesContextLoss] GLenum getError();
|
||||
[WebGLHandlesContextLoss] GLenum getError();
|
||||
|
||||
//any getFramebufferAttachmentParameter(GLenum target, GLenum attachment,
|
||||
// GLenum pname);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue