DI-Guy SDK Documentation  13.1
diguyGraphicsTexture.h
Go to the documentation of this file.
1 
2 /*********************************************************************
3  ** Copyright (c) 1992-2015 VT MAK
4  ** All rights reserved.
5  *********************************************************************/
6 
7 /*********************************************************************/
14 #ifndef __diguyGraphicsTexture_H
15 #define __diguyGraphicsTexture_H
16 
17 #ifdef SWIG
19 #else
20 #define CPLUSPLUS_ONLY
21 #endif
22 
23 #ifdef CPLUSPLUS_ONLY
24 #include <declspec_diguy.h>
25 #include <diguy_constants.h>
26 
27 class bdiGeometryTextureFile;
29 
30 
31 #endif
32 
33 /****************************************************************************/
34 /*l
35  *b Description:
36  **
37  ** This enumeration lists the types of compression that texture map data
38  ** may have.
39  **
40  */
41 typedef enum
42 {
51 
52 
53 /****************************************************************************/
54 /*l
55  *b Description:
56  **
57  ** This enumeration lists the type of texture map a given image file is
58  ** being used as.
59  **
60  */
61 typedef enum
62 {
74 
75 
76 /****************************************************************************/
77 /*l
78  *b Description:
79  **
80  ** This enumeration lists how the state stores the available textures in
81  ** the textures_available bitfield. Also used by the shader programs.
82  **
83  */
84 typedef enum
85 {
87  DIGUY_TEXTURE_MAP_MASK_SHADOW = 0x00000002,
89  DIGUY_TEXTURE_MAP_MASK_BUMP = 0x00000008,
91  DIGUY_TEXTURE_MAP_MASK_MISC_1 = 0x00000020,
92  DIGUY_TEXTURE_MAP_MASK_MISC_2 = 0x00000040,
93  DIGUY_TEXTURES_MAP_MASK_ALL = 0xffffffff
95 
96 /*l
97  *b Description:
98  **
99  ** This function converts the passed texture type enumeration into
100  ** a NULL-terminated C-style string.
101  **
102  *b Returns:
103  **
104  ** C-style string identifying texture map type
105  **
106  *b Callable From:
107  **
108  *- - C++
109  *- - Script
110  */
111 
112 BDI_DECLSPEC_bdiutil const char* diguy_texture_type_to_string(diguyTextureMapType texture_type);
113 
114 /*l
115  *b Description:
116  **
117  ** This function converts the passed C-style string into an
118  ** enumerated value.
119  **
120  *b Returns:
121  **
122  ** enumeration value of string
123  **
124  *b Callable From:
125  **
126  *- - C++
127  *- - Script
128  */
129 
130 BDI_DECLSPEC_bdiutil diguyTextureMapType diguy_texture_type_from_string(const char* string);
131 
132 /****************************************************************************/
133 class BDI_DECLSPEC_diguy diguyGraphicsTexture
134 {
135 
136 public:
137 
138 /*****************************************************************************/
151  /*l
152  *b Description:
153  **
154  ** Returns the name of the texture. This pointer will
155  ** never be NULL.
156  **
157  *b Returns:
158  **
159  ** name of the texture
160  */
161  const char* get_name();
162 
163  /*l
164  *b Description:
165  **
166  ** This function returns the filename of the texture. This pointer
167  ** may be NULL if the texture does not have an associated filename.
168  **
169  *b Returns:
170  **
171  ** filename of the texture
172  */
173  const char* get_filename();
174 
175  /*l
176  *b Returns:
177  **
178  ** the width of the texture, in pixels; -1 on failure
179  */
180  int get_width();
181 
182  /*l
183  *b Returns:
184  **
185  ** the height of the texture, in pixels; -1 on failure
186  */
187  int get_height();
188 
189  /*l
190  *b Description:
191  **
192  ** This function returns how many components the texture has. The
193  ** number of components will be an integer between 1 and 4.
194  **
195  ** Most textures have three components, red (R), green (G), and
196  ** blue (B), or RGB. These textures commonly have filenames with
197  ** the extension .rgb.
198  **
199  ** Four component textures add an alpha (A) channel, resulting in
200  ** RGBA. These textures commonly have filenames with the extension
201  ** .rgba.
202  **
203  ** One component textures have only an intensity (I). These textures
204  ** commonly have filenames with the extension .int.
205  **
206  ** Two component textures have only an intensity (I), and an alpha
207  ** channel. These textures commonly have filenames with the
208  ** extension .inta.
209  **
210  *b Returns:
211  **
212  ** number of components in texture; -1 on failure
213  */
214  int get_num_components();
215 
216  /*l
217  *b Description:
218  **
219  ** This function returns whether the texture contains an alpha
220  ** component. Textures that have an alpha component can make
221  ** objects semi-transparent, which can affect when said objects
222  ** should be drawn.
223  **
224  *b Returns:
225  **
226  ** 1 if texture contains an alpha component, 0 if not; -1 on failure
227  */
228  int get_contains_alpha_component();
229 
230 #ifdef CPLUSPLUS_ONLY
231 
232  /*l
233  *b Description:
234  **
235  ** This function returns a memory buffer with the actual texture
236  ** data.
237  **
238  ** The size of buffer can be obtained by calling
239  ** get_texture_map_data_size().
240  **
241  ** The texture information is packed into the buffer row by row,
242  ** in the following order:
243  **
244  *- - I (intensity) for one component textures
245  *- - IA (intensity and alpha) for two component textures
246  *- - RGB (red, blue, green) for three component textures
247  *- - RGBA (red, blue, green, alpha) for four component textures
248  **
249  ** There is one byte per component.
250  **
251  ** This function should not be called after free_loader_memory()
252  ** has been called.
253  **
254  ** Note that some renderers expect to take ownership of the texture
255  ** data that is passed to them. In this case, a copy of this texture
256  ** data must be made to avoid a double deletion of the memory. This
257  ** texture data will be deleted by the call to free_loader_memory(),
258  ** or when this object is deleted.
259  **
260  *b Returns:
261  **
262  ** pointer to texture map data
263  **
264  ** NOTE: The returned pointer may be NULL, if there was some problem
265  ** loading the texture file.
266  **
267  *b Callable From:
268  **
269  *- - C++
270  */
271  unsigned char* get_texture_map_data();
272 
273 #endif
274 
275  /*l
276  *b Description:
277  **
278  ** This function returns how many bytes are used by the texture
279  ** map data buffer.
280  **
281  *b Returns:
282  **
283  ** buffer size of texture map data, in bytes; may be 0 in the
284  ** case of a NULL texture
285  */
286  int get_texture_map_data_size();
287 
288  /*l
289  *b Description:
290  **
291  ** This function returns which compression method, if any, is
292  ** applied to the data returned bu get_texture_map_data().
293  **
294  ** Most often compressed textures come from .dds (DirectDraw Surface)
295  ** files.
296  **
297  *b Returns:
298  **
299  ** compression type enumeration
300  */
301  diguyGraphicsTextureCompressionType get_texture_compression_type();
302 
303  /*l
304  *b Description:
305  **
306  ** This function returns how many mipmaps are already included in
307  ** the texture map data.
308  **
309  ** Typically only .dds (DirectDraw Surface) textures have precomputed
310  ** mipmaps in them.
311  **
312  ** Note that values 0 and 1 are somewhat the same: there is only
313  ** one image in the texture map data: the base, unscaled image.
314  **
315  *b Returns:
316  **
317  ** num of included mipmaps
318  */
319  int get_num_included_mipmaps();
320 
321  /*l
322  *b Description:
323  **
324  ** This function returns the size of the data, in bytes, of the
325  ** specified mipmap.
326  **
327  ** "mipmap" 0 is the base, unscaled image, mipmap 1 is the first
328  ** scaled image, etc.
329  **
330  *b Returns:
331  **
332  ** data size, in bytes, of mipmap; -1 on error
333  */
334  int get_mipmap_data_size(int mipmap);
335 
336  /*l
337  *b Description:
338  **
339  ** This function returns the data offset of the specified mipmap
340  ** into the data pointer returned by get_texture_map_data().
341  **
342  ** "mipmap" 0 is the base, unscaled image, mipmap 1 is the first
343  ** scaled image, etc.
344  **
345  *b Returns:
346  **
347  ** data offset, in bytes, of mipmap; -1 on error
348  */
349  int get_mipmap_data_offset(int mipmap);
350 
351  /*l
352  *b Description:
353  **
354  ** This function returns the OpenGL pixel format enumeration of this
355  ** texture.
356  **
357  ** This enumeration will be one of the following:
358  **
359  *- - GL_LUMINANCE
360  *- - GL_LUMINANCE_ALPHA
361  *- - GL_RGB
362  *- - GL_RGBA
363  *- - GL_COMPRESSED_RGB_S3TC_DXT1_EXT
364  *- - GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
365  *- - GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
366  .* - GL_COMPRESSED_RGB_ALPHA_S3TC_DXT1_EXT
367  .* - GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
368  **
369  *b Returns:
370  **
371  ** OpenGL pixel format enum; -1 on error
372  **
373  ** In OpenGL and OSG environments, the returned value should be cast
374  ** into a GLenum.
375  */
376  int get_gl_format();
377 
378  /*l
379  *b Description:
380  **
381  ** This function returns the OpenGL pixel format string of this
382  ** texture. There are a large number of potential results depending
383  ** if compressed textures and/or sRGB textures are enabled.
384  **
385  ** Example of possible results:
386  **
387  *- - GL_RGB GL_RGBA
388  *- - sRGB: GL_SRGB GL_SRGB_ALPHA
389  *- - Compressed: GL_COMPRESSED_RGB_S3TC_DXT1 GL_COMPRESSED_RGBA_S3TC_DXT5
390  *- - sRGB + Compressed: GL_COMPRESSED_RGB_ALPHA_S3TC_DXT1 GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5
391  */
392  const char* get_gl_format_as_string();
393 
394  /*l
395  *b Description:
396  **
397  ** This function returns the "block size" of the dds compression
398  ** types. This value can be useful in generating mipmap data offsets.
399  **
400  ** Alternatively, the function get_mipmap_data_offset() can be called
401  ** to get the precomputed mipmap data offsets.
402  **
403  ** Currently this value will be either 8 (for DXT1 compression) or 16
404  ** (for DXT3 and DXT5 compression).
405  **
406  *b Returns:
407  **
408  ** block size, in bytes
409  */
410  int get_dds_block_size();
411 
412  /*l
413  *b Description:
414  **
415  ** For texture indices less than zero and greater than one, a decision
416  ** must be made as to whether the texture is repeated or whether the
417  ** edge pixels are replicated to fill the space.
418  **
419  ** This function returns whether the texture should be repeated
420  ** horizontally (don't clamp) or whether the edge column of pixels
421  ** should be used (do clamp).
422  **
423  ** Note that in MultiGen Creator attribute (.attr) files, this
424  ** corresponds to the "Wrap Method u" attribute.
425  **
426  *b Returns:
427  **
428  ** 0 is texture should be tiled, 1 if not; -1 on failure
429  */
430  int get_clamp_s();
431 
432  /*l
433  *b Description:
434  **
435  ** For texture indices less than zero and greater than one, a
436  ** decision must be made as to whether the texture is repeated
437  ** or whether the edge pixels are replicated to fill the space.
438  **
439  ** This function returns whether the texture should be repeated
440  ** vertically (don't clamp) or whether the edge row of pixels
441  ** should be used (do clamp).
442  **
443  ** Note that in MultiGen Creator attribute (.attr) files, this
444  ** corresponds to the "Wrap Method v" attribute.
445  **
446  *b Returns:
447  **
448  ** 0 is texture should be repeated, 1 if not; -1 on failure
449  */
450  int get_clamp_t();
451 
452  /*l
453  *b Description:
454  **
455  ** This function frees most memory allocated by the DI-Guy geometry
456  ** loader for this object.
457  **
458  ** This function should only be called during or after the object's
459  ** build() function has been called. After it has been called, calls
460  ** to many accessor functions will fail.
461  */
462  void free_loader_memory();
463 
464 
465 /*****************************************************************************/
477 #ifdef CPLUSPLUS_ONLY
478 
479  /*l
480  *b Description:
481  **
482  ** This function will be called by DI-Guy when it is time for a
483  ** renderer-specific texture object to be created. At that point
484  ** the texture information has been read from the texture file,
485  ** and is available via the Accessor Functions above.
486  **
487  *i Immediate Mode:
488  **
489  ** Immediate mode renderers may override this function, to
490  ** create an object that may be invoked by bind_now().
491  **
492  *i Scene Graph:
493  **
494  ** Scene graph renderers usually do override this function, to
495  ** create an object that gets associated with diguyGraphicsMesh
496  ** objects.
497  **
498  *b Callable From:
499  **
500  *- - N/A (automatically called by DI-Guy Graphics API during
501  *- the Build Stage)
502  */
503  virtual void build();
504 
505  /*l
506  *b Description:
507  **
508  ** This function will be called by DI-Guy when it is time for a
509  ** renderer-specific texture object to be destroyed.
510  **
511  *i Immediate Mode:
512  **
513  ** Immediate mode renderers may override this function, to
514  ** destroy any object that may have been created by build().
515  **
516  *i Scene Graph:
517  **
518  ** Scene graph renderers usually do override this function, to
519  ** destroy any object that may have been created by build().
520  **
521  *b Callable From:
522  **
523  *- - N/A (automatically called by DI-Guy Graphics API during
524  *- the Unbuild Stage)
525  */
526  virtual void unbuild();
527 
528  /*l
529  *b Description:
530  **
531  ** This function will be called by DI-Guy when the texture should
532  ** be made active, or bound.
533  **
534  *i Immediate Mode:
535  **
536  ** Immediate mode renderers usually do override this function, to
537  ** invoke the object created by build(), or make calls to the
538  ** renderer to set appropriate texture state.
539  **
540  *i Scene Graph:
541  **
542  ** Scene graph renderers usually do not override this function.
543  **
544  *b Callable From:
545  **
546  *- - N/A (automatically called by DI-Guy Graphics API during
547  *- Draw Stage)
548  */
549  virtual void bind_now(diguyTextureMapType texture_type);
550 
551  /*l
552  *b Description:
553  **
554  ** This function returns the last bound texture used by DI-Guy. This
555  ** value can be used in diguyGraphicsTexture::bind() to check to see
556  ** if a texture rebind is necessary; avoiding a texture rebind can
557  ** avoid a significant performance hit in some rendering systems.
558  **
559  *b Callable From:
560  **
561  *- - C++
562  */
563  static diguyGraphicsTexture* get_last_bound_texture(int texture_unit = 0);
564 
565  /*l
566  *b Description:
567  **
568  ** This function clears out the last bound texture variable.
569  ** diguyScenario::draw() automatically calls it, but it is also
570  ** recommended that it be called before drawing individual
571  ** diguyCharacters in case something outside of DI-Guy has changed
572  ** the texture.
573  **
574  *b Callable From:
575  **
576  *- - C++
577  */
578  static void clear_last_bound_texture();
579 
580 #endif
581 
582 
583 /****************************************************************************/
584 /****************************************************************************/
585 
590 #ifdef CPLUSPLUS_ONLY
592  bdiGeometryTextureFile* get_scripted_object() {return m_scripted_object;}
593 
594 protected:
595 
596  /*l
597  ** A protected constructor. Constructors are called automatically
598  ** by DI-Guy.
599  */
600  diguyGraphicsTexture(void* internal_data);
601 
602  /*l
603  ** A protected destructor. Destructors are called automatically
604  ** by DI-Guy.
605  */
606  virtual ~diguyGraphicsTexture();
607 
608 private:
609 
610  /*l
611  ** A pointer to internal data.
612  */
613  bdiGeometryTextureFile* m_scripted_object;
614 
615  friend class bdiGeometryTextureFile;
616  friend class bdiGeometryFactory;
617 
618 #endif
619 
620 };
621 
622 
623 #endif /* __diguyGraphicsTexture_H */
624 
const char * diguy_texture_type_to_string(diguyTextureMapType texture_type)
This function converts the passed texture type enumeration into a NULL-terminated C-style string...
Definition: diguyGraphicsTexture.h:64
Definition: diguyGraphicsTexture.h:59
diguyGraphicsTextureCompressionType
This enumeration lists the types of compression that texture map data may have.
Definition: diguyGraphicsTexture.h:38
Definition: diguyGraphicsTexture.h:60
Definition: diguyGraphicsTexture.h:83
Definition: diguyGraphicsTexture.h:84
Definition: diguyGraphicsTexture.h:41
Definition: diguyGraphicsTexture.h:58
Definition: diguyGraphicsTexture.h:61
Definition: diguyGraphicsTexture.h:81
Definition: diguyGraphicsTexture.h:62
Definition: diguyGraphicsTexture.h:40
Definition: diguyGraphicsTexture.h:67
Definition: diguyGraphicsTexture.h:63
Definition: diguyGraphicsTexture.h:45
Definition: diguyGraphicsTexture.h:42
diguyTextureMapMasks
This enumeration lists how the state stores the available textures in the textures_available bitfield...
Definition: diguyGraphicsTexture.h:77
A class that represents a shared texture. Can be subclassed by filling out the diguy_graphics_set_tex...
Definition: diguyGraphicsTexture.h:124
Definition: diguyGraphicsTexture.h:85
Definition: diguyGraphicsTexture.h:46
Definition: diguyGraphicsTexture.h:86
Definition: diguyGraphicsTexture.h:65
Definition: diguyGraphicsTexture.h:44
Definition: diguyGraphicsTexture.h:66
diguyTextureMapType
This enumeration lists the type of texture map a given image file is being used as.
Definition: diguyGraphicsTexture.h:56
Definition: diguyGraphicsTexture.h:82
Definition: diguyGraphicsTexture.h:79
Definition: diguyGraphicsTexture.h:43
diguyTextureMapType diguy_texture_type_from_string(const char *string)
This function converts the passed C-style string into an enumerated value.
Definition: diguyGraphicsTexture.h:80