Line data Source code
1 : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #include "WebGLExtensions.h"
7 :
8 : #include "GLContext.h"
9 : #include "mozilla/dom/WebGLRenderingContextBinding.h"
10 : #include "WebGLContext.h"
11 : #include "WebGLFormats.h"
12 :
13 : namespace mozilla {
14 :
15 0 : WebGLExtensionSRGB::WebGLExtensionSRGB(WebGLContext* webgl)
16 0 : : WebGLExtensionBase(webgl)
17 : {
18 0 : MOZ_ASSERT(IsSupported(webgl), "Don't construct extension if unsupported.");
19 :
20 0 : gl::GLContext* gl = webgl->GL();
21 0 : if (!gl->IsGLES()) {
22 : // Desktop OpenGL requires the following to be enabled in order to
23 : // support sRGB operations on framebuffers.
24 0 : gl->MakeCurrent();
25 0 : gl->fEnable(LOCAL_GL_FRAMEBUFFER_SRGB_EXT);
26 : }
27 :
28 0 : auto& fua = webgl->mFormatUsage;
29 :
30 0 : RefPtr<gl::GLContext> gl_ = gl; // Bug 1201275
31 : const auto fnAdd = [&fua, &gl_](webgl::EffectiveFormat effFormat, GLenum format,
32 0 : GLenum desktopUnpackFormat)
33 0 : {
34 0 : auto usage = fua->EditUsage(effFormat);
35 0 : usage->isFilterable = true;
36 :
37 0 : webgl::DriverUnpackInfo dui = {format, format, LOCAL_GL_UNSIGNED_BYTE};
38 0 : const auto pi = dui.ToPacking();
39 :
40 0 : if (!gl_->IsGLES())
41 0 : dui.unpackFormat = desktopUnpackFormat;
42 :
43 0 : fua->AddTexUnpack(usage, pi, dui);
44 :
45 0 : fua->AllowUnsizedTexFormat(pi, usage);
46 0 : };
47 :
48 0 : fnAdd(webgl::EffectiveFormat::SRGB8, LOCAL_GL_SRGB, LOCAL_GL_RGB);
49 0 : fnAdd(webgl::EffectiveFormat::SRGB8_ALPHA8, LOCAL_GL_SRGB_ALPHA, LOCAL_GL_RGBA);
50 :
51 0 : auto usage = fua->EditUsage(webgl::EffectiveFormat::SRGB8_ALPHA8);
52 0 : usage->SetRenderable();
53 0 : fua->AllowRBFormat(LOCAL_GL_SRGB8_ALPHA8, usage);
54 0 : }
55 :
56 0 : WebGLExtensionSRGB::~WebGLExtensionSRGB()
57 : {
58 0 : }
59 :
60 : bool
61 0 : WebGLExtensionSRGB::IsSupported(const WebGLContext* webgl)
62 : {
63 0 : gl::GLContext* gl = webgl->GL();
64 :
65 0 : return gl->IsSupported(gl::GLFeature::sRGB_framebuffer) &&
66 0 : gl->IsSupported(gl::GLFeature::sRGB_texture);
67 : }
68 :
69 :
70 0 : IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionSRGB, EXT_sRGB)
71 :
72 : } // namespace mozilla
|