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