lightrenderer.h

00001 /***************************************************************************
00002  *   Copyright (C) 2005-2011 by the FIFE team                              *
00003  *   http://www.fifengine.de                                               *
00004  *   This file is part of FIFE.                                            *
00005  *                                                                         *
00006  *   FIFE is free software; you can redistribute it and/or                 *
00007  *   modify it under the terms of the GNU Lesser General Public            *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2.1 of the License, or (at your option) any later version.    *
00010  *                                                                         *
00011  *   This library is distributed in the hope that it will be useful,       *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00014  *   Lesser General Public License for more details.                       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with this library; if not, write to the                 *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
00020  ***************************************************************************/
00021 
00022 #ifndef FIFE_LIGHTRENDERER_H
00023 #define FIFE_LIGHTRENDERER_H
00024 
00025 // Standard C++ library includes
00026 #include <vector>
00027 
00028 // 3rd party library includes
00029 
00030 // FIFE includes
00031 // These includes are split up in two parts, separated by one empty line
00032 // First block: files included from the FIFE root src directory
00033 // Second block: files included from the same folder
00034 #include "model/structures/renderernode.h"
00035 #include "view/rendererbase.h"
00036 #include "video/animation.h"
00037 
00038 namespace FIFE {
00039     class RenderBackend;
00040     class IFont;
00041 
00042     class LightRendererElementInfo {
00043     public:
00044         LightRendererElementInfo(RendererNode n, int32_t src, int32_t dst);
00045         virtual ~LightRendererElementInfo() {};
00046 
00047         virtual void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend) = 0;
00048         virtual std::string getName() = 0;
00049 
00050         RendererNode* getNode() { return &m_anchor; };
00051         int32_t getSrcBlend() { return m_src; };
00052         int32_t getDstBlend() { return m_dst; };
00053 
00054         void setStencil(uint8_t stencil_ref);
00055         int32_t getStencil();
00056         void removeStencil();
00057 
00058         virtual std::vector<uint8_t> getColor() { return std::vector<uint8_t>(); };
00059         virtual float getRadius() { return 0; };
00060         virtual int32_t getSubdivisions() { return 0; };
00061         virtual float getXStretch() { return 0; };
00062         virtual float getYStretch() { return 0; };
00063     
00064     protected:
00065         RendererNode m_anchor;
00066         int32_t m_src;
00067         int32_t m_dst;
00068         bool m_stencil;
00069         uint8_t m_stencil_ref;
00070     };
00071 
00072     class LightRendererImageInfo : public LightRendererElementInfo {
00073     public:
00074         LightRendererImageInfo(RendererNode n, ImagePtr image, int32_t src, int32_t dst);
00075         virtual ~LightRendererImageInfo() {};
00076 
00077         virtual void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend);
00078         virtual std::string getName() { return "image"; };
00079         ImagePtr getImage() { return m_image; };
00080 
00081     private:
00082         ImagePtr m_image;
00083     };
00084 
00085     class LightRendererAnimationInfo : public LightRendererElementInfo {
00086     public:
00087         LightRendererAnimationInfo(RendererNode n, AnimationPtr animation, int32_t src, int32_t dst);
00088         virtual ~LightRendererAnimationInfo() {};
00089 
00090         virtual void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend);
00091         virtual std::string getName() { return "animation"; };
00092         AnimationPtr getAnimation() { return m_animation; };
00093 
00094     private:
00095         AnimationPtr m_animation;
00096         uint32_t m_start_time;
00097         float m_time_scale;
00098     };
00099 
00100     class LightRendererSimpleLightInfo : public LightRendererElementInfo {
00101     public:
00102         LightRendererSimpleLightInfo(RendererNode n, uint8_t intensity, float radius, int32_t subdivisions, float xstretch, float ystretch, uint8_t r, uint8_t g, uint8_t b, int32_t src, int32_t dst);
00103         virtual ~LightRendererSimpleLightInfo() {};
00104 
00105         virtual void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend);
00106         virtual std::string getName() { return "simple"; };
00107 
00108         std::vector<uint8_t> getColor();
00109         float getRadius() { return m_radius; };
00110         int32_t getSubdivisions() { return m_subdivisions; };
00111         float getXStretch() { return m_xstretch; };
00112         float getYStretch() { return m_ystretch; };
00113 
00114     private:
00115         uint8_t m_intensity;
00116         float m_radius;
00117         int32_t m_subdivisions;
00118         float m_xstretch;
00119         float m_ystretch;
00120         uint8_t m_red;
00121         uint8_t m_green;
00122         uint8_t m_blue;
00123     };
00124 
00125     class LightRendererResizeInfo : public LightRendererElementInfo {
00126     public:
00127         LightRendererResizeInfo(RendererNode n, ImagePtr image, int32_t width, int32_t height, int32_t src, int32_t dst);
00128         virtual ~LightRendererResizeInfo() {};
00129 
00130         virtual void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend);
00131         virtual std::string getName() { return "resize"; };
00132 
00133         ImagePtr getImage() { return m_image; };
00134 
00135     private:
00136         ImagePtr m_image;
00137         int32_t m_width;
00138         int32_t m_height;
00139     };
00140 
00141     class LightRenderer: public RendererBase {
00142     public:
00147         LightRenderer(RenderBackend* renderbackend, int32_t position);
00148 
00149         LightRenderer(const LightRenderer& old);
00150 
00151         RendererBase* clone();
00152 
00155         virtual ~LightRenderer();
00156         void render(Camera* cam, Layer* layer, RenderList& instances);
00157         std::string getName() { return "LightRenderer"; }
00158 
00161         static LightRenderer* getInstance(IRendererContainer* cnt);
00162 
00163         void addImage(const std::string &group, RendererNode n, ImagePtr image, int32_t src=-1, int32_t dst=-1);
00164         void addAnimation(const std::string &group, RendererNode n, AnimationPtr animation, int32_t src=-1, int32_t dst=-1);
00165         void addSimpleLight(const std::string &group, RendererNode n, uint8_t intensity, float radius, int32_t subdivisions, float xstretch, float ystretch, uint8_t r, uint8_t g, uint8_t b, int32_t src=-1, int32_t dst=-1);
00166         void resizeImage(const std::string &group, RendererNode n, ImagePtr image, int32_t width, int32_t height, int32_t src=-1, int32_t dst=-1);
00167         void addStencilTest(const std::string &group, uint8_t stencil_ref=0);
00168         void removeStencilTest(const std::string &group);
00169         std::list<std::string> getGroups();
00170         std::vector<LightRendererElementInfo*> getLightInfo(const std::string &group);
00171         void removeAll(const std::string &group);
00172         void removeAll();
00173         void reset();
00174 
00175     private:
00176         std::map<std::string, std::vector<LightRendererElementInfo*> > m_groups;
00177     };
00178 
00179 }
00180 
00181 #endif