1 // Created on: 2021-01-15
2 // Copyright (c) 2021 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <OpenGl_ArbFBO.hxx>
16 #include <OpenGl_DepthPeeling.hxx>
18 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_DepthPeeling, OpenGl_NamedResource)
20 //=======================================================================
21 // function : OpenGl_DepthPeeling
23 //=======================================================================
24 OpenGl_DepthPeeling::OpenGl_DepthPeeling()
25 : OpenGl_NamedResource ("depth_peeling")
27 myDepthPeelFbosOit[0] = new OpenGl_FrameBuffer();
28 myDepthPeelFbosOit[1] = new OpenGl_FrameBuffer();
29 myFrontBackColorFbosOit[0] = new OpenGl_FrameBuffer();
30 myFrontBackColorFbosOit[1] = new OpenGl_FrameBuffer();
31 myBlendBackFboOit = new OpenGl_FrameBuffer();
34 // =======================================================================
35 // function : ~OpenGl_DepthPeeling
37 // =======================================================================
38 OpenGl_DepthPeeling::~OpenGl_DepthPeeling()
43 //=======================================================================
46 //=======================================================================
47 void OpenGl_DepthPeeling::Release (OpenGl_Context* theCtx)
49 myDepthPeelFbosOit[0] ->Release (theCtx);
50 myDepthPeelFbosOit[1] ->Release (theCtx);
51 myFrontBackColorFbosOit[0]->Release (theCtx);
52 myFrontBackColorFbosOit[1]->Release (theCtx);
53 myBlendBackFboOit ->Release (theCtx);
56 //=======================================================================
57 // function : EstimatedDataSize
59 //=======================================================================
60 Standard_Size OpenGl_DepthPeeling::EstimatedDataSize() const
62 return myDepthPeelFbosOit[0]->EstimatedDataSize()
63 + myDepthPeelFbosOit[1]->EstimatedDataSize()
64 + myFrontBackColorFbosOit[0]->EstimatedDataSize()
65 + myFrontBackColorFbosOit[1]->EstimatedDataSize()
66 + myBlendBackFboOit->EstimatedDataSize();
69 //=======================================================================
70 // function : AttachDepthTexture
72 //=======================================================================
73 void OpenGl_DepthPeeling::AttachDepthTexture (const Handle(OpenGl_Context)& theCtx,
74 const Handle(OpenGl_Texture)& theDepthStencilTexture)
76 if (!theDepthStencilTexture.IsNull()
77 && theDepthStencilTexture->IsValid())
79 for (int aPairIter = 0; aPairIter < 2; ++aPairIter)
81 myDepthPeelFbosOit[aPairIter]->BindBuffer (theCtx);
82 theCtx->arbFBO->glFramebufferTexture2D (GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
83 theDepthStencilTexture->GetTarget(),
84 theDepthStencilTexture->TextureId(), 0);
85 myDepthPeelFbosOit[aPairIter]->UnbindBuffer (theCtx);
90 //=======================================================================
91 // function : DetachDepthTexture
93 //=======================================================================
94 void OpenGl_DepthPeeling::DetachDepthTexture (const Handle(OpenGl_Context)& theCtx)
96 if (!myDepthPeelFbosOit[0]->DepthStencilTexture().IsNull())
98 for (int aPairIter = 0; aPairIter < 2; ++aPairIter)
100 myDepthPeelFbosOit[aPairIter]->BindBuffer (theCtx);
101 theCtx->arbFBO->glFramebufferTexture2D (GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
102 myDepthPeelFbosOit[aPairIter]->DepthStencilTexture()->GetTarget(),
104 myDepthPeelFbosOit[aPairIter]->UnbindBuffer (theCtx);