1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#pragma once
#include "iimage.h"
#include "imodule.h"
#include "MapExpression.h"
#include "parser/DefTokeniser.h"
#include "string/case_conv.h"
namespace shaders
{
class SoundMapExpression :
public ISoundMapExpression,
public NamedBindable
{
private:
bool _waveform;
std::string _filePath;
const char* const SOUND_MAP_PLACEHOLDER = "soundmap.png";
const char* const SOUND_MAP_PLACEHOLDER_WAVE = "soundmap_wave.png";
public:
SoundMapExpression(bool waveform) :
_waveform(waveform)
{}
virtual bool isCubeMap() const override
{
return false;
}
virtual bool isWaveform() const override
{
return _waveform;
}
virtual std::string getExpressionString() override
{
return _filePath;
}
virtual std::string getIdentifier() const override
{
return isWaveform() ? "__soundMapWave__" : "__soundMap__";
}
virtual TexturePtr bindTexture(const std::string& name, Role) const override
{
auto imagePath = module::GlobalModuleRegistry().getApplicationContext().getBitmapsPath();
imagePath += isWaveform() ? SOUND_MAP_PLACEHOLDER_WAVE : SOUND_MAP_PLACEHOLDER;
auto img = GlobalImageLoader().imageFromFile(imagePath);
return img ? img->bindTexture(name) : TexturePtr();
}
static std::shared_ptr<SoundMapExpression> CreateForTokens(parser::DefTokeniser& tokeniser)
{
bool waveform = string::to_lower_copy(tokeniser.peek()) == "waveform";
return std::make_shared<SoundMapExpression>(waveform);
}
};
}
|