2014-09-18 02:08:41 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* 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 "WebGL2Context.h"
|
2015-01-13 02:05:21 +03:00
|
|
|
|
2014-09-18 02:08:41 +04:00
|
|
|
#include "GLContext.h"
|
2015-07-15 03:37:28 +03:00
|
|
|
#include "GLScreenBuffer.h"
|
2015-01-13 02:05:21 +03:00
|
|
|
#include "WebGLContextUtils.h"
|
2015-08-06 09:31:00 +03:00
|
|
|
#include "WebGLFormats.h"
|
2015-07-15 03:37:28 +03:00
|
|
|
#include "WebGLFramebuffer.h"
|
2014-09-18 02:08:41 +04:00
|
|
|
|
2015-07-15 03:37:28 +03:00
|
|
|
namespace mozilla {
|
2014-09-18 02:08:41 +04:00
|
|
|
|
2015-01-13 02:05:21 +03:00
|
|
|
static bool
|
|
|
|
GetFBInfoForBlit(const WebGLFramebuffer* fb, WebGLContext* webgl,
|
|
|
|
const char* const fbInfo, GLsizei* const out_samples,
|
2015-11-25 07:15:29 +03:00
|
|
|
const webgl::FormatInfo** const out_colorFormat,
|
|
|
|
const webgl::FormatInfo** const out_depthFormat,
|
|
|
|
const webgl::FormatInfo** const out_stencilFormat)
|
2015-01-13 02:05:21 +03:00
|
|
|
{
|
|
|
|
auto status = fb->PrecheckFramebufferStatus();
|
|
|
|
if (status != LOCAL_GL_FRAMEBUFFER_COMPLETE) {
|
|
|
|
webgl->ErrorInvalidOperation("blitFramebuffer: %s is not"
|
|
|
|
" framebuffer-complete.", fbInfo);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*out_samples = 1; // TODO
|
2015-11-25 07:15:29 +03:00
|
|
|
*out_colorFormat = nullptr;
|
|
|
|
*out_depthFormat = nullptr;
|
|
|
|
*out_stencilFormat = nullptr;
|
2015-01-13 02:05:21 +03:00
|
|
|
|
|
|
|
if (fb->ColorAttachment(0).IsDefined()) {
|
2015-11-25 07:15:29 +03:00
|
|
|
const auto& attachment = fb->ColorAttachment(0);
|
|
|
|
*out_colorFormat = attachment.Format()->format;
|
2015-01-13 02:05:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fb->DepthStencilAttachment().IsDefined()) {
|
2015-11-25 07:15:29 +03:00
|
|
|
const auto& attachment = fb->DepthStencilAttachment();
|
|
|
|
*out_depthFormat = attachment.Format()->format;
|
2015-01-13 02:05:21 +03:00
|
|
|
*out_stencilFormat = *out_depthFormat;
|
|
|
|
} else {
|
|
|
|
if (fb->DepthAttachment().IsDefined()) {
|
2015-11-25 07:15:29 +03:00
|
|
|
const auto& attachment = fb->DepthAttachment();
|
|
|
|
*out_depthFormat = attachment.Format()->format;
|
2015-01-13 02:05:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fb->StencilAttachment().IsDefined()) {
|
2015-11-25 07:15:29 +03:00
|
|
|
const auto& attachment = fb->StencilAttachment();
|
|
|
|
*out_stencilFormat = attachment.Format()->format;
|
2015-01-13 02:05:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
static void
|
|
|
|
GetBackbufferFormats(const WebGLContextOptions& options,
|
|
|
|
const webgl::FormatInfo** const out_color,
|
|
|
|
const webgl::FormatInfo** const out_depth,
|
|
|
|
const webgl::FormatInfo** const out_stencil)
|
|
|
|
{
|
|
|
|
const auto effFormat = options.alpha ? webgl::EffectiveFormat::RGBA8
|
|
|
|
: webgl::EffectiveFormat::RGB8;
|
|
|
|
*out_color = webgl::GetFormat(effFormat);
|
|
|
|
|
|
|
|
*out_depth = nullptr;
|
|
|
|
*out_stencil = nullptr;
|
|
|
|
if (options.depth && options.stencil) {
|
|
|
|
*out_depth = webgl::GetFormat(webgl::EffectiveFormat::DEPTH24_STENCIL8);
|
|
|
|
*out_stencil = *out_depth;
|
|
|
|
} else {
|
|
|
|
if (options.depth) {
|
|
|
|
*out_depth = webgl::GetFormat(webgl::EffectiveFormat::DEPTH_COMPONENT16);
|
|
|
|
}
|
|
|
|
if (options.stencil) {
|
|
|
|
*out_stencil = webgl::GetFormat(webgl::EffectiveFormat::STENCIL_INDEX8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-18 02:08:41 +04:00
|
|
|
void
|
|
|
|
WebGL2Context::BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
|
|
|
|
GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
|
|
|
|
GLbitfield mask, GLenum filter)
|
|
|
|
{
|
2015-01-13 02:05:21 +03:00
|
|
|
const GLbitfield validBits = LOCAL_GL_COLOR_BUFFER_BIT |
|
|
|
|
LOCAL_GL_DEPTH_BUFFER_BIT |
|
|
|
|
LOCAL_GL_STENCIL_BUFFER_BIT;
|
|
|
|
if ((mask | validBits) != validBits) {
|
|
|
|
ErrorInvalidValue("blitFramebuffer: Invalid bit set in mask.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (filter) {
|
|
|
|
case LOCAL_GL_NEAREST:
|
|
|
|
case LOCAL_GL_LINEAR:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ErrorInvalidEnumInfo("blitFramebuffer: Bad `filter`:", filter);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const GLbitfield depthAndStencilBits = LOCAL_GL_DEPTH_BUFFER_BIT |
|
|
|
|
LOCAL_GL_STENCIL_BUFFER_BIT;
|
|
|
|
if (mask & depthAndStencilBits &&
|
|
|
|
filter != LOCAL_GL_NEAREST)
|
|
|
|
{
|
|
|
|
ErrorInvalidOperation("blitFramebuffer: DEPTH_BUFFER_BIT and"
|
|
|
|
" STENCIL_BUFFER_BIT can only be used with"
|
|
|
|
" NEAREST filtering.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mBoundReadFramebuffer == mBoundDrawFramebuffer) {
|
|
|
|
// TODO: It's actually more complicated than this. We need to check that
|
|
|
|
// the underlying buffers are not the same, not the framebuffers
|
|
|
|
// themselves.
|
|
|
|
ErrorInvalidOperation("blitFramebuffer: Source and destination must"
|
|
|
|
" differ.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLsizei srcSamples;
|
2015-11-25 07:15:29 +03:00
|
|
|
const webgl::FormatInfo* srcColorFormat = nullptr;
|
|
|
|
const webgl::FormatInfo* srcDepthFormat = nullptr;
|
|
|
|
const webgl::FormatInfo* srcStencilFormat = nullptr;
|
2015-01-13 02:05:21 +03:00
|
|
|
|
|
|
|
if (mBoundReadFramebuffer) {
|
|
|
|
if (!GetFBInfoForBlit(mBoundReadFramebuffer, this, "READ_FRAMEBUFFER",
|
|
|
|
&srcSamples, &srcColorFormat, &srcDepthFormat,
|
|
|
|
&srcStencilFormat))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
srcSamples = 1; // Always 1.
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
GetBackbufferFormats(mOptions, &srcColorFormat, &srcDepthFormat,
|
|
|
|
&srcStencilFormat);
|
2015-01-13 02:05:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
GLsizei dstSamples;
|
2015-11-25 07:15:29 +03:00
|
|
|
const webgl::FormatInfo* dstColorFormat = nullptr;
|
|
|
|
const webgl::FormatInfo* dstDepthFormat = nullptr;
|
|
|
|
const webgl::FormatInfo* dstStencilFormat = nullptr;
|
2015-01-13 02:05:21 +03:00
|
|
|
|
|
|
|
if (mBoundDrawFramebuffer) {
|
|
|
|
if (!GetFBInfoForBlit(mBoundDrawFramebuffer, this, "DRAW_FRAMEBUFFER",
|
|
|
|
&dstSamples, &dstColorFormat, &dstDepthFormat,
|
|
|
|
&dstStencilFormat))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dstSamples = gl->Screen()->Samples();
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
GetBackbufferFormats(mOptions, &dstColorFormat, &dstDepthFormat,
|
|
|
|
&dstStencilFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mask & LOCAL_GL_COLOR_BUFFER_BIT) {
|
|
|
|
const auto fnSignlessType = [](const webgl::FormatInfo* format)
|
|
|
|
-> webgl::ComponentType
|
|
|
|
{
|
|
|
|
if (!format)
|
|
|
|
return webgl::ComponentType::None;
|
2015-11-24 06:27:13 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
switch (format->componentType) {
|
|
|
|
case webgl::ComponentType::UInt:
|
|
|
|
return webgl::ComponentType::Int;
|
|
|
|
|
|
|
|
case webgl::ComponentType::NormUInt:
|
|
|
|
return webgl::ComponentType::NormInt;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return format->componentType;
|
2015-01-13 02:05:21 +03:00
|
|
|
}
|
2015-11-25 07:15:29 +03:00
|
|
|
};
|
2015-01-13 02:05:21 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
const auto srcType = fnSignlessType(srcColorFormat);
|
|
|
|
const auto dstType = fnSignlessType(dstColorFormat);
|
2015-01-13 02:05:21 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
if (srcType != dstType) {
|
|
|
|
ErrorInvalidOperation("blitFramebuffer: Color buffer format component type"
|
2015-01-13 02:05:21 +03:00
|
|
|
" mismatch.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
const bool srcIsInt = (srcType == webgl::ComponentType::Int);
|
2015-01-13 02:05:21 +03:00
|
|
|
if (srcIsInt && filter != LOCAL_GL_NEAREST) {
|
|
|
|
ErrorInvalidOperation("blitFramebuffer: Integer read buffers can only"
|
|
|
|
" be filtered with NEAREST.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* GLES 3.0.4, p199:
|
|
|
|
* Calling BlitFramebuffer will result in an INVALID_OPERATION error if
|
|
|
|
* mask includes DEPTH_BUFFER_BIT or STENCIL_BUFFER_BIT, and the source
|
|
|
|
* and destination depth and stencil buffer formats do not match.
|
|
|
|
*
|
|
|
|
* jgilbert: The wording is such that if only DEPTH_BUFFER_BIT is specified,
|
|
|
|
* the stencil formats must match. This seems wrong. It could be a spec bug,
|
|
|
|
* or I could be missing an interaction in one of the earlier paragraphs.
|
|
|
|
*/
|
|
|
|
if (mask & LOCAL_GL_DEPTH_BUFFER_BIT &&
|
|
|
|
dstDepthFormat != srcDepthFormat)
|
|
|
|
{
|
|
|
|
ErrorInvalidOperation("blitFramebuffer: Depth buffer formats must match"
|
|
|
|
" if selected.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mask & LOCAL_GL_STENCIL_BUFFER_BIT &&
|
|
|
|
dstStencilFormat != srcStencilFormat)
|
|
|
|
{
|
|
|
|
ErrorInvalidOperation("blitFramebuffer: Stencil buffer formats must"
|
|
|
|
" match if selected.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dstSamples != 1) {
|
|
|
|
ErrorInvalidOperation("blitFramebuffer: DRAW_FRAMEBUFFER may not have"
|
|
|
|
" multiple samples.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (srcSamples != 1) {
|
|
|
|
if (mask & LOCAL_GL_COLOR_BUFFER_BIT &&
|
|
|
|
dstColorFormat != srcColorFormat)
|
|
|
|
{
|
|
|
|
ErrorInvalidOperation("blitFramebuffer: Color buffer formats must"
|
|
|
|
" match if selected, when reading from a"
|
|
|
|
" multisampled source.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dstX0 != srcX0 ||
|
|
|
|
dstX1 != srcX1 ||
|
|
|
|
dstY0 != srcY0 ||
|
|
|
|
dstY1 != srcY1)
|
|
|
|
{
|
|
|
|
ErrorInvalidOperation("blitFramebuffer: If the source is"
|
|
|
|
" multisampled, then the source and dest"
|
|
|
|
" regions must match exactly.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fBlitFramebuffer(srcX0, srcY0, srcX1, srcY1,
|
|
|
|
dstX0, dstY0, dstX1, dstY1,
|
|
|
|
mask, filter);
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
2015-07-03 04:55:43 +03:00
|
|
|
static bool
|
|
|
|
ValidateTextureLayerAttachment(GLenum attachment)
|
|
|
|
{
|
|
|
|
if (LOCAL_GL_COLOR_ATTACHMENT0 < attachment &&
|
|
|
|
attachment <= LOCAL_GL_COLOR_ATTACHMENT15)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (attachment) {
|
|
|
|
case LOCAL_GL_DEPTH_ATTACHMENT:
|
|
|
|
case LOCAL_GL_DEPTH_STENCIL_ATTACHMENT:
|
|
|
|
case LOCAL_GL_STENCIL_ATTACHMENT:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-09-18 02:08:41 +04:00
|
|
|
void
|
2015-07-03 04:55:43 +03:00
|
|
|
WebGL2Context::FramebufferTextureLayer(GLenum target, GLenum attachment,
|
|
|
|
WebGLTexture* texture, GLint level, GLint layer)
|
2014-09-18 02:08:41 +04:00
|
|
|
{
|
2015-07-03 04:55:43 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!ValidateFramebufferTarget(target, "framebufferTextureLayer"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!ValidateTextureLayerAttachment(attachment))
|
|
|
|
return ErrorInvalidEnumInfo("framebufferTextureLayer: attachment:", attachment);
|
|
|
|
|
|
|
|
if (texture) {
|
|
|
|
if (texture->IsDeleted()) {
|
|
|
|
return ErrorInvalidValue("framebufferTextureLayer: texture must be a valid "
|
|
|
|
"texture object.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (level < 0)
|
|
|
|
return ErrorInvalidValue("framebufferTextureLayer: layer must be >= 0.");
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
switch (texture->Target().get()) {
|
2015-07-03 04:55:43 +03:00
|
|
|
case LOCAL_GL_TEXTURE_3D:
|
2015-11-25 07:15:29 +03:00
|
|
|
if (uint32_t(layer) >= mImplMax3DTextureSize) {
|
2015-07-03 04:55:43 +03:00
|
|
|
return ErrorInvalidValue("framebufferTextureLayer: layer must be < "
|
|
|
|
"MAX_3D_TEXTURE_SIZE");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_TEXTURE_2D_ARRAY:
|
2015-11-25 07:15:29 +03:00
|
|
|
if (uint32_t(layer) >= mImplMaxArrayTextureLayers) {
|
2015-07-03 04:55:43 +03:00
|
|
|
return ErrorInvalidValue("framebufferTextureLayer: layer must be < "
|
|
|
|
"MAX_ARRAY_TEXTURE_LAYERS");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return ErrorInvalidOperation("framebufferTextureLayer: texture must be an "
|
|
|
|
"existing 3D texture, or a 2D texture array.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGLFramebuffer* fb;
|
|
|
|
switch (target) {
|
|
|
|
case LOCAL_GL_FRAMEBUFFER:
|
|
|
|
case LOCAL_GL_DRAW_FRAMEBUFFER:
|
|
|
|
fb = mBoundDrawFramebuffer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_READ_FRAMEBUFFER:
|
|
|
|
fb = mBoundReadFramebuffer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Bad target.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fb) {
|
|
|
|
return ErrorInvalidOperation("framebufferTextureLayer: cannot modify"
|
|
|
|
" framebuffer 0.");
|
|
|
|
}
|
|
|
|
|
|
|
|
fb->FramebufferTextureLayer(attachment, texture, level, layer);
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
2015-08-06 09:31:00 +03:00
|
|
|
JS::Value
|
|
|
|
WebGL2Context::GetFramebufferAttachmentParameter(JSContext* cx,
|
|
|
|
GLenum target,
|
|
|
|
GLenum attachment,
|
|
|
|
GLenum pname,
|
2015-11-25 07:15:29 +03:00
|
|
|
ErrorResult& out_error)
|
2015-08-06 09:31:00 +03:00
|
|
|
{
|
2015-11-25 07:15:29 +03:00
|
|
|
return WebGLContext::GetFramebufferAttachmentParameter(cx, target, attachment, pname,
|
|
|
|
out_error);
|
2015-08-06 09:31:00 +03:00
|
|
|
}
|
|
|
|
|
2014-10-15 01:49:49 +04:00
|
|
|
// Map attachments intended for the default buffer, to attachments for a non-
|
|
|
|
// default buffer.
|
2015-05-25 14:50:15 +03:00
|
|
|
static bool
|
2014-10-15 01:49:49 +04:00
|
|
|
TranslateDefaultAttachments(const dom::Sequence<GLenum>& in, dom::Sequence<GLenum>* out)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < in.Length(); i++) {
|
|
|
|
switch (in[i]) {
|
|
|
|
case LOCAL_GL_COLOR:
|
2015-05-28 21:07:44 +03:00
|
|
|
if (!out->AppendElement(LOCAL_GL_COLOR_ATTACHMENT0, fallible)) {
|
2015-05-25 14:50:15 +03:00
|
|
|
return false;
|
|
|
|
}
|
2014-10-15 01:49:49 +04:00
|
|
|
break;
|
2015-05-25 14:50:15 +03:00
|
|
|
|
2014-10-15 01:49:49 +04:00
|
|
|
case LOCAL_GL_DEPTH:
|
2015-05-28 21:07:44 +03:00
|
|
|
if (!out->AppendElement(LOCAL_GL_DEPTH_ATTACHMENT, fallible)) {
|
2015-05-25 14:50:15 +03:00
|
|
|
return false;
|
|
|
|
}
|
2014-10-15 01:49:49 +04:00
|
|
|
break;
|
2015-05-25 14:50:15 +03:00
|
|
|
|
2014-10-15 01:49:49 +04:00
|
|
|
case LOCAL_GL_STENCIL:
|
2015-05-28 21:07:44 +03:00
|
|
|
if (!out->AppendElement(LOCAL_GL_STENCIL_ATTACHMENT, fallible)) {
|
2015-05-25 14:50:15 +03:00
|
|
|
return false;
|
|
|
|
}
|
2014-10-15 01:49:49 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-05-25 14:50:15 +03:00
|
|
|
|
|
|
|
return true;
|
2014-10-15 01:49:49 +04:00
|
|
|
}
|
|
|
|
|
2014-09-18 02:08:41 +04:00
|
|
|
void
|
2015-05-25 14:50:15 +03:00
|
|
|
WebGL2Context::InvalidateFramebuffer(GLenum target,
|
|
|
|
const dom::Sequence<GLenum>& attachments,
|
2015-07-15 03:37:28 +03:00
|
|
|
ErrorResult& rv)
|
2014-09-18 02:08:41 +04:00
|
|
|
{
|
2015-11-25 07:15:29 +03:00
|
|
|
const char funcName[] = "invalidateSubFramebuffer";
|
|
|
|
|
2014-10-15 01:49:49 +04:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
2015-01-13 02:05:21 +03:00
|
|
|
|
2014-10-15 01:49:49 +04:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
if (!ValidateFramebufferTarget(target, funcName))
|
2015-01-13 02:05:21 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
const WebGLFramebuffer* fb;
|
|
|
|
bool isDefaultFB;
|
|
|
|
switch (target) {
|
|
|
|
case LOCAL_GL_FRAMEBUFFER:
|
|
|
|
case LOCAL_GL_DRAW_FRAMEBUFFER:
|
|
|
|
fb = mBoundDrawFramebuffer;
|
|
|
|
isDefaultFB = gl->Screen()->IsDrawFramebufferDefault();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_READ_FRAMEBUFFER:
|
|
|
|
fb = mBoundReadFramebuffer;
|
|
|
|
isDefaultFB = gl->Screen()->IsReadFramebufferDefault();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Bad target.");
|
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
const bool badColorAttachmentIsInvalidOp = true;
|
2014-10-15 01:49:49 +04:00
|
|
|
for (size_t i = 0; i < attachments.Length(); i++) {
|
2015-11-25 07:15:29 +03:00
|
|
|
if (!ValidateFramebufferAttachment(fb, attachments[i], funcName,
|
|
|
|
badColorAttachmentIsInvalidOp))
|
2015-01-13 02:05:21 +03:00
|
|
|
{
|
2014-10-15 01:49:49 +04:00
|
|
|
return;
|
2015-01-13 02:05:21 +03:00
|
|
|
}
|
2014-10-15 01:49:49 +04:00
|
|
|
}
|
|
|
|
|
2015-03-17 02:29:37 +03:00
|
|
|
// InvalidateFramebuffer is a hint to the driver. Should be OK to
|
|
|
|
// skip calls if not supported, for example by OSX 10.9 GL
|
|
|
|
// drivers.
|
2015-11-25 07:15:29 +03:00
|
|
|
if (!gl->IsSupported(gl::GLFeature::invalidate_framebuffer))
|
2015-03-17 02:29:37 +03:00
|
|
|
return;
|
|
|
|
|
2015-01-13 02:05:21 +03:00
|
|
|
if (!fb && !isDefaultFB) {
|
2014-10-15 01:49:49 +04:00
|
|
|
dom::Sequence<GLenum> tmpAttachments;
|
2015-05-25 14:50:15 +03:00
|
|
|
if (!TranslateDefaultAttachments(attachments, &tmpAttachments)) {
|
2015-07-15 03:37:28 +03:00
|
|
|
rv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
2015-05-25 14:50:15 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
gl->fInvalidateFramebuffer(target, tmpAttachments.Length(),
|
|
|
|
tmpAttachments.Elements());
|
2014-10-15 01:49:49 +04:00
|
|
|
} else {
|
|
|
|
gl->fInvalidateFramebuffer(target, attachments.Length(), attachments.Elements());
|
|
|
|
}
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-15 01:49:49 +04:00
|
|
|
WebGL2Context::InvalidateSubFramebuffer(GLenum target, const dom::Sequence<GLenum>& attachments,
|
2015-05-25 14:50:15 +03:00
|
|
|
GLint x, GLint y, GLsizei width, GLsizei height,
|
2015-07-15 03:37:28 +03:00
|
|
|
ErrorResult& rv)
|
2014-09-18 02:08:41 +04:00
|
|
|
{
|
2015-11-25 07:15:29 +03:00
|
|
|
const char funcName[] = "invalidateSubFramebuffer";
|
|
|
|
|
2014-10-15 01:49:49 +04:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
2015-01-13 02:05:21 +03:00
|
|
|
|
2014-10-15 01:49:49 +04:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
if (!ValidateFramebufferTarget(target, funcName))
|
2015-01-13 02:05:21 +03:00
|
|
|
return;
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
if (width < 0 || height < 0) {
|
|
|
|
ErrorInvalidValue("%s: width and height must be >= 0.", funcName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-13 02:05:21 +03:00
|
|
|
const WebGLFramebuffer* fb;
|
|
|
|
bool isDefaultFB;
|
|
|
|
switch (target) {
|
|
|
|
case LOCAL_GL_FRAMEBUFFER:
|
|
|
|
case LOCAL_GL_DRAW_FRAMEBUFFER:
|
|
|
|
fb = mBoundDrawFramebuffer;
|
|
|
|
isDefaultFB = gl->Screen()->IsDrawFramebufferDefault();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_READ_FRAMEBUFFER:
|
|
|
|
fb = mBoundReadFramebuffer;
|
|
|
|
isDefaultFB = gl->Screen()->IsReadFramebufferDefault();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Bad target.");
|
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
const bool badColorAttachmentIsInvalidOp = true;
|
2014-10-15 01:49:49 +04:00
|
|
|
for (size_t i = 0; i < attachments.Length(); i++) {
|
2015-11-25 07:15:29 +03:00
|
|
|
if (!ValidateFramebufferAttachment(fb, attachments[i], funcName,
|
|
|
|
badColorAttachmentIsInvalidOp))
|
2015-01-13 02:05:21 +03:00
|
|
|
{
|
2014-10-15 01:49:49 +04:00
|
|
|
return;
|
2015-01-13 02:05:21 +03:00
|
|
|
}
|
2014-10-15 01:49:49 +04:00
|
|
|
}
|
|
|
|
|
2015-03-17 02:29:37 +03:00
|
|
|
// InvalidateFramebuffer is a hint to the driver. Should be OK to
|
|
|
|
// skip calls if not supported, for example by OSX 10.9 GL
|
|
|
|
// drivers.
|
2015-11-25 07:15:29 +03:00
|
|
|
if (!gl->IsSupported(gl::GLFeature::invalidate_framebuffer))
|
2015-03-17 02:29:37 +03:00
|
|
|
return;
|
|
|
|
|
2015-01-13 02:05:21 +03:00
|
|
|
if (!fb && !isDefaultFB) {
|
2014-10-15 01:49:49 +04:00
|
|
|
dom::Sequence<GLenum> tmpAttachments;
|
2015-05-25 14:50:15 +03:00
|
|
|
if (!TranslateDefaultAttachments(attachments, &tmpAttachments)) {
|
2015-07-15 03:37:28 +03:00
|
|
|
rv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
2015-05-25 14:50:15 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
gl->fInvalidateSubFramebuffer(target, tmpAttachments.Length(),
|
|
|
|
tmpAttachments.Elements(), x, y, width, height);
|
2014-10-15 01:49:49 +04:00
|
|
|
} else {
|
2015-11-25 07:15:29 +03:00
|
|
|
gl->fInvalidateSubFramebuffer(target, attachments.Length(),
|
|
|
|
attachments.Elements(), x, y, width, height);
|
2014-10-15 01:49:49 +04:00
|
|
|
}
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGL2Context::ReadBuffer(GLenum mode)
|
|
|
|
{
|
2015-02-19 03:57:05 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
2015-07-20 03:31:19 +03:00
|
|
|
const bool isColorAttachment = (mode >= LOCAL_GL_COLOR_ATTACHMENT0 &&
|
2015-11-25 07:15:29 +03:00
|
|
|
mode <= LastColorAttachmentEnum());
|
2015-07-20 03:31:19 +03:00
|
|
|
|
|
|
|
if (mode != LOCAL_GL_NONE && mode != LOCAL_GL_BACK && !isColorAttachment) {
|
|
|
|
ErrorInvalidEnum("readBuffer: `mode` must be one of NONE, BACK, or "
|
|
|
|
"COLOR_ATTACHMENTi. Was %s",
|
|
|
|
EnumName(mode));
|
|
|
|
return;
|
|
|
|
}
|
2015-02-19 03:57:05 +03:00
|
|
|
|
|
|
|
if (mBoundReadFramebuffer) {
|
|
|
|
if (mode != LOCAL_GL_NONE &&
|
|
|
|
!isColorAttachment)
|
|
|
|
{
|
2015-07-20 03:31:19 +03:00
|
|
|
ErrorInvalidOperation("readBuffer: If READ_FRAMEBUFFER is non-null, `mode` "
|
|
|
|
"must be COLOR_ATTACHMENTi or NONE. Was %s",
|
|
|
|
EnumName(mode));
|
2015-02-19 03:57:05 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-20 03:31:19 +03:00
|
|
|
MakeContextCurrent();
|
2015-02-19 03:57:05 +03:00
|
|
|
gl->fReadBuffer(mode);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Operating on the default framebuffer.
|
|
|
|
if (mode != LOCAL_GL_NONE &&
|
|
|
|
mode != LOCAL_GL_BACK)
|
|
|
|
{
|
2015-07-20 03:31:19 +03:00
|
|
|
ErrorInvalidOperation("readBuffer: If READ_FRAMEBUFFER is null, `mode`"
|
|
|
|
" must be BACK or NONE. Was %s",
|
|
|
|
EnumName(mode));
|
2015-02-19 03:57:05 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gl->Screen()->SetReadBuffer(mode);
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
2015-07-15 03:37:28 +03:00
|
|
|
} // namespace mozilla
|