From a89b9f2dabd238c31cc46fa83a1cb3c76f2a7f74 Mon Sep 17 00:00:00 2001 From: sireus Date: Tue, 10 May 2011 20:03:06 +0000 Subject: [PATCH] pave the way for hi-res textures git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@6416 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- docs/reference.xml | 14 ++++++++++++-- source/src/main.cpp | 4 ++++ source/src/protos.h | 4 +++- source/src/rendercubes.cpp | 2 +- source/src/texture.cpp | 34 +++++++++++++++++++++++++++------- 5 files changed, 47 insertions(+), 11 deletions(-) diff --git a/docs/reference.xml b/docs/reference.xml index 230a3267..5c78aef0 100644 --- a/docs/reference.xml +++ b/docs/reference.xml @@ -6026,13 +6026,15 @@ Output: Binds a texture to the current texture slot. Binds the texture indicated in the filename to the current texture slot and increments the slot number. + The texture is rendered at the given scale. At scale 1.0 (or if scale is 0), 32x32 texels cover one cube. At scale 2.0, which is the current maximum, it's 64x64. - + + - + @@ -6316,6 +6318,14 @@ Output: + + controls whether textures with a non-default scale will be scaled down while loading to increase performance (0) or stay at higher resolution (1). + + + + + + TODO diff --git a/source/src/main.cpp b/source/src/main.cpp index eef34b3b..0551f91a 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -594,6 +594,8 @@ void setupscreen(int &usedcolorbits, int &useddepthbits, int &usedfsaa) usedfsaa = config&2 ? fsaa : 0; } +extern int hirestextures; + void resetgl() { clearchanges(CHANGE_GFX); @@ -610,6 +612,7 @@ void resetgl() cleanuptextures(); cleanuptmus(); cleanupgl(); + uniformtexres = !hirestextures; c2skeepalive(); SDL_SetVideoMode(0, 0, 0, 0); @@ -1144,6 +1147,7 @@ int main(int argc, char **argv) execfile("config/auth.cfg"); execute("addallfavcatmenus"); // exec here, to add all categories (including those defined in autoexec.cfg) initing = NOT_INITING; + uniformtexres = !hirestextures; initlog("models"); preload_playermodels(); diff --git a/source/src/protos.h b/source/src/protos.h index 47efd33e..13ec3e24 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -275,11 +275,13 @@ struct Texture { char *name; int xs, ys, bpp, clamp; + float scale; bool mipmap, canreduce; GLuint id; }; extern Texture *notexture, *noworldtexture; extern bool silent_texture_load; +extern bool uniformtexres; extern void scaletexture(uchar *src, uint sw, uint sh, uint bpp, uchar *dst, uint dw, uint dh); extern void createtexture(int tnum, int w, int h, void *pixels, int clamp, bool mipmap, bool canreduce, GLenum format); @@ -288,7 +290,7 @@ extern SDL_Surface *creatergbsurface(int width, int height); extern SDL_Surface *creatergbasurface(int width, int height); extern SDL_Surface *forcergbsurface(SDL_Surface *os); extern SDL_Surface *forcergbasurface(SDL_Surface *os); -extern Texture *textureload(const char *name, int clamp = 0, bool mipmap = true, bool canreduce = false); +extern Texture *textureload(const char *name, int clamp = 0, bool mipmap = true, bool canreduce = false, float scale = 1.0f); extern Texture *lookuptexture(int tex, Texture *failtex = notexture); extern bool reloadtexture(Texture &t); extern bool reloadtexture(const char *name); diff --git a/source/src/rendercubes.cpp b/source/src/rendercubes.cpp index 107810bb..6821fb5e 100644 --- a/source/src/rendercubes.cpp +++ b/source/src/rendercubes.cpp @@ -125,7 +125,7 @@ int nquads; // for testing purpose. UNDOME on release. //const float TEXTURESCALE = 32.0f; VARP(texturescale, 16, 32, 64); -#define TEXTURESCALE float(texturescale) +#define TEXTURESCALE (float(texturescale) * (uniformtexres ? 1.0f : t->scale)) int striptype = 0, striptex, oh, oy, ox, odir; // the o* vars are used by the stripification int ol1r, ol1g, ol1b, ol2r, ol2g, ol2b; diff --git a/source/src/texture.cpp b/source/src/texture.cpp index d0cd4189..f0406821 100644 --- a/source/src/texture.cpp +++ b/source/src/texture.cpp @@ -338,9 +338,23 @@ SDL_Surface *texdecal(SDL_Surface *s) return m; } +void scalesurface(SDL_Surface *s, float scale) +{ + uint dw = s->w*scale, dh = s->h*scale; + uchar *buf = new uchar[dw*dh*s->format->BytesPerPixel]; + scaletexture((uchar *)s->pixels, s->w, s->h, s->format->BytesPerPixel, buf, dw, dh); + delete[] (uchar *)s->pixels; + s->w = dw; + s->h = dh; + s->pixels = buf; +} + bool silent_texture_load = false; -GLuint loadsurface(const char *texname, int &xs, int &ys, int &bpp, int clamp = 0, bool mipmap = true, bool canreduce = false) +VARFP(hirestextures, 0, 1, 1, initwarning("texture resolution", INIT_LOAD)); +bool uniformtexres = !hirestextures; + +GLuint loadsurface(const char *texname, int &xs, int &ys, int &bpp, int clamp = 0, bool mipmap = true, bool canreduce = false, float scale = 1.0f) { const char *file = texname; if(texname[0]=='<') @@ -390,6 +404,8 @@ GLuint loadsurface(const char *texname, int &xs, int &ys, int &bpp, int clamp = if(!strncmp(cmd, "decal", arg1-cmd)) { s = texdecal(s); format = texformat(s->format->BitsPerPixel); } } + if(uniformtexres && scale > 1.0f) scalesurface(s, 1.0f/scale); + GLuint tnum; glGenTextures(1, &tnum); createtexture(tnum, s->w, s->h, s->pixels, clamp, mipmap, canreduce, format); @@ -401,10 +417,10 @@ GLuint loadsurface(const char *texname, int &xs, int &ys, int &bpp, int clamp = } // management of texture slots -// each texture slot can have multople texture frames, of which currently only the first is used +// each texture slot can have multiple texture frames, of which currently only the first is used // additional frames can be used for various shaders -Texture *textureload(const char *name, int clamp, bool mipmap, bool canreduce) +Texture *textureload(const char *name, int clamp, bool mipmap, bool canreduce, float scale) { string pname; copystring(pname, name); @@ -412,7 +428,7 @@ Texture *textureload(const char *name, int clamp, bool mipmap, bool canreduce) Texture *t = textures.access(pname); if(t) return t; int xs, ys, bpp; - GLuint id = loadsurface(pname, xs, ys, bpp, clamp, mipmap, canreduce); + GLuint id = loadsurface(pname, xs, ys, bpp, clamp, mipmap, canreduce, scale); if(!id) return notexture; char *key = newstring(pname); t = &textures[key]; @@ -424,6 +440,7 @@ Texture *textureload(const char *name, int clamp, bool mipmap, bool canreduce) t->mipmap = mipmap; t->canreduce = canreduce; t->id = id; + t->scale = scale; return t; } @@ -458,6 +475,7 @@ Texture *createtexturefromsurface(const char *name, SDL_Surface *s) struct Slot { string name; + float scale; Texture *tex; bool loaded; }; @@ -466,13 +484,15 @@ vector slots; void texturereset() { slots.setsize(0); } -void texture(char *aframe, char *name) +void texture(char *scale, char *name) { Slot &s = slots.add(); copystring(s.name, name); path(s.name); + float sc = atof(scale); s.tex = NULL; s.loaded = false; + s.scale = (sc > 0 && sc <= 2.0f) ? sc : 1.0f; } COMMAND(texturereset, ARG_NONE); @@ -487,7 +507,7 @@ Texture *lookuptexture(int tex, Texture *failtex) if(!s.loaded) { defformatstring(pname)("packages/textures/%s", s.name); - s.tex = textureload(pname, 0, true, true); + s.tex = textureload(pname, 0, true, true, s.scale); if(s.tex==notexture) s.tex = failtex; s.loaded = true; } @@ -507,7 +527,7 @@ bool reloadtexture(Texture &t) { if(t.id) return true; int xs = 1, ys = 1, bpp = 0; - t.id = loadsurface(t.name, xs, ys, bpp, t.clamp, t.mipmap, t.canreduce); + t.id = loadsurface(t.name, xs, ys, bpp, t.clamp, t.mipmap, t.canreduce, t.scale); t.xs = xs; t.ys = ys; t.bpp = bpp;