[Bf-blender-cvs] [d9203820467] blender2.8: OpenSubdiv: Re-work C-API integration
Sergey Sharybin
noreply at git.blender.org
Mon Jul 16 11:18:17 CEST 2018
Commit: d9203820467665ba19e1956e035de663849e695c
Author: Sergey Sharybin
Date: Mon Jul 16 09:28:05 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBd9203820467665ba19e1956e035de663849e695c
OpenSubdiv: Re-work C-API integration
Main goal is to make API simpler to follow (at least ion terms what
is defined/declared where, as opposite of handful big headers which
includes all the declarations), and also avoid a big set of long and
obscure functions.
Now C-API files are split into smaller ones, following OpenSubdiv
behavior more closely, and also function pointers in structures
used a lot more, which shortens functions names,
UV integration part in GL Mesh is mainly stripped away, it needs
to be done differently. On a related topic, UV coordinates API in
converter needs to be removed as well, we do not need coordinates,
only island connectivity information there.
Additional changes:
- Varying interpolation in evaluator API are temporarily disabled,
need to extend API somewhere (probably, evaluator's API) to inform
layout information of vertex data (whether it contains varying
data, width, stride and such).
- Evaluator now can interpolate face-varying data.
Only works for adaptive refiner, since some issues in OpenSubdiv
itself.
Planned changes:
- Remove uv coordinates from TopologyConverter.
- Support evaluation of patches (as opposite to individual coordinates
as it happens currently).
- Support more flexible layout of varying and face-varying data.
It is stupid to assume varying is 3 floats and face-varying 2 floats.
- Support of second order derivatives.
- Everything else what i'm missing in this list.
===================================================================
M intern/opensubdiv/CMakeLists.txt
A intern/opensubdiv/internal/opensubdiv.cc
A intern/opensubdiv/internal/opensubdiv_converter_factory.cc
A intern/opensubdiv/internal/opensubdiv_converter_factory.h
A intern/opensubdiv/internal/opensubdiv_converter_internal.cc
A intern/opensubdiv/internal/opensubdiv_converter_internal.h
A intern/opensubdiv/internal/opensubdiv_converter_orient.cc
A intern/opensubdiv/internal/opensubdiv_converter_orient.h
A intern/opensubdiv/internal/opensubdiv_converter_orient_impl.h
A intern/opensubdiv/internal/opensubdiv_device_context_cuda.cc
A intern/opensubdiv/internal/opensubdiv_device_context_cuda.h
A intern/opensubdiv/internal/opensubdiv_device_context_opencl.cc
A intern/opensubdiv/internal/opensubdiv_device_context_opencl.h
A intern/opensubdiv/internal/opensubdiv_evaluator.cc
A intern/opensubdiv/internal/opensubdiv_evaluator_internal.cc
A intern/opensubdiv/internal/opensubdiv_evaluator_internal.h
A intern/opensubdiv/internal/opensubdiv_gl_mesh.cc
A intern/opensubdiv/internal/opensubdiv_gl_mesh_draw.cc
A intern/opensubdiv/internal/opensubdiv_gl_mesh_draw.h
A intern/opensubdiv/internal/opensubdiv_gl_mesh_fvar.cc
A intern/opensubdiv/internal/opensubdiv_gl_mesh_fvar.h
A intern/opensubdiv/internal/opensubdiv_gl_mesh_internal.cc
A intern/opensubdiv/internal/opensubdiv_gl_mesh_internal.h
R100 intern/opensubdiv/opensubdiv_gpu_capi.cc intern/opensubdiv/internal/opensubdiv_gpu.cc
A intern/opensubdiv/internal/opensubdiv_internal.h
A intern/opensubdiv/internal/opensubdiv_topology_refiner.cc
R100 intern/opensubdiv/opensubdiv_topology_refiner.h intern/opensubdiv/internal/opensubdiv_topology_refiner.h
A intern/opensubdiv/internal/opensubdiv_topology_refiner_internal.cc
A intern/opensubdiv/internal/opensubdiv_topology_refiner_internal.h
A intern/opensubdiv/internal/opensubdiv_util.cc
A intern/opensubdiv/internal/opensubdiv_util.h
D intern/opensubdiv/opensubdiv_capi.cc
M intern/opensubdiv/opensubdiv_capi.h
A intern/opensubdiv/opensubdiv_capi_type.h
D intern/opensubdiv/opensubdiv_converter.cc
M intern/opensubdiv/opensubdiv_converter_capi.h
D intern/opensubdiv/opensubdiv_device_context_cuda.cc
D intern/opensubdiv/opensubdiv_device_context_cuda.h
D intern/opensubdiv/opensubdiv_device_context_opencl.cc
D intern/opensubdiv/opensubdiv_device_context_opencl.h
D intern/opensubdiv/opensubdiv_evaluator_capi.cc
A intern/opensubdiv/opensubdiv_evaluator_capi.h
D intern/opensubdiv/opensubdiv_gl_mesh.h
A intern/opensubdiv/opensubdiv_gl_mesh_capi.h
D intern/opensubdiv/opensubdiv_intern.h
A intern/opensubdiv/opensubdiv_topology_refiner_capi.h
D intern/opensubdiv/opensubdiv_utils_capi.cc
R100 intern/opensubdiv/gpu_shader_opensubdiv_fragment.glsl intern/opensubdiv/shader/gpu_shader_opensubdiv_fragment.glsl
R100 intern/opensubdiv/gpu_shader_opensubdiv_geometry.glsl intern/opensubdiv/shader/gpu_shader_opensubdiv_geometry.glsl
R100 intern/opensubdiv/gpu_shader_opensubdiv_vertex.glsl intern/opensubdiv/shader/gpu_shader_opensubdiv_vertex.glsl
M source/blender/blenkernel/intern/CCGSubSurf.c
M source/blender/blenkernel/intern/CCGSubSurf_intern.h
M source/blender/blenkernel/intern/CCGSubSurf_opensubdiv.c
M source/blender/blenkernel/intern/CCGSubSurf_opensubdiv_converter.c
===================================================================
diff --git a/intern/opensubdiv/CMakeLists.txt b/intern/opensubdiv/CMakeLists.txt
index 876b5c0181f..887eb399224 100644
--- a/intern/opensubdiv/CMakeLists.txt
+++ b/intern/opensubdiv/CMakeLists.txt
@@ -34,20 +34,40 @@ set(INC_SYS
)
set(SRC
- opensubdiv_capi.cc
- opensubdiv_converter.cc
- opensubdiv_device_context_cuda.cc
- opensubdiv_device_context_opencl.cc
- opensubdiv_evaluator_capi.cc
- opensubdiv_gpu_capi.cc
- opensubdiv_utils_capi.cc
+ internal/opensubdiv.cc
+ internal/opensubdiv_converter_factory.cc
+ internal/opensubdiv_converter_internal.cc
+ internal/opensubdiv_converter_orient.cc
+ internal/opensubdiv_device_context_cuda.cc
+ internal/opensubdiv_device_context_opencl.cc
+ internal/opensubdiv_evaluator.cc
+ internal/opensubdiv_evaluator_internal.cc
+ internal/opensubdiv_gl_mesh.cc
+ internal/opensubdiv_gl_mesh_draw.cc
+ internal/opensubdiv_gl_mesh_fvar.cc
+ internal/opensubdiv_gl_mesh_internal.cc
+ internal/opensubdiv_topology_refiner.cc
+ internal/opensubdiv_topology_refiner_internal.cc
+ internal/opensubdiv_util.cc
+
+ internal/opensubdiv_converter_internal.h
+ internal/opensubdiv_converter_orient.h
+ internal/opensubdiv_converter_orient_impl.h
+ internal/opensubdiv_device_context_cuda.h
+ internal/opensubdiv_device_context_opencl.h
+ internal/opensubdiv_evaluator_internal.h
+ internal/opensubdiv_gl_mesh_fvar.h
+ internal/opensubdiv_gl_mesh_internal.h
+ internal/opensubdiv_internal.h
+ internal/opensubdiv_topology_refiner_internal.h
+ internal/opensubdiv_util.h
opensubdiv_capi.h
+ opensubdiv_capi_type.h
opensubdiv_converter_capi.h
- opensubdiv_device_context_cuda.h
- opensubdiv_device_context_opencl.h
- opensubdiv_intern.h
- opensubdiv_topology_refiner.h
+ opensubdiv_evaluator_capi.h
+ opensubdiv_gl_mesh_capi.h
+ opensubdiv_topology_refiner_capi.h
)
macro(OPENSUBDIV_DEFINE_COMPONENT component)
@@ -64,9 +84,9 @@ OPENSUBDIV_DEFINE_COMPONENT(OPENSUBDIV_HAS_OPENMP)
OPENSUBDIV_DEFINE_COMPONENT(OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK)
OPENSUBDIV_DEFINE_COMPONENT(OPENSUBDIV_HAS_GLSL_COMPUTE)
-data_to_c_simple(gpu_shader_opensubdiv_vertex.glsl SRC)
-data_to_c_simple(gpu_shader_opensubdiv_geometry.glsl SRC)
-data_to_c_simple(gpu_shader_opensubdiv_fragment.glsl SRC)
+data_to_c_simple(shader/gpu_shader_opensubdiv_vertex.glsl SRC)
+data_to_c_simple(shader/gpu_shader_opensubdiv_geometry.glsl SRC)
+data_to_c_simple(shader/gpu_shader_opensubdiv_fragment.glsl SRC)
add_definitions(-DGLEW_STATIC)
diff --git a/intern/opensubdiv/internal/opensubdiv.cc b/intern/opensubdiv/internal/opensubdiv.cc
new file mode 100644
index 00000000000..c2945ed25ab
--- /dev/null
+++ b/intern/opensubdiv/internal/opensubdiv.cc
@@ -0,0 +1,99 @@
+// Copyright 2013 Blender Foundation. All rights reserved.
+//
+// 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.
+//
+// Author: Sergey Sharybin
+// Contributor(s): Brecht van Lommel
+
+#include "opensubdiv_capi.h"
+
+#ifdef _MSC_VER
+# include <iso646.h>
+#endif
+
+#include <GL/glew.h>
+
+#include "opensubdiv_device_context_opencl.h"
+#include "opensubdiv_device_context_cuda.h"
+#include "opensubdiv_gl_mesh_capi.h"
+
+void openSubdiv_init(void) {
+ // Ensure all OpenGL strings are cached.
+ openSubdiv_getAvailableEvaluators();
+}
+
+void openSubdiv_cleanup(void) {
+ openSubdiv_deinitGLMeshDrawingResources();
+}
+
+int openSubdiv_getAvailableEvaluators(void) {
+ int flags = OPENSUBDIV_EVALUATOR_CPU;
+
+#ifdef OPENSUBDIV_HAS_OPENMP
+ flags |= OPENSUBDIV_EVALUATOR_OPENMP;
+#endif
+
+#ifdef OPENSUBDIV_HAS_OPENCL
+ if (CLDeviceContext::HAS_CL_VERSION_1_1()) {
+ flags |= OPENSUBDIV_EVALUATOR_OPENCL;
+ }
+#endif
+
+#ifdef OPENSUBDIV_HAS_CUDA
+ if (CudaDeviceContext::HAS_CUDA_VERSION_4_0()) {
+ flags |= OPENSUBDIV_EVALUATOR_CUDA;
+ }
+#endif
+
+#ifdef OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK
+ if (GLEW_VERSION_4_1) {
+ flags |= OPENSUBDIV_EVALUATOR_GLSL_TRANSFORM_FEEDBACK;
+ }
+#endif
+
+#ifdef OPENSUBDIV_HAS_GLSL_COMPUTE
+ if (GLEW_VERSION_4_3 || GLEW_ARB_compute_shader) {
+ flags |= OPENSUBDIV_EVALUATOR_GLSL_COMPUTE;
+ }
+#endif
+
+ return flags;
+}
+
+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 +
+ OPENSUBDIV_VERSION_PATCH;
+#elif defined(OPENSUBDIV_VERSION)
+ const char* version = STRINGIFY(OPENSUBDIV_VERSION);
+ if (version[0] == 'v') {
+ version += 1;
+ }
+ int major = 0, minor = 0, patch = 0;
+ vector<string> tokens;
+ opensubdiv_capi::stringSplit(&tokens, version, "_", true);
+ if (tokens.size() == 3) {
+ major = atoi(tokens[0].c_str());
+ minor = atoi(tokens[1].c_str());
+ patch = atoi(tokens[2].c_str());
+ }
+ return major * 10000 + minor * 100 + patch;
+#else
+ return 0;
+#endif
+}
diff --git a/intern/opensubdiv/internal/opensubdiv_converter_factory.cc b/intern/opensubdiv/internal/opensubdiv_converter_factory.cc
new file mode 100644
index 00000000000..bd6edbb9648
--- /dev/null
+++ b/intern/opensubdiv/internal/opensubdiv_converter_factory.cc
@@ -0,0 +1,438 @@
+// Copyright 2015 Blender Foundation. All rights reserved.
+//
+// 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.
+//
+// Author: Sergey Sharybin
+
+#ifdef _MSC_VER
+# include <iso646.h>
+#endif
+
+#include "internal/opensubdiv_converter_factory.h"
+
+#include <cassert>
+#include <cstdio>
+#include <stack>
+#include <vector>
+
+#include <opensubdiv/far/topologyRefinerFactory.h>
+
+#include "internal/opensubdiv_converter_internal.h"
+#include "internal/opensubdiv_converter_orient.h"
+#include "internal/opensubdiv_internal.h"
+#include "opensubdiv_converter_capi.h"
+
+struct TopologyRefinerData {
+ 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;
+ /// 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);
+ setNumBaseFaceVertices(refiner, face_index, num_face_vertices);
+ }
+ // Edges and edge-faces.
+ 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);
+ setNumBaseEdgeFaces(refiner, edge_index, num_edge_faces);
+ }
+ // Vertices and vertex-faces and vertex-edges.
+ const int num_vertices = converter->getNumVertices(converter);
+ setNumBaseVertices(refiner, num_vertices);
+ 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);
+ 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) {
+ using Far::IndexArray;
+ const OpenSubdiv_Converter* converter = cb_data.converter;
+ // Face relations.
+ const int num_faces = converter->getNumFaces(converter);
+ for (int face_index = 0; face_index < num_faces; ++face_index) {
+ IndexArray dst_face_verts = getBaseFaceVertices(refiner, face_index);
+ converter->getFaceVertices(converter, face_index, &dst_face_verts[0]);
+ IndexArray dst_face_edges = getBaseFaceEdges(refiner, face_index);
+ converter->getFaceEdges(converter, face_index, &dst_face_edges[0]);
+ }
+ // Edge relations.
+ const int num_edges = converter->getNumEdges(converter);
+ for (int edge_index = 0; edge_index < num_edges; ++edge_index) {
+ // Edge-vertices.
+ IndexArray dst_edge_vertices = getBaseEdgeVertices(refiner, edge_index);
+ converter->getEdgeVertices(converter, edge_index, &dst_edge_vertices[0]);
+ // Edge-faces.
+ IndexArray dst_edge_faces = getBaseEdgeFaces(refiner, edge_index);
+ converter->getEdgeFaces(converter, edge_index, &dst_edge_faces[0]);
+ }
+// TODO(sergey): Find a way to move this to an utility function.
+#ifdef OPENSUBDIV_ORIENT_TOPOLOGY
+ // Make face normals consistent.
+ std::vector<bool> face_used(num_faces, false);
+ std::stack<int> traverse_stack;
+ int face_start = 0, num_trave
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list