Add Depth compare / shadow sampler support. Officially this is only supported in glsl3 shaders.

- Add Texture:setDepthSampleMode(comparemode). Only works on textures with depth pixel formats. A texture with the depth sample mode set will only work with a depth sampler.
- Add DepthImage, DepthArrayImage, and DepthCubeImage sampler keywords to glsl3.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2017-04-12 20:26:06 -03:00
parent 0001b4695e
commit a0ef2ac28b
25 changed files with 444 additions and 151 deletions
+41
View File
@@ -277,6 +277,7 @@ bool Canvas::loadVolatile()
setFilter(filter);
setWrap(wrap);
setDepthSampleMode(depthCompareMode);
while (glGetError() != GL_NO_ERROR)
/* Clear the error buffer. */;
@@ -358,6 +359,8 @@ void Canvas::setFilter(const Texture::Filter &f)
if (!validateFilter(f, false))
throw love::Exception("Invalid texture filter.");
Graphics::flushStreamDrawsGlobal();
filter = f;
gl.bindTextureToUnit(this, 0, false);
gl.setTextureFilter(texType, filter);
@@ -365,6 +368,8 @@ void Canvas::setFilter(const Texture::Filter &f)
bool Canvas::setWrap(const Texture::Wrap &w)
{
Graphics::flushStreamDrawsGlobal();
bool success = true;
bool forceclamp = texType == TEXTURE_CUBE;
wrap = w;
@@ -402,6 +407,42 @@ bool Canvas::setMipmapSharpness(float /*sharpness*/)
return false;
}
void Canvas::setDepthSampleMode(Optional<CompareMode> mode)
{
Texture::setDepthSampleMode(mode);
bool supported = gl.isDepthCompareSampleSupported();
if (mode.hasValue && !supported)
throw love::Exception("Depth comparison sampling in shaders is not supported on this system.");
if (mode.hasValue)
{
Graphics::flushStreamDrawsGlobal();
gl.bindTextureToUnit(texType, texture, 0, false);
GLenum gltextype = OpenGL::getGLTextureType(texType);
// See the comment in depthstencil.h
GLenum glmode = OpenGL::getGLCompareMode(getReversedCompareMode(mode.value));
glTexParameteri(gltextype, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
glTexParameteri(gltextype, GL_TEXTURE_COMPARE_FUNC, glmode);
}
else if (isPixelFormatDepth(format) && supported)
{
Graphics::flushStreamDrawsGlobal();
gl.bindTextureToUnit(texType, texture, 0, false);
GLenum gltextype = OpenGL::getGLTextureType(texType);
glTexParameteri(gltextype, GL_TEXTURE_COMPARE_MODE, GL_NONE);
}
depthCompareMode = mode;
}
ptrdiff_t Canvas::getHandle() const
{
return texture;