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

Cleaned up CampVisPainter:

Introducing nifty error texture in case that there is nothing to render. Updated copyimage.frag to use texture coordinates instead of viewport pixels.
parent 6e2073bc
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "tgt/glcontextmanager.h" #include "tgt/glcontextmanager.h"
#include "tgt/gpucapabilities.h" #include "tgt/gpucapabilities.h"
#include "tgt/shadermanager.h" #include "tgt/shadermanager.h"
#include "tgt/texturereadertga.h"
#include "tgt/qt/qtapplication.h" #include "tgt/qt/qtapplication.h"
#include "tgt/qt/qtthreadedcanvas.h" #include "tgt/qt/qtthreadedcanvas.h"
#include "tbb/compat/thread" #include "tbb/compat/thread"
...@@ -53,6 +54,7 @@ namespace campvis { ...@@ -53,6 +54,7 @@ namespace campvis {
: QApplication(argc, argv) : QApplication(argc, argv)
, _localContext(0) , _localContext(0)
, _mainWindow(0) , _mainWindow(0)
, _errorTexture(nullptr)
, _initialized(false) , _initialized(false)
, _argc(argc) , _argc(argc)
, _argv(argv) , _argv(argv)
...@@ -137,6 +139,10 @@ namespace campvis { ...@@ -137,6 +139,10 @@ namespace campvis {
GLJobProc.start(); GLJobProc.start();
GLJobProc.registerContext(_localContext); GLJobProc.registerContext(_localContext);
// load textureData from file
tgt::TextureReaderTga trt;
_errorTexture = trt.loadTexture(CAMPVIS_SOURCE_DIR "/application/data/no_input.tga", tgt::Texture::LINEAR);
// parse argument list and create pipelines // parse argument list and create pipelines
QStringList pipelinesToAdd = this->arguments(); QStringList pipelinesToAdd = this->arguments();
for (int i = 1; i < pipelinesToAdd.size(); ++i) { for (int i = 1; i < pipelinesToAdd.size(); ++i) {
...@@ -158,6 +164,8 @@ namespace campvis { ...@@ -158,6 +164,8 @@ namespace campvis {
// Deinit everything OpenGL related using the local context. // Deinit everything OpenGL related using the local context.
tgt::GLContextScopedLock lock(_localContext); tgt::GLContextScopedLock lock(_localContext);
delete _errorTexture;
// Deinit pipeline first // Deinit pipeline first
for (std::vector<AbstractPipeline*>::iterator it = _pipelines.begin(); it != _pipelines.end(); ++it) { for (std::vector<AbstractPipeline*>::iterator it = _pipelines.begin(); it != _pipelines.end(); ++it) {
(*it)->deinit(); (*it)->deinit();
...@@ -213,6 +221,7 @@ namespace campvis { ...@@ -213,6 +221,7 @@ namespace campvis {
CampVisPainter* painter = new CampVisPainter(canvas, pipeline); CampVisPainter* painter = new CampVisPainter(canvas, pipeline);
canvas->setPainter(painter, false); canvas->setPainter(painter, false);
pipeline->setCanvas(canvas); pipeline->setCanvas(canvas);
painter->setErrorTexture(_errorTexture);
_visualizations.push_back(std::make_pair(pipeline, painter)); _visualizations.push_back(std::make_pair(pipeline, painter));
_pipelines.push_back(pipeline); _pipelines.push_back(pipeline);
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
namespace tgt { namespace tgt {
class GLCanvas; class GLCanvas;
class QtThreadedCanvas; class QtThreadedCanvas;
class Texture;
} }
namespace campvis { namespace campvis {
...@@ -152,6 +153,8 @@ namespace campvis { ...@@ -152,6 +153,8 @@ namespace campvis {
/// Main window hosting GUI stuff /// Main window hosting GUI stuff
MainWindow* _mainWindow; MainWindow* _mainWindow;
tgt::Texture* _errorTexture;
/// Flag, whether CampVisApplication was correctly initialized /// Flag, whether CampVisApplication was correctly initialized
bool _initialized; bool _initialized;
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "tgt/camera.h" #include "tgt/camera.h"
#include "tgt/quadric.h" #include "tgt/quadric.h"
#include "tgt/shadermanager.h" #include "tgt/shadermanager.h"
#include "tgt/texture.h"
#include "tgt/textureunit.h" #include "tgt/textureunit.h"
#include "tgt/qt/qtthreadedcanvas.h" #include "tgt/qt/qtthreadedcanvas.h"
...@@ -45,8 +46,9 @@ namespace campvis { ...@@ -45,8 +46,9 @@ namespace campvis {
CampVisPainter::CampVisPainter(tgt::GLCanvas* canvas, AbstractPipeline* pipeline) CampVisPainter::CampVisPainter(tgt::GLCanvas* canvas, AbstractPipeline* pipeline)
: tgt::Painter(canvas) : tgt::Painter(canvas)
, _pipeline(0) , _pipeline(nullptr)
, _copyShader(0) , _copyShader(nullptr)
, _errorTexture(nullptr)
{ {
tgtAssert(getCanvas() != 0, "The given canvas must not be 0!"); tgtAssert(getCanvas() != 0, "The given canvas must not be 0!");
_dirty = true; _dirty = true;
...@@ -68,13 +70,14 @@ namespace campvis { ...@@ -68,13 +70,14 @@ namespace campvis {
ScopedTypedData<RenderData> rd(_pipeline->getDataContainer(), _pipeline->getRenderTargetID()); ScopedTypedData<RenderData> rd(_pipeline->getDataContainer(), _pipeline->getRenderTargetID());
ImageRepresentationGL::ScopedRepresentation repGL(_pipeline->getDataContainer(), _pipeline->getRenderTargetID()); ImageRepresentationGL::ScopedRepresentation repGL(_pipeline->getDataContainer(), _pipeline->getRenderTargetID());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (rd != 0 || (repGL != 0 && repGL->getDimensionality() == 2)) {
// activate shader // activate the shader
_copyShader->activate(); _copyShader->activate();
_copyShader->setIgnoreUniformLocationError(true); tgt::Shader::IgnoreUniformLocationErrorGuard guard(_copyShader);
_copyShader->setUniform("_viewportSize", size);
_copyShader->setUniform("_viewportSizeRCP", 1.f / tgt::vec2(size)); // render whatever there is to render
_copyShader->setIgnoreUniformLocationError(false); if (rd != 0 || (repGL != 0 && repGL->getDimensionality() == 2)) {
_copyShader->setUniform("_viewMatrix", tgt::mat4::identity);
// bind input textures // bind input textures
tgt::TextureUnit colorUnit; tgt::TextureUnit colorUnit;
...@@ -82,41 +85,30 @@ namespace campvis { ...@@ -82,41 +85,30 @@ namespace campvis {
rd->bindColorTexture(_copyShader, colorUnit); rd->bindColorTexture(_copyShader, colorUnit);
else if (repGL) else if (repGL)
repGL->bind(_copyShader, colorUnit); repGL->bind(_copyShader, colorUnit);
LGL_ERROR;
// execute the shader // execute the shader
_copyShader->setAttributeLocation(0, "in_Position");
_copyShader->setAttributeLocation(1, "in_TexCoords");
QuadRdr.renderQuad(); QuadRdr.renderQuad();
_copyShader->deactivate();
LGL_ERROR;
} }
else { // if there is nothing to render, render the error texture
// TODO: render some nifty error texture else if (_errorTexture != nullptr) {
// so long, we do some dummy rendering float ratioRatio = static_cast<float>(size.y) / size.x;
tgt::Camera c(tgt::vec3(0.f,0.f,2.f)); tgt::mat4 viewMatrix = (ratioRatio > 1) ? tgt::mat4::createScale(tgt::vec3(1.f, 1.f / ratioRatio, 1.f)) : tgt::mat4::createScale(tgt::vec3(ratioRatio, 1.f, 1.f));
c.look(); _copyShader->setUniform("_viewMatrix", viewMatrix);
glColor3f(1.f, 0.f, 0.f);
tgt::Sphere sphere(.5f, 64, 32);
sphere.render();
/*
// render error texture
if (!errorTex_) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
return;
}
glClear(GL_DEPTH_BUFFER_BIT);
glActiveTexture(GL_TEXTURE0);
errorTex_->bind();
errorTex_->enable();
glColor3f(1.f, 1.f, 1.f); // bind input textures
renderQuad(); tgt::TextureUnit colorUnit;
colorUnit.activate();
_errorTexture->bind();
_copyShader->setUniform("_colorTexture", colorUnit.getUnitNumber());
errorTex_->disable();*/ // execute the shader
QuadRdr.renderQuad();
} }
else {
LERROR("Nothing to render but could not load error texture either.");
}
_copyShader->deactivate();
LGL_ERROR; LGL_ERROR;
getCanvas()->swap(); getCanvas()->swap();
...@@ -130,6 +122,8 @@ namespace campvis { ...@@ -130,6 +122,8 @@ namespace campvis {
try { try {
// TODO: Remove hardcoded paths, and use ShdrMgr.addPath() at some central location // TODO: Remove hardcoded paths, and use ShdrMgr.addPath() at some central location
_copyShader = ShdrMgr.load("core/glsl/passthrough.vert", "core/glsl/copyimage.frag", ""); _copyShader = ShdrMgr.load("core/glsl/passthrough.vert", "core/glsl/copyimage.frag", "");
_copyShader->setAttributeLocation(0, "in_Position");
_copyShader->setAttributeLocation(1, "in_TexCoords");
} }
catch (tgt::Exception& e) { catch (tgt::Exception& e) {
LERRORC("main.cpp", "Encountered tgt::Exception: " << e.what()); LERRORC("main.cpp", "Encountered tgt::Exception: " << e.what());
...@@ -174,4 +168,9 @@ namespace campvis { ...@@ -174,4 +168,9 @@ namespace campvis {
tgtAssert(dynamic_cast<tgt::QtThreadedCanvas*>(canvas) != 0, "Canvas must be of type QtThreadedCanvas!"); tgtAssert(dynamic_cast<tgt::QtThreadedCanvas*>(canvas) != 0, "Canvas must be of type QtThreadedCanvas!");
Painter::setCanvas(canvas); Painter::setCanvas(canvas);
} }
void CampVisPainter::setErrorTexture(tgt::Texture* texture) {
_errorTexture = texture;
}
} }
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
namespace tgt { namespace tgt {
class Shader; class Shader;
class QtThreadedCanvas; class QtThreadedCanvas;
class Texture;
} }
namespace campvis { namespace campvis {
...@@ -87,6 +88,8 @@ namespace campvis { ...@@ -87,6 +88,8 @@ namespace campvis {
*/ */
void setPipeline(AbstractPipeline* pipeline); void setPipeline(AbstractPipeline* pipeline);
void setErrorTexture(tgt::Texture* texture);
/** /**
* Slot being notified when the pipeline's render target changed. * Slot being notified when the pipeline's render target changed.
*/ */
...@@ -104,6 +107,8 @@ namespace campvis { ...@@ -104,6 +107,8 @@ namespace campvis {
tgt::Shader* _copyShader; ///< Shader for copying the render target to the framebuffer. tgt::Shader* _copyShader; ///< Shader for copying the render target to the framebuffer.
tbb::atomic<bool> _dirty; ///< Flag whether render result is dirty and needs to be rerendered. tbb::atomic<bool> _dirty; ///< Flag whether render result is dirty and needs to be rerendered.
std::condition_variable _renderCondition; ///< conditional wait condition for rendering std::condition_variable _renderCondition; ///< conditional wait condition for rendering
tgt::Texture* _errorTexture;
}; };
} }
......
...@@ -22,12 +22,11 @@ ...@@ -22,12 +22,11 @@
// //
// ================================================================================================ // ================================================================================================
in vec3 ex_TexCoord;
out vec4 out_Color; out vec4 out_Color;
#include "tools/texture2d.frag" #include "tools/texture2d.frag"
uniform vec2 _viewportSize;
uniform vec2 _viewportSizeRCP;
uniform sampler2D _colorTexture; uniform sampler2D _colorTexture;
uniform TextureParameters2D _texParams; uniform TextureParameters2D _texParams;
...@@ -36,10 +35,9 @@ uniform sampler2D _depthTexture; ...@@ -36,10 +35,9 @@ uniform sampler2D _depthTexture;
#endif #endif
void main() { void main() {
vec2 fragCoord = gl_FragCoord.xy * _viewportSizeRCP; out_Color = texture(_colorTexture, ex_TexCoord.xy);
out_Color = texture(_colorTexture, fragCoord);
#ifndef NO_DEPTH #ifndef NO_DEPTH
gl_FragDepth = texture(_depthTexture, fragCoord).r; gl_FragDepth = texture(_depthTexture, ex_TexCoord.xy).r;
#endif #endif
} }
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