FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
renderbackendopengl.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2013 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_RENDERBACKENSD_OPENGL_RENDERBACKENDOPENGL_H
23 #define FIFE_VIDEO_RENDERBACKENSD_OPENGL_RENDERBACKENDOPENGL_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 #include "fife_opengl.h"
36 
37 namespace FIFE {
38  class ScreenMode;
39 
44  public:
45  RenderBackendOpenGL(const SDL_Color& colorkey);
46  virtual ~RenderBackendOpenGL();
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(uint16_t elements, int32_t src, int32_t dst, bool light, bool stentest, uint8_t stenref, GLConstants stenop, GLConstants stenfunc);
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 drawTriangle(const Point& p1, const Point& p2, const Point& p3, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
78  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);
79  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);
80  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);
81  virtual void drawVertex(const Point& p, const uint8_t size, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
82  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);
83 
84  virtual void attachRenderTarget(ImagePtr& img, bool discard);
85  virtual void detachRenderTarget();
86 
87  void enableTextures(uint32_t texUnit);
88  void disableTextures(uint32_t texUnit);
89  void bindTexture(uint32_t texUnit, GLuint texId);
90  void bindTexture(GLuint textId);
91 
92  protected:
93  virtual void setClipArea(const Rect& cliparea, bool clear);
94 
95  void enableLighting();
96  void disableLighting();
97  void enableStencilTest();
98  void disableStencilTest();
99  void setStencilTest(uint8_t stencil_ref, GLenum stencil_op, GLenum stencil_func);
100  uint8_t getStencilRef() const;
101  void enableAlphaTest();
102  void disableAlphaTest();
103  void setAlphaTest(float ref_alpha);
104  void setEnvironmentalColor(const uint8_t* rgba);
105  void setVertexPointer(GLsizei stride, const GLvoid* ptr);
106  void setColorPointer(GLsizei stride, const GLvoid* ptr);
107  void setTexCoordPointer(uint32_t texUnit, GLsizei stride, const GLvoid* ptr);
108  void enableScissorTest();
109  void disableScissorTest();
110 
112  void prepareForOverlays();
113 
114  class RenderObject;
115 
116  struct renderData2T {
117  GLfloat vertex[2];
118  GLfloat texel[2];
119  GLfloat texel2[2];
120  GLubyte color[4];
121  };
122 
123  struct renderData {
124  GLfloat vertex[2];
125  GLfloat texel[2];
126  GLubyte color[4];
127  };
128  std::vector<renderData> m_render_datas;
129  std::vector<renderData2T> m_render_datas2T;
130  std::vector<RenderObject> m_render_objects;
131 
132  struct currentState {
133  // Textures
134  bool tex_enabled[2];
135  GLuint texture[2];
138 
139  // Pointers
140  const void* vertex_pointer;
141  const void* tex_pointer[2];
142  const void* color_pointer;
143 
144  // Stencil
147  GLint sten_buf;
148  GLenum sten_op;
149  GLenum sten_func;
150 
151  // Light
154 
155  // The rest
157  GLenum blend_src;
158  GLenum blend_dst;
161  } m_state;
162 
163  GLuint m_fbo_id;
166  };
167 
168 }
169 
170 #endif
171 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */
Abstract interface for all the renderbackends.
Definition: renderbackend.h:92
virtual void changeRenderInfos(uint16_t elements, int32_t src, int32_t dst, bool light, bool stentest, uint8_t stenref, GLConstants stenop, GLConstants stenfunc)
Dirty helper function to change the render infos.
virtual void setScreenMode(const ScreenMode &mode)
Sets the mainscreen display mode.
virtual void setLighting(float red, float green, float blue)
Set colors for lighting.
Base Class for Images.
Definition: image.h:47
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 uint32_t getLightingModel() const
Gets the current light model.
virtual void renderVertexArrays()
Render the Vertex Arrays, only for primitives (points, lines,...)
void disableTextures(uint32_t texUnit)
virtual void init(const std::string &driver)
Initializes the backend.
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.
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 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.
void setVertexPointer(GLsizei stride, const GLvoid *ptr)
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 setClipArea(const Rect &cliparea, bool clear)
Sets given clip area into image.
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.
void setStencilTest(uint8_t stencil_ref, GLenum stencil_op, GLenum stencil_func)
void enableTextures(uint32_t texUnit)
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 setLightingModel(uint32_t lighting)
Initializes the light.
virtual Image * createImage(IResourceLoader *loader=0)
void setEnvironmentalColor(const uint8_t *rgba)
unsigned char uint8_t
Definition: core.h:38
virtual void resetLighting()
Reset lighting with default values.
std::vector< RenderObject > m_render_objects
virtual void captureScreen(const std::string &filename)
Creates a Screenshot and saves it to a file.
std::vector< renderData2T > m_render_datas2T
virtual void clearBackBuffer()
Forces a clear of the backbuffer.
virtual void changeBlending(int32_t scr, int32_t dst)
Change the Blendingmodel.
struct FIFE::RenderBackendOpenGL::currentState m_state
unsigned short uint16_t
Definition: core.h:39
virtual void detachRenderTarget()
Detaches current render surface.
void setTexCoordPointer(uint32_t texUnit, GLsizei stride, const GLvoid *ptr)
void setAlphaTest(float ref_alpha)
virtual void createMainScreen(const ScreenMode &mode, const std::string &title, const std::string &icon)
Creates the mainscreen (the display window).
RenderBackendOpenGL(const SDL_Color &colorkey)
std::vector< renderData > m_render_datas
void setColorPointer(GLsizei stride, const GLvoid *ptr)
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.
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 attachRenderTarget(ImagePtr &img, bool discard)
Attaches given image as a new render surface.
unsigned int uint32_t
Definition: core.h:40
virtual void startFrame()
Called when a new frame starts.
The main class of the OpenGL-based renderer.
void bindTexture(uint32_t texUnit, GLuint texId)
virtual void endFrame()
Called when a frame is finished and ready to be displayed.
virtual void resetStencilBuffer(uint8_t buffer)
Reset stencil buffer with given value.
virtual const std::string & getName() const
The name of the renderbackend.