OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Equivalent of glTexSubImage2D ?

Goto page Previous  1, 2
 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
scrawl
Appreciator


Joined: 14 Dec 2014
Posts: 170

PostPosted: Thu Mar 02, 2017 1:40 pm    Post subject:
Reply with quote

Hi Johny,

By default, OSG will run graphics operations in a separate thread so trying to do OpenGL calls from the main thread will not have an effect. Update callbacks are always invoked from the main thread. Try using a DrawCallback on a Drawable or Camera instead which will be invoked from the OpenGL thread, and it will pass along the GraphicsContext for convenience as well.

If, however, you're set on not using threading at all, you can turn it off with the environment variable OSG_THREADING=SingleThreaded.

Cheers,
Jannik
Back to top
View user's profile Send private message
Steal
User


Joined: 26 Jan 2017
Posts: 56

PostPosted: Thu Mar 02, 2017 2:53 pm    Post subject:
Reply with quote

Hi,

Ow wow, yes.

Thank you!

Cheers,
Johny
Back to top
View user's profile Send private message
Steal
User


Joined: 26 Jan 2017
Posts: 56

PostPosted: Fri Mar 03, 2017 8:00 pm    Post subject:
Reply with quote

Hi,

For the lurker coming here for Awesomium, use the following code. The key is to use the unpack alignment settings.

Based on https://github.com/assertfail/bezel-webkit/blob/master/Source/wkSurface.cpp
Code:

OpenThreads::Mutex mutex;

std::vector<unsigned char*> reserves;

struct Paint {
   int reserve;
   unsigned char* src_buffer;
   int src_row_span;
   const Awesomium::Rect src_rect;
   const Awesomium::Rect dest_rect;
};
std::vector<Paint> paints;

int bpp = 4;

void DrawCallback::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 == texture->getTextureObject( cid ) )
      return;

   auto obj = texture->getTextureObject( cid );
   obj->bind();

   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);

      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 Paint(unsigned char* buffer, int ss, const Awesomium::Rect& sr, const Awesomium::Rect& dr) {

   OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mutex);

   int reserve = paints.size();

   if (reserves.size()==reserve)
      reserves.push_back( (unsigned char*)malloc(height * stride) );

   unsigned char* store = reserves.at( reserve );
   int row;

   // 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);

   paints.push_back( {reserve, store, ss, sr, dr} );

};


Thank you!

Cheers,
Johny
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts OSG equivalent of Performer pfSequence minghia General 7 Thu Aug 27, 2015 8:51 am View latest post
No new posts ssgsetfov equivalent function in osg tyson Submission 2 Thu Dec 15, 2011 4:50 am View latest post
No new posts Unable to find glTexSubImage2D altern... HiredK General 3 Thu Nov 03, 2011 4:39 am View latest post
No new posts Need help using glTexSubImage2D tLuisRodriguez General 5 Tue Mar 24, 2009 4:13 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP