diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-07-19 17:12:18 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-07-20 13:38:33 +0300 |
commit | 9a0634a253421c02dbb6d2864db49e4d382ea2a3 (patch) | |
tree | 3fa849fa99cc2b377a29de9f2d6201f35aed102f | |
parent | 690063edb928b2755462863d971600deb608f848 (diff) |
OpenSubdiv: Wrap OSD's TopologyRefier with own struct
This is a way for us to store extra data, such as UVs which we can
collect now on topology refiner stage.
-rw-r--r-- | intern/opensubdiv/CMakeLists.txt | 1 | ||||
-rw-r--r-- | intern/opensubdiv/opensubdiv_capi.cc | 7 | ||||
-rw-r--r-- | intern/opensubdiv/opensubdiv_converter.cc | 23 | ||||
-rw-r--r-- | intern/opensubdiv/opensubdiv_topology_refiner.h | 35 |
4 files changed, 56 insertions, 10 deletions
diff --git a/intern/opensubdiv/CMakeLists.txt b/intern/opensubdiv/CMakeLists.txt index 311b89b97cf..ab660b8162a 100644 --- a/intern/opensubdiv/CMakeLists.txt +++ b/intern/opensubdiv/CMakeLists.txt @@ -47,6 +47,7 @@ set(SRC opensubdiv_device_context_cuda.h opensubdiv_device_context_opencl.h opensubdiv_intern.h + opensubdiv_topology_refiner.h ) macro(OPENSUBDIV_DEFINE_COMPONENT component) diff --git a/intern/opensubdiv/opensubdiv_capi.cc b/intern/opensubdiv/opensubdiv_capi.cc index 9b9f4baa39e..0463982fdf6 100644 --- a/intern/opensubdiv/opensubdiv_capi.cc +++ b/intern/opensubdiv/opensubdiv_capi.cc @@ -69,6 +69,7 @@ #include <opensubdiv/far/stencilTable.h> #include "opensubdiv_intern.h" +#include "opensubdiv_topology_refiner.h" #include "MEM_guardedalloc.h" @@ -164,7 +165,7 @@ struct OpenSubdiv_GLMesh *openSubdiv_createOsdGLMeshFromTopologyRefiner( const int num_varying_elements = 3; GLMeshInterface *mesh = NULL; - TopologyRefiner *refiner = (TopologyRefiner*)topology_refiner; + TopologyRefiner *refiner = topology_refiner->osd_refiner; switch(evaluator_type) { #define CHECK_EVALUATOR_TYPE(type, class) \ @@ -210,7 +211,7 @@ struct OpenSubdiv_GLMesh *openSubdiv_createOsdGLMeshFromTopologyRefiner( (OpenSubdiv_GLMesh *) OBJECT_GUARDED_NEW(OpenSubdiv_GLMesh); gl_mesh->evaluator_type = evaluator_type; gl_mesh->descriptor = (OpenSubdiv_GLMeshDescr *) mesh; - gl_mesh->topology_refiner = (OpenSubdiv_TopologyRefinerDescr*)refiner; + gl_mesh->topology_refiner = topology_refiner; return gl_mesh; } @@ -249,6 +250,8 @@ void openSubdiv_deleteOsdGLMesh(struct OpenSubdiv_GLMesh *gl_mesh) #undef CHECK_EVALUATOR_TYPE } + /* NOTE: OSD refiner was owned by gl_mesh, no need to free it here. */ + OBJECT_GUARDED_DELETE(gl_mesh->topology_refiner, OpenSubdiv_TopologyRefinerDescr); OBJECT_GUARDED_DELETE(gl_mesh, OpenSubdiv_GLMesh); } diff --git a/intern/opensubdiv/opensubdiv_converter.cc b/intern/opensubdiv/opensubdiv_converter.cc index 0ad72c88a12..e718d6b4dc8 100644 --- a/intern/opensubdiv/opensubdiv_converter.cc +++ b/intern/opensubdiv/opensubdiv_converter.cc @@ -32,8 +32,12 @@ #include <opensubdiv/far/topologyRefinerFactory.h> +#include "MEM_guardedalloc.h" + #include "opensubdiv_converter_capi.h" #include "opensubdiv_intern.h" +#include "opensubdiv_topology_refiner.h" + #include <stack> @@ -524,26 +528,29 @@ struct OpenSubdiv_TopologyRefinerDescr *openSubdiv_createTopologyRefinerDescr( #ifdef OPENSUBDIV_VALIDATE_TOPOLOGY topology_options.validateFullTopology = true; #endif + OpenSubdiv_TopologyRefinerDescr *result = OBJECT_GUARDED_NEW(OpenSubdiv_TopologyRefinerDescr); /* We don't use guarded allocation here so we can re-use the refiner * for GL mesh creation directly. */ - return (struct OpenSubdiv_TopologyRefinerDescr*) + result->osd_refiner = TopologyRefinerFactory<OpenSubdiv_Converter>::Create( *converter, topology_options); + return result; } void openSubdiv_deleteTopologyRefinerDescr( OpenSubdiv_TopologyRefinerDescr *topology_refiner) { - delete (OpenSubdiv::Far::TopologyRefiner *)topology_refiner; + delete topology_refiner->osd_refiner; + OBJECT_GUARDED_DELETE(topology_refiner, OpenSubdiv_TopologyRefinerDescr); } int openSubdiv_topologyRefinerGetSubdivLevel( const OpenSubdiv_TopologyRefinerDescr *topology_refiner) { using OpenSubdiv::Far::TopologyRefiner; - const TopologyRefiner *refiner = (const TopologyRefiner *)topology_refiner; + const TopologyRefiner *refiner = topology_refiner->osd_refiner; return refiner->GetMaxLevel(); } @@ -552,7 +559,7 @@ int openSubdiv_topologyRefinerGetNumVerts( { using OpenSubdiv::Far::TopologyLevel; using OpenSubdiv::Far::TopologyRefiner; - const TopologyRefiner *refiner = (const TopologyRefiner *)topology_refiner; + const TopologyRefiner *refiner = topology_refiner->osd_refiner; const TopologyLevel &base_level = refiner->GetLevel(0); return base_level.GetNumVertices(); } @@ -562,7 +569,7 @@ int openSubdiv_topologyRefinerGetNumEdges( { using OpenSubdiv::Far::TopologyLevel; using OpenSubdiv::Far::TopologyRefiner; - const TopologyRefiner *refiner = (const TopologyRefiner *)topology_refiner; + const TopologyRefiner *refiner = topology_refiner->osd_refiner; const TopologyLevel &base_level = refiner->GetLevel(0); return base_level.GetNumEdges(); } @@ -572,7 +579,7 @@ int openSubdiv_topologyRefinerGetNumFaces( { using OpenSubdiv::Far::TopologyLevel; using OpenSubdiv::Far::TopologyRefiner; - const TopologyRefiner *refiner = (const TopologyRefiner *)topology_refiner; + const TopologyRefiner *refiner = topology_refiner->osd_refiner; const TopologyLevel &base_level = refiner->GetLevel(0); return base_level.GetNumFaces(); } @@ -583,7 +590,7 @@ int openSubdiv_topologyRefinerGetNumFaceVerts( { using OpenSubdiv::Far::TopologyLevel; using OpenSubdiv::Far::TopologyRefiner; - const TopologyRefiner *refiner = (const TopologyRefiner *)topology_refiner; + const TopologyRefiner *refiner = topology_refiner->osd_refiner; const TopologyLevel &base_level = refiner->GetLevel(0); return base_level.GetFaceVertices(face).size(); } @@ -595,7 +602,7 @@ int openSubdiv_topologyRefnerCompareConverter( using OpenSubdiv::Far::ConstIndexArray; using OpenSubdiv::Far::TopologyRefiner; using OpenSubdiv::Far::TopologyLevel; - const TopologyRefiner *refiner = (const TopologyRefiner *)topology_refiner; + const TopologyRefiner *refiner = topology_refiner->osd_refiner; const TopologyLevel &base_level = refiner->GetLevel(0); const int num_verts = base_level.GetNumVertices(); const int num_edges = base_level.GetNumEdges(); diff --git a/intern/opensubdiv/opensubdiv_topology_refiner.h b/intern/opensubdiv/opensubdiv_topology_refiner.h new file mode 100644 index 00000000000..5c299ac5df5 --- /dev/null +++ b/intern/opensubdiv/opensubdiv_topology_refiner.h @@ -0,0 +1,35 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2016 Blender Foundation. + * All rights reserved. + * + * Contributor(s): Sergey Sharybin. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __OPENSUBDIV_TOPOLOGY_REFINER_H__ +#define __OPENSUBDIV_TOPOLOGY_REFINER_H__ + +#include <opensubdiv/far/topologyRefiner.h> + +typedef struct OpenSubdiv_TopologyRefinerDescr { + OpenSubdiv::Far::TopologyRefiner *osd_refiner; +} OpenSubdiv_TopologyRefinerDescr; + +#endif /* __OPENSUBDIV_TOPOLOGY_REFINER_H__ */ |