Browse Source

Added BuiltiMaterialManagers and more work on GUI

Marko Pintera 12 năm trước cách đây
mục cha
commit
ff28162000
37 tập tin đã thay đổi với 548 bổ sung28 xóa
  1. 3 0
      CamelotCore/CamelotCore.vcxproj
  2. 9 0
      CamelotCore/CamelotCore.vcxproj.filters
  3. 19 0
      CamelotCore/Include/CmBuiltinMaterialManager.h
  4. 5 5
      CamelotCore/Include/CmCoreObject.h
  5. 54 0
      CamelotCore/Include/CmGUIMaterialManager.h
  6. 1 1
      CamelotCore/Include/CmGpuParams.h
  7. 12 11
      CamelotCore/Include/CmMaterial.h
  8. 10 0
      CamelotCore/Include/CmMaterialManager.cpp
  9. 1 0
      CamelotCore/Include/CmMaterialManager.h
  10. 9 0
      CamelotCore/Include/CmRendererManager.h
  11. 2 2
      CamelotCore/Include/CmResourceHandle.h
  12. 8 0
      CamelotCore/Source/CmApplication.cpp
  13. 5 5
      CamelotCore/Source/CmCoreObject.cpp
  14. 93 0
      CamelotCore/Source/CmGUIMaterialManager.cpp
  15. 1 1
      CamelotCore/Source/CmGpuParams.cpp
  16. 8 1
      CamelotCore/Source/CmMaterial.cpp
  17. 6 0
      CamelotCore/Source/CmRendererManager.cpp
  18. 7 1
      CamelotCore/Source/CmSprite.cpp
  19. 2 1
      CamelotCore/Source/CmTechnique.cpp
  20. 4 0
      CamelotCore/Source/CmTextSprite.cpp
  21. 2 0
      CamelotD3D11RenderSystem/CamelotD3D11RenderSystem.vcxproj
  22. 6 0
      CamelotD3D11RenderSystem/CamelotD3D11RenderSystem.vcxproj.filters
  23. 26 0
      CamelotD3D11RenderSystem/Include/CmD3D11BuiltinMaterialManager.h
  24. 85 0
      CamelotD3D11RenderSystem/Source/CmD3D11BuiltinMaterialManager.cpp
  25. 4 0
      CamelotD3D11RenderSystem/Source/CmD3D11RenderSystem.cpp
  26. 2 0
      CamelotD3D9Renderer/CamelotD3D9Renderer.vcxproj
  27. 6 0
      CamelotD3D9Renderer/CamelotD3D9Renderer.vcxproj.filters
  28. 26 0
      CamelotD3D9Renderer/Include/CmD3D9BuiltinMaterialManager.h
  29. 36 0
      CamelotD3D9Renderer/Source/CmD3D9BuiltinMaterialManager.cpp
  30. 4 0
      CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp
  31. 2 0
      CamelotGLRenderer/CamelotGLRenderer.vcxproj
  32. 6 0
      CamelotGLRenderer/CamelotGLRenderer.vcxproj.filters
  33. 26 0
      CamelotGLRenderer/Include/CmGLBuiltinMaterialManager.h
  34. 36 0
      CamelotGLRenderer/Source/CmGLBuiltinMaterialManager.cpp
  35. 4 0
      CamelotGLRenderer/Source/CmGLRenderSystem.cpp
  36. 7 0
      CamelotUtility/Include/CmModule.h
  37. 11 0
      TODO.txt

+ 3 - 0
CamelotCore/CamelotCore.vcxproj

@@ -178,6 +178,7 @@
   <ItemGroup>
   <ItemGroup>
     <ClInclude Include="Include\CmApplication.h" />
     <ClInclude Include="Include\CmApplication.h" />
     <ClInclude Include="Include\CmBlendStateRTTI.h" />
     <ClInclude Include="Include\CmBlendStateRTTI.h" />
+    <ClInclude Include="Include\CmBuiltinMaterialManager.h" />
     <ClInclude Include="Include\CmCamera.h" />
     <ClInclude Include="Include\CmCamera.h" />
     <ClInclude Include="Include\CmCameraRTTI.h" />
     <ClInclude Include="Include\CmCameraRTTI.h" />
     <ClInclude Include="Include\CmCgProgram.h" />
     <ClInclude Include="Include\CmCgProgram.h" />
@@ -215,6 +216,7 @@
     <ClInclude Include="Include\CmGUIElement.h" />
     <ClInclude Include="Include\CmGUIElement.h" />
     <ClInclude Include="Include\CmGUILabel.h" />
     <ClInclude Include="Include\CmGUILabel.h" />
     <ClInclude Include="Include\CmGUIManager.h" />
     <ClInclude Include="Include\CmGUIManager.h" />
+    <ClInclude Include="Include\CmGUIMaterialManager.h" />
     <ClInclude Include="Include\CmGUIWidget.h" />
     <ClInclude Include="Include\CmGUIWidget.h" />
     <ClInclude Include="Include\CmHardwareBuffer.h" />
     <ClInclude Include="Include\CmHardwareBuffer.h" />
     <ClInclude Include="Include\CmHardwareBufferManager.h" />
     <ClInclude Include="Include\CmHardwareBufferManager.h" />
@@ -325,6 +327,7 @@
     <ClCompile Include="Source\CmGUIElement.cpp" />
     <ClCompile Include="Source\CmGUIElement.cpp" />
     <ClCompile Include="Source\CmGUILabel.cpp" />
     <ClCompile Include="Source\CmGUILabel.cpp" />
     <ClCompile Include="Source\CmGUIManager.cpp" />
     <ClCompile Include="Source\CmGUIManager.cpp" />
+    <ClCompile Include="Source\CmGUIMaterialManager.cpp" />
     <ClCompile Include="Source\CmGUIWidget.cpp" />
     <ClCompile Include="Source\CmGUIWidget.cpp" />
     <ClCompile Include="Source\CmHardwareBufferManager.cpp" />
     <ClCompile Include="Source\CmHardwareBufferManager.cpp" />
     <ClCompile Include="Source\CmImportOptions.cpp" />
     <ClCompile Include="Source\CmImportOptions.cpp" />

+ 9 - 0
CamelotCore/CamelotCore.vcxproj.filters

@@ -456,6 +456,12 @@
     <ClInclude Include="Include\CmSpriteTexture.h">
     <ClInclude Include="Include\CmSpriteTexture.h">
       <Filter>Header Files\2D</Filter>
       <Filter>Header Files\2D</Filter>
     </ClInclude>
     </ClInclude>
+    <ClInclude Include="Include\CmGUIMaterialManager.h">
+      <Filter>Header Files\GUI</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\CmBuiltinMaterialManager.h">
+      <Filter>Source Files\Material</Filter>
+    </ClInclude>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\CamelotRenderer.cpp">
     <ClCompile Include="Source\CamelotRenderer.cpp">
