Skip to content

Commit

Permalink
Fixed GL-texture release for Material did not use the variant list.
Browse files Browse the repository at this point in the history
Cleanup.
  • Loading branch information
danij-deng committed Mar 27, 2011
1 parent 9310ca0 commit 3d357c6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 40 deletions.
9 changes: 9 additions & 0 deletions doomsday/engine/portable/include/p_materialmanager.h
Expand Up @@ -99,6 +99,15 @@ const ddstring_t* Materials_NamespaceNameForTextureNamespace(texturenamespaceid_
struct material_s* Materials_New(const dduri_t* name, int width,
int height, short flags, textureid_t tex, int texOriginX, int texOriginY);

/**
* Create a new material. If there exists one by the same name and in the
* same namespace, it is returned else a new material is created.
*
* \note: May fail on invalid definitions.
*
* @param def Material definition to construct from.
* @return The created material, ELSE @c 0.
*/
struct material_s* Materials_NewFromDef(ded_material_t* def);

struct material_s* Materials_ToMaterial(materialnum_t num);
Expand Down
64 changes: 24 additions & 40 deletions doomsday/engine/portable/src/p_materialmanager.c
Expand Up @@ -443,36 +443,18 @@ static material_t* linkMaterialToGlobalList(material_t* mat)
}

static material_t* createMaterial(int width, int height, short flags,
material_env_class_t envClass, textureid_t tex, short texOriginX,
short texOriginY)
{
material_t* mat = linkMaterialToGlobalList(allocMaterial());

mat->_isCustom = !Texture_IsFromIWAD(GL_ToTexture(tex));
mat->_width = width;
mat->_height = height;
mat->_envClass = envClass;
mat->numLayers = 1;
mat->layers[0].tex = tex;
mat->layers[0].texOrigin[0] = texOriginX;
mat->layers[0].texOrigin[1] = texOriginY;
return mat;
}

static material_t* createMaterialFromDef(int width, int height, short flags,
material_env_class_t envClass, const texture_t* tex, ded_material_t* def)
{
assert(def);
{
material_t* mat = linkMaterialToGlobalList(allocMaterial());

mat->_flags = flags;
mat->_isCustom = !Texture_IsFromIWAD(tex);
mat->_width = width;
mat->_height = height;
mat->_envClass = envClass;
mat->_def = def;
mat->numLayers = 1;
mat->layers[0].tex = Texture_Id(tex);
return mat;
}
}
Expand Down Expand Up @@ -593,13 +575,24 @@ void Materials_ProcessCacheQueue(void)
}
}

static void releaseGLTexturesForMaterial(material_t* mat)
static int releaseGLTexturesForMaterialWorker(materialvariant_t* variant,
void* paramaters)
{
assert(mat);
{ uint i;
for(i = 0; i < mat->numLayers; ++i)
GL_ReleaseGLTexturesForTexture(GL_ToTexture(mat->layers[i].tex));
assert(variant);
{
int i, layerCount = Material_LayerCount(MaterialVariant_GeneralCase(variant));
for(i = 0; i < layerCount; ++i)
{
const materialvariant_layer_t* ml = MaterialVariant_Layer(variant, i);
GL_ReleaseGLTexturesForTexture(GL_ToTexture(ml->tex));
}
return 0; // Continue iteration.
}
}

static void releaseGLTexturesForMaterial(material_t* mat)
{
Material_IterateVariants(mat, releaseGLTexturesForMaterialWorker, NULL);
}

void Materials_DeleteGLTextures(const char* namespaceName)
Expand All @@ -612,8 +605,8 @@ void Materials_DeleteGLTextures(const char* namespaceName)
if(!VALID_MATERIALNAMESPACE(matNamespace))
{
#if _DEBUG
Con_Message("Warning:Materials_DeleteGLTextures: Attempt to delete in unknown namespace (%s), ignoring.\n",
namespaceName);
Con_Message("Warning:Materials_DeleteGLTextures: Attempt to delete in "
"unknown namespace (%s), ignoring.\n", namespaceName);
#endif
return;
}
Expand Down Expand Up @@ -797,20 +790,11 @@ Con_Message("Materials_New: Warning, attempted to create material in "
if(tex == 0 || !(width > 0) || !(height > 0))
return NULL;

mat = createMaterial(width, height, flags, envClass, tex, texOriginX, texOriginY);
mat = createMaterial(width, height, flags, envClass, GL_ToTexture(tex), NULL);
newMaterialNameBinding(mat, name, mnamespace, hash);
return mat;
}

/**
* Create a new material. If there exists one by the same name and in the
* same namespace, it is returned else a new material is created.
*
* \note: May fail on invalid definitions.
*
* @param def Material definition to construct from.
* @return The created material, ELSE @c 0.
*/
material_t* Materials_NewFromDef(ded_material_t* def)
{
assert(def);
Expand Down Expand Up @@ -951,7 +935,7 @@ Con_Message("Warning: Attempted to create/update Material in unknown Namespace '
if(tex == 0 || !(width > 0) || !(height > 0))
return NULL;

mat = createMaterialFromDef(width, height, flags, envClass, tex, def);
mat = createMaterial(width, height, flags, envClass, tex, def);
newMaterialNameBinding(mat, name, mnamespace, hash);
return mat;
}
Expand Down Expand Up @@ -1232,10 +1216,10 @@ byte Materials_Prepare(material_snapshot_t* snapshot, material_t* mat,
variant = MaterialVariant_TranslationCurrent(variant);
mat = MaterialVariant_GeneralCase(variant);
}
assert(mat->numLayers > 0);

// Ensure all resources needed to visualize this material are loaded.
for(i = 0; i < mat->numLayers; ++i)
{ int i, layerCount = Material_LayerCount(mat);
for(i = 0; i < layerCount; ++i)
{
const materialvariant_layer_t* ml = MaterialVariant_Layer(variant, i);
byte result;
Expand All @@ -1245,7 +1229,7 @@ byte Materials_Prepare(material_snapshot_t* snapshot, material_t* mat,

if(result)
tmpResult = result;
}
}}

if((mb = bindForMaterial(mat)))
{
Expand Down

0 comments on commit 3d357c6

Please sign in to comment.