aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/webglrenderingcontext.rs
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2019-09-19 17:45:19 -0400
committerJosh Matthews <josh@joshmatthews.net>2019-09-20 01:28:22 -0400
commit778b48fa47d1fd13d77464373c7f0bc8a2b51d2a (patch)
tree793dae7ff6555014f40803dc2e5f71e5ca34e04f /components/script/dom/webglrenderingcontext.rs
parent7e4cf13f5b1106690f15d84029e31364c0c6907b (diff)
downloadservo-778b48fa47d1fd13d77464373c7f0bc8a2b51d2a.tar.gz
servo-778b48fa47d1fd13d77464373c7f0bc8a2b51d2a.zip
webgl: Implement component narrowing checks for CopyTexImage2D.
Diffstat (limited to 'components/script/dom/webglrenderingcontext.rs')
-rw-r--r--components/script/dom/webglrenderingcontext.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs
index 354f918a0dd..fb4c13b321e 100644
--- a/components/script/dom/webglrenderingcontext.rs
+++ b/components/script/dom/webglrenderingcontext.rs
@@ -1928,6 +1928,47 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
Err(_) => return,
};
+ let framebuffer_format = match self.bound_framebuffer.get() {
+ Some(fb) => match fb.attachment(constants::COLOR_ATTACHMENT0) {
+ Some(WebGLFramebufferAttachmentRoot::Renderbuffer(rb)) => {
+ TexFormat::from_gl_constant(rb.internal_format())
+ },
+ Some(WebGLFramebufferAttachmentRoot::Texture(texture)) => {
+ texture.image_info_for_target(&target, 0).internal_format()
+ },
+ None => None,
+ },
+ None => {
+ let attrs = self.GetContextAttributes().unwrap();
+ Some(if attrs.alpha {
+ TexFormat::RGBA
+ } else {
+ TexFormat::RGB
+ })
+ },
+ };
+
+ let framebuffer_format = match framebuffer_format {
+ Some(f) => f,
+ None => {
+ self.webgl_error(InvalidOperation);
+ return;
+ },
+ };
+
+ match (framebuffer_format, internal_format) {
+ (a, b) if a == b => (),
+ (TexFormat::RGBA, TexFormat::RGB) => (),
+ (TexFormat::RGBA, TexFormat::Alpha) => (),
+ (TexFormat::RGBA, TexFormat::Luminance) => (),
+ (TexFormat::RGBA, TexFormat::LuminanceAlpha) => (),
+ (TexFormat::RGB, TexFormat::Luminance) => (),
+ _ => {
+ self.webgl_error(InvalidOperation);
+ return;
+ },
+ }
+
// NB: TexImage2D depth is always equal to 1
handle_potential_webgl_error!(
self,