]> icculus.org git repositories - divverent/darkplaces.git/blob - r_textures.h
- fix specular stuff on Q1BSP
[divverent/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 // upload if r_textureprecache >= 1, otherwise defer loading until it is used
10 #define TEXF_PRECACHE 0x00000004
11 // upload immediately, never defer (ignore r_textureprecache)
12 #define TEXF_ALWAYSPRECACHE 0x00000008
13 // indicates texture coordinates should be clamped rather than wrapping
14 #define TEXF_CLAMP 0x00000020
15 // indicates texture should be uploaded using GL_NEAREST or GL_NEAREST_MIPMAP_NEAREST mode
16 #define TEXF_FORCENEAREST 0x00000040
17 // indicates texture should be uploaded using GL_LINEAR or GL_LINEAR_MIPMAP_NEAREST or GL_LINEAR_MIPMAP_LINEAR mode
18 #define TEXF_FORCELINEAR 0x00000080
19 // indicates texture should be affected by gl_picmip and gl_max_size cvar
20 #define TEXF_PICMIP 0x00000100
21 // indicates texture should be compressed if possible
22 #define TEXF_COMPRESS 0x00000200
23 // use this flag to block R_PurgeTexture from freeing a texture
24 #define TEXF_PERSISTENT 0x00000400
25 // indicates texture should use GL_COMPARE_R_TO_TEXTURE mode
26 #define TEXF_COMPARE 0x00000800
27 // indicates texture should use lower precision where supported
28 #define TEXF_LOWPRECISION 0x00001000
29 // used for checking if textures mismatch
30 #define TEXF_IMPORTANTBITS (TEXF_ALPHA | TEXF_MIPMAP | TEXF_CLAMP | TEXF_FORCENEAREST | TEXF_FORCELINEAR | TEXF_PICMIP | TEXF_COMPRESS | TEXF_COMPARE | TEXF_LOWPRECISION)
31
32 typedef enum textype_e
33 {
34         // 8bit paletted
35         TEXTYPE_PALETTE,
36         // 32bit RGBA
37         TEXTYPE_RGBA,
38         // 32bit BGRA (preferred format due to faster uploads on most hardware)
39         TEXTYPE_BGRA,
40         // 16bit D16 (16bit depth) or 32bit S8D24 (24bit depth, 8bit stencil unused)
41         TEXTYPE_SHADOWMAP,
42 }
43 textype_t;
44
45 // contents of this structure are mostly private to gl_textures.c
46 typedef struct rtexture_s
47 {
48         // this is exposed (rather than private) for speed reasons only
49         int texnum;
50 }
51 rtexture_t;
52
53 // contents of this structure are private to gl_textures.c
54 typedef struct rtexturepool_s
55 {
56         int useless;
57 }
58 rtexturepool_t;
59
60 typedef void (*updatecallback_t)(rtexture_t *rt, void *data);
61
62 // allocate a texture pool, to be used with R_LoadTexture
63 rtexturepool_t *R_AllocTexturePool(void);
64 // free a texture pool (textures can not be freed individually)
65 void R_FreeTexturePool(rtexturepool_t **rtexturepool);
66
67 // the color/normal/etc cvars should be checked by callers of R_LoadTexture* functions to decide whether to add TEXF_COMPRESS to the flags
68 extern cvar_t gl_texturecompression;
69 extern cvar_t gl_texturecompression_color;
70 extern cvar_t gl_texturecompression_normal;
71 extern cvar_t gl_texturecompression_gloss;
72 extern cvar_t gl_texturecompression_glow;
73 extern cvar_t gl_texturecompression_2d;
74 extern cvar_t gl_texturecompression_q3bsplightmaps;
75 extern cvar_t gl_texturecompression_q3bspdeluxemaps;
76 extern cvar_t gl_texturecompression_sky;
77 extern cvar_t gl_texturecompression_lightcubemaps;
78
79 // add a texture to a pool and optionally precache (upload) it
80 // (note: data == NULL is perfectly acceptable)
81 // (note: palette must not be NULL if using TEXTYPE_PALETTE)
82 rtexture_t *R_LoadTexture2D(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, const unsigned char *data, textype_t textype, int flags, const unsigned int *palette);
83 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, const unsigned int *palette);
84 rtexture_t *R_LoadTextureCubeMap(rtexturepool_t *rtexturepool, const char *identifier, int width, const unsigned char *data, textype_t textype, int flags, const unsigned int *palette);
85 rtexture_t *R_LoadTextureRectangle(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, const unsigned char *data, textype_t textype, int flags, const unsigned int *palette);
86 rtexture_t *R_LoadTextureShadowMapRectangle(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, int precision, qboolean filter);
87 rtexture_t *R_LoadTextureShadowMap2D(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, int precision, qboolean filter);
88 rtexture_t *R_LoadTextureShadowMapCube(rtexturepool_t *rtexturepool, const char *identifier, int width, int precision, qboolean filter);
89
90 // free a texture
91 void R_FreeTexture(rtexture_t *rt);
92
93 // update a portion of the image data of a texture, used by lightmap updates
94 // and procedural textures such as video playback.
95 void R_UpdateTexture(rtexture_t *rt, const unsigned char *data, int x, int y, int width, int height);
96
97 // returns the renderer dependent texture slot number (call this before each
98 // use, as a texture might not have been precached)
99 #define R_GetTexture(rt) ((rt) ? ((rt)->texnum > 0 ? (rt)->texnum : R_RealGetTexture(rt)) : r_texture_white->texnum)
100 int R_RealGetTexture (rtexture_t *rt);
101
102 // returns width of texture, as was specified when it was uploaded
103 int R_TextureWidth(rtexture_t *rt);
104
105 // returns height of texture, as was specified when it was uploaded
106 int R_TextureHeight(rtexture_t *rt);
107
108 // only frees the texture if TEXF_PERSISTENT is not set
109 // also resets the variable
110 void R_PurgeTexture(rtexture_t *prt);
111
112 // frees processing buffers each frame, and may someday animate procedural textures
113 void R_Textures_Frame(void);
114
115 // maybe rename this - sounds awful? [11/21/2007 Black]
116 void R_MarkDirtyTexture(rtexture_t *rt);
117 void R_MakeTextureDynamic(rtexture_t *rt, updatecallback_t updatecallback, void *data);
118
119 // Clear the texture's contents
120 void R_ClearTexture (rtexture_t *rt);
121
122 #endif
123