Horde3D

Next-Generation Graphics Engine
It is currently 21.11.2024, 19:55

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: 13.03.2014, 15:33 
Offline

Joined: 28.12.2013, 22:53
Posts: 5
I wanted to add an option to enable multisampling in the sample applications, but run into issues.

First let me give some links about the subject:

To enable multisampling, you have to do following things:
    Set the engine option: `h3dSetOption( H3DOptions::SampleCount, 8 );`
    Have a pipeline that supports multisampling

Currently, only the "HDR" pipeline supports multisampling.

I'm would like to enable multisampling for the forward pipeline. Reading the wiki and source code, it seems that you are forced to render in a separate FBO, do the resolve in another FBO and finally copy the image to the default FBO (window). This looks like a waste of buffer space and could cause issues on lower end card with little memory. I tried create a default FBO with multisampling (using `glfwWindowHint( GLFW_SAMPLES, 8 );`), but run into issues that Horde3D doesn't support multisampling on the default FBO.

My question is: Is the description given above correct or did I miss something? Does it make sense to add multisampling support for the default FBO?


Top
 Profile  
Reply with quote  
PostPosted: 13.03.2014, 16:36 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
You're right that this is still an issue. For default framebuffer like in the forwardpipeline there is currently no way to specify that you want multisampling to be activated. So the default will be applied and default means in case of Horde3D to disable multisampling by calling glDisable( GL_MULTISAMPLE ); in RenderDevice::setRenderBuffer( uint32 rbObj ).

This is IMHO not ideal. Maybe we should change this by querying the multisample state in RenderDevice::initStates() and use that state in setRenderBuffer().
Another way would be to query it everytime in beginRendering() but that would be proably to much as I guess even if you use other rendering libraries too, they won't change the multisampling state all the time.


Top
 Profile  
Reply with quote  
PostPosted: 14.03.2014, 10:12 
Offline

Joined: 08.01.2008, 14:57
Posts: 66
+1 for the first solution.


Top
 Profile  
Reply with quote  
PostPosted: 21.03.2014, 13:29 
Offline

Joined: 28.12.2013, 22:53
Posts: 5
Thanks for your comments. I did a patch following this guideline:
Quote:
querying the multisample state in RenderDevice::initStates() and use that state in setRenderBuffer()


The modifications to the samples are based on the new sample framework of zuck, so I will wait until the sample framework reaches the develop branch to send the pull request. In the meantime, please review the core patch below:

Code:
 Horde3D/Source/Horde3DEngine/egRendererBase.cpp | 7 ++++++-
 Horde3D/Source/Horde3DEngine/egRendererBase.h   | 1 +
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/Horde3D/Source/Horde3DEngine/egRendererBase.cpp b/Horde3D/Source/Horde3DEngine/egRendererBase.cpp
index 404e424..8624a50 100644
--- a/Horde3D/Source/Horde3DEngine/egRendererBase.cpp
+++ b/Horde3D/Source/Horde3DEngine/egRendererBase.cpp
@@ -153,6 +153,7 @@ RenderDevice::RenderDevice()
    _curVertLayout = _newVertLayout = 0;
    _curIndexBuf = _newIndexBuf = 0;
    _defaultFBO = 0;
+    _defaultFBOMultisampled = false;
    _indexFormat = (uint32)IDXFMT_16;
    _pendingMask = 0;
 }
@@ -166,6 +167,9 @@ RenderDevice::~RenderDevice()
 void RenderDevice::initStates()
 {
    glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
+    GLint value;
+    glGetIntegerv( GL_SAMPLE_BUFFERS, &value );
+    _defaultFBOMultisampled = value > 0;
 }
 
 
@@ -1030,7 +1034,8 @@ void RenderDevice::setRenderBuffer( uint32 rbObj )
       if( _defaultFBO == 0 ) glDrawBuffer( _outputBufferIndex == 1 ? GL_BACK_RIGHT : GL_BACK_LEFT );
       _fbWidth = _vpWidth + _vpX;
       _fbHeight = _vpHeight + _vpY;
-      glDisable( GL_MULTISAMPLE );
+        if( _defaultFBOMultisampled ) glEnable( GL_MULTISAMPLE );
+      else glDisable( GL_MULTISAMPLE );
    }
    else
    {
diff --git a/Horde3D/Source/Horde3DEngine/egRendererBase.h b/Horde3D/Source/Horde3DEngine/egRendererBase.h
index 136b2aa..52cfdbc 100644
--- a/Horde3D/Source/Horde3DEngine/egRendererBase.h
+++ b/Horde3D/Source/Horde3DEngine/egRendererBase.h
@@ -588,6 +588,7 @@ protected:
    uint32        _textureMem, _bufferMem;
 
    int                            _defaultFBO;
+    bool                           _defaultFBOMultisampled;
    uint32                         _numVertexLayouts;
    RDIVertexLayout                _vertexLayouts[MaxNumVertexLayouts];
    RDIObjects< RDIBuffer >        _buffers;


Top
 Profile  
Reply with quote  
PostPosted: 21.03.2014, 19:30 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
Looks good to me (without having tested it)


Top
 Profile  
Reply with quote  
PostPosted: 25.03.2014, 15:23 
Offline

Joined: 08.01.2008, 14:57
Posts: 66
Yeah, the patch looks good also to me.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 20 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group