Otclient  14/8/2020
coordsbuffer.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 COORDSBUFFER_H
24 #define COORDSBUFFER_H
25 
26 #include "vertexarray.h"
27 #include "hardwarebuffer.h"
28 
30 {
31  enum {
32  CACHE_MIN_VERTICES_COUNT = 48
33  };
34 public:
35  CoordsBuffer();
36  ~CoordsBuffer();
37 
38  void clear() {
39  m_textureCoordArray.clear();
40  m_vertexArray.clear();
41  m_hardwareCached = false;
42  }
43 
44  void addTriangle(const Point& a, const Point& b, const Point& c) {
45  m_vertexArray.addTriangle(a, b, c);
46  m_hardwareCached = false;
47  }
48  void addRect(const Rect& dest) {
49  m_vertexArray.addRect(dest);
50  m_hardwareCached = false;
51  }
52  void addRect(const Rect& dest, const Rect& src) {
53  m_vertexArray.addRect(dest);
54  m_textureCoordArray.addRect(src);
55  m_hardwareCached = false;
56  }
57  void addQuad(const Rect& dest, const Rect& src) {
58  m_vertexArray.addQuad(dest);
59  m_textureCoordArray.addQuad(src);
60  m_hardwareCached = false;
61  }
62  void addUpsideDownQuad(const Rect& dest, const Rect& src) {
63  m_vertexArray.addUpsideDownQuad(dest);
64  m_textureCoordArray.addQuad(src);
65  m_hardwareCached = false;
66  }
67 
68  void addBoudingRect(const Rect& dest, int innerLineWidth);
69  void addRepeatedRects(const Rect& dest, const Rect& src);
70 
72  void updateCaches();
73  bool isHardwareCached() { return m_hardwareCached; }
74 
75  float *getVertexArray() { return m_vertexArray.vertices(); }
76  float *getTextureCoordArray() { return m_textureCoordArray.vertices(); }
77  int getVertexCount() { return m_vertexArray.vertexCount(); }
78  int getTextureCoordCount() { return m_textureCoordArray.vertexCount(); }
79 
80  HardwareBuffer *getHardwareVertexArray() { return m_hardwareVertexArray; }
81  HardwareBuffer *getHardwareTextureCoordArray() { return m_hardwareTextureCoordArray; }
82 
83 private:
84  HardwareBuffer *m_hardwareVertexArray;
85  HardwareBuffer *m_hardwareTextureCoordArray;
86  HardwareBuffer::UsagePattern m_hardwareCacheMode;
87  VertexArray m_vertexArray;
88  VertexArray m_textureCoordArray;
89  bool m_hardwareCached;
90  bool m_hardwareCaching;
91 };
92 
93 #endif
HardwareBuffer::DynamicDraw
@ DynamicDraw
Definition: hardwarebuffer.h:40
CoordsBuffer::addRepeatedRects
void addRepeatedRects(const Rect &dest, const Rect &src)
Definition: coordsbuffer.cpp:57
hardwarebuffer.h
CoordsBuffer::getVertexArray
float * getVertexArray()
Definition: coordsbuffer.h:75
TRect< int >
VertexArray::addTriangle
void addTriangle(const Point &a, const Point &b, const Point &c)
Definition: vertexarray.h:33
CoordsBuffer::addUpsideDownQuad
void addUpsideDownQuad(const Rect &dest, const Rect &src)
Definition: coordsbuffer.h:62
VertexArray
Definition: vertexarray.h:29
CoordsBuffer::getTextureCoordCount
int getTextureCoordCount()
Definition: coordsbuffer.h:78
CoordsBuffer::addRect
void addRect(const Rect &dest, const Rect &src)
Definition: coordsbuffer.h:52
CoordsBuffer::enableHardwareCaching
void enableHardwareCaching(HardwareBuffer::UsagePattern usagePattern=HardwareBuffer::DynamicDraw)
Definition: coordsbuffer.cpp:86
CoordsBuffer::~CoordsBuffer
~CoordsBuffer()
Definition: coordsbuffer.cpp:35
HardwareBuffer::UsagePattern
UsagePattern
Definition: hardwarebuffer.h:37
HardwareBuffer
Definition: hardwarebuffer.h:29
CoordsBuffer::getVertexCount
int getVertexCount()
Definition: coordsbuffer.h:77
VertexArray::vertexCount
int vertexCount() const
Definition: vertexarray.h:78
CoordsBuffer::updateCaches
void updateCaches()
Definition: coordsbuffer.cpp:96
CoordsBuffer::isHardwareCached
bool isHardwareCached()
Definition: coordsbuffer.h:73
vertexarray.h
VertexArray::clear
void clear()
Definition: vertexarray.h:76
CoordsBuffer::clear
void clear()
Definition: coordsbuffer.h:38
VertexArray::addUpsideDownQuad
void addUpsideDownQuad(const Rect &rect)
Definition: vertexarray.h:64
CoordsBuffer::addBoudingRect
void addBoudingRect(const Rect &dest, int innerLineWidth)
Definition: coordsbuffer.cpp:41
CoordsBuffer::getHardwareTextureCoordArray
HardwareBuffer * getHardwareTextureCoordArray()
Definition: coordsbuffer.h:81
VertexArray::addRect
void addRect(const Rect &rect)
Definition: vertexarray.h:38
CoordsBuffer::CoordsBuffer
CoordsBuffer()
Definition: coordsbuffer.cpp:26
CoordsBuffer
Definition: coordsbuffer.h:29
VertexArray::vertices
float * vertices() const
Definition: vertexarray.h:77
CoordsBuffer::addRect
void addRect(const Rect &dest)
Definition: coordsbuffer.h:48
CoordsBuffer::getHardwareVertexArray
HardwareBuffer * getHardwareVertexArray()
Definition: coordsbuffer.h:80
TPoint< int >
CoordsBuffer::addQuad
void addQuad(const Rect &dest, const Rect &src)
Definition: coordsbuffer.h:57
CoordsBuffer::getTextureCoordArray
float * getTextureCoordArray()
Definition: coordsbuffer.h:76
CoordsBuffer::addTriangle
void addTriangle(const Point &a, const Point &b, const Point &c)
Definition: coordsbuffer.h:44
VertexArray::addQuad
void addQuad(const Rect &rect)
Definition: vertexarray.h:52