Implemented gl_FrontFacing for lines and points

TRAC #11419 Lines and points are always considered front-facing Signed-off-by: Shannon Woods Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@153 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent e007896b
...@@ -104,7 +104,8 @@ void OutputHLSL::header() ...@@ -104,7 +104,8 @@ void OutputHLSL::header()
out << "uniform float4 gl_Window;\n" out << "uniform float4 gl_Window;\n"
"uniform float2 gl_Depth;\n" "uniform float2 gl_Depth;\n"
"uniform bool gl_frontCCW;\n" "uniform bool gl_PointsOrLines;\n"
"uniform bool gl_FrontCCW;\n"
"\n"; "\n";
out << uniforms; out << uniforms;
out << "\n" out << "\n"
...@@ -546,7 +547,7 @@ void OutputHLSL::footer() ...@@ -546,7 +547,7 @@ void OutputHLSL::footer()
" gl_FragCoord.y = (input.gl_FragCoord.y * rhw) * gl_Window.y + gl_Window.w;\n" " gl_FragCoord.y = (input.gl_FragCoord.y * rhw) * gl_Window.y + gl_Window.w;\n"
" gl_FragCoord.z = (input.gl_FragCoord.z * rhw) * gl_Depth.x + gl_Depth.y;\n" " gl_FragCoord.z = (input.gl_FragCoord.z * rhw) * gl_Depth.x + gl_Depth.y;\n"
" gl_FragCoord.w = rhw;\n" " gl_FragCoord.w = rhw;\n"
" gl_FrontFacing = gl_frontCCW ? (input.vFace >= 0.0) : (input.vFace <= 0.0);\n"; " gl_FrontFacing = gl_PointsOrLines || (gl_FrontCCW ? (input.vFace >= 0.0) : (input.vFace <= 0.0));\n";
for (TSymbolTableLevel::const_iterator namedSymbol = symbols->begin(); namedSymbol != symbols->end(); namedSymbol++) for (TSymbolTableLevel::const_iterator namedSymbol = symbols->begin(); namedSymbol != symbols->end(); namedSymbol++)
{ {
......
...@@ -1256,15 +1256,19 @@ bool Context::applyRenderTarget(bool ignoreViewport) ...@@ -1256,15 +1256,19 @@ bool Context::applyRenderTarget(bool ignoreViewport)
} }
// Applies the fixed-function state (culling, depth test, alpha blending, stenciling, etc) to the Direct3D 9 device // Applies the fixed-function state (culling, depth test, alpha blending, stenciling, etc) to the Direct3D 9 device
void Context::applyState() void Context::applyState(GLenum drawMode)
{ {
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
Program *programObject = getCurrentProgram(); Program *programObject = getCurrentProgram();
GLint frontCCW = programObject->getUniformLocation("gl_frontCCW"); GLint frontCCW = programObject->getUniformLocation("gl_FrontCCW");
GLint ccw = (frontFace == GL_CCW); GLint ccw = (frontFace == GL_CCW);
programObject->setUniform1iv(frontCCW, 1, &ccw); programObject->setUniform1iv(frontCCW, 1, &ccw);
GLint pointsOrLines = programObject->getUniformLocation("gl_PointsOrLines");
GLint alwaysFront = !isTriangleMode(drawMode);
programObject->setUniform1iv(pointsOrLines, 1, &alwaysFront);
if (cullFace) if (cullFace)
{ {
device->SetRenderState(D3DRS_CULLMODE, es2dx::ConvertCullMode(cullMode, frontFace)); device->SetRenderState(D3DRS_CULLMODE, es2dx::ConvertCullMode(cullMode, frontFace));
...@@ -1854,7 +1858,7 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count) ...@@ -1854,7 +1858,7 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
return error(GL_INVALID_FRAMEBUFFER_OPERATION); return error(GL_INVALID_FRAMEBUFFER_OPERATION);
} }
applyState(); applyState(mode);
applyVertexBuffer(first, count); applyVertexBuffer(first, count);
applyShaders(); applyShaders();
applyTextures(); applyTextures();
...@@ -1896,7 +1900,7 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void* ...@@ -1896,7 +1900,7 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void*
return error(GL_INVALID_FRAMEBUFFER_OPERATION); return error(GL_INVALID_FRAMEBUFFER_OPERATION);
} }
applyState(); applyState(mode);
TranslatedIndexData indexInfo = applyIndexBuffer(indices, count, mode, type); TranslatedIndexData indexInfo = applyIndexBuffer(indices, count, mode, type);
applyVertexBuffer(indexInfo); applyVertexBuffer(indexInfo);
applyShaders(); applyShaders();
...@@ -2189,19 +2193,29 @@ Texture *Context::getIncompleteTexture(SamplerType type) ...@@ -2189,19 +2193,29 @@ Texture *Context::getIncompleteTexture(SamplerType type)
return t; return t;
} }
bool Context::cullSkipsDraw(GLenum primitiveType) bool Context::cullSkipsDraw(GLenum drawMode)
{
return cullFace && cullMode == GL_FRONT_AND_BACK && isTriangleMode(drawMode);
}
bool Context::isTriangleMode(GLenum drawMode)
{ {
if (cullFace && cullMode == GL_FRONT_AND_BACK && switch (drawMode)
(primitiveType == GL_TRIANGLES || primitiveType == GL_TRIANGLE_FAN || primitiveType == GL_TRIANGLE_STRIP))
{ {
case GL_TRIANGLES:
case GL_TRIANGLE_FAN:
case GL_TRIANGLE_STRIP:
return true; return true;
} case GL_POINTS:
else case GL_LINES:
{ case GL_LINE_LOOP:
case GL_LINE_STRIP:
return false; return false;
default: UNREACHABLE();
} }
}
return false;
}
} }
extern "C" extern "C"
......
...@@ -264,7 +264,7 @@ class Context : public State ...@@ -264,7 +264,7 @@ class Context : public State
bool getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams); bool getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams);
bool applyRenderTarget(bool ignoreViewport); bool applyRenderTarget(bool ignoreViewport);
void applyState(); void applyState(GLenum drawMode);
void applyVertexBuffer(GLint first, GLsizei count); void applyVertexBuffer(GLint first, GLsizei count);
void applyVertexBuffer(const TranslatedIndexData &indexInfo); void applyVertexBuffer(const TranslatedIndexData &indexInfo);
TranslatedIndexData applyIndexBuffer(const void *indices, GLsizei count, GLenum mode, GLenum type); TranslatedIndexData applyIndexBuffer(const void *indices, GLsizei count, GLenum mode, GLenum type);
...@@ -304,7 +304,8 @@ class Context : public State ...@@ -304,7 +304,8 @@ class Context : public State
Texture *getIncompleteTexture(SamplerType type); Texture *getIncompleteTexture(SamplerType type);
bool cullSkipsDraw(GLenum primitiveType); bool cullSkipsDraw(GLenum drawMode);
bool isTriangleMode(GLenum drawMode);
const egl::Config *const mConfig; const egl::Config *const mConfig;
......
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