More code cleanup, force inclusion of swizzling for GLM

This commit is contained in:
Alexander Bock
2014-09-19 17:44:33 +02:00
parent 51be4b1788
commit dd629db53d
11 changed files with 1241 additions and 1228 deletions

View File

@@ -74,6 +74,7 @@ set(DEPENDENT_LIBS ${DEPENDENT_LIBS} ${SGCT_LIBRARIES})
# GLM
set(GLM_ROOT_DIR "${GHOUL_ROOT_DIR}/ext/glm")
find_package(GLM REQUIRED)
add_definitions(-DGLM_SWIZZLE)
include_directories(${GLM_INCLUDE_DIRS})
# GLEW

View File

@@ -1,105 +1,106 @@
/*****************************************************************************************
* *
* 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 __RENDERABLEVOLUMECL_H__
#define __RENDERABLEVOLUMECL_H__
// open space includes
#include <openspace/rendering/renderablevolume.h>
// ghoul includes
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/framebufferobject.h>
#include <ghoul/opencl/clcontext.h>
#include <ghoul/opencl/clcommandqueue.h>
#include <ghoul/opencl/clprogram.h>
#include <ghoul/opencl/clkernel.h>
#include <ghoul/opencl/clworksize.h>
#include <ghoul/io/rawvolumereader.h>
#include <ghoul/filesystem/file.h>
#define SGCT_WINDOWS_INCLUDE
#include <sgct.h>
namespace sgct_utils {
class SGCTBox;
}
//#include <vector>
//#include <string>
#ifdef __APPLE__
#include <memory>
#else
#include <mutex>
#endif
namespace openspace {
class RenderableVolumeCL: public RenderableVolume {
public:
// constructors & destructor
RenderableVolumeCL(const ghoul::Dictionary& dictionary);
~RenderableVolumeCL();
bool initialize();
bool deinitialize();
virtual void render(const Camera *camera, const psc& thisPosition);
virtual void update();
private:
void safeKernelCompilation();
std::string _filename;
ghoul::RawVolumeReader::ReadHints _hints;
float _stepSize;
ghoul::opengl::FramebufferObject* _fbo;
ghoul::opengl::Texture* _backTexture;
ghoul::opengl::Texture* _frontTexture;
ghoul::opengl::Texture* _volume;
ghoul::opengl::Texture* _output;
ghoul::opengl::ProgramObject *_fboProgram;
ghoul::opengl::ProgramObject *_quadProgram;
sgct_utils::SGCTBox* _boundingBox;
GLuint _screenQuad;
ghoul::opencl::CLContext _context;
ghoul::opencl::CLCommandQueue _commands;
ghoul::opencl::CLProgram _program;
ghoul::opencl::CLKernel _kernel;
ghoul::opencl::CLWorkSize* _ws;
cl_mem _clBackTexture, _clFrontTexture, _clVolume, _clOutput;
ghoul::filesystem::File* _kernelSourceFile;
bool _kernelUpdateOnSave;
std::mutex* _kernelMutex;
};
} // namespace openspace
#endif
// This is still in the repository to be cannibalized for a possible rewrite (ab)
///*****************************************************************************************
// * *
// * 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 __RENDERABLEVOLUMECL_H__
//#define __RENDERABLEVOLUMECL_H__
//
//// open space includes
//#include <openspace/rendering/renderablevolume.h>
//
//// ghoul includes
//#include <ghoul/opengl/programobject.h>
//#include <ghoul/opengl/texture.h>
//#include <ghoul/opengl/framebufferobject.h>
//#include <ghoul/opencl/clcontext.h>
//#include <ghoul/opencl/clcommandqueue.h>
//#include <ghoul/opencl/clprogram.h>
//#include <ghoul/opencl/clkernel.h>
//#include <ghoul/opencl/clworksize.h>
//#include <ghoul/io/rawvolumereader.h>
//#include <ghoul/filesystem/file.h>
//
//#define SGCT_WINDOWS_INCLUDE
//#include <sgct.h>
//
//namespace sgct_utils {
// class SGCTBox;
//}
//
////#include <vector>
////#include <string>
//#ifdef __APPLE__
// #include <memory>
//#else
// #include <mutex>
//#endif
//
//namespace openspace {
//
//class RenderableVolumeCL: public RenderableVolume {
//public:
//
// // constructors & destructor
// RenderableVolumeCL(const ghoul::Dictionary& dictionary);
// ~RenderableVolumeCL();
//
// bool initialize();
// bool deinitialize();
//
// virtual void render(const Camera *camera, const psc& thisPosition);
// virtual void update();
//
//private:
//
// void safeKernelCompilation();
//
// std::string _filename;
// ghoul::RawVolumeReader::ReadHints _hints;
// float _stepSize;
// ghoul::opengl::FramebufferObject* _fbo;
// ghoul::opengl::Texture* _backTexture;
// ghoul::opengl::Texture* _frontTexture;
// ghoul::opengl::Texture* _volume;
// ghoul::opengl::Texture* _output;
// ghoul::opengl::ProgramObject *_fboProgram;
// ghoul::opengl::ProgramObject *_quadProgram;
// sgct_utils::SGCTBox* _boundingBox;
// GLuint _screenQuad;
//
// ghoul::opencl::CLContext _context;
// ghoul::opencl::CLCommandQueue _commands;
// ghoul::opencl::CLProgram _program;
// ghoul::opencl::CLKernel _kernel;
// ghoul::opencl::CLWorkSize* _ws;
// cl_mem _clBackTexture, _clFrontTexture, _clVolume, _clOutput;
//
// ghoul::filesystem::File* _kernelSourceFile;
// bool _kernelUpdateOnSave;
// std::mutex* _kernelMutex;
//
//};
//
//} // namespace openspace
//
//#endif

View File

@@ -1,118 +1,119 @@
/*****************************************************************************************
* *
* 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 __RENDERABLEVOLUMEEXPERT_H__
#define __RENDERABLEVOLUMEEXPERT_H__
// open space includes
#include <openspace/rendering/renderablevolume.h>
#include <openspace/rendering/volumeraycasterbox.h>
// ghoul includes
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/framebufferobject.h>
#include <ghoul/opencl/clcontext.h>
#include <ghoul/opencl/clcommandqueue.h>
#include <ghoul/opencl/clprogram.h>
#include <ghoul/opencl/clkernel.h>
#include <ghoul/filesystem/file.h>
#ifdef __APPLE__
#include <memory>
#else
#include <mutex>
#endif
namespace ghoul {
namespace opencl {
class CLWorkSize;
}
}
namespace openspace {
class RenderableVolumeExpert: public RenderableVolume {
public:
// constructors & destructor
RenderableVolumeExpert(const ghoul::Dictionary& dictionary);
~RenderableVolumeExpert();
bool initialize();
bool deinitialize();
virtual void render(const Camera *camera, const psc& thisPosition);
virtual void update();
private:
// private methods
void safeKernelCompilation();
void safeUpdateTexture(const ghoul::filesystem::File& file);
// Volumes
std::vector<std::string> _volumePaths;
std::vector<ghoul::Dictionary> _volumeHints;
// Textures
ghoul::opengl::Texture* _output;
std::vector<ghoul::opengl::Texture*> _volumes;
std::vector<ghoul::opengl::Texture*> _transferFunctions;
std::vector<ghoul::filesystem::File*> _transferFunctionsFiles;
// opencl texture memory pointers
cl_mem _clBackTexture;
cl_mem _clFrontTexture;
cl_mem _clOutput;
std::vector<cl_mem> _clVolumes;
std::vector<cl_mem> _clTransferFunctions;
// opencl program
ghoul::opencl::CLContext _context;
ghoul::opencl::CLCommandQueue _commands;
ghoul::opencl::CLProgram _program;
ghoul::opencl::CLKernel _kernel;
ghoul::opencl::CLWorkSize* _ws;
ghoul::filesystem::File* _kernelSourceFile;
std::vector<std::pair<ghoul::opencl::CLProgram::Option, bool> > _kernelOptions;
std::vector<std::string> _kernelIncludes;
std::vector<std::pair<std::string,std::string> > _kernelDefinitions;
bool _programUpdateOnSave;
// mutexes to prevent inconsistencies
std::mutex* _kernelLock;
std::mutex* _textureLock;
ghoul::opengl::ProgramObject *_quadProgram;
GLuint _screenQuad;
VolumeRaycasterBox* _colorBoxRenderer;
glm::vec3 _boxScaling;
};
} // namespace openspace
#endif
// This is still in the repository to be cannibalized for a possible rewrite (ab)
///*****************************************************************************************
// * *
// * 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 __RENDERABLEVOLUMEEXPERT_H__
//#define __RENDERABLEVOLUMEEXPERT_H__
//
//// open space includes
//#include <openspace/rendering/renderablevolume.h>
//#include <openspace/rendering/volumeraycasterbox.h>
//
//// ghoul includes
//#include <ghoul/opengl/programobject.h>
//#include <ghoul/opengl/texture.h>
//#include <ghoul/opengl/framebufferobject.h>
//#include <ghoul/opencl/clcontext.h>
//#include <ghoul/opencl/clcommandqueue.h>
//#include <ghoul/opencl/clprogram.h>
//#include <ghoul/opencl/clkernel.h>
//#include <ghoul/filesystem/file.h>
//
//#ifdef __APPLE__
// #include <memory>
//#else
// #include <mutex>
//#endif
//
//namespace ghoul {
// namespace opencl {
// class CLWorkSize;
// }
//}
//
//namespace openspace {
//
//class RenderableVolumeExpert: public RenderableVolume {
//public:
//
// // constructors & destructor
// RenderableVolumeExpert(const ghoul::Dictionary& dictionary);
// ~RenderableVolumeExpert();
//
// bool initialize();
// bool deinitialize();
//
// virtual void render(const Camera *camera, const psc& thisPosition);
// virtual void update();
//
//private:
//
// // private methods
// void safeKernelCompilation();
// void safeUpdateTexture(const ghoul::filesystem::File& file);
//
// // Volumes
// std::vector<std::string> _volumePaths;
// std::vector<ghoul::Dictionary> _volumeHints;
//
// // Textures
// ghoul::opengl::Texture* _output;
// std::vector<ghoul::opengl::Texture*> _volumes;
// std::vector<ghoul::opengl::Texture*> _transferFunctions;
// std::vector<ghoul::filesystem::File*> _transferFunctionsFiles;
//
// // opencl texture memory pointers
// cl_mem _clBackTexture;
// cl_mem _clFrontTexture;
// cl_mem _clOutput;
// std::vector<cl_mem> _clVolumes;
// std::vector<cl_mem> _clTransferFunctions;
//
// // opencl program
// ghoul::opencl::CLContext _context;
// ghoul::opencl::CLCommandQueue _commands;
// ghoul::opencl::CLProgram _program;
// ghoul::opencl::CLKernel _kernel;
// ghoul::opencl::CLWorkSize* _ws;
// ghoul::filesystem::File* _kernelSourceFile;
// std::vector<std::pair<ghoul::opencl::CLProgram::Option, bool> > _kernelOptions;
// std::vector<std::string> _kernelIncludes;
// std::vector<std::pair<std::string,std::string> > _kernelDefinitions;
// bool _programUpdateOnSave;
//
// // mutexes to prevent inconsistencies
// std::mutex* _kernelLock;
// std::mutex* _textureLock;
//
// ghoul::opengl::ProgramObject *_quadProgram;
// GLuint _screenQuad;
//
// VolumeRaycasterBox* _colorBoxRenderer;
// glm::vec3 _boxScaling;
//
//};
//
//} // namespace openspace
//
//#endif

View File

@@ -25,7 +25,6 @@
#ifndef __RENDERABLEVOLUMEGL_H__
#define __RENDERABLEVOLUMEGL_H__
// open space includes
#include <openspace/rendering/renderablevolume.h>
// ghoul includes
@@ -39,7 +38,6 @@ namespace openspace {
class RenderableVolumeGL: public RenderableVolume {
public:
// constructors & destructor
RenderableVolumeGL(const ghoul::Dictionary& dictionary);
~RenderableVolumeGL();

View File

@@ -61,6 +61,16 @@ namespace renderableplanet {
const std::string keyGeometry = "Geometry";
} // namespace renderableplanet
namespace renderablevolumegl {
const std::string keyVolume = "Volume";
const std::string keyHints = "Hints";
const std::string keyTransferFunction = "TransferFunction";
const std::string keySampler = "Sampler";
const std::string keyBoxScaling = "BoxScaling";
const std::string keyVolumeName = "VolumeName";
const std::string keyTransferFunctionName = "TransferFunctionName";
} // namespace renderablevolumegl
namespace planetgeometry {
const std::string keyType = "Type";
} // namespace planetgeometry

View File

@@ -52,7 +52,8 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
assert(success);
std::string path;
dictionary.getValue(constants::scenegraph::keyPathModule, path);
success = dictionary.getValue(constants::scenegraph::keyPathModule, path);
assert(success);
ghoul::Dictionary geometryDictionary;
success = dictionary.getValueSafe(
@@ -67,10 +68,9 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
// TODO: textures need to be replaced by a good system similar to the geometry as soon
// as the requirements are fixed (ab)
std::string texturePath = "";
if (dictionary.hasKey("Textures.Color")) {
dictionary.getValue("Textures.Color", texturePath);
success = dictionary.getValueSafe("Textures.Color", texturePath);
if (success)
_colorTexturePath = path + "/" + texturePath;
}
addPropertySubOwner(_geometry);

View File

@@ -1,401 +1,402 @@
/*****************************************************************************************
* *
* 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. *
****************************************************************************************/
// open space includes
#include <openspace/rendering/renderablevolumecl.h>
#include <openspace/engine/openspaceengine.h>
#include <ghoul/opengl/texturereader.h>
#include <ghoul/filesystem/filesystem.h>
#include <sgct.h>
#include <algorithm>
namespace {
std::string _loggerCat = "RenderableVolumeCL";
}
namespace openspace {
RenderableVolumeCL::RenderableVolumeCL(const ghoul::Dictionary& dictionary):
RenderableVolume(dictionary),
_backTexture(nullptr), _frontTexture(nullptr), _output(nullptr),
_clBackTexture(0), _clFrontTexture(0), _clOutput(0),
_kernelSourceFile(nullptr) {
_kernelMutex = new std::mutex;
_filename = "";
if(dictionary.hasKey("Volume")) {
if(dictionary.getValue("Volume", _filename)) {
_filename = findPath(_filename);
}
}
ghoul::Dictionary hintsDictionary;
if(dictionary.hasKey("Hints"))
dictionary.getValue("Hints", hintsDictionary);
_hints = readHints(hintsDictionary);
/*
if(dictionary.hasKey("TransferFunctions")) {
ghoul::Dictionary transferFunctions;
if(dictionary.getValue("TransferFunctions", transferFunctions)) {
auto keys = transferFunctions.keys();
for(auto key: keys) {
std::string transferFunctionPath = "";
if(transferFunctions.getValue(key, transferFunctionPath)) {
transferFunctionPath = findPath(transferFunctionPath);
if(transferFunctionPath != "") {
ghoul::filesystem::File* tmp = new ghoul::filesystem::File(transferFunctionPath, false);
ghoul::opengl::Texture* tmpTexture = ghoul::opengl::loadTexture(tmp->path());
_transferFunctions.push_back(tmpTexture);
_transferFunctionsFiles.push_back(tmp);
}
}
}
}
}
*/
if(dictionary.hasKey("UpdateOnSave")) {
dictionary.getValue("UpdateOnSave", _kernelUpdateOnSave);
}
/*
if(dictionary.hasKey("KernelOptions")) {
using namespace ghoul::opencl;
ghoul::Dictionary kernelOptions;
if(dictionary.getValue("KernelOptions", kernelOptions)) {
auto keys = kernelOptions.keys();
for(auto key: keys) {
bool value = false;
if(kernelOptions.getValue(key, value)) {
if(key == "DenormsAreZero") {
_kernelOptions.push_back(std::make_pair(CLProgram::Option::DenormsAreZero, value));
} else if(key == "FastRelaxedMath") {
_kernelOptions.push_back(std::make_pair(CLProgram::Option::FastRelaxedMath, value));
} else if(key == "FiniteMathOnly") {
_kernelOptions.push_back(std::make_pair(CLProgram::Option::FiniteMathOnly, value));
} else if(key == "KernelArgInfo") {
_kernelOptions.push_back(std::make_pair(CLProgram::Option::KernelArgInfo, value));
} else if(key == "MadEnable") {
_kernelOptions.push_back(std::make_pair(CLProgram::Option::MadEnable, value));
} else if(key == "NoSignedZero") {
_kernelOptions.push_back(std::make_pair(CLProgram::Option::NoSignedZero, value));
} else if(key == "OptDisable") {
_kernelOptions.push_back(std::make_pair(CLProgram::Option::OptDisable, value));
} else if(key == "SinglePrecisionConstant") {
_kernelOptions.push_back(std::make_pair(CLProgram::Option::SinglePrecisionConstant, value));
} else if(key == "StrictAliasing") {
_kernelOptions.push_back(std::make_pair(CLProgram::Option::StrictAliasing, value));
} else if(key == "UnsafeMathOptimizations") {
_kernelOptions.push_back(std::make_pair(CLProgram::Option::UnsafeMathOptimizations, value));
}
}
}
}
}
*/
std::string kernelPath = "";
if (dictionary.hasKey("Kernel")) {
if(dictionary.getValue("Kernel", kernelPath)) {
kernelPath = findPath(kernelPath);
}
}
if (kernelPath != "") {
_kernelSourceFile = new ghoul::filesystem::File(kernelPath, false);
}
}
RenderableVolumeCL::~RenderableVolumeCL() {
deinitialize();
delete _kernelMutex;
}
bool RenderableVolumeCL::initialize() {
assert(_filename != "");
// ------ VOLUME READING ----------------
ghoul::RawVolumeReader rawReader(_hints);
_volume = rawReader.read(_filename);
glm::size3_t d = _volume->dimensions();
// ------ SETUP GEOMETRY ----------------
const GLfloat size = 1.0f;
const GLfloat vertex_texcoord_data[] = { // square of two triangles (sigh)
// x y z s t
-size, -size, 0.0f, 0.0f, 0.0f,
size, size, 0.0f, 1.0f, 1.0f,
-size, size, 0.0f, 0.0f, 1.0f,
-size, -size, 0.0f, 0.0f, 0.0f,
size, -size, 0.0f, 1.0f, 0.0f,
size, size, 0.0f, 1.0f, 1.0f
};
GLuint vertexPositionBuffer;
glGenVertexArrays(1, &_screenQuad); // generate array
glBindVertexArray(_screenQuad); // bind array
glGenBuffers(1, &vertexPositionBuffer); // generate buffer
glBindBuffer(GL_ARRAY_BUFFER, vertexPositionBuffer); // bind buffer
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_texcoord_data), vertex_texcoord_data, GL_STATIC_DRAW);
// Vertex positions
GLuint vertexLocation = 2;
glEnableVertexAttribArray(vertexLocation);
glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 5*sizeof(GLfloat), reinterpret_cast<void*>(0));
// Texture coordinates
GLuint texcoordLocation = 0;
glEnableVertexAttribArray(texcoordLocation);
glVertexAttribPointer(texcoordLocation, 2, GL_FLOAT, GL_FALSE, 5*sizeof(GLfloat), (void*)(3*sizeof(GLfloat)));
glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind buffer
glBindVertexArray(0); //unbind array
_boundingBox = new sgct_utils::SGCTBox(1.0f, sgct_utils::SGCTBox::Regular);
// ------ SETUP SHADERS -----------------
// TODO error control or better design pattern
OsEng.ref().configurationManager().getValue("RaycastProgram", _fboProgram);
OsEng.ref().configurationManager().getValue("Quad", _quadProgram);
// ------ SETUP FBO ---------------------
_fbo = new ghoul::opengl::FramebufferObject();
_fbo->activate();
size_t x = sgct::Engine::instance()->getActiveXResolution();
size_t y = sgct::Engine::instance()->getActiveYResolution();
_backTexture = new ghoul::opengl::Texture(glm::size3_t(x,y,1));
_frontTexture = new ghoul::opengl::Texture(glm::size3_t(x,y,1));
_output = new ghoul::opengl::Texture(glm::size3_t(x,y,1));
_backTexture->uploadTexture();
_frontTexture->uploadTexture();
_output->uploadTexture();
_fbo->attachTexture(_backTexture, GL_COLOR_ATTACHMENT0);
_fbo->attachTexture(_frontTexture, GL_COLOR_ATTACHMENT1);
_fbo->deactivate();
_context = OsEng.clContext();
_commands = _context.createCommandQueue();
_clBackTexture = _context.createTextureFromGLTexture(CL_MEM_READ_ONLY, *_backTexture);
_clFrontTexture = _context.createTextureFromGLTexture(CL_MEM_READ_ONLY, *_frontTexture);
_clVolume = _context.createTextureFromGLTexture(CL_MEM_READ_ONLY, *_volume);
_clOutput = _context.createTextureFromGLTexture(CL_MEM_WRITE_ONLY, *_output);
auto privateCallback = [this](const ghoul::filesystem::File& file) {
safeKernelCompilation();
};
_kernelSourceFile = new ghoul::filesystem::File(_kernelSourceFile->path(), false);
if(_kernelUpdateOnSave)
_kernelSourceFile->setCallback(privateCallback);
safeKernelCompilation();
size_t local_x = 32;
size_t local_y = 32;
while (local_x > 1) {
if(x % local_x == 0)
break;
local_x /= 2;
}
while (local_y > 1) {
if(y % local_y == 0)
break;
local_y /= 2;
}
_ws = new ghoul::opencl::CLWorkSize ({x,y}, {local_x,local_y});
return true;
}
bool RenderableVolumeCL::deinitialize() {
delete _ws;
_ws = nullptr;
return true;
}
void RenderableVolumeCL::render(const Camera *camera, const psc &thisPosition) {
if( ! _kernel.isValidKernel())
return;
float speed = 50.0f;
float time = sgct::Engine::getTime();
glm::mat4 transform = camera->viewProjectionMatrix();
double factor = pow(10.0,thisPosition[3]);
transform = glm::translate(transform, glm::vec3(thisPosition[0]*factor, thisPosition[1]*factor, thisPosition[2]*factor));
transform = glm::rotate(transform, time*speed, glm::vec3(0.0f, 1.0f, 0.0f));
if(_kernel.isValidKernel()) {
_stepSize = 0.01f;
// ------ DRAW TO FBO -------------------
GLuint sgctFBO = ghoul::opengl::FramebufferObject::getActiveObject(); // Save SGCTs main FBO
_fbo->activate();
_fboProgram->activate();
_fboProgram->setUniform("modelViewProjection", transform);
// Draw backface
glDrawBuffer(GL_COLOR_ATTACHMENT0);
glClearColor(0.2f, 0.2f, 0.2f, 0);
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
_boundingBox->draw();
glDisable(GL_CULL_FACE);
// Draw frontface
glDrawBuffer(GL_COLOR_ATTACHMENT1);
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.2f, 0.2f, 0.2f, 0);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
_boundingBox->draw();
glDisable(GL_CULL_FACE);
_fboProgram->deactivate();
_fbo->deactivate();
// ------ DRAW TO SCREEN ----------------
glBindFramebuffer(GL_FRAMEBUFFER, sgctFBO); // Re-bind SGCTs main FBO
glFinish();
_commands.enqueueKernelBlocking(_kernel, *_ws);
_commands.finish();
_quadProgram->activate();
glActiveTexture(GL_TEXTURE0);
_output->bind();
glClearColor(0.0f, 0.0f, 0.0f, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindVertexArray(_screenQuad);
glDrawArrays(GL_TRIANGLES, 0, 6);
glBindVertexArray(0);
_quadProgram->deactivate();
}
}
void RenderableVolumeCL::update() {
}
void RenderableVolumeCL::safeKernelCompilation() {
std::string _loggerCat = "RenderableVolumeCL::safeKernelCompilation";
if(_context.isValidContext()) {
ghoul::opencl::CLProgram tmpProgram = _context.createProgram(_kernelSourceFile->path());
tmpProgram.setOption(ghoul::opencl::CLProgram::Option::OptDisable, true);
tmpProgram.setOption(ghoul::opencl::CLProgram::Option::KernelArgInfo, true);
if(tmpProgram.build()) {
ghoul::opencl::CLKernel tmpKernel = tmpProgram.createKernel("volumeraycaster");
if(tmpKernel.isValidKernel()) {
tmpKernel.setArgument(0, &_clFrontTexture);
tmpKernel.setArgument(1, &_clBackTexture);
tmpKernel.setArgument(2, &_clVolume);
tmpKernel.setArgument(3, &_clOutput);
// do the actual assignment behind locked doors
_kernelMutex->lock();
_program = tmpProgram;
_kernel = tmpKernel;
_kernelMutex->unlock();
LDEBUG("Done updating kernel");
} else {
LWARNING("Kernel is not valid");
}
} else {
LWARNING("Could not build CLProgram");
}
} else {
LWARNING("No valid CLContext");
}
}
/*
void RenderableVolumeCL::safeUpdateTexture(const ghoul::filesystem::File& file) {
int fileID = 0;
for (fileID = 0; fileID < _transferFunctionsFiles.size(); ++fileID) {
if (_transferFunctionsFiles.at(fileID) == &file) {
//LDEBUG("Transferfunction found at id " << fileID);
break;
}
}
if(fileID == _transferFunctionsFiles.size())
return;
LDEBUG("Updating transferfunction");
// create the new texture
ghoul::opengl::Texture* newTexture = ghoul::opengl::loadTexture(file.path());
if(newTexture) {
// upload the new texture and create a cl memory
newTexture->uploadTexture();
cl_mem clNewTexture = _context.createTextureFromGLTexture(CL_MEM_READ_ONLY, *newTexture);
if(clNewTexture == 0) {
delete newTexture;
return;
}
// everything is ok, critical point to replace current texture pointers
_textureLock->lock();
// deallocate current texture
delete _transferFunctions.at(fileID);
clReleaseMemObject(_clTransferFunctions.at(fileID));
// set the new texture
_transferFunctions.at(fileID) = newTexture;
_clTransferFunctions.at(fileID) = clNewTexture;
// update kernel
// __kernel arguments(front, back, output, [_volumes], .. fileID))
_kernel.setArgument(3 + _volumes.size() + fileID, &clNewTexture);
// end of critical section
_textureLock->unlock();
}
}
*/
} // namespace openspace
// This is still in the repository to be cannibalized for a possible rewrite (ab)
///*****************************************************************************************
// * *
// * 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. *
// ****************************************************************************************/
//
//// open space includes
//#include <openspace/rendering/renderablevolumecl.h>
//
//#include <openspace/engine/openspaceengine.h>
//
//#include <ghoul/opengl/texturereader.h>
//#include <ghoul/filesystem/filesystem.h>
//
//#include <sgct.h>
//
//#include <algorithm>
//
//namespace {
// std::string _loggerCat = "RenderableVolumeCL";
//}
//
//namespace openspace {
//
//RenderableVolumeCL::RenderableVolumeCL(const ghoul::Dictionary& dictionary):
// RenderableVolume(dictionary),
// _backTexture(nullptr), _frontTexture(nullptr), _output(nullptr),
// _clBackTexture(0), _clFrontTexture(0), _clOutput(0),
// _kernelSourceFile(nullptr) {
//
// _kernelMutex = new std::mutex;
//
// _filename = "";
// if(dictionary.hasKey("Volume")) {
// if(dictionary.getValue("Volume", _filename)) {
// _filename = findPath(_filename);
// }
// }
// ghoul::Dictionary hintsDictionary;
// if(dictionary.hasKey("Hints"))
// dictionary.getValue("Hints", hintsDictionary);
// _hints = readHints(hintsDictionary);
//
// /*
// if(dictionary.hasKey("TransferFunctions")) {
// ghoul::Dictionary transferFunctions;
// if(dictionary.getValue("TransferFunctions", transferFunctions)) {
// auto keys = transferFunctions.keys();
// for(auto key: keys) {
// std::string transferFunctionPath = "";
// if(transferFunctions.getValue(key, transferFunctionPath)) {
// transferFunctionPath = findPath(transferFunctionPath);
// if(transferFunctionPath != "") {
// ghoul::filesystem::File* tmp = new ghoul::filesystem::File(transferFunctionPath, false);
// ghoul::opengl::Texture* tmpTexture = ghoul::opengl::loadTexture(tmp->path());
//
// _transferFunctions.push_back(tmpTexture);
// _transferFunctionsFiles.push_back(tmp);
// }
// }
// }
// }
// }
// */
//
// if(dictionary.hasKey("UpdateOnSave")) {
// dictionary.getValue("UpdateOnSave", _kernelUpdateOnSave);
// }
//
// /*
// if(dictionary.hasKey("KernelOptions")) {
// using namespace ghoul::opencl;
// ghoul::Dictionary kernelOptions;
// if(dictionary.getValue("KernelOptions", kernelOptions)) {
// auto keys = kernelOptions.keys();
// for(auto key: keys) {
// bool value = false;
// if(kernelOptions.getValue(key, value)) {
// if(key == "DenormsAreZero") {
// _kernelOptions.push_back(std::make_pair(CLProgram::Option::DenormsAreZero, value));
// } else if(key == "FastRelaxedMath") {
// _kernelOptions.push_back(std::make_pair(CLProgram::Option::FastRelaxedMath, value));
// } else if(key == "FiniteMathOnly") {
// _kernelOptions.push_back(std::make_pair(CLProgram::Option::FiniteMathOnly, value));
// } else if(key == "KernelArgInfo") {
// _kernelOptions.push_back(std::make_pair(CLProgram::Option::KernelArgInfo, value));
// } else if(key == "MadEnable") {
// _kernelOptions.push_back(std::make_pair(CLProgram::Option::MadEnable, value));
// } else if(key == "NoSignedZero") {
// _kernelOptions.push_back(std::make_pair(CLProgram::Option::NoSignedZero, value));
// } else if(key == "OptDisable") {
// _kernelOptions.push_back(std::make_pair(CLProgram::Option::OptDisable, value));
// } else if(key == "SinglePrecisionConstant") {
// _kernelOptions.push_back(std::make_pair(CLProgram::Option::SinglePrecisionConstant, value));
// } else if(key == "StrictAliasing") {
// _kernelOptions.push_back(std::make_pair(CLProgram::Option::StrictAliasing, value));
// } else if(key == "UnsafeMathOptimizations") {
// _kernelOptions.push_back(std::make_pair(CLProgram::Option::UnsafeMathOptimizations, value));
// }
// }
// }
// }
// }
// */
//
// std::string kernelPath = "";
// if (dictionary.hasKey("Kernel")) {
// if(dictionary.getValue("Kernel", kernelPath)) {
// kernelPath = findPath(kernelPath);
// }
// }
// if (kernelPath != "") {
// _kernelSourceFile = new ghoul::filesystem::File(kernelPath, false);
// }
//
//}
//
//RenderableVolumeCL::~RenderableVolumeCL() {
// deinitialize();
// delete _kernelMutex;
//}
//
//bool RenderableVolumeCL::initialize() {
// assert(_filename != "");
// // ------ VOLUME READING ----------------
// ghoul::RawVolumeReader rawReader(_hints);
// _volume = rawReader.read(_filename);
// glm::size3_t d = _volume->dimensions();
//
// // ------ SETUP GEOMETRY ----------------
// const GLfloat size = 1.0f;
// const GLfloat vertex_texcoord_data[] = { // square of two triangles (sigh)
// // x y z s t
// -size, -size, 0.0f, 0.0f, 0.0f,
// size, size, 0.0f, 1.0f, 1.0f,
// -size, size, 0.0f, 0.0f, 1.0f,
// -size, -size, 0.0f, 0.0f, 0.0f,
// size, -size, 0.0f, 1.0f, 0.0f,
// size, size, 0.0f, 1.0f, 1.0f
// };
//
// GLuint vertexPositionBuffer;
// glGenVertexArrays(1, &_screenQuad); // generate array
// glBindVertexArray(_screenQuad); // bind array
// glGenBuffers(1, &vertexPositionBuffer); // generate buffer
// glBindBuffer(GL_ARRAY_BUFFER, vertexPositionBuffer); // bind buffer
// glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_texcoord_data), vertex_texcoord_data, GL_STATIC_DRAW);
//
// // Vertex positions
// GLuint vertexLocation = 2;
// glEnableVertexAttribArray(vertexLocation);
// glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 5*sizeof(GLfloat), reinterpret_cast<void*>(0));
//
// // Texture coordinates
// GLuint texcoordLocation = 0;
// glEnableVertexAttribArray(texcoordLocation);
// glVertexAttribPointer(texcoordLocation, 2, GL_FLOAT, GL_FALSE, 5*sizeof(GLfloat), (void*)(3*sizeof(GLfloat)));
//
// glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind buffer
// glBindVertexArray(0); //unbind array
//
// _boundingBox = new sgct_utils::SGCTBox(1.0f, sgct_utils::SGCTBox::Regular);
//
// // ------ SETUP SHADERS -----------------
// // TODO error control or better design pattern
// OsEng.ref().configurationManager().getValue("RaycastProgram", _fboProgram);
// OsEng.ref().configurationManager().getValue("Quad", _quadProgram);
//
// // ------ SETUP FBO ---------------------
// _fbo = new ghoul::opengl::FramebufferObject();
// _fbo->activate();
//
// size_t x = sgct::Engine::instance()->getActiveXResolution();
// size_t y = sgct::Engine::instance()->getActiveYResolution();
// _backTexture = new ghoul::opengl::Texture(glm::size3_t(x,y,1));
// _frontTexture = new ghoul::opengl::Texture(glm::size3_t(x,y,1));
// _output = new ghoul::opengl::Texture(glm::size3_t(x,y,1));
// _backTexture->uploadTexture();
// _frontTexture->uploadTexture();
// _output->uploadTexture();
// _fbo->attachTexture(_backTexture, GL_COLOR_ATTACHMENT0);
// _fbo->attachTexture(_frontTexture, GL_COLOR_ATTACHMENT1);
//
// _fbo->deactivate();
//
// _context = OsEng.clContext();
// _commands = _context.createCommandQueue();
//
// _clBackTexture = _context.createTextureFromGLTexture(CL_MEM_READ_ONLY, *_backTexture);
// _clFrontTexture = _context.createTextureFromGLTexture(CL_MEM_READ_ONLY, *_frontTexture);
// _clVolume = _context.createTextureFromGLTexture(CL_MEM_READ_ONLY, *_volume);
// _clOutput = _context.createTextureFromGLTexture(CL_MEM_WRITE_ONLY, *_output);
//
// auto privateCallback = [this](const ghoul::filesystem::File& file) {
// safeKernelCompilation();
// };
//
// _kernelSourceFile = new ghoul::filesystem::File(_kernelSourceFile->path(), false);
// if(_kernelUpdateOnSave)
// _kernelSourceFile->setCallback(privateCallback);
//
// safeKernelCompilation();
//
// size_t local_x = 32;
// size_t local_y = 32;
// while (local_x > 1) {
// if(x % local_x == 0)
// break;
// local_x /= 2;
// }
// while (local_y > 1) {
// if(y % local_y == 0)
// break;
// local_y /= 2;
// }
// _ws = new ghoul::opencl::CLWorkSize ({x,y}, {local_x,local_y});
//
// return true;
//
//}
//
//bool RenderableVolumeCL::deinitialize() {
//
// delete _ws;
// _ws = nullptr;
//
// return true;
//}
//
//void RenderableVolumeCL::render(const Camera *camera, const psc &thisPosition) {
//
// if( ! _kernel.isValidKernel())
// return;
//
// float speed = 50.0f;
// float time = sgct::Engine::getTime();
// glm::mat4 transform = camera->viewProjectionMatrix();
//
// double factor = pow(10.0,thisPosition[3]);
// transform = glm::translate(transform, glm::vec3(thisPosition[0]*factor, thisPosition[1]*factor, thisPosition[2]*factor));
// transform = glm::rotate(transform, time*speed, glm::vec3(0.0f, 1.0f, 0.0f));
//
//
// if(_kernel.isValidKernel()) {
// _stepSize = 0.01f;
//
// // ------ DRAW TO FBO -------------------
// GLuint sgctFBO = ghoul::opengl::FramebufferObject::getActiveObject(); // Save SGCTs main FBO
// _fbo->activate();
// _fboProgram->activate();
// _fboProgram->setUniform("modelViewProjection", transform);
//
// // Draw backface
// glDrawBuffer(GL_COLOR_ATTACHMENT0);
// glClearColor(0.2f, 0.2f, 0.2f, 0);
// glClear(GL_COLOR_BUFFER_BIT);
// glEnable(GL_CULL_FACE);
// glCullFace(GL_FRONT);
// _boundingBox->draw();
// glDisable(GL_CULL_FACE);
//
// // Draw frontface
// glDrawBuffer(GL_COLOR_ATTACHMENT1);
// glClear(GL_COLOR_BUFFER_BIT);
// glClearColor(0.2f, 0.2f, 0.2f, 0);
// glEnable(GL_CULL_FACE);
// glCullFace(GL_BACK);
// _boundingBox->draw();
// glDisable(GL_CULL_FACE);
//
// _fboProgram->deactivate();
// _fbo->deactivate();
//
// // ------ DRAW TO SCREEN ----------------
// glBindFramebuffer(GL_FRAMEBUFFER, sgctFBO); // Re-bind SGCTs main FBO
//
//
//
// glFinish();
// _commands.enqueueKernelBlocking(_kernel, *_ws);
// _commands.finish();
// _quadProgram->activate();
// glActiveTexture(GL_TEXTURE0);
// _output->bind();
// glClearColor(0.0f, 0.0f, 0.0f, 0);
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// glBindVertexArray(_screenQuad);
// glDrawArrays(GL_TRIANGLES, 0, 6);
// glBindVertexArray(0);
//
// _quadProgram->deactivate();
//
// }
//
//
//
//}
//
//void RenderableVolumeCL::update() {
//
//}
//
//void RenderableVolumeCL::safeKernelCompilation() {
// std::string _loggerCat = "RenderableVolumeCL::safeKernelCompilation";
// if(_context.isValidContext()) {
//
// ghoul::opencl::CLProgram tmpProgram = _context.createProgram(_kernelSourceFile->path());
// tmpProgram.setOption(ghoul::opencl::CLProgram::Option::OptDisable, true);
// tmpProgram.setOption(ghoul::opencl::CLProgram::Option::KernelArgInfo, true);
// if(tmpProgram.build()) {
// ghoul::opencl::CLKernel tmpKernel = tmpProgram.createKernel("volumeraycaster");
// if(tmpKernel.isValidKernel()) {
// tmpKernel.setArgument(0, &_clFrontTexture);
// tmpKernel.setArgument(1, &_clBackTexture);
// tmpKernel.setArgument(2, &_clVolume);
// tmpKernel.setArgument(3, &_clOutput);
//
// // do the actual assignment behind locked doors
// _kernelMutex->lock();
// _program = tmpProgram;
// _kernel = tmpKernel;
// _kernelMutex->unlock();
//
// LDEBUG("Done updating kernel");
// } else {
// LWARNING("Kernel is not valid");
// }
// } else {
// LWARNING("Could not build CLProgram");
// }
// } else {
// LWARNING("No valid CLContext");
// }
//}
// /*
//void RenderableVolumeCL::safeUpdateTexture(const ghoul::filesystem::File& file) {
// int fileID = 0;
// for (fileID = 0; fileID < _transferFunctionsFiles.size(); ++fileID) {
// if (_transferFunctionsFiles.at(fileID) == &file) {
// //LDEBUG("Transferfunction found at id " << fileID);
// break;
// }
// }
// if(fileID == _transferFunctionsFiles.size())
// return;
//
// LDEBUG("Updating transferfunction");
// // create the new texture
// ghoul::opengl::Texture* newTexture = ghoul::opengl::loadTexture(file.path());
//
// if(newTexture) {
//
// // upload the new texture and create a cl memory
// newTexture->uploadTexture();
// cl_mem clNewTexture = _context.createTextureFromGLTexture(CL_MEM_READ_ONLY, *newTexture);
//
// if(clNewTexture == 0) {
// delete newTexture;
// return;
// }
//
// // everything is ok, critical point to replace current texture pointers
// _textureLock->lock();
//
// // deallocate current texture
// delete _transferFunctions.at(fileID);
// clReleaseMemObject(_clTransferFunctions.at(fileID));
//
// // set the new texture
// _transferFunctions.at(fileID) = newTexture;
// _clTransferFunctions.at(fileID) = clNewTexture;
//
// // update kernel
// // __kernel arguments(front, back, output, [_volumes], .. fileID))
// _kernel.setArgument(3 + _volumes.size() + fileID, &clNewTexture);
//
// // end of critical section
// _textureLock->unlock();
// }
//}
//*/
//
//} // namespace openspace

