Started work on Samplers having IDs

This commit is contained in:
Jonas Strandstedt
2014-06-24 14:45:08 -04:00
parent 4033303fd0
commit 633c95a44b
8 changed files with 33 additions and 35 deletions

View File

@@ -50,7 +50,7 @@ public:
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);
int addSamplerfile(const std::string& filename);
protected:
virtual std::string settings() = 0;

View File

@@ -66,6 +66,7 @@ private:
glm::vec3 _boxScaling;
bool _updateTransferfunction;
int _id;
};
} // namespace openspace

View File

@@ -47,6 +47,7 @@ public:
SceneGraph* sceneGraph();
Camera* camera() const;
ABuffer* abuffer() const;
// sgct wrapped functions
bool initializeGL();

View File

@@ -47,11 +47,6 @@ out vec4 color;
// ================================================================================
#pragma openspace insert HEADERS
float volumeStepSize[] = {
stepSize
};
// ================================================================================
// The ABuffer specific includes and definitions
// ================================================================================

View File

@@ -138,9 +138,9 @@ void ABuffer::addTransferFunction(const std::string& tag,ghoul::opengl::Texture*
_transferFunctions.push_back(std::make_pair(tag, transferFunction));
}
void ABuffer::addSamplerfile(const std::string& filename) {
int ABuffer::addSamplerfile(const std::string& filename) {
if( ! FileSys.fileExists(filename))
return;
return -1;
auto fileCallback = [this](const ghoul::filesystem::File& file) {
_validShader = false;
@@ -148,7 +148,10 @@ void ABuffer::addSamplerfile(const std::string& filename) {
ghoul::filesystem::File* file = new ghoul::filesystem::File(filename);
file->setCallback(fileCallback);
_samplerFiles.push_back(file);
int size = _samplers.size();
_samplers.push_back("");
return size;
}
bool ABuffer::updateShader() {
@@ -234,10 +237,9 @@ void ABuffer::generateShaderSource() {
std::string ABuffer::openspaceHeaders() {
std::string headers;
headers += "#define MAX_VOLUMES " + std::to_string(_volumes.size()) + "\n";
headers += "#define MAX_VOLUMES " + std::to_string(_samplers.size()) + "\n";
for (int i = 0; i < _volumes.size(); ++i) {
headers += "uniform sampler3D " + _volumes.at(i).first + ";\n";
//headers += "void sampleVolume" + std::to_string(i+1) + "(inout vec4, vec3);\n";
}
for (int i = 0; i < _transferFunctions.size(); ++i) {
headers += "uniform sampler1D " + _transferFunctions.at(i).first + ";\n";
@@ -257,12 +259,20 @@ std::string ABuffer::openspaceHeaders() {
+ std::to_string(size[2]) + ".0),\n";
}
headers += "};\n";
headers += "float volumeStepSize[] = {\n";
for (int i = 0; i < _volumes.size(); ++i) {
glm::size3_t size = _volumes.at(i).second->dimensions();
headers += " stepSize,\n";
}
headers += "};\n";
return headers;
}
std::string ABuffer::openspaceSamplerCalls() {
std::string samplercalls;
for (int i = 0; i < _volumes.size(); ++i) {
for (int i = 0; i < _samplers.size(); ++i) {
auto found1 = _samplers.at(i).find_first_not_of("void ");
auto found2 = _samplers.at(i).find_first_of("(",found1);

View File

@@ -89,22 +89,6 @@ bool ABufferSingleLinked::initialize() {
glBindImageTexture(1, _fragmentTexture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32UI);
// ============================
// Volume and transferfunction data
// ============================
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)
addVolume("volume1", volume);
if(tf)
addTransferFunction("transferFunction1", tf);
if(sampler != "")
addSamplerfile(sampler);
return initializeABuffer();
}

View File

@@ -43,7 +43,7 @@ namespace openspace {
RenderableVolumeGL::RenderableVolumeGL(const ghoul::Dictionary& dictionary):
RenderableVolume(dictionary), _boxScaling(1.0, 1.0, 1.0),
_updateTransferfunction(false) {
_updateTransferfunction(false), _id(-1) {
_filename = "";
@@ -119,9 +119,11 @@ bool RenderableVolumeGL::initialize() {
_volume->uploadTexture();
_transferFunction = loadTransferFunction(_transferFunctionPath);
_transferFunction->uploadTexture();
OsEng.configurationManager().setValue("firstVolume", _volume);
OsEng.configurationManager().setValue("firstTransferFunction", _transferFunction);
OsEng.configurationManager().setValue("firstSampler", _samplerFilename);
// TODO: fix volume an transferfunction names
OsEng.renderEngine().abuffer()->addVolume("volume1", _volume);
OsEng.renderEngine().abuffer()->addTransferFunction("transferFunction1", _transferFunction);
_id = OsEng.renderEngine().abuffer()->addSamplerfile(_samplerFilename);
auto textureCallback = [this](const ghoul::filesystem::File& file) {
_updateTransferfunction = true;
@@ -146,7 +148,9 @@ void RenderableVolumeGL::render(const Camera *camera, const psc &thisPosition) {
const void* data = transferFunction->pixelData();
glBindBuffer(GL_COPY_READ_BUFFER, *transferFunction);
_transferFunction->bind();
glTexImage1D(GL_TEXTURE_1D, 0, _transferFunction->internalFormat(), _transferFunction->width(),0, _transferFunction->format(), _transferFunction->dataType(), data);
glTexImage1D( GL_TEXTURE_1D, 0, _transferFunction->internalFormat(),
_transferFunction->width(),0, _transferFunction->format(),
_transferFunction->dataType(), data);
//delete data;
delete transferFunction;
LDEBUG("Updated transferfunction!");
@@ -154,15 +158,14 @@ void RenderableVolumeGL::render(const Camera *camera, const psc &thisPosition) {
}
}
glm::mat4 transform ;
glm::mat4 camTransform = camera->viewRotationMatrix();
psc relative = thisPosition-camera->position();
transform = camTransform;
glm::mat4 transform = camera->viewRotationMatrix();
transform = glm::translate(transform, relative.vec3());
transform = glm::translate(transform, glm::vec3(-1.1,0.0,0.0));
transform = glm::scale(transform, _boxScaling);
// TODO: Use _id to identify this volume
_colorBoxRenderer->render(camera->viewProjectionMatrix(), transform);
}

View File

@@ -404,4 +404,8 @@ Camera* RenderEngine::camera() const {
return _mainCamera;
}
ABuffer* RenderEngine::abuffer() const {
return _abuffer;
}
} // namespace openspace