Commit e85587ac by Corentin Wallez Committed by Commit Bot

BlitGL: add a ScopedGLState to separate our state from the app's

BUG=angleproject:1356 Change-Id: I19ec4efa37d142ac7370815b078f4ba79caa0bea Reviewed-on: https://chromium-review.googlesource.com/412451 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 2291c935
......@@ -17,6 +17,9 @@
#include "libANGLE/renderer/gl/StateManagerGL.h"
#include "libANGLE/renderer/gl/WorkaroundsGL.h"
namespace rx
{
namespace
{
......@@ -46,10 +49,60 @@ gl::Error CheckLinkStatus(const rx::FunctionsGL *functions, GLuint program)
return gl::NoError();
}
} // anonymous namespace
namespace rx
class ScopedGLState : public angle::NonCopyable
{
public:
enum
{
KEEP_SCISSOR = 1,
};
ScopedGLState(StateManagerGL *stateManager,
const FunctionsGL *functions,
gl::Rectangle viewport,
int keepState = 0)
: mStateManager(stateManager), mFunctions(functions)
{
if (!(keepState & KEEP_SCISSOR))
{
mStateManager->setScissorTestEnabled(false);
}
mStateManager->setViewport(viewport);
mStateManager->setDepthRange(0.0f, 1.0f);
mStateManager->setBlendEnabled(false);
mStateManager->setColorMask(true, true, true, true);
mStateManager->setSampleAlphaToCoverageEnabled(false);
mStateManager->setSampleCoverageEnabled(false);
mStateManager->setDepthTestEnabled(false);
mStateManager->setStencilTestEnabled(false);
mStateManager->setCullFaceEnabled(false);
mStateManager->setPolygonOffsetFillEnabled(false);
mStateManager->setRasterizerDiscardEnabled(false);
mStateManager->pauseTransformFeedback();
mStateManager->pauseQueries();
}
~ScopedGLState()
{
// XFB resuming will be done automatically
mStateManager->resumeQueries();
}
void willUseTextureUnit(int unit)
{
if (mFunctions->bindSampler)
{
mStateManager->bindSampler(unit, 0);
}
}
private:
StateManagerGL *mStateManager;
const FunctionsGL *mFunctions;
};
} // anonymous namespace
BlitGL::BlitGL(const FunctionsGL *functions,
const WorkaroundsGL &workarounds,
......@@ -169,22 +222,13 @@ gl::Error BlitGL::copySubImageToLUMAWorkaroundTexture(GLuint texture,
mScratchTextures[1], 0);
// Render to the destination texture, sampling from the scratch texture
mStateManager->setViewport(gl::Rectangle(0, 0, sourceArea.width, sourceArea.height));
mStateManager->setScissorTestEnabled(false);
mStateManager->setDepthRange(0.0f, 1.0f);
mStateManager->setBlendEnabled(false);
mStateManager->setColorMask(true, true, true, true);
mStateManager->setSampleAlphaToCoverageEnabled(false);
mStateManager->setSampleCoverageEnabled(false);
mStateManager->setDepthTestEnabled(false);
mStateManager->setStencilTestEnabled(false);
mStateManager->setCullFaceEnabled(false);
mStateManager->setPolygonOffsetFillEnabled(false);
mStateManager->setRasterizerDiscardEnabled(false);
mStateManager->bindTexture(GL_TEXTURE_2D, mScratchTextures[0]);
ScopedGLState scopedState(mStateManager, mFunctions,
gl::Rectangle(0, 0, sourceArea.width, sourceArea.height));
scopedState.willUseTextureUnit(0);
setScratchTextureParameter(GL_TEXTURE_MIN_FILTER, GL_NEAREST);
setScratchTextureParameter(GL_TEXTURE_MAG_FILTER, GL_NEAREST);
mStateManager->activeTexture(0);
mStateManager->bindTexture(GL_TEXTURE_2D, mScratchTextures[0]);
......@@ -311,6 +355,11 @@ gl::Error BlitGL::blitColorBufferWithShader(const gl::Framebuffer *source,
mFunctions->copyTexImage2D(GL_TEXTURE_2D, 0, format, inBoundsSource.x, inBoundsSource.y,
inBoundsSource.width, inBoundsSource.height, 0);
setScratchTextureParameter(GL_TEXTURE_MIN_FILTER, filter);
setScratchTextureParameter(GL_TEXTURE_MAG_FILTER, filter);
setScratchTextureParameter(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
setScratchTextureParameter(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
// Compute normalized sampled draw quad region
......@@ -343,28 +392,14 @@ gl::Error BlitGL::blitColorBufferWithShader(const gl::Framebuffer *source,
gl::Vector2 texCoordOffset = gl::Vector2(TOffset.x - DOffset.x * texCoordScale.x,
TOffset.y - DOffset.y * texCoordScale.y);
// Reset all the state except scissor and viewport
mStateManager->setDepthRange(0.0f, 1.0f);
mStateManager->setBlendEnabled(false);
mStateManager->setColorMask(true, true, true, true);
mStateManager->setSampleAlphaToCoverageEnabled(false);
mStateManager->setSampleCoverageEnabled(false);
mStateManager->setDepthTestEnabled(false);
mStateManager->setStencilTestEnabled(false);
mStateManager->setCullFaceEnabled(false);
mStateManager->setPolygonOffsetFillEnabled(false);
mStateManager->setRasterizerDiscardEnabled(false);
// Use the viewport to draw exactly to the destination rectangle
mStateManager->setViewport(destArea);
// Reset all the state except scissor and use the viewport to draw exactly to the destination
// rectangle
ScopedGLState scopedState(mStateManager, mFunctions, destArea, ScopedGLState::KEEP_SCISSOR);
scopedState.willUseTextureUnit(0);
// Set uniforms
setScratchTextureParameter(GL_TEXTURE_MIN_FILTER, filter);
setScratchTextureParameter(GL_TEXTURE_MAG_FILTER, filter);
setScratchTextureParameter(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
setScratchTextureParameter(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
mStateManager->activeTexture(0);
mStateManager->bindTexture(GL_TEXTURE_2D, mScratchTextures[0]);
mStateManager->bindTexture(GL_TEXTURE_2D, textureId);
mStateManager->useProgram(mBlitProgram);
mFunctions->uniform1i(mSourceTextureLocation, 0);
......
......@@ -86,7 +86,7 @@ egl::Error DisplayGL::makeCurrent(egl::Surface *drawSurface, egl::Surface *readS
// Pause transform feedback before making a new surface current, to workaround anglebug.com/1426
ContextGL *glContext = GetImplAs<ContextGL>(context);
glContext->getStateManager()->pauseTransformFeedback(context->getContextState());
glContext->getStateManager()->pauseTransformFeedback();
SurfaceGL *glDrawSurface = GetImplAs<SurfaceGL>(drawSurface);
ANGLE_TRY(glDrawSurface->makeCurrent());
......
......@@ -661,17 +661,27 @@ gl::Error StateManagerGL::setDrawElementsState(const gl::ContextState &data,
return setGenericDrawState(data);
}
gl::Error StateManagerGL::pauseTransformFeedback(const gl::ContextState &data)
void StateManagerGL::pauseTransformFeedback()
{
// If the context is going to be changed, pause the previous context's transform feedback
if (data.getContext() != mPrevDrawContext)
if (mPrevDrawTransformFeedback != nullptr)
{
if (mPrevDrawTransformFeedback != nullptr)
{
mPrevDrawTransformFeedback->syncPausedState(true);
}
mPrevDrawTransformFeedback->syncPausedState(true);
}
}
void StateManagerGL::pauseQueries()
{
for (QueryGL *prevQuery : mCurrentQueries)
{
prevQuery->pause();
}
}
void StateManagerGL::resumeQueries()
{
for (QueryGL *prevQuery : mCurrentQueries)
{
prevQuery->resume();
}
return gl::Error(GL_NO_ERROR);
}
gl::Error StateManagerGL::onMakeCurrent(const gl::ContextState &data)
......@@ -681,10 +691,7 @@ gl::Error StateManagerGL::onMakeCurrent(const gl::ContextState &data)
// If the context has changed, pause the previous context's queries
if (data.getContext() != mPrevDrawContext)
{
for (QueryGL *prevQuery : mCurrentQueries)
{
prevQuery->pause();
}
pauseQueries();
}
mCurrentQueries.clear();
mPrevDrawTransformFeedback = nullptr;
......
......@@ -150,7 +150,9 @@ class StateManagerGL final : angle::NonCopyable
GLsizei instanceCount,
const GLvoid **outIndices);
gl::Error pauseTransformFeedback(const gl::ContextState &data);
void pauseTransformFeedback();
void pauseQueries();
void resumeQueries();
gl::Error onMakeCurrent(const gl::ContextState &data);
void syncState(const gl::State &state, const gl::State::DirtyBits &glDirtyBits);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment