[NUI] Split NUI Interop class (#804)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / TextureSet.cs
1 /*
2  * Copyright(c) 2017 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     /// <summary>
23     /// TextureSet is a handle to an object that specifies the set of images used as textures by a renderer.<br />
24     /// The images have to be ordered in the same order they are declared in the shader.
25     /// </summary>
26     /// <since_tizen> 3 </since_tizen>
27     public class TextureSet : BaseHandle
28     {
29         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
30
31         /// <summary>
32         /// Create an instance of TextureSet.
33         /// </summary>
34         /// <since_tizen> 3 </since_tizen>
35         public TextureSet() : this(Interop.TextureSet.TextureSet_New(), true)
36         {
37             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
38
39         }
40
41         internal TextureSet(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.TextureSet.TextureSet_SWIGUpcast(cPtr), cMemoryOwn)
42         {
43             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
44         }
45
46         /// <summary>
47         /// Sets the texture at position "index".
48         /// </summary>
49         /// <param name="index">The position in the texture set of the texture.</param>
50         /// <param name="texture">The texture.</param>
51         /// <since_tizen> 3 </since_tizen>
52         public void SetTexture(uint index, Texture texture)
53         {
54             Interop.TextureSet.TextureSet_SetTexture(swigCPtr, index, Texture.getCPtr(texture));
55             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
56         }
57
58         /// <summary>
59         /// Gets the image at position "index".
60         /// </summary>
61         /// <param name="index">The position in the texture set of the image.</param>
62         /// <returns>A handle to the image at the the specified position.</returns>
63         /// <since_tizen> 3 </since_tizen>
64         public Texture GetTexture(uint index)
65         {
66             //to fix memory leak issue, match the handle count with native side.
67             System.IntPtr cPtr = Interop.TextureSet.TextureSet_GetTexture(swigCPtr, index);
68             HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
69             Texture ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as Texture;
70             if (cPtr != null && ret == null)
71             {
72                 ret = new Texture(cPtr, false);
73                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
74                 return ret;
75             }
76             Interop.BaseHandle.delete_BaseHandle(CPtr);
77             CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
78
79             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
80             return ret;
81         }
82
83         /// <summary>
84         /// Sets the sampler to be used by the image at position "index".
85         /// </summary>
86         /// <param name="index">The position in the texture set of the image.</param>
87         /// <param name="sampler">The sampler to use.</param>
88         /// <since_tizen> 3 </since_tizen>
89         public void SetSampler(uint index, Sampler sampler)
90         {
91             Interop.TextureSet.TextureSet_SetSampler(swigCPtr, index, Sampler.getCPtr(sampler));
92             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
93         }
94
95         /// <summary>
96         /// Sets the sampler to be used by the image at position "index".
97         /// </summary>
98         /// <param name="index">The position in the texture set of the image.</param>
99         /// <returns>A handle to the sampler at the specified position.</returns>
100         /// <since_tizen> 3 </since_tizen>
101         public Sampler GetSampler(uint index)
102         {
103             //to fix memory leak issue, match the handle count with native side.
104             System.IntPtr cPtr = Interop.TextureSet.TextureSet_GetSampler(swigCPtr, index);
105             HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
106             Sampler ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as Sampler;
107             Interop.BaseHandle.delete_BaseHandle(CPtr);
108             CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
109
110             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
111             return ret;
112         }
113
114         /// <summary>
115         /// Gets the number of textures present in the TextureSet.
116         /// </summary>
117         /// <returns>The number of textures in the TextureSet.</returns>
118         /// <since_tizen> 3 </since_tizen>
119         public uint GetTextureCount()
120         {
121             uint ret = Interop.TextureSet.TextureSet_GetTextureCount(swigCPtr);
122             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
123             return ret;
124         }
125
126         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TextureSet obj)
127         {
128             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
129         }
130
131         /// <summary>
132         /// Dispose.
133         /// </summary>
134         /// <since_tizen> 3 </since_tizen>
135         protected override void Dispose(DisposeTypes type)
136         {
137             if (disposed)
138             {
139                 return;
140             }
141
142             if (type == DisposeTypes.Explicit)
143             {
144                 //Called by User
145                 //Release your own managed resources here.
146                 //You should release all of your own disposable objects here.
147
148             }
149
150             //Release your own unmanaged resources here.
151             //You should not access any managed member here except static instance.
152             //because the execution order of Finalizes is non-deterministic.
153
154             if (swigCPtr.Handle != global::System.IntPtr.Zero)
155             {
156                 if (swigCMemOwn)
157                 {
158                     swigCMemOwn = false;
159                     Interop.TextureSet.delete_TextureSet(swigCPtr);
160                 }
161                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
162             }
163
164             base.Dispose(type);
165         }
166     }
167
168 }