]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - r_textures.h
fix screenshot prefix updates on gamedir change
[xonotic/darkplaces.git] / r_textures.h
1
2 #ifndef R_TEXTURES_H
3 #define R_TEXTURES_H
4
5 // transparent
6 #define TEXF_ALPHA 0x00000001
7 // mipmapped
8 #define TEXF_MIPMAP 0x00000002
9 // multiply RGB by A channel before uploading
10 #define TEXF_RGBMULTIPLYBYALPHA 0x00000004
11 // indicates texture coordinates should be clamped rather than wrapping
12 #define TEXF_CLAMP 0x00000020
13 // indicates texture should be uploaded using GL_NEAREST or GL_NEAREST_MIPMAP_NEAREST mode
14 #define TEXF_FORCENEAREST 0x00000040
15 // indicates texture should be uploaded using GL_LINEAR or GL_LINEAR_MIPMAP_NEAREST or GL_LINEAR_MIPMAP_LINEAR mode
16 #define TEXF_FORCELINEAR 0x00000080
17 // indicates texture should be affected by gl_picmip and gl_max_size cvar
18 #define TEXF_PICMIP 0x00000100
19 // indicates texture should be compressed if possible
20 #define TEXF_COMPRESS 0x00000200
21 // 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)
22 #define TEXF_PERSISTENT 0x00000400
23 // indicates texture should use GL_COMPARE_R_TO_TEXTURE mode
24 #define TEXF_COMPARE 0x00000800
25 // indicates texture should use lower precision where supported
26 #define TEXF_LOWPRECISION 0x00001000
27 // indicates texture should support R_UpdateTexture on small regions, actual uploads may be delayed until R_Mesh_TexBind if gl_nopartialtextureupdates is on
28 #define TEXF_ALLOWUPDATES 0x00002000
29 // indicates texture should be affected by gl_picmip_world and r_picmipworld (maybe others in the future) instead of gl_picmip_other
30 #define TEXF_ISWORLD 0x00004000
31 // indicates texture should be affected by gl_picmip_sprites and r_picmipsprites (maybe others in the future) instead of gl_picmip_other
32 #define TEXF_ISSPRITE 0x00008000
33 // indicates the texture will be used as a render target (D3D hint)
34 #define TEXF_RENDERTARGET 0x0010000
35 // used for checking if textures mismatch
36 #define TEXF_IMPORTANTBITS (TEXF_ALPHA | TEXF_MIPMAP | TEXF_RGBMULTIPLYBYALPHA | TEXF_CLAMP | TEXF_FORCENEAREST | TEXF_FORCELINEAR | TEXF_PICMIP | TEXF_COMPRESS | TEXF_COMPARE | TEXF_LOWPRECISION | TEXF_RENDERTARGET)
37
38 typedef enum textype_e
39 {
40         // 8bit paletted
41         TEXTYPE_PALETTE,
42         // 32bit RGBA
43         TEXTYPE_RGBA,
44         // 32bit BGRA (preferred format due to faster uploads on most hardware)
45         TEXTYPE_BGRA,
46         // 8bit ALPHA (used for freetype fonts)
47         TEXTYPE_ALPHA,
48         // 4x4 block compressed 15bit color (4 bits per pixel)
49         TEXTYPE_DXT1,
50         // 4x4 block compressed 15bit color plus 1bit alpha (4 bits per pixel)
51         TEXTYPE_DXT1A,
52         // 4x4 block compressed 15bit color plus 8bit alpha (8 bits per pixel)
53         TEXTYPE_DXT3,
54         // 4x4 block compressed 15bit color plus 8bit alpha (8 bits per pixel)
55         TEXTYPE_DXT5,
56
57         // 8bit paletted in sRGB colorspace
58         TEXTYPE_SRGB_PALETTE,
59         // 32bit RGBA in sRGB colorspace
60         TEXTYPE_SRGB_RGBA,
61         // 32bit BGRA (preferred format due to faster uploads on most hardware) in sRGB colorspace
62         TEXTYPE_SRGB_BGRA,
63         // 4x4 block compressed 15bit color (4 bits per pixel) in sRGB colorspace
64         TEXTYPE_SRGB_DXT1,
65         // 4x4 block compressed 15bit color plus 1bit alpha (4 bits per pixel) in sRGB colorspace
66         TEXTYPE_SRGB_DXT1A,
67         // 4x4 block compressed 15bit color plus 8bit alpha (8 bits per pixel) in sRGB colorspace
68         TEXTYPE_SRGB_DXT3,
69         // 4x4 block compressed 15bit color plus 8bit alpha (8 bits per pixel) in sRGB colorspace
70         TEXTYPE_SRGB_DXT5,
71
72         // this represents the same format as the framebuffer, for fast copies
73         TEXTYPE_COLORBUFFER,
74         // this represents an RGBA half_float texture (4 16bit floats)
75         TEXTYPE_COLORBUFFER16F,
76         // this represents an RGBA float texture (4 32bit floats)
77         TEXTYPE_COLORBUFFER32F,
78         // 16bit D16 (16bit depth) or 32bit S8D24 (24bit depth, 8bit stencil unused)
79         TEXTYPE_SHADOWMAP
80 }
81 textype_t;
82
83 /*
84 #ifdef WIN32
85 #define SUPPORTD3D
86 #define SUPPORTDIRECTX
87 #ifdef SUPPORTD3D
88 #include <d3d9.h>
89 #endif
90 #endif
91 */
92
93 // contents of this structure are mostly private to gl_textures.c
94 typedef struct rtexture_s
95 {
96         // this is exposed (rather than private) for speed reasons only
97         int texnum;
98         qboolean dirty;
99         int gltexturetypeenum; // exposed for use in R_Mesh_TexBind
100         // d3d stuff the backend needs
101         void *d3dtexture;
102 #ifdef SUPPORTD3D
103         qboolean d3disdepthsurface; // for depth/stencil surfaces
104         int d3dformat;
105         int d3dusage;
106         int d3dpool;
107         int d3daddressu;
108         int d3daddressv;
109         int d3daddressw;
110         int d3dmagfilter;
111         int d3dminfilter;
112         int d3dmipfilter;
113         int d3dmaxmiplevelfilter;
114         int d3dmipmaplodbias;
115         int d3dmaxmiplevel;
116 #endif
117 }
118 rtexture_t;
119
120 // contents of this structure are private to gl_textures.c
121 typedef struct rtexturepool_s
122 {
123         int useless;
124 }
125 rtexturepool_t;
126
127 typedef void (*updatecallback_t)(rtexture_t *rt, void *data);
128
129 // allocate a texture pool, to be used with R_LoadTexture
130 rtexturepool_t *R_AllocTexturePool(void);
131 // free a texture pool (textures can not be freed individually)
132 void R_FreeTexturePool(rtexturepool_t **rtexturepool);
133
134 // the color/normal/etc cvars should be checked by callers of R_LoadTexture* functions to decide whether to add TEXF_COMPRESS to the flags
135 extern cvar_t gl_texturecompression;
136 extern cvar_t gl_texturecompression_color;
137 extern cvar_t gl_texturecompression_normal;
138 extern cvar_t gl_texturecompression_gloss;
139 extern cvar_t gl_texturecompression_glow;
140 extern cvar_t gl_texturecompression_2d;
141 extern cvar_t gl_texturecompression_q3bsplightmaps;
142 extern cvar_t gl_texturecompression_q3bspdeluxemaps;
143 extern cvar_t gl_texturecompression_sky;
144 extern cvar_t gl_texturecompression_lightcubemaps;
145 extern cvar_t gl_texturecompression_reflectmask;
146 extern cvar_t r_texture_dds_load;
147 extern cvar_t r_texture_dds_save;
148
149 // add a texture to a pool and optionally precache (upload) it
150 // (note: data == NULL is perfectly acceptable)
151 // (note: palette must not be NULL if using TEXTYPE_PALETTE)
152 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);
153 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);
154 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);
155 rtexture_t *R_LoadTextureShadowMap2D(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, int precision, qboolean filter);
156 rtexture_t *R_LoadTextureDDSFile(rtexturepool_t *rtexturepool, const char *filename, int flags, qboolean *hasalphaflag, float *avgcolor, int miplevel);
157
158 // saves a texture to a DDS file
159 int R_SaveTextureDDSFile(rtexture_t *rt, const char *filename, qboolean skipuncompressed, qboolean hasalpha);
160
161 // free a texture
162 void R_FreeTexture(rtexture_t *rt);
163
164 // update a portion of the image data of a texture, used by lightmap updates
165 // and procedural textures such as video playback, actual uploads may be
166 // delayed by gl_nopartialtextureupdates cvar until R_Mesh_TexBind uses it
167 void R_UpdateTexture(rtexture_t *rt, const unsigned char *data, int x, int y, int z, int width, int height, int depth);
168
169 // returns the renderer dependent texture slot number (call this before each
170 // use, as a texture might not have been precached)
171 #define R_GetTexture(rt) ((rt) ? ((rt)->dirty ? R_RealGetTexture(rt) : (rt)->texnum) : r_texture_white->texnum)
172 int R_RealGetTexture (rtexture_t *rt);
173
174 // returns width of texture, as was specified when it was uploaded
175 int R_TextureWidth(rtexture_t *rt);
176
177 // returns height of texture, as was specified when it was uploaded
178 int R_TextureHeight(rtexture_t *rt);
179
180 // only frees the texture if TEXF_PERSISTENT is not set
181 // also resets the variable
182 void R_PurgeTexture(rtexture_t *prt);
183
184 // frees processing buffers each frame, and may someday animate procedural textures
185 void R_Textures_Frame(void);
186
187 // maybe rename this - sounds awful? [11/21/2007 Black]
188 void R_MarkDirtyTexture(rtexture_t *rt);
189 void R_MakeTextureDynamic(rtexture_t *rt, updatecallback_t updatecallback, void *data);
190
191 // Clear the texture's contents
192 void R_ClearTexture (rtexture_t *rt);
193
194 // returns the desired picmip level for given TEXF_ flags
195 int R_PicmipForFlags(int flags);
196
197 #endif
198