1 // Copyright 2009 Dolphin Emulator Project 2 // Licensed under GPLv2+ 3 // Refer to the license.txt file included. 4 5 #pragma once 6 7 #include <array> 8 #include <cstddef> 9 10 #include "Common/CommonTypes.h" 11 #include "VideoBackends/Software/Vec3.h" 12 13 struct Vec4 14 { 15 float x; 16 float y; 17 float z; 18 float w; 19 }; 20 21 struct InputVertexData 22 { 23 u8 posMtx; 24 std::array<u8, 8> texMtx; 25 26 Vec3 position; 27 std::array<Vec3, 3> normal; 28 std::array<std::array<u8, 4>, 2> color; 29 std::array<std::array<float, 2>, 8> texCoords; 30 }; 31 32 struct OutputVertexData 33 { 34 // components in color channels 35 enum 36 { 37 RED_C, 38 GRN_C, 39 BLU_C, 40 ALP_C 41 }; 42 43 Vec3 mvPosition = {}; 44 Vec4 projectedPosition = {}; 45 Vec3 screenPosition = {}; 46 std::array<Vec3, 3> normal{}; 47 std::array<std::array<u8, 4>, 2> color{}; 48 std::array<Vec3, 8> texCoords{}; 49 LerpOutputVertexData50 void Lerp(float t, const OutputVertexData* a, const OutputVertexData* b) 51 { 52 #define LINTERP(T, OUT, IN) (OUT) + ((IN - OUT) * T) 53 54 #define LINTERP_INT(T, OUT, IN) (OUT) + (((IN - OUT) * T) >> 8) 55 56 mvPosition = LINTERP(t, a->mvPosition, b->mvPosition); 57 58 projectedPosition.x = LINTERP(t, a->projectedPosition.x, b->projectedPosition.x); 59 projectedPosition.y = LINTERP(t, a->projectedPosition.y, b->projectedPosition.y); 60 projectedPosition.z = LINTERP(t, a->projectedPosition.z, b->projectedPosition.z); 61 projectedPosition.w = LINTERP(t, a->projectedPosition.w, b->projectedPosition.w); 62 63 for (std::size_t i = 0; i < normal.size(); ++i) 64 { 65 normal[i] = LINTERP(t, a->normal[i], b->normal[i]); 66 } 67 68 const u16 t_int = static_cast<u16>(t * 256); 69 for (std::size_t i = 0; i < color[0].size(); ++i) 70 { 71 color[0][i] = LINTERP_INT(t_int, a->color[0][i], b->color[0][i]); 72 color[1][i] = LINTERP_INT(t_int, a->color[1][i], b->color[1][i]); 73 } 74 75 for (std::size_t i = 0; i < texCoords.size(); ++i) 76 { 77 texCoords[i] = LINTERP(t, a->texCoords[i], b->texCoords[i]); 78 } 79 80 #undef LINTERP 81 #undef LINTERP_INT 82 } 83 }; 84