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
|
|
|
|
2015-07-17 03:27:26 +03:00
|
|
|
using mozilla::webgl::EffectiveFormat;
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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);
|
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
|