2012-10-04 01:13:05 +04:00
|
|
|
/* 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"
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
#include "GLContext.h"
|
2012-10-04 01:13:05 +04:00
|
|
|
#include "mozilla/dom/WebGLRenderingContextBinding.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "WebGLContext.h"
|
2015-07-17 03:27:26 +03:00
|
|
|
#include "WebGLFormats.h"
|
2012-10-04 01:13:05 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
namespace mozilla {
|
2012-10-04 01:13:05 +04:00
|
|
|
|
2015-11-24 08:55:59 +03:00
|
|
|
WebGLExtensionTextureFloat::WebGLExtensionTextureFloat(WebGLContext* webgl)
|
|
|
|
: WebGLExtensionBase(webgl) {
|
2015-11-25 07:15:29 +03:00
|
|
|
MOZ_ASSERT(IsSupported(webgl));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
auto& fua = webgl->mFormatUsage;
|
|
|
|
gl::GLContext* gl = webgl->GL();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
webgl::PackingInfo pi;
|
|
|
|
webgl::DriverUnpackInfo dui;
|
|
|
|
const GLint* swizzle = nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
const auto fnAdd = [&fua, &pi, &dui,
|
|
|
|
&swizzle](webgl::EffectiveFormat effFormat) {
|
|
|
|
auto usage = fua->EditUsage(effFormat);
|
|
|
|
usage->textureSwizzleRGBA = swizzle;
|
|
|
|
fua->AddTexUnpack(usage, pi, dui);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
fua->AllowUnsizedTexFormat(pi, usage);
|
|
|
|
};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-01-29 01:27:57 +03:00
|
|
|
const bool needsSwizzle = gl->IsCoreProfile();
|
|
|
|
MOZ_ASSERT_IF(needsSwizzle, gl->IsSupported(gl::GLFeature::texture_swizzle));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-01-29 01:27:57 +03:00
|
|
|
const bool needsSizedFormat = !gl->IsGLES();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
////////////////
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
pi = {LOCAL_GL_RGBA, LOCAL_GL_FLOAT};
|
|
|
|
dui = {pi.format, pi.format, pi.type};
|
|
|
|
swizzle = nullptr;
|
2019-03-28 00:42:56 +03:00
|
|
|
if (needsSizedFormat ||
|
2019-03-30 09:42:18 +03:00
|
|
|
gl->IsExtensionSupported(
|
|
|
|
gl::GLContext::CHROMIUM_color_buffer_float_rgba)) {
|
2015-11-25 07:15:29 +03:00
|
|
|
dui.internalFormat = LOCAL_GL_RGBA32F;
|
|
|
|
}
|
|
|
|
fnAdd(webgl::EffectiveFormat::RGBA32F);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
//////
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
pi = {LOCAL_GL_RGB, LOCAL_GL_FLOAT};
|
|
|
|
dui = {pi.format, pi.format, pi.type};
|
|
|
|
swizzle = nullptr;
|
2016-01-29 01:27:57 +03:00
|
|
|
if (needsSizedFormat) {
|
2015-11-25 07:15:29 +03:00
|
|
|
dui.internalFormat = LOCAL_GL_RGB32F;
|
|
|
|
}
|
|
|
|
fnAdd(webgl::EffectiveFormat::RGB32F);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
//////
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
pi = {LOCAL_GL_LUMINANCE, LOCAL_GL_FLOAT};
|
|
|
|
dui = {pi.format, pi.format, pi.type};
|
|
|
|
swizzle = nullptr;
|
2016-01-29 01:27:57 +03:00
|
|
|
if (needsSwizzle) {
|
2015-11-25 07:15:29 +03:00
|
|
|
dui = {LOCAL_GL_R32F, LOCAL_GL_RED, LOCAL_GL_FLOAT};
|
|
|
|
swizzle = webgl::FormatUsageInfo::kLuminanceSwizzleRGBA;
|
2016-01-29 01:27:57 +03:00
|
|
|
} else if (needsSizedFormat) {
|
|
|
|
dui.internalFormat = LOCAL_GL_LUMINANCE32F_ARB;
|
2015-11-25 07:15:29 +03:00
|
|
|
}
|
|
|
|
fnAdd(webgl::EffectiveFormat::Luminance32F);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
//////
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
pi = {LOCAL_GL_ALPHA, LOCAL_GL_FLOAT};
|
|
|
|
dui = {pi.format, pi.format, pi.type};
|
|
|
|
swizzle = nullptr;
|
2016-01-29 01:27:57 +03:00
|
|
|
if (needsSwizzle) {
|
2015-11-25 07:15:29 +03:00
|
|
|
dui = {LOCAL_GL_R32F, LOCAL_GL_RED, LOCAL_GL_FLOAT};
|
|
|
|
swizzle = webgl::FormatUsageInfo::kAlphaSwizzleRGBA;
|
2016-01-29 01:27:57 +03:00
|
|
|
} else if (needsSizedFormat) {
|
|
|
|
dui.internalFormat = LOCAL_GL_ALPHA32F_ARB;
|
2015-11-25 07:15:29 +03:00
|
|
|
}
|
|
|
|
fnAdd(webgl::EffectiveFormat::Alpha32F);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
//////
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
pi = {LOCAL_GL_LUMINANCE_ALPHA, LOCAL_GL_FLOAT};
|
|
|
|
dui = {pi.format, pi.format, pi.type};
|
|
|
|
swizzle = nullptr;
|
2016-01-29 01:27:57 +03:00
|
|
|
if (needsSwizzle) {
|
2015-11-25 07:15:29 +03:00
|
|
|
dui = {LOCAL_GL_RG32F, LOCAL_GL_RG, LOCAL_GL_FLOAT};
|
|
|
|
swizzle = webgl::FormatUsageInfo::kLumAlphaSwizzleRGBA;
|
2016-01-29 01:27:57 +03:00
|
|
|
} else if (needsSizedFormat) {
|
|
|
|
dui.internalFormat = LOCAL_GL_LUMINANCE_ALPHA32F_ARB;
|
2015-11-25 07:15:29 +03:00
|
|
|
}
|
|
|
|
fnAdd(webgl::EffectiveFormat::Luminance32FAlpha32F);
|
2012-10-04 01:13:05 +04:00
|
|
|
}
|
|
|
|
|
2015-11-24 08:55:59 +03:00
|
|
|
WebGLExtensionTextureFloat::~WebGLExtensionTextureFloat() {}
|
2015-11-24 06:27:13 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
bool WebGLExtensionTextureFloat::IsSupported(const WebGLContext* webgl) {
|
2019-02-05 06:34:49 +03:00
|
|
|
if (webgl->IsWebGL2()) return false;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2019-02-05 06:34:49 +03:00
|
|
|
gl::GLContext* gl = webgl->GL();
|
2015-11-25 07:15:29 +03:00
|
|
|
if (!gl->IsSupported(gl::GLFeature::texture_float)) return false;
|
|
|
|
|
2016-01-29 01:27:57 +03:00
|
|
|
const bool needsSwizzle = gl->IsCoreProfile();
|
2015-11-25 07:15:29 +03:00
|
|
|
const bool hasSwizzle = gl->IsSupported(gl::GLFeature::texture_swizzle);
|
2016-01-29 01:27:57 +03:00
|
|
|
if (needsSwizzle && !hasSwizzle) return false;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-01 17:17:00 +03:00
|
|
|
IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionTextureFloat, OES_texture_float)
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|