Просмотр исходного кода

AsyncOp & Texture are now auto-generated

BearishSun 8 лет назад
Родитель
Сommit
d4e397920d
37 измененных файлов с 437 добавлено и 720 удалено
  1. 9 5
      Source/BansheeCore/Include/BsCommonTypes.h
  2. 1 1
      Source/BansheeCore/Include/BsMaterial.h
  3. 2 2
      Source/BansheeCore/Include/BsPixelData.h
  4. 2 2
      Source/BansheeCore/Include/BsResourceHandle.h
  5. 24 13
      Source/BansheeCore/Include/BsTexture.h
  6. 3 6
      Source/BansheeEngine/Include/BsPlainTextImporter.h
  7. 0 11
      Source/BansheeEngine/Source/BsPlainTextImporter.cpp
  8. 6 0
      Source/BansheeMono/Include/BsMonoArray.h
  9. 3 0
      Source/BansheeMono/Include/BsMonoUtil.h
  10. 5 0
      Source/BansheeMono/Source/BsMonoUtil.cpp
  11. 7 1
      Source/BansheeUtility/Include/BsAsyncOp.h
  12. 2 2
      Source/BansheeUtility/Include/BsPrerequisitesUtil.h
  13. 7 260
      Source/MBansheeEngine/Rendering/Texture.cs
  14. 2 47
      Source/MBansheeEngine/Utility/AsyncOp.cs
  15. 1 0
      Source/SBansheeEditor/CMakeLists.txt
  16. 2 1
      Source/SBansheeEditor/Source/BsScriptGUITextureField.cpp
  17. 4 4
      Source/SBansheeEngine/CMakeSources.cmake
  18. 44 0
      Source/SBansheeEngine/Include/BsAsyncOpEx.h
  19. 2 0
      Source/SBansheeEngine/Include/BsPixelDataEx.h
  20. 0 49
      Source/SBansheeEngine/Include/BsScriptAsyncOp.h
  21. 0 50
      Source/SBansheeEngine/Include/BsScriptTexture.h
  22. 122 0
      Source/SBansheeEngine/Include/BsTextureEx.h
  23. 36 0
      Source/SBansheeEngine/Source/BsAsyncOpEx.cpp
  24. 2 1
      Source/SBansheeEngine/Source/BsManagedSerializableField.cpp
  25. 2 1
      Source/SBansheeEngine/Source/BsManagedSerializableObjectInfo.cpp
  26. 2 1
      Source/SBansheeEngine/Source/BsScriptAssemblyManager.cpp
  27. 0 69
      Source/SBansheeEngine/Source/BsScriptAsyncOp.cpp
  28. 0 2
      Source/SBansheeEngine/Source/BsScriptCamera.cpp
  29. 2 1
      Source/SBansheeEngine/Source/BsScriptFontBitmap.cpp
  30. 3 2
      Source/SBansheeEngine/Source/BsScriptMaterial.cpp
  31. 2 1
      Source/SBansheeEngine/Source/BsScriptRenderTexture2D.cpp
  32. 2 1
      Source/SBansheeEngine/Source/BsScriptResource.cpp
  33. 2 1
      Source/SBansheeEngine/Source/BsScriptResourceManager.cpp
  34. 2 1
      Source/SBansheeEngine/Source/BsScriptResourceRef.cpp
  35. 2 1
      Source/SBansheeEngine/Source/BsScriptSpriteTexture.cpp
  36. 0 184
      Source/SBansheeEngine/Source/BsScriptTexture.cpp
  37. 132 0
      Source/SBansheeEngine/Source/BsTextureEx.cpp

+ 9 - 5
Source/BansheeCore/Include/BsCommonTypes.h

@@ -332,12 +332,16 @@ namespace bs
 	};
 
 	/**	Available texture types. */
-	enum TextureType
+	enum BS_SCRIPT_EXPORT() TextureType
 	{
-		TEX_TYPE_1D = 1, /**< One dimensional texture. Just a row of pixels. */
-		TEX_TYPE_2D = 2, /**< Two dimensional texture. */
-		TEX_TYPE_3D = 3, /**< Three dimensional texture. */
-		TEX_TYPE_CUBE_MAP = 4 /**< Texture consisting out of six 2D textures describing an inside of a cube. Allows special sampling. */
+		/** One dimensional texture. Just a row of pixels. */
+		TEX_TYPE_1D			BS_SCRIPT_EXPORT(n:Texture1D)	= 1, 
+		/** Two dimensional texture. */
+		TEX_TYPE_2D			BS_SCRIPT_EXPORT(n:Texture2D)	= 2,
+		/** Three dimensional texture. */
+		TEX_TYPE_3D			BS_SCRIPT_EXPORT(n:Texture3D)	= 3,
+		/** Texture consisting out of six 2D textures describing an inside of a cube. Allows special sampling. */
+		TEX_TYPE_CUBE_MAP	BS_SCRIPT_EXPORT(n:TextureCube) = 4 
 	};
 
 	/**	Contains data about a type used for GPU data parameters. */

+ 1 - 1
Source/BansheeCore/Include/BsMaterial.h

@@ -605,7 +605,7 @@ namespace bs
 		/** @copydoc CoreObject::markDependenciesDirty */
 		void _markDependenciesDirty() override;
 
-		/** @copydoc IResourceListener::markResourcesDirty */
+		/** @copydoc IResourceListener::markListenerResourcesDirty */
 		void _markResourcesDirty() override;
 
 		/** @} */

+ 2 - 2
Source/BansheeCore/Include/BsPixelData.h

@@ -14,7 +14,7 @@ namespace bs
 	 */
 
 	/** Pixel formats usable by images, textures and render surfaces. */
-    enum BS_SCRIPT_EXPORT(n:PixelFormat) PixelFormat
+    enum BS_SCRIPT_EXPORT() PixelFormat
     {
         /** Unknown pixel format. */
         PF_UNKNOWN				BS_SCRIPT_EXPORT(ex:true) = 0,
@@ -155,7 +155,7 @@ namespace bs
 	 *
 	 * @see		GpuResourceData
 	 */
-    class BS_CORE_EXPORT BS_SCRIPT_EXPORT(n:PixelData) PixelData : public GpuResourceData
+    class BS_CORE_EXPORT BS_SCRIPT_EXPORT() PixelData : public GpuResourceData
 	{
     public:
 		PixelData();

+ 2 - 2
Source/BansheeCore/Include/BsResourceHandle.h

@@ -135,7 +135,7 @@ namespace bs
 	public:
 		friend class WeakResourceHandleRTTI;
 		static RTTITypeBase* getRTTIStatic();
-		virtual RTTITypeBase* getRTTI() const override;
+		RTTITypeBase* getRTTI() const override;
 	};
 
 	/**	Specialization of TResourceHandleBase for normal (non-weak) handles. */
@@ -165,7 +165,7 @@ namespace bs
 		friend class WeakResourceHandleRTTI;
 		friend class ResourceHandleRTTI;
 		static RTTITypeBase* getRTTIStatic();
-		virtual RTTITypeBase* getRTTI() const override;
+		RTTITypeBase* getRTTI() const override;
 	};
 
 	/** @copydoc ResourceHandleBase */

+ 24 - 13
Source/BansheeCore/Include/BsTexture.h

@@ -15,17 +15,24 @@ namespace bs
 	 */
 
 	/**	Flags that describe how is a texture used. */
-    enum TextureUsage
+    enum BS_SCRIPT_EXPORT() TextureUsage
     {
-		TU_STATIC = GBU_STATIC, /**< A regular texture that is not often or ever updated from the CPU. */
-		TU_DYNAMIC = GBU_DYNAMIC, /**< A regular texture that is often updated by the CPU. */
-		TU_RENDERTARGET = 0x200, /**< Texture that can be rendered to by the GPU. */
-		TU_DEPTHSTENCIL = 0x400, /**< Texture used as a depth/stencil buffer by the GPU. */
-		TU_LOADSTORE = 0x800, /**< Texture that allows load/store operations from the GPU program. */
+		/** A regular texture that is not often or ever updated from the CPU. */
+		TU_STATIC			BS_SCRIPT_EXPORT(n:Default)			= GBU_STATIC, 
+		/** A regular texture that is often updated by the CPU. */
+		TU_DYNAMIC			BS_SCRIPT_EXPORT(n:Dynamic)			= GBU_DYNAMIC,
+		/** Texture that can be rendered to by the GPU. */
+		TU_RENDERTARGET		BS_SCRIPT_EXPORT(n:Render)			= 0x200,
+		/** Texture used as a depth/stencil buffer by the GPU. */
+		TU_DEPTHSTENCIL		BS_SCRIPT_EXPORT(n:DepthStencil)	= 0x400,
+		/** Texture that allows load/store operations from the GPU program. */
+		TU_LOADSTORE		BS_SCRIPT_EXPORT(n:LoadStore)		= 0x800,
 		/** All mesh data will also be cached in CPU memory, making it available for fast read access from the CPU. */
-		TU_CPUCACHED = 0x1000, 
-		TU_CPUREADABLE = 0x2000, /**< Allows the CPU to directly read the texture data buffers from the GPU. */
-		TU_DEFAULT = TU_STATIC
+		TU_CPUCACHED		BS_SCRIPT_EXPORT(n:CPUCached)		= 0x1000,
+		/** Allows the CPU to directly read the texture data buffers from the GPU. */
+		TU_CPUREADABLE		BS_SCRIPT_EXPORT(n:CPUReadable)		= 0x2000,
+		/** Default (most common) texture usage. */
+		TU_DEFAULT			BS_SCRIPT_EXPORT(ex:true)			= TU_STATIC
     };
 
 	/**	Texture mipmap options. */
