Added an ignoreViewport parameter to Renderer::setViewport.

TRAC #22145 Signed-off-by: Nicolas Capens Signed-off-by: Daniel Koch git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1518 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 3a0ef480
...@@ -1738,23 +1738,9 @@ bool Context::applyRenderTarget(bool ignoreViewport) ...@@ -1738,23 +1738,9 @@ bool Context::applyRenderTarget(bool ignoreViewport)
mRenderTargetDesc.format = renderbufferObject->getActualFormat(); mRenderTargetDesc.format = renderbufferObject->getActualFormat();
// D3D9_REPLACE end // D3D9_REPLACE end
Rectangle viewport = mState.viewport;
float zNear = clamp01(mState.zNear);
float zFar = clamp01(mState.zFar);
if (ignoreViewport)
{
viewport.x = 0;
viewport.y = 0;
viewport.width = mRenderTargetDesc.width;
viewport.height = mRenderTargetDesc.height;
zNear = 0.0f;
zFar = 1.0f;
}
ProgramBinary *programBinary = mState.currentProgram ? getCurrentProgramBinary() : NULL; ProgramBinary *programBinary = mState.currentProgram ? getCurrentProgramBinary() : NULL;
if (!mRenderer->setViewport(mState.viewport, mState.zNear, mState.zFar, ignoreViewport,
if (!mRenderer->setViewport(viewport, zNear, zFar, programBinary, mDxUniformsDirty)) programBinary, mDxUniformsDirty))
{ {
return false; return false;
} }
......
...@@ -88,7 +88,7 @@ class Renderer ...@@ -88,7 +88,7 @@ class Renderer
int stencilBackRef, bool frontFaceCCW) = 0; int stencilBackRef, bool frontFaceCCW) = 0;
virtual void setScissorRectangle(const gl::Rectangle &scissor) = 0; virtual void setScissorRectangle(const gl::Rectangle &scissor) = 0;
virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, bool ignoreViewport,
gl::ProgramBinary *currentProgram, bool forceSetUniforms) = 0; gl::ProgramBinary *currentProgram, bool forceSetUniforms) = 0;
virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer) = 0; virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer) = 0;
......
...@@ -365,32 +365,45 @@ void Renderer11::setScissorRectangle(const gl::Rectangle &scissor) ...@@ -365,32 +365,45 @@ void Renderer11::setScissorRectangle(const gl::Rectangle &scissor)
mForceSetScissor = false; mForceSetScissor = false;
} }
bool Renderer11::setViewport(const gl::Rectangle &viewport, float zNear, float zFar, bool Renderer11::setViewport(const gl::Rectangle &viewport, float zNear, float zFar, bool ignoreViewport,
gl::ProgramBinary *currentProgram, bool forceSetUniforms) gl::ProgramBinary *currentProgram, bool forceSetUniforms)
{ {
bool viewportChanged = mForceSetViewport || memcmp(&viewport, &mCurViewport, sizeof(gl::Rectangle)) != 0 || gl::Rectangle actualViewport = viewport;
zNear != mCurNear || zFar != mCurFar; float actualZNear = gl::clamp01(zNear);
float actualZFar = gl::clamp01(zFar);
if (ignoreViewport)
{
actualViewport.x = 0;
actualViewport.y = 0;
actualViewport.width = mRenderTargetDesc.width;
actualViewport.height = mRenderTargetDesc.height;
actualZNear = 0.0f;
actualZFar = 1.0f;
}
D3D11_VIEWPORT dxViewport; D3D11_VIEWPORT dxViewport;
dxViewport.TopLeftX = gl::clamp(viewport.x, 0, static_cast<int>(mRenderTargetDesc.width)); dxViewport.TopLeftX = gl::clamp(actualViewport.x, 0, static_cast<int>(mRenderTargetDesc.width));
dxViewport.TopLeftY = gl::clamp(viewport.y, 0, static_cast<int>(mRenderTargetDesc.height)); dxViewport.TopLeftY = gl::clamp(actualViewport.y, 0, static_cast<int>(mRenderTargetDesc.height));
dxViewport.Width = gl::clamp(viewport.width, 0, static_cast<int>(mRenderTargetDesc.width) - static_cast<int>(dxViewport.TopLeftX)); dxViewport.Width = gl::clamp(actualViewport.width, 0, static_cast<int>(mRenderTargetDesc.width) - static_cast<int>(dxViewport.TopLeftX));
dxViewport.Height = gl::clamp(viewport.height, 0, static_cast<int>(mRenderTargetDesc.height) - static_cast<int>(dxViewport.TopLeftY)); dxViewport.Height = gl::clamp(actualViewport.height, 0, static_cast<int>(mRenderTargetDesc.height) - static_cast<int>(dxViewport.TopLeftY));
dxViewport.MinDepth = zNear; dxViewport.MinDepth = actualZNear;
dxViewport.MaxDepth = zFar; dxViewport.MaxDepth = actualZFar;
if (dxViewport.Width <= 0 || dxViewport.Height <= 0) if (dxViewport.Width <= 0 || dxViewport.Height <= 0)
{ {
return false; // Nothing to render return false; // Nothing to render
} }
bool viewportChanged = mForceSetViewport || memcmp(&actualViewport, &mCurViewport, sizeof(gl::Rectangle)) != 0 ||
actualZNear != mCurNear || actualZFar != mCurFar;
if (viewportChanged) if (viewportChanged)
{ {
mDeviceContext->RSSetViewports(1, &dxViewport); mDeviceContext->RSSetViewports(1, &dxViewport);
mCurViewport = viewport; mCurViewport = actualViewport;
mCurNear = zNear; mCurNear = actualZNear;
mCurFar = zFar; mCurFar = actualZFar;
} }
if (currentProgram && (viewportChanged || forceSetUniforms)) if (currentProgram && (viewportChanged || forceSetUniforms))
...@@ -401,18 +414,18 @@ bool Renderer11::setViewport(const gl::Rectangle &viewport, float zNear, float z ...@@ -401,18 +414,18 @@ bool Renderer11::setViewport(const gl::Rectangle &viewport, float zNear, float z
// These values are used for computing gl_FragCoord in Program::linkVaryings(). // These values are used for computing gl_FragCoord in Program::linkVaryings().
GLint coord = currentProgram->getDxCoordLocation(); GLint coord = currentProgram->getDxCoordLocation();
GLfloat whxy[4] = { viewport.width * 0.5f, GLfloat whxy[4] = { actualViewport.width * 0.5f,
viewport.height * 0.5f, actualViewport.height * 0.5f,
viewport.x + (viewport.width * 0.5f), actualViewport.x + (actualViewport.width * 0.5f),
viewport.y + (viewport.height * 0.5f) }; actualViewport.y + (actualViewport.height * 0.5f) };
currentProgram->setUniform4fv(coord, 1, whxy); currentProgram->setUniform4fv(coord, 1, whxy);
GLint depth = currentProgram->getDxDepthLocation(); GLint depth = currentProgram->getDxDepthLocation();
GLfloat dz[2] = { (zFar - zNear) * 0.5f, (zNear + zFar) * 0.5f }; GLfloat dz[2] = { (actualZFar - actualZNear) * 0.5f, (actualZNear + actualZFar) * 0.5f };
currentProgram->setUniform2fv(depth, 1, dz); currentProgram->setUniform2fv(depth, 1, dz);
GLint depthRange = currentProgram->getDxDepthRangeLocation(); GLint depthRange = currentProgram->getDxDepthRangeLocation();
GLfloat nearFarDiff[3] = { zNear, zFar, zFar - zNear }; GLfloat nearFarDiff[3] = { actualZNear, actualZFar, actualZFar - actualZNear };
currentProgram->setUniform3fv(depthRange, 1, nearFarDiff); currentProgram->setUniform3fv(depthRange, 1, nearFarDiff);
} }
......
...@@ -55,7 +55,7 @@ class Renderer11 : public Renderer ...@@ -55,7 +55,7 @@ class Renderer11 : public Renderer
int stencilBackRef, bool frontFaceCCW); int stencilBackRef, bool frontFaceCCW);
virtual void setScissorRectangle(const gl::Rectangle &scissor); virtual void setScissorRectangle(const gl::Rectangle &scissor);
virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, bool ignoreViewport,
gl::ProgramBinary *currentProgram, bool forceSetUniforms); gl::ProgramBinary *currentProgram, bool forceSetUniforms);
virtual bool applyPrimitiveType(GLenum mode, GLsizei count); virtual bool applyPrimitiveType(GLenum mode, GLsizei count);
......
...@@ -911,32 +911,44 @@ void Renderer9::setScissorRectangle(const gl::Rectangle &scissor) ...@@ -911,32 +911,44 @@ void Renderer9::setScissorRectangle(const gl::Rectangle &scissor)
mForceSetScissor = false; mForceSetScissor = false;
} }
bool Renderer9::setViewport(const gl::Rectangle &viewport, float zNear, float zFar, bool Renderer9::setViewport(const gl::Rectangle &viewport, float zNear, float zFar, bool ignoreViewport,
gl::ProgramBinary *currentProgram, bool forceSetUniforms) gl::ProgramBinary *currentProgram, bool forceSetUniforms)
{ {
bool viewportChanged = mForceSetViewport || memcmp(&viewport, &mCurViewport, sizeof(gl::Rectangle)) != 0 || gl::Rectangle actualViewport = viewport;
zNear != mCurNear || zFar != mCurFar; float actualZNear = gl::clamp01(zNear);
float actualZFar = gl::clamp01(zFar);
if (ignoreViewport)
{
actualViewport.x = 0;
actualViewport.y = 0;
actualViewport.width = mRenderTargetDesc.width;
actualViewport.height = mRenderTargetDesc.height;
actualZNear = 0.0f;
actualZFar = 1.0f;
}
D3DVIEWPORT9 dxViewport; D3DVIEWPORT9 dxViewport;
dxViewport.X = gl::clamp(viewport.x, 0, static_cast<int>(mRenderTargetDesc.width)); dxViewport.X = gl::clamp(actualViewport.x, 0, static_cast<int>(mRenderTargetDesc.width));
dxViewport.Y = gl::clamp(viewport.y, 0, static_cast<int>(mRenderTargetDesc.height)); dxViewport.Y = gl::clamp(actualViewport.y, 0, static_cast<int>(mRenderTargetDesc.height));
dxViewport.Width = gl::clamp(viewport.width, 0, static_cast<int>(mRenderTargetDesc.width) - static_cast<int>(dxViewport.X)); dxViewport.Width = gl::clamp(actualViewport.width, 0, static_cast<int>(mRenderTargetDesc.width) - static_cast<int>(dxViewport.X));
dxViewport.Height = gl::clamp(viewport.height, 0, static_cast<int>(mRenderTargetDesc.height) - static_cast<int>(dxViewport.Y)); dxViewport.Height = gl::clamp(actualViewport.height, 0, static_cast<int>(mRenderTargetDesc.height) - static_cast<int>(dxViewport.Y));
dxViewport.MinZ = zNear; dxViewport.MinZ = actualZNear;
dxViewport.MaxZ = zFar; dxViewport.MaxZ = actualZFar;
if (dxViewport.Width <= 0 || dxViewport.Height <= 0) if (dxViewport.Width <= 0 || dxViewport.Height <= 0)
{ {
return false; // Nothing to render return false; // Nothing to render
} }
bool viewportChanged = mForceSetViewport || memcmp(&actualViewport, &mCurViewport, sizeof(gl::Rectangle)) != 0 ||
actualZNear != mCurNear || actualZFar != mCurFar;
if (viewportChanged) if (viewportChanged)
{ {
mDevice->SetViewport(&dxViewport); mDevice->SetViewport(&dxViewport);
mCurViewport = viewport; mCurViewport = actualViewport;
mCurNear = zNear; mCurNear = actualZNear;
mCurFar = zFar; mCurFar = actualZFar;
} }
if (currentProgram && (viewportChanged || forceSetUniforms)) if (currentProgram && (viewportChanged || forceSetUniforms))
...@@ -947,18 +959,18 @@ bool Renderer9::setViewport(const gl::Rectangle &viewport, float zNear, float zF ...@@ -947,18 +959,18 @@ bool Renderer9::setViewport(const gl::Rectangle &viewport, float zNear, float zF
// These values are used for computing gl_FragCoord in Program::linkVaryings(). // These values are used for computing gl_FragCoord in Program::linkVaryings().
GLint coord = currentProgram->getDxCoordLocation(); GLint coord = currentProgram->getDxCoordLocation();
GLfloat whxy[4] = { viewport.width * 0.5f, GLfloat whxy[4] = { actualViewport.width * 0.5f,
viewport.height * 0.5f, actualViewport.height * 0.5f,
viewport.x + (viewport.width * 0.5f), actualViewport.x + (actualViewport.width * 0.5f),
viewport.y + (viewport.height * 0.5f) }; actualViewport.y + (actualViewport.height * 0.5f) };
currentProgram->setUniform4fv(coord, 1, whxy); currentProgram->setUniform4fv(coord, 1, whxy);
GLint depth = currentProgram->getDxDepthLocation(); GLint depth = currentProgram->getDxDepthLocation();
GLfloat dz[2] = { (zFar - zNear) * 0.5f, (zNear + zFar) * 0.5f }; GLfloat dz[2] = { (actualZFar - actualZNear) * 0.5f, (actualZNear + actualZFar) * 0.5f };
currentProgram->setUniform2fv(depth, 1, dz); currentProgram->setUniform2fv(depth, 1, dz);
GLint depthRange = currentProgram->getDxDepthRangeLocation(); GLint depthRange = currentProgram->getDxDepthRangeLocation();
GLfloat nearFarDiff[3] = { zNear, zFar, zFar - zNear }; GLfloat nearFarDiff[3] = { actualZNear, actualZFar, actualZFar - actualZNear };
currentProgram->setUniform3fv(depthRange, 1, nearFarDiff); currentProgram->setUniform3fv(depthRange, 1, nearFarDiff);
} }
......
...@@ -90,7 +90,7 @@ class Renderer9 : public Renderer ...@@ -90,7 +90,7 @@ class Renderer9 : public Renderer
int stencilBackRef, bool frontFaceCCW); int stencilBackRef, bool frontFaceCCW);
virtual void setScissorRectangle(const gl::Rectangle &scissor); virtual void setScissorRectangle(const gl::Rectangle &scissor);
virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, bool ignoreViewport,
gl::ProgramBinary *currentProgram, bool forceSetUniforms); gl::ProgramBinary *currentProgram, bool forceSetUniforms);
virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer); virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer);
......
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