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 "WebGLTransformFeedback.h"
|
|
|
|
|
|
|
|
#include "GLContext.h"
|
|
|
|
#include "mozilla/dom/WebGL2RenderingContextBinding.h"
|
2019-07-03 05:22:52 +03:00
|
|
|
#include "mozilla/IntegerRange.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "WebGL2Context.h"
|
2017-01-12 03:03:56 +03:00
|
|
|
#include "WebGLProgram.h"
|
2014-09-18 02:08:41 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
namespace mozilla {
|
2014-09-18 02:08:41 +04:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
WebGLTransformFeedback::WebGLTransformFeedback(WebGLContext* webgl, GLuint tf)
|
2018-04-13 16:01:28 +03:00
|
|
|
: WebGLRefCountedObject(webgl),
|
|
|
|
mGLName(tf),
|
|
|
|
mIndexedBindings(webgl->mGLMaxTransformFeedbackSeparateAttribs),
|
|
|
|
mIsPaused(false),
|
|
|
|
mIsActive(false) {
|
|
|
|
mContext->mTransformFeedbacks.insertBack(this);
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
WebGLTransformFeedback::~WebGLTransformFeedback() { DeleteOnce(); }
|
|
|
|
|
|
|
|
void WebGLTransformFeedback::Delete() {
|
2016-09-10 07:02:54 +03:00
|
|
|
if (mGLName) {
|
|
|
|
mContext->gl->fDeleteTransformFeedbacks(1, &mGLName);
|
|
|
|
}
|
2014-11-26 05:00:06 +03:00
|
|
|
removeFrom(mContext->mTransformFeedbacks);
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
////////////////////////////////////////
|
|
|
|
|
|
|
|
void WebGLTransformFeedback::BeginTransformFeedback(GLenum primMode) {
|
2018-07-27 07:46:33 +03:00
|
|
|
if (mIsActive) return mContext->ErrorInvalidOperation("Already active.");
|
2016-09-10 07:02:54 +03:00
|
|
|
|
|
|
|
switch (primMode) {
|
|
|
|
case LOCAL_GL_POINTS:
|
|
|
|
case LOCAL_GL_LINES:
|
|
|
|
case LOCAL_GL_TRIANGLES:
|
|
|
|
break;
|
|
|
|
default:
|
2018-07-27 07:46:33 +03:00
|
|
|
mContext->ErrorInvalidEnum(
|
|
|
|
"`primitiveMode` must be one of POINTS, LINES, or"
|
|
|
|
" TRIANGLES.");
|
2016-09-10 07:02:54 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
const auto& prog = mContext->mCurrentProgram;
|
|
|
|
if (!prog || !prog->IsLinked() ||
|
2017-08-03 13:01:38 +03:00
|
|
|
prog->LinkInfo()->componentsPerTFVert.empty()) {
|
2018-07-27 07:46:33 +03:00
|
|
|
mContext->ErrorInvalidOperation(
|
|
|
|
"Current program not valid for transform"
|
|
|
|
" feedback.");
|
2018-11-30 13:46:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
const auto& linkInfo = prog->LinkInfo();
|
|
|
|
const auto& componentsPerTFVert = linkInfo->componentsPerTFVert;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
size_t minVertCapacity = SIZE_MAX;
|
|
|
|
for (size_t i = 0; i < componentsPerTFVert.size(); i++) {
|
|
|
|
const auto& indexedBinding = mIndexedBindings[i];
|
|
|
|
const auto& componentsPerVert = componentsPerTFVert[i];
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
const auto& buffer = indexedBinding.mBufferBinding;
|
|
|
|
if (!buffer) {
|
2018-07-27 07:46:33 +03:00
|
|
|
mContext->ErrorInvalidOperation(
|
|
|
|
"No buffer attached to required transform"
|
2016-09-10 07:02:54 +03:00
|
|
|
" feedback index %u.",
|
2018-07-27 07:46:33 +03:00
|
|
|
(uint32_t)i);
|
2016-09-10 07:02:54 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-03 05:22:52 +03:00
|
|
|
for (const auto iBound : IntegerRange(mIndexedBindings.size())) {
|
|
|
|
const auto& bound = mIndexedBindings[iBound].mBufferBinding.get();
|
|
|
|
if (iBound != i && buffer == bound) {
|
|
|
|
mContext->GenErrorIllegalUse(
|
|
|
|
LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER, static_cast<uint32_t>(i),
|
|
|
|
LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER, static_cast<uint32_t>(iBound));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
const size_t vertCapacity = buffer->ByteLength() / 4 / componentsPerVert;
|
|
|
|
minVertCapacity = std::min(minVertCapacity, vertCapacity);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-09-10 07:02:54 +03:00
|
|
|
|
|
|
|
////
|
|
|
|
|
|
|
|
const auto& gl = mContext->gl;
|
|
|
|
gl->fBeginTransformFeedback(primMode);
|
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
////
|
2016-09-10 07:02:54 +03:00
|
|
|
|
|
|
|
mIsActive = true;
|
|
|
|
MOZ_ASSERT(!mIsPaused);
|
|
|
|
|
|
|
|
mActive_Program = prog;
|
|
|
|
mActive_PrimMode = primMode;
|
|
|
|
mActive_VertPosition = 0;
|
|
|
|
mActive_VertCapacity = minVertCapacity;
|
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
////
|
2016-09-10 07:02:54 +03:00
|
|
|
|
|
|
|
mActive_Program->mNumActiveTFOs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebGLTransformFeedback::EndTransformFeedback() {
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!mIsActive) return mContext->ErrorInvalidOperation("Not active.");
|
2016-09-10 07:02:54 +03:00
|
|
|
|
|
|
|
////
|
|
|
|
|
|
|
|
const auto& gl = mContext->gl;
|
|
|
|
gl->fEndTransformFeedback();
|
|
|
|
|
2018-01-04 04:07:36 +03:00
|
|
|
if (gl->WorkAroundDriverBugs()) {
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// Multi-threaded GL on mac will generate INVALID_OP in some cases for at
|
|
|
|
// least BindBufferBase after an EndTransformFeedback if there is not a
|
|
|
|
// flush between the two. Single-threaded GL does not have this issue. This
|
|
|
|
// is likely due to not synchronizing client/server state, and erroring in
|
|
|
|
// BindBufferBase because the client thinks we're still in transform
|
|
|
|
// feedback.
|
|
|
|
gl->fFlush();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
////
|
|
|
|
|
|
|
|
mIsActive = false;
|
|
|
|
mIsPaused = false;
|
|
|
|
|
|
|
|
////
|
|
|
|
|
|
|
|
mActive_Program->mNumActiveTFOs--;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebGLTransformFeedback::PauseTransformFeedback() {
|
|
|
|
if (!mIsActive || mIsPaused) {
|
2018-07-27 07:46:33 +03:00
|
|
|
mContext->ErrorInvalidOperation("Not active or is paused.");
|
2016-09-10 07:02:54 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
////
|
|
|
|
|
|
|
|
const auto& gl = mContext->gl;
|
|
|
|
gl->fPauseTransformFeedback();
|
|
|
|
|
|
|
|
////
|
|
|
|
|
|
|
|
mIsPaused = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebGLTransformFeedback::ResumeTransformFeedback() {
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!mIsPaused) return mContext->ErrorInvalidOperation("Not paused.");
|
2016-09-10 07:02:54 +03:00
|
|
|
|
|
|
|
if (mContext->mCurrentProgram != mActive_Program) {
|
2018-07-27 07:46:33 +03:00
|
|
|
mContext->ErrorInvalidOperation("Active program differs from original.");
|
2016-09-10 07:02:54 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
////
|
|
|
|
|
|
|
|
const auto& gl = mContext->gl;
|
|
|
|
gl->fResumeTransformFeedback();
|
|
|
|
|
|
|
|
////
|
|
|
|
|
|
|
|
MOZ_ASSERT(mIsActive);
|
|
|
|
mIsPaused = false;
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
} // namespace mozilla
|