20
20
#include " vrb/VertexArray.h"
21
21
22
22
#include < array>
23
+ #include < list>
24
+ #include < sys/stat.h>
23
25
24
26
using namespace vrb ;
25
27
26
28
namespace crow {
27
29
30
+ static const std::string sPosx = " posx" ;
31
+ static const std::string sNegx = " negx" ;
32
+ static const std::string sPosy = " posy" ;
33
+ static const std::string sNegy = " negy" ;
34
+ static const std::string sPosz = " posz" ;
35
+ static const std::string sNegz = " negz" ;
36
+ static const std::list<std::string> sBaseNameList = std::list<std::string>({
37
+ sPosx , sNegx , sPosy , sNegy , sPosz , sNegz
38
+ });
39
+ static const std::list<std::string> sFileExt = std::list<std::string>({
40
+ " .ktx" , " .jpg" , " .png"
41
+ });
42
+
28
43
static TextureCubeMapPtr LoadTextureCube (vrb::CreationContextPtr& aContext, const std::string& aBasePath,
29
44
const std::string& aExtension, GLuint targetTexture = 0 ) {
30
45
TextureCubeMapPtr cubemap = vrb::TextureCubeMap::Create (aContext, targetTexture);
@@ -35,8 +50,8 @@ static TextureCubeMapPtr LoadTextureCube(vrb::CreationContextPtr& aContext, cons
35
50
cubemap->SetTextureParameter (GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
36
51
37
52
auto path = [&](const std::string &name) { return aBasePath + " /" + name + aExtension; };
38
- vrb::TextureCubeMap::Load (aContext, cubemap, path (" posx " ), path (" negx " ), path (" posy " ),
39
- path (" negy " ), path (" posz " ), path (" negz " ));
53
+ vrb::TextureCubeMap::Load (aContext, cubemap, path (sPosx ), path (sNegx ), path (sPosy ),
54
+ path (sNegy ), path (sPosz ), path (sNegz ));
40
55
return cubemap;
41
56
}
42
57
@@ -185,6 +200,33 @@ Skybox::GetRoot() const {
185
200
return m.root ;
186
201
}
187
202
203
+ static bool
204
+ FileDoesNotExist (const std::string& aName) {
205
+ struct stat buffer;
206
+ return (stat (aName.c_str (), &buffer) != 0 );
207
+ }
208
+
209
+ std::string
210
+ Skybox::ValidateCustomSkyboxAndFindFileExtension (const std::string& aBasePath) {
211
+ for (const std::string& ext: sFileExt ) {
212
+ int32_t fileCount = 0 ;
213
+ for (const std::string& baseName: sBaseNameList ) {
214
+ const std::string file = aBasePath + " /" + baseName + ext;
215
+ if (FileDoesNotExist (file)) {
216
+ if (fileCount > 0 ) {
217
+ VRB_ERROR (" Custom skybox file missing: %s" , file.c_str ());
218
+ }
219
+ break ;
220
+ }
221
+ fileCount++;
222
+ }
223
+ if (fileCount == sBaseNameList .size ()) {
224
+ return ext;
225
+ }
226
+ }
227
+
228
+ return std::string ();
229
+ }
188
230
189
231
SkyboxPtr
190
232
Skybox::Create (vrb::CreationContextPtr aContext, const VRLayerCubePtr& aLayer) {
0 commit comments