Prechádzať zdrojové kódy

Added GUIVIewport code (untested)

Marko Pintera 12 rokov pred
rodič
commit
4053fb5da8

+ 2 - 0
BansheeEngine/BansheeEngine.vcxproj

@@ -251,6 +251,7 @@
     <ClInclude Include="Include\BsGUITexture.h" />
     <ClInclude Include="Include\BsGUIToggle.h" />
     <ClInclude Include="Include\BsGUIToggleGroup.h" />
+    <ClInclude Include="Include\BsGUIViewport.h" />
     <ClInclude Include="Include\BsGUIWindowFrame.h" />
     <ClInclude Include="Include\BsGUIWindowMover.h" />
     <ClInclude Include="Include\BsPrerequisites.h" />
@@ -327,6 +328,7 @@
     <ClCompile Include="Source\BsGLBuiltinMaterialFactory.cpp" />
     <ClCompile Include="Source\BsUpdateCallback.cpp" />
     <ClCompile Include="Source\BsGUILayoutX.cpp" />
+    <ClCompile Include="Source\BsGUIViewport.cpp" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">

+ 6 - 0
BansheeEngine/BansheeEngine.vcxproj.filters

@@ -195,6 +195,9 @@
     <ClInclude Include="Include\BsDragAndDropManager.h">
       <Filter>Header Files\GUI</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsGUIViewport.h">
+      <Filter>Header Files\GUI</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsGUIElement.cpp">
@@ -335,5 +338,8 @@
     <ClCompile Include="Source\BsDragAndDropManager.cpp">
       <Filter>Source Files\GUI</Filter>
     </ClCompile>
+    <ClCompile Include="Source\BsGUIViewport.cpp">
+      <Filter>Source Files\GUI</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 3 - 3
BansheeEngine/Include/BsCamera.h

@@ -110,7 +110,7 @@ namespace BansheeEngine {
         ProjectionType mProjType;
 
         /// y-direction field-of-view (default 45)
-        CM::Radian mFOVy;
+        CM::Radian mHorzFOV;
         /// Far clip distance - default 10000
         float mFarDist;
         /// Near clip distance - default 100
@@ -191,11 +191,11 @@ namespace BansheeEngine {
             @note
                 Setting the FOV overrides the value supplied for frustum::setNearClipPlane.
          */
-        virtual void setFOVy(const CM::Radian& fovy);
+        virtual void setHorzFOV(const CM::Radian& fovy);
 
         /** Retrieves the frustums Y-dimension Field Of View (FOV).
         */
-        virtual const CM::Radian& getFOVy(void) const;
+        virtual const CM::Radian& getHorzFOV(void) const;
 
         /** Sets the position of the near clipping plane.
             @remarks

+ 67 - 0
BansheeEngine/Include/BsGUIViewport.h

@@ -0,0 +1,67 @@
+#pragma once
+
+#include "BsPrerequisites.h"
+#include "BsGUIElement.h"
+#include "CmMath.h"
+
+namespace BansheeEngine
+{
+	/**
+	 * @brief	Displays a Camera view in the form of a GUI element.
+	 */
+	class BS_EXPORT GUIViewport : public GUIElement
+	{
+	public:
+		static const CM::String& getGUITypeName();
+
+		/**
+		 * @note Render target used by the GUIWidget and Camera must be the same. 
+		 */
+		static GUIViewport* create(GUIWidget& parent, const HCamera& camera, float aspectRatio, CM::Degree fieldOfView, const GUIElementStyle* style = nullptr);
+
+		/**
+		 * @note Render target used by the GUIWidget and Camera must be the same. 
+		 */
+		static GUIViewport* create(GUIWidget& parent, const GUILayoutOptions& layoutOptions, const HCamera& camera, 
+			float aspectRatio, CM::Degree fieldOfView, const GUIElementStyle* style = nullptr);
+	protected:
+		~GUIViewport();
+
+		/**
+		 * @copydoc GUIElement::getNumRenderElements()
+		 */
+		virtual CM::UINT32 getNumRenderElements() const;
+
+		/**
+		 * @copydoc GUIElement::getMaterial()
+		 */
+		virtual const CM::HMaterial& getMaterial(CM::UINT32 renderElementIdx) const;
+
+		/**
+		 * @copydoc GUIElement::getNumQuads()
+		 */
+		virtual CM::UINT32 getNumQuads(CM::UINT32 renderElementIdx) const;
+
+		/**
+		 * @copydoc GUIElement::fillBuffer()
+		 */
+		virtual void fillBuffer(CM::UINT8* vertices, CM::UINT8* uv, CM::UINT32* indices, CM::UINT32 startingQuad, 
+			CM::UINT32 maxNumQuads, CM::UINT32 vertexStride, CM::UINT32 indexStride, CM::UINT32 renderElementIdx) const;
+
+		/**
+		 * @copydoc GUIElement::updateBounds()
+		 */
+		virtual void updateBounds();
+
+		virtual CM::UINT32 _getOptimalWidth() const;
+		virtual CM::UINT32 _getOptimalHeight() const;
+
+	private:
+		HCamera mCamera;
+		float mAspectRatio;
+		CM::Degree mFieldOfView;
+		CM::Radian mVerticalFOV;
+
+		GUIViewport(GUIWidget& parent, const GUIElementStyle* style, const HCamera& camera, float aspectRatio, CM::Degree fieldOfView, const GUILayoutOptions& layoutOptions);
+	};
+}

+ 7 - 7
BansheeEngine/Source/BsCamera.cpp

@@ -50,7 +50,7 @@ namespace BansheeEngine
 	Camera::Camera(const HSceneObject& parent)
         : Component(parent),
 		mProjType(PT_PERSPECTIVE), 
-		mFOVy(Radian(Math::PI/4.0f)), 
+		mHorzFOV(Radian(Math::PI/4.0f)), 
 		mFarDist(100000.0f), 
 		mNearDist(100.0f), 
 		mAspect(1.33333333333333f), 
@@ -72,7 +72,7 @@ namespace BansheeEngine
 		updateFrustum();
 
         // Reasonable defaults to camera params
-        mFOVy = Radian(Math::PI/4.0f);
+        mHorzFOV = Radian(Math::PI/4.0f);
         mNearDist = 100.0f;
         mFarDist = 100000.0f;
         mAspect = 1.33333333333333f;
@@ -96,16 +96,16 @@ namespace BansheeEngine
 		mViewport = cm_shared_ptr<Viewport, PoolAlloc>(target, left, top, width, height, ZOrder);
 	}
 	//-----------------------------------------------------------------------
