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 1, 2  Next
 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
Steal
User


Joined: 26 Jan 2017
Posts: 56

PostPosted: Mon Feb 27, 2017 7:46 pm    Post subject:
Equivalent of glTexSubImage2D ?
Reply with quote

Hi,

I've been exploring my options, and have not found a decent solution.

In the osg prerender example, there's an image that's attached to a camera. It is attached to a texture with texture->setImage(0, image);, and the camera has a post-draw callback that inverts the colors on the image.

The image holds the pixels of the scene.

When we render the texture, the texture may see that it has a dirty image attachment.

The problem is that I don't want to dirty the whole image, which is 2048x2048.

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


Joined: 26 Jan 2017
Posts: 56

PostPosted: Mon Feb 27, 2017 7:54 pm    Post subject:
Reply with quote

Hi,

Without being mr mysterious, I am 'implementing' Awesomium.

Thank you!

Cheers,
Johny
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 10791

PostPosted: Tue Feb 28, 2017 8:06 am    Post subject:
Equivalent of glTexSubImage2D ?
Reply with quote

HI Johny,

The OSG isn't a mechanism that automatically subloads a portion of an
osg::Image.

However, there osg::Texture2D has a osg::Textuew2D::SubcloadCallback
that you can subclass from and impement the load and subload methods.
This gives you full control over creation of the texture object,
initial loading the image data and subloading when required.

Robert.

On 27 February 2017 at 19:46, Johny Canes <> wrote:
Quote:
Hi,

I've been exploring my options, and have not found a decent solution.

In the osg prerender example, there's an image that's attached to a camera. It is attached to a texture with texture->setImage(0, image);, and the camera has a post-draw callback that inverts the colors on the image.

The image holds the pixels of the scene.

When we render the texture, the texture may see that it has a dirty image attachment.

The problem is that I don't want to dirty the whole image, which is 2048x2048.

Cheers,
Johny

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=70356#70356








------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Steal
User


Joined: 26 Jan 2017
Posts: 56

PostPosted: Tue Feb 28, 2017 9:23 am    Post subject:
Reply with quote

Hello,

Ah that's useful, ty. I was already thinking of hacking the OSG a little but no need.

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


Joined: 26 Jan 2017
Posts: 56

PostPosted: Tue Feb 28, 2017 11:29 am    Post subject:
Reply with quote

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


Joined: 26 Jan 2017
Posts: 56

PostPosted: Tue Feb 28, 2017 12:04 pm    Post subject:
Reply with quote

Hi,

Mh Robert, it seems glTexSubImage2D is the most straightforward. I don't want to build an abstraction around one simple operation.

This is about the Awesomium surface's Paint callback. In its most simple way, it will look like
Code:
   glTexSubImage2D(GL_TEXTURE_2D, 0, dest_rect.x, dest_rect.y, dest_rect.width, dest_rect.height, GL_BGRA_EXT, GL_UNSIGNED_BYTE, a);


There's a couple of things now. Can I or may I manually bind using
Code:
texture->getTextureObject( cid )->bind();
or alternatively, directly with
Code:
glBindTexture( GL_TEXTURE_2D, tid );
?

Thank you!

Cheers,
Johny
Back to top
View user's profile Send private message
mp3butcher (Julien Valentin)
Appreciator


Joined: 17 Feb 2010
Posts: 283

PostPosted: Tue Feb 28, 2017 4:37 pm    Post subject:
Re: Equivalent of glTexSubImage2D ?
Reply with quote

Hi steel
As we already said; it's difficult to understand what you want without code.
If I understand correctly you want to update a part of a texture with the content of an image...(to implement sprites?)
In this case There are:
    directcall to
    Code:
    Texture::applyTexImage2D_subload(State& state, GLenum target, const Image* image, GLsizei inwidth, GLsizei inheight, GLint inInternalFormat, GLint numMipmapLevels) const

    or use a Textue2D::SubloadCallback


But my humble opinion is it would be more efficient to work entirely with custom textures composition rtt with shaders...(it would avoid ntempestives RAM->VRAM transfer bus killer)

cheers

Steal wrote:
Hi,

I've been exploring my options, and have not found a decent solution.

In the osg prerender example, there's an image that's attached to a camera. It is attached to a texture with texture->setImage(0, image);, and the camera has a post-draw callback that inverts the colors on the image.

The image holds the pixels of the scene.

When we render the texture, the texture may see that it has a dirty image attachment.

The problem is that I don't want to dirty the whole image, which is 2048x2048.

Cheers,
Johny
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 10791

PostPosted: Tue Feb 28, 2017 5:28 pm    Post subject:
Equivalent of glTexSubImage2D ?
Reply with quote

On 28 February 2017 at 12:04, Johny Canes <> wrote:
Quote:
Hi,

Mh Robert, it seems glTexSubImage2D is the most straightforward. I don't want to build an abstraction around one simple operation.

There's a couple of things now. Can I or may I manually bind using
Code:
texture->getTextureObject( cid )->bind();

or alternatively, directly with
Code:
glBindTexture( GL_TEXTURE_2D, tid );

?

You should see the same result, the bind() call will just be doing a
glBindTexture call itself. Going dig into the source code to see what
it's doing.

The advantage of using TextureObject is that you can leverage the
OSG's ability to recycle textures objects and have them cleaned up
reliably. Recyling texture objects is really important when doing
paged scenes as creating and destroying GL objects is very expensive
relative to just subloading data. The OSG does this automatically for
you.

In your case you want to do subloading of portion of an image which
steps beyond what the core OSG provides, but texture objects and reuse
might still be important.

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Steal
User


Joined: 26 Jan 2017
Posts: 56

PostPosted: Wed Mar 01, 2017 8:47 am    Post subject:
Reply with quote

