#pragma once
#include "FloatPoint3D.h"
#include <wtf/RefCounted.h>
namespace WTF {
class TextStream;
}
namespace WebCore {
enum LightType {
LS_DISTANT,
LS_POINT,
LS_SPOT
};
class FilterEffect;
class LightSource : public RefCounted<LightSource> {
public:
struct ComputedLightingData {
FloatPoint3D lightVector;
FloatPoint3D colorVector;
float lightVectorLength;
};
struct PaintingData {
ComputedLightingData initialLightingData;
FloatPoint3D directionVector;
float coneCutOffLimit;
float coneFullLight;
int specularExponent;
};
LightSource(LightType type)
: m_type(type)
{ }
virtual ~LightSource() = default;
LightType type() const { return m_type; }
virtual WTF::TextStream& externalRepresentation(WTF::TextStream&) const = 0;
virtual void initPaintingData(const FilterEffect&, PaintingData&) = 0;
virtual ComputedLightingData computePixelLightingData(const PaintingData&, int x, int y, float z) const = 0;
virtual bool setAzimuth(float) { return false; }
virtual bool setElevation(float) { return false; }
virtual bool setX(float) { return false; }
virtual bool setY(float) { return false; }
virtual bool setZ(float) { return false; }
virtual bool setPointsAtX(float) { return false; }
virtual bool setPointsAtY(float) { return false; }
virtual bool setPointsAtZ(float) { return false; }
virtual bool setSpecularExponent(float) { return false; }
virtual bool setLimitingConeAngle(float) { return false; }
private:
LightType m_type;
};
}
#define SPECIALIZE_TYPE_TRAITS_LIGHTSOURCE(ClassName, Type) \
SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ClassName) \
static bool isType(const WebCore::LightSource& source) { return source.type() == WebCore::Type; } \
SPECIALIZE_TYPE_TRAITS_END()