[NUI] Refactor dispose pattern to reduce duplication (#1112)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / FrameBuffer.cs
1 /*
2  * Copyright(c) 2019 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 using System.Runtime.InteropServices;
19
20 namespace Tizen.NUI
21 {
22     internal class FrameBuffer : BaseHandle
23     {
24
25         internal FrameBuffer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.FrameBuffer.FrameBuffer_SWIGUpcast(cPtr), cMemoryOwn)
26         {
27         }
28
29         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FrameBuffer obj)
30         {
31             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
32         }
33
34         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
35         {
36             Interop.FrameBuffer.delete_FrameBuffer(swigCPtr);
37         }
38
39         /// <since_tizen> 3 </since_tizen>
40         public class Attachment
41         {
42             /// <since_tizen> 3 </since_tizen>
43             public enum Mask
44             {
45                 NONE = 0,
46                 DEPTH = 1 << 0,
47                 STENCIL = 1 << 1,
48                 DEPTH_STENCIL = DEPTH | STENCIL
49             }
50         }
51
52         public FrameBuffer(uint width, uint height, uint attachments) : this(Interop.FrameBuffer.FrameBuffer_New(width, height, attachments), true)
53         {
54             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
55
56         }
57
58         public void AttachColorTexture(Texture texture)
59         {
60             Interop.FrameBuffer.FrameBuffer_AttachColorTexture__SWIG_0(swigCPtr, Texture.getCPtr(texture));
61             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
62         }
63
64         public void AttachColorTexture(Texture texture, uint mipmapLevel, uint layer)
65         {
66             Interop.FrameBuffer.FrameBuffer_AttachColorTexture__SWIG_1(swigCPtr, Texture.getCPtr(texture), mipmapLevel, layer);
67             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
68         }
69
70         public Texture GetColorTexture()
71         {
72             //to fix memory leak issue, match the handle count with native side.
73             global::System.IntPtr cPtr = Interop.FrameBuffer.FrameBuffer_GetColorTexture(swigCPtr);
74             Texture ret = this.GetInstanceSafely<Texture>(cPtr);
75             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
76             return ret;
77         }
78     }
79 }