Commit bcf97fe1 authored by Jan Möbius's avatar Jan Möbius

Merge branch 'glres_cleanup' into 'master'

GL resource cleanup

See merge request !4
parents c753790d ea5d24fb
...@@ -2,5 +2,5 @@ include (plugin) ...@@ -2,5 +2,5 @@ include (plugin)
openflipper_plugin (DIRS PoissonReconstruction openflipper_plugin (DIRS PoissonReconstruction
INSTALLDATA Icons INSTALLDATA Icons
TYPES TRIANGLEMESH TYPES TRIANGLEMESH POLYMESH
OPT_TYPES SPLATCLOUD ) OPT_TYPES SPLATCLOUD )
...@@ -158,6 +158,9 @@ ABufferGenModifier ABufferGenModifier::instance; ...@@ -158,6 +158,9 @@ ABufferGenModifier ABufferGenModifier::instance;
OITLinkedList::OITLinkedList() OITLinkedList::OITLinkedList()
{ {
fragCounter_ = new ACG::AtomicCounter();
startOffsetBuffer_ = new ACG::TextureBuffer();
ABuffer_ = new ACG::TextureBuffer();
} }
...@@ -172,6 +175,17 @@ void OITLinkedList::initializePlugin() ...@@ -172,6 +175,17 @@ void OITLinkedList::initializePlugin()
ACG::ShaderProgGenerator::registerModifier(&ABufferGenModifier::instance); ACG::ShaderProgGenerator::registerModifier(&ABufferGenModifier::instance);
} }
void OITLinkedList::exit()
{
delete fragCounter_;
fragCounter_ = 0;
delete startOffsetBuffer_;
startOffsetBuffer_ = 0;
delete ABuffer_;
ABuffer_ = 0;
}
void OITLinkedList::render(ACG::GLState* _glState, Viewer::ViewerProperties& _properties) void OITLinkedList::render(ACG::GLState* _glState, Viewer::ViewerProperties& _properties)
...@@ -180,7 +194,7 @@ void OITLinkedList::render(ACG::GLState* _glState, Viewer::ViewerProperties& _pr ...@@ -180,7 +194,7 @@ void OITLinkedList::render(ACG::GLState* _glState, Viewer::ViewerProperties& _pr
prepareRenderingPipeline(_glState, _properties.drawMode(), PluginFunctions::getSceneGraphRootNode()); prepareRenderingPipeline(_glState, _properties.drawMode(), PluginFunctions::getSceneGraphRootNode());
renderOIT(_glState->viewport_width(), _glState->viewport_height(), _properties.multisampling()); renderOIT(_glState->viewport_width(), _glState->viewport_height(), _properties.multisampling(), _properties.backgroundColor());
// restore common opengl state // restore common opengl state
// log window remains hidden otherwise // log window remains hidden otherwise
...@@ -198,24 +212,24 @@ void OITLinkedList::prepareBuffers(int w, int h) ...@@ -198,24 +212,24 @@ void OITLinkedList::prepareBuffers(int w, int h)
const int offsetBufSize = numPixels * 4; // uint buffer for each pixel const int offsetBufSize = numPixels * 4; // uint buffer for each pixel
const int ABufSize = numPixels * 16 * estAvgLayers; const int ABufSize = numPixels * 16 * estAvgLayers;
if (startOffsetBuffer_.getBufferSize() < offsetBufSize) if (startOffsetBuffer_->getBufferSize() < offsetBufSize)
startOffsetBuffer_.setBufferData(offsetBufSize, 0, GL_R32UI, GL_DYNAMIC_DRAW); startOffsetBuffer_->setBufferData(offsetBufSize, 0, GL_R32UI, GL_DYNAMIC_DRAW);
if (ABuffer_.getBufferSize() < ABufSize) if (ABuffer_->getBufferSize() < ABufSize)
ABuffer_.setBufferData(ABufSize, 0, GL_RGBA32UI, GL_DYNAMIC_DRAW); ABuffer_->setBufferData(ABufSize, 0, GL_RGBA32UI, GL_DYNAMIC_DRAW);
// dbg: force unbind // dbg: force unbind
glBindTexture(GL_TEXTURE_BUFFER, 0); glBindTexture(GL_TEXTURE_BUFFER, 0);
// reset fragment counter // reset fragment counter
fragCounter_.set(0); fragCounter_->set(0);
// wait for buffer allocation // wait for buffer allocation
glMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT | GL_SHADER_IMAGE_ACCESS_BARRIER_BIT); glMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT | GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
} }
void OITLinkedList::renderOIT(int w, int h, bool multisampled) void OITLinkedList::renderOIT(int w, int h, bool multisampled, const ACG::Vec4f& backColor)
{ {
ACG::Vec2ui screenSize = ACG::Vec2ui(GLuint(w), GLuint(h)); ACG::Vec2ui screenSize = ACG::Vec2ui(GLuint(w), GLuint(h));
...@@ -231,7 +245,7 @@ void OITLinkedList::renderOIT(int w, int h, bool multisampled) ...@@ -231,7 +245,7 @@ void OITLinkedList::renderOIT(int w, int h, bool multisampled)
// load reset shader for startOffsetBuffer // load reset shader for startOffsetBuffer
GLSL::Program* shaderReset = ACG::ShaderCache::getInstance()->getProgram("ScreenQuad/screenquad.glsl", "OITLinkedList/reset.glsl"); GLSL::Program* shaderReset = ACG::ShaderCache::getInstance()->getProgram("ScreenQuad/screenquad.glsl", "OITLinkedList/reset.glsl");
startOffsetBuffer_.bindAsImage(0, GL_WRITE_ONLY); startOffsetBuffer_->bindAsImage(0, GL_WRITE_ONLY);
shaderReset->use(); shaderReset->use();
...@@ -264,11 +278,11 @@ void OITLinkedList::renderOIT(int w, int h, bool multisampled) ...@@ -264,11 +278,11 @@ void OITLinkedList::renderOIT(int w, int h, bool multisampled)
glGetIntegerv(GL_SAMPLES, &msaaSampleCount); glGetIntegerv(GL_SAMPLES, &msaaSampleCount);
// bind UAV buffers // bind UAV buffers
startOffsetBuffer_.bindAsImage(0, GL_READ_WRITE); startOffsetBuffer_->bindAsImage(0, GL_READ_WRITE);
ABuffer_.bindAsImage(1, GL_WRITE_ONLY); ABuffer_->bindAsImage(1, GL_WRITE_ONLY);
// bind atomic counter // bind atomic counter
fragCounter_.bind(0); fragCounter_->bind(0);
for (int i = 0; i < getNumRenderObjects(); ++i) for (int i = 0; i < getNumRenderObjects(); ++i)
{ {
...@@ -290,7 +304,7 @@ void OITLinkedList::renderOIT(int w, int h, bool multisampled) ...@@ -290,7 +304,7 @@ void OITLinkedList::renderOIT(int w, int h, bool multisampled)
renderObject(obj, shaderRender); renderObject(obj, shaderRender);
} }
fragCounter_.unbind(); fragCounter_->unbind();
// wait for render pass to finish! // wait for render pass to finish!
...@@ -331,11 +345,13 @@ void OITLinkedList::renderOIT(int w, int h, bool multisampled) ...@@ -331,11 +345,13 @@ void OITLinkedList::renderOIT(int w, int h, bool multisampled)
// init shader constants // init shader constants
shaderResolve->use(); shaderResolve->use();
startOffsetBuffer_.bindAsImage(0, GL_READ_ONLY); startOffsetBuffer_->bindAsImage(0, GL_READ_ONLY);
ABuffer_.bindAsImage(1, GL_READ_ONLY); ABuffer_->bindAsImage(1, GL_READ_ONLY);
shaderResolve->setUniform("g_ScreenSize", screenSize); shaderResolve->setUniform("g_ScreenSize", screenSize);
shaderResolve->setUniform("g_BackColor", backColor);
if (multisampled) if (multisampled)
shaderResolve->setUniform("g_SampleCount", GLuint(msaaSampleCount)); shaderResolve->setUniform("g_SampleCount", GLuint(msaaSampleCount));
...@@ -370,14 +386,14 @@ void OITLinkedList::renderOIT(int w, int h, bool multisampled) ...@@ -370,14 +386,14 @@ void OITLinkedList::renderOIT(int w, int h, bool multisampled)
unsigned int actualFragmentCount = 0; unsigned int actualFragmentCount = 0;
fragCounter_.get(&actualFragmentCount); fragCounter_->get(&actualFragmentCount);
// resize ABuffer if too small // resize ABuffer if too small
// RGBA32UI : 16 bytes per fragment // RGBA32UI : 16 bytes per fragment
if (int(actualFragmentCount) * 16 > ABuffer_.getBufferSize()) if (int(actualFragmentCount) * 16 > ABuffer_->getBufferSize())
{ {
ABuffer_.setBufferData(actualFragmentCount * 18, 0, ABuffer_.getFormat(), ABuffer_.getUsage()); ABuffer_->setBufferData(actualFragmentCount * 18, 0, ABuffer_->getFormat(), ABuffer_->getUsage());
// std::cout << "buffer size too small: " << actualFragmentCount << std::endl; // std::cout << "buffer size too small: " << actualFragmentCount << std::endl;
} }
......
...@@ -89,7 +89,7 @@ private slots: ...@@ -89,7 +89,7 @@ private slots:
//BaseInterface //BaseInterface
void initializePlugin(); void initializePlugin();
void exit(){} void exit();
// RenderInterface // RenderInterface
void render(ACG::GLState* _glState, Viewer::ViewerProperties& _properties); void render(ACG::GLState* _glState, Viewer::ViewerProperties& _properties);
...@@ -104,19 +104,18 @@ private: ...@@ -104,19 +104,18 @@ private:
void prepareBuffers(int w, int h); void prepareBuffers(int w, int h);
void renderOIT(int w, int h, bool multisampled); void renderOIT(int w, int h, bool multisampled, const ACG::Vec4f& backColor);
// counter for number of processed fragments // counter for number of processed fragments
ACG::AtomicCounter fragCounter_; ACG::AtomicCounter* fragCounter_;
// stores start offset into FLBuffer // stores start offset into FLBuffer
ACG::TextureBuffer startOffsetBuffer_; ACG::TextureBuffer* startOffsetBuffer_;
// ABuffer: per pixel linked list buffer // ABuffer: per pixel linked list buffer
ACG::TextureBuffer ABuffer_; ACG::TextureBuffer* ABuffer_;
}; };
...@@ -17,6 +17,8 @@ layout(binding = 1, rgba32ui) uniform uimageBuffer g_ABuffer; ...@@ -17,6 +17,8 @@ layout(binding = 1, rgba32ui) uniform uimageBuffer g_ABuffer;
uniform uvec2 g_ScreenSize; uniform uvec2 g_ScreenSize;
uniform vec4 g_BackColor;
struct FragListEntry struct FragListEntry
{ {
...@@ -93,7 +95,7 @@ void main() ...@@ -93,7 +95,7 @@ void main()
uiOffset = fragEntry.z; uiOffset = fragEntry.z;
} }
vec4 color = vec4(0, 0, 0, 1); vec4 color = g_BackColor;
// blend back to front // blend back to front
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment