ソースを参照

Getting render target bindings to work so it shows up in GUI
- Currently works on DX11 and OpenGL

Marko Pintera 12 年 前
コミット
cb10df23fe

+ 0 - 12
BansheeEngine/Include/BsCamera.h

@@ -494,18 +494,6 @@ namespace BansheeEngine {
 		void setIgnoreSceneRenderables(bool value) { mIgnoreSceneRenderables = true; }
 		bool getIgnoreSceneRenderables() const { return mIgnoreSceneRenderables; }
 
-        /** Project a sphere onto the near plane and get the bounding rectangle. 
-        @param sphere The world-space sphere to project
-        @param radius Radius of the sphere
-        @param left, top, right, bottom Pointers to destination values, these
-            will be completed with the normalised device coordinates (in the 
-            range {-1,1})
-        @returns true if the sphere was projected to a subset of the near plane,
-            false if the entire near plane was contained
-        */
-        virtual bool projectSphere(const CM::Sphere& sphere, 
-            float* left, float* top, float* right, float* bottom) const;
-
         /// Small constant used to reduce far plane projection to avoid inaccuracies
         static const float INFINITE_FAR_PLANE_ADJUST;
     protected:

+ 0 - 169
BansheeEngine/Source/BsCamera.cpp

@@ -692,181 +692,12 @@ namespace BansheeEngine
 		mProjType = pt;
 		invalidateFrustum();
 	}
-
 	//-----------------------------------------------------------------------
 	ProjectionType Camera::getProjectionType(void) const
 	{
 		return mProjType;
 	}
 	//---------------------------------------------------------------------
