Skip to content

Commit

Permalink
Refactor: Relocated TextureVariantSpec_Compare() to texturevariant.cpp
Browse files Browse the repository at this point in the history
Although some of the specification properties are only meaningful
for the purposes of rendering, which is a client only concern, the
server presently still needs to manage context specialized variants
at a logical level.

However, ultimately there should be no need for Texture::Variant or
their specification on server side.
  • Loading branch information
danij-deng committed Jan 17, 2013
1 parent 3990936 commit 476ee97
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 75 deletions.
8 changes: 0 additions & 8 deletions doomsday/engine/include/gl/gl_texmanager.h
Expand Up @@ -201,14 +201,6 @@ GLint GL_MinFilterForVariantSpec(variantspecification_t const *spec);
GLint GL_MagFilterForVariantSpec(variantspecification_t const *spec);
int GL_LogicalAnisoLevelForVariantSpec(variantspecification_t const *spec);

/**
* Compare the given TextureVariantSpecifications and determine whether they can
* be considered equal (dependent on current engine state and the available features
* of the GL implementation).
*/
int GL_CompareTextureVariantSpecifications(texturevariantspecification_t const *a,
texturevariantspecification_t const *b);

/**
* Prepare a TextureVariantSpecification according to usage context. If incomplete
* context information is supplied, suitable defaults are chosen in their place.
Expand Down
5 changes: 2 additions & 3 deletions doomsday/engine/include/resource/materialvariantspec.h
Expand Up @@ -21,8 +21,7 @@
#define LIBDENG_RESOURCE_MATERIALVARIANTSPEC_H

#include "def_data.h"

struct texturevariantspecification_s;
#include "resource/texture.h" // TextureVariantSpec

/// Identifiers for material usage contexts.
typedef enum {
Expand Down Expand Up @@ -58,7 +57,7 @@ struct MaterialVariantSpec
materialcontext_t context;

/// Specification for the primary texture.
struct texturevariantspecification_s *primarySpec;
texturevariantspecification_t *primarySpec;

public:
/**
Expand Down
8 changes: 8 additions & 0 deletions doomsday/engine/include/resource/texturevariantspec.h
Expand Up @@ -158,4 +158,12 @@ typedef struct texturevariantspecification_s {
} data; // type-specific data.
} texturevariantspecification_t;

/**
* Compare the given TextureVariantSpecifications and determine whether they can
* be considered equal (dependent on current engine state and the available features
* of the GL implementation).
*/
int TextureVariantSpec_Compare(texturevariantspecification_t const *a,
texturevariantspecification_t const *b);

#endif /* LIBDENG_RESOURCE_TEXTUREVARIANTSPEC_H */
62 changes: 1 addition & 61 deletions doomsday/engine/src/gl/gl_texmanager.cpp
Expand Up @@ -309,47 +309,6 @@ static texturevariantspecification_t *copyDetailVariantSpecification(
return spec;
}

#endif // __CLIENT__

/**
* @todo Magnification, Anisotropic filter level and GL texture wrap modes
* will be handled through dynamic changes to GL's texture environment state.
* Consequently they should be ignored here.
*/
static int compareVariantSpecifications(variantspecification_t const *a,
variantspecification_t const *b)
{
/// @todo We can be a bit cleverer here...
if(a->context != b->context) return 0;
if(a->flags != b->flags) return 0;
if(a->wrapS != b->wrapS || a->wrapT != b->wrapT) return 0;
//if(a->magFilter != b->magFilter) return 0;
//if(a->anisoFilter != b->anisoFilter) return 0;
if(a->mipmapped != b->mipmapped) return 0;
if(a->noStretch != b->noStretch) return 0;
if(a->gammaCorrection != b->gammaCorrection) return 0;
if(a->toAlpha != b->toAlpha) return 0;
if(a->border != b->border) return 0;
if(a->flags & TSF_HAS_COLORPALETTE_XLAT)
{
colorpalettetranslationspecification_t const *cptA = a->translated;
colorpalettetranslationspecification_t const *cptB = b->translated;
DENG_ASSERT(cptA && cptB);
if(cptA->tClass != cptB->tClass) return 0;
if(cptA->tMap != cptB->tMap) return 0;
}
return 1; // Equal.
}

static int compareDetailVariantSpecifications(detailvariantspecification_t const *a,
detailvariantspecification_t const *b)
{
if(a->contrast != b->contrast) return 0;
return 1; // Equal.
}

#ifdef __CLIENT__

