fc785ee8f17f04eec6a51b4520832f1fc0b0be5a
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Common / 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.ComponentModel;
19
20 namespace Tizen.NUI
21 {
22     /// This will be released at Tizen.NET API Level 6, so currently this would be used as inhouse API.
23     [EditorBrowsable(EditorBrowsableState.Never)]
24     public class FrameBuffer : BaseHandle
25     {
26
27         internal FrameBuffer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.FrameBuffer.Upcast(cPtr), cMemoryOwn)
28         {
29         }
30
31         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FrameBuffer obj)
32         {
33             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
34         }
35
36         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
37         {
38             Interop.FrameBuffer.DeleteFrameBuffer(swigCPtr);
39         }
40
41         /// <since_tizen> 3 </since_tizen>
42         public sealed class Attachment
43         {
44             /// <since_tizen> 3 </since_tizen>
45             public enum Mask
46             {
47                 NONE = 0,
48                 DEPTH = 1 << 0,
49                 STENCIL = 1 << 1,
50                 DEPTH_STENCIL = DEPTH | STENCIL
51             }
52         }
53
54         public FrameBuffer(uint width, uint height, uint attachments) : this(Interop.FrameBuffer.New(width, height, attachments), true)
55         {
56             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
57
58         }
59
60         public void AttachColorTexture(Texture texture)
61         {
62             Interop.FrameBuffer.AttachColorTexture(SwigCPtr, Texture.getCPtr(texture));
63             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
64         }
65
66         public void AttachColorTexture(Texture texture, uint mipmapLevel, uint layer)
67         {
68             Interop.FrameBuffer.AttachColorTexture(SwigCPtr, Texture.getCPtr(texture), mipmapLevel, layer);
69             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
70         }
71
72         public Texture GetColorTexture()
73         {
74             //to fix memory leak issue, match the handle count with native side.
75             global::System.IntPtr cPtr = Interop.FrameBuffer.GetColorTexture(SwigCPtr);
76             Texture ret = this.GetInstanceSafely<Texture>(cPtr);
77             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
78             return ret;
79         }
80     }
81 }