1 // SuperTuxKart - a fun racing game with go-kart 2 // Copyright (C) 2014-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_RENDER_TARGET_HPP 19 #define HEADER_RENDER_TARGET_HPP 20 21 #include <irrlicht.h> 22 #include <string> 23 24 class FrameBuffer; 25 class RTT; 26 class ShaderBasedRenderer; 27 28 class RenderTarget 29 { 30 public: ~RenderTarget()31 virtual ~RenderTarget() {} 32 33 virtual irr::core::dimension2du getTextureSize() const = 0; 34 35 virtual void renderToTexture(irr::scene::ICameraSceneNode* camera, float dt) = 0; 36 virtual void draw2DImage(const irr::core::rect<irr::s32>& dest_rect, 37 const irr::core::rect<irr::s32>* clip_rect, 38 const irr::video::SColor &colors, 39 bool use_alpha_channel_of_texture) const = 0; 40 }; 41 42 class GL1RenderTarget: public RenderTarget 43 { 44 private: 45 /** A pointer to texture on which a scene is rendered. Only used 46 * in between beginRenderToTexture() and endRenderToTexture calls. */ 47 irr::video::ITexture *m_render_target_texture; 48 49 /** Main node of the RTT scene */ 50 irr::scene::ISceneNode *m_rtt_main_node; 51 52 public: 53 GL1RenderTarget(const irr::core::dimension2du &dimension, 54 const std::string &name); 55 ~GL1RenderTarget(); 56 57 irr::core::dimension2du getTextureSize() const; 58 59 void renderToTexture(irr::scene::ICameraSceneNode* camera, float dt); 60 void draw2DImage(const irr::core::rect<irr::s32>& dest_rect, 61 const irr::core::rect<irr::s32>* clip_rect, 62 const irr::video::SColor &colors, 63 bool use_alpha_channel_of_texture) const; 64 65 }; 66 67 class GL3RenderTarget: public RenderTarget 68 { 69 private: 70 ShaderBasedRenderer* m_renderer; 71 std::string m_name; 72 RTT* m_rtts; 73 FrameBuffer* m_frame_buffer; 74 75 public: 76 GL3RenderTarget(const irr::core::dimension2du &dimension, 77 const std::string &name, 78 ShaderBasedRenderer *renderer); 79 ~GL3RenderTarget(); 80 void draw2DImage(const irr::core::rect<irr::s32>& dest_rect, 81 const irr::core::rect<irr::s32>* clip_rect, 82 const irr::video::SColor &colors, 83 bool use_alpha_channel_of_texture) const; 84 irr::core::dimension2du getTextureSize() const; 85 void renderToTexture(irr::scene::ICameraSceneNode* camera, float dt); setFrameBuffer(FrameBuffer * fb)86 void setFrameBuffer(FrameBuffer* fb) { m_frame_buffer = fb; } 87 88 }; 89 90 #endif 91