michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "WebGLContext.h" michael@0: #include "WebGLExtensions.h" michael@0: #include "mozilla/dom/WebGLRenderingContextBinding.h" michael@0: #include "WebGLTexture.h" michael@0: #include "WebGLRenderbuffer.h" michael@0: #include "WebGLFramebuffer.h" michael@0: #include "GLContext.h" michael@0: michael@0: #include michael@0: michael@0: using namespace mozilla; michael@0: using namespace gl; michael@0: michael@0: WebGLExtensionDrawBuffers::WebGLExtensionDrawBuffers(WebGLContext* context) michael@0: : WebGLExtensionBase(context) michael@0: { michael@0: GLint maxColorAttachments = 0; michael@0: GLint maxDrawBuffers = 0; michael@0: michael@0: gl::GLContext* gl = context->GL(); michael@0: michael@0: context->MakeContextCurrent(); michael@0: michael@0: gl->fGetIntegerv(LOCAL_GL_MAX_COLOR_ATTACHMENTS, &maxColorAttachments); michael@0: gl->fGetIntegerv(LOCAL_GL_MAX_DRAW_BUFFERS, &maxDrawBuffers); michael@0: michael@0: // WEBGL_draw_buffers specifications don't give a maximal value reachable by MAX_COLOR_ATTACHMENTS. michael@0: maxColorAttachments = std::min(maxColorAttachments, GLint(WebGLContext::sMaxColorAttachments)); michael@0: michael@0: if (context->MinCapabilityMode()) michael@0: { michael@0: maxColorAttachments = std::min(maxColorAttachments, GLint(sMinColorAttachments)); michael@0: } michael@0: michael@0: // WEBGL_draw_buffers specifications request MAX_COLOR_ATTACHMENTS >= MAX_DRAW_BUFFERS. michael@0: maxDrawBuffers = std::min(maxDrawBuffers, GLint(maxColorAttachments)); michael@0: michael@0: context->mGLMaxColorAttachments = maxColorAttachments; michael@0: context->mGLMaxDrawBuffers = maxDrawBuffers; michael@0: } michael@0: michael@0: WebGLExtensionDrawBuffers::~WebGLExtensionDrawBuffers() michael@0: { michael@0: } michael@0: michael@0: void WebGLExtensionDrawBuffers::DrawBuffersWEBGL(const dom::Sequence& buffers) michael@0: { michael@0: if (mIsLost) michael@0: return mContext->ErrorInvalidOperation("drawBuffersWEBGL: Extension is lost."); michael@0: michael@0: mContext->DrawBuffers(buffers); michael@0: } michael@0: michael@0: bool WebGLExtensionDrawBuffers::IsSupported(const WebGLContext* context) michael@0: { michael@0: gl::GLContext * gl = context->GL(); michael@0: michael@0: if (!gl->IsSupported(GLFeature::draw_buffers)) { michael@0: return false; michael@0: } michael@0: michael@0: GLint supportedColorAttachments = 0; michael@0: GLint supportedDrawBuffers = 0; michael@0: michael@0: context->MakeContextCurrent(); michael@0: michael@0: gl->fGetIntegerv(LOCAL_GL_MAX_COLOR_ATTACHMENTS, &supportedColorAttachments); michael@0: gl->fGetIntegerv(LOCAL_GL_MAX_COLOR_ATTACHMENTS, &supportedDrawBuffers); michael@0: michael@0: if (size_t(supportedColorAttachments) < sMinColorAttachments){ michael@0: // WEBGL_draw_buffers specifications request for 4 color attachments at least. michael@0: return false; michael@0: } michael@0: michael@0: if (size_t(supportedDrawBuffers) < sMinDrawBuffers){ michael@0: return false; michael@0: } michael@0: michael@0: return true; michael@0: } michael@0: michael@0: IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionDrawBuffers)