Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactor: Replace texture namespace implementation with PathDirectory
Texture names are now represented as Uri within the collection itself.
Names are no longer limited to eight characters and a directory hierarchy
may be defined within each namespace.

Statistical information useful for analyzing efficency of the texture
namespace hashes can be retrieved in _DEBUG builds using ccmd texturestats
  • Loading branch information
danij-deng committed Oct 31, 2011
1 parent 66e5870 commit fb38b39
Show file tree
Hide file tree
Showing 23 changed files with 1,041 additions and 622 deletions.
2 changes: 1 addition & 1 deletion doomsday/engine/api/dd_share.h
Expand Up @@ -1080,7 +1080,7 @@ typedef enum {
#define TEXTURENAMESPACE_COUNT (\
TEXTURENAMESPACE_LAST + 1 - TEXTURENAMESPACE_FIRST )

#define VALID_TEXTURENAMESPACE(id) (\
#define VALID_TEXTURENAMESPACEID(id) (\
(id) >= TEXTURENAMESPACE_FIRST && (id) <= TEXTURENAMESPACE_LAST)

/**
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/api/doomsday.def
Expand Up @@ -506,8 +506,8 @@ EXPORTS
GL_GrabScreen @109 NONAME
GL_SetFilter @132 NONAME
GL_SetFilterColor @441 NONAME
GL_TextureIndexForUri @438 NONAME
GL_TextureIndexForUri2 @501 NONAME
Textures_TypeIndexForUri @438 NONAME
Textures_TypeIndexForUri2 @501 NONAME

GL_ConfigureBorderedProjection @507 NONAME
GL_ConfigureBorderedProjection2 @508 NONAME
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/api/doomsday.h
Expand Up @@ -439,8 +439,8 @@ void GL_ConfigureBorderedProjection(borderedprojectionstate_t* bp, int flags, in
void GL_BeginBorderedProjection(borderedprojectionstate_t* bp);
void GL_EndBorderedProjection(borderedprojectionstate_t* bp);

uint GL_TextureIndexForUri(const Uri* uri);
uint GL_TextureIndexForUri2(const Uri* uri, boolean silent);
uint Textures_TypeIndexForUri(const Uri* uri);
uint Textures_TypeIndexForUri2(const Uri* uri, boolean silent);

//------------------------------------------------------------------------
//
Expand Down
3 changes: 3 additions & 0 deletions doomsday/engine/data/cphelp.txt
Expand Up @@ -400,6 +400,9 @@ desc = List all known surface materials.
[listmobjtypes]
desc = List all known mobj types.

[listtextures]
desc = List all known textures.

[listvars]
desc = List all console variables and their values.

Expand Down
69 changes: 38 additions & 31 deletions doomsday/engine/portable/include/gl_texmanager.h
Expand Up @@ -36,16 +36,19 @@
#include "gl_defer.h"
#include "texturevariantspecification.h"

#define TEXQ_BEST 8
#define MINTEXWIDTH 8
#define MINTEXHEIGHT 8

struct image_s;
struct texturecontent_s;
struct texture_s;
struct texturevariant_s;
struct texturevariantspecification_s;

#define TEXQ_BEST 8
#define MINTEXWIDTH 8
#define MINTEXHEIGHT 8

/// Components within a Texture path hierarchy are delimited by this character.
#define TEXTUREDIRECTORY_DELIMITER '/'

extern int ratioLimit;
extern int mipmapping, filterUI, texQuality, filterSprites;
extern int texMagMode, texAniso;
Expand Down Expand Up @@ -313,12 +316,6 @@ void GL_PrintTextureVariantSpecification(const texturevariantspecification_t* sp

void GL_ReleaseGLTexturesForTexture(struct texture_s* tex);

/**
* Given a texture identifier retrieve the associated texture.
* @return Found Texture object else @c NULL
*/
struct texture_s* GL_ToTexture(textureid_t id);

