Re: [osg-users] Setting a monochrome 2d texture from byte array

2019-11-05 Thread Steve Hardy
Hi,

Thanks for the responses.  I tried Robert's initial suggestions, but they get 

Code:
Warning: detected OpenGL error 'invalid value' at after RenderBin::draw(..)


on my system.

Glenn's suggestion basically worked, although the image was literally shades of 
red.  So I looked at the DefaultFont source, and tried GL_ALPHA.  Maybe that 
would have worked if I turned alpha blending on etc.  So just for kicks I tried 
GL_LUMINANCE (for internal and pixel format) and it worked!

So, for the record, here is what worked best for me:


Code:
img->setImage(w, h, 1, GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE, data, 
osg::Image::USE_MALLOC_FREE); // works!





Thank you!

Cheers,
Steve

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] OpenGL 4.4 and ARB_buffer_storage

2019-11-05 Thread Trajce Nikolov NICK
Hi Community,

I am trying to implement 4.4 Persistent Mapping Streaming, within the
context  of OSG. Bellow is from the spec. I am struggling at the moment
with making the buffer object sections, with the current OSG implementation
and not sure if it is possible so I am asking here for hints if any of you
have done something similar. Thanks a bunch as always!

Persistent mapped streaming

Given the availability of OpenGL 4.4 or ARB_buffer_storage
, the use of
persistent mapping of buffers becomes a possibility.

The idea here is to allocate an immutable buffer 2-3x the size you need,
and while you're executing operations from one region of the buffer while
you are writing to a different region. The difference between the prior
mapping scheme is that you are not frequently mapping and unmapping the
buffer. You map it persistently when you create the buffer, and keep it
mapped until it's time to delete the buffer.

This requires using glBufferStorage
 with the
GL_MAP_WRITE and GL_PERSISTENT_BITs. It also requires using glMapBufferRange
 with those
same bits when mapping it.

The general algorithm is as follows. The buffer is logically divided into 3
sections: the section you're writing to, and two sections that could
currently be in use.

The first step is to write to section 1 of the buffer. Once you have
finished writing, you must make this range of data visible to OpenGL by
flushing it (if you aren't mapping coherently). Then, you do whatever you
need to in order to ensure that this data is visible to OpenGL
.
Once the data is visible, you issue some number of Rendering Commands
 that read from that
section of the buffer. After issuing all of the commands that read from the
buffer, you create a fence sync object
.

Next frame, you start writing to buffer section 2. You do all of the above,
and create a new fence sync object. Keep each buffer section's sync objects
separate.

You do the same with buffer section 3 on the next frame.

On the fourth frame, you want to start using section 1 again. However, you
need to check section 1's sync object to see if it has completed *before* you
can start. You can only start writing to a section if that section's sync
object has completed.

-- 
trajce nikolov nick
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Setting a monochrome 2d texture from byte array

2019-11-05 Thread Glenn Waldron
Sandy,
Try this instead. You probably want normalized [0..1] data on the GPU, not
[0..255] integers.

 img->setImage(w, h, 1, GL_R8, GL_RED, GL_UNSIGNED_BYTE, data,
osg::Image::USE_MALLOC_FREE);

Glenn Waldron / osgEarth


On Tue, Nov 5, 2019 at 2:14 AM Steve Hardy  wrote:

> Hi,
>
> I am trying to render a monochrome camera image to a 2d texture, but
> without success unless I first convert it to BGR.
>
> After reading
> http://forum.openscenegraph.org/viewtopic.php?t=16236
> I got closer, but still no cigar as the result is a boring uniform black.
> Here is some code:
>
>
> Code:
> void VSGeode::setImageParameters(bool linear)
> {
> if (getNumDrawables() < 1)
> throw OSGWrapException("No drawables");
> quad = dynamic_cast(getDrawable(0));
> if (!quad)
> throw OSGWrapException("No geometry");
> osg::StateSet* state = quad->getStateSet();
> if (!state)
> throw OSGWrapException("No state");
> tex = state->getTextureAttribute(0,
> osg::StateAttribute::TEXTURE)->asTexture();
> if (!tex)
> throw OSGWrapException("No texture");
> tex->setFilter(osg::Texture::MIN_FILTER,linear ? osg::Texture::LINEAR
> : osg::Texture::NEAREST);
> tex->setFilter(osg::Texture::MAG_FILTER,linear ? osg::Texture::LINEAR
> : osg::Texture::NEAREST); // NEAREST for pixelated look, LINEAR for smooth.
> img = tex->getImage(0);
> }
>
> void VSGeode::setImageBGR(int w, int h, unsigned char * data)
> {
> img->setImage(w, h, 1, 3, GL_BGR, GL_UNSIGNED_BYTE, data,
> osg::Image::USE_MALLOC_FREE);
> quad->dirtyDisplayList();
> }
>
> void VSGeode::setImageMono8(int w, int h, unsigned char * data)
> {
> img->setImage(w, h, 1, GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE,
> data, osg::Image::USE_MALLOC_FREE); // black
> quad->dirtyDisplayList();
> }
>
>
>
> SetImageBGR() works fine, but as mentioned, setImageMono8() does not.
>
> What happens is that the image comes in from a hi-res GigE camera, and it
> is a monochrome byte array.  Because this is already fairly CPU intensive,
> I wish to avoid another copy to expand into a BGR array.  But for the life
> of me I can't work out a magic combo of parameters that actually works.
> The data really is there, since I can fake it and just call setImageBGR()
> and it comes up with something, albeit like a Degas painting.
>
> So what is the most efficient way of getting a grey-scale image in a
> texture, from a 2D byte array in memory?
>
> Thank you!
>
> Cheers,
> Steve
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=76871#76871
>
>
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Setting a monochrome 2d texture from byte array

2019-11-05 Thread Robert Osfield
Hi Steve,

Using a monochrome texture should be as simple as using GL_ALPHA or GL_RED
as the pixel format.  The OpenSceneGraph/src/osgText/DefaultFont.cpp
provides an example of a setting up a monochrome image.

Robert.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org