Explorar o código

Modifying engine script objects so they don't pass structures by value in internal calls

BearishSun %!s(int64=10) %!d(string=hai) anos
pai
achega
998c87109a

+ 128 - 128
MBansheeEngine/ContextMenu.cs

@@ -1,128 +1,128 @@
-using System;
-using System.Collections.Generic;
-using System.Runtime.CompilerServices;
-
-namespace BansheeEngine
-{
-    /// <summary>
-    /// Contains data used for initializing a context menu used on GUI elements. When specifying menu items you must provide
-    /// a path. Path must be formated in a certain way. All path elements must be separated by /, e.g. "View/Toolbars/Find". 
-    /// "View" would be the top level path element, "Toolbars" a child in its menu that opens up its own submenu, and "Find"
-    /// a child in the "Toolbars" sub-menu with an optional callback.
-    /// </summary>
-    public class ContextMenu : ScriptObject
-    {
-        private List<Action> callbacks = new List<Action>(); 
-
-        /// <summary>
-        /// Creates a new empty context menu data.
-        /// </summary>
-        public ContextMenu()
-        {
-            Internal_CreateInstance(this);
-        }
-
-        /// <summary>
-        /// Adds a new item to the menu.
-        /// </summary>
-        /// <param name="path">Path that determines where to add the element. See class information on how to specify paths.
-        ///                    All sub-elements of a path will be added automatically.</param>
-        /// <param name="callback">Callback to trigger when the path element is selected.</param>
-        public void AddItem(string path, Action callback)
-        {
-            Internal_AddItem(mCachedPtr, path, callbacks.Count, ShortcutKey.None);
-            callbacks.Add(callback);
-        }
-
-        /// <summary>
-        /// Adds a new item to the menu.
-        /// </summary>
-        /// <param name="path">Path that determines where to add the element. See class information on how to specify paths.
-        ///                    All sub-elements of a path will be added automatically.</param>
-        /// <param name="callback">Callback to trigger when the path element is selected.</param>
-        /// <param name="shortcut">Keyboard shortcut to display next to the item name.</param>
-        public void AddItem(string path, Action callback, ShortcutKey shortcut)
-        {
-            Internal_AddItem(mCachedPtr, path, callbacks.Count, shortcut);
-            callbacks.Add(callback);
-        }
-
-        /// <summary>
-        /// Adds a new item to the menu.
-        /// </summary>
-        /// <param name="path">Path that determines where to add the element. See class information on how to specify paths.
-        ///                    All sub-elements of a path will be added automatically.</param>
-        /// <param name="callback">Callback to trigger when the path element is selected.</param>
-        /// <param name="name">Localized name for the menu item.</param>
-        public void AddItem(string path, Action callback, LocString name)
-        {
-            Internal_AddItem(mCachedPtr, path, callbacks.Count, ShortcutKey.None);
-            callbacks.Add(callback);
-        }
-
-        /// <summary>
-        /// Adds a new item to the menu.
-        /// </summary>
-        /// <param name="path">Path that determines where to add the element. See class information on how to specify paths.
-        ///                    All sub-elements of a path will be added automatically.</param>
-        /// <param name="callback">Callback to trigger when the path element is selected.</param>
-        /// <param name="shortcut">Keyboard shortcut to display next to the item name.</param>
-        /// <param name="name">Localized name for the menu item.</param>
-        public void AddItem(string path, Action callback, ShortcutKey shortcut, LocString name)
-        {
-            Internal_AddItem(mCachedPtr, path, callbacks.Count, shortcut);
-            callbacks.Add(callback);
-        }
-
-        /// <summary>
-        /// Adds a new separator to the menu.
-        /// </summary>
-        /// <param name="path">Path that determines where to add the element. See class information on how to specify paths.
-        ///                    All sub-elements of a path will be added automatically.</param>
-        public void AddSeparator(string path)
-        {
-            Internal_AddSeparator(mCachedPtr, path);
-        }
-
-        /// <summary>
-        /// Sets a localized name of a specific menu element. If no localized name is set element labels will be displayed
-        /// as their names.
-        /// </summary>
-        /// <param name="label">Label of the element.</param>
-        /// <param name="name">Name to display when the menu is shown.</param>
-        public void SetLocalizedName(string label, LocString name)
-        {
-            IntPtr namePtr = IntPtr.Zero;
-            if (name != null)
-                namePtr = name.GetCachedPtr();
-
-            Internal_SetLocalizedName(mCachedPtr, label, namePtr);
-        }
-
-        /// <summary>
-        /// Triggered by the runtime when an element is selected the context menu.
-        /// </summary>
-        /// <param name="callbackIdx">Unique index of the element that was selected.</param>
-        private void InternalDoOnEntryTriggered(int callbackIdx)
-        {
-            if (callbackIdx < 0 || callbackIdx >= callbacks.Count)
-                return;
-
-            Action callback = callbacks[callbackIdx];
-            if (callback != null)
-                callback();
-        }
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_CreateInstance(ContextMenu instance);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_AddItem(IntPtr instance, string path, int callbackIdx, ShortcutKey shortcut);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_AddSeparator(IntPtr instance, string path);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetLocalizedName(IntPtr instance, string label, IntPtr name);
-    }
-}
+using System;
+using System.Collections.Generic;
+using System.Runtime.CompilerServices;
+
+namespace BansheeEngine
+{
+    /// <summary>
+    /// Contains data used for initializing a context menu used on GUI elements. When specifying menu items you must provide
+    /// a path. Path must be formated in a certain way. All path elements must be separated by /, e.g. "View/Toolbars/Find". 
+    /// "View" would be the top level path element, "Toolbars" a child in its menu that opens up its own submenu, and "Find"
+    /// a child in the "Toolbars" sub-menu with an optional callback.
+    /// </summary>
+    public class ContextMenu : ScriptObject
+    {
+        private List<Action> callbacks = new List<Action>(); 
+
+        /// <summary>
+        /// Creates a new empty context menu data.
+        /// </summary>
+        public ContextMenu()
+        {
+            Internal_CreateInstance(this);
+        }
+
+        /// <summary>
+        /// Adds a new item to the menu.
+        /// </summary>
+        /// <param name="path">Path that determines where to add the element. See class information on how to specify paths.
+        ///                    All sub-elements of a path will be added automatically.</param>
+        /// <param name="callback">Callback to trigger when the path element is selected.</param>
+        public void AddItem(string path, Action callback)
+        {
+            Internal_AddItem(mCachedPtr, path, callbacks.Count, ref ShortcutKey.None);
+            callbacks.Add(callback);
+        }
+
+        /// <summary>
+        /// Adds a new item to the menu.
+        /// </summary>
+        /// <param name="path">Path that determines where to add the element. See class information on how to specify paths.
+        ///                    All sub-elements of a path will be added automatically.</param>
+        /// <param name="callback">Callback to trigger when the path element is selected.</param>
+        /// <param name="shortcut">Keyboard shortcut to display next to the item name.</param>
+        public void AddItem(string path, Action callback, ShortcutKey shortcut)
+        {
+            Internal_AddItem(mCachedPtr, path, callbacks.Count, ref shortcut);
+            callbacks.Add(callback);
+        }
+
+        /// <summary>
+        /// Adds a new item to the menu.
+        /// </summary>
+        /// <param name="path">Path that determines where to add the element. See class information on how to specify paths.
+        ///                    All sub-elements of a path will be added automatically.</param>
+        /// <param name="callback">Callback to trigger when the path element is selected.</param>
+        /// <param name="name">Localized name for the menu item.</param>
+        public void AddItem(string path, Action callback, LocString name)
+        {
+            Internal_AddItem(mCachedPtr, path, callbacks.Count, ref ShortcutKey.None);
+            callbacks.Add(callback);
+        }
+
+        /// <summary>
+        /// Adds a new item to the menu.
+        /// </summary>
+        /// <param name="path">Path that determines where to add the element. See class information on how to specify paths.
+        ///                    All sub-elements of a path will be added automatically.</param>
+        /// <param name="callback">Callback to trigger when the path element is selected.</param>
+        /// <param name="shortcut">Keyboard shortcut to display next to the item name.</param>
+        /// <param name="name">Localized name for the menu item.</param>
+        public void AddItem(string path, Action callback, ShortcutKey shortcut, LocString name)
+        {
+            Internal_AddItem(mCachedPtr, path, callbacks.Count, ref shortcut);
+            callbacks.Add(callback);
+        }
+
+        /// <summary>
+        /// Adds a new separator to the menu.
+        /// </summary>
+        /// <param name="path">Path that determines where to add the element. See class information on how to specify paths.
+        ///                    All sub-elements of a path will be added automatically.</param>
+        public void AddSeparator(string path)
+        {
+            Internal_AddSeparator(mCachedPtr, path);
+        }
+
+        /// <summary>
+        /// Sets a localized name of a specific menu element. If no localized name is set element labels will be displayed
+        /// as their names.
+        /// </summary>
+        /// <param name="label">Label of the element.</param>
+        /// <param name="name">Name to display when the menu is shown.</param>
+        public void SetLocalizedName(string label, LocString name)
+        {
+            IntPtr namePtr = IntPtr.Zero;
+            if (name != null)
+                namePtr = name.GetCachedPtr();
+
+            Internal_SetLocalizedName(mCachedPtr, label, namePtr);
+        }
+
+        /// <summary>
+        /// Triggered by the runtime when an element is selected the context menu.
+        /// </summary>
+        /// <param name="callbackIdx">Unique index of the element that was selected.</param>
+        private void InternalDoOnEntryTriggered(int callbackIdx)
+        {
+            if (callbackIdx < 0 || callbackIdx >= callbacks.Count)
+                return;
+
+            Action callback = callbacks[callbackIdx];
+            if (callback != null)
+                callback();
+        }
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_CreateInstance(ContextMenu instance);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_AddItem(IntPtr instance, string path, int callbackIdx, ref ShortcutKey shortcut);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_AddSeparator(IntPtr instance, string path);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetLocalizedName(IntPtr instance, string label, IntPtr name);
+    }
+}

+ 180 - 180
MBansheeEngine/Cursor.cs

