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