Added derivative textures

This commit is contained in:
Josh Yelon 2005-10-05 16:25:02 +00:00
parent 8f74f5eaaf
commit 9478e2bf08
6 changed files with 230 additions and 166 deletions

View File

@ -362,6 +362,13 @@ update_shader_texture_bindings(CLP(ShaderContext) *prev, GSG *gsg)
TextureStage *stage = gsg->_target._texture->get_on_stage(_cg_texbind[i].stage);
tex = gsg->_target._texture->get_on_texture(stage);
}
if (_cg_texbind[i].suffix != 0) {
// The suffix feature is inefficient. It is a temporary hack.
if (tex == 0) {
continue;
}
tex = tex->load_related(_cg_texbind[i].suffix);
}
if ((tex == 0) || (tex->get_texture_type() != _cg_texbind[i].desiredtype)) {
continue;
}
@ -824,11 +831,14 @@ compile_cg_parameter(CGparameter p)
}
if (pieces[0] == "tex") {
if ((!errchk_cg_parameter_words(p,2)) ||
(!errchk_cg_parameter_direction(p, CG_IN)) ||
if ((!errchk_cg_parameter_direction(p, CG_IN)) ||
(!errchk_cg_parameter_variance(p, CG_UNIFORM)) ||
(!errchk_cg_parameter_sampler(p)))
return false;
if ((pieces.size() != 2)&&(pieces.size() != 3)) {
errchk_cg_output(p, "Invalid parameter name");
return false;
}
ShaderTexBind bind;
bind.parameter = p;
bind.name = 0;
@ -842,6 +852,9 @@ compile_cg_parameter(CGparameter p)
errchk_cg_output(p, "Invalid type for a tex-parameter");
return false;
}
if (pieces.size()==3) {
bind.suffix = InternalName::make(((string)"-") + pieces[2]);
}
_cg_texbind.push_back(bind);
return true;
}

View File

@ -65,6 +65,7 @@ private:
PT(InternalName) name;
int stage;
int desiredtype;
PT(InternalName) suffix;
};
struct ShaderTransBind {
CGparameter parameter;

View File

@ -750,6 +750,45 @@ store(PNMImage &pnmimage, int z) const {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: Texture::load_related
// Access: Published
// Description: Loads a texture whose filename is derived by
// concatenating a suffix to the filename of this
// texture. May return NULL, for example, if this
// texture doesn't have a filename.
////////////////////////////////////////////////////////////////////
Texture *Texture::
load_related(const PT(InternalName) &suffix) const {
RelatedTextures::const_iterator ti;
ti = _related_textures.find(suffix);
if (ti != _related_textures.end()) {
return (*ti).second;
}
if (!has_fullpath()) {
return (Texture*)NULL;
}
Filename main = get_fullpath();
main.set_basename_wo_extension(main.get_basename_wo_extension() +
suffix->get_name());
Texture *res;
if (has_alpha_fullpath()) {
Filename alph = get_alpha_fullpath();
alph.set_basename_wo_extension(alph.get_basename_wo_extension() +
suffix->get_name());
res = TexturePool::load_texture(main, alph,
_primary_file_num_channels,
_alpha_file_channel);
} else {
res = TexturePool::load_texture(main,
_primary_file_num_channels);
}
// I'm casting away the const-ness of 'this' because this
// field is only a cache.
((Texture *)this)->_related_textures.insert(RelatedTextures::value_type(suffix, res));
return res;
}
////////////////////////////////////////////////////////////////////
// Function: Texture::set_wrap_u
// Access: Published

View File

@ -24,6 +24,7 @@
#include "filename.h"
#include "typedWritableReferenceCount.h"
#include "namable.h"
#include "internalName.h"
#include "graphicsStateGuardianBase.h"
#include "pmap.h"
@ -181,6 +182,8 @@ PUBLISHED:
virtual bool load(const PNMImage &pnmimage, int z = 0);
bool store(PNMImage &pnmimage, int z = 0) const;
Texture *load_related(const PT(InternalName) &suffix) const;
INLINE bool has_filename() const;
INLINE const Filename &get_filename() const;
INLINE bool has_alpha_filename() const;
@ -353,6 +356,14 @@ protected:
typedef pmap<PreparedGraphicsObjects *, TextureContext *> Contexts;
Contexts _contexts;
// It is common, when using normal maps, specular maps, gloss maps,
// and such, to use a file naming convention where the filenames
// of the special maps are derived by concatenating a suffix to
// the name of the diffuse map. The following table enables
// lookup of the special maps given the diffuse map and the suffix.
typedef pmap<PT(InternalName), PT(Texture)> RelatedTextures;
RelatedTextures _related_textures;
// This value represents the intersection of all the dirty flags of
// the various TextureContexts that might be associated with this
// texture.