mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2024-11-28 19:23:53 +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:
parent
c4b531ed5e
commit
9faa503f32
5 changed files with 62 additions and 17 deletions
|
@ -25,6 +25,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#ifdef BBGE_USE_GLM
|
||||||
|
#include "glm/glm.hpp"
|
||||||
|
#include "glm/gtx/transform.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
bool RenderObject::renderCollisionShape = false;
|
bool RenderObject::renderCollisionShape = false;
|
||||||
int RenderObject::lastTextureApplied = 0;
|
int RenderObject::lastTextureApplied = 0;
|
||||||
bool RenderObject::lastTextureRepeat = false;
|
bool RenderObject::lastTextureRepeat = false;
|
||||||
|
@ -292,24 +297,51 @@ Vector RenderObject::getInvRotPosition(const Vector &vec)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderObject::matrixChain()
|
#ifdef BBGE_USE_GLM
|
||||||
|
static glm::mat4 matrixChain(const RenderObject *ro)
|
||||||
{
|
{
|
||||||
if (parent)
|
glm::mat4 tranformMatrix = glm::scale(
|
||||||
parent->matrixChain();
|
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
|
#ifdef BBGE_BUILD_OPENGL
|
||||||
glTranslatef(position.x+offset.x, position.y+offset.y, 0);
|
glTranslatef(ro->position.x+ro->offset.x, ro->position.y+ro->offset.y, 0);
|
||||||
glRotatef(rotation.z+rotationOffset.z, 0, 0, 1);
|
glRotatef(ro->rotation.z+ro->rotationOffset.z, 0, 0, 1);
|
||||||
glTranslatef(beforeScaleOffset.x, beforeScaleOffset.y, 0);
|
glTranslatef(ro->beforeScaleOffset.x, ro->beforeScaleOffset.y, 0);
|
||||||
glScalef(scale.x, scale.y, 0);
|
glScalef(ro->scale.x, ro->scale.y, 0);
|
||||||
if (isfh())
|
if (ro->isfh())
|
||||||
{
|
{
|
||||||
//glDisable(GL_CULL_FACE);
|
//glDisable(GL_CULL_FACE);
|
||||||
glRotatef(180, 0, 1, 0);
|
glRotatef(180, 0, 1, 0);
|
||||||
}
|
}
|
||||||
glTranslatef(internalOffset.x, internalOffset.y, 0);
|
glTranslatef(ro->internalOffset.x, ro->internalOffset.y, 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
float RenderObject::getWorldRotation()
|
float RenderObject::getWorldRotation()
|
||||||
{
|
{
|
||||||
|
@ -330,11 +362,19 @@ Vector RenderObject::getWorldPositionAndRotation()
|
||||||
|
|
||||||
Vector RenderObject::getWorldCollidePosition(const Vector &vec)
|
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
|
#ifdef BBGE_BUILD_OPENGL
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
matrixChain();
|
matrixChain(this);
|
||||||
glTranslatef(collidePosition.x+vec.x, collidePosition.y+vec.y, 0);
|
glTranslatef(collidePosition.x+vec.x, collidePosition.y+vec.y, 0);
|
||||||
|
|
||||||
float m[16];
|
float m[16];
|
||||||
|
@ -347,6 +387,7 @@ Vector RenderObject::getWorldCollidePosition(const Vector &vec)
|
||||||
#elif BBGE_BUILD_DIRECTX
|
#elif BBGE_BUILD_DIRECTX
|
||||||
return vec;
|
return vec;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderObject::fhTo(bool fh)
|
void RenderObject::fhTo(bool fh)
|
||||||
|
|
|
@ -93,7 +93,6 @@ public:
|
||||||
bool setTexture(const std::string &name);
|
bool setTexture(const std::string &name);
|
||||||
|
|
||||||
void toggleAlpha(float t = 0.2);
|
void toggleAlpha(float t = 0.2);
|
||||||
void matrixChain();
|
|
||||||
|
|
||||||
virtual void update(float dt);
|
virtual void update(float dt);
|
||||||
bool isDead() const {return _dead;}
|
bool isDead() const {return _dead;}
|
||||||
|
@ -130,8 +129,8 @@ public:
|
||||||
virtual void flipHorizontal();
|
virtual void flipHorizontal();
|
||||||
virtual void flipVertical();
|
virtual void flipVertical();
|
||||||
|
|
||||||
bool isfh() { return _fh; }
|
bool isfh() const { return _fh; }
|
||||||
bool isfv() { return _fv; }
|
bool isfv() const { return _fv; }
|
||||||
|
|
||||||
// recursive
|
// recursive
|
||||||
bool isfhr();
|
bool isfhr();
|
||||||
|
|
|
@ -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_VFS "Use Virtual File System? Required for some additional features." TRUE)
|
||||||
|
|
||||||
OPTION(AQUARIA_USE_SDL2 "Use SDL2" FALSE)
|
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.
|
# No Steamworks SDK for Linux at the moment. Roll our own achievements.
|
||||||
ADD_DEFINITIONS(-DBBGE_BUILD_ACHIEVEMENTS_INTERNAL=1)
|
ADD_DEFINITIONS(-DBBGE_BUILD_ACHIEVEMENTS_INTERNAL=1)
|
||||||
|
@ -303,6 +304,10 @@ IF(AQUARIA_USE_SDL2)
|
||||||
ADD_DEFINITIONS(-DBBGE_BUILD_SDL2=1)
|
ADD_DEFINITIONS(-DBBGE_BUILD_SDL2=1)
|
||||||
ENDIF(AQUARIA_USE_SDL2)
|
ENDIF(AQUARIA_USE_SDL2)
|
||||||
|
|
||||||
|
IF(AQUARIA_USE_GLM)
|
||||||
|
ADD_DEFINITIONS(-DBBGE_USE_GLM=1)
|
||||||
|
ENDIF(AQUARIA_USE_GLM)
|
||||||
|
|
||||||
IF(AQUARIA_DEMO_BUILD)
|
IF(AQUARIA_DEMO_BUILD)
|
||||||
message(STATUS "Demo build.")
|
message(STATUS "Demo build.")
|
||||||
ADD_DEFINITIONS(-DAQUARIA_DEMO=1)
|
ADD_DEFINITIONS(-DAQUARIA_DEMO=1)
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
Name="VCCLCompilerTool"
|
Name="VCCLCompilerTool"
|
||||||
Optimization="0"
|
Optimization="0"
|
||||||
AdditionalIncludeDirectories=""$(SolutionDir)\..\ExternalLibs\freetype2\include\freetype\config";"$(SolutionDir)\..\ExternalLibs\gl";"$(SolutionDir)\..\ExternalLibs\glpng\zlib";"$(SolutionDir)\..\ExternalLibs\glpng\png";"$(SolutionDir)\..\ExternalLibs\libogg-1.3.0\include";"$(SolutionDir)\..\ExternalLibs\libvorbis-1.3.3\include";"$(SolutionDir)\..\ExternalLibs\freetype2\include";"$(SolutionDir)\..\ExternalLibs\FTGL\include";"$(SolutionDir)\..\ExternalLibs\SDL2\include";"$(SolutionDir)\..\ExternalLibs\AL\include";"$(SolutionDir)\..\BBGE";"$(SolutionDir)\..\ExternalLibs\lua-5.1.4\src";"$(SolutionDir)\..\ExternalLibs\lvpa\include";"$(SolutionDir)\..\ExternalLibs\lvpa";"$(SolutionDir)\..\ExternalLibs\ttvfs";"$(SolutionDir)\..\ExternalLibs\ttvfs_cfileapi";"$(SolutionDir)\..\ExternalLibs""
|
AdditionalIncludeDirectories=""$(SolutionDir)\..\ExternalLibs\freetype2\include\freetype\config";"$(SolutionDir)\..\ExternalLibs\gl";"$(SolutionDir)\..\ExternalLibs\glpng\zlib";"$(SolutionDir)\..\ExternalLibs\glpng\png";"$(SolutionDir)\..\ExternalLibs\libogg-1.3.0\include";"$(SolutionDir)\..\ExternalLibs\libvorbis-1.3.3\include";"$(SolutionDir)\..\ExternalLibs\freetype2\include";"$(SolutionDir)\..\ExternalLibs\FTGL\include";"$(SolutionDir)\..\ExternalLibs\SDL2\include";"$(SolutionDir)\..\ExternalLibs\AL\include";"$(SolutionDir)\..\BBGE";"$(SolutionDir)\..\ExternalLibs\lua-5.1.4\src";"$(SolutionDir)\..\ExternalLibs\lvpa\include";"$(SolutionDir)\..\ExternalLibs\lvpa";"$(SolutionDir)\..\ExternalLibs\ttvfs";"$(SolutionDir)\..\ExternalLibs\ttvfs_cfileapi";"$(SolutionDir)\..\ExternalLibs""
|
||||||
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"
|
MinimalRebuild="true"
|
||||||
BasicRuntimeChecks="0"
|
BasicRuntimeChecks="0"
|
||||||
RuntimeLibrary="3"
|
RuntimeLibrary="3"
|
||||||
|
@ -124,7 +124,7 @@
|
||||||
OmitFramePointers="true"
|
OmitFramePointers="true"
|
||||||
EnableFiberSafeOptimizations="true"
|
EnableFiberSafeOptimizations="true"
|
||||||
AdditionalIncludeDirectories=""$(SolutionDir)\..\ExternalLibs\freetype2\include\freetype\config";"$(SolutionDir)\..\ExternalLibs\gl";"$(SolutionDir)\..\ExternalLibs\glpng\zlib";"$(SolutionDir)\..\ExternalLibs\glpng\png";"$(SolutionDir)\..\ExternalLibs\libogg-1.3.0\include";"$(SolutionDir)\..\ExternalLibs\libvorbis-1.3.3\include";"$(SolutionDir)\..\ExternalLibs\freetype2\include";"$(SolutionDir)\..\ExternalLibs\FTGL\include";"$(SolutionDir)\..\ExternalLibs\SDL2\include";"$(SolutionDir)\..\ExternalLibs\AL\include";"$(SolutionDir)\..\BBGE";"$(SolutionDir)\..\ExternalLibs\lua-5.1.4\src";"$(SolutionDir)\..\ExternalLibs\lvpa\include";"$(SolutionDir)\..\ExternalLibs\lvpa";"$(SolutionDir)\..\ExternalLibs\ttvfs";"$(SolutionDir)\..\ExternalLibs\ttvfs_cfileapi";"$(SolutionDir)\..\ExternalLibs""
|
AdditionalIncludeDirectories=""$(SolutionDir)\..\ExternalLibs\freetype2\include\freetype\config";"$(SolutionDir)\..\ExternalLibs\gl";"$(SolutionDir)\..\ExternalLibs\glpng\zlib";"$(SolutionDir)\..\ExternalLibs\glpng\png";"$(SolutionDir)\..\ExternalLibs\libogg-1.3.0\include";"$(SolutionDir)\..\ExternalLibs\libvorbis-1.3.3\include";"$(SolutionDir)\..\ExternalLibs\freetype2\include";"$(SolutionDir)\..\ExternalLibs\FTGL\include";"$(SolutionDir)\..\ExternalLibs\SDL2\include";"$(SolutionDir)\..\ExternalLibs\AL\include";"$(SolutionDir)\..\BBGE";"$(SolutionDir)\..\ExternalLibs\lua-5.1.4\src";"$(SolutionDir)\..\ExternalLibs\lvpa\include";"$(SolutionDir)\..\ExternalLibs\lvpa";"$(SolutionDir)\..\ExternalLibs\ttvfs";"$(SolutionDir)\..\ExternalLibs\ttvfs_cfileapi";"$(SolutionDir)\..\ExternalLibs""
|
||||||
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"
|
StringPooling="true"
|
||||||
ExceptionHandling="0"
|
ExceptionHandling="0"
|
||||||
RuntimeLibrary="0"
|
RuntimeLibrary="0"
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
Name="VCCLCompilerTool"
|
Name="VCCLCompilerTool"
|
||||||
Optimization="0"
|
Optimization="0"
|
||||||
AdditionalIncludeDirectories=""$(SolutionDir)\..\ExternalLibs\freetype2\include\freetype\config";"$(SolutionDir)\..\ExternalLibs\gl";"$(SolutionDir)\..\ExternalLibs\glpng\zlib";"$(SolutionDir)\..\ExternalLibs\glpng\png";"$(SolutionDir)\..\ExternalLibs\libogg-1.3.0\include";"$(SolutionDir)\..\ExternalLibs\libvorbis-1.3.3\include";"$(SolutionDir)\..\ExternalLibs\freetype2\include";"$(SolutionDir)\..\ExternalLibs\FTGL\include";"$(SolutionDir)\..\ExternalLibs\SDL2\include";"$(SolutionDir)\..\ExternalLibs\AL\include";"$(SolutionDir)\..\ExternalLibs\ttvfs";"$(SolutionDir)\..\ExternalLibs\ttvfs_cfileapi";"$(SolutionDir)\..\ExternalLibs\lvpa";"$(SolutionDir)\..\ExternalLibs\lvpa\include";"$(SolutionDir)\..\ExternalLibs""
|
AdditionalIncludeDirectories=""$(SolutionDir)\..\ExternalLibs\freetype2\include\freetype\config";"$(SolutionDir)\..\ExternalLibs\gl";"$(SolutionDir)\..\ExternalLibs\glpng\zlib";"$(SolutionDir)\..\ExternalLibs\glpng\png";"$(SolutionDir)\..\ExternalLibs\libogg-1.3.0\include";"$(SolutionDir)\..\ExternalLibs\libvorbis-1.3.3\include";"$(SolutionDir)\..\ExternalLibs\freetype2\include";"$(SolutionDir)\..\ExternalLibs\FTGL\include";"$(SolutionDir)\..\ExternalLibs\SDL2\include";"$(SolutionDir)\..\ExternalLibs\AL\include";"$(SolutionDir)\..\ExternalLibs\ttvfs";"$(SolutionDir)\..\ExternalLibs\ttvfs_cfileapi";"$(SolutionDir)\..\ExternalLibs\lvpa";"$(SolutionDir)\..\ExternalLibs\lvpa\include";"$(SolutionDir)\..\ExternalLibs""
|
||||||
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"
|
MinimalRebuild="true"
|
||||||
BasicRuntimeChecks="0"
|
BasicRuntimeChecks="0"
|
||||||
RuntimeLibrary="3"
|
RuntimeLibrary="3"
|
||||||
|
@ -116,7 +116,7 @@
|
||||||
OmitFramePointers="true"
|
OmitFramePointers="true"
|
||||||
EnableFiberSafeOptimizations="true"
|
EnableFiberSafeOptimizations="true"
|
||||||
AdditionalIncludeDirectories=""$(SolutionDir)\..\ExternalLibs\freetype2\include\freetype\config";"$(SolutionDir)\..\ExternalLibs\gl";"$(SolutionDir)\..\ExternalLibs\glpng\zlib";"$(SolutionDir)\..\ExternalLibs\glpng\png";"$(SolutionDir)\..\ExternalLibs\libogg-1.3.0\include";"$(SolutionDir)\..\ExternalLibs\libvorbis-1.3.3\include";"$(SolutionDir)\..\ExternalLibs\freetype2\include";"$(SolutionDir)\..\ExternalLibs\FTGL\include";"$(SolutionDir)\..\ExternalLibs\SDL2\include";"$(SolutionDir)\..\ExternalLibs\AL\include";"$(SolutionDir)\..\ExternalLibs\ttvfs";"$(SolutionDir)\..\ExternalLibs\ttvfs_cfileapi";"$(SolutionDir)\..\ExternalLibs\lvpa";"$(SolutionDir)\..\ExternalLibs\lvpa\include";"$(SolutionDir)\..\ExternalLibs""
|
AdditionalIncludeDirectories=""$(SolutionDir)\..\ExternalLibs\freetype2\include\freetype\config";"$(SolutionDir)\..\ExternalLibs\gl";"$(SolutionDir)\..\ExternalLibs\glpng\zlib";"$(SolutionDir)\..\ExternalLibs\glpng\png";"$(SolutionDir)\..\ExternalLibs\libogg-1.3.0\include";"$(SolutionDir)\..\ExternalLibs\libvorbis-1.3.3\include";"$(SolutionDir)\..\ExternalLibs\freetype2\include";"$(SolutionDir)\..\ExternalLibs\FTGL\include";"$(SolutionDir)\..\ExternalLibs\SDL2\include";"$(SolutionDir)\..\ExternalLibs\AL\include";"$(SolutionDir)\..\ExternalLibs\ttvfs";"$(SolutionDir)\..\ExternalLibs\ttvfs_cfileapi";"$(SolutionDir)\..\ExternalLibs\lvpa";"$(SolutionDir)\..\ExternalLibs\lvpa\include";"$(SolutionDir)\..\ExternalLibs""
|
||||||
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"
|
StringPooling="true"
|
||||||
ExceptionHandling="0"
|
ExceptionHandling="0"
|
||||||
RuntimeLibrary="0"
|
RuntimeLibrary="0"
|
||||||
|
|
Loading…
Reference in a new issue