From 2ff8750146c658f9cc20bce43fa24de1cfd39976 Mon Sep 17 00:00:00 2001 From: Dan Glastonbury Date: Fri, 17 Jul 2015 10:27:26 +1000 Subject: [PATCH] Bug 1184402 - Part 3: Add WebGL1 formats when enabling extensions. r=jgilbert --- dom/canvas/WebGL2Context.cpp | 2 - dom/canvas/WebGLExtensionColorBufferFloat.cpp | 21 +++++++++ .../WebGLExtensionColorBufferHalfFloat.cpp | 21 +++++++++ dom/canvas/WebGLExtensionSRGB.cpp | 19 ++++++++ dom/canvas/WebGLExtensionTextureFloat.cpp | 43 +++++++++++++++++++ .../WebGLExtensionTextureFloatLinear.cpp | 24 +++++++++++ dom/canvas/WebGLExtensionTextureHalfFloat.cpp | 42 ++++++++++++++++++ .../WebGLExtensionTextureHalfFloatLinear.cpp | 24 +++++++++++ dom/canvas/WebGLExtensions.h | 8 ++++ dom/canvas/WebGLFormats.cpp | 2 - dom/canvas/WebGLFormats.h | 2 - 11 files changed, 202 insertions(+), 6 deletions(-) diff --git a/dom/canvas/WebGL2Context.cpp b/dom/canvas/WebGL2Context.cpp index 9e699bd3e0fa..c64672d2958d 100644 --- a/dom/canvas/WebGL2Context.cpp +++ b/dom/canvas/WebGL2Context.cpp @@ -58,9 +58,7 @@ static const WebGLExtensionID kNativelySupportedExtensions[] = { 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, diff --git a/dom/canvas/WebGLExtensionColorBufferFloat.cpp b/dom/canvas/WebGLExtensionColorBufferFloat.cpp index 542494d2dd11..89c9cb1d8a0c 100644 --- a/dom/canvas/WebGLExtensionColorBufferFloat.cpp +++ b/dom/canvas/WebGLExtensionColorBufferFloat.cpp @@ -7,13 +7,34 @@ #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() diff --git a/dom/canvas/WebGLExtensionColorBufferHalfFloat.cpp b/dom/canvas/WebGLExtensionColorBufferHalfFloat.cpp index 89d06cdb5093..e80535c48142 100644 --- a/dom/canvas/WebGLExtensionColorBufferHalfFloat.cpp +++ b/dom/canvas/WebGLExtensionColorBufferHalfFloat.cpp @@ -7,13 +7,34 @@ #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() diff --git a/dom/canvas/WebGLExtensionSRGB.cpp b/dom/canvas/WebGLExtensionSRGB.cpp index d7526147fcf5..0502ae0243aa 100644 --- a/dom/canvas/WebGLExtensionSRGB.cpp +++ b/dom/canvas/WebGLExtensionSRGB.cpp @@ -8,9 +8,13 @@ #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) { @@ -23,6 +27,21 @@ WebGLExtensionSRGB::WebGLExtensionSRGB(WebGLContext* webgl) 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() diff --git a/dom/canvas/WebGLExtensionTextureFloat.cpp b/dom/canvas/WebGLExtensionTextureFloat.cpp index b85a75b14a0f..50d7b0cd6e4a 100644 --- a/dom/canvas/WebGLExtensionTextureFloat.cpp +++ b/dom/canvas/WebGLExtensionTextureFloat.cpp @@ -6,12 +6,55 @@ #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() diff --git a/dom/canvas/WebGLExtensionTextureFloatLinear.cpp b/dom/canvas/WebGLExtensionTextureFloatLinear.cpp index 69459dc74219..1a9330c3c42c 100644 --- a/dom/canvas/WebGLExtensionTextureFloatLinear.cpp +++ b/dom/canvas/WebGLExtensionTextureFloatLinear.cpp @@ -6,12 +6,36 @@ #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() diff --git a/dom/canvas/WebGLExtensionTextureHalfFloat.cpp b/dom/canvas/WebGLExtensionTextureHalfFloat.cpp index 27f80c67007b..044b60737a14 100644 --- a/dom/canvas/WebGLExtensionTextureHalfFloat.cpp +++ b/dom/canvas/WebGLExtensionTextureHalfFloat.cpp @@ -6,12 +6,54 @@ #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() diff --git a/dom/canvas/WebGLExtensionTextureHalfFloatLinear.cpp b/dom/canvas/WebGLExtensionTextureHalfFloatLinear.cpp index 21912069ef34..73949137eb5a 100644 --- a/dom/canvas/WebGLExtensionTextureHalfFloatLinear.cpp +++ b/dom/canvas/WebGLExtensionTextureHalfFloatLinear.cpp @@ -6,12 +6,36 @@ #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() diff --git a/dom/canvas/WebGLExtensions.h b/dom/canvas/WebGLExtensions.h index a474b5919a1b..4025ba541d9b 100644 --- a/dom/canvas/WebGLExtensions.h +++ b/dom/canvas/WebGLExtensions.h @@ -20,6 +20,10 @@ template class Sequence; } // namespace dom +namespace webgl { +class FormatUsageAuthority; +} // namespace webgl + class WebGLContext; class WebGLShader; class WebGLQuery; @@ -210,6 +214,8 @@ class WebGLExtensionTextureFloat : public WebGLExtensionBase { public: + static void InitWebGLFormats(webgl::FormatUsageAuthority* authority); + explicit WebGLExtensionTextureFloat(WebGLContext*); virtual ~WebGLExtensionTextureFloat(); @@ -230,6 +236,8 @@ class WebGLExtensionTextureHalfFloat : public WebGLExtensionBase { public: + static void InitWebGLFormats(webgl::FormatUsageAuthority* authority); + explicit WebGLExtensionTextureHalfFloat(WebGLContext*); virtual ~WebGLExtensionTextureHalfFloat(); diff --git a/dom/canvas/WebGLFormats.cpp b/dom/canvas/WebGLFormats.cpp index 42dc4de6ad2f..0028dde7af6f 100644 --- a/dom/canvas/WebGLFormats.cpp +++ b/dom/canvas/WebGLFormats.cpp @@ -809,7 +809,5 @@ FormatUsageAuthority::AddUnpackOption(GLenum unpackFormat, GLenum unpackType, MOZ_ALWAYS_TRUE(didInsert); } -////////////////////////////////////////////////////////////////////////////////////////// - } // namespace webgl } // namespace mozilla diff --git a/dom/canvas/WebGLFormats.h b/dom/canvas/WebGLFormats.h index a523d51dbc01..33735bab473f 100644 --- a/dom/canvas/WebGLFormats.h +++ b/dom/canvas/WebGLFormats.h @@ -259,8 +259,6 @@ public: } }; -//////////////////////////////////////// - } // namespace webgl } // namespace mozilla