using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Tizen.NUI.Binding;
using Tizen.NUI;
namespace Tizen.NUI.BaseComponents
{
///
/// GLView allows drawing with OpenGL.
/// GLView creates a context, a surface, and a render thread.
/// The render thread invokes user's callbacks.
///
/// 10
public class GLView : View
{
private GLInitializeDelegate glInitializeCallback;
private GLRenderFrameDelegate glRenderFrameCallback;
private GLTerminateDelegate glTerminateCallback;
private ViewResizeDelegate viewResizeCallback;
private ViewResizeDelegate internalResizeCallback;
///
/// Type of callback to initialize OpenGLES.
///
/// 10
public delegate void GLInitializeDelegate();
///
/// Type of callback to render the frame with OpenGLES APIs.
/// If the return value of this callback is not 0, the eglSwapBuffers() will be called.
///
/// The return value is not 0, the eglSwapBuffers() will be called.
/// 10
public delegate int GLRenderFrameDelegate();
///
/// Type of callback to clean up GL resource.
///
/// 10
public delegate void GLTerminateDelegate();
///
/// Type of resize callback
///
/// The resized width size of the GLView
/// The resized height size of the GLView
/// 10
public delegate void ViewResizeDelegate(int w, int h);
internal GLView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
{
}
///
/// Creates an initialized GLView.
///
/// The format of the color buffer
/// 10
public GLView(ColorFormat colorFormat) : this(Interop.GLView.New((int)colorFormat), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// Enumeration for the color format of the color buffer
///
/// 10
public enum ColorFormat
{
///
/// 8 red bits, 8 green bits, 8 blue bits
///
RGB888 = 0,
///
/// 8 red bits, 8 green bits, 8 blue bits, alpha 8 bits
///
RGBA8888
}
///
/// Gets or sets the rendering mode of the GLView.
///
/// 10
public GLRenderingMode RenderingMode
{
get
{
GLRenderingMode ret = (GLRenderingMode)Interop.GLView.GlViewGetRenderingMode(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
set
{
Interop.GLView.GlViewSetRenderingMode(SwigCPtr, (int)value);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
}
///
/// Registers GL callback functions to render with OpenGL ES
///
/// The callback function for GL initialization
/// The callback function to render the frame
/// The callback function to clean up GL resources
/// 10
public void RegisterGLCallbacks(GLInitializeDelegate glInit, GLRenderFrameDelegate glRenderFrame, GLTerminateDelegate glTerminate)
{
glInitializeCallback = glInit;
HandleRef InitHandleRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate(glInitializeCallback));
glRenderFrameCallback = glRenderFrame;
HandleRef RenderHandlerRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate(glRenderFrameCallback));
glTerminateCallback = glTerminate;
HandleRef TerminateHandlerRef = new HandleRef(this, Marshal.GetFunctionPointerForDelegate(glTerminateCallback));
Interop.GLView.GlViewRegisterGlCallbacks(SwigCPtr, InitHandleRef, RenderHandlerRef, TerminateHandlerRef);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
private void OnResized(int width, int height)
{
if (viewResizeCallback != null)
{
viewResizeCallback(width, height);
}
}
///
/// Sets the resize callback to the GLView.
/// When GLView is resized, the callback is invoked and it passes the width and height.
///
/// The resize callback function
/// 10
public void SetResizeCallback(ViewResizeDelegate callback)
{
viewResizeCallback = callback;
internalResizeCallback = OnResized;
Interop.GLView.GlViewSetResizeCallback(SwigCPtr, new HandleRef(this, Marshal.GetFunctionPointerForDelegate(internalResizeCallback)));
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
///
/// Sets graphics configuration for the GLView
///
/// The flag of depth buffer. When the value is true, 24bit depth buffer is enabled.
/// The flag of stencil. When the value is true, 8bit stencil buffer is enabled.
/// The bit of MSAA
/// The GLES version
/// True if the config was successfully set, false otherwise.
/// 10
public bool SetGraphicsConfig(bool depth, bool stencil, int msaa, GLESVersion version)
{
bool ret = Interop.GLView.GlViewSetGraphicsConfig(SwigCPtr, depth, stencil, msaa, (int)version);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
///
/// Renders once more, even when paused.
///
/// 10
public void RenderOnce()
{
Interop.GLView.GlViewRenderOnce(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
}
}