Просмотр исходного кода

EntryPoint & Profile added to GpuProgram

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

+ 2 - 0
CamelotRenderer/CamelotRenderer.vcxproj

@@ -142,6 +142,7 @@
     <ClInclude Include="OgreHeaderPrefix.h" />
     <ClInclude Include="OgreHeaderPrefix.h" />
     <ClInclude Include="OgreHeaderSuffix.h" />
     <ClInclude Include="OgreHeaderSuffix.h" />
     <ClInclude Include="OgreHighLevelGpuProgram.h" />
     <ClInclude Include="OgreHighLevelGpuProgram.h" />
+    <ClInclude Include="OgreHighLevelGpuProgramManager.h" />
     <ClInclude Include="OgreImageResampler.h" />
     <ClInclude Include="OgreImageResampler.h" />
     <ClInclude Include="OgreMath.h" />
     <ClInclude Include="OgreMath.h" />
     <ClInclude Include="OgreMatrix3.h" />
     <ClInclude Include="OgreMatrix3.h" />
@@ -225,6 +226,7 @@
     <ClCompile Include="OgreHardwarePixelBuffer.cpp" />
     <ClCompile Include="OgreHardwarePixelBuffer.cpp" />
     <ClCompile Include="OgreHardwareVertexBuffer.cpp" />
     <ClCompile Include="OgreHardwareVertexBuffer.cpp" />
     <ClCompile Include="OgreHighLevelGpuProgram.cpp" />
     <ClCompile Include="OgreHighLevelGpuProgram.cpp" />
+    <ClCompile Include="OgreHighLevelGpuProgramManager.cpp" />
     <ClCompile Include="OgreMath.cpp" />
     <ClCompile Include="OgreMath.cpp" />
     <ClCompile Include="OgreMatrix3.cpp" />
     <ClCompile Include="OgreMatrix3.cpp" />
     <ClCompile Include="OgreMatrix4.cpp" />
     <ClCompile Include="OgreMatrix4.cpp" />

+ 6 - 0
CamelotRenderer/CamelotRenderer.vcxproj.filters

@@ -319,6 +319,9 @@
     <ClInclude Include="OgreGpuProgramManager.h">
     <ClInclude Include="OgreGpuProgramManager.h">
       <Filter>Header Files</Filter>
       <Filter>Header Files</Filter>
     </ClInclude>
     </ClInclude>
+    <ClInclude Include="OgreHighLevelGpuProgramManager.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClCompile Include="stdafx.cpp">
     <ClCompile Include="stdafx.cpp">
@@ -522,5 +525,8 @@
     <ClCompile Include="OgreGpuProgramManager.cpp">
     <ClCompile Include="OgreGpuProgramManager.cpp">
       <Filter>Source Files</Filter>
       <Filter>Source Files</Filter>
     </ClCompile>
     </ClCompile>
+    <ClCompile Include="OgreHighLevelGpuProgramManager.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   </ItemGroup>
 </Project>
 </Project>

+ 11 - 1
CamelotRenderer/CmApplication.cpp

@@ -8,15 +8,19 @@
 #include "OgreRenderWindow.h"
 #include "OgreRenderWindow.h"
 #include "OgreCamera.h"
 #include "OgreCamera.h"
 #include "OgreViewport.h"
 #include "OgreViewport.h"
+#include "OgreHighLevelGpuProgram.h"
+#include "OgreHighLevelGpuProgramManager.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
 	Application::Application()
 	Application::Application()
