2
0
Эх сурвалжийг харах

Added GLGpuParamBlock
Removed all the default buffers

Marko Pintera 13 жил өмнө
parent
commit
caf40bae61
31 өөрчлөгдсөн 945 нэмэгдсэн , 1644 устгасан
  1. 3 2
      CamelotD3D11RenderSystem/Include/CmD3D11HardwareConstantBuffer.h
  2. 1 1
      CamelotD3D11RenderSystem/Include/CmD3D11VertexDeclaration.h
  3. 0 1
      CamelotD3D11RenderSystem/Source/CmD3D11HLSLProgram.cpp
  4. 2 2
      CamelotD3D11RenderSystem/Source/CmD3D11HardwareConstantBuffer.cpp
  5. 1 1
      CamelotD3D9Renderer/Include/CmD3D9VertexDeclaration.h
  6. 0 4
      CamelotD3D9Renderer/Source/CmD3D9VertexDeclaration.cpp
  7. 2 2
      CamelotGLRenderer/CamelotGLRenderer.vcxproj
  8. 6 6
      CamelotGLRenderer/CamelotGLRenderer.vcxproj.filters
  9. 0 141
      CamelotGLRenderer/Include/CmGLDefaultHardwareBufferManager.h
  10. 23 0
      CamelotGLRenderer/Include/CmGLGpuParamBlock.h
  11. 2 0
      CamelotGLRenderer/Include/CmGLPrerequisites.h
  12. 0 174
      CamelotGLRenderer/Source/CmGLDefaultHardwareBufferManager.cpp
  13. 41 0
      CamelotGLRenderer/Source/CmGLGpuParamBlock.cpp
  14. 10 33
      CamelotGLRenderer/Source/CmGLRenderSystem.cpp
  15. 2 0
      CamelotGLRenderer/Source/GLSL/src/CmGLSLProgram.cpp
  16. 2 4
      CamelotRenderer/CamelotRenderer.vcxproj
  17. 6 12
      CamelotRenderer/CamelotRenderer.vcxproj.filters
  18. 0 165
      CamelotRenderer/Include/CmDefaultHardwareBufferManager.h
  19. 2 2
      CamelotRenderer/Include/CmGpuParamBlock.h
  20. 0 21
      CamelotRenderer/Include/CmHardwareConstantBuffer.h
  21. 0 384
      CamelotRenderer/Include/CmHardwareVertexBuffer.h
  22. 1 0
      CamelotRenderer/Include/CmMeshDataRTTI.h
  23. 1 0
      CamelotRenderer/Include/CmRenderOperation.h
  24. 391 0
      CamelotRenderer/Include/CmVertexDeclaration.h
  25. 1 0
      CamelotRenderer/Include/CmVertexIndexData.h
  26. 0 222
      CamelotRenderer/Source/CmDefaultHardwareBufferManager.cpp
  27. 1 2
      CamelotRenderer/Source/CmHardwareBufferManager.cpp
  28. 0 17
      CamelotRenderer/Source/CmHardwareConstantBuffer.cpp
  29. 0 2
      CamelotRenderer/Source/CmHardwareIndexBuffer.cpp
  30. 0 446
      CamelotRenderer/Source/CmHardwareVertexBuffer.cpp
  31. 447 0
      CamelotRenderer/Source/CmVertexDeclaration.cpp

+ 3 - 2
CamelotD3D11RenderSystem/Include/CmD3D11HardwareConstantBuffer.h

@@ -1,12 +1,13 @@
 #pragma once
 #pragma once
 
 
 #include "CmD3D11Prerequisites.h"
 #include "CmD3D11Prerequisites.h"
-#include "CmHardwareConstantBuffer.h"
 #include "CmD3D11HardwareBuffer.h"
 #include "CmD3D11HardwareBuffer.h"
 
 