/// Result of a request to prepare a TextureVariant
typedef enum {
PTR_NOTFOUND = 0, /// Failed. No suitable variant could be found/prepared.
Expand All @@ -345,38 +342,48 @@ typedef enum {
*
* @return GL-name of the prepared variant if successful else @c 0
*/
DGLuint GL_PrepareTexture2(struct texture_s* tex,
texturevariantspecification_t* spec, preparetextureresult_t* returnOutcome);
DGLuint GL_PrepareTexture(struct texture_s* tex,
texturevariantspecification_t* spec);
DGLuint GL_PrepareTexture2(struct texture_s* tex, texturevariantspecification_t* spec, preparetextureresult_t* returnOutcome);
DGLuint GL_PrepareTexture(struct texture_s* tex, texturevariantspecification_t* spec); /* returnOutcome=NULL */

/**
* Same as GL_PrepareTexture(2) except for visibility of TextureVariant.
* \todo Should not need to be public.
*/
const struct texturevariant_s* GL_PrepareTextureVariant2(struct texture_s* tex,
texturevariantspecification_t* spec, preparetextureresult_t* returnOutcome);
const struct texturevariant_s* GL_PrepareTextureVariant(struct texture_s* tex,
texturevariantspecification_t* spec);
const struct texturevariant_s* GL_PrepareTextureVariant2(struct texture_s* tex, texturevariantspecification_t* spec, preparetextureresult_t* returnOutcome);
const struct texturevariant_s* GL_PrepareTextureVariant(struct texture_s* tex, texturevariantspecification_t* spec); /* returnOutcome=NULL*/

const struct texture_s* GL_CreateTexture2(const char* name, uint index,
texturenamespaceid_t texNamespace, int width, int height);
const struct texture_s* GL_CreateTexture(const char* name, uint index,
texturenamespaceid_t texNamespace);
/// @return Number of unique Textures in the collection.
uint Textures_Count(void);

const struct texture_s* GL_TextureByUri2(const Uri* uri, boolean silent);
const struct texture_s* GL_TextureByUri(const Uri* uri);
const struct texture_s* GL_TextureByIndex(int index, texturenamespaceid_t texNamespace);
/// @return Texture associated with unique identifier @a textureNum else @c NULL.
struct texture_s* Textures_ToTexture(textureid_t textureNum);

uint GL_TextureIndexForUri2(const Uri* uri, boolean silent);
uint GL_TextureIndexForUri(const Uri* uri);
/// @return Unique identifier associated with @a material else @c 0.
textureid_t Textures_ToTextureNum(struct texture_s* texture);

/**
* Given a Texture construct a new Uri reference to it.
* \todo Do not construct. Store into a resource namespace and return a reference.
* @return Associated Uri.
* Search the Textures collection for a Texture associated with @a uri.
* @return Found Texture else @c NULL.
*/
Uri* GL_NewUriForTexture(struct texture_s* tex);
struct texture_s* Textures_TextureForUri2(const Uri* uri, boolean quiet);
struct texture_s* Textures_TextureForUri(const Uri* uri); /* quiet=false */

/// Same as Textures::TextureForUri except @a uri is a C-string.
struct texture_s* Textures_TextureForUriCString2(const char* uri, boolean quiet);
struct texture_s* Textures_TextureForUriCString(const char* uri); /*quiet=!(verbose >= 1)*/

/// @return Unique name/path-to @a Texture. Must be destroyed with Uri_Delete().
Uri* Textures_ComposeUri(struct texture_s* texture);

struct texture_s* Textures_TextureForTypeIndex(int index, texturenamespaceid_t texNamespace);

uint Textures_TypeIndexForUri2(const Uri* uri, boolean quiet);
uint Textures_TypeIndexForUri(const Uri* uri); /* quiet=false */

texturenamespaceid_t Textures_NamespaceId(const struct texture_s* tex);

struct texture_s* Textures_CreateWithDimensions(const Uri* uri, uint typeIndex, int width, int height);
struct texture_s* Textures_Create(const Uri* uri, uint typeIndex); /* width=0, height=0*/

/**
* Change the GL minification filter for all prepared TextureVariants.
Expand Down
8 changes: 3 additions & 5 deletions doomsday/engine/portable/include/pathdirectory.h
Expand Up @@ -154,12 +154,10 @@ pathdirectory_search_t* PathDirectory_Search(pathdirectory_t* pd);
*
* @param path New path to add to the directory.
* @param delimiter Fragments of the path are delimited by this character.
* @param value Associated data value.
* @param userData User data to associate with the new path.
*/
struct pathdirectory_node_s* PathDirectory_Insert2(pathdirectory_t* pd,
const char* path, char delimiter, void* value);
struct pathdirectory_node_s* PathDirectory_Insert(pathdirectory_t* pd,
const char* path, char delimiter);
struct pathdirectory_node_s* PathDirectory_Insert2(pathdirectory_t* pd, const char* path, char delimiter, void* userData);
struct pathdirectory_node_s* PathDirectory_Insert(pathdirectory_t* pd, const char* path, char delimiter); /*userData = NULL*/

/**
* Iterate over nodes in the directory making a callback for each.
Expand Down
34 changes: 15 additions & 19 deletions doomsday/engine/portable/include/texture.h
Expand Up @@ -26,7 +26,7 @@
#define LIBDENG_GL_TEXTURE_H

struct texturevariant_s;
struct texturenamespace_namehash_node_s;
struct pathdirectory_node_s;

typedef enum {
TEXTURE_ANALYSIS_FIRST = 0,
Expand Down Expand Up @@ -56,24 +56,19 @@ typedef struct texture_s {
/// Dimensions in logical pixels (not necessarily the same as pixel dimensions).
int _width, _height;

/// Unique Texture Namespace Identifier.
/// \todo make external.
texturenamespaceid_t _texNamespace;
struct texturenamespace_namehash_node_s* _texNamespaceHashNode;
/// Pointer to this texture's node in the directory.
struct pathdirectory_node_s* _directoryNode;

/// List of variants (e.g., color translations).
struct texture_variantlist_node_s* _variants;

/// Table of analyses object ptrs, used for various purposes depending
/// on the variant specification.
void* _analyses[TEXTURE_ANALYSIS_COUNT];

/// Symbolic name.
char _name[9];
} texture_t;

texture_t* Texture_New(textureid_t id, const char name[9], int index);
texture_t* Texture_NewWithDimensions(textureid_t id, const char name[9], int index, int width, int height);
texture_t* Texture_New(textureid_t id, struct pathdirectory_node_s* directoryNode, int index);
texture_t* Texture_NewWithDimensions(textureid_t id, struct pathdirectory_node_s* directoryNode, int index, int width, int height);

void Texture_Delete(texture_t* tex);

Expand Down Expand Up @@ -124,9 +119,6 @@ void* Texture_Analysis(const texture_t* tex, texture_analysisid_t analysis);
/// @return Unique identifier.
textureid_t Texture_Id(const texture_t* tex);

/// @return Symbolic name.
const char* Texture_Name(const texture_t* tex);

/// @return @c true iff Texture represents an image loaded from an IWAD.
boolean Texture_IsFromIWAD(const texture_t* tex);

Expand Down Expand Up @@ -161,12 +153,16 @@ void Texture_SetHeight(texture_t* tex, int height);
/// @return Type-specific index of the wrapped image object.
int Texture_TypeIndex(const texture_t* tex);

/// @return Texture namespace identifier.
texturenamespaceid_t Texture_Namespace(const texture_t* tex);
/// @return PathDirectory node associated with this.
struct pathdirectory_node_s* Texture_DirectoryNode(const texture_t* texture);

/// @return Unique identifier of the namespace within which this Texture resides.
texturenamespaceid_t Textures_NamespaceId(const texture_t* texture);

/// @return Symbolic name/path-to this Texture. Must be destroyed with Str_Delete().
ddstring_t* Texture_ComposePath(const texture_t* texture);

/// @return Texture namespace hash node.
struct texturenamespace_namehash_node_s* Texture_NamespaceHashNode(const texture_t* tex);
/// @return Fully qualified/absolute Uri to this Texture. Must be destroyed with Uri_Delete().
Uri* Texture_ComposeUri(const texture_t* texture);

void Texture_SetNamespace(texture_t* tex, texturenamespaceid_t texNamespace,
struct texturenamespace_namehash_node_s* texNamespaceHashNode);
#endif /* LIBDENG_GL_TEXTURE_H */
12 changes: 6 additions & 6 deletions doomsday/engine/portable/src/def_main.c
Expand Up @@ -918,7 +918,7 @@ void Def_GenerateAutoMaterials(void)

if(0 == pcomTex->texId)
continue;
tex = GL_ToTexture(pcomTex->texId);
tex = Textures_ToTexture(pcomTex->texId);

idx = DED_AddMaterial(&defs, NULL);
mat = &defs.materials[idx];
Expand All @@ -932,7 +932,7 @@ void Def_GenerateAutoMaterials(void)

stage = DED_AddMaterialLayerStage(&mat->layers[0]);
st = &mat->layers[0].stages[stage];
st->texture = GL_NewUriForTexture(tex);
st->texture = Textures_ComposeUri(tex);
}}

