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

Vivid: allow multiple stencil geometry

parent 713a8e8c
......@@ -389,9 +389,16 @@ public:
icosphere->computeNormals();
// stencil = AdjacencyExtractor::extract( stencil.get() );
ref< Effect > fx = VividRendering::makeVividEffect();
Actor* stencil_act = mVividRendering->sceneManager()->tree()->addActor( icosphere.get(), fx.get(), NULL );
stencil_act->setEnableMask( 0 );
mVividRendering->setStencilGeommetry( icosphere.get() );
ref< Transform > tr1 = new Transform;
ref< Transform > tr2 = new Transform;
Actor* stencil_act1 = mVividRendering->sceneManager()->tree()->addActor( icosphere.get(), fx.get(), tr1.get() );
stencil_act1->setEnableMask( 0 );
Actor* stencil_act2 = mVividRendering->sceneManager()->tree()->addActor( icosphere.get(), fx.get(), tr2.get() );
stencil_act2->setEnableMask( 0 );
mVividRendering->stencilActors().push_back( stencil_act1 );
mVividRendering->stencilActors().push_back( stencil_act2 );
tr1->setLocalAndWorldMatrix( vl::mat4::getTranslation(-50,0,0) );
tr2->setLocalAndWorldMatrix( vl::mat4::getTranslation(+50,0,0) );
// make points
{
......@@ -507,8 +514,8 @@ public:
switch((unsigned char)tolower(unicode_ch))
{
case 'b':
mVividRendering->setBackgroundEnabled( ! mVividRendering->backgroundEnabled() );
if ( mVividRendering->backgroundEnabled() ) {
mVividRendering->setBackgroundImageEnabled( ! mVividRendering->backgroundImageEnabled() );
if ( mVividRendering->backgroundImageEnabled() ) {
mVividRendering->setBackgroundImage( mBackgroundImage.get() );
}
break;
......@@ -627,7 +634,7 @@ public:
}
// update textured quad
//if ( mVivid->backgroundImage() == mBackgroundImage.get() && mVivid->backgroundEnabled() ) {
//if ( mVivid->backgroundImage() == mBackgroundImage.get() && mVivid->backgroundImageEnabled() ) {
// if ( fract( Time::currentTime() ) < 0.25f ) {
// memcpy( mBackgroundImage->pixels(), mBackgroundImages[0]->pixels(), mBackgroundImage->requiredMemory() );
// mVivid->updateBackgroundImage();
......
......@@ -369,9 +369,6 @@ void VividRenderer::renderStencil(Camera* camera) {
glUseProgram(0); VL_CHECK_OGL();
// Setup legacy matrices
projViewTransfCallback()->updateMatrices( /*update_cm*/true, /*update_tr*/true, NULL, camera, NULL ); VL_CHECK_OGL()
// Double check main states are clean
VL_CHECK( ! glIsEnabled( GL_LIGHTING ) );
......@@ -379,11 +376,18 @@ void VividRenderer::renderStencil(Camera* camera) {
VL_CHECK( ! glIsEnabled( GL_BLEND ) );
VL_CHECK( ! glIsEnabled( GL_CULL_FACE ) );
glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); VL_CHECK_OGL();
// Render stencil geometry
glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); VL_CHECK_OGL();
VL_CHECK( mVividRendering->stencilGeometry() );
mVividRendering->stencilGeometry()->render( NULL, NULL, camera, framebuffer()->openglContext() ); VL_CHECK_OGL();
for( size_t i = 0; i < mVividRendering->stencilActors().size(); ++i ) {
Actor* actor = mVividRendering->stencilActors()[ i ].get();
Renderable* geom = actor->lod(0);
Transform* tr = actor->transform();
// Setup legacy matrices
projViewTransfCallback()->updateMatrices( /*update_cm*/true, /*update_tr*/true, NULL, camera, tr ); VL_CHECK_OGL()
geom->render( NULL, NULL, camera, framebuffer()->openglContext() ); VL_CHECK_OGL();
}
// Blit texture to main framebuffer
// This is only needed to make the stencil texture visible in StencilRender mode.
......@@ -555,8 +559,8 @@ void VividRenderer::renderFrontToBackPeeling(const RenderQueue* render_queue, Ca
// clear & render the background
camera->viewport()->setClearFlags( CF_CLEAR_COLOR_DEPTH );
camera->viewport()->activate();
if ( mVividRendering->backgroundEnabled() ) {
renderBackground( camera );
if ( mVividRendering->backgroundImageEnabled() ) {
renderBackgroundImage( camera );
}
glEnable( GL_BLEND );
......@@ -1024,7 +1028,7 @@ const RenderQueue* VividRenderer::render(const RenderQueue* render_queue, Camera
return render_queue;
}
//-------------------------------------------------------------------------------------------------
void VividRenderer::renderBackground( Camera* camera ) {
void VividRenderer::renderBackgroundImage( Camera* camera ) {
class SaveStates {
GLint mCurrentProgram;
GLboolean mDepthMask;
......
......@@ -84,7 +84,7 @@ namespace vl
protected:
void renderQueue(const RenderQueue* in_render_queue, vl::GLSLProgram* cur_glsl, Camera* camera, real frame_clock, bool depth_peeling_on=true, bool outline_on = false);
void renderBackground( Camera* camera );
void renderBackgroundImage( Camera* camera );
void render2DOutlines( const RenderQueue* in_render_queue, Camera* camera, real frame_clock );
void renderVolumes( const RenderQueue* in_render_queue, Camera* camera, real frame_clock );
......
......@@ -74,7 +74,7 @@ VividRendering::VividRendering() {
texture->getTexParameter()->setWrapT( vl::TPW_CLAMP_TO_EDGE );
mBackgroundTexSampler = new TextureSampler;
mBackgroundTexSampler->setTexture( texture.get() );
mBackgroundEnabled = false;
mBackgroundImageEnabled = false;
// Stencil Texture
......
......@@ -114,12 +114,10 @@ namespace vl
/** Background color used when stencil rendering mode is enabled. */
const vec4& stencilBackground() const { return mStencilBackground; }
/** The vl::Geometry used to render into the Stencil Texture. */
void setStencilGeommetry( Geometry* geom ) { mStencilGeometry = geom; }
/** The vl::Geometry used to render into the Stencil Texture. */
Geometry* stencilGeometry() { return mStencilGeometry.get(); }
/** The vl::Geometry used to render into the Stencil Texture. */
const Geometry* stencilGeometry() const { return mStencilGeometry.get(); }
/** The Actors containing Geometry used to render into the Stencil Texture. */
std::vector< ref<Actor> >& stencilActors() { return mStencilActors; }
/** The Actors containing Geometry used to render into the Stencil Texture. */
const std::vector< ref<Actor> >& stencilActors() const { return mStencilActors; }
/** Stencil Texture smoothness, ie. the size of the blur kernel, default is 10. Larger values take longer to compute. */
void setStencilSmoothness( int smoothness ) { mStencilSmoothness = smoothness; }
......@@ -128,8 +126,8 @@ namespace vl
// Background settings
void setBackgroundEnabled( bool enabled ){ mBackgroundEnabled = enabled; }
bool backgroundEnabled() const { return mBackgroundEnabled; }
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 );
......@@ -177,7 +175,7 @@ namespace vl
float mAlpha;
bool mStencilEnabled;
ref<Geometry> mStencilGeometry;
std::vector< ref<Actor> > mStencilActors;
int mStencilSmoothness;
vec4 mStencilBackground;
......@@ -185,7 +183,7 @@ namespace vl
float mOutline3DClipOffset;
float mOutline3DEyeOffset;
bool mBackgroundEnabled;
bool mBackgroundImageEnabled;
ref<TextureSampler> mBackgroundTexSampler;
ref<Image> mBackgroundImage;
......
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