TextureCacheBase: Remove the texture size limit for custom textures. Only the GPU restrictions for maximum texture size remain.

This commit is contained in:
NeoBrainX
2012-05-13 15:38:56 +02:00
parent 41d37ab0a0
commit 72e83140f0
3 changed files with 33 additions and 20 deletions

View File

@ -99,7 +99,6 @@ bool HiresTexExists(const char* filename)
PC_TexFormat GetHiresTex(const char *fileName, unsigned int *pWidth, unsigned int *pHeight, unsigned int *required_size, int texformat, unsigned int data_size, u8 *data)
{
std::string key(fileName);
if (textureMap.find(key) == textureMap.end())
return PC_TEX_FMT_NONE;
@ -108,23 +107,17 @@ PC_TexFormat GetHiresTex(const char *fileName, unsigned int *pWidth, unsigned in
int channels;
u8 *temp = SOIL_load_image(textureMap[key].c_str(), &width, &height, &channels, SOIL_LOAD_RGBA);
if (temp == NULL)
{
ERROR_LOG(VIDEO, "Custom texture %s failed to load", textureMap[key].c_str());
SOIL_free_image_data(temp);
return PC_TEX_FMT_NONE;
}
if (width > 2048 || height > 2048)
{
ERROR_LOG(VIDEO, "Custom texture %s is too large (%ix%i); textures can only be 2048 pixels tall and wide", textureMap[key].c_str(), width, height);
SOIL_free_image_data(temp);
return PC_TEX_FMT_NONE;
}
*pWidth = width;
*pHeight = height;
int offset = 0;
PC_TexFormat returnTex;
PC_TexFormat returnTex = PC_TEX_FMT_NONE;
switch (texformat)
{
@ -132,24 +125,32 @@ PC_TexFormat GetHiresTex(const char *fileName, unsigned int *pWidth, unsigned in
case GX_TF_I8:
case GX_TF_IA4:
case GX_TF_IA8:
*required_size = width * height * 8;
if (data_size < *required_size)
goto cleanup;
for (int i = 0; i < width * height * 4; i += 4)
{
// Rather than use a luminosity function, just use the most intense color for luminance
// TODO(neobrain): Isn't this kind of.. stupid?
data[offset++] = *std::max_element(temp+i, temp+i+3);
data[offset++] = temp[i+3];
}
returnTex = PC_TEX_FMT_IA8;
break;
default:
*required_size = width * height * 4;
if (data_size < *required_size)
goto cleanup;
memcpy(data, temp, width * height * 4);
returnTex = PC_TEX_FMT_RGBA32;
break;
}
*pWidth = width;
*pHeight = height;
SOIL_free_image_data(temp);
INFO_LOG(VIDEO, "loading custom texture from %s", textureMap[key].c_str());
cleanup:
SOIL_free_image_data(temp);
return returnTex;
}