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"
|
2016-07-22 09:25:41 +03:00
|
|
|
|
2014-09-18 02:08:41 +04:00
|
|
|
#include "GLContext.h"
|
2016-07-22 09:25:41 +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
|
|
|
|
2016-10-14 02:25:11 +03:00
|
|
|
bool
|
2018-07-27 07:46:33 +03:00
|
|
|
WebGL2Context::ValidateClearBuffer(GLenum buffer, GLint drawBuffer,
|
2016-12-22 13:22:12 +03:00
|
|
|
size_t availElemCount, GLuint elemOffset,
|
|
|
|
GLenum funcType)
|
2014-09-18 04:17:00 +04:00
|
|
|
{
|
2016-10-14 03:02:48 +03:00
|
|
|
if (elemOffset > availElemCount) {
|
2018-07-27 07:46:33 +03:00
|
|
|
ErrorInvalidValue("Offset too big for list.");
|
2016-10-14 03:02:48 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
availElemCount -= elemOffset;
|
|
|
|
|
|
|
|
////
|
|
|
|
|
2016-10-14 02:25:11 +03:00
|
|
|
size_t requiredElements;
|
2016-10-14 03:02:48 +03:00
|
|
|
GLint maxDrawBuffer;
|
2014-09-18 04:17:00 +04:00
|
|
|
switch (buffer) {
|
2016-10-14 02:25:11 +03:00
|
|
|
case LOCAL_GL_COLOR:
|
2014-09-18 04:17:00 +04:00
|
|
|
requiredElements = 4;
|
2016-10-14 03:02:48 +03:00
|
|
|
maxDrawBuffer = mGLMaxDrawBuffers - 1;
|
2014-09-18 04:17:00 +04:00
|
|
|
break;
|
|
|
|
|
2016-10-14 02:25:11 +03:00
|
|
|
case LOCAL_GL_DEPTH:
|
|
|
|
case LOCAL_GL_STENCIL:
|
2014-09-18 04:17:00 +04:00
|
|
|
requiredElements = 1;
|
2016-10-14 03:02:48 +03:00
|
|
|
maxDrawBuffer = 0;
|
2014-09-18 04:17:00 +04:00
|
|
|
break;
|
|
|
|
|
2016-12-22 13:22:12 +03:00
|
|
|
case LOCAL_GL_DEPTH_STENCIL:
|
|
|
|
requiredElements = 2;
|
|
|
|
maxDrawBuffer = 0;
|
|
|
|
break;
|
|
|
|
|
2016-10-14 02:25:11 +03:00
|
|
|
default:
|
2018-07-27 07:46:33 +03:00
|
|
|
ErrorInvalidEnumInfo("buffer", buffer);
|
2014-09-18 04:17:00 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-10-14 03:02:48 +03:00
|
|
|
if (drawBuffer < 0 || drawBuffer > maxDrawBuffer) {
|
2018-07-27 07:46:33 +03:00
|
|
|
ErrorInvalidValue("Invalid drawbuffer %d. This buffer only supports"
|
2016-10-14 03:02:48 +03:00
|
|
|
" `drawbuffer` values between 0 and %u.",
|
2018-07-27 07:46:33 +03:00
|
|
|
drawBuffer, maxDrawBuffer);
|
2014-09-18 04:17:00 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-10-14 03:02:48 +03:00
|
|
|
if (availElemCount < requiredElements) {
|
2018-07-27 07:46:33 +03:00
|
|
|
ErrorInvalidValue("Not enough elements. Require %zu. Given %zu.",
|
|
|
|
requiredElements, availElemCount);
|
2014-09-18 04:17:00 +04:00
|
|
|
return false;
|
|
|
|
}
|
2016-10-14 02:25:11 +03:00
|
|
|
|
2016-10-14 03:02:48 +03:00
|
|
|
////
|
2016-01-21 09:51:59 +03:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!BindCurFBForDraw())
|
2017-12-19 05:30:56 +03:00
|
|
|
return false;
|
|
|
|
|
2016-12-22 13:22:12 +03:00
|
|
|
const auto& fb = mBoundDrawFramebuffer;
|
|
|
|
if (fb) {
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!fb->ValidateClearBufferType(buffer, drawBuffer, funcType))
|
2016-12-22 13:22:12 +03:00
|
|
|
return false;
|
|
|
|
} else if (buffer == LOCAL_GL_COLOR) {
|
|
|
|
if (drawBuffer != 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (mDefaultFB_DrawBuffer0 == LOCAL_GL_NONE)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (funcType != LOCAL_GL_FLOAT) {
|
2018-07-27 07:46:33 +03:00
|
|
|
ErrorInvalidOperation("For default framebuffer, COLOR is always of type"
|
|
|
|
" FLOAT.");
|
2016-12-22 13:22:12 +03:00
|
|
|
return false;
|
|
|
|
}
|
2016-01-21 09:51:59 +03:00
|
|
|
}
|
|
|
|
|
2016-10-14 03:02:48 +03:00
|
|
|
return true;
|
2014-09-18 04:17:00 +04:00
|
|
|
}
|
|
|
|
|
2016-10-14 03:02:48 +03:00
|
|
|
////
|
2014-09-18 04:17:00 +04:00
|
|
|
|
|
|
|
void
|
2016-10-14 03:02:48 +03:00
|
|
|
WebGL2Context::ClearBufferfv(GLenum buffer, GLint drawBuffer, const Float32Arr& src,
|
|
|
|
GLuint srcElemOffset)
|
2014-09-18 04:17:00 +04:00
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "clearBufferfv");
|
2016-12-22 13:22:12 +03:00
|
|
|
if (IsContextLost())
|
2014-09-18 04:17:00 +04:00
|
|
|
return;
|
|
|
|
|
2016-12-22 13:22:12 +03:00
|
|
|
if (buffer != LOCAL_GL_COLOR &&
|
|
|
|
buffer != LOCAL_GL_DEPTH)
|
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
ErrorInvalidEnum("`buffer` must be COLOR or DEPTH.");
|
2016-12-22 13:22:12 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!ValidateClearBuffer(buffer, drawBuffer, src.elemCount, srcElemOffset,
|
2016-12-22 13:22:12 +03:00
|
|
|
LOCAL_GL_FLOAT))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-12-21 10:31:22 +03:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
if (!mBoundDrawFramebuffer &&
|
|
|
|
buffer == LOCAL_GL_DEPTH &&
|
|
|
|
mNeedsFakeNoDepth)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-22 13:22:12 +03:00
|
|
|
ScopedDrawCallWrapper wrapper(*this);
|
2016-10-14 03:02:48 +03:00
|
|
|
const auto ptr = src.elemBytes + srcElemOffset;
|
|
|
|
gl->fClearBufferfv(buffer, drawBuffer, ptr);
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-14 03:02:48 +03:00
|
|
|
WebGL2Context::ClearBufferiv(GLenum buffer, GLint drawBuffer, const Int32Arr& src,
|
|
|
|
GLuint srcElemOffset)
|
2014-09-18 02:08:41 +04:00
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "clearBufferiv");
|
2016-12-22 13:22:12 +03:00
|
|
|
if (IsContextLost())
|
2014-09-18 04:17:00 +04:00
|
|
|
return;
|
|
|
|
|
2016-12-22 13:22:12 +03:00
|
|
|
if (buffer != LOCAL_GL_COLOR &&
|
|
|
|
buffer != LOCAL_GL_STENCIL)
|
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
ErrorInvalidEnum("`buffer` must be COLOR or STENCIL.");
|
2016-12-22 13:22:12 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-12-21 10:31:22 +03:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!ValidateClearBuffer(buffer, drawBuffer, src.elemCount, srcElemOffset,
|
2016-12-22 13:22:12 +03:00
|
|
|
LOCAL_GL_INT))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
if (!mBoundDrawFramebuffer &&
|
|
|
|
buffer == LOCAL_GL_STENCIL &&
|
|
|
|
mNeedsFakeNoStencil)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-22 13:22:12 +03:00
|
|
|
ScopedDrawCallWrapper wrapper(*this);
|
2016-10-14 03:02:48 +03:00
|
|
|
const auto ptr = src.elemBytes + srcElemOffset;
|
|
|
|
gl->fClearBufferiv(buffer, drawBuffer, ptr);
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-14 03:02:48 +03:00
|
|
|
WebGL2Context::ClearBufferuiv(GLenum buffer, GLint drawBuffer, const Uint32Arr& src,
|
2016-12-21 10:31:22 +03:00
|
|
|
GLuint srcElemOffset)
|
2014-09-18 02:08:41 +04:00
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "clearBufferuiv");
|
2016-12-22 13:22:12 +03:00
|
|
|
if (IsContextLost())
|
2014-09-18 04:17:00 +04:00
|
|
|
return;
|
|
|
|
|
2016-12-22 13:22:12 +03:00
|
|
|
if (buffer != LOCAL_GL_COLOR)
|
2018-07-27 07:46:33 +03:00
|
|
|
return ErrorInvalidEnum("`buffer` must be COLOR.");
|
2016-12-21 10:31:22 +03:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!ValidateClearBuffer(buffer, drawBuffer, src.elemCount, srcElemOffset,
|
2016-12-22 13:22:12 +03:00
|
|
|
LOCAL_GL_UNSIGNED_INT))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScopedDrawCallWrapper wrapper(*this);
|
2016-10-14 03:02:48 +03:00
|
|
|
const auto ptr = src.elemBytes + srcElemOffset;
|
|
|
|
gl->fClearBufferuiv(buffer, drawBuffer, ptr);
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
2016-10-14 03:02:48 +03:00
|
|
|
////
|
2014-09-18 02:08:41 +04:00
|
|
|
|
|
|
|
void
|
2016-10-14 03:02:48 +03:00
|
|
|
WebGL2Context::ClearBufferfi(GLenum buffer, GLint drawBuffer, GLfloat depth,
|
|
|
|
GLint stencil)
|
2014-09-18 02:08:41 +04:00
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "clearBufferfi");
|
2016-12-22 13:22:12 +03:00
|
|
|
if (IsContextLost())
|
2016-03-17 08:45:00 +03:00
|
|
|
return;
|
|
|
|
|
2016-10-14 03:02:48 +03:00
|
|
|
if (buffer != LOCAL_GL_DEPTH_STENCIL)
|
2018-07-27 07:46:33 +03:00
|
|
|
return ErrorInvalidEnum("`buffer` must be DEPTH_STENCIL.");
|
2014-09-18 04:17:00 +04:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!ValidateClearBuffer(buffer, drawBuffer, 2, 0, 0))
|
2016-12-22 13:22:12 +03:00
|
|
|
return;
|
2016-12-21 10:31:22 +03:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
auto driverDepth = depth;
|
|
|
|
auto driverStencil = stencil;
|
|
|
|
if (!mBoundDrawFramebuffer) {
|
|
|
|
if (mNeedsFakeNoDepth) {
|
|
|
|
driverDepth = 1.0f;
|
|
|
|
} else if (mNeedsFakeNoStencil) {
|
|
|
|
driverStencil = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-22 13:22:12 +03:00
|
|
|
ScopedDrawCallWrapper wrapper(*this);
|
2017-12-19 05:30:56 +03:00
|
|
|
gl->fClearBufferfi(buffer, drawBuffer, driverDepth, driverStencil);
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
2015-07-15 03:37:28 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|