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 *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);
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 final
34 : {
35 : enum
36 : {
37 : IMAGE = 0,
38 : TYPE = 0xFF,
39 :
40 : STUB = 1<<8,
41 : TRANSIENT = 1<<9,
42 : ALPHA = 1<<11,
43 : MIRROR = 1<<12
44 : };
45 :
46 : const char *name;
47 : int type, w, h, xs, ys, bpp, clamp;
48 : bool mipmap, canreduce;
49 : GLuint id;
50 : uchar *alphamask;
51 :
52 1 : Texture() : alphamask(nullptr) {}
53 : const uchar * loadalphamask();
54 : float ratio() const;
55 : bool reload(); //if the texture does not have a valid GL texture, attempts to reload it
56 :
57 : };
58 :
59 : enum TextureLayers
60 : {
61 : Tex_Diffuse = 0,
62 : Tex_Normal,
63 : Tex_Glow,
64 :
65 : Tex_Spec,
66 : Tex_Depth,
67 : Tex_Alpha,
68 : Tex_Unknown,
69 : };
70 :
71 : struct MatSlot final : Slot, VSlot
72 : {
73 : MatSlot();
74 :
75 : /**
76 : * @brief Returns the type of slot object that this is.
77 : *
78 : * This is an enum value in the enum in slot.h in the slot object.
79 : *
80 : * @return SlotType_Material enum value
81 : */
82 : int type() const final;
83 :
84 : /**
85 : * @brief Returns string indicating what material slot this is.
86 : *
87 : * The return string is one of the four tempformatstring array entries. The
88 : * string returned has the format "material string <name>"
89 : *
90 : * @return pointer to c string containing this slot's name
91 : */
92 : const char *name() const final;
93 :
94 : /**
95 : * @brief Filler implementation of emptyvslot.
96 : *
97 : * Does not return an empty vslot like for the VSlot object. Returns
98 : * reference to `this` object instead regardless of its status.
99 : *
100 : * @return reference to `this` object
101 : */
102 : VSlot &emptyvslot() final;
103 :
104 : int cancombine(int) const final;
105 :
106 : void reset();
107 : void cleanup();
108 : };
109 :
110 : struct TexRotation final
111 : {
112 : bool flipx, flipy, swapxy;
113 : };
114 :
115 : extern const std::array<TexRotation, 8> texrotations;
116 : extern Texture *notexture;
117 : extern int maxvsuniforms;
118 :
119 : extern SDL_Surface *loadsurface(const char *name);
120 :
121 : extern MatSlot &lookupmaterialslot(int slot, bool load = true);
122 :
123 : extern void mergevslot(VSlot &dst, const VSlot &src, const VSlot &delta);
124 : extern void packvslot(std::vector<uchar> &buf, const VSlot &src);
125 :
126 : extern Slot dummyslot;
127 : extern DecalSlot dummydecalslot;
128 :
129 : #endif
|