mirror of
https://github.com/love2d/love.git
synced 2026-08-17 11:00:31 +02:00
Add new wrap mode "clampone". Pixels sampled outside of [0, 1] are white (1, 1, 1, 1).
--HG-- branch : minor
This commit is contained in:
@@ -357,11 +357,11 @@ bool Canvas::setWrap(const Texture::Wrap &w)
|
||||
wrap.s = wrap.t = wrap.r = WRAP_CLAMP;
|
||||
}
|
||||
|
||||
if (!gl.isClampZeroTextureWrapSupported())
|
||||
if (!gl.isClampZeroOneTextureWrapSupported())
|
||||
{
|
||||
if (wrap.s == WRAP_CLAMP_ZERO) wrap.s = WRAP_CLAMP;
|
||||
if (wrap.t == WRAP_CLAMP_ZERO) wrap.t = WRAP_CLAMP;
|
||||
if (wrap.r == WRAP_CLAMP_ZERO) wrap.r = WRAP_CLAMP;
|
||||
if (isClampZeroOrOne(wrap.s)) wrap.s = WRAP_CLAMP;
|
||||
if (isClampZeroOrOne(wrap.t)) wrap.t = WRAP_CLAMP;
|
||||
if (isClampZeroOrOne(wrap.r)) wrap.r = WRAP_CLAMP;
|
||||
}
|
||||
|
||||
gl.bindTextureToUnit(this, 0, false);
|
||||
|
||||
@@ -1363,7 +1363,7 @@ void Graphics::getAPIStats(int &shaderswitches) const
|
||||
void Graphics::initCapabilities()
|
||||
{
|
||||
capabilities.features[FEATURE_MULTI_CANVAS_FORMATS] = Canvas::isMultiFormatMultiCanvasSupported();
|
||||
capabilities.features[FEATURE_CLAMP_ZERO] = gl.isClampZeroTextureWrapSupported();
|
||||
capabilities.features[FEATURE_CLAMP_ZERO] = gl.isClampZeroOneTextureWrapSupported();
|
||||
capabilities.features[FEATURE_BLENDMINMAX] = GLAD_VERSION_1_4 || GLAD_ES_VERSION_3_0 || GLAD_EXT_blend_minmax;
|
||||
capabilities.features[FEATURE_LIGHTEN] = capabilities.features[FEATURE_BLENDMINMAX];
|
||||
capabilities.features[FEATURE_FULL_NPOT] = GLAD_VERSION_2_0 || GLAD_ES_VERSION_3_0 || GLAD_OES_texture_npot;
|
||||
|
||||
@@ -316,11 +316,11 @@ bool Image::setWrap(const Texture::Wrap &w)
|
||||
wrap.s = wrap.t = wrap.r = WRAP_CLAMP;
|
||||
}
|
||||
|
||||
if (!gl.isClampZeroTextureWrapSupported())
|
||||
if (!gl.isClampZeroOneTextureWrapSupported())
|
||||
{
|
||||
if (wrap.s == WRAP_CLAMP_ZERO) wrap.s = WRAP_CLAMP;
|
||||
if (wrap.t == WRAP_CLAMP_ZERO) wrap.t = WRAP_CLAMP;
|
||||
if (wrap.r == WRAP_CLAMP_ZERO) wrap.r = WRAP_CLAMP;
|
||||
if (isClampZeroOrOne(wrap.s)) wrap.s = WRAP_CLAMP;
|
||||
if (isClampZeroOrOne(wrap.t)) wrap.t = WRAP_CLAMP;
|
||||
if (isClampZeroOrOne(wrap.r)) wrap.r = WRAP_CLAMP;
|
||||
}
|
||||
|
||||
gl.bindTextureToUnit(this, 0, false);
|
||||
|
||||
@@ -1061,6 +1061,7 @@ GLint OpenGL::getGLWrapMode(Texture::WrapMode wmode)
|
||||
default:
|
||||
return GL_CLAMP_TO_EDGE;
|
||||
case Texture::WRAP_CLAMP_ZERO:
|
||||
case Texture::WRAP_CLAMP_ONE:
|
||||
return GL_CLAMP_TO_BORDER;
|
||||
case Texture::WRAP_REPEAT:
|
||||
return GL_REPEAT;
|
||||
@@ -1094,13 +1095,29 @@ GLint OpenGL::getGLCompareMode(CompareMode mode)
|
||||
}
|
||||
}
|
||||
|
||||
static bool isClampOne(Texture::WrapMode mode)
|
||||
{
|
||||
return mode == Texture::WRAP_CLAMP_ONE;
|
||||
}
|
||||
|
||||
void OpenGL::setTextureWrap(TextureType target, const graphics::Texture::Wrap &w)
|
||||
{
|
||||
glTexParameteri(getGLTextureType(target), GL_TEXTURE_WRAP_S, getGLWrapMode(w.s));
|
||||
glTexParameteri(getGLTextureType(target), GL_TEXTURE_WRAP_T, getGLWrapMode(w.t));
|
||||
GLenum textype = getGLTextureType(target);
|
||||
|
||||
if (Texture::isClampZeroOrOne(w.s) || Texture::isClampZeroOrOne(w.t) || Texture::isClampZeroOrOne(w.r))
|
||||
{
|
||||
GLfloat c[] = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
if (isClampOne(w.s) || isClampOne(w.t) || isClampOne(w.r))
|
||||
c[0] = c[1] = c[2] = c[3] = 1.0f;
|
||||
|
||||
glTexParameterfv(textype, GL_TEXTURE_BORDER_COLOR, c);
|
||||
}
|
||||
|
||||
glTexParameteri(textype, GL_TEXTURE_WRAP_S, getGLWrapMode(w.s));
|
||||
glTexParameteri(textype, GL_TEXTURE_WRAP_T, getGLWrapMode(w.t));
|
||||
|
||||
if (target == TEXTURE_VOLUME)
|
||||
glTexParameteri(getGLTextureType(target), GL_TEXTURE_WRAP_R, getGLWrapMode(w.r));
|
||||
glTexParameteri(textype, GL_TEXTURE_WRAP_R, getGLWrapMode(w.r));
|
||||
}
|
||||
|
||||
bool OpenGL::rawTexStorage(TextureType target, int levels, PixelFormat pixelformat, bool &isSRGB, int width, int height, int depth)
|
||||
@@ -1202,7 +1219,7 @@ bool OpenGL::isTextureTypeSupported(TextureType type) const
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenGL::isClampZeroTextureWrapSupported() const
|
||||
bool OpenGL::isClampZeroOneTextureWrapSupported() const
|
||||
{
|
||||
return GLAD_VERSION_1_3 || GLAD_EXT_texture_border_clamp || GLAD_NV_texture_border_clamp;
|
||||
}
|
||||
|
||||
@@ -348,7 +348,7 @@ public:
|
||||
bool rawTexStorage(TextureType target, int levels, PixelFormat pixelformat, bool &isSRGB, int width, int height, int depth = 1);
|
||||
|
||||
bool isTextureTypeSupported(TextureType type) const;
|
||||
bool isClampZeroTextureWrapSupported() const;
|
||||
bool isClampZeroOneTextureWrapSupported() const;
|
||||
bool isPixelShaderHighpSupported() const;
|
||||
bool isInstancingSupported() const;
|
||||
bool isDepthCompareSampleSupported() const;
|
||||
|
||||
Reference in New Issue
Block a user