GL Studio C++ Runtime API
image.h
Go to the documentation of this file.
1/// \file image.h
2/// \brief The Image class. All textures are converted internally into Images.
3///
4/// \par Copyright Information
5///
6/// Copyright (c) 2017 by The DiSTI Corporation.<br>
7/// 12249 Science Drive; Suite 300<br>
8/// Orlando, Florida 32826<br>
9/// USA<br>
10/// <br>
11/// All rights reserved.<br>
12///
13/// This Software contains proprietary trade secrets of DiSTI and may not be
14/// reproduced, in whole or part, in any form, or by any means of electronic,
15/// mechanical, or otherwise, without the written permission of DiSTI. Said
16/// permission may be derived through the purchase of applicable DiSTI product
17/// licenses which detail the distribution rights of this content and any
18/// Derivative Works based on this or other copyrighted DiSTI Software.
19///
20/// NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21/// AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22/// PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23/// AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24/// IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25/// PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26///
27/// LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28/// IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29/// INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30/// DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31/// INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32/// INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33/// OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34/// EXCEED FIVE DOLLARS (US$5.00).
35///
36/// The aforementioned terms and restrictions are governed by the laws of the
37/// State of Florida and the United States of America.
38
39#ifndef DISTI_INCLUDED_IMAGE_H
40#define DISTI_INCLUDED_IMAGE_H
41
42#include "IFontImage.h"
43#include "file_path_class.h"
44#include "gls_include.h"
45#include "list.h"
46#include "util.h"
47#include <stdio.h>
48
49#ifdef QNX
50# include <time.h>
51#endif
52
53namespace disti
54{
55class Mutex;
56const int IMG_TRANSPARENT = 0; /**< Alpha value for a transparent pixel */
57const int IMG_NON_TRANSPARENT = 255; /**< Alpha value for a non-transparent pixel */
58const int MAX_MIP_MAP_IMAGES = 16; /**< Maximum number of mipmapping levels */
59
60/// \details The glsImageCodec enum. Describes the compression level of a texture.
61typedef enum
62{
63 GLS_CODEC_RAW, /**< Image data is not compressed */
64 GLS_CODEC_LZ77, /**< Image data is compressed with LZ77 (Z-Lib) */
65 GLS_CODEC_JPEG /**< Image data is compressed with lossy JPEG */
67
68/// \details The ImageNPOTMode enum. Describes whether NPOT textures are allowed.
69typedef enum
70{
71 GLS_NPOT_AUTO, /**< Allow Non Power Of Two textures if able */
72 GLS_NPOT_ENABLED, /**< Always allow Non Power Of Two textures */
73 GLS_NPOT_DISABLED /**< Never allow Non Power Of Two textures */
75
76/** The glsInlineImage structure. This structure is generated and contains information needed to
77 * create reconstruct an inline generated image.
78 */
80{
81 typedef const unsigned char* const _BufferType; ///< Typedef for the type of buffer used by images.
82 unsigned int _width; ///< Width of image in pixels.
83 unsigned int _height; ///< Height of image in pixels.
84 unsigned int _components; ///< Number of components in image.
85 unsigned int _pixel_format; ///< GL_RGB, GL_RGBA ...
86 glsImageCodec _codec; ///< CODEC used to compress image.
87 unsigned long _crc; ///< CRC of image data (compressed or uncompressed?).
88 bool _gl_texture_compression; ///< Value of GlTextureCompression.
89 unsigned long _image_data_size; ///< Size of RGB data (compressed).
90 unsigned long _alpha_data_size; ///< Size of Alpha data (compressed). Zero if no alpha channel present.
91 unsigned int _line_length; ///< Length of each line of inline data, in bytes.
92 _BufferType* _rgb_buffer; ///< Pointer to the static compressed rgb buffer for the image.
93 _BufferType* _alpha_buffer; ///< Pointer to the static compressed alpha layer for the image.
94
95 /// Constructor
96 /// \param width Width of image in pixels.
97 /// \param height Height of image in pixels.
98 /// \param components Number of components in image.
99 /// \param pixel_format GL_RGB, GL_RGBA ...
100 /// \param codec CODEC used to compress image.
101 /// \param crc CRC of image data (compressed or uncompressed?).
102 /// \param gl_tex_compress Value of GlTextureCompression.
103 /// \param image_data_size Size of RGB data (compressed).
104 /// \param alpha_data_size Size of Alpha data (compressed). Zero if no alpha channel present.
105 /// \param line_length Length of each line of inline data, in bytes.
106 /// \param rgb_buffer Pointer to the static compressed rgb buffer for the image.
107 /// \param alpha_buffer Pointer to the static compressed alpha layer for the image.
108 glsInlineImage( unsigned int width,
109 unsigned int height,
110 unsigned int components,
111 unsigned int pixel_format,
112 glsImageCodec codec,
113 unsigned long crc,
114 bool gl_tex_compress,
115 unsigned long image_data_size,
116 unsigned long alpha_data_size,
117 unsigned int line_length,
118 const unsigned char* const* rgb_buffer,
119 const unsigned char* const* alpha_buffer )
120 : _width( width )
121 , _height( height )
122 , _components( components )
123 , _pixel_format( pixel_format )
124 , _codec( codec )
125 , _crc( crc )
126 , _gl_texture_compression( gl_tex_compress )
127 , _image_data_size( image_data_size )
128 , _alpha_data_size( alpha_data_size )
129 , _line_length( line_length )
130 , _rgb_buffer( rgb_buffer )
131 , _alpha_buffer( alpha_buffer )
132 {
133 }
134};
135
136/** Enable/Disable global Non Power Of Two capability. This will override the
137 * texture's setting from the editor.
138 * \note NPOT detection is not currently supported. (GLS-5940)
139 * \param state The state to set it to. Will enable, disable, or apply auto detection
140 for if NPOT support is available.
141 */
143
144/** Determines if Non Power Of Two textures are supported.
145 * \return GLS_NPOT_ENABLED if NPOT textures are supported, GLS_NPOT_DISABLED otherwise.
146 */
148
149/** By default, Image instances release their texture data in main memory after loading it to the GPU.
150 * This flag controls that default behavior for new Image instances. Set to false if you want all
151 * Images to keep a copy of their texture data loaded in main memory. (Note: This can dramatically
152 * increase memory usage.)
153 *
154 * \note The default applies only to Image instances created after this flag is set. To set or get
155 * the value behavior for a particular Image instance, call Image::SetReleaseImageDataEnabled()
156 * or Image::IsReleaseImageDataEnabled(), respectively.
157 *
158 * \note Default value: true
159 *
160 * \param enable The new default value
161 *
162 * \sa disti::Image::SetReleaseImageDataEnabled(), disti::Image::IsReleaseImageDataEnabled()
163 */
165
166/// See SetReleaseImageDataDefault() for more details.
167/// \sa disti::SetReleaseImageDataDefault( bool )
168/// \return The current value for the flag controlling the default behavior for new Image instances.
170
171/**
172 The Image class. Implements loading 2D image files.
173*/
174class Image
175 : virtual public IFontImage
176{
177protected:
178 unsigned int _textureHandle; /**< The texture handle of the image. */
179 int _pixelFormat; /**< Pixel format for the image */
180 int _pixelSize; /**< Size of a pixel in bytes */
181 int _errorFound; /**< Error found reading image file flag. */
182 char* _errorMessage; /**< Error message in string format. */
183 int _width; /**< Actual width of image in pixels. */
184 int _height; /**< Actual height of image in pixels. */
185 int _texWidth; /**< Texture width (power of 2) of the image in pixels. */
186 int _texHeight; /**< Texture height (power of 2) of the image in pixels. */
187
188 float _texCoord[ 2 ]; /**< Texture coordinates of upper right corner
189 * of image. This will be (1.0,1.0) for a
190 * square power of two image */
191
192 unsigned char* _rgbBuf; /**< Pointer to the image data for this image. */
193
194 bool _mipMap; /**< True if this image should use mip mapping */
195 unsigned char* _mmBuf[ MAX_MIP_MAP_IMAGES ]; /**< Pointers to the smaller versions of _rgbBuf */
196
197 unsigned long _crcValue; /**< CRC value used to determine if two images are the same */
198
199 int _numUsers; /**< Count of number of objects that reference this one */
200
201 bool _replaceImageFlag; /**< Indicates the images has been changed and needs to be re-bound */
202
203 bool _releaseImageData; /**< true to allow image data for image to be unloaded from main memory else false */
204
205 static bool _glTextureCompressionSupported; /**< Indicates if GL Texture compression is supported on the
206 Machine that this program is running on. */
207
208 bool _glTextureCompression; /**< Indicates if GL Texture compression is enabled for this image */
209
210 glsInlineImage* _staticInlineImage; /**< Inline image data for this image, if applicable. */
211
212 bool _allowImageSharing; /**< If false, causes Image::CrcValue() to always return 0, disabling duplicate checking. */
213
214 bool _allowNPOT; /**< If true, this texture is not scaled to power of two. */
215
216 bool _skipCopyOnAllocate; ///< If true, we allocate texture memory but omit initialization, useful for effects like render-to-texture.
217
218#ifdef GLES
219 unsigned int _stateManagerHandle; /**< Handle used by the OpenGL ES state manager to quickly find this texture */
220#endif
221
222 /** Convert Luminance Alpha texture to Alpha texture.
223 * Used on OpenGL ES target to speedup texturing for fonts
224 */
226
227public:
228 static GLS_EXPORT bool _globalMipMapEnabled; /**< Determines the default value for _mipMap, and does not
229 * do mip mapping if false */
230
231 /// All images get added to the InstanceList.
232 /// \return A modifiable refernce to the image list.
234
235 /// Use this Mutex when accessing the InstanceList.
236 /// \return A mutex for accessing the image list.
238
239 /** Empties the InstanceList
240 * This is done when loading objects which will be drawn in different
241 * OpenGL contexts.
242 */
244
245 /** Determines whether this image will release its image data from main memory when it is not needed.
246 *
247 * When enabled (true), the the Image will release the main memory copy of the data when it is not
248 * needed in order to save memory. This flag is enabled by default and should be disabled in situations
249 * such as when the ImageData for this Image cannot be re-created from permanent storage.
250 *
251 * \note The default value is determined by disti::GetReleaseImageDataDefault().
252 *
253 * \param enable Whether release of image data is enabled.
254 *
255 * \sa IsReleaseImageDataEnabled()
256 * \sa disti::SetReleaseImageDataDefault()
257 *
258 * \note The static methods SetUnloadImageDataEnabled() and IsUnloadImageDataEnabled() from Image and Image::InstanceListEntry
259 * were removed to disambiguate between the per-instance setting and the global setting. Code that was calling
260 * Image::SetUnloadImageDataEnabled() to set the default flag for all instances should now call disti::SetReleaseImageDataDefault().
261 * Code that was calling Image::InstanceListEntry::SetUnloadImageDataEnabled() to set the flag for only one instance
262 * should call this method.
263 */
265
266 /// \return Whether or not release of image data is enabled.
267 /// \sa SetReleaseImageDataEnabled()
268 /// \sa disti::GetReleaseImageDataDefault()
269 /// \note The static methods SetUnloadImageDataEnabled() and IsUnloadImageDataEnabled() from Image and Image::InstanceListEntry
270 /// were removed to disambiguate between the per-instance setting and the global setting. Code that was calling
271 /// Image::IsUnloadImageDataEnabled() to get the default flag for all instances should now call disti::GetReleaseImageDataDefault().
272 /// Code that was calling Image::InstanceListEntry::IsUnloadImageDataEnabled() to get the flag for only one instance
273 /// should call this method.
275
276#ifdef GLES
277 /// \copydoc IFontImage::StateManagerHandle()
278 virtual unsigned int StateManagerHandle() const { return _stateManagerHandle; }
279
280 /// \copydoc IFontImage::StateManagerHandle(unsigned int)
281 virtual void StateManagerHandle( unsigned int handle ) { _stateManagerHandle = handle; }
282#endif
283
284 /** These are options that are possibly used during loading of the image. */
286 {
287 public:
290 {
291 }
292
293 bool _reverseAlpha; ///< For compatibility with images with the alpha channel reversed.
294
295 /// Equality operator
296 /// \param rhs The object to compare against.
297 /// \return Whether or not the objects are equal.
298 bool operator==( const LoadOptions& rhs ) const
299 {
300 return ( _reverseAlpha == rhs._reverseAlpha );
301 }
302 }; // class LoadOptions
303
304 /** an entry in the Image::InstanceList */
306 {
307 public:
308 /** holds absolute file path, file size, mod time and image load options */
309 class FileID
310 {
311 public:
312 /** default ctor - no file */
314
315 /** ctor
316 * \param path path for file ( can be relative or absolute, will ultimately be stored in the FileID as an absolute path )
317 * \param loadOptions image loading options for file
318 */
319 GLS_EXPORT FileID( const FilePathClass& path, const LoadOptions& loadOptions );
320
321 /** copy ctor
322 * \param src FileID to copy
323 */
324 GLS_EXPORT FileID( const FileID& src );
325
326 /** get the absolute path for the file
327 * \return the absolute path for the file
328 */
330
331 /** get the image load options for the file
332 * \return the image load options for the file
333 */
335
336 /** get the file size for the file
337 * \return the file size for the file
338 */
339 GLS_EXPORT off_t GetFileSize() const;
340
341 /** get the modification time for the file
342 * \return the modification time for the file
343 */
344 GLS_EXPORT time_t GetModTime() const;
345
346 /** compare two FileID's checking for same absolute path and load options
347 * \note file size and mod time are not compared here, just absolute path and load options
348 * \param rhs FileID to compare
349 * \return true if equal absolute paths and load options
350 */
351 GLS_EXPORT bool operator==( const FileID& rhs ) const;
352
353 /// Assigment operator
354 /// \param rhs The object to copy from.
355 /// \return The resulting object (this).
357
358 /** get the absolute path for the given path
359 * \param imgPath path in question
360 * \return the absolute path for the given path
361 */
363
364 protected:
365 FilePathClass _path; /**< absolute path for image file */
366 LoadOptions _loadOptions; /**< load options associated with image */
367 off_t _fileSize; /**< size in bytes of image file */
368 time_t _modTime; /**< file mod time for image file */
369 }; // class FileID
370
371 /** array of FileID */
373
374 /** ctor
375 * \param img image for list entry
376 * \param imgPath [optional, defaults to ""] optional path to image file associated with image
377 * \param imgLoadOptions [optional] optional load options associated with image
378 */
379 GLS_EXPORT InstanceListEntry( Image* img, const FilePathClass& imgPath = FilePathClass(), const LoadOptions& imgLoadOptions = LoadOptions() );
380
381 /** dtor -- NOTE: image associated with entry is not destroyed */
383
384 /** get the image associated with the entry
385 * \return the image associated with the entry
386 */
388
389 /** get the image files associated with the entry
390 * \return the image files associated with the entry
391 */
393
394 /** determine if the given fileID is associated with this entry
395 * \param fileID file ID in question
396 * \param foundFileID [out] receives associated file ID if the given fileID is associated with this entry
397 * \return true if the given fileID is associated with this entry else false
398 */
399 GLS_EXPORT bool FileIsAssociatedWithImage( const FileID& fileID, FileID& foundFileID );
400
401 /** associate the given fileID with the image in this entry
402 * \param fileID file ID in question
403 */
405
406 /** disassociate the given fileID with the image in this entry
407 * \param fileID file ID in question
408 */
410
411 /** Attempt to reload the associated image from an associated image file. Associated image will
412 * be marked as no longer being a candidate for unloading.
413 * NOTE: Image::InstanceListMutex() cannot be locked when calling this method
414 * \return true if reload succeeded else false
415 * \pre Image::InstanceListMutex() is not locked
416 */
418
419 protected:
420 Image* _img; /**< image associated with entry */
421 FileIDArray _associatedFiles; /**< files associated with image else empty array */
422
423 private:
424 // disallow
426 InstanceListEntry operator=( const InstanceListEntry& rhs );
427 }; // class InstanceListEntry
428
429protected:
430 /** Add this image to the Image Sharing Instance List */
432
433 /** Set the Image _texWidth, _texHeight, _texWidth, _texCoord[0],
434 * and _texCoord[1]. Width and height must be set before calling
435 * this function. */
437
438 /** Allocate and initialize the pixel buffer memory for this image
439 * _texWidth, _textHeight and _pixelSize must be initialized prior to
440 * calling! _rgbBuf is set to the initialized memory.
441 * \param zeroOut Whether or not to clear the memory to zero on allocation.
442 * \return True if allocated. false on failure.
443 */
444 virtual GLS_EXPORT bool AllocatePixelMemory( bool zeroOut = true );
445
446 /// Allocate memory for Mip-Map images.
447 /// \param zeroOut Whether or not to clear the memory to zero on allocation.
448 /// \return Whether or not allocation was successful.
449 virtual GLS_EXPORT bool AllocateMipMapMemory( bool zeroOut = true );
450
451 /// Calculate mip-map images from the main image.
452 /// \param reCalc Whether or not to perform the calculation.
453 virtual GLS_EXPORT void CalculateMipMapImages( bool reCalc = false );
454
455 /** Helper routine used by constructor. Allocates pixel memory and sets the
456 * texture width, height and pixel size
457 * \param width Width of the image
458 * \param height Height of the image
459 * \param pixelSize The size in bytes of each pixel
460 */
461 virtual GLS_EXPORT void Initialize( int width, int height, int pixelSize );
462
463public:
464 /** \return The state of any error found reading image file flag. */
465 virtual GLS_EXPORT int ErrorFound();
466
467 /** Sets the error message.
468 * \param errorMessage String containing error message.
469 */
470 virtual GLS_EXPORT void SetError( char* errorMessage );
471
472 /// \return The error message found during reading image file
473 virtual GLS_EXPORT char* GetError();
474
475 /** Draws the image at the current raster position. */
476 virtual GLS_EXPORT void Draw();
477
478 /** Draws the image at the x,y raster position specified.
479 * \param x X position to draw the image
480 * \param y Y position to draw the image
481 */
482 virtual GLS_EXPORT void Draw( int x, int y );
483
484 /** \return A new image that is a duplicate of this image or NULL if duplication is not possible.
485 */
487
488 /** \return A pointer to the 2D image data */
489 virtual GLS_EXPORT unsigned char* ImageData();
490
491 /** \return the X position of the texture coordinate used for the image. */
492 virtual GLS_EXPORT float TextureCoordX();
493
494 /** \return the Y position of the texture coordinate used for the image. */
495 virtual GLS_EXPORT float TextureCoordY();
496
497 /** \return the texture width of the image file. This is the power
498 * of 2 size greater than or equal to the size of the image.
499 */
501
502 /** \return the texture height of the image file. This is the power
503 * of 2 size greater than or equal the size of the image.
504 */
506
507 /** \return the memory size of the image in bytes */
508 virtual GLS_EXPORT int Size();
509
510 /** \return the width of the image. */
511 virtual GLS_EXPORT int Width();
512
513 /** \return the height of the image. */
514 virtual GLS_EXPORT int Height();
515
516 /** \return true if the internal texture handle is valid */
518
519 /** \return the OpenGL texture handle of this texture instance */
520 virtual unsigned int TextureHandle() const { return _textureHandle; }
521
522 /** Returns the pixel format for this image
523 * \return The internal pixel format for this image
524 */
525 virtual GLS_EXPORT int PixelFormat();
526
527 /** Sets the pixel format for this image and also the pixel size as
528 * determined from the format. Eg. GL_RGBA has a pixel size of 4.
529 * \param format The new internal pixel format for this image
530 */
531 virtual GLS_EXPORT void PixelFormat( int format );
532
533 /** \return The OpenGL enumerator for the pixel format for this
534 * image as a string. Used for inline texture generation
535 */
537
538 /** \return The size of a pixel in this image in bytes */
539 virtual GLS_EXPORT int PixelSize();
540
541 /// \return A pointer to the memory location corresponding to the given X,Y position within the image.
542 /// \param x The X raster position.
543 /// \param y The Y raster position.
544 virtual GLS_EXPORT unsigned char* GetRasterPosition( int x, int y );
545
546 /** Set the value of a secific pixel in the rbg buffer.
547 * \param x X position of the pixel
548 * \param y Y position of the pixel
549 * \param color Color of the pixel
550 */
551 virtual GLS_EXPORT void SetPixel( int x, int y, float color[] );
552
553 /** Takes the image and creates a 2D Decal texture map. (Not Implemented)*/
555
556 /** Create a new texture object using Image object data. */
558
559 /** Deletes the OpenGL texture object for this Image. */
561
562 /** Make this Image object the active texture. */
563 virtual GLS_EXPORT void BindTexture();
564
565 /** Create an Image object with the specified image data and image size.
566 * \param data Pointer to the image data
567 * \param width Width of the image
568 * \param height Height of the image
569 * \param pixelFormat The format of each pixel, eg. GL_RGBA
570 */
571 GLS_EXPORT Image( const unsigned char* const data, int width, int height, int pixelFormat );
572
573 /** Create an Image object with the specified image size.
574 * \param width Width of the image
575 * \param height Height of the image
576 * \param pixelSize The size in bytes of each pixel
577 * \param allowNPOT If the image is allowed to be non-power of two (NPOT)
578 */
579 GLS_EXPORT Image( int width, int height, int pixelSize, bool allowNPOT = false );
580
581 /** Create an Image from an inline image (GL Studio 2.2 and later API)
582 * \param image Structure containing details of inline image
583 */
585
586 /** Create an Image from a buffer of ZLIB compressed data
587 * Image data must already be a power of two!
588 * \param width Width of the image
589 * \param height Height of the image
590 * \param components The size in bytes of each pixel
591 * \param format The OpenGL texture format to use
592 * \param comprLen The size of the compressed image
593 * \param data The buffer of compressed data
594 * \param crcVal The CRC value used to find duplicate textures
595 * \param lineLength The number of bytes in each inline image line
596 */
597 GLS_EXPORT Image( int width, int height, int components, int format, unsigned int comprLen, const unsigned char* const data[], unsigned long crcVal = 0, int lineLength = 320 );
598
599 /** Create an Image from a buffer of uncompressed data
600 * Image data must already be a power of two!
601 * \param width Width of the image
602 * \param height Height of the image
603 * \param components The size in bytes of each pixel
604 * \param format The OpenGL texture format to use
605 * \param pix The buffer of uncompressed data
606 * \param crcVal The CRC value used to find duplicate textures
607 * \param lineLength The number of bytes in each inline image line
608 */
609 GLS_EXPORT Image( int width, int height, int components, int format, const unsigned char* const pix[], unsigned long crcVal = 0, int lineLength = 320 );
610
611 /// Copy constructor
612 /// \param source The object to copy from.
613 GLS_EXPORT Image( const Image& source );
614
615 /** Constructor for an Image object. */
617
618 /// Perform the upload process from the CPU to the GPU.
619 virtual GLS_EXPORT void DoTexSubImage();
620
621 /** Unload RGB and mipmap data to save memory */
623
624protected:
625 /** Destroy an Image object. Frees the memory for the RGB buffer. */
627
628public:
629 /** Will delete the Image object if nobody is using it */
630 virtual GLS_EXPORT void DeleteUsage();
631
632 /** Lets this object know that another something is using this image */
633 virtual GLS_EXPORT void AddUsage();
634
635 /** \return the number of simultanious users of this image */
636 virtual GLS_EXPORT int NumUsers();
637
638 /// Assignment operator
639 /// \param im The object to copy from.
640 virtual GLS_EXPORT void operator=( Image& im );
641
642 /** Scale the texture to the nearest power of two */
643 virtual GLS_EXPORT void ScaleTexture();
644
645 /** \return the CRC value for this image. 0 indicates an invalid value or that duplicate checking is disabled for the Image.
646 */
647 virtual GLS_EXPORT unsigned long CrcValue();
648
649 /** Equality operator. Determines if two images are equal
650 * \param im Image to test
651 * \return boolean result
652 */
653 virtual GLS_EXPORT int operator==( Image& im );
654
655 /** Determines if an image #1 is the same a notional image based on the following criteria
656 * \param image Image #1
657 * \param width Width of notional image
658 * \param height Height of notional image
659 * \param components Number of components in the notional image
660 * \param crcVal 32 bit CRC of notional image
661 * \param glTexCompress GlTextureCompresssion setting for the image
662 * \return True if they are equal
663 */
664 static GLS_EXPORT bool IsDuplicate( Image* image, int width, int height, int components, unsigned long crcVal, bool glTexCompress );
665
666 /** Tries to find an image that is the same as this image
667 * \return A pointer to the first image in the image instance list that matches or NULL if not found
668 */
670
671 /** Tries to find an image that is the same as a notional image based on the following criteria
672 * \param width Width of notional image
673 * \param height Height of notional image
674 * \param components Number of components in the notional image
675 * \param crcVal 32 bit CRC of notional image
676 * \param glTexCompress GlTextureCompresssion setting for the image
677 * \return A pointer to the first image in the image instance list that matches or NULL if not found
678 */
679 static GLS_EXPORT Image* FindDuplicate( int width, int height, int components, unsigned long crcVal, bool glTexCompress );
680
681 /** Enable or disable mipmaps for this image
682 * \param set Whether or not mipmaps are enabled
683 */
684 virtual GLS_EXPORT void MipMap( bool set );
685
686 /** \return Whether or not mipmaps are enabled */
687 virtual GLS_EXPORT bool MipMap();
688
689 /** Enable or disable Open GL texture compression for this image
690 * \param set Whether or not Open GL texture compression is enabled
691 */
692 virtual GLS_EXPORT void GlTextureCompression( bool set );
693
694 /** \return Whether or not Open GL texture compression is enabled */
696
697 /** Scales the image up to the nearest power of two in each dimension */
699
700 /// Replaces the current image with the specified.
701 /// The new image must be the same _texWidth, _texHeight, and _pixelSize as the current image.
702 /// \param imageData The image data to replace with.
703 virtual GLS_EXPORT void ReplaceImage( unsigned char* imageData );
704
705 /** Replaces the current image with the specified.
706 * \param imageData buffer containing the new image data
707 * \param width new Width of the image. Must be a power of two (2^n).
708 * \param height new Height of the image. Must be a power of two (2^n).
709 * \param pixelSize The size in bytes of each pixel
710 * \returns true if successful, false if the operation is unsupported or there was an error.
711 */
712 virtual GLS_EXPORT bool ReplaceImage( unsigned char* imageData, int width, int height, int pixelSize );
713
714 /** Allocates the local rgb buffer from the glsInlineImage for this image.
715 * \returns true if successful, false on failure (e.g. this image doesn't have a glsInlineImage associated with it.)
716 */
718
719 /** Frees the local rgb buffer if this image has a glsInlineImage associated with it.
720 * \returns true if the buffer was freed, false if this Image does not have a glsInlineImage associated with it.
721 */
723
724 /** Removes the association between this Image and it's glsInlineImage data.
725 * This will use more memory, but makes the Image independent of the static data.
726 * This method will attempt to load the image before disconnecting from the glsInlineImage,
727 * if the load fails, ImageData() will return NULL afterwards.
728 * After calling this method, the Image will no longer have a glsInlineImage associated with it.
729 *
730 * \param loadImage If true, the _rgbBuf will be loaded from the image data before disconnecting
731 * If false, the _rgbBuf will be allocated but not initialized.
732 * \returns true if the Image had a glsInlineImage associated with it
733 * \return false if the Image did not have a glsInlineImage associated with it.
734 */
735 virtual GLS_EXPORT bool DisconnectInlineImage( bool loadImage = true );
736
737 /// If AllowImageSharing is true, this Image may be deleted by the texture palette if a duplicate texture is found.
738 /// This also implies that the Image will not change and may be used in place of another texture
739 /// with the same CrcValue(). If false this causes Image::CrcValue() to always return 0,
740 /// disabling duplicate checking. (default: true)
741 /// \note If this Image is already in a TexturePalette, you should call TexturePalette::DisableImageSharing() instead of this method.
742 /// \param value The new sharing flag to set.
743 virtual GLS_EXPORT void AllowImageSharing( bool value );
744
745 /// \return Whether or not this image can be deleted if a duplicate texture is found.
747
748 /// Disable texture GPU memory initialization, improves performance for effects like render-to-texture.
749 /// \param value True if we should not initialize this image with local texture data.
750 virtual GLS_EXPORT void SkipCopyOnAllocate( bool value );
751
752 /// \return Whether or not we should skip initialization during texture allocation.
753 virtual GLS_EXPORT bool SkipCopyOnAllocate() const;
754
755 /** Determine if non-power of two (NPOT) textures are allowed for this image.
756 * \return true if non-power of two (NPOT) textures are allowed.
757 */
759}; // class Image
760
761} // namespace disti
762
763#endif
IFontImage.
Definition: file_path_class.h:62
Definition: IFontImage.h:50
FilePathClass _path
Definition: image.h:365
static FilePathClass GetAbsoluteFilePath(const FilePathClass &imgPath)
off_t _fileSize
Definition: image.h:367
bool operator==(const FileID &rhs) const
LoadOptions _loadOptions
Definition: image.h:366
time_t _modTime
Definition: image.h:368
const LoadOptions & GetLoadOptions() const
FileID(const FilePathClass &path, const LoadOptions &loadOptions)
FileID & operator=(const FileID &rhs)
const FilePathClass & GetPath() const
Definition: image.h:306
Image * _img
Definition: image.h:420
InstanceListEntry(Image *img, const FilePathClass &imgPath=FilePathClass(), const LoadOptions &imgLoadOptions=LoadOptions())
bool FileIsAssociatedWithImage(const FileID &fileID, FileID &foundFileID)
DynamicArray< FileID > FileIDArray
Definition: image.h:372
void DisassociateFileWithImage(const FileID &fileID)
FileIDArray _associatedFiles
Definition: image.h:421
void AssociateFileWithImage(const FileID &fileID)
FileIDArray & GetAssociatedFiles()
Definition: image.h:286
bool operator==(const LoadOptions &rhs) const
Definition: image.h:298
bool _reverseAlpha
For compatibility with images with the alpha channel reversed.
Definition: image.h:293
Definition: image.h:176
virtual bool LoadInlineImageData()
virtual int Height()
int _errorFound
Definition: image.h:181
virtual unsigned char * ImageData()
bool IsReleaseImageDataEnabled()
void SetReleaseImageDataEnabled(bool enable)
virtual void DeleteUsage()
virtual void SetError(char *errorMessage)
virtual int Width()
int _pixelSize
Definition: image.h:180
virtual unsigned long CrcValue()
virtual int TextureHeight()
virtual Image * FindDuplicate()
bool _mipMap
Definition: image.h:194
virtual void ScaleToPowerOfTwo()
Image(const glsInlineImage &image)
static Image * FindDuplicate(int width, int height, int components, unsigned long crcVal, bool glTexCompress)
virtual int PixelSize()
virtual int operator==(Image &im)
virtual int NumUsers()
virtual bool AllocateMipMapMemory(bool zeroOut=true)
virtual void operator=(Image &im)
bool _allowNPOT
Definition: image.h:214
bool IsAllowNPOTTextures() const
virtual bool ReplaceImage(unsigned char *imageData, int width, int height, int pixelSize)
virtual bool SkipCopyOnAllocate() const
Image(const unsigned char *const data, int width, int height, int pixelFormat)
float _texCoord[2]
Definition: image.h:188
virtual void SetTexWidthHeight()
virtual Image * Clone()
static List_c & InstanceList()
virtual void DoTexSubImage()
Perform the upload process from the CPU to the GPU.
void UnloadRgbData()
virtual ~Image()
virtual unsigned char * GetRasterPosition(int x, int y)
virtual void Draw(int x, int y)
virtual bool TextureHandleValid()
virtual void DeallocateTextureBinding()
virtual int ErrorFound()
bool _releaseImageData
Definition: image.h:203
virtual void PixelFormat(int format)
virtual int TextureWidth()
virtual void ReplaceImage(unsigned char *imageData)
virtual bool DisconnectInlineImage(bool loadImage=true)
virtual void GlTextureCompression(bool set)
int _numUsers
Definition: image.h:199
void AddSelfToInstanceList()
unsigned char * _rgbBuf
Definition: image.h:192
virtual bool FreeInlineImageData()
virtual void Draw()
virtual char * GetError()
bool _skipCopyOnAllocate
If true, we allocate texture memory but omit initialization, useful for effects like render-to-textur...
Definition: image.h:216
int _pixelFormat
Definition: image.h:179
virtual void MipMap(bool set)
Image(const Image &source)
static bool _glTextureCompressionSupported
Definition: image.h:205
static void EmptyInstanceList()
virtual void AllocateTextureBinding()
virtual void ConvertLuminanceAlphaToAlpha()
Image(int width, int height, int components, int format, unsigned int comprLen, const unsigned char *const data[], unsigned long crcVal=0, int lineLength=320)
unsigned int _textureHandle
Definition: image.h:178
bool _replaceImageFlag
Definition: image.h:201
unsigned long _crcValue
Definition: image.h:197
virtual void AddUsage()
virtual char * PixelFormatString()
glsInlineImage * _staticInlineImage
Definition: image.h:210
virtual float TextureCoordX()
virtual float TextureCoordY()
virtual void ScaleTexture()
unsigned char * _mmBuf[MAX_MIP_MAP_IMAGES]
Definition: image.h:195
virtual int Size()
virtual void CalculateMipMapImages(bool reCalc=false)
virtual unsigned int TextureHandle() const
Definition: image.h:520
int _texWidth
Definition: image.h:185
virtual bool MipMap()
virtual void SetAsCurrentTexture()
char * _errorMessage
Definition: image.h:182
virtual int PixelFormat()
static disti::Mutex & InstanceListMutex()
int _texHeight
Definition: image.h:186
Image(int width, int height, int pixelSize, bool allowNPOT=false)
static bool IsDuplicate(Image *image, int width, int height, int components, unsigned long crcVal, bool glTexCompress)
virtual bool AllowImageSharing()
bool _allowImageSharing
Definition: image.h:212
int _height
Definition: image.h:184
Image(int width, int height, int components, int format, const unsigned char *const pix[], unsigned long crcVal=0, int lineLength=320)
virtual void SetPixel(int x, int y, float color[])
bool _glTextureCompression
Definition: image.h:208
virtual bool GlTextureCompression()
static bool _globalMipMapEnabled
Definition: image.h:228
virtual void BindTexture()
virtual bool AllocatePixelMemory(bool zeroOut=true)
int _width
Definition: image.h:183
virtual void AllowImageSharing(bool value)
virtual void Initialize(int width, int height, int pixelSize)
virtual void SkipCopyOnAllocate(bool value)
Definition: list.h:134
Definition: gls_mutex.h:51
A class to handle file paths.
A file for all GL Studio files to include.
#define GLS_EXPORT
Macro denoting which functions should be visible from the runtime library.
Definition: gls_include.h:50
The List_c class. Generic linked list.
Definition: bmpimage.h:46
ImageNPOTMode
Definition: image.h:70
@ GLS_NPOT_DISABLED
Definition: image.h:73
@ GLS_NPOT_ENABLED
Definition: image.h:72
@ GLS_NPOT_AUTO
Definition: image.h:71
void SetNPOTState(ImageNPOTMode state)
ImageNPOTMode DoesSystemSupportNPOT()
glsImageCodec
Definition: image.h:62
@ GLS_CODEC_JPEG
Definition: image.h:65
@ GLS_CODEC_LZ77
Definition: image.h:64
@ GLS_CODEC_RAW
Definition: image.h:63
void SetReleaseImageDataDefault(bool enable)
const int IMG_NON_TRANSPARENT
Definition: image.h:57
const int MAX_MIP_MAP_IMAGES
Definition: image.h:58
bool GetReleaseImageDataDefault()
const int IMG_TRANSPARENT
Definition: image.h:56
Definition: image.h:80
glsImageCodec _codec
CODEC used to compress image.
Definition: image.h:86
_BufferType * _alpha_buffer
Pointer to the static compressed alpha layer for the image.
Definition: image.h:93
unsigned int _pixel_format
GL_RGB, GL_RGBA ...
Definition: image.h:85
unsigned long _image_data_size
Size of RGB data (compressed).
Definition: image.h:89
const unsigned char *const _BufferType
Typedef for the type of buffer used by images.
Definition: image.h:81
_BufferType * _rgb_buffer
Pointer to the static compressed rgb buffer for the image.
Definition: image.h:92
glsInlineImage(unsigned int width, unsigned int height, unsigned int components, unsigned int pixel_format, glsImageCodec codec, unsigned long crc, bool gl_tex_compress, unsigned long image_data_size, unsigned long alpha_data_size, unsigned int line_length, const unsigned char *const *rgb_buffer, const unsigned char *const *alpha_buffer)
Definition: image.h:108
unsigned int _width
Width of image in pixels.
Definition: image.h:82
unsigned int _height
Height of image in pixels.
Definition: image.h:83
unsigned int _components
Number of components in image.
Definition: image.h:84
unsigned long _alpha_data_size
Size of Alpha data (compressed). Zero if no alpha channel present.
Definition: image.h:90
unsigned int _line_length
Length of each line of inline data, in bytes.
Definition: image.h:91
unsigned long _crc
CRC of image data (compressed or uncompressed?).
Definition: image.h:87
bool _gl_texture_compression
Value of GlTextureCompression.
Definition: image.h:88
Generally useful defines, macros, enumerations and function prototypes.
#define FALSE
False macro, for backward compatibility purposes.
Definition: util.h:104