1 //  SuperTuxKart - a fun racing game with go-kart
2 //  Copyright (C) 2015 SuperTuxKart-Team
3 //
4 //  This program is free software; you can redistribute it and/or
5 //  modify it under the terms of the GNU General Public License
6 //  as published by the Free Software Foundation; either version 3
7 //  of the License, or (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program; if not, write to the Free Software
16 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17 
18 #ifndef HEADER_ABSTRACT_RENDERER_HPP
19 #define HEADER_ABSTRACT_RENDERER_HPP
20 
21 #include "graphics/gl_headers.hpp"
22 #include <irrlicht.h>
23 #include <memory>
24 #include <string>
25 #include <vector>
26 
27 class RenderTarget;
28 
29 enum TypeRTT : unsigned int;
30 
31 struct GlowData {
32     irr::scene::ISceneNode * node;
33     float r, g, b;
34 };
35 
36 struct SHCoefficients;
37 
38 /**
39  *  \class AbstractRenderer
40  *  \brief Virtual base class for the renderer
41  *
42  *  \ingroup graphics
43  */
44 class AbstractRenderer
45 {
46 protected:
47     irr::core::vector2df m_current_screen_size;
48 
49 #ifdef DEBUG
50     void drawDebugMeshes() const;
51 
52     void drawJoint(bool drawline, bool drawname,
53                    irr::scene::ISkinnedMesh::SJoint* joint,
54                    irr::scene::ISkinnedMesh* mesh, int id) const;
55 #endif
56 
57     void renderSkybox(const irr::scene::ICameraSceneNode *camera) const;
58 
59 public:
AbstractRenderer()60     AbstractRenderer() {}
~AbstractRenderer()61     virtual ~AbstractRenderer(){}
62 
63     virtual void onLoadWorld()   = 0;
64     virtual void onUnloadWorld() = 0;
65 
resetPostProcessing()66     virtual void resetPostProcessing() {}
giveBoost(unsigned int cam_index)67     virtual void giveBoost(unsigned int cam_index) {}
68 
addSkyBox(const std::vector<irr::video::ITexture * > & texture,const std::vector<irr::video::ITexture * > & spherical_harmonics_textures)69     virtual void addSkyBox(const std::vector<irr::video::ITexture*> &texture,
70                            const std::vector<irr::video::ITexture*> &spherical_harmonics_textures) {}
removeSkyBox()71     virtual void removeSkyBox() {}
72 
73     //FIXME: these three methods should not appear in the public Renderer interface
getSHCoefficients() const74     virtual const SHCoefficients* getSHCoefficients()    const { return NULL; }
getRenderTargetTexture(TypeRTT which) const75     virtual GLuint getRenderTargetTexture(TypeRTT which) const { return 0;}
getDepthStencilTexture() const76     virtual GLuint getDepthStencilTexture(             ) const { return 0;}
77 
setAmbientLight(const irr::video::SColorf & light,bool force_SH_computation=true)78     virtual void setAmbientLight(const irr::video::SColorf &light,
79                                   bool force_SH_computation = true) {}
80 
addSunLight(const irr::core::vector3df & pos)81     virtual void addSunLight(const irr::core::vector3df &pos){}
82 
addGlowingNode(irr::scene::ISceneNode * n,float r=1.0f,float g=1.0f,float b=1.0f)83     virtual void addGlowingNode(irr::scene::ISceneNode *n,
84                                 float r = 1.0f, float g = 1.0f, float b = 1.0f) {}
85 
clearGlowingNodes()86     virtual void clearGlowingNodes() {}
87 
88     virtual void render(float dt, bool is_loading=false) = 0;
89 
90      // ------------------------------------------------------------------------
getCurrentScreenSize() const91     const irr::core::vector2df &getCurrentScreenSize() const
92     {
93         return m_current_screen_size;
94     }
95 
96     // ----------------------------------------------------------------------------
97     /** Create a RenderTarget (for rendering to a texture)
98      *  \param dimension The dimension of the texture
99      *  \param name A unique name for the render target
100      */
101     virtual std::unique_ptr<RenderTarget> createRenderTarget(const irr::core::dimension2du &dimension,
102                                                              const std::string &name) = 0;
createPostProcessing()103     virtual void createPostProcessing() {}
104 };
105 
106 #endif //HEADER_ABSTRACT_RENDERER_HPP
107