Explorar o código

Various Gizmo rendering fixes

Marko Pintera %!s(int64=11) %!d(string=hai) anos
pai
achega
b64a0482e7
Modificáronse 30 ficheiros con 394 adicións e 264 borrados
  1. 2 2
      BansheeCore/Include/BsSceneObject.h
  2. 4 1
      BansheeD3D9RenderSystem/Source/BsD3D9IndexBuffer.cpp
  3. 1 1
      BansheeD3D9RenderSystem/Source/BsD3D9RenderSystem.cpp
  4. 3 0
      BansheeD3D9RenderSystem/Source/BsD3D9VertexBuffer.cpp
  5. 2 9
      BansheeD3D9RenderSystem/Source/BsD3D9VertexDeclaration.cpp
  6. 1 0
      BansheeEditor/Include/BsEditorPrerequisites.h
  7. 92 78
      BansheeEditor/Include/BsGizmoManager.h
  8. 0 2
      BansheeEditor/Include/BsSceneCameraController.h
  9. 6 0
      BansheeEditor/Include/BsSceneEditorWidget.h
  10. 2 0
      BansheeEditor/Source/BsBuiltinEditorResources.cpp
  11. 6 2
      BansheeEditor/Source/BsEditorApplication.cpp
  12. 161 110
      BansheeEditor/Source/BsGizmoManager.cpp
  13. 2 0
      BansheeEditor/Source/BsSceneCameraController.cpp
  14. 12 1
      BansheeEditor/Source/BsSceneEditorWidget.cpp
  15. 2 0
      BansheeEngine/Source/BsDrawHelper.cpp
  16. 4 4
      BansheeEngine/Source/BsShapeMeshes3D.cpp
  17. 1 0
      BansheeGLRenderSystem/Include/BsGLIndexBuffer.h
  18. 1 0
      BansheeGLRenderSystem/Include/BsGLVertexBuffer.h
  19. 19 7
      BansheeGLRenderSystem/Source/BsGLIndexBuffer.cpp
  20. 4 1
      BansheeGLRenderSystem/Source/BsGLRenderSystem.cpp
  21. 19 7
      BansheeGLRenderSystem/Source/BsGLVertexBuffer.cpp
  22. 18 0
      MBansheeEditor/DbgGizmo.cs
  23. 8 0
      MBansheeEditor/DbgGizmoComponent.cs
  24. 1 1
      MBansheeEditor/DebugCameraHandle.cs
  25. 2 0
      MBansheeEditor/MBansheeEditor.csproj
  26. 3 0
      MBansheeEditor/Program.cs
  27. 11 11
      MBansheeEditor/Scene/Gizmos.cs
  28. 1 1
      SBansheeEngine/Source/BsManagedComponent.cpp
  29. 5 5
      SceneView.txt
  30. 1 21
      TODO.txt

+ 2 - 2
BansheeCore/Include/BsSceneObject.h

@@ -272,12 +272,12 @@ namespace BansheeEngine
 		/**
 		 * @brief	Checks if cached local transform needs updating.
 		 */
-		bool isCachedLocalTfrmUpToDate() const { return (mDirtyFlags & DirtyFlags::LocalTfrmDirty) != 0; }
+		bool isCachedLocalTfrmUpToDate() const { return (mDirtyFlags & DirtyFlags::LocalTfrmDirty) == 0; }
 
 		/**
 		 * @brief	Checks if cached world transform needs updating.
 		 */
-		bool isCachedWorldTfrmUpToDate() const { return (mDirtyFlags & DirtyFlags::WorldTfrmDirty) != 0; }
+		bool isCachedWorldTfrmUpToDate() const { return (mDirtyFlags & DirtyFlags::WorldTfrmDirty) == 0; }
 
 		/************************************************************************/
 		/* 								Hierarchy	                     		*/

+ 4 - 1
BansheeD3D9RenderSystem/Source/BsD3D9IndexBuffer.cpp

@@ -269,7 +269,10 @@ namespace BansheeEngine
 		assert(bufferResources != nullptr);
 		assert(bufferResources->mBuffer != nullptr);
 		assert(bufferResources->mOutOfDate);
-			
+		
+		if (bufferResources->mLockLength == 0)
+			return true;
+
 		void* dstBytes;
 		HRESULT hr;
 	

+ 1 - 1
BansheeD3D9RenderSystem/Source/BsD3D9RenderSystem.cpp

@@ -435,7 +435,7 @@ namespace BansheeEngine
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
-		if(!tex->isBindableAsShaderResource())
+		if (tex != nullptr && !tex->isBindableAsShaderResource())
 			BS_EXCEPT(InvalidParametersException, "Texture you have specified cannot be bound to a shader.");
 
 		if(gptype != GPT_FRAGMENT_PROGRAM && gptype != GPT_VERTEX_PROGRAM)

+ 3 - 0
BansheeD3D9RenderSystem/Source/BsD3D9VertexBuffer.cpp

@@ -266,6 +266,9 @@ namespace BansheeEngine
 		assert(bufferResources->mBuffer != nullptr);
 		assert(bufferResources->mOutOfDate);
 				
+		if (bufferResources->mLockLength == 0)
+			return true;
+
 		void* dstBytes;
 		HRESULT hr;
 		

+ 2 - 9
BansheeD3D9RenderSystem/Source/BsD3D9VertexDeclaration.cpp

@@ -61,16 +61,9 @@ namespace BansheeEngine
 				d3delems[idx].Stream = i->getStreamIdx();
 				d3delems[idx].Type = D3D9Mappings::get(i->getType());
 				d3delems[idx].Usage = D3D9Mappings::get(i->getSemantic());
-
-				if (i->getSemantic() == VES_COLOR)
-				{
-					d3delems[idx].UsageIndex = 0;
-				}
-				else
-				{
-					d3delems[idx].UsageIndex = static_cast<BYTE>(i->getSemanticIdx());
-				}
+				d3delems[idx].UsageIndex = static_cast<BYTE>(i->getSemanticIdx());
 			}
+
 			// Add terminator
 			d3delems[idx].Stream = 0xff;
 			d3delems[idx].Offset = 0;

+ 1 - 0
BansheeEditor/Include/BsEditorPrerequisites.h

@@ -62,6 +62,7 @@ namespace BansheeEngine
 	class HandleSliderDisc;
 	class HandleSliderManager;
 	class HandleDrawManager;
+	class SceneCameraController;
 
 	typedef std::shared_ptr<ProjectResourceMeta> ProjectResourceMetaPtr;
 	typedef std::shared_ptr<DockManagerLayout> DockManagerLayoutPtr;

+ 92 - 78
BansheeEditor/Include/BsGizmoManager.h

@@ -9,10 +9,12 @@
 
 namespace BansheeEngine
 {
+	class GizmoManagerCore;
+
 	class BS_ED_EXPORT GizmoManager : public Module<GizmoManager>
 	{
 	public:
-		GizmoManager(const HCamera& camera);
+		GizmoManager();
 		~GizmoManager();
 
 		void startGizmo(const HSceneObject& gizmoParent);
@@ -31,10 +33,12 @@ namespace BansheeEngine
 		void drawIcon(Vector3 position, HSpriteTexture image, bool fixedScale);
 
 		void update();
-		void renderForPicking(std::function<Color(UINT32)> idxToColorCallback);
+		void renderForPicking(const HCamera& camera, std::function<Color(UINT32)> idxToColorCallback);
 		void clearGizmos();
 
 	private:
+		friend class GizmoManagerCore;
+
 		struct CommonData
 		{
 			Color color;
@@ -83,77 +87,26 @@ namespace BansheeEngine
 			HTexture texture;
 		};
 
-		struct SolidMaterialData
-		{
-			HMaterial material;
-			
-			// Core
-			MaterialProxyPtr proxy;
-			GpuParamMat4 mViewProj;
-			GpuParamMat4 mViewIT;
-		};
-
-		struct WireMaterialData
-		{
-			HMaterial material;
-
-			// Core
-			MaterialProxyPtr proxy;
-			GpuParamMat4 mViewProj;
-		};
-
-		struct IconMaterialData
-		{
-			HMaterial material;
-
-			// Core
-			MaterialProxyPtr proxy;
-			GpuParamsPtr mFragParams;
-			GpuParamMat4 mViewProj;
-			GpuParamTexture mTexture;
-		};
-
-		struct PickingMaterialData
-		{
-			HMaterial material;
-
-			// Core
-			MaterialProxyPtr proxy;
-			GpuParamMat4 mViewProj;
-		};
-
-		struct AlphaPickingMaterialData
+		struct CoreInitData
 		{
-			HMaterial material;
-
-			// Core
-			MaterialProxyPtr proxy;
-			GpuParamsPtr mFragParams;
-			GpuParamMat4 mViewProj;
-			GpuParamTexture mTexture;
+			MaterialProxyPtr solidMatProxy;
+			MaterialProxyPtr wireMatProxy;
+			MaterialProxyPtr iconMatProxy;
+			MaterialProxyPtr pickingMatProxy;
+			MaterialProxyPtr alphaPickingMatProxy;
 		};
 
 		typedef Vector<IconRenderData> IconRenderDataVec;
 		typedef std::shared_ptr<IconRenderDataVec> IconRenderDataVecPtr;
 
-		TransientMeshPtr buildIconMesh(const Vector<IconData>& iconData, bool pickingOnly, IconRenderDataVecPtr& renderData);
-
-		void coreRender(const CameraProxy& camera);
-		void coreRenderSolidGizmos(Matrix4 viewMatrix, Matrix4 projMatrix, MeshProxyPtr mesh);
-		void coreRenderWireGizmos(Matrix4 viewMatrix, Matrix4 projMatrix, MeshProxyPtr mesh);
-		void coreRenderIconGizmos(Rect2I screenArea, MeshProxyPtr mesh, IconRenderDataVecPtr renderData);
-
-		void coreRenderGizmosForPicking(Matrix4 viewMatrix, Matrix4 projMatrix, MeshProxyPtr mesh);
-		void coreRenderIconGizmosForPicking(Rect2I screenArea, MeshProxyPtr mesh, IconRenderDataVecPtr renderData);
-
-		void coreUpdateData(const MeshProxyPtr& solidMeshProxy, const MeshProxyPtr& wireMeshProxy,
-			const MeshProxyPtr& iconMeshProxy, const IconRenderDataVecPtr& iconRenderData);
+		TransientMeshPtr buildIconMesh(const HCamera& camera, const Vector<IconData>& iconData, bool pickingOnly, IconRenderDataVecPtr& renderData);
 
 		void limitIconSize(UINT32& width, UINT32& height);
 		void calculateIconColors(const Color& tint, const Camera& camera, UINT32 iconHeight, bool fixedScale,
 			Color& normalColor, Color& fadedColor);
 
-		void initializeCore();
+		void initializeCore(const CoreInitData& initData);
+		void destroyCore(GizmoManagerCore* core);
 
 		static const UINT32 VERTEX_BUFFER_GROWTH;
 		static const UINT32 INDEX_BUFFER_GROWTH;
@@ -162,13 +115,9 @@ namespace BansheeEngine
 		static const float MAX_ICON_RANGE;
 		static const UINT32 OPTIMAL_ICON_SIZE;
 		static const float ICON_TEXEL_WORLD_SIZE;
-		static const float PICKING_ALPHA_CUTOFF;
 
 		typedef Set<IconData, std::function<bool(const IconData&, const IconData&)>> IconSet;
 
-		HCamera mCamera;
-		RenderTargetPtr mSceneRenderTarget;
-
 		Color mColor;
 		Matrix4 mTransform;
 		HSceneObject mActiveSO;
@@ -191,22 +140,11 @@ namespace BansheeEngine
 		TransientMeshPtr mWireMesh;
 		TransientMeshPtr mIconMesh;
 
-		// Core
-		MeshProxyPtr mSolidMeshProxy;
-		MeshProxyPtr mWireMeshProxy;
-		MeshProxyPtr mIconMeshProxy;
-		IconRenderDataVecPtr mIconRenderData;
+		GizmoManagerCore* mCore;
 
 		// Immutable
 		VertexDataDescPtr mIconVertexDesc;
 
-		SolidMaterialData mSolidMaterial;
-		WireMaterialData mWireMaterial;
-		IconMaterialData mIconMaterial;
-
-		PickingMaterialData mPickingMaterial;
-		AlphaPickingMaterialData mAlphaPickingMaterial;
-
 		// Transient
 		struct SortedIconData
 		{
@@ -217,4 +155,80 @@ namespace BansheeEngine
 
 		Vector<SortedIconData> mSortedIconData;
 	};
+
+	class GizmoManagerCore
+	{
+		friend class GizmoManager;
+
+		struct SolidMaterialData
+		{
+			MaterialProxyPtr proxy;
+			GpuParamMat4 mViewProj;
+			GpuParamMat4 mViewIT;
+		};
+
+		struct WireMaterialData
+		{
+			MaterialProxyPtr proxy;
+			GpuParamMat4 mViewProj;
+		};
+
+		struct IconMaterialData
+		{
+			MaterialProxyPtr proxy;
+			GpuParamsPtr mFragParams;
+			GpuParamMat4 mViewProj;
+			GpuParamTexture mTexture;
+		};
+
+		struct PickingMaterialData
+		{
+			MaterialProxyPtr proxy;
+			GpuParamMat4 mViewProj;
+		};
+
+		struct AlphaPickingMaterialData
+		{
+			MaterialProxyPtr proxy;
+			GpuParamsPtr mFragParams;
+			GpuParamMat4 mViewProj;
+			GpuParamTexture mTexture;
+		};
+
+		struct PrivatelyConstuct { };
+
+	public:
+		GizmoManagerCore(const PrivatelyConstuct& dummy);
+
+	private:
+		void initialize(const GizmoManager::CoreInitData& initData);
+
+		void render(const CameraProxy& camera);
+		void renderSolidGizmos(Matrix4 viewMatrix, Matrix4 projMatrix, MeshProxyPtr mesh);
+		void renderWireGizmos(Matrix4 viewMatrix, Matrix4 projMatrix, MeshProxyPtr mesh);
+		void renderIconGizmos(Rect2I screenArea, MeshProxyPtr mesh, GizmoManager::IconRenderDataVecPtr renderData);
+
+		void renderGizmosForPicking(Matrix4 viewMatrix, Matrix4 projMatrix, MeshProxyPtr mesh);
+		void renderIconGizmosForPicking(Rect2I screenArea, MeshProxyPtr mesh, GizmoManager::IconRenderDataVecPtr renderData);
+
+		void updateData(const RenderTargetPtr& rt, const MeshProxyPtr& solidMeshProxy, const MeshProxyPtr& wireMeshProxy,
+			const MeshProxyPtr& iconMeshProxy, const GizmoManager::IconRenderDataVecPtr& iconRenderData);
+
+		static const float PICKING_ALPHA_CUTOFF;
+
+		RenderTargetPtr mSceneRenderTarget;
+
+		MeshProxyPtr mSolidMeshProxy;
+		MeshProxyPtr mWireMeshProxy;
+		MeshProxyPtr mIconMeshProxy;
+		GizmoManager::IconRenderDataVecPtr mIconRenderData;
+
+		// Immutable
+		SolidMaterialData mSolidMaterial;
+		WireMaterialData mWireMaterial;
+		IconMaterialData mIconMaterial;
+
+		PickingMaterialData mPickingMaterial;
+		AlphaPickingMaterialData mAlphaPickingMaterial;
+	};
 }

+ 0 - 2
BansheeEditor/Include/BsSceneCameraController.h

@@ -28,8 +28,6 @@ namespace BansheeEngine
 		Degree mYaw;
 		bool mLastButtonState;
 
-		HCamera mCamera;
-
 		VirtualButton mMoveForward;
 		VirtualButton mMoveLeft;
 		VirtualButton mMoveRight;

+ 6 - 0
BansheeEditor/Include/BsSceneEditorWidget.h

@@ -2,6 +2,7 @@
 
 #include "BsEditorPrerequisites.h"
 #include "BsEditorWidget.h"
+#include "BsServiceLocator.h"
 
 namespace BansheeEngine
 {
@@ -18,6 +19,8 @@ namespace BansheeEngine
 		static void close();
 		static const String& getTypeName();
 
+		const HCamera& getSceneCamera() const { return mCamera; }
+
 	protected:
 		void doOnResized(UINT32 width, UINT32 height);
 		void doOnParentChanged();
@@ -49,6 +52,7 @@ namespace BansheeEngine
 		RenderTexturePtr mSceneRenderTarget;
 		GUIRenderTexture* mGUIRenderTexture;
 		HCamera mCamera;
+		GameObjectHandle<SceneCameraController> mCameraController;
 		SceneGrid* mSceneGrid;
 
 		HEvent mRenderCallback;
@@ -56,4 +60,6 @@ namespace BansheeEngine
 		HEvent mOnPointerPressedConn;
 		HEvent mOnPointerReleasedConn;
 	};
+
+	typedef ServiceLocator<SceneEditorWidget> SceneViewLocator;
 }

