Merge remote-tracking branch 'origin/master' into feature/launcherconfigs

# Conflicts:
#	ext/sgct
#	openspace.cfg
This commit is contained in:
Matthew Territo
2017-05-12 15:40:06 -06:00
663 changed files with 19692 additions and 12831 deletions
-41
View File
@@ -1,41 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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. *
****************************************************************************************/
#ifndef __OPENSPACE_APP_DATACONVERTER___CONVERSIONTASK___H__
#define __OPENSPACE_APP_DATACONVERTER___CONVERSIONTASK___H__
#include <functional>
namespace openspace {
namespace dataconverter {
class ConversionTask {
public:
virtual void perform(const std::function<void(float)>& onProgress) = 0;
};
} // namespace dataconverter
} // namespace openspace
#endif // __OPENSPACE_APP_DATACONVERTER___CONVERSIONTASK___H__
@@ -1,74 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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. *
****************************************************************************************/
#include <apps/DataConverter/milkywayconversiontask.h>
#include <modules/volume/textureslicevolumereader.h>
#include <modules/volume/rawvolumewriter.h>
#include <modules/volume/volumesampler.h>
namespace openspace {
namespace dataconverter {
MilkyWayConversionTask::MilkyWayConversionTask(
const std::string& inFilenamePrefix,
const std::string& inFilenameSuffix,
size_t inFirstIndex,
size_t inNSlices,
const std::string& outFilename,
const glm::ivec3& outDimensions)
: _inFilenamePrefix(inFilenamePrefix)
, _inFilenameSuffix(inFilenameSuffix)
, _inFirstIndex(inFirstIndex)
, _inNSlices(inNSlices)
, _outFilename(outFilename)
, _outDimensions(outDimensions) {}
void MilkyWayConversionTask::perform(const std::function<void(float)>& onProgress) {
std::vector<std::string> filenames;
for (int i = 0; i < _inNSlices; i++) {
filenames.push_back(_inFilenamePrefix + std::to_string(i + _inFirstIndex) + _inFilenameSuffix);
}
TextureSliceVolumeReader<glm::tvec4<GLfloat>> sliceReader(filenames, _inNSlices, 10);
sliceReader.initialize();
RawVolumeWriter<glm::tvec4<GLfloat>> rawWriter(_outFilename);
rawWriter.setDimensions(_outDimensions);
glm::vec3 resolutionRatio =
static_cast<glm::vec3>(sliceReader.dimensions()) / static_cast<glm::vec3>(rawWriter.dimensions());
VolumeSampler<TextureSliceVolumeReader<glm::tvec4<GLfloat>>> sampler(sliceReader, resolutionRatio);
std::function<glm::tvec4<GLfloat>(glm::ivec3)> sampleFunction = [&](glm::ivec3 outCoord) {
glm::vec3 inCoord = ((glm::vec3(outCoord) + glm::vec3(0.5)) * resolutionRatio) - glm::vec3(0.5);
glm::tvec4<GLfloat> value = sampler.sample(inCoord);
return value;
};
rawWriter.write(sampleFunction, onProgress);
}
}
}
@@ -1,65 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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. *
****************************************************************************************/
#ifndef __OPENSPACE_APP_DATACONVERTER___MILKYWAYCONVERSIONTASK___H__
#define __OPENSPACE_APP_DATACONVERTER___MILKYWAYCONVERSIONTASK___H__
#include <apps/DataConverter/conversiontask.h>
#include <string>
#include <ghoul/glm.h>
#include <functional>
#include <modules/volume/textureslicevolumereader.h>
#include <modules/volume/rawvolumewriter.h>
namespace openspace {
namespace dataconverter {
/**
* Converts a set of exr image slices to a raw volume
* with floating point RGBA data (32 bit per channel).
*/
class MilkyWayConversionTask : public ConversionTask {
public:
MilkyWayConversionTask(const std::string& inFilenamePrefix,
const std::string& inFilenameSuffix,
size_t inFirstIndex,
size_t inNSlices,
const std::string& outFilename,
const glm::ivec3& outDimensions);
void perform(const std::function<void(float)>& onProgress) override;
private:
std::string _inFilenamePrefix;
std::string _inFilenameSuffix;
size_t _inFirstIndex;
size_t _inNSlices;
std::string _outFilename;
glm::ivec3 _outDimensions;
};
} // namespace dataconverter
} // namespace openspace
#endif // __OPENSPACE_APP_DATACONVERTER___MILKYWAYCONVERSIONTASK___H__
@@ -1,86 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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. *
****************************************************************************************/
#include <apps/DataConverter/milkywaypointsconversiontask.h>
#include <modules/volume/textureslicevolumereader.h>
#include <modules/volume/rawvolumewriter.h>
#include <modules/volume/volumesampler.h>
#include <fstream>
#include <iostream>
namespace openspace {
namespace dataconverter {
MilkyWayPointsConversionTask::MilkyWayPointsConversionTask(
const std::string& inFilename,
const std::string& outFilename)
: _inFilename(inFilename)
, _outFilename(outFilename) {}
void MilkyWayPointsConversionTask::perform(const std::function<void(float)>& onProgress) {
std::ifstream in(_inFilename, std::ios::in);
std::ofstream out(_outFilename, std::ios::out | std::ios::binary);
std::string format;
int64_t nPoints;
in >> format >> nPoints;
size_t nFloats = nPoints * 7;
float* pointData = new float[nFloats];
float x, y, z, r, g, b, a;
for (size_t i = 0; i < nPoints; ++i) {
in >> x >> y >> z >> r >> g >> b >> a;
if (in.good()) {
pointData[i * 7 + 0] = x;
pointData[i * 7 + 1] = y;
pointData[i * 7 + 2] = z;
pointData[i * 7 + 3] = r;
pointData[i * 7 + 4] = g;
pointData[i * 7 + 5] = b;
pointData[i * 7 + 6] = a;
onProgress(static_cast<float>(i + 1) / nPoints);
} else {
std::cout << "Failed to convert point data.";
return;
}
}
out.write(reinterpret_cast<char*>(&nPoints), sizeof(int64_t));
out.write(reinterpret_cast<char*>(pointData), nFloats * sizeof(float));
in.close();
out.close();
}
}
}
@@ -1,59 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* 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. *
****************************************************************************************/
#ifndef __OPENSPACE_APP_DATACONVERTER___MILKYWAYPOINTSCONVERSIONTASK___H__
#define __OPENSPACE_APP_DATACONVERTER___MILKYWAYPOINTSCONVERSIONTASK___H__
#include <apps/DataConverter/conversiontask.h>
#include <string>
#include <ghoul/glm.h>
#include <functional>
#include <modules/volume/textureslicevolumereader.h>
#include <modules/volume/rawvolumewriter.h>
namespace openspace {
namespace dataconverter {
/**
* Converts ascii based point data
* int64_t n
* (float x, float y, float z, float r, float g, float b) * n
* to a binary (floating point) representation with the same layout.
*/
class MilkyWayPointsConversionTask : public ConversionTask {
public:
MilkyWayPointsConversionTask(const std::string& inFilename,
const std::string& outFilename);
void perform(const std::function<void(float)>& onProgress) override;
private:
std::string _inFilename;
std::string _outFilename;
};
} // namespace dataconverter
} // namespace openspace
#endif // __OPENSPACE_APP_DATACONVERTER___MILKYWAYPOINTSCONVERSIONTASK___H__
+112 -26
View File
@@ -1,26 +1,28 @@
#########################################################################################
# #
# OpenSpace #
# #
# Copyright (c) 2014-2015 #
# #
# 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. #
#########################################################################################
##########################################################################################
# #
# OpenSpace #
# #
# Copyright (c) 2014-2017 #
# #
# 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. #
##########################################################################################
include(${GHOUL_BASE_DIR}/support/cmake/CopySharedLibraries.cmake)
set(APPLICATION_NAME OpenSpace)
set(APPLICATION_LINK_TO_OPENSPACE ON)
@@ -29,15 +31,99 @@ if (WIN32)
set(RESOURCE_FILE ${OPENSPACE_APPS_DIR}/OpenSpace/openspace.rc)
endif ()
########################
# OpenVR section start #
########################
option(OPENSPACE_OPENVR_SUPPORT "Build OpenSpace application with OpenVR support" OFF)
if (OPENSPACE_OPENVR_SUPPORT)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${OPENSPACE_EXT_DIR}/sgct/cmake/modules/")
find_package(OpenVR REQUIRED)
set(SGCT_OPENVR_DEFINITIONS OPENVR_SUPPORT)
if(NOT SGCT_OPENVR_INCLUDE_DIRECTORY)
if( WIN32 )
find_path(SGCT_OPENVR_INCLUDE_DIRECTORY
NAMES SGCTOpenVR.h
PATHS $ENV{SGCT_ROOT_DIR}/additional_includes/openvr ${OPENSPACE_EXT_DIR}/sgct/additional_includes/openvr NO_DEFAULT_PATH
REQUIRED)
else()
find_path(SGCT_OPENVR_INCLUDE_DIRECTORY
NAMES SGCTOpenVR.h
PATH_SUFFIXES SGCTOpenVR
PATHS $ENV{SGCT_ROOT_DIR}/additional_includes/openvr ${OPENSPACE_EXT_DIR}/sgct/additional_includes/openvr
REQUIRED)
endif()
else()
set(SGCT_OPENVR_FILES ${SGCT_OPENVR_INCLUDE_DIRECTORY}/SGCTOpenVR.h ${SGCT_OPENVR_INCLUDE_DIRECTORY}/SGCTOpenVR.cpp)
endif()
else()
set(OPENVR_INCLUDE_DIRS "")
set(SGCT_OPENVR_INCLUDE_DIRECTORY "")
set(OPENVR_LIBRARY "")
set(SGCT_OPENVR_DEFINITIONS "")
endif()
########################
# OpenVR section end #
########################
########################
# Spout section start #
########################
if (WIN32)
option(OPENSPACE_SPOUT_SUPPORT "Build OpenSpace application with Spout support" OFF)
endif ()
set(SPOUT_INCLUDE_DIRS "")
set(SPOUT_LIBRARY "")
set(SPOUT_DEFINITIONS "")
if (OPENSPACE_SPOUT_SUPPORT)
set(SPOUT_INCLUDE_DIRS ${OPENSPACE_APPS_DIR}/OpenSpace/ext/spout)
set(SPOUT_LIBRARY ${OPENSPACE_APPS_DIR}/OpenSpace/ext/spout/SpoutLibrary.lib)
set(SPOUT_DEFINITIONS "OPENSPACE_HAS_SPOUT")
endif ()
########################
# Spout section end #
########################
add_executable(${APPLICATION_NAME}
${SGCT_OPENVR_FILES}
${OPENSPACE_APPS_DIR}/OpenSpace/main.cpp
${RESOURCE_FILE}
)
target_include_directories(${APPLICATION_NAME} PUBLIC ${OPENSPACE_BASE_DIR}/include)
target_link_libraries(${APPLICATION_NAME} libOpenSpace)
if (OPENSPACE_SPOUT_SUPPORT)
copy_files(
${APPLICATION_NAME}
${OPENSPACE_APPS_DIR}/OpenSpace/ext/spout/SpoutLibrary.dll
)
endif ()
target_include_directories(
${APPLICATION_NAME} PUBLIC
${OPENSPACE_BASE_DIR}/include
${OPENVR_INCLUDE_DIRS}
${SGCT_OPENVR_INCLUDE_DIRECTORY}
${SPOUT_INCLUDE_DIRS}
)
target_link_libraries(${APPLICATION_NAME}
libOpenSpace
${OPENVR_LIBRARY}
${SPOUT_LIBRARY}
)
target_compile_definitions(${APPLICATION_NAME} PUBLIC
${SGCT_OPENVR_DEFINITIONS}
${SPOUT_DEFINITIONS}
)
if (MSVC)
target_link_libraries(${APPLICATION_NAME} Dbghelp.lib)
set_target_properties(${APPLICATION_NAME} PROPERTIES LINK_FLAGS
"/NODEFAULTLIB:LIBCMTD.lib /NODEFAULTLIB:LIBCMT.lib"
)
endif ()
endif()
+8
View File
@@ -0,0 +1,8 @@
The spout folder is a copy of the folder:
SpoutSDK/Source in the repository:
https://github.com/leadedge/Spout2.git/SpoutSDK/Source/SPOUT_LIBRARY/Binaries
and
https://github.com/leadedge/Spout2.git/SpoutSDK/Source/SPOUT_LIBRARY/Include
Last update:
https://github.com/leadedge/Spout2/commit/28dbea6059cd7968c4d2b296d6739a5fdebe9104
Binary file not shown.
+90
View File
@@ -0,0 +1,90 @@
//
// SpoutLibrary.dll
//
// Spout SDK dll compatible with any C++ compiler
//
#include <windows.h>
#include <GL/GL.h>
#define SPOUTLIBRARY_EXPORTS // defined for this DLL. The application imports rather than exports
#ifdef SPOUTLIBRARY_EXPORTS
#define SPOUTAPI __declspec(dllexport)
#else
#define SPOUTAPI __declspec(dllimport)
#endif
////////////////////////////////////////////////////////////////////////////////
//
// COM-Like abstract interface.
// This interface doesn't require __declspec(dllexport/dllimport) specifier.
// Method calls are dispatched via virtual table.
// Any C++ compiler can use it.
// Instances are obtained via factory function.
//
struct SPOUTLIBRARY
{
// Sender
virtual bool CreateSender(const char *Sendername, unsigned int width, unsigned int height, DWORD dwFormat = 0) = 0;
virtual void ReleaseSender(DWORD dwMsec = 0) = 0;
virtual bool UpdateSender(const char* Sendername, unsigned int width, unsigned int height) = 0;
virtual bool SendTexture(GLuint TextureID, GLuint TextureTarget, unsigned int width, unsigned int height, bool bInvert = true, GLuint HostFBO = 0) = 0;
virtual bool SendImage(const unsigned char* pixels, unsigned int width, unsigned int height, GLenum glFormat = GL_RGBA, bool bInvert=false) = 0;
// Receiver
virtual bool CreateReceiver(char* Sendername, unsigned int &width, unsigned int &height, bool bUseActive = false) = 0;
virtual void ReleaseReceiver() = 0;
virtual bool ReceiveTexture(char* Sendername, unsigned int &width, unsigned int &height, GLuint TextureID = 0, GLuint TextureTarget = 0, bool bInvert = false, GLuint HostFBO = 0) = 0;
virtual bool ReceiveImage(char* Sendername, unsigned int &width, unsigned int &height, unsigned char* pixels, GLenum glFormat = GL_RGBA, bool bInvert = false, GLuint HostFBO=0) = 0;
virtual bool CheckReceiver(char* Sendername, unsigned int &width, unsigned int &height, bool &bConnected) = 0;
virtual bool GetImageSize(char* sendername, unsigned int &width, unsigned int &height, bool &bMemoryMode) = 0;
virtual bool BindSharedTexture() = 0;
virtual bool UnBindSharedTexture() = 0;
virtual bool DrawSharedTexture(float max_x = 1.0, float max_y = 1.0, float aspect = 1.0, bool bInvert = true) = 0;
virtual bool DrawToSharedTexture(GLuint TextureID, GLuint TextureTarget, unsigned int width, unsigned int height, float max_x = 1.0, float max_y = 1.0, float aspect = 1.0, bool bInvert = false, GLuint HostFBO = 0) = 0;
virtual int GetSenderCount() = 0;
virtual bool GetSenderName(int index, char* sendername, int MaxSize = 256) = 0;
virtual bool GetSenderInfo(const char* sendername, unsigned int &width, unsigned int &height, HANDLE &dxShareHandle, DWORD &dwFormat) = 0;
virtual bool GetActiveSender(char* Sendername) = 0;
virtual bool SetActiveSender(const char* Sendername) = 0;
// Utilities
virtual bool SetDX9(bool bDX9 = true) = 0; // User request to use DirectX 9 (default is DirectX 11)
virtual bool GetDX9() = 0; // Return the flag that has been set
virtual bool SetMemoryShareMode(bool bMem = true) = 0;
virtual bool GetMemoryShareMode() = 0;
virtual int GetMaxSenders() = 0; // Get maximum senders allowed
virtual void SetMaxSenders(int maxSenders) = 0; // Set maximum senders allowed
virtual bool GetHostPath(const char *sendername, char *hostpath, int maxchars) = 0; // The path of the host that produced the sender
virtual int GetVerticalSync() = 0;
virtual bool SetVerticalSync(bool bSync = true) = 0;
virtual bool SelectSenderPanel(const char* message = NULL) = 0;
// Access to globals
virtual bool GetSpoutSenderName(char * sendername, int maxchars) = 0; // get the global sender name
virtual bool IsSpoutInitialized() = 0; // has the class been initialized
// Adapter functions
virtual int GetNumAdapters() = 0; // Get the number of graphics adapters in the system
virtual bool GetAdapterName(int index, char *adaptername, int maxchars) = 0; // Get an adapter name
virtual bool SetAdapter(int index = 0) = 0; // Set required graphics adapter for output
virtual int GetAdapter() = 0; // Get the SpoutDirectX global adapter index
// Library release function
virtual void Release() = 0;
};
// Handle type. In C++ language the interface type is used.
typedef SPOUTLIBRARY* SPOUTHANDLE;
// Factory function that creates instances of the SPOUT object.
extern "C" SPOUTAPI SPOUTHANDLE WINAPI GetSpout(VOID);
////////////////////////////////////////////////////////////////////////////////
Binary file not shown.
+492 -214
View File
@@ -25,33 +25,151 @@
#include <openspace/engine/openspaceengine.h>
#include <openspace/engine/wrapper/sgctwindowwrapper.h>
#include <openspace/util/keys.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/assert.h>
#include <ghoul/opengl/ghoul_gl.h>
#include <sgct.h>
#include <chrono>
#include <thread>
sgct::Engine* _sgctEngine;
#ifdef WIN32
#include <openspace/openspace.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/misc/stacktrace.h>
#include <fmt/format.h>
#include <Windows.h>
#include <dbghelp.h>
#include <shellapi.h>
#include <shlobj.h>
#endif // WIN32
#ifdef OPENVR_SUPPORT
#include <SGCTOpenVR.h>
#endif // OPENVR_SUPPORT
#ifdef OPENSPACE_HAS_SPOUT
#include "SpoutLibrary.h"
#endif // OPENSPACE_HAS_SPOUT
#define DEVELOPER_MODE
namespace {
const char* _loggerCat = "main";
sgct::Engine* SgctEngine;
const char* OpenVRTag = "OpenVR";
const char* SpoutTag = "Spout";
#ifdef WIN32
LONG WINAPI generateMiniDump(EXCEPTION_POINTERS* exceptionPointers) {
SYSTEMTIME stLocalTime;
GetLocalTime(&stLocalTime);
LFATAL("Printing Stack Trace that lead to the crash:");
std::vector<std::string> stackTrace = ghoul::stackTrace();
for (const std::string& s : stackTrace) {
LINFO(s);
}
std::string dumpFile = fmt::format(
"OpenSpace_{}_{}_{}-{}-{}-{}-{}-{}-{}--{}--{}.dmp",
openspace::OPENSPACE_VERSION_MAJOR,
openspace::OPENSPACE_VERSION_MINOR,
openspace::OPENSPACE_VERSION_PATCH,
stLocalTime.wYear,
stLocalTime.wMonth,
stLocalTime.wDay,
stLocalTime.wHour,
stLocalTime.wMinute,
stLocalTime.wSecond,
GetCurrentProcessId(),
GetCurrentThreadId()
);
LINFO("Creating dump file: " << dumpFile);
HANDLE hDumpFile = CreateFile(
dumpFile.c_str(),
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_WRITE | FILE_SHARE_READ,
0,
CREATE_ALWAYS,
0,
0
);
MINIDUMP_EXCEPTION_INFORMATION exceptionParameter;
exceptionParameter.ThreadId = GetCurrentThreadId();
exceptionParameter.ExceptionPointers = exceptionPointers;
exceptionParameter.ClientPointers = TRUE;
BOOL success = MiniDumpWriteDump(
GetCurrentProcess(),
GetCurrentProcessId(),
hDumpFile,
MiniDumpWithDataSegs,
&exceptionParameter,
nullptr,
nullptr
);
if (success) {
LINFO("Created successfully");
}
else {
LERROR("Dumpfile created unsuccessfully");
}
return EXCEPTION_EXECUTE_HANDLER;
}
#endif // WIN32
#ifdef OPENVR_SUPPORT
sgct::SGCTWindow* FirstOpenVRWindow = nullptr;
#endif
#ifdef OPENSPACE_HAS_SPOUT
/**
* This struct stores all information about a single render window. Depending on the
* frame setup, each window can be mono or stereo, the information of which is stored in
* the \c leftOrMain and \c right members respectively.
*/
struct SpoutWindow {
struct SpoutData {
SPOUTHANDLE handle = nullptr;
bool initialized = false;
};
/// The left framebuffer (or main, if there is no stereo rendering)
SpoutData leftOrMain;
/// The right framebuffer
SpoutData right;
/// The window ID of this windows
size_t windowId = size_t(-1);
};
/// The list of all windows with spout senders
std::vector<SpoutWindow> SpoutWindows;
#endif // OPENSPACE_HAS_SPOUT
int main_main(int argc, char** argv);
void mainInitFunc();
void mainPreSyncFunc();
void mainPostSyncPreDrawFunc();
void mainRenderFunc();
void mainPostDrawFunc();
void mainKeyboardCallback(int key, int scancode, int action, int mods);
void mainCharCallback(unsigned int codepoint, int mods);
void mainMouseButtonCallback(int key, int action);
void mainMousePosCallback(double x, double y);
void mainMouseScrollCallback(double posX, double posY);
void mainEncodeFun();
void mainDecodeFun();
void mainExternalControlCallback(const char * receivedChars, int size);
void mainLogCallback(const char* msg);
std::pair<int, int> supportedOpenGLVersion() {
// Just create a window in order to retrieve the available OpenGL version before we
// create the real window
glfwInit();
// On OS X we need to explicitly set the version and specify that we are using CORE
@@ -66,185 +184,124 @@ std::pair<int, int> supportedOpenGLVersion() {
#endif
glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
// By creating an offscreen window, the user will not know that we created this window
GLFWwindow* offscreen = glfwCreateWindow(128, 128, "", nullptr, nullptr);
glfwMakeContextCurrent(offscreen);
// Get the OpenGL version
int major, minor;
glGetIntegerv(GL_MAJOR_VERSION, &major);
glGetIntegerv(GL_MINOR_VERSION, &minor);
// And get rid of the window again
glfwDestroyWindow(offscreen);
glfwWindowHint(GLFW_VISIBLE, GL_TRUE);
return { major, minor };
}
namespace {
const std::string _loggerCat = "main";
}
int main(int argc, char** argv) {
try {
return main_main(argc, argv);
}
catch (const ghoul::RuntimeError& e) {
// Write out all of the information about the exception, flush the logs, and throw
LFATALC(e.component, e.message);
LogMgr.flushLogs();
throw;
}
catch (const std::exception& e) {
// Write out all of the information about the exception, flush the logs, and throw
LFATALC("Exception", e.what());
LogMgr.flushLogs();
throw;
}
catch (...) {
// Write out all of the information about the exception, flush the logs, and throw
LFATALC("Exception", "Unknown exception");
LogMgr.flushLogs();
throw;
}
}
int main_main(int argc, char** argv) {
auto glVersion = supportedOpenGLVersion();
// create the OpenSpace engine and get arguments for the sgct engine
std::vector<std::string> sgctArguments;
const bool success = openspace::OpenSpaceEngine::create(
argc, argv,
std::make_unique<openspace::SGCTWindowWrapper>(),
sgctArguments
);
if (!success)
return EXIT_FAILURE;
LINFO("Detected OpenGL version: " << glVersion.first << "." << glVersion.second);
// create sgct engine c arguments
int newArgc = static_cast<int>(sgctArguments.size());
char** newArgv = new char*[newArgc];
for (int i = 0; i < newArgc; ++i) {
newArgv[i] = const_cast<char*>(sgctArguments.at(i).c_str());
}
// Need to set this before the creation of the sgct::Engine
sgct::MessageHandler::instance()->setLogToConsole(false);
sgct::MessageHandler::instance()->setShowTime(false);
sgct::MessageHandler::instance()->setLogToCallback(true);
sgct::MessageHandler::instance()->setLogCallback(mainLogCallback);
#ifdef __APPLE__
glfwWindowHint(GLFW_STENCIL_BITS, 8);
#endif
LDEBUG("Creating SGCT Engine");
_sgctEngine = new sgct::Engine(newArgc, newArgv);
// deallocate sgct c arguments
delete[] newArgv;
// Bind functions
_sgctEngine->setInitOGLFunction(mainInitFunc);
_sgctEngine->setPreSyncFunction(mainPreSyncFunc);
_sgctEngine->setPostSyncPreDrawFunction(mainPostSyncPreDrawFunc);
_sgctEngine->setDrawFunction(mainRenderFunc);
_sgctEngine->setPostDrawFunction(mainPostDrawFunc);
_sgctEngine->setKeyboardCallbackFunction(mainKeyboardCallback);
_sgctEngine->setMouseButtonCallbackFunction(mainMouseButtonCallback);
_sgctEngine->setMousePosCallbackFunction(mainMousePosCallback);
_sgctEngine->setMouseScrollCallbackFunction(mainMouseScrollCallback);
_sgctEngine->setExternalControlCallback(mainExternalControlCallback);
_sgctEngine->setCharCallbackFunction(mainCharCallback);
// Disable the immediate exit of the application when the ESC key is pressed
_sgctEngine->setExitKey(SGCT_KEY_UNKNOWN);
sgct::MessageHandler::instance()->setNotifyLevel(sgct::MessageHandler::NOTIFY_ALL);
// set encode and decode functions
// NOTE: starts synchronizing before init functions
sgct::SharedData::instance()->setEncodeFunction(mainEncodeFun);
sgct::SharedData::instance()->setDecodeFunction(mainDecodeFun);
// try to open a window
LDEBUG("Initialize SGCT Engine");
std::map<std::pair<int, int>, sgct::Engine::RunMode> versionMapping = {
{ { 3, 3 }, sgct::Engine::RunMode::OpenGL_3_3_Core_Profile },
{ { 4, 0 }, sgct::Engine::RunMode::OpenGL_4_0_Core_Profile },
{ { 4, 1 }, sgct::Engine::RunMode::OpenGL_4_1_Core_Profile },
{ { 4, 2 }, sgct::Engine::RunMode::OpenGL_4_2_Core_Profile },
{ { 4, 3 }, sgct::Engine::RunMode::OpenGL_4_3_Core_Profile },
{ { 4, 4 }, sgct::Engine::RunMode::OpenGL_4_4_Core_Profile },
{ { 4, 5 }, sgct::Engine::RunMode::OpenGL_4_5_Core_Profile }
};
ghoul_assert(
versionMapping.find(glVersion) != versionMapping.end(),
"Unknown OpenGL version. Missing statement in version mapping map"
);
sgct::Engine::RunMode rm = versionMapping[glVersion];
const bool initSuccess = _sgctEngine->init(rm);
if (!initSuccess) {
LFATAL("Initializing failed");
// could not open a window, deallocates and exits
delete _sgctEngine;
openspace::OpenSpaceEngine::destroy();
return EXIT_FAILURE;
}
// Main loop
LDEBUG("Starting rendering loop");
_sgctEngine->render();
LDEBUG("Ending rendering loop");
//clear function bindings to avoid crash after destroying the OpenSpace Engine
sgct::MessageHandler::instance()->setLogToCallback(false);
sgct::MessageHandler::instance()->setLogCallback(nullptr);
LDEBUG("Destroying OpenSpaceEngine");
openspace::OpenSpaceEngine::destroy();
// Clean up (deallocate)
LDEBUG("Destroying SGCT Engine");
delete _sgctEngine;
// Exit program
exit(EXIT_SUCCESS);
}
void mainInitFunc() {
LTRACE("main::mainInitFunc(begin)");
//is this node the master? (must be set after call to _sgctEngine->init())
OsEng.setMaster(_sgctEngine->isMaster());
LDEBUG("Initializing OpenSpace Engine");
bool success = OsEng.initialize();
LDEBUG("Initializing OpenGL in OpenSpace Engine");
if (success) {
success = OsEng.initializeGL();
LDEBUG("Initializing OpenSpace Engine started");
OsEng.initialize();
LDEBUG("Initializing OpenSpace Engine finished");
LDEBUG("Initializing OpenGL in OpenSpace Engine started");
OsEng.initializeGL();
LDEBUG("Initializing OpenGL in OpenSpace Engine finished");
// Find if we have at least one OpenVR window
// Save reference to first OpenVR window, which is the one we will copy to the HMD.
for (size_t i = 0; i < SgctEngine->getNumberOfWindows(); ++i) {
if (SgctEngine->getWindowPtr(i)->checkIfTagExists(OpenVRTag)) {
#ifdef OPENVR_SUPPORT
FirstOpenVRWindow = SgctEngine->getWindowPtr(i);
// If we have an OpenVRWindow, initialize OpenVR.
sgct::SGCTOpenVR::initialize(
SgctEngine->getNearClippingPlane(), SgctEngine->getFarClippingPlane()
);
#else
LWARNING(
"OpenVR was requested, but OpenSpace was compiled without VR support."
);
#endif
break;
}
}
if (!success) {
LFATAL("Initializing OpenSpaceEngine failed");
LogMgr.flushLogs();
exit(EXIT_FAILURE);
}
// Set the clear color for all non-linear projection viewports
size_t nWindows = _sgctEngine->getNumberOfWindows();
// @CLEANUP: Why is this necessary? We can set the clear color in the configuration
// files --- abock
const size_t nWindows = SgctEngine->getNumberOfWindows();
for (size_t i = 0; i < nWindows; ++i) {
sgct::SGCTWindow* w = _sgctEngine->getWindowPtr(i);
size_t nViewports = w->getNumberOfViewports();
sgct::SGCTWindow* w = SgctEngine->getWindowPtr(i);
const size_t nViewports = w->getNumberOfViewports();
for (size_t j = 0; j < nViewports; ++j) {
sgct_core::Viewport* v = w->getViewport(j);
ghoul_assert(v != nullptr, "Number of reported viewports was incorrect");
sgct_core::NonLinearProjection* p = v->getNonLinearProjectionPtr();
if (p)
if (p) {
p->setClearColor(glm::vec4(0.f, 0.f, 0.f, 1.f));
}
}
}
for (size_t i = 0; i < nWindows; ++i) {
const sgct::SGCTWindow* windowPtr = SgctEngine->getWindowPtr(i);
if (!windowPtr->checkIfTagExists(SpoutTag)) {
continue;
}
#ifdef OPENSPACE_HAS_SPOUT
SpoutWindow w;
w.windowId = i;
const sgct::SGCTWindow::StereoMode sm = windowPtr->getStereoMode();
const bool hasStereo =
(sm != sgct::SGCTWindow::No_Stereo) &&
(sm < sgct::SGCTWindow::Side_By_Side_Stereo);
if (hasStereo) {
SpoutWindow::SpoutData& left = w.leftOrMain;
left.handle = GetSpout();
left.initialized = left.handle->CreateSender(
(windowPtr->getName() + "_left").c_str(),
windowPtr->getXFramebufferResolution(),
windowPtr->getYFramebufferResolution()
);
SpoutWindow::SpoutData& right = w.right;
right.handle = GetSpout();
right.initialized = right.handle->CreateSender(
(windowPtr->getName() + "_right").c_str(),
windowPtr->getXFramebufferResolution(),
windowPtr->getYFramebufferResolution()
);
}
else {
SpoutWindow::SpoutData& main = w.leftOrMain;
main.handle = GetSpout();
main.initialized = main.handle->CreateSender(
windowPtr->getName().c_str(),
windowPtr->getXFramebufferResolution(),
windowPtr->getYFramebufferResolution()
);
}
SpoutWindows.push_back(std::move(w));
#else
LWARNING(
"Spout was requested, but OpenSpace was compiled without Spout support."
);
#endif // OPENSPACE_HAS_SPOUT
}
LTRACE("main::mainInitFunc(end)");
}
@@ -255,59 +312,96 @@ void mainPreSyncFunc() {
LTRACE("main::mainPreSyncFunc(end)");
}
volatile bool busyWaitDecode = false;
void mainPostSyncPreDrawFunc() {
// if (OsEng.useBusyWaitForDecode() && !sgct::Engine::instance()->isMaster()) {
// while (minilog.str().size() && minilog.str().back() != DECODE.end) {
// std::this_thread::sleep_for(std::chrono::microseconds(10));
// }
// }
LTRACE("main::postSynchronizationPreDraw(begin)");
OsEng.postSynchronizationPreDraw();
#ifdef OPENVR_SUPPORT
if (FirstOpenVRWindow) {
// Update pose matrices for all tracked OpenVR devices once per frame
sgct::SGCTOpenVR::updatePoses();
}
#endif // OPENVR_SUPPORT
LTRACE("main::postSynchronizationPreDraw(end)");
}
void mainRenderFunc() {
LTRACE("main::mainRenderFunc(begin)");
using glm::mat4;
using glm::translate;
//not the most efficient, but for clarity @JK
mat4 userMatrix = translate(mat4(1.f), _sgctEngine->getDefaultUserPtr()->getPos());
mat4 sceneMatrix = _sgctEngine->getModelMatrix();
mat4 viewMatrix = _sgctEngine->getCurrentViewMatrix() * userMatrix;
glm::mat4 viewMatrix =
SgctEngine->getCurrentViewMatrix() *
// User matrix
glm::translate(
glm::mat4(1.f),
SgctEngine->getDefaultUserPtr()->getPos()
)
;
//dont shift nav-direction on master, makes it very tricky to navigate @JK
if (!OsEng.ref().isMaster())
viewMatrix = viewMatrix * sceneMatrix;
glm::mat4 projectionMatrix = SgctEngine->getCurrentProjectionMatrix();
#ifdef OPENVR_SUPPORT
bool currentWindowIsHMD = FirstOpenVRWindow == SgctEngine->getCurrentWindowPtr();
if (sgct::SGCTOpenVR::isHMDActive() && currentWindowIsHMD) {
projectionMatrix = sgct::SGCTOpenVR::getHMDCurrentViewProjectionMatrix(
SgctEngine->getCurrentFrustumMode()
);
}
#endif
mat4 projectionMatrix = _sgctEngine->getCurrentProjectionMatrix();
OsEng.render(projectionMatrix, viewMatrix);
OsEng.render(
SgctEngine->getModelMatrix(),
viewMatrix,
projectionMatrix
);
LTRACE("main::mainRenderFunc(end)");
}
void mainPostDrawFunc() {
LTRACE("main::mainPostDrawFunc(begin)");
OsEng.postDraw();
LTRACE("main::mainPostDrawFunc(end)");
// if (OsEng.logSGCTOutOfOrderErrors()) {
// if (sgct::Engine::instance()->isMaster()) {
// if (minilog.str() != EXPECTED_MASTER_LOG) {
// LERRORC("Minilog", "Bad combination: " << minilog.str());
// }
// }
// else {
// if (minilog.str() != EXPECTED_SLAVE_LOG) {
// LERRORC("Minilog", "Bad combination: " << minilog.str());
// }
// }
// }
#ifdef OPENVR_SUPPORT
if (FirstOpenVRWindow) {
// Copy the first OpenVR window to the HMD
sgct::SGCTOpenVR::copyWindowToHMD(FirstOpenVRWindow);
}
#endif // OPENVR_SUPPORT
OsEng.postDraw();
#ifdef OPENSPACE_HAS_SPOUT
for (const SpoutWindow& w : SpoutWindows) {
sgct::SGCTWindow* window = SgctEngine->getWindowPtr(w.windowId);
if (w.leftOrMain.initialized) {
GLuint texId = window->getFrameBufferTexture(sgct::Engine::LeftEye);
glBindTexture(GL_TEXTURE_2D, texId);
w.leftOrMain.handle->SendTexture(
texId,
GL_TEXTURE_2D,
window->getXFramebufferResolution(),
window->getYFramebufferResolution()
);
}
if (w.right.initialized) {
GLuint texId = window->getFrameBufferTexture(sgct::Engine::RightEye);
glBindTexture(GL_TEXTURE_2D, texId);
w.right.handle->SendTexture(
texId,
GL_TEXTURE_2D,
window->getXFramebufferResolution(),
window->getYFramebufferResolution()
);
}
}
glBindTexture(GL_TEXTURE_2D, 0);
#endif // OPENSPACE_HAS_SPOUT
LTRACE("main::mainPostDrawFunc(end)");
}
void mainExternalControlCallback(const char* receivedChars, int size) {
LTRACE("main::mainExternalControlCallback(begin)");
if (OsEng.isMaster()) {
if (SgctEngine->isMaster()) {
OsEng.externalControlCallback(receivedChars, size, 0);
}
LTRACE("main::mainExternalControlCallback(end)");
@@ -315,40 +409,45 @@ void mainExternalControlCallback(const char* receivedChars, int size) {
void mainKeyboardCallback(int key, int, int action, int mods) {
LTRACE("main::mainKeyboardCallback(begin)");
if (OsEng.isMaster()) {
if (SgctEngine->isMaster()) {
OsEng.keyboardCallback(
openspace::Key(key),
openspace::KeyModifier(mods),
openspace::KeyAction(action)
);
);
}
LTRACE("main::mainKeyboardCallback(begin)");
}
void mainMouseButtonCallback(int key, int action) {
LTRACE("main::mainMouseButtonCallback(begin)");
if (OsEng.isMaster()) {
if (SgctEngine->isMaster()) {
OsEng.mouseButtonCallback(
openspace::MouseButton(key),
openspace::MouseAction(action)
);
);
}
LTRACE("main::mainMouseButtonCallback(end)");
}
void mainMousePosCallback(double x, double y) {
if (OsEng.isMaster())
if (SgctEngine->isMaster()) {
OsEng.mousePositionCallback(x, y);
}
}
void mainMouseScrollCallback(double posX, double posY) {
if (OsEng.isMaster())
void mainMouseScrollCallback(double, double posY) {
LTRACE("main::mainMouseScrollCallback(begin");
if (SgctEngine->isMaster()) {
OsEng.mouseScrollWheelCallback(posY);
}
LTRACE("main::mainMouseScrollCallback(end)");
}
void mainCharCallback(unsigned int codepoint, int mods) {
if (OsEng.isMaster())
if (SgctEngine->isMaster()) {
OsEng.charCallback(codepoint, openspace::KeyModifier(mods));
}
}
void mainEncodeFun() {
@@ -365,10 +464,189 @@ void mainDecodeFun() {
void mainLogCallback(const char* msg) {
std::string message = msg;
if (message.empty() || message == ".")
if (message.empty() || message == ".") {
// We don't want the empty '.' message that SGCT sends while it is waiting for
// connections from other network nodes
return;
}
// Remove the trailing \n that is passed along
LINFOC("SGCT", message.substr(0, std::max<size_t>(message.size() - 1, 0)));
LINFOC("SGCT", message.substr(0, message.size() - 1));
}
int main_main(int argc, char** argv) {
std::pair<int, int> glVersion = supportedOpenGLVersion();
// Create the OpenSpace engine and get arguments for the SGCT engine
// @CLEANUP: Replace the return valua with throwing an exception --abock
std::vector<std::string> sgctArguments;
bool requestQuit = false;
openspace::OpenSpaceEngine::create(
argc, argv,
std::make_unique<openspace::SGCTWindowWrapper>(),
sgctArguments,
requestQuit
);
if (requestQuit) {
return EXIT_SUCCESS;
}
LINFO("Detected OpenGL version: " << glVersion.first << "." << glVersion.second);
// Create sgct engine c arguments
int newArgc = static_cast<int>(sgctArguments.size());
char** newArgv = new char*[newArgc];
for (int i = 0; i < newArgc; ++i) {
newArgv[i] = const_cast<char*>(sgctArguments.at(i).c_str());
}
// Need to set this before the creation of the sgct::Engine
sgct::MessageHandler::instance()->setLogToConsole(false);
sgct::MessageHandler::instance()->setShowTime(false);
sgct::MessageHandler::instance()->setLogToCallback(true);
sgct::MessageHandler::instance()->setLogCallback(mainLogCallback);
#ifdef __APPLE__
glfwWindowHint(GLFW_STENCIL_BITS, 8);
#endif
LDEBUG("Creating SGCT Engine");
SgctEngine = new sgct::Engine(newArgc, newArgv);
// Deallocate sgct c arguments
delete[] newArgv;
// Bind functions
SgctEngine->setInitOGLFunction(mainInitFunc);
SgctEngine->setPreSyncFunction(mainPreSyncFunc);
SgctEngine->setPostSyncPreDrawFunction(mainPostSyncPreDrawFunc);
SgctEngine->setDrawFunction(mainRenderFunc);
SgctEngine->setPostDrawFunction(mainPostDrawFunc);
SgctEngine->setKeyboardCallbackFunction(mainKeyboardCallback);
SgctEngine->setMouseButtonCallbackFunction(mainMouseButtonCallback);
SgctEngine->setMousePosCallbackFunction(mainMousePosCallback);
SgctEngine->setMouseScrollCallbackFunction(mainMouseScrollCallback);
SgctEngine->setExternalControlCallback(mainExternalControlCallback);
SgctEngine->setCharCallbackFunction(mainCharCallback);
// Disable the immediate exit of the application when the ESC key is pressed
SgctEngine->setExitKey(SGCT_KEY_UNKNOWN);
sgct::MessageHandler::instance()->setNotifyLevel(sgct::MessageHandler::NOTIFY_ALL);
// Set encode and decode functions
// NOTE: starts synchronizing before init functions
sgct::SharedData::instance()->setEncodeFunction(mainEncodeFun);
sgct::SharedData::instance()->setDecodeFunction(mainDecodeFun);
// Try to open a window
LDEBUG("Initialize SGCT Engine");
std::map<std::pair<int, int>, sgct::Engine::RunMode> versionMapping = {
{ { 3, 3 }, sgct::Engine::RunMode::OpenGL_3_3_Core_Profile },
{ { 4, 0 }, sgct::Engine::RunMode::OpenGL_4_0_Core_Profile },
{ { 4, 1 }, sgct::Engine::RunMode::OpenGL_4_1_Core_Profile },
{ { 4, 2 }, sgct::Engine::RunMode::OpenGL_4_2_Core_Profile },
{ { 4, 3 }, sgct::Engine::RunMode::OpenGL_4_3_Core_Profile },
{ { 4, 4 }, sgct::Engine::RunMode::OpenGL_4_4_Core_Profile },
{ { 4, 5 }, sgct::Engine::RunMode::OpenGL_4_5_Core_Profile }
};
ghoul_assert(
versionMapping.find(glVersion) != versionMapping.end(),
"Unknown OpenGL version. Missing statement in version mapping map"
);
auto cleanup = [&](){
OsEng.deinitialize();
// Clear function bindings to avoid crash after destroying the OpenSpace Engine
sgct::MessageHandler::instance()->setLogToCallback(false);
sgct::MessageHandler::instance()->setLogCallback(nullptr);
LDEBUG("Destroying OpenSpaceEngine");
openspace::OpenSpaceEngine::destroy();
LDEBUG("Destroying SGCT Engine");
delete SgctEngine;
#ifdef OPENVR_SUPPORT
// Clean up OpenVR
sgct::SGCTOpenVR::shutdown();
#endif
#ifdef OPENSPACE_HAS_SPOUT
for (SpoutWindow& w : SpoutWindows) {
if (w.leftOrMain.handle) {
w.leftOrMain.handle->ReleaseReceiver();
w.leftOrMain.handle->Release();
}
if (w.right.handle) {
w.right.handle->ReleaseReceiver();
w.right.handle->Release();
}
}
#endif // OPENSPACE_HAS_SPOUT
};
bool initSuccess = SgctEngine->init(versionMapping[glVersion]);
if (!initSuccess) {
LFATAL("Initializing failed");
cleanup();
return EXIT_FAILURE;
}
// Main loop
LDEBUG("Starting rendering loop");
SgctEngine->render();
LDEBUG("Ending rendering loop");
cleanup();
// Exit program
exit(EXIT_SUCCESS);
}
} // namespace
int main(int argc, char** argv) {
#ifdef WIN32
SetUnhandledExceptionFilter(generateMiniDump);
#endif // WIN32
// If we are working as a developer, we don't want to catch the exceptions in order to
// find the locations where the exceptions are raised.
// If we are not in developer mode, we want to catch and at least log the error before
// dying
#ifdef DEVELOPER_MODE
return main_main(argc, argv);
#else
// We wrap the actual main function in a try catch block so that we can get and print
// some additional information in case an exception is raised
try {
return main_main(argc, argv);
}
catch (const ghoul::RuntimeError& e) {
// Write out all of the information about the exception and flush the logs
LFATALC(e.component, e.message);
LogMgr.flushLogs();
return EXIT_FAILURE;
}
catch (const ghoul::AssertionException& e) {
// We don't want to catch the assertion exception as we won't be able to add a
// breakpoint for debugging
LFATALC("Assertion failed", e.what());
throw;
} catch (const std::exception& e) {
LFATALC("Exception", e.what());
LogMgr.flushLogs();
return EXIT_FAILURE;
}
catch (...) {
LFATALC("Exception", "Unknown exception");
LogMgr.flushLogs();
return EXIT_FAILURE;
}
#endif // DEVELOPER_MODE
}
@@ -22,26 +22,18 @@
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #
#########################################################################################
set(APPLICATION_NAME DataConverter)
set(APPLICATION_NAME TaskRunner)
set(APPLICATION_LINK_TO_OPENSPACE ON)
include (${GHOUL_BASE_DIR}/support/cmake/handle_external_library.cmake)
set(application_path ${OPENSPACE_APPS_DIR}/DataConverter)
set(application_path ${OPENSPACE_APPS_DIR}/TaskRunner)
set(SOURCE_FILES
${application_path}/main.cpp
${application_path}/milkywayconversiontask.cpp
${application_path}/milkywaypointsconversiontask.cpp
)
set(HEADER_FILES
${application_path}/conversiontask.h
${application_path}/milkywayconversiontask.h
${application_path}/milkywaypointsconversiontask.h
)
add_executable(${APPLICATION_NAME} MACOSX_BUNDLE
${SOURCE_FILES}
${HEADER_FILES}
)
@@ -33,50 +33,98 @@
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/ghoul.h>
#include <openspace/scripting/scriptengine.h>
#include <openspace/rendering/renderable.h>
#include <openspace/util/progressbar.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/engine/configurationmanager.h>
#include <openspace/util/taskloader.h>
#include <openspace/util/factorymanager.h>
#include <openspace/util/task.h>
#include <openspace/scene/translation.h>
#include <openspace/scene/rotation.h>
#include <openspace/scene/scale.h>
#include <openspace/engine/moduleengine.h>
#include <apps/DataConverter/milkywayconversiontask.h>
#include <apps/DataConverter/milkywaypointsconversiontask.h>
int main(int argc, char** argv) {
using namespace openspace;
using namespace dataconverter;
ghoul::initialize();
namespace {
const std::string ConfigurationFile = "openspace.cfg";
const std::string _loggerCat = "TaskRunner Main";
}
void initTextureReaders() {
#ifdef GHOUL_USE_DEVIL
ghoul::io::TextureReader::ref().addReader(std::make_shared<ghoul::io::TextureReaderDevIL>());
#endif // GHOUL_USE_DEVIL
#ifdef GHOUL_USE_FREEIMAGE
ghoul::io::TextureReader::ref().addReader(std::make_shared<ghoul::io::TextureReaderFreeImage>());
#endif // GHOUL_USE_FREEIMAGE
}
openspace::ProgressBar pb(100);
std::function<void(float)> onProgress = [&](float progress) {
pb.print(progress * 100);
};
int main(int argc, char** argv) {
using namespace openspace;
// TODO: Make the converter configurable using either
// config files (json, lua dictionaries),
// lua scripts,
// or at the very least: a command line interface.
MilkyWayConversionTask mwConversionTask(
"F:/mw_june2016/volumeslices/img/comp/v003/frames/primary/0100/cam2_main.",
".exr",
1385,
512,
"F:/mw_june2016/mw_512_512_64_june.rawvolume",
glm::vec3(512, 512, 64));
ghoul::initialize();
initTextureReaders();
FactoryManager::initialize();
FactoryManager::ref().addFactory(
std::make_unique<ghoul::TemplateFactory<Renderable>>(),
"Renderable"
);
FactoryManager::ref().addFactory(
std::make_unique<ghoul::TemplateFactory<Task>>(),
"Task"
);
FactoryManager::ref().addFactory(
std::make_unique<ghoul::TemplateFactory<Translation>>(),
"Translation"
);
FactoryManager::ref().addFactory(
std::make_unique<ghoul::TemplateFactory<Rotation>>(),
"Rotation"
);
FactoryManager::ref().addFactory(
std::make_unique<ghoul::TemplateFactory<Scale>>(),
"Scale"
);
openspace::ConfigurationManager configuration;
std::string configurationFile = configuration.findConfiguration(ConfigurationFile);
configuration.loadFromFile(configurationFile);
ModuleEngine moduleEngine;
moduleEngine.initialize();
std::string tasksPath;
configuration.getValue(ConfigurationManager::KeyConfigTask, tasksPath);
LINFO("Initialization done.");
TaskLoader taskLoader;
std::vector<std::unique_ptr<Task>> tasks = taskLoader.tasksFromFile(tasksPath);
//MilkyWayPointsConversionTask mwpConversionTask("F:/mw_june2016/points.off", "F:/mw_june2016/points.off.binary");
size_t nTasks = tasks.size();
if (nTasks == 1) {
LINFO("Task queue has 1 item");
} else {
LINFO("Task queue has " << tasks.size() << " items");
}
for (size_t i = 0; i < tasks.size(); i++) {
Task& task = *tasks[i].get();
LINFO("Performing task " << (i+1) << " out of " << tasks.size() << ": " << task.description());
ProgressBar progressBar(100);
auto onProgress = [&progressBar](float progress) {
progressBar.print(progress * 100);
};
task.perform(onProgress);
}
mwConversionTask.perform(onProgress);
//mwpConversionTask.perform(onProgress);
std::cout << "Done." << std::endl;
std::cout << "Done performing tasks." << std::endl;
std::cin.get();
return 0;