Jump to content

[SOLVED] Unigine::Texture::getImage alternative to write into WidgetSprite


photo

Recommended Posts

Hello

 

We are testing to include Coherent UI framework, this works so far good, but I've read here (https://developer.unigine.com/forum/topic/507-texturegetimage-bug/?p=3051) that getImage should not be used. What are the best practices here?

 

Currently I return from an external class an Unigine::ImagePtr and set it with WidgetSprite::setImage after manipulation was done.

Unigine::TexturePtr texture = view->texture; //  Access from friend class

// Get image
Unigine::ImagePtr image = view->image; //Image was created with Unigine::TexturePtr::create2D

const size_t singlePixelSize = image->getPixelSize();
const size_t size = _width * _height * singlePixelSize;
int* originalSrc = (int*)SharedMemoryHelper::Map(_handle, size);

// Set lock
image->grab();


glBindTexture(GL_TEXTURE_2D, texture->getGLTextureID());
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, _width, _height, GL_BGRA, GL_UNSIGNED_BYTE, originalSrc);
glBindTexture(GL_TEXTURE_2D, 0);


// Release image
image->release();
texture->getImage(image);

Thanks

Manuel

Link to comment

Hi Manuel, I don't think that there is an alternative in your case. The texture download from GPU to CPU via getImage() should in general be avoided as this is a relatively slow operation and can harm render performance due to GPU stall for required CPU synchronization. But if there is no alternativ: who cares ?

Link to comment

Hello Ulf

 

Thanks a lot for your reply. It seems it's the way to go in this case.

 

I was looking through the images class and found the function Unigine::Image::getPixels (Returns the pointer to the array of pixels).

But it seems allocated too in the system memory if I understand it right.

Link to comment
×
×
  • Create New...