0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / OpenGl / OpenGl_DepthPeeling.cxx
1 // Created on: 2021-01-15
2 // Copyright (c) 2021 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
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.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #include <OpenGl_ArbFBO.hxx>
16 #include <OpenGl_DepthPeeling.hxx>
17
18 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_DepthPeeling, OpenGl_NamedResource)
19
20 //=======================================================================
21 // function : OpenGl_DepthPeeling
22 // purpose  :
23 //=======================================================================
24 OpenGl_DepthPeeling::OpenGl_DepthPeeling()
25 : OpenGl_NamedResource ("depth_peeling")
26 {
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();
32 }
33
34 // =======================================================================
35 // function : ~OpenGl_DepthPeeling
36 // purpose  :
37 // =======================================================================
38 OpenGl_DepthPeeling::~OpenGl_DepthPeeling()
39 {
40   Release (NULL);
41 }
42
43 //=======================================================================
44 // function : Release
45 // purpose  :
46 //=======================================================================
47 void OpenGl_DepthPeeling::Release (OpenGl_Context* theCtx)
48 {
49   myDepthPeelFbosOit[0]     ->Release (theCtx);
50   myDepthPeelFbosOit[1]     ->Release (theCtx);
51   myFrontBackColorFbosOit[0]->Release (theCtx);
52   myFrontBackColorFbosOit[1]->Release (theCtx);
53   myBlendBackFboOit         ->Release (theCtx);
54 }
55
56 //=======================================================================
57 // function : EstimatedDataSize
58 // purpose  :
59 //=======================================================================
60 Standard_Size OpenGl_DepthPeeling::EstimatedDataSize() const
61 {
62   return myDepthPeelFbosOit[0]->EstimatedDataSize()
63        + myDepthPeelFbosOit[1]->EstimatedDataSize()
64        + myFrontBackColorFbosOit[0]->EstimatedDataSize()
65        + myFrontBackColorFbosOit[1]->EstimatedDataSize()
66        + myBlendBackFboOit->EstimatedDataSize();
67 }
68
69 //=======================================================================
70 // function : AttachDepthTexture
71 // purpose  :
72 //=======================================================================
73 void OpenGl_DepthPeeling::AttachDepthTexture (const Handle(OpenGl_Context)& theCtx,
74                                               const Handle(OpenGl_Texture)& theDepthStencilTexture)
75 {
76   if (!theDepthStencilTexture.IsNull()
77     && theDepthStencilTexture->IsValid())
78   {
79     for (int aPairIter = 0; aPairIter < 2; ++aPairIter)
80     {
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);
86     }
87   }
88 }
89
90 //=======================================================================
91 // function : DetachDepthTexture
92 // purpose  :
93 //=======================================================================
94 void OpenGl_DepthPeeling::DetachDepthTexture (const Handle(OpenGl_Context)& theCtx)
95 {
96   if (!myDepthPeelFbosOit[0]->DepthStencilTexture().IsNull())
97   {
98     for (int aPairIter = 0; aPairIter < 2; ++aPairIter)
99     {
100       myDepthPeelFbosOit[aPairIter]->BindBuffer (theCtx);
101       theCtx->arbFBO->glFramebufferTexture2D (GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
102                                               myDepthPeelFbosOit[aPairIter]->DepthStencilTexture()->GetTarget(),
103                                               0, 0);
104       myDepthPeelFbosOit[aPairIter]->UnbindBuffer (theCtx);
105     }
106   }
107 }