~ubuntu-branches/ubuntu/trusty/manaplus/trusty-proposed

« back to all changes in this revision

Viewing changes to src/render/safeopenglgraphics.h

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi
  • Date: 2013-09-17 10:35:51 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20130917103551-az7p3nz9jgxwqjfn
Tags: 1.3.9.15-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  The ManaPlus Client
 
3
 *  Copyright (C) 2004-2009  The Mana World Development Team
 
4
 *  Copyright (C) 2009-2010  The Mana Developers
 
5
 *  Copyright (C) 2011-2013  The ManaPlus Developers
 
6
 *
 
7
 *  This file is part of The ManaPlus Client.
 
8
 *
 
9
 *  This program is free software; you can redistribute it and/or modify
 
10
 *  it under the terms of the GNU General Public License as published by
 
11
 *  the Free Software Foundation; either version 2 of the License, or
 
12
 *  any later version.
 
13
 *
 
14
 *  This program is distributed in the hope that it will be useful,
 
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 *  GNU General Public License for more details.
 
18
 *
 
19
 *  You should have received a copy of the GNU General Public License
 
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
21
 */
 
22
 
 
23
#ifndef RENDER_SAFEOPENGLGRAPHICS_H
 
24
#define RENDER_SAFEOPENGLGRAPHICS_H
 
25
 
 
26
#include "main.h"
 
27
#if defined USE_OPENGL && !defined ANDROID
 
28
 
 
29
#include "render/graphics.h"
 
30
 
 
31
#include "resources/fboinfo.h"
 
32
 
 
33
#ifdef ANDROID
 
34
#include <GLES/gl.h>
 
35
#include <GLES/glext.h>
 
36
#else
 
37
#ifndef USE_SDL2
 
38
#define GL_GLEXT_PROTOTYPES 1
 
39
#endif
 
40
#include <SDL_opengl.h>
 
41
#include <GL/glext.h>
 
42
#endif
 
43
 
 
44
class SafeOpenGLGraphics final : public Graphics
 
45
{
 
46
    public:
 
47
        SafeOpenGLGraphics();
 
48
 
 
49
        A_DELETE_COPY(SafeOpenGLGraphics)
 
50
 
 
51
        ~SafeOpenGLGraphics();
 
52
 
 
53
        bool setVideoMode(const int w, const int h, const int bpp,
 
54
                          const bool fs, const bool hwaccel,
 
55
                          const bool resize, const bool noFrame) override;
 
56
 
 
57
        /**
 
58
         * Draws a resclaled version of the image
 
59
         */
 
60
        bool drawRescaledImage(const Image *const image, int srcX, int srcY,
 
61
                               int dstX, int dstY,
 
62
                               const int width, const int height,
 
63
                               const int desiredWidth, const int desiredHeight,
 
64
                               const bool useColor) override;
 
65
 
 
66
        /**
 
67
         * Used to get the smooth rescale option over the standard function.
 
68
         */
 
69
        bool drawRescaledImage(const Image *const image, int srcX, int srcY,
 
70
                               int dstX, int dstY,
 
71
                               const int width, const int height,
 
72
                               const int desiredWidth, const int desiredHeight,
 
73
                               const bool useColor, bool smooth);
 
74
 
 
75
        void drawImagePattern(const Image *const image,
 
76
                              const int x, const int y,
 
77
                              const int w, const int h) override;
 
78
 
 
79
        /**
 
80
         * Draw a pattern based on a rescaled version of the given image...
 
81
         */
 
82
        void drawRescaledImagePattern(const Image *const image,
 
83
                                      const int x, const int y,
 
84
                                      const int w, const int h,
 
85
                                      const int scaledWidth,
 
86
                                      const int scaledHeight) override;
 
87
 
 
88
        void calcTile(ImageVertexes *const vert, const Image *const image,
 
89
                      int x, int y) const override;
 
90
 
 
91
        void calcTile(ImageCollection *const vertCol,
 
92
                      const Image *const image, int x, int y) override;
 
93
 
 
94
        void calcImagePattern(ImageVertexes *const vert,
 
95
                              const Image *const image,
 
96
                              const int x, const int y,
 
97
                              const int w, const int h) const;
 
98
 
 
99
        void calcImagePattern(ImageCollection *const vert,
 
100
                              const Image *const image,
 
101
                              const int x, const int y,
 
102
                              const int w, const int h) const;
 
103
 
 
104
        void drawTile(const ImageVertexes *const vert) override;
 
105
 
 
106
        void drawTile(const ImageCollection *const vertCol) override;
 
107
 
 
108
        void updateScreen() override;
 
109
 
 
110
        bool calcWindow(ImageCollection *const vertCol,
 
111
                        const int x, const int y,
 
112
                        const int w, const int h,
 
113
                        const ImageRect &imgRect);
 
114
 
 
115
        void _beginDraw();
 
116
 
 
117
        void _endDraw();
 
118
 
 
119
        bool pushClipArea(gcn::Rectangle area);
 
120
 
 
121
        void popClipArea();
 
122
 
 
123
        void setColor(const gcn::Color &color)
 
124
        {
 
125
            mColor = color;
 
126
            mColor2 = color;
 
127
            mColorAlpha = (color.a != 255);
 
128
        }
 
129
 
 
130
        void setColorAll(const gcn::Color &color, const gcn::Color &color2)
 
131
        {
 
132
            mColor = color;
 
133
            mColor2 = color2;
 
134
            mColorAlpha = (color.a != 255);
 
135
        }
 
136
 
 
137
        void drawPoint(int x, int y);
 
138
 
 
139
        void drawLine(int x1, int y1, int x2, int y2);
 
140
 
 
141
        void drawRectangle(const gcn::Rectangle &rect, const bool filled);
 
142
 
 
143
        void drawRectangle(const gcn::Rectangle &rect);
 
144
 
 
145
        void fillRectangle(const gcn::Rectangle &rect) override;
 
146
 
 
147
        void setTargetPlane(int width, int height);
 
148
 
 
149
        /**
 
150
         * Takes a screenshot and returns it as SDL surface.
 
151
         */
 
152
        SDL_Surface *getScreenshot() override A_WARN_UNUSED;
 
153
 
 
154
        void prepareScreenshot() override;
 
155
 
 
156
        static void bindTexture(const GLenum target, const GLuint texture);
 
157
 
 
158
        static GLuint mLastImage;
 
159
 
 
160
    protected:
 
161
        bool drawImage2(const Image *const image,
 
162
                        int srcX, int srcY,
 
163
                        int dstX, int dstY,
 
164
                        const int width, const int height,
 
165
                        const bool useColor);
 
166
 
 
167
        void setTexturingAndBlending(const bool enable);
 
168
 
 
169
    private:
 
170
        void inline setColorAlpha(float alpha);
 
171
 
 
172
        void inline restoreColor();
 
173
 
 
174
        bool mTexture;
 
175
        bool mIsByteColor;
 
176
        gcn::Color mByteColor;
 
177
        float mFloatColor;
 
178
        bool mColorAlpha;
 
179
        FBOInfo mFbo;
 
180
};
 
181
#endif
 
182
 
 
183
#endif  // RENDER_SAFEOPENGLGRAPHICS_H