소스 검색

Use OpenGL convention in vertex colors to avoid need for different vertex data depending on the API.

Lasse Öörni 14 년 전
부모
커밋
d82608a889
3개의 변경된 파일13개의 추가작업 그리고 10개의 파일을 삭제
  1. 11 3
      Engine/Graphics/Direct3D9/D3D9Graphics.cpp
  2. 1 1
      Engine/Graphics/Direct3D9/D3D9VertexDeclaration.cpp
  3. 1 6
      Engine/Math/Color.h

+ 11 - 3
Engine/Graphics/Direct3D9/D3D9Graphics.cpp

@@ -149,6 +149,15 @@ static const DWORD windowStyle = WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME & ~WS_MAXI
 
 static LRESULT CALLBACK wndProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam);
 
+static unsigned GetD3DColor(const Color& color)
+{
+    unsigned r = (unsigned)(Clamp(color.r_ * 255.0f, 0.0f, 255.0f));
+    unsigned g = (unsigned)(Clamp(color.g_ * 255.0f, 0.0f, 255.0f));
+    unsigned b = (unsigned)(Clamp(color.b_ * 255.0f, 0.0f, 255.0f));
+    unsigned a = (unsigned)(Clamp(color.a_ * 255.0f, 0.0f, 255.0f));
+    return (((a) & 0xff) << 24) | (((r) & 0xff) << 16) | (((g) & 0xff) << 8) | ((b) & 0xff);
+}
+
 OBJECTTYPESTATIC(Graphics);
 
 Graphics::Graphics(Context* context) :
@@ -592,10 +601,9 @@ void Graphics::Clear(unsigned flags, const Color& color, float depth, unsigned s
     if (flags & CLEAR_STENCIL)
         d3dFlags |= D3DCLEAR_STENCIL;
 
-    impl_->device_->Clear(0, 0, d3dFlags, color.ToUInt(), depth, stencil);
+    impl_->device_->Clear(0, 0, d3dFlags, GetD3DColor(color), depth, stencil);
 }
 
-
 void Graphics::Draw(PrimitiveType type, unsigned vertexStart, unsigned vertexCount)
 {
     if (!vertexCount)
@@ -1246,7 +1254,7 @@ void Graphics::SetTexture(unsigned index, Texture* texture)
             const Color& borderColor = texture->GetBorderColor();
             if (borderColor != impl_->borderColors_[index])
             {
-                impl_->device_->SetSamplerState(index, D3DSAMP_BORDERCOLOR, borderColor.ToUInt());
+                impl_->device_->SetSamplerState(index, D3DSAMP_BORDERCOLOR, GetD3DColor(borderColor));
                 impl_->borderColors_[index] = borderColor;
             }
         }

+ 1 - 1
Engine/Graphics/Direct3D9/D3D9VertexDeclaration.cpp

@@ -33,7 +33,7 @@ const BYTE d3dElementType[] =
 {
     D3DDECLTYPE_FLOAT3, // Position
     D3DDECLTYPE_FLOAT3, // Normal
-    D3DDECLTYPE_D3DCOLOR, // Color
+    D3DDECLTYPE_UBYTE4N, // Color
     D3DDECLTYPE_FLOAT2, // Texcoord1
     D3DDECLTYPE_FLOAT2, // Texcoord2
     D3DDECLTYPE_FLOAT3, // Cubetexcoord1

+ 1 - 6
Engine/Math/Color.h

@@ -121,12 +121,7 @@ public:
         unsigned g = (unsigned)(Clamp(g_ * 255.0f, 0.0f, 255.0f));
         unsigned b = (unsigned)(Clamp(b_ * 255.0f, 0.0f, 255.0f));
         unsigned a = (unsigned)(Clamp(a_ * 255.0f, 0.0f, 255.0f));
-        /// \todo Model data will need to be converted on OpenGL if it has vertex colors
-        #ifdef USE_OPENGL
-            return (((a) & 0xff) << 24) | (((b) & 0xff) << 16) | (((g) & 0xff) << 8) | ((r) & 0xff);
-        #else
-            return (((a) & 0xff) << 24) | (((r) & 0xff) << 16) | (((g) & 0xff) << 8) | ((b) & 0xff);
-        #endif
+        return (((a) & 0xff) << 24) | (((b) & 0xff) << 16) | (((g) & 0xff) << 8) | ((r) & 0xff);
     }
     
     /// Return as a four-dimensional vector.