File diff suppressed because it is too large Load Diff

View File

@@ -22,7 +22,6 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
// open space includes
#include <openspace/rendering/renderablevolumegl.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/util/powerscaledcoordinate.h>
@@ -35,78 +34,84 @@
#include <algorithm>
#include <openspace/engine/openspaceengine.h>
#include <openspace/util/constants.h>
namespace {
std::string _loggerCat = "RenderableVolumeGL";
const std::string _loggerCat = "RenderableVolumeGL";
}
namespace openspace {
RenderableVolumeGL::RenderableVolumeGL(const ghoul::Dictionary& dictionary):
RenderableVolume(dictionary), _boxScaling(1.0, 1.0, 1.0),
_updateTransferfunction(false), _id(-1) {
RenderableVolumeGL::RenderableVolumeGL(const ghoul::Dictionary& dictionary)
: RenderableVolume(dictionary)
, _transferFunctionName("")
, _volumeName("")
, _boxScaling(1.0, 1.0, 1.0)
, _w(0.f)
, _updateTransferfunction(false)
, _id(-1)
{
std::string name;
bool success = dictionary.getValue(constants::scenegraphnode::keyName, name);
assert(success);
_filename = "";
if(dictionary.hasKey("Volume")) {
if(dictionary.getValue("Volume", _filename)) {
_filename = findPath(_filename);
}
}
success = dictionary.getValueSafe(constants::renderablevolumegl::keyVolume,
_filename);
if (!success) {
LERROR("Node '" << name << "' did not contain a valid '" <<
constants::renderablevolumegl::keyVolume << "'");
return;
}
_filename = findPath(_filename);
LDEBUG("filename: " << _filename);
if(dictionary.hasKey("Hints"))
dictionary.getValue("Hints", _hintsDictionary);
LDEBUG("Volume Filename: " << _filename);
dictionary.getValueSafe(constants::renderablevolumegl::keyHints, _hintsDictionary);
_transferFunction = nullptr;
_transferFunctionFile = nullptr;
_transferFunctionPath = "";
if (dictionary.hasKey("TransferFunction")) {
std::string transferFunctionPath = "";
if(dictionary.getValue("TransferFunction", transferFunctionPath)) {
_transferFunctionPath = findPath(transferFunctionPath);
}
}
_samplerFilename = "";
if (dictionary.hasKey("Sampler")) {
if(dictionary.getValue("Sampler", _samplerFilename)) {
_samplerFilename = findPath(_samplerFilename);
}
}
if( _transferFunctionPath == "") {
LERROR("No transferFunction!");
} else {
_transferFunctionFile = new ghoul::filesystem::File(_transferFunctionPath, true);
}
if( _samplerFilename == "") {
LERROR("No samplerfile!");
}
success = dictionary.getValueSafe(
constants::renderablevolumegl::keyTransferFunction, _transferFunctionPath);
if (!success) {
LERROR("Node '" << name << "' did not contain a valid '" <<
constants::renderablevolumegl::keyTransferFunction << "'");
return;
}
_transferFunctionPath = findPath(_transferFunctionPath);
_transferFunctionFile = new ghoul::filesystem::File(_transferFunctionPath, true);
_samplerFilename = "";
success = dictionary.getValueSafe(constants::renderablevolumegl::keySampler,
_samplerFilename);
if (!success) {
LERROR("Node '" << name << "' did not contain a valid '" <<
constants::renderablevolumegl::keySampler << "'");
return;
}
_samplerFilename = findPath(_samplerFilename);
double tempValue;
if(dictionary.hasKey("BoxScaling.1") && dictionary.getValue("BoxScaling.1", tempValue)) {
if(tempValue > 0.0)
_boxScaling[0] = tempValue;
}
if(dictionary.hasKey("BoxScaling.2") && dictionary.getValue("BoxScaling.2", tempValue)) {
if(tempValue > 0.0)
_boxScaling[1] = tempValue;
}
if(dictionary.hasKey("BoxScaling.3") && dictionary.getValue("BoxScaling.3", tempValue)) {
if(tempValue > 0.0)
_boxScaling[2] = tempValue;
}
if(dictionary.hasKey("BoxScaling.4") && dictionary.getValue("BoxScaling.4", tempValue)) {
_w = tempValue;
}
else
_w = 0.0;
glm::vec4 scalingVec4(_boxScaling, _w);
success = dictionary.getValueSafe(constants::renderablevolumegl::keyBoxScaling,
scalingVec4);
if (success) {
_boxScaling = scalingVec4.xyz;
_w = scalingVec4.w;
}
else {
success = dictionary.getValueSafe(constants::renderablevolumegl::keyBoxScaling,
_boxScaling);
if (!success) {
LERROR("Node '" << name << "' did not contain a valid '" <<
constants::renderablevolumegl::keyBoxScaling << "'");
return;
}
}
_volumeName = "";
if (dictionary.hasKey("VolumeName"))
dictionary.getValue("VolumeName", _volumeName);
_transferFunctionName = "";
if (dictionary.hasKey("TransferFunctionName"))
dictionary.getValue("TransferFunctionName", _transferFunctionName);
dictionary.getValueSafe(constants::renderablevolumegl::keyVolumeName, _volumeName);
dictionary.getValueSafe(constants::renderablevolumegl::keyTransferFunctionName,
_transferFunctionName);
setBoundingSphere(PowerScaledScalar::CreatePSS(glm::length(_boxScaling)*pow(10,_w)));
}

View File

@@ -318,9 +318,9 @@ void ScriptEngine::addLibraryFunctions(const LuaLibrary& library, bool replace)
{
for (LuaLibrary::Function p : library.functions) {
if (!replace) {
ghoul::lua::logStack(_state);
//ghoul::lua::logStack(_state);
lua_getfield(_state, -1, p.name.c_str());
ghoul::lua::logStack(_state);
//ghoul::lua::logStack(_state);
const bool isNil = lua_isnil(_state, -1);
if (!isNil) {
LERROR("Function name '" << p.name << "' was already assigned");

View File

@@ -56,13 +56,8 @@ void FactoryManager::initialize()
_manager->addFactory(new ghoul::TemplateFactory<Renderable>);
_manager->factory<Renderable>()->registerClass<RenderablePlanet>(
"RenderablePlanet");
_manager->factory<Renderable>()->registerClass<RenderableVolumeCL>(
"RenderableVolumeCL");
_manager->factory<Renderable>()->registerClass<RenderableVolumeGL>(
"RenderableVolumeGL");
_manager->factory<Renderable>()->registerClass<RenderableVolumeExpert>(
"RenderableVolumeExpert");
_manager->factory<Renderable>()->registerClass<Flare>("RenderableFlare");
_manager->factory<Renderable>()->registerClass<RenderableFieldlines>("RenderableFieldlines");
// Add Ephimerides