1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-25 09:44:02 +00:00

Use glm for matrix math instead of the OpenGL stack

Should cause less GL pipeline stalling / driver spinlocking if enabled.
Disable AQUARIA_USE_GLM (default: true) in CMake to use the old GL pipeline version.

Based on the implementation by Matt Bierner:
https://bitbucket.org/mattbierner/ios-aquaria
This commit is contained in:
fgenesis 2015-07-12 22:16:55 +02:00
parent c4b531ed5e
commit 9faa503f32
5 changed files with 62 additions and 17 deletions

View file

@ -25,6 +25,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <assert.h>
#include <algorithm>
#ifdef BBGE_USE_GLM
#include "glm/glm.hpp"
#include "glm/gtx/transform.hpp"
#endif
bool RenderObject::renderCollisionShape = false;
int RenderObject::lastTextureApplied = 0;
bool RenderObject::lastTextureRepeat = false;
@ -292,24 +297,51 @@ Vector RenderObject::getInvRotPosition(const Vector &vec)
#endif
}
void RenderObject::matrixChain()
#ifdef BBGE_USE_GLM
static glm::mat4 matrixChain(const RenderObject *ro)
{
if (parent)
parent->matrixChain();
glm::mat4 tranformMatrix = glm::scale(
glm::translate(
glm::rotate(
glm::translate(
ro->getParent() ? matrixChain(ro->getParent()) : glm::mat4(1.0f),
glm::vec3(ro->position.x+ro->offset.x, ro->position.y+ro->offset.y, 0)
),
ro->rotation.z + ro->rotationOffset.z,
glm::vec3(0, 0, 1)
),
glm::vec3(ro->beforeScaleOffset.x, ro->beforeScaleOffset.y, 0.0f)
),
glm::vec3(ro->scale.x, ro->scale.y, 0.0f)
);
if (ro->isfh())
tranformMatrix *= glm::rotate(180.0f, 0.0f, 1.0f, 0.0f);
tranformMatrix *= glm::translate(ro->internalOffset.x, ro->internalOffset.y, 0.0f);
return tranformMatrix;
}
#else
static void matrixChain(RenderObject *ro)
{
if (RenderObject *parent = ro->getParent())
matrixChain(parent);
#ifdef BBGE_BUILD_OPENGL
glTranslatef(position.x+offset.x, position.y+offset.y, 0);
glRotatef(rotation.z+rotationOffset.z, 0, 0, 1);
glTranslatef(beforeScaleOffset.x, beforeScaleOffset.y, 0);
glScalef(scale.x, scale.y, 0);
if (isfh())
glTranslatef(ro->position.x+ro->offset.x, ro->position.y+ro->offset.y, 0);
glRotatef(ro->rotation.z+ro->rotationOffset.z, 0, 0, 1);
glTranslatef(ro->beforeScaleOffset.x, ro->beforeScaleOffset.y, 0);
glScalef(ro->scale.x, ro->scale.y, 0);
if (ro->isfh())
{
//glDisable(GL_CULL_FACE);
glRotatef(180, 0, 1, 0);
}
glTranslatef(internalOffset.x, internalOffset.y, 0);
glTranslatef(ro->internalOffset.x, ro->internalOffset.y, 0);
#endif
}
#endif
float RenderObject::getWorldRotation()
{
@ -330,11 +362,19 @@ Vector RenderObject::getWorldPositionAndRotation()
Vector RenderObject::getWorldCollidePosition(const Vector &vec)
{
#ifdef BBGE_USE_GLM
glm::mat4 transformMatrix = glm::translate(
matrixChain(this),
glm::vec3(collidePosition.x + vec.x, collidePosition.y + vec.y, 0.0f)
);
return Vector(transformMatrix[3][0], transformMatrix[3][1], 0);
#else
#ifdef BBGE_BUILD_OPENGL
glPushMatrix();
glLoadIdentity();
matrixChain();
matrixChain(this);
glTranslatef(collidePosition.x+vec.x, collidePosition.y+vec.y, 0);
float m[16];
@ -347,6 +387,7 @@ Vector RenderObject::getWorldCollidePosition(const Vector &vec)
#elif BBGE_BUILD_DIRECTX
return vec;
#endif
#endif
}
void RenderObject::fhTo(bool fh)

View file

@ -93,7 +93,6 @@ public:
bool setTexture(const std::string &name);
void toggleAlpha(float t = 0.2);
void matrixChain();
virtual void update(float dt);
bool isDead() const {return _dead;}
@ -130,8 +129,8 @@ public:
virtual void flipHorizontal();
virtual void flipVertical();
bool isfh() { return _fh; }
bool isfv() { return _fv; }
bool isfh() const { return _fh; }
bool isfv() const { return _fv; }
// recursive
bool isfhr();

View file

@ -31,6 +31,7 @@ OPTION(AQUARIA_DEMO_BUILD "Demo Build?" FALSE)
OPTION(AQUARIA_USE_VFS "Use Virtual File System? Required for some additional features." TRUE)
OPTION(AQUARIA_USE_SDL2 "Use SDL2" FALSE)
OPTION(AQUARIA_USE_GLM "Use GLM for matrix math" TRUE)
# No Steamworks SDK for Linux at the moment. Roll our own achievements.
ADD_DEFINITIONS(-DBBGE_BUILD_ACHIEVEMENTS_INTERNAL=1)
@ -303,6 +304,10 @@ IF(AQUARIA_USE_SDL2)
ADD_DEFINITIONS(-DBBGE_BUILD_SDL2=1)
ENDIF(AQUARIA_USE_SDL2)
IF(AQUARIA_USE_GLM)
ADD_DEFINITIONS(-DBBGE_USE_GLM=1)
ENDIF(AQUARIA_USE_GLM)
IF(AQUARIA_DEMO_BUILD)
message(STATUS "Demo build.")
ADD_DEFINITIONS(-DAQUARIA_DEMO=1)

View file

@ -42,7 +42,7 @@
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;$(SolutionDir)\..\ExternalLibs\freetype2\include\freetype\config&quot;;&quot;$(SolutionDir)\..\ExternalLibs\gl&quot;;&quot;$(SolutionDir)\..\ExternalLibs\glpng\zlib&quot;;&quot;$(SolutionDir)\..\ExternalLibs\glpng\png&quot;;&quot;$(SolutionDir)\..\ExternalLibs\libogg-1.3.0\include&quot;;&quot;$(SolutionDir)\..\ExternalLibs\libvorbis-1.3.3\include&quot;;&quot;$(SolutionDir)\..\ExternalLibs\freetype2\include&quot;;&quot;$(SolutionDir)\..\ExternalLibs\FTGL\include&quot;;&quot;$(SolutionDir)\..\ExternalLibs\SDL2\include&quot;;&quot;$(SolutionDir)\..\ExternalLibs\AL\include&quot;;&quot;$(SolutionDir)\..\BBGE&quot;;&quot;$(SolutionDir)\..\ExternalLibs\lua-5.1.4\src&quot;;&quot;$(SolutionDir)\..\ExternalLibs\lvpa\include&quot;;&quot;$(SolutionDir)\..\ExternalLibs\lvpa&quot;;&quot;$(SolutionDir)\..\ExternalLibs\ttvfs&quot;;&quot;$(SolutionDir)\..\ExternalLibs\ttvfs_cfileapi&quot;;&quot;$(SolutionDir)\..\ExternalLibs&quot;"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;GL_GLEXT_LEGACY=1;TIXML_USE_STL=1;HAVE_PUTENV=1;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;BBGE_BUILD_WINDOWS=1;BBGE_BUILD_VFS=1;VFS_ENABLE_C_API=1"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;GL_GLEXT_LEGACY=1;TIXML_USE_STL=1;HAVE_PUTENV=1;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;BBGE_BUILD_WINDOWS=1;BBGE_BUILD_VFS=1;VFS_ENABLE_C_API=1;BBGE_USE_GLM=1"
MinimalRebuild="true"
BasicRuntimeChecks="0"
RuntimeLibrary="3"
@ -124,7 +124,7 @@
OmitFramePointers="true"
EnableFiberSafeOptimizations="true"
AdditionalIncludeDirectories="&quot;$(SolutionDir)\..\ExternalLibs\freetype2\include\freetype\config&quot;;&quot;$(SolutionDir)\..\ExternalLibs\gl&quot;;&quot;$(SolutionDir)\..\ExternalLibs\glpng\zlib&quot;;&quot;$(SolutionDir)\..\ExternalLibs\glpng\png&quot;;&quot;$(SolutionDir)\..\ExternalLibs\libogg-1.3.0\include&quot;;&quot;$(SolutionDir)\..\ExternalLibs\libvorbis-1.3.3\include&quot;;&quot;$(SolutionDir)\..\ExternalLibs\freetype2\include&quot;;&quot;$(SolutionDir)\..\ExternalLibs\FTGL\include&quot;;&quot;$(SolutionDir)\..\ExternalLibs\SDL2\include&quot;;&quot;$(SolutionDir)\..\ExternalLibs\AL\include&quot;;&quot;$(SolutionDir)\..\BBGE&quot;;&quot;$(SolutionDir)\..\ExternalLibs\lua-5.1.4\src&quot;;&quot;$(SolutionDir)\..\ExternalLibs\lvpa\include&quot;;&quot;$(SolutionDir)\..\ExternalLibs\lvpa&quot;;&quot;$(SolutionDir)\..\ExternalLibs\ttvfs&quot;;&quot;$(SolutionDir)\..\ExternalLibs\ttvfs_cfileapi&quot;;&quot;$(SolutionDir)\..\ExternalLibs&quot;"
PreprocessorDefinitions="WIN32;NDEBUG;GL_GLEXT_LEGACY=1;TIXML_USE_STL=1;HAVE_PUTENV=1;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;BBGE_BUILD_WINDOWS=1;_HAS_EXCEPTIONS=0;BBGE_BUILD_VFS=1;VFS_ENABLE_C_API=1"
PreprocessorDefinitions="WIN32;NDEBUG;GL_GLEXT_LEGACY=1;TIXML_USE_STL=1;HAVE_PUTENV=1;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;BBGE_BUILD_WINDOWS=1;_HAS_EXCEPTIONS=0;BBGE_BUILD_VFS=1;VFS_ENABLE_C_API=1;BBGE_USE_GLM=1"
StringPooling="true"
ExceptionHandling="0"
RuntimeLibrary="0"

View file

@ -43,7 +43,7 @@
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;$(SolutionDir)\..\ExternalLibs\freetype2\include\freetype\config&quot;;&quot;$(SolutionDir)\..\ExternalLibs\gl&quot;;&quot;$(SolutionDir)\..\ExternalLibs\glpng\zlib&quot;;&quot;$(SolutionDir)\..\ExternalLibs\glpng\png&quot;;&quot;$(SolutionDir)\..\ExternalLibs\libogg-1.3.0\include&quot;;&quot;$(SolutionDir)\..\ExternalLibs\libvorbis-1.3.3\include&quot;;&quot;$(SolutionDir)\..\ExternalLibs\freetype2\include&quot;;&quot;$(SolutionDir)\..\ExternalLibs\FTGL\include&quot;;&quot;$(SolutionDir)\..\ExternalLibs\SDL2\include&quot;;&quot;$(SolutionDir)\..\ExternalLibs\AL\include&quot;;&quot;$(SolutionDir)\..\ExternalLibs\ttvfs&quot;;&quot;$(SolutionDir)\..\ExternalLibs\ttvfs_cfileapi&quot;;&quot;$(SolutionDir)\..\ExternalLibs\lvpa&quot;;&quot;$(SolutionDir)\..\ExternalLibs\lvpa\include&quot;;&quot;$(SolutionDir)\..\ExternalLibs&quot;"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;GL_GLEXT_LEGACY=1;TIXML_USE_STL=1;HAVE_PUTENV=1;FTGL_LIBRARY_STATIC;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;BBGE_BUILD_WINDOWS=1;VFS_ENABLE_C_API=1"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;GL_GLEXT_LEGACY=1;TIXML_USE_STL=1;HAVE_PUTENV=1;FTGL_LIBRARY_STATIC;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;BBGE_BUILD_WINDOWS=1;VFS_ENABLE_C_API=1;BBGE_USE_GLM=1"
MinimalRebuild="true"
BasicRuntimeChecks="0"
RuntimeLibrary="3"
@ -116,7 +116,7 @@
OmitFramePointers="true"
EnableFiberSafeOptimizations="true"
AdditionalIncludeDirectories="&quot;$(SolutionDir)\..\ExternalLibs\freetype2\include\freetype\config&quot;;&quot;$(SolutionDir)\..\ExternalLibs\gl&quot;;&quot;$(SolutionDir)\..\ExternalLibs\glpng\zlib&quot;;&quot;$(SolutionDir)\..\ExternalLibs\glpng\png&quot;;&quot;$(SolutionDir)\..\ExternalLibs\libogg-1.3.0\include&quot;;&quot;$(SolutionDir)\..\ExternalLibs\libvorbis-1.3.3\include&quot;;&quot;$(SolutionDir)\..\ExternalLibs\freetype2\include&quot;;&quot;$(SolutionDir)\..\ExternalLibs\FTGL\include&quot;;&quot;$(SolutionDir)\..\ExternalLibs\SDL2\include&quot;;&quot;$(SolutionDir)\..\ExternalLibs\AL\include&quot;;&quot;$(SolutionDir)\..\ExternalLibs\ttvfs&quot;;&quot;$(SolutionDir)\..\ExternalLibs\ttvfs_cfileapi&quot;;&quot;$(SolutionDir)\..\ExternalLibs\lvpa&quot;;&quot;$(SolutionDir)\..\ExternalLibs\lvpa\include&quot;;&quot;$(SolutionDir)\..\ExternalLibs&quot;"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;GL_GLEXT_LEGACY=1;TIXML_USE_STL=1;HAVE_PUTENV=1;FTGL_LIBRARY_STATIC;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;BBGE_BUILD_WINDOWS=1;_HAS_EXCEPTIONS=0;VFS_ENABLE_C_API=1"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;GL_GLEXT_LEGACY=1;TIXML_USE_STL=1;HAVE_PUTENV=1;FTGL_LIBRARY_STATIC;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;BBGE_BUILD_WINDOWS=1;_HAS_EXCEPTIONS=0;VFS_ENABLE_C_API=1;BBGE_USE_GLM=1"
StringPooling="true"
ExceptionHandling="0"
RuntimeLibrary="0"