+ 2 - 0
BansheeEditor/Source/BsBuiltinEditorResources.cpp

@@ -242,6 +242,8 @@ namespace BansheeEngine
 		initWireGizmoShader();
 		initSolidGizmoShader();
 		initIconGizmoShader();
+		initGizmoPickingShader();
+		initGizmoPickingAlphaShader();
 
 		Path fontPath = FileSystem::getWorkingDirectoryPath();
 		fontPath.append(DefaultSkinFolder);

+ 6 - 2
BansheeEditor/Source/BsEditorApplication.cpp

@@ -11,6 +11,9 @@
 #include "BsResourceImporter.h"
 #include "BsEditorWidgetLayout.h"
 #include "BsSceneEditorWidget.h"
+#include "BsScenePicking.h"
+#include "BsSelection.h"
+#include "BsGizmoManager.h"
 
 // DEBUG ONLY
 #include "DbgEditorWidget1.h"
@@ -37,8 +40,6 @@
 #include "BsGUILayout.h"
 #include "BsEvent.h"
 #include "BsRenderer.h"
-#include "BsScenePicking.h"
-#include "BsSelection.h"
 
 namespace BansheeEngine
 {
@@ -84,10 +85,12 @@ namespace BansheeEngine
 
 		ScenePicking::startUp();
 		Selection::startUp();
+		GizmoManager::startUp();
 	}
 
 	EditorApplication::~EditorApplication()
 	{
+		GizmoManager::shutDown();
 		Selection::shutDown();
 		ScenePicking::shutDown();
 
@@ -372,6 +375,7 @@ namespace BansheeEngine
 
 		ProjectLibrary::instance().update();
 		EditorWindowManager::instance().update();	
+		GizmoManager::instance().update();
 	}
 
 	bool EditorApplication::isProjectLoaded() const

+ 161 - 110
BansheeEditor/Source/BsGizmoManager.cpp

@@ -16,6 +16,7 @@
 #include "BsTransientMesh.h"
 #include "BsRendererManager.h"
 #include "BsDrawHelper.h"
+#include "BsSceneEditorWidget.h"
 
 using namespace std::placeholders;
 
@@ -28,13 +29,10 @@ namespace BansheeEngine
 	const float GizmoManager::MAX_ICON_RANGE = 500.0f;
 	const UINT32 GizmoManager::OPTIMAL_ICON_SIZE = 64;
 	const float GizmoManager::ICON_TEXEL_WORLD_SIZE = 0.05f;
-	const float GizmoManager::PICKING_ALPHA_CUTOFF = 0.5f;
 
-	GizmoManager::GizmoManager(const HCamera& camera)
-		:mCamera(camera), mPickable(false), mDrawHelper(nullptr), mPickingDrawHelper(nullptr)
+	GizmoManager::GizmoManager()
+		:mPickable(false), mDrawHelper(nullptr), mPickingDrawHelper(nullptr), mCore(nullptr)
 	{
-		mSceneRenderTarget = mCamera->getViewport()->getTarget();
-
 		mDrawHelper = bs_new<DrawHelper>();
 		mPickingDrawHelper = bs_new<DrawHelper>();
 
@@ -46,19 +44,23 @@ namespace BansheeEngine
 
 		mIconMeshHeap = MeshHeap::create(VERTEX_BUFFER_GROWTH, INDEX_BUFFER_GROWTH, mIconVertexDesc);
 
-		mSolidMaterial.material = BuiltinEditorResources::instance().createSolidGizmoMat();
-		mWireMaterial.material = BuiltinEditorResources::instance().createWireGizmoMat();
-		mIconMaterial.material = BuiltinEditorResources::instance().createIconGizmoMat();
-		mPickingMaterial.material = BuiltinEditorResources::instance().createGizmoPickingMat();
-		mAlphaPickingMaterial.material = BuiltinEditorResources::instance().createAlphaGizmoPickingMat();
+		HMaterial solidMaterial = BuiltinEditorResources::instance().createSolidGizmoMat();
+		HMaterial wireMaterial = BuiltinEditorResources::instance().createWireGizmoMat();
+		HMaterial iconMaterial = BuiltinEditorResources::instance().createIconGizmoMat();
+		HMaterial pickingMaterial = BuiltinEditorResources::instance().createGizmoPickingMat();
+		HMaterial alphaPickingMaterial = BuiltinEditorResources::instance().createAlphaGizmoPickingMat();
+
+		CoreInitData initData;
 
-		mSolidMaterial.proxy = mSolidMaterial.material->_createProxy();
-		mWireMaterial.proxy = mWireMaterial.material->_createProxy();
-		mIconMaterial.proxy = mIconMaterial.material->_createProxy();
-		mPickingMaterial.proxy = mPickingMaterial.material->_createProxy();
-		mAlphaPickingMaterial.proxy = mAlphaPickingMaterial.material->_createProxy();
+		initData.solidMatProxy = solidMaterial->_createProxy();
+		initData.wireMatProxy = wireMaterial->_createProxy();
+		initData.iconMatProxy = iconMaterial->_createProxy();
+		initData.pickingMatProxy = pickingMaterial->_createProxy();
+		initData.alphaPickingMatProxy = alphaPickingMaterial->_createProxy();
 
-		gCoreAccessor().queueCommand(std::bind(&GizmoManager::initializeCore, this));
+		mCore = bs_new<GizmoManagerCore>(GizmoManagerCore::PrivatelyConstuct());
+
+		gCoreAccessor().queueCommand(std::bind(&GizmoManager::initializeCore, this, initData));
 	}
 
 	GizmoManager::~GizmoManager()
@@ -74,62 +76,18 @@ namespace BansheeEngine
 
 		bs_delete(mDrawHelper);
 		bs_delete(mPickingDrawHelper);
+
+		gCoreAccessor().queueCommand(std::bind(&GizmoManager::destroyCore, this, mCore));
 	}
 
-	void GizmoManager::initializeCore()
+	void GizmoManager::initializeCore(const CoreInitData& initData)
 	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		// TODO - Make a better interface when dealing with parameters through proxies?
