Re: [Opensg-users] OpenSG 2: Setting up the depth buffer

2015-10-19 Thread Johannes
Hello Gerrit,

once again. I did a glance at the multisampling OpenGL technique and 
compared it to the OpenSG texture/FBO usage. As I see it, multisampling 
is currently not supported by OpenSG.

Following the wikipedia entry

https://www.opengl.org/wiki/Multisampling#Allocating_a_Multisample_Render_Target

OpenSG does have to use the GL_TEXTURE_2D_MULTISAMPLE flag(s) and the 
glTexImage2DMultisample api(s) in order to support multisampling. Is 
there any reason not to uses these on a multisampling rendering context.

What is your opinion with respect to multisampling?
Do you have experience with the multisampling in OpenGL generally?
Should we add support for proper multisampling to OpenSG?

Is multisampling used by others regularily?
Do other post process their render buffers for antialiasing instead of 
hardware multisampling?

Best,
Johannes



--
___
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users


Re: [Opensg-users] OpenSG 2: Setting up the depth buffer

2015-10-19 Thread Johannes
Hello Gerrit,

suppose we would have a corresponding FBOForeground, which manages a FBO 
and would be filled from the render buffer by blit operation at the end 
of the render task (probably on request only).
What I have in mind is to setup such a foreground in my first viewport 
and to use the FBO in the second viewport's FBOBackground in my dynamic 
case. The FBO would have to be adapted at resize and would have to 
respect the multisampling settings of the underlying render context.

Do you think that this is good plan?
Do I have overseen some constraint that could not be fulfilled?

Best,
Johannes

P.S. I did already a simple example with the new FBOBackground and it 
worked well.




--
___
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users


Re: [Opensg-users] OpenSG 2: Setting up the depth buffer

2015-10-19 Thread Johannes
Hello Gerrit,

below you can find my simple not finished example with the 
FBOBackground. It works reasonably with a standard render context but 
fails with a multisampling context.

I have currently not figured out what exactly is going wrong, so.

Best,
Johannes


// User interface:
//  a) mouse=> standard navigator
//  b) keyboard =>
//  '1': toggle between static and dynamic mode
//

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#ifdef OSG_BUILD_ACTIVE
// Headers
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#else
// Headers
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#endif

OSG_USING_NAMESPACE; // just for convenience but not recommended

#define USE_MULTISAMPLING

#ifdef _DEBUG
const int max_tori =  500;
#else
const int max_tori = 1;
#endif

//
// Helper class for building FBO
//
class FBOBuilder
{
public:
 struct TextureData {
 TextureData()
 : enable(true)
 , pixel_format(Image::OSG_RGBA_PF)
 , type(Image::OSG_UINT8_IMAGEDATA)
 , main_memory(true)
 , texObj(nullptr)
 , image(nullptr) {}
~TextureData() {texObj = nullptr; image = nullptr; }

 bool enable;
 UInt32 pixel_format;
 Int32 type;
 bool main_memory;
 TextureObjChunkUnrecPtr texObj;
 ImageUnrecPtr image;
 };

 typedef std::vector VecTextureDataT;

public:
 FBOBuilder(const VecTextureDataT& buffers, bool depth, 
bool stencil, const TextureData& ds_buffer)
 : _buffers(buffers) , _depth(depth) , _stencil(stencil) 
, _ds_buffer(ds_buffer) {}
~FBOBuilder() {}

public:
 FrameBufferObjectTransitPtroperator()(UInt32 width, UInt32 
height) const;

private:
 VecTextureDataT _buffers;
 bool_depth;
 bool_stencil;
 TextureData _ds_buffer;
};

