MantisBT
Mantis Bug Tracker Workflow

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0031964Community[OCCT] OCCT:Visualizationpublic2020-11-28 09:442020-12-22 18:46
ReporterVico Liang 
Assigned Tokgv 
PrioritynormalSeverityfeature 
StatusnewResolutionopen 
PlatformOSOS Version
Product Version 
Target Version[OCCT] 7.6.0*Fixed in Version 
Summary0031964: Visualization, TKOpenGl - add option to disable background color filling for external render buffer
DescriptionThere is a user case to render directly to external buffer as an overlay. This feature requires not clear color buffer, depth buffer, stencil buffer, etc. Is it possible to add options?
TagsNo tags attached.
Test case number
Attached Filespng file icon FBO-changes status.png (81,726 bytes) 2020-12-02 05:25

- Relationships
related to 0031988feedbackkgv Community Visualization - use Quantity_ColorRGBA as background rather than Quantity_Color to support alpha channel 
related to 0031597verifiedbugmaster Open CASCADE Visualization, TKOpenGl - allow disabling Alpha component writes within OpenGl_Context::ColorMask() 

-  Notes
(0097113)
kgv (developer)
2020-11-28 11:07
edited on: 2020-11-28 11:12

Vico,

current rendering pipeline including rendering into additional off-screen buffers and blitting result image into window buffer or into another off-screen buffer. In such pipeline, not clearing a temporary off-screen buffer would produce just undefined results on a screen while blitting image from a temporary to another buffer as currently there are no options to copy only portions of the image or define copy criteria.

OCCT renderer is commonly used as first render layer (e.g. it fills in image as background, which can be augmented by external renderer) when combined with another renderer. Combination in opposite order should be also technically possible, but it would require thoughtful alterings to OCCT renderer, which couldn't be easily verified without real use case of two combined renderers. Hence, I would rather avoid trying to make any blind patches to OCCT just adding options like not clearing color or depth buffer without being able to confirm that these flags actually help in real-world use case.

The most straight-forward approach I can imagine is assigning an off-screen FBO to OpenGl_View::SetFBO() - which could be either a wrapper to an off-screen buffer used by another renderer (like
QOpenGLFramebufferObject/
QOpenGLWidget), or something different and disabling OpenGl_View::SetImmediateModeDrawToFront() in a similar way as V3d_View::ToPixMap() does for making an off-screen image dump (this disables usage of additional FBOs by OCCT renderer).

The experiments with non-clearing buffer could be done without patching OCCT.
First clearing is done within OpenGl_View::redraw() method before calling OpenGl_View::render(), which are virtual methods, so that application may override OpenGl_View::redraw() to skip clearing the buffer.

(0097145)
Vico Liang (developer)
2020-11-28 18:01

Dear KGV, Thanks for the details. I'll try it as your options and let you know the result.
(0097146)
Vico Liang (developer)
2020-11-30 03:25

Dear KGV,

I'd like to ask a question about the two redraw fucntios : RedrawImmediate() and Redraw() which one should be used when filling the externl render buffer? The app has immediate layers, to gain better performance, shall i use RedrawImmediate rather than Redraw()?

Thanks.
(0097158)
kgv (developer)
2020-11-30 12:35

Both Redraw() and RedrawImmediate() are called by normal OCCT application (Redraw() is called first, then RedrawImmediate() is called while moving mouse for dynamic highlighting, then Redraw() again when camera position changes or when changing scene content).

AIS_ViewController::handleViewRedraw() decides which to call basing on V3d_View::IsInvalidated() state, so that other AIS_ViewController methods modifying the scene call V3d_View::Invalidate().
(0097177)
Vico Liang (developer)
2020-11-30 17:47

OK, your explaination is really helpful for me to understand the background of redraw logic. Thank you so much for your time.
(0097228)
Vico Liang (developer)
2020-12-02 05:17
edited on: 2020-12-02 05:36

Dear Kirill,

I found an issue when using the QOpenGLFramebufferObject item as OCCT FBO. OCCT will changes the opengl context inside QT and it can't be recovered with function call QQuickWindow::resetOpenGLState(). After returning from OCCT FBO rendering, the whole QT screen will become a little darker.

I have tried that on windows 10 with vs2017. I'm trying to use the underlay mode without chaning anything of OCCT. I uploaded the pictures. Coule you please help to look at this? Is there a way to restore to the original status after FBO rendering?

Thanks.

(0097295)
Vico Liang (developer)
2020-12-04 08:50

Dear Kirill,

I found an issue when using QOpenGLFramebufferObject as external FBO. The color attachment type is not GL_RENDERBUFFER, the type is GL_TEXTURE. The below function will generate an error: "OpenGl_FrameBuffer::InitWrapper(), color attachment of unsupported type has been skipped!"

