Mana
Loading...
Searching...
No Matches
openglgraphics.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#ifdef USE_OPENGL
25#include "graphics.h"
26
27#define NO_SDL_GLEXT
28
29#include <SDL_opengl.h>
30
31#include <memory>
32
33class VideoSettings;
34
35class OpenGLGraphics final : public Graphics
36{
37 public:
38 static std::unique_ptr<OpenGLGraphics> create(SDL_Window *window,
39 const VideoSettings &settings);
40
41 OpenGLGraphics(SDL_Window *window, SDL_GLContext glContext);
42
43 ~OpenGLGraphics() override;
44
45 void setVSync(bool sync) override;
46
54 void setReduceInputLag(bool reduceInputLag);
55 bool getReduceInputLag() const { return mReduceInputLag; }
56
57 void updateSize(int windowWidth, int windowHeight, float scale) override;
58
62 bool drawRescaledImage(const Image *image, int srcX, int srcY,
63 int dstX, int dstY,
64 int width, int height,
65 int desiredWidth, int desiredHeight,
66 bool useColor) override;
67
68 bool drawRescaledImageF(const Image *image,
69 int srcX, int srcY,
70 float dstX, float dstY,
71 int width, int height,
72 float desiredWidth, float desiredHeight,
73 bool useColor) override;
74
75 void drawImagePattern(const Image *image,
76 int x, int y,
77 int w, int h) override;
78
82 void drawRescaledImagePattern(const Image *image,
83 int srcX, int srcY,
84 int srcW, int srcH,
85 int dstX, int dstY,
86 int dstW, int dstH,
87 int scaledWidth, int scaledHeight) override;
88
89 void updateScreen() override;
90
91 void windowToLogical(int windowX, int windowY,
92 float &logicalX, float &logicalY) const override;
93
94 bool pushClipArea(gcn::Rectangle area) override;
95 void popClipArea() override;
96
97 void setColor(const gcn::Color &color) override;
98
99 void drawPoint(int x, int y) override;
100
101 void drawLine(int x1, int y1, int x2, int y2) override;
102
103 void drawRectangle(const gcn::Rectangle &rect, bool filled);
104
105 void drawRectangle(const gcn::Rectangle &rect) override;
106
107 void fillRectangle(const gcn::Rectangle &rect) override;
108
112 SDL_Surface *getScreenshot() override;
113
114 static void bindTexture(GLenum target, GLuint texture);
115
116 static GLuint mLastImage;
117
118 protected:
119 void setTexturingAndBlending(bool enable);
120
121 void updateClipRect() override;
122
123 private:
124 void drawQuadArrayfi(int size);
125
126 void drawQuadArrayii(int size);
127
128 SDL_Window *mWindow = nullptr;
129 SDL_GLContext mContext = nullptr;
130 GLfloat *mFloatTexArray;
131 GLint *mIntTexArray;
132 GLint *mIntVertArray;
133 float mUserScale = 1.0f;
134 float mScaleX = 1.0f;
135 float mScaleY = 1.0f;
136 bool mAlpha = false;
137 bool mTexture = false;
138 bool mColorAlpha = false;
139 bool mReduceInputLag = true;
140};
141#endif //USE_OPENGL
A central point of control for graphics.
Definition graphics.h:78
virtual void updateScreen()=0
Updates the screen.
virtual void drawImagePattern(const Image *image, int x, int y, int w, int h)
Definition graphics.cpp:99
bool drawRescaledImage(const Image *image, int x, int y, int width, int height)
Draws a rescaled version of the image.
Definition graphics.cpp:52
virtual SDL_Surface * getScreenshot()=0
Takes a screenshot and returns it as SDL surface.
void drawRescaledImagePattern(const Image *image, int x, int y, int w, int h, int scaledWidth, int scaledHeight)
Draw a pattern based on a rescaled version of the given image.
Definition graphics.cpp:108
void setColor(const gcn::Color &color) override
Definition graphics.h:255
virtual void updateClipRect()=0
virtual void windowToLogical(int windowX, int windowY, float &logicalX, float &logicalY) const =0
Converts a window coordinate to a logical coordinate.
virtual void updateSize(int width, int height, float scale)
Called when the window size or scale has changed.
Definition graphics.cpp:30
virtual void setVSync(bool sync)=0
Sets whether vertical refresh syncing is enabled.
virtual bool drawRescaledImageF(const Image *image, int srcX, int srcY, float dstX, float dstY, int width, int height, float desiredWidth, float desiredHeight, bool useColor=false)
Draws a rescaled version of the image.
Definition graphics.cpp:60
Defines a class for loading and storing images.
Definition image.h:45