-	bool Camera::projectSphere(const Sphere& sphere, 
-		float* left, float* top, float* right, float* bottom) const
-	{
-		// See http://www.gamasutra.com/features/20021011/lengyel_06.htm
-		// Transform light position into camera space
-
-		updateView();
-		Vector3 eyeSpacePos = mViewMatrix.transformAffine(sphere.getCenter());
-
-		// initialise
-		*left = *bottom = -1.0f;
-		*right = *top = 1.0f;
-
-		if (eyeSpacePos.z < 0)
-		{
-			updateFrustum();
-			const Matrix4& projMatrix = getProjectionMatrix();
-			float r = sphere.getRadius();
-			float rsq = r * r;
-
-			// early-exit
-			if (eyeSpacePos.squaredLength() <= rsq)
-				return false;
-
-			float Lxz = Math::Sqr(eyeSpacePos.x) + Math::Sqr(eyeSpacePos.z);
-			float Lyz = Math::Sqr(eyeSpacePos.y) + Math::Sqr(eyeSpacePos.z);
-
-			// Find the tangent planes to the sphere
-			// XZ first
-			// calculate quadratic discriminant: b*b - 4ac
-			// x = Nx
-			// a = Lx^2 + Lz^2
-			// b = -2rLx
-			// c = r^2 - Lz^2
-			float a = Lxz;
-			float b = -2.0f * r * eyeSpacePos.x;
-			float c = rsq - Math::Sqr(eyeSpacePos.z);
-			float D = b*b - 4.0f*a*c;
-
-			// two roots?
-			if (D > 0)
-			{
-				float sqrootD = Math::Sqrt(D);
-				// solve the quadratic to get the components of the normal
-				float Nx0 = (-b + sqrootD) / (2 * a);
-				float Nx1 = (-b - sqrootD) / (2 * a);
-
-				// Derive Z from this
-				float Nz0 = (r - Nx0 * eyeSpacePos.x) / eyeSpacePos.z;
-				float Nz1 = (r - Nx1 * eyeSpacePos.x) / eyeSpacePos.z;
-
-				// Get the point of tangency
-				// Only consider points of tangency in front of the camera
-				float Pz0 = (Lxz - rsq) / (eyeSpacePos.z - ((Nz0 / Nx0) * eyeSpacePos.x));
-				if (Pz0 < 0)
-				{
-					// Project point onto near plane in worldspace
-					float nearx0 = (Nz0 * mNearDist) / Nx0;
-					// now we need to map this to viewport coords
-					// use projection matrix since that will take into account all factors
-					Vector3 relx0 = projMatrix * Vector3(nearx0, 0, -mNearDist);
-
-					// find out whether this is a left side or right side
-					float Px0 = -(Pz0 * Nz0) / Nx0;
-					if (Px0 > eyeSpacePos.x)
-					{
-						*right = std::min(*right, relx0.x);
-					}
-					else
-					{
-						*left = std::max(*left, relx0.x);
-					}
-				}
-				float Pz1 = (Lxz - rsq) / (eyeSpacePos.z - ((Nz1 / Nx1) * eyeSpacePos.x));
-				if (Pz1 < 0)
-				{
-					// Project point onto near plane in worldspace
-					float nearx1 = (Nz1 * mNearDist) / Nx1;
-					// now we need to map this to viewport coords
-					// use projection matrix since that will take into account all factors
-					Vector3 relx1 = projMatrix * Vector3(nearx1, 0, -mNearDist);
-
-					// find out whether this is a left side or right side
-					float Px1 = -(Pz1 * Nz1) / Nx1;
-					if (Px1 > eyeSpacePos.x)
-					{
-						*right = std::min(*right, relx1.x);
-					}
-					else
-					{
-						*left = std::max(*left, relx1.x);
-					}
-				}
-			}
-
-
-			// Now YZ 
-			// calculate quadratic discriminant: b*b - 4ac
-			// x = Ny
-			// a = Ly^2 + Lz^2
-			// b = -2rLy
-			// c = r^2 - Lz^2
-			a = Lyz;
-			b = -2.0f * r * eyeSpacePos.y;
-			c = rsq - Math::Sqr(eyeSpacePos.z);
-			D = b*b - 4.0f*a*c;
-
-			// two roots?
-			if (D > 0)
-			{
-				float sqrootD = Math::Sqrt(D);
-				// solve the quadratic to get the components of the normal
-				float Ny0 = (-b + sqrootD) / (2 * a);
-				float Ny1 = (-b - sqrootD) / (2 * a);
-
-				// Derive Z from this
-				float Nz0 = (r - Ny0 * eyeSpacePos.y) / eyeSpacePos.z;
-				float Nz1 = (r - Ny1 * eyeSpacePos.y) / eyeSpacePos.z;
-
-				// Get the point of tangency
-				// Only consider points of tangency in front of the camera
-				float Pz0 = (Lyz - rsq) / (eyeSpacePos.z - ((Nz0 / Ny0) * eyeSpacePos.y));
-				if (Pz0 < 0)
-				{
-					// Project point onto near plane in worldspace
-					float neary0 = (Nz0 * mNearDist) / Ny0;
-					// now we need to map this to viewport coords
-					// use projection matriy since that will take into account all factors
-					Vector3 rely0 = projMatrix * Vector3(0, neary0, -mNearDist);
-
-					// find out whether this is a top side or bottom side
-					float Py0 = -(Pz0 * Nz0) / Ny0;
-					if (Py0 > eyeSpacePos.y)
-					{
-						*top = std::min(*top, rely0.y);
-					}
-					else
-					{
-						*bottom = std::max(*bottom, rely0.y);
-					}
-				}
-				float Pz1 = (Lyz - rsq) / (eyeSpacePos.z - ((Nz1 / Ny1) * eyeSpacePos.y));
-				if (Pz1 < 0)
-				{
-					// Project point onto near plane in worldspace
-					float neary1 = (Nz1 * mNearDist) / Ny1;
-					// now we need to map this to viewport coords
-					// use projection matriy since that will take into account all factors
-					Vector3 rely1 = projMatrix * Vector3(0, neary1, -mNearDist);
-
-					// find out whether this is a top side or bottom side
-					float Py1 = -(Pz1 * Nz1) / Ny1;
-					if (Py1 > eyeSpacePos.y)
-					{
-						*top = std::min(*top, rely1.y);
-					}
-					else
-					{
-						*bottom = std::max(*bottom, rely1.y);
-					}
-				}
-			}
-		}
-
-		return (*left != -1.0f) || (*top != 1.0f) || (*right != 1.0f) || (*bottom != -1.0f);
-
-	}
-	//---------------------------------------------------------------------
 	void Camera::setCustomViewMatrix(bool enable, const Matrix4& viewMatrix)
 	{
 		mCustomViewMatrix = enable;

+ 0 - 19
CamelotClient/CamelotClient.cpp

@@ -31,7 +31,6 @@
 
 
 #include "CmDebugCamera.h"
-#include "CmTestTextSprite.h"
 #include "DbgEditorWidget1.h"
 #include "DbgEditorWidget2.h"
 #include "CmRTTIType.h"
@@ -74,26 +73,9 @@ int CALLBACK WinMain(
 	RenderSystem* renderSystem = RenderSystem::instancePtr();
 	RenderWindowPtr renderWindow = gApplication().getPrimaryWindow();
 
-	HSceneObject cameraGO = SceneObject::create("MainCamera");
-	HCamera camera = cameraGO->addComponent<Camera>();
-
-	camera->initialize(renderWindow, 0.0f, 0.0f, 1.0f, 1.0f, 0);
-	cameraGO->setPosition(Vector3(0,50,1240));
-	cameraGO->lookAt(Vector3(0,50,-300));
-	camera->setNearClipDistance(5);
-	camera->setAspectRatio(800.0f / 600.0f);
-
-	GameObjectHandle<DebugCamera> debugCamera = cameraGO->addComponent<DebugCamera>();
-
 	HSceneObject testModelGO = SceneObject::create("TestMesh");
 	HRenderable testRenderable = testModelGO->addComponent<Renderable>();
 
-	HSceneObject testTextGO = SceneObject::create("TestText");
-	GameObjectHandle<TestTextSprite> textSprite = testTextGO->addComponent<TestTextSprite>();
-	textSprite->initialize(camera->getViewport().get(), renderWindow.get());
-
-	textSprite->init(camera, "Testing in a new row, does this work?");
-
 #if defined DX9
 	///////////////// HLSL 9 SHADERS //////////////////////////
 	String dx9psLoc = "C:\\Projects\\BansheeEngine\\Data\\hlsl9_ps.gpuprog";
@@ -336,7 +318,6 @@ int CALLBACK WinMain(
 	vertProgRef.reset();
 
 	testModelGO->destroy();
-	cameraGO->destroy();
 
 	newPassGL = nullptr;
 	newTechniqueGL = nullptr;

+ 4 - 4
CamelotClient/CamelotClient.vcxproj

@@ -255,8 +255,6 @@
     <Text Include="ReadMe.txt" />
   </ItemGroup>
   <ItemGroup>
-    <ClInclude Include="CmDebugCamera.h" />
-    <ClInclude Include="CmTestTextSprite.h" />
     <ClInclude Include="Include\BsDockManager.h" />
     <ClInclude Include="Include\BsEditorPrerequisites.h" />
     <ClInclude Include="Include\BsEditorWidget.h" />
@@ -267,6 +265,8 @@
     <ClInclude Include="Include\BsGUITabbedTitleBar.h" />
     <ClInclude Include="Include\BsGUIWindowFrameWidget.h" />
     <ClInclude Include="Include\BsMainEditorWindow.h" />
+    <ClInclude Include="Include\CmDebugCamera.h" />
+    <ClInclude Include="Include\CmTestTextSprite.h" />
     <ClInclude Include="Include\DbgEditorWidget1.h" />
     <ClInclude Include="Include\DbgEditorWidget2.h" />
     <ClInclude Include="stdafx.h" />
@@ -274,8 +274,6 @@
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="CamelotClient.cpp" />
-    <ClCompile Include="CmDebugCamera.cpp" />
-    <ClCompile Include="CmTestTextSprite.cpp" />
     <ClCompile Include="Source\BsDockManager.cpp" />
     <ClCompile Include="Source\BsEditorWidget.cpp" />
     <ClCompile Include="Source\BsEditorWidgetContainer.cpp" />
@@ -285,6 +283,8 @@
     <ClCompile Include="Source\BsGUITabbedTitleBar.cpp" />
     <ClCompile Include="Source\BsGUIWindowFrameWidget.cpp" />
     <ClCompile Include="Source\BsMainEditorWindow.cpp" />
+    <ClCompile Include="Source\CmDebugCamera.cpp" />
+    <ClCompile Include="Source\CmTestTextSprite.cpp" />
     <ClCompile Include="Source\DbgEditorWidget1.cpp" />
     <ClCompile Include="Source\DbgEditorWidget2.cpp" />
     <ClCompile Include="stdafx.cpp" />

+ 12 - 12
CamelotClient/CamelotClient.vcxproj.filters

@@ -30,12 +30,6 @@
     <ClInclude Include="targetver.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="CmDebugCamera.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="CmTestTextSprite.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
     <ClInclude Include="Include\BsEditorWidgetContainer.h">
       <Filter>Header Files\Editor</Filter>
     </ClInclude>
@@ -72,6 +66,12 @@
     <ClInclude Include="Include\BsMainEditorWindow.h">
       <Filter>Header Files\Editor</Filter>
     </ClInclude>
+    <ClInclude Include="Include\CmTestTextSprite.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\CmDebugCamera.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="stdafx.cpp">
@@ -80,12 +80,6 @@
     <ClCompile Include="CamelotClient.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="CmDebugCamera.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="CmTestTextSprite.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="Source\BsEditorWidgetContainer.cpp">
       <Filter>Source Files\Editor</Filter>
     </ClCompile>
@@ -119,5 +113,11 @@
     <ClCompile Include="Source\BsMainEditorWindow.cpp">
       <Filter>Source Files\Editor</Filter>
     </ClCompile>
+    <ClCompile Include="Source\CmTestTextSprite.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\CmDebugCamera.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 4 - 2
CamelotClient/Include/BsEditorWindowBase.h

@@ -22,7 +22,10 @@ namespace BansheeEditor
 	protected:
 		EditorWindowBase();
 		EditorWindowBase(CM::RenderWindowPtr renderWindow);
+
+		CM::HSceneObject mSceneObject;
 		BS::HGUIWidget mGUI;
+		BS::HCamera mCamera;
 		bool mOwnsRenderWindow;
 
 		void construct(CM::RenderWindowPtr renderWindow);
@@ -30,8 +33,7 @@ namespace BansheeEditor
 		virtual void movedOrResized() { }
 	private:
 		CM::RenderWindowPtr mRenderWindow;
-		CM::HSceneObject mSceneObject;
-
+		
 		void movedOrResized(CM::RenderWindow& renderWindow);
 	};
 }

+ 39 - 0
CamelotClient/Include/CmDebugCamera.h

@@ -0,0 +1,39 @@
+#pragma once
+
+#include "BsPrerequisites.h"
+#include "CmComponent.h"
+#include "CmMath.h"
+
+namespace CamelotFramework
+{
+	class DebugCamera : public Component
+	{
+	private:
+		float mCurrentSpeed;
+
+		Degree mPitch;
+		Degree mYaw;
+		bool mLastButtonState;
+
+		BS::HCamera mCamera;
+
+		static const float START_SPEED;
+		static const float TOP_SPEED;
+		static const float ACCELERATION;
+		static const float FAST_MODE_MULTIPLIER;
+		static const float ROTATION_SPEED; // Degrees/second
+
+		/************************************************************************/
+		/* 						COMPONENT OVERRIDES                      		*/
+		/************************************************************************/
+	protected:
+		friend class SceneObject;
+
+		/** Standard constructor.
+        */
+		DebugCamera(const HSceneObject& parent);
+
+	public:
+		virtual void update();
+	};
+}

+ 19 - 0
CamelotClient/Include/CmTestTextSprite.h

@@ -0,0 +1,19 @@
+#include "BsPrerequisites.h"
+#include "BsGUIWidget.h"
+
+namespace CamelotFramework
+{
+	class TestTextSprite : public BansheeEngine::GUIWidget
+	{
+	protected:
+		friend class CM::SceneObject;
+
+		TestTextSprite(const HSceneObject& parent);
+	public:
+		~TestTextSprite();
+
+		virtual void update();
+
+		void init(const BS::HCamera& camera, const String& text, CM::RenderTexturePtr sceneView);
+	};
+}

+ 7 - 7
CamelotClient/Source/BsEditorWindowBase.cpp

@@ -61,21 +61,21 @@ namespace BansheeEditor
 		mRenderWindow = renderWindow;
 		mSceneObject = SceneObject::create("EditorWindow");
 
-		HCamera camera = mSceneObject->addComponent<Camera>();
-		camera->initialize(renderWindow, 0.0f, 0.0f, 1.0f, 1.0f, 0);
-		camera->setNearClipDistance(5);
-		camera->setAspectRatio(1.0f);
-		camera->setIgnoreSceneRenderables(true);
+		mCamera = mSceneObject->addComponent<Camera>();
+		mCamera->initialize(renderWindow, 0.0f, 0.0f, 1.0f, 1.0f, 0);
+		mCamera->setNearClipDistance(5);
+		mCamera->setAspectRatio(1.0f);
+		mCamera->setIgnoreSceneRenderables(true);
 
 		mGUI = mSceneObject->addComponent<GUIWidget>();
-		mGUI->initialize(camera->getViewport().get(), renderWindow.get());
+		mGUI->initialize(mCamera->getViewport().get(), renderWindow.get());
 		mGUI->setDepth(128);
 
 		mGUI->setSkin(&EngineGUI::instance().getSkin());
 
 		GameObjectHandle<WindowFrameWidget> frame = mSceneObject->addComponent<WindowFrameWidget>();
 		frame->setSkin(&EngineGUI::instance().getSkin());
-		frame->initialize(camera->getViewport().get(), renderWindow.get());
+		frame->initialize(mCamera->getViewport().get(), renderWindow.get());
 		frame->setDepth(129);
 
 		RenderWindowManager::instance().onMovedOrResized.connect(boost::bind(&EditorWindowBase::movedOrResized, this, _1));

+ 25 - 0
CamelotClient/Source/BsMainEditorWindow.cpp

@@ -1,5 +1,12 @@
 #include "BsMainEditorWindow.h"
 #include "BsDockManager.h"
+#include "BsCamera.h"
+#include "CmSceneObject.h"
+#include "CmRenderTexture.h"
+
+// DEBUG ONLY
+#include "CmTestTextSprite.h"
+#include "CmDebugCamera.h"
 
 using namespace CamelotFramework;
 using namespace BansheeEngine;
@@ -9,7 +16,25 @@ namespace BansheeEditor
 	MainEditorWindow::MainEditorWindow(CM::RenderWindowPtr renderWindow)
 		:EditorWindowBase(renderWindow), mDockManager(cm_new<DockManager>(mGUI.get()))
 	{
+		// DEBUG ONLY
+
+		HSceneObject sceneCameraGO = SceneObject::create("SceneCamera");
+		HCamera sceneCamera = sceneCameraGO->addComponent<Camera>();
+
+		RenderTexturePtr sceneRenderTarget = RenderTexture::create(TEX_TYPE_2D, 800, 600);
+
+		sceneCamera->initialize(sceneRenderTarget, 0.0f, 0.0f, 1.0f, 1.0f, 0);
+		sceneCameraGO->setPosition(Vector3(0,50,1240));
+		sceneCameraGO->lookAt(Vector3(0,50,-300));
+		sceneCamera->setNearClipDistance(5);
+		sceneCamera->setAspectRatio(800.0f / 600.0f);
+
+		GameObjectHandle<DebugCamera> debugCamera = sceneCameraGO->addComponent<DebugCamera>();
+
+		GameObjectHandle<TestTextSprite> textSprite = mSceneObject->addComponent<TestTextSprite>();
+		textSprite->initialize(mCamera->getViewport().get(), renderWindow.get());
 
+		textSprite->init(mCamera, "Testing in a new row, does this work?", sceneRenderTarget);
 	}
 
 	MainEditorWindow::~MainEditorWindow()

+ 97 - 0
CamelotClient/Source/CmDebugCamera.cpp

@@ -0,0 +1,97 @@
+#include "CmDebugCamera.h"
+#include "CmInput.h"
+#include "CmVector3.h"
+#include "CmTime.h"
+#include "CmMath.h"
+#include "CmSceneObject.h"
+#include "BsCamera.h"
+#include "CmCursor.h"
+
+using namespace BansheeEngine;
+
+namespace CamelotFramework
+{
+	const float DebugCamera::START_SPEED = 40.0f;
+	const float DebugCamera::TOP_SPEED = 130.0f;
+	const float DebugCamera::ACCELERATION = 10.0f;
+	const float DebugCamera::FAST_MODE_MULTIPLIER = 2.0f;
+	const float DebugCamera::ROTATION_SPEED = 0.5f; // Degrees/pixel
+
+	DebugCamera::DebugCamera(const HSceneObject& parent)
+		:Component(parent), mPitch(0.0f), mYaw(0.0f), mLastButtonState(false)
+	{
+		mCamera = sceneObject()->getComponent<Camera>();
+		mCamera->setNearClipDistance(5);
+
+		//gameObject()->setPosition(Vector3(0,0,5050));
+		//gameObject()->lookAt(Vector3(0,0,-300));
+
+		sceneObject()->setPosition(Vector3(0,0,0));
+		sceneObject()->lookAt(Vector3(0,0,-1));
+	}
+
+	void DebugCamera::update()
+	{
+		bool goingForward = gInput().isButtonDown(BC_W) || gInput().isButtonDown(BC_UP);
+		bool goingBack = gInput().isButtonDown(BC_S) || gInput().isButtonDown(BC_DOWN);
+		bool goingLeft = gInput().isButtonDown(BC_A) || gInput().isButtonDown(BC_LEFT);
+		bool goingRight = gInput().isButtonDown(BC_D) || gInput().isButtonDown(BC_RIGHT);
+		bool fastMove = gInput().isButtonDown(BC_LSHIFT);
+		bool camRotating = gInput().isButtonDown(BC_MOUSE_RIGHT);
+
+		if(camRotating != mLastButtonState)
+		{
+			if(camRotating)
+				Cursor::hide();
+			else
+				Cursor::show();
+
+			mLastButtonState = camRotating;
+		}
+
+		Vector3 direction = Vector3::ZERO;
+		if (goingForward) direction += SO()->getForward();
+		if (goingBack) direction -= SO()->getForward();
+		if (goingRight) direction += SO()->getRight();
+		if (goingLeft) direction -= SO()->getRight();
+
+		if (direction.squaredLength() != 0)
+		{
+			direction.normalize();
+
+			float multiplier = 1.0f;
+			if(fastMove)
+				multiplier = FAST_MODE_MULTIPLIER;
+
+			mCurrentSpeed = Math::Clamp(mCurrentSpeed + ACCELERATION * gTime().getFrameDelta(), START_SPEED, TOP_SPEED);
+			mCurrentSpeed *= multiplier;
+		}
+		else
+		{
+			mCurrentSpeed = 0.0f;
+		}
+
+		float tooSmall = std::numeric_limits<float>::epsilon();
+		if(mCurrentSpeed > tooSmall)
+		{
+			Vector3 velocity = direction * mCurrentSpeed;
+			SO()->move(velocity * gTime().getFrameDelta());
+		}
+
+		if(camRotating)
+		{
+			mYaw += Degree(gInput().getHorizontalAxis() * ROTATION_SPEED);
+			mPitch += Degree(gInput().getVerticalAxis() * ROTATION_SPEED);
+
+			Quaternion yRot;
+			yRot.FromAngleAxis(Radian(mYaw), Vector3::UP);
+
+			Quaternion xRot;
+			xRot.FromAngleAxis(Radian(mPitch), yRot.xAxis());
+
+			Quaternion camRot = xRot * yRot;
+
+			SO()->setRotation(camRot);
+		}
+	}
+}

+ 45 - 0
CamelotClient/Source/CmTestTextSprite.cpp

@@ -0,0 +1,45 @@
+#include "CmTestTextSprite.h"
+#include "CmSceneObject.h"
+#include "BsRenderable.h"
+#include "CmMesh.h"
+#include "CmVector2.h"
+#include "BsTextSprite.h"
+#include "CmFont.h"
+#include "CmMaterial.h"
+#include "BsGUILabel.h"
+#include "BsGUISkin.h"
+#include "BsOverlayManager.h"
+#include "BsSpriteTexture.h"
+#include "BsEngineGUI.h"
+#include "BsGUITexture.h"
+#include "BsGUIArea.h"
+#include "BsGUILayout.h"
+
+using namespace BansheeEngine;
+
+namespace CamelotFramework
+{
+	TestTextSprite::TestTextSprite(const HSceneObject& parent)
+		:GUIWidget(parent)
+	{
+	}
+
+	TestTextSprite::~TestTextSprite()
+	{
+	}
+
+	void TestTextSprite::init(const HCamera& camera, const String& text, CM::RenderTexturePtr sceneView)
+	{
+		setSkin(&EngineGUI::instance().getSkin());
+
+		GUIArea* area = GUIArea::createStretchedXY(*this, 0, 0, 0, 0);
+
+		SpriteTexturePtr spriteTex = std::make_shared<SpriteTexture>(sceneView->getBindableColorTexture());
+		area->getLayout().addElement(GUITexture::create(*this, GUILayoutOptions::fixed(800, 600), spriteTex));
+	}
+
+	void TestTextSprite::update()
+	{
+
+	}
+}

+ 6 - 1
CamelotCore/Include/CmRenderTexture.h

@@ -45,7 +45,7 @@ namespace CamelotFramework
 		virtual ~RenderTexture();
 
 		static RenderTexturePtr create(TextureType textureType, UINT32 width, UINT32 height, 
-			PixelFormat format, bool hwGamma, UINT32 fsaa, const String& fsaaHint, 
+			PixelFormat format = PF_R8G8B8A8, bool hwGamma = false, UINT32 fsaa = 0, const String& fsaaHint = "", 
 			bool createDepth = true, PixelFormat depthStencilFormat = PF_D24S8);
 
 		void initialize(const RENDER_TEXTURE_DESC& desc);
@@ -60,10 +60,15 @@ namespace CamelotFramework
 		 */
 		bool requiresTextureFlipping() const { return false; }
 
+		const HTexture& getBindableColorTexture() const { return mBindableColorTex; }
+		const HTexture& getBindableDepthStencilTexture() const { return mBindableDepthStencilTex; }
 	protected:
 		TextureViewPtr mColorSurface;
 		TextureViewPtr mDepthStencilSurface;
 
+		HTexture mBindableColorTex;
+		HTexture mBindableDepthStencilTex;
+
 		RenderTexture();
 
 		/**

+ 7 - 6
CamelotCore/Include/CmTexture.h

@@ -92,8 +92,9 @@ namespace CamelotFramework {
         */
         virtual TextureType getTextureType(void) const { return mTextureType; }
 
-        /** Gets the number of mipmaps to be used for this texture.
-        */
+        /** Gets the number of mipmaps to be used for this texture. This number excludes the top level  
+         * map (which is always assumed to be present). 
+         */
         virtual UINT32 getNumMipmaps(void) const {return mNumMipmaps;}
 
 		/** Gets whether this texture will be set up so that on sampling it, 
@@ -112,15 +113,15 @@ namespace CamelotFramework {
 
 		/** Returns the height of the texture.
         */
-        virtual UINT32 getHeight(void) const { return mHeight; }
+        virtual UINT32 getHeight() const { return mHeight; }
 
         /** Returns the width of the texture.
         */
-        virtual UINT32 getWidth(void) const { return mWidth; }
+        virtual UINT32 getWidth() const { return mWidth; }
 
         /** Returns the depth of the texture (only applicable for 3D textures).
         */
-        virtual UINT32 getDepth(void) const { return mDepth; }
+        virtual UINT32 getDepth() const { return mDepth; }
 
         /** Returns the TextureUsage indentifier for this Texture
         */
@@ -130,7 +131,7 @@ namespace CamelotFramework {
 		virtual PixelFormat getFormat() const { return mFormat; }
 
         /** Returns true if the texture has an alpha layer. */
-        virtual bool hasAlpha(void) const;
+        virtual bool hasAlpha() const;
 
         /** Return the number of faces this texture has. This will be 6 for a cubemap
         	texture and 1 for a 1D, 2D or 3D one.

+ 1 - 1
CamelotCore/Include/CmTextureManager.h

@@ -170,7 +170,7 @@ namespace CamelotFramework {
 		 * 			and (optionally) a depth/stencil surface
 		 */
 		virtual RenderTexturePtr createRenderTexture(TextureType textureType, UINT32 width, UINT32 height, 
-			PixelFormat format, bool hwGamma, UINT32 fsaa, const String& fsaaHint, 
+			PixelFormat format = PF_R8G8B8A8, bool hwGamma = false, UINT32 fsaa = 0, const String& fsaaHint = "", 
 			bool createDepth = true, PixelFormat depthStencilFormat = PF_D24S8);
 
 		/**

+ 10 - 2
CamelotCore/Source/CmRenderTexture.cpp

@@ -103,20 +103,28 @@ namespace CamelotFramework
 		if(mColorSurface->getTexture()->getTextureType() != TEX_TYPE_2D)
 			CM_EXCEPT(NotImplementedException, "Render textures are currently only implemented for 2D surfaces.");
 
-		if((mColorSurface->getFirstArraySlice() + mColorSurface->getNumArraySlices()) >= mColorSurface->getTexture()->getNumFaces())
+		if((mColorSurface->getFirstArraySlice() + mColorSurface->getNumArraySlices()) > mColorSurface->getTexture()->getNumFaces())
 		{
 			CM_EXCEPT(InvalidParametersException, "Provided number of faces is out of range. Face: " + 
 				toString(mColorSurface->getFirstArraySlice() + mColorSurface->getNumArraySlices()) + 
 				". Max num faces: " + toString(mColorSurface->getTexture()->getNumFaces()));
 		}
 
-		if(mColorSurface->getMostDetailedMip() >= mColorSurface->getTexture()->getNumMipmaps())
+		if(mColorSurface->getMostDetailedMip() > mColorSurface->getTexture()->getNumMipmaps())
 		{
 			CM_EXCEPT(InvalidParametersException, "Provided number of mip maps is out of range. Mip level: " + 
 				toString(mColorSurface->getMostDetailedMip()) + ". Max num mipmaps: " + toString(mColorSurface->getTexture()->getNumMipmaps()));
 		}
 
 		RenderTarget::initialize();
+
+		// Create non-persistent resource handles for the used textures (we only need them because a lot of the code accepts only handles,
+		// since they're non persistent they don't really have any benefit over shared pointers)
+		if(mColorSurface != nullptr)
+			mBindableColorTex = Resource::_createResourceHandle(mColorSurface->getTexture());
+
+		if(mDepthStencilSurface != nullptr)
+			mBindableDepthStencilTex = Resource::_createResourceHandle(mDepthStencilSurface->getTexture());
 	}
 
 	void RenderTexture::throwIfBuffersDontMatch() const

+ 2 - 3
CamelotCore/Source/CmTexture.cpp

@@ -174,7 +174,6 @@ namespace CamelotFramework {
 		return face * (getNumMipmaps() + 1) + mip;
 	}
 
-	//----------------------------------------------------------------------------
 	PixelData Texture::lock(GpuLockOptions options, UINT32 mipLevel, UINT32 face)
 	{
 		THROW_IF_NOT_CORE_THREAD;
@@ -187,14 +186,14 @@ namespace CamelotFramework {
 
 		return lockImpl(options, mipLevel, face);
 	}
-	//-----------------------------------------------------------------------------
+
 	void Texture::unlock()
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
 		unlockImpl();
 	}
-	//-----------------------------------------------------------------------------
+
 	void Texture::copy(TexturePtr& target)
 	{
 		THROW_IF_NOT_CORE_THREAD;

+ 0 - 5
CamelotD3D11RenderSystem/Include/CmD3D11RenderTexture.h

@@ -18,10 +18,5 @@ namespace CamelotFramework
 		friend class D3D11TextureManager;
 
 		D3D11RenderTexture();
-
-		/**
-		 * @copydoc RenderTexture::initialize_internal().
-		 */
-		void initialize_internal();
 	};
 }