static colorpalettetranslationspecification_t *applyColorPaletteTranslationSpecification(
colorpalettetranslationspecification_t *spec, int tClass, int tMap)
{
Expand Down Expand Up @@ -467,7 +426,7 @@ static texturevariantspecification_t *findVariantSpecification(
// Do we already have a concrete version of the template specification?
for(; node; node = node->next)
{
if(GL_CompareTextureVariantSpecifications(node->spec, &tpl))
if(TextureVariantSpec_Compare(node->spec, &tpl))
return node->spec;
}

Expand Down Expand Up @@ -1130,25 +1089,6 @@ void GL_InitTextureManager()
initedOk = true;
}

#endif // __CLIENT__

int GL_CompareTextureVariantSpecifications(texturevariantspecification_t const *a,
texturevariantspecification_t const *b)
{
DENG_ASSERT(a && b);
if(a == b) return 1;
if(a->type != b->type) return 0;
switch(a->type)
{
case TST_GENERAL: return compareVariantSpecifications(TS_GENERAL(*a), TS_GENERAL(*b));
case TST_DETAIL: return compareDetailVariantSpecifications(TS_DETAIL(*a), TS_DETAIL(*b));
}
Con_Error("GL_CompareTextureVariantSpecifications: Invalid type %i.", (int) a->type);
exit(1); // Unreachable.
}

#ifdef __CLIENT__

void GL_ResetTextureManager()
{
if(!initedOk) return;
Expand Down
3 changes: 1 addition & 2 deletions doomsday/engine/src/resource/materialvariant.cpp
Expand Up @@ -27,7 +27,6 @@
#endif

#include "map/r_world.h" // R_UpdateMapSurfacesOnMaterialChange
#include "gl/gl_texmanager.h" // GL_CompareTextureVariantSpecifications
#include "render/r_main.h" // frameTimePos

#include "resource/materialvariantspec.h"
Expand All @@ -38,7 +37,7 @@ bool MaterialVariantSpec::compare(MaterialVariantSpec const &other) const
{
if(this == &other) return 1;
if(context != other.context) return 0;
return 1 == GL_CompareTextureVariantSpecifications(primarySpec, other.primarySpec);
return 1 == TextureVariantSpec_Compare(primarySpec, other.primarySpec);
}

struct Material::Variant::Instance
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/src/resource/texture.cpp
Expand Up @@ -205,7 +205,7 @@ Texture::Variant *Texture::chooseVariant(ChooseVariantMethod method,
break;

case FuzzyMatchSpec:
if(GL_CompareTextureVariantSpecifications(&cand, &spec))
if(TextureVariantSpec_Compare(&cand, &spec))
{
// This will do fine.
return *i;
Expand Down
51 changes: 51 additions & 0 deletions doomsday/engine/src/resource/texturevariant.cpp
Expand Up @@ -19,6 +19,57 @@

#include "resource/texture.h"

/**
* @todo Magnification, Anisotropic filter level and GL texture wrap modes
* will be handled through dynamic changes to GL's texture environment state.
* Consequently they should be ignored here.
*/
static int compareVariantSpecifications(variantspecification_t const *a,
variantspecification_t const *b)
{
/// @todo We can be a bit cleverer here...
if(a->context != b->context) return 0;
if(a->flags != b->flags) return 0;
if(a->wrapS != b->wrapS || a->wrapT != b->wrapT) return 0;
//if(a->magFilter != b->magFilter) return 0;
//if(a->anisoFilter != b->anisoFilter) return 0;
if(a->mipmapped != b->mipmapped) return 0;
if(a->noStretch != b->noStretch) return 0;
if(a->gammaCorrection != b->gammaCorrection) return 0;
if(a->toAlpha != b->toAlpha) return 0;
if(a->border != b->border) return 0;
if(a->flags & TSF_HAS_COLORPALETTE_XLAT)
{
colorpalettetranslationspecification_t const *cptA = a->translated;
colorpalettetranslationspecification_t const *cptB = b->translated;
DENG_ASSERT(cptA && cptB);
if(cptA->tClass != cptB->tClass) return 0;
if(cptA->tMap != cptB->tMap) return 0;
}
return 1; // Equal.
}

static int compareDetailVariantSpecifications(detailvariantspecification_t const *a,
detailvariantspecification_t const *b)
{
if(a->contrast != b->contrast) return 0;
return 1; // Equal.
}

int TextureVariantSpec_Compare(texturevariantspecification_t const *a,
texturevariantspecification_t const *b)
{
DENG_ASSERT(a && b);
if(a == b) return 1;
if(a->type != b->type) return 0;
switch(a->type)
{
case TST_GENERAL: return compareVariantSpecifications(TS_GENERAL(*a), TS_GENERAL(*b));
case TST_DETAIL: return compareDetailVariantSpecifications(TS_DETAIL(*a), TS_DETAIL(*b));
}
throw de::Error("TextureVariantSpec_Compare", QString("Invalid type %1").arg(a->type));
}

namespace de {

struct Texture::Variant::Instance
Expand Down

0 comments on commit 476ee97

Please sign in to comment.