6 #define TEXF_ALPHA 0x00000001
8 #define TEXF_MIPMAP 0x00000002
9 // indicates texture coordinates should be clamped rather than wrapping
10 #define TEXF_CLAMP 0x00000020
11 // indicates texture should be uploaded using GL_NEAREST or GL_NEAREST_MIPMAP_NEAREST mode
12 #define TEXF_FORCENEAREST 0x00000040
13 // indicates texture should be uploaded using GL_LINEAR or GL_LINEAR_MIPMAP_NEAREST or GL_LINEAR_MIPMAP_LINEAR mode
14 #define TEXF_FORCELINEAR 0x00000080
15 // indicates texture should be affected by gl_picmip and gl_max_size cvar
16 #define TEXF_PICMIP 0x00000100
17 // indicates texture should be compressed if possible
18 #define TEXF_COMPRESS 0x00000200
19 // use this flag to block R_PurgeTexture from freeing a texture (only used by r_texture_white and similar which may be used in skinframe_t)
20 #define TEXF_PERSISTENT 0x00000400
21 // indicates texture should use GL_COMPARE_R_TO_TEXTURE mode
22 #define TEXF_COMPARE 0x00000800
23 // indicates texture should use lower precision where supported
24 #define TEXF_LOWPRECISION 0x00001000
25 // indicates texture should support R_UpdateTexture, actual uploads may be delayed until R_Mesh_TexBind if gl_nopartialtextureupdates is on
26 #define TEXF_ALLOWUPDATES 0x00002000
27 // indicates texture should be affected by gl_picmip_world and r_picmipworld (maybe others in the future) instead of gl_picmip_other
28 #define TEXF_ISWORLD 0x00004000
29 // indicates texture should be affected by gl_picmip_sprites and r_picmipsprites (maybe others in the future) instead of gl_picmip_other
30 #define TEXF_ISSPRITE 0x00008000
31 // indicates the texture will be used as a render target (D3D hint)
32 #define TEXF_RENDERTARGET 0x0010000
33 // used for checking if textures mismatch
34 #define TEXF_IMPORTANTBITS (TEXF_ALPHA | TEXF_MIPMAP | TEXF_CLAMP | TEXF_FORCENEAREST | TEXF_FORCELINEAR | TEXF_PICMIP | TEXF_COMPRESS | TEXF_COMPARE | TEXF_LOWPRECISION | TEXF_RENDERTARGET)
36 typedef enum textype_e
42 // 32bit BGRA (preferred format due to faster uploads on most hardware)
44 // 16bit D16 (16bit depth) or 32bit S8D24 (24bit depth, 8bit stencil unused)
46 // 8bit ALPHA (used for freetype fonts)
48 // 4x4 block compressed 15bit color (4 bits per pixel)
50 // 4x4 block compressed 15bit color plus 1bit alpha (4 bits per pixel)
52 // 4x4 block compressed 15bit color plus 8bit alpha (8 bits per pixel)
54 // 4x4 block compressed 15bit color plus 8bit alpha (8 bits per pixel)
56 // this represents the same format as the framebuffer, for fast copies
64 #define SUPPORTDIRECTX
71 // contents of this structure are mostly private to gl_textures.c
72 typedef struct rtexture_s
74 // this is exposed (rather than private) for speed reasons only
77 int gltexturetypeenum; // exposed for use in R_Mesh_TexBind
78 // d3d stuff the backend needs
90 int d3dmaxmiplevelfilter;
97 // contents of this structure are private to gl_textures.c
98 typedef struct rtexturepool_s
104 typedef void (*updatecallback_t)(rtexture_t *rt, void *data);
106 // allocate a texture pool, to be used with R_LoadTexture
107 rtexturepool_t *R_AllocTexturePool(void);
108 // free a texture pool (textures can not be freed individually)
109 void R_FreeTexturePool(rtexturepool_t **rtexturepool);
111 // the color/normal/etc cvars should be checked by callers of R_LoadTexture* functions to decide whether to add TEXF_COMPRESS to the flags
112 extern cvar_t gl_texturecompression;
113 extern cvar_t gl_texturecompression_color;
114 extern cvar_t gl_texturecompression_normal;
115 extern cvar_t gl_texturecompression_gloss;
116 extern cvar_t gl_texturecompression_glow;
117 extern cvar_t gl_texturecompression_2d;
118 extern cvar_t gl_texturecompression_q3bsplightmaps;
119 extern cvar_t gl_texturecompression_q3bspdeluxemaps;
120 extern cvar_t gl_texturecompression_sky;
121 extern cvar_t gl_texturecompression_lightcubemaps;
122 extern cvar_t gl_texturecompression_reflectmask;
124 // add a texture to a pool and optionally precache (upload) it
125 // (note: data == NULL is perfectly acceptable)
126 // (note: palette must not be NULL if using TEXTYPE_PALETTE)
127 rtexture_t *R_LoadTexture2D(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, const unsigned char *data, textype_t textype, int flags, int miplevel, const unsigned int *palette);
128 rtexture_t *R_LoadTexture3D(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, int depth, const unsigned char *data, textype_t textype, int flags, int miplevel, const unsigned int *palette);
129 rtexture_t *R_LoadTextureCubeMap(rtexturepool_t *rtexturepool, const char *identifier, int width, const unsigned char *data, textype_t textype, int flags, int miplevel, const unsigned int *palette);
130 rtexture_t *R_LoadTextureRectangle(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, const unsigned char *data, textype_t textype, int flags, int miplevel, const unsigned int *palette);
131 rtexture_t *R_LoadTextureShadowMapRectangle(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, int precision, qboolean filter);
132 rtexture_t *R_LoadTextureShadowMap2D(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, int precision, qboolean filter);
133 rtexture_t *R_LoadTextureShadowMapCube(rtexturepool_t *rtexturepool, const char *identifier, int width, int precision, qboolean filter);
134 rtexture_t *R_LoadTextureDDSFile(rtexturepool_t *rtexturepool, const char *filename, int flags, qboolean *hasalphaflag, float *avgcolor, int miplevel);
136 // saves a texture to a DDS file
137 int R_SaveTextureDDSFile(rtexture_t *rt, const char *filename, qboolean skipuncompressed, qboolean hasalpha);
140 void R_FreeTexture(rtexture_t *rt);
142 // update a portion of the image data of a texture, used by lightmap updates
143 // and procedural textures such as video playback, actual uploads may be
144 // delayed by gl_nopartialtextureupdates cvar until R_Mesh_TexBind uses it
145 void R_UpdateTexture(rtexture_t *rt, const unsigned char *data, int x, int y, int width, int height);
147 // returns the renderer dependent texture slot number (call this before each
148 // use, as a texture might not have been precached)
149 #define R_GetTexture(rt) ((rt) ? ((rt)->dirty ? R_RealGetTexture(rt) : (rt)->texnum) : r_texture_white->texnum)
150 int R_RealGetTexture (rtexture_t *rt);
152 // returns width of texture, as was specified when it was uploaded
153 int R_TextureWidth(rtexture_t *rt);
155 // returns height of texture, as was specified when it was uploaded
156 int R_TextureHeight(rtexture_t *rt);
158 // only frees the texture if TEXF_PERSISTENT is not set
159 // also resets the variable
160 void R_PurgeTexture(rtexture_t *prt);
162 // frees processing buffers each frame, and may someday animate procedural textures
163 void R_Textures_Frame(void);
165 // maybe rename this - sounds awful? [11/21/2007 Black]
166 void R_MarkDirtyTexture(rtexture_t *rt);
167 void R_MakeTextureDynamic(rtexture_t *rt, updatecallback_t updatecallback, void *data);
169 // Clear the texture's contents
170 void R_ClearTexture (rtexture_t *rt);
172 // returns the desired picmip level for given TEXF_ flags
173 int R_PicmipForFlags(int flags);