Marko Pintera 13 лет назад
Родитель
Сommit
7052e68acf

+ 1 - 0
CamelotRenderer/CamelotRenderer.vcxproj

@@ -107,6 +107,7 @@
     <ClInclude Include="Include\CmGpuProgram.h" />
     <ClInclude Include="Include\CmGpuProgram.h" />
     <ClInclude Include="Include\CmGpuProgramManager.h" />
     <ClInclude Include="Include\CmGpuProgramManager.h" />
     <ClInclude Include="Include\CmGpuProgramParams.h" />
     <ClInclude Include="Include\CmGpuProgramParams.h" />
+    <ClInclude Include="Include\CmGpuProgramRTTI.h" />
     <ClInclude Include="Include\CmHardwareBuffer.h" />
     <ClInclude Include="Include\CmHardwareBuffer.h" />
     <ClInclude Include="Include\CmHardwareBufferManager.h" />
     <ClInclude Include="Include\CmHardwareBufferManager.h" />
     <ClInclude Include="Include\CmHardwareIndexBuffer.h" />
     <ClInclude Include="Include\CmHardwareIndexBuffer.h" />

+ 3 - 0
CamelotRenderer/CamelotRenderer.vcxproj.filters

@@ -274,6 +274,9 @@
     <ClInclude Include="Include\CmResourceRefRTTI.h">
     <ClInclude Include="Include\CmResourceRefRTTI.h">
       <Filter>Header Files\RTTI</Filter>
       <Filter>Header Files\RTTI</Filter>
     </ClInclude>
     </ClInclude>
+    <ClInclude Include="Include\CmGpuProgramRTTI.h">
+      <Filter>Header Files\RTTI</Filter>
+    </ClInclude>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\CamelotRenderer.cpp">
     <ClCompile Include="Source\CamelotRenderer.cpp">

+ 2 - 0
CamelotRenderer/Include/CmApplication.h

@@ -41,6 +41,8 @@ namespace CamelotEngine
 			TextureRef mDbgTexture;
 			TextureRef mDbgTexture;
 			MeshRef mDbgMesh;
 			MeshRef mDbgMesh;
 			GameObjectPtr mCameraGO;
 			GameObjectPtr mCameraGO;
+			GpuProgramParametersPtr mVertParams;
+			GpuProgramParametersPtr mFragParams;
 	};
 	};
 
 
 	CM_EXPORT Application& gApplication();
 	CM_EXPORT Application& gApplication();

+ 10 - 20
CamelotRenderer/Include/CmGpuProgram.h

@@ -33,6 +33,7 @@ THE SOFTWARE.
 #include "CmRenderOperation.h"
 #include "CmRenderOperation.h"
 #include "CmGpuProgramParams.h"
 #include "CmGpuProgramParams.h"
 #include "CmRenderSystemCapabilities.h"
 #include "CmRenderSystemCapabilities.h"
