2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 extern alias TizenSystemInformation;
21 using System.ComponentModel;
22 using System.Collections.Generic;
23 using System.Runtime.InteropServices;
28 /// The GLWindow class is to draw with native GLES.<br />
29 /// This class is the special window. It is for native GLES application.<br />
30 /// So, some special functions and type are supported.<br />
31 /// In addition, basic window's functions are supported, too.<br />
33 [EditorBrowsable(EditorBrowsableState.Never)]
34 public partial class GLWindow : BaseHandle
36 internal GLWindow(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
42 /// Creates an initialized handle to a new GLWindow.<br />
43 /// This creates an GLWindow with default options.!--<br />
45 /// <returns>A new GLWindow.</returns>
46 [EditorBrowsable(EditorBrowsableState.Never)]
47 public GLWindow() : this(Interop.GLWindow.GlWindowNew(), true)
49 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
53 /// Creates an initialized handle to a new GLWindow.<br />
54 /// This API can create GLWindow with specific option.<br />
56 /// <param name="name">The name for GL window. </param>
57 /// <param name="windowPosition">The position and size of the Window.</param>
58 /// <param name="isTranslucent">Whether Window is translucent.</param>
59 /// <returns>A new Window.</returns>
60 [EditorBrowsable(EditorBrowsableState.Never)]
61 public GLWindow(string name, Rectangle windowPosition = null, bool isTranslucent = false) : this(Interop.GLWindow.GlWindowNew(Rectangle.getCPtr(windowPosition), name, "", isTranslucent), true)
63 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
67 /// Enumeration for orientation of the window is the way in which a rectangular page is oriented for normal viewing.
69 [EditorBrowsable(EditorBrowsableState.Never)]
70 public enum GLWindowOrientation
73 /// Portrait orientation. The height of the display area is greater than the width.
75 [EditorBrowsable(EditorBrowsableState.Never)]
79 /// Landscape orientation. A wide view area is needed.
81 [EditorBrowsable(EditorBrowsableState.Never)]
85 /// Portrait inverse orientation.
87 [EditorBrowsable(EditorBrowsableState.Never)]
88 PortraitInverse = 180,
91 /// Landscape inverse orientation.
93 [EditorBrowsable(EditorBrowsableState.Never)]
94 LandscapeInverse = 270,
97 /// No orientation. It is for the preferred orientation
98 /// Especially, NoOrientationPreference only has the effect for the preferred orientation.
99 /// It is used to unset the preferred orientation with SetPreferredOrientation.
101 [EditorBrowsable(EditorBrowsableState.Never)]
102 NoOrientationPreference = -1
106 /// Gets or sets a size of the window.
108 /// <exception cref="ArgumentNullException"> Thrown when value is null. </exception>
109 [EditorBrowsable(EditorBrowsableState.Never)]
110 public Size2D WindowSize
114 global::System.IntPtr intPtr = Interop.GLWindow.GlWindowGetPositionSize(SwigCPtr);
115 var val = new Rectangle(intPtr, true);
116 Size2D ret = new Size2D(val.Width, val.Height);
125 throw new ArgumentNullException(nameof(value));
128 global::System.IntPtr intPtr = Interop.GLWindow.GlWindowGetPositionSize(SwigCPtr);
129 Rectangle val = new Rectangle(intPtr, true);
130 Rectangle ret = new Rectangle(val.X, val.Y, value.Width, value.Height);
133 Interop.GLWindow.GlWindowSetPositionSize(SwigCPtr, Rectangle.getCPtr(ret));
139 /// Sets graphics configuration for GLWindow
141 /// <param name="depth">The flag of depth buffer. If true is set, 24bit depth buffer is enabled.</param>
142 /// <param name="stencil">The flag of stencil. it true is set, 8bit stencil buffer is enabled.</param>
143 /// <param name="msaa">The bit of msaa.</param>
144 /// <param name="version">The GLES version.</param>
145 [EditorBrowsable(EditorBrowsableState.Never)]
146 public void SetGraphicsConfig(bool depth, bool stencil, int msaa, GLESVersion version)
148 Interop.GLWindow.GlWindowSetGraphicsConfig(SwigCPtr, depth, stencil, msaa, (int)version);
149 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
153 /// Shows the GLWindow if it is hidden.
155 [EditorBrowsable(EditorBrowsableState.Never)]
158 Interop.GLWindow.GlWindowShow(SwigCPtr);
159 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
163 /// Hides the GLWindow if it is showing.
165 [EditorBrowsable(EditorBrowsableState.Never)]
168 Interop.GLWindow.GlWindowHide(SwigCPtr);
169 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
173 /// Raises the window to the top of the window stack.
175 [EditorBrowsable(EditorBrowsableState.Never)]
178 Interop.GLWindow.GlWindowRaise(SwigCPtr);
179 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
183 /// Lowers the window to the bottom of the window stack.
185 [EditorBrowsable(EditorBrowsableState.Never)]
188 Interop.GLWindow.GlWindowLower(SwigCPtr);
189 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
193 /// Activates the window to the top of the window stack even it is iconified.
195 [EditorBrowsable(EditorBrowsableState.Never)]
196 public void Activate()
198 Interop.GLWindow.GlWindowActivate(SwigCPtr);
199 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
203 /// Sets position and size of the window. This API guarantees that
204 /// both moving and resizing of window will appear on the screen at once.
206 [EditorBrowsable(EditorBrowsableState.Never)]
207 public Rectangle WindowPositionSize
211 global::System.IntPtr intPtr = Interop.GLWindow.GlWindowGetPositionSize(SwigCPtr);
212 Rectangle val = new Rectangle(intPtr, true);
213 Rectangle ret = new Rectangle(val.X, val.Y, val.Width, val.Height);
220 Interop.GLWindow.GlWindowSetPositionSize(SwigCPtr, Rectangle.getCPtr(value));
225 /// Gets the count of supported auxiliary hints of the GLWindow.
227 /// <returns>The number of supported auxiliary hints.</returns>
228 [EditorBrowsable(EditorBrowsableState.Never)]
229 public uint GetSupportedAuxiliaryHintCount()
231 uint ret = Interop.GLWindow.GlWindowGetSupportedAuxiliaryHintCount(SwigCPtr);
232 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
237 /// Gets the supported auxiliary hint string of the GLWindow.
239 /// <param name="index">The index of the supported auxiliary hint lists.</param>
240 /// <returns>The auxiliary hint string of the index.</returns>
241 [EditorBrowsable(EditorBrowsableState.Never)]
242 public string GetSupportedAuxiliaryHint(uint index)
244 string ret = Interop.GLWindow.GlWindowGetSupportedAuxiliaryHint(SwigCPtr, index);
245 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
250 /// Creates an auxiliary hint of the GLWindow.
252 /// <param name="hint">The auxiliary hint string.</param>
253 /// <param name="value">The value string.</param>
254 /// <returns>The ID of created auxiliary hint, or 0 on failure.</returns>
255 [EditorBrowsable(EditorBrowsableState.Never)]
256 public uint AddAuxiliaryHint(string hint, string value)
258 uint ret = Interop.GLWindow.GlWindowAddAuxiliaryHint(SwigCPtr, hint, value);
259 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
264 /// Removes an auxiliary hint of the GLWindow.
266 /// <param name="id">The ID of the auxiliary hint.</param>
267 /// <returns>True if no error occurred, false otherwise.</returns>
268 [EditorBrowsable(EditorBrowsableState.Never)]
269 public bool RemoveAuxiliaryHint(uint id)
271 bool ret = Interop.GLWindow.GlWindowRemoveAuxiliaryHint(SwigCPtr, id);
272 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
277 /// Changes a value of the auxiliary hint.
279 /// <param name="id">The auxiliary hint ID.</param>
280 /// <param name="value">The value string to be set.</param>
281 /// <returns>True if no error occurred, false otherwise.</returns>
282 [EditorBrowsable(EditorBrowsableState.Never)]
283 public bool SetAuxiliaryHintValue(uint id, string value)
285 bool ret = Interop.GLWindow.GlWindowSetAuxiliaryHintValue(SwigCPtr, id, value);
286 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
291 /// Gets a value of the auxiliary hint.
293 /// <param name="id">The auxiliary hint ID.</param>
294 /// <returns>The string value of the auxiliary hint ID, or an empty string if none exists.</returns>
295 [EditorBrowsable(EditorBrowsableState.Never)]
296 public string GetAuxiliaryHintValue(uint id)
298 string ret = Interop.GLWindow.GlWindowGetAuxiliaryHintValue(SwigCPtr, id);
299 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
304 /// Gets an ID of the auxiliary hint string.
306 /// <param name="hint">The auxiliary hint string.</param>
307 /// <returns>The ID of auxiliary hint string, or 0 on failure.</returns>
308 [EditorBrowsable(EditorBrowsableState.Never)]
309 public uint GetAuxiliaryHintId(string hint)
311 uint ret = Interop.GLWindow.GlWindowGetAuxiliaryHintId(SwigCPtr, hint);
312 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
317 /// Sets a region to accept input events.
319 /// <param name="inputRegion">The region to accept input events.</param>
320 [EditorBrowsable(EditorBrowsableState.Never)]
321 public void SetInputRegion(Rectangle inputRegion)
323 Interop.GLWindow.GlWindowSetInputRegion(SwigCPtr, Rectangle.getCPtr(inputRegion));
324 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
328 /// Sets a transparent window's visual state to opaque. <br />
329 /// If a visual state of a transparent window is opaque, <br />
330 /// then the window manager could handle it as an opaque window when calculating visibility.
332 /// <param name="opaque">Whether the window's visual state is opaque.</param>
333 /// <remarks>This will have no effect on an opaque window. <br />
334 /// It doesn't change transparent window to opaque window but lets the window manager know the visual state of the window.
336 [EditorBrowsable(EditorBrowsableState.Never)]
337 public void SetOpaqueState(bool opaque)
339 Interop.GLWindow.GlWindowSetOpaqueState(SwigCPtr, opaque);
340 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
344 /// Returns whether a transparent window's visual state is opaque or not.
346 /// <returns>True if the window's visual state is opaque, false otherwise.</returns>
347 /// <remarks> The return value has no meaning on an opaque window. </remarks>
348 [EditorBrowsable(EditorBrowsableState.Never)]
349 public bool IsOpaqueState()
351 bool ret = Interop.GLWindow.GlWindowIsOpaqueState(SwigCPtr);
352 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
357 /// Sets a preferred orientation.
359 /// <param name="orientation">The preferred orientation.</param>
360 [EditorBrowsable(EditorBrowsableState.Never)]
361 public void SetPreferredOrientation(GLWindow.GLWindowOrientation orientation)
363 Interop.GLWindow.GlWindowSetPreferredOrientation(SwigCPtr, (int)orientation);
364 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
368 /// Gets current orientation of the window.
370 /// <returns>The current window orientation if previously set, or none.</returns>
371 [EditorBrowsable(EditorBrowsableState.Never)]
372 public GLWindow.GLWindowOrientation GetCurrentOrientation()
374 GLWindow.GLWindowOrientation ret = (GLWindow.GLWindowOrientation)Interop.GLWindow.GlWindowGetCurrentOrientation(SwigCPtr);
375 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
380 /// Sets available orientations of the window.
381 /// This API is for setting several orientations one time.
383 /// <param name="orientations">The list of orientations.</param>
384 /// <exception cref="ArgumentNullException"> Thrown when orientations is null. </exception>
385 [EditorBrowsable(EditorBrowsableState.Never)]
386 public void SetAvailableOrientations(List<GLWindow.GLWindowOrientation> orientations)
388 if (null == orientations)
390 throw new ArgumentNullException(nameof(orientations));
393 PropertyArray orientationArray = new PropertyArray();
394 for (int i = 0; i < orientations.Count; i++)
396 PropertyValue val = new PropertyValue((int)orientations[i]);
397 orientationArray.PushBack(val);
401 Interop.GLWindow.GlWindowSetAvailableOrientations(SwigCPtr, PropertyArray.getCPtr(orientationArray), orientations.Count);
402 orientationArray.Dispose();
403 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
407 /// Allows at least one more render, even when paused.
408 /// The window should be shown, not minimised.
410 [EditorBrowsable(EditorBrowsableState.Never)]
411 public void RenderOnce()
413 Interop.GLWindow.GlWindowRenderOnce(SwigCPtr);
414 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
418 /// Type of callback to initialize native GL code.
420 [EditorBrowsable(EditorBrowsableState.Never)]
421 public delegate void GLInitializeCallbackType();
423 GLInitializeCallbackType GLInitializeCallback;
424 HandleRef InitHandleRef;
427 /// Type of callback to render to frame to use native GL code.
429 [EditorBrowsable(EditorBrowsableState.Never)]
430 public delegate int GLRenderFrameCallbackType();
432 GLRenderFrameCallbackType GLRenderFrameCallback;
433 HandleRef RenderHandlerRef;
437 /// Type of callback to cleanup native GL resource.
439 [EditorBrowsable(EditorBrowsableState.Never)]
440 public delegate void GLTerminateCallbackType();
442 GLTerminateCallbackType GLTerminateCallback;
443 HandleRef TerminateHandlerRef;
446 /// Registers GL callback functions for application.
448 /// <param name="glInit">The callback function for application initialize</param>
449 /// <param name="glRenderFrame">The callback function to render to the frame</param>
450 /// <param name="glTerminate">The callback function to clean-up application GL resource</param>
451 [EditorBrowsable(EditorBrowsableState.Never)]
452 public void RegisterGLCallbacks(GLInitializeCallbackType glInit, GLRenderFrameCallbackType glRenderFrame, GLTerminateCallbackType glTerminate)
454 GLInitializeCallback = glInit;
455 InitHandleRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(GLInitializeCallback));
457 GLRenderFrameCallback = glRenderFrame;
458 RenderHandlerRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(GLRenderFrameCallback));
460 GLTerminateCallback = glTerminate;
461 TerminateHandlerRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(GLTerminateCallback));
463 Interop.GLWindow.GlWindowRegisterGlCallbacks(SwigCPtr, InitHandleRef, RenderHandlerRef, TerminateHandlerRef);
465 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
469 /// Destroy the window immediately.
471 [EditorBrowsable(EditorBrowsableState.Never)]
472 public void Destroy()
478 /// Gets or sets a Rendeirng Mode of GLWindow.
480 [EditorBrowsable(EditorBrowsableState.Never)]
481 public GLRenderingMode RenderingMode
483 [EditorBrowsable(EditorBrowsableState.Never)]
486 GLRenderingMode mode = (GLRenderingMode)Interop.GLWindow.GlWindowGetRenderingMode(SwigCPtr);
487 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
490 [EditorBrowsable(EditorBrowsableState.Never)]
493 Interop.GLWindow.GlWindowSetRenderingMode(SwigCPtr, (int)value);
494 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
499 /// Dispose for Window
501 protected override void Dispose(DisposeTypes type)
508 this.DisconnectNativeSignals();
513 /// This will not be public opened.
514 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
516 Interop.Window.DeleteWindow(swigCPtr);