Skip to content

Commit

Permalink
Refactor: Reimplemented texture resource bookkeeping
Browse files Browse the repository at this point in the history
Management of the logical Texture instances, metafiles and related
objects was revised to crystallize the design and to begin moving the
whole system toward a design similar to de::FS.

Todo: Cleanup
  • Loading branch information
danij-deng committed Dec 4, 2012
1 parent efbff63 commit 38d01af
Show file tree
Hide file tree
Showing 49 changed files with 2,439 additions and 2,173 deletions.
29 changes: 0 additions & 29 deletions doomsday/engine/api/dd_share.h
Expand Up @@ -1248,35 +1248,6 @@ typedef enum materialschemeid_e {
/// @c true= val can be interpreted as a valid material scheme identifier.
#define VALID_MATERIALSCHEMEID(val) ((val) >= MATERIALSCHEME_FIRST && (val) <= MATERIALSCHEME_LAST)

/*
* Texture Schemes
*/

/// Texture scheme identifiers. @ingroup scheme
typedef enum textureschemeid_e {
TS_ANY = -1,
TEXTURESCHEME_FIRST = 2000,
TS_SYSTEM = TEXTURESCHEME_FIRST,
TS_FLATS,
TS_TEXTURES,
TS_SPRITES,
TS_PATCHES,
TS_DETAILS,
TS_REFLECTIONS,
TS_MASKS,
TS_MODELSKINS,
TS_MODELREFLECTIONSKINS,
TS_LIGHTMAPS,
TS_FLAREMAPS,
TEXTURESCHEME_LAST = TS_FLAREMAPS,
TS_INVALID /// Special value used to signify an invalid scheme identifier.
} textureschemeid_t;

#define TEXTURESCHEME_COUNT (TEXTURESCHEME_LAST - TEXTURESCHEME_FIRST + 1)

/// @c true= val can be interpreted as a valid texture scheme identifier.
#define VALID_TEXTURESCHEMEID(val) ((val) >= TEXTURESCHEME_FIRST && (val) <= TEXTURESCHEME_LAST)

/*
* Font Schemes
*/
Expand Down
6 changes: 3 additions & 3 deletions doomsday/engine/api/doomsday.def
Expand Up @@ -21,7 +21,7 @@ EXPORTS
DD_GetVariable @43 NONAME
DD_GetPlayer @44 NONAME
DD_MaterialForTextureUniqueId @234 NONAME
DD_ParseTextureSchemeName @502 NONAME
; DD_ParseTextureSchemeName @502 NONAME
DD_ParseMaterialSchemeName @503 NONAME

; Base: Types.
Expand Down Expand Up @@ -673,8 +673,8 @@ EXPORTS
R_ComposePatchUri @247 NONAME
R_ComposePatchPath @858 NONAME

R_TextureUniqueId @438 NONAME
R_TextureUniqueId2 @501 NONAME
Textures_UniqueId @438 NONAME
Textures_UniqueId2 @501 NONAME

R_CreateAnimGroup @241 NONAME
R_AddAnimGroupFrame @242 NONAME
Expand Down
7 changes: 3 additions & 4 deletions doomsday/engine/api/doomsday.h
Expand Up @@ -196,7 +196,6 @@ boolean DD_GameInfo(GameInfo* info);

/// @addtogroup scheme
///@{
textureschemeid_t DD_ParseTextureSchemeName(const char* str);
materialschemeid_t DD_ParseMaterialSchemeName(const char* str);
///@}

Expand All @@ -205,7 +204,7 @@ materialschemeid_t DD_ParseMaterialSchemeName(const char* str);
* @ingroup resource
*/
///@{
materialid_t DD_MaterialForTextureUniqueId(textureschemeid_t texSchemeId, int uniqueId);
materialid_t DD_MaterialForTextureUniqueId(char const *schemeName, int uniqueId);
///@}

/// @addtogroup defs
Expand Down Expand Up @@ -648,8 +647,8 @@ boolean R_GetPatchInfo(patchid_t id, patchinfo_t* info);
Uri* R_ComposePatchUri(patchid_t id);
AutoStr* R_ComposePatchPath(patchid_t id);

int R_TextureUniqueId2(const Uri* uri, boolean quiet);
int R_TextureUniqueId(const Uri* uri); /*quiet=false*/
int Textures_UniqueId2(const Uri* uri, boolean quiet);
int Textures_UniqueId(const Uri* uri); /*quiet=false*/

int R_CreateAnimGroup(int flags);
void R_AddAnimGroupFrame(int groupNum, const Uri* texture, int tics, int randomTics);
Expand Down
1 change: 1 addition & 0 deletions doomsday/engine/engine.pro
Expand Up @@ -306,6 +306,7 @@ DENG_HEADERS += \
include/resource/r_data.h \
include/resource/rawtexture.h \
include/resource/texture.h \
include/resource/texturemetafile.h \
include/resource/textures.h \
include/resource/texturevariant.h \
include/resource/texturevariantspecification.h \
Expand Down
11 changes: 6 additions & 5 deletions doomsday/engine/include/dd_main.h
Expand Up @@ -200,20 +200,21 @@ de::ResourceClass& DD_ResourceClassById(resourceclassid_t classId);
*/
de::ResourceClass& DD_ResourceClassByName(de::String name);

/// @return Symbolic name of the material scheme associated with @a textureSchemeName.
ddstring_t const *DD_MaterialSchemeNameForTextureScheme(de::String textureSchemeName);

extern "C" {
#endif // __cplusplus

textureschemeid_t DD_ParseTextureSchemeName(const char* str);

materialschemeid_t DD_ParseMaterialSchemeName(const char* str);

fontschemeid_t DD_ParseFontSchemeName(const char* str);

/// @return Symbolic name of the material scheme associated with @a schemeId.
const ddstring_t* DD_MaterialSchemeNameForTextureScheme(textureschemeid_t schemeId);
/// @return Symbolic name of the material scheme associated with @a textureSchemeName.
ddstring_t const *DD_MaterialSchemeNameForTextureScheme(ddstring_t const *textureSchemeName);

/// @return Unique identifier of the material associated with the identified @a uniqueId texture.
materialid_t DD_MaterialForTextureUniqueId(textureschemeid_t schemeId, int uniqueId);
materialid_t DD_MaterialForTextureUniqueId(char const *schemeName, int uniqueId);

const char* value_Str(int val);

Expand Down
5 changes: 5 additions & 0 deletions doomsday/engine/include/de_resource.h
Expand Up @@ -23,6 +23,7 @@
#define LIBDENG_RESOURCE_SUBSYSTEM_H

#include "resource/animgroups.h"
#include "resource/bitmapfont.h"
#include "resource/colorpalettes.h"
#include "resource/font.h"
#include "resource/fonts.h"
Expand All @@ -36,4 +37,8 @@
#include "resource/wad.h"
#include "resource/zip.h"

#ifdef __cplusplus
# include "resource/texturemetafile.h"
#endif

#endif /* LIBDENG_RESOURCE_SUBSYSTEM_H */
26 changes: 9 additions & 17 deletions doomsday/engine/include/gl/gl_texmanager.h
Expand Up @@ -119,21 +119,17 @@ void GL_ReleaseRuntimeTextures(void);
void GL_ReleaseSystemTextures(void);

/**
* Release all textures in the identified scheme(s).
* Release all textures in the identified scheme.
*
* @param schemeId Unique identifier of the scheme to process or @c TS_ANY
* to release all textures in any scheme.
* @param schemeName Symbolic name of the texture scheme to process.
*/
void GL_ReleaseTexturesByScheme(textureschemeid_t schemeId);
void GL_ReleaseTexturesByScheme(char const *schemeName);

/**
* Release all textures associated with the specified @a texture.
* @param texture Logical Texture. Can be @c NULL, in which case this is a null-op.
*
* @note Can also be used as an iterator callback.
*/
int GL_ReleaseGLTexturesByTexture2(Texture* texture, void* paramaters);
int GL_ReleaseGLTexturesByTexture(Texture* texture); /*paramaters=NULL*/
void GL_ReleaseGLTexturesByTexture(Texture* texture);

/**
* Release all textures associated with the specified variant @a texture.
Expand Down Expand Up @@ -309,8 +305,8 @@ void GL_BindTexture(struct texturevariant_s* tex);
DGLuint GL_PrepareExtTexture(const char* name, gfxmode_t mode, int useMipmap,
int minFilter, int magFilter, int anisoFilter, int wrapS, int wrapT, int flags);

DGLuint GL_PrepareSysFlareTexture(flaretexid_t flare);
DGLuint GL_PrepareLightMap(const Uri* path);
DGLuint GL_PrepareSysFlaremap(flaretexid_t flare);
DGLuint GL_PrepareLightmap(Uri const *path);
DGLuint GL_PrepareLSTexture(lightingtexid_t which);
DGLuint GL_PrepareRawTexture(rawtex_t* rawTex);

Expand All @@ -324,21 +320,17 @@ struct texturevariant_s* GL_PreparePatchTexture(Texture* tex);
*
* @param name Name of a flare texture or "0" to "4".
* @param oldIdx Old method of flare texture selection, by id.
*
* @return @c 0= Use the automatic selection logic.
*/
DGLuint GL_PrepareFlareTexture(const Uri* path, int oldIdx);
DGLuint GL_PrepareFlareTexture(Uri const *path, int oldIdx);

DGLuint GL_NewTextureWithParams(dgltexformat_t format, int width, int height,
const uint8_t* pixels, int flags);
DGLuint GL_NewTextureWithParams2(dgltexformat_t format, int width, int height,
const uint8_t* pixels, int flags, int grayMipmap, int minFilter, int magFilter,
int anisoFilter, int wrapS, int wrapT);

/**
* @param tex Texture instance to compose the cache name of.
* @return The chosen cache name for this texture.
*/
AutoStr* GL_ComposeCacheNameForTexture(Texture* tex);

/**
* Dump the pixel data of @a img to an ARGB32 at @a filePath.
*
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/include/resource/fonts.h
Expand Up @@ -113,7 +113,7 @@ fontid_t Fonts_Id(struct font_s* font);
struct font_s* Fonts_ToFont(fontid_t fontId);

/// @return Font associated with the scheme-unique identifier @a index else @c NOFONTID.
textureid_t Fonts_FontForUniqueId(fontschemeid_t schemeId, int uniqueId);
fontid_t Fonts_FontForUniqueId(fontschemeid_t schemeId, int uniqueId);

/// @return Scheme-unique identfier associated with the identified @a fontId.
int Fonts_UniqueId(fontid_t fontId);
Expand Down
27 changes: 9 additions & 18 deletions doomsday/engine/include/resource/r_data.h
Expand Up @@ -157,25 +157,16 @@ Uri *R_ComposePatchUri(patchid_t id);
/// returned if the id is invalid/unknown.
AutoStr *R_ComposePatchPath(patchid_t id);

struct texture_s *R_CreateSkinTex(Uri const *filePath, boolean isShinySkin);

struct texture_s *R_CreateLightMap(Uri const *resourcePath);

struct texture_s *R_CreateFlareTexture(Uri const *resourcePath);

struct texture_s *R_CreateReflectionTexture(Uri const *resourcePath);

struct texture_s *R_CreateMaskTexture(Uri const *resourcePath, Size2Raw const *size);

/**
* Construct a DetailTexture according to the paramaters of the definition.
* @note May return an existing DetailTexture if it is concluded that the
* definition does not infer a unique DetailTexture.
*
* @param def Definition describing the desired DetailTexture.
* @return DetailTexture inferred from the definition or @c NULL if invalid.
/*
* TODO: Merge/generalize these very similar routines.
*/
struct texture_s *R_CreateDetailTextureFromDef(ded_detailtexture_t const *def);

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"
Expand Down
2 changes: 0 additions & 2 deletions doomsday/engine/include/resource/rawtexture.h
Expand Up @@ -24,8 +24,6 @@

#include "dd_share.h" // For lumpnum_t

#include <de/Str.h>

/**
* A rawtex is a lump raw graphic that has been prepared for render.
*/
Expand Down
15 changes: 10 additions & 5 deletions doomsday/engine/include/resource/texture.h
Expand Up @@ -24,9 +24,10 @@
#define LIBDENG_RESOURCE_TEXTURE_H

#include <de/size.h>
#include "textures.h"
#include "texturevariant.h"

typedef int textureid_t;

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -53,6 +54,7 @@ typedef enum {
#ifdef __cplusplus

#include <list>
#include <QFlag>

namespace de {

Expand All @@ -79,7 +81,7 @@ class Texture
* for the resultant texture.
* @param userData User data to associate with the resultant texture.
*/
Texture(textureid_t bindId, void *userData = 0);
Texture(textureid_t bindId, Flags flags = 0, void *userData = 0);

/**
* @param bindId Unique identifier of the primary binding in the owning
Expand All @@ -90,7 +92,7 @@ class Texture
* image at load time.
* @param userData User data to associate with the resultant texture.
*/
Texture(textureid_t bindId, Size2Raw const &dimensions, void *userData = 0);
Texture(textureid_t bindId, Size2Raw const &dimensions, Flags flags = 0, void *userData = 0);

~Texture();

Expand Down Expand Up @@ -130,10 +132,13 @@ class Texture
*/
TextureVariant &addVariant(TextureVariant &variant);

/// @return Number of variants for this texture.
/// @return Number of variants for the texture.
uint variantCount() const;

/// Destroy all prepared variants owned by this texture.
/// Destroy all analyses for the texture.
void clearAnalyses();

/// Destroy all prepared variants for the texture.
void clearVariants();

/**
Expand Down

0 comments on commit 38d01af

Please sign in to comment.