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
This commit is contained in:
+12
-2
@@ -6026,13 +6026,15 @@ Output:
|
||||
<description>Binds a texture to the current texture slot.</description>
|
||||
<remarks>
|
||||
<remark>Binds the texture indicated in the filename to the current texture slot and increments the slot number.</remark>
|
||||
<remark>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.</remark>
|
||||
</remarks>
|
||||
<references>
|
||||
<identifierReference name="loadnotexture" identifier="loadnotexture"/>
|
||||
<identifierReference name="texture" identifier="loadnotexture"/>
|
||||
<identifierReference name="texturereset" identifier="texturereset"/>
|
||||
<identifierReference name="hirestextures" identifier="hirestextures"/>
|
||||
</references>
|
||||
<arguments>
|
||||
<argument token="0" description="This is a redundant value. Always leave this value as 0 here so it doesn'tbreak your configurations." valueNotes="0"/>
|
||||
<argument token="S" description="Scale of the texture to load (should be a power of two)." valueNotes="Float"/>
|
||||
<argument token="F" description="File name of the texture to bind" valueNotes="String"/>
|
||||
</arguments>
|
||||
</command>
|
||||
@@ -6316,6 +6318,14 @@ Output:
|
||||
<value token="N" description="TODO" minValue="-1" maxValue="3" defaultValue="0" />
|
||||
</variable>
|
||||
|
||||
<variable name="hirestextures">
|
||||
<description>controls whether textures with a non-default scale will be scaled down while loading to increase performance (0) or stay at higher resolution (1).</description>
|
||||
<value token="N" description="TODO" minValue="0" maxValue="1" defaultValue="1" />
|
||||
<references>
|
||||
<identifierReference name="texture" identifier="texture"/>
|
||||
</references>
|
||||
</variable>
|
||||
|
||||
<variable name="texturescale">
|
||||
<description>TODO</description>
|
||||
<value token="N" description="TODO" minValue="16" maxValue="64" defaultValue="32" />
|
||||
|
||||
@@ -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();
|
||||
|
||||
+3
-1
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
+27
-7
@@ -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<Slot> 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;
|
||||
|
||||
Reference in New Issue
Block a user