Browse Source

Documentation
Fixed an issue where sampler overrides weren't generated for default sampler states

Marko Pintera 10 years ago
parent
commit
a2831fc54b

+ 1 - 1
BansheeRenderer/Source/BsBansheeRenderer.cpp

@@ -538,7 +538,7 @@ namespace BansheeEngine
 								if (samplerState != nullptr)
 									stageOverrides.stateOverrides[slot] = SamplerOverrideUtility::generateSamplerOverride(samplerState, mCoreOptions);
 								else
-									stageOverrides.stateOverrides[slot] = nullptr;
+									stageOverrides.stateOverrides[slot] = SamplerOverrideUtility::generateSamplerOverride(SamplerStateCore::getDefault(), mCoreOptions);;
 							}	
 						}
 					}

+ 1 - 1
BansheeRenderer/Source/BsSamplerOverrides.cpp

@@ -87,7 +87,7 @@ namespace BansheeEngine
 
 						SPtr<SamplerStateCore> samplerState = params->getSamplerState(slot);
 						if (samplerState == nullptr)
-							continue;
+							samplerState = SamplerStateCore::getDefault();
 
 						bool needsOverride = checkNeedsOverride(samplerState, options);
 

+ 33 - 4
SBansheeEngine/Include/BsScriptMeshData.h

@@ -6,6 +6,9 @@
 
 namespace BansheeEngine
 {
+	/**
+	 * @brief	Valid index types for mesh indices.
+	 */
 	// Note: Do not modify, it must match the layout of C# enum IndexType
 	enum class ScriptIndexType
 	{
@@ -13,21 +16,51 @@ namespace BansheeEngine
 		Index32
 	};
 
+	/**
+	 * @brief	Interop class between C++ & CLR for RendererMeshData.
+	 */
 	class BS_SCR_BE_EXPORT ScriptMeshData : public ScriptObject <ScriptMeshData>
 	{
 	public:
 		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "MeshData")
 
+		/**
+		 * @brief	Returns the internal wrapped mesh data.
+		 */
 		RendererMeshDataPtr getInternalValue() const { return mMeshData; }
 
+		/**
+		 * @brief	Creates a new managed MeshData object from the provided
+		 *			native render mesh data.
+		 */
 		static MonoObject* create(const RendererMeshDataPtr& meshData);
+
+		/**
+		 * @brief	Creates a new managed MeshData object from the provided
+		 *			native mesh data.
+		 */
 		static MonoObject* create(const MeshDataPtr& meshData);
 	private:
 		ScriptMeshData(MonoObject* managedInstance);
 		~ScriptMeshData();
 
+		/**
+		 * @brief	Initializes the object. Must be called after construction
+		 *			and before use.
+		 */
 		void initialize(const RendererMeshDataPtr& meshData);
 
+		/**
+		 * @brief	Checks is the underlying mesh data of the provided object locked.
+		 *			When locked mesh data cannot be accessed.
+		 */
+		static bool checkIsLocked(ScriptMeshData* thisPtr);
+
+		RendererMeshDataPtr mMeshData;
+
+		/************************************************************************/
+		/* 								CLR HOOKS						   		*/
+		/************************************************************************/
 		static void internal_CreateInstance(MonoObject* instance, int numVertices,
 			int numIndices, VertexLayout vertex, ScriptIndexType index);
 		static MonoArray* internal_GetPositions(ScriptMeshData* thisPtr);
@@ -48,9 +81,5 @@ namespace BansheeEngine
 		static void internal_SetIndices(ScriptMeshData* thisPtr, MonoArray* value);
 		static int internal_GetVertexCount(ScriptMeshData* thisPtr);
 		static int internal_GetIndexCount(ScriptMeshData* thisPtr);
-
-		static bool checkIsLocked(ScriptMeshData* thisPtr);
-		
-		RendererMeshDataPtr mMeshData;
 	};
 }

+ 76 - 5
SBansheeEngine/Include/BsScriptObject.h

