| 1 |
/*************************************************************************** |
| 2 |
* Copyright (C) 2005-2019 by the FIFE team * |
| 3 |
* http://www.fifengine.net * |
| 4 |
* This file is part of FIFE. * |
| 5 |
* * |
| 6 |
* FIFE is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Lesser General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2.1 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
| 14 |
* Lesser General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Lesser General Public * |
| 17 |
* License along with this library; if not, write to the * |
| 18 |
* Free Software Foundation, Inc., * |
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
| 20 |
***************************************************************************/ |
| 21 |
|
| 22 |
#ifndef FIFE_TARGETRENDERER_H |
| 23 |
#define FIFE_TARGETRENDERER_H |
| 24 |
|
| 25 |
// Standard C++ library includes |
| 26 |
|
| 27 |
// 3rd party library includes |
| 28 |
|
| 29 |
// FIFE includes |
| 30 |
// These includes are split up in two parts, separated by one empty line |
| 31 |
// First block: files included from the FIFE root src directory |
| 32 |
// Second block: files included from the same folder |
| 33 |
#include "view/renderers/offrenderer.h" |
| 34 |
|
| 35 |
namespace FIFE { |
| 36 |
|
| 37 |
class RenderTarget { |
| 38 |
friend class TargetRenderer; |
| 39 |
public: |
| 40 |
/** Destructor. |
| 41 |
*/ |
| 42 |
~RenderTarget(); |
| 43 |
|
| 44 |
void addLine(const std::string &group, Point n1, Point n2, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255); |
| 45 |
void addPoint(const std::string &group, Point n, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255); |
| 46 |
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); |
| 47 |
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); |
| 48 |
void addVertex(const std::string &group, Point n, int32_t size, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255); |
| 49 |
void addText(const std::string &group, Point n, IFont* font, const std::string &text); |
| 50 |
void addImage(const std::string &group, Point n, ImagePtr image); |
| 51 |
void addAnimation(const std::string &group, Point n, AnimationPtr animation); |
| 52 |
void resizeImage(const std::string &group, Point n, ImagePtr image, int32_t width, int32_t height); |
| 53 |
void removeAll(const std::string &group); |
| 54 |
void removeAll(); |
| 55 |
void render(); |
| 56 |
|
| 57 |
ImagePtr getTarget() { return m_target; } |
| 58 |
private: |
| 59 |
RenderTarget(RenderBackend* rb, const std::string& name, uint32_t width, uint32_t height); |
| 60 |
RenderTarget(RenderBackend* rb, ImagePtr& image); |
| 61 |
|
| 62 |
// Non copyable |
| 63 |
RenderTarget(const RenderTarget& rhs); /* = delete */ |
| 64 |
RenderTarget& operator=(const RenderTarget& rhs); /* = delete */ |
| 65 |
|
| 66 |
std::map<std::string, std::vector<OffRendererElementInfo*> > m_groups; |
| 67 |
RenderBackend* m_renderbackend; |
| 68 |
ImagePtr m_target; |
| 69 |
}; |
| 70 |
typedef SharedPtr<RenderTarget> RenderTargetPtr; |
| 71 |
|
| 72 |
class TargetRenderer { |
| 73 |
public: |
| 74 |
/** Constructor. |
| 75 |
* @param renderbackend to use |
| 76 |
*/ |
| 77 |
TargetRenderer(RenderBackend* renderbackend); |
| 78 |
|
| 79 |
/** Destructor. |
| 80 |
*/ |
| 81 |
virtual ~TargetRenderer(); |
| 82 |
|
| 83 |
/** Creates render target |
| 84 |
*/ |
| 85 |
RenderTargetPtr createRenderTarget(const std::string& name, uint32_t width, uint32_t height); |
| 86 |
RenderTargetPtr createRenderTarget(ImagePtr& image); |
| 87 |
|
| 88 |
// -1 - dont render |
| 89 |
// 0 - just for the next frame |
| 90 |
// 1 - every frame |
| 91 |
// 2 - every two frames, etc... |
| 92 |
void setRenderTarget(const std::string& targetname, bool discard, int32_t ndraws = 0); |
| 93 |
void render(); |
| 94 |
|
| 95 |
private: |
| 96 |
struct RenderJob { |
| 97 |
int32_t ndraws; |
| 98 |
int32_t lasttime_draw; |
| 99 |
RenderTargetPtr target; |
| 100 |
bool discard; |
| 101 |
}; |
| 102 |
typedef std::map<std::string, RenderJob> RenderJobMap; |
| 103 |
RenderJobMap m_targets; |
| 104 |
RenderBackend* m_renderbackend; |
| 105 |
}; |
| 106 |
|
| 107 |
} |
| 108 |
|
| 109 |
#endif |