FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
renderbackendsdl.h
Go to the documentation of this file.
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_VIDEO_RENDERBACKENDS_SDL_RENDERBACKENDSDL_H
23 #define FIFE_VIDEO_RENDERBACKENDS_SDL_RENDERBACKENDSDL_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 "video/renderbackend.h"
34 
35 namespace FIFE {
36 
37  class ScreenMode;
38 
44  public:
45  RenderBackendSDL(const SDL_Color& colorkey);
46  virtual ~RenderBackendSDL();
47  virtual const std::string& getName() const;
48  virtual void startFrame();
49  virtual void endFrame();
50  virtual void init(const std::string& driver);
51  virtual void clearBackBuffer();
52  virtual void setLightingModel(uint32_t lighting);
53  virtual uint32_t getLightingModel() const;
54  virtual void setLighting(float red, float green, float blue);
55  virtual void resetLighting();
56  virtual void resetStencilBuffer(uint8_t buffer);
57  virtual void changeBlending(int32_t scr, int32_t dst);
58 
59  virtual void createMainScreen(const ScreenMode& mode, const std::string& title, const std::string& icon);
60  virtual void setScreenMode(const ScreenMode& mode);
61 
62  virtual Image* createImage(IResourceLoader* loader = 0);
63  virtual Image* createImage(const std::string& name, IResourceLoader* loader = 0);
64  virtual Image* createImage(const uint8_t* data, uint32_t width, uint32_t height);
65  virtual Image* createImage(const std::string& name, const uint8_t* data, uint32_t width, uint32_t height);
66  virtual Image* createImage(SDL_Surface* surface);
67  virtual Image* createImage(const std::string& name, SDL_Surface* surface);
68 
69  virtual void renderVertexArrays();
70  virtual void addImageToArray(uint32_t id, const Rect& rec, float const* st, uint8_t alpha, uint8_t const* rgba);
71  virtual void changeRenderInfos(RenderDataType type, uint16_t elements, int32_t src, int32_t dst, bool light, bool stentest, uint8_t stenref, GLConstants stenop, GLConstants stenfunc, OverlayType otype = OVERLAY_TYPE_NONE);
72  virtual void captureScreen(const std::string& filename);
73  virtual void captureScreen(const std::string& filename, uint32_t width, uint32_t height);
74 
75  virtual bool putPixel(int32_t x, int32_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
76  virtual void drawLine(const Point& p1, const Point& p2, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
77  virtual void drawThickLine(const Point& p1, const Point& p2, uint8_t width, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
78  virtual void drawPolyLine(const std::vector<Point>& points, uint8_t width, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
79  virtual void drawBezier(const std::vector<Point>& points, int32_t steps, uint8_t width, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
80  virtual void drawTriangle(const Point& p1, const Point& p2, const Point& p3, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
81  virtual void drawRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
82  virtual void fillRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
83  virtual void drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
84  virtual void drawVertex(const Point& p, const uint8_t size, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
85  virtual void drawCircle(const Point& p, uint32_t radius, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
86  virtual void drawFillCircle(const Point& p, uint32_t radius, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
87  virtual void drawCircleSegment(const Point& p, uint32_t radius, int32_t sangle, int32_t eangle, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
88  virtual void drawFillCircleSegment(const Point& p, uint32_t radius, int32_t sangle, int32_t eangle, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
89  virtual void drawLightPrimitive(const Point& p, uint8_t intensity, float radius, int32_t subdivisions, float xstretch, float ystretch, uint8_t red, uint8_t green, uint8_t blue);
90 
91  virtual void enableScissorTest();
92  virtual void disableScissorTest();
93 
94  virtual void attachRenderTarget(ImagePtr& img, bool discard);
95  virtual void detachRenderTarget();
96 
97  virtual void renderGuiGeometry(const std::vector<GuiVertex>& vertices, const std::vector<int>& indices, const DoublePoint& translation, ImagePtr texture);
98 
99  SDL_Renderer* getRenderer() { return m_renderer; }
100 
101  protected:
102  virtual void setClipArea(const Rect& cliparea, bool clear);
103 
104  SDL_Renderer* m_renderer;
105  };
106 
107 }
108 
109 #endif
virtual void renderGuiGeometry(const std::vector< GuiVertex > &vertices, const std::vector< int > &indices, const DoublePoint &translation, ImagePtr texture)
Renders geometry required by gui.
Abstract interface for all the renderbackends.
virtual void createMainScreen(const ScreenMode &mode, const std::string &title, const std::string &icon)
Creates the mainscreen (the display window).
virtual const std::string & getName() const
The name of the renderbackend.
virtual void drawFillCircleSegment(const Point &p, uint32_t radius, int32_t sangle, int32_t eangle, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws a filled circle segment.
Base Class for Images.
Definition: image.h:48
virtual void renderVertexArrays()
Render the Vertex Arrays, only for primitives (points, lines,...)
virtual void drawTriangle(const Point &p1, const Point &p2, const Point &p3, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws triangle between given points with given RGBA.
The main class of the SDL-based renderer.
virtual void resetStencilBuffer(uint8_t buffer)
Reset stencil buffer with given value.
virtual void drawFillCircle(const Point &p, uint32_t radius, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws a filled circle.
virtual void captureScreen(const std::string &filename)
Creates a Screenshot and saves it to a file.
SDL_Renderer * getRenderer()
virtual void setClipArea(const Rect &cliparea, bool clear)
Sets given clip area into image.
virtual void drawQuad(const Point &p1, const Point &p2, const Point &p3, const Point &p4, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws quad between given points with given RGBA.
virtual Image * createImage(IResourceLoader *loader=0)
virtual void disableScissorTest()
Disables scissor test on the render backend.
virtual void startFrame()
Called when a new frame starts.
virtual void setScreenMode(const ScreenMode &mode)
Sets the mainscreen display mode.
virtual bool putPixel(int32_t x, int32_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Writes pixel to given position.
unsigned char uint8_t
Definition: core.h:38
virtual void drawCircleSegment(const Point &p, uint32_t radius, int32_t sangle, int32_t eangle, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws a circle segment.
virtual void drawLightPrimitive(const Point &p, uint8_t intensity, float radius, int32_t subdivisions, float xstretch, float ystretch, uint8_t red, uint8_t green, uint8_t blue)
Draws a light primitive that based on a triangle fan.
virtual void drawRectangle(const Point &p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws an axis parallel rectangle.
RenderBackendSDL(const SDL_Color &colorkey)
virtual void drawBezier(const std::vector< Point > &points, int32_t steps, uint8_t width, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws bezier curve between given points with given RGBA and width.
virtual uint32_t getLightingModel() const
Gets the current light model.
virtual void detachRenderTarget()
Detaches current render surface.
virtual void resetLighting()
Reset lighting with default values.
virtual void changeRenderInfos(RenderDataType type, uint16_t elements, int32_t src, int32_t dst, bool light, bool stentest, uint8_t stenref, GLConstants stenop, GLConstants stenfunc, OverlayType otype=OVERLAY_TYPE_NONE)
Dirty helper function to change the render infos.
unsigned short uint16_t
Definition: core.h:39
virtual void fillRectangle(const Point &p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws a filled axis parallel rectangle.
virtual void clearBackBuffer()
Forces a clear of the backbuffer.
virtual void endFrame()
Called when a frame is finished and ready to be displayed.
virtual void changeBlending(int32_t scr, int32_t dst)
Change the Blendingmodel.
virtual void setLighting(float red, float green, float blue)
Set colors for lighting.
virtual void drawLine(const Point &p1, const Point &p2, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws line between given points with given RGBA.
virtual void drawPolyLine(const std::vector< Point > &points, uint8_t width, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws lines between given points with given RGBA and width.
virtual void attachRenderTarget(ImagePtr &img, bool discard)
Attaches given image as a new render surface.
virtual void drawCircle(const Point &p, uint32_t radius, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws a circle.
RenderDataType
unsigned int uint32_t
Definition: core.h:40
virtual void drawThickLine(const Point &p1, const Point &p2, uint8_t width, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws line between given points with given RGBA and width.
virtual void addImageToArray(uint32_t id, const Rect &rec, float const *st, uint8_t alpha, uint8_t const *rgba)
Add the Image data to the array.
virtual void enableScissorTest()
Enables scissor test on the render backend.
virtual void setLightingModel(uint32_t lighting)
Initializes the light.
virtual void drawVertex(const Point &p, const uint8_t size, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws a quad that represents a vertex with given RGBA.
virtual void init(const std::string &driver)
Initializes the backend.