Merge pull request #1063 from OpenSpace/bug/macosbuild

macos compile and build (still needs ring shader const fix)
This commit is contained in:
Alexander Bock
2020-02-10 23:39:39 +01:00
committed by GitHub
21 changed files with 106 additions and 75 deletions

View File

@@ -72,7 +72,15 @@ if (SGCT_SPOUT_SUPPORT AND NOT OPENSPACE_MODULE_SPOUT)
set(OPENSPACE_MODULE_SPOUT ON CACHE BOOL "Build OPENSPACE_MODULE_SPOUTModule" FORCE)
endif ()
set(MACOSX_BUNDLE_ICON_FILE openspace.icns)
#####
# macos
#####
if (APPLE)
set(MACOSX_BUNDLE_ICON_FILE openspace.icns)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OS X deployment version" FORCE)
set(CMAKE_XCODE_ATTRIBUTE_OTHER_CODE_SIGN_FLAGS "--deep" CACHE STRING "Other Code Signing Flags" FORCE)
endif()
create_new_application(OpenSpace
${SGCT_OPENVR_FILES}

View File

@@ -34,8 +34,7 @@
<Window fullScreen="false" name="GUI" tags="GUI">
<Stereo type="none" />
<Size x="1280" y="720" />
<Res x="2048" y="2048" />
<Size x="1024" y="1024" />
<Pos x="50" y="50" />
<Viewport>
<Pos x="0.0" y="0.0" />

View File

@@ -15,7 +15,6 @@ asset.require('util/default_joystick')
-- Load web gui
asset.require('util/webgui')
asset.request('customization/globebrowsing')
asset.onInitialize(function ()
openspace.setDefaultGuiSorting()

View File

@@ -20,7 +20,7 @@ local initializeAndAddNodes = function()
local lineElement = satelliteHelper.makeSingleLineElement(tle, filename)
local period = satelliteHelper.getPeriodFromElement(lineElement)
local path = tle .. "\\" .. filename
local path = tle .. "/" .. filename
-- TLE data is only relevant in EarthInertial frame which means the model
-- will inherit some irrelevant rotations from its parent. To get around that

View File

@@ -38,7 +38,7 @@ function isValidTLEFileFormat(lineArr)
end
local makeSingleLineElement = function(tle, filename)
local path = tle .. "\\" .. filename
local path = tle .. "/" .. filename
local file = io.open(path, "r")
assert(file, "File not found: " .. path)

View File

@@ -50,7 +50,7 @@ namespace openspace::scripting {
*/
class ScriptEngine : public Syncable, public DocumentationGenerator {
public:
using ScriptCallback = std::optional<std::function<void(ghoul::Dictionary)>>;
using ScriptCallback = std::function<void(ghoul::Dictionary)>;
BooleanType(RemoteScripting);
struct QueueItem {

View File

@@ -366,10 +366,13 @@ void RenderableTrail::render(const RenderData& data, RendererTasks&) {
p->setUniform(c.nVertices, nVertices);
glm::ivec2 resolution = global::renderEngine.renderingResolution();
p->setUniform(c.resolution, resolution);
p->setUniform(c.lineWidth, ceil((2.f * 1.f + lw) * std::sqrt(2.f)));
#ifndef __APPLE__
glm::ivec2 resolution = global::renderEngine.renderingResolution();
p->setUniform(c.resolution, resolution);
p->setUniform(c.lineWidth, ceil((2.f * 1.f + lw) * std::sqrt(2.f)));
#endif
if (renderPoints) {
// The stride parameter determines the distance between larger points and

View File

@@ -60,9 +60,12 @@ uniform float orenNayarRoughness;
#endif
#if SHADOW_MAPPING_ENABLED
#define NSSamplesMinusOne #{nShadowSamples}
#define NSSamples (NSSamplesMinusOne + 1)
in vec4 shadowCoords;
uniform sampler2DShadow shadowMapTexture;
uniform int nShadowSamples;
uniform float zFightingPercentage;
#endif
@@ -273,19 +276,19 @@ Fragment getFragment() {
normalizedShadowCoords.xy = normalizedShadowCoords.xy / normalizedShadowCoords.w;
normalizedShadowCoords.w = 1.0;
float sum = 0;
for (int i = 0; i < nShadowSamples; ++i) {
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-nShadowSamples + i, -nShadowSamples + i));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-nShadowSamples + i, 0));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-nShadowSamples + i, nShadowSamples - i));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( 0 , -nShadowSamples + i));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( 0 , nShadowSamples - i));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( nShadowSamples - i, -nShadowSamples + i));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( nShadowSamples - i, 0));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( nShadowSamples - i, nShadowSamples - i));
}
float sum = 0;
#for i in 0..#{nShadowSamples}
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-NSSamples + #{i}, -NSSamples + #{i}));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-NSSamples + #{i}, 0));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-NSSamples + #{i}, NSSamples - #{i}));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( 0 , -NSSamples + #{i}));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( 0 , NSSamples - #{i}));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( NSSamples - #{i}, -NSSamples + #{i}));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( NSSamples - #{i}, 0));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( NSSamples - #{i}, NSSamples - #{i}));
#endfor
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(0, 0));
shadow = sum / (8.0 * nShadowSamples + 1.f);
shadow = sum / (8.0 * NSSamples + 1.f);
}
frag.color.xyz *= shadow < 0.99 ? clamp(shadow + 0.3, 0.0, 1.0) : shadow;
#endif

