1313#include < OpenGl_View.hxx>
1414#include < OpenGl_Window.hxx>
1515
16+ // ! OpenGL FBO subclass for wrapping FBO created by Qt using GL_RGBA8
17+ // ! texture format instead of GL_SRGB8_ALPHA8.
18+ // ! This FBO is set to OpenGl_Context::SetDefaultFrameBuffer() as a final target.
19+ // ! Subclass calls OpenGl_Context::SetFrameBufferSRGB() with sRGB=false flag,
20+ // ! which asks OCCT to disable GL_FRAMEBUFFER_SRGB and apply sRGB gamma correction manually.
21+ class OcctQtFrameBuffer : public OpenGl_FrameBuffer
22+ {
23+ DEFINE_STANDARD_RTTI_INLINE (OcctQtFrameBuffer, OpenGl_FrameBuffer)
24+ public:
25+ // ! Empty constructor.
26+ OcctQtFrameBuffer () {}
27+
28+ // ! Make this FBO active in context.
29+ virtual void BindBuffer (const Handle (OpenGl_Context)& theGlCtx) override
30+ {
31+ OpenGl_FrameBuffer::BindBuffer (theGlCtx);
32+ theGlCtx->SetFrameBufferSRGB (true , false );
33+ }
34+
35+ // ! Make this FBO as drawing target in context.
36+ virtual void BindDrawBuffer (const Handle (OpenGl_Context)& theGlCtx) override
37+ {
38+ OpenGl_FrameBuffer::BindDrawBuffer (theGlCtx);
39+ theGlCtx->SetFrameBufferSRGB (true , false );
40+ }
41+
42+ // ! Make this FBO as reading source in context.
43+ virtual void BindReadBuffer (const Handle (OpenGl_Context)& theGlCtx) override
44+ {
45+ OpenGl_FrameBuffer::BindReadBuffer (theGlCtx);
46+ }
47+ };
48+
1649// ================================================================
1750// Function : GetGlContext
1851// ================================================================
@@ -23,18 +56,27 @@ Handle(OpenGl_Context) OcctGlTools::GetGlContext(const Handle(V3d_View)& theView
2356}
2457
2558// ================================================================
26- // Function : InitializeGlWindow
59+ // Function : GetGlNativeWindow
2760// ================================================================
28- bool OcctGlTools::InitializeGlWindow (const Handle (V3d_View)& theView,
29- const Aspect_Drawable theNativeWin,
30- const Graphic3d_Vec2i& theSize)
61+ Aspect_Drawable OcctGlTools::GetGlNativeWindow (Aspect_Drawable theNativeWin)
3162{
32- Aspect_Drawable aNativeWin = theNativeWin;
63+ Aspect_Drawable aNativeWin = (Aspect_Drawable) theNativeWin;
3364#ifdef _WIN32
3465 HDC aWglDevCtx = wglGetCurrentDC ();
3566 HWND aWglWin = WindowFromDC (aWglDevCtx);
3667 aNativeWin = (Aspect_Drawable)aWglWin;
3768#endif
69+ return aNativeWin;
70+ }
71+
72+ // ================================================================
73+ // Function : InitializeGlWindow
74+ // ================================================================
75+ bool OcctGlTools::InitializeGlWindow (const Handle (V3d_View)& theView,
76+ const Aspect_Drawable theNativeWin,
77+ const Graphic3d_Vec2i& theSize)
78+ {
79+ const Aspect_Drawable aNativeWin = GetGlNativeWindow (theNativeWin);
3880
3981 Handle (OpenGl_GraphicDriver) aDriver = Handle (OpenGl_GraphicDriver)::DownCast (theView->Viewer ()->Driver ());
4082 Handle (OpenGl_Context) aGlCtx = new OpenGl_Context ();
@@ -62,6 +104,46 @@ bool OcctGlTools::InitializeGlWindow(const Handle(V3d_View)& theView,
62104 return true ;
63105}
64106
107+ // ================================================================
108+ // Function : InitializeGlFbo
109+ // ================================================================
110+ bool OcctGlTools::InitializeGlFbo (const Handle (V3d_View)& theView)
111+ {
112+ Handle (OpenGl_Context) aGlCtx = OcctGlTools::GetGlContext (theView);
113+ Handle (OpenGl_FrameBuffer) aDefaultFbo = aGlCtx->DefaultFrameBuffer ();
114+ if (aDefaultFbo.IsNull ())
115+ {
116+ aDefaultFbo = new OcctQtFrameBuffer ();
117+ aGlCtx->SetDefaultFrameBuffer (aDefaultFbo);
118+ }
119+ if (!aDefaultFbo->InitWrapper (aGlCtx))
120+ {
121+ aDefaultFbo.Nullify ();
122+ Message::DefaultMessenger ()->Send (" Default FBO wrapper creation failed" , Message_Fail);
123+ return false ;
124+ }
125+
126+ Graphic3d_Vec2i aViewSizeOld;
127+ const Graphic3d_Vec2i aViewSizeNew = aDefaultFbo->GetVPSize ();
128+ Handle (Aspect_NeutralWindow) aWindow = Handle (Aspect_NeutralWindow)::DownCast (theView->Window ());
129+ aWindow->Size (aViewSizeOld.x (), aViewSizeOld.y ());
130+ if (aViewSizeNew != aViewSizeOld)
131+ {
132+ aWindow->SetSize (aViewSizeNew.x (), aViewSizeNew.y ());
133+ theView->MustBeResized ();
134+ theView->Invalidate ();
135+ #if (OCC_VERSION_HEX >= 0x070700)
136+ for (const Handle (V3d_View)& aSubviewIter : theView->Subviews ())
137+ {
138+ aSubviewIter->MustBeResized ();
139+ aSubviewIter->Invalidate ();
140+ aDefaultFbo->SetupViewport (aGlCtx);
141+ }
142+ #endif
143+ }
144+ return true ;
145+ }
146+
65147// ================================================================
66148// Function : ResetGlStateBeforeOcct
67149// ================================================================
0 commit comments