Skip to content

Commit

Permalink
Refactor|Material: Relocated DetailLayerState and ShinyLayerState to …
Browse files Browse the repository at this point in the history
…Material::Variant
  • Loading branch information
danij-deng committed Jan 22, 2013
1 parent cbb37ed commit f86491d
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 226 deletions.
219 changes: 113 additions & 106 deletions doomsday/client/include/resource/material.h
Expand Up @@ -112,6 +112,48 @@ class Material : public de::MapElement
float inter;
};

/// @todo Much of this does not belong here, these values should be
/// interpolated by MaterialSnapshot.
struct DetailLayerState
{
/// The details texture.
de::Texture *texture;

/// Scaling factor [0..1] (for both axes).
float scale;

/// Strength multiplier [0..1].
float strength;

DetailLayerState() : texture(0), scale(0), strength(0) {}
};

/// @todo Much of this does not belong here, these values should be
/// interpolated by MaterialSnapshot.
struct ShineLayerState
{
/// The shine texture.
de::Texture *texture;

/// The mask texture (if any).
de::Texture *maskTexture;

/// Texture blendmode for the shine texture.
blendmode_t blendmode;

/// Strength multiplier [0..1].
float strength;

/// Minimum sector color (RGB).
float minColor[3];

ShineLayerState()
: texture(0), maskTexture(0), blendmode(blendmode_t(0)), strength(0)
{
std::memset(minColor, 0, sizeof(minColor));
}
};

private:
/**
* @param generalCase Material from which this variant is derived.
Expand Down Expand Up @@ -198,6 +240,77 @@ class Material : public de::MapElement
friend class Material;
friend struct Material::Instance;

public:
/*
* Here follows methods awaiting cleanup/redesign/removal.
*/

/**
* Provides access to the detail texturing layer state.
*
* @throws UnknownLayerError if the material has no details layer.
*
* @see Material::isDetailed()
*/
DetailLayerState const &detailLayer() const;

/**
* Change the detail texture linked to this.
* @param tex Texture to be linked with.
*/
void setDetailTexture(de::Texture *tex);

/**
* Change the detail texture strength factor for this.
* @param strength New strength value (will be clamped to [0..1]).
*/
void setDetailStrength(float strength);

/**
* Change the detail texture scale factor for this.
* @param scale New scale value (will be clamped to [0..1]).
*/
void setDetailScale(float scale);

/**
* Provides access to the shine texturing layer state.
*
* @throws UnknownLayerError if the material has no shiny layer.
*
* @see Material::isShiny()
*/
ShineLayerState const &shineLayer() const;

/**
* Change the Shiny Texture linked to this.
* @param tex Texture to be linked with.
*/
void setShinyTexture(de::Texture *tex);

/**
* Change the material's linked shiny mask texture.
* @param tex Texture to be linked with.
*/
void setShinyMaskTexture(de::Texture *tex);

/**
* Change the Shiny Texture blendmode for this.
* @param blendmode New blendmode value.
*/
void setShinyBlendmode(blendmode_t blendmode);

/**
* Change the Shiny Texture strength factor for this.
* @param strength New strength value (will be clamped to [0..1]).
*/
void setShinyStrength(float strength);

/**
* Change the Shiny Texture minColor for this.
* @param colorRGB New RGB color values (each component will be clamped to [0..1]).
*/
void setShinyMinColor(float const colorRGB[3]);

private:
struct Instance;
Instance *d;
Expand Down Expand Up @@ -243,46 +356,6 @@ class Material : public de::MapElement
Stages stages_;
};

/// @todo Does not belong here - relocate to Variant.
struct DetailLayerState
{
/// The details texture.
de::Texture *texture;

/// Scaling factor [0..1] (for both axes).
float scale;

/// Strength multiplier [0..1].
float strength;

DetailLayerState() : texture(0), scale(0), strength(0) {}
};

/// @todo Does not belong here - relocate to Variant.
struct ShineLayerState
{
/// The shine texture.
de::Texture *texture;

/// The mask texture (if any).
de::Texture *maskTexture;

/// Texture blendmode for the shine texture.
blendmode_t blendmode;

/// Strength multiplier [0..1].
float strength;

/// Minimum sector color (RGB).
float minColor[3];

ShineLayerState()
: texture(0), maskTexture(0), blendmode(blendmode_t(0)), strength(0)
{
std::memset(minColor, 0, sizeof(minColor));
}
};

/// A list of layers.
typedef QList<Material::Layer *> Layers;

Expand Down Expand Up @@ -573,72 +646,6 @@ class Material : public de::MapElement
* Here follows methods awaiting cleanup/redesign/removal.
*/

/**
* Provides access to the detail texturing layer state.
*
* @throws UnknownLayerError if the material has no details layer.
*
* @see isDetailed()
*/
DetailLayerState const &detailLayer() const;

/**
* Change the detail texture linked to this.
* @param tex Texture to be linked with.
*/
void setDetailTexture(de::Texture *tex);

/**
* Change the detail texture strength factor for this.
* @param strength New strength value (will be clamped to [0..1]).
*/
void setDetailStrength(float strength);

