DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
r_textures.h
Go to the documentation of this file.
1
2#ifndef R_TEXTURES_H
3#define R_TEXTURES_H
4
5#include "qtypes.h"
6#include "qdefs.h"
7
8// transparent
9#define TEXF_ALPHA 0x00000001
10// mipmapped
11#define TEXF_MIPMAP 0x00000002
12// multiply RGB by A channel before uploading
13#define TEXF_RGBMULTIPLYBYALPHA 0x00000004
14// indicates texture coordinates should be clamped rather than wrapping
15#define TEXF_CLAMP 0x00000020
16// indicates texture should be uploaded using GL_NEAREST or GL_NEAREST_MIPMAP_NEAREST mode
17#define TEXF_FORCENEAREST 0x00000040
18// indicates texture should be uploaded using GL_LINEAR or GL_LINEAR_MIPMAP_NEAREST or GL_LINEAR_MIPMAP_LINEAR mode
19#define TEXF_FORCELINEAR 0x00000080
20// indicates texture should be affected by gl_picmip and gl_max_size cvar
21#define TEXF_PICMIP 0x00000100
22// indicates texture should be compressed if possible
23#define TEXF_COMPRESS 0x00000200
24// 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)
25#define TEXF_PERSISTENT 0x00000400
26// indicates texture should use GL_COMPARE_R_TO_TEXTURE mode
27#define TEXF_COMPARE 0x00000800
28// indicates texture should use lower precision where supported
29#define TEXF_LOWPRECISION 0x00001000
30// indicates texture should support R_UpdateTexture on small regions, actual uploads may be delayed until R_Mesh_TexBind if gl_nopartialtextureupdates is on
31#define TEXF_ALLOWUPDATES 0x00002000
32// indicates texture should be affected by gl_picmip_world and r_picmipworld (maybe others in the future) instead of gl_picmip_other
33#define TEXF_ISWORLD 0x00004000
34// indicates texture should be affected by gl_picmip_sprites and r_picmipsprites (maybe others in the future) instead of gl_picmip_other
35#define TEXF_ISSPRITE 0x00008000
36// indicates the texture will be used as a render target (D3D hint)
37#define TEXF_RENDERTARGET 0x0010000
38// used for checking if textures mismatch
39#define TEXF_IMPORTANTBITS (TEXF_ALPHA | TEXF_MIPMAP | TEXF_RGBMULTIPLYBYALPHA | TEXF_CLAMP | TEXF_FORCENEAREST | TEXF_FORCELINEAR | TEXF_PICMIP | TEXF_COMPARE | TEXF_LOWPRECISION | TEXF_RENDERTARGET)
40// set as a flag to force the texture to be reloaded
41#define TEXF_FORCE_RELOAD 0x80000000
42
43typedef enum textype_e
44{
45 // placeholder for unused textures in r_rendertarget_t
47
48 // 8bit paletted
50 // 32bit RGBA
52 // 32bit BGRA (preferred format due to faster uploads on most hardware)
54 // 8bit ALPHA (used for freetype fonts)
56 // 4x4 block compressed 15bit color (4 bits per pixel)
58 // 4x4 block compressed 15bit color plus 1bit alpha (4 bits per pixel)
60 // 4x4 block compressed 15bit color plus 8bit alpha (8 bits per pixel)
62 // 4x4 block compressed 15bit color plus 8bit alpha (8 bits per pixel)
64
65 // default compressed type for GLES2
67
68 // 8bit paletted in sRGB colorspace
70 // 32bit RGBA in sRGB colorspace
72 // 32bit BGRA (preferred format due to faster uploads on most hardware) in sRGB colorspace
74 // 4x4 block compressed 15bit color (4 bits per pixel) in sRGB colorspace
76 // 4x4 block compressed 15bit color plus 1bit alpha (4 bits per pixel) in sRGB colorspace
78 // 4x4 block compressed 15bit color plus 8bit alpha (8 bits per pixel) in sRGB colorspace
80 // 4x4 block compressed 15bit color plus 8bit alpha (8 bits per pixel) in sRGB colorspace
82
83 // this represents the same format as the framebuffer, for fast copies
85 // this represents an RGBA half_float texture (4 16bit floats)
87 // this represents an RGBA float texture (4 32bit floats)
89 // depth-stencil buffer (or texture)
91 // depth-stencil buffer (or texture)
93 // 32bit D24S8 buffer (24bit depth, 8bit stencil), not supported on OpenGL ES
95 // shadowmap-friendly format with depth comparison (not supported on some hardware)
97 // shadowmap-friendly format with raw reading (not supported on some hardware)
99 // shadowmap-friendly format with depth comparison (not supported on some hardware)
101 // shadowmap-friendly format with raw reading (not supported on some hardware)
103}
105
106// contents of this structure are mostly private to gl_textures.c
107typedef struct rtexture_s
108{
109 // this is exposed (rather than private) for speed reasons only
110 int texnum; // GL texture slot number
111 int renderbuffernum; // GL renderbuffer slot number
112 qbool dirty; // indicates that R_RealGetTexture should be called
113 qbool glisdepthstencil; // indicates that FBO attachment has to be GL_DEPTH_STENCIL_ATTACHMENT
114 int gltexturetypeenum; // used by R_Mesh_TexBind
115}
117
118// contents of this structure are private to gl_textures.c
119typedef struct rtexturepool_s
120{
122}
124
125typedef struct skinframe_s
126{
127 struct rtexture_s *stain; // inverse modulate with background (used for decals and such)
128 struct rtexture_s *merged; // original texture without glow
129 struct rtexture_s *base; // original texture without pants/shirt/glow
130 struct rtexture_s *pants; // pants only (in greyscale)
131 struct rtexture_s *shirt; // shirt only (in greyscale)
132 struct rtexture_s *nmap; // normalmap (bumpmap for dot3)
133 struct rtexture_s *gloss; // glossmap (for dot3)
134 struct rtexture_s *glow; // glow only (fullbrights)
135 struct rtexture_s *fog; // alpha of the base texture (if not opaque)
136 struct rtexture_s *reflect; // colored mask for cubemap reflections
137 // accounting data for hash searches:
138 // the compare variables are used to identify internal skins from certain
139 // model formats
140 // (so that two q1bsp maps with the same texture name for different
141 // textures do not have any conflicts)
142 struct skinframe_s *next; // next on hash chain
143 char basename[MAX_QPATH]; // name of this
144 int textureflags; // texture flags to use
148 // mark and sweep garbage collection, this value is updated to a new value
149 // on each level change for the used skinframes, if some are not used they
150 // are freed
151 unsigned int loadsequence;
152 // indicates whether this texture has transparent pixels
154 // average texture color, if applicable
155 float avgcolor[4];
156 // for mdl skins, we actually only upload on first use (many are never used, and they are almost never used in both base+pants+shirt and merged modes)
157 unsigned char *qpixels;
165}
167
168typedef void (*updatecallback_t)(rtexture_t *rt, void *data);
169
170// allocate a texture pool, to be used with R_LoadTexture
172// free a texture pool (textures can not be freed individually)
173void R_FreeTexturePool(rtexturepool_t **rtexturepool);
174
175// the color/normal/etc cvars should be checked by callers of R_LoadTexture* functions to decide whether to add TEXF_COMPRESS to the flags
176extern struct cvar_s gl_texturecompression;
177extern struct cvar_s gl_texturecompression_color;
178extern struct cvar_s gl_texturecompression_normal;
179extern struct cvar_s gl_texturecompression_gloss;
180extern struct cvar_s gl_texturecompression_glow;
181extern struct cvar_s gl_texturecompression_2d;
182extern struct cvar_s gl_texturecompression_q3bsplightmaps;
183extern struct cvar_s gl_texturecompression_q3bspdeluxemaps;
184extern struct cvar_s gl_texturecompression_sky;
185extern struct cvar_s gl_texturecompression_lightcubemaps;
186extern struct cvar_s gl_texturecompression_reflectmask;
187extern struct cvar_s r_texture_dds_load;
188extern struct cvar_s r_texture_dds_save;
189
190// add a texture to a pool and optionally precache (upload) it
191// (note: data == NULL is perfectly acceptable)
192// (note: palette must not be NULL if using TEXTYPE_PALETTE)
193rtexture_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);
194rtexture_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);
195rtexture_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);
196rtexture_t *R_LoadTextureShadowMap2D(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, textype_t textype, qbool filter);
197rtexture_t *R_LoadTextureRenderBuffer(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, textype_t textype);
198rtexture_t *R_LoadTextureDDSFile(rtexturepool_t *rtexturepool, const char *filename, qbool srgb, int flags, qbool *hasalphaflag, float *avgcolor, int miplevel, qbool optionaltexture);
199
200// saves a texture to a DDS file
201int R_SaveTextureDDSFile(rtexture_t *rt, const char *filename, qbool skipuncompressed, qbool hasalpha);
202
203// free a texture
204void R_FreeTexture(rtexture_t *rt);
205
206// update a portion of the image data of a texture, used by lightmap updates
207// and procedural textures such as video playback, actual uploads may be
208// delayed by gl_nopartialtextureupdates cvar until R_Mesh_TexBind uses it
209// combine has 3 values: 0 = immediately upload (glTexSubImage2D), 1 = combine with other updates (glTexSubImage2D on next draw), 2 = combine with other updates and never upload partial images (glTexImage2D on next draw)
210void R_UpdateTexture(rtexture_t *rt, const unsigned char *data, int x, int y, int z, int width, int height, int depth, int combine);
211
212// returns the renderer dependent texture slot number (call this before each
213// use, as a texture might not have been precached)
214#define R_GetTexture(rt) ((rt) ? ((rt)->dirty ? R_RealGetTexture(rt) : (rt)->texnum) : r_texture_white->texnum)
216
217// returns width of texture, as was specified when it was uploaded
219
220// returns height of texture, as was specified when it was uploaded
222
223// returns flags of texture, as was specified when it was uploaded
225
226// only frees the texture if TEXF_PERSISTENT is not set
227// also resets the variable
228void R_PurgeTexture(rtexture_t *prt);
229
230// frees processing buffers each frame, and may someday animate procedural textures
231void R_Textures_Frame(void);
232
233// maybe rename this - sounds awful? [11/21/2007 Black]
235void R_MakeTextureDynamic(rtexture_t *rt, updatecallback_t updatecallback, void *data);
236
237// Clear the texture's contents
238void R_ClearTexture (rtexture_t *rt);
239
240// returns the desired picmip level for given TEXF_ flags
241int R_PicmipForFlags(int flags);
242
243void R_TextureStats_Print(qbool printeach, qbool printpool, qbool printtotal);
244
245#endif
246
float flags
void() predraw
GLubyte GLubyte GLubyte z
Definition glquake.h:782
GLenum GLsizei width
Definition glquake.h:622
GLenum GLsizei GLsizei height
Definition glquake.h:622
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition glquake.h:609
GLint GLenum GLint GLint y
Definition glquake.h:651
GLint GLenum GLsizei GLsizei GLsizei depth
Definition glquake.h:648
GLint GLenum GLint x
Definition glquake.h:651
GLsizeiptr const GLvoid * data
Definition glquake.h:639
#define MAX_QPATH
max length of a quake game pathname
Definition qdefs.h:169
bool qbool
Definition qtypes.h:9
int R_RealGetTexture(rtexture_t *rt)
void R_FreeTexturePool(rtexturepool_t **rtexturepool)
void R_ClearTexture(rtexture_t *rt)
int R_TextureFlags(rtexture_t *rt)
void R_MakeTextureDynamic(rtexture_t *rt, updatecallback_t updatecallback, void *data)
struct cvar_s r_texture_dds_save
Definition gl_rmain.c:157
rtexture_t * R_LoadTextureRenderBuffer(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, textype_t textype)
struct cvar_s gl_texturecompression_q3bspdeluxemaps
Definition gl_textures.c:44
struct cvar_s gl_texturecompression_gloss
Definition gl_textures.c:40
int R_TextureHeight(rtexture_t *rt)
void R_UpdateTexture(rtexture_t *rt, const unsigned char *data, int x, int y, int z, int width, int height, int depth, int combine)
struct cvar_s gl_texturecompression
Definition gl_textures.c:37
void R_TextureStats_Print(qbool printeach, qbool printpool, qbool printtotal)
rtexture_t * R_LoadTextureShadowMap2D(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, textype_t textype, qbool filter)
int R_TextureWidth(rtexture_t *rt)
rtexture_t * R_LoadTextureDDSFile(rtexturepool_t *rtexturepool, const char *filename, qbool srgb, int flags, qbool *hasalphaflag, float *avgcolor, int miplevel, qbool optionaltexture)
int R_SaveTextureDDSFile(rtexture_t *rt, const char *filename, qbool skipuncompressed, qbool hasalpha)
struct cvar_s r_texture_dds_load
Definition gl_rmain.c:156
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)
textype_t
Definition r_textures.h:44
@ TEXTYPE_SRGB_DXT1
Definition r_textures.h:75
@ TEXTYPE_DXT5
Definition r_textures.h:63
@ TEXTYPE_PALETTE
Definition r_textures.h:49
@ TEXTYPE_ETC1
Definition r_textures.h:66
@ TEXTYPE_SHADOWMAP16_RAW
Definition r_textures.h:98
@ TEXTYPE_SRGB_BGRA
Definition r_textures.h:73
@ TEXTYPE_ALPHA
Definition r_textures.h:55
@ TEXTYPE_SRGB_RGBA
Definition r_textures.h:71
@ TEXTYPE_COLORBUFFER
Definition r_textures.h:84
@ TEXTYPE_DXT1
Definition r_textures.h:57
@ TEXTYPE_SHADOWMAP16_COMP
Definition r_textures.h:96
@ TEXTYPE_SRGB_DXT5
Definition r_textures.h:81
@ TEXTYPE_SRGB_PALETTE
Definition r_textures.h:69
@ TEXTYPE_SRGB_DXT3
Definition r_textures.h:79
@ TEXTYPE_COLORBUFFER32F
Definition r_textures.h:88
@ TEXTYPE_DEPTHBUFFER24
Definition r_textures.h:92
@ TEXTYPE_DXT1A
Definition r_textures.h:59
@ TEXTYPE_UNUSED
Definition r_textures.h:46
@ TEXTYPE_DEPTHBUFFER16
Definition r_textures.h:90
@ TEXTYPE_BGRA
Definition r_textures.h:53
@ TEXTYPE_DXT3
Definition r_textures.h:61
@ TEXTYPE_SRGB_DXT1A
Definition r_textures.h:77
@ TEXTYPE_RGBA
Definition r_textures.h:51
@ TEXTYPE_SHADOWMAP24_RAW
Definition r_textures.h:102
@ TEXTYPE_DEPTHBUFFER24STENCIL8
Definition r_textures.h:94
@ TEXTYPE_SHADOWMAP24_COMP
Definition r_textures.h:100
@ TEXTYPE_COLORBUFFER16F
Definition r_textures.h:86
rtexturepool_t * R_AllocTexturePool(void)
void R_FreeTexture(rtexture_t *rt)
struct cvar_s gl_texturecompression_q3bsplightmaps
Definition gl_textures.c:43
void(* updatecallback_t)(rtexture_t *rt, void *data)
Definition r_textures.h:168
void R_MarkDirtyTexture(rtexture_t *rt)
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)
struct cvar_s gl_texturecompression_sky
Definition gl_textures.c:45
struct cvar_s gl_texturecompression_glow
Definition gl_textures.c:41
void R_PurgeTexture(rtexture_t *prt)
struct cvar_s gl_texturecompression_color
Definition gl_textures.c:38
struct cvar_s gl_texturecompression_reflectmask
Definition gl_textures.c:47
void R_Textures_Frame(void)
struct cvar_s gl_texturecompression_lightcubemaps
Definition gl_textures.c:46
int R_PicmipForFlags(int flags)
struct cvar_s gl_texturecompression_normal
Definition gl_textures.c:39
struct cvar_s gl_texturecompression_2d
Definition gl_textures.c:42
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)
int renderbuffernum
Definition r_textures.h:111
qbool dirty
Definition r_textures.h:112
int gltexturetypeenum
Definition r_textures.h:114
qbool glisdepthstencil
Definition r_textures.h:113
struct rtexture_s * pants
Definition r_textures.h:130
struct rtexture_s * stain
Definition r_textures.h:127
qbool qgeneratebase
Definition r_textures.h:161
struct rtexture_s * merged
Definition r_textures.h:128
struct rtexture_s * shirt
Definition r_textures.h:131
struct skinframe_s * next
Definition r_textures.h:142
struct rtexture_s * reflect
Definition r_textures.h:136
struct rtexture_s * base
Definition r_textures.h:129
struct rtexture_s * gloss
Definition r_textures.h:133
qbool qhascolormapping
Definition r_textures.h:160
struct rtexture_s * fog
Definition r_textures.h:135
struct rtexture_s * nmap
Definition r_textures.h:132
qbool qgenerateglow
Definition r_textures.h:164
unsigned int loadsequence
Definition r_textures.h:151
unsigned char * qpixels
Definition r_textures.h:157
int compareheight
Definition r_textures.h:146
struct rtexture_s * glow
Definition r_textures.h:134
qbool qgeneratenmap
Definition r_textures.h:163
qbool qgeneratemerged
Definition r_textures.h:162
qbool hasalpha
Definition r_textures.h:153