C++ SDK Reference  12.5
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
diguyGraphicsTexture.h
Go to the documentation of this file.
1 
2 /*
3  * Copyright (C) 1992-2013 Boston Dynamics
4  * ALL RIGHTS RESERVED.
5  *
6  * These coded instructions, statements, and computer programs
7  * contain unpublished proprietary information of Boston Dynamics
8  * and are protected by Copyright Laws of the United States.
9  * They may not be used, duplicated, or disclosed in any form, in
10  * whole or in part, without the prior written consent from Boston
11  * Dynamics.
12  *
13  * RESTRICTED RIGHTS LEGEND
14  * Use, duplication, or disclosure by the government is subject
15  * to restrictions as set forth in FAR 52.227.19(c)(2) or
16  * subparagraph (c)(1)(ii) of the Rights in Technical Data and
17  * Computer Software clause at DFARS 252.227-7013 and/or in
18  * similar or successor clauses in the FAR, or the DOD or NASA
19  * FAR Supplement, or to subparagraphs (c)(1) and (c)(2) of the
20  * Commercial Computer Software--Restricted Rights at 48 CFR
21  * 52.227-19, as applicable. Unpublished-rights reserved under
22  * the Copyright Laws of the United States.
23  * Contractor/Manufacturer is:
24  * Boston Dynamics/78 Fourth Avenue/Waltham MA 02451.
25  */
26 
27 /*********************************************************************/
34 #ifndef __diguyGraphicsTexture_H
35 #define __diguyGraphicsTexture_H
36 
37 #ifdef SWIG
39 #else
40 #define CPLUSPLUS_ONLY
41 #endif
42 
43 #ifdef CPLUSPLUS_ONLY
44 #include <declspec_diguy.h>
45 #include <diguy_constants.h>
46 
47 class bdiGeometryTextureFile;
49 
50 
51 #endif
52 
53 /****************************************************************************/
54 /*l
55  *b Description:
56  **
57  ** This enumeration lists the types of compression that texture map data
58  ** may have.
59  **
60  */
61 typedef enum
62 {
71 
72 
73 /****************************************************************************/
74 /*l
75  *b Description:
76  **
77  ** This enumeration lists the type of texture map a given image file is
78  ** being used as.
79  **
80  */
81 typedef enum
82 {
93 
94 
95 /****************************************************************************/
96 /*l
97  *b Description:
98  **
99  ** This enumeration lists how the state stores the available textures in
100  ** the textures_available bitfield. Also used by the shader programs.
101  **
102  */
103 typedef enum
104 {
106  DIGUY_TEXTURE_MAP_MASK_SHADOW = 0x00000002,
107  DIGUY_TEXTURE_MAP_MASK_SPECULAR = 0x00000004,
108  DIGUY_TEXTURE_MAP_MASK_BUMP = 0x00000008,
110  DIGUY_TEXTURE_MAP_MASK_MISC_1 = 0x00000020,
111  DIGUY_TEXTURE_MAP_MASK_MISC_2 = 0x00000040,
112  DIGUY_TEXTURES_MAP_MASK_ALL = 0xffffffff
114 
115 /*l
116  *b Description:
117  **
118  ** This function converts the passed texture type enumeration into
119  ** a NULL-terminated C-style string.
120  **
121  *b Returns:
122  **
123  ** C-style string identifying texture map type
124  **
125  *b Callable From:
126  **
127  *- - C++
128  *- - Script
129  */
130 
131 BDI_DECLSPEC_bdiutil const char* diguy_texture_type_to_string(diguyTextureMapType texture_type);
132 
133 /*l
134  *b Description:
135  **
136  ** This function converts the passed C-style string into an
137  ** enumerated value.
138  **
139  *b Returns:
140  **
141  ** enumeration value of string
142  **
143  *b Callable From:
144  **
145  *- - C++
146  *- - Script
147  */
148 
149 BDI_DECLSPEC_bdiutil diguyTextureMapType diguy_texture_type_from_string(const char* string);
150 
151 /****************************************************************************/
152 class BDI_DECLSPEC_diguy diguyGraphicsTexture
153 {
154 
155 public:
156 
157 /*****************************************************************************/
166  /*l
167  *b Description:
168  **
169  ** Returns the name of the texture. This pointer will
170  ** never be NULL.
171  **
172  *b Returns:
173  **
174  ** name of the texture
175  **
176  *b Callable From:
177  **
178  *- - C++
179  */
180  const char* get_name();
181 
182  /*l
183  *b Description:
184  **
185  ** This function returns the filename of the texture. This pointer
186  ** may be NULL if the texture does not have an associated filename.
187  **
188  *b Returns:
189  **
190  ** filename of the texture
191  **
192  *b Callable From:
193  **
194  *- - C++
195  */
196  const char* get_filename();
197 
198  /*l
199  *b Returns:
200  **
201  ** the width of the texture, in pixels; -1 on failure
202  **
203  *b Callable From:
204  **
205  *- - C++
206  */
207  int get_width();
208 
209  /*l
210  *b Returns:
211  **
212  ** the height of the texture, in pixels; -1 on failure
213  **
214  *b Callable From:
215  **
216  *- - C++
217  */
218  int get_height();
219 
220  /*l
221  *b Description:
222  **
223  ** This function returns how many components the texture has. The
224  ** number of components will be an integer between 1 and 4.
225  **
226  ** Most textures have three components, red (R), green (G), and
227  ** blue (B), or RGB. These textures commonly have filenames with
228  ** the extension .rgb.
229  **
230  ** Four component textures add an alpha (A) channel, resulting in
231  ** RGBA. These textures commonly have filenames with the extension
232  ** .rgba.
233  **
234  ** One component textures have only an intensity (I). These textures
235  ** commonly have filenames with the extension .int.
236  **
237  ** Two component textures have only an intensity (I), and an alpha
238  ** channel. These textures commonly have filenames with the
239  ** extension .inta.
240  **
241  *b Returns:
242  **
243  ** number of components in texture; -1 on failure
244  **
245  *b Callable From:
246  **
247  *- - C++
248  */
249  int get_num_components();
250 
251  /*l
252  *b Description:
253  **
254  ** This function returns whether the texture contains an alpha
255  ** component. Textures that have an alpha component can make
256  ** objects semi-transparent, which can affect when said objects
257  ** should be drawn.
258  **
259  *b Returns:
260  **
261  ** 1 if texture contains an alpha component, 0 if not; -1 on failure
262  **
263  *b Callable From:
264  **
265  *- - C++
266  */
267  int get_contains_alpha_component();
268 
269 #ifdef CPLUSPLUS_ONLY
270 
271  /*l
272  *b Description:
273  **
274  ** This function returns a memory buffer with the actual texture
275  ** data.
276  **
277  ** The size of buffer can be obtained by calling
278  ** get_texture_map_data_size().
279  **
280  ** The texture information is packed into the buffer row by row,
281  ** in the following order:
282  **
283  *- - I (intensity) for one component textures
284  *- - IA (intensity and alpha) for two component textures
285  *- - RGB (red, blue, green) for three component textures
286  *- - RGBA (red, blue, green, alpha) for four component textures
287  **
288  ** There is one byte per component.
289  **
290  ** This function should not be called after free_loader_memory()
291  ** has been called.
292  **
293  ** Note that some renderers expect to take ownership of the texture
294  ** data that is passed to them. In this case, a copy of this texture
295  ** data must be made to avoid a double deletion of the memory. This
296  ** texture data will be deleted by the call to free_loader_memory(),
297  ** or when this object is deleted.
298  **
299  *b Returns:
300  **
301  ** pointer to texture map data
302  **
303  ** NOTE: The returned pointer may be NULL, if there was some problem
304  ** loading the texture file.
305  **
306  *b Callable From:
307  **
308  *- - C++
309  */
310  unsigned char* get_texture_map_data();
311 
312 #endif
313 
314  /*l
315  *b Description:
316  **
317  ** This function returns how many bytes are used by the texture
318  ** map data buffer.
319  **
320  *b Returns:
321  **
322  ** buffer size of texture map data, in bytes; may be 0 in the
323  ** case of a NULL texture
324  **
325  *b Callable From:
326  **
327  *- - C++
328  */
329  int get_texture_map_data_size();
330 
331  /*l
332  *b Description:
333  **
334  ** This function returns which compression method, if any, is
335  ** applied to the data returned bu get_texture_map_data().
336  **
337  ** Most often compressed textures come from .dds (DirectDraw Surface)
338  ** files.
339  **
340  *b Returns:
341  **
342  ** compression type enumeration
343  **
344  *b Callable From:
345  **
346  *- - C++
347  */
348  diguyGraphicsTextureCompressionType get_texture_compression_type();
349 
350  /*l
351  *b Description:
352  **
353  ** This function returns how many mipmaps are already included in
354  ** the texture map data.
355  **
356  ** Typically only .dds (DirectDraw Surface) textures have precomputed
357  ** mipmaps in them.
358  **
359  ** Note that values 0 and 1 are somewhat the same: there is only
360  ** one image in the texture map data: the base, unscaled image.
361  **
362  *b Returns:
363  **
364  ** num of included mipmaps
365  **
366  *b Callable From:
367  **
368  *- - C++
369  */
370  int get_num_included_mipmaps();
371 
372  /*l
373  *b Description:
374  **
375  ** This function returns the size of the data, in bytes, of the
376  ** specified mipmap.
377  **
378  ** "mipmap" 0 is the base, unscaled image, mipmap 1 is the first
379  ** scaled image, etc.
380  **
381  *b Returns:
382  **
383  ** data size, in bytes, of mipmap; -1 on error
384  **
385  *b Callable From:
386  **
387  *- - C++
388  */
389  int get_mipmap_data_size(int mipmap);
390 
391  /*l
392  *b Description:
393  **
394  ** This function returns the data offset of the specified mipmap
395  ** into the data pointer returned by get_texture_map_data().
396  **
397  ** "mipmap" 0 is the base, unscaled image, mipmap 1 is the first
398  ** scaled image, etc.
399  **
400  *b Returns:
401  **
402  ** data offset, in bytes, of mipmap; -1 on error
403  **
404  *b Callable From:
405  **
406  *- - C++
407  */
408  int get_mipmap_data_offset(int mipmap);
409 
410  /*l
411  *b Description:
412  **
413  ** This function returns the OpenGL pixel format enumeration of this
414  ** texture.
415  **
416  ** This enumeration will be one of the following:
417  **
418  *- - GL_LUMINANCE
419  *- - GL_LUMINANCE_ALPHA
420  *- - GL_RGB
421  *- - GL_RGBA
422  *- - GL_COMPRESSED_RGB_S3TC_DXT1_EXT
423  *- - GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
424  *- - GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
425  .* - GL_COMPRESSED_RGB_ALPHA_S3TC_DXT1_EXT
426  .* - GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
427  **
428  *b Returns:
429  **
430  ** OpenGL pixel format enum; -1 on error
431  **
432  ** In OpenGL and OSG environments, the returned value should be cast
433  ** into a GLenum.
434  **
435  *b Callable From:
436  **
437  *- - C++
438  */
439  int get_gl_format();
440 
441  /*l
442  *b Description:
443  **
444  ** This function returns the OpenGL pixel format string of this
445  ** texture. There are a large number of potential results depending
446  ** if compressed textures and/or sRGB textures are enabled.
447  **
448  ** Example of possible results:
449  **
450  *- - GL_RGB GL_RGBA
451  *- - sRGB: GL_SRGB GL_SRGB_ALPHA
452  *- - Compressed: GL_COMPRESSED_RGB_S3TC_DXT1 GL_COMPRESSED_RGBA_S3TC_DXT5
453  *- - sRGB + Compressed: GL_COMPRESSED_RGB_ALPHA_S3TC_DXT1 GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5
454  */
455  const char* get_gl_format_as_string();
456 
457  /*l
458  *b Description:
459  **
460  ** This function returns the "block size" of the dds compression
461  ** types. This value can be useful in generating mipmap data offsets.
462  **
463  ** Alternatively, the function get_mipmap_data_offset() can be called
464  ** to get the precomputed mipmap data offsets.
465  **
466  ** Currently this value will be either 8 (for DXT1 compression) or 16
467  ** (for DXT3 and DXT5 compression).
468  **
469  *b Returns:
470  **
471  ** block size, in bytes
472  **
473  *b Callable From:
474  **
475  *- - C++
476  */
477  int get_dds_block_size();
478 
479  /*l
480  *b Description:
481  **
482  ** For texture indices less than zero and greater than one, a decision
483  ** must be made as to whether the texture is repeated or whether the
484  ** edge pixels are replicated to fill the space.
485  **
486  ** This function returns whether the texture should be repeated
487  ** horizontally (don't clamp) or whether the edge column of pixels
488  ** should be used (do clamp).
489  **
490  ** Note that in MultiGen Creator attribute (.attr) files, this
491  ** corresponds to the "Wrap Method u" attribute.
492  **
493  *b Returns:
494  **
495  ** 0 is texture should be tiled, 1 if not; -1 on failure
496  **
497  *b Callable From:
498  **
499  *- - C++
500  */
501  int get_clamp_s();
502 
503  /*l
504  *b Description:
505  **
506  ** For texture indices less than zero and greater than one, a
507  ** decision must be made as to whether the texture is repeated
508  ** or whether the edge pixels are replicated to fill the space.
509  **
510  ** This function returns whether the texture should be repeated
511  ** vertically (don't clamp) or whether the edge row of pixels
512  ** should be used (do clamp).
513  **
514  ** Note that in MultiGen Creator attribute (.attr) files, this
515  ** corresponds to the "Wrap Method v" attribute.
516  **
517  *b Returns:
518  **
519  ** 0 is texture should be repeated, 1 if not; -1 on failure
520  **
521  *b Callable From:
522  **
523  *- - C++
524  */
525  int get_clamp_t();
526 
527  /*l
528  *b Description:
529  **
530  ** This function frees most memory allocated by the DI-Guy geometry
531  ** loader for this object.
532  **
533  ** This function should only be called during or after the object's
534  ** build() function has been called. After it has been called, calls
535  ** to many accessor functions will fail.
536  **
537  *b Callable From:
538  **
539  *- - C++
540  */
541  void free_loader_memory();
542 
543 
544 /*****************************************************************************/
556 #ifdef CPLUSPLUS_ONLY
557 
558  /*l
559  *b Description:
560  **
561  ** This function will be called by DI-Guy when it is time for a
562  ** renderer-specific texture object to be created. At that point
563  ** the texture information has been read from the texture file,
564  ** and is available via the Accessor Functions above.
565  **
566  *i Immediate Mode:
567  **
568  ** Immediate mode renderers may override this function, to
569  ** create an object that may be invoked by bind_now().
570  **
571  *i Scene Graph:
572  **
573  ** Scene graph renderers usually do override this function, to
574  ** create an object that gets associated with diguyGraphicsMesh
575  ** objects.
576  **
577  *b Callable From:
578  **
579  *- - N/A (automatically called by DI-Guy Graphics API during
580  *- the Build Stage)
581  */
582  virtual void build();
583 
584  /*l
585  *b Description:
586  **
587  ** This function will be called by DI-Guy when it is time for a
588  ** renderer-specific texture object to be destroyed.
589  **
590  *i Immediate Mode:
591  **
592  ** Immediate mode renderers may override this function, to
593  ** destroy any object that may have been created by build().
594  **
595  *i Scene Graph:
596  **
597  ** Scene graph renderers usually do override this function, to
598  ** destroy any object that may have been created by build().
599  **
600  *b Callable From:
601  **
602  *- - N/A (automatically called by DI-Guy Graphics API during
603  *- the Unbuild Stage)
604  */
605  virtual void unbuild();
606 
607  /*l
608  *b Description:
609  **
610  ** This function will be called by DI-Guy when the texture should
611  ** be made active, or bound.
612  **
613  *i Immediate Mode:
614  **
615  ** Immediate mode renderers usually do override this function, to
616  ** invoke the object created by build(), or make calls to the
617  ** renderer to set appropriate texture state.
618  **
619  *i Scene Graph:
620  **
621  ** Scene graph renderers usually do not override this function.
622  **
623  *b Callable From:
624  **
625  *- - N/A (automatically called by DI-Guy Graphics API during
626  *- Draw Stage)
627  */
628  virtual void bind_now(diguyTextureMapType texture_type);
629 
630  /*l
631  *b Description:
632  **
633  ** This function returns the last bound texture used by DI-Guy. This
634  ** value can be used in diguyGraphicsTexture::bind() to check to see
635  ** if a texture rebind is necessary; avoiding a texture rebind can
636  ** avoid a significant performance hit in some rendering systems.
637  **
638  *b Callable From:
639  **
640  *- - C++
641  */
642  static diguyGraphicsTexture* get_last_bound_texture(int texture_unit = 0);
643 
644  /*l
645  *b Description:
646  **
647  ** This function clears out the last bound texture variable.
648  ** diguyScenario::draw() automatically calls it, but it is also
649  ** recommended that it be called before drawing individual
650  ** diguyCharacters in case something outside of DI-Guy has changed
651  ** the texture.
652  **
653  *b Callable From:
654  **
655  *- - C++
656  */
657  static void clear_last_bound_texture();
658 
659 #endif
660 
661 
662 /****************************************************************************/
663 /****************************************************************************/
664 
669 #ifdef CPLUSPLUS_ONLY
671  bdiGeometryTextureFile* get_scripted_object() {return m_scripted_object;}
672 
673 protected:
674 
675  /*l
676  ** A protected constructor. Constructors are called automatically
677  ** by DI-Guy.
678  */
679  diguyGraphicsTexture(void* internal_data);
680 
681  /*l
682  ** A protected destructor. Destructors are called automatically
683  ** by DI-Guy.
684  */
685  virtual ~diguyGraphicsTexture();
686 
687 private:
688 
689  /*l
690  ** A pointer to internal data.
691  */
692  bdiGeometryTextureFile* m_scripted_object;
693 
694  friend class bdiGeometryTextureFile;
695  friend class bdiGeometryFactory;
696 
697 #endif
698 
699 };
700 
701 
702 #endif /* __diguyGraphicsTexture_H */
703