Commit 0b886474 authored by Laszlo Agocs's avatar Laszlo Agocs

gl: Add tex.compare func support

parent bb04781d
......@@ -200,6 +200,18 @@ QT_BEGIN_NAMESPACE
#define GL_MAX_DRAW_BUFFERS 0x8824
#endif
#ifndef GL_TEXTURE_COMPARE_MODE
#define GL_TEXTURE_COMPARE_MODE 0x884C
#endif
#ifndef GL_COMPARE_REF_TO_TEXTURE
#define GL_COMPARE_REF_TO_TEXTURE 0x884E
#endif
#ifndef GL_TEXTURE_COMPARE_FUNC
#define GL_TEXTURE_COMPARE_FUNC 0x884D
#endif
static QSurfaceFormat qrhigles2_effectiveFormat()
{
QSurfaceFormat fmt = QSurfaceFormat::defaultFormat();
......@@ -1330,6 +1342,31 @@ static inline GLenum toGlWrapMode(QRhiSampler::AddressMode m)
}
}
static inline GLenum toGlTextureCompareFunc(QRhiSampler::CompareOp op)
{
switch (op) {
case QRhiSampler::Never:
return GL_NEVER;
case QRhiSampler::Less:
return GL_LESS;
case QRhiSampler::Equal:
return GL_EQUAL;
case QRhiSampler::LessOrEqual:
return GL_LEQUAL;
case QRhiSampler::Greater:
return GL_GREATER;
case QRhiSampler::NotEqual:
return GL_NOTEQUAL;
case QRhiSampler::GreaterOrEqual:
return GL_GEQUAL;
case QRhiSampler::Always:
return GL_ALWAYS;
default:
Q_UNREACHABLE();
return GL_NEVER;
}
}
void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
{
QGles2CommandBuffer *cbD = QRHI_RES(QGles2CommandBuffer, cb);
......@@ -1762,6 +1799,12 @@ void QRhiGles2::setChangedUniforms(QRhiGraphicsPipeline *ps, QRhiShaderResourceB
f->glTexParameteri(texD->target, GL_TEXTURE_WRAP_S, samplerD->glwraps);
f->glTexParameteri(texD->target, GL_TEXTURE_WRAP_T, samplerD->glwrapt);
f->glTexParameteri(texD->target, GL_TEXTURE_WRAP_R, samplerD->glwrapr);
if (samplerD->gltexcomparefunc != GL_NEVER) {
f->glTexParameteri(texD->target, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
f->glTexParameteri(texD->target, GL_TEXTURE_COMPARE_FUNC, samplerD->gltexcomparefunc);
} else {
f->glTexParameteri(texD->target, GL_TEXTURE_COMPARE_MODE, GL_NONE);
}
}
f->glUniform1i(sampler.glslLocation, texUnit);
......@@ -2242,6 +2285,7 @@ bool QGles2Sampler::build()
glwraps = toGlWrapMode(m_addressU);
glwrapt = toGlWrapMode(m_addressV);
glwrapr = toGlWrapMode(m_addressW);
gltexcomparefunc = toGlTextureCompareFunc(m_compareOp);
generation += 1;
return true;
......
......@@ -113,6 +113,7 @@ struct QGles2Sampler : public QRhiSampler
GLenum glwraps;
GLenum glwrapt;
GLenum glwrapr;
GLenum gltexcomparefunc;
uint generation = 0;
friend class QRhiGles2;
......
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