Kaynağa Gözat

Text material resolution now gets set dynamically

Marko Pintera 12 yıl önce
ebeveyn
işleme
5bf23618b8

+ 1 - 1
CamelotCore/Include/CmCamera.h

@@ -517,7 +517,7 @@ namespace CamelotEngine {
 			float width = 1.0f, float height = 1.0f,
 			int ZOrder = 0);
 
-		ViewportPtr getViewport() { return mViewport; }
+		ViewportPtr getViewport() const { return mViewport; }
 
 		/************************************************************************/
 		/* 						COMPONENT OVERRIDES                      		*/

+ 8 - 8
CamelotCore/Include/CmViewport.h

@@ -97,42 +97,42 @@ namespace CamelotEngine {
 		/** Gets one of the relative dimensions of the viewport,
             a value between 0.0 and 1.0.
         */
-        float getLeft(void) const;
+        float getNormalizedLeft(void) const;
 
         /** Gets one of the relative dimensions of the viewport, a value
             between 0.0 and 1.0.
         */
-        float getTop(void) const;
+        float getNormalizedTop(void) const;
 
         /** Gets one of the relative dimensions of the viewport, a value
             between 0.0 and 1.0.
         */
 
-        float getWidth(void) const;
+        float getNormalizedWidth(void) const;
         /** Gets one of the relative dimensions of the viewport, a value
             between 0.0 and 1.0.
         */
 
-        float getHeight(void) const;
+        float getNormalizedHeight(void) const;
         /** Gets one of the actual dimensions of the viewport, a value in
             pixels.
         */
 
-        int getActualLeft(void) const;
+        int getLeft(void) const;
         /** Gets one of the actual dimensions of the viewport, a value in
             pixels.
         */
 
-        int getActualTop(void) const;
+        int getTop(void) const;
         /** Gets one of the actual dimensions of the viewport, a value in
             pixels.
         */
-        int getActualWidth(void) const;
+        int getWidth(void) const;
         /** Gets one of the actual dimensions of the viewport, a value in
             pixels.
         */
 
-        int getActualHeight(void) const;
+        int getHeight(void) const;
                
         /** Sets the dimensions (after creation).
             @param

+ 7 - 0
CamelotCore/Source/CmGUIWidget.cpp

@@ -6,6 +6,8 @@
 #include "CmMaterial.h"
 #include "CmPass.h"
 #include "CmMesh.h"
+#include "CmCamera.h"
+#include "CmViewport.h"
 
 namespace CamelotEngine
 {
@@ -167,6 +169,11 @@ namespace CamelotEngine
 		{
 			HMaterial material = mCachedMaterials[meshIdx];
 
+			// TODO - Possible optimization. I currently divide by width/height inside the shader, while it
+			// might be more optimal to just scale the mesh as the resolution changes?
+			material->setFloat("halfViewportWidth", camera->getViewport()->getWidth() * 0.5f);
+			material->setFloat("halfViewportHeight", camera->getViewport()->getHeight() * 0.5f);
+
 			if(material == nullptr || !material.isLoaded())
 				continue;
 

+ 8 - 8
CamelotCore/Source/CmViewport.cpp

@@ -90,42 +90,42 @@ namespace CamelotEngine {
         return mTarget;
     }
     //---------------------------------------------------------------------
-    float Viewport::getLeft(void) const
+    float Viewport::getNormalizedLeft(void) const
     {
         return mRelLeft;
     }
     //---------------------------------------------------------------------
-    float Viewport::getTop(void) const
+    float Viewport::getNormalizedTop(void) const
     {
         return mRelTop;
     }
     //---------------------------------------------------------------------
-    float Viewport::getWidth(void) const
+    float Viewport::getNormalizedWidth(void) const
     {
         return mRelWidth;
     }
     //---------------------------------------------------------------------
-    float Viewport::getHeight(void) const
+    float Viewport::getNormalizedHeight(void) const
     {
         return mRelHeight;
     }
     //---------------------------------------------------------------------
-    int Viewport::getActualLeft(void) const
+    int Viewport::getLeft(void) const
     {
         return mActLeft;
     }
     //---------------------------------------------------------------------
-    int Viewport::getActualTop(void) const
+    int Viewport::getTop(void) const
     {
         return mActTop;
     }
     //---------------------------------------------------------------------
-    int Viewport::getActualWidth(void) const
+    int Viewport::getWidth(void) const
     {
         return mActWidth;
     }
     //---------------------------------------------------------------------
-    int Viewport::getActualHeight(void) const
+    int Viewport::getHeight(void) const
     {
         return mActHeight;
     }

+ 7 - 2
CamelotD3D11RenderSystem/Source/CmD3D11BuiltinMaterialManager.cpp

@@ -28,14 +28,17 @@ namespace CamelotEngine
 	void D3D11BuiltinMaterialManager::initSpriteTextShader()
 	{
 		String vsCode = "										\
+			float halfViewportWidth;							\
+			float halfViewportHeight;							\
+																\
 			void vs_main(										\
 			in float3 inPos : POSITION,							\
 			in float2 uv : TEXCOORD0,							\
 			out float4 oPosition : SV_Position,					\
 			out float2 oUv : TEXCOORD0)							\
 			{													\
-				float tfrmdX = (inPos.x / 640) - 1.0f;			\
-				float tfrmdY = (inPos.y / 360) + 1.0f;			\
+				float tfrmdX = (inPos.x / halfViewportWidth) - 1.0f;			\
+				float tfrmdY = (inPos.y / halfViewportHeight) + 1.0f;			\
 																\
 				oPosition = float4(tfrmdX, tfrmdY, 0, 1);		\
 				oUv = uv;										\
@@ -60,6 +63,8 @@ namespace CamelotEngine
 
 		mSpriteTextShader = Shader::create("TextShader");
 
+		mSpriteTextShader->addParameter("halfViewportWidth", "halfViewportWidth", GPDT_FLOAT1);
+		mSpriteTextShader->addParameter("halfViewportHeight", "halfViewportHeight", GPDT_FLOAT1);
 		mSpriteTextShader->addParameter("mainTexSamp", "mainTexSamp", GPOT_SAMPLER2D);
 		mSpriteTextShader->addParameter("mainTexture", "mainTexture", GPOT_TEXTURE2D);
 

+ 4 - 4
CamelotD3D11RenderSystem/Source/CmD3D11RenderSystem.cpp

@@ -313,10 +313,10 @@ namespace CamelotEngine
 		setRenderTarget(target);
 
 		// set viewport dimensions
-		mViewport.TopLeftX = (FLOAT)vp->getActualLeft();
-		mViewport.TopLeftY = (FLOAT)vp->getActualTop();
-		mViewport.Width = (FLOAT)vp->getActualWidth();
-		mViewport.Height = (FLOAT)vp->getActualHeight();
+		mViewport.TopLeftX = (FLOAT)vp->getLeft();
+		mViewport.TopLeftY = (FLOAT)vp->getTop();
+		mViewport.Width = (FLOAT)vp->getWidth();
+		mViewport.Height = (FLOAT)vp->getHeight();
 
 		if (vp->getTarget()->requiresTextureFlipping())
 		{

+ 4 - 4
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -1132,10 +1132,10 @@ namespace CamelotEngine
 		setCullingMode( mCullingMode );
 
 		// set viewport dimensions
-		d3dvp.X = vp->getActualLeft();
-		d3dvp.Y = vp->getActualTop();
-		d3dvp.Width = vp->getActualWidth();
-		d3dvp.Height = vp->getActualHeight();
+		d3dvp.X = vp->getLeft();
+		d3dvp.Y = vp->getTop();
+		d3dvp.Width = vp->getWidth();
+		d3dvp.Height = vp->getHeight();
 		if (target->requiresTextureFlipping())
 		{
 			// Convert "top-left" to "bottom-left"

+ 4 - 4
CamelotGLRenderer/Source/CmGLRenderSystem.cpp

@@ -535,10 +535,10 @@ namespace CamelotEngine
 		setRenderTarget(target);
 
 		// Calculate the "lower-left" corner of the viewport
-		mViewportWidth = vp->getActualWidth();
-		mViewportHeight = vp->getActualHeight();
-		mViewportLeft = vp->getActualLeft();
-		mViewportTop = vp->getActualTop();
+		mViewportWidth = vp->getWidth();
+		mViewportHeight = vp->getHeight();
+		mViewportLeft = vp->getLeft();
+		mViewportTop = vp->getTop();
 
 		if (!target->requiresTextureFlipping())
 		{

+ 7 - 22
TODO.txt

@@ -25,28 +25,13 @@ Add TextUtil class
  - Ability to calculate a size of a line (will need this if I want to add "..." to text that doesn't fit)
  - Maybe even move line and word classes to it
 
- When rendering GUIWidget its individual elements need to be sorted based on Z depth so the transparency works as expected
-
-Immediate TODO:
-Implement image shader for D3D11BuiltinMaterialManager
-Improve text shader so it doesn't have resolution values hardcoded in
-Implement D3D9 and GL BuiltInMaterialManager
-
-Test:
-Need sorted rendering as fonts render before scene and blending doesn't work as it should
- - Implemented 2D renderer and ensure it runs after everything else
- - Or just add render queue ID to meshes?
-Start work on GUILabel element?
- - Work on other sprites after that.
-Better font (Terminal?)
-Test word wrap, implement clipping
-Add HLSL9 and GLSL text materials & shaders
-Add resolution to GUI shader
-TextSprite needs to return multiple buffers in case characters are from different pages
-
-Mesh usability overhaul:
- A way to clear a mesh  (Mesh.Clear)
- A way to update mesh buffers without recreating vertex/index buffers (Setting data currently does exactly that)
+Immediate sprite related stuff:
+ - Implement image shader for D3D11BuiltinMaterialManager
+ - Improve text shader so it doesn't have resolution values hardcoded in
+ - Implement D3D9 and GL BuiltInMaterialManager
+ - When rendering GUIWidget its individual elements need to be sorted based on Z depth so the transparency works as expected
+ - A way to update mesh buffers without recreating vertex/index buffers (Setting data currently does exactly that)
+ - Transformable GUI elements and their bounds
 
 -----------------------IMMEDIATE TODO---------------------------------------------------------------