Moving global blackout factor into RenderEngine

Cleanup of Abuffer implementations
This commit is contained in:
Alexander Bock
2015-06-05 14:25:35 +02:00
parent 17498c28c6
commit 8de6d9db05
8 changed files with 28 additions and 63 deletions

View File

@@ -55,7 +55,7 @@ public:
ABuffer();
virtual ~ABuffer();
virtual void resolve();
virtual void resolve(float blackoutFactor);
virtual bool initialize() = 0;
virtual bool reinitialize();

View File

@@ -36,6 +36,8 @@ public:
virtual ~ABufferFramebuffer();
virtual bool initialize();
void resolve(float blackoutFactor);
virtual void clear();
virtual void preRender();
virtual void postRender();

View File

@@ -56,6 +56,8 @@ const float stepSize = 0.01;
const float samplingRate = 1.0;
uniform float ALPHA_LIMIT = 0.99;
uniform float blackoutFactor = 0.0;
// Math defintions
#define M_E 2.7182818284590452354
@@ -307,7 +309,7 @@ void main() {
out_color = vec4(texCoord,0.0,1.0);
int frag_count = build_local_fragments_list();
sort_fragments_list(frag_count);
out_color = calculate_final_color(frag_count);
out_color = blackoutFactor * calculate_final_color(frag_count);
}
// ================================================================================

View File

