Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'intern/opensubdiv/internal')
-rw-r--r--intern/opensubdiv/internal/opensubdiv.cc17
-rw-r--r--intern/opensubdiv/internal/opensubdiv_converter_factory.cc130
-rw-r--r--intern/opensubdiv/internal/opensubdiv_converter_factory.h4
-rw-r--r--intern/opensubdiv/internal/opensubdiv_converter_internal.cc15
-rw-r--r--intern/opensubdiv/internal/opensubdiv_converter_internal.h8
-rw-r--r--intern/opensubdiv/internal/opensubdiv_converter_orient.cc21
-rw-r--r--intern/opensubdiv/internal/opensubdiv_converter_orient.h19
-rw-r--r--intern/opensubdiv/internal/opensubdiv_converter_orient_impl.h15
-rw-r--r--intern/opensubdiv/internal/opensubdiv_device_context_cuda.cc135
-rw-r--r--intern/opensubdiv/internal/opensubdiv_device_context_cuda.h2
-rw-r--r--intern/opensubdiv/internal/opensubdiv_device_context_opencl.cc165
-rw-r--r--intern/opensubdiv/internal/opensubdiv_device_context_opencl.h2
-rw-r--r--intern/opensubdiv/internal/opensubdiv_edge_map.h81
-rw-r--r--intern/opensubdiv/internal/opensubdiv_evaluator.cc129
-rw-r--r--intern/opensubdiv/internal/opensubdiv_evaluator_internal.cc637
-rw-r--r--intern/opensubdiv/internal/opensubdiv_evaluator_internal.h52
-rw-r--r--intern/opensubdiv/internal/opensubdiv_gl_mesh.cc152
-rw-r--r--intern/opensubdiv/internal/opensubdiv_gl_mesh_draw.cc271
-rw-r--r--intern/opensubdiv/internal/opensubdiv_gl_mesh_draw.h4
-rw-r--r--intern/opensubdiv/internal/opensubdiv_gl_mesh_fvar.cc76
-rw-r--r--intern/opensubdiv/internal/opensubdiv_gl_mesh_fvar.h12
-rw-r--r--intern/opensubdiv/internal/opensubdiv_gl_mesh_internal.cc8
-rw-r--r--intern/opensubdiv/internal/opensubdiv_gl_mesh_internal.h4
-rw-r--r--intern/opensubdiv/internal/opensubdiv_topology_refiner.cc382
-rw-r--r--intern/opensubdiv/internal/opensubdiv_topology_refiner_internal.cc7
-rw-r--r--intern/opensubdiv/internal/opensubdiv_topology_refiner_internal.h2
-rw-r--r--intern/opensubdiv/internal/opensubdiv_util.cc15
-rw-r--r--intern/opensubdiv/internal/opensubdiv_util.h6
28 files changed, 1147 insertions, 1224 deletions
diff --git a/intern/opensubdiv/internal/opensubdiv.cc b/intern/opensubdiv/internal/opensubdiv.cc
index b535532b3ae..dc19d3d9306 100644
--- a/intern/opensubdiv/internal/opensubdiv.cc
+++ b/intern/opensubdiv/internal/opensubdiv.cc
@@ -26,16 +26,19 @@
#include "opensubdiv_device_context_cuda.h"
#include "opensubdiv_gl_mesh_capi.h"
-void openSubdiv_init(void) {
+void openSubdiv_init(void)
+{
// Ensure all OpenGL strings are cached.
openSubdiv_getAvailableEvaluators();
}
-void openSubdiv_cleanup(void) {
+void openSubdiv_cleanup(void)
+{
openSubdiv_deinitGLMeshDrawingResources();
}
-int openSubdiv_getAvailableEvaluators(void) {
+int openSubdiv_getAvailableEvaluators(void)
+{
int flags = OPENSUBDIV_EVALUATOR_CPU;
#ifdef OPENSUBDIV_HAS_OPENMP
@@ -69,15 +72,15 @@ int openSubdiv_getAvailableEvaluators(void) {
return flags;
}
-int openSubdiv_getVersionHex(void) {
+int openSubdiv_getVersionHex(void)
+{
#if defined(OPENSUBDIV_VERSION_NUMBER)
return OPENSUBDIV_VERSION_NUMBER;
#elif defined(OPENSUBDIV_VERSION_MAJOR)
- return OPENSUBDIV_VERSION_MAJOR * 10000 +
- OPENSUBDIV_VERSION_MINOR * 100 +
+ return OPENSUBDIV_VERSION_MAJOR * 10000 + OPENSUBDIV_VERSION_MINOR * 100 +
OPENSUBDIV_VERSION_PATCH;
#elif defined(OPENSUBDIV_VERSION)
- const char* version = STRINGIFY(OPENSUBDIV_VERSION);
+ const char *version = STRINGIFY(OPENSUBDIV_VERSION);
if (version[0] == 'v') {
version += 1;
}
diff --git a/intern/opensubdiv/internal/opensubdiv_converter_factory.cc b/intern/opensubdiv/internal/opensubdiv_converter_factory.cc
index e07880b7d8d..0c1514f2fea 100644
--- a/intern/opensubdiv/internal/opensubdiv_converter_factory.cc
+++ b/intern/opensubdiv/internal/opensubdiv_converter_factory.cc
@@ -34,29 +34,27 @@
#include "opensubdiv_converter_capi.h"
using opensubdiv_capi::min;
-using opensubdiv_capi::vector;
using opensubdiv_capi::stack;
+using opensubdiv_capi::vector;
struct TopologyRefinerData {
- const OpenSubdiv_Converter* converter;
+ const OpenSubdiv_Converter *converter;
};
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Far {
-template <>
-inline bool
-TopologyRefinerFactory<TopologyRefinerData>::resizeComponentTopology(
- TopologyRefiner& refiner,
- const TopologyRefinerData& cb_data) {
- const OpenSubdiv_Converter* converter = cb_data.converter;
+template<>
+inline bool TopologyRefinerFactory<TopologyRefinerData>::resizeComponentTopology(
+ TopologyRefiner &refiner, const TopologyRefinerData &cb_data)
+{
+ const OpenSubdiv_Converter *converter = cb_data.converter;
// Faces and face-vertices.
const int num_faces = converter->getNumFaces(converter);
setNumBaseFaces(refiner, num_faces);
for (int face_index = 0; face_index < num_faces; ++face_index) {
- const int num_face_vertices =
- converter->getNumFaceVertices(converter, face_index);
+ const int num_face_vertices = converter->getNumFaceVertices(converter, face_index);
setNumBaseFaceVertices(refiner, face_index, num_face_vertices);
}
// Vertices.
@@ -70,31 +68,26 @@ TopologyRefinerFactory<TopologyRefinerData>::resizeComponentTopology(
const int num_edges = converter->getNumEdges(converter);
setNumBaseEdges(refiner, num_edges);
for (int edge_index = 0; edge_index < num_edges; ++edge_index) {
- const int num_edge_faces =
- converter->getNumEdgeFaces(converter, edge_index);
+ const int num_edge_faces = converter->getNumEdgeFaces(converter, edge_index);
setNumBaseEdgeFaces(refiner, edge_index, num_edge_faces);
}
// Vertex-faces and vertex-edges.
for (int vertex_index = 0; vertex_index < num_vertices; ++vertex_index) {
- const int num_vert_edges =
- converter->getNumVertexEdges(converter, vertex_index);
- const int num_vert_faces =
- converter->getNumVertexFaces(converter, vertex_index);
+ const int num_vert_edges = converter->getNumVertexEdges(converter, vertex_index);
+ const int num_vert_faces = converter->getNumVertexFaces(converter, vertex_index);
setNumBaseVertexEdges(refiner, vertex_index, num_vert_edges);
setNumBaseVertexFaces(refiner, vertex_index, num_vert_faces);
}
return true;
}
-template <>
-inline bool
-TopologyRefinerFactory<TopologyRefinerData>::assignComponentTopology(
- TopologyRefiner& refiner,
- const TopologyRefinerData& cb_data) {
+template<>
+inline bool TopologyRefinerFactory<TopologyRefinerData>::assignComponentTopology(
+ TopologyRefiner &refiner, const TopologyRefinerData &cb_data)
+{
using Far::IndexArray;
- const OpenSubdiv_Converter* converter = cb_data.converter;
- const bool full_topology_specified =
- converter->specifiesFullTopology(converter);
+ const OpenSubdiv_Converter *converter = cb_data.converter;
+ const bool full_topology_specified = converter->specifiesFullTopology(converter);
// Face relations.
const int num_faces = converter->getNumFaces(converter);
for (int face_index = 0; face_index < num_faces; ++face_index) {
@@ -125,47 +118,41 @@ TopologyRefinerFactory<TopologyRefinerData>::assignComponentTopology(
for (int vertex_index = 0; vertex_index < num_vertices; ++vertex_index) {
// Vertex-faces.
IndexArray dst_vertex_faces = getBaseVertexFaces(refiner, vertex_index);
- const int num_vertex_faces =
- converter->getNumVertexFaces(converter, vertex_index);
+ const int num_vertex_faces = converter->getNumVertexFaces(converter, vertex_index);
vertex_faces.resize(num_vertex_faces);
converter->getVertexFaces(converter, vertex_index, &vertex_faces[0]);
// Vertex-edges.
IndexArray dst_vertex_edges = getBaseVertexEdges(refiner, vertex_index);
- const int num_vertex_edges =
- converter->getNumVertexEdges(converter, vertex_index);
+ const int num_vertex_edges = converter->getNumVertexEdges(converter, vertex_index);
vertex_edges.resize(num_vertex_edges);
converter->getVertexEdges(converter, vertex_index, &vertex_edges[0]);
- memcpy(&dst_vertex_edges[0], &vertex_edges[0],
- sizeof(int) * num_vertex_edges);
- memcpy(&dst_vertex_faces[0], &vertex_faces[0],
- sizeof(int) * num_vertex_faces);
+ memcpy(&dst_vertex_edges[0], &vertex_edges[0], sizeof(int) * num_vertex_edges);
+ memcpy(&dst_vertex_faces[0], &vertex_faces[0], sizeof(int) * num_vertex_faces);
}
populateBaseLocalIndices(refiner);
return true;
}
-template <>
+template<>
inline bool TopologyRefinerFactory<TopologyRefinerData>::assignComponentTags(
- TopologyRefiner& refiner,
- const TopologyRefinerData& cb_data) {
+ TopologyRefiner &refiner, const TopologyRefinerData &cb_data)
+{
using OpenSubdiv::Sdc::Crease;
- const OpenSubdiv_Converter* converter = cb_data.converter;
- const bool full_topology_specified =
- converter->specifiesFullTopology(converter);
+ const OpenSubdiv_Converter *converter = cb_data.converter;
+ const bool full_topology_specified = converter->specifiesFullTopology(converter);
const int num_edges = converter->getNumEdges(converter);
for (int edge_index = 0; edge_index < num_edges; ++edge_index) {
- const float sharpness =
- converter->getEdgeSharpness(converter, edge_index);
+ const float sharpness = converter->getEdgeSharpness(converter, edge_index);
if (sharpness < 1e-6f) {
continue;
}
if (full_topology_specified) {
setBaseEdgeSharpness(refiner, edge_index, sharpness);
- } else {
+ }
+ else {
int edge_vertices[2];
converter->getEdgeVertices(converter, edge_index, edge_vertices);
- const int base_edge_index = findBaseEdge(
- refiner, edge_vertices[0], edge_vertices[1]);
+ const int base_edge_index = findBaseEdge(refiner, edge_vertices[0], edge_vertices[1]);
if (base_edge_index == OpenSubdiv::Far::INDEX_INVALID) {
printf("OpenSubdiv Error: failed to find reconstructed edge\n");
return false;
@@ -181,8 +168,7 @@ inline bool TopologyRefinerFactory<TopologyRefinerData>::assignComponentTags(
for (int vertex_index = 0; vertex_index < num_vertices; ++vertex_index) {
ConstIndexArray vertex_edges = getBaseVertexEdges(refiner, vertex_index);
if (converter->isInfiniteSharpVertex(converter, vertex_index)) {
- setBaseVertexSharpness(
- refiner, vertex_index, Crease::SHARPNESS_INFINITE);
+ setBaseVertexSharpness(refiner, vertex_index, Crease::SHARPNESS_INFINITE);
continue;
}
float sharpness = converter->getVertexSharpness(converter, vertex_index);
@@ -199,12 +185,11 @@ inline bool TopologyRefinerFactory<TopologyRefinerData>::assignComponentTags(
return true;
}
-template <>
-inline bool
-TopologyRefinerFactory<TopologyRefinerData>::assignFaceVaryingTopology(
- TopologyRefiner& refiner,
- const TopologyRefinerData& cb_data) {
- const OpenSubdiv_Converter* converter = cb_data.converter;
+template<>
+inline bool TopologyRefinerFactory<TopologyRefinerData>::assignFaceVaryingTopology(
+ TopologyRefiner &refiner, const TopologyRefinerData &cb_data)
+{
+ const OpenSubdiv_Converter *converter = cb_data.converter;
const int num_layers = converter->getNumUVLayers(converter);
if (num_layers <= 0) {
// No UV maps, we can skip any face-varying data.
@@ -219,11 +204,9 @@ TopologyRefinerFactory<TopologyRefinerData>::assignFaceVaryingTopology(
// TODO(sergey): Need to check whether converter changed the winding of
// face to match OpenSubdiv's expectations.
for (int face_index = 0; face_index < num_faces; ++face_index) {
- Far::IndexArray dst_face_uvs =
- getBaseFaceFVarValues(refiner, face_index, channel);
+ Far::IndexArray dst_face_uvs = getBaseFaceFVarValues(refiner, face_index, channel);
for (int corner = 0; corner < dst_face_uvs.size(); ++corner) {
- const int uv_index =
- converter->getFaceCornerUVIndex(converter, face_index, corner);
+ const int uv_index = converter->getFaceCornerUVIndex(converter, face_index, corner);
dst_face_uvs[corner] = uv_index;
}
}
@@ -232,10 +215,10 @@ TopologyRefinerFactory<TopologyRefinerData>::assignFaceVaryingTopology(
return true;
}
-template <>
+template<>
inline void TopologyRefinerFactory<TopologyRefinerData>::reportInvalidTopology(
- TopologyError /*errCode*/, const char* msg,
- const TopologyRefinerData& /*mesh*/) {
+ TopologyError /*errCode*/, const char *msg, const TopologyRefinerData & /*mesh*/)
+{
printf("OpenSubdiv Error: %s\n", msg);
}
@@ -247,9 +230,9 @@ namespace opensubdiv_capi {
namespace {
-OpenSubdiv::Sdc::Options::VtxBoundaryInterpolation
-getVtxBoundaryInterpolationFromCAPI(
- OpenSubdiv_VtxBoundaryInterpolation boundary_interpolation) {
+OpenSubdiv::Sdc::Options::VtxBoundaryInterpolation getVtxBoundaryInterpolationFromCAPI(
+ OpenSubdiv_VtxBoundaryInterpolation boundary_interpolation)
+{
using OpenSubdiv::Sdc::Options;
switch (boundary_interpolation) {
case OSD_VTX_BOUNDARY_NONE:
@@ -265,31 +248,28 @@ getVtxBoundaryInterpolationFromCAPI(
} // namespace
-OpenSubdiv::Far::TopologyRefiner* createOSDTopologyRefinerFromConverter(
- OpenSubdiv_Converter* converter) {
- using OpenSubdiv::Sdc::Options;
+OpenSubdiv::Far::TopologyRefiner *createOSDTopologyRefinerFromConverter(
+ OpenSubdiv_Converter *converter)
+{
using OpenSubdiv::Far::TopologyRefinerFactory;
- const OpenSubdiv::Sdc::SchemeType scheme_type =
- getSchemeTypeFromCAPI(converter->getSchemeType(converter));
- const Options::FVarLinearInterpolation linear_interpolation =
- getFVarLinearInterpolationFromCAPI(
- converter->getFVarLinearInterpolation(converter));
+ using OpenSubdiv::Sdc::Options;
+ const OpenSubdiv::Sdc::SchemeType scheme_type = getSchemeTypeFromCAPI(
+ converter->getSchemeType(converter));
+ const Options::FVarLinearInterpolation linear_interpolation = getFVarLinearInterpolationFromCAPI(
+ converter->getFVarLinearInterpolation(converter));
Options options;
options.SetVtxBoundaryInterpolation(
- getVtxBoundaryInterpolationFromCAPI(
- converter->getVtxBoundaryInterpolation(converter)));
+ getVtxBoundaryInterpolationFromCAPI(converter->getVtxBoundaryInterpolation(converter)));
options.SetCreasingMethod(Options::CREASE_UNIFORM);
options.SetFVarLinearInterpolation(linear_interpolation);
- TopologyRefinerFactory<TopologyRefinerData>::Options topology_options(
- scheme_type, options);
+ TopologyRefinerFactory<TopologyRefinerData>::Options topology_options(scheme_type, options);
#ifdef OPENSUBDIV_VALIDATE_TOPOLOGY
topology_options.validateFullTopology = true;
#endif
TopologyRefinerData cb_data;
cb_data.converter = converter;
- return TopologyRefinerFactory<TopologyRefinerData>::Create(
- cb_data, topology_options);
+ return TopologyRefinerFactory<TopologyRefinerData>::Create(cb_data, topology_options);
}
} // namespace opensubdiv_capi
diff --git a/intern/opensubdiv/internal/opensubdiv_converter_factory.h b/intern/opensubdiv/internal/opensubdiv_converter_factory.h
index 451418813e1..a1038474d33 100644
--- a/intern/opensubdiv/internal/opensubdiv_converter_factory.h
+++ b/intern/opensubdiv/internal/opensubdiv_converter_factory.h
@@ -29,8 +29,8 @@ struct OpenSubdiv_Converter;
namespace opensubdiv_capi {
-OpenSubdiv::Far::TopologyRefiner* createOSDTopologyRefinerFromConverter(
- struct OpenSubdiv_Converter* converter);
+OpenSubdiv::Far::TopologyRefiner *createOSDTopologyRefinerFromConverter(
+ struct OpenSubdiv_Converter *converter);
} // namespace opensubdiv_capi
diff --git a/intern/opensubdiv/internal/opensubdiv_converter_internal.cc b/intern/opensubdiv/internal/opensubdiv_converter_internal.cc
index 2f7a7109ea1..e8d2f237936 100644
--- a/intern/opensubdiv/internal/opensubdiv_converter_internal.cc
+++ b/intern/opensubdiv/internal/opensubdiv_converter_internal.cc
@@ -27,7 +27,8 @@
namespace opensubdiv_capi {
-OpenSubdiv::Sdc::SchemeType getSchemeTypeFromCAPI(OpenSubdiv_SchemeType type) {
+OpenSubdiv::Sdc::SchemeType getSchemeTypeFromCAPI(OpenSubdiv_SchemeType type)
+{
switch (type) {
case OSD_SCHEME_BILINEAR:
return OpenSubdiv::Sdc::SCHEME_BILINEAR;
@@ -40,9 +41,9 @@ OpenSubdiv::Sdc::SchemeType getSchemeTypeFromCAPI(OpenSubdiv_SchemeType type) {
return OpenSubdiv::Sdc::SCHEME_CATMARK;
}
-OpenSubdiv::Sdc::Options::FVarLinearInterpolation
-getFVarLinearInterpolationFromCAPI(
- OpenSubdiv_FVarLinearInterpolation linear_interpolation) {
+OpenSubdiv::Sdc::Options::FVarLinearInterpolation getFVarLinearInterpolationFromCAPI(
+ OpenSubdiv_FVarLinearInterpolation linear_interpolation)
+{
typedef OpenSubdiv::Sdc::Options Options;
switch (linear_interpolation) {
case OSD_FVAR_LINEAR_INTERPOLATION_NONE:
@@ -62,9 +63,9 @@ getFVarLinearInterpolationFromCAPI(
return Options::FVAR_LINEAR_NONE;
}
-OpenSubdiv_FVarLinearInterpolation
-getCAPIFVarLinearInterpolationFromOSD(
- OpenSubdiv::Sdc::Options::FVarLinearInterpolation linear_interpolation) {
+OpenSubdiv_FVarLinearInterpolation getCAPIFVarLinearInterpolationFromOSD(
+ OpenSubdiv::Sdc::Options::FVarLinearInterpolation linear_interpolation)
+{
typedef OpenSubdiv::Sdc::Options Options;
switch (linear_interpolation) {
case Options::FVAR_LINEAR_NONE:
diff --git a/intern/opensubdiv/internal/opensubdiv_converter_internal.h b/intern/opensubdiv/internal/opensubdiv_converter_internal.h
index 411514c45dc..11c6bdd7f3b 100644
--- a/intern/opensubdiv/internal/opensubdiv_converter_internal.h
+++ b/intern/opensubdiv/internal/opensubdiv_converter_internal.h
@@ -37,14 +37,12 @@ OpenSubdiv::Sdc::SchemeType getSchemeTypeFromCAPI(OpenSubdiv_SchemeType type);
// Convert face-varying interpolation type from C-API to an OpenSubdiv
// native enum.
-OpenSubdiv::Sdc::Options::FVarLinearInterpolation
-getFVarLinearInterpolationFromCAPI(
+OpenSubdiv::Sdc::Options::FVarLinearInterpolation getFVarLinearInterpolationFromCAPI(
OpenSubdiv_FVarLinearInterpolation linear_interpolation);
// Similar to above, just other way around.
-OpenSubdiv_FVarLinearInterpolation
-getCAPIFVarLinearInterpolationFromOSD(
- OpenSubdiv::Sdc::Options::FVarLinearInterpolation linear_interpolation);
+OpenSubdiv_FVarLinearInterpolation getCAPIFVarLinearInterpolationFromOSD(
+ OpenSubdiv::Sdc::Options::FVarLinearInterpolation linear_interpolation);
} // namespace opensubdiv_capi
diff --git a/intern/opensubdiv/internal/opensubdiv_converter_orient.cc b/intern/opensubdiv/internal/opensubdiv_converter_orient.cc
index 449e9028180..e3367fc6314 100644
--- a/intern/opensubdiv/internal/opensubdiv_converter_orient.cc
+++ b/intern/opensubdiv/internal/opensubdiv_converter_orient.cc
@@ -24,10 +24,11 @@ namespace opensubdiv_capi {
void checkOrientedVertexConnectivity(const int num_vertex_edges,
const int num_vertex_faces,
- const int* vertex_edges,
- const int* vertex_faces,
- const int* dst_vertex_edges,
- const int* dst_vertex_faces) {
+ const int *vertex_edges,
+ const int *vertex_faces,
+ const int *dst_vertex_edges,
+ const int *dst_vertex_faces)
+{
#ifndef NDEBUG
for (int i = 0; i < num_vertex_faces; ++i) {
bool found = false;
@@ -54,12 +55,12 @@ void checkOrientedVertexConnectivity(const int num_vertex_edges,
}
}
#else
- (void) num_vertex_edges;
- (void) num_vertex_faces;
- (void) vertex_edges;
- (void) vertex_faces;
- (void) dst_vertex_edges;
- (void) dst_vertex_faces;
+ (void)num_vertex_edges;
+ (void)num_vertex_faces;
+ (void)vertex_edges;
+ (void)vertex_faces;
+ (void)dst_vertex_edges;
+ (void)dst_vertex_faces;
#endif
}
diff --git a/intern/opensubdiv/internal/opensubdiv_converter_orient.h b/intern/opensubdiv/internal/opensubdiv_converter_orient.h
index b783007a0cb..967871845cb 100644
--- a/intern/opensubdiv/internal/opensubdiv_converter_orient.h
+++ b/intern/opensubdiv/internal/opensubdiv_converter_orient.h
@@ -17,31 +17,30 @@
// Author: Sergey Sharybin
#ifndef OPENSUBDIV_CONVERTER_ORIENT_H_
-#define OPENSUBDIV_CONVERTER_ORIENT_H_
+# define OPENSUBDIV_CONVERTER_ORIENT_H_
-#include <opensubdiv/far/types.h>
+# include <opensubdiv/far/types.h>
// Set of utility functions which are needed to bring topology to an orientation
// (or, winding, if you wish) which OpenSubdiv expects.
namespace opensubdiv_capi {
-inline void reverseFaceVertices(int* face_vertices, const int num_vertices);
+inline void reverseFaceVertices(int *face_vertices, const int num_vertices);
// TODO(sergey): Document which value corresponds to which winding.
inline int getLoopWinding(int vert0_of_face, int vert1_of_face);
-inline void reverseFaceLoops(
- OpenSubdiv::Far::IndexArray* face_vertices,
- OpenSubdiv::Far::IndexArray* face_edges);
+inline void reverseFaceLoops(OpenSubdiv::Far::IndexArray *face_vertices,
+ OpenSubdiv::Far::IndexArray *face_edges);
// Used for debugging, checks whether orientation happened correct.
void checkOrientedVertexConnectivity(const int num_vertex_edges,
const int num_vertex_faces,
- const int* vertex_edges,
- const int* vertex_faces,
- const int* dst_vertex_edges,
- const int* dst_vertex_faces);
+ const int *vertex_edges,
+ const int *vertex_faces,
+ const int *dst_vertex_edges,
+ const int *dst_vertex_faces);
} // namespace opensubdiv_capi
diff --git a/intern/opensubdiv/internal/opensubdiv_converter_orient_impl.h b/intern/opensubdiv/internal/opensubdiv_converter_orient_impl.h
index 3e946595bba..aa717f5d99d 100644
--- a/intern/opensubdiv/internal/opensubdiv_converter_orient_impl.h
+++ b/intern/opensubdiv/internal/opensubdiv_converter_orient_impl.h
@@ -27,7 +27,8 @@
namespace opensubdiv_capi {
-inline void reverseFaceVertices(int* face_vertices, const int num_vertices) {
+inline void reverseFaceVertices(int *face_vertices, const int num_vertices)
+{
int last_vert = face_vertices[num_vertices - 1];
for (int i = num_vertices - 1; i > 0; --i) {
face_vertices[i] = face_vertices[i - 1];
@@ -35,21 +36,23 @@ inline void reverseFaceVertices(int* face_vertices, const int num_vertices) {
face_vertices[0] = last_vert;
}
-inline int getLoopWinding(int vert0_of_face, int vert1_of_face) {
+inline int getLoopWinding(int vert0_of_face, int vert1_of_face)
+{
int delta_face = vert1_of_face - vert0_of_face;
if (abs(delta_face) != 1) {
if (delta_face > 0) {
delta_face = -1;
- } else {
+ }
+ else {
delta_face = 1;
}
}
return delta_face;
}
-inline void reverseFaceLoops(
- OpenSubdiv::Far::IndexArray* face_vertices,
- OpenSubdiv::Far::IndexArray* face_edges) {
+inline void reverseFaceLoops(OpenSubdiv::Far::IndexArray *face_vertices,
+ OpenSubdiv::Far::IndexArray *face_edges)
+{
const int num_face_vertices = face_vertices->size();
for (int i = 0; i < num_face_vertices / 2; ++i) {
const int j = num_face_vertices - i - 1;
diff --git a/intern/opensubdiv/internal/opensubdiv_device_context_cuda.cc b/intern/opensubdiv/internal/opensubdiv_device_context_cuda.cc
index f5bc12efa84..5ce8af0434e 100644
--- a/intern/opensubdiv/internal/opensubdiv_device_context_cuda.cc
+++ b/intern/opensubdiv/internal/opensubdiv_device_context_cuda.cc
@@ -24,68 +24,70 @@
#ifdef OPENSUBDIV_HAS_CUDA
-#ifdef _MSC_VER
-# include <iso646.h>
-#endif
+# ifdef _MSC_VER
+# include <iso646.h>
+# endif
-#include "opensubdiv_device_context_cuda.h"
+# include "opensubdiv_device_context_cuda.h"
-#if defined(_WIN32)
-# include <windows.h>
-#elif defined(__APPLE__)
-# include <OpenGL/OpenGL.h>
-#else
-# include <GL/glx.h>
-# include <X11/Xlib.h>
-#endif
+# if defined(_WIN32)
+# include <windows.h>
+# elif defined(__APPLE__)
+# include <OpenGL/OpenGL.h>
+# else
+# include <GL/glx.h>
+# include <X11/Xlib.h>
+# endif
-#include <cuda.h>
-#include <cuda_gl_interop.h>
-#include <cuda_runtime_api.h>
-#include <cstdio>
+# include <cuda.h>
+# include <cuda_gl_interop.h>
+# include <cuda_runtime_api.h>
+# include <cstdio>
-#include "internal/opensubdiv_util.h"
+# include "internal/opensubdiv_util.h"
-#define message(fmt, ...)
+# define message(fmt, ...)
// #define message(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
-#define error(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
+# define error(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
namespace {
-int getCudaDeviceForCurrentGLContext() {
+int getCudaDeviceForCurrentGLContext()
+{
// Find and use the CUDA device for the current GL context
unsigned int interop_device_count = 0;
int interopDevices[1];
- cudaError_t status = cudaGLGetDevices(&interop_device_count,
- interopDevices,
- 1,
- cudaGLDeviceListCurrentFrame);
+ cudaError_t status = cudaGLGetDevices(
+ &interop_device_count, interopDevices, 1, cudaGLDeviceListCurrentFrame);
if (status == cudaErrorNoDevice || interop_device_count != 1) {
message("CUDA no interop devices found.\n");
return 0;
}
int device = interopDevices[0];
-#if defined(_WIN32)
+# if defined(_WIN32)
return device;
-#elif defined(__APPLE__)
+# elif defined(__APPLE__)
return device;
-#else // X11
- Display* display = glXGetCurrentDisplay();
+# else // X11
+ Display *display = glXGetCurrentDisplay();
int screen = DefaultScreen(display);
if (device != screen) {
- error("The CUDA interop device (%d) does not match "
- "the screen used by the current GL context (%d), "
- "which may cause slow performance on systems "
- "with multiple GPU devices.",
- device, screen);
+ error(
+ "The CUDA interop device (%d) does not match "
+ "the screen used by the current GL context (%d), "
+ "which may cause slow performance on systems "
+ "with multiple GPU devices.",
+ device,
+ screen);
}
message("CUDA init using device for current GL context: %d\n", device);
return device;
-#endif
+# endif
}
// Beginning of GPU Architecture definitions.
-int convertSMVer2Cores_local(int major, int minor) {
+int convertSMVer2Cores_local(int major, int minor)
+{
// Defines for GPU Architecture types (using the SM version to determine
// the # of cores per SM
typedef struct {
@@ -95,15 +97,14 @@ int convertSMVer2Cores_local(int major, int minor) {
int Cores;
} sSMtoCores;
- sSMtoCores nGpuArchCoresPerSM[] = {
- {0x10, 8}, // Tesla Generation (SM 1.0) G80 class.
- {0x11, 8}, // Tesla Generation (SM 1.1) G8x class.
- {0x12, 8}, // Tesla Generation (SM 1.2) G9x class.
- {0x13, 8}, // Tesla Generation (SM 1.3) GT200 class.
- {0x20, 32}, // Fermi Generation (SM 2.0) GF100 class.
- {0x21, 48}, // Fermi Generation (SM 2.1) GF10x class.
- {0x30, 192}, // Fermi Generation (SM 3.0) GK10x class.
- {-1, -1}};
+ sSMtoCores nGpuArchCoresPerSM[] = {{0x10, 8}, // Tesla Generation (SM 1.0) G80 class.
+ {0x11, 8}, // Tesla Generation (SM 1.1) G8x class.
+ {0x12, 8}, // Tesla Generation (SM 1.2) G9x class.
+ {0x13, 8}, // Tesla Generation (SM 1.3) GT200 class.
+ {0x20, 32}, // Fermi Generation (SM 2.0) GF100 class.
+ {0x21, 48}, // Fermi Generation (SM 2.1) GF10x class.
+ {0x30, 192}, // Fermi Generation (SM 3.0) GK10x class.
+ {-1, -1}};
int index = 0;
while (nGpuArchCoresPerSM[index].SM != -1) {
if (nGpuArchCoresPerSM[index].SM == ((major << 4) + minor)) {
@@ -116,7 +117,8 @@ int convertSMVer2Cores_local(int major, int minor) {
}
// This function returns the best GPU (with maximum GFLOPS).
-int cutGetMaxGflopsDeviceId() {
+int cutGetMaxGflopsDeviceId()
+{
int current_device = 0, sm_per_multiproc = 0;
int max_compute_perf = 0, max_perf_device = -1;
int device_count = 0, best_SM_arch = 0;
@@ -136,16 +138,15 @@ int cutGetMaxGflopsDeviceId() {
cuDeviceComputeCapability(&compat_major, &compat_minor, current_device);
if (compat_major == 9999 && compat_minor == 9999) {
sm_per_multiproc = 1;
- } else {
+ }
+ else {
sm_per_multiproc = convertSMVer2Cores_local(compat_major, compat_minor);
}
int multi_processor_count;
- cuDeviceGetAttribute(&multi_processor_count,
- CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT,
- current_device);
+ cuDeviceGetAttribute(
+ &multi_processor_count, CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT, current_device);
int clock_rate;
- cuDeviceGetAttribute(&clock_rate, CU_DEVICE_ATTRIBUTE_CLOCK_RATE,
- current_device);
+ cuDeviceGetAttribute(&clock_rate, CU_DEVICE_ATTRIBUTE_CLOCK_RATE, current_device);
int compute_perf = multi_processor_count * sm_per_multiproc * clock_rate;
if (compute_perf > max_compute_perf) {
/* If we find GPU with SM major > 2, search only these */
@@ -155,7 +156,8 @@ int cutGetMaxGflopsDeviceId() {
max_compute_perf = compute_perf;
max_perf_device = current_device;
}
- } else {
+ }
+ else {
max_compute_perf = compute_perf;
max_perf_device = current_device;
}
@@ -167,19 +169,20 @@ int cutGetMaxGflopsDeviceId() {
} // namespace
-bool CudaDeviceContext::HAS_CUDA_VERSION_4_0() {
-#ifdef OPENSUBDIV_HAS_CUDA
+bool CudaDeviceContext::HAS_CUDA_VERSION_4_0()
+{
+# ifdef OPENSUBDIV_HAS_CUDA
static bool cuda_initialized = false;
static bool cuda_load_success = true;
if (!cuda_initialized) {
cuda_initialized = true;
-#ifdef OPENSUBDIV_HAS_CUEW
+# ifdef OPENSUBDIV_HAS_CUEW
cuda_load_success = cuewInit(CUEW_INIT_CUDA) == CUEW_SUCCESS;
if (!cuda_load_success) {
fprintf(stderr, "Loading CUDA failed.\n");
}
-#endif
+# endif
// Need to initialize CUDA here so getting device
// with the maximum FPLOS works fine.
if (cuInit(0) == CUDA_SUCCESS) {
@@ -189,25 +192,28 @@ bool CudaDeviceContext::HAS_CUDA_VERSION_4_0() {
if (cutGetMaxGflopsDeviceId() < 0) {
cuda_load_success = false;
}
- } else {
+ }
+ else {
cuda_load_success = false;
}
}
return cuda_load_success;
-#else
+# else
return false;
-#endif
+# endif
}
-CudaDeviceContext::CudaDeviceContext()
- : initialized_(false) {
+CudaDeviceContext::CudaDeviceContext() : initialized_(false)
+{
}
-CudaDeviceContext::~CudaDeviceContext() {
+CudaDeviceContext::~CudaDeviceContext()
+{
cudaDeviceReset();
}
-bool CudaDeviceContext::Initialize() {
+bool CudaDeviceContext::Initialize()
+{
// See if any cuda device is available.
int device_count = 0;
cudaGetDeviceCount(&device_count);
@@ -220,7 +226,8 @@ bool CudaDeviceContext::Initialize() {
return true;
}
-bool CudaDeviceContext::IsInitialized() const {
+bool CudaDeviceContext::IsInitialized() const
+{
return initialized_;
}
diff --git a/intern/opensubdiv/internal/opensubdiv_device_context_cuda.h b/intern/opensubdiv/internal/opensubdiv_device_context_cuda.h
index ef212df10f0..10164e0cfc5 100644
--- a/intern/opensubdiv/internal/opensubdiv_device_context_cuda.h
+++ b/intern/opensubdiv/internal/opensubdiv_device_context_cuda.h
@@ -40,7 +40,7 @@ class CudaDeviceContext {
bool Initialize();
// Initialze cuda device from the ID3D11Device.
- bool Initialize(ID3D11Device* device);
+ bool Initialize(ID3D11Device *device);
// Returns true if the cuda device has already been initialized.
bool IsInitialized() const;
diff --git a/intern/opensubdiv/internal/opensubdiv_device_context_opencl.cc b/intern/opensubdiv/internal/opensubdiv_device_context_opencl.cc
index f6f1458b189..12f6ced4bbb 100644
--- a/intern/opensubdiv/internal/opensubdiv_device_context_opencl.cc
+++ b/intern/opensubdiv/internal/opensubdiv_device_context_opencl.cc
@@ -26,26 +26,27 @@
#ifdef OPENSUBDIV_HAS_OPENCL
-#if defined(_WIN32)
-# include <windows.h>
-#elif defined(__APPLE__)
-# include <OpenGL/OpenGL.h>
-#else
-# include <GL/glx.h>
-#endif
+# if defined(_WIN32)
+# include <windows.h>
+# elif defined(__APPLE__)
+# include <OpenGL/OpenGL.h>
+# else
+# include <GL/glx.h>
+# endif
-#include <cstdio>
-#include <cstring>
+# include <cstdio>
+# include <cstring>
-#include "internal/opensubdiv_util.h"
+# include "internal/opensubdiv_util.h"
-#define message(...) // fprintf(stderr, __VA_ARGS__)
-#define error(...) fprintf(stderr, __VA_ARGS__)
+# define message(...) // fprintf(stderr, __VA_ARGS__)
+# define error(...) fprintf(stderr, __VA_ARGS__)
namespace {
// Returns the first found platform.
-cl_platform_id findPlatform() {
+cl_platform_id findPlatform()
+{
cl_uint num_platforms;
cl_int ci_error_number = clGetPlatformIDs(0, NULL, &num_platforms);
if (ci_error_number != CL_SUCCESS) {
@@ -60,11 +61,8 @@ cl_platform_id findPlatform() {
ci_error_number = clGetPlatformIDs(num_platforms, &cl_platform_ids[0], NULL);
char ch_buffer[1024];
for (cl_uint i = 0; i < num_platforms; ++i) {
- ci_error_number = clGetPlatformInfo(cl_platform_ids[i],
- CL_PLATFORM_NAME,
- sizeof(ch_buffer),
- ch_buffer,
- NULL);
+ ci_error_number = clGetPlatformInfo(
+ cl_platform_ids[i], CL_PLATFORM_NAME, sizeof(ch_buffer), ch_buffer, NULL);
if (ci_error_number == CL_SUCCESS) {
cl_platform_id platform_id = cl_platform_ids[i];
return platform_id;
@@ -74,20 +72,18 @@ cl_platform_id findPlatform() {
}
// Return the device in cl_devices which supports the extension.
-int findExtensionSupportedDevice(cl_device_id* cl_devices,
+int findExtensionSupportedDevice(cl_device_id *cl_devices,
int num_devices,
- const char* extension_name) {
+ const char *extension_name)
+{
// Find a device that supports sharing with GL/D3D11
// (SLI / X-fire configurations)
cl_int cl_error_number;
for (int i = 0; i < num_devices; ++i) {
// Get extensions string size.
size_t extensions_size;
- cl_error_number = clGetDeviceInfo(cl_devices[i],
- CL_DEVICE_EXTENSIONS,
- 0,
- NULL,
- &extensions_size);
+ cl_error_number = clGetDeviceInfo(
+ cl_devices[i], CL_DEVICE_EXTENSIONS, 0, NULL, &extensions_size);
if (cl_error_number != CL_SUCCESS) {
error("Error %d in clGetDeviceInfo\n", cl_error_number);
return -1;
@@ -95,11 +91,8 @@ int findExtensionSupportedDevice(cl_device_id* cl_devices,
if (extensions_size > 0) {
// Get extensions string.
string extensions('\0', extensions_size);
- cl_error_number = clGetDeviceInfo(cl_devices[i],
- CL_DEVICE_EXTENSIONS,
- extensions_size,
- &extensions[0],
- &extensions_size);
+ cl_error_number = clGetDeviceInfo(
+ cl_devices[i], CL_DEVICE_EXTENSIONS, extensions_size, &extensions[0], &extensions_size);
if (cl_error_number != CL_SUCCESS) {
error("Error %d in clGetDeviceInfo\n", cl_error_number);
continue;
@@ -119,12 +112,12 @@ int findExtensionSupportedDevice(cl_device_id* cl_devices,
} // namespace
-CLDeviceContext::CLDeviceContext()
- : cl_context_(NULL),
- cl_command_queue_(NULL) {
+CLDeviceContext::CLDeviceContext() : cl_context_(NULL), cl_command_queue_(NULL)
+{
}
-CLDeviceContext::~CLDeviceContext() {
+CLDeviceContext::~CLDeviceContext()
+{
if (cl_command_queue_) {
clReleaseCommandQueue(cl_command_queue_);
}
@@ -133,8 +126,9 @@ CLDeviceContext::~CLDeviceContext() {
}
}
-bool CLDeviceContext::HAS_CL_VERSION_1_1() {
-#ifdef OPENSUBDIV_HAS_CLEW
+bool CLDeviceContext::HAS_CL_VERSION_1_1()
+{
+# ifdef OPENSUBDIV_HAS_CLEW
static bool clew_initialized = false;
static bool clew_load_success;
if (!clew_initialized) {
@@ -145,55 +139,53 @@ bool CLDeviceContext::HAS_CL_VERSION_1_1() {
}
}
return clew_load_success;
-#endif
+# endif
return true;
}
-bool CLDeviceContext::Initialize() {
-#ifdef OPENSUBDIV_HAS_CLEW
+bool CLDeviceContext::Initialize()
+{
+# ifdef OPENSUBDIV_HAS_CLEW
if (!clGetPlatformIDs) {
error("Error clGetPlatformIDs function not bound.\n");
return false;
}
-#endif
+# endif
cl_int cl_error_number;
cl_platform_id cp_platform = findPlatform();
-#if defined(_WIN32)
- cl_context_properties props[] = {
- CL_GL_CONTEXT_KHR,
- (cl_context_properties)wglGetCurrentContext(),
- CL_WGL_HDC_KHR,
- (cl_context_properties)wglGetCurrentDC(),
- CL_CONTEXT_PLATFORM,
- (cl_context_properties)cp_platform,
- 0};
-#elif defined(__APPLE__)
+# if defined(_WIN32)
+ cl_context_properties props[] = {CL_GL_CONTEXT_KHR,
+ (cl_context_properties)wglGetCurrentContext(),
+ CL_WGL_HDC_KHR,
+ (cl_context_properties)wglGetCurrentDC(),
+ CL_CONTEXT_PLATFORM,
+ (cl_context_properties)cp_platform,
+ 0};
+# elif defined(__APPLE__)
CGLContextObj kCGLContext = CGLGetCurrentContext();
CGLShareGroupObj kCGLShareGroup = CGLGetShareGroup(kCGLContext);
- cl_context_properties props[] = {CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE,
- (cl_context_properties)kCGLShareGroup,
- 0};
-#else
cl_context_properties props[] = {
- CL_GL_CONTEXT_KHR,
- (cl_context_properties)glXGetCurrentContext(),
- CL_GLX_DISPLAY_KHR,
- (cl_context_properties)glXGetCurrentDisplay(),
- CL_CONTEXT_PLATFORM,
- (cl_context_properties)cp_platform,
- 0};
-#endif
+ CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, (cl_context_properties)kCGLShareGroup, 0};
+# else
+ cl_context_properties props[] = {CL_GL_CONTEXT_KHR,
+ (cl_context_properties)glXGetCurrentContext(),
+ CL_GLX_DISPLAY_KHR,
+ (cl_context_properties)glXGetCurrentDisplay(),
+ CL_CONTEXT_PLATFORM,
+ (cl_context_properties)cp_platform,
+ 0};
+# endif
-#if defined(__APPLE__)
- _clContext = clCreateContext(props, 0, NULL, clLogMessagesToStdoutAPPLE, NULL,
- &cl_error_number);
+# if defined(__APPLE__)
+ _clContext = clCreateContext(props, 0, NULL, clLogMessagesToStdoutAPPLE, NULL, &cl_error_number);
if (cl_error_number != CL_SUCCESS) {
error("Error %d in clCreateContext\n", cl_error_number);
return false;
}
size_t devices_size = 0;
- clGetGLContextInfoAPPLE(_clContext, kCGLContext,
+ clGetGLContextInfoAPPLE(_clContext,
+ kCGLContext,
CL_CGL_DEVICES_FOR_SUPPORTED_VIRTUAL_SCREENS_APPLE,
0,
NULL,
@@ -204,13 +196,14 @@ bool CLDeviceContext::Initialize() {
return false;
}
vector<cl_device_id> cl_devices(num_devices);
- clGetGLContextInfoAPPLE(_clContext, kCGLContext,
+ clGetGLContextInfoAPPLE(_clContext,
+ kCGLContext,
CL_CGL_DEVICES_FOR_SUPPORTED_VIRTUAL_SCREENS_APPLE,
num_devices * sizeof(cl_device_id),
&cl_devices[0],
NULL);
int cl_device_used = 0;
-#else // not __APPLE__
+# else // not __APPLE__
// Get the number of GPU devices available to the platform.
cl_uint num_devices = 0;
clGetDeviceIDs(cp_platform, CL_DEVICE_TYPE_GPU, 0, NULL, &num_devices);
@@ -220,33 +213,22 @@ bool CLDeviceContext::Initialize() {
}
// Create the device list.
vector<cl_device_id> cl_devices(num_devices);
- clGetDeviceIDs(cp_platform,
- CL_DEVICE_TYPE_GPU,
- num_devices,
- &cl_devices[0],
- NULL);
- const char* extension = "cl_khr_gl_sharing";
- int cl_device_used = findExtensionSupportedDevice(&cl_devices[0],
- num_devices,
- extension);
+ clGetDeviceIDs(cp_platform, CL_DEVICE_TYPE_GPU, num_devices, &cl_devices[0], NULL);
+ const char *extension = "cl_khr_gl_sharing";
+ int cl_device_used = findExtensionSupportedDevice(&cl_devices[0], num_devices, extension);
if (cl_device_used < 0) {
error("No device found that supports CL/GL context sharing\n");
return false;
}
- cl_context_ = clCreateContext(props,
- 1,
- &cl_devices[cl_device_used],
- NULL, NULL,
- &cl_error_number);
-#endif // not __APPLE__
+ cl_context_ = clCreateContext(
+ props, 1, &cl_devices[cl_device_used], NULL, NULL, &cl_error_number);
+# endif // not __APPLE__
if (cl_error_number != CL_SUCCESS) {
error("Error %d in clCreateContext\n", cl_error_number);
return false;
}
- cl_command_queue_ = clCreateCommandQueue(cl_context_,
- cl_devices[cl_device_used],
- 0,
- &cl_error_number);
+ cl_command_queue_ = clCreateCommandQueue(
+ cl_context_, cl_devices[cl_device_used], 0, &cl_error_number);
if (cl_error_number != CL_SUCCESS) {
error("Error %d in clCreateCommandQueue\n", cl_error_number);
return false;
@@ -254,15 +236,18 @@ bool CLDeviceContext::Initialize() {
return true;
}
-bool CLDeviceContext::IsInitialized() const {
+bool CLDeviceContext::IsInitialized() const
+{
return (cl_context_ != NULL);
}
-cl_context CLDeviceContext::GetContext() const {
+cl_context CLDeviceContext::GetContext() const
+{
return cl_context_;
}
-cl_command_queue CLDeviceContext::GetCommandQueue() const {
+cl_command_queue CLDeviceContext::GetCommandQueue() const
+{
return cl_command_queue_;
}
diff --git a/intern/opensubdiv/internal/opensubdiv_device_context_opencl.h b/intern/opensubdiv/internal/opensubdiv_device_context_opencl.h
index bc751cb6954..6baf0774319 100644
--- a/intern/opensubdiv/internal/opensubdiv_device_context_opencl.h
+++ b/intern/opensubdiv/internal/opensubdiv_device_context_opencl.h
@@ -26,7 +26,7 @@
#define OPENSUBDIV_DEVICE_CONTEXT_OPENCL_H_
#ifdef OPENSUBDIV_HAS_OPENCL
-#include <opensubdiv/osd/opencl.h>
+# include <opensubdiv/osd/opencl.h>
class CLDeviceContext {
public:
diff --git a/intern/opensubdiv/internal/opensubdiv_edge_map.h b/intern/opensubdiv/internal/opensubdiv_edge_map.h
index 8825f663c15..661b8a10eda 100644
--- a/intern/opensubdiv/internal/opensubdiv_edge_map.h
+++ b/intern/opensubdiv/internal/opensubdiv_edge_map.h
@@ -31,7 +31,7 @@ class EdgeKey {
inline EdgeKey(int v1, int v2);
inline size_t hash() const;
- inline bool operator==(const EdgeKey& other) const;
+ inline bool operator==(const EdgeKey &other) const;
// These indices are guaranteed to be so v1 < v2.
int v1;
@@ -39,8 +39,7 @@ class EdgeKey {
};
// Map from an edge defined by its verticies index to a custom tag value.
-template<typename T>
-class EdgeTagMap {
+template<typename T> class EdgeTagMap {
public:
typedef EdgeKey key_type;
typedef T value_type;
@@ -49,16 +48,16 @@ class EdgeTagMap {
// Modifiers.
inline void clear();
- inline void insert(const key_type& key, const value_type& value);
- inline void insert(int v1, int v2, const value_type& value);
+ inline void insert(const key_type &key, const value_type &value);
+ inline void insert(int v1, int v2, const value_type &value);
// Lookup.
- value_type& at(const key_type& key);
- value_type& at(key_type&& key);
- value_type& at(int v1, int v2);
+ value_type &at(const key_type &key);
+ value_type &at(key_type &&key);
+ value_type &at(int v1, int v2);
- value_type& operator[](const key_type& key);
- value_type& operator[](key_type&& key);
+ value_type &operator[](const key_type &key);
+ value_type &operator[](key_type &&key);
protected:
unordered_map<key_type, value_type> edge_tags_;
@@ -69,77 +68,79 @@ class EdgeTagMap {
// EdgeKey.
-EdgeKey::EdgeKey()
- : v1(-1),
- v2(-1) {
+EdgeKey::EdgeKey() : v1(-1), v2(-1)
+{
}
-EdgeKey::EdgeKey(int v1, int v2) {
+EdgeKey::EdgeKey(int v1, int v2)
+{
assert(v1 >= 0);
assert(v2 >= 0);
assert(v1 != v2);
if (v1 < v2) {
this->v1 = v1;
this->v2 = v2;
- } else {
+ }
+ else {
this->v1 = v2;
this->v2 = v1;
}
}
-size_t EdgeKey::hash() const {
+size_t EdgeKey::hash() const
+{
return (static_cast<uint64_t>(v1) << 32) | v2;
}
-bool EdgeKey::operator==(const EdgeKey& other) const {
- return v1 == other.v1 &&
- v2 == other.v2;
+bool EdgeKey::operator==(const EdgeKey &other) const
+{
+ return v1 == other.v1 && v2 == other.v2;
}
// EdgeTagMap.
-template<typename T>
-EdgeTagMap<T>::EdgeTagMap() {
+template<typename T> EdgeTagMap<T>::EdgeTagMap()
+{
}
-template<typename T>
-void EdgeTagMap<T>::clear() {
+template<typename T> void EdgeTagMap<T>::clear()
+{
edge_tags_.clear();
}
-template<typename T>
-void EdgeTagMap<T>::insert(const key_type& key, const value_type& value) {
+template<typename T> void EdgeTagMap<T>::insert(const key_type &key, const value_type &value)
+{
edge_tags_.insert(make_pair(key, value));
}
-template<typename T>
-void EdgeTagMap<T>::insert(int v1, int v2, const value_type& value) {
+template<typename T> void EdgeTagMap<T>::insert(int v1, int v2, const value_type &value)
+{
insert(EdgeKey(v1, v2), value);
}
-template<typename T>
-typename EdgeTagMap<T>::value_type& EdgeTagMap<T>::at(const key_type& key) {
+template<typename T> typename EdgeTagMap<T>::value_type &EdgeTagMap<T>::at(const key_type &key)
+{
return edge_tags_.at[key];
}
-template<typename T>
-typename EdgeTagMap<T>::value_type& EdgeTagMap<T>::at(key_type&& key) {
+template<typename T> typename EdgeTagMap<T>::value_type &EdgeTagMap<T>::at(key_type &&key)
+{
return edge_tags_.at[key];
}
-template<typename T>
-typename EdgeTagMap<T>::value_type& EdgeTagMap<T>::at(int v1, int v2) {
+template<typename T> typename EdgeTagMap<T>::value_type &EdgeTagMap<T>::at(int v1, int v2)
+{
return edge_tags_.at(EdgeKey(v1, v2));
}
template<typename T>
-typename EdgeTagMap<T>::value_type& EdgeTagMap<T>::operator[](
- const key_type& key) {
+typename EdgeTagMap<T>::value_type &EdgeTagMap<T>::operator[](const key_type &key)
+{
return edge_tags_[key];
}
-template<typename T>
-typename EdgeTagMap<T>::value_type& EdgeTagMap<T>::operator[](key_type&& key) {
+template<typename T> typename EdgeTagMap<T>::value_type &EdgeTagMap<T>::operator[](key_type &&key)
+{
return edge_tags_[key];
}
@@ -147,9 +148,9 @@ typename EdgeTagMap<T>::value_type& EdgeTagMap<T>::operator[](key_type&& key) {
namespace std {
-template <>
-struct hash<opensubdiv_capi::EdgeKey> {
- std::size_t operator()(const opensubdiv_capi::EdgeKey& key) const {
+template<> struct hash<opensubdiv_capi::EdgeKey> {
+ std::size_t operator()(const opensubdiv_capi::EdgeKey &key) const
+ {
return key.hash();
}
};
diff --git a/intern/opensubdiv/internal/opensubdiv_evaluator.cc b/intern/opensubdiv/internal/opensubdiv_evaluator.cc
index 49b8626448b..2500691885c 100644
--- a/intern/opensubdiv/internal/opensubdiv_evaluator.cc
+++ b/intern/opensubdiv/internal/opensubdiv_evaluator.cc
@@ -25,108 +25,105 @@
namespace {
-void setCoarsePositions(OpenSubdiv_Evaluator* evaluator,
- const float* positions,
- const int start_vertex_index, const int num_vertices) {
- evaluator->internal->eval_output->setCoarsePositions(positions,
- start_vertex_index,
- num_vertices);
+void setCoarsePositions(OpenSubdiv_Evaluator *evaluator,
+ const float *positions,
+ const int start_vertex_index,
+ const int num_vertices)
+{
+ evaluator->internal->eval_output->setCoarsePositions(
+ positions, start_vertex_index, num_vertices);
}
-void setVaryingData(OpenSubdiv_Evaluator* evaluator,
- const float* varying_data,
- const int start_vertex_index, const int num_vertices) {
- evaluator->internal->eval_output->setVaryingData(varying_data,
- start_vertex_index,
- num_vertices);
+void setVaryingData(OpenSubdiv_Evaluator *evaluator,
+ const float *varying_data,
+ const int start_vertex_index,
+ const int num_vertices)
+{
+ evaluator->internal->eval_output->setVaryingData(varying_data, start_vertex_index, num_vertices);
}
-void setFaceVaryingData(OpenSubdiv_Evaluator* evaluator,
+void setFaceVaryingData(OpenSubdiv_Evaluator *evaluator,
const int face_varying_channel,
- const float* face_varying_data,
- const int start_vertex_index, const int num_vertices) {
- evaluator->internal->eval_output->setFaceVaryingData(face_varying_channel,
- face_varying_data,
- start_vertex_index,
- num_vertices);
+ const float *face_varying_data,
+ const int start_vertex_index,
+ const int num_vertices)
+{
+ evaluator->internal->eval_output->setFaceVaryingData(
+ face_varying_channel, face_varying_data, start_vertex_index, num_vertices);
}
-void setCoarsePositionsFromBuffer(OpenSubdiv_Evaluator* evaluator,
- const void* buffer,
+void setCoarsePositionsFromBuffer(OpenSubdiv_Evaluator *evaluator,
+ const void *buffer,
const int start_offset,
const int stride,
const int start_vertex_index,
- const int num_vertices) {
+ const int num_vertices)
+{
evaluator->internal->eval_output->setCoarsePositionsFromBuffer(
- buffer,
- start_offset,
- stride,
- start_vertex_index,
- num_vertices);
+ buffer, start_offset, stride, start_vertex_index, num_vertices);
}
-void setVaryingDataFromBuffer(OpenSubdiv_Evaluator* evaluator,
- const void* buffer,
+void setVaryingDataFromBuffer(OpenSubdiv_Evaluator *evaluator,
+ const void *buffer,
const int start_offset,
const int stride,
const int start_vertex_index,
- const int num_vertices) {
+ const int num_vertices)
+{
evaluator->internal->eval_output->setVaryingDataFromBuffer(
- buffer,
- start_offset,
- stride,
- start_vertex_index,
- num_vertices);
+ buffer, start_offset, stride, start_vertex_index, num_vertices);
}
-void setFaceVaryingDataFromBuffer(OpenSubdiv_Evaluator* evaluator,
+void setFaceVaryingDataFromBuffer(OpenSubdiv_Evaluator *evaluator,
const int face_varying_channel,
- const void* buffer,
+ const void *buffer,
const int start_offset,
const int stride,
const int start_vertex_index,
- const int num_vertices) {
+ const int num_vertices)
+{
evaluator->internal->eval_output->setFaceVaryingDataFromBuffer(
- face_varying_channel,
- buffer,
- start_offset,
- stride,
- start_vertex_index,
- num_vertices);
+ face_varying_channel, buffer, start_offset, stride, start_vertex_index, num_vertices);
}
-void refine(OpenSubdiv_Evaluator* evaluator) {
+void refine(OpenSubdiv_Evaluator *evaluator)
+{
evaluator->internal->eval_output->refine();
}
-void evaluateLimit(OpenSubdiv_Evaluator* evaluator,
+void evaluateLimit(OpenSubdiv_Evaluator *evaluator,
const int ptex_face_index,
- const float face_u, const float face_v,
- float P[3], float dPdu[3], float dPdv[3]) {
- evaluator->internal->eval_output->evaluateLimit(ptex_face_index,
- face_u, face_v,
- P, dPdu, dPdv);
+ const float face_u,
+ const float face_v,
+ float P[3],
+ float dPdu[3],
+ float dPdv[3])
+{
+ evaluator->internal->eval_output->evaluateLimit(ptex_face_index, face_u, face_v, P, dPdu, dPdv);
}
-void evaluateVarying(OpenSubdiv_Evaluator* evaluator,
+void evaluateVarying(OpenSubdiv_Evaluator *evaluator,
const int ptex_face_index,
- float face_u, float face_v,
- float varying[3]) {
- evaluator->internal->eval_output->evaluateVarying(ptex_face_index,
- face_u, face_v,
- varying);
+ float face_u,
+ float face_v,
+ float varying[3])
+{
+ evaluator->internal->eval_output->evaluateVarying(ptex_face_index, face_u, face_v, varying);
}
-void evaluateFaceVarying(OpenSubdiv_Evaluator* evaluator,
+void evaluateFaceVarying(OpenSubdiv_Evaluator *evaluator,
const int face_varying_channel,
const int ptex_face_index,
- float face_u, float face_v,
- float face_varying[2]) {
+ float face_u,
+ float face_v,
+ float face_varying[2])
+{
evaluator->internal->eval_output->evaluateFaceVarying(
face_varying_channel, ptex_face_index, face_u, face_v, face_varying);
}
-void assignFunctionPointers(OpenSubdiv_Evaluator* evaluator) {
+void assignFunctionPointers(OpenSubdiv_Evaluator *evaluator)
+{
evaluator->setCoarsePositions = setCoarsePositions;
evaluator->setVaryingData = setVaryingData;
evaluator->setFaceVaryingData = setFaceVaryingData;
@@ -144,15 +141,17 @@ void assignFunctionPointers(OpenSubdiv_Evaluator* evaluator) {
} // namespace
-OpenSubdiv_Evaluator* openSubdiv_createEvaluatorFromTopologyRefiner(
- OpenSubdiv_TopologyRefiner* topology_refiner) {
- OpenSubdiv_Evaluator* evaluator = OBJECT_GUARDED_NEW(OpenSubdiv_Evaluator);
+OpenSubdiv_Evaluator *openSubdiv_createEvaluatorFromTopologyRefiner(
+ OpenSubdiv_TopologyRefiner *topology_refiner)
+{
+ OpenSubdiv_Evaluator *evaluator = OBJECT_GUARDED_NEW(OpenSubdiv_Evaluator);
assignFunctionPointers(evaluator);
evaluator->internal = openSubdiv_createEvaluatorInternal(topology_refiner);
return evaluator;
}
-void openSubdiv_deleteEvaluator(OpenSubdiv_Evaluator* evaluator) {
+void openSubdiv_deleteEvaluator(OpenSubdiv_Evaluator *evaluator)
+{
openSubdiv_deleteEvaluatorInternal(evaluator->internal);
OBJECT_GUARDED_DELETE(evaluator, OpenSubdiv_Evaluator);
}
diff --git a/intern/opensubdiv/internal/opensubdiv_evaluator_internal.cc b/intern/opensubdiv/internal/opensubdiv_evaluator_internal.cc
index 9a8729ccda4..fa45c0119ec 100644
--- a/intern/opensubdiv/internal/opensubdiv_evaluator_internal.cc
+++ b/intern/opensubdiv/internal/opensubdiv_evaluator_internal.cc
@@ -42,17 +42,17 @@
#include "internal/opensubdiv_util.h"
#include "opensubdiv_topology_refiner_capi.h"
-using OpenSubdiv::Osd::BufferDescriptor;
-using OpenSubdiv::Osd::CpuEvaluator;
-using OpenSubdiv::Osd::CpuPatchTable;
-using OpenSubdiv::Osd::CpuVertexBuffer;
-using OpenSubdiv::Osd::PatchCoord;
using OpenSubdiv::Far::PatchMap;
using OpenSubdiv::Far::PatchTable;
using OpenSubdiv::Far::PatchTableFactory;
using OpenSubdiv::Far::StencilTable;
using OpenSubdiv::Far::StencilTableFactory;
using OpenSubdiv::Far::TopologyRefiner;
+using OpenSubdiv::Osd::BufferDescriptor;
+using OpenSubdiv::Osd::CpuEvaluator;
+using OpenSubdiv::Osd::CpuPatchTable;
+using OpenSubdiv::Osd::CpuVertexBuffer;
+using OpenSubdiv::Osd::PatchCoord;
// TODO(sergey): Remove after official requirement bump for OSD version.
#if OPENSUBDIV_VERSION_NUMBER >= 30200
@@ -70,23 +70,27 @@ namespace {
// supported.
class PatchCoordBuffer : public vector<PatchCoord> {
public:
- static PatchCoordBuffer* Create(int size) {
- PatchCoordBuffer* buffer = new PatchCoordBuffer();
+ static PatchCoordBuffer *Create(int size)
+ {
+ PatchCoordBuffer *buffer = new PatchCoordBuffer();
buffer->resize(size);
return buffer;
}
- PatchCoord* BindCpuBuffer() {
- return reinterpret_cast<PatchCoord*>(&(*this)[0]);
+ PatchCoord *BindCpuBuffer()
+ {
+ return reinterpret_cast<PatchCoord *>(&(*this)[0]);
}
- int GetNumVertices() {
+ int GetNumVertices()
+ {
return size();
}
- void UpdateData(const PatchCoord* patch_coords, int num_patch_coords) {
+ void UpdateData(const PatchCoord *patch_coords, int num_patch_coords)
+ {
memcpy(&(*this)[0],
- reinterpret_cast<const void*>(patch_coords),
+ reinterpret_cast<const void *>(patch_coords),
sizeof(PatchCoord) * num_patch_coords);
}
};
@@ -95,26 +99,31 @@ class PatchCoordBuffer : public vector<PatchCoord> {
// coordinates to the CPU evaluator. Other evaluators are not supported.
class SinglePatchCoordBuffer {
public:
- static SinglePatchCoordBuffer* Create() {
+ static SinglePatchCoordBuffer *Create()
+ {
return new SinglePatchCoordBuffer();
}
- SinglePatchCoordBuffer() {
+ SinglePatchCoordBuffer()
+ {
}
- explicit SinglePatchCoordBuffer(const PatchCoord &patch_coord)
- : patch_coord_(patch_coord) {
+ explicit SinglePatchCoordBuffer(const PatchCoord &patch_coord) : patch_coord_(patch_coord)
+ {
}
- PatchCoord* BindCpuBuffer() {
+ PatchCoord *BindCpuBuffer()
+ {
return &patch_coord_;
}
- int GetNumVertices() {
+ int GetNumVertices()
+ {
return 1;
}
- void UpdateData(const PatchCoord &patch_coord) {
+ void UpdateData(const PatchCoord &patch_coord)
+ {
patch_coord_ = patch_coord;
}
@@ -126,20 +135,22 @@ class SinglePatchCoordBuffer {
// and better to be allocated in stack rather than in heap.
//
// TODO(sergey): Check if bare arrays could be used by CPU evaluator.
-template <int element_size, int num_vertices>
-class StackAllocatedBuffer {
+template<int element_size, int num_vertices> class StackAllocatedBuffer {
public:
- static PatchCoordBuffer* Create(int /*size*/) {
+ static PatchCoordBuffer *Create(int /*size*/)
+ {
// TODO(sergey): Validate that requested size is smaller than static
// stack memory size.
return new StackAllocatedBuffer<element_size, num_vertices>();
}
- float* BindCpuBuffer() {
+ float *BindCpuBuffer()
+ {
return &data_[0];
}
- int GetNumVertices() {
+ int GetNumVertices()
+ {
return num_vertices;
}
@@ -148,87 +159,82 @@ class StackAllocatedBuffer {
float data_[element_size * num_vertices];
};
-template <typename EVAL_VERTEX_BUFFER,
- typename STENCIL_TABLE,
- typename PATCH_TABLE,
- typename EVALUATOR,
- typename DEVICE_CONTEXT = void>
+template<typename EVAL_VERTEX_BUFFER,
+ typename STENCIL_TABLE,
+ typename PATCH_TABLE,
+ typename EVALUATOR,
+ typename DEVICE_CONTEXT = void>
class FaceVaryingVolatileEval {
public:
typedef OpenSubdiv::Osd::EvaluatorCacheT<EVALUATOR> EvaluatorCache;
FaceVaryingVolatileEval(int face_varying_channel,
- const StencilTable* face_varying_stencils,
+ const StencilTable *face_varying_stencils,
int face_varying_width,
- PATCH_TABLE* patch_table,
- EvaluatorCache* evaluator_cache = NULL,
- DEVICE_CONTEXT* device_context = NULL)
+ PATCH_TABLE *patch_table,
+ EvaluatorCache *evaluator_cache = NULL,
+ DEVICE_CONTEXT *device_context = NULL)
: face_varying_channel_(face_varying_channel),
src_face_varying_desc_(0, face_varying_width, face_varying_width),
patch_table_(patch_table),
evaluator_cache_(evaluator_cache),
- device_context_(device_context) {
+ device_context_(device_context)
+ {
using OpenSubdiv::Osd::convertToCompatibleStencilTable;
- num_coarse_face_varying_vertices_ =
- face_varying_stencils->GetNumControlVertices();
- const int num_total_face_varying_vertices =
- face_varying_stencils->GetNumControlVertices() +
- face_varying_stencils->GetNumStencils();
- src_face_varying_data_ =
- EVAL_VERTEX_BUFFER::Create(2,
- num_total_face_varying_vertices,
- device_context);
- face_varying_stencils_ = convertToCompatibleStencilTable<STENCIL_TABLE>(
- face_varying_stencils, device_context_);
- }
-
- ~FaceVaryingVolatileEval() {
+ num_coarse_face_varying_vertices_ = face_varying_stencils->GetNumControlVertices();
+ const int num_total_face_varying_vertices = face_varying_stencils->GetNumControlVertices() +
+ face_varying_stencils->GetNumStencils();
+ src_face_varying_data_ = EVAL_VERTEX_BUFFER::Create(
+ 2, num_total_face_varying_vertices, device_context);
+ face_varying_stencils_ = convertToCompatibleStencilTable<STENCIL_TABLE>(face_varying_stencils,
+ device_context_);
+ }
+
+ ~FaceVaryingVolatileEval()
+ {
delete src_face_varying_data_;
delete face_varying_stencils_;
}
- void updateData(const float* src, int start_vertex, int num_vertices) {
- src_face_varying_data_->UpdateData(src,
- start_vertex,
- num_vertices,
- device_context_);
+ void updateData(const float *src, int start_vertex, int num_vertices)
+ {
+ src_face_varying_data_->UpdateData(src, start_vertex, num_vertices, device_context_);
}
- void refine() {
+ void refine()
+ {
BufferDescriptor dst_face_varying_desc = src_face_varying_desc_;
dst_face_varying_desc.offset += num_coarse_face_varying_vertices_ *
src_face_varying_desc_.stride;
- const EVALUATOR* eval_instance = OpenSubdiv::Osd::GetEvaluator<EVALUATOR>(
- evaluator_cache_,
- src_face_varying_desc_,
- dst_face_varying_desc,
- device_context_);
- EVALUATOR::EvalStencils(src_face_varying_data_, src_face_varying_desc_,
- src_face_varying_data_, dst_face_varying_desc,
+ const EVALUATOR *eval_instance = OpenSubdiv::Osd::GetEvaluator<EVALUATOR>(
+ evaluator_cache_, src_face_varying_desc_, dst_face_varying_desc, device_context_);
+ EVALUATOR::EvalStencils(src_face_varying_data_,
+ src_face_varying_desc_,
+ src_face_varying_data_,
+ dst_face_varying_desc,
face_varying_stencils_,
eval_instance,
device_context_);
}
- void evalPatch(const PatchCoord& patch_coord, float face_varying[2]) {
+ void evalPatch(const PatchCoord &patch_coord, float face_varying[2])
+ {
StackAllocatedBuffer<2, 1> face_varying_data;
BufferDescriptor face_varying_desc(0, 2, 2);
SinglePatchCoordBuffer patch_coord_buffer(patch_coord);
- const EVALUATOR* eval_instance =
- OpenSubdiv::Osd::GetEvaluator<EVALUATOR>(evaluator_cache_,
- src_face_varying_desc_,
- face_varying_desc,
- device_context_);
- EVALUATOR::EvalPatchesFaceVarying(
- src_face_varying_data_, src_face_varying_desc_,
- &face_varying_data, face_varying_desc,
- patch_coord_buffer.GetNumVertices(),
- &patch_coord_buffer,
- patch_table_,
- face_varying_channel_,
- eval_instance,
- device_context_);
- const float* refined_face_varying = face_varying_data.BindCpuBuffer();
+ const EVALUATOR *eval_instance = OpenSubdiv::Osd::GetEvaluator<EVALUATOR>(
+ evaluator_cache_, src_face_varying_desc_, face_varying_desc, device_context_);
+ EVALUATOR::EvalPatchesFaceVarying(src_face_varying_data_,
+ src_face_varying_desc_,
+ &face_varying_data,
+ face_varying_desc,
+ patch_coord_buffer.GetNumVertices(),
+ &patch_coord_buffer,
+ patch_table_,
+ face_varying_channel_,
+ eval_instance,
+ device_context_);
+ const float *refined_face_varying = face_varying_data.BindCpuBuffer();
memcpy(face_varying, refined_face_varying, sizeof(float) * 2);
}
@@ -238,14 +244,14 @@ class FaceVaryingVolatileEval {
BufferDescriptor src_face_varying_desc_;
int num_coarse_face_varying_vertices_;
- EVAL_VERTEX_BUFFER* src_face_varying_data_;
- const STENCIL_TABLE* face_varying_stencils_;
+ EVAL_VERTEX_BUFFER *src_face_varying_data_;
+ const STENCIL_TABLE *face_varying_stencils_;
// NOTE: We reference this, do not own it.
- PATCH_TABLE* patch_table_;
+ PATCH_TABLE *patch_table_;
- EvaluatorCache* evaluator_cache_;
- DEVICE_CONTEXT* device_context_;
+ EvaluatorCache *evaluator_cache_;
+ DEVICE_CONTEXT *device_context_;
};
// Volatile evaluator which can be used from threads.
@@ -254,12 +260,12 @@ class FaceVaryingVolatileEval {
// TODO(sergey): Make it possible to evaluate multiple face varying layers.
// (or maybe, it's cheap to create new evaluator for existing
// topology to evaluate all needed face varying layers?)
-template <typename SRC_VERTEX_BUFFER,
- typename EVAL_VERTEX_BUFFER,
- typename STENCIL_TABLE,
- typename PATCH_TABLE,
- typename EVALUATOR,
- typename DEVICE_CONTEXT = void>
+template<typename SRC_VERTEX_BUFFER,
+ typename EVAL_VERTEX_BUFFER,
+ typename STENCIL_TABLE,
+ typename PATCH_TABLE,
+ typename EVALUATOR,
+ typename DEVICE_CONTEXT = void>
class VolatileEvalOutput {
public:
typedef OpenSubdiv::Osd::EvaluatorCacheT<EVALUATOR> EvaluatorCache;
@@ -267,146 +273,141 @@ class VolatileEvalOutput {
STENCIL_TABLE,
PATCH_TABLE,
EVALUATOR,
- DEVICE_CONTEXT> FaceVaryingEval;
-
- VolatileEvalOutput(
- const StencilTable* vertex_stencils,
- const StencilTable* varying_stencils,
- const vector<const StencilTable*>& all_face_varying_stencils,
- const int face_varying_width,
- const PatchTable* patch_table,
- EvaluatorCache* evaluator_cache = NULL,
- DEVICE_CONTEXT* device_context = NULL)
+ DEVICE_CONTEXT>
+ FaceVaryingEval;
+
+ VolatileEvalOutput(const StencilTable *vertex_stencils,
+ const StencilTable *varying_stencils,
+ const vector<const StencilTable *> &all_face_varying_stencils,
+ const int face_varying_width,
+ const PatchTable *patch_table,
+ EvaluatorCache *evaluator_cache = NULL,
+ DEVICE_CONTEXT *device_context = NULL)
: src_desc_(0, 3, 3),
src_varying_desc_(0, 3, 3),
face_varying_width_(face_varying_width),
evaluator_cache_(evaluator_cache),
- device_context_(device_context) {
+ device_context_(device_context)
+ {
// Total number of vertices = coarse points + refined points + local points.
int num_total_vertices = vertex_stencils->GetNumControlVertices() +
vertex_stencils->GetNumStencils();
num_coarse_vertices_ = vertex_stencils->GetNumControlVertices();
using OpenSubdiv::Osd::convertToCompatibleStencilTable;
- src_data_ =
- SRC_VERTEX_BUFFER::Create(3, num_total_vertices, device_context_);
- src_varying_data_ =
- SRC_VERTEX_BUFFER::Create(3, num_total_vertices, device_context_);
+ src_data_ = SRC_VERTEX_BUFFER::Create(3, num_total_vertices, device_context_);
+ src_varying_data_ = SRC_VERTEX_BUFFER::Create(3, num_total_vertices, device_context_);
patch_table_ = PATCH_TABLE::Create(patch_table, device_context_);
patch_coords_ = NULL;
- vertex_stencils_ = convertToCompatibleStencilTable<STENCIL_TABLE>(
- vertex_stencils, device_context_);
- varying_stencils_ = convertToCompatibleStencilTable<STENCIL_TABLE>(
- varying_stencils, device_context_);
+ vertex_stencils_ = convertToCompatibleStencilTable<STENCIL_TABLE>(vertex_stencils,
+ device_context_);
+ varying_stencils_ = convertToCompatibleStencilTable<STENCIL_TABLE>(varying_stencils,
+ device_context_);
// Create evaluators for every face varying channel.
face_varying_evaluators.reserve(all_face_varying_stencils.size());
int face_varying_channel = 0;
- foreach (const StencilTable* face_varying_stencils,
- all_face_varying_stencils) {
- face_varying_evaluators.push_back(
- new FaceVaryingEval(face_varying_channel,
- face_varying_stencils,
- face_varying_width,
- patch_table_,
- evaluator_cache_,
- device_context_));
+ foreach (const StencilTable *face_varying_stencils, all_face_varying_stencils) {
+ face_varying_evaluators.push_back(new FaceVaryingEval(face_varying_channel,
+ face_varying_stencils,
+ face_varying_width,
+ patch_table_,
+ evaluator_cache_,
+ device_context_));
++face_varying_channel;
}
}
- ~VolatileEvalOutput() {
+ ~VolatileEvalOutput()
+ {
delete src_data_;
delete src_varying_data_;
delete patch_table_;
delete vertex_stencils_;
delete varying_stencils_;
- foreach (FaceVaryingEval* face_varying_evaluator, face_varying_evaluators) {
+ foreach (FaceVaryingEval *face_varying_evaluator, face_varying_evaluators) {
delete face_varying_evaluator;
}
}
// TODO(sergey): Implement binding API.
- void updateData(const float* src, int start_vertex, int num_vertices) {
+ void updateData(const float *src, int start_vertex, int num_vertices)
+ {
src_data_->UpdateData(src, start_vertex, num_vertices, device_context_);
}
- void updateVaryingData(const float* src, int start_vertex, int num_vertices) {
- src_varying_data_->UpdateData(src,
- start_vertex,
- num_vertices,
- device_context_);
+ void updateVaryingData(const float *src, int start_vertex, int num_vertices)
+ {
+ src_varying_data_->UpdateData(src, start_vertex, num_vertices, device_context_);
}
void updateFaceVaryingData(const int face_varying_channel,
- const float* src,
+ const float *src,
int start_vertex,
- int num_vertices) {
+ int num_vertices)
+ {
assert(face_varying_channel >= 0);
assert(face_varying_channel < face_varying_evaluators.size());
- face_varying_evaluators[face_varying_channel]->updateData(
- src, start_vertex, num_vertices);
+ face_varying_evaluators[face_varying_channel]->updateData(src, start_vertex, num_vertices);
}
- bool hasVaryingData() const {
+ bool hasVaryingData() const
+ {
// return varying_stencils_ != NULL;
// TODO(sergey): Check this based on actual topology.
return false;
}
- bool hasFaceVaryingData() const {
+ bool hasFaceVaryingData() const
+ {
return face_varying_evaluators.size() != 0;
}
- void refine() {
+ void refine()
+ {
// Evaluate vertex positions.
BufferDescriptor dst_desc = src_desc_;
dst_desc.offset += num_coarse_vertices_ * src_desc_.stride;
- const EVALUATOR* eval_instance =
- OpenSubdiv::Osd::GetEvaluator<EVALUATOR>(evaluator_cache_,
- src_desc_,
- dst_desc,
- device_context_);
- EVALUATOR::EvalStencils(src_data_, src_desc_,
- src_data_, dst_desc,
+ const EVALUATOR *eval_instance = OpenSubdiv::Osd::GetEvaluator<EVALUATOR>(
+ evaluator_cache_, src_desc_, dst_desc, device_context_);
+ EVALUATOR::EvalStencils(src_data_,
+ src_desc_,
+ src_data_,
+ dst_desc,
vertex_stencils_,
eval_instance,
device_context_);
// Evaluate varying data.
if (hasVaryingData()) {
BufferDescriptor dst_varying_desc = src_varying_desc_;
- dst_varying_desc.offset +=
- num_coarse_vertices_ * src_varying_desc_.stride;
+ dst_varying_desc.offset += num_coarse_vertices_ * src_varying_desc_.stride;
eval_instance = OpenSubdiv::Osd::GetEvaluator<EVALUATOR>(
- evaluator_cache_,
- src_varying_desc_,
- dst_varying_desc,
- device_context_);
- EVALUATOR::EvalStencils(src_varying_data_, src_varying_desc_,
- src_varying_data_, dst_varying_desc,
+ evaluator_cache_, src_varying_desc_, dst_varying_desc, device_context_);
+ EVALUATOR::EvalStencils(src_varying_data_,
+ src_varying_desc_,
+ src_varying_data_,
+ dst_varying_desc,
varying_stencils_,
- eval_instance, device_context_);
+ eval_instance,
+ device_context_);
}
// Evaluate face-varying data.
if (hasFaceVaryingData()) {
- foreach (FaceVaryingEval* face_varying_evaluator,
- face_varying_evaluators) {
+ foreach (FaceVaryingEval *face_varying_evaluator, face_varying_evaluators) {
face_varying_evaluator->refine();
}
}
}
- void evalPatchCoord(const PatchCoord& patch_coord, float P[3]) {
+ void evalPatchCoord(const PatchCoord &patch_coord, float P[3])
+ {
StackAllocatedBuffer<6, 1> vertex_data;
// TODO(sergey): Varying data is interleaved in vertex array, so need to
// adjust stride if there is a varying data.
// BufferDescriptor vertex_desc(0, 3, 6);
BufferDescriptor vertex_desc(0, 3, 3);
SinglePatchCoordBuffer patch_coord_buffer(patch_coord);
- const EVALUATOR* eval_instance =
- OpenSubdiv::Osd::GetEvaluator<EVALUATOR>(evaluator_cache_,
- src_desc_,
- vertex_desc,
- device_context_);
+ const EVALUATOR *eval_instance = OpenSubdiv::Osd::GetEvaluator<EVALUATOR>(
+ evaluator_cache_, src_desc_, vertex_desc, device_context_);
EVALUATOR::EvalPatches(src_data_,
src_desc_,
&vertex_data,
@@ -416,13 +417,15 @@ class VolatileEvalOutput {
patch_table_,
eval_instance,
device_context_);
- const float* refined_vertices = vertex_data.BindCpuBuffer();
+ const float *refined_vertices = vertex_data.BindCpuBuffer();
memcpy(P, refined_vertices, sizeof(float) * 3);
}
- void evalPatchesWithDerivatives(const PatchCoord& patch_coord,
+ void evalPatchesWithDerivatives(const PatchCoord &patch_coord,
float P[3],
- float dPdu[3], float dPdv[3]) {
+ float dPdu[3],
+ float dPdv[3])
+ {
StackAllocatedBuffer<6, 1> vertex_data, derivatives;
// TODO(sergey): Varying data is interleaved in vertex array, so need to
// adjust stride if there is a varying data.
@@ -430,25 +433,25 @@ class VolatileEvalOutput {
BufferDescriptor vertex_desc(0, 3, 3);
BufferDescriptor du_desc(0, 3, 6), dv_desc(3, 3, 6);
SinglePatchCoordBuffer patch_coord_buffer(patch_coord);
- const EVALUATOR* eval_instance =
- OpenSubdiv::Osd::GetEvaluator<EVALUATOR>(evaluator_cache_,
- src_desc_,
- vertex_desc,
- du_desc, dv_desc,
- device_context_);
- EVALUATOR::EvalPatches(src_data_, src_desc_,
- &vertex_data, vertex_desc,
- &derivatives, du_desc,
- &derivatives, dv_desc,
+ const EVALUATOR *eval_instance = OpenSubdiv::Osd::GetEvaluator<EVALUATOR>(
+ evaluator_cache_, src_desc_, vertex_desc, du_desc, dv_desc, device_context_);
+ EVALUATOR::EvalPatches(src_data_,
+ src_desc_,
+ &vertex_data,
+ vertex_desc,
+ &derivatives,
+ du_desc,
+ &derivatives,
+ dv_desc,
patch_coord_buffer.GetNumVertices(),
&patch_coord_buffer,
patch_table_,
eval_instance,
device_context_);
- const float* refined_vertices = vertex_data.BindCpuBuffer();
+ const float *refined_vertices = vertex_data.BindCpuBuffer();
memcpy(P, refined_vertices, sizeof(float) * 3);
if (dPdu != NULL || dPdv != NULL) {
- const float* refined_derivatives = derivatives.BindCpuBuffer();
+ const float *refined_derivatives = derivatives.BindCpuBuffer();
if (dPdu != NULL) {
memcpy(dPdu, refined_derivatives, sizeof(float) * 3);
}
@@ -458,53 +461,53 @@ class VolatileEvalOutput {
}
}
- void evalPatchVarying(const PatchCoord& patch_coord, float varying[3]) {
+ void evalPatchVarying(const PatchCoord &patch_coord, float varying[3])
+ {
StackAllocatedBuffer<6, 1> varying_data;
BufferDescriptor varying_desc(3, 3, 6);
SinglePatchCoordBuffer patch_coord_buffer(patch_coord);
- const EVALUATOR* eval_instance =
- OpenSubdiv::Osd::GetEvaluator<EVALUATOR>(evaluator_cache_,
- src_varying_desc_,
- varying_desc,
- device_context_);
- EVALUATOR::EvalPatchesVarying(src_varying_data_, src_varying_desc_,
- &varying_data, varying_desc,
+ const EVALUATOR *eval_instance = OpenSubdiv::Osd::GetEvaluator<EVALUATOR>(
+ evaluator_cache_, src_varying_desc_, varying_desc, device_context_);
+ EVALUATOR::EvalPatchesVarying(src_varying_data_,
+ src_varying_desc_,
+ &varying_data,
+ varying_desc,
patch_coord_buffer.GetNumVertices(),
&patch_coord_buffer,
patch_table_,
eval_instance,
device_context_);
- const float* refined_varying = varying_data.BindCpuBuffer();
+ const float *refined_varying = varying_data.BindCpuBuffer();
memcpy(varying, refined_varying, sizeof(float) * 3);
}
void evalPatchFaceVarying(const int face_varying_channel,
- const PatchCoord& patch_coord,
- float face_varying[2]) {
+ const PatchCoord &patch_coord,
+ float face_varying[2])
+ {
assert(face_varying_channel >= 0);
assert(face_varying_channel < face_varying_evaluators.size());
- face_varying_evaluators[face_varying_channel]->evalPatch(
- patch_coord, face_varying);
+ face_varying_evaluators[face_varying_channel]->evalPatch(patch_coord, face_varying);
}
private:
- SRC_VERTEX_BUFFER* src_data_;
- SRC_VERTEX_BUFFER* src_varying_data_;
- PatchCoordBuffer* patch_coords_;
- PATCH_TABLE* patch_table_;
+ SRC_VERTEX_BUFFER *src_data_;
+ SRC_VERTEX_BUFFER *src_varying_data_;
+ PatchCoordBuffer *patch_coords_;
+ PATCH_TABLE *patch_table_;
BufferDescriptor src_desc_;
BufferDescriptor src_varying_desc_;
int num_coarse_vertices_;
- const STENCIL_TABLE* vertex_stencils_;
- const STENCIL_TABLE* varying_stencils_;
+ const STENCIL_TABLE *vertex_stencils_;
+ const STENCIL_TABLE *varying_stencils_;
int face_varying_width_;
- vector<FaceVaryingEval*> face_varying_evaluators;
+ vector<FaceVaryingEval *> face_varying_evaluators;
- EvaluatorCache* evaluator_cache_;
- DEVICE_CONTEXT* device_context_;
+ EvaluatorCache *evaluator_cache_;
+ DEVICE_CONTEXT *device_context_;
};
} // namespace
@@ -517,12 +520,12 @@ class CpuEvalOutput : public VolatileEvalOutput<CpuVertexBuffer,
CpuPatchTable,
CpuEvaluator> {
public:
- CpuEvalOutput(const StencilTable* vertex_stencils,
- const StencilTable* varying_stencils,
- const vector<const StencilTable*>& all_face_varying_stencils,
+ CpuEvalOutput(const StencilTable *vertex_stencils,
+ const StencilTable *varying_stencils,
+ const vector<const StencilTable *> &all_face_varying_stencils,
const int face_varying_width,
- const PatchTable* patch_table,
- EvaluatorCache* evaluator_cache = NULL)
+ const PatchTable *patch_table,
+ EvaluatorCache *evaluator_cache = NULL)
: VolatileEvalOutput<CpuVertexBuffer,
CpuVertexBuffer,
StencilTable,
@@ -532,171 +535,179 @@ class CpuEvalOutput : public VolatileEvalOutput<CpuVertexBuffer,
all_face_varying_stencils,
face_varying_width,
patch_table,
- evaluator_cache) {
+ evaluator_cache)
+ {
}
};
////////////////////////////////////////////////////////////////////////////////
// Evaluator wrapper for anonymous API.
-CpuEvalOutputAPI::CpuEvalOutputAPI(CpuEvalOutput* implementation,
- OpenSubdiv::Far::PatchMap* patch_map)
- : implementation_(implementation),
- patch_map_(patch_map) {
+CpuEvalOutputAPI::CpuEvalOutputAPI(CpuEvalOutput *implementation,
+ OpenSubdiv::Far::PatchMap *patch_map)
+ : implementation_(implementation), patch_map_(patch_map)
+{
}
-CpuEvalOutputAPI::~CpuEvalOutputAPI() {
+CpuEvalOutputAPI::~CpuEvalOutputAPI()
+{
delete implementation_;
}
-void CpuEvalOutputAPI::setCoarsePositions(const float* positions,
+void CpuEvalOutputAPI::setCoarsePositions(const float *positions,
const int start_vertex_index,
- const int num_vertices) {
+ const int num_vertices)
+{
// TODO(sergey): Add sanity check on indices.
implementation_->updateData(positions, start_vertex_index, num_vertices);
}
-void CpuEvalOutputAPI::setVaryingData(const float* varying_data,
+void CpuEvalOutputAPI::setVaryingData(const float *varying_data,
const int start_vertex_index,
- const int num_vertices) {
+ const int num_vertices)
+{
// TODO(sergey): Add sanity check on indices.
- implementation_->updateVaryingData(varying_data,
- start_vertex_index,
- num_vertices);
+ implementation_->updateVaryingData(varying_data, start_vertex_index, num_vertices);
}
void CpuEvalOutputAPI::setFaceVaryingData(const int face_varying_channel,
- const float* face_varying_data,
+ const float *face_varying_data,
const int start_vertex_index,
- const int num_vertices) {
+ const int num_vertices)
+{
// TODO(sergey): Add sanity check on indices.
- implementation_->updateFaceVaryingData(face_varying_channel,
- face_varying_data,
- start_vertex_index,
- num_vertices);
+ implementation_->updateFaceVaryingData(
+ face_varying_channel, face_varying_data, start_vertex_index, num_vertices);
}
-void CpuEvalOutputAPI::setCoarsePositionsFromBuffer(
- const void* buffer,
- const int start_offset,
- const int stride,
- const int start_vertex_index,
- const int num_vertices) {
+void CpuEvalOutputAPI::setCoarsePositionsFromBuffer(const void *buffer,
+ const int start_offset,
+ const int stride,
+ const int start_vertex_index,
+ const int num_vertices)
+{
// TODO(sergey): Add sanity check on indices.
- const unsigned char* current_buffer = (unsigned char *)buffer;
+ const unsigned char *current_buffer = (unsigned char *)buffer;
current_buffer += start_offset;
for (int i = 0; i < num_vertices; ++i) {
const int current_vertex_index = start_vertex_index + i;
- implementation_->updateData(reinterpret_cast<const float*>(current_buffer),
- current_vertex_index, 1);
+ implementation_->updateData(
+ reinterpret_cast<const float *>(current_buffer), current_vertex_index, 1);
current_buffer += stride;
}
}
-void CpuEvalOutputAPI::setVaryingDataFromBuffer(
- const void* buffer,
- const int start_offset,
- const int stride,
- const int start_vertex_index,
- const int num_vertices) {
+void CpuEvalOutputAPI::setVaryingDataFromBuffer(const void *buffer,
+ const int start_offset,
+ const int stride,
+ const int start_vertex_index,
+ const int num_vertices)
+{
// TODO(sergey): Add sanity check on indices.
- const unsigned char* current_buffer = (unsigned char *)buffer;
+ const unsigned char *current_buffer = (unsigned char *)buffer;
current_buffer += start_offset;
for (int i = 0; i < num_vertices; ++i) {
const int current_vertex_index = start_vertex_index + i;
implementation_->updateVaryingData(
- reinterpret_cast<const float*>(current_buffer),
- current_vertex_index, 1);
+ reinterpret_cast<const float *>(current_buffer), current_vertex_index, 1);
current_buffer += stride;
}
}
-void CpuEvalOutputAPI::setFaceVaryingDataFromBuffer(
- const int face_varying_channel,
- const void* buffer,
- const int start_offset,
- const int stride,
- const int start_vertex_index,
- const int num_vertices) {
+void CpuEvalOutputAPI::setFaceVaryingDataFromBuffer(const int face_varying_channel,
+ const void *buffer,
+ const int start_offset,
+ const int stride,
+ const int start_vertex_index,
+ const int num_vertices)
+{
// TODO(sergey): Add sanity check on indices.
- const unsigned char* current_buffer = (unsigned char *)buffer;
+ const unsigned char *current_buffer = (unsigned char *)buffer;
current_buffer += start_offset;
for (int i = 0; i < num_vertices; ++i) {
const int current_vertex_index = start_vertex_index + i;
- implementation_->updateFaceVaryingData(
- face_varying_channel,
- reinterpret_cast<const float*>(current_buffer),
- current_vertex_index, 1);
+ implementation_->updateFaceVaryingData(face_varying_channel,
+ reinterpret_cast<const float *>(current_buffer),
+ current_vertex_index,
+ 1);
current_buffer += stride;
}
}
-void CpuEvalOutputAPI::refine() {
+void CpuEvalOutputAPI::refine()
+{
implementation_->refine();
}
void CpuEvalOutputAPI::evaluateLimit(const int ptex_face_index,
- float face_u, float face_v,
- float P[3], float dPdu[3], float dPdv[3]) {
+ float face_u,
+ float face_v,
+ float P[3],
+ float dPdu[3],
+ float dPdv[3])
+{
assert(face_u >= 0.0f);
assert(face_u <= 1.0f);
assert(face_v >= 0.0f);
assert(face_v <= 1.0f);
- const PatchTable::PatchHandle* handle =
- patch_map_->FindPatch(ptex_face_index, face_u, face_v);
+ const PatchTable::PatchHandle *handle = patch_map_->FindPatch(ptex_face_index, face_u, face_v);
PatchCoord patch_coord(*handle, face_u, face_v);
if (dPdu != NULL || dPdv != NULL) {
implementation_->evalPatchesWithDerivatives(patch_coord, P, dPdu, dPdv);
- } else {
+ }
+ else {
implementation_->evalPatchCoord(patch_coord, P);
- }}
+ }
+}
void CpuEvalOutputAPI::evaluateVarying(const int ptex_face_index,
- float face_u, float face_v,
- float varying[3]) {
+ float face_u,
+ float face_v,
+ float varying[3])
+{
assert(face_u >= 0.0f);
assert(face_u <= 1.0f);
assert(face_v >= 0.0f);
assert(face_v <= 1.0f);
- const PatchTable::PatchHandle* handle =
- patch_map_->FindPatch(ptex_face_index, face_u, face_v);
+ const PatchTable::PatchHandle *handle = patch_map_->FindPatch(ptex_face_index, face_u, face_v);
PatchCoord patch_coord(*handle, face_u, face_v);
implementation_->evalPatchVarying(patch_coord, varying);
}
void CpuEvalOutputAPI::evaluateFaceVarying(const int face_varying_channel,
const int ptex_face_index,
- float face_u, float face_v,
- float face_varying[2]) {
+ float face_u,
+ float face_v,
+ float face_varying[2])
+{
assert(face_u >= 0.0f);
assert(face_u <= 1.0f);
assert(face_v >= 0.0f);
assert(face_v <= 1.0f);
- const PatchTable::PatchHandle* handle =
- patch_map_->FindPatch(ptex_face_index, face_u, face_v);
+ const PatchTable::PatchHandle *handle = patch_map_->FindPatch(ptex_face_index, face_u, face_v);
PatchCoord patch_coord(*handle, face_u, face_v);
- implementation_->evalPatchFaceVarying(
- face_varying_channel, patch_coord, face_varying);
+ implementation_->evalPatchFaceVarying(face_varying_channel, patch_coord, face_varying);
}
} // namespace opensubdiv_capi
OpenSubdiv_EvaluatorInternal::OpenSubdiv_EvaluatorInternal()
- : eval_output(NULL),
- patch_map(NULL),
- patch_table(NULL) {
+ : eval_output(NULL), patch_map(NULL), patch_table(NULL)
+{
}
-OpenSubdiv_EvaluatorInternal::~OpenSubdiv_EvaluatorInternal() {
+OpenSubdiv_EvaluatorInternal::~OpenSubdiv_EvaluatorInternal()
+{
delete eval_output;
delete patch_map;
delete patch_table;
}
-OpenSubdiv_EvaluatorInternal* openSubdiv_createEvaluatorInternal(
- OpenSubdiv_TopologyRefiner* topology_refiner) {
+OpenSubdiv_EvaluatorInternal *openSubdiv_createEvaluatorInternal(
+ OpenSubdiv_TopologyRefiner *topology_refiner)
+{
using opensubdiv_capi::vector;
- TopologyRefiner* refiner = topology_refiner->internal->osd_topology_refiner;
+ TopologyRefiner *refiner = topology_refiner->internal->osd_topology_refiner;
if (refiner == NULL) {
// Happens on bad topology.
return NULL;
@@ -718,7 +729,8 @@ OpenSubdiv_EvaluatorInternal* openSubdiv_createEvaluatorInternal(
options.considerFVarChannels = has_face_varying_data;
options.useInfSharpPatch = use_inf_sharp_patch;
refiner->RefineAdaptive(options);
- } else {
+ }
+ else {
TopologyRefiner::UniformOptions options(level);
refiner->RefineUniform(options);
}
@@ -728,38 +740,31 @@ OpenSubdiv_EvaluatorInternal* openSubdiv_createEvaluatorInternal(
// Vertex stencils.
StencilTableFactory::Options vertex_stencil_options;
vertex_stencil_options.generateOffsets = stencil_generate_offsets;
- vertex_stencil_options.generateIntermediateLevels =
- stencil_generate_intermediate_levels;
- const StencilTable* vertex_stencils =
- StencilTableFactory::Create(*refiner, vertex_stencil_options);
+ vertex_stencil_options.generateIntermediateLevels = stencil_generate_intermediate_levels;
+ const StencilTable *vertex_stencils = StencilTableFactory::Create(*refiner,
+ vertex_stencil_options);
// Varying stencils.
//
// TODO(sergey): Seems currently varying stencils are always required in
// OpenSubdiv itself.
- const StencilTable* varying_stencils = NULL;
+ const StencilTable *varying_stencils = NULL;
if (has_varying_data) {
StencilTableFactory::Options varying_stencil_options;
varying_stencil_options.generateOffsets = stencil_generate_offsets;
- varying_stencil_options.generateIntermediateLevels =
- stencil_generate_intermediate_levels;
- varying_stencil_options.interpolationMode =
- StencilTableFactory::INTERPOLATE_VARYING;
- varying_stencils =
- StencilTableFactory::Create(*refiner, varying_stencil_options);
+ varying_stencil_options.generateIntermediateLevels = stencil_generate_intermediate_levels;
+ varying_stencil_options.interpolationMode = StencilTableFactory::INTERPOLATE_VARYING;
+ varying_stencils = StencilTableFactory::Create(*refiner, varying_stencil_options);
}
// Face warying stencil.
-vector<const StencilTable*> all_face_varying_stencils;
+ vector<const StencilTable *> all_face_varying_stencils;
#ifdef OPENSUBDIV_HAS_FVAR_EVALUATION
all_face_varying_stencils.reserve(num_face_varying_channels);
- for (int face_varying_channel = 0;
- face_varying_channel < num_face_varying_channels;
+ for (int face_varying_channel = 0; face_varying_channel < num_face_varying_channels;
++face_varying_channel) {
StencilTableFactory::Options face_varying_stencil_options;
face_varying_stencil_options.generateOffsets = stencil_generate_offsets;
- face_varying_stencil_options.generateIntermediateLevels =
- stencil_generate_intermediate_levels;
- face_varying_stencil_options.interpolationMode =
- StencilTableFactory::INTERPOLATE_FACE_VARYING;
+ face_varying_stencil_options.generateIntermediateLevels = stencil_generate_intermediate_levels;
+ face_varying_stencil_options.interpolationMode = StencilTableFactory::INTERPOLATE_FACE_VARYING;
face_varying_stencil_options.fvarChannel = face_varying_channel;
all_face_varying_stencils.push_back(
StencilTableFactory::Create(*refiner, face_varying_stencil_options));
@@ -774,42 +779,35 @@ vector<const StencilTable*> all_face_varying_stencils;
patch_options.useInfSharpPatch = use_inf_sharp_patch;
patch_options.generateFVarTables = has_face_varying_data;
patch_options.generateFVarLegacyLinearPatches = false;
- const PatchTable* patch_table = PatchTableFactory::Create(
- *refiner, patch_options);
+ const PatchTable *patch_table = PatchTableFactory::Create(*refiner, patch_options);
// Append local points stencils.
// Point stencils.
- const StencilTable* local_point_stencil_table =
- patch_table->GetLocalPointStencilTable();
+ const StencilTable *local_point_stencil_table = patch_table->GetLocalPointStencilTable();
if (local_point_stencil_table != NULL) {
- const StencilTable* table =
- StencilTableFactory::AppendLocalPointStencilTable(
- *refiner, vertex_stencils, local_point_stencil_table);
+ const StencilTable *table = StencilTableFactory::AppendLocalPointStencilTable(
+ *refiner, vertex_stencils, local_point_stencil_table);
delete vertex_stencils;
vertex_stencils = table;
}
// Varying stencils.
if (has_varying_data) {
- const StencilTable* local_point_varying_stencil_table =
+ const StencilTable *local_point_varying_stencil_table =
patch_table->GetLocalPointVaryingStencilTable();
if (local_point_varying_stencil_table != NULL) {
- const StencilTable* table =
- StencilTableFactory::AppendLocalPointStencilTable(
- *refiner, varying_stencils, local_point_varying_stencil_table);
+ const StencilTable *table = StencilTableFactory::AppendLocalPointStencilTable(
+ *refiner, varying_stencils, local_point_varying_stencil_table);
delete varying_stencils;
varying_stencils = table;
}
}
#ifdef OPENSUBDIV_HAS_FVAR_EVALUATION
- for (int face_varying_channel = 0;
- face_varying_channel < num_face_varying_channels;
+ for (int face_varying_channel = 0; face_varying_channel < num_face_varying_channels;
++face_varying_channel) {
- const StencilTable* table =
- StencilTableFactory::AppendLocalPointStencilTableFaceVarying(
- *refiner,
- all_face_varying_stencils[face_varying_channel],
- patch_table->GetLocalPointFaceVaryingStencilTable(
- face_varying_channel),
- face_varying_channel);
+ const StencilTable *table = StencilTableFactory::AppendLocalPointStencilTableFaceVarying(
+ *refiner,
+ all_face_varying_stencils[face_varying_channel],
+ patch_table->GetLocalPointFaceVaryingStencilTable(face_varying_channel),
+ face_varying_channel);
if (table != NULL) {
delete all_face_varying_stencils[face_varying_channel];
all_face_varying_stencils[face_varying_channel] = table;
@@ -818,30 +816,25 @@ vector<const StencilTable*> all_face_varying_stencils;
#endif
// Create OpenSubdiv's CPU side evaluator.
// TODO(sergey): Make it possible to use different evaluators.
- opensubdiv_capi::CpuEvalOutput* eval_output =
- new opensubdiv_capi::CpuEvalOutput(vertex_stencils,
- varying_stencils,
- all_face_varying_stencils,
- 2,
- patch_table);
- OpenSubdiv::Far::PatchMap* patch_map = new PatchMap(*patch_table);
+ opensubdiv_capi::CpuEvalOutput *eval_output = new opensubdiv_capi::CpuEvalOutput(
+ vertex_stencils, varying_stencils, all_face_varying_stencils, 2, patch_table);
+ OpenSubdiv::Far::PatchMap *patch_map = new PatchMap(*patch_table);
// Wrap everything we need into an object which we control from our side.
- OpenSubdiv_EvaluatorInternal* evaluator_descr;
+ OpenSubdiv_EvaluatorInternal *evaluator_descr;
evaluator_descr = OBJECT_GUARDED_NEW(OpenSubdiv_EvaluatorInternal);
- evaluator_descr->eval_output =
- new opensubdiv_capi::CpuEvalOutputAPI(eval_output, patch_map);
+ evaluator_descr->eval_output = new opensubdiv_capi::CpuEvalOutputAPI(eval_output, patch_map);
evaluator_descr->patch_map = patch_map;
evaluator_descr->patch_table = patch_table;
// TOOD(sergey): Look into whether we've got duplicated stencils arrays.
delete vertex_stencils;
delete varying_stencils;
- foreach (const StencilTable* table, all_face_varying_stencils) {
+ foreach (const StencilTable *table, all_face_varying_stencils) {
delete table;
}
return evaluator_descr;
}
-void openSubdiv_deleteEvaluatorInternal(
- OpenSubdiv_EvaluatorInternal* evaluator) {
+void openSubdiv_deleteEvaluatorInternal(OpenSubdiv_EvaluatorInternal *evaluator)
+{
OBJECT_GUARDED_DELETE(evaluator, OpenSubdiv_EvaluatorInternal);
}
diff --git a/intern/opensubdiv/internal/opensubdiv_evaluator_internal.h b/intern/opensubdiv/internal/opensubdiv_evaluator_internal.h
index 7d9178f38dc..7c963227d17 100644
--- a/intern/opensubdiv/internal/opensubdiv_evaluator_internal.h
+++ b/intern/opensubdiv/internal/opensubdiv_evaluator_internal.h
@@ -42,29 +42,30 @@ class CpuEvalOutput;
class CpuEvalOutputAPI {
public:
// NOTE: API object becomes an owner of evaluator. Patch we are referencing.
- CpuEvalOutputAPI(CpuEvalOutput* implementation,
- OpenSubdiv::Far::PatchMap* patch_map);
+ CpuEvalOutputAPI(CpuEvalOutput *implementation, OpenSubdiv::Far::PatchMap *patch_map);
~CpuEvalOutputAPI();
// Set coarse positions from a continuous array of coordinates.
- void setCoarsePositions(const float* positions,
+ void setCoarsePositions(const float *positions,
const int start_vertex_index,
const int num_vertices);
// Set varying data from a continuous array of data.
- void setVaryingData(const float* varying_data,
- const int start_vertex_index, const int num_vertices);
+ void setVaryingData(const float *varying_data,
+ const int start_vertex_index,
+ const int num_vertices);
// Set face varying data from a continuous array of data.
//
// TODO(sergey): Find a better name for vertex here. It is not the vertex of
// geometry, but a vertex of UV map.
void setFaceVaryingData(const int face_varying_channel,
- const float* varying_data,
- const int start_vertex_index, const int num_vertices);
+ const float *varying_data,
+ const int start_vertex_index,
+ const int num_vertices);
// Set coarse vertex position from a continuous memory buffer where
// first coordinate starts at offset of `start_offset` and there is `stride`
// bytes between adjacent vertex coordinates.
- void setCoarsePositionsFromBuffer(const void* buffer,
+ void setCoarsePositionsFromBuffer(const void *buffer,
const int start_offset,
const int stride,
const int start_vertex_index,
@@ -72,7 +73,7 @@ class CpuEvalOutputAPI {
// Set varying data from a continuous memory buffer where
// first coordinate starts at offset of `start_offset` and there is `stride`
// bytes between adjacent vertex coordinates.
- void setVaryingDataFromBuffer(const void* buffer,
+ void setVaryingDataFromBuffer(const void *buffer,
const int start_offset,
const int stride,
const int start_vertex_index,
@@ -84,7 +85,7 @@ class CpuEvalOutputAPI {
// TODO(sergey): Find a better name for vertex here. It is not the vertex of
// geometry, but a vertex of UV map.
void setFaceVaryingDataFromBuffer(const int face_varying_channel,
- const void* buffer,
+ const void *buffer,
const int start_offset,
const int stride,
const int start_vertex_index,
@@ -96,24 +97,26 @@ class CpuEvalOutputAPI {
// Evaluate given ptex face at given bilinear coordinate.
// If derivatives are NULL, they will not be evaluated.
void evaluateLimit(const int ptex_face_index,
- float face_u, float face_v,
- float P[3], float dPdu[3], float dPdv[3]);
+ float face_u,
+ float face_v,
+ float P[3],
+ float dPdu[3],
+ float dPdv[3]);
// Evaluate varying data at a given bilinear coordinate of given ptex face.
- void evaluateVarying(const int ptes_face_index,
- float face_u, float face_v,
- float varying[3]);
+ void evaluateVarying(const int ptes_face_index, float face_u, float face_v, float varying[3]);
// Evaluate facee-varying data at a given bilinear coordinate of given
// ptex face.
void evaluateFaceVarying(const int face_varying_channel,
const int ptes_face_index,
- float face_u, float face_v,
+ float face_u,
+ float face_v,
float face_varying[2]);
protected:
- CpuEvalOutput* implementation_;
- OpenSubdiv::Far::PatchMap* patch_map_;
+ CpuEvalOutput *implementation_;
+ OpenSubdiv::Far::PatchMap *patch_map_;
};
} // namespace opensubdiv_capi
@@ -123,15 +126,14 @@ struct OpenSubdiv_EvaluatorInternal {
OpenSubdiv_EvaluatorInternal();
~OpenSubdiv_EvaluatorInternal();
- opensubdiv_capi::CpuEvalOutputAPI* eval_output;
- const OpenSubdiv::Far::PatchMap* patch_map;
- const OpenSubdiv::Far::PatchTable* patch_table;
+ opensubdiv_capi::CpuEvalOutputAPI *eval_output;
+ const OpenSubdiv::Far::PatchMap *patch_map;
+ const OpenSubdiv::Far::PatchTable *patch_table;
};
-OpenSubdiv_EvaluatorInternal* openSubdiv_createEvaluatorInternal(
- struct OpenSubdiv_TopologyRefiner* topology_refiner);
+OpenSubdiv_EvaluatorInternal *openSubdiv_createEvaluatorInternal(
+ struct OpenSubdiv_TopologyRefiner *topology_refiner);
-void openSubdiv_deleteEvaluatorInternal(
- OpenSubdiv_EvaluatorInternal* evaluator);
+void openSubdiv_deleteEvaluatorInternal(OpenSubdiv_EvaluatorInternal *evaluator);
#endif // OPENSUBDIV_EVALUATOR_INTERNAL_H_
diff --git a/intern/opensubdiv/internal/opensubdiv_gl_mesh.cc b/intern/opensubdiv/internal/opensubdiv_gl_mesh.cc
index 469480e0fcd..0e4d9ce0a83 100644
--- a/intern/opensubdiv/internal/opensubdiv_gl_mesh.cc
+++ b/intern/opensubdiv/internal/opensubdiv_gl_mesh.cc
@@ -33,20 +33,14 @@ using OpenSubdiv::Osd::MeshBitset;
// CPU backend.
#include <opensubdiv/osd/cpuEvaluator.h>
#include <opensubdiv/osd/cpuGLVertexBuffer.h>
-using OpenSubdiv::Osd::CpuGLVertexBuffer;
using OpenSubdiv::Osd::CpuEvaluator;
-typedef Mesh<CpuGLVertexBuffer,
- StencilTable,
- CpuEvaluator,
- GLPatchTable> OsdCpuMesh;
+using OpenSubdiv::Osd::CpuGLVertexBuffer;
+typedef Mesh<CpuGLVertexBuffer, StencilTable, CpuEvaluator, GLPatchTable> OsdCpuMesh;
// OpenMP backend.
#ifdef OPENSUBDIV_HAS_OPENMP
# include <opensubdiv/osd/ompEvaluator.h>
using OpenSubdiv::Osd::OmpEvaluator;
-typedef Mesh<CpuGLVertexBuffer,
- StencilTable,
- OmpEvaluator,
- GLPatchTable> OsdOmpMesh;
+typedef Mesh<CpuGLVertexBuffer, StencilTable, OmpEvaluator, GLPatchTable> OsdOmpMesh;
#endif
// OpenCL backend.
#ifdef OPENSUBDIV_HAS_OPENCL
@@ -57,11 +51,8 @@ using OpenSubdiv::Osd::CLEvaluator;
using OpenSubdiv::Osd::CLGLVertexBuffer;
using OpenSubdiv::Osd::CLStencilTable;
/* TODO(sergey): Use CLDeviceContext similar to OSD examples? */
-typedef Mesh<CLGLVertexBuffer,
- CLStencilTable,
- CLEvaluator,
- GLPatchTable,
- CLDeviceContext> OsdCLMesh;
+typedef Mesh<CLGLVertexBuffer, CLStencilTable, CLEvaluator, GLPatchTable, CLDeviceContext>
+ OsdCLMesh;
static CLDeviceContext g_cl_device_context;
#endif
// CUDA backend.
@@ -72,23 +63,18 @@ static CLDeviceContext g_cl_device_context;
using OpenSubdiv::Osd::CudaEvaluator;
using OpenSubdiv::Osd::CudaGLVertexBuffer;
using OpenSubdiv::Osd::CudaStencilTable;
-typedef Mesh<CudaGLVertexBuffer,
- CudaStencilTable,
- CudaEvaluator,
- GLPatchTable> OsdCudaMesh;
+typedef Mesh<CudaGLVertexBuffer, CudaStencilTable, CudaEvaluator, GLPatchTable> OsdCudaMesh;
static CudaDeviceContext g_cuda_device_context;
#endif
// Transform feedback backend.
#ifdef OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK
# include <opensubdiv/osd/glVertexBuffer.h>
# include <opensubdiv/osd/glXFBEvaluator.h>
-using OpenSubdiv::Osd::GLXFBEvaluator;
using OpenSubdiv::Osd::GLStencilTableTBO;
using OpenSubdiv::Osd::GLVertexBuffer;
-typedef Mesh<GLVertexBuffer,
- GLStencilTableTBO,
- GLXFBEvaluator,
- GLPatchTable> OsdGLSLTransformFeedbackMesh;
+using OpenSubdiv::Osd::GLXFBEvaluator;
+typedef Mesh<GLVertexBuffer, GLStencilTableTBO, GLXFBEvaluator, GLPatchTable>
+ OsdGLSLTransformFeedbackMesh;
#endif
// GLSL compute backend.
#ifdef OPENSUBDIV_HAS_GLSL_COMPUTE
@@ -97,10 +83,8 @@ typedef Mesh<GLVertexBuffer,
using OpenSubdiv::Osd::GLComputeEvaluator;
using OpenSubdiv::Osd::GLStencilTableSSBO;
using OpenSubdiv::Osd::GLVertexBuffer;
-typedef Mesh<GLVertexBuffer,
- GLStencilTableSSBO,
- GLComputeEvaluator,
- GLPatchTable> OsdGLSLComputeMesh;
+typedef Mesh<GLVertexBuffer, GLStencilTableSSBO, GLComputeEvaluator, GLPatchTable>
+ OsdGLSLComputeMesh;
#endif
#include "MEM_guardedalloc.h"
@@ -116,27 +100,23 @@ using opensubdiv_capi::vector;
namespace {
-GLMeshInterface* createGLMeshInterface(
- OpenSubdiv::Far::TopologyRefiner* topology_refiner,
- const MeshBitset& bits,
- const int num_vertex_elements,
- const int num_varying_elements,
- const int level,
- eOpenSubdivEvaluator evaluator_type) {
- GLMeshInterface* mesh = NULL;
+GLMeshInterface *createGLMeshInterface(OpenSubdiv::Far::TopologyRefiner *topology_refiner,
+ const MeshBitset &bits,
+ const int num_vertex_elements,
+ const int num_varying_elements,
+ const int level,
+ eOpenSubdivEvaluator evaluator_type)
+{
+ GLMeshInterface *mesh = NULL;
switch (evaluator_type) {
-#define CHECK_EVALUATOR_TYPE(type, class) \
- case OPENSUBDIV_EVALUATOR_##type: \
- mesh = new class(topology_refiner, \
- num_vertex_elements, \
- num_varying_elements, \
- level, \
- bits); \
+#define CHECK_EVALUATOR_TYPE(type, class) \
+ case OPENSUBDIV_EVALUATOR_##type: \
+ mesh = new class(topology_refiner, num_vertex_elements, num_varying_elements, level, bits); \
break;
-#define CHECK_EVALUATOR_TYPE_STUB(type) \
- case OPENSUBDIV_EVALUATOR_##type: \
- mesh = NULL; \
+#define CHECK_EVALUATOR_TYPE_STUB(type) \
+ case OPENSUBDIV_EVALUATOR_##type: \
+ mesh = NULL; \
break;
CHECK_EVALUATOR_TYPE(CPU, OsdCpuMesh)
@@ -175,47 +155,46 @@ GLMeshInterface* createGLMeshInterface(
////////////////////////////////////////////////////////////////////////////////
// GLMesh structure "methods".
-opensubdiv_capi::GLMeshFVarData* createFVarData(
- OpenSubdiv::Far::TopologyRefiner* topology_refiner,
- GLMeshInterface* mesh,
- const float *fvar_src_buffer) {
+opensubdiv_capi::GLMeshFVarData *createFVarData(OpenSubdiv::Far::TopologyRefiner *topology_refiner,
+ GLMeshInterface *mesh,
+ const float *fvar_src_buffer)
+{
using opensubdiv_capi::GLMeshFVarData;
- GLMeshFVarData* fvar_data = new GLMeshFVarData();
- fvar_data->create(topology_refiner,
- mesh->GetFarPatchTable(),
- 2,
- fvar_src_buffer);
+ GLMeshFVarData *fvar_data = new GLMeshFVarData();
+ fvar_data->create(topology_refiner, mesh->GetFarPatchTable(), 2, fvar_src_buffer);
return fvar_data;
}
-unsigned int getPatchIndexBuffer(OpenSubdiv_GLMesh* gl_mesh) {
- return gl_mesh->internal->mesh_interface
- ->GetPatchTable()
- ->GetPatchIndexBuffer();
+unsigned int getPatchIndexBuffer(OpenSubdiv_GLMesh *gl_mesh)
+{
+ return gl_mesh->internal->mesh_interface->GetPatchTable()->GetPatchIndexBuffer();
}
-void bindVertexBuffer(OpenSubdiv_GLMesh* gl_mesh) {
+void bindVertexBuffer(OpenSubdiv_GLMesh *gl_mesh)
+{
gl_mesh->internal->mesh_interface->BindVertexBuffer();
}
-void setCoarsePositions(OpenSubdiv_GLMesh* gl_mesh,
- const float* positions,
+void setCoarsePositions(OpenSubdiv_GLMesh *gl_mesh,
+ const float *positions,
const int start_vertex,
- const int num_vertices) {
- gl_mesh->internal->mesh_interface->UpdateVertexBuffer(positions,
- start_vertex,
- num_vertices);
+ const int num_vertices)
+{
+ gl_mesh->internal->mesh_interface->UpdateVertexBuffer(positions, start_vertex, num_vertices);
}
-void refine(OpenSubdiv_GLMesh* gl_mesh) {
+void refine(OpenSubdiv_GLMesh *gl_mesh)
+{
gl_mesh->internal->mesh_interface->Refine();
}
-void synchronize(struct OpenSubdiv_GLMesh* gl_mesh) {
+void synchronize(struct OpenSubdiv_GLMesh *gl_mesh)
+{
gl_mesh->internal->mesh_interface->Synchronize();
}
-void assignFunctionPointers(OpenSubdiv_GLMesh* gl_mesh) {
+void assignFunctionPointers(OpenSubdiv_GLMesh *gl_mesh)
+{
gl_mesh->getPatchIndexBuffer = getPatchIndexBuffer;
gl_mesh->bindVertexBuffer = bindVertexBuffer;
gl_mesh->setCoarsePositions = setCoarsePositions;
@@ -229,11 +208,10 @@ void assignFunctionPointers(OpenSubdiv_GLMesh* gl_mesh) {
} // namespace
struct OpenSubdiv_GLMesh *openSubdiv_createOsdGLMeshFromTopologyRefiner(
- OpenSubdiv_TopologyRefiner* topology_refiner,
- eOpenSubdivEvaluator evaluator_type) {
+ OpenSubdiv_TopologyRefiner *topology_refiner, eOpenSubdivEvaluator evaluator_type)
+{
using OpenSubdiv::Far::TopologyRefiner;
- TopologyRefiner* osd_topology_refiner =
- topology_refiner->internal->osd_topology_refiner;
+ TopologyRefiner *osd_topology_refiner = topology_refiner->internal->osd_topology_refiner;
// TODO(sergey): Query this from refiner.
const bool is_adaptive = false;
MeshBitset bits;
@@ -244,17 +222,16 @@ struct OpenSubdiv_GLMesh *openSubdiv_createOsdGLMeshFromTopologyRefiner(
bits.set(OpenSubdiv::Osd::MeshEndCapBSplineBasis, 1);
const int num_vertex_elements = 3;
const int num_varying_elements = 3;
- GLMeshInterface* mesh = createGLMeshInterface(
- osd_topology_refiner,
- bits,
- num_vertex_elements,
- num_varying_elements,
- osd_topology_refiner->GetMaxLevel(),
- evaluator_type);
+ GLMeshInterface *mesh = createGLMeshInterface(osd_topology_refiner,
+ bits,
+ num_vertex_elements,
+ num_varying_elements,
+ osd_topology_refiner->GetMaxLevel(),
+ evaluator_type);
if (mesh == NULL) {
return NULL;
}
- OpenSubdiv_GLMesh* gl_mesh = OBJECT_GUARDED_NEW(OpenSubdiv_GLMesh);
+ OpenSubdiv_GLMesh *gl_mesh = OBJECT_GUARDED_NEW(OpenSubdiv_GLMesh);
assignFunctionPointers(gl_mesh);
gl_mesh->internal = new OpenSubdiv_GLMeshInternal();
gl_mesh->internal->evaluator_type = evaluator_type;
@@ -266,19 +243,18 @@ struct OpenSubdiv_GLMesh *openSubdiv_createOsdGLMeshFromTopologyRefiner(
// to store base level UVs somewhere else.
vector<float> uvs;
vector<float> fvar_data_buffer;
- opensubdiv_capi::interpolateFVarData(*osd_topology_refiner,
- uvs,
- &fvar_data_buffer);
- gl_mesh->internal->fvar_data = createFVarData(osd_topology_refiner,
- mesh,
- &fvar_data_buffer[0]);
- } else {
+ opensubdiv_capi::interpolateFVarData(*osd_topology_refiner, uvs, &fvar_data_buffer);
+ gl_mesh->internal->fvar_data = createFVarData(
+ osd_topology_refiner, mesh, &fvar_data_buffer[0]);
+ }
+ else {
gl_mesh->internal->fvar_data = NULL;
}
return gl_mesh;
}
-void openSubdiv_deleteOsdGLMesh(OpenSubdiv_GLMesh* gl_mesh) {
+void openSubdiv_deleteOsdGLMesh(OpenSubdiv_GLMesh *gl_mesh)
+{
delete gl_mesh->internal;
OBJECT_GUARDED_DELETE(gl_mesh, OpenSubdiv_GLMesh);
}
diff --git a/intern/opensubdiv/internal/opensubdiv_gl_mesh_draw.cc b/intern/opensubdiv/internal/opensubdiv_gl_mesh_draw.cc
index c1efc439b2e..cbccf69e02d 100644
--- a/intern/opensubdiv/internal/opensubdiv_gl_mesh_draw.cc
+++ b/intern/opensubdiv/internal/opensubdiv_gl_mesh_draw.cc
@@ -111,11 +111,13 @@ static Transform g_transform;
namespace {
GLuint compileShader(GLenum shaderType,
- const char* version,
- const char* define,
- const char* source) {
- const char* sources[] = {
- version, define,
+ const char *version,
+ const char *define,
+ const char *source)
+{
+ const char *sources[] = {
+ version,
+ define,
#ifdef SUPPORT_COLOR_MATERIAL
"#define SUPPORT_COLOR_MATERIAL\n",
#else
@@ -143,22 +145,20 @@ GLuint compileShader(GLenum shaderType,
return shader;
}
-GLuint linkProgram(const char* version, const char* define) {
- GLuint vertexShader =
- compileShader(GL_VERTEX_SHADER, version, define,
- datatoc_gpu_shader_opensubdiv_vertex_glsl);
+GLuint linkProgram(const char *version, const char *define)
+{
+ GLuint vertexShader = compileShader(
+ GL_VERTEX_SHADER, version, define, datatoc_gpu_shader_opensubdiv_vertex_glsl);
if (vertexShader == 0) {
return 0;
}
- GLuint geometryShader =
- compileShader(GL_GEOMETRY_SHADER, version, define,
- datatoc_gpu_shader_opensubdiv_geometry_glsl);
+ GLuint geometryShader = compileShader(
+ GL_GEOMETRY_SHADER, version, define, datatoc_gpu_shader_opensubdiv_geometry_glsl);
if (geometryShader == 0) {
return 0;
}
- GLuint fragmentShader =
- compileShader(GL_FRAGMENT_SHADER, version, define,
- datatoc_gpu_shader_opensubdiv_fragment_glsl);
+ GLuint fragmentShader = compileShader(
+ GL_FRAGMENT_SHADER, version, define, datatoc_gpu_shader_opensubdiv_fragment_glsl);
if (fragmentShader == 0) {
return 0;
}
@@ -189,17 +189,14 @@ GLuint linkProgram(const char* version, const char* define) {
return 0;
}
- glUniformBlockBinding(program, glGetUniformBlockIndex(program, "Lighting"),
- 0);
+ glUniformBlockBinding(program, glGetUniformBlockIndex(program, "Lighting"), 0);
if (GLEW_VERSION_4_1) {
- glProgramUniform1i(
- program, glGetUniformLocation(program, "texture_buffer"), 0);
- glProgramUniform1i(
- program, glGetUniformLocation(program, "FVarDataOffsetBuffer"), 30);
- glProgramUniform1i(
- program, glGetUniformLocation(program, "FVarDataBuffer"), 31);
- } else {
+ glProgramUniform1i(program, glGetUniformLocation(program, "texture_buffer"), 0);
+ glProgramUniform1i(program, glGetUniformLocation(program, "FVarDataOffsetBuffer"), 30);
+ glProgramUniform1i(program, glGetUniformLocation(program, "FVarDataBuffer"), 31);
+ }
+ else {
glUseProgram(program);
glUniform1i(glGetUniformLocation(program, "texture_buffer"), 0);
glUniform1i(glGetUniformLocation(program, "FVarDataOffsetBuffer"), 30);
@@ -210,25 +207,19 @@ GLuint linkProgram(const char* version, const char* define) {
return program;
}
-void bindProgram(OpenSubdiv_GLMesh* gl_mesh, int program) {
+void bindProgram(OpenSubdiv_GLMesh *gl_mesh, int program)
+{
glUseProgram(program);
// Matrices
- glUniformMatrix4fv(glGetUniformLocation(program, "modelViewMatrix"),
- 1,
- false,
- g_transform.model_view_matrix);
- glUniformMatrix4fv(glGetUniformLocation(program, "projectionMatrix"),
- 1,
- false,
- g_transform.projection_matrix);
- glUniformMatrix3fv(glGetUniformLocation(program, "normalMatrix"),
- 1,
- false,
- g_transform.normal_matrix);
+ glUniformMatrix4fv(
+ glGetUniformLocation(program, "modelViewMatrix"), 1, false, g_transform.model_view_matrix);
+ glUniformMatrix4fv(
+ glGetUniformLocation(program, "projectionMatrix"), 1, false, g_transform.projection_matrix);
+ glUniformMatrix3fv(
+ glGetUniformLocation(program, "normalMatrix"), 1, false, g_transform.normal_matrix);
// Lighting.
glBindBuffer(GL_UNIFORM_BUFFER, g_lighting_ub);
- glBufferSubData(
- GL_UNIFORM_BUFFER, 0, sizeof(g_lighting_data), &g_lighting_data);
+ glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(g_lighting_data), &g_lighting_data);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
glBindBufferBase(GL_UNIFORM_BUFFER, 0, g_lighting_ub);
// Color.
@@ -243,7 +234,7 @@ void bindProgram(OpenSubdiv_GLMesh* gl_mesh, int program) {
glUniform1f(glGetUniformLocation(program, "shininess"), color[0]);
}
// Face-vertex data.
- opensubdiv_capi::GLMeshFVarData* fvar_data = gl_mesh->internal->fvar_data;
+ opensubdiv_capi::GLMeshFVarData *fvar_data = gl_mesh->internal->fvar_data;
if (fvar_data != NULL) {
if (fvar_data->texture_buffer) {
glActiveTexture(GL_TEXTURE31);
@@ -255,15 +246,16 @@ void bindProgram(OpenSubdiv_GLMesh* gl_mesh, int program) {
glBindTexture(GL_TEXTURE_BUFFER, fvar_data->offset_buffer);
glActiveTexture(GL_TEXTURE0);
}
- glUniform1i(glGetUniformLocation(program, "osd_fvar_count"),
- fvar_data->fvar_width);
+ glUniform1i(glGetUniformLocation(program, "osd_fvar_count"), fvar_data->fvar_width);
if (fvar_data->channel_offsets.size() > 0 && g_active_uv_index >= 0) {
glUniform1i(glGetUniformLocation(program, "osd_active_uv_offset"),
fvar_data->channel_offsets[g_active_uv_index]);
- } else {
+ }
+ else {
glUniform1i(glGetUniformLocation(program, "osd_active_uv_offset"), 0);
}
- } else {
+ }
+ else {
glUniform1i(glGetUniformLocation(program, "osd_fvar_count"), 0);
glUniform1i(glGetUniformLocation(program, "osd_active_uv_offset"), 0);
}
@@ -271,7 +263,8 @@ void bindProgram(OpenSubdiv_GLMesh* gl_mesh, int program) {
} // namespace
-bool openSubdiv_initGLMeshDrawingResources(void) {
+bool openSubdiv_initGLMeshDrawingResources(void)
+{
static bool need_init = true;
static bool init_success = false;
if (!need_init) {
@@ -280,16 +273,19 @@ bool openSubdiv_initGLMeshDrawingResources(void) {
// TODO(sergey): Update OSD drawing to OpenGL 3.3 core,
// then remove following line.
return false;
- const char* version = "";
+ const char *version = "";
if (GLEW_VERSION_3_2) {
version = "#version 150 compatibility\n";
- } else if (GLEW_VERSION_3_1) {
- version = "#version 140\n"
- "#extension GL_ARB_compatibility: enable\n";
- } else {
+ }
+ else if (GLEW_VERSION_3_1) {
+ version =
+ "#version 140\n"
+ "#extension GL_ARB_compatibility: enable\n";
+ }
+ else {
version = "#version 130\n";
// Minimum supported for OpenSubdiv.
- }
+ }
g_flat_fill_solid_program = linkProgram(version,
"#define USE_COLOR_MATERIAL\n"
"#define USE_LIGHTING\n"
@@ -309,49 +305,42 @@ bool openSubdiv_initGLMeshDrawingResources(void) {
"#define USE_TEXTURE_2D\n"
"#define SMOOTH_SHADING\n");
- g_flat_fill_solid_shadeless_program =
- linkProgram(version,
- "#define USE_COLOR_MATERIAL\n"
- "#define FLAT_SHADING\n");
- g_flat_fill_texture2d_shadeless_program =
- linkProgram(version,
- "#define USE_COLOR_MATERIAL\n"
- "#define USE_TEXTURE_2D\n"
- "#define FLAT_SHADING\n");
- g_smooth_fill_solid_shadeless_program =
- linkProgram(version,
- "#define USE_COLOR_MATERIAL\n"
- "#define SMOOTH_SHADING\n");
- g_smooth_fill_texture2d_shadeless_program =
- linkProgram(version,
- "#define USE_COLOR_MATERIAL\n"
- "#define USE_TEXTURE_2D\n"
- "#define SMOOTH_SHADING\n");
+ g_flat_fill_solid_shadeless_program = linkProgram(version,
+ "#define USE_COLOR_MATERIAL\n"
+ "#define FLAT_SHADING\n");
+ g_flat_fill_texture2d_shadeless_program = linkProgram(version,
+ "#define USE_COLOR_MATERIAL\n"
+ "#define USE_TEXTURE_2D\n"
+ "#define FLAT_SHADING\n");
+ g_smooth_fill_solid_shadeless_program = linkProgram(version,
+ "#define USE_COLOR_MATERIAL\n"
+ "#define SMOOTH_SHADING\n");
+ g_smooth_fill_texture2d_shadeless_program = linkProgram(version,
+ "#define USE_COLOR_MATERIAL\n"
+ "#define USE_TEXTURE_2D\n"
+ "#define SMOOTH_SHADING\n");
g_wireframe_program = linkProgram(version, "#define WIREFRAME\n");
glGenBuffers(1, &g_lighting_ub);
glBindBuffer(GL_UNIFORM_BUFFER, g_lighting_ub);
- glBufferData(GL_UNIFORM_BUFFER,
- sizeof(g_lighting_data),
- NULL,
- GL_STATIC_DRAW);
+ glBufferData(GL_UNIFORM_BUFFER, sizeof(g_lighting_data), NULL, GL_STATIC_DRAW);
need_init = false;
- init_success = g_flat_fill_solid_program != 0 &&
- g_flat_fill_texture2d_program != 0 &&
- g_smooth_fill_solid_program != 0 &&
- g_smooth_fill_texture2d_program != 0 && g_wireframe_program;
+ init_success = g_flat_fill_solid_program != 0 && g_flat_fill_texture2d_program != 0 &&
+ g_smooth_fill_solid_program != 0 && g_smooth_fill_texture2d_program != 0 &&
+ g_wireframe_program;
return init_success;
}
-void openSubdiv_deinitGLMeshDrawingResources(void) {
+void openSubdiv_deinitGLMeshDrawingResources(void)
+{
if (g_lighting_ub != 0) {
glDeleteBuffers(1, &g_lighting_ub);
}
-#define SAFE_DELETE_PROGRAM(program) \
- do { \
- if (program) { \
- glDeleteProgram(program); \
- } \
+#define SAFE_DELETE_PROGRAM(program) \
+ do { \
+ if (program) { \
+ glDeleteProgram(program); \
+ } \
} while (false)
SAFE_DELETE_PROGRAM(g_flat_fill_solid_program);
@@ -371,7 +360,8 @@ namespace opensubdiv_capi {
namespace {
-GLuint prepare_patchDraw(OpenSubdiv_GLMesh* gl_mesh, bool fill_quads) {
+GLuint prepare_patchDraw(OpenSubdiv_GLMesh *gl_mesh, bool fill_quads)
+{
GLint program = 0;
if (!g_use_osd_glsl) {
glGetIntegerv(GL_CURRENT_PROGRAM, &program);
@@ -383,7 +373,7 @@ GLuint prepare_patchDraw(OpenSubdiv_GLMesh* gl_mesh, bool fill_quads) {
glUniform1i(location, model == GL_FLAT);
}
// Face-vertex data.
- opensubdiv_capi::GLMeshFVarData* fvar_data = gl_mesh->internal->fvar_data;
+ opensubdiv_capi::GLMeshFVarData *fvar_data = gl_mesh->internal->fvar_data;
if (fvar_data != NULL) {
if (fvar_data->texture_buffer) {
glActiveTexture(GL_TEXTURE31);
@@ -402,13 +392,14 @@ GLuint prepare_patchDraw(OpenSubdiv_GLMesh* gl_mesh, bool fill_quads) {
location = glGetUniformLocation(program, "osd_active_uv_offset");
if (location != -1) {
if (fvar_data->channel_offsets.size() > 0 && g_active_uv_index >= 0) {
- glUniform1i(location,
- fvar_data->channel_offsets[g_active_uv_index]);
- } else {
+ glUniform1i(location, fvar_data->channel_offsets[g_active_uv_index]);
+ }
+ else {
glUniform1i(location, 0);
}
}
- } else {
+ }
+ else {
glUniform1i(glGetUniformLocation(program, "osd_fvar_count"), 0);
glUniform1i(glGetUniformLocation(program, "osd_active_uv_offset"), 0);
}
@@ -423,18 +414,21 @@ GLuint prepare_patchDraw(OpenSubdiv_GLMesh* gl_mesh, bool fill_quads) {
if (model == GL_FLAT) {
if (use_texture_2d) {
program = g_flat_fill_texture2d_program;
- } else {
+ }
+ else {
program = g_flat_fill_solid_program;
}
- } else {
+ }
+ else {
if (use_texture_2d) {
program = g_smooth_fill_texture2d_program;
- } else {
+ }
+ else {
program = g_smooth_fill_solid_program;
}
}
-
- } else {
+ }
+ else {
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
program = g_wireframe_program;
}
@@ -442,20 +436,19 @@ GLuint prepare_patchDraw(OpenSubdiv_GLMesh* gl_mesh, bool fill_quads) {
return program;
}
-void perform_drawElements(GLuint program,
- int patch_index,
- int num_elements,
- int start_element) {
+void perform_drawElements(GLuint program, int patch_index, int num_elements, int start_element)
+{
if (program) {
glUniform1i(glGetUniformLocation(program, "PrimitiveIdBase"), patch_index);
}
glDrawElements(GL_LINES_ADJACENCY,
num_elements,
GL_UNSIGNED_INT,
- reinterpret_cast<void*>(start_element * sizeof(unsigned int)));
+ reinterpret_cast<void *>(start_element * sizeof(unsigned int)));
}
-void finishPatchDraw(bool fill_quads) {
+void finishPatchDraw(bool fill_quads)
+{
// TODO(sergey): Some of the stuff could be done once after the whole
// mesh is displayed.
/// Restore state.
@@ -469,13 +462,13 @@ void finishPatchDraw(bool fill_quads) {
}
}
-void drawPartitionPatchesRange(GLMeshInterface* mesh,
+void drawPartitionPatchesRange(GLMeshInterface *mesh,
GLuint program,
int start_patch,
- int num_patches) {
+ int num_patches)
+{
int traversed_patches = 0, num_remained_patches = num_patches;
- const OpenSubdiv::Osd::PatchArrayVector &patches =
- mesh->GetPatchTable()->GetPatchArrays();
+ const OpenSubdiv::Osd::PatchArrayVector &patches = mesh->GetPatchTable()->GetPatchArrays();
for (int i = 0; i < patches.size(); ++i) {
const OpenSubdiv::Osd::PatchArray &patch = patches[i];
OpenSubdiv::Far::PatchDescriptor desc = patch.GetDescriptor();
@@ -486,11 +479,12 @@ void drawPartitionPatchesRange(GLMeshInterface* mesh,
start_patch < traversed_patches + num_block_patches) {
const int num_control_verts = desc.GetNumControlVertices();
const int start_draw_patch = start_patch - traversed_patches;
- const int num_draw_patches = min(
- num_remained_patches, num_block_patches - start_draw_patch);
- perform_drawElements(
- program, i + start_draw_patch, num_draw_patches * num_control_verts,
- patch.GetIndexBase() + start_draw_patch * num_control_verts);
+ const int num_draw_patches = min(num_remained_patches,
+ num_block_patches - start_draw_patch);
+ perform_drawElements(program,
+ i + start_draw_patch,
+ num_draw_patches * num_control_verts,
+ patch.GetIndexBase() + start_draw_patch * num_control_verts);
num_remained_patches -= num_draw_patches;
}
if (num_remained_patches == 0) {
@@ -501,34 +495,33 @@ void drawPartitionPatchesRange(GLMeshInterface* mesh,
}
}
-static void drawAllPatches(GLMeshInterface* mesh, GLuint program) {
- const OpenSubdiv::Osd::PatchArrayVector &patches =
- mesh->GetPatchTable()->GetPatchArrays();
+static void drawAllPatches(GLMeshInterface *mesh, GLuint program)
+{
+ const OpenSubdiv::Osd::PatchArrayVector &patches = mesh->GetPatchTable()->GetPatchArrays();
for (int i = 0; i < patches.size(); ++i) {
const OpenSubdiv::Osd::PatchArray &patch = patches[i];
OpenSubdiv::Far::PatchDescriptor desc = patch.GetDescriptor();
OpenSubdiv::Far::PatchDescriptor::Type patchType = desc.GetType();
if (patchType == OpenSubdiv::Far::PatchDescriptor::QUADS) {
- perform_drawElements(program, i,
- patch.GetNumPatches() * desc.GetNumControlVertices(),
- patch.GetIndexBase());
+ perform_drawElements(
+ program, i, patch.GetNumPatches() * desc.GetNumControlVertices(), patch.GetIndexBase());
}
}
}
} // namespace
-void GLMeshDisplayPrepare(struct OpenSubdiv_GLMesh* /*gl_mesh*/,
+void GLMeshDisplayPrepare(struct OpenSubdiv_GLMesh * /*gl_mesh*/,
const bool use_osd_glsl,
- const int active_uv_index) {
+ const int active_uv_index)
+{
g_active_uv_index = active_uv_index;
g_use_osd_glsl = (use_osd_glsl != 0);
// Update transformation matrices.
glGetFloatv(GL_PROJECTION_MATRIX, g_transform.projection_matrix);
glGetFloatv(GL_MODELVIEW_MATRIX, g_transform.model_view_matrix);
- copy_m3_m4((float(*)[3])g_transform.normal_matrix,
- (float(*)[4])g_transform.model_view_matrix);
+ copy_m3_m4((float(*)[3])g_transform.normal_matrix, (float(*)[4])g_transform.model_view_matrix);
invert_m3((float(*)[3])g_transform.normal_matrix);
transpose_m3((float(*)[3])g_transform.normal_matrix);
// Update OpenGL lights positions, colors etc.
@@ -540,36 +533,31 @@ void GLMeshDisplayPrepare(struct OpenSubdiv_GLMesh* /*gl_mesh*/,
g_lighting_data.num_enabled++;
}
// TODO(sergey): Stop using glGetLight.
- glGetLightfv(GL_LIGHT0 + i, GL_POSITION,
- g_lighting_data.lights[i].position);
+ glGetLightfv(GL_LIGHT0 + i, GL_POSITION, g_lighting_data.lights[i].position);
glGetLightfv(GL_LIGHT0 + i, GL_AMBIENT, g_lighting_data.lights[i].ambient);
glGetLightfv(GL_LIGHT0 + i, GL_DIFFUSE, g_lighting_data.lights[i].diffuse);
- glGetLightfv(GL_LIGHT0 + i, GL_SPECULAR,
- g_lighting_data.lights[i].specular);
- glGetLightfv(GL_LIGHT0 + i, GL_SPOT_DIRECTION,
- g_lighting_data.lights[i].spot_direction);
+ glGetLightfv(GL_LIGHT0 + i, GL_SPECULAR, g_lighting_data.lights[i].specular);
+ glGetLightfv(GL_LIGHT0 + i, GL_SPOT_DIRECTION, g_lighting_data.lights[i].spot_direction);
#ifdef SUPPORT_COLOR_MATERIAL
- glGetLightfv(GL_LIGHT0 + i, GL_CONSTANT_ATTENUATION,
- &g_lighting_data.lights[i].constant_attenuation);
- glGetLightfv(GL_LIGHT0 + i, GL_LINEAR_ATTENUATION,
- &g_lighting_data.lights[i].linear_attenuation);
- glGetLightfv(GL_LIGHT0 + i, GL_QUADRATIC_ATTENUATION,
- &g_lighting_data.lights[i].quadratic_attenuation);
- glGetLightfv(GL_LIGHT0 + i, GL_SPOT_CUTOFF,
- &g_lighting_data.lights[i].spot_cutoff);
- glGetLightfv(GL_LIGHT0 + i, GL_SPOT_EXPONENT,
- &g_lighting_data.lights[i].spot_exponent);
- g_lighting_data.lights[i].spot_cos_cutoff =
- cos(g_lighting_data.lights[i].spot_cutoff);
+ glGetLightfv(
+ GL_LIGHT0 + i, GL_CONSTANT_ATTENUATION, &g_lighting_data.lights[i].constant_attenuation);
+ glGetLightfv(
+ GL_LIGHT0 + i, GL_LINEAR_ATTENUATION, &g_lighting_data.lights[i].linear_attenuation);
+ glGetLightfv(
+ GL_LIGHT0 + i, GL_QUADRATIC_ATTENUATION, &g_lighting_data.lights[i].quadratic_attenuation);
+ glGetLightfv(GL_LIGHT0 + i, GL_SPOT_CUTOFF, &g_lighting_data.lights[i].spot_cutoff);
+ glGetLightfv(GL_LIGHT0 + i, GL_SPOT_EXPONENT, &g_lighting_data.lights[i].spot_exponent);
+ g_lighting_data.lights[i].spot_cos_cutoff = cos(g_lighting_data.lights[i].spot_cutoff);
#endif
}
}
-void GLMeshDisplayDrawPatches(OpenSubdiv_GLMesh* gl_mesh,
+void GLMeshDisplayDrawPatches(OpenSubdiv_GLMesh *gl_mesh,
const bool fill_quads,
const int start_patch,
- const int num_patches) {
- GLMeshInterface* mesh = gl_mesh->internal->mesh_interface;
+ const int num_patches)
+{
+ GLMeshInterface *mesh = gl_mesh->internal->mesh_interface;
// Make sure all global invariants are initialized.
if (!openSubdiv_initGLMeshDrawingResources()) {
return;
@@ -578,7 +566,8 @@ void GLMeshDisplayDrawPatches(OpenSubdiv_GLMesh* gl_mesh,
GLuint program = prepare_patchDraw(gl_mesh, fill_quads != 0);
if (start_patch != -1) {
drawPartitionPatchesRange(mesh, program, start_patch, num_patches);
- } else {
+ }
+ else {
drawAllPatches(mesh, program);
}
// Finish patch drawing by restoring all changes to the OpenGL context.
diff --git a/intern/opensubdiv/internal/opensubdiv_gl_mesh_draw.h b/intern/opensubdiv/internal/opensubdiv_gl_mesh_draw.h
index 5421b5cf707..599ab9550e7 100644
--- a/intern/opensubdiv/internal/opensubdiv_gl_mesh_draw.h
+++ b/intern/opensubdiv/internal/opensubdiv_gl_mesh_draw.h
@@ -25,11 +25,11 @@ struct OpenSubdiv_GLMesh;
namespace opensubdiv_capi {
-void GLMeshDisplayPrepare(struct OpenSubdiv_GLMesh* gl_mesh,
+void GLMeshDisplayPrepare(struct OpenSubdiv_GLMesh *gl_mesh,
const bool use_osd_glsl,
const int active_uv_index);
-void GLMeshDisplayDrawPatches(OpenSubdiv_GLMesh* gl_mesh,
+void GLMeshDisplayDrawPatches(OpenSubdiv_GLMesh *gl_mesh,
const bool fill_quads,
const int start_patch,
const int num_patches);
diff --git a/intern/opensubdiv/internal/opensubdiv_gl_mesh_fvar.cc b/intern/opensubdiv/internal/opensubdiv_gl_mesh_fvar.cc
index 32787ef05a3..6efbe93d2d8 100644
--- a/intern/opensubdiv/internal/opensubdiv_gl_mesh_fvar.cc
+++ b/intern/opensubdiv/internal/opensubdiv_gl_mesh_fvar.cc
@@ -28,16 +28,17 @@ namespace opensubdiv_capi {
////////////////////////////////////////////////////////////////////////////////
// GLMeshFVarData
-GLMeshFVarData::GLMeshFVarData()
- : texture_buffer(0),
- offset_buffer(0) {
+GLMeshFVarData::GLMeshFVarData() : texture_buffer(0), offset_buffer(0)
+{
}
-GLMeshFVarData::~GLMeshFVarData() {
+GLMeshFVarData::~GLMeshFVarData()
+{
release();
}
-void GLMeshFVarData::release() {
+void GLMeshFVarData::release()
+{
if (texture_buffer) {
glDeleteTextures(1, &texture_buffer);
}
@@ -50,11 +51,11 @@ void GLMeshFVarData::release() {
channel_offsets.clear();
}
-void GLMeshFVarData::create(
- const OpenSubdiv::Far::TopologyRefiner* topology_refiner,
- const OpenSubdiv::Far::PatchTable* patch_table,
- int fvar_width,
- const float* fvar_src_data) {
+void GLMeshFVarData::create(const OpenSubdiv::Far::TopologyRefiner *topology_refiner,
+ const OpenSubdiv::Far::PatchTable *patch_table,
+ int fvar_width,
+ const float *fvar_src_data)
+{
release();
this->fvar_width = fvar_width;
/// Expand fvar data to per-patch array.
@@ -64,8 +65,7 @@ void GLMeshFVarData::create(
int fvar_data_offset = 0;
channel_offsets.resize(num_channels);
for (int channel = 0; channel < num_channels; ++channel) {
- OpenSubdiv::Far::ConstIndexArray indices =
- patch_table->GetFVarValues(channel);
+ OpenSubdiv::Far::ConstIndexArray indices = patch_table->GetFVarValues(channel);
channel_offsets[channel] = data.size();
data.reserve(data.size() + indices.size() * fvar_width);
for (int fvert = 0; fvert < indices.size(); ++fvert) {
@@ -75,31 +75,26 @@ void GLMeshFVarData::create(
}
}
if (topology_refiner->IsUniform()) {
- const int num_values_max =
- topology_refiner->GetLevel(max_level).GetNumFVarValues(channel);
+ const int num_values_max = topology_refiner->GetLevel(max_level).GetNumFVarValues(channel);
fvar_data_offset += num_values_max * fvar_width;
- } else {
- const int num_values_total =
- topology_refiner->GetNumFVarValuesTotal(channel);
+ }
+ else {
+ const int num_values_total = topology_refiner->GetNumFVarValuesTotal(channel);
fvar_data_offset += num_values_total * fvar_width;
}
}
GLuint buffer;
glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
- glBufferData(GL_ARRAY_BUFFER,
- data.size() * sizeof(float), &data[0],
- GL_STATIC_DRAW);
+ glBufferData(GL_ARRAY_BUFFER, data.size() * sizeof(float), &data[0], GL_STATIC_DRAW);
glGenTextures(1, &texture_buffer);
glBindTexture(GL_TEXTURE_BUFFER, texture_buffer);
glTexBuffer(GL_TEXTURE_BUFFER, GL_R32F, buffer);
glDeleteBuffers(1, &buffer);
glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
- glBufferData(GL_ARRAY_BUFFER,
- channel_offsets.size() * sizeof(int),
- &channel_offsets[0],
- GL_STATIC_DRAW);
+ glBufferData(
+ GL_ARRAY_BUFFER, channel_offsets.size() * sizeof(int), &channel_offsets[0], GL_STATIC_DRAW);
glGenTextures(1, &offset_buffer);
glBindTexture(GL_TEXTURE_BUFFER, offset_buffer);
glTexBuffer(GL_TEXTURE_BUFFER, GL_R32I, buffer);
@@ -113,26 +108,28 @@ void GLMeshFVarData::create(
struct FVarVertex {
float u, v;
- void Clear() {
+ void Clear()
+ {
u = v = 0.0f;
}
- void AddWithWeight(FVarVertex const& src, float weight) {
+ void AddWithWeight(FVarVertex const &src, float weight)
+ {
u += weight * src.u;
v += weight * src.v;
}
};
-void interpolateFVarData(const OpenSubdiv::Far::TopologyRefiner& refiner,
- const vector<float>& uvs,
- vector<float>* fvar_data) {
+void interpolateFVarData(const OpenSubdiv::Far::TopologyRefiner &refiner,
+ const vector<float> &uvs,
+ vector<float> *fvar_data)
+{
const int fvar_width = 2;
const int max_level = refiner.GetMaxLevel();
size_t fvar_data_offset = 0, values_offset = 0;
for (int channel = 0; channel < refiner.GetNumFVarChannels(); ++channel) {
const int num_values = refiner.GetLevel(0).GetNumFVarValues(channel) * 2;
- const int num_values_max =
- refiner.GetLevel(max_level).GetNumFVarValues(channel);
+ const int num_values_max = refiner.GetLevel(max_level).GetNumFVarValues(channel);
const int num_values_total = refiner.GetNumFVarValuesTotal(channel);
if (num_values_total <= 0) {
continue;
@@ -142,29 +139,26 @@ void interpolateFVarData(const OpenSubdiv::Far::TopologyRefiner& refiner,
// For uniform we only keep the highest level of refinement.
fvar_data->resize(fvar_data->size() + num_values_max * fvar_width);
vector<FVarVertex> buffer(num_values_total - num_values_max);
- FVarVertex* src = &buffer[0];
+ FVarVertex *src = &buffer[0];
memcpy(src, &uvs[values_offset], num_values * sizeof(float));
// Defer the last level to treat separately with its alternate
// destination.
for (int level = 1; level < max_level; ++level) {
- FVarVertex* dst =
- src + refiner.GetLevel(level - 1).GetNumFVarValues(channel);
+ FVarVertex *dst = src + refiner.GetLevel(level - 1).GetNumFVarValues(channel);
primvar_refiner.InterpolateFaceVarying(level, src, dst, channel);
src = dst;
}
- FVarVertex* dst =
- reinterpret_cast<FVarVertex*>(&(*fvar_data)[fvar_data_offset]);
+ FVarVertex *dst = reinterpret_cast<FVarVertex *>(&(*fvar_data)[fvar_data_offset]);
primvar_refiner.InterpolateFaceVarying(max_level, src, dst, channel);
fvar_data_offset += num_values_max * fvar_width;
- } else {
+ }
+ else {
// For adaptive we keep all levels.
fvar_data->resize(fvar_data->size() + num_values_total * fvar_width);
- FVarVertex* src =
- reinterpret_cast<FVarVertex*>(&(*fvar_data)[fvar_data_offset]);
+ FVarVertex *src = reinterpret_cast<FVarVertex *>(&(*fvar_data)[fvar_data_offset]);
memcpy(src, &uvs[values_offset], num_values * sizeof(float));
for (int level = 1; level <= max_level; ++level) {
- FVarVertex* dst =
- src + refiner.GetLevel(level - 1).GetNumFVarValues(channel);
+ FVarVertex *dst = src + refiner.GetLevel(level - 1).GetNumFVarValues(channel);
primvar_refiner.InterpolateFaceVarying(level, src, dst, channel);
src = dst;
}
diff --git a/intern/opensubdiv/internal/opensubdiv_gl_mesh_fvar.h b/intern/opensubdiv/internal/opensubdiv_gl_mesh_fvar.h
index 0c5982f2c8b..cef78daced7 100644
--- a/intern/opensubdiv/internal/opensubdiv_gl_mesh_fvar.h
+++ b/intern/opensubdiv/internal/opensubdiv_gl_mesh_fvar.h
@@ -37,10 +37,10 @@ class GLMeshFVarData {
~GLMeshFVarData();
void release();
- void create(const OpenSubdiv::Far::TopologyRefiner* refiner,
- const OpenSubdiv::Far::PatchTable* patch_table,
+ void create(const OpenSubdiv::Far::TopologyRefiner *refiner,
+ const OpenSubdiv::Far::PatchTable *patch_table,
int fvar_width,
- const float* fvar_src_data);
+ const float *fvar_src_data);
unsigned int texture_buffer;
unsigned int offset_buffer;
@@ -48,9 +48,9 @@ class GLMeshFVarData {
int fvar_width;
};
-void interpolateFVarData(const OpenSubdiv::Far::TopologyRefiner& refiner,
- const vector<float>& uvs,
- vector<float>* fvar_data);
+void interpolateFVarData(const OpenSubdiv::Far::TopologyRefiner &refiner,
+ const vector<float> &uvs,
+ vector<float> *fvar_data);
} // namespace opensubdiv_capi
diff --git a/intern/opensubdiv/internal/opensubdiv_gl_mesh_internal.cc b/intern/opensubdiv/internal/opensubdiv_gl_mesh_internal.cc
index 3abba9cf8f8..57e56bad3fb 100644
--- a/intern/opensubdiv/internal/opensubdiv_gl_mesh_internal.cc
+++ b/intern/opensubdiv/internal/opensubdiv_gl_mesh_internal.cc
@@ -21,12 +21,12 @@
#include "internal/opensubdiv_gl_mesh_fvar.h"
OpenSubdiv_GLMeshInternal::OpenSubdiv_GLMeshInternal()
- : evaluator_type(OPENSUBDIV_EVALUATOR_CPU),
- mesh_interface(NULL),
- fvar_data(NULL) {
+ : evaluator_type(OPENSUBDIV_EVALUATOR_CPU), mesh_interface(NULL), fvar_data(NULL)
+{
}
-OpenSubdiv_GLMeshInternal::~OpenSubdiv_GLMeshInternal() {
+OpenSubdiv_GLMeshInternal::~OpenSubdiv_GLMeshInternal()
+{
delete mesh_interface;
delete fvar_data;
}
diff --git a/intern/opensubdiv/internal/opensubdiv_gl_mesh_internal.h b/intern/opensubdiv/internal/opensubdiv_gl_mesh_internal.h
index 7796b450e69..cb92fb18362 100644
--- a/intern/opensubdiv/internal/opensubdiv_gl_mesh_internal.h
+++ b/intern/opensubdiv/internal/opensubdiv_gl_mesh_internal.h
@@ -36,8 +36,8 @@ typedef struct OpenSubdiv_GLMeshInternal {
~OpenSubdiv_GLMeshInternal();
eOpenSubdivEvaluator evaluator_type;
- OpenSubdiv::Osd::GLMeshInterface* mesh_interface;
- opensubdiv_capi::GLMeshFVarData* fvar_data;
+ OpenSubdiv::Osd::GLMeshInterface *mesh_interface;
+ opensubdiv_capi::GLMeshFVarData *fvar_data;
} OpenSubdiv_GLMeshInternal;
#endif // OPENSUBDIV_GL_MESH_INTERNAL_H_
diff --git a/intern/opensubdiv/internal/opensubdiv_topology_refiner.cc b/intern/opensubdiv/internal/opensubdiv_topology_refiner.cc
index c77ddc49df7..69907da8a8c 100644
--- a/intern/opensubdiv/internal/opensubdiv_topology_refiner.cc
+++ b/intern/opensubdiv/internal/opensubdiv_topology_refiner.cc
@@ -32,164 +32,164 @@ using opensubdiv_capi::vector;
namespace {
-const OpenSubdiv::Far::TopologyRefiner* getOSDTopologyRefiner(
- const OpenSubdiv_TopologyRefiner* topology_refiner) {
+const OpenSubdiv::Far::TopologyRefiner *getOSDTopologyRefiner(
+ const OpenSubdiv_TopologyRefiner *topology_refiner)
+{
return topology_refiner->internal->osd_topology_refiner;
}
-const OpenSubdiv::Far::TopologyLevel* getOSDTopologyBaseLevel(
- const OpenSubdiv_TopologyRefiner* topology_refiner) {
+const OpenSubdiv::Far::TopologyLevel *getOSDTopologyBaseLevel(
+ const OpenSubdiv_TopologyRefiner *topology_refiner)
+{
return &getOSDTopologyRefiner(topology_refiner)->GetLevel(0);
}
-int getSubdivisionLevel(const OpenSubdiv_TopologyRefiner* topology_refiner) {
+int getSubdivisionLevel(const OpenSubdiv_TopologyRefiner *topology_refiner)
+{
return topology_refiner->internal->settings.level;
}
-bool getIsAdaptive(const OpenSubdiv_TopologyRefiner* topology_refiner) {
+bool getIsAdaptive(const OpenSubdiv_TopologyRefiner *topology_refiner)
+{
return topology_refiner->internal->settings.is_adaptive;
}
////////////////////////////////////////////////////////////////////////////////
// Query basic topology information from base level.
-int getNumVertices(const OpenSubdiv_TopologyRefiner* topology_refiner) {
+int getNumVertices(const OpenSubdiv_TopologyRefiner *topology_refiner)
+{
return getOSDTopologyBaseLevel(topology_refiner)->GetNumVertices();
}
-int getNumEdges(const OpenSubdiv_TopologyRefiner* topology_refiner) {
+int getNumEdges(const OpenSubdiv_TopologyRefiner *topology_refiner)
+{
return getOSDTopologyBaseLevel(topology_refiner)->GetNumEdges();
}
-int getNumFaces(const OpenSubdiv_TopologyRefiner* topology_refiner) {
+int getNumFaces(const OpenSubdiv_TopologyRefiner *topology_refiner)
+{
return getOSDTopologyBaseLevel(topology_refiner)->GetNumFaces();
}
////////////////////////////////////////////////////////////////////////////////
// PTex face geometry queries.
-static void convertArrayToRaw(
- const OpenSubdiv::Far::ConstIndexArray& array,
- int* raw_array) {
+static void convertArrayToRaw(const OpenSubdiv::Far::ConstIndexArray &array, int *raw_array)
+{
for (int i = 0; i < array.size(); ++i) {
raw_array[i] = array[i];
}
}
-int getNumFaceVertices(const OpenSubdiv_TopologyRefiner* topology_refiner,
- const int face_index) {
- const OpenSubdiv::Far::TopologyLevel* base_level =
- getOSDTopologyBaseLevel(topology_refiner);
+int getNumFaceVertices(const OpenSubdiv_TopologyRefiner *topology_refiner, const int face_index)
+{
+ const OpenSubdiv::Far::TopologyLevel *base_level = getOSDTopologyBaseLevel(topology_refiner);
return base_level->GetFaceVertices(face_index).size();
}
-void getFaceVertices(const OpenSubdiv_TopologyRefiner* topology_refiner,
+void getFaceVertices(const OpenSubdiv_TopologyRefiner *topology_refiner,
const int face_index,
- int* face_vertices_indices) {
- const OpenSubdiv::Far::TopologyLevel* base_level =
- getOSDTopologyBaseLevel(topology_refiner);
- OpenSubdiv::Far::ConstIndexArray array =
- base_level->GetFaceVertices(face_index);
+ int *face_vertices_indices)
+{
+ const OpenSubdiv::Far::TopologyLevel *base_level = getOSDTopologyBaseLevel(topology_refiner);
+ OpenSubdiv::Far::ConstIndexArray array = base_level->GetFaceVertices(face_index);
convertArrayToRaw(array, face_vertices_indices);
}
-int getNumFaceEdges(const OpenSubdiv_TopologyRefiner* topology_refiner,
- const int face_index) {
- const OpenSubdiv::Far::TopologyLevel* base_level =
- getOSDTopologyBaseLevel(topology_refiner);
+int getNumFaceEdges(const OpenSubdiv_TopologyRefiner *topology_refiner, const int face_index)
+{
+ const OpenSubdiv::Far::TopologyLevel *base_level = getOSDTopologyBaseLevel(topology_refiner);
return base_level->GetFaceEdges(face_index).size();
}
-void getFaceEdges(const OpenSubdiv_TopologyRefiner* topology_refiner,
+void getFaceEdges(const OpenSubdiv_TopologyRefiner *topology_refiner,
const int face_index,
- int* face_edges_indices) {
- const OpenSubdiv::Far::TopologyLevel* base_level =
- getOSDTopologyBaseLevel(topology_refiner);
+ int *face_edges_indices)
+{
+ const OpenSubdiv::Far::TopologyLevel *base_level = getOSDTopologyBaseLevel(topology_refiner);
OpenSubdiv::Far::ConstIndexArray array = base_level->GetFaceEdges(face_index);
convertArrayToRaw(array, face_edges_indices);
}
-void getEdgeVertices(const OpenSubdiv_TopologyRefiner* topology_refiner,
+void getEdgeVertices(const OpenSubdiv_TopologyRefiner *topology_refiner,
const int edge_index,
- int edge_vertices_indices[2]) {
- const OpenSubdiv::Far::TopologyLevel* base_level =
- getOSDTopologyBaseLevel(topology_refiner);
- OpenSubdiv::Far::ConstIndexArray array =
- base_level->GetEdgeVertices(edge_index);
+ int edge_vertices_indices[2])
+{
+ const OpenSubdiv::Far::TopologyLevel *base_level = getOSDTopologyBaseLevel(topology_refiner);
+ OpenSubdiv::Far::ConstIndexArray array = base_level->GetEdgeVertices(edge_index);
assert(array.size() == 2);
edge_vertices_indices[0] = array[0];
edge_vertices_indices[1] = array[1];
}
-int getNumFacePtexFaces(const OpenSubdiv_TopologyRefiner* topology_refiner,
- const int face_index) {
- const int num_face_vertices =
- topology_refiner->getNumFaceVertices(topology_refiner, face_index);
+int getNumFacePtexFaces(const OpenSubdiv_TopologyRefiner *topology_refiner, const int face_index)
+{
+ const int num_face_vertices = topology_refiner->getNumFaceVertices(topology_refiner, face_index);
if (num_face_vertices == 4) {
return 1;
- } else {
+ }
+ else {
return num_face_vertices;
}
}
-int getNumPtexFaces(const OpenSubdiv_TopologyRefiner* topology_refiner) {
+int getNumPtexFaces(const OpenSubdiv_TopologyRefiner *topology_refiner)
+{
const int num_faces = topology_refiner->getNumFaces(topology_refiner);
int num_ptex_faces = 0;
for (int face_index = 0; face_index < num_faces; ++face_index) {
- num_ptex_faces +=
- topology_refiner->getNumFacePtexFaces(topology_refiner, face_index);
+ num_ptex_faces += topology_refiner->getNumFacePtexFaces(topology_refiner, face_index);
}
return num_ptex_faces;
}
-void fillFacePtexIndexOffset(const OpenSubdiv_TopologyRefiner* topology_refiner,
- int* face_ptex_index_offset) {
+void fillFacePtexIndexOffset(const OpenSubdiv_TopologyRefiner *topology_refiner,
+ int *face_ptex_index_offset)
+{
const int num_faces = topology_refiner->getNumFaces(topology_refiner);
int num_ptex_faces = 0;
for (int face_index = 0; face_index < num_faces; ++face_index) {
face_ptex_index_offset[face_index] = num_ptex_faces;
- num_ptex_faces +=
- topology_refiner->getNumFacePtexFaces(topology_refiner, face_index);
+ num_ptex_faces += topology_refiner->getNumFacePtexFaces(topology_refiner, face_index);
}
}
////////////////////////////////////////////////////////////////////////////////
// Face-varying data.
-int getNumFVarChannels(
- const struct OpenSubdiv_TopologyRefiner* topology_refiner) {
- const OpenSubdiv::Far::TopologyLevel* base_level =
- getOSDTopologyBaseLevel(topology_refiner);
+int getNumFVarChannels(const struct OpenSubdiv_TopologyRefiner *topology_refiner)
+{
+ const OpenSubdiv::Far::TopologyLevel *base_level = getOSDTopologyBaseLevel(topology_refiner);
return base_level->GetNumFVarChannels();
}
OpenSubdiv_FVarLinearInterpolation getFVarLinearInterpolation(
- const struct OpenSubdiv_TopologyRefiner* topology_refiner) {
+ const struct OpenSubdiv_TopologyRefiner *topology_refiner)
+{
return opensubdiv_capi::getCAPIFVarLinearInterpolationFromOSD(
- getOSDTopologyRefiner(topology_refiner)->GetFVarLinearInterpolation());
+ getOSDTopologyRefiner(topology_refiner)->GetFVarLinearInterpolation());
}
-int getNumFVarValues(
- const struct OpenSubdiv_TopologyRefiner* topology_refiner,
- const int channel) {
- const OpenSubdiv::Far::TopologyLevel* base_level =
- getOSDTopologyBaseLevel(topology_refiner);
+int getNumFVarValues(const struct OpenSubdiv_TopologyRefiner *topology_refiner, const int channel)
+{
+ const OpenSubdiv::Far::TopologyLevel *base_level = getOSDTopologyBaseLevel(topology_refiner);
return base_level->GetNumFVarValues(channel);
}
-const int* getFaceFVarValueIndices(
- const struct OpenSubdiv_TopologyRefiner* topology_refiner,
- const int face_index,
- const int channel) {
- const OpenSubdiv::Far::TopologyLevel* base_level =
- getOSDTopologyBaseLevel(topology_refiner);
+const int *getFaceFVarValueIndices(const struct OpenSubdiv_TopologyRefiner *topology_refiner,
+ const int face_index,
+ const int channel)
+{
+ const OpenSubdiv::Far::TopologyLevel *base_level = getOSDTopologyBaseLevel(topology_refiner);
return &base_level->GetFaceFVarValues(face_index, channel)[0];
}
////////////////////////////////////////////////////////////////////////////////
// Internal helpers.
-void assignFunctionPointers(OpenSubdiv_TopologyRefiner* topology_refiner) {
+void assignFunctionPointers(OpenSubdiv_TopologyRefiner *topology_refiner)
+{
topology_refiner->getSubdivisionLevel = getSubdivisionLevel;
topology_refiner->getIsAdaptive = getIsAdaptive;
// Basic topology information.
@@ -212,27 +212,26 @@ void assignFunctionPointers(OpenSubdiv_TopologyRefiner* topology_refiner) {
topology_refiner->getFaceFVarValueIndices = getFaceFVarValueIndices;
}
-OpenSubdiv_TopologyRefiner* allocateTopologyRefiner() {
- OpenSubdiv_TopologyRefiner* topology_refiner =
- OBJECT_GUARDED_NEW(OpenSubdiv_TopologyRefiner);
- topology_refiner->internal =
- OBJECT_GUARDED_NEW(OpenSubdiv_TopologyRefinerInternal);
+OpenSubdiv_TopologyRefiner *allocateTopologyRefiner()
+{
+ OpenSubdiv_TopologyRefiner *topology_refiner = OBJECT_GUARDED_NEW(OpenSubdiv_TopologyRefiner);
+ topology_refiner->internal = OBJECT_GUARDED_NEW(OpenSubdiv_TopologyRefinerInternal);
assignFunctionPointers(topology_refiner);
return topology_refiner;
}
} // namespace
-OpenSubdiv_TopologyRefiner* openSubdiv_createTopologyRefinerFromConverter(
- OpenSubdiv_Converter* converter,
- const OpenSubdiv_TopologyRefinerSettings* settings) {
- OpenSubdiv::Far::TopologyRefiner* osd_topology_refiner =
+OpenSubdiv_TopologyRefiner *openSubdiv_createTopologyRefinerFromConverter(
+ OpenSubdiv_Converter *converter, const OpenSubdiv_TopologyRefinerSettings *settings)
+{
+ OpenSubdiv::Far::TopologyRefiner *osd_topology_refiner =
opensubdiv_capi::createOSDTopologyRefinerFromConverter(converter);
if (osd_topology_refiner == NULL) {
// Happens on empty or bad topology.
return NULL;
}
- OpenSubdiv_TopologyRefiner* topology_refiner = allocateTopologyRefiner();
+ OpenSubdiv_TopologyRefiner *topology_refiner = allocateTopologyRefiner();
topology_refiner->internal->osd_topology_refiner = osd_topology_refiner;
// Store setting which we want to keep track of and which can not be stored
// in OpenSubdiv's descriptor yet.
@@ -240,10 +239,9 @@ OpenSubdiv_TopologyRefiner* openSubdiv_createTopologyRefinerFromConverter(
return topology_refiner;
}
-void openSubdiv_deleteTopologyRefiner(
- OpenSubdiv_TopologyRefiner* topology_refiner) {
- OBJECT_GUARDED_DELETE(topology_refiner->internal,
- OpenSubdiv_TopologyRefinerInternal);
+void openSubdiv_deleteTopologyRefiner(OpenSubdiv_TopologyRefiner *topology_refiner)
+{
+ OBJECT_GUARDED_DELETE(topology_refiner->internal, OpenSubdiv_TopologyRefinerInternal);
OBJECT_GUARDED_DELETE(topology_refiner, OpenSubdiv_TopologyRefiner);
}
@@ -256,22 +254,20 @@ namespace {
///////////////////////////////////////////////////////////
// Quick preliminary checks.
-bool checkSchemeTypeMatches(
- const OpenSubdiv::Far::TopologyRefiner* topology_refiner,
- const OpenSubdiv_Converter* converter) {
- const OpenSubdiv::Sdc::SchemeType converter_scheme_type =
- opensubdiv_capi::getSchemeTypeFromCAPI(
- converter->getSchemeType(converter));
+bool checkSchemeTypeMatches(const OpenSubdiv::Far::TopologyRefiner *topology_refiner,
+ const OpenSubdiv_Converter *converter)
+{
+ const OpenSubdiv::Sdc::SchemeType converter_scheme_type = opensubdiv_capi::getSchemeTypeFromCAPI(
+ converter->getSchemeType(converter));
return (converter_scheme_type == topology_refiner->GetSchemeType());
}
-bool checkOptionsMatches(
- const OpenSubdiv::Far::TopologyRefiner* topology_refiner,
- const OpenSubdiv_Converter* converter) {
+bool checkOptionsMatches(const OpenSubdiv::Far::TopologyRefiner *topology_refiner,
+ const OpenSubdiv_Converter *converter)
+{
typedef OpenSubdiv::Sdc::Options Options;
const Options options = topology_refiner->GetSchemeOptions();
- const Options::FVarLinearInterpolation fvar_interpolation =
- options.GetFVarLinearInterpolation();
+ const Options::FVarLinearInterpolation fvar_interpolation = options.GetFVarLinearInterpolation();
const Options::FVarLinearInterpolation converter_fvar_interpolation =
opensubdiv_capi::getFVarLinearInterpolationFromCAPI(
converter->getFVarLinearInterpolation(converter));
@@ -281,20 +277,19 @@ bool checkOptionsMatches(
return true;
}
-bool checkGeometryCountersMatches(
- const OpenSubdiv::Far::TopologyRefiner* topology_refiner,
- const OpenSubdiv_Converter* converter) {
+bool checkGeometryCountersMatches(const OpenSubdiv::Far::TopologyRefiner *topology_refiner,
+ const OpenSubdiv_Converter *converter)
+{
using OpenSubdiv::Far::TopologyLevel;
- const TopologyLevel& base_level = topology_refiner->GetLevel(0);
- return (
- (converter->getNumVertices(converter) == base_level.GetNumVertices()) &&
- (converter->getNumEdges(converter) == base_level.GetNumEdges()) &&
- (converter->getNumFaces(converter) == base_level.GetNumFaces()));
+ const TopologyLevel &base_level = topology_refiner->GetLevel(0);
+ return ((converter->getNumVertices(converter) == base_level.GetNumVertices()) &&
+ (converter->getNumEdges(converter) == base_level.GetNumEdges()) &&
+ (converter->getNumFaces(converter) == base_level.GetNumFaces()));
}
-bool checkPreliminaryMatches(
- const OpenSubdiv::Far::TopologyRefiner* topology_refiner,
- const OpenSubdiv_Converter* converter) {
+bool checkPreliminaryMatches(const OpenSubdiv::Far::TopologyRefiner *topology_refiner,
+ const OpenSubdiv_Converter *converter)
+{
return checkSchemeTypeMatches(topology_refiner, converter) &&
checkOptionsMatches(topology_refiner, converter) &&
checkGeometryCountersMatches(topology_refiner, converter);
@@ -315,29 +310,31 @@ class CyclicArray {
typedef int size_type;
static constexpr size_type npos = -1;
- explicit CyclicArray(const std::vector<int>& data)
- : data_(data.data()),
- size_(data.size()) {
+ explicit CyclicArray(const std::vector<int> &data) : data_(data.data()), size_(data.size())
+ {
}
- explicit CyclicArray(const OpenSubdiv::Far::ConstIndexArray& data)
- : data_(&data[0]),
- size_(data.size()) {
+ explicit CyclicArray(const OpenSubdiv::Far::ConstIndexArray &data)
+ : data_(&data[0]), size_(data.size())
+ {
}
- inline value_type operator[](int index) const {
+ inline value_type operator[](int index) const
+ {
assert(index >= 0);
// TODO(sergey): Check whether doing check for element index exceeding total
// number of indices prior to modulo helps performance.
return data_[index % size()];
}
- inline size_type size() const {
+ inline size_type size() const
+ {
return size_;
}
// Find index of first occurrence of a given value.
- inline size_type find(const value_type value) const {
+ inline size_type find(const value_type value) const
+ {
const int num_indices = size();
for (size_type i = 0; i < num_indices; ++i) {
if (value == (*this)[i]) {
@@ -348,14 +345,15 @@ class CyclicArray {
}
protected:
- const value_type* data_;
+ const value_type *data_;
const size_type size_;
};
-bool compareCyclicForward(const CyclicArray& array_a,
+bool compareCyclicForward(const CyclicArray &array_a,
const int start_a,
- const CyclicArray& array_b,
- const int start_b) {
+ const CyclicArray &array_b,
+ const int start_b)
+{
const int num_elements = array_a.size();
for (int i = 0; i < num_elements; ++i) {
if (array_a[start_a + i] != array_b[start_b + i]) {
@@ -365,15 +363,15 @@ bool compareCyclicForward(const CyclicArray& array_a,
return true;
}
-bool compareCyclicBackward(const CyclicArray& array_a,
+bool compareCyclicBackward(const CyclicArray &array_a,
const int start_a,
- const CyclicArray& array_b,
- const int start_b) {
+ const CyclicArray &array_b,
+ const int start_b)
+{
const int num_elements = array_a.size();
// TODO(sergey): Some optimization might be possible with memcmp trickery.
for (int i = 0; i < num_elements; ++i) {
- if (array_a[start_a + (num_elements - i - 1)] !=
- array_b[start_b + (num_elements - i - 1)]) {
+ if (array_a[start_a + (num_elements - i - 1)] != array_b[start_b + (num_elements - i - 1)]) {
return false;
}
}
@@ -389,8 +387,8 @@ bool compareCyclicBackward(const CyclicArray& array_a,
// TODO(sergey): Check whether this is needed, ot whether OpenSubdiv is only
// creating edges in a proper orientation without modifying indices of face
// verticies.
-bool checkVerticesOfFacesMatch(const CyclicArray& indices_a,
- const CyclicArray& indices_b) {
+bool checkVerticesOfFacesMatch(const CyclicArray &indices_a, const CyclicArray &indices_b)
+{
if (indices_a.size() != indices_a.size()) {
return false;
}
@@ -410,37 +408,34 @@ bool checkVerticesOfFacesMatch(const CyclicArray& indices_a,
return false;
}
-bool checkGeometryFacesMatch(
- const OpenSubdiv::Far::TopologyRefiner* topology_refiner,
- const OpenSubdiv_Converter* converter) {
+bool checkGeometryFacesMatch(const OpenSubdiv::Far::TopologyRefiner *topology_refiner,
+ const OpenSubdiv_Converter *converter)
+{
using OpenSubdiv::Far::ConstIndexArray;
using OpenSubdiv::Far::TopologyLevel;
- const TopologyLevel& base_level = topology_refiner->GetLevel(0);
+ const TopologyLevel &base_level = topology_refiner->GetLevel(0);
const int num_faces = base_level.GetNumFaces();
// TODO(sergey): Consider using data structure which keeps handful of
// elements on stack before doing heep allocation.
vector<int> conv_face_vertices;
for (int face_index = 0; face_index < num_faces; ++face_index) {
- const ConstIndexArray& face_vertices =
- base_level.GetFaceVertices(face_index);
+ const ConstIndexArray &face_vertices = base_level.GetFaceVertices(face_index);
const int num_face_vertices = face_vertices.size();
- if (num_face_vertices !=
- converter->getNumFaceVertices(converter, face_index)) {
+ if (num_face_vertices != converter->getNumFaceVertices(converter, face_index)) {
return false;
}
conv_face_vertices.resize(num_face_vertices);
converter->getFaceVertices(converter, face_index, &conv_face_vertices[0]);
- if (!checkVerticesOfFacesMatch(CyclicArray(conv_face_vertices),
- CyclicArray(face_vertices))) {
+ if (!checkVerticesOfFacesMatch(CyclicArray(conv_face_vertices), CyclicArray(face_vertices))) {
return false;
}
}
return true;
}
-bool checkGeometryMatches(
- const OpenSubdiv::Far::TopologyRefiner* topology_refiner,
- const OpenSubdiv_Converter* converter) {
+bool checkGeometryMatches(const OpenSubdiv::Far::TopologyRefiner *topology_refiner,
+ const OpenSubdiv_Converter *converter)
+{
// NOTE: Since OpenSubdiv's topology refiner doesn't contain loose edges, we
// are only checking for faces to be matched. Changes in edges we don't care
// here too much (they'll be checked for creases changes later).
@@ -450,11 +445,11 @@ bool checkGeometryMatches(
///////////////////////////////////////////////////////////
// Compare attributes which affects on topology
-inline bool checkSingleEdgeSharpnessMatch(
- const OpenSubdiv::Far::TopologyLevel& base_level,
- int base_level_edge_index,
- const OpenSubdiv_Converter* converter,
- int converter_edge_index) {
+inline bool checkSingleEdgeSharpnessMatch(const OpenSubdiv::Far::TopologyLevel &base_level,
+ int base_level_edge_index,
+ const OpenSubdiv_Converter *converter,
+ int converter_edge_index)
+{
// NOTE: Boundary and non-manifold edges are internally forced to an infinite
// sharpness. So we can not reliably compare those.
//
@@ -464,36 +459,34 @@ inline bool checkSingleEdgeSharpnessMatch(
return true;
}
const float sharpness = base_level.GetEdgeSharpness(base_level_edge_index);
- const float converter_sharpness =
- converter->getEdgeSharpness(converter, converter_edge_index);
+ const float converter_sharpness = converter->getEdgeSharpness(converter, converter_edge_index);
if (sharpness != converter_sharpness) {
return false;
}
return true;
}
-inline bool checkSingleEdgeTagMatch(
- const OpenSubdiv::Far::TopologyLevel& base_level,
- int base_level_edge_index,
- const OpenSubdiv_Converter* converter,
- int converter_edge_index) {
- return checkSingleEdgeSharpnessMatch(base_level, base_level_edge_index,
- converter, converter_edge_index);
+inline bool checkSingleEdgeTagMatch(const OpenSubdiv::Far::TopologyLevel &base_level,
+ int base_level_edge_index,
+ const OpenSubdiv_Converter *converter,
+ int converter_edge_index)
+{
+ return checkSingleEdgeSharpnessMatch(
+ base_level, base_level_edge_index, converter, converter_edge_index);
}
// Compares edge tags between topology refiner and converter in a case when
// converter specifies a full topology.
// This is simplest loop, since we know that order of edges matches.
-bool checkEdgeTagsMatchFullTopology(
- const OpenSubdiv::Far::TopologyRefiner* topology_refiner,
- const OpenSubdiv_Converter* converter) {
+bool checkEdgeTagsMatchFullTopology(const OpenSubdiv::Far::TopologyRefiner *topology_refiner,
+ const OpenSubdiv_Converter *converter)
+{
using OpenSubdiv::Far::ConstIndexArray;
using OpenSubdiv::Far::TopologyLevel;
- const TopologyLevel& base_level = topology_refiner->GetLevel(0);
+ const TopologyLevel &base_level = topology_refiner->GetLevel(0);
const int num_edges = base_level.GetNumEdges();
for (int edge_index = 0; edge_index < num_edges; ++edge_index) {
- if (!checkSingleEdgeTagMatch(
- base_level, edge_index, converter, edge_index)) {
+ if (!checkSingleEdgeTagMatch(base_level, edge_index, converter, edge_index)) {
return false;
}
}
@@ -503,12 +496,12 @@ bool checkEdgeTagsMatchFullTopology(
// Compares tags of edges in the case when orientation of edges is left up to
// OpenSubdiv. In this case we do need to take care of mapping edges from the
// converter to current topology refiner, since the order is not guaranteed.
-bool checkEdgeTagsMatchAutoOrient(
- const OpenSubdiv::Far::TopologyRefiner* topology_refiner,
- const OpenSubdiv_Converter* converter) {
+bool checkEdgeTagsMatchAutoOrient(const OpenSubdiv::Far::TopologyRefiner *topology_refiner,
+ const OpenSubdiv_Converter *converter)
+{
using OpenSubdiv::Far::ConstIndexArray;
using OpenSubdiv::Far::TopologyLevel;
- const TopologyLevel& base_level = topology_refiner->GetLevel(0);
+ const TopologyLevel &base_level = topology_refiner->GetLevel(0);
const int num_edges = base_level.GetNumEdges();
// Create mapping for quick lookup of edge index from its verticies indices.
//
@@ -520,41 +513,39 @@ bool checkEdgeTagsMatchAutoOrient(
edge_map.insert(edge_vertices[0], edge_vertices[1], edge_index);
}
// Compare all edges.
- for (int converter_edge_index = 0;
- converter_edge_index < num_edges;
- ++converter_edge_index) {
+ for (int converter_edge_index = 0; converter_edge_index < num_edges; ++converter_edge_index) {
// Get edge verticies indices, and lookup corresponding edge index in the
// base topology level.
int edge_vertices[2];
converter->getEdgeVertices(converter, converter_edge_index, edge_vertices);
- const int base_level_edge_index = edge_map.at(
- edge_vertices[0], edge_vertices[1]);
+ const int base_level_edge_index = edge_map.at(edge_vertices[0], edge_vertices[1]);
// Perform actual test.
if (!checkSingleEdgeTagMatch(
- base_level, base_level_edge_index, converter, converter_edge_index)) {
+ base_level, base_level_edge_index, converter, converter_edge_index)) {
return false;
}
}
return true;
}
-bool checkEdgeTagsMatch(
- const OpenSubdiv::Far::TopologyRefiner* topology_refiner,
- const OpenSubdiv_Converter* converter) {
+bool checkEdgeTagsMatch(const OpenSubdiv::Far::TopologyRefiner *topology_refiner,
+ const OpenSubdiv_Converter *converter)
+{
if (converter->specifiesFullTopology(converter)) {
return checkEdgeTagsMatchFullTopology(topology_refiner, converter);
- } else {
+ }
+ else {
return checkEdgeTagsMatchAutoOrient(topology_refiner, converter);
}
}
-bool checkvertexSharpnessMatch(
- const OpenSubdiv::Far::TopologyRefiner* topology_refiner,
- const OpenSubdiv_Converter* converter) {
+bool checkvertexSharpnessMatch(const OpenSubdiv::Far::TopologyRefiner *topology_refiner,
+ const OpenSubdiv_Converter *converter)
+{
using OpenSubdiv::Far::ConstIndexArray;
using OpenSubdiv::Far::TopologyLevel;
using OpenSubdiv::Sdc::Crease;
- const TopologyLevel& base_level = topology_refiner->GetLevel(0);
+ const TopologyLevel &base_level = topology_refiner->GetLevel(0);
// Create mapping for quick lookup of edge index from its verticies indices.
//
// TODO(sergey): Consider caching it in some sort of wrapper around topology
@@ -573,7 +564,8 @@ bool checkvertexSharpnessMatch(
if (current_sharpness != Crease::SHARPNESS_INFINITE) {
return false;
}
- } else {
+ }
+ else {
ConstIndexArray vertex_edges = base_level.GetVertexEdges(vertex_index);
float sharpness = converter->getVertexSharpness(converter, vertex_index);
if (vertex_edges.size() == 2) {
@@ -587,10 +579,8 @@ bool checkvertexSharpnessMatch(
const int edge0_converter_index = edge_map[edge0_key];
const int edge1_converter_index = edge_map[edge1_key];
// Lookup sharpness.
- const float sharpness0 = converter->getEdgeSharpness(
- converter, edge0_converter_index);
- const float sharpness1 = converter->getEdgeSharpness(
- converter, edge1_converter_index);
+ const float sharpness0 = converter->getEdgeSharpness(converter, edge0_converter_index);
+ const float sharpness1 = converter->getEdgeSharpness(converter, edge1_converter_index);
// TODO(sergey): Find a better mixing between edge and vertex sharpness.
sharpness += min(sharpness0, sharpness1);
sharpness = min(sharpness, 10.0f);
@@ -603,20 +593,19 @@ bool checkvertexSharpnessMatch(
return true;
}
-bool checkSingleUVLayerMatch(
- const OpenSubdiv::Far::TopologyLevel& base_level,
- const OpenSubdiv_Converter* converter,
- const int layer_index) {
+bool checkSingleUVLayerMatch(const OpenSubdiv::Far::TopologyLevel &base_level,
+ const OpenSubdiv_Converter *converter,
+ const int layer_index)
+{
converter->precalcUVLayer(converter, layer_index);
const int num_faces = base_level.GetNumFaces();
// TODO(sergey): Need to check whether converter changed the winding of
// face to match OpenSubdiv's expectations.
for (int face_index = 0; face_index < num_faces; ++face_index) {
- OpenSubdiv::Far::ConstIndexArray base_level_face_uvs =
- base_level.GetFaceFVarValues(face_index, layer_index);
+ OpenSubdiv::Far::ConstIndexArray base_level_face_uvs = base_level.GetFaceFVarValues(
+ face_index, layer_index);
for (int corner = 0; corner < base_level_face_uvs.size(); ++corner) {
- const int uv_index =
- converter->getFaceCornerUVIndex(converter, face_index, corner);
+ const int uv_index = converter->getFaceCornerUVIndex(converter, face_index, corner);
if (base_level_face_uvs[corner] != uv_index) {
converter->finishUVLayer(converter);
return false;
@@ -627,12 +616,12 @@ bool checkSingleUVLayerMatch(
return true;
}
-bool checkUVLayersMatch(
- const OpenSubdiv::Far::TopologyRefiner* topology_refiner,
- const OpenSubdiv_Converter* converter) {
+bool checkUVLayersMatch(const OpenSubdiv::Far::TopologyRefiner *topology_refiner,
+ const OpenSubdiv_Converter *converter)
+{
using OpenSubdiv::Far::TopologyLevel;
const int num_layers = converter->getNumUVLayers(converter);
- const TopologyLevel& base_level = topology_refiner->GetLevel(0);
+ const TopologyLevel &base_level = topology_refiner->GetLevel(0);
// Number of UV layers should match.
if (base_level.GetNumFVarChannels() != num_layers) {
return false;
@@ -645,9 +634,9 @@ bool checkUVLayersMatch(
return true;
}
-bool checkTopologyAttributesMatch(
- const OpenSubdiv::Far::TopologyRefiner* topology_refiner,
- const OpenSubdiv_Converter* converter) {
+bool checkTopologyAttributesMatch(const OpenSubdiv::Far::TopologyRefiner *topology_refiner,
+ const OpenSubdiv_Converter *converter)
+{
return checkEdgeTagsMatch(topology_refiner, converter) &&
checkvertexSharpnessMatch(topology_refiner, converter) &&
checkUVLayersMatch(topology_refiner, converter);
@@ -657,10 +646,9 @@ bool checkTopologyAttributesMatch(
} // namespace opensubdiv_capi
bool openSubdiv_topologyRefinerCompareWithConverter(
- const OpenSubdiv_TopologyRefiner* topology_refiner,
- const OpenSubdiv_Converter* converter) {
- const OpenSubdiv::Far::TopologyRefiner* refiner =
- getOSDTopologyRefiner(topology_refiner);
+ const OpenSubdiv_TopologyRefiner *topology_refiner, const OpenSubdiv_Converter *converter)
+{
+ const OpenSubdiv::Far::TopologyRefiner *refiner = getOSDTopologyRefiner(topology_refiner);
return (opensubdiv_capi::checkPreliminaryMatches(refiner, converter) &&
opensubdiv_capi::checkGeometryMatches(refiner, converter) &&
opensubdiv_capi::checkTopologyAttributesMatch(refiner, converter));
diff --git a/intern/opensubdiv/internal/opensubdiv_topology_refiner_internal.cc b/intern/opensubdiv/internal/opensubdiv_topology_refiner_internal.cc
index 4636679761f..f3054a17da2 100644
--- a/intern/opensubdiv/internal/opensubdiv_topology_refiner_internal.cc
+++ b/intern/opensubdiv/internal/opensubdiv_topology_refiner_internal.cc
@@ -19,8 +19,11 @@
#include "internal/opensubdiv_topology_refiner_internal.h"
OpenSubdiv_TopologyRefinerInternal::OpenSubdiv_TopologyRefinerInternal()
- : osd_topology_refiner(NULL) {}
+ : osd_topology_refiner(NULL)
+{
+}
-OpenSubdiv_TopologyRefinerInternal::~OpenSubdiv_TopologyRefinerInternal() {
+OpenSubdiv_TopologyRefinerInternal::~OpenSubdiv_TopologyRefinerInternal()
+{
delete osd_topology_refiner;
}
diff --git a/intern/opensubdiv/internal/opensubdiv_topology_refiner_internal.h b/intern/opensubdiv/internal/opensubdiv_topology_refiner_internal.h
index f7ca6a7ad5e..b0f5d4079ef 100644
--- a/intern/opensubdiv/internal/opensubdiv_topology_refiner_internal.h
+++ b/intern/opensubdiv/internal/opensubdiv_topology_refiner_internal.h
@@ -32,7 +32,7 @@ struct OpenSubdiv_TopologyRefinerInternal {
OpenSubdiv_TopologyRefinerInternal();
~OpenSubdiv_TopologyRefinerInternal();
- OpenSubdiv::Far::TopologyRefiner* osd_topology_refiner;
+ OpenSubdiv::Far::TopologyRefiner *osd_topology_refiner;
// Subdivision settingsa this refiner is created for.
//
diff --git a/intern/opensubdiv/internal/opensubdiv_util.cc b/intern/opensubdiv/internal/opensubdiv_util.cc
index 040c9a07512..6e6f3a0920f 100644
--- a/intern/opensubdiv/internal/opensubdiv_util.cc
+++ b/intern/opensubdiv/internal/opensubdiv_util.cc
@@ -25,17 +25,19 @@
namespace opensubdiv_capi {
-void stringSplit(vector<string>* tokens,
- const string& str,
- const string& separators,
- bool skip_empty) {
+void stringSplit(vector<string> *tokens,
+ const string &str,
+ const string &separators,
+ bool skip_empty)
+{
size_t token_start = 0, token_length = 0;
for (size_t i = 0; i < str.length(); ++i) {
const char ch = str[i];
if (separators.find(ch) == string::npos) {
// Append non-separator char to a token.
++token_length;
- } else {
+ }
+ else {
// Append current token to the list (if any).
if (token_length > 0 || !skip_empty) {
string token = str.substr(token_start, token_length);
@@ -48,8 +50,7 @@ void stringSplit(vector<string>* tokens,
}
// Append token which might be at the end of the string.
if ((token_length != 0) ||
- (!skip_empty && token_start > 0 &&
- separators.find(str[token_start-1]) != string::npos)) {
+ (!skip_empty && token_start > 0 && separators.find(str[token_start - 1]) != string::npos)) {
string token = str.substr(token_start, token_length);
tokens->push_back(token);
}
diff --git a/intern/opensubdiv/internal/opensubdiv_util.h b/intern/opensubdiv/internal/opensubdiv_util.h
index 067c194478c..7817ebac96e 100644
--- a/intern/opensubdiv/internal/opensubdiv_util.h
+++ b/intern/opensubdiv/internal/opensubdiv_util.h
@@ -46,9 +46,9 @@ using std::vector;
#define STRINGIFY_APPEND(a, b) "" a #b
#define STRINGIFY(x) STRINGIFY_APPEND("", x)
-void stringSplit(vector<string>* tokens,
- const string& str,
- const string& separators,
+void stringSplit(vector<string> *tokens,
+ const string &str,
+ const string &separators,
bool skip_empty);
} // namespace opensubdiv_capi