Line data Source code
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/. */
5 :
6 : #include "WebGLExtensions.h"
7 :
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"
15 :
16 : namespace mozilla {
17 :
18 0 : WebGLExtensionDrawBuffers::WebGLExtensionDrawBuffers(WebGLContext* webgl)
19 0 : : WebGLExtensionBase(webgl)
20 : {
21 0 : MOZ_ASSERT(IsSupported(webgl), "Don't construct extension if unsupported.");
22 :
23 : // WEBGL_draw_buffers:
24 : // "The value of the MAX_COLOR_ATTACHMENTS_WEBGL parameter must be greater than or
25 : // equal to that of the MAX_DRAW_BUFFERS_WEBGL parameter."
26 0 : webgl->mImplMaxColorAttachments = webgl->mGLMaxColorAttachments;
27 0 : webgl->mImplMaxDrawBuffers = std::min(webgl->mGLMaxDrawBuffers,
28 0 : webgl->mImplMaxColorAttachments);
29 0 : }
30 :
31 0 : WebGLExtensionDrawBuffers::~WebGLExtensionDrawBuffers()
32 : {
33 0 : }
34 :
35 : void
36 0 : WebGLExtensionDrawBuffers::DrawBuffersWEBGL(const dom::Sequence<GLenum>& buffers)
37 : {
38 0 : if (mIsLost) {
39 0 : mContext->ErrorInvalidOperation("drawBuffersWEBGL: Extension is lost.");
40 0 : return;
41 : }
42 :
43 0 : mContext->DrawBuffers(buffers);
44 : }
45 :
46 : bool
47 0 : WebGLExtensionDrawBuffers::IsSupported(const WebGLContext* webgl)
48 : {
49 0 : gl::GLContext* gl = webgl->GL();
50 :
51 0 : if (!gl->IsExtensionSupported(gl::GLContext::ARB_draw_buffers) &&
52 0 : !gl->IsExtensionSupported(gl::GLContext::EXT_draw_buffers))
53 : {
54 0 : return false;
55 : }
56 :
57 : // WEBGL_draw_buffers requires at least 4 color attachments.
58 0 : if (webgl->mGLMaxDrawBuffers < webgl->kMinMaxDrawBuffers ||
59 0 : webgl->mGLMaxColorAttachments < webgl->kMinMaxColorAttachments)
60 : {
61 0 : return false;
62 : }
63 :
64 0 : return true;
65 : }
66 :
67 0 : IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionDrawBuffers, WEBGL_draw_buffers)
68 :
69 : } // namespace mozilla
|