1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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/. */
6 #include "WebGLExtensions.h"
9 #include "mozilla/dom/WebGLRenderingContextBinding.h"
10 #include "WebGLContext.h"
11 #include "WebGLFormats.h"
15 WebGLExtensionSRGB::WebGLExtensionSRGB(WebGLContext
* webgl
)
16 : WebGLExtensionBase(webgl
) {
17 MOZ_ASSERT(IsSupported(webgl
), "Don't construct extension if unsupported.");
19 gl::GLContext
* gl
= webgl
->GL();
21 // Desktop OpenGL requires the following to be enabled in order to
22 // support sRGB operations on framebuffers.
23 gl
->fEnable(LOCAL_GL_FRAMEBUFFER_SRGB_EXT
);
26 auto& fua
= webgl
->mFormatUsage
;
28 RefPtr
<gl::GLContext
> gl_
= gl
; // Bug 1201275
29 const auto fnAdd
= [&fua
, &gl_
](webgl::EffectiveFormat effFormat
,
30 GLenum format
, GLenum desktopUnpackFormat
) {
31 auto usage
= fua
->EditUsage(effFormat
);
32 usage
->isFilterable
= true;
34 webgl::DriverUnpackInfo dui
= {format
, format
, LOCAL_GL_UNSIGNED_BYTE
};
35 const auto pi
= dui
.ToPacking();
37 if (!gl_
->IsGLES()) dui
.unpackFormat
= desktopUnpackFormat
;
39 fua
->AddTexUnpack(usage
, pi
, dui
);
41 fua
->AllowUnsizedTexFormat(pi
, usage
);
44 fnAdd(webgl::EffectiveFormat::SRGB8
, LOCAL_GL_SRGB
, LOCAL_GL_RGB
);
45 fnAdd(webgl::EffectiveFormat::SRGB8_ALPHA8
, LOCAL_GL_SRGB_ALPHA
,
48 auto usage
= fua
->EditUsage(webgl::EffectiveFormat::SRGB8_ALPHA8
);
49 usage
->SetRenderable();
50 fua
->AllowRBFormat(LOCAL_GL_SRGB8_ALPHA8
, usage
);
53 bool WebGLExtensionSRGB::IsSupported(const WebGLContext
* const webgl
) {
54 if (webgl
->IsWebGL2()) return false;
56 return webgl
->gl
->IsSupported(gl::GLFeature::sRGB
);
59 } // namespace mozilla