This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/blenkernel/BKE_subdiv_foreach.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

166 lines
7.2 KiB
C++
Raw Normal View History

/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2018 Blender Foundation. All rights reserved. */
/** \file
* \ingroup bke
*/
#pragma once
#include "BLI_sys_types.h"
#ifdef __cplusplus
extern "C" {
#endif
struct Mesh;
struct Subdiv;
struct SubdivForeachContext;
struct SubdivToMeshSettings;
typedef bool (*SubdivForeachTopologyInformationCb)(const struct SubdivForeachContext *context,
int num_vertices,
int num_edges,
int num_loops,
int num_polygons,
OpenSubDiv: add support for an OpenGL evaluator This evaluator is used in order to evaluate subdivision at render time, allowing for faster renders of meshes with a subdivision surface modifier placed at the last position in the modifier list. When evaluating the subsurf modifier, we detect whether we can delegate evaluation to the draw code. If so, the subdivision is first evaluated on the GPU using our own custom evaluator (only the coarse data needs to be initially sent to the GPU), then, buffers for the final `MeshBufferCache` are filled on the GPU using a set of compute shaders. However, some buffers are still filled on the CPU side, if doing so on the GPU is impractical (e.g. the line adjacency buffer used for x-ray, whose logic is hardly GPU compatible). This is done at the mesh buffer extraction level so that the result can be readily used in the various OpenGL engines, without having to write custom geometry or tesselation shaders. We use our own subdivision evaluation shaders, instead of OpenSubDiv's vanilla one, in order to control the data layout, and interpolation. For example, we store vertex colors as compressed 16-bit integers, while OpenSubDiv's default evaluator only work for float types. In order to still access the modified geometry on the CPU side, for use in modifiers or transform operators, a dedicated wrapper type is added `MESH_WRAPPER_TYPE_SUBD`. Subdivision will be lazily evaluated via `BKE_object_get_evaluated_mesh` which will create such a wrapper if possible. If the final subdivision surface is not needed on the CPU side, `BKE_object_get_evaluated_mesh_no_subsurf` should be used. Enabling or disabling GPU subdivision can be done through the user preferences (under Viewport -> Subdivision). See patch description for benchmarks. Reviewed By: campbellbarton, jbakker, fclem, brecht, #eevee_viewport Differential Revision: https://developer.blender.org/D12406
2021-12-27 16:34:47 +01:00
const int *subdiv_polygon_offset);
typedef void (*SubdivForeachVertexFromCornerCb)(const struct SubdivForeachContext *context,
void *tls,
int ptex_face_index,
float u,
float v,
int coarse_vertex_index,
int coarse_poly_index,
int coarse_corner,
int subdiv_vertex_index);
typedef void (*SubdivForeachVertexFromEdgeCb)(const struct SubdivForeachContext *context,
void *tls,
int ptex_face_index,
float u,
float v,
int coarse_edge_index,
int coarse_poly_index,
int coarse_corner,
int subdiv_vertex_index);
typedef void (*SubdivForeachVertexInnerCb)(const struct SubdivForeachContext *context,
void *tls,
int ptex_face_index,
float u,
float v,
int coarse_poly_index,
int coarse_corner,
int subdiv_vertex_index);
typedef void (*SubdivForeachEdgeCb)(const struct SubdivForeachContext *context,
void *tls,
int coarse_edge_index,
int subdiv_edge_index,
bool is_loose,
int subdiv_v1,
int subdiv_v2);
typedef void (*SubdivForeachLoopCb)(const struct SubdivForeachContext *context,
void *tls,
int ptex_face_index,
float u,
float v,
int coarse_loop_index,
int coarse_poly_index,
int coarse_corner,
int subdiv_loop_index,
int subdiv_vertex_index,
int subdiv_edge_index);
typedef void (*SubdivForeachPolygonCb)(const struct SubdivForeachContext *context,
void *tls,
int coarse_poly_index,
int subdiv_poly_index,
int start_loop_index,
int num_loops);
typedef void (*SubdivForeachLooseCb)(const struct SubdivForeachContext *context,
void *tls,
int coarse_vertex_index,
int subdiv_vertex_index);
typedef void (*SubdivForeachVertexOfLooseEdgeCb)(const struct SubdivForeachContext *context,
void *tls,
int coarse_edge_index,
float u,
int subdiv_vertex_index);
typedef struct SubdivForeachContext {
/* Is called when topology information becomes available.
* Is only called once.
*
* NOTE: If this callback returns false, the foreach loop is aborted.
*/
SubdivForeachTopologyInformationCb topology_info;
/* These callbacks are called from every ptex which shares "emitting"
* vertex or edge.
*/
SubdivForeachVertexFromCornerCb vertex_every_corner;
SubdivForeachVertexFromEdgeCb vertex_every_edge;
/* Those callbacks are run once per subdivision vertex, ptex is undefined
2019-06-17 12:51:53 +10:00
* as in it will be whatever first ptex face happened to be traversed in
* the multi-threaded environment and which shares "emitting" vertex or
* edge.
*/
SubdivForeachVertexFromCornerCb vertex_corner;
SubdivForeachVertexFromEdgeCb vertex_edge;
/* Called exactly once, always corresponds to a single ptex face. */
SubdivForeachVertexInnerCb vertex_inner;
/* Called once for each loose vertex. One loose coarse vertex corresponds
* to a single subdivision vertex.
*/
SubdivForeachLooseCb vertex_loose;
/* Called once per vertex created for loose edge. */
SubdivForeachVertexOfLooseEdgeCb vertex_of_loose_edge;
/* NOTE: If subdivided edge does not come from coarse edge, ORIGINDEX_NONE
* will be passed as coarse_edge_index.
*/
SubdivForeachEdgeCb edge;
/* NOTE: If subdivided loop does not come from coarse loop, ORIGINDEX_NONE
* will be passed as coarse_loop_index.
*/
SubdivForeachLoopCb loop;
SubdivForeachPolygonCb poly;
/* User-defined pointer, to allow callbacks know something about context the
* traversal is happening for.
*/
void *user_data;
/* Initial value of TLS data. */
void *user_data_tls;
/* Size of TLS data. */
size_t user_data_tls_size;
/* Function to free TLS storage. */
void (*user_data_tls_free)(void *tls);
} SubdivForeachContext;
/* Invokes callbacks in the order and with values which corresponds to creation
* of final subdivided mesh.
*
2020-03-30 12:26:29 +02:00
* Main goal is to abstract all the traversal routines to give geometry element
* indices (for vertices, edges, loops, polygons) in the same way as subdivision
* modifier will do for a dense mesh.
*
* Returns true if the whole topology was traversed, without any early exits.
*
* TODO(sergey): Need to either get rid of subdiv or of coarse_mesh.
2019-06-17 12:51:53 +10:00
* The main point here is to be able to get base level topology, which can be
* done with either of those. Having both of them is kind of redundant.
*/
bool BKE_subdiv_foreach_subdiv_geometry(struct Subdiv *subdiv,
const struct SubdivForeachContext *context,
const struct SubdivToMeshSettings *mesh_settings,
const struct Mesh *coarse_mesh);
#ifdef __cplusplus
}
#endif