summaryrefslogtreecommitdiff
path: root/lib/gltexture.cc
diff options
context:
space:
mode:
authorpixel <pixel>2002-12-08 20:00:50 +0000
committerpixel <pixel>2002-12-08 20:00:50 +0000
commit4fde43181e0c726a1e0de1e26ffe1983774d1ed0 (patch)
tree4ad33126d854b941d972fc744056077f4adae30d /lib/gltexture.cc
parent218f34ad9e9026493fad5ead4dcafafc295b68cd (diff)
Commit of the day
Diffstat (limited to 'lib/gltexture.cc')
-rw-r--r--lib/gltexture.cc84
1 files changed, 71 insertions, 13 deletions
diff --git a/lib/gltexture.cc b/lib/gltexture.cc
index 61ba71c..b96184f 100644
--- a/lib/gltexture.cc
+++ b/lib/gltexture.cc
@@ -4,7 +4,13 @@
#include <generic.h>
#include "gltexture.h"
-mogltk::texture::texture(int w, int h, bool plane) throw (GeneralException) : width(w), height(h), planar(plane) {
+#ifdef TRACE_TEXTURES
+mogltk::texture * mogltk::texture::header = 0;
+mogltk::texture * mogltk::texture::footer = 0;
+#endif
+
+mogltk::texture::texture(int w, int h, bool plane) throw (GeneralException) : width(w), height(h),
+ texture_allocated(false), planar(plane) {
if ((BITCOUNT(w) != 1) || (BITCOUNT(h) != 1))
throw GeneralException("Size of the texture not a power of 2!");
@@ -23,26 +29,59 @@ mogltk::texture::texture(int w, int h, bool plane) throw (GeneralException) : wi
))) {
throw GeneralException("Can't create RGB Surface");
}
+
+#ifdef TRACE_TEXTURES
+ next = 0;
+ prev = footer;
+ footer = this;
+ if (!header) {
+ header = this;
+ }
+ if (prev) {
+ prev->next = this;
+ }
+#endif
}
mogltk::texture::~texture() {
if (surface) {
SDL_FreeSurface(surface);
- } else {
+ }
+
+ if (texture_allocated) {
glDeleteTextures(1, &tex);
}
+
+#ifdef TRACE_TEXTURES
+ if (prev) {
+ prev->next = next;
+ }
+
+ if (next) {
+ next->prev = prev;
+ }
+
+ if (this == footer) {
+ footer = prev;
+ }
+
+ if (this == header) {
+ header = next;
+ }
+#endif
}
-SDL_Surface * mogltk::texture::GetSurface() throw (GeneralException) {
- if (!surface)
- throw GeneralException("Texture already generated");
+SDL_Surface * mogltk::texture::GetSurface() {
return surface;
}
-void mogltk::texture::Generate() throw (GeneralException) {
- if (!surface)
- throw GeneralException("Texture already generated");
+void mogltk::texture::Generate() {
+ if (texture_allocated) {
+ glDeleteTextures(1, &tex);
+ }
+ glGenTextures(1, &tex);
+
if (planar) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -56,13 +95,12 @@ void mogltk::texture::Generate() throw (GeneralException) {
// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels);
}
- SDL_FreeSurface(surface);
- surface = 0;
+ texture_allocated = true;
}
-void mogltk::texture::Bind(bool expand) throw (GeneralException) {
- if (surface)
- throw GeneralException("Texture is not yet generated");
+void mogltk::texture::Bind(bool expand) {
+ if (!texture_allocated)
+ Generate();
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, tex);
if (expand) {
@@ -71,6 +109,26 @@ void mogltk::texture::Bind(bool expand) throw (GeneralException) {
glScaled(1 / (double) width, 1 / (double) height, 1);
glMatrixMode(GL_MODELVIEW);
}
+
+#ifdef TRACE_TEXTURES
+ if (header == this)
+ return;
+
+ if (prev) {
+ prev->next = next;
+ }
+
+ if (next) {
+ next->prev = prev;
+ }
+
+ if (footer = this) {
+ footer = prev;
+ }
+
+ header->prev = this;
+ header = this;
+#endif
}
GLuint mogltk::texture::GetWidth() {