23 int offsets[16], sizes[16], type = 0;
24 uint width = 0, height = 0;
28 glBindTexture(GL_TEXTURE_2D,
id);
48 const bool hasmipmaps = (attr[3] > 0);
49 const size_t mipmax = hasmipmaps ? 16 : 1;
55 <<
static_cast<uint>(attr[0]) <<
static_cast<uint>(attr[1]) <<
static_cast<uint>(attr[2])
56 <<
static_cast<uint>(attr[3]) <<
"width" << width <<
"height" << height;
71 LOG_ERROR << __FILE__ << __FUNCTION__ << __LINE__ <<
"type=" << type;
73 unsigned char* buf =
new unsigned char[sizes[0]];
82 LOG_ERROR << __FUNCTION__ << __LINE__ <<
"Failed to load texture";
90 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, flipped.
width(), flipped.
height(), 0, GL_BGRA, GL_UNSIGNED_BYTE, flipped.
data());
114 unsigned char* ucbuf =
nullptr;
116 ucbuf =
new unsigned char[width * height * 4];
118 GLint format = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
123 if (attr[1] == 8 || attr[1] == 4)
125 format = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
129 if (attr[1] == 0 && attr[2] == 0)
131 format = GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
136 if (attr[1] == 8 && attr[2] == 7)
138 format = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
144 unsigned char* buf =
new unsigned char[sizes[0]];
147 for (
size_t i = 0; i < mipmax; i++)
149 if (width == 0) width = 1;
150 if (height == 0) height = 1;
151 if (offsets[i] && sizes[i])
156 const int size = ((width + 3) / 4) * ((height + 3) / 4) * blocksize;
160 glCompressedTexImage2DARB(GL_TEXTURE_2D,
static_cast<GLint
>(i), format, width, height, 0, size, buf);
165 glTexImage2D(GL_TEXTURE_2D,
static_cast<GLint
>(i), GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
185 else if (attr[0] == 1)
199 unsigned int pal[256];
202 unsigned char* buf =
new unsigned char[sizes[0]];
203 unsigned int* buf2 =
new unsigned int[width * height];
205 const int alphabits = attr[1];
206 const bool hasalpha = (alphabits != 0);
210 for (
size_t i = 0; i < mipmax; i++)
212 if (width == 0) width = 1;
213 if (height == 0) height = 1;
214 if (offsets[i] && sizes[i])
222 unsigned int* p = buf2;
223 const unsigned char* c = buf;
224 const unsigned char* a = buf + width * height;
225 for (
uint y = 0; y < height; y++)
227 for (
uint x = 0; x < width; x++)
231 k = ((k & 0x00FF0000) >> 16) | ((k & 0x0000FF00)) | ((k & 0x000000FF) << 16);
239 else if (alphabits == 4)
241 alpha = (*a & (0xf << cnt++)) * 0x11;
248 else if (alphabits == 1)
251 alpha = (*a & (1 << cnt++)) ? 0xff : 0;
266 glTexImage2D(GL_TEXTURE_2D,
static_cast<GLint
>(i), GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf2);
281 LOG_ERROR << __FILE__ << __FUNCTION__ << __LINE__ <<
"type=" << type <<
"attr[0]=" << attr[0];
293 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
294 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
void decompressDXTC(GLint format, int w, int h, size_t size, unsigned char *src, unsigned char *dest)
void getPixels(unsigned char *buff, unsigned int format=GL_RGBA)