[Bf-blender-cvs] [b5fda893ced] functions: add byte attribute type
Jacques Lucke
noreply at git.blender.org
Sun Jun 9 13:52:49 CEST 2019
Commit: b5fda893ced0a2bf8df34a8ca27a1e456e886464
Author: Jacques Lucke
Date: Sun Jun 9 13:51:37 2019 +0200
Branches: functions
https://developer.blender.org/rBb5fda893ced0a2bf8df34a8ca27a1e456e886464
add byte attribute type
===================================================================
M source/blender/simulations/bparticles/c_wrapper.cpp
M source/blender/simulations/bparticles/core.hpp
M source/blender/simulations/bparticles/particles_container.cpp
M source/blender/simulations/bparticles/particles_container.hpp
M source/blender/simulations/bparticles/playground_solver.cpp
===================================================================
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 884e3188e8d..9f8dadeae1d 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -14,7 +14,6 @@
return (T2)value; \
}
-using BParticles::AttributeType;
using BParticles::Description;
using BParticles::EmitterBuffers;
using BParticles::EmitterInfoBuilder;
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index a5492f62d7b..ce292d21853 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -25,17 +25,13 @@ using BLI::StringRef;
using BLI::Vec3;
using std::unique_ptr;
-enum AttributeType {
- Float = 1,
- Vector3 = 2,
-};
-
class NamedBuffers {
public:
virtual ~NamedBuffers();
virtual uint size() = 0;
virtual ArrayRef<float> float_buffer(StringRef name) = 0;
virtual ArrayRef<Vec3> vec3_buffer(StringRef name) = 0;
+ virtual ArrayRef<uint8_t> byte_buffer(StringRef name) = 0;
};
class Force {
@@ -75,6 +71,11 @@ class EmitterBuffers {
return m_buffers.vec3_buffer(name);
}
+ ArrayRef<uint8_t> byte_buffer(StringRef name)
+ {
+ return m_buffers.byte_buffer(name);
+ }
+
uint size()
{
return m_buffers.size();
@@ -90,6 +91,7 @@ class EmitterInfo {
Emitter *m_emitter;
SmallSetVector<std::string> m_used_float_attributes;
SmallSetVector<std::string> m_used_vec3_attributes;
+ SmallSetVector<std::string> m_used_byte_attributes;
friend EmitterInfoBuilder;
@@ -109,6 +111,11 @@ class EmitterInfo {
return m_used_vec3_attributes.values();
}
+ ArrayRef<std::string> used_byte_attributes()
+ {
+ return m_used_byte_attributes.values();
+ }
+
bool uses_float_attribute(StringRef name)
{
return m_used_float_attributes.contains(name.to_std_string());
diff --git a/source/blender/simulations/bparticles/particles_container.cpp b/source/blender/simulations/bparticles/particles_container.cpp
index b15bc27fc09..19e74873a24 100644
--- a/source/blender/simulations/bparticles/particles_container.cpp
+++ b/source/blender/simulations/bparticles/particles_container.cpp
@@ -5,22 +5,27 @@ namespace BParticles {
ParticlesBlock::ParticlesBlock(ParticlesContainer &container,
ArrayRef<float *> float_buffers,
ArrayRef<Vec3 *> vec3_buffers,
+ ArrayRef<uint8_t *> byte_buffers,
uint active_amount)
: m_container(container),
m_float_buffers(float_buffers.to_small_vector()),
m_vec3_buffers(vec3_buffers.to_small_vector()),
+ m_byte_buffers(byte_buffers.to_small_vector()),
m_active_amount(active_amount)
{
- BLI_assert(m_float_buffers.size() == container.float_attribute_amount());
- BLI_assert(m_vec3_buffers.size() == container.vec3_attribute_amount());
+ BLI_assert(m_float_buffers.size() == container.float_attribute_names().size());
+ BLI_assert(m_vec3_buffers.size() == container.vec3_attribute_names().size());
+ BLI_assert(m_byte_buffers.size() == container.byte_attribute_names().size());
}
ParticlesContainer::ParticlesContainer(uint block_size,
ArrayRef<std::string> float_attribute_names,
- ArrayRef<std::string> vec3_attribute_names)
+ ArrayRef<std::string> vec3_attribute_names,
+ ArrayRef<std::string> byte_attribute_names)
: m_block_size(block_size),
m_float_attribute_names(float_attribute_names.to_small_vector()),
- m_vec3_attribute_names(vec3_attribute_names.to_small_vector())
+ m_vec3_attribute_names(vec3_attribute_names.to_small_vector()),
+ m_byte_attribute_names(byte_attribute_names.to_small_vector())
{
BLI_assert(
SmallSetVector<std::string>::Disjoint(m_float_attribute_names, m_vec3_attribute_names));
@@ -45,7 +50,11 @@ ParticlesBlock *ParticlesContainer::new_block()
for (uint i = 0; i < m_vec3_attribute_names.size(); i++) {
vec3_buffers.append((Vec3 *)MEM_malloc_arrayN(m_block_size, sizeof(Vec3), __func__));
}
- ParticlesBlock *block = new ParticlesBlock(*this, float_buffers, vec3_buffers);
+ SmallVector<uint8_t *> byte_buffers;
+ for (uint i = 0; i < m_byte_attribute_names.size(); i++) {
+ byte_buffers.append((uint8_t *)MEM_malloc_arrayN(m_block_size, sizeof(uint8_t), __func__));
+ }
+ ParticlesBlock *block = new ParticlesBlock(*this, float_buffers, vec3_buffers, byte_buffers);
m_blocks.add_new(block);
return block;
}
@@ -63,6 +72,9 @@ void ParticlesContainer::release_block(ParticlesBlock *block)
for (Vec3 *buffer : block->vec3_buffers()) {
MEM_freeN((void *)buffer);
}
+ for (uint8_t *buffer : block->byte_buffers()) {
+ MEM_freeN((void *)buffer);
+ }
m_blocks.remove(block);
delete block;
}
@@ -80,7 +92,6 @@ static void move_buffers(ArrayRef<T *> from_buffers,
}
}
-/* TODO: test if this actually works */
void ParticlesBlock::MoveUntilFull(ParticlesBlock *from, ParticlesBlock *to)
{
BLI_assert(&from->container() == &to->container());
@@ -95,12 +106,13 @@ void ParticlesBlock::MoveUntilFull(ParticlesBlock *from, ParticlesBlock *to)
move_buffers<float>(
from->float_buffers(), to->float_buffers(), src_start, dst_start, move_amount);
move_buffers<Vec3>(from->vec3_buffers(), to->vec3_buffers(), src_start, dst_start, move_amount);
+ move_buffers<uint8_t>(
+ from->byte_buffers(), to->byte_buffers(), src_start, dst_start, move_amount);
from->active_amount() -= move_amount;
to->active_amount() += move_amount;
}
-/* TODO: test if this actually works */
void ParticlesBlock::Compress(ArrayRef<ParticlesBlock *> blocks)
{
std::sort(blocks.begin(), blocks.end(), [](ParticlesBlock *a, ParticlesBlock *b) {
diff --git a/source/blender/simulations/bparticles/particles_container.hpp b/source/blender/simulations/bparticles/particles_container.hpp
index 47b901a388e..79655061014 100644
--- a/source/blender/simulations/bparticles/particles_container.hpp
+++ b/source/blender/simulations/bparticles/particles_container.hpp
@@ -26,22 +26,27 @@ class ParticlesContainer {
uint m_block_size;
SmallSetVector<std::string> m_float_attribute_names;
SmallSetVector<std::string> m_vec3_attribute_names;
+ SmallSetVector<std::string> m_byte_attribute_names;
SmallSet<ParticlesBlock *> m_blocks;
public:
ParticlesContainer(uint block_size,
ArrayRef<std::string> float_attribute_names,
- ArrayRef<std::string> vec3_attribute_names);
+ ArrayRef<std::string> vec3_attribute_names,
+ ArrayRef<std::string> byte_attribute_names);
~ParticlesContainer();
uint block_size() const;
+
SmallSetVector<std::string> &float_attribute_names();
SmallSetVector<std::string> &vec3_attribute_names();
- uint float_attribute_amount() const;
- uint vec3_attribute_amount() const;
+ SmallSetVector<std::string> &byte_attribute_names();
+
uint float_buffer_index(StringRef name) const;
uint vec3_buffer_index(StringRef name) const;
+ uint byte_buffer_index(StringRef name) const;
+
const SmallSet<ParticlesBlock *> &active_blocks();
ParticlesBlock *new_block();
@@ -59,8 +64,10 @@ class ParticlesBlockSlice : public NamedBuffers {
ParticlesBlock *block();
uint size() override;
+
ArrayRef<float> float_buffer(StringRef name) override;
ArrayRef<Vec3> vec3_buffer(StringRef name) override;
+ ArrayRef<uint8_t> byte_buffer(StringRef name) override;
ParticlesBlockSlice take_front(uint n);
};
@@ -69,12 +76,14 @@ class ParticlesBlock {
ParticlesContainer &m_container;
SmallVector<float *> m_float_buffers;
SmallVector<Vec3 *> m_vec3_buffers;
+ SmallVector<uint8_t *> m_byte_buffers;
uint m_active_amount;
public:
ParticlesBlock(ParticlesContainer &container,
ArrayRef<float *> float_buffers,
ArrayRef<Vec3 *> vec3_buffers,
+ ArrayRef<uint8_t *> byte_buffers,
uint active_amount = 0);
uint &active_amount();
@@ -90,8 +99,11 @@ class ParticlesBlock {
ArrayRef<float *> float_buffers();
ArrayRef<Vec3 *> vec3_buffers();
+ ArrayRef<uint8_t *> byte_buffers();
+
float *float_buffer(StringRef name);
Vec3 *vec3_buffer(StringRef name);
+ uint8_t *byte_buffer(StringRef name);
ParticlesBlockSlice slice(uint start, uint length);
ParticlesBlockSlice slice_all();
@@ -121,14 +133,9 @@ inline SmallSetVector<std::string> &ParticlesContainer::vec3_attribute_names()
return m_vec3_attribute_names;
}
-inline uint ParticlesContainer::float_attribute_amount() const
-{
- return m_float_attribute_names.size();
-}
-
-inline uint ParticlesContainer::vec3_attribute_amount() const
+inline SmallSetVector<std::string> &ParticlesContainer::byte_attribute_names()
{
- return m_vec3_attribute_names.size();
+ return m_byte_attribute_names;
}
inline uint ParticlesContainer::float_buffer_index(StringRef name) const
@@ -141,6 +148,11 @@ inline uint ParticlesContainer::vec3_buffer_index(StringRef name) const
return m_vec3_attribute_names.index(name.to_std_string());
}
+inline uint ParticlesContainer::byte_buffer_index(StringRef name) const
+{
+ return m_byte_attribute_names.index(name.to_std_string());
+}
+
inline const SmallSet<ParticlesBlock *> &ParticlesContainer::active_blocks()
{
return m_blocks;
@@ -199,12 +211,29 @@ inline ArrayRef<Vec3 *> ParticlesBlock::vec3_buffers()
return m_vec3_buffers;
}
+inline ArrayRef<uint8_t *> ParticlesBlock::byte_buffers()
+{
+ return m_byte_buffers;
+}
+
inline float *ParticlesBlock::float_buffer(StringRef name)
{
uint index = m_container.float_buffer_index(name);
return m_float_buffers[index];
}
+inline Vec3 *ParticlesBlock::vec3_buffer(StringRef name)
+{
+ uint index = m_container.vec3_buffer_index(name);
+ return m_vec3_buffers[index];
+}
+
+inline uint8_t *ParticlesBlock::byte_buffer(StringRef name)
+{
+ uint in
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list