Hi,

Thanks for the amazing answers. I'm not trying for sprites, I'm for a repaint over an existing surface. The code below works on another project of mine, but I haven't got it working in my OSG app yet...

What it does, it gives you an BGRA buffer for you to paint your existing surface with. (e.g. if you hover a small html element with a :hover style, only that will get painted)

Code:
void nr::as::Zurface::Paint(unsigned char* src_buffer, int src_row_span, const Awesomium::Rect& src_rect, const Awesomium::Rect& dest_rect) {
   auto cid = gGc->getState()->getContextID();

   texture->getTextureObject( cid )->bind();

   unsigned char* a = &src_buffer[0];

   glTexSubImage2D(GL_TEXTURE_2D, 0, dest_rect.x, dest_rect.y, dest_rect.width, dest_rect.height, GL_BGRA_EXT, GL_UNSIGNED_BYTE, a);

   glBindTexture( GL_TEXTURE_2D, 0 ); // unbind?
}


Awesomium has its own threads and this one is an arbitrary callback. Should I mutex?

Thank you!

Cheers,
Johny
Back to top
View user's profile Send private message
SMesserschmidt (Sebastian Messerschmidt)
Forum Moderator


Joined: 10 Sep 2013
Posts: 704

PostPosted: Wed Mar 01, 2017 9:16 am    Post subject:
Equivalent of glTexSubImage2D ?
Reply with quote

Hi Johny,

Quote:
Hi,

Thanks for the amazing answers. I'm not trying for sprites, I'm for a repaint over an existing surface. The code below works on another project of mine, but I haven't got it working in my OSG app yet...

What it does, it gives you an BGRA buffer for you to paint your existing surface with.


Code:
void nr::as::Zurface::Paint(unsigned char* src_buffer, int src_row_span, const Awesomium::Rect& src_rect, const Awesomium::Rect& dest_rect) {
auto cid = gGc->getState()->getContextID();

texture->getTextureObject( cid )->bind();

unsigned char* a = &src_buffer[0];

glTexSubImage2D(GL_TEXTURE_2D, 0, dest_rect.x, dest_rect.y, dest_rect.width, dest_rect.height, GL_BGRA_EXT, GL_UNSIGNED_BYTE, a);

glBindTexture( GL_TEXTURE_2D, 0 ); // unbind?
}




Awesomium has its own threads and this one is an arbitrary callback. Should I mutex?

If you don't want to block either threads, you can copy the buffer data
and apply it in an callback of the scenegraph. You'll need a mutex
anyways to protect you update-buffer;-)

Cheers
Sebastian
Quote:

Thank you!

Cheers,
Johny

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=70367#70367









------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Steal
User


Joined: 26 Jan 2017
Posts: 56

PostPosted: Wed Mar 01, 2017 12:24 pm    Post subject:
Reply with quote

Hi,

Thanks. Where would I put the callback? As a pre-callback for the quad that is rendered by the ortographic camera? Something like that sounds alright to me for a view(er) slave with its own graph.

Currently though, texture->getTextureObject( cid )->bind();

and subsequently the glTexSubImage2D does not change my texture. Any ideas on why? Am I really binding the right texture? Code above ^.

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


Joined: 26 Jan 2017
Posts: 56

PostPosted: Thu Mar 02, 2017 10:57 am    Post subject:
Reply with quote

Hi,

On the upside, I've been studying the workings of OSG and looking at the source code really helps. However, my glTexSubImage2D continues to have zero effect. I'm doing this via a operator StateAttribute callback on the texture, binding it, then trying to write pixels. I've also discovered the scoped lock mutex, which is really cool.

However, the gl operation still doesn't do anything.

When I look at how Texture2D.cpp does it, it uses `glPixelStorei(GL_UNPACK_ROW_LENGTH, x);` and the like, but I've no idea how to use these...

It also shouldn't matter, if I get the alignments and unpack hints wrong, it should at least produce some jitters, but my gl call does nothing. Any ideas?

Thank you!

Cheers,
Johny
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 10791

PostPosted: Thu Mar 02, 2017 11:04 am    Post subject:
Equivalent of glTexSubImage2D ?
Reply with quote

Hi Johny,

On 2 March 2017 at 10:57, Johny Canes <> wrote:
Quote:
On the upside, I've been studying the workings of OSG and looking at the source code really helps. However, my glTexSubImage2D continues to have zero effect on its code. I'm doing this via a operator StateAttribute callback on the texture, binding it, then trying to write pixels. I've also discovered the scoped lock mutex, which is really cool.

However, the gl operation still doesn't do anything.

When I look at how Texture2D.cpp does it, it uses `glPixelStorei(GL_UNPACK_ROW_LENGTH, x);` and the like, but I've no idea how to use these...

I'm afraid there isn't too much we can do to help at this point as
there are too many elements specific to the code you are integrating
to know what is precisely going on. It's really a task that requires
the code in front of you and to be able to step through what is
happening to be able to debug it.

If you are planning on open sourcing your integration code then
perhaps others in the community will be able to help out as then
they'd be able to run the code first hand and may be able to see what
is going on.

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Steal
User


Joined: 26 Jan 2017
Posts: 56

PostPosted: Thu Mar 02, 2017 11:24 am    Post subject:
Reply with quote

Hi,

I'll post a pretty print I know you guys like colors.

https://codepaste.net/cwre47

The callback is attached with `texture->setUpdateCallback( new Painter() );`

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


Joined: 26 Jan 2017
Posts: 56

PostPosted: Thu Mar 02, 2017 12:44 pm    Post subject:
Reply with quote

Hi,

Oh it's throwing an INVALID_OPERATION

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 1, 2  Next
Page 1 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