openscenegraph / OpenSceneGraph

OpenSceneGraph git repository
http://www.openscenegraph.org
Other
3.2k stars 1.41k forks source link

asynchronous thread loading texture #177

Closed sczhaoyu closed 7 years ago

sczhaoyu commented 7 years ago

Mr openscenegraph: While I was using multithreading to change the model's texture, I couldn't use glMapBuffer function. It also couldn't be used on the pointer I created.

sczhaoyu commented 7 years ago

code: void run(){ auto ext = context->getState()->get(); GLuint pid[1]; ext->glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pid[1]); ext->glBufferData(GL_PIXEL_UNPACK_BUFFER, len, 0, GL_STREAM_DRAW_ARB); } glGetError Code :1282

openscenegraph commented 7 years ago

OpenGL calls should only ever be called by a thread with a valid graphics context, if you do calls outside this then you will get GL errors.

The OSG will do all set up and use of PBO's automatically for you so there shouldn't be any need to do PBO calls manually for most common usage cases. For dynamically updateded textures all one need to do is update the osg::Image data attached to the osg::Texture and call image->dirty() on the image so ensure the data is passed on the next time the texture is passed to OpenGL. To use PBO's in this process you simply assign an osg::PixerlBufferObject to the osg::Image.

sczhaoyu commented 7 years ago

Thanks