-		{
-			MaterialProxyPtr proxy = mWireMaterial.proxy;
-			GpuParamsPtr vertParams = proxy->params[proxy->passes[0].vertexProgParamsIdx];
-
-			vertParams->getParam("matViewProj", mWireMaterial.mViewProj);
-		}
-
-		{
-			MaterialProxyPtr proxy = mSolidMaterial.proxy;
-			GpuParamsPtr vertParams = proxy->params[proxy->passes[0].vertexProgParamsIdx];
-
-			vertParams->getParam("matViewProj", mSolidMaterial.mViewProj);
-			vertParams->getParam("matViewIT", mSolidMaterial.mViewIT);
-		}
-
-		{
-			MaterialProxyPtr proxy = mIconMaterial.proxy;
-			GpuParamsPtr vertParams = proxy->params[proxy->passes[0].vertexProgParamsIdx];
-
-			vertParams->getParam("matViewProj", mIconMaterial.mViewProj);
-
-			mIconMaterial.mFragParams = proxy->params[proxy->passes[0].fragmentProgParamsIdx];
-
-			mIconMaterial.mFragParams->getTextureParam("mainTexture", mIconMaterial.mTexture);
-		}
-
-		{
-			MaterialProxyPtr proxy = mPickingMaterial.proxy;
-			GpuParamsPtr vertParams = proxy->params[proxy->passes[0].vertexProgParamsIdx];
-
-			vertParams->getParam("matViewProj", mPickingMaterial.mViewProj);
-		}
-
-		{
-			MaterialProxyPtr proxy = mAlphaPickingMaterial.proxy;
-			GpuParamsPtr vertParams = proxy->params[proxy->passes[0].vertexProgParamsIdx];
-
-			vertParams->getParam("matViewProj", mAlphaPickingMaterial.mViewProj);
-
-			mAlphaPickingMaterial.mFragParams = proxy->params[proxy->passes[0].fragmentProgParamsIdx];
-			mAlphaPickingMaterial.mFragParams->getTextureParam("mainTexture", mAlphaPickingMaterial.mTexture);
-
-			GpuParamFloat alphaCutoffParam;
-			mAlphaPickingMaterial.mFragParams->getParam("alphaCutoff", alphaCutoffParam);
-			alphaCutoffParam.set(PICKING_ALPHA_CUTOFF);
-		}
+		mCore->initialize(initData);
+	}
 
-		RendererPtr activeRenderer = RendererManager::instance().getActive();
-		activeRenderer->onCorePostRenderViewport.connect(std::bind(&GizmoManager::coreRender, this, _1));
+	void GizmoManager::destroyCore(GizmoManagerCore* core)
+	{
+		bs_delete(core);
 	}
 
 	void GizmoManager::startGizmo(const HSceneObject& gizmoParent)
@@ -270,22 +228,40 @@ namespace BansheeEngine
 		if (mIconMesh != nullptr)
 			mIconMeshHeap->dealloc(mIconMesh);
 
-		IconRenderDataVecPtr iconRenderData;
+		HCamera sceneCamera;
+		RenderTargetPtr rt;
+		SceneEditorWidget* sceneView = SceneViewLocator::instance();
+		if (sceneView != nullptr)
+		{
+			sceneCamera = sceneView->getSceneCamera();
+			rt = sceneCamera->getViewport()->getTarget();
+
+			IconRenderDataVecPtr iconRenderData;
+
+			mSolidMesh = mDrawHelper->buildSolidMesh();
+			mWireMesh = mDrawHelper->buildWireMesh();
+			mIconMesh = buildIconMesh(sceneCamera, mIconData, false, iconRenderData);
 
-		mSolidMesh = mDrawHelper->buildSolidMesh();
-		mWireMesh = mDrawHelper->buildWireMesh();
-		mIconMesh = buildIconMesh(mIconData, false, iconRenderData);
+			MeshProxyPtr solidMeshProxy = mSolidMesh->_createProxy(0);
+			MeshProxyPtr wireMeshProxy = mWireMesh->_createProxy(0);
+			MeshProxyPtr iconMeshProxy = mIconMesh->_createProxy(0);
 
-		MeshProxyPtr solidMeshProxy = mSolidMesh->_createProxy(0);
-		MeshProxyPtr wireMeshProxy = mWireMesh->_createProxy(0);
-		MeshProxyPtr iconMeshProxy = mIconMesh->_createProxy(0);
+			gCoreAccessor().queueCommand(std::bind(&GizmoManagerCore::updateData, mCore, rt, solidMeshProxy, wireMeshProxy, iconMeshProxy, iconRenderData));
+		}
+		else
+		{
+			mSolidMesh = nullptr;
+			mWireMesh = nullptr;
+			mIconMesh = nullptr;
 
-		gCoreAccessor().queueCommand(std::bind(&GizmoManager::coreUpdateData, this, solidMeshProxy, wireMeshProxy, iconMeshProxy, iconRenderData));
+			IconRenderDataVecPtr iconRenderData = bs_shared_ptr<IconRenderDataVec>();
+			gCoreAccessor().queueCommand(std::bind(&GizmoManagerCore::updateData, mCore, nullptr, nullptr, nullptr, nullptr, iconRenderData));
+		}
 
 		clearGizmos();
 	}
 
-	void GizmoManager::renderForPicking(std::function<Color(UINT32)> idxToColorCallback)
+	void GizmoManager::renderForPicking(const HCamera& camera, std::function<Color(UINT32)> idxToColorCallback)
 	{
 		Vector<IconData> iconData;
 		IconRenderDataVecPtr iconRenderData;
@@ -371,23 +347,23 @@ namespace BansheeEngine
 
 		TransientMeshPtr solidMesh = mPickingDrawHelper->buildSolidMesh();
 		TransientMeshPtr wireMesh = mPickingDrawHelper->buildWireMesh();
-		TransientMeshPtr iconMesh = buildIconMesh(iconData, true, iconRenderData);
+		TransientMeshPtr iconMesh = buildIconMesh(camera, iconData, true, iconRenderData);
 
 		// Note: This must be rendered while Scene view is being rendered
-		Matrix4 viewMat = mCamera->getViewMatrix();
-		Matrix4 projMat = mCamera->getProjectionMatrix();
-		ViewportPtr viewport = mCamera->getViewport();
+		Matrix4 viewMat = camera->getViewMatrix();
+		Matrix4 projMat = camera->getProjectionMatrix();
+		ViewportPtr viewport = camera->getViewport();
 
-		gCoreAccessor().queueCommand(std::bind(&GizmoManager::coreRenderGizmosForPicking,
-			this, viewMat, projMat, solidMesh->_createProxy(0)));
+		gCoreAccessor().queueCommand(std::bind(&GizmoManagerCore::renderGizmosForPicking,
+			mCore, viewMat, projMat, solidMesh->_createProxy(0)));
 
-		gCoreAccessor().queueCommand(std::bind(&GizmoManager::coreRenderGizmosForPicking,
-			this, viewMat, projMat, wireMesh->_createProxy(0)));
+		gCoreAccessor().queueCommand(std::bind(&GizmoManagerCore::renderGizmosForPicking,
+			mCore, viewMat, projMat, wireMesh->_createProxy(0)));
 
-		Rect2I screenArea = mCamera->getViewport()->getArea();
+		Rect2I screenArea = camera->getViewport()->getArea();
 
-		gCoreAccessor().queueCommand(std::bind(&GizmoManager::coreRenderIconGizmosForPicking,
-			this, screenArea, iconMesh->_createProxy(0), iconRenderData));
+		gCoreAccessor().queueCommand(std::bind(&GizmoManagerCore::renderIconGizmosForPicking,
+			mCore, screenArea, iconMesh->_createProxy(0), iconRenderData));
 
 		mPickingDrawHelper->releaseSolidMesh(solidMesh);
 		mPickingDrawHelper->releaseWireMesh(wireMesh);
@@ -407,7 +383,8 @@ namespace BansheeEngine
 		mDrawHelper->clear();
 	}
 