OpenGl_FrameBuffer::InitWrapper (const Handle(OpenGl_Context)& theGlCtx)
{
    
  // VICO NOTE: (aColorType == GL_TEXTURE)
  if (aColorType == GL_RENDERBUFFER)
  {
    theGlCtx->arbFBO->glGetFramebufferAttachmentParameteriv (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &aColorId);
    myGlColorRBufferId = aColorId;
  }
  else if (aColorType != GL_NONE)
  {
    TCollection_ExtendedString aMsg = "OpenGl_FrameBuffer::InitWrapper(), color attachment of unsupported type has been skipped!";
    theGlCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION,
                           GL_DEBUG_TYPE_ERROR,
                           0,
                           GL_DEBUG_SEVERITY_HIGH,
                           aMsg);
  }
(0097843)
Vico Liang (developer)
2020-12-21 18:18

The root cause is that OCCT changed the flag: GL_FRAMEBUFFER_SRGB
(0097848)
kgv (developer)
2020-12-21 19:50

If you mean "glEnable (GL_FRAMEBUFFER_SRGB);" then how it could affect "OpenGl_FrameBuffer::InitWrapper()"?
(0097854)
Vico Liang (developer)
2020-12-22 03:03

>>If you mean "glEnable (GL_FRAMEBUFFER_SRGB);" then how it could affect "OpenGl_FrameBuffer::InitWrapper()"?
No, "glEnable (GL_FRAMEBUFFER_SRGB)" will not affect "OpenGl_FrameBuffer::InitWrapper()". "aColorType == GL_TEXTURE" in function "OpenGl_FrameBuffer::InitWrapper()" is not handled properly which will post an error message.

I mean flag GL_FRAMEBUFFER_SRGB is changed to enabled after rendering to QOpenGLFramebufferObject. It's better to restore this flag after rendering.
(0097860)
kgv (developer)
2020-12-22 10:59
edited on: 2020-12-22 11:00

Dear Vico,

> I mean flag GL_FRAMEBUFFER_SRGB is changed to enabled after rendering to QOpenGLFramebufferObject.
> It's better to restore this flag after rendering.
OCCT 3D Viewer is unaware of any expectations of OpenGL state of external engine.
The other engine might rely on GL_FRAMEBUFFER_SRGB for proper rendering or do not handle it well - both cases are possible, and the first one is more natural when combined with OCCT 3D Viewer.

Therefore, disabling GL_FRAMEBUFFER_SRGB should be done at application level at the place returning control over OpenGL context rendering from OCCT 3D Viewer to other engine.

void viewerRestoreGlState (const Handle(OpenGl_GraphicDriver)& theDriver)
{
  const Handle(OpenGl_Context)& aGlCtx = theDriver->GetSharedContext();
  if (aGlCtx->core15fwd != nullptr)
  {
    aGlCtx->core15fwd->glActiveTexture (GL_TEXTURE0);
  }
  if (aGlCtx->hasSRGBControl)
  {
    aGlCtx->core11fwd->glDisable (GL_FRAMEBUFFER_SRGB);
  }
  ::glPixelStorei (GL_PACK_ALIGNMENT,   4);
  ::glPixelStorei (GL_UNPACK_ALIGNMENT, 4);
}


(0097869)
Vico Liang (developer)
2020-12-22 18:46

Dear Kirill,

Thanks so much for your hint. I will use the function as your provided to restore the openGL state after rendering. It's a great help for me.

- Issue History
Date Modified Username Field Change
2020-11-28 09:44 Vico Liang New Issue
2020-11-28 09:44 Vico Liang Assigned To => kgv
2020-11-28 11:07 kgv Note Added: 0097113
2020-11-28 11:07 kgv Severity minor => feature
2020-11-28 11:07 kgv Summary Add option to disable background color filling for external render buffer => Visualization, TKOpenGl - add option to disable background color filling for external render buffer
2020-11-28 11:08 kgv Note Edited: 0097113 View Revisions
2020-11-28 11:09 kgv Note Edited: 0097113 View Revisions
2020-11-28 11:10 kgv Note Edited: 0097113 View Revisions
2020-11-28 11:12 kgv Note Edited: 0097113 View Revisions
2020-11-28 18:01 Vico Liang Note Added: 0097145
2020-11-30 03:25 Vico Liang Note Added: 0097146
2020-11-30 12:35 kgv Note Added: 0097158
2020-11-30 17:47 Vico Liang Note Added: 0097177
2020-12-02 05:17 Vico Liang Note Added: 0097228
2020-12-02 05:25 Vico Liang File Added: FBO-changes status.png
2020-12-02 05:36 Vico Liang Note Edited: 0097228 View Revisions
2020-12-04 08:50 Vico Liang Note Added: 0097295
2020-12-21 15:18 kgv Relationship added related to 0031988
2020-12-21 15:18 kgv Relationship added related to 0031597
2020-12-21 18:18 Vico Liang Note Added: 0097843
2020-12-21 19:50 kgv Note Added: 0097848
2020-12-22 03:03 Vico Liang Note Added: 0097854
2020-12-22 10:59 kgv Note Added: 0097860
2020-12-22 10:59 kgv Note Edited: 0097860 View Revisions
2020-12-22 11:00 kgv Note Edited: 0097860 View Revisions
2020-12-22 11:00 kgv Note Edited: 0097860 View Revisions
2020-12-22 18:46 Vico Liang Note Added: 0097869


Copyright © 2000 - 2021 MantisBT Team
Powered by Mantis Bugtracker