@@ -12,6 +12,10 @@ namespace BansheeEngine
 {
 	struct ScriptObjectBackup;
 
+	/**
+	 * @brief	Helper class to initialize all script interop objects
+	 *			as soon as the library is loaded.
+	 */
 	template <class Type, class Base>
 	struct InitScriptObjectOnStart
 	{
@@ -20,41 +24,83 @@ namespace BansheeEngine
 		{
 			ScriptObject<Type, Base>::_initMetaData();
 		}
-
-		void makeSureIAmInstantiated() { }
 	};
 
+	/**
+	 * @brief	Base class for all script interop objects. Interop
+	 *			objects form a connection between C++ and CLR classes
+	 *			and methods.
+	 */
 	class BS_SCR_BE_EXPORT ScriptObjectBase
 	{
 	public:
 		ScriptObjectBase(MonoObject* instance);
 		virtual ~ScriptObjectBase();
 
+		/**
+		 * @brief	Gets the managed object this interop object represents.
+		 */
 		MonoObject* getManagedInstance() const { return mManagedInstance; }
+
+		/**
+		 * @brief	Should the interop object persist through assembly reload.
+		 *			If false then the interop object will be destroyed on reload.
+		 */
 		virtual bool isPersistent() const { return false; }
 
+		/**
+		 * @brief	Clears any managed instance references from the interop object.
+		 *			Normally called right after the assemblies are unloaded.
+		 */
 		virtual void _clearManagedInstance() { }
+
+		/**
+		 * @brief	Allows persistent objects to restore their managed instances after
+		 *			assembly reload.
+		 */
 		virtual void _restoreManagedInstance() { }
+
+		/**
+		 * @brief	Called when the managed instance gets destroyed. Usually
+		 *			triggered by the runtime when the finalizer is called.
+		 */
 		virtual void _onManagedInstanceDeleted();
 
+		/**
+		 * @brief	Called before assembly reload starts to give the object a chance to
+		 *			back up its data.
+		 */
 		virtual ScriptObjectBackup beginRefresh();
+
+		/**
+		 * @brief	Called after assembly reload starts to give the object a chance
+		 *			to restore the data backed up by the previous ::beginRefresh call.
+		 */
 		virtual void endRefresh(const ScriptObjectBackup& data);
 
 	protected:
 		MonoObject* mManagedInstance;
 	};
 
+	/**
+	 * @brief	Base class for all persistent interop objects. Persistent objects
+	 *			persist through assembly reload.
+	 */
 	class BS_SCR_BE_EXPORT PersistentScriptObjectBase : public ScriptObjectBase
 	{
 	public:
 		PersistentScriptObjectBase(MonoObject* instance);
 		virtual ~PersistentScriptObjectBase();
 
+		/**
+		 * @copydoc	ScriptObjectBase::isPersistent 
+		 */
 		virtual bool isPersistent() const override { return true; }
 	};
 
 	/**
-	 * @brief	 Base class for objects that can be extended using Mono scripting
+	 * @brief	Template version of ScriptObjectBase populates the object
+	 *			meta-data on library load.
 	 */
 	template <class Type, class Base = ScriptObjectBase>
 	class ScriptObject : public Base
@@ -78,6 +124,9 @@ namespace BansheeEngine
 		virtual ~ScriptObject() 
 		{ }
 
+		/**
+		 * @copydoc	ScriptObjectBase::_clearManagedInstance
+		 */
 		void _clearManagedInstance()
 		{
 			if (metaData.thisPtrField != nullptr && mManagedInstance != nullptr)
@@ -86,6 +135,9 @@ namespace BansheeEngine
 			mManagedInstance = nullptr;
 		}
 
+		/**
+		 * @copydoc	ScriptObjectBase::_restoreManagedInstance
+		 */
 		void _restoreManagedInstance()
 		{
 			mManagedInstance = _createManagedInstance(true);
@@ -96,11 +148,19 @@ namespace BansheeEngine
 				metaData.thisPtrField->setValue(mManagedInstance, &param);
 		}
 
+		/**
+		 * @brief	Creates a new managed instance of the type wrapped
+		 *			by this interop object.
+		 */
 		virtual MonoObject* _createManagedInstance(bool construct)
 		{
 			return metaData.scriptClass->createInstance(construct);
 		}
 
+		/**
+		 * @brief	Converts a managed instance into a specific interop object.
+		 *			Caller must ensure the managed instance is of the proper type.
+		 */
 		static Type* toNative(MonoObject* managedInstance)
 		{
 			Type* nativeInstance = nullptr;
@@ -111,8 +171,16 @@ namespace BansheeEngine
 			return nativeInstance;
 		}
 
+		/**
+		 * @brief	Returns the meta-data containing class and method information
+		 *			for the managed type.
+		 */
 		static const ScriptMeta* getMetaData() { return &metaData; }
 
+		/**
+		 * @brief	Initializes the meta-data containing class and method information
+		 *			for the managed type. Called on library load and on assembly reload.
+		 */
 		static void _initMetaData()
 		{
 			metaData = ScriptMeta(Type::getAssemblyName(), Type::getNamespace(), Type::getTypeName(), &Type::initRuntimeData);
@@ -124,15 +192,18 @@ namespace BansheeEngine
 		static ScriptMeta metaData;
 
 	private:
-		static InitScriptObjectOnStart<Type, Base> initOnStart;
+		static volatile InitScriptObjectOnStart<Type, Base> initOnStart;
 	};
 
 	template <typename Type, typename Base>
-	InitScriptObjectOnStart<Type, Base> ScriptObject<Type, Base>::initOnStart;
+	volatile InitScriptObjectOnStart<Type, Base> ScriptObject<Type, Base>::initOnStart;
 
 	template <typename Type, typename Base>
 	ScriptMeta ScriptObject<Type, Base>::metaData;
 
+	/**
+	 * @brief	Contains backed up interop object data.
+	 */
 	struct ScriptObjectBackup
 	{
 		Any data;

+ 6 - 0
SBansheeEngine/Include/BsScriptObjectImpl.h

@@ -6,6 +6,9 @@
 
 namespace BansheeEngine
 {
+	/**
+	 * @brief	Interop class between C++ & CLR for ScriptObject.
+	 */
 	class BS_SCR_BE_EXPORT ScriptObjectImpl : public ScriptObject<ScriptObjectImpl>
 	{
 	public:
@@ -14,6 +17,9 @@ namespace BansheeEngine
 	private:
 		ScriptObjectImpl(MonoObject* instance);
 
+		/************************************************************************/
+		/* 								CLR HOOKS						   		*/
+		/************************************************************************/
 		static void internal_managedInstanceDeleted(ScriptObjectBase* instance);
 	};
 }

+ 27 - 2
SBansheeEngine/Include/BsScriptObjectManager.h

@@ -5,17 +5,35 @@
 
 namespace BansheeEngine
 {
+	/**
+	 * @brief	Keeps track of all script interop objects and handles assembly refresh.
+	 */
 	class BS_SCR_BE_EXPORT ScriptObjectManager : public Module <ScriptObjectManager>
 	{
 	public:
 		ScriptObjectManager();
 		~ScriptObjectManager();
 
+		/**
+		 * @brief	Registers a newly created script interop object.
+		 */
 		void registerScriptObject(ScriptObjectBase* instance);
+
+		/**
+		 * @brief	Unregisters a script interop object that is no longer valid.
+		 */
 		void unregisterScriptObject(ScriptObjectBase* instance);
 
+		/**
+		 * @brief	Reloads all script assemblies. This involves backup up managed
+		 *			object data, destroying all managed objects and restoring
+		 *			the objects after reload.
+		 */
 		void refreshAssemblies();
 
+		/**
+		 * @brief	Called once per frame. Triggers queued finalizer callbacks.
+		 */
 		void update();
 
 		/**
@@ -30,8 +48,6 @@ namespace BansheeEngine
 		/**
 		 * @brief	Triggers _onManagedInstanceDeleted deleted callbacks on all objects that were finalized this frame.
 		 *			This allows the native portions of those objects to properly clean up any resources.
-		 *
-		 * @note	Sim thread.
 		 */
 		void processFinalizedObjects();
 
@@ -41,7 +57,16 @@ namespace BansheeEngine
 		 */
 		Event<void()> onRefreshDomainLoaded;
 
+		/**
+		 * @brief	Triggered just before the assembly refresh starts. At this point all managed
+		 *			objects are still valid, but are about to be destroyed.
+		 */
 		Event<void()> onRefreshStarted;
+
+		/**
+		 * @brief	Triggered after the assembly refresh ends. New assemblies should be loaded at
+		 *			this point.
+		 */
 		Event<void()> onRefreshComplete;
 	private:
 		Set<ScriptObjectBase*> mScriptObjects;

+ 25 - 4
SBansheeEngine/Include/BsScriptPixelData.h

@@ -7,21 +7,46 @@
 
 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);
@@ -35,9 +60,5 @@ namespace BansheeEngine
 		static void internal_getSlicePitch(ScriptPixelData* thisPtr, int* value);
 		static void internal_getSize(ScriptPixelData* thisPtr, int* value);
 		static void internal_getIsConsecutive(ScriptPixelData* thisPtr, bool* value);
-
-		static bool checkIsLocked(ScriptPixelData* thisPtr);
-
-		PixelDataPtr mPixelData;
 	};
 }

+ 8 - 2
SBansheeEngine/Include/BsScriptPixelUtility.h

@@ -7,12 +7,20 @@
 
 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);