// Flats.
Expand All @@ -947,7 +947,7 @@ void Def_GenerateAutoMaterials(void)

if(0 == flatTex->texId)
continue;
tex = GL_ToTexture(flatTex->texId);
tex = Textures_ToTexture(flatTex->texId);

idx = DED_AddMaterial(&defs, NULL);
mat = &defs.materials[idx];
Expand All @@ -960,7 +960,7 @@ void Def_GenerateAutoMaterials(void)

stage = DED_AddMaterialLayerStage(&mat->layers[0]);
st = &mat->layers[0].stages[stage];
st->texture = GL_NewUriForTexture(tex);
st->texture = Textures_ComposeUri(tex);
}}

// Sprites.
Expand All @@ -975,7 +975,7 @@ void Def_GenerateAutoMaterials(void)

if(0 == sprTex->texId)
continue;
tex = GL_ToTexture(sprTex->texId);
tex = Textures_ToTexture(sprTex->texId);

idx = DED_AddMaterial(&defs, NULL);
mat = &defs.materials[idx];
Expand All @@ -988,7 +988,7 @@ void Def_GenerateAutoMaterials(void)

stage = DED_AddMaterialLayerStage(&mat->layers[0]);
st = &mat->layers[0].stages[stage];
st->texture = GL_NewUriForTexture(tex);
st->texture = Textures_ComposeUri(tex);
st->texOrigin[0] = sprTex->offX;
st->texOrigin[1] = sprTex->offY;
}}
Expand Down
31 changes: 17 additions & 14 deletions doomsday/engine/portable/src/fonts.c
Expand Up @@ -943,18 +943,18 @@ void Fonts_CharDimensions(font_t* font, int* width, int* height, unsigned char c

static void printFontInfo(const fontbind_t* fb, boolean printNamespace)
{
int numDigits = M_NumDigits(Fonts_Count());
int numDigits = MAX_OF(3/*uid*/, M_NumDigits(Fonts_Count()));
font_t* font = FontBind_Font(fb);
ddstring_t* path = FontBind_ComposePath(fb);
Uri* uri = Fonts_ComposeUri(font);
const ddstring_t* path = (printNamespace? Uri_ToString(uri) : Uri_Path(uri));

Con_Printf(" %*u: \"", numDigits, (unsigned int) Fonts_ToFontNum(font));
if(printNamespace)
Con_Printf("%s:", Str_Text(nameForFontNamespaceId(FontBind_NamespaceId(fb))));
Con_Printf(" %*u: %-*s %s", numDigits, (unsigned int) Fonts_ToFontNum(font),
printNamespace? 22 : 14, F_PrettyPath(Str_Text(path)),
Font_Type(font) == FT_BITMAP? "bitmap" : "bitmap_composite");

Con_Printf("%s\" %s ", Str_Text(path), Font_Type(font) == FT_BITMAP? "bitmap" : "bitmap_composite");
if(Font_IsPrepared(font))
{
Con_Printf("(ascent:%i, descent:%i, leading:%i", Fonts_Ascent(font), Fonts_Descent(font), Fonts_Leading(font));
Con_Printf(" (ascent:%i, descent:%i, leading:%i", Fonts_Ascent(font), Fonts_Descent(font), Fonts_Leading(font));
if(Font_Type(font) == FT_BITMAP && BitmapFont_GLTextureName(font))
{
Con_Printf(", texWidth:%i, texHeight:%i", BitmapFont_TextureWidth(font), BitmapFont_TextureHeight(font));
Expand All @@ -966,7 +966,9 @@ static void printFontInfo(const fontbind_t* fb, boolean printNamespace)
Con_Printf("\n");
}

Str_Delete(path);
Uri_Delete(uri);
if(printNamespace)
Str_Delete((ddstring_t*)path);
}

/**
Expand Down Expand Up @@ -1067,10 +1069,11 @@ static int compareFontBindByPath(const void* fbA, const void* fbB)
static size_t printFonts2(fontnamespaceid_t namespaceId, const char* like,
boolean printNamespace)
{
int numDigits = M_NumDigits(Fonts_Count());
int count = 0;
int numDigits, count = 0;
fontbind_t** foundFonts = collectFonts(namespaceId, like, &count, NULL);

if(!foundFonts) return 0;

if(!printNamespace)
Con_FPrintf(CPF_YELLOW, "Known fonts in namespace '%s'", Str_Text(nameForFontNamespaceId(namespaceId)));
else // Any namespace.
Expand All @@ -1080,11 +1083,11 @@ static size_t printFonts2(fontnamespaceid_t namespaceId, const char* like,
Con_FPrintf(CPF_YELLOW, " like \"%s\"", like);
Con_FPrintf(CPF_YELLOW, ":\n");

if(!foundFonts)
return 0;

// Print the result index key.
Con_Printf(" uid: \"%s\" font-type", VALID_FONTNAMESPACEID(namespaceId)? "font-name" : "<namespace>:font-name");
numDigits = MAX_OF(3/*uid*/, M_NumDigits(Fonts_Count()));
Con_Printf(" %*s: %-*s type", numDigits, "uid",
printNamespace? 22 : 14, printNamespace? "namespace:path" : "path");

// Fonts may be prepared only if GL is inited thus if we can't prepare, we can't list property values.
if(GL_IsInited())
{
Expand Down

0 comments on commit fb38b39

Please sign in to comment.