HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GLTextureHandler.h
Go to the documentation of this file.
1 //
2 // Copyright Contributors to the MaterialX Project
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 
6 #ifndef MATERIALX_GLTEXTUREHANDLER_H
7 #define MATERIALX_GLTEXTUREHANDLER_H
8 
9 /// @file
10 /// OpenGL texture handler
11 
13 
15 
17 
18 /// Shared pointer to an OpenGL texture handler
19 using GLTextureHandlerPtr = std::shared_ptr<class GLTextureHandler>;
20 
21 /// @class GLTextureHandler
22 /// An OpenGL texture handler class
24 {
25  public:
27  {
28  return ImageHandlerPtr(new GLTextureHandler(imageLoader));
29  }
30 
31  /// Bind an image. This method will bind the texture to an active texture
32  /// unit as defined by the corresponding image description. The method
33  /// will fail if there are not enough available image units to bind to.
34  bool bindImage(ImagePtr image, const ImageSamplingProperties& samplingProperties) override;
35 
36  /// Unbind an image.
37  bool unbindImage(ImagePtr image) override;
38 
39  /// Create rendering resources for the given image.
40  bool createRenderResources(ImagePtr image, bool generateMipMaps, bool useAsRenderTarget = false) override;
41 
42  /// Release rendering resources for the given image, or for all cached images
43  /// if no image pointer is specified.
44  void releaseRenderResources(ImagePtr image = nullptr) override;
45 
46  /// Return the bound texture location for a given resource
47  int getBoundTextureLocation(unsigned int resourceId);
48 
49  /// Utility to map an address mode enumeration to an OpenGL address mode
50  static int mapAddressModeToGL(ImageSamplingProperties::AddressMode addressModeEnum);
51 
52  /// Utility to map a filter type enumeration to an OpenGL filter type
53  static int mapFilterTypeToGL(ImageSamplingProperties::FilterType filterTypeEnum, bool enableMipmaps);
54 
55  /// Utility to map generic texture properties to OpenGL texture formats.
56  static void mapTextureFormatToGL(Image::BaseType baseType, unsigned int channelCount, bool srgb,
57  int& glType, int& glFormat, int& glInternalFormat);
58 
59  protected:
60  // Protected constructor
61  GLTextureHandler(ImageLoaderPtr imageLoader);
62 
63  // Return the first free texture location that can be bound to.
64  int getNextAvailableTextureLocation();
65 
66  protected:
67  std::vector<unsigned int> _boundTextureLocations;
68 };
69 
71 
72 #endif
virtual bool unbindImage(ImagePtr image)
#define MATERIALX_NAMESPACE_BEGIN
Definition: Generated.h:25
static ImageHandlerPtr create(ImageLoaderPtr imageLoader)
GLenum GLenum GLsizei void * image
Definition: glad.h:5132
BaseType
Definition: Image.h:48
virtual bool createRenderResources(ImagePtr image, bool generateMipMaps, bool useAsRenderTarget=false)
Create rendering resources for the given image.
virtual bool bindImage(ImagePtr image, const ImageSamplingProperties &samplingProperties)
std::shared_ptr< ImageHandler > ImageHandlerPtr
Shared pointer to an ImageHandler.
Definition: ImageHandler.h:32
std::shared_ptr< ImageLoader > ImageLoaderPtr
Shared pointer to an ImageLoader.
Definition: ImageHandler.h:35
#define MX_RENDERGLSL_API
Definition: Export.h:18
virtual void releaseRenderResources(ImagePtr image=nullptr)
#define MATERIALX_NAMESPACE_END
Definition: Generated.h:26
std::vector< unsigned int > _boundTextureLocations
shared_ptr< Image > ImagePtr
A shared pointer to an image.
Definition: Image.h:23
std::shared_ptr< class GLTextureHandler > GLTextureHandlerPtr
Shared pointer to an OpenGL texture handler.