mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Removed unnecessary tabs in empty lines, fixed texture filtering when the minification and mipmap filter are the same
This commit is contained in:
@@ -77,7 +77,7 @@ public:
|
||||
static bool getConstant(WrapMode in, const char *&out);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
// The default image filter
|
||||
static Filter defaultFilter;
|
||||
|
||||
|
||||
@@ -97,9 +97,9 @@ struct FramebufferStrategyGL3 : public FramebufferStrategy
|
||||
|
||||
glGenTextures(1, &img);
|
||||
bindTexture(img);
|
||||
|
||||
|
||||
setTextureFilter(Image::getDefaultFilter());
|
||||
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height,
|
||||
0, GL_RGBA, format, NULL);
|
||||
bindTexture(0);
|
||||
@@ -165,7 +165,7 @@ struct FramebufferStrategyPackedEXT : public FramebufferStrategy
|
||||
|
||||
glGenTextures(1, &img);
|
||||
bindTexture(img);
|
||||
|
||||
|
||||
setTextureFilter(Image::getDefaultFilter());
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height,
|
||||
@@ -232,9 +232,9 @@ struct FramebufferStrategyEXT : public FramebufferStrategyPackedEXT
|
||||
|
||||
glGenTextures(1, &img);
|
||||
bindTexture(img);
|
||||
|
||||
|
||||
setTextureFilter(Image::getDefaultFilter());
|
||||
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height,
|
||||
0, GL_RGBA, format, NULL);
|
||||
bindTexture(0);
|
||||
|
||||
@@ -147,26 +147,26 @@ void Image::checkMipmapsCreated() const
|
||||
{
|
||||
if (filter.mipmap != FILTER_NEAREST && filter.mipmap != FILTER_LINEAR)
|
||||
return;
|
||||
|
||||
|
||||
if (!hasMipmapSupport())
|
||||
throw love::Exception("Mipmap filtering is not supported on this system!");
|
||||
|
||||
|
||||
// some old GPUs/systems claim support for NPOT textures, but fail when generating mipmaps
|
||||
// we can't detect which systems will do this, so we fail gracefully for all NPOT images
|
||||
int w = int(width), h = int(height);
|
||||
if (w != next_p2(w) || h != next_p2(h))
|
||||
throw love::Exception("Could not generate mipmaps: image does not have power of two dimensions!");
|
||||
|
||||
|
||||
bind();
|
||||
|
||||
|
||||
GLboolean mipmapscreated;
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, (GLint *)&mipmapscreated);
|
||||
|
||||
|
||||
// generate mipmaps for this image if we haven't already
|
||||
if (!mipmapscreated)
|
||||
{
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
|
||||
|
||||
|
||||
if (GLEE_VERSION_3_0 || GLEE_ARB_framebuffer_object)
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
else if (GLEE_EXT_framebuffer_object)
|
||||
@@ -180,7 +180,7 @@ void Image::checkMipmapsCreated() const
|
||||
void Image::setFilter(const Image::Filter &f)
|
||||
{
|
||||
filter = f;
|
||||
|
||||
|
||||
bind();
|
||||
checkMipmapsCreated();
|
||||
setTextureFilter(f);
|
||||
@@ -194,7 +194,7 @@ const Image::Filter &Image::getFilter() const
|
||||
void Image::setWrap(const Image::Wrap &w)
|
||||
{
|
||||
wrap = w;
|
||||
|
||||
|
||||
bind();
|
||||
setTextureWrap(w);
|
||||
}
|
||||
@@ -208,10 +208,10 @@ void Image::setMipmapSharpness(float sharpness)
|
||||
{
|
||||
if (!hasMipmapSharpnessSupport())
|
||||
return;
|
||||
|
||||
|
||||
// LOD bias has the range (-maxbias, maxbias)
|
||||
mipmapsharpness = std::min(std::max(sharpness, -maxmipmapsharpness + 0.01f), maxmipmapsharpness - 0.01f);
|
||||
|
||||
|
||||
bind();
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, -mipmapsharpness); // negative bias is sharper
|
||||
}
|
||||
@@ -243,7 +243,7 @@ bool Image::loadVolatile()
|
||||
{
|
||||
if (hasMipmapSharpnessSupport())
|
||||
glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS, &maxmipmapsharpness);
|
||||
|
||||
|
||||
if (hasNpot())
|
||||
return loadVolatileNPOT();
|
||||
else
|
||||
@@ -254,10 +254,10 @@ bool Image::loadVolatilePOT()
|
||||
{
|
||||
glGenTextures(1,(GLuint *)&texture);
|
||||
bindTexture(texture);
|
||||
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
||||
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
@@ -290,7 +290,7 @@ bool Image::loadVolatilePOT()
|
||||
GL_RGBA,
|
||||
GL_UNSIGNED_BYTE,
|
||||
data->getData());
|
||||
|
||||
|
||||
setMipmapSharpness(mipmapsharpness);
|
||||
setFilter(filter);
|
||||
setWrap(wrap);
|
||||
@@ -302,10 +302,10 @@ bool Image::loadVolatileNPOT()
|
||||
{
|
||||
glGenTextures(1,(GLuint *)&texture);
|
||||
bindTexture(texture);
|
||||
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
||||
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
@@ -318,7 +318,7 @@ bool Image::loadVolatileNPOT()
|
||||
GL_RGBA,
|
||||
GL_UNSIGNED_BYTE,
|
||||
data->getData());
|
||||
|
||||
|
||||
setMipmapSharpness(mipmapsharpness);
|
||||
setFilter(filter);
|
||||
setWrap(wrap);
|
||||
|
||||
@@ -105,9 +105,9 @@ public:
|
||||
void setWrap(const Image::Wrap &w);
|
||||
|
||||
const Image::Wrap &getWrap() const;
|
||||
|
||||
|
||||
void setMipmapSharpness(float sharpness);
|
||||
|
||||
|
||||
float getMipmapSharpness() const;
|
||||
|
||||
void bind() const;
|
||||
@@ -143,22 +143,22 @@ private:
|
||||
|
||||
// The source vertices of the image.
|
||||
vertex vertices[4];
|
||||
|
||||
|
||||
// Mipmap texture LOD bias value
|
||||
float mipmapsharpness;
|
||||
|
||||
|
||||
// Implementation-dependent maximum/minimum mipmap sharpness values
|
||||
float maxmipmapsharpness;
|
||||
|
||||
|
||||
// The image's filter mode
|
||||
Image::Filter filter;
|
||||
|
||||
|
||||
// The image's wrap mode
|
||||
Image::Wrap wrap;
|
||||
|
||||
bool loadVolatilePOT();
|
||||
bool loadVolatileNPOT();
|
||||
|
||||
|
||||
void checkMipmapsCreated() const;
|
||||
|
||||
}; // Image
|
||||
|
||||
@@ -65,13 +65,13 @@ void setTextureFilter(const graphics::Image::Filter &f)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (f.min == f.mipmap == Image::FILTER_NEAREST)
|
||||
if (f.min == Image::FILTER_NEAREST && f.mipmap == Image::FILTER_NEAREST)
|
||||
gmin = GL_NEAREST_MIPMAP_NEAREST;
|
||||
else if (f.min == Image::FILTER_NEAREST && f.mipmap == Image::FILTER_LINEAR)
|
||||
gmin = GL_NEAREST_MIPMAP_LINEAR;
|
||||
else if (f.min == Image::FILTER_LINEAR && f.mipmap == Image::FILTER_NEAREST)
|
||||
gmin = GL_LINEAR_MIPMAP_NEAREST;
|
||||
else if (f.min == f.mipmap == Image::FILTER_LINEAR)
|
||||
else if (f.min == Image::FILTER_LINEAR && f.mipmap == Image::FILTER_LINEAR)
|
||||
gmin = GL_LINEAR_MIPMAP_LINEAR;
|
||||
else
|
||||
gmin = GL_LINEAR;
|
||||
|
||||
@@ -105,7 +105,7 @@ ParticleSystem::~ParticleSystem()
|
||||
|
||||
if (pStart != 0)
|
||||
delete [] pStart;
|
||||
|
||||
|
||||
if (particleVerts != 0)
|
||||
delete [] particleVerts;
|
||||
}
|
||||
@@ -207,10 +207,10 @@ void ParticleSystem::setBufferSize(unsigned int size)
|
||||
pLast = pStart = new particle[size];
|
||||
|
||||
pEnd = pStart + size;
|
||||
|
||||
|
||||
if (particleVerts != 0)
|
||||
delete [] particleVerts;
|
||||
|
||||
|
||||
// each particle has 4 vertices
|
||||
particleVerts = new vertex[size*4];
|
||||
}
|
||||
@@ -468,7 +468,7 @@ bool ParticleSystem::isFull() const
|
||||
void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
|
||||
{
|
||||
if (sprite == 0) return; // just in case of failure
|
||||
|
||||
|
||||
int numParticles = count();
|
||||
if (numParticles == 0) return; // don't bother if there's nothing to do
|
||||
|
||||
@@ -478,25 +478,26 @@ void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, flo
|
||||
static Matrix t;
|
||||
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
|
||||
glMultMatrixf((const GLfloat *)t.getElements());
|
||||
|
||||
|
||||
const vertex * imageVerts = sprite->getVertices();
|
||||
|
||||
|
||||
// set the vertex data for each particle (transformation, texcoords, color)
|
||||
for (int i = 0; i < numParticles; i++)
|
||||
{
|
||||
particle * p = pStart + i;
|
||||
|
||||
|
||||
// particle vertices are sprite vertices transformed by particle information
|
||||
t.setTransformation(p->position[0], p->position[1], p->rotation, p->size, p->size, offsetX, offsetY, 0.0f, 0.0f);
|
||||
t.transform(&particleVerts[i*4], &imageVerts[0], 4);
|
||||
|
||||
|
||||
// set the texture coordinate and color data for particle vertices
|
||||
for (int v = 0; v < 4; v++) {
|
||||
for (int v = 0; v < 4; v++)
|
||||
{
|
||||
int vi = (i * 4) + v; // current vertex index for particle
|
||||
|
||||
|
||||
particleVerts[vi].s = imageVerts[v].s;
|
||||
particleVerts[vi].t = imageVerts[v].t;
|
||||
|
||||
|
||||
// particle colors are stored as floats (0-1) but vertex colors are stored as unsigned bytes (0-255)
|
||||
particleVerts[vi].r = p->color.r*255;
|
||||
particleVerts[vi].g = p->color.g*255;
|
||||
@@ -504,19 +505,19 @@ void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, flo
|
||||
particleVerts[vi].a = p->color.a*255;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sprite->bind();
|
||||
|
||||
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vertex), (GLvoid *)&particleVerts[0].r);
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&particleVerts[0].x);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&particleVerts[0].s);
|
||||
|
||||
|
||||
glDrawArrays(GL_QUADS, 0, numParticles*4);
|
||||
|
||||
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
@@ -406,7 +406,7 @@ protected:
|
||||
|
||||
// Pointer to the end of the memory allocation.
|
||||
particle *pEnd;
|
||||
|
||||
|
||||
// array of transformed vertex data for all particles, for drawing
|
||||
vertex * particleVerts;
|
||||
|
||||
|
||||
@@ -601,10 +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))
|
||||
@@ -613,7 +613,7 @@ int w_setDefaultImageFilter(lua_State *L)
|
||||
Image::Filter f;
|
||||
f.min = min;
|
||||
f.mag = mag;
|
||||
|
||||
|
||||
instance->setDefaultImageFilter(f);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -50,17 +50,17 @@ int w_Image_getHeight(lua_State *L)
|
||||
int w_Image_setFilter(lua_State *L)
|
||||
{
|
||||
Image *t = luax_checkimage(L, 1);
|
||||
|
||||
|
||||
Image::Filter f;
|
||||
|
||||
|
||||
const char *minstr = luaL_checkstring(L, 2);
|
||||
const char *magstr = luaL_optstring(L, 3, minstr);
|
||||
|
||||
|
||||
if (!Image::getConstant(minstr, f.min))
|
||||
return luaL_error(L, "Invalid filter mode: %s", minstr);
|
||||
if (!Image::getConstant(magstr, f.mag))
|
||||
return luaL_error(L, "Invalid filter mode: %s", magstr);
|
||||
|
||||
|
||||
if (lua_isnoneornil(L, 4))
|
||||
f.mipmap = Image::FILTER_NONE; // mipmapping is disabled unless third argument is given
|
||||
else
|
||||
@@ -69,16 +69,16 @@ int w_Image_setFilter(lua_State *L)
|
||||
if (!Image::getConstant(mipmapstr, f.mipmap))
|
||||
return luaL_error(L, "Invalid filter mode: %s", mipmapstr);
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
t->setFilter(f);
|
||||
}
|
||||
catch(love::Exception &e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
return luaL_error(L, "%s", e.what());
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -92,32 +92,32 @@ int w_Image_getFilter(lua_State *L)
|
||||
Image::getConstant(f.mag, magstr);
|
||||
lua_pushstring(L, minstr);
|
||||
lua_pushstring(L, magstr);
|
||||
|
||||
|
||||
const char *mipmapstr;
|
||||
if (Image::getConstant(f.mipmap, mipmapstr))
|
||||
lua_pushstring(L, mipmapstr);
|
||||
else
|
||||
lua_pushnil(L); // only return a mipmap filter if mipmapping is enabled
|
||||
|
||||
|
||||
return 3;
|
||||
}
|
||||
|
||||
int w_Image_setWrap(lua_State *L)
|
||||
{
|
||||
Image *i = luax_checkimage(L, 1);
|
||||
|
||||
|
||||
Image::Wrap w;
|
||||
|
||||
|
||||
const char *sstr = luaL_checkstring(L, 2);
|
||||
const char *tstr = luaL_optstring(L, 3, sstr);
|
||||
|
||||
|
||||
if (!Image::getConstant(sstr, w.s))
|
||||
return luaL_error(L, "Invalid wrap mode: %s", sstr);
|
||||
if (!Image::getConstant(tstr, w.t))
|
||||
return luaL_error(L, "Invalid wrap mode, %s", tstr);
|
||||
|
||||
i->setWrap(w);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ int w_Image_setMipmapSharpness(lua_State *L)
|
||||
|
||||
float sharpness = (float) luaL_checknumber(L, 2);
|
||||
i->setMipmapSharpness(sharpness);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user