-		:mRenderWindow(nullptr), mViewport(nullptr)
+		:mRenderWindow(nullptr), mViewport(nullptr), mCamera(nullptr), mGpuProgramManager(nullptr)
 	{ }
 	{ }
 
 
 	void Application::startUp()
 	void Application::startUp()
 	{
 	{
+		mGpuProgramManager = new Ogre::HighLevelGpuProgramManager(); // TODO - Use Camelot::Module for instantiating this
+
 		RenderSystemManager::initialize("D3D9RenderSystem");
 		RenderSystemManager::initialize("D3D9RenderSystem");
 		
 		
 		Ogre::RenderSystem* renderSystem = RenderSystemManager::getActive();
 		Ogre::RenderSystem* renderSystem = RenderSystemManager::getActive();
@@ -35,6 +39,9 @@ namespace CamelotEngine
 
 
 		mViewport = mRenderWindow->addViewport();
 		mViewport = mRenderWindow->addViewport();
 
 
+		Ogre::HighLevelGpuProgramPtr fragProg = mGpuProgramManager->createProgram("barg", "barg", "hlsl", Ogre::GPT_FRAGMENT_PROGRAM, Ogre::GPP_PS_1_1);
+		fragProg->load();
+
 		while(true)
 		while(true)
 		{
 		{
 			Ogre::WindowEventUtilities::messagePump();
 			Ogre::WindowEventUtilities::messagePump();
@@ -47,6 +54,9 @@ namespace CamelotEngine
 	{
 	{
 		if(RenderSystemManager::getActive() != nullptr)
 		if(RenderSystemManager::getActive() != nullptr)
 			RenderSystemManager::getActive()->shutdown();
 			RenderSystemManager::getActive()->shutdown();
+
+		if(mGpuProgramManager != nullptr)
+			delete mGpuProgramManager;
 	}
 	}
 
 
 	void Application::DBG_renderSimpleFrame()
 	void Application::DBG_renderSimpleFrame()

+ 3 - 0
CamelotRenderer/CmApplication.h

@@ -7,6 +7,7 @@ namespace Ogre
 	class RenderWindow;
 	class RenderWindow;
 	class Viewport;
 	class Viewport;
 	class Camera;
 	class Camera;
+	class HighLevelGpuProgramManager;
 }
 }
 
 
 namespace CamelotEngine
 namespace CamelotEngine
@@ -22,6 +23,8 @@ namespace CamelotEngine
 			void DBG_renderSimpleFrame();
 			void DBG_renderSimpleFrame();
 
 
 		private:
 		private:
+			Ogre::HighLevelGpuProgramManager* mGpuProgramManager;
+
 			Ogre::RenderWindow* mRenderWindow;
 			Ogre::RenderWindow* mRenderWindow;
 			Ogre::Viewport* mViewport;
 			Ogre::Viewport* mViewport;
 			Ogre::Camera* mCamera;
 			Ogre::Camera* mCamera;

+ 2 - 12
CamelotRenderer/OgreD3D9GpuProgram.cpp

@@ -137,16 +137,6 @@ namespace Ogre {
 		}
 		}
 		else
 		else
 		{
 		{
-			// Normal load-from-source approach
-			if (mLoadFromFile)
-			{
-				//// find & load source code
-				//DataStreamPtr stream = 
-				//	ResourceGroupManager::getSingleton().openResource(
-				//	mFilename, mGroup, true, this);
-				//mSource = stream->getAsString();
-			}
-
 			// Call polymorphic load
 			// Call polymorphic load
 			loadFromSource(d3d9Device);
 			loadFromSource(d3d9Device);
 		}
 		}
@@ -266,7 +256,7 @@ namespace Ogre {
 		}
 		}
     }
     }
 	//-----------------------------------------------------------------------------
 	//-----------------------------------------------------------------------------
-    void D3D9GpuVertexProgram::unloadImpl(void)
+    void D3D9GpuVertexProgram::unload(void)
     {
     {
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
 
@@ -373,7 +363,7 @@ namespace Ogre {
 		}
 		}
     }
     }
 	//-----------------------------------------------------------------------------
 	//-----------------------------------------------------------------------------
