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) ...@@ -36,8 +36,10 @@ Texture::Texture(rx::Renderer *renderer, GLuint id) : RefCountObject(id)
mSamplerState.wrapR = GL_REPEAT; mSamplerState.wrapR = GL_REPEAT;
mSamplerState.maxAnisotropy = 1.0f; mSamplerState.maxAnisotropy = 1.0f;
mSamplerState.lodOffset = 0; mSamplerState.lodOffset = 0;
mSamplerState.compareMode = GL_NONE;
mSamplerState.compareFunc = GL_LEQUAL;
mUsage = GL_NONE; mUsage = GL_NONE;
mDirtyImages = true; mDirtyImages = true;
mImmutable = false; mImmutable = false;
...@@ -138,6 +140,40 @@ bool Texture::setMaxAnisotropy(float textureMaxAnisotropy, float contextMaxAniso ...@@ -138,6 +140,40 @@ bool Texture::setMaxAnisotropy(float textureMaxAnisotropy, float contextMaxAniso
return true; 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) // Returns true on successful usage state update (valid enum parameter)
bool Texture::setUsage(GLenum usage) bool Texture::setUsage(GLenum usage)
{ {
...@@ -672,6 +708,23 @@ bool Texture2D::isSamplerComplete() const ...@@ -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; return true;
} }
......
...@@ -74,6 +74,8 @@ class Texture : public RefCountObject ...@@ -74,6 +74,8 @@ class Texture : public RefCountObject
bool setWrapT(GLenum wrap); bool setWrapT(GLenum wrap);
bool setWrapR(GLenum wrap); bool setWrapR(GLenum wrap);
bool setMaxAnisotropy(float textureMaxAnisotropy, float contextMaxAnisotropy); bool setMaxAnisotropy(float textureMaxAnisotropy, float contextMaxAnisotropy);
bool setCompareMode(GLenum mode);
bool setCompareFunc(GLenum func);
bool setUsage(GLenum usage); bool setUsage(GLenum usage);
GLenum getMinFilter() const; GLenum getMinFilter() const;
......
...@@ -143,6 +143,9 @@ struct SamplerState ...@@ -143,6 +143,9 @@ struct SamplerState
GLenum wrapR; GLenum wrapR;
float maxAnisotropy; float maxAnisotropy;
int lodOffset; int lodOffset;
GLenum compareMode;
GLenum compareFunc;
}; };
struct ClearParameters struct ClearParameters
......
...@@ -7057,6 +7057,28 @@ void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param) ...@@ -7057,6 +7057,28 @@ void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
UNIMPLEMENTED(); UNIMPLEMENTED();
break; 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: default:
return gl::error(GL_INVALID_ENUM); return gl::error(GL_INVALID_ENUM);
} }
...@@ -7166,13 +7188,33 @@ void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param) ...@@ -7166,13 +7188,33 @@ void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
case GL_TEXTURE_SWIZZLE_A: case GL_TEXTURE_SWIZZLE_A:
case GL_TEXTURE_BASE_LEVEL: case GL_TEXTURE_BASE_LEVEL:
case GL_TEXTURE_MAX_LEVEL: case GL_TEXTURE_MAX_LEVEL:
if (context->getClientVersion() < 3)
{
return gl::error(GL_INVALID_ENUM);
}
UNIMPLEMENTED();
break;
case GL_TEXTURE_COMPARE_MODE: 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: case GL_TEXTURE_COMPARE_FUNC:
if (context->getClientVersion() < 3) if (context->getClientVersion() < 3)
{ {
return gl::error(GL_INVALID_ENUM); return gl::error(GL_INVALID_ENUM);
} }
UNIMPLEMENTED(); if (!texture->setCompareFunc((GLenum)param))
{
return gl::error(GL_INVALID_ENUM);
}
break; break;
default: default:
......
...@@ -375,13 +375,14 @@ ID3D11SamplerState *RenderStateCache::getSamplerState(const gl::SamplerState &sa ...@@ -375,13 +375,14 @@ ID3D11SamplerState *RenderStateCache::getSamplerState(const gl::SamplerState &sa
} }
D3D11_SAMPLER_DESC samplerDesc; 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.AddressU = gl_d3d11::ConvertTextureWrap(samplerState.wrapS);
samplerDesc.AddressV = gl_d3d11::ConvertTextureWrap(samplerState.wrapT); samplerDesc.AddressV = gl_d3d11::ConvertTextureWrap(samplerState.wrapT);
samplerDesc.AddressW = gl_d3d11::ConvertTextureWrap(samplerState.wrapR); samplerDesc.AddressW = gl_d3d11::ConvertTextureWrap(samplerState.wrapR);
samplerDesc.MipLODBias = static_cast<float>(samplerState.lodOffset); samplerDesc.MipLODBias = static_cast<float>(samplerState.lodOffset);
samplerDesc.MaxAnisotropy = samplerState.maxAnisotropy; samplerDesc.MaxAnisotropy = samplerState.maxAnisotropy;
samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER; samplerDesc.ComparisonFunc = gl_d3d11::ConvertComparison(samplerState.compareFunc);
samplerDesc.BorderColor[0] = 0.0f; samplerDesc.BorderColor[0] = 0.0f;
samplerDesc.BorderColor[1] = 0.0f; samplerDesc.BorderColor[1] = 0.0f;
samplerDesc.BorderColor[2] = 0.0f; samplerDesc.BorderColor[2] = 0.0f;
......
...@@ -155,11 +155,13 @@ D3D11_STENCIL_OP ConvertStencilOp(GLenum stencilOp) ...@@ -155,11 +155,13 @@ D3D11_STENCIL_OP ConvertStencilOp(GLenum stencilOp)
return d3dStencilOp; 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) if (maxAnisotropy > 1.0f)
{ {
return D3D11_ENCODE_ANISOTROPIC_FILTER(false); return D3D11_ENCODE_ANISOTROPIC_FILTER(comparison);
} }
else else
{ {
...@@ -184,7 +186,7 @@ D3D11_FILTER ConvertFilter(GLenum minFilter, GLenum magFilter, float maxAnisotro ...@@ -184,7 +186,7 @@ D3D11_FILTER ConvertFilter(GLenum minFilter, GLenum magFilter, float maxAnisotro
default: UNREACHABLE(); 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); ...@@ -29,7 +29,7 @@ D3D11_DEPTH_WRITE_MASK ConvertDepthMask(bool depthWriteEnabled);
UINT8 ConvertStencilMask(GLuint stencilmask); UINT8 ConvertStencilMask(GLuint stencilmask);
D3D11_STENCIL_OP ConvertStencilOp(GLenum stencilOp); 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); D3D11_TEXTURE_ADDRESS_MODE ConvertTextureWrap(GLenum wrap);
FLOAT ConvertMinLOD(GLenum minFilter, unsigned int lodOffset); FLOAT ConvertMinLOD(GLenum minFilter, unsigned int lodOffset);
FLOAT ConvertMaxLOD(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