@@ -87,10 +94,14 @@ namespace bs
          */
         UINT32 getNumMipmaps() const {return mDesc.numMips;}
 
-		/** Gets whether this texture will be set up so that on sampling it, hardware gamma correction is applied. */
+		/** 
+		 * Determines does the texture contain gamma corrected data. If true then the GPU will automatically convert the 
+		 * pixels to linear space before reading from the texture, and convert them to gamma space when writing to the
+		 * texture. 
+		 */
 		bool isHardwareGammaEnabled() const { return mDesc.hwGamma; }
 
-		/**	Gets the number of samples used for multisampling (0 if multisampling is not used). */
+		/**	Gets the number of samples used for multisampling (0 or 1 if multisampling is not used). */
 		UINT32 getNumSamples() const { return mDesc.numSamples; }
 
         /**	Returns the height of the texture.  */
@@ -102,7 +113,7 @@ namespace bs
         /**	Returns the depth of the texture (only applicable for 3D textures). */
         UINT32 getDepth() const { return mDesc.depth; }
 
-        /**	Returns texture usage (TextureUsage) of this texture. */
+        /**	Returns a value that signals the engine in what way is the texture expected to be used. */
         int getUsage() const { return mDesc.usage; }
 
 		/**	Returns the pixel format for the texture surface. */
@@ -153,7 +164,7 @@ namespace bs
 	 *
 	 * @note	Sim thread.
 	 */
-    class BS_CORE_EXPORT Texture : public Resource
+    class BS_CORE_EXPORT BS_SCRIPT_EXPORT() Texture : public Resource
     {
     public:
 		/**

+ 3 - 6
Source/BansheeEngine/Include/BsPlainTextImporter.h

@@ -15,17 +15,14 @@ namespace bs
 	class BS_EXPORT PlainTextImporter : public SpecificImporter
 	{
 	public:
-		PlainTextImporter();
-		virtual ~PlainTextImporter();
-
 		/** @copydoc SpecificImporter::isExtensionSupported */
-		virtual bool isExtensionSupported(const WString& ext) const override;
+		bool isExtensionSupported(const WString& ext) const override;
 
 		/** @copydoc SpecificImporter::isMagicNumberSupported */
-		virtual bool isMagicNumberSupported(const UINT8* magicNumPtr, UINT32 numBytes) const override;
+		bool isMagicNumberSupported(const UINT8* magicNumPtr, UINT32 numBytes) const override;
 
 		/** @copydoc SpecificImporter::import */
-		virtual SPtr<Resource> import(const Path& filePath, SPtr<const ImportOptions> importOptions) override;
+		SPtr<Resource> import(const Path& filePath, SPtr<const ImportOptions> importOptions) override;
 
 		static const WString DEFAULT_EXTENSION;
 	};

+ 0 - 11
Source/BansheeEngine/Source/BsPlainTextImporter.cpp

@@ -7,17 +7,6 @@
 
 namespace bs
 {
-	PlainTextImporter::PlainTextImporter()
-		:SpecificImporter()
-	{
-
-	}
-
-	PlainTextImporter::~PlainTextImporter()
-	{
-
-	}
-
 	bool PlainTextImporter::isExtensionSupported(const WString& ext) const
 	{
 		WString lowerCaseExt = ext;

+ 6 - 0
Source/BansheeMono/Include/BsMonoArray.h

@@ -212,6 +212,12 @@ namespace bs
 		{
 			return ScriptArray(MonoUtil::getBoolClass(), size);
 		}
+
+		template<>
+		inline ScriptArray ScriptArray_create<MonoObject*>(UINT32 size)
+		{
+			return ScriptArray(MonoUtil::getObjectClass(), size);
+		}
 	}
 
 	/** @} */

+ 3 - 0
Source/BansheeMono/Include/BsMonoUtil.h

@@ -116,6 +116,9 @@ namespace bs
 		/** Returns Mono class for a char. */
 		static ::MonoClass* getCharClass();
 
+		/** Returns Mono class for a generic object. */
+		static ::MonoClass* getObjectClass();
+
 		/** @copydoc throwIfException(MonoObject*) */
 		static void throwIfException(MonoException* exception);
 

+ 5 - 0
Source/BansheeMono/Source/BsMonoUtil.cpp

@@ -300,6 +300,11 @@ namespace bs
 		return mono_get_char_class();
 	}
 
