NativeVertexFormat.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright 2009 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <array>
  5. #include <cstddef>
  6. #include "Common/CommonTypes.h"
  7. #include "VideoBackends/Software/Vec3.h"
  8. struct Vec4
  9. {
  10. float x;
  11. float y;
  12. float z;
  13. float w;
  14. };
  15. struct InputVertexData
  16. {
  17. u8 posMtx;
  18. std::array<u8, 8> texMtx;
  19. Vec3 position;
  20. std::array<Vec3, 3> normal;
  21. std::array<std::array<u8, 4>, 2> color;
  22. std::array<std::array<float, 2>, 8> texCoords;
  23. };
  24. struct OutputVertexData
  25. {
  26. // components in color channels
  27. enum
  28. {
  29. RED_C,
  30. GRN_C,
  31. BLU_C,
  32. ALP_C
  33. };
  34. Vec3 mvPosition = {};
  35. Vec4 projectedPosition = {};
  36. Vec3 screenPosition = {};
  37. std::array<Vec3, 3> normal{};
  38. std::array<std::array<u8, 4>, 2> color{};
  39. std::array<Vec3, 8> texCoords{};
  40. void Lerp(float t, const OutputVertexData* a, const OutputVertexData* b)
  41. {
  42. #define LINTERP(T, OUT, IN) (OUT) + ((IN - OUT) * T)
  43. #define LINTERP_INT(T, OUT, IN) (OUT) + (((IN - OUT) * T) >> 8)
  44. mvPosition = LINTERP(t, a->mvPosition, b->mvPosition);
  45. projectedPosition.x = LINTERP(t, a->projectedPosition.x, b->projectedPosition.x);
  46. projectedPosition.y = LINTERP(t, a->projectedPosition.y, b->projectedPosition.y);
  47. projectedPosition.z = LINTERP(t, a->projectedPosition.z, b->projectedPosition.z);
  48. projectedPosition.w = LINTERP(t, a->projectedPosition.w, b->projectedPosition.w);
  49. for (std::size_t i = 0; i < normal.size(); ++i)
  50. {
  51. normal[i] = LINTERP(t, a->normal[i], b->normal[i]);
  52. }
  53. const u16 t_int = static_cast<u16>(t * 256);
  54. for (std::size_t i = 0; i < color[0].size(); ++i)
  55. {
  56. color[0][i] = LINTERP_INT(t_int, a->color[0][i], b->color[0][i]);
  57. color[1][i] = LINTERP_INT(t_int, a->color[1][i], b->color[1][i]);
  58. }
  59. for (std::size_t i = 0; i < texCoords.size(); ++i)
  60. {
  61. texCoords[i] = LINTERP(t, a->texCoords[i], b->texCoords[i]);
  62. }
  63. #undef LINTERP
  64. #undef LINTERP_INT
  65. }
  66. };