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