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