@@ -704,5 +710,8 @@
     <ClCompile Include="Source\CmGUIManager.cpp">
     <ClCompile Include="Source\CmGUIManager.cpp">
       <Filter>Source Files\GUI</Filter>
       <Filter>Source Files\GUI</Filter>
     </ClCompile>
     </ClCompile>
+    <ClCompile Include="Source\CmGUIMaterialManager.cpp">
+      <Filter>Source Files\GUI</Filter>
+    </ClCompile>
   </ItemGroup>
   </ItemGroup>
 </Project>
 </Project>

+ 19 - 0
CamelotCore/Include/CmBuiltinMaterialManager.h

@@ -0,0 +1,19 @@
+#pragma once
+
+#include "CmPrerequisites.h"
+#include "CmModule.h"
+
+namespace CamelotEngine
+{
+	/**
+	 * @brief	Provides access to various materials that are required for core engine systems. 
+	 * 			Each render system implementation needs to provide its own implementation of this
+	 * 			module.
+	 */
+	class CM_EXPORT BuiltinMaterialManager : public Module<BuiltinMaterialManager>
+	{
+	public:
+		virtual MaterialHandle createSpriteTextMaterial() const = 0;
+		virtual MaterialHandle createSpriteImageMaterial() const = 0;
+	};
+}

+ 5 - 5
CamelotCore/Include/CmCoreObject.h

@@ -65,6 +65,11 @@ o		 *
 		 */
 		 */
 		void setThisPtr(std::shared_ptr<CoreObject> ptrThis);
 		void setThisPtr(std::shared_ptr<CoreObject> ptrThis);
 
 
+		/**
+		 * @brief	Returns an unique identifier for this object.
+		 */
+		UINT64 getInternalID() const { return mInternalID; }
+
 		/**
 		/**
 		 * @brief	Schedules the object to be destroyed, and then deleted.
 		 * @brief	Schedules the object to be destroyed, and then deleted.
 		 *
 		 *
@@ -114,11 +119,6 @@ o		 *
 		 */
 		 */
 		static AsyncOp queueReturnGpuCommand(std::shared_ptr<CoreObject>& obj, boost::function<void(AsyncOp&)> func);
 		static AsyncOp queueReturnGpuCommand(std::shared_ptr<CoreObject>& obj, boost::function<void(AsyncOp&)> func);
 
 
-		/**
-		 * @brief	Returns an unique identifier for this object.
-		 */
-		UINT64 getInternalID() const { return mInternalID; }
-
 		bool isScheduledToBeInitialized() const { return (mFlags & CGO_SCHEDULED_FOR_INIT) != 0; }
 		bool isScheduledToBeInitialized() const { return (mFlags & CGO_SCHEDULED_FOR_INIT) != 0; }
 		bool isScheduledToBeDeleted() const { return (mFlags & CGO_SCHEDULED_FOR_DELETE) != 0; }
 		bool isScheduledToBeDeleted() const { return (mFlags & CGO_SCHEDULED_FOR_DELETE) != 0; }
 		bool requiresInitOnRenderThread() const { return (mFlags & CGO_INIT_ON_RENDER_THREAD) != 0; }
 		bool requiresInitOnRenderThread() const { return (mFlags & CGO_INIT_ON_RENDER_THREAD) != 0; }

+ 54 - 0
CamelotCore/Include/CmGUIMaterialManager.h

@@ -0,0 +1,54 @@
+#pragma once
+
+#include "CmPrerequisites.h"
+#include "CmModule.h"
+
+namespace CamelotEngine
+{
+	/**
+	 * @brief	Manages the materials used by the GUI system. Ensures that the GUI system doesn't
+	 * 			create an unnecessarily large amount of equivalent materials.
+	 */
+	class CM_EXPORT GUIMaterialManager : public Module<GUIMaterialManager>
+	{
+	public:
+		/**
+		 * @brief	Creates a new material, or returns a reference to an existing one based on
+		 * 			the provided primary texture.
+		 * 			
+		 *			Returned material can be used for text rendering.
+		 *			
+		 *			Make sure to release all materials with a call to "releaseMaterial()".
+		 */
+		const MaterialHandle& requestTextMaterial(const TextureHandle& texture) const;
+
+		/**
+		 * @brief	Creates a new material, or returns a reference to an existing one based on
+		 * 			the provided primary texture.
+		 * 			
+		 *			Returned material can be used for normal image rendering.
+		 *			
+		 *			Make sure to release all materials with a call to "releaseMaterial()".
+		 */
+		const MaterialHandle& requestImageMaterial(const TextureHandle& texture) const;
+
+		/**
+		 * @brief	Releases the held reference to the material. This allows us to fully unload a material
+		 * 			and their textures when they are no longer being used.
+		 */
+		void releaseMaterial(const MaterialHandle& material) const;
+	private:
+		struct GUIMaterial
+		{
+			GUIMaterial()
+				:refCount(0)
+			{ }
+
+			MaterialHandle handle;
+			UINT32 refCount;
+		};
+
+		mutable vector<GUIMaterial>::type mTextMaterials;
+		mutable vector<GUIMaterial>::type mImageMaterials;
+	};
+}

+ 1 - 1
CamelotCore/Include/CmGpuParams.h

@@ -44,7 +44,7 @@ namespace CamelotEngine
 		 */
 		 */
 		void setParam(const String& name, const void* value, UINT32 sizeBytes, UINT32 arrayIndex = 0);
 		void setParam(const String& name, const void* value, UINT32 sizeBytes, UINT32 arrayIndex = 0);
 
 
-		void setTexture(const String& name, TextureHandle& val);
+		void setTexture(const String& name, const TextureHandle& val);
 		TextureHandle getTexture(UINT32 slot);
 		TextureHandle getTexture(UINT32 slot);
 
 
 		void setSamplerState(const String& name, SamplerStateHandle& val);
 		void setSamplerState(const String& name, SamplerStateHandle& val);

+ 12 - 11
CamelotCore/Include/CmMaterial.h

@@ -67,7 +67,7 @@ namespace CamelotEngine
 
 
 		ShaderPtr getShader() const { return mShader; }
 		ShaderPtr getShader() const { return mShader; }
 
 
-		void setTexture(const String& name, TextureHandle& value);
+		void setTexture(const String& name, const TextureHandle& value);
 		void setSamplerState(const String& name, SamplerStateHandle& samplerState);
 		void setSamplerState(const String& name, SamplerStateHandle& samplerState);
 		void setFloat(const String& name, float value, UINT32 arrayIdx = 0);
 		void setFloat(const String& name, float value, UINT32 arrayIdx = 0);
 		void setColor(const String& name, const Color& value, UINT32 arrayIdx = 0);
 		void setColor(const String& name, const Color& value, UINT32 arrayIdx = 0);
@@ -80,6 +80,16 @@ namespace CamelotEngine
 
 
 		void setParamBlock(const String& name, GpuParamBlockPtr paramBlock);
 		void setParamBlock(const String& name, GpuParamBlockPtr paramBlock);
 
 
