Added ABuffer reinitialization

- Fixed so ABuffer reinitializes properly (could probably be optimized by
  not resizing of smaller than before)
- Now setting size properly from window dimensions
- SGCT side-by-side stereo working
This commit is contained in:
Jonas Strandstedt
2014-10-17 14:50:40 +02:00
parent 9a1b59a73e
commit 7ef5295bb7
12 changed files with 87 additions and 51 deletions
+5
View File
@@ -49,6 +49,7 @@ public:
ABuffer();
virtual ~ABuffer();
virtual void resolve();
virtual bool reinitialize();
void addVolume(const std::string& tag,ghoul::opengl::Texture* volume);
void addTransferFunction(const std::string& tag,ghoul::opengl::Texture* transferFunction);
@@ -58,6 +59,7 @@ public:
protected:
virtual std::string settings() = 0;
virtual bool reinitializeInternal() = 0;
bool initializeABuffer();
@@ -72,6 +74,9 @@ protected:
unsigned int _width, _height, _totalPixels;
private:
void updateDimensions();
GLuint _screenQuad;
bool _validShader;
@@ -41,6 +41,8 @@ public:
virtual void postRender();
virtual std::string settings();
protected:
virtual bool reinitializeInternal();
private:
+1
View File
@@ -31,6 +31,7 @@ class ABuffer_I {
public:
virtual ~ABuffer_I() {};
virtual bool initialize() = 0;
virtual bool reinitialize() = 0;
virtual void clear() = 0;
virtual void preRender() = 0;
@@ -41,6 +41,8 @@ public:
virtual void postRender();
virtual std::string settings();
protected:
virtual bool reinitializeInternal();
private:
+2
View File
@@ -41,6 +41,8 @@ public:
virtual void postRender();
virtual std::string settings();
protected:
virtual bool reinitializeInternal();
private:
+3 -3
View File
@@ -34,9 +34,9 @@ layout (binding = 0, offset = 0) uniform atomic_uint atomicCounterBuffer;
layout (binding = 0, r32ui) uniform uimage2D anchorPointerTexture;
layout (binding = 1, rgba32ui) uniform uimageBuffer fragmentTexture;
#define _MAX_LAYERS_ 64
#define _SCREEN_WIDTH_ 1280
#define _SCREEN_HEIGHT_ 720
#define _MAX_LAYERS_ MAX_LAYERS
#define _SCREEN_WIDTH_ SCREEN_WIDTH
#define _SCREEN_HEIGHT_ SCREEN_HEIGHT
#endif
ABufferStruct_t createGeometryFragment(vec4 fragColor, vec4 position, float z = gl_FragCoord.z) {
+29 -18
View File
@@ -48,11 +48,7 @@ namespace {
namespace openspace {
ABuffer::ABuffer() : _validShader(false), _resolveShader(nullptr) {
int x1, xSize, y1, ySize;
sgct::Engine::instance()->getActiveWindowPtr()->getCurrentViewportPixelCoords(x1, y1, xSize, ySize);
_width = xSize;
_height = ySize;
_totalPixels = _width * _height;
updateDimensions();
}
ABuffer::~ABuffer() {
@@ -71,7 +67,6 @@ bool ABuffer::initializeABuffer() {
// ============================
auto shaderCallback = [this](ghoul::opengl::ProgramObject* program) {
// Error for visibility in log
LERROR(program->name() << " invalidated");
_validShader = false;
};
@@ -110,10 +105,17 @@ bool ABuffer::initializeABuffer() {
return true;
}
bool ABuffer::reinitialize() {
// set the total resolution for all viewports
updateDimensions();
return reinitializeInternal();
}
void ABuffer::resolve() {
if( ! _validShader) {
SleepEx(0, TRUE);
//generateShaderSource();
generateShaderSource();
updateShader();
_validShader = true;
}
@@ -184,7 +186,10 @@ bool ABuffer::updateShader() {
for (int i = 0; i < _transferFunctions.size(); ++i) {
_resolveShader->setUniform(_transferFunctions.at(i).first, startAt + i);
}
LINFO("Successfully updated shader!");
LINFO("Successfully updated ABuffer resolve shader!");
}
else {
LWARNING("Couldn't update ABuffer resolve shader");
}
return s;
}
@@ -215,7 +220,7 @@ void ABuffer::openspaceHeaders() {
std::ofstream f(absPath(generatedHeadersPath));
f << "#define MAX_VOLUMES " << std::to_string(_samplers.size()) << "\n"
<< "#define MAX_TF " << std::to_string(_transferFunctions.size()) << "\n";
<< "#define MAX_TF " << _transferFunctions.size() << "\n";
for (int i = 0; i < _volumes.size(); ++i) {
f << "uniform sampler3D " << _volumes.at(i).first << ";\n";
}
@@ -246,7 +251,7 @@ void ABuffer::openspaceHeaders() {
}
f << "};\n";
f << "#define LOOP_LIMIT " + std::to_string(maxLoop) + "\n";
f << "#define LOOP_LIMIT " << maxLoop << "\n";
f << "float volumeStepSize[] = {\n";
for (int i = 0; i < _volumes.size(); ++i) {
@@ -272,11 +277,11 @@ void ABuffer::openspaceSamplerCalls() {
auto found2 = _samplers.at(i).find_first_of("(", found1);
if (found1 != std::string::npos && found2 != std::string::npos) {
std::string functionName = _samplers.at(i).substr(found1, found2 - found1);
f << "#ifndef SKIP_VOLUME_" << std::to_string(i) << "\n"
<< "if((currentVolumeBitmask & (1 << " << std::to_string(i) << ")) == " << std::to_string(1 << i) << ") {\n"
<< " vec4 c = " << functionName << "(final_color,volume_position[" << std::to_string(i) << "]);\n"
<< " blendStep(final_color, c, volumeStepSize[" << std::to_string(i) << "]);\n"
<< " volume_position[" << std::to_string(i) << "] += volume_direction[" << std::to_string(i) << "]*volumeStepSize[" << std::to_string(i) << "];\n"
f << "#ifndef SKIP_VOLUME_" << i << "\n"
<< "if((currentVolumeBitmask & (1 << " << i << ")) == " << std::to_string(1 << i) << ") {\n"
<< " vec4 c = " << functionName << "(final_color,volume_position[" << i << "]);\n"
<< " blendStep(final_color, c, volumeStepSize[" << i << "]);\n"
<< " volume_position[" << i << "] += volume_direction[" << i << "]*volumeStepSize[" << i << "];\n"
<< "}\n"
<< "#endif\n";
}
@@ -299,18 +304,18 @@ void ABuffer::openspaceTransferFunction() {
<< "float SCREEN_HEIGHTf = float(SCREEN_HEIGHT);\n"
<< "float SCREEN_WIDTHf = float(SCREEN_WIDTH);\n";
for (int i = 0; i < _transferFunctions.size(); ++i) {
f << "if( gl_FragCoord.y > SCREEN_HEIGHTf-showfunc_size*" << std::to_string(i + 1)
f << "if( gl_FragCoord.y > SCREEN_HEIGHTf-showfunc_size*" << i + 1
<< " && gl_FragCoord.y < SCREEN_HEIGHTf-showfunc_size*" << std::to_string(i) << ") {\n"
<< " float normalizedIntensity = gl_FragCoord.x / (SCREEN_WIDTHf-1) ;\n"
<< " vec4 tfc = texture(" << _transferFunctions.at(i).first << ", normalizedIntensity);\n"
<< " final_color = tfc;\n"
<< " float cmpf = SCREEN_HEIGHTf-showfunc_size*" << std::to_string(i + 1) << " + tfc.a*showfunc_size;\n"
<< " float cmpf = SCREEN_HEIGHTf-showfunc_size*" << i + 1 << " + tfc.a*showfunc_size;\n"
<< " if(gl_FragCoord.y > cmpf) {\n"
<< " final_color = vec4(0,0,0,0);\n"
<< " } else {\n"
<< " final_color.a = 1.0;\n"
<< " }\n"
<< "} else if(ceil(gl_FragCoord.y) == SCREEN_HEIGHTf - showfunc_size*" << std::to_string(i + 1) << ") {\n"
<< "} else if(ceil(gl_FragCoord.y) == SCREEN_HEIGHTf - showfunc_size*" << i + 1 << ") {\n"
<< " const float intensity = 0.4;\n"
<< " final_color = vec4(intensity,intensity,intensity,1.0);\n"
<< "}\n";
@@ -323,5 +328,11 @@ void ABuffer::invalidateABuffer() {
_validShader = false;
}
void ABuffer::updateDimensions() {
_width = sgct::Engine::instance()->getActiveWindowPtr()->getXFramebufferResolution();
_height = sgct::Engine::instance()->getActiveWindowPtr()->getYFramebufferResolution();
_totalPixels = _width * _height;
}
} // openspace
+19 -13
View File
@@ -59,10 +59,22 @@ bool ABufferSingleLinked::initialize() {
// BUFFERS
// ============================
glGenTextures(1, &_anchorPointerTexture);
glGenBuffers(1, &_anchorPointerTextureInitializer);
glGenBuffers(1, &_atomicCounterBuffer);
glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, _atomicCounterBuffer);
glBufferData(GL_ATOMIC_COUNTER_BUFFER, sizeof(GLuint), NULL, GL_DYNAMIC_COPY);
glGenBuffers(1, &_fragmentBuffer);
glGenTextures(1, &_fragmentTexture);
reinitialize();
return initializeABuffer();
}
bool ABufferSingleLinked::reinitializeInternal() {
glBindTexture(GL_TEXTURE_2D, _anchorPointerTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32UI, _width, _height, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, NULL);
glGenBuffers(1, &_anchorPointerTextureInitializer);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, _anchorPointerTextureInitializer);
glBufferData(GL_PIXEL_UNPACK_BUFFER, _totalPixels * sizeof(GLuint), NULL, GL_STATIC_DRAW);
@@ -71,22 +83,16 @@ bool ABufferSingleLinked::initialize() {
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
glGenBuffers(1, &_atomicCounterBuffer);
glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, _atomicCounterBuffer);
glBufferData(GL_ATOMIC_COUNTER_BUFFER, sizeof(GLuint), NULL, GL_DYNAMIC_COPY);
glGenBuffers(1, &_fragmentBuffer);
glBindBuffer(GL_TEXTURE_BUFFER, _fragmentBuffer);
glBufferData(GL_TEXTURE_BUFFER, MAX_LAYERS*_totalPixels*sizeof(GLfloat)*4, NULL, GL_DYNAMIC_COPY);
glBufferData(GL_TEXTURE_BUFFER, MAX_LAYERS*_totalPixels*sizeof(GLfloat) * 4, NULL, GL_DYNAMIC_COPY);
glGenTextures(1, &_fragmentTexture);
glBindTexture(GL_TEXTURE_BUFFER, _fragmentTexture);
glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32UI, _fragmentBuffer);
glBindTexture(GL_TEXTURE_BUFFER, 0);
glBindTexture(GL_TEXTURE_BUFFER, _fragmentTexture);
glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32UI, _fragmentBuffer);
glBindTexture(GL_TEXTURE_BUFFER, 0);
glBindImageTexture(1, _fragmentTexture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32UI);
glBindImageTexture(1, _fragmentTexture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32UI);
return initializeABuffer();
return true;
}
void ABufferSingleLinked::clear() {
+4
View File
@@ -89,6 +89,10 @@ bool ABufferDynamic::initialize() {
return initializeABuffer();
}
bool ABufferDynamic::reinitializeInternal() {
return false;
}
void ABufferDynamic::clear() {
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, _anchorPointerTextureInitializer);
glBindTexture(GL_TEXTURE_2D, _anchorPointerTexture);
+4
View File
@@ -97,6 +97,10 @@ bool ABufferFixed::initialize() {
return initializeABuffer();
}
bool ABufferFixed::reinitializeInternal() {
return false;
}
void ABufferFixed::clear() {
// Bind texture initializer
+15 -16
View File
@@ -185,15 +185,17 @@ bool RenderEngine::initializeGL()
void RenderEngine::postSynchronizationPreDraw()
{
sgct_core::SGCTNode * thisNode = sgct_core::ClusterManager::instance()->getThisNodePtr();
for (unsigned int i = 0; i < thisNode->getNumberOfWindows(); i++)
if (sgct::Engine::instance()->getWindowPtr(i)->isWindowResized())
generateGlslConfig();
// Move time forward.
//_runtimeData->advanceTimeBy(1, DAY);
//_runtimeData->advanceTimeBy(1, HOUR);
//_runtimeData->advanceTimeBy(30, MINUTE);
//_runtimeData->advanceTimeBy(1, MILLISECOND);
bool updateAbuffer = false;
for (unsigned int i = 0; i < thisNode->getNumberOfWindows(); i++) {
if (sgct::Engine::instance()->getWindowPtr(i)->isWindowResized()) {
updateAbuffer = true;
break;
}
}
if (updateAbuffer) {
generateGlslConfig();
_abuffer->reinitialize();
}
// converts the quaternion used to rotation matrices
_mainCamera->compileViewRotationMatrix();
@@ -202,13 +204,13 @@ void RenderEngine::postSynchronizationPreDraw()
_sceneGraph->update({Time::ref().currentTime()});
_mainCamera->setCameraDirection(glm::vec3(0, 0, -1));
_sceneGraph->evaluate(_mainCamera);
_abuffer->clear();
}
void RenderEngine::render()
{
// SGCT resets certain settings
//glEnable(GL_DEPTH_TEST);
//glEnable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
@@ -232,7 +234,6 @@ void RenderEngine::render()
// render the scene starting from the root node
_abuffer->clear();
_abuffer->preRender();
_sceneGraph->render({*_mainCamera, psc()});
_abuffer->postRender();
@@ -504,10 +505,8 @@ ABuffer* RenderEngine::abuffer() const {
void RenderEngine::generateGlslConfig() {
LDEBUG("Generating GLSLS config, expect shader recompilation");
int x1, xSize, y1, ySize;
sgct::Engine::instance()->
getActiveWindowPtr()->
getCurrentViewportPixelCoords(x1, y1, xSize, ySize);
int xSize = sgct::Engine::instance()->getActiveWindowPtr()->getXFramebufferResolution();;
int ySize = sgct::Engine::instance()->getActiveWindowPtr()->getYFramebufferResolution();;
// TODO: Make this file creation dynamic and better in every way
// TODO: If the screen size changes it is enough if this file is regenerated to