[osg-users] Equivalent of glTexSubImage2D ?
Johny Canes
psijsma at gmail.com
Fri Mar 3 12:00:42 PST 2017
Hi,
For the lurker coming here for Awesomium, use the following code. The key is to use the unpack alignment settings.
Very non optimized and copied from https://github.com/assertfail/bezel-webkit/blob/master/Source/wkSurface.cpp
Code:
void nr::awe::Drawer::operator() (const osg::Camera& cam) const {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mutex);
if (paints.size()<1)
return;
//if ( ! gGc->getState() )
//return;
auto cid = gGc->getState()->getContextID();
if ( NULL == awe::texture->getTextureObject( cid ) )
return;
auto obj = awe::texture->getTextureObject( cid );
obj->bind();
int bpp = 4;
int stride = nr::width * 4;
for ( auto p : paints )
{
glPixelStorei(GL_UNPACK_ROW_LENGTH, stride/bpp);
glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, p.dest_rect.height);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, p.dest_rect.x);
glPixelStorei(GL_UNPACK_SKIP_ROWS, p.dest_rect.y);
glTexSubImage2D(
GL_TEXTURE_2D,
0,
p.dest_rect.x,
p.dest_rect.y,
p.dest_rect.width,
p.dest_rect.height,
GL_BGRA,
GL_UNSIGNED_BYTE,
p.src_buffer);
//unsigned char* a = &p.src_buffer[0];
//glTexSubImage2D(GL_TEXTURE_2D, 0, p.dest_rect.x, p.dest_rect.y, p.dest_rect.width, p.dest_rect.height, GL_BGRA_EXT, GL_UNSIGNED_BYTE, a);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
delete p.src_buffer;
}
paints.clear();
}
void nr::awe::Zurface::Paint(unsigned char* buffer, int ss, const Awesomium::Rect& sr, const Awesomium::Rect& dr) {
int row;
int bpp = 4;
int stride = nr::width * 4;
unsigned char* store = (unsigned char*) malloc(nr::height * stride);
memset(store, 0, height * stride);
// copy the region to our store
for (row = 0 ; row < dr.height ; ++row)
memcpy(store+(row+dr.y)*stride+(dr.x*bpp),
buffer+(row+sr.y)*ss+(sr.x*4),
dr.width*bpp);
//memcpy(copy, src_buffer, src_row_span * src_rect.height);
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mutex);
paints.push_back( {store, ss, sr, dr} );
};
Thank you!
Cheers,
Johny
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=70405#70405
More information about the osg-users
mailing list