Commit 824e7b3e by Nicolas Capens

Implement alpha testing.

Change-Id: I0fe062ea826b73b2bdf28ad3ed6e72e51c576840 Reviewed-on: https://swiftshader-review.googlesource.com/3635Tested-by: 's avatarNicolas Capens <capn@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 18bcfcc5
......@@ -307,6 +307,7 @@ copy "$(OutDir)libEGL.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)_$(Platfor
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\common\debug.h" />
<ClInclude Include="..\common\Image.hpp" />
<ClInclude Include="..\common\Object.hpp" />
<ClInclude Include="..\include\EGL\egl.h" />
<ClInclude Include="..\include\EGL\eglext.h" />
......@@ -314,7 +315,6 @@ copy "$(OutDir)libEGL.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)_$(Platfor
<ClInclude Include="Config.h" />
<ClInclude Include="Context.hpp" />
<ClInclude Include="Display.h" />
<ClInclude Include="Image.hpp" />
<ClInclude Include="libEGL.hpp" />
<ClInclude Include="main.h" />
<ClInclude Include="resource.h" />
......
......@@ -64,9 +64,6 @@
<ClInclude Include="Context.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Image.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Texture.hpp">
<Filter>Header Files</Filter>
</ClInclude>
......@@ -76,6 +73,9 @@
<ClInclude Include="libEGL.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\common\Image.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="libEGL.rc" />
......
......@@ -206,6 +206,10 @@ Context::Context(const egl::Config *config, const Context *shareContext)
clipFlags = 0;
alphaTest = false;
alphaTestFunc = GL_ALWAYS;
alphaTestRef = 0;
mHasBeenCurrent = false;
markAllStateDirty();
......@@ -374,6 +378,22 @@ void Context::setDepthRange(float zNear, float zFar)
mState.zFar = zFar;
}
void Context::setAlphaTest(bool enabled)
{
alphaTest = enabled;
}
bool Context::isAlphaTestEnabled() const
{
return alphaTest;
}
void Context::setAlphaFunc(GLenum alphaFunc, GLclampf reference)
{
alphaTestFunc = alphaFunc;
alphaTestRef = reference;
}
void Context::setBlend(bool enabled)
{
if(mState.blend != enabled)
......@@ -1822,6 +1842,10 @@ void Context::applyState(GLenum drawMode)
device->setTextureTransform(1, textureStack1.isIdentity() ? 0 : 4, false);
device->setTexGen(0, sw::TEXGEN_NONE);
device->setTexGen(1, sw::TEXGEN_NONE);
device->setAlphaTestEnable(alphaTest);
device->setAlphaCompare(es2sw::ConvertAlphaComparison(alphaTestFunc));
device->setAlphaReference(alphaTestRef * 0xFF);
}
GLenum Context::applyVertexBuffer(GLint base, GLint first, GLsizei count)
......@@ -2995,6 +3019,11 @@ void Context::setClipPlaneEnable(int index, bool enable)
device->setClipFlags(clipFlags);
}
bool Context::isClipPlaneEnabled(int index) const
{
return (clipFlags & (1 << index)) != 0;
}
void Context::clientActiveTexture(GLenum texture)
{
clientTexture = texture;
......
......@@ -300,6 +300,10 @@ public:
void setDepthFunc(GLenum depthFunc);
void setDepthRange(float zNear, float zFar);
void setAlphaTest(bool enabled);
bool isAlphaTestEnabled() const;
void setAlphaFunc(GLenum alphaFunc, GLclampf reference);
void setBlend(bool enabled);
bool isBlendEnabled() const;
void setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha);
......@@ -480,6 +484,7 @@ public:
void setClipPlane(int index, const float plane[4]);
void setClipPlaneEnable(int index, bool enable);
bool isClipPlaneEnabled(int index) const;
private:
virtual ~Context();
......@@ -553,6 +558,10 @@ private:
int clipFlags;
bool alphaTest;
GLenum alphaTestFunc;
float alphaTestRef;
Device *device;
ResourceManager *mResourceManager;
};
......
......@@ -97,7 +97,29 @@ void ActiveTexture(GLenum texture)
void AlphaFunc(GLenum func, GLclampf ref)
{
UNIMPLEMENTED();
TRACE("(GLenum func = 0x%X, GLclampf ref = %f)", func, ref);
switch(func)
{
case GL_NEVER:
case GL_ALWAYS:
case GL_LESS:
case GL_LEQUAL:
case GL_EQUAL:
case GL_GEQUAL:
case GL_GREATER:
case GL_NOTEQUAL:
break;
default:
return error(GL_INVALID_ENUM);
}
es1::Context *context = es1::getContext();
if(context)
{
context->setAlphaFunc(func, clamp01(ref));
}
}
void AlphaFuncx(GLenum func, GLclampx ref)
......@@ -1188,7 +1210,7 @@ void Disable(GLenum cap)
case GL_FOG: context->setFog(false); break;
case GL_TEXTURE_2D: context->setTexture2Denabled(false); break;
case GL_TEXTURE_EXTERNAL_OES: context->setTextureExternalEnabled(false); break;
case GL_ALPHA_TEST: UNIMPLEMENTED(); break;
case GL_ALPHA_TEST: context->setAlphaTest(false); break;
case GL_COLOR_LOGIC_OP: UNIMPLEMENTED(); break;
case GL_POINT_SMOOTH: UNIMPLEMENTED(); break;
case GL_LINE_SMOOTH: UNIMPLEMENTED(); break;
......@@ -1310,7 +1332,7 @@ void Enable(GLenum cap)
case GL_FOG: context->setFog(true); break;
case GL_TEXTURE_2D: context->setTexture2Denabled(true); break;
case GL_TEXTURE_EXTERNAL_OES: context->setTextureExternalEnabled(true); break;
case GL_ALPHA_TEST: UNIMPLEMENTED(); break;
case GL_ALPHA_TEST: context->setAlphaTest(true); break;
case GL_COLOR_LOGIC_OP: UNIMPLEMENTED(); break;
case GL_POINT_SMOOTH: UNIMPLEMENTED(); break;
case GL_LINE_SMOOTH: UNIMPLEMENTED(); break;
......@@ -2386,6 +2408,13 @@ GLboolean IsEnabled(GLenum cap)
case GL_DEPTH_TEST: return context->isDepthTestEnabled();
case GL_BLEND: return context->isBlendEnabled();
case GL_DITHER: return context->isDitherEnabled();
case GL_ALPHA_TEST: return context->isAlphaTestEnabled();
case GL_CLIP_PLANE0: return context->isClipPlaneEnabled(0);
case GL_CLIP_PLANE1: return context->isClipPlaneEnabled(1);
case GL_CLIP_PLANE2: return context->isClipPlaneEnabled(2);
case GL_CLIP_PLANE3: return context->isClipPlaneEnabled(3);
case GL_CLIP_PLANE4: return context->isClipPlaneEnabled(4);
case GL_CLIP_PLANE5: return context->isClipPlaneEnabled(5);
default:
return error(GL_INVALID_ENUM, GL_FALSE);
}
......
......@@ -238,6 +238,24 @@ namespace es2sw
return sw::STENCIL_ALWAYS;
}
sw::AlphaCompareMode ConvertAlphaComparison(GLenum comparison)
{
switch(comparison)
{
case GL_NEVER: return sw::ALPHA_NEVER;
case GL_ALWAYS: return sw::ALPHA_ALWAYS;
case GL_LESS: return sw::ALPHA_LESS;
case GL_LEQUAL: return sw::ALPHA_LESSEQUAL;
case GL_EQUAL: return sw::ALPHA_EQUAL;
case GL_GREATER: return sw::ALPHA_GREATER;
case GL_GEQUAL: return sw::ALPHA_GREATEREQUAL;
case GL_NOTEQUAL: return sw::ALPHA_NOTEQUAL;
default: UNREACHABLE(comparison);
}
return sw::ALPHA_ALWAYS;
}
sw::Color<float> ConvertColor(es1::Color color)
{
return sw::Color<float>(color.red, color.green, color.blue, color.alpha);
......
......@@ -48,6 +48,7 @@ namespace es2sw
{
sw::DepthCompareMode ConvertDepthComparison(GLenum comparison);
sw::StencilCompareMode ConvertStencilComparison(GLenum comparison);
sw::AlphaCompareMode ConvertAlphaComparison(GLenum comparison);
sw::Color<float> ConvertColor(es1::Color color);
sw::BlendFactor ConvertBlendFunc(GLenum blend);
sw::BlendOperation ConvertBlendOp(GLenum blendOp);
......
......@@ -98,7 +98,7 @@ namespace sw
struct DrawData
{
const void *constants;
const Constants *constants;
const void *input[VERTEX_ATTRIBUTES];
unsigned int stride[VERTEX_ATTRIBUTES];
......
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