1 #ifndef OPENMW_COMPONENTS_SCENEUTIL_UTIL_H
2 #define OPENMW_COMPONENTS_SCENEUTIL_UTIL_H
3 
4 #include <osg/Matrix>
5 #include <osg/BoundingSphere>
6 #include <osg/Camera>
7 #include <osg/NodeCallback>
8 #include <osg/Texture2D>
9 #include <osg/Vec4f>
10 
11 #include <components/resource/resourcesystem.hpp>
12 
13 #include "statesetupdater.hpp"
14 
15 namespace SceneUtil
16 {
17     class GlowUpdater : public SceneUtil::StateSetUpdater
18     {
19     public:
20         GlowUpdater(int texUnit, const osg::Vec4f& color, const std::vector<osg::ref_ptr<osg::Texture2D> >& textures,
21             osg::Node* node, float duration, Resource::ResourceSystem* resourcesystem);
22 
23         void setDefaults(osg::StateSet *stateset) override;
24 
25         void removeTexture(osg::StateSet* stateset);
26         void apply(osg::StateSet *stateset, osg::NodeVisitor *nv) override;
27 
28         bool isPermanentGlowUpdater();
29 
30         bool isDone();
31 
32         void setColor(const osg::Vec4f& color);
33 
34         void setDuration(float duration);
35 
36     private:
37         int mTexUnit;
38         osg::Vec4f mColor;
39         osg::Vec4f mOriginalColor; // for restoring the color of a permanent glow after a temporary glow on the object finishes
40         std::vector<osg::ref_ptr<osg::Texture2D> > mTextures;
41         osg::Node* mNode;
42         float mDuration;
43         float mOriginalDuration; // for recording that this is originally a permanent glow if it is changed to a temporary one
44         float mStartingTime;
45         Resource::ResourceSystem* mResourceSystem;
46         bool mColorChanged;
47         bool mDone;
48     };
49 
50     // Transform a bounding sphere by a matrix
51     // based off private code in osg::Transform
52     // TODO: patch osg to make public
53     void transformBoundingSphere (const osg::Matrixf& matrix, osg::BoundingSphere& bsphere);
54 
55     osg::Vec4f colourFromRGB (unsigned int clr);
56 
57     osg::Vec4f colourFromRGBA (unsigned int value);
58 
59     float makeOsgColorComponent (unsigned int value, unsigned int shift);
60 
61     bool hasUserDescription(const osg::Node* node, const std::string pattern);
62 
63     osg::ref_ptr<GlowUpdater> addEnchantedGlow(osg::ref_ptr<osg::Node> node, Resource::ResourceSystem* resourceSystem, osg::Vec4f glowColor, float glowDuration=-1);
64 
65     // Alpha-to-coverage requires a multisampled framebuffer, so we need to set that up for RTTs
66     bool attachAlphaToCoverageFriendlyFramebufferToCamera(osg::Camera* camera, osg::Camera::BufferComponent buffer, osg::Texture* texture, unsigned int level = 0, unsigned int face = 0, bool mipMapGeneration = false);
67 }
68 
69 #endif
70