+		TextureHandle getTexture(const String& name) const;
+		SamplerStateHandle getSamplerState(const String& name) const;
+		float getFloat(const String& name, UINT32 arrayIdx = 0) const;
+		Vector2 getVec2(const String& name, UINT32 arrayIdx = 0) const;
+		Vector3 getVec3(const String& name, UINT32 arrayIdx = 0) const;
+		Vector4 getVec4(const String& name, UINT32 arrayIdx = 0) const;
+		Matrix3 getMat3(const String& name, UINT32 arrayIdx = 0) const;
+		Matrix4 getMat4(const String& name, UINT32 arrayIdx = 0) const;
+		const StructData& getStructData(const String& name, UINT32 arrayIdx = 0) const;
+
 		UINT32 getNumPasses() const;
 		UINT32 getNumPasses() const;
 
 
 		PassPtr getPass(UINT32 passIdx) const;
 		PassPtr getPass(UINT32 passIdx) const;
@@ -87,6 +97,7 @@ namespace CamelotEngine
 		PassParametersPtr getPassParameters(UINT32 passIdx) const;
 		PassParametersPtr getPassParameters(UINT32 passIdx) const;
 
 
 		static MaterialHandle create();
 		static MaterialHandle create();
+		static MaterialHandle create(ShaderPtr shader);
 	private:
 	private:
 		friend class MaterialManager;
 		friend class MaterialManager;
 
 
@@ -135,16 +146,6 @@ namespace CamelotEngine
 
 
 		const map<String, String>::type& getValidParamNames() const { return mValidParams; }
 		const map<String, String>::type& getValidParamNames() const { return mValidParams; }
 
 
-		TextureHandle getTexture(const String& name) const;
-		SamplerStateHandle getSamplerState(const String& name) const;
-		float getFloat(const String& name, UINT32 arrayIdx = 0) const;
-		Vector2 getVec2(const String& name, UINT32 arrayIdx = 0) const;
-		Vector3 getVec3(const String& name, UINT32 arrayIdx = 0) const;
-		Vector4 getVec4(const String& name, UINT32 arrayIdx = 0) const;
-		Matrix3 getMat3(const String& name, UINT32 arrayIdx = 0) const;
-		Matrix4 getMat4(const String& name, UINT32 arrayIdx = 0) const;
-		const StructData& getStructData(const String& name, UINT32 arrayIdx = 0) const;
-
 		void initBestTechnique();
 		void initBestTechnique();
 
 
 		map<String, const GpuParamDataDesc*>::type determineValidDataParameters(const vector<const GpuParamDesc*>::type& paramDescs) const;
 		map<String, const GpuParamDataDesc*>::type determineValidDataParameters(const vector<const GpuParamDesc*>::type& paramDescs) const;

+ 10 - 0
CamelotCore/Include/CmMaterialManager.cpp

@@ -11,4 +11,14 @@ namespace CamelotEngine
 
 
 		return newMat;
 		return newMat;
 	}
 	}
+
+	MaterialPtr MaterialManager::create(ShaderPtr shader) const
+	{
+		MaterialPtr newMat(new Material(), &CoreObject::_deleteDelayed);
+		newMat->setThisPtr(newMat);
+		newMat->initialize();
+		newMat->setShader(shader);
+
+		return newMat;
+	}
 }
 }

+ 1 - 0
CamelotCore/Include/CmMaterialManager.h

@@ -9,5 +9,6 @@ namespace CamelotEngine
 	{
 	{
 	public:
 	public:
 		MaterialPtr create() const;
 		MaterialPtr create() const;
+		MaterialPtr create(ShaderPtr shader) const;
 	};
 	};
 }
 }

+ 9 - 0
CamelotCore/Include/CmRendererManager.h

@@ -12,6 +12,15 @@ namespace CamelotEngine
 		void setActive(const String& name);
 		void setActive(const String& name);
 		RendererPtr getActive() { return mActiveRenderer; }
 		RendererPtr getActive() { return mActiveRenderer; }
 
 
+		/**
+		 * @brief	Core renderer represents a set of shared features within all renderers.
+		 * 			Techniques using this renderer name will report as if they are supported regardless
+		 * 			of the active renderer.
+		 *
+		 * @return	The core renderer name.
+		 */
+		static const String& getCoreRendererName();
+
 		void registerFactory(RendererFactoryPtr factory);
 		void registerFactory(RendererFactoryPtr factory);
 	private:
 	private:
 		std::vector<RendererFactoryPtr> mAvailableFactories;
 		std::vector<RendererFactoryPtr> mAvailableFactories;

+ 2 - 2
CamelotCore/Include/CmResourceHandle.h

@@ -111,12 +111,12 @@ namespace CamelotEngine
 		{ 
 		{ 
 			throwIfNotLoaded();
 			throwIfNotLoaded();
 
 
-			return static_cast<T*>(mData->mPtr.get()); 
+			return reinterpret_cast<T*>(mData->mPtr.get()); 
 		}
 		}
 		T* operator->() const { return get(); }
 		T* operator->() const { return get(); }
 		T& operator*() const { return *get(); }
 		T& operator*() const { return *get(); }
 
 
-		std::shared_ptr<T> getInternalPtr() 
+		std::shared_ptr<T> getInternalPtr() const
 		{ 
 		{ 
 			throwIfNotLoaded();
 			throwIfNotLoaded();
 
 

+ 8 - 0
CamelotCore/Source/CmApplication.cpp

@@ -27,6 +27,8 @@
 #include "CmFontManager.h"
 #include "CmFontManager.h"
 #include "CmRenderer.h"
 #include "CmRenderer.h"
 #include "CmDeferredRenderContext.h"
 #include "CmDeferredRenderContext.h"
+#include "CmGUIMaterialManager.h"
+#include "CmGUIManager.h"
 
 
 #include "CmMaterial.h"
 #include "CmMaterial.h"
 #include "CmShader.h"
 #include "CmShader.h"
@@ -85,6 +87,9 @@ namespace CamelotEngine
 		loadPlugin("CamelotFBXImporter"); // TODO - Load this automatically somehow
 		loadPlugin("CamelotFBXImporter"); // TODO - Load this automatically somehow
 		loadPlugin("CamelotFontImporter"); // TODO - Load this automatically somehow
 		loadPlugin("CamelotFontImporter"); // TODO - Load this automatically somehow
 
 
+		GUIMaterialManager::startUp(new GUIMaterialManager());
+		GUIManager::startUp(new GUIManager());
+
 		loadPlugin("CamelotOISInput"); // TODO - Load this automatically somehow
 		loadPlugin("CamelotOISInput"); // TODO - Load this automatically somehow
 	}
 	}
 
 
