1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 #include "WebGLExtensions.h"
6
7 #include "GLContext.h"
8 #include "mozilla/dom/WebGLRenderingContextBinding.h"
9 #include "WebGLContext.h"
10 #include "WebGLFormats.h"
11
12 namespace mozilla {
13
WebGLExtensionColorBufferHalfFloat(WebGLContext * webgl)14 WebGLExtensionColorBufferHalfFloat::WebGLExtensionColorBufferHalfFloat(
15 WebGLContext* webgl)
16 : WebGLExtensionBase(webgl) {
17 MOZ_ASSERT(IsSupported(webgl), "Don't construct extension if unsupported.");
18 SetRenderable(webgl::FormatRenderableState::Implicit(
19 WebGLExtensionID::EXT_color_buffer_half_float));
20 }
21
SetRenderable(const webgl::FormatRenderableState state)22 void WebGLExtensionColorBufferHalfFloat::SetRenderable(
23 const webgl::FormatRenderableState state) {
24 auto& fua = mContext->mFormatUsage;
25
26 auto fnUpdateUsage = [&](GLenum sizedFormat, webgl::EffectiveFormat effFormat,
27 const bool renderable) {
28 auto usage = fua->EditUsage(effFormat);
29 if (renderable) {
30 usage->SetRenderable(state);
31 }
32 fua->AllowRBFormat(sizedFormat, usage, renderable);
33 };
34
35 #define FOO(x, y) fnUpdateUsage(LOCAL_GL_##x, webgl::EffectiveFormat::x, y)
36
37 FOO(RGBA16F, true);
38 FOO(RGB16F, false); // It's not required, thus not portable. (Also there's a
39 // wicked driver bug on Mac+Intel)
40
41 #undef FOO
42 }
43
OnSetExplicit()44 void WebGLExtensionColorBufferHalfFloat::OnSetExplicit() {
45 SetRenderable(webgl::FormatRenderableState::Explicit());
46 }
47
IsSupported(const WebGLContext * webgl)48 bool WebGLExtensionColorBufferHalfFloat::IsSupported(
49 const WebGLContext* webgl) {
50 if (webgl->IsWebGL2()) return false;
51
52 const auto& gl = webgl->gl;
53 return gl->IsSupported(gl::GLFeature::renderbuffer_color_half_float) &&
54 gl->IsSupported(gl::GLFeature::frag_color_float);
55 }
56
57 } // namespace mozilla
58