Bug 1184402 - Part 3: Add WebGL1 formats when enabling extensions. r=jgilbert
authorDan Glastonbury <dglastonbury@mozilla.com>
Fri, 17 Jul 2015 10:27:26 +1000
changeset 287019 5a61f0b040fc561a17ecd32cacf1c3d5f2c36f03
parent 287018 5fe2bb2c7656d76619a34fb96152e49a6e514532
child 287020 1dd68bfb40418dcafe1e626d31c8f29abe9f1f57
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgilbert
bugs1184402
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1184402 - Part 3: Add WebGL1 formats when enabling extensions. r=jgilbert
dom/canvas/WebGL2Context.cpp
dom/canvas/WebGLExtensionColorBufferFloat.cpp
dom/canvas/WebGLExtensionColorBufferHalfFloat.cpp
dom/canvas/WebGLExtensionSRGB.cpp
dom/canvas/WebGLExtensionTextureFloat.cpp
dom/canvas/WebGLExtensionTextureFloatLinear.cpp
dom/canvas/WebGLExtensionTextureHalfFloat.cpp
dom/canvas/WebGLExtensionTextureHalfFloatLinear.cpp
dom/canvas/WebGLExtensions.h
dom/canvas/WebGLFormats.cpp
dom/canvas/WebGLFormats.h
--- a/dom/canvas/WebGL2Context.cpp
+++ b/dom/canvas/WebGL2Context.cpp
@@ -53,19 +53,17 @@ WebGL2Context::WrapObject(JSContext* cx,
 
 // These WebGL 1 extensions are natively supported by WebGL 2.
 static const WebGLExtensionID kNativelySupportedExtensions[] = {
     WebGLExtensionID::ANGLE_instanced_arrays,
     WebGLExtensionID::EXT_blend_minmax,
     WebGLExtensionID::EXT_sRGB,
     WebGLExtensionID::OES_element_index_uint,
     WebGLExtensionID::OES_standard_derivatives,
-    WebGLExtensionID::OES_texture_float,
     WebGLExtensionID::OES_texture_float_linear,
-    WebGLExtensionID::OES_texture_half_float,
     WebGLExtensionID::OES_texture_half_float_linear,
     WebGLExtensionID::OES_vertex_array_object,
     WebGLExtensionID::WEBGL_depth_texture,
     WebGLExtensionID::WEBGL_draw_buffers
 };
 
 static const gl::GLFeature kRequiredFeatures[] = {
     gl::GLFeature::blend_minmax,
--- a/dom/canvas/WebGLExtensionColorBufferFloat.cpp
+++ b/dom/canvas/WebGLExtensionColorBufferFloat.cpp
@@ -2,23 +2,44 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLExtensions.h"
 
 #include "GLContext.h"
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
 #include "WebGLContext.h"
+#include "WebGLFormats.h"
 
 namespace mozilla {
 
+using mozilla::webgl::EffectiveFormat;
+
 WebGLExtensionColorBufferFloat::WebGLExtensionColorBufferFloat(WebGLContext* webgl)
     : WebGLExtensionBase(webgl)
 {
     MOZ_ASSERT(IsSupported(webgl), "Don't construct extension if unsupported.");
+
+    webgl::FormatUsageAuthority* authority = webgl->mFormatUsage.get();
+
+    auto updateUsage = [authority](EffectiveFormat effectiveFormat) {
+        webgl::FormatUsageInfo* usage = authority->GetUsage(effectiveFormat);
+        MOZ_ASSERT(usage);
+        usage->asRenderbuffer = usage->isRenderable = true;
+    };
+
+    // Ensure require formats are initialized.
+    WebGLExtensionTextureFloat::InitWebGLFormats(authority);
+
+    // Update usage to allow asRenderbuffer and isRenderable
+    updateUsage(EffectiveFormat::RGBA32F);
+    updateUsage(EffectiveFormat::RGB32F);
+    updateUsage(EffectiveFormat::Luminance32FAlpha32F);
+    updateUsage(EffectiveFormat::Luminance32F);
+    updateUsage(EffectiveFormat::Alpha32F);
 }
 
 WebGLExtensionColorBufferFloat::~WebGLExtensionColorBufferFloat()
 {
 }
 
 bool
 WebGLExtensionColorBufferFloat::IsSupported(const WebGLContext* webgl)
--- a/dom/canvas/WebGLExtensionColorBufferHalfFloat.cpp
+++ b/dom/canvas/WebGLExtensionColorBufferHalfFloat.cpp
@@ -2,23 +2,44 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLExtensions.h"
 
 #include "GLContext.h"
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
 #include "WebGLContext.h"
+#include "WebGLFormats.h"
 
 namespace mozilla {
 
+using mozilla::webgl::EffectiveFormat;
+
 WebGLExtensionColorBufferHalfFloat::WebGLExtensionColorBufferHalfFloat(WebGLContext* webgl)
     : WebGLExtensionBase(webgl)
 {
     MOZ_ASSERT(IsSupported(webgl), "Don't construct extension if unsupported.");
+
+    webgl::FormatUsageAuthority* authority = webgl->mFormatUsage.get();
+
+    auto updateUsage = [authority](EffectiveFormat effectiveFormat) {
+        webgl::FormatUsageInfo* usage = authority->GetUsage(effectiveFormat);
+        MOZ_ASSERT(usage);
+        usage->asRenderbuffer = usage->isRenderable = true;
+    };
+
+    // Ensure require formats are initialized.
+    WebGLExtensionTextureHalfFloat::InitWebGLFormats(authority);
+
+    // Update usage to allow asRenderbuffer and isRenderable
+    updateUsage(EffectiveFormat::RGBA16F);
+    updateUsage(EffectiveFormat::RGB16F);
+    updateUsage(EffectiveFormat::Luminance16FAlpha16F);
+    updateUsage(EffectiveFormat::Luminance16F);
+    updateUsage(EffectiveFormat::Alpha16F);
 }
 
 WebGLExtensionColorBufferHalfFloat::~WebGLExtensionColorBufferHalfFloat()
 {
 }
 
 bool
 WebGLExtensionColorBufferHalfFloat::IsSupported(const WebGLContext* webgl)
--- a/dom/canvas/WebGLExtensionSRGB.cpp
+++ b/dom/canvas/WebGLExtensionSRGB.cpp
@@ -3,31 +3,50 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLExtensions.h"
 
 #include "GLContext.h"
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
 #include "WebGLContext.h"
+#include "WebGLFormats.h"
 
 namespace mozilla {
 
+using mozilla::webgl::EffectiveFormat;
+
+
 WebGLExtensionSRGB::WebGLExtensionSRGB(WebGLContext* webgl)
     : WebGLExtensionBase(webgl)
 {
     MOZ_ASSERT(IsSupported(webgl), "Don't construct extension if unsupported.");
 
     gl::GLContext* gl = webgl->GL();
     if (!gl->IsGLES()) {
         // Desktop OpenGL requires the following to be enabled in order to
         // support sRGB operations on framebuffers.
         gl->MakeCurrent();
         gl->fEnable(LOCAL_GL_FRAMEBUFFER_SRGB_EXT);
     }
+
+    webgl::FormatUsageAuthority* authority = webgl->mFormatUsage.get();
+
+    auto addFormatIfMissing = [authority](EffectiveFormat effectiveFormat,
+                                          GLenum unpackFormat, GLenum unpackType,
+                                          bool asRenderbuffer)
+        {
+            if (!authority->GetUsage(effectiveFormat)) {
+                authority->AddFormat(effectiveFormat, asRenderbuffer, asRenderbuffer, true, true);
+                authority->AddUnpackOption(unpackFormat, unpackType, effectiveFormat);
+            }
+        };
+
+    addFormatIfMissing(EffectiveFormat::SRGB8       , LOCAL_GL_SRGB      , LOCAL_GL_UNSIGNED_BYTE, false);
+    addFormatIfMissing(EffectiveFormat::SRGB8_ALPHA8, LOCAL_GL_SRGB_ALPHA, LOCAL_GL_UNSIGNED_BYTE, true);
 }
 
 WebGLExtensionSRGB::~WebGLExtensionSRGB()
 {
 }
 
 bool
 WebGLExtensionSRGB::IsSupported(const WebGLContext* webgl)
--- a/dom/canvas/WebGLExtensionTextureFloat.cpp
+++ b/dom/canvas/WebGLExtensionTextureFloat.cpp
@@ -1,22 +1,65 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLExtensions.h"
 
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
 #include "WebGLContext.h"
+#include "WebGLFormats.h"
 
 namespace mozilla {
 
+using mozilla::webgl::EffectiveFormat;
+
+void
+WebGLExtensionTextureFloat::InitWebGLFormats(webgl::FormatUsageAuthority* authority)
+{
+    MOZ_ASSERT(authority);
+
+    auto addFormatIfMissing = [authority](EffectiveFormat effectiveFormat)
+        {
+            if (!authority->GetUsage(effectiveFormat)) {
+                authority->AddFormat(effectiveFormat, false, false, false, false);
+            }
+        };
+
+    // Populate authority with any missing effective formats.
+    addFormatIfMissing(EffectiveFormat::RGBA32F);
+    addFormatIfMissing(EffectiveFormat::RGB32F);
+    addFormatIfMissing(EffectiveFormat::Luminance32FAlpha32F);
+    addFormatIfMissing(EffectiveFormat::Luminance32F);
+    addFormatIfMissing(EffectiveFormat::Alpha32F);
+}
+
 WebGLExtensionTextureFloat::WebGLExtensionTextureFloat(WebGLContext* webgl)
     : WebGLExtensionBase(webgl)
 {
+    webgl::FormatUsageAuthority* authority = webgl->mFormatUsage.get();
+
+    auto updateUsage = [authority](EffectiveFormat effectiveFormat,
+                                   GLenum unpackFormat, GLenum unpackType)
+        {
+            webgl::FormatUsageInfo* usage = authority->GetUsage(effectiveFormat);
+            MOZ_ASSERT(usage);
+            usage->asTexture = true;
+            authority->AddUnpackOption(unpackFormat, unpackType, effectiveFormat);
+        };
+
+    // Ensure require formats are initialized.
+    InitWebGLFormats(authority);
+
+    // Update usage to allow asTexture and add unpack
+    updateUsage(EffectiveFormat::RGBA32F             , LOCAL_GL_RGBA           , LOCAL_GL_FLOAT);
+    updateUsage(EffectiveFormat::RGB32F              , LOCAL_GL_RGB            , LOCAL_GL_FLOAT);
+    updateUsage(EffectiveFormat::Luminance32FAlpha32F, LOCAL_GL_LUMINANCE_ALPHA, LOCAL_GL_FLOAT);
+    updateUsage(EffectiveFormat::Luminance32F        , LOCAL_GL_LUMINANCE      , LOCAL_GL_FLOAT);
+    updateUsage(EffectiveFormat::Alpha32F            , LOCAL_GL_ALPHA          , LOCAL_GL_FLOAT);
 }
 
 WebGLExtensionTextureFloat::~WebGLExtensionTextureFloat()
 {
 }
 
 IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionTextureFloat, OES_texture_float)
 
--- a/dom/canvas/WebGLExtensionTextureFloatLinear.cpp
+++ b/dom/canvas/WebGLExtensionTextureFloatLinear.cpp
@@ -1,22 +1,46 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLExtensions.h"
 
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
 #include "WebGLContext.h"
+#include "WebGLFormats.h"
 
 namespace mozilla {
 
+using mozilla::webgl::EffectiveFormat;
+
 WebGLExtensionTextureFloatLinear::WebGLExtensionTextureFloatLinear(WebGLContext* webgl)
     : WebGLExtensionBase(webgl)
 {
+    // This update requires that the authority already be populated by
+    // WebGLExtensionTextureFloat.  Enabling extensions to control
+    // features is a mess in WebGL
+
+    webgl::FormatUsageAuthority* authority = webgl->mFormatUsage.get();
+
+    auto updateUsage = [authority](EffectiveFormat effectiveFormat) {
+        webgl::FormatUsageInfo* usage = authority->GetUsage(effectiveFormat);
+        MOZ_ASSERT(usage);
+        usage->isFilterable = true;
+    };
+
+    // Ensure require formats are initialized.
+    WebGLExtensionTextureFloat::InitWebGLFormats(authority);
+
+    // Update usage to allow isFilterable
+    updateUsage(EffectiveFormat::RGBA32F);
+    updateUsage(EffectiveFormat::RGB32F);
+    updateUsage(EffectiveFormat::Luminance32FAlpha32F);
+    updateUsage(EffectiveFormat::Luminance32F);
+    updateUsage(EffectiveFormat::Alpha32F);
 }
 
 WebGLExtensionTextureFloatLinear::~WebGLExtensionTextureFloatLinear()
 {
 }
 
 IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionTextureFloatLinear, OES_texture_float_linear)
 
--- a/dom/canvas/WebGLExtensionTextureHalfFloat.cpp
+++ b/dom/canvas/WebGLExtensionTextureHalfFloat.cpp
@@ -1,22 +1,64 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLExtensions.h"
 
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
 #include "WebGLContext.h"
+#include "WebGLFormats.h"
 
 namespace mozilla {
 
+using mozilla::webgl::EffectiveFormat;
+
+void
+WebGLExtensionTextureHalfFloat::InitWebGLFormats(webgl::FormatUsageAuthority* authority)
+{
+    MOZ_ASSERT(authority);
+
+    auto addFormatIfMissing = [authority](EffectiveFormat effectiveFormat)
+        {
+            if (!authority->GetUsage(effectiveFormat)) {
+                authority->AddFormat(effectiveFormat, false, false, false, false);
+            }
+        };
+
+    // Populate authority with any missing effective formats.
+    addFormatIfMissing(EffectiveFormat::RGBA16F);
+    addFormatIfMissing(EffectiveFormat::RGB16F);
+    addFormatIfMissing(EffectiveFormat::Luminance16FAlpha16F);
+    addFormatIfMissing(EffectiveFormat::Luminance16F);
+    addFormatIfMissing(EffectiveFormat::Alpha16F);
+}
+
 WebGLExtensionTextureHalfFloat::WebGLExtensionTextureHalfFloat(WebGLContext* webgl)
     : WebGLExtensionBase(webgl)
 {
+    webgl::FormatUsageAuthority* authority = webgl->mFormatUsage.get();
+
+    auto updateUsage = [authority](EffectiveFormat effectiveFormat,
+                                   GLenum unpackFormat, GLenum unpackType)
+        {
+            webgl::FormatUsageInfo* usage = authority->GetUsage(effectiveFormat);
+            MOZ_ASSERT(usage);
+            usage->asTexture = true;
+            authority->AddUnpackOption(unpackFormat, unpackType, effectiveFormat);
+        };
+
+    InitWebGLFormats(authority);
+
+    // Update usage to allow asTexture and add unpack
+    updateUsage(EffectiveFormat::RGBA16F             , LOCAL_GL_RGBA           , LOCAL_GL_HALF_FLOAT_OES);
+    updateUsage(EffectiveFormat::RGB16F              , LOCAL_GL_RGB            , LOCAL_GL_HALF_FLOAT_OES);
+    updateUsage(EffectiveFormat::Luminance16FAlpha16F, LOCAL_GL_LUMINANCE_ALPHA, LOCAL_GL_HALF_FLOAT_OES);
+    updateUsage(EffectiveFormat::Luminance16F        , LOCAL_GL_LUMINANCE      , LOCAL_GL_HALF_FLOAT_OES);
+    updateUsage(EffectiveFormat::Alpha16F            , LOCAL_GL_ALPHA          , LOCAL_GL_HALF_FLOAT_OES);
 }
 
 WebGLExtensionTextureHalfFloat::~WebGLExtensionTextureHalfFloat()
 {
 }
 
 IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionTextureHalfFloat, OES_texture_half_float)
 
--- a/dom/canvas/WebGLExtensionTextureHalfFloatLinear.cpp
+++ b/dom/canvas/WebGLExtensionTextureHalfFloatLinear.cpp
@@ -1,22 +1,46 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLExtensions.h"
 
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
 #include "WebGLContext.h"
+#include "WebGLFormats.h"
 
 namespace mozilla {
 
+using mozilla::webgl::EffectiveFormat;
+
 WebGLExtensionTextureHalfFloatLinear::WebGLExtensionTextureHalfFloatLinear(WebGLContext* webgl)
     : WebGLExtensionBase(webgl)
 {
+    // This update requires that the authority already be populated by
+    // WebGLExtensionTextureHalfFloat.  Enabling extensions to control
+    // features is a mess in WebGL
+
+    webgl::FormatUsageAuthority* authority = webgl->mFormatUsage.get();
+
+    auto updateUsage = [authority](EffectiveFormat effectiveFormat) {
+        webgl::FormatUsageInfo* usage = authority->GetUsage(effectiveFormat);
+        MOZ_ASSERT(usage);
+        usage->isFilterable = true;
+    };
+
+    // Ensure require formats are initialized.
+    WebGLExtensionTextureHalfFloat::InitWebGLFormats(authority);
+
+    // Update usage to allow isFilterable
+    updateUsage(EffectiveFormat::RGBA16F);
+    updateUsage(EffectiveFormat::RGB16F);
+    updateUsage(EffectiveFormat::Luminance16FAlpha16F);
+    updateUsage(EffectiveFormat::Luminance16F);
+    updateUsage(EffectiveFormat::Alpha16F);
 }
 
 WebGLExtensionTextureHalfFloatLinear::~WebGLExtensionTextureHalfFloatLinear()
 {
 }
 
 IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionTextureHalfFloatLinear, OES_texture_half_float_linear)
 
--- a/dom/canvas/WebGLExtensions.h
+++ b/dom/canvas/WebGLExtensions.h
@@ -15,16 +15,20 @@
 
 namespace mozilla {
 
 namespace dom {
 template<typename T>
 class Sequence;
 } // namespace dom
 
+namespace webgl {
+class FormatUsageAuthority;
+} // namespace webgl
+
 class WebGLContext;
 class WebGLShader;
 class WebGLQuery;
 class WebGLTimerQuery;
 class WebGLVertexArray;
 
 class WebGLExtensionBase
     : public nsWrapperCache
@@ -205,16 +209,18 @@ public:
 
     DECL_WEBGL_EXTENSION_GOOP
 };
 
 class WebGLExtensionTextureFloat
     : public WebGLExtensionBase
 {
 public:
+    static void InitWebGLFormats(webgl::FormatUsageAuthority* authority);
+
     explicit WebGLExtensionTextureFloat(WebGLContext*);
     virtual ~WebGLExtensionTextureFloat();
 
     DECL_WEBGL_EXTENSION_GOOP
 };
 
 class WebGLExtensionTextureFloatLinear
     : public WebGLExtensionBase
@@ -225,16 +231,18 @@ public:
 
     DECL_WEBGL_EXTENSION_GOOP
 };
 
 class WebGLExtensionTextureHalfFloat
     : public WebGLExtensionBase
 {
 public:
+    static void InitWebGLFormats(webgl::FormatUsageAuthority* authority);
+
     explicit WebGLExtensionTextureHalfFloat(WebGLContext*);
     virtual ~WebGLExtensionTextureHalfFloat();
 
     DECL_WEBGL_EXTENSION_GOOP
 };
 
 class WebGLExtensionTextureHalfFloatLinear
     : public WebGLExtensionBase
--- a/dom/canvas/WebGLFormats.cpp
+++ b/dom/canvas/WebGLFormats.cpp
@@ -804,12 +804,10 @@ FormatUsageAuthority::AddUnpackOption(GL
 
     MOZ_RELEASE_ASSERT(usage->asTexture);
 
     auto res = usage->validUnpacks.insert(unpack);
     bool didInsert = res.second;
     MOZ_ALWAYS_TRUE(didInsert);
 }
 
-//////////////////////////////////////////////////////////////////////////////////////////
-
 } // namespace webgl
 } // namespace mozilla
--- a/dom/canvas/WebGLFormats.h
+++ b/dom/canvas/WebGLFormats.h
@@ -254,14 +254,12 @@ public:
     FormatUsageInfo* GetUsage(EffectiveFormat format);
 
     FormatUsageInfo* GetUsage(const FormatInfo* format)
     {
         return GetUsage(format->effectiveFormat);
     }
 };
 
-////////////////////////////////////////
-
 } // namespace webgl
 } // namespace mozilla
 
 #endif // WEBGL_FORMATS_H_