-	TransientMeshPtr GizmoManager::buildIconMesh(const Vector<IconData>& iconData, bool pickingOnly, GizmoManager::IconRenderDataVecPtr& iconRenderData)
+	TransientMeshPtr GizmoManager::buildIconMesh(const HCamera& camera, const Vector<IconData>& iconData, 
+		bool pickingOnly, GizmoManager::IconRenderDataVecPtr& iconRenderData)
 	{
 		mSortedIconData.clear();
 		
@@ -417,10 +394,10 @@ namespace BansheeEngine
 		UINT32 i = 0;
 		for (auto& iconData : mIconData)
 		{
-			Vector3 viewPoint = mCamera->worldToViewPoint(iconData.position);
+			Vector3 viewPoint = camera->worldToViewPoint(iconData.position);
 
 			float distance = -viewPoint.z;
-			if (distance < mCamera->getNearClipDistance()) // Ignore behind clip plane
+			if (distance < camera->getNearClipDistance()) // Ignore behind clip plane
 				continue;
 
 			if (distance > MAX_ICON_RANGE) // Ignore too far away
@@ -435,7 +412,7 @@ namespace BansheeEngine
 			SortedIconData& sortedIconData = mSortedIconData[i];
 			sortedIconData.iconIdx = i;
 			sortedIconData.distance = distance;
-			sortedIconData.screenPosition = mCamera->viewToScreenPoint(viewPoint);
+			sortedIconData.screenPosition = camera->viewToScreenPoint(viewPoint);
 
 			i++;
 		}
@@ -470,12 +447,12 @@ namespace BansheeEngine
 		UINT32* indices = meshData->getIndices32();
 
 		float cameraScale = 1.0f;
-		if (mCamera->getProjectionType() == PT_ORTHOGRAPHIC)
-			cameraScale = mCamera->getViewport()->getHeight() / mCamera->getOrthoWindowHeight();
+		if (camera->getProjectionType() == PT_ORTHOGRAPHIC)
+			cameraScale = camera->getViewport()->getHeight() / camera->getOrthoWindowHeight();
 		else
 		{
-			Radian vertFOV(Math::tan(mCamera->getHorzFOV() * 0.5f));
-			cameraScale = (mCamera->getViewport()->getHeight() * 0.5f) / vertFOV.valueRadians();
+			Radian vertFOV(Math::tan(camera->getHorzFOV() * 0.5f));
+			cameraScale = (camera->getViewport()->getHeight() * 0.5f) / vertFOV.valueRadians();
 		}
 
 		iconRenderData = bs_shared_ptr<IconRenderDataVec>();
@@ -510,7 +487,7 @@ namespace BansheeEngine
 			limitIconSize(iconWidth, iconHeight);
 
 			Color normalColor, fadedColor;
-			calculateIconColors(curIconData.color, *mCamera.get(), iconHeight, curIconData.fixedScale, normalColor, fadedColor);
+			calculateIconColors(curIconData.color, *camera.get(), iconHeight, curIconData.fixedScale, normalColor, fadedColor);
 
 			Vector3 position((float)sortedIconData.screenPosition.x, (float)sortedIconData.screenPosition.y, sortedIconData.distance);
 			// TODO - Does the depth need to be corrected since it was taken from a projective camera (probably)?
@@ -521,7 +498,7 @@ namespace BansheeEngine
 			if (!curIconData.fixedScale)
 			{
 				float iconScale = 1.0f;
-				if (mCamera->getProjectionType() == PT_ORTHOGRAPHIC)
+				if (camera->getProjectionType() == PT_ORTHOGRAPHIC)
 					iconScale = cameraScale;
 				else
 					iconScale = cameraScale / sortedIconData.distance;
@@ -604,16 +581,85 @@ namespace BansheeEngine
 		fadedColor.a *= 0.2f;
 	}
 
-	void GizmoManager::coreUpdateData(const MeshProxyPtr& solidMeshProxy, const MeshProxyPtr& wireMeshProxy,
-		const MeshProxyPtr& iconMeshProxy, const IconRenderDataVecPtr& iconRenderData)
+	const float GizmoManagerCore::PICKING_ALPHA_CUTOFF = 0.5f;
+
+	GizmoManagerCore::GizmoManagerCore(const PrivatelyConstuct& dummy)
+	{
+	}
+
+	void GizmoManagerCore::initialize(const GizmoManager::CoreInitData& initData)
 	{
+		THROW_IF_NOT_CORE_THREAD;
+
+		mSolidMaterial.proxy = initData.solidMatProxy;
+		mWireMaterial.proxy = initData.wireMatProxy;
+		mIconMaterial.proxy = initData.iconMatProxy;
+		mPickingMaterial.proxy = initData.pickingMatProxy;
+		mAlphaPickingMaterial.proxy = initData.alphaPickingMatProxy;
+
+		// TODO - Make a better interface when dealing with parameters through proxies?
+		{
+			MaterialProxyPtr proxy = mWireMaterial.proxy;
+			GpuParamsPtr vertParams = proxy->params[proxy->passes[0].vertexProgParamsIdx];
+
+			vertParams->getParam("matViewProj", mWireMaterial.mViewProj);
+		}
+
+		{
+			MaterialProxyPtr proxy = mSolidMaterial.proxy;
+			GpuParamsPtr vertParams = proxy->params[proxy->passes[0].vertexProgParamsIdx];
+
+			vertParams->getParam("matViewProj", mSolidMaterial.mViewProj);
+			vertParams->getParam("matViewIT", mSolidMaterial.mViewIT);
+		}
+
+		{
+			MaterialProxyPtr proxy = mIconMaterial.proxy;
+			GpuParamsPtr vertParams = proxy->params[proxy->passes[0].vertexProgParamsIdx];
+
+			vertParams->getParam("matViewProj", mIconMaterial.mViewProj);
+
+			mIconMaterial.mFragParams = proxy->params[proxy->passes[0].fragmentProgParamsIdx];
+
+			mIconMaterial.mFragParams->getTextureParam("mainTexture", mIconMaterial.mTexture);
+		}
+
+		{
+			MaterialProxyPtr proxy = mPickingMaterial.proxy;
+			GpuParamsPtr vertParams = proxy->params[proxy->passes[0].vertexProgParamsIdx];
+
+			vertParams->getParam("matViewProj", mPickingMaterial.mViewProj);
+		}
+
+		{
+			MaterialProxyPtr proxy = mAlphaPickingMaterial.proxy;
+			GpuParamsPtr vertParams = proxy->params[proxy->passes[0].vertexProgParamsIdx];
+
+			vertParams->getParam("matViewProj", mAlphaPickingMaterial.mViewProj);
+
+			mAlphaPickingMaterial.mFragParams = proxy->params[proxy->passes[0].fragmentProgParamsIdx];
+			mAlphaPickingMaterial.mFragParams->getTextureParam("mainTexture", mAlphaPickingMaterial.mTexture);
+
+			GpuParamFloat alphaCutoffParam;
+			mAlphaPickingMaterial.mFragParams->getParam("alphaCutoff", alphaCutoffParam);
+			alphaCutoffParam.set(PICKING_ALPHA_CUTOFF);
+		}
+
+		RendererPtr activeRenderer = RendererManager::instance().getActive();
+		activeRenderer->onCorePostRenderViewport.connect(std::bind(&GizmoManagerCore::render, this, _1));
+	}
+
+	void GizmoManagerCore::updateData(const RenderTargetPtr& rt, const MeshProxyPtr& solidMeshProxy, const MeshProxyPtr& wireMeshProxy,
+		const MeshProxyPtr& iconMeshProxy, const GizmoManager::IconRenderDataVecPtr& iconRenderData)
+	{
+		mSceneRenderTarget = rt;
 		mSolidMeshProxy = solidMeshProxy;
 		mWireMeshProxy = wireMeshProxy;
 		mIconMeshProxy = iconMeshProxy;
 		mIconRenderData = iconRenderData;
 	}
 
-	void GizmoManager::coreRender(const CameraProxy& camera)
+	void GizmoManagerCore::render(const CameraProxy& camera)
 	{
 		if (camera.viewport.getTarget() != mSceneRenderTarget)
 			return;
@@ -629,12 +675,17 @@ namespace BansheeEngine
 		screenArea.width = (int)(normArea.width * width);
 		screenArea.height = (int)(normArea.height * height);
 
-		coreRenderSolidGizmos(camera.viewMatrix, camera.projMatrix, mSolidMeshProxy);
-		coreRenderWireGizmos(camera.viewMatrix, camera.projMatrix, mWireMeshProxy);
-		coreRenderIconGizmos(screenArea, mIconMeshProxy, mIconRenderData);
+		if (mSolidMeshProxy != nullptr)
+			renderSolidGizmos(camera.viewMatrix, camera.projMatrix, mSolidMeshProxy);
+
+		if (mWireMeshProxy != nullptr)
+			renderWireGizmos(camera.viewMatrix, camera.projMatrix, mWireMeshProxy);
+
+		if (mIconMeshProxy != nullptr)
+			renderIconGizmos(screenArea, mIconMeshProxy, mIconRenderData);
 	}
 
-	void GizmoManager::coreRenderSolidGizmos(Matrix4 viewMatrix, Matrix4 projMatrix, MeshProxyPtr meshProxy)
+	void GizmoManagerCore::renderSolidGizmos(Matrix4 viewMatrix, Matrix4 projMatrix, MeshProxyPtr meshProxy)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
@@ -648,7 +699,7 @@ namespace BansheeEngine
 		Renderer::draw(*meshProxy);
 	}
 
