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"
|
2014-11-26 05:00:06 +03:00
|
|
|
#include "WebGLActiveInfo.h"
|
|
|
|
#include "WebGLProgram.h"
|
|
|
|
#include "WebGLTransformFeedback.h"
|
2014-09-18 02:08:41 +04:00
|
|
|
#include "GLContext.h"
|
|
|
|
|
2015-07-15 03:37:28 +03:00
|
|
|
namespace mozilla {
|
2014-09-18 02:08:41 +04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// Transform Feedback
|
|
|
|
|
|
|
|
already_AddRefed<WebGLTransformFeedback>
|
|
|
|
WebGL2Context::CreateTransformFeedback()
|
|
|
|
{
|
2014-11-26 05:00:06 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
GLuint tf = 0;
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fGenTransformFeedbacks(1, &tf);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WebGLTransformFeedback> globj = new WebGLTransformFeedback(this, tf);
|
2014-11-26 05:00:06 +03:00
|
|
|
return globj.forget();
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGL2Context::DeleteTransformFeedback(WebGLTransformFeedback* tf)
|
|
|
|
{
|
2014-11-26 05:00:06 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!ValidateObjectAllowDeletedOrNull("deleteTransformFeedback", tf))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!tf || tf->IsDeleted())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (mBoundTransformFeedback == tf)
|
2015-10-28 01:01:29 +03:00
|
|
|
BindTransformFeedback(LOCAL_GL_TRANSFORM_FEEDBACK, nullptr);
|
2014-11-26 05:00:06 +03:00
|
|
|
|
|
|
|
tf->RequestDelete();
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebGL2Context::IsTransformFeedback(WebGLTransformFeedback* tf)
|
|
|
|
{
|
2014-11-26 05:00:06 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return false;
|
|
|
|
|
2015-12-01 19:56:00 +03:00
|
|
|
if (!ValidateObjectAllowDeletedOrNull("isTransformFeedback", tf))
|
2014-11-26 05:00:06 +03:00
|
|
|
return false;
|
|
|
|
|
2015-12-01 19:56:00 +03:00
|
|
|
if (!tf || tf->IsDeleted())
|
2014-11-26 05:00:06 +03:00
|
|
|
return false;
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
2015-05-21 02:57:48 +03:00
|
|
|
return gl->fIsTransformFeedback(tf->mGLName);
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-26 05:00:06 +03:00
|
|
|
WebGL2Context::BindTransformFeedback(GLenum target, WebGLTransformFeedback* tf)
|
2014-09-18 02:08:41 +04:00
|
|
|
{
|
2014-11-26 05:00:06 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!ValidateObjectAllowDeletedOrNull("bindTransformFeedback", tf))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (target != LOCAL_GL_TRANSFORM_FEEDBACK)
|
|
|
|
return ErrorInvalidEnum("bindTransformFeedback: target must be TRANSFORM_FEEDBACK");
|
|
|
|
|
|
|
|
WebGLRefPtr<WebGLTransformFeedback> currentTF = mBoundTransformFeedback;
|
|
|
|
if (currentTF && currentTF->mIsActive && !currentTF->mIsPaused) {
|
|
|
|
return ErrorInvalidOperation("bindTransformFeedback: Currently bound transform "
|
|
|
|
"feedback is active and not paused");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tf && tf->IsDeleted())
|
|
|
|
return ErrorInvalidOperation("bindTransformFeedback: Attempt to bind deleted id");
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
2015-05-21 02:57:48 +03:00
|
|
|
gl->fBindTransformFeedback(target, tf ? tf->mGLName : 0);
|
2014-11-26 05:00:06 +03:00
|
|
|
if (tf)
|
|
|
|
mBoundTransformFeedback = tf;
|
|
|
|
else
|
|
|
|
mBoundTransformFeedback = mDefaultTransformFeedback;
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGL2Context::BeginTransformFeedback(GLenum primitiveMode)
|
|
|
|
{
|
2014-11-26 05:00:06 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
|
|
|
WebGLTransformFeedback* tf = mBoundTransformFeedback;
|
|
|
|
MOZ_ASSERT(tf);
|
|
|
|
if (!tf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (tf->mIsActive)
|
|
|
|
return ErrorInvalidOperation("beginTransformFeedback: transform feedback is active");
|
|
|
|
|
|
|
|
const GLenum mode = tf->mMode;
|
|
|
|
if (mode != LOCAL_GL_POINTS && mode != LOCAL_GL_LINES && mode != LOCAL_GL_TRIANGLES)
|
|
|
|
return ErrorInvalidEnum("beginTransformFeedback: primitive must be one of POINTS, LINES, or TRIANGLES");
|
|
|
|
|
|
|
|
// TODO:
|
|
|
|
// GL_INVALID_OPERATION is generated by glBeginTransformFeedback
|
|
|
|
// if any binding point used in transform feedback mode does not
|
|
|
|
// have a buffer object bound. In interleaved mode, only the first
|
|
|
|
// buffer object binding point is ever written to.
|
|
|
|
|
|
|
|
// GL_INVALID_OPERATION is generated by glBeginTransformFeedback
|
|
|
|
// if no binding points would be used, either because no program
|
|
|
|
// object is active of because the active program object has
|
|
|
|
// specified no varying variables to record.
|
|
|
|
if (!mCurrentProgram)
|
|
|
|
return ErrorInvalidOperation("beginTransformFeedback: no program is active");
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fBeginTransformFeedback(primitiveMode);
|
|
|
|
tf->mIsActive = true;
|
|
|
|
tf->mIsPaused = false;
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGL2Context::EndTransformFeedback()
|
|
|
|
{
|
2014-11-26 05:00:06 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
|
|
|
WebGLTransformFeedback* tf = mBoundTransformFeedback;
|
|
|
|
MOZ_ASSERT(tf);
|
|
|
|
|
|
|
|
if (!tf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!tf->mIsActive)
|
|
|
|
return ErrorInvalidOperation("%s: transform feedback in not active",
|
|
|
|
"endTransformFeedback");
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fEndTransformFeedback();
|
|
|
|
tf->mIsActive = false;
|
|
|
|
tf->mIsPaused = false;
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-26 05:00:06 +03:00
|
|
|
WebGL2Context::PauseTransformFeedback()
|
2014-09-18 02:08:41 +04:00
|
|
|
{
|
2014-11-26 05:00:06 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
2014-09-18 02:08:41 +04:00
|
|
|
|
2014-11-26 05:00:06 +03:00
|
|
|
WebGLTransformFeedback* tf = mBoundTransformFeedback;
|
|
|
|
MOZ_ASSERT(tf);
|
|
|
|
if (!tf)
|
|
|
|
return;
|
2014-09-18 02:08:41 +04:00
|
|
|
|
2014-11-26 05:00:06 +03:00
|
|
|
if (!tf->mIsActive || tf->mIsPaused) {
|
|
|
|
return ErrorInvalidOperation("%s: transform feedback is not active or is paused",
|
|
|
|
"pauseTransformFeedback");
|
|
|
|
}
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fPauseTransformFeedback();
|
|
|
|
tf->mIsPaused = true;
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-26 05:00:06 +03:00
|
|
|
WebGL2Context::ResumeTransformFeedback()
|
2014-09-18 02:08:41 +04:00
|
|
|
{
|
2014-11-26 05:00:06 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
|
|
|
WebGLTransformFeedback* tf = mBoundTransformFeedback;
|
|
|
|
MOZ_ASSERT(tf);
|
|
|
|
if (!tf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!tf->mIsActive || !tf->mIsPaused)
|
|
|
|
return ErrorInvalidOperation("resumeTransformFeedback: transform feedback is not active or is not paused");
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fResumeTransformFeedback();
|
|
|
|
tf->mIsPaused = false;
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-26 05:00:06 +03:00
|
|
|
WebGL2Context::TransformFeedbackVaryings(WebGLProgram* program,
|
|
|
|
const dom::Sequence<nsString>& varyings,
|
|
|
|
GLenum bufferMode)
|
2014-09-18 02:08:41 +04:00
|
|
|
{
|
2014-11-26 05:00:06 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!ValidateObject("transformFeedbackVaryings: program", program))
|
|
|
|
return;
|
|
|
|
|
2015-04-21 04:02:34 +03:00
|
|
|
program->TransformFeedbackVaryings(varyings, bufferMode);
|
2014-11-26 05:00:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<WebGLActiveInfo>
|
|
|
|
WebGL2Context::GetTransformFeedbackVarying(WebGLProgram* program, GLuint index)
|
|
|
|
{
|
|
|
|
if (IsContextLost())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
if (!ValidateObject("getTransformFeedbackVarying: program", program))
|
|
|
|
return nullptr;
|
|
|
|
|
2015-04-21 04:02:34 +03:00
|
|
|
return program->GetTransformFeedbackVarying(index);
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
2015-07-15 03:37:28 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|