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