opensubdiv_evaluator_internal.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // Copyright 2018 Blender Foundation. All rights reserved.
  2. //
  3. // This program is free software; you can redistribute it and/or
  4. // modify it under the terms of the GNU General Public License
  5. // as published by the Free Software Foundation; either version 2
  6. // of the License, or (at your option) any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software Foundation,
  15. // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. //
  17. // Author: Sergey Sharybin
  18. #ifndef OPENSUBDIV_EVALUATOR_INTERNAL_H_
  19. #define OPENSUBDIV_EVALUATOR_INTERNAL_H_
  20. #ifdef _MSC_VER
  21. # include <iso646.h>
  22. #endif
  23. #include <opensubdiv/far/patchMap.h>
  24. #include <opensubdiv/far/patchTable.h>
  25. struct OpenSubdiv_TopologyRefiner;
  26. namespace opensubdiv_capi {
  27. // Anonymous forward declaration of actual evaluator implementation.
  28. class CpuEvalOutput;
  29. // Wrapper around implementaiton, which defines API which we are capable to
  30. // provide over the implementation.
  31. //
  32. // TODO(sergey): It is almost the same as C-API object, so ideally need to
  33. // merge them somehow, but how to do this and keep files with all the templates
  34. // and such separate?
  35. class CpuEvalOutputAPI {
  36. public:
  37. // NOTE: API object becomes an owner of evaluator. Patch we are referencing.
  38. CpuEvalOutputAPI(CpuEvalOutput *implementation, OpenSubdiv::Far::PatchMap *patch_map);
  39. ~CpuEvalOutputAPI();
  40. // Set coarse positions from a continuous array of coordinates.
  41. void setCoarsePositions(const float *positions,
  42. const int start_vertex_index,
  43. const int num_vertices);
  44. // Set varying data from a continuous array of data.
  45. void setVaryingData(const float *varying_data,
  46. const int start_vertex_index,
  47. const int num_vertices);
  48. // Set face varying data from a continuous array of data.
  49. //
  50. // TODO(sergey): Find a better name for vertex here. It is not the vertex of
  51. // geometry, but a vertex of UV map.
  52. void setFaceVaryingData(const int face_varying_channel,
  53. const float *varying_data,
  54. const int start_vertex_index,
  55. const int num_vertices);
  56. // Set coarse vertex position from a continuous memory buffer where
  57. // first coordinate starts at offset of `start_offset` and there is `stride`
  58. // bytes between adjacent vertex coordinates.
  59. void setCoarsePositionsFromBuffer(const void *buffer,
  60. const int start_offset,
  61. const int stride,
  62. const int start_vertex_index,
  63. const int num_vertices);
  64. // Set varying data from a continuous memory buffer where
  65. // first coordinate starts at offset of `start_offset` and there is `stride`
  66. // bytes between adjacent vertex coordinates.
  67. void setVaryingDataFromBuffer(const void *buffer,
  68. const int start_offset,
  69. const int stride,
  70. const int start_vertex_index,
  71. const int num_vertices);
  72. // Set face varying data from a continuous memory buffer where
  73. // first coordinate starts at offset of `start_offset` and there is `stride`
  74. // bytes between adjacent vertex coordinates.
  75. //
  76. // TODO(sergey): Find a better name for vertex here. It is not the vertex of
  77. // geometry, but a vertex of UV map.
  78. void setFaceVaryingDataFromBuffer(const int face_varying_channel,
  79. const void *buffer,
  80. const int start_offset,
  81. const int stride,
  82. const int start_vertex_index,
  83. const int num_vertices);
  84. // Refine after coarse positions update.
  85. void refine();
  86. // Evaluate given ptex face at given bilinear coordinate.
  87. // If derivatives are NULL, they will not be evaluated.
  88. void evaluateLimit(const int ptex_face_index,
  89. float face_u,
  90. float face_v,
  91. float P[3],
  92. float dPdu[3],
  93. float dPdv[3]);
  94. // Evaluate varying data at a given bilinear coordinate of given ptex face.
  95. void evaluateVarying(const int ptes_face_index, float face_u, float face_v, float varying[3]);
  96. // Evaluate facee-varying data at a given bilinear coordinate of given
  97. // ptex face.
  98. void evaluateFaceVarying(const int face_varying_channel,
  99. const int ptes_face_index,
  100. float face_u,
  101. float face_v,
  102. float face_varying[2]);
  103. protected:
  104. CpuEvalOutput *implementation_;
  105. OpenSubdiv::Far::PatchMap *patch_map_;
  106. };
  107. } // namespace opensubdiv_capi
  108. struct OpenSubdiv_EvaluatorInternal {
  109. public:
  110. OpenSubdiv_EvaluatorInternal();
  111. ~OpenSubdiv_EvaluatorInternal();
  112. opensubdiv_capi::CpuEvalOutputAPI *eval_output;
  113. const OpenSubdiv::Far::PatchMap *patch_map;
  114. const OpenSubdiv::Far::PatchTable *patch_table;
  115. };
  116. OpenSubdiv_EvaluatorInternal *openSubdiv_createEvaluatorInternal(
  117. struct OpenSubdiv_TopologyRefiner *topology_refiner);
  118. void openSubdiv_deleteEvaluatorInternal(OpenSubdiv_EvaluatorInternal *evaluator);
  119. #endif // OPENSUBDIV_EVALUATOR_INTERNAL_H_