瀏覽代碼

Added menu items for GUI widget
Fixed incorrect window resolution recorded in game settings

BearishSun 10 年之前
父節點
當前提交
66a198398f

+ 0 - 2
BansheeCore/BansheeCore.vcxproj

@@ -311,7 +311,6 @@
     <ClInclude Include="Include\BsPrefabRTTI.h" />
     <ClInclude Include="Include\BsPrefabUtility.h" />
     <ClInclude Include="Include\BsRendererMeshData.h" />
-    <ClInclude Include="Include\BsRendererUtility.h" />
     <ClInclude Include="Include\BsShaderIncludeRTTI.h" />
     <ClInclude Include="Include\BsIResourceListener.h" />
     <ClInclude Include="Include\BsMaterialParam.h" />
@@ -496,7 +495,6 @@
     <ClCompile Include="Source\BsGpuParams.cpp" />
     <ClCompile Include="Source\BsProfilerGPU.cpp" />
     <ClCompile Include="Source\BsRendererMeshData.cpp" />
-    <ClCompile Include="Source\BsRendererUtility.cpp" />
     <ClCompile Include="Source\BsShaderInclude.cpp" />
     <ClCompile Include="Source\BsGpuProgram.cpp" />
     <ClCompile Include="Source\BsGpuResourceData.cpp" />

+ 0 - 6
BansheeCore/BansheeCore.vcxproj.filters

@@ -548,9 +548,6 @@
     <ClInclude Include="Include\BsParamBlocks.h">
       <Filter>Header Files\Renderer</Filter>
     </ClInclude>
-    <ClInclude Include="Include\BsRendererUtility.h">
-      <Filter>Header Files\Renderer</Filter>
-    </ClInclude>
     <ClInclude Include="Include\BsProfilerCPU.h">
       <Filter>Header Files\Profiling</Filter>
     </ClInclude>
@@ -889,9 +886,6 @@
     <ClCompile Include="Source\Win32\BsWin32Window.cpp">
       <Filter>Source Files\Win32</Filter>
     </ClCompile>
-    <ClCompile Include="Source\BsRendererUtility.cpp">
-      <Filter>Source Files\Renderer</Filter>
-    </ClCompile>
     <ClCompile Include="Source\BsProfilerCPU.cpp">
       <Filter>Source Files\Profiling</Filter>
     </ClCompile>

+ 2 - 0
BansheeEngine/BansheeEngine.vcxproj

@@ -275,6 +275,7 @@
     <ClCompile Include="Source\BsRenderer.cpp" />
     <ClCompile Include="Source\BsRendererMaterial.cpp" />
     <ClCompile Include="Source\BsRendererMaterialManager.cpp" />
+    <ClCompile Include="Source\BsRendererUtility.cpp" />
     <ClCompile Include="Source\BsRenderQueue.cpp" />
     <ClCompile Include="Source\BsScriptCode.cpp" />
     <ClCompile Include="Source\BsScriptCodeImporter.cpp" />
@@ -319,6 +320,7 @@
     <ClInclude Include="Include\BsRenderer.h" />
     <ClInclude Include="Include\BsRendererMaterial.h" />
     <ClInclude Include="Include\BsRendererMaterialManager.h" />
+    <ClInclude Include="Include\BsRendererUtility.h" />
     <ClInclude Include="Include\BsScriptCode.h" />
     <ClInclude Include="Include\BsScriptCodeImporter.h" />
     <ClInclude Include="Include\BsScriptCodeImportOptions.h" />

+ 6 - 0
BansheeEngine/BansheeEngine.vcxproj.filters

@@ -398,6 +398,9 @@
     <ClInclude Include="Include\BsShortcutKey.h">
       <Filter>Header Files\GUI</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsRendererUtility.h">
+      <Filter>Header Files\Renderer</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsGUIElement.cpp">
@@ -664,5 +667,8 @@
     <ClCompile Include="Source\BsCGUIWidget.cpp">
       <Filter>Source Files\GUI</Filter>
     </ClCompile>
+    <ClCompile Include="Source\BsRendererUtility.cpp">
+      <Filter>Source Files\Renderer</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 14 - 0
BansheeEngine/Include/BsPrerequisites.h

