From d31a9b0538b85a366b7602e80c730e587c00a8c5 Mon Sep 17 00:00:00 2001 From: Kearwood Gilbert Date: Sun, 22 Apr 2018 23:27:20 -0700 Subject: [PATCH] Switching from GLEW to GLAD, WIP refactoring math library to separate built library, 'hydra'. --- .gitmodules | 9 + 3rdparty/glad | 1 + 3rdparty/glfw | 1 + CMakeLists.txt | 24 +++ hydra | 1 + kraken/KREngine-common.h | 454 +++++++++++++++++++-------------------- kraken/KRHelpers.h | 68 +++--- 7 files changed, 297 insertions(+), 261 deletions(-) create mode 100644 .gitmodules create mode 160000 3rdparty/glad create mode 160000 3rdparty/glfw create mode 160000 hydra diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..3d622d7 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,9 @@ +[submodule "3rdparty/glfw"] + path = 3rdparty/glfw + url = git@github.com:glfw/glfw.git +[submodule "3rdparty/glad"] + path = 3rdparty/glad + url = git@github.com:Dav1dde/glad.git +[submodule "hydra"] + path = hydra + url = git@github.com:KrakenEngine/hydra.git diff --git a/3rdparty/glad b/3rdparty/glad new file mode 160000 index 0000000..5831fb7 --- /dev/null +++ b/3rdparty/glad @@ -0,0 +1 @@ +Subproject commit 5831fb7741d2ab951a684b86c1570b77d7ab5cfb diff --git a/3rdparty/glfw b/3rdparty/glfw new file mode 160000 index 0000000..23dfeee --- /dev/null +++ b/3rdparty/glfw @@ -0,0 +1 @@ +Subproject commit 23dfeee4cb4fac69f0b1f3614c4305e2129cf43b diff --git a/CMakeLists.txt b/CMakeLists.txt index a5c672c..1d7c4c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,6 +84,30 @@ if(Boost_FOUND) target_link_libraries(kraken ${Boost_LIBRARIES}) endif() +# ---- Hydra ---- +add_subdirectory(hydra) +include_directories(hydra/include) +target_link_libraries(kraken hydra) + +# ---- OpenGL ---- +find_package(OpenGL REQUIRED) +include_directories( ${OPENGL_INCLUDE_DIRS} ) +target_link_libraries(kraken ${OPENGL_LIBRARIES}) + +# ---- GLAD ---- +add_subdirectory(3rdparty/glad) +include_directories(${GLAD_INCLUDE_DIRS}) +target_link_libraries(kraken glad) + +# ---- GLFW ---- +set(GLFW_BUILD_EXAMPLES OFF CACHE INTERNAL "Build the GLFW example programs") +set(GLFW_BUILD_TESTS OFF CACHE INTERNAL "Build the GLFW test programs") +set(GLFW_BUILD_DOCS OFF CACHE INTERNAL "Build the GLFW documentation") +set(GLFW_INSTALL OFF CACHE INTERNAL "Generate installation target") +add_subdirectory(3rdparty/glfw) +include_directories(3rdparty/glfw/include) +target_link_libraries(kraken glfw ${GLFW_LIBRARIES}) + # add_custom_target(package # COMMENT "Compressing..." # WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/archive" diff --git a/hydra b/hydra new file mode 160000 index 0000000..00bb9b6 --- /dev/null +++ b/hydra @@ -0,0 +1 @@ +Subproject commit 00bb9b66892c1f3918c6ce83cf2e1c7cbe6c3948 diff --git a/kraken/KREngine-common.h b/kraken/KREngine-common.h index 4c1a665..07202d3 100755 --- a/kraken/KREngine-common.h +++ b/kraken/KREngine-common.h @@ -1,227 +1,227 @@ -// -// KREngine-common.h -// KREngine -// -// Created by Kearwood Gilbert on 12-03-15. -// Copyright (c) 2012 Kearwood Software. All rights reserved. -// - - - -#ifndef KRENGINE_COMMON_H -#define KRENGINE_COMMON_H - -#include "public/kraken.h" -#include "KRHelpers.h" -using namespace kraken; - -#include -#include -#include -#include -#include -#include - - -#include -#include -#include -#include -#include -#include -#include - -#include "../3rdparty/tinyxml2/tinyxml2.h" -#if defined(__APPLE__) - -#include -#include -#include - -#include -#include -#include -#include - -#endif - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -// _USE_MATH_DEFINES must be defined to get M_PI in Windows -#define _USE_MATH_DEFINES -#include - - -#include -#include - - - - -using std::vector; -using std::string; -using std::set; -using std::list; -using std::map; - -using std::multimap; - -using std::stack; -using std::queue; - -#ifdef __APPLE__ -#include "TargetConditionals.h" -#include -#include -#include -#define KRAKEN_HAVE_BLAS 1 -#endif - -#define KRENGINE_MAX_TEXTURE_UNITS 8 - - -#if !defined(__i386__) && defined(__arm__) -#define KRAKEN_USE_ARM_NEON -#endif - - -#include -using std::unordered_map; -using std::unordered_multimap; -using std::hash; - -#if defined(_WIN32) || defined(_WIN64) - -#include -#include -typedef int64_t __int64_t; -typedef uint64_t __uint64_t; -typedef int32_t __int32_t; -typedef uint32_t __uint32_t; -typedef int16_t __int16_t; -typedef uint16_t __uint16_t; -typedef int8_t __int8_t; -typedef uint8_t __uint8_t; - -#include -// OpenGL ES 2.0 mapping to OpenGL 3.2 -#define glDeleteQueriesEXT glDeleteQueries -#define glGenQueriesEXT glGenQueries -#define glBeginQueryEXT glBeginQuery -#define glEndQueryEXT glEndQuery -#define glGetQueryObjectuivEXT glGetQueryObjectuiv -#define glTexStorage2DEXT glTexStorage2D -#define GL_ANY_SAMPLES_PASSED_EXT GL_ANY_SAMPLES_PASSED -#define GL_QUERY_RESULT_EXT GL_QUERY_RESULT - -#elif TARGET_OS_IPHONE - -#include -#include - -#else - -#include -#include - -// OpenGL ES 2.0 mapping to OpenGL 3.2 -#define glDepthRangef glDepthRange -#define glClearDepthf glClearDepth -#define glDeleteQueriesEXT glDeleteQueries -#define glGenQueriesEXT glGenQueries -#define glBeginQueryEXT glBeginQuery -#define glEndQueryEXT glEndQuery -#define glGetQueryObjectuivEXT glGetQueryObjectuiv -#define glTexStorage2DEXT glTexStorage2D -#define GL_ANY_SAMPLES_PASSED_EXT GL_ANY_SAMPLES_PASSED -#define GL_QUERY_RESULT_EXT GL_QUERY_RESULT - -#define GL_OES_mapbuffer 1 -#define glMapBufferOES glMapBuffer -#define glUnmapBufferOES glUnmapBuffer -#define GL_WRITE_ONLY_OES GL_WRITE_ONLY - -#define GL_OES_vertex_array_object 1 -#define glGenVertexArraysOES glGenVertexArrays -#define glBindVertexArrayOES glBindVertexArray -#define glDeleteVertexArraysOES glDeleteVertexArrays - -#endif - -#if defined(DEBUG) || defined(_DEBUG) -#define GLDEBUG(x) \ -x; \ -{ \ -GLenum e; \ -while( (e=glGetError()) != GL_NO_ERROR) \ -{ \ -fprintf(stderr, "Error at line number %d, in file %s. glGetError() returned %i for call %s\n",__LINE__, __FILE__, e, #x ); \ -} \ -} -#else -#define GLDEBUG(x) x; -#endif - - -#if defined(DEBUG) || defined(_DEBUG) -#define ALDEBUG(x) \ -x; \ -{ \ -GLenum e; \ -while( (e=alGetError()) != AL_NO_ERROR) \ -{ \ -fprintf(stderr, "Error at line number %d, in file %s. alGetError() returned %i for call %s\n",__LINE__, __FILE__, e, #x ); \ -} \ -} -#else -#define ALDEBUG(x) x; -#endif - -#if defined(DEBUG) || defined(_DEBUG) -#define OSDEBUG(x) \ -{ \ -OSStatus e = x; \ -if( e != noErr) \ -{ \ -fprintf(stderr, "Error at line number %d, in file %s. Returned %d for call %s\n",__LINE__, __FILE__, (int)e, #x ); \ -} \ -} -#else -#define OSDEBUG(x) x; -#endif - - -#if defined(GL_EXT_debug_marker) && (defined(DEBUG) || defined(_DEBUG)) - -#define GL_PUSH_GROUP_MARKER(x) glPushGroupMarkerEXT(0, x) -#define GL_POP_GROUP_MARKER glPopGroupMarkerEXT() - -#else - -#define GL_PUSH_GROUP_MARKER(x) -#define GL_POP_GROUP_MARKER - -#endif - -typedef enum { - STREAM_LEVEL_OUT, - STREAM_LEVEL_IN_LQ, - STREAM_LEVEL_IN_HQ -} kraken_stream_level; - -#include "KRBehavior.h" - -#endif - -using namespace kraken; +// +// KREngine-common.h +// KREngine +// +// Created by Kearwood Gilbert on 12-03-15. +// Copyright (c) 2012 Kearwood Software. All rights reserved. +// + + + +#ifndef KRENGINE_COMMON_H +#define KRENGINE_COMMON_H + +#include "public/kraken.h" +#include "KRHelpers.h" +using namespace kraken; + +#include +#include +#include +#include +#include +#include + + +#include +#include +#include +#include +#include +#include +#include + +#include "../3rdparty/tinyxml2/tinyxml2.h" +#if defined(__APPLE__) + +#include +#include +#include + +#include +#include +#include +#include + +#endif + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +// _USE_MATH_DEFINES must be defined to get M_PI in Windows +#define _USE_MATH_DEFINES +#include + + +#include +#include + + + + +using std::vector; +using std::string; +using std::set; +using std::list; +using std::map; + +using std::multimap; + +using std::stack; +using std::queue; + +#ifdef __APPLE__ +#include "TargetConditionals.h" +#include +#include +#include +#define KRAKEN_HAVE_BLAS 1 +#endif + +#define KRENGINE_MAX_TEXTURE_UNITS 8 + + +#if !defined(__i386__) && defined(__arm__) +#define KRAKEN_USE_ARM_NEON +#endif + + +#include +using std::unordered_map; +using std::unordered_multimap; +using std::hash; + +#if defined(_WIN32) || defined(_WIN64) + +#include +#include +typedef int64_t __int64_t; +typedef uint64_t __uint64_t; +typedef int32_t __int32_t; +typedef uint32_t __uint32_t; +typedef int16_t __int16_t; +typedef uint16_t __uint16_t; +typedef int8_t __int8_t; +typedef uint8_t __uint8_t; + +#include +// OpenGL ES 2.0 mapping to OpenGL 3.2 +#define glDeleteQueriesEXT glDeleteQueries +#define glGenQueriesEXT glGenQueries +#define glBeginQueryEXT glBeginQuery +#define glEndQueryEXT glEndQuery +#define glGetQueryObjectuivEXT glGetQueryObjectuiv +#define glTexStorage2DEXT glTexStorage2D +#define GL_ANY_SAMPLES_PASSED_EXT GL_ANY_SAMPLES_PASSED +#define GL_QUERY_RESULT_EXT GL_QUERY_RESULT + +#elif TARGET_OS_IPHONE + +#include +#include + +#else + +#include +#include + +// OpenGL ES 2.0 mapping to OpenGL 3.2 +#define glDepthRangef glDepthRange +#define glClearDepthf glClearDepth +#define glDeleteQueriesEXT glDeleteQueries +#define glGenQueriesEXT glGenQueries +#define glBeginQueryEXT glBeginQuery +#define glEndQueryEXT glEndQuery +#define glGetQueryObjectuivEXT glGetQueryObjectuiv +#define glTexStorage2DEXT glTexStorage2D +#define GL_ANY_SAMPLES_PASSED_EXT GL_ANY_SAMPLES_PASSED +#define GL_QUERY_RESULT_EXT GL_QUERY_RESULT + +#define GL_OES_mapbuffer 1 +#define glMapBufferOES glMapBuffer +#define glUnmapBufferOES glUnmapBuffer +#define GL_WRITE_ONLY_OES GL_WRITE_ONLY + +#define GL_OES_vertex_array_object 1 +#define glGenVertexArraysOES glGenVertexArrays +#define glBindVertexArrayOES glBindVertexArray +#define glDeleteVertexArraysOES glDeleteVertexArrays + +#endif + +#if defined(DEBUG) || defined(_DEBUG) +#define GLDEBUG(x) \ +x; \ +{ \ +GLenum e; \ +while( (e=glGetError()) != GL_NO_ERROR) \ +{ \ +fprintf(stderr, "Error at line number %d, in file %s. glGetError() returned %i for call %s\n",__LINE__, __FILE__, e, #x ); \ +} \ +} +#else +#define GLDEBUG(x) x; +#endif + + +#if defined(DEBUG) || defined(_DEBUG) +#define ALDEBUG(x) \ +x; \ +{ \ +GLenum e; \ +while( (e=alGetError()) != AL_NO_ERROR) \ +{ \ +fprintf(stderr, "Error at line number %d, in file %s. alGetError() returned %i for call %s\n",__LINE__, __FILE__, e, #x ); \ +} \ +} +#else +#define ALDEBUG(x) x; +#endif + +#if defined(DEBUG) || defined(_DEBUG) +#define OSDEBUG(x) \ +{ \ +OSStatus e = x; \ +if( e != noErr) \ +{ \ +fprintf(stderr, "Error at line number %d, in file %s. Returned %d for call %s\n",__LINE__, __FILE__, (int)e, #x ); \ +} \ +} +#else +#define OSDEBUG(x) x; +#endif + + +#if defined(GL_EXT_debug_marker) && (defined(DEBUG) || defined(_DEBUG)) + +#define GL_PUSH_GROUP_MARKER(x) glPushGroupMarkerEXT(0, x) +#define GL_POP_GROUP_MARKER glPopGroupMarkerEXT() + +#else + +#define GL_PUSH_GROUP_MARKER(x) +#define GL_POP_GROUP_MARKER + +#endif + +typedef enum { + STREAM_LEVEL_OUT, + STREAM_LEVEL_IN_LQ, + STREAM_LEVEL_IN_HQ +} kraken_stream_level; + +#include "KRBehavior.h" + +#endif + +using namespace kraken; diff --git a/kraken/KRHelpers.h b/kraken/KRHelpers.h index 05a2468..247473d 100644 --- a/kraken/KRHelpers.h +++ b/kraken/KRHelpers.h @@ -1,34 +1,34 @@ -#ifndef KRHELPERS_H -#define KRHELPERS_H - -#if defined(_WIN32) || defined(_WIN64) -#include -#elif defined(__linux__) || defined(__unix__) || defined(__posix__) -#include -#include -#include -#elif defined(__APPLE__) -#include -#include -#endif -#include "../3rdparty/tinyxml2/tinyxml2.h" - -#define KRMIN(x,y) ((x) < (y) ? (x) : (y)) -#define KRMAX(x,y) ((x) > (y) ? (x) : (y)) -#define KRCLAMP(x, min, max) (KRMAX(KRMIN(x, max), min)) -#define KRALIGN(x) ((x + 3) & ~0x03) - -float const PI = 3.141592653589793f; -float const D2R = PI * 2 / 360; - -namespace kraken { - void SetUniform(GLint location, const Vector2 &v); - void SetUniform(GLint location, const Vector3 &v); - void SetUniform(GLint location, const Vector4 &v); - void SetUniform(GLint location, const Matrix4 &v); - - void setXMLAttribute(const std::string &base_name, ::tinyxml2::XMLElement *e, const Vector3 &value, const Vector3 &default_value); - const Vector3 getXMLAttribute(const std::string &base_name, ::tinyxml2::XMLElement *e, const Vector3 &default_value); -} // namespace kraken - -#endif +#ifndef KRHELPERS_H +#define KRHELPERS_H + +#if defined(_WIN32) || defined(_WIN64) +#include +#elif defined(__linux__) || defined(__unix__) || defined(__posix__) +#include +#include +#include +#elif defined(__APPLE__) +#include +#include +#endif +#include "../3rdparty/tinyxml2/tinyxml2.h" + +#define KRMIN(x,y) ((x) < (y) ? (x) : (y)) +#define KRMAX(x,y) ((x) > (y) ? (x) : (y)) +#define KRCLAMP(x, min, max) (KRMAX(KRMIN(x, max), min)) +#define KRALIGN(x) ((x + 3) & ~0x03) + +float const PI = 3.141592653589793f; +float const D2R = PI * 2 / 360; + +namespace kraken { + void SetUniform(GLint location, const Vector2 &v); + void SetUniform(GLint location, const Vector3 &v); + void SetUniform(GLint location, const Vector4 &v); + void SetUniform(GLint location, const Matrix4 &v); + + void setXMLAttribute(const std::string &base_name, ::tinyxml2::XMLElement *e, const Vector3 &value, const Vector3 &default_value); + const Vector3 getXMLAttribute(const std::string &base_name, ::tinyxml2::XMLElement *e, const Vector3 &default_value); +} // namespace kraken + +#endif