Skip to content

Commit

Permalink
Refactor: Various texture creation cleanup refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Dec 13, 2012
1 parent c34788b commit d826923
Show file tree
Hide file tree
Showing 12 changed files with 415 additions and 712 deletions.
26 changes: 11 additions & 15 deletions doomsday/engine/include/gl/gl_texmanager.h
Expand Up @@ -181,40 +181,36 @@ boolean GL_UploadTexture(int glFormat, int loadFormat, const uint8_t* pixels,
*
* @return @c true iff successful.
*/
boolean GL_UploadTextureGrayMipmap(int glFormat, int loadFormat, const uint8_t* pixels,
boolean GL_UploadTextureGrayMipmap(int glFormat, int loadFormat, uint8_t const *pixels,
int width, int height, float grayFactor);

/**
* @note Can be rather time-consuming due to forced scaling operations and
* the generation of mipmaps.
*/
void GL_UploadTextureContent(const struct texturecontent_s* content);
void GL_UploadTextureContent(struct texturecontent_s const *content);

uint8_t* GL_LoadImage(struct image_s* img, const char* filePath);
uint8_t* GL_LoadImageStr(struct image_s* img, const ddstring_t* filePath);
uint8_t *GL_LoadImage(struct image_s *img, char const *filePath);
uint8_t *GL_LoadImageStr(struct image_s *img, ddstring_t const *filePath);

TexSource GL_LoadRawTex(struct image_s* image, const rawtex_t* r);
TexSource GL_LoadRawTex(struct image_s *image, rawtex_t const *r);

TexSource GL_LoadExtTexture(struct image_s* image, const char* name, gfxmode_t mode);
TexSource GL_LoadExtTexture(struct image_s *image, char const *name, gfxmode_t mode);

TexSource GL_LoadFlatLump(struct image_s* image, FileHandle* file);
TexSource GL_LoadFlatLump(struct image_s *image, FileHandle *file);

TexSource GL_LoadPatchLump(struct image_s* image, FileHandle* file, int tclass,
TexSource GL_LoadPatchLump(struct image_s *image, FileHandle *file, int tclass,
int tmap, int border);

TexSource GL_LoadDetailTextureLump(struct image_s* image, FileHandle* file);

TexSource GL_LoadPatchComposite(struct image_s* image, Texture* tex);

TexSource GL_LoadPatchCompositeAsSky(struct image_s* image, Texture* tex, boolean zeroMask);
TexSource GL_LoadDetailTextureLump(struct image_s *image, FileHandle *file);

/**
* 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(const texturevariantspecification_t* a,
const texturevariantspecification_t* b);
int GL_CompareTextureVariantSpecifications(texturevariantspecification_t const *a,
texturevariantspecification_t const *b);

/**
* Prepare a TextureVariantSpecification according to usage context. If incomplete
Expand Down
17 changes: 5 additions & 12 deletions doomsday/engine/include/resource/r_data.h
Expand Up @@ -82,20 +82,13 @@ Uri *R_ComposePatchUri(patchid_t id);
/// @return Path for the patch associated with @a id. A zero-length string is
/// returned if the id is invalid/unknown.
AutoStr *R_ComposePatchPath(patchid_t id);

/*
* TODO: Merge/generalize these very similar routines.
*/

struct texture_s *R_CreateSkinTex(Uri const *resourceUri, boolean isShinySkin);
struct texture_s *R_CreateLightmap(Uri const *resourceUri);
struct texture_s *R_CreateFlaremap(Uri const *resourceUri);
struct texture_s *R_CreateReflectionTexture(Uri const *resourceUri);
struct texture_s *R_CreateMaskTexture(Uri const *resourceUri, Size2Raw const *dimensions);
struct texture_s *R_CreateDetailTexture(Uri const *resourceUri);

#ifdef __cplusplus
} // extern "C"
#endif

#ifdef __cplusplus
struct texture_s *R_DefineTexture(de::String schemeName, de::Uri const &resourceUri, QSize const &dimensions);
struct texture_s *R_DefineTexture(de::String schemeName, de::Uri const &resourceUri);
#endif

#endif /// LIBDENG_REFRESH_DATA_H
15 changes: 1 addition & 14 deletions doomsday/engine/include/resource/texture.h
Expand Up @@ -88,22 +88,9 @@ class Texture
public:
/**
* @param manifest Manifest derived to yield the texture.
* @param flags Texture classification flags.
* @param userData User data to associate with the resultant texture.
*/
Texture(TextureManifest &manifest, Flags flags = 0, void *userData = 0);

/**
* @param manifest Manifest derived to yield the Texture.
* @param dimensions World dimensions of the texture in map space
* coordinates. If width=0 and height=0, their value
* will be inferred from the actual pixel dimensions
* of the image resource at load time.
* @param flags Texture classification flags.
* @param userData User data to associate with the resultant texture.
*/
Texture(TextureManifest &manifest, QSize const &dimensions,
Flags flags = 0, void *userData = 0);
Texture(TextureManifest &manifest, void *userData = 0);

~Texture();

Expand Down
67 changes: 44 additions & 23 deletions doomsday/engine/include/resource/texturemanifest.h
Expand Up @@ -47,18 +47,8 @@ class TextureManifest : public PathTree::Node
* Derive a new logical Texture instance by interpreting the manifest.
* The first time a texture is derived from the manifest, said texture
* is assigned to the manifest (ownership is assumed).
*
* @param flags Texture classification flags.
*/
Texture *derive(Texture::Flags flags = 0);

/**
* @copydoc derive()
* @param dimensions Logical dimensions. Components can be @c 0 in which
* case their value will be inherited from the actual
* pixel dimensions of the image at load time.
*/
Texture *derive(QSize const &dimensions, Texture::Flags flags = 0);
Texture *derive();

/**
* Returns the owning scheme of the TextureManifest.
Expand Down Expand Up @@ -107,30 +97,61 @@ class TextureManifest : public PathTree::Node
bool setResourceUri(Uri const &newUri);

/**
* Returns the logical Texture instance associated with the manifest;
* otherwise @c 0.
* Returns the scheme-unique identifier for the manifest.
*/
Texture *texture() const;
int uniqueId() const;

/**
* Change the logical Texture associated with the manifest.
* Change the unique identifier property of the manifest.
*
* @param newTexture New logical Texture to associate.
* @return @c true iff @a newUniqueId differed to the existing unique
* identifier, which was subsequently changed.
*/
void setTexture(Texture *newTexture);
bool setUniqueId(int newUniqueId);

/**
* Returns the scheme-unique identifier for the manifest.
* Returns the logical dimensions property of the manifest.
*/
int uniqueId() const;
QSize const &logicalDimensions() const;

/**
* Change the unique identifier associated with the manifest.
* Change the logical dimensions property of the manifest.
*
* @return @c true iff @a newUniqueId differed to the existing unique
* identifier, which was subsequently changed.
* @param newDimensions New logical dimensions. Components can be @c 0 in
* which case their value will be inherited from the pixel dimensions of
* the image at load time.
*/
bool setUniqueId(int newUniqueId);
bool setLogicalDimensions(QSize const &newDimensions);

/**
* Returns the world origin offset property of the manifest.
*/
QPoint const &origin() const;

/**
* Change the world origin offest property of the manifest.
*
* @param newOrigin New origin offset.
*/
void setOrigin(QPoint const &newOrigin);

/**
* Returns the texture flags property of the manifest.
*/
Texture::Flags &flags();

/**
* Returns the logical Texture instance associated with the manifest;
* otherwise @c 0.
*/
Texture *texture() const;

/**
* Change the logical Texture associated with the manifest.
*
* @param newTexture New logical Texture to associate.
*/
void setTexture(Texture *newTexture);

/// Returns a reference to the application's texture system.
static Textures &textures();
Expand Down
33 changes: 14 additions & 19 deletions doomsday/engine/include/resource/textures.h
Expand Up @@ -72,20 +72,9 @@ class Textures
* Interpret a manifest producing a new logical Texture instance..
*
* @param manifest The manifest to be interpreted.
* @param flags Texture Flags.
* @param userData User data to associate with the resultant texture.
*/
static Texture *interpret(Manifest &manifest, Texture::Flags flags,
void *userData = 0);

/**
* @copydoc interpret()
* @param dimensions Logical dimensions. Components can be @c 0 in
* which case their value will be inherited from the
* actual pixel dimensions of the image at load time.
*/
static Texture *interpret(Manifest &manifest, QSize const &dimensions,
Texture::Flags flags, void *userData = 0);
static Texture *interpret(Manifest &manifest, void *userData = 0);
};

/**
Expand Down Expand Up @@ -193,19 +182,25 @@ class Textures
* Texture which will be defined later. If a manifest with the specified
* @a uri already exists the existing manifest will be returned.
*
* If either the unique id or the @a resourceUri differs from that which
* is already defined in pre-existing manifest, any associated logical
* Texture instance is released (any GL-textures acquired for it).
* If any of the property values (flags, dimensions, etc...) differ from
* that which is already defined in the pre-existing manifest, any texture
* which is currently associated is released (any GL-textures acquired for
* it are deleted).
*
* @param uri Uri representing a path to the texture in the
* virtual hierarchy.
* @param uniqueId Scheme-unique identifier to associate with the
* texture.
* @param resourceUri Uri to the associated data resource.
*
* @param flags Texture flags property.
* @param dimensions Logical dimensions property.
* @param origin World origin offset property.
* @param uniqueId Unique identifier property.
* @param resourceUri Resource URI property.
*
* @return Manifest for this URI; otherwise @c 0 if @a uri is invalid.
*/
Manifest *declare(Uri const &uri, int uniqueId, Uri const *resourceUri);
Manifest *declare(Uri const &uri, de::Texture::Flags flags,
QSize const &dimensions, QPoint const &origin, int uniqueId,
de::Uri const *resourceUri = 0);

/**
* Iterate over defined Textures in the collection making a callback for
Expand Down
93 changes: 73 additions & 20 deletions doomsday/engine/src/def_main.cpp
Expand Up @@ -967,10 +967,10 @@ static int generateMaterialDefForCompositeTexture(de::TextureManifest &manifest,

if(de::Texture *tex = manifest.texture())
{
de::CompositeTexture* pcTex = reinterpret_cast<de::CompositeTexture *>(tex->userDataPointer());
DENG_ASSERT(pcTex);
mat->width = tex->width();
mat->height = tex->height();
de::CompositeTexture* pcTex = reinterpret_cast<de::CompositeTexture *>(tex->userDataPointer());
DENG_ASSERT(pcTex);
mat->flags = (pcTex->flags().testFlag(de::CompositeTexture::NoDraw)? MATF_NO_DRAW : 0);
}
#if _DEBUG
Expand Down Expand Up @@ -1418,6 +1418,36 @@ static void initAnimGroup(ded_group_t* def)
}
}

static void defineFlaremap(uri_s const *_resourceUri)
{
if(!_resourceUri) return;
de::Uri const &resourceUri = reinterpret_cast<de::Uri const &>(*_resourceUri);
if(resourceUri.isEmpty()) return;

// Reference to none?
if(!resourceUri.path().toStringRef().compareWithoutCase("-")) return;

// Reference to a "built-in" flaremap?
de::String const &resourcePathStr = resourceUri.path().toStringRef();
if(resourcePathStr.length() == 1 &&
resourcePathStr.first() >= '0' && resourcePathStr.first() <= '4')
return;

R_DefineTexture("Flaremaps", resourceUri);
}

static void defineLightmap(uri_s const *_resourceUri)
{
if(!_resourceUri) return;
de::Uri const &resourceUri = reinterpret_cast<de::Uri const &>(*_resourceUri);
if(resourceUri.isEmpty()) return;

// Reference to none?
if(!resourceUri.path().toStringRef().compareWithoutCase("-")) return;

R_DefineTexture("Lightmaps", resourceUri);
}

void Def_PostInit(void)
{
char name[40];
Expand Down Expand Up @@ -1462,8 +1492,7 @@ void Def_PostInit(void)
{
ded_detailtexture_t *dtl = &defs.details[i];
if(!dtl->detailTex) continue;

R_CreateDetailTexture(dtl->detailTex);
R_DefineTexture("Details", reinterpret_cast<de::Uri &>(*dtl->detailTex));
}

// Lights.
Expand All @@ -1473,11 +1502,22 @@ void Def_PostInit(void)
{
ded_light_t* lig = &defs.lights[i];

R_CreateLightmap(lig->up);
R_CreateLightmap(lig->down);
R_CreateLightmap(lig->sides);

R_CreateFlaremap(lig->flare);
if(lig->up)
{
defineLightmap(lig->up);
}
if(lig->down)
{
defineLightmap(lig->down);
}
if(lig->sides)
{
defineLightmap(lig->sides);
}
if(lig->flare)
{
defineFlaremap(lig->flare);
}
}

for(int i = 0; i < defs.count.decorations.num; ++i)
Expand All @@ -1490,11 +1530,22 @@ void Def_PostInit(void)

if(!R_IsValidLightDecoration(lig)) break;

R_CreateLightmap(lig->up);
R_CreateLightmap(lig->down);
R_CreateLightmap(lig->sides);

R_CreateFlaremap(lig->flare);
if(lig->up)
{
defineLightmap(lig->up);
}
if(lig->down)
{
defineLightmap(lig->down);
}
if(lig->sides)
{
defineLightmap(lig->sides);
}
if(lig->flare)
{
defineFlaremap(lig->flare);
}
}
}

Expand All @@ -1504,13 +1555,15 @@ void Def_PostInit(void)
for(int i = 0; i < defs.count.reflections.num; ++i)
{
ded_reflection_t* ref = &defs.reflections[i];
Size2Raw size;

R_CreateReflectionTexture(ref->shinyMap);

size.width = ref->maskWidth;
size.height = ref->maskHeight;
R_CreateMaskTexture(ref->maskMap, &size);
if(ref->shinyMap)
{
R_DefineTexture("Reflections", reinterpret_cast<de::Uri &>(*ref->shinyMap));
}
if(ref->maskMap)
{
R_DefineTexture("Masks", reinterpret_cast<de::Uri &>(*ref->maskMap), QSize(ref->maskWidth, ref->maskHeight));
}
}

// Animation groups.
Expand Down

0 comments on commit d826923

Please sign in to comment.