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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
#pragma once
#include <string>
#include <memory>
#include "ishaderexpression.h"
#include "NamedBindable.h"
#include "parser/DefTokeniser.h"
using parser::DefTokeniser;
namespace shaders
{
class MapExpression;
typedef std::shared_ptr<MapExpression> MapExpressionPtr;
/**
* \brief
* Abstract base class for map expressions.
*
* Map expression are recursive expressions that generate an image, such as
* "heightmap(addnormals(blah, bleh), 1).
*/
class MapExpression :
public IMapExpression,
public NamedBindable
{
public: /* INTERFACE METHODS */
virtual bool isCubeMap() const override
{
return false;
}
public:
/* BindableTexture interface */
TexturePtr bindTexture(const std::string& name, Role role) const override
{
ImagePtr img = getImage();
if (img)
return img->bindTexture(name, role);
else
return TexturePtr();
}
// Abstract method to be implemented
virtual ImagePtr getImage() const = 0;
public: /* STATIC CONSTRUCTION METHODS */
/** Creates the a MapExpression out of the given token. Nested mapexpressions
* are recursively passed to child classes.
*/
static MapExpressionPtr createForToken(DefTokeniser& token);
static MapExpressionPtr createForString(const std::string& str);
protected:
/** greebo: Assures that the image is matching the desired dimensions.
*
* @input: The image to be rescaled. If it doesn't match <width x height>
* it is rescaled and the resampled image is returned.
*
* Note: The input image is removed from the heap after resampling
* and a new one is allocated and returned.
*
* @returns: the resampled image, this might as well be input.
*/
static ImagePtr getResampled(const ImagePtr& input, std::size_t width, std::size_t height);
};
// the specific MapExpressions
class HeightMapExpression :
public MapExpression
{
MapExpressionPtr heightMapExp;
float scale;
public:
HeightMapExpression(DefTokeniser& token);
ImagePtr getImage() const override;
std::string getIdentifier() const override;
std::string getExpressionString() override;
};
class AddNormalsExpression :
public MapExpression
{
MapExpressionPtr mapExpOne;
MapExpressionPtr mapExpTwo;
public:
AddNormalsExpression(DefTokeniser& token);
ImagePtr getImage() const override;
std::string getIdentifier() const override;
std::string getExpressionString() override;
};
class SmoothNormalsExpression :
public MapExpression
{
MapExpressionPtr mapExp;
public:
SmoothNormalsExpression(DefTokeniser& token);
ImagePtr getImage() const override;
std::string getIdentifier() const override;
std::string getExpressionString() override;
};
class AddExpression : public MapExpression {
MapExpressionPtr mapExpOne;
MapExpressionPtr mapExpTwo;
public:
AddExpression(DefTokeniser& token);
ImagePtr getImage() const override;
std::string getIdentifier() const override;
std::string getExpressionString() override;
};
class ScaleExpression :
public MapExpression
{
MapExpressionPtr mapExp;
float scaleRed;
float scaleGreen;
float scaleBlue;
float scaleAlpha;
public:
ScaleExpression(DefTokeniser& token);
ImagePtr getImage() const override;
std::string getIdentifier() const override;
std::string getExpressionString() override;
};
class InvertAlphaExpression :
public MapExpression
{
MapExpressionPtr mapExp;
public:
InvertAlphaExpression(DefTokeniser& token);
ImagePtr getImage() const override;
std::string getIdentifier() const override;
std::string getExpressionString() override;
};
class InvertColorExpression :
public MapExpression
{
MapExpressionPtr mapExp;
public:
InvertColorExpression(DefTokeniser& token);
ImagePtr getImage() const;
std::string getIdentifier() const;
std::string getExpressionString() override;
};
class MakeIntensityExpression :
public MapExpression
{
MapExpressionPtr mapExp;
public:
MakeIntensityExpression(DefTokeniser& token);
ImagePtr getImage() const override;
std::string getIdentifier() const override;
std::string getExpressionString() override;
};
class MakeAlphaExpression :
public MapExpression
{
MapExpressionPtr mapExp;
public:
MakeAlphaExpression(DefTokeniser& token);
ImagePtr getImage() const override;
std::string getIdentifier() const override;
std::string getExpressionString() override;
};
/**
* \brief
* MapExpression consisting of a single image name.
*
* This is found at the core of all map expressions.
*/
class ImageExpression
: public MapExpression
{
private:
std::string _imgName;
public:
ImageExpression(const std::string& imgName);
ImagePtr getImage() const override;
std::string getIdentifier() const override;
std::string getExpressionString() override;
};
} // namespace shaders
|