mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-01-24 17:26:41 +00:00
some more TileRender optimization
- no longer uses GL matrix stack manipulation, all matrix math is done locally - use fixed rotation matrixes for fh/fv - don't touch GL buffers (fixes crash with prev. commit)
This commit is contained in:
parent
ee7129982f
commit
d3cbc181bd
2 changed files with 29 additions and 10 deletions
|
@ -53,6 +53,7 @@ GL_FUNC(void,glPixelZoom,(GLfloat xfactor, GLfloat yfactor),(xfactor,yfactor),)
|
||||||
GL_FUNC(void,glPointSize,(GLfloat size),(size),)
|
GL_FUNC(void,glPointSize,(GLfloat size),(size),)
|
||||||
GL_FUNC(void,glPopMatrix,(void),(),)
|
GL_FUNC(void,glPopMatrix,(void),(),)
|
||||||
GL_FUNC(void,glPushMatrix,(void),(),)
|
GL_FUNC(void,glPushMatrix,(void),(),)
|
||||||
|
GL_FUNC(void,glLoadMatrixf,(const GLfloat *m),(m),)
|
||||||
GL_FUNC(void,glReadPixels,(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels),(x,y,width,height,format,type,pixels),)
|
GL_FUNC(void,glReadPixels,(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels),(x,y,width,height,format,type,pixels),)
|
||||||
GL_FUNC(void,glRotatef,(GLfloat angle, GLfloat x, GLfloat y, GLfloat z),(angle,x,y,z),)
|
GL_FUNC(void,glRotatef,(GLfloat angle, GLfloat x, GLfloat y, GLfloat z),(angle,x,y,z),)
|
||||||
GL_FUNC(void,glScalef,(GLfloat x, GLfloat y, GLfloat z),(x,y,z),)
|
GL_FUNC(void,glScalef,(GLfloat x, GLfloat y, GLfloat z),(x,y,z),)
|
||||||
|
|
|
@ -5,6 +5,21 @@
|
||||||
#include "RenderGrid.h"
|
#include "RenderGrid.h"
|
||||||
#include "RenderObject.h"
|
#include "RenderObject.h"
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
|
||||||
|
struct StaticData
|
||||||
|
{
|
||||||
|
glm::mat4 fh, fv;
|
||||||
|
StaticData()
|
||||||
|
: fh(glm::rotate(glm::mat4(), 180.0f, glm::vec3(0,1,0)))
|
||||||
|
, fv(glm::rotate(glm::mat4(), 180.0f, glm::vec3(1,0,0)))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static const StaticData staticdata;
|
||||||
|
|
||||||
|
|
||||||
TileRender::TileRender(const TileStorage& tiles)
|
TileRender::TileRender(const TileStorage& tiles)
|
||||||
: storage(tiles), renderBorders(false)
|
: storage(tiles), renderBorders(false)
|
||||||
|
@ -58,6 +73,10 @@ void TileRender::onRender(const RenderState& rs) const
|
||||||
|
|
||||||
RenderState rx(rs);
|
RenderState rx(rs);
|
||||||
|
|
||||||
|
// FIXME: this is such a hack. remove this once we pass matrices explicitly
|
||||||
|
glm::mat4 originalMat;
|
||||||
|
glGetFloatv(GL_MODELVIEW_MATRIX, &originalMat[0][0]);
|
||||||
|
|
||||||
// prepare. get parallax scroll factors
|
// prepare. get parallax scroll factors
|
||||||
const RenderObjectLayer& rl = core->renderObjectLayers[this->layer];
|
const RenderObjectLayer& rl = core->renderObjectLayers[this->layer];
|
||||||
const Vector M = rl.followCameraMult; // affected by parallaxLock
|
const Vector M = rl.followCameraMult; // affected by parallaxLock
|
||||||
|
@ -131,8 +150,7 @@ void TileRender::onRender(const RenderState& rs) const
|
||||||
glColor4f(rs.color.x, rs.color.y, rs.color.z, alpha);
|
glColor4f(rs.color.x, rs.color.y, rs.color.z, alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
glPushMatrix();
|
glm::mat4 m = glm::translate(originalMat, glm::vec3(pos.x, pos.y, pos.z));
|
||||||
glTranslatef(pos.x, pos.y, pos.z);
|
|
||||||
|
|
||||||
// HACK: Due to a renderer bug in older versions, vertical flip is ignored
|
// HACK: Due to a renderer bug in older versions, vertical flip is ignored
|
||||||
// when a grid-based tile effect is applied.
|
// when a grid-based tile effect is applied.
|
||||||
|
@ -148,22 +166,25 @@ void TileRender::onRender(const RenderState& rs) const
|
||||||
if ((effflag & (TILEFLAG_FH | TILEFLAG_FV)) == (TILEFLAG_FH | TILEFLAG_FV))
|
if ((effflag & (TILEFLAG_FH | TILEFLAG_FV)) == (TILEFLAG_FH | TILEFLAG_FV))
|
||||||
effrot += 180;
|
effrot += 180;
|
||||||
|
|
||||||
glRotatef(effrot, 0, 0, 1);
|
m = glm::rotate(m, effrot, glm::vec3(0,0,1));
|
||||||
|
|
||||||
|
|
||||||
switch(effflag & (TILEFLAG_FH | TILEFLAG_FV))
|
switch(effflag & (TILEFLAG_FH | TILEFLAG_FV))
|
||||||
{
|
{
|
||||||
case TILEFLAG_FH:
|
case TILEFLAG_FH:
|
||||||
glRotatef(180, 0, 1, 0);
|
m *= staticdata.fh;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TILEFLAG_FV:
|
case TILEFLAG_FV:
|
||||||
glRotatef(180, 1, 0, 0);
|
m *= staticdata.fv;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: ; // both or none set, nothing to do
|
default: ; // both or none set, nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
glScalef(sw, sh, 1);
|
m = glm::scale(m, glm::vec3(sw, sh, 1));
|
||||||
|
|
||||||
|
glLoadMatrixf(&m[0][0]);
|
||||||
|
|
||||||
|
|
||||||
const RenderGrid *grid = tile.getGrid();
|
const RenderGrid *grid = tile.getGrid();
|
||||||
|
@ -199,12 +220,9 @@ void TileRender::onRender(const RenderState& rs) const
|
||||||
glDrawArrays(GL_LINE_LOOP, 0, 4);
|
glDrawArrays(GL_LINE_LOOP, 0, 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glPopMatrix();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
|
glLoadMatrixf(&originalMat[0][0]);
|
||||||
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
|
|
||||||
|
|
||||||
RenderObject::lastTextureApplied = lastTexId;
|
RenderObject::lastTextureApplied = lastTexId;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue