Skip to content

Commit

Permalink
Fix JPG skyboxes. Do not require restart to switch to a custom env. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro authored and bluemarvin committed Aug 6, 2019
1 parent 343e53e commit c5d3ca6
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,28 @@ private void setEnvOverride(boolean value) {
mBinding.envOverrideSwitch.setOnCheckedChangeListener(mEnvOverrideListener);

SettingsStore.getInstance(getContext()).setEnvironmentOverrideEnabled(value);
mWidgetManager.updateEnvironment();
}

private OnClickListener mResetListener = (view) -> {
boolean restart = false;
boolean updated = false;
if (mBinding.envOverrideSwitch.isChecked() != SettingsStore.ENV_OVERRIDE_DEFAULT) {
setEnvOverride(SettingsStore.ENV_OVERRIDE_DEFAULT);
restart = true;
updated = true;
}

if (!mEnvironmentsRadio.getValueForId(mEnvironmentsRadio.getCheckedRadioButtonId()).equals(SettingsStore.ENV_DEFAULT)) {
setEnv(mEnvironmentsRadio.getIdForValue(SettingsStore.ENV_DEFAULT), true);
updated = true;
}

if (restart)
showRestartDialog();
if (updated) {
mWidgetManager.updateEnvironment();
}
};

private SwitchSetting.OnCheckedChangeListener mEnvOverrideListener = (compoundButton, value, doApply) -> {
setEnvOverride(value);
showRestartDialog();
};

