Otclient  14/8/2020
texture.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #ifndef TEXTURE_H
24 #define TEXTURE_H
25 
26 #include "declarations.h"
27 
29 {
30 public:
31  Texture();
32  Texture(const Size& size);
33  Texture(const ImagePtr& image, bool buildMipmaps = false, bool compress = false);
34  virtual ~Texture();
35 
36  void uploadPixels(const ImagePtr& image, bool buildMipmaps = false, bool compress = false);
37  void bind();
38  void copyFromScreen(const Rect& screenRect);
39  virtual bool buildHardwareMipmaps();
40 
41  virtual void setSmooth(bool smooth);
42  virtual void setRepeat(bool repeat);
43  void setUpsideDown(bool upsideDown);
45 
46  uint getId() { return m_id; }
47  ticks_t getTime() { return m_time; }
48  int getWidth() { return m_size.width(); }
49  int getHeight() { return m_size.height(); }
50  const Size& getSize() { return m_size; }
51  const Size& getGlSize() { return m_glSize; }
53  bool isEmpty() { return m_id == 0; }
54  bool hasRepeat() { return m_repeat; }
55  bool hasMipmaps() { return m_hasMipmaps; }
56  virtual bool isAnimatedTexture() { return false; }
57 
58 protected:
59  void createTexture();
60  bool setupSize(const Size& size, bool forcePowerOfTwo = false);
61  void setupWrap();
62  void setupFilters();
63  void setupTranformMatrix();
64  void setupPixels(int level, const Size& size, uchar *pixels, int channels = 4, bool compress = false);
65 
75 };
76 
77 #endif
Texture::setupWrap
void setupWrap()
Definition: texture.cpp:187
Texture::createTexture
void createTexture()
Definition: texture.cpp:158
Texture::m_upsideDown
stdext::boolean< false > m_upsideDown
Definition: texture.h:73
TRect< int >
Texture::m_id
uint m_id
Definition: texture.h:66
Texture::getSize
const Size & getSize()
Definition: texture.h:50
Texture::setUpsideDown
void setUpsideDown(bool upsideDown)
Definition: texture.cpp:150
Texture
Definition: texture.h:28
ticks_t
int64 ticks_t
Definition: types.h:43
Texture::Texture
Texture()
Definition: texture.cpp:30
Texture::getWidth
int getWidth()
Definition: texture.h:48
stdext::time
ticks_t time()
Definition: time.cpp:33
Texture::setupSize
bool setupSize(const Size &size, bool forcePowerOfTwo=false)
Definition: texture.cpp:164
stdext::boolean< false >
Texture::~Texture
virtual ~Texture()
Definition: texture.cpp:61
TSize::width
int width() const
Definition: size.h:43
Texture::getHeight
int getHeight()
Definition: texture.h:49
Texture::m_size
Size m_size
Definition: texture.h:68
Texture::uploadPixels
void uploadPixels(const ImagePtr &image, bool buildMipmaps=false, bool compress=false)
Definition: texture.cpp:71
Texture::m_hasMipmaps
stdext::boolean< false > m_hasMipmaps
Definition: texture.h:71
uint
unsigned int uint
Definition: types.h:31
Texture::m_time
ticks_t m_time
Definition: texture.h:67
Texture::bind
void bind()
Definition: texture.cpp:98
Texture::hasMipmaps
bool hasMipmaps()
Definition: texture.h:55
Texture::getTransformMatrix
const Matrix3 & getTransformMatrix()
Definition: texture.h:52
Texture::setTime
void setTime(ticks_t time)
Definition: texture.h:44
Texture::setupPixels
void setupPixels(int level, const Size &size, uchar *pixels, int channels=4, bool compress=false)
Definition: texture.cpp:227
Texture::m_glSize
Size m_glSize
Definition: texture.h:69
Texture::m_repeat
stdext::boolean< false > m_repeat
Definition: texture.h:74
Texture::getGlSize
const Size & getGlSize()
Definition: texture.h:51
Texture::copyFromScreen
void copyFromScreen(const Rect &screenRect)
Definition: texture.cpp:105
Texture::getId
uint getId()
Definition: texture.h:46
Texture::getTime
ticks_t getTime()
Definition: texture.h:47
Texture::buildHardwareMipmaps
virtual bool buildHardwareMipmaps()
Definition: texture.cpp:111
Texture::isAnimatedTexture
virtual bool isAnimatedTexture()
Definition: texture.h:56
TSize::height
int height() const
Definition: size.h:44
uchar
unsigned char uchar
Definition: types.h:29
declarations.h
Texture::isEmpty
bool isEmpty()
Definition: texture.h:53
Texture::hasRepeat
bool hasRepeat()
Definition: texture.h:54
stdext::shared_object_ptr
Definition: shared_object.h:39
Texture::setupTranformMatrix
void setupTranformMatrix()
Definition: texture.cpp:214
Texture::setSmooth
virtual void setSmooth(bool smooth)
Definition: texture.cpp:127
Texture::m_smooth
stdext::boolean< false > m_smooth
Definition: texture.h:72
Texture::m_transformMatrix
Matrix3 m_transformMatrix
Definition: texture.h:70
Matrix
Definition: matrix.h:32
TSize< int >
stdext::shared_object
Definition: shared_object.h:41
Texture::setupFilters
void setupFilters()
Definition: texture.cpp:199
Texture::setRepeat
virtual void setRepeat(bool repeat)
Definition: texture.cpp:140