diff options
Diffstat (limited to 'intern/opensubdiv/internal/opensubdiv_gl_mesh.cc')
-rw-r--r-- | intern/opensubdiv/internal/opensubdiv_gl_mesh.cc | 152 |
1 files changed, 64 insertions, 88 deletions
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); } |