Otclient  14/8/2020
painterogl.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 PAINTEROGL_H
24 #define PAINTEROGL_H
25 
27 
28 class PainterOGL : public Painter
29 {
30 public:
31  struct PainterState {
37  float opacity;
44  };
45 
46  PainterOGL();
47  virtual ~PainterOGL() { }
48 
49  virtual void bind() { refreshState(); }
50  virtual void unbind() { }
51 
52  void resetState();
53  virtual void refreshState();
54  void saveState();
55  void saveAndResetState();
56  void restoreSavedState();
57 
58  void clear(const Color& color);
59  void clearRect(const Color& color, const Rect& rect);
60 
61  virtual void setTransformMatrix(const Matrix3& transformMatrix) { m_transformMatrix = transformMatrix; }
62  virtual void setProjectionMatrix(const Matrix3& projectionMatrix) { m_projectionMatrix = projectionMatrix; }
63  virtual void setTextureMatrix(const Matrix3& textureMatrix) { m_textureMatrix = textureMatrix; }
64  virtual void setCompositionMode(CompositionMode compositionMode);
65  virtual void setBlendEquation(BlendEquation blendEquation);
66  virtual void setClipRect(const Rect& clipRect);
67  virtual void setShaderProgram(PainterShaderProgram *shaderProgram) { m_shaderProgram = shaderProgram; }
68  virtual void setTexture(Texture *texture);
69  virtual void setAlphaWriting(bool enable);
70 
71  void setTexture(const TexturePtr& texture) { setTexture(texture.get()); }
72  void setResolution(const Size& resolution);
73 
74  void scale(float x, float y);
75  void translate(float x, float y);
76  void rotate(float angle);
77  void rotate(float x, float y, float angle);
78 
79  void pushTransformMatrix();
80  void popTransformMatrix();
81 
87  bool getAlphaWriting() { return m_alphaWriting; }
88 
90  void resetTexture() { setTexture(nullptr); }
93 
94 protected:
95  void updateGlTexture();
97  void updateGlBlendEquation();
98  void updateGlClipRect();
99  void updateGlAlphaWriting();
100  void updateGlViewport();
101 
103 
104  std::vector<Matrix3> m_transformMatrixStack;
108 
112 
115 
117 };
118 
119 #endif
PainterOGL::unbind
virtual void unbind()
Definition: painterogl.h:50
PainterOGL::m_transformMatrixStack
std::vector< Matrix3 > m_transformMatrixStack
Definition: painterogl.h:104
PainterOGL::pushTransformMatrix
void pushTransformMatrix()
Definition: painterogl.cpp:239
Painter::BlendEquation_Add
@ BlendEquation_Add
Definition: painter.h:35
Color
Definition: color.h:32
PainterOGL::PainterState::compositionMode
Painter::CompositionMode compositionMode
Definition: painterogl.h:38
TRect< int >
PainterOGL::m_textureMatrix
Matrix3 m_textureMatrix
Definition: painterogl.h:107
Texture
Definition: texture.h:28
PainterOGL::PainterOGL
PainterOGL()
Definition: painterogl.cpp:27
PainterOGL::resetState
void resetState()
Definition: painterogl.cpp:41
PainterOGL::m_texture
Texture * m_texture
Definition: painterogl.h:110
PainterOGL::updateGlClipRect
void updateGlClipRect()
Definition: painterogl.cpp:295
PainterOGL::PainterState::blendEquation
Painter::BlendEquation blendEquation
Definition: painterogl.h:39
PainterOGL::PainterState::projectionMatrix
Matrix3 projectionMatrix
Definition: painterogl.h:34
PainterOGL::PainterState::alphaWriting
bool alphaWriting
Definition: painterogl.h:43
PainterOGL::m_coordsBuffer
CoordsBuffer m_coordsBuffer
Definition: painterogl.h:102
PainterOGL::bind
virtual void bind()
Definition: painterogl.h:49
PainterOGL::setResolution
void setResolution(const Size &resolution)
Definition: painterogl.cpp:173
PainterOGL::resetTexture
void resetTexture()
Definition: painterogl.h:90
PainterOGL::setTexture
void setTexture(const TexturePtr &texture)
Definition: painterogl.h:71
PainterOGL::PainterState::texture
Texture * texture
Definition: painterogl.h:41
PainterOGL::PainterState::clipRect
Rect clipRect
Definition: painterogl.h:40
PainterOGL::m_olderStates
PainterState m_olderStates[10]
Definition: painterogl.h:113
PainterOGL::setClipRect
virtual void setClipRect(const Rect &clipRect)
Definition: painterogl.cpp:136
PainterOGL::PainterState::resolution
Size resolution
Definition: painterogl.h:32
PainterOGL::getTextureMatrix
Matrix3 getTextureMatrix()
Definition: painterogl.h:84
PainterOGL::getShaderProgram
PainterShaderProgram * getShaderProgram()
Definition: painterogl.h:86
PainterOGL::PainterState
Definition: painterogl.h:31
PainterOGL::getProjectionMatrix
Matrix3 getProjectionMatrix()
Definition: painterogl.h:83
Painter::CompositionMode
CompositionMode
Definition: painter.h:38
painter.h
PainterOGL::m_alphaWriting
bool m_alphaWriting
Definition: painterogl.h:111
PainterOGL::restoreSavedState
void restoreSavedState()
Definition: painterogl.cpp:88
PainterOGL::resetAlphaWriting
void resetAlphaWriting()
Definition: painterogl.h:91
PainterOGL::PainterState::color
Color color
Definition: painterogl.h:36
PainterOGL::updateGlTexture
void updateGlTexture()
Definition: painterogl.cpp:252
uint
unsigned int uint
Definition: types.h:31
PainterOGL::getTransformMatrix
Matrix3 getTransformMatrix()
Definition: painterogl.h:82
PainterOGL::updateGlBlendEquation
void updateGlBlendEquation()
Definition: painterogl.cpp:285
PainterOGL::translate
void translate(float x, float y)
Definition: painterogl.cpp:210
PainterOGL::m_glTextureId
uint m_glTextureId
Definition: painterogl.h:116
Painter
Definition: painter.h:31
PainterOGL::PainterState::shaderProgram
PainterShaderProgram * shaderProgram
Definition: painterogl.h:42
PainterOGL::clear
void clear(const Color &color)
Definition: painterogl.cpp:105
PainterOGL::~PainterOGL
virtual ~PainterOGL()
Definition: painterogl.h:47
Painter::BlendEquation
BlendEquation
Definition: painter.h:34
PainterOGL::m_transformMatrix
Matrix3 m_transformMatrix
Definition: painterogl.h:105
PainterShaderProgram
Definition: paintershaderprogram.h:30
Matrix3
Matrix3x3 Matrix3
Definition: matrix.h:243
PainterOGL::PainterState::opacity
float opacity
Definition: painterogl.h:37
PainterOGL::getAlphaWriting
bool getAlphaWriting()
Definition: painterogl.h:87
PainterOGL::setTextureMatrix
virtual void setTextureMatrix(const Matrix3 &textureMatrix)
Definition: painterogl.h:63
PainterOGL::setShaderProgram
virtual void setShaderProgram(PainterShaderProgram *shaderProgram)
Definition: painterogl.h:67
PainterOGL::updateGlAlphaWriting
void updateGlAlphaWriting()
Definition: painterogl.cpp:306
PainterOGL::clearRect
void clearRect(const Color &color, const Rect &rect)
Definition: painterogl.cpp:111
PainterOGL::setCompositionMode
virtual void setCompositionMode(CompositionMode compositionMode)
Definition: painterogl.cpp:120
PainterOGL::m_blendEquation
BlendEquation m_blendEquation
Definition: painterogl.h:109
stdext::shared_object_ptr< Texture >
CoordsBuffer
Definition: coordsbuffer.h:29
PainterOGL::setProjectionMatrix
virtual void setProjectionMatrix(const Matrix3 &projectionMatrix)
Definition: painterogl.h:62
PainterOGL::PainterState::transformMatrix
Matrix3 transformMatrix
Definition: painterogl.h:33
PainterOGL::m_projectionMatrix
Matrix3 m_projectionMatrix
Definition: painterogl.h:106
PainterOGL::resetBlendEquation
void resetBlendEquation()
Definition: painterogl.h:89
PainterOGL::setTexture
virtual void setTexture(Texture *texture)
Definition: painterogl.cpp:144
PainterOGL::popTransformMatrix
void popTransformMatrix()
Definition: painterogl.cpp:245
PainterOGL::resetTransformMatrix
void resetTransformMatrix()
Definition: painterogl.h:92
PainterOGL::saveState
void saveState()
Definition: painterogl.cpp:64
Matrix
Definition: matrix.h:32
PainterOGL::setBlendEquation
virtual void setBlendEquation(BlendEquation blendEquation)
Definition: painterogl.cpp:128
PainterOGL::PainterState::textureMatrix
Matrix3 textureMatrix
Definition: painterogl.h:35
PainterOGL::saveAndResetState
void saveAndResetState()
Definition: painterogl.cpp:82
PainterOGL::setTransformMatrix
virtual void setTransformMatrix(const Matrix3 &transformMatrix)
Definition: painterogl.h:61
TSize< int >
PainterOGL::setAlphaWriting
virtual void setAlphaWriting(bool enable)
Definition: painterogl.cpp:164
PainterOGL::updateGlViewport
void updateGlViewport()
Definition: painterogl.cpp:314
PainterOGL::rotate
void rotate(float angle)
Definition: painterogl.cpp:221
Painter::m_shaderProgram
PainterShaderProgram * m_shaderProgram
Definition: painter.h:114
PainterOGL::scale
void scale(float x, float y)
Definition: painterogl.cpp:199
stdext::shared_object_ptr::get
T * get() const
Definition: shared_object.h:82
PainterOGL
Definition: painterogl.h:28
PainterOGL::m_oldStateIndex
int m_oldStateIndex
Definition: painterogl.h:114
PainterOGL::updateGlCompositionMode
void updateGlCompositionMode()
Definition: painterogl.cpp:258
PainterOGL::getBlendEquation
BlendEquation getBlendEquation()
Definition: painterogl.h:85
PainterOGL::refreshState
virtual void refreshState()
Definition: painterogl.cpp:54