Quellcode durchsuchen

Move utils functions to headers

Daniele Bartolini vor 12 Jahren
Ursprung
Commit
acb754a3c6
2 geänderte Dateien mit 108 neuen und 4 gelöschten Zeilen
  1. 79 2
      engine/renderers/PixelFormat.h
  2. 29 2
      engine/renderers/VertexFormat.h

+ 79 - 2
engine/renderers/PixelFormat.h

@@ -104,10 +104,87 @@ class Pixel
 public:
 public:
 
 
 	/// Returns the bytes occupied by @a format
 	/// Returns the bytes occupied by @a format
-	static size_t bytes_per_pixel(PixelFormat format);
+	static size_t bytes_per_pixel(PixelFormat format)
+	{
+		switch (format)
+		{
+			case PF_L_8:
+			case PF_RGB_3_3_2:
+			case PF_BGR_2_3_3:
+			{
+				return 1;
+			}
+			case PF_L_16:
+			case PF_LA_8:
+			case PF_AL_8:
+			case PF_RGB_5_6_5:
+			case PF_BGR_5_6_5:
+			case PF_RGBA_4_4_4_4:
+			case PF_RGBA_5_5_5_1:
+			case PF_ABGR_4_4_4_4:
+			case PF_ABGR_1_5_5_5:
+			{
+				return 2;
+			}
+			case PF_RGB_8:
+			case PF_BGR_8:
+			{
+				return 3;
+			}
+			case PF_L_32:
+			case PF_L_FLOAT_32:
+			case PF_LA_16:
+			case PF_AL_16:
+			case PF_RGBA_8:
+			case PF_RGBA_8_8_8_8:
+			case PF_RGBA_10_10_10_2:
+			case PF_ABGR_8:
+			case PF_ABGR_8_8_8_8:
+			case PF_ABGR_2_10_10_10:
+			{
+				return 4;
+			}
+			case PF_RGB_16:
+			case PF_BGR_16:
+			{
+				return 6;
+			}
+			case PF_LA_32:
+			case PF_LA_FLOAT_32:
+			case PF_AL_32:
+			case PF_AL_FLOAT_32:
+			case PF_RGBA_16:
+			case PF_ABGR_16:
+			{
+				return 8;
+			}
+			case PF_RGB_32:
+			case PF_RGB_FLOAT_32:
+			case PF_BGR_32:
+			case PF_BGR_FLOAT_32:
+			{
+				return 12;
+			}
+			case PF_RGBA_32:
+			case PF_RGBA_FLOAT_32:
+			case PF_ABGR_32:
+			case PF_ABGR_FLOAT_32:
+			{
+				return 16;
+			}
+			case PF_UNKNOWN:
+			default:
+			{
+				return 0;
+			}
+		}
+	}
 
 
 	/// Returns the bits occupied by @a format
 	/// Returns the bits occupied by @a format
-	static size_t bits_per_pixel(PixelFormat format);
+	static size_t bits_per_pixel(PixelFormat format)
+	{
+		return bytes_per_pixel(format) * 8;
+	}
 
 
 private:
 private:
 
 

+ 29 - 2
engine/renderers/VertexFormat.h

@@ -48,10 +48,37 @@ class Vertex
 public:
 public:
 
 
 	/// Returns the bytes occupied by @a format
 	/// Returns the bytes occupied by @a format
-	static size_t bytes_per_vertex(VertexFormat format);
+	static size_t bytes_per_vertex(VertexFormat format)
+	{
+		switch (format)
+		{
+			case VF_XY_FLOAT_32:
+			case VF_UV_FLOAT_32:
+			{
+				return 8;
+			}
+			case VF_XYZ_FLOAT_32:
+			case VF_UVT_FLOAT_32:
+			case VF_XYZ_NORMAL_FLOAT_32:
+			{
+				return 12;
+			}
+			case VF_XYZ_UV_XYZ_NORMAL_FLOAT_32:
+			{
+				return 32;
+			}
+			default:
+			{
+				return 0;
+			}
+		}
+	}
 
 
 	/// Returns the bits occupied by @a format
 	/// Returns the bits occupied by @a format
-	static size_t bits_per_vertex(VertexFormat format);
+	static size_t bits_per_vertex(VertexFormat format)
+	{
+		return bytes_per_vertex(format) * 8;
+	}
 
 
 private:
 private: