Skip to content

Commit

Permalink
Enforce data hiding
Browse files Browse the repository at this point in the history
Moved texturevariant_s into texturevariant.c as there is no need
to expose its internal structure.
  • Loading branch information
danij-deng committed Jan 10, 2012
1 parent 372341e commit ec4bc15
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 29 deletions.
27 changes: 6 additions & 21 deletions doomsday/engine/portable/include/texturevariant.h
Expand Up @@ -21,8 +21,8 @@
* Boston, MA 02110-1301 USA
*/

#ifndef LIBDENG_GL_TEXTUREVARIANT_H
#define LIBDENG_GL_TEXTUREVARIANT_H
#ifndef LIBDENG_REFRESH_TEXTUREVARIANT_H
#define LIBDENG_REFRESH_TEXTUREVARIANT_H

#include "texturevariantspecification.h"

Expand All @@ -36,31 +36,16 @@ struct texture_s;
#define TVF_IS_UPLOADED 0x2 /// Texture has been uploaded to GL.
/**@}*/

typedef struct texturevariant_s {
/// Superior Texture of which this is a derivative.
struct texture_s* _generalCase;

/// @see textureVariantFlags
int _flags;

/// Name of the associated GL texture object.
DGLuint _glName;

/// Prepared coordinates for the bottom right of the texture minus border.
float _s, _t;

/// Specification used to derive this variant.
texturevariantspecification_t* _spec;
} texturevariant_t;
struct texturevariant_s; // The texturevariant instance (opaque).
typedef struct texturevariant_s texturevariant_t;

/**
* @param generalCase Texture from which this variant is derived.
* @param glName GL-name of the associated texture object.
* @param spec Specification used to derive this variant. Ownership of
* specifcation is NOT given to the resultant TextureVariant
*/
texturevariant_t* TextureVariant_New(struct texture_s* generalCase,
DGLuint glName, texturevariantspecification_t* spec);
texturevariantspecification_t* spec);

void TextureVariant_Delete(texturevariant_t* tex);

Expand All @@ -84,4 +69,4 @@ void TextureVariant_SetCoords(texturevariant_t* tex, float s, float t);
DGLuint TextureVariant_GLName(const texturevariant_t* tex);
void TextureVariant_SetGLName(texturevariant_t* tex, DGLuint glName);

#endif /* LIBDENG_GL_TEXTUREVARIANT_H */
#endif /* LIBDENG_REFRESH_TEXTUREVARIANT_H */
3 changes: 2 additions & 1 deletion doomsday/engine/portable/src/gl_texmanager.c
Expand Up @@ -3207,7 +3207,8 @@ static texturevariant_t* tryLoadImageAndPrepareVariant(texture_t* tex,
if(!variant)
{
DGLuint newGLName = GL_GetReservedTextureName();
variant = TextureVariant_New(tex, newGLName, spec);
variant = TextureVariant_New(tex, spec);
TextureVariant_SetGLName(variant, newGLName);
Texture_AddVariant(tex, variant);
}
// Are we re-preparing a released texture?
Expand Down
36 changes: 29 additions & 7 deletions doomsday/engine/portable/src/texturevariant.c
Expand Up @@ -28,22 +28,44 @@
#include "texture.h"
#include "texturevariant.h"

struct texturevariant_s {
/// Superior Texture of which this is a derivative.
struct texture_s* _generalCase;

/// @see textureVariantFlags
int _flags;

/// Name of the associated GL texture object.
DGLuint _glName;

/// Prepared coordinates for the bottom right of the texture minus border.
float _s, _t;

/// Specification used to derive this variant.
texturevariantspecification_t* _spec;
};

texturevariant_t* TextureVariant_New(texture_t* generalCase,
DGLuint glName, texturevariantspecification_t* spec)
texturevariantspecification_t* spec)
{
assert(generalCase && spec);
{
texturevariant_t* tex = tex = (texturevariant_t*) malloc(sizeof(*tex));
if(NULL == tex)
texturevariant_t* tex;

if(!generalCase)
Con_Error("TextureVariant::New: Attempted with invalid generalCase reference (=NULL).");
if(!spec)
Con_Error("TextureVariant::New: Attempted with invalid spec reference (=NULL).");

tex = (texturevariant_t*) malloc(sizeof(*tex));
if(!tex)
Con_Error("TextureVariant::Construct: Failed on allocation of %lu bytes for "
"new TextureVariant.", (unsigned long) sizeof(*tex));

tex->_generalCase = generalCase;
tex->_spec = spec;
tex->_flags = 0;
tex->_s = tex->_t = 0;
tex->_glName = glName;
tex->_glName = 0;
return tex;
}
}

void TextureVariant_Delete(texturevariant_t* tex)
Expand Down

0 comments on commit ec4bc15

Please sign in to comment.