Skip to content

Commit

Permalink
GL Texture Manager|Refactor: Numerous cleanup refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Feb 19, 2013
1 parent c26890d commit a016fce
Show file tree
Hide file tree
Showing 20 changed files with 414 additions and 433 deletions.
89 changes: 38 additions & 51 deletions doomsday/client/include/gl/gl_texmanager.h
Expand Up @@ -27,18 +27,20 @@
#ifndef LIBDENG_GL_TEXMANAGER_H
#define LIBDENG_GL_TEXMANAGER_H

#ifndef __cplusplus
# error "gl/gl_texmanager.h requires C++"
#endif

#include "sys_opengl.h"

#include "filehandle.h"
//#include "filehandle.h"
#include "gl/texturecontent.h"
#include "resource/image.h"
#include "resource/r_data.h" // For flaretexid_t, lightingtexid_t, etc...
#include "resource/rawtexture.h"
#include "Texture"
#include "TextureVariantSpec"

struct image_s;
struct texturecontent_s;
struct texturevariant_s;

#define TEXQ_BEST 8
#define MINTEXWIDTH 8
#define MINTEXHEIGHT 8
Expand All @@ -56,28 +58,24 @@ DENG_EXTERN_C boolean noHighResPatches;
DENG_EXTERN_C boolean highResWithPWAD;
DENG_EXTERN_C byte loadExtAlways;

