changeset 50:7ff46a00bcd3

Working on GuiRenderContext
author koryspansel
date Fri, 23 Sep 2011 17:58:17 -0700
parents 48705dc6e568
children efd2b1ca5b77
files LightClone/Source/GuiButton.cpp LightClone/Source/GuiButton.h LightClone/Source/GuiCursor.cpp LightClone/Source/GuiCursor.h LightClone/Source/GuiElement.cpp LightClone/Source/GuiElement.h LightClone/Source/GuiImage.cpp LightClone/Source/GuiImage.h LightClone/Source/GuiInterface.cpp LightClone/Source/GuiInterface.h LightClone/Source/GuiLabel.cpp LightClone/Source/GuiLabel.h LightClone/Source/GuiRenderContext.cpp LightClone/Source/RenderContext.cpp
diffstat 14 files changed, 122 insertions(+), 127 deletions(-) [+]
line wrap: on
line diff
--- a/LightClone/Source/GuiButton.cpp	Fri Sep 23 16:54:51 2011 -0700
+++ b/LightClone/Source/GuiButton.cpp	Fri Sep 23 17:58:17 2011 -0700
@@ -65,7 +65,8 @@
 /*
  * Render
  */
-void GuiButton::Render(RenderContext& kContext, Camera& kCamera)
+//void GuiButton::Render(RenderContext& kContext, Camera& kCamera)
+void GuiButton::Render(GuiRenderContext& kContext)
 {
 	if(nFlags & GuiElementFlag_Visible)
 	{
@@ -78,7 +79,7 @@
 
 			const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f);
 
-			kContext.ApplyCameraToEffect(kCamera, pEffect);
+			kContext.GetRenderContext()->ApplyCameraToEffect(*kContext.GetCamera(), pEffect);
 
 			D3DXMATRIX kScale;
 			D3DXMatrixScaling(&kScale, kDimensions.x, kDimensions.y, 1.0f);
@@ -99,7 +100,7 @@
 			pEffect->Begin(&nPasses, 0);
 			pEffect->BeginPass(0);
 
-			kContext.DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace);
+			kContext.GetRenderContext()->DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace);
 
 			pEffect->EndPass();
 			pEffect->End();
@@ -131,7 +132,7 @@
 			}
 		}
 
-		GuiElement::Render(kContext, kCamera);
+		GuiElement::Render(kContext);
 	}
 }
 
--- a/LightClone/Source/GuiButton.h	Fri Sep 23 16:54:51 2011 -0700
+++ b/LightClone/Source/GuiButton.h	Fri Sep 23 17:58:17 2011 -0700
@@ -94,7 +94,8 @@
 	/*
 	 * Render
 	 */
-	virtual void Render(RenderContext& kContext, Camera& kCamera);
+	virtual void Render(GuiRenderContext& kContext);
+	//virtual void Render(RenderContext& kContext, Camera& kCamera);
 
 	/*
 	 * SetTexture
--- a/LightClone/Source/GuiCursor.cpp	Fri Sep 23 16:54:51 2011 -0700
+++ b/LightClone/Source/GuiCursor.cpp	Fri Sep 23 17:58:17 2011 -0700
@@ -54,7 +54,8 @@
 /*
  * Render
  */
-void GuiCursor::Render(RenderContext& kContext, Camera& kCamera)
+//void GuiCursor::Render(RenderContext& kContext, Camera& kCamera)
+void GuiCursor::Render(GuiRenderContext& kContext)
 {
 	if(pTexture)
 	{
@@ -65,7 +66,7 @@
 
 		const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f);
 
-		kContext.ApplyCameraToEffect(kCamera, pEffect);
+		kContext.GetRenderContext()->ApplyCameraToEffect(*kContext.GetCamera(), pEffect);
 
 		pEffect->SetTechnique(pEffect->GetTechnique(0));
 		pEffect->Begin(&nPasses, 0);
@@ -85,11 +86,13 @@
 		pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pTexture);
 		pEffect->CommitChanges();
 
-		kContext.DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace);
+		kContext.GetRenderContext()->DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace);
 
 		pEffect->EndPass();
 		pEffect->End();
 	}
+
+	GuiElement::Render(kContext);
 }
 
 /*
--- a/LightClone/Source/GuiCursor.h	Fri Sep 23 16:54:51 2011 -0700
+++ b/LightClone/Source/GuiCursor.h	Fri Sep 23 17:58:17 2011 -0700
@@ -58,7 +58,8 @@
 	/*
 	 * Render
 	 */
-	virtual void Render(RenderContext& kContext, Camera& kCamera);
+	//virtual void Render(RenderContext& kContext, Camera& kCamera);
+	virtual void Render(GuiRenderContext& kContext);
 
 	/*
 	 * SetTexture
--- a/LightClone/Source/GuiElement.cpp	Fri Sep 23 16:54:51 2011 -0700
+++ b/LightClone/Source/GuiElement.cpp	Fri Sep 23 17:58:17 2011 -0700
@@ -52,13 +52,14 @@
 /*
  * Render
  */
-void GuiElement::Render(RenderContext& kContext, Camera& kCamera)
+//void GuiElement::Render(RenderContext& kContext, Camera& kCamera)
+void GuiElement::Render(GuiRenderContext& kContext)
 {
 	if(nFlags & GuiElementFlag_Visible)
 	{
 		for(uint32 i = 0; i < kChildren.Size(); ++i)
 		{
-			kChildren[i]->Render(kContext, kCamera);
+			kChildren[i]->Render(kContext);
 		}
 	}
 }
--- a/LightClone/Source/GuiElement.h	Fri Sep 23 16:54:51 2011 -0700
+++ b/LightClone/Source/GuiElement.h	Fri Sep 23 17:58:17 2011 -0700
@@ -11,6 +11,7 @@
 #include "Camera.h"
 #include "ArrayList.h"
 #include "GuiEventMap.h"
+#include "GuiRenderContext.h"
 
 /*
  * GuiElementFlag
@@ -110,7 +111,8 @@
 	/*
 	 * Render
 	 */
-	virtual void Render(RenderContext& kContext, Camera& kCamera);
+	//virtual void Render(RenderContext& kContext, Camera& kCamera);
+	virtual void Render(GuiRenderContext& kContext);
 
 	/*
 	 * SetInterface
--- a/LightClone/Source/GuiImage.cpp	Fri Sep 23 16:54:51 2011 -0700
+++ b/LightClone/Source/GuiImage.cpp	Fri Sep 23 17:58:17 2011 -0700
@@ -19,6 +19,7 @@
 {
 	pResourceManager = pManager;
 
+	/*
 	ErrorCode eCode = pResourceManager->CreateEffectFromFile("Data\\Shaders\\TexturedQuad.fx", &pEffect);
 	if(eCode == Error_Success)
 	{
@@ -28,8 +29,9 @@
 			eCode = SetupVertexBuffer();
 		}
 	}
+	*/
 
-	return eCode;
+	return Error_Success;
 }
 
 /*
@@ -37,11 +39,13 @@
  */
 void GuiImage::Terminate()
 {
+	/*
 	if(pVertexBuffer)
 	{
 		pVertexBuffer->Release();
 		pVertexBuffer = NULL;
 	}
+	*/
 }
 
 /*
@@ -54,12 +58,14 @@
 /*
  * Render
  */
-void GuiImage::Render(RenderContext& kContext, Camera& kCamera)
+//void GuiImage::Render(RenderContext& kContext, Camera& kCamera)
+void GuiImage::Render(GuiRenderContext& kContext)
 {
 	if(nFlags & GuiElementFlag_Visible)
 	{
 		if(pTexture)
 		{
+			/*
 			uint32 nPasses = 0;
 
 			const float fOffsetX = -0.5f * ScreenSizeX;
@@ -67,7 +73,7 @@
 
 			const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f);
 
-			kContext.ApplyCameraToEffect(kCamera, pEffect);
+			kContext.GetRenderContext()->ApplyCameraToEffect(*kContext.GetCamera(), pEffect);
 
 			D3DXMATRIX kScale;
 			D3DXMatrixScaling(&kScale, kDimensions.x, kDimensions.y, 1.0f);
@@ -80,21 +86,25 @@
 			D3DXMATRIX kWorldMatrix;
 			D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate);
 
-			pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix);
-			pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector);
-			pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pTexture);
+			//pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix);
+			//pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector);
+			//pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pTexture);
+
+			//pEffect->SetTechnique(pEffect->GetTechnique(0));
+			//pEffect->Begin(&nPasses, 0);
+			//pEffect->BeginPass(0);
 
-			pEffect->SetTechnique(pEffect->GetTechnique(0));
-			pEffect->Begin(&nPasses, 0);
-			pEffect->BeginPass(0);
+			//kContext.GetRenderContext()->DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace);
+			kContext.AddToBatch(pTexture, kLocation, GetDimensions(), kColor);
 
-			kContext.DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace);
+			//pEffect->EndPass();
+			//pEffect->End();
+			*/
 
-			pEffect->EndPass();
-			pEffect->End();
+			kContext.AddToBatch(pTexture, GetPosition(), GetDimensions(), D3DCOLOR_XRGB(255, 255, 255));
 		}
 
-		GuiElement::Render(kContext, kCamera);
+		GuiElement::Render(kContext);
 	}
 }
 
