Skip to content

Commit

Permalink
Apply ComparisonFunction in SamplerState.OpenGL
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Jones committed Mar 18, 2015
1 parent 59d6eb7 commit 3624b2d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 30 deletions.
24 changes: 24 additions & 0 deletions MonoGame.Framework/Graphics/GraphicsExtensions.cs
Expand Up @@ -438,6 +438,30 @@ public static BlendingFactorDest GetBlendFactorDest (this Blend blend)

}

public static DepthFunction GetDepthFunction(this CompareFunction compare)
{
switch (compare)
{
default:
case CompareFunction.Always:
return DepthFunction.Always;
case CompareFunction.Equal:
return DepthFunction.Equal;
case CompareFunction.Greater:
return DepthFunction.Greater;
case CompareFunction.GreaterEqual:
return DepthFunction.Gequal;
case CompareFunction.Less:
return DepthFunction.Less;
case CompareFunction.LessEqual:
return DepthFunction.Lequal;
case CompareFunction.Never:
return DepthFunction.Never;
case CompareFunction.NotEqual:
return DepthFunction.Notequal;
}
}

#if WINDOWS || LINUX || ANGLE
/// <summary>
/// Convert a <see cref="SurfaceFormat"/> to an OpenTK.Graphics.ColorFormat.
Expand Down
31 changes: 1 addition & 30 deletions MonoGame.Framework/Graphics/States/DepthStencilState.OpenGL.cs
Expand Up @@ -37,36 +37,7 @@ internal void PlatformApplyState(GraphicsDevice device, bool force = false)

if (force || this.DepthBufferFunction != device._lastDepthStencilState.DepthBufferFunction)
{
DepthFunction func;
switch (DepthBufferFunction)
{
default:
case CompareFunction.Always:
func = DepthFunction.Always;
break;
case CompareFunction.Equal:
func = DepthFunction.Equal;
break;
case CompareFunction.Greater:
func = DepthFunction.Greater;
break;
case CompareFunction.GreaterEqual:
func = DepthFunction.Gequal;
break;
case CompareFunction.Less:
func = DepthFunction.Less;
break;
case CompareFunction.LessEqual:
func = DepthFunction.Lequal;
break;
case CompareFunction.Never:
func = DepthFunction.Never;
break;
case CompareFunction.NotEqual:
func = DepthFunction.Notequal;
break;
}
GL.DepthFunc(func);
GL.DepthFunc(DepthBufferFunction.GetDepthFunction());
GraphicsExtensions.CheckGLError();
device._lastDepthStencilState.DepthBufferFunction = this.DepthBufferFunction;
}
Expand Down
13 changes: 13 additions & 0 deletions MonoGame.Framework/Graphics/States/SamplerState.OpenGL.cs
Expand Up @@ -149,6 +149,19 @@ internal void Activate(GraphicsDevice device, TextureTarget target, bool useMipm
// LOD bias is not supported by glTexParameter in OpenGL ES 2.0
GL.TexParameter(target, TextureParameterName.TextureLodBias, MipMapLevelOfDetailBias);
GraphicsExtensions.CheckGLError();
// Comparison samplers are not supported in OpenGL ES 2.0 (without an extension, anyway)
if (ComparisonFunction != CompareFunction.Never)
{
GL.TexParameter(target, TextureParameterName.TextureCompareMode, (int) TextureCompareMode.CompareRefToTexture);
GraphicsExtensions.CheckGLError();
GL.TexParameter(target, TextureParameterName.TextureCompareFunc, (int) ComparisonFunction.GetDepthFunction());
GraphicsExtensions.CheckGLError();
}
else
{
GL.TexParameter(target, TextureParameterName.TextureCompareMode, (int) TextureCompareMode.None);
GraphicsExtensions.CheckGLError();
}
#endif
if (GraphicsDevice.GraphicsCapabilities.SupportsTextureMaxLevel)
{
Expand Down

2 comments on commit 3624b2d

@mgbot
Copy link
Member

@mgbot mgbot commented on 3624b2d Mar 18, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity MonoGame :: Develop (Win) Build 3.4.0.30 is now running

@mgbot
Copy link
Member

@mgbot mgbot commented on 3624b2d Mar 18, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity MonoGame :: Develop (Win) Build 3.4.0.30 outcome was SUCCESS
Summary: Tests passed: 460, ignored: 6 Build time: 00:14:57

Please sign in to comment.