/**
* Change the detail texture scale factor for this.
* @param scale New scale value (will be clamped to [0..1]).
*/
void setDetailScale(float scale);

/**
* Provides access to the shine texturing layer state.
*
* @throws UnknownLayerError if the material has no shiny layer.
*
* @see isShiny()
*/
ShineLayerState const &shineLayer() const;

/**
* Change the Shiny Texture linked to this.
* @param tex Texture to be linked with.
*/
void setShinyTexture(de::Texture *tex);

/**
* Change the material's linked shiny mask texture.
* @param tex Texture to be linked with.
*/
void setShinyMaskTexture(de::Texture *tex);

/**
* Change the Shiny Texture blendmode for this.
* @param blendmode New blendmode value.
*/
void setShinyBlendmode(blendmode_t blendmode);

/**
* Change the Shiny Texture strength factor for this.
* @param strength New strength value (will be clamped to [0..1]).
*/
void setShinyStrength(float strength);

/**
* Change the Shiny Texture minColor for this.
* @param colorRGB New RGB color values (each component will be clamped to [0..1]).
*/
void setShinyMinColor(float const colorRGB[3]);

/**
* Returns @c true if the material is marked as "autogenerated".
*/
Expand Down
7 changes: 1 addition & 6 deletions doomsday/client/src/def_main.cpp
Expand Up @@ -1024,14 +1024,9 @@ static void generateMaterialDefs()

static void updateMaterialFromDef(Material &material, ded_material_t &def)
{
material.setDefinition(&def);
// Textures are updated automatically at prepare-time, so just clear them.
material.setDetailTexture(0);
material.setShinyTexture(0);
material.setShinyMaskTexture(0);

MaterialManifest &manifest = material.manifest();

material.setDefinition(&def);
material.setFlags(def.flags);
material.setDimensions(QSize(def.width, def.height));
material.setAudioEnvironment(S_AudioEnvironmentForMaterial(def.uri));
Expand Down
78 changes: 4 additions & 74 deletions doomsday/client/src/resource/material.cpp
Expand Up @@ -121,12 +121,6 @@ struct Material::Instance
/// @see materialFlags
short flags;

/// Detail texturing layer.
Material::DetailLayerState detailLayer;

/// Shine texturing layer.
Material::ShineLayerState shineLayer;

/// Layers.
Material::Layers layers;

Expand Down Expand Up @@ -279,14 +273,14 @@ bool Material::isAnimated() const

bool Material::isDetailed() const
{
/// @todo fixme: Do not determine this from the layer state.
return !!d->detailLayer.texture;
/// @todo fixme: Determine this from our own configuration.
return false;
}

bool Material::isShiny() const
{
/// @todo fixme: Do not determine this from the layer state.
return !!d->shineLayer.texture;
/// @todo fixme: Determine this from our own configuration.
return false;
}

bool Material::isSkyMasked() const
Expand Down Expand Up @@ -332,70 +326,6 @@ void Material::setAudioEnvironment(AudioEnvironmentClass envClass)
d->envClass = envClass;
}

Material::DetailLayerState const &Material::detailLayer() const
{
if(isDetailed())
{
return d->detailLayer;
}
/// @throw UnknownLayerError The material has no details layer.
throw UnknownLayerError("Material::detailLayer", "Material has no details layer");
}

void Material::setDetailTexture(Texture *tex)
{
d->detailLayer.texture = tex;
}

void Material::setDetailStrength(float strength)
{
d->detailLayer.strength = MINMAX_OF(0, strength, 1);
}

void Material::setDetailScale(float scale)
{
d->detailLayer.scale = MINMAX_OF(0, scale, 1);
}

Material::ShineLayerState const &Material::shineLayer() const
{
if(isShiny())
{
return d->shineLayer;
}
/// @throw UnknownLayerError The material has no shine layer.
throw UnknownLayerError("Material::shineLayer", "Material has no shine layer");
}

void Material::setShinyTexture(Texture *tex)
{
d->shineLayer.texture = tex;
}

void Material::setShinyMaskTexture(Texture *tex)
{
d->shineLayer.maskTexture = tex;
}

void Material::setShinyBlendmode(blendmode_t blendmode)
{
DENG2_ASSERT(VALID_BLENDMODE(blendmode));
d->shineLayer.blendmode = blendmode;
}

void Material::setShinyMinColor(float const colorRGB[3])
{
DENG2_ASSERT(colorRGB);
d->shineLayer.minColor[CR] = MINMAX_OF(0, colorRGB[CR], 1);
d->shineLayer.minColor[CG] = MINMAX_OF(0, colorRGB[CG], 1);
d->shineLayer.minColor[CB] = MINMAX_OF(0, colorRGB[CB], 1);
}

void Material::setShinyStrength(float strength)
{
d->shineLayer.strength = MINMAX_OF(0, strength, 1);
}

int Material::layerCount() const
{
return d->layers.count();
Expand Down

0 comments on commit f86491d

Please sign in to comment.