use vertex buffers
This commit is contained in:
parent
cc7c334d73
commit
1a3dcb215e
7
TODO
7
TODO
|
@ -31,4 +31,9 @@ restore win32 platform
|
||||||
set special types for g_configs like lists/point/size
|
set special types for g_configs like lists/point/size
|
||||||
restore ctrl+g and keybindings
|
restore ctrl+g and keybindings
|
||||||
create a class for reading binary files
|
create a class for reading binary files
|
||||||
handle corrupt errors in dat/spr
|
handle corrupt errors in dat/spr
|
||||||
|
|
||||||
|
use CoordsBuffer in font
|
||||||
|
cache into framebuffers
|
||||||
|
implement glbuffer for CoordsBuffer
|
||||||
|
use indices in CoordsBuffer
|
|
@ -146,6 +146,7 @@ SET(framework_SOURCES ${framework_SOURCES}
|
||||||
${CMAKE_CURRENT_LIST_DIR}/graphics/shader.cpp
|
${CMAKE_CURRENT_LIST_DIR}/graphics/shader.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/graphics/shaderprogram.cpp
|
${CMAKE_CURRENT_LIST_DIR}/graphics/shaderprogram.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/graphics/paintershaderprogram.cpp
|
${CMAKE_CURRENT_LIST_DIR}/graphics/paintershaderprogram.cpp
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/graphics/coordsbuffer.cpp
|
||||||
|
|
||||||
# framework otml
|
# framework otml
|
||||||
${CMAKE_CURRENT_LIST_DIR}/otml/otmldocument.cpp
|
${CMAKE_CURRENT_LIST_DIR}/otml/otmldocument.cpp
|
||||||
|
|
|
@ -133,67 +133,72 @@ BorderImagePtr BorderImage::loadFromOTML(const OTMLNodePtr& borderImageNode)
|
||||||
void BorderImage::draw(const Rect& screenCoords)
|
void BorderImage::draw(const Rect& screenCoords)
|
||||||
{
|
{
|
||||||
//TODO: borderimage drawing could be optimized by caching the render into a texture
|
//TODO: borderimage drawing could be optimized by caching the render into a texture
|
||||||
|
if(screenCoords != m_cachedScreenCoords) {
|
||||||
|
m_cachedScreenCoords = screenCoords;
|
||||||
|
m_coordsBuffer.clear();
|
||||||
|
|
||||||
Rect rectCoords;
|
Rect rectCoords;
|
||||||
Size centerSize = screenCoords.size() - m_bordersSize;
|
Size centerSize = screenCoords.size() - m_bordersSize;
|
||||||
|
|
||||||
// first the center
|
// first the center
|
||||||
if(centerSize.area() > 0) {
|
if(centerSize.area() > 0) {
|
||||||
rectCoords = Rect(screenCoords.left() + m_leftBorderTexCoords.width(),
|
rectCoords = Rect(screenCoords.left() + m_leftBorderTexCoords.width(),
|
||||||
screenCoords.top() + m_topBorderTexCoords.height(),
|
screenCoords.top() + m_topBorderTexCoords.height(),
|
||||||
centerSize);
|
centerSize);
|
||||||
g_painter.drawRepeatedTexturedRect(rectCoords, m_texture, m_centerTexCoords);
|
m_coordsBuffer.addRepeatedRects(rectCoords, m_centerTexCoords);
|
||||||
|
}
|
||||||
|
|
||||||
|
// top left corner
|
||||||
|
rectCoords = Rect(screenCoords.topLeft(),
|
||||||
|
m_topLeftCornerTexCoords.size());
|
||||||
|
m_coordsBuffer.addRepeatedRects(rectCoords, m_topLeftCornerTexCoords);
|
||||||
|
|
||||||
|
// top
|
||||||
|
rectCoords = Rect(screenCoords.left() + m_topLeftCornerTexCoords.width(),
|
||||||
|
screenCoords.topLeft().y,
|
||||||
|
centerSize.width(),
|
||||||
|
m_topBorderTexCoords.height());
|
||||||
|
m_coordsBuffer.addRepeatedRects(rectCoords, m_topBorderTexCoords);
|
||||||
|
|
||||||
|
|
||||||
|
// top right corner
|
||||||
|
rectCoords = Rect(screenCoords.left() + m_topLeftCornerTexCoords.width() + centerSize.width(),
|
||||||
|
screenCoords.top(),
|
||||||
|
m_topRightCornerTexCoords.size());
|
||||||
|
m_coordsBuffer.addRepeatedRects(rectCoords, m_topRightCornerTexCoords);
|
||||||
|
|
||||||
|
// left
|
||||||
|
rectCoords = Rect(screenCoords.left(),
|
||||||
|
screenCoords.top() + m_topLeftCornerTexCoords.height(),
|
||||||
|
m_leftBorderTexCoords.width(),
|
||||||
|
centerSize.height());
|
||||||
|
m_coordsBuffer.addRepeatedRects(rectCoords, m_leftBorderTexCoords);
|
||||||
|
|
||||||
|
// right
|
||||||
|
rectCoords = Rect(screenCoords.left() + m_leftBorderTexCoords.width() + centerSize.width(),
|
||||||
|
screenCoords.top() + m_topRightCornerTexCoords.height(),
|
||||||
|
m_rightBorderTexCoords.width(),
|
||||||
|
centerSize.height());
|
||||||
|
m_coordsBuffer.addRepeatedRects(rectCoords, m_rightBorderTexCoords);
|
||||||
|
|
||||||
|
// bottom left corner
|
||||||
|
rectCoords = Rect(screenCoords.left(),
|
||||||
|
screenCoords.top() + m_topLeftCornerTexCoords.height() + centerSize.height(),
|
||||||
|
m_bottomLeftCornerTexCoords.size());
|
||||||
|
m_coordsBuffer.addRepeatedRects(rectCoords, m_bottomLeftCornerTexCoords);
|
||||||
|
|
||||||
|
// bottom
|
||||||
|
rectCoords = Rect(screenCoords.left() + m_bottomLeftCornerTexCoords.width(),
|
||||||
|
screenCoords.top() + m_topBorderTexCoords.height() + centerSize.height(),
|
||||||
|
centerSize.width(),
|
||||||
|
m_bottomBorderTexCoords.height());
|
||||||
|
m_coordsBuffer.addRepeatedRects(rectCoords, m_bottomBorderTexCoords);
|
||||||
|
|
||||||
|
// bottom right corner
|
||||||
|
rectCoords = Rect(screenCoords.left() + m_bottomLeftCornerTexCoords.width() + centerSize.width(),
|
||||||
|
screenCoords.top() + m_topRightCornerTexCoords.height() + centerSize.height(),
|
||||||
|
m_bottomRightCornerTexCoords.size());
|
||||||
|
m_coordsBuffer.addRepeatedRects(rectCoords, m_bottomRightCornerTexCoords);
|
||||||
}
|
}
|
||||||
|
g_painter.drawTextureCoords(m_coordsBuffer, m_texture);
|
||||||
// top left corner
|
|
||||||
rectCoords = Rect(screenCoords.topLeft(),
|
|
||||||
m_topLeftCornerTexCoords.size());
|
|
||||||
g_painter.drawTexturedRect(rectCoords, m_texture, m_topLeftCornerTexCoords);
|
|
||||||
|
|
||||||
// top
|
|
||||||
rectCoords = Rect(screenCoords.left() + m_topLeftCornerTexCoords.width(),
|
|
||||||
screenCoords.topLeft().y,
|
|
||||||
centerSize.width(),
|
|
||||||
m_topBorderTexCoords.height());
|
|
||||||
g_painter.drawRepeatedTexturedRect(rectCoords, m_texture, m_topBorderTexCoords);
|
|
||||||
|
|
||||||
|
|
||||||
// top right corner
|
|
||||||
rectCoords = Rect(screenCoords.left() + m_topLeftCornerTexCoords.width() + centerSize.width(),
|
|
||||||
screenCoords.top(),
|
|
||||||
m_topRightCornerTexCoords.size());
|
|
||||||
g_painter.drawTexturedRect(rectCoords, m_texture, m_topRightCornerTexCoords);
|
|
||||||
|
|
||||||
// left
|
|
||||||
rectCoords = Rect(screenCoords.left(),
|
|
||||||
screenCoords.top() + m_topLeftCornerTexCoords.height(),
|
|
||||||
m_leftBorderTexCoords.width(),
|
|
||||||
centerSize.height());
|
|
||||||
g_painter.drawRepeatedTexturedRect(rectCoords, m_texture, m_leftBorderTexCoords);
|
|
||||||
|
|
||||||
// right
|
|
||||||
rectCoords = Rect(screenCoords.left() + m_leftBorderTexCoords.width() + centerSize.width(),
|
|
||||||
screenCoords.top() + m_topRightCornerTexCoords.height(),
|
|
||||||
m_rightBorderTexCoords.width(),
|
|
||||||
centerSize.height());
|
|
||||||
g_painter.drawRepeatedTexturedRect(rectCoords, m_texture, m_rightBorderTexCoords);
|
|
||||||
|
|
||||||
// bottom left corner
|
|
||||||
rectCoords = Rect(screenCoords.left(),
|
|
||||||
screenCoords.top() + m_topLeftCornerTexCoords.height() + centerSize.height(),
|
|
||||||
m_bottomLeftCornerTexCoords.size());
|
|
||||||
g_painter.drawTexturedRect(rectCoords, m_texture, m_bottomLeftCornerTexCoords);
|
|
||||||
|
|
||||||
// bottom
|
|
||||||
rectCoords = Rect(screenCoords.left() + m_bottomLeftCornerTexCoords.width(),
|
|
||||||
screenCoords.top() + m_topBorderTexCoords.height() + centerSize.height(),
|
|
||||||
centerSize.width(),
|
|
||||||
m_bottomBorderTexCoords.height());
|
|
||||||
g_painter.drawRepeatedTexturedRect(rectCoords, m_texture, m_bottomBorderTexCoords);
|
|
||||||
|
|
||||||
// bottom right corner
|
|
||||||
rectCoords = Rect(screenCoords.left() + m_bottomLeftCornerTexCoords.width() + centerSize.width(),
|
|
||||||
screenCoords.top() + m_topRightCornerTexCoords.height() + centerSize.height(),
|
|
||||||
m_bottomRightCornerTexCoords.size());
|
|
||||||
g_painter.drawTexturedRect(rectCoords, m_texture, m_bottomRightCornerTexCoords);
|
|
||||||
}
|
}
|
|
@ -0,0 +1,110 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "coordsbuffer.h"
|
||||||
|
|
||||||
|
void CoordsBuffer::clear()
|
||||||
|
{
|
||||||
|
m_destRects.reset();
|
||||||
|
m_srcRects.reset();
|
||||||
|
m_textureCoords.clear();
|
||||||
|
m_vertexCoords.clear();
|
||||||
|
m_updateCache = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoordsBuffer::addRect(const Rect& dest)
|
||||||
|
{
|
||||||
|
m_destRects << dest;
|
||||||
|
m_updateCache = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoordsBuffer::addRect(const Rect& dest, const Rect& src)
|
||||||
|
{
|
||||||
|
m_destRects << dest;
|
||||||
|
m_srcRects << src;
|
||||||
|
m_updateCache = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoordsBuffer::addBoudingRect(const Rect& dest, int innerLineWidth)
|
||||||
|
{
|
||||||
|
int left = dest.left();
|
||||||
|
int right = dest.right();
|
||||||
|
int top = dest.top();
|
||||||
|
int bottom = dest.bottom();
|
||||||
|
int width = dest.width();
|
||||||
|
int height = dest.height();
|
||||||
|
int w = innerLineWidth;
|
||||||
|
|
||||||
|
addRect(Rect(left, top, width - w, w)); // top
|
||||||
|
addRect(Rect(right - w + 1, top, w, height - w)); // right
|
||||||
|
addRect(Rect(left + w, bottom - w + 1, width - w, w)); // bottom
|
||||||
|
addRect(Rect(left, top + w, w, height - w)); // left
|
||||||
|
m_updateCache = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoordsBuffer::addRepeatedRects(const Rect& dest, const Rect& src)
|
||||||
|
{
|
||||||
|
if(dest.isEmpty() || src.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
Rect virtualDest(0, 0, dest.size());
|
||||||
|
for(int y = 0; y <= virtualDest.height(); y += src.height()) {
|
||||||
|
for(int x = 0; x <= virtualDest.width(); x += src.width()) {
|
||||||
|
Rect partialDest(x, y, src.size());
|
||||||
|
Rect partialSrc(src);
|
||||||
|
|
||||||
|
// partialCoords to screenCoords bottomRight
|
||||||
|
if(partialDest.bottom() > virtualDest.bottom()) {
|
||||||
|
partialSrc.setBottom(partialSrc.bottom() + (virtualDest.bottom() - partialDest.bottom()));
|
||||||
|
partialDest.setBottom(virtualDest.bottom());
|
||||||
|
}
|
||||||
|
if(partialDest.right() > virtualDest.right()) {
|
||||||
|
partialSrc.setRight(partialSrc.right() + (virtualDest.right() - partialDest.right()));
|
||||||
|
partialDest.setRight(virtualDest.right());
|
||||||
|
}
|
||||||
|
|
||||||
|
partialDest.translate(dest.topLeft());
|
||||||
|
m_destRects << partialDest;
|
||||||
|
m_srcRects << partialSrc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_updateCache = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoordsBuffer::cacheVertexArrays()
|
||||||
|
{
|
||||||
|
if(!m_updateCache)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int numDestRects = m_destRects.size();
|
||||||
|
int numSrcRects = m_srcRects.size();
|
||||||
|
m_vertexCoords.clear();
|
||||||
|
m_textureCoords.clear();
|
||||||
|
|
||||||
|
for(int i=0;i<numDestRects;++i) {
|
||||||
|
m_vertexCoords.addRect(m_destRects[i]);
|
||||||
|
if(numSrcRects == numDestRects)
|
||||||
|
m_textureCoords.addRect(m_srcRects[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_updateCache = false;
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
|
||||||
|
*
|
||||||
|
* 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"
|
||||||
|
|
||||||
|
class CoordsBuffer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
// no texture
|
||||||
|
void addRect(const Rect& dest);
|
||||||
|
void addBoudingRect(const Rect& dest, int innerLineWidth);
|
||||||
|
|
||||||
|
// textured
|
||||||
|
void addRect(const Rect& dest, const Rect& src);
|
||||||
|
void addRepeatedRects(const Rect& dest, const Rect& src);
|
||||||
|
|
||||||
|
void cacheVertexArrays();
|
||||||
|
|
||||||
|
GLfloat *getVertexCoords() const { return m_vertexCoords.vertexArray(); }
|
||||||
|
GLfloat *getTextureCoords() const { return m_textureCoords.vertexArray(); }
|
||||||
|
int getVertexCount() const { return m_vertexCoords.vertexCount(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
DataBuffer<Rect> m_destRects;
|
||||||
|
DataBuffer<Rect> m_srcRects;
|
||||||
|
VertexArray m_vertexCoords;
|
||||||
|
VertexArray m_textureCoords;
|
||||||
|
Boolean<true> m_updateCache;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "glbuffer.h"
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
|
||||||
|
*
|
||||||
|
* 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 GLBUFFER_H
|
||||||
|
#define GLBUFFER_H
|
||||||
|
|
||||||
|
class GLBuffer
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -52,7 +52,13 @@ void Image::loadFromOTML(const OTMLNodePtr& imageNode)
|
||||||
|
|
||||||
void Image::draw(const Rect& screenCoords)
|
void Image::draw(const Rect& screenCoords)
|
||||||
{
|
{
|
||||||
if(m_texture) {
|
if(!m_texture)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(m_cachedScreenCoords != screenCoords) {
|
||||||
|
m_cachedScreenCoords = screenCoords;
|
||||||
|
m_coordsBuffer.clear();
|
||||||
|
|
||||||
if(m_fixedRatio) {
|
if(m_fixedRatio) {
|
||||||
const Size& texSize = m_texture->getSize();
|
const Size& texSize = m_texture->getSize();
|
||||||
Size texCoordsSize = screenCoords.size();
|
Size texCoordsSize = screenCoords.size();
|
||||||
|
@ -63,12 +69,14 @@ void Image::draw(const Rect& screenCoords)
|
||||||
else if(texSize.width() > texCoordsSize.width())
|
else if(texSize.width() > texCoordsSize.width())
|
||||||
texCoordsOffset.x = (texSize.width() - texCoordsSize.width())/2;
|
texCoordsOffset.x = (texSize.width() - texCoordsSize.width())/2;
|
||||||
|
|
||||||
g_painter.drawTexturedRect(screenCoords, m_texture, Rect(texCoordsOffset, texCoordsSize));
|
m_coordsBuffer.addRect(screenCoords, Rect(texCoordsOffset, texCoordsSize));
|
||||||
} else {
|
} else {
|
||||||
if(m_repeated)
|
if(m_repeated)
|
||||||
g_painter.drawRepeatedTexturedRect(screenCoords, m_texture, m_textureCoords);
|
m_coordsBuffer.addRepeatedRects(screenCoords, m_textureCoords);
|
||||||
else
|
else
|
||||||
g_painter.drawTexturedRect(screenCoords, m_texture, m_textureCoords);
|
m_coordsBuffer.addRect(screenCoords, m_textureCoords);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_painter.drawTextureCoords(m_coordsBuffer, m_texture);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#define IMAGE_H
|
#define IMAGE_H
|
||||||
|
|
||||||
#include "declarations.h"
|
#include "declarations.h"
|
||||||
|
#include "coordsbuffer.h"
|
||||||
|
|
||||||
#include <framework/otml/declarations.h>
|
#include <framework/otml/declarations.h>
|
||||||
|
|
||||||
|
@ -41,6 +42,9 @@ protected:
|
||||||
Rect m_textureCoords;
|
Rect m_textureCoords;
|
||||||
bool m_fixedRatio;
|
bool m_fixedRatio;
|
||||||
bool m_repeated;
|
bool m_repeated;
|
||||||
|
|
||||||
|
Rect m_cachedScreenCoords;
|
||||||
|
CoordsBuffer m_coordsBuffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "paintershaderprogram.h"
|
#include "paintershaderprogram.h"
|
||||||
#include "shaderprogram.h"
|
#include "shaderprogram.h"
|
||||||
#include "graphics.h"
|
#include "graphics.h"
|
||||||
|
#include "vertexarray.h"
|
||||||
|
|
||||||
Painter g_painter;
|
Painter g_painter;
|
||||||
|
|
||||||
|
@ -94,6 +95,40 @@ void Painter::updateProjectionMatrix(const Size& viewportSize, bool inverseYAxis
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Painter::drawCoords(CoordsBuffer& coordsBuffer)
|
||||||
|
{
|
||||||
|
coordsBuffer.cacheVertexArrays();
|
||||||
|
|
||||||
|
if(coordsBuffer.getVertexCount() < 3)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_drawSolidColorProgram->prepareForDraw();
|
||||||
|
m_drawSolidColorProgram->setProjectionMatrix(m_projectionMatrix);
|
||||||
|
m_drawSolidColorProgram->setOpacity(m_currentOpacity);
|
||||||
|
m_drawSolidColorProgram->setColor(m_currentColor);
|
||||||
|
m_drawSolidColorProgram->setVertexCoords(coordsBuffer.getVertexCoords());
|
||||||
|
m_drawSolidColorProgram->drawTriangles(coordsBuffer.getVertexCount());
|
||||||
|
m_drawSolidColorProgram->releaseFromDraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Painter::drawTextureCoords(CoordsBuffer& coordsBuffer, const TexturePtr& texture)
|
||||||
|
{
|
||||||
|
coordsBuffer.cacheVertexArrays();
|
||||||
|
|
||||||
|
if(coordsBuffer.getVertexCount() < 3)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_drawTexturedProgram->prepareForDraw();
|
||||||
|
m_drawTexturedProgram->setProjectionMatrix(m_projectionMatrix);
|
||||||
|
m_drawTexturedProgram->setOpacity(m_currentOpacity);
|
||||||
|
m_drawTexturedProgram->setColor(m_currentColor);
|
||||||
|
m_drawTexturedProgram->setTexture(texture);
|
||||||
|
m_drawTexturedProgram->setVertexCoords(coordsBuffer.getVertexCoords());
|
||||||
|
m_drawTexturedProgram->setTextureCoords(coordsBuffer.getTextureCoords());
|
||||||
|
m_drawTexturedProgram->drawTriangles(coordsBuffer.getVertexCount());
|
||||||
|
m_drawTexturedProgram->releaseFromDraw();
|
||||||
|
}
|
||||||
|
|
||||||
void Painter::drawTexturedRect(const Rect& dest, const TexturePtr& texture)
|
void Painter::drawTexturedRect(const Rect& dest, const TexturePtr& texture)
|
||||||
{
|
{
|
||||||
drawTexturedRect(dest, texture, Rect(Point(0,0), texture->getSize()));
|
drawTexturedRect(dest, texture, Rect(Point(0,0), texture->getSize()));
|
||||||
|
@ -104,25 +139,9 @@ void Painter::drawTexturedRect(const Rect& dest, const TexturePtr& texture, cons
|
||||||
if(dest.isEmpty() || src.isEmpty() || !texture->getId())
|
if(dest.isEmpty() || src.isEmpty() || !texture->getId())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GLfloat vertexCoords[] = { (float)dest.left(), (float)dest.top(),
|
m_coordsBuffer.clear();
|
||||||
(float)dest.right()+1, (float)dest.top(),
|
m_coordsBuffer.addRect(dest, src);
|
||||||
(float)dest.left(), (float)dest.bottom()+1,
|
drawTextureCoords(m_coordsBuffer, texture);
|
||||||
(float)dest.right()+1, (float)dest.bottom()+1 };
|
|
||||||
|
|
||||||
GLfloat textureCoords[] = { (float)src.left(), (float)src.top(),
|
|
||||||
(float)src.right()+1, (float)src.top(),
|
|
||||||
(float)src.left(), (float)src.bottom()+1,
|
|
||||||
(float)src.right()+1, (float)src.bottom()+1 };
|
|
||||||
|
|
||||||
m_drawTexturedProgram->prepareForDraw();
|
|
||||||
m_drawTexturedProgram->setProjectionMatrix(m_projectionMatrix);
|
|
||||||
m_drawTexturedProgram->setOpacity(m_currentOpacity);
|
|
||||||
m_drawTexturedProgram->setColor(m_currentColor);
|
|
||||||
m_drawTexturedProgram->setTexture(texture);
|
|
||||||
m_drawTexturedProgram->setVertexCoords(vertexCoords);
|
|
||||||
m_drawTexturedProgram->setTextureCoords(textureCoords);
|
|
||||||
m_drawTexturedProgram->drawTriangleStrip(4);
|
|
||||||
m_drawTexturedProgram->releaseFromDraw();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Painter::drawRepeatedTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src)
|
void Painter::drawRepeatedTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src)
|
||||||
|
@ -130,27 +149,9 @@ void Painter::drawRepeatedTexturedRect(const Rect& dest, const TexturePtr& textu
|
||||||
if(dest.isEmpty() || src.isEmpty() || !texture->getId())
|
if(dest.isEmpty() || src.isEmpty() || !texture->getId())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//TODO: use vertex arrays..
|
m_coordsBuffer.clear();
|
||||||
Rect virtualDest(0, 0, dest.size());
|
m_coordsBuffer.addRepeatedRects(dest, src);
|
||||||
for(int y = 0; y <= virtualDest.height(); y += src.height()) {
|
drawTextureCoords(m_coordsBuffer, texture);
|
||||||
for(int x = 0; x <= virtualDest.width(); x += src.width()) {
|
|
||||||
Rect partialDest(x, y, src.size());
|
|
||||||
Rect partialSrc = src;
|
|
||||||
|
|
||||||
// partialCoords to screenCoords bottomRight
|
|
||||||
if(partialDest.bottom() > virtualDest.bottom()) {
|
|
||||||
partialSrc.setBottom(partialSrc.bottom() + (virtualDest.bottom() - partialDest.bottom()));
|
|
||||||
partialDest.setBottom(virtualDest.bottom());
|
|
||||||
}
|
|
||||||
if(partialDest.right() > virtualDest.right()) {
|
|
||||||
partialSrc.setRight(partialSrc.right() + (virtualDest.right() - partialDest.right()));
|
|
||||||
partialDest.setRight(virtualDest.right());
|
|
||||||
}
|
|
||||||
|
|
||||||
partialDest.translate(dest.topLeft());
|
|
||||||
drawTexturedRect(partialDest, texture, partialSrc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Painter::drawFilledRect(const Rect& dest)
|
void Painter::drawFilledRect(const Rect& dest)
|
||||||
|
@ -158,23 +159,9 @@ void Painter::drawFilledRect(const Rect& dest)
|
||||||
if(dest.isEmpty())
|
if(dest.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GLfloat right = dest.right()+1;
|
m_coordsBuffer.clear();
|
||||||
GLfloat bottom = dest.bottom()+1;
|
m_coordsBuffer.addRect(dest);
|
||||||
GLfloat top = dest.top();
|
drawCoords(m_coordsBuffer);
|
||||||
GLfloat left = dest.left();
|
|
||||||
|
|
||||||
GLfloat vertexCoords[] = { left, top,
|
|
||||||
right, top,
|
|
||||||
left, bottom,
|
|
||||||
right, bottom };
|
|
||||||
|
|
||||||
m_drawSolidColorProgram->prepareForDraw();
|
|
||||||
m_drawSolidColorProgram->setProjectionMatrix(m_projectionMatrix);
|
|
||||||
m_drawSolidColorProgram->setOpacity(m_currentOpacity);
|
|
||||||
m_drawSolidColorProgram->setColor(m_currentColor);
|
|
||||||
m_drawSolidColorProgram->setVertexCoords(vertexCoords);
|
|
||||||
m_drawSolidColorProgram->drawTriangleStrip(4);
|
|
||||||
m_drawSolidColorProgram->releaseFromDraw();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Painter::drawBoundingRect(const Rect& dest, int innerLineWidth)
|
void Painter::drawBoundingRect(const Rect& dest, int innerLineWidth)
|
||||||
|
@ -182,33 +169,9 @@ void Painter::drawBoundingRect(const Rect& dest, int innerLineWidth)
|
||||||
if(dest.isEmpty() || innerLineWidth == 0)
|
if(dest.isEmpty() || innerLineWidth == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GLfloat right = dest.right()+1;
|
m_coordsBuffer.clear();
|
||||||
GLfloat bottom = dest.bottom()+1;
|
m_coordsBuffer.addBoudingRect(dest, innerLineWidth);
|
||||||
GLfloat top = dest.top();
|
drawCoords(m_coordsBuffer);
|
||||||
GLfloat left = dest.left();
|
|
||||||
GLfloat w = innerLineWidth;
|
|
||||||
|
|
||||||
GLfloat vertexCoords[] = { left, top,
|
|
||||||
right, top,
|
|
||||||
left, top+w,
|
|
||||||
right, top+w,
|
|
||||||
right-w, top+w,
|
|
||||||
right, bottom,
|
|
||||||
right-w, bottom,
|
|
||||||
right-w, bottom-w,
|
|
||||||
left, bottom,
|
|
||||||
left, bottom-w,
|
|
||||||
left+w, bottom-w,
|
|
||||||
left, top+w,
|
|
||||||
left+w, top+w };
|
|
||||||
|
|
||||||
m_drawSolidColorProgram->prepareForDraw();
|
|
||||||
m_drawSolidColorProgram->setProjectionMatrix(m_projectionMatrix);
|
|
||||||
m_drawSolidColorProgram->setOpacity(m_currentOpacity);
|
|
||||||
m_drawSolidColorProgram->setColor(m_currentColor);
|
|
||||||
m_drawSolidColorProgram->setVertexCoords(vertexCoords);
|
|
||||||
m_drawSolidColorProgram->drawTriangleStrip(13);
|
|
||||||
m_drawSolidColorProgram->releaseFromDraw();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Painter::setCompositionMode(Painter::CompositionMode compositionMode)
|
void Painter::setCompositionMode(Painter::CompositionMode compositionMode)
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
#define PAINTER_H
|
#define PAINTER_H
|
||||||
|
|
||||||
#include "declarations.h"
|
#include "declarations.h"
|
||||||
|
#include <framework/util/databuffer.h>
|
||||||
|
#include "coordsbuffer.h"
|
||||||
|
|
||||||
class Painter
|
class Painter
|
||||||
{
|
{
|
||||||
|
@ -37,6 +39,10 @@ public:
|
||||||
void terminate();
|
void terminate();
|
||||||
|
|
||||||
void updateProjectionMatrix(const Size& viewportSize, bool inverseYAxis = false);
|
void updateProjectionMatrix(const Size& viewportSize, bool inverseYAxis = false);
|
||||||
|
|
||||||
|
void drawCoords(CoordsBuffer& coordsBuffer);
|
||||||
|
void drawTextureCoords(CoordsBuffer& coordsBuffer, const TexturePtr& texture);
|
||||||
|
|
||||||
void drawTexturedRect(const Rect& dest, const TexturePtr& texture);
|
void drawTexturedRect(const Rect& dest, const TexturePtr& texture);
|
||||||
void drawTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src);
|
void drawTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src);
|
||||||
void drawRepeatedTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src);
|
void drawRepeatedTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src);
|
||||||
|
@ -57,6 +63,7 @@ private:
|
||||||
GLfloat m_projectionMatrix[3][3];
|
GLfloat m_projectionMatrix[3][3];
|
||||||
Color m_currentColor;
|
Color m_currentColor;
|
||||||
GLfloat m_currentOpacity;
|
GLfloat m_currentOpacity;
|
||||||
|
CoordsBuffer m_coordsBuffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Painter g_painter;
|
extern Painter g_painter;
|
||||||
|
|
|
@ -83,6 +83,11 @@ void PainterShaderProgram::drawTriangleStrip(int numVertices)
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, numVertices);
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, numVertices);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PainterShaderProgram::drawTriangles(int numVertices)
|
||||||
|
{
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, numVertices);
|
||||||
|
}
|
||||||
|
|
||||||
void PainterShaderProgram::releaseFromDraw()
|
void PainterShaderProgram::releaseFromDraw()
|
||||||
{
|
{
|
||||||
if(m_mustDisableTexCoordsArray) {
|
if(m_mustDisableTexCoordsArray) {
|
||||||
|
|
|
@ -47,6 +47,7 @@ public:
|
||||||
|
|
||||||
void prepareForDraw();
|
void prepareForDraw();
|
||||||
void drawTriangleStrip(int numVertices);
|
void drawTriangleStrip(int numVertices);
|
||||||
|
void drawTriangles(int numVertices);
|
||||||
void releaseFromDraw();
|
void releaseFromDraw();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -132,7 +132,7 @@ std::vector<uint8> Texture::getPixels()
|
||||||
// copy pixels from opengl memory
|
// copy pixels from opengl memory
|
||||||
std::vector<uint8> pixels(m_glSize.area()*4, 0);
|
std::vector<uint8> pixels(m_glSize.area()*4, 0);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_textureId);
|
glBindTexture(GL_TEXTURE_2D, m_textureId);
|
||||||
//glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]);
|
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]);
|
||||||
|
|
||||||
// convert pixels to the real texture size
|
// convert pixels to the real texture size
|
||||||
if(m_size != m_glSize)
|
if(m_size != m_glSize)
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "textureglyphcache.h"
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
|
||||||
|
*
|
||||||
|
* 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 TEXTUREGLYPHCACHE_H
|
||||||
|
#define TEXTUREGLYPHCACHE_H
|
||||||
|
|
||||||
|
class TextureGlyphCache
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,67 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
|
||||||
|
*
|
||||||
|
* 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 VERTEXARRAY_H
|
||||||
|
#define VERTEXARRAY_H
|
||||||
|
|
||||||
|
#include "declarations.h"
|
||||||
|
#include <framework/util/databuffer.h>
|
||||||
|
|
||||||
|
class VertexArray
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
inline void addVertex(GLfloat x, GLfloat y) { m_buffer << x << y; }
|
||||||
|
inline void addRect(const Rect& rect) {
|
||||||
|
GLfloat top = rect.top();
|
||||||
|
GLfloat right = rect.right()+1;
|
||||||
|
GLfloat bottom = rect.bottom()+1;
|
||||||
|
GLfloat left = rect.left();
|
||||||
|
|
||||||
|
addVertex(left, top);
|
||||||
|
addVertex(right, top);
|
||||||
|
addVertex(left, bottom);
|
||||||
|
addVertex(left, bottom);
|
||||||
|
addVertex(right, top);
|
||||||
|
addVertex(right, bottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void addQuad(const Rect& rect) {
|
||||||
|
GLfloat top = rect.top();
|
||||||
|
GLfloat right = rect.right()+1;
|
||||||
|
GLfloat bottom = rect.bottom()+1;
|
||||||
|
GLfloat left = rect.left();
|
||||||
|
|
||||||
|
addVertex(left, top);
|
||||||
|
addVertex(right, top);
|
||||||
|
addVertex(left, bottom);
|
||||||
|
addVertex(right, bottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear() { m_buffer.reset(); }
|
||||||
|
GLfloat *vertexArray() const { return m_buffer.data(); }
|
||||||
|
int vertexCount() const { return m_buffer.size() / 2; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
DataBuffer<GLfloat> m_buffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,69 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
|
||||||
|
*
|
||||||
|
* 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 DATABUFFER_H
|
||||||
|
#define DATABUFFER_H
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
class DataBuffer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DataBuffer(int res = 64) {
|
||||||
|
m_capacity = res;
|
||||||
|
m_buffer = new T[m_capacity];
|
||||||
|
m_size = 0;
|
||||||
|
}
|
||||||
|
~DataBuffer() { delete[] m_buffer; }
|
||||||
|
|
||||||
|
inline void reset() { m_size = 0; }
|
||||||
|
inline bool isEmpty() const { return m_size == 0; }
|
||||||
|
|
||||||
|
inline int size() const { return m_size; }
|
||||||
|
inline T *data() const { return m_buffer; }
|
||||||
|
|
||||||
|
inline const T& at(int i) const { return m_buffer[i]; }
|
||||||
|
inline const T& last() const { return m_buffer[m_size-1]; }
|
||||||
|
inline const T& first() const { return m_buffer[0]; }
|
||||||
|
inline const T& operator[](int i) const { return m_buffer[i]; }
|
||||||
|
inline T& operator[](int i) { return m_buffer[i]; }
|
||||||
|
|
||||||
|
inline void add(const T &t) {
|
||||||
|
if(m_size >= m_capacity) {
|
||||||
|
m_capacity *= 2;
|
||||||
|
T *buffer = new T[m_capacity];
|
||||||
|
for(int i=0;i<m_size;++i)
|
||||||
|
buffer[i] = m_buffer[i];
|
||||||
|
delete[] m_buffer;
|
||||||
|
m_buffer = buffer;
|
||||||
|
}
|
||||||
|
m_buffer[m_size++] = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline DataBuffer &operator<<(const T &t) { add(t); return *this; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_size;
|
||||||
|
int m_capacity;
|
||||||
|
T *m_buffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue