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"
10 #include "mozilla/dom/WebGLRenderingContextBinding.h"
11 #include "WebGLContext.h"
12 #include "WebGLFramebuffer.h"
13 #include "WebGLRenderbuffer.h"
14 #include "WebGLTexture.h"
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()
50 WebGLExtensionDrawBuffers::DrawBuffersWEBGL(const dom::Sequence
<GLenum
>& buffers
)
53 mContext
->ErrorInvalidOperation("drawBuffersWEBGL: Extension is lost.");
57 mContext
->DrawBuffers(buffers
);
61 WebGLExtensionDrawBuffers::IsSupported(const WebGLContext
* webgl
)
63 gl::GLContext
* gl
= webgl
->GL();
65 if (!gl
->IsSupported(gl::GLFeature::draw_buffers
))
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
)
80 if (size_t(supportedDrawBuffers
) < kMinDrawBuffers
)
86 IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionDrawBuffers
)
88 } // namespace mozilla