Release 4.0.0-preview1-00301
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Texture.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 namespace Tizen.NUI
19 {
20     /// <summary>
21     /// Texture represents a texture object used as input or output by shaders.
22     /// </summary>
23     public class Texture : BaseHandle
24     {
25         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
26
27         internal Texture(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Texture_SWIGUpcast(cPtr), cMemoryOwn)
28         {
29             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
30         }
31
32         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Texture obj)
33         {
34             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
35         }
36
37         /// <summary>
38         /// Dispose.
39         /// </summary>
40         /// <since_tizen> 3 </since_tizen>
41         protected override void Dispose(DisposeTypes type)
42         {
43             if (disposed)
44             {
45                 return;
46             }
47
48             if (type == DisposeTypes.Explicit)
49             {
50                 //Called by User
51                 //Release your own managed resources here.
52                 //You should release all of your own disposable objects here.
53
54             }
55
56             //Release your own unmanaged resources here.
57             //You should not access any managed member here except static instance.
58             //because the execution order of Finalizes is non-deterministic.
59
60             if (swigCPtr.Handle != global::System.IntPtr.Zero)
61             {
62                 if (swigCMemOwn)
63                 {
64                     swigCMemOwn = false;
65                     NDalicPINVOKE.delete_Texture(swigCPtr);
66                 }
67                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
68             }
69
70             base.Dispose(type);
71         }
72
73         /// <summary>
74         /// Creates a new Texture object.
75         /// </summary>
76         /// <param name="type">The type of the texture.</param>
77         /// <param name="format">The format of the pixel data.</param>
78         /// <param name="width">The width of the texture.</param>
79         /// <param name="height">The height of the texture.</param>
80         /// <since_tizen> 3 </since_tizen>
81         public Texture(TextureType type, PixelFormat format, uint width, uint height) : this(NDalicPINVOKE.Texture_New__SWIG_0((int)type, (int)format, width, height), true)
82         {
83             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
84
85         }
86         internal Texture(NativeImageInterface nativeImageInterface) : this(NDalicPINVOKE.Texture_New__SWIG_1(NativeImageInterface.getCPtr(nativeImageInterface)), true)
87         {
88             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
89
90         }
91
92         /// <summary>
93         /// Uploads data to the texture from a PixelData object.
94         /// </summary>
95         /// <param name="pixelData">The pixelData object.</param>
96         /// <returns>True if the PixelData object has compatible pixel format and fits within the texture, false otherwise.</returns>
97         /// <since_tizen> 3 </since_tizen>
98         public bool Upload(PixelData pixelData)
99         {
100             bool ret = NDalicPINVOKE.Texture_Upload__SWIG_0(swigCPtr, PixelData.getCPtr(pixelData));
101             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
102             return ret;
103         }
104
105         /// <summary>
106         /// Uploads data to the texture from a PixelData object.
107         /// </summary>
108         /// <param name="pixelData">The pixelData object.</param>
109         /// <param name="layer">The layer of a cube map or array texture.</param>
110         /// <param name="mipmap">The level-of-detail number. Level 0 is the base image level. Level n is the nth mipmap reduction image.</param>
111         /// <param name="xOffset">The horizontal offset of the rectangular area in the texture that will be updated.</param>
112         /// <param name="yOffset">The vertical offset of the rectangular area in the texture that will be updated.</param>
113         /// <param name="width">The width of the rectangular area in the texture that will be updated.</param>
114         /// <param name="height">height of the rectangular area in the texture that will be updated.</param>
115         /// <returns>True if the PixelData object has compatible pixel format and fits within the texture, false otherwise.</returns>
116         /// <since_tizen> 3 </since_tizen>
117         public bool Upload(PixelData pixelData, uint layer, uint mipmap, uint xOffset, uint yOffset, uint width, uint height)
118         {
119             bool ret = NDalicPINVOKE.Texture_Upload__SWIG_1(swigCPtr, PixelData.getCPtr(pixelData), layer, mipmap, xOffset, yOffset, width, height);
120             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
121             return ret;
122         }
123
124         /// <summary>
125         /// Generates mipmaps for the texture.<br />
126         /// This will auto generate all the mipmaps for the texture based on the data in the base level.
127         /// </summary>
128         /// <since_tizen> 3 </since_tizen>
129         public void GenerateMipmaps()
130         {
131             NDalicPINVOKE.Texture_GenerateMipmaps(swigCPtr);
132             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
133         }
134
135         /// <summary>
136         /// Returns the width of the texture.<br />
137         /// </summary>
138         /// <returns>The width, in pixels, of the texture.</returns>
139         /// <since_tizen> 3 </since_tizen>
140         public uint GetWidth()
141         {
142             uint ret = NDalicPINVOKE.Texture_GetWidth(swigCPtr);
143             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
144             return ret;
145         }
146
147         /// <summary>
148         /// Returns the height of the texture..<br />
149         /// </summary>
150         /// <returns>The height, in pixels, of the texture.</returns>
151         /// <since_tizen> 3 </since_tizen>
152         public uint GetHeight()
153         {
154             uint ret = NDalicPINVOKE.Texture_GetHeight(swigCPtr);
155             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
156             return ret;
157         }
158
159         internal Texture(SWIGTYPE_p_Dali__Internal__Texture pointer) : this(NDalicPINVOKE.new_Texture__SWIG_2(SWIGTYPE_p_Dali__Internal__Texture.getCPtr(pointer)), true)
160         {
161             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
162         }
163
164     }
165
166 }