00001 #ifndef __TEXTURE__
00002 #define __TEXTURE__
00003
00004 #include <OpenGL.h>
00005 #include "Dim2D.h"
00006 #include "TextureData.h"
00007
00008 namespace apig {
00009
00011 class Texture {
00012 public:
00013
00014 Texture() : id(0), texData(NULL), loaded(false) {}
00015 Texture(GLuint id, GLenum texMode) : id(id), texData(NULL), texMode(texMode), loaded(hasContent()) {}
00016 Texture(const TextureData *texData, GLenum interpMode = GL_NEAREST, GLenum wrapMode = GL_CLAMP);
00017 Texture(GLenum texMode, GLenum interpMode = GL_NEAREST, GLenum wrapMode = GL_CLAMP);
00018
00019
00020 void load();
00021 void load(GLint internalFormat);
00022 bool isLoaded() const { return loaded; }
00023
00024
00025 void activate() const;
00026 void deactivate() const;
00027 void destroy();
00028
00029
00030 void activate(int texNum) const;
00031 void deactivate(int texNum) const;
00032
00033
00034
00035 void setInterpMode(GLenum interpMode);
00036 void setWrapMode(GLenum wrapMode);
00037 void setBorderColor(const float *color) const;
00038 void setBorderColor(float r, float g, float b, float a = 1) const;
00039
00040 GLuint getID() const { return id; }
00041 GLenum getMode() const { return texMode; }
00042
00043
00044
00045 static Texture createTex1D(int w, GLint internalFormat = GL_RGBA, GLenum interpMode = GL_NEAREST, GLenum wrapMode = GL_CLAMP);
00046 static Texture createTex2D(int w, int h, GLint internalFormat = GL_RGBA, GLenum interpMode = GL_NEAREST, GLenum wrapMode = GL_CLAMP);
00047 static Texture createTex3D(int w, int h, int d, GLint internalFormat = GL_RGBA, GLenum interpMode = GL_NEAREST, GLenum wrapMode = GL_CLAMP);
00048 static Texture createTexCube(int n, GLint internalFormat = GL_RGBA, GLenum interpMode = GL_NEAREST, GLenum wrapMode = GL_CLAMP);
00049
00050 void copyReadBuffer(GLenum internalFormat, int w, int h, int x=0, int y=0);
00051
00052
00053 void bind() const;
00054 int getParam(GLenum paramName) const;
00055 int getLevelParam(GLenum paramName, int level = 0) const { return getLevelParam(texMode, paramName, level); }
00056 int getLevelParam(int target, GLenum paramName, int level = 0) const;
00057 int getWidth() const { return getLevelParam(GL_TEXTURE_WIDTH); }
00058 int getHeight() const { return getLevelParam(GL_TEXTURE_HEIGHT); }
00059 int getDepth() const { return getLevelParam(GL_TEXTURE_DEPTH); }
00060
00061
00062
00063 Dim2D renderSize(int level = 0) const { return renderSize(texMode, level); }
00064 Dim2D renderSize(GLenum target, int level = 0) const;
00065
00066 private:
00067 void generateID();
00068 void init() const;
00069 void updateInterpMode() const;
00070 void updateWrapMode() const;
00071 bool hasContent() const;
00072
00073 private:
00074 GLuint id;
00075 const TextureData *texData;
00076 mutable GLenum texMode,
00077 interpMode,
00078 wrapMode;
00079 bool loaded;
00080 };
00081
00082 }
00083
00084 #endif
00085