Browse Source

Added automatic conversion of RGBA color to BGRA for DirectX9 vertex color

Marko Pintera 12 years ago
parent
commit
a3234b2fed

+ 8 - 0
CamelotCore/Include/CmVertexBuffer.h

@@ -54,6 +54,14 @@ namespace CamelotFramework
         UINT32 getVertexSize(void) const { return mVertexSize; }
         /// Get the number of vertices in this buffer
         UINT32 getNumVertices(void) const { return mNumVertices; }
+
+		/**
+		 * @brief	Some render systems expect vertex color bits in an order different than
+		 * 			RGBA, in which case override this to flip the RGB order.
+		 */
+		virtual bool vertexColorReqRGBFlip() { return false; }
+
+		static const int MAX_SEMANTIC_IDX = 8;
 	protected:
 		HardwareBufferManager* mMgr;
 		UINT32 mNumVertices;

+ 20 - 0
CamelotCore/Source/CmMesh.cpp

@@ -90,6 +90,26 @@ namespace CamelotFramework
 
 			memcpy(vertBufferData, srcVertBufferData, bufferSize);
 
+			if(vertexBuffer->vertexColorReqRGBFlip())
+			{
+				UINT32 vertexStride = meshData.getVertexStride(i);
+				for(INT32 semanticIdx = 0; semanticIdx < VertexBuffer::MAX_SEMANTIC_IDX; semanticIdx++)
+				{
+					if(!meshData.hasElement(VES_COLOR, semanticIdx, i))
+						continue;
+
+					UINT8* colorData = vertBufferData + meshData.getElementOffset(VES_COLOR, semanticIdx, i);
+					for(UINT32 j = 0; j < mVertexData->vertexCount; j++)
+					{
+						UINT32* curColor = (UINT32*)colorData;
+
+						(*curColor) = ((*curColor) & 0xFF00FF00) | ((*curColor >> 16) & 0x000000FF) | ((*curColor << 16) & 0x00FF0000);
+
+						colorData += vertexStride;
+					}
+				}
+			}
+
 			vertexBuffer->unlock();
 		}
 	}

+ 1 - 0
CamelotD3D9Renderer/Include/CmD3D9VertexBuffer.h

@@ -64,6 +64,7 @@ namespace CamelotFramework {
         /// Get D3D9-specific vertex buffer
         IDirect3DVertexBuffer9* getD3D9VertexBuffer(void);
 
+		virtual bool vertexColorReqRGBFlip() { return true; }
 	protected:	
 		struct BufferResources
 		{