private ImageRadioGroupSetting.OnCheckedChangeListener mEnvsListener = (checkedId, doApply) -> {
Expand Down
42 changes: 21 additions & 21 deletions app/src/main/cpp/BrowserWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,23 +644,8 @@ BrowserWorld::InitializeJava(JNIEnv* aEnv, jobject& aActivity, jobject& aAssetMa
m.controllers->SetPointerColor(vrb::Color(VRBrowser::GetPointerColor()));
m.loadingAnimation->LoadModels(m.loader);
m.rootController->AddNode(m.controllers->GetRoot());
std::string skyboxPath = VRBrowser::GetActiveEnvironment();
std::string extension;
if (VRBrowser::isOverrideEnvPathEnabled()) {
std::string storagePath = VRBrowser::GetStorageAbsolutePath(INJECT_SKYBOX_PATH);
if (std::ifstream(storagePath)) {
skyboxPath = storagePath;
extension = Skybox::ValidateCustomSkyboxAndFindFileExtension(storagePath);
if (!extension.empty()) {
skyboxPath = storagePath;
VRB_DEBUG("Found custom skybox file extension: %s", extension.c_str());
} else {
VRB_ERROR("Failed to find custom skybox files.");
}
}
}
#if !defined(SNAPDRAGONVR)
CreateSkyBox(skyboxPath, extension);
UpdateEnvironment();
// Don't load the env model, we are going for skyboxes in v1.0
// CreateFloor();
#endif
Expand Down Expand Up @@ -797,9 +782,24 @@ BrowserWorld::SetTemporaryFilePath(const std::string& aPath) {
void
BrowserWorld::UpdateEnvironment() {
ASSERT_ON_RENDER_THREAD();
std::string env = VRBrowser::GetActiveEnvironment();
VRB_LOG("Setting environment: %s", env.c_str());
CreateSkyBox(env, "");
std::string skyboxPath = VRBrowser::GetActiveEnvironment();
std::string extension;
if (VRBrowser::isOverrideEnvPathEnabled()) {
std::string storagePath = VRBrowser::GetStorageAbsolutePath(INJECT_SKYBOX_PATH);
if (std::ifstream(storagePath)) {
skyboxPath = storagePath;
extension = Skybox::ValidateCustomSkyboxAndFindFileExtension(storagePath);
if (!extension.empty()) {
skyboxPath = storagePath;
VRB_DEBUG("Found custom skybox file extension: %s", extension.c_str());
} else {
VRB_ERROR("Failed to find custom skybox files.");
}
}
}

VRB_LOG("Setting environment: %s", skyboxPath.c_str());
CreateSkyBox(skyboxPath, extension);
}

void
Expand Down Expand Up @@ -1330,14 +1330,14 @@ BrowserWorld::CreateSkyBox(const std::string& aBasePath, const std::string& aExt
ASSERT_ON_RENDER_THREAD();
const bool empty = aBasePath == "cubemap/void";
const std::string extension = aExtension.empty() ? ".ktx" : aExtension;
const GLenum glFormat = extension == ".ktx" ? GL_COMPRESSED_RGB8_ETC2 : GL_RGB8;
const GLenum glFormat = extension == ".ktx" ? GL_COMPRESSED_RGB8_ETC2 : GL_RGBA8;
const int32_t size = 1024;
if (m.skybox && empty) {
m.skybox->SetVisible(false);
return;
} else if (m.skybox) {
m.skybox->SetVisible(true);
if (m.skybox->GetLayer() && m.skybox->GetLayer()->GetWidth() != size) {
if (m.skybox->GetLayer() && (m.skybox->GetLayer()->GetWidth() != size || m.skybox->GetLayer()->GetFormat() != glFormat)) {
VRLayerCubePtr oldLayer = m.skybox->GetLayer();
VRLayerCubePtr newLayer = m.device->CreateLayerCube(size, size, glFormat);
m.skybox->SetLayer(newLayer);
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/cpp/VRLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,19 +372,22 @@ struct VRLayerCube::State: public VRLayer::State {
int32_t height;
bool loaded;
uint32_t textureHandle;
GLuint glFormat;
State():
width(0),
height(0),
loaded(false),
textureHandle(0)
textureHandle(0),
glFormat(GL_RGBA8)
{}
};

VRLayerCubePtr
VRLayerCube::Create(const int32_t aWidth, const int32_t aHeight) {
VRLayerCube::Create(const int32_t aWidth, const int32_t aHeight, const GLuint aGLFormat) {
auto result = std::make_shared<vrb::ConcreteClass<VRLayerCube, VRLayerCube::State>>();
result->m.width = aWidth;
result->m.height = aHeight;
result->m.glFormat = aGLFormat;
return result;
}

Expand Down Expand Up @@ -413,6 +416,11 @@ VRLayerCube::SetTextureHandle(uint32_t aTextureHandle){
m.textureHandle = aTextureHandle;
}

GLuint
VRLayerCube::GetFormat() const {
return m.glFormat;
}

void
VRLayerCube::SetLoaded(bool aLoaded) {
m.loaded = aLoaded;
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/cpp/VRLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,13 @@ typedef std::shared_ptr<VRLayerCube> VRLayerCubePtr;

class VRLayerCube: public VRLayer {
public:
static VRLayerCubePtr Create(const int32_t aWidth, const int32_t aHeight);
static VRLayerCubePtr Create(const int32_t aWidth, const int32_t aHeight, const GLuint aGLFormat);

int32_t GetWidth() const;
int32_t GetHeight() const;
GLuint GetTextureHandle() const;
bool IsLoaded() const;
GLuint GetFormat() const;

void SetTextureHandle(uint32_t aTextureHandle);
void SetLoaded(bool aReady);
Expand Down
2 changes: 1 addition & 1 deletion app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,7 @@ DeviceDelegateOculusVR::CreateLayerCube(int32_t aWidth, int32_t aHeight, GLint a
if (m.cubeLayer) {
m.cubeLayer->Destroy();
}
VRLayerCubePtr layer = VRLayerCube::Create(aWidth, aHeight);
VRLayerCubePtr layer = VRLayerCube::Create(aWidth, aHeight, aInternalFormat);
m.cubeLayer = OculusLayerCube::Create(layer, aInternalFormat);
if (m.ovr) {
vrb::RenderContextPtr context = m.context.lock();
Expand Down

0 comments on commit c5d3ca6

Please sign in to comment.