Commit 6b08081c authored by Michele Bosi's avatar Michele Bosi

Vivid: simplified background image management

parent a4cbc993
......@@ -516,7 +516,8 @@ public:
case 'b':
mVividRendering->setBackgroundImageEnabled( ! mVividRendering->backgroundImageEnabled() );
if ( mVividRendering->backgroundImageEnabled() ) {
mVividRendering->setBackgroundImage( mBackgroundImage.get() );
// mVividRendering->setBackgroundImage( mBackgroundImage.get() );
mVividRendering->backgroundTexSampler()->texture()->createTexture2D( mBackgroundImage.get(), TF_RGBA, false, false );
}
break;
case 'v':
......
......@@ -1097,8 +1097,8 @@ void VividRenderer::renderBackgroundImage( Camera* camera ) {
float ipa = camera_cal->pixelAspectRatio(); // image pixel aspect ratio
float sw = (float) framebuffer()->width();
float sh = (float) framebuffer()->height();
float iw = (float) mVividRendering->backgroundImage()->width();
float ih = (float) mVividRendering->backgroundImage()->height() * ipa;
float iw = (float) mVividRendering->backgroundTexSampler()->texture()->width();
float ih = (float) mVividRendering->backgroundTexSampler()->texture()->height() * ipa;
// allow aspect ratio
......
......@@ -63,8 +63,7 @@ VividRendering::VividRendering() {
// We could use mipmaps generation because the time to generate the mipmap in the GPU seems negligible
// compared to the time necessary to upload the image.
// We don't enable mipmaps mainly for simplicity and future compatibility to in-GPU updated textures.
mBackgroundImage = new Image( 32, 32, 0, 1, vl::IF_RGBA, vl::IT_BYTE );
ref< Texture > texture = new Texture( mBackgroundImage.get(), TF_RGBA, false );
ref< Texture > texture = new Texture( 32, 32, TF_RGBA, false );
texture->getTexParameter()->setGenerateMipmap( false );
texture->getTexParameter()->setMagFilter( vl::TPF_LINEAR );
texture->getTexParameter()->setMinFilter( vl::TPF_LINEAR );
......@@ -92,20 +91,6 @@ void VividRendering::setupVolume( Image* img, const AABB& bounds, Image* transfe
// Initialize the volume
mVividVolume->setupVolume( img, bounds, transfer_func );
}
//------------------------------------------------------------------------------
void VividRendering::setBackgroundImage(Image* image) {
mBackgroundImage = image;
// create a new texture using the background image
ref< Texture > texture = new Texture( mBackgroundImage.get(), TF_RGBA, false );
// old texture gets automatically deleted
mBackgroundTexSampler->setTexture( texture.get() );
}
//------------------------------------------------------------------------------
void VividRendering::updateBackgroundTexture() {
VL_CHECK( mBackgroundImage->width() == mBackgroundTexSampler->texture()->width() );
VL_CHECK( mBackgroundImage->height() == mBackgroundTexSampler->texture()->height() );
mBackgroundTexSampler->texture()->setMipLevel( TextureUnit0, mBackgroundImage.get(), false );
}
//-----------------------------------------------------------------------------
ref<Effect> VividRendering::makeVividEffect(Effect* effect) {
......
......@@ -129,17 +129,9 @@ namespace vl
void setBackgroundImageEnabled( bool enabled ){ mBackgroundImageEnabled = enabled; }
bool backgroundImageEnabled() const { return mBackgroundImageEnabled; }
/** Use this function if the background picture changes size or format. */
void setBackgroundImage( Image* image );
Image* backgroundImage() { return mBackgroundImage.get(); }
const Image* backgroundImage() const { return mBackgroundImage.get(); }
TextureSampler* backgroundTexSampler() { return mBackgroundTexSampler.get(); }
const TextureSampler* backgroundTexSampler() const { return mBackgroundTexSampler.get(); }
/** Updates the background texture with the contents of the background image. */
void updateBackgroundTexture();
// Volumes
/** Initializes all the volume data, uniforms and textures using VividVolume::setupVolume() and adds the volume actor to the scene.
......@@ -184,7 +176,6 @@ namespace vl
bool mBackgroundImageEnabled;
ref<TextureSampler> mBackgroundTexSampler;
ref<Image> mBackgroundImage;
// Volume
......
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