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