Skip to content

Commit

Permalink
Refactor|Resources: Raw textures are used by the client only
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jul 28, 2016
1 parent 78acf56 commit 3064eac
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 54 deletions.
5 changes: 4 additions & 1 deletion doomsday/apps/client/include/resource/clientresources.h
Expand Up @@ -101,6 +101,8 @@ class ClientResources : public Resources

typedef QMap<de::dint, de::Record> SpriteSet; ///< frame => Sprite

static ClientResources &get();

public:
/**
* Construct a new resource system, configuring all resource classes and
Expand Down Expand Up @@ -149,6 +151,8 @@ class ClientResources : public Resources

patchid_t declarePatch(de::String encodedName);

#ifdef __CLIENT__

/**
* Returns a rawtex_t for the given lump if one already exists; otherwise @c 0.
*/
Expand All @@ -165,7 +169,6 @@ class ClientResources : public Resources
*/
QList<rawtex_t *> collectRawTextures() const;

#ifdef __CLIENT__
/**
* Determines if a manifest exists for a resource on @a path.
*
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/dd_main.cpp
Expand Up @@ -1378,9 +1378,9 @@ static dint DD_UpdateEngineStateWorker(void *context)
//
// Rebuild resource data models (defs might've changed).
//
App_ResourceSystem().clearAllRawTextures();
App_ResourceSystem().initSprites();
#ifdef __CLIENT__
App_ResourceSystem().clearAllRawTextures();
App_ResourceSystem().initModels();
#endif
Def_PostInit();
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/gl/gl_main.cpp
Expand Up @@ -945,7 +945,7 @@ void GL_SetPSprite(world::Material *material, dint tClass, dint tMap)

void GL_SetRawImage(lumpnum_t lumpNum, gl::Wrapping wrapS, gl::Wrapping wrapT)
{
if(rawtex_t *rawTex = resSys().declareRawTexture(lumpNum))
if(rawtex_t *rawTex = ClientResources::get().declareRawTexture(lumpNum))
{
GL_BindTextureUnmanaged(GL_PrepareRawTexture(*rawTex), wrapS, wrapT,
(filterUI ? gl::Linear : gl::Nearest));
Expand Down
66 changes: 33 additions & 33 deletions doomsday/apps/client/src/gl/gl_texmanager.cpp
Expand Up @@ -61,7 +61,7 @@ static DGLuint sysFlareTextures[NUM_SYSFLARE_TEXTURES];

void GL_InitTextureManager()
{
if(initedOk)
if (initedOk)
{
GL_LoadLightingSystemTextures();
GL_LoadFlareTextures();
Expand Down Expand Up @@ -97,7 +97,7 @@ static int reloadTextures(void *context)
Rend_ParticleLoadSystemTextures();
Rend_ParticleLoadExtraTextures();

if(usingBusyMode)
if (usingBusyMode)
{
Con_SetProgress(200);
}
Expand All @@ -106,13 +106,13 @@ static int reloadTextures(void *context)

void GL_TexReset()
{
if(!initedOk) return;
if (!initedOk) return;

App_ResourceSystem().releaseAllGLTextures();
LOG_GL_VERBOSE("Released all GL textures");

bool useBusyMode = !BusyMode_Active();
if(useBusyMode)
if (useBusyMode)
{
BusyMode_FreezeGameForBusyMode();

Expand All @@ -128,7 +128,7 @@ void GL_TexReset()

void GL_LoadLightingSystemTextures()
{
if(novideo || !initedOk) return;
if (novideo || !initedOk) return;

// Preload lighting system textures.
GL_PrepareLSTexture(LST_DYNAMIC);
Expand All @@ -138,16 +138,16 @@ void GL_LoadLightingSystemTextures()

void GL_ReleaseAllLightingSystemTextures()
{
if(novideo || !initedOk) return;
if (novideo || !initedOk) return;

glDeleteTextures(NUM_LIGHTING_TEXTURES, (GLuint const *) lightingTextures);
zap(lightingTextures);
}

GLuint GL_PrepareLSTexture(lightingtexid_t which)
{
if(novideo) return 0;
if(which < 0 || which >= NUM_LIGHTING_TEXTURES) return 0;
if (novideo) return 0;
if (which < 0 || which >= NUM_LIGHTING_TEXTURES) return 0;

static const struct TexDef {
char const *name;
Expand All @@ -163,11 +163,11 @@ GLuint GL_PrepareLSTexture(lightingtexid_t which)
};
struct TexDef const &def = texDefs[which];

if(!lightingTextures[which])
if (!lightingTextures[which])
{
image_t image;

if(GL_LoadExtImage(image, def.name, def.mode))
if (GL_LoadExtImage(image, def.name, def.mode))
{
// Loaded successfully and converted accordingly.
// Upload the image to GL.
Expand All @@ -191,11 +191,11 @@ GLuint GL_PrepareLSTexture(lightingtexid_t which)

void GL_LoadFlareTextures()
{
if(novideo || !initedOk) return;
if (novideo || !initedOk) return;

GL_PrepareSysFlaremap(FXT_ROUND);
GL_PrepareSysFlaremap(FXT_FLARE);
if(!haloRealistic)
if (!haloRealistic)
{
GL_PrepareSysFlaremap(FXT_BRFLARE);
GL_PrepareSysFlaremap(FXT_BIGFLARE);
Expand All @@ -204,16 +204,16 @@ void GL_LoadFlareTextures()

void GL_ReleaseAllFlareTextures()
{
if(novideo || !initedOk) return;
if (novideo || !initedOk) return;

glDeleteTextures(NUM_SYSFLARE_TEXTURES, (GLuint const *) sysFlareTextures);
zap(sysFlareTextures);
}

GLuint GL_PrepareSysFlaremap(flaretexid_t which)
{
if(novideo) return 0;
if(which < 0 || which >= NUM_SYSFLARE_TEXTURES) return 0;
if (novideo) return 0;
if (which < 0 || which >= NUM_SYSFLARE_TEXTURES) return 0;

static const struct TexDef {
char const *name;
Expand All @@ -225,11 +225,11 @@ GLuint GL_PrepareSysFlaremap(flaretexid_t which)
};
struct TexDef const &def = texDefs[which];

if(!sysFlareTextures[which])
if (!sysFlareTextures[which])
{
image_t image;

if(GL_LoadExtImage(image, def.name, LGM_WHITE_ALPHA))
if (GL_LoadExtImage(image, def.name, LGM_WHITE_ALPHA))
{
// Loaded successfully and converted accordingly.
// Upload the image to GL.
Expand All @@ -253,19 +253,19 @@ GLuint GL_PrepareSysFlaremap(flaretexid_t which)

GLuint GL_PrepareFlaremap(de::Uri const &resourceUri)
{
if(resourceUri.path().length() == 1)
if (resourceUri.path().length() == 1)
{
// Select a system flare by numeric identifier?
int number = resourceUri.path().toStringRef().first().digitValue();
if(number == 0) return 0; // automatic
if(number >= 1 && number <= 4)
if (number == 0) return 0; // automatic
if (number >= 1 && number <= 4)
{
return GL_PrepareSysFlaremap(flaretexid_t(number - 1));
}
}
if(auto *tex = res::Textures::get().texture("Flaremaps", resourceUri))
if (auto *tex = res::Textures::get().texture("Flaremaps", resourceUri))
{
if(TextureVariant const *variant = static_cast<ClientTexture *>(tex)->prepareVariant(Rend_HaloTextureSpec()))
if (TextureVariant const *variant = static_cast<ClientTexture *>(tex)->prepareVariant(Rend_HaloTextureSpec()))
{
return variant->glName();
}
Expand All @@ -288,13 +288,13 @@ static res::Source loadRaw(image_t &image, rawtex_t const &raw)

return GL_LoadImage(image, foundPath)? res::External : res::None;
}
catch(FS1::NotFoundError const&)
catch (FS1::NotFoundError const&)
{} // Ignore this error.

try
{
FileHandle &file = fileSys.openLump(fileSys.lump(raw.lumpNum));
if(Image_LoadFromFile(image, file))
if (Image_LoadFromFile(image, file))
{
fileSys.releaseFile(file.file());
delete &file;
Expand All @@ -315,7 +315,7 @@ static res::Source loadRaw(image_t &image, rawtex_t const &raw)
// Load the raw image data.
size_t const numPels = RAW_WIDTH * RAW_HEIGHT;
image.pixels = (uint8_t *) M_Malloc(3 * numPels);
if(fileLength < 3 * numPels)
if (fileLength < 3 * numPels)
{
std::memset(image.pixels, 0, 3 * numPels);
}
Expand All @@ -329,22 +329,22 @@ static res::Source loadRaw(image_t &image, rawtex_t const &raw)
#undef RAW_HEIGHT
#undef RAW_WIDTH
}
catch(LumpIndex::NotFoundError const &)
catch (LumpIndex::NotFoundError const &)
{} // Ignore error.

return res::None;
}

GLuint GL_PrepareRawTexture(rawtex_t &raw)
{
if(raw.lumpNum < 0 || raw.lumpNum >= App_FileSystem().lumpCount()) return 0;
if (raw.lumpNum < 0 || raw.lumpNum >= App_FileSystem().lumpCount()) return 0;

if(!raw.tex)
if (!raw.tex)
{
image_t image;
Image_Init(image);

if(loadRaw(image, raw) == res::External)
if (loadRaw(image, raw) == res::External)
{
// Loaded an external raw texture.
raw.tex = GL_NewTextureWithParams(image.pixelSize == 4? DGL_RGBA : DGL_RGB,
Expand Down Expand Up @@ -374,9 +374,9 @@ GLuint GL_PrepareRawTexture(rawtex_t &raw)

void GL_SetRawTexturesMinFilter(int newMinFilter)
{
foreach(rawtex_t *raw, App_ResourceSystem().collectRawTextures())
foreach (rawtex_t *raw, App_ResourceSystem().collectRawTextures())
{
if(raw->tex) // Is the texture loaded?
if (raw->tex) // Is the texture loaded?
{
DENG_ASSERT_IN_MAIN_THREAD();
DENG_ASSERT_GL_CONTEXT_ACTIVE();
Expand All @@ -389,9 +389,9 @@ void GL_SetRawTexturesMinFilter(int newMinFilter)

void GL_ReleaseTexturesForRawImages()
{
foreach(rawtex_t *raw, App_ResourceSystem().collectRawTextures())
foreach (rawtex_t *raw, App_ResourceSystem().collectRawTextures())
{
if(raw->tex)
if (raw->tex)
{
glDeleteTextures(1, (GLuint const *) &raw->tex);
raw->tex = 0;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/render/r_draw.cpp
Expand Up @@ -62,7 +62,7 @@ static void loadViewBorderPatches()
borderPatches[0] = 0;
for(uint i = 1; i < 9; ++i)
{
borderPatches[i] = ClientApp::resources().declarePatch(borderGraphicsNames[i]->path());
borderPatches[i] = ClientResources::get().declarePatch(borderGraphicsNames[i]->path());
}

// Detemine the view border size.
Expand Down
19 changes: 11 additions & 8 deletions doomsday/apps/client/src/resource/base/clientresources.cpp
Expand Up @@ -425,10 +425,13 @@ DENG2_PIMPL(ClientResources)
, DENG2_OBSERVES(res::ColorPalette, ColorTableChange)
#endif
{
#ifdef __CLIENT__
Binder binder;
Record savedSessionModule; // SavedSession: manipulation, conversion, etc... (based on native class SavedSession)

typedef QHash<lumpnum_t, rawtex_t *> RawTextureHash;
RawTextureHash rawTexHash;

#ifdef __CLIENT__
/// System subspace schemes containing the manifests/resources.
FontSchemes fontSchemes;
QList<FontScheme *> fontSchemeCreationOrder;
Expand Down Expand Up @@ -490,11 +493,6 @@ DENG2_PIMPL(ClientResources)

QMap<spritenum_t, SpriteSet> sprites;

#ifdef __CLIENT__
Binder binder;
Record savedSessionModule; // SavedSession: manipulation, conversion, etc... (based on native class SavedSession)
#endif

Impl(Public *i)
: Base(i)
#ifdef __CLIENT__
Expand Down Expand Up @@ -2063,6 +2061,11 @@ DENG2_PIMPL(ClientResources)
}
};

ClientResources &ClientResources::get() // static
{
return static_cast<ClientResources &>(Resources::get());
}

ClientResources::ClientResources() : d(new Impl(this))
{}

Expand Down Expand Up @@ -2255,6 +2258,8 @@ patchid_t ClientResources::declarePatch(String encodedName)
return 0;
}

#ifdef __CLIENT__

rawtex_t *ClientResources::rawTexture(lumpnum_t lumpNum)
{
LOG_AS("ClientResources::rawTexture");
Expand Down Expand Up @@ -2302,8 +2307,6 @@ void ClientResources::clearAllRawTextures()
d->rawTexHash.clear();
}

#ifdef __CLIENT__

void ClientResources::releaseAllSystemGLTextures()
{
if (::novideo) return;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/ui/infine/finaleanimwidget.cpp
Expand Up @@ -220,7 +220,7 @@ static void drawPicFrame(FinaleAnimWidget *p, uint frame, float const _origin[3]
switch (f->type)
{
case FinaleAnimWidget::Frame::PFT_RAW: {
rawtex_t *rawTex = App_ResourceSystem().declareRawTexture(f->texRef.lumpNum);
rawtex_t *rawTex = ClientResources::get().declareRawTexture(f->texRef.lumpNum);
if (rawTex)
{
DGLuint glName = GL_PrepareRawTexture(*rawTex);
Expand Down

0 comments on commit 3064eac

Please sign in to comment.