View File

@@ -25,6 +25,9 @@
#include "PowerScaling/powerScaling_fs.hglsl"
#include "fragment.glsl"
#define NSSamplesMinusOne #{nShadowSamples}
#define NSSamples (NSSamplesMinusOne + 1)
in vec2 vs_st;
in float vs_screenSpaceDepth;
in vec4 shadowCoords;
@@ -36,12 +39,12 @@ uniform float transparency;
uniform vec3 sunPosition;
uniform float _nightFactor;
uniform int nShadowSamples;
uniform float zFightingPercentage;
// temp
in vec4 fragPosInLightSpace;
Fragment getFragment() {
// Moving the origin to the center
vec2 st = (vs_st - vec2(0.5)) * 2.0;
@@ -83,20 +86,20 @@ Fragment getFragment() {
normalizedShadowCoords.w = 1.0;
float sum = 0;
for (int i = 0; i < nShadowSamples; ++i) {
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-nShadowSamples + i, -nShadowSamples + i));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-nShadowSamples + i, 0));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-nShadowSamples + i, nShadowSamples - i));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( 0 , -nShadowSamples + i));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( 0 , nShadowSamples - i));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( nShadowSamples - i, -nShadowSamples + i));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( nShadowSamples - i, 0));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( nShadowSamples - i, nShadowSamples - i));
}
#for i in 0..#{nShadowSamples}
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-NSSamples + #{i}, -NSSamples + #{i}));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-NSSamples + #{i}, 0));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-NSSamples + #{i}, NSSamples - #{i}));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( 0 , -NSSamples + #{i}));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( 0 , NSSamples - #{i}));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( NSSamples - #{i}, -NSSamples + #{i}));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( NSSamples - #{i}, 0));
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( NSSamples - #{i}, NSSamples - #{i}));
#endfor
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(0, 0));
shadow = sum / (8.0 * nShadowSamples + 1.f);
shadow = clamp(sum / (8.0 * NSSamples + 1.f), 0.35, 1.0);
}
// The normal for the one plane depends on whether we are dealing
// with a front facing or back facing fragment
vec3 normal;
@@ -117,7 +120,7 @@ Fragment getFragment() {
Fragment frag;
frag.color = (0.65 * diffuse * shadow) + diffuse * 0.35;
frag.color = diffuse * shadow;
frag.depth = vs_screenSpaceDepth;
frag.gPosition = vec4(1e30, 1e30, 1e30, 1.0);
frag.gNormal = vec4(normal, 1.0);

View File

@@ -304,7 +304,7 @@ BoundingHeights boundingHeightsForChunk(const Chunk& chunk, const LayerManager&
const bool hasTileMetaData = chunkTile.tile.metaData.has_value();
if (goodTile && hasTileMetaData) {
const TileMetaData& tileMetaData = chunkTile.tile.metaData.value();
const TileMetaData& tileMetaData = *chunkTile.tile.metaData;
const float minValue = settings->performLayerSettings(
tileMetaData.minValues[HeightChannel]
@@ -518,7 +518,7 @@ RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary)
BoolProperty(EclipseHardShadowsInfo, false),
BoolProperty(ShadowMappingInfo, false),
FloatProperty(ZFightingPercentageInfo, 0.995f, 0.000001f, 1.f),
IntProperty(NumberShadowSamplesInfo, 5, 1, 20),
IntProperty(NumberShadowSamplesInfo, 5, 1, 7),
FloatProperty(TargetLodScaleFactorInfo, 15.f, 1.f, 50.f),
FloatProperty(CurrentLodScaleFactorInfo, 15.f, 1.f, 50.f),
FloatProperty(CameraMinHeightInfo, 100.f, 0.f, 1000.f),
@@ -566,6 +566,9 @@ RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary)
_shadowMappingPropertyOwner.addProperty(_generalProperties.shadowMapping);
_shadowMappingPropertyOwner.addProperty(_generalProperties.zFightingPercentage);
_shadowMappingPropertyOwner.addProperty(_generalProperties.nShadowSamples);
_generalProperties.nShadowSamples.onChange([&]() {
_shadersNeedRecompilation = true;
});
addPropertySubOwner(_shadowMappingPropertyOwner);
_generalProperties.targetLodScaleFactor.onChange([this]() {
@@ -1338,7 +1341,6 @@ void RenderableGlobe::renderChunkGlobally(const Chunk& chunk, const RenderData&
glBindTexture(GL_TEXTURE_2D, shadowData.shadowDepthTexture);
program.setUniform("shadowMapTexture", shadowMapUnit);
program.setUniform("nShadowSamples", _generalProperties.nShadowSamples);
program.setUniform("zFightingPercentage", _generalProperties.zFightingPercentage);
}
@@ -1469,7 +1471,6 @@ void RenderableGlobe::renderChunkLocally(const Chunk& chunk, const RenderData& d
glBindTexture(GL_TEXTURE_2D, shadowData.shadowDepthTexture);
program.setUniform("shadowMapTexture", shadowMapUnit);
program.setUniform("nShadowSamples", _generalProperties.nShadowSamples);
program.setUniform("zFightingPercentage", _generalProperties.zFightingPercentage);
}
@@ -1744,6 +1745,9 @@ void RenderableGlobe::recompileShaders() {
shaderDictionary.setValue(p.first, p.second);
}
// Shadow Mapping Samples
shaderDictionary.setValue("nShadowSamples", _generalProperties.nShadowSamples - 1);
//
// Create local shader
//

View File

@@ -49,10 +49,12 @@
#include <locale>
namespace {
constexpr const std::array<const char*, 10> UniformNames = {
constexpr const char* _loggerCat = "RingsComponent";
constexpr const std::array<const char*, 9> UniformNames = {
"modelViewProjectionMatrix", "textureOffset", "transparency", "_nightFactor",
"sunPosition", "ringTexture", "shadowMatrix", "shadowMapTexture",
"nShadowSamples", "zFightingPercentage"
"zFightingPercentage"
};
constexpr const std::array<const char*, 3> GeomUniformNames = {
@@ -174,7 +176,7 @@ RingsComponent::RingsComponent(const ghoul::Dictionary& dictionary)
, _transparency(TransparencyInfo, 0.15f, 0.f, 1.f)
, _enabled({ "Enabled", "Enabled", "Enable/Disable Rings" }, true)
, _zFightingPercentage(ZFightingPercentageInfo, 0.995f, 0.000001f, 1.f)
, _nShadowSamples(NumberShadowSamplesInfo, 2, 1, 20)
, _nShadowSamples(NumberShadowSamplesInfo, 2, 1, 7)
, _ringsDictionary(dictionary)
{
using ghoul::filesystem::File;
@@ -243,6 +245,7 @@ void RingsComponent::initialize() {
if (_ringsDictionary.hasKey(NumberShadowSamplesInfo.identifier)) {
_nShadowSamples = _ringsDictionary.value<int>(NumberShadowSamplesInfo.identifier);
}
_nShadowSamples.onChange([this]() { compileShadowShader(); });
addProperty(_nShadowSamples);
addProperty(_transparency);
@@ -253,11 +256,7 @@ bool RingsComponent::isReady() const {
}
void RingsComponent::initializeGL() {
_shader = global::renderEngine.buildRenderProgram(
"RingsProgram",
absPath("${MODULE_GLOBEBROWSING}/shaders/rings_vs.glsl"),
absPath("${MODULE_GLOBEBROWSING}/shaders/rings_fs.glsl")
);
compileShadowShader();
_geometryOnlyShader = global::renderEngine.buildRenderProgram(
"RingsGeomOnlyProgram",
@@ -326,7 +325,6 @@ void RingsComponent::draw(const RenderData& data,
_shader->setUniform(_uniformCache.transparency, _transparency);
_shader->setUniform(_uniformCache.nightFactor, _nightFactor);
_shader->setUniform(_uniformCache.sunPosition, _sunPosition);
_shader->setUniform(_uniformCache.nShadowSamples, _nShadowSamples);
_shader->setUniform(_uniformCache.zFightingPercentage, _zFightingPercentage);
ringTextureUnit.activate();
@@ -377,8 +375,7 @@ void RingsComponent::draw(const RenderData& data,
void RingsComponent::update(const UpdateData& data) {
if (_shader->isDirty()) {
_shader->rebuildFromFile();
ghoul::opengl::updateUniformLocations(*_shader, _uniformCache, UniformNames);
compileShadowShader();
}
if (_geometryOnlyShader->isDirty()) {
@@ -474,6 +471,25 @@ void RingsComponent::createPlane() {
);
}
void RingsComponent::compileShadowShader() {
ghoul::Dictionary dict;
dict.setValue("nShadowSamples", std::to_string(_nShadowSamples - 1));
try {
global::renderEngine.removeRenderProgram(_shader.get());
_shader = global::renderEngine.buildRenderProgram(
"RingsProgram",
absPath("${MODULE_GLOBEBROWSING}/shaders/rings_vs.glsl"),
absPath("${MODULE_GLOBEBROWSING}/shaders/rings_fs.glsl"),
dict
);
}
catch (const ghoul::RuntimeError& e) {
LERROR(e.message);
}
ghoul::opengl::updateUniformLocations(*_shader, _uniformCache, UniformNames);
}
bool RingsComponent::isEnabled() const {
return _enabled;
}

View File

@@ -77,6 +77,7 @@ public:
private:
void loadTexture();
void createPlane();
void compileShadowShader();
properties::StringProperty _texturePath;
properties::FloatProperty _size;
@@ -90,8 +91,7 @@ private:
std::unique_ptr<ghoul::opengl::ProgramObject> _shader;
std::unique_ptr<ghoul::opengl::ProgramObject> _geometryOnlyShader;
UniformCache(modelViewProjectionMatrix, textureOffset, transparency, nightFactor,
sunPosition, ringTexture, shadowMatrix, shadowMapTexture, nShadowSamples,
zFightingPercentage
sunPosition, ringTexture, shadowMatrix, shadowMapTexture, zFightingPercentage
) _uniformCache;
UniformCache(modelViewProjectionMatrix, textureOffset, ringTexture)
_geomUniformCache;

View File

@@ -166,7 +166,7 @@ documentation::Documentation ShadowComponent::Documentation() {
}
ShadowComponent::ShadowComponent(const ghoul::Dictionary& dictionary)
: properties::PropertyOwner({ "ShadowsComponent" })
: properties::PropertyOwner({ "ShadowsComponent" })
, _saveDepthTexture(SaveDepthTextureInfo)
, _distanceFraction(DistanceFractionInfo, 20, 1, 10000)
, _enabled({ "Enabled", "Enabled", "Enable/Disable Shadows" }, true)

View File

@@ -108,13 +108,10 @@ private:
int _shadowDepthTextureWidth = 4096;
bool _dynamicDepthTextureRes = true;
// All of these initializations should probably be 0 since they are GLuints?
GLuint _shadowDepthTexture = -1;
GLuint _positionInLightSpaceTexture = -1;
GLuint _shadowFBO = -1;
GLuint _firstPassSubroutine = -1;
GLuint _secondPassSubroutine = 1;
GLint _defaultFBO = -1;
GLuint _shadowDepthTexture = 0;
GLuint _positionInLightSpaceTexture = 0;
GLuint _shadowFBO = 0;
GLint _defaultFBO = 0;
GLint _mViewport[4];
GLboolean _faceCulling;

View File

@@ -173,7 +173,7 @@ bool initTexturesFromLoadedData(DefaultTileProvider& t) {
if (tile) {
const cache::ProviderTileKey key = { tile->tileIndex, t.uniqueIdentifier };
ghoul_assert(!t.tileCache->exist(key), "Tile must not be existing in cache");
t.tileCache->createTileAndPut(key, std::move(tile.value()));
t.tileCache->createTileAndPut(key, std::move(*tile));
return true;
}
}

View File

@@ -78,7 +78,7 @@ ghoul::Dictionary NavigationHandler::NavigationState::dictionary() const {
cameraDict.setValue(KeyAim, aim);
}
if (up.has_value()) {
cameraDict.setValue(KeyUp, up.value());
cameraDict.setValue(KeyUp, *up);
if (std::abs(yaw) > Epsilon) {
cameraDict.setValue(KeyYaw, yaw);
@@ -218,7 +218,7 @@ void NavigationHandler::updateCamera(double deltaTime) {
ghoul_assert(_camera != nullptr, "Camera must not be nullptr");
if (_pendingNavigationState.has_value()) {
applyNavigationState(_pendingNavigationState.value());
applyNavigationState(*_pendingNavigationState);
_orbitalNavigator.resetVelocities();
_pendingNavigationState.reset();
}
@@ -274,7 +274,7 @@ void NavigationHandler::applyNavigationState(const NavigationHandler::Navigation
glm::dvec3(referenceFrameTransform * glm::dvec4(ns.position, 1.0));
glm::dvec3 up = ns.up.has_value() ?
glm::normalize(referenceFrameTransform * ns.up.value()) :
glm::normalize(referenceFrameTransform * *ns.up) :
glm::dvec3(0.0, 1.0, 0.0);
// Construct vectors of a "neutral" view, i.e. when the aim is centered in view.

View File

@@ -101,7 +101,7 @@ int getNavigationState(lua_State* L) {
if (state.up.has_value()) {
ghoul::lua::push(L, "Up");
pushVector(L, state.up.value());
pushVector(L, *state.up);
lua_rawset(L, -3);
}
if (state.yaw != 0) {

View File

@@ -424,7 +424,7 @@ void OrbitalNavigator::updateCameraStateFromStates(double deltaTime) {
const glm::dvec3 prevCameraPosition = _camera->positionVec3();
const glm::dvec3 anchorDisplacement = _previousAnchorNodePosition.has_value() ?
(anchorPos - _previousAnchorNodePosition.value()) :
(anchorPos - *_previousAnchorNodePosition) :
glm::dvec3(0.0);
CameraPose pose = {
@@ -464,10 +464,10 @@ void OrbitalNavigator::updateCameraStateFromStates(double deltaTime) {
if (_aimNode && _aimNode != _anchorNode && hasPreviousPositions) {
const glm::dvec3 aimPos = _aimNode->worldPosition();
const glm::dvec3 cameraToAnchor =
_previousAnchorNodePosition.value() - prevCameraPosition;
*_previousAnchorNodePosition - prevCameraPosition;
Displacement anchorToAim = {
_previousAimNodePosition.value() - _previousAnchorNodePosition.value(),
*_previousAimNodePosition - *_previousAnchorNodePosition,
aimPos - anchorPos
};
@@ -502,7 +502,7 @@ void OrbitalNavigator::updateCameraStateFromStates(double deltaTime) {
glm::quat_cast(_anchorNode->worldRotationMatrix());
glm::dquat anchorNodeRotationDiff = _previousAnchorNodeRotation.has_value() ?
_previousAnchorNodeRotation.value() * glm::inverse(anchorRotation) :
*_previousAnchorNodeRotation * glm::inverse(anchorRotation) :
glm::dquat(1.0, 0.0, 0.0, 0.0);
_previousAnchorNodeRotation = anchorRotation;

View File

@@ -166,7 +166,7 @@ void LoadingScreen::render() {
const glm::vec2 dpiScaling = global::windowDelegate.dpiScaling();
const glm::ivec2 res =
glm::vec2(global::windowDelegate.currentSubwindowSize()) / dpiScaling;
glm::vec2(global::windowDelegate.currentSubwindowSize()) * dpiScaling;
float screenAspectRatio = static_cast<float>(res.x) / static_cast<float>(res.y);
@@ -317,7 +317,6 @@ void LoadingScreen::render() {
ProgressbarCenter.y + progressbarSize.y
};
for (Item& item : _items) {
if (!item.hasLocation) {
// Compute a new location

View File

@@ -179,7 +179,7 @@ bool ScriptEngine::runScript(const std::string& script, ScriptCallback callback)
if (callback) {
ghoul::Dictionary returnValue =
ghoul::lua::loadArrayDictionaryFromString(script, _state);
callback.value()(returnValue);
callback(returnValue);
} else {
ghoul::lua::runScript(_state, script);
}

View File

@@ -132,7 +132,7 @@ void VersionChecker::cancel() {
}
VersionChecker::SemanticVersion VersionChecker::latestVersion() {
return _latestVersion.value();
return *_latestVersion;
}
bool operator<(const VersionChecker::SemanticVersion a,