mirror of
https://github.com/love2d/love.git
synced 2026-08-14 01:20:56 +02:00
Applied patch from issue #542 (texture filtering inconsistencies) in main LÖVE repository
This commit is contained in:
@@ -25,6 +25,8 @@ namespace love
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
Image::Filter Image::defaultFilter;
|
||||
|
||||
Image::Filter::Filter()
|
||||
: min(FILTER_LINEAR)
|
||||
, mag(FILTER_LINEAR)
|
||||
@@ -41,6 +43,16 @@ Image::~Image()
|
||||
{
|
||||
}
|
||||
|
||||
void Image::setDefaultFilter(const Filter &f)
|
||||
{
|
||||
defaultFilter = f;
|
||||
}
|
||||
|
||||
const Image::Filter &Image::getDefaultFilter()
|
||||
{
|
||||
return defaultFilter;
|
||||
}
|
||||
|
||||
bool Image::getConstant(const char *in, FilterMode &out)
|
||||
{
|
||||
return filterModes.find(in, out);
|
||||
|
||||
@@ -64,6 +64,10 @@ public:
|
||||
};
|
||||
|
||||
virtual ~Image();
|
||||
|
||||
// The default filter.
|
||||
static void setDefaultFilter(const Filter &f);
|
||||
static const Filter &getDefaultFilter();
|
||||
|
||||
static bool getConstant(const char *in, FilterMode &out);
|
||||
static bool getConstant(FilterMode in, const char *&out);
|
||||
@@ -71,6 +75,9 @@ public:
|
||||
static bool getConstant(WrapMode in, const char *&out);
|
||||
|
||||
private:
|
||||
|
||||
// The default image filter
|
||||
static Filter defaultFilter;
|
||||
|
||||
static StringMap<FilterMode, FILTER_MAX_ENUM>::Entry filterModeEntries[];
|
||||
static StringMap<FilterMode, FILTER_MAX_ENUM> filterModes;
|
||||
|
||||
@@ -97,8 +97,9 @@ struct FramebufferStrategyGL3 : public FramebufferStrategy
|
||||
|
||||
glGenTextures(1, &img);
|
||||
bindTexture(img);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
||||
setTextureFilter(Image::getDefaultFilter());
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height,
|
||||
0, GL_RGBA, format, NULL);
|
||||
bindTexture(0);
|
||||
@@ -164,8 +165,8 @@ struct FramebufferStrategyPackedEXT : public FramebufferStrategy
|
||||
|
||||
glGenTextures(1, &img);
|
||||
bindTexture(img);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
||||
setTextureFilter(Image::getDefaultFilter());
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height,
|
||||
0, GL_RGBA, format, NULL);
|
||||
@@ -231,8 +232,9 @@ struct FramebufferStrategyEXT : public FramebufferStrategyPackedEXT
|
||||
|
||||
glGenTextures(1, &img);
|
||||
bindTexture(img);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
||||
setTextureFilter(Image::getDefaultFilter());
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height,
|
||||
0, GL_RGBA, format, NULL);
|
||||
bindTexture(0);
|
||||
@@ -311,6 +313,8 @@ Canvas::Canvas(int width, int height, TextureType texture_type)
|
||||
vertices[2].t = 1;
|
||||
vertices[3].s = 1;
|
||||
vertices[3].t = 0;
|
||||
|
||||
settings.filter = Image::getDefaultFilter();
|
||||
|
||||
getStrategy();
|
||||
|
||||
@@ -456,51 +460,26 @@ love::image::ImageData *Canvas::getImageData(love::image::Image *image)
|
||||
|
||||
void Canvas::setFilter(const Image::Filter &f)
|
||||
{
|
||||
GLint gmin = (f.min == Image::FILTER_NEAREST) ? GL_NEAREST : GL_LINEAR;
|
||||
GLint gmag = (f.mag == Image::FILTER_NEAREST) ? GL_NEAREST : GL_LINEAR;
|
||||
|
||||
bindTexture(img);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gmin);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gmag);
|
||||
setTextureFilter(f);
|
||||
}
|
||||
|
||||
Image::Filter Canvas::getFilter() const
|
||||
{
|
||||
GLint gmin, gmag;
|
||||
|
||||
bindTexture(img);
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, &gmin);
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, &gmag);
|
||||
|
||||
Image::Filter f;
|
||||
f.min = (gmin == GL_NEAREST) ? Image::FILTER_NEAREST : Image::FILTER_LINEAR;
|
||||
f.mag = (gmag == GL_NEAREST) ? Image::FILTER_NEAREST : Image::FILTER_LINEAR;
|
||||
return f;
|
||||
return getTextureFilter();
|
||||
}
|
||||
|
||||
void Canvas::setWrap(const Image::Wrap &w)
|
||||
{
|
||||
GLint wrap_s = (w.s == Image::WRAP_CLAMP) ? GL_CLAMP_TO_EDGE : GL_REPEAT;
|
||||
GLint wrap_t = (w.t == Image::WRAP_CLAMP) ? GL_CLAMP_TO_EDGE : GL_REPEAT;
|
||||
|
||||
bindTexture(img);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t);
|
||||
setTextureWrap(w);
|
||||
}
|
||||
|
||||
Image::Wrap Canvas::getWrap() const
|
||||
{
|
||||
GLint wrap_s, wrap_t;
|
||||
bindTexture(img);
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, &wrap_s);
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, &wrap_t);
|
||||
|
||||
Image::Wrap w;
|
||||
w.s = (wrap_s == GL_CLAMP_TO_EDGE) ? Image::WRAP_CLAMP : Image::WRAP_REPEAT;
|
||||
w.t = (wrap_t == GL_CLAMP_TO_EDGE) ? Image::WRAP_CLAMP : Image::WRAP_REPEAT;
|
||||
|
||||
return w;
|
||||
return getTextureWrap();
|
||||
}
|
||||
|
||||
bool Canvas::loadVolatile()
|
||||
|
||||
@@ -116,16 +116,15 @@ void Font::createTexture()
|
||||
GLuint t;
|
||||
glGenTextures(1, &t);
|
||||
textures.push_back(t);
|
||||
|
||||
bindTexture(t);
|
||||
|
||||
setTextureFilter(filter);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
|
||||
(filter.mag == Image::FILTER_LINEAR) ? GL_LINEAR : GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
||||
(filter.min == Image::FILTER_LINEAR) ? GL_LINEAR : GL_NEAREST);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
GLint format = (type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA);
|
||||
|
||||
GLint format = (type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA);
|
||||
|
||||
// try to initialize the texture, attempting smaller sizes if initialization fails
|
||||
bool initialized = false;
|
||||
@@ -493,6 +492,28 @@ float Font::getSpacing() const
|
||||
return mSpacing;
|
||||
}
|
||||
|
||||
void Font::setFilter(const Image::Filter &f)
|
||||
{
|
||||
std::vector<GLuint>::const_iterator it;
|
||||
for (it = textures.begin(); it != textures.end(); ++it)
|
||||
{
|
||||
bindTexture(*it);
|
||||
setTextureFilter(f);
|
||||
}
|
||||
}
|
||||
|
||||
Image::Filter Font::getFilter()
|
||||
{
|
||||
std::vector<GLuint>::const_iterator it;
|
||||
for (it = textures.begin(); it != textures.end(); ++it)
|
||||
{
|
||||
bindTexture(*it);
|
||||
return getTextureFilter();
|
||||
}
|
||||
|
||||
return Image::getDefaultFilter();
|
||||
}
|
||||
|
||||
bool Font::loadVolatile()
|
||||
{
|
||||
createTexture();
|
||||
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
*
|
||||
* @param data The font data to construct from.
|
||||
**/
|
||||
Font(love::font::Rasterizer *r, const Image::Filter &filter = Image::Filter());
|
||||
Font(love::font::Rasterizer *r, const Image::Filter &filter = Image::getDefaultFilter());
|
||||
|
||||
virtual ~Font();
|
||||
|
||||
@@ -125,6 +125,9 @@ public:
|
||||
* Returns the spacing modifier.
|
||||
**/
|
||||
float getSpacing() const;
|
||||
|
||||
void setFilter(const Image::Filter &f);
|
||||
Image::Filter getFilter();
|
||||
|
||||
// Implements Volatile.
|
||||
bool loadVolatile();
|
||||
|
||||
@@ -567,11 +567,6 @@ void Graphics::setColorMode(Graphics::ColorMode mode)
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
}
|
||||
|
||||
void Graphics::setDefaultImageFilter(const Image::Filter &f)
|
||||
{
|
||||
Image::setDefaultFilter(f);
|
||||
}
|
||||
|
||||
Graphics::BlendMode Graphics::getBlendMode()
|
||||
{
|
||||
GLint dst, src, equation;
|
||||
@@ -606,6 +601,11 @@ Graphics::ColorMode Graphics::getColorMode()
|
||||
return COLOR_REPLACE;
|
||||
}
|
||||
|
||||
void Graphics::setDefaultImageFilter(const Image::Filter &f)
|
||||
{
|
||||
Image::setDefaultFilter(f);
|
||||
}
|
||||
|
||||
const Image::Filter &Graphics::getDefaultImageFilter() const
|
||||
{
|
||||
return Image::getDefaultFilter();
|
||||
|
||||
@@ -33,8 +33,6 @@ namespace graphics
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Image::Filter Image::defaultFilter;
|
||||
|
||||
Image::Image(love::image::ImageData *data)
|
||||
: width((float)(data->getWidth()))
|
||||
, height((float)(data->getHeight()))
|
||||
@@ -63,7 +61,7 @@ Image::Image(love::image::ImageData *data)
|
||||
vertices[3].s = 1;
|
||||
vertices[3].t = 0;
|
||||
|
||||
settings.filter = defaultFilter;
|
||||
settings.filter = getDefaultFilter();
|
||||
}
|
||||
|
||||
Image::~Image()
|
||||
@@ -146,141 +144,26 @@ void Image::drawq(love::graphics::Quad *quad, float x, float y, float angle, flo
|
||||
|
||||
void Image::setFilter(const Image::Filter &f)
|
||||
{
|
||||
GLint gmin, gmag;
|
||||
gmin = gmag = 0; // so that they're not used uninitialized
|
||||
|
||||
switch (f.min)
|
||||
{
|
||||
case FILTER_LINEAR:
|
||||
gmin = GL_LINEAR;
|
||||
break;
|
||||
case FILTER_NEAREST:
|
||||
gmin = GL_NEAREST;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (f.mag)
|
||||
{
|
||||
case FILTER_LINEAR:
|
||||
gmag = GL_LINEAR;
|
||||
break;
|
||||
case FILTER_NEAREST:
|
||||
gmag = GL_NEAREST;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
bind();
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gmin);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gmag);
|
||||
setTextureFilter(f);
|
||||
}
|
||||
|
||||
Image::Filter Image::getFilter() const
|
||||
{
|
||||
bind();
|
||||
|
||||
GLint gmin, gmag;
|
||||
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, &gmin);
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, &gmag);
|
||||
|
||||
Image::Filter f;
|
||||
|
||||
switch (gmin)
|
||||
{
|
||||
case GL_NEAREST:
|
||||
f.min = FILTER_NEAREST;
|
||||
break;
|
||||
case GL_LINEAR:
|
||||
default:
|
||||
f.min = FILTER_LINEAR;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (gmin)
|
||||
{
|
||||
case GL_NEAREST:
|
||||
f.mag = FILTER_NEAREST;
|
||||
break;
|
||||
case GL_LINEAR:
|
||||
default:
|
||||
f.mag = FILTER_LINEAR;
|
||||
break;
|
||||
}
|
||||
|
||||
return f;
|
||||
return getTextureFilter();
|
||||
}
|
||||
|
||||
void Image::setWrap(Image::Wrap w)
|
||||
void Image::setWrap(Image::Wrap &w)
|
||||
{
|
||||
GLint gs, gt;
|
||||
|
||||
switch (w.s)
|
||||
{
|
||||
case WRAP_CLAMP:
|
||||
gs = GL_CLAMP_TO_EDGE;
|
||||
break;
|
||||
case WRAP_REPEAT:
|
||||
default:
|
||||
gs = GL_REPEAT;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (w.t)
|
||||
{
|
||||
case WRAP_CLAMP:
|
||||
gt = GL_CLAMP_TO_EDGE;
|
||||
break;
|
||||
case WRAP_REPEAT:
|
||||
default:
|
||||
gt = GL_REPEAT;
|
||||
break;
|
||||
}
|
||||
|
||||
bind();
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, gs);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, gt);
|
||||
setTextureWrap(w);
|
||||
}
|
||||
|
||||
Image::Wrap Image::getWrap() const
|
||||
{
|
||||
bind();
|
||||
|
||||
GLint gs, gt;
|
||||
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, &gs);
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, >);
|
||||
|
||||
Wrap w;
|
||||
|
||||
switch (gs)
|
||||
{
|
||||
case GL_CLAMP_TO_EDGE:
|
||||
w.s = WRAP_CLAMP;
|
||||
break;
|
||||
case GL_REPEAT:
|
||||
default:
|
||||
w.s = WRAP_REPEAT;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (gt)
|
||||
{
|
||||
case GL_CLAMP_TO_EDGE:
|
||||
w.t = WRAP_CLAMP;
|
||||
break;
|
||||
case GL_REPEAT:
|
||||
default:
|
||||
w.t = WRAP_REPEAT;
|
||||
break;
|
||||
}
|
||||
|
||||
return w;
|
||||
return getTextureWrap();
|
||||
}
|
||||
|
||||
void Image::bind() const
|
||||
@@ -417,16 +300,6 @@ bool Image::hasNpot()
|
||||
return GLEE_ARB_texture_non_power_of_two != 0;
|
||||
}
|
||||
|
||||
void Image::setDefaultFilter(const Image::Filter &f)
|
||||
{
|
||||
defaultFilter = f;
|
||||
}
|
||||
|
||||
const Image::Filter &Image::getDefaultFilter()
|
||||
{
|
||||
return defaultFilter;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -103,7 +103,7 @@ public:
|
||||
|
||||
Image::Filter getFilter() const;
|
||||
|
||||
void setWrap(Image::Wrap r);
|
||||
void setWrap(Image::Wrap &w);
|
||||
|
||||
Image::Wrap getWrap() const;
|
||||
|
||||
@@ -118,10 +118,6 @@ public:
|
||||
|
||||
static bool hasNpot();
|
||||
|
||||
// The default filter.
|
||||
static void setDefaultFilter(const Image::Filter &f);
|
||||
static const Image::Filter &getDefaultFilter();
|
||||
|
||||
private:
|
||||
|
||||
void drawv(const Matrix &t, const vertex *v) const;
|
||||
@@ -153,9 +149,6 @@ private:
|
||||
bool loadVolatilePOT();
|
||||
bool loadVolatileNPOT();
|
||||
|
||||
// The default image filter
|
||||
static Image::Filter defaultFilter;
|
||||
|
||||
}; // Image
|
||||
|
||||
} // opengl
|
||||
|
||||
@@ -52,6 +52,133 @@ void deleteTexture(GLuint texture)
|
||||
glDeleteTextures(1, &texture);
|
||||
}
|
||||
|
||||
void setTextureFilter(const graphics::Image::Filter &f)
|
||||
{
|
||||
GLint gmin, gmag;
|
||||
|
||||
switch (f.min)
|
||||
{
|
||||
case Image::FILTER_NEAREST:
|
||||
gmin = GL_NEAREST;
|
||||
break;
|
||||
case Image::FILTER_LINEAR:
|
||||
default:
|
||||
gmin = GL_LINEAR;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (f.mag)
|
||||
{
|
||||
case Image::FILTER_NEAREST:
|
||||
gmag = GL_NEAREST;
|
||||
break;
|
||||
case Image::FILTER_LINEAR:
|
||||
default:
|
||||
gmag = GL_LINEAR;
|
||||
break;
|
||||
}
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gmin);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gmag);
|
||||
}
|
||||
|
||||
graphics::Image::Filter getTextureFilter()
|
||||
{
|
||||
GLint gmin, gmag;
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, &gmin);
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, &gmag);
|
||||
|
||||
Image::Filter f;
|
||||
|
||||
switch (gmin)
|
||||
{
|
||||
case GL_NEAREST:
|
||||
f.min = Image::FILTER_NEAREST;
|
||||
break;
|
||||
case GL_LINEAR:
|
||||
default:
|
||||
f.min = Image::FILTER_LINEAR;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (gmag)
|
||||
{
|
||||
case GL_NEAREST:
|
||||
f.mag = Image::FILTER_NEAREST;
|
||||
break;
|
||||
case GL_LINEAR:
|
||||
default:
|
||||
f.mag = Image::FILTER_LINEAR;
|
||||
break;
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
void setTextureWrap(const graphics::Image::Wrap &w)
|
||||
{
|
||||
GLint gs, gt;
|
||||
|
||||
switch (w.s)
|
||||
{
|
||||
case Image::WRAP_CLAMP:
|
||||
gs = GL_CLAMP_TO_EDGE;
|
||||
break;
|
||||
case Image::WRAP_REPEAT:
|
||||
default:
|
||||
gs = GL_REPEAT;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (w.t)
|
||||
{
|
||||
case Image::WRAP_CLAMP:
|
||||
gt = GL_CLAMP_TO_EDGE;
|
||||
break;
|
||||
case Image::WRAP_REPEAT:
|
||||
default:
|
||||
gt = GL_REPEAT;
|
||||
break;
|
||||
}
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, gs);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, gt);
|
||||
}
|
||||
|
||||
graphics::Image::Wrap getTextureWrap()
|
||||
{
|
||||
GLint gs, gt;
|
||||
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, &gs);
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, >);
|
||||
|
||||
Image::Wrap w;
|
||||
|
||||
switch (gs)
|
||||
{
|
||||
case GL_CLAMP_TO_EDGE:
|
||||
w.s = Image::WRAP_CLAMP;
|
||||
break;
|
||||
case GL_REPEAT:
|
||||
default:
|
||||
w.s = Image::WRAP_REPEAT;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (gt)
|
||||
{
|
||||
case GL_CLAMP_TO_EDGE:
|
||||
w.t = Image::WRAP_CLAMP;
|
||||
break;
|
||||
case GL_REPEAT:
|
||||
default:
|
||||
w.t = Image::WRAP_REPEAT;
|
||||
break;
|
||||
}
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#define LOVE_COMMON_OPENGL_H
|
||||
|
||||
#include "GLee.h"
|
||||
#include "graphics/Image.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -48,6 +49,28 @@ void bindTexture(GLuint texture, bool override = false);
|
||||
**/
|
||||
void deleteTexture(GLuint texture);
|
||||
|
||||
/**
|
||||
* Sets the image filter mode for the currently bound texture
|
||||
* @param f The image filter to set
|
||||
*/
|
||||
void setTextureFilter(const graphics::Image::Filter &f);
|
||||
|
||||
/**
|
||||
* Returns the image filter mode for the currently bound texture
|
||||
*/
|
||||
graphics::Image::Filter getTextureFilter();
|
||||
|
||||
/**
|
||||
* Sets the image wrap mode for the currently bound texture
|
||||
* @param w The wrap mode to set
|
||||
*/
|
||||
void setTextureWrap(const graphics::Image::Wrap &w);
|
||||
|
||||
/**
|
||||
* Returns the image wrap mode for the currently bound texture
|
||||
*/
|
||||
graphics::Image::Wrap getTextureWrap();
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -67,17 +67,26 @@ int w_Canvas_getImageData(lua_State *L)
|
||||
int w_Canvas_setFilter(lua_State *L)
|
||||
{
|
||||
Canvas *canvas = luax_checkcanvas(L, 1);
|
||||
|
||||
Image::FilterMode min;
|
||||
Image::FilterMode mag;
|
||||
|
||||
const char *minstr = luaL_checkstring(L, 2);
|
||||
const char *magstr = luaL_checkstring(L, 3);
|
||||
|
||||
const char *magstr = luaL_optstring(L, 3, minstr);
|
||||
|
||||
if (!Image::getConstant(minstr, min))
|
||||
return luaL_error(L, "Invalid filter mode: %s", minstr);
|
||||
if (!Image::getConstant(magstr, mag))
|
||||
return luaL_error(L, "Invalid filter mode: %s", magstr);
|
||||
|
||||
Image::Filter f;
|
||||
if (!Image::getConstant(minstr, f.min))
|
||||
return luaL_error(L, "Invalid min filter mode: %s", minstr);
|
||||
if (!Image::getConstant(magstr, f.mag))
|
||||
return luaL_error(L, "Invalid max filter mode: %s", magstr);
|
||||
|
||||
f.min = min;
|
||||
f.mag = mag;
|
||||
|
||||
canvas->setFilter(f);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int w_Canvas_getFilter(lua_State *L)
|
||||
@@ -99,16 +108,24 @@ int w_Canvas_getFilter(lua_State *L)
|
||||
int w_Canvas_setWrap(lua_State *L)
|
||||
{
|
||||
Canvas *canvas = luax_checkcanvas(L, 1);
|
||||
const char *wrap_s = luaL_checkstring(L, 2);
|
||||
const char *wrap_t = luaL_checkstring(L, 3);
|
||||
|
||||
|
||||
Image::WrapMode s;
|
||||
Image::WrapMode t;
|
||||
|
||||
const char *sstr = luaL_checkstring(L, 2);
|
||||
const char *tstr = luaL_optstring(L, 3, sstr);
|
||||
|
||||
if (!Image::getConstant(sstr, s))
|
||||
return luaL_error(L, "Invalid wrap mode: %s", sstr);
|
||||
if (!Image::getConstant(tstr, t))
|
||||
return luaL_error(L, "Invalid wrap mode, %s", tstr);
|
||||
|
||||
Image::Wrap w;
|
||||
if (!Image::getConstant(wrap_s, w.s))
|
||||
return luaL_error(L, "Invalid wrap mode: %s", wrap_s);
|
||||
if (!Image::getConstant(wrap_t, w.t))
|
||||
return luaL_error(L, "Invalid wrap mode: %s", wrap_t);
|
||||
|
||||
w.s = s;
|
||||
w.t = t;
|
||||
|
||||
canvas->setWrap(w);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +90,45 @@ int w_Font_getLineHeight(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Font_setFilter(lua_State *L)
|
||||
{
|
||||
Font *t = luax_checkfont(L, 1);
|
||||
|
||||
Image::FilterMode min;
|
||||
Image::FilterMode mag;
|
||||
|
||||
const char *minstr = luaL_checkstring(L, 2);
|
||||
const char *magstr = luaL_optstring(L, 3, minstr);
|
||||
|
||||
if (!Image::getConstant(minstr, min))
|
||||
return luaL_error(L, "Invalid filter mode: %s", minstr);
|
||||
if (!Image::getConstant(magstr, mag))
|
||||
return luaL_error(L, "Invalid filter mode: %s", magstr);
|
||||
|
||||
Image::Filter f;
|
||||
f.min = min;
|
||||
f.mag = mag;
|
||||
|
||||
t->setFilter(f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Font_getFilter(lua_State *L)
|
||||
{
|
||||
Font *t = luax_checkfont(L, 1);
|
||||
Image::Filter f = t->getFilter();
|
||||
Image::FilterMode min = f.min;
|
||||
Image::FilterMode mag = f.mag;
|
||||
const char *minstr;
|
||||
const char *magstr;
|
||||
Image::getConstant(min, minstr);
|
||||
Image::getConstant(mag, magstr);
|
||||
lua_pushstring(L, minstr);
|
||||
lua_pushstring(L, magstr);
|
||||
return 2;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getHeight", w_Font_getHeight },
|
||||
@@ -97,6 +136,8 @@ static const luaL_Reg functions[] =
|
||||
{ "getWrap", w_Font_getWrap },
|
||||
{ "setLineHeight", w_Font_setLineHeight },
|
||||
{ "getLineHeight", w_Font_getLineHeight },
|
||||
{ "setFilter", w_Font_setFilter },
|
||||
{ "getFilter", w_Font_getFilter },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
@@ -38,6 +38,8 @@ int w_Font_getWidth(lua_State *L);
|
||||
int w_Font_getWrap(lua_State *L);
|
||||
int w_Font_setLineHeight(lua_State *L);
|
||||
int w_Font_getLineHeight(lua_State *L);
|
||||
int w_Font_setFilter(lua_State *L);
|
||||
int w_Font_getFilter(lua_State *L);
|
||||
extern "C" int luaopen_font(lua_State *L);
|
||||
|
||||
} // opengl
|
||||
|
||||
@@ -601,8 +601,10 @@ int w_setDefaultImageFilter(lua_State *L)
|
||||
{
|
||||
Image::FilterMode min;
|
||||
Image::FilterMode mag;
|
||||
|
||||
const char *minstr = luaL_checkstring(L, 1);
|
||||
const char *magstr = luaL_optstring(L, 2, minstr);
|
||||
|
||||
if (!Image::getConstant(minstr, min))
|
||||
return luaL_error(L, "Invalid filter mode: %s", minstr);
|
||||
if (!Image::getConstant(magstr, mag))
|
||||
@@ -611,6 +613,7 @@ int w_setDefaultImageFilter(lua_State *L)
|
||||
Image::Filter f;
|
||||
f.min = min;
|
||||
f.mag = mag;
|
||||
|
||||
instance->setDefaultImageFilter(f);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -50,19 +50,24 @@ int w_Image_getHeight(lua_State *L)
|
||||
int w_Image_setFilter(lua_State *L)
|
||||
{
|
||||
Image *t = luax_checkimage(L, 1);
|
||||
Image::Filter f;
|
||||
|
||||
Image::FilterMode min;
|
||||
Image::FilterMode mag;
|
||||
|
||||
const char *minstr = luaL_checkstring(L, 2);
|
||||
const char *magstr = luaL_optstring(L, 3, minstr);
|
||||
|
||||
if (!Image::getConstant(minstr, min))
|
||||
return luaL_error(L, "Invalid filter mode: %s", minstr);
|
||||
if (!Image::getConstant(magstr, mag))
|
||||
return luaL_error(L, "Invalid filter mode: %s", magstr);
|
||||
|
||||
Image::Filter f;
|
||||
f.min = min;
|
||||
f.mag = mag;
|
||||
|
||||
t->setFilter(f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -84,19 +89,24 @@ int w_Image_getFilter(lua_State *L)
|
||||
int w_Image_setWrap(lua_State *L)
|
||||
{
|
||||
Image *i = luax_checkimage(L, 1);
|
||||
Image::Wrap w;
|
||||
|
||||
Image::WrapMode s;
|
||||
Image::WrapMode t;
|
||||
|
||||
const char *sstr = luaL_checkstring(L, 2);
|
||||
const char *tstr = luaL_optstring(L, 3, sstr);
|
||||
|
||||
if (!Image::getConstant(sstr, s))
|
||||
return luaL_error(L, "Invalid wrap mode: %s", sstr);
|
||||
if (!Image::getConstant(tstr, t))
|
||||
return luaL_error(L, "Invalid wrap mode, %s", tstr);
|
||||
|
||||
Image::Wrap w;
|
||||
w.s = s;
|
||||
w.t = t;
|
||||
|
||||
i->setWrap(w);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user