[NUI] TCSACR-226 code change (#1032)
[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         internal TextureSet(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.TextureSet.TextureSet_SWIGUpcast(cPtr), cMemoryOwn)
41         {
42             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
43         }
44
45         /// <summary>
46         /// Sets the texture at position "index".
47         /// </summary>
48         /// <param name="index">The position in the texture set of the texture.</param>
49         /// <param name="texture">The texture.</param>
50         /// <since_tizen> 3 </since_tizen>
51         public void SetTexture(uint index, Texture texture)
52         {
53             Interop.TextureSet.TextureSet_SetTexture(swigCPtr, index, Texture.getCPtr(texture));
54             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
55         }
56
57         /// <summary>
58         /// Gets the image at position "index".
59         /// </summary>
60         /// <param name="index">The position in the texture set of the image.</param>
61         /// <returns>A handle to the image at the the specified position.</returns>
62         /// <since_tizen> 3 </since_tizen>
63         public Texture GetTexture(uint index)
64         {
65             //to fix memory leak issue, match the handle count with native side.
66             System.IntPtr cPtr = Interop.TextureSet.TextureSet_GetTexture(swigCPtr, index);
67             HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
68             Texture ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as Texture;
69             if (cPtr != null && ret == null)
70             {
71                 ret = new Texture(cPtr, false);
72                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
73                 return ret;
74             }
75             Interop.BaseHandle.delete_BaseHandle(CPtr);
76             CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
77
78             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
79             return ret;
80         }
81
82         /// <summary>
83         /// Sets the sampler to be used by the image at position "index".
84         /// </summary>
85         /// <param name="index">The position in the texture set of the image.</param>
86         /// <param name="sampler">The sampler to use.</param>
87         /// <since_tizen> 3 </since_tizen>
88         public void SetSampler(uint index, Sampler sampler)
89         {
90             Interop.TextureSet.TextureSet_SetSampler(swigCPtr, index, Sampler.getCPtr(sampler));
91             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
92         }
93
94         /// <summary>
95         /// Sets the sampler to be used by the image at position "index".
96         /// </summary>
97         /// <param name="index">The position in the texture set of the image.</param>
98         /// <returns>A handle to the sampler at the specified position.</returns>
99         /// <since_tizen> 3 </since_tizen>
100         public Sampler GetSampler(uint index)
101         {
102             //to fix memory leak issue, match the handle count with native side.
103             System.IntPtr cPtr = Interop.TextureSet.TextureSet_GetSampler(swigCPtr, index);
104             HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
105             Sampler ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as Sampler;
106             Interop.BaseHandle.delete_BaseHandle(CPtr);
107             CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
108
109             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
110             return ret;
111         }
112
113         /// <summary>
114         /// Gets the number of textures present in the TextureSet.
115         /// </summary>
116         /// <returns>The number of textures in the TextureSet.</returns>
117         /// <since_tizen> 3 </since_tizen>
118         public uint GetTextureCount()
119         {
120             uint ret = Interop.TextureSet.TextureSet_GetTextureCount(swigCPtr);
121             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
122             return ret;
123         }
124
125         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TextureSet obj)
126         {
127             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
128         }
129
130         /// <summary>
131         /// Dispose.
132         /// </summary>
133         /// <since_tizen> 3 </since_tizen>
134         protected override void Dispose(DisposeTypes type)
135         {
136             if (disposed)
137             {
138                 return;
139             }
140
141             //Release your own unmanaged resources here.
142             //You should not access any managed member here except static instance.
143             //because the execution order of Finalizes is non-deterministic.
144
145             if (swigCPtr.Handle != global::System.IntPtr.Zero)
146             {
147                 if (swigCMemOwn)
148                 {
149                     swigCMemOwn = false;
150                     Interop.TextureSet.delete_TextureSet(swigCPtr);
151                 }
152                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
153             }
154
155             base.Dispose(type);
156         }
157     }
158 }