Forráskód Böngészése

Removed some useless cg stuff

Marko Pintera 13 éve
szülő
commit
01243d6be4

+ 4 - 4
CamelotClient/CamelotClient.cpp

@@ -84,13 +84,13 @@ int _tmain(int argc, _TCHAR* argv[])
 
 
 	//String vertShaderCode = "float4x4 matViewProjection;	\
 	//String vertShaderCode = "float4x4 matViewProjection;	\
 	//						void vs_main(										\
 	//						void vs_main(										\
-	//						float4 inPos : POSITION,							\
-	//						float2 uv : TEXCOORD0,								\
+	//						float4 cm_position : POSITION,							\
+	//						float2 cm_texcoord0 : TEXCOORD0,								\
 	//						out float4 oPosition : POSITION,					\
 	//						out float4 oPosition : POSITION,					\
 	//						out float2 oUv : TEXCOORD0)							\
 	//						out float2 oUv : TEXCOORD0)							\
 	//						{														\
 	//						{														\
-	//						oPosition = mul(matViewProjection, inPos);			\
-	//						oUv = uv;											\
+	//						oPosition = mul(matViewProjection, cm_position);			\
+	//						oUv = cm_texcoord0;											\
 	//						}";
 	//						}";
 
 
 	//vertProg =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "cg", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
 	//vertProg =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "cg", GPT_VERTEX_PROGRAM, GPP_VS_2_0);

+ 5 - 0
CamelotD3D11RenderSystem/Include/CmD3D11RenderSystem.h

@@ -12,6 +12,11 @@ namespace CamelotEngine
 
 
 		const String& getName() const;
 		const String& getName() const;
 		
 		
+		/**
+		 * @copydoc RenderSystem::getShadingLanguageName()
+		 */
+		const String& getShadingLanguageName() const;
+
 		void setBlendState(const BlendState& blendState);
 		void setBlendState(const BlendState& blendState);
 		void setRasterizerState(const RasterizerState& rasterizerState);
 		void setRasterizerState(const RasterizerState& rasterizerState);
 		void setDepthStencilState(const DepthStencilState& depthStencilState);
 		void setDepthStencilState(const DepthStencilState& depthStencilState);

+ 0 - 3
CamelotD3D11RenderSystem/Source/CmD3D11Mappings.cpp

@@ -775,9 +775,6 @@ namespace CamelotEngine
 		case D3D_SRV_DIMENSION_TEXTURE2D:
 		case D3D_SRV_DIMENSION_TEXTURE2D:
 		case D3D_SRV_DIMENSION_TEXTURE2DMS:
 		case D3D_SRV_DIMENSION_TEXTURE2DMS:
 			return TEX_TYPE_2D;
 			return TEX_TYPE_2D;
-		case D3D_SRV_DIMENSION_TEXTURE2DARRAY:
-		case D3D_SRV_DIMENSION_TEXTURE2DMSARRAY:
-			return TEX_TYPE_2D_ARRAY;
 		case D3D_SRV_DIMENSION_TEXTURE3D:
 		case D3D_SRV_DIMENSION_TEXTURE3D:
 			return TEX_TYPE_3D;
 			return TEX_TYPE_3D;
 		case D3D_SRV_DIMENSION_TEXTURECUBE:
 		case D3D_SRV_DIMENSION_TEXTURECUBE:

+ 49 - 0
CamelotD3D11RenderSystem/Source/CmD3D11RenderSystem.cpp

@@ -32,6 +32,12 @@ namespace CamelotEngine
 		return strName;
 		return strName;
 	}
 	}
 
 
+	const String& D3D11RenderSystem::getShadingLanguageName() const
+	{
+		static String strName("hlsl");
+		return strName;
+	}
+
 	void D3D11RenderSystem::initialize_internal()
 	void D3D11RenderSystem::initialize_internal()
 	{
 	{
 		HRESULT hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&mDXGIFactory);
 		HRESULT hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&mDXGIFactory);
@@ -220,6 +226,49 @@ namespace CamelotEngine
 
 
 	void D3D11RenderSystem::initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps)
 	void D3D11RenderSystem::initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps)
 	{
 	{
+		mCurrentCapabilities = new RenderSystemCapabilities();
+
+		mCurrentCapabilities->addShaderProfile("ps_4_0");
+		mCurrentCapabilities->addShaderProfile("vs_4_0");
+		mCurrentCapabilities->addShaderProfile("gs_4_0");
+
+		mCurrentCapabilities->addShaderProfile("ps_4_1");
+		mCurrentCapabilities->addShaderProfile("vs_4_1");
+		mCurrentCapabilities->addShaderProfile("gs_4_1");
+
+		mCurrentCapabilities->addShaderProfile("ps_5_0");
+		mCurrentCapabilities->addShaderProfile("vs_5_0");
+		mCurrentCapabilities->addShaderProfile("gs_5_0");
+		mCurrentCapabilities->addShaderProfile("cs_5_0");
+		mCurrentCapabilities->addShaderProfile("hs_5_0");
+		mCurrentCapabilities->addShaderProfile("ds_5_0");
+
+		// TODO - IF FEATURE LEVEL 10
+		{
+			mCurrentCapabilities->addGpuProgramProfile(GPP_PS_4_0, "ps_4_0");
+			mCurrentCapabilities->addGpuProgramProfile(GPP_VS_4_0, "vs_4_0");
+			mCurrentCapabilities->addGpuProgramProfile(GPP_GS_4_0, "gs_4_0");
+		}
+		
+		// TODO - IF FEATURE LEVEL 10.1
+		{
+			mCurrentCapabilities->addGpuProgramProfile(GPP_PS_4_1, "ps_4_1");
+			mCurrentCapabilities->addGpuProgramProfile(GPP_VS_4_1, "vs_4_1");
+			mCurrentCapabilities->addGpuProgramProfile(GPP_GS_4_1, "gs_4_1");
+		}
+
+		// TODO - IF FEATURE LEVEL 11
+		{
+			mCurrentCapabilities->addGpuProgramProfile(GPP_PS_5_0, "ps_5_0");
+			mCurrentCapabilities->addGpuProgramProfile(GPP_VS_5_0, "vs_5_0");
+			mCurrentCapabilities->addGpuProgramProfile(GPP_GS_5_0, "gs_5_0");
+			mCurrentCapabilities->addGpuProgramProfile(GPP_CS_5_0, "cs_5_0");
+			mCurrentCapabilities->addGpuProgramProfile(GPP_HS_5_0, "hs_5_0");
+			mCurrentCapabilities->addGpuProgramProfile(GPP_DS_5_0, "ds_5_0");
+		}
+
+		// TODO - All other caps need to be initialized
+
 		throw std::exception("The method or operation is not implemented.");
 		throw std::exception("The method or operation is not implemented.");
 	}
 	}
 
 

+ 0 - 1
CamelotD3D11RenderSystem/Source/CmD3D11Texture.cpp

@@ -529,7 +529,6 @@ namespace CamelotEngine
 			break;
 			break;
 		case TEX_TYPE_2D:
 		case TEX_TYPE_2D:
 		case TEX_TYPE_CUBE_MAP:
 		case TEX_TYPE_CUBE_MAP:
-		case TEX_TYPE_2D_ARRAY:
 			{
 			{
 				D3D11_TEXTURE2D_DESC desc;
 				D3D11_TEXTURE2D_DESC desc;
 				m2DTex->GetDesc(&desc);
 				m2DTex->GetDesc(&desc);

+ 8 - 0
CamelotD3D9Renderer/Include/CmD3D9RenderSystem.h

@@ -49,8 +49,16 @@ namespace CamelotEngine
 		// destructor
 		// destructor
 		~D3D9RenderSystem();
 		~D3D9RenderSystem();
 
 
+		/**
+		 * @copydoc RenderSystem::getName()
+		 */
 		const String& getName() const;
 		const String& getName() const;
 
 
+		/**
+		 * @copydoc RenderSystem::getShadingLanguageName()
+		 */
+		const String& getShadingLanguageName() const;
+
 		void destroyRenderTarget(RenderTarget* renderTarget);
 		void destroyRenderTarget(RenderTarget* renderTarget);
 
 
 		/**
 		/**

+ 9 - 2
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -137,12 +137,19 @@ namespace CamelotEngine
 
 
 		msD3D9RenderSystem = NULL;
 		msD3D9RenderSystem = NULL;
 	}
 	}
-	//---------------------------------------------------------------------
+
 	const String& D3D9RenderSystem::getName() const
 	const String& D3D9RenderSystem::getName() const
 	{
 	{
 		static String strName( "D3D9RenderSystem");
 		static String strName( "D3D9RenderSystem");
 		return strName;
 		return strName;
 	}
 	}
+
+	const String& D3D9RenderSystem::getShadingLanguageName() const
+	{
+		static String strName("hlsl");
+		return strName;
+	}
+
 	void D3D9RenderSystem::initialize_internal()
 	void D3D9RenderSystem::initialize_internal()
 	{
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 		THROW_IF_NOT_RENDER_THREAD;
@@ -252,7 +259,7 @@ namespace CamelotEngine
 	{
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 		THROW_IF_NOT_RENDER_THREAD;
 
 
-		GpuProgram* bindingPrg = prg->getBindingDelegate_internal();
+		GpuProgram* bindingPrg = prg->getBindingDelegate();
 
 
 		HRESULT hr;
 		HRESULT hr;
 		switch (bindingPrg->getType())
 		switch (bindingPrg->getType())

+ 5 - 0
CamelotGLRenderer/Include/CmGLRenderSystem.h

@@ -52,6 +52,11 @@ namespace CamelotEngine {
 		 */
 		 */
         const String& getName(void) const;
         const String& getName(void) const;
 
 
+		/**
+		 * @copydoc RenderSystem::getShadingLanguageName()
+		 */
+		const String& getShadingLanguageName() const;
+
 		/**
 		/**
 		 * @copydoc RenderSystem::setRenderTarget()
 		 * @copydoc RenderSystem::setRenderTarget()
 		 */
 		 */

+ 45 - 11
CamelotGLRenderer/Source/CmGLRenderSystem.cpp

@@ -144,6 +144,13 @@ namespace CamelotEngine
 		return strName;
 		return strName;
 	}
 	}
 
 