@@ -149,6 +154,9 @@ namespace CamelotEngine
 	{
 	{
 		mPrimaryRenderWindow = nullptr;
 		mPrimaryRenderWindow = nullptr;
 
 
+		GUIManager::shutDown();
+		GUIMaterialManager::shutDown();
+
 		Importer::shutDown();
 		Importer::shutDown();
 		FontManager::shutDown();
 		FontManager::shutDown();
 		MaterialManager::shutDown();
 		MaterialManager::shutDown();

+ 5 - 5
CamelotCore/Source/CmCoreObject.cpp

@@ -99,15 +99,15 @@ namespace CamelotEngine
 
 
 	void CoreObject::waitUntilInitialized()
 	void CoreObject::waitUntilInitialized()
 	{
 	{
-#if CM_DEBUG_MODE
-		if(CM_THREAD_CURRENT_ID == RenderSystem::instancePtr()->getRenderThreadId())
-			CM_EXCEPT(InternalErrorException, "You cannot call this method on the render thread. It will cause a deadlock!");
-#endif
-
 		if(!isInitialized())
 		if(!isInitialized())
 		{
 		{
 			if(requiresInitOnRenderThread())
 			if(requiresInitOnRenderThread())
 			{
 			{
+#if CM_DEBUG_MODE
+				if(CM_THREAD_CURRENT_ID == RenderSystem::instancePtr()->getRenderThreadId())
+					CM_EXCEPT(InternalErrorException, "You cannot call this method on the render thread. It will cause a deadlock!");
+#endif
+
 				CM_LOCK_MUTEX_NAMED(mCoreGpuObjectLoadedMutex, lock);
 				CM_LOCK_MUTEX_NAMED(mCoreGpuObjectLoadedMutex, lock);
 				while(!isInitialized())
 				while(!isInitialized())
 				{
 				{

+ 93 - 0
CamelotCore/Source/CmGUIMaterialManager.cpp

@@ -0,0 +1,93 @@
+#include "CmGUIMaterialManager.h"
+#include "CmMaterial.h"
+#include "CmDebug.h"
+#include "CmBuiltinMaterialManager.h"
+
+namespace CamelotEngine
+{
+	const MaterialHandle& GUIMaterialManager::requestTextMaterial(const TextureHandle& texture) const
+	{
+		for(auto& matHandle : mTextMaterials)
+		{
+			const MaterialHandle& material = matHandle.handle;
+			if(material->getTexture("mainTexture") == texture)
+			{
+				matHandle.refCount++;
+				return material;
+			}
+		}
+
+		mTextMaterials.push_back(GUIMaterial());
+
+		GUIMaterial& material = mTextMaterials[mTextMaterials.size() - 1];
+		material.handle = BuiltinMaterialManager::instance().createSpriteTextMaterial();
+		material.handle->setTexture("mainTexture", texture);
+		material.refCount = 1;		
+
+		return material.handle;
+	}
+
+	const MaterialHandle& GUIMaterialManager::requestImageMaterial(const TextureHandle& texture) const
+	{
+		for(auto& matHandle : mImageMaterials)
+		{
+			const MaterialHandle& material = matHandle.handle;
+			if(material->getTexture("mainTexture") == texture)
+			{
+				matHandle.refCount++;
+				return material;
+			}
+		}
+
+		mImageMaterials.push_back(GUIMaterial());
+
+		GUIMaterial& material = mImageMaterials[mImageMaterials.size() - 1];
+		material.handle = BuiltinMaterialManager::instance().createSpriteImageMaterial();
+		material.handle->setTexture("mainTexture", texture);
+		material.refCount = 1;		
+
+		return material.handle;
+	}
+
+	void GUIMaterialManager::releaseMaterial(const MaterialHandle& material) const
+	{
+		bool released = false;
+
+		UINT32 i = 0;
+		for(auto& matHandle : mTextMaterials)
+		{
+			if(matHandle.handle == material)
+			{
+				if(--matHandle.refCount == 0)
+				{
+					mTextMaterials.erase(mTextMaterials.begin() + i);
+					released = true;
+					break;
+				}
+			}
+
+			i++;
+		}
+
+		i = 0;
+		for(auto& matHandle : mImageMaterials)
+		{
+			if(matHandle.handle == material)
+			{
+				if(--matHandle.refCount == 0)
+				{
+					mImageMaterials.erase(mImageMaterials.begin() + i);
+					released = true;
+					break;
+				}
+			}
+
+			i++;
+		}
+
+		if(!released)
+		{
+			LOGWRN("Trying to release a material that doesn't exist in the GUI Manager. Material ID: " + toString(material->getInternalID()));
+		}
+	}
+}

+ 1 - 1
CamelotCore/Source/CmGpuParams.cpp

@@ -229,7 +229,7 @@ namespace CamelotEngine
 		}
 		}
 	}
 	}
 
 
-	void GpuParams::setTexture(const String& name, TextureHandle& val)
+	void GpuParams::setTexture(const String& name, const TextureHandle& val)
 	{
 	{
 		auto paramIter = mParamDesc.textures.find(name);
 		auto paramIter = mParamDesc.textures.find(name);
 		if(paramIter == mParamDesc.textures.end())
 		if(paramIter == mParamDesc.textures.end())

+ 8 - 1
CamelotCore/Source/CmMaterial.cpp

@@ -510,7 +510,7 @@ namespace CamelotEngine
 		}
 		}
 	}
 	}
 
 
-	void Material::setTexture(const String& name, TextureHandle& value)
+	void Material::setTexture(const String& name, const TextureHandle& value)
 	{
 	{
 		throwIfNotInitialized();
 		throwIfNotInitialized();
 
 
@@ -887,6 +887,13 @@ namespace CamelotEngine
 		return static_resource_cast<Material>(Resource::_createResourceHandle(materialPtr));
 		return static_resource_cast<Material>(Resource::_createResourceHandle(materialPtr));
 	}
 	}
 
 
+	MaterialHandle Material::create(ShaderPtr shader)
+	{
+		MaterialPtr materialPtr = MaterialManager::instance().create(shader);
+
+		return static_resource_cast<Material>(Resource::_createResourceHandle(materialPtr));
+	}
+
 	RTTITypeBase* Material::getRTTIStatic()
 	RTTITypeBase* Material::getRTTIStatic()
 	{
 	{
 		return MaterialRTTI::instance();
 		return MaterialRTTI::instance();

+ 6 - 0
CamelotCore/Source/CmRendererManager.cpp

@@ -25,6 +25,12 @@ namespace CamelotEngine
 		}
 		}
 	}
 	}
 
 
+	const String& RendererManager::getCoreRendererName()
+	{
+		static String name = "CoreRenderer";
+		return name;
+	}
+
 	void RendererManager::registerFactory(RendererFactoryPtr factory)
 	void RendererManager::registerFactory(RendererFactoryPtr factory)
 	{
 	{
 		assert(factory != nullptr);
 		assert(factory != nullptr);

+ 7 - 1
CamelotCore/Source/CmSprite.cpp

@@ -1,5 +1,6 @@
 #include "CmTextSprite.h"
 #include "CmTextSprite.h"
 #include "CmVector2.h"
 #include "CmVector2.h"
+#include "CmGUIMaterialManager.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
@@ -11,7 +12,7 @@ namespace CamelotEngine
 
 
 	Sprite::~Sprite()
 	Sprite::~Sprite()
 	{
 	{
-
+		clearMesh();
 	}
 	}
 
 
 	UINT32 Sprite::getNumRenderElements() const
 	UINT32 Sprite::getNumRenderElements() const
@@ -109,6 +110,11 @@ namespace CamelotEngine
 
 
 			if(renderElem.indexes != nullptr)
 			if(renderElem.indexes != nullptr)
 				delete[] renderElem.indexes;
 				delete[] renderElem.indexes;
+
+			if(renderElem.material != nullptr)
+			{
+				GUIMaterialManager::instance().releaseMaterial(renderElem.material);
+			}
 		}
 		}
 
 
 		mCachedRenderElements.clear();
 		mCachedRenderElements.clear();

+ 2 - 1
CamelotCore/Source/CmTechnique.cpp

@@ -49,7 +49,8 @@ namespace CamelotEngine
 	bool Technique::isSupported() const
 	bool Technique::isSupported() const
 	{
 	{
 		if(RenderSystem::instancePtr()->getName() == mRenderSystem &&
 		if(RenderSystem::instancePtr()->getName() == mRenderSystem &&
-			RendererManager::instance().getActive()->getName() == mRenderer)
+			(RendererManager::instance().getActive()->getName() == mRenderer ||
+			 RendererManager::getCoreRendererName() == mRenderer))
 		{
 		{
 			return true;
 			return true;
 		}
 		}

+ 4 - 0
CamelotCore/Source/CmTextSprite.cpp

@@ -3,6 +3,7 @@
 #include "CmFontDesc.h"
 #include "CmFontDesc.h"
 #include "CmFont.h"
 #include "CmFont.h"
 #include "CmVector2.h"
 #include "CmVector2.h"
+#include "CmGUIMaterialManager.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
@@ -368,11 +369,14 @@ namespace CamelotEngine
 		}
 		}
 
 
 		// Actually generate a mesh
 		// Actually generate a mesh
+		UINT32 texPage = 0;
 		for(auto& renderElem : mCachedRenderElements)
 		for(auto& renderElem : mCachedRenderElements)
 		{
 		{
 			renderElem.vertices = new Vector2[renderElem.numQuads * 4];
 			renderElem.vertices = new Vector2[renderElem.numQuads * 4];
 			renderElem.uvs = new Vector2[renderElem.numQuads * 4];
 			renderElem.uvs = new Vector2[renderElem.numQuads * 4];
 			renderElem.indexes = new UINT32[renderElem.numQuads * 6];
 			renderElem.indexes = new UINT32[renderElem.numQuads * 6];
+			renderElem.material = GUIMaterialManager::instance().requestTextMaterial(fontData->texturePages[texPage]);
+			texPage++;
 		}
 		}
 
 
 		vector<UINT32>::type faceOffsets(mCachedRenderElements.size(), 0);
 		vector<UINT32>::type faceOffsets(mCachedRenderElements.size(), 0);

+ 2 - 0
CamelotD3D11RenderSystem/CamelotD3D11RenderSystem.vcxproj

@@ -151,6 +151,7 @@
   </ItemDefinitionGroup>
   </ItemDefinitionGroup>
   <ItemGroup>
   <ItemGroup>
     <ClInclude Include="Include\CmD3D11BlendState.h" />
     <ClInclude Include="Include\CmD3D11BlendState.h" />
+    <ClInclude Include="Include\CmD3D11BuiltinMaterialManager.h" />
     <ClInclude Include="Include\CmD3D11DepthStencilState.h" />
     <ClInclude Include="Include\CmD3D11DepthStencilState.h" />
     <ClInclude Include="Include\CmD3D11GpuBuffer.h" />
     <ClInclude Include="Include\CmD3D11GpuBuffer.h" />
     <ClInclude Include="Include\CmD3D11GpuBufferView.h" />
     <ClInclude Include="Include\CmD3D11GpuBufferView.h" />
@@ -188,6 +189,7 @@
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\CmD3D11BlendState.cpp" />
     <ClCompile Include="Source\CmD3D11BlendState.cpp" />
+    <ClCompile Include="Source\CmD3D11BuiltinMaterialManager.cpp" />
     <ClCompile Include="Source\CmD3D11DepthStencilState.cpp" />
     <ClCompile Include="Source\CmD3D11DepthStencilState.cpp" />
     <ClCompile Include="Source\CmD3D11Device.cpp" />
     <ClCompile Include="Source\CmD3D11Device.cpp" />
     <ClCompile Include="Source\CmD3D11Driver.cpp" />
     <ClCompile Include="Source\CmD3D11Driver.cpp" />

+ 6 - 0
CamelotD3D11RenderSystem/CamelotD3D11RenderSystem.vcxproj.filters

@@ -123,6 +123,9 @@
     <ClInclude Include="Include\CmD3D11TextureView.h">
     <ClInclude Include="Include\CmD3D11TextureView.h">
       <Filter>Header Files</Filter>
       <Filter>Header Files</Filter>
     </ClInclude>
     </ClInclude>
+    <ClInclude Include="Include\CmD3D11BuiltinMaterialManager.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\CmD3D11GpuProgram.cpp">
     <ClCompile Include="Source\CmD3D11GpuProgram.cpp">
@@ -227,5 +230,8 @@
     <ClCompile Include="Source\CmD3D11TextureView.cpp">
     <ClCompile Include="Source\CmD3D11TextureView.cpp">
       <Filter>Source Files</Filter>
       <Filter>Source Files</Filter>
     </ClCompile>
     </ClCompile>
+    <ClCompile Include="Source\CmD3D11BuiltinMaterialManager.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   </ItemGroup>
 </Project>
 </Project>

+ 26 - 0
CamelotD3D11RenderSystem/Include/CmD3D11BuiltinMaterialManager.h

@@ -0,0 +1,26 @@
+#pragma once
+
+#include "CmD3D11Prerequisites.h"
+#include "CmBuiltinMaterialManager.h"
+
+namespace CamelotEngine
+{
+	/**
+	 * @copydoc BuiltinMaterialManager
+	 */
+	class D3D11BuiltinMaterialManager : public BuiltinMaterialManager
+	{
+	public:
+		MaterialHandle createSpriteTextMaterial() const;
+		MaterialHandle createSpriteImageMaterial() const;
+
+	protected:
+		ShaderPtr mSpriteTextShader;
+		ShaderPtr mSpriteImageShader;
+
+		void onStartUp();
+
+		void initSpriteTextShader();
+		void initSpriteImageShader();
+	};
+}

+ 85 - 0
CamelotD3D11RenderSystem/Source/CmD3D11BuiltinMaterialManager.cpp

@@ -0,0 +1,85 @@
+#include "CmD3D11BuiltinMaterialManager.h"
+#include "CmRendererManager.h"
+#include "CmHighLevelGpuProgram.h"
+#include "CmShader.h"
+#include "CmTechnique.h"
+#include "CmPass.h"
+#include "CmMaterial.h"
+#include "CmBlendState.h"
+
+namespace CamelotEngine
+{
+	MaterialHandle D3D11BuiltinMaterialManager::createSpriteTextMaterial() const
+	{
+		return Material::create(mSpriteTextShader);
+	}
+
+	MaterialHandle D3D11BuiltinMaterialManager::createSpriteImageMaterial() const
+	{
+		return Material::create(mSpriteImageShader);
+	}
+
+	void D3D11BuiltinMaterialManager::onStartUp()
+	{
+		initSpriteTextShader();
+		initSpriteImageShader();
+	}
+
+	void D3D11BuiltinMaterialManager::initSpriteTextShader()
+	{
+		String vsCode = "										\
+			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;			\
+																\
+				oPosition = float4(tfrmdX, tfrmdY, 0, 1);		\
+				oUv = uv;										\
+			}													\
+			";
+
+		String psCode = "																			\
+			SamplerState mainTexSamp : register(s0);												\
+			Texture2D mainTexture : register(t0);													\
+																									\
+			float4 ps_main(in float4 inPos : SV_Position, float2 uv : TEXCOORD0) : SV_Target		\
+			{																						\
+				float4 color = float4(1.0f, 1.0f, 1.0f, mainTexture.Sample(mainTexSamp, uv).r);		\
+				return color;																		\
+			}";
+
+		HighLevelGpuProgramHandle vsProgram = HighLevelGpuProgram::create(vsCode, "vs_main", "hlsl", GPT_VERTEX_PROGRAM, GPP_VS_4_0);
+		HighLevelGpuProgramHandle psProgram = HighLevelGpuProgram::create(psCode, "ps_main", "hlsl", GPT_FRAGMENT_PROGRAM, GPP_PS_4_0);
+
+		vsProgram.waitUntilLoaded();
+		psProgram.waitUntilLoaded();
+
+		mSpriteTextShader = Shader::create("TextShader");
+
+		mSpriteTextShader->addParameter("mainTexSamp", "mainTexSamp", GPOT_SAMPLER2D);
+		mSpriteTextShader->addParameter("mainTexture", "mainTexture", GPOT_TEXTURE2D);
+
+		TechniquePtr newTechnique = mSpriteTextShader->addTechnique("D3D11RenderSystem", RendererManager::getCoreRendererName()); 
+		PassPtr newPass = newTechnique->addPass();
+		newPass->setVertexProgram(vsProgram);
+		newPass->setFragmentProgram(psProgram);
+
+		BLEND_STATE_DESC desc;
+		desc.renderTargetDesc[0].blendEnable = true;
+		desc.renderTargetDesc[0].srcBlend = BF_SOURCE_ALPHA;
+		desc.renderTargetDesc[0].dstBlend = BF_INV_SOURCE_ALPHA;
+		desc.renderTargetDesc[0].blendOp = BO_ADD;
+
+		BlendStateHandle blendState = BlendState::create(desc);
+		newPass->setBlendState(blendState);
+	}
+
+	void D3D11BuiltinMaterialManager::initSpriteImageShader()
+	{
+		// TODO
+	}
+}

+ 4 - 0
CamelotD3D11RenderSystem/Source/CmD3D11RenderSystem.cpp

@@ -20,6 +20,7 @@
 #include "CmD3D11GpuParamBlock.h"
 #include "CmD3D11GpuParamBlock.h"
 #include "CmD3D11InputLayoutManager.h"
 #include "CmD3D11InputLayoutManager.h"
 #include "CmD3D11HLSLProgram.h"
 #include "CmD3D11HLSLProgram.h"
+#include "CmD3D11BuiltinMaterialManager.h"
 #include "CmGpuParams.h"
 #include "CmGpuParams.h"
 #include "CmDebug.h"
 #include "CmDebug.h"
 #include "CmException.h"
 #include "CmException.h"
@@ -125,6 +126,8 @@ namespace CamelotEngine
 		// Create render state manager
 		// Create render state manager
 		RenderStateManager::startUp(new D3D11RenderStateManager());
 		RenderStateManager::startUp(new D3D11RenderStateManager());
 
 
+		BuiltinMaterialManager::startUp(new D3D11BuiltinMaterialManager());
+
 		mCurrentCapabilities = createRenderSystemCapabilities();
 		mCurrentCapabilities = createRenderSystemCapabilities();
 
 
 		mCurrentCapabilities->addShaderProfile("hlsl");
 		mCurrentCapabilities->addShaderProfile("hlsl");
@@ -145,6 +148,7 @@ namespace CamelotEngine
 		mActiveVertexDeclaration = nullptr;
 		mActiveVertexDeclaration = nullptr;
 		mActiveVertexShader = nullptr;
 		mActiveVertexShader = nullptr;
 
 
+		BuiltinMaterialManager::shutDown();
 		RenderStateManager::shutDown();
 		RenderStateManager::shutDown();
 		RenderWindowManager::shutDown();
 		RenderWindowManager::shutDown();
 		GpuProgramManager::shutDown();
 		GpuProgramManager::shutDown();

+ 2 - 0
CamelotD3D9Renderer/CamelotD3D9Renderer.vcxproj

@@ -151,6 +151,7 @@
     </Link>
     </Link>
   </ItemDefinitionGroup>
   </ItemDefinitionGroup>
   <ItemGroup>
   <ItemGroup>
+    <ClInclude Include="Include\CmD3D9BuiltinMaterialManager.h" />
     <ClInclude Include="Include\CmD3D9Device.h" />
     <ClInclude Include="Include\CmD3D9Device.h" />
     <ClInclude Include="Include\CmD3D9DeviceManager.h" />
     <ClInclude Include="Include\CmD3D9DeviceManager.h" />
     <ClInclude Include="Include\CmD3D9Driver.h" />
     <ClInclude Include="Include\CmD3D9Driver.h" />
@@ -185,6 +186,7 @@
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClCompile Include="CmD3D9Plugin.cpp" />
     <ClCompile Include="CmD3D9Plugin.cpp" />
+    <ClCompile Include="Source\CmD3D9BuiltinMaterialManager.cpp" />
     <ClCompile Include="Source\CmD3D9Device.cpp" />
     <ClCompile Include="Source\CmD3D9Device.cpp" />
     <ClCompile Include="Source\CmD3D9DeviceManager.cpp" />
     <ClCompile Include="Source\CmD3D9DeviceManager.cpp" />
     <ClCompile Include="Source\CmD3D9Driver.cpp" />
     <ClCompile Include="Source\CmD3D9Driver.cpp" />

+ 6 - 0
CamelotD3D9Renderer/CamelotD3D9Renderer.vcxproj.filters

@@ -111,6 +111,9 @@
     <ClInclude Include="Include\CmD3D9HLSLParamParser.h">
     <ClInclude Include="Include\CmD3D9HLSLParamParser.h">
       <Filter>Header Files</Filter>
       <Filter>Header Files</Filter>
     </ClInclude>
     </ClInclude>
+    <ClInclude Include="Include\CmD3D9BuiltinMaterialManager.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\CmD3D9Device.cpp">
     <ClCompile Include="Source\CmD3D9Device.cpp">
@@ -200,5 +203,8 @@
     <ClCompile Include="Source\CmD3D9GpuBuffer.cpp">
     <ClCompile Include="Source\CmD3D9GpuBuffer.cpp">
       <Filter>Source Files</Filter>
       <Filter>Source Files</Filter>
     </ClCompile>
     </ClCompile>
+    <ClCompile Include="Source\CmD3D9BuiltinMaterialManager.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   </ItemGroup>
 </Project>
 </Project>

+ 26 - 0
CamelotD3D9Renderer/Include/CmD3D9BuiltinMaterialManager.h

@@ -0,0 +1,26 @@
+#pragma once
+
+#include "CmD3D9Prerequisites.h"
+#include "CmBuiltinMaterialManager.h"
+
+namespace CamelotEngine
+{
+	/**
+	 * @copydoc BuiltinMaterialManager
+	 */
+	class D3D9BuiltinMaterialManager : public BuiltinMaterialManager
+	{
+	public:
+		MaterialHandle createSpriteTextMaterial() const;
+		MaterialHandle createSpriteImageMaterial() const;
+
+	protected:
+		ShaderPtr mSpriteTextShader;
+		ShaderPtr mSpriteImageShader;
+
+		void onStartUp();
+
+		void initSpriteTextShader();
+		void initSpriteImageShader();
+	};
+}

+ 36 - 0
CamelotD3D9Renderer/Source/CmD3D9BuiltinMaterialManager.cpp

@@ -0,0 +1,36 @@
+#include "CmD3D9BuiltinMaterialManager.h"
+#include "CmHighLevelGpuProgram.h"
+#include "CmShader.h"
+#include "CmTechnique.h"
+#include "CmPass.h"
+#include "CmMaterial.h"
+#include "CmBlendState.h"
+
+namespace CamelotEngine
+{
+	MaterialHandle D3D9BuiltinMaterialManager::createSpriteTextMaterial() const
+	{
+		return Material::create(mSpriteTextShader);
+	}
+
+	MaterialHandle D3D9BuiltinMaterialManager::createSpriteImageMaterial() const
+	{
+		return Material::create(mSpriteImageShader);
+	}
+
+	void D3D9BuiltinMaterialManager::onStartUp()
+	{
+		initSpriteTextShader();
+		initSpriteImageShader();
+	}
+
+	void D3D9BuiltinMaterialManager::initSpriteTextShader()
+	{
+		// TODO
+	}
+
+	void D3D9BuiltinMaterialManager::initSpriteImageShader()
+	{
+		// TODO
+	}
+}

+ 4 - 0
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -47,6 +47,7 @@ THE SOFTWARE.
 #include "CmD3D9DeviceManager.h"
 #include "CmD3D9DeviceManager.h"
 #include "CmD3D9ResourceManager.h"
 #include "CmD3D9ResourceManager.h"
 #include "CmD3D9RenderWindowManager.h"
 #include "CmD3D9RenderWindowManager.h"
+#include "CmD3D9BuiltinMaterialManager.h"
 #include "CmHighLevelGpuProgramManager.h"
 #include "CmHighLevelGpuProgramManager.h"
 #include "CmRenderStateManager.h"
 #include "CmRenderStateManager.h"
 #include "CmAsyncOp.h"
 #include "CmAsyncOp.h"
@@ -182,6 +183,8 @@ namespace CamelotEngine
 		// Create render state manager
 		// Create render state manager
 		RenderStateManager::startUp(new RenderStateManager());
 		RenderStateManager::startUp(new RenderStateManager());
 
 
+		BuiltinMaterialManager::startUp(new D3D9BuiltinMaterialManager());
+
 		// call superclass method
 		// call superclass method
 		RenderSystem::initialize_internal();
 		RenderSystem::initialize_internal();
 	}
 	}
