Create new FBO if Canvas render target size chanages
As doesnt seem to work to just resize the texture, if changing the size of the Canvas render target a new FBO is created and placed on all active placements.
This commit is contained in:
parent
a882263033
commit
2263823f75
@ -159,15 +159,30 @@ namespace canvas
|
|||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void Canvas::update(double delta_time_sec)
|
void Canvas::update(double delta_time_sec)
|
||||||
{
|
{
|
||||||
if( !_texture.serviceable() )
|
if( (!_texture.serviceable() && _status != STATUS_DIRTY)
|
||||||
{
|
|| (_status & CREATE_FAILED) )
|
||||||
if( _status != STATUS_OK )
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if( _status == STATUS_DIRTY )
|
||||||
|
{
|
||||||
_texture.setSize(_size_x, _size_y);
|
_texture.setSize(_size_x, _size_y);
|
||||||
|
|
||||||
|
if( !_texture.serviceable() )
|
||||||
|
{
|
||||||
_texture.useImageCoords(true);
|
_texture.useImageCoords(true);
|
||||||
_texture.useStencil(true);
|
_texture.useStencil(true);
|
||||||
_texture.allocRT(/*_camera_callback*/);
|
_texture.allocRT(/*_camera_callback*/);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Resizing causes a new texture to be created so we need to reapply all
|
||||||
|
// existing placements
|
||||||
|
for(size_t i = 0; i < _placements.size(); ++i)
|
||||||
|
{
|
||||||
|
if( !_placements[i].empty() )
|
||||||
|
_dirty_placements.push_back( _placements[i].front()->getProps() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
osg::Camera* camera = _texture.getCamera();
|
osg::Camera* camera = _texture.getCamera();
|
||||||
|
|
||||||
@ -183,6 +198,8 @@ namespace canvas
|
|||||||
if( _texture.serviceable() )
|
if( _texture.serviceable() )
|
||||||
{
|
{
|
||||||
setStatusFlags(STATUS_OK);
|
setStatusFlags(STATUS_OK);
|
||||||
|
setStatusFlags(STATUS_DIRTY, false);
|
||||||
|
_render_dirty = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -273,8 +290,7 @@ namespace canvas
|
|||||||
if( _size_x == sx )
|
if( _size_x == sx )
|
||||||
return;
|
return;
|
||||||
_size_x = sx;
|
_size_x = sx;
|
||||||
|
setStatusFlags(STATUS_DIRTY);
|
||||||
// TODO resize if texture already allocated
|
|
||||||
|
|
||||||
if( _size_x <= 0 )
|
if( _size_x <= 0 )
|
||||||
setStatusFlags(MISSING_SIZE_X);
|
setStatusFlags(MISSING_SIZE_X);
|
||||||
@ -291,8 +307,7 @@ namespace canvas
|
|||||||
if( _size_y == sy )
|
if( _size_y == sy )
|
||||||
return;
|
return;
|
||||||
_size_y = sy;
|
_size_y = sy;
|
||||||
|
setStatusFlags(STATUS_DIRTY);
|
||||||
// TODO resize if texture already allocated
|
|
||||||
|
|
||||||
if( _size_y <= 0 )
|
if( _size_y <= 0 )
|
||||||
setStatusFlags(MISSING_SIZE_Y);
|
setStatusFlags(MISSING_SIZE_Y);
|
||||||
@ -545,7 +560,7 @@ namespace canvas
|
|||||||
_status_msg = "Missing size-y";
|
_status_msg = "Missing size-y";
|
||||||
else if( _status & CREATE_FAILED )
|
else if( _status & CREATE_FAILED )
|
||||||
_status_msg = "Creating render target failed";
|
_status_msg = "Creating render target failed";
|
||||||
else if( _status == STATUS_OK && !_texture.serviceable() )
|
else if( _status == STATUS_DIRTY )
|
||||||
_status_msg = "Creation pending...";
|
_status_msg = "Creation pending...";
|
||||||
else
|
else
|
||||||
_status_msg = "Ok";
|
_status_msg = "Ok";
|
||||||
|
@ -46,9 +46,10 @@ namespace canvas
|
|||||||
enum StatusFlags
|
enum StatusFlags
|
||||||
{
|
{
|
||||||
STATUS_OK,
|
STATUS_OK,
|
||||||
MISSING_SIZE_X = 0x0001,
|
STATUS_DIRTY = 1,
|
||||||
MISSING_SIZE_Y = 0x0002,
|
MISSING_SIZE_X = STATUS_DIRTY << 1,
|
||||||
CREATE_FAILED = 0x0004
|
MISSING_SIZE_Y = MISSING_SIZE_X << 1,
|
||||||
|
CREATE_FAILED = MISSING_SIZE_Y << 1
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,8 +70,7 @@ namespace canvas
|
|||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
ODGauge::~ODGauge()
|
ODGauge::~ODGauge()
|
||||||
{
|
{
|
||||||
if( camera.valid() && _system_adapter )
|
clear();
|
||||||
_system_adapter->removeCamera(camera.get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
@ -86,8 +85,10 @@ namespace canvas
|
|||||||
_size_x = size_x;
|
_size_x = size_x;
|
||||||
_size_y = size_y < 0 ? size_x : size_y;
|
_size_y = size_y < 0 ? size_x : size_y;
|
||||||
|
|
||||||
if( texture.valid() )
|
if( serviceable() )
|
||||||
texture->setTextureSize(_size_x, _size_x);
|
reinit();
|
||||||
|
else if( texture )
|
||||||
|
texture->setTextureSize(_size_x, _size_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
@ -217,6 +218,25 @@ namespace canvas
|
|||||||
rtAvailable = true;
|
rtAvailable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void ODGauge::reinit()
|
||||||
|
{
|
||||||
|
osg::NodeCallback* cull_callback = camera ? camera->getCullCallback() : 0;
|
||||||
|
clear();
|
||||||
|
allocRT(cull_callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void ODGauge::clear()
|
||||||
|
{
|
||||||
|
if( camera.valid() && _system_adapter )
|
||||||
|
_system_adapter->removeCamera(camera.get());
|
||||||
|
camera.release();
|
||||||
|
texture.release();
|
||||||
|
|
||||||
|
rtAvailable = false;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void ODGauge::updateCoordinateFrame()
|
void ODGauge::updateCoordinateFrame()
|
||||||
{
|
{
|
||||||
|
@ -123,6 +123,8 @@ namespace canvas
|
|||||||
|
|
||||||
// Real initialization function. Bad name.
|
// Real initialization function. Bad name.
|
||||||
void allocRT(osg::NodeCallback* camera_cull_callback = 0);
|
void allocRT(osg::NodeCallback* camera_cull_callback = 0);
|
||||||
|
void reinit();
|
||||||
|
void clear();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user