@@ -2,6 +2,20 @@
 
 #include "BsCorePrerequisites.h"
 
+/** @defgroup Engine Engine
+ *	Specific implementation of the BansheeCore layer. This layer provides a more focused goal than the more generic
+ *  BansheeCore layer, and therefore provides specific implementations of various abstract interfaces from BansheeCore,
+ *  either directly or through specific plugins.
+ *  @{
+ */
+
+/** @defgroup Renderer-Engine Renderer
+  *	Abstract interface and helper functionality for rendering scene objects and other geometry (e.g. GUI). Provides more
+  * specialized functionality than Renderer abstraction in BansheeCore.
+  */
+
+/** @} */
+
 #if (BS_PLATFORM == BS_PLATFORM_WIN32) && !defined(__MINGW32__)
 #	ifdef BS_EXPORTS
 #		define BS_EXPORT __declspec(dllexport)

+ 12 - 4
BansheeCore/Include/BsRendererUtility.h → BansheeEngine/Include/BsRendererUtility.h

@@ -1,6 +1,6 @@
 #pragma once
 
-#include "BsCorePrerequisites.h"
+#include "BsPrerequisites.h"
 #include "BsModule.h"
 #include "BsRect2.h"
 #include "BsVector2I.h"
@@ -8,7 +8,7 @@
 namespace BansheeEngine
 {
 	/** @cond INTERNAL */
-	/** @addtogroup Renderer
+	/** @addtogroup Renderer-Engine
 	 *  @{
 	 */
 
@@ -17,7 +17,7 @@ namespace BansheeEngine
 	 * 			
 	 * @note	Core thread only.
 	 */
-	class BS_CORE_EXPORT RendererUtility : public Module<RendererUtility>
+	class BS_EXPORT RendererUtility : public Module<RendererUtility>
 	{
 	public:
 		RendererUtility();
@@ -65,8 +65,16 @@ namespace BansheeEngine
 		void drawScreenQuad(const ViewportCore& viewport, const Rect2& uv = Rect2(0.0f, 0.0f, 1.0f, 1.0f), 
 			const Vector2I& textureSize = Vector2I(1, 1));
 
+		/** Returns a stencil mesh used for a point light (a unit sphere). */
+		SPtr<MeshCore> getPointLightStencil() const { return mPointLightStencilMesh; }
+
+		/** Returns a stencil mesh used for spot light. Actual vertex positions need to be computed in shader. */
+		SPtr<MeshCore> getSpotLightStencil() const { return mSpotLightStencilMesh; }
+
 	private:
 		SPtr<MeshCore> mFullScreenQuadMesh;
+		SPtr<MeshCore> mPointLightStencilMesh;
+		SPtr<MeshCore> mSpotLightStencilMesh;
 	};
 
 	/**
@@ -74,7 +82,7 @@ namespace BansheeEngine
 	 * 			
 	 * @note	Core thread only.
 	 */
-	BS_CORE_EXPORT RendererUtility& gRendererUtility();
+	BS_EXPORT RendererUtility& gRendererUtility();
 
 	/** @} */
 	/** @endcond */

+ 3 - 109
BansheeEngine/Source/BsLight.cpp

@@ -1,119 +1,13 @@
 #include "BsLight.h"
 #include "BsLightRTTI.h"
-#include "BsRendererManager.h"
 #include "BsRenderer.h"
 #include "BsFrameAlloc.h"
 #include "BsSceneObject.h"
-#include "BsVertexDataDesc.h"
 #include "BsMesh.h"
-#include "BsShapeMeshes3D.h"
+#include "BsRendererUtility.h"
 
 namespace BansheeEngine
 {
-	/** Contains stencil meshes used for rendering light geometry */
-	class LightStencilGeometry
-	{
-	public:
-		/** Returns a stencil mesh used for a point light (a unit sphere). */
-		static SPtr<MeshCore> getPointLightStencil()
-		{
-			if (sPointLightMesh == nullptr)
-			{
-				SPtr<VertexDataDesc> vertexDesc = bs_shared_ptr_new<VertexDataDesc>();
-				vertexDesc->addVertElem(VET_FLOAT3, VES_POSITION);
-
-				UINT32 numVertices = 0;
-				UINT32 numIndices = 0;
-
-				ShapeMeshes3D::getNumElementsSphere(3, numVertices, numIndices);
-				MeshDataPtr meshData = bs_shared_ptr_new<MeshData>(numVertices, numIndices, vertexDesc);
-
-				UINT32* indexData = meshData->getIndices32();
-				UINT8* positionData = meshData->getElementData(VES_POSITION);
-
-				Sphere localSphere(Vector3::ZERO, 1.0f);
-				ShapeMeshes3D::solidSphere(localSphere, positionData, nullptr, 0,
-					vertexDesc->getVertexStride(), indexData, 0, 3);
-
-				sPointLightMesh = MeshCore::create(meshData);
-			}
-
-			return sPointLightMesh;
-		}
-
-		/** Returns a stencil mesh used for spot light. Actual vertex positions need to be computed in shader. */
-		static SPtr<MeshCore> getSpotLightStencil()
-		{
-			if (sSpotLightMesh == nullptr)
-			{
-				UINT32 numSides = LightCore::LIGHT_CONE_NUM_SIDES;
-				UINT32 numSlices = LightCore::LIGHT_CONE_NUM_SLICES;
-
-				SPtr<VertexDataDesc> vertexDesc = bs_shared_ptr_new<VertexDataDesc>();
-				vertexDesc->addVertElem(VET_FLOAT3, VES_POSITION);
-
-				UINT32 numVertices = numSides * numSlices * 2;
-				UINT32 numIndices = ((numSides * 2) * (numSlices - 1) * 2) * 3;
-
-				MeshDataPtr meshData = bs_shared_ptr_new<MeshData>(numVertices, numIndices, vertexDesc);
-
-				UINT32* indexData = meshData->getIndices32();
-				UINT8* positionData = meshData->getElementData(VES_POSITION);
-				UINT32 stride = vertexDesc->getVertexStride();
-
-				// Dummy vertex positions, actual ones generated in shader
-				for (UINT32 i = 0; i < numVertices; i++)
-				{
-					memcpy(positionData, &Vector3::ZERO, sizeof(Vector3));
-					positionData += stride;
-				}
-
-				// Cone indices
-				UINT32 curIdx = 0;
-				for (UINT32 sliceIdx = 0; sliceIdx < (numSlices - 1); sliceIdx++)
-				{
-					for (UINT32 sideIdx = 0; sideIdx < numSides; sideIdx++)
-					{
-						indexData[curIdx++] = sliceIdx * numSides + sideIdx;
-						indexData[curIdx++] = sliceIdx * numSides + (sideIdx + 1) % numSides;
-						indexData[curIdx++] = (sliceIdx + 1) * numSides + sideIdx;
-
-						indexData[curIdx++] = sliceIdx * numSides + (sideIdx + 1) % numSides;
-						indexData[curIdx++] = (sliceIdx + 1) * numSides + (sideIdx + 1) % numSides;
-						indexData[curIdx++] = (sliceIdx + 1) * numSides + sideIdx;
-					}
-				}
-
-				// Sphere cap indices
-				UINT32 coneOffset = numSides * numSlices;
-				for (UINT32 sliceIdx = 0; sliceIdx < (numSlices - 1); sliceIdx++)
-				{
-					for (UINT32 sideIdx = 0; sideIdx < numSides; sideIdx++)
-					{
-						indexData[curIdx++] = coneOffset + sliceIdx * numSides + sideIdx;
-						indexData[curIdx++] = coneOffset + sliceIdx * numSides + (sideIdx + 1) % numSides;
-						indexData[curIdx++] = coneOffset + (sliceIdx + 1) * numSides + sideIdx;
-
-						indexData[curIdx++] = coneOffset + sliceIdx * numSides + (sideIdx + 1) % numSides;
-						indexData[curIdx++] = coneOffset + (sliceIdx + 1) * numSides + (sideIdx + 1) % numSides;
-						indexData[curIdx++] = coneOffset + (sliceIdx + 1) * numSides + sideIdx;
-					}
-				}
-
-				sSpotLightMesh = MeshCore::create(meshData);
-			}
-
-			return sSpotLightMesh;
-		}
-
-	private:
-		static SPtr<MeshCore> sPointLightMesh;
-		static SPtr<MeshCore> sSpotLightMesh;
-	};
-
-	SPtr<MeshCore> LightStencilGeometry::sPointLightMesh;
-	SPtr<MeshCore> LightStencilGeometry::sSpotLightMesh;
-
 	LightBase::LightBase()
 		:mType(LightType::Point), mCastsShadows(false), mRange(10.0f),
 		mIntensity(5.0f), mSpotAngle(45), mSpotFalloffAngle(35.0f), mColor(Color::White), 
@@ -304,9 +198,9 @@ namespace BansheeEngine
 		case LightType::Directional:
 			return nullptr;
 		case LightType::Point:
-			return LightStencilGeometry::getPointLightStencil();
+			return RendererUtility::instance().getPointLightStencil();
 		case LightType::Spot:
-			return LightStencilGeometry::getSpotLightStencil();
+			return RendererUtility::instance().getSpotLightStencil();
 		}
 
 		return nullptr;

+ 86 - 4
BansheeCore/Source/BsRendererUtility.cpp → BansheeEngine/Source/BsRendererUtility.cpp

@@ -9,16 +9,98 @@
 #include "BsRasterizerState.h"
 #include "BsGpuParams.h"
 #include "BsGpuParamDesc.h"
+#include "BsShapeMeshes3D.h"
+#include "BsLight.h"
 
 namespace BansheeEngine
 {
 	RendererUtility::RendererUtility()
 	{
-		VertexDataDescPtr vertexDesc = bs_shared_ptr_new<VertexDataDesc>();
-		vertexDesc->addVertElem(VET_FLOAT3, VES_POSITION);
-		vertexDesc->addVertElem(VET_FLOAT2, VES_TEXCOORD);
+		{
+			VertexDataDescPtr vertexDesc = bs_shared_ptr_new<VertexDataDesc>();
+			vertexDesc->addVertElem(VET_FLOAT3, VES_POSITION);
+			vertexDesc->addVertElem(VET_FLOAT2, VES_TEXCOORD);
+
+			mFullScreenQuadMesh = MeshCore::create(4, 6, vertexDesc);
+		}
+
+		{
+			SPtr<VertexDataDesc> vertexDesc = bs_shared_ptr_new<VertexDataDesc>();
+			vertexDesc->addVertElem(VET_FLOAT3, VES_POSITION);
+
+			UINT32 numVertices = 0;
+			UINT32 numIndices = 0;
+
+			ShapeMeshes3D::getNumElementsSphere(3, numVertices, numIndices);
+			MeshDataPtr meshData = bs_shared_ptr_new<MeshData>(numVertices, numIndices, vertexDesc);
+
+			UINT32* indexData = meshData->getIndices32();
+			UINT8* positionData = meshData->getElementData(VES_POSITION);
+
+			Sphere localSphere(Vector3::ZERO, 1.0f);
+			ShapeMeshes3D::solidSphere(localSphere, positionData, nullptr, 0,
+				vertexDesc->getVertexStride(), indexData, 0, 3);
+
+			mPointLightStencilMesh = MeshCore::create(meshData);
+		}
+
+		{
+			UINT32 numSides = LightCore::LIGHT_CONE_NUM_SIDES;
+			UINT32 numSlices = LightCore::LIGHT_CONE_NUM_SLICES;
+
+			SPtr<VertexDataDesc> vertexDesc = bs_shared_ptr_new<VertexDataDesc>();
+			vertexDesc->addVertElem(VET_FLOAT3, VES_POSITION);
+
+			UINT32 numVertices = numSides * numSlices * 2;
+			UINT32 numIndices = ((numSides * 2) * (numSlices - 1) * 2) * 3;
+
+			MeshDataPtr meshData = bs_shared_ptr_new<MeshData>(numVertices, numIndices, vertexDesc);
+
+			UINT32* indexData = meshData->getIndices32();
+			UINT8* positionData = meshData->getElementData(VES_POSITION);
+			UINT32 stride = vertexDesc->getVertexStride();
 
-		mFullScreenQuadMesh = MeshCore::create(4, 6, vertexDesc);
+			// Dummy vertex positions, actual ones generated in shader
+			for (UINT32 i = 0; i < numVertices; i++)
+			{
+				memcpy(positionData, &Vector3::ZERO, sizeof(Vector3));
+				positionData += stride;
+			}
+
+			// Cone indices
+			UINT32 curIdx = 0;
+			for (UINT32 sliceIdx = 0; sliceIdx < (numSlices - 1); sliceIdx++)
+			{
+				for (UINT32 sideIdx = 0; sideIdx < numSides; sideIdx++)
+				{
+					indexData[curIdx++] = sliceIdx * numSides + sideIdx;
+					indexData[curIdx++] = sliceIdx * numSides + (sideIdx + 1) % numSides;
+					indexData[curIdx++] = (sliceIdx + 1) * numSides + sideIdx;
+
+					indexData[curIdx++] = sliceIdx * numSides + (sideIdx + 1) % numSides;
+					indexData[curIdx++] = (sliceIdx + 1) * numSides + (sideIdx + 1) % numSides;
+					indexData[curIdx++] = (sliceIdx + 1) * numSides + sideIdx;
+				}
+			}
+
+			// Sphere cap indices
+			UINT32 coneOffset = numSides * numSlices;
+			for (UINT32 sliceIdx = 0; sliceIdx < (numSlices - 1); sliceIdx++)
+			{
+				for (UINT32 sideIdx = 0; sideIdx < numSides; sideIdx++)
+				{
+					indexData[curIdx++] = coneOffset + sliceIdx * numSides + sideIdx;
+					indexData[curIdx++] = coneOffset + sliceIdx * numSides + (sideIdx + 1) % numSides;
+					indexData[curIdx++] = coneOffset + (sliceIdx + 1) * numSides + sideIdx;
+
+					indexData[curIdx++] = coneOffset + sliceIdx * numSides + (sideIdx + 1) % numSides;
+					indexData[curIdx++] = coneOffset + (sliceIdx + 1) * numSides + (sideIdx + 1) % numSides;
+					indexData[curIdx++] = coneOffset + (sliceIdx + 1) * numSides + sideIdx;
+				}
+			}
+
+			mSpotLightStencilMesh = MeshCore::create(meshData);
+		}
 	}
 
 	RendererUtility::~RendererUtility()

+ 28 - 0
MBansheeEditor/MenuItems.cs

@@ -92,6 +92,21 @@ namespace BansheeEditor
             EditorApplication.SetSceneDirty();
         }
 
+        /// <summary>
+        /// Adds a GUI widget component to the currently selected scene object.
+        /// </summary>
+        [MenuItem("Components/GUI widget", 7045)]
+        private static void AddGUIWidget()
+        {
+            SceneObject so = Selection.SceneObject;
+            if (so == null)
+                return;
+
+            UndoRedo.RecordSO(so, false, "Added a GUIWidget component");
+            so.AddComponent<GUIWidget>();
+            EditorApplication.SetSceneDirty();
+        }
+
         /// <summary>
         /// Creates a new empty scene object.
         /// </summary>
@@ -179,6 +194,19 @@ namespace BansheeEditor
             EditorApplication.SetSceneDirty();
         }
 
+        /// <summary>
+        /// Creates a new scene object with a GUI widget component.
+        /// </summary>
+        [MenuItem("Scene Objects/GUI widget", 8045)]
+        private static void AddGUIWidgetSO()
+        {
+            SceneObject so = UndoRedo.CreateSO("GUIWidget", "Created a GUIWidget");
+            so.AddComponent<GUIWidget>();
+
+            Selection.SceneObject = so;
+            EditorApplication.SetSceneDirty();
+        }
+
         /// <summary>
         /// Creates a new scene object with a box primitive.
         /// </summary>

+ 1 - 1
SBansheeEditor/Source/BsScriptBuildManager.cpp

@@ -394,7 +394,7 @@ namespace BansheeEngine
 			gameSettings->mainSceneUUID = platformInfo->mainScene.getUUID();
 			gameSettings->fullscreen = platformInfo->fullscreen;
 			gameSettings->resolutionWidth = platformInfo->windowedWidth;
-			gameSettings->resolutionWidth = platformInfo->windowedHeight;
+			gameSettings->resolutionHeight = platformInfo->windowedHeight;
 
 			switch (platformInfo->type)
 			{