Line data Source code
1 : #ifndef TEXTURE_H_
2 : #define TEXTURE_H_
3 :
4 : extern int hwtexsize, hwcubetexsize, hwmaxaniso, maxtexsize, hwtexunits, hwvtexunits;
5 :
6 : extern Texture *textureload(const char *name, int clamp = 0, bool mipit = true, bool msg = true);
7 : extern bool floatformat(GLenum format);
8 : extern void loadshaders();
9 : extern void createtexture(int tnum, int w, int h, const void *pixels, int clamp, int filter, GLenum component = GL_RGB, GLenum target = GL_TEXTURE_2D, int pw = 0, int ph = 0, int pitch = 0, bool resize = true, GLenum format = GL_FALSE, bool swizzle = false);
10 : extern void create3dtexture(int tnum, int w, int h, int d, const void *pixels, int clamp, int filter, GLenum component = GL_RGB, GLenum target = GL_TEXTURE_3D, bool swizzle = false);
11 : extern bool reloadtexture(const char *name);
12 : extern void clearslots();
13 : extern void compacteditvslots();
14 : extern void compactvslots(cube * const c, int n = 8);
15 : extern void compactvslot(int &index);
16 : extern void compactvslot(VSlot &vs);
17 : extern void reloadtextures();
18 : extern void cleanuptextures();
19 : extern bool settexture(const char *name, int clamp = 0);
20 :
21 : //for imagedata manipulation
22 : extern void scaletexture(const uchar * RESTRICT src, uint sw, uint sh, uint bpp, uint pitch, uchar * RESTRICT dst, uint dw, uint dh);
23 : extern void reorienttexture(const uchar * RESTRICT src, int sw, int sh, int bpp, int stride, uchar * RESTRICT dst, bool flipx, bool flipy, bool swapxy);
24 : extern GLenum texformat(int bpp, bool swizzle = false);
25 :
26 : struct Slot;
27 : struct VSlot;
28 :
29 : // management of texture slots
30 : // each texture slot can have multiple texture frames, of which currently only the first is used
31 : // additional frames can be used for various shaders
32 :
33 : struct Texture
34 : {
35 : enum
36 : {
37 : IMAGE = 0,
38 : CUBEMAP = 1,
39 : TYPE = 0xFF,
40 :
41 : STUB = 1<<8,
42 : TRANSIENT = 1<<9,
43 : COMPRESSED = 1<<10,
44 : ALPHA = 1<<11,
45 : MIRROR = 1<<12,
46 : FLAGS = 0xFF00
47 : };
48 :
49 : char *name;
50 : int type, w, h, xs, ys, bpp, clamp;
51 : bool mipmap, canreduce;
52 : GLuint id;
53 : uchar *alphamask;
54 :
55 1 : Texture() : alphamask(nullptr) {}
56 : const uchar * loadalphamask();
57 : float ratio() const;
58 : bool reload(); //if the texture does not have a valid GL texture, attempts to reload it
59 :
60 : };
61 :
62 : enum TextureLayers
63 : {
64 : Tex_Diffuse = 0,
65 : Tex_Normal,
66 : Tex_Glow,
67 :
68 : Tex_Spec,
69 : Tex_Depth,
70 : Tex_Alpha,
71 : Tex_Unknown,
72 : };
73 :
74 : struct MatSlot final : Slot, VSlot
75 : {
76 : MatSlot();
77 :
78 0 : int type() const override final
79 : {
80 0 : return SlotType_Material;
81 : }
82 : const char *name() const override final;
83 :
84 0 : VSlot &emptyvslot() override final
85 : {
86 0 : return *this;
87 : }
88 :
89 0 : int cancombine(int) const override final
90 : {
91 0 : return -1;
92 : }
93 :
94 0 : void reset()
95 : {
96 0 : Slot::reset();
97 0 : VSlot::reset();
98 0 : }
99 :
100 0 : void cleanup()
101 : {
102 0 : Slot::cleanup();
103 0 : VSlot::cleanup();
104 0 : }
105 : };
106 :
107 : struct texrotation
108 : {
109 : bool flipx, flipy, swapxy;
110 : };
111 :
112 : extern const texrotation texrotations[8];
113 : extern Texture *notexture;
114 : extern int maxvsuniforms, maxfsuniforms;
115 :
116 : extern SDL_Surface *loadsurface(const char *name);
117 :
118 : extern MatSlot &lookupmaterialslot(int slot, bool load = true);
119 :
120 : extern void mergevslot(VSlot &dst, const VSlot &src, const VSlot &delta);
121 : extern void packvslot(std::vector<uchar> &buf, const VSlot &src);
122 :
123 : extern Slot dummyslot;
124 : extern VSlot dummyvslot;
125 : extern DecalSlot dummydecalslot;
126 :
127 : #endif
|