1- //
2- // ofCubeMap.h
3- //
4- // Created by Nick Hardeman on 10/16/22.
5- //
6-
71#pragma once
82
93#include " ofShader.h"
1812
1913class ofVboMesh ;
2014class ofGLProgrammableRenderer ;
21-
22- class ofCubeMap {
23- public:
24- struct ofCubeMapSettings {
25- of::filesystem::path filePath { " " };
26- of::filesystem::path cacheDirectory { " " };
27-
28- bool overwriteCache = false ;
29- bool useCache = false ;
30- bool useLutTex = false ;
31- bool flipVertically = true ;
32- bool useMaximumPrecision = false ;
33-
34- int resolution = 512 ;
15+ class ofMaterial ;
16+
17+
18+ struct ofCubeMapSettings {
19+ of::filesystem::path filePath { " " }; // /< path to load the cube map, a single texture
20+ of::filesystem::path cacheDirectory { " " }; // /< directory to cache the irradiance and pre filter maps
21+
22+ bool overwriteCache = false ; // /< overwrite the cache of the irradiance and pre filter maps
23+ bool useCache = false ; // /< check for cached irradiance and pre filter images on disk
24+ bool useLutTex = false ; // /< create a lut texture to pass to the shaders
25+ bool flipVertically = true ; // /< flip the loaded cubemap image vertically
26+ bool useMaximumPrecision = false ; // /< use 32 bit float (GL_RGB32F) precision, default is 16 bit (GL_RGB16F)
27+
28+ int resolution = 512 ; // /< resolution of each side of the cube map to be generated
3529#ifdef TARGET_OPENGLES
36- int irradianceRes = 16 ;
37- int preFilterRes = 64 ;
30+ int irradianceRes = 16 ; // /< resolution of each side of the irradiance map to be generated
31+ int preFilterRes = 64 ;// /< resolution of each side of the pre filter map to be generated
3832#else
39- int irradianceRes = 32 ;
40- int preFilterRes = 128 ;
33+ int irradianceRes = 32 ; // /< resolution of each side of the irradiance map to be generated
34+ int preFilterRes = 128 ; // /< resolution of each side of the pre filter map to be generated
4135#endif
42- };
36+ };
4337
38+ class ofCubeMap {
39+ protected:
40+
41+ // / \class ofCubeMap::Data
42+ // /
43+ // / \brief Data class structure for storing GL texture ids and other data regarding cube maps
44+ // / Used internally for access to cube map data in the rendering pipeline, ie. ofMaterial.
45+ // / A Data class is created for each instance of ofCubeMap and all of them can be accessed by ofCubeMapsData().
46+ // / Which is declared towards the bottom of this file.
4447 class Data {
4548 public:
46- GLuint cubeMapId = 0 ;
49+ GLuint cubeMapId = 0 ; // /< GL texture id of the cube map
4750 bool bCubeMapAllocated = false ;
48- GLuint irradianceMapId = 0 ;
51+ GLuint irradianceMapId = 0 ; // /< GL texture id of the irradiance map
4952 bool bIrradianceAllocated = false ;
50- GLuint preFilteredMapId = 0 ;
53+ GLuint preFilteredMapId = 0 ; // /< GL texture id of the pre filter map
5154 bool bPreFilteredMapAllocated = false ;
52-
55+
5356 int index = -1 ;
5457 bool isEnabled = true ;
55-
56- ofCubeMapSettings settings;
57-
58- int maxMipLevels = 5 ;
59- float exposure = 1.0 ;
58+
59+ ofCubeMapSettings settings; // /< settings associated with this cube map
60+
61+ int maxMipLevels = 5 ; // /< number of mip map levels for generating the prefilted map
62+ float exposure = 1.0 ; // /< used for storing the exposure of the cube map, which is set with ofCubeMap::setExposure()
6063 };
61-
62- static GLenum getTextureTarget ();
64+
65+ // / \brief Global storage for all cube maps created. The Data class holds infomation about textures and other information
66+ // / relevant for rendering. This function is utilized internally.
67+ // / More about the Data class above.
68+ // / \return std::vector<std::weak_ptr<ofCubeMap::Data>>&.
69+ static std::vector<std::weak_ptr<ofCubeMap::Data>>& getCubeMapsData ();
70+
71+ // / \brief Is there any active cube map.
72+ // / \return true if there is any active cube map.
6373 static bool hasActiveCubeMap ();
74+ // / \brief Get the first cube map data that is enabled.
75+ // / \return std::shared_ptr<ofCubeMap::Data> of the active cube map data.
6476 static std::shared_ptr<ofCubeMap::Data> getActiveData ();
77+ // / \brief Internal function for releasing the GL texture memory.
78+ // / \param std::shared_ptr<ofCubeMap::Data> cube map data holding texture ids to clear.
6579 static void clearTextureData (std::shared_ptr<ofCubeMap::Data> adata);
6680 #ifdef TARGET_ANDROID
6781 static void regenerateAllTextures ();
6882 #endif
6983 static const ofTexture & getBrdfLutTexture ();
84+
85+ friend class ofMaterial ;
86+ friend class ofShader ;
87+
88+ public:
89+
90+ // / \brief Return the GL texture type.
91+ // / \return GLenum GL_TEXTURE_CUBE_MAP.
92+ static GLenum getTextureTarget ();
7093
7194 ofCubeMap ();
7295 ofCubeMap (const ofCubeMap & mom);
7396 ofCubeMap (ofCubeMap && mom);
7497
7598 ~ofCubeMap ();
7699
77- // / \load an image and convert to cube map.
100+ // / \load An image and convert to cube map.
78101 // / \param apath path to the image to load.
79102 // / \param aFaceResolution resolution of the cube map image sides.
80103 // / \param aBFlipY flip the images upside down.
81104 bool load (const of::filesystem::path & apath, int aFaceResolution, bool aBFlipY = true );
82- // / \load an image and convert to cube map.
105+ // / \load An image and convert to cube map.
83106 // / \param apath path to the image to load.
84107 // / \param aFaceResolution resolution of the cube map image sides.
85108 // / \param aBFlipY flip the images upside down.
@@ -94,14 +117,18 @@ class ofCubeMap {
94117 // / \param mom The ofCubeMap to copy from. Reuses internal GL texture IDs.
95118 ofCubeMap & operator =(const ofCubeMap & mom);
96119 ofCubeMap & operator =(ofCubeMap && mom);
97-
120+ // / \brief Clear the GL textures.
98121 void clear ();
99-
122+ // / \brief Calls drawCubeMap();
100123 void draw ();
124+ // / \brief Render the cube map.
101125 void drawCubeMap ();
126+ // / \brief Render the irradiance map.
102127 void drawIrradiance ();
128+ // / \brief Render prefilted map.
129+ // / \param aRoughness from 0 - 1.
103130 void drawPrefilteredCube (float aRoughness);
104-
131+
105132 bool isEnabled () { return data->isEnabled ; }
106133 bool isEnabled () const { return data->isEnabled ; }
107134 void setEnabled (bool ab) { data->isEnabled = ab; }
@@ -111,18 +138,36 @@ class ofCubeMap {
111138 bool hasIrradianceMap ();
112139
113140 int getFaceResolution () { return data->settings .resolution ; }
141+ // / \brief Get the GL texture id of the cube map.
142+ // / \return GLuint.
114143 GLuint getTextureId ();
144+ // / \brief Does this platform support HDR.
145+ // / \return bool.
115146 bool doesSupportHdr ();
147+ // / \brief Is this cube map HDR.
148+ // / \return bool.
116149 bool isHdr ();
150+ // / \brief Are the textures GL_RGB16F.
151+ // / \return bool.
117152 bool isMediumPrecision ();
118-
153+ // / \brief Set the exposure of the cube map.
154+ // / \param aExposure from 0 - 1.
119155 void setExposure (float aExposure);
156+ // / \brief Get the exposure of the cube map.
157+ // / \return float from 0 - 1.
120158 float getExposure () { return data->exposure ; }
121-
159+ // / \brief Use as precalculated BRDF Lut texture.
160+ // / \param ab bool to use texture.
122161 void setUseBrdfLutTexture (bool ab);
162+ // / \brief Is Using BRDF Lut texture.
163+ // / \return bool.
123164 bool isUsingLutBrdfTexture () { return data->settings .useLutTex ; }
124-
165+
166+ // / \brief Get the texture id of the irradiance map.
167+ // / \return GLuint, texture id.
125168 GLuint getIrradianceMapId () { return data->irradianceMapId ; }
169+ // / \brief Get the texture id of the pre filtered map.
170+ // / \return GLuint, texture id.
126171 GLuint getPrefilterMapId () { return data->preFilteredMapId ; }
127172
128173protected:
@@ -178,4 +223,3 @@ class ofCubeMap {
178223 static ofShader shaderBrdfLUT;
179224};
180225
181- std::vector<std::weak_ptr<ofCubeMap::Data>> & ofCubeMapsData ();
0 commit comments