-	void GizmoManager::coreRenderWireGizmos(Matrix4 viewMatrix, Matrix4 projMatrix, MeshProxyPtr meshProxy)
+	void GizmoManagerCore::renderWireGizmos(Matrix4 viewMatrix, Matrix4 projMatrix, MeshProxyPtr meshProxy)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
@@ -661,7 +712,7 @@ namespace BansheeEngine
 		Renderer::draw(*meshProxy);
 	}
 
-	void GizmoManager::coreRenderIconGizmos(Rect2I screenArea, MeshProxyPtr meshProxy, IconRenderDataVecPtr renderData)
+	void GizmoManagerCore::renderIconGizmos(Rect2I screenArea, MeshProxyPtr meshProxy, GizmoManager::IconRenderDataVecPtr renderData)
 	{
 		RenderSystem& rs = RenderSystem::instance();
 		MeshBasePtr mesh;
@@ -686,7 +737,7 @@ namespace BansheeEngine
 		rs.setDrawOperation(DOT_TRIANGLE_LIST);
 
 		// Set up ortho matrix
-		Matrix4 projMat; 
+		Matrix4 projMat;
 
 		float left = screenArea.x + rs.getHorizontalTexelOffset();
 		float right = screenArea.x + screenArea.width + rs.getHorizontalTexelOffset();
@@ -717,7 +768,7 @@ namespace BansheeEngine
 		mesh->_notifyUsedOnGPU();
 	}
 
-	void GizmoManager::coreRenderGizmosForPicking(Matrix4 viewMatrix, Matrix4 projMatrix, MeshProxyPtr meshProxy)
+	void GizmoManagerCore::renderGizmosForPicking(Matrix4 viewMatrix, Matrix4 projMatrix, MeshProxyPtr meshProxy)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
@@ -729,7 +780,7 @@ namespace BansheeEngine
 		Renderer::draw(*meshProxy);
 	}
 
-	void GizmoManager::coreRenderIconGizmosForPicking(Rect2I screenArea, MeshProxyPtr meshProxy, IconRenderDataVecPtr renderData)
+	void GizmoManagerCore::renderIconGizmosForPicking(Rect2I screenArea, MeshProxyPtr meshProxy, GizmoManager::IconRenderDataVecPtr renderData)
 	{
 		RenderSystem& rs = RenderSystem::instance();
 		MeshBasePtr mesh;

+ 2 - 0
BansheeEditor/Source/BsSceneCameraController.cpp

@@ -9,6 +9,8 @@
 #include "BsEditorApplication.h"
 #include "BsCursor.h"
 
+#include "BsDebug.h"
+
 namespace BansheeEngine
 {
 	const String SceneCameraController::MOVE_FORWARD_BTN = "SceneForward";

+ 12 - 1
BansheeEditor/Source/BsSceneEditorWidget.cpp

@@ -39,6 +39,8 @@ namespace BansheeEngine
 	SceneEditorWidget::SceneEditorWidget(const ConstructPrivately& dummy, EditorWidgetContainer& parentContainer)
 		:EditorWidget<SceneEditorWidget>(HString(L"SceneEditorWidget"), parentContainer), mGUIRenderTexture(nullptr)
 	{
+		SceneViewLocator::_provide(this);
+
 		updateRenderTexture(getWidth(), getHeight());
 
 		mRenderCallback = RendererManager::instance().getActive()->onRenderViewport.connect(std::bind(&SceneEditorWidget::render, this, _1, _2));
@@ -58,10 +60,19 @@ namespace BansheeEngine
 		mOnPointerMovedConn.disconnect();
 		mOnPointerPressedConn.disconnect();
 		mOnPointerReleasedConn.disconnect();
+
+		SceneViewLocator::_provide(nullptr);
 	}
 
 	void SceneEditorWidget::_update()
 	{
+		if (mCameraController)
+		{
+			mCameraController->update();
+
+			LOGWRN(toString(mCameraController->sceneObject()->getWorldPosition()));
+		}
+
 		//// DEBUG ONLY
 		//if (gTime().getCurrentFrameNumber() == 100)
 		//{
@@ -188,7 +199,7 @@ namespace BansheeEngine
 			mCamera->setNearClipDistance(0.005f);
 			mCamera->setFarClipDistance(1000.0f);
 
-			sceneCameraSO->addComponent<SceneCameraController>();
+			mCameraController = sceneCameraSO->addComponent<SceneCameraController>();
 
 			GUILayout& layout = mContent->getLayout();
 

+ 2 - 0
BansheeEngine/Source/BsDrawHelper.cpp

@@ -15,6 +15,8 @@ namespace BansheeEngine
 		: mTotalRequiredSolidVertices(0), mTotalRequiredSolidIndices(0), 
 		mTotalRequiredWireVertices(0), mTotalRequiredWireIndices(0)
 	{
+		mTransform = Matrix4::IDENTITY;
+
 		mSolidVertexDesc = bs_shared_ptr<VertexDataDesc>();
 		mSolidVertexDesc->addVertElem(VET_FLOAT3, VES_POSITION);
 		mSolidVertexDesc->addVertElem(VET_FLOAT3, VES_NORMAL);

+ 4 - 4
BansheeEngine/Source/BsShapeMeshes3D.cpp

@@ -399,7 +399,7 @@ namespace BansheeEngine
 			Vector3(-1, 0, 0)
 		};
 
-		outNormals += (vertexOffset + vertexStride);
+		outNormals += (vertexOffset * vertexStride);
 		for (UINT32 face = 0; face < 6; face++)
 		{
 			outNormals = writeVector3(outNormals, vertexStride, faceNormals[face]);
@@ -417,8 +417,8 @@ namespace BansheeEngine
 			indices[face * 6 + 1] = faceVertOffset + 1;
 			indices[face * 6 + 2] = faceVertOffset + 2;
 			indices[face * 6 + 3] = faceVertOffset + 2;
-			indices[face * 6 + 3] = faceVertOffset + 3;
-			indices[face * 6 + 3] = faceVertOffset + 0;
+			indices[face * 6 + 4] = faceVertOffset + 3;
+			indices[face * 6 + 5] = faceVertOffset + 0;
 		}
 	}
 
@@ -656,7 +656,7 @@ namespace BansheeEngine
 
 		Vector3 normal = area.getAxisHorz().cross(area.getAxisVert());
 
-		outNormals += (vertexOffset + vertexStride);
+		outNormals += (vertexOffset * vertexStride);
 		outNormals = writeVector3(outNormals, vertexStride, normal);
 		outNormals = writeVector3(outNormals, vertexStride, normal);
 		outNormals = writeVector3(outNormals, vertexStride, normal);

+ 1 - 0
BansheeGLRenderSystem/Include/BsGLIndexBuffer.h

@@ -57,5 +57,6 @@ namespace BansheeEngine
 
 	private:
 		GLuint mBufferId;
+		bool mZeroLocked;
     };
 }

