coordsbuffer.h

main 110 lines · 3.6 KB Raw
Alex Alex Commit Client Upload Part 2 19/10/2026 00:06
1/*
2 * Copyright (c) 2010-2017 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
28class CoordsBuffer
29{
30public:
31 CoordsBuffer();
32 ~CoordsBuffer();
33 CoordsBuffer(CoordsBuffer& c) = delete;
34 CoordsBuffer& operator=(CoordsBuffer& c) = delete;
35 CoordsBuffer(CoordsBuffer&& c) noexcept : m_vertexArray(c.m_vertexArray), m_textureCoordArray(c.m_textureCoordArray)
36 {
37 m_locked = c.m_locked = true;
38 };
39
40 void clear() {
41 if (m_locked)
42 unlock(true);
43 m_textureCoordArray->clear();
44 m_vertexArray->clear();
45 }
46
47 void addTriangle(const Point& a, const Point& b, const Point& c) {
48 if (m_locked)
49 unlock();
50 m_vertexArray->addTriangle(a, b, c);
51 }
52 void addRect(const Rect& dest) {
53 if (m_locked)
54 unlock();
55 m_vertexArray->addRect(dest);
56 }
57 void addRect(const Rect& dest, const Rect& src)
58 {
59 if (m_locked)
60 unlock();
61 m_vertexArray->addRect(dest);
62 m_textureCoordArray->addRect(src);
63 }
64 void addRect(const RectF& dest, const RectF& src)
65 {
66 if (m_locked)
67 unlock();
68 m_vertexArray->addRect(dest);
69 m_textureCoordArray->addRect(src);
70 }
71 void addQuad(const Rect& dest, const Rect& src) {
72 if (m_locked)
73 unlock();
74 m_vertexArray->addQuad(dest);
75 m_textureCoordArray->addQuad(src);
76 }
77 void addUpsideDownQuad(const Rect& dest, const Rect& src) {
78 if (m_locked)
79 unlock();
80 m_vertexArray->addUpsideDownQuad(dest);
81 m_textureCoordArray->addQuad(src);
82 }
83
84 void addBoudingRect(const Rect& dest, int innerLineWidth);
85 void addRepeatedRects(const Rect& dest, const Rect& src);
86
87 float *getVertexArray() { return m_vertexArray->vertices(); }
88 float *getTextureCoordArray() { return m_textureCoordArray->vertices(); }
89 int getVertexCount() { return m_vertexArray->vertexCount(); }
90 int getTextureCoordCount() { return m_textureCoordArray->vertexCount(); }
91 HardwareBuffer* getVertexHardwareCache() { return m_vertexArray->getHardwareCache(); }
92 HardwareBuffer* getTextureHardwareCache() { return m_textureCoordArray->getHardwareCache(); }
93
94 void unlock(bool clear = false);
95 void cache()
96 {
97 m_locked = true;
98 m_vertexArray->cache();
99 m_textureCoordArray->cache();
100 }
101 Rect getTextureRect();
102
103private:
104 bool m_locked = false;
105 std::shared_ptr<VertexArray> m_vertexArray;
106 std::shared_ptr<VertexArray> m_textureCoordArray;
107};
108
109#endif
110
Top