In January 2021 we will introduce a 10 GB quota for project repositories. Higher limits for individual projects will be available on request. Please see https://doku.lrz.de/display/PUBLIC/GitLab for more information.

Commit bab66780 authored by schultezub's avatar schultezub

long commit of several refactorings - sorry for not splitting this up:

 * Fixed Issue #38: Made common GLSL header conform to the standards (no samplers in structs)
 * Fixed failing destruction of OpenGL buffers when destructing GeometryData from threads without OpenGL context
 * Fixed wrong pointers in GLContexts due to using this pointer of incompletely constructed class

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@463 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 3e66024d
......@@ -47,8 +47,8 @@ using namespace campvis;
**/
int main(int argc, char** argv) {
CampVisApplication app(argc, argv);
app.addVisualizationPipeline("Advanced Ultrasound Visualization", new AdvancedUsVis());
//app.addVisualizationPipeline("IXPV", new IxpvDemo());
//app.addVisualizationPipeline("Advanced Ultrasound Visualization", new AdvancedUsVis());
app.addVisualizationPipeline("IXPV", new IxpvDemo());
//app.addVisualizationPipeline("SliceVis", new SliceVis());
//app.addVisualizationPipeline("DVRVis", new DVRVis());
#ifdef HAS_KISSCL
......
......@@ -47,7 +47,7 @@
namespace campvis {
const std::string TumVisPainter::loggerCat_ = "CAMPVis.core.TumVisPainter";
TumVisPainter::TumVisPainter(tgt::QtThreadedCanvas* canvas, VisualizationPipeline* pipeline)
TumVisPainter::TumVisPainter(tgt::GLCanvas* canvas, VisualizationPipeline* pipeline)
: Runnable()
, tgt::Painter(canvas)
, _pipeline(0)
......@@ -107,7 +107,7 @@ namespace campvis {
// bind input textures
tgt::TextureUnit colorUnit, depthUnit;
image->bind(_copyShader, &colorUnit, &depthUnit);
image->bind(_copyShader, colorUnit, depthUnit);
LGL_ERROR;
// execute the shader
......
......@@ -62,7 +62,7 @@ namespace campvis {
* \param canvas Canvas to render on
* \param pipeline Pipeline to render
*/
TumVisPainter(tgt::QtThreadedCanvas* canvas, VisualizationPipeline* pipeline);
TumVisPainter(tgt::GLCanvas* canvas, VisualizationPipeline* pipeline);
/**
* Destructor, stops and waits for the rendering thread if it's still running.
......
......@@ -36,9 +36,18 @@ out vec4 out_Color;
#include "tools/texture3d.frag"
#include "tools/transferfunction.frag"
uniform Texture2D _texture2d;
uniform Texture3D _texture3d;
uniform TransferFunction1D _transferFunction;
// 2D texture
uniform sampler2D _texture2d;
uniform TextureParameters2D _2dTextureParams;
// 3D texture
uniform sampler3D _texture3d;
uniform TextureParameters3D _3dTextureParams;
// Transfer Function
uniform sampler1D _transferFunction;
uniform TFParameters1D _transferFunctionParams;
uniform bool _is3d;
uniform int _sliceNumber;
uniform vec4 _color;
......@@ -51,26 +60,26 @@ void main() {
if (_sliceNumber < 0) {
// perform MIP
out_Color = vec4(0.0);
for (float slice = 0.0; slice < 1.0; slice += _texture3d._sizeRCP.z) {
out_Color = max(out_Color, lookupTF(_transferFunction, getElement3DNormalized(_texture3d, vec3(ex_TexCoord.xy, slice)).a));
for (float slice = 0.0; slice < 1.0; slice += _3dTextureParams._sizeRCP.z) {
out_Color = max(out_Color, lookupTF(_transferFunction, _transferFunctionParams, getElement3DNormalized(_texture3d, _3dTextureParams, vec3(ex_TexCoord.xy, slice)).a));
}
}
else {
// render the corresponding slice
vec3 coord = vec3(ex_TexCoord.xy, (_sliceNumber + 0.5) / (_texture3d._size.z));
out_Color = lookupTF(_transferFunction, getElement3DNormalized(_texture3d, coord).a);
vec3 coord = vec3(ex_TexCoord.xy, (_sliceNumber + 0.5) / (_3dTextureParams._size.z));
out_Color = lookupTF(_transferFunction, _transferFunctionParams, getElement3DNormalized(_texture3d, _3dTextureParams, coord).a);
}
}
else {
vec4 texel = getElement2DNormalized(_texture2d, ex_TexCoord.xy);
if (_texture2d._numChannels == 1) {
out_Color = lookupTF(_transferFunction, texel.a);
vec4 texel = getElement2DNormalized(_texture2d, _2dTextureParams, ex_TexCoord.xy);
if (_2dTextureParams._numChannels == 1) {
out_Color = lookupTF(_transferFunction, _transferFunctionParams, texel.a);
}
else if (_texture2d._numChannels == 3) {
else if (_2dTextureParams._numChannels == 3) {
out_Color = vec4(abs(texel.rgb), 1.0);
}
else if (_texture2d._numChannels == 4) {
out_Color = (abs(texel) - vec4(_transferFunction._intensityDomain.x)) / (_transferFunction._intensityDomain.y - _transferFunction._intensityDomain.x);
else if (_2dTextureParams._numChannels == 4) {
out_Color = (abs(texel) - vec4(_transferFunctionParams._intensityDomain.x)) / (_transferFunctionParams._intensityDomain.y - _transferFunctionParams._intensityDomain.x);
}
else {
out_Color = vec4(0.1, 0.6, 1.0, 0.75);
......
......@@ -134,8 +134,8 @@ namespace campvis {
tgt::TextureUnit tfUnit, unit2d, unit3d;
p_transferFunction.getTF()->bind(_paintShader, tfUnit);
_paintShader->setUniform("_texture2d._texture", unit2d.getUnitNumber());
_paintShader->setUniform("_texture3d._texture", unit3d.getUnitNumber());
_paintShader->setUniform("_texture2d", unit2d.getUnitNumber());
_paintShader->setUniform("_texture3d", unit3d.getUnitNumber());
for (int y = 0; y < _numTiles.y; ++y) {
for (int x = 0; x < _numTiles.x; ++x) {
......@@ -162,9 +162,9 @@ namespace campvis {
unit2d.activate();
texture->bind();
_paintShader->setUniform("_is3d", false);
_paintShader->setUniform("_texture2d._size", tgt::vec2(texture->getDimensions().xy()));
_paintShader->setUniform("_texture2d._sizeRCP", tgt::vec2(1.f) / tgt::vec2(texture->getDimensions().xy()));
_paintShader->setUniform("_texture2d._numChannels", static_cast<int>(texture->getNumChannels()));
_paintShader->setUniform("_2dTextureParams._size", tgt::vec2(texture->getDimensions().xy()));
_paintShader->setUniform("_2dTextureParams._sizeRCP", tgt::vec2(1.f) / tgt::vec2(texture->getDimensions().xy()));
_paintShader->setUniform("_2dTextureParams._numChannels", static_cast<int>(texture->getNumChannels()));
}
else {
// clamp current slice to texture size, since this can't be done in event handler:
......@@ -174,9 +174,9 @@ namespace campvis {
texture->bind();
_paintShader->setUniform("_is3d", true);
_paintShader->setUniform("_sliceNumber", p_currentSlice.getValue());
_paintShader->setUniform("_texture3d._size", tgt::vec3(texture->getDimensions()));
_paintShader->setUniform("_texture3d._sizeRCP", tgt::vec3(1.f) / tgt::vec3(texture->getDimensions()));
_paintShader->setUniform("_texture2d._numChannels", static_cast<int>(texture->getNumChannels()));
_paintShader->setUniform("_3dTextureParams._size", tgt::vec3(texture->getDimensions()));
_paintShader->setUniform("_3dTextureParams._sizeRCP", tgt::vec3(1.f) / tgt::vec3(texture->getDimensions()));
_paintShader->setUniform("_3dTextureParams._numChannels", static_cast<int>(texture->getNumChannels()));
}
_paintShader->setIgnoreUniformLocationError(false);
......
......@@ -85,7 +85,7 @@ namespace campvis {
_texture = 0;
}
void AbstractTransferFunction::bind(tgt::Shader* shader, const tgt::TextureUnit& texUnit, const std::string& transFuncUniform /*= "_transferFunction"*/) {
void AbstractTransferFunction::bind(tgt::Shader* shader, const tgt::TextureUnit& texUnit, const std::string& transFuncUniform /*= "_transferFunction"*/, const std::string& transFuncParamsUniform /*= "_transferFunctionParameters"*/) {
tgtAssert(shader != 0, "Shader must not be 0.");
{
......@@ -103,13 +103,13 @@ namespace campvis {
bool tmp = shader->getIgnoreUniformLocationError();
shader->setIgnoreUniformLocationError(true);
shader->setUniform(transFuncUniform + "._texture", texUnit.getUnitNumber());
shader->setUniform(transFuncUniform, texUnit.getUnitNumber());
switch (getDimensionality()) {
case 1:
shader->setUniform(transFuncUniform + "._intensityDomain", tgt::vec2(_intensityDomain));
shader->setUniform(transFuncParamsUniform + "._intensityDomain", tgt::vec2(_intensityDomain));
break;
case 2:
shader->setUniform(transFuncUniform + "._intensityDomainX", tgt::vec2(_intensityDomain));
shader->setUniform(transFuncParamsUniform + "._intensityDomainX", tgt::vec2(_intensityDomain));
break;
default:
tgtAssert(false, "Unsupported TF dimensionality!");
......
......@@ -95,9 +95,10 @@ namespace campvis {
* \note Calling thread must have a valid OpenGL context.
* \param shader Shader used for rendering
* \param texUnit Texture unit to bind texture to
* \param transFuncUniform Uniform name to store the TF struct
* \param transFuncUniform Uniform name to store the TF sampler
* \param transFuncParamsUniform Uniform name to store the TF parameters struct
*/
void bind(tgt::Shader* shader, const tgt::TextureUnit& texUnit, const std::string& transFuncUniform = "_transferFunction");
void bind(tgt::Shader* shader, const tgt::TextureUnit& texUnit, const std::string& transFuncUniform = "_transferFunction", const std::string& transFuncParamsUniform = "_transferFunctionParams");
/**
* Creates the OpenGL texture.
......
......@@ -129,6 +129,8 @@ namespace campvis {
}
void FaceGeometry::createGLBuffers() const {
GeometryData::createGLBuffers();
if (! _buffersInitialized) {
try {
_verticesBuffer = new tgt::BufferObject(tgt::BufferObject::ARRAY_BUFFER, tgt::BufferObject::USAGE_STATIC_DRAW);
......
......@@ -31,6 +31,9 @@
#include "tgt/buffer.h"
#include "tgt/vertexarrayobject.h"
#include "tgt/qt/qtcontextmanager.h"
#include "core/tools/opengljobprocessor.h"
namespace campvis {
GeometryData::GeometryData()
......@@ -40,6 +43,7 @@ namespace campvis {
, _texCoordsBuffer(0)
, _colorsBuffer(0)
, _normalsBuffer(0)
, _context(0)
{
}
......@@ -55,10 +59,10 @@ namespace campvis {
}
GeometryData::~GeometryData() {
delete _verticesBuffer;
delete _texCoordsBuffer;
delete _colorsBuffer;
delete _normalsBuffer;
if (_buffersInitialized) {
std::vector<tgt::BufferObject*> buffers(_buffers, _buffers + NUM_BUFFERS);
GLJobProc.enqueueJob(_context, makeJobOnHeap(&GeometryData::deleteBuffers, buffers), OpenGLJobProcessor::LowPriorityJob);
}
}
GeometryData& GeometryData::operator=(const GeometryData& rhs) {
......@@ -68,22 +72,25 @@ namespace campvis {
AbstractData::operator=(rhs);
// delete old VBOs and null pointers
delete _verticesBuffer;
_verticesBuffer = 0;
if (_buffersInitialized) {
std::vector<tgt::BufferObject*> buffers(_buffers, _buffers + NUM_BUFFERS);
GLJobProc.enqueueJob(_context, makeJobOnHeap(&GeometryData::deleteBuffers, buffers), OpenGLJobProcessor::LowPriorityJob);
}
delete _texCoordsBuffer;
_verticesBuffer = 0;
_texCoordsBuffer = 0;
delete _colorsBuffer;
_colorsBuffer = 0;
delete _normalsBuffer;
_normalsBuffer = 0;
_buffersInitialized = false;
return *this;
}
void GeometryData::deleteBuffers(std::vector<tgt::BufferObject*> buffers) {
for (std::vector<tgt::BufferObject*>::iterator it = buffers.begin(); it != buffers.end(); ++it)
delete *it;
}
size_t GeometryData::getVideoMemoryFootprint() const {
size_t sum = 0;
......@@ -99,6 +106,11 @@ namespace campvis {
return sum;
}
void GeometryData::createGLBuffers() const {
if (! _buffersInitialized)
_context = CtxtMgr.getCurrentContext();
}
const tgt::BufferObject* GeometryData::getVerticesBuffer() const {
return _verticesBuffer;
}
......
......@@ -31,9 +31,11 @@
#define GEOMETRYDATA_H__
#include "core/datastructures/abstractdata.h"
#include <vector>
namespace tgt {
class BufferObject;
class QtCanvas;
}
namespace campvis {
......@@ -55,6 +57,8 @@ namespace campvis {
GeometryData& operator=(const GeometryData& rhs);
static void deleteBuffers(std::vector<tgt::BufferObject*> buffers);
virtual AbstractData* clone() const = 0;
/// \see AbstractData::getVideoMemoryFootprint()
......@@ -69,8 +73,9 @@ namespace campvis {
/**
* Creates the OpenGL VBOs and the VAO for this geometry.
* Must be called from a valid OpenGL context.
* \note When overwriting this method, make sure to call base class method first!
*/
virtual void createGLBuffers() const = 0;
virtual void createGLBuffers() const;
const tgt::BufferObject* getVerticesBuffer() const;
......@@ -83,10 +88,22 @@ namespace campvis {
protected:
// mutable to support const lazy initialization
mutable bool _buffersInitialized;
mutable tgt::BufferObject* _verticesBuffer;
mutable tgt::BufferObject* _texCoordsBuffer;
mutable tgt::BufferObject* _colorsBuffer;
mutable tgt::BufferObject* _normalsBuffer;
enum { NUM_BUFFERS = 4 };
union {
struct {
mutable tgt::BufferObject* _verticesBuffer;
mutable tgt::BufferObject* _texCoordsBuffer;
mutable tgt::BufferObject* _colorsBuffer;
mutable tgt::BufferObject* _normalsBuffer;
};
mutable tgt::BufferObject* _buffers[NUM_BUFFERS];
};
private:
mutable tgt::QtCanvas* _context; ///< OpenGL context the buffers were created in (so that they can be deleted correctly)
};
}
......
......@@ -184,7 +184,7 @@ namespace campvis {
_texture->bind();
}
void ImageRepresentationGL::bind(tgt::Shader* shader, const tgt::TextureUnit& texUnit, const std::string& texUniform /*= "_texture"*/) const {
void ImageRepresentationGL::bind(tgt::Shader* shader, const tgt::TextureUnit& texUnit, const std::string& texUniform /*= "_texture"*/, const std::string& texParamsUniform) const {
bind(texUnit);
bool tmp = shader->getIgnoreUniformLocationError();
shader->setIgnoreUniformLocationError(true);
......@@ -195,21 +195,21 @@ namespace campvis {
break;
case 2:
shader->setUniform(texUniform + "._texture", texUnit.getUnitNumber());
shader->setUniform(texUniform + "._size", tgt::vec2(getSize().xy()));
shader->setUniform(texUniform + "._sizeRCP", tgt::vec2(1.f) / tgt::vec2(getSize().xy()));
shader->setUniform(texUniform + "._numChannels", static_cast<int>(_parent->getNumChannels()));
shader->setUniform(texUniform, texUnit.getUnitNumber());
shader->setUniform(texParamsUniform + "._size", tgt::vec2(getSize().xy()));
shader->setUniform(texParamsUniform + "._sizeRCP", tgt::vec2(1.f) / tgt::vec2(getSize().xy()));
shader->setUniform(texParamsUniform + "._numChannels", static_cast<int>(_parent->getNumChannels()));
break;
case 3:
shader->setUniform(texUniform + "._texture", texUnit.getUnitNumber());
shader->setUniform(texUniform + "._size", tgt::vec3(getSize()));
shader->setUniform(texUniform + "._sizeRCP", tgt::vec3(1.f) / tgt::vec3(getSize()));
shader->setUniform(texUniform + "._numChannels", static_cast<int>(_parent->getNumChannels()));
shader->setUniform(texUniform + "._voxelSize", _parent->getMappingInformation().getVoxelSize());
shader->setUniform(texUniform + "._voxelSizeRCP", tgt::vec3(1.f) / _parent->getMappingInformation().getVoxelSize());
shader->setUniform(texUniform + "._textureToWorldMatrix", _parent->getMappingInformation().getTextureToWorldMatrix());
shader->setUniform(texUniform + "._realWorldMapping", tgt::vec2(_parent->getMappingInformation().getRealWorldMapping()._shift, _parent->getMappingInformation().getRealWorldMapping()._scale));
shader->setUniform(texUniform, texUnit.getUnitNumber());
shader->setUniform(texParamsUniform + "._size", tgt::vec3(getSize()));
shader->setUniform(texParamsUniform + "._sizeRCP", tgt::vec3(1.f) / tgt::vec3(getSize()));
shader->setUniform(texParamsUniform + "._numChannels", static_cast<int>(_parent->getNumChannels()));
shader->setUniform(texParamsUniform + "._voxelSize", _parent->getMappingInformation().getVoxelSize());
shader->setUniform(texParamsUniform + "._voxelSizeRCP", tgt::vec3(1.f) / _parent->getMappingInformation().getVoxelSize());
shader->setUniform(texParamsUniform + "._textureToWorldMatrix", _parent->getMappingInformation().getTextureToWorldMatrix());
shader->setUniform(texParamsUniform + "._realWorldMapping", tgt::vec2(_parent->getMappingInformation().getRealWorldMapping()._shift, _parent->getMappingInformation().getRealWorldMapping()._scale));
break;
default:
......
......@@ -105,27 +105,18 @@ namespace campvis {
virtual ImageRepresentationGL* getSubImage(ImageData* parent, const tgt::svec3& llf, const tgt::svec3& urb) const;
/**
* Binds the texture without activating a texture unit.
*/
void bind() const;
/**
* Activates the texture unit \a texUnit and binds the texture.
* \param texUnit Texture unit to activate
*/
void bind(const tgt::TextureUnit& texUnit) const;
/**
* Binds the image to the given shader using \a texUnit as texture unit and \a texUniform as shader uniform.
* \param shader Shader to bind image and set uniforms to.
* \param texUnit TextureUnit to bind image to.
* \param texUniform Uniform name for the sampler.
* \param shader Shader to bind image and set uniforms to.
* \param texUnit TextureUnit to bind image to.
* \param texUniform Uniform name for the sampler.
* \param texParamsUniform Name for texture parameters struct uniform.
*/
void bind(
tgt::Shader* shader,
const tgt::TextureUnit& texUnit,
const std::string& texUniform = "_texture") const;
const std::string& texUniform = "_texture",
const std::string& texParamsUniform = "_textureParams") const;
/**
* Gets the OpenGL texture.
......@@ -171,6 +162,17 @@ namespace campvis {
template<typename BASETYPE, size_t NUMCHANNELS>
ImageRepresentationGL(ImageData* parent, const GenericImageRepresentationLocal<BASETYPE, NUMCHANNELS>* data);
/**
* Binds the texture without activating a texture unit.
*/
void bind() const;
/**
* Activates the texture unit \a texUnit and binds the texture.
* \param texUnit Texture unit to activate
*/
void bind(const tgt::TextureUnit& texUnit) const;
/**
* Creates the OpenGL texture from the given pointer \a wtp.
* \param wtp WeaklyTypedPointer with source image data
......
......@@ -135,42 +135,46 @@ namespace campvis {
_fbo->deactivate();
}
void ImageRepresentationRenderTarget::bindColorTexture(size_t index /*= 0*/) const {
void ImageRepresentationRenderTarget::bindColorTexture(tgt::Shader* shader, const tgt::TextureUnit& colorTexUnit, const std::string& colorTexUniform /*= "_colorTexture"*/, const std::string& texParamsUniform /*= "_texParams"*/, size_t index /*= 0*/) const {
tgtAssert(index < _colorTextures.size(), "Color texture index out of bounds!");
_colorTextures[index]->bind();
}
bool tmp = shader->getIgnoreUniformLocationError();
shader->setIgnoreUniformLocationError(true);
void ImageRepresentationRenderTarget::bindColorTexture(const tgt::TextureUnit& texUnit, size_t index /*= 0*/) const {
tgtAssert(index < _colorTextures.size(), "Color texture index out of bounds!");
texUnit.activate();
_colorTextures[index]->bind();
}
bindColorTexture(colorTexUnit, index);
shader->setUniform(colorTexUniform, colorTexUnit.getUnitNumber());
shader->setUniform(texParamsUniform + "._size", tgt::vec2(getSize().xy()));
shader->setUniform(texParamsUniform + "._sizeRCP", tgt::vec2(1.f) / tgt::vec2(getSize().xy()));
shader->setUniform(texParamsUniform + "._numChannels", static_cast<int>(_parent->getNumChannels()));
void ImageRepresentationRenderTarget::bindDepthTexture() const {
_depthTexture->bind();
shader->setIgnoreUniformLocationError(tmp);
}
void ImageRepresentationRenderTarget::bindDepthTexture(const tgt::TextureUnit& texUnit) const {
texUnit.activate();
_depthTexture->bind();
void ImageRepresentationRenderTarget::bindDepthTexture(tgt::Shader* shader, const tgt::TextureUnit& depthTexUnit, const std::string& depthTexUniform /*= "_depthTexture"*/, const std::string& texParamsUniform /*= "_texParams"*/) const {
bool tmp = shader->getIgnoreUniformLocationError();
shader->setIgnoreUniformLocationError(true);
bindDepthTexture(depthTexUnit);
shader->setUniform(depthTexUniform, depthTexUnit.getUnitNumber());
shader->setUniform(texParamsUniform + "._size", tgt::vec2(getSize().xy()));
shader->setUniform(texParamsUniform + "._sizeRCP", tgt::vec2(1.f) / tgt::vec2(getSize().xy()));
shader->setUniform(texParamsUniform + "._numChannels", static_cast<int>(_parent->getNumChannels()));
shader->setIgnoreUniformLocationError(tmp);
}
void ImageRepresentationRenderTarget::bind(tgt::Shader* shader, const tgt::TextureUnit* colorTexUnit, const tgt::TextureUnit* depthTexUnit, const std::string& colorTexUniform /*= "_colorTextures"*/, const std::string& depthTexUniform /*= "_depthTexture"*/, size_t index /*= 0*/) const {
void ImageRepresentationRenderTarget::bind(tgt::Shader* shader, const tgt::TextureUnit& colorTexUnit, const tgt::TextureUnit& depthTexUnit, const std::string& colorTexUniform /*= "_colorTexture"*/, const std::string& depthTexUniform /*= "_depthTexture"*/, const std::string& texParamsUniform /*= "_texParams"*/, size_t index /*= 0*/) const {
tgtAssert(index < _colorTextures.size(), "Color texture index out of bounds!");
bool tmp = shader->getIgnoreUniformLocationError();
shader->setIgnoreUniformLocationError(true);
if (colorTexUnit != 0) {
bindColorTexture(*colorTexUnit, index);
shader->setUniform(colorTexUniform + "._texture", colorTexUnit->getUnitNumber());
shader->setUniform(colorTexUniform + "._size", tgt::vec2(getSize().xy()));
shader->setUniform(colorTexUniform + "._sizeRCP", tgt::vec2(1.f) / tgt::vec2(getSize().xy()));
}
if (depthTexUnit != 0) {
bindDepthTexture(*depthTexUnit);
shader->setUniform(depthTexUniform + "._texture", depthTexUnit->getUnitNumber());
shader->setUniform(depthTexUniform + "._size", tgt::vec2(getSize().xy()));
shader->setUniform(depthTexUniform + "._sizeRCP", tgt::vec2(1.f) / tgt::vec2(getSize().xy()));
}
bindColorTexture(colorTexUnit, index);
bindDepthTexture(depthTexUnit);
shader->setUniform(colorTexUniform, colorTexUnit.getUnitNumber());
shader->setUniform(depthTexUniform, depthTexUnit.getUnitNumber());
shader->setUniform(texParamsUniform + "._size", tgt::vec2(getSize().xy()));
shader->setUniform(texParamsUniform + "._sizeRCP", tgt::vec2(1.f) / tgt::vec2(getSize().xy()));
shader->setUniform(texParamsUniform + "._numChannels", static_cast<int>(_parent->getNumChannels()));
shader->setIgnoreUniformLocationError(tmp);
}
......@@ -329,4 +333,16 @@ namespace campvis {
return 0;
}
void ImageRepresentationRenderTarget::bindColorTexture(const tgt::TextureUnit& texUnit, size_t index /*= 0*/) const {
tgtAssert(index < _colorTextures.size(), "Color texture index out of bounds!");
texUnit.activate();
_colorTextures[index]->bind();
}
void ImageRepresentationRenderTarget::bindDepthTexture(const tgt::TextureUnit& texUnit) const {
texUnit.activate();
_depthTexture->bind();
}
}
\ No newline at end of file
......@@ -118,6 +118,12 @@ namespace campvis {
*/
void createAndAttachTexture(GLint internalFormat);
/**
* Gets the number of color textures/attachments of this render target.
* \return _colorTextures.size()
*/
size_t getNumColorTextures() const;
/**
* Gets the color texture of this render target
* \param index Index of the color texture attachment to return.
......@@ -142,50 +148,55 @@ namespace campvis {
void deactivate();
/**
* Binds the color texture without activating a texture unit.
*/
void bindColorTexture(size_t index = 0) const;
/**
* Binds the depth texture without activating a texture unit.
*/
void bindDepthTexture() const;
/**
* Activates the texture unit \a texUnit and binds the color texture.
* \param texUnit Texture unit to activate
*/
void bindColorTexture(const tgt::TextureUnit& texUnit, size_t index = 0) const;
/**
* Activates the texture unit \a texUnit and binds the depth texture.
* \param texUnit Texture unit to activate
* Binds the color texture with index \a index of this render target
* and sets the corresponding shader uniforms.
*
* \param shader Shader to set the uniforms to.
* \param colorTexUnit Color texture unit.
* \param colorTexUniform Name for color texture sampler.
* \param texParamsUniform Name for texture parameters struct uniform.
* \param index Index of the color texture to bind.
*/
void bindDepthTexture(const tgt::TextureUnit& texUnit) const;
void bindColorTexture(
tgt::Shader* shader,
const tgt::TextureUnit& colorTexUnit,
const std::string& colorTexUniform = "_colorTexture",
const std::string& texParamsUniform = "_texParams",
size_t index = 0) const;
/**
* Gets the number of color textures/attachments of this render target.
* \return _colorTextures.size()
* Binds the depth texture of this render target and sets the corresponding shader uniforms.
*
* \param shader Shader to set the uniforms to.
* \param depthTexUnit Depth texture unit.
* \param depthTexUniform Name for depth texture sampler.
* \param texParamsUniform Name for texture parameters struct uniform.
*/
size_t getNumColorTextures() const;
void bindDepthTexture(
tgt::Shader* shader,
const tgt::TextureUnit& depthTexUnit,
const std::string& depthTexUniform = "_depthTexture",
const std::string& texParamsUniform = "_texParams") const;
/**
* Binds the textures of this render target and sets the according shader uniforms.
* Of \a colorTexUnit or \a depthTexUnit is 0, the corresponding texture will not be bound
* and the corresponding uniforms will not be set.
* Binds the color texture with index \a index and the depth texture of this render target
* and sets the corresponding shader uniforms.
*
* \param shader Shader to set the uniforms to.