1

I have a 2D texture placed over rectangular area - it's a dynamic texture image (640x480).

tex = new osg::Texture2D;
tex->setDataVariance( osg::Object::DYNAMIC );
tex->setResizeNonPowerOfTwoHint( false );
tex->setFilter( osg::Texture2D::MIN_FILTER, osg::Texture2D::NEAREST );
tex->setFilter( osg::Texture2D::MAG_FILTER, osg::Texture2D::NEAREST );
tex->setImage(myImage);

My image data is updated in other thread often (each N milliseconds):

myImage->setImage(
    width,
    height,
    1,
    3,
    GL_BGR,
    gl_data_size,
    (BYTE *)newImageData,
    osg::Image::AllocationMode::USE_MALLOC_FREE
);

And after that I want to update rendered image, if I use dirty( thought this was a best way for update ) on image set to texture, e.g.

// Update callback
...
myImage->dirty();
...

My performance is about 7-8 times slower than if I use just image replacement with same pointer.

// Update callback
...
tex->setImage(myImage);
...

Reading documentation and gidelines of OSG makes me think the correct way is - 'dirty()'. But it's extremly slow. Do I missunderstand something or there is a mistake in my code?

4

2 回答 2

1

正确的方法是在图像上调用dirty()。

尝试在图像中添加 osg::PixelBufferObject 以加快传输到显卡的速度。

myImage->setPixelBufferObject(new osg::PixelBufferObject(myImage));
于 2012-06-15T16:02:35.200 回答
1

我假设您使用的不是 OSG 的最新(3.0.1)版本,因为它缺少 Image 类的“脏”方法。在以前的版本 (2.x) 中:

inline void Image::dirty()
{
    ++_modifiedCount;
    if (_bufferObject.valid())
        _bufferObject->dirty();
}

dirty()依次重置_bufferObject的所有编译列表。另一方面setImage是这样开始的:

void Texture2D::setImage(Image* image)
{
    if (_image == image) return;
    ...
}

所以在你的情况下,如果你对图像使用相同的指针,它什么也不做。这就是它更快的原因,但我不知道如果没有任何变化,OSG 如何更新实际纹理。

于 2012-06-13T08:56:32.773 回答