targetrenderer.h

00001 /***************************************************************************
00002  *   Copyright (C) 2005-2011 by the FIFE team                              *
00003  *   http://www.fifengine.net                                              *
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_TARGETRENDERER_H
00023 #define FIFE_TARGETRENDERER_H
00024 
00025 // Standard C++ library includes
00026 
00027 // 3rd party library includes
00028 
00029 // FIFE includes
00030 // These includes are split up in two parts, separated by one empty line
00031 // First block: files included from the FIFE root src directory
00032 // Second block: files included from the same folder
00033 #include "view/renderers/offrenderer.h"
00034 
00035 namespace FIFE {
00036 
00037     class RenderTarget {
00038         friend class TargetRenderer;
00039     public:
00042         ~RenderTarget();
00043 
00044         void addLine(const std::string &group, Point n1, Point n2, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
00045         void addPoint(const std::string &group, Point n, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
00046         void addTriangle(const std::string &group, Point n1, Point n2, Point n3, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
00047         void addQuad(const std::string &group, Point n1, Point n2, Point n3, Point n4, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
00048         void addVertex(const std::string &group, Point n, int32_t size, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
00049         void addText(const std::string &group, Point n, IFont* font, const std::string &text);
00050         void addImage(const std::string &group, Point n, ImagePtr image);
00051         void addAnimation(const std::string &group, Point n, AnimationPtr animation);
00052         void resizeImage(const std::string &group, Point n, ImagePtr image, int32_t width, int32_t height);
00053         void removeAll(const std::string &group);
00054         void removeAll();
00055         void render();
00056 
00057         ImagePtr getTarget() { return m_target; }
00058     private:
00059         RenderTarget(RenderBackend* rb, const std::string& name, uint32_t width, uint32_t height);
00060         RenderTarget(RenderBackend* rb, ImagePtr& image);
00061 
00062         // Non copyable
00063         RenderTarget(const RenderTarget& rhs); /* = delete */
00064         RenderTarget& operator=(const RenderTarget& rhs); /* = delete */
00065 
00066         std::map<std::string, std::vector<OffRendererElementInfo*> > m_groups;
00067         RenderBackend* m_renderbackend;
00068         ImagePtr m_target;
00069     };
00070     typedef SharedPtr<RenderTarget> RenderTargetPtr;
00071 
00072     class TargetRenderer {
00073     public:
00077         TargetRenderer(RenderBackend* renderbackend);
00078 
00081         virtual ~TargetRenderer();
00082 
00085         RenderTargetPtr createRenderTarget(const std::string& name, uint32_t width, uint32_t height);
00086         RenderTargetPtr createRenderTarget(ImagePtr& image);
00087 
00088         // -1 - dont render
00089         // 0 - just for the next frame
00090         // 1 - every frame
00091         // 2 - every two frames, etc...
00092         void setRenderTarget(const std::string& targetname, bool discard, int32_t ndraws = 0);
00093         void render();
00094 
00095     private:
00096         struct RenderJob {
00097             int32_t ndraws;
00098             int32_t lasttime_draw;
00099             RenderTargetPtr target;
00100             bool discard;
00101         };
00102         typedef std::map<std::string, RenderJob> RenderJobMap;
00103         RenderJobMap m_targets;
00104         RenderBackend* m_renderbackend;
00105     };
00106 
00107 }
00108 
00109 #endif