Commit c82fc413 by Geoff Lang Committed by Shannon Woods

Added support for TEXTURE_COMPARE_MODE and TEXTURE_COMPARE_FUNC sampler states.

TRAC #23394 Signed-off-by: Nicolas Capens Signed-off-by: Shannon Woods Author: Geoff Lang
parent 08be89da
......@@ -36,8 +36,10 @@ Texture::Texture(rx::Renderer *renderer, GLuint id) : RefCountObject(id)
mSamplerState.wrapR = GL_REPEAT;
mSamplerState.maxAnisotropy = 1.0f;
mSamplerState.lodOffset = 0;
mSamplerState.compareMode = GL_NONE;
mSamplerState.compareFunc = GL_LEQUAL;
mUsage = GL_NONE;
mDirtyImages = true;
mImmutable = false;
......@@ -138,6 +140,40 @@ bool Texture::setMaxAnisotropy(float textureMaxAnisotropy, float contextMaxAniso
return true;
}
bool Texture::setCompareMode(GLenum mode)
{
// Acceptable mode parameters from GLES 3.0.2 spec, table 3.17
switch (mode)
{
case GL_NONE:
case GL_COMPARE_REF_TO_TEXTURE:
mSamplerState.compareMode = mode;
return true;
default:
return false;
}
}
bool Texture::setCompareFunc(GLenum func)
{
// Acceptable function parameters from GLES 3.0.2 spec, table 3.17
switch (func)
{
case GL_LEQUAL:
case GL_GEQUAL:
case GL_LESS:
case GL_GREATER:
case GL_EQUAL:
case GL_NOTEQUAL:
case GL_ALWAYS:
case GL_NEVER:
mSamplerState.compareFunc = func;
return true;
default:
return false;
}
}
// Returns true on successful usage state update (valid enum parameter)
bool Texture::setUsage(GLenum usage)
{
......@@ -672,6 +708,23 @@ bool Texture2D::isSamplerComplete() const
}
}
// OpenGLES 3.0.2 spec section 3.8.13 states that a texture is not mipmap complete if:
// The internalformat specified for the texture arrays is a sized internal depth or
// depth and stencil format (see table 3.13), the value of TEXTURE_COMPARE_-
// MODE is NONE, and either the magnification filter is not NEAREST or the mini-
// fication filter is neither NEAREST nor NEAREST_MIPMAP_NEAREST.
if (gl::GetDepthBits(getInternalFormat(0), mRenderer->getCurrentClientVersion()) > 0)
{
if (mSamplerState.compareMode == GL_NONE)
{
if ((mSamplerState.minFilter != GL_NEAREST && mSamplerState.minFilter != GL_NEAREST_MIPMAP_NEAREST) ||
mSamplerState.magFilter != GL_NEAREST)
{
return false;
}
}
}
return true;
}
......
......@@ -74,6 +74,8 @@ class Texture : public RefCountObject
bool setWrapT(GLenum wrap);
bool setWrapR(GLenum wrap);
bool setMaxAnisotropy(float textureMaxAnisotropy, float contextMaxAnisotropy);
bool setCompareMode(GLenum mode);
bool setCompareFunc(GLenum func);
bool setUsage(GLenum usage);
GLenum getMinFilter() const;
......
......@@ -143,6 +143,9 @@ struct SamplerState
GLenum wrapR;
float maxAnisotropy;
int lodOffset;
GLenum compareMode;
GLenum compareFunc;
};
struct ClearParameters
......
......@@ -7057,6 +7057,28 @@ void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
UNIMPLEMENTED();
break;
case GL_TEXTURE_COMPARE_MODE:
if (context->getClientVersion() < 3)
{
return gl::error(GL_INVALID_ENUM);
}
if (!texture->setCompareMode((GLenum)param))
{
return gl::error(GL_INVALID_ENUM);
}
break;
case GL_TEXTURE_COMPARE_FUNC:
if (context->getClientVersion() < 3)
{
return gl::error(GL_INVALID_ENUM);
}
if (!texture->setCompareFunc((GLenum)param))
{
return gl::error(GL_INVALID_ENUM);
}
break;
default:
return gl::error(GL_INVALID_ENUM);
}
......@@ -7166,13 +7188,33 @@ void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
case GL_TEXTURE_SWIZZLE_A:
case GL_TEXTURE_BASE_LEVEL:
case GL_TEXTURE_MAX_LEVEL:
if (context->getClientVersion() < 3)
{
return gl::error(GL_INVALID_ENUM);
}
UNIMPLEMENTED();
break;
case GL_TEXTURE_COMPARE_MODE:
if (context->getClientVersion() < 3)
{
return gl::error(GL_INVALID_ENUM);
}
if (!texture->setCompareMode((GLenum)param))
{
return gl::error(GL_INVALID_ENUM);
}
break;
case GL_TEXTURE_COMPARE_FUNC:
if (context->getClientVersion() < 3)
{
return gl::error(GL_INVALID_ENUM);
}
UNIMPLEMENTED();
if (!texture->setCompareFunc((GLenum)param))
{
return gl::error(GL_INVALID_ENUM);
}
break;
default:
......
......@@ -375,13 +375,14 @@ ID3D11SamplerState *RenderStateCache::getSamplerState(const gl::SamplerState &sa
}
D3D11_SAMPLER_DESC samplerDesc;
samplerDesc.Filter = gl_d3d11::ConvertFilter(samplerState.minFilter, samplerState.magFilter, samplerState.maxAnisotropy);
samplerDesc.Filter = gl_d3d11::ConvertFilter(samplerState.minFilter, samplerState.magFilter,
samplerState.maxAnisotropy, samplerState.compareMode);
samplerDesc.AddressU = gl_d3d11::ConvertTextureWrap(samplerState.wrapS);
samplerDesc.AddressV = gl_d3d11::ConvertTextureWrap(samplerState.wrapT);
samplerDesc.AddressW = gl_d3d11::ConvertTextureWrap(samplerState.wrapR);
samplerDesc.MipLODBias = static_cast<float>(samplerState.lodOffset);
samplerDesc.MaxAnisotropy = samplerState.maxAnisotropy;
samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
samplerDesc.ComparisonFunc = gl_d3d11::ConvertComparison(samplerState.compareFunc);
samplerDesc.BorderColor[0] = 0.0f;
samplerDesc.BorderColor[1] = 0.0f;
samplerDesc.BorderColor[2] = 0.0f;
......
......@@ -155,11 +155,13 @@ D3D11_STENCIL_OP ConvertStencilOp(GLenum stencilOp)
return d3dStencilOp;
}
D3D11_FILTER ConvertFilter(GLenum minFilter, GLenum magFilter, float maxAnisotropy)
D3D11_FILTER ConvertFilter(GLenum minFilter, GLenum magFilter, float maxAnisotropy, GLenum comparisonMode)
{
bool comparison = comparisonMode != GL_NONE;
if (maxAnisotropy > 1.0f)
{
return D3D11_ENCODE_ANISOTROPIC_FILTER(false);
return D3D11_ENCODE_ANISOTROPIC_FILTER(comparison);
}
else
{
......@@ -184,7 +186,7 @@ D3D11_FILTER ConvertFilter(GLenum minFilter, GLenum magFilter, float maxAnisotro
default: UNREACHABLE();
}
return D3D11_ENCODE_BASIC_FILTER(dxMin, dxMag, dxMip, false);
return D3D11_ENCODE_BASIC_FILTER(dxMin, dxMag, dxMip, comparison);
}
}
......
......@@ -29,7 +29,7 @@ D3D11_DEPTH_WRITE_MASK ConvertDepthMask(bool depthWriteEnabled);
UINT8 ConvertStencilMask(GLuint stencilmask);
D3D11_STENCIL_OP ConvertStencilOp(GLenum stencilOp);
D3D11_FILTER ConvertFilter(GLenum minFilter, GLenum magFilter, float maxAnisotropy);
D3D11_FILTER ConvertFilter(GLenum minFilter, GLenum magFilter, float maxAnisotropy, GLenum comparisonMode);
D3D11_TEXTURE_ADDRESS_MODE ConvertTextureWrap(GLenum wrap);
FLOAT ConvertMinLOD(GLenum minFilter, unsigned int lodOffset);
FLOAT ConvertMaxLOD(GLenum minFilter, unsigned int lodOffset);
......
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