From 2d3add1b36348a146012a56cc39ebe0335678e61 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Mon, 16 May 2011 20:21:41 -0300 Subject: [PATCH] fix texture bug --- src/framework/graphics/texture.cpp | 69 ++++++++++++++++++------------ src/framework/graphics/texture.h | 4 +- 2 files changed, 43 insertions(+), 30 deletions(-) diff --git a/src/framework/graphics/texture.cpp b/src/framework/graphics/texture.cpp index 0b6fd5b1..d5ddff70 100644 --- a/src/framework/graphics/texture.cpp +++ b/src/framework/graphics/texture.cpp @@ -24,42 +24,54 @@ #include #include +#include "graphics.h" -Texture::Texture(int width, int height, int channels, const uchar *pixels) +Texture::Texture(int width, int height, int channels, uchar *pixels) { // generate opengl texture m_textureId = internalLoadGLTexture(pixels, channels, width, height); } -uint Texture::internalLoadGLTexture(const uchar *pixels, int channels, int width, int height) +uint Texture::internalLoadGLTexture(uchar *pixels, int channels, int width, int height) { + GLint texSize; + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize); + if(width > texSize || height > texSize) { + flogError("loading texture with size %dx%d failed, the maximum size is %dx%d", width % height % texSize % texSize); + return 0; + } + // generate gl texture GLuint id; glGenTextures(1, &id); glBindTexture(GL_TEXTURE_2D, id); - - // convert texture size to power of 2 - int glWidth = 1; - while(glWidth < width) - glWidth = glWidth << 1; - - int glHeight = 1; - while(glHeight < height) - glHeight = glHeight << 1; - m_size.setSize(width, height); - m_glSize.setSize(glWidth, glHeight); - - uchar *out = NULL; - if(m_size != m_glSize) { - out = new uchar[glHeight*glWidth*channels]; - memset(out, 0, glHeight*glWidth*channels); - if(pixels) - for(int y=0;y { public: /// Create a texture, width and height must be a multiple of 2 - Texture(int width, int height, int channels, const uchar *pixels = NULL); + Texture(int width, int height, int channels, uchar *pixels = NULL); virtual ~Texture(); /// Enable texture bilinear filter (smooth scaled textures) @@ -48,7 +48,7 @@ public: protected: Texture() { } - uint internalLoadGLTexture(const uchar *pixels, int channels, int w, int h); + uint internalLoadGLTexture(uchar *pixels, int channels, int w, int h); uint m_textureId; Size m_size;