From d613505a776c1cfd07a5b35fe0421a29288d73ae Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Fri, 10 Jun 2011 15:03:27 +0200 Subject: [PATCH] Only pad when needed --- src/modules/graphics/opengl/Image.cpp | 35 ++++++++++++++++++++++++++- src/modules/graphics/opengl/Image.h | 3 +++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/modules/graphics/opengl/Image.cpp b/src/modules/graphics/opengl/Image.cpp index b4f9459dd..53256507b 100644 --- a/src/modules/graphics/opengl/Image.cpp +++ b/src/modules/graphics/opengl/Image.cpp @@ -29,7 +29,6 @@ namespace graphics { namespace opengl { - Image::Image(love::image::ImageData * data) : width((float)(data->getWidth())), height((float)(data->getHeight())), texture(0) { @@ -276,6 +275,14 @@ namespace opengl } bool Image::loadVolatile() + { + if (GLEE_ARB_texture_non_power_of_two) + return loadVolatileNPOT(); + else + return loadVolatilePOT(); + } + + bool Image::loadVolatilePOT() { glGenTextures(1,(GLuint*)&texture); glBindTexture(GL_TEXTURE_2D, texture); @@ -321,6 +328,32 @@ namespace opengl return true; } + bool Image::loadVolatileNPOT() + { + glGenTextures(1,(GLuint*)&texture); + glBindTexture(GL_TEXTURE_2D, 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); + + glTexImage2D(GL_TEXTURE_2D, + 0, + GL_RGBA8, + (GLsizei)width, + (GLsizei)height, + 0, + GL_RGBA, + GL_UNSIGNED_BYTE, + data->getData()); + + setFilter(settings.filter); + setWrap(settings.wrap); + + return true; + } + void Image::unloadVolatile() { settings.filter = getFilter(); diff --git a/src/modules/graphics/opengl/Image.h b/src/modules/graphics/opengl/Image.h index 3a2456efa..3d8b24149 100644 --- a/src/modules/graphics/opengl/Image.h +++ b/src/modules/graphics/opengl/Image.h @@ -69,6 +69,9 @@ namespace opengl Image::Wrap wrap; } settings; + bool loadVolatilePOT(); + bool loadVolatileNPOT(); + public: /**