@@ -24,7 +32,5 @@ namespace BansheeEngine
 		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);
-
-		ScriptPixelUtility(MonoObject* instance);
 	};
 }

+ 26 - 7
SBansheeEngine/Include/BsScriptPlainText.h

@@ -7,26 +7,45 @@
 
 namespace BansheeEngine
 {
+	/**
+	 * @brief	Interop class between C++ & CLR for PlainText.
+	 */
 	class BS_SCR_BE_EXPORT ScriptPlainText : public ScriptObject <ScriptPlainText, ScriptResourceBase>
 	{
 	public:
 		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "PlainText")
 
-		HResource getNativeHandle() const { return mPlainText; }
-		void setNativeHandle(const HResource& resource);
+		/**
+		 * @copydoc	ScriptResourceBase::getNativeHandle
+		 */
+		HResource getNativeHandle() const override { return mPlainText; }
 
+		/**
+		 * @copydoc	ScriptResourceBase::setNativeHandle
+		 */
+		void setNativeHandle(const HResource& resource) override;
+
+		/**
+		 * @brief	Returns the internal wrapped plain text resource.
+		 */
 		HPlainText getPlainTextHandle() const { return mPlainText; }
 	private:
 		friend class ScriptResourceManager;
 
-		static void internal_createInstance(MonoObject* instance, MonoString* text);
-		static MonoString* internal_getText(ScriptPlainText* thisPtr);
-		static void internal_setText(ScriptPlainText* thisPtr, MonoString* text);
-
 		ScriptPlainText(MonoObject* instance, const HPlainText& plainText);
 
-		void _onManagedInstanceDeleted();
+		/**
+		 * @copydoc	ScriptObjectBase::_onManagedInstanceDeleted
+		 */
+		void _onManagedInstanceDeleted() override;
 
 		HPlainText mPlainText;
+
+		/************************************************************************/
+		/* 								CLR HOOKS						   		*/
+		/************************************************************************/
+		static void internal_createInstance(MonoObject* instance, MonoString* text);
+		static MonoString* internal_getText(ScriptPlainText* thisPtr);
+		static void internal_setText(ScriptPlainText* thisPtr, MonoString* text);
 	};
 }

+ 24 - 5
SBansheeEngine/Include/BsScriptPrefab.h

@@ -6,26 +6,45 @@
 
 namespace BansheeEngine
 {
+	/**
+	 * @brief	Interop class between C++ & CLR for Prefab.
+	 */
 	class BS_SCR_BE_EXPORT ScriptPrefab : public ScriptObject<ScriptPrefab, ScriptResourceBase>
 	{
 	public:
 		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "Prefab")
 
+		/**
+		 * @copydoc	ScriptResourceBase::getNativeHandle
+		 */
 		HResource getNativeHandle() const override { return mPrefab; }
-		void setNativeHandle(const HResource& resource);
 
+		/**
+		 * @copydoc	ScriptResourceBase::setNativeHandle
+		 */
+		void setNativeHandle(const HResource& resource) override;
+
+		/**
+		 * @brief	Returns the internal wrapped prefab resource.
+		 */
 		HPrefab getPrefabHandle() const { return mPrefab; }
 	private:
 		friend class ScriptResourceManager;
 
 		ScriptPrefab(MonoObject* instance, const HPrefab& prefab);
 
+		/**
+		 * @copydoc	ScriptObjectBase::_onManagedInstanceDeleted
+		 */
+		void _onManagedInstanceDeleted() override;
+
+		HPrefab mPrefab;
+
+		/************************************************************************/
+		/* 								CLR HOOKS						   		*/
+		/************************************************************************/
 		static void internal_CreateInstance(MonoObject* instance, ScriptSceneObject* so);
 		static MonoObject* internal_GetRoot(ScriptPrefab* instance);
 		static MonoObject* internal_Instantiate(ScriptPrefab* instance);
-
-		void _onManagedInstanceDeleted();
-
-		HPrefab mPrefab;
 	};
 }

+ 11 - 2
SBansheeEngine/Include/BsScriptProfilerOverlayInternal.h

@@ -6,22 +6,31 @@
 
 namespace BansheeEngine
 {
+	/**
+	 * @brief	Interop class between C++ & CLR for ProfilerOverlayInternal.
+	 */
 	class BS_SCR_BE_EXPORT ScriptProfilerOverlayInternal : public ScriptObject < ScriptProfilerOverlayInternal >
 	{
 	public:
 		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "ProfilerOverlayInternal")
 
+		/**
+		 * @brief	Returns the native profiler overlay instance.
+		 */
 		ProfilerOverlayInternal* getInternal() const { return mProfilerOverlayInternal; }
 
 	private:
 		ScriptProfilerOverlayInternal(MonoObject* managedInstance, const SPtr<CameraHandler>& camera);
 		~ScriptProfilerOverlayInternal();
 
+		ProfilerOverlayInternal* mProfilerOverlayInternal;
+
+		/************************************************************************/
+		/* 								CLR HOOKS						   		*/
+		/************************************************************************/
 		static void internal_CreateInstance(MonoObject* instance, ScriptCameraHandler* camera);
 		static void internal_SetType(ScriptProfilerOverlayInternal* thisPtr, ProfilerOverlayType type);
 		static void internal_Update(ScriptProfilerOverlayInternal* thisPtr);
 		static void internal_DestroyInstance(ScriptProfilerOverlayInternal* thisPtr);
-
-		ProfilerOverlayInternal* mProfilerOverlayInternal;
 	};
 }

+ 12 - 0
SBansheeEngine/Include/BsScriptRenderTarget.h

