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 
WebGLExtensionColorBufferFloat(WebGLContext * webgl)14 WebGLExtensionColorBufferFloat::WebGLExtensionColorBufferFloat(
15     WebGLContext* webgl)
16     : WebGLExtensionBase(webgl) {
17   MOZ_ASSERT(IsSupported(webgl), "Don't construct extension if unsupported.");
18   SetRenderable(webgl::FormatRenderableState::Implicit(
19       WebGLExtensionID::WEBGL_color_buffer_float));
20 }
21 
SetRenderable(const webgl::FormatRenderableState state)22 void WebGLExtensionColorBufferFloat::SetRenderable(
23     const webgl::FormatRenderableState state) {
24   auto& fua = mContext->mFormatUsage;
25 
26   auto fnUpdateUsage = [&](GLenum sizedFormat,
27                            webgl::EffectiveFormat effFormat) {
28     auto usage = fua->EditUsage(effFormat);
29     usage->SetRenderable(state);
30     fua->AllowRBFormat(sizedFormat, usage);
31   };
32 
33 #define FOO(x) fnUpdateUsage(LOCAL_GL_##x, webgl::EffectiveFormat::x)
34 
35   // The extension doesn't actually add RGB32F; only RGBA32F.
36   FOO(RGBA32F);
37 
38 #undef FOO
39 }
40 
OnSetExplicit()41 void WebGLExtensionColorBufferFloat::OnSetExplicit() {
42   SetRenderable(webgl::FormatRenderableState::Explicit());
43 }
44 
IsSupported(const WebGLContext * webgl)45 bool WebGLExtensionColorBufferFloat::IsSupported(const WebGLContext* webgl) {
46   if (webgl->IsWebGL2()) return false;
47 
48   const auto& gl = webgl->gl;
49   return gl->IsSupported(gl::GLFeature::renderbuffer_color_float) &&
50          gl->IsSupported(gl::GLFeature::frag_color_float);
51 }
52 
53 }  // namespace mozilla
54