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

« back to all changes in this revision

Viewing changes to src/render/mobileopenglgraphics.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_MOBILEOPENGLGRAPHICS_H
 
24
#define RENDER_MOBILEOPENGLGRAPHICS_H
 
25
 
 
26
#include "main.h"
 
27
#ifdef USE_OPENGL
 
28
 
 
29
#include "localconsts.h"
 
30
#include "render/graphics.h"
 
31
 
 
32
#include "resources/fboinfo.h"
 
33
 
 
34
#ifdef ANDROID
 
35
#include <GLES/gl.h>
 
36
#include <GLES/glext.h>
 
37
#include <GLES2/gl2.h>
 
38
#else
 
39
#ifndef USE_SDL2
 
40
#define GL_GLEXT_PROTOTYPES 1
 
41
#endif
 
42
#include <SDL_opengl.h>
 
43
#include <GL/glext.h>
 
44
#endif
 
45
 
 
46
#include <set>
 
47
 
 
48
class NormalOpenGLGraphicsVertexes;
 
49
 
 
50
class MobileOpenGLGraphics final : public Graphics
 
51
{
 
52
    public:
 
53
        MobileOpenGLGraphics();
 
54
 
 
55
        A_DELETE_COPY(MobileOpenGLGraphics)
 
56
 
 
57
        ~MobileOpenGLGraphics();
 
58
 
 
59
        bool setVideoMode(const int w, const int h, const int bpp,
 
60
                          const bool fs, const bool hwaccel,
 
61
                          const bool resize, const bool noFrame) override;
 
62
 
 
63
 
 
64
        /**
 
65
         * Draws a resclaled version of the image
 
66
         */
 
67
        bool drawRescaledImage(const Image *const image, int srcX, int srcY,
 
68
                               int dstX, int dstY,
 
69
                               const int width, const int height,
 
70
                               const int desiredWidth, const int desiredHeight,
 
71
                               const bool useColor) override;
 
72
 
 
73
        /**
 
74
         * Used to get the smooth rescale option over the standard function.
 
75
         */
 
76
        bool drawRescaledImage(const Image *const image, int srcX, int srcY,
 
77
                               int dstX, int dstY,
 
78
                               const int width, const int height,
 
79
                               const int desiredWidth, const int desiredHeight,
 
80
                               const bool useColor, bool smooth);
 
81
 
 
82
        void drawImagePattern(const Image *const image,
 
83
                              const int x, const int y,
 
84
                              const int w, const int h) override;
 
85
 
 
86
        /**
 
87
         * Draw a pattern based on a rescaled version of the given image...
 
88
         */
 
89
        void drawRescaledImagePattern(const Image *const image,
 
90
                                      const int x, const int y,
 
91
                                      const int w, const int h,
 
92
                                      const int scaledWidth,
 
93
                                      const int scaledHeight) override;
 
94
 
 
95
        void calcImagePattern(ImageVertexes *const vert,
 
96
                              const Image *const image,
 
97
                              const int x, const int y,
 
98
                              const int w, const int h) const override;
 
99
 
 
100
        void calcImagePattern(ImageCollection *const vert,
 
101
                              const Image *const image,
 
102
                              const int x, const int y,
 
103
                              const int w, const int h) const override;
 
104
 
 
105
        void calcTile(ImageVertexes *const vert, const Image *const image,
 
106
                      int x, int y) const override;
 
107
 
 
108
        void drawTile(const ImageCollection *const vertCol);
 
109
 
 
110
        void calcTile(ImageCollection *const vertCol,
 
111
                      const Image *const image, int x, int y) override;
 
112
 
 
113
        void drawTile(const ImageVertexes *const vert) override;
 
114
 
 
115
        bool calcWindow(ImageCollection *const vertCol,
 
116
                        const int x, const int y,
 
117
                        const int w, const int h,
 
118
                        const ImageRect &imgRect);
 
119
 
 
120
        void updateScreen() override;
 
121
 
 
122
        void _beginDraw();
 
123
 
 
124
        void _endDraw();
 
125
 
 
126
        bool pushClipArea(gcn::Rectangle area);
 
127
 
 
128
        void popClipArea();
 
129
 
 
130
        void setColor(const gcn::Color &color)
 
131
        {
 
132
            mColor = color;
 
133
            mColor2 = color;
 
134
            mColorAlpha = (color.a != 255);
 
135
        }
 
136
 
 
137
        void setColorAll(const gcn::Color &color, const gcn::Color &color2)
 
138
        {
 
139
            mColor = color;
 
140
            mColor2 = color2;
 
141
            mColorAlpha = (color.a != 255);
 
142
        }
 
143
 
 
144
        void drawPoint(int x, int y);
 
145
 
 
146
        void drawLine(int x1, int y1, int x2, int y2);
 
147
 
 
148
        void drawRectangle(const gcn::Rectangle &rect, const bool filled);
 
149
 
 
150
        void drawRectangle(const gcn::Rectangle &rect);
 
151
 
 
152
        void fillRectangle(const gcn::Rectangle &rect);
 
153
 
 
154
        void setTargetPlane(int width, int height);
 
155
 
 
156
        inline void drawTriangleArrayfs(const GLshort *const shortVertArray,
 
157
                                        const GLfloat *const floatTexArray,
 
158
                                        const int size);
 
159
 
 
160
        inline void drawTriangleArrayfs(const int size);
 
161
 
 
162
        inline void drawLineArrays(const int size);
 
163
 
 
164
        inline void drawVertexes(const NormalOpenGLGraphicsVertexes &ogl);
 
165
 
 
166
        void initArrays() override;
 
167
 
 
168
        static void dumpSettings();
 
169
 
 
170
        /**
 
171
         * Takes a screenshot and returns it as SDL surface.
 
172
         */
 
173
        SDL_Surface *getScreenshot() override A_WARN_UNUSED;
 
174
 
 
175
        void prepareScreenshot() override;
 
176
 
 
177
        bool drawNet(const int x1, const int y1, const int x2, const int y2,
 
178
                     const int width, const int height) override;
 
179
 
 
180
        int getMemoryUsage();
 
181
 
 
182
        void updateTextureFormat();
 
183
 
 
184
#ifdef DEBUG_DRAW_CALLS
 
185
        virtual unsigned int getDrawCalls() const
 
186
        { return mLastDrawCalls; }
 
187
 
 
188
        static unsigned int mDrawCalls;
 
189
 
 
190
        static unsigned int mLastDrawCalls;
 
191
#endif
 
192
 
 
193
        static void bindTexture(const GLenum target, const GLuint texture);
 
194
 
 
195
        static GLuint mLastImage;
 
196
 
 
197
    protected:
 
198
        bool drawImage2(const Image *const image,
 
199
                        int srcX, int srcY,
 
200
                        int dstX, int dstY,
 
201
                        const int width, const int height,
 
202
                        const bool useColor) override;
 
203
 
 
204
        void setTexturingAndBlending(const bool enable);
 
205
 
 
206
        void debugBindTexture(const Image *image);
 
207
 
 
208
    private:
 
209
        void inline setColorAlpha(float alpha);
 
210
 
 
211
        void inline restoreColor();
 
212
 
 
213
        GLfloat *mFloatTexArray;
 
214
        GLint *mIntTexArray;
 
215
        GLint *mIntVertArray;
 
216
        GLshort *mShortVertArray;
 
217
        bool mTexture;
 
218
 
 
219
        bool mIsByteColor;
 
220
        gcn::Color mByteColor;
 
221
        float mFloatColor;
 
222
        int mMaxVertices;
 
223
        bool mColorAlpha;
 
224
#ifdef DEBUG_BIND_TEXTURE
 
225
        std::string mOldTexture;
 
226
        unsigned mOldTextureId;
 
227
#endif
 
228
        FBOInfo mFbo;
 
229
};
 
230
#endif
 
231
 
 
232
#endif  // RENDER_MOBILEOPENGLGRAPHICS_H