mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-01 17:20:09 -06:00
Added support for configuration file
- BASE_PATH is set using the openspace.cfg file. The binary will look
upwards in the directory hierarchy until it is found.
- All other paths is defined in the configurationfile. Paths may be
absolute or relative using the ${BASE_PATH} token
- Moved SGCT configuration files to its own folder
- Updated tests to support new configuration loading
- TODO: Make the loading of configuration easier for the programmer.
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <ghoul/misc/configurationmanager.h>
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
@@ -35,14 +36,17 @@ class ScriptEngine;
|
||||
|
||||
class OpenSpaceEngine {
|
||||
public:
|
||||
static void create(int argc, char** argv, int& newArgc, char**& newArgv);
|
||||
static void create(int argc, char** argv, std::vector<std::string>& sgctArguments);
|
||||
static void destroy();
|
||||
static OpenSpaceEngine& ref();
|
||||
|
||||
static bool isInitialized();
|
||||
bool initialize();
|
||||
static bool registerFilePaths();
|
||||
|
||||
|
||||
static bool registerPathsFromDictionary(const ghoul::Dictionary& dictionary);
|
||||
static bool registerBasePathFromConfigurationFile(const std::string& filename);
|
||||
static bool findConfiguration(std::string& filename) ;
|
||||
|
||||
ghoul::ConfigurationManager& configurationManager();
|
||||
InteractionHandler& interactionHandler();
|
||||
RenderEngine& renderEngine();
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
<?xml version="1.0" ?>
|
||||
<shaders>
|
||||
<shader identifier="powerscale">
|
||||
<vertex path="shaders/powerscale_vs.glsl" />
|
||||
<fragment path="shaders/powerscale_fs.glsl" />
|
||||
<bindings>
|
||||
<attribute name="in_position" position="0" />
|
||||
<attribute name="in_st" position="1" />
|
||||
<attribute name="in_normal" position="2" />
|
||||
<attribute name="in_color" position="3" />
|
||||
<fragdata name="diffuse" position="0" />
|
||||
</bindings>
|
||||
</shader>
|
||||
<shader identifier="pscstandard">
|
||||
<vertex path="shaders/pscstandard_vs.glsl" />
|
||||
<fragment path="shaders/pscstandard_fs.glsl" />
|
||||
<bindings>
|
||||
<attribute name="in_position" position="0" />
|
||||
<attribute name="in_st" position="1" />
|
||||
<attribute name="in_normal" position="2" />
|
||||
<fragdata name="diffuse" position="0" />
|
||||
</bindings>
|
||||
</shader>
|
||||
</shaders>
|
||||
@@ -1,107 +0,0 @@
|
||||
/**
|
||||
Copyright (C) 2012-2014 Jonas Strandstedt
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#version 150
|
||||
|
||||
uniform mat4 ViewProjection;
|
||||
uniform mat4 ModelTransform;
|
||||
uniform vec4 campos;
|
||||
uniform vec4 objpos;
|
||||
uniform float time;
|
||||
uniform sampler2D texture1;
|
||||
uniform sampler2D texture2;
|
||||
uniform sampler2D texture3;
|
||||
uniform float TessLevel;
|
||||
uniform bool Wireframe;
|
||||
uniform bool Lightsource;
|
||||
uniform bool UseTexture;
|
||||
|
||||
in vec2 vs_st;
|
||||
in vec3 vs_stp;
|
||||
in vec4 vs_normal;
|
||||
in vec4 vs_color;
|
||||
in vec4 vs_position;
|
||||
|
||||
out vec4 diffuse;
|
||||
|
||||
const float k = 10.0;
|
||||
|
||||
vec4 psc_normlization(vec4 invec) {
|
||||
|
||||
float xymax = max(invec.x,invec.y);
|
||||
|
||||
if(invec.z > 0.0f || invec.z < 0.0f) {
|
||||
return invec / abs(invec.z);
|
||||
} else if (xymax != 0.0f) {
|
||||
return invec / xymax;
|
||||
} else {
|
||||
return invec / -.0;
|
||||
}
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
|
||||
// Observable universe is 10^27m, setting the far value to extremely high, aka 30!! ERMAHGERD!
|
||||
float s_far = 27.0; //= gl_DepthRange.far; // 40
|
||||
float s_farcutoff = 12.0;
|
||||
float s_nearcutoff = 7.0;
|
||||
float s_near = 0.0f;// gl_DepthRange.near; // 0.1
|
||||
float depth;
|
||||
|
||||
// the value can be normalized to 1
|
||||
vec4 p = vs_position;
|
||||
if(vs_position.w <= 0.5) {
|
||||
//depth = abs(vs_position.z * pow(10, vs_position.w)) / pow(k,s_far);
|
||||
depth = (vs_position.w+log(abs(vs_position.z)))/pow(k, vs_position.w);
|
||||
} else if(vs_position.w < 3.0) {
|
||||
depth = vs_position.w+log(abs(vs_position.z))/pow(k, vs_position.w);
|
||||
} else {
|
||||
depth = vs_position.w+log(abs(vs_position.z));
|
||||
}
|
||||
|
||||
// DEBUG
|
||||
float depth_orig = depth;
|
||||
float x = 0.0f;
|
||||
float cutoffs = 0.0;
|
||||
float orig_z = vs_position.z;
|
||||
|
||||
// calculate a normalized depth [0.0 1.0]
|
||||
if((depth > s_near && depth <= s_nearcutoff) || (depth > s_farcutoff && depth < s_far)) {
|
||||
|
||||
// completely linear interpolation [s_near .. depth .. s_far]
|
||||
depth = (depth - s_near) / (s_far - s_near);
|
||||
|
||||
} else if(depth > s_nearcutoff && depth < s_farcutoff) {
|
||||
|
||||
// DEBUG
|
||||
cutoffs = 1.0;
|
||||
|
||||
// interpolate [10^s_nearcutoff .. 10^depth .. 10^s_farcutoff]
|
||||
// calculate between 0..1 where the depth is
|
||||
x = (pow(10,depth) - pow(10, s_nearcutoff)) / (pow(10,s_farcutoff) - pow(10, s_nearcutoff));
|
||||
|
||||
// remap the depth to the 0..1 depth buffer
|
||||
depth = s_nearcutoff + x * (s_farcutoff - s_nearcutoff);
|
||||
depth = (depth - s_near) / (s_far - s_near);
|
||||
|
||||
} else {
|
||||
// where am I?
|
||||
// do I need to be discarded?
|
||||
//discard;
|
||||
}
|
||||
|
||||
|
||||
// set the depth
|
||||
gl_FragDepth = depth;
|
||||
|
||||
// color
|
||||
diffuse = texture2D(texture1, vs_st);
|
||||
//diffuse = vec4(1.0,0.0,0.0,1.0);
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
/**
|
||||
Copyright (C) 2012-2014 Jonas Strandstedt
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#version 150
|
||||
|
||||
uniform mat4 ViewProjection;
|
||||
uniform mat4 ModelTransform;
|
||||
uniform vec4 campos;
|
||||
uniform mat4 camrot;
|
||||
uniform vec2 scaling;
|
||||
uniform vec4 objpos;
|
||||
uniform float time;
|
||||
uniform sampler2D texture1;
|
||||
uniform sampler2D texture2;
|
||||
uniform sampler2D texture3;
|
||||
uniform float TessLevel;
|
||||
uniform bool Wireframe;
|
||||
uniform bool Lightsource;
|
||||
uniform bool UseTexture;
|
||||
|
||||
in vec3 in_position;
|
||||
in vec2 in_st;
|
||||
in vec3 in_normal;
|
||||
in vec4 in_color;
|
||||
in vec3 in_attribute3f;
|
||||
in float in_attribute1f;
|
||||
|
||||
out vec2 vs_st;
|
||||
out vec3 vs_stp;
|
||||
out vec4 vs_normal;
|
||||
out vec4 vs_color;
|
||||
out vec4 vs_position;
|
||||
|
||||
const float k = 10.0;
|
||||
const float dgr_to_rad = 0.0174532925;
|
||||
|
||||
vec4 psc_addition(vec4 v1, vec4 v2) {
|
||||
float ds = v2.w - v1.w;
|
||||
if(ds >= 0) {
|
||||
float p = pow(k,-ds);
|
||||
return vec4(v1.x*p + v2.x, v1.y*p + v2.y, v1.z*p + v2.z, v2.w);
|
||||
} else {
|
||||
float p = pow(k,ds);
|
||||
return vec4(v1.x + v2.x*p, v1.y + v2.y*p, v1.z + v2.z*p, v1.w);
|
||||
}
|
||||
}
|
||||
|
||||
vec4 psc_to_meter(vec4 v1, vec2 v2) {
|
||||
return vec4(v1.xyz * v2.x * pow(k,v2.y + v1.w), 1.0);
|
||||
}
|
||||
|
||||
vec4 psc_scaling(vec4 v1, vec2 v2) {
|
||||
float ds = v2.y - v1.w;
|
||||
if(ds >= 0) {
|
||||
return vec4(v1.xyz * v2.x * pow(k,v1.w), v2.y);
|
||||
} else {
|
||||
return vec4(v1.xyz * v2.x * pow(k,v2.y), v1.w);
|
||||
}
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
// set variables
|
||||
vs_st = in_st;
|
||||
vs_stp = in_position;
|
||||
vs_normal = normalize(ModelTransform * vec4(in_normal,1));
|
||||
vs_color = in_color;
|
||||
|
||||
// fetch model and view translation
|
||||
vec4 vertex_translate = ModelTransform[3];
|
||||
|
||||
// rotate and scale vertex with model transform and add the translation
|
||||
vec3 local_vertex_pos = mat3(ModelTransform) * in_position + vertex_translate.xyz;
|
||||
|
||||
// PSC addition; local vertex position and the object power scaled world position
|
||||
vs_position = psc_addition(vec4(local_vertex_pos,0),objpos);
|
||||
|
||||
// PSC addition; rotated and viewscaled vertex and the cmaeras negative position
|
||||
vs_position = psc_addition(vs_position,vec4(-campos.xyz,campos.w));
|
||||
|
||||
// rotate the camera
|
||||
vs_position = camrot * vs_position;
|
||||
|
||||
// rescales the scene to fit inside the view frustum
|
||||
// is set from the main program, but these are decent values
|
||||
//vec2 scaling = vec2(1.0, -8.0);
|
||||
|
||||
// project using the rescaled coordinates,
|
||||
//vec4 vs_position_rescaled = psc_scaling(vs_position, scaling);
|
||||
vec4 vs_position_rescaled = psc_to_meter(vs_position, scaling);
|
||||
|
||||
// project the position to view space
|
||||
gl_Position = ViewProjection * vs_position_rescaled;
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
/**
|
||||
Copyright (C) 2012-2014 Jonas Strandstedt
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#version 400 core
|
||||
|
||||
uniform mat4 ViewProjection;
|
||||
uniform mat4 ModelTransform;
|
||||
uniform vec4 campos;
|
||||
uniform vec4 objpos;
|
||||
uniform float time;
|
||||
uniform sampler2D texture1;
|
||||
uniform sampler2D texture2;
|
||||
uniform sampler2D texture3;
|
||||
uniform float TessLevel;
|
||||
uniform bool Wireframe;
|
||||
uniform bool Lightsource;
|
||||
uniform bool UseTexture;
|
||||
|
||||
in vec2 vs_st;
|
||||
in vec3 vs_stp;
|
||||
in vec4 vs_normal;
|
||||
in vec4 vs_position;
|
||||
|
||||
out vec4 diffuse;
|
||||
|
||||
const float k = 10.0;
|
||||
|
||||
vec4 psc_normlization(vec4 invec) {
|
||||
|
||||
float xymax = max(invec.x,invec.y);
|
||||
|
||||
if(invec.z > 0.0f || invec.z < 0.0f) {
|
||||
return invec / abs(invec.z);
|
||||
} else if (xymax != 0.0f) {
|
||||
return invec / xymax;
|
||||
} else {
|
||||
return invec / -.0;
|
||||
}
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
|
||||
// Observable universe is 10^27m, setting the far value to extremely high, aka 30!! ERMAHGERD!
|
||||
float s_far = 27.0; //= gl_DepthRange.far; // 40
|
||||
float s_farcutoff = 12.0;
|
||||
float s_nearcutoff = 7.0;
|
||||
float s_near = 0.0f;// gl_DepthRange.near; // 0.1
|
||||
float depth;
|
||||
|
||||
// the value can be normalized to 1
|
||||
vec4 p = vs_position;
|
||||
if(vs_position.w <= 0.5) {
|
||||
//depth = abs(vs_position.z * pow(10, vs_position.w)) / pow(k,s_far);
|
||||
depth = (vs_position.w+log(abs(vs_position.z)))/pow(k, vs_position.w);
|
||||
} else if(vs_position.w < 3.0) {
|
||||
depth = vs_position.w+log(abs(vs_position.z))/pow(k, vs_position.w);
|
||||
} else {
|
||||
depth = vs_position.w+log(abs(vs_position.z));
|
||||
}
|
||||
|
||||
// DEBUG
|
||||
float depth_orig = depth;
|
||||
float x = 0.0f;
|
||||
float cutoffs = 0.0;
|
||||
float orig_z = vs_position.z;
|
||||
|
||||
// calculate a normalized depth [0.0 1.0]
|
||||
if((depth > s_near && depth <= s_nearcutoff) || (depth > s_farcutoff && depth < s_far)) {
|
||||
|
||||
// completely linear interpolation [s_near .. depth .. s_far]
|
||||
depth = (depth - s_near) / (s_far - s_near);
|
||||
|
||||
} else if(depth > s_nearcutoff && depth < s_farcutoff) {
|
||||
|
||||
// DEBUG
|
||||
cutoffs = 1.0;
|
||||
|
||||
// interpolate [10^s_nearcutoff .. 10^depth .. 10^s_farcutoff]
|
||||
// calculate between 0..1 where the depth is
|
||||
x = (pow(10,depth) - pow(10, s_nearcutoff)) / (pow(10,s_farcutoff) - pow(10, s_nearcutoff));
|
||||
|
||||
// remap the depth to the 0..1 depth buffer
|
||||
depth = s_nearcutoff + x * (s_farcutoff - s_nearcutoff);
|
||||
depth = (depth - s_near) / (s_far - s_near);
|
||||
|
||||
} else {
|
||||
// where am I?
|
||||
// do I need to be discarded?
|
||||
// discard;
|
||||
}
|
||||
|
||||
|
||||
// set the depth
|
||||
gl_FragDepth = depth;
|
||||
|
||||
// color
|
||||
diffuse = texture2D(texture1, vs_st);
|
||||
// diffuse = vec4(vs_position.xyz * pow(10, vs_position.w), 1.0);
|
||||
// diffuse = vec4(vs_st, 0.0, 1.0);
|
||||
//diffuse = vec4(1.0,0.0,0.0,1.0);
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
/**
|
||||
Copyright (C) 2012-2014 Jonas Strandstedt
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#version 400 core
|
||||
|
||||
uniform mat4 ViewProjection;
|
||||
uniform mat4 ModelTransform;
|
||||
uniform vec4 campos;
|
||||
uniform mat4 camrot;
|
||||
uniform vec2 scaling;
|
||||
uniform vec4 objpos;
|
||||
uniform float time;
|
||||
uniform sampler2D texture1;
|
||||
uniform sampler2D texture2;
|
||||
uniform sampler2D texture3;
|
||||
uniform float TessLevel;
|
||||
uniform bool Wireframe;
|
||||
uniform bool Lightsource;
|
||||
uniform bool UseTexture;
|
||||
|
||||
in vec4 in_position;
|
||||
in vec2 in_st;
|
||||
in vec3 in_normal;
|
||||
|
||||
out vec2 vs_st;
|
||||
out vec3 vs_stp;
|
||||
out vec4 vs_normal;
|
||||
out vec4 vs_position;
|
||||
|
||||
const float k = 10.0;
|
||||
const float dgr_to_rad = 0.0174532925;
|
||||
|
||||
vec4 psc_addition(vec4 v1, vec4 v2) {
|
||||
float ds = v2.w - v1.w;
|
||||
if(ds >= 0) {
|
||||
float p = pow(k,-ds);
|
||||
return vec4(v1.x*p + v2.x, v1.y*p + v2.y, v1.z*p + v2.z, v2.w);
|
||||
} else {
|
||||
float p = pow(k,ds);
|
||||
return vec4(v1.x + v2.x*p, v1.y + v2.y*p, v1.z + v2.z*p, v1.w);
|
||||
}
|
||||
}
|
||||
|
||||
vec4 psc_to_meter(vec4 v1, vec2 v2) {
|
||||
return vec4(v1.xyz * v2.x * pow(k,v2.y + v1.w), 1.0);
|
||||
}
|
||||
|
||||
vec4 psc_scaling(vec4 v1, vec2 v2) {
|
||||
float ds = v2.y - v1.w;
|
||||
if(ds >= 0) {
|
||||
return vec4(v1.xyz * v2.x * pow(k,v1.w), v2.y);
|
||||
} else {
|
||||
return vec4(v1.xyz * v2.x * pow(k,v2.y), v1.w);
|
||||
}
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
// set variables
|
||||
vs_st = in_st;
|
||||
vs_stp = in_position.xyz;
|
||||
vs_normal = normalize(ModelTransform * vec4(in_normal,1));
|
||||
|
||||
// fetch model and view translation
|
||||
vec4 vertex_translate = ModelTransform[3];
|
||||
|
||||
// rotate and scale vertex with model transform and add the translation
|
||||
vec3 local_vertex_pos = mat3(ModelTransform) * in_position.xyz + vertex_translate.xyz;
|
||||
|
||||
// PSC addition; local vertex position and the object power scaled world position
|
||||
vs_position = psc_addition(vec4(local_vertex_pos,in_position.w),objpos);
|
||||
|
||||
// PSC addition; rotated and viewscaled vertex and the cmaeras negative position
|
||||
vs_position = psc_addition(vs_position,vec4(-campos.xyz,campos.w));
|
||||
|
||||
// rotate the camera
|
||||
vs_position = camrot * vs_position;
|
||||
|
||||
// rescales the scene to fit inside the view frustum
|
||||
// is set from the main program, but these are decent values
|
||||
//vec2 scaling = vec2(1.0, -8.0);
|
||||
|
||||
// project using the rescaled coordinates,
|
||||
//vec4 vs_position_rescaled = psc_scaling(vs_position, scaling);
|
||||
vec4 vs_position_rescaled = psc_to_meter(vs_position, scaling);
|
||||
|
||||
// project the position to view space
|
||||
gl_Position = ViewProjection * vs_position_rescaled;
|
||||
}
|
||||
12
openspace.cfg
Normal file
12
openspace.cfg
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
paths = {
|
||||
SGCT = "${BASE_PATH}/config/sgct",
|
||||
SCRIPTS = "${BASE_PATH}/scripts",
|
||||
KERNELS = "${BASE_PATH}/kernels",
|
||||
SHADERS = "${BASE_PATH}/shaders",
|
||||
OPENSPACE_DATA = "${BASE_PATH}/openspace-data",
|
||||
TESTDIR = "${BASE_PATH}/src/tests",
|
||||
SCENEPATH = "${OPENSPACE_DATA}/scene"
|
||||
},
|
||||
sgctConfig = "${SGCT}/single.xml",
|
||||
}
|
||||
@@ -83,8 +83,6 @@ include_directories(${HEADER_ROOT_DIR})
|
||||
set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${OPENSPACE_EXT_DIR}/tinythread.cpp)
|
||||
include_directories(${GHOUL_ROOT_DIR}/ext/boost)
|
||||
|
||||
add_definitions(-DBASE_PATH="${CMAKE_SOURCE_DIR}")
|
||||
|
||||
if (APPLE)
|
||||
add_definitions(-D__APPLE__)
|
||||
set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ ${CMAKE_CXX_FLAGS}")
|
||||
|
||||
@@ -38,22 +38,10 @@
|
||||
#include <ghoul/logging/logging>
|
||||
#include <ghoul/misc/configurationmanager.h>
|
||||
#include <ghoul/systemcapabilities/systemcapabilities.h>
|
||||
|
||||
#ifdef __WIN32__
|
||||
// Windows: Binary two folders down
|
||||
#define FIXED_BASE_PATH "../.."
|
||||
#elif __APPLE__
|
||||
// OS X : Binary three folders down
|
||||
#define FIXED_BASE_PATH "../../.."
|
||||
#else
|
||||
// Linux : Binary three folders down
|
||||
#define FIXED_BASE_PATH ".."
|
||||
#endif
|
||||
|
||||
// Check if CMake have provided a base path.
|
||||
#ifndef BASE_PATH
|
||||
#define BASE_PATH FIXED_BASE_PATH
|
||||
#endif
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
#include <ghoul/lua/lua_helper.h>
|
||||
#include <ghoul/cmdparser/commandlineparser.h>
|
||||
#include <ghoul/cmdparser/commandlinecommand.h>
|
||||
|
||||
using namespace ghoul::filesystem;
|
||||
using namespace ghoul::logging;
|
||||
@@ -92,17 +80,115 @@ OpenSpaceEngine& OpenSpaceEngine::ref() {
|
||||
return *_engine;
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::create(int argc, char** argv, int& newArgc, char**& newArgv) {
|
||||
bool OpenSpaceEngine::registerPathsFromDictionary(const ghoul::Dictionary& dictionary) {
|
||||
auto path_keys = dictionary.keys();
|
||||
for(auto key: path_keys) {
|
||||
std::string p;
|
||||
if(dictionary.getValue(key, p)) {
|
||||
std::stringstream ss;
|
||||
ss << "${" << key << "}";
|
||||
LDEBUG(ss.str() << ": " << p);
|
||||
FileSys.registerPathToken(ss.str(), p);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
bool OpenSpaceEngine::registerBasePathFromConfigurationFile(const std::string& filename) {
|
||||
if( ! FileSys.fileExists(filename))
|
||||
return false;
|
||||
|
||||
const std::string absolutePath = FileSys.absolutePath(filename);
|
||||
|
||||
auto last = absolutePath.find_last_of("/");
|
||||
if(last == absolutePath.npos)
|
||||
return false;
|
||||
|
||||
std::string basePath = absolutePath.substr(0, last);
|
||||
|
||||
FileSys.registerPathToken("${BASE_PATH}", basePath);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OpenSpaceEngine::findConfiguration(std::string& filename) {
|
||||
if (filename != "") {
|
||||
return FileSys.fileExists(filename);
|
||||
}
|
||||
std::string currentDirectory = FileSys.currentDirectory();
|
||||
size_t occurrences = std::count(currentDirectory.begin(), currentDirectory.end(), '/');
|
||||
|
||||
std::string cfgname = "openspace.cfg";
|
||||
|
||||
for (int i = 0; i < occurrences; ++i) {
|
||||
if(i > 0) {
|
||||
cfgname = "../" + cfgname;
|
||||
}
|
||||
|
||||
if(FileSys.fileExists(cfgname))
|
||||
break;
|
||||
}
|
||||
if ( ! FileSys.fileExists(cfgname)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
filename = cfgname;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::create(int argc, char** argv, std::vector<std::string>& sgctArguments) {
|
||||
// TODO custom assert (ticket #5)
|
||||
assert(_engine == nullptr);
|
||||
|
||||
// set the arguments for SGCT
|
||||
newArgc = 3;
|
||||
newArgv = new char*[3];
|
||||
newArgv[0] = "prog";
|
||||
newArgv[1] = "-config";
|
||||
newArgv[2] = FIXED_BASE_PATH"/config/single.xml";
|
||||
// initialize ghoul logging
|
||||
LogManager::initialize(LogManager::LogLevel::Debug, true);
|
||||
LogMgr.addLog(new ConsoleLog);
|
||||
|
||||
// TODO change so initialize is not called in the create function
|
||||
ghoul::filesystem::FileSystem::initialize();
|
||||
|
||||
// TODO parse arguments if filename is specified, if not use default
|
||||
std::string configurationFilePath = "";
|
||||
|
||||
LDEBUG("Finding configuration");
|
||||
if( ! OpenSpaceEngine::findConfiguration(configurationFilePath)) {
|
||||
LFATAL("Could not find OpenSpace configuration file!");
|
||||
assert(false);
|
||||
}
|
||||
|
||||
LDEBUG("registering base path");
|
||||
if( ! OpenSpaceEngine::registerBasePathFromConfigurationFile(configurationFilePath)) {
|
||||
LFATAL("Could not register base path");
|
||||
assert(false);
|
||||
}
|
||||
|
||||
// TODO make cleaner interface for configuration loading
|
||||
lua_State* state = luaL_newstate();
|
||||
if (state == nullptr) {
|
||||
LFATAL("Error creating new Lua state: Memory allocation error");
|
||||
assert(false);
|
||||
}
|
||||
luaL_openlibs(state);
|
||||
ghoul::Dictionary configuration;
|
||||
ghoul::lua::lua_loadIntoDictionary(state, &configuration, configurationFilePath, true);
|
||||
if(configuration.hasKey("paths")) {
|
||||
ghoul::Dictionary pathsDictionary;
|
||||
if(configuration.getValue("paths", pathsDictionary)) {
|
||||
OpenSpaceEngine::registerPathsFromDictionary(pathsDictionary);
|
||||
}
|
||||
}
|
||||
lua_close(state);
|
||||
|
||||
std::string sgctConfigurationPath = "${SGCT}/single.xml";
|
||||
if(configuration.hasKey("sgctConfig")) {
|
||||
configuration.getValue("sgctConfig", sgctConfigurationPath);
|
||||
}
|
||||
|
||||
sgctArguments.push_back("OpenSpace");
|
||||
sgctArguments.push_back("-config");
|
||||
sgctArguments.push_back(absPath(sgctConfigurationPath));
|
||||
|
||||
// create objects
|
||||
_engine = new OpenSpaceEngine;
|
||||
_engine->_renderEngine = new RenderEngine;
|
||||
@@ -120,13 +206,8 @@ bool OpenSpaceEngine::isInitialized() {
|
||||
|
||||
bool OpenSpaceEngine::initialize() {
|
||||
|
||||
// initialize ghou logging
|
||||
LogManager::initialize(LogManager::LogLevel::Debug, true);
|
||||
LogMgr.addLog(new ConsoleLog);
|
||||
|
||||
// Register the filepaths from static function enables easy testing
|
||||
ghoul::filesystem::FileSystem::initialize();
|
||||
registerFilePaths();
|
||||
//registerFilePaths();
|
||||
|
||||
// initialize the configurationmanager with the default configuration
|
||||
_configurationManager->initialize();
|
||||
@@ -158,17 +239,6 @@ bool OpenSpaceEngine::initialize() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OpenSpaceEngine::registerFilePaths() {
|
||||
|
||||
FileSys.registerPathToken("${BASE_PATH}", FileSys.relativePath(BASE_PATH));
|
||||
FileSys.registerPathToken("${SCRIPTS}", "${BASE_PATH}/scripts");
|
||||
FileSys.registerPathToken("${OPENSPACE-DATA}", "${BASE_PATH}/openspace-data");
|
||||
FileSys.registerPathToken("${SCENEPATH}", "${OPENSPACE-DATA}/scene");
|
||||
FileSys.registerPathToken("${SHADERS}", "${BASE_PATH}/shaders");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ghoul::ConfigurationManager& OpenSpaceEngine::configurationManager() {
|
||||
// TODO custom assert (ticket #5)
|
||||
assert(_configurationManager != nullptr);
|
||||
|
||||
19
src/main.cpp
19
src/main.cpp
@@ -45,13 +45,26 @@ void mainEncodeFun();
|
||||
void mainDecodeFun();
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int newArgc;
|
||||
char** newArgv;
|
||||
openspace::OpenSpaceEngine::create(argc, argv, newArgc, newArgv);
|
||||
|
||||
// create the OpenSpace engine and get arguments for the sgct engine
|
||||
std::vector<std::string> sgctArguments;
|
||||
openspace::OpenSpaceEngine::create(argc, argv, sgctArguments);
|
||||
|
||||
// create sgct engine c arguments
|
||||
int newArgc = sgctArguments.size();
|
||||
char** newArgv = new char*[newArgc];
|
||||
for (int i = 0; i < newArgc; ++i) {
|
||||
//newArgv[i] = new char[sgctArguments.at(i).length()];
|
||||
//std::strcpy(newArgv[i], sgctArguments.at(i).c_str());
|
||||
newArgv[i] = const_cast<char*>(sgctArguments.at(i).c_str());
|
||||
}
|
||||
|
||||
_sgctEngine = new sgct::Engine(newArgc, newArgv);
|
||||
|
||||
// deallocate sgct c arguments
|
||||
for (int i = 0; i < newArgc; ++i) {
|
||||
//delete newArgv[i];
|
||||
}
|
||||
delete[] newArgv;
|
||||
|
||||
// Bind functions
|
||||
|
||||
@@ -35,19 +35,50 @@
|
||||
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
#include <iostream>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
|
||||
using namespace ghoul::cmdparser;
|
||||
using namespace ghoul::filesystem;
|
||||
using namespace ghoul::logging;
|
||||
|
||||
namespace {
|
||||
std::string _loggerCat = "OpenSpaceTest";
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
LogManager::initialize(LogManager::LogLevel::None);
|
||||
LogMgr.addLog(new ConsoleLog);
|
||||
|
||||
FileSystem::initialize();
|
||||
std::string configurationFilePath = "";
|
||||
LDEBUG("Finding configuration");
|
||||
if( ! openspace::OpenSpaceEngine::findConfiguration(configurationFilePath)) {
|
||||
LFATAL("Could not find OpenSpace configuration file!");
|
||||
assert(false);
|
||||
}
|
||||
|
||||
openspace::OpenSpaceEngine::registerFilePaths();
|
||||
FileSys.registerPathToken("${TESTDIR}", "${BASE_PATH}/src/tests");
|
||||
LDEBUG("registering base path");
|
||||
if( ! openspace::OpenSpaceEngine::registerBasePathFromConfigurationFile(configurationFilePath)) {
|
||||
LFATAL("Could not register base path");
|
||||
assert(false);
|
||||
}
|
||||
|
||||
lua_State* state = luaL_newstate();
|
||||
if (state == nullptr) {
|
||||
LFATAL("Error creating new Lua state: Memory allocation error");
|
||||
assert(false);
|
||||
}
|
||||
luaL_openlibs(state);
|
||||
ghoul::Dictionary configuration;
|
||||
ghoul::lua::lua_loadIntoDictionary(state, &configuration, configurationFilePath, true);
|
||||
if(configuration.hasKey("paths")) {
|
||||
ghoul::Dictionary pathsDictionary;
|
||||
if(configuration.getValue("paths", pathsDictionary)) {
|
||||
openspace::OpenSpaceEngine::registerPathsFromDictionary(pathsDictionary);
|
||||
}
|
||||
}
|
||||
lua_close(state);
|
||||
|
||||
openspace::Time::init();
|
||||
openspace::Spice::init();
|
||||
|
||||
@@ -68,7 +68,7 @@ void Spice::loadDefaultKernels() {
|
||||
assert(this_);
|
||||
|
||||
// load
|
||||
loadKernel(absPath("${OPENSPACE-DATA}/spice/de430_1850-2150.bsp"));
|
||||
loadKernel(absPath("${OPENSPACE_DATA}/spice/de430_1850-2150.bsp"));
|
||||
//Summary for: de430_1850-2150.bsp
|
||||
//Bodies: MERCURY BARYCENTER (1) SATURN BARYCENTER (6) MERCURY (199)
|
||||
// VENUS BARYCENTER (2) URANUS BARYCENTER (7) VENUS (299)
|
||||
@@ -79,7 +79,7 @@ void Spice::loadDefaultKernels() {
|
||||
// ----------------------------- -----------------------------
|
||||
// 1849 DEC 26 00:00:00.000 2150 JAN 22 00:00:00.000
|
||||
|
||||
loadKernel(absPath("${OPENSPACE-DATA}/spice/pck00010.tpc"));
|
||||
loadKernel(absPath("${OPENSPACE_DATA}/spice/pck00010.tpc"));
|
||||
}
|
||||
|
||||
bool Spice::loadKernel(const std::string &path) {
|
||||
|
||||
@@ -18,7 +18,7 @@ Time::Time() {
|
||||
time_ = 0.0;
|
||||
|
||||
// load spice time kernel
|
||||
furnsh_c (absPath("${OPENSPACE-DATA}/spice/naif0010.tls").c_str());
|
||||
furnsh_c (absPath("${OPENSPACE_DATA}/spice/naif0010.tls").c_str());
|
||||
|
||||
// convert UTC to ET
|
||||
str2et_c ( "2006 JAN 31 01:00", &time_ );
|
||||
|
||||
Reference in New Issue
Block a user