-	void Camera::setFOVy(const Radian& fov)
+	void Camera::setHorzFOV(const Radian& fov)
 	{
-		mFOVy = fov;
+		mHorzFOV = fov;
 		invalidateFrustum();
 	}
 
 	//-----------------------------------------------------------------------
-	const Radian& Camera::getFOVy(void) const
+	const Radian& Camera::getHorzFOV(void) const
 	{
-		return mFOVy;
+		return mHorzFOV;
 	}
 
 
@@ -345,7 +345,7 @@ namespace BansheeEngine
 			// Calculate general projection parameters
 			else if (mProjType == PT_PERSPECTIVE)
 			{
-				Radian thetaY (mFOVy * 0.5f);
+				Radian thetaY (mHorzFOV * 0.5f);
 				float tanThetaY = Math::Tan(thetaY);
 				float tanThetaX = tanThetaY * mAspect;
 

+ 114 - 0
BansheeEngine/Source/BsGUIViewport.cpp

@@ -0,0 +1,114 @@
+#include "BsGUIViewport.h"
+#include "BsGUIWidget.h"
+#include "BsGUISkin.h"
+#include "BsSpriteTexture.h"
+#include "BsGUILayoutOptions.h"
+#include "BsCamera.h"
+#include "CmViewport.h"
+#include "CmRenderTarget.h"
+#include "CmException.h"
+
+using namespace CamelotFramework;
+
+namespace BansheeEngine
+{
+	const String& GUIViewport::getGUITypeName()
+	{
+		static String name = "Viewport";
+		return name;
+	}
+
+	GUIViewport::GUIViewport(GUIWidget& parent, const GUIElementStyle* style, const HCamera& camera, 
+		float aspectRatio, CM::Degree fieldOfView, const GUILayoutOptions& layoutOptions)
+		:GUIElement(parent, style, layoutOptions), mCamera(camera), mAspectRatio(aspectRatio),
+		mFieldOfView(fieldOfView)
+	{
+		RenderTargetPtr guiRenderTarget = parent.getTarget()->getTarget();
+		RenderTargetPtr cameraRenderTarget = camera->getViewport()->getTarget();
+
+		if(guiRenderTarget != cameraRenderTarget)
+			CM_EXCEPT(InvalidParametersException, "Camera provided to GUIViewport must use the same render target as the GUIWidget this element is located on.")
+
+		mVerticalFOV = 2.0f * Math::ATan(Math::Tan(mFieldOfView.valueRadians() * 0.5f) * (1.0f / mAspectRatio));
+	}
+
+	GUIViewport::~GUIViewport()
+	{
+
+	}
+
+	GUIViewport* GUIViewport::create(GUIWidget& parent, const HCamera& camera, float aspectRatio, CM::Degree fieldOfView, const GUIElementStyle* style)
+	{
+		if(style == nullptr)
+		{
+			const GUISkin* skin = parent.getSkin();
+			style = skin->getStyle(getGUITypeName());
+		}
+
+		return new (cm_alloc<GUIViewport, PoolAlloc>()) GUIViewport(parent, style, camera, aspectRatio, fieldOfView, getDefaultLayoutOptions(style));
+	}
+
+	GUIViewport* GUIViewport::create(GUIWidget& parent, const GUILayoutOptions& layoutOptions, const HCamera& camera, 
+		float aspectRatio, CM::Degree fieldOfView, const GUIElementStyle* style)
+	{
+		if(style == nullptr)
+		{
+			const GUISkin* skin = parent.getSkin();
+			style = skin->getStyle(getGUITypeName());
+		}
+
+		return new (cm_alloc<GUIViewport, PoolAlloc>()) GUIViewport(parent, style, camera, aspectRatio, fieldOfView, layoutOptions);
+	}
+
+	UINT32 GUIViewport::getNumRenderElements() const
+	{
+		return 0;
+	}
+
+	const HMaterial& GUIViewport::getMaterial(UINT32 renderElementIdx) const
+	{
+		CM_EXCEPT(InternalErrorException, "This element has no render element so no material can be retrieved.");
+	}
+
+	UINT32 GUIViewport::getNumQuads(UINT32 renderElementIdx) const
+	{
+		return 0;
+	}
+
+	void GUIViewport::updateBounds()
+	{
+		Rect mBounds = Rect(0, 0, mWidth, mHeight);
+		mBounds.clip(mClipRect);
+		mBounds.x += mOffset.x;
+		mBounds.y += mOffset.y;
+	}
+
+	UINT32 GUIViewport::_getOptimalWidth() const
+	{
+		return 0;
+	}
+
+	UINT32 GUIViewport::_getOptimalHeight() const
+	{
+		return 0;
+	}
+
+	void GUIViewport::fillBuffer(UINT8* vertices, UINT8* uv, UINT32* indices, UINT32 startingQuad, UINT32 maxNumQuads, 
+		UINT32 vertexStride, UINT32 indexStride, UINT32 renderElementIdx) const
+	{
+		float currentAspect = mWidth / (float)mHeight;
+		Radian currentFOV = 2.0f * Math::ATan(Math::Tan(mVerticalFOV * 0.5f) * currentAspect);
+
+		mCamera->setHorzFOV(currentFOV);
+
+		ViewportPtr viewport = mCamera->getViewport();
+		RenderTargetPtr renderTarget = viewport->getTarget();
+
+		float x = mOffset.x / (float)renderTarget->getWidth();
+		float y = mOffset.y / (float)renderTarget->getHeight();
+		float width = mWidth / (float)renderTarget->getWidth();
+		float height = mHeight / (float)renderTarget->getHeight();
+
+		viewport->setDimensions(x, y, width, height);
+	}
+}

+ 0 - 4
CamelotClient/CamelotClient.cpp

@@ -66,10 +66,6 @@ int CALLBACK WinMain(
 	gBansheeApp().startUp(renderWindowDesc, "CamelotGLRenderSystem", "BansheeForwardRenderer", "D:\\CamelotResourceMetas");
 #endif
 
-	//CommandQueue::addBreakpoint(0, 19);
-	//CommandQueue::addBreakpoint(0, 22);
-	//CommandQueue::addBreakpoint(0, 12);
-
 	RenderSystem* renderSystem = RenderSystem::instancePtr();
 	RenderWindowPtr renderWindow = gApplication().getPrimaryWindow();
 

+ 0 - 6
EditorWindowDock.txt

@@ -20,14 +20,8 @@ DockContainer biggest issues:
 FIRST CREATE DOCK CONTAINER WITHOUT DRAG AND DROP SUPPORT
 
 RenderTexture issues:
- Rename waitUntilInitialized to synchronize()
  Set up a GUIViewport element which sets up a camera so it renders to that part of the window
 
- DirectX 9 currently DOES NOT support bindable render textures:
-  - Bindable render textures should be created using CreateTexture and D3DUSAGE_RENDERTARGET/D3DUSAGE_DEPTHSTENCIL
-   - UNLESS render target is using antialiasing, in which case it cannot be bound and should be created as it
-    - However if it cannot be bound I should warn the user (in RenderTexture::getBindable* methods)
-
 Make sure to test everything thoroughly - right now I have tested very little
 Drag and drop manager currently ignores the provided icon, but it should use it as a cursor