+ 1 - 0
BansheeGLRenderSystem/Include/BsGLVertexBuffer.h

@@ -66,6 +66,7 @@ namespace BansheeEngine
 
 	private:
 		GLuint mBufferId;
+		bool mZeroLocked;
 
 		Vector<GLVertexArrayObject> mVAObjects;
     };

+ 19 - 7
BansheeGLRenderSystem/Source/BsGLIndexBuffer.cpp

@@ -6,7 +6,7 @@
 namespace BansheeEngine 
 {
     GLIndexBuffer::GLIndexBuffer(IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage)
-        : IndexBuffer(idxType, numIndexes, usage, false)
+		: IndexBuffer(idxType, numIndexes, usage, false), mZeroLocked(false)
     {  }
 
     GLIndexBuffer::~GLIndexBuffer()
@@ -76,12 +76,21 @@ namespace BansheeEngine
 		else
 			access = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT;
 
-		void* pBuffer = glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER, offset, length, access);
-
-		if(pBuffer == 0)
+		void* pBuffer = nullptr;
+		
+		if (length > 0)
 		{
-			BS_EXCEPT(InternalErrorException, "Index Buffer: Out of memory");
+			pBuffer = glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER, offset, length, access);
+
+			if (pBuffer == nullptr)
+			{
+				BS_EXCEPT(InternalErrorException, "Index Buffer: Out of memory");
+			}
+
+			mZeroLocked = false;
 		}
+		else
+			mZeroLocked = true;
 
 		void* retPtr = static_cast<void*>(static_cast<unsigned char*>(pBuffer));
 
@@ -93,9 +102,12 @@ namespace BansheeEngine
     {
 		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mBufferId);
 
-		if(!glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER))
+		if (!mZeroLocked)
 		{
-			BS_EXCEPT(InternalErrorException, "Buffer data corrupted, please reload");
+			if (!glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER))
+			{
+				BS_EXCEPT(InternalErrorException, "Buffer data corrupted, please reload");
+			}
 		}
 
 		mIsLocked = false;

+ 4 - 1
BansheeGLRenderSystem/Source/BsGLRenderSystem.cpp

@@ -2097,6 +2097,9 @@ namespace BansheeEngine
 
 	void __stdcall openGlErrorCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, GLvoid *userParam)
 	{
-		BS_EXCEPT(RenderingAPIException, "OpenGL error: " + String(message));
+		if (type != GL_DEBUG_TYPE_PERFORMANCE && type != GL_DEBUG_TYPE_OTHER)
+		{
+			BS_EXCEPT(RenderingAPIException, "OpenGL error: " + String(message));
+		}
 	}
 }

+ 19 - 7
BansheeGLRenderSystem/Source/BsGLVertexBuffer.cpp

@@ -8,7 +8,7 @@ namespace BansheeEngine
 {
     GLVertexBuffer::GLVertexBuffer(UINT32 vertexSize, 
         UINT32 numVertices, GpuBufferUsage usage)
-        : VertexBuffer(vertexSize, numVertices, usage, false)
+		: VertexBuffer(vertexSize, numVertices, usage, false), mZeroLocked(false)
     {
     }
 
@@ -97,12 +97,21 @@ namespace BansheeEngine
 		else
 			access = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT;
 
-		void* buffer = glMapBufferRange(GL_ARRAY_BUFFER, offset, length, access);
+		void* buffer = nullptr;
 
-		if(buffer == nullptr)
+		if (length > 0)
 		{
-			BS_EXCEPT(InternalErrorException, "Cannot map vertex buffer.");
+			buffer = glMapBufferRange(GL_ARRAY_BUFFER, offset, length, access);
+
+			if (buffer == nullptr)
+			{
+				BS_EXCEPT(InternalErrorException, "Cannot map vertex buffer.");
+			}
+
+			mZeroLocked = false;
 		}
+		else
+			mZeroLocked = true;
 
 		void* retPtr = static_cast<void*>(static_cast<unsigned char*>(buffer));
 
@@ -110,13 +119,16 @@ namespace BansheeEngine
 		return retPtr;
     }
 
-	void GLVertexBuffer::unlockImpl(void)
+	void GLVertexBuffer::unlockImpl()
     {
 		glBindBuffer(GL_ARRAY_BUFFER, mBufferId);
 
-		if(!glUnmapBuffer(GL_ARRAY_BUFFER))
+		if (!mZeroLocked)
 		{
-			BS_EXCEPT(InternalErrorException, "Buffer data corrupted, please reload.");
+			if (!glUnmapBuffer(GL_ARRAY_BUFFER))
+			{
+				BS_EXCEPT(InternalErrorException, "Buffer data corrupted, please reload.");
+			}
 		}
 
         mIsLocked = false;

+ 18 - 0
MBansheeEditor/DbgGizmo.cs

@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BansheeEngine;
+
+namespace BansheeEditor
+{
+    class DbgGizmo
+    {
+        [DrawGizmo(DrawGizmoFlags.NotSelected | DrawGizmoFlags.Pickable)]
+        private static void DrawDbgComponentGizmo(DbgGizmoComponent target)
+        {
+            Gizmos.DrawCube(target.sceneObject.position, new Vector3(1, 1, 1));
+        }
+    }
+}

+ 8 - 0
MBansheeEditor/DbgGizmoComponent.cs

@@ -0,0 +1,8 @@
+using BansheeEngine;
+
+namespace BansheeEditor
+{
+    public class DbgGizmoComponent : Component
+    {
+    }
+}

+ 1 - 1
MBansheeEditor/DebugCameraHandle.cs

@@ -34,7 +34,7 @@ namespace BansheeEditor
                 HandleDrawing.SetColor(Color.white);
             else
                 HandleDrawing.SetColor(Color.green);
-            
+
             HandleDrawing.DrawLine(target.sceneObject.position, end);
         }
     }

+ 2 - 0
MBansheeEditor/MBansheeEditor.csproj

@@ -41,6 +41,8 @@
   <ItemGroup>
     <Compile Include="DbgCustomInspector.cs" />
     <Compile Include="DbgEditorWindow.cs" />
+    <Compile Include="DbgGizmo.cs" />
+    <Compile Include="DbgGizmoComponent.cs" />
     <Compile Include="DbgResource.cs" />
     <Compile Include="DebugCameraHandle.cs" />
     <Compile Include="Debug_Component1.cs" />

+ 3 - 0
MBansheeEditor/Program.cs

@@ -19,6 +19,9 @@ namespace BansheeEditor
 
             window.SetObjectToInspect(newDbgObject);
 
+            SceneObject gizmoDbgObject = new SceneObject("GizmoDebug");
+            gizmoDbgObject.AddComponent<DbgGizmoComponent>();
+
             DbgResource testResource = new DbgResource();
             //ProjectLibrary.Create(testResource, @"D:\DummyBansheeProject\Resources\testResource");
 

+ 11 - 11
MBansheeEditor/Scene/Gizmos.cs

