Nebula
Loading...
Searching...
No Matches
envelopesamplebuffer.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
14
15//------------------------------------------------------------------------------
16namespace Particles
17{
19{
20public:
25
27 void Setup(const EmitterAttrs& emitterAttrs, SizeT numSamples);
29 void Discard();
31 bool IsValid() const;
32
34 IndexT AsSampleIndex(float t) const;
36 float* LookupSamples(IndexT sampleIndex) const;
38 SizeT GetNumSamples() const;
40 const float* GetSampleBuffer() const;
41
42private:
44 float* buffer;
45};
46
47//------------------------------------------------------------------------------
50inline bool
52{
53 return (0 != this->buffer);
54}
55
56//------------------------------------------------------------------------------
59inline IndexT
61{
62 IndexT index = IndexT(t / this->numSamples);
63
64 // make sure index is in valid range
65 index = Math::clamp(index, 0, this->numSamples - 1);
66 return index;
67}
68
69//------------------------------------------------------------------------------
72inline float*
74{
75 #if NEBULA_BOUNDSCHECKS
76 n_assert((sampleIndex >= 0) && (sampleIndex < this->numSamples));
77 n_assert(0 != buffer);
78 #endif
79 return this->buffer + (sampleIndex * EmitterAttrs::NumEnvelopeAttrs);
80}
81
82//------------------------------------------------------------------------------
85inline SizeT
87{
88 return this->numSamples;
89}
90
91//------------------------------------------------------------------------------
94inline const float*
96{
97 return this->buffer;
98}
99
100} // namespace Particles
101//------------------------------------------------------------------------------
102
A container for particle emitter attributes.
Definition emitterattrs.h:20
@ NumEnvelopeAttrs
Definition emitterattrs.h:93
A lookup table for pre-sampled envelope curves.
Definition envelopesamplebuffer.h:19
IndexT AsSampleIndex(float t) const
convert t-value (0.0 to 1.0) into a lookup index
Definition envelopesamplebuffer.h:60
SizeT numSamples
Definition envelopesamplebuffer.h:43
float * LookupSamples(IndexT sampleIndex) const
get pointer to samples, index into array by EmitterAttrs::EnvelopeAttr
Definition envelopesamplebuffer.h:73
EnvelopeSampleBuffer()
constructor
Definition envelopesamplebuffer.cc:15
bool IsValid() const
return true if object has been setup
Definition envelopesamplebuffer.h:51
const float * GetSampleBuffer() const
get the sample buffer
Definition envelopesamplebuffer.h:95
~EnvelopeSampleBuffer()
destructor
Definition envelopesamplebuffer.cc:25
SizeT GetNumSamples() const
get the number of samples per attribute
Definition envelopesamplebuffer.h:86
void Setup(const EmitterAttrs &emitterAttrs, SizeT numSamples)
setup the sample buffer
Definition envelopesamplebuffer.cc:37
void Discard()
discard the sample buffer
Definition envelopesamplebuffer.cc:59
float * buffer
Definition envelopesamplebuffer.h:44
#define n_assert(exp)
Definition debug.h:50
__forceinline float clamp(float val, float minVal, float maxVal)
Float clamping.
Definition scalar.h:487
Particle context controls playing and enabling/disabling of particle emitters inside a model.
Definition modelnode.h:37
int SizeT
Definition types.h:49
int IndexT
Definition types.h:48