2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2014-09-18 02:08:41 +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 "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-07-27 07:46:33 +03:00
|
|
|
bool WebGL2Context::ValidateClearBuffer(GLenum buffer, GLint drawBuffer,
|
2016-12-22 13:22:12 +03:00
|
|
|
size_t availElemCount,
|
|
|
|
GLuint elemOffset, GLenum funcType) {
|
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;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-10-14 03:02:48 +03:00
|
|
|
////
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
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;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
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;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
////
|
|
|
|
|
2014-09-18 04:17:00 +04:00
|
|
|
if (!BindCurFBForDraw()) return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-12-22 13:22:12 +03:00
|
|
|
if (mDefaultFB_DrawBuffer0 == LOCAL_GL_NONE) return true;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-12-22 13:22:12 +03:00
|
|
|
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;
|
2014-09-18 04:17:00 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-09-18 04:17:00 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
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
|
|
|
void WebGL2Context::ClearBufferfv(GLenum buffer, GLint drawBuffer,
|
2016-10-14 03:02:48 +03:00
|
|
|
const Float32Arr& src, GLuint srcElemOffset) {
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "clearBufferfv");
|
|
|
|
if (IsContextLost()) return;
|
2017-12-19 05:30:56 +03:00
|
|
|
|
2016-12-22 13:22:12 +03:00
|
|
|
if (buffer != LOCAL_GL_COLOR && buffer != LOCAL_GL_DEPTH) {
|
|
|
|
ErrorInvalidEnum("`buffer` must be COLOR or DEPTH.");
|
|
|
|
return;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-12-22 13:22:12 +03:00
|
|
|
|
|
|
|
if (!ValidateClearBuffer(buffer, drawBuffer, src.elemCount, srcElemOffset,
|
|
|
|
LOCAL_GL_FLOAT)) {
|
|
|
|
return;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-12-22 13:22:12 +03:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!mBoundDrawFramebuffer && buffer == LOCAL_GL_DEPTH && mNeedsFakeNoDepth) {
|
2016-12-22 13:22:12 +03:00
|
|
|
return;
|
2016-01-21 09:51:59 +03:00
|
|
|
}
|
|
|
|
|
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 04:17:00 +04:00
|
|
|
}
|
|
|
|
|
2016-10-14 03:02:48 +03:00
|
|
|
void WebGL2Context::ClearBufferiv(GLenum buffer, GLint drawBuffer,
|
|
|
|
const Int32Arr& src, GLuint srcElemOffset) {
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "clearBufferiv");
|
2016-12-22 13:22:12 +03:00
|
|
|
if (IsContextLost()) return;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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;
|
|
|
|
}
|
2018-11-30 13:46:48 +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;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
if (!mBoundDrawFramebuffer && buffer == LOCAL_GL_STENCIL &&
|
|
|
|
mNeedsFakeNoStencil) {
|
|
|
|
return;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-10-14 03:02:48 +03:00
|
|
|
void WebGL2Context::ClearBufferuiv(GLenum buffer, GLint drawBuffer,
|
|
|
|
const Uint32Arr& src, GLuint srcElemOffset) {
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "clearBufferuiv");
|
2016-12-22 13:22:12 +03:00
|
|
|
if (IsContextLost()) return;
|
2016-12-21 10:31:22 +03:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (buffer != LOCAL_GL_COLOR)
|
|
|
|
return ErrorInvalidEnum("`buffer` must be COLOR.");
|
2016-12-22 13:22:12 +03:00
|
|
|
|
2017-12-19 05:30:56 +03:00
|
|
|
if (!ValidateClearBuffer(buffer, drawBuffer, src.elemCount, srcElemOffset,
|
|
|
|
LOCAL_GL_UNSIGNED_INT)) {
|
|
|
|
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->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
|
|
|
|
2016-10-14 03:02:48 +03:00
|
|
|
void WebGL2Context::ClearBufferfi(GLenum buffer, GLint drawBuffer,
|
|
|
|
GLfloat depth, GLint stencil) {
|
|
|
|
const FuncScope funcScope(*this, "clearBufferfi");
|
2016-12-22 13:22:12 +03:00
|
|
|
if (IsContextLost()) return;
|
2014-09-18 02:08:41 +04:00
|
|
|
|
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.");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!ValidateClearBuffer(buffer, drawBuffer, 2, 0, 0)) return;
|
2014-09-18 02:08:41 +04:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
auto driverDepth = depth;
|
2017-12-19 05:30:56 +03:00
|
|
|
auto driverStencil = stencil;
|
|
|
|
if (!mBoundDrawFramebuffer) {
|
|
|
|
if (mNeedsFakeNoDepth) {
|
|
|
|
driverDepth = 1.0f;
|
|
|
|
} else if (mNeedsFakeNoStencil) {
|
|
|
|
driverStencil = 0;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-12-19 05:30:56 +03:00
|
|
|
|
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
|