--- a/LightClone/Source/GuiImage.h	Fri Sep 23 16:54:51 2011 -0700
+++ b/LightClone/Source/GuiImage.h	Fri Sep 23 17:58:17 2011 -0700
@@ -60,7 +60,8 @@
 	/*
 	 * Render
 	 */
-	virtual void Render(RenderContext& kContext, Camera& kCamera);
+	//virtual void Render(RenderContext& kContext, Camera& kCamera);
+	virtual void Render(GuiRenderContext& kContext);
 
 	/*
 	 * SetTexture
--- a/LightClone/Source/GuiInterface.cpp	Fri Sep 23 16:54:51 2011 -0700
+++ b/LightClone/Source/GuiInterface.cpp	Fri Sep 23 17:58:17 2011 -0700
@@ -18,20 +18,24 @@
  */
 ErrorCode GuiInterface::Initialize(ResourceManager* pResourceManager, InputManager* pInput)
 {
-	ErrorCode eCode = GuiElement::Initialize(pResourceManager);
+	ErrorCode eCode = kRenderContext.Initialize(pResourceManager);
 	if(eCode == Error_Success)
 	{
-		eCode = pCursor->Initialize(pResourceManager);
+		eCode = GuiElement::Initialize(pResourceManager);
 		if(eCode == Error_Success)
 		{
-			eCode = pCursor->SetTexture("Data\\Textures\\Arrow.tga");
+			eCode = pCursor->Initialize(pResourceManager);
 			if(eCode == Error_Success)
 			{
-				pInputManager = pInput;
-				//ASSERT(pInputManager);
+				eCode = pCursor->SetTexture("Data\\Textures\\Arrow.tga");
+				if(eCode == Error_Success)
+				{
+					pInputManager = pInput;
+					//ASSERT(pInputManager);
 
-				pInputManager->SetBounds(0.0f, 0.0f, (float)ScreenSizeX, (float)ScreenSizeY);
-				pInputManager->SetMouse(0.5f * ScreenSizeX, 0.5f * ScreenSizeY);
+					pInputManager->SetBounds(0.0f, 0.0f, (float)ScreenSizeX, (float)ScreenSizeY);
+					pInputManager->SetMouse(0.5f * ScreenSizeX, 0.5f * ScreenSizeY);
+				}
 			}
 		}
 	}
@@ -161,29 +165,26 @@
  */
 void GuiInterface::Render(RenderContext& kContext, Camera& kCamera)
 {
-	//kRenderContext.Begin(&kContext, &kCamera);
+	kRenderContext.Begin(&kContext, &kCamera);
 
 	if(nFlags & GuiElementFlag_Visible)
 	{
-		//TODO: Inside Render functions call kContext.AddToBatch(pTexture, kPosition, kDimensions, kColor)
-		GuiElement::Render(kContext, kCamera);
+		//GuiElement::Render(kContext, kCamera);
+		GuiElement::Render(kRenderContext);
 
 		if(pCursor)
 		{
 			if(pDragElement)
 			{
-				const D3DXVECTOR2& kPosition = pCursor->GetPosition();
-				const D3DXVECTOR2& kDimensions = pDragElement->GetDimensions();
-
-				pDragElement->SetPosition(kPosition - 0.5f * kDimensions);
-				pDragElement->Render(kContext, kCamera);
+				pDragElement->SetPosition(pCursor->GetPosition() - 0.5f * pDragElement->GetDimensions());
+				pDragElement->Render(kRenderContext);
 			}
 
-			pCursor->Render(kContext, kCamera);
+			pCursor->Render(kRenderContext);
 		}
 	}
 
-	//kRenderContext.End();
+	kRenderContext.End();
 }
 
 /*
--- a/LightClone/Source/GuiInterface.h	Fri Sep 23 16:54:51 2011 -0700
+++ b/LightClone/Source/GuiInterface.h	Fri Sep 23 17:58:17 2011 -0700
@@ -109,6 +109,11 @@
 	 * Initialize
 	 */
 	using GuiElement::Initialize;
+
+	/*
+	 * Render
+	 */
+	using GuiElement::Render;
 };
 
 #endif //__GUIINTERFACE_H__
