mirror of
https://github.com/edubart/otclient.git
synced 2025-10-19 05:53:26 +02:00
performance improvements
* no more freezes because of file IO from hard disk, now we cache sound/spr file buffers * more opengl painter tweaks
This commit is contained in:
@@ -100,7 +100,13 @@ void CoordsBuffer::updateCaches()
|
||||
if(!m_hardwareCaching || m_hardwareCached)
|
||||
return;
|
||||
|
||||
if(m_vertexArray.vertexCount() > 0) {
|
||||
int vertexCount = m_vertexArray.vertexCount();
|
||||
|
||||
// there is only performance improvement when caching a lot of vertices
|
||||
if(vertexCount < CACHE_MIN_VERTICES_COUNT)
|
||||
return;
|
||||
|
||||
if(vertexCount > 0) {
|
||||
if(!m_hardwareVertexArray && m_vertexArray.vertexCount() > 0)
|
||||
m_hardwareVertexArray = new HardwareBuffer(HardwareBuffer::VertexBuffer);
|
||||
m_hardwareVertexArray->bind();
|
||||
|
@@ -28,6 +28,9 @@
|
||||
|
||||
class CoordsBuffer
|
||||
{
|
||||
enum {
|
||||
CACHE_MIN_VERTICES_COUNT = 48
|
||||
};
|
||||
public:
|
||||
CoordsBuffer();
|
||||
~CoordsBuffer();
|
||||
|
@@ -104,25 +104,27 @@ void Painter::setTexture(Texture* texture)
|
||||
|
||||
m_texture = texture;
|
||||
|
||||
GLuint glTextureId;
|
||||
if(texture) {
|
||||
setTextureMatrix(texture->getTransformMatrix());
|
||||
glTextureId = texture->getId();
|
||||
} else
|
||||
glTextureId = 0;
|
||||
|
||||
GLuint glTextureId = texture->getId();
|
||||
if(glTextureId != m_glTextureId) {
|
||||
m_glTextureId = glTextureId;
|
||||
updateGlTexture();
|
||||
}
|
||||
if(m_glTextureId != glTextureId) {
|
||||
m_glTextureId = glTextureId;
|
||||
updateGlTexture();
|
||||
}
|
||||
}
|
||||
|
||||
void Painter::updateGlTexture()
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, m_glTextureId);
|
||||
if(m_glTextureId != 0)
|
||||
glBindTexture(GL_TEXTURE_2D, m_glTextureId);
|
||||
}
|
||||
|
||||
void Painter::updateGlCompositionMode()
|
||||
{
|
||||
glEnable(GL_BLEND);
|
||||
switch(m_compositionMode) {
|
||||
case CompositionMode_Normal:
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
@@ -62,7 +62,12 @@ void PainterOGL1::drawCoords(CoordsBuffer& coordsBuffer, DrawMode drawMode)
|
||||
if(vertexCount == 0)
|
||||
return;
|
||||
|
||||
bool textured = coordsBuffer.getTextureCoordCount() != 0;
|
||||
bool textured = coordsBuffer.getTextureCoordCount() != 0 && m_texture;
|
||||
|
||||
// skip drawing of empty textures
|
||||
if(textured && m_texture->isEmpty())
|
||||
return;
|
||||
|
||||
if(textured != m_textureEnabled) {
|
||||
if(textured)
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
@@ -121,7 +126,7 @@ void PainterOGL1::drawCoords(CoordsBuffer& coordsBuffer, DrawMode drawMode)
|
||||
|
||||
void PainterOGL1::drawTextureCoords(CoordsBuffer& coordsBuffer, const TexturePtr& texture)
|
||||
{
|
||||
if(!texture->getId())
|
||||
if(texture->isEmpty())
|
||||
return;
|
||||
|
||||
setTexture(texture.get());
|
||||
@@ -130,7 +135,7 @@ void PainterOGL1::drawTextureCoords(CoordsBuffer& coordsBuffer, const TexturePtr
|
||||
|
||||
void PainterOGL1::drawTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src)
|
||||
{
|
||||
if(dest.isEmpty() || src.isEmpty() || !texture->getId())
|
||||
if(dest.isEmpty() || src.isEmpty() || texture->isEmpty())
|
||||
return;
|
||||
|
||||
setTexture(texture.get());
|
||||
@@ -142,7 +147,7 @@ void PainterOGL1::drawTexturedRect(const Rect& dest, const TexturePtr& texture,
|
||||
|
||||
void PainterOGL1::drawRepeatedTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src)
|
||||
{
|
||||
if(dest.isEmpty() || src.isEmpty() || !texture->getId())
|
||||
if(dest.isEmpty() || src.isEmpty() || texture->isEmpty())
|
||||
return;
|
||||
|
||||
setTexture(texture.get());
|
||||
|
@@ -62,7 +62,11 @@ void PainterOGL2::drawCoords(CoordsBuffer& coordsBuffer, DrawMode drawMode)
|
||||
if(vertexCount == 0)
|
||||
return;
|
||||
|
||||
bool textured = coordsBuffer.getTextureCoordCount() > 0;
|
||||
bool textured = coordsBuffer.getTextureCoordCount() > 0 && m_texture;
|
||||
|
||||
// skip drawing of empty textures
|
||||
if(textured && m_texture->isEmpty())
|
||||
return;
|
||||
|
||||
// update shader with the current painter state
|
||||
m_drawProgram->bind();
|
||||
@@ -100,7 +104,7 @@ void PainterOGL2::drawCoords(CoordsBuffer& coordsBuffer, DrawMode drawMode)
|
||||
|
||||
void PainterOGL2::drawTextureCoords(CoordsBuffer& coordsBuffer, const TexturePtr& texture)
|
||||
{
|
||||
if(!texture->getId())
|
||||
if(texture->isEmpty())
|
||||
return;
|
||||
|
||||
setDrawProgram(m_shaderProgram ? m_shaderProgram : g_shaders.getDrawTexturedProgram().get());
|
||||
@@ -110,7 +114,7 @@ void PainterOGL2::drawTextureCoords(CoordsBuffer& coordsBuffer, const TexturePtr
|
||||
|
||||
void PainterOGL2::drawTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src)
|
||||
{
|
||||
if(dest.isEmpty() || src.isEmpty() || !texture->getId())
|
||||
if(dest.isEmpty() || src.isEmpty() || texture->isEmpty())
|
||||
return;
|
||||
|
||||
setDrawProgram(m_shaderProgram ? m_shaderProgram : g_shaders.getDrawTexturedProgram().get());
|
||||
@@ -123,7 +127,7 @@ void PainterOGL2::drawTexturedRect(const Rect& dest, const TexturePtr& texture,
|
||||
|
||||
void PainterOGL2::drawRepeatedTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src)
|
||||
{
|
||||
if(dest.isEmpty() || src.isEmpty() || !texture->getId())
|
||||
if(dest.isEmpty() || src.isEmpty() || texture->isEmpty())
|
||||
return;
|
||||
|
||||
setDrawProgram(m_shaderProgram ? m_shaderProgram : g_shaders.getDrawTexturedProgram().get());
|
||||
|
@@ -179,10 +179,12 @@ void Texture::generateSoftwareMipmaps(std::vector<uint8> inPixels)
|
||||
|
||||
Size inSize = getSize();
|
||||
Size outSize = inSize / 2;
|
||||
std::vector<uint8> outPixels(outSize.area()*4);
|
||||
std::vector<uint8> outPixels;
|
||||
|
||||
int mipmap = 1;
|
||||
while(true) {
|
||||
outPixels.resize(outSize.area()*4);
|
||||
|
||||
// this is a simple bilinear filtering algorithm, it combines every 4 pixels in one pixel
|
||||
for(int x=0;x<outSize.width();++x) {
|
||||
for(int y=0;y<outSize.height();++y) {
|
||||
|
@@ -60,7 +60,9 @@ TexturePtr TextureManager::getTexture(const std::string& fileName)
|
||||
logError("unable to load texture '", fileName, "': ", e.what());
|
||||
texture = g_graphics.getEmptyTexture();
|
||||
}
|
||||
m_textures[filePath] = texture;
|
||||
|
||||
if(texture)
|
||||
m_textures[filePath] = texture;
|
||||
}
|
||||
|
||||
return texture;
|
||||
|
Reference in New Issue
Block a user