@@ -55,20 +55,17 @@ namespace openspace {
ABuffer::ABuffer()
: _validShader(false)
, _resolveShader(nullptr)
, _volumeStepFactor(0.0f)
, _volumeStepFactor(0.f)
{
updateDimensions();
}
ABuffer::~ABuffer() {
if(_resolveShader)
delete _resolveShader;
delete _resolveShader;
for(auto file: _samplerFiles) {
for (auto file: _samplerFiles)
delete file;
}
}
bool ABuffer::initializeABuffer() {
@@ -88,14 +85,14 @@ bool ABuffer::initializeABuffer() {
if (!_resolveShader)
return false;
_resolveShader->setProgramObjectCallback(shaderCallback);
// Remove explicit callback and use programobject isDirty instead ---abock
#ifndef __APPLE__
// ============================
// GEOMETRY (quad)
// ============================
const GLfloat size = 1.0f;
const GLfloat vertex_data[] = { // square of two triangles (sigh)
// x y z w s t
const GLfloat vertex_data[] = {
// x y s t
-size, -size, 0.0f, 1.0f,
size, size, 0.0f, 1.0f,
-size, size, 0.0f, 1.0f,
@@ -111,20 +108,17 @@ bool ABuffer::initializeABuffer() {
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*4, reinterpret_cast<void*>(0));
glEnableVertexAttribArray(0);
#endif
return true;
}
bool ABuffer::reinitialize() {
// set the total resolution for all viewports
updateDimensions();
return reinitializeInternal();
}
void ABuffer::resolve() {
#ifndef __APPLE__
if( ! _validShader) {
void ABuffer::resolve(float blackoutFactor) {
if (!_validShader) {
generateShaderSource();
updateShader();
_validShader = true;
@@ -134,13 +128,14 @@ void ABuffer::resolve() {
return;
_resolveShader->activate();
_resolveShader->setUniform("blackoutFactor", blackoutFactor);
int startAt = 0;
for(int i = 0; i < _volumes.size(); ++i) {
for (int i = 0; i < _volumes.size(); ++i) {
glActiveTexture(GL_TEXTURE0 + i);
_volumes.at(i).second->bind();
startAt = i + 1;
}
for(int i = 0; i < _transferFunctions.size(); ++i) {
for (int i = 0; i < _transferFunctions.size(); ++i) {
glActiveTexture(GL_TEXTURE0 + startAt + i);
_transferFunctions.at(i).second->bind();
}
@@ -158,7 +153,6 @@ void ABuffer::resolve() {
glDrawArrays(GL_TRIANGLES, 0, 6);
_resolveShader->deactivate();
#endif
}
void ABuffer::addVolume(const std::string& tag,ghoul::opengl::Texture* volume) {
@@ -212,8 +206,7 @@ bool ABuffer::updateShader() {
}
void ABuffer::generateShaderSource() {
for(int i = 0; i < _samplerFiles.size(); ++i) {
for (int i = 0; i < _samplerFiles.size(); ++i) {
std::string line, source = "";
std::ifstream samplerFile(_samplerFiles.at(i)->path());
if(samplerFile.is_open()) {
@@ -233,7 +226,6 @@ void ABuffer::generateShaderSource() {
}
void ABuffer::openspaceHeaders() {
std::ofstream f(absPath(generatedHeadersPath));
f << "#define MAX_VOLUMES " << std::to_string(_samplers.size()) << "\n"
<< "#define MAX_TF " << _transferFunctions.size() << "\n";

View File

@@ -59,6 +59,9 @@ void ABufferFramebuffer::preRender() {
void ABufferFramebuffer::postRender() {
}
void ABufferFramebuffer::resolve(float blackoutFactor) {
}
std::vector<ABuffer::fragmentData> ABufferFramebuffer::pixelData() {
return std::vector<ABuffer::fragmentData>();

View File

@@ -56,11 +56,11 @@ ABufferSingleLinked::ABufferSingleLinked()
{}
ABufferSingleLinked::~ABufferSingleLinked() {
glDeleteTextures(1,&_anchorPointerTexture);
glDeleteTextures(1,&_fragmentTexture);
glDeleteBuffers(1,&_anchorPointerTextureInitializer);
glDeleteBuffers(1,&_atomicCounterBuffer);
glDeleteBuffers(1,&_anchorPointerTextureInitializer);
glDeleteTextures(1, &_anchorPointerTexture);
glDeleteTextures(1, &_fragmentTexture);
glDeleteBuffers(1, &_anchorPointerTextureInitializer);
glDeleteBuffers(1, &_atomicCounterBuffer);
glDeleteBuffers(1, &_anchorPointerTextureInitializer);
}
bool ABufferSingleLinked::initialize() {
@@ -123,7 +123,6 @@ void ABufferSingleLinked::clear() {
}
void ABufferSingleLinked::preRender() {
// Bind head-pointer image for read-write
glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, _atomicCounterBuffer);
glBindImageTexture(0, _anchorPointerTexture, 0, GL_FALSE, 0, GL_READ_WRITE, GL_R32UI);
@@ -135,7 +134,6 @@ void ABufferSingleLinked::postRender() {
}
std::vector<ABufferSingleLinked::fragmentData> ABufferSingleLinked::pixelData() {
unsigned int* anchorTexture = new unsigned int[_totalPixels];
unsigned int* fragmentBuffer = new unsigned int[_totalPixels*MAX_LAYERS*4];
@@ -201,4 +199,4 @@ std::vector<ABufferSingleLinked::fragmentData> ABufferSingleLinked::pixelData()
return d;
}
} // openspace
} // openspace

View File

@@ -73,12 +73,6 @@ std::pair<int, int> supportedOpenGLVersion () {
return { major, minor };
}
//temporary post-FX functions, TODO make a more permanent solution to this @JK
void postFXPass();
void setupPostFX();
GLint _postFXTexLoc;
GLint _postFXOpacityLoc;
#include <ghoul/lua/lua_helper.h>
namespace {
@@ -195,9 +189,6 @@ void mainInitFunc() {
std::cin.ignore(100);
exit(EXIT_FAILURE);
}
//temporary post-FX solution, TODO add a more permanent solution @JK
setupPostFX();
}
void mainPreSyncFunc() {
@@ -272,26 +263,3 @@ void mainLogCallback(const char* msg){
// Remove the trailing \n that is passed along
LINFOC("SGCT", message.substr(0, std::max<size_t>(message.size() - 1, 0)));
}
void postFXPass(){
glUniform1i(_postFXTexLoc, 0);
if (OsEng.isMaster())
glUniform1f(_postFXOpacityLoc, 1.f);
else
glUniform1f(_postFXOpacityLoc, OsEng.renderEngine()->globalBlackOutFactor());
}
void setupPostFX(){
#ifndef __APPLE__
sgct::PostFX fx[1];
sgct::ShaderProgram *shader;
fx[0].init("OpacityControl", absPath("${SHADERS}/postFX_vs.glsl"), absPath("${SHADERS}/postFX_fs.glsl"));
fx[0].setUpdateUniformsFunction(postFXPass);
shader = fx[0].getShaderProgram();
shader->bind();
_postFXTexLoc = shader->getUniformLocation("Tex");
_postFXOpacityLoc = shader->getUniformLocation("Opacity");
shader->unbind();
_sgctEngine->addPostFX(fx[0]);
#endif
}

View File

@@ -395,7 +395,7 @@ void RenderEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &vi
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
_abuffer->resolve();
_abuffer->resolve(_globalBlackOutFactor);
glDisable(GL_BLEND);
}
else {