Properly handle buffer name hash collisions
[alure.git] / src / buffer.h
blob2ba3170a577b9e460661c388fe64834f71679b9d
1 #ifndef BUFFER_H
2 #define BUFFER_H
4 #include <algorithm>
6 #include "main.h"
8 namespace alure {
10 ALenum GetFormat(ChannelConfig chans, SampleType type);
12 class BufferImpl {
13 ContextImpl &mContext;
14 ALuint mId;
16 ALuint mFrequency;
17 ChannelConfig mChannelConfig;
18 SampleType mSampleType;
20 Vector<Source> mSources;
22 const String mName;
23 size_t mNameHash;
25 public:
26 BufferImpl(ContextImpl &context, ALuint id, ALuint freq, ChannelConfig config, SampleType type,
27 StringView name, size_t name_hash)
28 : mContext(context), mId(id), mFrequency(freq), mChannelConfig(config), mSampleType(type)
29 , mName(String(name)), mNameHash(name_hash)
30 { }
32 void cleanup();
34 ContextImpl &getContext() { return mContext; }
35 ALuint getId() const { return mId; }
37 void addSource(Source source) { mSources.push_back(source); }
38 void removeSource(Source source)
40 auto iter = std::find(mSources.cbegin(), mSources.cend(), source);
41 if(iter != mSources.cend()) mSources.erase(iter);
44 void load(ALuint frames, ALenum format, SharedPtr<Decoder> decoder, ContextImpl *ctx);
46 ALuint getLength() const;
48 ALuint getFrequency() const { return mFrequency; }
49 ChannelConfig getChannelConfig() const { return mChannelConfig; }
50 SampleType getSampleType() const { return mSampleType; }
52 ALuint getSize() const;
54 void setLoopPoints(ALuint start, ALuint end);
55 std::pair<ALuint,ALuint> getLoopPoints() const;
57 Vector<Source> getSources() const { return mSources; }
59 StringView getName() const { return mName; }
61 size_t getSourceCount() const { return mSources.size(); }
63 size_t getNameHash() const { return mNameHash; }
66 } // namespace alure
68 #endif /* BUFFER_H */