+// TODO - This isn't really used. Should be ported to D3D11GpuParamBlock
+
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
-	class CM_D3D11_EXPORT D3D11HardwareConstantBuffer : public HardwareConstantBuffer
+	class CM_D3D11_EXPORT D3D11HardwareConstantBuffer
 	{
 	{
 	public:
 	public:
 		D3D11HardwareConstantBuffer(D3D11Device& device, HardwareBufferManagerBase* mgr, UINT32 sizeBytes, 
 		D3D11HardwareConstantBuffer(D3D11Device& device, HardwareBufferManagerBase* mgr, UINT32 sizeBytes, 

+ 1 - 1
CamelotD3D11RenderSystem/Include/CmD3D11VertexDeclaration.h

@@ -1,7 +1,7 @@
 #pragma once
 #pragma once
 
 
 #include "CmD3D11Prerequisites.h"
 #include "CmD3D11Prerequisites.h"
-#include "CmHardwareVertexBuffer.h"
+#include "CmVertexDeclaration.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {

+ 0 - 1
CamelotD3D11RenderSystem/Source/CmD3D11HLSLProgram.cpp

@@ -4,7 +4,6 @@
 #include "CmGpuProgramManager.h"
 #include "CmGpuProgramManager.h"
 #include "CmD3D11GpuProgram.h"
 #include "CmD3D11GpuProgram.h"
 #include "CmHardwareBufferManager.h"
 #include "CmHardwareBufferManager.h"
-#include "CmHardwareConstantBuffer.h"
 #include "CmD3D11RenderSystem.h"
 #include "CmD3D11RenderSystem.h"
 #include "CmException.h"
 #include "CmException.h"
 #include "CmDebug.h"
 #include "CmDebug.h"

+ 2 - 2
CamelotD3D11RenderSystem/Source/CmD3D11HardwareConstantBuffer.cpp

@@ -4,9 +4,9 @@ namespace CamelotEngine
 {
 {
 	D3D11HardwareConstantBuffer::D3D11HardwareConstantBuffer(D3D11Device& device, HardwareBufferManagerBase* mgr, UINT32 sizeBytes, 
 	D3D11HardwareConstantBuffer::D3D11HardwareConstantBuffer(D3D11Device& device, HardwareBufferManagerBase* mgr, UINT32 sizeBytes, 
 		HardwareBuffer::Usage usage, bool useSystemMem)
 		HardwareBuffer::Usage usage, bool useSystemMem)
-		:HardwareConstantBuffer(mgr, sizeBytes, usage, useSystemMem)
+		//:HardwareConstantBuffer(mgr, sizeBytes, usage, useSystemMem)
 	{
 	{
-		mBuffer = new D3D11HardwareBuffer(D3D11HardwareBuffer::CONSTANT_BUFFER, mSizeInBytes, usage, device, useSystemMem, false);
+		//mBuffer = new D3D11HardwareBuffer(D3D11HardwareBuffer::CONSTANT_BUFFER, mSizeInBytes, usage, device, useSystemMem, false);
 	}
 	}
 
 
 	D3D11HardwareConstantBuffer::~D3D11HardwareConstantBuffer()
 	D3D11HardwareConstantBuffer::~D3D11HardwareConstantBuffer()

+ 1 - 1
CamelotD3D9Renderer/Include/CmD3D9VertexDeclaration.h

@@ -29,7 +29,7 @@ THE SOFTWARE.
 #define __D3D9VERTEXDECLARATION_H__
 #define __D3D9VERTEXDECLARATION_H__
 
 
 #include "CmD3D9Prerequisites.h"
 #include "CmD3D9Prerequisites.h"
-#include "CmHardwareVertexBuffer.h"
+#include "CmVertexDeclaration.h"
 #include "CmD3D9Resource.h"
 #include "CmD3D9Resource.h"
 
 
 namespace CamelotEngine { 
 namespace CamelotEngine { 

+ 0 - 4
CamelotD3D9Renderer/Source/CmD3D9VertexDeclaration.cpp

@@ -185,9 +185,5 @@ namespace CamelotEngine {
 		}	
 		}	
 		mMapDeviceToDeclaration.clear();
 		mMapDeviceToDeclaration.clear();
 	}
 	}
-
-	//-----------------------------------------------------------------------
-
-
 }
 }
 
 

+ 2 - 2
CamelotGLRenderer/CamelotGLRenderer.vcxproj

@@ -148,9 +148,9 @@
   </ItemDefinitionGroup>
   </ItemDefinitionGroup>
   <ItemGroup>
   <ItemGroup>
     <ClInclude Include="Include\CmGLContext.h" />
     <ClInclude Include="Include\CmGLContext.h" />
-    <ClInclude Include="Include\CmGLDefaultHardwareBufferManager.h" />
     <ClInclude Include="Include\CmGLDepthStencilBuffer.h" />
     <ClInclude Include="Include\CmGLDepthStencilBuffer.h" />
     <ClInclude Include="Include\CmGLFrameBufferObject.h" />
     <ClInclude Include="Include\CmGLFrameBufferObject.h" />
+    <ClInclude Include="Include\CmGLGpuParamBlock.h" />
     <ClInclude Include="Include\CmGLGpuProgramManager.h" />
     <ClInclude Include="Include\CmGLGpuProgramManager.h" />
     <ClInclude Include="Include\CmGLHardwareBufferManager.h" />
     <ClInclude Include="Include\CmGLHardwareBufferManager.h" />
     <ClInclude Include="Include\CmGLHardwareIndexBuffer.h" />
     <ClInclude Include="Include\CmGLHardwareIndexBuffer.h" />
@@ -182,9 +182,9 @@
   <ItemGroup>
   <ItemGroup>
     <ClCompile Include="CmGLPlugin.cpp" />
     <ClCompile Include="CmGLPlugin.cpp" />
     <ClCompile Include="Source\CmGLContext.cpp" />
     <ClCompile Include="Source\CmGLContext.cpp" />
-    <ClCompile Include="Source\CmGLDefaultHardwareBufferManager.cpp" />
     <ClCompile Include="Source\CmGLDepthStencilBuffer.cpp" />
     <ClCompile Include="Source\CmGLDepthStencilBuffer.cpp" />
     <ClCompile Include="Source\CmGLFrameBufferObject.cpp" />
     <ClCompile Include="Source\CmGLFrameBufferObject.cpp" />
+    <ClCompile Include="Source\CmGLGpuParamBlock.cpp" />
     <ClCompile Include="Source\CmGLGpuProgramManager.cpp" />
     <ClCompile Include="Source\CmGLGpuProgramManager.cpp" />
     <ClCompile Include="Source\CmGLHardwareBufferManager.cpp" />
     <ClCompile Include="Source\CmGLHardwareBufferManager.cpp" />
     <ClCompile Include="Source\CmGLHardwareIndexBuffer.cpp" />
     <ClCompile Include="Source\CmGLHardwareIndexBuffer.cpp" />

+ 6 - 6
CamelotGLRenderer/CamelotGLRenderer.vcxproj.filters

@@ -27,9 +27,6 @@
     <ClInclude Include="Include\CmGLContext.h">
     <ClInclude Include="Include\CmGLContext.h">
       <Filter>Header Files</Filter>
       <Filter>Header Files</Filter>
     </ClInclude>
     </ClInclude>
-    <ClInclude Include="Include\CmGLDefaultHardwareBufferManager.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
     <ClInclude Include="Include\CmGLFrameBufferObject.h">
     <ClInclude Include="Include\CmGLFrameBufferObject.h">
       <Filter>Header Files</Filter>
       <Filter>Header Files</Filter>
     </ClInclude>
     </ClInclude>
@@ -117,6 +114,9 @@
     <ClInclude Include="Include\CmGLMultiRenderTexture.h">
     <ClInclude Include="Include\CmGLMultiRenderTexture.h">
       <Filter>Header Files</Filter>
       <Filter>Header Files</Filter>
     </ClInclude>
     </ClInclude>
+    <ClInclude Include="Include\CmGLGpuParamBlock.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\GLSL\src\CmGLSLExtSupport.cpp">
     <ClCompile Include="Source\GLSL\src\CmGLSLExtSupport.cpp">
@@ -140,9 +140,6 @@
     <ClCompile Include="Source\CmGLContext.cpp">
     <ClCompile Include="Source\CmGLContext.cpp">
       <Filter>Source Files</Filter>
       <Filter>Source Files</Filter>
     </ClCompile>
     </ClCompile>
-    <ClCompile Include="Source\CmGLDefaultHardwareBufferManager.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="Source\CmGLFrameBufferObject.cpp">
     <ClCompile Include="Source\CmGLFrameBufferObject.cpp">
       <Filter>Source Files</Filter>
       <Filter>Source Files</Filter>
     </ClCompile>
     </ClCompile>
@@ -206,5 +203,8 @@
     <ClCompile Include="Source\CmGLMultiRenderTexture.cpp">
     <ClCompile Include="Source\CmGLMultiRenderTexture.cpp">
       <Filter>Source Files</Filter>
       <Filter>Source Files</Filter>
     </ClCompile>
     </ClCompile>
+    <ClCompile Include="Source\CmGLGpuParamBlock.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   </ItemGroup>
 </Project>
 </Project>

+ 0 - 141
CamelotGLRenderer/Include/CmGLDefaultHardwareBufferManager.h

@@ -1,141 +0,0 @@
-/*
------------------------------------------------------------------------------
-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 __GLDefaultHardwareBufferManager_H__
-#define __GLDefaultHardwareBufferManager_H__
-
-#include "CmGLPrerequisites.h"
-#include "CmHardwareBufferManager.h"
-#include "CmHardwareVertexBuffer.h"
-#include "CmHardwareIndexBuffer.h"
-
-namespace CamelotEngine {
-
-    /// Specialisation of HardwareVertexBuffer for emulation
-    class CM_RSGL_EXPORT GLDefaultHardwareVertexBuffer : public HardwareVertexBuffer 
-    {
-	protected:
-		unsigned char* mpData;
-        /// @copydoc HardwareBuffer::lock
-        void* lockImpl(UINT32 offset, UINT32 length, LockOptions options);
-        /// @copydoc HardwareBuffer::unlock
-        void unlockImpl(void);
-
-    public:
-		GLDefaultHardwareVertexBuffer(UINT32 vertexSize, UINT32 numVertices, HardwareBuffer::Usage usage);
-		GLDefaultHardwareVertexBuffer(HardwareBufferManagerBase* mgr, UINT32 vertexSize, UINT32 numVertices, 
-            HardwareBuffer::Usage usage);
-        ~GLDefaultHardwareVertexBuffer();
-        /// @copydoc HardwareBuffer::readData
-        void readData(UINT32 offset, UINT32 length, void* pDest);
-        /// @copydoc HardwareBuffer::writeData
-
-        void writeData(UINT32 offset, UINT32 length, const void* pSource,
-				bool discardWholeBuffer = false);
-        /** Override HardwareBuffer to turn off all shadowing. */
-        void* lock(UINT32 offset, UINT32 length, LockOptions options);
-        /** Override HardwareBuffer to turn off all shadowing. */
-		void unlock(void);
-
-        //void* getDataPtr(void) const { return (void*)mpData; }
-        void* getDataPtr(UINT32 offset) const { return (void*)(mpData + offset); }
-    };
-
-	/// Specialisation of HardwareIndexBuffer for emulation
-    class CM_RSGL_EXPORT GLDefaultHardwareIndexBuffer : public HardwareIndexBuffer
-    {
-	protected:
-		unsigned char* mpData;
-        /// @copydoc HardwareBuffer::lock
-        void* lockImpl(UINT32 offset, UINT32 length, LockOptions options);
-        /// @copydoc HardwareBuffer::unlock
-        void unlockImpl(void);
-    public:
-		GLDefaultHardwareIndexBuffer(IndexType idxType, UINT32 numIndexes, HardwareBuffer::Usage usage);
-        ~GLDefaultHardwareIndexBuffer();
-        /// @copydoc HardwareBuffer::readData
-        void readData(UINT32 offset, UINT32 length, void* pDest);
-        /// @copydoc HardwareBuffer::writeData
-        void writeData(UINT32 offset, UINT32 length, const void* pSource,
-				bool discardWholeBuffer = false);
-        /** Override HardwareBuffer to turn off all shadowing. */
-        void* lock(UINT32 offset, UINT32 length, LockOptions options);
-        /** Override HardwareBuffer to turn off all shadowing. */
-        void unlock(void);
-
-        void* getDataPtr(UINT32 offset) const { return (void*)(mpData + offset); }
-    };
-
-	/** Specialisation of HardwareBufferManager to emulate hardware buffers.
-	@remarks
-		You might want to instantiate this class if you want to utilise
-		classes like MeshSerializer without having initialised the 
-		rendering system (which is required to create a 'real' hardware
-		buffer manager.
-	*/
-	class CM_RSGL_EXPORT GLDefaultHardwareBufferManagerBase : public HardwareBufferManagerBase
-	{
-    public:
-        GLDefaultHardwareBufferManagerBase();
-        ~GLDefaultHardwareBufferManagerBase();
-
-		/**
-		 * @copydoc HardwareBufferManagerBase::createVertexBuffer
-		 */
-		HardwareVertexBufferPtr 
-            createVertexBuffer(UINT32 vertexSize, UINT32 numVerts, 
-				HardwareBuffer::Usage usage, bool streamOut = false);
-
-		/**
-		 * @copydoc HardwareBufferManagerBase::createIndexBuffer
-		 */
-		HardwareIndexBufferPtr 
-            createIndexBuffer(HardwareIndexBuffer::IndexType itype, UINT32 numIndexes, 
-				HardwareBuffer::Usage usage);
-
-		/** @copydoc HardwareBufferManagerInterface::createGpuParamBlock */
-		GpuParamBlockPtr createGpuParamBlock(const GpuParamBlockDesc& paramDesc);
-    };
-
-	/// GLDefaultHardwareBufferManagerBase as a Singleton
-	class CM_RSGL_EXPORT GLDefaultHardwareBufferManager : public HardwareBufferManager
-	{
-	public:
-		GLDefaultHardwareBufferManager()
-			: HardwareBufferManager(new GLDefaultHardwareBufferManagerBase()) 
-		{
-
-		}
-		~GLDefaultHardwareBufferManager()
-		{
-			delete mImpl;
-		}
-	};
-}
-
-#endif

+ 23 - 0
CamelotGLRenderer/Include/CmGLGpuParamBlock.h

@@ -0,0 +1,23 @@
+#pragma once
+
+#include "CmGLPrerequisites.h"
+#include "CmGpuParamBlock.h"
+
+namespace CamelotEngine
+{
+	class CM_RSGL_EXPORT GLGpuParamBlock : public GpuParamBlock
+	{
+	public:
+		GLGpuParamBlock(const GpuParamBlockDesc& desc);
+		~GLGpuParamBlock();
+
+		virtual void updateIfDirty();
+		virtual GpuParamBlockPtr clone() const;
+
+		GLuint getGLHandle() const { return mGLHandle; }
+
+	private:
+		GLuint mGLHandle;
+		bool mBufferInitialized;
+	};
+}

+ 2 - 0
CamelotGLRenderer/Include/CmGLPrerequisites.h

@@ -41,9 +41,11 @@ namespace CamelotEngine {
     class GLRTTManager;
     class GLRTTManager;
     class GLHardwarePixelBuffer;
     class GLHardwarePixelBuffer;
     class GLRenderBuffer;
     class GLRenderBuffer;
+	class GLGpuParamBlock;
 
 
 	typedef std::shared_ptr<GLHardwarePixelBuffer> GLHardwarePixelBufferPtr;
 	typedef std::shared_ptr<GLHardwarePixelBuffer> GLHardwarePixelBufferPtr;
 	typedef std::shared_ptr<GLRenderBuffer> GLRenderBufferPtr;
 	typedef std::shared_ptr<GLRenderBuffer> GLRenderBufferPtr;
+	typedef std::shared_ptr<GLGpuParamBlock> GLGpuParamBlockPtr;
 
 
 	enum TypeID_D3D9
 	enum TypeID_D3D9
 	{
 	{

+ 0 - 174
CamelotGLRenderer/Source/CmGLDefaultHardwareBufferManager.cpp

@@ -1,174 +0,0 @@
-/*
------------------------------------------------------------------------------
-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 "CmGLDefaultHardwareBufferManager.h"
-#include "CmGpuParamBlock.h"
-#include "CmException.h"
-
-namespace CamelotEngine {
-
-	GLDefaultHardwareVertexBuffer::GLDefaultHardwareVertexBuffer(UINT32 vertexSize, UINT32 numVertices, 
-																 HardwareBuffer::Usage usage)
-	: HardwareVertexBuffer(0, vertexSize, numVertices, usage, true)
-	{
-		mpData = static_cast<unsigned char*>(_aligned_malloc(mSizeInBytes, CM_SIMD_ALIGNMENT));
-	}
-	//-----------------------------------------------------------------------
-	GLDefaultHardwareVertexBuffer::GLDefaultHardwareVertexBuffer(HardwareBufferManagerBase* mgr, UINT32 vertexSize, UINT32 numVertices, 
-		HardwareBuffer::Usage usage)
-		: HardwareVertexBuffer(mgr, vertexSize, numVertices, usage, true)
-	{
-        mpData = static_cast<unsigned char*>(_aligned_malloc(mSizeInBytes, CM_SIMD_ALIGNMENT));
-	}
-	//-----------------------------------------------------------------------
-    GLDefaultHardwareVertexBuffer::~GLDefaultHardwareVertexBuffer()
-	{
-		_aligned_free(mpData);
-	}
-	//-----------------------------------------------------------------------
-    void* GLDefaultHardwareVertexBuffer::lockImpl(UINT32 offset, UINT32 length, LockOptions options)
-	{
-        // Only for use internally, no 'locking' as such
-		return mpData + offset;
-	}
-	//-----------------------------------------------------------------------
-	void GLDefaultHardwareVertexBuffer::unlockImpl(void)
-	{
-        // Nothing to do
-	}
-	//-----------------------------------------------------------------------
-    void* GLDefaultHardwareVertexBuffer::lock(UINT32 offset, UINT32 length, LockOptions options)
-	{
-        mIsLocked = true;
-		return mpData + offset;
-	}
-	//-----------------------------------------------------------------------
-	void GLDefaultHardwareVertexBuffer::unlock(void)
-	{
-        mIsLocked = false;
-        // Nothing to do
-	}
-	//-----------------------------------------------------------------------
-    void GLDefaultHardwareVertexBuffer::readData(UINT32 offset, UINT32 length, void* pDest)
-	{
-		assert((offset + length) <= mSizeInBytes);
-		memcpy(pDest, mpData + offset, length);
-	}
-	//-----------------------------------------------------------------------
-    void GLDefaultHardwareVertexBuffer::writeData(UINT32 offset, UINT32 length, const void* pSource,
-			bool discardWholeBuffer)
-	{
-		assert((offset + length) <= mSizeInBytes);
-		// ignore discard, memory is not guaranteed to be zeroised
-		memcpy(mpData + offset, pSource, length);
-
-	}
-	//-----------------------------------------------------------------------
-
-	GLDefaultHardwareIndexBuffer::GLDefaultHardwareIndexBuffer(IndexType idxType, 
-		UINT32 numIndexes, HardwareBuffer::Usage usage) 
-		: HardwareIndexBuffer(0, idxType, numIndexes, usage, true)
-	{
-		mpData = new unsigned char[mSizeInBytes];
-	}
-	//-----------------------------------------------------------------------
-    GLDefaultHardwareIndexBuffer::~GLDefaultHardwareIndexBuffer()
-	{
-		delete [] mpData;
-	}
-	//-----------------------------------------------------------------------
-    void* GLDefaultHardwareIndexBuffer::lockImpl(UINT32 offset, UINT32 length, LockOptions options)
-	{
-        // Only for use internally, no 'locking' as such
-		return mpData + offset;
-	}
-	//-----------------------------------------------------------------------
-	void GLDefaultHardwareIndexBuffer::unlockImpl(void)
-	{
-        // Nothing to do
-	}
-	//-----------------------------------------------------------------------
-    void* GLDefaultHardwareIndexBuffer::lock(UINT32 offset, UINT32 length, LockOptions options)
-	{
-        mIsLocked = true;
-		return mpData + offset;
-	}
-	//-----------------------------------------------------------------------
-	void GLDefaultHardwareIndexBuffer::unlock(void)
-	{
-        mIsLocked = false;
-        // Nothing to do
-	}
-	//-----------------------------------------------------------------------
-    void GLDefaultHardwareIndexBuffer::readData(UINT32 offset, UINT32 length, void* pDest)
-	{
-		assert((offset + length) <= mSizeInBytes);
-		memcpy(pDest, mpData + offset, length);
-	}
-	//-----------------------------------------------------------------------
-    void GLDefaultHardwareIndexBuffer::writeData(UINT32 offset, UINT32 length, const void* pSource,
-			bool discardWholeBuffer)
-	{
-		assert((offset + length) <= mSizeInBytes);
-		// ignore discard, memory is not guaranteed to be zeroised
-		memcpy(mpData + offset, pSource, length);
-
-	}
-	//-----------------------------------------------------------------------
-	
-	
-    //-----------------------------------------------------------------------
-    GLDefaultHardwareBufferManagerBase::GLDefaultHardwareBufferManagerBase()
-	{
-	}
-    //-----------------------------------------------------------------------
-    GLDefaultHardwareBufferManagerBase::~GLDefaultHardwareBufferManagerBase()
-	{
-        destroyAllBindings();
-	}
-    //-----------------------------------------------------------------------
-	HardwareVertexBufferPtr 
-        GLDefaultHardwareBufferManagerBase::createVertexBuffer(UINT32 vertexSize, 
-		UINT32 numVerts, HardwareBuffer::Usage usage, bool streamOut)
-	{
-		return HardwareVertexBufferPtr(
-			new GLDefaultHardwareVertexBuffer(this, vertexSize, numVerts, usage));
-	}
-    //-----------------------------------------------------------------------
-	HardwareIndexBufferPtr 
-        GLDefaultHardwareBufferManagerBase::createIndexBuffer(HardwareIndexBuffer::IndexType itype, 
-		UINT32 numIndexes, HardwareBuffer::Usage usage)
-	{
-		return HardwareIndexBufferPtr(
-			new GLDefaultHardwareIndexBuffer(itype, numIndexes, usage) );
-	}
-	//---------------------------------------------------------------------
-	GpuParamBlockPtr GLDefaultHardwareBufferManagerBase::createGpuParamBlock(const GpuParamBlockDesc& paramDesc)
-	{
-		return GpuParamBlockPtr(new GpuParamBlock(paramDesc));
-	}
-}

+ 41 - 0
CamelotGLRenderer/Source/CmGLGpuParamBlock.cpp

@@ -0,0 +1,41 @@
+#include "CmGLGpuParamBlock.h"
+
+namespace CamelotEngine
+{
+	GLGpuParamBlock::GLGpuParamBlock(const GpuParamBlockDesc& desc)
+		:GpuParamBlock(desc), mBufferInitialized(false), mGLHandle(0)
+	{
+
+	}
+
+	GLGpuParamBlock::~GLGpuParamBlock()
+	{
+
+	}
+
+	void GLGpuParamBlock::updateIfDirty()
+	{
+		if(mDirty)
+		{
+			if(!mBufferInitialized)
+			{
+				glGenBuffers(1, &mGLHandle);
+				glBindBuffer(GL_UNIFORM_BUFFER, mGLHandle);
+				glBufferData(mGLHandle, mSize, mData, GL_WRITE_ONLY);
+			}
+			else
+				glBufferSubData(GL_UNIFORM_BUFFER, 0 , mSize, mData);
+		}
+
+		GpuParamBlock::updateIfDirty();
+	}
+
+	GpuParamBlockPtr GLGpuParamBlock::clone() const
+	{
+		std::shared_ptr<GLGpuParamBlock> clonedParamBlock(new GLGpuParamBlock(*this));
+		clonedParamBlock->mData = new UINT8[mSize];
+		memcpy(clonedParamBlock->mData, mData, mSize);
+
+		return clonedParamBlock;
+	}
+}

+ 10 - 33
CamelotGLRenderer/Source/CmGLRenderSystem.cpp

@@ -33,7 +33,6 @@ THE SOFTWARE.s
 #include "CmGLTextureManager.h"
 #include "CmGLTextureManager.h"
 #include "CmGLHardwareVertexBuffer.h"
 #include "CmGLHardwareVertexBuffer.h"
 #include "CmGLHardwareIndexBuffer.h"
 #include "CmGLHardwareIndexBuffer.h"
-#include "CmGLDefaultHardwareBufferManager.h"
 #include "CmGLUtil.h"
 #include "CmGLUtil.h"
 #include "CmGLSLGpuProgram.h"
 #include "CmGLSLGpuProgram.h"
 #include "CmGLSLProgram.h"
 #include "CmGLSLProgram.h"
@@ -636,16 +635,10 @@ namespace CamelotEngine
 
 
 			HardwareVertexBufferPtr vertexBuffer = 
 			HardwareVertexBufferPtr vertexBuffer = 
 				op.vertexData->vertexBufferBinding->getBuffer(elem->getSource());
 				op.vertexData->vertexBufferBinding->getBuffer(elem->getSource());
-			if(mCurrentCapabilities->hasCapability(RSC_VBO))
-			{
-				glBindBufferARB(GL_ARRAY_BUFFER_ARB, 
-					static_cast<const GLHardwareVertexBuffer*>(vertexBuffer.get())->getGLBufferId());
-				pBufferData = VBO_BUFFER_OFFSET(elem->getOffset());
-			}
-			else
-			{
-				pBufferData = static_cast<const GLDefaultHardwareVertexBuffer*>(vertexBuffer.get())->getDataPtr(elem->getOffset());
-			}
+
+			glBindBufferARB(GL_ARRAY_BUFFER_ARB, static_cast<const GLHardwareVertexBuffer*>(vertexBuffer.get())->getGLBufferId());
+			pBufferData = VBO_BUFFER_OFFSET(elem->getOffset());
+
 			if (op.vertexData->vertexStart)
 			if (op.vertexData->vertexStart)
 			{
 			{
 				pBufferData = static_cast<char*>(pBufferData) + op.vertexData->vertexStart * vertexBuffer->getVertexSize();
 				pBufferData = static_cast<char*>(pBufferData) + op.vertexData->vertexStart * vertexBuffer->getVertexSize();
@@ -734,21 +727,12 @@ namespace CamelotEngine
 
 
 		if (op.useIndexes)
 		if (op.useIndexes)
 		{
 		{
-			if(mCurrentCapabilities->hasCapability(RSC_VBO))
-			{
-				glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 
-					static_cast<GLHardwareIndexBuffer*>(
-					op.indexData->indexBuffer.get())->getGLBufferId());
+			glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 
+				static_cast<GLHardwareIndexBuffer*>(
+				op.indexData->indexBuffer.get())->getGLBufferId());
 
 
-				pBufferData = VBO_BUFFER_OFFSET(
-					op.indexData->indexStart * op.indexData->indexBuffer->getIndexSize());
-			}
-			else
-			{
-				pBufferData = static_cast<GLDefaultHardwareIndexBuffer*>(
-					op.indexData->indexBuffer.get())->getDataPtr(
-					op.indexData->indexStart * op.indexData->indexBuffer->getIndexSize());
-			}
+			pBufferData = VBO_BUFFER_OFFSET(
+				op.indexData->indexStart * op.indexData->indexBuffer->getIndexSize());
 
 
 			GLenum indexType = (op.indexData->indexBuffer->getType() == HardwareIndexBuffer::IT_16BIT) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
 			GLenum indexType = (op.indexData->indexBuffer->getType() == HardwareIndexBuffer::IT_16BIT) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
 
 
@@ -1728,14 +1712,7 @@ namespace CamelotEngine
 			glUnmapBufferARB = glUnmapBuffer;
 			glUnmapBufferARB = glUnmapBuffer;
 		}
 		}
 
 
-		if(caps->hasCapability(RSC_VBO))
-		{
-			HardwareBufferManager::startUp(new GLHardwareBufferManager);
-		}
-		else
-		{
-			HardwareBufferManager::startUp(new GLDefaultHardwareBufferManager);
-		}
+		HardwareBufferManager::startUp(new GLHardwareBufferManager);
 
 
 		// GPU Program Manager setup
 		// GPU Program Manager setup
 		GpuProgramManager::startUp(new GLGpuProgramManager());
 		GpuProgramManager::startUp(new GLGpuProgramManager());

+ 2 - 0
CamelotGLRenderer/Source/GLSL/src/CmGLSLProgram.cpp

@@ -31,6 +31,7 @@ THE SOFTWARE.
 #include "CmGpuProgramManager.h"
 #include "CmGpuProgramManager.h"
 #include "CmHighLevelGpuProgramManager.h"
 #include "CmHighLevelGpuProgramManager.h"
 #include "CmException.h"
 #include "CmException.h"
+#include "CmVertexIndexData.h"
 
 
 #include "CmGLSLProgram.h"
 #include "CmGLSLProgram.h"
 #include "CmGLSLGpuProgram.h"
 #include "CmGLSLGpuProgram.h"
@@ -45,6 +46,7 @@ namespace CamelotEngine
 	{
 	{
 	public:
 	public:
 		void buildUniformDescriptions(GLuint glProgram, GpuParamDesc& returnParamDesc);
 		void buildUniformDescriptions(GLuint glProgram, GpuParamDesc& returnParamDesc);
+		void buildVertexDeclaration(GLuint glProgram, VertexDeclaration& declaration);
 
 
 	private:
 	private:
 		void determineParamInfo(GpuParamMemberDesc& desc, const String& paramName, GLuint programHandle, GLuint uniformIndex);
 		void determineParamInfo(GpuParamMemberDesc& desc, const String& paramName, GLuint programHandle, GLuint uniformIndex);

+ 2 - 4
CamelotRenderer/CamelotRenderer.vcxproj

@@ -187,7 +187,6 @@
     <ClInclude Include="Include\CmCommon.h" />
     <ClInclude Include="Include\CmCommon.h" />
     <ClInclude Include="Include\CmComponentRTTI.h" />
     <ClInclude Include="Include\CmComponentRTTI.h" />
     <ClInclude Include="Include\CmConfigOptionMap.h" />
     <ClInclude Include="Include\CmConfigOptionMap.h" />
-    <ClInclude Include="Include\CmDefaultHardwareBufferManager.h" />
     <ClInclude Include="Include\CmDeferredRenderContext.h" />
     <ClInclude Include="Include\CmDeferredRenderContext.h" />
     <ClInclude Include="Include\CmDepthStencilBuffer.h" />
     <ClInclude Include="Include\CmDepthStencilBuffer.h" />
     <ClInclude Include="Include\CmDepthStencilStateRTTI.h" />
     <ClInclude Include="Include\CmDepthStencilStateRTTI.h" />
@@ -201,7 +200,6 @@
     <ClInclude Include="Include\CmGpuProgramRTTI.h" />
     <ClInclude Include="Include\CmGpuProgramRTTI.h" />
     <ClInclude Include="Include\CmHardwareBuffer.h" />
     <ClInclude Include="Include\CmHardwareBuffer.h" />
     <ClInclude Include="Include\CmHardwareBufferManager.h" />
     <ClInclude Include="Include\CmHardwareBufferManager.h" />
-    <ClInclude Include="Include\CmHardwareConstantBuffer.h" />
     <ClInclude Include="Include\CmHardwareIndexBuffer.h" />
     <ClInclude Include="Include\CmHardwareIndexBuffer.h" />
     <ClInclude Include="Include\CmHardwareOcclusionQuery.h" />
     <ClInclude Include="Include\CmHardwareOcclusionQuery.h" />
     <ClInclude Include="Include\CmHardwarePixelBuffer.h" />
     <ClInclude Include="Include\CmHardwarePixelBuffer.h" />
@@ -252,6 +250,7 @@
     <ClInclude Include="Include\CmTextureManager.h" />
     <ClInclude Include="Include\CmTextureManager.h" />
     <ClInclude Include="Include\CmTextureRTTI.h" />
     <ClInclude Include="Include\CmTextureRTTI.h" />
     <ClInclude Include="Include\CmSamplerState.h" />
     <ClInclude Include="Include\CmSamplerState.h" />
+    <ClInclude Include="Include\CmVertexDeclaration.h" />
     <ClInclude Include="Include\CmVertexIndexData.h" />
     <ClInclude Include="Include\CmVertexIndexData.h" />
     <ClInclude Include="Include\CmViewport.h" />
     <ClInclude Include="Include\CmViewport.h" />
     <ClInclude Include="Include\CmWindowEventUtilities.h" />
     <ClInclude Include="Include\CmWindowEventUtilities.h" />
@@ -275,7 +274,6 @@
     <ClCompile Include="Source\CmCgProgram.cpp" />
     <ClCompile Include="Source\CmCgProgram.cpp" />
     <ClCompile Include="Source\CmCgProgramFactory.cpp" />
     <ClCompile Include="Source\CmCgProgramFactory.cpp" />
     <ClCompile Include="Source\CmCommandQueue.cpp" />
     <ClCompile Include="Source\CmCommandQueue.cpp" />
-    <ClCompile Include="Source\CmDefaultHardwareBufferManager.cpp" />
     <ClCompile Include="Source\CmDeferredRenderContext.cpp" />
     <ClCompile Include="Source\CmDeferredRenderContext.cpp" />
     <ClCompile Include="Source\CmDepthStencilBuffer.cpp" />
     <ClCompile Include="Source\CmDepthStencilBuffer.cpp" />
     <ClCompile Include="Source\CmDepthStencilState.cpp" />
     <ClCompile Include="Source\CmDepthStencilState.cpp" />
@@ -285,7 +283,6 @@
     <ClCompile Include="Source\CmGpuProgramManager.cpp" />
     <ClCompile Include="Source\CmGpuProgramManager.cpp" />
     <ClCompile Include="Source\CmGpuProgramParams.cpp" />
     <ClCompile Include="Source\CmGpuProgramParams.cpp" />
     <ClCompile Include="Source\CmHardwareBufferManager.cpp" />
     <ClCompile Include="Source\CmHardwareBufferManager.cpp" />
-    <ClCompile Include="Source\CmHardwareConstantBuffer.cpp" />
     <ClCompile Include="Source\CmHardwareIndexBuffer.cpp" />
     <ClCompile Include="Source\CmHardwareIndexBuffer.cpp" />
     <ClCompile Include="Source\CmHardwareOcclusionQuery.cpp" />
     <ClCompile Include="Source\CmHardwareOcclusionQuery.cpp" />
     <ClCompile Include="Source\CmHardwarePixelBuffer.cpp" />
     <ClCompile Include="Source\CmHardwarePixelBuffer.cpp" />
@@ -321,6 +318,7 @@
     <ClCompile Include="Source\CmTexture.cpp" />
     <ClCompile Include="Source\CmTexture.cpp" />
     <ClCompile Include="Source\CmTextureManager.cpp" />
     <ClCompile Include="Source\CmTextureManager.cpp" />
     <ClCompile Include="Source\CmSamplerState.cpp" />
     <ClCompile Include="Source\CmSamplerState.cpp" />
+    <ClCompile Include="Source\CmVertexDeclaration.cpp" />
     <ClCompile Include="Source\CmVertexIndexData.cpp" />
     <ClCompile Include="Source\CmVertexIndexData.cpp" />
     <ClCompile Include="Source\CmViewport.cpp" />
     <ClCompile Include="Source\CmViewport.cpp" />
     <ClCompile Include="Source\CmWindowEventUtilities.cpp" />
     <ClCompile Include="Source\CmWindowEventUtilities.cpp" />

+ 6 - 12
CamelotRenderer/CamelotRenderer.vcxproj.filters

@@ -173,9 +173,6 @@
     <ClInclude Include="Include\CmGpuProgram.h">
     <ClInclude Include="Include\CmGpuProgram.h">
       <Filter>Header Files\RenderSystem</Filter>
       <Filter>Header Files\RenderSystem</Filter>
     </ClInclude>
     </ClInclude>
-    <ClInclude Include="Include\CmDefaultHardwareBufferManager.h">
-      <Filter>Header Files\RenderSystem</Filter>
-    </ClInclude>
     <ClInclude Include="Include\CmImporter.h">
     <ClInclude Include="Include\CmImporter.h">
       <Filter>Header Files\Importer</Filter>
       <Filter>Header Files\Importer</Filter>
     </ClInclude>
     </ClInclude>
@@ -308,9 +305,6 @@
     <ClInclude Include="Include\CmResourceHandleRTTI.h">
     <ClInclude Include="Include\CmResourceHandleRTTI.h">
       <Filter>Header Files\RTTI</Filter>
       <Filter>Header Files\RTTI</Filter>
     </ClInclude>
     </ClInclude>
-    <ClInclude Include="Include\CmHardwareConstantBuffer.h">
-      <Filter>Header Files\RenderSystem</Filter>
-    </ClInclude>
     <ClInclude Include="Include\CmCommandQueue.h">
     <ClInclude Include="Include\CmCommandQueue.h">
       <Filter>Header Files\RenderSystem</Filter>
       <Filter>Header Files\RenderSystem</Filter>
     </ClInclude>
     </ClInclude>
@@ -359,6 +353,9 @@
     <ClInclude Include="Include\CmGpuParamBlock.h">
     <ClInclude Include="Include\CmGpuParamBlock.h">
       <Filter>Header Files\RenderSystem</Filter>
       <Filter>Header Files\RenderSystem</Filter>
     </ClInclude>
     </ClInclude>
+    <ClInclude Include="Include\CmVertexDeclaration.h">
+      <Filter>Header Files\RenderSystem</Filter>
+    </ClInclude>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\CamelotRenderer.cpp">
     <ClCompile Include="Source\CamelotRenderer.cpp">
@@ -379,9 +376,6 @@
     <ClCompile Include="Source\CmWindowEventUtilities.cpp">
     <ClCompile Include="Source\CmWindowEventUtilities.cpp">
       <Filter>Source Files\Utility</Filter>
       <Filter>Source Files\Utility</Filter>
     </ClCompile>
     </ClCompile>
-    <ClCompile Include="Source\CmDefaultHardwareBufferManager.cpp">
-      <Filter>Source Files\RenderSystem</Filter>
-    </ClCompile>
     <ClCompile Include="Source\CmGpuProgram.cpp">
     <ClCompile Include="Source\CmGpuProgram.cpp">
       <Filter>Source Files\RenderSystem</Filter>
       <Filter>Source Files\RenderSystem</Filter>
     </ClCompile>
     </ClCompile>
@@ -505,9 +499,6 @@
     <ClCompile Include="Source\CmSpecificImporter.cpp">
     <ClCompile Include="Source\CmSpecificImporter.cpp">
       <Filter>Source Files\Importer</Filter>
       <Filter>Source Files\Importer</Filter>
     </ClCompile>
     </ClCompile>
-    <ClCompile Include="Source\CmHardwareConstantBuffer.cpp">
-      <Filter>Source Files\RenderSystem</Filter>
-    </ClCompile>
     <ClCompile Include="Source\CmCommandQueue.cpp">
     <ClCompile Include="Source\CmCommandQueue.cpp">
       <Filter>Source Files\RenderSystem</Filter>
       <Filter>Source Files\RenderSystem</Filter>
     </ClCompile>
     </ClCompile>
@@ -541,5 +532,8 @@
     <ClCompile Include="Source\CmGpuParamBlock.cpp">
     <ClCompile Include="Source\CmGpuParamBlock.cpp">
       <Filter>Source Files\RenderSystem</Filter>
       <Filter>Source Files\RenderSystem</Filter>
     </ClCompile>
     </ClCompile>
+    <ClCompile Include="Source\CmVertexDeclaration.cpp">
+      <Filter>Source Files\RenderSystem</Filter>
+    </ClCompile>
   </ItemGroup>
   </ItemGroup>
 </Project>
 </Project>

+ 0 - 165
CamelotRenderer/Include/CmDefaultHardwareBufferManager.h

@@ -1,165 +0,0 @@
-/*
------------------------------------------------------------------------------
-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 __DefaultHardwareBufferManager_H__
-#define __DefaultHardwareBufferManager_H__
-
-#include "CmPrerequisites.h"
-#include "CmHardwareBufferManager.h"
-#include "CmHardwareVertexBuffer.h"
-#include "CmHardwareIndexBuffer.h"
-#include "CmHardwareConstantBuffer.h"
-
-namespace CamelotEngine {
-	/** \addtogroup Core
-	*  @{
-	*/
-	/** \addtogroup RenderSystem
-	*  @{
-	*/
-
-    /// Specialisation of HardwareVertexBuffer for emulation
-    class CM_EXPORT DefaultHardwareVertexBuffer : public HardwareVertexBuffer 
-    {
-	protected:
-		unsigned char* mpData;
-        /** See HardwareBuffer. */
-        void* lockImpl(UINT32 offset, UINT32 length, LockOptions options);
-        /** See HardwareBuffer. */
-		void unlockImpl(void);
-    public:
-		DefaultHardwareVertexBuffer(UINT32 vertexSize, UINT32 numVertices, HardwareBuffer::Usage usage);
-		DefaultHardwareVertexBuffer(HardwareBufferManagerBase* mgr, UINT32 vertexSize, UINT32 numVertices, 
-            HardwareBuffer::Usage usage);
-        ~DefaultHardwareVertexBuffer();
-        /** See HardwareBuffer. */
-        void readData(UINT32 offset, UINT32 length, void* pDest);
-        /** See HardwareBuffer. */
-        void writeData(UINT32 offset, UINT32 length, const void* pSource,
-				bool discardWholeBuffer = false);
-        /** Override HardwareBuffer to turn off all shadowing. */
-        void* lock(UINT32 offset, UINT32 length, LockOptions options);
-        /** Override HardwareBuffer to turn off all shadowing. */
-		void unlock(void);
-
-
-    };
-
-	/// Specialisation of HardwareIndexBuffer for emulation
-    class CM_EXPORT DefaultHardwareIndexBuffer : public HardwareIndexBuffer
-    {
-	protected:
-		unsigned char* mpData;
-        /** See HardwareBuffer. */
-        void* lockImpl(UINT32 offset, UINT32 length, LockOptions options);
-        /** See HardwareBuffer. */
-		void unlockImpl(void);
-    public:
-		DefaultHardwareIndexBuffer(IndexType idxType, UINT32 numIndexes, HardwareBuffer::Usage usage);
-        ~DefaultHardwareIndexBuffer();
-        /** See HardwareBuffer. */
-        void readData(UINT32 offset, UINT32 length, void* pDest);
-        /** See HardwareBuffer. */
-        void writeData(UINT32 offset, UINT32 length, const void* pSource,
-				bool discardWholeBuffer = false);
-        /** Override HardwareBuffer to turn off all shadowing. */
-        void* lock(UINT32 offset, UINT32 length, LockOptions options);
-        /** Override HardwareBuffer to turn off all shadowing. */
-		void unlock(void);
-
-    };
-
-	/// Specialisation of HardwareConstantBuffer for emulation
-	class CM_EXPORT DefaultHardwareConstantBuffer : public HardwareConstantBuffer
-	{
-	protected:
-		unsigned char* mpData;
-		/** See HardwareBuffer. */
-		void* lockImpl(UINT32 offset, UINT32 length, LockOptions options);
-		/** See HardwareBuffer. */
-		void unlockImpl(void);
-	public:
-		DefaultHardwareConstantBuffer(HardwareBufferManagerBase* mgr, UINT32 sizeBytes, HardwareBuffer::Usage usage);
-		~DefaultHardwareConstantBuffer();
-		/** See HardwareBuffer. */
-		void readData(UINT32 offset, UINT32 length, void* pDest);
-		/** See HardwareBuffer. */
-		void writeData(UINT32 offset, UINT32 length, const void* pSource,
-			bool discardWholeBuffer = false);
-		/** Override HardwareBuffer to turn off all shadowing. */
-		void* lock(UINT32 offset, UINT32 length, LockOptions options);
-		/** Override HardwareBuffer to turn off all shadowing. */
-		void unlock(void);
-	};
-
-	/** Specialisation of HardwareBufferManagerBase to emulate hardware buffers.
-	@remarks
-		You might want to instantiate this class if you want to utilise
-		classes like MeshSerializer without having initialised the 
-		rendering system (which is required to create a 'real' hardware
-		buffer manager.
-	*/
-	class CM_EXPORT DefaultHardwareBufferManagerBase : public HardwareBufferManagerBase
-	{
-    public:
-        DefaultHardwareBufferManagerBase();
-        ~DefaultHardwareBufferManagerBase();
-        /// Creates a hardware vertex buffer
-		HardwareVertexBufferPtr 
-            createVertexBuffer(UINT32 vertexSize, UINT32 numVerts, 
-				HardwareBuffer::Usage usage, bool streamOut = false);
-		/// Create a hardware index buffer
-		HardwareIndexBufferPtr 
-            createIndexBuffer(HardwareIndexBuffer::IndexType itype, UINT32 numIndexes, 
-				HardwareBuffer::Usage usage);
-
-		/** @copydoc HardwareBufferManagerInterface::createGpuParamBlock */
-		GpuParamBlockPtr createGpuParamBlock(const GpuParamBlockDesc& paramDesc);
-    };
-
-	/// DefaultHardwareBufferManager as a Singleton
-	class CM_EXPORT DefaultHardwareBufferManager : public HardwareBufferManager
-	{
-	public:
-		DefaultHardwareBufferManager()
-			: HardwareBufferManager(new DefaultHardwareBufferManagerBase()) 
-		{
-
-		}
-		~DefaultHardwareBufferManager()
-		{
-			delete mImpl;
-		}
-	};
-
-	/** @} */
-	/** @} */
-
-}
-
-#endif

+ 2 - 2
CamelotRenderer/Include/CmGpuParamBlock.h

@@ -8,7 +8,7 @@ namespace CamelotEngine
 	{
 	{
 	public:
 	public:
 		GpuParamBlock(const GpuParamBlockDesc& desc);
 		GpuParamBlock(const GpuParamBlockDesc& desc);
-		~GpuParamBlock();
+		virtual ~GpuParamBlock();
 
 
 		void write(UINT32 offset, const void* data, UINT32 size);
 		void write(UINT32 offset, const void* data, UINT32 size);
 		void zeroOut(UINT32 offset, UINT32 size);
 		void zeroOut(UINT32 offset, UINT32 size);
@@ -20,7 +20,7 @@ namespace CamelotEngine
 		virtual GpuParamBlockPtr clone() const;
 		virtual GpuParamBlockPtr clone() const;
 		
 		
 		static GpuParamBlockPtr create(const GpuParamBlockDesc& desc);
 		static GpuParamBlockPtr create(const GpuParamBlockDesc& desc);
-	private:
+	protected:
 		bool mDirty;
 		bool mDirty;
 		UINT8* mData;
 		UINT8* mData;
 		UINT32 mSize;
 		UINT32 mSize;

+ 0 - 21
CamelotRenderer/Include/CmHardwareConstantBuffer.h

@@ -1,21 +0,0 @@
-#pragma once
-
-#include "CmPrerequisites.h"
-#include "CmHardwareBuffer.h"
-
-namespace CamelotEngine
-{
-	class CM_EXPORT HardwareConstantBuffer : public HardwareBuffer
-	{
-	protected:
-		HardwareBufferManagerBase* mMgr;
-
-	public:
-		/// Should be called by HardwareBufferManager
-		HardwareConstantBuffer(HardwareBufferManagerBase* mgr, UINT32 sizeBytes, HardwareBuffer::Usage usage, bool useSystemMemory);
-		~HardwareConstantBuffer();
-
-		/// Return the manager of this buffer, if any
-		HardwareBufferManagerBase* getManager() const { return mMgr; }
-	};
-}

+ 0 - 384
CamelotRenderer/Include/CmHardwareVertexBuffer.h

@@ -66,390 +66,6 @@ namespace CamelotEngine {
 
 
 	typedef std::shared_ptr<HardwareVertexBuffer> HardwareVertexBufferPtr;
 	typedef std::shared_ptr<HardwareVertexBuffer> HardwareVertexBufferPtr;
 
 
-    /// Vertex element semantics, used to identify the meaning of vertex buffer contents
-	enum VertexElementSemantic {
-		/// Position, 3 reals per vertex
-		VES_POSITION = 1,
-		/// Blending weights
-		VES_BLEND_WEIGHTS = 2,
-        /// Blending indices
-        VES_BLEND_INDICES = 3,
-		/// Normal, 3 reals per vertex
-		VES_NORMAL = 4,
-		/// Diffuse colours
-		VES_DIFFUSE = 5,
-		/// Specular colours
-		VES_SPECULAR = 6,
-		/// Texture coordinates
-		VES_TEXTURE_COORDINATES = 7,
-        /// Binormal (Y axis if normal is Z)
-        VES_BITANGENT = 8,
-        /// Tangent (X axis if normal is Z)
-        VES_TANGENT = 9,
-		/// Transformed vertex position
-		VES_POSITIONT = 10,
-		/// Point size
-		VES_PSIZE = 11
-	};
-
-    /// Vertex element type, used to identify the base types of the vertex contents
-    enum VertexElementType
-    {
-        VET_FLOAT1 = 0,
-        VET_FLOAT2 = 1,
-        VET_FLOAT3 = 2,
-        VET_FLOAT4 = 3,
-        /// alias to more specific color type - use the current rendersystem's color packing
-		VET_COLOR = 4,
-		VET_SHORT1 = 5,
-		VET_SHORT2 = 6,
-		VET_SHORT3 = 7,
-		VET_SHORT4 = 8,
-        VET_UBYTE4 = 9,
-        /// D3D style compact color
-        VET_COLOR_ARGB = 10,
-        /// GL style compact color
-        VET_COLOR_ABGR = 11
-    };
-
-    /** This class declares the usage of a single vertex buffer as a component
-        of a complete VertexDeclaration.
-        @remarks
-        Several vertex buffers can be used to supply the input geometry for a
-        rendering operation, and in each case a vertex buffer can be used in
-        different ways for different operations; the buffer itself does not
-        define the semantics (position, normal etc), the VertexElement
-        class does.
-    */
-	class CM_EXPORT VertexElement
-    {
-    protected:
-        /// The source vertex buffer, as bound to an index using VertexBufferBinding
-        unsigned short mSource;
-        /// The offset in the buffer that this element starts at
-        UINT32 mOffset;
-        /// The type of element
-        VertexElementType mType;
-        /// The meaning of the element
-        VertexElementSemantic mSemantic;
-        /// Index of the item, only applicable for some elements like texture coords
-        unsigned short mIndex;
-    public:
-		/// Constructor, should not be called directly, only needed because of list
-		VertexElement() {}
-        /// Constructor, should not be called directly, call VertexDeclaration::addElement
-        VertexElement(unsigned short source, UINT32 offset, VertexElementType theType,
-            VertexElementSemantic semantic, unsigned short index = 0);
-        /// Gets the vertex buffer index from where this element draws it's values
-        unsigned short getSource(void) const { return mSource; }
-        /// Gets the offset into the buffer where this element starts
-        UINT32 getOffset(void) const { return mOffset; }
-        /// Gets the data format of this element
-        VertexElementType getType(void) const { return mType; }
-        /// Gets the meaning of this element
-        VertexElementSemantic getSemantic(void) const { return mSemantic; }
-        /// Gets the index of this element, only applicable for repeating elements
-        unsigned short getIndex(void) const { return mIndex; }
-		/// Gets the size of this element in bytes
-		UINT32 getSize(void) const;
-		/// Utility method for helping to calculate offsets
-		static UINT32 getTypeSize(VertexElementType etype);
-		/// Utility method which returns the count of values in a given type
-		static unsigned short getTypeCount(VertexElementType etype);
-		/** Simple converter function which will turn a single-value type into a
-			multi-value type based on a parameter.
-		*/
-		static VertexElementType multiplyTypeCount(VertexElementType baseType, unsigned short count);
-		/** Simple converter function which will a type into it's single-value
-			equivalent - makes switches on type easier.
-		*/
-		static VertexElementType getBaseType(VertexElementType multiType);
-
-		/** Utility method for converting colour from
-			one packed 32-bit colour type to another.
-		@param srcType The source type
-		@param dstType The destination type
-		@param ptr Read / write value to change
-		*/
-		static void convertColourValue(VertexElementType srcType,
-			VertexElementType dstType, UINT32* ptr);
-
-		/** Utility method for converting colour to
-			a packed 32-bit colour type.
-		@param src source colour
-		@param dst The destination type
-		*/
-		static UINT32 convertColourValue(const Color& src,
-			VertexElementType dst);
-
-		/** Utility method to get the most appropriate packed colour vertex element format. */
-		static VertexElementType getBestColourVertexElementType(void);
-
-        inline bool operator== (const VertexElement& rhs) const
-        {
-            if (mType != rhs.mType ||
-                mIndex != rhs.mIndex ||
-                mOffset != rhs.mOffset ||
-                mSemantic != rhs.mSemantic ||
-                mSource != rhs.mSource)
-                return false;
-            else
-                return true;
-
-        }
-        /** Adjusts a pointer to the base of a vertex to point at this element.
-        @remarks
-            This variant is for void pointers, passed as a parameter because we can't
-            rely on covariant return types.
-        @param pBase Pointer to the start of a vertex in this buffer.
-        @param pElem Pointer to a pointer which will be set to the start of this element.
-        */
-        inline void baseVertexPointerToElement(void* pBase, void** pElem) const
-        {
-            // The only way we can do this is to cast to char* in order to use byte offset
-            // then cast back to void*.
-            *pElem = static_cast<void*>(
-            	static_cast<unsigned char*>(pBase) + mOffset);
-        }
-        /** Adjusts a pointer to the base of a vertex to point at this element.
-        @remarks
-            This variant is for float pointers, passed as a parameter because we can't
-            rely on covariant return types.
-        @param pBase Pointer to the start of a vertex in this buffer.
-        @param pElem Pointer to a pointer which will be set to the start of this element.
-        */
-        inline void baseVertexPointerToElement(void* pBase, float** pElem) const
-        {
-            // The only way we can do this is to cast to char* in order to use byte offset
-            // then cast back to float*. However we have to go via void* because casting
-            // directly is not allowed
-            *pElem = static_cast<float*>(
-                static_cast<void*>(
-                    static_cast<unsigned char*>(pBase) + mOffset));
-        }
-
-        /** Adjusts a pointer to the base of a vertex to point at this element.
-        @remarks
-            This variant is for RGBA pointers, passed as a parameter because we can't
-            rely on covariant return types.
-        @param pBase Pointer to the start of a vertex in this buffer.
-        @param pElem Pointer to a pointer which will be set to the start of this element.
-        */
-        inline void baseVertexPointerToElement(void* pBase, RGBA** pElem) const
-        {
-            *pElem = static_cast<RGBA*>(
-                static_cast<void*>(
-                    static_cast<unsigned char*>(pBase) + mOffset));
-        }
-        /** Adjusts a pointer to the base of a vertex to point at this element.
-        @remarks
-            This variant is for char pointers, passed as a parameter because we can't
-            rely on covariant return types.
-        @param pBase Pointer to the start of a vertex in this buffer.
-        @param pElem Pointer to a pointer which will be set to the start of this element.
-        */
-        inline void baseVertexPointerToElement(void* pBase, unsigned char** pElem) const
-        {
-            *pElem = static_cast<unsigned char*>(pBase) + mOffset;
-        }
-
-        /** Adjusts a pointer to the base of a vertex to point at this element.
-        @remarks
-        This variant is for UINT16 pointers, passed as a parameter because we can't
-        rely on covariant return types.
-        @param pBase Pointer to the start of a vertex in this buffer.
-        @param pElem Pointer to a pointer which will be set to the start of this element.
-        */
-        inline void baseVertexPointerToElement(void* pBase, unsigned short** pElem) const
-        {
-			*pElem = static_cast<unsigned short*>(
-				static_cast<void*>(
-					static_cast<unsigned char*>(pBase) + mOffset));
-        }
-
-
-    };
-    /** This class declares the format of a set of vertex inputs, which
-        can be issued to the rendering API through a RenderOperation.
-	@remarks
-	You should be aware that the ordering and structure of the
-	VertexDeclaration can be very important on DirectX with older
-	cards,so if you want to maintain maximum compatibility with
-	all render systems and all cards you should be careful to follow these
-	rules:<ol>
-	<li>VertexElements should be added in the following order, and the order of the
-	elements within a shared buffer should be as follows:
-	position, blending weights, normals, diffuse colours, specular colours,
-            texture coordinates (in order, with no gaps)</li>
-	<li>You must not have unused gaps in your buffers which are not referenced
-	by any VertexElement</li>
-	<li>You must not cause the buffer & offset settings of 2 VertexElements to overlap</li>
-	</ol>
-	Whilst GL and more modern graphics cards in D3D will allow you to defy these rules,
-	sticking to them will ensure that your buffers have the maximum compatibility.
-	@par
-	Like the other classes in this functional area, these declarations should be created and
-	destroyed using the HardwareBufferManager.
-    */
-	class CM_EXPORT VertexDeclaration : public IReflectable
-    {
-    public:
-		/// Defines the list of vertex elements that makes up this declaration
-        typedef list<VertexElement>::type VertexElementList;
-        /// Sort routine for vertex elements
-        static bool vertexElementLess(const VertexElement& e1, const VertexElement& e2);
-    protected:
-        VertexElementList mElementList;
-    public:
-        /// Standard constructor, not you should use HardwareBufferManager::createVertexDeclaration
-        VertexDeclaration();
-        virtual ~VertexDeclaration();
-
-        /** Get the number of elements in the declaration. */
-        UINT32 getElementCount(void) { return (UINT32)mElementList.size(); }
-        /** Gets read-only access to the list of vertex elements. */
-        const VertexElementList& getElements(void) const;
-        /** Get a single element. */
-        const VertexElement* getElement(unsigned short index);
-
-        /** Sorts the elements in this list to be compatible with the maximum
-            number of rendering APIs / graphics cards.
-        @remarks
-            Older graphics cards require vertex data to be presented in a more
-            rigid way, as defined in the main documentation for this class. As well
-            as the ordering being important, where shared source buffers are used, the
-            declaration must list all the elements for each source in turn.
-        */
-        void sort(void);
-
-        /** Remove any gaps in the source buffer list used by this declaration.
-        @remarks
-            This is useful if you've modified a declaration and want to remove
-            any gaps in the list of buffers being used. Note, however, that if this
-            declaration is already being used with a VertexBufferBinding, you will
-            need to alter that too. This method is mainly useful when reorganising
-            buffers based on an altered declaration.
-        @note
-            This will cause the vertex declaration to be re-sorted.
-        */
-        void closeGapsInSource(void);
-
-        /** Gets the index of the highest source value referenced by this declaration. */
-        unsigned short getMaxSource(void) const;
-
-
-
-        /** Adds a new VertexElement to this declaration.
-        @remarks
-            This method adds a single element (positions, normals etc) to the end of the
-            vertex declaration. <b>Please read the information in VertexDeclaration about
-	    the importance of ordering and structure for compatibility with older D3D drivers</b>.
-	    @param source The binding index of HardwareVertexBuffer which will provide the source for this element.
-			See VertexBufferBindingState for full information.
-        @param offset The offset in bytes where this element is located in the buffer
-        @param theType The data format of the element (3 floats, a colour etc)
-        @param semantic The meaning of the data (position, normal, diffuse colour etc)
-        @param index Optional index for multi-input elements like texture coordinates
-		@returns A reference to the VertexElement added.
-        */
-        virtual const VertexElement& addElement(unsigned short source, UINT32 offset, VertexElementType theType,
-            VertexElementSemantic semantic, unsigned short index = 0);
-        /** Inserts a new VertexElement at a given position in this declaration.
-        @remarks
-        This method adds a single element (positions, normals etc) at a given position in this
-        vertex declaration. <b>Please read the information in VertexDeclaration about
-        the importance of ordering and structure for compatibility with older D3D drivers</b>.
-        @param source The binding index of HardwareVertexBuffer which will provide the source for this element.
-        See VertexBufferBindingState for full information.
-        @param offset The offset in bytes where this element is located in the buffer
-        @param theType The data format of the element (3 floats, a colour etc)
-        @param semantic The meaning of the data (position, normal, diffuse colour etc)
-        @param index Optional index for multi-input elements like texture coordinates
-        @returns A reference to the VertexElement added.
-        */
-        virtual const VertexElement& insertElement(unsigned short atPosition,
-            unsigned short source, UINT32 offset, VertexElementType theType,
-            VertexElementSemantic semantic, unsigned short index = 0);
-
-        /** Remove the element at the given index from this declaration. */
-        virtual void removeElement(unsigned short elem_index);
-
-        /** Remove the element with the given semantic and usage index.
-        @remarks
-            In this case 'index' means the usage index for repeating elements such
-            as texture coordinates. For other elements this will always be 0 and does
-            not refer to the index in the vector.
-        */
-        virtual void removeElement(VertexElementSemantic semantic, unsigned short index = 0);
-
-		/** Remove all elements. */
-		virtual void removeAllElements(void);
-
-        /** Modify an element in-place, params as addElement.
-	   @remarks
-	   <b>Please read the information in VertexDeclaration about
-	    the importance of ordering and structure for compatibility with older D3D drivers</b>.
-	 */
-        virtual void modifyElement(unsigned short elem_index, unsigned short source, UINT32 offset, VertexElementType theType,
-            VertexElementSemantic semantic, unsigned short index = 0);
-
-		/** Finds a VertexElement with the given semantic, and index if there is more than
-			one element with the same semantic.
-        @remarks
-            If the element is not found, this method returns null.
-		*/
-		virtual const VertexElement* findElementBySemantic(VertexElementSemantic sem, unsigned short index = 0);
-		/** Based on the current elements, gets the size of the vertex for a given buffer source.
-		@param source The buffer binding index for which to get the vertex size.
-		*/
-
-		/** Gets a list of elements which use a given source.
-		@remarks
-			Note that the list of elements is returned by value therefore is separate from
-			the declaration as soon as this method returns.
-		*/
-		virtual VertexElementList findElementsBySource(unsigned short source);
-
-		/** Gets the vertex size defined by this declaration for a given source. */
-        virtual UINT32 getVertexSize(unsigned short source);
-
-        /** Clones this declaration. 
-		@param mgr Optional HardwareBufferManager to use for creating the clone
-			(if null, use the current default).
-		*/
-        virtual VertexDeclarationPtr clone(HardwareBufferManagerBase* mgr = 0);
-
-        inline bool operator== (const VertexDeclaration& rhs) const
-        {
-            if (mElementList.size() != rhs.mElementList.size())
-                return false;
-
-            VertexElementList::const_iterator i, iend, rhsi, rhsiend;
-            iend = mElementList.end();
-            rhsiend = rhs.mElementList.end();
-            rhsi = rhs.mElementList.begin();
-            for (i = mElementList.begin(); i != iend && rhsi != rhsiend; ++i, ++rhsi)
-            {
-                if ( !(*i == *rhsi) )
-                    return false;
-            }
-
-            return true;
-        }
-        inline bool operator!= (const VertexDeclaration& rhs) const
-        {
-            return !(*this == rhs);
-        }
-
-		/************************************************************************/
-		/* 								SERIALIZATION                      		*/
-		/************************************************************************/
-	public:
-		friend class VertexDeclarationRTTI;
-		static RTTITypeBase* getRTTIStatic();
-		virtual RTTITypeBase* getRTTI() const;
-    };
-
 	/** Records the state of all the vertex buffer bindings required to provide a vertex declaration
 	/** Records the state of all the vertex buffer bindings required to provide a vertex declaration
 		with the input data it needs for the vertex elements.
 		with the input data it needs for the vertex elements.
 	@remarks
 	@remarks

+ 1 - 0
CamelotRenderer/Include/CmMeshDataRTTI.h

@@ -4,6 +4,7 @@
 #include "CmRTTIType.h"
 #include "CmRTTIType.h"
 #include "CmMeshData.h"
 #include "CmMeshData.h"
 #include "CmManagedDataBlock.h"
 #include "CmManagedDataBlock.h"
+#include "CmVertexDeclaration.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {

+ 1 - 0
CamelotRenderer/Include/CmRenderOperation.h

@@ -28,6 +28,7 @@ THE SOFTWARE.
 #pragma once
 #pragma once
 
 
 #include "CmPrerequisites.h"
 #include "CmPrerequisites.h"
+#include "CmVertexDeclaration.h"
 #include "CmVertexIndexData.h"
 #include "CmVertexIndexData.h"
 
 
 namespace CamelotEngine {
 namespace CamelotEngine {

+ 391 - 0
CamelotRenderer/Include/CmVertexDeclaration.h

@@ -0,0 +1,391 @@
+#pragma once
+
+#include "CmPrerequisites.h"
+#include "CmColor.h"
+
+namespace CamelotEngine
+{
+	/// Vertex element semantics, used to identify the meaning of vertex buffer contents
+	enum VertexElementSemantic {
+		/// Position, 3 reals per vertex
+		VES_POSITION = 1,
+		/// Blending weights
+		VES_BLEND_WEIGHTS = 2,
+        /// Blending indices
+        VES_BLEND_INDICES = 3,
+		/// Normal, 3 reals per vertex
+		VES_NORMAL = 4,
+		/// Diffuse colours
+		VES_DIFFUSE = 5,
+		/// Specular colours
+		VES_SPECULAR = 6,
+		/// Texture coordinates
+		VES_TEXTURE_COORDINATES = 7,
+        /// Binormal (Y axis if normal is Z)
+        VES_BITANGENT = 8,
+        /// Tangent (X axis if normal is Z)
+        VES_TANGENT = 9,
+		/// Transformed vertex position
+		VES_POSITIONT = 10,
+		/// Point size
+		VES_PSIZE = 11
+	};
+
+    /// Vertex element type, used to identify the base types of the vertex contents
+    enum VertexElementType
+    {
+        VET_FLOAT1 = 0,
+        VET_FLOAT2 = 1,
+        VET_FLOAT3 = 2,
+        VET_FLOAT4 = 3,
+        /// alias to more specific color type - use the current rendersystem's color packing
+		VET_COLOR = 4,
+		VET_SHORT1 = 5,
+		VET_SHORT2 = 6,
+		VET_SHORT3 = 7,
+		VET_SHORT4 = 8,
+        VET_UBYTE4 = 9,
+        /// D3D style compact color
+        VET_COLOR_ARGB = 10,
+        /// GL style compact color
+        VET_COLOR_ABGR = 11
+    };
+
+    /** This class declares the usage of a single vertex buffer as a component
+        of a complete VertexDeclaration.
+        @remarks
+        Several vertex buffers can be used to supply the input geometry for a
+        rendering operation, and in each case a vertex buffer can be used in
+        different ways for different operations; the buffer itself does not
+        define the semantics (position, normal etc), the VertexElement
+        class does.
+    */
+	class CM_EXPORT VertexElement
+    {
+    protected:
+        /// The source vertex buffer, as bound to an index using VertexBufferBinding
+        unsigned short mSource;
+        /// The offset in the buffer that this element starts at
+        UINT32 mOffset;
+        /// The type of element
+        VertexElementType mType;
+        /// The meaning of the element
+        VertexElementSemantic mSemantic;
+        /// Index of the item, only applicable for some elements like texture coords
+        unsigned short mIndex;
+    public:
+		/// Constructor, should not be called directly, only needed because of list
+		VertexElement() {}
+        /// Constructor, should not be called directly, call VertexDeclaration::addElement
+        VertexElement(unsigned short source, UINT32 offset, VertexElementType theType,
+            VertexElementSemantic semantic, unsigned short index = 0);
+        /// Gets the vertex buffer index from where this element draws it's values
+        unsigned short getSource(void) const { return mSource; }
+        /// Gets the offset into the buffer where this element starts
+        UINT32 getOffset(void) const { return mOffset; }
+        /// Gets the data format of this element
+        VertexElementType getType(void) const { return mType; }
+        /// Gets the meaning of this element
+        VertexElementSemantic getSemantic(void) const { return mSemantic; }
+        /// Gets the index of this element, only applicable for repeating elements
+        unsigned short getIndex(void) const { return mIndex; }
+		/// Gets the size of this element in bytes
+		UINT32 getSize(void) const;
+		/// Utility method for helping to calculate offsets
+		static UINT32 getTypeSize(VertexElementType etype);
+		/// Utility method which returns the count of values in a given type
+		static unsigned short getTypeCount(VertexElementType etype);
+		/** Simple converter function which will turn a single-value type into a
+			multi-value type based on a parameter.
+		*/
+		static VertexElementType multiplyTypeCount(VertexElementType baseType, unsigned short count);
+		/** Simple converter function which will a type into it's single-value
+			equivalent - makes switches on type easier.
+		*/
+		static VertexElementType getBaseType(VertexElementType multiType);
+
+		/** Utility method for converting colour from
+			one packed 32-bit colour type to another.
+		@param srcType The source type
+		@param dstType The destination type
+		@param ptr Read / write value to change
+		*/
+		static void convertColourValue(VertexElementType srcType,
+			VertexElementType dstType, UINT32* ptr);
+
+		/** Utility method for converting colour to
+			a packed 32-bit colour type.
+		@param src source colour
+		@param dst The destination type
+		*/
+		static UINT32 convertColourValue(const Color& src,
+			VertexElementType dst);
+
+		/** Utility method to get the most appropriate packed colour vertex element format. */
+		static VertexElementType getBestColourVertexElementType(void);
+
+        inline bool operator== (const VertexElement& rhs) const
+        {
+            if (mType != rhs.mType ||
+                mIndex != rhs.mIndex ||
+                mOffset != rhs.mOffset ||
+                mSemantic != rhs.mSemantic ||
+                mSource != rhs.mSource)
+                return false;
+            else
+                return true;
+
+        }
+        /** Adjusts a pointer to the base of a vertex to point at this element.
+        @remarks
+            This variant is for void pointers, passed as a parameter because we can't
+            rely on covariant return types.
+        @param pBase Pointer to the start of a vertex in this buffer.
+        @param pElem Pointer to a pointer which will be set to the start of this element.
+        */
+        inline void baseVertexPointerToElement(void* pBase, void** pElem) const
+        {
+            // The only way we can do this is to cast to char* in order to use byte offset
+            // then cast back to void*.
+            *pElem = static_cast<void*>(
+            	static_cast<unsigned char*>(pBase) + mOffset);
+        }
+        /** Adjusts a pointer to the base of a vertex to point at this element.
+        @remarks
+            This variant is for float pointers, passed as a parameter because we can't
+            rely on covariant return types.
+        @param pBase Pointer to the start of a vertex in this buffer.
+        @param pElem Pointer to a pointer which will be set to the start of this element.
+        */
+        inline void baseVertexPointerToElement(void* pBase, float** pElem) const
+        {
+            // The only way we can do this is to cast to char* in order to use byte offset
+            // then cast back to float*. However we have to go via void* because casting
+            // directly is not allowed
+            *pElem = static_cast<float*>(
+                static_cast<void*>(
+                    static_cast<unsigned char*>(pBase) + mOffset));
+        }
+
+        /** Adjusts a pointer to the base of a vertex to point at this element.
+        @remarks
+            This variant is for RGBA pointers, passed as a parameter because we can't
+            rely on covariant return types.
+        @param pBase Pointer to the start of a vertex in this buffer.
+        @param pElem Pointer to a pointer which will be set to the start of this element.
+        */
+        inline void baseVertexPointerToElement(void* pBase, RGBA** pElem) const
+        {
+            *pElem = static_cast<RGBA*>(
+                static_cast<void*>(
+                    static_cast<unsigned char*>(pBase) + mOffset));
+        }
+        /** Adjusts a pointer to the base of a vertex to point at this element.
+        @remarks
+            This variant is for char pointers, passed as a parameter because we can't
+            rely on covariant return types.
+        @param pBase Pointer to the start of a vertex in this buffer.
+        @param pElem Pointer to a pointer which will be set to the start of this element.
+        */
+        inline void baseVertexPointerToElement(void* pBase, unsigned char** pElem) const
+        {
+            *pElem = static_cast<unsigned char*>(pBase) + mOffset;
+        }
+
+        /** Adjusts a pointer to the base of a vertex to point at this element.
+        @remarks
+        This variant is for UINT16 pointers, passed as a parameter because we can't
+        rely on covariant return types.
+        @param pBase Pointer to the start of a vertex in this buffer.
+        @param pElem Pointer to a pointer which will be set to the start of this element.
+        */
+        inline void baseVertexPointerToElement(void* pBase, unsigned short** pElem) const
+        {
+			*pElem = static_cast<unsigned short*>(
+				static_cast<void*>(
+					static_cast<unsigned char*>(pBase) + mOffset));
+        }
+
+
+    };
+    /** This class declares the format of a set of vertex inputs, which
+        can be issued to the rendering API through a RenderOperation.
+	@remarks
+	You should be aware that the ordering and structure of the
+	VertexDeclaration can be very important on DirectX with older
+	cards,so if you want to maintain maximum compatibility with
+	all render systems and all cards you should be careful to follow these
+	rules:<ol>
+	<li>VertexElements should be added in the following order, and the order of the
+	elements within a shared buffer should be as follows:
+	position, blending weights, normals, diffuse colours, specular colours,
+            texture coordinates (in order, with no gaps)</li>
+	<li>You must not have unused gaps in your buffers which are not referenced
+	by any VertexElement</li>
+	<li>You must not cause the buffer & offset settings of 2 VertexElements to overlap</li>
+	</ol>
+	Whilst GL and more modern graphics cards in D3D will allow you to defy these rules,
+	sticking to them will ensure that your buffers have the maximum compatibility.
+	@par
+	Like the other classes in this functional area, these declarations should be created and
+	destroyed using the HardwareBufferManager.
+    */
+	class CM_EXPORT VertexDeclaration : public IReflectable
+    {
+    public:
+		/// Defines the list of vertex elements that makes up this declaration
+        typedef list<VertexElement>::type VertexElementList;
+        /// Sort routine for vertex elements
+        static bool vertexElementLess(const VertexElement& e1, const VertexElement& e2);
+    protected:
+        VertexElementList mElementList;
+    public:
+        /// Standard constructor, not you should use HardwareBufferManager::createVertexDeclaration
+        VertexDeclaration();
+        virtual ~VertexDeclaration();
+
+        /** Get the number of elements in the declaration. */
+        UINT32 getElementCount(void) { return (UINT32)mElementList.size(); }
+        /** Gets read-only access to the list of vertex elements. */
+        const VertexElementList& getElements(void) const;
+        /** Get a single element. */
+        const VertexElement* getElement(unsigned short index);
+
+        /** Sorts the elements in this list to be compatible with the maximum
+            number of rendering APIs / graphics cards.
+        @remarks
+            Older graphics cards require vertex data to be presented in a more
+            rigid way, as defined in the main documentation for this class. As well
+            as the ordering being important, where shared source buffers are used, the
+            declaration must list all the elements for each source in turn.
+        */
+        void sort(void);
+
+        /** Remove any gaps in the source buffer list used by this declaration.
+        @remarks
+            This is useful if you've modified a declaration and want to remove
+            any gaps in the list of buffers being used. Note, however, that if this
+            declaration is already being used with a VertexBufferBinding, you will
+            need to alter that too. This method is mainly useful when reorganising
+            buffers based on an altered declaration.
+        @note
+            This will cause the vertex declaration to be re-sorted.
+        */
+        void closeGapsInSource(void);
+
+        /** Gets the index of the highest source value referenced by this declaration. */
+        unsigned short getMaxSource(void) const;
+
+
+
+        /** Adds a new VertexElement to this declaration.
+        @remarks
+            This method adds a single element (positions, normals etc) to the end of the
+            vertex declaration. <b>Please read the information in VertexDeclaration about
+	    the importance of ordering and structure for compatibility with older D3D drivers</b>.
+	    @param source The binding index of HardwareVertexBuffer which will provide the source for this element.
+			See VertexBufferBindingState for full information.
+        @param offset The offset in bytes where this element is located in the buffer
+        @param theType The data format of the element (3 floats, a colour etc)
+        @param semantic The meaning of the data (position, normal, diffuse colour etc)
+        @param index Optional index for multi-input elements like texture coordinates
+		@returns A reference to the VertexElement added.
+        */
+        virtual const VertexElement& addElement(unsigned short source, UINT32 offset, VertexElementType theType,
+            VertexElementSemantic semantic, unsigned short index = 0);
+        /** Inserts a new VertexElement at a given position in this declaration.
+        @remarks
+        This method adds a single element (positions, normals etc) at a given position in this
+        vertex declaration. <b>Please read the information in VertexDeclaration about
+        the importance of ordering and structure for compatibility with older D3D drivers</b>.
+        @param source The binding index of HardwareVertexBuffer which will provide the source for this element.
+        See VertexBufferBindingState for full information.
+        @param offset The offset in bytes where this element is located in the buffer
+        @param theType The data format of the element (3 floats, a colour etc)
+        @param semantic The meaning of the data (position, normal, diffuse colour etc)
+        @param index Optional index for multi-input elements like texture coordinates
+        @returns A reference to the VertexElement added.
+        */
+        virtual const VertexElement& insertElement(unsigned short atPosition,
+            unsigned short source, UINT32 offset, VertexElementType theType,
+            VertexElementSemantic semantic, unsigned short index = 0);
+
+        /** Remove the element at the given index from this declaration. */
+        virtual void removeElement(unsigned short elem_index);
+
+        /** Remove the element with the given semantic and usage index.
+        @remarks
+            In this case 'index' means the usage index for repeating elements such
+            as texture coordinates. For other elements this will always be 0 and does
+            not refer to the index in the vector.
+        */
+        virtual void removeElement(VertexElementSemantic semantic, unsigned short index = 0);
+
+		/** Remove all elements. */
+		virtual void removeAllElements(void);
+
+        /** Modify an element in-place, params as addElement.
+	   @remarks
+	   <b>Please read the information in VertexDeclaration about
+	    the importance of ordering and structure for compatibility with older D3D drivers</b>.
+	 */
+        virtual void modifyElement(unsigned short elem_index, unsigned short source, UINT32 offset, VertexElementType theType,
+            VertexElementSemantic semantic, unsigned short index = 0);
+
+		/** Finds a VertexElement with the given semantic, and index if there is more than
+			one element with the same semantic.
+        @remarks
+            If the element is not found, this method returns null.
+		*/
+		virtual const VertexElement* findElementBySemantic(VertexElementSemantic sem, unsigned short index = 0);
+		/** Based on the current elements, gets the size of the vertex for a given buffer source.
+		@param source The buffer binding index for which to get the vertex size.
+		*/
+
+		/** Gets a list of elements which use a given source.
+		@remarks
+			Note that the list of elements is returned by value therefore is separate from
+			the declaration as soon as this method returns.
+		*/
+		virtual VertexElementList findElementsBySource(unsigned short source);
+
+		/** Gets the vertex size defined by this declaration for a given source. */
+        virtual UINT32 getVertexSize(unsigned short source);
+
+        /** Clones this declaration. 
+		@param mgr Optional HardwareBufferManager to use for creating the clone
+			(if null, use the current default).
+		*/
+        virtual VertexDeclarationPtr clone(HardwareBufferManagerBase* mgr = 0);
+
+        inline bool operator== (const VertexDeclaration& rhs) const
+        {
+            if (mElementList.size() != rhs.mElementList.size())
+                return false;
+
+            VertexElementList::const_iterator i, iend, rhsi, rhsiend;
+            iend = mElementList.end();
+            rhsiend = rhs.mElementList.end();
+            rhsi = rhs.mElementList.begin();
+            for (i = mElementList.begin(); i != iend && rhsi != rhsiend; ++i, ++rhsi)
+            {
+                if ( !(*i == *rhsi) )
+                    return false;
+            }
+
+            return true;
+        }
+        inline bool operator!= (const VertexDeclaration& rhs) const
+        {
+            return !(*this == rhs);
+        }
+
+		/************************************************************************/
+		/* 								SERIALIZATION                      		*/
+		/************************************************************************/
+	public:
+		friend class VertexDeclarationRTTI;
+		static RTTITypeBase* getRTTIStatic();
+		virtual RTTITypeBase* getRTTI() const;
+    };
+}

+ 1 - 0
CamelotRenderer/Include/CmVertexIndexData.h

@@ -29,6 +29,7 @@ THE SOFTWARE.
 #define __VertexIndexData_H__
 #define __VertexIndexData_H__
 
 
 #include "CmPrerequisites.h"
 #include "CmPrerequisites.h"
+#include "CmVertexDeclaration.h"
 #include "CmHardwareVertexBuffer.h"
 #include "CmHardwareVertexBuffer.h"
 #include "CmHardwareIndexBuffer.h"
 #include "CmHardwareIndexBuffer.h"
 
 

+ 0 - 222
CamelotRenderer/Source/CmDefaultHardwareBufferManager.cpp

@@ -1,222 +0,0 @@
-/*
------------------------------------------------------------------------------
-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 "CmDefaultHardwareBufferManager.h"
-
-namespace CamelotEngine {
-
-	DefaultHardwareVertexBuffer::DefaultHardwareVertexBuffer(UINT32 vertexSize, UINT32 numVertices, 
-															 HardwareBuffer::Usage usage)
-	: HardwareVertexBuffer(0, vertexSize, numVertices, usage, true)
-	{
-        // Allocate aligned memory for better SIMD processing friendly.
-        mpData = static_cast<unsigned char*>(_aligned_malloc(mSizeInBytes, CM_SIMD_ALIGNMENT));
-	}
-	//-----------------------------------------------------------------------
-	DefaultHardwareVertexBuffer::DefaultHardwareVertexBuffer(HardwareBufferManagerBase* mgr, UINT32 vertexSize, UINT32 numVertices, 
-		HardwareBuffer::Usage usage)
-        : HardwareVertexBuffer(mgr, vertexSize, numVertices, usage, true)
-	{
-        // Allocate aligned memory for better SIMD processing friendly.
-        mpData = static_cast<unsigned char*>(_aligned_malloc(mSizeInBytes, CM_SIMD_ALIGNMENT));
-	}
-	//-----------------------------------------------------------------------
-    DefaultHardwareVertexBuffer::~DefaultHardwareVertexBuffer()
-	{
-		_aligned_free(mpData);
-	}
-	//-----------------------------------------------------------------------
-    void* DefaultHardwareVertexBuffer::lockImpl(UINT32 offset, UINT32 length, LockOptions options)
-	{
-        // Only for use internally, no 'locking' as such
-		return mpData + offset;
-	}
-	//-----------------------------------------------------------------------
-	void DefaultHardwareVertexBuffer::unlockImpl(void)
-	{
-        // Nothing to do
-	}
-	//-----------------------------------------------------------------------
-    void* DefaultHardwareVertexBuffer::lock(UINT32 offset, UINT32 length, LockOptions options)
-	{
-        mIsLocked = true;
-		return mpData + offset;
-	}
-	//-----------------------------------------------------------------------
-	void DefaultHardwareVertexBuffer::unlock(void)
-	{
-        mIsLocked = false;
-        // Nothing to do
-	}
-	//-----------------------------------------------------------------------
-    void DefaultHardwareVertexBuffer::readData(UINT32 offset, UINT32 length, void* pDest)
-	{
-		assert((offset + length) <= mSizeInBytes);
-		memcpy(pDest, mpData + offset, length);
-	}
-	//-----------------------------------------------------------------------
-    void DefaultHardwareVertexBuffer::writeData(UINT32 offset, UINT32 length, const void* pSource,
-			bool discardWholeBuffer)
-	{
-		assert((offset + length) <= mSizeInBytes);
-		// ignore discard, memory is not guaranteed to be zeroised
-		memcpy(mpData + offset, pSource, length);
-
-	}
-	//-----------------------------------------------------------------------
-
-	DefaultHardwareIndexBuffer::DefaultHardwareIndexBuffer(IndexType idxType, 
-		UINT32 numIndexes, HardwareBuffer::Usage usage) 
-		: HardwareIndexBuffer(0, idxType, numIndexes, usage, true)
-	{
-		mpData = (unsigned char*)malloc(sizeof(unsigned char) * mSizeInBytes);
-	}
-	//-----------------------------------------------------------------------
-    DefaultHardwareIndexBuffer::~DefaultHardwareIndexBuffer()
-	{
-		free(mpData);
-	}
-	//-----------------------------------------------------------------------
-    void* DefaultHardwareIndexBuffer::lockImpl(UINT32 offset, UINT32 length, LockOptions options)
-	{
-        // Only for use internally, no 'locking' as such
-		return mpData + offset;
-	}
-	//-----------------------------------------------------------------------
-	void DefaultHardwareIndexBuffer::unlockImpl(void)
-	{
-        // Nothing to do
-	}
-	//-----------------------------------------------------------------------
-    void* DefaultHardwareIndexBuffer::lock(UINT32 offset, UINT32 length, LockOptions options)
-	{
-        mIsLocked = true;
-		return mpData + offset;
-	}
-	//-----------------------------------------------------------------------
-	void DefaultHardwareIndexBuffer::unlock(void)
-	{
-        mIsLocked = false;
-        // Nothing to do
-	}
-	//-----------------------------------------------------------------------
-    void DefaultHardwareIndexBuffer::readData(UINT32 offset, UINT32 length, void* pDest)
-	{
-		assert((offset + length) <= mSizeInBytes);
-		memcpy(pDest, mpData + offset, length);
-	}
-	//-----------------------------------------------------------------------
-    void DefaultHardwareIndexBuffer::writeData(UINT32 offset, UINT32 length, const void* pSource,
-			bool discardWholeBuffer)
-	{
-		assert((offset + length) <= mSizeInBytes);
-		// ignore discard, memory is not guaranteed to be zeroised
-		memcpy(mpData + offset, pSource, length);
-
-	}
-	//-----------------------------------------------------------------------
-	DefaultHardwareConstantBuffer::DefaultHardwareConstantBuffer(HardwareBufferManagerBase* mgr, UINT32 sizeBytes, HardwareBuffer::Usage usage)
-		: HardwareConstantBuffer(mgr, sizeBytes, usage, true)
-	{
-		// Allocate aligned memory for better SIMD processing friendly.
-		mpData = static_cast<unsigned char*>(_aligned_malloc(mSizeInBytes, CM_SIMD_ALIGNMENT));
-	}
-	//-----------------------------------------------------------------------
-	DefaultHardwareConstantBuffer::~DefaultHardwareConstantBuffer()
-	{
-		_aligned_free(mpData);
-	}
-	//-----------------------------------------------------------------------
-	void* DefaultHardwareConstantBuffer::lockImpl(UINT32 offset, UINT32 length, LockOptions options)
-	{
-		// Only for use internally, no 'locking' as such
-		return mpData + offset;
-	}
-	//-----------------------------------------------------------------------
-	void DefaultHardwareConstantBuffer::unlockImpl(void)
-	{
-		// Nothing to do
-	}
-	//-----------------------------------------------------------------------
-	void* DefaultHardwareConstantBuffer::lock(UINT32 offset, UINT32 length, LockOptions options)
-	{
-		mIsLocked = true;
-		return mpData + offset;
-	}
-	//-----------------------------------------------------------------------
-	void DefaultHardwareConstantBuffer::unlock(void)
-	{
-		mIsLocked = false;
-		// Nothing to do
-	}
-	//-----------------------------------------------------------------------
-	void DefaultHardwareConstantBuffer::readData(UINT32 offset, UINT32 length, void* pDest)
-	{
-		assert((offset + length) <= mSizeInBytes);
-		memcpy(pDest, mpData + offset, length);
-	}
-	//-----------------------------------------------------------------------
-	void DefaultHardwareConstantBuffer::writeData(UINT32 offset, UINT32 length, const void* pSource,
-		bool discardWholeBuffer)
-	{
-		assert((offset + length) <= mSizeInBytes);
-		// ignore discard, memory is not guaranteed to be zeroised
-		memcpy(mpData + offset, pSource, length);
-
-	}
-    //-----------------------------------------------------------------------
-    DefaultHardwareBufferManagerBase::DefaultHardwareBufferManagerBase()
-	{
-	}
-    //-----------------------------------------------------------------------
-    DefaultHardwareBufferManagerBase::~DefaultHardwareBufferManagerBase()
-	{
-        destroyAllBindings(); 
-	}
-    //-----------------------------------------------------------------------
-	HardwareVertexBufferPtr 
-        DefaultHardwareBufferManagerBase::createVertexBuffer(UINT32 vertexSize, 
-		UINT32 numVerts, HardwareBuffer::Usage usage, bool streamOut)
-	{
-        DefaultHardwareVertexBuffer* vb = new DefaultHardwareVertexBuffer(this, vertexSize, numVerts, usage);
-        return HardwareVertexBufferPtr(vb);
-	}
-    //-----------------------------------------------------------------------
-	HardwareIndexBufferPtr 
-        DefaultHardwareBufferManagerBase::createIndexBuffer(HardwareIndexBuffer::IndexType itype, 
-		UINT32 numIndexes, HardwareBuffer::Usage usage)
-	{
-        DefaultHardwareIndexBuffer* ib = new DefaultHardwareIndexBuffer(itype, numIndexes, usage);
-		return HardwareIndexBufferPtr(ib);
-	}
-	//-----------------------------------------------------------------------
-	GpuParamBlockPtr DefaultHardwareBufferManagerBase::createGpuParamBlock(const GpuParamBlockDesc& paramDesc)
-	{
-		return GpuParamBlockPtr(new GpuParamBlock(paramDesc));
-	}
-}

+ 1 - 2
CamelotRenderer/Source/CmHardwareBufferManager.cpp

@@ -28,8 +28,7 @@ THE SOFTWARE.
 
 
 #include "CmHardwareBufferManager.h"
 #include "CmHardwareBufferManager.h"
 #include "CmVertexIndexData.h"
 #include "CmVertexIndexData.h"
-#include "CmHardwareConstantBuffer.h"
-
+#include "CmVertexDeclaration.h"
 
 
 namespace CamelotEngine {
 namespace CamelotEngine {
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------

+ 0 - 17
CamelotRenderer/Source/CmHardwareConstantBuffer.cpp

@@ -1,17 +0,0 @@
-#include "CmHardwareConstantBuffer.h"
-#include "CmHardwareBufferManager.h"
-
-namespace CamelotEngine
-{
-	HardwareConstantBuffer::HardwareConstantBuffer(HardwareBufferManagerBase* mgr, UINT32 sizeBytes, HardwareBuffer::Usage usage, bool useSystemMemory)
-		: HardwareBuffer(usage, useSystemMemory)
-	{
-		// Calculate the size of the vertices
-		mSizeInBytes = sizeBytes;
-	}
-
-	HardwareConstantBuffer::~HardwareConstantBuffer()
-	{
-
-	}
-}

+ 0 - 2
CamelotRenderer/Source/CmHardwareIndexBuffer.cpp

@@ -28,8 +28,6 @@ THE SOFTWARE.
 
 
 #include "CmHardwareIndexBuffer.h"
 #include "CmHardwareIndexBuffer.h"
 #include "CmHardwareBufferManager.h"
 #include "CmHardwareBufferManager.h"
-#include "CmDefaultHardwareBufferManager.h"
-
 
 
 namespace CamelotEngine {
 namespace CamelotEngine {
 
 

+ 0 - 446
CamelotRenderer/Source/CmHardwareVertexBuffer.cpp

@@ -30,7 +30,6 @@ THE SOFTWARE.
 #include "CmColor.h"
 #include "CmColor.h"
 #include "CmException.h"
 #include "CmException.h"
 #include "CmHardwareBufferManager.h"
 #include "CmHardwareBufferManager.h"
-#include "CmDefaultHardwareBufferManager.h"
 #include "CmRenderSystem.h"
 #include "CmRenderSystem.h"
 #include "CmVertexDeclarationRTTI.h"
 #include "CmVertexDeclarationRTTI.h"
 
 
@@ -57,451 +56,6 @@ namespace CamelotEngine {
 			mMgr->_notifyVertexBufferDestroyed(this);
 			mMgr->_notifyVertexBufferDestroyed(this);
 		}
 		}
     }
     }
-    //-----------------------------------------------------------------------------
-    VertexElement::VertexElement(unsigned short source, UINT32 offset, 
-        VertexElementType theType, VertexElementSemantic semantic, unsigned short index)
-        : mSource(source), mOffset(offset), mType(theType), 
-        mSemantic(semantic), mIndex(index)
-    {
-    }
-    //-----------------------------------------------------------------------------
-	UINT32 VertexElement::getSize(void) const
-	{
-		return getTypeSize(mType);
-	}
-	//-----------------------------------------------------------------------------
-	UINT32 VertexElement::getTypeSize(VertexElementType etype)
-	{
-		switch(etype)
-		{
-		case VET_COLOR:
-		case VET_COLOR_ABGR:
-		case VET_COLOR_ARGB:
-			return sizeof(RGBA);
-		case VET_FLOAT1:
-			return sizeof(float);
-		case VET_FLOAT2:
-			return sizeof(float)*2;
-		case VET_FLOAT3:
-			return sizeof(float)*3;
-		case VET_FLOAT4:
-			return sizeof(float)*4;
-		case VET_SHORT1:
-			return sizeof(short);
-		case VET_SHORT2:
-			return sizeof(short)*2;
-		case VET_SHORT3:
-			return sizeof(short)*3;
-		case VET_SHORT4:
-			return sizeof(short)*4;
-        case VET_UBYTE4:
-            return sizeof(unsigned char)*4;
-		}
-		return 0;
-	}
-	//-----------------------------------------------------------------------------
-	unsigned short VertexElement::getTypeCount(VertexElementType etype)
-	{
-		switch (etype)
-		{
-		case VET_COLOR:
-		case VET_COLOR_ABGR:
-		case VET_COLOR_ARGB:
-			return 1;
-		case VET_FLOAT1:
-			return 1;
-		case VET_FLOAT2:
-			return 2;
-		case VET_FLOAT3:
-			return 3;
-		case VET_FLOAT4:
-			return 4;
-		case VET_SHORT1:
-			return 1;
-		case VET_SHORT2:
-			return 2;
-		case VET_SHORT3:
-			return 3;
-		case VET_SHORT4:
-			return 4;
-        case VET_UBYTE4:
-            return 4;
-		}
-		CM_EXCEPT(InvalidParametersException, "Invalid type");
-	}
-	//-----------------------------------------------------------------------------
-	VertexElementType VertexElement::multiplyTypeCount(VertexElementType baseType, 
-		unsigned short count)
-	{
-		switch (baseType)
-		{
-		case VET_FLOAT1:
-			switch(count)
-			{
-			case 1:
-				return VET_FLOAT1;
-			case 2:
-				return VET_FLOAT2;
-			case 3:
-				return VET_FLOAT3;
-			case 4:
-				return VET_FLOAT4;
-            default:
-                break;
-			}
-			break;
-		case VET_SHORT1:
-			switch(count)
-			{
-			case 1:
-				return VET_SHORT1;
-			case 2:
-				return VET_SHORT2;
-			case 3:
-				return VET_SHORT3;
-			case 4:
-				return VET_SHORT4;
-            default:
-                break;
-			}
-			break;
-        default:
-            break;
-		}
-		CM_EXCEPT(InvalidParametersException, "Invalid base type");
-	}
-	//--------------------------------------------------------------------------
-	VertexElementType VertexElement::getBestColourVertexElementType(void)
-	{
-		// Use the current render system to determine if possible
-		if (CamelotEngine::RenderSystem::instancePtr())
-		{
-			return CamelotEngine::RenderSystem::instancePtr()->getColorVertexElementType();
-		}
-		else
-		{
-			// We can't know the specific type right now, so pick a type
-			// based on platform
-#if CM_PLATFORM == CM_PLATFORM_WIN32
-			return VET_COLOR_ARGB; // prefer D3D format on windows
-#else
-			return VET_COLOR_ABGR; // prefer GL format on everything else
-#endif
-
-		}
-	}
-	//--------------------------------------------------------------------------
-	void VertexElement::convertColourValue(VertexElementType srcType, 
-		VertexElementType dstType, UINT32* ptr)
-	{
-		if (srcType == dstType)
-			return;
-
-		// Conversion between ARGB and ABGR is always a case of flipping R/B
-		*ptr = 
-		   ((*ptr&0x00FF0000)>>16)|((*ptr&0x000000FF)<<16)|(*ptr&0xFF00FF00);				
-	}
-	//--------------------------------------------------------------------------
-	UINT32 VertexElement::convertColourValue(const Color& src, 
-		VertexElementType dst)
-	{
-		switch(dst)
-		{
-#if CM_PLATFORM == CM_PLATFORM_WIN32
-        default:
-#endif
-		case VET_COLOR_ARGB:
-			return src.getAsARGB();
-#if CM_PLATFORM != CM_PLATFORM_WIN32
-        default:
-#endif
-		case VET_COLOR_ABGR: 
-			return src.getAsABGR();
-		};
-
-	}
-	//-----------------------------------------------------------------------------
-	VertexElementType VertexElement::getBaseType(VertexElementType multiType)
-	{
-		switch (multiType)
-		{
-			case VET_FLOAT1:
-			case VET_FLOAT2:
-			case VET_FLOAT3:
-			case VET_FLOAT4:
-				return VET_FLOAT1;
-			case VET_COLOR:
-				return VET_COLOR;
-			case VET_COLOR_ABGR:
-				return VET_COLOR_ABGR;
-			case VET_COLOR_ARGB:
-				return VET_COLOR_ARGB;
-			case VET_SHORT1:
-			case VET_SHORT2:
-			case VET_SHORT3:
-			case VET_SHORT4:
-				return VET_SHORT1;
-			case VET_UBYTE4:
-				return VET_UBYTE4;
-		};
-        // To keep compiler happy
-        return VET_FLOAT1;
-	}
-	//-----------------------------------------------------------------------------
-    VertexDeclaration::VertexDeclaration()
-    {
-    }
-    //-----------------------------------------------------------------------------
-    VertexDeclaration::~VertexDeclaration()
-    {
-    }
-    //-----------------------------------------------------------------------------
-    const VertexDeclaration::VertexElementList& VertexDeclaration::getElements(void) const
-    {
-        return mElementList;
-    }
-    //-----------------------------------------------------------------------------
-    const VertexElement& VertexDeclaration::addElement(unsigned short source, 
-        UINT32 offset, VertexElementType theType,
-        VertexElementSemantic semantic, unsigned short index)
-    {
-		// Refine colour type to a specific type
-		if (theType == VET_COLOR)
-		{
-			theType = VertexElement::getBestColourVertexElementType();
-		}
-        mElementList.push_back(
-            VertexElement(source, offset, theType, semantic, index)
-            );
-		return mElementList.back();
-    }
-    //-----------------------------------------------------------------------------
-    const VertexElement& VertexDeclaration::insertElement(unsigned short atPosition,
-        unsigned short source, UINT32 offset, VertexElementType theType,
-        VertexElementSemantic semantic, unsigned short index)
-    {
-        if (atPosition >= mElementList.size())
-        {
-            return addElement(source, offset, theType, semantic, index);
-        }
-
-        VertexElementList::iterator i = mElementList.begin();
-        for (unsigned short n = 0; n < atPosition; ++n)
-            ++i;
-
-        i = mElementList.insert(i, 
-            VertexElement(source, offset, theType, semantic, index));
-        return *i;
-
-    }
-    //-----------------------------------------------------------------------------
-    const VertexElement* VertexDeclaration::getElement(unsigned short index)
-    {
-        assert(index < mElementList.size() && "Index out of bounds");
-
-        VertexElementList::iterator i = mElementList.begin();
-        for (unsigned short n = 0; n < index; ++n)
-            ++i;
-
-        return &(*i);
-
-    }
-    //-----------------------------------------------------------------------------
-    void VertexDeclaration::removeElement(unsigned short elem_index)
-    {
-        assert(elem_index < mElementList.size() && "Index out of bounds");
-        VertexElementList::iterator i = mElementList.begin();
-        for (unsigned short n = 0; n < elem_index; ++n)
-            ++i;
-        mElementList.erase(i);
-    }
-    //-----------------------------------------------------------------------------
-    void VertexDeclaration::removeElement(VertexElementSemantic semantic, unsigned short index)
-    {
-		VertexElementList::iterator ei, eiend;
-		eiend = mElementList.end();
-		for (ei = mElementList.begin(); ei != eiend; ++ei)
-		{
-			if (ei->getSemantic() == semantic && ei->getIndex() == index)
-			{
-				mElementList.erase(ei);
-                break;
-			}
-		}
-    }
-	//-----------------------------------------------------------------------------
-	void VertexDeclaration::removeAllElements(void)
-	{
-		mElementList.clear();
-	}
-    //-----------------------------------------------------------------------------
-    void VertexDeclaration::modifyElement(unsigned short elem_index, 
-        unsigned short source, UINT32 offset, VertexElementType theType,
-        VertexElementSemantic semantic, unsigned short index)
-    {
-        assert(elem_index < mElementList.size() && "Index out of bounds");
-        VertexElementList::iterator i = mElementList.begin();
-        std::advance(i, elem_index);
-        (*i) = VertexElement(source, offset, theType, semantic, index);
-    }
-    //-----------------------------------------------------------------------------
-	const VertexElement* VertexDeclaration::findElementBySemantic(
-		VertexElementSemantic sem, unsigned short index)
-	{
-		VertexElementList::const_iterator ei, eiend;
-		eiend = mElementList.end();
-		for (ei = mElementList.begin(); ei != eiend; ++ei)
-		{
-			if (ei->getSemantic() == sem && ei->getIndex() == index)
-			{
-				return &(*ei);
-			}
-		}
-
-		return NULL;
-
-
-	}
-	//-----------------------------------------------------------------------------
-	VertexDeclaration::VertexElementList VertexDeclaration::findElementsBySource(
-		unsigned short source)
-	{
-		VertexElementList retList;
-		VertexElementList::const_iterator ei, eiend;
-		eiend = mElementList.end();
-		for (ei = mElementList.begin(); ei != eiend; ++ei)
-		{
-			if (ei->getSource() == source)
-			{
-				retList.push_back(*ei);
-			}
-		}
-		return retList;
-
-	}
-
-	//-----------------------------------------------------------------------------
-	UINT32 VertexDeclaration::getVertexSize(unsigned short source)
-	{
-		VertexElementList::const_iterator i, iend;
-		iend = mElementList.end();
-		UINT32 sz = 0;
-
-		for (i = mElementList.begin(); i != iend; ++i)
-		{
-			if (i->getSource() == source)
-			{
-				sz += i->getSize();
-
-			}
-		}
-		return sz;
-	}
-    //-----------------------------------------------------------------------------
-    VertexDeclarationPtr VertexDeclaration::clone(HardwareBufferManagerBase* mgr)
-    {
-		HardwareBufferManagerBase* pManager = mgr ? mgr : HardwareBufferManager::instancePtr(); 
-        VertexDeclarationPtr ret = pManager->createVertexDeclaration();
-
-		VertexElementList::const_iterator i, iend;
-		iend = mElementList.end();
-		for (i = mElementList.begin(); i != iend; ++i)
-		{
-            ret->addElement(i->getSource(), i->getOffset(), i->getType(), i->getSemantic(), i->getIndex());
-        }
-        return ret;
-    }
-    //-----------------------------------------------------------------------------
-    // Sort routine for VertexElement
-    bool VertexDeclaration::vertexElementLess(const VertexElement& e1, const VertexElement& e2)
-    {
-        // Sort by source first
-        if (e1.getSource() < e2.getSource())
-        {
-            return true;
-        }
-        else if (e1.getSource() == e2.getSource())
-        {
-            // Use ordering of semantics to sort
-            if (e1.getSemantic() < e2.getSemantic())
-            {
-                return true;
-            }
-            else if (e1.getSemantic() == e2.getSemantic())
-            {
-                // Use index to sort
-                if (e1.getIndex() < e2.getIndex())
-                {
-                    return true;
-                }
-            }
-        }
-        return false;
-    }
-    void VertexDeclaration::sort(void)
-    {
-        mElementList.sort(VertexDeclaration::vertexElementLess);
-    }
-    //-----------------------------------------------------------------------------
-    void VertexDeclaration::closeGapsInSource(void)
-    {
-        if (mElementList.empty())
-            return;
-
-        // Sort first
-        sort();
-
-        VertexElementList::iterator i, iend;
-        iend = mElementList.end();
-        unsigned short targetIdx = 0;
-        unsigned short lastIdx = getElement(0)->getSource();
-        unsigned short c = 0;
-        for (i = mElementList.begin(); i != iend; ++i, ++c)
-        {
-            VertexElement& elem = *i;
-            if (lastIdx != elem.getSource())
-            {
-                targetIdx++;
-                lastIdx = elem.getSource();
-            }
-            if (targetIdx != elem.getSource())
-            {
-                modifyElement(c, targetIdx, elem.getOffset(), elem.getType(), 
-                    elem.getSemantic(), elem.getIndex());
-            }
-
-        }
-
-    }
-    //-----------------------------------------------------------------------------
-    unsigned short VertexDeclaration::getMaxSource(void) const
-    {
-        VertexElementList::const_iterator i, iend;
-        iend = mElementList.end();
-        unsigned short ret = 0;
-        for (i = mElementList.begin(); i != iend; ++i)
-        {
-            if (i->getSource() > ret)
-            {
-                ret = i->getSource();
-            }
-
-        }
-        return ret;
-    }
-	/************************************************************************/
-	/* 								SERIALIZATION                      		*/
-	/************************************************************************/
-	RTTITypeBase* VertexDeclaration::getRTTIStatic()
-	{
-		return VertexDeclarationRTTI::instance();
-	}
-
-	RTTITypeBase* VertexDeclaration::getRTTI() const
-	{
-		return getRTTIStatic();
-	}
-
     //-----------------------------------------------------------------------------
     //-----------------------------------------------------------------------------
 	VertexBufferBinding::VertexBufferBinding() : mHighIndex(0)
 	VertexBufferBinding::VertexBufferBinding() : mHighIndex(0)
 	{
 	{

+ 447 - 0
CamelotRenderer/Source/CmVertexDeclaration.cpp

@@ -0,0 +1,447 @@
+#include "CmVertexDeclaration.h"
+#include "CmVertexDeclarationRTTI.h"
+#include "CmHardwareBufferManager.h"
+#include "CmRenderSystem.h"
+
+namespace CamelotEngine
+{
+	VertexElement::VertexElement(unsigned short source, UINT32 offset, 
+		VertexElementType theType, VertexElementSemantic semantic, unsigned short index)
+		: mSource(source), mOffset(offset), mType(theType), 
+		mSemantic(semantic), mIndex(index)
+	{
+	}
+	//-----------------------------------------------------------------------------
+	UINT32 VertexElement::getSize(void) const
+	{
+		return getTypeSize(mType);
+	}
+	//-----------------------------------------------------------------------------
+	UINT32 VertexElement::getTypeSize(VertexElementType etype)
+	{
+		switch(etype)
+		{
+		case VET_COLOR:
+		case VET_COLOR_ABGR:
+		case VET_COLOR_ARGB:
+			return sizeof(RGBA);
+		case VET_FLOAT1:
+			return sizeof(float);
+		case VET_FLOAT2:
+			return sizeof(float)*2;
+		case VET_FLOAT3:
+			return sizeof(float)*3;
+		case VET_FLOAT4:
+			return sizeof(float)*4;
+		case VET_SHORT1:
+			return sizeof(short);
+		case VET_SHORT2:
+			return sizeof(short)*2;
+		case VET_SHORT3:
+			return sizeof(short)*3;
+		case VET_SHORT4:
+			return sizeof(short)*4;
+		case VET_UBYTE4:
+			return sizeof(unsigned char)*4;
+		}
+		return 0;
+	}
+	//-----------------------------------------------------------------------------
+	unsigned short VertexElement::getTypeCount(VertexElementType etype)
+	{
+		switch (etype)
+		{
+		case VET_COLOR:
+		case VET_COLOR_ABGR:
+		case VET_COLOR_ARGB:
+			return 1;
+		case VET_FLOAT1:
+			return 1;
+		case VET_FLOAT2:
+			return 2;
+		case VET_FLOAT3:
+			return 3;
+		case VET_FLOAT4:
+			return 4;
+		case VET_SHORT1:
+			return 1;
+		case VET_SHORT2:
+			return 2;
+		case VET_SHORT3:
+			return 3;
+		case VET_SHORT4:
+			return 4;
+		case VET_UBYTE4:
+			return 4;
+		}
+		CM_EXCEPT(InvalidParametersException, "Invalid type");
+	}
+	//-----------------------------------------------------------------------------
+	VertexElementType VertexElement::multiplyTypeCount(VertexElementType baseType, 
+		unsigned short count)
+	{
+		switch (baseType)
+		{
+		case VET_FLOAT1:
+			switch(count)
+			{
+			case 1:
+				return VET_FLOAT1;
+			case 2:
+				return VET_FLOAT2;
+			case 3:
+				return VET_FLOAT3;
+			case 4:
+				return VET_FLOAT4;
+			default:
+				break;
+			}
+			break;
+		case VET_SHORT1:
+			switch(count)
+			{
+			case 1:
+				return VET_SHORT1;
+			case 2:
+				return VET_SHORT2;
+			case 3:
+				return VET_SHORT3;
+			case 4:
+				return VET_SHORT4;
+			default:
+				break;
+			}
+			break;
+		default:
+			break;
+		}
+		CM_EXCEPT(InvalidParametersException, "Invalid base type");
+	}
+	//--------------------------------------------------------------------------
+	VertexElementType VertexElement::getBestColourVertexElementType(void)
+	{
+		// Use the current render system to determine if possible
+		if (CamelotEngine::RenderSystem::instancePtr())
+		{
+			return CamelotEngine::RenderSystem::instancePtr()->getColorVertexElementType();
+		}
+		else
+		{
+			// We can't know the specific type right now, so pick a type
+			// based on platform
+#if CM_PLATFORM == CM_PLATFORM_WIN32
+			return VET_COLOR_ARGB; // prefer D3D format on windows
+#else
+			return VET_COLOR_ABGR; // prefer GL format on everything else
+#endif
+
+		}
+	}
+	//--------------------------------------------------------------------------
+	void VertexElement::convertColourValue(VertexElementType srcType, 
+		VertexElementType dstType, UINT32* ptr)
+	{
+		if (srcType == dstType)
+			return;
+
+		// Conversion between ARGB and ABGR is always a case of flipping R/B
+		*ptr = 
+			((*ptr&0x00FF0000)>>16)|((*ptr&0x000000FF)<<16)|(*ptr&0xFF00FF00);				
+	}
+	//--------------------------------------------------------------------------
+	UINT32 VertexElement::convertColourValue(const Color& src, 
+		VertexElementType dst)
+	{
+		switch(dst)
+		{
+#if CM_PLATFORM == CM_PLATFORM_WIN32
+		default:
+#endif
+		case VET_COLOR_ARGB:
+			return src.getAsARGB();
+#if CM_PLATFORM != CM_PLATFORM_WIN32
+		default:
+#endif
+		case VET_COLOR_ABGR: 
+			return src.getAsABGR();
+		};
+
+	}
+	//-----------------------------------------------------------------------------
+	VertexElementType VertexElement::getBaseType(VertexElementType multiType)
+	{
+		switch (multiType)
+		{
+		case VET_FLOAT1:
+		case VET_FLOAT2:
+		case VET_FLOAT3:
+		case VET_FLOAT4:
+			return VET_FLOAT1;
+		case VET_COLOR:
+			return VET_COLOR;
+		case VET_COLOR_ABGR:
+			return VET_COLOR_ABGR;
+		case VET_COLOR_ARGB:
+			return VET_COLOR_ARGB;
+		case VET_SHORT1:
+		case VET_SHORT2:
+		case VET_SHORT3:
+		case VET_SHORT4:
+			return VET_SHORT1;
+		case VET_UBYTE4:
+			return VET_UBYTE4;
+		};
+		// To keep compiler happy
+		return VET_FLOAT1;
+	}
+	//-----------------------------------------------------------------------------
+	VertexDeclaration::VertexDeclaration()
+	{
+	}
+	//-----------------------------------------------------------------------------
+	VertexDeclaration::~VertexDeclaration()
+	{
+	}
+	//-----------------------------------------------------------------------------
+	const VertexDeclaration::VertexElementList& VertexDeclaration::getElements(void) const
+	{
+		return mElementList;
+	}
+	//-----------------------------------------------------------------------------
+	const VertexElement& VertexDeclaration::addElement(unsigned short source, 
+		UINT32 offset, VertexElementType theType,
+		VertexElementSemantic semantic, unsigned short index)
+	{
+		// Refine colour type to a specific type
+		if (theType == VET_COLOR)
+		{
+			theType = VertexElement::getBestColourVertexElementType();
+		}
+		mElementList.push_back(
+			VertexElement(source, offset, theType, semantic, index)
+			);
+		return mElementList.back();
+	}
+	//-----------------------------------------------------------------------------
+	const VertexElement& VertexDeclaration::insertElement(unsigned short atPosition,
+		unsigned short source, UINT32 offset, VertexElementType theType,
+		VertexElementSemantic semantic, unsigned short index)
+	{
+		if (atPosition >= mElementList.size())
+		{
+			return addElement(source, offset, theType, semantic, index);
+		}
+
+		VertexElementList::iterator i = mElementList.begin();
+		for (unsigned short n = 0; n < atPosition; ++n)
+			++i;
+
+		i = mElementList.insert(i, 
+			VertexElement(source, offset, theType, semantic, index));
+		return *i;
+
+	}
+	//-----------------------------------------------------------------------------
+	const VertexElement* VertexDeclaration::getElement(unsigned short index)
+	{
+		assert(index < mElementList.size() && "Index out of bounds");
+
+		VertexElementList::iterator i = mElementList.begin();
+		for (unsigned short n = 0; n < index; ++n)
+			++i;
+
+		return &(*i);
+
+	}
+	//-----------------------------------------------------------------------------
+	void VertexDeclaration::removeElement(unsigned short elem_index)
+	{
+		assert(elem_index < mElementList.size() && "Index out of bounds");
+		VertexElementList::iterator i = mElementList.begin();
+		for (unsigned short n = 0; n < elem_index; ++n)
+			++i;
+		mElementList.erase(i);
+	}
+	//-----------------------------------------------------------------------------
+	void VertexDeclaration::removeElement(VertexElementSemantic semantic, unsigned short index)
+	{
+		VertexElementList::iterator ei, eiend;
+		eiend = mElementList.end();
+		for (ei = mElementList.begin(); ei != eiend; ++ei)
+		{
+			if (ei->getSemantic() == semantic && ei->getIndex() == index)
+			{
+				mElementList.erase(ei);
+				break;
+			}
+		}
+	}
+	//-----------------------------------------------------------------------------
+	void VertexDeclaration::removeAllElements(void)
+	{
+		mElementList.clear();
+	}
+	//-----------------------------------------------------------------------------
+	void VertexDeclaration::modifyElement(unsigned short elem_index, 
+		unsigned short source, UINT32 offset, VertexElementType theType,
+		VertexElementSemantic semantic, unsigned short index)
+	{
+		assert(elem_index < mElementList.size() && "Index out of bounds");
+		VertexElementList::iterator i = mElementList.begin();
+		std::advance(i, elem_index);
+		(*i) = VertexElement(source, offset, theType, semantic, index);
+	}
+	//-----------------------------------------------------------------------------
+	const VertexElement* VertexDeclaration::findElementBySemantic(
+		VertexElementSemantic sem, unsigned short index)
+	{
+		VertexElementList::const_iterator ei, eiend;
+		eiend = mElementList.end();
+		for (ei = mElementList.begin(); ei != eiend; ++ei)
+		{
+			if (ei->getSemantic() == sem && ei->getIndex() == index)
+			{
+				return &(*ei);
+			}
+		}
+
+		return NULL;
+	}
+	//-----------------------------------------------------------------------------
+	VertexDeclaration::VertexElementList VertexDeclaration::findElementsBySource(
+		unsigned short source)
+	{
+		VertexElementList retList;
+		VertexElementList::const_iterator ei, eiend;
+		eiend = mElementList.end();
+		for (ei = mElementList.begin(); ei != eiend; ++ei)
+		{
+			if (ei->getSource() == source)
+			{
+				retList.push_back(*ei);
+			}
+		}
+		return retList;
+	}
+	//-----------------------------------------------------------------------------
+	UINT32 VertexDeclaration::getVertexSize(unsigned short source)
+	{
+		VertexElementList::const_iterator i, iend;
+		iend = mElementList.end();
+		UINT32 sz = 0;
+
+		for (i = mElementList.begin(); i != iend; ++i)
+		{
+			if (i->getSource() == source)
+			{
+				sz += i->getSize();
+
+			}
+		}
+		return sz;
+	}
+	//-----------------------------------------------------------------------------
+	VertexDeclarationPtr VertexDeclaration::clone(HardwareBufferManagerBase* mgr)
+	{
+		HardwareBufferManagerBase* pManager = mgr ? mgr : HardwareBufferManager::instancePtr(); 
+		VertexDeclarationPtr ret = pManager->createVertexDeclaration();
+
+		VertexElementList::const_iterator i, iend;
+		iend = mElementList.end();
+		for (i = mElementList.begin(); i != iend; ++i)
+		{
+			ret->addElement(i->getSource(), i->getOffset(), i->getType(), i->getSemantic(), i->getIndex());
+		}
+		return ret;
+	}
+	//-----------------------------------------------------------------------------
+	// Sort routine for VertexElement
+	bool VertexDeclaration::vertexElementLess(const VertexElement& e1, const VertexElement& e2)
+	{
+		// Sort by source first
+		if (e1.getSource() < e2.getSource())
+		{
+			return true;
+		}
+		else if (e1.getSource() == e2.getSource())
+		{
+			// Use ordering of semantics to sort
+			if (e1.getSemantic() < e2.getSemantic())
+			{
+				return true;
+			}
+			else if (e1.getSemantic() == e2.getSemantic())
+			{
+				// Use index to sort
+				if (e1.getIndex() < e2.getIndex())
+				{
+					return true;
+				}
+			}
+		}
+		return false;
+	}
+	void VertexDeclaration::sort(void)
+	{
+		mElementList.sort(VertexDeclaration::vertexElementLess);
+	}
+	//-----------------------------------------------------------------------------
+	void VertexDeclaration::closeGapsInSource(void)
+	{
+		if (mElementList.empty())
+			return;
+
+		// Sort first
+		sort();
+
+		VertexElementList::iterator i, iend;
+		iend = mElementList.end();
+		unsigned short targetIdx = 0;
+		unsigned short lastIdx = getElement(0)->getSource();
+		unsigned short c = 0;
+		for (i = mElementList.begin(); i != iend; ++i, ++c)
+		{
+			VertexElement& elem = *i;
+			if (lastIdx != elem.getSource())
+			{
+				targetIdx++;
+				lastIdx = elem.getSource();
+			}
+			if (targetIdx != elem.getSource())
+			{
+				modifyElement(c, targetIdx, elem.getOffset(), elem.getType(), 
+					elem.getSemantic(), elem.getIndex());
+			}
+
+		}
+
+	}
+	//-----------------------------------------------------------------------------
+	unsigned short VertexDeclaration::getMaxSource(void) const
+	{
+		VertexElementList::const_iterator i, iend;
+		iend = mElementList.end();
+		unsigned short ret = 0;
+		for (i = mElementList.begin(); i != iend; ++i)
+		{
+			if (i->getSource() > ret)
+			{
+				ret = i->getSource();
+			}
+
+		}
+		return ret;
+	}
+	/************************************************************************/
+	/* 								SERIALIZATION                      		*/
+	/************************************************************************/
+	RTTITypeBase* VertexDeclaration::getRTTIStatic()
+	{
+		return VertexDeclarationRTTI::instance();
+	}
+
+	RTTITypeBase* VertexDeclaration::getRTTI() const
+	{
+		return getRTTIStatic();
+	}
+}