mirror of
https://github.com/edubart/otclient.git
synced 2025-12-25 09:17:11 +01:00
graphics optimizations/fixes/features
* cache text vertex for StaticText, AnimatedText and Creature names * improved outfit rendering * fully compatible with OpenGL 1.1 * enable mipmaping for game sprites again * Ctrl+W hotkey clean game texts
This commit is contained in:
@@ -131,13 +131,57 @@ bool Image::nextMipmap()
|
||||
assert(m_bpp == 4);
|
||||
assert(stdext::is_power_of_two(m_size.width()) && stdext::is_power_of_two(m_size.height()));
|
||||
|
||||
if(m_size.width() == 1 || m_size.height() == 1)
|
||||
int iw = m_size.width();
|
||||
int ih = m_size.height();
|
||||
if(iw == 1 && ih == 1)
|
||||
return false;
|
||||
|
||||
Size size = m_size / 2;
|
||||
std::vector<uint8> pixels(size.area()*4, 0xFF);
|
||||
int ow = iw > 1 ? iw/2 : 1;
|
||||
int oh = ih > 1 ? ih/2 : 1;
|
||||
|
||||
std::vector<uint8> pixels(ow*oh*4, 0xFF);
|
||||
|
||||
//FIXME: calculate mipmaps for 8x1, 4x1, 2x1 ...
|
||||
if(iw != 1 && ih != 1) {
|
||||
for(int x=0;x<ow;++x) {
|
||||
for(int y=0;y<oh;++y) {
|
||||
uint8 *inPixel[4];
|
||||
inPixel[0] = &m_pixels[((y*2)*iw + (x*2))*4];
|
||||
inPixel[1] = &m_pixels[((y*2)*iw + (x*2)+1)*4];
|
||||
inPixel[2] = &m_pixels[((y*2+1)*iw + (x*2))*4];
|
||||
inPixel[3] = &m_pixels[((y*2+1)*iw + (x*2)+1)*4];
|
||||
uint8 *outPixel = &pixels[(y*ow + x)*4];
|
||||
|
||||
int pixelsSum[4];
|
||||
for(int i=0;i<4;++i)
|
||||
pixelsSum[i] = 0;
|
||||
|
||||
int usedPixels = 0;
|
||||
for(int j=0;j<4;++j) {
|
||||
// ignore colors of complete alpha pixels
|
||||
if(inPixel[j][3] < 16)
|
||||
continue;
|
||||
|
||||
for(int i=0;i<4;++i)
|
||||
pixelsSum[i] += inPixel[j][i];
|
||||
|
||||
usedPixels++;
|
||||
}
|
||||
|
||||
// try to guess the alpha pixel more accurately
|
||||
for(int i=0;i<4;++i) {
|
||||
if(usedPixels > 0)
|
||||
outPixel[i] = pixelsSum[i] / usedPixels;
|
||||
else
|
||||
outPixel[i] = 0;
|
||||
}
|
||||
outPixel[3] = pixelsSum[3]/4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_pixels = pixels;
|
||||
m_size = size;
|
||||
m_size = Size(ow, oh);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user