FrameBufferObjectTransitPtr FBOBuilder::operator()(
 UInt32 width,
 UInt32 height) const
{
 //
 // Setup the FBO
 //
 FrameBufferObjectUnrecPtr fbo = FrameBufferObject::create();
 //
 // multiple color buffers
 //
 for (UINT32 idx = 0; idx < _buffers.size(); ++idx) {
 //
 // use textures?
 //
 if (_buffers[idx].enable) {
 ImageUnrecPtr   texImg = (_buffers[idx].image  == 
nullptr ? Image::create()   : _buffers[idx].image);
 TextureObjChunkUnrecPtr texObj = (_buffers[idx].texObj == 
nullptr ? TextureObjChunk::create() : _buffers[idx].texObj);
 TextureBufferUnrecPtr   texBuf = TextureBuffer::create();

 if (_buffers[idx].image == nullptr)
 texImg->set(_buffers[idx].pixel_format,
 width, height, 1, 1, 1, 0.f, nullptr,
 _buffers[idx].type,
 _buffers[idx].main_memory);

 texObj->setImage(texImg);
 texBuf->setTexture(texObj);

 fbo->setColorAttachment(texBuf, idx);
 } else
 //
 // no, then use simple render buffer
 //
 {
 RenderBufferUnrecPtr renBuf = RenderBuffer::create();
 renBuf->setInternalFormat(_buffers[idx].pixel_format);
 fbo->setColorAttachment(renBuf, idx);
 }
 fbo->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT + 
idx);
 }
 //
 // a sole depth buffer
 //
 if (_depth && !_stencil) {
 //
 // use textures?
 //
 if (_ds_buffer.enable) {
 ImageUnrecPtr   texImg = (_ds_buffer.image  == 
nullptr ? Image::create()   : _ds_buffer.image);
 TextureObjChunkUnrecPtr texObj = (_ds_buffer.texObj == 
nullptr ? TextureObjChunk::create() : _ds_buffer.texObj);
 TextureBufferUnrecPtr   texBuf = TextureBuffer::create();

 if (_ds_buffer.image == nullptr)
 texImg->set(_ds_buffer.pixel_format,
 width, height, 1, 1, 1, 0.f, nullptr,
 _ds_buffer.type,
 _ds_buffer.main_memory);

 texObj->setImage(texImg);

 if (_ds_buffer.texObj == nullptr) {
 texObj->setInternalFormat(GL_DEPTH_COMPONENT24);
 texObj->setExternalFormat(GL_DEPTH_COMPONENT24);
 }
 texBuf->setTexture(texObj);

 fbo->setDepthAttachment(texBuf);
 } else
 //
 // no, then use simple render buffer
 //
 {
 RenderBufferUnrecPtr renBuf = RenderBuffer::create();
 

Re: [Opensg-users] OpenSG 2: Setting up the depth buffer

2015-10-09 Thread Gerrit Voß

Hello,

I added a new OSGFBOBackground which takes a FramebufferObject and 
on clear tries to blit all color, depth and stencil buffers,
either to the active FBO or to the window framebuffer. 

I only came around to do some quick testing, but it gives you
something to start with (and ideally it already does what you
need). I will do some further testing, especially on robustness.


kind regards
  gerrit



--
___
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users


Re: [Opensg-users] OpenSG 2: Setting up the depth buffer

2015-10-09 Thread Johannes
Hello Gerrit,

On 09.10.2015 12:52, Gerrit Voß wrote:
>
> I added a new OSGFBOBackground which takes a FramebufferObject and
> on clear tries to blit all color, depth and stencil buffers,
> either to the active FBO or to the window framebuffer.
>
This is really great. I will immediately take an OpenSG snapshot and 
look into it. However, I will be offline the next week and can not give 
you direct response, so.

> I only came around to do some quick testing, but it gives you
> something to start with (and ideally it already does what you
> need). I will do some further testing, especially on robustness.
>
I have started with an example as I have written. I think it can be 
properly extended to be part of the OpenSG examples when finished.

One point I have in mind with respect to robustness is the support of 
multisampled render context/buffers. But, I don't currently know every 
nut, bolt and screw in this area.

Thanks, and best regards,
Johannes



--
___
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users


Re: [Opensg-users] OpenSG 2: Setting up the depth buffer

2015-10-07 Thread Gerrit Voß

Hi,

On Tue, 2015-10-06 at 10:11 +0200, Johannes Brunen wrote:
> Hello,
> 
>  
> 
> I'm looking for a method to setup the depth buffer and possibly the
> stencil buffer befor starting rendering a viewport.
> 
>  
> 
> Suppose I have rendered a viewport with complex geometry into textures
> with a FBO. I know how to do that, but now I want to initialize the
> color and depth/stencil buffer from these textures  for rendering a
> second viewport. I have to render the second viewport a couple of times
> dynamically and won't render the first viewport in this situation.
> 
>  
> 
> Can this be done with OpenSG? Can anyone give me an outline of such a
> setup?

a passive background might help. It can take a clear callback
where you can do the blitting. Another option in there
is to blit the current framebuffer into an FBO (which is not directly
what you are looking for). Adding blitting from another FBO should not
be to difficult, well depending on how accurate the 'what to blit'
settings have to be. I'll have a look.

kind regards
  gerrit



--
Full-scale, agent-less Infrastructure Monitoring from a single dashboard
Integrate with 40+ ManageEngine ITSM Solutions for complete visibility
Physical-Virtual-Cloud Infrastructure monitoring from one console
Real user monitoring with APM Insights and performance trend reports 
Learn More http://pubads.g.doubleclick.net/gampad/clk?id=247754911=/4140
___
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users


Re: [Opensg-users] OpenSG 2: Setting up the depth buffer

2015-10-07 Thread Gerrit Voß

Hi,

On Wed, 2015-10-07 at 13:55 +0200, Johannes wrote:
> On 07.10.2015 09:27, Gerrit Voß wrote:
> >
> > a passive background might help. It can take a clear callback
> > where you can do the blitting. Another option in there
> > is to blit the current framebuffer into an FBO (which is not directly
> > what you are looking for). Adding blitting from another FBO should not
> > be to difficult, well depending on how accurate the 'what to blit'
> > settings have to be. I'll have a look.
> >
> Great :-)
> 
> I'm also playing around with an example with a PolygonBackground, but I 
> have problems getting it to run. What I'm trying is to create a viewport
> with a PolygonBackground that is painting the texture image from a FBO 
> that I have rendered prior to that. In that simple setup the image is 
> rendered perfectly fine. However, when I add a shader program chunk to 
> the material of the PolygonBackground that shader code is never called.
> I debugged the relevant code places where GL_COMPILE_STATUS and 
> GL_LINK_STATUS is checked, but the example program did not stop at these 
> places. Additionally, I debugged the State::activate(...) function. The 
> TextureObjChunk, TextureEnvChunk and the MaterialChunk get activated but 
> not so the ShaderProgramChunk.
> 
> The poor man's idea with the shader is, that I can adapt the depth 
> buffer beside of the color buffer in the fragment shader.
> 
> Below you can find part of the example. Could you take a brief look? Is 
> shader code in the PolygonBackground forbidden generally? In case it 
> helps I can post or upload the complete example code.
> 
> 
> However, I would prefer some infrastructure that is easier to setup. 
> Maybe we could come up with a FancyBackground that takes a FBO and 
> manages the blitting (color, depth, stencil) internally. Especially, I 
> do not like a solution involving a shader in the first place.

that might be the best solution.

For your shader problem below, that is an old issue. It boils down to
shaders being cached during the traversal and remapped to a different
object. So the frontend objects does not do any actual OpenGL calls.
The easiest way around this is to use a SimpleSHLChunk instead if one
wants to activate the shader directly.

kind regards
  gerrit



--
Full-scale, agent-less Infrastructure Monitoring from a single dashboard
Integrate with 40+ ManageEngine ITSM Solutions for complete visibility
Physical-Virtual-Cloud Infrastructure monitoring from one console
Real user monitoring with APM Insights and performance trend reports 
Learn More http://pubads.g.doubleclick.net/gampad/clk?id=247754911=/4140
___
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users


Re: [Opensg-users] OpenSG 2: Setting up the depth buffer

2015-10-07 Thread Johannes
On 07.10.2015 14:52, Gerrit Voß wrote:
>
> For your shader problem below, ...
> The easiest way around this is to use a SimpleSHLChunk instead ...

I did not know about that one :-(

I took a look into the PassiveBackground implementation and it seems 
that it is quite near to what is needed here if I understand correctly.
If ClearFrameBufferObject is set and no ClearCallback is defined it does 
perform some blitting by

osgGlBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, 0)
osgGlBlitFramebuffer(
 pEnv->getPixelLeft (),
 pEnv->getPixelBottom(),
 pEnv->getPixelRight (),
 pEnv->getPixelTop (),
 pEnv->getPixelLeft (),
 pEnv->getPixelBottom(),
 pEnv->getPixelRight (),
 pEnv->getPixelTop (),
 (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT),
 GL_NEAREST);

osgGlBindFramebuffer(
 GL_READ_FRAMEBUFFER_EXT,
 win->getGLObjectId(pEnv->getActiveFBO()));


Am I correct that this blit from the main render buffer into the active FBO?


Assume that we store the FBO into the FancyBackground. How do we do the 
opposite blit operation?

glBindFramebuffer(GL_READ_FRAMEBUFFER, my_fbo);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);

glReadBuffer(GL_COLOR_ATTACHMENT0);
glDrawBuffer(GL_COLOR_ATTACHMENT0);

osgGlBlitFramebuffer(
 pEnv->getPixelLeft (),
 pEnv->getPixelBottom(),
 pEnv->getPixelRight (),
 pEnv->getPixelTop (),
 pEnv->getPixelLeft (),
 pEnv->getPixelBottom(),
 pEnv->getPixelRight (),
 pEnv->getPixelTop (),
 (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT),
 GL_NEAREST);

What is my_fbo actually, i.e. where do I get the id of the stored FBO?

I have no experience with GL framebuffer handling, so any hints are 
welcomed.

Best,
Johannes






--
Full-scale, agent-less Infrastructure Monitoring from a single dashboard
Integrate with 40+ ManageEngine ITSM Solutions for complete visibility
Physical-Virtual-Cloud Infrastructure monitoring from one console
Real user monitoring with APM Insights and performance trend reports 
Learn More http://pubads.g.doubleclick.net/gampad/clk?id=247754911=/4140
___
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users