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:
Eduardo Bart
2012-06-08 21:40:22 -03:00
parent 1a7f2a44fc
commit 95cf7eb788
21 changed files with 180 additions and 155 deletions

View File

@@ -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;
}