+	::MonoClass* MonoUtil::getObjectClass()
+	{
+		return mono_get_object_class();
+	}
+
 	void MonoUtil::throwIfException(MonoException* exception)
 	{
 		throwIfException(reinterpret_cast<MonoObject*>(exception));

+ 7 - 1
Source/BansheeUtility/Include/BsAsyncOp.h

@@ -77,7 +77,7 @@ namespace bs
 			:mSyncData(syncData)
 		{ }
 
-		/** True if the async operation has completed. */
+		/** Returns true if the async operation has completed. */
 		bool hasCompleted() const;
 
 		/**
@@ -102,6 +102,12 @@ namespace bs
 			return any_cast<T>(mData->mReturnValue);
 		}
 
+		/** 
+		 * Retrieves the value returned by the async operation as a generic type. Only valid if hasCompleted() returns 
+		 * true. 
+		 */
+		Any getGenericReturnValue() const { return mData->mReturnValue; }
+
 	public: // ***** INTERNAL ******
 		/** @name Internal 
 		 *  @{

+ 2 - 2
Source/BansheeUtility/Include/BsPrerequisitesUtil.h

@@ -219,8 +219,8 @@
  *
  * Supported options:
  *  - n - Specify a different name for the type in the scripting API (e.g. "n:MyName"). Usable on types and methods.
- *  - v - Specify a different visibility (default is public). Supported values are "public" and "internal". Usable on types
- *		  and methods.
+ *  - v - Specify a different visibility (default is public). Supported values are "public", "internal" and "private". 
+ *		  Usable on types and methods.
  *  - f - Specify the name of the output file(s) for the script object and its potential wrappers. If not specified
  *		  the name of the type will be used for the file. Usable on types only.
  *	- pl - Specify whether the type is plain or not (default is false). Supported values are "true" or "false". Plain 

+ 7 - 260
Source/MBansheeEngine/Rendering/Texture.cs

@@ -9,111 +9,8 @@ namespace BansheeEngine
      *  @{
      */
 
-    /// <summary>
-    /// Base class for all textures. Contains a set of pixels of certain dimensions that can be used for rendering
-    /// or read/written directly.
-    /// </summary>
-    public class Texture : Resource
+    public partial class Texture
     {
-        /// <summary>
-        /// Returns the pixel format for the texture surface.
-        /// </summary>
-        public PixelFormat PixelFormat
-        {
-            get
-            {
-                PixelFormat value;
-                Internal_GetPixelFormat(mCachedPtr, out value);
-                return value;
-            }
-        }
-
-        /// <summary>
-        /// Returns a value that signals the engine in what way is the texture expected to be used.
-        /// </summary>
-        public TextureUsage Usage
-        {
-            get
-            {
-                TextureUsage value;
-                Internal_GetUsage(mCachedPtr, out value);
-                return value;
-            }
-        }
-
-        /// <summary>
-        /// Width of the texture in pixels.
-        /// </summary>
-        public int Width
-        {
-            get
-            {
-                int value;
-                Internal_GetWidth(mCachedPtr, out value);
-                return value;
-            }
-        }
-
-        /// <summary>
-        /// Height of the texture in pixels.
-        /// </summary>
-        public int Height
-        {
-            get
-            {
-                int value;
-                Internal_GetHeight(mCachedPtr, out value);
-                return value;
-            }
-        }
-
-        /// <summary>
-        /// Determines does the texture contain gamma corrected data. If true then the GPU will automatically convert
-        /// the pixels to linear space before reading from the texture, and convert them to gamma space when writing
-        /// to the texture.
-        /// </summary>
-        public bool GammaCorrection
-        {
-            get
-            {
-                bool value;
-                Internal_GetGammaCorrection(mCachedPtr, out value);
-                return value;
-            }
-        }
-
-        /// <summary>
-        /// Number of samples per pixel. Zero or one mean no multisampling will be used.
-        /// </summary>
-        public int SampleCount
-        {
-            get
-            {
-                int value;
-                Internal_GetSampleCount(mCachedPtr, out value);
-                return value;
-            }
-        }
-
-        /// <summary>
-        /// Returns how many mipmap levels does the texture contain.
-        /// </summary>
-        public int MipmapCount
-        {
-            get
-            {
-                int value;
-                Internal_GetMipmapCount(mCachedPtr, out value);
-                return value;
-            }
-        }
-
-        /// <summary>
-        /// Constructor for the internal use by the runtime.
-        /// </summary>
-        private Texture()
-        { }
-
         /// <summary>
         /// Creates a new blank 2D texture.
         /// </summary>
@@ -131,8 +28,8 @@ namespace BansheeEngine
             TextureUsage usage = TextureUsage.Default, int numSamples = 1, bool hasMipmaps = false, 
             bool gammaCorrection = false)
         {
-            Texture texture = new Texture();
-            Internal_CreateInstance(texture, format, width, height, 1, TextureType.Texture2D, usage, numSamples,
+            Texture texture = new Texture(true);
+            Internal_create(texture, format, width, height, 1, TextureType.Texture2D, usage, numSamples,
                 hasMipmaps, gammaCorrection);
 
             return texture;
@@ -151,8 +48,8 @@ namespace BansheeEngine
         public static Texture Create3D(int width, int height, int depth, PixelFormat format = PixelFormat.R8G8B8A8,
             TextureUsage usage = TextureUsage.Default, bool hasMipmaps = false)
         {
-            Texture texture = new Texture();
-            Internal_CreateInstance(texture, format, width, height, depth, TextureType.Texture3D, usage, 1,
+            Texture texture = new Texture(true);
+            Internal_create(texture, format, width, height, depth, TextureType.Texture3D, usage, 1,
                 hasMipmaps, false);
 
             return texture;
@@ -172,152 +69,12 @@ namespace BansheeEngine
         public static Texture CreateCube(int size, PixelFormat format = PixelFormat.R8G8B8A8,
             TextureUsage usage = TextureUsage.Default, bool hasMipmaps = false, bool gammaCorrection = false)
         {
-            Texture texture = new Texture();
-            Internal_CreateInstance(texture, format, size, size, 1, TextureType.TextureCube, usage, 1,
+            Texture texture = new Texture(true);
+            Internal_create(texture, format, size, size, 1, TextureType.TextureCube, usage, 1,
                 hasMipmaps, gammaCorrection);
 
             return texture;
         }
-
-        /// <summary>
-        /// Returns pixels for the specified mip level & face. Pixels will be read from system memory, which means the
-        /// texture has to be created with <see cref="TextureUsage.CPUCached"/>. If the texture was updated from the GPU the
-        /// pixels retrieved from this method will not reflect that, and you should use <see cref="GetGPUPixels"/> instead.
-        /// </summary>
-        /// <param name="mipLevel">Mip level to retrieve pixels for. Top level (0) is the highest quality.</param>
-        /// <param name="face">Face to read the pixels from. Cubemap textures have six faces whose face indices are as
-        ///                    specified in the <see cref="CubeFace"/> enum. Array textures can have an arbitrary number
-        ///                    of faces (if it's a cubemap array it has to be a multiple of 6).</param>
-        /// <returns>A set of pixels for the specified mip level.</returns>
-        public PixelData GetPixels(int mipLevel = 0, int face = 0)
-        {
-            return Internal_GetPixels(mCachedPtr, face, mipLevel);
-        }
-
-        /// <summary>
-        /// Sets pixels for the specified mip level and face.
-        /// </summary>
-        /// <param name="data">Pixels to assign to the specified mip level. Pixel data must match the mip level size
-        ///                    and texture pixel format.</param>
-        /// <param name="mipLevel">Mip level to set pixels for. Top level (0) is the highest quality.</param>
-        /// <param name="face">Face to set pixels for. Cubemap textures have six faces whose face indices are as
-        ///                    specified in the <see cref="CubeFace"/> enum. Array textures can have an arbitrary number
-        ///                    of faces (if it's a cubemap array it has to be a multiple of 6).</param>
-        public void SetPixels(PixelData data, int mipLevel = 0, int face = 0)
-        {
-            Internal_SetPixels(mCachedPtr, data, face, mipLevel);
-        }
-
-        /// <summary>
-        /// Sets pixels for the specified mip level and face.
-        /// </summary>
-        /// <param name="data">Pixels to assign to the specified mip level. Size of the array must match the mip level
-        ///                    dimensions. Data is expected to be laid out row by row. Pixels will be automatically
-        ///                    converted to the valid pixel format.</param>
-        /// <param name="mipLevel">Mip level to set pixels for. Top level (0) is the highest quality.</param>
-        /// <param name="face">Face to set pixels for. Cubemap textures have six faces whose face indices are as
-        ///                    specified in the <see cref="CubeFace"/> enum. Array textures can have an arbitrary number
-        ///                    of faces (if it's a cubemap array it has to be a multiple of 6).</param>
-        public void SetPixels(Color[] data, int mipLevel = 0, int face = 0)
-        {
-            Internal_SetPixelsArray(mCachedPtr, data, face, mipLevel);
-        }
-
-        /// <summary>
-        /// Reads texture pixels directly from the GPU. This is similar to <see cref="GetPixels"/> but the texture doesn't
-        /// need to be created with <see cref="TextureUsage.CPUCached"/>, and the data will contain any updates performed by
-        /// the GPU. This method can be potentially slow as it introduces a CPU-GPU synchronization point. Additionally
-        /// this method is asynchronous which means the data is not available immediately.
-        /// </summary>
-        /// <param name="mipLevel">Mip level to retrieve pixels for. Top level (0) is the highest quality.</param>
-        /// <param name="face">Face to read the pixels from. Cubemap textures have six faces whose face indices are as
-        ///                    specified in the <see cref="CubeFace"/> enum. Array textures can have an arbitrary number
-        ///                    of faces (if it's a cubemap array it has to be a multiple of 6).</param>
-        /// <returns><see cref="AsyncOp"/> object that will contain <see cref="PixelData"/> object when the operation 
-        ///          completes.</returns>
-        public AsyncOp GetGPUPixels(int mipLevel = 0, int face = 0)
-        {
-            return Internal_GetGPUPixels(mCachedPtr, face, mipLevel);
-        }
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_GetPixelFormat(IntPtr thisPtr, out PixelFormat value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_GetUsage(IntPtr thisPtr, out TextureUsage value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_GetWidth(IntPtr thisPtr, out int value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_GetHeight(IntPtr thisPtr, out int value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_GetGammaCorrection(IntPtr thisPtr, out bool value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_GetSampleCount(IntPtr thisPtr, out int value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_GetMipmapCount(IntPtr thisPtr, out int value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_CreateInstance(Texture instance, PixelFormat format, int width,
-            int height, int depth, TextureType texType, TextureUsage usage, int numSamples, bool hasMipmaps, 
-            bool gammaCorrection);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern PixelData Internal_GetPixels(IntPtr thisPtr, int face, int mipLevel);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern AsyncOp Internal_GetGPUPixels(IntPtr thisPtr, int face, int mipLevel);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetPixels(IntPtr thisPtr, PixelData data, int face, int mipLevel);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_SetPixelsArray(IntPtr thisPtr, Color[] data, int face, int mipLevel);
-    }
-
-    /// <summary>
-    /// Flags that describe how is a texture used.
-    /// </summary>
-    public enum TextureUsage // Note: Must match C++ enum TextureUsage
-    {
-        /// <summary>
-        /// A regular texture that is not often or ever updated from the CPU.
-        /// </summary>
-        Default = 0x1,
-
-        /// <summary>
-        /// A regular texture that is often updated by the CPU.
-        /// </summary>
-        Dynamic = 0x2,
-
-        /// <summary>
-        /// Texture that can be rendered to by the GPU.
-        /// </summary>
-        Render = 0x200,
-
-        /// <summary>
-        /// Texture used as a depth/stencil buffer by the GPU.
-        /// </summary>
-        DepthStencil = 0x400,
-
-        /// <summary>
-        /// Texture that allows load/store operations from the GPU program.
-        /// </summary>
-        LoadStore = 0x800,
-
-        /// <summary>
-        /// All mesh data will also be cached in CPU memory, making it available for fast read access from the CPU.
-        /// </summary>
-        CPUCached = 0x1000,
-
-        /// <summary>
-        /// Allows the CPU to directly read the texture data buffers from the GPU.
-        /// </summary>
-        CPUReadable = 0x2000,
     }
 
     /// <summary>
@@ -333,15 +90,5 @@ namespace BansheeEngine
         NegativeZ = 5,
     }
 
-    /// <summary>
-    /// Supported texture types.
-    /// </summary>
-    internal enum TextureType // Note: Must match C++ enum TextureType
-    {
-        Texture2D = 2,
-        Texture3D = 3,
-        TextureCube = 4
-    }
-
     /** @} */
 }

+ 2 - 47
Source/MBansheeEngine/Utility/AsyncOp.cs

@@ -9,33 +9,8 @@ namespace BansheeEngine
      *  @{
      */
 
-    /// <summary>
-    /// Object you may use to check on the results of an asynchronous operation. Contains uninitialized data until 
-    /// <see cref="IsCompleted"/> returns true.
-    /// </summary>
-    public class AsyncOp : ScriptObject
+    public partial class AsyncOp
     {
-        /// <summary>
-        /// Constructs a new async operation.
-        /// </summary>
-        internal AsyncOp() // Note: For internal runtime use only
-        {
-            Internal_CreateInstance(this);
-        }
-
-        /// <summary>
-        /// Checks has the asynchronous operation completed.
-        /// </summary>
-        public bool IsCompleted
-        {
-            get
-            {
-                bool value;
-                Internal_IsComplete(mCachedPtr, out value);
-                return value;
-            }
-        }
-
         /// <summary>
         /// Retrieves the value returned by the async operation. Only valid if <see cref="IsCompleted"/> returns true.
         /// </summary>
@@ -43,28 +18,8 @@ namespace BansheeEngine
         /// <returns>Return value of the async operation.</returns>
         public T GetReturnValue<T>()
         {
-            return (T)Internal_GetReturnValue(mCachedPtr);
+            return (T)Internal_getReturnValue(mCachedPtr);
         }
-
-        /// <summary>
-        /// Blocks the calling thread until asynchronous operation completes.
-        /// </summary>
-        public void BlockUntilComplete()
-        {
-            Internal_BlockUntilComplete(mCachedPtr);
-        }
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        internal static extern void Internal_CreateInstance(AsyncOp managedInstance);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        internal static extern void Internal_IsComplete(IntPtr thisPtr, out bool value);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        internal static extern object Internal_GetReturnValue(IntPtr thisPtr);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        internal static extern void Internal_BlockUntilComplete(IntPtr thisPtr);
     }
 
     /** @} */

+ 1 - 0
Source/SBansheeEditor/CMakeLists.txt

@@ -13,6 +13,7 @@ set(SBansheeEditor_INC
 	"../BansheeEditor/Include"
 	"../BansheeMono/Include"
 	"../SBansheeEngine/Include"
+	"${PROJECT_BINARY_DIR}/Generated/Engine/Include"
 	"${PROJECT_BINARY_DIR}/Generated/Editor/Include")
 
 include_directories(${SBansheeEditor_INC})	

+ 2 - 1
Source/SBansheeEditor/Source/BsScriptGUITextureField.cpp

@@ -10,10 +10,11 @@
 #include "BsGUIOptions.h"
 #include "BsGUIContent.h"
 #include "BsScriptGUIContent.h"
-#include "BsScriptTexture.h"
 #include "BsScriptResourceManager.h"
 #include "BsScriptResourceRef.h"
 
+#include "BsScriptTexture.generated.h"
+
 using namespace std::placeholders;
 
 namespace bs

+ 4 - 4
Source/SBansheeEngine/CMakeSources.cmake

@@ -77,7 +77,6 @@ set(BS_SBANSHEEENGINE_SRC_WRAPPERS_PHYSICS
 )
 
 set(BS_SBANSHEEENGINE_INC_WRAPPERS
-	"Include/BsScriptAsyncOp.h"
 	"Include/BsScriptBoneWeight.h"
 	"Include/BsScriptBuiltin.h"
 	"Include/BsScriptCamera.h"
@@ -115,7 +114,6 @@ set(BS_SBANSHEEENGINE_INC_WRAPPERS
 	"Include/BsScriptVector2I.h"
 	"Include/BsScriptVector.h"
 	"Include/BsScriptTime.h"
-	"Include/BsScriptTexture.h"
 	"Include/BsScriptStringTable.h"
 	"Include/BsScriptSpriteTexture.h"
 	"Include/BsScriptShaderInclude.h"
@@ -211,7 +209,6 @@ set(BS_SBANSHEEENGINE_SRC_SERIALIZATION
 )
 
 set(BS_SBANSHEEENGINE_SRC_WRAPPERS
-	"Source/BsScriptAsyncOp.cpp"
 	"Source/BsScriptBoneWeight.cpp"
 	"Source/BsScriptBuiltin.cpp"
 	"Source/BsScriptCamera.cpp"
@@ -244,7 +241,6 @@ set(BS_SBANSHEEENGINE_SRC_WRAPPERS
 	"Source/BsScriptVector2I.cpp"
 	"Source/BsScriptVector.cpp"
 	"Source/BsScriptTime.cpp"
-	"Source/BsScriptTexture.cpp"
 	"Source/BsScriptStringTable.cpp"
 	"Source/BsScriptSpriteTexture.cpp"
 	"Source/BsScriptShaderInclude.cpp"
@@ -317,10 +313,14 @@ set(BS_SBANSHEEENGINE_INC_RTTI
 
 set(BS_SBANSHEEENGINE_INC_EXTENSIONS
 	"Include/BsPixelDataEx.h"
+	"Include/BsAsyncOpEx.h"
+	"Include/BsTextureEx.h"
 )
 
 set(BS_SBANSHEEENGINE_SRC_EXTENSIONS
 	"Source/BsPixelDataEx.cpp"
+	"Source/BsAsyncOpEx.cpp"
+	"Source/BsTextureEx.cpp"
 )
 
 source_group("Header Files" FILES ${BS_SBANSHEEENGINE_INC_NOFILTER})

+ 44 - 0
Source/SBansheeEngine/Include/BsAsyncOpEx.h

@@ -0,0 +1,44 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#pragma once
+
+#include "BsScriptEnginePrerequisites.h"
+#include "BsScriptObject.h"
+#include "BsAsyncOp.h"
+
+namespace bs
+{
+	/** @addtogroup ScriptInteropEngine
+	 *  @{
+	 */
+	/** @cond SCRIPT_EXTENSIONS */
+
+	/** 
+	 * Object you may use to check on the results of an asynchronous operation. Contains uninitialized data until 
+	 * IsComplete returns true.
+	 */
+	class BS_SCR_BE_EXPORT BS_SCRIPT_EXPORT(n:AsyncOp) AsyncOpEx
+	{
+	public:
+		AsyncOpEx(const AsyncOp& op, const std::function<ScriptObjectBase*(const AsyncOp&)>& convertCallback);
+
+		/** @copydoc AsyncOp::hasCompleted */
+		BS_SCRIPT_EXPORT(n:IsComplete,pr:getter)
+		bool isComplete() const;
+
+		/** Retrieves the value returned by the async operation. Only valid if IsComplete returns true. */
+		BS_SCRIPT_EXPORT(n:ReturnValue,pr:getter)
+		ScriptObjectBase* getReturnValue() const;
+
+		/** @copydoc AsyncOp::blockUntilComplete */
+		BS_SCRIPT_EXPORT(n:BlockUntilComplete)
+		void blockUntilComplete() const;
+
+	private:
+		AsyncOp mAsyncOp;
+		std::function<ScriptObjectBase*(const AsyncOp&)> mConvertCallback;
+	};
+
+	/** @endcond */
+	/** @} */
+}

+ 2 - 0
Source/SBansheeEngine/Include/BsPixelDataEx.h

@@ -11,6 +11,7 @@ namespace bs
 	/** @addtogroup ScriptInteropEngine
 	 *  @{
 	 */
+	/** @cond SCRIPT_EXTENSIONS */
 
 	/** Extension class for PixelData, for adding additional functionality for the script version of PixelData. */
 	class BS_SCRIPT_EXPORT(e:PixelData) PixelDataEx
@@ -83,5 +84,6 @@ namespace bs
 		static bool checkIsLocked(const SPtr<PixelData>& thisPtr);
 	};
 
+	/** @endcond */
 	/** @} */
 }

+ 0 - 49
Source/SBansheeEngine/Include/BsScriptAsyncOp.h

@@ -1,49 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsScriptEnginePrerequisites.h"
-#include "BsScriptObject.h"
-#include "BsAsyncOp.h"
-
-namespace bs
-{
-	/** @addtogroup ScriptInteropEngine
-	 *  @{
-	 */
-
-	/**	Interop class between C++ & CLR for AsyncOp. */
-	class BS_SCR_BE_EXPORT ScriptAsyncOp : public ScriptObject<ScriptAsyncOp>
-	{
-	public:
-		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "AsyncOp")
-
-		/**
-		 * Creates a new managed AsyncOp instance.
-		 *
-		 * @param[in]	op						Native AsyncOp to wrap.
-		 * @param[in]	asyncOpToReturnValue	Callback that converts the returned value from native async op to a managed
-		 *										object.
-		 */
-		static MonoObject* create(const AsyncOp& op, std::function<MonoObject*(const AsyncOp&)> asyncOpToReturnValue);
-
-	private:
-		ScriptAsyncOp(MonoObject* instance);
-
-		/**	Finishes construction of the AsyncOp wrapper. Must be called before using the object. */
-		void initialize(const AsyncOp& op, std::function<MonoObject*(const AsyncOp&)> asyncOpToReturnValue);
-
-		AsyncOp mAsyncOp;
-		std::function<MonoObject*(const AsyncOp&)> mConvertCallback;
-
-		/************************************************************************/
-		/* 								CLR HOOKS						   		*/
-		/************************************************************************/
-		static void internal_createInstance(MonoObject* managedInstance);
-		static void internal_isComplete(ScriptAsyncOp* thisPtr, bool* value);
-		static MonoObject* internal_getReturnValue(ScriptAsyncOp* thisPtr);
-		static void internal_blockUntilComplete(ScriptAsyncOp* thisPtr);
-	};
-
-	/** @} */
-}

+ 0 - 50
Source/SBansheeEngine/Include/BsScriptTexture.h

@@ -1,50 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsScriptEnginePrerequisites.h"
-#include "BsScriptResource.h"
-#include "BsPixelData.h"
-#include "BsTexture.h"
-
-namespace bs
-{
-	/** @addtogroup ScriptInteropEngine
-	 *  @{
-	 */
-
-	/**	Interop class between C++ & CLR for Texture. */
-	class BS_SCR_BE_EXPORT ScriptTexture : public TScriptResource <ScriptTexture, Texture>
-	{
-	public:
-		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "Texture")
-
-		/**	Creates an empty, uninitialized managed instance of the resource interop object. */
-		static MonoObject* createInstance();
-
-	private:
-		friend class ScriptResourceManager;
-
-		ScriptTexture(MonoObject* instance, const HTexture& texture);
-
-		/************************************************************************/
-		/* 								CLR HOOKS						   		*/
-		/************************************************************************/
-		static void internal_createInstance(MonoObject* instance, PixelFormat format, UINT32 width,
-			UINT32 height, UINT32 depth, TextureType texType, TextureUsage usage, UINT32 numSamples, bool hasMipmaps, 
-			bool gammaCorrection);
-		static void internal_getPixelFormat(ScriptTexture* thisPtr, PixelFormat* value);
-		static void internal_getUsage(ScriptTexture* thisPtr, TextureUsage* value);
-		static void internal_getWidth(ScriptTexture* thisPtr, int* value);
-		static void internal_getHeight(ScriptTexture* thisPtr, int* value);
-		static void internal_getGammaCorrection(ScriptTexture* thisPtr, bool* value);
-		static void internal_getSampleCount(ScriptTexture* thisPtr, int* value);
-		static void internal_getMipmapCount(ScriptTexture* thisPtr, int* value);
-		static MonoObject* internal_getPixels(ScriptTexture* thisPtr, UINT32 face, UINT32 mipLevel);
-		static MonoObject* internal_getGPUPixels(ScriptTexture* thisPtr, UINT32 face, UINT32 mipLevel);
-		static void internal_setPixels(ScriptTexture* thisPtr, MonoObject* data, UINT32 face, UINT32 mipLevel);
-		static void internal_setPixelsArray(ScriptTexture* thisPtr, MonoArray* colors, UINT32 face, UINT32 mipLevel);
-	};
-
-	/** @} */
-}

+ 122 - 0
Source/SBansheeEngine/Include/BsTextureEx.h

@@ -0,0 +1,122 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#pragma once
+
+#include "BsScriptEnginePrerequisites.h"
+#include "BsScriptResource.h"
+#include "BsPixelData.h"
+#include "BsTexture.h"
+
+namespace bs
+{
+	class AsyncOpEx;
+
+	/** @addtogroup ScriptInteropEngine
+	 *  @{
+	 */
+	/** @cond SCRIPT_EXTENSIONS */
+
+	 /** Extension class for Texture, for adding additional functionality for the script version of PixelData. */
+	class BS_SCRIPT_EXPORT(e:Texture) TextureEx
+	{
+	public:
+		BS_SCRIPT_EXPORT(ec:Texture,v:private)
+		static HTexture create(PixelFormat format, UINT32 width, UINT32 height, UINT32 depth, TextureType texType, 
+			TextureUsage usage, UINT32 numSamples, bool hasMipmaps, bool gammaCorrection);
+
+		/** @copydoc TextureProperties::getFormat */
+		BS_SCRIPT_EXPORT(e:Texture,n:PixelFormat,pr:getter)
+		static PixelFormat getPixelFormat(const HTexture& thisPtr);
+
+		/** @copydoc TextureProperties::getUsage */
+		BS_SCRIPT_EXPORT(e:Texture,n:Usage,pr:getter)
+		static TextureUsage getUsage(const HTexture& thisPtr);
+
+		/** @copydoc TextureProperties::getTextureType */
+		BS_SCRIPT_EXPORT(e:Texture,n:Type,pr:getter)
+		static TextureType getType(const HTexture& thisPtr);
+
+		/** @copydoc TextureProperties::getWidth */
+		BS_SCRIPT_EXPORT(e:Texture,n:Width,pr:getter)
+		static UINT32 getWidth(const HTexture& thisPtr);
+
+		/** @copydoc TextureProperties::getHeight */
+		BS_SCRIPT_EXPORT(e:Texture,n:Height,pr:getter)
+		static UINT32 getHeight(const HTexture& thisPtr);
+
+		/** @copydoc TextureProperties::getDepth */
+		BS_SCRIPT_EXPORT(e:Texture,n:Depth,pr:getter)
+		static UINT32 getDepth(const HTexture& thisPtr);
+
+		/** @copydoc TextureProperties::isHardwareGammaEnabled */
+		BS_SCRIPT_EXPORT(e:Texture,n:GammaSpace,pr:getter)
+		static bool getGammaCorrection(const HTexture& thisPtr);
+
+		/** @copydoc TextureProperties::getNumSamples */
+		BS_SCRIPT_EXPORT(e:Texture,n:SampleCount,pr:getter)
+		static UINT32 getSampleCount(const HTexture& thisPtr);
+
+		/** @copydoc TextureProperties::getNumMipmaps */
+		BS_SCRIPT_EXPORT(e:Texture,n:MipMapCount,pr:getter)
+		static UINT32 getMipmapCount(const HTexture& thisPtr);
+
+		/**
+		 * Returns pixels for the specified mip level & face. Pixels will be read from system memory, which means the
+		 * texture has to be created with TextureUsage.CPUCached. If the texture was updated from the GPU the
+		 * pixels retrieved from this method will not reflect that, and you should use GetGPUPixels instead.
+		 * 
+         * @param mipLevel	Mip level to retrieve pixels for. Top level (0) is the highest quality.
+         * @param face		Face to read the pixels from. Cubemap textures have six faces whose face indices are as
+         *					specified in the CubeFace enum. Array textures can have an arbitrary number of faces (if it's a
+         *					cubemap array it has to be a multiple of 6).
+         * @return			A set of pixels for the specified mip level.
+		 */
+		BS_SCRIPT_EXPORT(e:Texture,n:GetPixels)
+		static SPtr<PixelData> getPixels(const HTexture& thisPtr, UINT32 face, UINT32 mipLevel);
+
+		/**
+		 * Reads texture pixels directly from the GPU. This is similar to GetPixels" but the texture doesn't
+		 * need to be created with TextureUsage.CPUCached, and the data will contain any updates performed by
+		 * the GPU. This method can be potentially slow as it introduces a CPU-GPU synchronization point. Additionally
+		 * this method is asynchronous which means the data is not available immediately.
+		 *
+		 * @param mipLevel	Mip level to retrieve pixels for. Top level (0) is the highest quality.
+		 * @param face		Face to read the pixels from. Cubemap textures have six faces whose face indices are as
+		 *					specified in the CubeFace enum. Array textures can have an arbitrary number of faces (if it's a
+		 *					cubemap array it has to be a multiple of 6).
+		 * @return			AsyncOp object that will contain a PixelData object when the operation completes.
+		 */
+		BS_SCRIPT_EXPORT(e:Texture,n:GetGPUPixels)
+		static SPtr<AsyncOpEx> getGPUPixels(const HTexture& thisPtr, UINT32 face, UINT32 mipLevel);
+
+		/**
+		 * Sets pixels for the specified mip level and face.
+		 *
+		 * @param data		Pixels to assign to the specified mip level. Pixel data must match the mip level size and
+		 *					texture pixel format.
+		 * @param mipLevel	Mip level to set pixels for. Top level (0) is the highest quality.
+		 * @param face		Face to write the pixels to. Cubemap textures have six faces whose face indices are as
+		 *					specified in the CubeFace enum. Array textures can have an arbitrary number of faces (if it's a
+		 *					cubemap array it has to be a multiple of 6).
+		 */
+		BS_SCRIPT_EXPORT(e:Texture,n:SetPixels)
+		static void setPixels(const HTexture& thisPtr, const SPtr<PixelData>& data, UINT32 face, UINT32 mipLevel);
+
+		/**
+		 * Sets pixels for the specified mip level and face.
+		 *
+		 * @param colors	Pixels to assign to the specified mip level. Size of the array must match the mip level
+		 *                  dimensions. Data is expected to be laid out row by row. Pixels will be automatically
+		 *                  converted to the valid pixel format.
+		 * @param mipLevel	Mip level to set pixels for. Top level (0) is the highest quality.
+		 * @param face		Face to write the pixels to. Cubemap textures have six faces whose face indices are as
+		 *					specified in the CubeFace enum. Array textures can have an arbitrary number of faces (if it's a
+		 *					cubemap array it has to be a multiple of 6).
+		 */
+		BS_SCRIPT_EXPORT(e:Texture,n:SetPixels)
+		static void setPixelsArray(const HTexture& thisPtr, const Vector<Color>& colors, UINT32 face, UINT32 mipLevel);
+	};
+
+	/** @endcond */
+	/** @} */
+}

+ 36 - 0
Source/SBansheeEngine/Source/BsAsyncOpEx.cpp

@@ -0,0 +1,36 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#include "BsAsyncOpEx.h"
+#include "BsCoreThread.h"
+
+namespace bs
+{
+	AsyncOpEx::AsyncOpEx(const AsyncOp& op, const std::function<ScriptObjectBase*(const AsyncOp&)>& convertCallback)
+		:mAsyncOp(op), mConvertCallback(convertCallback)
+	{ }
+
+	bool AsyncOpEx::isComplete() const
+	{
+		return mAsyncOp.hasCompleted();
+	}
+
+	ScriptObjectBase* AsyncOpEx::getReturnValue() const
+	{
+		if (!mAsyncOp.hasCompleted())
+			return nullptr;
+
+		if (mConvertCallback == nullptr)
+			return nullptr;
+
+		return mConvertCallback(mAsyncOp);
+	}
+
+	void AsyncOpEx::blockUntilComplete() const
+	{
+		if (!mAsyncOp.hasCompleted())
+		{
+			gCoreThread().submit();
+			mAsyncOp.blockUntilComplete();
+		}
+	}
+}

+ 2 - 1
Source/SBansheeEngine/Source/BsManagedSerializableField.cpp

@@ -7,7 +7,6 @@
 #include "BsMonoManager.h"
 #include "BsScriptResourceManager.h"
 #include "BsScriptGameObjectManager.h"
-#include "BsScriptTexture.h"
 #include "BsScriptSpriteTexture.h"
 #include "BsScriptManagedResource.h"
 #include "BsScriptPlainText.h"
@@ -33,6 +32,8 @@
 #include "BsManagedSerializableDictionary.h"
 #include "BsScriptAssemblyManager.h"
 
+#include "BsScriptTexture.generated.h"
+
 namespace bs
 {
 	template<class T>

+ 2 - 1
Source/SBansheeEngine/Source/BsManagedSerializableObjectInfo.cpp

@@ -8,7 +8,6 @@
 #include "BsMonoManager.h"
 #include "BsMonoField.h"
 #include "BsMonoProperty.h"
-#include "BsScriptTexture.h"
 #include "BsScriptSpriteTexture.h"
 #include "BsScriptAssemblyManager.h"
 #include "BsScriptMaterial.h"
@@ -28,6 +27,8 @@
 #include "BsScriptManagedResource.h"
 #include <BsScriptStep.h>
 
+#include "BsScriptTexture.generated.h"
+
 namespace bs
 {
 	RTTITypeBase* ManagedSerializableAssemblyInfo::getRTTIStatic()

+ 2 - 1
Source/SBansheeEngine/Source/BsScriptAssemblyManager.cpp

@@ -10,7 +10,6 @@
 #include "BsMonoProperty.h"
 #include "BsScriptManagedResource.h"
 #include "BsScriptComponent.h"
-#include "BsScriptTexture.h"
 #include "BsScriptSpriteTexture.h"
 #include "BsScriptMaterial.h"
 #include "BsScriptMesh.h"
@@ -28,6 +27,8 @@
 #include "BsScriptAnimationClip.h"
 #include "BsBuiltinComponentLookup.h"
 
+#include "BsScriptTexture.generated.h"
+
 namespace bs
 {
 	ScriptAssemblyManager::ScriptAssemblyManager()

+ 0 - 69
Source/SBansheeEngine/Source/BsScriptAsyncOp.cpp

@@ -1,69 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsScriptAsyncOp.h"
-#include "BsMonoManager.h"
-#include "BsMonoClass.h"
-#include "BsMonoUtil.h"
-#include "BsCoreThread.h"
-
-namespace bs
-{
-	ScriptAsyncOp::ScriptAsyncOp(MonoObject* instance)
-		:ScriptObject(instance)
-	{ }
-
-	void ScriptAsyncOp::initRuntimeData()
-	{
-		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptAsyncOp::internal_createInstance);
-		metaData.scriptClass->addInternalCall("Internal_IsComplete", &ScriptAsyncOp::internal_isComplete);
-		metaData.scriptClass->addInternalCall("Internal_GetReturnValue", &ScriptAsyncOp::internal_getReturnValue);
-		metaData.scriptClass->addInternalCall("Internal_BlockUntilComplete", &ScriptAsyncOp::internal_blockUntilComplete);
-	}
-
-	MonoObject* ScriptAsyncOp::create(const AsyncOp& op, 
-		std::function<MonoObject*(const AsyncOp&)> asyncOpToReturnValue)
-	{
-		MonoObject* managedInstance = metaData.scriptClass->createInstance();
-
-		ScriptAsyncOp* scriptAsyncOp = toNative(managedInstance);
-		scriptAsyncOp->initialize(op, asyncOpToReturnValue);
-
-		return managedInstance;
-	}
-
-	void ScriptAsyncOp::initialize(const AsyncOp& op, std::function<MonoObject*(const AsyncOp&)> asyncOpToReturnValue)
-	{
-		mAsyncOp = op;
-		mConvertCallback = asyncOpToReturnValue;
-	}
-
-	void ScriptAsyncOp::internal_createInstance(MonoObject* managedInstance)
-	{
-		new (bs_alloc<ScriptAsyncOp>()) ScriptAsyncOp(managedInstance);
-	}
-
-	void ScriptAsyncOp::internal_isComplete(ScriptAsyncOp* thisPtr, bool* value)
-	{
-		*value = thisPtr->mAsyncOp.hasCompleted();
-	}
-
-	MonoObject* ScriptAsyncOp::internal_getReturnValue(ScriptAsyncOp* thisPtr)
-	{
-		if (!thisPtr->mAsyncOp.hasCompleted())
-			return nullptr;
-
-		if (thisPtr->mConvertCallback == nullptr)
-			return nullptr;
-
-		return thisPtr->mConvertCallback(thisPtr->mAsyncOp);
-	}
-
-	void ScriptAsyncOp::internal_blockUntilComplete(ScriptAsyncOp* thisPtr)
-	{
-		if (!thisPtr->mAsyncOp.hasCompleted())
-		{
-			gCoreThread().submit();
-			thisPtr->mAsyncOp.blockUntilComplete();
-		}
-	}
-}

+ 0 - 2
Source/SBansheeEngine/Source/BsScriptCamera.cpp

@@ -17,8 +17,6 @@
 #include "BsGUIManager.h"
 #include "BsStandardPostProcessSettings.h"
 #include "BsScriptPostProcessSettings.h"
-#include "BsScriptTexture.h"
-#include "BsScriptResourceManager.h"
 
 namespace bs
 {

+ 2 - 1
Source/SBansheeEngine/Source/BsScriptFontBitmap.cpp

@@ -6,9 +6,10 @@
 #include "BsMonoClass.h"
 #include "BsMonoManager.h"
 #include "BsScriptResourceManager.h"
-#include "BsScriptTexture.h"
 #include "BsMonoUtil.h"
 
+#include "BsScriptTexture.generated.h"
+
 namespace bs
 {
 	ScriptFontBitmap::ScriptFontBitmap(MonoObject* instance, SPtr<const FontBitmap> bitmap)

+ 3 - 2
Source/SBansheeEngine/Source/BsScriptMaterial.cpp

@@ -8,8 +8,9 @@
 #include "BsMonoManager.h"
 #include "BsMonoUtil.h"
 #include "BsScriptShader.h"
-#include "BsScriptTexture.h"
-#include <BsBuiltinResources.h>
+#include "BsBuiltinResources.h"
+
+#include "BsScriptTexture.generated.h"
 
 namespace bs
 {

+ 2 - 1
Source/SBansheeEngine/Source/BsScriptRenderTexture2D.cpp

@@ -6,10 +6,11 @@
 #include "BsMonoClass.h"
 #include "BsMonoManager.h"
 #include "BsRenderTexture.h"
-#include "BsScriptTexture.h"
 #include "BsMonoUtil.h"
 #include "BsScriptResourceManager.h"
 
+#include "BsScriptTexture.generated.h"
+
 namespace bs
 {
 	ScriptRenderTexture2D::ScriptRenderTexture2D(const SPtr<RenderTarget>& target, MonoObject* instance)

+ 2 - 1
Source/SBansheeEngine/Source/BsScriptResource.cpp

@@ -4,7 +4,6 @@
 #include "BsScriptResourceManager.h"
 #include "BsResource.h"
 #include "BsMonoUtil.h"
-#include "BsScriptTexture.h"
 #include "BsScriptSpriteTexture.h"
 #include "BsScriptMaterial.h"
 #include "BsScriptMesh.h"
@@ -21,6 +20,8 @@
 #include "BsScriptPrefab.h"
 #include "BsScriptAnimationClip.h"
 
+#include "BsScriptTexture.generated.h"
+
 namespace bs
 {
 	ScriptResourceBase::ScriptResourceBase(MonoObject* instance)

+ 2 - 1
Source/SBansheeEngine/Source/BsScriptResourceManager.cpp

@@ -5,7 +5,6 @@
 #include "BsMonoAssembly.h"
 #include "BsMonoClass.h"
 #include "BsResources.h"
-#include "BsScriptTexture.h"
 #include "BsScriptSpriteTexture.h"
 #include "BsScriptPlainText.h"
 #include "BsScriptScriptCode.h"
@@ -24,6 +23,8 @@
 #include "BsScriptManagedResource.h"
 #include "BsScriptAssemblyManager.h"
 
+#include "BsScriptTexture.generated.h"
+
 using namespace std::placeholders;
 
 namespace bs

+ 2 - 1
Source/SBansheeEngine/Source/BsScriptResourceRef.cpp

@@ -6,10 +6,11 @@
 #include "BsMonoUtil.h"
 #include "BsResources.h"
 #include "BsScriptResource.h"
-#include "BsScriptTexture.h"
 #include "BsScriptResourceManager.h"
 #include "BsApplication.h"
 
+#include "BsScriptTexture.generated.h"
+
 namespace bs
 {
 	ScriptResourceRef::ScriptResourceRef(MonoObject* instance, const WeakResourceHandle<Resource>& resource)

+ 2 - 1
Source/SBansheeEngine/Source/BsScriptSpriteTexture.cpp

@@ -7,7 +7,8 @@
 #include "BsMonoClass.h"
 #include "BsMonoManager.h"
 #include "BsSpriteTexture.h"
-#include "BsScriptTexture.h"
+
+#include "BsScriptTexture.generated.h"
 
 namespace bs
 {

+ 0 - 184
Source/SBansheeEngine/Source/BsScriptTexture.cpp

@@ -1,184 +0,0 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsScriptTexture.h"
-#include "BsScriptMeta.h"
-#include "BsMonoField.h"
-#include "BsMonoClass.h"
-#include "BsMonoManager.h"
-#include "BsScriptResourceManager.h"
-#include "BsScriptAsyncOp.h"
-
-#include "BsScriptPixelData.generated.h"
-
-using namespace std::placeholders;
-
-namespace bs
-{
-	ScriptTexture::ScriptTexture(MonoObject* instance, const HTexture& texture)
-		:TScriptResource(instance, texture)
-	{
-
-	}
-
-	void ScriptTexture::initRuntimeData()
-	{
-		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptTexture::internal_createInstance);
-		metaData.scriptClass->addInternalCall("Internal_GetPixelFormat", &ScriptTexture::internal_getPixelFormat);
-		metaData.scriptClass->addInternalCall("Internal_GetUsage", &ScriptTexture::internal_getUsage);
-		metaData.scriptClass->addInternalCall("Internal_GetWidth", &ScriptTexture::internal_getWidth);
-		metaData.scriptClass->addInternalCall("Internal_GetHeight", &ScriptTexture::internal_getHeight);
-		metaData.scriptClass->addInternalCall("Internal_GetGammaCorrection", &ScriptTexture::internal_getGammaCorrection);
-		metaData.scriptClass->addInternalCall("Internal_GetSampleCount", &ScriptTexture::internal_getSampleCount);
-		metaData.scriptClass->addInternalCall("Internal_GetMipmapCount", &ScriptTexture::internal_getMipmapCount);
-		metaData.scriptClass->addInternalCall("Internal_GetPixels", &ScriptTexture::internal_getPixels);
-		metaData.scriptClass->addInternalCall("Internal_GetGPUPixels", &ScriptTexture::internal_getGPUPixels);
-		metaData.scriptClass->addInternalCall("Internal_SetPixels", &ScriptTexture::internal_setPixels);
-		metaData.scriptClass->addInternalCall("Internal_SetPixelsArray", &ScriptTexture::internal_setPixelsArray);
-	}
-
-	void ScriptTexture::internal_createInstance(MonoObject* instance, PixelFormat format, UINT32 width,
-		UINT32 height, UINT32 depth, TextureType texType, TextureUsage usage, UINT32 numSamples, bool hasMipmaps, 
-		bool gammaCorrection)
-	{
-		int numMips = 0;
-		if (hasMipmaps)
-			numMips = PixelUtil::getMaxMipmaps(width, height, 1, format);
-
-		TEXTURE_DESC texDesc;
-		texDesc.type = texType;
-		texDesc.width = width;
-		texDesc.height = height;
-		
-		if (texType == TEX_TYPE_3D)
-			texDesc.depth = depth;
-		else
-			texDesc.depth = 1;
-
-		texDesc.numMips = numMips;
-		texDesc.format = format;
-		texDesc.usage = usage;
-		texDesc.hwGamma = gammaCorrection;
-		texDesc.numSamples = numSamples;
-
-		HTexture texture = Texture::create(texDesc);
-
-		ScriptTexture* scriptInstance;
-		ScriptResourceManager::instance().createScriptResource(instance, texture, &scriptInstance);
-	}
-
-	void ScriptTexture::internal_getPixelFormat(ScriptTexture* thisPtr, PixelFormat* value)
-	{
-		HTexture texture = static_resource_cast<Texture>(thisPtr->getGenericHandle());
-		*value = texture->getProperties().getFormat();
-	}
-
-	void ScriptTexture::internal_getUsage(ScriptTexture* thisPtr, TextureUsage* value)
-	{
-		HTexture texture = static_resource_cast<Texture>(thisPtr->getGenericHandle());
-		*value = (TextureUsage)texture->getProperties().getUsage();
-	}
-
-	void ScriptTexture::internal_getWidth(ScriptTexture* thisPtr, int* value)
-	{
-		HTexture texture = static_resource_cast<Texture>(thisPtr->getGenericHandle());
-		*value = (TextureUsage)texture->getProperties().getWidth();
-	}
-
-	void ScriptTexture::internal_getHeight(ScriptTexture* thisPtr, int* value)
-	{
-		HTexture texture = static_resource_cast<Texture>(thisPtr->getGenericHandle());
-		*value = (TextureUsage)texture->getProperties().getHeight();
-	}
-
-	void ScriptTexture::internal_getGammaCorrection(ScriptTexture* thisPtr, bool* value)
-	{
-		HTexture texture = static_resource_cast<Texture>(thisPtr->getGenericHandle());
-		*value = (TextureUsage)texture->getProperties().isHardwareGammaEnabled();
-	}
-
-	void ScriptTexture::internal_getSampleCount(ScriptTexture* thisPtr, int* value)
-	{
-		HTexture texture = static_resource_cast<Texture>(thisPtr->getGenericHandle());
-		*value = (TextureUsage)texture->getProperties().getNumSamples();
-	}
-
-	void ScriptTexture::internal_getMipmapCount(ScriptTexture* thisPtr, int* value)
-	{
-		HTexture texture = static_resource_cast<Texture>(thisPtr->getGenericHandle());
-		*value = (TextureUsage)texture->getProperties().getNumMipmaps();
-	}
-
-	MonoObject* ScriptTexture::internal_getPixels(ScriptTexture* thisPtr, UINT32 face, UINT32 mipLevel)
-	{
-		HTexture texture = thisPtr->getHandle();
-
-		SPtr<PixelData> pixelData = texture->getProperties().allocBuffer(face, mipLevel);
-		texture->readCachedData(*pixelData, face, mipLevel);
-
-		return ScriptPixelData::create(pixelData);
-	}
-
-	MonoObject* ScriptTexture::internal_getGPUPixels(ScriptTexture* thisPtr, UINT32 face, UINT32 mipLevel)
-	{
-		HTexture texture = thisPtr->getHandle();
-		SPtr<PixelData> readData = texture->getProperties().allocBuffer(face, mipLevel);
-
-		AsyncOp asyncOp = texture->readData(readData, face, mipLevel);
-
-		std::function<MonoObject*(const AsyncOp&, const SPtr<PixelData>&)> asyncOpToMono =
-			[&](const AsyncOp& op, const SPtr<PixelData>& returnValue)
-		{
-			return ScriptPixelData::create(returnValue);
-		};
-
-		return ScriptAsyncOp::create(asyncOp, std::bind(asyncOpToMono, _1, readData));
-	}
-
-	void ScriptTexture::internal_setPixels(ScriptTexture* thisPtr, MonoObject* data, UINT32 face, UINT32 mipLevel)
-	{
-		ScriptPixelData* scriptPixelData = ScriptPixelData::toNative(data);
-
-		if (scriptPixelData != nullptr)
-		{
-			HTexture texture = thisPtr->getHandle();
-			texture->writeData(scriptPixelData->getInternal(), face, mipLevel, false);
-		}
-	}
-
-	void ScriptTexture::internal_setPixelsArray(ScriptTexture* thisPtr, MonoArray* colors, UINT32 face, UINT32 mipLevel)
-	{
-		if (colors == nullptr)
-		{
-			LOGWRN("SetPixels called with a null array. Ignoring call.");
-			return;
-		}
-
-		ScriptArray scriptArray(colors);
-		Color* colorsRaw = (Color*)scriptArray.getRawPtr(sizeof(Color), 0);
-		UINT32 numElements = (UINT32)scriptArray.size();
-
-		HTexture texture = thisPtr->getHandle();
-		const TextureProperties& props = texture->getProperties();
-
-		UINT32 texNumElements = props.getWidth() * props.getHeight() * props.getDepth();
-
-		if (texNumElements != numElements)
-		{
-			LOGWRN("SetPixels called with incorrect dimensions. Ignoring call.");
-			return;
-		}		
-
-		SPtr<PixelData> pixelData = bs_shared_ptr_new<PixelData>(props.getWidth(), props.getHeight(), props.getDepth(), 
-			props.getFormat());
-		pixelData->allocateInternalBuffer();
-		pixelData->setColors(colorsRaw, numElements);
-
-		texture->writeData(pixelData, face, mipLevel, false);
-	}
-
-
-	MonoObject* ScriptTexture::createInstance()
-	{
-		return metaData.scriptClass->createInstance();
-	}
-}

+ 132 - 0
Source/SBansheeEngine/Source/BsTextureEx.cpp

@@ -0,0 +1,132 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#include "BsTextureEx.h"
+#include "BsAsyncOpEx.h"
+
+#include "BsScriptPixelData.generated.h"
+
+using namespace std::placeholders;
+
+namespace bs
+{
+	HTexture TextureEx::create(PixelFormat format, UINT32 width, UINT32 height, UINT32 depth, TextureType texType, 
+		TextureUsage usage, UINT32 numSamples, bool hasMipmaps, bool gammaCorrection)
+	{
+		int numMips = 0;
+		if (hasMipmaps)
+			numMips = PixelUtil::getMaxMipmaps(width, height, 1, format);
+
+		TEXTURE_DESC texDesc;
+		texDesc.type = texType;
+		texDesc.width = width;
+		texDesc.height = height;
+		
+		if (texType == TEX_TYPE_3D)
+			texDesc.depth = depth;
+		else
+			texDesc.depth = 1;
+
+		texDesc.numMips = numMips;
+		texDesc.format = format;
+		texDesc.usage = usage;
+		texDesc.hwGamma = gammaCorrection;
+		texDesc.numSamples = numSamples;
+
+		return Texture::create(texDesc);
+	}
+
+	PixelFormat TextureEx::getPixelFormat(const HTexture& thisPtr)
+	{
+		return thisPtr->getProperties().getFormat();
+	}
+
+	TextureUsage TextureEx::getUsage(const HTexture& thisPtr)
+	{
+		return (TextureUsage)thisPtr->getProperties().getUsage();
+	}
+
+	TextureType TextureEx::getType(const HTexture& thisPtr)
+	{
+		return thisPtr->getProperties().getTextureType();
+	}
+
+	UINT32 TextureEx::getWidth(const HTexture& thisPtr)
+	{
+		return thisPtr->getProperties().getWidth();
+	}
+
+	UINT32 TextureEx::getHeight(const HTexture& thisPtr)
+	{
+		return thisPtr->getProperties().getHeight();
+	}
+
+	UINT32 TextureEx::getDepth(const HTexture& thisPtr)
+	{
+		return thisPtr->getProperties().getDepth();
+	}
+
+	bool TextureEx::getGammaCorrection(const HTexture& thisPtr)
+	{
+		return thisPtr->getProperties().isHardwareGammaEnabled();
+	}
+
+	UINT32 TextureEx::getSampleCount(const HTexture& thisPtr)
+	{
+		return thisPtr->getProperties().getNumSamples();
+	}
+
+	UINT32 TextureEx::getMipmapCount(const HTexture& thisPtr)
+	{
+		return thisPtr->getProperties().getNumMipmaps();
+	}
+
+	SPtr<PixelData> TextureEx::getPixels(const HTexture& thisPtr, UINT32 face, UINT32 mipLevel)
+	{
+		SPtr<PixelData> pixelData = thisPtr->getProperties().allocBuffer(face, mipLevel);
+		thisPtr->readCachedData(*pixelData, face, mipLevel);
+
+		return pixelData;
+	}
+
+	SPtr<AsyncOpEx> TextureEx::getGPUPixels(const HTexture& thisPtr, UINT32 face, UINT32 mipLevel)
+	{
+		SPtr<PixelData> readData = thisPtr->getProperties().allocBuffer(face, mipLevel);
+		AsyncOp asyncOp = thisPtr->readData(readData, face, mipLevel);
+
+		std::function<ScriptObjectBase*(const AsyncOp&)> asyncOpToMono =
+			[&readData](const AsyncOp& op)
+		{
+			MonoObject* obj = ScriptPixelData::create(readData);
+			return ScriptPixelData::toNative(obj);
+		};
+
+		return bs_shared_ptr_new<AsyncOpEx>(asyncOp, asyncOpToMono);
+	}
+
+	void TextureEx::setPixels(const HTexture& thisPtr, const SPtr<PixelData>& data, UINT32 face, UINT32 mipLevel)
+	{
+		if (data != nullptr)
+			thisPtr->writeData(data, face, mipLevel, false);
+	}
+
+	void TextureEx::setPixelsArray(const HTexture& thisPtr, const Vector<Color>& colors, UINT32 face, UINT32 mipLevel)
+	{
+		UINT32 numElements = (UINT32)colors.size();
+
+		const TextureProperties& props = thisPtr->getProperties();
+		UINT32 texNumElements = props.getWidth() * props.getHeight() * props.getDepth();
+
+		if (texNumElements != numElements)
+		{
+			LOGWRN("SetPixels called with incorrect dimensions. Ignoring call.");
+			return;
+		}		
+
+		SPtr<PixelData> pixelData = bs_shared_ptr_new<PixelData>(props.getWidth(), props.getHeight(), props.getDepth(), 
+			props.getFormat());
+		pixelData->allocateInternalBuffer();
+		pixelData->setColors(colors);
+
+		thisPtr->writeData(pixelData, face, mipLevel, false);
+	}
+}