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