ABuffer uses sampler files

- RenderableVolumeGL provides a filepath to sampler
- ABuffer reloads all sampler files for each recompilation
- ABuffer has mostly private members
This commit is contained in:
Jonas Strandstedt
2014-06-24 11:31:06 -04:00
parent 3fe447274f
commit fe701ddc5a
6 changed files with 69 additions and 25 deletions

View File

@@ -43,10 +43,15 @@ namespace openspace {
class ABuffer: public ABuffer_I {
public:
ABuffer();
virtual ~ABuffer() {};
virtual ~ABuffer();
virtual void resolve();
void addVolume(const std::string& tag,ghoul::opengl::Texture* volume);
void addTransferFunction(const std::string& tag,ghoul::opengl::Texture* transferFunction);
void addSamplerfile(const std::string& filename);
protected:
virtual std::string settings() = 0;
@@ -60,6 +65,8 @@ protected:
std::string openspaceSamplers();
unsigned int _width, _height, _totalPixels;
private:
GLuint _screenQuad;
bool _validShader;
@@ -69,10 +76,9 @@ protected:
std::vector<std::pair<std::string,ghoul::opengl::Texture*> > _volumes;
std::vector<std::pair<std::string,ghoul::opengl::Texture*> > _transferFunctions;
std::vector<ghoul::filesystem::File*> _samplerFiles;
std::vector<std::string> _samplers;
private:
}; // ABuffer

View File

@@ -36,12 +36,6 @@
#include <ghoul/io/rawvolumereader.h>
#include <ghoul/filesystem/file.h>
#ifdef __APPLE__
#include <memory>
#else
#include <mutex>
#endif
namespace openspace {
class RenderableVolumeGL: public RenderableVolume {
@@ -61,6 +55,7 @@ private:
std::string _filename;
std::string _transferFunctionPath;
std::string _samplerFilename;
ghoul::filesystem::File* _transferFunctionFile;

View File

@@ -56,6 +56,14 @@ ABuffer::ABuffer(): _validShader(true) {
_fragmentShaderPath = fragmentShaderSourcePath.substr(0, fragmentShaderSourcePath.length()-4) + "gglsl";
}
ABuffer::~ABuffer() {
if(_fragmentShaderFile)
delete _fragmentShaderFile;
if(_resolveShader)
delete _resolveShader;
}
bool ABuffer::initializeABuffer() {
// ============================
// SHADERS
@@ -122,6 +130,27 @@ void ABuffer::resolve() {
}
}
void ABuffer::addVolume(const std::string& tag,ghoul::opengl::Texture* volume) {
_volumes.push_back(std::make_pair(tag, volume));
}
void ABuffer::addTransferFunction(const std::string& tag,ghoul::opengl::Texture* transferFunction) {
_transferFunctions.push_back(std::make_pair(tag, transferFunction));
}
void ABuffer::addSamplerfile(const std::string& filename) {
if( ! FileSys.fileExists(filename))
return;
auto fileCallback = [this](const ghoul::filesystem::File& file) {
_validShader = false;
};
ghoul::filesystem::File* file = new ghoul::filesystem::File(filename);
file->setCallback(fileCallback);
_samplerFiles.push_back(file);
_samplers.push_back("");
}
bool ABuffer::updateShader() {
using ghoul::opengl::ShaderObject;
@@ -166,6 +195,19 @@ bool ABuffer::updateShader() {
}
void ABuffer::generateShaderSource() {
for(int i = 0; i < _samplerFiles.size(); ++i) {
std::string line, source = "";
std::ifstream samplerFile(_samplerFiles.at(i)->path());
if(samplerFile.is_open()) {
while(std::getline(samplerFile, line)) {
source += line + "\n";
}
}
samplerFile.close();
_samplers.at(i) = source;
}
std::string line, source = "";
std::ifstream fragmentShaderFile(_fragmentShaderFile->path());
if(fragmentShaderFile.is_open()) {

View File

@@ -50,12 +50,6 @@ ABufferSingleLinked::~ABufferSingleLinked() {
if(_data != 0)
delete _data;
if(_fragmentShaderFile)
delete _fragmentShaderFile;
if(_resolveShader)
delete _resolveShader;
glDeleteTextures(1,&_anchorPointerTexture);
glDeleteTextures(1,&_fragmentTexture);
glDeleteBuffers(1,&_anchorPointerTextureInitializer);
@@ -100,19 +94,16 @@ bool ABufferSingleLinked::initialize() {
// ============================
ghoul::opengl::Texture* volume = nullptr;
ghoul::opengl::Texture* tf = nullptr;
std::string sampler = "";
OsEng.configurationManager().getValue("firstVolume", volume);
OsEng.configurationManager().getValue("firstTransferFunction", tf);
OsEng.configurationManager().getValue("firstSampler", sampler);
if(volume)
_volumes.push_back(std::make_pair(std::string("volume1"), volume));
addVolume("volume1", volume);
if(tf)
_transferFunctions.push_back(std::make_pair(std::string("transferFunction1"), tf));
_samplers.push_back(R"(
void sampleVolume1(inout vec4 finalColor, vec3 position) {
float intensity = texture(volume1, position).x;
vec4 color = texture(transferFunction1, intensity);
blendStep(finalColor, color, stepSize);
}
)");
addTransferFunction("transferFunction1", tf);
if(sampler != "")
addSamplerfile(sampler);
return initializeABuffer();
}

View File

@@ -66,11 +66,20 @@ RenderableVolumeGL::RenderableVolumeGL(const ghoul::Dictionary& dictionary):
_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!");
}
double tempValue;
@@ -108,6 +117,7 @@ bool RenderableVolumeGL::initialize() {
_transferFunction->uploadTexture();
OsEng.configurationManager().setValue("firstVolume", _volume);
OsEng.configurationManager().setValue("firstTransferFunction", _transferFunction);
OsEng.configurationManager().setValue("firstSampler", _samplerFilename);
auto textureCallback = [this](const ghoul::filesystem::File& file) {
_updateTransferfunction = true;