-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTexture.h
More file actions
528 lines (418 loc) · 18.7 KB
/
Texture.h
File metadata and controls
528 lines (418 loc) · 18.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
/*
Self Descriptive header
contains standalone texture helper functions
classes contained/hierarchy,
class Texture1D
|
|
|===> class Texture2D
| |
| |
| |===> class TextureMutable
|
|===> class Texture3D
|
|
|===> class TextureCube
*/
#ifndef TEX_H__
#define TEX_H__
#pragma comment(lib, "DevIL.lib")
#pragma comment(lib, "ilut.lib")
#pragma comment(lib, "ilu.lib")
#ifndef INCLUDE_SKYBOX_ONLY
#include "CoreEngine.h"
#endif
#include <il/il.h>
#include <il/ilu.h>
#include <il/ilut.h>
#include <gl/glext.h>
#include "Client.h"
namespace DifferentialArts
{
#define MAX_TEX 256
#define TEXTURE_INDEX_START 7
/*
This is a global texture array, preferably use this to store your textures
start from 7 Onwards in the array, the indices before 7 are used for
skybox textures and font texture.
If you use this array for your textures, you dont need to bother about
freeing them at all, the FreeTextures() function takes care of it
*/
typedef GLuint GLTexture;
extern GLuint g_Textures[MAX_TEX];
//Loads nearly any TEXTURE format, into a GLuint texture array
RX_API bool LoadTexture(const char* fileName, GLuint texArray[], GLuint texID, bool Mipmaps,
GLuint &width, GLuint &height, bool sClampToEdge, bool tClampToEdge);
//Loads nearly any TEXTURE format from cross cube maps, into a GLuint texture array
RX_API bool LoadCrossCubeMapTexture(const char* fileName, GLuint texArray[], GLuint texID, bool mipmaps,
GLuint &width, GLuint &height,
GLuint HDRIFormat = GL_RGBA16F_ARB);
//Loads nearly any TEXTURE format, into a single GLuint (loads from lump)
RX_API bool LoadTextureFromLump(GLvoid* lump, GLuint texArray[], GLuint texID, bool Mipmaps, GLuint size_l,
GLuint &width, GLuint &height, bool sClampToEdge, bool tClampToEdge);
//Loads nearly any TEXTURE format, into a single GLuint
RX_API bool LoadTexture(const char* fileName, GLuint texture, bool Mipmaps, GLuint &width, GLuint &height,
bool sClampToEdge, bool tClampToEdge);
//Loads nearly any TEXTURE format from cross cube maps, into a single GLuint
RX_API bool LoadCrossCubeMapTexture(const char* fileName, GLuint texture, bool mipmaps, GLuint &width, GLuint &height,
GLuint HDRIFormat = GL_RGBA16F_ARB);
//Loads nearly any TEXTURE format, into a single GLuint (loads from lump)
RX_API bool LoadCrossCubeMapTextureFromLump(GLvoid* lump, GLuint texture, bool mipmaps, GLuint size_l,
GLuint &width, GLuint &height,
GLuint HDRIFormat = GL_RGBA16F_ARB);
//Loads nearly any TEXTURE format, into a GLuint texture array (loads from lump)
RX_API bool LoadCrossCubeMapTextureFromLump(GLvoid* lump, GLuint texArray[], GLuint texID, bool mipmaps,
GLuint size_l,
GLuint &width, GLuint &height,
GLuint HDRIFormat = GL_RGBA16F_ARB);
//Loads nearly any TEXTURE format, into a single GLuint (loads from lump)
RX_API bool LoadTextureFromLump(GLvoid* lump, GLuint texture, bool mipmaps, GLuint size_l,
GLuint &width, GLuint &height,
GLuint HDRIFormat = GL_RGBA16F_ARB,
bool sClampToEdge = true, bool tClampToEdge = true);
//Loads a 1 dimensional texture, Loads nearly any TEXTURE format
RX_API bool LoadTexture1D(const char* fileName, GLuint texArray[], GLuint texID, bool Mipmaps, GLuint &width,
bool sClampToEdge);
//Loads a 1 dimensional texture, Loads nearly any TEXTURE format (loads from lump)
RX_API bool LoadTexture1DFromLump(GLvoid* lump, GLuint texArray[], GLuint texID, bool Mipmaps,
GLuint size_l, GLuint &width, bool sClampToEdge);
//Loads a texture and excludes the given R,G,B colour pixels (colour key) Loads nearly any TEXTURE format
RX_API bool LoadTextureKey(const char* fileName, GLuint texArray[], GLuint texID, bool Mipmaps,
GLubyte r, GLubyte g, GLubyte b, GLuint &width, GLuint &height);
//Loads a single texture, dont use this, has bugs
RX_API bool LoadTextureSingle(const char* fileName, GLuint* id, bool Mipmaps);
//Sets the current used texture to the specified texture
RX_API void setTexture(unsigned int tex);
//Sets the current used texture to the specified texture, used for multitexturing, SPecify texture unit, 4 MAX
RX_API void setMultiTexture(unsigned int tex, unsigned int texUNIT); //DEPRECATED DON'T EVER EVER USE
//Frees all textures in g_Textures, doesn't free all textures used in engine
RX_API void FreeTextures();
//Delete a texture referenced by a GLuint
RX_API void DeleteTexture(GLTexture &texture);
//Generate a single ilut image
RX_API ILuint GenerateSingleImage(void);
// Delete the image name. of ilut
RX_API void DeleteSingleImage(ILuint ImageName);
/*===========DONT BOTHER ABOUT THE BELOW FUNCTIONS, DONT USE THEM EITHER==========*/
//Dont bother about the below two functions, they are internal to the framework
RX_API bool LoadTextureForSkyBox(const char* fileName, GLuint texArray[], GLuint texID, bool Mipmaps);
//Loads JPG texture only, into a GLuint texture array
//RX_API bool LoadTextureJPG(const char* fileName, GLuint texArray[], GLuint texID, bool Mipmaps, float reduce);
//Loads a texture and excludes the given R,G,B colour pixels (colour key) JPG ONLY
//RX_API bool LoadTextureJPGKey(const char* fileName, GLuint texArray[], GLuint texID, bool Mipmaps, float reduce, GLubyte r, GLubyte g, GLubyte b);
/*===========END OF DONT BOTHER==========*/
/* Font texture */
//#define FONT_TEXTURE 0
/* SkyBox defines, used by class Skybox */
/*
#define FRONT 1
#define BACK 2
#define TOP 3
#define BOTTOM 4
#define LEFT 5
#define RIGHT 6
*/
enum ENUM_BASE_TEXTURE_SET_ENUMERATION
{
FONT_TEXTURE,
FRONT,
BACK,
TOP,
BOTTOM,
LEFT,
RIGHT
};
/*
==========================================================
class Texture1D
==========================================================
*/
/*! \class Texture1D
\brief Handles single dimensional textures.
\author Rajesh Peter Douglas D'Monte
Use this class if you would like to load and texture map
and objects with single dimensional textures.
*/
class RX_API Texture1D
{
public:
Texture1D();//!< Constructor, this constructor sets the texture type to GL_TEXTURE_1D automatically
~Texture1D();//!< Destructor, doesn't do anything, Instead call Free() method.
/*!<
This is for memory security reasons. In case external data relied on this class and
the deconstructor was called, then the program will crash. So the user is expected
to free objects manually.
@see Free()
*/
GLuint getTextureUnit(void);//!< Returns the current texture unit the texture object is using
/*!<
Retrieves the current texture unit the texture object is using
@return A \a GLuint that represents the texture unit the current texture object is bound to.
*/
void bindTextureToTextureUnit(GLuint unit);//!< Binds the texture to texture unit 'GLuint unit'
void bindTexture(void);
//!< Set this texture to render onwards on geometry (uses texture the last active texture unit)
bool saveImageToDisk(const char* oFileName, int mipLevel = 0, GLuint face = 0); //!< Saves the texture to disk
/*!<
Use this method to save your texture onto disk.
\param oFileName The path on disk to which the texture is to be saved.
\param mipLevel For specifying the mipmap level to be saved.
\param face This parameter is ignored for Texture1D and Texture2D.
\a face is to be used with TextureCube only. \a Range [1, 6].
@return true if the function succeeds
*/
inline GLuint getTextureType(void);//!< Returns the texture type. For Texture1D, it will return \a GL_TEXTURE_1D
inline GLuint getTexture(void);//!< Returns the texture object, a GLuint
inline GLuint* getPointerToTexture(void);//!< Returns the pointer to the texture object, a GLuint
void operator=(Texture1D &pCTexture);
//!< This doesn't copy the contents of the given texture. It just assigns the same texture ID.
virtual bool LoadTextureImage(const char* textureFileName, bool mipmaps = false,
bool sClampToEdge = true,
bool tClampToEdge = true /*this parameter is ignored if texture is 1D*/);
//!< Loads a texture from disk.
/*!<
\param textureFileName The texture path on disk.
\param mipmaps Specifies if the texture is mipmapped or not.
\param sClampToEdge Specifies if the texture is s clamped or not.
\param tClampToEdge Specifies if the texture is t clamped or not. Ignored for Texture1D.
@return true if the function succeeds
*/
virtual void SetTextureClamping(bool sClampToEdge = true, bool tClampToEdge = true);
//!< Sets the texture clamping
/*!<
\param sClampToEdge Specifies if the texture is s clamped or not.
\param tClampToEdge Specifies if the texture is t clamped or not. Ignored for Texture1D.
@return true if the function succeeds
*/
virtual bool LoadTextureImageFromLump(GLvoid* lump, GLuint size, bool mipmaps = false,
bool sClampToEdge = true,
bool tClampToEdge = true /*this parameter is ignored*/);
//!< Loads a texture from a data lump.
/*!<
\param lump Pointer to data lump.
\param size The size of the lump. If you want no bounds checking, specify 0.
\param mipmaps Specifies if the texture is mipmapped or not.
\param sClampToEdge Specifies if the texture is s clamped or not.
\param tClampToEdge Specifies if the texture is t clamped or not. Ignored for Texture1D.
@return true if the function succeeds
*/
virtual bool LoadTextureImage_MipMaps(const char* textureFileName);
//!< Deprecated. Use LoadTextureImage() or LoadTextureImageFromLump() instead
/*!<
\deprecated
@see LoadTextureImage()
@see LoadTextureImageFromLump()
*/
virtual bool CreateEmptyTexture(int width, int height, int internalFormat/*Can be channels*/,
int format, bool mipMapExt, int type = GL_UNSIGNED_BYTE,
int minFilter = GL_NEAREST, int magFilter = GL_NEAREST,
bool sClampToEdge = true, bool tClampToEdge = true);
//!< Creates an empty texture
/*!<
\param width The texture width
\param height The texture height. Ignored in Texture1D.
\param internalFormat The internal format of the texture. Can be number of channels. \a Range [0, 4].
\param format The texture format. Eg: \a GL_RGB, \a GL_RGBA.
\param mipMapExt Specifies if the texture is to be mipmapped or not.
\param type The texture format type. Eg: \a GL_UNSIGNED_BYE, \a GL_INT.
@return true if the function succeeds
*/
virtual void RenderCurrentViewportToTexture(void);
//!< Renders the current viewport to this texture object. Doesn't work for floating point textures.
virtual void Free(void);
//!< Frees the texture object and prints the path name, if the texture had a path name.
void ReleaseTextureOnly(void); //!< Deprecated. Frees the texture object and doesn't print the path name,
/*!<
\deprecated
@see Free()
*/
GLuint getWidth(void) const; //!< Returns the width of the texture
const char* getFileName(void) const; //!< Returns the file name of the texture
protected:
GLuint mTextureUnit;
GLuint mTextureType;
GLuint mTexture;
char fileName[256];
GLuint mWidth;
GLuint mFileLoadMode;
Texture1D(GLuint type);
};
/*
==========================================================
class Texture2D inherits from Texture1D
==========================================================
*/
/*! \class Texture2D
\brief Class for handling 2 dimensional textures.
\author Rajesh Peter Douglas D'Monte
Use this class if you would like to load and texture map
and objects with 2 dimensional textures.
*/
class RX_API Texture2D: public Texture1D
{
public:
Texture2D();//!< Constructor
~Texture2D();//!< Destructor. Does Nothing. Call Free() instead.
/*!<
This is for memory security reasons. In case external data relied on this class and
the deconstructor was called, then the program will crash. So the user is expected
to free objects manually.
@see Free()
*/
virtual bool LoadTextureImage(const char* textureFileName, bool mipmaps = false,
bool sClampToEdge = true, bool tClampToEdge = true);
virtual bool LoadTextureImageFromLump(GLvoid* lump, GLuint size, bool mipmaps = false,
bool sClampToEdge = true, bool tClampToEdge = true);
void SetBorderColor(float r = 0.6f, float g = 0.6f, float b = 0.6f, float a = 1.0f);
virtual bool CreateEmptyTexture(int width, int height, int internalFormat/*Can be channels*/,
int format, bool mipMapExt, int type = GL_UNSIGNED_BYTE,
int minFilter = GL_NEAREST, int magFilter = GL_NEAREST,
bool sClampToEdge = true, bool tClampToEdge = true,
int border = 0); //Format can be GL_RGB, GL_DEPTH_COMPONENT etc
virtual void RenderCurrentViewportToTexture(void);
virtual void SetTextureClamping(bool sClampToEdge = true, bool tClampToEdge = true);
//!< Sets the texture clamping
/*!<
\param sClampToEdge Specifies if the texture is s clamped or not.
\param tClampToEdge Specifies if the texture is t clamped or not. Ignored for Texture1D.
@return true if the function succeeds
*/
/*
Method Name: LoadTextureImage_MipMaps
IMPORTANT: This function is deprecated! use LoadTextureImage instead.
For backward compatibility reasons, this method is retained
*/
virtual bool LoadTextureImage_MipMaps(const char* textureFileName);
virtual void Free(void);
GLuint getHeight(void) const; //!< Returns the height of the texture
protected:
GLuint mHeight;
};
/*
==================================================================================================================
class Texture3D inherits from Texture1D
WARNING: USEABLE FUNCTIONS ARE, Free, PrepareJitterMap, other functions are NOT to be used with 3D textures
==================================================================================================================
*/
/*! \class Texture3D
\brief Class for handling 3 dimensional textures.
\author Rajesh Peter Douglas D'Monte
Use this class if you would like to prepare 3D jittermap textures.
\bug None of the inherited functions work except for Free(). This class is to be used exclusively for
preparing jitter maps alone.
*/
class RX_API Texture3D: public Texture1D
{
public:
Texture3D();//!< Constructor
~Texture3D();//!< Destructor. Does Nothing. Call Free() instead.
/*!<
This is for memory security reasons. In case external data relied on this class and
the deconstructor was called, then the program will crash. So the user is expected
to free objects manually.
@see Free()
*/
bool PrepareJitterMap(GLint size, GLint samples_u, GLint samples_v); //!< Prepares a jitter map as a 3D texture
/*!<
Prepares a jitter map as a 3D texture.
\param size The resolution of the 3D texture. Eg: \a 16
\param samples_u The number of u samples. Eg: \a 4
\param samples_v The number of v samples. Eg: \a 8
@return true if the function succeeds
*/
virtual void Free(void);
protected:
GLuint mHeight, mDepth;
};
/*
class TextureCube inherits from Texture1D, doesn't load cube map 2D textures... see
class CSkyBox for skyboxes and cube map images
*/
/*! \class TextureCube
\brief Class for handling cubemap textures.
\author Rajesh Peter Douglas D'Monte
Use this class if you would like to load and texture map
and objects with cube map textures.
*/
class RX_API TextureCube: public Texture1D
{
public:
TextureCube();//!< Constructor
~TextureCube();//!< Destructor. Does Nothing. Call Free() instead.
/*!<
This is for memory security reasons. In case external data relied on this class and
the deconstructor was called, then the program will crash. So the user is expected
to free objects manually.
@see Free()
*/
virtual bool LoadTextureImage(const char* textureFileName, bool mipmaps = false, GLuint HDRIFormat = GL_RGBA16F_ARB);
//!< Loads only from CROSS CUBE MAP IMAGE
/*!<
The method definition is different from that of Texture1D
\param textureFileName The file path to load from.
\param mipmaps Specifies whether the texture is to be mipmapped or not.
\param HDRIFormat Specifies the texture format.
@return true if the function succeeds
*/
virtual bool LoadTextureImageFromLumpCube(GLvoid* lump, GLuint size, bool mipmaps = false,
GLuint HDRIFormat = GL_RGBA16F_ARB);
//!< Loads a cube map texture from lump data.
/*!<
Loads a cube map texture from lump data
\param lump Pointer to data lump.
\param size The size of the lump. If you want no bounds checking, specify 0.
\param mipmaps Specifies if the texture is mipmapped or not.
\param HDRIFormat Specifies the texture format.
@return true if the function succeeds
*/
virtual bool CreateEmptyTexture(int width, int height, int internalFormat/*Can be channels*/,
int format, bool mipMapExt, int type = GL_UNSIGNED_BYTE,
int minFilter = GL_NEAREST, int magFilter = GL_NEAREST,
bool sClampToEdge = true, bool tClampToEdge = true,
int border = 0); //Format can be GL_RGB, GL_DEPTH_COMPONENT etc
virtual void RenderCurrentViewportToTexture(int cubeFace);
bool GenerateNormalizationCubeMap(GLuint size);//!< Generates a normalization cubemap.
/*!<
This method is used to generate a normalization cubemap
\param size Specifies the resolution of the normalization cube map. Has to be a perfect square and
a power of two. Eg: \a 256, \a 128, \a 512 etc
@return true if the function succeeds
*/
virtual void Free(void);
protected:
GLuint mHeight;
};
/*
========================================================================================
General TARGET Texture class (GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_NV ONLY)
========================================================================================
*/
/*! \class TextureMutable
\brief Class for handling 2D textures.
\author Rajesh Peter Douglas D'Monte
Use this class if you would like to load and texture map
and objects with 2D textures. It differs from Texture2D by giving the user
the ability to change the texture object type to \a GL_TEXTURE_RECTANGLE_NV
*/
class RX_API TextureMutable: public Texture2D
{
public:
TextureMutable();//!< Constructor
~TextureMutable();//!< Destructor. Does Nothing. Call Free() instead.
/*!<
This is for memory security reasons. In case external data relied on this class and
the deconstructor was called, then the program will crash. So the user is expected
to free objects manually.
@see Free()
*/
/* target can be GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_NV */
void setTarget(GLenum target); //!< MUST BE CALLED BEFORE you can use an instance of this class.
/*!<
MUST BE CALLED BEFORE you can use an instance of this class
\param target Specifies the texture object target. Can be \a GL_TEXTURE_2D or \a GL_TEXTURE_RECTANGLE_NV.
*/
virtual void Free(void);
};
}
#endif