-    void D3D9GpuFragmentProgram::unloadImpl(void)
+    void D3D9GpuFragmentProgram::unload(void)
     {
     {
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
 

+ 5 - 4
CamelotRenderer/OgreD3D9GpuProgram.h

@@ -111,6 +111,8 @@ namespace Ogre {
         D3D9GpuVertexProgram();
         D3D9GpuVertexProgram();
 		~D3D9GpuVertexProgram();
 		~D3D9GpuVertexProgram();
         
         
+		void unload(void);
+
 		/// Gets the vertex shader
 		/// Gets the vertex shader
         IDirect3DVertexShader9* getVertexShader(void);
         IDirect3DVertexShader9* getVertexShader(void);
 
 
@@ -121,8 +123,6 @@ namespace Ogre {
 		virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
 		virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
 
 
     protected:
     protected:
-        /** @copydoc Resource::unloadImpl */
-        void unloadImpl(void);
         void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode);
         void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode);
 
 
 	protected:
 	protected:
@@ -138,6 +138,9 @@ namespace Ogre {
     public:
     public:
         D3D9GpuFragmentProgram();
         D3D9GpuFragmentProgram();
 		~D3D9GpuFragmentProgram();
 		~D3D9GpuFragmentProgram();
+
+		void unload(void);
+
         /// Gets the pixel shader
         /// Gets the pixel shader
         IDirect3DPixelShader9* getPixelShader(void);
         IDirect3DPixelShader9* getPixelShader(void);
 
 
@@ -148,8 +151,6 @@ namespace Ogre {
 		virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
 		virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
 
 
     protected:
     protected:
-        /** @copydoc Resource::unloadImpl */
-        void unloadImpl(void);
         void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode);
         void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode);
 
 
 	protected:
 	protected:

+ 43 - 6
CamelotRenderer/OgreD3D9HLSLProgram.cpp

@@ -90,6 +90,39 @@ namespace Ogre {
 
 
 	};
 	};
 
 
+	String gpuProgramProfileToHLSLProfile(GpuProgramProfile profile)
+	{
+		switch(profile)
+		{
+		case GPP_PS_1_1:
+			return "ps_1_1";
+		case GPP_PS_1_2:
+			return "ps_1_2";
+		case GPP_PS_1_3:
+			return "ps_1_3";
+		case GPP_PS_1_4:
+			return "ps_1_4";
+		case GPP_PS_2_0:
+			return "ps_2_0";
+		case GPP_PS_2_a:
+			return "ps_2_a";
+		case GPP_PS_2_b:
+			return "ps_2_b";
+		case GPP_PS_3_0:
+			return "ps_3_0";
+		case GPP_VS_1_1:
+			return "vs_1_1";
+		case GPP_VS_2_0:
+			return "vs_2_0";
+		case GPP_VS_2_a:
+			return "vs_2_a";
+		case GPP_VS_3_0:
+			return "vs_3_1";
+		default:
+			assert(false); // Unsupported profile
+		}
+	}
+
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     void D3D9HLSLProgram::loadFromSource(void)
     void D3D9HLSLProgram::loadFromSource(void)
@@ -208,6 +241,8 @@ namespace Ogre {
 		// include handler
 		// include handler
 		HLSLIncludeHandler includeHandler(this);
 		HLSLIncludeHandler includeHandler(this);
 
 
+		String hlslProfile = gpuProgramProfileToHLSLProfile(mProfile);
+
         // Compile & assemble into microcode
         // Compile & assemble into microcode
         HRESULT hr = D3DXCompileShader(
         HRESULT hr = D3DXCompileShader(
             mSource.c_str(),
             mSource.c_str(),
@@ -215,7 +250,7 @@ namespace Ogre {
             pDefines,
             pDefines,
             &includeHandler, 
             &includeHandler, 
             mEntryPoint.c_str(),
             mEntryPoint.c_str(),
-            mTarget.c_str(),
+            hlslProfile.c_str(),
             compileFlags,
             compileFlags,
             &mpMicroCode,
             &mpMicroCode,
             &errors,
             &errors,
@@ -242,12 +277,14 @@ namespace Ogre {
     {
     {
 		if (!mCompileError)
 		if (!mCompileError)
 		{
 		{
+			String hlslProfile = gpuProgramProfileToHLSLProfile(mProfile);
+
 			// Create a low-level program, give it the same name as us
 			// Create a low-level program, give it the same name as us
 			mAssemblerProgram = 
 			mAssemblerProgram = 
 				GpuProgramManager::getSingleton().createProgram(
 				GpuProgramManager::getSingleton().createProgram(
 					"",// dummy source, since we'll be using microcode
 					"",// dummy source, since we'll be using microcode
 					mType, 
 					mType, 
-					mTarget);
+					hlslProfile);
 			static_cast<D3D9GpuProgram*>(mAssemblerProgram.get())->setExternalMicrocode(mpMicroCode);
 			static_cast<D3D9GpuProgram*>(mAssemblerProgram.get())->setExternalMicrocode(mpMicroCode);
 		}
 		}
 
 
@@ -501,8 +538,6 @@ namespace Ogre {
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     D3D9HLSLProgram::D3D9HLSLProgram()
     D3D9HLSLProgram::D3D9HLSLProgram()
         : HighLevelGpuProgram()
         : HighLevelGpuProgram()
-        , mTarget()
-        , mEntryPoint()
         , mPreprocessorDefines()
         , mPreprocessorDefines()
         , mColumnMajorMatrices(true)
         , mColumnMajorMatrices(true)
         , mpMicroCode(NULL), mpConstTable(NULL)
         , mpMicroCode(NULL), mpConstTable(NULL)
@@ -549,8 +584,10 @@ namespace Ogre {
         if (mCompileError || !isRequiredCapabilitiesSupported())
         if (mCompileError || !isRequiredCapabilitiesSupported())
             return false;
             return false;
 
 
+		String hlslProfile = gpuProgramProfileToHLSLProfile(mProfile);
+
 		RenderSystem* rs = CamelotEngine::RenderSystemManager::getActive();
 		RenderSystem* rs = CamelotEngine::RenderSystemManager::getActive();
-		return rs->getCapabilities()->isShaderProfileSupported(mTarget);
+		return rs->getCapabilities()->isShaderProfileSupported(hlslProfile);
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     GpuProgramParametersSharedPtr D3D9HLSLProgram::createParameters(void)
     GpuProgramParametersSharedPtr D3D9HLSLProgram::createParameters(void)
@@ -566,7 +603,7 @@ namespace Ogre {
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     void D3D9HLSLProgram::setTarget(const String& target)
     void D3D9HLSLProgram::setTarget(const String& target)
     {
     {
-        mTarget = target;
+        //mTarget = target;
     }
     }
 
 
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------

+ 1 - 3
CamelotRenderer/OgreD3D9HLSLProgram.h

@@ -119,8 +119,6 @@ namespace Ogre {
         void processParamElement(D3DXHANDLE parent, String prefix, unsigned int index) const;
         void processParamElement(D3DXHANDLE parent, String prefix, unsigned int index) const;
 		void populateDef(D3DXCONSTANT_DESC& d3dDesc, GpuConstantDefinition& def) const;
 		void populateDef(D3DXCONSTANT_DESC& d3dDesc, GpuConstantDefinition& def) const;
 
 
-        String mTarget;
-        String mEntryPoint;
         String mPreprocessorDefines;
         String mPreprocessorDefines;
         bool mColumnMajorMatrices;
         bool mColumnMajorMatrices;
 
 
@@ -160,7 +158,7 @@ namespace Ogre {
         /** Sets the shader target to compile down to, e.g. 'vs_1_1'. */
         /** Sets the shader target to compile down to, e.g. 'vs_1_1'. */
         void setTarget(const String& target);
         void setTarget(const String& target);
         /** Gets the shader target to compile down to, e.g. 'vs_1_1'. */
         /** Gets the shader target to compile down to, e.g. 'vs_1_1'. */
-        const String& getTarget(void) const { return mTarget; }
+        const String& getTarget(void) const { return ""; }
         /** Sets the preprocessor defines use to compile the program. */
         /** Sets the preprocessor defines use to compile the program. */
         void setPreprocessorDefines(const String& defines) { mPreprocessorDefines = defines; }
         void setPreprocessorDefines(const String& defines) { mPreprocessorDefines = defines; }
         /** Sets the preprocessor defines use to compile the program. */
         /** Sets the preprocessor defines use to compile the program. */

+ 7 - 2
CamelotRenderer/OgreD3D9HLSLProgramFactory.cpp

@@ -47,9 +47,14 @@ namespace Ogre {
         return sLanguageName;
         return sLanguageName;
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
-    HighLevelGpuProgram* D3D9HLSLProgramFactory::create()
+    HighLevelGpuProgram* D3D9HLSLProgramFactory::create(const String& source, const String& entryPoint, GpuProgramProfile profile)
     {
     {
-        return new D3D9HLSLProgram();
+		D3D9HLSLProgram* prog = new D3D9HLSLProgram();
+		prog->setSource(source);
+		prog->setEntryPoint(entryPoint);
+		prog->setProfile(profile);
+
+        return prog;
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
 	void D3D9HLSLProgramFactory::destroy(HighLevelGpuProgram* prog)
 	void D3D9HLSLProgramFactory::destroy(HighLevelGpuProgram* prog)

+ 4 - 3
CamelotRenderer/OgreD3D9HLSLProgramFactory.h

@@ -29,11 +29,12 @@ THE SOFTWARE.
 #define __D3D9HLSLProgramFactory_H__
 #define __D3D9HLSLProgramFactory_H__
 
 
 #include "OgreD3D9Prerequisites.h"
 #include "OgreD3D9Prerequisites.h"
+#include "OgreHighLevelGpuProgramManager.h"
 
 
 namespace Ogre
 namespace Ogre
 {
 {
     /** Factory class for D3D9 HLSL programs. */
     /** Factory class for D3D9 HLSL programs. */
-    class _OgreD3D9Export D3D9HLSLProgramFactory
+    class _OgreD3D9Export D3D9HLSLProgramFactory : public HighLevelGpuProgramFactory
     {
     {
     protected:
     protected:
 		static String sLanguageName;
 		static String sLanguageName;
@@ -42,8 +43,8 @@ namespace Ogre
         ~D3D9HLSLProgramFactory();
         ~D3D9HLSLProgramFactory();
 		/// Get the name of the language this factory creates programs for
 		/// Get the name of the language this factory creates programs for
 		const String& getLanguage(void) const;
 		const String& getLanguage(void) const;
-        static HighLevelGpuProgram* create();
-		static void destroy(HighLevelGpuProgram* prog);
+        HighLevelGpuProgram* create(const String& source, const String& entryPoint, GpuProgramProfile profile);
+		void destroy(HighLevelGpuProgram* prog);
 
 
     };
     };
 }
 }

+ 4 - 3
CamelotRenderer/OgreD3D9RenderSystem.cpp

@@ -47,6 +47,7 @@ THE SOFTWARE.
 #include "OgreD3D9MultiRenderTarget.h"
 #include "OgreD3D9MultiRenderTarget.h"
 #include "OgreD3D9DeviceManager.h"
 #include "OgreD3D9DeviceManager.h"
 #include "OgreD3D9ResourceManager.h"
 #include "OgreD3D9ResourceManager.h"
+#include "OgreHighLevelGpuProgramManager.h"
 
 
 #define FLOAT2DWORD(f) *((DWORD*)&f)
 #define FLOAT2DWORD(f) *((DWORD*)&f)
 
 
@@ -1317,9 +1318,9 @@ namespace Ogre
 				"Trying to initialize D3D9RenderSystem from RenderSystemCapabilities that do not support Direct3D9",
 				"Trying to initialize D3D9RenderSystem from RenderSystemCapabilities that do not support Direct3D9",
 				"D3D9RenderSystem::initialiseFromRenderSystemCapabilities");
 				"D3D9RenderSystem::initialiseFromRenderSystemCapabilities");
 		}
 		}
-		// TODO PORT - If i'll be supporting factories enable this
-		//if (caps->isShaderProfileSupported("hlsl"))
-		//	HighLevelGpuProgramManager::getSingleton().addFactory(mHLSLProgramFactory);
+
+		if (caps->isShaderProfileSupported("hlsl"))
+			HighLevelGpuProgramManager::getSingleton().addFactory(mHLSLProgramFactory);
 	}
 	}
 
 
 	//-----------------------------------------------------------------------
 	//-----------------------------------------------------------------------

+ 1 - 1
CamelotRenderer/OgreD3D9TextureManager.h

@@ -36,7 +36,7 @@ namespace Ogre
 	class _OgreD3D9Export D3D9TextureManager
 	class _OgreD3D9Export D3D9TextureManager
 	{
 	{
 	public:		
 	public:		
-        /// @copydoc ResourceManager::createImpl
+        /// @copydoc ResourceManager::create
         static D3D9Texture* create(const NameValuePairList* createParams);
         static D3D9Texture* create(const NameValuePairList* createParams);
 
 
 	public:
 	public:

+ 25 - 0
CamelotRenderer/OgreGpuProgram.h

@@ -51,6 +51,21 @@ namespace Ogre {
 		GPT_GEOMETRY_PROGRAM
 		GPT_GEOMETRY_PROGRAM
 	};
 	};
 
 
+	enum GpuProgramProfile
+	{
+		GPP_PS_1_1,
+		GPP_PS_1_2,
+		GPP_PS_1_3,
+		GPP_PS_1_4,
+		GPP_PS_2_0,
+		GPP_PS_2_a,
+		GPP_PS_2_b,
+		GPP_PS_3_0,
+		GPP_VS_1_1,
+		GPP_VS_2_0,
+		GPP_VS_2_a,
+		GPP_VS_3_0
+	};
 
 
     // Forward declaration 
     // Forward declaration 
     class GpuProgramPtr;
     class GpuProgramPtr;
@@ -127,6 +142,10 @@ namespace Ogre {
 		static CmdAdjacency msAdjacencyCmd;
 		static CmdAdjacency msAdjacencyCmd;
 		/// The type of the program
 		/// The type of the program
 		GpuProgramType mType;
 		GpuProgramType mType;
+		/// Name of the shader entry method
+		String mEntryPoint;
+		/// Shader profiler that we are targeting (e.g. vs_1_1, etc.). Make sure profile matches the type.
+		GpuProgramProfile mProfile;
 		/// The name of the file to load source from (may be blank)
 		/// The name of the file to load source from (may be blank)
 		String mFilename;
 		String mFilename;
         /// The assembler source of the program (may be blank until file loaded)
         /// The assembler source of the program (may be blank until file loaded)
@@ -227,6 +246,12 @@ namespace Ogre {
 		virtual void setType(GpuProgramType t);
 		virtual void setType(GpuProgramType t);
         /// Get the program type
         /// Get the program type
         virtual GpuProgramType getType(void) const { return mType; }
         virtual GpuProgramType getType(void) const { return mType; }
+		/// Sets the gpu program profile (e.g. vs_1_1, etc.). Make sure it matches the program type.
+		virtual void setProfile(GpuProgramProfile profile) { mProfile = profile; }
+		virtual GpuProgramProfile getProfile() const { return mProfile; }
+		/// Sets the name of the entry method for the program
+		virtual void setEntryPoint(const String& entryPoint) { mEntryPoint = entryPoint; }
+		virtual const String& getEntryPoint() const { return mEntryPoint; }
 
 
         /** Returns the GpuProgram which should be bound to the pipeline.
         /** Returns the GpuProgram which should be bound to the pipeline.
         @remarks
         @remarks

+ 1 - 0
CamelotRenderer/OgreHighLevelGpuProgram.cpp

@@ -124,6 +124,7 @@ namespace Ogre
 				//	<< e.getFullDescription();
 				//	<< e.getFullDescription();
 
 
 				mCompileError = true;
 				mCompileError = true;
+				throw;
 			}
 			}
         }
         }
     }
     }

+ 168 - 0
CamelotRenderer/OgreHighLevelGpuProgramManager.cpp

@@ -0,0 +1,168 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+    (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2011 Torus Knot Software Ltd
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+-----------------------------------------------------------------------------
+*/
+#include "OgreHighLevelGpuProgramManager.h"
+
+namespace Ogre {
+
+	String sNullLang = "null";
+	class NullProgram : public HighLevelGpuProgram
+	{
+	protected:
+		/** Internal load implementation, must be implemented by subclasses.
+		*/
+		void loadFromSource(void) {}
+		/** Internal method for creating an appropriate low-level program from this
+		high-level program, must be implemented by subclasses. */
+		void createLowLevelImpl(void) {}
+		/// Internal unload implementation, must be implemented by subclasses
+		void unloadHighLevelImpl(void) {}
+		/// Populate the passed parameters with name->index map, must be overridden
+		void populateParameterNames(GpuProgramParametersSharedPtr params)
+		{
+			// Skip the normal implementation
+			// Ensure we don't complain about missing parameter names
+			params->setIgnoreMissingParams(true);
+
+		}
+		void buildConstantDefinitions() const
+		{
+			// do nothing
+		}
+	public:
+		NullProgram()
+			: HighLevelGpuProgram(){}
+		~NullProgram() {}
+		/// Overridden from GpuProgram - never supported
+		bool isSupported(void) const { return false; }
+		/// Overridden from GpuProgram
+		const String& getLanguage(void) const { return sNullLang; }
+
+		/// Overridden from StringInterface
+		bool setParameter(const String& name, const String& value)
+		{
+			// always silently ignore all parameters so as not to report errors on
+			// unsupported platforms
+			return true;
+		}
+
+	};
+	class NullProgramFactory : public HighLevelGpuProgramFactory
+	{
+	public:
+		NullProgramFactory() {}
+		~NullProgramFactory() {}
+		/// Get the name of the language this factory creates programs for
+		const String& getLanguage(void) const 
+		{ 
+			return sNullLang;
+		}
+		HighLevelGpuProgram* create(const String& source, const String& entryPoint, GpuProgramProfile profile)
+		{
+			return OGRE_NEW NullProgram();
+		}
+		void destroy(HighLevelGpuProgram* prog)
+		{
+			OGRE_DELETE prog;
+		}
+
+	};
+	//-----------------------------------------------------------------------
+	template<> HighLevelGpuProgramManager* 
+	Singleton<HighLevelGpuProgramManager>::ms_Singleton = 0;
+    HighLevelGpuProgramManager* HighLevelGpuProgramManager::getSingletonPtr(void)
+    {
+        return ms_Singleton;
+    }
+    HighLevelGpuProgramManager& HighLevelGpuProgramManager::getSingleton(void)
+    {  
+        assert( ms_Singleton );  return ( *ms_Singleton );  
+    }
+	//-----------------------------------------------------------------------
+	HighLevelGpuProgramManager::HighLevelGpuProgramManager()
+	{
+		mNullFactory = OGRE_NEW NullProgramFactory();
+		addFactory(mNullFactory);
+	}
+	//-----------------------------------------------------------------------
+	HighLevelGpuProgramManager::~HighLevelGpuProgramManager()
+	{
+		OGRE_DELETE mNullFactory;
+	}
+    //---------------------------------------------------------------------------
+	void HighLevelGpuProgramManager::addFactory(HighLevelGpuProgramFactory* factory)
+	{
+		// deliberately allow later plugins to override earlier ones
+		mFactories[factory->getLanguage()] = factory;
+	}
+    //---------------------------------------------------------------------------
+    void HighLevelGpuProgramManager::removeFactory(HighLevelGpuProgramFactory* factory)
+    {
+        // Remove only if equal to registered one, since it might overridden
+        // by other plugins
+        FactoryMap::iterator it = mFactories.find(factory->getLanguage());
+        if (it != mFactories.end() && it->second == factory)
+        {
+            mFactories.erase(it);
+        }
+    }
+    //---------------------------------------------------------------------------
+	HighLevelGpuProgramFactory* HighLevelGpuProgramManager::getFactory(const String& language)
+	{
+		FactoryMap::iterator i = mFactories.find(language);
+
+		if (i == mFactories.end())
+		{
+			// use the null factory to create programs that will never be supported
+			i = mFactories.find(sNullLang);
+		}
+		return i->second;
+	}
+	//---------------------------------------------------------------------
+	bool HighLevelGpuProgramManager::isLanguageSupported(const String& lang)
+	{
+		FactoryMap::iterator i = mFactories.find(lang);
+
+		return i != mFactories.end();
+
+	}
+    //---------------------------------------------------------------------------
+    HighLevelGpuProgramPtr HighLevelGpuProgramManager::createProgram(const String& source, const String& entryPoint, const String& language, GpuProgramType gptype, GpuProgramProfile profile)
+    {
+        HighLevelGpuProgramPtr ret = HighLevelGpuProgramPtr(getFactory(language)->create(source, entryPoint, profile));
+
+        HighLevelGpuProgramPtr prg = ret;
+        prg->setType(gptype);
+        prg->setSyntaxCode(language);
+
+        return prg;
+    }
+    //---------------------------------------------------------------------------
+    HighLevelGpuProgramFactory::~HighLevelGpuProgramFactory() 
+    {
+    }
+}

+ 145 - 0
CamelotRenderer/OgreHighLevelGpuProgramManager.h

@@ -0,0 +1,145 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+    (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2011 Torus Knot Software Ltd
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+-----------------------------------------------------------------------------
+*/
+#ifndef __HighLevelGpuProgramManager_H__
+#define __HighLevelGpuProgramManager_H__
+
+#include "OgrePrerequisites.h"
+#include "OgreSingleton.h"
+#include "OgreException.h"
+#include "OgreHighLevelGpuProgram.h"
+
+namespace Ogre {
+
+	/** \addtogroup Core
+	*  @{
+	*/
+	/** \addtogroup Resources
+	*  @{
+	*/
+	/** Interface definition for factories of HighLevelGpuProgram. */
+	class _OgreExport HighLevelGpuProgramFactory
+	{
+	public:
+        HighLevelGpuProgramFactory() {}
+        virtual ~HighLevelGpuProgramFactory();
+		/// Get the name of the language this factory creates programs for
+		virtual const String& getLanguage(void) const = 0;
+        virtual HighLevelGpuProgram* create(const String& source, const String& entryPoint, GpuProgramProfile profile) = 0;
+		virtual void destroy(HighLevelGpuProgram* prog) = 0;
+	};
+	/** This ResourceManager manages high-level vertex and fragment programs. 
+	@remarks
+		High-level vertex and fragment programs can be used instead of assembler programs
+		as managed by GpuProgramManager; however they typically result in a GpuProgram
+		being created as a derivative of the high-level program. High-level programs are
+		easier to write, and can often be API-independent, unlike assembler programs. 
+	@par
+		This class not only manages the programs themselves, it also manages the factory
+		classes which allow the creation of high-level programs using a variety of high-level
+		syntaxes. Plugins can be created which register themselves as high-level program
+		factories and as such the engine can be extended to accept virtually any kind of
+		program provided a plugin is written.
+	*/
+	class _OgreExport HighLevelGpuProgramManager : public Singleton<HighLevelGpuProgramManager>
+	{
+	public:
+		typedef map<String, HighLevelGpuProgramFactory*>::type FactoryMap;
+	protected:
+		/// Factories capable of creating HighLevelGpuProgram instances
+		FactoryMap mFactories;
+
+		/// Factory for dealing with programs for languages we can't create
+		HighLevelGpuProgramFactory* mNullFactory;
+
+		HighLevelGpuProgramFactory* getFactory(const String& language);
+	public:
+		HighLevelGpuProgramManager();
+		~HighLevelGpuProgramManager();
+		/** Add a new factory object for high-level programs of a given language. */
+		void addFactory(HighLevelGpuProgramFactory* factory);
+		/** Remove a factory object for high-level programs of a given language. */
+		void removeFactory(HighLevelGpuProgramFactory* factory);
+
+		/** Returns whether a given high-level language is supported. */
+		bool isLanguageSupported(const String& lang);
+
+
+        /** Create a new, unloaded HighLevelGpuProgram. 
+		@par
+			This method creates a new program of the type specified as the second and third parameters.
+			You will have to call further methods on the returned program in order to 
+			define the program fully before you can load it.
+		@param name The identifying name of the program
+        @param groupName The name of the resource group which this program is
+            to be a member of
+		@param language Code of the language to use (e.g. "cg")
+		@param gptype The type of program to create
+		*/
+		HighLevelGpuProgramPtr createProgram(const String& source, const String& entryPoint, const String& language, GpuProgramType gptype, GpuProgramProfile profile);
+
+        /** Override standard Singleton retrieval.
+        @remarks
+        Why do we do this? Well, it's because the Singleton
+        implementation is in a .h file, which means it gets compiled
+        into anybody who includes it. This is needed for the
+        Singleton template to work, but we actually only want it
+        compiled into the implementation of the class based on the
+        Singleton, not all of them. If we don't change this, we get
+        link errors when trying to use the Singleton-based class from
+        an outside dll.
+        @par
+        This method just delegates to the template version anyway,
+        but the implementation stays in this single compilation unit,
+        preventing link errors.
+        */
+        static HighLevelGpuProgramManager& getSingleton(void);
+        /** Override standard Singleton retrieval.
+        @remarks
+        Why do we do this? Well, it's because the Singleton
+        implementation is in a .h file, which means it gets compiled
+        into anybody who includes it. This is needed for the
+        Singleton template to work, but we actually only want it
+        compiled into the implementation of the class based on the
+        Singleton, not all of them. If we don't change this, we get
+        link errors when trying to use the Singleton-based class from
+        an outside dll.
+        @par
+        This method just delegates to the template version anyway,
+        but the implementation stays in this single compilation unit,
+        preventing link errors.
+        */
+        static HighLevelGpuProgramManager* getSingletonPtr(void);
+
+
+	};
+	/** @} */
+	/** @} */
+
+}
+
+#endif

+ 1 - 0
CamelotRenderer/TODO.txt

@@ -93,6 +93,7 @@ Other notes:
  - Port all math methods to Camelot
  - Port all math methods to Camelot
  - Rename all macros and other OGRE references to CM
  - Rename all macros and other OGRE references to CM
  - How am I notified on device reset? (When I need to reload my resources)
  - How am I notified on device reset? (When I need to reload my resources)
+ - If possible, make sure GLSL uses EntryPoint and Profile fields I have added to GpuProgram
  
  
 After everything is polished:
 After everything is polished:
  - Make sure the renderer can run on a separate thread
  - Make sure the renderer can run on a separate thread