@@ -201,6 +204,7 @@ namespace CamelotEngine
 		SAFE_DELETE( mDriverList );
 		SAFE_DELETE( mDriverList );
 		mActiveD3DDriver = NULL;	
 		mActiveD3DDriver = NULL;	
 
 
+		BuiltinMaterialManager::shutDown();
 		TextureManager::shutDown();
 		TextureManager::shutDown();
 		HardwareBufferManager::shutDown();
 		HardwareBufferManager::shutDown();
 		GpuProgramManager::shutDown();	
 		GpuProgramManager::shutDown();	

+ 2 - 0
CamelotGLRenderer/CamelotGLRenderer.vcxproj

@@ -151,6 +151,7 @@
     </Link>
     </Link>
   </ItemDefinitionGroup>
   </ItemDefinitionGroup>
   <ItemGroup>
   <ItemGroup>
+    <ClInclude Include="Include\CmGLBuiltinMaterialManager.h" />
     <ClInclude Include="Include\CmGLContext.h" />
     <ClInclude Include="Include\CmGLContext.h" />
     <ClInclude Include="Include\CmGLFrameBufferObject.h" />
     <ClInclude Include="Include\CmGLFrameBufferObject.h" />
     <ClInclude Include="Include\CmGLGpuBuffer.h" />
     <ClInclude Include="Include\CmGLGpuBuffer.h" />
