2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit e41c14c1 authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

further work on OpenGL refactoring

parent 42480c65
...@@ -63,6 +63,9 @@ namespace campvis { ...@@ -63,6 +63,9 @@ namespace campvis {
{ {
tgtAssert(_fbo != 0, "FBO must not be 0."); tgtAssert(_fbo != 0, "FBO must not be 0.");
_fbo->activate(); _fbo->activate();
const tgt::ivec2& windowSize = vp->_renderTargetSize.getValue();
glViewport(0, 0, static_cast<GLsizei>(windowSize.x), static_cast<GLsizei>(windowSize.y));
} }
~FramebufferActivationGuard() { ~FramebufferActivationGuard() {
......
...@@ -103,8 +103,7 @@ namespace campvis { ...@@ -103,8 +103,7 @@ namespace campvis {
maxDepth = std::max(maxDepth, curDepth); maxDepth = std::max(maxDepth, curDepth);
} }
std::pair<ImageData*, ImageRepresentationRenderTarget*> tempTarget = ImageRepresentationRenderTarget::createWithImageData(_renderTargetSize.getValue()); FramebufferActivationGuard fag(this);
std::pair<ImageData*, ImageRepresentationRenderTarget*> outputTarget = ImageRepresentationRenderTarget::createWithImageData(_renderTargetSize.getValue());
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_ALWAYS); glDepthFunc(GL_ALWAYS);
...@@ -124,21 +123,22 @@ namespace campvis { ...@@ -124,21 +123,22 @@ namespace campvis {
_shader->setUniform("_warmColor", p_warmColor.getValue()); _shader->setUniform("_warmColor", p_warmColor.getValue());
} }
tempTarget.second->activate(); createAndAttachDepthTexture();
LGL_ERROR;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
QuadRdr.renderQuad(); QuadRdr.renderQuad();
tempTarget.second->deactivate();
std::pair<ImageData*, ImageRepresentationRenderTarget*> tempTarget = ImageRepresentationRenderTarget::createWithImageData(_renderTargetSize.getValue(), _fbo);
_fbo->detachAll();
createAndAttachColorTexture();
createAndAttachDepthTexture();
inputImage->bind(_shader, colorUnit, depthUnit); inputImage->bind(_shader, colorUnit, depthUnit);
tempTarget.second->bindDepthTexture(_shader, pass2DepthUnit, "_depthPass2Texture", "_pass2TexParams"); tempTarget.second->bindDepthTexture(_shader, pass2DepthUnit, "_depthPass2Texture", "_pass2TexParams");
_shader->setUniform("_direction", tgt::vec2(0.f, 1.f)); _shader->setUniform("_direction", tgt::vec2(0.f, 1.f));
outputTarget.second->activate();
LGL_ERROR;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
QuadRdr.renderQuad(); QuadRdr.renderQuad();
outputTarget.second->deactivate(); std::pair<ImageData*, ImageRepresentationRenderTarget*> outputTarget = ImageRepresentationRenderTarget::createWithImageData(_renderTargetSize.getValue(), _fbo);
_shader->deactivate(); _shader->deactivate();
tgt::TextureUnit::setZeroUnit(); tgt::TextureUnit::setZeroUnit();
...@@ -146,7 +146,7 @@ namespace campvis { ...@@ -146,7 +146,7 @@ namespace campvis {
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
LGL_ERROR; LGL_ERROR;
data.addData(p_outputImage.getValue() + "temp", tempTarget.first); delete tempTarget.first;
data.addData(p_outputImage.getValue(), outputTarget.first); data.addData(p_outputImage.getValue(), outputTarget.first);
p_outputImage.issueWrite(); p_outputImage.issueWrite();
} }
......
...@@ -137,6 +137,7 @@ namespace campvis { ...@@ -137,6 +137,7 @@ namespace campvis {
} }
} }
FramebufferActivationGuard fag(this);
decorateRenderProlog(data, _shader); decorateRenderProlog(data, _shader);
const tgt::Camera& cam = p_camera.getValue(); const tgt::Camera& cam = p_camera.getValue();
...@@ -175,8 +176,8 @@ namespace campvis { ...@@ -175,8 +176,8 @@ namespace campvis {
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
// create entry points texture // create entry points texture
std::pair<ImageData*, ImageRepresentationRenderTarget*> entrypoints = ImageRepresentationRenderTarget::createWithImageData(_renderTargetSize.getValue(), GL_RGBA16); createAndAttachTexture(GL_RGBA16);
entrypoints.second->activate(); createAndAttachDepthTexture();
_shader->setUniform("_isEntrypoint", true); _shader->setUniform("_isEntrypoint", true);
glDepthFunc(GL_LESS); glDepthFunc(GL_LESS);
...@@ -185,11 +186,12 @@ namespace campvis { ...@@ -185,11 +186,12 @@ namespace campvis {
glCullFace(p_enableMirror.getValue() ? GL_FRONT : GL_BACK); glCullFace(p_enableMirror.getValue() ? GL_FRONT : GL_BACK);
clipped.render(GL_POLYGON); clipped.render(GL_POLYGON);
entrypoints.second->deactivate(); std::pair<ImageData*, ImageRepresentationRenderTarget*> entrypoints = ImageRepresentationRenderTarget::createWithImageData(_renderTargetSize.getValue(), _fbo);
_fbo->detachAll();
// create exit points texture // create exit points texture
std::pair<ImageData*, ImageRepresentationRenderTarget*> exitpoints = ImageRepresentationRenderTarget::createWithImageData(_renderTargetSize.getValue(), GL_RGBA16); createAndAttachTexture(GL_RGBA16);
exitpoints.second->activate(); createAndAttachDepthTexture();
_shader->setUniform("_isEntrypoint", false); _shader->setUniform("_isEntrypoint", false);
if (geometryImage != 0) { if (geometryImage != 0) {
...@@ -202,8 +204,7 @@ namespace campvis { ...@@ -202,8 +204,7 @@ namespace campvis {
glCullFace(p_enableMirror.getValue() ? GL_BACK : GL_FRONT); glCullFace(p_enableMirror.getValue() ? GL_BACK : GL_FRONT);
clipped.render(GL_POLYGON); clipped.render(GL_POLYGON);
exitpoints.second->deactivate(); std::pair<ImageData*, ImageRepresentationRenderTarget*> exitpoints = ImageRepresentationRenderTarget::createWithImageData(_renderTargetSize.getValue(), _fbo);
decorateRenderEpilog(_shader); decorateRenderEpilog(_shader);
_shader->deactivate(); _shader->deactivate();
......
...@@ -100,8 +100,9 @@ namespace campvis { ...@@ -100,8 +100,9 @@ namespace campvis {
_shader->setIgnoreUniformLocationError(false); _shader->setIgnoreUniformLocationError(false);
// create entry points texture // create entry points texture
std::pair<ImageData*, ImageRepresentationRenderTarget*> rt = ImageRepresentationRenderTarget::createWithImageData(_renderTargetSize.getValue(), GL_RGBA16); FramebufferActivationGuard fag(this);
rt.second->activate(); createAndAttachColorTexture();
createAndAttachDepthTexture();
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS); glDepthFunc(GL_LESS);
...@@ -109,13 +110,12 @@ namespace campvis { ...@@ -109,13 +110,12 @@ namespace campvis {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
proxyGeometry->render(); proxyGeometry->render();
rt.second->deactivate();
decorateRenderEpilog(_shader); decorateRenderEpilog(_shader);
_shader->deactivate(); _shader->deactivate();
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
LGL_ERROR; LGL_ERROR;
data.addData(p_renderTargetID.getValue(), rt.first); data.addData(p_renderTargetID.getValue(), ImageRepresentationRenderTarget::createWithImageData(_renderTargetSize.getValue(), _fbo).first);
p_renderTargetID.issueWrite(); p_renderTargetID.issueWrite();
} }
else { else {
......
...@@ -84,24 +84,23 @@ namespace campvis { ...@@ -84,24 +84,23 @@ namespace campvis {
ImageRepresentationRenderTarget::ScopedRepresentation mirrorRendered(data, p_mirrorRenderID.getValue()); ImageRepresentationRenderTarget::ScopedRepresentation mirrorRendered(data, p_mirrorRenderID.getValue());
if (normalImage != 0 && mirrorImage != 0 && mirrorRendered != 0) { if (normalImage != 0 && mirrorImage != 0 && mirrorRendered != 0) {
std::pair<ImageData*, ImageRepresentationRenderTarget*> rt = ImageRepresentationRenderTarget::createWithImageData(_renderTargetSize.getValue());
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_ALWAYS); glDepthFunc(GL_ALWAYS);
FramebufferActivationGuard fag(this);
createAndAttachColorTexture();
createAndAttachDepthTexture();
_shader->activate(); _shader->activate();
tgt::TextureUnit normalColorUnit, normalDepthUnit, mirrorColorUnit, mirrorDepthUnit, mirrorRenderedDepthUnit; decorateRenderProlog(data, _shader);
tgt::TextureUnit normalColorUnit, normalDepthUnit, mirrorColorUnit, mirrorDepthUnit, mirrorRenderedDepthUnit;
normalImage->bind(_shader, normalColorUnit, normalDepthUnit, "_normalColor", "_normalDepth", "_normalTexParams"); normalImage->bind(_shader, normalColorUnit, normalDepthUnit, "_normalColor", "_normalDepth", "_normalTexParams");
mirrorImage->bind(_shader, mirrorColorUnit, mirrorDepthUnit, "_mirrorColor", "_mirrorDepth", "_mirrorTexParams"); mirrorImage->bind(_shader, mirrorColorUnit, mirrorDepthUnit, "_mirrorColor", "_mirrorDepth", "_mirrorTexParams");
mirrorRendered->bindDepthTexture(_shader, mirrorRenderedDepthUnit, "_mirrorRenderedDepth", "_mirrorRenderedTexParams"); mirrorRendered->bindDepthTexture(_shader, mirrorRenderedDepthUnit, "_mirrorRenderedDepth", "_mirrorRenderedTexParams");
decorateRenderProlog(data, _shader);
rt.second->activate();
LGL_ERROR;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
QuadRdr.renderQuad(); QuadRdr.renderQuad();
rt.second->deactivate();
_shader->deactivate(); _shader->deactivate();
tgt::TextureUnit::setZeroUnit(); tgt::TextureUnit::setZeroUnit();
...@@ -109,7 +108,7 @@ namespace campvis { ...@@ -109,7 +108,7 @@ namespace campvis {
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
LGL_ERROR; LGL_ERROR;
data.addData(p_targetImageID.getValue(), rt.first); data.addData(p_targetImageID.getValue(), ImageRepresentationRenderTarget::createWithImageData(_renderTargetSize.getValue(), _fbo).first);
p_targetImageID.issueWrite(); p_targetImageID.issueWrite();
} }
else { else {
......
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