1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/src/WebGLExtensionDrawBuffers.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,87 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.7 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "WebGLContext.h" 1.10 +#include "WebGLExtensions.h" 1.11 +#include "mozilla/dom/WebGLRenderingContextBinding.h" 1.12 +#include "WebGLTexture.h" 1.13 +#include "WebGLRenderbuffer.h" 1.14 +#include "WebGLFramebuffer.h" 1.15 +#include "GLContext.h" 1.16 + 1.17 +#include <algorithm> 1.18 + 1.19 +using namespace mozilla; 1.20 +using namespace gl; 1.21 + 1.22 +WebGLExtensionDrawBuffers::WebGLExtensionDrawBuffers(WebGLContext* context) 1.23 + : WebGLExtensionBase(context) 1.24 +{ 1.25 + GLint maxColorAttachments = 0; 1.26 + GLint maxDrawBuffers = 0; 1.27 + 1.28 + gl::GLContext* gl = context->GL(); 1.29 + 1.30 + context->MakeContextCurrent(); 1.31 + 1.32 + gl->fGetIntegerv(LOCAL_GL_MAX_COLOR_ATTACHMENTS, &maxColorAttachments); 1.33 + gl->fGetIntegerv(LOCAL_GL_MAX_DRAW_BUFFERS, &maxDrawBuffers); 1.34 + 1.35 + // WEBGL_draw_buffers specifications don't give a maximal value reachable by MAX_COLOR_ATTACHMENTS. 1.36 + maxColorAttachments = std::min(maxColorAttachments, GLint(WebGLContext::sMaxColorAttachments)); 1.37 + 1.38 + if (context->MinCapabilityMode()) 1.39 + { 1.40 + maxColorAttachments = std::min(maxColorAttachments, GLint(sMinColorAttachments)); 1.41 + } 1.42 + 1.43 + // WEBGL_draw_buffers specifications request MAX_COLOR_ATTACHMENTS >= MAX_DRAW_BUFFERS. 1.44 + maxDrawBuffers = std::min(maxDrawBuffers, GLint(maxColorAttachments)); 1.45 + 1.46 + context->mGLMaxColorAttachments = maxColorAttachments; 1.47 + context->mGLMaxDrawBuffers = maxDrawBuffers; 1.48 +} 1.49 + 1.50 +WebGLExtensionDrawBuffers::~WebGLExtensionDrawBuffers() 1.51 +{ 1.52 +} 1.53 + 1.54 +void WebGLExtensionDrawBuffers::DrawBuffersWEBGL(const dom::Sequence<GLenum>& buffers) 1.55 +{ 1.56 + if (mIsLost) 1.57 + return mContext->ErrorInvalidOperation("drawBuffersWEBGL: Extension is lost."); 1.58 + 1.59 + mContext->DrawBuffers(buffers); 1.60 +} 1.61 + 1.62 +bool WebGLExtensionDrawBuffers::IsSupported(const WebGLContext* context) 1.63 +{ 1.64 + gl::GLContext * gl = context->GL(); 1.65 + 1.66 + if (!gl->IsSupported(GLFeature::draw_buffers)) { 1.67 + return false; 1.68 + } 1.69 + 1.70 + GLint supportedColorAttachments = 0; 1.71 + GLint supportedDrawBuffers = 0; 1.72 + 1.73 + context->MakeContextCurrent(); 1.74 + 1.75 + gl->fGetIntegerv(LOCAL_GL_MAX_COLOR_ATTACHMENTS, &supportedColorAttachments); 1.76 + gl->fGetIntegerv(LOCAL_GL_MAX_COLOR_ATTACHMENTS, &supportedDrawBuffers); 1.77 + 1.78 + if (size_t(supportedColorAttachments) < sMinColorAttachments){ 1.79 + // WEBGL_draw_buffers specifications request for 4 color attachments at least. 1.80 + return false; 1.81 + } 1.82 + 1.83 + if (size_t(supportedDrawBuffers) < sMinDrawBuffers){ 1.84 + return false; 1.85 + } 1.86 + 1.87 + return true; 1.88 +} 1.89 + 1.90 +IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionDrawBuffers)