Browse Source

Bugfix: Getting Skybox component operational in the editor

BearishSun 8 years ago
parent
commit
5c727c9470

+ 7 - 0
Source/BansheeCore/Components/BsCSkybox.cpp

@@ -33,6 +33,13 @@ namespace bs
 			mInternal->initialize();
 		else
 			mInternal = Skybox::create();
+
+		gSceneManager()._bindActor(mInternal, sceneObject());
+	}
+
+	void CSkybox::onDestroyed()
+	{
+		gSceneManager()._unbindActor(mInternal);
 	}
 
 	RTTITypeBase* CSkybox::getRTTIStatic()

+ 3 - 0
Source/BansheeCore/Components/BsCSkybox.h

@@ -60,6 +60,9 @@ namespace bs
 		/** @copydoc Component::onInitialized */
 		void onInitialized() override;
 
+		/** @copydoc Component::onDestroyed */
+		void onDestroyed() override;
+
 		/** @copydoc Component::update */
 		void update() override { }
 

+ 1 - 1
Source/BansheeCore/RTTI/BsSkyboxRTTI.h

@@ -58,7 +58,7 @@ namespace bs
 
 		SPtr<IReflectable> newRTTIObject() override
 		{
-			return Skybox::create();
+			return Skybox::createEmpty();
 		}
 	};
 

+ 1 - 1
Source/BansheeCore/Renderer/BsRenderable.h

@@ -208,7 +208,7 @@ namespace bs
 		/** @copydoc IResourceListener::notifyResourceChanged */
 		void notifyResourceChanged(const HResource& resource) override;
 
-		/**	Creates a new renderable handler instance without initializing it. */
+		/**	Creates a new renderable instance without initializing it. */
 		static SPtr<Renderable> createEmpty();
 
 		SPtr<Animation> mAnimation;

+ 38 - 23
Source/BansheeCore/Renderer/BsSkybox.cpp

