aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/webglrenderbuffer.rs
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2018-08-01 15:40:53 -0400
committerJosh Matthews <josh@joshmatthews.net>2018-08-02 02:05:53 -0400
commit03eb7e4dd2c36265319440db38100ba9aa92e182 (patch)
tree00bf6288bdebd3e64b4ca93f439b588dc2e490ef /components/script/dom/webglrenderbuffer.rs
parent3334e477c184bba409a280b104e60cc7107a5a15 (diff)
downloadservo-03eb7e4dd2c36265319440db38100ba9aa92e182.tar.gz
servo-03eb7e4dd2c36265319440db38100ba9aa92e182.zip
webgl: Emulate some renderbuffer formats in non-GLES.
Diffstat (limited to 'components/script/dom/webglrenderbuffer.rs')
-rw-r--r--components/script/dom/webglrenderbuffer.rs33
1 files changed, 26 insertions, 7 deletions
diff --git a/components/script/dom/webglrenderbuffer.rs b/components/script/dom/webglrenderbuffer.rs
index 1074f9797e0..fa7d7324f94 100644
--- a/components/script/dom/webglrenderbuffer.rs
+++ b/components/script/dom/webglrenderbuffer.rs
@@ -4,13 +4,14 @@
// https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl
use canvas_traits::webgl::{webgl_channel, WebGLCommand, WebGLError, WebGLRenderbufferId, WebGLResult};
+use dom::bindings::codegen::Bindings::WebGL2RenderingContextBinding::WebGL2RenderingContextConstants as WebGl2Constants;
use dom::bindings::codegen::Bindings::WebGLRenderbufferBinding;
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
use dom::bindings::inheritance::Castable;
use dom::bindings::reflector::{DomObject, reflect_dom_object};
use dom::bindings::root::DomRoot;
use dom::webglobject::WebGLObject;
-use dom::webglrenderingcontext::WebGLRenderingContext;
+use dom::webglrenderingcontext::{WebGLRenderingContext, is_gles};
use dom_struct::dom_struct;
use std::cell::Cell;
@@ -61,6 +62,10 @@ impl WebGLRenderbuffer {
self.size.get()
}
+ pub fn internal_format(&self) -> u32 {
+ self.internal_format.get().unwrap_or(constants::RGBA4)
+ }
+
pub fn bind(&self, target: u32) {
self.ever_bound.set(true);
self.upcast::<WebGLObject>()
@@ -88,25 +93,39 @@ impl WebGLRenderbuffer {
pub fn storage(&self, internal_format: u32, width: i32, height: i32) -> WebGLResult<()> {
// Validate the internal_format, and save it for completeness
// validation.
- match internal_format {
+ let actual_format = match internal_format {
constants::RGBA4 |
- constants::RGB565 |
- constants::RGB5_A1 |
constants::DEPTH_COMPONENT16 |
constants::STENCIL_INDEX8 |
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#6.7
- constants::DEPTH_STENCIL => {
- self.internal_format.set(Some(internal_format))
+ constants::DEPTH_STENCIL => internal_format,
+ constants::RGB5_A1 => {
+ // 16-bit RGBA formats are not supported on desktop GL.
+ if is_gles() {
+ constants::RGB5_A1
+ } else {
+ WebGl2Constants::RGBA8
+ }
+ }
+ constants::RGB565 => {
+ // RGB565 is not supported on desktop GL.
+ if is_gles() {
+ constants::RGB565
+ } else {
+ WebGl2Constants::RGB8
+ }
}
_ => return Err(WebGLError::InvalidEnum),
};
+ self.internal_format.set(Some(internal_format));
+
// FIXME: Invalidate completeness after the call
self.upcast::<WebGLObject>().context().send_command(
WebGLCommand::RenderbufferStorage(
constants::RENDERBUFFER,
- internal_format,
+ actual_format,
width,
height,
)