Skip to content

Commit

Permalink
GL Texture Manager: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Mar 21, 2013
1 parent b7d59d1 commit ea5804c
Showing 1 changed file with 21 additions and 29 deletions.
50 changes: 21 additions & 29 deletions doomsday/client/src/gl/gl_texmanager.cpp
Expand Up @@ -87,7 +87,7 @@ static TexSource loadPatch(image_t &image, de::FileHandle &file, int tclass = 0,
static TexSource loadDetail(image_t &image, de::FileHandle &file);

static TexSource loadRaw(image_t &image, rawtex_t const &raw);
static TexSource loadPatchComposite(image_t &image, Texture &tex,
static TexSource loadPatchComposite(image_t &image, Texture const &tex,
bool zeroMask = false, bool useZeroOriginIfOneComponent = false);

int ratioLimit = 0; // Zero if none.
Expand Down Expand Up @@ -575,11 +575,11 @@ static void uploadContentUnmanaged(uploadcontentmethod_t uploadMethod,
uploadContent(uploadMethod, content);
}

static TexSource loadSourceImage(de::Texture &tex, texturevariantspecification_t const &baseSpec,
image_t &image)
static TexSource loadSourceImage(Texture const &tex,
texturevariantspecification_t const &spec, image_t &image)
{
TexSource source = TEXS_NONE;
variantspecification_t const &spec = TS_GENERAL(baseSpec);
variantspecification_t const &vspec = TS_GENERAL(spec);
if(!tex.manifest().schemeName().compareWithoutCase("Textures"))
{
// Attempt to load an external replacement for this composite texture?
Expand All @@ -592,13 +592,13 @@ static TexSource loadSourceImage(de::Texture &tex, texturevariantspecification_t

if(source == TEXS_NONE)
{
if(TC_SKYSPHERE_DIFFUSE != spec.context)
if(TC_SKYSPHERE_DIFFUSE != vspec.context)
{
source = loadPatchComposite(image, tex);
}
else
{
bool const zeroMask = !!(spec.flags & TSF_ZEROMASK);
bool const zeroMask = (vspec.flags & TSF_ZEROMASK) != 0;
bool const useZeroOriginIfOneComponent = true;
source = loadPatchComposite(image, tex, zeroMask, useZeroOriginIfOneComponent);
}
Expand Down Expand Up @@ -647,15 +647,15 @@ static TexSource loadSourceImage(de::Texture &tex, texturevariantspecification_t
else if(!tex.manifest().schemeName().compareWithoutCase("Patches"))
{
int tclass = 0, tmap = 0;
if(spec.flags & TSF_HAS_COLORPALETTE_XLAT)
if(vspec.flags & TSF_HAS_COLORPALETTE_XLAT)
{
DENG_ASSERT(spec.translated);
tclass = spec.translated->tClass;
tmap = spec.translated->tMap;
DENG_ASSERT(vspec.translated);
tclass = vspec.translated->tClass;
tmap = vspec.translated->tMap;
}

// Attempt to load an external replacement for this patch?
if(!noHighResTex && (loadExtAlways || highResWithPWAD || !tex.isFlagged(de::Texture::Custom)))
if(!noHighResTex && (loadExtAlways || highResWithPWAD || !tex.isFlagged(Texture::Custom)))
{
de::Uri uri = tex.manifest().composeUri();
source = loadExternalTexture(image, uri.compose(), "-ck");
Expand All @@ -674,7 +674,7 @@ static TexSource loadSourceImage(de::Texture &tex, texturevariantspecification_t
de::File1 &lump = App_FileSystem().nameIndex().lump(lumpNum);
de::FileHandle &hndl = App_FileSystem().openLump(lump);

source = loadPatch(image, hndl, tclass, tmap, spec.border);
source = loadPatch(image, hndl, tclass, tmap, vspec.border);

App_FileSystem().releaseFile(hndl.file());
delete &hndl;
Expand All @@ -688,11 +688,11 @@ static TexSource loadSourceImage(de::Texture &tex, texturevariantspecification_t
else if(!tex.manifest().schemeName().compareWithoutCase("Sprites"))
{
int tclass = 0, tmap = 0;
if(spec.flags & TSF_HAS_COLORPALETTE_XLAT)
if(vspec.flags & TSF_HAS_COLORPALETTE_XLAT)
{
DENG_ASSERT(spec.translated);
tclass = spec.translated->tClass;
tmap = spec.translated->tMap;
DENG_ASSERT(vspec.translated);
tclass = vspec.translated->tClass;
tmap = vspec.translated->tMap;
}

// Attempt to load an external replacement for this sprite?
Expand All @@ -701,7 +701,7 @@ static TexSource loadSourceImage(de::Texture &tex, texturevariantspecification_t
de::Uri uri = tex.manifest().composeUri();

// Prefer psprite or translated versions if available.
if(TC_PSPRITE_DIFFUSE == spec.context)
if(TC_PSPRITE_DIFFUSE == vspec.context)
{
source = loadExternalTexture(image, "Patches:" + uri.path() + "-hud", "-ck");
}
Expand Down Expand Up @@ -729,7 +729,7 @@ static TexSource loadSourceImage(de::Texture &tex, texturevariantspecification_t
de::File1 &lump = App_FileSystem().nameIndex().lump(lumpNum);
de::FileHandle &hndl = App_FileSystem().openLump(lump);

source = loadPatch(image, hndl, tclass, tmap, spec.border);
source = loadPatch(image, hndl, tclass, tmap, vspec.border);

App_FileSystem().releaseFile(hndl.file());
delete &hndl;
Expand Down Expand Up @@ -2110,8 +2110,8 @@ static TexSource loadPatch(image_t &image, de::FileHandle &hndl, int tclass, int
return TEXS_NONE;
}

static TexSource loadPatchComposite(image_t &image, de::Texture &tex, bool maskZero,
bool useZeroOriginIfOneComponent)
static TexSource loadPatchComposite(image_t &image, Texture const &tex,
bool maskZero, bool useZeroOriginIfOneComponent)
{
LOG_AS("GL_LoadPatchComposite");

Expand All @@ -2121,8 +2121,7 @@ static TexSource loadPatchComposite(image_t &image, de::Texture &tex, bool maskZ
image.size.height = tex.height();
image.paletteId = defaultColorPalette;

image.pixels = (uint8_t*) M_Calloc(2 * image.size.width * image.size.height);
if(!image.pixels) Con_Error("GL_LoadPatchComposite: Failed on allocation of %lu bytes for new Image pixel data.", (unsigned long) (2 * image.size.width * image.size.height));
image.pixels = (uint8_t *) M_Calloc(2 * image.size.width * image.size.height);

CompositeTexture const &texDef = *reinterpret_cast<CompositeTexture *>(tex.userDataPointer());
DENG2_FOR_EACH_CONST(CompositeTexture::Components, i, texDef.components())
Expand Down Expand Up @@ -2449,7 +2448,6 @@ static void performImageAnalyses(Texture &tex, image_t const *image,
if(firstInit)
{
cp = (colorpalette_analysis_t*) M_Malloc(sizeof(*cp));
if(!cp) Con_Error("performImageAnalyses: Failed on allocation of %lu bytes for new ColorPaletteAnalysis.", (unsigned long) sizeof(*cp));
tex.setAnalysisDataPointer(Texture::ColorPaletteAnalysis, cp);
}

Expand All @@ -2466,7 +2464,6 @@ static void performImageAnalyses(Texture &tex, image_t const *image,
if(firstInit)
{
pl = (pointlight_analysis_t *) M_Malloc(sizeof *pl);
if(!pl) Con_Error("performImageAnalyses: Failed on allocation of %lu bytes for new PointLightAnalysis.", (unsigned long) sizeof(*pl));
tex.setAnalysisDataPointer(Texture::BrightPointAnalysis, pl);
}

Expand All @@ -2487,7 +2484,6 @@ static void performImageAnalyses(Texture &tex, image_t const *image,
if(firstInit)
{
aa = (averagealpha_analysis_t *) M_Malloc(sizeof(*aa));
if(!aa) Con_Error("performImageAnalyses: Failed on allocation of %lu bytes for new AverageAlphaAnalysis.", (unsigned long) sizeof(*aa));
tex.setAnalysisDataPointer(Texture::AverageAlphaAnalysis, aa);
}

Expand Down Expand Up @@ -2524,7 +2520,6 @@ static void performImageAnalyses(Texture &tex, image_t const *image,
if(firstInit)
{
ac = (averagecolor_analysis_t *) M_Malloc(sizeof(*ac));
if(!ac) Con_Error("performImageAnalyses: Failed on allocation of %lu bytes for new AverageColorAnalysis.", (unsigned long) sizeof(*ac));
tex.setAnalysisDataPointer(Texture::AverageColorAnalysis, ac);
}

Expand Down Expand Up @@ -2552,7 +2547,6 @@ static void performImageAnalyses(Texture &tex, image_t const *image,
if(firstInit)
{
ac = (averagecolor_analysis_t *) M_Malloc(sizeof(*ac));
if(!ac) Con_Error("performImageAnalyses: Failed on allocation of %lu bytes for new AverageColorAnalysis.", (unsigned long) sizeof(*ac));
tex.setAnalysisDataPointer(Texture::AverageColorAmplifiedAnalysis, ac);
}

Expand Down Expand Up @@ -2581,7 +2575,6 @@ static void performImageAnalyses(Texture &tex, image_t const *image,
if(firstInit)
{
ac = (averagecolor_analysis_t *) M_Malloc(sizeof(*ac));
if(!ac) Con_Error("performImageAnalyses: Failed on allocation of %lu bytes for new AverageColorAnalysis.", (unsigned long) sizeof(*ac));
tex.setAnalysisDataPointer(Texture::AverageTopColorAnalysis, ac);
}

Expand Down Expand Up @@ -2609,7 +2602,6 @@ static void performImageAnalyses(Texture &tex, image_t const *image,
if(firstInit)
{
ac = (averagecolor_analysis_t *) M_Malloc(sizeof(*ac));
if(!ac) Con_Error("performImageAnalyses: Failed on allocation of %lu bytes for new AverageColorAnalysis.", (unsigned long) sizeof(*ac));
tex.setAnalysisDataPointer(Texture::AverageBottomColorAnalysis, ac);
}

Expand Down

0 comments on commit ea5804c

Please sign in to comment.