]> git.xonotic.org Git - xonotic/darkplaces.git/blob - r_textures.h
Add qdefs.h and qstats.h to split up quakedef.h. Make a lot of headers standalone...
[xonotic/darkplaces.git] / r_textures.h
1
2 #ifndef R_TEXTURES_H
3 #define R_TEXTURES_H
4
5 #include "qtypes.h"
6 #include "cvar.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
43 typedef enum textype_e
44 {
45         // placeholder for unused textures in r_rendertarget_t
46         TEXTYPE_UNUSED,
47
48         // 8bit paletted
49         TEXTYPE_PALETTE,
50         // 32bit RGBA
51         TEXTYPE_RGBA,
52         // 32bit BGRA (preferred format due to faster uploads on most hardware)
53         TEXTYPE_BGRA,
54         // 8bit ALPHA (used for freetype fonts)
55         TEXTYPE_ALPHA,
56         // 4x4 block compressed 15bit color (4 bits per pixel)
57         TEXTYPE_DXT1,
58         // 4x4 block compressed 15bit color plus 1bit alpha (4 bits per pixel)
59         TEXTYPE_DXT1A,
60         // 4x4 block compressed 15bit color plus 8bit alpha (8 bits per pixel)
61         TEXTYPE_DXT3,
62         // 4x4 block compressed 15bit color plus 8bit alpha (8 bits per pixel)
63         TEXTYPE_DXT5,
64
65         // default compressed type for GLES2
66         TEXTYPE_ETC1,
67
68         // 8bit paletted in sRGB colorspace
69         TEXTYPE_SRGB_PALETTE,
70         // 32bit RGBA in sRGB colorspace
71         TEXTYPE_SRGB_RGBA,
72         // 32bit BGRA (preferred format due to faster uploads on most hardware) in sRGB colorspace
73         TEXTYPE_SRGB_BGRA,
74         // 4x4 block compressed 15bit color (4 bits per pixel) in sRGB colorspace
75         TEXTYPE_SRGB_DXT1,
76         // 4x4 block compressed 15bit color plus 1bit alpha (4 bits per pixel) in sRGB colorspace
77         TEXTYPE_SRGB_DXT1A,
78         // 4x4 block compressed 15bit color plus 8bit alpha (8 bits per pixel) in sRGB colorspace
79         TEXTYPE_SRGB_DXT3,
80         // 4x4 block compressed 15bit color plus 8bit alpha (8 bits per pixel) in sRGB colorspace
81         TEXTYPE_SRGB_DXT5,
82
83         // this represents the same format as the framebuffer, for fast copies
84         TEXTYPE_COLORBUFFER,
85         // this represents an RGBA half_float texture (4 16bit floats)
86         TEXTYPE_COLORBUFFER16F,
87         // this represents an RGBA float texture (4 32bit floats)
88         TEXTYPE_COLORBUFFER32F,
89         // depth-stencil buffer (or texture)
90         TEXTYPE_DEPTHBUFFER16,
91         // depth-stencil buffer (or texture)
92         TEXTYPE_DEPTHBUFFER24,
93         // 32bit D24S8 buffer (24bit depth, 8bit stencil), not supported on OpenGL ES
94         TEXTYPE_DEPTHBUFFER24STENCIL8,
95         // shadowmap-friendly format with depth comparison (not supported on some hardware)
96         TEXTYPE_SHADOWMAP16_COMP,
97         // shadowmap-friendly format with raw reading (not supported on some hardware)
98         TEXTYPE_SHADOWMAP16_RAW,
99         // shadowmap-friendly format with depth comparison (not supported on some hardware)
100         TEXTYPE_SHADOWMAP24_COMP,
101         // shadowmap-friendly format with raw reading (not supported on some hardware)
102         TEXTYPE_SHADOWMAP24_RAW,
103 }
104 textype_t;
105
106 // contents of this structure are mostly private to gl_textures.c
107 typedef 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 }
116 rtexture_t;
117
118 // contents of this structure are private to gl_textures.c
119 typedef struct rtexturepool_s
120 {
121         int useless;
122 }
123 rtexturepool_t;
124
125 typedef void (*updatecallback_t)(rtexture_t *rt, void *data);
126
127 // allocate a texture pool, to be used with R_LoadTexture
128 rtexturepool_t *R_AllocTexturePool(void);
129 // free a texture pool (textures can not be freed individually)
130 void R_FreeTexturePool(rtexturepool_t **rtexturepool);
131
132 // the color/normal/etc cvars should be checked by callers of R_LoadTexture* functions to decide whether to add TEXF_COMPRESS to the flags
133 extern cvar_t gl_texturecompression;
134 extern cvar_t gl_texturecompression_color;
135 extern cvar_t gl_texturecompression_normal;
136 extern cvar_t gl_texturecompression_gloss;
137 extern cvar_t gl_texturecompression_glow;
138 extern cvar_t gl_texturecompression_2d;
139 extern cvar_t gl_texturecompression_q3bsplightmaps;
140 extern cvar_t gl_texturecompression_q3bspdeluxemaps;
141 extern cvar_t gl_texturecompression_sky;
142 extern cvar_t gl_texturecompression_lightcubemaps;
143 extern cvar_t gl_texturecompression_reflectmask;
144 extern cvar_t r_texture_dds_load;
145 extern cvar_t r_texture_dds_save;
146
147 // add a texture to a pool and optionally precache (upload) it
148 // (note: data == NULL is perfectly acceptable)
149 // (note: palette must not be NULL if using TEXTYPE_PALETTE)
150 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);
151 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);
152 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);
153 rtexture_t *R_LoadTextureShadowMap2D(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, textype_t textype, qbool filter);
154 rtexture_t *R_LoadTextureRenderBuffer(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, textype_t textype);
155 rtexture_t *R_LoadTextureDDSFile(rtexturepool_t *rtexturepool, const char *filename, qbool srgb, int flags, qbool *hasalphaflag, float *avgcolor, int miplevel, qbool optionaltexture);
156
157 // saves a texture to a DDS file
158 int R_SaveTextureDDSFile(rtexture_t *rt, const char *filename, qbool skipuncompressed, qbool hasalpha);
159
160 // free a texture
161 void R_FreeTexture(rtexture_t *rt);
162
163 // update a portion of the image data of a texture, used by lightmap updates
164 // and procedural textures such as video playback, actual uploads may be
165 // delayed by gl_nopartialtextureupdates cvar until R_Mesh_TexBind uses it
166 void R_UpdateTexture(rtexture_t *rt, const unsigned char *data, int x, int y, int z, int width, int height, int depth);
167
168 // returns the renderer dependent texture slot number (call this before each
169 // use, as a texture might not have been precached)
170 #define R_GetTexture(rt) ((rt) ? ((rt)->dirty ? R_RealGetTexture(rt) : (rt)->texnum) : r_texture_white->texnum)
171 int R_RealGetTexture (rtexture_t *rt);
172
173 // returns width of texture, as was specified when it was uploaded
174 int R_TextureWidth(rtexture_t *rt);
175
176 // returns height of texture, as was specified when it was uploaded
177 int R_TextureHeight(rtexture_t *rt);
178
179 // returns flags of texture, as was specified when it was uploaded
180 int R_TextureFlags(rtexture_t *rt);
181
182 // only frees the texture if TEXF_PERSISTENT is not set
183 // also resets the variable
184 void R_PurgeTexture(rtexture_t *prt);
185
186 // frees processing buffers each frame, and may someday animate procedural textures
187 void R_Textures_Frame(void);
188
189 // maybe rename this - sounds awful? [11/21/2007 Black]
190 void R_MarkDirtyTexture(rtexture_t *rt);
191 void R_MakeTextureDynamic(rtexture_t *rt, updatecallback_t updatecallback, void *data);
192
193 // Clear the texture's contents
194 void R_ClearTexture (rtexture_t *rt);
195
196 // returns the desired picmip level for given TEXF_ flags
197 int R_PicmipForFlags(int flags);
198
199 void R_TextureStats_Print(qbool printeach, qbool printpool, qbool printtotal);
200
201 #endif
202