mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-29 15:29:26 -05:00
Merge branch 'develop' into OpenCLWrapper
Conflicts: ext/ghoul src/engine/openspaceengine.cpp
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 __OPENSPACEENGINE_H__
|
||||
#define __OPENSPACEENGINE_H__
|
||||
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <ghoul/misc/configurationmanager.h>
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
|
||||
#include <openspace/rendering/volumeraycaster.h>
|
||||
#include <openspace/flare/flare.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class ScriptEngine;
|
||||
|
||||
class OpenSpaceEngine {
|
||||
public:
|
||||
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 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();
|
||||
|
||||
// SGCT callbacks
|
||||
bool initializeGL();
|
||||
void preSynchronization();
|
||||
void postSynchronizationPreDraw();
|
||||
void render();
|
||||
void postDraw();
|
||||
void keyboardCallback(int key, int action);
|
||||
void mouseButtonCallback(int key, int action);
|
||||
void mousePositionCallback(int x, int y);
|
||||
void mouseScrollWheelCallback(int pos);
|
||||
|
||||
void encode();
|
||||
void decode();
|
||||
|
||||
private:
|
||||
OpenSpaceEngine();
|
||||
~OpenSpaceEngine();
|
||||
|
||||
static OpenSpaceEngine* _engine;
|
||||
|
||||
VolumeRaycaster* _volumeRaycaster;
|
||||
Flare* _flare;
|
||||
ghoul::ConfigurationManager* _configurationManager;
|
||||
InteractionHandler* _interactionHandler;
|
||||
RenderEngine* _renderEngine;
|
||||
ScriptEngine* _scriptEngine;
|
||||
};
|
||||
|
||||
#define OsEng (openspace::OpenSpaceEngine::ref())
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACEENGINE_H__
|
||||
@@ -0,0 +1,63 @@
|
||||
#ifndef ANIMATOR_H
|
||||
#define ANIMATOR_H
|
||||
|
||||
/*
|
||||
* Author: Victor Sand (victor.sand@gmail.com)
|
||||
* Encapsulates animation logic
|
||||
*
|
||||
*/
|
||||
|
||||
namespace osp {
|
||||
|
||||
class Config;
|
||||
|
||||
class Animator {
|
||||
public:
|
||||
static Animator * New(Config *_config);
|
||||
|
||||
// Signals the animator to update its state if needed
|
||||
void Update(float _elapsedTime);
|
||||
// Pauses if unpaused, unpauses if paused
|
||||
void TogglePause();
|
||||
// If FPS mode is on, don't wait. Update every timestep.
|
||||
void ToggleFPSMode();
|
||||
|
||||
void SetPaused(bool _paused);
|
||||
void SetFPSMode(bool _fpsMode);
|
||||
void ManualTimestep(int _manualTimestep);
|
||||
|
||||
unsigned int CurrentTimestep() const { return currentTimestep_; }
|
||||
unsigned int NextTimestep() const {
|
||||
return currentTimestep_ < numTimesteps_-1 ? currentTimestep_+1 : 0;
|
||||
}
|
||||
|
||||
void SetCurrentTimestep(unsigned int _timestep);
|
||||
void SetNumTimesteps(unsigned int _numTimesteps);
|
||||
void IncTimestep();
|
||||
void DecTimestep();
|
||||
|
||||
bool UpdateConfig();
|
||||
|
||||
private:
|
||||
Animator();
|
||||
Animator(Config *_config);
|
||||
Animator(const Animator&) { }
|
||||
|
||||
Config *config_;
|
||||
|
||||
// Number of timesteps before looping occurs
|
||||
unsigned int numTimesteps_;
|
||||
// Current timestep, the output of the Animator
|
||||
unsigned int currentTimestep_;
|
||||
bool fpsMode_;
|
||||
bool paused_;
|
||||
// Keeps track of elapsed time between timestep updates
|
||||
float elapsedTime_;
|
||||
// Time before timestep gets updates
|
||||
float refreshInterval_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* Author: Victor Sand (victor.sand@gmail.com)
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BRICKMANAGER_H
|
||||
#define BRICKMANAGER_H
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <fstream>
|
||||
#include <boost/timer/timer.hpp>
|
||||
#include <stdio.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
// Make sure we get 64 bits for offset
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
// For easy switching between offset types
|
||||
#define off off64_t
|
||||
|
||||
namespace osp {
|
||||
|
||||
class Config;
|
||||
|
||||
class BrickManager {
|
||||
public:
|
||||
static BrickManager * New(Config *_config);
|
||||
~BrickManager();
|
||||
|
||||
Config *config_;
|
||||
|
||||
enum BUFFER_INDEX { EVEN = 0, ODD };
|
||||
|
||||
// Read header data from file, should normally only be called once
|
||||
// unless header data changes
|
||||
bool ReadHeader();
|
||||
|
||||
bool InitAtlas();
|
||||
|
||||
// Build brick list from request list
|
||||
// Resets values in _brickRequest to 0
|
||||
bool BuildBrickList(BUFFER_INDEX _bufIdx, std::vector<int> &_brickRequest);
|
||||
|
||||
// Upload bricks from memory buffer to PBO using the brick list
|
||||
bool DiskToPBO(BUFFER_INDEX _pboIndex);
|
||||
|
||||
// Init transfer from PBO to texture atlas
|
||||
bool PBOToAtlas(BUFFER_INDEX _pboIndex);
|
||||
|
||||
std::vector<int> BrickList(BUFFER_INDEX _bufIdx) {
|
||||
return brickLists_[_bufIdx];
|
||||
}
|
||||
|
||||
ghoul::opengl::Texture * TextureAtlas() { return textureAtlas_; }
|
||||
|
||||
// Header accessors
|
||||
unsigned int GridType() const { return gridType_; }
|
||||
unsigned int NumOrigTimesteps() const { return numOrigTimesteps_; }
|
||||
unsigned int NumTimesteps() const { return numTimesteps_; }
|
||||
unsigned int XBrickDim() const { return xBrickDim_; }
|
||||
unsigned int YBrickDim() const { return yBrickDim_; }
|
||||
unsigned int ZBrickDim() const { return zBrickDim_; }
|
||||
unsigned int XNumBricks() const { return xNumBricks_; }
|
||||
unsigned int YNumBricks() const { return yNumBricks_; }
|
||||
unsigned int ZNumBricks() const { return zNumBricks_; }
|
||||
unsigned int PaddingWidth() const { return paddingWidth_; }
|
||||
unsigned int DataSize() const { return dataSize_; }
|
||||
|
||||
private:
|
||||
|
||||
BrickManager();
|
||||
BrickManager(Config *_config);
|
||||
BrickManager(const BrickManager&);
|
||||
|
||||
// Header data
|
||||
unsigned int gridType_;
|
||||
unsigned int numOrigTimesteps_;
|
||||
unsigned int numTimesteps_;
|
||||
unsigned int xBrickDim_;
|
||||
unsigned int yBrickDim_;
|
||||
unsigned int zBrickDim_;
|
||||
unsigned int xNumBricks_;
|
||||
unsigned int yNumBricks_;
|
||||
unsigned int zNumBricks_;
|
||||
unsigned int dataSize_;
|
||||
|
||||
unsigned int numBricks_;
|
||||
unsigned int brickDim_;
|
||||
unsigned int paddedBrickDim_;
|
||||
unsigned int atlasDim_;
|
||||
|
||||
const unsigned int paddingWidth_ = 1;
|
||||
|
||||
unsigned int numBrickVals_;
|
||||
unsigned int numBricksFrame_;
|
||||
unsigned int numBricksTree_;
|
||||
unsigned int brickSize_;
|
||||
unsigned int volumeSize_;
|
||||
unsigned int numValsTot_;
|
||||
|
||||
// Texture coordinates to be assigned
|
||||
int xCoord_;
|
||||
int yCoord_;
|
||||
int zCoord_;
|
||||
|
||||
// Texture where the actual atlas is kept
|
||||
ghoul::opengl::Texture *textureAtlas_;
|
||||
|
||||
std::vector<std::vector<int> > brickLists_;
|
||||
|
||||
// C-style I/O
|
||||
std::FILE *file_;
|
||||
off_t dataPos_;
|
||||
|
||||
bool hasReadHeader_;
|
||||
bool atlasInitialized_;
|
||||
|
||||
// PBOs
|
||||
unsigned int pboHandle_[2];
|
||||
|
||||
// Caching, one for each PBO
|
||||
std::vector<std::vector<int> > bricksInPBO_;
|
||||
std::vector<std::vector<bool> > usedCoords_;
|
||||
|
||||
// Increment the coordinate to be assigned (handle looping)
|
||||
void IncCoord();
|
||||
// Linear version of the current x, y, z coordinate to be assigned
|
||||
unsigned int LinearCoord(int _x, int _y, int _z);
|
||||
// 3D coordinates from linear index
|
||||
void CoordsFromLin(int _idx, int &_x, int &_y, int &_z);
|
||||
|
||||
// Fill a brick in the volume using a pointer to flattened brick data
|
||||
bool FillVolume(float *_in,
|
||||
float *_out,
|
||||
unsigned int _x,
|
||||
unsigned int _y,
|
||||
unsigned int _z);
|
||||
|
||||
// Timer and timer constants
|
||||
boost::timer::cpu_timer timer_;
|
||||
const double BYTES_PER_GB = 1073741824.0;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Author: Victor Sand (victor.sand@gmail.com)
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CL_MANAGER_H_
|
||||
#define CL_MANAGER_H_
|
||||
|
||||
#include <ghoul/opencl/ghoul_cl.h>
|
||||
#include <ghoul/opencl/clcontext.h>
|
||||
#include <ghoul/opencl/clcommandqueue.h>
|
||||
#include <ghoul/opencl/clprogram.h>
|
||||
#include <ghoul/opencl/clkernel.h>
|
||||
#include <ghoul/opencl/clutil.h>
|
||||
#include <ghoul/opencl/clworksize.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <openspace/flare/KernelConstants.h>
|
||||
|
||||
namespace osp {
|
||||
|
||||
class TransferFunction;
|
||||
class CLProgram;
|
||||
class TSP;
|
||||
|
||||
class CLManager {
|
||||
public:
|
||||
static CLManager * New();
|
||||
~CLManager();
|
||||
|
||||
// Different queue indices for working with asynchronous uploads/executions
|
||||
enum QueueIndex { EXECUTE, TRANSFER, NUM_QUEUE_INDICES };
|
||||
enum TextureType { TEXTURE_1D, TEXTURE_2D, TEXTURE_3D };
|
||||
enum Permissions { READ_ONLY, WRITE_ONLY, READ_WRITE };
|
||||
enum AllocMode { USE_HOST_PTR, ALLOC_HOST_PTR, COPY_HOST_PTR };
|
||||
|
||||
// These four functions should be run in this order
|
||||
bool InitPlatform();
|
||||
bool InitDevices();
|
||||
bool CreateContext();
|
||||
bool CreateCommandQueue();
|
||||
|
||||
// Name a program and create it from source text file
|
||||
bool CreateProgram(std::string _programName, std::string _fileName);
|
||||
// Build program after creation
|
||||
bool BuildProgram(std::string _programName);
|
||||
// Create kernel after building program
|
||||
bool CreateKernel(std::string _programName);
|
||||
|
||||
// Add an OpenGL texture to a program
|
||||
bool AddTexture(std::string _programName, unsigned int _argNr,
|
||||
ghoul::opengl::Texture *_texture, TextureType _textureType,
|
||||
Permissions _permissions);
|
||||
|
||||
bool AddTexture(std::string _programName, unsigned int _argNr,
|
||||
ghoul::opengl::Texture *_texture, TextureType _textureType,
|
||||
Permissions _permissions, cl_mem& _clTextureMem);
|
||||
|
||||
bool AddTexture(std::string _programName, unsigned int _argNr,
|
||||
cl_mem _texture, Permissions _permissions);
|
||||
|
||||
bool AddBuffer(std::string _programName, unsigned int _argNr,
|
||||
void *_hostPtr, unsigned int _sizeInBytes,
|
||||
AllocMode _allocMode, Permissions _permissions);
|
||||
|
||||
bool ReadBuffer(std::string _programName, unsigned int _argNr,
|
||||
void *_hostPtr, unsigned int _sizeInBytes,
|
||||
bool _blocking);
|
||||
|
||||
// Free resources
|
||||
bool ReleaseBuffer(std::string _programName, unsigned int _argNr);
|
||||
|
||||
// Set the value of an integer argument
|
||||
bool SetInt(std::string _programName, unsigned int _argNr, int _val);
|
||||
|
||||
// Aquire any shared textures, set up kernel arguments etc
|
||||
bool PrepareProgram(std::string _programName);
|
||||
|
||||
// Launch program kernel (returns immediately)
|
||||
bool LaunchProgram(std::string _programName,
|
||||
unsigned int _gx, unsigned int _gy,
|
||||
unsigned int _lx, unsigned int _ly);
|
||||
|
||||
// Wait for kernel to finish, releaste any shared resources
|
||||
bool FinishProgram(std::string _programName);
|
||||
|
||||
// Finish all commands in a command queue
|
||||
// Can be used e.g. to sync a DMA transfer operation
|
||||
bool FinishQueue(QueueIndex _queueIndex);
|
||||
|
||||
friend class CLProgram;
|
||||
|
||||
private:
|
||||
CLManager();
|
||||
CLManager(const CLManager&);
|
||||
|
||||
// Read kernel source from file, return char array
|
||||
// Store number of chars in _numChar argument
|
||||
char * ReadSource(std::string _fileName, int &_numChars) const;
|
||||
// Check state in a cl_int, print error if state is not CL_SUCCESS
|
||||
bool CheckSuccess(cl_int _error, std::string _location) const;
|
||||
// Translate cl_int enum to readable string
|
||||
std::string ErrorString(cl_int _error) const;
|
||||
// Convert CLManager::Permissions to cl_mem_flags
|
||||
cl_mem_flags ConvertPermissions(Permissions _permissions);
|
||||
// Conver CLManager::AllocMode to cl_mem_flags
|
||||
cl_mem_flags ConvertAllocMode(AllocMode _allocMode);
|
||||
|
||||
static const unsigned int MAX_PLATFORMS = 32;
|
||||
static const unsigned int MAX_DEVICES = 32;
|
||||
static const unsigned int MAX_NAME_LENGTH = 128;
|
||||
|
||||
// Used for storing and reading error state during function calls
|
||||
cl_int error_;
|
||||
cl_uint numPlatforms_;
|
||||
cl_platform_id platforms_[MAX_PLATFORMS];
|
||||
cl_uint numDevices_;
|
||||
cl_device_id devices_[MAX_DEVICES];
|
||||
// Maximum allocatable size for each device
|
||||
cl_ulong maxMemAllocSize_[MAX_DEVICES];
|
||||
char deviceName_[MAX_NAME_LENGTH];
|
||||
char driverVersion_[MAX_NAME_LENGTH];
|
||||
char platformVersion_[MAX_NAME_LENGTH];
|
||||
//cl_context context_;
|
||||
ghoul::opencl::CLCommandQueue commandQueues_[NUM_QUEUE_INDICES];
|
||||
|
||||
// Programs are mapped using strings
|
||||
std::map<std::string, CLProgram*> clPrograms_;
|
||||
|
||||
ghoul::opencl::CLContext _context;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Victor Sand (victor.sand@gmail.com)
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CL_PROGRAM_H_
|
||||
#define CL_PROGRAM_H_
|
||||
|
||||
#include <ghoul/opencl/ghoul_cl.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <openspace/flare/KernelConstants.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
namespace osp {
|
||||
|
||||
class CLManager;
|
||||
class TransferFunction;
|
||||
class Texture;
|
||||
|
||||
class CLProgram {
|
||||
public:
|
||||
static CLProgram * New(const std::string &_programName,
|
||||
CLManager *_clManager);
|
||||
~CLProgram();
|
||||
|
||||
struct MemArg {
|
||||
size_t size_;
|
||||
cl_mem mem_;
|
||||
};
|
||||
|
||||
cl_program Program() { return program_; }
|
||||
cl_kernel Kernel() { return kernel_; }
|
||||
cl_int Error() { return error_; }
|
||||
|
||||
bool CreateProgram(std::string _fileName);
|
||||
bool BuildProgram();
|
||||
bool CreateKernel();
|
||||
|
||||
bool AddTexture(unsigned int _argNr, ghoul::opengl::Texture *_texture,
|
||||
GLuint _textureType,
|
||||
cl_mem_flags _permissions);
|
||||
|
||||
bool AddTexture(unsigned int _argNr, ghoul::opengl::Texture *_texture,
|
||||
GLuint _textureType,
|
||||
cl_mem_flags _permissions, cl_mem& _clTextureMem);
|
||||
|
||||
bool AddTexture(unsigned int _argNr, cl_mem _texture,
|
||||
cl_mem_flags _permissions);
|
||||
|
||||
bool AddBuffer(unsigned int _argNr,
|
||||
void *_hostPtr,
|
||||
unsigned int _sizeInBytes,
|
||||
cl_mem_flags _allocMode,
|
||||
cl_mem_flags _permissions);
|
||||
|
||||
bool ReadBuffer(unsigned int _argNr,
|
||||
void *_hostPtr,
|
||||
unsigned int _sizeInBytes,
|
||||
cl_bool _blocking);
|
||||
|
||||
bool ReleaseBuffer(unsigned int _argNr);
|
||||
|
||||
bool SetInt(unsigned int _argNr, int _val);
|
||||
|
||||
bool PrepareProgram();
|
||||
bool LaunchProgram(unsigned int _gx, unsigned int _gy,
|
||||
unsigned int _lx, unsigned int _ly);
|
||||
bool FinishProgram();
|
||||
|
||||
private:
|
||||
CLProgram(const std::string &_programName, CLManager *_clManager);
|
||||
CLProgram();
|
||||
CLProgram(const CLProgram&);
|
||||
|
||||
char * ReadSource(const std::string &_fileName, int &_numChars) const;
|
||||
|
||||
std::string programName_;
|
||||
|
||||
CLManager *clManager_;
|
||||
cl_program program_;
|
||||
cl_kernel kernel_;
|
||||
cl_int error_;
|
||||
// Stores device OGL textures together with their kernel arg nummer
|
||||
std::map<cl_uint, cl_mem> OGLTextures_;
|
||||
// Stores non-texture memory buffer arguments
|
||||
std::map<cl_uint, MemArg> memArgs_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Author: Victor Sand (victor.sand@gmail.com)
|
||||
*
|
||||
* Simple functionality to read, save and access constants.
|
||||
* Reads the specified file as soon as the object is created.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_H_
|
||||
#define CONFIG_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace osp {
|
||||
|
||||
class Config {
|
||||
public:
|
||||
static Config * New(const std::string &_configFilename);
|
||||
~Config();
|
||||
|
||||
// Reads the config file, can be called by external modules
|
||||
bool Read();
|
||||
|
||||
int WinWidth() const { return winWidth_; }
|
||||
int WinHeight() const { return winHeight_; }
|
||||
bool ClearCache() const { return clearCache_; }
|
||||
int TextureDivisionFactor() const { return textureDivisionFactor_; }
|
||||
unsigned int LocalWorkSizeX() const { return localWorkSizeX_; }
|
||||
unsigned int LocalWorkSizeY() const { return localWorkSizeY_; }
|
||||
std::string TSPFilename() const { return TSPFilename_; }
|
||||
std::string TFFilename() const { return TFFilename_; }
|
||||
std::string RaycasterKernelFilename()const{return raycasterKernelFilename_;}
|
||||
std::string TSPTraversalKernelFilename() const
|
||||
{ return TSPTraversalKernelFilename_; }
|
||||
std::string CubeShaderVertFilename() const { return cubeShaderVertFilename_;}
|
||||
std::string CubeShaderFragFilename() const { return cubeShaderFragFilename_;}
|
||||
std::string QuadShaderVertFilename() const { return quadShaderVertFilename_;}
|
||||
std::string QuadShaderFragFilename() const { return quadShaderFragFilename_;}
|
||||
float SpatialErrorTolerance() const { return spatialErrorTolerance_; }
|
||||
float TemporalErrorTolerance() const { return temporalErrorTolerance_; }
|
||||
float TSPTraversalStepsize() const { return TSPTraversalStepsize_; }
|
||||
float RaycasterStepsize() const { return raycasterStepsize_; }
|
||||
float RaycasterIntensity() const { return raycasterIntensity_; }
|
||||
float AnimatorRefreshInterval() const { return animatorRefreshInterval_; }
|
||||
float MousePitchFactor() const { return mousePitchFactor_; }
|
||||
float MouseRollFactor() const { return mouseRollFactor_; }
|
||||
float ZoomFactor() const { return zoomFactor_; }
|
||||
float StartPitch() const { return startPitch_; }
|
||||
float StartRoll() const { return startRoll_; }
|
||||
float StartYaw() const { return startYaw_; }
|
||||
float TranslateX() const { return translateX_; }
|
||||
float TranslateY() const { return translateY_; }
|
||||
float TranslateZ() const { return translateZ_; }
|
||||
int CalculateError() const { return calculateError_; }
|
||||
float PitchSpeed() const { return pitchSpeed_; }
|
||||
float RollSpeed() const { return rollSpeed_; }
|
||||
float YawSpeed() const { return yawSpeed_; }
|
||||
bool TakeScreenshot() const { return takeScreenshot_; }
|
||||
|
||||
private:
|
||||
Config();
|
||||
Config(const std::string &_configFilename);
|
||||
Config(const Config&);
|
||||
|
||||
std::string configFilename_;
|
||||
|
||||
int winWidth_;
|
||||
int winHeight_;
|
||||
bool clearCache_;
|
||||
int textureDivisionFactor_;
|
||||
unsigned int localWorkSizeX_;
|
||||
unsigned int localWorkSizeY_;
|
||||
std::string TSPFilename_;
|
||||
std::string TFFilename_;
|
||||
std::string raycasterKernelFilename_;
|
||||
std::string TSPTraversalKernelFilename_;
|
||||
std::string cubeShaderVertFilename_;
|
||||
std::string cubeShaderFragFilename_;
|
||||
std::string quadShaderVertFilename_;
|
||||
std::string quadShaderFragFilename_;
|
||||
float spatialErrorTolerance_;
|
||||
float temporalErrorTolerance_;
|
||||
float TSPTraversalStepsize_;
|
||||
float raycasterStepsize_;
|
||||
float raycasterIntensity_;
|
||||
float animatorRefreshInterval_;
|
||||
float mousePitchFactor_;
|
||||
float mouseRollFactor_;
|
||||
float zoomFactor_;
|
||||
float startPitch_;
|
||||
float startRoll_;
|
||||
float startYaw_;
|
||||
float translateX_;
|
||||
float translateY_;
|
||||
float translateZ_;
|
||||
int calculateError_;
|
||||
float pitchSpeed_;
|
||||
float rollSpeed_;
|
||||
float yawSpeed_;
|
||||
bool takeScreenshot_;
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef KERNELCONSTANTS_H_
|
||||
#define KERNELCONSTANTS_H_
|
||||
|
||||
/*
|
||||
Author: Victor Sand (victor.sand@gmail.com)
|
||||
Simple structs to gather constants used in kernel
|
||||
*/
|
||||
|
||||
namespace osp {
|
||||
|
||||
struct KernelConstants {
|
||||
int gridType_;
|
||||
float stepsize_;
|
||||
float intensity_;
|
||||
int numTimesteps_;
|
||||
int numValuesPerNode_;
|
||||
int numOTNodes_;
|
||||
int numBoxesPerAxis_;
|
||||
float temporalTolerance_;
|
||||
float spatialTolerance_;
|
||||
int rootLevel_;
|
||||
int paddedBrickDim_;
|
||||
};
|
||||
|
||||
struct TraversalConstants {
|
||||
int gridType_;
|
||||
float stepsize_;
|
||||
int numTimesteps_;
|
||||
int numValuesPerNode_;
|
||||
int numOTNodes_;
|
||||
float temporalTolerance_;
|
||||
float spatialTolerance_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,65 @@
|
||||
#ifndef MAPPINGKEY_H
|
||||
#define MAPPINGKEY_H
|
||||
|
||||
|
||||
/*
|
||||
Author: Victor Sand (victor.sand@gmail.com)
|
||||
Mapping key used in transfer function. A key includes an intensity
|
||||
for which the key is active, and RGBA values for that specific intensity.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <openspace/flare/Utils.h>
|
||||
|
||||
namespace osp {
|
||||
|
||||
class MappingKey {
|
||||
public:
|
||||
MappingKey();
|
||||
MappingKey(const MappingKey &_mappingKey);
|
||||
MappingKey(float _intensity, unsigned int _r, unsigned int _g,
|
||||
unsigned int _b, unsigned int _a);
|
||||
~MappingKey();
|
||||
|
||||
float Intensity() const { return intensity_; }
|
||||
unsigned int R() const { return r_; }
|
||||
unsigned int G() const { return g_; }
|
||||
unsigned int B() const { return b_; }
|
||||
unsigned int A() const { return a_; }
|
||||
unsigned int Channel(unsigned int _channel) const {
|
||||
switch (_channel) {
|
||||
case 0:
|
||||
return r_;
|
||||
case 1:
|
||||
return g_;
|
||||
case 2:
|
||||
return b_;
|
||||
case 3:
|
||||
return a_;
|
||||
default:
|
||||
ERROR("Invalid channel, returning 0");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void SetValues(float _intensity, unsigned int _r, unsigned int _g,
|
||||
unsigned int _b, unsigned int _a);
|
||||
|
||||
// Comparsion by intensity for sorting purposes
|
||||
bool operator<(const MappingKey &_mappingKey) const;
|
||||
MappingKey & operator=(const MappingKey &_mappingKey);
|
||||
|
||||
private:
|
||||
float intensity_;
|
||||
unsigned int r_;
|
||||
unsigned int g_;
|
||||
unsigned int b_;
|
||||
unsigned int a_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream &os,
|
||||
const osp::MappingKey &_mappingKey);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,196 @@
|
||||
#ifndef RAYCASTER_H_
|
||||
#define RAYCASTER_H_
|
||||
|
||||
/*
|
||||
Author: Victor Sand (victor.sand@gmail.com)
|
||||
Mammoth workhorse class that ties all parts of the raycaster application
|
||||
together. Manages state, render calls and a lot of initializations.
|
||||
TODO: Iteratively break away parts from it into other classes.
|
||||
*/
|
||||
|
||||
#include <openspace/flare/Renderer.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <glm/glm.hpp>
|
||||
#include <ghoul/opencl/ghoul_cl.h>
|
||||
#include <openspace/flare/KernelConstants.h>
|
||||
#include <boost/timer/timer.hpp>
|
||||
#include <openspace/flare/TSP.h>
|
||||
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
namespace osp {
|
||||
|
||||
class TransferFunction;
|
||||
class Animator;
|
||||
class BrickManager;
|
||||
class CLManager;
|
||||
class Config;
|
||||
|
||||
class Raycaster : public Renderer {
|
||||
public:
|
||||
|
||||
static Raycaster * New(Config *_config);
|
||||
virtual ~Raycaster();
|
||||
virtual bool Render(float _timestep);
|
||||
|
||||
// Called by the SGCT window manager
|
||||
bool Reload();
|
||||
|
||||
// Init pipeline for double buffered setup
|
||||
bool InitPipeline();
|
||||
|
||||
// Reload GLSL shaders
|
||||
bool ReloadShaders();
|
||||
// Reload transfer function file
|
||||
bool ReloadTransferFunctions();
|
||||
// Initialize the color cube used for raycasting.
|
||||
// TODO Make cube class.
|
||||
bool InitCube();
|
||||
// Init the quad used for output texture rendering
|
||||
bool InitQuad();
|
||||
// Run all of CLHandlers initialization functions
|
||||
bool InitCL();
|
||||
// Set up buffers for the different rendering stages
|
||||
bool InitFramebuffers();
|
||||
// Set up two pixel buffers for texture streaming
|
||||
bool InitPixelBuffers();
|
||||
// Update matrices with current view parameters
|
||||
bool UpdateMatrices();
|
||||
// Bind transformation matrices to a ShaderProgram
|
||||
bool BindTransformationMatrices(ghoul::opengl::ProgramObject *_program);
|
||||
// Read kernel config from file and voxel data,
|
||||
// update the constants that get sent to the kernel every frame
|
||||
bool UpdateKernelConfig();
|
||||
// For keyboard handling, retrieve the last known state of a key
|
||||
bool KeyLastState(int _key) const;
|
||||
// Add a transfer function to the transfer function list
|
||||
// TODO Actually support and make use of multiple TFs
|
||||
void AddTransferFunction(TransferFunction *_transferFunction);
|
||||
|
||||
ghoul::opengl::Texture * CubeFrontTexture() const { return cubeFrontTex_; }
|
||||
ghoul::opengl::Texture * CubeBackTexture() const { return cubeBackTex_; }
|
||||
ghoul::opengl::Texture * QuadTexture() const { return quadTex_; }
|
||||
|
||||
void SetKernelConfigFilename(const std::string &_filename);
|
||||
void SetCubeFrontTexture(ghoul::opengl::Texture *_cubeFrontTexture);
|
||||
void SetCubeBackTexture(ghoul::opengl::Texture *_cubeBackTexture);
|
||||
void SetQuadTexture(ghoul::opengl::Texture *_quadTexture);
|
||||
void SetCubeShaderProgram(ghoul::opengl::ProgramObject *_cubeShaderProgram);
|
||||
void SetQuadShaderProgram(ghoul::opengl::ProgramObject *_quadShaderProgram);
|
||||
void SetAnimator(Animator *_animator);
|
||||
void SetCLManager(CLManager *_clManager);
|
||||
void SetBrickManager(BrickManager *_brickManager);
|
||||
void SetTSP(TSP *_tsp);
|
||||
|
||||
// SGCT
|
||||
void SetModelParams(float _pitch, float _yaw, float _roll);
|
||||
void SetViewParams(float _translateX, float _translateY, float _translateZ);
|
||||
|
||||
private:
|
||||
Raycaster();
|
||||
Raycaster(Config *_config);
|
||||
|
||||
Config *config_;
|
||||
|
||||
// VAO handles
|
||||
unsigned int cubeVAO_;
|
||||
unsigned int quadVAO_;
|
||||
|
||||
// Buffer object handles
|
||||
unsigned int cubeFrontFBO_;
|
||||
unsigned int cubeBackFBO_;
|
||||
unsigned int renderbufferObject_;
|
||||
unsigned int cubePosbufferObject_;
|
||||
unsigned int quadPosbufferObject_;
|
||||
unsigned int cubePositionAttrib_;
|
||||
unsigned int quadPositionAttrib_;
|
||||
// Shaders
|
||||
ghoul::opengl::ProgramObject *cubeShaderProgram_;
|
||||
ghoul::opengl::ProgramObject *quadShaderProgram_;
|
||||
// Textures
|
||||
ghoul::opengl::Texture *cubeFrontTex_;
|
||||
ghoul::opengl::Texture *cubeBackTex_;
|
||||
ghoul::opengl::Texture *quadTex_;
|
||||
ghoul::opengl::Texture *volumeTex_;
|
||||
// Model params
|
||||
float pitch_;
|
||||
float yaw_;
|
||||
float roll_;
|
||||
// View
|
||||
float translateX_;
|
||||
float translateY_;
|
||||
float translateZ_;
|
||||
|
||||
// Tranformation matrices
|
||||
glm::mat4 model_;
|
||||
glm::mat4 view_;
|
||||
glm::mat4 proj_;
|
||||
// State
|
||||
bool cubeInitialized_;
|
||||
bool quadInitialized_;
|
||||
bool framebuffersInitialized_;
|
||||
bool pingPong_; // texture streaming
|
||||
|
||||
// Animator to control update rate and looping
|
||||
Animator * animator_;
|
||||
// Used to see if it is time to update frames
|
||||
unsigned int lastTimestep_;
|
||||
// Used for ping pong memory buffering
|
||||
unsigned int pingPongIndex_;
|
||||
// Kernel constants
|
||||
KernelConstants kernelConstants_;
|
||||
TraversalConstants traversalConstants_;
|
||||
std::string kernelConfigFilename_;
|
||||
// Transfer functions
|
||||
std::vector<TransferFunction*> transferFunctions_;
|
||||
|
||||
// Brick manager with access to brick data
|
||||
BrickManager *brickManager_;
|
||||
|
||||
bool LaunchTSPTraversal(unsigned int _timestep);
|
||||
|
||||
// Brick request list
|
||||
std::vector<int> brickRequest_;
|
||||
|
||||
// TSP tree structure (not actual data)
|
||||
TSP *tsp_;
|
||||
|
||||
// Entry point for all things OpenCL
|
||||
CLManager *clManager_;
|
||||
|
||||
// Helper function for updating and binding kernel constants
|
||||
bool UpdateKernelConstants();
|
||||
|
||||
// For the corresponding CL kernel
|
||||
static const unsigned int cubeFrontArg_ = 0;
|
||||
static const unsigned int cubeBackArg_ = 1;
|
||||
static const unsigned int quadArg_ = 2;
|
||||
static const unsigned int textureAtlasArg_ = 3;
|
||||
static const unsigned int constantsArg_ = 4;
|
||||
static const unsigned int transferFunctionArg_ = 5;
|
||||
static const unsigned int tspArg_ = 6;
|
||||
static const unsigned int brickListArg_ = 7;
|
||||
static const unsigned int timestepArg_ = 8;
|
||||
|
||||
static const unsigned int tspCubeFrontArg_ = 0;
|
||||
static const unsigned int tspCubeBackArg_ = 1;
|
||||
static const unsigned int tspConstantsArg_ = 2;
|
||||
static const unsigned int tspTSPArg_ = 3;
|
||||
static const unsigned int tspBrickListArg_ = 4;
|
||||
static const unsigned int tspTimestepArg_ = 5;
|
||||
|
||||
|
||||
// Timer and timer constants
|
||||
boost::timer::cpu_timer timer_;
|
||||
|
||||
|
||||
cl_mem cubeFrontCLmem;
|
||||
cl_mem cubeBackCLmem;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,45 @@
|
||||
#ifndef RENDERER_H
|
||||
#define RENDERER_H
|
||||
|
||||
/*
|
||||
Author: Victor Sand (victor.sand@gmail.com)
|
||||
Renderer abstract class, Render() functions needs to be
|
||||
implemented by subclasses.
|
||||
TODO No real use right now but to handle key and mouse state
|
||||
TODO Write better and manageable key state functionality
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace osp {
|
||||
|
||||
class Renderer {
|
||||
public:
|
||||
virtual bool Render(float _timestep) = 0;
|
||||
virtual ~Renderer();
|
||||
void SetKeyPressed(int _key, bool _pressed);
|
||||
bool KeyPressed(int _key) const;
|
||||
void SetWinWidth(unsigned int _winWidth);
|
||||
void SetWinHeight(unsigned int _winHeight);
|
||||
void SetMousePosition(float _mouseX, float _mouseY);
|
||||
void SetMousePressed(bool _leftPressed, bool _rightPressed);
|
||||
float FPS() const;
|
||||
protected:
|
||||
Renderer();
|
||||
// Window
|
||||
unsigned int winWidth_;
|
||||
unsigned int winHeight_;
|
||||
// Mouse
|
||||
bool leftMouseDown_;
|
||||
bool rightMouseDown_;
|
||||
float currentMouseX_;
|
||||
float currentMouseY_;
|
||||
float lastMouseX_;
|
||||
float lastMouseY_;
|
||||
// Keyboard
|
||||
std::map<int, bool> keysPressed_; // Is key pressed or not?
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Author: Victor Sand (victor.sand@gmail.com)
|
||||
*
|
||||
* Construct a traversable TSP structure with structure and error info
|
||||
* from a .tsp file
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef TSP_H_
|
||||
#define TSP_H_
|
||||
|
||||
// Make sure to use 64 bits for file offset
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
|
||||
// For easy switching between offset types
|
||||
// (off_t, off64_t etc)
|
||||
#define off off64_t
|
||||
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
namespace osp {
|
||||
|
||||
class Config;
|
||||
class TransferFunction;
|
||||
|
||||
class TSP {
|
||||
public:
|
||||
|
||||
enum NodeData {
|
||||
BRICK_INDEX = 0,
|
||||
CHILD_INDEX,
|
||||
SPATIAL_ERR,
|
||||
TEMPORAL_ERR,
|
||||
NUM_DATA
|
||||
};
|
||||
|
||||
static TSP * New(Config * _config);
|
||||
~TSP();
|
||||
|
||||
// Struct for convenience
|
||||
// Note: UNUSED in this implementation
|
||||
struct Color {
|
||||
Color() {
|
||||
r = g = b = a = 0.f;
|
||||
}
|
||||
Color(float _r, float _g, float _b, float _a) {
|
||||
r = _r;
|
||||
g = _g;
|
||||
b = _b;
|
||||
a = _a;
|
||||
}
|
||||
float r;
|
||||
float g;
|
||||
float b;
|
||||
float a;
|
||||
};
|
||||
|
||||
// Tries to read cached file
|
||||
bool ReadCache();
|
||||
// Write structure to cache
|
||||
bool WriteCache();
|
||||
|
||||
bool ReadHeader();
|
||||
|
||||
// Functions to build TSP tree and calculate errors
|
||||
bool Construct();
|
||||
bool CalculateSpatialError();
|
||||
bool CalculateTemporalError();
|
||||
|
||||
int * Data() { return &data_[0]; }
|
||||
unsigned int Size() { return data_.size(); }
|
||||
|
||||
// TODO support dimensions of differens sizes
|
||||
unsigned int BrickDim() const { return xBrickDim_; }
|
||||
unsigned int PaddedBrickDim() const { return paddedBrickDim_; }
|
||||
unsigned int NumBricksPerAxis() const { return xNumBricks_; }
|
||||
unsigned int NumOrigTimesteps() const { return numOrigTimesteps_; }
|
||||
unsigned int NumTimesteps() const { return numTimesteps_; }
|
||||
unsigned int NumTotalNodes() const { return numTotalNodes_; }
|
||||
unsigned int NumValuesPerNode() const { return NUM_DATA; }
|
||||
unsigned int NumBSTNodes() const { return numBSTNodes_; }
|
||||
unsigned int NumOTNodes() const { return numOTNodes_; }
|
||||
unsigned int NumOTLevels() const { return numOTLevels_; }
|
||||
|
||||
private:
|
||||
TSP();
|
||||
TSP(Config *_config);
|
||||
TSP(const TSP&);
|
||||
|
||||
Config *config_;
|
||||
|
||||
// Holds the actual structure
|
||||
std::vector<int> data_;
|
||||
|
||||
// Data from file
|
||||
unsigned int gridType_;
|
||||
unsigned int numOrigTimesteps_;
|
||||
unsigned int numTimesteps_;
|
||||
unsigned int xBrickDim_;
|
||||
unsigned int yBrickDim_;
|
||||
unsigned int zBrickDim_;
|
||||
unsigned int xNumBricks_;
|
||||
unsigned int yNumBricks_;
|
||||
unsigned int zNumBricks_;
|
||||
//unsigned int dataSize_;
|
||||
|
||||
// Additional metadata
|
||||
unsigned int paddedBrickDim_;
|
||||
unsigned int numTotalNodes_;
|
||||
unsigned int numBSTLevels_;
|
||||
unsigned int numBSTNodes_;
|
||||
unsigned int numOTLevels_;
|
||||
unsigned int numOTNodes_;
|
||||
|
||||
const unsigned int paddingWidth_ = 1;
|
||||
|
||||
// Error stats
|
||||
float minSpatialError_;
|
||||
float maxSpatialError_;
|
||||
float medianSpatialError_;
|
||||
float minTemporalError_;
|
||||
float maxTemporalError_;
|
||||
float medianTemporalError_;
|
||||
|
||||
// Returns a list of the octree leaf nodes that a given input
|
||||
// brick covers. If the input is already a leaf, the list will
|
||||
// only contain that one index.
|
||||
std::list<unsigned int> CoveredLeafBricks(unsigned int _brickIndex);
|
||||
|
||||
// Returns a list of the BST leaf nodes that a given input brick
|
||||
// covers (at the same spatial subdivision level).
|
||||
std::list<unsigned int> CoveredBSTLeafBricks(unsigned int _brickIndex);
|
||||
|
||||
// Return a list of eight children brick incices given a brick index
|
||||
std::list<unsigned int> ChildBricks(unsigned int _brickIndex);
|
||||
|
||||
//std::ios::pos_type dataPos_;
|
||||
// Position of first data entry (after header)
|
||||
off_t dataPos_;
|
||||
|
||||
// Calculate weighted square distance between two RGBA colors
|
||||
// c2 should be an averaged or zero color
|
||||
float SquaredDist(Color _c1, Color _c2);
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef TIMER_H_
|
||||
#define TIMER_H_
|
||||
|
||||
/*
|
||||
* Author: Victor Sand (victor.sand@gmail.com)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace osp {
|
||||
|
||||
class Timer {
|
||||
public:
|
||||
Timer();
|
||||
void Start();
|
||||
void Stop();
|
||||
void Print();
|
||||
private:
|
||||
float elapsedTime_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif;
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
#ifndef TRANSFERFUNCTION_H
|
||||
#define TRANSFERFUNCTION_H
|
||||
|
||||
/*
|
||||
Author: Victor Sand (victor.sand@gmail.com)
|
||||
Transfer function class that consists of a number of MappingKeys. When
|
||||
the mapping keys are added, the transfer function can be constructed by
|
||||
interpolating between the MappingKey values.
|
||||
TODO Use Texture1D for implementation when OpenCL 1.2 is supported
|
||||
*/
|
||||
|
||||
#include <openspace/flare/MappingKey.h>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
namespace osp {
|
||||
|
||||
|
||||
class TransferFunction {
|
||||
public:
|
||||
static TransferFunction * New();
|
||||
~TransferFunction();
|
||||
|
||||
struct Color {
|
||||
float r;
|
||||
float g;
|
||||
float b;
|
||||
float a;
|
||||
};
|
||||
|
||||
enum Interpolation {
|
||||
LINEAR = 0,
|
||||
};
|
||||
|
||||
// Host side sample
|
||||
bool Sample(float &_r, float &_g, float &_b, float &_a, float _i);
|
||||
|
||||
// Take the saved values and construct a texture
|
||||
bool ConstructTexture();
|
||||
// Read TF from the in file
|
||||
bool ReadFile();
|
||||
std::string ToString() const;
|
||||
|
||||
// Mutators
|
||||
void SetInFilename(const std::string &_inFilename);
|
||||
|
||||
// Accessors
|
||||
unsigned int Width() const { return width_; }
|
||||
ghoul::opengl::Texture * Texture() { return texture_; }
|
||||
|
||||
// TODO temp
|
||||
float * FloatData() { return floatData_; }
|
||||
|
||||
// Operators
|
||||
TransferFunction& operator=(const TransferFunction &_tf);
|
||||
|
||||
private:
|
||||
TransferFunction();
|
||||
TransferFunction(const TransferFunction &_tf);
|
||||
float *floatData_;
|
||||
|
||||
ghoul::opengl::Texture *texture_;
|
||||
unsigned int width_;
|
||||
float lower_;
|
||||
float upper_;
|
||||
bool generatedTexture_;
|
||||
std::string inFilename_;
|
||||
std::set<MappingKey> mappingKeys_;
|
||||
Interpolation interpolation_;
|
||||
|
||||
// Linearly interpolate between two values. Distance
|
||||
// is assumed to be normalized.
|
||||
inline float Lerp(float _v0, float _v1, float _d) {
|
||||
return _v0*(1.0 - _d) + _v1*_d;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
std::ostream & operator<<(std::ostream &os, const osp::TransferFunction &_tf);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
Auhtor: Victor Sand (victor.sand@gmail.com)
|
||||
Global helper functions and utilities
|
||||
*/
|
||||
|
||||
#ifndef UTILS_H_
|
||||
#define UTILS_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace osp {
|
||||
|
||||
#define INFO(x) std::cout << x << std::endl;
|
||||
#define DEBUG(x) std::cout << "DEBUG: " << x << std::endl
|
||||
#define ERROR(x) std::cout << "ERROR: " << x << std::endl
|
||||
#define WARNING(x) std::cout << "WARNING: " << x << std::endl
|
||||
|
||||
// Print the last GL error if there is one, function returns the code for
|
||||
// the error so that it can be compared to GL_NO_ERROR, for example
|
||||
unsigned int CheckGLError(std::string _location);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 __FLARE_H__
|
||||
#define __FLARE_H__
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <sgct.h>
|
||||
#include <openspace/flare/Animator.h>
|
||||
#include <openspace/flare/Raycaster.h>
|
||||
#include <openspace/flare/Config.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class Flare {
|
||||
public:
|
||||
Flare();
|
||||
~Flare();
|
||||
|
||||
void render();
|
||||
void initNavigation();
|
||||
|
||||
void keyboard(int key, int action);
|
||||
void mouse(int button, int action);
|
||||
void preSync();
|
||||
void postDraw();
|
||||
void encode();
|
||||
void decode();
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
||||
osp::Config* _config;
|
||||
osp::Raycaster* _raycaster;
|
||||
osp::Animator* _animator;
|
||||
|
||||
sgct::SharedBool _animationPaused;
|
||||
sgct::SharedBool _fpsMode;
|
||||
sgct::SharedFloat _elapsedTime;
|
||||
sgct::SharedInt _manualTimestep;
|
||||
sgct::SharedFloat _pitch;
|
||||
sgct::SharedFloat _yaw;
|
||||
sgct::SharedFloat _roll;
|
||||
sgct::SharedFloat _translateX;
|
||||
sgct::SharedFloat _translateY;
|
||||
sgct::SharedFloat _translateZ;
|
||||
sgct::SharedBool _reloadFlag;
|
||||
|
||||
float _oldTime;
|
||||
float _currentTime;
|
||||
bool _leftMouseButton;
|
||||
double _currentMouseX;
|
||||
double _currentMouseY;
|
||||
double _lastMouseX;
|
||||
double _lastMouseY;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __FLARE_H__
|
||||
@@ -0,0 +1,55 @@
|
||||
#ifndef DEVICEIDENTIFIER_H
|
||||
#define DEVICEIDENTIFIER_H
|
||||
|
||||
// std includes
|
||||
#include <array>
|
||||
#include <mutex>
|
||||
#include <memory>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
#define MAXDEVICES 16
|
||||
|
||||
enum class InputDevice {NONE, UNKNOWN, SPACENAVIGATOR, XBOX};
|
||||
|
||||
class DeviceIdentifier {
|
||||
public:
|
||||
static DeviceIdentifier& ref();
|
||||
virtual ~DeviceIdentifier();
|
||||
|
||||
static void init();
|
||||
static void deinit();
|
||||
static bool isInitialized();
|
||||
|
||||
void scanDevices();
|
||||
const int numberOfDevices() const;
|
||||
const InputDevice type(const int device) const;
|
||||
|
||||
void update();
|
||||
void update(const int device);
|
||||
|
||||
const int getButtons(const int device, unsigned char **buttons = nullptr) const;
|
||||
const int getAxes(const int device, float **axespos = nullptr) const;
|
||||
void get(const int device, unsigned char **buttons, float **axespos) const;
|
||||
|
||||
private:
|
||||
// singleton
|
||||
static DeviceIdentifier* this_;
|
||||
DeviceIdentifier(void);
|
||||
DeviceIdentifier(const DeviceIdentifier& src);
|
||||
DeviceIdentifier& operator=(const DeviceIdentifier& rhs);
|
||||
|
||||
|
||||
// member variables
|
||||
int devices_;
|
||||
std::array<InputDevice, MAXDEVICES> inputDevice_;
|
||||
std::array<int, MAXDEVICES> numberOfAxes_;
|
||||
std::array<int, MAXDEVICES> numberOfButtons_;
|
||||
std::array<float *, MAXDEVICES> axesPos_;
|
||||
std::array<unsigned char *, MAXDEVICES> buttons_;
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef EXTERNALCONNECTIONCONTROLLER_H
|
||||
#define EXTERNALCONNECTIONCONTROLLER_H
|
||||
|
||||
#include <openspace/interaction/externalcontrol/externalcontrol.h>
|
||||
#include <vector>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class ExternalConnectionController: public ExternalControl {
|
||||
public:
|
||||
|
||||
// constructors & destructor
|
||||
ExternalConnectionController();
|
||||
~ExternalConnectionController();
|
||||
|
||||
private:
|
||||
|
||||
std::vector<ExternalControl*> controllers;
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef EXTERNALCONTROL_H
|
||||
#define EXTERNALCONTROL_H
|
||||
|
||||
#include <openspace/util/pss.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class ExternalControl {
|
||||
public:
|
||||
|
||||
// constructors & destructor
|
||||
ExternalControl();
|
||||
virtual ~ExternalControl();
|
||||
|
||||
virtual void update();
|
||||
|
||||
void rotate(const glm::quat &rotation);
|
||||
void orbit(const glm::quat &rotation);
|
||||
void distance(const pss &distance);
|
||||
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,28 @@
|
||||
//#ifndef JOYSTICKEXTERNALCONTROL_H
|
||||
//#define JOYSTICKEXTERNALCONTROL_H
|
||||
//
|
||||
//#include "externalcontrol/pythonexternalcontrol.h"
|
||||
//
|
||||
//namespace openspace {
|
||||
//
|
||||
//class JoystickExternalControl: public PythonExternalControl {
|
||||
//public:
|
||||
//
|
||||
// // constructors & destructor
|
||||
// JoystickExternalControl(const char *filename);
|
||||
// ~JoystickExternalControl();
|
||||
//
|
||||
// void setInputDevice(const int device);
|
||||
// void update();
|
||||
//
|
||||
//private:
|
||||
//
|
||||
// // joystick
|
||||
// int inputDevice_;
|
||||
// int numberOfButtons_;
|
||||
// int numberOfAxes_;
|
||||
//};
|
||||
//
|
||||
//} // namespace openspace
|
||||
//
|
||||
//#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
//#ifndef KEYBOARDEXTERNALCONTROL_H
|
||||
//#define KEYBOARDEXTERNALCONTROL_H
|
||||
//
|
||||
//#include "externalcontrol/pythonexternalcontrol.h"
|
||||
//
|
||||
//namespace openspace {
|
||||
//
|
||||
//class KeyboardExternalControl: public PythonExternalControl {
|
||||
//public:
|
||||
//
|
||||
// // constructors & destructor
|
||||
// KeyboardExternalControl(const char *filename);
|
||||
// ~KeyboardExternalControl();
|
||||
//
|
||||
// void update();
|
||||
//
|
||||
// void keyboardCallback(int key, int action);
|
||||
//private:
|
||||
// int *keys_;
|
||||
//
|
||||
//};
|
||||
//
|
||||
//} // namespace openspace
|
||||
//
|
||||
//#endif
|
||||
@@ -0,0 +1,28 @@
|
||||
//#ifndef MOUSEEXTERNALCONTROL_H
|
||||
//#define MOUSEEXTERNALCONTROL_H
|
||||
//
|
||||
//#include "externalcontrol/pythonexternalcontrol.h"
|
||||
//
|
||||
//namespace openspace {
|
||||
//
|
||||
//class MouseExternalControl: public PythonExternalControl {
|
||||
//public:
|
||||
//
|
||||
// // constructors & destructor
|
||||
// MouseExternalControl(const char *filename);
|
||||
// ~MouseExternalControl();
|
||||
//
|
||||
// void update();
|
||||
//
|
||||
// void mouseButtonCallback(int key, int action);
|
||||
// void mousePosCallback(int x, int y);
|
||||
// void mouseScrollCallback(int pos);
|
||||
//private:
|
||||
//
|
||||
// int x_, y_, pos_, button1_, button2_, button3_;
|
||||
//
|
||||
//};
|
||||
//
|
||||
//} // namespace openspace
|
||||
//
|
||||
//#endif
|
||||
@@ -0,0 +1,35 @@
|
||||
//#ifndef PYTHONEXTERNALCONTROL_H
|
||||
//#define PYTHONEXTERNALCONTROL_H
|
||||
//
|
||||
//#include <thread>
|
||||
//#include <mutex>
|
||||
//
|
||||
//#include "externalcontrol/externalcontrol.h"
|
||||
//#include "python/pythonscript.h"
|
||||
//
|
||||
//namespace openspace {
|
||||
//
|
||||
//class PythonExternalControl: public ExternalControl {
|
||||
//public:
|
||||
//
|
||||
// // constructors & destructor
|
||||
// PythonExternalControl(const char *filename);
|
||||
// ~PythonExternalControl();
|
||||
//
|
||||
// static PyMethodDef* getMethodDef();
|
||||
//
|
||||
// void message(const char *text);
|
||||
// virtual void update();
|
||||
// void clear();
|
||||
//private:
|
||||
// PythonScript ps_;
|
||||
//
|
||||
//protected:
|
||||
// void run();
|
||||
// int pyarrSize_;
|
||||
// PyObject **pyarr_;
|
||||
//};
|
||||
//
|
||||
//} // namespace openspace
|
||||
//
|
||||
//#endif
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef RANDOMEXTERNALCONTROL_H
|
||||
#define RANDOMEXTERNALCONTROL_H
|
||||
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
|
||||
#include <openspace/interaction/externalcontrol/externalcontrol.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class RandomExternalControl: public ExternalControl {
|
||||
public:
|
||||
|
||||
// constructors & destructor
|
||||
RandomExternalControl();
|
||||
~RandomExternalControl();
|
||||
|
||||
private:
|
||||
std::mutex inputGuard;
|
||||
bool *keepGoing_;
|
||||
// std::thread *backgroundThread;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,78 @@
|
||||
#ifndef INTERACTIONHANDLER_H
|
||||
#define INTERACTIONHANDLER_H
|
||||
|
||||
// open space includes
|
||||
#include <openspace/util/camera.h>
|
||||
#include <openspace/interaction/externalcontrol/externalcontrol.h>
|
||||
#include <openspace/scenegraph/scenegraphnode.h>
|
||||
|
||||
// std includes
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <memory>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class InteractionHandler {
|
||||
public:
|
||||
InteractionHandler(void);
|
||||
InteractionHandler(const InteractionHandler& src);
|
||||
InteractionHandler& operator=(const InteractionHandler& rhs);
|
||||
virtual ~InteractionHandler();
|
||||
|
||||
//static void init();
|
||||
//static void deinit();
|
||||
// static InteractionHandler& ref();
|
||||
//static bool isInitialized();
|
||||
|
||||
void enable();
|
||||
void disable();
|
||||
const bool isEnabled() const;
|
||||
|
||||
void connectDevices();
|
||||
void addExternalControl(ExternalControl* controller);
|
||||
|
||||
void setCamera(Camera *camera = nullptr);
|
||||
Camera * getCamera() const;
|
||||
const psc getOrigin() const;
|
||||
void lockControls();
|
||||
void unlockControls();
|
||||
|
||||
void setFocusNode(SceneGraphNode *node);
|
||||
|
||||
void orbit(const glm::quat &rotation);
|
||||
void rotate(const glm::quat &rotation);
|
||||
void distance(const pss &distance);
|
||||
|
||||
void lookAt(const glm::quat &rotation);
|
||||
void setRotation(const glm::quat &rotation);
|
||||
|
||||
void update(const double dt);
|
||||
|
||||
double getDt();
|
||||
|
||||
void keyboardCallback(int key, int action);
|
||||
void mouseButtonCallback(int key, int action);
|
||||
void mousePositionCallback(int x, int y);
|
||||
void mouseScrollWheelCallback(int pos);
|
||||
|
||||
private:
|
||||
|
||||
Camera *camera_;
|
||||
bool enabled_;
|
||||
SceneGraphNode *node_;
|
||||
|
||||
double dt_;
|
||||
|
||||
// used for calling when updating and deallocation
|
||||
std::vector<ExternalControl*> controllers_;
|
||||
|
||||
// for locking and unlocking
|
||||
std::mutex cameraGuard_;
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,41 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 __QUERY_H__
|
||||
#define __QUERY_H__
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class SceneGraph;
|
||||
class SceneGraphNode;
|
||||
|
||||
SceneGraph* getSceneGraph();
|
||||
|
||||
SceneGraphNode* getSceneGraphNode(const std::string& name);
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // __QUERY_H__
|
||||
@@ -0,0 +1,36 @@
|
||||
#ifndef RENDERABLE_H
|
||||
#define RENDERABLE_H
|
||||
|
||||
// open space includes
|
||||
#include <openspace/util/psc.h>
|
||||
#include <openspace/util/pss.h>
|
||||
#include <openspace/util/camera.h>
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class Renderable {
|
||||
public:
|
||||
|
||||
// constructors & destructor
|
||||
Renderable(const ghoul::Dictionary& dictionary);
|
||||
virtual ~Renderable();
|
||||
|
||||
virtual bool initialize() = 0;
|
||||
virtual bool deinitialize() = 0;
|
||||
|
||||
void setBoundingSphere(const pss &boundingSphere);
|
||||
const pss &getBoundingSphere();
|
||||
|
||||
virtual void render(const Camera *camera, const psc &thisPosition) = 0;
|
||||
virtual void update();
|
||||
protected:
|
||||
Renderable();
|
||||
private:
|
||||
pss boundingSphere_;
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef RENDERABLEBODY_H
|
||||
#define RENDERABLEBODY_H
|
||||
|
||||
// open space includes
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/util/sphere.h>
|
||||
|
||||
// ghoul includes
|
||||
#include "ghoul/opengl/programobject.h"
|
||||
#include "ghoul/opengl/texture.h"
|
||||
|
||||
namespace openspace {
|
||||
/*
|
||||
class RenderableBody: public Renderable {
|
||||
public:
|
||||
|
||||
// constructors & destructor
|
||||
RenderableBody(const pss &radius);
|
||||
~RenderableBody();
|
||||
|
||||
void setProgramObject(ghoul::opengl::ProgramObject *programObject);
|
||||
void setTexture(ghoul::opengl::Texture *texture);
|
||||
|
||||
virtual void render(const Camera *camera, const psc &thisPosition);
|
||||
virtual void update();
|
||||
|
||||
private:
|
||||
ghoul::opengl::ProgramObject *programObject_;
|
||||
ghoul::opengl::Texture *texture_;
|
||||
double rad_;
|
||||
|
||||
gl4::Sphere *planet_;
|
||||
};
|
||||
*/
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,45 @@
|
||||
#ifndef RENDERABLEPLANET_H
|
||||
#define RENDERABLEPLANET_H
|
||||
|
||||
// open space includes
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/util/powerscaledsphere.h>
|
||||
|
||||
// ghoul includes
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class RenderablePlanet: public Renderable {
|
||||
public:
|
||||
|
||||
// constructors & destructor
|
||||
RenderablePlanet(const ghoul::Dictionary& dictionary);
|
||||
~RenderablePlanet();
|
||||
|
||||
bool initialize();
|
||||
bool deinitialize();
|
||||
|
||||
void setProgramObject(ghoul::opengl::ProgramObject *programObject = nullptr);
|
||||
void setTexture(ghoul::opengl::Texture *texture);
|
||||
|
||||
virtual void render(const Camera *camera, const psc &thisPosition);
|
||||
virtual void update();
|
||||
|
||||
private:
|
||||
|
||||
// shader
|
||||
ghoul::opengl::ProgramObject *programObject_;
|
||||
|
||||
// texture
|
||||
std::string _texturePath;
|
||||
ghoul::opengl::Texture *texture_;
|
||||
|
||||
// Object
|
||||
PowerScaledSphere *planet_;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,62 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 __RENDERENGINE_H__
|
||||
#define __RENDERENGINE_H__
|
||||
|
||||
#include <openspace/scenegraph/scenegraph.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class Camera;
|
||||
|
||||
class RenderEngine {
|
||||
public:
|
||||
RenderEngine();
|
||||
~RenderEngine();
|
||||
|
||||
bool initialize();
|
||||
|
||||
SceneGraph* sceneGraph();
|
||||
|
||||
// sgct wrapped functions
|
||||
bool initializeGL();
|
||||
void postSynchronizationPreDraw();
|
||||
void render();
|
||||
void postDraw();
|
||||
|
||||
// object extensions
|
||||
//virtual void encode();
|
||||
//virtual void decode();
|
||||
|
||||
private:
|
||||
Camera* _mainCamera;
|
||||
SceneGraph* _sceneGraph;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __RENDERENGINE_H__
|
||||
@@ -0,0 +1,62 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 VOLUMERAYCASTER_H
|
||||
#define VOLUMERAYCASTER_H
|
||||
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/framebufferobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
#include <sgct.h>
|
||||
|
||||
namespace openspace {
|
||||
using namespace ghoul::opengl;
|
||||
|
||||
class VolumeRaycaster {
|
||||
public:
|
||||
VolumeRaycaster();
|
||||
~VolumeRaycaster();
|
||||
void initialize();
|
||||
void render();
|
||||
|
||||
private:
|
||||
void setupTwopassRaycaster();
|
||||
void setupSinglepassRaycaster();
|
||||
|
||||
void renderWithTwopassRaycaster(glm::mat4 modelViewProjectionMatrix);
|
||||
void renderWithSinglepassRaycaster(glm::mat4 modelViewProjectionMatrix);
|
||||
|
||||
FramebufferObject* _fbo;
|
||||
Texture* _backTexture;
|
||||
Texture* _frontTexture;
|
||||
Texture* _volume;
|
||||
ProgramObject *_fboProgram, *_twopassProgram, *_singlepassProgram;
|
||||
sgct_utils::SGCTBox* _boundingBox;
|
||||
GLuint _screenQuad, _cubeCenterVBO;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // VOLUMERAYCASTER_H
|
||||
@@ -0,0 +1,46 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 __CONSTANTPOSITIONINFORMATION_H__
|
||||
#define __CONSTANTPOSITIONINFORMATION_H__
|
||||
|
||||
#include "positioninformation.h"
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class ConstantPositionInformation: public PositionInformation {
|
||||
public:
|
||||
ConstantPositionInformation(const ghoul::Dictionary& dictionary);
|
||||
virtual ~ConstantPositionInformation();
|
||||
virtual bool initialize();
|
||||
virtual const psc& position() const;
|
||||
virtual void update();
|
||||
protected:
|
||||
private:
|
||||
psc _position;
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
#endif
|
||||
@@ -0,0 +1,47 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 __POSITIONINFORMATION_H__
|
||||
#define __POSITIONINFORMATION_H__
|
||||
|
||||
#include <openspace/util/psc.h>
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class PositionInformation {
|
||||
public:
|
||||
PositionInformation(const ghoul::Dictionary& dictionary);
|
||||
virtual ~PositionInformation();
|
||||
virtual bool initialize() = 0;
|
||||
virtual const psc& position() const = 0;
|
||||
virtual void update() = 0;
|
||||
protected:
|
||||
PositionInformation();
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
#endif
|
||||
@@ -0,0 +1,103 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 SCENEGRAPH_H
|
||||
#define SCENEGRAPH_H
|
||||
|
||||
// open space includes
|
||||
#include <openspace/scenegraph/scenegraphnode.h>
|
||||
|
||||
// std includes
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
// ghoul includes
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class SceneGraph {
|
||||
public:
|
||||
|
||||
// constructors & destructor
|
||||
SceneGraph();
|
||||
~SceneGraph();
|
||||
|
||||
/**
|
||||
* Initalizes the SceneGraph by loading modules from the ${SCENEPATH} directory
|
||||
*/
|
||||
bool initialize();
|
||||
|
||||
/*
|
||||
* Clean up everything
|
||||
*/
|
||||
bool deinitialize();
|
||||
|
||||
/*
|
||||
* Load the scenegraph from the provided folder
|
||||
*/
|
||||
bool loadFromModulePath(const std::string& path);
|
||||
|
||||
/*
|
||||
* Updates all SceneGraphNodes relative positions
|
||||
*/
|
||||
void update();
|
||||
|
||||
/*
|
||||
* Evaluates if the SceneGraphNodes are visible to the provided camera
|
||||
*/
|
||||
void evaluate(Camera *camera);
|
||||
|
||||
/*
|
||||
* Render visible SceneGraphNodes using the provided camera
|
||||
*/
|
||||
void render(Camera *camera);
|
||||
|
||||
/*
|
||||
* Prints the SceneGraph tree. For debugging purposes
|
||||
*/
|
||||
void printChildren() const;
|
||||
|
||||
/*
|
||||
* Returns the root SceneGraphNode
|
||||
*/
|
||||
SceneGraphNode* root() const;
|
||||
|
||||
private:
|
||||
|
||||
void loadModulesFromModulePath(const std::string& modulePath);
|
||||
|
||||
std::string _focus, _position;
|
||||
|
||||
// actual scenegraph
|
||||
SceneGraphNode *_root;
|
||||
std::vector<SceneGraphNode*> _nodes;
|
||||
std::map<std::string, SceneGraphNode*> _allNodes;
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,103 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 SCENEGRAPHNODE_H
|
||||
#define SCENEGRAPHNODE_H
|
||||
|
||||
// open space includes
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/scenegraph/positioninformation.h>
|
||||
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
|
||||
// std includes
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class SceneGraphNode {
|
||||
public:
|
||||
|
||||
// constructors & destructor
|
||||
SceneGraphNode(const ghoul::Dictionary& dictionary);
|
||||
~SceneGraphNode();
|
||||
|
||||
bool initialize();
|
||||
bool deinitialize();
|
||||
|
||||
// essential
|
||||
void update();
|
||||
void evaluate(const Camera *camera, const psc &parentPosition = psc());
|
||||
void render(const Camera *camera, const psc &parentPosition = psc());
|
||||
|
||||
// set & get
|
||||
void addNode(SceneGraphNode* child);
|
||||
|
||||
void setName(const std::string &name);
|
||||
void setParent(SceneGraphNode *parent);
|
||||
const psc& getPosition() const;
|
||||
psc getWorldPosition() const;
|
||||
std::string nodeName() const;
|
||||
|
||||
SceneGraphNode* parent() const;
|
||||
const std::vector<SceneGraphNode*>& children() const;
|
||||
|
||||
// bounding sphere
|
||||
pss calculateBoundingSphere();
|
||||
|
||||
SceneGraphNode* get(const std::string& name);
|
||||
|
||||
void print() const;
|
||||
|
||||
// renderable
|
||||
void setRenderable(Renderable *renderable);
|
||||
const Renderable * getRenderable() const;
|
||||
|
||||
private:
|
||||
|
||||
// essential
|
||||
std::vector<SceneGraphNode*> _children;
|
||||
SceneGraphNode* _parent;
|
||||
std::string _nodeName;
|
||||
PositionInformation* _position;
|
||||
|
||||
// renderable
|
||||
Renderable *_renderable;
|
||||
bool _renderableVisible;
|
||||
|
||||
// bounding sphere
|
||||
bool _boundingSphereVisible;
|
||||
pss _boundingSphere;
|
||||
|
||||
// private helper methods
|
||||
bool sphereInsideFrustum(const psc s_pos, const pss & s_rad, const Camera *camera);
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#include <openspace/scenegraph/scenegraphnode.inl>
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,60 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 SCENEGRAPHNODE_INL
|
||||
#define SCENEGRAPHNODE_INL
|
||||
|
||||
#include <openspace/util/factorymanager.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
template<class T>
|
||||
bool safeCreationWithDictionary( T** object,
|
||||
const std::string& key,
|
||||
ghoul::Dictionary* dictionary,
|
||||
const std::string& path = "")
|
||||
{
|
||||
if(dictionary->hasKey(key)) {
|
||||
ghoul::Dictionary tmpDictionary;
|
||||
if(dictionary->getValue(key, tmpDictionary)) {
|
||||
if ( ! tmpDictionary.hasKey("Path") && path != "") {
|
||||
tmpDictionary.setValue("Path", path);
|
||||
}
|
||||
std::string renderableType;
|
||||
if(tmpDictionary.getValue("Type", renderableType)) {
|
||||
ghoul::TemplateFactory<T>* factory = FactoryManager::ref().factoryByType<T>();
|
||||
T* tmp = factory->create(renderableType, tmpDictionary);
|
||||
if(tmp != nullptr) {
|
||||
*object = tmp;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,51 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 __SPICEPOSITIONINFORMATION_H__
|
||||
#define __SPICEPOSITIONINFORMATION_H__
|
||||
|
||||
#include <openspace/scenegraph/positioninformation.h>
|
||||
|
||||
#include <openspace/util/psc.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class SpicePositionInformation: public PositionInformation {
|
||||
public:
|
||||
SpicePositionInformation(const ghoul::Dictionary& dictionary);
|
||||
virtual ~SpicePositionInformation();
|
||||
virtual bool initialize();
|
||||
virtual const psc& position() const;
|
||||
virtual void update();
|
||||
protected:
|
||||
private:
|
||||
|
||||
std::string _targetName, _originName;
|
||||
int _target, _origin;
|
||||
psc _position;
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
#endif
|
||||
@@ -0,0 +1,111 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* GHOUL *
|
||||
* General Helpful Open Utility Library *
|
||||
* *
|
||||
* Copyright (c) 2012-2014 *
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifdef GHL_TIMING_TESTS
|
||||
|
||||
#ifdef WIN32
|
||||
#define START_TIMER(__name__, __stream__, __num__) \
|
||||
__stream__ << #__name__; \
|
||||
double __name__##Total = 0.0; \
|
||||
unsigned int __name__##Num = 0; \
|
||||
for (__name__##Num = 0; __name__##Num < __num__; ++__name__##Num) { \
|
||||
reset(); \
|
||||
LARGE_INTEGER __name__##Start; \
|
||||
LARGE_INTEGER __name__##End; \
|
||||
QueryPerformanceCounter(&__name__##Start)
|
||||
|
||||
#define START_TIMER_NO_RESET(__name__, __stream__, __num__) \
|
||||
__stream__ << #__name__; \
|
||||
double __name__##Total = 0.0; \
|
||||
unsigned int __name__##Num = 0; \
|
||||
for (__name__##Num = 0; __name__##Num < __num__; ++__name__##Num) { \
|
||||
LARGE_INTEGER __name__##Start; \
|
||||
LARGE_INTEGER __name__##End; \
|
||||
QueryPerformanceCounter(&__name__##Start)
|
||||
|
||||
#define START_TIMER_PREPARE(__name__, __stream__, __num__, __prepare__) \
|
||||
__stream__ << #__name__; \
|
||||
double __name__##Total = 0.0; \
|
||||
unsigned int __name__##Num = 0; \
|
||||
for (__name__##Num = 0; __name__##Num < __num__; ++__name__##Num) { \
|
||||
reset(); \
|
||||
__prepare__; \
|
||||
LARGE_INTEGER __name__##Start; \
|
||||
LARGE_INTEGER __name__##End; \
|
||||
QueryPerformanceCounter(&__name__##Start)
|
||||
|
||||
#define FINISH_TIMER(__name__, __stream__) \
|
||||
QueryPerformanceCounter(&__name__##End); \
|
||||
LARGE_INTEGER freq; \
|
||||
QueryPerformanceFrequency(&freq); \
|
||||
const double freqD = double(freq.QuadPart) / 1000000.0; \
|
||||
const double res = ((__name__##End.QuadPart - __name__##Start.QuadPart) / freqD);\
|
||||
__name__##Total += res; \
|
||||
} \
|
||||
__stream__ << '\t' << __name__##Total / __name__##Num << "us\n";
|
||||
|
||||
#else
|
||||
|
||||
#include <chrono>
|
||||
|
||||
#define START_TIMER(__name__, __stream__, __num__) \
|
||||
__stream__ << #__name__; \
|
||||
std::chrono::nanoseconds __name__##Total = std::chrono::nanoseconds(0); \
|
||||
unsigned int __name__##Num = 0; \
|
||||
for (__name__##Num = 0; __name__##Num < __num__; ++__name__##Num) { \
|
||||
reset(); \
|
||||
std::chrono::high_resolution_clock::time_point __name__##End; \
|
||||
std::chrono::high_resolution_clock::time_point __name__##Start = \
|
||||
std::chrono::high_resolution_clock::now()
|
||||
|
||||
#define START_TIMER_NO_RESET(__name__, __stream__, __num__) \
|
||||
__stream__ << #__name__; \
|
||||
std::chrono::nanoseconds __name__##Total = std::chrono::nanoseconds(0); \
|
||||
unsigned int __name__##Num = 0; \
|
||||
for (__name__##Num = 0; __name__##Num < __num__; ++__name__##Num) { \
|
||||
std::chrono::high_resolution_clock::time_point __name__##End; \
|
||||
std::chrono::high_resolution_clock::time_point __name__##Start = \
|
||||
std::chrono::high_resolution_clock::now()
|
||||
|
||||
#define START_TIMER_PREPARE(__name__, __stream__, __num__, __prepare__) \
|
||||
__stream__ << #__name__; \
|
||||
std::chrono::nanoseconds __name__##Total = std::chrono::nanoseconds(0); \
|
||||
unsigned int __name__##Num = 0; \
|
||||
for (__name__##Num = 0; __name__##Num < __num__; ++__name__##Num) { \
|
||||
reset(); \
|
||||
__prepare__; \
|
||||
std::chrono::high_resolution_clock::time_point __name__##End; \
|
||||
std::chrono::high_resolution_clock::time_point __name__##Start = \
|
||||
std::chrono::high_resolution_clock::now()
|
||||
|
||||
#define FINISH_TIMER(__name__, __stream__) \
|
||||
__name__##End = std::chrono::high_resolution_clock::now(); \
|
||||
const std::chrono::nanoseconds d = __name__##End - __name__##Start; \
|
||||
__name__##Total += d; \
|
||||
} \
|
||||
__stream__ << #__name__ << '\t' << __name__##Total.count() / 1000.0 << "us" << '\n';
|
||||
#endif
|
||||
|
||||
#endif // GHL_TIMING_TESTS
|
||||
@@ -0,0 +1,83 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* GHOUL *
|
||||
* General Helpful Open Utility Library *
|
||||
* *
|
||||
* Copyright (c) 2012-2014 *
|
||||
* *
|
||||
* 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 "gtest/gtest.h"
|
||||
|
||||
#include <openspace/util/psc.h>
|
||||
#include <openspace/util/pss.h>
|
||||
|
||||
class PowerscaleCoordinatesTest : public testing::Test {
|
||||
protected:
|
||||
PowerscaleCoordinatesTest() {
|
||||
}
|
||||
|
||||
~PowerscaleCoordinatesTest() {
|
||||
}
|
||||
|
||||
void reset() {
|
||||
}
|
||||
|
||||
openspace::SceneGraph* scenegraph;
|
||||
};
|
||||
|
||||
|
||||
TEST_F(PowerscaleCoordinatesTest, psc) {
|
||||
|
||||
openspace::psc reference(2.0, 1.0, 1.1, 1.0);
|
||||
|
||||
openspace::psc first(1.0,0.0,1.0,0.0);
|
||||
openspace::psc second(1.9,1.0,1.0,1.0);
|
||||
|
||||
EXPECT_EQ(reference, first + second);
|
||||
EXPECT_TRUE(reference == (first + second));
|
||||
|
||||
openspace::psc third = first;
|
||||
first[0] = 0.0;
|
||||
|
||||
EXPECT_TRUE(third != first);
|
||||
|
||||
|
||||
}
|
||||
|
||||
TEST_F(PowerscaleCoordinatesTest, pss) {
|
||||
|
||||
openspace::pss first(1.0,1.0);
|
||||
openspace::pss second(1.0,-1.0);
|
||||
EXPECT_EQ(openspace::pss(1.01,1.0), first + second);
|
||||
EXPECT_EQ(openspace::pss(1.01,1.0), second + first);
|
||||
/*
|
||||
EXPECT_TRUE(first < (first + second));
|
||||
bool retu =(second < (first + second));
|
||||
|
||||
std::cout << "retu: " << retu << std::endl;
|
||||
EXPECT_TRUE(retu);
|
||||
|
||||
EXPECT_FALSE(first > (first + second));
|
||||
EXPECT_FALSE(second > (first + second));
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* GHOUL *
|
||||
* General Helpful Open Utility Library *
|
||||
* *
|
||||
* Copyright (c) 2012-2014 *
|
||||
* *
|
||||
* 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 "gtest/gtest.h"
|
||||
|
||||
#include <openspace/scenegraph/scenegraph.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/spice.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
|
||||
class SceneGraphTest : public testing::Test {
|
||||
protected:
|
||||
SceneGraphTest() {
|
||||
_scenegraph = new openspace::SceneGraph;
|
||||
}
|
||||
|
||||
~SceneGraphTest() {
|
||||
_scenegraph = new openspace::SceneGraph;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
delete _scenegraph;
|
||||
_scenegraph = new openspace::SceneGraph;
|
||||
}
|
||||
|
||||
openspace::SceneGraph* _scenegraph;
|
||||
};
|
||||
|
||||
TEST_F(SceneGraphTest, SceneGraphNode) {
|
||||
|
||||
openspace::SceneGraphNode* node = new openspace::SceneGraphNode(ghoul::Dictionary());
|
||||
|
||||
// Should not have a renderable and position should be 0,0,0,0 (undefined).
|
||||
EXPECT_EQ(nullptr, node->getRenderable());
|
||||
EXPECT_EQ(openspace::psc(), node->getPosition());
|
||||
|
||||
delete node;
|
||||
ghoul::Dictionary nodeDictionary;
|
||||
|
||||
ghoul::Dictionary positionDictionary;
|
||||
ghoul::Dictionary positionPositionArrayDictionary;
|
||||
|
||||
ghoul::Dictionary renderableDictionary;
|
||||
|
||||
renderableDictionary.setValue("Type", std::string("RenderablePlanet"));
|
||||
|
||||
positionPositionArrayDictionary.setValue("1", 1.0);
|
||||
positionPositionArrayDictionary.setValue("2", 1.0);
|
||||
positionPositionArrayDictionary.setValue("3", 1.0);
|
||||
positionPositionArrayDictionary.setValue("4", 1.0);
|
||||
|
||||
positionDictionary.setValue("Type", std::string("Static"));
|
||||
positionDictionary.setValue("Position", positionPositionArrayDictionary);
|
||||
|
||||
nodeDictionary.setValue("Position", positionDictionary);
|
||||
nodeDictionary.setValue("Renderable", renderableDictionary);
|
||||
|
||||
node = new openspace::SceneGraphNode(nodeDictionary);
|
||||
|
||||
// This node should have a renderable (probably no good values but an existing one)
|
||||
EXPECT_TRUE(node->getRenderable());
|
||||
|
||||
// position should be initialized
|
||||
EXPECT_EQ(openspace::psc(1.0,1.0,1.0,1.0), node->getPosition());
|
||||
|
||||
delete node;
|
||||
}
|
||||
|
||||
TEST_F(SceneGraphTest, Loading) {
|
||||
|
||||
|
||||
// Should not successfully load a non existing scenegraph
|
||||
EXPECT_FALSE(_scenegraph->loadFromModulePath(absPath("${TESTDIR}/ScenegraphTestNonExisting")));
|
||||
|
||||
// Existing scenegraph should load
|
||||
EXPECT_TRUE(_scenegraph->loadFromModulePath(absPath("${TESTDIR}/ScenegraphTest")));
|
||||
|
||||
// This loading should fail regardless of existing or not since the
|
||||
// scenegraph is already loaded
|
||||
EXPECT_FALSE(_scenegraph->loadFromModulePath(absPath("${TESTDIR}/ScenegraphTest")));
|
||||
}
|
||||
|
||||
TEST_F(SceneGraphTest, Reinitializing) {
|
||||
|
||||
// Existing scenegraph should load
|
||||
EXPECT_TRUE(_scenegraph->loadFromModulePath(absPath("${TESTDIR}/ScenegraphTest")));
|
||||
|
||||
_scenegraph->deinitialize();
|
||||
|
||||
// Existing scenegraph should load
|
||||
EXPECT_TRUE(_scenegraph->loadFromModulePath(absPath("${TESTDIR}/ScenegraphTest")));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
#ifndef CAMERA_H
|
||||
#define CAMERA_H
|
||||
|
||||
// open space includes
|
||||
#include <openspace/util/psc.h>
|
||||
|
||||
// glm includes
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class Camera {
|
||||
public:
|
||||
|
||||
// constructors & destructor
|
||||
Camera();
|
||||
~Camera();
|
||||
|
||||
void setPosition(psc pos);
|
||||
const psc& getPosition() const;
|
||||
|
||||
void setViewProjectionMatrix(const glm::mat4 &viewProjectionMatrix);
|
||||
void setCameraDirection(const glm::vec3 &cameraDirection);
|
||||
|
||||
const glm::mat4 & getViewProjectionMatrix() const;
|
||||
const glm::mat4 & getViewRotationMatrix() const;
|
||||
void compileViewRotationMatrix();
|
||||
|
||||
void rotate(glm::quat rotation);
|
||||
void setRotation(glm::quat rotation);
|
||||
const glm::quat & getRotation() const;
|
||||
|
||||
const glm::vec3 & getViewDirection() const;
|
||||
const float & getMaxFov() const;
|
||||
const float & getSinMaxFov() const;
|
||||
void setMaxFov(const float &fov);
|
||||
void setScaling(const glm::vec2 &scaling);
|
||||
const glm::vec2 & getScaling() const;
|
||||
|
||||
private:
|
||||
float maxFov_;
|
||||
float sinMaxFov_;
|
||||
psc position_;
|
||||
glm::mat4 viewProjectionMatrix_;
|
||||
glm::vec3 viewDirection_;
|
||||
glm::vec3 cameraDirection_;
|
||||
glm::vec2 scaling_;
|
||||
|
||||
glm::quat viewRotation_;
|
||||
glm::mat4 viewRotationMatrix_; // compiled from the quaternion
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,84 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 __FACTORYMANAGER_H__
|
||||
#define __FACTORYMANAGER_H__
|
||||
|
||||
// ghoul includes
|
||||
#include <ghoul/misc/templatefactory.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
|
||||
#include <openspace/scenegraph/positioninformation.h>
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class FactoryManager {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Static initializer that initializes the static member. This needs to be done before
|
||||
* the FactoryManager can be used. If the manager has been already initialized, an
|
||||
* assertion will be triggered.
|
||||
*/
|
||||
static void initialize();
|
||||
static void deinitialize();
|
||||
|
||||
/**
|
||||
* This method returns a reference to the initialized FactoryManager. If the manager
|
||||
* has not been initialized, an assertion will be triggered.
|
||||
* \return An initialized reference to the singleton manager
|
||||
*/
|
||||
static FactoryManager& ref();
|
||||
|
||||
template<class T>
|
||||
ghoul::TemplateFactory<T>* factoryByType();
|
||||
|
||||
private:
|
||||
FactoryManager();
|
||||
|
||||
/// Not implemented on purpose, using this should result in an error
|
||||
FactoryManager(const FactoryManager& c);
|
||||
|
||||
/// Not implemented on purpose, using this should result in an error
|
||||
~FactoryManager();
|
||||
|
||||
static FactoryManager* _manager; ///<Singleton member
|
||||
|
||||
ghoul::TemplateFactory<Renderable> _renderableFactory;
|
||||
ghoul::TemplateFactory<PositionInformation> _positionInformationFactory;
|
||||
|
||||
};
|
||||
|
||||
// Forward declare template specializations
|
||||
template<>
|
||||
ghoul::TemplateFactory<Renderable()>* FactoryManager::factoryByType();
|
||||
template<>
|
||||
ghoul::TemplateFactory<PositionInformation()>* FactoryManager::factoryByType();
|
||||
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
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.
|
||||
*/
|
||||
#ifndef GEOMETRY_H
|
||||
#define GEOMETRY_H
|
||||
|
||||
// open space includes
|
||||
#include <openspace/util/vbo.h>
|
||||
|
||||
namespace gl4
|
||||
{
|
||||
class Geometry : public VBO
|
||||
{
|
||||
public:
|
||||
//initializers
|
||||
Geometry();
|
||||
virtual ~Geometry();
|
||||
|
||||
virtual void init();
|
||||
glm::mat4 getTransform();
|
||||
|
||||
private:
|
||||
glm::vec2 _limits[3];
|
||||
glm::vec3 _position;
|
||||
glm::mat4 _rotation;
|
||||
protected:
|
||||
std::string _texture;
|
||||
glm::mat4 _transform;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
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.
|
||||
*/
|
||||
#ifndef PLANET_H
|
||||
#define PLANET_H
|
||||
|
||||
// open space includes
|
||||
#include <openspace/util/pss.h>
|
||||
#include <openspace/util/vbo_template.h>
|
||||
|
||||
// std includes
|
||||
#include <string>
|
||||
|
||||
namespace openspace
|
||||
{
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GLfloat location[4];
|
||||
GLfloat tex[2];
|
||||
GLfloat normal[3];
|
||||
GLubyte padding[28]; // Pads the struct out to 64 bytes for performance increase
|
||||
} Vertex;
|
||||
|
||||
class Planet
|
||||
{
|
||||
public:
|
||||
//initializers
|
||||
Planet(pss radius, int levels = 4);
|
||||
~Planet();
|
||||
|
||||
void setHeightMap(const std::string &path);
|
||||
void render();
|
||||
|
||||
private:
|
||||
|
||||
VBO<Vertex> *vbo;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
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.
|
||||
*/
|
||||
#ifndef __POWERSCALEDSPHERE_H__
|
||||
#define __POWERSCALEDSPHERE_H__
|
||||
|
||||
// open space includes
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
#include <openspace/util/psc.h>
|
||||
#include <openspace/util/pss.h>
|
||||
|
||||
|
||||
namespace openspace {
|
||||
|
||||
|
||||
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GLfloat location[4];
|
||||
GLfloat tex[2];
|
||||
GLfloat normal[3];
|
||||
GLubyte padding[28]; // Pads the struct out to 64 bytes for performance increase
|
||||
} Vertex;
|
||||
|
||||
|
||||
class PowerScaledSphere
|
||||
{
|
||||
public:
|
||||
//initializers
|
||||
PowerScaledSphere(const pss radius, int segments = 8);
|
||||
~PowerScaledSphere();
|
||||
|
||||
bool initialize();
|
||||
|
||||
void render();
|
||||
|
||||
private:
|
||||
GLuint _vaoID;
|
||||
GLuint _vBufferID;
|
||||
GLuint _iBufferID;
|
||||
|
||||
GLenum _mode;
|
||||
unsigned int _isize;
|
||||
unsigned int _vsize;
|
||||
Vertex *_varray;
|
||||
int *_iarray;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,98 @@
|
||||
#ifndef PSC_H
|
||||
#define PSC_H
|
||||
|
||||
// open space includes
|
||||
// glm includes
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace openspace
|
||||
{
|
||||
|
||||
// forward declare the power scaled scalars
|
||||
class pss;
|
||||
|
||||
class psc {
|
||||
public:
|
||||
|
||||
// constructors
|
||||
psc();
|
||||
psc(const glm::vec4 &v);
|
||||
psc(const glm::dvec4 &v);
|
||||
psc(const glm::vec3 &v);
|
||||
psc(const glm::dvec3 &v);
|
||||
psc(const float &f1,const float &f2,const float &f3,const float &f4);
|
||||
psc(const double &d1,const double &d2,const double &d3,const double &d4);
|
||||
|
||||
static psc CreatePSC(double d1, double d2, double d3);
|
||||
|
||||
// print n' debug
|
||||
void print() const;
|
||||
void print(const char *name) const;
|
||||
|
||||
// get functions
|
||||
const double * value_ptr();
|
||||
const float * value_ptrf();
|
||||
glm::dvec4 getVec4() const;
|
||||
glm::vec4 getVec4f();
|
||||
glm::dvec3 getVec3() const;
|
||||
glm::vec3 getVec3f();
|
||||
pss length() const;
|
||||
glm::dvec3 getDirection() const;
|
||||
glm::vec3 getDirectionf() const;
|
||||
|
||||
// multiplication
|
||||
psc mul(const glm::mat4 &m) const;
|
||||
psc mul(const glm::dmat4 &m) const;
|
||||
|
||||
// operator overloading
|
||||
psc & operator=(const psc &rhs);
|
||||
psc & operator+=(const psc &rhs);
|
||||
const psc operator+(const psc &rhs) const;
|
||||
psc & operator-=(const psc &rhs);
|
||||
const psc operator-(const psc &rhs) const;
|
||||
double& operator[](unsigned int idx);
|
||||
const double& operator[](unsigned int idx) const;
|
||||
const double dot(const psc &rhs) const;
|
||||
const double angle(const psc &rhs) const;
|
||||
|
||||
// scalar operators
|
||||
const psc operator*(const double &rhs) const;
|
||||
const psc operator*(const float &rhs) const;
|
||||
psc &operator*=(const pss &rhs);
|
||||
const psc operator*(const pss &rhs) const;
|
||||
|
||||
// comparasion
|
||||
bool operator==(const psc &other) const;
|
||||
bool operator!=(const psc &other) const;
|
||||
bool operator<(const psc &other) const;
|
||||
bool operator>(const psc &other) const;
|
||||
bool operator<=(const psc &other) const;
|
||||
bool operator>=(const psc &other) const;
|
||||
|
||||
// glm integration
|
||||
psc & operator=(const glm::vec4 &rhs);
|
||||
psc & operator=(const glm::vec3 &rhs);
|
||||
psc & operator=(const glm::dvec4 &rhs);
|
||||
psc & operator=(const glm::dvec3 &rhs);
|
||||
|
||||
friend std::ostream& operator<<(::std::ostream& os, const psc& rhs);
|
||||
|
||||
// allow the power scaled scalars to acces private members
|
||||
friend class pss;
|
||||
private:
|
||||
|
||||
// internal glm vector
|
||||
glm::dvec4 vec_;
|
||||
|
||||
// float vector used when returning float values
|
||||
glm::vec4 vecf_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,91 @@
|
||||
#ifndef PSS_H
|
||||
#define PSS_H
|
||||
|
||||
// glm includes
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace openspace
|
||||
{
|
||||
|
||||
// forward declare the power scaled coordinates
|
||||
class psc;
|
||||
|
||||
class pss {
|
||||
public:
|
||||
|
||||
// constructors
|
||||
pss();
|
||||
pss(const glm::vec2 &v);
|
||||
pss(const glm::dvec2 &v);
|
||||
pss(const float &f1,const float &f2);
|
||||
pss(const double &d1,const double &d2);
|
||||
static pss CreatePSS(double d1);
|
||||
|
||||
// print n' debug
|
||||
void print() const;
|
||||
void print(const char *name) const;
|
||||
|
||||
// get functions
|
||||
const double * value_ptr();
|
||||
const float * value_ptrf();
|
||||
glm::dvec2 getVec2() const;
|
||||
glm::vec2 getVec2f();
|
||||
double length() const;
|
||||
float lengthf() const;
|
||||
|
||||
// operator overloading
|
||||
pss & operator=(const pss &rhs);
|
||||
pss & operator+=(const pss &rhs);
|
||||
const pss operator+(const pss &rhs) const;
|
||||
pss & operator-=(const pss &rhs);
|
||||
const pss operator-(const pss &rhs) const;
|
||||
pss & operator*=(const pss &rhs);
|
||||
const pss operator*(const pss &rhs) const;
|
||||
pss & operator*=(const double &rhs);
|
||||
const pss operator*(const double &rhs) const;
|
||||
pss & operator*=(const float &rhs);
|
||||
const pss operator*(const float &rhs) const;
|
||||
double& operator[](unsigned int idx);
|
||||
const double& operator[](unsigned int idx) const;
|
||||
|
||||
// comparasion
|
||||
bool operator==(const pss &other) const;
|
||||
bool operator<(const pss &other) const;
|
||||
bool operator>(const pss &other) const;
|
||||
bool operator<=(const pss &other) const;
|
||||
bool operator>=(const pss &other) const;
|
||||
|
||||
bool operator==(const double &other) const;
|
||||
bool operator<(const double &other) const;
|
||||
bool operator>(const double &other) const;
|
||||
bool operator<=(const double &other) const;
|
||||
bool operator>=(const double &other) const;
|
||||
|
||||
// glm integration
|
||||
pss & operator=(const glm::vec2 &rhs);
|
||||
pss & operator=(const float &rhs);
|
||||
pss & operator=(const glm::dvec2 &rhs);
|
||||
pss & operator=(const double &rhs);
|
||||
|
||||
friend std::ostream& operator<<(::std::ostream& os, const pss& rhs);
|
||||
|
||||
// allow the power scaled coordinates to acces private members
|
||||
friend class psc;
|
||||
private:
|
||||
|
||||
// internal glm vector
|
||||
glm::dvec2 vec_;
|
||||
|
||||
// float vector used when returning float values
|
||||
glm::vec2 vecf_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
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.
|
||||
*/
|
||||
#ifndef SPHERE_H
|
||||
#define SPHERE_H
|
||||
|
||||
// open space includes
|
||||
#include <openspace/util/geometry.h>
|
||||
|
||||
namespace gl4
|
||||
{
|
||||
class Sphere: public Geometry
|
||||
{
|
||||
public:
|
||||
//initializers
|
||||
Sphere(float radius = 1.0f, int segments = 8, bool tessellation = false);
|
||||
~Sphere();
|
||||
|
||||
private:
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,42 @@
|
||||
#ifndef SPICE_H
|
||||
#define SPICE_H
|
||||
|
||||
// std includes
|
||||
#include <string>
|
||||
|
||||
namespace openspace
|
||||
{
|
||||
|
||||
class Spice {
|
||||
public:
|
||||
virtual ~Spice();
|
||||
|
||||
static void init();
|
||||
static void deinit();
|
||||
static Spice& ref();
|
||||
static bool isInitialized();
|
||||
|
||||
void loadDefaultKernels();
|
||||
bool loadKernel(const std::string &path);
|
||||
|
||||
void bod_NameToInt(const std::string &name, int *id, int *success);
|
||||
bool getRadii(const std::string & name, double radii[3], int *n);
|
||||
|
||||
bool spk_getPosition(const std::string &target, const std::string &origin, double state[3]);
|
||||
void spk_getPosition(int target, int origin, double state[3]);
|
||||
bool spk_getOrientation(const std::string &target, double state[3][3]);
|
||||
|
||||
private:
|
||||
static Spice* this_;
|
||||
Spice(void);
|
||||
Spice(const Spice& src);
|
||||
Spice& operator=(const Spice& rhs);
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef ENGINETIME_H
|
||||
#define ENGINETIME_H
|
||||
|
||||
namespace openspace
|
||||
{
|
||||
|
||||
class Time {
|
||||
public:
|
||||
virtual ~Time();
|
||||
|
||||
static void init();
|
||||
static void deinit();
|
||||
static Time& ref();
|
||||
static bool isInitialized();
|
||||
|
||||
void setTime(const char* stringTime);
|
||||
double getTime();
|
||||
|
||||
private:
|
||||
static Time* this_;
|
||||
Time(void);
|
||||
Time(const Time& src);
|
||||
Time& operator=(const Time& rhs);
|
||||
|
||||
double time_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
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.
|
||||
*/
|
||||
#ifndef VBO_H
|
||||
#define VBO_H
|
||||
|
||||
// sgct includes
|
||||
//#include "sgct.h"
|
||||
#include <ghoul/opengl/opengl>
|
||||
|
||||
|
||||
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GLfloat location[3];
|
||||
GLfloat tex[2];
|
||||
GLfloat normal[3];
|
||||
GLfloat color[4];
|
||||
GLfloat attribute[3];
|
||||
GLfloat float_attribute;
|
||||
//GLubyte padding[4]; // Pads the struct out to 64 bytes for performance increase
|
||||
} Vertex;
|
||||
|
||||
namespace gl4
|
||||
{
|
||||
class VBO
|
||||
{
|
||||
public:
|
||||
//initializers
|
||||
VBO();
|
||||
~VBO();
|
||||
|
||||
// init VBO
|
||||
virtual void init();
|
||||
void setProportions(float w, float h) { _w = w; _h = h;};
|
||||
|
||||
// render
|
||||
void render();
|
||||
private:
|
||||
|
||||
GLuint _vaoID;
|
||||
GLuint _vBufferID;
|
||||
GLuint _iBufferID;
|
||||
float _w;
|
||||
float _h;
|
||||
|
||||
protected:
|
||||
// arrays with all triangles and indices
|
||||
GLenum _mode;
|
||||
unsigned int _isize;
|
||||
unsigned int _vsize;
|
||||
Vertex *_varray;
|
||||
int *_iarray;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
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.
|
||||
*/
|
||||
#ifndef VBOTEMPLATE_H
|
||||
#define VBOTEMPLATE_H
|
||||
|
||||
// std includes
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
|
||||
// sgct includes
|
||||
#include "ghoul/logging/consolelog.h"
|
||||
|
||||
// sgct includes
|
||||
//#include "sgct.h"
|
||||
#include <ghoul/opengl/opengl>
|
||||
|
||||
|
||||
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
|
||||
|
||||
namespace openspace
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
class VBO {
|
||||
public:
|
||||
//initializers
|
||||
VBO(const std::vector<std::tuple<int, GLenum, int> > descriptor, T *varray, int vsize, int *iarray, int isize): descriptor_(descriptor), isize_(isize), vsize_(vsize), varray_(varray), iarray_(iarray) {
|
||||
static_assert(std::is_pod<T>::value, "Template typename should be a POD");
|
||||
vBufferID_ = 0;
|
||||
iBufferID_ = 0;
|
||||
vaoID_ = 0;
|
||||
}
|
||||
~VBO() {};
|
||||
|
||||
// init VBO
|
||||
void init() {
|
||||
|
||||
//ghoul logging
|
||||
std::string _loggerCat = "VBO::init";
|
||||
|
||||
GLuint errorID = glGetError();
|
||||
glGenVertexArrays(1, &vaoID_);
|
||||
|
||||
// First VAO setup
|
||||
glBindVertexArray(vaoID_);
|
||||
|
||||
glGenBuffers(1, &vBufferID_);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vBufferID_);
|
||||
glBufferData(GL_ARRAY_BUFFER, vsize_*sizeof(T), varray_, GL_STATIC_DRAW);
|
||||
|
||||
|
||||
for(size_t i = 0; i < descriptor_.size(); ++i) {
|
||||
glVertexAttribPointer(i,std::get<0>(descriptor_.at(i)), std::get<1>(descriptor_.at(i)), GL_FALSE, sizeof(T), BUFFER_OFFSET(std::get<2>(descriptor_.at(i))));
|
||||
glEnableVertexAttribArray(i);
|
||||
}
|
||||
|
||||
glGenBuffers(1, &iBufferID_);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, iBufferID_);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, isize_*sizeof(int), iarray_, GL_STATIC_DRAW);
|
||||
|
||||
if(vBufferID_ == 0) {
|
||||
LERROR("Vertex buffer not initialized");
|
||||
}
|
||||
if(iBufferID_ == 0) {
|
||||
LERROR("Index buffer not initialized");
|
||||
}
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
errorID = glGetError();
|
||||
if(errorID != GL_NO_ERROR)
|
||||
{
|
||||
LERROR("OpenGL error: " << glewGetErrorString(errorID));
|
||||
LERROR("Attempting to proceed anyway. Expect rendering errors or a crash.");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// render
|
||||
void render() {
|
||||
glBindVertexArray(vaoID_); // select first VAO
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, iBufferID_);
|
||||
glDrawElements(GL_TRIANGLES, isize_, GL_UNSIGNED_INT, BUFFER_OFFSET(0));
|
||||
glBindVertexArray(0);
|
||||
};
|
||||
private:
|
||||
|
||||
GLuint vaoID_;
|
||||
GLuint vBufferID_;
|
||||
GLuint iBufferID_;
|
||||
|
||||
unsigned int isize_;
|
||||
unsigned int vsize_;
|
||||
|
||||
std::vector<std::tuple<int, GLenum, int> > descriptor_;
|
||||
T *varray_;
|
||||
int *iarray_;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user