llmeshoptimizer.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * @file llmeshoptimizer.h
  3. * @brief Wrapper around the meshoptimizer library
  4. *
  5. * $LicenseInfo:firstyear=2021&license=viewergpl$
  6. *
  7. * Copyright (c) 2021, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_MESHOPTIMIZER_H
  33. #define LL_MESHOPTIMIZER_H
  34. #include "stdtypes.h"
  35. class LLVector2;
  36. class LLVector4a;
  37. // Purely static class
  38. class LLMeshOptimizer
  39. {
  40. public:
  41. LLMeshOptimizer() = delete;
  42. ~LLMeshOptimizer() = delete;
  43. static void generateShadowIndexBuffer16(U16* dest, const U16* indices,
  44. U64 idx_count,
  45. const LLVector4a* vert_pos,
  46. const LLVector4a* normals,
  47. const LLVector2* tex_coords,
  48. U64 vert_count);
  49. static void generateShadowIndexBuffer32(U32* dest, const U32* indices,
  50. U64 idx_count,
  51. const LLVector4a* vert_pos,
  52. const LLVector4a* normals,
  53. const LLVector2* tex_coords,
  54. U64 vert_count);
  55. // Remap methods welding indentical vertexes together and removing unused
  56. // vertices if indices were provided.
  57. static size_t generateRemapMulti16(U32* remap,
  58. const U16* indices, U64 index_count,
  59. const LLVector4a* vert_pos,
  60. const LLVector4a* normals,
  61. const LLVector2* tex_coords,
  62. U64 vert_count);
  63. static size_t generateRemapMulti32(U32* remap,
  64. const U32* indices, U64 index_count,
  65. const LLVector4a* vert_pos,
  66. const LLVector4a* normals,
  67. const LLVector2* tex_coords,
  68. U64 vert_count);
  69. static void remapIndexBuffer16(U16* dest, const U16* indices,
  70. U64 index_count, const U32* remap);
  71. static void remapIndexBuffer32(U32* dest, const U32* indices,
  72. U64 index_count, const U32* remap);
  73. // Works for both positions and normals vertex buffers.
  74. static void remapVertsBuffer(LLVector4a* dest, const LLVector4a* verts,
  75. U64 count, const U32* remap);
  76. static void remapTexCoordsBuffer(LLVector2* dest, const LLVector2* tc,
  77. U64 tc_count, const U32* remap);
  78. // Simplification methods returning the amount of indices in 'dest';
  79. // 'sloppy' engages a variant of an algorithm that does not respect
  80. // topology as much but is much more effective for simpler models. When
  81. // not NULL, 'result_error' returns how far from original the model is in
  82. // percents.
  83. static size_t simplify16(U16* dest, const U16* indices, U64 idx_count,
  84. const LLVector4a* vert_pos, U64 vert_count,
  85. U64 vert_pos_stride, U64 target_idx_count,
  86. F32 target_error, bool sloppy, F32* result_error);
  87. static size_t simplify32(U32* dest, const U32* indices, U64 idx_count,
  88. const LLVector4a* vert_pos, U64 vert_count,
  89. U64 vert_pos_stride, U64 target_idx_count,
  90. F32 target_error, bool sloppy, F32* result_error);
  91. };
  92. #endif // LL_MESHOPTIMIZER_H