2013-11-05 01:05:04 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* 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
|
|
|
|
2013-11-05 01:05:04 +04:00
|
|
|
#include "GLContext.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "mozilla/dom/WebGLRenderingContextBinding.h"
|
|
|
|
#include "WebGLContext.h"
|
2015-07-17 03:27:26 +03:00
|
|
|
#include "WebGLFormats.h"
|
2013-11-05 01:05:04 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
namespace mozilla {
|
2013-11-05 01:05:04 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLExtensionSRGB::WebGLExtensionSRGB(WebGLContext* webgl)
|
|
|
|
: WebGLExtensionBase(webgl)
|
2013-11-05 01:05:04 +04:00
|
|
|
{
|
2014-11-14 07:03:50 +03:00
|
|
|
MOZ_ASSERT(IsSupported(webgl), "Don't construct extension if unsupported.");
|
|
|
|
|
|
|
|
gl::GLContext* gl = webgl->GL();
|
2013-11-05 01:05:04 +04:00
|
|
|
if (!gl->IsGLES()) {
|
2014-11-14 07:03:50 +03:00
|
|
|
// Desktop OpenGL requires the following to be enabled in order to
|
|
|
|
// support sRGB operations on framebuffers.
|
2013-11-05 01:05:04 +04:00
|
|
|
gl->MakeCurrent();
|
|
|
|
gl->fEnable(LOCAL_GL_FRAMEBUFFER_SRGB_EXT);
|
|
|
|
}
|
2015-07-17 03:27:26 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
auto& fua = webgl->mFormatUsage;
|
|
|
|
|
|
|
|
RefPtr<gl::GLContext> gl_ = gl; // Bug 1201275
|
|
|
|
const auto fnAdd = [&fua, &gl_](webgl::EffectiveFormat effFormat, GLenum format,
|
|
|
|
GLenum desktopUnpackFormat)
|
|
|
|
{
|
|
|
|
auto usage = fua->EditUsage(effFormat);
|
|
|
|
usage->isFilterable = true;
|
|
|
|
|
|
|
|
webgl::DriverUnpackInfo dui = {format, format, LOCAL_GL_UNSIGNED_BYTE};
|
|
|
|
const auto pi = dui.ToPacking();
|
|
|
|
|
|
|
|
if (!gl_->IsGLES())
|
|
|
|
dui.unpackFormat = desktopUnpackFormat;
|
|
|
|
|
|
|
|
fua->AddTexUnpack(usage, pi, dui);
|
|
|
|
|
|
|
|
fua->AllowUnsizedTexFormat(pi, usage);
|
|
|
|
};
|
2015-07-17 03:27:26 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
fnAdd(webgl::EffectiveFormat::SRGB8, LOCAL_GL_SRGB, LOCAL_GL_RGB);
|
|
|
|
fnAdd(webgl::EffectiveFormat::SRGB8_ALPHA8, LOCAL_GL_SRGB_ALPHA, LOCAL_GL_RGBA);
|
2015-07-17 03:27:26 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
auto usage = fua->EditUsage(webgl::EffectiveFormat::SRGB8_ALPHA8);
|
2016-06-06 23:43:18 +03:00
|
|
|
usage->SetRenderable();
|
2015-11-25 07:15:29 +03:00
|
|
|
fua->AllowRBFormat(LOCAL_GL_SRGB8_ALPHA8, usage);
|
2013-11-05 01:05:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
WebGLExtensionSRGB::~WebGLExtensionSRGB()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLExtensionSRGB::IsSupported(const WebGLContext* webgl)
|
2013-11-05 01:05:04 +04:00
|
|
|
{
|
2014-11-14 07:03:50 +03:00
|
|
|
gl::GLContext* gl = webgl->GL();
|
2013-11-05 01:05:04 +04:00
|
|
|
|
2015-03-24 10:11:10 +03:00
|
|
|
return gl->IsSupported(gl::GLFeature::sRGB_framebuffer) &&
|
|
|
|
gl->IsSupported(gl::GLFeature::sRGB_texture);
|
2013-11-05 01:05:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-01 17:17:00 +03:00
|
|
|
IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionSRGB, EXT_sRGB)
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|