]> icculus.org git repositories - divverent/darkplaces.git/blob - r_textures.h
fix typo in last commit
[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 // indicates texture coordinates should be clamped rather than wrapping
10 #define TEXF_CLAMP 0x00000020
11 // indicates texture should be uploaded using GL_NEAREST or GL_NEAREST_MIPMAP_NEAREST mode
12 #define TEXF_FORCENEAREST 0x00000040
13 // indicates texture should be uploaded using GL_LINEAR or GL_LINEAR_MIPMAP_NEAREST or GL_LINEAR_MIPMAP_LINEAR mode
14 #define TEXF_FORCELINEAR 0x00000080
15 // indicates texture should be affected by gl_picmip and gl_max_size cvar
16 #define TEXF_PICMIP 0x00000100
17 // indicates texture should be compressed if possible
18 #define TEXF_COMPRESS 0x00000200
19 // 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)
20 #define TEXF_PERSISTENT 0x00000400
21 // indicates texture should use GL_COMPARE_R_TO_TEXTURE mode
22 #define TEXF_COMPARE 0x00000800
23 // indicates texture should use lower precision where supported
24 #define TEXF_LOWPRECISION 0x00001000
25 // indicates texture should support R_UpdateTexture
26 #define TEXF_ALLOWUPDATES 0x00002000
27 // indicates texture should support R_FlushTexture (improving speed on multiple partial updates per draw)
28 #define TEXF_MANUALFLUSHUPDATES 0x00004000
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         // 8bit ALPHA (used for freetype fonts)
43         TEXTYPE_ALPHA,
44 }
45 textype_t;
46
47 // contents of this structure are mostly private to gl_textures.c
48 typedef struct rtexture_s
49 {
50         // this is exposed (rather than private) for speed reasons only
51         int texnum;
52 }
53 rtexture_t;
54
55 // contents of this structure are private to gl_textures.c
56 typedef struct rtexturepool_s
57 {
58         int useless;
59 }
60 rtexturepool_t;
61
62 typedef void (*updatecallback_t)(rtexture_t *rt, void *data);
63
64 // allocate a texture pool, to be used with R_LoadTexture
65 rtexturepool_t *R_AllocTexturePool(void);
66 // free a texture pool (textures can not be freed individually)
67 void R_FreeTexturePool(rtexturepool_t **rtexturepool);
68
69 // the color/normal/etc cvars should be checked by callers of R_LoadTexture* functions to decide whether to add TEXF_COMPRESS to the flags
70 extern cvar_t gl_texturecompression;
71 extern cvar_t gl_texturecompression_color;
72 extern cvar_t gl_texturecompression_normal;
73 extern cvar_t gl_texturecompression_gloss;
74 extern cvar_t gl_texturecompression_glow;
75 extern cvar_t gl_texturecompression_2d;
76 extern cvar_t gl_texturecompression_q3bsplightmaps;
77 extern cvar_t gl_texturecompression_q3bspdeluxemaps;
78 extern cvar_t gl_texturecompression_sky;
79 extern cvar_t gl_texturecompression_lightcubemaps;
80
81 // add a texture to a pool and optionally precache (upload) it
82 // (note: data == NULL is perfectly acceptable)
83 // (note: palette must not be NULL if using TEXTYPE_PALETTE)
84 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);
85 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);
86 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);
87 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);
88 rtexture_t *R_LoadTextureShadowMapRectangle(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, int precision, qboolean filter);
89 rtexture_t *R_LoadTextureShadowMap2D(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, int precision, qboolean filter);
90 rtexture_t *R_LoadTextureShadowMapCube(rtexturepool_t *rtexturepool, const char *identifier, int width, int precision, qboolean filter);
91
92 // free a texture
93 void R_FreeTexture(rtexture_t *rt);
94
95 // update a portion of the image data of a texture, used by lightmap updates
96 // and procedural textures such as video playback.
97 // if TEXF_MANUALFLUSHUPDATES is used, you MUST call R_FlushTexture to apply the updates
98 void R_UpdateTexture(rtexture_t *rt, const unsigned char *data, int x, int y, int width, int height);
99 // if TEXF_MANUALFLUSHUPDATES is used, call this to apply the updates,
100 // otherwise this function does nothing
101 void R_FlushTexture(rtexture_t *rt);
102
103 // returns the renderer dependent texture slot number (call this before each
104 // use, as a texture might not have been precached)
105 #define R_GetTexture(rt) ((rt) ? ((rt)->texnum > 0 ? (rt)->texnum : R_RealGetTexture(rt)) : r_texture_white->texnum)
106 int R_RealGetTexture (rtexture_t *rt);
107
108 // returns width of texture, as was specified when it was uploaded
109 int R_TextureWidth(rtexture_t *rt);
110
111 // returns height of texture, as was specified when it was uploaded
112 int R_TextureHeight(rtexture_t *rt);
113
114 // only frees the texture if TEXF_PERSISTENT is not set
115 // also resets the variable
116 void R_PurgeTexture(rtexture_t *prt);
117
118 // frees processing buffers each frame, and may someday animate procedural textures
119 void R_Textures_Frame(void);
120
121 // maybe rename this - sounds awful? [11/21/2007 Black]
122 void R_MarkDirtyTexture(rtexture_t *rt);
123 void R_MakeTextureDynamic(rtexture_t *rt, updatecallback_t updatecallback, void *data);
124
125 // Clear the texture's contents
126 void R_ClearTexture (rtexture_t *rt);
127
128 #endif
129