From 58d8064ce2beb470ed36ea6bf4b0ac5bed8d0079 Mon Sep 17 00:00:00 2001 From: pixel Date: Thu, 2 Feb 2006 17:29:04 +0000 Subject: Having a better texture tainting solution, which will hopefully avoid texture mess when going fullscreen. --- lib/base.cc | 3 ++- lib/font.cc | 7 +++++-- lib/glbase.cc | 3 ++- lib/shape.cc | 4 +++- lib/sprite.cc | 3 ++- lib/texture.cc | 30 +++++++++++++----------------- 6 files changed, 27 insertions(+), 23 deletions(-) (limited to 'lib') diff --git a/lib/base.cc b/lib/base.cc index 85606c6..db0e77f 100644 --- a/lib/base.cc +++ b/lib/base.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: base.cc,v 1.15 2005-04-03 19:39:06 pixel Exp $ */ +/* $Id: base.cc,v 1.16 2006-02-02 17:29:05 pixel Exp $ */ #include #include @@ -151,6 +151,7 @@ mogltk::texture * mogltk::base::GrabTexture() { int w = nextpower(GetWidth()); int h = nextpower(GetHeight()); texture * r = new texture(w, h); + r->name = "texture grabbed"; SDL_BlitSurface(getsurface(), NULL, r->GetSurface(), NULL); diff --git a/lib/font.cc b/lib/font.cc index 8527d15..fab51e4 100644 --- a/lib/font.cc +++ b/lib/font.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: font.cc,v 1.17 2005-12-01 13:48:12 pixel Exp $ */ +/* $Id: font.cc,v 1.18 2006-02-02 17:29:05 pixel Exp $ */ #include #include @@ -150,6 +150,7 @@ mogltk::font::font(Handle * ffont) : textcolor(255, 255, 255, 255), shadow(0), w for (i = 0; i < nbT; i++) { fonttex[i] = alloctexture(); + fonttex[i]->name = "Main font texture number " + String(i); for (j = 0; j < 15; j++) { fontcache[j][i] = 0; } @@ -605,6 +606,7 @@ mogltk::texture * mogltk::font::printtex(rect * _r, const ugly_string & m, va_li ph = nextpower(r.h); t = new texture(pw, ph); + t->name = String("Text-on-texture: '") + m.p + "'"; for (p = buffer; *p; p++) { if (*p == '\n') { @@ -672,7 +674,7 @@ mogltk::font * mogltk::SystemFont; mogltk::font * mogltk::FixedFont; mogltk::texture * mogltk::font::alloctexture() { - return new mogltk::texture(256, 256); + return new texture(256, 256); } void mogltk::font::Bind(int f) { @@ -691,6 +693,7 @@ void mogltk::font::checknbind(int index, ColorP c) { if (!fontcache[i][index]) { fontcache[i][index] = alloctexture(); + fontcache[i][index]->name = "Color font texture number " + String(index); for (y = 0; y < 256; y++) { for (x = 0; x < 256; x++) { t.fromSDL(fontcache[15][index]->GetPixels()[(y << 8) + x], f); diff --git a/lib/glbase.cc b/lib/glbase.cc index 2edeec5..89b849a 100644 --- a/lib/glbase.cc +++ b/lib/glbase.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: glbase.cc,v 1.22 2004-11-27 21:48:03 pixel Exp $ */ +/* $Id: glbase.cc,v 1.23 2006-02-02 17:29:05 pixel Exp $ */ #include #include @@ -224,6 +224,7 @@ mogltk::texture * mogltk::glbase::GrabTexture() { int w = nextpower(GetWidth()); int h = nextpower(GetHeight()); texture * r = new texture(w, h); + r->name = "Texture grabbed."; SDL_Surface * t; t = GrabSurface(); diff --git a/lib/shape.cc b/lib/shape.cc index 7a3312a..63b0920 100644 --- a/lib/shape.cc +++ b/lib/shape.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: shape.cc,v 1.20 2005-12-01 13:48:12 pixel Exp $ */ +/* $Id: shape.cc,v 1.21 2006-02-02 17:29:05 pixel Exp $ */ #include #include @@ -177,6 +177,7 @@ mogltk::texture * mogltk::fill::Talloc() { for (y = 1; y <= (maxY - minY); y <<= 1); cached = new texture(x, y, true); + cached->name = "Fill-texture - cached"; return cached; } @@ -190,6 +191,7 @@ mogltk::texture * mogltk::fill::STalloc() { for (y = 1; y <= (maxY - minY); y <<= 1); scached = new texture(x, y, true); + cached->name = "Fill-texture - scached"; return scached; } diff --git a/lib/sprite.cc b/lib/sprite.cc index bd0df94..bce6bf2 100644 --- a/lib/sprite.cc +++ b/lib/sprite.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: sprite.cc,v 1.15 2004-11-27 21:48:03 pixel Exp $ */ +/* $Id: sprite.cc,v 1.16 2006-02-02 17:29:05 pixel Exp $ */ #include #include "engine.h" @@ -85,6 +85,7 @@ void mogltk::Sprite::alloc() { mogltk::Sprite::TexList::TexList(int size) { tex = new texture(size, size, true); + tex->name = "Sprite texture."; if (header) header->prev = this; diff --git a/lib/texture.cc b/lib/texture.cc index 45e9f3b..aa927c8 100644 --- a/lib/texture.cc +++ b/lib/texture.cc @@ -17,9 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: texture.cc,v 1.13 2006-02-02 14:09:49 pixel Exp $ */ - -#define DEBUG +/* $Id: texture.cc,v 1.14 2006-02-02 17:29:05 pixel Exp $ */ #include #include @@ -32,8 +30,6 @@ #endif #include "gettext.h" -#define DEBUG 1 - mogltk::texture * mogltk::texture::header = 0; mogltk::texture * mogltk::texture::footer = 0; @@ -82,9 +78,7 @@ mogltk::texture::texture(Handle * h, bool plane) throw (GeneralException) : width = temp->w; height = temp->h; -#ifdef DEBUG printm(M_INFO, "Creating texture from file: size %ix%i\n", height, width); -#endif if ((!ISPOT(width)) || (!ISPOT(height))) { SDL_FreeSurface(temp); @@ -143,9 +137,7 @@ mogltk::texture::texture(SDL_Surface * temp, bool plane) throw (GeneralException width = temp->w; height = temp->h; -#ifdef DEBUG printm(M_INFO, "Creating texture from file: size %ix%i\n", height, width); -#endif if ((!ISPOT(width)) || (!ISPOT(height))) { throw GeneralException(_("Size of the texture not a power of 2!")); @@ -273,9 +265,8 @@ void mogltk::texture::Generate() { } glGenTextures(1, &tex); -#ifdef DEBUG - printm(M_INFO, _("Generated texture index: %i\n"), tex); -#endif + + printm(M_INFO, "Generated texture " + name + " with index " + tex + "\n"); glBindTexture(GL_TEXTURE_2D, tex); @@ -288,9 +279,6 @@ void mogltk::texture::Generate() { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels); } else { -#endif -#ifdef DEBUG - printm(M_INFO, _("Generating 3D texture: %i\n"), tex); #endif glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); @@ -360,12 +348,20 @@ void mogltk::texture::Unbind(void) { } void mogltk::texture::Taint(void) { - if (taintable) + if (taintable) { + printm(M_INFO, "Tainting texture " + name + "\n"); tainted = true; + if (active == this) + Unbind(); + if (texture_allocated) { + glDeleteTextures(1, &tex); + texture_allocated = false; + } + } } void mogltk::texture::Taintall(void) { - active = 0; + Unbind(); if (header) header->recTaint(); } -- cgit v1.2.3