Skip to content

Commit

Permalink
Fixed: System textures are released and freed when changing game modes.
Browse files Browse the repository at this point in the history
Refactored management of abstract textures and their namespaces to allow
partially clearing the texture database. It is now possible to clear by
texture type (system or runtime) or by texture namespace (TN_*).

Now when a game change occurs only textures marked "runtime" are cleared.
  • Loading branch information
danij-deng committed Jul 16, 2011
1 parent 644a646 commit 64c29d1
Show file tree
Hide file tree
Showing 5 changed files with 302 additions and 106 deletions.
7 changes: 6 additions & 1 deletion doomsday/engine/portable/include/gl_texmanager.h
Expand Up @@ -74,7 +74,6 @@ void GL_InitTextureManager(void);
void GL_ResetTextureManager(void);

void GL_ShutdownTextureManager(void);
void GL_DestroyTextures(void);

void GL_TexReset(void);

Expand Down Expand Up @@ -104,6 +103,12 @@ void GL_ReleaseSystemTextures(void);
*/
void GL_ReleaseTexturesForRawImages(void);

void GL_DestroyTextures(void);

void GL_DestroyRuntimeTextures(void);

void GL_DestroySystemTextures(void);

/**
* Called when changing the value of any cvar affecting texture quality which
* in turn calls GL_TexReset. Added to remove the need for reseting manually.
Expand Down
13 changes: 9 additions & 4 deletions doomsday/engine/portable/include/texture.h
Expand Up @@ -26,6 +26,7 @@
#define LIBDENG_GL_TEXTURE_H

struct texturevariant_s;
struct texturenamespace_hashnode_s;

typedef enum {
TEXTURE_ANALYSIS_FIRST = 0,
Expand Down Expand Up @@ -57,6 +58,7 @@ typedef struct texture_s {
/// Unique Texture Namespace Identifier.
/// \todo make external.
texturenamespaceid_t _texNamespace;
struct texturenamespace_hashnode_s* _texNamespaceHashNode;

/// List of variants (e.g., color translations).
struct texture_variantlist_node_s* _variants;
Expand All @@ -69,10 +71,8 @@ typedef struct texture_s {
char _name[9];
} texture_t;

texture_t* Texture_Construct(textureid_t id, const char name[9],
texturenamespaceid_t texNamespace, int index);
texture_t* Texture_Construct2(textureid_t id, const char name[9],
texturenamespaceid_t texNamespace, int index, int width, int height);
texture_t* Texture_Construct(textureid_t id, const char name[9], int index);
texture_t* Texture_Construct2(textureid_t id, const char name[9], int index, int width, int height);

void Texture_Destruct(texture_t* tex);

Expand Down Expand Up @@ -160,4 +160,9 @@ int Texture_TypeIndex(const texture_t* tex);
/// @return Texture namespace identifier.
texturenamespaceid_t Texture_Namespace(const texture_t* tex);

/// @return Texture namespace hash node.
struct texturenamespace_hashnode_s* Texture_NamespaceHashNode(const texture_t* tex);

void Texture_SetNamespace(texture_t* tex, texturenamespaceid_t texNamespace,
struct texturenamespace_hashnode_s* texNamespaceHashNode);
#endif /* LIBDENG_GL_TEXTURE_H */
17 changes: 8 additions & 9 deletions doomsday/engine/portable/src/dd_main.c
Expand Up @@ -1045,14 +1045,13 @@ boolean DD_ChangeGame2(gameinfo_t* info, boolean allowReload)
if(netGame)
Con_Execute(CMDS_DDAY, isServer ? "net server close" : "net disconnect", true, false);

GL_PurgeDeferredTasks();
GL_SetFilter(false);
S_Reset();
Demo_StopPlayback();

GL_ReleaseRuntimeTextures();
//GL_ShutdownFont();
GL_PurgeDeferredTasks();
GL_ClearTextureMemory();
UI_ReleaseTextures();
GL_SetFilter(false);

// If a game is presently loaded; unload it.
if(!DD_IsNullGameInfo(DD_GameInfo()))
Expand Down Expand Up @@ -1096,8 +1095,7 @@ boolean DD_ChangeGame2(gameinfo_t* info, boolean allowReload)
R_ClearPatchTexs();
R_DestroyColorPalettes();

/// \fixme dj: We do not want to destroy *everything*!
GL_DestroyTextures();
GL_DestroyRuntimeTextures();

Sfx_InitLogical();
P_InitThinkerLists(0x1|0x2);
Expand Down Expand Up @@ -2230,7 +2228,8 @@ materialnamespaceid_t DD_ParseFontNamespace(const char* str)

const ddstring_t* DD_TextureNamespaceNameForId(texturenamespaceid_t id)
{
static const ddstring_t namespaceNames[TEXTURENAMESPACE_COUNT] = {
static const ddstring_t namespaceNames[TEXTURENAMESPACE_COUNT+1] = {
/* No namespace name */ { "" },
/* TN_SYSTEM */ { TN_SYSTEM_NAME },
/* TN_FLATS */ { TN_FLATS_NAME },
/* TN_TEXTURES */ { TN_TEXTURES_NAME },
Expand All @@ -2245,8 +2244,8 @@ const ddstring_t* DD_TextureNamespaceNameForId(texturenamespaceid_t id)
/* TN_FLAREMAPS */ { TN_FLAREMAPS_NAME }
};
if(VALID_TEXTURENAMESPACE(id))
return &namespaceNames[id - TEXTURENAMESPACE_FIRST];
return NULL;
return namespaceNames + 1 + (id - TEXTURENAMESPACE_FIRST);
return namespaceNames + 0;
}

materialnum_t DD_MaterialForTextureIndex(uint index, texturenamespaceid_t texNamespace)
Expand Down

0 comments on commit 64c29d1

Please sign in to comment.