+
+	const String& GLRenderSystem::getShadingLanguageName() const
+	{
+		static String strName("glsl");
+		return strName;
+	}
+
 	void GLRenderSystem::initialize_internal()
 	void GLRenderSystem::initialize_internal()
 	{
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 		THROW_IF_NOT_RENDER_THREAD;
@@ -210,7 +217,7 @@ namespace CamelotEngine
 	{
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 		THROW_IF_NOT_RENDER_THREAD;
 
 
-		GpuProgram* bindingPrg = prg->getBindingDelegate_internal();
+		GpuProgram* bindingPrg = prg->getBindingDelegate();
 		GLSLGpuProgram* glprg = static_cast<GLSLGpuProgram*>(bindingPrg);
 		GLSLGpuProgram* glprg = static_cast<GLSLGpuProgram*>(bindingPrg);
 
 
 		// Unbind previous gpu program first.
 		// Unbind previous gpu program first.
@@ -1983,11 +1990,6 @@ namespace CamelotEngine
 			GLEW_EXT_geometry_shader4)
 			GLEW_EXT_geometry_shader4)
 		{
 		{
 			rsc->setCapability(RSC_GEOMETRY_PROGRAM);
 			rsc->setCapability(RSC_GEOMETRY_PROGRAM);
-			rsc->addShaderProfile("nvgp4");
-
-			//Also add the CG profiles
-			rsc->addShaderProfile("gpu_gp");
-			rsc->addShaderProfile("gp4gp");
 
 
 			rsc->setGeometryProgramConstantBoolCount(0);
 			rsc->setGeometryProgramConstantBoolCount(0);
 			rsc->setGeometryProgramConstantIntCount(0);
 			rsc->setGeometryProgramConstantIntCount(0);
@@ -2016,11 +2018,7 @@ namespace CamelotEngine
 			// Check for dxt compression
 			// Check for dxt compression
 			if(GLEW_EXT_texture_compression_s3tc)
 			if(GLEW_EXT_texture_compression_s3tc)
 			{
 			{
-#if defined(__APPLE__) && defined(__PPC__)
-				// Apple on ATI & PPC has errors in DXT
-				if (mGLSupport->getGLVendor().find("ATI") == std::string::npos)
-#endif
-					rsc->setCapability(RSC_TEXTURE_COMPRESSION_DXT);
+				rsc->setCapability(RSC_TEXTURE_COMPRESSION_DXT);
 			}
 			}
 			// Check for vtc compression
 			// Check for vtc compression
 			if(GLEW_NV_texture_compression_vtc)
 			if(GLEW_NV_texture_compression_vtc)
@@ -2190,6 +2188,42 @@ namespace CamelotEngine
 		// Mipmap LOD biasing
 		// Mipmap LOD biasing
 		rsc->setCapability(RSC_MIPMAP_LOD_BIAS);
 		rsc->setCapability(RSC_MIPMAP_LOD_BIAS);
 
 
+		// These are Cg supported profiles, not really used in OpenGL itself in any way
+		rsc->addShaderProfile("glslf");
+		rsc->addShaderProfile("glslv");
+		rsc->addShaderProfile("glslg");
+
+		rsc->addGpuProgramProfile(GPP_PS_1_1, "glslf");
+		rsc->addGpuProgramProfile(GPP_PS_1_2, "glslf");
+		rsc->addGpuProgramProfile(GPP_PS_1_3, "glslf");
+		rsc->addGpuProgramProfile(GPP_PS_1_4, "glslf");
+		rsc->addGpuProgramProfile(GPP_PS_2_0, "glslf");
+		rsc->addGpuProgramProfile(GPP_PS_2_x, "glslf");
+		rsc->addGpuProgramProfile(GPP_PS_2_a, "glslf");
+		rsc->addGpuProgramProfile(GPP_PS_2_b, "glslf");
+		rsc->addGpuProgramProfile(GPP_PS_3_0, "glslf");
+		rsc->addGpuProgramProfile(GPP_PS_3_x, "glslf");
+
+		rsc->addGpuProgramProfile(GPP_VS_1_1, "glslv");
+		rsc->addGpuProgramProfile(GPP_VS_2_0, "glslv");
+		rsc->addGpuProgramProfile(GPP_VS_2_x, "glslv");
+		rsc->addGpuProgramProfile(GPP_VS_2_a, "glslv");
+		rsc->addGpuProgramProfile(GPP_VS_3_0, "glslv");
+
+		rsc->addGpuProgramProfile(GPP_PS_4_0, "glslf");
+		rsc->addGpuProgramProfile(GPP_VS_4_0, "glslv");
+		rsc->addGpuProgramProfile(GPP_GS_4_0, "glslg");
+
+		rsc->addGpuProgramProfile(GPP_PS_4_0, "glslf");
+		rsc->addGpuProgramProfile(GPP_VS_4_0, "glslv");
+		rsc->addGpuProgramProfile(GPP_GS_4_0, "glslg");
+
+		rsc->addGpuProgramProfile(GPP_PS_4_1, "glslf");
+		rsc->addGpuProgramProfile(GPP_VS_4_1, "glslv");
+		rsc->addGpuProgramProfile(GPP_GS_4_1, "glslg");
+
+		// No SM5 support for Cg as right now it only supports NV extensions, which isn't very useful
+
 		// Alpha to coverage?
 		// Alpha to coverage?
 		if (mGLSupport->checkExtension("GL_ARB_multisample"))
 		if (mGLSupport->checkExtension("GL_ARB_multisample"))
 		{
 		{

+ 19 - 29
CamelotRenderer/Include/CmCgProgram.h

@@ -35,12 +35,9 @@ THE SOFTWARE.
 namespace CamelotEngine {
 namespace CamelotEngine {
     /** Specialisation of HighLevelGpuProgram to provide support for nVidia's CG language.
     /** Specialisation of HighLevelGpuProgram to provide support for nVidia's CG language.
     @remarks
     @remarks
-        Cg can be used to compile common, high-level, C-like code down to assembler
-        language for both GL and Direct3D, for multiple graphics cards. You must
-        supply a list of profiles which your program must support using
-        setProfiles() before the program is loaded in order for this to work. The
-        program will then negotiate with the renderer to compile the appropriate program
-        for the API and graphics card capabilities.
+        In its current state Cg only acts as a translator and internally creates either a HLSL
+		or a GLSL object. Cg doesn't support SM5 for GLSL (only Nvidia cards are supported,
+		which makes it very much useless for majority of projects).
     */
     */
     class CM_EXPORT CgProgram : public HighLevelGpuProgram
     class CM_EXPORT CgProgram : public HighLevelGpuProgram
     {
     {
@@ -49,17 +46,20 @@ namespace CamelotEngine {
 
 
         /** Gets the entry point defined for this program. */
         /** Gets the entry point defined for this program. */
         const String& getEntryPoint(void) const { return mEntryPoint; }
         const String& getEntryPoint(void) const { return mEntryPoint; }
-        /** Sets the compilation arguments for this program ie the first method called. */
-        void setCompileArguments(const String& args) { mCompileArgs = args; }
-        /** Gets the entry point defined for this program. */
-        const String& getCompileArguments(void) const { return mCompileArgs; }
         /// Overridden from GpuProgram
         /// Overridden from GpuProgram
         bool isSupported(void) const;
         bool isSupported(void) const;
         /// Overridden from GpuProgram
         /// Overridden from GpuProgram
         const String& getLanguage(void) const;
         const String& getLanguage(void) const;
 
 
-		/// scan the file for #include and replace with source from the OGRE resources
-		static String resolveCgIncludes(const String& source, Resource* resourceBeingLoaded, const String& fileName);
+		/**
+		 * @copydoc HighLevelGpuProgram::getBindingDelegate().
+		 */
+		GpuProgram* getBindingDelegate();
+
+		/**
+		 * @copydoc HighLevelGpuProgram::createParameters().
+		 */
+		GpuParamsPtr createParameters();
 
 
     protected:
     protected:
 		friend class CgProgramFactory;
 		friend class CgProgramFactory;
@@ -68,6 +68,8 @@ namespace CamelotEngine {
         CGcontext mCgContext;
         CGcontext mCgContext;
         /// Program handle
         /// Program handle
         CGprogram mCgProgram;
         CGprogram mCgProgram;
+		String mSelectedProfile;
+		CGprofile mSelectedCgProfile;
 
 
 		CgProgram(CGcontext context, const String& source, const String& entryPoint, const String& language, 
 		CgProgram(CGcontext context, const String& source, const String& entryPoint, const String& language, 
 			GpuProgramType gptype, GpuProgramProfile profile, bool isAdjacencyInfoRequired = false);
 			GpuProgramType gptype, GpuProgramProfile profile, bool isAdjacencyInfoRequired = false);
@@ -79,27 +81,15 @@ namespace CamelotEngine {
 		 * @copydoc GpuProgram::unload_internal()
 		 * @copydoc GpuProgram::unload_internal()
 		 */
 		 */
         void unload_internal(void);
         void unload_internal(void);
-        /// Populate the passed parameters with name->index map, must be overridden
-        void buildConstantDefinitions() const;
-
-		/// Recurse down structures getting data on parameters
-		void recurseParams(CGparameter param, UINT32 contextArraySize = 1) const;
-		/// Turn a Cg type into a GpuConstantType and number of elements
-		void mapTypeAndElementSize(CGtype cgType, bool isRegisterCombiner, GpuConstantDefinition& def) const;
 
 
-        String mSelectedProfile;
-        CGprofile mSelectedCgProfile;
-        String mCompileArgs;
-        // Unfortunately Cg uses char** for arguments - bleh
-        // This is a null-terminated list of char* (each null terminated)
-        char** mCgArguments;
+		/**
+		 * @brief	Cg acts only like a wrapper to a rendersystem specific program.
+		 * 			This returns the actual program we are wrapping.
+		 */
+		HighLevelGpuProgramPtr getWrappedProgram() const;
 
 
         /// Internal method which works out which profile to use for this program
         /// Internal method which works out which profile to use for this program
         void selectProfile(void);
         void selectProfile(void);
-        /// Internal method which merges manual and automatic compile arguments
-        void buildArgs(void);
-        /// Releases memory for the horrible Cg char**
-        void freeCgArgs(void);
 
 
 		/************************************************************************/
 		/************************************************************************/
 		/* 								SERIALIZATION                      		*/
 		/* 								SERIALIZATION                      		*/

+ 4 - 1
CamelotRenderer/Include/CmGpuProgram.h

@@ -68,6 +68,7 @@ namespace CamelotEngine {
 		GPP_PS_3_0,
 		GPP_PS_3_0,
 		GPP_PS_3_x,
 		GPP_PS_3_x,
 		GPP_PS_4_0,
 		GPP_PS_4_0,
+		GPP_PS_4_1,
 		GPP_PS_5_0,
 		GPP_PS_5_0,
 		GPP_VS_1_1,
 		GPP_VS_1_1,
 		GPP_VS_2_0,
 		GPP_VS_2_0,
@@ -75,8 +76,10 @@ namespace CamelotEngine {
 		GPP_VS_2_a,
 		GPP_VS_2_a,
 		GPP_VS_3_0,
 		GPP_VS_3_0,
 		GPP_VS_4_0,
 		GPP_VS_4_0,
+		GPP_VS_4_1,
 		GPP_VS_5_0,
 		GPP_VS_5_0,
 		GPP_GS_4_0,
 		GPP_GS_4_0,
+		GPP_GS_4_1,
 		GPP_GS_5_0,
 		GPP_GS_5_0,
 		GPP_HS_5_0,
 		GPP_HS_5_0,
 		GPP_DS_5_0,
 		GPP_DS_5_0,
@@ -159,7 +162,7 @@ namespace CamelotEngine {
         @remarks
         @remarks
             This method is simply to allow some subclasses of GpuProgram to delegate
             This method is simply to allow some subclasses of GpuProgram to delegate
             the program which is bound to the pipeline to a delegate, if required. */
             the program which is bound to the pipeline to a delegate, if required. */
-        virtual GpuProgram* getBindingDelegate_internal(void) { return this; }
+        virtual GpuProgram* getBindingDelegate(void) { return this; }
 
 
         /** Returns whether this program can be supported on the current renderer and hardware. */
         /** Returns whether this program can be supported on the current renderer and hardware. */
         virtual bool isSupported(void) const;
         virtual bool isSupported(void) const;

+ 12 - 6
CamelotRenderer/Include/CmHighLevelGpuProgram.h

@@ -66,12 +66,18 @@ namespace CamelotEngine {
         ~HighLevelGpuProgram();
         ~HighLevelGpuProgram();
 
 
 		/**
 		/**
-		 * @brief	Initializes the gpu program. This must be called right after the program is constructed. 
-		 * 			Called by HighLevelGpuManager upon creation, so usually you don't want to call this manually.
-		 * 			
-		 * @note	Initialization is not done immediately, and is instead just scheduled on the render thread.
+		 * @brief	Initializes the gpu program. This must be called right after the program is
+		 * 			constructed. Called by HighLevelGpuManager upon creation, so usually you don't want
+		 * 			to call this manually.
+		 *		 
+		 * @param	internalCall	(optional) Set to true if initializing from within the RenderSystem.
+		 * 							Most users don't have to be concerned about this.
+		 * 							
+		 * @note	Initialization is not done immediately, and is instead just scheduled on the
+		 * 			render thread. Unless internalCall is specified, in which case it is initialized
+		 * 			right away.
 		 */
 		 */
-		void initialize();
+		void initialize(bool internalCall = false);
 
 
 		/**
 		/**
 		 * @brief	Performs HighLevelGpuProgram initialization. Only callable from the render thread.
 		 * @brief	Performs HighLevelGpuProgram initialization. Only callable from the render thread.
@@ -84,7 +90,7 @@ namespace CamelotEngine {
 		virtual void unload_internal();
 		virtual void unload_internal();
 
 
         /** @copydoc GpuProgram::getBindingDelegate */
         /** @copydoc GpuProgram::getBindingDelegate */
-        GpuProgram* getBindingDelegate_internal(void) { return mAssemblerProgram.get(); }
+        virtual GpuProgram* getBindingDelegate(void) { return mAssemblerProgram.get(); }
 
 
     protected:
     protected:
 		/** Constructor, should be used only by factory classes. */
 		/** Constructor, should be used only by factory classes. */

+ 6 - 2
CamelotRenderer/Include/CmHighLevelGpuProgramManager.h

@@ -100,16 +100,20 @@ namespace CamelotEngine {
             to be a member of
             to be a member of
 		@param language Code of the language to use (e.g. "cg")
 		@param language Code of the language to use (e.g. "cg")
 		@param gptype The type of program to create
 		@param gptype The type of program to create
+		* @param	internalCall	(optional) Set to true if calling this method from within the RenderSystem.
+		* 							Most users don't have to be concerned about this.
 		*/
 		*/
-		HighLevelGpuProgramPtr create(const String& source, const String& entryPoint, const String& language, GpuProgramType gptype, GpuProgramProfile profile);
+		HighLevelGpuProgramPtr create(const String& source, const String& entryPoint, const String& language, GpuProgramType gptype, GpuProgramProfile profile, bool internalCall = false);
 
 
 		/** Create a new HighLevelGpuProgram. 
 		/** Create a new HighLevelGpuProgram. 
 		@par
 		@par
 			This method creates a new program of the specified language. You need to set other 
 			This method creates a new program of the specified language. You need to set other 
 			properties like source, entry point, type, profile manually.
 			properties like source, entry point, type, profile manually.
 		@param language Code of the language to use (e.g. "cg")
 		@param language Code of the language to use (e.g. "cg")
+		* @param	internalCall	(optional) Set to true if calling this method from within the RenderSystem.
+		* 							Most users don't have to be concerned about this.
 		*/
 		*/
-		HighLevelGpuProgramPtr create(const String& language);
+		HighLevelGpuProgramPtr create(const String& language, bool internalCall = false);
 
 
 		/**
 		/**
 		 * @brief	Creates a completely empty and uninitialized HighLevelGpuProgram.
 		 * @brief	Creates a completely empty and uninitialized HighLevelGpuProgram.

+ 5 - 0
CamelotRenderer/Include/CmRenderSystem.h

@@ -90,6 +90,11 @@ namespace CamelotEngine
 		*/
 		*/
 		virtual const String& getName(void) const = 0;
 		virtual const String& getName(void) const = 0;
 
 
+		/**
+		 * @brief	Gets the name of the primary shading language.
+		 */
+		virtual const String& getShadingLanguageName() const = 0;
+
 		/** Attaches the passed render target to the render system.
 		/** Attaches the passed render target to the render system.
 		*/
 		*/
 		virtual void attachRenderTarget(RenderTarget &target);
 		virtual void attachRenderTarget(RenderTarget &target);

+ 1 - 3
CamelotRenderer/Include/CmTexture.h

@@ -63,9 +63,7 @@ namespace CamelotEngine {
         /// 3D volume texture, used in combination with 3D texture coordinates
         /// 3D volume texture, used in combination with 3D texture coordinates
         TEX_TYPE_3D = 3,
         TEX_TYPE_3D = 3,
         /// 3D cube map, used in combination with 3D texture coordinates
         /// 3D cube map, used in combination with 3D texture coordinates
-        TEX_TYPE_CUBE_MAP = 4,
-		// Array of 2D textures,
-		TEX_TYPE_2D_ARRAY = 5
+        TEX_TYPE_CUBE_MAP = 4
     };
     };
 
 
 	/** Enum identifying special mipmap numbers
 	/** Enum identifying special mipmap numbers

+ 37 - 479
CamelotRenderer/Source/CmCgProgram.cpp

@@ -28,6 +28,7 @@ THE SOFTWARE.
 #include "CmCgProgram.h"
 #include "CmCgProgram.h"
 #include "CmGpuProgramManager.h"
 #include "CmGpuProgramManager.h"
 #include "CmHighLevelGpuProgramManager.h"
 #include "CmHighLevelGpuProgramManager.h"
+#include "CmRenderSystem.h"
 #include "CmDebug.h"
 #include "CmDebug.h"
 #include "CmException.h"
 #include "CmException.h"
 #include "CmCgProgramRTTI.h"
 #include "CmCgProgramRTTI.h"
@@ -56,6 +57,9 @@ namespace CamelotEngine {
         mSelectedProfile.clear();
         mSelectedProfile.clear();
         mSelectedCgProfile = CG_PROFILE_UNKNOWN;
         mSelectedCgProfile = CG_PROFILE_UNKNOWN;
 
 
+		RenderSystem* rs = RenderSystem::instancePtr();
+		const String& rsName = rs->getName();
+
 		mSelectedProfile = GpuProgramManager::instance().gpuProgProfileToRSSpecificProfile(mProfile);
 		mSelectedProfile = GpuProgramManager::instance().gpuProgProfileToRSSpecificProfile(mProfile);
 		GpuProgramManager& gpuMgr = GpuProgramManager::instance();
 		GpuProgramManager& gpuMgr = GpuProgramManager::instance();
 		if (gpuMgr.isSyntaxSupported(mSelectedProfile))
 		if (gpuMgr.isSyntaxSupported(mSelectedProfile))
@@ -69,85 +73,22 @@ namespace CamelotEngine {
 			mSelectedProfile.clear();
 			mSelectedProfile.clear();
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
-    void CgProgram::buildArgs(void)
-    {
-        vector<String>::type args;
-        if (!mCompileArgs.empty())
-            args = StringUtil::split(mCompileArgs);
-
-        vector<String>::type::const_iterator i;
-        if (mSelectedCgProfile == CG_PROFILE_VS_1_1)
-        {
-            // Need the 'dcls' argument whenever we use this profile
-            // otherwise compilation of the assembler will fail
-            bool dclsFound = false;
-            for (i = args.begin(); i != args.end(); ++i)
-            {
-                if (*i == "dcls")
-                {
-                    dclsFound = true;
-                    break;
-                }
-            }
-            if (!dclsFound)
-            {
-                args.push_back("-profileopts");
-				args.push_back("dcls");
-            }
-        }
-        // Now split args into that god-awful char** that Cg insists on
-        freeCgArgs();
-        mCgArguments = (char**)malloc(sizeof(char*) * (args.size() + 1));
-        int index = 0;
-        for (i = args.begin(); i != args.end(); ++i, ++index)
-        {
-            mCgArguments[index] = (char*)malloc(sizeof(char) * (i->length() + 1));
-            strcpy(mCgArguments[index], i->c_str());
-        }
-        // Null terminate list
-        mCgArguments[index] = 0;
-
-
-    }
-    //-----------------------------------------------------------------------
-    void CgProgram::freeCgArgs(void)
-    {
-        if (mCgArguments)
-        {
-            size_t index = 0;
-            char* current = mCgArguments[index];
-            while (current)
-            {
-				free(current);
-				mCgArguments[index] = 0;
-                current = mCgArguments[++index];
-            }
-			free(mCgArguments);
-            mCgArguments = 0;
-        }
-    }
-    //-----------------------------------------------------------------------
     void CgProgram::loadFromSource(void)
     void CgProgram::loadFromSource(void)
     {
     {
         // Create Cg Program
         // Create Cg Program
         selectProfile();
         selectProfile();
 		if (mSelectedCgProfile == CG_PROFILE_UNKNOWN)
 		if (mSelectedCgProfile == CG_PROFILE_UNKNOWN)
 		{
 		{
-			gDebug().log("Attempted to load Cg program but no supported "
-				"profile was found.", "RenderSystem");
+			LOGWRN("Attempted to load Cg program but no supported profile was found.");
 			return;
 			return;
 		}
 		}
-        buildArgs();
 
 
 		// TODO PORT - This doesn't load includes
 		// TODO PORT - This doesn't load includes
 		// deal with includes
 		// deal with includes
 		String sourceToUse = mSource;
 		String sourceToUse = mSource;
 		//String sourceToUse = resolveCgIncludes(mSource, this, mFilename);
 		//String sourceToUse = resolveCgIncludes(mSource, this, mFilename);
         mCgProgram = cgCreateProgram(mCgContext, CG_SOURCE, sourceToUse.c_str(), 
         mCgProgram = cgCreateProgram(mCgContext, CG_SOURCE, sourceToUse.c_str(), 
-            mSelectedCgProfile, mEntryPoint.c_str(), const_cast<const char**>(mCgArguments));
-
-        // Test
-        //LogManager::getSingleton().logMessage(cgGetProgramString(mCgProgram, CG_COMPILED_PROGRAM));
+            mSelectedCgProfile, mEntryPoint.c_str(), nullptr);
 
 
         // Check for errors
         // Check for errors
         checkForCgError("CgProgram::loadFromSource", 
         checkForCgError("CgProgram::loadFromSource", 
@@ -156,330 +97,61 @@ namespace CamelotEngine {
 		// ignore any previous error
 		// ignore any previous error
 		if (mSelectedCgProfile != CG_PROFILE_UNKNOWN && !mCompileError)
 		if (mSelectedCgProfile != CG_PROFILE_UNKNOWN && !mCompileError)
 		{
 		{
-			if (mSelectedCgProfile == CG_PROFILE_VS_4_0 || mSelectedCgProfile == CG_PROFILE_PS_4_0)
-			{
-				String hlslSourceFromCg = cgGetProgramString(mCgProgram, CG_COMPILED_PROGRAM);
-
-				// Create a high-level program, give it the same name as us
-				HighLevelGpuProgramPtr vp = 
-					HighLevelGpuProgramManager::instance().create(
-					hlslSourceFromCg, "main", "hlsl", mType, mProfile);
+			String sourceFromCg = cgGetProgramString(mCgProgram, CG_COMPILED_PROGRAM);
 
 
-				vp->initialize();
+			// Create a low-level program, give it the same name as us
+			mAssemblerProgram = 
+				HighLevelGpuProgramManager::instance().create(
+				sourceFromCg, mEntryPoint, RenderSystem::instance().getShadingLanguageName(), mType, mProfile, true);
 
 
-				mAssemblerProgram = vp;
-			}
-			else
-			{
-
-				String shaderAssemblerCode = cgGetProgramString(mCgProgram, CG_COMPILED_PROGRAM);
-
-				// Create a low-level program, give it the same name as us
-				mAssemblerProgram = 
-					GpuProgramManager::instance().createProgram(
-					shaderAssemblerCode, "", mSelectedProfile,
-					mType, 
-					GPP_NONE);
-			}
 			// Shader params need to be forwarded to low level implementation
 			// Shader params need to be forwarded to low level implementation
 			mAssemblerProgram->setAdjacencyInfoRequired(isAdjacencyInfoRequired());
 			mAssemblerProgram->setAdjacencyInfoRequired(isAdjacencyInfoRequired());
 		}
 		}
+
+		cgDestroyProgram(mCgProgram);
+		checkForCgError("CgProgram::unloadImpl", "Error while unloading Cg program", mCgContext);
+		mCgProgram = nullptr;
     }
     }
-    //-----------------------------------------------------------------------
+
     void CgProgram::unload_internal(void)
     void CgProgram::unload_internal(void)
     {
     {
-        // Unload Cg Program
-        // Lowlevel program will get unloaded elsewhere
-        if (mCgProgram)
-        {
-            cgDestroyProgram(mCgProgram);
-            checkForCgError("CgProgram::unloadImpl", 
-                "Error while unloading Cg program", 
-                mCgContext);
-            mCgProgram = 0;
-        }
-
 		HighLevelGpuProgram::unload_internal();
 		HighLevelGpuProgram::unload_internal();
     }
     }
-    //-----------------------------------------------------------------------
-    void CgProgram::buildConstantDefinitions() const
-    {
-        // Derive parameter names from Cg
-		//createParameterMappingStructures(true);
-
-		if (!mCgProgram)
-			return;
 
 
-		recurseParams(cgGetFirstParameter(mCgProgram, CG_PROGRAM));
-        recurseParams(cgGetFirstParameter(mCgProgram, CG_GLOBAL));
+	GpuParamsPtr CgProgram::createParameters()
+	{
+		return getWrappedProgram()->createParameters();
 	}
 	}
-	//---------------------------------------------------------------------
-	void CgProgram::recurseParams(CGparameter parameter, UINT32 contextArraySize) const
+
+	GpuProgram* CgProgram::getBindingDelegate(void)
 	{
 	{
-		//while (parameter != 0)
-  //      {
-  //          // Look for parameters
-  //          // Don't bother enumerating unused parameters, especially since they will
-  //          // be optimised out and therefore not in the indexed versions
-  //          CGtype paramType = cgGetParameterType(parameter);
-
-  //          if (cgGetParameterVariability(parameter) == CG_UNIFORM &&
-  //              paramType != CG_SAMPLERRECT &&
-  //              cgGetParameterDirection(parameter) != CG_OUT && 
-  //              cgIsParameterReferenced(parameter))
-  //          {
-		//		int arraySize;
-
-		//		switch(paramType)
-		//		{
-		//		case CG_STRUCT:
-		//			recurseParams(cgGetFirstStructParameter(parameter));
-		//			break;
-		//		case CG_ARRAY:
-		//			// Support only 1-dimensional arrays
-		//			arraySize = cgGetArraySize(parameter, 0);
-		//			recurseParams(cgGetArrayParameter(parameter, 0), (size_t)arraySize);
-		//			break;
-		//		default:
-		//			// Normal path (leaf)
-		//			String paramName = cgGetParameterName(parameter);
-		//			UINT32 logicalIndex = (UINT32)cgGetParameterResourceIndex(parameter);
-
-		//			// Get the parameter resource, to calculate the physical index
-		//			CGresource res = cgGetParameterResource(parameter);
-		//			bool isRegisterCombiner = false;
-		//			UINT32 regCombinerPhysicalIndex = 0;
-		//			switch (res)
-		//			{
-		//			case CG_COMBINER_STAGE_CONST0:
-		//				// register combiner, const 0
-		//				// the index relates to the texture stage; store this as (stage * 2) + 0
-		//				regCombinerPhysicalIndex = logicalIndex * 2;
-		//				isRegisterCombiner = true;
-		//				break;
-		//			case CG_COMBINER_STAGE_CONST1:
-		//				// register combiner, const 1
-		//				// the index relates to the texture stage; store this as (stage * 2) + 1
-		//				regCombinerPhysicalIndex = (logicalIndex * 2) + 1;
-		//				isRegisterCombiner = true;
-		//				break;
-		//			default:
-		//				// normal constant
-		//				break;
-		//			}
-
-		//			// Trim the '[0]' suffix if it exists, we will add our own indexing later
-		//			if (StringUtil::endsWith(paramName, "[0]", false))
-		//			{
-		//				paramName.erase(paramName.size() - 3);
-		//			}
-
-
-		//			GpuConstantDefinition def;
-		//			def.arraySize = contextArraySize;
-		//			mapTypeAndElementSize(paramType, isRegisterCombiner, def);
-
-		//			if (def.constType == GCT_UNKNOWN)
-		//			{
-		//				gDebug().log("Problem parsing the following Cg Uniform: '" + paramName + "'", "RenderSystem");
-		//				// next uniform
-		//				parameter = cgGetNextParameter(parameter);
-		//				continue;
-		//			}
-		//			if (isRegisterCombiner)
-		//			{
-		//				def.physicalIndex = regCombinerPhysicalIndex;
-		//			}
-		//			else
-		//			{
-		//				// base position on existing buffer contents
-		//				if(def.isSampler())
-		//				{
-		//					def.physicalIndex = mSamplerLogicalToPhysical->bufferSize;
-		//				}
-		//				else
-		//				{
-		//					if (def.isFloat())
-		//					{
-		//						def.physicalIndex = mFloatLogicalToPhysical->bufferSize;
-		//					}
-		//					else
-		//					{
-		//						def.physicalIndex = mIntLogicalToPhysical->bufferSize;
-		//					}
-		//				}
-		//			}
-
-		//			def.logicalIndex = logicalIndex;
-		//			mConstantDefs->map.insert(GpuConstantDefinitionMap::value_type(paramName, def));
-
-		//			// Record logical / physical mapping
-		//			if(def.isSampler())
-		//			{
-		//				mSamplerLogicalToPhysical->map.insert(
-		//					GpuLogicalIndexUseMap::value_type(logicalIndex, 
-		//					GpuLogicalIndexUse(def.physicalIndex, def.arraySize, GPV_GLOBAL)));
-		//				mSamplerLogicalToPhysical->bufferSize += def.arraySize;
-		//				mConstantDefs->samplerCount = mSamplerLogicalToPhysical->bufferSize;
-
-		//				mTextureLogicalToPhysical->map.insert(
-		//					GpuLogicalIndexUseMap::value_type(logicalIndex, 
-		//					GpuLogicalIndexUse(def.physicalIndex, def.arraySize, GPV_GLOBAL)));
-		//				mTextureLogicalToPhysical->bufferSize += def.arraySize;
-		//				mConstantDefs->textureCount = mTextureLogicalToPhysical->bufferSize;
-		//			}
-		//			else
-		//			{
-		//				if (def.isFloat())
-		//				{
-		//					mFloatLogicalToPhysical->map.insert(
-		//						GpuLogicalIndexUseMap::value_type(logicalIndex, 
-		//						GpuLogicalIndexUse(def.physicalIndex, def.arraySize * def.elementSize, GPV_GLOBAL)));
-		//					mFloatLogicalToPhysical->bufferSize += def.arraySize * def.elementSize;
-		//					mConstantDefs->floatBufferSize = mFloatLogicalToPhysical->bufferSize;
-		//				}
-		//				else
-		//				{
-		//					mIntLogicalToPhysical->map.insert(
-		//						GpuLogicalIndexUseMap::value_type(logicalIndex, 
-		//						GpuLogicalIndexUse(def.physicalIndex, def.arraySize * def.elementSize, GPV_GLOBAL)));
-		//					mIntLogicalToPhysical->bufferSize += def.arraySize * def.elementSize;
-		//					mConstantDefs->intBufferSize = mIntLogicalToPhysical->bufferSize;
-		//				}
-		//			}
-
-		//			// Deal with array indexing
-		//			mConstantDefs->generateConstantDefinitionArrayEntries(paramName, def);
-
-		//			break;
-		//
-		//		}
-		//			
-  //          }
-  //          // Get next
-  //          parameter = cgGetNextParameter(parameter);
-  //      }
-
-        
-    }
-	//-----------------------------------------------------------------------
-	void CgProgram::mapTypeAndElementSize(CGtype cgType, bool isRegisterCombiner, 
-		GpuConstantDefinition& def) const
+		if(mAssemblerProgram)
+			return getWrappedProgram()->getBindingDelegate();
+
+		return nullptr;
+	}
+
+	HighLevelGpuProgramPtr CgProgram::getWrappedProgram() const
 	{
 	{
-		if (isRegisterCombiner)
-		{
-			// register combiners are the only single-float entries in our buffer
-			def.constType = GCT_FLOAT1;
-			def.elementSize = 1;
-		}
-		else
-		{
-			switch(cgType)
-			{
-			case CG_SAMPLER1D:
-				def.constType = GCT_SAMPLER1D;
-				break;
-			case CG_SAMPLER2D:
-				def.constType = GCT_SAMPLER2D;
-				break;
-			case CG_SAMPLER3D:
-				def.constType = GCT_SAMPLER3D;
-				break;
-			case CG_SAMPLERCUBE:
-				def.constType = GCT_SAMPLERCUBE;
-				break;
-			case CG_FLOAT:
-			case CG_FLOAT1:
-			case CG_HALF:
-			case CG_HALF1:
-				def.constType = GCT_FLOAT1;
-				break;
-			case CG_FLOAT2:
-			case CG_HALF2:
-				def.constType = GCT_FLOAT2;
-				break;
-			case CG_FLOAT3:
-			case CG_HALF3:
-				def.constType = GCT_FLOAT3;
-				break;
-			case CG_FLOAT4:
-			case CG_HALF4:
-				def.constType = GCT_FLOAT4;
-				break;
-			case CG_FLOAT2x2:
-			case CG_HALF2x2:
-				def.constType = GCT_MATRIX_2X2;
-				break;
-			case CG_FLOAT2x3:
-			case CG_HALF2x3:
-				def.constType = GCT_MATRIX_2X3;
-				break;
-			case CG_FLOAT2x4:
-			case CG_HALF2x4:
-				def.constType = GCT_MATRIX_2X4;
-				break;
-			case CG_FLOAT3x2:
-			case CG_HALF3x2:
-				def.constType = GCT_MATRIX_3X2;
-				break;
-			case CG_FLOAT3x3:
-			case CG_HALF3x3:
-				def.constType = GCT_MATRIX_3X3;
-				break;
-			case CG_FLOAT3x4:
-			case CG_HALF3x4:
-				def.constType = GCT_MATRIX_3X4;
-				break;
-			case CG_FLOAT4x2:
-			case CG_HALF4x2:
-				def.constType = GCT_MATRIX_4X2;
-				break;
-			case CG_FLOAT4x3:
-			case CG_HALF4x3:
-				def.constType = GCT_MATRIX_4X3;
-				break;
-			case CG_FLOAT4x4:
-			case CG_HALF4x4:
-				def.constType = GCT_MATRIX_4X4;
-				break;
-			case CG_INT:
-			case CG_INT1:
-				def.constType = GCT_INT1;
-				break;
-			case CG_INT2:
-				def.constType = GCT_INT2;
-				break;
-			case CG_INT3:
-				def.constType = GCT_INT3;
-				break;
-			case CG_INT4:
-				def.constType = GCT_INT4;
-				break;
-			default:
-				def.constType = GCT_UNKNOWN;
-				break;
-			}
-			// Cg pads
-			def.elementSize = GpuConstantDefinition::getElementSize(def.constType, true);
-		}
+		HighLevelGpuProgramPtr wrappedProgram = std::static_pointer_cast<HighLevelGpuProgram>(mAssemblerProgram);
+
+		return wrappedProgram;
 	}
 	}
-    //-----------------------------------------------------------------------
-		CgProgram::CgProgram(CGcontext context, const String& source, const String& entryPoint, const String& language, 
+
+	CgProgram::CgProgram(CGcontext context, const String& source, const String& entryPoint, const String& language, 
 			GpuProgramType gptype, GpuProgramProfile profile, bool isAdjacencyInfoRequired)
 			GpuProgramType gptype, GpuProgramProfile profile, bool isAdjacencyInfoRequired)
         : HighLevelGpuProgram(source, entryPoint, language, gptype, profile, isAdjacencyInfoRequired), 
         : HighLevelGpuProgram(source, entryPoint, language, gptype, profile, isAdjacencyInfoRequired), 
         mCgContext(context), mCgProgram(0), 
         mCgContext(context), mCgProgram(0), 
-        mSelectedCgProfile(CG_PROFILE_UNKNOWN), mCgArguments(0)
+        mSelectedCgProfile(CG_PROFILE_UNKNOWN)
     {
     {
 
 
     }
     }
-    //-----------------------------------------------------------------------
+
     CgProgram::~CgProgram()
     CgProgram::~CgProgram()
     {
     {
-        freeCgArgs();
-
         unload_internal();
         unload_internal();
     }
     }
-    //-----------------------------------------------------------------------
+
     bool CgProgram::isSupported(void) const
     bool CgProgram::isSupported(void) const
     {
     {
         if (mCompileError || !isRequiredCapabilitiesSupported())
         if (mCompileError || !isRequiredCapabilitiesSupported())
@@ -491,121 +163,7 @@ namespace CamelotEngine {
 
 
         return false;
         return false;
     }
     }
-	//-----------------------------------------------------------------------
-	String CgProgram::resolveCgIncludes(const String& inSource, Resource* resourceBeingLoaded, const String& fileName)
-	{
-		String outSource;
-		// TODO PORT - Includes are not handled ATM
-		// output will be at least this big
-		//outSource.reserve(inSource.length());
-
-		//size_t startMarker = 0;
-		//size_t i = inSource.find("#include");
-		//while (i != String::npos)
-		//{
-		//	size_t includePos = i;
-		//	size_t afterIncludePos = includePos + 8;
-		//	size_t newLineBefore = inSource.rfind("\n", includePos);
-
-		//	// check we're not in a comment
-		//	size_t lineCommentIt = inSource.rfind("//", includePos);
-		//	if (lineCommentIt != String::npos)
-		//	{
-		//		if (newLineBefore == String::npos || lineCommentIt > newLineBefore)
-		//		{
-		//			// commented
-		//			i = inSource.find("#include", afterIncludePos);
-		//			continue;
-		//		}
-
-		//	}
-		//	size_t blockCommentIt = inSource.rfind("/*", includePos);
-		//	if (blockCommentIt != String::npos)
-		//	{
-		//		size_t closeCommentIt = inSource.rfind("*/", includePos);
-		//		if (closeCommentIt == String::npos || closeCommentIt < blockCommentIt)
-		//		{
-		//			// commented
-		//			i = inSource.find("#include", afterIncludePos);
-		//			continue;
-		//		}
-
-		//	}
-
-		//	// find following newline (or EOF)
-		//	size_t newLineAfter = inSource.find("\n", afterIncludePos);
-		//	// find include file string container
-		//	String endDelimeter = "\"";
-		//	size_t startIt = inSource.find("\"", afterIncludePos);
-		//	if (startIt == String::npos || startIt > newLineAfter)
-		//	{
-		//		// try <>
-		//		startIt = inSource.find("<", afterIncludePos);
-		//		if (startIt == String::npos || startIt > newLineAfter)
-		//		{
-		//			CM_EXCEPT(InternalErrorException,
-		//				"Badly formed #include directive (expected \" or <) in file "
-		//				+ fileName + ": " + inSource.substr(includePos, newLineAfter-includePos));
-		//		}
-		//		else
-		//		{
-		//			endDelimeter = ">";
-		//		}
-		//	}
-		//	size_t endIt = inSource.find(endDelimeter, startIt+1);
-		//	if (endIt == String::npos || endIt <= startIt)
-		//	{
-		//		CM_EXCEPT(InternalErrorException,
-		//			"Badly formed #include directive (expected " + endDelimeter + ") in file "
-		//			+ fileName + ": " + inSource.substr(includePos, newLineAfter-includePos));
-		//	}
-
-		//	// extract filename
-		//	String filename(inSource.substr(startIt+1, endIt-startIt-1));
-
-		//	// open included file
-		//	DataStreamPtr resource = ResourceGroupManager::getSingleton().
-		//		openResource(filename, resourceBeingLoaded->getGroup(), true, resourceBeingLoaded);
-
-		//	// replace entire include directive line
-		//	// copy up to just before include
-		//	if (newLineBefore != String::npos && newLineBefore >= startMarker)
-		//		outSource.append(inSource.substr(startMarker, newLineBefore-startMarker+1));
-
-		//	size_t lineCount = 0;
-		//	size_t lineCountPos = 0;
-		//	
-		//	// Count the line number of #include statement
-		//	lineCountPos = outSource.find('\n');
-		//	while(lineCountPos != String::npos)
-		//	{
-		//		lineCountPos = outSource.find('\n', lineCountPos+1);
-		//		lineCount++;
-		//	}
-
-		//	// Add #line to the start of the included file to correct the line count
-		//	outSource.append("#line 1 \"" + filename + "\"\n");
-
-		//	outSource.append(resource->getAsString());
-
-		//	// Add #line to the end of the included file to correct the line count
-		//	outSource.append("\n#line " + toString(lineCount) + 
-		//		"\"" + fileName + "\"\n");
-
-		//	startMarker = newLineAfter;
-
-		//	if (startMarker != String::npos)
-		//		i = inSource.find("#include", startMarker);
-		//	else
-		//		i = String::npos;
-
-		//}
-		//// copy any remaining characters
-		//outSource.append(inSource.substr(startMarker));
-
-		return outSource;
-	}
-    //-----------------------------------------------------------------------
+
     const String& CgProgram::getLanguage(void) const
     const String& CgProgram::getLanguage(void) const
     {
     {
         static const String language = "cg";
         static const String language = "cg";

+ 5 - 2
CamelotRenderer/Source/CmHighLevelGpuProgram.cpp

@@ -48,9 +48,12 @@ namespace CamelotEngine
     {
     {
     }
     }
 	//---------------------------------------------------------------------------
 	//---------------------------------------------------------------------------
-	void HighLevelGpuProgram::initialize()
+	void HighLevelGpuProgram::initialize(bool internalCall)
 	{
 	{
-		RenderSystem::instancePtr()->queueCommand(boost::bind(&HighLevelGpuProgram::initialize_internal, this));
+		if(internalCall)
+			initialize_internal();
+		else
+			RenderSystem::instancePtr()->queueCommand(boost::bind(&HighLevelGpuProgram::initialize_internal, this));
 	}
 	}
     //---------------------------------------------------------------------------
     //---------------------------------------------------------------------------
     void HighLevelGpuProgram::initialize_internal()
     void HighLevelGpuProgram::initialize_internal()

+ 5 - 4
CamelotRenderer/Source/CmHighLevelGpuProgramManager.cpp

@@ -146,20 +146,21 @@ namespace CamelotEngine {
 
 
 	}
 	}
     //---------------------------------------------------------------------------
     //---------------------------------------------------------------------------
-    HighLevelGpuProgramPtr HighLevelGpuProgramManager::create(const String& source, const String& entryPoint, const String& language, GpuProgramType gptype, GpuProgramProfile profile)
+    HighLevelGpuProgramPtr HighLevelGpuProgramManager::create(const String& source, const String& entryPoint, const String& language, 
+		GpuProgramType gptype, GpuProgramProfile profile, bool internalCall)
     {
     {
 		HighLevelGpuProgramFactory* factory = getFactory(language);
 		HighLevelGpuProgramFactory* factory = getFactory(language);
         HighLevelGpuProgramPtr ret = HighLevelGpuProgramPtr(factory->create(source, entryPoint, gptype, profile), boost::bind(&HighLevelGpuProgramFactory::destroy, factory, _1));
         HighLevelGpuProgramPtr ret = HighLevelGpuProgramPtr(factory->create(source, entryPoint, gptype, profile), boost::bind(&HighLevelGpuProgramFactory::destroy, factory, _1));
-		ret->initialize();
+		ret->initialize(internalCall);
 
 
         return ret;
         return ret;
     }
     }
 	//---------------------------------------------------------------------------
 	//---------------------------------------------------------------------------
-	HighLevelGpuProgramPtr HighLevelGpuProgramManager::create(const String& language)
+	HighLevelGpuProgramPtr HighLevelGpuProgramManager::create(const String& language, bool internalCall)
 	{
 	{
 		HighLevelGpuProgramFactory* factory = getFactory(language);
 		HighLevelGpuProgramFactory* factory = getFactory(language);
 		HighLevelGpuProgramPtr ret = HighLevelGpuProgramPtr(factory->create(), boost::bind(&HighLevelGpuProgramFactory::destroy, factory, _1));
 		HighLevelGpuProgramPtr ret = HighLevelGpuProgramPtr(factory->create(), boost::bind(&HighLevelGpuProgramFactory::destroy, factory, _1));
-		ret->initialize();
+		ret->initialize(internalCall);
 
 
 		return ret;
 		return ret;
 	}
 	}

+ 1 - 1
CamelotRenderer/Source/CmRenderSystem.cpp

@@ -289,7 +289,7 @@ namespace CamelotEngine {
 	{
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 		THROW_IF_NOT_RENDER_THREAD;
 
 
-		switch(prg->getBindingDelegate_internal()->getType())
+		switch(prg->getBindingDelegate()->getType())
 		{
 		{
 		case GPT_VERTEX_PROGRAM:
 		case GPT_VERTEX_PROGRAM:
 			// mark clip planes dirty if changed (programmable can change space)
 			// mark clip planes dirty if changed (programmable can change space)

+ 26 - 91
CamelotRenderer/TODO.txt

@@ -12,107 +12,44 @@
 
 
 -----------------------IMMEDIATE TODO---------------------------------------------------------------
 -----------------------IMMEDIATE TODO---------------------------------------------------------------
 
 
-Plan until end of February:
-Week A:
- Generic buffers DX11 and dummy implementations (that log warnings) for DX9 and OpenGL
- Texture buffers in DX11 and OpenGL
- A way to bind buffers to a Pass, while specifying buffer range
 
 
-Week B:
- Stream out (mainly OpenGL)
- Static/Dynamic usage for GpuParamBlocks
+>>>>>>>>>>FINAL SPRINT BEFORE EDITOR WORK
+ Working generic buffers
+ A way to bind buffers to a Pass, while specifying buffer range
+ Fully implement DX11
+ Better creation of PrimaryWindow
  GpuParams support for bools, buffers, structs
  GpuParams support for bools, buffers, structs
-
-Week C:
- Refactor render system methods to comply with DX11
- Implement working DX11 render system Part 1
-
-Week D:
- Implement working DX11 render system Part 2
-
-Week E:
- Refactor so that primary window is created with rendersystem initialization
- Make RenderTexture and DepthStenciLTexture use common interface
-
-Week F:
+ Static/Dynamic usage for GpuParamBlocks
  Ability to switch out GpuParamBlocks
  Ability to switch out GpuParamBlocks
  Smart way of initializing GpuParamBlocks (without duplicates)
  Smart way of initializing GpuParamBlocks (without duplicates)
  Port CG so it no longer uses low level shaders
  Port CG so it no longer uses low level shaders
+  - Cg support for param blocks
  Fix MaterialRTTI saving (Save params per gpuprogram is simplest and cleanest)
  Fix MaterialRTTI saving (Save params per gpuprogram is simplest and cleanest)
  Make sure that gpu programs assigned to Pass don't share parameters of different types
  Make sure that gpu programs assigned to Pass don't share parameters of different types
-
-Week G:
- Refactor how we handle RenderTargets (no attach/detach, and no waitForVSync propery in RenderSystem)
+ Make RenderTexture and DepthStenciLTexture use common interface
  Fix how and when is GpuParamBlock created/destroyed. Needs to happen on the render thread
  Fix how and when is GpuParamBlock created/destroyed. Needs to happen on the render thread
+ Refactor how we handle RenderTargets (no attach/detach, and no waitForVSync propery in RenderSystem)
+ waitForVsync can probably be moved somewhere other than being directly in RenderSystem? (where is it in DX11?)
 
 
 >>>>>>>>>>>>>>>START WORKING ON THE EDITOR!
 >>>>>>>>>>>>>>>START WORKING ON THE EDITOR!
  
  
 
 
-
-
-/////
------------GpuProgramParameters/Pass/Material REFACTOR------------------------------
-
-Destroying and constructing GpuParamBlock happens on main thread, which is wrong (especially destroying it)
-
-Saving/loading of material params isn't completed (in MAterialRTTI)
-Port DX11 to new shader param system
-Ability to switch out GpuParamBlocks (i.e. share them between programs)
-Ability to create Pass without automatically creating param blocks
-Automatically creating a pass should be smart about not creating duplicate param blocks
-Port CG so it doesn't attempt to use low level GL shaders (which I have removed)
-
-Handling of array parameters? This needs testing
- - I'm currently ignoring array elements in GL due to the name their names are handled
-
-
 ---------------------------------------------------
 ---------------------------------------------------
 
 
-monitorIndex is ignored in DX11
-
-Creating a primary window and initializing the render system should probably be one step
- - OpenGL requires it anyway in order to get context (Make sure to update GLRenderWindowManager if I change how this works)
- - I can't imagine much use for a render system without a window. (Windowless client is a possibility, but in that case entire render system would not be needed)
- - And if just rendering to texture (or similar) is needed, a hidden window may be used
-
-Don't forget to check out Unity DX11 documentation on how to implement DX11 features (http://docs.unity3d.com/Documentation/Manual/DirectX11.html)
-
-Unity has a common class for both RenderTexture and DepthStencilBuffer
- - Maybe rename DepthStencilBuffer to DepthStencilTexture?
-
-waitForVsync can probably be moved somewhere other than being directly in RenderSystem? (where is it in DX11?)
-
-Keeping a list of all render targets in RenderSystem shouldn't be needed (and calling attach/detach renderTarget). Renderer should determine in what order are render targets presented.
-
-Make CommandQueue not use mutexes and use atomics instead??
-Make sure that the simulation can't run faster then the render thread! (Block the main thread until previous render finishes)
-Figure out how to handle accessing texture from a non-render thread?
-
 Issue of setting individual parameters on a material
 Issue of setting individual parameters on a material
  - Material can contain multiple techniques
  - Material can contain multiple techniques
  - How do I ensure parameters are valid for all techniques?
  - How do I ensure parameters are valid for all techniques?
  - Require user to create a Material parameter specification?
  - Require user to create a Material parameter specification?
  - Also need a way to avoid displaying internal parameters used by the active renderer
  - Also need a way to avoid displaying internal parameters used by the active renderer
-/////
-
-
 
 
 RenderSystem needed modifications
 RenderSystem needed modifications
- - High priority
-  - Figure out how to handle different resource views and setting them on Passes
-    - Specifying buffer & texture ranges
-	- Setting UAV for both buffers and textures (Need to add a special flag for texture creation)
-  - Generic buffers (Normal/Structured/Raw/Append/Consume/Indirect)
+  - Texture resource views (Specifying just a subresource of a texture as a shader parameter)
+  - UAV for textures
+  - Stream out (write vertex buffers) (DX11 and GL)
   - Texture buffers 
   - Texture buffers 
    - Just add a special texture type? OpenGL doesn't support getting offset from within a texture buffer anyway
    - Just add a special texture type? OpenGL doesn't support getting offset from within a texture buffer anyway
-  - Stream out (write vertex buffers) (DX11 and GL)
-  - Static/Dynamic usage for GpuParamBlocks
-  - GpuParams need to support bools, buffers & structs (void*)
   - Tesselation (hull/domain) shader
   - Tesselation (hull/domain) shader
   - Detachable and readable depthstencil buffer (Window buffers not required as they behave a bit differently in OpenGL)
   - Detachable and readable depthstencil buffer (Window buffers not required as they behave a bit differently in OpenGL)
-   - Also make DepthStencilBuffer share common features with RenderTexture
-  
- - Low priority
   - OpenGL provides image load/store which seems to be GL UAV equivalent (http://www.opengl.org/wiki/Image_Load_Store)
   - OpenGL provides image load/store which seems to be GL UAV equivalent (http://www.opengl.org/wiki/Image_Load_Store)
   - Resolving MSAA textures (i.e. copying them to non-MSAA so they can be displayed on-screen). DX has ResolveSubresource, and OpenGL might have something similar.
   - Resolving MSAA textures (i.e. copying them to non-MSAA so they can be displayed on-screen). DX has ResolveSubresource, and OpenGL might have something similar.
   - Single and dual channel textures (especially render textures, which are very important for effects like SSAO)
   - Single and dual channel textures (especially render textures, which are very important for effects like SSAO)
@@ -128,27 +65,15 @@ RenderSystem needed modifications
   - Multiple adapters (multi gpu)
   - Multiple adapters (multi gpu)
   - HLSL9/HLSL11/GLSL/Cg shaders need preprocessor defines & includes
   - HLSL9/HLSL11/GLSL/Cg shaders need preprocessor defines & includes
 
 
-
-
-
 Command buffer TODO:
 Command buffer TODO:
+ - Make CommandQueue not use mutexes and use atomics instead??
+ - Make sure that the simulation can't run faster then the render thread! (Block the main thread until previous render finishes)
+ - Figure out how to handle accessing texture from a non-render thread?
  - When importing a resource, and registering it with Resources I don't think it properly gets added to the loaded resources array? For some reason shaders get created twice.
  - When importing a resource, and registering it with Resources I don't think it properly gets added to the loaded resources array? For some reason shaders get created twice.
  - Doing setPixels_async in the texture doesn't make sure that the user doesn't actually modify the provided PixelData after
  - Doing setPixels_async in the texture doesn't make sure that the user doesn't actually modify the provided PixelData after
     that call.
     that call.
  - In general I need to rethink how to handle modifying resources with multithreading
  - In general I need to rethink how to handle modifying resources with multithreading
 
 
-Mesh
- - Make sure to queue up mesh deletion to make sure it gets destroyed on the render thread
-
-Make initialize & initialize_internal protected?
- - Only their factories and RTTI classes need to access it (and they can be friends)
- - Would need to modify HighLevelGpuProgram::mAssemblerProgram
-
-When saving a resource, make sure resource is properly loaded before saving
-  - Add doc to Resources::save that says it will block until render thread updates the resource
-  - Add documentation that tells the user that reading a resource non-async will block the thread and execute all queued render commands first
-  - Remove Response handlers from Resources
-
 -----------------------BACKLOG TODO---------------------------------------------------------------
 -----------------------BACKLOG TODO---------------------------------------------------------------
 
 
 HIGH PRIORITY TODO:
 HIGH PRIORITY TODO:
@@ -158,6 +83,8 @@ HIGH PRIORITY TODO:
  - GetRenderOperation doesn't consider sub-meshes
  - GetRenderOperation doesn't consider sub-meshes
 
 
 Mid priority TODO:
 Mid priority TODO:
+ - monitorIndex is ignored in DX11
+ - Make sure to queue up mesh deletion to make sure it gets destroyed on the render thread
  - Resource handle should store a unique integer ID, which just points to a table of GUIDs. Keeping GUID string everywhere in not efficient.
  - Resource handle should store a unique integer ID, which just points to a table of GUIDs. Keeping GUID string everywhere in not efficient.
  - Add a field that tracks % of resource deserialization in BinarySerializer
  - Add a field that tracks % of resource deserialization in BinarySerializer
  - Mesh loading:
  - Mesh loading:
@@ -166,6 +93,8 @@ Mid priority TODO:
   - Search for all remaining "TODO PORT" comments and fix them
   - Search for all remaining "TODO PORT" comments and fix them
   - Ogre performed special DDS loading. I removed that. I'm not sure if I'll need to re-add it?
   - Ogre performed special DDS loading. I removed that. I'm not sure if I'll need to re-add it?
   - My log is not thread safe yet it is being called from multiple threads.
   - My log is not thread safe yet it is being called from multiple threads.
+  - Handling of shader array parameters? This needs testing
+   - I'm currently ignoring array elements in GL due to the name their names are handled
  - RTTI:
  - RTTI:
      When defining RTTIType like so: 
      When defining RTTIType like so: 
       RTTIType<D3D9HLSLProgram, HighLevelGpuProgram, D3D9HLSLProgramRTTI>
       RTTIType<D3D9HLSLProgram, HighLevelGpuProgram, D3D9HLSLProgramRTTI>
@@ -190,6 +119,11 @@ Low priority TODO:
  - Fix up WorkQueue as it doesn't lock when initializing, to make sure threads are actually started before returning
  - Fix up WorkQueue as it doesn't lock when initializing, to make sure threads are actually started before returning
  - DepthStencilBuffer & Texture should possibly share the same interface instead of being two separate classes? I'll need to assign DepthStencil to shaders sometimes. Not possible in DX9 but possible in DX11.
  - DepthStencilBuffer & Texture should possibly share the same interface instead of being two separate classes? I'll need to assign DepthStencil to shaders sometimes. Not possible in DX9 but possible in DX11.
  - CPU reading or writing to a render texture in OpenGL is not supported. (CmGLHardwarePixelBuffer::upload/download). 
  - CPU reading or writing to a render texture in OpenGL is not supported. (CmGLHardwarePixelBuffer::upload/download). 
+ - When saving a resource, make sure resource is properly loaded before saving
+   - Add doc to Resources::save that says it will block until render thread updates the resource
+   - Add documentation that tells the user that reading a resource non-async will block the thread and execute all queued render commands first
+   - Remove Response handlers from Resources
+- Cg doesn't work. Either remove it or get it to work
 
 
 Optional TODO:
 Optional TODO:
  - Add precompiled headers to all projects
  - Add precompiled headers to all projects
@@ -215,6 +149,7 @@ After everything is polished
  - Multihead device
  - Multihead device
  - 3D rendering (use low level hardware methods for it)
  - 3D rendering (use low level hardware methods for it)
  
  
+ - Don't forget to check out Unity DX11 documentation on how to implement DX11 features (http://docs.unity3d.com/Documentation/Manual/DirectX11.html)
  - Go to Game Engine Architecture book and make a list of Utility systems we will need (Config files, Parsers, File I/O etc)
  - Go to Game Engine Architecture book and make a list of Utility systems we will need (Config files, Parsers, File I/O etc)
  - Go to GEA book and read about resource managers before implementing them
  - Go to GEA book and read about resource managers before implementing them
    - Actually I should re-read most of the chapers in the book, or all of it
    - Actually I should re-read most of the chapers in the book, or all of it