Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 4 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "WebGLContext.h" |
michael@0 | 7 | #include "WebGLExtensions.h" |
michael@0 | 8 | #include "mozilla/dom/WebGLRenderingContextBinding.h" |
michael@0 | 9 | #include "WebGLTexture.h" |
michael@0 | 10 | #include "WebGLRenderbuffer.h" |
michael@0 | 11 | #include "WebGLFramebuffer.h" |
michael@0 | 12 | #include "GLContext.h" |
michael@0 | 13 | |
michael@0 | 14 | #include <algorithm> |
michael@0 | 15 | |
michael@0 | 16 | using namespace mozilla; |
michael@0 | 17 | using namespace gl; |
michael@0 | 18 | |
michael@0 | 19 | WebGLExtensionDrawBuffers::WebGLExtensionDrawBuffers(WebGLContext* context) |
michael@0 | 20 | : WebGLExtensionBase(context) |
michael@0 | 21 | { |
michael@0 | 22 | GLint maxColorAttachments = 0; |
michael@0 | 23 | GLint maxDrawBuffers = 0; |
michael@0 | 24 | |
michael@0 | 25 | gl::GLContext* gl = context->GL(); |
michael@0 | 26 | |
michael@0 | 27 | context->MakeContextCurrent(); |
michael@0 | 28 | |
michael@0 | 29 | gl->fGetIntegerv(LOCAL_GL_MAX_COLOR_ATTACHMENTS, &maxColorAttachments); |
michael@0 | 30 | gl->fGetIntegerv(LOCAL_GL_MAX_DRAW_BUFFERS, &maxDrawBuffers); |
michael@0 | 31 | |
michael@0 | 32 | // WEBGL_draw_buffers specifications don't give a maximal value reachable by MAX_COLOR_ATTACHMENTS. |
michael@0 | 33 | maxColorAttachments = std::min(maxColorAttachments, GLint(WebGLContext::sMaxColorAttachments)); |
michael@0 | 34 | |
michael@0 | 35 | if (context->MinCapabilityMode()) |
michael@0 | 36 | { |
michael@0 | 37 | maxColorAttachments = std::min(maxColorAttachments, GLint(sMinColorAttachments)); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | // WEBGL_draw_buffers specifications request MAX_COLOR_ATTACHMENTS >= MAX_DRAW_BUFFERS. |
michael@0 | 41 | maxDrawBuffers = std::min(maxDrawBuffers, GLint(maxColorAttachments)); |
michael@0 | 42 | |
michael@0 | 43 | context->mGLMaxColorAttachments = maxColorAttachments; |
michael@0 | 44 | context->mGLMaxDrawBuffers = maxDrawBuffers; |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | WebGLExtensionDrawBuffers::~WebGLExtensionDrawBuffers() |
michael@0 | 48 | { |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | void WebGLExtensionDrawBuffers::DrawBuffersWEBGL(const dom::Sequence<GLenum>& buffers) |
michael@0 | 52 | { |
michael@0 | 53 | if (mIsLost) |
michael@0 | 54 | return mContext->ErrorInvalidOperation("drawBuffersWEBGL: Extension is lost."); |
michael@0 | 55 | |
michael@0 | 56 | mContext->DrawBuffers(buffers); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | bool WebGLExtensionDrawBuffers::IsSupported(const WebGLContext* context) |
michael@0 | 60 | { |
michael@0 | 61 | gl::GLContext * gl = context->GL(); |
michael@0 | 62 | |
michael@0 | 63 | if (!gl->IsSupported(GLFeature::draw_buffers)) { |
michael@0 | 64 | return false; |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | GLint supportedColorAttachments = 0; |
michael@0 | 68 | GLint supportedDrawBuffers = 0; |
michael@0 | 69 | |
michael@0 | 70 | context->MakeContextCurrent(); |
michael@0 | 71 | |
michael@0 | 72 | gl->fGetIntegerv(LOCAL_GL_MAX_COLOR_ATTACHMENTS, &supportedColorAttachments); |
michael@0 | 73 | gl->fGetIntegerv(LOCAL_GL_MAX_COLOR_ATTACHMENTS, &supportedDrawBuffers); |
michael@0 | 74 | |
michael@0 | 75 | if (size_t(supportedColorAttachments) < sMinColorAttachments){ |
michael@0 | 76 | // WEBGL_draw_buffers specifications request for 4 color attachments at least. |
michael@0 | 77 | return false; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | if (size_t(supportedDrawBuffers) < sMinDrawBuffers){ |
michael@0 | 81 | return false; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | return true; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionDrawBuffers) |