]> git.xonotic.org Git - xonotic/darkplaces.git/blob - r_textures.h
Now with new Travis secret key.
[xonotic/darkplaces.git] / r_textures.h
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
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 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
145         int comparewidth;
146         int compareheight;
147         int comparecrc;
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
153         qbool hasalpha;
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;
158         int qwidth;
159         int qheight;
160         qbool qhascolormapping;
161         qbool qgeneratebase;
162         qbool qgeneratemerged;
163         qbool qgeneratenmap;
164         qbool qgenerateglow;
165 }
166 skinframe_t;
167
168 typedef void (*updatecallback_t)(rtexture_t *rt, void *data);
169
170 // allocate a texture pool, to be used with R_LoadTexture
171 rtexturepool_t *R_AllocTexturePool(void);
172 // free a texture pool (textures can not be freed individually)
173 void 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
176 extern struct cvar_s gl_texturecompression;
177 extern struct cvar_s gl_texturecompression_color;
178 extern struct cvar_s gl_texturecompression_normal;
179 extern struct cvar_s gl_texturecompression_gloss;
180 extern struct cvar_s gl_texturecompression_glow;
181 extern struct cvar_s gl_texturecompression_2d;
182 extern struct cvar_s gl_texturecompression_q3bsplightmaps;
183 extern struct cvar_s gl_texturecompression_q3bspdeluxemaps;
184 extern struct cvar_s gl_texturecompression_sky;
185 extern struct cvar_s gl_texturecompression_lightcubemaps;
186 extern struct cvar_s gl_texturecompression_reflectmask;
187 extern struct cvar_s r_texture_dds_load;
188 extern 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)
193 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);
194 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);
195 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);
196 rtexture_t *R_LoadTextureShadowMap2D(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, textype_t textype, qbool filter);
197 rtexture_t *R_LoadTextureRenderBuffer(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, textype_t textype);
198 rtexture_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
201 int R_SaveTextureDDSFile(rtexture_t *rt, const char *filename, qbool skipuncompressed, qbool hasalpha);
202
203 // free a texture
204 void 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)
210 void 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)
215 int R_RealGetTexture (rtexture_t *rt);
216
217 // returns width of texture, as was specified when it was uploaded
218 int R_TextureWidth(rtexture_t *rt);
219
220 // returns height of texture, as was specified when it was uploaded
221 int R_TextureHeight(rtexture_t *rt);
222
223 // returns flags of texture, as was specified when it was uploaded
224 int R_TextureFlags(rtexture_t *rt);
225
226 // only frees the texture if TEXF_PERSISTENT is not set
227 // also resets the variable
228 void R_PurgeTexture(rtexture_t *prt);
229
230 // frees processing buffers each frame, and may someday animate procedural textures
231 void R_Textures_Frame(void);
232
233 // maybe rename this - sounds awful? [11/21/2007 Black]
234 void R_MarkDirtyTexture(rtexture_t *rt);
235 void R_MakeTextureDynamic(rtexture_t *rt, updatecallback_t updatecallback, void *data);
236
237 // Clear the texture's contents
238 void R_ClearTexture (rtexture_t *rt);
239
240 // returns the desired picmip level for given TEXF_ flags
241 int R_PicmipForFlags(int flags);
242
243 void R_TextureStats_Print(qbool printeach, qbool printpool, qbool printtotal);
244
245 #endif
246