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