From 779df670fe1f3bcf9d0569fbd81fbc9c470b95ec Mon Sep 17 00:00:00 2001 From: ac-stef Date: Fri, 29 May 2015 15:34:34 +0200 Subject: [PATCH] fix scaled world textures (a.k.a hires textures) Until now, every texture file was only loaded once after game start. When a subsequent use of an already in use texture required a different scaling factor, the texture was not reloaded. Simultaneous use of one texture file with different scaling factors was completely impossible. Now, the scaling factor is treated as part of the file name. Therefore, a texture will be loaded again, if it is needed in a different scaling factor. Also: using out of range scaling factors with the "texture" command now results in an error message. Some map config authors don't use the command properly... Also: removed the unneeded createtexturefromsurface() --- source/src/main.cpp | 3 ++- source/src/protos.h | 2 -- source/src/renderhud.cpp | 8 ++++--- source/src/texture.cpp | 47 ++++++---------------------------------- 4 files changed, 14 insertions(+), 46 deletions(-) diff --git a/source/src/main.cpp b/source/src/main.cpp index 2566b1f2..56cb36f0 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -658,9 +658,10 @@ void resetgl() extern void reloadfonts(); extern void reloadtextures(); + extern Texture *startscreen; c2skeepalive(); if(!reloadtexture(*notexture) || - !reloadtexture("packages/misc/startscreen.png")) + !reloadtexture(*startscreen)) fatal("failed to reload core texture"); loadingscreen(); c2skeepalive(); diff --git a/source/src/protos.h b/source/src/protos.h index be6936bf..66bf146d 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -303,9 +303,7 @@ extern Texture *textureload(const char *name, int clamp = 0, bool mipmap = true, extern Texture *lookuptexture(int tex, Texture *failtex = notexture, bool trydl = false); extern const char *gettextureslot(int i); extern bool reloadtexture(Texture &t); -extern bool reloadtexture(const char *name); extern void reloadtextures(); -Texture *createtexturefromsurface(const char *name, SDL_Surface *s); extern void blitsurface(SDL_Surface *dst, SDL_Surface *src, int x, int y); void loadskymap(bool reload); diff --git a/source/src/renderhud.cpp b/source/src/renderhud.cpp index 10472ccb..2159022d 100644 --- a/source/src/renderhud.cpp +++ b/source/src/renderhud.cpp @@ -1138,10 +1138,12 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat glMatrixMode(GL_MODELVIEW); } + +Texture *startscreen = NULL; + void loadingscreen(const char *fmt, ...) { - static Texture *logo = NULL; - if(!logo) logo = textureload("packages/misc/startscreen.png", 3); + if(!startscreen) startscreen = textureload("packages/misc/startscreen.png", 3); glEnable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); @@ -1159,7 +1161,7 @@ void loadingscreen(const char *fmt, ...) loopi(fmt ? 1 : 2) { glClear(GL_COLOR_BUFFER_BIT); - quad(logo->id, (VIRTW-VIRTH)/2, 0, VIRTH, 0, 0, 1); + quad(startscreen->id, (VIRTW-VIRTH)/2, 0, VIRTH, 0, 0, 1); if(fmt) { glEnable(GL_BLEND); diff --git a/source/src/texture.cpp b/source/src/texture.cpp index 84700fdc..9d7c9216 100644 --- a/source/src/texture.cpp +++ b/source/src/texture.cpp @@ -62,6 +62,7 @@ void scaletexture(uchar *src, uint sw, uint sh, uint bpp, uchar *dst, uint dw, u Texture *notexture = NULL, *noworldtexture = NULL; +#define TEXSCALEPREFIXSIZE 8 hashtable textures; VAR(hwtexsize, 1, 0, 0); @@ -428,17 +429,17 @@ GLuint loadsurface(const char *texname, int &xs, int &ys, int &bpp, int clamp = Texture *textureload(const char *name, int clamp, bool mipmap, bool canreduce, float scale, bool trydl) { - string pname; - copystring(pname, name); - path(pname); + defformatstring(pname)("%.7g ", scale); + copystring(pname + TEXSCALEPREFIXSIZE, name, MAXSTRLEN - TEXSCALEPREFIXSIZE); + path(pname + TEXSCALEPREFIXSIZE); Texture *t = textures.access(pname); if(t) return t; int xs, ys, bpp; - GLuint id = loadsurface(pname, xs, ys, bpp, clamp, mipmap, canreduce, scale, trydl); + GLuint id = loadsurface(pname + TEXSCALEPREFIXSIZE, xs, ys, bpp, clamp, mipmap, canreduce, scale, trydl); if(!id) return notexture; char *key = newstring(pname); t = &textures[key]; - t->name = key; + t->name = key + TEXSCALEPREFIXSIZE; t->xs = xs; t->ys = ys; t->bpp = bpp; @@ -450,34 +451,6 @@ Texture *textureload(const char *name, int clamp, bool mipmap, bool canreduce, f return t; } -Texture *createtexturefromsurface(const char *name, SDL_Surface *s) -{ - string pname; - copystring(pname, name); - path(pname); - Texture *t = textures.access(pname); - if(!t) - { - char *key = newstring(pname); - t = &textures[key]; - t->name = key; - } - - GLuint tnum; - glGenTextures(1, &tnum); - GLenum format = texformat(s->format->BitsPerPixel); - createtexture(tnum, s->w, s->h, s->pixels, 0, true, false, format); - - t->xs = s->w; - t->ys = s->h; - t->bpp = s->format->BitsPerPixel; - t->clamp = 0; - t->mipmap = true; - t->canreduce = false; - t->id = tnum; - return t; -} - struct Slot { string name; @@ -525,6 +498,7 @@ COMMANDF(texture, "fs", (float *scale, char *name) intret(slots.length()); Slot &s = slots.add(); _texture(s, scale, name); + if(*scale < 0.0f || *scale > 2.0f) conoutf("\f3texture slot #%d \"%s\" error: scale factor %.7g out of range 0..2", slots.length() - 1, name, *scale); flagmapconfigchange(); }); @@ -580,13 +554,6 @@ bool reloadtexture(Texture &t) return t.id!=0; } -bool reloadtexture(const char *name) -{ - Texture *t = textures.access(path(name, true)); - if(t) return reloadtexture(*t); - return false; -} - void reloadtextures() { enumerate(textures, Texture, t, reloadtexture(t));