@@ -1,180 +1,180 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Runtime.CompilerServices;
-using System.Text;
-
-namespace BansheeEngine
-{
-    /// <summary>
-    /// Allows manipulation of the platform cursor.
-    /// </summary>
-    public static class Cursor
-    {
-        /// <summary>
-        /// Position of the cursor in screen coordinates.
-        /// </summary>
-        public static Vector2I ScreenPosition
-        {
-            get
-            {
-                Vector2I value;
-                Internal_GetScreenPosition(out value);
-                return value;
-            }
-
-            set
-            {
-                Internal_SetScreenPosition(value);
-            }
-        }
-
-        /// <summary>
-        /// Hides the cursor.
-        /// </summary>
-        public static void Hide()
-        {
-            Internal_Hide();
-        }
-
-        /// <summary>
-        /// Shows the cursor.
-        /// </summary>
-        public static void Show()
-        {
-            Internal_Show();
-        }
-
-        /// <summary>
-        /// Clips the cursor to the specified area. Enabled until <see cref="ClipDisable"/> is called.
-        /// </summary>
-        /// <param name="area">Area in screen space to clip the cursor to.</param>
-        public static void ClipToRect(Rect2I area)
-        {
-            Internal_ClipToRect(area);
-        }
-
-        /// <summary>
-        /// Disables cursor clipping previously enabled with <see cref="ClipToRect"/>.
-        /// </summary>
-        public static void ClipDisable()
-        {
-            Internal_ClipDisable();
-        }
-
-        /// <summary>
-        /// Changes the active cursor icon.
-        /// </summary>
-        /// <param name="name">Name of the cursor icon, previously registered with 
-        ///                    <see cref="SetCursorIcon(string,PixelData,Vector2I)"/></param>
-        public static void SetCursor(string name)
-        {
-            Internal_SetCursorStr(name);
-        }
-
-        /// <summary>
-        /// Changes the active cursor icon.
-        /// </summary>
-        /// <param name="type">One of the built-in cursor types.</param>
-        public static void SetCursor(CursorType type)
-        {
-            Internal_SetCursor(type);
-        }
-
-        /// <summary>
-        /// Updates the look of a specific cursor icon.
-        /// </summary>
-        /// <param name="name">Name of the cursor.</param>
-        /// <param name="iconData">Pixel data specifying the new look.</param>
-        /// <param name="hotspot">Offset into the icon image that determines where the cursor point is.</param>
-        public static void SetCursorIcon(string name, PixelData iconData, Vector2I hotspot)
-        {
-            Internal_SetCursorIconStr(name, iconData, hotspot);
-        }
-
-        /// <summary>
-        /// Updates the look of a specific cursor icon.
-        /// </summary>
-        /// <param name="type">One of the built-in cursor types.</param>
-        /// <param name="iconData">Pixel data specifying the new look.</param>
-        /// <param name="hotspot">Offset into the icon image that determines where the cursor point is.</param>
-        public static void SetCursorIcon(CursorType type, PixelData iconData, Vector2I hotspot)
-        {
-            Internal_SetCursorIcon(type, iconData, hotspot);
-        }
-
-        /// <summary>
-        /// Removes a cursor icon.
-        /// </summary>
-        /// <param name="name">Name of the cursor.</param>
-        public static void ClearCursorIcon(string name)
-        {
-            Internal_ClearCursorIconStr(name);
-        }
-
-        /// <summary>
-        /// Removes a cursor icon.
-        /// </summary>
-        /// <param name="type">One of the built-in cursor types.</param>
-        public static void ClearCursorIcon(CursorType type)
-        {
-            Internal_ClearCursorIcon(type);
-        }
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_GetScreenPosition(out Vector2I value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetScreenPosition(Vector2I value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_Hide();
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_Show();
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_ClipToRect(Rect2I value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_ClipDisable();
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetCursorStr(string name);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetCursor(CursorType cursor);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetCursorIconStr(string name, PixelData iconData, Vector2I hotspot);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetCursorIcon(CursorType cursor, PixelData iconData, Vector2I hotspot);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_ClearCursorIconStr(string name);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_ClearCursorIcon(CursorType cursor);
-    }
-
-    /// <summary>
-    /// Built-in cursor types.
-    /// </summary>
-    public enum CursorType //Note: Must match C++ enum CursorType
-	{
-		Arrow,
-		ArrowDrag,
-		ArrowLeftRight,
-		Wait,
-		IBeam,
-		SizeNESW,
-		SizeNS,
-		SizeNWSE,
-		SizeWE,
-		Deny,
-
-		// Keep at the end
-		Count
-	};
-}
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Text;
+
+namespace BansheeEngine
+{
+    /// <summary>
+    /// Allows manipulation of the platform cursor.
+    /// </summary>
+    public static class Cursor
+    {
+        /// <summary>
+        /// Position of the cursor in screen coordinates.
+        /// </summary>
+        public static Vector2I ScreenPosition
+        {
+            get
+            {
+                Vector2I value;
+                Internal_GetScreenPosition(out value);
+                return value;
+            }
+
+            set
+            {
+                Internal_SetScreenPosition(ref value);
+            }
+        }
+
+        /// <summary>
+        /// Hides the cursor.
+        /// </summary>
+        public static void Hide()
+        {
+            Internal_Hide();
+        }
+
+        /// <summary>
+        /// Shows the cursor.
+        /// </summary>
+        public static void Show()
+        {
+            Internal_Show();
+        }
+
+        /// <summary>
+        /// Clips the cursor to the specified area. Enabled until <see cref="ClipDisable"/> is called.
+        /// </summary>
+        /// <param name="area">Area in screen space to clip the cursor to.</param>
+        public static void ClipToRect(Rect2I area)
+        {
+            Internal_ClipToRect(ref area);
+        }
+
+        /// <summary>
+        /// Disables cursor clipping previously enabled with <see cref="ClipToRect"/>.
+        /// </summary>
+        public static void ClipDisable()
+        {
+            Internal_ClipDisable();
+        }
+
+        /// <summary>
+        /// Changes the active cursor icon.
+        /// </summary>
+        /// <param name="name">Name of the cursor icon, previously registered with 
+        ///                    <see cref="SetCursorIcon(string,PixelData,Vector2I)"/></param>
+        public static void SetCursor(string name)
+        {
+            Internal_SetCursorStr(name);
+        }
+
+        /// <summary>
+        /// Changes the active cursor icon.
+        /// </summary>
+        /// <param name="type">One of the built-in cursor types.</param>
+        public static void SetCursor(CursorType type)
+        {
+            Internal_SetCursor(type);
+        }
+
+        /// <summary>
+        /// Updates the look of a specific cursor icon.
+        /// </summary>
+        /// <param name="name">Name of the cursor.</param>
+        /// <param name="iconData">Pixel data specifying the new look.</param>
+        /// <param name="hotspot">Offset into the icon image that determines where the cursor point is.</param>
+        public static void SetCursorIcon(string name, PixelData iconData, Vector2I hotspot)
+        {
+            Internal_SetCursorIconStr(name, iconData, ref hotspot);
+        }
+
+        /// <summary>
+        /// Updates the look of a specific cursor icon.
+        /// </summary>
+        /// <param name="type">One of the built-in cursor types.</param>
+        /// <param name="iconData">Pixel data specifying the new look.</param>
+        /// <param name="hotspot">Offset into the icon image that determines where the cursor point is.</param>
+        public static void SetCursorIcon(CursorType type, PixelData iconData, Vector2I hotspot)
+        {
+            Internal_SetCursorIcon(type, iconData, ref hotspot);
+        }
+
+        /// <summary>
+        /// Removes a cursor icon.
+        /// </summary>
+        /// <param name="name">Name of the cursor.</param>
+        public static void ClearCursorIcon(string name)
+        {
+            Internal_ClearCursorIconStr(name);
+        }
+
+        /// <summary>
+        /// Removes a cursor icon.
+        /// </summary>
+        /// <param name="type">One of the built-in cursor types.</param>
+        public static void ClearCursorIcon(CursorType type)
+        {
+            Internal_ClearCursorIcon(type);
+        }
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetScreenPosition(out Vector2I value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetScreenPosition(ref Vector2I value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_Hide();
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_Show();
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_ClipToRect(ref Rect2I value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_ClipDisable();
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetCursorStr(string name);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetCursor(CursorType cursor);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetCursorIconStr(string name, PixelData iconData, ref Vector2I hotspot);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetCursorIcon(CursorType cursor, PixelData iconData, ref Vector2I hotspot);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_ClearCursorIconStr(string name);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_ClearCursorIcon(CursorType cursor);
+    }
+
+    /// <summary>
+    /// Built-in cursor types.
+    /// </summary>
+    public enum CursorType //Note: Must match C++ enum CursorType
+	{
+		Arrow,
+		ArrowDrag,
+		ArrowLeftRight,
+		Wait,
+		IBeam,
+		SizeNESW,
+		SizeNS,
+		SizeNWSE,
+		SizeWE,
+		Deny,
+
+		// Keep at the end
+		Count
+	};
+}

+ 365 - 353
MBansheeEngine/Material.cs

@@ -1,353 +1,365 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Runtime.CompilerServices;
-using System.Text;
-
-namespace BansheeEngine
-{
-    /// <summary>
-    /// Material that controls how objects are rendered. It is represented by a shader and parameters used to set up that 
-    /// shader. It provides a simple interface for manipulating the parameters.
-    /// </summary>
-    public class Material : Resource
-    {
-        /// <summary>
-        /// Creates a new empty material that references no shader.
-        /// </summary>
-        public Material()
-        {
-            Internal_CreateInstance(this, IntPtr.Zero);
-        }
-
-        /// <summary>
-        /// Constructor for internal runtime use only.
-        /// </summary>
-        /// <param name="dummy">Dummy parameter to differentiate it from other constructors.</param>
-        private Material(bool dummy)
-        { }
-
-        /// <summary>
-        /// Creates a new material with the specified shader.
-        /// </summary>
-        /// <param name="shader">Shader to initialize the material with.</param>
-        public Material(Shader shader)
-        {
-            IntPtr nativeShader = IntPtr.Zero;
-            if (shader != null)
-                nativeShader = shader.GetCachedPtr();
-
-            Internal_CreateInstance(this, nativeShader);
-        }
-
-        /// <summary>
-        /// Shader used by the material. Best technique from the shader will be used for rendering, depending on currently
-        /// active renderer and render API.
-        /// </summary>
-        public Shader Shader
-        {
-            get { return Internal_GetShader(mCachedPtr); }
-            set
-            {
-                IntPtr nativeShader = IntPtr.Zero;
-                if (value != null)
-                    nativeShader = value.GetCachedPtr();
-
-                Internal_SetShader(mCachedPtr, nativeShader); 
-            }
-        }
-
-        /// <summary>
-        /// Assigns a float value to the shader parameter with the specified name.
-        /// </summary>
-        /// <param name="name">Name of the shader parameter.</param>
-        /// <param name="value">Value of the parameter.</param>
-        public void SetFloat(string name, float value)
-        {
-            Internal_SetFloat(mCachedPtr, name, value);
-        }
-
-        /// <summary>
-        /// Assigns a 2D vector to the shader parameter with the specified name.
-        /// </summary>
-        /// <param name="name">Name of the shader parameter.</param>
-        /// <param name="value">Value of the parameter.</param>
-        public void SetVector2(string name, Vector2 value)
-        {
-            Internal_SetVector2(mCachedPtr, name, value);
-        }
-
-        /// <summary>
-        /// Assigns a 3D vector to the shader parameter with the specified name.
-        /// </summary>
-        /// <param name="name">Name of the shader parameter.</param>
-        /// <param name="value">Value of the parameter.</param>
-        public void SetVector3(string name, Vector3 value)
-        {
-            Internal_SetVector3(mCachedPtr, name, value);
-        }
-
-        /// <summary>
-        /// Assigns a 4D vector to the shader parameter with the specified name.
-        /// </summary>
-        /// <param name="name">Name of the shader parameter.</param>
-        /// <param name="value">Value of the parameter.</param>
-        public void SetVector4(string name, Vector4 value)
-        {
-            Internal_SetVector4(mCachedPtr, name, value);
-        }
-
-        /// <summary>
-        /// Assigns a 3x3 matrix to the shader parameter with the specified name.
-        /// </summary>
-        /// <param name="name">Name of the shader parameter.</param>
-        /// <param name="value">Value of the parameter.</param>
-        public void SetMatrix3(string name, Matrix3 value)
-        {
-            Internal_SetMatrix3(mCachedPtr, name, value);
-        }
-
-        /// <summary>
-        /// Assigns a 4x4 matrix to the shader parameter with the specified name.
-        /// </summary>
-        /// <param name="name">Name of the shader parameter.</param>
-        /// <param name="value">Value of the parameter.</param>
-        public void SetMatrix4(string name, Matrix4 value)
-        {
-            Internal_SetMatrix4(mCachedPtr, name, value);
-        }
-
-        /// <summary>
-        /// Assigns a color to the shader parameter with the specified name.
-        /// </summary>
-        /// <param name="name">Name of the shader parameter.</param>
-        /// <param name="value">Value of the parameter.</param>
-        public void SetColor(string name, Color value)
-        {
-            Internal_SetColor(mCachedPtr, name, value);
-        }
-
-        /// <summary>
-        /// Assigns a 2D texture to the shader parameter with the specified name.
-        /// </summary>
-        /// <param name="name">Name of the shader parameter.</param>
-        /// <param name="value">Value of the parameter.</param>
-        public void SetTexture2D(string name, Texture2D value)
-        {
-            IntPtr texturePtr = IntPtr.Zero;
-            if (value != null)
-                texturePtr = value.GetCachedPtr();
-
-            Internal_SetTexture2D(mCachedPtr, name, texturePtr);
-        }
-
-        /// <summary>
-        /// Assigns a 3D texture to the shader parameter with the specified name.
-        /// </summary>
-        /// <param name="name">Name of the shader parameter.</param>
-        /// <param name="value">Value of the parameter.</param>
-        public void SetTexture3D(string name, Texture3D value)
-        {
-            IntPtr texturePtr = IntPtr.Zero;
-            if (value != null)
-                texturePtr = value.GetCachedPtr();
-
-            Internal_SetTexture3D(mCachedPtr, name, texturePtr);
-        }
-
-        /// <summary>
-        /// Assigns a cube texture to the shader parameter with the specified name.
-        /// </summary>
-        /// <param name="name">Name of the shader parameter.</param>
-        /// <param name="value">Value of the parameter.</param>
-        public void SetTextureCube(string name, TextureCube value)
-        {
-            IntPtr texturePtr = IntPtr.Zero;
-            if (value != null)
-                texturePtr = value.GetCachedPtr();
-
-            Internal_SetTextureCube(mCachedPtr, name, texturePtr);
-        }
-
-        /// <summary>
-        /// Returns a float value assigned with the parameter with the specified name.
-        /// </summary>
-        /// <param name="name">Name of the shader parameter.</param>
-        /// <returns>Value of the parameter.</returns>
-        public float GetFloat(string name)
-        {
-            return Internal_GetFloat(mCachedPtr, name);
-        }
-
-        /// <summary>
-        /// Returns a 2D vector assigned with the parameter with the specified name.
-        /// </summary>
-        /// <param name="name">Name of the shader parameter.</param>
-        /// <returns>Value of the parameter.</returns>
-        public Vector2 GetVector2(string name)
-        {
-            return Internal_GetVector2(mCachedPtr, name);
-        }
-
-        /// <summary>
-        /// Returns a 3D vector assigned with the parameter with the specified name.
-        /// </summary>
-        /// <param name="name">Name of the shader parameter.</param>
-        /// <returns>Value of the parameter.</returns>
-        public Vector3 GetVector3(string name)
-        {
-            return Internal_GetVector3(mCachedPtr, name);
-        }
-
-        /// <summary>
-        /// Returns a 4D vector assigned with the parameter with the specified name.
-        /// </summary>
-        /// <param name="name">Name of the shader parameter.</param>
-        /// <returns>Value of the parameter.</returns>
-        public Vector4 GetVector4(string name)
-        {
-            return Internal_GetVector4(mCachedPtr, name);
-        }
-
-        /// <summary>
-        /// Returns a 3x3 matrix assigned with the parameter with the specified name.
-        /// </summary>
-        /// <param name="name">Name of the shader parameter.</param>
-        /// <returns>Value of the parameter.</returns>
-        public Matrix3 GetMatrix3(string name)
-        {
-            return Internal_GetMatrix3(mCachedPtr, name);
-        }
-
-        /// <summary>
-        /// Returns a 4x4 matrix assigned with the parameter with the specified name.
-        /// </summary>
-        /// <param name="name">Name of the shader parameter.</param>
-        /// <returns>Value of the parameter.</returns>
-        public Matrix4 GetMatrix4(string name)
-        {
-            return Internal_GetMatrix4(mCachedPtr, name);
-        }
-
-        /// <summary>
-        /// Returns a color assigned with the parameter with the specified name.
-        /// </summary>
-        /// <param name="name">Name of the shader parameter.</param>
-        /// <returns>Value of the parameter.</returns>
-        public Color GetColor(string name)
-        {
-            return Internal_GetColor(mCachedPtr, name);
-        }
-
-        /// <summary>
-        /// Returns a 2D texture assigned with the parameter with the specified name.
-        /// </summary>
-        /// <param name="name">Name of the shader parameter.</param>
-        /// <returns>Value of the parameter.</returns>
-        public Texture2D GetTexture2D(string name)
-        {
-            return Internal_GetTexture2D(mCachedPtr, name);
-        }
-
-        /// <summary>
-        /// Returns a 3D texture assigned with the parameter with the specified name.
-        /// </summary>
-        /// <param name="name">Name of the shader parameter.</param>
-        /// <returns>Value of the parameter.</returns>
-        public Texture3D GetTexture3D(string name)
-        {
-            return Internal_GetTexture3D(mCachedPtr, name);
-        }
-
-        /// <summary>
-        /// Returns a cube texture assigned with the parameter with the specified name.
-        /// </summary>
-        /// <param name="name">Name of the shader parameter.</param>
-        /// <returns>Value of the parameter.</returns>
-        public TextureCube GetTextureCube(string name)
-        {
-            return Internal_GetTextureCube(mCachedPtr, name);
-        }
-
-        /// <summary>
-        /// Creates a deep copy of the material.
-        /// </summary>
-        /// <returns>A new object with exact data as this object.</returns>
-        public Material Clone()
-        {
-            return Internal_Clone(mCachedPtr);
-        }
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_CreateInstance(Material instance, IntPtr shader);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Shader Internal_GetShader(IntPtr nativeInstance);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetShader(IntPtr nativeInstance, IntPtr shader);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetFloat(IntPtr nativeInstance, string name, float value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetVector2(IntPtr nativeInstance, string name, Vector2 value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetVector3(IntPtr nativeInstance, string name, Vector3 value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetVector4(IntPtr nativeInstance, string name, Vector4 value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetMatrix3(IntPtr nativeInstance, string name, Matrix3 value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetMatrix4(IntPtr nativeInstance, string name, Matrix4 value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetColor(IntPtr nativeInstance, string name, Color value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetTexture2D(IntPtr nativeInstance, string name, IntPtr value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetTexture3D(IntPtr nativeInstance, string name, IntPtr value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetTextureCube(IntPtr nativeInstance, string name, IntPtr value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern float Internal_GetFloat(IntPtr nativeInstance, string name);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Vector2 Internal_GetVector2(IntPtr nativeInstance, string name);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Vector3 Internal_GetVector3(IntPtr nativeInstance, string name);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Vector4 Internal_GetVector4(IntPtr nativeInstance, string name);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Matrix3 Internal_GetMatrix3(IntPtr nativeInstance, string name);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Matrix4 Internal_GetMatrix4(IntPtr nativeInstance, string name);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Color Internal_GetColor(IntPtr nativeInstance, string name);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Texture2D Internal_GetTexture2D(IntPtr nativeInstance, string name);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Texture3D Internal_GetTexture3D(IntPtr nativeInstance, string name);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern TextureCube Internal_GetTextureCube(IntPtr nativeInstance, string name);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Material Internal_Clone(IntPtr nativeInstance);
-    }
-}
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Text;
+
+namespace BansheeEngine
+{
+    /// <summary>
+    /// Material that controls how objects are rendered. It is represented by a shader and parameters used to set up that 
+    /// shader. It provides a simple interface for manipulating the parameters.
+    /// </summary>
+    public class Material : Resource
+    {
+        /// <summary>
+        /// Creates a new empty material that references no shader.
+        /// </summary>
+        public Material()
+        {
+            Internal_CreateInstance(this, IntPtr.Zero);
+        }
+
+        /// <summary>
+        /// Constructor for internal runtime use only.
+        /// </summary>
+        /// <param name="dummy">Dummy parameter to differentiate it from other constructors.</param>
+        private Material(bool dummy)
+        { }
+
+        /// <summary>
+        /// Creates a new material with the specified shader.
+        /// </summary>
+        /// <param name="shader">Shader to initialize the material with.</param>
+        public Material(Shader shader)
+        {
+            IntPtr nativeShader = IntPtr.Zero;
+            if (shader != null)
+                nativeShader = shader.GetCachedPtr();
+
+            Internal_CreateInstance(this, nativeShader);
+        }
+
+        /// <summary>
+        /// Shader used by the material. Best technique from the shader will be used for rendering, depending on currently
+        /// active renderer and render API.
+        /// </summary>
+        public Shader Shader
+        {
+            get { return Internal_GetShader(mCachedPtr); }
+            set
+            {
+                IntPtr nativeShader = IntPtr.Zero;
+                if (value != null)
+                    nativeShader = value.GetCachedPtr();
+
+                Internal_SetShader(mCachedPtr, nativeShader); 
+            }
+        }
+
+        /// <summary>
+        /// Assigns a float value to the shader parameter with the specified name.
+        /// </summary>
+        /// <param name="name">Name of the shader parameter.</param>
+        /// <param name="value">Value of the parameter.</param>
+        public void SetFloat(string name, float value)
+        {
+            Internal_SetFloat(mCachedPtr, name, value);
+        }
+
+        /// <summary>
+        /// Assigns a 2D vector to the shader parameter with the specified name.
+        /// </summary>
+        /// <param name="name">Name of the shader parameter.</param>
+        /// <param name="value">Value of the parameter.</param>
+        public void SetVector2(string name, Vector2 value)
+        {
+            Internal_SetVector2(mCachedPtr, name, ref value);
+        }
+
+        /// <summary>
+        /// Assigns a 3D vector to the shader parameter with the specified name.
+        /// </summary>
+        /// <param name="name">Name of the shader parameter.</param>
+        /// <param name="value">Value of the parameter.</param>
+        public void SetVector3(string name, Vector3 value)
+        {
+            Internal_SetVector3(mCachedPtr, name, ref value);
+        }
+
+        /// <summary>
+        /// Assigns a 4D vector to the shader parameter with the specified name.
+        /// </summary>
+        /// <param name="name">Name of the shader parameter.</param>
+        /// <param name="value">Value of the parameter.</param>
+        public void SetVector4(string name, Vector4 value)
+        {
+            Internal_SetVector4(mCachedPtr, name, ref value);
+        }
+
+        /// <summary>
+        /// Assigns a 3x3 matrix to the shader parameter with the specified name.
+        /// </summary>
+        /// <param name="name">Name of the shader parameter.</param>
+        /// <param name="value">Value of the parameter.</param>
+        public void SetMatrix3(string name, Matrix3 value)
+        {
+            Internal_SetMatrix3(mCachedPtr, name, ref value);
+        }
+
+        /// <summary>
+        /// Assigns a 4x4 matrix to the shader parameter with the specified name.
+        /// </summary>
+        /// <param name="name">Name of the shader parameter.</param>
+        /// <param name="value">Value of the parameter.</param>
+        public void SetMatrix4(string name, Matrix4 value)
+        {
+            Internal_SetMatrix4(mCachedPtr, name, ref value);
+        }
+
+        /// <summary>
+        /// Assigns a color to the shader parameter with the specified name.
+        /// </summary>
+        /// <param name="name">Name of the shader parameter.</param>
+        /// <param name="value">Value of the parameter.</param>
+        public void SetColor(string name, Color value)
+        {
+            Internal_SetColor(mCachedPtr, name, ref value);
+        }
+
+        /// <summary>
+        /// Assigns a 2D texture to the shader parameter with the specified name.
+        /// </summary>
+        /// <param name="name">Name of the shader parameter.</param>
+        /// <param name="value">Value of the parameter.</param>
+        public void SetTexture2D(string name, Texture2D value)
+        {
+            IntPtr texturePtr = IntPtr.Zero;
+            if (value != null)
+                texturePtr = value.GetCachedPtr();
+
+            Internal_SetTexture2D(mCachedPtr, name, texturePtr);
+        }
+
+        /// <summary>
+        /// Assigns a 3D texture to the shader parameter with the specified name.
+        /// </summary>
+        /// <param name="name">Name of the shader parameter.</param>
+        /// <param name="value">Value of the parameter.</param>
+        public void SetTexture3D(string name, Texture3D value)
+        {
+            IntPtr texturePtr = IntPtr.Zero;
+            if (value != null)
+                texturePtr = value.GetCachedPtr();
+
+            Internal_SetTexture3D(mCachedPtr, name, texturePtr);
+        }
+
+        /// <summary>
+        /// Assigns a cube texture to the shader parameter with the specified name.
+        /// </summary>
+        /// <param name="name">Name of the shader parameter.</param>
+        /// <param name="value">Value of the parameter.</param>
+        public void SetTextureCube(string name, TextureCube value)
+        {
+            IntPtr texturePtr = IntPtr.Zero;
+            if (value != null)
+                texturePtr = value.GetCachedPtr();
+
+            Internal_SetTextureCube(mCachedPtr, name, texturePtr);
+        }
+
+        /// <summary>
+        /// Returns a float value assigned with the parameter with the specified name.
+        /// </summary>
+        /// <param name="name">Name of the shader parameter.</param>
+        /// <returns>Value of the parameter.</returns>
+        public float GetFloat(string name)
+        {
+            return Internal_GetFloat(mCachedPtr, name);
+        }
+
+        /// <summary>
+        /// Returns a 2D vector assigned with the parameter with the specified name.
+        /// </summary>
+        /// <param name="name">Name of the shader parameter.</param>
+        /// <returns>Value of the parameter.</returns>
+        public Vector2 GetVector2(string name)
+        {
+            Vector2 value;
+            Internal_GetVector2(mCachedPtr, name, out value);
+            return value;
+        }
+
+        /// <summary>
+        /// Returns a 3D vector assigned with the parameter with the specified name.
+        /// </summary>
+        /// <param name="name">Name of the shader parameter.</param>
+        /// <returns>Value of the parameter.</returns>
+        public Vector3 GetVector3(string name)
+        {
+            Vector3 value;
+            Internal_GetVector3(mCachedPtr, name, out value);
+            return value;
+        }
+
+        /// <summary>
+        /// Returns a 4D vector assigned with the parameter with the specified name.
+        /// </summary>
+        /// <param name="name">Name of the shader parameter.</param>
+        /// <returns>Value of the parameter.</returns>
+        public Vector4 GetVector4(string name)
+        {
+            Vector4 value;
+            Internal_GetVector4(mCachedPtr, name, out value);
+            return value;
+        }
+
+        /// <summary>
+        /// Returns a 3x3 matrix assigned with the parameter with the specified name.
+        /// </summary>
+        /// <param name="name">Name of the shader parameter.</param>
+        /// <returns>Value of the parameter.</returns>
+        public Matrix3 GetMatrix3(string name)
+        {
+            Matrix3 value;
+            Internal_GetMatrix3(mCachedPtr, name, out value);
+            return value;
+        }
+
+        /// <summary>
+        /// Returns a 4x4 matrix assigned with the parameter with the specified name.
+        /// </summary>
+        /// <param name="name">Name of the shader parameter.</param>
+        /// <returns>Value of the parameter.</returns>
+        public Matrix4 GetMatrix4(string name)
+        {
+            Matrix4 value;
+            Internal_GetMatrix4(mCachedPtr, name, out value);
+            return value;
+        }
+
+        /// <summary>
+        /// Returns a color assigned with the parameter with the specified name.
+        /// </summary>
+        /// <param name="name">Name of the shader parameter.</param>
+        /// <returns>Value of the parameter.</returns>
+        public Color GetColor(string name)
+        {
+            Color value;
+            Internal_GetColor(mCachedPtr, name, out value);
+            return value;
+        }
+
+        /// <summary>
+        /// Returns a 2D texture assigned with the parameter with the specified name.
+        /// </summary>
+        /// <param name="name">Name of the shader parameter.</param>
+        /// <returns>Value of the parameter.</returns>
+        public Texture2D GetTexture2D(string name)
+        {
+            return Internal_GetTexture2D(mCachedPtr, name);
+        }
+
+        /// <summary>
+        /// Returns a 3D texture assigned with the parameter with the specified name.
+        /// </summary>
+        /// <param name="name">Name of the shader parameter.</param>
+        /// <returns>Value of the parameter.</returns>
+        public Texture3D GetTexture3D(string name)
+        {
+            return Internal_GetTexture3D(mCachedPtr, name);
+        }
+
+        /// <summary>
+        /// Returns a cube texture assigned with the parameter with the specified name.
+        /// </summary>
+        /// <param name="name">Name of the shader parameter.</param>
+        /// <returns>Value of the parameter.</returns>
+        public TextureCube GetTextureCube(string name)
+        {
+            return Internal_GetTextureCube(mCachedPtr, name);
+        }
+
+        /// <summary>
+        /// Creates a deep copy of the material.
+        /// </summary>
+        /// <returns>A new object with exact data as this object.</returns>
+        public Material Clone()
+        {
+            return Internal_Clone(mCachedPtr);
+        }
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_CreateInstance(Material instance, IntPtr shader);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern Shader Internal_GetShader(IntPtr nativeInstance);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetShader(IntPtr nativeInstance, IntPtr shader);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetFloat(IntPtr nativeInstance, string name, float value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetVector2(IntPtr nativeInstance, string name, ref Vector2 value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetVector3(IntPtr nativeInstance, string name, ref Vector3 value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetVector4(IntPtr nativeInstance, string name, ref Vector4 value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetMatrix3(IntPtr nativeInstance, string name, ref Matrix3 value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetMatrix4(IntPtr nativeInstance, string name, ref Matrix4 value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetColor(IntPtr nativeInstance, string name, ref Color value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetTexture2D(IntPtr nativeInstance, string name, IntPtr value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetTexture3D(IntPtr nativeInstance, string name, IntPtr value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetTextureCube(IntPtr nativeInstance, string name, IntPtr value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern float Internal_GetFloat(IntPtr nativeInstance, string name);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetVector2(IntPtr nativeInstance, string name, out Vector2 value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetVector3(IntPtr nativeInstance, string name, out Vector3 value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetVector4(IntPtr nativeInstance, string name, out Vector4 value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetMatrix3(IntPtr nativeInstance, string name, out Matrix3 value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetMatrix4(IntPtr nativeInstance, string name, out Matrix4 value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetColor(IntPtr nativeInstance, string name, out Color value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern Texture2D Internal_GetTexture2D(IntPtr nativeInstance, string name);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern Texture3D Internal_GetTexture3D(IntPtr nativeInstance, string name);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern TextureCube Internal_GetTextureCube(IntPtr nativeInstance, string name);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern Material Internal_Clone(IntPtr nativeInstance);
+    }
+}

+ 468 - 353
MBansheeEngine/NativeCamera.cs

@@ -1,353 +1,468 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Runtime.CompilerServices;
-using System.Text;
-
-namespace BansheeEngine
-{
-    /// <summary>
-    /// Projection type to use by the camera.
-    /// </summary>
-    public enum ProjectionType // Note: Must match C++ enum ProjectionType
-    {
-        /// <summary>
-        /// Projection type where object size remains constant and parallel lines remain parallel.
-        /// </summary>
-        Orthographic, 
-
-        /// <summary>
-        /// Projection type that emulates human vision. Objects farther away appear smaller.
-        /// </summary>
-        Perspective
-    }
-
-    /// <summary>
-    /// Flags that specify which portions, if any, of the viewport are to be cleared before rendering.
-    /// </summary>
-    [Flags]
-    public enum ClearFlags // Don't reorder, used by native code
-    {
-        None = 0, Color = 0x01, Depth = 0x02, Stencil = 0x04
-    }
-
-    /// <summary>
-    /// Wrapper around the native Camera class.
-    /// <see cref="Camera"/>
-    /// </summary>
-    internal class NativeCamera : ScriptObject
-    {
-        internal float aspectRatio
-        {
-            get { return Internal_GetAspect(mCachedPtr); }
-            set { Internal_SetAspect(mCachedPtr, value); }
-        }
-
-        internal float nearClipPlane
-        {
-            get { return Internal_GetNearClip(mCachedPtr); }
-            set { Internal_SetNearClip(mCachedPtr, value); }
-        }
-
-        internal float farClipPlane
-        {
-            get { return Internal_GetFarClip(mCachedPtr); }
-            set { Internal_SetFarClip(mCachedPtr, value); }
-        }
-
-        internal Degree fieldOfView
-        {
-            get { Degree value; Internal_GetFieldOfView(mCachedPtr, out value); return value; }
-            set { Internal_SetFieldOfView(mCachedPtr, value); }
-        }
-
-        internal Rect2 viewportRect
-        {
-            get { return Internal_GetViewportRect(mCachedPtr); }
-            set { Internal_SetViewportRect(mCachedPtr, value); }
-        }
-
-        internal ProjectionType projectionType
-        {
-            get { return Internal_GetProjectionType(mCachedPtr); }
-            set { Internal_SetProjectionType(mCachedPtr, value); }
-        }
-
-        internal float orthoHeight
-        {
-            get { return Internal_GetOrthographicHeight(mCachedPtr); }
-            set { Internal_SetOrthographicHeight(mCachedPtr, value); }
-        }
-
-        internal float orthoWidth
-        {
-            get { return Internal_GetOrthographicWidth(mCachedPtr); }
-        }
-
-        internal Color clearColor
-        {
-            get { return Internal_GetClearColor(mCachedPtr); }
-            set { Internal_SetClearColor(mCachedPtr, value); }
-        }
-
-        internal float clearDepth
-        {
-            get { return Internal_GetDepthClearValue(mCachedPtr); }
-            set { Internal_SetDepthClearValue(mCachedPtr, value); }
-        }
-
-        internal UInt16 clearStencil
-        {
-            get { return Internal_GetStencilClearValue(mCachedPtr); }
-            set { Internal_SetStencilClearValue(mCachedPtr, value); }
-        }
-
-        internal ClearFlags clearFlags
-        {
-            get { return Internal_GetClearFlags(mCachedPtr); }
-            set { Internal_SetClearFlags(mCachedPtr, value); }
-        }
-
-        internal int priority
-        {
-            get { return Internal_GetPriority(mCachedPtr); }
-            set { Internal_SetPriority(mCachedPtr, value); }
-        }
-
-        internal UInt64 layers
-        {
-            get { return Internal_GetLayers(mCachedPtr); }
-            set { Internal_SetLayers(mCachedPtr, value); }
-        }
-
-        internal Matrix4 projMatrix
-        {
-            get { return Internal_GetProjMatrix(mCachedPtr); }
-        }
-
-        internal Matrix4 projMatrixInv
-        {
-            get { return Internal_GetProjMatrixInv(mCachedPtr); }
-        }
-
-        internal Matrix4 viewMatrix
-        {
-            get { return Internal_GetViewMatrix(mCachedPtr); }
-        }
-
-        internal Matrix4 viewMatrixInv
-        {
-            get { return Internal_GetViewMatrixInv(mCachedPtr); }
-        }
-
-        internal int widthPixels
-        {
-            get { return Internal_GetWidthPixels(mCachedPtr); }
-        }
-
-        internal int heightPixels
-        {
-            get { return Internal_GetHeightPixels(mCachedPtr); }
-        }
-
-        internal RenderTarget target
-        {
-            get
-            {
-                return _target;
-            }
-            set
-            {
-                _target = value;
-
-                IntPtr targetPtr = IntPtr.Zero;
-                if (_target != null)
-                    targetPtr = _target.mCachedPtr;
-
-                Internal_SetRenderTarget(mCachedPtr, targetPtr);
-            }
-        }
-
-        internal bool main
-        {
-            get { return Internal_GetMain(mCachedPtr); }
-            set { Internal_SetMain(mCachedPtr, value); }
-        }
-
-        internal Vector2I WorldToScreen(Vector3 value) { return Internal_WorldToScreen(mCachedPtr, value); }
-        internal Vector2 WorldToClip(Vector3 value) { return Internal_WorldToClip(mCachedPtr, value); }
-        internal Vector3 WorldToView(Vector3 value) { return Internal_WorldToView(mCachedPtr, value); }
-
-        internal Vector3 ScreenToWorld(Vector2I value, float depth) { return Internal_ScreenToWorld(mCachedPtr, value, depth); }
-        internal Vector3 ScreenToView(Vector2I value, float depth) { return Internal_ScreenToView(mCachedPtr, value, depth); }
-        internal Vector2 ScreenToClip(Vector2I value) { return Internal_ScreenToClip(mCachedPtr, value); }
-
-        internal Vector3 ViewToWorld(Vector3 value) { return Internal_ViewToWorld(mCachedPtr, value); }
-        internal Vector2I ViewToScreen(Vector3 value) { return Internal_ViewToScreen(mCachedPtr, value); }
-        internal Vector2 ViewToClip(Vector3 value) { return Internal_ViewToClip(mCachedPtr, value); }
-
-        internal Vector3 ClipToWorld(Vector2 value, float depth) { return Internal_ClipToWorld(mCachedPtr, value, depth); }
-        internal Vector3 ClipToView(Vector2 value, float depth) { return Internal_ClipToView(mCachedPtr, value, depth); }
-        internal Vector2I ClipToScreen(Vector2 value) { return Internal_ClipToScreen(mCachedPtr, value); }
-
-        internal Ray ScreenToWorldRay(Vector2I value) { return Internal_ScreenToWorldRay(mCachedPtr, value); }
-        internal Vector3 ProjectPoint(Vector3 value) { return Internal_ProjectPoint(mCachedPtr, value); }
-        internal Vector3 UnprojectPoint(Vector3 value) { return Internal_UnprojectPoint(mCachedPtr, value); }
-
-        private RenderTarget _target;
-
-        public NativeCamera(SceneObject sceneObject)
-        {
-            IntPtr sceneObjPtr = IntPtr.Zero;
-            if (sceneObject != null)
-                sceneObjPtr = sceneObject.GetCachedPtr();
-
-            Internal_Create(this, sceneObjPtr);
-        }
-
-        internal void UpdateView(SceneObject sceneObject)
-        {
-            Internal_UpdateView(mCachedPtr, sceneObject.mCachedPtr);
-        }
-
-        internal void OnDestroy()
-        {
-            Internal_OnDestroy(mCachedPtr);
-        }
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_Create(NativeCamera instance, IntPtr parentSO);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern float Internal_GetAspect(IntPtr instance);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetAspect(IntPtr instance, float value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern float Internal_GetNearClip(IntPtr instance);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetNearClip(IntPtr instance, float value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern float Internal_GetFarClip(IntPtr instance);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetFarClip(IntPtr instance, float value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_GetFieldOfView(IntPtr instance, out Degree value);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetFieldOfView(IntPtr instance, Degree value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Rect2 Internal_GetViewportRect(IntPtr instance);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetViewportRect(IntPtr instance, Rect2 value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern ProjectionType Internal_GetProjectionType(IntPtr instance);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetProjectionType(IntPtr instance, ProjectionType value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern float Internal_GetOrthographicHeight(IntPtr instance);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetOrthographicHeight(IntPtr instance, float value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern float Internal_GetOrthographicWidth(IntPtr instance);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Color Internal_GetClearColor(IntPtr instance);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetClearColor(IntPtr instance, Color value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern float Internal_GetDepthClearValue(IntPtr instance);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetDepthClearValue(IntPtr instance, float value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern UInt16 Internal_GetStencilClearValue(IntPtr instance);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetStencilClearValue(IntPtr instance, UInt16 value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern ClearFlags Internal_GetClearFlags(IntPtr instance);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetClearFlags(IntPtr instance, ClearFlags value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern int Internal_GetPriority(IntPtr instance);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetPriority(IntPtr instance, int value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern UInt64 Internal_GetLayers(IntPtr instance);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetLayers(IntPtr instance, UInt64 value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Matrix4 Internal_GetProjMatrix(IntPtr instance);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Matrix4 Internal_GetProjMatrixInv(IntPtr instance);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Matrix4 Internal_GetViewMatrix(IntPtr instance);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Matrix4 Internal_GetViewMatrixInv(IntPtr instance);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern int Internal_GetWidthPixels(IntPtr instance);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern int Internal_GetHeightPixels(IntPtr instance);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Vector2I Internal_WorldToScreen(IntPtr instance, Vector3 value);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Vector2 Internal_WorldToClip(IntPtr instance, Vector3 value);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Vector3 Internal_WorldToView(IntPtr instance, Vector3 value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Vector3 Internal_ScreenToWorld(IntPtr instance, Vector2I value, float depth);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Vector3 Internal_ScreenToView(IntPtr instance, Vector2I value, float depth);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Vector2 Internal_ScreenToClip(IntPtr instance, Vector2I value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Vector3 Internal_ViewToWorld(IntPtr instance, Vector3 value);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Vector2I Internal_ViewToScreen(IntPtr instance, Vector3 value);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Vector2 Internal_ViewToClip(IntPtr instance, Vector3 value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Vector3 Internal_ClipToWorld(IntPtr instance, Vector2 value, float depth);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Vector3 Internal_ClipToView(IntPtr instance, Vector2 value, float depth);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Vector2I Internal_ClipToScreen(IntPtr instance, Vector2 value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Ray Internal_ScreenToWorldRay(IntPtr instance, Vector2I value);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Vector3 Internal_ProjectPoint(IntPtr instance, Vector3 value);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern Vector3 Internal_UnprojectPoint(IntPtr instance, Vector3 value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetRenderTarget(IntPtr instance, IntPtr rt);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern bool Internal_GetMain(IntPtr instance);
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetMain(IntPtr instance, bool main);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_UpdateView(IntPtr instance, IntPtr parentSO);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_OnDestroy(IntPtr thisPtr);
-    }
-}
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Text;
+
+namespace BansheeEngine
+{
+    /// <summary>
+    /// Projection type to use by the camera.
+    /// </summary>
+    public enum ProjectionType // Note: Must match C++ enum ProjectionType
+    {
+        /// <summary>
+        /// Projection type where object size remains constant and parallel lines remain parallel.
+        /// </summary>
+        Orthographic, 
+
+        /// <summary>
+        /// Projection type that emulates human vision. Objects farther away appear smaller.
+        /// </summary>
+        Perspective
+    }
+
+    /// <summary>
+    /// Flags that specify which portions, if any, of the viewport are to be cleared before rendering.
+    /// </summary>
+    [Flags]
+    public enum ClearFlags // Don't reorder, used by native code
+    {
+        None = 0, Color = 0x01, Depth = 0x02, Stencil = 0x04
+    }
+
+    /// <summary>
+    /// Wrapper around the native Camera class.
+    /// <see cref="Camera"/>
+    /// </summary>
+    internal class NativeCamera : ScriptObject
+    {
+        internal float aspectRatio
+        {
+            get { return Internal_GetAspect(mCachedPtr); }
+            set { Internal_SetAspect(mCachedPtr, value); }
+        }
+
+        internal float nearClipPlane
+        {
+            get { return Internal_GetNearClip(mCachedPtr); }
+            set { Internal_SetNearClip(mCachedPtr, value); }
+        }
+
+        internal float farClipPlane
+        {
+            get { return Internal_GetFarClip(mCachedPtr); }
+            set { Internal_SetFarClip(mCachedPtr, value); }
+        }
+
+        internal Degree fieldOfView
+        {
+            get { Degree value; Internal_GetFieldOfView(mCachedPtr, out value); return value; }
+            set { Internal_SetFieldOfView(mCachedPtr, value); }
+        }
+
+        internal Rect2 viewportRect
+        {
+            get
+            {
+                Rect2 value;
+                Internal_GetViewportRect(mCachedPtr, out value);
+                return value;
+            }
+            set { Internal_SetViewportRect(mCachedPtr, ref value); }
+        }
+
+        internal ProjectionType projectionType
+        {
+            get { return Internal_GetProjectionType(mCachedPtr); }
+            set { Internal_SetProjectionType(mCachedPtr, value); }
+        }
+
+        internal float orthoHeight
+        {
+            get { return Internal_GetOrthographicHeight(mCachedPtr); }
+            set { Internal_SetOrthographicHeight(mCachedPtr, value); }
+        }
+
+        internal float orthoWidth
+        {
+            get { return Internal_GetOrthographicWidth(mCachedPtr); }
+        }
+
+        internal Color clearColor
+        {
+            get
+            {
+                Color value;
+                Internal_GetClearColor(mCachedPtr, out value);
+                return value;
+            }
+            set { Internal_SetClearColor(mCachedPtr, ref value); }
+        }
+
+        internal float clearDepth
+        {
+            get { return Internal_GetDepthClearValue(mCachedPtr); }
+            set { Internal_SetDepthClearValue(mCachedPtr, value); }
+        }
+
+        internal UInt16 clearStencil
+        {
+            get { return Internal_GetStencilClearValue(mCachedPtr); }
+            set { Internal_SetStencilClearValue(mCachedPtr, value); }
+        }
+
+        internal ClearFlags clearFlags
+        {
+            get { return Internal_GetClearFlags(mCachedPtr); }
+            set { Internal_SetClearFlags(mCachedPtr, value); }
+        }
+
+        internal int priority
+        {
+            get { return Internal_GetPriority(mCachedPtr); }
+            set { Internal_SetPriority(mCachedPtr, value); }
+        }
+
+        internal UInt64 layers
+        {
+            get { return Internal_GetLayers(mCachedPtr); }
+            set { Internal_SetLayers(mCachedPtr, value); }
+        }
+
+        internal Matrix4 projMatrix
+        {
+            get
+            {
+                Matrix4 value;
+                Internal_GetProjMatrix(mCachedPtr, out value);
+                return value;
+            }
+        }
+
+        internal Matrix4 projMatrixInv
+        {
+            get
+            {
+                Matrix4 value;
+                Internal_GetProjMatrixInv(mCachedPtr, out value);
+                return value;
+            }
+        }
+
+        internal Matrix4 viewMatrix
+        {
+            get
+            {
+                Matrix4 value;
+                Internal_GetViewMatrix(mCachedPtr, out value);
+                return value;
+            }
+        }
+
+        internal Matrix4 viewMatrixInv
+        {
+            get
+            {
+                Matrix4 value;
+                Internal_GetViewMatrixInv(mCachedPtr, out value);
+                return value;
+            }
+        }
+
+        internal int widthPixels
+        {
+            get { return Internal_GetWidthPixels(mCachedPtr); }
+        }
+
+        internal int heightPixels
+        {
+            get { return Internal_GetHeightPixels(mCachedPtr); }
+        }
+
+        internal RenderTarget target
+        {
+            get
+            {
+                return _target;
+            }
+            set
+            {
+                _target = value;
+
+                IntPtr targetPtr = IntPtr.Zero;
+                if (_target != null)
+                    targetPtr = _target.mCachedPtr;
+
+                Internal_SetRenderTarget(mCachedPtr, targetPtr);
+            }
+        }
+
+        internal bool main
+        {
+            get { return Internal_GetMain(mCachedPtr); }
+            set { Internal_SetMain(mCachedPtr, value); }
+        }
+
+        internal Vector2I WorldToScreen(Vector3 value)
+        {
+            Vector2I output;
+            Internal_WorldToScreen(mCachedPtr, ref value, out output);
+            return output;
+        }
+
+        internal Vector2 WorldToClip(Vector3 value)
+        {
+            Vector2 output;
+            Internal_WorldToClip(mCachedPtr, ref value, out output);
+            return output;
+        }
+
+        internal Vector3 WorldToView(Vector3 value)
+        {
+            Vector3 output;
+            Internal_WorldToView(mCachedPtr, ref value, out output);
+            return output;
+        }
+
+        internal Vector3 ScreenToWorld(Vector2I value, float depth)
+        {
+            Vector3 output;
+            Internal_ScreenToWorld(mCachedPtr, ref value, depth, out output);
+            return output;
+        }
+
+        internal Vector3 ScreenToView(Vector2I value, float depth)
+        {
+            Vector3 output;
+            Internal_ScreenToView(mCachedPtr, ref value, depth, out output);
+            return output;
+        }
+
+        internal Vector2 ScreenToClip(Vector2I value)
+        {
+            Vector2 output;
+            Internal_ScreenToClip(mCachedPtr, ref value, out output);
+            return output;
+        }
+
+        internal Vector3 ViewToWorld(Vector3 value)
+        {
+            Vector3 output;
+            Internal_ViewToWorld(mCachedPtr, ref value, out output);
+            return output;
+        }
+
+        internal Vector2I ViewToScreen(Vector3 value)
+        {
+            Vector2I output;
+            Internal_ViewToScreen(mCachedPtr, ref value, out output);
+            return output;
+        }
+
+        internal Vector2 ViewToClip(Vector3 value)
+        {
+            Vector2 output;
+            Internal_ViewToClip(mCachedPtr, ref value, out output);
+            return output;
+        }
+
+        internal Vector3 ClipToWorld(Vector2 value, float depth)
+        {
+            Vector3 output;
+            Internal_ClipToWorld(mCachedPtr, ref value, depth, out output);
+            return output;
+        }
+
+        internal Vector3 ClipToView(Vector2 value, float depth)
+        {
+            Vector3 output;
+            Internal_ClipToView(mCachedPtr, ref value, depth, out output);
+            return output;
+        }
+
+        internal Vector2I ClipToScreen(Vector2 value)
+        {
+            Vector2I output;
+            Internal_ClipToScreen(mCachedPtr, ref value, out output);
+            return output;
+        }
+
+        internal Ray ScreenToWorldRay(Vector2I value)
+        {
+            Ray output;
+            Internal_ScreenToWorldRay(mCachedPtr, ref value, out output);
+            return output;
+        }
+
+        internal Vector3 ProjectPoint(Vector3 value)
+        {
+            Vector3 output;
+            Internal_ProjectPoint(mCachedPtr, ref value, out output);
+            return output;
+        }
+
+        internal Vector3 UnprojectPoint(Vector3 value)
+        {
+            Vector3 output;
+            Internal_UnprojectPoint(mCachedPtr, ref value, out output);
+            return output;
+        }
+
+        private RenderTarget _target;
+
+        public NativeCamera(SceneObject sceneObject)
+        {
+            IntPtr sceneObjPtr = IntPtr.Zero;
+            if (sceneObject != null)
+                sceneObjPtr = sceneObject.GetCachedPtr();
+
+            Internal_Create(this, sceneObjPtr);
+        }
+
+        internal void UpdateView(SceneObject sceneObject)
+        {
+            Internal_UpdateView(mCachedPtr, sceneObject.mCachedPtr);
+        }
+
+        internal void OnDestroy()
+        {
+            Internal_OnDestroy(mCachedPtr);
+        }
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_Create(NativeCamera instance, IntPtr parentSO);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern float Internal_GetAspect(IntPtr instance);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetAspect(IntPtr instance, float value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern float Internal_GetNearClip(IntPtr instance);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetNearClip(IntPtr instance, float value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern float Internal_GetFarClip(IntPtr instance);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetFarClip(IntPtr instance, float value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetFieldOfView(IntPtr instance, out Degree value);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetFieldOfView(IntPtr instance, Degree value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetViewportRect(IntPtr instance, out Rect2 value);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetViewportRect(IntPtr instance, ref Rect2 value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern ProjectionType Internal_GetProjectionType(IntPtr instance);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetProjectionType(IntPtr instance, ProjectionType value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern float Internal_GetOrthographicHeight(IntPtr instance);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetOrthographicHeight(IntPtr instance, float value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern float Internal_GetOrthographicWidth(IntPtr instance);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetClearColor(IntPtr instance, out Color value);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetClearColor(IntPtr instance, ref Color value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern float Internal_GetDepthClearValue(IntPtr instance);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetDepthClearValue(IntPtr instance, float value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern UInt16 Internal_GetStencilClearValue(IntPtr instance);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetStencilClearValue(IntPtr instance, UInt16 value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern ClearFlags Internal_GetClearFlags(IntPtr instance);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetClearFlags(IntPtr instance, ClearFlags value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern int Internal_GetPriority(IntPtr instance);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetPriority(IntPtr instance, int value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern UInt64 Internal_GetLayers(IntPtr instance);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetLayers(IntPtr instance, UInt64 value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetProjMatrix(IntPtr instance, out Matrix4 output);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetProjMatrixInv(IntPtr instance, out Matrix4 output);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetViewMatrix(IntPtr instance, out Matrix4 output);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetViewMatrixInv(IntPtr instance, out Matrix4 output);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern int Internal_GetWidthPixels(IntPtr instance);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern int Internal_GetHeightPixels(IntPtr instance);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_WorldToScreen(IntPtr instance, ref Vector3 value, out Vector2I output);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_WorldToClip(IntPtr instance, ref Vector3 value, out Vector2 output);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_WorldToView(IntPtr instance, ref Vector3 value, out Vector3 output);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_ScreenToWorld(IntPtr instance, ref Vector2I value, float depth, out Vector3 output);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_ScreenToView(IntPtr instance, ref Vector2I value, float depth, out Vector3 output);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_ScreenToClip(IntPtr instance, ref Vector2I value, out Vector2 output);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_ViewToWorld(IntPtr instance, ref Vector3 value, out Vector3 output);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_ViewToScreen(IntPtr instance, ref Vector3 value, out Vector2I output);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_ViewToClip(IntPtr instance, ref Vector3 value, out Vector2 output);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_ClipToWorld(IntPtr instance, ref Vector2 value, float depth, out Vector3 output);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_ClipToView(IntPtr instance, ref Vector2 value, float depth, out Vector3 output);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_ClipToScreen(IntPtr instance, ref Vector2 value, out Vector2I output);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_ScreenToWorldRay(IntPtr instance, ref Vector2I value, out Ray output);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_ProjectPoint(IntPtr instance, ref Vector3 value, out Vector3 output);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_UnprojectPoint(IntPtr instance, ref Vector3 value, out Vector3 output);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetRenderTarget(IntPtr instance, IntPtr rt);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern bool Internal_GetMain(IntPtr instance);
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetMain(IntPtr instance, bool main);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_UpdateView(IntPtr instance, IntPtr parentSO);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_OnDestroy(IntPtr thisPtr);
+    }
+}

+ 443 - 439
MBansheeEngine/PixelData.cs

@@ -1,439 +1,443 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Text;
-
-namespace BansheeEngine
-{
-    /// <summary>
-    /// Pixel formats usable by images, textures and render surfaces.
-    /// </summary>
-    public enum PixelFormat // Note: Must match C++ enum PixelFormat
-    {
-        /// <summary>
-        /// 8-bit pixel format, all bits red.
-        /// </summary>
-        R8 = 1,
-        /// <summary>
-        /// 2 byte pixel format, 1 byte red, 1 byte green.
-        /// </summary>
-        R8G8 = 2,
-        /// <summary>
-        /// 24-bit pixel format, 8 bits for red, green and blue.
-        /// </summary>
-        R8G8B8 = 3,
-        /// <summary>
-        /// 32-bit pixel format, 8 bits for red, green, blue and alpha.
-        /// </summary>
-        R8G8B8A8 = 8,
-        /// <summary>
-        /// DXT1/BC1 format containing opaque RGB or 1-bit alpha RGB. 4 bits per pixel.
-        /// </summary>
-        BC1 = 13,
-        /// <summary>
-        /// DXT3/BC2 format containing RGB with premultiplied alpha. 4 bits per pixel.
-        /// </summary>
-        BC1a = 14,
-        /// <summary>
-        /// DXT3/BC2 format containing RGB with explicit alpha. 8 bits per pixel.
-        /// </summary>
-        BC2 = 15,
-        /// <summary>
-        /// DXT5/BC2 format containing RGB with explicit alpha. 8 bits per pixel. Better alpha gradients than BC2.
-        /// </summary>
-        BC3 = 16,
-        /// <summary>
-        /// One channel compressed format. 4 bits per pixel.
-        /// </summary>
-        BC4 = 17,
-        /// <summary>
-        /// Two channel compressed format. 8 bits per pixel.
-        /// </summary>
-        BC5 = 18,
-        /// <summary>
-        /// Format storing RGB in half (16-bit) floating point format usable for HDR. 8 bits per pixel.
-        /// </summary>
-        BC6H = 19,
-        /// <summary>
-        /// Format storing RGB with optional alpha channel. Similar to BC1/BC2/BC3 formats but with higher quality and 
-        /// higher decompress overhead. 8 bits per pixel.
-        /// </summary>
-        BC7 = 20,
-        /// <summary>
-        /// 16-bit pixel format, 16 bits (float) for red.
-        /// </summary>
-        Float16_R = 21,
-        /// <summary>
-        /// 32-bit, 2-channel s10e5 floating point pixel format, 16-bit red, 16-bit green.
-        /// </summary>
-        Float16_RG = 22,
-        /// <summary>
-        /// 48-bit pixel format, 16 bits (float) for red, 16 bits (float) for green, 16 bits (float) for blue.
-        /// </summary>
-        Float16_RGB = 23,
-        /// <summary>
-        /// 64-bit pixel format, 16 bits (float) for red, 16 bits (float) for green, 16 bits (float) for blue, 16 bits 
-        /// (float) for alpha.
-        /// </summary>
-        Float16_RGBA = 24,
-        /// <summary>
-        /// 32-bit pixel format, 32 bits (float) for red.
-        /// </summary>
-        Float32_R = 25,
-        /// <summary>
-        /// 64-bit, 2-channel floating point pixel format, 32-bit red, 32-bit green.
-        /// </summary>
-        Float32_RG = 26,
-        /// <summary>
-        /// 96-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue.
-        /// </summary>
-        Float32_RGB = 27,
-        /// <summary>
-        /// 128-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue, 
-        /// 32 bits (float) for alpha.
-        /// </summary>
-        Float32_RGBA = 28,
-        /// <summary>
-        /// Depth stencil format, 32bit depth, 8bit stencil + 24 unused.
-        /// </summary>
-        D32_S8X24 = 29,
-        /// <summary>
-        /// Depth stencil fomrat, 24bit depth + 8bit stencil.
-        /// </summary>
-        D24S8 = 30,
-        /// <summary>
-        /// Depth format, 32bits.
-        /// </summary>
-        D32 = 31,
-        /// <summary>
-        /// Depth format, 16bits.
-        /// </summary>
-        D16 = 32
-    };
-
-    /// <summary>
-    /// A buffer describing a volume (3D), image (2D) or line (1D) of pixels in memory. Pixels are stored as a succession 
-    /// of "depth" slices, each containing "height" rows of "width" pixels.
-    /// </summary>
-    public sealed class PixelData : ScriptObject
-    {
-        /// <summary>
-        /// Width, height and depth of the pixels this object is capable of holding.
-        /// </summary>
-        public PixelVolume Extents
-        {
-            get
-            {
-                PixelVolume volume;
-                Internal_GetExtents(mCachedPtr, out volume);
-                return volume;
-            }
-        }
-
-        /// <summary>
-        /// Format of the pixels in the buffer.
-        /// </summary>
-        public PixelFormat Format
-        {
-            get
-            {
-                PixelFormat format;
-                Internal_GetFormat(mCachedPtr, out format);
-                return format;
-            }
-        }
-
-        /// <summary>
-        /// Returns number of bytes per a row of pixels.
-        /// </summary>
-        public int RawRowPitch
-        {
-            get
-            {
-                int rowPitch;
-                Internal_GetRowPitch(mCachedPtr, out rowPitch);
-                return rowPitch;
-            }
-        }
-
-        /// <summary>
-        /// Returns number of bytes per a 2D slice/plane of pixels.
-        /// </summary>
-        public int RawSlicePitch
-        {
-            get
-            {
-                int slicePitch;
-                Internal_GetSlicePitch(mCachedPtr, out slicePitch);
-                return slicePitch;
-            }
-        }
-
-        /// <summary>
-        /// Returns total number of bytes used by all the pixels.
-        /// </summary>
-        public int RawSize
-        {
-            get
-            {
-                int size;
-                Internal_GetSize(mCachedPtr, out size);
-                return size;
-            }
-        }
-
-        /// <summary>
-        /// Checks are the pixels in the buffer consecutive. If this is false then the buffer has padding and you should
-        /// check <see cref="RawRowPitch"/> and <see cref="RawSlicePitch"/> when accessing it directly.
-        /// </summary>
-        public bool RawIsConsecutive
-        {
-            get
-            {
-                bool isConsecutive;
-                Internal_GetIsConsecutive(mCachedPtr, out isConsecutive);
-                return isConsecutive;
-            }
-        }
-
-        /// <summary>
-        /// Constructor for internal use by the runtime.
-        /// </summary>
-        private PixelData()
-        { }
-
-        /// <summary>
-        /// Creates a new pixel data buffer capable of storing the specified amount of pixels.
-        /// </summary>
-        /// <param name="volume">Width, height and depth determining number of pixels to store.</param>
-        /// <param name="format">Format of individual pixels.</param>
-        public PixelData(PixelVolume volume, PixelFormat format = PixelFormat.R8G8B8A8)
-        {
-            Internal_CreateInstance(this, volume, format);
-        }
-
-        /// <summary>
-        /// Creates a new 2D pixel data buffer capable of storing the specified amount of pixels.
-        /// </summary>
-        /// <param name="width">Number of pixels in each row.</param>
-        /// <param name="height">Number of pixels in each column.</param>
-        /// <param name="format">Format of individual pixels.</param>
-        public PixelData(int width, int height, PixelFormat format = PixelFormat.R8G8B8A8)
-        {
-            Internal_CreateInstance(this, new PixelVolume(0, 0, width, height), format);
-        }
-
-        /// <summary>
-        /// Creates a new 3D pixel data buffer capable of storing the specified amount of pixels.
-        /// </summary>
-        /// <param name="width">Number of pixels in each row.</param>
-        /// <param name="height">Number of pixels in each column.</param>
-        /// <param name="depth">Number of 2D slices.</param>
-        /// <param name="format">Format of individual pixels.</param>
-        public PixelData(int width, int height, int depth, PixelFormat format = PixelFormat.R8G8B8A8)
-        {
-            Internal_CreateInstance(this, new PixelVolume(0, 0, 0, width, height, depth), format);
-        }
-
-        /// <summary>
-        /// Returns a pixel at the specified location in the buffer.
-        /// </summary>
-        /// <param name="x">X coordinate of the pixel.</param>
-        /// <param name="y">Y coordinate of the pixel.</param>
-        /// <param name="z">Z coordinate of the pixel.</param>
-        /// <returns>Value of the pixel, or undefined value if coordinates are out of range.</returns>
-        public Color GetPixel(int x, int y, int z = 0)
-        {
-            Color pixel;
-            Internal_GetPixel(mCachedPtr, x, y, z, out pixel);
-            return pixel;
-        }
-
-        /// <summary>
-        /// Sets a pixel at the specified location in the buffer.
-        /// </summary>
-        /// <param name="color">Color of the pixel to set.</param>
-        /// <param name="x">X coordinate of the pixel.</param>
-        /// <param name="y">Y coordinate of the pixel.</param>
-        /// <param name="z">Z coordinate of the pixel.</param>
-        public void SetPixel(Color color, int x, int y, int z = 0)
-        {
-            Internal_SetPixel(mCachedPtr, x, y, z, color);
-        }
-
-        /// <summary>
-        /// Returns values of all pixels. 
-        /// </summary>
-        /// <returns>All pixels in the buffer ordered consecutively. Pixels are stored as a succession of "depth" slices, 
-        ///          each containing "height" rows of "width" pixels.</returns>
-        public Color[] GetPixels()
-        {
-            Color[] pixels;
-            Internal_GetPixels(mCachedPtr, out pixels);
-            return pixels;
-        }
-
-        /// <summary>
-        /// Sets all pixels in the buffer. Caller must ensure that number of pixels match the extends of the buffer.
-        /// </summary>
-        /// <param name="pixels">All pixels to set ordered consecutively. Pixels are stored as a succession of "depth" 
-        ///                      slices, each containing "height" rows of "width" pixels.</param>
-        public void SetPixels(Color[] pixels)
-        {
-            Internal_SetPixels(mCachedPtr, pixels);
-        }
-
-        /// <summary>
-        /// Returns all pixels in the buffer as raw bytes.
-        /// </summary>
-        /// <returns>Raw pixel bytes. It is up to the caller to interpret the pixel format and account for potential 
-        ///          row and slice pitch values.</returns>
-        public byte[] GetRawPixels()
-        {
-            byte[] pixels;
-            Internal_GetRawPixels(mCachedPtr, out pixels);
-            return pixels;
-        }
-
-        /// <summary>
-        /// Sets all pixels in the buffer as raw bytes.
-        /// </summary>
-        /// <param name="pixels">Raw pixel bytes. It is up to the caller to set the proper pixel format and account for 
-        ///                      potential row and slice pitch values.</param>
-        public void SetRawPixels(byte[] pixels)
-        {
-            Internal_SetRawPixels(mCachedPtr, pixels);
-        }
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_CreateInstance(PixelData instance, PixelVolume volume, PixelFormat format);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_GetPixel(IntPtr thisPtr, int x, int y, int z, out Color value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetPixel(IntPtr thisPtr, int x, int y, int z, Color value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_GetPixels(IntPtr thisPtr, out Color[] value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetPixels(IntPtr thisPtr, Color[] value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_GetRawPixels(IntPtr thisPtr, out byte[] value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetRawPixels(IntPtr thisPtr, byte[] value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_GetExtents(IntPtr thisPtr, out PixelVolume value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_GetFormat(IntPtr thisPtr, out PixelFormat value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_GetRowPitch(IntPtr thisPtr, out int value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_GetSlicePitch(IntPtr thisPtr, out int value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_GetSize(IntPtr thisPtr, out int value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_GetIsConsecutive(IntPtr thisPtr, out bool value);
-    }
-
-    /// <summary>
-    /// Represents a 3D region of pixels used for referencing pixel data.
-    /// </summary>
-    [StructLayout(LayoutKind.Sequential)]
-    public struct PixelVolume // Note: Must match C++ class PixelVolume
-    {
-        private int left, top, right, bottom, front, back;
-
-        /// <summary>
-        /// Returns the left border of the pixel region (minimal X).
-        /// </summary>
-        public int Left { get { return left; } }
-
-        /// <summary>
-        /// Returns the right border of the pixel region (maximal X).
-        /// </summary>
-        public int Right { get { return right; } }
-
-        /// <summary>
-        /// Returns the top border of the pixel region (minimal Y).
-        /// </summary>
-        public int Top { get { return top; } }
-
-        /// <summary>
-        /// Returns the bottom border of the pixel region (maximal Y).
-        /// </summary>
-        public int Bottom { get { return bottom; } }
-
-        /// <summary>
-        /// Returns the front border of the pixel region (minimal Z).
-        /// </summary>
-        public int Front { get { return front; } }
-
-        /// <summary>
-        /// Returns the back border of the pixel region (maximal Z).
-        /// </summary>
-        public int Back { get { return back; } }
-
-        /// <summary>
-        /// Returns the number of pixels between right and left borders of the volume.
-        /// </summary>
-        public int Width { get { return right - left; } }
-
-        /// <summary>
-        /// Returns the number of pixels between bottom and top borders of the volume.
-        /// </summary>
-        public int Height { get { return bottom - top; } }
-
-        /// <summary>
-        /// Returns the number of pixels between back and front borders of the volume.
-        /// </summary>
-        public int Depth { get { return back - front; } }
-
-        /// <summary>
-        /// Creates a new 2D region.
-        /// </summary>
-        /// <param name="left">Left border of the region.</param>
-        /// <param name="top">Top border of the region.</param>
-        /// <param name="right">Right border of the region. Must be larger than left border.</param>
-        /// <param name="bottom">Bottom border of the region. Must be larger than top border.</param>
-        public PixelVolume(int left, int top, int right, int bottom)
-        {
-            this.left = left;
-            this.right = right;
-            this.top = top;
-            this.bottom = bottom;
-            this.front = 0;
-            this.back = 1;
-        }
-
-        /// <summary>
-        /// Creates a new 3D region.
-        /// </summary>
-        /// <param name="left">Left border of the region.</param>
-        /// <param name="top">Top border of the region.</param>
-        /// <param name="front">Front border of the region.</param>
-        /// <param name="right">Right border of the region. Must be larger than left border.</param>
-        /// <param name="bottom">Bottom border of the region. Must be larger than top border.</param>
-        /// <param name="back">Back border of the region. Must be larger than back border.</param>
-        public PixelVolume(int left, int top, int front, int right, int bottom, int back)
-        {
-            this.left = left;
-            this.right = right;
-            this.top = top;
-            this.bottom = bottom;
-            this.front = front;
-            this.back = back;
-        }
-    };
-}
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Text;
+
+namespace BansheeEngine
+{
+    /// <summary>
+    /// Pixel formats usable by images, textures and render surfaces.
+    /// </summary>
+    public enum PixelFormat // Note: Must match C++ enum PixelFormat
+    {
+        /// <summary>
+        /// 8-bit pixel format, all bits red.
+        /// </summary>
+        R8 = 1,
+        /// <summary>
+        /// 2 byte pixel format, 1 byte red, 1 byte green.
+        /// </summary>
+        R8G8 = 2,
+        /// <summary>
+        /// 24-bit pixel format, 8 bits for red, green and blue.
+        /// </summary>
+        R8G8B8 = 3,
+        /// <summary>
+        /// 32-bit pixel format, 8 bits for red, green, blue and alpha.
+        /// </summary>
+        R8G8B8A8 = 8,
+        /// <summary>
+        /// DXT1/BC1 format containing opaque RGB or 1-bit alpha RGB. 4 bits per pixel.
+        /// </summary>
+        BC1 = 13,
+        /// <summary>
+        /// DXT3/BC2 format containing RGB with premultiplied alpha. 4 bits per pixel.
+        /// </summary>
+        BC1a = 14,
+        /// <summary>
+        /// DXT3/BC2 format containing RGB with explicit alpha. 8 bits per pixel.
+        /// </summary>
+        BC2 = 15,
+        /// <summary>
+        /// DXT5/BC2 format containing RGB with explicit alpha. 8 bits per pixel. Better alpha gradients than BC2.
+        /// </summary>
+        BC3 = 16,
+        /// <summary>
+        /// One channel compressed format. 4 bits per pixel.
+        /// </summary>
+        BC4 = 17,
+        /// <summary>
+        /// Two channel compressed format. 8 bits per pixel.
+        /// </summary>
+        BC5 = 18,
+        /// <summary>
+        /// Format storing RGB in half (16-bit) floating point format usable for HDR. 8 bits per pixel.
+        /// </summary>
+        BC6H = 19,
+        /// <summary>
+        /// Format storing RGB with optional alpha channel. Similar to BC1/BC2/BC3 formats but with higher quality and 
+        /// higher decompress overhead. 8 bits per pixel.
+        /// </summary>
+        BC7 = 20,
+        /// <summary>
+        /// 16-bit pixel format, 16 bits (float) for red.
+        /// </summary>
+        Float16_R = 21,
+        /// <summary>
+        /// 32-bit, 2-channel s10e5 floating point pixel format, 16-bit red, 16-bit green.
+        /// </summary>
+        Float16_RG = 22,
+        /// <summary>
+        /// 48-bit pixel format, 16 bits (float) for red, 16 bits (float) for green, 16 bits (float) for blue.
+        /// </summary>
+        Float16_RGB = 23,
+        /// <summary>
+        /// 64-bit pixel format, 16 bits (float) for red, 16 bits (float) for green, 16 bits (float) for blue, 16 bits 
+        /// (float) for alpha.
+        /// </summary>
+        Float16_RGBA = 24,
+        /// <summary>
+        /// 32-bit pixel format, 32 bits (float) for red.
+        /// </summary>
+        Float32_R = 25,
+        /// <summary>
+        /// 64-bit, 2-channel floating point pixel format, 32-bit red, 32-bit green.
+        /// </summary>
+        Float32_RG = 26,
+        /// <summary>
+        /// 96-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue.
+        /// </summary>
+        Float32_RGB = 27,
+        /// <summary>
+        /// 128-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue, 
+        /// 32 bits (float) for alpha.
+        /// </summary>
+        Float32_RGBA = 28,
+        /// <summary>
+        /// Depth stencil format, 32bit depth, 8bit stencil + 24 unused.
+        /// </summary>
+        D32_S8X24 = 29,
+        /// <summary>
+        /// Depth stencil fomrat, 24bit depth + 8bit stencil.
+        /// </summary>
+        D24S8 = 30,
+        /// <summary>
+        /// Depth format, 32bits.
+        /// </summary>
+        D32 = 31,
+        /// <summary>
+        /// Depth format, 16bits.
+        /// </summary>
+        D16 = 32
+    };
+
+    /// <summary>
+    /// A buffer describing a volume (3D), image (2D) or line (1D) of pixels in memory. Pixels are stored as a succession 
+    /// of "depth" slices, each containing "height" rows of "width" pixels.
+    /// </summary>
+    public sealed class PixelData : ScriptObject
+    {
+        /// <summary>
+        /// Width, height and depth of the pixels this object is capable of holding.
+        /// </summary>
+        public PixelVolume Extents
+        {
+            get
+            {
+                PixelVolume volume;
+                Internal_GetExtents(mCachedPtr, out volume);
+                return volume;
+            }
+        }
+
+        /// <summary>
+        /// Format of the pixels in the buffer.
+        /// </summary>
+        public PixelFormat Format
+        {
+            get
+            {
+                PixelFormat format;
+                Internal_GetFormat(mCachedPtr, out format);
+                return format;
+            }
+        }
+
+        /// <summary>
+        /// Returns number of bytes per a row of pixels.
+        /// </summary>
+        public int RawRowPitch
+        {
+            get
+            {
+                int rowPitch;
+                Internal_GetRowPitch(mCachedPtr, out rowPitch);
+                return rowPitch;
+            }
+        }
+
+        /// <summary>
+        /// Returns number of bytes per a 2D slice/plane of pixels.
+        /// </summary>
+        public int RawSlicePitch
+        {
+            get
+            {
+                int slicePitch;
+                Internal_GetSlicePitch(mCachedPtr, out slicePitch);
+                return slicePitch;
+            }
+        }
+
+        /// <summary>
+        /// Returns total number of bytes used by all the pixels.
+        /// </summary>
+        public int RawSize
+        {
+            get
+            {
+                int size;
+                Internal_GetSize(mCachedPtr, out size);
+                return size;
+            }
+        }
+
+        /// <summary>
+        /// Checks are the pixels in the buffer consecutive. If this is false then the buffer has padding and you should
+        /// check <see cref="RawRowPitch"/> and <see cref="RawSlicePitch"/> when accessing it directly.
+        /// </summary>
+        public bool RawIsConsecutive
+        {
+            get
+            {
+                bool isConsecutive;
+                Internal_GetIsConsecutive(mCachedPtr, out isConsecutive);
+                return isConsecutive;
+            }
+        }
+
+        /// <summary>
+        /// Constructor for internal use by the runtime.
+        /// </summary>
+        private PixelData()
+        { }
+
+        /// <summary>
+        /// Creates a new pixel data buffer capable of storing the specified amount of pixels.
+        /// </summary>
+        /// <param name="volume">Width, height and depth determining number of pixels to store.</param>
+        /// <param name="format">Format of individual pixels.</param>
+        public PixelData(PixelVolume volume, PixelFormat format = PixelFormat.R8G8B8A8)
+        {
+            Internal_CreateInstance(this, ref volume, format);
+        }
+
+        /// <summary>
+        /// Creates a new 2D pixel data buffer capable of storing the specified amount of pixels.
+        /// </summary>
+        /// <param name="width">Number of pixels in each row.</param>
+        /// <param name="height">Number of pixels in each column.</param>
+        /// <param name="format">Format of individual pixels.</param>
+        public PixelData(int width, int height, PixelFormat format = PixelFormat.R8G8B8A8)
+        {
+            PixelVolume volume = new PixelVolume(0, 0, width, height);
+
+            Internal_CreateInstance(this, ref volume, format);
+        }
+
+        /// <summary>
+        /// Creates a new 3D pixel data buffer capable of storing the specified amount of pixels.
+        /// </summary>
+        /// <param name="width">Number of pixels in each row.</param>
+        /// <param name="height">Number of pixels in each column.</param>
+        /// <param name="depth">Number of 2D slices.</param>
+        /// <param name="format">Format of individual pixels.</param>
+        public PixelData(int width, int height, int depth, PixelFormat format = PixelFormat.R8G8B8A8)
+        {
+            PixelVolume volume = new PixelVolume(0, 0, 0, width, height, depth);
+
+            Internal_CreateInstance(this, ref volume, format);
+        }
+
+        /// <summary>
+        /// Returns a pixel at the specified location in the buffer.
+        /// </summary>
+        /// <param name="x">X coordinate of the pixel.</param>
+        /// <param name="y">Y coordinate of the pixel.</param>
+        /// <param name="z">Z coordinate of the pixel.</param>
+        /// <returns>Value of the pixel, or undefined value if coordinates are out of range.</returns>
+        public Color GetPixel(int x, int y, int z = 0)
+        {
+            Color pixel;
+            Internal_GetPixel(mCachedPtr, x, y, z, out pixel);
+            return pixel;
+        }
+
+        /// <summary>
+        /// Sets a pixel at the specified location in the buffer.
+        /// </summary>
+        /// <param name="color">Color of the pixel to set.</param>
+        /// <param name="x">X coordinate of the pixel.</param>
+        /// <param name="y">Y coordinate of the pixel.</param>
+        /// <param name="z">Z coordinate of the pixel.</param>
+        public void SetPixel(Color color, int x, int y, int z = 0)
+        {
+            Internal_SetPixel(mCachedPtr, x, y, z, ref color);
+        }
+
+        /// <summary>
+        /// Returns values of all pixels. 
+        /// </summary>
+        /// <returns>All pixels in the buffer ordered consecutively. Pixels are stored as a succession of "depth" slices, 
+        ///          each containing "height" rows of "width" pixels.</returns>
+        public Color[] GetPixels()
+        {
+            Color[] pixels;
+            Internal_GetPixels(mCachedPtr, out pixels);
+            return pixels;
+        }
+
+        /// <summary>
+        /// Sets all pixels in the buffer. Caller must ensure that number of pixels match the extends of the buffer.
+        /// </summary>
+        /// <param name="pixels">All pixels to set ordered consecutively. Pixels are stored as a succession of "depth" 
+        ///                      slices, each containing "height" rows of "width" pixels.</param>
+        public void SetPixels(Color[] pixels)
+        {
+            Internal_SetPixels(mCachedPtr, pixels);
+        }
+
+        /// <summary>
+        /// Returns all pixels in the buffer as raw bytes.
+        /// </summary>
+        /// <returns>Raw pixel bytes. It is up to the caller to interpret the pixel format and account for potential 
+        ///          row and slice pitch values.</returns>
+        public byte[] GetRawPixels()
+        {
+            byte[] pixels;
+            Internal_GetRawPixels(mCachedPtr, out pixels);
+            return pixels;
+        }
+
+        /// <summary>
+        /// Sets all pixels in the buffer as raw bytes.
+        /// </summary>
+        /// <param name="pixels">Raw pixel bytes. It is up to the caller to set the proper pixel format and account for 
+        ///                      potential row and slice pitch values.</param>
+        public void SetRawPixels(byte[] pixels)
+        {
+            Internal_SetRawPixels(mCachedPtr, pixels);
+        }
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_CreateInstance(PixelData instance, ref PixelVolume volume, PixelFormat format);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetPixel(IntPtr thisPtr, int x, int y, int z, out Color value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetPixel(IntPtr thisPtr, int x, int y, int z, ref Color value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetPixels(IntPtr thisPtr, out Color[] value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetPixels(IntPtr thisPtr, Color[] value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetRawPixels(IntPtr thisPtr, out byte[] value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetRawPixels(IntPtr thisPtr, byte[] value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetExtents(IntPtr thisPtr, out PixelVolume value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetFormat(IntPtr thisPtr, out PixelFormat value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetRowPitch(IntPtr thisPtr, out int value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetSlicePitch(IntPtr thisPtr, out int value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetSize(IntPtr thisPtr, out int value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetIsConsecutive(IntPtr thisPtr, out bool value);
+    }
+
+    /// <summary>
+    /// Represents a 3D region of pixels used for referencing pixel data.
+    /// </summary>
+    [StructLayout(LayoutKind.Sequential)]
+    public struct PixelVolume // Note: Must match C++ class PixelVolume
+    {
+        private int left, top, right, bottom, front, back;
+
+        /// <summary>
+        /// Returns the left border of the pixel region (minimal X).
+        /// </summary>
+        public int Left { get { return left; } }
+
+        /// <summary>
+        /// Returns the right border of the pixel region (maximal X).
+        /// </summary>
+        public int Right { get { return right; } }
+
+        /// <summary>
+        /// Returns the top border of the pixel region (minimal Y).
+        /// </summary>
+        public int Top { get { return top; } }
+
+        /// <summary>
+        /// Returns the bottom border of the pixel region (maximal Y).
+        /// </summary>
+        public int Bottom { get { return bottom; } }
+
+        /// <summary>
+        /// Returns the front border of the pixel region (minimal Z).
+        /// </summary>
+        public int Front { get { return front; } }
+
+        /// <summary>
+        /// Returns the back border of the pixel region (maximal Z).
+        /// </summary>
+        public int Back { get { return back; } }
+
+        /// <summary>
+        /// Returns the number of pixels between right and left borders of the volume.
+        /// </summary>
+        public int Width { get { return right - left; } }
+
+        /// <summary>
+        /// Returns the number of pixels between bottom and top borders of the volume.
+        /// </summary>
+        public int Height { get { return bottom - top; } }
+
+        /// <summary>
+        /// Returns the number of pixels between back and front borders of the volume.
+        /// </summary>
+        public int Depth { get { return back - front; } }
+
+        /// <summary>
+        /// Creates a new 2D region.
+        /// </summary>
+        /// <param name="left">Left border of the region.</param>
+        /// <param name="top">Top border of the region.</param>
+        /// <param name="right">Right border of the region. Must be larger than left border.</param>
+        /// <param name="bottom">Bottom border of the region. Must be larger than top border.</param>
+        public PixelVolume(int left, int top, int right, int bottom)
+        {
+            this.left = left;
+            this.right = right;
+            this.top = top;
+            this.bottom = bottom;
+            this.front = 0;
+            this.back = 1;
+        }
+
+        /// <summary>
+        /// Creates a new 3D region.
+        /// </summary>
+        /// <param name="left">Left border of the region.</param>
+        /// <param name="top">Top border of the region.</param>
+        /// <param name="front">Front border of the region.</param>
+        /// <param name="right">Right border of the region. Must be larger than left border.</param>
+        /// <param name="bottom">Bottom border of the region. Must be larger than top border.</param>
+        /// <param name="back">Back border of the region. Must be larger than back border.</param>
+        public PixelVolume(int left, int top, int front, int right, int bottom, int back)
+        {
+            this.left = left;
+            this.right = right;
+            this.top = top;
+            this.bottom = bottom;
+            this.front = front;
+            this.back = back;
+        }
+    };
+}

+ 309 - 309
MBansheeEngine/PixelUtility.cs

@@ -1,309 +1,309 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Text;
-
-namespace BansheeEngine
-{
-    /// <summary>
-    /// Utility methods for converting and managing pixel data and formats.
-    /// </summary>
-    public static class PixelUtility
-    {
-        /// <summary>
-        /// Returns the size of the memory region required to hold pixels of the provided size ana format.
-        /// </summary>
-        /// <param name="width">Number of pixels in each row.</param>
-        /// <param name="height">Number of pixels in each column.</param>
-        /// <param name="depth">Number of 2D slices.</param>
-        /// <param name="format">Format of individual pixels.</param>
-        /// <returns>Size of the memory region in bytes.</returns>
-        public static int GetMemorySize(int width, int height, int depth, PixelFormat format)
-        {
-            int value;
-            Internal_GetMemorySize(width, height, depth, format, out value);
-            return value;
-        }
-
-        /// <summary>
-        /// Checks if the provided pixel format has an alpha channel.
-        /// </summary>
-        /// <param name="format">Format to check.</param>
-        /// <returns>True if the format contains an alpha channel.</returns>
-        public static bool HasAlpha(PixelFormat format)
-        {
-            bool value;
-            Internal_HasAlpha(format, out value);
-            return value;
-        }
-
-        /// <summary>
-        /// Checks is the provided pixel format a floating point format.
-        /// </summary>
-        /// <param name="format">Format to check.</param>
-        /// <returns>True if the format contains floating point values.</returns>
-        public static bool IsFloatingPoint(PixelFormat format)
-        {
-            bool value;
-            Internal_IsFloatingPoint(format, out value);
-            return value;
-        }
-
-        /// <summary>
-        /// Checks is the provided pixel format contains compressed data.
-        /// </summary>
-        /// <param name="format">Format to check.</param>
-        /// <returns>True if the format contains compressed data.</returns>
-        public static bool IsCompressed(PixelFormat format)
-        {
-            bool value;
-            Internal_IsCompressed(format, out value);
-            return value;
-        }
-
-        /// <summary>
-        /// Checks is the provided pixel format a depth/stencil buffer format.
-        /// </summary>
-        /// <param name="format">Format to check.</param>
-        /// <returns>True if the format is a depth/stencil buffer format.</returns>
-        public static bool IsDepth(PixelFormat format)
-        {
-            bool value;
-            Internal_IsDepth(format, out value);
-            return value;
-        }
-
-        /// <summary>
-        /// Returns the maximum number of mip maps that can be generated until we reachthe minimum size possible. This does 
-        /// not count the base level.
-        /// </summary>
-        /// <param name="width">Number of pixels in each row.</param>
-        /// <param name="height">Number of pixels in each column.</param>
-        /// <param name="depth">Number of 2D slices.</param>
-        /// <param name="format">Format of individual pixels.</param>
-        /// <returns>Possible number of mip-maps not counting the base level.</returns>
-        public static int GetMaxMipmaps(int width, int height, int depth, PixelFormat format)
-        {
-            int value;
-            Internal_GetMaxMipmaps(width, height, depth, format, out value);
-            return value;
-        }
-
-        /// <summary>
-        /// Converts a set of pixels from one format to another.
-        /// </summary>
-        /// <param name="source">Pixels to convert.</param>
-        /// <param name="newFormat">New pixel format.</param>
-        /// <returns>New pixel data object containing the converted pixels.</returns>
-        public static PixelData ConvertFormat(PixelData source, PixelFormat newFormat)
-        {
-            return Internal_ConvertFormat(source, newFormat);
-        }
-
-        /// <summary>
-        /// Compresses the provided pixels using the specified compression options.
-        /// </summary>
-        /// <param name="source">Pixels to compress.</param>
-        /// <param name="options">Options to control the compression. Make sure the format contained within is a
-        ///                       compressed format.</param>
-        /// <returns>New pixel data object containing the compressed pixels.</returns>
-        public static PixelData Compress(PixelData source, CompressionOptions options)
-        {
-            return Internal_Compress(source, options);
-        }
-
-        /// <summary>
-        /// Generates mip-maps from the provided source data using the specified compression options. Returned list includes 
-        /// the base level.
-        /// </summary>
-        /// <param name="source">Pixels to generate mip-maps for.</param>
-        /// <param name="options">Options controlling mip-map generation.</param>
-        /// <returns>A list of calculated mip-map data. First entry is the largest mip and other follow in order from 
-        ///          largest to smallest.</returns>
-		public static PixelData[] GenerateMipmaps(PixelData source, MipMapGenOptions options)
-        {
-            return Internal_GenerateMipmaps(source, options);
-        }
-
-        /// <summary>
-        /// Scales pixel data in the source buffer and stores the scaled data in the destination buffer.
-        /// </summary>
-        /// <param name="source">Source pixels to scale.</param>
-        /// <param name="newSize">New dimensions to scale to.</param>
-        /// <param name="filter">Filter to use when scaling.</param>
-        /// <returns>New pixel data object containing the scaled pixels.</returns>
-        public static PixelData Scale(PixelData source, PixelVolume newSize, ScaleFilter filter = ScaleFilter.Linear)
-        {
-            return Internal_Scale(source, newSize, filter);
-        }
-
-        /// <summary>
-        /// Applies gamma correction to the pixels in the provided buffer.
-        /// </summary>
-        /// <param name="source">Source pixels to gamma correct.</param>
-        /// <param name="gamma">Gamma value to apply.</param>
-        public static void ApplyGamma(PixelData source, float gamma)
-        {
-            Internal_ApplyGamma(source, gamma);
-        }
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_GetMemorySize(int width, int height, int depth, PixelFormat format, out int value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_HasAlpha(PixelFormat format, out bool value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_IsFloatingPoint(PixelFormat format, out bool value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_IsCompressed(PixelFormat format, out bool value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_IsDepth(PixelFormat format, out bool value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_GetMaxMipmaps(int width, int height, int depth, PixelFormat format, out int value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern PixelData Internal_ConvertFormat(PixelData source, PixelFormat newFormat);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern PixelData Internal_Compress(PixelData source, CompressionOptions options);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern PixelData[] Internal_GenerateMipmaps(PixelData source, MipMapGenOptions options);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern PixelData Internal_Scale(PixelData source, PixelVolume newSize, ScaleFilter filter);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_ApplyGamma(PixelData source, float gamma);
-    }
-
-    /// <summary>
-    /// Filtering types to use when scaling images.
-    /// </summary>
-    public enum ScaleFilter // Note: Must match the C++ enum PixelUtil::Filter
-    {
-        /// <summary>
-        /// No filtering is performed and nearest existing value is used.
-        /// </summary>
-        Nearest,
-        /// <summary>
-        /// Box filter is applied, averaging nearby pixels.
-        /// </summary>
-        Linear
-    };
-
-    /// <summary>
-    /// Types of texture compression quality.
-    /// </summary>
-    public enum CompressionQuality // Note: Must match the C++ enum CompressionQuality
-	{
-		Fastest,
-		Normal,
-		Production,
-		Highest
-	};
-
-    /// <summary>
-    /// Mode of the alpha channel in a texture.
-    /// </summary>
-    public enum AlphaMode // Note: Must match the C++ enum AlphaMode
-	{
-        /// <summary>
-        /// Texture has no alpha values.
-        /// </summary>
-		None,
-        /// <summary>
-        /// Alpha is in the separate transparency channel.
-        /// </summary>
-		Transparency,
-        /// <summary>
-        /// Alpha values have been pre-multiplied with the color values.
-        /// </summary>
-		Premultiplied
-	};
-
-    /// <summary>
-    /// Wrap mode to use when generating mip maps.
-    /// </summary>
-    public enum MipMapWrapMode // Note: Must match the C++ enum MipMapWrapMode
-	{
-		Mirror,
-		Repeat,
-		Clamp
-	};
-
-    /// <summary>
-    /// Filter to use when generating mip maps.
-    /// </summary>
-    public enum MipMapFilter // Note: Must match the C++ enum MipMapFilter
-	{
-		Box,
-		Triangle,
-		Kaiser
-	};
-
-    /// <summary>
-    /// Options used to control texture compression.
-    /// </summary>
-    [StructLayout(LayoutKind.Sequential)]
-    public struct CompressionOptions // Note: Must match the C++ struct CompressionOptions
-	{
-        /// <summary>
-        /// Format to compress to. Must be a format containing compressed data.
-        /// </summary>
-		public PixelFormat format;
-
-        /// <summary>
-        /// Controls how to (and if) to compress the alpha channel.
-        /// </summary>
-	    public AlphaMode alphaMode;
-
-        /// <summary>
-        /// Determines does the input data represent a normal map.
-        /// </summary>
-		public bool isNormalMap;
-
-        /// <summary>
-        /// Determines has the input data been gamma corrected.
-        /// </summary>
-		public bool isSRGB;
-
-        /// <summary>
-        /// Compressed image quality. Better compression might take longer to execute but will generate better results.
-        /// </summary>
-		public CompressionQuality quality;
-	};
-
-    /// <summary>
-    /// Options used to control texture mip map generation.
-    /// </summary>
-    [StructLayout(LayoutKind.Sequential)]
-    public struct MipMapGenOptions // Note: Must match the C++ struct MipMapGenOptions
-	{
-        /// <summary>
-        /// Filter to use when downsamping input data.
-        /// </summary>
-		public MipMapFilter filter;
-
-        /// <summary>
-        /// Determines how to downsample pixels on borders.
-        /// </summary>
-		public MipMapWrapMode wrapMode;
-
-        /// <summary>
-        /// Determines does the input data represent a normal map.
-        /// </summary>
-		public bool isNormalMap;
-
-        /// <summary>
-        /// Should the downsampled values be re-normalized. Only relevant for mip-maps representing normal maps.
-        /// </summary>
-		public bool normalizeMipmaps;
-	};
-}
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Text;
+
+namespace BansheeEngine
+{
+    /// <summary>
+    /// Utility methods for converting and managing pixel data and formats.
+    /// </summary>
+    public static class PixelUtility
+    {
+        /// <summary>
+        /// Returns the size of the memory region required to hold pixels of the provided size ana format.
+        /// </summary>
+        /// <param name="width">Number of pixels in each row.</param>
+        /// <param name="height">Number of pixels in each column.</param>
+        /// <param name="depth">Number of 2D slices.</param>
+        /// <param name="format">Format of individual pixels.</param>
+        /// <returns>Size of the memory region in bytes.</returns>
+        public static int GetMemorySize(int width, int height, int depth, PixelFormat format)
+        {
+            int value;
+            Internal_GetMemorySize(width, height, depth, format, out value);
+            return value;
+        }
+
+        /// <summary>
+        /// Checks if the provided pixel format has an alpha channel.
+        /// </summary>
+        /// <param name="format">Format to check.</param>
+        /// <returns>True if the format contains an alpha channel.</returns>
+        public static bool HasAlpha(PixelFormat format)
+        {
+            bool value;
+            Internal_HasAlpha(format, out value);
+            return value;
+        }
+
+        /// <summary>
+        /// Checks is the provided pixel format a floating point format.
+        /// </summary>
+        /// <param name="format">Format to check.</param>
+        /// <returns>True if the format contains floating point values.</returns>
+        public static bool IsFloatingPoint(PixelFormat format)
+        {
+            bool value;
+            Internal_IsFloatingPoint(format, out value);
+            return value;
+        }
+
+        /// <summary>
+        /// Checks is the provided pixel format contains compressed data.
+        /// </summary>
+        /// <param name="format">Format to check.</param>
+        /// <returns>True if the format contains compressed data.</returns>
+        public static bool IsCompressed(PixelFormat format)
+        {
+            bool value;
+            Internal_IsCompressed(format, out value);
+            return value;
+        }
+
+        /// <summary>
+        /// Checks is the provided pixel format a depth/stencil buffer format.
+        /// </summary>
+        /// <param name="format">Format to check.</param>
+        /// <returns>True if the format is a depth/stencil buffer format.</returns>
+        public static bool IsDepth(PixelFormat format)
+        {
+            bool value;
+            Internal_IsDepth(format, out value);
+            return value;
+        }
+
+        /// <summary>
+        /// Returns the maximum number of mip maps that can be generated until we reachthe minimum size possible. This does 
+        /// not count the base level.
+        /// </summary>
+        /// <param name="width">Number of pixels in each row.</param>
+        /// <param name="height">Number of pixels in each column.</param>
+        /// <param name="depth">Number of 2D slices.</param>
+        /// <param name="format">Format of individual pixels.</param>
+        /// <returns>Possible number of mip-maps not counting the base level.</returns>
+        public static int GetMaxMipmaps(int width, int height, int depth, PixelFormat format)
+        {
+            int value;
+            Internal_GetMaxMipmaps(width, height, depth, format, out value);
+            return value;
+        }
+
+        /// <summary>
+        /// Converts a set of pixels from one format to another.
+        /// </summary>
+        /// <param name="source">Pixels to convert.</param>
+        /// <param name="newFormat">New pixel format.</param>
+        /// <returns>New pixel data object containing the converted pixels.</returns>
+        public static PixelData ConvertFormat(PixelData source, PixelFormat newFormat)
+        {
+            return Internal_ConvertFormat(source, newFormat);
+        }
+
+        /// <summary>
+        /// Compresses the provided pixels using the specified compression options.
+        /// </summary>
+        /// <param name="source">Pixels to compress.</param>
+        /// <param name="options">Options to control the compression. Make sure the format contained within is a
+        ///                       compressed format.</param>
+        /// <returns>New pixel data object containing the compressed pixels.</returns>
+        public static PixelData Compress(PixelData source, CompressionOptions options)
+        {
+            return Internal_Compress(source, ref options);
+        }
+
+        /// <summary>
+        /// Generates mip-maps from the provided source data using the specified compression options. Returned list includes 
+        /// the base level.
+        /// </summary>
+        /// <param name="source">Pixels to generate mip-maps for.</param>
+        /// <param name="options">Options controlling mip-map generation.</param>
+        /// <returns>A list of calculated mip-map data. First entry is the largest mip and other follow in order from 
+        ///          largest to smallest.</returns>
+		public static PixelData[] GenerateMipmaps(PixelData source, MipMapGenOptions options)
+        {
+            return Internal_GenerateMipmaps(source, ref options);
+        }
+
+        /// <summary>
+        /// Scales pixel data in the source buffer and stores the scaled data in the destination buffer.
+        /// </summary>
+        /// <param name="source">Source pixels to scale.</param>
+        /// <param name="newSize">New dimensions to scale to.</param>
+        /// <param name="filter">Filter to use when scaling.</param>
+        /// <returns>New pixel data object containing the scaled pixels.</returns>
+        public static PixelData Scale(PixelData source, PixelVolume newSize, ScaleFilter filter = ScaleFilter.Linear)
+        {
+            return Internal_Scale(source, ref newSize, filter);
+        }
+
+        /// <summary>
+        /// Applies gamma correction to the pixels in the provided buffer.
+        /// </summary>
+        /// <param name="source">Source pixels to gamma correct.</param>
+        /// <param name="gamma">Gamma value to apply.</param>
+        public static void ApplyGamma(PixelData source, float gamma)
+        {
+            Internal_ApplyGamma(source, gamma);
+        }
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetMemorySize(int width, int height, int depth, PixelFormat format, out int value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_HasAlpha(PixelFormat format, out bool value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_IsFloatingPoint(PixelFormat format, out bool value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_IsCompressed(PixelFormat format, out bool value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_IsDepth(PixelFormat format, out bool value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetMaxMipmaps(int width, int height, int depth, PixelFormat format, out int value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern PixelData Internal_ConvertFormat(PixelData source, PixelFormat newFormat);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern PixelData Internal_Compress(PixelData source, ref CompressionOptions options);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern PixelData[] Internal_GenerateMipmaps(PixelData source, ref MipMapGenOptions options);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern PixelData Internal_Scale(PixelData source, ref PixelVolume newSize, ScaleFilter filter);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_ApplyGamma(PixelData source, float gamma);
+    }
+
+    /// <summary>
+    /// Filtering types to use when scaling images.
+    /// </summary>
+    public enum ScaleFilter // Note: Must match the C++ enum PixelUtil::Filter
+    {
+        /// <summary>
+        /// No filtering is performed and nearest existing value is used.
+        /// </summary>
+        Nearest,
+        /// <summary>
+        /// Box filter is applied, averaging nearby pixels.
+        /// </summary>
+        Linear
+    };
+
+    /// <summary>
+    /// Types of texture compression quality.
+    /// </summary>
+    public enum CompressionQuality // Note: Must match the C++ enum CompressionQuality
+	{
+		Fastest,
+		Normal,
+		Production,
+		Highest
+	};
+
+    /// <summary>
+    /// Mode of the alpha channel in a texture.
+    /// </summary>
+    public enum AlphaMode // Note: Must match the C++ enum AlphaMode
+	{
+        /// <summary>
+        /// Texture has no alpha values.
+        /// </summary>
+		None,
+        /// <summary>
+        /// Alpha is in the separate transparency channel.
+        /// </summary>
+		Transparency,
+        /// <summary>
+        /// Alpha values have been pre-multiplied with the color values.
+        /// </summary>
+		Premultiplied
+	};
+
+    /// <summary>
+    /// Wrap mode to use when generating mip maps.
+    /// </summary>
+    public enum MipMapWrapMode // Note: Must match the C++ enum MipMapWrapMode
+	{
+		Mirror,
+		Repeat,
+		Clamp
+	};
+
+    /// <summary>
+    /// Filter to use when generating mip maps.
+    /// </summary>
+    public enum MipMapFilter // Note: Must match the C++ enum MipMapFilter
+	{
+		Box,
+		Triangle,
+		Kaiser
+	};
+
+    /// <summary>
+    /// Options used to control texture compression.
+    /// </summary>
+    [StructLayout(LayoutKind.Sequential)]
+    public struct CompressionOptions // Note: Must match the C++ struct CompressionOptions
+	{
+        /// <summary>
+        /// Format to compress to. Must be a format containing compressed data.
+        /// </summary>
+		public PixelFormat format;
+
+        /// <summary>
+        /// Controls how to (and if) to compress the alpha channel.
+        /// </summary>
+	    public AlphaMode alphaMode;
+
+        /// <summary>
+        /// Determines does the input data represent a normal map.
+        /// </summary>
+		public bool isNormalMap;
+
+        /// <summary>
+        /// Determines has the input data been gamma corrected.
+        /// </summary>
+		public bool isSRGB;
+
+        /// <summary>
+        /// Compressed image quality. Better compression might take longer to execute but will generate better results.
+        /// </summary>
+		public CompressionQuality quality;
+	};
+
+    /// <summary>
+    /// Options used to control texture mip map generation.
+    /// </summary>
+    [StructLayout(LayoutKind.Sequential)]
+    public struct MipMapGenOptions // Note: Must match the C++ struct MipMapGenOptions
+	{
+        /// <summary>
+        /// Filter to use when downsamping input data.
+        /// </summary>
+		public MipMapFilter filter;
+
+        /// <summary>
+        /// Determines how to downsample pixels on borders.
+        /// </summary>
+		public MipMapWrapMode wrapMode;
+
+        /// <summary>
+        /// Determines does the input data represent a normal map.
+        /// </summary>
+		public bool isNormalMap;
+
+        /// <summary>
+        /// Should the downsampled values be re-normalized. Only relevant for mip-maps representing normal maps.
+        /// </summary>
+		public bool normalizeMipmaps;
+	};
+}

+ 31 - 27
MBansheeEngine/SceneObject.cs

@@ -50,7 +50,7 @@ namespace BansheeEngine
 
             set
             {
-                Internal_SetPosition(mCachedPtr, value);
+                Internal_SetPosition(mCachedPtr, ref value);
             }
         }
 
@@ -68,7 +68,7 @@ namespace BansheeEngine
 
             set
             {
-                Internal_SetLocalPosition(mCachedPtr, value);
+                Internal_SetLocalPosition(mCachedPtr, ref value);
             }
         }
 
@@ -86,7 +86,7 @@ namespace BansheeEngine
 
             set
             {
-                Internal_SetRotation(mCachedPtr, value);
+                Internal_SetRotation(mCachedPtr, ref value);
             }
         }
 
@@ -104,7 +104,7 @@ namespace BansheeEngine
 
             set
             {
-                Internal_SetLocalRotation(mCachedPtr, value);
+                Internal_SetLocalRotation(mCachedPtr, ref value);
             }
         }
 
@@ -135,7 +135,7 @@ namespace BansheeEngine
 
             set
             {
-                Internal_SetLocalScale(mCachedPtr, value);
+                Internal_SetLocalScale(mCachedPtr, ref value);
             }
         }
 
@@ -180,7 +180,7 @@ namespace BansheeEngine
             }
             set
             {
-                Internal_SetForward(mCachedPtr, value);
+                Internal_SetForward(mCachedPtr, ref value);
             }
         }
 
@@ -349,7 +349,8 @@ namespace BansheeEngine
         /// <param name="position">Position in local space where to look at.</param>
         public void LookAt(Vector3 position)
         {
-            Internal_LookAt(mCachedPtr, position, Vector3.YAxis);
+            Vector3 up = Vector3.YAxis;
+            Internal_LookAt(mCachedPtr, ref position, ref up);
         }
 
         /// <summary>
@@ -359,7 +360,7 @@ namespace BansheeEngine
         /// <param name="up">Determines the object's Y axis orientation.</param>
         public void LookAt(Vector3 position, Vector3 up)
         {
-            Internal_LookAt(mCachedPtr, position, up);
+            Internal_LookAt(mCachedPtr, ref position, ref up);
         }
 
         /// <summary>
@@ -368,7 +369,7 @@ namespace BansheeEngine
         /// <param name="amount">Amount and direction to move the object along.</param>
         public void Move(Vector3 amount)
         {
-            Internal_Move(mCachedPtr, amount);
+            Internal_Move(mCachedPtr, ref amount);
         }
 
         /// <summary>
@@ -377,7 +378,7 @@ namespace BansheeEngine
         /// <param name="amount">Amount and direction to move the object along.</param>
         public void MoveLocal(Vector3 amount)
         {
-            Internal_MoveLocal(mCachedPtr, amount);
+            Internal_MoveLocal(mCachedPtr, ref amount);
         }
 
         /// <summary>
@@ -386,7 +387,7 @@ namespace BansheeEngine
         /// <param name="amount">Quaternion that specifies the rotation.</param>
         public void Rotate(Quaternion amount)
         {
-            Internal_Rotate(mCachedPtr, amount);
+            Internal_Rotate(mCachedPtr, ref amount);
         }
 
         /// <summary>
@@ -395,7 +396,8 @@ namespace BansheeEngine
         /// <param name="angle">Angle to rotate by.</param>
         public void Roll(Degree angle)
         {
-            Internal_Roll(mCachedPtr, angle);
+            Radian radianAngle = angle;
+            Internal_Roll(mCachedPtr, ref radianAngle);
         }
 
         /// <summary>
@@ -404,7 +406,8 @@ namespace BansheeEngine
         /// <param name="angle">Angle to rotate by.</param>
         public void Yaw(Degree angle)
         {
-            Internal_Yaw(mCachedPtr, angle);
+            Radian radianAngle = angle;
+            Internal_Yaw(mCachedPtr, ref radianAngle);
         }
 
         /// <summary>
@@ -413,7 +416,8 @@ namespace BansheeEngine
         /// <param name="angle">Angle to rotate by.</param>
         public void Pitch(Degree angle)
         {
-            Internal_Pitch(mCachedPtr, angle);
+            Radian radianAngle = angle;
+            Internal_Pitch(mCachedPtr, ref radianAngle);
         }
 
         /// <summary>
@@ -482,19 +486,19 @@ namespace BansheeEngine
         private static extern void Internal_GetLocalScale(IntPtr nativeInstance, out Vector3 value);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetPosition(IntPtr nativeInstance, Vector3 value);
+        private static extern void Internal_SetPosition(IntPtr nativeInstance, ref Vector3 value);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetLocalPosition(IntPtr nativeInstance, Vector3 value);
+        private static extern void Internal_SetLocalPosition(IntPtr nativeInstance, ref Vector3 value);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetRotation(IntPtr nativeInstance, Quaternion value);
+        private static extern void Internal_SetRotation(IntPtr nativeInstance, ref Quaternion value);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetLocalRotation(IntPtr nativeInstance, Quaternion value);
+        private static extern void Internal_SetLocalRotation(IntPtr nativeInstance, ref Quaternion value);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetLocalScale(IntPtr nativeInstance, Vector3 value);
+        private static extern void Internal_SetLocalScale(IntPtr nativeInstance, ref Vector3 value);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_GetLocalTransform(IntPtr nativeInstance, out Matrix4 value);
@@ -503,28 +507,28 @@ namespace BansheeEngine
         private static extern void Internal_GetWorldTransform(IntPtr nativeInstance, out Matrix4 value);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_LookAt(IntPtr nativeInstance, Vector3 direction, Vector3 up);
+        private static extern void Internal_LookAt(IntPtr nativeInstance, ref Vector3 direction, ref Vector3 up);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_Move(IntPtr nativeInstance, Vector3 value);
+        private static extern void Internal_Move(IntPtr nativeInstance, ref Vector3 value);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_MoveLocal(IntPtr nativeInstance, Vector3 value);
+        private static extern void Internal_MoveLocal(IntPtr nativeInstance, ref  Vector3 value);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_Rotate(IntPtr nativeInstance, Quaternion value);
+        private static extern void Internal_Rotate(IntPtr nativeInstance, ref Quaternion value);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_Roll(IntPtr nativeInstance, Radian value);
+        private static extern void Internal_Roll(IntPtr nativeInstance, ref Radian value);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_Yaw(IntPtr nativeInstance, Radian value);
+        private static extern void Internal_Yaw(IntPtr nativeInstance, ref Radian value);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_Pitch(IntPtr nativeInstance, Radian value);
+        private static extern void Internal_Pitch(IntPtr nativeInstance, ref Radian value);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetForward(IntPtr nativeInstance, Vector3 value);
+        private static extern void Internal_SetForward(IntPtr nativeInstance, ref Vector3 value);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_GetForward(IntPtr nativeInstance, out Vector3 value);

+ 10 - 7
MBansheeEngine/SpriteTexture.cs

@@ -21,7 +21,10 @@ namespace BansheeEngine
         /// <param name="texture">Texture to wrap by the sprite texture.</param>
         public SpriteTexture(Texture2D texture)
         {
-            Internal_CreateInstance(this, texture, Vector2.Zero, Vector2.One);
+            Vector2 offset = Vector2.Zero;
+            Vector2 scale = Vector2.One;
+
+            Internal_CreateInstance(this, texture, ref offset, ref scale);
         }
 
         /// <summary>
@@ -33,7 +36,7 @@ namespace BansheeEngine
         /// <param name="uvScale">Size of the area used by the sprite texture, in normalized coordinates.</param>
         public SpriteTexture(Texture2D texture, Vector2 uvOffset, Vector2 uvScale)
         {
-            Internal_CreateInstance(this, texture, uvOffset, uvScale);
+            Internal_CreateInstance(this, texture, ref uvOffset, ref uvScale);
         }
 
         /// <summary>
@@ -58,7 +61,7 @@ namespace BansheeEngine
         public Vector2 Offset
         {
             get { Vector2 value; Internal_GetOffset(mCachedPtr, out value); return value; }
-            set { Internal_SetOffset(mCachedPtr, value); }
+            set { Internal_SetOffset(mCachedPtr, ref value); }
         }
 
         /// <summary>
@@ -67,7 +70,7 @@ namespace BansheeEngine
         public Vector2 Scale
         {
             get { Vector2 value; Internal_GetScale(mCachedPtr, out value); return value; }
-            set { Internal_SetScale(mCachedPtr, value); }
+            set { Internal_SetScale(mCachedPtr, ref value); }
         }
 
         /// <summary>
@@ -88,7 +91,7 @@ namespace BansheeEngine
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_CreateInstance(SpriteTexture instance, 
-            Texture2D teture, Vector2 offset, Vector2 scale);
+            Texture2D texture, ref Vector2 offset, ref Vector2 scale);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern Texture2D Internal_GetTexture(IntPtr thisPtr);
@@ -100,13 +103,13 @@ namespace BansheeEngine
         private static extern void Internal_GetOffset(IntPtr thisPtr, out Vector2 value);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetOffset(IntPtr thisPtr, Vector2 value);
+        private static extern void Internal_SetOffset(IntPtr thisPtr, ref Vector2 value);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_GetScale(IntPtr thisPtr, out Vector2 value);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetScale(IntPtr thisPtr, Vector2 value);
+        private static extern void Internal_SetScale(IntPtr thisPtr, ref Vector2 value);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern int Internal_GetWidth(IntPtr thisPtr);

+ 139 - 139
MBansheeEngine/VirtualInput.cs

@@ -1,139 +1,139 @@
-using System.Runtime.CompilerServices;
-
-namespace BansheeEngine
-{
-    /// <summary>
-    /// Handles virtual input that allows you to receive virtual input events that hide the actual physical input, allowing 
-    /// you to easily change the input keys while being transparent to the external code.
-    /// </summary>
-    public static class VirtualInput
-    {
-        public delegate void OnButtonEventDelegate(VirtualButton btn, int deviceIdx);
-
-        /// <summary>
-        /// Triggered when a physical button combination corresponding to a virtual button is pressed.
-        /// </summary>
-        public static event OnButtonEventDelegate OnButtonDown;
-
-        /// <summary>
-        /// Triggered when a physical button combination corresponding to a virtual button is released.
-        /// </summary>
-        public static event OnButtonEventDelegate OnButtonUp;
-
-        /// <summary>
-        /// Triggered every frame while a physical button combination corresponding to a virtual button is being held down.
-        /// </summary>
-        public static event OnButtonEventDelegate OnButtonHeld;
-
-        /// <summary>
-        /// Input configuration that describes how physical keys map to virtual keys.
-        /// </summary>
-        public static InputConfiguration KeyConfig
-        {
-            get
-            {
-                return Internal_GetKeyConfig();
-            }
-
-            set
-            {
-                Internal_SetKeyConfig(value);
-            }
-        }
-
-        /// <summary>
-        /// Checks if the physical button combination corresponding to the specified virtual button is being pressed this
-        /// frame.
-        /// </summary>
-        /// <param name="button">Virtual button to check.</param>
-        /// <param name="deviceIdx">Optional device index in case multiple input devices are available.</param>
-		public static bool IsButtonDown(VirtualButton button, int deviceIdx = 0)
-	    {
-            return Internal_IsButtonDown(button, deviceIdx);
-	    }
-
-        /// <summary>
-        /// Checks if the physical button combination corresponding to the specified virtual button is being released this
-        /// frame.
-        /// </summary>
-        /// <param name="button">Virtual button to check.</param>
-        /// <param name="deviceIdx">Optional device index in case multiple input devices are available.</param>
-        public static bool IsButtonUp(VirtualButton button, int deviceIdx = 0)
-        {
-            return Internal_IsButtonUp(button, deviceIdx);
-        }
-
-        /// <summary>
-        /// Checks if the physical button combination corresponding to the specified virtual button is being held down.
-        /// </summary>
-        /// <param name="button">Virtual button to check.</param>
-        /// <param name="deviceIdx">Index of the device to check.</param>
-        public static bool IsButtonHeld(VirtualButton button, int deviceIdx = 0)
-        {
-            return Internal_IsButtonHeld(button, deviceIdx);
-        }
-
-        /// <summary>
-        /// Returns normalized value for the specified input axis. 
-        /// </summary>
-        /// <param name="axis">Virtual axis identifier.</param>
-        /// <param name="deviceIdx">Optional device index in case multiple input devices are available.</param>
-        /// <returns>Axis value, normally in [-1.0, 1.0] range, but can be outside the range for devices with unbound axes 
-        ///          (e.g. mouse).</returns>
-        public static float GetAxisValue(VirtualAxis axis, int deviceIdx = 0)
-        {
-            return Internal_GetAxisValue(axis, deviceIdx);
-        }
-
-        /// <summary>
-        /// Triggered by the runtime when the virtual button is pressed.
-        /// </summary>
-        /// <param name="button">Virtual button that was pressed.</param>
-        /// <param name="deviceIdx">Index of the device the button was pressed on.</param>
-        private static void Internal_TriggerButtonDown(VirtualButton button, int deviceIdx)
-        {
-            if (OnButtonDown != null)
-                OnButtonDown(button, deviceIdx);
-        }
-
-        /// <summary>
-        /// Triggered by the runtime when the virtual button is released.
-        /// </summary>
-        /// <param name="button">Virtual button that was released.</param>
-        /// <param name="deviceIdx">Index of the device the button was released on.</param>
-        private static void Internal_TriggerButtonUp(VirtualButton button, int deviceIdx)
-        {
-            if (OnButtonUp != null)
-                OnButtonUp(button, deviceIdx);
-        }
-
-        /// <summary>
-        /// Triggered by the runtime every frame while a virtual button is being held down.
-        /// </summary>
-        /// <param name="button">Virtual button that is being held down.</param>
-        /// <param name="deviceIdx">Index of the device the button is being held down on.</param>
-        private static void Internal_TriggerButtonHeld(VirtualButton button, int deviceIdx)
-        {
-            if (OnButtonHeld != null)
-                OnButtonHeld(button, deviceIdx);
-        }
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern InputConfiguration Internal_GetKeyConfig();
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetKeyConfig(InputConfiguration inputConfig);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern bool Internal_IsButtonDown(VirtualButton button, int deviceIdx);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern bool Internal_IsButtonUp(VirtualButton button, int deviceIdx);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern bool Internal_IsButtonHeld(VirtualButton button, int deviceIdx);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern float Internal_GetAxisValue(VirtualAxis button, int deviceIdx);
-	};
-}
+using System.Runtime.CompilerServices;
+
+namespace BansheeEngine
+{
+    /// <summary>
+    /// Handles virtual input that allows you to receive virtual input events that hide the actual physical input, allowing 
+    /// you to easily change the input keys while being transparent to the external code.
+    /// </summary>
+    public static class VirtualInput
+    {
+        public delegate void OnButtonEventDelegate(VirtualButton btn, int deviceIdx);
+
+        /// <summary>
+        /// Triggered when a physical button combination corresponding to a virtual button is pressed.
+        /// </summary>
+        public static event OnButtonEventDelegate OnButtonDown;
+
+        /// <summary>
+        /// Triggered when a physical button combination corresponding to a virtual button is released.
+        /// </summary>
+        public static event OnButtonEventDelegate OnButtonUp;
+
+        /// <summary>
+        /// Triggered every frame while a physical button combination corresponding to a virtual button is being held down.
+        /// </summary>
+        public static event OnButtonEventDelegate OnButtonHeld;
+
+        /// <summary>
+        /// Input configuration that describes how physical keys map to virtual keys.
+        /// </summary>
+        public static InputConfiguration KeyConfig
+        {
+            get
+            {
+                return Internal_GetKeyConfig();
+            }
+
+            set
+            {
+                Internal_SetKeyConfig(value);
+            }
+        }
+
+        /// <summary>
+        /// Checks if the physical button combination corresponding to the specified virtual button is being pressed this
+        /// frame.
+        /// </summary>
+        /// <param name="button">Virtual button to check.</param>
+        /// <param name="deviceIdx">Optional device index in case multiple input devices are available.</param>
+		public static bool IsButtonDown(VirtualButton button, int deviceIdx = 0)
+	    {
+            return Internal_IsButtonDown(ref button, deviceIdx);
+	    }
+
+        /// <summary>
+        /// Checks if the physical button combination corresponding to the specified virtual button is being released this
+        /// frame.
+        /// </summary>
+        /// <param name="button">Virtual button to check.</param>
+        /// <param name="deviceIdx">Optional device index in case multiple input devices are available.</param>
+        public static bool IsButtonUp(VirtualButton button, int deviceIdx = 0)
+        {
+            return Internal_IsButtonUp(ref button, deviceIdx);
+        }
+
+        /// <summary>
+        /// Checks if the physical button combination corresponding to the specified virtual button is being held down.
+        /// </summary>
+        /// <param name="button">Virtual button to check.</param>
+        /// <param name="deviceIdx">Index of the device to check.</param>
+        public static bool IsButtonHeld(VirtualButton button, int deviceIdx = 0)
+        {
+            return Internal_IsButtonHeld(ref button, deviceIdx);
+        }
+
+        /// <summary>
+        /// Returns normalized value for the specified input axis. 
+        /// </summary>
+        /// <param name="axis">Virtual axis identifier.</param>
+        /// <param name="deviceIdx">Optional device index in case multiple input devices are available.</param>
+        /// <returns>Axis value, normally in [-1.0, 1.0] range, but can be outside the range for devices with unbound axes 
+        ///          (e.g. mouse).</returns>
+        public static float GetAxisValue(VirtualAxis axis, int deviceIdx = 0)
+        {
+            return Internal_GetAxisValue(ref axis, deviceIdx);
+        }
+
+        /// <summary>
+        /// Triggered by the runtime when the virtual button is pressed.
+        /// </summary>
+        /// <param name="button">Virtual button that was pressed.</param>
+        /// <param name="deviceIdx">Index of the device the button was pressed on.</param>
+        private static void Internal_TriggerButtonDown(VirtualButton button, int deviceIdx)
+        {
+            if (OnButtonDown != null)
+                OnButtonDown(button, deviceIdx);
+        }
+
+        /// <summary>
+        /// Triggered by the runtime when the virtual button is released.
+        /// </summary>
+        /// <param name="button">Virtual button that was released.</param>
+        /// <param name="deviceIdx">Index of the device the button was released on.</param>
+        private static void Internal_TriggerButtonUp(VirtualButton button, int deviceIdx)
+        {
+            if (OnButtonUp != null)
+                OnButtonUp(button, deviceIdx);
+        }
+
+        /// <summary>
+        /// Triggered by the runtime every frame while a virtual button is being held down.
+        /// </summary>
+        /// <param name="button">Virtual button that is being held down.</param>
+        /// <param name="deviceIdx">Index of the device the button is being held down on.</param>
+        private static void Internal_TriggerButtonHeld(VirtualButton button, int deviceIdx)
+        {
+            if (OnButtonHeld != null)
+                OnButtonHeld(button, deviceIdx);
+        }
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern InputConfiguration Internal_GetKeyConfig();
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetKeyConfig(InputConfiguration inputConfig);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern bool Internal_IsButtonDown(ref VirtualButton button, int deviceIdx);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern bool Internal_IsButtonUp(ref VirtualButton button, int deviceIdx);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern bool Internal_IsButtonHeld(ref VirtualButton button, int deviceIdx);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern float Internal_GetAxisValue(ref VirtualAxis button, int deviceIdx);
+	};
+}

+ 133 - 133
SBansheeEngine/Include/BsScriptCamera.h

@@ -1,134 +1,134 @@
-#pragma once
-
-#include "BsScriptEnginePrerequisites.h"
-#include "BsScriptObject.h"
-#include "BsVector2.h"
-#include "BsVector3.h"
-#include "BsVector2I.h"
-#include "BsRay.h"
-#include "BsDegree.h"
-#include "BsMatrix4.h"
-#include "BsRect2.h"
-#include "BsColor.h"
-
-namespace BansheeEngine
-{
-	/**
-	 * @brief	Interop class between C++ & CLR for Camera.
-	 */
-	class BS_SCR_BE_EXPORT ScriptCamera : public ScriptObject<ScriptCamera>
-	{
-	public:
-		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "NativeCamera")
-
-		/**
-		 * @brief	Returns the wrapped native Camera object.
-		 */
-		SPtr<Camera> getInternal() const { return mCamera; }
-
-	private:
-		ScriptCamera(MonoObject* managedInstance, const HSceneObject& parentSO);
-		~ScriptCamera();
-
-		/**
-		 * @brief	Updates the internal camera handler from the transform of the
-		 *			provided scene object.
-		 */
-		void updateView(const HSceneObject& parent);
-
-		/**
-		 * @brief	Destroys the internal camera handler object.
-		 */
-		void destroy();
-
-		/**
-		 * @copydoc	ScriptObject::_onManagedInstanceDeleted
-		 */
-		void _onManagedInstanceDeleted() override;
-
-		SPtr<Camera> mCamera;
-		UINT32 mLastUpdateHash;
-
-		/************************************************************************/
-		/* 								CLR HOOKS						   		*/
-		/************************************************************************/
-		static void internal_Create(MonoObject* managedInstance, ScriptSceneObject* parentSO);
-
-		static float internal_GetAspect(ScriptCamera* instance);
-		static void internal_SetAspect(ScriptCamera* instance, float value);
-		static float internal_GetNearClip(ScriptCamera* instance);
-		static void internal_SetNearClip(ScriptCamera* instance, float value);
-
-		static float internal_GetFarClip(ScriptCamera* instance);
-		static void internal_SetFarClip(ScriptCamera* instance, float value);
-
-		static void internal_GetFieldOfView(ScriptCamera* instance, Degree* value);
-		static void internal_SetFieldOfView(ScriptCamera* instance, Degree value);
-
-		static Rect2 internal_GetViewportRect(ScriptCamera* instance);
-		static void internal_SetViewportRect(ScriptCamera* instance, Rect2 value);
-
-		static UINT32 internal_GetProjectionType(ScriptCamera* instance);
-		static void internal_SetProjectionType(ScriptCamera* instance, UINT32 value);
-
-		static float internal_GetOrthographicHeight(ScriptCamera* instance);
-		static void internal_SetOrthographicHeight(ScriptCamera* instance, float value);
-
-		static float internal_GetOrthographicWidth(ScriptCamera* instance);
-
-		static Color internal_GetClearColor(ScriptCamera* instance);
-		static void internal_SetClearColor(ScriptCamera* instance, Color value);
-
-		static float internal_GetDepthClearValue(ScriptCamera* instance);
-		static void internal_SetDepthClearValue(ScriptCamera* instance, float value);
-
-		static UINT16 internal_GetStencilClearValue(ScriptCamera* instance);
-		static void internal_SetStencilClearValue(ScriptCamera* instance, UINT16 value);
-
-		static UINT32 internal_GetClearFlags(ScriptCamera* instance);
-		static void internal_SetClearFlags(ScriptCamera* instance, UINT32 value);
-
-		static int internal_GetPriority(ScriptCamera* instance);
-		static void internal_SetPriority(ScriptCamera* instance, int value);
-
-		static UINT64 internal_GetLayers(ScriptCamera* instance);
-		static void internal_SetLayers(ScriptCamera* instance, UINT64 value);
-
-		static Matrix4 internal_GetProjMatrix(ScriptCamera* instance);
-		static Matrix4 internal_GetProjMatrixInv(ScriptCamera* instance);
-
-		static Matrix4 internal_GetViewMatrix(ScriptCamera* instance);
-		static Matrix4 internal_GetViewMatrixInv(ScriptCamera* instance);
-
-		static int internal_GetWidthPixels(ScriptCamera* instance);
-		static int internal_GetHeightPixels(ScriptCamera* instance);
-
-		static Vector2I internal_WorldToScreen(ScriptCamera* instance, Vector3 value);
-		static Vector2 internal_WorldToClip(ScriptCamera* instance, Vector3 value);
-		static Vector3 internal_WorldToView(ScriptCamera* instance, Vector3 value);
-
-		static Vector3 internal_ScreenToWorld(ScriptCamera* instance, Vector2I value, float depth);
-		static Vector3 internal_ScreenToView(ScriptCamera* instance, Vector2I value, float depth);
-		static Vector2 internal_ScreenToClip(ScriptCamera* instance, Vector2I value);
-
-		static Vector3 internal_ViewToWorld(ScriptCamera* instance, Vector3 value);
-		static Vector2I internal_ViewToScreen(ScriptCamera* instance, Vector3 value);
-		static Vector2 internal_ViewToClip(ScriptCamera* instance, Vector3 value);
-
-		static Vector3 internal_ClipToWorld(ScriptCamera* instance, Vector2 value, float depth);
-		static Vector3 internal_ClipToView(ScriptCamera* instance, Vector2 value, float depth);
-		static Vector2I internal_ClipToScreen(ScriptCamera* instance, Vector2 value);
-
-		static Ray internal_ScreenToWorldRay(ScriptCamera* instance, Vector2I value);
-		static Vector3 internal_ProjectPoint(ScriptCamera* instance, Vector3 value);
-		static Vector3 internal_UnprojectPoint(ScriptCamera* instance, Vector3 value);
-
-		static void internal_SetRenderTarget(ScriptCamera* instance, ScriptRenderTarget* target);
-
-		static bool internal_GetMain(ScriptCamera* instance);
-		static void internal_SetMain(ScriptCamera* instance, bool main);
-
-		static void internal_UpdateView(ScriptCamera* instance, ScriptSceneObject* parent);
-		static void internal_OnDestroy(ScriptCamera* instance);
-	};
+#pragma once
+
+#include "BsScriptEnginePrerequisites.h"
+#include "BsScriptObject.h"
+#include "BsVector2.h"
+#include "BsVector3.h"
+#include "BsVector2I.h"
+#include "BsRay.h"
+#include "BsDegree.h"
+#include "BsMatrix4.h"
+#include "BsRect2.h"
+#include "BsColor.h"
+
+namespace BansheeEngine
+{
+	/**
+	 * @brief	Interop class between C++ & CLR for Camera.
+	 */
+	class BS_SCR_BE_EXPORT ScriptCamera : public ScriptObject<ScriptCamera>
+	{
+	public:
+		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "NativeCamera")
+
+		/**
+		 * @brief	Returns the wrapped native Camera object.
+		 */
+		SPtr<Camera> getInternal() const { return mCamera; }
+
+	private:
+		ScriptCamera(MonoObject* managedInstance, const HSceneObject& parentSO);
+		~ScriptCamera();
+
+		/**
+		 * @brief	Updates the internal camera handler from the transform of the
+		 *			provided scene object.
+		 */
+		void updateView(const HSceneObject& parent);
+
+		/**
+		 * @brief	Destroys the internal camera handler object.
+		 */
+		void destroy();
+
+		/**
+		 * @copydoc	ScriptObject::_onManagedInstanceDeleted
+		 */
+		void _onManagedInstanceDeleted() override;
+
+		SPtr<Camera> mCamera;
+		UINT32 mLastUpdateHash;
+
+		/************************************************************************/
+		/* 								CLR HOOKS						   		*/
+		/************************************************************************/
+		static void internal_Create(MonoObject* managedInstance, ScriptSceneObject* parentSO);
+
+		static float internal_GetAspect(ScriptCamera* instance);
+		static void internal_SetAspect(ScriptCamera* instance, float value);
+		static float internal_GetNearClip(ScriptCamera* instance);
+		static void internal_SetNearClip(ScriptCamera* instance, float value);
+
+		static float internal_GetFarClip(ScriptCamera* instance);
+		static void internal_SetFarClip(ScriptCamera* instance, float value);
+
+		static void internal_GetFieldOfView(ScriptCamera* instance, Degree* value);
+		static void internal_SetFieldOfView(ScriptCamera* instance, Degree* value);
+
+		static void internal_GetViewportRect(ScriptCamera* instance, Rect2* value);
+		static void internal_SetViewportRect(ScriptCamera* instance, Rect2* value);
+
+		static UINT32 internal_GetProjectionType(ScriptCamera* instance);
+		static void internal_SetProjectionType(ScriptCamera* instance, UINT32 value);
+
+		static float internal_GetOrthographicHeight(ScriptCamera* instance);
+		static void internal_SetOrthographicHeight(ScriptCamera* instance, float value);
+
+		static float internal_GetOrthographicWidth(ScriptCamera* instance);
+
+		static void internal_GetClearColor(ScriptCamera* instance, Color* value);
+		static void internal_SetClearColor(ScriptCamera* instance, Color* value);
+
+		static float internal_GetDepthClearValue(ScriptCamera* instance);
+		static void internal_SetDepthClearValue(ScriptCamera* instance, float value);
+
+		static UINT16 internal_GetStencilClearValue(ScriptCamera* instance);
+		static void internal_SetStencilClearValue(ScriptCamera* instance, UINT16 value);
+
+		static UINT32 internal_GetClearFlags(ScriptCamera* instance);
+		static void internal_SetClearFlags(ScriptCamera* instance, UINT32 value);
+
+		static int internal_GetPriority(ScriptCamera* instance);
+		static void internal_SetPriority(ScriptCamera* instance, int value);
+
+		static UINT64 internal_GetLayers(ScriptCamera* instance);
+		static void internal_SetLayers(ScriptCamera* instance, UINT64 value);
+
+		static void internal_GetProjMatrix(ScriptCamera* instance, Matrix4* value);
+		static void internal_GetProjMatrixInv(ScriptCamera* instance, Matrix4* value);
+
+		static void internal_GetViewMatrix(ScriptCamera* instance, Matrix4* value);
+		static void internal_GetViewMatrixInv(ScriptCamera* instance, Matrix4* value);
+
+		static int internal_GetWidthPixels(ScriptCamera* instance);
+		static int internal_GetHeightPixels(ScriptCamera* instance);
+
+		static void internal_WorldToScreen(ScriptCamera* instance, Vector3* value, Vector2I* output);
+		static void internal_WorldToClip(ScriptCamera* instance, Vector3* value, Vector2* output);
+		static void internal_WorldToView(ScriptCamera* instance, Vector3* value, Vector3* output);
+
+		static void internal_ScreenToWorld(ScriptCamera* instance, Vector2I* value, float depth, Vector3* output);
+		static void internal_ScreenToView(ScriptCamera* instance, Vector2I* value, float depth, Vector3* output);
+		static void internal_ScreenToClip(ScriptCamera* instance, Vector2I* value, Vector2* output);
+
+		static void internal_ViewToWorld(ScriptCamera* instance, Vector3* value, Vector3* output);
+		static void internal_ViewToScreen(ScriptCamera* instance, Vector3* value, Vector2I* output);
+		static void internal_ViewToClip(ScriptCamera* instance, Vector3* value, Vector2* output);
+
+		static void internal_ClipToWorld(ScriptCamera* instance, Vector2* value, float depth, Vector3* output);
+		static void internal_ClipToView(ScriptCamera* instance, Vector2* value, float depth, Vector3* output);
+		static void internal_ClipToScreen(ScriptCamera* instance, Vector2* value, Vector2I* output);
+
+		static void internal_ScreenToWorldRay(ScriptCamera* instance, Vector2I* value, Ray* output);
+		static void internal_ProjectPoint(ScriptCamera* instance, Vector3* value, Vector3* output);
+		static void internal_UnprojectPoint(ScriptCamera* instance, Vector3* value, Vector3* output);
+
+		static void internal_SetRenderTarget(ScriptCamera* instance, ScriptRenderTarget* target);
+
+		static bool internal_GetMain(ScriptCamera* instance);
+		static void internal_SetMain(ScriptCamera* instance, bool main);
+
+		static void internal_UpdateView(ScriptCamera* instance, ScriptSceneObject* parent);
+		static void internal_OnDestroy(ScriptCamera* instance);
+	};
 }

+ 43 - 43
SBansheeEngine/Include/BsScriptContextMenu.h

@@ -1,44 +1,44 @@
-#pragma once
-
-#include "BsScriptEnginePrerequisites.h"
-#include "BsScriptObject.h"
-
-namespace BansheeEngine
-{
-	/**
-	 * @brief	Interop class between C++ & CLR for GUIContextMenu.
-	 */
-	class BS_SCR_BE_EXPORT ScriptContextMenu : public ScriptObject < ScriptContextMenu >
-	{
-	public:
-		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "ContextMenu")
-
-		/**
-		 * @brief	Returns the internal native context menu object.
-		 */
-		GUIContextMenuPtr getInternal() const { return mContextMenu; }
-
-	private:
-		ScriptContextMenu(MonoObject* instance);
-
-		/**
-		 * @brief	Triggered when an item in the context menu is clicked.
-		 *
-		 * @param	idx	Sequential index of the item that was clicked.
-		 */
-		void onContextMenuItemTriggered(UINT32 idx);
-
-		GUIContextMenuPtr mContextMenu;
-
-		/************************************************************************/
-		/* 								CLR HOOKS						   		*/
-		/************************************************************************/
-		typedef void(__stdcall *OnEntryTriggeredThunkDef) (MonoObject*, UINT32 callbackIdx, MonoException**);
-		static OnEntryTriggeredThunkDef onEntryTriggered;
-
-		static void internal_CreateInstance(MonoObject* instance);
-		static void internal_AddItem(ScriptContextMenu* instance, MonoString* path, UINT32 callbackIdx, ShortcutKey shortcut);
-		static void internal_AddSeparator(ScriptContextMenu* instance, MonoString* path);
-		static void internal_SetLocalizedName(ScriptContextMenu* instance, MonoString* label, ScriptHString* name);
-	};
+#pragma once
+
+#include "BsScriptEnginePrerequisites.h"
+#include "BsScriptObject.h"
+
+namespace BansheeEngine
+{
+	/**
+	 * @brief	Interop class between C++ & CLR for GUIContextMenu.
+	 */
+	class BS_SCR_BE_EXPORT ScriptContextMenu : public ScriptObject < ScriptContextMenu >
+	{
+	public:
+		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "ContextMenu")
+
+		/**
+		 * @brief	Returns the internal native context menu object.
+		 */
+		GUIContextMenuPtr getInternal() const { return mContextMenu; }
+
+	private:
+		ScriptContextMenu(MonoObject* instance);
+
+		/**
+		 * @brief	Triggered when an item in the context menu is clicked.
+		 *
+		 * @param	idx	Sequential index of the item that was clicked.
+		 */
+		void onContextMenuItemTriggered(UINT32 idx);
+
+		GUIContextMenuPtr mContextMenu;
+
+		/************************************************************************/
+		/* 								CLR HOOKS						   		*/
+		/************************************************************************/
+		typedef void(__stdcall *OnEntryTriggeredThunkDef) (MonoObject*, UINT32 callbackIdx, MonoException**);
+		static OnEntryTriggeredThunkDef onEntryTriggered;
+
+		static void internal_CreateInstance(MonoObject* instance);
+		static void internal_AddItem(ScriptContextMenu* instance, MonoString* path, UINT32 callbackIdx, ShortcutKey* shortcut);
+		static void internal_AddSeparator(ScriptContextMenu* instance, MonoString* path);
+		static void internal_SetLocalizedName(ScriptContextMenu* instance, MonoString* label, ScriptHString* name);
+	};
 }

+ 36 - 36
SBansheeEngine/Include/BsScriptCursor.h

@@ -1,37 +1,37 @@
-#pragma once
-
-#include "BsScriptEnginePrerequisites.h"
-#include "BsScriptObject.h"
-#include "BsRect2I.h"
-#include "BsVector2I.h"
-
-namespace BansheeEngine
-{
-	/**
-	 * @brief	Interop class between C++ & CLR for Cursor.
-	 */
-	class BS_SCR_BE_EXPORT ScriptCursor : public ScriptObject <ScriptCursor>
-	{
-	public:
-		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "Cursor")
-
-	private:
-		ScriptCursor(MonoObject* instance);
-
-		/************************************************************************/
-		/* 								CLR HOOKS						   		*/
-		/************************************************************************/
-		static void internal_getScreenPosition(Vector2I* value);
-		static void internal_setScreenPosition(Vector2I value);
-		static void internal_hide();
-		static void internal_show();
-		static void internal_clipToRect(Rect2I value);
-		static void internal_clipDisable();
-		static void internal_setCursorStr(MonoString* name);
-		static void internal_setCursor(CursorType cursor);
-		static void internal_setCursorIconStr(MonoString* name, MonoObject* iconData, Vector2I hotspot);
-		static void internal_setCursorIcon(CursorType cursor, MonoObject* iconData, Vector2I hotspot);
-		static void internal_clearCursorIconStr(MonoString* name);
-		static void internal_clearCursorIcon(CursorType cursor);
-	};
+#pragma once
+
+#include "BsScriptEnginePrerequisites.h"
+#include "BsScriptObject.h"
+#include "BsRect2I.h"
+#include "BsVector2I.h"
+
+namespace BansheeEngine
+{
+	/**
+	 * @brief	Interop class between C++ & CLR for Cursor.
+	 */
+	class BS_SCR_BE_EXPORT ScriptCursor : public ScriptObject <ScriptCursor>
+	{
+	public:
+		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "Cursor")
+
+	private:
+		ScriptCursor(MonoObject* instance);
+
+		/************************************************************************/
+		/* 								CLR HOOKS						   		*/
+		/************************************************************************/
+		static void internal_getScreenPosition(Vector2I* value);
+		static void internal_setScreenPosition(Vector2I* value);
+		static void internal_hide();
+		static void internal_show();
+		static void internal_clipToRect(Rect2I* value);
+		static void internal_clipDisable();
+		static void internal_setCursorStr(MonoString* name);
+		static void internal_setCursor(CursorType cursor);
+		static void internal_setCursorIconStr(MonoString* name, MonoObject* iconData, Vector2I* hotspot);
+		static void internal_setCursorIcon(CursorType cursor, MonoObject* iconData, Vector2I* hotspot);
+		static void internal_clearCursorIconStr(MonoString* name);
+		static void internal_clearCursorIcon(CursorType cursor);
+	};
 }

+ 68 - 68
SBansheeEngine/Include/BsScriptMaterial.h

@@ -1,69 +1,69 @@
-#pragma once
-
-#include "BsScriptEnginePrerequisites.h"
-#include "BsScriptResource.h"
-#include "BsMaterial.h"
-#include "BsVector2.h"
-#include "BsVector3.h"
-#include "BsVector4.h"
-#include "BsMatrix3.h"
-#include "BsMatrix4.h"
-#include "BsColor.h"
-
-namespace BansheeEngine
-{
-	/**
-	 * @brief	Interop class between C++ & CLR for Material.
-	 */
-	class BS_SCR_BE_EXPORT ScriptMaterial : public TScriptResource <ScriptMaterial, Material>
-	{
-	public:
-		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "Material")
-
-	private:
-		friend class ScriptResourceManager;
-
-		ScriptMaterial(MonoObject* instance, const HMaterial& material);
-
-		/**
-		 * @copydoc	ScriptObjectBase::_createManagedInstance
-		 */
-		MonoObject* _createManagedInstance(bool construct) override;
-
-		/**
-		 * @brief	Creates an empty, uninitialized managed instance of the resource interop object.
-		 */
-		static MonoObject* createInstance();
-
-		/************************************************************************/
-		/* 								CLR HOOKS						   		*/
-		/************************************************************************/
-		static void internal_CreateInstance(MonoObject* instance, ScriptShader* shader);
-		static MonoObject* internal_Clone(ScriptMaterial* nativeInstance);
-
-		static MonoObject* internal_GetShader(ScriptMaterial* nativeInstance);
-		static void internal_SetShader(ScriptMaterial* nativeInstance, ScriptShader* shader);
-
-		static void internal_SetFloat(ScriptMaterial* nativeInstance, MonoString* name, float value);
-		static void internal_SetVector2(ScriptMaterial* nativeInstance, MonoString* name, Vector2 value);
-		static void internal_SetVector3(ScriptMaterial* nativeInstance, MonoString* name, Vector3 value);
-		static void internal_SetVector4(ScriptMaterial* nativeInstance, MonoString* name, Vector4 value);
-		static void internal_SetMatrix3(ScriptMaterial* nativeInstance, MonoString* name, Matrix3 value);
-		static void internal_SetMatrix4(ScriptMaterial* nativeInstance, MonoString* name, Matrix4 value);
-		static void internal_SetColor(ScriptMaterial* nativeInstance, MonoString* name, Color value);
-		static void internal_SetTexture2D(ScriptMaterial* nativeInstance, MonoString* name, ScriptTexture2D* value);
-		static void internal_SetTexture3D(ScriptMaterial* nativeInstance, MonoString* name, ScriptTexture3D* value);
-		static void internal_SetTextureCube(ScriptMaterial* nativeInstance, MonoString* name, ScriptTextureCube* value);
-
-		static float internal_GetFloat(ScriptMaterial* nativeInstance, MonoString* name);
-		static Vector2 internal_GetVector2(ScriptMaterial* nativeInstance, MonoString* name);
-		static Vector3 internal_GetVector3(ScriptMaterial* nativeInstance, MonoString* name);
-		static Vector4 internal_GetVector4(ScriptMaterial* nativeInstance, MonoString* name);
-		static Matrix3 internal_GetMatrix3(ScriptMaterial* nativeInstance, MonoString* name);
-		static Matrix4 internal_GetMatrix4(ScriptMaterial* nativeInstance, MonoString* name);
-		static Color internal_GetColor(ScriptMaterial* nativeInstance, MonoString* name);
-		static MonoObject* internal_GetTexture2D(ScriptMaterial* nativeInstance, MonoString* name);
-		static MonoObject* internal_GetTexture3D(ScriptMaterial* nativeInstance, MonoString* name);
-		static MonoObject* internal_GetTextureCube(ScriptMaterial* nativeInstance, MonoString* name);
-	};
+#pragma once
+
+#include "BsScriptEnginePrerequisites.h"
+#include "BsScriptResource.h"
+#include "BsMaterial.h"
+#include "BsVector2.h"
+#include "BsVector3.h"
+#include "BsVector4.h"
+#include "BsMatrix3.h"
+#include "BsMatrix4.h"
+#include "BsColor.h"
+
+namespace BansheeEngine
+{
+	/**
+	 * @brief	Interop class between C++ & CLR for Material.
+	 */
+	class BS_SCR_BE_EXPORT ScriptMaterial : public TScriptResource <ScriptMaterial, Material>
+	{
+	public:
+		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "Material")
+
+	private:
+		friend class ScriptResourceManager;
+
+		ScriptMaterial(MonoObject* instance, const HMaterial& material);
+
+		/**
+		 * @copydoc	ScriptObjectBase::_createManagedInstance
+		 */
+		MonoObject* _createManagedInstance(bool construct) override;
+
+		/**
+		 * @brief	Creates an empty, uninitialized managed instance of the resource interop object.
+		 */
+		static MonoObject* createInstance();
+
+		/************************************************************************/
+		/* 								CLR HOOKS						   		*/
+		/************************************************************************/
+		static void internal_CreateInstance(MonoObject* instance, ScriptShader* shader);
+		static MonoObject* internal_Clone(ScriptMaterial* nativeInstance);
+
+		static MonoObject* internal_GetShader(ScriptMaterial* nativeInstance);
+		static void internal_SetShader(ScriptMaterial* nativeInstance, ScriptShader* shader);
+
+		static void internal_SetFloat(ScriptMaterial* nativeInstance, MonoString* name, float value);
+		static void internal_SetVector2(ScriptMaterial* nativeInstance, MonoString* name, Vector2* value);
+		static void internal_SetVector3(ScriptMaterial* nativeInstance, MonoString* name, Vector3* value);
+		static void internal_SetVector4(ScriptMaterial* nativeInstance, MonoString* name, Vector4* value);
+		static void internal_SetMatrix3(ScriptMaterial* nativeInstance, MonoString* name, Matrix3* value);
+		static void internal_SetMatrix4(ScriptMaterial* nativeInstance, MonoString* name, Matrix4* value);
+		static void internal_SetColor(ScriptMaterial* nativeInstance, MonoString* name, Color* value);
+		static void internal_SetTexture2D(ScriptMaterial* nativeInstance, MonoString* name, ScriptTexture2D* value);
+		static void internal_SetTexture3D(ScriptMaterial* nativeInstance, MonoString* name, ScriptTexture3D* value);
+		static void internal_SetTextureCube(ScriptMaterial* nativeInstance, MonoString* name, ScriptTextureCube* value);
+
+		static float internal_GetFloat(ScriptMaterial* nativeInstance, MonoString* name);
+		static void internal_GetVector2(ScriptMaterial* nativeInstance, MonoString* name, Vector2* value);
+		static void internal_GetVector3(ScriptMaterial* nativeInstance, MonoString* name, Vector3* value);
+		static void internal_GetVector4(ScriptMaterial* nativeInstance, MonoString* name, Vector4* value);
+		static void internal_GetMatrix3(ScriptMaterial* nativeInstance, MonoString* name, Matrix3* value);
+		static void internal_GetMatrix4(ScriptMaterial* nativeInstance, MonoString* name, Matrix4* value);
+		static void internal_GetColor(ScriptMaterial* nativeInstance, MonoString* name, Color* value);
+		static MonoObject* internal_GetTexture2D(ScriptMaterial* nativeInstance, MonoString* name);
+		static MonoObject* internal_GetTexture3D(ScriptMaterial* nativeInstance, MonoString* name);
+		static MonoObject* internal_GetTextureCube(ScriptMaterial* nativeInstance, MonoString* name);
+	};
 }

+ 63 - 63
SBansheeEngine/Include/BsScriptPixelData.h

@@ -1,64 +1,64 @@
-#pragma once
-
-#include "BsScriptEnginePrerequisites.h"
-#include "BsScriptObject.h"
-#include "BsPixelData.h"
-#include "BsColor.h"
-
-namespace BansheeEngine
-{
-	/**
-	 * @brief	Interop class between C++ & CLR for PixelData.
-	 */
-	class BS_SCR_BE_EXPORT ScriptPixelData : public ScriptObject <ScriptPixelData>
-	{
-	public:
-		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "PixelData")
-
-		/**
-		 * @brief	Returns the internal wrapped pixel data.
-		 */
-		PixelDataPtr getInternalValue() const { return mPixelData; }
-
-		/**
-		 * @brief	Creates a new managed pixel data instance that wraps
-		 *			the provided native pixel data instance.
-		 */
-		static MonoObject* create(const PixelDataPtr& pixelData);
-
-	private:
-		ScriptPixelData(MonoObject* managedInstance);
-		~ScriptPixelData();
-
-		/**
-		 * @brief	Initializes the object. Must be called after construction
-		 *			and before use.
-		 */
-		void initialize(const PixelDataPtr& pixelData);
-
-		/**
-		 * @brief	Checks is the underlying pixel data of the provided object locked.
-		 *			When locked pixel data cannot be accessed.
-		 */
-		static bool checkIsLocked(ScriptPixelData* thisPtr);
-
-		PixelDataPtr mPixelData;
-
-		/************************************************************************/
-		/* 								CLR HOOKS						   		*/
-		/************************************************************************/
-		static void internal_createInstance(MonoObject* instance, PixelVolume volume, PixelFormat format);
-		static void internal_getPixel(ScriptPixelData* thisPtr, int x, int y, int z, Color* value);
-		static void internal_setPixel(ScriptPixelData* thisPtr, int x, int y, int z, Color value);
-		static void internal_getPixels(ScriptPixelData* thisPtr, MonoArray** value);
-		static void internal_setPixels(ScriptPixelData* thisPtr, MonoArray* value);
-		static void internal_getRawPixels(ScriptPixelData* thisPtr, MonoArray** value);
-		static void internal_setRawPixels(ScriptPixelData* thisPtr, MonoArray* value);
-		static void internal_getExtents(ScriptPixelData* thisPtr, PixelVolume* value);
-		static void internal_getFormat(ScriptPixelData* thisPtr, PixelFormat* value);
-		static void internal_getRowPitch(ScriptPixelData* thisPtr, int* value);
-		static void internal_getSlicePitch(ScriptPixelData* thisPtr, int* value);
-		static void internal_getSize(ScriptPixelData* thisPtr, int* value);
-		static void internal_getIsConsecutive(ScriptPixelData* thisPtr, bool* value);
-	};
+#pragma once
+
+#include "BsScriptEnginePrerequisites.h"
+#include "BsScriptObject.h"
+#include "BsPixelData.h"
+#include "BsColor.h"
+
+namespace BansheeEngine
+{
+	/**
+	 * @brief	Interop class between C++ & CLR for PixelData.
+	 */
+	class BS_SCR_BE_EXPORT ScriptPixelData : public ScriptObject <ScriptPixelData>
+	{
+	public:
+		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "PixelData")
+
+		/**
+		 * @brief	Returns the internal wrapped pixel data.
+		 */
+		PixelDataPtr getInternalValue() const { return mPixelData; }
+
+		/**
+		 * @brief	Creates a new managed pixel data instance that wraps
+		 *			the provided native pixel data instance.
+		 */
+		static MonoObject* create(const PixelDataPtr& pixelData);
+
+	private:
+		ScriptPixelData(MonoObject* managedInstance);
+		~ScriptPixelData();
+
+		/**
+		 * @brief	Initializes the object. Must be called after construction
+		 *			and before use.
+		 */
+		void initialize(const PixelDataPtr& pixelData);
+
+		/**
+		 * @brief	Checks is the underlying pixel data of the provided object locked.
+		 *			When locked pixel data cannot be accessed.
+		 */
+		static bool checkIsLocked(ScriptPixelData* thisPtr);
+
+		PixelDataPtr mPixelData;
+
+		/************************************************************************/
+		/* 								CLR HOOKS						   		*/
+		/************************************************************************/
+		static void internal_createInstance(MonoObject* instance, PixelVolume* volume, PixelFormat format);
+		static void internal_getPixel(ScriptPixelData* thisPtr, int x, int y, int z, Color* value);
+		static void internal_setPixel(ScriptPixelData* thisPtr, int x, int y, int z, Color* value);
+		static void internal_getPixels(ScriptPixelData* thisPtr, MonoArray** value);
+		static void internal_setPixels(ScriptPixelData* thisPtr, MonoArray* value);
+		static void internal_getRawPixels(ScriptPixelData* thisPtr, MonoArray** value);
+		static void internal_setRawPixels(ScriptPixelData* thisPtr, MonoArray* value);
+		static void internal_getExtents(ScriptPixelData* thisPtr, PixelVolume* value);
+		static void internal_getFormat(ScriptPixelData* thisPtr, PixelFormat* value);
+		static void internal_getRowPitch(ScriptPixelData* thisPtr, int* value);
+		static void internal_getSlicePitch(ScriptPixelData* thisPtr, int* value);
+		static void internal_getSize(ScriptPixelData* thisPtr, int* value);
+		static void internal_getIsConsecutive(ScriptPixelData* thisPtr, bool* value);
+	};
 }

+ 35 - 35
SBansheeEngine/Include/BsScriptPixelUtility.h

@@ -1,36 +1,36 @@
-#pragma once
-
-#include "BsScriptEnginePrerequisites.h"
-#include "BsScriptObject.h"
-#include "BsPixelData.h"
-#include "BsPixelUtil.h"
-
-namespace BansheeEngine
-{
-	/**
-	 * @brief	Interop class between C++ & CLR for PixelUtility.
-	 */
-	class BS_SCR_BE_EXPORT ScriptPixelUtility : public ScriptObject <ScriptPixelUtility>
-	{
-	public:
-		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "PixelUtility")
-
-	private:
-		ScriptPixelUtility(MonoObject* instance);
-
-		/************************************************************************/
-		/* 								CLR HOOKS						   		*/
-		/************************************************************************/
-		static void internal_getMemorySize(UINT32 width, UINT32 height, UINT32 depth, PixelFormat format, UINT32* value);
-		static void internal_hasAlpha(PixelFormat format, bool* value);
-		static void internal_isFloatingPoint(PixelFormat format, bool* value);
-		static void internal_isCompressed(PixelFormat format, bool* value);
-		static void internal_isDepth(PixelFormat format, bool* value);
-		static void internal_getMaxMipmaps(UINT32 width, UINT32 height, UINT32 depth, PixelFormat format, UINT32* value);
-		static MonoObject* internal_convertFormat(MonoObject* source, PixelFormat newFormat);
-		static MonoObject* internal_compress(MonoObject* source, CompressionOptions options);
-		static MonoArray* internal_generateMipmaps(MonoObject* source, MipMapGenOptions options);
-		static MonoObject* internal_scale(MonoObject* source, PixelVolume newSize, PixelUtil::Filter filter);
-		static void internal_applyGamma(MonoObject* source, float gamma);
-	};
+#pragma once
+
+#include "BsScriptEnginePrerequisites.h"
+#include "BsScriptObject.h"
+#include "BsPixelData.h"
+#include "BsPixelUtil.h"
+
+namespace BansheeEngine
+{
+	/**
+	 * @brief	Interop class between C++ & CLR for PixelUtility.
+	 */
+	class BS_SCR_BE_EXPORT ScriptPixelUtility : public ScriptObject <ScriptPixelUtility>
+	{
+	public:
+		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "PixelUtility")
+
+	private:
+		ScriptPixelUtility(MonoObject* instance);
+
+		/************************************************************************/
+		/* 								CLR HOOKS						   		*/
+		/************************************************************************/
+		static void internal_getMemorySize(UINT32 width, UINT32 height, UINT32 depth, PixelFormat format, UINT32* value);
+		static void internal_hasAlpha(PixelFormat format, bool* value);
+		static void internal_isFloatingPoint(PixelFormat format, bool* value);
+		static void internal_isCompressed(PixelFormat format, bool* value);
+		static void internal_isDepth(PixelFormat format, bool* value);
+		static void internal_getMaxMipmaps(UINT32 width, UINT32 height, UINT32 depth, PixelFormat format, UINT32* value);
+		static MonoObject* internal_convertFormat(MonoObject* source, PixelFormat newFormat);
+		static MonoObject* internal_compress(MonoObject* source, CompressionOptions* options);
+		static MonoArray* internal_generateMipmaps(MonoObject* source, MipMapGenOptions* options);
+		static MonoObject* internal_scale(MonoObject* source, PixelVolume* newSize, PixelUtil::Filter filter);
+		static void internal_applyGamma(MonoObject* source, float gamma);
+	};
 }

+ 13 - 13
SBansheeEngine/Include/BsScriptSceneObject.h

@@ -83,22 +83,22 @@ namespace BansheeEngine
 		static void internal_getScale(ScriptSceneObject* nativeInstance, Vector3* value);
 		static void internal_getLocalScale(ScriptSceneObject* nativeInstance, Vector3* value);
 
-		static void internal_setPosition(ScriptSceneObject* nativeInstance, Vector3 value);
-		static void internal_setLocalPosition(ScriptSceneObject* nativeInstance, Vector3 value);
-		static void internal_setRotation(ScriptSceneObject* nativeInstance, Quaternion value);
-		static void internal_setLocalRotation(ScriptSceneObject* nativeInstance, Quaternion value);
-		static void internal_setLocalScale(ScriptSceneObject* nativeInstance, Vector3 value);
+		static void internal_setPosition(ScriptSceneObject* nativeInstance, Vector3* value);
+		static void internal_setLocalPosition(ScriptSceneObject* nativeInstance, Vector3* value);
+		static void internal_setRotation(ScriptSceneObject* nativeInstance, Quaternion* value);
+		static void internal_setLocalRotation(ScriptSceneObject* nativeInstance, Quaternion* value);
+		static void internal_setLocalScale(ScriptSceneObject* nativeInstance, Vector3* value);
 
 		static void internal_getLocalTransform(ScriptSceneObject* nativeInstance, Matrix4* value);
 		static void internal_getWorldTransform(ScriptSceneObject* nativeInstance, Matrix4* value);
-		static void internal_lookAt(ScriptSceneObject* nativeInstance, Vector3 direction, Vector3 up);
-		static void internal_move(ScriptSceneObject* nativeInstance, Vector3 value);
-		static void internal_moveLocal(ScriptSceneObject* nativeInstance, Vector3 value);
-		static void internal_rotate(ScriptSceneObject* nativeInstance, Quaternion value);
-		static void internal_roll(ScriptSceneObject* nativeInstance, Radian value);
-		static void internal_yaw(ScriptSceneObject* nativeInstance, Radian value);
-		static void internal_pitch(ScriptSceneObject* nativeInstance, Radian value);
-		static void internal_setForward(ScriptSceneObject* nativeInstance, Vector3 value);
+		static void internal_lookAt(ScriptSceneObject* nativeInstance, Vector3* direction, Vector3* up);
+		static void internal_move(ScriptSceneObject* nativeInstance, Vector3* value);
+		static void internal_moveLocal(ScriptSceneObject* nativeInstance, Vector3* value);
+		static void internal_rotate(ScriptSceneObject* nativeInstance, Quaternion* value);
+		static void internal_roll(ScriptSceneObject* nativeInstance, Radian* value);
+		static void internal_yaw(ScriptSceneObject* nativeInstance, Radian* value);
+		static void internal_pitch(ScriptSceneObject* nativeInstance, Radian* value);
+		static void internal_setForward(ScriptSceneObject* nativeInstance, Vector3* value);
 		static void internal_getForward(ScriptSceneObject* nativeInstance, Vector3* value);
 		static void internal_getUp(ScriptSceneObject* nativeInstance, Vector3* value);
 		static void internal_getRight(ScriptSceneObject* nativeInstance, Vector3* value);

+ 3 - 3
SBansheeEngine/Include/BsScriptSpriteTexture.h

@@ -32,13 +32,13 @@ namespace BansheeEngine
 		/************************************************************************/
 		/* 								CLR HOOKS						   		*/
 		/************************************************************************/
-		static void internal_createInstance(MonoObject* instance, MonoObject* texture, Vector2 offset, Vector2 scale);
+		static void internal_createInstance(MonoObject* instance, MonoObject* texture, Vector2* offset, Vector2* scale);
 		static MonoObject* internal_GetTexture(ScriptSpriteTexture* thisPtr);
 		static void internal_SetTexture(ScriptSpriteTexture* thisPtr, ScriptTexture2D* value);
 		static void internal_GetOffset(ScriptSpriteTexture* thisPtr, Vector2* value);
-		static void internal_SetOffset(ScriptSpriteTexture* thisPtr, Vector2 value);
+		static void internal_SetOffset(ScriptSpriteTexture* thisPtr, Vector2* value);
 		static void internal_GetScale(ScriptSpriteTexture* thisPtr, Vector2* value);
-		static void internal_SetScale(ScriptSpriteTexture* thisPtr, Vector2 value);
+		static void internal_SetScale(ScriptSpriteTexture* thisPtr, Vector2* value);
 		static UINT32 internal_GetWidth(ScriptSpriteTexture* thisPtr);
 		static UINT32 internal_GetHeight(ScriptSpriteTexture* thisPtr);
 	};

+ 73 - 73
SBansheeEngine/Include/BsScriptVirtualInput.h

@@ -1,74 +1,74 @@
-#pragma once
-
-#include "BsScriptEnginePrerequisites.h"
-#include "BsScriptObject.h"
-#include "BsInputConfiguration.h"
-
-namespace BansheeEngine
-{
-	/**
-	 * @brief	Interop class between C++ & CLR for VirtualInput.
-	 */
-	class BS_SCR_BE_EXPORT ScriptVirtualInput : public ScriptObject<ScriptVirtualInput>
-	{
-	public:
-		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "VirtualInput")
-
-		/**
-		 * @brief	Must be called on library load. Hooks up necessary callbacks.
-		 */
-		static void startUp();
-
-		/**
-		 * @brief	Must be called before library shutdown. Releases previously hooked callbacks.
-		 */
-		static void shutDown();
-	private:
-		/**
-		 * @brief	Triggered whenever a virtual button is pressed.
-		 *
-		 * @param	btn			Virtual button that was pressed.
-		 * @param	deviceIdx	Index of the device the button was pressed on.
-		 */
-		static void onButtonDown(const VirtualButton& btn, UINT32 deviceIdx);
-
-		/**
-		 * @brief	Triggered whenever a virtual button is released.
-		 *
-		 * @param	btn			Virtual button that was released.
-		 * @param	deviceIdx	Index of the device the button was released on.
-		 */
-		static void onButtonUp(const VirtualButton& btn, UINT32 deviceIdx);
-
-		/**
-		 * @brief	Triggered every frame while a virtual button is held down.
-		 *
-		 * @param	btn			Virtual button that is being held.
-		 * @param	deviceIdx	Index of the device the button is held.
-		 */
-		static void onButtonHeld(const VirtualButton& btn, UINT32 deviceIdx);
-
-		static HEvent OnButtonPressedConn;
-		static HEvent OnButtonReleasedConn;
-		static HEvent OnButtonHeldConn;
-
-		ScriptVirtualInput(MonoObject* instance);
-
-		/************************************************************************/
-		/* 								CLR HOOKS						   		*/
-		/************************************************************************/
-
-		static MonoObject* internal_getKeyConfig();
-		static void internal_setKeyConfig(MonoObject* keyConfig);
-		static bool internal_isButtonHeld(VirtualButton btn, UINT32 deviceIdx);
-		static bool internal_isButtonDown(VirtualButton btn, UINT32 deviceIdx);
-		static bool internal_isButtonUp(VirtualButton btn, UINT32 deviceIdx);
-		static float internal_getAxisValue(VirtualAxis axis, UINT32 deviceIdx);
-
-		typedef void(__stdcall *OnButtonEventThunkDef) (MonoObject*, UINT32, MonoException**);
-
-		static OnButtonEventThunkDef OnButtonUpThunk;
-		static OnButtonEventThunkDef OnButtonDownThunk;
-		static OnButtonEventThunkDef OnButtonHeldThunk;
-	};
+#pragma once
+
+#include "BsScriptEnginePrerequisites.h"
+#include "BsScriptObject.h"
+#include "BsInputConfiguration.h"
+
+namespace BansheeEngine
+{
+	/**
+	 * @brief	Interop class between C++ & CLR for VirtualInput.
+	 */
+	class BS_SCR_BE_EXPORT ScriptVirtualInput : public ScriptObject<ScriptVirtualInput>
+	{
+	public:
+		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "VirtualInput")
+
+		/**
+		 * @brief	Must be called on library load. Hooks up necessary callbacks.
+		 */
+		static void startUp();
+
+		/**
+		 * @brief	Must be called before library shutdown. Releases previously hooked callbacks.
+		 */
+		static void shutDown();
+	private:
+		/**
+		 * @brief	Triggered whenever a virtual button is pressed.
+		 *
+		 * @param	btn			Virtual button that was pressed.
+		 * @param	deviceIdx	Index of the device the button was pressed on.
+		 */
+		static void onButtonDown(const VirtualButton& btn, UINT32 deviceIdx);
+
+		/**
+		 * @brief	Triggered whenever a virtual button is released.
+		 *
+		 * @param	btn			Virtual button that was released.
+		 * @param	deviceIdx	Index of the device the button was released on.
+		 */
+		static void onButtonUp(const VirtualButton& btn, UINT32 deviceIdx);
+
+		/**
+		 * @brief	Triggered every frame while a virtual button is held down.
+		 *
+		 * @param	btn			Virtual button that is being held.
+		 * @param	deviceIdx	Index of the device the button is held.
+		 */
+		static void onButtonHeld(const VirtualButton& btn, UINT32 deviceIdx);
+
+		static HEvent OnButtonPressedConn;
+		static HEvent OnButtonReleasedConn;
+		static HEvent OnButtonHeldConn;
+
+		ScriptVirtualInput(MonoObject* instance);
+
+		/************************************************************************/
+		/* 								CLR HOOKS						   		*/
+		/************************************************************************/
+
+		static MonoObject* internal_getKeyConfig();
+		static void internal_setKeyConfig(MonoObject* keyConfig);
+		static bool internal_isButtonHeld(VirtualButton* btn, UINT32 deviceIdx);
+		static bool internal_isButtonDown(VirtualButton* btn, UINT32 deviceIdx);
+		static bool internal_isButtonUp(VirtualButton* btn, UINT32 deviceIdx);
+		static float internal_getAxisValue(VirtualAxis* axis, UINT32 deviceIdx);
+
+		typedef void(__stdcall *OnButtonEventThunkDef) (MonoObject*, UINT32, MonoException**);
+
+		static OnButtonEventThunkDef OnButtonUpThunk;
+		static OnButtonEventThunkDef OnButtonDownThunk;
+		static OnButtonEventThunkDef OnButtonHeldThunk;
+	};
 }

+ 436 - 436
SBansheeEngine/Source/BsScriptCamera.cpp

@@ -1,437 +1,437 @@
-#include "BsScriptCamera.h"
-#include "BsScriptMeta.h"
-#include "BsMonoField.h"
-#include "BsMonoClass.h"
-#include "BsMonoManager.h"
-#include "BsMonoUtil.h"
-#include "BsApplication.h"
-#include "BsCamera.h"
-#include "BsScriptSceneObject.h"
-#include "BsSceneObject.h"
-#include "BsScriptRenderTarget.h"
-#include "BsSceneManager.h"
-
-namespace BansheeEngine
-{
-	ScriptCamera::ScriptCamera(MonoObject* managedInstance, const HSceneObject& parentSO)
-		:ScriptObject(managedInstance), mCamera(nullptr), mLastUpdateHash(0)
-	{ 
-		mCamera = Camera::create(nullptr);
-		gSceneManager()._registerCamera(mCamera, parentSO);
-	}
-
-	ScriptCamera::~ScriptCamera()
-	{
-
-	}
-
-	void ScriptCamera::initRuntimeData()
-	{
-		metaData.scriptClass->addInternalCall("Internal_Create", &ScriptCamera::internal_Create);
-
-		metaData.scriptClass->addInternalCall("Internal_GetAspect", &ScriptCamera::internal_GetAspect);
-		metaData.scriptClass->addInternalCall("Internal_SetAspect", &ScriptCamera::internal_SetAspect);
-		metaData.scriptClass->addInternalCall("Internal_GetNearClip", &ScriptCamera::internal_GetNearClip);
-		metaData.scriptClass->addInternalCall("Internal_SetNearClip", &ScriptCamera::internal_SetNearClip);
-
-		metaData.scriptClass->addInternalCall("Internal_GetFarClip", &ScriptCamera::internal_GetFarClip);
-		metaData.scriptClass->addInternalCall("Internal_SetFarClip", &ScriptCamera::internal_SetFarClip);
-
-		metaData.scriptClass->addInternalCall("Internal_GetFieldOfView", &ScriptCamera::internal_GetFieldOfView);
-		metaData.scriptClass->addInternalCall("Internal_SetFieldOfView", &ScriptCamera::internal_SetFieldOfView);
-
-		metaData.scriptClass->addInternalCall("Internal_GetViewportRect", &ScriptCamera::internal_GetViewportRect);
-		metaData.scriptClass->addInternalCall("Internal_SetViewportRect", &ScriptCamera::internal_SetViewportRect);
-
-		metaData.scriptClass->addInternalCall("Internal_GetProjectionType", &ScriptCamera::internal_GetProjectionType);
-		metaData.scriptClass->addInternalCall("Internal_SetProjectionType", &ScriptCamera::internal_SetProjectionType);
-
-		metaData.scriptClass->addInternalCall("Internal_GetOrthographicHeight", &ScriptCamera::internal_GetOrthographicHeight);
-		metaData.scriptClass->addInternalCall("Internal_SetOrthographicHeight", &ScriptCamera::internal_SetOrthographicHeight);
-
-		metaData.scriptClass->addInternalCall("Internal_GetOrthographicWidth", &ScriptCamera::internal_GetOrthographicWidth);
-
-		metaData.scriptClass->addInternalCall("Internal_GetClearColor", &ScriptCamera::internal_GetClearColor);
-		metaData.scriptClass->addInternalCall("Internal_SetClearColor", &ScriptCamera::internal_SetClearColor);
-
-		metaData.scriptClass->addInternalCall("Internal_GetDepthClearValue", &ScriptCamera::internal_GetDepthClearValue);
-		metaData.scriptClass->addInternalCall("Internal_SetDepthClearValue", &ScriptCamera::internal_SetDepthClearValue);
-
-		metaData.scriptClass->addInternalCall("Internal_GetStencilClearValue", &ScriptCamera::internal_GetStencilClearValue);
-		metaData.scriptClass->addInternalCall("Internal_SetStencilClearValue", &ScriptCamera::internal_SetStencilClearValue);
-
-		metaData.scriptClass->addInternalCall("Internal_GetClearFlags", &ScriptCamera::internal_GetClearFlags);
-		metaData.scriptClass->addInternalCall("Internal_SetClearFlags", &ScriptCamera::internal_SetClearFlags);
-
-		metaData.scriptClass->addInternalCall("Internal_GetPriority", &ScriptCamera::internal_GetPriority);
-		metaData.scriptClass->addInternalCall("Internal_SetPriority", &ScriptCamera::internal_SetPriority);
-
-		metaData.scriptClass->addInternalCall("Internal_GetLayers", &ScriptCamera::internal_GetLayers);
-		metaData.scriptClass->addInternalCall("Internal_SetLayers", &ScriptCamera::internal_SetLayers);
-
-		metaData.scriptClass->addInternalCall("Internal_GetProjMatrix", &ScriptCamera::internal_GetProjMatrix);
-		metaData.scriptClass->addInternalCall("Internal_GetProjMatrixInv", &ScriptCamera::internal_GetProjMatrixInv);
-
-		metaData.scriptClass->addInternalCall("Internal_GetViewMatrix", &ScriptCamera::internal_GetViewMatrix);
-		metaData.scriptClass->addInternalCall("Internal_GetViewMatrixInv", &ScriptCamera::internal_GetViewMatrixInv);
-
-		metaData.scriptClass->addInternalCall("Internal_GetWidthPixels", &ScriptCamera::internal_GetWidthPixels);
-		metaData.scriptClass->addInternalCall("Internal_GetHeightPixels", &ScriptCamera::internal_GetHeightPixels);
-
-		metaData.scriptClass->addInternalCall("Internal_WorldToScreen", &ScriptCamera::internal_WorldToScreen);
-		metaData.scriptClass->addInternalCall("Internal_WorldToClip", &ScriptCamera::internal_WorldToClip);
-		metaData.scriptClass->addInternalCall("Internal_WorldToView", &ScriptCamera::internal_WorldToView);
-
-		metaData.scriptClass->addInternalCall("Internal_ScreenToWorld", &ScriptCamera::internal_ScreenToWorld);
-		metaData.scriptClass->addInternalCall("Internal_ScreenToView", &ScriptCamera::internal_ScreenToView);
-		metaData.scriptClass->addInternalCall("Internal_ScreenToClip", &ScriptCamera::internal_ScreenToClip);
-
-		metaData.scriptClass->addInternalCall("Internal_ViewToWorld", &ScriptCamera::internal_ViewToWorld);
-		metaData.scriptClass->addInternalCall("Internal_ViewToScreen", &ScriptCamera::internal_ViewToScreen);
-		metaData.scriptClass->addInternalCall("Internal_ViewToClip", &ScriptCamera::internal_ViewToClip);
-
-		metaData.scriptClass->addInternalCall("Internal_ClipToWorld", &ScriptCamera::internal_ClipToWorld);
-		metaData.scriptClass->addInternalCall("Internal_ClipToView", &ScriptCamera::internal_ClipToView);
-		metaData.scriptClass->addInternalCall("Internal_ClipToScreen", &ScriptCamera::internal_ClipToScreen);
-
-		metaData.scriptClass->addInternalCall("Internal_ScreenToWorldRay", &ScriptCamera::internal_ScreenToWorldRay);
-		metaData.scriptClass->addInternalCall("Internal_ProjectPoint", &ScriptCamera::internal_ProjectPoint);
-		metaData.scriptClass->addInternalCall("Internal_UnprojectPoint", &ScriptCamera::internal_UnprojectPoint);
-
-		metaData.scriptClass->addInternalCall("Internal_SetRenderTarget", &ScriptCamera::internal_SetRenderTarget);
-
-		metaData.scriptClass->addInternalCall("Internal_GetMain", &ScriptCamera::internal_GetMain);
-		metaData.scriptClass->addInternalCall("Internal_SetMain", &ScriptCamera::internal_SetMain);
-
-		metaData.scriptClass->addInternalCall("Internal_UpdateView", &ScriptCamera::internal_UpdateView);
-		metaData.scriptClass->addInternalCall("Internal_OnDestroy", &ScriptCamera::internal_OnDestroy);
-	}
-
-	void ScriptCamera::updateView(const HSceneObject& parent)
-	{
-		if (parent.isDestroyed())
-			return;
-
-		UINT32 curHash = parent->getTransformHash();
-		if (curHash != mLastUpdateHash)
-		{
-			mCamera->setPosition(parent->getWorldPosition());
-			mCamera->setRotation(parent->getWorldRotation());
-
-			mLastUpdateHash = curHash;
-		}
-	}
-
-	void ScriptCamera::internal_Create(MonoObject* managedInstance, ScriptSceneObject* parentSO)
-	{
-		HSceneObject so;
-		if (parentSO != nullptr)
-			so = parentSO->getNativeHandle();
-
-		ScriptCamera* nativeInstance = new (bs_alloc<ScriptCamera>()) ScriptCamera(managedInstance, so);
-	}
-
-	float ScriptCamera::internal_GetAspect(ScriptCamera* instance)
-	{
-		return instance->mCamera->getAspectRatio();
-	}
-
-	void ScriptCamera::internal_SetAspect(ScriptCamera* instance, float value)
-	{
-		instance->mCamera->setAspectRatio(value);
-	}
-
-	float ScriptCamera::internal_GetNearClip(ScriptCamera* instance)
-	{
-		return instance->mCamera->getNearClipDistance();
-	}
-
-	void ScriptCamera::internal_SetNearClip(ScriptCamera* instance, float value)
-	{
-		instance->mCamera->setNearClipDistance(value);
-	}
-
-	float ScriptCamera::internal_GetFarClip(ScriptCamera* instance)
-	{
-		return instance->mCamera->getFarClipDistance();
-	}
-
-	void ScriptCamera::internal_SetFarClip(ScriptCamera* instance, float value)
-	{
-		instance->mCamera->setFarClipDistance(value);
-	}
-
-	void ScriptCamera::internal_GetFieldOfView(ScriptCamera* instance, Degree* value)
-	{
-		*value = instance->mCamera->getHorzFOV();
-	}
-
-	void ScriptCamera::internal_SetFieldOfView(ScriptCamera* instance, Degree value)
-	{
-		instance->mCamera->setHorzFOV(value);
-	}
-
-	Rect2 ScriptCamera::internal_GetViewportRect(ScriptCamera* instance)
-	{
-		return instance->mCamera->getViewport()->getNormArea();
-	}
-
-	void ScriptCamera::internal_SetViewportRect(ScriptCamera* instance, Rect2 value)
-	{
-		instance->mCamera->getViewport()->setArea(value.x, value.y, value.width, value.height);
-	}
-
-	UINT32 ScriptCamera::internal_GetProjectionType(ScriptCamera* instance)
-	{
-		return instance->mCamera->getProjectionType();
-	}
-
-	void ScriptCamera::internal_SetProjectionType(ScriptCamera* instance, UINT32 value)
-	{
-		instance->mCamera->setProjectionType((ProjectionType)value);
-	}
-
-	float ScriptCamera::internal_GetOrthographicHeight(ScriptCamera* instance)
-	{
-		return instance->mCamera->getOrthoWindowHeight();
-	}
-
-	void ScriptCamera::internal_SetOrthographicHeight(ScriptCamera* instance, float value)
-	{
-		instance->mCamera->setOrthoWindowHeight(value);
-	}
-
-	float ScriptCamera::internal_GetOrthographicWidth(ScriptCamera* instance)
-	{
-		return instance->mCamera->getOrthoWindowWidth();
-	}
-
-	Color ScriptCamera::internal_GetClearColor(ScriptCamera* instance)
-	{
-		return instance->mCamera->getViewport()->getClearColor();
-	}
-
-	void ScriptCamera::internal_SetClearColor(ScriptCamera* instance, Color value)
-	{
-		ViewportPtr vp = instance->mCamera->getViewport();
-		vp->setClearValues(value, vp->getClearDepthValue(), vp->getClearStencilValue());
-	}
-
-	float ScriptCamera::internal_GetDepthClearValue(ScriptCamera* instance)
-	{
-		return instance->mCamera->getViewport()->getClearDepthValue();
-	}
-
-	void ScriptCamera::internal_SetDepthClearValue(ScriptCamera* instance, float value)
-	{
-		ViewportPtr vp = instance->mCamera->getViewport();
-		vp->setClearValues(vp->getClearColor(), value, vp->getClearStencilValue());
-	}
-
-	UINT16 ScriptCamera::internal_GetStencilClearValue(ScriptCamera* instance)
-	{
-		return instance->mCamera->getViewport()->getClearStencilValue();
-	}
-
-	void ScriptCamera::internal_SetStencilClearValue(ScriptCamera* instance, UINT16 value)
-	{
-		ViewportPtr vp = instance->mCamera->getViewport();
-		vp->setClearValues(vp->getClearColor(), vp->getClearDepthValue(), value);
-	}
-
-	UINT32 ScriptCamera::internal_GetClearFlags(ScriptCamera* instance)
-	{
-		ViewportPtr vp = instance->mCamera->getViewport();
-		UINT32 clearFlags = 0;
-
-		clearFlags |= vp->getRequiresColorClear() ? 0x01 : 0;
-		clearFlags |= vp->getRequiresDepthClear() ? 0x02 : 0;
-		clearFlags |= vp->getRequiresStencilClear() ? 0x04 : 0;
-
-		return clearFlags;
-	}
-
-	void ScriptCamera::internal_SetClearFlags(ScriptCamera* instance, UINT32 value)
-	{
-		ViewportPtr vp = instance->mCamera->getViewport();
-
-		vp->setRequiresClear((value & 0x01) != 0,
-			(value & 0x02) != 0, (value & 0x04) != 0);
-	}
-
-	int ScriptCamera::internal_GetPriority(ScriptCamera* instance)
-	{
-		return instance->mCamera->getPriority();
-	}
-
-	void ScriptCamera::internal_SetPriority(ScriptCamera* instance, int value)
-	{
-		instance->mCamera->setPriority(value);
-	}
-
-	UINT64 ScriptCamera::internal_GetLayers(ScriptCamera* instance)
-	{
-		return instance->mCamera->getLayers();
-	}
-
-	void ScriptCamera::internal_SetLayers(ScriptCamera* instance, UINT64 value)
-	{
-		instance->mCamera->setLayers(value);
-	}
-
-	Matrix4 ScriptCamera::internal_GetProjMatrix(ScriptCamera* instance)
-	{
-		return instance->mCamera->getProjectionMatrixRS();
-	}
-
-	Matrix4 ScriptCamera::internal_GetProjMatrixInv(ScriptCamera* instance)
-	{
-		return instance->mCamera->getProjectionMatrixRSInv();
-	}
-
-	Matrix4 ScriptCamera::internal_GetViewMatrix(ScriptCamera* instance)
-	{
-		return instance->mCamera->getViewMatrix();
-	}
-
-	Matrix4 ScriptCamera::internal_GetViewMatrixInv(ScriptCamera* instance)
-	{
-		return instance->mCamera->getViewMatrixInv();
-	}
-
-	int ScriptCamera::internal_GetWidthPixels(ScriptCamera* instance)
-	{
-		ViewportPtr vp = instance->mCamera->getViewport();
-
-		return vp->getWidth();
-	}
-
-	int ScriptCamera::internal_GetHeightPixels(ScriptCamera* instance)
-	{
-		ViewportPtr vp = instance->mCamera->getViewport();
-
-		return vp->getHeight();
-	}
-
-	Vector2I ScriptCamera::internal_WorldToScreen(ScriptCamera* instance, Vector3 value)
-	{
-		return instance->mCamera->worldToScreenPoint(value);
-	}
-
-	Vector2 ScriptCamera::internal_WorldToClip(ScriptCamera* instance, Vector3 value)
-	{
-		return instance->mCamera->worldToClipPoint(value);
-	}
-
-	Vector3 ScriptCamera::internal_WorldToView(ScriptCamera* instance, Vector3 value)
-	{
-		return instance->mCamera->worldToViewPoint(value);
-	}
-
-	Vector3 ScriptCamera::internal_ScreenToWorld(ScriptCamera* instance, Vector2I value, float depth)
-	{
-		return instance->mCamera->screenToWorldPoint(value, depth);
-	}
-
-	Vector3 ScriptCamera::internal_ScreenToView(ScriptCamera* instance, Vector2I value, float depth)
-	{
-		return instance->mCamera->screenToViewPoint(value, depth);
-	}
-
-	Vector2 ScriptCamera::internal_ScreenToClip(ScriptCamera* instance, Vector2I value)
-	{
-		return instance->mCamera->screenToClipPoint(value);
-	}
-
-	Vector3 ScriptCamera::internal_ViewToWorld(ScriptCamera* instance, Vector3 value)
-	{
-		return instance->mCamera->viewToWorldPoint(value);
-	}
-
-	Vector2I ScriptCamera::internal_ViewToScreen(ScriptCamera* instance, Vector3 value)
-	{
-		return instance->mCamera->viewToScreenPoint(value);
-	}
-
-	Vector2 ScriptCamera::internal_ViewToClip(ScriptCamera* instance, Vector3 value)
-	{
-		return instance->mCamera->viewToClipPoint(value);
-	}
-
-	Vector3 ScriptCamera::internal_ClipToWorld(ScriptCamera* instance, Vector2 value, float depth)
-	{
-		return instance->mCamera->clipToWorldPoint(value, depth);
-	}
-
-	Vector3 ScriptCamera::internal_ClipToView(ScriptCamera* instance, Vector2 value, float depth)
-	{
-		return instance->mCamera->clipToViewPoint(value, depth);
-	}
-
-	Vector2I ScriptCamera::internal_ClipToScreen(ScriptCamera* instance, Vector2 value)
-	{
-		return instance->mCamera->clipToScreenPoint(value);
-	}
-
-	Ray ScriptCamera::internal_ScreenToWorldRay(ScriptCamera* instance, Vector2I value)
-	{
-		return instance->mCamera->screenPointToRay(value);
-	}
-
-	Vector3 ScriptCamera::internal_ProjectPoint(ScriptCamera* instance, Vector3 value)
-	{
-		return instance->mCamera->projectPoint(value);
-	}
-
-	Vector3 ScriptCamera::internal_UnprojectPoint(ScriptCamera* instance, Vector3 value)
-	{
-		return instance->mCamera->unprojectPoint(value);
-	}
-
-	void ScriptCamera::internal_SetRenderTarget(ScriptCamera* instance, ScriptRenderTarget* target)
-	{
-		if (target == nullptr)
-			instance->mCamera->getViewport()->setTarget(nullptr);
-		else
-			instance->mCamera->getViewport()->setTarget(target->getNativeValue());
-	}
-
-	bool ScriptCamera::internal_GetMain(ScriptCamera* instance)
-	{
-		return instance->mCamera->isMain();
-	}
-
-	void ScriptCamera::internal_SetMain(ScriptCamera* instance, bool main)
-	{
-		instance->mCamera->setMain(main);
-		gSceneManager()._notifyMainCameraStateChanged(instance->mCamera);
-	}
-
-	void ScriptCamera::internal_UpdateView(ScriptCamera* instance, ScriptSceneObject* parent)
-	{
-		HSceneObject parentSO = parent->getNativeSceneObject();
-
-		instance->updateView(parentSO);
-	}
-
-	void ScriptCamera::internal_OnDestroy(ScriptCamera* instance)
-	{
-		instance->destroy();
-	}
-
-	void ScriptCamera::destroy()
-	{
-		if (mCamera->isDestroyed())
-			return;
-
-		gSceneManager()._unregisterCamera(mCamera);
-		mCamera->destroy();
-	}
-
-	void ScriptCamera::_onManagedInstanceDeleted()
-	{
-		destroy();
-
-		ScriptObject::_onManagedInstanceDeleted();
-	}
+#include "BsScriptCamera.h"
+#include "BsScriptMeta.h"
+#include "BsMonoField.h"
+#include "BsMonoClass.h"
+#include "BsMonoManager.h"
+#include "BsMonoUtil.h"
+#include "BsApplication.h"
+#include "BsCamera.h"
+#include "BsScriptSceneObject.h"
+#include "BsSceneObject.h"
+#include "BsScriptRenderTarget.h"
+#include "BsSceneManager.h"
+
+namespace BansheeEngine
+{
+	ScriptCamera::ScriptCamera(MonoObject* managedInstance, const HSceneObject& parentSO)
+		:ScriptObject(managedInstance), mCamera(nullptr), mLastUpdateHash(0)
+	{ 
+		mCamera = Camera::create(nullptr);
+		gSceneManager()._registerCamera(mCamera, parentSO);
+	}
+
+	ScriptCamera::~ScriptCamera()
+	{
+
+	}
+
+	void ScriptCamera::initRuntimeData()
+	{
+		metaData.scriptClass->addInternalCall("Internal_Create", &ScriptCamera::internal_Create);
+
+		metaData.scriptClass->addInternalCall("Internal_GetAspect", &ScriptCamera::internal_GetAspect);
+		metaData.scriptClass->addInternalCall("Internal_SetAspect", &ScriptCamera::internal_SetAspect);
+		metaData.scriptClass->addInternalCall("Internal_GetNearClip", &ScriptCamera::internal_GetNearClip);
+		metaData.scriptClass->addInternalCall("Internal_SetNearClip", &ScriptCamera::internal_SetNearClip);
+
+		metaData.scriptClass->addInternalCall("Internal_GetFarClip", &ScriptCamera::internal_GetFarClip);
+		metaData.scriptClass->addInternalCall("Internal_SetFarClip", &ScriptCamera::internal_SetFarClip);
+
+		metaData.scriptClass->addInternalCall("Internal_GetFieldOfView", &ScriptCamera::internal_GetFieldOfView);
+		metaData.scriptClass->addInternalCall("Internal_SetFieldOfView", &ScriptCamera::internal_SetFieldOfView);
+
+		metaData.scriptClass->addInternalCall("Internal_GetViewportRect", &ScriptCamera::internal_GetViewportRect);
+		metaData.scriptClass->addInternalCall("Internal_SetViewportRect", &ScriptCamera::internal_SetViewportRect);
+
+		metaData.scriptClass->addInternalCall("Internal_GetProjectionType", &ScriptCamera::internal_GetProjectionType);
+		metaData.scriptClass->addInternalCall("Internal_SetProjectionType", &ScriptCamera::internal_SetProjectionType);
+
+		metaData.scriptClass->addInternalCall("Internal_GetOrthographicHeight", &ScriptCamera::internal_GetOrthographicHeight);
+		metaData.scriptClass->addInternalCall("Internal_SetOrthographicHeight", &ScriptCamera::internal_SetOrthographicHeight);
+
+		metaData.scriptClass->addInternalCall("Internal_GetOrthographicWidth", &ScriptCamera::internal_GetOrthographicWidth);
+
+		metaData.scriptClass->addInternalCall("Internal_GetClearColor", &ScriptCamera::internal_GetClearColor);
+		metaData.scriptClass->addInternalCall("Internal_SetClearColor", &ScriptCamera::internal_SetClearColor);
+
+		metaData.scriptClass->addInternalCall("Internal_GetDepthClearValue", &ScriptCamera::internal_GetDepthClearValue);
+		metaData.scriptClass->addInternalCall("Internal_SetDepthClearValue", &ScriptCamera::internal_SetDepthClearValue);
+
+		metaData.scriptClass->addInternalCall("Internal_GetStencilClearValue", &ScriptCamera::internal_GetStencilClearValue);
+		metaData.scriptClass->addInternalCall("Internal_SetStencilClearValue", &ScriptCamera::internal_SetStencilClearValue);
+
+		metaData.scriptClass->addInternalCall("Internal_GetClearFlags", &ScriptCamera::internal_GetClearFlags);
+		metaData.scriptClass->addInternalCall("Internal_SetClearFlags", &ScriptCamera::internal_SetClearFlags);
+
+		metaData.scriptClass->addInternalCall("Internal_GetPriority", &ScriptCamera::internal_GetPriority);
+		metaData.scriptClass->addInternalCall("Internal_SetPriority", &ScriptCamera::internal_SetPriority);
+
+		metaData.scriptClass->addInternalCall("Internal_GetLayers", &ScriptCamera::internal_GetLayers);
+		metaData.scriptClass->addInternalCall("Internal_SetLayers", &ScriptCamera::internal_SetLayers);
+
+		metaData.scriptClass->addInternalCall("Internal_GetProjMatrix", &ScriptCamera::internal_GetProjMatrix);
+		metaData.scriptClass->addInternalCall("Internal_GetProjMatrixInv", &ScriptCamera::internal_GetProjMatrixInv);
+
+		metaData.scriptClass->addInternalCall("Internal_GetViewMatrix", &ScriptCamera::internal_GetViewMatrix);
+		metaData.scriptClass->addInternalCall("Internal_GetViewMatrixInv", &ScriptCamera::internal_GetViewMatrixInv);
+
+		metaData.scriptClass->addInternalCall("Internal_GetWidthPixels", &ScriptCamera::internal_GetWidthPixels);
+		metaData.scriptClass->addInternalCall("Internal_GetHeightPixels", &ScriptCamera::internal_GetHeightPixels);
+
+		metaData.scriptClass->addInternalCall("Internal_WorldToScreen", &ScriptCamera::internal_WorldToScreen);
+		metaData.scriptClass->addInternalCall("Internal_WorldToClip", &ScriptCamera::internal_WorldToClip);
+		metaData.scriptClass->addInternalCall("Internal_WorldToView", &ScriptCamera::internal_WorldToView);
+
+		metaData.scriptClass->addInternalCall("Internal_ScreenToWorld", &ScriptCamera::internal_ScreenToWorld);
+		metaData.scriptClass->addInternalCall("Internal_ScreenToView", &ScriptCamera::internal_ScreenToView);
+		metaData.scriptClass->addInternalCall("Internal_ScreenToClip", &ScriptCamera::internal_ScreenToClip);
+
+		metaData.scriptClass->addInternalCall("Internal_ViewToWorld", &ScriptCamera::internal_ViewToWorld);
+		metaData.scriptClass->addInternalCall("Internal_ViewToScreen", &ScriptCamera::internal_ViewToScreen);
+		metaData.scriptClass->addInternalCall("Internal_ViewToClip", &ScriptCamera::internal_ViewToClip);
+
+		metaData.scriptClass->addInternalCall("Internal_ClipToWorld", &ScriptCamera::internal_ClipToWorld);
+		metaData.scriptClass->addInternalCall("Internal_ClipToView", &ScriptCamera::internal_ClipToView);
+		metaData.scriptClass->addInternalCall("Internal_ClipToScreen", &ScriptCamera::internal_ClipToScreen);
+
+		metaData.scriptClass->addInternalCall("Internal_ScreenToWorldRay", &ScriptCamera::internal_ScreenToWorldRay);
+		metaData.scriptClass->addInternalCall("Internal_ProjectPoint", &ScriptCamera::internal_ProjectPoint);
+		metaData.scriptClass->addInternalCall("Internal_UnprojectPoint", &ScriptCamera::internal_UnprojectPoint);
+
+		metaData.scriptClass->addInternalCall("Internal_SetRenderTarget", &ScriptCamera::internal_SetRenderTarget);
+
+		metaData.scriptClass->addInternalCall("Internal_GetMain", &ScriptCamera::internal_GetMain);
+		metaData.scriptClass->addInternalCall("Internal_SetMain", &ScriptCamera::internal_SetMain);
+
+		metaData.scriptClass->addInternalCall("Internal_UpdateView", &ScriptCamera::internal_UpdateView);
+		metaData.scriptClass->addInternalCall("Internal_OnDestroy", &ScriptCamera::internal_OnDestroy);
+	}
+
+	void ScriptCamera::updateView(const HSceneObject& parent)
+	{
+		if (parent.isDestroyed())
+			return;
+
+		UINT32 curHash = parent->getTransformHash();
+		if (curHash != mLastUpdateHash)
+		{
+			mCamera->setPosition(parent->getWorldPosition());
+			mCamera->setRotation(parent->getWorldRotation());
+
+			mLastUpdateHash = curHash;
+		}
+	}
+
+	void ScriptCamera::internal_Create(MonoObject* managedInstance, ScriptSceneObject* parentSO)
+	{
+		HSceneObject so;
+		if (parentSO != nullptr)
+			so = parentSO->getNativeHandle();
+
+		ScriptCamera* nativeInstance = new (bs_alloc<ScriptCamera>()) ScriptCamera(managedInstance, so);
+	}
+
+	float ScriptCamera::internal_GetAspect(ScriptCamera* instance)
+	{
+		return instance->mCamera->getAspectRatio();
+	}
+
+	void ScriptCamera::internal_SetAspect(ScriptCamera* instance, float value)
+	{
+		instance->mCamera->setAspectRatio(value);
+	}
+
+	float ScriptCamera::internal_GetNearClip(ScriptCamera* instance)
+	{
+		return instance->mCamera->getNearClipDistance();
+	}
+
+	void ScriptCamera::internal_SetNearClip(ScriptCamera* instance, float value)
+	{
+		instance->mCamera->setNearClipDistance(value);
+	}
+
+	float ScriptCamera::internal_GetFarClip(ScriptCamera* instance)
+	{
+		return instance->mCamera->getFarClipDistance();
+	}
+
+	void ScriptCamera::internal_SetFarClip(ScriptCamera* instance, float value)
+	{
+		instance->mCamera->setFarClipDistance(value);
+	}
+
+	void ScriptCamera::internal_GetFieldOfView(ScriptCamera* instance, Degree* value)
+	{
+		*value = instance->mCamera->getHorzFOV();
+	}
+
+	void ScriptCamera::internal_SetFieldOfView(ScriptCamera* instance, Degree* value)
+	{
+		instance->mCamera->setHorzFOV(*value);
+	}
+
+	void ScriptCamera::internal_GetViewportRect(ScriptCamera* instance, Rect2* value)
+	{
+		*value = instance->mCamera->getViewport()->getNormArea();
+	}
+
+	void ScriptCamera::internal_SetViewportRect(ScriptCamera* instance, Rect2* value)
+	{
+		instance->mCamera->getViewport()->setArea(value->x, value->y, value->width, value->height);
+	}
+
+	UINT32 ScriptCamera::internal_GetProjectionType(ScriptCamera* instance)
+	{
+		return instance->mCamera->getProjectionType();
+	}
+
+	void ScriptCamera::internal_SetProjectionType(ScriptCamera* instance, UINT32 value)
+	{
+		instance->mCamera->setProjectionType((ProjectionType)value);
+	}
+
+	float ScriptCamera::internal_GetOrthographicHeight(ScriptCamera* instance)
+	{
+		return instance->mCamera->getOrthoWindowHeight();
+	}
+
+	void ScriptCamera::internal_SetOrthographicHeight(ScriptCamera* instance, float value)
+	{
+		instance->mCamera->setOrthoWindowHeight(value);
+	}
+
+	float ScriptCamera::internal_GetOrthographicWidth(ScriptCamera* instance)
+	{
+		return instance->mCamera->getOrthoWindowWidth();
+	}
+
+	void ScriptCamera::internal_GetClearColor(ScriptCamera* instance, Color* value)
+	{
+		*value = instance->mCamera->getViewport()->getClearColor();
+	}
+
+	void ScriptCamera::internal_SetClearColor(ScriptCamera* instance, Color* value)
+	{
+		ViewportPtr vp = instance->mCamera->getViewport();
+		vp->setClearValues(*value, vp->getClearDepthValue(), vp->getClearStencilValue());
+	}
+
+	float ScriptCamera::internal_GetDepthClearValue(ScriptCamera* instance)
+	{
+		return instance->mCamera->getViewport()->getClearDepthValue();
+	}
+
+	void ScriptCamera::internal_SetDepthClearValue(ScriptCamera* instance, float value)
+	{
+		ViewportPtr vp = instance->mCamera->getViewport();
+		vp->setClearValues(vp->getClearColor(), value, vp->getClearStencilValue());
+	}
+
+	UINT16 ScriptCamera::internal_GetStencilClearValue(ScriptCamera* instance)
+	{
+		return instance->mCamera->getViewport()->getClearStencilValue();
+	}
+
+	void ScriptCamera::internal_SetStencilClearValue(ScriptCamera* instance, UINT16 value)
+	{
+		ViewportPtr vp = instance->mCamera->getViewport();
+		vp->setClearValues(vp->getClearColor(), vp->getClearDepthValue(), value);
+	}
+
+	UINT32 ScriptCamera::internal_GetClearFlags(ScriptCamera* instance)
+	{
+		ViewportPtr vp = instance->mCamera->getViewport();
+		UINT32 clearFlags = 0;
+
+		clearFlags |= vp->getRequiresColorClear() ? 0x01 : 0;
+		clearFlags |= vp->getRequiresDepthClear() ? 0x02 : 0;
+		clearFlags |= vp->getRequiresStencilClear() ? 0x04 : 0;
+
+		return clearFlags;
+	}
+
+	void ScriptCamera::internal_SetClearFlags(ScriptCamera* instance, UINT32 value)
+	{
+		ViewportPtr vp = instance->mCamera->getViewport();
+
+		vp->setRequiresClear((value & 0x01) != 0,
+			(value & 0x02) != 0, (value & 0x04) != 0);
+	}
+
+	int ScriptCamera::internal_GetPriority(ScriptCamera* instance)
+	{
+		return instance->mCamera->getPriority();
+	}
+
+	void ScriptCamera::internal_SetPriority(ScriptCamera* instance, int value)
+	{
+		instance->mCamera->setPriority(value);
+	}
+
+	UINT64 ScriptCamera::internal_GetLayers(ScriptCamera* instance)
+	{
+		return instance->mCamera->getLayers();
+	}
+
+	void ScriptCamera::internal_SetLayers(ScriptCamera* instance, UINT64 value)
+	{
+		instance->mCamera->setLayers(value);
+	}
+
+	void ScriptCamera::internal_GetProjMatrix(ScriptCamera* instance, Matrix4* output)
+	{
+		*output = instance->mCamera->getProjectionMatrixRS();
+	}
+
+	void ScriptCamera::internal_GetProjMatrixInv(ScriptCamera* instance, Matrix4* output)
+	{
+		*output = instance->mCamera->getProjectionMatrixRSInv();
+	}
+
+	void ScriptCamera::internal_GetViewMatrix(ScriptCamera* instance, Matrix4* output)
+	{
+		*output = instance->mCamera->getViewMatrix();
+	}
+
+	void ScriptCamera::internal_GetViewMatrixInv(ScriptCamera* instance, Matrix4* output)
+	{
+		*output = instance->mCamera->getViewMatrixInv();
+	}
+
+	int ScriptCamera::internal_GetWidthPixels(ScriptCamera* instance)
+	{
+		ViewportPtr vp = instance->mCamera->getViewport();
+
+		return vp->getWidth();
+	}
+
+	int ScriptCamera::internal_GetHeightPixels(ScriptCamera* instance)
+	{
+		ViewportPtr vp = instance->mCamera->getViewport();
+
+		return vp->getHeight();
+	}
+
+	void ScriptCamera::internal_WorldToScreen(ScriptCamera* instance, Vector3* value, Vector2I* output)
+	{
+		*output = instance->mCamera->worldToScreenPoint(*value);
+	}
+
+	void ScriptCamera::internal_WorldToClip(ScriptCamera* instance, Vector3* value, Vector2* output)
+	{
+		*output = instance->mCamera->worldToClipPoint(*value);
+	}
+
+	void ScriptCamera::internal_WorldToView(ScriptCamera* instance, Vector3* value, Vector3* output)
+	{
+		*output = instance->mCamera->worldToViewPoint(*value);
+	}
+
+	void ScriptCamera::internal_ScreenToWorld(ScriptCamera* instance, Vector2I* value, float depth, Vector3* output)
+	{
+		*output = instance->mCamera->screenToWorldPoint(*value, depth);
+	}
+
+	void ScriptCamera::internal_ScreenToView(ScriptCamera* instance, Vector2I* value, float depth, Vector3* output)
+	{
+		*output = instance->mCamera->screenToViewPoint(*value, depth);
+	}
+
+	void ScriptCamera::internal_ScreenToClip(ScriptCamera* instance, Vector2I* value, Vector2* output)
+	{
+		*output = instance->mCamera->screenToClipPoint(*value);
+	}
+
+	void ScriptCamera::internal_ViewToWorld(ScriptCamera* instance, Vector3* value, Vector3* output)
+	{
+		*output = instance->mCamera->viewToWorldPoint(*value);
+	}
+
+	void ScriptCamera::internal_ViewToScreen(ScriptCamera* instance, Vector3* value, Vector2I* output)
+	{
+		*output = instance->mCamera->viewToScreenPoint(*value);
+	}
+
+	void ScriptCamera::internal_ViewToClip(ScriptCamera* instance, Vector3* value, Vector2* output)
+	{
+		*output = instance->mCamera->viewToClipPoint(*value);
+	}
+
+	void ScriptCamera::internal_ClipToWorld(ScriptCamera* instance, Vector2* value, float depth, Vector3* output)
+	{
+		*output = instance->mCamera->clipToWorldPoint(*value, depth);
+	}
+
+	void ScriptCamera::internal_ClipToView(ScriptCamera* instance, Vector2* value, float depth, Vector3* output)
+	{
+		*output = instance->mCamera->clipToViewPoint(*value, depth);
+	}
+
+	void ScriptCamera::internal_ClipToScreen(ScriptCamera* instance, Vector2* value, Vector2I* output)
+	{
+		*output = instance->mCamera->clipToScreenPoint(*value);
+	}
+
+	void ScriptCamera::internal_ScreenToWorldRay(ScriptCamera* instance, Vector2I* value, Ray* output)
+	{
+		*output = instance->mCamera->screenPointToRay(*value);
+	}
+
+	void ScriptCamera::internal_ProjectPoint(ScriptCamera* instance, Vector3* value, Vector3* output)
+	{
+		*output = instance->mCamera->projectPoint(*value);
+	}
+
+	void ScriptCamera::internal_UnprojectPoint(ScriptCamera* instance, Vector3* value, Vector3* output)
+	{
+		*output = instance->mCamera->unprojectPoint(*value);
+	}
+
+	void ScriptCamera::internal_SetRenderTarget(ScriptCamera* instance, ScriptRenderTarget* target)
+	{
+		if (target == nullptr)
+			instance->mCamera->getViewport()->setTarget(nullptr);
+		else
+			instance->mCamera->getViewport()->setTarget(target->getNativeValue());
+	}
+
+	bool ScriptCamera::internal_GetMain(ScriptCamera* instance)
+	{
+		return instance->mCamera->isMain();
+	}
+
+	void ScriptCamera::internal_SetMain(ScriptCamera* instance, bool main)
+	{
+		instance->mCamera->setMain(main);
+		gSceneManager()._notifyMainCameraStateChanged(instance->mCamera);
+	}
+
+	void ScriptCamera::internal_UpdateView(ScriptCamera* instance, ScriptSceneObject* parent)
+	{
+		HSceneObject parentSO = parent->getNativeSceneObject();
+
+		instance->updateView(parentSO);
+	}
+
+	void ScriptCamera::internal_OnDestroy(ScriptCamera* instance)
+	{
+		instance->destroy();
+	}
+
+	void ScriptCamera::destroy()
+	{
+		if (mCamera->isDestroyed())
+			return;
+
+		gSceneManager()._unregisterCamera(mCamera);
+		mCamera->destroy();
+	}
+
+	void ScriptCamera::_onManagedInstanceDeleted()
+	{
+		destroy();
+
+		ScriptObject::_onManagedInstanceDeleted();
+	}
 }

+ 69 - 69
SBansheeEngine/Source/BsScriptContextMenu.cpp

@@ -1,70 +1,70 @@
-#include "BsScriptContextMenu.h"
-#include "BsScriptMeta.h"
-#include "BsMonoField.h"
-#include "BsMonoClass.h"
-#include "BsMonoManager.h"
-#include "BsMonoMethod.h"
-#include "BsMonoUtil.h"
-#include "BsGUIContextMenu.h"
-#include "BsScriptHString.h"
-
-using namespace std::placeholders;
-
-namespace BansheeEngine
-{
-	ScriptContextMenu::OnEntryTriggeredThunkDef ScriptContextMenu::onEntryTriggered;
-
-	ScriptContextMenu::ScriptContextMenu(MonoObject* instance)
-		: ScriptObject(instance)
-	{
-		mContextMenu = bs_shared_ptr_new<GUIContextMenu>();
-	}
-
-	void ScriptContextMenu::initRuntimeData()
-	{
-		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptContextMenu::internal_CreateInstance);
-		metaData.scriptClass->addInternalCall("Internal_AddItem", &ScriptContextMenu::internal_AddItem);
-		metaData.scriptClass->addInternalCall("Internal_AddSeparator", &ScriptContextMenu::internal_AddSeparator);
-		metaData.scriptClass->addInternalCall("Internal_SetLocalizedName", &ScriptContextMenu::internal_SetLocalizedName);
-
-		onEntryTriggered = (OnEntryTriggeredThunkDef)metaData.scriptClass->getMethod("InternalDoOnEntryTriggered", 1)->getThunk();
-	}
-
-	void ScriptContextMenu::internal_CreateInstance(MonoObject* instance)
-	{
-		ScriptContextMenu* nativeInstance = new (bs_alloc<ScriptContextMenu>()) ScriptContextMenu(instance);
-	}
-
-	void ScriptContextMenu::internal_AddItem(ScriptContextMenu* instance, MonoString* path, UINT32 callbackIdx,
-		ShortcutKey shortcut)
-	{
-		WString nativePath = MonoUtil::monoToWString(path);
-
-		GUIContextMenuPtr contextMenu = instance->getInternal();
-		contextMenu->addMenuItem(nativePath, std::bind(&ScriptContextMenu::onContextMenuItemTriggered,
-			instance, callbackIdx), 0, shortcut);
-	}
-
-	void ScriptContextMenu::internal_AddSeparator(ScriptContextMenu* instance, MonoString* path)
-	{
-		WString nativePath = MonoUtil::monoToWString(path);
-
-		GUIContextMenuPtr contextMenu = instance->getInternal();
-		contextMenu->addSeparator(nativePath, 0);
-	}
-
-	void ScriptContextMenu::internal_SetLocalizedName(ScriptContextMenu* instance, MonoString* label, ScriptHString* name)
-	{
-		if (label == nullptr || name == nullptr)
-			return;
-
-		WString nativeLabel = MonoUtil::monoToWString(label);
-		GUIContextMenuPtr contextMenu = instance->getInternal();
-		contextMenu->setLocalizedName(nativeLabel, name->getInternalValue());
-	}
-
-	void ScriptContextMenu::onContextMenuItemTriggered(UINT32 idx)
-	{
-		MonoUtil::invokeThunk(onEntryTriggered, getManagedInstance(), idx);
-	}
+#include "BsScriptContextMenu.h"
+#include "BsScriptMeta.h"
+#include "BsMonoField.h"
+#include "BsMonoClass.h"
+#include "BsMonoManager.h"
+#include "BsMonoMethod.h"
+#include "BsMonoUtil.h"
+#include "BsGUIContextMenu.h"
+#include "BsScriptHString.h"
+
+using namespace std::placeholders;
+
+namespace BansheeEngine
+{
+	ScriptContextMenu::OnEntryTriggeredThunkDef ScriptContextMenu::onEntryTriggered;
+
+	ScriptContextMenu::ScriptContextMenu(MonoObject* instance)
+		: ScriptObject(instance)
+	{
+		mContextMenu = bs_shared_ptr_new<GUIContextMenu>();
+	}
+
+	void ScriptContextMenu::initRuntimeData()
+	{
+		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptContextMenu::internal_CreateInstance);
+		metaData.scriptClass->addInternalCall("Internal_AddItem", &ScriptContextMenu::internal_AddItem);
+		metaData.scriptClass->addInternalCall("Internal_AddSeparator", &ScriptContextMenu::internal_AddSeparator);
+		metaData.scriptClass->addInternalCall("Internal_SetLocalizedName", &ScriptContextMenu::internal_SetLocalizedName);
+
+		onEntryTriggered = (OnEntryTriggeredThunkDef)metaData.scriptClass->getMethod("InternalDoOnEntryTriggered", 1)->getThunk();
+	}
+
+	void ScriptContextMenu::internal_CreateInstance(MonoObject* instance)
+	{
+		ScriptContextMenu* nativeInstance = new (bs_alloc<ScriptContextMenu>()) ScriptContextMenu(instance);
+	}
+
+	void ScriptContextMenu::internal_AddItem(ScriptContextMenu* instance, MonoString* path, UINT32 callbackIdx,
+		ShortcutKey* shortcut)
+	{
+		WString nativePath = MonoUtil::monoToWString(path);
+
+		GUIContextMenuPtr contextMenu = instance->getInternal();
+		contextMenu->addMenuItem(nativePath, std::bind(&ScriptContextMenu::onContextMenuItemTriggered,
+			instance, callbackIdx), 0, *shortcut);
+	}
+
+	void ScriptContextMenu::internal_AddSeparator(ScriptContextMenu* instance, MonoString* path)
+	{
+		WString nativePath = MonoUtil::monoToWString(path);
+
+		GUIContextMenuPtr contextMenu = instance->getInternal();
+		contextMenu->addSeparator(nativePath, 0);
+	}
+
+	void ScriptContextMenu::internal_SetLocalizedName(ScriptContextMenu* instance, MonoString* label, ScriptHString* name)
+	{
+		if (label == nullptr || name == nullptr)
+			return;
+
+		WString nativeLabel = MonoUtil::monoToWString(label);
+		GUIContextMenuPtr contextMenu = instance->getInternal();
+		contextMenu->setLocalizedName(nativeLabel, name->getInternalValue());
+	}
+
+	void ScriptContextMenu::onContextMenuItemTriggered(UINT32 idx)
+	{
+		MonoUtil::invokeThunk(onEntryTriggered, getManagedInstance(), idx);
+	}
 }

+ 108 - 108
SBansheeEngine/Source/BsScriptCursor.cpp

@@ -1,109 +1,109 @@
-#include "BsScriptCursor.h"
-#include "BsMonoManager.h"
-#include "BsMonoClass.h"
-#include "BsMonoUtil.h"
-#include "BsCursor.h"
-#include "BsScriptPixelData.h"
-
-namespace BansheeEngine
-{
-	ScriptCursor::ScriptCursor(MonoObject* instance)
-		:ScriptObject(instance)
-	{ }
-
-	void ScriptCursor::initRuntimeData()
-	{
-		metaData.scriptClass->addInternalCall("Internal_GetScreenPosition", &ScriptCursor::internal_getScreenPosition);
-		metaData.scriptClass->addInternalCall("Internal_SetScreenPosition", &ScriptCursor::internal_setScreenPosition);
-		metaData.scriptClass->addInternalCall("Internal_Hide", &ScriptCursor::internal_hide);
-		metaData.scriptClass->addInternalCall("Internal_Show", &ScriptCursor::internal_show);
-		metaData.scriptClass->addInternalCall("Internal_ClipToRect", &ScriptCursor::internal_clipToRect);
-		metaData.scriptClass->addInternalCall("Internal_ClipDisable", &ScriptCursor::internal_clipDisable);
-		metaData.scriptClass->addInternalCall("Internal_SetCursor", &ScriptCursor::internal_setCursor);
-		metaData.scriptClass->addInternalCall("Internal_SetCursorStr", &ScriptCursor::internal_setCursorStr);
-		metaData.scriptClass->addInternalCall("Internal_SetCursorIcon", &ScriptCursor::internal_setCursorIcon);
-		metaData.scriptClass->addInternalCall("Internal_SetCursorIconStr", &ScriptCursor::internal_setCursorIconStr);
-		metaData.scriptClass->addInternalCall("Internal_ClearCursorIcon", &ScriptCursor::internal_clearCursorIcon);
-		metaData.scriptClass->addInternalCall("Internal_ClearCursorIconStr", &ScriptCursor::internal_clearCursorIconStr);
-	}
-
-	void ScriptCursor::internal_getScreenPosition(Vector2I* value)
-	{
-		Cursor::instance().getScreenPosition();
-	}
-
-	void ScriptCursor::internal_setScreenPosition(Vector2I value)
-	{
-		Cursor::instance().setScreenPosition(value);
-	}
-
-	void ScriptCursor::internal_hide()
-	{
-		Cursor::instance().hide();
-	}
-
-	void ScriptCursor::internal_show()
-	{
-		Cursor::instance().show();
-	}
-
-	void ScriptCursor::internal_clipToRect(Rect2I value)
-	{
-		Cursor::instance().clipToRect(value);
-	}
-
-	void ScriptCursor::internal_clipDisable()
-	{
-		Cursor::instance().clipDisable();
-	}
-
-	void ScriptCursor::internal_setCursorStr(MonoString* name)
-	{
-		String nameStr = MonoUtil::monoToString(name);
-		Cursor::instance().setCursor(nameStr);
-	}
-
-	void ScriptCursor::internal_setCursor(CursorType cursor)
-	{
-		Cursor::instance().setCursor(cursor);
-	}
-
-	void ScriptCursor::internal_setCursorIconStr(MonoString* name, MonoObject* iconData, Vector2I hotspot)
-	{
-		String nameStr = MonoUtil::monoToString(name);
-
-		ScriptPixelData* scriptPixelData = ScriptPixelData::toNative(iconData);
-
-		if (scriptPixelData != nullptr)
-		{
-			PixelDataPtr pixelData = scriptPixelData->getInternalValue();
-			Cursor::instance().setCursorIcon(nameStr, *pixelData, hotspot);
-		}
-		else
-			Cursor::instance().clearCursorIcon(nameStr);
-	}
-
-	void ScriptCursor::internal_setCursorIcon(CursorType cursor, MonoObject* iconData, Vector2I hotspot)
-	{
-		ScriptPixelData* scriptPixelData = ScriptPixelData::toNative(iconData);
-
-		if (scriptPixelData != nullptr)
-		{
-			PixelDataPtr pixelData = scriptPixelData->getInternalValue();
-			Cursor::instance().setCursorIcon(cursor, *pixelData, hotspot);
-		}
-		else
-			Cursor::instance().clearCursorIcon(cursor);
-	}
-
-	void ScriptCursor::internal_clearCursorIconStr(MonoString* name)
-	{
-		String nameStr = MonoUtil::monoToString(name);
-		Cursor::instance().clearCursorIcon(nameStr);
-	}
-
-	void ScriptCursor::internal_clearCursorIcon(CursorType cursor)
-	{
-		Cursor::instance().clearCursorIcon(cursor);
-	}
+#include "BsScriptCursor.h"
+#include "BsMonoManager.h"
+#include "BsMonoClass.h"
+#include "BsMonoUtil.h"
+#include "BsCursor.h"
+#include "BsScriptPixelData.h"
+
+namespace BansheeEngine
+{
+	ScriptCursor::ScriptCursor(MonoObject* instance)
+		:ScriptObject(instance)
+	{ }
+
+	void ScriptCursor::initRuntimeData()
+	{
+		metaData.scriptClass->addInternalCall("Internal_GetScreenPosition", &ScriptCursor::internal_getScreenPosition);
+		metaData.scriptClass->addInternalCall("Internal_SetScreenPosition", &ScriptCursor::internal_setScreenPosition);
+		metaData.scriptClass->addInternalCall("Internal_Hide", &ScriptCursor::internal_hide);
+		metaData.scriptClass->addInternalCall("Internal_Show", &ScriptCursor::internal_show);
+		metaData.scriptClass->addInternalCall("Internal_ClipToRect", &ScriptCursor::internal_clipToRect);
+		metaData.scriptClass->addInternalCall("Internal_ClipDisable", &ScriptCursor::internal_clipDisable);
+		metaData.scriptClass->addInternalCall("Internal_SetCursor", &ScriptCursor::internal_setCursor);
+		metaData.scriptClass->addInternalCall("Internal_SetCursorStr", &ScriptCursor::internal_setCursorStr);
+		metaData.scriptClass->addInternalCall("Internal_SetCursorIcon", &ScriptCursor::internal_setCursorIcon);
+		metaData.scriptClass->addInternalCall("Internal_SetCursorIconStr", &ScriptCursor::internal_setCursorIconStr);
+		metaData.scriptClass->addInternalCall("Internal_ClearCursorIcon", &ScriptCursor::internal_clearCursorIcon);
+		metaData.scriptClass->addInternalCall("Internal_ClearCursorIconStr", &ScriptCursor::internal_clearCursorIconStr);
+	}
+
+	void ScriptCursor::internal_getScreenPosition(Vector2I* value)
+	{
+		Cursor::instance().getScreenPosition();
+	}
+
+	void ScriptCursor::internal_setScreenPosition(Vector2I* value)
+	{
+		Cursor::instance().setScreenPosition(*value);
+	}
+
+	void ScriptCursor::internal_hide()
+	{
+		Cursor::instance().hide();
+	}
+
+	void ScriptCursor::internal_show()
+	{
+		Cursor::instance().show();
+	}
+
+	void ScriptCursor::internal_clipToRect(Rect2I* value)
+	{
+		Cursor::instance().clipToRect(*value);
+	}
+
+	void ScriptCursor::internal_clipDisable()
+	{
+		Cursor::instance().clipDisable();
+	}
+
+	void ScriptCursor::internal_setCursorStr(MonoString* name)
+	{
+		String nameStr = MonoUtil::monoToString(name);
+		Cursor::instance().setCursor(nameStr);
+	}
+
+	void ScriptCursor::internal_setCursor(CursorType cursor)
+	{
+		Cursor::instance().setCursor(cursor);
+	}
+
+	void ScriptCursor::internal_setCursorIconStr(MonoString* name, MonoObject* iconData, Vector2I* hotspot)
+	{
+		String nameStr = MonoUtil::monoToString(name);
+
+		ScriptPixelData* scriptPixelData = ScriptPixelData::toNative(iconData);
+
+		if (scriptPixelData != nullptr)
+		{
+			PixelDataPtr pixelData = scriptPixelData->getInternalValue();
+			Cursor::instance().setCursorIcon(nameStr, *pixelData, *hotspot);
+		}
+		else
+			Cursor::instance().clearCursorIcon(nameStr);
+	}
+
+	void ScriptCursor::internal_setCursorIcon(CursorType cursor, MonoObject* iconData, Vector2I* hotspot)
+	{
+		ScriptPixelData* scriptPixelData = ScriptPixelData::toNative(iconData);
+
+		if (scriptPixelData != nullptr)
+		{
+			PixelDataPtr pixelData = scriptPixelData->getInternalValue();
+			Cursor::instance().setCursorIcon(cursor, *pixelData, *hotspot);
+		}
+		else
+			Cursor::instance().clearCursorIcon(cursor);
+	}
+
+	void ScriptCursor::internal_clearCursorIconStr(MonoString* name)
+	{
+		String nameStr = MonoUtil::monoToString(name);
+		Cursor::instance().clearCursorIcon(nameStr);
+	}
+
+	void ScriptCursor::internal_clearCursorIcon(CursorType cursor)
+	{
+		Cursor::instance().clearCursorIcon(cursor);
+	}
 }

+ 295 - 295
SBansheeEngine/Source/BsScriptMaterial.cpp

@@ -1,296 +1,296 @@
-#include "BsScriptMaterial.h"
-#include "BsScriptResourceManager.h"
-#include "BsScriptMeta.h"
-#include "BsMonoField.h"
-#include "BsMonoClass.h"
-#include "BsMonoManager.h"
-#include "BsMonoUtil.h"
-#include "BsScriptShader.h"
-#include "BsScriptTexture2D.h"
-#include "BsScriptTexture3D.h"
-#include "BsScriptTextureCube.h"
-#include <BsBuiltinResources.h>
-
-namespace BansheeEngine
-{
-	ScriptMaterial::ScriptMaterial(MonoObject* instance, const HMaterial& material)
-		:TScriptResource(instance, material)
-	{
-		int a = 5;
-	}
-
-	void ScriptMaterial::initRuntimeData()
-	{
-		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptMaterial::internal_CreateInstance);
-		metaData.scriptClass->addInternalCall("Internal_Clone", &ScriptMaterial::internal_Clone);
-
-		metaData.scriptClass->addInternalCall("Internal_GetShader", &ScriptMaterial::internal_GetShader);
-		metaData.scriptClass->addInternalCall("Internal_SetShader", &ScriptMaterial::internal_SetShader);
-
-		metaData.scriptClass->addInternalCall("Internal_SetFloat", &ScriptMaterial::internal_SetFloat);
-		metaData.scriptClass->addInternalCall("Internal_SetVector2", &ScriptMaterial::internal_SetVector2);
-		metaData.scriptClass->addInternalCall("Internal_SetVector3", &ScriptMaterial::internal_SetVector3);
-		metaData.scriptClass->addInternalCall("Internal_SetVector4", &ScriptMaterial::internal_SetVector4);
-		metaData.scriptClass->addInternalCall("Internal_SetMatrix3", &ScriptMaterial::internal_SetMatrix3);
-		metaData.scriptClass->addInternalCall("Internal_SetMatrix4", &ScriptMaterial::internal_SetMatrix4);
-		metaData.scriptClass->addInternalCall("Internal_SetColor", &ScriptMaterial::internal_SetColor);
-		metaData.scriptClass->addInternalCall("Internal_SetTexture2D", &ScriptMaterial::internal_SetTexture2D);
-		metaData.scriptClass->addInternalCall("Internal_SetTexture3D", &ScriptMaterial::internal_SetTexture3D);
-		metaData.scriptClass->addInternalCall("Internal_SetTextureCube", &ScriptMaterial::internal_SetTextureCube);
-
-		metaData.scriptClass->addInternalCall("Internal_GetFloat", &ScriptMaterial::internal_GetFloat);
-		metaData.scriptClass->addInternalCall("Internal_GetVector2", &ScriptMaterial::internal_GetVector2);
-		metaData.scriptClass->addInternalCall("Internal_GetVector3", &ScriptMaterial::internal_GetVector3);
-		metaData.scriptClass->addInternalCall("Internal_GetVector4", &ScriptMaterial::internal_GetVector4);
-		metaData.scriptClass->addInternalCall("Internal_GetMatrix3", &ScriptMaterial::internal_GetMatrix3);
-		metaData.scriptClass->addInternalCall("Internal_GetMatrix4", &ScriptMaterial::internal_GetMatrix4);
-		metaData.scriptClass->addInternalCall("Internal_GetColor", &ScriptMaterial::internal_GetColor);
-		metaData.scriptClass->addInternalCall("Internal_GetTexture2D", &ScriptMaterial::internal_GetTexture2D);
-		metaData.scriptClass->addInternalCall("Internal_GetTexture3D", &ScriptMaterial::internal_GetTexture3D);
-		metaData.scriptClass->addInternalCall("Internal_GetTextureCube", &ScriptMaterial::internal_GetTextureCube);
-	}
-
-	void ScriptMaterial::internal_CreateInstance(MonoObject* instance, ScriptShader* shader)
-	{
-		HShader nativeShader;
-		if (shader != nullptr)
-			nativeShader = shader->getHandle();
-
-		if (nativeShader == nullptr)
-			nativeShader = BuiltinResources::instance().getDiffuseShader();
-
-		HMaterial material = Material::create(nativeShader);
-
-		ScriptMaterial* scriptInstance;
-		ScriptResourceManager::instance().createScriptResource(instance, material, &scriptInstance);
-	}
-
-	MonoObject* ScriptMaterial::internal_Clone(ScriptMaterial* nativeInstance)
-	{
-		HMaterial clone = nativeInstance->getHandle()->clone();
-
-		ScriptMaterial* scriptClone;
-		ScriptResourceManager::instance().createScriptResource(clone, &scriptClone);
-
-		return scriptClone->getManagedInstance();
-	}
-
-	MonoObject* ScriptMaterial::internal_GetShader(ScriptMaterial* nativeInstance)
-	{
-		HShader shader = nativeInstance->getHandle()->getShader();
-
-		if (shader == nullptr)
-			return nullptr;
-
-		ScriptShader* scriptShader;
-		ScriptResourceManager::instance().getScriptResource(shader, &scriptShader, true);
-
-		return scriptShader->getManagedInstance();
-	}
-
-	void ScriptMaterial::internal_SetShader(ScriptMaterial* nativeInstance, ScriptShader* shader)
-	{
-		HShader nativeShader;
-		if (shader != nullptr)
-			nativeShader = shader->getHandle();
-
-		if (nativeShader == nullptr)
-			nativeShader = BuiltinResources::instance().getDiffuseShader();
-
-		nativeInstance->getHandle()->setShader(nativeShader);
-	}
-
-	void ScriptMaterial::internal_SetFloat(ScriptMaterial* nativeInstance, MonoString* name, float value)
-	{
-		String paramName = MonoUtil::monoToString(name);
-
-		nativeInstance->getHandle()->setFloat(paramName, value);
-	}
-
-	void ScriptMaterial::internal_SetVector2(ScriptMaterial* nativeInstance, MonoString* name, Vector2 value)
-	{
-		String paramName = MonoUtil::monoToString(name);
-
-		nativeInstance->getHandle()->setVec2(paramName, value);
-	}
-
-	void ScriptMaterial::internal_SetVector3(ScriptMaterial* nativeInstance, MonoString* name, Vector3 value)
-	{
-		String paramName = MonoUtil::monoToString(name);
-
-		nativeInstance->getHandle()->setVec3(paramName, value);
-	}
-
-	void ScriptMaterial::internal_SetVector4(ScriptMaterial* nativeInstance, MonoString* name, Vector4 value)
-	{
-		String paramName = MonoUtil::monoToString(name);
-
-		nativeInstance->getHandle()->setVec4(paramName, value);
-	}
-
-	void ScriptMaterial::internal_SetMatrix3(ScriptMaterial* nativeInstance, MonoString* name, Matrix3 value)
-	{
-		String paramName = MonoUtil::monoToString(name);
-
-		nativeInstance->getHandle()->setMat3(paramName, value);
-	}
-
-	void ScriptMaterial::internal_SetMatrix4(ScriptMaterial* nativeInstance, MonoString* name, Matrix4 value)
-	{
-		String paramName = MonoUtil::monoToString(name);
-
-		nativeInstance->getHandle()->setMat4(paramName, value);
-	}
-
-	void ScriptMaterial::internal_SetColor(ScriptMaterial* nativeInstance, MonoString* name, Color value)
-	{
-		String paramName = MonoUtil::monoToString(name);
-
-		nativeInstance->getHandle()->setColor(paramName, value);
-	}
-
-	void ScriptMaterial::internal_SetTexture2D(ScriptMaterial* nativeInstance, MonoString* name, ScriptTexture2D* value)
-	{
-		String paramName = MonoUtil::monoToString(name);
-
-		HTexture texture;
-
-		if (value != nullptr)
-			texture = value->getHandle();
-
-		nativeInstance->getHandle()->setTexture(paramName, texture);
-	}
-
-	void ScriptMaterial::internal_SetTexture3D(ScriptMaterial* nativeInstance, MonoString* name, ScriptTexture3D* value)
-	{
-		String paramName = MonoUtil::monoToString(name);
-
-		HTexture texture;
-
-		if (value != nullptr)
-			texture = value->getHandle();
-
-		nativeInstance->getHandle()->setTexture(paramName, texture);
-	}
-
-	void ScriptMaterial::internal_SetTextureCube(ScriptMaterial* nativeInstance, MonoString* name, ScriptTextureCube* value)
-	{
-		String paramName = MonoUtil::monoToString(name);
-
-		HTexture texture;
-
-		if (value != nullptr)
-			texture = value->getHandle();
-
-		nativeInstance->getHandle()->setTexture(paramName, texture);
-	}
-
-	float ScriptMaterial::internal_GetFloat(ScriptMaterial* nativeInstance, MonoString* name)
-	{
-		String paramName = MonoUtil::monoToString(name);
-
-		return nativeInstance->getHandle()->getFloat(paramName);
-	}
-
-	Vector2 ScriptMaterial::internal_GetVector2(ScriptMaterial* nativeInstance, MonoString* name)
-	{
-		String paramName = MonoUtil::monoToString(name);
-
-		return nativeInstance->getHandle()->getVec2(paramName);
-	}
-
-	Vector3 ScriptMaterial::internal_GetVector3(ScriptMaterial* nativeInstance, MonoString* name)
-	{
-		String paramName = MonoUtil::monoToString(name);
-
-		return nativeInstance->getHandle()->getVec3(paramName);
-	}
-
-	Vector4 ScriptMaterial::internal_GetVector4(ScriptMaterial* nativeInstance, MonoString* name)
-	{
-		String paramName = MonoUtil::monoToString(name);
-
-		return nativeInstance->getHandle()->getVec4(paramName);
-	}
-
-	Matrix3 ScriptMaterial::internal_GetMatrix3(ScriptMaterial* nativeInstance, MonoString* name)
-	{
-		String paramName = MonoUtil::monoToString(name);
-
-		return nativeInstance->getHandle()->getMat3(paramName);
-	}
-
-	Matrix4 ScriptMaterial::internal_GetMatrix4(ScriptMaterial* nativeInstance, MonoString* name)
-	{
-		String paramName = MonoUtil::monoToString(name);
-
-		return nativeInstance->getHandle()->getMat4(paramName);
-	}
-
-	Color ScriptMaterial::internal_GetColor(ScriptMaterial* nativeInstance, MonoString* name)
-	{
-		String paramName = MonoUtil::monoToString(name);
-
-		return nativeInstance->getHandle()->getColor(paramName);
-	}
-
-	MonoObject* ScriptMaterial::internal_GetTexture2D(ScriptMaterial* nativeInstance, MonoString* name)
-	{
-		String paramName = MonoUtil::monoToString(name);
-
-		HTexture texture = nativeInstance->getHandle()->getTexture(paramName);
-		if (texture == nullptr)
-			return nullptr;
-
-		ScriptTexture2D* scriptTexture;
-		ScriptResourceManager::instance().getScriptResource(texture, &scriptTexture, true);
-
-		return scriptTexture->getManagedInstance();
-	}
-
-	MonoObject* ScriptMaterial::internal_GetTexture3D(ScriptMaterial* nativeInstance, MonoString* name)
-	{
-		String paramName = MonoUtil::monoToString(name);
-
-		HTexture texture = nativeInstance->getHandle()->getTexture(paramName);
-		if (texture == nullptr)
-			return nullptr;
-
-		ScriptTexture3D* scriptTexture;
-		ScriptResourceManager::instance().getScriptResource(texture, &scriptTexture, true);
-
-		return scriptTexture->getManagedInstance();
-	}
-
-	MonoObject* ScriptMaterial::internal_GetTextureCube(ScriptMaterial* nativeInstance, MonoString* name)
-	{
-		String paramName = MonoUtil::monoToString(name);
-
-		HTexture texture = nativeInstance->getHandle()->getTexture(paramName);
-		if (texture == nullptr)
-			return nullptr;
-
-		ScriptTextureCube* scriptTexture;
-		ScriptResourceManager::instance().getScriptResource(texture, &scriptTexture, true);
-
-		return scriptTexture->getManagedInstance();
-	}
-
-	MonoObject* ScriptMaterial::createInstance()
-	{
-		bool dummy = false;
-
-		void* params[1];
-		params[0] = &dummy;
-
-		return metaData.scriptClass->createInstance("bool", params);
-	}
-
-	MonoObject* ScriptMaterial::_createManagedInstance(bool construct)
-	{
-		if (construct)
-			return createInstance();
-
-		return metaData.scriptClass->createInstance(false);
-	}
+#include "BsScriptMaterial.h"
+#include "BsScriptResourceManager.h"
+#include "BsScriptMeta.h"
+#include "BsMonoField.h"
+#include "BsMonoClass.h"
+#include "BsMonoManager.h"
+#include "BsMonoUtil.h"
+#include "BsScriptShader.h"
+#include "BsScriptTexture2D.h"
+#include "BsScriptTexture3D.h"
+#include "BsScriptTextureCube.h"
+#include <BsBuiltinResources.h>
+
+namespace BansheeEngine
+{
+	ScriptMaterial::ScriptMaterial(MonoObject* instance, const HMaterial& material)
+		:TScriptResource(instance, material)
+	{
+		int a = 5;
+	}
+
+	void ScriptMaterial::initRuntimeData()
+	{
+		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptMaterial::internal_CreateInstance);
+		metaData.scriptClass->addInternalCall("Internal_Clone", &ScriptMaterial::internal_Clone);
+
+		metaData.scriptClass->addInternalCall("Internal_GetShader", &ScriptMaterial::internal_GetShader);
+		metaData.scriptClass->addInternalCall("Internal_SetShader", &ScriptMaterial::internal_SetShader);
+
+		metaData.scriptClass->addInternalCall("Internal_SetFloat", &ScriptMaterial::internal_SetFloat);
+		metaData.scriptClass->addInternalCall("Internal_SetVector2", &ScriptMaterial::internal_SetVector2);
+		metaData.scriptClass->addInternalCall("Internal_SetVector3", &ScriptMaterial::internal_SetVector3);
+		metaData.scriptClass->addInternalCall("Internal_SetVector4", &ScriptMaterial::internal_SetVector4);
+		metaData.scriptClass->addInternalCall("Internal_SetMatrix3", &ScriptMaterial::internal_SetMatrix3);
+		metaData.scriptClass->addInternalCall("Internal_SetMatrix4", &ScriptMaterial::internal_SetMatrix4);
+		metaData.scriptClass->addInternalCall("Internal_SetColor", &ScriptMaterial::internal_SetColor);
+		metaData.scriptClass->addInternalCall("Internal_SetTexture2D", &ScriptMaterial::internal_SetTexture2D);
+		metaData.scriptClass->addInternalCall("Internal_SetTexture3D", &ScriptMaterial::internal_SetTexture3D);
+		metaData.scriptClass->addInternalCall("Internal_SetTextureCube", &ScriptMaterial::internal_SetTextureCube);
+
+		metaData.scriptClass->addInternalCall("Internal_GetFloat", &ScriptMaterial::internal_GetFloat);
+		metaData.scriptClass->addInternalCall("Internal_GetVector2", &ScriptMaterial::internal_GetVector2);
+		metaData.scriptClass->addInternalCall("Internal_GetVector3", &ScriptMaterial::internal_GetVector3);
+		metaData.scriptClass->addInternalCall("Internal_GetVector4", &ScriptMaterial::internal_GetVector4);
+		metaData.scriptClass->addInternalCall("Internal_GetMatrix3", &ScriptMaterial::internal_GetMatrix3);
+		metaData.scriptClass->addInternalCall("Internal_GetMatrix4", &ScriptMaterial::internal_GetMatrix4);
+		metaData.scriptClass->addInternalCall("Internal_GetColor", &ScriptMaterial::internal_GetColor);
+		metaData.scriptClass->addInternalCall("Internal_GetTexture2D", &ScriptMaterial::internal_GetTexture2D);
+		metaData.scriptClass->addInternalCall("Internal_GetTexture3D", &ScriptMaterial::internal_GetTexture3D);
+		metaData.scriptClass->addInternalCall("Internal_GetTextureCube", &ScriptMaterial::internal_GetTextureCube);
+	}
+
+	void ScriptMaterial::internal_CreateInstance(MonoObject* instance, ScriptShader* shader)
+	{
+		HShader nativeShader;
+		if (shader != nullptr)
+			nativeShader = shader->getHandle();
+
+		if (nativeShader == nullptr)
+			nativeShader = BuiltinResources::instance().getDiffuseShader();
+
+		HMaterial material = Material::create(nativeShader);
+
+		ScriptMaterial* scriptInstance;
+		ScriptResourceManager::instance().createScriptResource(instance, material, &scriptInstance);
+	}
+
+	MonoObject* ScriptMaterial::internal_Clone(ScriptMaterial* nativeInstance)
+	{
+		HMaterial clone = nativeInstance->getHandle()->clone();
+
+		ScriptMaterial* scriptClone;
+		ScriptResourceManager::instance().createScriptResource(clone, &scriptClone);
+
+		return scriptClone->getManagedInstance();
+	}
+
+	MonoObject* ScriptMaterial::internal_GetShader(ScriptMaterial* nativeInstance)
+	{
+		HShader shader = nativeInstance->getHandle()->getShader();
+
+		if (shader == nullptr)
+			return nullptr;
+
+		ScriptShader* scriptShader;
+		ScriptResourceManager::instance().getScriptResource(shader, &scriptShader, true);
+
+		return scriptShader->getManagedInstance();
+	}
+
+	void ScriptMaterial::internal_SetShader(ScriptMaterial* nativeInstance, ScriptShader* shader)
+	{
+		HShader nativeShader;
+		if (shader != nullptr)
+			nativeShader = shader->getHandle();
+
+		if (nativeShader == nullptr)
+			nativeShader = BuiltinResources::instance().getDiffuseShader();
+
+		nativeInstance->getHandle()->setShader(nativeShader);
+	}
+
+	void ScriptMaterial::internal_SetFloat(ScriptMaterial* nativeInstance, MonoString* name, float value)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		nativeInstance->getHandle()->setFloat(paramName, value);
+	}
+
+	void ScriptMaterial::internal_SetVector2(ScriptMaterial* nativeInstance, MonoString* name, Vector2* value)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		nativeInstance->getHandle()->setVec2(paramName, *value);
+	}
+
+	void ScriptMaterial::internal_SetVector3(ScriptMaterial* nativeInstance, MonoString* name, Vector3* value)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		nativeInstance->getHandle()->setVec3(paramName, *value);
+	}
+
+	void ScriptMaterial::internal_SetVector4(ScriptMaterial* nativeInstance, MonoString* name, Vector4* value)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		nativeInstance->getHandle()->setVec4(paramName, *value);
+	}
+
+	void ScriptMaterial::internal_SetMatrix3(ScriptMaterial* nativeInstance, MonoString* name, Matrix3* value)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		nativeInstance->getHandle()->setMat3(paramName, *value);
+	}
+
+	void ScriptMaterial::internal_SetMatrix4(ScriptMaterial* nativeInstance, MonoString* name, Matrix4* value)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		nativeInstance->getHandle()->setMat4(paramName, *value);
+	}
+
+	void ScriptMaterial::internal_SetColor(ScriptMaterial* nativeInstance, MonoString* name, Color* value)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		nativeInstance->getHandle()->setColor(paramName, *value);
+	}
+
+	void ScriptMaterial::internal_SetTexture2D(ScriptMaterial* nativeInstance, MonoString* name, ScriptTexture2D* value)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		HTexture texture;
+
+		if (value != nullptr)
+			texture = value->getHandle();
+
+		nativeInstance->getHandle()->setTexture(paramName, texture);
+	}
+
+	void ScriptMaterial::internal_SetTexture3D(ScriptMaterial* nativeInstance, MonoString* name, ScriptTexture3D* value)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		HTexture texture;
+
+		if (value != nullptr)
+			texture = value->getHandle();
+
+		nativeInstance->getHandle()->setTexture(paramName, texture);
+	}
+
+	void ScriptMaterial::internal_SetTextureCube(ScriptMaterial* nativeInstance, MonoString* name, ScriptTextureCube* value)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		HTexture texture;
+
+		if (value != nullptr)
+			texture = value->getHandle();
+
+		nativeInstance->getHandle()->setTexture(paramName, texture);
+	}
+
+	float ScriptMaterial::internal_GetFloat(ScriptMaterial* nativeInstance, MonoString* name)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		return nativeInstance->getHandle()->getFloat(paramName);
+	}
+
+	void ScriptMaterial::internal_GetVector2(ScriptMaterial* nativeInstance, MonoString* name, Vector2* value)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		*value = nativeInstance->getHandle()->getVec2(paramName);
+	}
+
+	void ScriptMaterial::internal_GetVector3(ScriptMaterial* nativeInstance, MonoString* name, Vector3* value)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		*value = nativeInstance->getHandle()->getVec3(paramName);
+	}
+
+	void ScriptMaterial::internal_GetVector4(ScriptMaterial* nativeInstance, MonoString* name, Vector4* value)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		*value = nativeInstance->getHandle()->getVec4(paramName);
+	}
+
+	void ScriptMaterial::internal_GetMatrix3(ScriptMaterial* nativeInstance, MonoString* name, Matrix3* value)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		*value = nativeInstance->getHandle()->getMat3(paramName);
+	}
+
+	void ScriptMaterial::internal_GetMatrix4(ScriptMaterial* nativeInstance, MonoString* name, Matrix4* value)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		*value = nativeInstance->getHandle()->getMat4(paramName);
+	}
+
+	void ScriptMaterial::internal_GetColor(ScriptMaterial* nativeInstance, MonoString* name, Color* value)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		*value = nativeInstance->getHandle()->getColor(paramName);
+	}
+
+	MonoObject* ScriptMaterial::internal_GetTexture2D(ScriptMaterial* nativeInstance, MonoString* name)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		HTexture texture = nativeInstance->getHandle()->getTexture(paramName);
+		if (texture == nullptr)
+			return nullptr;
+
+		ScriptTexture2D* scriptTexture;
+		ScriptResourceManager::instance().getScriptResource(texture, &scriptTexture, true);
+
+		return scriptTexture->getManagedInstance();
+	}
+
+	MonoObject* ScriptMaterial::internal_GetTexture3D(ScriptMaterial* nativeInstance, MonoString* name)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		HTexture texture = nativeInstance->getHandle()->getTexture(paramName);
+		if (texture == nullptr)
+			return nullptr;
+
+		ScriptTexture3D* scriptTexture;
+		ScriptResourceManager::instance().getScriptResource(texture, &scriptTexture, true);
+
+		return scriptTexture->getManagedInstance();
+	}
+
+	MonoObject* ScriptMaterial::internal_GetTextureCube(ScriptMaterial* nativeInstance, MonoString* name)
+	{
+		String paramName = MonoUtil::monoToString(name);
+
+		HTexture texture = nativeInstance->getHandle()->getTexture(paramName);
+		if (texture == nullptr)
+			return nullptr;
+
+		ScriptTextureCube* scriptTexture;
+		ScriptResourceManager::instance().getScriptResource(texture, &scriptTexture, true);
+
+		return scriptTexture->getManagedInstance();
+	}
+
+	MonoObject* ScriptMaterial::createInstance()
+	{
+		bool dummy = false;
+
+		void* params[1];
+		params[0] = &dummy;
+
+		return metaData.scriptClass->createInstance("bool", params);
+	}
+
+	MonoObject* ScriptMaterial::_createManagedInstance(bool construct)
+	{
+		if (construct)
+			return createInstance();
+
+		return metaData.scriptClass->createInstance(false);
+	}
 }

+ 310 - 310
SBansheeEngine/Source/BsScriptPixelData.cpp

@@ -1,311 +1,311 @@
-#include "BsScriptPixelData.h"
-#include "BsScriptMeta.h"
-#include "BsMonoField.h"
-#include "BsMonoClass.h"
-#include "BsMonoManager.h"
-#include "BsMonoUtil.h"
-#include "BsPixelUtil.h"
-#include "BsScriptColor.h"
-
-namespace BansheeEngine
-{
-	ScriptPixelData::ScriptPixelData(MonoObject* managedInstance)
-		:ScriptObject(managedInstance)
-	{
-
-	}
-
-	ScriptPixelData::~ScriptPixelData()
-	{
-
-	}
-
-	void ScriptPixelData::initRuntimeData()
-	{
-		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptPixelData::internal_createInstance);
-		metaData.scriptClass->addInternalCall("Internal_GetPixel", &ScriptPixelData::internal_getPixel);
-		metaData.scriptClass->addInternalCall("Internal_SetPixel", &ScriptPixelData::internal_setPixel);
-		metaData.scriptClass->addInternalCall("Internal_GetPixels", &ScriptPixelData::internal_getPixels);
-		metaData.scriptClass->addInternalCall("Internal_SetPixels", &ScriptPixelData::internal_setPixels);
-		metaData.scriptClass->addInternalCall("Internal_GetRawPixels", &ScriptPixelData::internal_getRawPixels);
-		metaData.scriptClass->addInternalCall("Internal_SetRawPixels", &ScriptPixelData::internal_setRawPixels);
-		metaData.scriptClass->addInternalCall("Internal_GetExtents", &ScriptPixelData::internal_getExtents);
-		metaData.scriptClass->addInternalCall("Internal_GetFormat", &ScriptPixelData::internal_getFormat);
-		metaData.scriptClass->addInternalCall("Internal_GetRowPitch", &ScriptPixelData::internal_getRowPitch);
-		metaData.scriptClass->addInternalCall("Internal_GetSlicePitch", &ScriptPixelData::internal_getSlicePitch);
-		metaData.scriptClass->addInternalCall("Internal_GetSize", &ScriptPixelData::internal_getSize);
-		metaData.scriptClass->addInternalCall("Internal_GetIsConsecutive", &ScriptPixelData::internal_getIsConsecutive);
-	}
-
-	void ScriptPixelData::initialize(const PixelDataPtr& pixelData)
-	{
-		mPixelData = pixelData;
-	}
-
-	MonoObject* ScriptPixelData::create(const PixelDataPtr& pixelData)
-	{
-		MonoObject* pixelDataObj = metaData.scriptClass->createInstance();
-
-		ScriptPixelData* scriptPixelData = ScriptPixelData::toNative(pixelDataObj);
-		scriptPixelData->initialize(pixelData);
-
-		return pixelDataObj;
-	}
-
-	void ScriptPixelData::internal_createInstance(MonoObject* instance, PixelVolume volume, PixelFormat format)
-	{
-		PixelDataPtr pixelData = bs_shared_ptr_new<PixelData>(volume, format);
-		pixelData->allocateInternalBuffer();
-
-		ScriptPixelData* scriptPixelData = new (bs_alloc<ScriptPixelData>()) ScriptPixelData(instance);
-		scriptPixelData->initialize(pixelData);
-	}
-
-	void ScriptPixelData::internal_getPixel(ScriptPixelData* thisPtr, int x, int y, int z, Color* value)
-	{
-		if (!checkIsLocked(thisPtr))
-			*value = thisPtr->mPixelData->getColorAt(x, y, z);
-		else
-			*value = Color();
-	}
-
-	void ScriptPixelData::internal_setPixel(ScriptPixelData* thisPtr, int x, int y, int z, Color value)
-	{
-		if (!checkIsLocked(thisPtr))
-			thisPtr->mPixelData->setColorAt(value, x, y, z);
-	}
-
-	void ScriptPixelData::internal_getPixels(ScriptPixelData* thisPtr, MonoArray** value)
-	{
-		if (!checkIsLocked(thisPtr))
-			return;
-
-		PixelDataPtr pixelData = thisPtr->mPixelData;
-		PixelVolume pixelVolume = pixelData->getExtents();
-		UINT32 depth = pixelVolume.getDepth();
-		UINT32 height = pixelVolume.getHeight();
-		UINT32 width = pixelVolume.getWidth();
-
-		::MonoClass* colorClass = ScriptColor::getMetaData()->scriptClass->_getInternalClass();
-		UINT32 totalNumElements = width * height * depth;
-		MonoArray* colorArray = mono_array_new(MonoManager::instance().getDomain(),
-			colorClass, totalNumElements);
-
-		PixelFormat format = pixelData->getFormat();
-		UINT32 pixelSize = PixelUtil::getNumElemBytes(format);
-		UINT8* data = pixelData->getData();
-
-		UINT32 rowPitch = pixelData->getRowPitch();
-		UINT32 slicePitch = pixelData->getSlicePitch();
-
-		// Note: Can I copy bytes more directly?
-		for (UINT32 z = 0; z < depth; z++)
-		{
-			UINT32 zArrayIdx = z * width * height;
-			UINT32 zDataIdx = z * slicePitch * pixelSize;
-
-			for (UINT32 y = 0; y < height; y++)
-			{
-				UINT32 yArrayIdx = y * width;
-				UINT32 yDataIdx = y * rowPitch * pixelSize;
-
-				for (UINT32 x = 0; x < width; x++)
-				{
-					UINT32 arrayIdx = x + yArrayIdx + zArrayIdx;
-					UINT32 dataIdx = x * pixelSize + yDataIdx + zDataIdx;
-
-					UINT8* dest = data + dataIdx;
-					mono_array_set(colorArray, Color, arrayIdx, *(Color*)dest);
-				}
-			}
-		}
-
-		*value = colorArray;
-
-	}
-
-	void ScriptPixelData::internal_setPixels(ScriptPixelData* thisPtr, MonoArray* value)
-	{
-		if (!checkIsLocked(thisPtr))
-			return;
-
-		PixelDataPtr pixelData = thisPtr->mPixelData;
-		PixelVolume pixelVolume = pixelData->getExtents();
-		UINT32 depth = pixelVolume.getDepth();
-		UINT32 height = pixelVolume.getHeight();
-		UINT32 width = pixelVolume.getWidth();
-
-		UINT32 arrayLen = (UINT32)mono_array_length(value);
-		UINT32 totalNumElements = width * height * depth;
-		if (arrayLen != totalNumElements)
-		{
-			LOGERR("Unable to set colors, invalid array size.")
-			return;
-		}
-
-		PixelFormat format = pixelData->getFormat();
-		UINT32 pixelSize = PixelUtil::getNumElemBytes(format);
-		UINT8* data = pixelData->getData();
-
-		UINT32 rowPitch = pixelData->getRowPitch();
-		UINT32 slicePitch = pixelData->getSlicePitch();
-
-		for (UINT32 z = 0; z < depth; z++)
-		{
-			UINT32 zArrayIdx = z * width * height;
-			UINT32 zDataIdx = z * slicePitch * pixelSize;
-
-			for (UINT32 y = 0; y < height; y++)
-			{
-				UINT32 yArrayIdx = y * width;
-				UINT32 yDataIdx = y * rowPitch * pixelSize;
-
-				for (UINT32 x = 0; x < width; x++)
-				{
-					UINT32 arrayIdx = x + yArrayIdx + zArrayIdx;
-					UINT32 dataIdx = x * pixelSize + yDataIdx + zDataIdx;
-
-					UINT8* dest = data + dataIdx;
-
-					Color color = mono_array_get(value, Color, arrayIdx);
-					PixelUtil::packColor(color, format, dest);
-				}
-			}
-		}
-	}
-
-	void ScriptPixelData::internal_getRawPixels(ScriptPixelData* thisPtr, MonoArray** value)
-	{
-		if (!checkIsLocked(thisPtr))
-			return;
-
-		PixelDataPtr pixelData = thisPtr->mPixelData;
-		PixelVolume pixelVolume = pixelData->getExtents();
-		UINT32 depth = pixelVolume.getDepth();
-		UINT32 height = pixelVolume.getHeight();
-		UINT32 width = pixelVolume.getWidth();
-
-		MonoArray* byteArray = mono_array_new(MonoManager::instance().getDomain(),
-			mono_get_byte_class(), pixelData->getSize());
-
-		PixelFormat format = pixelData->getFormat();
-		UINT32 pixelSize = PixelUtil::getNumElemBytes(format);
-		UINT8* data = pixelData->getData();
-
-		UINT32 rowPitch = pixelData->getRowPitch();
-		UINT32 slicePitch = pixelData->getSlicePitch();
-
-		// Note: Can I copy bytes more directly?
-		for (UINT32 z = 0; z < depth; z++)
-		{
-			UINT32 zArrayIdx = z * width * height;
-			UINT32 zDataIdx = z * slicePitch * pixelSize;
-
-			for (UINT32 y = 0; y < height; y++)
-			{
-				UINT32 yArrayIdx = y * width;
-				UINT32 yDataIdx = y * rowPitch * pixelSize;
-
-				for (UINT32 x = 0; x < width; x++)
-				{
-					UINT32 arrayIdx = x + yArrayIdx + zArrayIdx;
-					UINT32 dataIdx = x * pixelSize + yDataIdx + zDataIdx;
-
-					UINT8* dest = data + dataIdx;
-					mono_array_set(byteArray, char, arrayIdx, *dest);
-				}
-			}
-		}
-
-		*value = byteArray;
-	}
-
-	void ScriptPixelData::internal_setRawPixels(ScriptPixelData* thisPtr, MonoArray* value)
-	{
-		if (!checkIsLocked(thisPtr))
-			return;
-
-		PixelDataPtr pixelData = thisPtr->mPixelData;
-		PixelVolume pixelVolume = pixelData->getExtents();
-		UINT32 depth = pixelVolume.getDepth();
-		UINT32 height = pixelVolume.getHeight();
-		UINT32 width = pixelVolume.getWidth();
-
-		UINT32 arrayLen = (UINT32)mono_array_length(value);
-		if (pixelData->getSize() != arrayLen)
-		{
-			LOGERR("Unable to set colors, invalid array size.")
-			return;
-		}
-
-		PixelFormat format = pixelData->getFormat();
-		UINT32 pixelSize = PixelUtil::getNumElemBytes(format);
-		UINT8* data = pixelData->getData();
-
-		UINT32 rowPitch = pixelData->getRowPitch();
-		UINT32 slicePitch = pixelData->getSlicePitch();
-
-		// Note: Can I copy bytes more directly?
-		for (UINT32 z = 0; z < depth; z++)
-		{
-			UINT32 zArrayIdx = z * width * height;
-			UINT32 zDataIdx = z * slicePitch * pixelSize;
-
-			for (UINT32 y = 0; y < height; y++)
-			{
-				UINT32 yArrayIdx = y * width;
-				UINT32 yDataIdx = y * rowPitch * pixelSize;
-
-				for (UINT32 x = 0; x < width; x++)
-				{
-					UINT32 arrayIdx = x + yArrayIdx + zArrayIdx;
-					UINT32 dataIdx = x * pixelSize + yDataIdx + zDataIdx;
-
-					UINT8* dest = data + dataIdx;
-					*dest = mono_array_get(value, char, arrayIdx);
-				}
-			}
-		}
-	}
-
-	void ScriptPixelData::internal_getExtents(ScriptPixelData* thisPtr, PixelVolume* value)
-	{
-		*value = thisPtr->mPixelData->getExtents();
-	}
-
-	void ScriptPixelData::internal_getFormat(ScriptPixelData* thisPtr, PixelFormat* value)
-	{
-		*value = thisPtr->mPixelData->getFormat();
-	}
-
-	void ScriptPixelData::internal_getRowPitch(ScriptPixelData* thisPtr, int* value)
-	{
-		*value = thisPtr->mPixelData->getRowPitch();
-	}
-
-	void ScriptPixelData::internal_getSlicePitch(ScriptPixelData* thisPtr, int* value)
-	{
-		*value = thisPtr->mPixelData->getSlicePitch();
-	}
-
-	void ScriptPixelData::internal_getSize(ScriptPixelData* thisPtr, int* value)
-	{
-		*value = thisPtr->mPixelData->getSize();
-	}
-
-	void ScriptPixelData::internal_getIsConsecutive(ScriptPixelData* thisPtr, bool* value)
-	{
-		*value = thisPtr->mPixelData->isConsecutive();
-	}
-
-	bool ScriptPixelData::checkIsLocked(ScriptPixelData* thisPtr)
-	{
-		if (thisPtr->mPixelData->isLocked())
-		{
-			LOGWRN("Attempting to access a locked pixel data buffer.");
-			return true;
-		}
-
-		return false;
-	}
+#include "BsScriptPixelData.h"
+#include "BsScriptMeta.h"
+#include "BsMonoField.h"
+#include "BsMonoClass.h"
+#include "BsMonoManager.h"
+#include "BsMonoUtil.h"
+#include "BsPixelUtil.h"
+#include "BsScriptColor.h"
+
+namespace BansheeEngine
+{
+	ScriptPixelData::ScriptPixelData(MonoObject* managedInstance)
+		:ScriptObject(managedInstance)
+	{
+
+	}
+
+	ScriptPixelData::~ScriptPixelData()
+	{
+
+	}
+
+	void ScriptPixelData::initRuntimeData()
+	{
+		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptPixelData::internal_createInstance);
+		metaData.scriptClass->addInternalCall("Internal_GetPixel", &ScriptPixelData::internal_getPixel);
+		metaData.scriptClass->addInternalCall("Internal_SetPixel", &ScriptPixelData::internal_setPixel);
+		metaData.scriptClass->addInternalCall("Internal_GetPixels", &ScriptPixelData::internal_getPixels);
+		metaData.scriptClass->addInternalCall("Internal_SetPixels", &ScriptPixelData::internal_setPixels);
+		metaData.scriptClass->addInternalCall("Internal_GetRawPixels", &ScriptPixelData::internal_getRawPixels);
+		metaData.scriptClass->addInternalCall("Internal_SetRawPixels", &ScriptPixelData::internal_setRawPixels);
+		metaData.scriptClass->addInternalCall("Internal_GetExtents", &ScriptPixelData::internal_getExtents);
+		metaData.scriptClass->addInternalCall("Internal_GetFormat", &ScriptPixelData::internal_getFormat);
+		metaData.scriptClass->addInternalCall("Internal_GetRowPitch", &ScriptPixelData::internal_getRowPitch);
+		metaData.scriptClass->addInternalCall("Internal_GetSlicePitch", &ScriptPixelData::internal_getSlicePitch);
+		metaData.scriptClass->addInternalCall("Internal_GetSize", &ScriptPixelData::internal_getSize);
+		metaData.scriptClass->addInternalCall("Internal_GetIsConsecutive", &ScriptPixelData::internal_getIsConsecutive);
+	}
+
+	void ScriptPixelData::initialize(const PixelDataPtr& pixelData)
+	{
+		mPixelData = pixelData;
+	}
+
+	MonoObject* ScriptPixelData::create(const PixelDataPtr& pixelData)
+	{
+		MonoObject* pixelDataObj = metaData.scriptClass->createInstance();
+
+		ScriptPixelData* scriptPixelData = ScriptPixelData::toNative(pixelDataObj);
+		scriptPixelData->initialize(pixelData);
+
+		return pixelDataObj;
+	}
+
+	void ScriptPixelData::internal_createInstance(MonoObject* instance, PixelVolume* volume, PixelFormat format)
+	{
+		PixelDataPtr pixelData = bs_shared_ptr_new<PixelData>(*volume, format);
+		pixelData->allocateInternalBuffer();
+
+		ScriptPixelData* scriptPixelData = new (bs_alloc<ScriptPixelData>()) ScriptPixelData(instance);
+		scriptPixelData->initialize(pixelData);
+	}
+
+	void ScriptPixelData::internal_getPixel(ScriptPixelData* thisPtr, int x, int y, int z, Color* value)
+	{
+		if (!checkIsLocked(thisPtr))
+			*value = thisPtr->mPixelData->getColorAt(x, y, z);
+		else
+			*value = Color();
+	}
+
+	void ScriptPixelData::internal_setPixel(ScriptPixelData* thisPtr, int x, int y, int z, Color* value)
+	{
+		if (!checkIsLocked(thisPtr))
+			thisPtr->mPixelData->setColorAt(*value, x, y, z);
+	}
+
+	void ScriptPixelData::internal_getPixels(ScriptPixelData* thisPtr, MonoArray** value)
+	{
+		if (!checkIsLocked(thisPtr))
+			return;
+
+		PixelDataPtr pixelData = thisPtr->mPixelData;
+		PixelVolume pixelVolume = pixelData->getExtents();
+		UINT32 depth = pixelVolume.getDepth();
+		UINT32 height = pixelVolume.getHeight();
+		UINT32 width = pixelVolume.getWidth();
+
+		::MonoClass* colorClass = ScriptColor::getMetaData()->scriptClass->_getInternalClass();
+		UINT32 totalNumElements = width * height * depth;
+		MonoArray* colorArray = mono_array_new(MonoManager::instance().getDomain(),
+			colorClass, totalNumElements);
+
+		PixelFormat format = pixelData->getFormat();
+		UINT32 pixelSize = PixelUtil::getNumElemBytes(format);
+		UINT8* data = pixelData->getData();
+
+		UINT32 rowPitch = pixelData->getRowPitch();
+		UINT32 slicePitch = pixelData->getSlicePitch();
+
+		// Note: Can I copy bytes more directly?
+		for (UINT32 z = 0; z < depth; z++)
+		{
+			UINT32 zArrayIdx = z * width * height;
+			UINT32 zDataIdx = z * slicePitch * pixelSize;
+
+			for (UINT32 y = 0; y < height; y++)
+			{
+				UINT32 yArrayIdx = y * width;
+				UINT32 yDataIdx = y * rowPitch * pixelSize;
+
+				for (UINT32 x = 0; x < width; x++)
+				{
+					UINT32 arrayIdx = x + yArrayIdx + zArrayIdx;
+					UINT32 dataIdx = x * pixelSize + yDataIdx + zDataIdx;
+
+					UINT8* dest = data + dataIdx;
+					mono_array_set(colorArray, Color, arrayIdx, *(Color*)dest);
+				}
+			}
+		}
+
+		*value = colorArray;
+
+	}
+
+	void ScriptPixelData::internal_setPixels(ScriptPixelData* thisPtr, MonoArray* value)
+	{
+		if (!checkIsLocked(thisPtr))
+			return;
+
+		PixelDataPtr pixelData = thisPtr->mPixelData;
+		PixelVolume pixelVolume = pixelData->getExtents();
+		UINT32 depth = pixelVolume.getDepth();
+		UINT32 height = pixelVolume.getHeight();
+		UINT32 width = pixelVolume.getWidth();
+
+		UINT32 arrayLen = (UINT32)mono_array_length(value);
+		UINT32 totalNumElements = width * height * depth;
+		if (arrayLen != totalNumElements)
+		{
+			LOGERR("Unable to set colors, invalid array size.")
+			return;
+		}
+
+		PixelFormat format = pixelData->getFormat();
+		UINT32 pixelSize = PixelUtil::getNumElemBytes(format);
+		UINT8* data = pixelData->getData();
+
+		UINT32 rowPitch = pixelData->getRowPitch();
+		UINT32 slicePitch = pixelData->getSlicePitch();
+
+		for (UINT32 z = 0; z < depth; z++)
+		{
+			UINT32 zArrayIdx = z * width * height;
+			UINT32 zDataIdx = z * slicePitch * pixelSize;
+
+			for (UINT32 y = 0; y < height; y++)
+			{
+				UINT32 yArrayIdx = y * width;
+				UINT32 yDataIdx = y * rowPitch * pixelSize;
+
+				for (UINT32 x = 0; x < width; x++)
+				{
+					UINT32 arrayIdx = x + yArrayIdx + zArrayIdx;
+					UINT32 dataIdx = x * pixelSize + yDataIdx + zDataIdx;
+
+					UINT8* dest = data + dataIdx;
+
+					Color color = mono_array_get(value, Color, arrayIdx);
+					PixelUtil::packColor(color, format, dest);
+				}
+			}
+		}
+	}
+
+	void ScriptPixelData::internal_getRawPixels(ScriptPixelData* thisPtr, MonoArray** value)
+	{
+		if (!checkIsLocked(thisPtr))
+			return;
+
+		PixelDataPtr pixelData = thisPtr->mPixelData;
+		PixelVolume pixelVolume = pixelData->getExtents();
+		UINT32 depth = pixelVolume.getDepth();
+		UINT32 height = pixelVolume.getHeight();
+		UINT32 width = pixelVolume.getWidth();
+
+		MonoArray* byteArray = mono_array_new(MonoManager::instance().getDomain(),
+			mono_get_byte_class(), pixelData->getSize());
+
+		PixelFormat format = pixelData->getFormat();
+		UINT32 pixelSize = PixelUtil::getNumElemBytes(format);
+		UINT8* data = pixelData->getData();
+
+		UINT32 rowPitch = pixelData->getRowPitch();
+		UINT32 slicePitch = pixelData->getSlicePitch();
+
+		// Note: Can I copy bytes more directly?
+		for (UINT32 z = 0; z < depth; z++)
+		{
+			UINT32 zArrayIdx = z * width * height;
+			UINT32 zDataIdx = z * slicePitch * pixelSize;
+
+			for (UINT32 y = 0; y < height; y++)
+			{
+				UINT32 yArrayIdx = y * width;
+				UINT32 yDataIdx = y * rowPitch * pixelSize;
+
+				for (UINT32 x = 0; x < width; x++)
+				{
+					UINT32 arrayIdx = x + yArrayIdx + zArrayIdx;
+					UINT32 dataIdx = x * pixelSize + yDataIdx + zDataIdx;
+
+					UINT8* dest = data + dataIdx;
+					mono_array_set(byteArray, char, arrayIdx, *dest);
+				}
+			}
+		}
+
+		*value = byteArray;
+	}
+
+	void ScriptPixelData::internal_setRawPixels(ScriptPixelData* thisPtr, MonoArray* value)
+	{
+		if (!checkIsLocked(thisPtr))
+			return;
+
+		PixelDataPtr pixelData = thisPtr->mPixelData;
+		PixelVolume pixelVolume = pixelData->getExtents();
+		UINT32 depth = pixelVolume.getDepth();
+		UINT32 height = pixelVolume.getHeight();
+		UINT32 width = pixelVolume.getWidth();
+
+		UINT32 arrayLen = (UINT32)mono_array_length(value);
+		if (pixelData->getSize() != arrayLen)
+		{
+			LOGERR("Unable to set colors, invalid array size.")
+			return;
+		}
+
+		PixelFormat format = pixelData->getFormat();
+		UINT32 pixelSize = PixelUtil::getNumElemBytes(format);
+		UINT8* data = pixelData->getData();
+
+		UINT32 rowPitch = pixelData->getRowPitch();
+		UINT32 slicePitch = pixelData->getSlicePitch();
+
+		// Note: Can I copy bytes more directly?
+		for (UINT32 z = 0; z < depth; z++)
+		{
+			UINT32 zArrayIdx = z * width * height;
+			UINT32 zDataIdx = z * slicePitch * pixelSize;
+
+			for (UINT32 y = 0; y < height; y++)
+			{
+				UINT32 yArrayIdx = y * width;
+				UINT32 yDataIdx = y * rowPitch * pixelSize;
+
+				for (UINT32 x = 0; x < width; x++)
+				{
+					UINT32 arrayIdx = x + yArrayIdx + zArrayIdx;
+					UINT32 dataIdx = x * pixelSize + yDataIdx + zDataIdx;
+
+					UINT8* dest = data + dataIdx;
+					*dest = mono_array_get(value, char, arrayIdx);
+				}
+			}
+		}
+	}
+
+	void ScriptPixelData::internal_getExtents(ScriptPixelData* thisPtr, PixelVolume* value)
+	{
+		*value = thisPtr->mPixelData->getExtents();
+	}
+
+	void ScriptPixelData::internal_getFormat(ScriptPixelData* thisPtr, PixelFormat* value)
+	{
+		*value = thisPtr->mPixelData->getFormat();
+	}
+
+	void ScriptPixelData::internal_getRowPitch(ScriptPixelData* thisPtr, int* value)
+	{
+		*value = thisPtr->mPixelData->getRowPitch();
+	}
+
+	void ScriptPixelData::internal_getSlicePitch(ScriptPixelData* thisPtr, int* value)
+	{
+		*value = thisPtr->mPixelData->getSlicePitch();
+	}
+
+	void ScriptPixelData::internal_getSize(ScriptPixelData* thisPtr, int* value)
+	{
+		*value = thisPtr->mPixelData->getSize();
+	}
+
+	void ScriptPixelData::internal_getIsConsecutive(ScriptPixelData* thisPtr, bool* value)
+	{
+		*value = thisPtr->mPixelData->isConsecutive();
+	}
+
+	bool ScriptPixelData::checkIsLocked(ScriptPixelData* thisPtr)
+	{
+		if (thisPtr->mPixelData->isLocked())
+		{
+			LOGWRN("Attempting to access a locked pixel data buffer.");
+			return true;
+		}
+
+		return false;
+	}
 }

+ 138 - 138
SBansheeEngine/Source/BsScriptPixelUtility.cpp

@@ -1,139 +1,139 @@
-#include "BsScriptPixelUtility.h"
-#include "BsMonoManager.h"
-#include "BsMonoClass.h"
-#include "BsMonoUtil.h"
-#include "BsDebug.h"
-#include "BsScriptPixelData.h"
-
-namespace BansheeEngine
-{
-	ScriptPixelUtility::ScriptPixelUtility(MonoObject* instance)
-		:ScriptObject(instance)
-	{ }
-
-	void ScriptPixelUtility::initRuntimeData()
-	{
-		metaData.scriptClass->addInternalCall("Internal_GetMemorySize", &ScriptPixelUtility::internal_getMemorySize);
-		metaData.scriptClass->addInternalCall("Internal_HasAlpha", &ScriptPixelUtility::internal_hasAlpha);
-		metaData.scriptClass->addInternalCall("Internal_IsFloatingPoint", &ScriptPixelUtility::internal_isFloatingPoint);
-		metaData.scriptClass->addInternalCall("Internal_IsCompressed", &ScriptPixelUtility::internal_isCompressed);
-		metaData.scriptClass->addInternalCall("Internal_IsDepth", &ScriptPixelUtility::internal_isDepth);
-		metaData.scriptClass->addInternalCall("Internal_GetMaxMipmaps", &ScriptPixelUtility::internal_getMaxMipmaps);
-		metaData.scriptClass->addInternalCall("Internal_ConvertFormat", &ScriptPixelUtility::internal_convertFormat);
-		metaData.scriptClass->addInternalCall("Internal_Compress", &ScriptPixelUtility::internal_compress);
-		metaData.scriptClass->addInternalCall("Internal_GenerateMipmaps", &ScriptPixelUtility::internal_generateMipmaps);
-		metaData.scriptClass->addInternalCall("Internal_Scale", &ScriptPixelUtility::internal_scale);
-		metaData.scriptClass->addInternalCall("Internal_ApplyGamma", &ScriptPixelUtility::internal_applyGamma);
-	}
-
-	void ScriptPixelUtility::internal_getMemorySize(UINT32 width, UINT32 height, UINT32 depth, PixelFormat format, UINT32* value)
-	{
-		*value = PixelUtil::getMemorySize(width, height, depth, format);
-	}
-
-	void ScriptPixelUtility::internal_hasAlpha(PixelFormat format, bool* value)
-	{
-		*value = PixelUtil::hasAlpha(format);
-	}
-
-	void ScriptPixelUtility::internal_isFloatingPoint(PixelFormat format, bool* value)
-	{
-		*value = PixelUtil::isFloatingPoint(format);
-	}
-
-	void ScriptPixelUtility::internal_isCompressed(PixelFormat format, bool* value)
-	{
-		*value = PixelUtil::isCompressed(format);
-	}
-
-	void ScriptPixelUtility::internal_isDepth(PixelFormat format, bool* value)
-	{
-		*value = PixelUtil::isDepth(format);
-	}
-
-	void ScriptPixelUtility::internal_getMaxMipmaps(UINT32 width, UINT32 height, UINT32 depth, PixelFormat format, UINT32* value)
-	{
-		*value = PixelUtil::getMaxMipmaps(width, height, depth, format);
-	}
-
-	MonoObject* ScriptPixelUtility::internal_convertFormat(MonoObject* source, PixelFormat newFormat)
-	{
-		ScriptPixelData* sourceScriptPixelData = ScriptPixelData::toNative(source);
-		if (sourceScriptPixelData == nullptr)
-			return nullptr;
-
-		PixelDataPtr sourcePixelData = sourceScriptPixelData->getInternalValue();
-		PixelDataPtr outputData = bs_shared_ptr_new<PixelData>(sourcePixelData->getWidth(), sourcePixelData->getHeight(), 
-			sourcePixelData->getDepth(), newFormat);
-		outputData->allocateInternalBuffer();
-
-		PixelUtil::bulkPixelConversion(*sourcePixelData, *outputData);
-
-		return ScriptPixelData::create(outputData);
-	}
-
-	MonoObject* ScriptPixelUtility::internal_compress(MonoObject* source, CompressionOptions options)
-	{
-		ScriptPixelData* sourceScriptPixelData = ScriptPixelData::toNative(source);
-		if (sourceScriptPixelData == nullptr)
-			return nullptr;
-
-		PixelDataPtr sourcePixelData = sourceScriptPixelData->getInternalValue();
-		PixelDataPtr outputData = bs_shared_ptr_new<PixelData>(sourcePixelData->getWidth(), sourcePixelData->getHeight(), 
-			sourcePixelData->getDepth(), options.format);
-		outputData->allocateInternalBuffer();
-
-		PixelUtil::compress(*sourcePixelData, *outputData, options);
-
-		return ScriptPixelData::create(outputData);
-	}
-
-	MonoArray* ScriptPixelUtility::internal_generateMipmaps(MonoObject* source, MipMapGenOptions options)
-	{
-		ScriptPixelData* sourceScriptPixelData = ScriptPixelData::toNative(source);
-		if (sourceScriptPixelData == nullptr)
-			return nullptr;
-
-		PixelDataPtr sourcePixelData = sourceScriptPixelData->getInternalValue();
-		Vector<PixelDataPtr> mipmaps = PixelUtil::genMipmaps(*sourcePixelData, options);
-
-		UINT32 numElements = (UINT32)mipmaps.size();
-		MonoArray* outputArray = mono_array_new(MonoManager::instance().getDomain(),
-			ScriptPixelData::getMetaData()->scriptClass->_getInternalClass(), numElements);
-
-		for (UINT32 i = 0; i < numElements; i++)
-		{
-			MonoObject* managedPixelData = ScriptPixelData::create(mipmaps[i]);
-
-			mono_array_set(outputArray, MonoObject*, i, managedPixelData);
-		}
-
-		return outputArray;
-	}
-
-	MonoObject* ScriptPixelUtility::internal_scale(MonoObject* source, PixelVolume newSize, PixelUtil::Filter filter)
-	{
-		ScriptPixelData* sourceScriptPixelData = ScriptPixelData::toNative(source);
-		if (sourceScriptPixelData == nullptr)
-			return nullptr;
-
-		PixelDataPtr sourcePixelData = sourceScriptPixelData->getInternalValue();
-		PixelDataPtr outputData = bs_shared_ptr_new<PixelData>(sourcePixelData->getWidth(), sourcePixelData->getHeight(),
-			sourcePixelData->getDepth(), sourcePixelData->getFormat());
-		outputData->allocateInternalBuffer();
-
-		PixelUtil::scale(*sourcePixelData, *outputData, filter);
-
-		return ScriptPixelData::create(outputData);
-	}
-
-	void ScriptPixelUtility::internal_applyGamma(MonoObject* source, float gamma)
-	{
-		ScriptPixelData* sourceScriptPixelData = ScriptPixelData::toNative(source);
-		if (sourceScriptPixelData == nullptr)
-			return;
-
-		PixelDataPtr pixelData = sourceScriptPixelData->getInternalValue();
-		PixelUtil::applyGamma(pixelData->getData(), gamma, pixelData->getSize(), PixelUtil::getNumElemBits(pixelData->getFormat()));
-	}
+#include "BsScriptPixelUtility.h"
+#include "BsMonoManager.h"
+#include "BsMonoClass.h"
+#include "BsMonoUtil.h"
+#include "BsDebug.h"
+#include "BsScriptPixelData.h"
+
+namespace BansheeEngine
+{
+	ScriptPixelUtility::ScriptPixelUtility(MonoObject* instance)
+		:ScriptObject(instance)
+	{ }
+
+	void ScriptPixelUtility::initRuntimeData()
+	{
+		metaData.scriptClass->addInternalCall("Internal_GetMemorySize", &ScriptPixelUtility::internal_getMemorySize);
+		metaData.scriptClass->addInternalCall("Internal_HasAlpha", &ScriptPixelUtility::internal_hasAlpha);
+		metaData.scriptClass->addInternalCall("Internal_IsFloatingPoint", &ScriptPixelUtility::internal_isFloatingPoint);
+		metaData.scriptClass->addInternalCall("Internal_IsCompressed", &ScriptPixelUtility::internal_isCompressed);
+		metaData.scriptClass->addInternalCall("Internal_IsDepth", &ScriptPixelUtility::internal_isDepth);
+		metaData.scriptClass->addInternalCall("Internal_GetMaxMipmaps", &ScriptPixelUtility::internal_getMaxMipmaps);
+		metaData.scriptClass->addInternalCall("Internal_ConvertFormat", &ScriptPixelUtility::internal_convertFormat);
+		metaData.scriptClass->addInternalCall("Internal_Compress", &ScriptPixelUtility::internal_compress);
+		metaData.scriptClass->addInternalCall("Internal_GenerateMipmaps", &ScriptPixelUtility::internal_generateMipmaps);
+		metaData.scriptClass->addInternalCall("Internal_Scale", &ScriptPixelUtility::internal_scale);
+		metaData.scriptClass->addInternalCall("Internal_ApplyGamma", &ScriptPixelUtility::internal_applyGamma);
+	}
+
+	void ScriptPixelUtility::internal_getMemorySize(UINT32 width, UINT32 height, UINT32 depth, PixelFormat format, UINT32* value)
+	{
+		*value = PixelUtil::getMemorySize(width, height, depth, format);
+	}
+
+	void ScriptPixelUtility::internal_hasAlpha(PixelFormat format, bool* value)
+	{
+		*value = PixelUtil::hasAlpha(format);
+	}
+
+	void ScriptPixelUtility::internal_isFloatingPoint(PixelFormat format, bool* value)
+	{
+		*value = PixelUtil::isFloatingPoint(format);
+	}
+
+	void ScriptPixelUtility::internal_isCompressed(PixelFormat format, bool* value)
+	{
+		*value = PixelUtil::isCompressed(format);
+	}
+
+	void ScriptPixelUtility::internal_isDepth(PixelFormat format, bool* value)
+	{
+		*value = PixelUtil::isDepth(format);
+	}
+
+	void ScriptPixelUtility::internal_getMaxMipmaps(UINT32 width, UINT32 height, UINT32 depth, PixelFormat format, UINT32* value)
+	{
+		*value = PixelUtil::getMaxMipmaps(width, height, depth, format);
+	}
+
+	MonoObject* ScriptPixelUtility::internal_convertFormat(MonoObject* source, PixelFormat newFormat)
+	{
+		ScriptPixelData* sourceScriptPixelData = ScriptPixelData::toNative(source);
+		if (sourceScriptPixelData == nullptr)
+			return nullptr;
+
+		PixelDataPtr sourcePixelData = sourceScriptPixelData->getInternalValue();
+		PixelDataPtr outputData = bs_shared_ptr_new<PixelData>(sourcePixelData->getWidth(), sourcePixelData->getHeight(), 
+			sourcePixelData->getDepth(), newFormat);
+		outputData->allocateInternalBuffer();
+
+		PixelUtil::bulkPixelConversion(*sourcePixelData, *outputData);
+
+		return ScriptPixelData::create(outputData);
+	}
+
+	MonoObject* ScriptPixelUtility::internal_compress(MonoObject* source, CompressionOptions* options)
+	{
+		ScriptPixelData* sourceScriptPixelData = ScriptPixelData::toNative(source);
+		if (sourceScriptPixelData == nullptr)
+			return nullptr;
+
+		PixelDataPtr sourcePixelData = sourceScriptPixelData->getInternalValue();
+		PixelDataPtr outputData = bs_shared_ptr_new<PixelData>(sourcePixelData->getWidth(), sourcePixelData->getHeight(), 
+			sourcePixelData->getDepth(), options->format);
+		outputData->allocateInternalBuffer();
+
+		PixelUtil::compress(*sourcePixelData, *outputData, *options);
+
+		return ScriptPixelData::create(outputData);
+	}
+
+	MonoArray* ScriptPixelUtility::internal_generateMipmaps(MonoObject* source, MipMapGenOptions* options)
+	{
+		ScriptPixelData* sourceScriptPixelData = ScriptPixelData::toNative(source);
+		if (sourceScriptPixelData == nullptr)
+			return nullptr;
+
+		PixelDataPtr sourcePixelData = sourceScriptPixelData->getInternalValue();
+		Vector<PixelDataPtr> mipmaps = PixelUtil::genMipmaps(*sourcePixelData, *options);
+
+		UINT32 numElements = (UINT32)mipmaps.size();
+		MonoArray* outputArray = mono_array_new(MonoManager::instance().getDomain(),
+			ScriptPixelData::getMetaData()->scriptClass->_getInternalClass(), numElements);
+
+		for (UINT32 i = 0; i < numElements; i++)
+		{
+			MonoObject* managedPixelData = ScriptPixelData::create(mipmaps[i]);
+
+			mono_array_set(outputArray, MonoObject*, i, managedPixelData);
+		}
+
+		return outputArray;
+	}
+
+	MonoObject* ScriptPixelUtility::internal_scale(MonoObject* source, PixelVolume* newSize, PixelUtil::Filter filter)
+	{
+		ScriptPixelData* sourceScriptPixelData = ScriptPixelData::toNative(source);
+		if (sourceScriptPixelData == nullptr)
+			return nullptr;
+
+		PixelDataPtr sourcePixelData = sourceScriptPixelData->getInternalValue();
+		PixelDataPtr outputData = bs_shared_ptr_new<PixelData>(newSize->getWidth(), newSize->getHeight(),
+			newSize->getDepth(), sourcePixelData->getFormat());
+		outputData->allocateInternalBuffer();
+
+		PixelUtil::scale(*sourcePixelData, *outputData, filter);
+
+		return ScriptPixelData::create(outputData);
+	}
+
+	void ScriptPixelUtility::internal_applyGamma(MonoObject* source, float gamma)
+	{
+		ScriptPixelData* sourceScriptPixelData = ScriptPixelData::toNative(source);
+		if (sourceScriptPixelData == nullptr)
+			return;
+
+		PixelDataPtr pixelData = sourceScriptPixelData->getInternalValue();
+		PixelUtil::applyGamma(pixelData->getData(), gamma, pixelData->getSize(), PixelUtil::getNumElemBits(pixelData->getFormat()));
+	}
 }

+ 26 - 26
SBansheeEngine/Source/BsScriptSceneObject.cpp

@@ -240,34 +240,34 @@ namespace BansheeEngine
 			*value = Vector3();
 	}
 
-	void ScriptSceneObject::internal_setPosition(ScriptSceneObject* nativeInstance, Vector3 value)
+	void ScriptSceneObject::internal_setPosition(ScriptSceneObject* nativeInstance, Vector3* value)
 	{
 		if (!checkIfDestroyed(nativeInstance))
-			nativeInstance->mSceneObject->setWorldPosition(value);
+			nativeInstance->mSceneObject->setWorldPosition(*value);
 	}
 
-	void ScriptSceneObject::internal_setLocalPosition(ScriptSceneObject* nativeInstance, Vector3 value)
+	void ScriptSceneObject::internal_setLocalPosition(ScriptSceneObject* nativeInstance, Vector3* value)
 	{
 		if (!checkIfDestroyed(nativeInstance))
-			nativeInstance->mSceneObject->setPosition(value);
+			nativeInstance->mSceneObject->setPosition(*value);
 	}
 
-	void ScriptSceneObject::internal_setRotation(ScriptSceneObject* nativeInstance, Quaternion value)
+	void ScriptSceneObject::internal_setRotation(ScriptSceneObject* nativeInstance, Quaternion* value)
 	{
 		if (!checkIfDestroyed(nativeInstance))
-			nativeInstance->mSceneObject->setWorldRotation(value);
+			nativeInstance->mSceneObject->setWorldRotation(*value);
 	}
 
-	void ScriptSceneObject::internal_setLocalRotation(ScriptSceneObject* nativeInstance, Quaternion value)
+	void ScriptSceneObject::internal_setLocalRotation(ScriptSceneObject* nativeInstance, Quaternion* value)
 	{
 		if (!checkIfDestroyed(nativeInstance))
-			nativeInstance->mSceneObject->setRotation(value);
+			nativeInstance->mSceneObject->setRotation(*value);
 	}
 
-	void ScriptSceneObject::internal_setLocalScale(ScriptSceneObject* nativeInstance, Vector3 value)
+	void ScriptSceneObject::internal_setLocalScale(ScriptSceneObject* nativeInstance, Vector3* value)
 	{
 		if (!checkIfDestroyed(nativeInstance))
-			nativeInstance->mSceneObject->setScale(value);
+			nativeInstance->mSceneObject->setScale(*value);
 	}
 
 	void ScriptSceneObject::internal_getLocalTransform(ScriptSceneObject* nativeInstance, Matrix4* value)
@@ -286,52 +286,52 @@ namespace BansheeEngine
 			*value = Matrix4();
 	}
 
-	void ScriptSceneObject::internal_lookAt(ScriptSceneObject* nativeInstance, Vector3 direction, Vector3 up)
+	void ScriptSceneObject::internal_lookAt(ScriptSceneObject* nativeInstance, Vector3* direction, Vector3* up)
 	{
 		if (!checkIfDestroyed(nativeInstance))
-			nativeInstance->mSceneObject->lookAt(direction, up);
+			nativeInstance->mSceneObject->lookAt(*direction, *up);
 	}
 
-	void ScriptSceneObject::internal_move(ScriptSceneObject* nativeInstance, Vector3 value)
+	void ScriptSceneObject::internal_move(ScriptSceneObject* nativeInstance, Vector3* value)
 	{
 		if (!checkIfDestroyed(nativeInstance))
-			nativeInstance->mSceneObject->move(value);
+			nativeInstance->mSceneObject->move(*value);
 	}
 
-	void ScriptSceneObject::internal_moveLocal(ScriptSceneObject* nativeInstance, Vector3 value)
+	void ScriptSceneObject::internal_moveLocal(ScriptSceneObject* nativeInstance, Vector3* value)
 	{
 		if (!checkIfDestroyed(nativeInstance))
-			nativeInstance->mSceneObject->moveRelative(value);
+			nativeInstance->mSceneObject->moveRelative(*value);
 	}
 
-	void ScriptSceneObject::internal_rotate(ScriptSceneObject* nativeInstance, Quaternion value)
+	void ScriptSceneObject::internal_rotate(ScriptSceneObject* nativeInstance, Quaternion* value)
 	{
 		if (!checkIfDestroyed(nativeInstance))
-			nativeInstance->mSceneObject->rotate(value);
+			nativeInstance->mSceneObject->rotate(*value);
 	}
 
-	void ScriptSceneObject::internal_roll(ScriptSceneObject* nativeInstance, Radian value)
+	void ScriptSceneObject::internal_roll(ScriptSceneObject* nativeInstance, Radian* value)
 	{
 		if (!checkIfDestroyed(nativeInstance))
-			nativeInstance->mSceneObject->roll(value);
+			nativeInstance->mSceneObject->roll(*value);
 	}
 
-	void ScriptSceneObject::internal_yaw(ScriptSceneObject* nativeInstance, Radian value)
+	void ScriptSceneObject::internal_yaw(ScriptSceneObject* nativeInstance, Radian* value)
 	{
 		if (!checkIfDestroyed(nativeInstance))
-			nativeInstance->mSceneObject->yaw(value);
+			nativeInstance->mSceneObject->yaw(*value);
 	}
 
-	void ScriptSceneObject::internal_pitch(ScriptSceneObject* nativeInstance, Radian value)
+	void ScriptSceneObject::internal_pitch(ScriptSceneObject* nativeInstance, Radian* value)
 	{
 		if (!checkIfDestroyed(nativeInstance))
-			nativeInstance->mSceneObject->pitch(value);
+			nativeInstance->mSceneObject->pitch(*value);
 	}
 
-	void ScriptSceneObject::internal_setForward(ScriptSceneObject* nativeInstance, Vector3 value)
+	void ScriptSceneObject::internal_setForward(ScriptSceneObject* nativeInstance, Vector3* value)
 	{
 		if (!checkIfDestroyed(nativeInstance))
-			nativeInstance->mSceneObject->setForward(value);
+			nativeInstance->mSceneObject->setForward(*value);
 	}
 
 	void ScriptSceneObject::internal_getForward(ScriptSceneObject* nativeInstance, Vector3* value)

+ 6 - 6
SBansheeEngine/Source/BsScriptSpriteTexture.cpp

@@ -39,7 +39,7 @@ namespace BansheeEngine
 		return scriptSpriteTex->getManagedInstance();
 	}
 
-	void ScriptSpriteTexture::internal_createInstance(MonoObject* instance, MonoObject* texture, Vector2 offset, Vector2 scale)
+	void ScriptSpriteTexture::internal_createInstance(MonoObject* instance, MonoObject* texture, Vector2* offset, Vector2* scale)
 	{
 		ScriptTexture2D* scriptTexture = ScriptTexture2D::toNative(texture);
 		ScriptSpriteTexture* scriptInstance;
@@ -50,7 +50,7 @@ namespace BansheeEngine
 		}
 		else
 		{
-			HSpriteTexture spriteTexture = SpriteTexture::create(offset, scale, scriptTexture->getHandle());
+			HSpriteTexture spriteTexture = SpriteTexture::create(*offset, *scale, scriptTexture->getHandle());
 
 			ScriptResourceManager::instance().createScriptResource(instance, spriteTexture, &scriptInstance);
 		}
@@ -97,13 +97,13 @@ namespace BansheeEngine
 		*value = spriteTexture->getOffset();
 	}
 
-	void ScriptSpriteTexture::internal_SetOffset(ScriptSpriteTexture* thisPtr, Vector2 value)
+	void ScriptSpriteTexture::internal_SetOffset(ScriptSpriteTexture* thisPtr, Vector2* value)
 	{
 		HSpriteTexture spriteTexture = thisPtr->getHandle();
 		if (!spriteTexture.isLoaded())
 			return;
 
-		spriteTexture->setOffset(value);
+		spriteTexture->setOffset(*value);
 	}
 
 	void ScriptSpriteTexture::internal_GetScale(ScriptSpriteTexture* thisPtr, Vector2* value)
@@ -118,13 +118,13 @@ namespace BansheeEngine
 		*value = spriteTexture->getScale();
 	}
 
-	void ScriptSpriteTexture::internal_SetScale(ScriptSpriteTexture* thisPtr, Vector2 value)
+	void ScriptSpriteTexture::internal_SetScale(ScriptSpriteTexture* thisPtr, Vector2* value)
 	{
 		HSpriteTexture spriteTexture = thisPtr->getHandle();
 		if (!spriteTexture.isLoaded())
 			return;
 
-		spriteTexture->setScale(value);
+		spriteTexture->setScale(*value);
 	}
 
 	UINT32 ScriptSpriteTexture::internal_GetWidth(ScriptSpriteTexture* thisPtr)

+ 118 - 118
SBansheeEngine/Source/BsScriptVirtualInput.cpp

@@ -1,119 +1,119 @@
-#include "BsScriptVirtualInput.h"
-#include "BsMonoManager.h"
-#include "BsMonoClass.h"
-#include "BsMonoMethod.h"
-#include "BsMonoUtil.h"
-#include "BsVirtualInput.h"
-#include "BsScriptVirtualButton.h"
-#include "BsScriptInputConfiguration.h"
-#include "BsPlayInEditorManager.h"
-
-namespace BansheeEngine
-{
-	ScriptVirtualInput::OnButtonEventThunkDef ScriptVirtualInput::OnButtonUpThunk;
-	ScriptVirtualInput::OnButtonEventThunkDef ScriptVirtualInput::OnButtonDownThunk;
-	ScriptVirtualInput::OnButtonEventThunkDef ScriptVirtualInput::OnButtonHeldThunk;
-
-	HEvent ScriptVirtualInput::OnButtonPressedConn;
-	HEvent ScriptVirtualInput::OnButtonReleasedConn;
-	HEvent ScriptVirtualInput::OnButtonHeldConn;
-
-	ScriptVirtualInput::ScriptVirtualInput(MonoObject* instance)
-		:ScriptObject(instance)
-	{ }
-
-	void ScriptVirtualInput::initRuntimeData()
-	{
-		metaData.scriptClass->addInternalCall("Internal_GetKeyConfig", &ScriptVirtualInput::internal_getKeyConfig);
-		metaData.scriptClass->addInternalCall("Internal_SetKeyConfig", &ScriptVirtualInput::internal_setKeyConfig);
-		metaData.scriptClass->addInternalCall("Internal_IsButtonHeld", &ScriptVirtualInput::internal_isButtonHeld);
-		metaData.scriptClass->addInternalCall("Internal_IsButtonDown", &ScriptVirtualInput::internal_isButtonDown);
-		metaData.scriptClass->addInternalCall("Internal_IsButtonUp", &ScriptVirtualInput::internal_isButtonUp);
-		metaData.scriptClass->addInternalCall("Internal_GetAxisValue", &ScriptVirtualInput::internal_getAxisValue);
-
-		OnButtonUpThunk = (OnButtonEventThunkDef)metaData.scriptClass->getMethodExact("Internal_TriggerButtonDown", "VirtualButton,int")->getThunk();
-		OnButtonDownThunk = (OnButtonEventThunkDef)metaData.scriptClass->getMethodExact("Internal_TriggerButtonUp", "VirtualButton,int")->getThunk();
-		OnButtonHeldThunk = (OnButtonEventThunkDef)metaData.scriptClass->getMethodExact("Internal_TriggerButtonHeld", "VirtualButton,int")->getThunk();
-	}
-
-	void ScriptVirtualInput::startUp()
-	{
-		VirtualInput& input = VirtualInput::instance();
-
-		OnButtonPressedConn = input.onButtonDown.connect(&ScriptVirtualInput::onButtonDown);
-		OnButtonReleasedConn = input.onButtonUp.connect(&ScriptVirtualInput::onButtonUp);
-		OnButtonHeldConn = input.onButtonHeld.connect(&ScriptVirtualInput::onButtonHeld);
-	}
-
-	void ScriptVirtualInput::shutDown()
-	{
-		OnButtonPressedConn.disconnect();
-		OnButtonReleasedConn.disconnect();
-		OnButtonHeldConn.disconnect();
-	}
-
-	void ScriptVirtualInput::onButtonDown(const VirtualButton& btn, UINT32 deviceIdx)
-	{
-		if (PlayInEditorManager::instance().getState() != PlayInEditorState::Playing)
-			return;
-
-		MonoObject* virtualButton = ScriptVirtualButton::box(btn);
-		MonoUtil::invokeThunk(OnButtonDownThunk, virtualButton, deviceIdx);
-	}
-
-	void ScriptVirtualInput::onButtonUp(const VirtualButton& btn, UINT32 deviceIdx)
-	{
-		if (PlayInEditorManager::instance().getState() != PlayInEditorState::Playing)
-			return;
-
-		MonoObject* virtualButton = ScriptVirtualButton::box(btn);
-		MonoUtil::invokeThunk(OnButtonUpThunk, virtualButton, deviceIdx);
-	}
-
-	void ScriptVirtualInput::onButtonHeld(const VirtualButton& btn, UINT32 deviceIdx)
-	{
-		if (PlayInEditorManager::instance().getState() != PlayInEditorState::Playing)
-			return;
-
-		MonoObject* virtualButton = ScriptVirtualButton::box(btn);
-		MonoUtil::invokeThunk(OnButtonHeldThunk, virtualButton, deviceIdx);
-	}
-
-	MonoObject* ScriptVirtualInput::internal_getKeyConfig()
-	{
-		InputConfigurationPtr inputConfig = VirtualInput::instance().getConfiguration();
-
-		ScriptInputConfiguration* scriptInputConfig = ScriptInputConfiguration::getScriptInputConfig(inputConfig);
-		if (scriptInputConfig == nullptr)
-			scriptInputConfig = ScriptInputConfiguration::createScriptInputConfig(inputConfig);
-
-		return scriptInputConfig->getManagedInstance();
-	}
-
-	void ScriptVirtualInput::internal_setKeyConfig(MonoObject* keyConfig)
-	{
-		ScriptInputConfiguration* inputConfig = ScriptInputConfiguration::toNative(keyConfig);
-
-		VirtualInput::instance().setConfiguration(inputConfig->getInternalValue());
-	}
-
-	bool ScriptVirtualInput::internal_isButtonHeld(VirtualButton btn, UINT32 deviceIdx)
-	{
-		return VirtualInput::instance().isButtonHeld(btn, deviceIdx);
-	}
-
-	bool ScriptVirtualInput::internal_isButtonDown(VirtualButton btn, UINT32 deviceIdx)
-	{
-		return VirtualInput::instance().isButtonDown(btn, deviceIdx);
-	}
-
-	bool ScriptVirtualInput::internal_isButtonUp(VirtualButton btn, UINT32 deviceIdx)
-	{
-		return VirtualInput::instance().isButtonUp(btn, deviceIdx);
-	}
-
-	float ScriptVirtualInput::internal_getAxisValue(VirtualAxis axis, UINT32 deviceIdx)
-	{
-		return VirtualInput::instance().getAxisValue(axis, deviceIdx);
-	}
+#include "BsScriptVirtualInput.h"
+#include "BsMonoManager.h"
+#include "BsMonoClass.h"
+#include "BsMonoMethod.h"
+#include "BsMonoUtil.h"
+#include "BsVirtualInput.h"
+#include "BsScriptVirtualButton.h"
+#include "BsScriptInputConfiguration.h"
+#include "BsPlayInEditorManager.h"
+
+namespace BansheeEngine
+{
+	ScriptVirtualInput::OnButtonEventThunkDef ScriptVirtualInput::OnButtonUpThunk;
+	ScriptVirtualInput::OnButtonEventThunkDef ScriptVirtualInput::OnButtonDownThunk;
+	ScriptVirtualInput::OnButtonEventThunkDef ScriptVirtualInput::OnButtonHeldThunk;
+
+	HEvent ScriptVirtualInput::OnButtonPressedConn;
+	HEvent ScriptVirtualInput::OnButtonReleasedConn;
+	HEvent ScriptVirtualInput::OnButtonHeldConn;
+
+	ScriptVirtualInput::ScriptVirtualInput(MonoObject* instance)
+		:ScriptObject(instance)
+	{ }
+
+	void ScriptVirtualInput::initRuntimeData()
+	{
+		metaData.scriptClass->addInternalCall("Internal_GetKeyConfig", &ScriptVirtualInput::internal_getKeyConfig);
+		metaData.scriptClass->addInternalCall("Internal_SetKeyConfig", &ScriptVirtualInput::internal_setKeyConfig);
+		metaData.scriptClass->addInternalCall("Internal_IsButtonHeld", &ScriptVirtualInput::internal_isButtonHeld);
+		metaData.scriptClass->addInternalCall("Internal_IsButtonDown", &ScriptVirtualInput::internal_isButtonDown);
+		metaData.scriptClass->addInternalCall("Internal_IsButtonUp", &ScriptVirtualInput::internal_isButtonUp);
+		metaData.scriptClass->addInternalCall("Internal_GetAxisValue", &ScriptVirtualInput::internal_getAxisValue);
+
+		OnButtonUpThunk = (OnButtonEventThunkDef)metaData.scriptClass->getMethodExact("Internal_TriggerButtonDown", "VirtualButton,int")->getThunk();
+		OnButtonDownThunk = (OnButtonEventThunkDef)metaData.scriptClass->getMethodExact("Internal_TriggerButtonUp", "VirtualButton,int")->getThunk();
+		OnButtonHeldThunk = (OnButtonEventThunkDef)metaData.scriptClass->getMethodExact("Internal_TriggerButtonHeld", "VirtualButton,int")->getThunk();
+	}
+
+	void ScriptVirtualInput::startUp()
+	{
+		VirtualInput& input = VirtualInput::instance();
+
+		OnButtonPressedConn = input.onButtonDown.connect(&ScriptVirtualInput::onButtonDown);
+		OnButtonReleasedConn = input.onButtonUp.connect(&ScriptVirtualInput::onButtonUp);
+		OnButtonHeldConn = input.onButtonHeld.connect(&ScriptVirtualInput::onButtonHeld);
+	}
+
+	void ScriptVirtualInput::shutDown()
+	{
+		OnButtonPressedConn.disconnect();
+		OnButtonReleasedConn.disconnect();
+		OnButtonHeldConn.disconnect();
+	}
+
+	void ScriptVirtualInput::onButtonDown(const VirtualButton& btn, UINT32 deviceIdx)
+	{
+		if (PlayInEditorManager::instance().getState() != PlayInEditorState::Playing)
+			return;
+
+		MonoObject* virtualButton = ScriptVirtualButton::box(btn);
+		MonoUtil::invokeThunk(OnButtonDownThunk, virtualButton, deviceIdx);
+	}
+
+	void ScriptVirtualInput::onButtonUp(const VirtualButton& btn, UINT32 deviceIdx)
+	{
+		if (PlayInEditorManager::instance().getState() != PlayInEditorState::Playing)
+			return;
+
+		MonoObject* virtualButton = ScriptVirtualButton::box(btn);
+		MonoUtil::invokeThunk(OnButtonUpThunk, virtualButton, deviceIdx);
+	}
+
+	void ScriptVirtualInput::onButtonHeld(const VirtualButton& btn, UINT32 deviceIdx)
+	{
+		if (PlayInEditorManager::instance().getState() != PlayInEditorState::Playing)
+			return;
+
+		MonoObject* virtualButton = ScriptVirtualButton::box(btn);
+		MonoUtil::invokeThunk(OnButtonHeldThunk, virtualButton, deviceIdx);
+	}
+
+	MonoObject* ScriptVirtualInput::internal_getKeyConfig()
+	{
+		InputConfigurationPtr inputConfig = VirtualInput::instance().getConfiguration();
+
+		ScriptInputConfiguration* scriptInputConfig = ScriptInputConfiguration::getScriptInputConfig(inputConfig);
+		if (scriptInputConfig == nullptr)
+			scriptInputConfig = ScriptInputConfiguration::createScriptInputConfig(inputConfig);
+
+		return scriptInputConfig->getManagedInstance();
+	}
+
+	void ScriptVirtualInput::internal_setKeyConfig(MonoObject* keyConfig)
+	{
+		ScriptInputConfiguration* inputConfig = ScriptInputConfiguration::toNative(keyConfig);
+
+		VirtualInput::instance().setConfiguration(inputConfig->getInternalValue());
+	}
+
+	bool ScriptVirtualInput::internal_isButtonHeld(VirtualButton* btn, UINT32 deviceIdx)
+	{
+		return VirtualInput::instance().isButtonHeld(*btn, deviceIdx);
+	}
+
+	bool ScriptVirtualInput::internal_isButtonDown(VirtualButton* btn, UINT32 deviceIdx)
+	{
+		return VirtualInput::instance().isButtonDown(*btn, deviceIdx);
+	}
+
+	bool ScriptVirtualInput::internal_isButtonUp(VirtualButton* btn, UINT32 deviceIdx)
+	{
+		return VirtualInput::instance().isButtonUp(*btn, deviceIdx);
+	}
+
+	float ScriptVirtualInput::internal_getAxisValue(VirtualAxis* axis, UINT32 deviceIdx)
+	{
+		return VirtualInput::instance().getAxisValue(*axis, deviceIdx);
+	}
 }