--- a/LightClone/Source/GuiLabel.cpp	Fri Sep 23 16:54:51 2011 -0700
+++ b/LightClone/Source/GuiLabel.cpp	Fri Sep 23 17:58:17 2011 -0700
@@ -36,7 +36,7 @@
 /*
  * Render
  */
-void GuiLabel::Render(RenderContext& kContext, Camera& kCamera)
+void GuiLabel::Render(GuiRenderContext& kContext)
 {
 	if(nFlags & GuiElementFlag_Visible)
 	{
@@ -66,7 +66,7 @@
 			pFont->DrawTextA(NULL, kLabel, kLabel.Length(), &kRectangle, nFormat, kColor);
 		}
 
-		GuiElement::Render(kContext, kCamera);
+		GuiElement::Render(kContext);
 	}
 }
 
--- a/LightClone/Source/GuiLabel.h	Fri Sep 23 16:54:51 2011 -0700
+++ b/LightClone/Source/GuiLabel.h	Fri Sep 23 17:58:17 2011 -0700
@@ -68,7 +68,8 @@
 	/*
 	 * Render
 	 */
-	virtual void Render(RenderContext& kContext, Camera& kCamera);
+	//virtual void Render(RenderContext& kContext, Camera& kCamera);
+	virtual void Render(GuiRenderContext& kContext);
 
 	/*
 	 * SetFont
--- a/LightClone/Source/GuiRenderContext.cpp	Fri Sep 23 16:54:51 2011 -0700
+++ b/LightClone/Source/GuiRenderContext.cpp	Fri Sep 23 17:58:17 2011 -0700
@@ -24,6 +24,22 @@
 		if(eCode == Error_Success)
 		{
 			//eCode = SetupVertexBuffer();
+			Vertex::Quad* pVertices = NULL;
+
+			HRESULT hResult = pVertexBuffer->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD);
+			if(FAILED(hResult))
+			{
+				return Error_Fail;
+			}
+
+			pVertices[0]	= Vertex::Quad(+0.0f, -1.0f, 1.0f, 0.0f, 1.0f);
+			pVertices[1]	= Vertex::Quad(+0.0f, +0.0f, 1.0f, 0.0f, 0.0f);
+			pVertices[2]	= Vertex::Quad(+1.0f, +0.0f, 1.0f, 1.0f, 0.0f);
+			pVertices[3]	= Vertex::Quad(+0.0f, -1.0f, 1.0f, 0.0f, 1.0f);
+			pVertices[4]	= Vertex::Quad(+1.0f, +0.0f, 1.0f, 1.0f, 0.0f);
+			pVertices[5]	= Vertex::Quad(+1.0f, -1.0f, 1.0f, 1.0f, 1.0f);
+
+			pVertexBuffer->Unlock();
 		}
 	}
 
@@ -54,7 +70,16 @@
 		pContext = pRenderContext;
 		pCamera = pRenderCamera;
 
-		pContext->ApplyCameraToEffect(*pCamera, pEffect);
+		if(pEffect)
+		{
+			uint32 nPasses = 0;			
+
+			pEffect->SetTechnique(pEffect->GetTechnique(0));
+			pEffect->Begin(&nPasses, 0);
+			pEffect->BeginPass(0);
+
+			pContext->ApplyCameraToEffect(*pCamera, pEffect);
+		}
 	}
 }
 
@@ -68,12 +93,6 @@
 
 	//TODO: Submit primitives
 
-	uint32 nPasses = 0;
-
-	pEffect->SetTechnique(pEffect->GetTechnique(0));
-	pEffect->Begin(&nPasses, 0);
-	pEffect->BeginPass(0);
-
 	/*
 	for each batch:
 	{
@@ -87,28 +106,6 @@
 
 	pEffect->EndPass();
 	pEffect->End();
-
-	/*
-	const float fOffsetX = -0.5f * ScreenSizeX;
-	const float fOffsetY = +0.5f * ScreenSizeY;
-
-	const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f);
-
-	kContext.ApplyCameraToEffect(kCamera, pEffect);
-
-	D3DXMATRIX kScale;
-	D3DXMatrixScaling(&kScale, kDimensions.x, kDimensions.y, 1.0f);
-
-	const D3DXVECTOR2& kLocation = GetPosition();
-
-	D3DXMATRIX kTranslate;
-	D3DXMatrixTranslation(&kTranslate, fOffsetX + kLocation.x + 0.5f, fOffsetY - kLocation.y + 0.5f, 0.0f);
-
-	D3DXMATRIX kWorldMatrix;
-	D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate);
-
-	kContext.DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace);
-	*/
 }
 
 /*
@@ -116,6 +113,27 @@
  */
 ErrorCode GuiRenderContext::AddToBatch(IDirect3DTexture9* pTexture, const D3DXVECTOR2& kPosition, const D3DXVECTOR2& kSize, D3DCOLOR kColor)
 {
+	const float fOffsetX = -0.5f * ScreenSizeX;
+	const float fOffsetY = +0.5f * ScreenSizeY;
+
+	const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f);
+
+	D3DXMATRIX kScale;
+	D3DXMatrixScaling(&kScale, kSize.x, kSize.y, 1.0f);
+
+	D3DXMATRIX kTranslate;
+	D3DXMatrixTranslation(&kTranslate, fOffsetX + kPosition.x + 0.5f, fOffsetY - kPosition.y + 0.5f, 0.0f);
+
+	D3DXMATRIX kWorldMatrix;
+	D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate);
+
+	pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix);
+	pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector);
+	pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pTexture);
+
+	pContext->DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace);
+
+	return Error_Success;
 }
 
 /*
--- a/LightClone/Source/RenderContext.cpp	Fri Sep 23 16:54:51 2011 -0700
+++ b/LightClone/Source/RenderContext.cpp	Fri Sep 23 17:58:17 2011 -0700
@@ -133,62 +133,12 @@
 
 		if(kHandleView)
 			pEffect->SetMatrix(kHandleView, &kCamera.GetView());
+
+		pEffect->CommitChanges();
 	}
 }
 
 /*
- * SetupCamera3D
- */
-/*
-void RenderContext::SetupCamera3D(ID3DXEffect* pEffect, const D3DXVECTOR3& kLocation, const D3DXVECTOR3& kTarget, float fViewAngle)
-{
-	D3DVIEWPORT9 kViewport;
-	if(SUCCEEDED(pGraphicsDevice->GetViewport(&kViewport)))
-	{
-		D3DXHANDLE kHandleProj	= pEffect->GetParameterByName(NULL, "kProjection");
-		D3DXHANDLE kHandleView	= pEffect->GetParameterByName(NULL, "kView");
-
-		// setup projection matrix
-		D3DXMatrixPerspectiveFovLH(&kProjection, fViewAngle, (float)kViewport.Width / (float)kViewport.Height, 1.0f, 1024.0f);
-
-		// setup view matrix
-		D3DXMatrixLookAtLH(&kView, &kLocation, &kTarget, &D3DXVECTOR3(0.0f, 1.0f, 0.0f));
-
-		if(kHandleProj && kHandleView)
-		{
-			// apply parameters to shader
-			pEffect->SetMatrix(kHandleProj, &kProjection);
-			pEffect->SetMatrix(kHandleView, &kView);
-		}
-	}
-}
-*/
-
-/*
- * SetupCamera2D
- */
-/*
-void RenderContext::SetupCamera2D(ID3DXEffect* pEffect)
-{
-	D3DVIEWPORT9 kViewport;
-	if(SUCCEEDED(pGraphicsDevice->GetViewport(&kViewport)))
-	{
-		D3DXHANDLE kHandle = pEffect->GetParameterByName(NULL, "kProjection");
-		if(kHandle)
-		{
-			// setup projection matrix
-			D3DXMatrixOrthoLH(&kProjection, (float)kViewport.Width, (float)kViewport.Height, 1.0f, 1024.0f);
-
-			// setup view matrix
-			D3DXMatrixIdentity(&kView);
-
-			pEffect->SetMatrix(kHandle, &kProjection);
-		}
-	}
-}
-*/
-
-/*
  * DrawTriangles
  */
 void RenderContext::DrawTriangles(IDirect3DVertexDeclaration9* pDeclaration, IDirect3DVertexBuffer9* pBuffer, uint32 nSize, uint32 nCount)