@@ -187,6 +188,7 @@
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClCompile Include="CmGLPlugin.cpp" />
     <ClCompile Include="CmGLPlugin.cpp" />
+    <ClCompile Include="Source\CmGLBuiltinMaterialManager.cpp" />
     <ClCompile Include="Source\CmGLContext.cpp" />
     <ClCompile Include="Source\CmGLContext.cpp" />
     <ClCompile Include="Source\CmGLFrameBufferObject.cpp" />
     <ClCompile Include="Source\CmGLFrameBufferObject.cpp" />
     <ClCompile Include="Source\CmGLGpuBuffer.cpp" />
     <ClCompile Include="Source\CmGLGpuBuffer.cpp" />

+ 6 - 0
CamelotGLRenderer/CamelotGLRenderer.vcxproj.filters

@@ -123,6 +123,9 @@
     <ClInclude Include="Include\CmGLGpuBuffer.h">
     <ClInclude Include="Include\CmGLGpuBuffer.h">
       <Filter>Header Files</Filter>
       <Filter>Header Files</Filter>
     </ClInclude>
     </ClInclude>
+    <ClInclude Include="Include\CmGLBuiltinMaterialManager.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\GLSL\src\CmGLSLExtSupport.cpp">
     <ClCompile Include="Source\GLSL\src\CmGLSLExtSupport.cpp">
