💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.9 KiB

  1. /*
  2. * Copyright (C) 2023 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <engine/gl/cube-map.hpp>
  20. namespace gl {
  21. cube_map_layout infer_cube_map_layout(std::uint32_t width, std::uint32_t height) noexcept
  22. {
  23. if (width == height / 6)
  24. {
  25. return cube_map_layout::column;
  26. }
  27. else if (width == height * 6)
  28. {
  29. return cube_map_layout::row;
  30. }
  31. else if (width == (height / 4) * 3)
  32. {
  33. return cube_map_layout::vertical_cross;
  34. }
  35. else if (width == (height * 4) / 3)
  36. {
  37. return cube_map_layout::horizontal_cross;
  38. }
  39. else if (width == height * 2)
  40. {
  41. return cube_map_layout::equirectangular;
  42. }
  43. else if (width == height)
  44. {
  45. return cube_map_layout::spherical;
  46. }
  47. return cube_map_layout::unknown;
  48. }
  49. std::uint32_t infer_cube_map_face_width(std::uint32_t width, std::uint32_t height, cube_map_layout layout) noexcept
  50. {
  51. switch (layout)
  52. {
  53. case cube_map_layout::column:
  54. case cube_map_layout::spherical:
  55. return width;
  56. case cube_map_layout::row:
  57. return height;
  58. case cube_map_layout::vertical_cross:
  59. return height / 4;
  60. case cube_map_layout::horizontal_cross:
  61. case cube_map_layout::equirectangular:
  62. return width / 4;
  63. default:
  64. return 0;
  65. }
  66. }
  67. } // namespace gl