@@ -5,9 +5,15 @@
 
 namespace BansheeEngine
 {
+	/**
+	 * @brief	Base interop class for any types deriving from RenderTarget.
+	 */
 	class BS_SCR_BE_EXPORT ScriptRenderTargetBase : public ScriptObjectBase
 	{
 	public:
+		/**
+		 * @brief	Returns the native render target this object wraps.
+		 */
 		virtual RenderTargetPtr getNativeValue() const = 0;
 
 	protected:
@@ -20,6 +26,9 @@ namespace BansheeEngine
 		virtual ~ScriptRenderTargetBase() {}
 	};
 
+	/**
+	 * @brief	Interop class between C++ & CLR for RenderTarget.
+	 */
 	class BS_SCR_BE_EXPORT ScriptRenderTarget : public ScriptObject<ScriptRenderTarget, ScriptRenderTargetBase>
 	{
 	public:
@@ -28,6 +37,9 @@ namespace BansheeEngine
 	private:
 		ScriptRenderTarget(MonoObject* instance);
 
+		/************************************************************************/
+		/* 								CLR HOOKS						   		*/
+		/************************************************************************/
 		static void internal_getWidth(ScriptRenderTarget* thisPtr, int* value);
 		static void internal_getHeight(ScriptRenderTarget* thisPtr, int* value);
 		static void internal_getGammaCorrection(ScriptRenderTarget* thisPtr, bool* value);

+ 3 - 0
SBansheeEngine/Include/BsScriptRenderTexture.h

@@ -5,6 +5,9 @@
 
 namespace BansheeEngine
 {
+	/**
+	 * @brief	Interop class between C++ & CLR for RenderTexture.
+	 */
 	class BS_SCR_BE_EXPORT ScriptRenderTexture : public ScriptObject <ScriptRenderTexture, ScriptRenderTargetBase>
 	{
 	public:

+ 24 - 5
SBansheeEngine/Include/BsScriptRenderTexture2D.h

@@ -6,26 +6,45 @@
 
 namespace BansheeEngine
 {
+	/**
+	 * @brief	Interop class between C++ & CLR for a single or multi RenderTexture using a 2D texture.
+	 */
 	class BS_SCR_BE_EXPORT ScriptRenderTexture2D : public ScriptObject < ScriptRenderTexture2D, ScriptRenderTargetBase >
 	{
 	public:
 		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "RenderTexture2D")
 
-		RenderTargetPtr getNativeValue() const { return mRenderTarget; }
+		/**
+		 * @copydoc	ScriptRenderTargetBase::getNativeValue
+		 */
+		RenderTargetPtr getNativeValue() const override { return mRenderTarget; }
+
+		/**
+		 * @brief	Returns the internal wrapped render texture. Returns null if this object
+		 *			instead wraps a multi render target.
+		 */
 		RenderTexturePtr getRenderTexture() const;
+
+		/**
+		 * @brief	Returns the internal wrapped multi render texture. Returns null if this object
+		 *			instead wraps a single render target.
+		 */
 		MultiRenderTexturePtr getMultiRenderTexture() const;
 
 	private:
 		ScriptRenderTexture2D(const RenderTargetPtr& target, bool isMulti, MonoObject* instance);
 
-		static void internal_createDetailed(MonoObject* instance, PixelFormat format, UINT32 width, UINT32 height, 
+		RenderTargetPtr mRenderTarget;
+		bool mIsMulti;
+
+		/************************************************************************/
+		/* 								CLR HOOKS						   		*/
+		/************************************************************************/
+		static void internal_createDetailed(MonoObject* instance, PixelFormat format, UINT32 width, UINT32 height,
 			UINT32 numSamples, bool gammaCorrection, bool createDepth, PixelFormat depthStencilFormat);
 		static void internal_create(MonoObject* instance, MonoArray* colorSurfaces, MonoObject* depthStencilSurface);
 
 		static void internal_getColorSurfaces(ScriptRenderTexture2D* thisPtr, MonoArray** value);
 		static void internal_getDepthStencilSurface(ScriptRenderTexture2D* thisPtr, MonoObject** value);
-
-		RenderTargetPtr mRenderTarget;
-		bool mIsMulti;
 	};
 }

+ 21 - 5
SBansheeEngine/Include/BsScriptRenderableHandler.h

@@ -5,19 +5,40 @@
 
 namespace BansheeEngine
 {
+	/**
+	 * @brief	Interop class between C++ & CLR for RenderableHandler.
+	 */
 	class BS_SCR_BE_EXPORT ScriptRenderableHandler : public ScriptObject < ScriptRenderableHandler >
 	{
 	public:
 		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "RenderableHandler")
 
+		/**
+		 * @brief	Returns the native wrapped renderable handler.
+		 */
 		SPtr<RenderableHandler> getInternal() const { return mRenderableHandler; }
 
 	private:
 		ScriptRenderableHandler(MonoObject* managedInstance, const HSceneObject& parentSO);
 		~ScriptRenderableHandler();
 
+		/**
+		 * @brief	Updates the internal transform of the renderable handled according to
+		 *			the scene object it is attached to.
+		 */
 		void updateTransform(const HSceneObject& parent);
 
+		/**
+		 * @brief	Destroys the internal renderable handler object.
+		 */
+		void destroy();
+
+		SPtr<RenderableHandler> mRenderableHandler;
+		UINT32 mLastUpdateHash;
+
+		/************************************************************************/
+		/* 								CLR HOOKS						   		*/
+		/************************************************************************/
 		static void internal_Create(MonoObject* instance, ScriptSceneObject* parentSO);
 		static void internal_UpdateTransform(ScriptRenderableHandler* thisPtr, ScriptSceneObject* parentSO);
 		static void internal_SetMesh(ScriptRenderableHandler* thisPtr, ScriptMesh* mesh);
@@ -26,10 +47,5 @@ namespace BansheeEngine
 		static void internal_SetLayers(ScriptRenderableHandler* thisPtr, UINT64 layers);
 		static void internal_SetMaterial(ScriptRenderableHandler* thisPtr, ScriptMaterial* material, int index);
 		static void internal_OnDestroy(ScriptRenderableHandler* thisPtr);
-
-		void destroy();
-
-		SPtr<RenderableHandler> mRenderableHandler;
-		UINT32 mLastUpdateHash;
 	};
 }

+ 34 - 6
SBansheeEngine/Include/BsScriptResource.h

@@ -5,19 +5,40 @@
 
 namespace BansheeEngine
 {
+	/**
+	 * @brief	Types of resources accessible from script code.
+	 */
+	// Note: Must be the same as C# enum ScriptResourceType
 	enum class ScriptResourceType
 	{
 		Texture, SpriteTexture, Mesh, Font, Shader, Material, Prefab, PlainText, ScriptCode, StringTable, Undefined
 	};
 
+	/**
+	 * @brief	Base class for all resource interop objects.
+	 */
 	class BS_SCR_BE_EXPORT ScriptResourceBase : public PersistentScriptObjectBase
 	{
 	public:
+		/**
+		 * @brief	Returns the internal wrapped resource.
+		 */
 		virtual HResource getNativeHandle() const = 0;
+
+		/**
+		 * @brief	Sets the internal resource this object wraps.
+		 */
 		virtual void setNativeHandle(const HResource& resource) = 0;
 
-		virtual ScriptObjectBackup beginRefresh();
-		virtual void endRefresh(const ScriptObjectBackup& backupData);
+		/**
+		 * @copydoc	ScriptObjectBase::beginRefresh
+		 */
+		virtual ScriptObjectBackup beginRefresh() override;
+
+		/**
+		 * @copydoc	ScriptObjectBase::endRefresh
+		 */
+		virtual void endRefresh(const ScriptObjectBackup& backupData) override;
 
 	protected:
 		friend class ScriptResourceManager;
@@ -28,15 +49,22 @@ namespace BansheeEngine
 		bool mRefreshInProgress;
 	};
 
+	/**
+	 * @brief	Interop class between C++ & CLR for Resource.
+	 */
 	class BS_SCR_BE_EXPORT ScriptResource : public ScriptObject<ScriptResource, ScriptResourceBase>
 	{
 	public:
-		static String getAssemblyName() { return ENGINE_ASSEMBLY; }
-		static String getNamespace() { return "BansheeEngine"; }
-		static String getTypeName() { return "Resource"; }
-		static void initRuntimeData() { }
+		SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "Resource")
 
+		/**
+		 * @brief	Converts a RTTI id belonging to a resource type into a ScriptResourceType.
+		 */
 		static ScriptResourceType getTypeFromTypeId(UINT32 typeId);
+
+		/**
+		 * @brief	Converts a ScriptResourceType into a RTTI id belonging to that resource type.
+		 */
 		static UINT32 getTypeIdFromType(ScriptResourceType type);
 	private:
 		ScriptResource(MonoObject* instance)

+ 55 - 9
SBansheeEngine/Include/BsScriptResourceManager.h

@@ -6,48 +6,94 @@
 
 namespace BansheeEngine
 {
+	/**
+	 * @brief	Handles creation and lookup of script interop objects for resources.
+	 *			Since resources can be created in native code yet used by managed code
+	 *			this manager provides lookups to find managed equivalents of
+	 *			native resources.
+	 */
 	class BS_SCR_BE_EXPORT ScriptResourceManager : public Module<ScriptResourceManager>
 	{
 	public:
 		ScriptResourceManager();
 
 		/**
-		 * @note Throws an exception if resource for the handle already exists.
-		 * 		 Creates a new managed instance of the object.
+		 * @brief	Creates a new managed instance and interop object for the specified resource.
+		 *
+		 * @param	resourceHandle	Native resource to wrap in a managed instance.
+		 * @param	out				Output interop object corresponding to the new managed instance.
+		 *
+		 * @note	Throws an exception if a managed instance for the provided resource already exists.
 		 */
 		template<class RetType, class InType>
 		void createScriptResource(const ResourceHandle<InType>& resourceHandle, RetType** out);
 
 		/**
-		 * @note Throws an exception if resource for the handle already exists.
-		 * 		 Initializes the ScriptResource with an existing managed instance.
+		 * @brief	Creates a new interop object for the specified resource using an existing managed instance.
+		 *
+		 * @param	existingInstance	Existing managed instance. Caller must ensure the managed instance
+		 *								matches the native resource type.
+		 * @param	resourceHandle		Native resource to link to the managed instance.
+		 * @param	out					Output interop object corresponding to the new managed instance.
+		 *
+		 * @note	Throws an exception if a managed instance for the provided resource already exists.
 		 */
 		template<class RetType, class InType>
 		void createScriptResource(MonoObject* existingInstance, const ResourceHandle<InType>& resourceHandle, RetType** out);
 
 		/**
-		 * @note If @p create is true, creates a new script resource if one doesn't exist, 
-		 *		 otherwise returns nullptr if script resource doesn't exist.
+		 * @brief	Attempts to find an existing interop object for the specified resource, and optionally
+		 *			creates a new one if one cannot be found.
+		 * 
+		 * @param	resourceHandle	Resource to search for.
+		 * @param	out				Found or created interop object containing the resource.
+		 * @param	create			If a resource cannot be found new one will be created when this
+		 *							is true. If false and the resource doesn't exist it will be null.
 		 */
 		template<class RetType, class InType>
 		void getScriptResource(const ResourceHandle<InType>& resourceHandle, RetType** out, bool create = false);
 
+		/**
+		 * @brief	Creates a new managed instance and interop object for the specified string table.
+		 *
+		 * @param	resourceHandle	Native string table resource to wrap in a managed instance.
+		 * @param	out				Output string table interop object corresponding to the new managed instance.
+		 *
+		 * @note	Throws an exception if a managed instance for the provided resource already exists.
+		 */
 		template<>
 		void createScriptResource(const ResourceHandle<StringTable>& resourceHandle, ScriptStringTable** out);
 
+		/**
+		 * @brief	Creates a new managed instance and interop object for the specified resource.
+		 *
+		 * @param	resourceHandle	Native resource to wrap in a managed instance.
+		 * @param	out				Output interop object corresponding to the new managed instance.
+		 *
+		 * @note	Throws an exception if a managed instance for the provided resource already exists.
+		 */
 		template<>
 		void createScriptResource(const HResource& resourceHandle, ScriptResourceBase** out);
 
 		/**
-		 * @note Returns nullptr if script resource doesn't exist.
+		 * @brief	Attempts to find a resource interop object for a resource with the specified UUID.
+		 *			Returns null if the object cannot be found.
 		 */
 		ScriptResourceBase* getScriptResource(const String& UUID);
 
+		/**
+		 * @brief	Deletes the provided resource interop objects. All resource interop objects
+		 *			should be deleted using this method.
+		 */
 		void destroyScriptResource(ScriptResourceBase* resource);
 
 	private:
-		UnorderedMap<String, ScriptResourceBase*> mScriptResources;
-
+		/**
+		 * @brief	Throws an exception if the provided UUID already exists in the interop object
+		 *			lookup table.
+		 */
 		void throwExceptionIfInvalidOrDuplicate(const String& uuid) const;
+
+		UnorderedMap<String, ScriptResourceBase*> mScriptResources;
 	};
 }

+ 5 - 0
SBansheeEngine/Source/BsScriptResource.cpp

@@ -20,6 +20,11 @@ namespace BansheeEngine
 		PersistentScriptObjectBase::endRefresh(backupData);
 	}
 
+	void ScriptResource::initRuntimeData()
+	{
+		
+	}
+
 	ScriptResourceType ScriptResource::getTypeFromTypeId(UINT32 typeId)
 	{
 		switch (typeId)

+ 3 - 2
TODO.txt

@@ -54,9 +54,10 @@ Code quality improvements:
 ----------------------------------------------------------------------
 Polish
 
-SceneTreeView
- - When having scene window in focus and then right clicking on Hierarchy the cursor becomes invisible
  - Duplicating a mesh doesn't properly render the mesh
+  - It seems to be due to renderables sharing materials. I generate a separate per-object buffer per each
+    renderable (but maybe I shouldn't? Just generate the one and update it before rendering) and then assign
+	it to the same MaterialCore which means whichever one was applied last was the one that sticks.
 
 Ribek use:
  - Camera, Renderable, Material, Texture inspector