@@ -5,52 +5,52 @@ namespace BansheeEditor
 {
     public class Gizmos
     {
-        private Color _color;
-        private Matrix4 _transform;
+        private static Color _color;
+        private static Matrix4 _transform;
 
-        public Color color
+        public static Color color
         {
             get { return _color; }
             set { _color = value; Internal_SetColor(_color); }
         }
 
-        public Matrix4 transform
+        public static Matrix4 transform
         {
             get { return _transform; }
             set { _transform = value; Internal_SetTransform(_transform); }
         }
 
-        public void DrawCube(Vector3 position, Vector3 extents)
+        public static void DrawCube(Vector3 position, Vector3 extents)
         {
             Internal_DrawCube(position, extents);
         }
 
-        public void DrawSphere(Vector3 position, float radius)
+        public static void DrawSphere(Vector3 position, float radius)
         {
             Internal_DrawSphere(position, radius);
         }
 
-        public void DrawWireCube(Vector3 position, Vector3 extents)
+        public static void DrawWireCube(Vector3 position, Vector3 extents)
         {
             Internal_DrawWireCube(position, extents);
         }
 
-        public void DrawWireSphere(Vector3 position, float radius)
+        public static void DrawWireSphere(Vector3 position, float radius)
         {
             Internal_DrawWireSphere(position, radius);
         }
 
-        public void DrawLine(Vector3 start, Vector3 end)
+        public static void DrawLine(Vector3 start, Vector3 end)
         {
             Internal_DrawLine(start, end);
         }
 
-        public void DrawFrustum(Vector3 position, float aspect, Degree FOV, float near, float far)
+        public static void DrawFrustum(Vector3 position, float aspect, Degree FOV, float near, float far)
         {
             Internal_DrawFrustum(position, aspect, FOV, near, far);
         }
 
-        public void DrawIcon(Vector3 position, SpriteTexture image, bool fixedScale)
+        public static void DrawIcon(Vector3 position, SpriteTexture image, bool fixedScale)
         {
             Internal_DrawIcon(position, image, fixedScale);
         }

+ 1 - 1
SBansheeEngine/Source/BsManagedComponent.cpp

@@ -7,7 +7,7 @@
 namespace BansheeEngine
 {
 	ManagedComponent::ManagedComponent(const HSceneObject& parent, MonoReflectionType* runtimeType)
-		:mManagedInstance(nullptr), mRuntimeType(runtimeType)
+		:Component(parent), mManagedInstance(nullptr), mRuntimeType(runtimeType)
 	{
 		MonoType* monoType = mono_reflection_type_get_type(mRuntimeType);
 		::MonoClass* monoClass = mono_type_get_class(monoType);

+ 5 - 5
SceneView.txt

@@ -1,21 +1,19 @@
 
-TODO:
- - Core thread gets stuck on shutdown when OpenGL is used...Somewhere in kernel
-
  GIZMO TODO:
   - Figure out how to deal with builtin components like Camera and Renderable (e.g. how will they have gizmos since they're not managed components?)
+    - Make those two a non-component types. Anywhere they are used in the Renderer they should just be passed as pointers.
+	- Then make a Component wrapper around the non-component types, and also a C# wrapper around the same types
 
 TESTING:
 Ensure all 3 render systems compile and run
  - Test selection on all 3 render systems
- - RE-ENABLE SCISSOR TEST FOR PICKING SHADERS!!
  - Picking need to test something with alpha
  - Ensure that selecting an item in scene properly marks it in scene view
  - Ensure that selecting an item in scene or resource tree view properly updates Selection
 
 Test gizmos
  - START UP GIZMO MANAGER SOMEWHERE
- - Test rendering of basic 2D and 3D gizmos
+ - Test rendering of basic wire and solid gizmos
  - Test rendering of icon gizmos
  - Test them all from C#
  - HOOK UP GIZMO SELECTION and test it
@@ -30,6 +28,8 @@ IMPLEMENT SELECTION RENDERING
 IMPROVE SceneGrid LOOK AND ENSURE IT RENDERS FINE ON ALL APIS
  - LIKELY USE PIXEL SceneGrid WITH AA
 
+Need a way to drag and drop items from Scene tree view to Scene view
+
 LATER:
  - Need a way to render text for gizmos and handles, and in scene in general
  - Add drag to select

+ 1 - 21
TODO.txt

@@ -9,39 +9,24 @@ Optimization notes:
 
 A lot of stuff is still using GSyncedMainCA but it should be using gMainCA - Find and replace
 
-I still re-create GUIWidget mesh every frame instead of just updating it.
-
 I call waitUntilLoaded too many times. Sometimes 5-6 times in a single function. Each of those calls will be extremely slow.
+
 GUIWidget::updateMeshes leaks. If I leave the game running I can see memory continously going up
- - BansheeApplication should probably derive from Camlelot application. Right now user needs to know the difference between 
-   gApplication and gBansheeApp, which is non-intuitive (e.g. retrieving a window can be done on gApplication, but running main loop can happen on both
 
-IMMEDIATE:
- - Update debug camera so it uses callbacks
- 
  - I have disabled linear filtering because it doesn't look good on scale9grid textures. (Add another material so it works with stretched textures?)
- - Enable alpha test so I don't render completely transparent pixels.
  - What happens when I don't set a texture for a state of a GUI element. Use a dummy white texture probably?
     - Make sure GUI system uses a dummy texture if one isn't available
 	- SpriteTexture keeps a static reference to DUmmyTexture which I need to release before shutdown
 
 - Hover colors of the scroll bar are wrong
 
-TextBox needed elements:
- - Get DebugCamera to ignore input if GUI has already processed it
-
  - LATER
   - TAB between input elements
   - Remove updateText calls from updateRenderElementsInternal and instead call it whenever offsets change
   - I might consider not rendering caret from within input sprite to avoid redrawing it while, and draw it directly from GUIManager
 
------------
-
 Maybe determine mesh front faces based on normals?
 
-Immediate TODO:
- - A way to update mesh buffers without recreating vertex/index buffers (Setting data currently does exactly that)
-
 ----------------------------------------------------------------------------------------------
 Other:
  - Move Debug to CamelotCore and add SetFillMode
@@ -66,8 +51,6 @@ Medium priority:
 Low priority TODO
  - Remove template from RTTIType and move it to IReflectable? This way i can hopefully move GetRTTITypeStatic and GetRTTIType to IReflectable so I don't
    need to manually implement those for every method.
- - Viewport needs to be updated when I call RenderTarget::setFullscreen/finishSwitchingFullscreen/updateWindowRect/windowMovedOrResized. Currently it's not
- - CPU reading or writing to a render texture in OpenGL is not supported. (CmGLHardwarePixelBuffer::upload/download). 
  - When saving a resource, make sure resource is properly loaded before saving
    - Add doc to Resources::save that says it will block until render thread updates the resource
    - Add documentation that tells the user that reading a resource non-async will block the thread and execute all queued render commands first
@@ -99,13 +82,10 @@ Low priority TODO
  - I don't have a way to set Texture filtering or wrap modes, default ones are always set on initialization
 ----------------------------------------------------------------------------------------------
 Optional:
- - Need better handling for shader techniques. Some Materials are able to run on all renderers yet I can only specify one. This is problematic
-    for Materials for things like text and sprites, which should run on all renderers, even if user adds a new one
  - Add precompiled headers to all projects
  - Serializable callbacks can't be null otherwise compiler complains
  - FBX importer can be greatly sped up by implementing a better allocator
  - Extend texture copy so it accepts different subregions & subresources (currently only entire resource can be copied)
- - Need a way to convert MSAA render texture into a normal render texture
  - Vertex buffer start offset is not supported when calling Draw methods
  - When rendering Scale9Grid GUI elements the stretched center will cause linear interpolation to kick in and blend the edges with the border parts of the texture.
   - I should use point filtering for scale9grid, but that doesn't work in general case for stretched textures as they would look bad