]> icculus.org git repositories - divverent/darkplaces.git/blob - r_textures.h
Adding the new vm
[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 // allocated as a fragment in a larger texture, mipmap is not allowed with
14 // this, mostly used for lightmaps
15 #define TEXF_FRAGMENT 0x00000010
16 // indicates texture coordinates should be clamped rather than wrapping
17 #define TEXF_CLAMP 0x00000020
18 // indicates texture should be uploaded using GL_NEAREST or GL_NEAREST_MIPMAP_NEAREST mode
19 #define TEXF_FORCENEAREST 0x00000040
20 // indicates texture should be uploaded using GL_LINEAR or GL_LINEAR_MIPMAP_NEAREST or GL_LINEAR_MIPMAP_LINEAR mode
21 #define TEXF_FORCELINEAR 0x00000080
22 // used for checking if textures mismatch
23 #define TEXF_IMPORTANTBITS (TEXF_ALPHA | TEXF_MIPMAP | TEXF_FRAGMENT | TEXF_CLAMP | TEXF_FORCENEAREST | TEXF_FORCELINEAR)
24
25 // 8bit paletted
26 #define TEXTYPE_PALETTE 1
27 // 24bit RGB
28 #define TEXTYPE_RGB 2
29 // 32bit RGBA
30 #define TEXTYPE_RGBA 3
31 // 16bit DSDT
32 #define TEXTYPE_DSDT 4
33
34 // contents of this structure are mostly private to gl_textures.c
35 typedef struct
36 {
37         // this is exposed (rather than private) for speed reasons only
38         int texnum;
39 }
40 rtexture_t;
41
42 // contents of this structure are private to gl_textures.c
43 typedef struct
44 {
45         int useless;
46 }
47 rtexturepool_t;
48
49 // allocate a texture pool, to be used with R_LoadTexture
50 rtexturepool_t *R_AllocTexturePool(void);
51 // free a texture pool (textures can not be freed individually)
52 void R_FreeTexturePool(rtexturepool_t **rtexturepool);
53
54 // important technical note:
55 // fragment textures must have a width that is compatible with the fragment
56 // update system, to get a compliant size, use R_CompatibleFragmentWidth
57 int R_CompatibleFragmentWidth(int width, int textype, int flags);
58
59 // add a texture to a pool and optionally precache (upload) it
60 // (note: data == NULL is perfectly acceptable)
61 // (note: palette must not be NULL if using TEXTYPE_PALETTE)
62 rtexture_t *R_LoadTexture1D(rtexturepool_t *rtexturepool, const char *identifier, int width, const qbyte *data, int textype, int flags, const unsigned int *palette);
63 rtexture_t *R_LoadTexture2D(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, const qbyte *data, int textype, int flags, const unsigned int *palette);
64 rtexture_t *R_LoadTexture3D(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, int depth, const qbyte *data, int textype, int flags, const unsigned int *palette);
65 rtexture_t *R_LoadTextureCubeMap(rtexturepool_t *rtexturepool, const char *identifier, int width, const qbyte *data, int textype, int flags, const unsigned int *palette);
66
67 // free a texture
68 void R_FreeTexture(rtexture_t *rt);
69
70 // update the image data of a texture, used by lightmap updates and
71 // procedural textures.
72 void R_UpdateTexture(rtexture_t *rt, qbyte *data);
73
74 // location of the fragment in the texture (note: any parameter except rt can
75 // be NULL)
76 void R_FragmentLocation(rtexture_t *rt, int *x, int *y, float *fx1, float *fy1, float *fx2, float *fy2);
77 void R_FragmentLocation3D(rtexture_t *rt, int *x, int *y, int *z, float *fx1, float *fy1, float *fz1, float *fx2, float *fy2, float *fz2);
78
79 // returns the renderer dependent texture slot number (call this before each
80 // use, as a texture might not have been precached)
81 #define R_GetTexture(rt) ((rt) ? ((rt)->texnum >= 0 ? (rt)->texnum : R_RealGetTexture(rt)) : 0)
82 int R_RealGetTexture (rtexture_t *rt);
83
84 // returns true if the texture is transparent (useful for rendering code)
85 int R_TextureHasAlpha(rtexture_t *rt);
86
87 // returns width of texture, as was specified when it was uploaded
88 int R_TextureWidth(rtexture_t *rt);
89
90 // returns height of texture, as was specified when it was uploaded
91 int R_TextureHeight(rtexture_t *rt);
92
93 // frees processing buffers each frame, and may someday animate procedural textures
94 void R_Textures_Frame(void);
95
96 #endif
97