Mana
Loading...
Searching...
No Matches
image.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#include "resources/resource.h"
25
26#include <SDL.h>
27
28#ifdef USE_OPENGL
29
30/* The definition of OpenGL extensions by SDL is giving problems with recent
31 * gl.h headers, since they also include these definitions. As we're not using
32 * extensions anyway it's safe to just disable the SDL version.
33 */
34#define NO_SDL_GLEXT
35
36#include <SDL_opengl.h>
37#endif
38
39class Dye;
40
44class Image : public Resource
45{
46 friend class SDLGraphics;
47#ifdef USE_OPENGL
48 friend class OpenGLGraphics;
49#endif
50
51 public:
52 ~Image() override;
53
62 static Resource *load(SDL_RWops *rw);
63
73 static Resource *load(SDL_RWops *rw, const Dye &dye);
74
78 static Image *load(SDL_Surface *);
79
83 int getWidth() const
84 { return mBounds.w; }
85
89 int getHeight() const
90 { return mBounds.h; }
91
96 static bool useOpenGL();
97
101 void setAlpha(float alpha);
102
106 float getAlpha() const
107 { return mAlpha; }
108
115 Image *getSubImage(int x, int y, int width, int height);
116
117 // SDL only public functions
118
123 { mDisableTransparency = true; }
124
126 { return mDisableTransparency; }
127
128 static void setRenderer(SDL_Renderer *renderer);
129
130#ifdef USE_OPENGL
131
132 // OpenGL only public functions
133
138 static void setLoadAsOpenGL(bool useOpenGL);
139
140 static bool getLoadAsOpenGL() { return mUseOpenGL; }
141
142 int getTextureWidth() const { return mTexWidth; }
143 int getTextureHeight() const { return mTexHeight; }
144 static int getTextureType() { return mTextureType; }
145#endif
146
147 protected:
148
149 // -----------------------
150 // Generic protected members
151 // -----------------------
152
153 SDL_Rect mBounds;
154 float mAlpha = 1.0f;
155
156 // -----------------------
157 // SDL protected members
158 // -----------------------
159
161 Image(SDL_Texture *texture, int width, int height);
162
164 static Image *_SDLload(SDL_Surface *tmpImage);
165
166 SDL_Texture *mTexture = nullptr;
167
170
171 static SDL_Renderer *mRenderer;
172
173 // -----------------------
174 // OpenGL protected members
175 // -----------------------
176#ifdef USE_OPENGL
180 Image(GLuint glimage, int width, int height,
181 int texWidth, int texHeight);
182
186 static int powerOfTwo(int input);
187
188 static Image *_GLload(SDL_Surface *image);
189
190 GLuint mGLImage = 0;
191 int mTexWidth, mTexHeight;
192
193 static bool mUseOpenGL;
194 static bool mPowerOfTwoTextures;
195 static int mTextureType;
196 static int mTextureSize;
197#endif
198};
199
203class SubImage : public Image
204{
205 public:
206 SubImage(Image *parent, SDL_Texture *texture,
207 int x, int y, int width, int height);
208#ifdef USE_OPENGL
209 SubImage(Image *parent, GLuint image, int x, int y,
210 int width, int height, int texWidth, int textHeight);
211#endif
212
213 ~SubImage() override;
214
215 private:
217};
Class for dispatching pixel-recoloring amongst several palettes.
Definition dye.h:66
Defines a class for loading and storing images.
Definition image.h:45
int getHeight() const
Returns the height of the image.
Definition image.h:89
static Image * _SDLload(SDL_Surface *tmpImage)
SDL_Surface to SDL_Texture Image loader.
Definition image.cpp:184
SDL_Texture * mTexture
Definition image.h:166
int getWidth() const
Returns the width of the image.
Definition image.h:83
static bool SDLisTransparencyDisabled()
Definition image.h:125
static Resource * load(SDL_RWops *rw)
Loads an image from an SDL_RWops structure.
Definition image.cpp:98
SDL_Rect mBounds
Definition image.h:153
static void SDLdisableTransparency()
Disable the transparency handling (for low CPUs in SDL Mode)
Definition image.h:122
~Image() override
Definition image.cpp:81
static bool useOpenGL()
Tells if the system is using OpenGL or SDL.
Definition image.cpp:167
Image * getSubImage(int x, int y, int width, int height)
Creates a new image with the desired clipping rectangle.
Definition image.cpp:331
static bool mDisableTransparency
Stores whether the transparency is disabled.
Definition image.h:169
void setAlpha(float alpha)
Sets the alpha value of this image.
Definition image.cpp:176
float getAlpha() const
Returns the alpha value of this image.
Definition image.h:106
static void setRenderer(SDL_Renderer *renderer)
Definition image.cpp:193
float mAlpha
Definition image.h:154
static SDL_Renderer * mRenderer
Definition image.h:171
Automatically counting Resource reference.
Definition resource.h:74
A generic reference counted resource object.
Definition resource.h:31
A clipped version of a larger image.
Definition image.h:204
~SubImage() override
Definition image.cpp:380
ResourceRef< Image > mParent
Definition image.h:216