+#include "CmResource.h"
 
 
 namespace CamelotEngine {
 namespace CamelotEngine {
 
 
@@ -59,7 +60,7 @@ namespace CamelotEngine {
 		If you wish to use higher level shading languages like HLSL and Cg, you need to 
 		If you wish to use higher level shading languages like HLSL and Cg, you need to 
 		use the HighLevelGpuProgram class instead.
 		use the HighLevelGpuProgram class instead.
 	*/
 	*/
-	class CM_EXPORT GpuProgram
+	class CM_EXPORT GpuProgram : public Resource
 	{
 	{
 	protected:
 	protected:
 		/// The type of the program
 		/// The type of the program
@@ -74,8 +75,6 @@ namespace CamelotEngine {
         String mSource;
         String mSource;
         /// Syntax code e.g. arbvp1, vs_2_0 etc
         /// Syntax code e.g. arbvp1, vs_2_0 etc
         String mSyntaxCode;
         String mSyntaxCode;
-		/// The default parameters for use with this object
-		GpuProgramParametersSharedPtr mDefaultParams;
 		/// Did we encounter a compilation error?
 		/// Did we encounter a compilation error?
 		bool mCompileError;
 		bool mCompileError;
 		/** Record of logical to physical buffer maps. Mandatory for low-level
 		/** Record of logical to physical buffer maps. Mandatory for low-level
@@ -119,7 +118,7 @@ namespace CamelotEngine {
 
 
 		virtual ~GpuProgram() {}
 		virtual ~GpuProgram() {}
 
 
-		virtual void load(void);
+		virtual void loadImpl();
 		virtual void unload() {}
 		virtual void unload() {}
 
 
 		/** Sets the source assembly for this program from an in-memory string.
 		/** Sets the source assembly for this program from an in-memory string.
@@ -173,22 +172,6 @@ namespace CamelotEngine {
             they are appropriate.
             they are appropriate.
         */
         */
         virtual GpuProgramParametersSharedPtr createParameters(void);
         virtual GpuProgramParametersSharedPtr createParameters(void);
-		
-		/** Get a reference to the default parameters which are to be used for all
-			uses of this program.
-		@remarks
-			A program can be set up with a list of default parameters, which can save time when 
-			using a program many times in a material with roughly the same settings. By 
-			retrieving the default parameters and populating it with the most used options, 
-			any new parameter objects created from this program afterwards will automatically include
-			the default parameters; thus users of the program need only change the parameters
-			which are unique to their own usage of the program.
-		*/
-		virtual GpuProgramParametersSharedPtr getDefaultParameters(void);
-
-        /** Returns true if default parameters have been set up.  
-        */
-        virtual bool hasDefaultParameters(void) const { return mDefaultParams != nullptr; }
 
 
 		/** Returns a string that specifies the language of the gpu programs as specified
 		/** Returns a string that specifies the language of the gpu programs as specified
         in a material script. ie: asm, cg, hlsl, glsl
         in a material script. ie: asm, cg, hlsl, glsl
@@ -219,6 +202,13 @@ namespace CamelotEngine {
         /// Virtual method which must be implemented by subclasses, load from mSource
         /// Virtual method which must be implemented by subclasses, load from mSource
         virtual void loadFromSource(void) = 0;
         virtual void loadFromSource(void) = 0;
 
 
+		/************************************************************************/
+		/* 								SERIALIZATION                      		*/
+		/************************************************************************/
+	public:
+		friend class GpuProgramRTTI;
+		static RTTITypeBase* getRTTIStatic();
+		virtual RTTITypeBase* getRTTI() const;
 	};
 	};
 
 
 	/** @} */
 	/** @} */

+ 38 - 0
CamelotRenderer/Include/CmGpuProgramRTTI.h

@@ -0,0 +1,38 @@
+#pragma once
+
+#include "CmPrerequisites.h"
+#include "CmRTTIType.h"
+#include "CmGpuProgram.h"
+
+namespace CamelotEngine
+{
+	class CM_EXPORT GpuProgramRTTI : public RTTIType<GpuProgram, Resource, GpuProgramRTTI>
+	{
+	private:
+		CM_SETGET_MEMBER(mSize, UINT32, GpuProgram)
+		CM_SETGET_MEMBER(mUUID, String, GpuProgram);
+
+	public:
+		GpuProgramRTTI()
+		{
+			CM_ADD_PLAINFIELD(mSize, 0, GpuProgramRTTI)
+			CM_ADD_PLAINFIELD(mUUID, 1, GpuProgramRTTI)
+		}
+
+		virtual const String& getRTTIName()
+		{
+			static String name = "GpuProgram";
+			return name;
+		}
+
+		virtual UINT32 getRTTIId()
+		{
+			return TID_GpuProgram;
+		}
+
+		virtual std::shared_ptr<IReflectable> newRTTIObject()
+		{
+			CM_EXCEPT(InternalErrorException, "Cannot instantiate abstract class!"); // TODO - Need to initialize this properly
+		}
+	};
+}

+ 1 - 1
CamelotRenderer/Include/CmHighLevelGpuProgram.h

@@ -98,7 +98,7 @@ namespace CamelotEngine {
         HighLevelGpuProgram();
         HighLevelGpuProgram();
         ~HighLevelGpuProgram();
         ~HighLevelGpuProgram();
 
 
-		virtual void load();
+		virtual void loadImpl();
 		virtual void unload();
 		virtual void unload();
 
 
         /** Creates a new parameters object compatible with this program definition. 
         /** Creates a new parameters object compatible with this program definition. 

+ 2 - 1
CamelotRenderer/Include/CmPrerequisites.h

@@ -154,7 +154,8 @@ namespace CamelotEngine
 		TID_Component = 1006,
 		TID_Component = 1006,
 		TID_Camera = 1007,
 		TID_Camera = 1007,
 		TID_Renderable = 1008,
 		TID_Renderable = 1008,
-		TID_ResourceRef = 1009
+		TID_ResourceRef = 1009,
+		TID_GpuProgram = 1010
 	};
 	};
 }
 }
 
 

+ 7 - 4
CamelotRenderer/Source/CmApplication.cpp

@@ -136,6 +136,9 @@ namespace CamelotEngine
 
 
 		//mVertProg = HighLevelGpuProgramManager::instance().createProgram(vertShaderCode, "main", "glsl", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
 		//mVertProg = HighLevelGpuProgramManager::instance().createProgram(vertShaderCode, "main", "glsl", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
 		//mVertProg->load();
 		//mVertProg->load();
+		
+		mVertParams = mVertProg->createParameters();
+		mFragParams = mFragProg->createParameters();
 
 
 		//ShaderPtr newShader(new Shader("TestShader"));
 		//ShaderPtr newShader(new Shader("TestShader"));
 		//TechniquePtr newTechnique = newShader->addTechnique("GLRenderSystem", "ForwardRenderer");
 		//TechniquePtr newTechnique = newShader->addTechnique("GLRenderSystem", "ForwardRenderer");
@@ -403,8 +406,8 @@ namespace CamelotEngine
 		renderSystem->clearFrameBuffer(FBT_COLOUR | FBT_DEPTH, Color::Blue);
 		renderSystem->clearFrameBuffer(FBT_COLOUR | FBT_DEPTH, Color::Blue);
 		renderSystem->_beginFrame();
 		renderSystem->_beginFrame();
 
 
-		mVertProg->getDefaultParameters()->setNamedConstant("matViewProjection", viewProjMatrix);
-		mFragProg->getDefaultParameters()->setNamedConstant("tex", mDbgTexture);
+		mVertParams->setNamedConstant("matViewProjection", viewProjMatrix);
+		mFragParams->setNamedConstant("tex", mDbgTexture);
 		//renderSystem->bindGpuProgramParameters(GPT_VERTEX_PROGRAM, mVertProg->getDefaultParameters(), GPV_ALL);
 		//renderSystem->bindGpuProgramParameters(GPT_VERTEX_PROGRAM, mVertProg->getDefaultParameters(), GPV_ALL);
 
 
 		//renderSystem->_setTexture(0, true, mDbgTexture);
 		//renderSystem->_setTexture(0, true, mDbgTexture);
@@ -413,8 +416,8 @@ namespace CamelotEngine
 		renderSystem->bindGpuProgram(mVertProg->_getBindingDelegate()); // TODO - I don't like this. Shader should be able to be bound directly!
 		renderSystem->bindGpuProgram(mVertProg->_getBindingDelegate()); // TODO - I don't like this. Shader should be able to be bound directly!
 
 
 		// TODO - Shaders need to be bound and only then parameters can be set. I need to encapuslate this better because I can't expect users to know that
 		// TODO - Shaders need to be bound and only then parameters can be set. I need to encapuslate this better because I can't expect users to know that
-		renderSystem->bindGpuProgramParameters(GPT_FRAGMENT_PROGRAM, mFragProg->getDefaultParameters(), GPV_ALL); // TODO - If I dont call bind parameters before shader wont activate? I think I should handle that differently
-		renderSystem->bindGpuProgramParameters(GPT_VERTEX_PROGRAM, mVertProg->getDefaultParameters(), GPV_ALL);
+		renderSystem->bindGpuProgramParameters(GPT_FRAGMENT_PROGRAM, mFragParams, GPV_ALL); // TODO - If I dont call bind parameters before shader wont activate? I think I should handle that differently
+		renderSystem->bindGpuProgramParameters(GPT_VERTEX_PROGRAM, mVertParams, GPV_ALL);
 
 
 		
 		
 		
 		

+ 15 - 21
CamelotRenderer/Source/CmGpuProgram.cpp

@@ -33,6 +33,7 @@ THE SOFTWARE.
 #include "CmException.h"
 #include "CmException.h"
 #include "CmRenderSystem.h"
 #include "CmRenderSystem.h"
 #include "CmRenderSystemManager.h"
 #include "CmRenderSystemManager.h"
+#include "CmGpuProgramRTTI.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
@@ -59,19 +60,13 @@ namespace CamelotEngine
         mSource = source;
         mSource = source;
 		mCompileError = false;
 		mCompileError = false;
     }
     }
-		
-
     //-----------------------------------------------------------------------------
     //-----------------------------------------------------------------------------
-    void GpuProgram::load(void)
+    void GpuProgram::loadImpl(void)
     {
     {
         // Call polymorphic load
         // Call polymorphic load
 		try 
 		try 
 		{
 		{
 			loadFromSource();
 			loadFromSource();
-
-			assert(mDefaultParams == nullptr);
-
-			mDefaultParams = createParameters();
 		}
 		}
 		catch (const Exception&)
 		catch (const Exception&)
 		{
 		{
@@ -134,22 +129,8 @@ namespace CamelotEngine
 		// link shared logical / physical map for low-level use
 		// link shared logical / physical map for low-level use
 		ret->_setLogicalIndexes(mFloatLogicalToPhysical, mIntLogicalToPhysical, mSamplerLogicalToPhysical);
 		ret->_setLogicalIndexes(mFloatLogicalToPhysical, mIntLogicalToPhysical, mSamplerLogicalToPhysical);
 
 
-        // Copy in default parameters if present
-        if (mDefaultParams != nullptr)
-            ret->copyConstantsFrom(*(mDefaultParams.get()));
-        
         return ret;
         return ret;
     }
     }
-    //-----------------------------------------------------------------------------
-    GpuProgramParametersSharedPtr GpuProgram::getDefaultParameters(void)
-    {
-        if (mDefaultParams == nullptr)
-        {
-            mDefaultParams = createParameters();
-        }
-        return mDefaultParams;
-    }
-
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     const String& GpuProgram::getLanguage(void) const
     const String& GpuProgram::getLanguage(void) const
     {
     {
@@ -157,5 +138,18 @@ namespace CamelotEngine
 
 
         return language;
         return language;
     }
     }
+
+	/************************************************************************/
+	/* 								SERIALIZATION                      		*/
+	/************************************************************************/
+	RTTITypeBase* GpuProgram::getRTTIStatic()
+	{
+		return GpuProgramRTTI::instance();
+	}
+
+	RTTITypeBase* GpuProgram::getRTTI() const
+	{
+		return GpuProgram::getRTTIStatic();
+	}
 }
 }
 
 

+ 1 - 8
CamelotRenderer/Source/CmHighLevelGpuProgram.cpp

@@ -37,7 +37,7 @@ namespace CamelotEngine
     {
     {
     }
     }
     //---------------------------------------------------------------------------
     //---------------------------------------------------------------------------
-    void HighLevelGpuProgram::load()
+    void HighLevelGpuProgram::loadImpl()
     {
     {
 		if (isSupported())
 		if (isSupported())
 		{
 		{
@@ -85,9 +85,6 @@ namespace CamelotEngine
 			populateParameterNames(params);
 			populateParameterNames(params);
 		}
 		}
 
 
-		// Copy in default parameters if present
-		if (mDefaultParams != nullptr)
-			params->copyConstantsFrom(*(mDefaultParams.get()));
         return params;
         return params;
     }
     }
     //---------------------------------------------------------------------------
     //---------------------------------------------------------------------------
@@ -99,10 +96,6 @@ namespace CamelotEngine
 			{
 			{
 				loadHighLevelImpl();
 				loadHighLevelImpl();
 				mHighLevelLoaded = true;
 				mHighLevelLoaded = true;
-
-				assert(mDefaultParams == nullptr); // TODO - These two lines and replicated both here and in GpuProgram. I should probably add another load method that holds it all in one place?
-				mDefaultParams = createParameters();
-
 			}
 			}
 			catch (const Exception& e)
 			catch (const Exception& e)
 			{
 			{