@@ -215,5 +218,8 @@
     <ClCompile Include="Source\CmGLGpuBuffer.cpp">
     <ClCompile Include="Source\CmGLGpuBuffer.cpp">
       <Filter>Source Files</Filter>
       <Filter>Source Files</Filter>
     </ClCompile>
     </ClCompile>
+    <ClCompile Include="Source\CmGLBuiltinMaterialManager.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   </ItemGroup>
 </Project>
 </Project>

+ 26 - 0
CamelotGLRenderer/Include/CmGLBuiltinMaterialManager.h

@@ -0,0 +1,26 @@
+#pragma once
+
+#include "CmGLPrerequisites.h"
+#include "CmBuiltinMaterialManager.h"
+
+namespace CamelotEngine
+{
+	/**
+	 * @copydoc BuiltinMaterialManager
+	 */
+	class GLBuiltinMaterialManager : public BuiltinMaterialManager
+	{
+	public:
+		MaterialHandle createSpriteTextMaterial() const;
+		MaterialHandle createSpriteImageMaterial() const;
+
+	protected:
+		ShaderPtr mSpriteTextShader;
+		ShaderPtr mSpriteImageShader;
+
+		void onStartUp();
+
+		void initSpriteTextShader();
+		void initSpriteImageShader();
+	};
+}

