Notice: If you are member of any public project or group, please make sure that your GitLab username is not the same as the LRZ identifier/Kennung (see https://gitlab.lrz.de/profile/account). Please change your username if necessary. For more information see the section "Public projects / Öffentliche Projekte" at https://doku.lrz.de/display/PUBLIC/GitLab . Thank you!

Commit 079e0bb3 authored by Jakob Weiss's avatar Jakob Weiss

Usage example for reusable data

Very crude demonstration, mainly to prove that everything compiles and (probably?) works as intended. No writable image representations, hence the weird loopholes to remove the representations from the representations list. No deadlocks! yaay!
parent ceaff5fb
......@@ -170,6 +170,12 @@ namespace campvis {
template<typename T>
const T* getRepresentation(bool performConversion = true) const;
/**
* Removes the representation from the list and turns ownership over to the caller. Use only if you know what you are doing..
*/
template<typename T>
T* removeRepresentationUnsafe();
/**
* Returns the number of currently stored representations.
* \return _representations.size();
......@@ -245,6 +251,31 @@ namespace campvis {
return 0;
}
template<typename T>
T* campvis::ImageData::removeRepresentationUnsafe() {
std::vector<const AbstractImageRepresentation*> reps;
T* found = nullptr;
for (auto it = _representations.begin(); it != _representations.end(); ++it) {
if (const T* tester = dynamic_cast<const T*>(*it)) {
found = const_cast<T*>(tester);
}
else {
reps.push_back(*it);
}
}
// we are calling this on a non-const ImageData object so we assume that it is write-locked by a ScopedTypedData
// instance and the following should be threadsafe
if (found) {
_representations.clear();
for (auto it = reps.begin(); it != reps.end(); ++it) {
_representations.push_back(*it);
}
}
return found;
}
template<typename T>
const T* campvis::ImageData::tryPerformConversion() const {
for (auto it = _representations.begin(); it != _representations.end(); ++it) {
......
......@@ -26,6 +26,8 @@
#include "cgt/textureunit.h"
#include "core/datastructures/imagedata.h"
#include "core/datastructures/renderdata.h"
#include "core/datastructures/imagerepresentationgl.h"
namespace campvis {
......@@ -67,7 +69,7 @@ namespace campvis {
AbstractProcessor::deinit();
}
void VisualizationProcessor::createAndAttachTexture(GLint internalFormat, GLenum attachment) {
void VisualizationProcessor::createAndAttachTexture(GLint internalFormat, GLenum attachment, ScopedTypedData<RenderData, true>* renderData /*= nullptr*/) {
cgtAssert(_fbo->isActive(), "Trying to attach a texture while FBO is not bound!");
// acqiure a new TextureUnit, so that we don't mess with other currently bound textures during texture upload...
......@@ -77,15 +79,41 @@ namespace campvis {
// Set OpenGL pixel alignment to 1 to avoid problems with NPOT textures
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
// create texture
cgt::Texture* tex = new cgt::Texture(GL_TEXTURE_2D, getRenderTargetSize(), internalFormat, cgt::Texture::LINEAR);
cgt::Texture* tex = nullptr;
if (renderData) {
ImageRepresentationGL* glRep;
if (attachment == GL_DEPTH_ATTACHMENT)
if(auto id = (*renderData)->getDepthTexture())
glRep = const_cast<ImageRepresentationGL*>(id->getRepresentation<ImageRepresentationGL>(false));
else
if(auto id =(*renderData)->getColorTexture(_fbo->getNumColorAttachments()))
glRep = const_cast<ImageRepresentationGL*>(id->getRepresentation<ImageRepresentationGL>(false));
if (glRep) {
tex = const_cast<cgt::Texture*>(glRep->getTexture());
if (tex->getType() != GL_TEXTURE_2D || tex->getDimensions() != getRenderTargetSize()
|| tex->getInternalFormat() != internalFormat)
tex = nullptr;
else {
// somehow detach the cgt::Texture from the ImageRepresentationGL
// yes this is horrible code
const_cast<ImageData*>(glRep->getParent())->removeRepresentationUnsafe<ImageRepresentationGL>();
}
}
}
if (!tex) {
// create texture
tex = new cgt::Texture(GL_TEXTURE_2D, getRenderTargetSize(), internalFormat, cgt::Texture::LINEAR);
}
tex->setWrapping(cgt::Texture::CLAMP_TO_EDGE);
// attach texture to FBO
_fbo->attachTexture(tex, attachment);
}
void VisualizationProcessor::createAndAttachTexture(GLint internalFormat) {
void VisualizationProcessor::createAndAttachTexture(GLint internalFormat, ScopedTypedData<RenderData, true>* renderData /*= nullptr*/) {
GLenum attachment = 0;
switch(internalFormat) {
case GL_R32F:
......@@ -127,12 +155,12 @@ namespace campvis {
return cgt::ivec3(getEffectiveViewportSize(), 1);
}
void VisualizationProcessor::createAndAttachColorTexture() {
createAndAttachTexture(GL_RGBA8);
void VisualizationProcessor::createAndAttachColorTexture(ScopedTypedData<RenderData, true>* renderData /*= nullptr*/) {
createAndAttachTexture(GL_RGBA8, renderData);
}
void VisualizationProcessor::createAndAttachDepthTexture() {
createAndAttachTexture(GL_DEPTH_COMPONENT24);
void VisualizationProcessor::createAndAttachDepthTexture(ScopedTypedData<RenderData, true>* renderData /*= nullptr*/) {
createAndAttachTexture(GL_DEPTH_COMPONENT24, renderData);
}
void VisualizationProcessor::setViewportSizeProperty(IVec2Property* viewportSizeProp) {
......
......@@ -34,6 +34,7 @@
namespace campvis {
class ImageData;
class RenderData;
/**
* Specialization of AbstractProcessor for visualization purposes.
......@@ -138,7 +139,7 @@ namespace campvis {
* \param internalFormat Internal OpenGL texture format
* \param attachment Target attachment for texture
*/
void createAndAttachTexture(GLint internalFormat, GLenum attachment);
void createAndAttachTexture(GLint internalFormat, GLenum attachment, ScopedTypedData<RenderData, true>* renderData = nullptr);
/**
* Creates a texture with the given format and attaches it to the FBO using the default attachments.
......@@ -146,19 +147,19 @@ namespace campvis {
* GL_COLOR_ATTACHMENT_0 + <number of color textures attached>.
* \param internalFormat Internal OpenGL texture format
*/
void createAndAttachTexture(GLint internalFormat);
void createAndAttachTexture(GLint internalFormat, ScopedTypedData<RenderData, true>* renderData = nullptr);
/**
* Creates a color texture with format GL_RGBA8 and attaches it to the FBO using the
* default attachment.
*/
void createAndAttachColorTexture();
void createAndAttachColorTexture(ScopedTypedData<RenderData, true>* renderData = nullptr);
/**
* Creates a depth texture with format GL_DEPTH_COMPONENT24 and attaches it to the FBO
* using the default attachment.
*/
void createAndAttachDepthTexture();
void createAndAttachDepthTexture(ScopedTypedData<RenderData, true>* renderData = nullptr);
/**
* Returns the current viewport size as ivec3.
......
......@@ -66,13 +66,15 @@ namespace campvis {
void SimpleRaycaster::processImpl(DataContainer& data, ImageRepresentationGL::ScopedRepresentation& image) {
ScopedTypedData<LightSourceData> light(data, p_lightId.getValue());
ScopedTypedData<RenderData, true> outputImage(data, p_targetImageID.getValue());
if (p_enableShading.getValue() == false || light != nullptr) {
FramebufferActivationGuard fag(this);
createAndAttachTexture(GL_RGBA8);
createAndAttachTexture(GL_RGBA32F);
createAndAttachTexture(GL_RGBA32F);
createAndAttachDepthTexture();
createAndAttachTexture(GL_RGBA8, &outputImage);
createAndAttachTexture(GL_RGBA32F, &outputImage);
createAndAttachTexture(GL_RGBA32F, &outputImage);
createAndAttachDepthTexture(&outputImage);
static const GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 , GL_COLOR_ATTACHMENT2 };
glDrawBuffers(3, buffers);
......@@ -94,8 +96,6 @@ namespace campvis {
LGL_ERROR;
data.addData(p_targetImageID.getValue(), new RenderData(_fbo));
}
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