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
|
|
|
|
|
|
|
void
|
|
|
|
WebGL2Context::BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
|
|
|
|
GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
|
|
|
|
GLbitfield mask, GLenum filter)
|
|
|
|
{
|
2015-12-15 03:11:59 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
////
|
2015-11-24 06:27:13 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
const auto& readFB = mBoundReadFramebuffer;
|
|
|
|
if (readFB &&
|
|
|
|
!readFB->ValidateAndInitAttachments("blitFramebuffer's READ_FRAMEBUFFER"))
|
2015-01-13 02:05:21 +03:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
const auto& drawFB = mBoundDrawFramebuffer;
|
|
|
|
if (drawFB &&
|
|
|
|
!drawFB->ValidateAndInitAttachments("blitFramebuffer's DRAW_FRAMEBUFFER"))
|
2015-01-13 02:05:21 +03:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
////
|
2015-07-03 04:55:43 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
WebGLFramebuffer::BlitFramebuffer(this,
|
|
|
|
readFB, srcX0, srcY0, srcX1, srcY1,
|
|
|
|
drawFB, dstX0, dstY0, dstX1, dstY1,
|
|
|
|
mask, filter);
|
2015-07-03 04:55:43 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2016-07-19 10:36:54 +03:00
|
|
|
const char funcName[] = "framebufferTextureLayer";
|
2015-07-03 04:55:43 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (!ValidateFramebufferTarget(target, funcName))
|
2015-07-03 04:55:43 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
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:
|
2016-06-06 18:17:23 +03:00
|
|
|
MOZ_CRASH("GFX: Bad target.");
|
2015-07-03 04:55:43 +03:00
|
|
|
}
|
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (!fb)
|
|
|
|
return ErrorInvalidOperation("%a: Xannot modify framebuffer 0.");
|
2015-07-03 04:55:43 +03:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
fb->FramebufferTextureLayer(funcName, 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:
|
2016-06-06 18:17:23 +03:00
|
|
|
MOZ_CRASH("GFX: Bad target.");
|
2015-01-13 02:05:21 +03:00
|
|
|
}
|
|
|
|
|
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:
|
2016-06-06 18:17:23 +03:00
|
|
|
MOZ_CRASH("GFX: Bad target.");
|
2015-01-13 02:05:21 +03:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2016-07-19 10:36:54 +03:00
|
|
|
const char funcName[] = "readBuffer";
|
2015-02-19 03:57:05 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (mBoundReadFramebuffer) {
|
2016-07-19 10:36:54 +03:00
|
|
|
mBoundReadFramebuffer->ReadBuffer(funcName, mode);
|
2015-02-19 03:57:05 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Operating on the default framebuffer.
|
|
|
|
if (mode != LOCAL_GL_NONE &&
|
|
|
|
mode != LOCAL_GL_BACK)
|
|
|
|
{
|
2016-07-19 10:36:54 +03:00
|
|
|
ErrorInvalidOperation("%s: If READ_FRAMEBUFFER is null, `mode` must be BACK or"
|
|
|
|
" NONE. Was %s",
|
|
|
|
funcName, 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
|