mirror of
https://github.com/edubart/otclient.git
synced 2025-10-19 05:53:26 +02:00
optimizations
This commit is contained in:
@@ -30,6 +30,7 @@ PainterShaderProgram::PainterShaderProgram()
|
||||
{
|
||||
m_textures.fill(std::make_tuple(-1, 0));
|
||||
m_startTime = g_clock.time();
|
||||
m_lastTexture = -1;
|
||||
}
|
||||
|
||||
bool PainterShaderProgram::link()
|
||||
@@ -72,6 +73,7 @@ void PainterShaderProgram::setUniformTexture(int location, const TexturePtr& tex
|
||||
assert(index >= 0 && index <= 1);
|
||||
|
||||
m_textures[index] = std::make_tuple(location, texture ? texture->getId() : 0);
|
||||
m_lastTexture = std::max(m_lastTexture, index);
|
||||
}
|
||||
|
||||
void PainterShaderProgram::setTexture(const TexturePtr& texture)
|
||||
@@ -102,7 +104,8 @@ void PainterShaderProgram::draw(CoordsBuffer& coordsBuffer, DrawMode drawMode)
|
||||
coordsBuffer.getHardwareVertexBuffer()->bind();
|
||||
setAttributeArray(PainterShaderProgram::VERTEX_COORDS_ATTR, hardwareCached ? 0 : coordsBuffer.getVertexBuffer(), 2);
|
||||
|
||||
if(coordsBuffer.getTextureVertexCount() != 0) {
|
||||
bool hasTexture = coordsBuffer.getTextureVertexCount() != 0;
|
||||
if(hasTexture) {
|
||||
enableAttributeArray(PainterShaderProgram::TEXTURE_COORDS_ATTR);
|
||||
if(hardwareCached)
|
||||
coordsBuffer.getHardwareTextureVertexBuffer()->bind();
|
||||
@@ -112,23 +115,21 @@ void PainterShaderProgram::draw(CoordsBuffer& coordsBuffer, DrawMode drawMode)
|
||||
if(hardwareCached)
|
||||
HardwareBuffer::unbind(HardwareBuffer::VertexBuffer);
|
||||
|
||||
for(int i=0;i<(int)m_textures.size();++i) {
|
||||
for(int i=m_lastTexture;i>=0;--i) {
|
||||
int location = std::get<0>(m_textures[i]);
|
||||
if(location == -1)
|
||||
break;
|
||||
int id = std::get<1>(m_textures[i]);
|
||||
uint id = std::get<1>(m_textures[i]);
|
||||
setUniformValue(location, i);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0+i);
|
||||
if(m_lastTexture > 0)
|
||||
glActiveTexture(GL_TEXTURE0+i);
|
||||
glBindTexture(GL_TEXTURE_2D, id);
|
||||
}
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
glDrawArrays(drawMode, 0, vertexCount);
|
||||
|
||||
disableAttributeArray(PainterShaderProgram::VERTEX_COORDS_ATTR);
|
||||
|
||||
if(coordsBuffer.getTextureVertexCount() != 0)
|
||||
if(hasTexture)
|
||||
disableAttributeArray(PainterShaderProgram::TEXTURE_COORDS_ATTR);
|
||||
}
|
||||
|
||||
|
@@ -59,7 +59,8 @@ public:
|
||||
private:
|
||||
DrawMode m_drawMode;
|
||||
float m_startTime;
|
||||
std::array<std::tuple<int, int>, 4> m_textures;
|
||||
std::array<std::tuple<int, uint>, 4> m_textures;
|
||||
int m_lastTexture;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user