summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/tiletex.cc
diff options
context:
space:
mode:
Diffstat (limited to 'crawl-ref/source/tiletex.cc')
-rw-r--r--crawl-ref/source/tiletex.cc150
1 files changed, 67 insertions, 83 deletions
diff --git a/crawl-ref/source/tiletex.cc b/crawl-ref/source/tiletex.cc
index f289352656..b8d80d9704 100644
--- a/crawl-ref/source/tiletex.cc
+++ b/crawl-ref/source/tiletex.cc
@@ -52,59 +52,85 @@ bool GenericTexture::load_texture(const char *filename,
// Determine texture format
unsigned char *pixels = (unsigned char*)img->pixels;
- int new_width = img->w;
- int new_height = img->h;
+ int new_width = 1;
+ while (new_width < img->w)
+ new_width *= 2;
+ int new_height = 1;
+ while (new_height < img->h)
+ new_height *= 2;
+
GLenum texture_format;
if (bpp == 4)
{
- if (img->format->Rmask == 0x000000ff)
- texture_format = GL_RGBA;
- else
- texture_format = GL_BGRA;
+ if (new_width != img->w || new_height != img->h)
+ {
+ SDL_LockSurface(img);
+ pixels = new unsigned char[4 * new_width * new_height];
+ memset(pixels, 0, 4 * new_width * new_height);
+
+ int dest = 0;
+ for (int y = 0; y < img->h; y++)
+ {
+ for (int x = 0; x < img->w; x++)
+ {
+ unsigned char *p = ((unsigned char*)img->pixels
+ + y * img->pitch + x * bpp);
+ unsigned int pixel = *(unsigned int*)p;
+ SDL_GetRGBA(pixel, img->format, &pixels[dest],
+ &pixels[dest+1], &pixels[dest+2],
+ &pixels[dest+3]);
+ dest += 4;
+ }
+ dest += 4 * (new_width - img->w);
+ }
+
+ SDL_UnlockSurface(img);
+ }
+ texture_format = GL_RGBA;
}
else if (bpp == 3)
{
- if (img->format->Rmask == 0x000000ff)
- texture_format = GL_RGB;
- else
- texture_format = GL_BGR;
+ if (new_width != img->w || new_height != img->h)
+ {
+ SDL_LockSurface(img);
+ pixels = new unsigned char[4 * new_width * new_height];
+ memset(pixels, 0, 4 * new_width * new_height);
+
+ int dest = 0;
+ for (int y = 0; y < img->h; y++)
+ {
+ for (int x = 0; x < img->w; x++)
+ {
+ unsigned char *p = ((unsigned char*)img->pixels
+ + y * img->pitch + x * bpp);
+ unsigned int pixel;
+ if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
+ pixel = p[0] << 16 | p[1] << 8 | p[2];
+ else
+ pixel = p[0] | p[1] << 8 | p[2];
+ SDL_GetRGBA(pixel, img->format, &pixels[dest],
+ &pixels[dest+1], &pixels[dest+2],
+ &pixels[dest+3]);
+ dest += 4;
+ }
+ dest += 4 * (new_width - img->w);
+ }
+
+ SDL_UnlockSurface(img);
+ }
+ texture_format = GL_RGBA;
}
else if (bpp == 1)
{
// need to depalettize
SDL_LockSurface(img);
- // Prefer power-of-two textures to avoid texture bleeding from
- // floating point error.
- // TODO enne - convert non-palettized to power-of-2 as well?
- new_width = 1;
- while (new_width < img->w)
- new_width *= 2;
- new_height = 1;
- while (new_height < img->h)
- new_height *= 2;
-
pixels = new unsigned char[4 * new_width * new_height];
SDL_Palette* pal = img->format->palette;
ASSERT(pal);
ASSERT(pal->colors);
- // Find transparent colour
- // TODO enne - this should probably be removed from rltiles
- // TODO enne - is there more than one transparent color??
- int trans_index = -1;
- for (int p = 0; p < pal->ncolors ; p++)
- {
- if (pal->colors[p].r == 71 &&
- pal->colors[p].g == 108 &&
- pal->colors[p].b == 108)
- {
- trans_index = p;
- break;
- }
- }
-
int src = 0;
int dest = 0;
for (int y = 0; y < img->h; y++)
@@ -116,7 +142,7 @@ bool GenericTexture::load_texture(const char *filename,
pixels[dest*4 ] = pal->colors[index].r;
pixels[dest*4 + 1] = pal->colors[index].g;
pixels[dest*4 + 2] = pal->colors[index].b;
- pixels[dest*4 + 3] = (index == trans_index) ? 0 : 255;
+ pixels[dest*4 + 3] = 255;
dest++;
}
while (x++ < new_width)
@@ -213,57 +239,15 @@ void GenericTexture::bind()
glBindTexture(GL_TEXTURE_2D, m_handle);
}
-void TilesTexture::get_texcoord_doll(int part, int idx, int ymax, float &x, float &y, float &wx, float &wy, int &wx_pix, int &wy_pix, int &ox, int &oy)
+TilesTexture::TilesTexture() :
+ GenericTexture(), m_tile_max(0), m_tile_info(NULL)
{
- int tile_idx = tilep_parts_start[part];
- int nx = tilep_parts_nx[part];
- int ny = tilep_parts_ny[part];
- ox = tilep_parts_ox[part];
- oy = tilep_parts_oy[part];
- wx_pix = TILE_X / nx;
- wy_pix = TILE_Y / ny;
-
- if (!idx)
- {
- wy = -1;
- return;
- }
- idx--;
- tile_idx += idx / (nx * ny);
-
- if (oy + wy_pix > ymax)
- wy_pix -= oy + wy_pix - ymax;
-
- int xs = (tile_idx % TILEP_PER_ROW) * TILE_X;
- int ys = (tile_idx / TILEP_PER_ROW) * TILE_Y;
- xs += (idx % nx) * TILE_X / nx;
- ys += ((idx / nx) % ny) * TILE_Y / ny;
-
- x = xs / (float)m_width;
- y = ys / (float)m_height;
- wx = wx_pix / (float)m_width;
- wy = wy_pix / (float)m_height;
}
-void TilesTexture::get_texcoord(int idx, float &x, float &y,
- float &wx, float &wy)
+void TilesTexture::set_info(int _max, tile_info *_info)
{
- const unsigned int tile_size = 32;
- unsigned int tiles_per_row = m_width / tile_size;
-
- wx = tile_size / (float)m_width;
- wy = tile_size / (float)m_height;
-
- unsigned int row = idx / tiles_per_row;
- unsigned int col = idx % tiles_per_row;
-
- x = tile_size * col / (float)m_width;
- y = tile_size * row / (float)m_height;
-
- ASSERT(row >= 0);
- ASSERT(col >= 0);
- ASSERT(x + wx <= m_width);
- ASSERT(y + wy <= m_height);
+ m_tile_max = _max;
+ m_tile_info = _info;
}