2004-08-22 22:29:09 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2005-12-01 11:40:45 +00:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
// draw.c -- this is the only file outside the refresh that touches the
|
|
|
|
// vid buffer
|
|
|
|
|
|
|
|
#include "quakedef.h"
|
2009-11-04 21:16:50 +00:00
|
|
|
#ifdef GLQUAKE
|
2004-08-22 22:29:09 +00:00
|
|
|
#include "glquake.h"
|
|
|
|
#include "shader.h"
|
2009-11-04 21:16:50 +00:00
|
|
|
#include "gl_draw.h"
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2005-12-01 11:40:45 +00:00
|
|
|
#include <stdlib.h> // is this needed for atoi?
|
|
|
|
#include <stdio.h> // is this needed for atoi?
|
|
|
|
|
2004-08-22 22:29:09 +00:00
|
|
|
//#define GL_USE8BITTEX
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
static void GL_Upload32 (char *name, unsigned *data, int width, int height, unsigned int flags);
|
|
|
|
static void GL_Upload32_BGRA (char *name, unsigned *data, int width, int height, unsigned int flags);
|
|
|
|
static void GL_Upload24BGR_Flip (char *name, qbyte *framedata, int inwidth, int inheight, unsigned int flags);
|
|
|
|
static void GL_Upload8 (char *name, qbyte *data, int width, int height, unsigned int flags, unsigned int alpha);
|
2010-07-11 02:22:39 +00:00
|
|
|
static void GL_Upload8Pal32 (qbyte *data, qbyte *pal, int width, int height, unsigned int flags);
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2010-07-11 02:22:39 +00:00
|
|
|
void GL_UploadFmt(texid_t tex, char *name, enum uploadfmt fmt, void *data, void *palette, int width, int height, unsigned int flags)
|
2009-11-04 21:16:50 +00:00
|
|
|
{
|
2011-02-25 04:22:14 +00:00
|
|
|
GL_MTBind(0, GL_TEXTURE_2D, tex);
|
2009-11-04 21:16:50 +00:00
|
|
|
switch(fmt)
|
|
|
|
{
|
|
|
|
case TF_INVALID:
|
|
|
|
break;
|
|
|
|
|
2009-11-07 13:29:15 +00:00
|
|
|
case TF_RGBX32:
|
|
|
|
flags |= IF_NOALPHA;
|
2009-11-04 21:16:50 +00:00
|
|
|
case TF_RGBA32:
|
|
|
|
GL_Upload32(name, data, width, height, flags);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TF_BGRA32:
|
|
|
|
GL_Upload32_BGRA(name, data, width, height, flags);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// case TF_BGRA24:
|
|
|
|
// GL_Upload24BGR(name, data, width, height, flags);
|
|
|
|
// break;
|
|
|
|
|
|
|
|
case TF_BGR24_FLIP:
|
|
|
|
GL_Upload24BGR_Flip(name, data, width, height, flags);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TF_SOLID8:
|
|
|
|
GL_Upload8(name, data, width, height, flags, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TF_TRANS8:
|
|
|
|
GL_Upload8(name, data, width, height, flags, 1);
|
|
|
|
break;
|
|
|
|
|
2010-07-11 02:22:39 +00:00
|
|
|
case TF_8PAL24:
|
|
|
|
GL_Upload8Pal24(data, palette, width, height, flags);
|
|
|
|
break;
|
|
|
|
case TF_8PAL32:
|
|
|
|
GL_Upload8Pal32(data, palette, width, height, flags);
|
|
|
|
break;
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
default:
|
|
|
|
Sys_Error("Unsupported image format type\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-07-11 02:22:39 +00:00
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
texid_t GL_LoadTextureFmt (char *name, int width, int height, enum uploadfmt fmt, void *data, unsigned int flags)
|
|
|
|
{
|
|
|
|
extern cvar_t r_shadow_bumpscale_basetexture;
|
|
|
|
switch(fmt)
|
|
|
|
{
|
|
|
|
case TF_INVALID:
|
|
|
|
return r_nulltex;
|
|
|
|
|
2009-11-07 13:29:15 +00:00
|
|
|
case TF_RGBX32:
|
|
|
|
flags |= IF_NOALPHA;
|
2009-11-04 21:16:50 +00:00
|
|
|
case TF_RGBA32:
|
|
|
|
return GL_LoadTexture32(name, width, height, data, flags);
|
|
|
|
|
|
|
|
case TF_TRANS8:
|
|
|
|
return GL_LoadTexture(name, width, height, data, flags, 1);
|
|
|
|
|
|
|
|
case TF_TRANS8_FULLBRIGHT:
|
|
|
|
return GL_LoadTextureFB(name, width, height, data, flags);
|
|
|
|
|
|
|
|
case TF_SOLID8:
|
|
|
|
return GL_LoadTexture(name, width, height, data, flags, 0);
|
|
|
|
|
Fixes, workarounds, and breakages. Hexen2 should work much better (-hexen2 says no mission pack, -portals says h2mp). Started working on splitting bigcoords per client, far too much work still to go on that. Removed gl_ztrick entirely. Enabled csprogs download by default. Added client support for fitzquake's 666 protocol, needs testing, some cleanup for dp protocols too, no server support, couldn't selectively enable it anyway. Now attempting to cache shadow meshes for explosions and stuff. Played with lightmaps a little, should potentially run a little faster on certain (intel?) cards. Tweeked npfte a little to try to avoid deadlocks and crashes. Fixed sky worldspawn parsing. Added h2mp's model format. Fixed baseline issue in q2 client, made servers generate q2 baselines. MOVETYPE_PUSH will not rotate extra if rotation is forced. Made status command show allowed client types. Changed lighting on weapons - should now be shaded.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/branches/wip@3572 fc73d0e0-1445-4013-8a0c-d673dee63da5
2010-08-11 03:36:31 +00:00
|
|
|
case TF_H2_T7G1:
|
|
|
|
return GL_LoadTexture(name, width, height, data, flags, 2);
|
|
|
|
case TF_H2_TRANS8_0:
|
|
|
|
return GL_LoadTexture(name, width, height, data, flags, 3);
|
|
|
|
case TF_H2_T4A4:
|
|
|
|
return GL_LoadTexture(name, width, height, data, flags, 4);
|
|
|
|
|
2009-11-05 03:07:52 +00:00
|
|
|
case TF_HEIGHT8PAL:
|
2009-11-04 21:16:50 +00:00
|
|
|
case TF_HEIGHT8:
|
|
|
|
return GL_LoadTexture8Bump(name, width, height, data, flags, r_shadow_bumpscale_basetexture.value);
|
|
|
|
|
|
|
|
default:
|
|
|
|
Sys_Error("Unsupported image format type\n");
|
2010-07-11 10:53:13 +00:00
|
|
|
return r_nulltex;
|
2009-11-04 21:16:50 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
qbyte *uploadmemorybuffer;
|
|
|
|
int sizeofuploadmemorybuffer;
|
|
|
|
qbyte *uploadmemorybufferintermediate;
|
|
|
|
int sizeofuploadmemorybufferintermediate;
|
|
|
|
|
|
|
|
extern qbyte gammatable[256];
|
|
|
|
|
2010-07-11 02:22:39 +00:00
|
|
|
#ifdef GL_USE8BITTEX
|
2004-08-22 22:29:09 +00:00
|
|
|
unsigned char *d_15to8table;
|
|
|
|
qboolean inited15to8;
|
2010-07-11 02:22:39 +00:00
|
|
|
#endif
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
extern cvar_t gl_max_size;
|
|
|
|
extern cvar_t gl_picmip;
|
2005-01-28 04:28:07 +00:00
|
|
|
extern cvar_t gl_lerpimages;
|
2004-11-13 17:31:04 +00:00
|
|
|
extern cvar_t gl_picmip2d;
|
2004-08-22 22:29:09 +00:00
|
|
|
extern cvar_t gl_compress;
|
2010-07-11 02:22:39 +00:00
|
|
|
extern cvar_t gl_smoothcrosshair;
|
2006-06-04 02:25:10 +00:00
|
|
|
extern cvar_t gl_texturemode, gl_texture_anisotropic_filtering;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
extern cvar_t gl_savecompressedtex;
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
texid_t missing_texture; //texture used when one is missing.
|
2010-02-06 01:25:04 +00:00
|
|
|
|
2006-06-04 02:25:10 +00:00
|
|
|
int gl_anisotropy_factor;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
mpic_t *conback;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
#include "hash.h"
|
|
|
|
hashtable_t gltexturetable;
|
|
|
|
bucket_t *gltexturetablebuckets[256];
|
|
|
|
|
|
|
|
int gl_filter_min = GL_LINEAR_MIPMAP_NEAREST;
|
|
|
|
int gl_filter_max = GL_LINEAR;
|
2007-06-10 05:14:38 +00:00
|
|
|
int gl_filter_max_2d = GL_LINEAR;
|
2012-01-01 02:26:42 +00:00
|
|
|
int gl_mipcap_min = 0;
|
|
|
|
int gl_mipcap_max = 1000;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
typedef struct gltexture_s
|
|
|
|
{
|
2011-10-27 16:16:29 +00:00
|
|
|
texcom_t com;
|
2009-11-04 21:16:50 +00:00
|
|
|
texid_t texnum;
|
2004-08-22 22:29:09 +00:00
|
|
|
char identifier[64];
|
|
|
|
int width, height, bpp;
|
2009-11-04 21:16:50 +00:00
|
|
|
unsigned int flags;
|
2004-08-22 22:29:09 +00:00
|
|
|
struct gltexture_s *next;
|
|
|
|
} gltexture_t;
|
|
|
|
|
|
|
|
static gltexture_t *gltextures;
|
|
|
|
|
2011-10-27 16:16:29 +00:00
|
|
|
static gltexture_t *GL_AllocNewGLTexture(char *ident, int w, int h)
|
|
|
|
{
|
|
|
|
gltexture_t *glt;
|
|
|
|
glt = BZ_Malloc(sizeof(*glt) + sizeof(bucket_t));
|
|
|
|
glt->next = gltextures;
|
|
|
|
gltextures = glt;
|
|
|
|
|
|
|
|
glt->texnum.ref = &glt->com;
|
|
|
|
Q_strncpyz (glt->identifier, ident, sizeof(glt->identifier));
|
|
|
|
glt->flags = IF_NOMIPMAP;
|
|
|
|
glt->width = w;
|
|
|
|
glt->height = h;
|
|
|
|
glt->bpp = 0;
|
|
|
|
glt->com.regsequence = r_regsequence;
|
|
|
|
|
|
|
|
qglGenTextures(1, &glt->texnum.num);
|
|
|
|
|
2012-01-17 07:57:46 +00:00
|
|
|
if (*glt->identifier)
|
|
|
|
Hash_Add(&gltexturetable, glt->identifier, glt, (bucket_t*)(glt+1));
|
2011-10-27 16:16:29 +00:00
|
|
|
return glt;
|
|
|
|
}
|
|
|
|
|
|
|
|
texid_t GL_AllocNewTexture(char *name, int w, int h)
|
|
|
|
{
|
|
|
|
gltexture_t *glt = GL_AllocNewGLTexture(name, w, h);
|
|
|
|
return glt->texnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GL_DestroyTexture(texid_t tex)
|
|
|
|
{
|
|
|
|
if (!tex.ref)
|
|
|
|
return;
|
|
|
|
|
|
|
|
qglDeleteTextures(1, &tex.num);
|
|
|
|
}
|
|
|
|
|
2004-08-22 22:29:09 +00:00
|
|
|
//=============================================================================
|
|
|
|
/* Support Routines */
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char *name;
|
2005-11-30 01:20:53 +00:00
|
|
|
char *altname;
|
2004-08-22 22:29:09 +00:00
|
|
|
int minimize, maximize;
|
|
|
|
} glmode_t;
|
|
|
|
|
|
|
|
glmode_t modes[] = {
|
2005-11-30 01:20:53 +00:00
|
|
|
{"GL_NEAREST", "n", GL_NEAREST, GL_NEAREST},
|
|
|
|
{"GL_LINEAR", "l", GL_LINEAR, GL_LINEAR},
|
|
|
|
{"GL_NEAREST_MIPMAP_NEAREST", "nn", GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST},
|
|
|
|
{"GL_LINEAR_MIPMAP_NEAREST", "ln", GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR},
|
|
|
|
{"GL_NEAREST_MIPMAP_LINEAR", "nl", GL_NEAREST_MIPMAP_LINEAR, GL_NEAREST},
|
|
|
|
{"GL_LINEAR_MIPMAP_LINEAR", "ll", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR}
|
2004-08-22 22:29:09 +00:00
|
|
|
};
|
|
|
|
|
2006-06-04 02:25:10 +00:00
|
|
|
void GL_Texture_Anisotropic_Filtering_Callback (struct cvar_s *var, char *oldvalue)
|
2005-12-01 11:40:45 +00:00
|
|
|
{
|
|
|
|
gltexture_t *glt;
|
2006-06-04 02:25:10 +00:00
|
|
|
int anfactor;
|
2005-12-01 11:40:45 +00:00
|
|
|
|
2006-06-04 03:55:51 +00:00
|
|
|
if (qrenderer != QR_OPENGL)
|
|
|
|
return;
|
|
|
|
|
2006-06-04 02:25:10 +00:00
|
|
|
gl_anisotropy_factor = 0;
|
|
|
|
|
|
|
|
if (gl_config.ext_texture_filter_anisotropic < 2)
|
2005-12-01 11:40:45 +00:00
|
|
|
return;
|
2006-01-16 06:22:18 +00:00
|
|
|
|
2006-06-04 02:25:10 +00:00
|
|
|
anfactor = bound(1, var->value, gl_config.ext_texture_filter_anisotropic);
|
2005-12-01 11:40:45 +00:00
|
|
|
|
|
|
|
/* change all the existing max anisotropy settings */
|
|
|
|
for (glt = gltextures; glt ; glt = glt->next) //redo anisotropic filtering when map is changed
|
|
|
|
{
|
2009-11-04 21:16:50 +00:00
|
|
|
if (!(glt->flags & IF_NOMIPMAP))
|
2005-12-01 11:40:45 +00:00
|
|
|
{
|
2011-02-25 04:22:14 +00:00
|
|
|
GL_MTBind(0, GL_TEXTURE_2D, glt->texnum);
|
2009-11-04 21:16:50 +00:00
|
|
|
qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anfactor);
|
2005-12-01 11:40:45 +00:00
|
|
|
}
|
|
|
|
}
|
2006-06-04 02:25:10 +00:00
|
|
|
|
|
|
|
if (anfactor >= 2)
|
|
|
|
gl_anisotropy_factor = anfactor;
|
|
|
|
else
|
|
|
|
gl_anisotropy_factor = 0;
|
2005-12-01 11:40:45 +00:00
|
|
|
}
|
|
|
|
|
2012-01-01 02:26:42 +00:00
|
|
|
void GL_Mipcap_Callback (struct cvar_s *var, char *oldvalue)
|
|
|
|
{
|
|
|
|
gltexture_t *glt;
|
|
|
|
char *s = var->string;
|
|
|
|
|
|
|
|
s = COM_Parse(s);
|
|
|
|
gl_mipcap_min = *com_token?atoi(com_token):0;
|
|
|
|
if (gl_mipcap_min > 3) /*cap it to 3, so no 16*16 textures get bugged*/
|
|
|
|
gl_mipcap_min = 3;
|
|
|
|
s = COM_Parse(s);
|
|
|
|
gl_mipcap_max = *com_token?atoi(com_token):1000;
|
|
|
|
if (gl_mipcap_max < gl_mipcap_min)
|
|
|
|
gl_mipcap_max = gl_mipcap_min;
|
|
|
|
|
|
|
|
for (glt=gltextures ; glt ; glt=glt->next)
|
|
|
|
{
|
|
|
|
if (!(glt->flags & IF_NOMIPMAP))
|
|
|
|
if (glt->flags & IF_MIPCAP)
|
|
|
|
{
|
|
|
|
GL_MTBind(0, GL_TEXTURE_2D, glt->texnum);
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, gl_mipcap_min);
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, gl_mipcap_max);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-08-22 22:29:09 +00:00
|
|
|
/*
|
|
|
|
===============
|
|
|
|
Draw_TextureMode_f
|
|
|
|
===============
|
|
|
|
*/
|
2006-04-14 05:23:11 +00:00
|
|
|
void GL_Texturemode_Callback (struct cvar_s *var, char *oldvalue)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
gltexture_t *glt;
|
|
|
|
|
2006-04-14 05:23:11 +00:00
|
|
|
if (qrenderer != QR_OPENGL)
|
|
|
|
return;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2005-11-30 01:20:53 +00:00
|
|
|
for (i=0 ; i< sizeof(modes)/sizeof(modes[0]) ; i++)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
2006-04-14 05:23:11 +00:00
|
|
|
if (!Q_strcasecmp (modes[i].name, var->string ) )
|
2005-11-30 01:20:53 +00:00
|
|
|
break;
|
2006-04-14 05:23:11 +00:00
|
|
|
if (!Q_strcasecmp (modes[i].altname, var->string ) )
|
2004-08-22 22:29:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-04-15 03:31:23 +00:00
|
|
|
if (i == sizeof(modes)/sizeof(modes[0]))
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
2005-11-30 01:20:53 +00:00
|
|
|
Con_Printf ("bad gl_texturemode name\n");
|
2004-08-22 22:29:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gl_filter_min = modes[i].minimize;
|
|
|
|
gl_filter_max = modes[i].maximize;
|
|
|
|
|
|
|
|
// change all the existing mipmap texture objects
|
|
|
|
for (glt=gltextures ; glt ; glt=glt->next)
|
|
|
|
{
|
2009-11-04 21:16:50 +00:00
|
|
|
if (!(glt->flags & IF_NOMIPMAP))
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
2011-02-25 04:22:14 +00:00
|
|
|
GL_MTBind(0, GL_TEXTURE_2D, glt->texnum);
|
2009-11-04 21:16:50 +00:00
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_min);
|
2011-10-27 16:16:29 +00:00
|
|
|
if (glt->flags & IF_NEAREST)
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
else
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max);
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-06-10 05:14:38 +00:00
|
|
|
void GL_Texturemode2d_Callback (struct cvar_s *var, char *oldvalue)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
gltexture_t *glt;
|
|
|
|
|
|
|
|
if (qrenderer != QR_OPENGL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i=0 ; i< sizeof(modes)/sizeof(modes[0]) ; i++)
|
|
|
|
{
|
|
|
|
if (!Q_strcasecmp (modes[i].name, var->string ) )
|
|
|
|
break;
|
|
|
|
if (!Q_strcasecmp (modes[i].altname, var->string ) )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == sizeof(modes)/sizeof(modes[0]))
|
|
|
|
{
|
|
|
|
Con_Printf ("bad gl_texturemode name\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// gl_filter_min = modes[i].minimize;
|
|
|
|
gl_filter_max_2d = modes[i].maximize;
|
|
|
|
|
|
|
|
// change all the existing mipmap texture objects
|
|
|
|
for (glt=gltextures ; glt ; glt=glt->next)
|
|
|
|
{
|
2009-11-04 21:16:50 +00:00
|
|
|
if (glt->flags & IF_NOMIPMAP)
|
2007-06-10 05:14:38 +00:00
|
|
|
{
|
2011-02-25 04:22:14 +00:00
|
|
|
GL_MTBind(0, GL_TEXTURE_2D, glt->texnum);
|
2009-11-04 21:16:50 +00:00
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_max_2d);
|
2011-10-27 16:16:29 +00:00
|
|
|
if (glt->flags & IF_NEAREST)
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
else
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max_2d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLDraw_ImageList_f(void)
|
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
gltexture_t *glt;
|
|
|
|
for (glt=gltextures ; glt ; glt=glt->next)
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
Con_Printf("%s (%i*%i, seq=%i)\n", glt->identifier, glt->width, glt->height, glt->com.regsequence);
|
|
|
|
}
|
|
|
|
Con_Printf("%i images\n", count);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLDraw_FlushOldTextures(void)
|
|
|
|
{
|
|
|
|
gltexture_t **link = &gltextures, *t;
|
|
|
|
while (*link)
|
|
|
|
{
|
|
|
|
t = *link;
|
|
|
|
if (t->com.regsequence != r_regsequence)
|
|
|
|
{
|
|
|
|
qglDeleteTextures(1, &t->texnum.num);
|
|
|
|
(*link)->next = t->next;
|
|
|
|
BZ_Free(t);
|
2007-06-10 05:14:38 +00:00
|
|
|
}
|
2011-10-27 16:16:29 +00:00
|
|
|
else
|
|
|
|
link = &(*link)->next;
|
2007-06-10 05:14:38 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-27 16:16:29 +00:00
|
|
|
|
2004-08-22 22:29:09 +00:00
|
|
|
/*
|
|
|
|
===============
|
|
|
|
Draw_Init
|
|
|
|
===============
|
|
|
|
*/
|
2011-10-27 16:16:29 +00:00
|
|
|
void GLDraw_Init (void)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
char ver[40];
|
|
|
|
|
|
|
|
int maxtexsize;
|
|
|
|
|
2011-01-30 01:32:30 +00:00
|
|
|
if (gltextures)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
2011-01-30 01:32:30 +00:00
|
|
|
Con_Printf("gl_draw didn't shut down cleanly\n");
|
|
|
|
gltextures = NULL;
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
memset(gltexturetablebuckets, 0, sizeof(gltexturetablebuckets));
|
|
|
|
Hash_InitTable(&gltexturetable, sizeof(gltexturetablebuckets)/sizeof(gltexturetablebuckets[0]), gltexturetablebuckets);
|
|
|
|
|
2004-11-23 01:23:45 +00:00
|
|
|
GL_FlushBackEnd();
|
2004-08-22 22:29:09 +00:00
|
|
|
// GL_FlushSkinCache();
|
2004-10-10 06:32:29 +00:00
|
|
|
TRACE(("dbg: GLDraw_ReInit: GL_GAliasFlushSkinCache\n"));
|
2004-08-22 22:29:09 +00:00
|
|
|
GL_GAliasFlushSkinCache();
|
|
|
|
|
2005-01-07 02:59:56 +00:00
|
|
|
qglGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxtexsize);
|
2004-08-22 22:29:09 +00:00
|
|
|
if (gl_max_size.value > maxtexsize)
|
|
|
|
{
|
|
|
|
sprintf(ver, "%i", maxtexsize);
|
|
|
|
Cvar_ForceSet (&gl_max_size, ver);
|
|
|
|
}
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
maxtexsize = gl_max_size.value;
|
|
|
|
|
2011-09-16 05:56:54 +00:00
|
|
|
if (gl_config.gles)
|
|
|
|
{
|
|
|
|
if (maxtexsize < 512) //this needs to be able to hold the image in unscaled form.
|
|
|
|
sizeofuploadmemorybufferintermediate = 512*512*4; //make sure we can load 512*512 images whatever happens.
|
|
|
|
else
|
|
|
|
sizeofuploadmemorybufferintermediate = maxtexsize*maxtexsize*4; //gl supports huge images, so so shall we.
|
|
|
|
}
|
2004-08-22 22:29:09 +00:00
|
|
|
else
|
2011-09-16 05:56:54 +00:00
|
|
|
{
|
|
|
|
if (maxtexsize < 2048) //this needs to be able to hold the image in unscaled form.
|
|
|
|
sizeofuploadmemorybufferintermediate = 2048*2048*4; //make sure we can load 2048*2048 images whatever happens.
|
|
|
|
else
|
|
|
|
sizeofuploadmemorybufferintermediate = maxtexsize*maxtexsize*4; //gl supports huge images, so so shall we.
|
|
|
|
}
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
//required to hold the image after scaling has occured
|
|
|
|
sizeofuploadmemorybuffer = maxtexsize*maxtexsize*4;
|
2004-10-10 06:32:29 +00:00
|
|
|
TRACE(("dbg: GLDraw_ReInit: Allocating upload buffers\n"));
|
2004-08-22 22:29:09 +00:00
|
|
|
uploadmemorybuffer = BZ_Realloc(uploadmemorybuffer, sizeofuploadmemorybuffer);
|
|
|
|
uploadmemorybufferintermediate = BZ_Realloc(uploadmemorybufferintermediate, sizeofuploadmemorybufferintermediate);
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
R2D_Init();
|
2004-10-10 06:32:29 +00:00
|
|
|
|
|
|
|
TRACE(("dbg: GLDraw_ReInit: GL_BeginRendering\n"));
|
2009-11-04 21:16:50 +00:00
|
|
|
GL_BeginRendering ();
|
2004-10-10 06:32:29 +00:00
|
|
|
TRACE(("dbg: GLDraw_ReInit: SCR_DrawLoading\n"));
|
|
|
|
|
2012-01-17 07:57:46 +00:00
|
|
|
GL_Set2D(false);
|
2004-10-10 06:32:29 +00:00
|
|
|
|
2005-01-07 02:59:56 +00:00
|
|
|
qglClear(GL_COLOR_BUFFER_BIT);
|
2004-10-10 06:32:29 +00:00
|
|
|
{
|
2011-03-31 01:14:01 +00:00
|
|
|
mpic_t *pic = R2D_SafeCachePic ("gfx/loading.lmp");
|
2004-10-10 06:32:29 +00:00
|
|
|
if (pic)
|
2011-03-31 01:14:01 +00:00
|
|
|
R2D_ScalePic ( ((int)vid.width - pic->width)/2,
|
2009-11-04 21:16:50 +00:00
|
|
|
((int)vid.height - 48 - pic->height)/2, pic->width, pic->height, pic);
|
2004-10-10 06:32:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TRACE(("dbg: GLDraw_ReInit: GL_EndRendering\n"));
|
2005-12-01 11:40:45 +00:00
|
|
|
GL_EndRendering ();
|
2004-11-18 17:55:04 +00:00
|
|
|
GL_DoSwap();
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2005-01-17 18:06:45 +00:00
|
|
|
GL_SetupSceneProcessingTextures();
|
2005-01-12 22:15:50 +00:00
|
|
|
|
2004-08-22 22:29:09 +00:00
|
|
|
//
|
|
|
|
// get the other pics we need
|
|
|
|
//
|
2011-03-31 01:14:01 +00:00
|
|
|
TRACE(("dbg: GLDraw_ReInit: R2D_SafePicFromWad\n"));
|
|
|
|
draw_disc = R2D_SafePicFromWad ("disc");
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2010-07-11 02:22:39 +00:00
|
|
|
#ifdef GL_USE8BITTEX
|
2004-08-22 22:29:09 +00:00
|
|
|
inited15to8 = false;
|
2010-07-11 02:22:39 +00:00
|
|
|
#endif
|
2004-09-13 03:20:04 +00:00
|
|
|
|
2005-01-07 02:59:56 +00:00
|
|
|
qglClearColor (1,0,0,0);
|
2004-09-13 03:20:04 +00:00
|
|
|
|
2004-10-10 06:32:29 +00:00
|
|
|
TRACE(("dbg: GLDraw_ReInit: PPL_LoadSpecularFragmentProgram\n"));
|
2010-03-25 22:56:11 +00:00
|
|
|
GL_InitSceneProcessingShaders();
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2011-10-27 16:16:29 +00:00
|
|
|
Cmd_AddRemCommand ("r_imagelist", GLDraw_ImageList_f);
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
2011-10-27 16:16:29 +00:00
|
|
|
|
2004-08-22 22:29:09 +00:00
|
|
|
void GLDraw_DeInit (void)
|
|
|
|
{
|
2011-10-27 16:16:29 +00:00
|
|
|
Cmd_RemoveCommand ("r_imagelist");
|
2009-11-04 21:16:50 +00:00
|
|
|
|
|
|
|
if (font_conchar)
|
|
|
|
Font_Free(font_conchar);
|
|
|
|
font_conchar = NULL;
|
|
|
|
if (font_tiny)
|
|
|
|
Font_Free(font_tiny);
|
|
|
|
font_tiny = NULL;
|
2005-12-01 11:40:45 +00:00
|
|
|
|
2004-08-22 22:29:09 +00:00
|
|
|
draw_disc = NULL;
|
|
|
|
|
2004-10-10 06:32:29 +00:00
|
|
|
if (uploadmemorybuffer)
|
|
|
|
BZ_Free(uploadmemorybuffer); //free the mem
|
|
|
|
if (uploadmemorybufferintermediate)
|
|
|
|
BZ_Free(uploadmemorybufferintermediate);
|
2004-08-22 22:29:09 +00:00
|
|
|
uploadmemorybuffer = NULL; //make sure we know it's free
|
2009-11-04 21:16:50 +00:00
|
|
|
uploadmemorybufferintermediate = NULL;
|
|
|
|
sizeofuploadmemorybuffer = 0; //and give a nice safe sys_error if we try using it.
|
|
|
|
sizeofuploadmemorybufferintermediate = 0;
|
|
|
|
|
2010-07-11 02:22:39 +00:00
|
|
|
#ifdef RTLIGHTS
|
|
|
|
Sh_Shutdown();
|
2004-10-19 16:10:14 +00:00
|
|
|
#endif
|
2009-11-04 21:16:50 +00:00
|
|
|
Shader_Shutdown();
|
2011-01-30 01:32:30 +00:00
|
|
|
|
|
|
|
while(gltextures)
|
|
|
|
{
|
|
|
|
gltexture_t *glt;
|
|
|
|
glt = gltextures;
|
|
|
|
gltextures = gltextures->next;
|
2011-10-27 16:16:29 +00:00
|
|
|
|
2011-01-30 01:32:30 +00:00
|
|
|
BZ_Free(glt);
|
|
|
|
}
|
|
|
|
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
GL_Set2D
|
|
|
|
|
|
|
|
Setup as if the screen was 320*200
|
|
|
|
================
|
|
|
|
*/
|
2012-01-17 07:57:46 +00:00
|
|
|
void GL_Set2D (qboolean flipped)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
2011-02-25 04:22:14 +00:00
|
|
|
extern cvar_t gl_screenangle;
|
|
|
|
float rad, ang;
|
|
|
|
float tmp[16], tmp2[16];
|
|
|
|
float w = vid.width, h = vid.height;
|
|
|
|
|
|
|
|
ang = (gl_screenangle.value>0?(gl_screenangle.value+45):(gl_screenangle.value-45))/90;
|
|
|
|
ang = (int)ang * 90;
|
|
|
|
if (ang)
|
|
|
|
{ /*more expensive maths*/
|
|
|
|
rad = (ang * M_PI) / 180;
|
|
|
|
|
|
|
|
w = fabs(cos(rad)) * (vid.width) + fabs(sin(rad)) * (vid.height);
|
|
|
|
h = fabs(sin(rad)) * (vid.width) + fabs(cos(rad)) * (vid.height);
|
|
|
|
|
2011-07-30 14:14:56 +00:00
|
|
|
Matrix4x4_CM_Orthographic(r_refdef.m_projection, w/-2.0f, w/2.0f, h/2.0f, h/-2.0f, -99999, 99999);
|
2011-02-25 04:22:14 +00:00
|
|
|
|
2011-07-30 14:14:56 +00:00
|
|
|
Matrix4x4_Identity(tmp);
|
|
|
|
Matrix4_Multiply(Matrix4x4_CM_NewTranslation((vid.width/-2.0f), (vid.height/-2.0f), 0), tmp, tmp2);
|
|
|
|
Matrix4_Multiply(Matrix4x4_CM_NewRotation(-ang, 0, 0, 1), tmp2, r_refdef.m_view);
|
2011-02-25 04:22:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-17 07:57:46 +00:00
|
|
|
if (flipped)
|
|
|
|
Matrix4x4_CM_Orthographic(r_refdef.m_projection, 0, vid.width, 0, vid.height, -99999, 99999);
|
|
|
|
else
|
|
|
|
Matrix4x4_CM_Orthographic(r_refdef.m_projection, 0, vid.width, vid.height, 0, -99999, 99999);
|
2011-07-30 14:14:56 +00:00
|
|
|
Matrix4x4_Identity(r_refdef.m_view);
|
2011-02-25 04:22:14 +00:00
|
|
|
}
|
|
|
|
r_refdef.time = realtime;
|
2011-01-23 03:44:49 +00:00
|
|
|
/*flush that gl state*/
|
2009-11-04 21:16:50 +00:00
|
|
|
qglViewport (0, 0, vid.pixelwidth, vid.pixelheight);
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2011-01-23 03:44:49 +00:00
|
|
|
if (qglLoadMatrixf)
|
|
|
|
{
|
|
|
|
qglMatrixMode(GL_PROJECTION);
|
|
|
|
qglLoadMatrixf(r_refdef.m_projection);
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2011-01-23 03:44:49 +00:00
|
|
|
qglMatrixMode(GL_MODELVIEW);
|
|
|
|
qglLoadMatrixf(r_refdef.m_view);
|
|
|
|
}
|
2011-06-05 23:53:33 +00:00
|
|
|
|
|
|
|
GL_SetShaderState2D(true);
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//====================================================================
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
GL_FindTexture
|
|
|
|
================
|
|
|
|
*/
|
2009-11-04 21:16:50 +00:00
|
|
|
texid_t GL_FindTexture (char *identifier)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
gltexture_t *glt;
|
|
|
|
|
|
|
|
glt = Hash_Get(&gltexturetable, identifier);
|
|
|
|
if (glt)
|
2009-11-04 21:16:50 +00:00
|
|
|
{
|
|
|
|
image_width = glt->width;
|
|
|
|
image_height = glt->height;
|
2004-08-22 22:29:09 +00:00
|
|
|
return glt->texnum;
|
2009-11-04 21:16:50 +00:00
|
|
|
}
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
return r_nulltex;
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gltexture_t *GL_MatchTexture (char *identifier, int bits, int width, int height)
|
|
|
|
{
|
|
|
|
gltexture_t *glt;
|
|
|
|
|
|
|
|
glt = Hash_Get(&gltexturetable, identifier);
|
|
|
|
while(glt)
|
|
|
|
{
|
|
|
|
if (glt->bpp == bits && width == glt->width && height == glt->height)
|
|
|
|
return glt;
|
|
|
|
|
|
|
|
glt = Hash_GetNext(&gltexturetable, identifier, glt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
for (glt=gltextures ; glt ; glt=glt->next)
|
|
|
|
{
|
|
|
|
if (glt->bpp == bits && width == glt->width && height == glt->height)
|
|
|
|
{
|
|
|
|
if (!strcmp (identifier, glt->identifier))
|
2005-12-01 11:40:45 +00:00
|
|
|
{
|
2004-08-22 22:29:09 +00:00
|
|
|
return glt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-01-28 04:28:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void Image_Resample32LerpLine (const qbyte *in, qbyte *out, int inwidth, int outwidth)
|
|
|
|
{
|
|
|
|
int j, xi, oldx = 0, f, fstep, endx, lerp;
|
|
|
|
fstep = (int) (inwidth*65536.0f/outwidth);
|
|
|
|
endx = (inwidth-1);
|
|
|
|
for (j = 0,f = 0;j < outwidth;j++, f += fstep)
|
|
|
|
{
|
|
|
|
xi = f >> 16;
|
|
|
|
if (xi != oldx)
|
|
|
|
{
|
|
|
|
in += (xi - oldx) * 4;
|
|
|
|
oldx = xi;
|
|
|
|
}
|
|
|
|
if (xi < endx)
|
|
|
|
{
|
|
|
|
lerp = f & 0xFFFF;
|
|
|
|
*out++ = (qbyte) ((((in[4] - in[0]) * lerp) >> 16) + in[0]);
|
|
|
|
*out++ = (qbyte) ((((in[5] - in[1]) * lerp) >> 16) + in[1]);
|
|
|
|
*out++ = (qbyte) ((((in[6] - in[2]) * lerp) >> 16) + in[2]);
|
|
|
|
*out++ = (qbyte) ((((in[7] - in[3]) * lerp) >> 16) + in[3]);
|
|
|
|
}
|
|
|
|
else // last pixel of the line has no pixel to lerp to
|
|
|
|
{
|
|
|
|
*out++ = in[0];
|
|
|
|
*out++ = in[1];
|
|
|
|
*out++ = in[2];
|
|
|
|
*out++ = in[3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//yes, this is lordhavok's code.
|
|
|
|
//superblur away!
|
|
|
|
#define LERPBYTE(i) r = row1[i];out[i] = (qbyte) ((((row2[i] - r) * lerp) >> 16) + r)
|
|
|
|
static void Image_Resample32Lerp(const void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight)
|
|
|
|
{
|
|
|
|
int i, j, r, yi, oldy, f, fstep, lerp, endy = (inheight-1), inwidth4 = inwidth*4, outwidth4 = outwidth*4;
|
|
|
|
qbyte *out;
|
|
|
|
const qbyte *inrow;
|
|
|
|
qbyte *tmem, *row1, *row2;
|
|
|
|
|
|
|
|
tmem = row1 = BZ_Malloc(2*(outwidth*4));
|
|
|
|
row2 = row1 + (outwidth * 4);
|
|
|
|
|
|
|
|
out = outdata;
|
|
|
|
fstep = (int) (inheight*65536.0f/outheight);
|
|
|
|
|
|
|
|
inrow = indata;
|
|
|
|
oldy = 0;
|
|
|
|
Image_Resample32LerpLine (inrow, row1, inwidth, outwidth);
|
|
|
|
Image_Resample32LerpLine (inrow + inwidth4, row2, inwidth, outwidth);
|
|
|
|
for (i = 0, f = 0;i < outheight;i++,f += fstep)
|
|
|
|
{
|
|
|
|
yi = f >> 16;
|
|
|
|
if (yi < endy)
|
|
|
|
{
|
|
|
|
lerp = f & 0xFFFF;
|
|
|
|
if (yi != oldy)
|
|
|
|
{
|
|
|
|
inrow = (qbyte *)indata + inwidth4*yi;
|
|
|
|
if (yi == oldy+1)
|
|
|
|
memcpy(row1, row2, outwidth4);
|
|
|
|
else
|
|
|
|
Image_Resample32LerpLine (inrow, row1, inwidth, outwidth);
|
|
|
|
Image_Resample32LerpLine (inrow + inwidth4, row2, inwidth, outwidth);
|
|
|
|
oldy = yi;
|
|
|
|
}
|
|
|
|
j = outwidth - 4;
|
|
|
|
while(j >= 0)
|
|
|
|
{
|
|
|
|
LERPBYTE( 0);
|
|
|
|
LERPBYTE( 1);
|
|
|
|
LERPBYTE( 2);
|
|
|
|
LERPBYTE( 3);
|
|
|
|
LERPBYTE( 4);
|
|
|
|
LERPBYTE( 5);
|
|
|
|
LERPBYTE( 6);
|
|
|
|
LERPBYTE( 7);
|
|
|
|
LERPBYTE( 8);
|
|
|
|
LERPBYTE( 9);
|
|
|
|
LERPBYTE(10);
|
|
|
|
LERPBYTE(11);
|
|
|
|
LERPBYTE(12);
|
|
|
|
LERPBYTE(13);
|
|
|
|
LERPBYTE(14);
|
|
|
|
LERPBYTE(15);
|
|
|
|
out += 16;
|
|
|
|
row1 += 16;
|
|
|
|
row2 += 16;
|
|
|
|
j -= 4;
|
|
|
|
}
|
|
|
|
if (j & 2)
|
|
|
|
{
|
|
|
|
LERPBYTE( 0);
|
|
|
|
LERPBYTE( 1);
|
|
|
|
LERPBYTE( 2);
|
|
|
|
LERPBYTE( 3);
|
|
|
|
LERPBYTE( 4);
|
|
|
|
LERPBYTE( 5);
|
|
|
|
LERPBYTE( 6);
|
|
|
|
LERPBYTE( 7);
|
|
|
|
out += 8;
|
|
|
|
row1 += 8;
|
|
|
|
row2 += 8;
|
|
|
|
}
|
|
|
|
if (j & 1)
|
|
|
|
{
|
|
|
|
LERPBYTE( 0);
|
|
|
|
LERPBYTE( 1);
|
|
|
|
LERPBYTE( 2);
|
|
|
|
LERPBYTE( 3);
|
|
|
|
out += 4;
|
|
|
|
row1 += 4;
|
|
|
|
row2 += 4;
|
|
|
|
}
|
|
|
|
row1 -= outwidth4;
|
|
|
|
row2 -= outwidth4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (yi != oldy)
|
|
|
|
{
|
|
|
|
inrow = (qbyte *)indata + inwidth4*yi;
|
|
|
|
if (yi == oldy+1)
|
|
|
|
memcpy(row1, row2, outwidth4);
|
|
|
|
else
|
|
|
|
Image_Resample32LerpLine (inrow, row1, inwidth, outwidth);
|
|
|
|
oldy = yi;
|
|
|
|
}
|
|
|
|
memcpy(out, row1, outwidth4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BZ_Free(tmem);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-22 22:29:09 +00:00
|
|
|
/*
|
|
|
|
================
|
|
|
|
GL_ResampleTexture
|
|
|
|
================
|
|
|
|
*/
|
2011-03-12 13:51:40 +00:00
|
|
|
static void GL_ResampleTexture (unsigned *in, int inwidth, int inheight, unsigned *out, int outwidth, int outheight)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
unsigned *inrow;
|
|
|
|
unsigned frac, fracstep;
|
|
|
|
|
2010-07-11 02:22:39 +00:00
|
|
|
if (gl_lerpimages.ival)
|
2005-01-28 04:28:07 +00:00
|
|
|
{
|
|
|
|
Image_Resample32Lerp(in, inwidth, inheight, out, outwidth, outheight);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-08-22 22:29:09 +00:00
|
|
|
fracstep = inwidth*0x10000/outwidth;
|
|
|
|
for (i=0 ; i<outheight ; i++, out += outwidth)
|
|
|
|
{
|
|
|
|
inrow = in + inwidth*(i*inheight/outheight);
|
2005-04-16 16:21:27 +00:00
|
|
|
frac = outwidth*fracstep;
|
2005-08-26 22:56:51 +00:00
|
|
|
j=outwidth-1;
|
|
|
|
while ((j+1)&3)
|
2005-01-28 04:28:07 +00:00
|
|
|
{
|
|
|
|
out[j] = inrow[frac>>16];
|
2005-04-16 16:21:27 +00:00
|
|
|
frac -= fracstep;
|
2005-01-28 04:28:07 +00:00
|
|
|
j--;
|
|
|
|
}
|
|
|
|
for ( ; j>=0 ; j-=4)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
out[j+3] = inrow[frac>>16];
|
2005-04-16 16:21:27 +00:00
|
|
|
frac -= fracstep;
|
|
|
|
out[j+2] = inrow[frac>>16];
|
|
|
|
frac -= fracstep;
|
|
|
|
out[j+1] = inrow[frac>>16];
|
|
|
|
frac -= fracstep;
|
|
|
|
out[j+0] = inrow[frac>>16];
|
|
|
|
frac -= fracstep;
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
GL_Resample8BitTexture -- JACK
|
|
|
|
================
|
|
|
|
*/
|
2011-03-12 13:51:40 +00:00
|
|
|
static void GL_Resample8BitTexture (unsigned char *in, int inwidth, int inheight, unsigned char *out, int outwidth, int outheight)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
unsigned char *inrow;
|
|
|
|
unsigned frac, fracstep;
|
|
|
|
|
|
|
|
fracstep = inwidth*0x10000/outwidth;
|
|
|
|
for (i=0 ; i<outheight ; i++, out += outwidth)
|
|
|
|
{
|
|
|
|
inrow = in + inwidth*(i*inheight/outheight);
|
|
|
|
frac = fracstep >> 1;
|
|
|
|
for (j=0 ; j<outwidth ; j+=4)
|
|
|
|
{
|
|
|
|
out[j] = inrow[frac>>16];
|
|
|
|
frac += fracstep;
|
|
|
|
out[j+1] = inrow[frac>>16];
|
|
|
|
frac += fracstep;
|
|
|
|
out[j+2] = inrow[frac>>16];
|
|
|
|
frac += fracstep;
|
|
|
|
out[j+3] = inrow[frac>>16];
|
|
|
|
frac += fracstep;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
GL_MipMap
|
|
|
|
|
|
|
|
Operates in place, quartering the size of the texture
|
|
|
|
================
|
|
|
|
*/
|
2011-03-12 13:51:40 +00:00
|
|
|
static void GL_MipMap (qbyte *in, int width, int height)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
qbyte *out;
|
2009-07-18 11:06:28 +00:00
|
|
|
qbyte *inrow;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2009-07-18 11:06:28 +00:00
|
|
|
//with npot
|
|
|
|
int rowwidth = width*4; //rowwidth is the byte width of the input
|
|
|
|
inrow = in;
|
|
|
|
|
|
|
|
width >>= 1; //ensure its truncated, so don't merge with the *8
|
2004-08-22 22:29:09 +00:00
|
|
|
height >>= 1;
|
|
|
|
out = in;
|
2009-07-18 11:06:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
for (i=0 ; i<height ; i++, inrow+=rowwidth*2)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
2009-07-18 11:06:28 +00:00
|
|
|
for (in = inrow, j=0 ; j<width ; j++, out+=4, in+=8)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
2009-07-18 11:06:28 +00:00
|
|
|
out[0] = (in[0] + in[4] + in[rowwidth+0] + in[rowwidth+4])>>2;
|
|
|
|
out[1] = (in[1] + in[5] + in[rowwidth+1] + in[rowwidth+5])>>2;
|
|
|
|
out[2] = (in[2] + in[6] + in[rowwidth+2] + in[rowwidth+6])>>2;
|
|
|
|
out[3] = (in[3] + in[7] + in[rowwidth+3] + in[rowwidth+7])>>2;
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef GL_USE8BITTEX
|
|
|
|
#ifdef GL_EXT_paletted_texture
|
|
|
|
void GLDraw_Init15to8(void)
|
|
|
|
{
|
|
|
|
int i, r, g, b, v, k;
|
|
|
|
int r1, g1, b1;
|
|
|
|
qbyte *pal;
|
|
|
|
float dist, bestdist;
|
2006-01-02 23:01:54 +00:00
|
|
|
vfsfile_t *f;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
qboolean savetable;
|
|
|
|
|
|
|
|
// JACK: 3D distance calcs - k is last closest, l is the distance.
|
|
|
|
if (inited15to8)
|
|
|
|
return;
|
|
|
|
if (!d_15to8table)
|
|
|
|
d_15to8table = BZ_Malloc(sizeof(qbyte) * 32768);
|
|
|
|
inited15to8 = true;
|
|
|
|
|
|
|
|
savetable = COM_CheckParm("-save15to8");
|
|
|
|
|
|
|
|
if (savetable)
|
2006-01-02 23:01:54 +00:00
|
|
|
f = FS_OpenVFS("glquake/15to8.pal");
|
2004-08-22 22:29:09 +00:00
|
|
|
else
|
|
|
|
f = NULL;
|
|
|
|
if (f)
|
|
|
|
{
|
2006-01-02 23:01:54 +00:00
|
|
|
VFS_READ(f, d_15to8table, 1<<15);
|
|
|
|
VFS_CLOSE(f);
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i=0; i < (1<<15); i++)
|
|
|
|
{
|
|
|
|
/* Maps
|
|
|
|
000000000000000
|
|
|
|
000000000011111 = Red = 0x1F
|
|
|
|
000001111100000 = Blue = 0x03E0
|
|
|
|
111110000000000 = Grn = 0x7C00
|
|
|
|
*/
|
|
|
|
r = ((i & 0x1F) << 3)+4;
|
|
|
|
g = ((i & 0x03E0) >> 2)+4;
|
|
|
|
b = ((i & 0x7C00) >> 7)+4;
|
|
|
|
pal = (unsigned char *)d_8to24rgbtable;
|
|
|
|
for (v=0,k=0,bestdist=10000.0; v<256; v++,pal+=4) {
|
|
|
|
r1 = (int)r - (int)pal[0];
|
|
|
|
g1 = (int)g - (int)pal[1];
|
|
|
|
b1 = (int)b - (int)pal[2];
|
|
|
|
dist = sqrt(((r1*r1)+(g1*g1)+(b1*b1)));
|
|
|
|
if (dist < bestdist) {
|
|
|
|
k=v;
|
|
|
|
bestdist = dist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
d_15to8table[i]=k;
|
|
|
|
}
|
|
|
|
if (savetable)
|
|
|
|
{
|
2006-01-02 23:01:54 +00:00
|
|
|
FS_WriteFile("glquake/15to8.pal", d_15to8table, 1<<15, FS_GAME);
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
GL_MipMap8Bit
|
|
|
|
|
|
|
|
Mipping for 8 bit textures
|
|
|
|
================
|
|
|
|
*/
|
2011-03-12 13:51:40 +00:00
|
|
|
static void GL_MipMap8Bit (qbyte *in, int width, int height)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
qbyte *out;
|
|
|
|
unsigned short r,g,b;
|
|
|
|
qbyte *at1, *at2, *at3, *at4;
|
|
|
|
|
|
|
|
height >>= 1;
|
|
|
|
out = in;
|
|
|
|
for (i=0 ; i<height ; i++, in+=width)
|
|
|
|
for (j=0 ; j<width ; j+=2, out+=1, in+=2)
|
|
|
|
{
|
|
|
|
at1 = (qbyte *) &d_8to24rgbtable[in[0]];
|
|
|
|
at2 = (qbyte *) &d_8to24rgbtable[in[1]];
|
|
|
|
at3 = (qbyte *) &d_8to24rgbtable[in[width+0]];
|
|
|
|
at4 = (qbyte *) &d_8to24rgbtable[in[width+1]];
|
|
|
|
|
|
|
|
r = (at1[0]+at2[0]+at3[0]+at4[0]); r>>=5;
|
|
|
|
g = (at1[1]+at2[1]+at3[1]+at4[1]); g>>=5;
|
|
|
|
b = (at1[2]+at2[2]+at3[2]+at4[2]); b>>=5;
|
|
|
|
|
|
|
|
out[0] = d_15to8table[(r<<0) + (g<<5) + (b<<10)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
qboolean GL_UploadCompressed (qbyte *file, int *out_width, int *out_height, unsigned int *out_flags)
|
2005-12-01 11:40:45 +00:00
|
|
|
{
|
2004-08-22 22:29:09 +00:00
|
|
|
int miplevel;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
int compressed_size;
|
|
|
|
int internalformat;
|
|
|
|
int nummips;
|
|
|
|
#define GETVAR(var) memcpy(var, file, sizeof(*var));file+=sizeof(*var);
|
|
|
|
|
2004-10-19 16:10:14 +00:00
|
|
|
if (!gl_config.arb_texture_compression || !gl_compress.value)
|
2004-08-22 22:29:09 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
GETVAR(&nummips)
|
|
|
|
GETVAR(out_width)
|
|
|
|
GETVAR(out_height)
|
2009-11-04 21:16:50 +00:00
|
|
|
GETVAR(out_flags)
|
2004-08-22 22:29:09 +00:00
|
|
|
for (miplevel = 0; miplevel < nummips; miplevel++)
|
|
|
|
{
|
|
|
|
GETVAR(&width);
|
|
|
|
GETVAR(&height);
|
|
|
|
GETVAR(&compressed_size);
|
|
|
|
GETVAR(&internalformat);
|
|
|
|
width = LittleLong(width);
|
|
|
|
height = LittleLong(height);
|
|
|
|
compressed_size = LittleLong(compressed_size);
|
|
|
|
internalformat = LittleLong(internalformat);
|
|
|
|
|
2005-12-01 11:40:45 +00:00
|
|
|
qglCompressedTexImage2DARB(GL_TEXTURE_2D, miplevel, internalformat, width, height, 0, compressed_size, file);
|
2004-08-22 22:29:09 +00:00
|
|
|
file += compressed_size;
|
|
|
|
}
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
if (!((*out_flags) & IF_NOMIPMAP))
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
2009-11-04 21:16:50 +00:00
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_min);
|
2011-10-27 16:16:29 +00:00
|
|
|
if (*out_flags & IF_NEAREST)
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
else
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max);
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-11-04 21:16:50 +00:00
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_max_2d);
|
2011-10-27 16:16:29 +00:00
|
|
|
if (*out_flags & IF_NEAREST)
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
else
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max_2d);
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-10-10 06:32:29 +00:00
|
|
|
|
2004-12-08 04:02:57 +00:00
|
|
|
void GL_RoundDimensions(int *scaled_width, int *scaled_height, qboolean mipmap)
|
|
|
|
{
|
2004-10-19 16:10:14 +00:00
|
|
|
if (gl_config.arb_texture_non_power_of_two) //NPOT is a simple extension that relaxes errors.
|
2004-10-10 06:32:29 +00:00
|
|
|
{
|
2004-12-08 04:02:57 +00:00
|
|
|
TRACE(("dbg: GL_RoundDimensions: GL_ARB_texture_non_power_of_two\n"));
|
2004-10-10 06:32:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-12-08 04:02:57 +00:00
|
|
|
int width = *scaled_width;
|
|
|
|
int height = *scaled_height;
|
|
|
|
for (*scaled_width = 1 ; *scaled_width < width ; *scaled_width<<=1)
|
2004-10-10 06:32:29 +00:00
|
|
|
;
|
2004-12-08 04:02:57 +00:00
|
|
|
for (*scaled_height = 1 ; *scaled_height < height ; *scaled_height<<=1)
|
2004-10-10 06:32:29 +00:00
|
|
|
;
|
2011-09-16 05:56:54 +00:00
|
|
|
|
|
|
|
/*round npot textures down if we're running on an embedded system*/
|
|
|
|
if (gl_config.gles)
|
|
|
|
{
|
|
|
|
if (*scaled_width != width)
|
|
|
|
*scaled_width >>= 1;
|
|
|
|
if (*scaled_height != height)
|
|
|
|
*scaled_height >>= 1;
|
|
|
|
}
|
2004-10-10 06:32:29 +00:00
|
|
|
}
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2004-11-13 17:31:04 +00:00
|
|
|
if (mipmap)
|
|
|
|
{
|
2004-12-08 04:02:57 +00:00
|
|
|
TRACE(("dbg: GL_RoundDimensions: %f\n", gl_picmip.value));
|
|
|
|
*scaled_width >>= (int)gl_picmip.value;
|
|
|
|
*scaled_height >>= (int)gl_picmip.value;
|
2004-11-13 17:31:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-12-08 04:02:57 +00:00
|
|
|
*scaled_width >>= (int)gl_picmip2d.value;
|
|
|
|
*scaled_height >>= (int)gl_picmip2d.value;
|
2004-11-13 17:31:04 +00:00
|
|
|
}
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2004-12-08 04:02:57 +00:00
|
|
|
TRACE(("dbg: GL_RoundDimensions: %f\n", gl_max_size.value));
|
2004-08-22 22:29:09 +00:00
|
|
|
if (gl_max_size.value)
|
|
|
|
{
|
2004-12-08 04:02:57 +00:00
|
|
|
if (*scaled_width > gl_max_size.value)
|
|
|
|
*scaled_width = gl_max_size.value;
|
|
|
|
if (*scaled_height > gl_max_size.value)
|
|
|
|
*scaled_height = gl_max_size.value;
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
2004-12-08 04:02:57 +00:00
|
|
|
if (*scaled_width < 1)
|
|
|
|
*scaled_width = 1;
|
|
|
|
if (*scaled_height < 1)
|
|
|
|
*scaled_height = 1;
|
|
|
|
}
|
2011-09-16 05:56:54 +00:00
|
|
|
|
2011-12-27 08:35:19 +00:00
|
|
|
void GL_8888to565(int targ, unsigned char *in, unsigned short *out, unsigned int mip, unsigned int w, unsigned int h)
|
2011-09-16 05:56:54 +00:00
|
|
|
{
|
|
|
|
unsigned int p = w*h;
|
|
|
|
unsigned short tmp;
|
|
|
|
void *iout = out;
|
|
|
|
|
|
|
|
while(p-->0)
|
|
|
|
{
|
|
|
|
tmp = ((*in++>>3) << 11);
|
|
|
|
tmp |= ((*in++>>2) << 5);
|
|
|
|
tmp |= ((*in++>>3) << 0);
|
|
|
|
in++;
|
|
|
|
*out++ = tmp;
|
|
|
|
}
|
2011-12-27 08:35:19 +00:00
|
|
|
qglTexImage2D (targ, mip, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, iout);
|
2011-09-16 05:56:54 +00:00
|
|
|
}
|
|
|
|
|
2011-12-27 08:35:19 +00:00
|
|
|
void GL_8888to4444(int targ, unsigned char *in, unsigned short *out, unsigned int mip, unsigned int w, unsigned int h)
|
2011-09-16 05:56:54 +00:00
|
|
|
{
|
|
|
|
unsigned int p = w*h;
|
|
|
|
unsigned short tmp;
|
|
|
|
void *iout = out;
|
|
|
|
|
|
|
|
while(p-->0)
|
|
|
|
{
|
|
|
|
tmp = ((*in++>>4) << 12);
|
|
|
|
tmp |= ((*in++>>4) << 8);
|
|
|
|
tmp |= ((*in++>>4) << 4);
|
|
|
|
tmp |= ((*in++>>4) << 0);
|
|
|
|
*out++ = tmp;
|
|
|
|
}
|
2011-12-27 08:35:19 +00:00
|
|
|
qglTexImage2D (targ, mip, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, iout);
|
2011-09-16 05:56:54 +00:00
|
|
|
}
|
|
|
|
|
2004-12-08 04:02:57 +00:00
|
|
|
/*
|
|
|
|
===============
|
|
|
|
GL_Upload32
|
|
|
|
===============
|
|
|
|
*/
|
2009-11-04 21:16:50 +00:00
|
|
|
void GL_Upload32_Int (char *name, unsigned *data, int width, int height, unsigned int flags, GLenum glcolormode)
|
2004-12-08 04:02:57 +00:00
|
|
|
{
|
|
|
|
int miplevel=0;
|
|
|
|
int samples;
|
|
|
|
unsigned *scaled = (unsigned *)uploadmemorybuffer;
|
|
|
|
int scaled_width, scaled_height;
|
2011-09-16 05:56:54 +00:00
|
|
|
int type;
|
2011-12-27 08:35:19 +00:00
|
|
|
int targ;
|
2004-12-08 04:02:57 +00:00
|
|
|
|
|
|
|
TRACE(("dbg: GL_Upload32: %s %i %i\n", name, width, height));
|
|
|
|
|
|
|
|
scaled_width = width;
|
|
|
|
scaled_height = height;
|
2009-11-04 21:16:50 +00:00
|
|
|
GL_RoundDimensions(&scaled_width, &scaled_height, !(flags & IF_NOMIPMAP));
|
2004-10-10 06:32:29 +00:00
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
if (!(flags & IF_NOALPHA))
|
2008-11-09 22:29:28 +00:00
|
|
|
{ //make sure it does actually have those alpha pixels
|
|
|
|
int i;
|
2009-11-04 21:16:50 +00:00
|
|
|
flags |= IF_NOALPHA;
|
2008-11-09 22:29:28 +00:00
|
|
|
for (i = 3; i < width*height*4; i+=4)
|
|
|
|
{
|
|
|
|
if (((unsigned char*)data)[i] < 255)
|
|
|
|
{
|
2009-11-04 21:16:50 +00:00
|
|
|
flags &= ~IF_NOALPHA;
|
2008-11-09 22:29:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-27 08:35:19 +00:00
|
|
|
switch((flags & IF_TEXTYPE) >> IF_TEXTYPESHIFT)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
targ = GL_TEXTURE_2D;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
targ = GL_TEXTURE_3D;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
targ = GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB + (((flags & IF_TEXTYPE) >> IF_TEXTYPESHIFT) - 2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-10-10 06:32:29 +00:00
|
|
|
TRACE(("dbg: GL_Upload32: %i %i\n", scaled_width, scaled_height));
|
|
|
|
|
2004-08-22 22:29:09 +00:00
|
|
|
if (scaled_width * scaled_height > sizeofuploadmemorybuffer/4)
|
|
|
|
Sys_Error ("GL_LoadTexture: too big");
|
|
|
|
|
2011-02-06 20:56:39 +00:00
|
|
|
if (gl_config.gles)
|
2011-09-16 05:56:54 +00:00
|
|
|
{
|
|
|
|
glcolormode = GL_RGBA; /*our input is RGBA or RGBX, with the internal format restriction, we must therefore always have an alpha value*/
|
|
|
|
type = GL_UNSIGNED_BYTE;
|
|
|
|
|
|
|
|
if (flags & IF_NOALPHA)
|
|
|
|
{
|
|
|
|
/*no alpha there, yay*/
|
|
|
|
type = GL_UNSIGNED_SHORT_5_6_5;
|
|
|
|
glcolormode = GL_RGB;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*we need an alpha channel, sorry for any banding*/
|
|
|
|
type = GL_UNSIGNED_SHORT_4_4_4_4;
|
|
|
|
glcolormode = GL_RGBA;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*GLES requires that the internal format match the format*/
|
|
|
|
samples = glcolormode;
|
|
|
|
}
|
2011-02-06 20:56:39 +00:00
|
|
|
else
|
2011-09-16 05:56:54 +00:00
|
|
|
{
|
2011-02-06 20:56:39 +00:00
|
|
|
samples = (flags&IF_NOALPHA) ? GL_RGB : GL_RGBA;
|
2011-09-16 05:56:54 +00:00
|
|
|
type = GL_UNSIGNED_BYTE;
|
|
|
|
}
|
2011-02-06 20:56:39 +00:00
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
if (gl_config.arb_texture_compression && gl_compress.value && name && !(flags&IF_NOMIPMAP))
|
|
|
|
samples = (flags&IF_NOALPHA) ? GL_COMPRESSED_RGB_ARB : GL_COMPRESSED_RGBA_ARB;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2011-12-27 08:35:19 +00:00
|
|
|
if (flags&IF_CLAMP)
|
|
|
|
{
|
|
|
|
qglTexParameteri(targ, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
qglTexParameteri(targ, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
if (targ != GL_TEXTURE_2D)
|
|
|
|
qglTexParameteri(targ, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qglTexParameteri(targ, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
|
|
qglTexParameteri(targ, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
|
|
if (targ != GL_TEXTURE_2D)
|
|
|
|
qglTexParameteri(targ, GL_TEXTURE_WRAP_R, GL_REPEAT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (targ == GL_TEXTURE_3D)
|
2011-12-23 03:12:29 +00:00
|
|
|
{
|
|
|
|
int r,d;
|
|
|
|
if (scaled_height * scaled_height != scaled_width)
|
|
|
|
return;
|
|
|
|
|
|
|
|
qglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
if (flags & IF_NEAREST)
|
|
|
|
qglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
else
|
|
|
|
qglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
|
|
|
|
for (d = 0; d < scaled_height; d++)
|
|
|
|
{
|
|
|
|
/*each 'layer' is sequential, which means we need to de-interlace the layers*/
|
|
|
|
for (r = 0; r < scaled_height; r++)
|
|
|
|
{
|
|
|
|
memcpy(scaled + (r + d*scaled_height) * scaled_height, data + (r*scaled_height + d) * scaled_height, scaled_height*sizeof(*data));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
qglTexImage3D (GL_TEXTURE_3D, 0, samples, scaled_height, scaled_height, scaled_height, 0, glcolormode, GL_UNSIGNED_BYTE, scaled);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
if (gl_config.sgis_generate_mipmap && !(flags&IF_NOMIPMAP))
|
2004-10-10 06:32:29 +00:00
|
|
|
{
|
|
|
|
TRACE(("dbg: GL_Upload32: GL_SGIS_generate_mipmap\n"));
|
2011-12-27 08:35:19 +00:00
|
|
|
qglTexParameteri(targ, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
|
2004-10-10 06:32:29 +00:00
|
|
|
}
|
2011-10-27 16:16:29 +00:00
|
|
|
|
2011-09-05 01:48:23 +00:00
|
|
|
if (!(flags&IF_NOMIPMAP))
|
|
|
|
{
|
2011-12-27 08:35:19 +00:00
|
|
|
qglTexParameteri(targ, GL_TEXTURE_MIN_FILTER, gl_filter_min);
|
2011-10-27 16:16:29 +00:00
|
|
|
if (flags & IF_NEAREST)
|
2011-12-27 08:35:19 +00:00
|
|
|
qglTexParameteri(targ, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
2011-10-27 16:16:29 +00:00
|
|
|
else
|
2011-12-27 08:35:19 +00:00
|
|
|
qglTexParameteri(targ, GL_TEXTURE_MAG_FILTER, gl_filter_max);
|
2011-09-05 01:48:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-27 08:35:19 +00:00
|
|
|
qglTexParameteri(targ, GL_TEXTURE_MIN_FILTER, gl_filter_max_2d);
|
2011-10-27 16:16:29 +00:00
|
|
|
if (flags & IF_NEAREST)
|
2011-12-27 08:35:19 +00:00
|
|
|
qglTexParameteri(targ, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
2011-10-27 16:16:29 +00:00
|
|
|
else
|
2011-12-27 08:35:19 +00:00
|
|
|
qglTexParameteri(targ, GL_TEXTURE_MAG_FILTER, gl_filter_max_2d);
|
2011-09-05 01:48:23 +00:00
|
|
|
}
|
2004-10-10 06:32:29 +00:00
|
|
|
|
2004-08-22 22:29:09 +00:00
|
|
|
if (scaled_width == width && scaled_height == height)
|
|
|
|
{
|
2009-11-04 21:16:50 +00:00
|
|
|
if ((flags&IF_NOMIPMAP)||gl_config.sgis_generate_mipmap) //gotta love this with NPOT textures... :)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
2004-10-10 06:32:29 +00:00
|
|
|
TRACE(("dbg: GL_Upload32: non-mipmapped/unscaled\n"));
|
2011-09-16 05:56:54 +00:00
|
|
|
if (type == GL_UNSIGNED_SHORT_5_6_5)
|
2011-12-27 08:35:19 +00:00
|
|
|
GL_8888to565(targ, (unsigned char *)data, (unsigned short*)scaled, 0, scaled_width, scaled_height);
|
2011-09-16 05:56:54 +00:00
|
|
|
else if (type == GL_UNSIGNED_SHORT_4_4_4_4)
|
2011-12-27 08:35:19 +00:00
|
|
|
GL_8888to4444(targ, (unsigned char *)data, (unsigned short*)scaled, 0, scaled_width, scaled_height);
|
2011-09-16 05:56:54 +00:00
|
|
|
else
|
2011-12-27 08:35:19 +00:00
|
|
|
qglTexImage2D (targ, 0, samples, scaled_width, scaled_height, 0, glcolormode, GL_UNSIGNED_BYTE, data);
|
2004-08-22 22:29:09 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
memcpy (scaled, data, width*height*4);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
GL_ResampleTexture (data, width, height, scaled, scaled_width, scaled_height);
|
|
|
|
|
2004-10-10 06:32:29 +00:00
|
|
|
TRACE(("dbg: GL_Upload32: recaled\n"));
|
2011-09-16 05:56:54 +00:00
|
|
|
if (type == GL_UNSIGNED_SHORT_5_6_5)
|
2011-12-27 08:35:19 +00:00
|
|
|
GL_8888to565(targ, (unsigned char *)scaled, (unsigned short*)uploadmemorybufferintermediate, 0, scaled_width, scaled_height);
|
2011-09-16 05:56:54 +00:00
|
|
|
else if (type == GL_UNSIGNED_SHORT_4_4_4_4)
|
2011-12-27 08:35:19 +00:00
|
|
|
GL_8888to4444(targ, (unsigned char *)scaled, (unsigned short*)uploadmemorybufferintermediate, 0, scaled_width, scaled_height);
|
2011-09-16 05:56:54 +00:00
|
|
|
else
|
2011-12-27 08:35:19 +00:00
|
|
|
qglTexImage2D (targ, 0, samples, scaled_width, scaled_height, 0, glcolormode, GL_UNSIGNED_BYTE, scaled);
|
2009-11-04 21:16:50 +00:00
|
|
|
if (!(flags&IF_NOMIPMAP) && !gl_config.sgis_generate_mipmap)
|
2005-12-01 11:40:45 +00:00
|
|
|
{
|
2004-08-22 22:29:09 +00:00
|
|
|
miplevel = 0;
|
2004-10-10 06:32:29 +00:00
|
|
|
TRACE(("dbg: GL_Upload32: mips\n"));
|
2004-08-22 22:29:09 +00:00
|
|
|
while (scaled_width > 1 || scaled_height > 1)
|
|
|
|
{
|
|
|
|
GL_MipMap ((qbyte *)scaled, scaled_width, scaled_height);
|
|
|
|
scaled_width >>= 1;
|
|
|
|
scaled_height >>= 1;
|
|
|
|
if (scaled_width < 1)
|
|
|
|
scaled_width = 1;
|
|
|
|
if (scaled_height < 1)
|
|
|
|
scaled_height = 1;
|
|
|
|
miplevel++;
|
2011-09-16 05:56:54 +00:00
|
|
|
if (type == GL_UNSIGNED_SHORT_5_6_5)
|
2011-12-27 08:35:19 +00:00
|
|
|
GL_8888to565(targ, (unsigned char *)scaled, (unsigned short*)uploadmemorybufferintermediate, miplevel, scaled_width, scaled_height);
|
2011-09-16 05:56:54 +00:00
|
|
|
else if (type == GL_UNSIGNED_SHORT_4_4_4_4)
|
2011-12-27 08:35:19 +00:00
|
|
|
GL_8888to4444(targ, (unsigned char *)scaled, (unsigned short*)uploadmemorybufferintermediate, miplevel, scaled_width, scaled_height);
|
2011-09-16 05:56:54 +00:00
|
|
|
else
|
2011-12-27 08:35:19 +00:00
|
|
|
qglTexImage2D (targ, miplevel, samples, scaled_width, scaled_height, 0, glcolormode, GL_UNSIGNED_BYTE, scaled);
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-16 05:56:54 +00:00
|
|
|
|
2011-12-27 08:35:19 +00:00
|
|
|
if (targ == GL_TEXTURE_2D && gl_config.arb_texture_compression && gl_compress.value && gl_savecompressedtex.value && name && !(flags&IF_NOMIPMAP))
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
2006-01-02 23:01:54 +00:00
|
|
|
vfsfile_t *out;
|
2004-08-22 22:29:09 +00:00
|
|
|
int miplevels;
|
|
|
|
GLint compressed;
|
|
|
|
GLint compressed_size;
|
|
|
|
GLint internalformat;
|
|
|
|
unsigned char *img;
|
|
|
|
char outname[MAX_OSPATH];
|
|
|
|
int i;
|
|
|
|
miplevels = miplevel+1;
|
2005-12-01 11:40:45 +00:00
|
|
|
qglGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_ARB, &compressed);
|
2004-08-22 22:29:09 +00:00
|
|
|
if (compressed == GL_TRUE && !strstr(name, "..")) //is there any point in bothering with the whole endian thing?
|
|
|
|
{
|
2011-07-22 15:11:35 +00:00
|
|
|
Q_snprintfz(outname, sizeof(outname), "tex/%s.tex", name);
|
2006-01-02 23:01:54 +00:00
|
|
|
FS_CreatePath(outname, FS_GAME);
|
|
|
|
out = FS_OpenVFS(outname, "wb", FS_GAME);
|
2004-08-22 22:29:09 +00:00
|
|
|
if (out)
|
|
|
|
{
|
|
|
|
i = LittleLong(miplevels);
|
2006-01-02 23:01:54 +00:00
|
|
|
VFS_WRITE(out, &i, sizeof(i));
|
2004-08-22 22:29:09 +00:00
|
|
|
i = LittleLong(width);
|
2006-01-02 23:01:54 +00:00
|
|
|
VFS_WRITE(out, &i, sizeof(i));
|
2004-08-22 22:29:09 +00:00
|
|
|
i = LittleLong(height);
|
2006-01-02 23:01:54 +00:00
|
|
|
VFS_WRITE(out, &i, sizeof(i));
|
2009-11-04 21:16:50 +00:00
|
|
|
i = LittleLong(flags);
|
2006-01-02 23:01:54 +00:00
|
|
|
VFS_WRITE(out, &i, sizeof(i));
|
2004-08-22 22:29:09 +00:00
|
|
|
for (miplevel = 0; miplevel < miplevels; miplevel++)
|
|
|
|
{
|
2005-01-07 02:59:56 +00:00
|
|
|
qglGetTexLevelParameteriv(GL_TEXTURE_2D, miplevel, GL_TEXTURE_COMPRESSED_ARB, &compressed);
|
|
|
|
qglGetTexLevelParameteriv(GL_TEXTURE_2D, miplevel, GL_TEXTURE_INTERNAL_FORMAT, &internalformat);
|
|
|
|
qglGetTexLevelParameteriv(GL_TEXTURE_2D, miplevel, GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB, &compressed_size);
|
|
|
|
qglGetTexLevelParameteriv(GL_TEXTURE_2D, miplevel, GL_TEXTURE_WIDTH, &width);
|
|
|
|
qglGetTexLevelParameteriv(GL_TEXTURE_2D, miplevel, GL_TEXTURE_HEIGHT, &height);
|
2004-08-22 22:29:09 +00:00
|
|
|
img = (unsigned char *)BZ_Malloc(compressed_size * sizeof(unsigned char));
|
|
|
|
qglGetCompressedTexImageARB(GL_TEXTURE_2D, miplevel, img);
|
|
|
|
|
|
|
|
i = LittleLong(width);
|
2006-01-02 23:01:54 +00:00
|
|
|
VFS_WRITE(out, &i, sizeof(i));
|
2004-08-22 22:29:09 +00:00
|
|
|
i = LittleLong(height);
|
2006-01-02 23:01:54 +00:00
|
|
|
VFS_WRITE(out, &i, sizeof(i));
|
2004-08-22 22:29:09 +00:00
|
|
|
i = LittleLong(compressed_size);
|
2006-01-02 23:01:54 +00:00
|
|
|
VFS_WRITE(out, &i, sizeof(i));
|
2004-08-22 22:29:09 +00:00
|
|
|
i = LittleLong(internalformat);
|
2006-01-02 23:01:54 +00:00
|
|
|
VFS_WRITE(out, &i, sizeof(i));
|
|
|
|
VFS_WRITE(out, img, compressed_size);
|
2004-08-22 22:29:09 +00:00
|
|
|
BZ_Free(img);
|
|
|
|
}
|
2006-01-02 23:01:54 +00:00
|
|
|
VFS_CLOSE(out);
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-10-10 06:32:29 +00:00
|
|
|
done:
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2006-06-04 02:25:10 +00:00
|
|
|
if (gl_anisotropy_factor)
|
|
|
|
qglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, gl_anisotropy_factor); // without this, you could loose anisotropy on mapchange
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2011-09-05 01:48:23 +00:00
|
|
|
if (gl_config.sgis_generate_mipmap && !(flags&IF_NOMIPMAP))
|
2011-12-27 08:35:19 +00:00
|
|
|
qglTexParameteri(targ, GL_GENERATE_MIPMAP_SGIS, GL_FALSE);
|
2012-01-01 02:26:42 +00:00
|
|
|
|
|
|
|
/*apply this flag after, so that we can safely change the base (to avoid drivers just not uploading lower mips)*/
|
|
|
|
if (flags & IF_MIPCAP)
|
|
|
|
{
|
|
|
|
qglTexParameteri(targ, GL_TEXTURE_BASE_LEVEL, gl_mipcap_min);
|
|
|
|
qglTexParameteri(targ, GL_TEXTURE_MAX_LEVEL, gl_mipcap_max);
|
|
|
|
}
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
void GL_Upload32 (char *name, unsigned *data, int width, int height, unsigned int flags)
|
2008-11-09 22:29:28 +00:00
|
|
|
{
|
2009-11-04 21:16:50 +00:00
|
|
|
GL_Upload32_Int(name, data, width, height, flags, GL_RGBA);
|
2008-11-09 22:29:28 +00:00
|
|
|
}
|
2009-11-04 21:16:50 +00:00
|
|
|
void GL_Upload32_BGRA (char *name, unsigned *data, int width, int height, unsigned int flags)
|
2008-11-09 22:29:28 +00:00
|
|
|
{
|
2009-11-04 21:16:50 +00:00
|
|
|
GL_Upload32_Int(name, data, width, height, flags, GL_BGRA_EXT);
|
2008-11-09 22:29:28 +00:00
|
|
|
}
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
void GL_Upload24BGR (char *name, qbyte *framedata, int inwidth, int inheight, unsigned int flags)
|
2006-03-06 01:41:09 +00:00
|
|
|
{
|
|
|
|
int outwidth, outheight;
|
|
|
|
int y, x;
|
|
|
|
|
|
|
|
int v;
|
|
|
|
unsigned int f, fstep;
|
|
|
|
qbyte *src, *dest;
|
|
|
|
dest = uploadmemorybufferintermediate;
|
|
|
|
//change from bgr bottomup to rgba topdown
|
|
|
|
|
|
|
|
for (outwidth = 1; outwidth < inwidth; outwidth*=2)
|
|
|
|
;
|
|
|
|
for (outheight = 1; outheight < inheight; outheight*=2)
|
|
|
|
;
|
|
|
|
|
|
|
|
if (outwidth > 512)
|
|
|
|
outwidth = 512;
|
|
|
|
if (outheight > 512)
|
|
|
|
outheight = 512;
|
|
|
|
|
|
|
|
if (outwidth*outheight > sizeofuploadmemorybufferintermediate/4)
|
|
|
|
Sys_Error("MediaGL_ShowFrameBGR_24_Flip: image too big (%i*%i)", inwidth, inheight);
|
|
|
|
|
|
|
|
for (y=0 ; y<outheight ; y++)
|
|
|
|
{
|
|
|
|
v = (y*(float)inheight/outheight);
|
|
|
|
src = framedata + v*(inwidth*3);
|
|
|
|
{
|
|
|
|
f = 0;
|
|
|
|
fstep = ((inwidth)*0x10000)/outwidth;
|
|
|
|
|
|
|
|
for (x=outwidth ; x&3 ; x--) //do the odd ones first. (bigger condition)
|
|
|
|
{
|
|
|
|
*dest++ = src[(f>>16)*3+2];
|
|
|
|
*dest++ = src[(f>>16)*3+1];
|
|
|
|
*dest++ = src[(f>>16)*3+0];
|
|
|
|
*dest++ = 255;
|
|
|
|
f += fstep;
|
|
|
|
}
|
|
|
|
for ( ; x ; x-=4) //loop through the remaining chunks.
|
|
|
|
{
|
|
|
|
dest[0] = src[(f>>16)*3+2];
|
|
|
|
dest[1] = src[(f>>16)*3+1];
|
|
|
|
dest[2] = src[(f>>16)*3+0];
|
|
|
|
dest[3] = 255;
|
|
|
|
f += fstep;
|
|
|
|
|
|
|
|
dest[4] = src[(f>>16)*3+2];
|
|
|
|
dest[5] = src[(f>>16)*3+1];
|
|
|
|
dest[6] = src[(f>>16)*3+0];
|
|
|
|
dest[7] = 255;
|
|
|
|
f += fstep;
|
|
|
|
|
|
|
|
dest[8] = src[(f>>16)*3+2];
|
|
|
|
dest[9] = src[(f>>16)*3+1];
|
|
|
|
dest[10] = src[(f>>16)*3+0];
|
|
|
|
dest[11] = 255;
|
|
|
|
f += fstep;
|
|
|
|
|
|
|
|
dest[12] = src[(f>>16)*3+2];
|
|
|
|
dest[13] = src[(f>>16)*3+1];
|
|
|
|
dest[14] = src[(f>>16)*3+0];
|
|
|
|
dest[15] = 255;
|
|
|
|
f += fstep;
|
|
|
|
|
|
|
|
dest += 16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
GL_Upload32 (name, (unsigned int*)uploadmemorybufferintermediate, outwidth, outheight, flags);
|
2006-03-06 01:41:09 +00:00
|
|
|
}
|
2009-11-04 21:16:50 +00:00
|
|
|
void GL_Upload24BGR_Flip (char *name, qbyte *framedata, int inwidth, int inheight, unsigned int flags)
|
2006-03-06 01:41:09 +00:00
|
|
|
{
|
|
|
|
int outwidth, outheight;
|
|
|
|
int y, x;
|
|
|
|
|
|
|
|
int v;
|
|
|
|
unsigned int f, fstep;
|
|
|
|
qbyte *src, *dest;
|
|
|
|
dest = uploadmemorybufferintermediate;
|
|
|
|
//change from bgr bottomup to rgba topdown
|
|
|
|
|
|
|
|
for (outwidth = 1; outwidth < inwidth; outwidth*=2)
|
|
|
|
;
|
|
|
|
for (outheight = 1; outheight < inheight; outheight*=2)
|
|
|
|
;
|
|
|
|
|
|
|
|
if (outwidth > 512)
|
|
|
|
outwidth = 512;
|
|
|
|
if (outheight > 512)
|
|
|
|
outheight = 512;
|
|
|
|
|
|
|
|
if (outwidth*outheight > sizeofuploadmemorybufferintermediate/4)
|
|
|
|
Sys_Error("MediaGL_ShowFrameBGR_24_Flip: image too big (%i*%i)", inwidth, inheight);
|
|
|
|
|
|
|
|
for (y=1 ; y<=outheight ; y++)
|
|
|
|
{
|
|
|
|
v = ((outheight - y)*(float)inheight/outheight);
|
|
|
|
src = framedata + v*(inwidth*3);
|
|
|
|
{
|
|
|
|
f = 0;
|
|
|
|
fstep = ((inwidth)*0x10000)/outwidth;
|
|
|
|
|
|
|
|
for (x=outwidth ; x&3 ; x--) //do the odd ones first. (bigger condition)
|
|
|
|
{
|
|
|
|
*dest++ = src[(f>>16)*3+2];
|
|
|
|
*dest++ = src[(f>>16)*3+1];
|
|
|
|
*dest++ = src[(f>>16)*3+0];
|
|
|
|
*dest++ = 255;
|
|
|
|
f += fstep;
|
|
|
|
}
|
|
|
|
for ( ; x ; x-=4) //loop through the remaining chunks.
|
|
|
|
{
|
|
|
|
dest[0] = src[(f>>16)*3+2];
|
|
|
|
dest[1] = src[(f>>16)*3+1];
|
|
|
|
dest[2] = src[(f>>16)*3+0];
|
|
|
|
dest[3] = 255;
|
|
|
|
f += fstep;
|
|
|
|
|
|
|
|
dest[4] = src[(f>>16)*3+2];
|
|
|
|
dest[5] = src[(f>>16)*3+1];
|
|
|
|
dest[6] = src[(f>>16)*3+0];
|
|
|
|
dest[7] = 255;
|
|
|
|
f += fstep;
|
|
|
|
|
|
|
|
dest[8] = src[(f>>16)*3+2];
|
|
|
|
dest[9] = src[(f>>16)*3+1];
|
|
|
|
dest[10] = src[(f>>16)*3+0];
|
|
|
|
dest[11] = 255;
|
|
|
|
f += fstep;
|
|
|
|
|
|
|
|
dest[12] = src[(f>>16)*3+2];
|
|
|
|
dest[13] = src[(f>>16)*3+1];
|
|
|
|
dest[14] = src[(f>>16)*3+0];
|
|
|
|
dest[15] = 255;
|
|
|
|
f += fstep;
|
|
|
|
|
|
|
|
dest += 16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
GL_Upload32 (name, (unsigned int*)uploadmemorybufferintermediate, outwidth, outheight, flags);
|
2006-03-06 01:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
void GL_Upload8Grey (unsigned char*data, int width, int height, unsigned int flags)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
int samples;
|
|
|
|
unsigned char *scaled = uploadmemorybuffer;
|
|
|
|
int scaled_width, scaled_height;
|
|
|
|
|
2004-12-08 04:02:57 +00:00
|
|
|
scaled_width = width;
|
|
|
|
scaled_height = height;
|
2009-11-04 21:16:50 +00:00
|
|
|
GL_RoundDimensions(&scaled_width, &scaled_height, !(flags&IF_NOMIPMAP));
|
2004-10-10 06:32:29 +00:00
|
|
|
|
2004-08-22 22:29:09 +00:00
|
|
|
if (scaled_width * scaled_height > sizeofuploadmemorybuffer/4)
|
|
|
|
Sys_Error ("GL_LoadTexture: too big");
|
|
|
|
|
|
|
|
samples = 1;//alpha ? gl_alpha_format : gl_solid_format;
|
|
|
|
|
|
|
|
if (scaled_width == width && scaled_height == height)
|
|
|
|
{
|
2009-11-04 21:16:50 +00:00
|
|
|
if (flags&IF_NOMIPMAP)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
2005-01-07 02:59:56 +00:00
|
|
|
qglTexImage2D (GL_TEXTURE_2D, 0, samples, scaled_width, scaled_height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, data);
|
2004-08-22 22:29:09 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
memcpy (scaled, data, width*height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
GL_Resample8BitTexture (data, width, height, scaled, scaled_width, scaled_height);
|
|
|
|
|
2005-01-07 02:59:56 +00:00
|
|
|
qglTexImage2D (GL_TEXTURE_2D, 0, samples, scaled_width, scaled_height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, scaled);
|
2009-11-04 21:16:50 +00:00
|
|
|
if (!(flags&IF_NOMIPMAP))
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
int miplevel;
|
|
|
|
|
|
|
|
miplevel = 0;
|
|
|
|
while (scaled_width > 1 || scaled_height > 1)
|
|
|
|
{
|
|
|
|
GL_MipMap ((qbyte *)scaled, scaled_width, scaled_height);
|
|
|
|
scaled_width >>= 1;
|
|
|
|
scaled_height >>= 1;
|
|
|
|
if (scaled_width < 1)
|
|
|
|
scaled_width = 1;
|
|
|
|
if (scaled_height < 1)
|
|
|
|
scaled_height = 1;
|
|
|
|
miplevel++;
|
2005-01-07 02:59:56 +00:00
|
|
|
qglTexImage2D (GL_TEXTURE_2D, miplevel, samples, scaled_width, scaled_height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, scaled);
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
done: ;
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
if (!(flags&IF_NOMIPMAP))
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
2009-11-04 21:16:50 +00:00
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_min);
|
2011-10-27 16:16:29 +00:00
|
|
|
if (flags & IF_NEAREST)
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
else
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max);
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-11-04 21:16:50 +00:00
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_max_2d);
|
2011-10-27 16:16:29 +00:00
|
|
|
if (flags & IF_NEAREST)
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
else
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max_2d);
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GL_MipMapNormal (qbyte *in, int width, int height)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
qbyte *out;
|
|
|
|
float inv255 = 1.0f/255.0f;
|
|
|
|
float inv127 = 1.0f/127.0f;
|
|
|
|
float x,y,z,l,mag00,mag01,mag10,mag11;
|
|
|
|
|
|
|
|
|
|
|
|
width <<=2;
|
|
|
|
height >>= 1;
|
|
|
|
out = in;
|
|
|
|
for (i=0 ; i<height ; i++, in+=width)
|
|
|
|
{
|
|
|
|
for (j=0 ; j<width ; j+=8, out+=4, in+=8)
|
|
|
|
{
|
|
|
|
|
|
|
|
mag00 = inv255 * in[3];
|
|
|
|
mag01 = inv255 * in[7];
|
|
|
|
mag10 = inv255 * in[width+3];
|
|
|
|
mag11 = inv255 * in[width+7];
|
|
|
|
|
|
|
|
x = mag00*(inv127*in[0]-1.0)+
|
|
|
|
mag01*(inv127*in[4]-1.0)+
|
|
|
|
mag10*(inv127*in[width+0]-1.0)+
|
|
|
|
mag11*(inv127*in[width+4]-1.0);
|
|
|
|
y = mag00*(inv127*in[1]-1.0)+
|
|
|
|
mag01*(inv127*in[5]-1.0)+
|
|
|
|
mag10*(inv127*in[width+1]-1.0)+
|
|
|
|
mag11*(inv127*in[width+5]-1.0);
|
|
|
|
z = mag00*(inv127*in[2]-1.0)+
|
|
|
|
mag01*(inv127*in[6]-1.0)+
|
|
|
|
mag10*(inv127*in[width+2]-1.0)+
|
|
|
|
mag11*(inv127*in[width+6]-1.0);
|
|
|
|
|
|
|
|
l = sqrt(x*x+y*y+z*z);
|
|
|
|
if (l == 0.0) {
|
|
|
|
x = 0.0;
|
|
|
|
y = 0.0;
|
|
|
|
z = 1.0;
|
|
|
|
} else {
|
|
|
|
//normalize it.
|
|
|
|
l=1/l;
|
|
|
|
x *=l;
|
|
|
|
y *=l;
|
|
|
|
z *=l;
|
|
|
|
}
|
|
|
|
out[0] = (unsigned char)128 + 127*x;
|
|
|
|
out[1] = (unsigned char)128 + 127*y;
|
|
|
|
out[2] = (unsigned char)128 + 127*z;
|
|
|
|
|
|
|
|
l = l/4.0;
|
|
|
|
if (l > 1.0) {
|
|
|
|
out[3] = 255;
|
|
|
|
} else {
|
|
|
|
out[3] = (qbyte)(255.0*l);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//PENTA
|
|
|
|
|
|
|
|
//sizeofuploadmemorybufferintermediate is guarenteed to be bigger or equal to the normal uploadbuffer size
|
|
|
|
unsigned int * genNormalMap(qbyte *pixels, int w, int h, float scale)
|
|
|
|
{
|
|
|
|
int i, j, wr, hr;
|
|
|
|
unsigned char r, g, b;
|
|
|
|
unsigned *nmap = (unsigned *)uploadmemorybufferintermediate;
|
|
|
|
float sqlen, reciplen, nx, ny, nz;
|
|
|
|
|
|
|
|
const float oneOver255 = 1.0f/255.0f;
|
|
|
|
|
|
|
|
float c, cx, cy, dcx, dcy;
|
|
|
|
|
|
|
|
wr = w;
|
|
|
|
hr = h;
|
|
|
|
|
|
|
|
for (i=0; i<h; i++) {
|
|
|
|
for (j=0; j<w; j++) {
|
|
|
|
/* Expand [0,255] texel values to the [0,1] range. */
|
|
|
|
c = pixels[i*wr + j] * oneOver255;
|
|
|
|
/* Expand the texel to its right. */
|
|
|
|
cx = pixels[i*wr + (j+1)%wr] * oneOver255;
|
|
|
|
/* Expand the texel one up. */
|
|
|
|
cy = pixels[((i+1)%hr)*wr + j] * oneOver255;
|
|
|
|
dcx = scale * (c - cx);
|
|
|
|
dcy = scale * (c - cy);
|
|
|
|
|
|
|
|
/* Normalize the vector. */
|
|
|
|
sqlen = dcx*dcx + dcy*dcy + 1;
|
|
|
|
reciplen = 1.0f/(float)sqrt(sqlen);
|
|
|
|
nx = dcx*reciplen;
|
|
|
|
ny = -dcy*reciplen;
|
|
|
|
nz = reciplen;
|
|
|
|
|
|
|
|
/* Repack the normalized vector into an RGB unsigned qbyte
|
|
|
|
vector in the normal map image. */
|
|
|
|
r = (qbyte) (128 + 127*nx);
|
|
|
|
g = (qbyte) (128 + 127*ny);
|
|
|
|
b = (qbyte) (128 + 127*nz);
|
|
|
|
|
|
|
|
/* The highest resolution mipmap level always has a
|
|
|
|
unit length magnitude. */
|
2005-08-03 23:14:59 +00:00
|
|
|
nmap[i*w+j] = LittleLong ((pixels[i*wr + j] << 24)|(b << 16)|(g << 8)|(r)); // <AWE> Added support for big endian.
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &nmap[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
//PENTA
|
2005-08-03 23:14:59 +00:00
|
|
|
void GL_UploadBump(qbyte *data, int width, int height, qboolean mipmap, float bumpscale)
|
2004-12-08 04:02:57 +00:00
|
|
|
{
|
2004-08-22 22:29:09 +00:00
|
|
|
unsigned char *scaled = uploadmemorybuffer;
|
|
|
|
int scaled_width, scaled_height;
|
|
|
|
qbyte *nmap;
|
|
|
|
|
2004-10-10 06:32:29 +00:00
|
|
|
TRACE(("dbg: GL_UploadBump entered: %i %i\n", width, height));
|
|
|
|
|
2004-12-08 04:02:57 +00:00
|
|
|
scaled_width = width;
|
|
|
|
scaled_height = height;
|
|
|
|
GL_RoundDimensions(&scaled_width, &scaled_height, mipmap);
|
2004-10-10 06:32:29 +00:00
|
|
|
|
2004-08-22 22:29:09 +00:00
|
|
|
if (scaled_width * scaled_height > sizeofuploadmemorybuffer/4)
|
|
|
|
Sys_Error ("GL_LoadTexture: too big");
|
|
|
|
|
|
|
|
//To resize or not to resize
|
|
|
|
if (scaled_width == width && scaled_height == height)
|
|
|
|
{
|
|
|
|
memcpy (scaled, data, width*height);
|
|
|
|
scaled_width = width;
|
|
|
|
scaled_height = height;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
//Just picks pixels so grayscale is equivalent with 8 bit.
|
|
|
|
GL_Resample8BitTexture (data, width, height, scaled, scaled_width, scaled_height);
|
|
|
|
}
|
|
|
|
|
2005-08-03 23:14:59 +00:00
|
|
|
nmap = (qbyte *)genNormalMap(scaled,scaled_width,scaled_height,bumpscale);
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2005-01-07 02:59:56 +00:00
|
|
|
qglTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA
|
2004-08-22 22:29:09 +00:00
|
|
|
, scaled_width, scaled_height, 0,
|
|
|
|
GL_RGBA, GL_UNSIGNED_BYTE, nmap);
|
|
|
|
|
|
|
|
//glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
//glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
if (mipmap)
|
|
|
|
{
|
|
|
|
int miplevel;
|
|
|
|
|
|
|
|
miplevel = 0;
|
|
|
|
while (scaled_width > 1 || scaled_height > 1)
|
|
|
|
{
|
2011-12-05 15:23:40 +00:00
|
|
|
GL_MipMap(nmap,scaled_width,scaled_height);
|
2004-08-22 22:29:09 +00:00
|
|
|
//GL_MipMapGray((qbyte *)scaled, scaled_width, scaled_height);
|
|
|
|
scaled_width >>= 1;
|
|
|
|
scaled_height >>= 1;
|
|
|
|
if (scaled_width < 1)
|
|
|
|
scaled_width = 1;
|
|
|
|
if (scaled_height < 1)
|
|
|
|
scaled_height = 1;
|
|
|
|
miplevel++;
|
|
|
|
|
2005-01-07 02:59:56 +00:00
|
|
|
qglTexImage2D (GL_TEXTURE_2D, miplevel, GL_RGBA, scaled_width, scaled_height, 0, GL_RGBA,
|
2004-08-22 22:29:09 +00:00
|
|
|
GL_UNSIGNED_BYTE, nmap);
|
|
|
|
//glTexImage2D (GL_TEXTURE_2D, miplevel, GL_RGBA, scaled_width, scaled_height, 0, GL_RGBA,
|
|
|
|
// GL_UNSIGNED_BYTE, genNormalMap(scaled,scaled_width,scaled_height,4.0f));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mipmap)
|
|
|
|
{
|
2009-11-04 21:16:50 +00:00
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_min);
|
2011-10-27 16:16:29 +00:00
|
|
|
if (0 & IF_NEAREST)
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
else
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max);
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-11-04 21:16:50 +00:00
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_max_2d);
|
2011-10-27 16:16:29 +00:00
|
|
|
if (0 & IF_NEAREST)
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
else
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max_2d);
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if (gl_texturefilteranisotropic)
|
|
|
|
// glTexParameterfv (GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, &gl_texureanisotropylevel);
|
|
|
|
|
2004-10-10 06:32:29 +00:00
|
|
|
TRACE(("dbg: GL_UploadBump: escaped %i %i\n", width, height));
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef GL_USE8BITTEX
|
|
|
|
#ifdef GL_EXT_paletted_texture
|
2005-12-01 11:40:45 +00:00
|
|
|
void GL_Upload8_EXT (qbyte *data, int width, int height, qboolean mipmap, qboolean alpha)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
int i, s;
|
|
|
|
qboolean noalpha;
|
|
|
|
int samples;
|
|
|
|
unsigned char *scaled = uploadmemorybuffer;
|
|
|
|
int scaled_width, scaled_height;
|
|
|
|
|
|
|
|
GLDraw_Init15to8();
|
|
|
|
|
|
|
|
s = width*height;
|
|
|
|
// if there are no transparent pixels, make it a 3 component
|
|
|
|
// texture even if it was specified as otherwise
|
|
|
|
if (alpha)
|
|
|
|
{
|
|
|
|
noalpha = true;
|
|
|
|
for (i=0 ; i<s ; i++)
|
|
|
|
{
|
|
|
|
if (data[i] == 255)
|
|
|
|
noalpha = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alpha && noalpha)
|
|
|
|
alpha = false;
|
|
|
|
}
|
|
|
|
|
2004-12-08 04:02:57 +00:00
|
|
|
scaled_width = width;
|
|
|
|
scaled_height = height;
|
|
|
|
GL_RoundDimensions(&scaled_width, &scaled_height, mipmap);
|
2004-10-10 06:32:29 +00:00
|
|
|
|
2004-08-22 22:29:09 +00:00
|
|
|
if (scaled_width * scaled_height > sizeofuploadmemorybufferintermediate/4)
|
|
|
|
Sys_Error ("GL_LoadTexture: too big");
|
|
|
|
|
|
|
|
samples = 1; // alpha ? gl_alpha_format : gl_solid_format;
|
|
|
|
|
|
|
|
if (scaled_width == width && scaled_height == height)
|
|
|
|
{
|
|
|
|
if (!mipmap)
|
|
|
|
{
|
|
|
|
glTexImage2D (GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, scaled_width, scaled_height, 0, GL_COLOR_INDEX , GL_UNSIGNED_BYTE, data);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
memcpy (scaled, data, width*height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
GL_Resample8BitTexture (data, width, height, scaled, scaled_width, scaled_height);
|
|
|
|
|
|
|
|
glTexImage2D (GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, scaled_width, scaled_height, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, scaled);
|
|
|
|
if (mipmap)
|
|
|
|
{
|
|
|
|
int miplevel;
|
|
|
|
|
|
|
|
miplevel = 0;
|
|
|
|
while (scaled_width > 1 || scaled_height > 1)
|
|
|
|
{
|
|
|
|
GL_MipMap8Bit ((qbyte *)scaled, scaled_width, scaled_height);
|
|
|
|
scaled_width >>= 1;
|
|
|
|
scaled_height >>= 1;
|
|
|
|
if (scaled_width < 1)
|
|
|
|
scaled_width = 1;
|
|
|
|
if (scaled_height < 1)
|
|
|
|
scaled_height = 1;
|
|
|
|
miplevel++;
|
|
|
|
glTexImage2D (GL_TEXTURE_2D, miplevel, GL_COLOR_INDEX8_EXT, scaled_width, scaled_height, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, scaled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
done: ;
|
|
|
|
|
|
|
|
if (mipmap)
|
|
|
|
{
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_min);
|
2011-10-27 16:16:29 +00:00
|
|
|
if (flags & IF_NEAREST)
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
else
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max);
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-06-10 05:14:38 +00:00
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_max_2d);
|
2011-10-27 16:16:29 +00:00
|
|
|
if (flags & IF_NEAREST)
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
else
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max_2d);
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
GL_Upload8
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
int ColorIndex[16] =
|
|
|
|
{
|
|
|
|
0, 31, 47, 63, 79, 95, 111, 127, 143, 159, 175, 191, 199, 207, 223, 231
|
|
|
|
};
|
|
|
|
|
|
|
|
unsigned ColorPercent[16] =
|
|
|
|
{
|
|
|
|
25, 51, 76, 102, 114, 127, 140, 153, 165, 178, 191, 204, 216, 229, 237, 247
|
|
|
|
};
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
void GL_Upload8 (char *name, qbyte *data, int width, int height, unsigned int flags, unsigned int alpha)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
unsigned *trans = (unsigned *)uploadmemorybufferintermediate;
|
|
|
|
int i, s;
|
|
|
|
qboolean noalpha;
|
|
|
|
int p;
|
|
|
|
|
|
|
|
if (width*height > sizeofuploadmemorybufferintermediate/4)
|
|
|
|
Sys_Error("GL_Upload8: image too big (%i*%i)", width, height);
|
|
|
|
|
|
|
|
s = width*height;
|
|
|
|
// if there are no transparent pixels, make it a 3 component
|
|
|
|
// texture even if it was specified as otherwise
|
2009-11-04 21:16:50 +00:00
|
|
|
if (alpha && !(flags & IF_NOALPHA))
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
noalpha = true;
|
|
|
|
for (i=0 ; i<s ; i++)
|
|
|
|
{
|
|
|
|
p = data[i];
|
|
|
|
if (p == 255)
|
2005-09-15 05:55:43 +00:00
|
|
|
{
|
2004-08-22 22:29:09 +00:00
|
|
|
noalpha = false;
|
2005-09-15 05:55:43 +00:00
|
|
|
trans[i] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
trans[i] = d_8to24rgbtable[p];
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch( alpha )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
if (alpha && noalpha)
|
|
|
|
alpha = false;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
alpha = true;
|
|
|
|
for (i=0 ; i<s ; i++)
|
|
|
|
{
|
|
|
|
p = data[i];
|
|
|
|
if (p == 0)
|
|
|
|
trans[i] &= 0x00ffffff;
|
|
|
|
else if( p & 1 )
|
|
|
|
{
|
|
|
|
trans[i] &= 0x00ffffff;
|
|
|
|
trans[i] |= ( ( int )( 255 * 0.5 ) ) << 24;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
trans[i] |= 0xff000000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
alpha = true;
|
|
|
|
for (i=0 ; i<s ; i++)
|
|
|
|
{
|
|
|
|
p = data[i];
|
|
|
|
if (p == 0)
|
|
|
|
trans[i] &= 0x00ffffff;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
alpha = true;
|
|
|
|
for (i=0 ; i<s ; i++)
|
|
|
|
{
|
|
|
|
p = data[i];
|
|
|
|
trans[i] = d_8to24rgbtable[ColorIndex[p>>4]] & 0x00ffffff;
|
|
|
|
trans[i] |= ( int )ColorPercent[p&15] << 24;
|
|
|
|
//trans[i] = 0x7fff0000;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-11-04 21:16:50 +00:00
|
|
|
//2:H2_T7G1
|
|
|
|
//3:H2_TRANS8_0
|
|
|
|
//4:H2_T4A4
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-03-20 02:57:11 +00:00
|
|
|
for (i=(s&~3)-4 ; i>=0 ; i-=4)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
2010-12-05 02:46:07 +00:00
|
|
|
trans[i] = d_8to24rgbtable[data[i]]|0xff000000;
|
|
|
|
trans[i+1] = d_8to24rgbtable[data[i+1]]|0xff000000;
|
|
|
|
trans[i+2] = d_8to24rgbtable[data[i+2]]|0xff000000;
|
|
|
|
trans[i+3] = d_8to24rgbtable[data[i+3]]|0xff000000;
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
2005-03-20 02:57:11 +00:00
|
|
|
for (i=s&~3 ; i<s ; i++) //wow, funky
|
|
|
|
{
|
|
|
|
trans[i] = d_8to24rgbtable[data[i]];
|
|
|
|
}
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef GL_USE8BITTEX
|
|
|
|
#ifdef GL_EXT_paletted_texture
|
|
|
|
if (GLVID_Is8bit() && !alpha && (data!=scrap_texels[0])) {
|
|
|
|
GL_Upload8_EXT (data, width, height, mipmap, alpha);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
2011-02-25 04:22:14 +00:00
|
|
|
checkglerror();
|
2009-11-04 21:16:50 +00:00
|
|
|
GL_Upload32 (name, trans, width, height, flags);
|
2011-02-25 04:22:14 +00:00
|
|
|
checkglerror();
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
void GL_Upload8FB (qbyte *data, int width, int height, unsigned flags)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
unsigned *trans = (unsigned *)uploadmemorybufferintermediate;
|
|
|
|
int i, s;
|
|
|
|
int p;
|
|
|
|
|
|
|
|
s = width*height;
|
|
|
|
if (s > sizeofuploadmemorybufferintermediate/4)
|
|
|
|
Sys_Error("GL_Upload8FB: image too big (%i*%i)", width, height);
|
|
|
|
// if there are no transparent pixels, make it a 3 component
|
|
|
|
// texture even if it was specified as otherwise
|
|
|
|
for (i=0 ; i<s ; i++)
|
|
|
|
{
|
|
|
|
p = data[i];
|
|
|
|
if (p <= 255-vid.fullbright)
|
|
|
|
trans[i] = 0;
|
|
|
|
else
|
|
|
|
trans[i] = d_8to24rgbtable[p];
|
|
|
|
}
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
GL_Upload32 (NULL, trans, width, height, flags);
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
void GL_Upload8Pal24 (qbyte *data, qbyte *pal, int width, int height, unsigned int flags)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
qbyte *trans = uploadmemorybufferintermediate;
|
|
|
|
int i, s;
|
|
|
|
qboolean noalpha;
|
|
|
|
int p;
|
|
|
|
extern qbyte gammatable[256];
|
2006-02-27 00:42:25 +00:00
|
|
|
extern qboolean gammaworks;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
s = width*height;
|
|
|
|
if (s > sizeofuploadmemorybufferintermediate/4)
|
|
|
|
Sys_Error("GL_Upload8Pal24: image too big (%i*%i)", width, height);
|
|
|
|
|
|
|
|
// if there are no transparent pixels, make it a 3 component
|
|
|
|
// texture even if it was specified as otherwise
|
2006-02-27 00:42:25 +00:00
|
|
|
if (gammaworks)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
2009-11-04 21:16:50 +00:00
|
|
|
if (!(flags & IF_NOALPHA))
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
2006-02-27 00:42:25 +00:00
|
|
|
noalpha = true;
|
|
|
|
for (i=0 ; i<s ; i++)
|
|
|
|
{
|
|
|
|
p = data[i];
|
|
|
|
if (p == 255)
|
|
|
|
noalpha = false;
|
|
|
|
trans[(i<<2)+0] = pal[p*3+0];
|
|
|
|
trans[(i<<2)+1] = pal[p*3+1];
|
|
|
|
trans[(i<<2)+2] = pal[p*3+2];
|
|
|
|
trans[(i<<2)+3] = (p==255)?0:255;
|
|
|
|
}
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
if (noalpha)
|
|
|
|
flags |= IF_NOALPHA;
|
2006-02-27 00:42:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (s&3)
|
|
|
|
Sys_Error ("GL_Upload8: s&3");
|
|
|
|
for (i=0 ; i<s ; i+=1)
|
|
|
|
{
|
|
|
|
trans[(i<<2)+0] = pal[data[i]*3+0];
|
|
|
|
trans[(i<<2)+1] = pal[data[i]*3+1];
|
|
|
|
trans[(i<<2)+2] = pal[data[i]*3+2];
|
|
|
|
trans[(i<<2)+3] = 255;
|
|
|
|
}
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2006-02-27 00:42:25 +00:00
|
|
|
else
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
2009-11-04 21:16:50 +00:00
|
|
|
if (!(flags & IF_NOALPHA))
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
2006-02-27 00:42:25 +00:00
|
|
|
noalpha = true;
|
|
|
|
for (i=0 ; i<s ; i++)
|
|
|
|
{
|
|
|
|
p = data[i];
|
|
|
|
if (p == 255)
|
|
|
|
noalpha = false;
|
|
|
|
trans[(i<<2)+0] = gammatable[pal[p*3+0]];
|
|
|
|
trans[(i<<2)+1] = gammatable[pal[p*3+1]];
|
|
|
|
trans[(i<<2)+2] = gammatable[pal[p*3+2]];
|
|
|
|
trans[(i<<2)+3] = (p==255)?0:255;
|
|
|
|
}
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
if (noalpha)
|
|
|
|
flags |= IF_NOALPHA;
|
2006-02-27 00:42:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (s&3)
|
|
|
|
Sys_Error ("GL_Upload8: s&3");
|
|
|
|
for (i=0 ; i<s ; i+=1)
|
|
|
|
{
|
|
|
|
trans[(i<<2)+0] = gammatable[pal[data[i]*3+0]];
|
|
|
|
trans[(i<<2)+1] = gammatable[pal[data[i]*3+1]];
|
|
|
|
trans[(i<<2)+2] = gammatable[pal[data[i]*3+2]];
|
|
|
|
trans[(i<<2)+3] = 255;
|
|
|
|
}
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-04 21:16:50 +00:00
|
|
|
GL_Upload32 (NULL, (unsigned*)trans, width, height, flags);
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
2010-07-11 02:22:39 +00:00
|
|
|
static void GL_Upload8Pal32 (qbyte *data, qbyte *pal, int width, int height, unsigned int flags)
|
2005-05-13 10:42:48 +00:00
|
|
|
{
|
|
|
|
qbyte *trans = uploadmemorybufferintermediate;
|
|
|
|
int i, s;
|
|
|
|
extern qbyte gammatable[256];
|
|
|
|
|
|
|
|
s = width*height;
|
|
|
|
if (s > sizeofuploadmemorybufferintermediate/4)
|
|
|
|
Sys_Error("GL_Upload8Pal32: image too big (%i*%i)", width, height);
|
|
|
|
|
|
|
|
if (s&3)
|
|
|
|
Sys_Error ("GL_Upload8: s&3");
|
|
|
|
for (i=0 ; i<s ; i+=1)
|
|
|
|
{
|
|
|
|
trans[(i<<2)+0] = gammatable[pal[data[i]*4+0]];
|
|
|
|
trans[(i<<2)+1] = gammatable[pal[data[i]*4+1]];
|
|
|
|
trans[(i<<2)+2] = gammatable[pal[data[i]*4+2]];
|
|
|
|
trans[(i<<2)+3] = gammatable[pal[data[i]*4+3]];
|
|
|
|
}
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
GL_Upload32 (NULL, (unsigned*)trans, width, height, flags);
|
2005-05-13 10:42:48 +00:00
|
|
|
}
|
2004-08-22 22:29:09 +00:00
|
|
|
/*
|
|
|
|
================
|
|
|
|
GL_LoadTexture
|
|
|
|
================
|
|
|
|
*/
|
2009-11-04 21:16:50 +00:00
|
|
|
texid_t GL_LoadTexture (char *identifier, int width, int height, qbyte *data, unsigned int flags, unsigned int transtype)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
gltexture_t *glt;
|
|
|
|
|
2005-07-28 15:22:15 +00:00
|
|
|
// see if the texture is already present
|
2004-08-22 22:29:09 +00:00
|
|
|
if (identifier[0])
|
|
|
|
{
|
|
|
|
glt = GL_MatchTexture(identifier, 8, width, height);
|
|
|
|
if (glt)
|
2004-10-10 06:32:29 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
TRACE(("dbg: GL_LoadTexture: duplicate %s\n", identifier));
|
2004-08-22 22:29:09 +00:00
|
|
|
return glt->texnum;
|
2004-10-10 06:32:29 +00:00
|
|
|
}
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
2004-10-10 06:32:29 +00:00
|
|
|
TRACE(("dbg: GL_LoadTexture: new %s\n", identifier));
|
|
|
|
|
2011-10-27 16:16:29 +00:00
|
|
|
glt = GL_AllocNewGLTexture(identifier, width, height);
|
2004-08-22 22:29:09 +00:00
|
|
|
glt->bpp = 8;
|
2009-11-04 21:16:50 +00:00
|
|
|
glt->flags = flags;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2011-02-25 04:22:14 +00:00
|
|
|
checkglerror();
|
|
|
|
GL_MTBind(0, GL_TEXTURE_2D, glt->texnum);
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
GL_Upload8 ("8bit", data, width, height, flags, transtype);
|
2011-02-25 04:22:14 +00:00
|
|
|
checkglerror();
|
2009-06-21 17:45:33 +00:00
|
|
|
return glt->texnum;
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
texid_t GL_LoadTextureFB (char *identifier, int width, int height, qbyte *data, unsigned int flags)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
gltexture_t *glt;
|
|
|
|
|
2005-07-28 15:22:15 +00:00
|
|
|
// see if the texture is already present
|
2004-08-22 22:29:09 +00:00
|
|
|
if (identifier[0])
|
|
|
|
{
|
|
|
|
glt = GL_MatchTexture(identifier, 8, width, height);
|
|
|
|
if (glt)
|
|
|
|
return glt->texnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < width*height; i++)
|
|
|
|
if (data[i] > 255-vid.fullbright)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (i == width*height)
|
2009-11-04 21:16:50 +00:00
|
|
|
return r_nulltex; //none found, don't bother uploading.
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2011-10-27 16:16:29 +00:00
|
|
|
glt = GL_AllocNewGLTexture(identifier, width, height);
|
2004-08-22 22:29:09 +00:00
|
|
|
glt->bpp = 8;
|
2009-11-04 21:16:50 +00:00
|
|
|
glt->flags = flags;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2011-02-25 04:22:14 +00:00
|
|
|
GL_MTBind(0, GL_TEXTURE_2D, glt->texnum);
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
GL_Upload8FB (data, width, height, flags);
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2009-06-21 17:45:33 +00:00
|
|
|
return glt->texnum;
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
texid_t GL_LoadTexture8Pal24 (char *identifier, int width, int height, qbyte *data, qbyte *palette24, unsigned int flags)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
gltexture_t *glt;
|
|
|
|
|
2005-07-28 15:22:15 +00:00
|
|
|
// see if the texture is already present
|
2004-08-22 22:29:09 +00:00
|
|
|
if (identifier[0])
|
|
|
|
{
|
|
|
|
glt = GL_MatchTexture(identifier, 24, width, height);
|
|
|
|
if (glt)
|
|
|
|
return glt->texnum;
|
|
|
|
}
|
|
|
|
|
2011-10-27 16:16:29 +00:00
|
|
|
glt = GL_AllocNewGLTexture(identifier, width, height);
|
2004-08-22 22:29:09 +00:00
|
|
|
glt->bpp = 24;
|
2009-11-04 21:16:50 +00:00
|
|
|
glt->flags = flags;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2011-02-25 04:22:14 +00:00
|
|
|
GL_MTBind(0, GL_TEXTURE_2D, glt->texnum);
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
GL_Upload8Pal24 (data, palette24, width, height, flags);
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2009-06-21 17:45:33 +00:00
|
|
|
return glt->texnum;
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
2009-11-04 21:16:50 +00:00
|
|
|
texid_t GL_LoadTexture8Pal32 (char *identifier, int width, int height, qbyte *data, qbyte *palette32, unsigned int flags)
|
2005-05-13 10:42:48 +00:00
|
|
|
{
|
|
|
|
gltexture_t *glt;
|
|
|
|
|
2005-07-28 15:22:15 +00:00
|
|
|
// see if the texture is already present
|
2005-05-13 10:42:48 +00:00
|
|
|
if (identifier[0])
|
|
|
|
{
|
|
|
|
glt = GL_MatchTexture(identifier, 32, width, height);
|
|
|
|
if (glt)
|
|
|
|
return glt->texnum;
|
|
|
|
}
|
|
|
|
|
2011-10-27 16:16:29 +00:00
|
|
|
glt = GL_AllocNewGLTexture(identifier, width, height);
|
2005-05-13 10:42:48 +00:00
|
|
|
glt->bpp = 32;
|
2009-11-04 21:16:50 +00:00
|
|
|
glt->flags = flags;
|
2005-05-13 10:42:48 +00:00
|
|
|
|
2011-02-25 04:22:14 +00:00
|
|
|
GL_MTBind(0, GL_TEXTURE_2D, glt->texnum);
|
2005-05-13 10:42:48 +00:00
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
GL_Upload8Pal32 (data, palette32, width, height, flags);
|
2005-05-13 10:42:48 +00:00
|
|
|
|
2009-06-21 17:45:33 +00:00
|
|
|
return glt->texnum;
|
2005-05-13 10:42:48 +00:00
|
|
|
}
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
texid_t GL_LoadTexture32 (char *identifier, int width, int height, void *data, unsigned int flags)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
// qboolean noalpha;
|
|
|
|
// int p, s;
|
2011-12-27 08:35:19 +00:00
|
|
|
gltexture_t *glt = NULL;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2005-07-28 15:22:15 +00:00
|
|
|
// see if the texture is already present
|
2004-08-22 22:29:09 +00:00
|
|
|
if (identifier[0])
|
|
|
|
{
|
|
|
|
glt = GL_MatchTexture(identifier, 32, width, height);
|
2011-12-27 08:35:19 +00:00
|
|
|
if (glt && !(flags & IF_REPLACE))
|
2004-08-22 22:29:09 +00:00
|
|
|
return glt->texnum;
|
|
|
|
}
|
2011-12-27 08:35:19 +00:00
|
|
|
if (!glt)
|
|
|
|
glt = GL_AllocNewGLTexture(identifier, width, height);
|
2004-08-22 22:29:09 +00:00
|
|
|
glt->bpp = 32;
|
2009-11-04 21:16:50 +00:00
|
|
|
glt->flags = flags;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2011-12-27 08:35:19 +00:00
|
|
|
switch((flags & IF_TEXTYPE) >> IF_TEXTYPESHIFT)
|
|
|
|
{
|
|
|
|
case 0:
|
2011-12-23 03:12:29 +00:00
|
|
|
GL_MTBind(0, GL_TEXTURE_2D, glt->texnum);
|
2011-12-27 08:35:19 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
GL_MTBind(0, GL_TEXTURE_3D, glt->texnum);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GL_MTBind(0, GL_TEXTURE_CUBE_MAP_ARB, glt->texnum);
|
|
|
|
break;
|
|
|
|
}
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
GL_Upload32 (identifier, data, width, height, flags);
|
2008-12-23 02:55:20 +00:00
|
|
|
|
2009-06-21 17:45:33 +00:00
|
|
|
return glt->texnum;
|
2008-12-23 02:55:20 +00:00
|
|
|
}
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
texid_t GL_LoadTexture32_BGRA (char *identifier, int width, int height, unsigned *data, unsigned int flags)
|
2008-12-23 02:55:20 +00:00
|
|
|
{
|
|
|
|
// qboolean noalpha;
|
|
|
|
// int p, s;
|
|
|
|
gltexture_t *glt;
|
|
|
|
|
|
|
|
// see if the texture is already present
|
|
|
|
if (identifier[0])
|
|
|
|
{
|
|
|
|
glt = GL_MatchTexture(identifier, 32, width, height);
|
|
|
|
if (glt)
|
|
|
|
return glt->texnum;
|
|
|
|
}
|
|
|
|
|
2011-10-27 16:16:29 +00:00
|
|
|
glt = GL_AllocNewGLTexture(identifier, width, height);
|
2008-12-23 02:55:20 +00:00
|
|
|
glt->bpp = 32;
|
2009-11-04 21:16:50 +00:00
|
|
|
glt->flags = flags;
|
2008-12-23 02:55:20 +00:00
|
|
|
|
2011-02-25 04:22:14 +00:00
|
|
|
GL_MTBind(0, GL_TEXTURE_2D, glt->texnum);
|
2008-12-23 02:55:20 +00:00
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
GL_Upload32_BGRA (identifier, data, width, height, flags);
|
2008-12-23 02:55:20 +00:00
|
|
|
|
2009-06-21 17:45:33 +00:00
|
|
|
return glt->texnum;
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
texid_t GL_LoadCompressed(char *name)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
unsigned char *file;
|
|
|
|
gltexture_t *glt;
|
|
|
|
char inname[MAX_OSPATH];
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
if (!gl_config.arb_texture_compression || !gl_compress.ival)
|
|
|
|
return r_nulltex;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
|
2005-07-28 15:22:15 +00:00
|
|
|
// see if the texture is already present
|
2004-08-22 22:29:09 +00:00
|
|
|
if (name[0])
|
|
|
|
{
|
2009-11-04 21:16:50 +00:00
|
|
|
texid_t num = GL_FindTexture(name);
|
|
|
|
if (TEXVALID(num))
|
2004-08-22 22:29:09 +00:00
|
|
|
return num;
|
|
|
|
}
|
|
|
|
else
|
2009-11-04 21:16:50 +00:00
|
|
|
return r_nulltex;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
|
2006-03-06 01:41:09 +00:00
|
|
|
snprintf(inname, sizeof(inname)-1, "tex/%s.tex", name);
|
2005-12-01 11:40:45 +00:00
|
|
|
file = COM_LoadFile(inname, 5);
|
2004-08-22 22:29:09 +00:00
|
|
|
if (!file)
|
2009-11-04 21:16:50 +00:00
|
|
|
return r_nulltex;
|
2005-12-01 11:40:45 +00:00
|
|
|
|
2011-10-27 16:16:29 +00:00
|
|
|
glt = GL_AllocNewGLTexture(name, 0, 0);
|
2004-08-22 22:29:09 +00:00
|
|
|
glt->bpp = 32;
|
2009-11-04 21:16:50 +00:00
|
|
|
glt->flags = 0;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2011-02-25 04:22:14 +00:00
|
|
|
GL_MTBind(0, GL_TEXTURE_2D, glt->texnum);
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
if (!GL_UploadCompressed(file, &glt->width, &glt->height, (unsigned int *)&glt->flags))
|
|
|
|
return r_nulltex;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2009-06-21 17:45:33 +00:00
|
|
|
return glt->texnum;
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
texid_t GL_LoadTexture8Grey (char *identifier, int width, int height, unsigned char *data, unsigned int flags)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
// qboolean noalpha;
|
|
|
|
// int p, s;
|
|
|
|
gltexture_t *glt;
|
|
|
|
|
2005-07-28 15:22:15 +00:00
|
|
|
// see if the texture is already present
|
2004-08-22 22:29:09 +00:00
|
|
|
if (identifier[0])
|
|
|
|
{
|
|
|
|
glt = GL_MatchTexture(identifier, 8, width, height);
|
|
|
|
if (glt)
|
|
|
|
return glt->texnum;
|
|
|
|
}
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
flags |= IF_NOALPHA;
|
|
|
|
|
2011-10-27 16:16:29 +00:00
|
|
|
glt = GL_AllocNewGLTexture(identifier, width, height);
|
2004-08-22 22:29:09 +00:00
|
|
|
glt->bpp = 8;
|
2009-11-04 21:16:50 +00:00
|
|
|
glt->flags = flags;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2011-02-25 04:22:14 +00:00
|
|
|
GL_MTBind(0, GL_TEXTURE_2D, glt->texnum);
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
GL_Upload8Grey (data, width, height, flags);
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2009-06-21 17:45:33 +00:00
|
|
|
return glt->texnum;
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
texid_t GL_LoadTexture8Bump (char *identifier, int width, int height, unsigned char *data, unsigned int flags, float bumpscale)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
|
|
|
// qboolean noalpha;
|
|
|
|
// int p, s;
|
|
|
|
gltexture_t *glt;
|
|
|
|
|
2005-07-28 15:22:15 +00:00
|
|
|
// see if the texture is already present
|
2004-08-22 22:29:09 +00:00
|
|
|
if (identifier[0])
|
|
|
|
{
|
|
|
|
glt = GL_MatchTexture(identifier, 8, width, height);
|
|
|
|
if (glt)
|
2004-10-10 06:32:29 +00:00
|
|
|
{
|
|
|
|
TRACE(("dbg: GL_LoadTexture8Bump: duplicated %s\n", identifier));
|
2004-08-22 22:29:09 +00:00
|
|
|
return glt->texnum;
|
2004-10-10 06:32:29 +00:00
|
|
|
}
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
2004-10-10 06:32:29 +00:00
|
|
|
TRACE(("dbg: GL_LoadTexture8Bump: new %s\n", identifier));
|
|
|
|
|
2011-10-27 16:16:29 +00:00
|
|
|
glt = GL_AllocNewGLTexture(identifier, width, height);
|
2004-08-22 22:29:09 +00:00
|
|
|
glt->bpp = 8;
|
2009-11-04 21:16:50 +00:00
|
|
|
glt->flags = flags;
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2011-02-25 04:22:14 +00:00
|
|
|
GL_MTBind(0, GL_TEXTURE_2D, glt->texnum);
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
GL_UploadBump (data, width, height, flags, bumpscale);
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2009-06-21 17:45:33 +00:00
|
|
|
return glt->texnum;
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
GL_LoadPicTexture
|
|
|
|
================
|
|
|
|
*/
|
2009-11-04 21:16:50 +00:00
|
|
|
texid_t GL_LoadPicTexture (qpic_t *pic)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
2009-11-04 21:16:50 +00:00
|
|
|
return GL_LoadTexture ("", pic->width, pic->height, pic->data, IF_NOMIPMAP, 1);
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
|
2005-01-12 08:38:31 +00:00
|
|
|
#endif
|