[NUI] Fix some incorrect implements when we get Texture relative items
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Rendering / TextureSet.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 using System.ComponentModel;
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
30         /// <summary>
31         /// Create an instance of TextureSet.
32         /// </summary>
33         /// <since_tizen> 3 </since_tizen>
34         public TextureSet() : this(Interop.TextureSet.New(), true)
35         {
36             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
37         }
38
39         internal TextureSet(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
40         {
41         }
42
43         /// <summary>
44         /// Sets the texture at position "index".
45         /// </summary>
46         /// <param name="index">The position in the texture set of the texture.</param>
47         /// <param name="texture">The texture.</param>
48         /// <since_tizen> 3 </since_tizen>
49         public void SetTexture(uint index, Texture texture)
50         {
51             Interop.TextureSet.SetTexture(SwigCPtr, index, Texture.getCPtr(texture));
52             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
53         }
54
55         /// <summary>
56         /// Gets the image at position "index".
57         /// </summary>
58         /// <param name="index">The position in the texture set of the image.</param>
59         /// <returns>A handle to the image at the specified position.</returns>
60         /// <since_tizen> 3 </since_tizen>
61         public Texture GetTexture(uint index)
62         {
63             global::System.IntPtr cPtr = Interop.TextureSet.GetTexture(SwigCPtr, index);
64             Texture ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Texture;
65             if (ret != null)
66             {
67                 Interop.BaseHandle.DeleteBaseHandle(new global::System.Runtime.InteropServices.HandleRef(this, cPtr));
68             }
69             else
70             {
71                 ret = new Texture(cPtr, true);
72             }
73             NDalicPINVOKE.ThrowExceptionIfExists();
74             return ret;
75         }
76
77         /// <summary>
78         /// Sets the sampler to be used by the image at position "index".
79         /// </summary>
80         /// <param name="index">The position in the texture set of the image.</param>
81         /// <param name="sampler">The sampler to use.</param>
82         /// <since_tizen> 3 </since_tizen>
83         public void SetSampler(uint index, Sampler sampler)
84         {
85             Interop.TextureSet.SetSampler(SwigCPtr, index, Sampler.getCPtr(sampler));
86             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
87         }
88
89         /// <summary>
90         /// Sets the sampler to be used by the image at position "index".
91         /// </summary>
92         /// <param name="index">The position in the texture set of the image.</param>
93         /// <returns>A handle to the sampler at the specified position.</returns>
94         /// <since_tizen> 3 </since_tizen>
95         public Sampler GetSampler(uint index)
96         {
97             global::System.IntPtr cPtr = Interop.TextureSet.GetSampler(SwigCPtr, index);
98             Sampler ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Sampler;
99             if (ret != null)
100             {
101                 Interop.BaseHandle.DeleteBaseHandle(new global::System.Runtime.InteropServices.HandleRef(this, cPtr));
102             }
103             else
104             {
105                 ret = new Sampler(cPtr, true);
106             }
107             NDalicPINVOKE.ThrowExceptionIfExists();
108             return ret;
109         }
110
111         /// <summary>
112         /// Gets the number of textures present in the TextureSet.
113         /// </summary>
114         /// <returns>The number of textures in the TextureSet.</returns>
115         /// <since_tizen> 3 </since_tizen>
116         public uint GetTextureCount()
117         {
118             uint ret = Interop.TextureSet.GetTextureCount(SwigCPtr);
119             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
120             return ret;
121         }
122
123         /// This will not be public opened.
124         [EditorBrowsable(EditorBrowsableState.Never)]
125         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
126         {
127             Interop.TextureSet.DeleteTextureSet(swigCPtr);
128         }
129     }
130 }