2011-12-07 19:49:20 +01:00
|
|
|
/*
|
2013-01-08 19:21:54 +01:00
|
|
|
* Copyright (c) 2010-2013 OTClient <https://github.com/edubart/otclient>
|
2011-12-07 19:49:20 +01:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef COORDSBUFFER_H
|
|
|
|
#define COORDSBUFFER_H
|
|
|
|
|
|
|
|
#include "vertexarray.h"
|
2012-03-20 20:10:04 +01:00
|
|
|
#include "hardwarebuffer.h"
|
2011-12-07 19:49:20 +01:00
|
|
|
|
|
|
|
class CoordsBuffer
|
|
|
|
{
|
2012-04-24 23:05:46 +02:00
|
|
|
enum {
|
|
|
|
CACHE_MIN_VERTICES_COUNT = 48
|
|
|
|
};
|
2011-12-07 19:49:20 +01:00
|
|
|
public:
|
2012-03-20 20:10:04 +01:00
|
|
|
CoordsBuffer();
|
|
|
|
~CoordsBuffer();
|
2011-12-07 19:49:20 +01:00
|
|
|
|
2012-03-20 20:10:04 +01:00
|
|
|
void clear() {
|
2012-04-19 01:03:43 +02:00
|
|
|
m_textureCoordArray.clear();
|
|
|
|
m_vertexArray.clear();
|
2012-03-20 20:10:04 +01:00
|
|
|
m_hardwareCached = false;
|
|
|
|
}
|
|
|
|
|
2012-06-10 08:09:37 +02:00
|
|
|
void addTriangle(const Point& a, const Point& b, const Point& c) {
|
|
|
|
m_vertexArray.addTriangle(a, b, c);
|
|
|
|
m_hardwareCached = false;
|
|
|
|
}
|
2012-03-20 20:10:04 +01:00
|
|
|
void addRect(const Rect& dest) {
|
2012-04-19 01:03:43 +02:00
|
|
|
m_vertexArray.addRect(dest);
|
2012-03-20 20:10:04 +01:00
|
|
|
m_hardwareCached = false;
|
|
|
|
}
|
|
|
|
void addRect(const Rect& dest, const Rect& src) {
|
2012-04-19 01:03:43 +02:00
|
|
|
m_vertexArray.addRect(dest);
|
|
|
|
m_textureCoordArray.addRect(src);
|
2012-03-20 20:10:04 +01:00
|
|
|
m_hardwareCached = false;
|
|
|
|
}
|
2012-04-08 21:28:03 +02:00
|
|
|
void addQuad(const Rect& dest, const Rect& src) {
|
2012-04-19 01:03:43 +02:00
|
|
|
m_vertexArray.addQuad(dest);
|
|
|
|
m_textureCoordArray.addQuad(src);
|
2012-04-08 21:28:03 +02:00
|
|
|
m_hardwareCached = false;
|
|
|
|
}
|
2013-01-08 22:31:41 +01:00
|
|
|
void addUpsideDownQuad(const Rect& dest, const Rect& src) {
|
|
|
|
m_vertexArray.addUpsideDownQuad(dest);
|
|
|
|
m_textureCoordArray.addQuad(src);
|
|
|
|
m_hardwareCached = false;
|
|
|
|
}
|
2011-12-07 19:49:20 +01:00
|
|
|
|
2012-03-20 20:10:04 +01:00
|
|
|
void addBoudingRect(const Rect& dest, int innerLineWidth);
|
2011-12-07 19:49:20 +01:00
|
|
|
void addRepeatedRects(const Rect& dest, const Rect& src);
|
|
|
|
|
2012-03-20 20:10:04 +01:00
|
|
|
void enableHardwareCaching(HardwareBuffer::UsagePattern usagePattern = HardwareBuffer::DynamicDraw);
|
|
|
|
void updateCaches();
|
|
|
|
bool isHardwareCached() { return m_hardwareCached; }
|
|
|
|
|
2012-06-17 17:21:46 +02:00
|
|
|
float *getVertexArray() { return m_vertexArray.vertices(); }
|
|
|
|
float *getTextureCoordArray() { return m_textureCoordArray.vertices(); }
|
|
|
|
int getVertexCount() { return m_vertexArray.vertexCount(); }
|
|
|
|
int getTextureCoordCount() { return m_textureCoordArray.vertexCount(); }
|
2011-12-07 19:49:20 +01:00
|
|
|
|
2012-04-19 01:03:43 +02:00
|
|
|
HardwareBuffer *getHardwareVertexArray() { return m_hardwareVertexArray; }
|
|
|
|
HardwareBuffer *getHardwareTextureCoordArray() { return m_hardwareTextureCoordArray; }
|
2011-12-07 19:49:20 +01:00
|
|
|
|
|
|
|
private:
|
2012-04-19 01:03:43 +02:00
|
|
|
HardwareBuffer *m_hardwareVertexArray;
|
|
|
|
HardwareBuffer *m_hardwareTextureCoordArray;
|
2012-03-20 20:10:04 +01:00
|
|
|
HardwareBuffer::UsagePattern m_hardwareCacheMode;
|
2012-04-19 01:03:43 +02:00
|
|
|
VertexArray m_vertexArray;
|
|
|
|
VertexArray m_textureCoordArray;
|
2012-03-20 20:10:04 +01:00
|
|
|
bool m_hardwareCached;
|
|
|
|
bool m_hardwareCaching;
|
2011-12-07 19:49:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|