gobj: add Geom::get_animated_vertex_data() short-hand

This is a method for getting the animated vertex data that will keep working even if GeomVertexData::animate_vertices() gets deprecated due to #421 being fixed.
This commit is contained in:
rdb 2018-10-15 22:11:54 +02:00
parent 0131d1013b
commit bcc2e3e404
6 changed files with 32 additions and 12 deletions

View File

@ -1254,7 +1254,7 @@ compare_collider_to_geom(CollisionEntry &entry, const Geom *geom,
if (geom->get_primitive_type() == Geom::PT_polygons) {
Thread *current_thread = Thread::get_current_thread();
CPT(GeomVertexData) data = geom->get_vertex_data()->animate_vertices(true, current_thread);
CPT(GeomVertexData) data = geom->get_animated_vertex_data(true, current_thread);
GeomVertexReader vertex(data, InternalName::get_vertex());
int num_primitives = geom->get_num_primitives();

View File

@ -484,8 +484,7 @@ recompute_geom(Geom *geom, const LMatrix4 &rel_mat) {
const LMatrix4 &to_uv = _invert_uvs ? lens_to_uv_inverted : lens_to_uv;
// Iterate through all the vertices in the Geom.
CPT(GeomVertexData) vdata = geom->get_vertex_data(current_thread);
vdata = vdata->animate_vertices(true, current_thread);
CPT(GeomVertexData) vdata = geom->get_animated_vertex_data(true, current_thread);
CPT(GeomVertexFormat) vformat = vdata->get_format();
if (!vformat->has_column(_texcoord_name) || (_texcoord_3d && vformat->get_column(_texcoord_name)->get_num_components() < 3)) {
@ -507,7 +506,7 @@ recompute_geom(Geom *geom, const LMatrix4 &rel_mat) {
PT(GeomVertexData) modify_vdata = geom->modify_vertex_data();
// Maybe the vdata has animation that we should consider.
CPT(GeomVertexData) animated_vdata = geom->get_vertex_data(current_thread)->animate_vertices(true, current_thread);
CPT(GeomVertexData) animated_vdata = geom->get_animated_vertex_data(true, current_thread);
GeomVertexWriter texcoord(modify_vdata, _texcoord_name, current_thread);
GeomVertexWriter color(modify_vdata, current_thread);
@ -674,9 +673,8 @@ make_mesh_geom(const Geom *geom, Lens *lens, LMatrix4 &rel_mat) {
Thread *current_thread = Thread::get_current_thread();
PT(Geom) new_geom = geom->make_copy();
new_geom->set_vertex_data(new_geom->get_animated_vertex_data(false, current_thread));
PT(GeomVertexData) vdata = new_geom->modify_vertex_data();
new_geom->set_vertex_data(vdata->animate_vertices(false, current_thread));
vdata = new_geom->modify_vertex_data();
GeomVertexRewriter vertex(vdata, InternalName::get_vertex());
while (!vertex.is_at_end()) {
LVertex vert = vertex.get_data3();

View File

@ -286,6 +286,28 @@ make_nonindexed(bool composite_only) {
return num_changed;
}
/**
* Returns a GeomVertexData that represents the results of computing the
* vertex animation on the CPU for this Geom's vertex data.
*
* If there is no CPU-defined vertex animation on this object, this just
* returns the original object.
*
* If there is vertex animation, but the VertexTransform values have not
* changed since last time, this may return the same pointer it returned
* previously. Even if the VertexTransform values have changed, it may still
* return the same pointer, but with its contents modified (this is preferred,
* since it allows the graphics backend to update vertex buffers optimally).
*
* If force is false, this method may return immediately with stale data, if
* the vertex data is not completely resident. If force is true, this method
* will never return stale data, but may block until the data is available.
*/
CPT(GeomVertexData) Geom::
get_animated_vertex_data(bool force, Thread *current_thread) const {
return get_vertex_data()->animate_vertices(force, current_thread);
}
/**
* Replaces the ith GeomPrimitive object stored within the Geom with the new
* object.
@ -1311,8 +1333,7 @@ compute_internal_bounds(Geom::CData *cdata, Thread *current_thread) const {
int num_vertices = 0;
// Get the vertex data, after animation.
CPT(GeomVertexData) vertex_data = cdata->_data.get_read_pointer(current_thread);
vertex_data = vertex_data->animate_vertices(true, current_thread);
CPT(GeomVertexData) vertex_data = get_animated_vertex_data(true, current_thread);
// Now actually compute the bounding volume. We do this by using
// calc_tight_bounds to determine our box first.

View File

@ -85,6 +85,8 @@ PUBLISHED:
void offset_vertices(const GeomVertexData *data, int offset);
int make_nonindexed(bool composite_only);
CPT(GeomVertexData) get_animated_vertex_data(bool force, Thread *current_thread) const;
INLINE bool is_empty() const;
INLINE size_t get_num_primitives() const;

View File

@ -866,7 +866,7 @@ transfer_geom(GeomNode *geom_node, const InternalName *texcoord_name,
PT(Geom) geom = orig_geom->make_copy();
// Ensure that any vertex animation has been applied.
geom->set_vertex_data(geom->get_vertex_data(current_thread)->animate_vertices(true, current_thread));
geom->set_vertex_data(geom->get_animated_vertex_data(true, current_thread));
// Now get a modifiable pointer to the vertex data in the new Geom. This
// will actually perform a deep copy of the vertex data.

View File

@ -376,8 +376,7 @@ r_prepare_scene(GraphicsStateGuardianBase *gsg, const RenderState *node_state,
geom = transformer.premunge_geom(geom, munger);
// Prepare each of the vertex arrays in the munged Geom.
CPT(GeomVertexData) vdata = geom->get_vertex_data(current_thread);
vdata = vdata->animate_vertices(false, current_thread);
CPT(GeomVertexData) vdata = geom->get_animated_vertex_data(false, current_thread);
GeomVertexDataPipelineReader vdata_reader(vdata, current_thread);
int num_arrays = vdata_reader.get_num_arrays();
for (int i = 0; i < num_arrays; ++i) {
@ -474,7 +473,7 @@ calc_tight_bounds(LPoint3 &min_point, LPoint3 &max_point, bool &found_any,
for (gi = geoms->begin(); gi != geoms->end(); ++gi) {
CPT(Geom) geom = (*gi)._geom.get_read_pointer();
geom->calc_tight_bounds(min_point, max_point, found_any,
geom->get_vertex_data(current_thread)->animate_vertices(true, current_thread),
geom->get_animated_vertex_data(true, current_thread),
!next_transform->is_identity(), mat,
current_thread);
}