diff options
author | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2022-05-24 06:02:57 +0300 |
---|---|---|
committer | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2022-05-24 06:02:57 +0300 |
commit | cd968a32739587a5baacdd278a670d44570cbd8a (patch) | |
tree | 33ef22c30e0352fdc2ea073847bcc1342ebc3dfc /source/blender/draw/intern/draw_attributes.cc | |
parent | 64a5a7ade1e98234247a4140c182423ebc616d26 (diff) |
EEVEE: support Curves attributes rendering
This adds support to render Curves attributes in EEVEE.
Each attribute is stored in a texture derived from a VBO. As the
shading group needs the textures to be valid upon creation, the
attributes are created and setup during its very creation, instead
of doing it lazily via create_requested which we cannot rely on
anyway as contrary to the mesh batch, we do cannot really tell if
attributes need to be updated or else via some `DRW_batch_requested`.
Since point attributes need refinement, and since attributes are all
cast to vec4/float4 to account for differences in type conversions
between Blender and OpenGL, the refinement shader for points is
used as is. The point attributes are stored for each subdivision level
in CurvesEvalFinalCache. Each subdivision level also keeps track of the
attributes already in use so they are properly updated when needed.
Some basic garbage collection was added similar to what is done
for meshes: if the attributes used over time have been different
from the currently used attributes for too long, then the buffers
are freed, ensuring that stale attributesare removed.
This adds `CurvesInfos` to the shader creation info, which stores
the scope in which the attributes are defined. Scopes are stored
as booleans, in an array indexed by attribute loading order which
is also the order in which the attributes were added to the material.
A mapping is necessary between the indices used for the scoping, and
the ones used in the Curves cache, as this may contain stale
attributes which have not been garbage collected yet.
Common utilities with the mesh code for handling requested
attributes were moved to a separate file.
Differential Revision: https://developer.blender.org/D14916
Diffstat (limited to 'source/blender/draw/intern/draw_attributes.cc')
-rw-r--r-- | source/blender/draw/intern/draw_attributes.cc | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/source/blender/draw/intern/draw_attributes.cc b/source/blender/draw/intern/draw_attributes.cc new file mode 100644 index 00000000000..714f1dbb3d1 --- /dev/null +++ b/source/blender/draw/intern/draw_attributes.cc @@ -0,0 +1,112 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later + * Copyright 2022 Blender Foundation. All rights reserved. */ + +#include "draw_attributes.h" + +/* Return true if the given DRW_AttributeRequest is already in the requests. */ +static bool drw_attributes_has_request(const DRW_Attributes *requests, DRW_AttributeRequest req) +{ + for (int i = 0; i < requests->num_requests; i++) { + const DRW_AttributeRequest src_req = requests->requests[i]; + if (src_req.domain != req.domain) { + continue; + } + if (src_req.layer_index != req.layer_index) { + continue; + } + if (src_req.cd_type != req.cd_type) { + continue; + } + return true; + } + return false; +} + +static void drw_attributes_merge_requests(const DRW_Attributes *src_requests, + DRW_Attributes *dst_requests) +{ + for (int i = 0; i < src_requests->num_requests; i++) { + if (dst_requests->num_requests == GPU_MAX_ATTR) { + return; + } + + if (drw_attributes_has_request(dst_requests, src_requests->requests[i])) { + continue; + } + + dst_requests->requests[dst_requests->num_requests] = src_requests->requests[i]; + dst_requests->num_requests += 1; + } +} + +void drw_attributes_clear(DRW_Attributes *attributes) +{ + memset(attributes, 0, sizeof(DRW_Attributes)); +} + +void drw_attributes_merge(DRW_Attributes *dst, + const DRW_Attributes *src, + ThreadMutex *render_mutex) +{ + BLI_mutex_lock(render_mutex); + drw_attributes_merge_requests(src, dst); + BLI_mutex_unlock(render_mutex); +} + +bool drw_attributes_overlap(const DRW_Attributes *a, const DRW_Attributes *b) +{ + for (int i = 0; i < b->num_requests; i++) { + if (!drw_attributes_has_request(a, b->requests[i])) { + return false; + } + } + + return true; +} + +DRW_AttributeRequest *drw_attributes_add_request(DRW_Attributes *attrs, + CustomDataType type, + int layer, + AttributeDomain domain) +{ + if (attrs->num_requests >= GPU_MAX_ATTR) { + return nullptr; + } + + DRW_AttributeRequest *req = &attrs->requests[attrs->num_requests]; + req->cd_type = type; + req->layer_index = layer; + req->domain = domain; + attrs->num_requests += 1; + return req; +} + +bool drw_custom_data_match_attribute(const CustomData *custom_data, + const char *name, + int *r_layer_index, + int *r_type) +{ + const int possible_attribute_types[7] = { + CD_PROP_BOOL, + CD_PROP_INT8, + CD_PROP_INT32, + CD_PROP_FLOAT, + CD_PROP_FLOAT2, + CD_PROP_FLOAT3, + CD_PROP_COLOR, + }; + + for (int i = 0; i < ARRAY_SIZE(possible_attribute_types); i++) { + const int attr_type = possible_attribute_types[i]; + int layer_index = CustomData_get_named_layer(custom_data, attr_type, name); + if (layer_index == -1) { + continue; + } + + *r_layer_index = layer_index; + *r_type = attr_type; + return true; + } + + return false; +} |