+ 6 - 0
CamelotD3D11RenderSystem/Source/CmD3D11RenderSystem.cpp

@@ -424,6 +424,9 @@ namespace CamelotFramework
 		default:
 			CM_EXCEPT(InvalidParametersException, "Unsupported gpu program type: " + toString(prg->getType()));
 		}
+
+		if (mDevice->hasError())
+			CM_EXCEPT(RenderingAPIException, "Failed to bindGpuProgram : " + mDevice->getErrorDescription());
 	}
 
 	void D3D11RenderSystem::unbindGpuProgram(GpuProgramType gptype)
@@ -523,6 +526,9 @@ namespace CamelotFramework
 				break;
 			};
 		}
+
+		if (mDevice->hasError())
+			CM_EXCEPT(RenderingAPIException, "Failed to bindGpuParams : " + mDevice->getErrorDescription());
 	}
 
 	void D3D11RenderSystem::draw(UINT32 vertexCount)

+ 0 - 5
CamelotD3D11RenderSystem/Source/CmD3D11RenderTexture.cpp

@@ -19,11 +19,6 @@ namespace CamelotFramework
 	{
 	}
 
-	void D3D11RenderTexture::initialize_internal()
-	{
-		// Do nothing
-	}
-
 	void D3D11RenderTexture::getCustomAttribute(const String& name, void* pData) const
 	{
 		if(name == "RTV")

+ 11 - 11
CamelotD3D9Renderer/Source/CmD3D9Texture.cpp

@@ -940,17 +940,7 @@ namespace CamelotFramework
 		IDirect3DVolume9 *volume;				
 		UINT32 mip, face;
 
-		
 		assert(textureResources != NULL);
-		assert(textureResources->pBaseTex);
-		// Make sure number of mips is right
-		UINT32 numCreatedMips = textureResources->pBaseTex->GetLevelCount() - 1;
-
-		if(numCreatedMips != mNumMipmaps)
-		{
-			CM_EXCEPT(InternalErrorException, "Number of created and wanted mip map levels doesn't match: " + 
-				toString(numCreatedMips) + "/" + toString(mNumMipmaps));
-		}
 
 		// Need to know static / dynamic
 		unsigned int bufusage;
@@ -998,7 +988,7 @@ namespace CamelotFramework
 		}
 		else if((mUsage & TU_DEPTHSTENCIL) != 0)
 		{
-			assert(textureResources->pFSAASurface);
+			assert(textureResources->pDepthStencilSurface);
 			assert(getTextureType() == TEX_TYPE_2D);
 
 			D3D9PixelBuffer* currPixelBuffer = GETLEVEL(0, 0);
@@ -1008,6 +998,16 @@ namespace CamelotFramework
 		}
 		else
 		{
+			assert(textureResources->pBaseTex);
+			// Make sure number of mips is right
+			UINT32 numCreatedMips = textureResources->pBaseTex->GetLevelCount() - 1;
+
+			if(numCreatedMips != mNumMipmaps)
+			{
+				CM_EXCEPT(InternalErrorException, "Number of created and wanted mip map levels doesn't match: " + 
+					toString(numCreatedMips) + "/" + toString(mNumMipmaps));
+			}
+
 			switch(getTextureType()) 
 			{
 			case TEX_TYPE_2D:

+ 2 - 1
CamelotGLRenderer/Source/CmGLFrameBufferObject.cpp

@@ -145,7 +145,8 @@ namespace CamelotFramework
             }
         }
 
-		mDepthStencilBuffer->bindToFramebuffer(GL_DEPTH_STENCIL_ATTACHMENT, 0);
+		if(mDepthStencilBuffer != nullptr)
+			mDepthStencilBuffer->bindToFramebuffer(GL_DEPTH_STENCIL_ATTACHMENT, 0);
 
 		/// Do glDrawBuffer calls
 		GLenum bufs[CM_MAX_MULTIPLE_RENDER_TARGETS];

+ 0 - 4
CamelotGLRenderer/Source/CmGLTexture.cpp

@@ -79,16 +79,12 @@ namespace CamelotFramework {
 
 		if((mUsage & TU_RENDERTARGET) != 0)
 		{
-			mNumMipmaps = 1;
-
 			if(mTextureType != TEX_TYPE_2D)
 				CM_EXCEPT(NotImplementedException, "Only 2D render targets are supported at the moment");
 		}
 
 		if((mUsage & TU_DEPTHSTENCIL) != 0)
 		{
-			mNumMipmaps = 1;
-
 			if(mTextureType != TEX_TYPE_2D)
 				CM_EXCEPT(NotImplementedException, "Only 2D depth stencil targets are supported at the moment");