FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
renderbackend.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_RENDERBACKEND_H
23 #define FIFE_VIDEO_RENDERBACKEND_H
24 
25 // Standard C++ library includes
26 #include <string>
27 #include <vector>
28 
29 // Platform specific includes
30 #include "util/base/fife_stdint.h"
31 
32 // 3rd party library includes
33 #include <SDL.h>
34 #include <SDL_video.h>
35 
36 // FIFE includes
37 // These includes are split up in two parts, separated by one empty line
38 // First block: files included from the FIFE root src directory
39 // Second block: files included from the same folder
40 #include "util/base/singleton.h"
41 #include "util/structures/point.h"
42 #include "util/structures/rect.h"
43 #include "video/devicecaps.h"
44 
45 #include "image.h"
46 #include "color.h"
47 
48 #ifdef HAVE_OPENGL
50 #endif
51 
52 namespace FIFE {
53 
54  class Image;
55 
56 #ifdef HAVE_OPENGL
57  enum GLConstants {
58  KEEP = GL_KEEP,
59  ZERO = GL_ZERO,
60  REPLACE = GL_REPLACE,
61  INCR = GL_INCR,
62  DECR = GL_DECR,
63  INVERT = GL_INVERT,
64  NEVER = GL_NEVER,
65  LESS = GL_LESS,
66  LEQUAL = GL_LEQUAL,
67  GREATER = GL_GREATER,
68  GEQUAL = GL_GEQUAL,
69  EQUAL = GL_EQUAL,
70  NOTEQUAL = GL_NOTEQUAL,
71  ALWAYS = GL_ALWAYS
72  };
73 #else
74  enum GLConstants {
75  KEEP = 0,
89  };
90 #endif
91 
92  enum OverlayType {
97  };
98 
104  };
105 
111  };
112 
113  class GuiVertex {
114  public:
118  };
119 
121  class RenderBackend: public DynamicSingleton<RenderBackend> {
122  public:
126  RenderBackend(const SDL_Color& colorkey);
127 
130  virtual ~RenderBackend();
131 
135  virtual const std::string& getName() const = 0;
136 
139  virtual void startFrame();
140 
143  virtual void endFrame();
144 
147  virtual void init(const std::string& driver) = 0;
148 
151  virtual void clearBackBuffer() = 0;
152 
155  virtual void setLightingModel(uint32_t lighting) = 0;
156 
159  virtual uint32_t getLightingModel() const = 0;
160 
163  virtual void setLighting(float red, float green, float blue) = 0;
164 
167  virtual void resetLighting() = 0;
168 
171  virtual void resetStencilBuffer(uint8_t buffer) = 0;
172 
175  virtual void changeBlending(int32_t scr, int32_t dst) = 0;
176 
179  void deinit();
180 
186  virtual void createMainScreen(const ScreenMode& mode, const std::string& title, const std::string& icon) = 0;
187 
191  virtual void setScreenMode(const ScreenMode& mode) = 0;
192 
193  virtual Image* createImage(IResourceLoader* loader = 0) = 0;
194  virtual Image* createImage(const std::string& name, IResourceLoader* loader = 0) = 0;
195 
202  virtual Image* createImage(const uint8_t* data, uint32_t width, uint32_t height) = 0;
203  virtual Image* createImage(const std::string& name, const uint8_t* data, uint32_t width, uint32_t height) = 0;
204 
210  virtual Image* createImage(SDL_Surface* surface) = 0;
211  virtual Image* createImage(const std::string& name, SDL_Surface* surface) = 0;
212 
215  virtual void renderVertexArrays() = 0;
216 
219  virtual void addImageToArray(uint32_t id, const Rect& rec, float const* st, uint8_t alpha, uint8_t const* rgba) = 0;
220 
223  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) = 0;
224 
227  virtual void captureScreen(const std::string& filename) = 0;
228 
231  virtual void captureScreen(const std::string& filename, uint32_t width, uint32_t height) = 0;
232 
233  SDL_Window* getWindow() {return m_window; }
234 
238  const ScreenMode& getCurrentScreenMode() const;
239 
240  uint32_t getWidth() const;
241  uint32_t getHeight() const;
242  uint32_t getScreenWidth() const { return getWidth(); }
243  uint32_t getScreenHeight() const { return getHeight(); }
244  const Rect& getArea() const;
245 
250  void pushClipArea(const Rect& cliparea, bool clear=true);
251 
255  void popClipArea();
256 
260  const Rect& getClipArea() const;
261 
264  virtual bool putPixel(int32_t x, int32_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) = 0;
265 
268  virtual void drawLine(const Point& p1, const Point& p2, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) = 0;
269 
272  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) = 0;
273 
276  virtual void drawPolyLine(const std::vector<Point>& points, uint8_t width, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) = 0;
277 
280  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) = 0;
281 
284  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) = 0;
285 
288  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) = 0;
289 
292  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) = 0;
293 
296  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) = 0;
297 
300  virtual void drawVertex(const Point& p, const uint8_t size, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) = 0;
301 
304  virtual void drawCircle(const Point& p, uint32_t radius, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) = 0;
305 
308  virtual void drawFillCircle(const Point& p, uint32_t radius, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) = 0;
309 
313  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) = 0;
314 
318  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) = 0;
319 
322  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) = 0;
323 
326  virtual void enableScissorTest() = 0;
327 
330  virtual void disableScissorTest() = 0;
331 
337  void setAlphaOptimizerEnabled(bool enabled){ m_isalphaoptimized = enabled; }
338 
341  bool isAlphaOptimizerEnabled() const { return m_isalphaoptimized; }
342 
346  void setImageCompressingEnabled(bool enabled) { m_compressimages = enabled; }
347 
350  bool isImageCompressingEnabled() const { return m_compressimages; }
351 
354  void setFramebufferEnabled(bool enabled) { m_useframebuffer = enabled; }
355 
358  bool isFramebufferEnabled() const { return m_useframebuffer; }
359 
362  void setNPOTEnabled(bool enabled) { m_usenpot = enabled; }
363 
366  bool isNPOTEnabled() const { return m_usenpot; }
367 
373  void setTextureFiltering(TextureFiltering filter);
374 
377  TextureFiltering getTextureFiltering() const;
378 
382  void setMipmappingEnabled(bool enabled);
383 
386  bool isMipmappingEnabled() const;
387 
390  int32_t getMaxAnisotropy() const;
391 
395  void setMonochromeEnabled(bool enabled);
396 
399  bool isMonochromeEnabled() const;
400 
404  void setDepthBufferEnabled(bool enabled);
405 
408  bool isDepthBufferEnabled() const;
409 
414  void setAlphaTestValue(float alpha);
415 
418  float getAlphaTestValue() const;
419 
422  void setColorKeyEnabled(bool colorkeyenable);
423 
426  bool isColorKeyEnabled() const;
427 
430  void setColorKey(const SDL_Color& colorkey);
431 
434  const SDL_Color& getColorKey() const;
435 
438  void setBackgroundColor(uint8_t r, uint8_t g, uint8_t b);
439 
442  void resetBackgroundColor();
443 
446  const SDL_PixelFormat& getPixelFormat() const;
447 
450  void setVSyncEnabled(bool vsync);
451 
454  bool isVSyncEnabled() const;
455 
458  void setFrameLimitEnabled(bool limited);
459 
462  bool isFrameLimitEnabled() const;
463 
466  void setFrameLimit(uint16_t framelimit);
467 
470  uint16_t getFrameLimit() const;
471 
474  SDL_Surface* getScreenSurface();
475 
478  SDL_Surface* getRenderTargetSurface();
479 
482  virtual void attachRenderTarget(ImagePtr& img, bool discard) = 0;
483 
486  virtual void detachRenderTarget() = 0;
487 
490  virtual void renderGuiGeometry(const std::vector<GuiVertex>& vertices, const std::vector<int>& indices, const DoublePoint& translation, ImagePtr texture) = 0;
491 
494  Point getBezierPoint(const std::vector<Point>& points, int32_t elements, float t);
495 
498  void addControlPoints(const std::vector<Point>& points, std::vector<Point>& newPoints);
499 
500  protected:
501 
505  virtual void setClipArea(const Rect& cliparea, bool clear) = 0;
506 
507  SDL_Window* m_window;
508  SDL_Surface* m_screen;
509  SDL_Surface* m_target;
512  bool m_usenpot;
515  SDL_Color m_colorkey;
517  SDL_PixelFormat m_rgba_format;
518 
520  SDL_Color m_backgroundcolor;
521 
522  // mipmapping
524  // texture filter
526  // max anisotropy
528  // monochrome rendering
530  // depth buffer rendering
532  // alpha test value
534  // vsync value
535  bool m_vSync;
536 
540  void clearClipArea();
541 
542  class ClipInfo {
543  public:
545  bool clearing;
546  };
547  std::stack<ClipInfo> m_clipstack;
548 
550  private:
554 
555  };
556 }
557 
558 #endif
Abstract interface for all the renderbackends.
SDL_Surface * m_target
SDL_Window * getWindow()
Base Class for Images.
Definition: image.h:48
SDL_PixelFormat m_rgba_format
SDL_Window * m_window
uint32_t getScreenWidth() const
void setFramebufferEnabled(bool enabled)
Enables or disable the usage of the framebuffer, if available.
uint32_t getScreenHeight() const
DoublePoint texCoords
bool isImageCompressingEnabled() const
unsigned char uint8_t
Definition: core.h:38
void setNPOTEnabled(bool enabled)
Enables or disable the usage of npot, if available.
Another Singleton.
Definition: singleton.h:82
bool isAlphaOptimizerEnabled() const
unsigned short uint16_t
Definition: core.h:39
SDL_Surface * m_screen
void setAlphaOptimizerEnabled(bool enabled)
Enable or disable the alpha &#39;optimizing&#39; code.
SDL_Color m_backgroundcolor
TextureFiltering m_textureFilter
bool isNPOTEnabled() const
TextureFiltering
Definition: renderbackend.h:99
bool isFramebufferEnabled() const
ScreenMode m_screenMode
RenderDataType
std::stack< ClipInfo > m_clipstack
unsigned int uint32_t
Definition: core.h:40
DoublePoint position
void setImageCompressingEnabled(bool enabled)
Enables or disable compressing images by video driver.