Skip to content

Commit

Permalink
move reloadtexture() to texture object
Browse files Browse the repository at this point in the history
  • Loading branch information
no-lex committed Feb 10, 2023
1 parent 3aa91a2 commit 6847146
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/engine/render/rendertext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ void reloadfonts()
ENUMERATE(fonts, font, f,
for(uint i = 0; i < f.texs.size(); i++)
{
if(!reloadtexture(*f.texs[i]))
if(!f.texs[i]->reload())
{
fatal("failed to reload font texture");
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine/render/renderwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ void resetgl()

inbetweenframes = false;
//texture reloading
if(!reloadtexture(*notexture) ||
if(!notexture->reload() ||
!reloadtexture("<premul>media/interface/logo.png") ||
!reloadtexture("<premul>media/interface/logo_1024.png") ||
!reloadtexture("media/interface/background.png") ||
Expand Down
16 changes: 8 additions & 8 deletions src/engine/render/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2583,24 +2583,24 @@ bool reloadtexture(const char *name)
Texture *t = textures.access(copypath(name));
if(t)
{
return reloadtexture(*t);
return t->reload();
}
return true;
}

bool reloadtexture(Texture &tex)
bool Texture::reload()
{
if(tex.id)
if(id)
{
return true;
}
switch(tex.type&Texture::TYPE)
switch(type&TYPE)
{
case Texture::IMAGE:
case IMAGE:
{
int compress = 0;
ImageData s;
if(!s.texturedata(tex.name, true, &compress) || !newtexture(&tex, nullptr, s, tex.clamp, tex.mipmap, false, false, compress))
if(!s.texturedata(name, true, &compress) || !newtexture(this, nullptr, s, clamp, mipmap, false, false, compress))
{
return false;
}
Expand All @@ -2627,7 +2627,7 @@ void reloadtex(char *name)
t->alphamask = nullptr;
Texture oldtex = *t;
t->id = 0;
if(!reloadtexture(*t))
if(!t->reload())
{
if(t->id)
{
Expand All @@ -2644,7 +2644,7 @@ void reloadtextures()
ENUMERATE(textures, Texture, tex,
{
loadprogress = static_cast<float>(++reloaded)/textures.numelems;
reloadtexture(tex);
tex.reload();
});
loadprogress = 0;
}
Expand Down
3 changes: 2 additions & 1 deletion src/engine/render/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ extern void createtexture(int tnum, int w, int h, const void *pixels, int clamp,
extern void create3dtexture(int tnum, int w, int h, int d, const void *pixels, int clamp, int filter, GLenum component = GL_RGB, GLenum target = GL_TEXTURE_3D, bool swizzle = false);
extern GLuint setuppostfx(int w, int h, GLuint outfbo = 0);
extern void renderpostfx(GLuint outfbo = 0);
extern bool reloadtexture(Texture &tex);
extern bool reloadtexture(const char *name);
extern void clearslots();
extern void compacteditvslots();
Expand Down Expand Up @@ -59,6 +58,8 @@ struct Texture
const uchar * loadalphamask();
void cleanup();
float ratio() const;
bool reload(); //if the texture does not have a valid GL texture, attempts to reload it

};

enum
Expand Down

0 comments on commit 6847146

Please sign in to comment.