@@ -12,17 +12,9 @@
 namespace bs
 {
 	SkyboxBase::SkyboxBase()
-		: mIsActive(true), mBrightness(1.0f)
+		: mBrightness(1.0f)
 	{ }
 
-	template <bool Core>
-	TSkybox<Core>::TSkybox()
-		: SkyboxBase()
-	{ }
-
-	template class TSkybox<true>;
-	template class TSkybox<false>;
-
 	Skybox::Skybox()
 	{
 		// This shouldn't normally happen, as filtered textures are generated when a radiance texture is assigned, but
@@ -100,16 +92,36 @@ namespace bs
 		ct::gRenderer()->addTask(mRendererTask);
 	}
 
+	void Skybox::setTexture(const HTexture& texture)
+	{
+		mTexture = texture; 
+
+		mFilteredRadiance = nullptr;
+		mIrradiance = nullptr;
+
+		if(mTexture.isLoaded())
+			filterTexture();
+
+		_markCoreDirty((ActorDirtyFlag)SkyboxDirtyFlag::Texture);
+	}
+
 	SPtr<ct::Skybox> Skybox::getCore() const
 	{
 		return std::static_pointer_cast<ct::Skybox>(mCoreSpecific);
 	}
 
-	SPtr<Skybox> Skybox::create()
+	SPtr<Skybox> Skybox::createEmpty()
 	{
 		Skybox* skybox = new (bs_alloc<Skybox>()) Skybox();
 		SPtr<Skybox> skyboxPtr = bs_core_ptr<Skybox>(skybox);
 		skyboxPtr->_setThisPtr(skyboxPtr);
+
+		return skyboxPtr;
+	}
+
+	SPtr<Skybox> Skybox::create()
+	{
+		SPtr<Skybox> skyboxPtr = createEmpty();
 		skyboxPtr->initialize();
 
 		return skyboxPtr;
@@ -117,6 +129,10 @@ namespace bs
 
 	SPtr<ct::CoreObject> Skybox::createCore() const
 	{
+		SPtr<ct::Texture> radiance;
+		if (mTexture)
+			radiance = mTexture->getCore();
+
 		SPtr<ct::Texture> filteredRadiance;
 		if (mFilteredRadiance)
 			filteredRadiance = mFilteredRadiance->getCore();
@@ -125,7 +141,7 @@ namespace bs
 		if (mIrradiance)
 			irradiance = mIrradiance->getCore();
 
-		ct::Skybox* skybox = new (bs_alloc<ct::Skybox>()) ct::Skybox(filteredRadiance, irradiance);
+		ct::Skybox* skybox = new (bs_alloc<ct::Skybox>()) ct::Skybox(radiance, filteredRadiance, irradiance);
 		SPtr<ct::Skybox> skyboxPtr = bs_shared_ptr<ct::Skybox>(skybox);
 		skyboxPtr->_setThisPtr(skyboxPtr);
 
@@ -135,7 +151,7 @@ namespace bs
 	CoreSyncData Skybox::syncToCore(FrameAlloc* allocator)
 	{
 		UINT32 size = 0;
-		size += rttiGetElemSize(mIsActive);
+		size += getActorSyncDataSize();
 		size += rttiGetElemSize(mBrightness);
 		size += sizeof(SPtr<ct::Texture>);
 		size += rttiGetElemSize(getCoreDirtyFlags());
@@ -143,7 +159,7 @@ namespace bs
 		UINT8* buffer = allocator->alloc(size);
 
 		char* dataPtr = (char*)buffer;
-		dataPtr = rttiWriteElem(mIsActive, dataPtr);
+		dataPtr = syncActorTo(dataPtr);
 		dataPtr = rttiWriteElem(mBrightness, dataPtr);
 		dataPtr = rttiWriteElem(getCoreDirtyFlags(), dataPtr);
 
@@ -158,11 +174,8 @@ namespace bs
 		return CoreSyncData(buffer, size);
 	}
 
-	void Skybox::_markCoreDirty(SkyboxDirtyFlag flags)
+	void Skybox::_markCoreDirty(ActorDirtyFlag flags)
 	{
-		if(flags == SkyboxDirtyFlag::Texture)
-			filterTexture();
-
 		markCoreDirty((UINT32)flags);
 	}
 
@@ -178,9 +191,11 @@ namespace bs
 
 	namespace ct
 	{
-		Skybox::Skybox(const SPtr<Texture>& filteredRadiance, const SPtr<Texture>& irradiance)
+		Skybox::Skybox(const SPtr<Texture>& radiance, const SPtr<Texture>& filteredRadiance, const SPtr<Texture>& irradiance)
 			:mFilteredRadiance(filteredRadiance), mIrradiance(irradiance)
-		{ }
+		{
+			mTexture = radiance;
+		}
 
 		Skybox::~Skybox()
 		{
@@ -199,9 +214,9 @@ namespace bs
 			char* dataPtr = (char*)data.getBuffer();
 
 			SkyboxDirtyFlag dirtyFlags;
-			bool oldIsActive = mIsActive;
+			bool oldIsActive = mActive;
 
-			dataPtr = rttiReadElem(mIsActive, dataPtr);
+			dataPtr = syncActorFrom(dataPtr);
 			dataPtr = rttiReadElem(mBrightness, dataPtr);
 			dataPtr = rttiReadElem(dirtyFlags, dataPtr);
 
@@ -211,9 +226,9 @@ namespace bs
 			texture->~SPtr<Texture>();
 			dataPtr += sizeof(SPtr<Texture>);
 
-			if (oldIsActive != mIsActive)
+			if (oldIsActive != mActive)
 			{
-				if (mIsActive)
+				if (mActive)
 					gRenderer()->notifySkyboxAdded(this);
 				else
 					gRenderer()->notifySkyboxRemoved(this);

+ 27 - 44
Source/BansheeCore/Renderer/BsSkybox.h

@@ -5,6 +5,7 @@
 #include "BsCorePrerequisites.h"
 #include "Reflection/BsIReflectable.h"
 #include "CoreThread/BsCoreObject.h"
+#include "Scene/BsSceneActor.h"
 
 namespace bs
 {
@@ -17,26 +18,21 @@ namespace bs
 	 *  @{
 	 */
 
-	/**	Signals which portion of a skybox is dirty. */
+	/**	Signals which portion of a Skybox is dirty. */
 	enum class SkyboxDirtyFlag
 	{
-		Texture = 0x01,
-		Everything = 0x02
+		// First few bits reserved by ActorDiryFlag
+		Texture = 1 << 4
 	};
 
+
 	/** Base class for both core and sim thread implementations of a skybox. */
-	class BS_CORE_EXPORT SkyboxBase
+	class BS_CORE_EXPORT SkyboxBase : public SceneActor
 	{
 	public:
 		SkyboxBase();
 		virtual ~SkyboxBase() { }
 
-		/**	Checks whether the skybox should be used or not. */
-		bool getIsActive() const { return mIsActive; }
-
-		/**	Sets whether the skybox should be used or not. */
-		void setIsActive(bool active) { mIsActive = active; _markCoreDirty(); }
-
 		/** 
 		 * Brightness multiplier that will be applied to skybox values before they're being used. Allows you to make the
 		 * skybox more or less bright. Equal to one by default. 
@@ -46,40 +42,10 @@ namespace bs
 		/** @see setBrightness */
 		float getBrightness() const { return mBrightness; }
 
-		/**
-		 * Marks the simulation thread object as dirty and notifies the system its data should be synced with its core
-		 * thread counterpart.
-		 */
-		virtual void _markCoreDirty(SkyboxDirtyFlag flags = SkyboxDirtyFlag::Everything) { }
-
 	protected:
-		bool mIsActive; /**< Determines whether the skybox should be rendered or not. */
 		float mBrightness; /**< Multiplier to apply to evaluated skybox values before using them. */
 	};
 
-	/** Templated base class for both core and sim thread implementations of a skybox. */
-	template<bool Core>
-	class BS_CORE_EXPORT TSkybox : public SkyboxBase
-	{
-		typedef typename TTextureType<Core>::Type TextureType;
-
-	public:
-		TSkybox();
-		virtual ~TSkybox() { }
-
-		/**
-		 * Assigns an environment map to use for sampling skybox radiance. Must be a cube-map texture, and should ideally
-		 * contain HDR data.
-		 */
-		void setTexture(const TextureType& texture) { mTexture = texture; _markCoreDirty(SkyboxDirtyFlag::Texture); }
-
-		/** Gets the texture assigned through setTexture(). */
-		TextureType getTexture() const { return mTexture; }
-
-	protected:
-		TextureType mTexture;
-	};
-
 	/** @} */
 	/** @addtogroup Renderer-Internal
 	 *  @{
@@ -88,10 +54,19 @@ namespace bs
 	namespace ct { class Skybox; }
 
 	/** Allows you to specify an environment map to use for sampling radiance of the sky. */
-	class BS_CORE_EXPORT Skybox : public IReflectable, public CoreObject, public TSkybox<false>
+	class BS_CORE_EXPORT Skybox : public IReflectable, public CoreObject, public SkyboxBase
 	{
 	public:
 		~Skybox();
+
+		/**
+		 * Determines an environment map to use for sampling skybox radiance. Must be a cube-map texture, and should ideally
+		 * contain HDR data.
+		 */
+		void setTexture(const HTexture& texture);
+
+		/** @copydoc setTexture */
+		HTexture getTexture() const { return mTexture; }
 		
 		/**	Retrieves an implementation of the skybox usable only from the core thread. */
 		SPtr<ct::Skybox> getCore() const;
@@ -112,11 +87,12 @@ namespace bs
 		SPtr<ct::CoreObject> createCore() const override;
 
 		/** @copydoc SkyboxBase::_markCoreDirty */
-		void _markCoreDirty(SkyboxDirtyFlag flags = SkyboxDirtyFlag::Everything) override;
+		void _markCoreDirty(ActorDirtyFlag flags = ActorDirtyFlag::Everything) override;
 
 		/** @copydoc CoreObject::syncToCore */
 		CoreSyncData syncToCore(FrameAlloc* allocator) override;
 
+		HTexture mTexture;
 		SPtr<Texture> mFilteredRadiance;
 		SPtr<Texture> mIrradiance;
 		SPtr<ct::RendererTask> mRendererTask;
@@ -128,16 +104,22 @@ namespace bs
 		friend class SkyboxRTTI;
 		static RTTITypeBase* getRTTIStatic();
 		RTTITypeBase* getRTTI() const override;
+
+		/**	Creates a new skybox instance without initializing it. */
+		static SPtr<Skybox> createEmpty();
 	};
 
 	namespace ct
 	{
 		/** Core thread usable version of a bs::Skybox */
-		class BS_CORE_EXPORT Skybox : public CoreObject, public TSkybox<true>
+		class BS_CORE_EXPORT Skybox : public CoreObject, public SkyboxBase
 		{
 		public:
 			~Skybox();
 
+			/** @copydoc bs::Skybox::setTexture */
+			SPtr<Texture> getTexture() const { return mTexture; }
+		
 			/** 
 			 * Returns a texture containing filtered version of the radiance texture used for reflections. This might not
 			 * be available if it hasn't been generated yet.
@@ -152,7 +134,7 @@ namespace bs
 		protected:
 			friend class bs::Skybox;
 
-			Skybox(const SPtr<Texture>& filteredRadiance, const SPtr<Texture>& irradiance);
+			Skybox(const SPtr<Texture>& radiance, const SPtr<Texture>& filteredRadiance, const SPtr<Texture>& irradiance);
 
 			/** @copydoc CoreObject::initialize */
 			void initialize() override;
@@ -160,6 +142,7 @@ namespace bs
 			/** @copydoc CoreObject::syncToCore */
 			void syncToCore(const CoreSyncData& data) override;
 
+			SPtr<Texture> mTexture;
 			SPtr<Texture> mFilteredRadiance;
 			SPtr<Texture> mIrradiance;
 		};

+ 8 - 6
Source/BansheeCore/Win32/BsWin32Input.cpp

@@ -41,26 +41,30 @@ namespace bs
 		HRESULT hr = CoInitialize(nullptr);
 		bool cleanupCOM = SUCCEEDED(hr);
 
+		BSTR classNameSpace = SysAllocString(L"\\\\.\\root\\cimv2");
+		BSTR className = SysAllocString(L"Win32_PNPEntity");
+		BSTR deviceID = SysAllocString(L"DeviceID");
+
+		IWbemServices* IWbemServices = nullptr;
+		IEnumWbemClassObject* enumDevices = nullptr;
+		IWbemClassObject* devices[20] = { 0 };
+
 		// Create WMI
 		IWbemLocator* IWbemLocator = nullptr;
 		hr = CoCreateInstance(__uuidof(WbemLocator), nullptr, CLSCTX_INPROC_SERVER, __uuidof(IWbemLocator), (LPVOID*)&IWbemLocator);
 		if (FAILED(hr) || IWbemLocator == nullptr)
 			goto cleanup;
 
-		BSTR classNameSpace = SysAllocString(L"\\\\.\\root\\cimv2");
 		if (classNameSpace == nullptr)
 			goto cleanup;
 
-		BSTR className = SysAllocString(L"Win32_PNPEntity");
 		if (className == nullptr)
 			goto cleanup;
 
-		BSTR deviceID = SysAllocString(L"DeviceID");
 		if (deviceID == nullptr)
 			goto cleanup;
 
 		// Connect to WMI
-		IWbemServices* IWbemServices = nullptr;
 		hr = IWbemLocator->ConnectServer(classNameSpace, nullptr, nullptr, 0L, 0L, nullptr, nullptr, &IWbemServices);
 		if (FAILED(hr) || IWbemServices == nullptr)
 			goto cleanup;
@@ -68,13 +72,11 @@ namespace bs
 		// Switch security level to IMPERSONATE
 		CoSetProxyBlanket(IWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, nullptr, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, nullptr, EOAC_NONE);
 
-		IEnumWbemClassObject* enumDevices = nullptr;
 		hr = IWbemServices->CreateInstanceEnum(className, 0, nullptr, &enumDevices);
 		if (FAILED(hr) || enumDevices == nullptr)
 			goto cleanup;
 
 		// Loop over all devices
-		IWbemClassObject* devices[20] = { 0 };
 		for (;; )
 		{
 			DWORD numDevices = 0;

+ 1 - 1
Source/SBansheeEditor/Wrappers/BsScriptOSDropTarget.cpp

@@ -25,7 +25,7 @@ namespace bs
 	ScriptOSDropTarget::OnDropThunkDef ScriptOSDropTarget::onDropThunk;
 
 	ScriptOSDropTarget::ScriptOSDropTarget(MonoObject* instance, ScriptEditorWindow* parent)
-		:ScriptObject(instance)
+		:ScriptObject(instance), mParent(parent)
 	{
 		mGCHandle = MonoUtil::newWeakGCHandle(instance);