2014-03-12 06:51:39 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2013-06-22 03:44:17 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "WebGLExtensions.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "GLContext.h"
|
|
|
|
#include "mozilla/dom/WebGLRenderingContextBinding.h"
|
|
|
|
#include "WebGLContext.h"
|
|
|
|
#include "WebGLFramebuffer.h"
|
|
|
|
#include "WebGLRenderbuffer.h"
|
|
|
|
#include "WebGLTexture.h"
|
2013-06-22 03:44:17 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
namespace mozilla {
|
2013-06-22 03:44:17 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLExtensionDrawBuffers::WebGLExtensionDrawBuffers(WebGLContext* webgl)
|
|
|
|
: WebGLExtensionBase(webgl)
|
2013-06-22 03:44:17 +04:00
|
|
|
{
|
2014-11-14 07:03:50 +03:00
|
|
|
MOZ_ASSERT(IsSupported(webgl), "Don't construct extension if unsupported.");
|
|
|
|
|
2013-06-22 03:44:17 +04:00
|
|
|
GLint maxColorAttachments = 0;
|
|
|
|
GLint maxDrawBuffers = 0;
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
webgl->MakeContextCurrent();
|
|
|
|
gl::GLContext* gl = webgl->GL();
|
2013-06-22 03:44:17 +04:00
|
|
|
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_COLOR_ATTACHMENTS, &maxColorAttachments);
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
|
|
|
|
|
|
|
|
// WEBGL_draw_buffers specifications don't give a maximal value reachable by MAX_COLOR_ATTACHMENTS.
|
2014-05-01 01:30:23 +04:00
|
|
|
maxColorAttachments = std::min(maxColorAttachments, GLint(WebGLContext::kMaxColorAttachments));
|
2013-06-22 03:44:17 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
if (webgl->MinCapabilityMode())
|
|
|
|
maxColorAttachments = std::min(maxColorAttachments, GLint(kMinColorAttachments));
|
2013-06-22 03:44:17 +04:00
|
|
|
|
|
|
|
// WEBGL_draw_buffers specifications request MAX_COLOR_ATTACHMENTS >= MAX_DRAW_BUFFERS.
|
|
|
|
maxDrawBuffers = std::min(maxDrawBuffers, GLint(maxColorAttachments));
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
webgl->mGLMaxColorAttachments = maxColorAttachments;
|
|
|
|
webgl->mGLMaxDrawBuffers = maxDrawBuffers;
|
2013-06-22 03:44:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
WebGLExtensionDrawBuffers::~WebGLExtensionDrawBuffers()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
void
|
|
|
|
WebGLExtensionDrawBuffers::DrawBuffersWEBGL(const dom::Sequence<GLenum>& buffers)
|
2013-06-22 03:44:17 +04:00
|
|
|
{
|
2014-11-14 07:03:50 +03:00
|
|
|
if (mIsLost) {
|
|
|
|
mContext->ErrorInvalidOperation("drawBuffersWEBGL: Extension is lost.");
|
|
|
|
return;
|
|
|
|
}
|
2014-03-12 06:51:39 +04:00
|
|
|
|
2013-07-17 20:13:38 +04:00
|
|
|
mContext->DrawBuffers(buffers);
|
2013-06-22 03:44:17 +04:00
|
|
|
}
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
bool
|
|
|
|
WebGLExtensionDrawBuffers::IsSupported(const WebGLContext* webgl)
|
2013-06-22 03:44:17 +04:00
|
|
|
{
|
2014-11-14 07:03:50 +03:00
|
|
|
gl::GLContext* gl = webgl->GL();
|
2013-06-22 03:44:17 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
if (!gl->IsSupported(gl::GLFeature::draw_buffers))
|
2013-06-22 03:44:17 +04:00
|
|
|
return false;
|
|
|
|
|
|
|
|
GLint supportedColorAttachments = 0;
|
|
|
|
GLint supportedDrawBuffers = 0;
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
webgl->MakeContextCurrent();
|
2013-06-22 03:44:17 +04:00
|
|
|
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_COLOR_ATTACHMENTS, &supportedColorAttachments);
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_COLOR_ATTACHMENTS, &supportedDrawBuffers);
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
// WEBGL_draw_buffers requires at least 4 color attachments.
|
|
|
|
if (size_t(supportedColorAttachments) < kMinColorAttachments)
|
2013-06-22 03:44:17 +04:00
|
|
|
return false;
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
if (size_t(supportedDrawBuffers) < kMinDrawBuffers)
|
2013-06-22 03:44:17 +04:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-01 17:17:00 +03:00
|
|
|
IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionDrawBuffers, WEBGL_draw_buffers)
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|