+ 36 - 0
CamelotGLRenderer/Source/CmGLBuiltinMaterialManager.cpp

@@ -0,0 +1,36 @@
+#include "CmGLBuiltinMaterialManager.h"
+#include "CmHighLevelGpuProgram.h"
+#include "CmShader.h"
+#include "CmTechnique.h"
+#include "CmPass.h"
+#include "CmMaterial.h"
+#include "CmBlendState.h"
+
+namespace CamelotEngine
+{
+	MaterialHandle GLBuiltinMaterialManager::createSpriteTextMaterial() const
+	{
+		return Material::create(mSpriteTextShader);
+	}
+
+	MaterialHandle GLBuiltinMaterialManager::createSpriteImageMaterial() const
+	{
+		return Material::create(mSpriteImageShader);
+	}
+
+	void GLBuiltinMaterialManager::onStartUp()
+	{
+		initSpriteTextShader();
+		initSpriteImageShader();
+	}
+
+	void GLBuiltinMaterialManager::initSpriteTextShader()
+	{
+		// TODO
+	}
+
+	void GLBuiltinMaterialManager::initSpriteImageShader()
+	{
+		// TODO
+	}
+}

+ 4 - 0
CamelotGLRenderer/Source/CmGLRenderSystem.cpp

@@ -47,6 +47,7 @@ THE SOFTWARE.s
 #include "CmDepthStencilState.h"
 #include "CmDepthStencilState.h"
 #include "CmGLRenderTexture.h"
 #include "CmGLRenderTexture.h"
 #include "CmGLRenderWindowManager.h"
 #include "CmGLRenderWindowManager.h"
+#include "CmGLBuiltinMaterialManager.h"
 #include "CmGLSLProgramPipelineManager.h"
 #include "CmGLSLProgramPipelineManager.h"
 #include "CmRenderStateManager.h"
 #include "CmRenderStateManager.h"
 #include "CmGpuParams.h"
 #include "CmGpuParams.h"
@@ -145,6 +146,8 @@ namespace CamelotEngine
 
 
 		RenderStateManager::startUp(new RenderStateManager());
 		RenderStateManager::startUp(new RenderStateManager());
 
 
+		BuiltinMaterialManager::startUp(new GLBuiltinMaterialManager());
+
 		RenderSystem::initialize_internal();
 		RenderSystem::initialize_internal();
 	}
 	}
 
 
@@ -200,6 +203,7 @@ namespace CamelotEngine
 		mGLSupport->stop();
 		mGLSupport->stop();
 
 
 		TextureManager::shutDown();
 		TextureManager::shutDown();
+		BuiltinMaterialManager::shutDown();
 		RenderWindowManager::shutDown();
 		RenderWindowManager::shutDown();
 		RenderStateManager::shutDown();
 		RenderStateManager::shutDown();
 
 

+ 7 - 0
CamelotUtility/Include/CmModule.h

@@ -62,6 +62,8 @@ namespace CamelotEngine
 
 
 			_instance = moduleInstance;
 			_instance = moduleInstance;
 			isShutDown = false;
 			isShutDown = false;
+
+			moduleInstance->onStartUp();
 		}
 		}
 
 
 		/**
 		/**
@@ -75,6 +77,8 @@ namespace CamelotEngine
 					"Trying to shut down an already shut down module.");
 					"Trying to shut down an already shut down module.");
 			}
 			}
 
 
+			_instance->onShutDown();
+
 			delete _instance;
 			delete _instance;
 			isShutDown = true;
 			isShutDown = true;
 		}
 		}
@@ -101,6 +105,9 @@ namespace CamelotEngine
 		Module(const Module&) { }
 		Module(const Module&) { }
 		Module& operator=(const Module&) { return *this; }
 		Module& operator=(const Module&) { return *this; }
 
 
+		virtual void onStartUp() {}
+		virtual void onShutDown() {}
+
 	private:
 	private:
 		static T* _instance;
 		static T* _instance;
 		static bool isShutDown;
 		static bool isShutDown;

+ 11 - 0
TODO.txt

@@ -21,6 +21,15 @@ Figure out how to store texture references in a font?
 
 
 Move Debug to CamelotCore and add SetFillMode
 Move Debug to CamelotCore and add SetFillMode
 
 
+Immediate TODO:
+Add clone() method to Materials
+Implement image shader for D3D11BuiltinMaterialManager
+Improve text shader so it doesn't have resolution values hardcoded in
+Start-up D3D11BuiltinMaterialManager
+Implement D3D9 and GL BuiltInMaterialManager
+Start-up GUIManager
+
+
 Test:
 Test:
 Need sorted rendering as fonts render before scene and blending doesn't work as it should
 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
  - Implemented 2D renderer and ensure it runs after everything else
@@ -210,6 +219,8 @@ Low priority TODO:
  - Go through pixel formats and removed unused ones: L8, L16, A4L4, and many others
  - Go through pixel formats and removed unused ones: L8, L16, A4L4, and many others
 
 
 Optional TODO:
 Optional TODO:
+ - Need better handling for shader techniques. Some Materials are able to run on all renderers yet I can only specify one. This is problematic
+    for Materials for things like text and sprites, which should run on all renderers, even if user adds a new one
  - Add precompiled headers to all projects
  - Add precompiled headers to all projects
  - If possible, make sure GLSL uses EntryPoint and Profile fields I have added to GpuProgram
  - If possible, make sure GLSL uses EntryPoint and Profile fields I have added to GpuProgram
  - Move all x86 libs to x86 folders. Move all binaries to x86 folders as well
  - Move all x86 libs to x86 folders. Move all binaries to x86 folders as well