Combine dx_Depth and dx_FrontCCW into dx_DepthFront.

TRAC #22245 Signed-off-by: Daniel Koch Signed-off-by: Geoff Lang Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1582 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 97c852b2
......@@ -207,13 +207,12 @@ void OutputHLSL::header()
if (mUsesFragCoord)
{
out << "uniform float4 dx_Coord;\n"
"uniform float2 dx_Depth;\n";
out << "uniform float4 dx_Coord;\n";
}
if (mUsesFrontFacing)
if (mUsesFragCoord || mUsesFrontFacing)
{
out << "uniform float dx_FrontCCW;\n";
out << "uniform float3 dx_DepthFront;\n";
}
out << "\n";
......
......@@ -1701,8 +1701,8 @@ bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *nu
}
// Applies the render target surface, depth stencil surface, viewport rectangle and
// scissor rectangle to the Direct3D 9 device
bool Context::applyRenderTarget(bool ignoreViewport)
// scissor rectangle to the renderer
bool Context::applyRenderTarget(GLenum drawMode, bool ignoreViewport)
{
Framebuffer *framebufferObject = getDrawFramebuffer();
......@@ -1714,8 +1714,8 @@ bool Context::applyRenderTarget(bool ignoreViewport)
mRenderer->applyRenderTarget(framebufferObject);
ProgramBinary *programBinary = mState.currentProgram ? getCurrentProgramBinary() : NULL;
if (!mRenderer->setViewport(mState.viewport, mState.zNear, mState.zFar, ignoreViewport,
programBinary, mDxUniformsDirty))
if (!mRenderer->setViewport(mState.viewport, mState.zNear, mState.zFar, drawMode, mState.rasterizer.frontFace,
ignoreViewport, programBinary, mDxUniformsDirty))
{
return false;
}
......@@ -1729,14 +1729,6 @@ bool Context::applyRenderTarget(bool ignoreViewport)
// Applies the fixed-function state (culling, depth test, alpha blending, stenciling, etc) to the Direct3D 9 device
void Context::applyState(GLenum drawMode)
{
ProgramBinary *programBinary = getCurrentProgramBinary();
Framebuffer *framebufferObject = getDrawFramebuffer();
GLint frontCCW = programBinary->getDxFrontCCWLocation();
GLfloat ccw = !IsTriangleMode(drawMode) ? 0.0f : (mState.rasterizer.frontFace == GL_CCW ? 1.0f : -1.0f);
programBinary->setUniform1fv(frontCCW, 1, &ccw);
mRenderer->setRasterizerState(mState.rasterizer);
unsigned int mask = 0;
......@@ -1744,6 +1736,7 @@ void Context::applyState(GLenum drawMode)
{
if (mState.sampleCoverageValue != 0)
{
Framebuffer *framebufferObject = getDrawFramebuffer();
float threshold = 0.5f;
for (int i = 0; i < framebufferObject->getSamples(); ++i)
......@@ -1946,7 +1939,7 @@ void Context::clear(GLbitfield mask)
return error(GL_INVALID_VALUE);
}
if (!applyRenderTarget(true)) // Clips the clear to the scissor rectangle but not the viewport
if (!applyRenderTarget(GL_TRIANGLES, true)) // Clips the clear to the scissor rectangle but not the viewport
{
return;
}
......@@ -1977,7 +1970,7 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instan
return;
}
if (!applyRenderTarget(false))
if (!applyRenderTarget(mode, false))
{
return;
}
......@@ -2023,7 +2016,7 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid
return;
}
if (!applyRenderTarget(false))
if (!applyRenderTarget(mode, false))
{
return;
}
......
......@@ -69,8 +69,8 @@ enum
MAX_TEXTURE_IMAGE_UNITS = 16,
MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF = 4, // For devices supporting vertex texture fetch
MAX_COMBINED_TEXTURE_IMAGE_UNITS_VTF = MAX_TEXTURE_IMAGE_UNITS + MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF,
MAX_FRAGMENT_UNIFORM_VECTORS_SM2 = 32 - 4, // Reserve space for dx_Coord, dx_Depth, dx_DepthRange and dx_FrontCCW.
MAX_FRAGMENT_UNIFORM_VECTORS_SM3 = 224 - 4,
MAX_FRAGMENT_UNIFORM_VECTORS_SM2 = 32 - 3, // Reserve space for dx_Coord, dx_DepthFront and dx_DepthRange.
MAX_FRAGMENT_UNIFORM_VECTORS_SM3 = 224 - 3,
MAX_DRAW_BUFFERS = 1
};
......@@ -423,7 +423,7 @@ class Context
private:
DISALLOW_COPY_AND_ASSIGN(Context);
bool applyRenderTarget(bool ignoreViewport);
bool applyRenderTarget(GLenum drawMode, bool ignoreViewport);
void applyState(GLenum drawMode);
void applyShaders();
void applyTextures();
......
......@@ -83,10 +83,9 @@ ProgramBinary::ProgramBinary(rx::Renderer *renderer) : mRenderer(renderer), RefC
mUsedPixelSamplerRange = 0;
mDxDepthRangeLocation = -1;
mDxDepthLocation = -1;
mDxDepthFrontLocation = -1;
mDxCoordLocation = -1;
mDxHalfPixelSizeLocation = -1;
mDxFrontCCWLocation = -1;
}
ProgramBinary::~ProgramBinary()
......@@ -1462,7 +1461,7 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, std::string& pixelHLSL, std::
" gl_FragCoord.y = (input.gl_FragCoord.y * rhw) * dx_Coord.y + dx_Coord.w;\n";
}
pixelHLSL += " gl_FragCoord.z = (input.gl_FragCoord.z * rhw) * dx_Depth.x + dx_Depth.y;\n"
pixelHLSL += " gl_FragCoord.z = (input.gl_FragCoord.z * rhw) * dx_DepthFront.x + dx_DepthFront.y;\n"
" gl_FragCoord.w = rhw;\n";
}
......@@ -1474,7 +1473,7 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, std::string& pixelHLSL, std::
if (fragmentShader->mUsesFrontFacing)
{
pixelHLSL += " gl_FrontFacing = (input.vFace * dx_FrontCCW >= 0.0);\n";
pixelHLSL += " gl_FrontFacing = (input.vFace * dx_DepthFront.z >= 0.0);\n";
}
for (VaryingList::iterator varying = fragmentShader->mVaryings.begin(); varying != fragmentShader->mVaryings.end(); varying++)
......@@ -1625,10 +1624,9 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length)
}
stream.read(&mDxDepthRangeLocation);
stream.read(&mDxDepthLocation);
stream.read(&mDxDepthFrontLocation);
stream.read(&mDxCoordLocation);
stream.read(&mDxHalfPixelSizeLocation);
stream.read(&mDxFrontCCWLocation);
unsigned int pixelShaderSize;
stream.read(&pixelShaderSize);
......@@ -1733,10 +1731,9 @@ bool ProgramBinary::save(void* binary, GLsizei bufSize, GLsizei *length)
}
stream.write(mDxDepthRangeLocation);
stream.write(mDxDepthLocation);
stream.write(mDxDepthFrontLocation);
stream.write(mDxCoordLocation);
stream.write(mDxHalfPixelSizeLocation);
stream.write(mDxFrontCCWLocation);
UINT pixelShaderSize = mPixelExecutable->getLength();
stream.write(pixelShaderSize);
......@@ -1859,10 +1856,9 @@ bool ProgramBinary::link(InfoLog &infoLog, const AttributeBindings &attributeBin
// these uniforms are searched as already-decorated because gl_ and dx_
// are reserved prefixes, and do not receive additional decoration
mDxDepthRangeLocation = getUniformLocation("dx_DepthRange");
mDxDepthLocation = getUniformLocation("dx_Depth");
mDxDepthFrontLocation = getUniformLocation("dx_DepthFront");
mDxCoordLocation = getUniformLocation("dx_Coord");
mDxHalfPixelSizeLocation = getUniformLocation("dx_HalfPixelSize");
mDxFrontCCWLocation = getUniformLocation("dx_FrontCCW");
Context *context = getContext();
context->markDxUniformsDirty();
......@@ -2655,9 +2651,9 @@ GLint ProgramBinary::getDxDepthRangeLocation() const
return mDxDepthRangeLocation;
}
GLint ProgramBinary::getDxDepthLocation() const
GLint ProgramBinary::getDxDepthFrontLocation() const
{
return mDxDepthLocation;
return mDxDepthFrontLocation;
}
GLint ProgramBinary::getDxCoordLocation() const
......@@ -2670,11 +2666,6 @@ GLint ProgramBinary::getDxHalfPixelSizeLocation() const
return mDxHalfPixelSizeLocation;
}
GLint ProgramBinary::getDxFrontCCWLocation() const
{
return mDxFrontCCWLocation;
}
ProgramBinary::Sampler::Sampler() : active(false), logicalTextureUnit(0), textureType(TEXTURE_2D)
{
}
......
......@@ -130,10 +130,9 @@ class ProgramBinary : public RefCountObject
bool getUniformiv(GLint location, GLsizei *bufSize, GLint *params);
GLint getDxDepthRangeLocation() const;
GLint getDxDepthLocation() const;
GLint getDxDepthFrontLocation() const;
GLint getDxCoordLocation() const;
GLint getDxHalfPixelSizeLocation() const;
GLint getDxFrontCCWLocation() const;
void dirtyAllUniforms();
void applyUniforms();
......@@ -212,10 +211,9 @@ class ProgramBinary : public RefCountObject
UniformIndex mUniformIndex;
GLint mDxDepthRangeLocation;
GLint mDxDepthLocation;
GLint mDxDepthFrontLocation;
GLint mDxCoordLocation;
GLint mDxHalfPixelSizeLocation;
GLint mDxFrontCCWLocation;
bool mValidated;
......
......@@ -90,8 +90,8 @@ class Renderer
int stencilBackRef, bool frontFaceCCW) = 0;
virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled) = 0;
virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, bool ignoreViewport,
gl::ProgramBinary *currentProgram, bool forceSetUniforms) = 0;
virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace,
bool ignoreViewport, gl::ProgramBinary *currentProgram, bool forceSetUniforms) = 0;
virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer) = 0;
virtual void applyShaders(gl::ProgramBinary *programBinary) = 0;
......
......@@ -384,8 +384,8 @@ void Renderer11::setScissorRectangle(const gl::Rectangle &scissor, bool enabled)
mForceSetScissor = false;
}
bool Renderer11::setViewport(const gl::Rectangle &viewport, float zNear, float zFar, bool ignoreViewport,
gl::ProgramBinary *currentProgram, bool forceSetUniforms)
bool Renderer11::setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace,
bool ignoreViewport, gl::ProgramBinary *currentProgram, bool forceSetUniforms)
{
gl::Rectangle actualViewport = viewport;
float actualZNear = gl::clamp01(zNear);
......@@ -439,9 +439,10 @@ bool Renderer11::setViewport(const gl::Rectangle &viewport, float zNear, float z
actualViewport.y + (actualViewport.height * 0.5f) };
currentProgram->setUniform4fv(coord, 1, whxy);
GLint depth = currentProgram->getDxDepthLocation();
GLfloat dz[2] = { (actualZFar - actualZNear) * 0.5f, (actualZNear + actualZFar) * 0.5f };
currentProgram->setUniform2fv(depth, 1, dz);
GLint depthFront = currentProgram->getDxDepthFrontLocation();
GLfloat ccw = !gl::IsTriangleMode(drawMode) ? 0.0f : (frontFace == GL_CCW ? 1.0f : -1.0f);
GLfloat dz[3] = { (actualZFar - actualZNear) * 0.5f, (actualZNear + actualZFar) * 0.5f, ccw };
currentProgram->setUniform3fv(depthFront, 1, dz);
GLint depthRange = currentProgram->getDxDepthRangeLocation();
GLfloat nearFarDiff[3] = { actualZNear, actualZFar, actualZFar - actualZNear };
......
......@@ -56,8 +56,8 @@ class Renderer11 : public Renderer
int stencilBackRef, bool frontFaceCCW);
virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled);
virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, bool ignoreViewport,
gl::ProgramBinary *currentProgram, bool forceSetUniforms);
virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace,
bool ignoreViewport, gl::ProgramBinary *currentProgram, bool forceSetUniforms);
virtual bool applyPrimitiveType(GLenum mode, GLsizei count);
virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer);
......
......@@ -892,8 +892,8 @@ void Renderer9::setScissorRectangle(const gl::Rectangle &scissor, bool enabled)
mForceSetScissor = false;
}
bool Renderer9::setViewport(const gl::Rectangle &viewport, float zNear, float zFar, bool ignoreViewport,
gl::ProgramBinary *currentProgram, bool forceSetUniforms)
bool Renderer9::setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace,
bool ignoreViewport, gl::ProgramBinary *currentProgram, bool forceSetUniforms)
{
gl::Rectangle actualViewport = viewport;
float actualZNear = gl::clamp01(zNear);
......@@ -946,9 +946,10 @@ bool Renderer9::setViewport(const gl::Rectangle &viewport, float zNear, float zF
actualViewport.y + (actualViewport.height * 0.5f) };
currentProgram->setUniform4fv(coord, 1, whxy);
GLint depth = currentProgram->getDxDepthLocation();
GLfloat dz[2] = { (actualZFar - actualZNear) * 0.5f, (actualZNear + actualZFar) * 0.5f };
currentProgram->setUniform2fv(depth, 1, dz);
GLint depthFront = currentProgram->getDxDepthFrontLocation();
GLfloat ccw = !gl::IsTriangleMode(drawMode) ? 0.0f : (frontFace == GL_CCW ? 1.0f : -1.0f);
GLfloat dz[3] = { (actualZFar - actualZNear) * 0.5f, (actualZNear + actualZFar) * 0.5f, ccw };
currentProgram->setUniform3fv(depthFront, 1, dz);
GLint depthRange = currentProgram->getDxDepthRangeLocation();
GLfloat nearFarDiff[3] = { actualZNear, actualZFar, actualZFar - actualZNear };
......
......@@ -85,8 +85,8 @@ class Renderer9 : public Renderer
int stencilBackRef, bool frontFaceCCW);
virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled);
virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, bool ignoreViewport,
gl::ProgramBinary *currentProgram, bool forceSetUniforms);
virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace,
bool ignoreViewport, gl::ProgramBinary *currentProgram, bool forceSetUniforms);
virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer);
virtual void applyShaders(gl::ProgramBinary *programBinary);
......
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