Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / dom / canvas / WebGLExtensionDrawBuffers.cpp
blobca04a2be9e23fbb30fa2b09c7b866102044c382c
1 /* -*- Mode: C++; tab-width: 4; 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 file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "WebGLExtensions.h"
8 #include <algorithm>
9 #include "GLContext.h"
10 #include "mozilla/dom/WebGLRenderingContextBinding.h"
11 #include "WebGLContext.h"
12 #include "WebGLFramebuffer.h"
13 #include "WebGLRenderbuffer.h"
14 #include "WebGLTexture.h"
16 namespace mozilla {
18 WebGLExtensionDrawBuffers::WebGLExtensionDrawBuffers(WebGLContext* webgl)
19 : WebGLExtensionBase(webgl)
21 MOZ_ASSERT(IsSupported(webgl), "Don't construct extension if unsupported.");
23 GLint maxColorAttachments = 0;
24 GLint maxDrawBuffers = 0;
26 webgl->MakeContextCurrent();
27 gl::GLContext* gl = webgl->GL();
29 gl->fGetIntegerv(LOCAL_GL_MAX_COLOR_ATTACHMENTS, &maxColorAttachments);
30 gl->fGetIntegerv(LOCAL_GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
32 // WEBGL_draw_buffers specifications don't give a maximal value reachable by MAX_COLOR_ATTACHMENTS.
33 maxColorAttachments = std::min(maxColorAttachments, GLint(WebGLContext::kMaxColorAttachments));
35 if (webgl->MinCapabilityMode())
36 maxColorAttachments = std::min(maxColorAttachments, GLint(kMinColorAttachments));
38 // WEBGL_draw_buffers specifications request MAX_COLOR_ATTACHMENTS >= MAX_DRAW_BUFFERS.
39 maxDrawBuffers = std::min(maxDrawBuffers, GLint(maxColorAttachments));
41 webgl->mGLMaxColorAttachments = maxColorAttachments;
42 webgl->mGLMaxDrawBuffers = maxDrawBuffers;
45 WebGLExtensionDrawBuffers::~WebGLExtensionDrawBuffers()
49 void
50 WebGLExtensionDrawBuffers::DrawBuffersWEBGL(const dom::Sequence<GLenum>& buffers)
52 if (mIsLost) {
53 mContext->ErrorInvalidOperation("drawBuffersWEBGL: Extension is lost.");
54 return;
57 mContext->DrawBuffers(buffers);
60 bool
61 WebGLExtensionDrawBuffers::IsSupported(const WebGLContext* webgl)
63 gl::GLContext* gl = webgl->GL();
65 if (!gl->IsSupported(gl::GLFeature::draw_buffers))
66 return false;
68 GLint supportedColorAttachments = 0;
69 GLint supportedDrawBuffers = 0;
71 webgl->MakeContextCurrent();
73 gl->fGetIntegerv(LOCAL_GL_MAX_COLOR_ATTACHMENTS, &supportedColorAttachments);
74 gl->fGetIntegerv(LOCAL_GL_MAX_COLOR_ATTACHMENTS, &supportedDrawBuffers);
76 // WEBGL_draw_buffers requires at least 4 color attachments.
77 if (size_t(supportedColorAttachments) < kMinColorAttachments)
78 return false;
80 if (size_t(supportedDrawBuffers) < kMinDrawBuffers)
81 return false;
83 return true;
86 IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionDrawBuffers)
88 } // namespace mozilla