#ifdef __cplusplus
extern "C" {
#endif

void GL_TexRegister(void);
void GL_TexRegister();

/**
* Called before real texture management is up and running, during engine
* early init.
*/
void GL_EarlyInitTextureManager(void);
DENG_EXTERN_C void GL_EarlyInitTextureManager();

void GL_InitTextureManager(void);
void GL_InitTextureManager();

void GL_ShutdownTextureManager(void);
void GL_ShutdownTextureManager();

/**
* Call this if a full cleanup of the textures is required (engine update).
*/
void GL_ResetTextureManager(void);
void GL_ResetTextureManager();

void GL_TexReset(void);
void GL_TexReset();

/**
* Determine the optimal size for a texture. Usually the dimensions are scaled
Expand All @@ -104,13 +102,13 @@ void GL_UpdateTexParams(int mipMode);
void GL_SetTextureParams(int minMode, int gameTex, int uiTex);

/// Release all textures in all schemes.
void GL_ReleaseTextures(void);
void GL_ReleaseTextures();

/// Release all textures flagged 'runtime'.
void GL_ReleaseRuntimeTextures(void);
void GL_ReleaseRuntimeTextures();

/// Release all textures flagged 'system'.
void GL_ReleaseSystemTextures(void);
void GL_ReleaseSystemTextures();

/**
* Release all textures in the identified scheme.
Expand All @@ -123,33 +121,33 @@ 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.
*/
void GL_ReleaseGLTexturesByTexture(struct texture_s *texture);
void GL_ReleaseGLTexturesByTexture(de::Texture &texture);

/**
* Release all textures associated with the specified variant @a texture.
*/
void GL_ReleaseVariantTexture(struct texturevariant_s *texture);
void GL_ReleaseVariantTexture(de::TextureVariant &texture);

/**
* Release all variants of @a tex which match @a spec.
*
* @param texture Logical Texture to process. Can be @c NULL, in which case this is a null-op.
* @param spec Specification to match. Comparision mode is exact and not fuzzy.
*/
void GL_ReleaseVariantTexturesBySpec(struct texture_s *tex, texturevariantspecification_t *spec);
void GL_ReleaseVariantTexturesBySpec(de::Texture &texture, texturevariantspecification_t &spec);

/// Release all textures associated with the identified colorpalette @a paletteId.
void GL_ReleaseTexturesByColorPalette(colorpaletteid_t paletteId);

/// Release all textures used with 'Raw Images'.
void GL_ReleaseTexturesForRawImages(void);
void GL_ReleaseTexturesForRawImages();

void GL_PruneTextureVariantSpecifications(void);
DENG_EXTERN_C void GL_PruneTextureVariantSpecifications();

/**
* Prepares all the system textures (dlight, ptcgens).
*/
void GL_LoadSystemTextures(void);
void GL_LoadSystemTextures();

/**
* @param glFormat Identifier of the desired GL texture format.
Expand Down Expand Up @@ -182,16 +180,15 @@ boolean GL_UploadTextureGrayMipmap(int glFormat, int loadFormat, uint8_t const *
* @note Can be rather time-consuming due to forced scaling operations and
* the generation of mipmaps.
*/
void GL_UploadTextureContent(struct texturecontent_s const *content);
void GL_UploadTextureContent(texturecontent_t const &content);

uint8_t *GL_LoadImage(struct image_s *img, char const *filePath);
uint8_t *GL_LoadImageStr(struct image_s *img, ddstring_t const *filePath);
uint8_t *GL_LoadImage(image_t &image, de::String nativePath);

TexSource GL_LoadExtTexture(struct image_s *image, char const *name, gfxmode_t mode);
TexSource GL_LoadExtImage(image_t &image, char const *searchPath, gfxmode_t mode);

GLint GL_MinFilterForVariantSpec(variantspecification_t const *spec);
GLint GL_MagFilterForVariantSpec(variantspecification_t const *spec);
int GL_LogicalAnisoLevelForVariantSpec(variantspecification_t const *spec);
GLint GL_MinFilterForVariantSpec(variantspecification_t const &spec);
GLint GL_MagFilterForVariantSpec(variantspecification_t const &spec);
int GL_LogicalAnisoLevelForVariantSpec(variantspecification_t const &spec);

/**
* Prepare a TextureVariantSpecification according to usage context. If incomplete
Expand All @@ -203,9 +200,9 @@ int GL_LogicalAnisoLevelForVariantSpec(variantspecification_t const *spec);
* @param tClass Color palette translation class.
* @param tMap Color palette translation map.
*
* @return A rationalized and valid TextureVariantSpecification or @c NULL if out of memory.
* @return A rationalized and valid TextureVariantSpecification.
*/
texturevariantspecification_t *GL_TextureVariantSpecificationForContext(
texturevariantspecification_t &GL_TextureVariantSpecificationForContext(
texturevariantusagecontext_t tc, int flags, byte border, int tClass,
int tMap, int wrapS, int wrapT, int minFilter, int magFilter, int anisoFilter,
boolean mipmapped, boolean gammaCorrection, boolean noStretch, boolean toAlpha);
Expand All @@ -214,33 +211,30 @@ texturevariantspecification_t *GL_TextureVariantSpecificationForContext(
* Prepare a TextureVariantSpecification according to usage context. If incomplete
* context information is supplied, suitable defaults are chosen in their place.
*
* @return A rationalized and valid TextureVariantSpecification or @c NULL if out of memory.
* @return A rationalized and valid TextureVariantSpecification.
*/
texturevariantspecification_t *GL_DetailTextureVariantSpecificationForContext(
texturevariantspecification_t &GL_DetailTextureVariantSpecificationForContext(
float contrast);

/**
* Output a human readable representation of TextureVariantSpecification to console.
*
* @param spec Specification to echo.
*/
void GL_PrintTextureVariantSpecification(texturevariantspecification_t const *spec);
void GL_PrintTextureVariantSpecification(texturevariantspecification_t const &spec);

/**
* Dump the pixel data of @a img to an ARGB32 at @a filePath.
*
* @param img The image to be dumped. A temporary copy will be made if
* @param image The image to be dumped. A temporary copy will be made if
* the pixel data is not already in either ARGB32 or ABGR32
* formats.
* @param filePath Location to write the new file. If an extension is not
* specified the file will be in PNG format.
*
* @return @c true= Dump was successful.
*/
boolean GL_DumpImage(struct image_s const *img, char const *filePath);

#ifdef __cplusplus
} // extern "C"
boolean GL_DumpImage(image_t const &image, char const *filePath);

/// Result of a request to prepare a Texture::Variant
typedef enum {
Expand Down Expand Up @@ -295,21 +289,14 @@ inline de::TextureVariant *GL_PrepareTexture(de::Texture &texture,
* revised texture management APIs.
*/

extern "C" {
#endif // __cplusplus

DGLuint GL_PrepareSysFlaremap(flaretexid_t which);
DGLuint GL_PrepareLSTexture(lightingtexid_t which);
DGLuint GL_PrepareUITexture(uitexid_t which);

DGLuint GL_PrepareRawTexture(rawtex_t *rawTex);
DGLuint GL_PrepareRawTexture(rawtex_t &rawTex);

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

#ifdef __cplusplus
} // extern "C"
#endif
DGLuint GL_NewTextureWithParams(dgltexformat_t format, int width, int height, uint8_t const *pixels, int flags,
int grayMipmap, int minFilter, int magFilter, int anisoFilter, int wrapS, int wrapT);

#endif /* LIBDENG_GL_TEXMANAGER_H */
5 changes: 4 additions & 1 deletion doomsday/client/include/map/linedef.h
Expand Up @@ -245,8 +245,11 @@ void LineDef_UpdateAABox(LineDef* lineDef);
* @param side Side of the LineDef we are interested in.
* @param deltaL Light delta for the left edge written here.
* @param deltaR Light delta for the right edge written here.
*
* @deprecated Now that we store surface tangent space normals use those
* rather than angles. @todo Remove me.
*/
void LineDef_LightLevelDelta(LineDef* lineDef, int side, float* deltaL, float* deltaR);
void LineDef_LightLevelDelta(LineDef *lineDef, int side, float *deltaL, float *deltaR);

/**
* Get a property value, selected by DMU_* name.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/include/resource/texturevariantspec.h
Expand Up @@ -147,8 +147,8 @@ typedef struct {
uint8_t contrast;
} detailvariantspecification_t;

#define TS_GENERAL(ts) (&(ts).data.variant)
#define TS_DETAIL(ts) (&(ts).data.detailvariant)
#define TS_GENERAL(ts) ((ts).data.variant)
#define TS_DETAIL(ts) ((ts).data.detailvariant)

typedef struct texturevariantspecification_s {
texturevariantspecificationtype_t type;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/gl/dgl_common.cpp
Expand Up @@ -861,7 +861,7 @@ DGLuint DGL_NewTextureWithParams(dgltexformat_t format, int width, int height,
uint8_t const *pixels, int flags, int minFilter, int magFilter,
int anisoFilter, int wrapS, int wrapT)
{
return GL_NewTextureWithParams2(format, width, height, (uint8_t *)pixels, flags, 0,
return GL_NewTextureWithParams(format, width, height, (uint8_t *)pixels, flags, 0,
(minFilter == DGL_LINEAR ? GL_LINEAR :
minFilter == DGL_NEAREST ? GL_NEAREST :
minFilter == DGL_NEAREST_MIPMAP_NEAREST ? GL_NEAREST_MIPMAP_NEAREST :
Expand Down
9 changes: 5 additions & 4 deletions doomsday/client/src/gl/gl_defer.cpp
Expand Up @@ -197,14 +197,15 @@ LIBDENG_GL_DEFER2(uintArray, GLsizei s, const GLuint* v)
enqueueTask(DTT_FUNC_PTR_UINT_ARRAY, api);
}

static void processTask(deferredtask_t* task)
static void processTask(deferredtask_t *task)
{
apifunc_t* api = (apifunc_t*) task->data;
apifunc_t *api = (apifunc_t *) task->data;

switch(task->type)
{
case DTT_UPLOAD_TEXTURECONTENT:
GL_UploadTextureContent((struct texturecontent_s *) task->data);
DENG2_ASSERT(task->data);
GL_UploadTextureContent(*reinterpret_cast<texturecontent_t *>(task->data));
break;

case DTT_SET_VSYNC:
Expand Down Expand Up @@ -433,7 +434,7 @@ void GL_ProcessDeferredTasks(uint timeOutMilliSeconds)
GL_ReserveNames();
}

void GL_DeferTextureUpload(const struct texturecontent_s* content)
void GL_DeferTextureUpload(struct texturecontent_s const *content)
{
// Defer this operation. Need to make a copy.
enqueueTask(DTT_UPLOAD_TEXTURECONTENT, GL_ConstructTextureContentCopy(content));
Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/gl/gl_main.cpp
Expand Up @@ -781,7 +781,7 @@ void GL_SetRawImage(lumpnum_t lumpNum, int wrapS, int wrapT)
LIBDENG_ASSERT_IN_MAIN_THREAD();
LIBDENG_ASSERT_GL_CONTEXT_ACTIVE();

GL_BindTextureUnmanaged(GL_PrepareRawTexture(rawTex), (filterUI ? GL_LINEAR : GL_NEAREST));
GL_BindTextureUnmanaged(GL_PrepareRawTexture(*rawTex), (filterUI ? GL_LINEAR : GL_NEAREST));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapS);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapT);
}
Expand All @@ -808,8 +808,8 @@ void GL_BindTexture(Texture::Variant *tex)
texturevariantspecification_t const &spec = tex->spec();
if(spec.type == TST_GENERAL)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, TS_GENERAL(spec)->wrapS);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, TS_GENERAL(spec)->wrapT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, TS_GENERAL(spec).wrapS);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, TS_GENERAL(spec).wrapT);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_MagFilterForVariantSpec(TS_GENERAL(spec)));
if(GL_state.features.texFilterAniso)
Expand Down

0 comments on commit a016fce

Please sign in to comment.