├── .gitignore ├── .gitmodules ├── .travis.yml ├── Architecture.dia ├── BuildHelper.py ├── LICENSE ├── README.md ├── SConstruct ├── build_and_test.py ├── build_cef.sh ├── cef_client ├── README.md ├── SConstruct ├── include │ ├── AttributeBinding.hpp │ ├── ClientApp.hpp │ ├── DuplicateAttributeException.hpp │ ├── DuplicateFunctionException.hpp │ ├── ExceptionList.hpp │ ├── FunctionBinding.hpp │ ├── FunctionList.hpp │ ├── Macros.hpp │ └── ObjectBinding.hpp └── src │ ├── AttributeBinding.cpp │ ├── ClientApp.cpp │ ├── DuplicateAttributeException.cpp │ ├── DuplicateFunctionException.cpp │ ├── FunctionBinding.cpp │ ├── Main.cpp │ └── ObjectBinding.cpp ├── colorizer.py ├── data └── shaders │ ├── glr.glsl │ ├── glr_basic.program │ ├── glr_gui.frag │ ├── glr_gui.program │ ├── glr_gui.vert │ ├── light.glsl │ ├── material.glsl │ ├── mesh_only.frag │ ├── mesh_only.program │ ├── mesh_only.vert │ ├── shader.frag │ ├── shader.vert │ ├── sky_box.frag │ ├── sky_box.program │ ├── sky_box.vert │ ├── test.frag │ ├── test.program │ ├── voxel.frag │ ├── voxel.program │ └── voxel.vert ├── docs ├── bootstrap.min.css ├── bootstrap.min.js ├── customdoxygen.css ├── doxy-boot.js ├── doxygen_generate.sh ├── footer.html ├── glrdox ├── header.html └── jquery-1.11.0.min.js ├── extras ├── FpsCamera.cpp └── FpsCamera.hpp ├── include ├── BasicSceneManager.hpp ├── BasicSceneNode.hpp ├── Camera.hpp ├── Configure.hpp ├── GlrInclude.hpp ├── GlrProgram.hpp ├── ICamera.hpp ├── ILight.hpp ├── ISceneManager.hpp ├── ISceneNode.hpp ├── IWindow.hpp ├── IWindowResizeListener.hpp ├── Id.hpp ├── IdManager.hpp ├── Light.hpp ├── ProgramSettings.hpp ├── Window.hpp ├── environment │ ├── EnvironmentManager.hpp │ ├── IEnvironmentManager.hpp │ ├── ISky.hpp │ ├── SkyBox.hpp │ └── SkyBoxPlane.hpp ├── exceptions │ ├── Exception.hpp │ ├── ExceptionInclude.hpp │ ├── FormatException.hpp │ ├── GlException.hpp │ ├── InvalidArgumentException.hpp │ ├── IoException.hpp │ ├── LogicException.hpp │ └── RuntimeException.hpp ├── glw │ ├── AnimatedBoneNode.hpp │ ├── Animation.hpp │ ├── Animation.inl │ ├── AnimationManager.hpp │ ├── Bone.hpp │ ├── BoneData.hpp │ ├── BoneNode.hpp │ ├── Constants.hpp │ ├── IAnimation.hpp │ ├── IAnimationManager.hpp │ ├── IBindable.hpp │ ├── IGraphicsObject.hpp │ ├── IMaterial.hpp │ ├── IMaterialBindListener.hpp │ ├── IMaterialManager.hpp │ ├── IMesh.hpp │ ├── IMeshManager.hpp │ ├── IOpenGlDevice.hpp │ ├── ITexture.hpp │ ├── ITextureBindListener.hpp │ ├── ITextureManager.hpp │ ├── Material.hpp │ ├── Material.inl │ ├── MaterialData.hpp │ ├── MaterialManager.hpp │ ├── Mesh.hpp │ ├── Mesh.inl │ ├── MeshManager.hpp │ ├── OpenGlDevice.hpp │ ├── OpenGlDeviceSettings.hpp │ ├── Texture2D.hpp │ ├── Texture2D.inl │ ├── Texture2DArray.hpp │ ├── Texture2DArray.inl │ ├── TextureManager.hpp │ ├── TextureSettings.hpp │ ├── VertexBoneData.hpp │ └── shaders │ │ ├── CPreProcessor.hpp │ │ ├── Constants.hpp │ │ ├── GlrParser.hpp │ │ ├── GlrPreProcessor.hpp │ │ ├── GlrShader.hpp │ │ ├── GlrShaderProgram.hpp │ │ ├── GlslShader.hpp │ │ ├── GlslShaderProgram.hpp │ │ ├── IShader.hpp │ │ ├── IShaderProgram.hpp │ │ ├── IShaderProgramBindListener.hpp │ │ ├── IShaderProgramManager.hpp │ │ └── ShaderProgramManager.hpp ├── gui │ ├── IGui.hpp │ ├── IGuiComponent.hpp │ ├── IGuiObject.hpp │ └── cef │ │ ├── Gui.hpp │ │ ├── GuiComponent.hpp │ │ ├── GuiObject.hpp │ │ └── RenderHandler.hpp ├── models │ ├── AnimationData.hpp │ ├── AnimationSet.hpp │ ├── AssImpLoader.hpp │ ├── Billboard.hpp │ ├── BillboardManager.hpp │ ├── Constants.hpp │ ├── IBillboard.hpp │ ├── IBillboardManager.hpp │ ├── IModel.hpp │ ├── IModelManager.hpp │ ├── IRenderable.hpp │ ├── MaterialData.hpp │ ├── MeshData.hpp │ ├── Model.hpp │ ├── Model.inl │ ├── ModelData.hpp │ ├── ModelLoader.hpp │ ├── ModelManager.hpp │ └── TextureData.hpp ├── serialize │ ├── ITextSerializable.hpp │ ├── Serialization.hpp │ ├── SplitMember.hpp │ ├── TextInArchive.hpp │ ├── TextOutArchive.hpp │ ├── glm │ │ ├── IVec4.hpp │ │ ├── Mat4.hpp │ │ ├── Quat.hpp │ │ ├── Vec2.hpp │ │ ├── Vec3.hpp │ │ └── Vec4.hpp │ └── std │ │ ├── Map.hpp │ │ └── Vector.hpp └── terrain │ ├── Constants.hpp │ ├── IFieldFunction.hpp │ ├── ITerrain.hpp │ ├── ITerrainManager.hpp │ ├── ITerrainManagerEventListener.hpp │ ├── IVoxelChunkMeshGenerator.hpp │ ├── Interp.hpp │ ├── Interpolation.hpp │ ├── Terrain.hpp │ ├── Terrain.md │ ├── TerrainManager.hpp │ ├── TerrainMesh.hpp │ ├── TerrainMeshSerializer.hpp │ ├── TerrainSettings.hpp │ ├── Voxel.hpp │ ├── VoxelChunk.hpp │ ├── VoxelChunkCache.hpp │ ├── VoxelChunkNoiseGenerator.hpp │ ├── dual_contouring │ ├── LICENSE │ ├── Qef.hpp │ ├── README │ └── VoxelChunkMeshGenerator.hpp │ └── marching_cubes │ ├── README │ └── VoxelChunkMeshGenerator.hpp ├── samples ├── SConstruct ├── lights │ ├── SConstruct │ └── src │ │ ├── Main.cpp │ │ ├── Main.hpp │ │ └── extras │ │ ├── FpsCamera.cpp │ │ └── FpsCamera.hpp ├── resources │ └── models │ │ └── StickMan_0 │ │ ├── LICENSE.md │ │ ├── README.md │ │ ├── StickMan_0.blend │ │ └── StickMan_0.x └── simple │ ├── SConstruct │ └── src │ ├── Main.cpp │ ├── Main.hpp │ └── extras │ ├── FpsCamera.cpp │ └── FpsCamera.hpp ├── setup.py ├── src ├── BasicSceneManager.cpp ├── BasicSceneNode.cpp ├── Camera.cpp ├── GlrProgram.cpp ├── Id.cpp ├── IdManager.cpp ├── Light.cpp ├── Window.cpp ├── environment │ ├── EnvironmentManager.cpp │ ├── SkyBox.cpp │ └── SkyBoxPlane.cpp ├── exceptions │ ├── Exception.cpp │ ├── FormatException.cpp │ ├── GlException.cpp │ ├── InvalidArgumentException.cpp │ ├── IoException.cpp │ ├── LogicException.cpp │ └── RuntimeException.cpp ├── glw │ ├── Animation.cpp │ ├── AnimationManager.cpp │ ├── Constants.cpp │ ├── Material.cpp │ ├── MaterialManager.cpp │ ├── Mesh.cpp │ ├── MeshManager.cpp │ ├── OpenGlDevice.cpp │ ├── Texture2D.cpp │ ├── Texture2DArray.cpp │ ├── TextureManager.cpp │ └── shaders │ │ ├── CPreProcessor.cpp │ │ ├── GlrParser.cpp │ │ ├── GlrPreProcessor.cpp │ │ ├── GlrShader.cpp │ │ ├── GlrShaderProgram.cpp │ │ ├── GlslShader.cpp │ │ ├── GlslShaderProgram.cpp │ │ └── ShaderProgramManager.cpp ├── gui │ └── cef │ │ ├── Gui.cpp │ │ ├── GuiComponent.cpp │ │ ├── GuiObject.cpp │ │ └── RenderHandler.cpp ├── models │ ├── AssImpLoader.cpp │ ├── Billboard.cpp │ ├── BillboardManager.cpp │ ├── Model.cpp │ ├── ModelLoader.cpp │ └── ModelManager.cpp ├── refactor.sh ├── serialize │ ├── TextInArchive.cpp │ └── TextOutArchive.cpp └── terrain │ ├── Interpolation.cpp │ ├── Terrain.cpp │ ├── TerrainManager.cpp │ ├── TerrainMesh.cpp │ ├── TerrainMeshSerializer.cpp │ ├── Voxel.cpp │ ├── VoxelChunk.cpp │ ├── VoxelChunkCache.cpp │ ├── VoxelChunkNoiseGenerator.cpp │ ├── dual_contouring │ ├── Qef.cpp │ └── VoxelChunkMeshGenerator.cpp │ └── marching_cubes │ └── VoxelChunkMeshGenerator.cpp ├── tests ├── SConstruct ├── build_and_run.py └── src │ ├── CameraTests.cpp │ ├── CefClientTests.cpp │ ├── FpsCameraTests.cpp │ ├── GlrProgramTests.cpp │ ├── Main.cpp │ ├── MeshManagerTests.cpp │ ├── SceneManagerTests.cpp │ ├── SceneNodeTests.cpp │ └── shaders │ ├── glr.glsl │ ├── glr_basic.program │ ├── light.glsl │ ├── material.glsl │ ├── shader.frag │ └── shader.vert └── xsupplicant.cfg /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated source # 2 | #################### 3 | include/glw/shaders/ShaderData.hpp 4 | 5 | # Compiled source # 6 | ################### 7 | build/ 8 | *.o 9 | cef_client/build/ 10 | *.pyc 11 | samples/simple/build/ 12 | samples/lights/build/ 13 | tests/build/ 14 | 15 | # Windows debug files # 16 | ####################### 17 | *.pdb 18 | 19 | # CEF lib directory # 20 | ##################### 21 | lib 22 | 23 | # Dependencies directory # 24 | ########################## 25 | deps 26 | 27 | # Documentation # 28 | ################# 29 | docs/dox/* 30 | 31 | # Logs and databases # 32 | ###################### 33 | .sconsign.dblite 34 | glr.log 35 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "src/common/logger"] 2 | path = src/common/logger 3 | url = https://github.com/jarrettchisholm/logger.git 4 | [submodule "cef_client/src/common/logger"] 5 | path = cef_client/src/common/logger 6 | url = https://github.com/jarrettchisholm/logger.git 7 | [submodule "src/common/utilities"] 8 | path = src/common/utilities 9 | url = https://github.com/jarrettchisholm/utilities.git 10 | [submodule "cef_client/src/common/utilities"] 11 | path = cef_client/src/common/utilities 12 | url = https://github.com/jarrettchisholm/utilities.git 13 | [submodule "src/common/math"] 14 | path = src/common/math 15 | url = https://github.com/jarrettchisholm/math.git 16 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | compiler: 3 | - gcc 4 | env: 5 | - SCONS_NUM_JOBS=2 6 | before_install: 7 | - if test $CC = gcc; then sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test; fi 8 | - sudo apt-get update -qq 9 | - sudo apt-get install build-essential libgtk2.0-dev libgtkglext1-dev 10 | - if test $CC = gcc; then sudo apt-get install gcc-4.7 g++-4.7; fi 11 | - if test $CC = gcc; then sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 20; fi 12 | - if test $CC = gcc; then sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.7 20; fi 13 | - if test $CC = gcc; then sudo update-alternatives --config gcc; fi 14 | - if test $CC = gcc; then sudo update-alternatives --config g++; fi 15 | install: 16 | - python setup.py release 17 | script: 18 | - python build_and_test.py 19 | -------------------------------------------------------------------------------- /Architecture.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jarrettchisholm/glr/79a57b12e26fe84595e833cace3528cb9c82bc20/Architecture.dia -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 2 | Version 2, December 2004 3 | 4 | Copyright (C) 2004 Sam Hocevar 5 | 6 | Everyone is permitted to copy and distribute verbatim or modified 7 | copies of this license document, and changing it is allowed as long 8 | as the name is changed. 9 | 10 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 12 | 13 | 0. You just DO WHAT THE FUCK YOU WANT TO. 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Graphics Language Renderer 2 | ========================== 3 | 4 | [![Build Status](https://travis-ci.org/jarrettchisholm/glr.png)](https://travis-ci.org/jarrettchisholm/glr) 5 | 6 | Overview 7 | -------- 8 | A graphics rendering engine written in C++ (using C++11) and OpenGL (targetting 3.2 and above). 9 | 10 | Goals 11 | ----- 12 | The goals for this project is to create a graphics rendering engine library that is: 13 | - Fast 14 | - Easy to use 15 | - Robust 16 | 17 | Furthermore, the goals for the code are for it to be: 18 | - Documented 19 | - Clean 20 | 21 | Compile 22 | ------- 23 | You will need several pre-requisites installed before compilation will work. For an automated setup, check out 24 | the [Automatic Building](https://github.com/jarrettchisholm/glr/wiki/Automatic-Building) section of the wiki. 25 | 26 | Assuming you have all the pre-requisites ready to go, you can compile by running `python setup.py` followed by `scons` from the terminal (or 27 | the Developer Command Prompt for VS2013 on Windows). 28 | 29 | For more details about compiling, check out the [wiki](https://github.com/jarrettchisholm/glr/wiki). 30 | -------------------------------------------------------------------------------- /build_and_test.py: -------------------------------------------------------------------------------- 1 | #! /bin/python 2 | 3 | import subprocess, sys, os 4 | import shlex 5 | 6 | args = '' 7 | for arg in sys.argv: 8 | if (arg != 'build_and_test.py' and arg != 'build_and_run.py'): 9 | args += ' ' + arg 10 | 11 | exitCode = subprocess.call( 'scons ' + args, shell=True) 12 | 13 | if (exitCode is not 0): 14 | sys.exit(1) 15 | 16 | os.chdir( 'tests/' ) 17 | exitCode = subprocess.call( 'scons ' + args, shell=True) 18 | 19 | if (exitCode is not 0): 20 | sys.exit(1) 21 | 22 | # Don't run the tests yet (Can't on Travis CI) 23 | #os.chdir( 'build/' ) 24 | #exitCode = subprocess.call( "./glr_tests" ) 25 | # 26 | #if (exitCode is not 0): 27 | # sys.exit(1) 28 | -------------------------------------------------------------------------------- /build_cef.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | cd deps/cef3 4 | cmake . 5 | make -j2 6 | 7 | -------------------------------------------------------------------------------- /cef_client/README.md: -------------------------------------------------------------------------------- 1 | Compile 2 | ======= 3 | To compile, run `scons` from the command line. 4 | 5 | **Note**: You must have a 'lib' directory with the files: 6 | 7 | **Linux** 8 | 9 | - libcef.so 10 | - libffmpegsumo.so 11 | - libcef_dll_wrapper.lib 12 | - libcef_dll_wrapper 13 | 14 | **Windows** 15 | 16 | - libcef.dll 17 | - libcef.lib 18 | - libffmpegsumo.dll 19 | - libcef_dll_wrapper.lib 20 | 21 | The libcef_dll_wrapper is the directory that contains all of the cef_dll object files (within their folder heirarchy). 22 | -------------------------------------------------------------------------------- /cef_client/include/AttributeBinding.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ATTRIBUTEBINDING_H_ 2 | #define ATTRIBUTEBINDING_H_ 3 | 4 | #include 5 | 6 | #include 7 | 8 | #include "Macros.hpp" 9 | 10 | namespace glr 11 | { 12 | namespace cef_client 13 | { 14 | 15 | class AttributeBinding 16 | { 17 | public: 18 | AttributeBinding(std::wstring name); 19 | AttributeBinding(std::wstring name, std::wstring valueWstring); 20 | AttributeBinding(std::wstring name, std::string valueString); 21 | AttributeBinding(std::wstring name, int valueInt); 22 | AttributeBinding(std::wstring name, unsigned int valueUint); 23 | AttributeBinding(std::wstring name, bool valueBool); 24 | AttributeBinding(std::wstring name, float valueFloat); 25 | AttributeBinding(std::wstring name, double valueDouble); 26 | AttributeBinding(std::wstring name, CefRefPtr valueV8); 27 | 28 | virtual ~AttributeBinding(); 29 | 30 | // TODO: Get rid of macros for getters and setters 31 | GETSET(std::wstring, name_, Name) 32 | 33 | GETSET(std::wstring, valueWstring_, ValueWstring) 34 | GETSET(std::string, valueString_, ValueString) 35 | GETSET(int, valueInt_, ValueInt) 36 | GETSET(unsigned int, valueUint_, ValueUint) 37 | GETSET(bool, valueBool_, ValueBool) 38 | GETSET(float, valueFloat_, ValueFloat) 39 | GETSET(double, valueDouble_, ValueDouble) 40 | GETSET(CefRefPtr, valueV8_, ValueV8) 41 | 42 | GETSET(bool, isWstring_, IsWstring) 43 | GETSET(bool, isString_, IsString) 44 | GETSET(bool, isInt_, IsInt) 45 | GETSET(bool, isUint_, IsUint) 46 | GETSET(bool, isBool_, IsBool) 47 | GETSET(bool, isFloat_, IsFloat) 48 | GETSET(bool, isDouble_, IsDouble) 49 | GETSET(bool, isV8_, IsV8) 50 | 51 | private: 52 | std::wstring name_; 53 | 54 | std::wstring valueWstring_; 55 | std::string valueString_; 56 | int valueInt_; 57 | unsigned int valueUint_; 58 | bool valueBool_; 59 | float valueFloat_; 60 | double valueDouble_; 61 | CefRefPtr valueV8_; 62 | 63 | bool isWstring_; 64 | bool isString_; 65 | bool isInt_; 66 | bool isUint_; 67 | bool isBool_; 68 | bool isFloat_; 69 | bool isDouble_; 70 | bool isV8_; 71 | 72 | }; 73 | 74 | } 75 | } 76 | 77 | #endif /* ATTRIBUTEBINDING_H_ */ 78 | -------------------------------------------------------------------------------- /cef_client/include/DuplicateAttributeException.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DUPLICATEATTRIBUTEEXCEPTION_H_ 2 | #define DUPLICATEATTRIBUTEEXCEPTION_H_ 3 | 4 | #include 5 | 6 | namespace glr 7 | { 8 | namespace cef_client 9 | { 10 | 11 | class DuplicateAttributeException : public std::runtime_error 12 | { 13 | public: 14 | DuplicateAttributeException(std::wstring attrName); 15 | virtual ~DuplicateAttributeException() throw(); 16 | }; 17 | 18 | } 19 | } 20 | 21 | #endif /* DUPLICATEATTRIBUTEEXCEPTION_H_ */ 22 | -------------------------------------------------------------------------------- /cef_client/include/DuplicateFunctionException.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DUPLICATEFUNCTIONEXCEPTION_H_ 2 | #define DUPLICATEFUNCTIONEXCEPTION_H_ 3 | 4 | #include 5 | 6 | namespace glr 7 | { 8 | namespace cef_client 9 | { 10 | 11 | class DuplicateFunctionException : public std::runtime_error 12 | { 13 | public: 14 | DuplicateFunctionException(std::wstring funcName); 15 | virtual ~DuplicateFunctionException() throw(); 16 | }; 17 | 18 | } 19 | } 20 | 21 | #endif /* DUPLICATEFUNCTIONEXCEPTION_H_ */ 22 | -------------------------------------------------------------------------------- /cef_client/include/ExceptionList.hpp: -------------------------------------------------------------------------------- 1 | #ifndef EXCEPTIONLIST_H_ 2 | #define EXCEPTIONLIST_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace glr 8 | { 9 | namespace cef_client 10 | { 11 | 12 | /** 13 | * Exceptions available: 14 | * 15 | * BIND_EXCEPTION - when something bad happens during binding 16 | * JS_BIND_EXCEPTION - when something bad happens during binding of a js callback function 17 | * EXECUTE_EXCEPTION - when something bad happens during execution of a bound function 18 | * MESSAGE_EXCEPTION 19 | */ 20 | enum Exception 21 | { 22 | BIND_EXCEPTION = 0, 23 | JS_BIND_EXCEPTION, 24 | EXECUTE_EXCEPTION, 25 | MESSAGE_EXCEPTION 26 | }; 27 | 28 | namespace 29 | { 30 | 31 | std::string getStringName(Exception exception) 32 | { 33 | switch (exception) 34 | { 35 | case Exception::BIND_EXCEPTION: 36 | return std::string("BindException"); 37 | break; 38 | 39 | case Exception::JS_BIND_EXCEPTION: 40 | return std::string("JsBindException"); 41 | break; 42 | 43 | case Exception::EXECUTE_EXCEPTION: 44 | return std::string("ExecuteException"); 45 | break; 46 | 47 | case Exception::MESSAGE_EXCEPTION: 48 | return std::string("MessageException"); 49 | break; 50 | 51 | default: 52 | return std::string(); 53 | } 54 | 55 | return std::string(); 56 | } 57 | 58 | } 59 | 60 | } 61 | } 62 | 63 | #endif /* EXCEPTIONLIST_H_ */ 64 | 65 | -------------------------------------------------------------------------------- /cef_client/include/FunctionBinding.hpp: -------------------------------------------------------------------------------- 1 | #ifndef FUNCTIONBINDING_H_ 2 | #define FUNCTIONBINDING_H_ 3 | 4 | #include 5 | 6 | #include "Macros.hpp" 7 | 8 | namespace glr 9 | { 10 | namespace cef_client 11 | { 12 | 13 | class FunctionBinding 14 | { 15 | public: 16 | FunctionBinding(std::wstring name); 17 | virtual ~FunctionBinding(); 18 | 19 | // TODO: Get rid of macro setter and getter 20 | GETSET(std::wstring, name_, Name) 21 | 22 | private: 23 | std::wstring name_; 24 | }; 25 | 26 | } 27 | } 28 | 29 | #endif /* FUNCTIONBINDING_H_ */ 30 | -------------------------------------------------------------------------------- /cef_client/include/FunctionList.hpp: -------------------------------------------------------------------------------- 1 | #ifndef FUNCTIONLIST_H_ 2 | #define FUNCTIONLIST_H_ 3 | 4 | #include 5 | 6 | namespace glr 7 | { 8 | namespace cef_client 9 | { 10 | /* 11 | enum Function 12 | { 13 | ADD_FUNCTION = 0, 14 | REMOVE_FUNCTION, 15 | ADD_ATTRIBUTE, 16 | REMOVE_ATTRIBUTE, 17 | ADD_OBJECT, 18 | REMOVE_OBJECT, 19 | ADD_ATTRIBUTE_TO_OBJECT, 20 | REMOVE_ATTRIBUTE_FROM_OBJECT, 21 | ADD_METHOD_TO_OBJECT, 22 | REMOVE_METHOD_FROM_OBJECT, 23 | FUNCTION_RESULT, 24 | ALL_BINDINGS_SENT 25 | }; 26 | */ 27 | 28 | /** 29 | * Functions available to send to the browser: 30 | * 31 | * ExecuteFunction 32 | * funcName [ [, ...]] 33 | * ReadyForBindings 34 | * 35 | * AllBindingsReceived 36 | * 37 | * 38 | * Functions the browser can send us: 39 | * 40 | * AddFunction 41 | * funcName 42 | * RemoveFunction 43 | * funcName 44 | * AddAttribute 45 | * attrName 46 | * RemoveAttribute 47 | * attrName 48 | * AddObject 49 | * objName 50 | * RemoveObject 51 | * objName 52 | * AddAttributeToObject 53 | * objName attrName 54 | * RemoveAttributeFromObject 55 | * objName attrName 56 | * AddMethodToObject 57 | * objName methodName 58 | * RemoveMethodFromObject 59 | * objName methodName 60 | * FunctionResult 61 | * resultType resultValue 62 | * AllBindingsSent 63 | * 64 | */ 65 | const std::wstring ADD_FUNCTION = L"AddFunction"; 66 | const std::wstring REMOVE_FUNCTION = L"RemoveFunction"; 67 | const std::wstring ADD_ATTRIBUTE = L"AddAttribute"; 68 | const std::wstring REMOVE_ATTRIBUTE = L"RemoveAttribute"; 69 | const std::wstring ADD_OBJECT = L"AddObject"; 70 | const std::wstring REMOVE_OBJECT = L"RemoveObject"; 71 | const std::wstring ADD_ATTRIBUTE_TO_OBJECT = L"AddAttributeToObject"; 72 | const std::wstring REMOVE_ATTRIBUTE_FROM_OBJECT = L"RemoveAttributeFromObject"; 73 | const std::wstring ADD_METHOD_TO_OBJECT = L"AddMethodToObject"; 74 | const std::wstring REMOVE_METHOD_FROM_OBJECT = L"RemoveMethodFromObject"; 75 | const std::wstring FUNCTION_RESULT = L"FunctionResult"; 76 | const std::wstring ALL_BINDINGS_SENT = L"AllBindingsSent"; 77 | 78 | // Functions to be sent to the browser process 79 | const std::wstring EXECUTE_FUNCTION = L"ExecuteFunction"; 80 | const std::wstring READY_FOR_BINDINGS = L"ReadyForBindings"; 81 | const std::wstring ALL_BINDINGS_RECEIVED = L"AllBindingsReceived"; 82 | 83 | // Status values to be returned to a browser process 84 | const std::wstring SUCCESS = L"Success"; 85 | const std::wstring EXCEPTION = L"Exception"; 86 | 87 | } 88 | } 89 | 90 | #endif /* FUNCTIONLIST_H_ */ 91 | 92 | -------------------------------------------------------------------------------- /cef_client/include/Macros.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MACROS_H_ 2 | #define MACROS_H_ 3 | 4 | #define GETSET(Type, MemberName, FaceName) \ 5 | Type get##FaceName() const { \ 6 | return MemberName; \ 7 | }; \ 8 | \ 9 | void set##FaceName(Type value) { \ 10 | MemberName = value; \ 11 | }; 12 | 13 | #define GETSET_INTERFACE(Type, FaceName) \ 14 | virtual Type get##FaceName() const = 0; \ 15 | \ 16 | virtual void set##FaceName(Type value) = 0; 17 | 18 | 19 | /* 20 | #define GETSET(ClassName, Type, MemberName, FaceName) \ 21 | Type ClassName::get##FaceName() const { \ 22 | return MemberName; \ 23 | }; \ 24 | \ 25 | void ClassName::set##FaceName(Type value) { \ 26 | MemberName = value; \ 27 | } 28 | */ 29 | 30 | #endif /* MACROS_H_ */ 31 | -------------------------------------------------------------------------------- /cef_client/include/ObjectBinding.hpp: -------------------------------------------------------------------------------- 1 | #ifndef OBJECTBINDING_H_ 2 | #define OBJECTBINDING_H_ 3 | 4 | #include "FunctionBinding.hpp" 5 | #include "AttributeBinding.hpp" 6 | 7 | #include "ExceptionList.hpp" 8 | 9 | namespace glr 10 | { 11 | namespace cef_client 12 | { 13 | 14 | class ObjectBinding : public CefV8Handler 15 | { 16 | public: 17 | ObjectBinding(); 18 | ObjectBinding(std::wstring name); 19 | 20 | virtual ~ObjectBinding(); 21 | 22 | /* 23 | * When your javascript calls a method that has been defined as a native api call, it will call this method. 24 | * 25 | * This method will encode the function call, and send it to the browser process over IPC. 26 | * 27 | * The format that is sent via IPC looks like this: 28 | * [, ..] 29 | * 30 | * The browser process will process the function call, execute the requested function (if it exists), and send the result via IPC to this 31 | * process. 32 | */ 33 | bool Execute(const CefString& name, CefRefPtr object, const CefV8ValueList& arguments, CefRefPtr& retval, CefString& exception); 34 | 35 | bool hasFunction(std::wstring funcName); 36 | bool hasAttribute(std::wstring attrName); 37 | void addFunction(FunctionBinding function); 38 | void addAttribute(AttributeBinding attribute); 39 | 40 | const std::vector< FunctionBinding > getFunctions(); 41 | const std::vector< AttributeBinding > getAttributes(); 42 | 43 | GETSET(std::wstring, name_, Name) 44 | 45 | private: 46 | std::wstring name_; 47 | std::vector< FunctionBinding > functions_; 48 | std::vector< AttributeBinding > attributes_; 49 | 50 | void sendMessageException(CefRefPtr browser, std::string messageId, Exception exception, std::wstring message); 51 | 52 | // NOTE: Must be at bottom 53 | public: 54 | IMPLEMENT_REFCOUNTING( ObjectBinding ) 55 | }; 56 | 57 | } 58 | } 59 | 60 | #endif /* OBJECTBINDING_H_ */ 61 | -------------------------------------------------------------------------------- /cef_client/src/AttributeBinding.cpp: -------------------------------------------------------------------------------- 1 | #include "AttributeBinding.hpp" 2 | 3 | namespace glr 4 | { 5 | namespace cef_client 6 | { 7 | 8 | AttributeBinding::AttributeBinding(std::wstring name) : name_(name) 9 | { 10 | } 11 | 12 | AttributeBinding::AttributeBinding(std::wstring name, std::wstring valueWstring) : name_(name), valueWstring_(valueWstring), isWstring_(true) 13 | { 14 | } 15 | 16 | AttributeBinding::AttributeBinding(std::wstring name, std::string valueString) : name_(name), valueString_(valueString), isString_(true) 17 | { 18 | } 19 | 20 | AttributeBinding::AttributeBinding(std::wstring name, int valueInt) : name_(name), valueInt_(valueInt), isInt_(true) 21 | { 22 | } 23 | 24 | AttributeBinding::AttributeBinding(std::wstring name, unsigned int valueUint) : name_(name), valueUint_(valueUint), isUint_(true) 25 | { 26 | } 27 | 28 | AttributeBinding::AttributeBinding(std::wstring name, bool valueBool) : name_(name), valueBool_(valueBool), isBool_(true) 29 | { 30 | } 31 | 32 | AttributeBinding::AttributeBinding(std::wstring name, float valueFloat) : name_(name), valueFloat_(valueFloat), isFloat_(true) 33 | { 34 | } 35 | 36 | AttributeBinding::AttributeBinding(std::wstring name, double valueDouble) : name_(name), valueDouble_(valueDouble), isDouble_(true) 37 | { 38 | } 39 | 40 | AttributeBinding::AttributeBinding(std::wstring name, CefRefPtr valueV8) : name_(name), valueV8_(valueV8), isV8_(true) 41 | { 42 | } 43 | 44 | AttributeBinding::~AttributeBinding() 45 | { 46 | } 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /cef_client/src/DuplicateAttributeException.cpp: -------------------------------------------------------------------------------- 1 | #include "DuplicateAttributeException.hpp" 2 | 3 | namespace glr 4 | { 5 | namespace cef_client 6 | { 7 | 8 | DuplicateAttributeException::DuplicateAttributeException(std::wstring attrName) : std::runtime_error("Attribute with name already exists.") 9 | { 10 | } 11 | 12 | DuplicateAttributeException::~DuplicateAttributeException() throw() 13 | { 14 | } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /cef_client/src/DuplicateFunctionException.cpp: -------------------------------------------------------------------------------- 1 | #include "DuplicateFunctionException.hpp" 2 | 3 | namespace glr 4 | { 5 | namespace cef_client 6 | { 7 | 8 | DuplicateFunctionException::DuplicateFunctionException(std::wstring funcName) : std::runtime_error("Function with name already exists.") 9 | { 10 | } 11 | 12 | DuplicateFunctionException::~DuplicateFunctionException() throw() 13 | { 14 | } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /cef_client/src/FunctionBinding.cpp: -------------------------------------------------------------------------------- 1 | #include "FunctionBinding.hpp" 2 | 3 | namespace glr 4 | { 5 | namespace cef_client 6 | { 7 | 8 | FunctionBinding::FunctionBinding(std::wstring name) : name_(name) 9 | { 10 | } 11 | 12 | FunctionBinding::~FunctionBinding() 13 | { 14 | } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /cef_client/src/Main.cpp: -------------------------------------------------------------------------------- 1 | #include "ClientApp.hpp" 2 | 3 | int main(int argc, char *argv[]) 4 | { 5 | #ifdef _WIN32 6 | CefMainArgs args(nullptr); 7 | #else 8 | CefMainArgs args(argc, argv); 9 | #endif 10 | CefRefPtr app = new glr::cef_client::ClientApp(); 11 | return CefExecuteProcess(args, app.get(), nullptr); 12 | } 13 | -------------------------------------------------------------------------------- /data/shaders/glr.glsl: -------------------------------------------------------------------------------- 1 | #type na 2 | #name glr 3 | 4 | uniform mat4 projectionMatrix; 5 | uniform mat4 viewMatrix; 6 | uniform mat4 modelMatrix; 7 | uniform mat4 pvmMatrix; 8 | uniform mat3 normalMatrix; 9 | -------------------------------------------------------------------------------- /data/shaders/glr_basic.program: -------------------------------------------------------------------------------- 1 | #name glr_basic 2 | #type program 3 | 4 | #include "shader.vert" 5 | #include "shader.frag" 6 | -------------------------------------------------------------------------------- /data/shaders/glr_gui.frag: -------------------------------------------------------------------------------- 1 | #version 150 core 2 | 3 | #extension GL_EXT_texture_array : enable 4 | 5 | #type fragment 6 | 7 | in vec2 textureCoord; 8 | in vec3 normalDirection; 9 | 10 | @bind Texture2D 11 | uniform sampler2D tex2D; 12 | 13 | void main() 14 | { 15 | 16 | gl_FragColor = texture2D(tex2D, textureCoord); 17 | 18 | /* 19 | float bug = 0.0; 20 | bvec4 result = equal( materials[0].diffuse, vec4(0.0, 0.0, 0.0, 0.0) ); 21 | if(result[0] && result[1] && result[2]) bug = 1.0; 22 | gl_FragColor.x += bug; 23 | */ 24 | } 25 | -------------------------------------------------------------------------------- /data/shaders/glr_gui.program: -------------------------------------------------------------------------------- 1 | #name glr_gui 2 | #type program 3 | 4 | #include "glr_gui.vert" 5 | #include "glr_gui.frag" 6 | -------------------------------------------------------------------------------- /data/shaders/glr_gui.vert: -------------------------------------------------------------------------------- 1 | #version 150 core 2 | 3 | #type vertex 4 | 5 | #include 6 | 7 | in vec3 in_Position; 8 | in vec2 in_Texture; 9 | in vec3 in_Normal; 10 | 11 | out vec2 textureCoord; 12 | out vec3 normalDirection; 13 | out vec3 lightDirection; 14 | 15 | void main() 16 | { 17 | gl_Position = pvmMatrix * vec4(in_Position, 1.0); 18 | 19 | textureCoord = in_Texture; 20 | 21 | normalDirection = normalize(normalMatrix * in_Normal); 22 | 23 | /* 24 | float bug = 0.0; 25 | bvec3 result = equal( diffuseReflection, vec3(0.0, 0.0, 0.0) ); 26 | if(result[0] && result[1] && result[2]) bug = 1.0; 27 | diffuseReflection.x += bug; 28 | */ 29 | } 30 | -------------------------------------------------------------------------------- /data/shaders/light.glsl: -------------------------------------------------------------------------------- 1 | #type na 2 | #name light 3 | 4 | struct Light 5 | { 6 | vec4 ambient; 7 | vec4 diffuse; 8 | vec4 specular; 9 | vec4 position; 10 | vec4 direction; 11 | }; 12 | -------------------------------------------------------------------------------- /data/shaders/material.glsl: -------------------------------------------------------------------------------- 1 | #type na 2 | #name material 3 | 4 | struct Material 5 | { 6 | vec4 ambient; 7 | vec4 diffuse; 8 | vec4 specular; 9 | vec4 emission; 10 | //float shininess; 11 | //float strength; 12 | }; 13 | -------------------------------------------------------------------------------- /data/shaders/mesh_only.frag: -------------------------------------------------------------------------------- 1 | #version 150 core 2 | 3 | #type fragment 4 | 5 | in vec4 color; 6 | 7 | void main() 8 | { 9 | gl_FragColor = vec4(0.5, 0.5, 0.5, 1.0); //color; 10 | } 11 | -------------------------------------------------------------------------------- /data/shaders/mesh_only.program: -------------------------------------------------------------------------------- 1 | #name mesh_only 2 | #type program 3 | 4 | #include "mesh_only.vert" 5 | #include "mesh_only.frag" 6 | -------------------------------------------------------------------------------- /data/shaders/mesh_only.vert: -------------------------------------------------------------------------------- 1 | #version 150 core 2 | 3 | #type vertex 4 | 5 | #include 6 | 7 | in vec3 in_Position; 8 | in vec2 in_Texture; 9 | in vec4 in_Color; 10 | in vec3 in_Normal; 11 | 12 | out vec4 color; 13 | 14 | void main() 15 | { 16 | gl_Position = pvmMatrix * vec4(in_Position, 1.0); 17 | 18 | color = in_Color; 19 | } 20 | -------------------------------------------------------------------------------- /data/shaders/shader.frag: -------------------------------------------------------------------------------- 1 | #version 150 core 2 | 3 | #extension GL_EXT_texture_array : enable 4 | 5 | #ifndef NUM_MATERIALS 6 | #define NUM_MATERIALS 1 7 | #endif 8 | 9 | #type fragment 10 | 11 | #include 12 | 13 | in vec2 textureCoord; 14 | in vec3 normalDirection; 15 | in vec3 lightDirection; 16 | in vec4 color; 17 | in float bug; 18 | 19 | @bind Texture2D 20 | uniform sampler2D tex2D; 21 | 22 | //@bind Texture2DArray 23 | //uniform sampler2DArray tex2DArray; 24 | 25 | @bind Material 26 | layout(std140) uniform Materials 27 | { 28 | Material materials[ NUM_MATERIALS ]; 29 | }; 30 | 31 | 32 | void main() 33 | { 34 | vec3 ct, cf; 35 | vec4 texel; 36 | float intensity, at, af; 37 | intensity = max( dot(lightDirection, normalize(normalDirection)), 0.0 ); 38 | 39 | cf = intensity * (materials[0].diffuse).rgb + materials[0].ambient.rgb; 40 | af = materials[0].diffuse.a; 41 | //texel = texture2DArray(tex2DArray, vec3(textureCoord, 1)); 42 | texel = texture2D(tex2D, textureCoord); 43 | 44 | ct = texel.rgb; 45 | at = texel.a; 46 | 47 | gl_FragColor = vec4(ct * cf, at * af); 48 | 49 | 50 | 51 | // Show bugs 52 | if (bug != 0.0) 53 | { 54 | if (bug == 1.0) 55 | gl_FragColor.x += bug; 56 | else if (bug == 2.0) 57 | gl_FragColor.y += bug; 58 | } 59 | 60 | /* 61 | float bug = 0.0; 62 | bvec4 result = equal( materials[0].diffuse, vec4(0.0, 0.0, 0.0, 0.0) ); 63 | if(result[0] && result[1] && result[2]) bug = 1.0; 64 | gl_FragColor.x += bug; 65 | */ 66 | } 67 | -------------------------------------------------------------------------------- /data/shaders/shader.vert: -------------------------------------------------------------------------------- 1 | #version 150 core 2 | 3 | #ifndef NUM_LIGHTS 4 | #define NUM_LIGHTS 1 5 | #endif 6 | 7 | #ifndef MAX_BONES 8 | #define MAX_BONES 100 9 | #endif 10 | 11 | #type vertex 12 | 13 | #include 14 | #include 15 | 16 | in vec3 in_Position; 17 | in vec2 in_Texture; 18 | in vec4 in_Color; 19 | in vec3 in_Normal; 20 | in ivec4 in_BoneIds; 21 | in vec4 in_BoneWeights; 22 | 23 | out vec2 textureCoord; 24 | out vec3 normalDirection; 25 | out vec3 lightDirection; 26 | out vec4 color; 27 | out float bug; 28 | 29 | @bind Light 30 | layout(std140) uniform Lights 31 | { 32 | Light lights[ NUM_LIGHTS ]; 33 | }; 34 | 35 | @bind Bone 36 | layout(std140) uniform Bones 37 | { 38 | mat4 bones[ MAX_BONES ]; 39 | }; 40 | 41 | void main() 42 | { 43 | // Calculate the transformation on the vertex position based on the bone weightings 44 | mat4 boneTransform = bones[ in_BoneIds[0] ] * in_BoneWeights[0]; 45 | boneTransform += bones[ in_BoneIds[1] ] * in_BoneWeights[1]; 46 | boneTransform += bones[ in_BoneIds[2] ] * in_BoneWeights[2]; 47 | boneTransform += bones[ in_BoneIds[3] ] * in_BoneWeights[3]; 48 | 49 | // Temporary - this will cease all animation (and show just the model) - this works if you want to just show the model 50 | //mat4 tempM = mat4(1.0); 51 | //boneTransform = tempM; 52 | 53 | // This is for animating the model 54 | vec4 tempPosition = boneTransform * vec4(in_Position, 1.0); 55 | gl_Position = pvmMatrix * tempPosition; 56 | 57 | // Assign texture coordinates 58 | textureCoord = in_Texture; 59 | 60 | // Calculate normal 61 | vec4 normalDirTemp = boneTransform * vec4(in_Normal, 0.0); 62 | normalDirection = normalize(normalMatrix * normalDirTemp.xyz); 63 | //normalDirection = normalize(normalMatrix * in_Normal); 64 | 65 | // Calculate light direction 66 | vec4 lightDirTemp = viewMatrix * lights[0].direction; 67 | lightDirection = normalize(vec3(lightDirTemp)); 68 | 69 | color = in_Color; 70 | 71 | 72 | // If we have any bugs, should highlight the vertex red or green 73 | bug = 0.0; 74 | float sum = in_BoneWeights[0] + in_BoneWeights[1] + in_BoneWeights[2] + in_BoneWeights[3]; 75 | if (sum > 1.05f) 76 | bug = 1.0; 77 | else if (sum < 0.95f) 78 | bug = 2.0; 79 | //else if (in_BoneIds[0] > 32 || in_BoneIds[1] > 32 || in_BoneIds[2] > 32 || in_BoneIds[3] > 32) 80 | // bug = 3.0; 81 | // disable bug highlighting 82 | //bug = 0.0; 83 | 84 | 85 | 86 | /* 87 | bvec4 result = equal( in_BoneIds, ivec4(0, 0, 0, 0) ); 88 | if(result[0] && result[1] && result[2] && result[3]) 89 | bug = 1.0; 90 | result = equal( in_BoneWeights, vec4(0.0, 0.0, 0.0, 0.0) ); 91 | if(result[0] && result[1] && result[2] && result[3]) 92 | bug = 2.0; 93 | */ 94 | 95 | } 96 | -------------------------------------------------------------------------------- /data/shaders/sky_box.frag: -------------------------------------------------------------------------------- 1 | #version 150 core 2 | 3 | #extension GL_EXT_texture_array : enable 4 | 5 | #ifndef NUM_MATERIALS 6 | #define NUM_MATERIALS 1 7 | #endif 8 | 9 | #type fragment 10 | 11 | #include 12 | 13 | in vec2 textureCoord; 14 | in vec4 color; 15 | 16 | @bind Texture2D 17 | uniform sampler2D tex2D; 18 | 19 | @bind Material 20 | layout(std140) uniform Materials 21 | { 22 | Material materials[ NUM_MATERIALS ]; 23 | }; 24 | 25 | 26 | void main() 27 | { 28 | vec3 ct, cf; 29 | vec4 texel; 30 | float at, af; 31 | 32 | cf = (materials[0].diffuse).rgb + materials[0].ambient.rgb; 33 | af = materials[0].diffuse.a; 34 | texel = texture2D(tex2D, textureCoord); 35 | 36 | ct = texel.rgb; 37 | at = texel.a; 38 | 39 | gl_FragColor = vec4(ct * cf, at * af); 40 | } 41 | -------------------------------------------------------------------------------- /data/shaders/sky_box.program: -------------------------------------------------------------------------------- 1 | #name sky_box 2 | #type program 3 | 4 | #include "sky_box.vert" 5 | #include "sky_box.frag" 6 | -------------------------------------------------------------------------------- /data/shaders/sky_box.vert: -------------------------------------------------------------------------------- 1 | #version 150 core 2 | 3 | #type vertex 4 | 5 | #include 6 | 7 | in vec3 in_Position; 8 | in vec2 in_Texture; 9 | in vec4 in_Color; 10 | in vec3 in_Normal; 11 | 12 | out vec2 textureCoord; 13 | out vec4 color; 14 | 15 | void main() 16 | { 17 | gl_Position = pvmMatrix * vec4(in_Position, 1.0); 18 | 19 | // Assign texture coordinates 20 | textureCoord = in_Texture; 21 | 22 | color = in_Color; 23 | } 24 | -------------------------------------------------------------------------------- /data/shaders/test.frag: -------------------------------------------------------------------------------- 1 | #version 150 core 2 | 3 | #type fragment 4 | 5 | in vec2 textureCoord; 6 | in vec3 normalDirection; 7 | in vec3 lightDirection; 8 | in vec4 color; 9 | in float bug; 10 | 11 | void main() { 12 | gl_FragColor = color; 13 | } 14 | -------------------------------------------------------------------------------- /data/shaders/test.program: -------------------------------------------------------------------------------- 1 | #name test 2 | #type program 3 | 4 | #include "shader.vert" 5 | #include "test.frag" 6 | -------------------------------------------------------------------------------- /data/shaders/voxel.program: -------------------------------------------------------------------------------- 1 | #name voxel 2 | #type program 3 | 4 | #include "voxel.vert" 5 | #include "voxel.frag" 6 | -------------------------------------------------------------------------------- /data/shaders/voxel.vert: -------------------------------------------------------------------------------- 1 | #version 150 core 2 | 3 | #ifndef NUM_LIGHTS 4 | #define NUM_LIGHTS 1 5 | #endif 6 | 7 | #type vertex 8 | 9 | #include 10 | #include 11 | 12 | in vec3 in_Position; 13 | in vec2 in_Texture; 14 | in vec4 in_Color; 15 | in vec3 in_Normal; 16 | @location 6 17 | in vec4 in_texBlend; 18 | 19 | out vec2 textureCoord; 20 | out vec3 normal; 21 | out vec3 terrainTextureNormal; 22 | out vec3 lightDirection; 23 | out vec3 position; 24 | out vec4 color; 25 | out vec4 texBlend; 26 | 27 | @bind Light 28 | layout(std140) uniform Lights 29 | { 30 | Light lights[ NUM_LIGHTS ]; 31 | }; 32 | 33 | void main() 34 | { 35 | gl_Position = pvmMatrix * vec4(in_Position, 1.0); 36 | 37 | // Assign texture coordinates 38 | textureCoord = in_Texture; 39 | 40 | // Calculate normal 41 | terrainTextureNormal = in_Normal; 42 | normal = normalize(normalMatrix * in_Normal); 43 | 44 | // Calculate light direction 45 | vec4 lightDirTemp = viewMatrix * lights[0].direction; 46 | lightDirection = normalize(vec3(lightDirTemp)); 47 | 48 | color = in_Color; 49 | position = in_Position; 50 | texBlend = in_texBlend; 51 | } 52 | -------------------------------------------------------------------------------- /docs/doxy-boot.js: -------------------------------------------------------------------------------- 1 | $( document ).ready(function() { 2 | $("div.headertitle").addClass("page-header"); 3 | $("div.title").addClass("h1"); 4 | 5 | $('li > a[href="index.html"] > span').before(" "); 6 | $('li > a[href="index.html"] > span').text("IceBreakers Entertainment"); 7 | $('li > a[href="modules.html"] > span').before(" "); 8 | $('li > a[href="namespaces.html"] > span').before(" "); 9 | $('li > a[href="annotated.html"] > span').before(" "); 10 | $('li > a[href="classes.html"] > span').before(" "); 11 | $('li > a[href="inherits.html"] > span').before(" "); 12 | $('li > a[href="functions.html"] > span').before(" "); 13 | $('li > a[href="functions_func.html"] > span').before(" "); 14 | $('li > a[href="functions_vars.html"] > span').before(" "); 15 | $('li > a[href="functions_enum.html"] > span').before(" "); 16 | $('li > a[href="functions_eval.html"] > span').before(" "); 17 | $('img[src="ftv2ns.png"]').replaceWith('N '); 18 | $('img[src="ftv2cl.png"]').replaceWith('C '); 19 | 20 | $("ul.tablist").addClass("nav nav-pills nav-justified"); 21 | $("ul.tablist").css("margin-top", "0.5em"); 22 | $("ul.tablist").css("margin-bottom", "0.5em"); 23 | $("li.current").addClass("active"); 24 | $("iframe").attr("scrolling", "yes"); 25 | 26 | $("#nav-path > ul").addClass("breadcrumb"); 27 | 28 | $("table.params").addClass("table"); 29 | $("div.ingroups").wrapInner(""); 30 | $("div.levels").css("margin", "0.5em"); 31 | $("div.levels > span").addClass("btn btn-default btn-xs"); 32 | $("div.levels > span").css("margin-right", "0.25em"); 33 | 34 | $("table.directory").addClass("table table-striped"); 35 | $("div.summary > a").addClass("btn btn-default btn-xs"); 36 | $("table.fieldtable").addClass("table"); 37 | $(".fragment").addClass("well"); 38 | $(".memitem").addClass("panel panel-default"); 39 | $(".memproto").addClass("panel-heading"); 40 | $(".memdoc").addClass("panel-body"); 41 | $("span.mlabel").addClass("label label-info"); 42 | 43 | $("table.memberdecls").addClass("table"); 44 | $("[class^=memitem]").addClass("active"); 45 | 46 | $("div.ah").addClass("btn btn-default"); 47 | $("span.mlabels").addClass("pull-right"); 48 | $("table.mlabels").css("width", "100%") 49 | $("td.mlabels-right").addClass("pull-right"); 50 | 51 | $("div.ttc").addClass("panel panel-info"); 52 | $("div.ttname").addClass("panel-heading"); 53 | $("div.ttdef,div.ttdoc,div.ttdeci").addClass("panel-body"); 54 | }); 55 | -------------------------------------------------------------------------------- /docs/doxygen_generate.sh: -------------------------------------------------------------------------------- 1 | doxygen glrdox 2 | 3 | mkdir dox/html/static 4 | mkdir dox/html/static/css 5 | mkdir dox/html/static/js 6 | 7 | cp bootstrap.min.css dox/html/static/css/ 8 | cp customdoxygen.css dox/html/static/css/ 9 | cp bootstrap.min.js dox/html/static/js/ 10 | cp jquery-1.11.0.min.js dox/html/static/js/ 11 | cp doxy-boot.js dox/html/static/js/ 12 | -------------------------------------------------------------------------------- /docs/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /docs/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | $projectname: $title 7 | $title 8 | 9 | 10 | 11 | 12 | $treeview 13 | $search 14 | $mathjax 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /extras/FpsCamera.cpp: -------------------------------------------------------------------------------- 1 | #include "FpsCamera.hpp" 2 | 3 | namespace glr 4 | { 5 | namespace extras 6 | { 7 | 8 | FpsCamera::FpsCamera(ICamera* camera, glmd::float32 speed) : camera_(camera), speed_(speed) 9 | { 10 | initialize(); 11 | } 12 | 13 | FpsCamera::~FpsCamera() 14 | { 15 | } 16 | 17 | void FpsCamera::initialize() 18 | { 19 | } 20 | 21 | bool FpsCamera::isActive() 22 | { 23 | return true; 24 | } 25 | 26 | void FpsCamera::moveForward() 27 | { 28 | camera_->move( glm::vec3(0.0f, 0.0f, -speed_) ); 29 | } 30 | 31 | void FpsCamera::moveBack() 32 | { 33 | camera_->move( glm::vec3(0.0f, 0.0f, speed_) ); 34 | } 35 | 36 | void FpsCamera::moveLeft() 37 | { 38 | camera_->move( glm::vec3(-speed_, 0.0f, 0.0f) ); 39 | } 40 | 41 | void FpsCamera::moveRight() 42 | { 43 | camera_->move( glm::vec3(speed_, 0.0f, 0.0f) ); 44 | } 45 | 46 | ICamera* FpsCamera::getCamera() 47 | { 48 | return camera_; 49 | } 50 | 51 | void FpsCamera::rotate(const glm::detail::float32& degrees, const glm::vec3& axis) 52 | { 53 | if ( axis == glm::vec3(0.0f, 1.0f, 0.0f) ) 54 | camera_->rotate(degrees, axis, ISceneNode::TransformSpace::TS_LOCAL); 55 | else 56 | camera_->rotate(degrees, axis, ISceneNode::TransformSpace::TS_WORLD); 57 | } 58 | 59 | void FpsCamera::tick(glm::detail::float32 time) 60 | { 61 | camera_->tick(time); 62 | } 63 | 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /extras/FpsCamera.hpp: -------------------------------------------------------------------------------- 1 | #ifndef FPSCAMERA_H_ 2 | #define FPSCAMERA_H_ 3 | 4 | #define GLM_FORCE_RADIANS 5 | #include "glm/glm.hpp" 6 | 7 | #include "GlrInclude.hpp" 8 | 9 | namespace glr 10 | { 11 | namespace extras 12 | { 13 | 14 | class FpsCamera 15 | { 16 | public: 17 | FpsCamera(ICamera* camera, glmd::float32 speed); 18 | virtual ~FpsCamera(); 19 | 20 | bool isActive(); 21 | 22 | void moveForward(); 23 | void moveBack(); 24 | void moveLeft(); 25 | void moveRight(); 26 | 27 | ICamera* getCamera(); 28 | 29 | void rotate(const glm::detail::float32& degrees, const glm::vec3& axis); 30 | 31 | /** 32 | * 33 | */ 34 | void tick(glmd::float32 time); 35 | 36 | private: 37 | ICamera* camera_; 38 | glmd::float32 speed_; 39 | 40 | void initialize(); 41 | }; 42 | 43 | } 44 | } 45 | 46 | #endif /* FPSCAMERA_H_ */ 47 | -------------------------------------------------------------------------------- /include/BasicSceneNode.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BASICSCENENODE_H_ 2 | #define BASICSCENENODE_H_ 3 | 4 | #include 5 | 6 | #include "ISceneNode.hpp" 7 | #include "glw/IOpenGlDevice.hpp" 8 | 9 | #include "glw/shaders/IShaderProgram.hpp" 10 | 11 | #include "ISceneManager.hpp" 12 | 13 | // Forward declaration (so we can set it as a friend class below) 14 | class BasicSceneManager; 15 | 16 | namespace glr 17 | { 18 | 19 | class BasicSceneNode : public virtual ISceneNode 20 | { 21 | public: 22 | BasicSceneNode(Id id, glw::IOpenGlDevice* openGlDevice); 23 | BasicSceneNode(Id id, std::string name, glw::IOpenGlDevice* openGlDevice); 24 | BasicSceneNode(Id id, std::string name, const glm::vec3& position, const glm::quat& orientation, const glm::vec3& scale, glw::IOpenGlDevice* openGlDevice); 25 | BasicSceneNode(Id id, const BasicSceneNode& other); 26 | virtual ~BasicSceneNode(); 27 | 28 | void copy(const BasicSceneNode& other); 29 | 30 | virtual const Id& getId() const; 31 | virtual void setName(std::string name); 32 | virtual const std::string& getName() const; 33 | 34 | virtual glm::vec3& getPosition(); 35 | virtual void setPosition(const glm::vec3& newPos); 36 | virtual void setPosition(glm::detail::float32 x, glm::detail::float32 y, glm::detail::float32 z); 37 | 38 | virtual glm::vec3& getScale(); 39 | virtual void setScale(const glm::vec3& scale); 40 | virtual void setScale(glm::detail::float32 x, glm::detail::float32 y, glm::detail::float32 z); 41 | 42 | virtual void translate(const glm::vec3& trans, TransformSpace relativeTo = TS_LOCAL); 43 | virtual void translate(glm::detail::float32 x, glm::detail::float32 y, glm::detail::float32 z, TransformSpace relativeTo = TS_LOCAL); 44 | 45 | virtual const glm::quat& getOrientation() const; 46 | virtual void rotate(const glm::detail::float32 degrees, const glm::vec3& axis, TransformSpace relativeTo = TS_LOCAL); 47 | virtual void rotate(const glm::quat& quaternion, TransformSpace relativeTo = TS_LOCAL); 48 | 49 | virtual void lookAt(const glm::vec3& lookAt); 50 | 51 | virtual void attach(models::IRenderable* renderable); 52 | virtual void attach(shaders::IShaderProgram* shaderProgram); 53 | virtual void detach(models::IRenderable* renderable); 54 | virtual models::IRenderable* getRenderable() const; 55 | virtual shaders::IShaderProgram* getShaderProgram() const; 56 | 57 | virtual void render(); 58 | 59 | protected: 60 | models::IRenderable* renderable_; 61 | shaders::IShaderProgram* shaderProgram_; 62 | 63 | ISceneManager* sceneManager_; 64 | 65 | Id id_; 66 | std::string name_; 67 | glm::vec3 pos_; 68 | glm::quat orientationQuaternion_; 69 | glm::vec3 scale_; 70 | glw::IOpenGlDevice* openGlDevice_; 71 | 72 | bool active_; 73 | 74 | private: 75 | // We don't copy straight up, since we need a new id for the copy 76 | BasicSceneNode(const BasicSceneNode& other); 77 | }; 78 | 79 | } 80 | 81 | #endif /* BASICSCENENODE_H_ */ 82 | -------------------------------------------------------------------------------- /include/Camera.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GLR_CAMERA_H_ 2 | #define GLR_CAMERA_H_ 3 | 4 | #include "ICamera.hpp" 5 | #include "BasicSceneNode.hpp" 6 | 7 | namespace glr 8 | { 9 | 10 | class Camera : public virtual ICamera, public BasicSceneNode 11 | { 12 | public: 13 | Camera(Id id, glw::IOpenGlDevice* openGlDevice); 14 | virtual ~Camera(); 15 | 16 | // inherited from ICamera 17 | virtual bool isActive() const; 18 | 19 | virtual void render(); 20 | 21 | virtual void attach(models::IModel* model); 22 | 23 | virtual void move(const glm::vec3& moveVector); 24 | 25 | virtual void tick(glm::detail::float32 time); 26 | 27 | virtual const glm::mat4& getViewMatrix() const; 28 | 29 | private: 30 | glm::detail::int32 prevX_; 31 | glm::detail::int32 prevY_; 32 | 33 | glm::mat4 viewMatrix_; 34 | glm::vec3 direction_; 35 | 36 | glm::vec3 movementBuffer_; 37 | glm::detail::float32 moveSpeed_; 38 | glm::detail::float32 rotSpeed_; 39 | void clearMovementBuffer(); 40 | glm::detail::float32 xRot_; 41 | glm::detail::float32 yRot_; 42 | 43 | void initialize(); 44 | }; 45 | 46 | } 47 | 48 | #endif /* GLR_CAMERA_H_ */ 49 | -------------------------------------------------------------------------------- /include/Configure.hpp: -------------------------------------------------------------------------------- 1 | // we require a C++ compiler. 2 | #if !defined(__cplusplus) 3 | #error C++ compiler required. 4 | #endif 5 | 6 | #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(_WIN64) || defined(__WIN64__) || defined(WIN64) 7 | #define OS_WINDOWS 1 8 | #elif defined(linux) || defined(freebsd) || defined(__linux__) 9 | #define OS_LINUX 1 10 | #elif defined(__APPLE__) 11 | #define OS_MAC 1 12 | #endif 13 | 14 | 15 | #if !defined(OS_WINDOWS) && !defined(OS_LINUX) && !defined(OS_MAC) 16 | #error "OS NOT SUPPORTED"; 17 | #endif 18 | -------------------------------------------------------------------------------- /include/GlrInclude.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GLRINCLUDE_H_ 2 | #define GLRINCLUDE_H_ 3 | 4 | #if HAVE_CONFIG_H 5 | #include 6 | #endif 7 | 8 | #include "GlrProgram.hpp" 9 | #include "IWindow.hpp" 10 | #include "ISceneManager.hpp" 11 | #include "ISceneNode.hpp" 12 | #include "ICamera.hpp" 13 | #include "Id.hpp" 14 | 15 | #include "models/IModel.hpp" 16 | #include "models/IModelManager.hpp" 17 | 18 | #include "gui/IGui.hpp" 19 | #include "gui/IGuiComponent.hpp" 20 | 21 | #include "glw/IOpenGlDevice.hpp" 22 | 23 | #include "terrain/IFieldFunction.hpp" 24 | #include "terrain/ITerrainManager.hpp" 25 | #include "terrain/ITerrain.hpp" 26 | 27 | #include "exceptions/ExceptionInclude.hpp" 28 | 29 | #endif /* GLRINCLUDE_H_ */ 30 | 31 | -------------------------------------------------------------------------------- /include/GlrProgram.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GLRPROGRAM_H_ 2 | #define GLRPROGRAM_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include "Configure.hpp" 8 | 9 | #ifdef OS_WINDOWS 10 | #include 11 | #endif 12 | 13 | #include "ProgramSettings.hpp" 14 | 15 | #include "glw/IOpenGlDevice.hpp" 16 | #include "IWindow.hpp" 17 | #include "BasicSceneNode.hpp" 18 | #include "BasicSceneManager.hpp" 19 | #include "Light.hpp" 20 | 21 | #include "gui/IGui.hpp" 22 | 23 | 24 | #include "models/IModelManager.hpp" 25 | #include "models/IBillboardManager.hpp" 26 | 27 | #include "glw/shaders/IShaderProgramManager.hpp" 28 | #include "glw/shaders/IShaderProgramBindListener.hpp" 29 | 30 | namespace glr 31 | { 32 | 33 | /** 34 | * @mainpage Graphics Language Renderer Documentation 35 | * 36 | * @b Note: This documentation is for an alpha product, and is not necessarily representative of the final product. 37 | * 38 | */ 39 | 40 | /** 41 | * 42 | */ 43 | class GlrProgram : public shaders::IShaderProgramBindListener 44 | { 45 | public: 46 | GlrProgram(ProgramSettings properties = ProgramSettings()); 47 | virtual ~GlrProgram(); 48 | 49 | void beginRender(); 50 | void endRender(); 51 | virtual void render(); 52 | 53 | IWindow* createWindow(std::string name = std::string("Window"), std::string title = std::string("Untitled Window"), glm::detail::uint32 width = 800, glm::detail::uint32 height = 600, glm::detail::uint32 depth = 24, 54 | bool fullscreen = false, bool vsync = false); 55 | 56 | void setSceneManager(std::unique_ptr sceneManager); 57 | 58 | IWindow* getWindow(); 59 | ISceneManager* getSceneManager(); 60 | gui::IGui* getHtmlGui(); 61 | glw::IOpenGlDevice* getOpenGlDevice(); 62 | models::IModelManager* getModelManager() const; 63 | models::IBillboardManager* getBillboardManager() const; 64 | 65 | void reloadShaders(); 66 | 67 | /* Implementation of IShaderProgramBindListener method */ 68 | virtual void shaderBindCallback(shaders::IShaderProgram* shader); 69 | 70 | private: 71 | glm::detail::uint32 numLights_; 72 | std::map > lightUbos_; 73 | std::map > materialUbos_; 74 | 75 | // Should this be IOpenGlDevice instead of OpenGlDevice? 76 | std::unique_ptr< glw::IOpenGlDevice > openGlDevice_; 77 | std::unique_ptr< models::IModelManager > modelManager_; 78 | std::unique_ptr< models::IBillboardManager > billboardManager_; 79 | std::unique_ptr< ISceneManager > sMgr_; 80 | std::unique_ptr< IWindow > window_; 81 | std::unique_ptr< gui::IGui > gui_; 82 | 83 | shaders::IShaderProgramManager* shaderProgramManager_; 84 | 85 | ProgramSettings settings_; 86 | 87 | void setupUniformBufferObjectBindings(shaders::IShaderProgram* shader); 88 | void setupLightUbo(std::string name, shaders::IShaderProgram* shader); 89 | void releaseLightUbo(std::string name); 90 | void bindUniformBufferObjects(shaders::IShaderProgram* shader); 91 | 92 | void initialize(ProgramSettings settings); 93 | void initializeProperties(ProgramSettings settings); 94 | }; 95 | 96 | } 97 | 98 | #endif /* GLRPROGRAM_H_ */ 99 | -------------------------------------------------------------------------------- /include/ICamera.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ICAMERA_H_ 2 | #define ICAMERA_H_ 3 | 4 | #include "ISceneNode.hpp" 5 | 6 | namespace glr 7 | { 8 | 9 | class ICamera : public virtual ISceneNode 10 | { 11 | public: 12 | virtual ~ICamera() 13 | { 14 | } 15 | ; 16 | 17 | virtual bool isActive() const = 0; 18 | 19 | virtual void move(const glm::vec3& moveVector) = 0; 20 | 21 | virtual void tick(glm::detail::float32 time) = 0; 22 | 23 | virtual const glm::mat4& getViewMatrix() const = 0; 24 | }; 25 | 26 | } 27 | 28 | #endif /* ICAMERA_H_ */ 29 | -------------------------------------------------------------------------------- /include/ILight.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ILIGHT_H_ 2 | #define ILIGHT_H_ 3 | 4 | #include 5 | 6 | #include "ISceneNode.hpp" 7 | 8 | namespace glr 9 | { 10 | 11 | struct LightData 12 | { 13 | glm::vec4 ambient; 14 | glm::vec4 diffuse; 15 | glm::vec4 specular; 16 | glm::vec4 position; 17 | glm::vec4 direction; 18 | }; 19 | 20 | class ILight : public virtual ISceneNode 21 | { 22 | public: 23 | virtual ~ILight() 24 | { 25 | } 26 | ; 27 | 28 | virtual void setLightData(LightData data) = 0; 29 | // TODO: add 'set' methods for each piece of light data 30 | 31 | virtual const LightData& getLightData() const = 0; 32 | // TODO: add 'get' methods for each piece of light data 33 | }; 34 | 35 | } 36 | 37 | #endif /* ILIGHT_H_ */ 38 | -------------------------------------------------------------------------------- /include/ISceneManager.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ISCENEMANAGER_H_ 2 | #define ISCENEMANAGER_H_ 3 | 4 | #include "ISceneNode.hpp" 5 | #include "ICamera.hpp" 6 | #include "ILight.hpp" 7 | #include "environment/IEnvironmentManager.hpp" 8 | #include "models/IModelManager.hpp" 9 | #include "models/IBillboardManager.hpp" 10 | #include "terrain/ITerrainManager.hpp" 11 | #include "terrain/IFieldFunction.hpp" 12 | #include "terrain/TerrainSettings.hpp" 13 | #include "glw/shaders/IShaderProgramManager.hpp" 14 | 15 | namespace glr 16 | { 17 | 18 | namespace glmd = glm::detail; 19 | 20 | class ISceneManager 21 | { 22 | public: 23 | virtual ~ISceneManager() 24 | { 25 | } 26 | ; 27 | 28 | virtual ISceneNode* createSceneNode(const std::string& name = std::string()) = 0; 29 | virtual ICamera* createCamera(glm::detail::uint32 speed = 1, glm::detail::uint32 rotationSpeed = 5) = 0; 30 | virtual ILight* createLight(const std::string& name = std::string()) = 0; 31 | 32 | virtual void setCamera(std::unique_ptr camera) = 0; 33 | 34 | virtual ISceneNode* getSceneNode(Id id) const = 0; 35 | virtual ISceneNode* getSceneNode(const std::string& name) const = 0; 36 | virtual ICamera* getCamera() const = 0; 37 | virtual ILight* getLight(Id id) const = 0; 38 | virtual ILight* getLight(const std::string& name) const = 0; 39 | 40 | virtual void destroySceneNode(Id id) = 0; 41 | virtual void destroySceneNode(const std::string& name) = 0; 42 | virtual void destroySceneNode(ISceneNode* node) = 0; 43 | virtual void destroyAllSceneNodes() = 0; 44 | virtual void destroyCamera() = 0; 45 | virtual void destroyLight(Id id) = 0; 46 | virtual void destroyLight(const std::string& name) = 0; 47 | virtual void destroyLight(ILight* node) = 0; 48 | virtual void destroyAllLights() = 0; 49 | 50 | virtual glmd::uint32 getNumSceneNodes() const = 0; 51 | virtual glmd::uint32 getNumLights() const = 0; 52 | 53 | virtual void drawAll() = 0; 54 | 55 | virtual void setDefaultShaderProgram(shaders::IShaderProgram* shaderProgram) = 0; 56 | 57 | virtual const glm::mat4& getModelMatrix() const = 0; 58 | 59 | virtual env::IEnvironmentManager* getEnvironmentManager() = 0; 60 | // TODO: make this just a getter? 61 | virtual terrain::ITerrainManager* getTerrainManager(terrain::IFieldFunction* fieldFunction = nullptr, terrain::TerrainSettings terrainSettings = terrain::TerrainSettings()) = 0; 62 | virtual shaders::IShaderProgramManager* getShaderProgramManager() const = 0; 63 | 64 | virtual const std::vector& getLightData() = 0; 65 | }; 66 | 67 | } 68 | 69 | #endif /* ISCENEMANAGER_H_ */ 70 | -------------------------------------------------------------------------------- /include/ISceneNode.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ISCENENODE_H_ 2 | #define ISCENENODE_H_ 3 | 4 | #include 5 | 6 | #define GLM_FORCE_RADIANS 7 | #include 8 | #include "glm/gtc/quaternion.hpp" 9 | 10 | #include "models/IRenderable.hpp" 11 | 12 | #include "Id.hpp" 13 | 14 | namespace glr 15 | { 16 | 17 | class ISceneNode 18 | { 19 | public: 20 | virtual ~ISceneNode() 21 | { 22 | } 23 | ; 24 | 25 | enum TransformSpace 26 | { 27 | TS_LOCAL = 0, 28 | TS_WORLD 29 | }; 30 | 31 | virtual const Id& getId() const = 0; 32 | virtual void setName(std::string name) = 0; 33 | virtual const std::string& getName() const = 0; 34 | 35 | virtual glm::vec3& getPosition() = 0; 36 | virtual void setPosition(const glm::vec3& newPos) = 0; 37 | virtual void setPosition(glm::detail::float32 x, glm::detail::float32 y, glm::detail::float32 z) = 0; 38 | 39 | virtual glm::vec3& getScale() = 0; 40 | virtual void setScale(const glm::vec3& scale) = 0; 41 | virtual void setScale(glm::detail::float32 x, glm::detail::float32 y, glm::detail::float32 z) = 0; 42 | 43 | virtual void translate(const glm::vec3& trans, TransformSpace relativeTo = TS_LOCAL) = 0; 44 | virtual void translate(glm::detail::float32 x, glm::detail::float32 y, glm::detail::float32 z, TransformSpace relativeTo = TS_LOCAL) = 0; 45 | 46 | virtual const glm::quat& getOrientation() const = 0; 47 | /** 48 | * Rotates the scene node around the axis 'axis' the specified number of degrees. This rotation is relative to the transform space specified 49 | * by 'relativeTo'. 50 | */ 51 | virtual void rotate(const glm::detail::float32 degrees, const glm::vec3& axis, TransformSpace relativeTo = TS_LOCAL) = 0; 52 | virtual void rotate(const glm::quat& quaternion, TransformSpace relativeTo = TS_LOCAL) = 0; 53 | 54 | virtual void lookAt(const glm::vec3& lookAt) = 0; 55 | 56 | virtual void attach(models::IRenderable* renderable) = 0; 57 | virtual void attach(shaders::IShaderProgram* shaderProgram) = 0; 58 | virtual void detach(models::IRenderable* renderable) = 0; 59 | virtual models::IRenderable* getRenderable() const = 0; 60 | virtual shaders::IShaderProgram* getShaderProgram() const = 0; 61 | 62 | virtual void render() = 0; 63 | 64 | }; 65 | 66 | } 67 | 68 | #endif /* ISCENENODE_H_ */ 69 | -------------------------------------------------------------------------------- /include/IWindow.hpp: -------------------------------------------------------------------------------- 1 | #ifndef IWINDOW_H_ 2 | #define IWINDOW_H_ 3 | 4 | #include 5 | 6 | #include "IWindowResizeListener.hpp" 7 | 8 | #include "Configure.hpp" 9 | 10 | #ifdef OS_WINDOWS 11 | #include 12 | #endif 13 | 14 | #define GLM_FORCE_RADIANS 15 | #include 16 | 17 | namespace glr 18 | { 19 | 20 | class IWindow 21 | { 22 | public: 23 | virtual ~IWindow() 24 | { 25 | } 26 | ; 27 | 28 | #if defined(OS_LINUX) 29 | typedef unsigned long WindowHandle; 30 | #elif defined(OS_WINDOWS) 31 | typedef HWND* WindowHandle; 32 | #elif defined(OS_MAC) 33 | typedef void* WindowHandle; 34 | #endif 35 | 36 | typedef void* InternalWindow; 37 | 38 | virtual WindowHandle getWindowHandle() const = 0; 39 | virtual InternalWindow getInternalWindowPointer() const = 0; 40 | 41 | virtual void destroy() = 0; 42 | virtual void resize(glm::detail::uint32 width, glm::detail::uint32 height) = 0; 43 | virtual void handleEvents() = 0; 44 | virtual void render() = 0; 45 | 46 | virtual glm::detail::uint32 getWidth() const = 0; 47 | virtual glm::detail::uint32 getHeight() const = 0; 48 | virtual glm::vec2 getPosition() const = 0; 49 | virtual glm::detail::uint32 getDepth() const = 0; 50 | virtual const glm::mat4& getProjectionMatrix() const = 0; 51 | 52 | virtual void addWindowResizeListener(IWindowResizeListener* listener) = 0; 53 | virtual void removeWindowResizeListener(IWindowResizeListener* listener) = 0; 54 | }; 55 | 56 | } 57 | 58 | #endif /* IWINDOW_H_ */ 59 | -------------------------------------------------------------------------------- /include/IWindowResizeListener.hpp: -------------------------------------------------------------------------------- 1 | #ifndef IWINDOWRESIZELISTENER_H_ 2 | #define IWINDOWRESIZELISTENER_H_ 3 | 4 | #include 5 | 6 | #define GLM_FORCE_RADIANS 7 | #include 8 | 9 | namespace glr 10 | { 11 | 12 | class IWindowResizeListener 13 | { 14 | public: 15 | virtual ~IWindowResizeListener() 16 | { 17 | } 18 | ; 19 | 20 | virtual void windowSizeUpdate(glm::detail::uint32 width, glm::detail::uint32 height) = 0; 21 | }; 22 | 23 | } 24 | 25 | #endif /* IWINDOWRESIZELISTENER_H_ */ 26 | -------------------------------------------------------------------------------- /include/Id.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ID_H_ 2 | #define ID_H_ 3 | 4 | #include 5 | 6 | #include 7 | 8 | namespace glr 9 | { 10 | 11 | class Id 12 | { 13 | public: 14 | Id(); 15 | explicit Id(glm::detail::uint32 id); 16 | // We make the destructor non-virtual so that we can't extend this class easily 17 | ~Id(); 18 | 19 | glm::detail::uint32 getId() const; 20 | 21 | bool operator == (const Id &other) const; 22 | bool operator != (const Id &other) const; 23 | bool operator < (const Id &other) const; 24 | bool operator > (const Id &other) const; 25 | bool operator <= (const Id &other) const; 26 | bool operator >= (const Id &other) const; 27 | bool operator << (const Id &other) const; 28 | 29 | friend std::ostream& operator << (std::ostream& os, const Id& id); 30 | 31 | static const Id INVALID; 32 | 33 | private: 34 | glm::detail::uint32 id_; 35 | }; 36 | 37 | } 38 | 39 | #endif /* ID_H_ */ 40 | -------------------------------------------------------------------------------- /include/IdManager.hpp: -------------------------------------------------------------------------------- 1 | #ifndef IDMANAGER_H_ 2 | #define IDMANAGER_H_ 3 | 4 | #include "Id.hpp" 5 | 6 | namespace glr 7 | { 8 | 9 | class IdManager 10 | { 11 | public: 12 | IdManager(); 13 | virtual ~IdManager(); 14 | 15 | Id createId(); 16 | 17 | private: 18 | glm::detail::uint32 currentId_; 19 | }; 20 | 21 | } 22 | 23 | #endif /* IDMANAGER_H_ */ 24 | -------------------------------------------------------------------------------- /include/Light.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LIGHT_H_ 2 | #define LIGHT_H_ 3 | 4 | #include "ILight.hpp" 5 | #include "BasicSceneNode.hpp" 6 | 7 | namespace glr 8 | { 9 | 10 | class Light : public virtual ILight, public BasicSceneNode 11 | { 12 | public: 13 | Light(Id id, glw::IOpenGlDevice* openGlDevice); 14 | Light(Id id, std::string name, glw::IOpenGlDevice* openGlDevice); 15 | virtual ~Light(); 16 | 17 | // inherited from ILight 18 | virtual void render(); 19 | 20 | virtual void attach(models::IModel* model); 21 | 22 | virtual void setLightData(LightData data); 23 | 24 | virtual const LightData& getLightData() const; 25 | 26 | private: 27 | LightData lightData_; 28 | 29 | void initialize(); 30 | }; 31 | 32 | } 33 | 34 | #endif /* LIGHT_H_ */ 35 | -------------------------------------------------------------------------------- /include/ProgramSettings.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PROGRAMSETTINGS_H_ 2 | #define PROGRAMSETTINGS_H_ 3 | 4 | #include 5 | 6 | namespace glr 7 | { 8 | 9 | /** 10 | * Used to pass in GlrProgram settings (so we don't have to have a method with a whole ton of parameters). 11 | */ 12 | struct ProgramSettings 13 | { 14 | ProgramSettings() : defaultTextureDir("") 15 | { 16 | } 17 | 18 | std::string defaultTextureDir; 19 | }; 20 | 21 | } 22 | 23 | #endif /* PROGRAMSETTINGS_H_ */ 24 | -------------------------------------------------------------------------------- /include/Window.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GLWINDOW_H_ 2 | #define GLWINDOW_H_ 3 | 4 | #include 5 | 6 | #include 7 | 8 | #include "IWindow.hpp" 9 | 10 | namespace glr 11 | { 12 | 13 | namespace glmd = glm::detail; 14 | 15 | class Window : public IWindow 16 | { 17 | public: 18 | Window(glm::detail::int32 width, glm::detail::int32 height, std::string title); 19 | virtual ~Window(); 20 | 21 | virtual WindowHandle getWindowHandle() const; 22 | virtual IWindow::InternalWindow getInternalWindowPointer() const; 23 | 24 | virtual void resize(glm::detail::uint32 width, glm::detail::uint32 height); 25 | virtual void destroy(); 26 | virtual void render(); 27 | virtual void handleEvents(); 28 | 29 | virtual glm::detail::uint32 getWidth() const; 30 | virtual glm::detail::uint32 getHeight() const; 31 | virtual glm::vec2 getPosition() const; 32 | virtual glm::detail::uint32 getDepth() const; 33 | virtual const glm::mat4& getProjectionMatrix() const; 34 | 35 | virtual void addWindowResizeListener(IWindowResizeListener* listener); 36 | virtual void removeWindowResizeListener(IWindowResizeListener* listener); 37 | 38 | private: 39 | glmd::int32 x_; 40 | glmd::int32 y_; 41 | glmd::uint32 width_; 42 | glmd::uint32 height_; 43 | glmd::uint32 depth_; 44 | 45 | std::unique_ptr window_; 46 | 47 | glm::mat4 projectionMatrix_; 48 | 49 | std::vector< IWindowResizeListener* > windowResizeListeners_; 50 | 51 | void initialize(); 52 | }; 53 | 54 | } 55 | 56 | #endif /* GLWINDOW_H_ */ 57 | -------------------------------------------------------------------------------- /include/environment/EnvironmentManager.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ENVIRONMENTMANAGER_H_ 2 | #define ENVIRONMENTMANAGER_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include "IdManager.hpp" 8 | 9 | #include "glw/IOpenGlDevice.hpp" 10 | #include "models/IModelManager.hpp" 11 | 12 | #include "environment/IEnvironmentManager.hpp" 13 | #include "environment/SkyBox.hpp" 14 | 15 | namespace glr 16 | { 17 | namespace env 18 | { 19 | 20 | class EnvironmentManager : public IEnvironmentManager 21 | { 22 | public: 23 | EnvironmentManager(glw::IOpenGlDevice* openGlDevice, models::IModelManager* modelManager); 24 | virtual ~EnvironmentManager(); 25 | 26 | virtual ISky* createSkyBox(); 27 | virtual ISky* getSkyBox(Id id); 28 | virtual ISky* getSkyBox(const std::string& name); 29 | 30 | virtual void destroySkyBox(Id id); 31 | virtual void destroySkyBox(const std::string& name); 32 | virtual void destroySkyBox(ISky* skybox); 33 | 34 | virtual void render(); 35 | 36 | virtual void setFollowTarget(ISceneNode* target); 37 | 38 | private: 39 | glw::IOpenGlDevice* openGlDevice_; 40 | models::IModelManager* modelManager_; 41 | ISceneNode* followTarget_; 42 | 43 | IdManager idManager_; 44 | 45 | std::vector< std::unique_ptr > skyBoxes_; 46 | }; 47 | 48 | } 49 | } 50 | 51 | #endif /* ENVIRONMENTMANAGER_H_ */ 52 | -------------------------------------------------------------------------------- /include/environment/IEnvironmentManager.hpp: -------------------------------------------------------------------------------- 1 | #ifndef IENVIRONMENTMANAGER_H_ 2 | #define IENVIRONMENTMANAGER_H_ 3 | 4 | #include 5 | 6 | #include "ISceneNode.hpp" 7 | #include "environment/ISky.hpp" 8 | 9 | namespace glr 10 | { 11 | namespace env 12 | { 13 | 14 | class IEnvironmentManager 15 | { 16 | public: 17 | virtual ~IEnvironmentManager() 18 | { 19 | } 20 | ; 21 | 22 | virtual ISky* createSkyBox() = 0; 23 | virtual ISky* getSkyBox(Id id) = 0; 24 | virtual ISky* getSkyBox(const std::string& name) = 0; 25 | virtual void destroySkyBox(Id id) = 0; 26 | virtual void destroySkyBox(const std::string& name) = 0; 27 | virtual void destroySkyBox(ISky* skybox) = 0; 28 | 29 | virtual void render() = 0; 30 | 31 | virtual void setFollowTarget(ISceneNode* target) = 0; 32 | }; 33 | 34 | } 35 | } 36 | 37 | #endif /* IENVIRONMENTMANAGER_H_ */ 38 | -------------------------------------------------------------------------------- /include/environment/ISky.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ISKY_H_ 2 | #define ISKY_H_ 3 | 4 | #define GLM_FORCE_RADIANS 5 | #include 6 | 7 | #include "ISceneNode.hpp" 8 | 9 | namespace glr 10 | { 11 | namespace env 12 | { 13 | 14 | class ISky : public virtual ISceneNode 15 | { 16 | public: 17 | virtual ~ISky() 18 | { 19 | } 20 | ; 21 | }; 22 | 23 | } 24 | } 25 | 26 | #endif /* ISKY_H_ */ 27 | -------------------------------------------------------------------------------- /include/environment/SkyBox.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SKYBOX_H_ 2 | #define SKYBOX_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define GLM_FORCE_RADIANS 9 | #include 10 | 11 | #include "BasicSceneNode.hpp" 12 | #include "environment/ISky.hpp" 13 | #include "environment/SkyBoxPlane.hpp" 14 | 15 | namespace glr 16 | { 17 | namespace env 18 | { 19 | 20 | class SkyBox : public virtual ISky, public BasicSceneNode 21 | { 22 | public: 23 | SkyBox(Id id, glw::IOpenGlDevice* openGlDevice, models::IModelManager* modelManager); 24 | SkyBox(Id id, std::string name, glw::IOpenGlDevice* openGlDevice, models::IModelManager* modelManager); 25 | virtual ~SkyBox(); 26 | 27 | virtual void render(); 28 | 29 | void move( const glm::vec3& movement ); 30 | 31 | private: 32 | void initialize(models::IModelManager* modelManager); 33 | 34 | std::vector< std::unique_ptr > sides_; 35 | std::vector< std::unique_ptr > models_; 36 | }; 37 | 38 | } 39 | } 40 | 41 | #endif /* SKYBOX_H_ */ 42 | -------------------------------------------------------------------------------- /include/environment/SkyBoxPlane.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SKYBOXPLANE_H_ 2 | #define SKYBOXPLANE_H_ 3 | 4 | #include 5 | #include 6 | 7 | #define GLM_FORCE_RADIANS 8 | #include 9 | 10 | #include "BasicSceneNode.hpp" 11 | 12 | namespace glr 13 | { 14 | namespace env 15 | { 16 | 17 | class SkyBoxPlane : public BasicSceneNode 18 | { 19 | public: 20 | SkyBoxPlane(Id id, std::string name, glw::IOpenGlDevice* openGlDevice); 21 | virtual ~SkyBoxPlane(); 22 | 23 | void move( const glm::vec3& movement ); 24 | 25 | virtual void setPosition(glm::vec3& newPos); 26 | virtual void setPosition(glm::detail::float32 x, glm::detail::float32 y, glm::detail::float32 z); 27 | 28 | virtual void translate(const glm::vec3& trans, TransformSpace relativeTo = TS_LOCAL); 29 | virtual void translate(glm::detail::float32 x, glm::detail::float32 y, glm::detail::float32 z, TransformSpace relativeTo = TS_LOCAL); 30 | 31 | private: 32 | glm::vec3 nodePos_; 33 | glm::vec3 cameraPos_; 34 | }; 35 | 36 | } 37 | } 38 | 39 | #endif /* SKYBOXPLANE_H_ */ 40 | -------------------------------------------------------------------------------- /include/exceptions/Exception.hpp: -------------------------------------------------------------------------------- 1 | #ifndef EXCEPTION_H_ 2 | #define EXCEPTION_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace glr 8 | { 9 | namespace exception 10 | { 11 | 12 | class Exception : public std::exception 13 | { 14 | public: 15 | Exception(const std::string& message = std::string("Glr Exception")); 16 | virtual ~Exception() throw(); 17 | 18 | virtual const char* what() const throw(); 19 | 20 | protected: 21 | std::string message_; 22 | }; 23 | 24 | } 25 | } 26 | 27 | #endif /* EXCEPTION_H_ */ 28 | -------------------------------------------------------------------------------- /include/exceptions/ExceptionInclude.hpp: -------------------------------------------------------------------------------- 1 | #ifndef EXCEPTIONINCLUDE_H_ 2 | #define EXCEPTIONINCLUDE_H_ 3 | 4 | #include "exceptions/Exception.hpp" 5 | #include "exceptions/LogicException.hpp" 6 | #include "exceptions/RuntimeException.hpp" 7 | #include "exceptions/FormatException.hpp" 8 | #include "exceptions/IoException.hpp" 9 | #include "exceptions/GlException.hpp" 10 | #include "exceptions/InvalidArgumentException.hpp" 11 | 12 | #endif /* EXCEPTIONINCLUDE_H_ */ 13 | -------------------------------------------------------------------------------- /include/exceptions/FormatException.hpp: -------------------------------------------------------------------------------- 1 | #ifndef FORMATEXCEPTION_H_ 2 | #define FORMATEXCEPTION_H_ 3 | 4 | #include "exceptions/Exception.hpp" 5 | 6 | namespace glr 7 | { 8 | namespace exception 9 | { 10 | 11 | class FormatException : public Exception 12 | { 13 | public: 14 | FormatException(const std::string& message = std::string("Glr FormatException")); 15 | virtual ~FormatException() throw(); 16 | }; 17 | 18 | } 19 | } 20 | 21 | #endif /* FORMATEXCEPTION_H_ */ 22 | -------------------------------------------------------------------------------- /include/exceptions/GlException.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GLEXCEPTION_H_ 2 | #define GLEXCEPTION_H_ 3 | 4 | #include "exceptions/Exception.hpp" 5 | 6 | namespace glr 7 | { 8 | namespace exception 9 | { 10 | 11 | class GlException : public Exception 12 | { 13 | public: 14 | GlException(const std::string& message = std::string("Glr GlException")); 15 | virtual ~GlException() throw(); 16 | }; 17 | 18 | } 19 | } 20 | 21 | #endif /* GLEXCEPTION_H_ */ 22 | -------------------------------------------------------------------------------- /include/exceptions/InvalidArgumentException.hpp: -------------------------------------------------------------------------------- 1 | #ifndef INVALIDARGUMENTEXCEPTION_H_ 2 | #define INVALIDARGUMENTEXCEPTION_H_ 3 | 4 | #include "exceptions/LogicException.hpp" 5 | 6 | namespace glr 7 | { 8 | namespace exception 9 | { 10 | 11 | class InvalidArgumentException : public LogicException 12 | { 13 | public: 14 | InvalidArgumentException(const std::string& message = std::string("Glr InvalidArgumentException")); 15 | virtual ~InvalidArgumentException() throw(); 16 | }; 17 | 18 | } 19 | } 20 | 21 | #endif /* INVALIDARGUMENTEXCEPTION_H_ */ 22 | -------------------------------------------------------------------------------- /include/exceptions/IoException.hpp: -------------------------------------------------------------------------------- 1 | #ifndef IOEXCEPTION_H_ 2 | #define IOEXCEPTION_H_ 3 | 4 | #include "exceptions/Exception.hpp" 5 | 6 | namespace glr 7 | { 8 | namespace exception 9 | { 10 | 11 | class IoException : public Exception 12 | { 13 | public: 14 | IoException(const std::string& message = std::string("Glr IoException")); 15 | virtual ~IoException() throw(); 16 | }; 17 | 18 | } 19 | } 20 | 21 | #endif /* IOEXCEPTION_H_ */ 22 | -------------------------------------------------------------------------------- /include/exceptions/LogicException.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LOGICEXCEPTION_H_ 2 | #define LOGICEXCEPTION_H_ 3 | 4 | #include 5 | 6 | namespace glr 7 | { 8 | namespace exception 9 | { 10 | 11 | class LogicException : public std::logic_error 12 | { 13 | public: 14 | LogicException(const std::string& message = std::string("Glr LogicException")); 15 | virtual ~LogicException() throw(); 16 | 17 | virtual const char* what() throw(); 18 | 19 | protected: 20 | std::string message_; 21 | }; 22 | 23 | } 24 | } 25 | 26 | #endif /* LOGICEXCEPTION_H_ */ 27 | -------------------------------------------------------------------------------- /include/exceptions/RuntimeException.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RUNTIMEEXCEPTION_H_ 2 | #define RUNTIMEEXCEPTION_H_ 3 | 4 | #include 5 | 6 | namespace glr 7 | { 8 | namespace exception 9 | { 10 | 11 | class RuntimeException : public std::runtime_error 12 | { 13 | public: 14 | RuntimeException(const std::string& message = std::string("Glr RuntimeException")); 15 | virtual ~RuntimeException() throw(); 16 | 17 | virtual const char* what() throw(); 18 | 19 | protected: 20 | std::string message_; 21 | }; 22 | 23 | } 24 | } 25 | 26 | #endif /* RUNTIMEEXCEPTION_H_ */ 27 | -------------------------------------------------------------------------------- /include/glw/AnimatedBoneNode.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ANIMATEDBONENODE_H_ 2 | #define ANIMATEDBONENODE_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define GLM_FORCE_RADIANS 9 | #include 10 | #include "glm/gtc/quaternion.hpp" 11 | 12 | #include "serialize/Serialization.hpp" 13 | #include "serialize/std/Vector.hpp" 14 | #include "serialize/glm/Vec3.hpp" 15 | #include "serialize/glm/Quat.hpp" 16 | 17 | namespace glr 18 | { 19 | namespace glw 20 | { 21 | 22 | struct AnimatedBoneNode 23 | { 24 | AnimatedBoneNode() 25 | {} 26 | AnimatedBoneNode( 27 | std::string name, 28 | std::vector< glm::detail::float64 > positionTimes, 29 | std::vector< glm::detail::float64 > rotationTimes, 30 | std::vector< glm::detail::float64 > scalingTimes, 31 | std::vector< glm::vec3 > positions, 32 | std::vector< glm::quat > rotations, 33 | std::vector< glm::vec3 > scalings 34 | ) : name(std::move(name)), positionTimes(std::move(positionTimes)), rotationTimes(std::move(rotationTimes)), scalingTimes(std::move(scalingTimes)), positions(std::move(positions)), rotations(std::move(rotations)), scalings(std::move(scalings)) 35 | {} 36 | 37 | std::string name; 38 | std::vector< glm::detail::float64 > positionTimes; 39 | std::vector< glm::detail::float64 > rotationTimes; 40 | std::vector< glm::detail::float64 > scalingTimes; 41 | std::vector< glm::vec3 > positions; 42 | std::vector< glm::quat > rotations; 43 | std::vector< glm::vec3 > scalings; 44 | }; 45 | 46 | } 47 | } 48 | 49 | BOOST_SERIALIZATION_SPLIT_FREE(glr::glw::AnimatedBoneNode) 50 | 51 | namespace boost 52 | { 53 | namespace serialization 54 | { 55 | 56 | template void save(Archive& ar, const glr::glw::AnimatedBoneNode& abn, unsigned int version) 57 | { 58 | ar & abn.name & abn.positionTimes & abn.rotationTimes & abn.scalingTimes; 59 | ar & abn.positions & abn.rotations & abn.scalings; 60 | } 61 | 62 | template void load(Archive& ar, glr::glw::AnimatedBoneNode& abn, unsigned int version) 63 | { 64 | ar & abn.name & abn.positionTimes & abn.rotationTimes & abn.scalingTimes; 65 | ar & abn.positions & abn.rotations & abn.scalings; 66 | } 67 | 68 | } 69 | } 70 | 71 | #endif /* ANIMATEDBONENODE_H_ */ 72 | -------------------------------------------------------------------------------- /include/glw/Animation.inl: -------------------------------------------------------------------------------- 1 | namespace glr 2 | { 3 | namespace glw 4 | { 5 | 6 | template void Animation::serialize(Archive& ar, const unsigned int version) 7 | { 8 | boost::serialization::void_cast_register( 9 | static_cast(nullptr), 10 | static_cast(nullptr) 11 | ); 12 | 13 | ar & name_; 14 | ar & duration_; 15 | ar & ticksPerSecond_; 16 | ar & animatedBoneNodes_; 17 | } 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /include/glw/AnimationManager.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ANIMATIONMANAGER_H_ 2 | #define ANIMATIONMANAGER_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "IAnimationManager.hpp" 10 | 11 | #include "IOpenGlDevice.hpp" 12 | 13 | #include "serialize/SplitMember.hpp" 14 | 15 | namespace glr 16 | { 17 | namespace glw 18 | { 19 | 20 | class Animation; 21 | 22 | class AnimationManager : public IAnimationManager 23 | { 24 | public: 25 | AnimationManager(IOpenGlDevice* openGlDevice); 26 | virtual ~AnimationManager(); 27 | 28 | virtual IAnimation* getAnimation(const std::string& name) const; 29 | virtual IAnimation* addAnimation(const std::string& name, bool initialize = true); 30 | virtual IAnimation* addAnimation(const std::string& name, glm::detail::float64 duration, glm::detail::float64 ticksPerSecond, std::map< std::string, AnimatedBoneNode > animatedBoneNodes, bool initialize = true); 31 | 32 | virtual void serialize(const std::string& filename); 33 | virtual void serialize(serialize::TextOutArchive& outArchive); 34 | 35 | virtual void deserialize(const std::string& filename); 36 | virtual void deserialize(serialize::TextInArchive& inArchive); 37 | 38 | private: 39 | /** 40 | * Required by serialization. 41 | */ 42 | AnimationManager(); 43 | 44 | IOpenGlDevice* openGlDevice_; 45 | 46 | std::map< std::string, std::unique_ptr > animations_; 47 | 48 | mutable std::mutex accessMutex_; 49 | 50 | friend class boost::serialization::access; 51 | 52 | template void serialize(Archive& ar, const unsigned int version); 53 | // Need to do these because boost serialization doesn't have a standard implementation for std::unique_ptr 54 | // Apparently, std::unique_ptr will have a serializable implementation in boost 1.56 55 | // TODO: Implement one myself? 56 | template void save(Archive & ar, const unsigned int version) const; 57 | template void load(Archive & ar, const unsigned int version); 58 | }; 59 | 60 | } 61 | } 62 | 63 | #endif /* ANIMATIONMANAGER_H_ */ 64 | -------------------------------------------------------------------------------- /include/glw/Bone.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BONE_H_ 2 | #define BONE_H_ 3 | 4 | #define GLM_FORCE_RADIANS 5 | #include 6 | 7 | #include "serialize/Serialization.hpp" 8 | #include "serialize/std/Vector.hpp" 9 | #include "serialize/glm/Mat4.hpp" 10 | 11 | namespace glr 12 | { 13 | namespace glw 14 | { 15 | 16 | struct Bone 17 | { 18 | std::string name; 19 | glm::mat4 boneOffset; 20 | }; 21 | 22 | } 23 | } 24 | 25 | 26 | BOOST_SERIALIZATION_SPLIT_FREE(glr::glw::Bone) 27 | 28 | namespace boost 29 | { 30 | namespace serialization 31 | { 32 | 33 | template void save(Archive& ar, const glr::glw::Bone& b, unsigned int version) 34 | { 35 | ar & b.name & b.boneOffset; 36 | } 37 | 38 | template void load(Archive& ar, glr::glw::Bone& b, unsigned int version) 39 | { 40 | ar & b.name & b.boneOffset; 41 | } 42 | 43 | } 44 | } 45 | 46 | #endif /* BONE_H_ */ 47 | -------------------------------------------------------------------------------- /include/glw/BoneData.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BONEDATA_H_ 2 | #define BONEDATA_H_ 3 | 4 | #include "serialize/Serialization.hpp" 5 | #include "serialize/std/Vector.hpp" 6 | #include "serialize/std/Map.hpp" 7 | 8 | #include "Bone.hpp" 9 | 10 | namespace glr 11 | { 12 | namespace glw 13 | { 14 | 15 | /** 16 | * 17 | */ 18 | struct BoneData 19 | { 20 | std::string name; 21 | std::map< std::string, glm::detail::uint32 > boneIndexMap; 22 | std::vector< Bone > boneTransform; 23 | }; 24 | 25 | } 26 | } 27 | 28 | BOOST_SERIALIZATION_SPLIT_FREE(glr::glw::BoneData) 29 | 30 | namespace boost 31 | { 32 | namespace serialization 33 | { 34 | 35 | template void save(Archive& ar, const glr::glw::BoneData& bd, unsigned int version) 36 | { 37 | ar & bd.name & bd.boneIndexMap & bd.boneTransform; 38 | } 39 | 40 | template void load(Archive& ar, glr::glw::BoneData& bd, unsigned int version) 41 | { 42 | ar & bd.name & bd.boneIndexMap & bd.boneTransform; 43 | } 44 | 45 | } 46 | } 47 | 48 | #endif /* BONEDATA_H_ */ 49 | -------------------------------------------------------------------------------- /include/glw/BoneNode.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BONENODE_H_ 2 | #define BONENODE_H_ 3 | 4 | #include "serialize/Serialization.hpp" 5 | #include "serialize/std/Vector.hpp" 6 | #include "serialize/glm/Mat4.hpp" 7 | 8 | namespace glr 9 | { 10 | namespace glw 11 | { 12 | 13 | /** 14 | * 15 | */ 16 | struct BoneNode 17 | { 18 | std::string name; 19 | glm::mat4 transformation; 20 | std::vector< BoneNode > children; 21 | }; 22 | 23 | } 24 | } 25 | 26 | BOOST_SERIALIZATION_SPLIT_FREE(glr::glw::BoneNode) 27 | 28 | namespace boost 29 | { 30 | namespace serialization 31 | { 32 | 33 | template void save(Archive& ar, const glr::glw::BoneNode& bn, unsigned int version) 34 | { 35 | auto size = bn.children.size(); 36 | ar & bn.name & bn.transformation; 37 | ar & size; 38 | for (auto& child : bn.children) 39 | { 40 | ar & child; 41 | } 42 | } 43 | 44 | template void load(Archive& ar, glr::glw::BoneNode& bn, unsigned int version) 45 | { 46 | std::vector< glr::glw::BoneNode >::size_type size = 0; 47 | 48 | ar & bn.name & bn.transformation; 49 | ar & size; 50 | for (glm::detail::uint32 i=0; i < size; i++) 51 | { 52 | glr::glw::BoneNode node = glr::glw::BoneNode(); 53 | ar & node; 54 | bn.children.push_back( node ); 55 | } 56 | } 57 | 58 | } 59 | } 60 | 61 | #endif /* BONENODE_H_ */ 62 | -------------------------------------------------------------------------------- /include/glw/Constants.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GLR_GLW_CONSTANTS_H_ 2 | #define GLR_GLW_CONSTANTS_H_ 3 | 4 | #include 5 | 6 | #define GLM_FORCE_RADIANS 7 | #include 8 | 9 | namespace glr 10 | { 11 | namespace glw 12 | { 13 | 14 | namespace glmd = glm::detail; 15 | 16 | class Constants { 17 | public: 18 | static const std::string MODEL_DIRECTORY; 19 | 20 | static const glmd::uint32 MAX_NUMBER_OF_BONES_PER_MESH; 21 | 22 | static const std::string GLR_IDENTITY_BONES; 23 | }; 24 | 25 | } 26 | } 27 | 28 | #endif /* GLR_GLW_CONSTANTS_H_ */ 29 | -------------------------------------------------------------------------------- /include/glw/IAnimationManager.hpp: -------------------------------------------------------------------------------- 1 | #ifndef IANIMATIONMANAGER_H_ 2 | #define IANIMATIONMANAGER_H_ 3 | 4 | #include 5 | 6 | #include "Animation.hpp" 7 | 8 | #include "serialize/ITextSerializable.hpp" 9 | 10 | namespace glr 11 | { 12 | namespace glw 13 | { 14 | 15 | class IAnimation; 16 | 17 | class IAnimationManager : public virtual serialize::ITextSerializable 18 | { 19 | public: 20 | virtual ~IAnimationManager() 21 | { 22 | } 23 | ; 24 | 25 | /** 26 | * Returns the animation with the given name. If an animation with the given name doesn't exist, it returns 27 | * nullptr. 28 | * 29 | * **Thread Safe**: This method is safe to call in a multi-threaded environment. 30 | * 31 | * @param name The name of the animation to retrieve. 32 | * 33 | * @return The Animation object with name 'name', or nullptr if no animation exists with that name. 34 | */ 35 | virtual IAnimation* getAnimation(const std::string& name) const = 0; 36 | 37 | /** 38 | * Creates an animation with the given name. 39 | * 40 | * If an animation already exists with the given name, it will return that animation. 41 | * 42 | * **Partially Thread Safe**: If initialize is false, this method is safe to call in a multi-threaded environment. However, 43 | * if initialize is true, this method is *not* thread safe, and should only be called from the OpenGL thread. 44 | * 45 | * @param name The name to use for the new animation. 46 | * @param initialize If true, will initialize all of the resources required for this animation. Otherwise, it will 47 | * just create the animation and return it (without initializing it). 48 | * 49 | * @return An Animation object. 50 | */ 51 | virtual IAnimation* addAnimation(const std::string& name, bool initialize = true) = 0; 52 | 53 | /** 54 | * Creates an animation with the given name and using the provided animation data. 55 | * 56 | * If an animation already exists with the given name, it will return that animation. 57 | * 58 | * **Partially Thread Safe**: If initialize is false, this method is safe to call in a multi-threaded environment. However, 59 | * if initialize is true, this method is *not* thread safe, and should only be called from the OpenGL thread. 60 | * 61 | * @param name The name to use for the new animation. 62 | * @param duration The duration of the new animation. 63 | * @param ticksPerSecond The number of ticks per second. 64 | * @param animatedBoneNodes The animated bone nodes. 65 | * @param initialize If true, will initialize all of the resources required for this animation. Otherwise, it will 66 | * just create the animation and return it (without initializing it). 67 | * 68 | * @return An Animation object. 69 | */ 70 | virtual IAnimation* addAnimation(const std::string& name, glm::detail::float64 duration, glm::detail::float64 ticksPerSecond, std::map< std::string, AnimatedBoneNode > animatedBoneNodes, bool initialize = true) = 0; 71 | }; 72 | 73 | } 74 | } 75 | 76 | #endif /* IANIMATIONMANAGER_H_ */ 77 | -------------------------------------------------------------------------------- /include/glw/IBindable.hpp: -------------------------------------------------------------------------------- 1 | #ifndef IBINDABLE_H_ 2 | #define IBINDABLE_H_ 3 | 4 | namespace glr 5 | { 6 | namespace glw 7 | { 8 | 9 | class IBindable 10 | { 11 | public: 12 | virtual ~IBindable() 13 | { 14 | } 15 | ; 16 | 17 | /** 18 | * Will bind the current resource for use in an OpenGL shader program. 19 | * 20 | * **Note**: This method is *not* thread safe - it should only be called from the OpenGL thread. 21 | */ 22 | virtual void bind() const = 0; 23 | }; 24 | 25 | } 26 | } 27 | 28 | #endif /* IBINDABLE_H_ */ 29 | -------------------------------------------------------------------------------- /include/glw/IMaterial.hpp: -------------------------------------------------------------------------------- 1 | #ifndef IMATERIAL_H_ 2 | #define IMATERIAL_H_ 3 | 4 | #include "IGraphicsObject.hpp" 5 | #include "IMaterialBindListener.hpp" 6 | 7 | #include "serialize/ITextSerializable.hpp" 8 | 9 | namespace glr 10 | { 11 | namespace glw 12 | { 13 | 14 | class IMaterial : public virtual IGraphicsObject, public virtual serialize::ITextSerializable 15 | { 16 | public: 17 | virtual ~IMaterial() 18 | { 19 | } 20 | ; 21 | 22 | /** 23 | * Binds the data in OpenGL, making it ready to use. 24 | * 25 | * **Not Thread Safe**: This method is *not* safe to call in a multi-threaded environment, and should only be called from the 26 | * OpenGL thread. 27 | */ 28 | virtual void bind() = 0; 29 | 30 | /** 31 | * Returns the OpenGL Buffer Id for this resource. 32 | * 33 | * @return The OpenGL Buffer Id. 34 | */ 35 | virtual GLuint getBufferId() const = 0; 36 | 37 | virtual void setAmbient(const glm::vec4& ambient) = 0; 38 | virtual void setDiffuse(const glm::vec4& diffuse) = 0; 39 | virtual void setSpecular(const glm::vec4& specular) = 0; 40 | virtual void setEmission(const glm::vec4& emission) = 0; 41 | virtual void setShininess(glm::detail::float32 shininess) = 0; 42 | virtual void setStrength(glm::detail::float32 strength) = 0; 43 | 44 | /** 45 | * Returns the name of this material. 46 | * 47 | * @return The name of the material. 48 | */ 49 | virtual const std::string& getName() const = 0; 50 | 51 | /** 52 | * Add a listener, which will be notified when this material gets bound. 53 | * 54 | * @param bindListener A pointer to an object implementing the IMaterialBindListener interface. 55 | */ 56 | virtual void addBindListener(IMaterialBindListener* bindListener) = 0; 57 | 58 | /** 59 | * Remove a bind listener. 60 | * 61 | * @param bindListener A pointer to an IMaterialBindListener object that should be removed as a bind listener for this material. 62 | */ 63 | virtual void removeBindListener(IMaterialBindListener* bindListener) = 0; 64 | }; 65 | 66 | } 67 | } 68 | 69 | #endif /* IMATERIAL_H_ */ 70 | -------------------------------------------------------------------------------- /include/glw/IMaterialBindListener.hpp: -------------------------------------------------------------------------------- 1 | #ifndef IMATERIALBINDLISTENER_H_ 2 | #define IMATERIALBINDLISTENER_H_ 3 | 4 | namespace glr 5 | { 6 | namespace glw 7 | { 8 | 9 | class IMaterial; 10 | 11 | class IMaterialBindListener 12 | { 13 | public: 14 | virtual ~IMaterialBindListener() 15 | { 16 | } 17 | ; 18 | 19 | virtual void materialBindCallback(IMaterial* material) = 0; 20 | }; 21 | 22 | } 23 | } 24 | 25 | #endif /* IMATERIALBINDLISTENER_H_ */ 26 | -------------------------------------------------------------------------------- /include/glw/IMaterialManager.hpp: -------------------------------------------------------------------------------- 1 | #ifndef IMATERIALMANAGER_H_ 2 | #define IMATERIALMANAGER_H_ 3 | 4 | #include 5 | 6 | #include "serialize/ITextSerializable.hpp" 7 | 8 | namespace glr 9 | { 10 | namespace glw 11 | { 12 | 13 | class IMaterial; 14 | 15 | class IMaterialManager : public virtual serialize::ITextSerializable 16 | { 17 | public: 18 | virtual ~IMaterialManager() 19 | { 20 | } 21 | ; 22 | 23 | /** 24 | * Returns the material with the given name. If a material with the given name doesn't exist, it returns 25 | * nullptr. 26 | * 27 | * **Thread Safe**: This method is safe to call in a multi-threaded environment. 28 | * 29 | * @param name The name of the material to retrieve. 30 | * 31 | * @return The Material object with name 'name', or nullptr if no material exists with that name. 32 | */ 33 | virtual IMaterial* getMaterial(const std::string& name) const = 0; 34 | 35 | /** 36 | * Creates a material with the given name. 37 | * 38 | * If a material already exists with the given name, it will return that material. 39 | * 40 | * **Partially Thread Safe**: If initialize is false, this method is safe to call in a multi-threaded environment. However, 41 | * if initialize is true, this method is *not* thread safe, and should only be called from the OpenGL thread. 42 | * 43 | * @param name The name to use for the new material. 44 | * 45 | * @return A Material object. 46 | */ 47 | virtual IMaterial* addMaterial(const std::string& name) = 0; 48 | 49 | /** 50 | * Creates a material with the given name and using the provided material data. 51 | * 52 | * If a material already exists with the given name, it will return that material. 53 | * 54 | * **Partially Thread Safe**: If initialize is false, this method is safe to call in a multi-threaded environment. However, 55 | * if initialize is true, this method is *not* thread safe, and should only be called from the OpenGL thread. 56 | * 57 | * @param name The name to use for the new material. 58 | * @param ambient 59 | * @param diffuse 60 | * @param specular 61 | * @param emission 62 | * @param shininess 63 | * @param strength 64 | * @param initialize If true, will initialize all of the resources required for this material. Otherwise, it will 65 | * just create the material and return it (without initializing it). 66 | * 67 | * @return A Material object. 68 | */ 69 | virtual IMaterial* addMaterial( 70 | const std::string& name, 71 | glm::vec4 ambient, 72 | glm::vec4 diffuse, 73 | glm::vec4 specular, 74 | glm::vec4 emission, 75 | glm::detail::float32 shininess, 76 | glm::detail::float32 strength, 77 | bool initialize = true 78 | ) = 0; 79 | }; 80 | 81 | } 82 | } 83 | 84 | #endif /* IMATERIALMANAGER_H_ */ 85 | -------------------------------------------------------------------------------- /include/glw/IMesh.hpp: -------------------------------------------------------------------------------- 1 | #ifndef IMESH_H_ 2 | #define IMESH_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define GLM_FORCE_RADIANS 9 | #include 10 | 11 | #include "VertexBoneData.hpp" 12 | #include "BoneData.hpp" 13 | #include "Bone.hpp" 14 | 15 | #include "IGraphicsObject.hpp" 16 | 17 | #include "common/logger/Logger.hpp" 18 | 19 | #include "serialize/ITextSerializable.hpp" 20 | 21 | namespace glr 22 | { 23 | namespace glw 24 | { 25 | 26 | /** 27 | * Represents a Mesh which can be rendered in the scene. 28 | */ 29 | class IMesh : public virtual IGraphicsObject, public virtual serialize::ITextSerializable 30 | { 31 | public: 32 | virtual ~IMesh() 33 | { 34 | } 35 | ; 36 | 37 | /** 38 | * Will render this mesh in the scene. 39 | * 40 | * **Not Thread Safe**: This method is *not* safe to call in a multi-threaded environment, and should only be called from the 41 | * OpenGL thread. 42 | */ 43 | virtual void render() = 0; 44 | 45 | /** 46 | * Returns a reference to the bone data. 47 | */ 48 | virtual BoneData& getBoneData() = 0; 49 | 50 | /** 51 | * Returns the name of this mesh. 52 | * 53 | * @return The name of the mesh. 54 | */ 55 | virtual const std::string& getName() const = 0; 56 | }; 57 | 58 | } 59 | } 60 | 61 | #endif /* IMESH_H_ */ 62 | -------------------------------------------------------------------------------- /include/glw/ITexture.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ITEXTURE_H_ 2 | #define ITEXTURE_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define GLM_FORCE_RADIANS 9 | #include 10 | 11 | #include "IGraphicsObject.hpp" 12 | #include "ITextureBindListener.hpp" 13 | #include "TextureSettings.hpp" 14 | 15 | #include "common/logger/Logger.hpp" 16 | #include "common/utilities/ImageLoader.hpp" 17 | 18 | #include "serialize/ITextSerializable.hpp" 19 | 20 | namespace glr 21 | { 22 | namespace glw 23 | { 24 | 25 | class ITexture : public virtual IGraphicsObject, public virtual serialize::ITextSerializable 26 | { 27 | public: 28 | virtual ~ITexture() 29 | { 30 | } 31 | ; 32 | 33 | /** 34 | * Binds the data in OpenGL, making it ready to use. 35 | * 36 | * **Not Thread Safe**: This method is *not* safe to call in a multi-threaded environment, and should only be called from the 37 | * OpenGL thread. 38 | * 39 | * @param texturePosition The texture position to bind to. This must be a value between 0 - 9. 40 | */ 41 | virtual void bind(GLuint texturePosition = 0) = 0; 42 | 43 | /** 44 | * Returns the name of this texture. 45 | * 46 | * @return The name of the texture. 47 | */ 48 | virtual const std::string& getName() const = 0; 49 | 50 | /** 51 | * Add a listener, which will be notified when this texture gets bound. 52 | * 53 | * @param bindListener A pointer to an object implementing the ITextureBindListener interface. 54 | */ 55 | virtual void addBindListener(ITextureBindListener* bindListener) = 0; 56 | 57 | /** 58 | * Remove a bind listener. 59 | * 60 | * @param bindListener A pointer to an ITextureBindListener object that should be removed as a bind listener for this texture. 61 | */ 62 | virtual void removeBindListener(ITextureBindListener* bindListener) = 0; 63 | }; 64 | 65 | } 66 | } 67 | 68 | #endif /* MESH_H_ */ 69 | -------------------------------------------------------------------------------- /include/glw/ITextureBindListener.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ITEXTUREBINDLISTENER_H_ 2 | #define ITEXTUREBINDLISTENER_H_ 3 | 4 | namespace glr 5 | { 6 | namespace glw 7 | { 8 | 9 | class ITexture; 10 | 11 | class ITextureBindListener 12 | { 13 | public: 14 | virtual ~ITextureBindListener() 15 | { 16 | } 17 | ; 18 | 19 | virtual void textureBindCallback(ITexture* texture) = 0; 20 | }; 21 | 22 | } 23 | } 24 | 25 | #endif /* ITEXTUREBINDLISTENER_H_ */ 26 | -------------------------------------------------------------------------------- /include/glw/Material.inl: -------------------------------------------------------------------------------- 1 | namespace glr 2 | { 3 | namespace glw 4 | { 5 | 6 | template void Material::serialize(Archive& ar, const unsigned int version) 7 | { 8 | boost::serialization::void_cast_register( 9 | static_cast(nullptr), 10 | static_cast(nullptr) 11 | ); 12 | 13 | ar & name_; 14 | ar & ambient_; 15 | ar & diffuse_; 16 | ar & specular_; 17 | ar & emission_; 18 | ar & shininess_; 19 | ar & strength_; 20 | } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /include/glw/MaterialData.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MATERIALDATA_H_ 2 | #define MATERIALDATA_H_ 3 | 4 | #define GLM_FORCE_RADIANS 5 | #include 6 | 7 | #include "serialize/Serialization.hpp" 8 | #include "serialize/std/Vector.hpp" 9 | #include "serialize/glm/Vec4.hpp" 10 | 11 | namespace glr 12 | { 13 | namespace glw 14 | { 15 | 16 | struct MaterialData 17 | { 18 | glm::vec4 ambient; 19 | glm::vec4 diffuse; 20 | glm::vec4 specular; 21 | glm::vec4 emission; 22 | //glm::detail::float32 shininess; 23 | //glm::detail::float32 strength; 24 | }; 25 | 26 | } 27 | } 28 | 29 | BOOST_SERIALIZATION_SPLIT_FREE(glr::glw::MaterialData) 30 | 31 | namespace boost 32 | { 33 | namespace serialization 34 | { 35 | 36 | template void save(Archive& ar, const glr::glw::MaterialData& md, unsigned int version) 37 | { 38 | ar & md.ambient & md.diffuse & md.specular & md.emission; 39 | } 40 | 41 | template void load(Archive& ar, glr::glw::MaterialData& md, unsigned int version) 42 | { 43 | ar & md.ambient & md.diffuse & md.specular & md.emission; 44 | } 45 | 46 | } 47 | } 48 | 49 | #endif /* MATERIALDATA_H_ */ 50 | -------------------------------------------------------------------------------- /include/glw/MaterialManager.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MATERIALMANAGER_H_ 2 | #define MATERIALMANAGER_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | #include "IOpenGlDevice.hpp" 12 | 13 | #include "IMaterialManager.hpp" 14 | 15 | #include "serialize/SplitMember.hpp" 16 | 17 | namespace glr 18 | { 19 | namespace glw 20 | { 21 | 22 | class Material; 23 | 24 | class MaterialManager : public IMaterialManager 25 | { 26 | public: 27 | MaterialManager(IOpenGlDevice* openGlDevice); 28 | virtual ~MaterialManager(); 29 | 30 | virtual IMaterial* getMaterial(const std::string& name) const; 31 | virtual IMaterial* addMaterial(const std::string& name); 32 | virtual IMaterial* addMaterial( 33 | const std::string& name, 34 | glm::vec4 ambient, 35 | glm::vec4 diffuse, 36 | glm::vec4 specular, 37 | glm::vec4 emission, 38 | glm::detail::float32 shininess, 39 | glm::detail::float32 strength, 40 | bool initialize = true 41 | ); 42 | 43 | virtual void serialize(const std::string& filename); 44 | virtual void serialize(serialize::TextOutArchive& outArchive); 45 | 46 | virtual void deserialize(const std::string& filename); 47 | virtual void deserialize(serialize::TextInArchive& inArchive); 48 | 49 | private: 50 | /** 51 | * Required by serialization. 52 | */ 53 | MaterialManager(); 54 | 55 | IOpenGlDevice* openGlDevice_; 56 | 57 | std::map< std::string, std::unique_ptr > materials_; 58 | 59 | mutable std::mutex accessMutex_; 60 | 61 | friend class boost::serialization::access; 62 | 63 | template void serialize(Archive& ar, const unsigned int version); 64 | // Need to do these because boost serialization doesn't have a standard implementation for std::unique_ptr 65 | // Apparently, std::unique_ptr will have a serializable implementation in boost 1.56 66 | // TODO: Implement one myself? 67 | template void save(Archive & ar, const unsigned int version) const; 68 | template void load(Archive & ar, const unsigned int version); 69 | }; 70 | 71 | } 72 | } 73 | 74 | #endif /* MATERIALMANAGER_H_ */ 75 | -------------------------------------------------------------------------------- /include/glw/Mesh.inl: -------------------------------------------------------------------------------- 1 | namespace glr 2 | { 3 | namespace glw 4 | { 5 | 6 | template void Mesh::serialize(Archive& ar, const unsigned int version) 7 | { 8 | boost::serialization::void_cast_register( 9 | static_cast(nullptr), 10 | static_cast(nullptr) 11 | ); 12 | //ar & boost::serialization::base_object(*this); 13 | ar & name_; 14 | ar & vertices_; 15 | ar & normals_; 16 | ar & textureCoordinates_; 17 | ar & colors_; 18 | ar & vertexBoneData_; 19 | ar & boneData_; 20 | } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /include/glw/MeshManager.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MESHMANAGER_H_ 2 | #define MESHMANAGER_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "IMeshManager.hpp" 10 | 11 | #include "IOpenGlDevice.hpp" 12 | 13 | #include "Mesh.hpp" 14 | 15 | #include "serialize/SplitMember.hpp" 16 | 17 | namespace glr 18 | { 19 | namespace glw 20 | { 21 | 22 | class MeshManager : public IMeshManager 23 | { 24 | public: 25 | MeshManager(IOpenGlDevice* openGlDevice); 26 | virtual ~MeshManager(); 27 | 28 | virtual IMesh* getMesh(const std::string& name) const; 29 | virtual IMesh* addMesh(const std::string& name); 30 | virtual IMesh* addMesh( 31 | const std::string& name, 32 | std::vector< glm::vec3 > vertices, 33 | std::vector< glm::vec3 > normals, 34 | std::vector< glm::vec2 > textureCoordinates, 35 | std::vector< glm::vec4 > colors, 36 | std::vector< VertexBoneData > bones, 37 | BoneData boneData, 38 | bool initialize = true 39 | ); 40 | virtual IMesh* addMesh( 41 | const std::string& name, 42 | std::vector< glm::vec3 > vertices, 43 | std::vector< glm::vec3 > normals, 44 | std::vector< glm::vec2 > textureCoordinates, 45 | std::vector< glm::vec4 > colors, 46 | bool initialize = true 47 | ); 48 | virtual void destroyMesh( const std::string& name ); 49 | virtual void destroyMesh( IMesh* mesh ); 50 | 51 | virtual void serialize(const std::string& filename); 52 | virtual void serialize(serialize::TextOutArchive& outArchive); 53 | 54 | virtual void deserialize(const std::string& filename); 55 | virtual void deserialize(serialize::TextInArchive& inArchive); 56 | 57 | private: 58 | /** 59 | * Required by serialization. 60 | */ 61 | MeshManager(); 62 | 63 | IOpenGlDevice* openGlDevice_; 64 | 65 | std::map< std::string, std::unique_ptr > meshes_; 66 | 67 | mutable std::mutex accessMutex_; 68 | 69 | friend class boost::serialization::access; 70 | 71 | template void serialize(Archive& ar, const unsigned int version); 72 | // Need to do these because boost serialization doesn't have a standard implementation for std::unique_ptr 73 | // Apparently, std::unique_ptr will have a serializable implementation in boost 1.56 74 | // TODO: Implement one myself? 75 | template void save(Archive & ar, const unsigned int version) const; 76 | template void load(Archive & ar, const unsigned int version); 77 | }; 78 | 79 | } 80 | } 81 | 82 | #endif /* MESHMANAGER_H_ */ 83 | -------------------------------------------------------------------------------- /include/glw/OpenGlDeviceSettings.hpp: -------------------------------------------------------------------------------- 1 | #ifndef OPENGLDEVICESETTINGS_H_ 2 | #define OPENGLDEVICESETTINGS_H_ 3 | 4 | #include 5 | 6 | #include "glw/Constants.hpp" 7 | 8 | namespace glr 9 | { 10 | namespace glw 11 | { 12 | 13 | /** 14 | * Used to pass in OpenGlDeviceSettings settings (so we don't have to have a method with a whole ton of parameters). 15 | */ 16 | struct OpenGlDeviceSettings 17 | { 18 | OpenGlDeviceSettings() : defaultTextureDir(glr::glw::Constants::MODEL_DIRECTORY) 19 | { 20 | } 21 | 22 | std::string defaultTextureDir; 23 | }; 24 | 25 | } 26 | } 27 | 28 | #endif /* OPENGLDEVICESETTINGS_H_ */ 29 | -------------------------------------------------------------------------------- /include/glw/Texture2D.inl: -------------------------------------------------------------------------------- 1 | namespace glr 2 | { 3 | namespace glw 4 | { 5 | 6 | template void Texture2D::serialize(Archive& ar, const unsigned int version) 7 | { 8 | boost::serialization::void_cast_register( 9 | static_cast(nullptr), 10 | static_cast(nullptr) 11 | ); 12 | 13 | ar & name_; 14 | ar & image_; 15 | ar & internalFormat_; 16 | } 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /include/glw/Texture2DArray.inl: -------------------------------------------------------------------------------- 1 | namespace glr 2 | { 3 | namespace glw 4 | { 5 | 6 | template void Texture2DArray::serialize(Archive& ar, const unsigned int version) 7 | { 8 | boost::serialization::void_cast_register( 9 | static_cast(nullptr), 10 | static_cast(nullptr) 11 | ); 12 | 13 | ar & name_; 14 | ar & images_; 15 | } 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /include/glw/TextureManager.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TEXTUREMANAGER_H_ 2 | #define TEXTUREMANAGER_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "IOpenGlDevice.hpp" 10 | 11 | #include "ITextureManager.hpp" 12 | 13 | #include "serialize/SplitMember.hpp" 14 | 15 | namespace glr 16 | { 17 | namespace glw 18 | { 19 | 20 | class TextureManager : public ITextureManager 21 | { 22 | public: 23 | TextureManager(IOpenGlDevice* openGlDevice); 24 | virtual ~TextureManager(); 25 | 26 | virtual ITexture* getTexture(const std::string& name) const; 27 | virtual Texture2D* getTexture2D(const std::string& name) const; 28 | virtual Texture2DArray* getTexture2DArray(const std::string& name) const; 29 | 30 | virtual Texture2D* addTexture2D(const std::string& name, const TextureSettings settings = TextureSettings()); 31 | virtual Texture2D* addTexture2D(const std::string& name, const std::string& filename, const TextureSettings settings = TextureSettings(), bool initialize = true); 32 | virtual Texture2D* addTexture2D(const std::string& name, utilities::Image* image, const TextureSettings settings = TextureSettings(), bool initialize = true); 33 | virtual Texture2DArray* addTexture2DArray(const std::string& name, const TextureSettings settings = TextureSettings()); 34 | virtual Texture2DArray* addTexture2DArray(const std::string& name, const std::vector& filenames, const TextureSettings settings = TextureSettings(), bool initialize = true); 35 | virtual Texture2DArray* addTexture2DArray(const std::string& name, const std::vector& images, const TextureSettings settings = TextureSettings(), bool initialize = true); 36 | 37 | virtual void serialize(const std::string& filename); 38 | virtual void serialize(serialize::TextOutArchive& outArchive); 39 | 40 | virtual void deserialize(const std::string& filename); 41 | virtual void deserialize(serialize::TextInArchive& inArchive); 42 | 43 | private: 44 | /** 45 | * Required by serialization. 46 | */ 47 | TextureManager(); 48 | 49 | IOpenGlDevice* openGlDevice_; 50 | 51 | std::map< std::string, std::unique_ptr > textures2D_; 52 | std::map< std::string, std::unique_ptr > textures2DArray_; 53 | 54 | mutable std::recursive_mutex accessMutex_; 55 | 56 | friend class boost::serialization::access; 57 | 58 | template void serialize(Archive& ar, const unsigned int version); 59 | // Need to do these because boost serialization doesn't have a standard implementation for std::unique_ptr 60 | // Apparently, std::unique_ptr will have a serializable implementation in boost 1.56 61 | // TODO: Implement one myself? 62 | template void save(Archive & ar, const unsigned int version) const; 63 | template void load(Archive & ar, const unsigned int version); 64 | }; 65 | 66 | } 67 | } 68 | 69 | #endif /* TEXTUREMANAGER_H_ */ 70 | -------------------------------------------------------------------------------- /include/glw/TextureSettings.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TEXTURESETTINGS_H_ 2 | #define TEXTURESETTINGS_H_ 3 | 4 | namespace glr 5 | { 6 | namespace glw 7 | { 8 | 9 | 10 | /** 11 | * Used to pass in TextureSettings settings (so we don't have to have a method with a whole ton of parameters). 12 | */ 13 | struct TextureSettings 14 | { 15 | TextureSettings() : textureWrapS(GL_CLAMP_TO_EDGE), textureWrapT(GL_CLAMP_TO_EDGE) 16 | { 17 | } 18 | 19 | GLint textureWrapS; 20 | GLint textureWrapT; 21 | }; 22 | 23 | } 24 | } 25 | 26 | #endif /* TEXTURESETTINGS_H_ */ 27 | -------------------------------------------------------------------------------- /include/glw/VertexBoneData.hpp: -------------------------------------------------------------------------------- 1 | #ifndef VERTEXBONEDATA_H_ 2 | #define VERTEXBONEDATA_H_ 3 | 4 | #define GLM_FORCE_RADIANS 5 | #include 6 | 7 | #include "serialize/Serialization.hpp" 8 | #include "serialize/std/Vector.hpp" 9 | #include "serialize/glm/Vec4.hpp" 10 | #include "serialize/glm/IVec4.hpp" 11 | 12 | namespace glr 13 | { 14 | namespace glw 15 | { 16 | 17 | struct VertexBoneData 18 | { 19 | glm::ivec4 boneIds; 20 | glm::vec4 weights; 21 | 22 | VertexBoneData() 23 | { 24 | boneIds = glm::ivec4(0); 25 | weights = glm::vec4(0.0f); 26 | } 27 | 28 | void addBoneWeight( glm::detail::uint32 id, glm::detail::float32 weight ) 29 | { 30 | for (glm::detail::uint32 i = 0; i < 4; i++) 31 | { 32 | if (weights[i] == 0.0f) 33 | { 34 | boneIds[i] = id; 35 | weights[i] = weight; 36 | 37 | assert( weights[0] + weights[1] + weights[2] + weights[3] < 1.05f ); 38 | 39 | return; 40 | } 41 | } 42 | 43 | // If we get here, we have too many bones per vertex 44 | assert(0); 45 | } 46 | }; 47 | 48 | } 49 | } 50 | 51 | BOOST_SERIALIZATION_SPLIT_FREE(glr::glw::VertexBoneData) 52 | 53 | namespace boost 54 | { 55 | namespace serialization 56 | { 57 | 58 | template void save(Archive& ar, const glr::glw::VertexBoneData& vbw, unsigned int version) 59 | { 60 | ar & vbw.boneIds & vbw.weights; 61 | } 62 | 63 | template void load(Archive& ar, glr::glw::VertexBoneData& vbw, unsigned int version) 64 | { 65 | ar & vbw.boneIds & vbw.weights; 66 | } 67 | 68 | } 69 | } 70 | 71 | #endif /* VERTEXBONEDATA_H_ */ 72 | -------------------------------------------------------------------------------- /include/glw/shaders/Constants.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CONSTANTS_H_ 2 | #define CONSTANTS_H_ 3 | 4 | namespace glr 5 | { 6 | namespace shaders 7 | { 8 | namespace constants 9 | { 10 | 11 | static const std::string SHADER_DIRECTORY = std::string("/home/jarrett/projects/chisholmsoft/glr/data/shaders/"); 12 | 13 | } 14 | 15 | } 16 | } 17 | 18 | #endif /* CONSTANTS_H_ */ 19 | -------------------------------------------------------------------------------- /include/glw/shaders/GlrPreProcessor.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GLRPREPROCESSOR_H 2 | #define GLRPREPROCESSOR_H 3 | 4 | #include "CPreProcessor.hpp" 5 | 6 | #include "../../exceptions/GlException.hpp" 7 | 8 | namespace glr 9 | { 10 | namespace shaders 11 | { 12 | 13 | /** 14 | * Class that will extend the functionality of the CPreProcessor class for anything specific to processing 15 | * 'glr' shader source data. 16 | */ 17 | class GlrPreProcessor : public CPreProcessor 18 | { 19 | public: 20 | GlrPreProcessor(std::string source, std::string baseDirectory = std::string()); 21 | 22 | private: 23 | }; 24 | 25 | } 26 | } 27 | 28 | #endif /* GLRPREPROCESSOR_H */ 29 | -------------------------------------------------------------------------------- /include/glw/shaders/GlrShader.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GLRSHADER_H 2 | #define GLRSHADER_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "IShader.hpp" 9 | 10 | #include "GlrParser.hpp" 11 | 12 | namespace glr 13 | { 14 | namespace shaders 15 | { 16 | 17 | /** 18 | * Class representing a `glr` shader. This is a shader that contains the 'raw' shader source (i.e. before it has been processed). 19 | * 20 | * Note that, in the shader source, there are 2 kinds of `#include` directives. The first one looks like this: 21 | * 22 | * `#include ` 23 | * 24 | * The `<` and `>` around the filename indicate that this is a 'system' file to include. GLR has several of these system shader source 25 | * files available for use. 26 | * 27 | * The second one looks like this: 28 | * 29 | * `#include "myshader.vs"` 30 | * 31 | * This will include a file named `myshader.vs` from the disk. This is so that you can include your own, user-defined shader files. 32 | * 33 | * You can use this class to then process the 'raw' shader source into something more amenable to an opengl shader. 34 | */ 35 | class GlrShader 36 | { 37 | public: 38 | GlrShader(std::string source, std::string baseDirectory = std::string()); 39 | GlrShader(std::string name, std::string source, std::string baseDirectory = std::string()); 40 | virtual ~GlrShader(); 41 | 42 | void process(std::map< std::string, std::string > defineMap); 43 | 44 | const std::string& getName() const; 45 | IShader::Type getType() const; 46 | std::string getProcessedSource() const; 47 | std::string getSource() const; 48 | std::vector< std::pair > getBindings(); 49 | std::vector< std::pair > getLocationBindings(); 50 | 51 | bool containsPreProcessorCommands() const; 52 | 53 | private: 54 | std::string name_; 55 | IShader::Type type_; 56 | 57 | std::string source_; 58 | std::string processedSource_; 59 | std::string baseDirectory_; 60 | 61 | std::vector< std::pair > bindBindings_; 62 | std::vector< std::pair > locationBindings_; 63 | }; 64 | 65 | } 66 | } 67 | 68 | #endif /* GLRSHADER_H */ 69 | -------------------------------------------------------------------------------- /include/glw/shaders/GlrShaderProgram.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GLRSHADERPROGRAM_H 2 | #define GLRSHADERPROGRAM_H 3 | 4 | #include 5 | 6 | #include "GlrShader.hpp" 7 | 8 | namespace glr 9 | { 10 | namespace shaders 11 | { 12 | 13 | /** 14 | * Class representing a 'glr' shader program. This is source data that contains #defines, #includes, etc. However, unlike actual shader source files, 15 | * the source for a shader program doesn't actually include source data when processing the #include directive. Instead, this directive indicates 16 | * a shader source file that is to be used when 'building/compiling' this shader program. 17 | * 18 | * The #include directive indicates a shader source file to use for this shader program. During processing of the GlrShaderProgram, it will 19 | * load the GlrShader specified, and also pass any #defines, etc, that have been set before the #include directive. This will 20 | * allow you to specify some #define values before actually processing a source file, which can be useful if you want a shader program to 21 | * have, for example, a certain number of lights available use. 22 | * 23 | * Note that GlrShader objects are reused between different GlrShaderPrograms. This means that, once you have processed a GlrShaderProgram, 24 | * you will need to convert it into a GlslShaderProgram immediately after. Otherwise, the processing you have done using the GlrShader objects 25 | * may be lost once they are reused in processing of another GlrShaderProgram. 26 | */ 27 | class GlrShaderProgram 28 | { 29 | public: 30 | GlrShaderProgram(std::string source, std::string baseDirectory = std::string()); 31 | GlrShaderProgram(std::string name, std::string source, std::string baseDirectory = std::string()); 32 | virtual ~GlrShaderProgram(); 33 | 34 | /** 35 | * Process this shader program. This function will find the shaders that are required for this shader program using the provided 36 | * glrShaderMap, and use those shaders (i.e. process those shaders) for this particular shader program. 37 | * 38 | * @param glrShaderMap A map that maps a shader filename (as a string) to the GlrShader object. 39 | */ 40 | void process(const std::map< std::string, std::unique_ptr >& glrShaderMap); 41 | 42 | virtual const std::string& getName() const; 43 | 44 | std::vector< GlrShader* > getShaders(); 45 | 46 | private: 47 | std::string name_; 48 | std::string source_; 49 | std::string baseDirectory_; 50 | 51 | std::vector< GlrShader* > shaders_; 52 | }; 53 | 54 | } 55 | } 56 | 57 | #endif /* GLRSHADERPROGRAM_H */ 58 | -------------------------------------------------------------------------------- /include/glw/shaders/GlslShader.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GLSLSHADER_H_ 2 | #define GLSLSHADER_H_ 3 | 4 | #include 5 | 6 | #define GLM_FORCE_RADIANS 7 | #include 8 | 9 | #include "IShader.hpp" 10 | 11 | namespace glmd = glm::detail; 12 | 13 | namespace glr 14 | { 15 | namespace shaders 16 | { 17 | 18 | /** 19 | * Class representing a 'glsl' shader. This is a shader that contains the final, processed shader source. 20 | */ 21 | class GlslShader : public IShader 22 | { 23 | public: 24 | GlslShader(std::string source, Type type); 25 | GlslShader(std::string name, std::string source, Type type, std::vector< std::pair > bindings, std::vector< std::pair > locationBindings); 26 | virtual ~GlslShader(); 27 | 28 | virtual void bind(); 29 | virtual IShader::Type getType() const; 30 | virtual GLuint getGlShaderId() const; 31 | virtual IShader::BindingsMap getBindings(); 32 | 33 | void compile(); 34 | 35 | const std::string& getName() const; 36 | 37 | private: 38 | GLuint shaderId_; 39 | 40 | std::string name_; 41 | std::string source_; 42 | Type type_; 43 | 44 | BindingsMap bindings_; 45 | }; 46 | 47 | } 48 | } 49 | 50 | #endif /* GLSLSHADER_H_ */ 51 | -------------------------------------------------------------------------------- /include/glw/shaders/GlslShaderProgram.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GLSLSHADERPROGRAM_H_ 2 | #define GLSLSHADERPROGRAM_H_ 3 | 4 | #include 5 | #include 6 | 7 | #define GLM_FORCE_RADIANS 8 | #include 9 | 10 | #include "IShaderProgram.hpp" 11 | 12 | #include "../IOpenGlDevice.hpp" 13 | 14 | #include "GlslShader.hpp" 15 | 16 | namespace glr 17 | { 18 | namespace shaders 19 | { 20 | 21 | /** 22 | * Class representing a 'glsl' shader program. This is a shader program that holds all of the processed shader source required for this shader program. 23 | */ 24 | class GlslShaderProgram : public IShaderProgram 25 | { 26 | public: 27 | GlslShaderProgram(std::string name, std::vector< std::unique_ptr > shaders, glw::IOpenGlDevice* openGlDevice); 28 | virtual ~GlslShaderProgram(); 29 | 30 | virtual void bind(); 31 | virtual GLuint getGLShaderProgramId() const; 32 | virtual IShader::BindingsMap getBindings(); 33 | void compile(); 34 | 35 | virtual GLint getBindPointByVariableName(const std::string& varName) const; 36 | virtual GLint getBindPointByBindingName(IShader::BindType bindType) const; 37 | 38 | virtual GLint getVertexAttributeLocationByName(const std::string& varName) const; 39 | 40 | const std::string& getName() const; 41 | 42 | virtual void addBindListener(IShaderProgramBindListener* bindListener); 43 | virtual void removeBindListener(IShaderProgramBindListener* bindListener); 44 | void removeAllBindListeners(); 45 | 46 | void unbind(); 47 | static void unbindAll(); 48 | 49 | private: 50 | GLuint programId_; 51 | 52 | std::string name_; 53 | std::vector< std::unique_ptr > shaders_; 54 | glw::IOpenGlDevice* openGlDevice_; 55 | 56 | IShader::BindingsMap bindings_; 57 | 58 | std::vector bindListeners_; 59 | 60 | void generateBindings(); 61 | }; 62 | 63 | } 64 | } 65 | 66 | #endif /* GLSLSHADERPROGRAM_H_ */ 67 | -------------------------------------------------------------------------------- /include/glw/shaders/IShaderProgramBindListener.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ISHADERPROGRAMBINDLISTENER_H_ 2 | #define ISHADERPROGRAMBINDLISTENER_H_ 3 | 4 | #include "IShaderProgram.hpp" 5 | 6 | namespace glr 7 | { 8 | namespace shaders 9 | { 10 | // Forward declaration due to circular dependency IShaderProgram 11 | class IShaderProgram; 12 | 13 | class IShaderProgramBindListener 14 | { 15 | public: 16 | virtual ~IShaderProgramBindListener() 17 | { 18 | } 19 | ; 20 | 21 | virtual void shaderBindCallback(IShaderProgram* shader) = 0; 22 | }; 23 | 24 | } 25 | } 26 | 27 | #endif /* ISHADERPROGRAMBINDLISTENER_H_ */ 28 | -------------------------------------------------------------------------------- /include/glw/shaders/IShaderProgramManager.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ISHADERPROGRAMMANAGER_H_ 2 | #define ISHADERPROGRAMMANAGER_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "IShaderProgram.hpp" 9 | 10 | #include "IShaderProgramBindListener.hpp" 11 | 12 | namespace glr 13 | { 14 | namespace shaders 15 | { 16 | 17 | class IShaderProgramManager 18 | { 19 | public: 20 | virtual ~IShaderProgramManager() 21 | { 22 | } 23 | ; 24 | 25 | virtual IShaderProgram* getShaderProgram(const std::string& filename) const = 0; 26 | 27 | virtual void loadShaderPrograms(const std::string& directory) = 0; 28 | virtual void reloadShaders() = 0; 29 | 30 | /** 31 | * Adds the given IShaderProgramBindListener object to all currently active IShaderProgram objects. It will then store 32 | * the given IShaderProgramBindListener object, and each time a new IShaderProgram manager object is created, it will add 33 | * the given IShaderProgramBindListener object to the newly created IShaderProgram. 34 | * 35 | * @param bindListener The object implementing the IShaderProgramBindListener that we want to add as a bind listener to all new and existing IShaderPrograms. 36 | */ 37 | virtual void addDefaultBindListener(IShaderProgramBindListener* bindListener) = 0; 38 | /** 39 | * Removes the given IShaderProgramBindListener object from all currently active IShaderProgram objects. It will then remove 40 | * the given IShaderProgramBindListener object from the IShaderProgramManager, so that each time a new IShaderProgram manager object is created, it will 41 | * no longer add the given IShaderProgramBindListener object to the newly created IShaderProgram. 42 | * 43 | * @param bindListener The object implementing the IShaderProgramBindListener that we no longer want to add to newly created IShaderProgram objects, and that we want to 44 | * remove as a bind listener to all existing IShaderPrograms. 45 | */ 46 | virtual void removeDefaultBindListener(IShaderProgramBindListener* bindListener) = 0; 47 | }; 48 | 49 | } 50 | } 51 | 52 | #endif /* ISHADERPROGRAMMANAGER_H_ */ 53 | -------------------------------------------------------------------------------- /include/glw/shaders/ShaderProgramManager.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHADERPROGRAMMANAGER_H_ 2 | #define SHADERPROGRAMMANAGER_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include "IShaderProgramManager.hpp" 11 | 12 | #include "GlslShaderProgram.hpp" 13 | #include "GlrShaderProgram.hpp" 14 | #include "GlslShader.hpp" 15 | #include "GlrShader.hpp" 16 | 17 | 18 | namespace glr 19 | { 20 | namespace shaders 21 | { 22 | namespace fs = boost::filesystem; 23 | 24 | class ShaderProgramManager : public IShaderProgramManager 25 | { 26 | public: 27 | ShaderProgramManager(glw::IOpenGlDevice* openGlDevice, bool autoLoad = true, std::vector defaultBindListeners = std::vector()); 28 | virtual ~ShaderProgramManager(); 29 | 30 | virtual IShaderProgram* getShaderProgram(const std::string& name) const; 31 | 32 | virtual void loadShaderPrograms(const std::string& directory); 33 | 34 | virtual void addDefaultBindListener(IShaderProgramBindListener* bindListener); 35 | virtual void removeDefaultBindListener(IShaderProgramBindListener* bindListener); 36 | void removeAllDefaultBindListeners(); 37 | 38 | void loadStandardShaderPrograms(); 39 | 40 | /** 41 | * Unloads and then reloads all of the shaders that have previously been loaded. 42 | * 43 | * Note that this method is destructive - if you have any pointers to shader programs, their contents 44 | * will become undefined after calling this method. 45 | */ 46 | virtual void reloadShaders(); 47 | 48 | void load(const std::string& directory); 49 | void load(fs::path directory, const std::string& baseDirectory = std::string()); 50 | void load(std::vector filenames, const std::string& baseDirectory = std::string()); 51 | void load(std::vector filePaths, const std::string& baseDirectory = std::string()); 52 | void load(std::map dataMap, const std::string& baseDirectory = std::string()); 53 | 54 | private: 55 | std::map< std::string, std::unique_ptr > glrProgramMap_; 56 | std::map< std::string, std::unique_ptr > glrShaderMap_; 57 | std::map< std::string, std::unique_ptr > glslProgramMap_; 58 | 59 | glw::IOpenGlDevice* openGlDevice_; 60 | 61 | std::vector defaultBindListeners_; 62 | 63 | std::unique_ptr convertGlrProgramToGlslProgram(GlrShaderProgram* glrProgram) const; 64 | 65 | // A list of all of the directories that have had their shaders loaded 66 | std::vector< std::string > loadedShaderDirectories_; 67 | 68 | bool isShader(const std::string& source) const; 69 | bool isProgram(const std::string& source) const; 70 | bool isMisc(const std::string& source) const; 71 | 72 | // Used for searching for the 'type' of a shader / shader program file 73 | static std::string prepend_; 74 | static std::string append_; 75 | }; 76 | 77 | } 78 | } 79 | 80 | #endif /* SHADERPROGRAMMANAGER_H_ */ 81 | -------------------------------------------------------------------------------- /include/gui/IGui.hpp: -------------------------------------------------------------------------------- 1 | #ifndef IGUI_H_ 2 | #define IGUI_H_ 3 | 4 | #include 5 | 6 | #include "IGuiComponent.hpp" 7 | 8 | #include "IWindowResizeListener.hpp" 9 | 10 | namespace glr 11 | { 12 | namespace gui 13 | { 14 | 15 | class IGui: public IWindowResizeListener 16 | { 17 | public: 18 | virtual ~IGui() 19 | { 20 | } 21 | ; 22 | 23 | virtual void destroy() = 0; 24 | 25 | virtual void mouseMoved(glm::detail::int32 xPos, glm::detail::int32 yPos) = 0; 26 | virtual void mouseButton(glm::detail::uint32 buttonId, glm::detail::int32 xPos, glm::detail::int32 yPos, bool down, glm::detail::int32 clickCount = 1) = 0; 27 | virtual void mouseWheel(glm::detail::int32 xPos, glm::detail::int32 yPos, glm::detail::int32 xScroll, glm::detail::int32 yScroll) = 0; 28 | 29 | virtual void textEvent(const wchar_t* evt, size_t evtLength) = 0; 30 | virtual void keyEvent(bool pressed, glm::detail::int32 mods, glm::detail::int32 virtualKeyCode, glm::detail::int32 scanCode) = 0; 31 | 32 | virtual void processMessages() = 0; 33 | virtual void update() = 0; 34 | virtual void render() = 0; 35 | virtual IGuiComponent* loadFromFile(std::string filename) = 0; 36 | virtual IGuiComponent* loadFromData(std::string data) = 0; 37 | virtual void release(IGuiComponent*) = 0; 38 | 39 | virtual void windowSizeUpdate(glm::detail::uint32 width, glm::detail::uint32 height) = 0; 40 | }; 41 | 42 | } 43 | } 44 | 45 | #endif /* IGUI_H_ */ 46 | -------------------------------------------------------------------------------- /include/gui/IGuiComponent.hpp: -------------------------------------------------------------------------------- 1 | #ifndef IGUICOMPONENT_H_ 2 | #define IGUICOMPONENT_H_ 3 | 4 | #define GLM_FORCE_RADIANS 5 | #include 6 | 7 | #include "IGuiObject.hpp" 8 | 9 | namespace glr 10 | { 11 | namespace gui 12 | { 13 | 14 | /** 15 | * 16 | */ 17 | class IGuiComponent 18 | { 19 | public: 20 | virtual ~IGuiComponent() 21 | { 22 | } 23 | ; 24 | 25 | /** 26 | * Load the resources necessary for this IGuiComponent object, and also binds 27 | * GUIObject objects and methods. 28 | * 29 | * Note that any GUIObjects created AFTER load() has been called will not have their 30 | * objects / methods bound. 31 | */ 32 | virtual void load() = 0; 33 | 34 | /** 35 | * Frees the resources used by this IGuiComponent object. Any bindings are also removed. 36 | * 37 | * Note that any GUIObjects still existing are not destroyed - you may call load() again after 38 | * unload(), and your GUIObjects will be rebound. 39 | */ 40 | virtual void unload() = 0; 41 | 42 | /** 43 | * Execute the code given by script on the current IGuiComponent object. 44 | * 45 | * @param script The code to execute. 46 | */ 47 | virtual void executeScript(const std::wstring& script) = 0; 48 | 49 | virtual bool isVisible() const = 0; 50 | virtual void setVisible(bool isVisible) = 0; 51 | 52 | /** 53 | * Create a GUIObject that your gui can use to talk to your application. 54 | * 55 | * This is essentially how you 'bind' objects and methods from your gui to your application. 56 | * 57 | * @param name The name associated with this GUIObject 58 | * @return A pointer to an IGuiObject, or nullptr if the GUIObject could not be created successfully. 59 | */ 60 | virtual IGuiObject* createGuiObject(const std::wstring& name) = 0; 61 | 62 | virtual IGuiObject* getGuiObject(const std::wstring& name) const = 0; 63 | }; 64 | 65 | } 66 | } 67 | 68 | #endif /* IGUICOMPONENT_H_ */ 69 | -------------------------------------------------------------------------------- /include/gui/IGuiObject.hpp: -------------------------------------------------------------------------------- 1 | #ifndef IGUIOBJECT_H_ 2 | #define IGUIOBJECT_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | namespace glr 11 | { 12 | namespace gui 13 | { 14 | 15 | class IGuiObject 16 | { 17 | public: 18 | virtual ~IGuiObject() 19 | { 20 | } 21 | ; 22 | 23 | /** 24 | * Adds a lambda callback function to this IGuiObject. The function has the specified name, and it's signature 25 | * is specified by the passed in std::function object. 26 | * 27 | * @param function The actual function to be called. 28 | */ 29 | virtual void addFunction(const std::wstring& name, std::function function) = 0; 30 | virtual void addFunction(const std::wstring& name, std::function function) = 0; 31 | virtual void addFunction(const std::wstring& name, std::function function) = 0; 32 | virtual void addFunction(const std::wstring& name, std::function function) = 0; 33 | virtual void addFunction(const std::wstring& name, std::function function) = 0; 34 | virtual void addFunction(const std::wstring& name, std::function function) = 0; 35 | virtual void addFunction(const std::wstring& name, std::function function) = 0; 36 | 37 | /** 38 | * Adds a lambda callback function to this IGuiObject. The function has the specified name, and it's signature 39 | * is specified by the passed in std::function object. The signature can also have an unspecified number of 40 | * parameters, implemented as boost::any objects. 41 | * 42 | * @param function The actual function to be called. 43 | */ 44 | virtual void addFunction(const std::wstring& name, std::function)> function) = 0; 45 | virtual void addFunction(const std::wstring& name, std::function)> function) = 0; 46 | virtual void addFunction(const std::wstring& name, std::function)> function) = 0; 47 | virtual void addFunction(const std::wstring& name, std::function)> function) = 0; 48 | virtual void addFunction(const std::wstring& name, std::function)> function) = 0; 49 | virtual void addFunction(const std::wstring& name, std::function)> function) = 0; 50 | virtual void addFunction(const std::wstring& name, std::function)> function) = 0; 51 | }; 52 | 53 | } 54 | } 55 | 56 | #endif /* IGUIOBJECT_H_ */ 57 | -------------------------------------------------------------------------------- /include/gui/cef/Gui.hpp: -------------------------------------------------------------------------------- 1 | #ifdef USE_CEF 2 | 3 | #ifndef GUI_H_ 4 | #define GUI_H_ 5 | 6 | #include 7 | #include 8 | 9 | #include "../IGui.hpp" 10 | 11 | #include "GuiComponent.hpp" 12 | 13 | #include "glw/shaders/IShaderProgramManager.hpp" 14 | #include "glw/IOpenGlDevice.hpp" 15 | 16 | namespace glr 17 | { 18 | namespace gui 19 | { 20 | namespace cef 21 | { 22 | 23 | class Gui : public IGui 24 | { 25 | public: 26 | Gui(glw::IOpenGlDevice* openGlDevice, shaders::IShaderProgramManager* shaderProgramManager, glmd::uint32 width, glmd::uint32 height); 27 | virtual ~Gui(); 28 | 29 | virtual void destroy(); 30 | 31 | virtual void mouseMoved(glm::detail::int32 xPos, glm::detail::int32 yPos); 32 | virtual void mouseButton(glm::detail::uint32 buttonId, glm::detail::int32 xPos, glm::detail::int32 yPos, bool down, glm::detail::int32 clickCount = 1); 33 | virtual void mouseWheel(glm::detail::int32 xPos, glm::detail::int32 yPos, glm::detail::int32 xScroll, glm::detail::int32 yScroll); 34 | 35 | virtual void textEvent(const wchar_t* evt, size_t evtLength); 36 | virtual void keyEvent(bool pressed, glm::detail::int32 mods, glm::detail::int32 virtualKeyCode, glm::detail::int32 scanCode); 37 | 38 | virtual void processMessages(); 39 | virtual void update(); 40 | virtual void render(); 41 | virtual IGuiComponent* loadFromFile(std::string filename); 42 | virtual IGuiComponent* loadFromData(std::string data); 43 | virtual void release(IGuiComponent*); 44 | 45 | virtual void windowSizeUpdate(glm::detail::uint32 width, glm::detail::uint32 height); 46 | 47 | private: 48 | std::vector< std::unique_ptr > views_; 49 | 50 | glw::IOpenGlDevice* openGlDevice_; 51 | shaders::IShaderProgramManager* shaderProgramManager_; 52 | 53 | glmd::uint32 width_; 54 | glmd::uint32 height_; 55 | }; 56 | 57 | } 58 | } 59 | } 60 | 61 | #endif /* GUI_H_ */ 62 | 63 | #endif /* USE_CEF */ 64 | -------------------------------------------------------------------------------- /include/gui/cef/RenderHandler.hpp: -------------------------------------------------------------------------------- 1 | #ifdef USE_CEF 2 | 3 | #ifndef RENDERHANDLER_H_ 4 | #define RENDERHANDLER_H_ 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include "glw/IOpenGlDevice.hpp" 12 | 13 | namespace glr 14 | { 15 | namespace gui 16 | { 17 | namespace cef 18 | { 19 | 20 | class RenderHandler : public CefRenderHandler 21 | { 22 | public: 23 | RenderHandler(glm::detail::uint32 webTexture, glm::detail::uint32 width, glm::detail::uint32 height); 24 | 25 | /** 26 | * If the size of the window changes, this method should be called with the new dimensions. 27 | * 28 | * @param width The new width of the window. 29 | * @param height The new height of the window. 30 | */ 31 | void windowSizeUpdate(glm::detail::uint32 width, glm::detail::uint32 height); 32 | 33 | // CefRenderHandler interface 34 | virtual bool GetViewRect(CefRefPtr browser, CefRect& rect); 35 | virtual void OnPaint(CefRefPtr browser, PaintElementType type, const RectList& dirtyRects, const void* buffer, int width, int height); 36 | 37 | private: 38 | glm::detail::uint32 webTexture_; 39 | glm::detail::uint32 width_; 40 | glm::detail::uint32 height_; 41 | 42 | // CefBase interface 43 | // NOTE: Must be at bottom 44 | public: 45 | IMPLEMENT_REFCOUNTING(RenderHandler) 46 | }; 47 | 48 | } 49 | } 50 | } 51 | 52 | #endif /* RENDERHANDLER_H_ */ 53 | 54 | #endif /* USE_CEF */ 55 | -------------------------------------------------------------------------------- /include/models/AnimationData.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ANIMATIONDATA_H_ 2 | #define ANIMATIONDATA_H_ 3 | 4 | #include 5 | #include 6 | 7 | #define GLM_FORCE_RADIANS 8 | #include 9 | 10 | #include "glw/AnimatedBoneNode.hpp" 11 | 12 | namespace glr 13 | { 14 | namespace models 15 | { 16 | 17 | struct AnimationData 18 | { 19 | std::string name; 20 | glm::detail::float64 duration; 21 | glm::detail::float64 ticksPerSecond; 22 | 23 | std::map< std::string, glw::AnimatedBoneNode > animatedBoneNodes; 24 | }; 25 | 26 | } 27 | } 28 | 29 | #endif /* ANIMATIONDATA_H_ */ 30 | -------------------------------------------------------------------------------- /include/models/AnimationSet.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ANIMATIONSET_H_ 2 | #define ANIMATIONSET_H_ 3 | 4 | #include 5 | #include 6 | 7 | #define GLM_FORCE_RADIANS 8 | #include 9 | 10 | #include "glw/BoneNode.hpp" 11 | #include "models/AnimationData.hpp" 12 | 13 | namespace glr 14 | { 15 | namespace models 16 | { 17 | 18 | struct AnimationSet 19 | { 20 | std::string name; 21 | 22 | glw::BoneNode rootBoneNode; 23 | std::map< std::string, AnimationData > animations; 24 | glm::mat4 globalInverseTransformation; 25 | }; 26 | 27 | } 28 | } 29 | 30 | #endif /* ANIMATIONSET_H_ */ 31 | -------------------------------------------------------------------------------- /include/models/AssImpLoader.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ASSIMPLOADER_H_ 2 | #define ASSIMPLOADER_H_ 3 | 4 | #include 5 | 6 | #include "models/IModel.hpp" 7 | 8 | namespace glr 9 | { 10 | namespace models 11 | { 12 | 13 | class AssImpLoader 14 | { 15 | public: 16 | AssImpLoader() 17 | { 18 | } 19 | ; 20 | 21 | virtual ~AssImpLoader() 22 | { 23 | } 24 | ; 25 | 26 | virtual ModelData* loadModel(const std::string path) = 0; 27 | }; 28 | 29 | } 30 | } 31 | 32 | #endif /* ASSIMPLOADER_H_ */ 33 | -------------------------------------------------------------------------------- /include/models/Billboard.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BILLBOARD_H_ 2 | #define BILLBOARD_H_ 3 | 4 | #include "models/IBillboard.hpp" 5 | 6 | #include "glw/IOpenGlDevice.hpp" 7 | 8 | #include "glw/IMesh.hpp" 9 | #include "glw/ITexture.hpp" 10 | #include "glw/IMaterial.hpp" 11 | 12 | namespace glr 13 | { 14 | namespace models 15 | { 16 | 17 | /** 18 | * 19 | */ 20 | class Billboard : public IBillboard 21 | { 22 | public: 23 | Billboard(Id id, std::string name, glw::IMesh* mesh, glw::ITexture* texture, glw::IMaterial* material, glw::IOpenGlDevice* openGlDevice); 24 | virtual ~Billboard(); 25 | 26 | virtual const Id& getId() const; 27 | virtual const std::string& getName() const; 28 | 29 | virtual void render(shaders::IShaderProgram& shader); 30 | 31 | private: 32 | Id id_; 33 | std::string name_; 34 | 35 | glw::IMesh* mesh_; 36 | glw::ITexture* texture_; 37 | glw::IMaterial* material_; 38 | 39 | glw::IOpenGlDevice* openGlDevice_; 40 | }; 41 | 42 | } 43 | } 44 | 45 | #endif /* BILLBOARD_H_ */ 46 | -------------------------------------------------------------------------------- /include/models/BillboardManager.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BILLBOARDMANAGER_H_ 2 | #define BILLBOARDMANAGER_H_ 3 | 4 | #include 5 | 6 | #include "models/IBillboardManager.hpp" 7 | 8 | #include "glw/IOpenGlDevice.hpp" 9 | 10 | #include "IdManager.hpp" 11 | 12 | namespace glr 13 | { 14 | namespace models 15 | { 16 | 17 | /** 18 | * 19 | */ 20 | class BillboardManager : public IBillboardManager 21 | { 22 | public: 23 | BillboardManager(glw::IOpenGlDevice* openGlDevice); 24 | virtual ~BillboardManager(); 25 | 26 | virtual IBillboard* createBillboard(const std::string& name, glw::IMesh* mesh, glw::ITexture* texture, glw::IMaterial* material); 27 | 28 | virtual IBillboard* getBillboard(Id id) const; 29 | virtual IBillboard* getBillboard(const std::string& name) const; 30 | 31 | virtual void destroyBillboard(Id id); 32 | virtual void destroyBillboard(const std::string& name); 33 | virtual void destroyBillboard(IBillboard* billboard); 34 | 35 | private: 36 | glw::IOpenGlDevice* openGlDevice_; 37 | 38 | std::vector< std::unique_ptr > billboards_; 39 | 40 | IdManager idManager_; 41 | 42 | mutable std::mutex accessMutex_; 43 | }; 44 | 45 | } 46 | } 47 | 48 | #endif /* BILLBOARDMANAGER_H_ */ 49 | -------------------------------------------------------------------------------- /include/models/Constants.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CONSTANTS_H_ 2 | #define CONSTANTS_H_ 3 | 4 | namespace glr 5 | { 6 | namespace models 7 | { 8 | 9 | class Constants 10 | { 11 | public: 12 | static const std::string MODEL_DIRECTORY; 13 | }; 14 | 15 | const std::string Constants::MODEL_DIRECTORY = std::string("/home/jarrett/projects/chisholmsoft/models/"); 16 | 17 | } 18 | } 19 | 20 | #endif /* CONSTANTS_H_ */ 21 | -------------------------------------------------------------------------------- /include/models/IBillboard.hpp: -------------------------------------------------------------------------------- 1 | #ifndef IBILLBOARD_H_ 2 | #define IBILLBOARD_H_ 3 | 4 | #define GLM_FORCE_RADIANS 5 | #include 6 | 7 | #include "Id.hpp" 8 | 9 | #include "IRenderable.hpp" 10 | #include "glw/shaders/IShaderProgram.hpp" 11 | 12 | #include "glw/IMesh.hpp" 13 | #include "glw/ITexture.hpp" 14 | #include "glw/IMaterial.hpp" 15 | 16 | namespace glr 17 | { 18 | namespace models 19 | { 20 | 21 | /** 22 | * 23 | */ 24 | class IBillboard : public virtual IRenderable 25 | { 26 | public: 27 | virtual ~IBillboard() 28 | { 29 | } 30 | ; 31 | 32 | /** 33 | * Get the id of this model. 34 | * 35 | * @return The id of this model. 36 | */ 37 | virtual const Id& getId() const = 0; 38 | 39 | /** 40 | * Get the name of this model. 41 | * 42 | * @return The name of this model. 43 | */ 44 | virtual const std::string& getName() const = 0; 45 | }; 46 | 47 | } 48 | } 49 | 50 | #endif /* IBILLBOARD_H_ */ 51 | -------------------------------------------------------------------------------- /include/models/IRenderable.hpp: -------------------------------------------------------------------------------- 1 | #ifndef IRENDERABLE_H_ 2 | #define IRENDERABLE_H_ 3 | 4 | #include "glw/shaders/IShaderProgram.hpp" 5 | 6 | namespace glr 7 | { 8 | namespace models 9 | { 10 | 11 | class IRenderable 12 | { 13 | public: 14 | virtual ~IRenderable() 15 | { 16 | } 17 | ; 18 | 19 | /** 20 | * Render this object to the scene using the provided shader. 21 | * 22 | * @param shader The shader to use to render this object to the scene. 23 | */ 24 | virtual void render(shaders::IShaderProgram& shader) = 0; 25 | }; 26 | 27 | } 28 | } 29 | 30 | #endif /* IRENDERABLE_H_ */ 31 | -------------------------------------------------------------------------------- /include/models/MaterialData.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MATERIALDATA_H_ 2 | #define MATERIALDATA_H_ 3 | 4 | #include 5 | 6 | #define GLM_FORCE_RADIANS 7 | #include 8 | 9 | #include "glw/VertexBoneData.hpp" 10 | 11 | namespace glr 12 | { 13 | namespace models 14 | { 15 | 16 | struct MaterialData 17 | { 18 | std::string name; 19 | GLenum fill_mode; 20 | glm::vec4 ambient; 21 | glm::vec4 diffuse; 22 | glm::vec4 specular; 23 | glm::vec4 emission; 24 | glm::detail::float32 shininess; 25 | glm::detail::float32 strength; 26 | }; 27 | 28 | } 29 | } 30 | 31 | #endif /* MATERIALDATA_H_ */ 32 | -------------------------------------------------------------------------------- /include/models/MeshData.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MESHDATA_H_ 2 | #define MESHDATA_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include "glw/VertexBoneData.hpp" 8 | 9 | namespace glr 10 | { 11 | namespace models 12 | { 13 | 14 | struct MeshData 15 | { 16 | std::string name; 17 | std::vector< glm::vec3 > vertices; 18 | std::vector< glm::vec3 > normals; 19 | std::vector< glm::vec2 > textureCoordinates; 20 | std::vector< glm::vec4 > colors; 21 | std::vector< glw::VertexBoneData > bones; 22 | }; 23 | 24 | } 25 | } 26 | 27 | #endif /* MESHDATA_H_ */ 28 | -------------------------------------------------------------------------------- /include/models/Model.inl: -------------------------------------------------------------------------------- 1 | namespace glr 2 | { 3 | namespace models 4 | { 5 | 6 | template void Model::serialize(Archive& ar, const unsigned int version) 7 | { 8 | boost::serialization::split_member(ar, *this, version); 9 | } 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /include/models/ModelData.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MODELDATA_H_ 2 | #define MODELDATA_H_ 3 | 4 | #include "models/MeshData.hpp" 5 | #include "models/MaterialData.hpp" 6 | #include "models/TextureData.hpp" 7 | #include "glw/BoneData.hpp" 8 | 9 | namespace glr 10 | { 11 | namespace models 12 | { 13 | 14 | struct ModelData 15 | { 16 | MeshData meshData; 17 | MaterialData materialData; 18 | TextureData textureData; 19 | glw::BoneData boneData; 20 | }; 21 | 22 | } 23 | } 24 | 25 | #endif /* MODELDATA_H_ */ 26 | -------------------------------------------------------------------------------- /include/models/ModelManager.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MODELMANAGER_H_ 2 | #define MODELMANAGER_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | // assimp include files. These three are usually needed. 12 | #include 13 | #include 14 | #include 15 | 16 | #include "models/IModelManager.hpp" 17 | 18 | #include "IdManager.hpp" 19 | 20 | #include "serialize/SplitMember.hpp" 21 | 22 | namespace glr 23 | { 24 | 25 | namespace glw 26 | { 27 | class IOpenGlDevice; 28 | } 29 | 30 | namespace models 31 | { 32 | 33 | class ModelLoader; 34 | class Model; 35 | 36 | class ModelManager : public IModelManager 37 | { 38 | public: 39 | ModelManager(glw::IOpenGlDevice* openGlDevice); 40 | virtual ~ModelManager(); 41 | 42 | virtual IModel* getModelTemplate(Id id) const; 43 | virtual IModel* getModelTemplate(const std::string& name) const; 44 | 45 | virtual void loadModel(const std::string& name, const std::string& filename, bool initialize = true); 46 | 47 | virtual void destroyModelTemplate(Id id); 48 | virtual void destroyModelTemplate(const std::string& name); 49 | virtual void destroyModelTemplate(IModel* model); 50 | 51 | virtual IModel* createInstance(const std::string& name); 52 | 53 | virtual void destroyInstance(Id id); 54 | virtual void destroyInstance(IModel* model); 55 | 56 | virtual IModel* getInstance(Id id) const; 57 | 58 | virtual void serialize(const std::string& filename); 59 | virtual void serialize(serialize::TextOutArchive& outArchive); 60 | 61 | virtual void deserialize(const std::string& filename); 62 | virtual void deserialize(serialize::TextInArchive& inArchive); 63 | 64 | private: 65 | /** 66 | * Required for serialization. 67 | */ 68 | ModelManager(); 69 | 70 | glw::IOpenGlDevice* openGlDevice_; 71 | 72 | aiLogStream stream; 73 | 74 | std::vector< std::unique_ptr > models_; 75 | std::vector< std::unique_ptr > modelInstances_; 76 | 77 | std::unique_ptr modelLoader_; 78 | 79 | IdManager idManager_; 80 | 81 | mutable std::recursive_mutex accessMutex_; 82 | 83 | Model* getModel(Id id) const; 84 | Model* getModel(const std::string& name) const; 85 | 86 | friend class boost::serialization::access; 87 | 88 | template void serialize(Archive& ar, const unsigned int version); 89 | // Need to do these because boost serialization doesn't have a standard implementation for std::unique_ptr 90 | // Apparently, std::unique_ptr will have a serializable implementation in boost 1.56 91 | // TODO: Implement one myself? 92 | template void save(Archive & ar, const unsigned int version) const; 93 | template void load(Archive & ar, const unsigned int version); 94 | }; 95 | 96 | } 97 | } 98 | 99 | #endif /* MODELMANAGER_H_ */ 100 | -------------------------------------------------------------------------------- /include/models/TextureData.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TEXTUREDATA_H_ 2 | #define TEXTUREDATA_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include "glw/TextureSettings.hpp" 8 | #include "glw/VertexBoneData.hpp" 9 | 10 | namespace glr 11 | { 12 | namespace models 13 | { 14 | 15 | struct TextureData 16 | { 17 | std::string filename; 18 | glw::TextureSettings settings; 19 | }; 20 | 21 | } 22 | } 23 | 24 | #endif /* TEXTUREDATA_H_ */ 25 | -------------------------------------------------------------------------------- /include/serialize/ITextSerializable.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ITEXTSERIALIZABLE_H_ 2 | #define ITEXTSERIALIZABLE_H_ 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include "Serialization.hpp" 9 | #include "std/Vector.hpp" 10 | 11 | #include "serialize/glm/Vec2.hpp" 12 | #include "serialize/glm/Vec3.hpp" 13 | #include "serialize/glm/Vec4.hpp" 14 | #include "serialize/glm/Mat4.hpp" 15 | #include "serialize/glm/Quat.hpp" 16 | 17 | #include "TextOutArchive.hpp" 18 | #include "TextInArchive.hpp" 19 | 20 | namespace glr 21 | { 22 | namespace serialize 23 | { 24 | 25 | /** 26 | * 27 | */ 28 | class ITextSerializable 29 | { 30 | public: 31 | virtual ~ITextSerializable() 32 | { 33 | } 34 | ; 35 | 36 | /** 37 | * Serialize the object to the provided filename. 38 | * 39 | * **Not Thread Safe**: This method is *not* safe to call in a multi-threaded environment. When you are calling this 40 | * method, no other threads should be accessing this object. 41 | */ 42 | virtual void serialize(const std::string& filename) = 0; 43 | 44 | /** 45 | * Serialize the object to the provided archive. 46 | * 47 | * **Not Thread Safe**: This method is *not* safe to call in a multi-threaded environment. When you are calling this 48 | * method, no other threads should be accessing this object. 49 | */ 50 | virtual void serialize(TextOutArchive& outArchive) = 0; 51 | 52 | /** 53 | * Deserializes the object from the provided filename. 54 | * 55 | * **Not Thread Safe**: This method is *not* safe to call in a multi-threaded environment. When you are calling this 56 | * method, no other threads should be accessing this object. 57 | */ 58 | virtual void deserialize(const std::string& filename) = 0; 59 | 60 | /** 61 | * Deserializes the object from the provided archive. 62 | * 63 | * **Not Thread Safe**: This method is *not* safe to call in a multi-threaded environment. When you are calling this 64 | * method, no other threads should be accessing this object. 65 | */ 66 | virtual void deserialize(TextInArchive& inArchive) = 0; 67 | }; 68 | 69 | } 70 | } 71 | 72 | #endif /* ITEXTSERIALIZABLE_H_ */ 73 | -------------------------------------------------------------------------------- /include/serialize/Serialization.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /include/serialize/SplitMember.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /include/serialize/TextInArchive.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TEXTINARCHIVE_H_ 2 | #define TEXTINARCHIVE_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace glr 10 | { 11 | namespace serialize 12 | { 13 | 14 | /** 15 | * 16 | */ 17 | class TextInArchive : public boost::archive::text_iarchive 18 | { 19 | public: 20 | TextInArchive(std::ifstream& ifstream); 21 | virtual ~TextInArchive(); 22 | }; 23 | 24 | } 25 | } 26 | 27 | #endif /* TEXTINARCHIVE_H_ */ 28 | -------------------------------------------------------------------------------- /include/serialize/TextOutArchive.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TEXTOUTARCHIVE_H_ 2 | #define TEXTOUTARCHIVE_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace glr 10 | { 11 | namespace serialize 12 | { 13 | 14 | /** 15 | * 16 | */ 17 | class TextOutArchive : public boost::archive::text_oarchive 18 | { 19 | public: 20 | TextOutArchive(std::ofstream& ofstream); 21 | virtual ~TextOutArchive(); 22 | }; 23 | 24 | } 25 | } 26 | 27 | #endif /* TEXTOUTARCHIVE_H_ */ 28 | -------------------------------------------------------------------------------- /include/serialize/glm/IVec4.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GLMIVEC4SERIALIZE_H_ 2 | #define GLMIVEC4SERIALIZE_H_ 3 | 4 | #include "serialize/Serialization.hpp" 5 | #include "serialize/std/Vector.hpp" 6 | 7 | #define GLM_FORCE_RADIANS 8 | #include 9 | 10 | BOOST_SERIALIZATION_SPLIT_FREE(glm::ivec4) 11 | 12 | namespace boost 13 | { 14 | namespace serialization 15 | { 16 | 17 | template void save(Archive& ar, const glm::ivec4& v, unsigned int version) 18 | { 19 | ar & v.w & v.x & v.y & v.z; 20 | } 21 | 22 | template void load(Archive& ar, glm::ivec4& v, unsigned int version) 23 | { 24 | ar & v.w & v.x & v.y & v.z; 25 | } 26 | 27 | } 28 | } 29 | 30 | #endif /* GLMIVEC4SERIALIZE_H_ */ 31 | -------------------------------------------------------------------------------- /include/serialize/glm/Mat4.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GLMMAT4SERIALIZE_H_ 2 | #define GLMMAT4SERIALIZE_H_ 3 | 4 | #include "serialize/Serialization.hpp" 5 | #include "serialize/std/Vector.hpp" 6 | 7 | #define GLM_FORCE_RADIANS 8 | #include 9 | 10 | BOOST_SERIALIZATION_SPLIT_FREE(glm::mat4) 11 | 12 | namespace boost 13 | { 14 | namespace serialization 15 | { 16 | 17 | template void save(Archive& ar, const glm::mat4& m, unsigned int version) 18 | { 19 | for (glm::detail::uint32 i=0; i < 4u; i++) 20 | for (glm::detail::uint32 j=0; j < 4u; j++) 21 | ar & m[i][j]; 22 | } 23 | 24 | template void load(Archive& ar, glm::mat4& m, unsigned int version) 25 | { 26 | for (glm::detail::uint32 i=0; i < 4u; i++) 27 | for (glm::detail::uint32 j=0; j < 4u; j++) 28 | ar & m[i][j]; 29 | } 30 | 31 | } 32 | } 33 | 34 | #endif /* GLMMAT4SERIALIZE_H_ */ 35 | -------------------------------------------------------------------------------- /include/serialize/glm/Quat.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GLMQUATSERIALIZE_H_ 2 | #define GLMQUATSERIALIZE_H_ 3 | 4 | #include "serialize/Serialization.hpp" 5 | #include "serialize/std/Vector.hpp" 6 | 7 | #define GLM_FORCE_RADIANS 8 | #include 9 | #include "glm/gtc/quaternion.hpp" 10 | 11 | BOOST_SERIALIZATION_SPLIT_FREE(glm::quat) 12 | 13 | namespace boost 14 | { 15 | namespace serialization 16 | { 17 | 18 | template void save(Archive& ar, const glm::quat& q, unsigned int version) 19 | { 20 | ar & q.x & q.y & q.z & q.w; 21 | } 22 | 23 | template void load(Archive& ar, glm::quat& q, unsigned int version) 24 | { 25 | ar & q.x & q.y & q.z & q.w; 26 | } 27 | 28 | } 29 | } 30 | 31 | #endif /* GLMQUATSERIALIZE_H_ */ 32 | -------------------------------------------------------------------------------- /include/serialize/glm/Vec2.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GLMVEC2SERIALIZE_H_ 2 | #define GLMVEC2SERIALIZE_H_ 3 | 4 | #include "serialize/Serialization.hpp" 5 | #include "serialize/std/Vector.hpp" 6 | 7 | #define GLM_FORCE_RADIANS 8 | #include 9 | 10 | BOOST_SERIALIZATION_SPLIT_FREE(glm::vec2) 11 | 12 | namespace boost 13 | { 14 | namespace serialization 15 | { 16 | 17 | template void save(Archive& ar, const glm::vec2& v, unsigned int version) 18 | { 19 | ar & v.x & v.y; 20 | } 21 | 22 | template void load(Archive& ar, glm::vec2& v, unsigned int version) 23 | { 24 | ar & v.x & v.y; 25 | } 26 | 27 | } 28 | } 29 | 30 | #endif /* GLMVEC2SERIALIZE_H_ */ 31 | -------------------------------------------------------------------------------- /include/serialize/glm/Vec3.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GLMVEC3SERIALIZE_H_ 2 | #define GLMVEC3SERIALIZE_H_ 3 | 4 | #include "serialize/Serialization.hpp" 5 | #include "serialize/std/Vector.hpp" 6 | 7 | #define GLM_FORCE_RADIANS 8 | #include 9 | 10 | BOOST_SERIALIZATION_SPLIT_FREE(glm::vec3) 11 | 12 | namespace boost 13 | { 14 | namespace serialization 15 | { 16 | 17 | template void save(Archive& ar, const glm::vec3& v, unsigned int version) 18 | { 19 | ar & v.x & v.y & v.z; 20 | } 21 | 22 | template void load(Archive& ar, glm::vec3& v, unsigned int version) 23 | { 24 | ar & v.x & v.y & v.z; 25 | } 26 | 27 | } 28 | } 29 | 30 | #endif /* GLMVEC3SERIALIZE_H_ */ 31 | -------------------------------------------------------------------------------- /include/serialize/glm/Vec4.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GLMVEC4SERIALIZE_H_ 2 | #define GLMVEC4SERIALIZE_H_ 3 | 4 | #include "serialize/Serialization.hpp" 5 | #include "serialize/std/Vector.hpp" 6 | 7 | #define GLM_FORCE_RADIANS 8 | #include 9 | 10 | BOOST_SERIALIZATION_SPLIT_FREE(glm::vec4) 11 | 12 | namespace boost 13 | { 14 | namespace serialization 15 | { 16 | 17 | template void save(Archive& ar, const glm::vec4& v, unsigned int version) 18 | { 19 | ar & v.w & v.x & v.y & v.z; 20 | } 21 | 22 | template void load(Archive& ar, glm::vec4& v, unsigned int version) 23 | { 24 | ar & v.w & v.x & v.y & v.z; 25 | } 26 | 27 | } 28 | } 29 | 30 | #endif /* GLMVEC4SERIALIZE_H_ */ 31 | -------------------------------------------------------------------------------- /include/serialize/std/Map.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /include/serialize/std/Vector.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /include/terrain/Constants.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TERRAIN_CONSTANTS_H_ 2 | #define TERRAIN_CONSTANTS_H_ 3 | 4 | namespace glr 5 | { 6 | namespace terrain 7 | { 8 | namespace constants 9 | { 10 | 11 | //---- Terrain constants ----// 12 | static const glm::detail::float32 RESOLUTION = 1.0f; 13 | static const glm::detail::int32 CHUNK_SIZE = 16; 14 | static const glm::detail::int32 SIZE = (glm::detail::int32)(CHUNK_SIZE / RESOLUTION); 15 | static const glm::detail::int32 MAX_LENGTH = 256; 16 | static const glm::detail::int32 MAX_WIDTH = 256; 17 | static const glm::detail::int32 MAX_HEIGHT = 128; 18 | 19 | //---- Noise generation constants ----// 20 | // The offset is the index where the smoothing algorithm would start smoothing the noise field from 21 | static const glm::detail::int32 POINT_FIELD_OFFSET = 1; 22 | // The overset is how many 'extra' dimensions to add to the density field 23 | static const glm::detail::int32 POINT_FIELD_OVERSET = 3; 24 | 25 | //---- Dual Contouring algorithm constants ----// 26 | static const glm::detail::float32 TOLERANCE_DENSITY = 1e-3f; 27 | static const glm::detail::float32 EPSILON_DENSITY = 1e-4f; 28 | static const glm::detail::float32 TOLERANCE_COORD = 1e-5f; 29 | static const glm::detail::float32 EPSILON_VALUE = 0.001f; 30 | 31 | } 32 | } 33 | } 34 | 35 | #endif /* TERRAIN_CONSTANTS_H_ */ 36 | -------------------------------------------------------------------------------- /include/terrain/IFieldFunction.hpp: -------------------------------------------------------------------------------- 1 | #ifndef IFIELDFUNCTION_H_ 2 | #define IFIELDFUNCTION_H_ 3 | 4 | #define GLM_FORCE_RADIANS 5 | #include 6 | 7 | namespace glr 8 | { 9 | namespace terrain 10 | { 11 | 12 | class IFieldFunction 13 | { 14 | public: 15 | virtual ~IFieldFunction() 16 | { 17 | } 18 | ; 19 | 20 | /** 21 | * 22 | */ 23 | virtual glm::detail::float32 getNoise(glm::detail::float32 x, glm::detail::float32 y, glm::detail::float32 z) = 0; 24 | }; 25 | 26 | } 27 | } 28 | 29 | #endif /* IFIELDFUNCTION_H_ */ 30 | -------------------------------------------------------------------------------- /include/terrain/ITerrain.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ITERRAIN_H_ 2 | #define ITERRAIN_H_ 3 | 4 | #define GLM_FORCE_RADIANS 5 | #include 6 | 7 | #include "ISceneNode.hpp" 8 | #include "TerrainSettings.hpp" 9 | 10 | namespace glr 11 | { 12 | 13 | namespace models 14 | { 15 | class IModel; 16 | } 17 | 18 | namespace terrain 19 | { 20 | 21 | struct Point 22 | { 23 | glmd::float32 density; 24 | glm::vec3 pos; 25 | }; 26 | 27 | struct Block 28 | { 29 | Point points[2][2][2]; 30 | glmd::int32 index; 31 | glm::vec3 meshPoint; 32 | glm::vec3 meshPointNormal; 33 | }; 34 | 35 | class ITerrain : public virtual ISceneNode 36 | { 37 | public: 38 | virtual ~ITerrain() 39 | { 40 | } 41 | ; 42 | 43 | /** 44 | * Will render the terrain to scene. 45 | * 46 | * **Not Thread Safe**: This method is *not* safe to call in a multi-threaded environment, and should only be called from the 47 | * OpenGL thread. 48 | */ 49 | virtual void render() = 0; 50 | 51 | /** 52 | * Tells us whether this terrain has changes that need to be passed to OpenGL. 53 | */ 54 | virtual bool isDirty() const = 0; 55 | virtual void setIsDirty(bool isDirty) = 0; 56 | 57 | /** 58 | * Will update this terrain. 59 | * 60 | * **Not Thread Safe**: This method is *not* safe to call in a multi-threaded environment, and should only be called from the 61 | * OpenGL thread. 62 | */ 63 | virtual void update() = 0; 64 | 65 | virtual void generate(TerrainSettings settings = TerrainSettings()) = 0; 66 | 67 | virtual bool isEmptyOrSolid() const = 0; 68 | 69 | /** 70 | * Will prepare or update all of the graphics for this terrain chunk. After this function returns, the terrain will be ready to 71 | * be rendered on the screen. 72 | * 73 | * **Not Thread Safe**: This method is *not* safe to call in a multi-threaded environment, and should only be called from the 74 | * OpenGL thread. 75 | */ 76 | virtual void prepareOrUpdateGraphics() = 0; 77 | 78 | /** 79 | * Will set and update the level of detail of the terrain. If the lod passed in is the same as the current lod, this method 80 | * will do nothing. 81 | * 82 | * If the level of detail is different than the current value, this method will do any preparation necessary for the lod change, and 83 | * then mark the terrain as dirty. 84 | */ 85 | virtual void updateLod(LevelOfDetail lod) = 0; 86 | 87 | /** 88 | * Returns the current lod value. 89 | * 90 | * @return The current level of detail. 91 | */ 92 | virtual LevelOfDetail getLod() const = 0; 93 | 94 | virtual glm::detail::int32 getGridX() const = 0; 95 | virtual glm::detail::int32 getGridY() const = 0; 96 | virtual glm::detail::int32 getGridZ() const = 0; 97 | 98 | /** 99 | * Returns the model associated with this terrain. 100 | * 101 | * @return The model associated with this terrain. 102 | */ 103 | virtual models::IModel* getModel() const = 0; 104 | }; 105 | 106 | } 107 | } 108 | 109 | #endif /* ITERRAIN_H_ */ 110 | -------------------------------------------------------------------------------- /include/terrain/ITerrainManagerEventListener.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ITERRAINMANAGEREVENTLISTENER_H_ 2 | #define ITERRAINMANAGEREVENTLISTENER_H_ 3 | 4 | #include "ITerrain.hpp" 5 | 6 | namespace glr 7 | { 8 | namespace terrain 9 | { 10 | 11 | class ITerrainManagerEventListener 12 | { 13 | public: 14 | virtual ~ITerrainManagerEventListener() 15 | { 16 | } 17 | ; 18 | 19 | /** 20 | * Is called when a new terrain is added to the Terrain Manager. 21 | * 22 | * @param terrain The new terrain that was added. 23 | */ 24 | virtual void terrainAdded(ITerrain* terrain) = 0; 25 | 26 | /** 27 | * Is called when a terrain is removed from the Terrain Manager. 28 | * 29 | * @param terrain The terrain that was removed. 30 | */ 31 | virtual void terrainRemoved(ITerrain* terrain) = 0; 32 | }; 33 | 34 | } 35 | } 36 | 37 | #endif /* ITERRAINMANAGEREVENTLISTENER_H_ */ 38 | -------------------------------------------------------------------------------- /include/terrain/IVoxelChunkMeshGenerator.hpp: -------------------------------------------------------------------------------- 1 | #ifndef IVOXELCHUNKMESHGENERATOR_H_ 2 | #define IVOXELCHUNKMESHGENERATOR_H_ 3 | 4 | #include "IFieldFunction.hpp" 5 | #include "VoxelChunk.hpp" 6 | 7 | namespace glr 8 | { 9 | namespace terrain 10 | { 11 | 12 | class IVoxelChunkMeshGenerator 13 | { 14 | public: 15 | 16 | /** 17 | * Will generate a mesh of the provided VoxelChunk, and put the data in the provided vectors (vertices, normals, and textureBlendingValues). 18 | */ 19 | virtual void generateMesh(VoxelChunk& chunk, glm::detail::int32 length, glm::detail::int32 width, glm::detail::int32 height, std::vector& vertices, std::vector& normals, std::vector& textureBlendingValues) const = 0; 20 | }; 21 | 22 | } 23 | } 24 | 25 | #endif /* IVOXELCHUNKMESHGENERATOR_H_ */ 26 | -------------------------------------------------------------------------------- /include/terrain/Interp.hpp: -------------------------------------------------------------------------------- 1 | double ffn_bilinear(double, double, const double*); //Interpolation on FFN-like grid (hardcoded) 2 | 3 | 4 | 5 | 6 | /* 2D interpolation */ 7 | double bilinear_interp (double, double, const double*, // X, Y, *TABLE 8 | const int, const int, // NX, NY 9 | const double, const double, // X_MIN, X_MAX 10 | const double, const double, // Y_MIN, Y_MAX 11 | const int, const double); // OUT_OF_DOMAIN_FLAG, OUT_OF_DOMAIN_VALUE 12 | 13 | 14 | /* 2D interpolation on non-equidistant (user-supplied) grid*/ 15 | double 16 | bilinear_interp_arbitrary_grid(double , double , double*, // X, Y, *TABLE 17 | const double*, const int, // X_tbl, NX 18 | const double*, const int, // Y_tbl, NY 19 | const int, const double); // OUT_OF_DOMAIN_FLAG, OUT_OF_DOMAIN_VALUE); 20 | 21 | 22 | 23 | /* 3D interpolation on equidistant grid*/ 24 | double trilinear_interp (double, double, double, const double*, // X, Y, Z, *TABLE 25 | const int, const int, const int, // NX, NY, NZ 26 | const double, const double, // X_MIN, Y_MAX 27 | const double, const double, // Y_MIN, Y_MAX 28 | const double, const double, // Z_MIN, Z_MAX 29 | const int, const double); // OUT_OF_DOMAIN_FLAG, OUT_OF_DOMAIN_VALUE); 30 | 31 | /* 3D interpolation on non-equidistant (user-supplied) grid*/ 32 | double 33 | trilinear_interp_arbitrary_grid(double , double , double , double*, // X, Y, Z, *TABLE 34 | const double*, const int, // X_tbl, NX 35 | const double*, const int, // Y_tbl, NY 36 | const double*, const int, // Z_tbl, NZ 37 | const int, const double); // OUT_OF_DOMAIN_FLAG, OUT_OF_DOMAIN_VALUE); 38 | 39 | 40 | -------------------------------------------------------------------------------- /include/terrain/Interpolation.hpp: -------------------------------------------------------------------------------- 1 | #include "Interp.hpp" 2 | 3 | /* bilinear interpolation inside unit square */ 4 | inline double bilinear_interp_unit_square 5 | (double, double, double, double, double, double); 6 | 7 | /* trilinear interpolation inside unit cube */ 8 | inline double trilinear_interp_unit_cube 9 | (double , double , double , double , double , double , double , double , double , double , double ); 10 | 11 | double 12 | trilinear_interp(double X, double Y, double Z, const double *tbl, 13 | const int N_X, const int N_Y, const int N_Z, 14 | const double X_MIN, const double X_MAX, 15 | const double Y_MIN, const double Y_MAX, 16 | const double Z_MIN, const double Z_MAX, 17 | const int OUT_OF_DOMAIN, const double OUT_OF_DOMAIN_VALUE); 18 | -------------------------------------------------------------------------------- /include/terrain/Terrain.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TERRAIN_H_ 2 | #define TERRAIN_H_ 3 | 4 | #include 5 | 6 | #include "ITerrain.hpp" 7 | #include "BasicSceneNode.hpp" 8 | 9 | namespace glr 10 | { 11 | namespace terrain 12 | { 13 | 14 | class TerrainMesh; 15 | class IVoxelChunkMeshGenerator; 16 | 17 | class Terrain : public virtual ITerrain, public BasicSceneNode 18 | { 19 | public: 20 | Terrain(Id id, glw::IOpenGlDevice* openGlDevice, glmd::int32 gridX, glmd::int32 gridY, glmd::int32 gridZ, 21 | glmd::int32 length, glmd::int32 width, glmd::int32 height, IFieldFunction* fieldFunction, IVoxelChunkMeshGenerator* voxelChunkMeshGenerator); 22 | Terrain(Id id, std::string name, glw::IOpenGlDevice* openGlDevice, glmd::int32 gridX, glmd::int32 gridY, glmd::int32 gridZ); 23 | Terrain(Id id, std::string name, glm::vec3& position, const glm::quat& orientation, glm::vec3& scale, glw::IOpenGlDevice* openGlDevice, 24 | glmd::int32 gridX, glmd::int32 gridY, glmd::int32 gridZ); 25 | Terrain(Id id, const Terrain& other); 26 | virtual ~Terrain(); 27 | 28 | virtual void render(); 29 | virtual bool isDirty() const; 30 | virtual void setIsDirty(bool isDirty); 31 | 32 | virtual void update(); 33 | 34 | virtual void updateLod(LevelOfDetail lod); 35 | virtual LevelOfDetail getLod() const; 36 | 37 | virtual void generate(TerrainSettings settings = TerrainSettings()); 38 | 39 | void freeVideoMemory(); 40 | 41 | bool isActive() const; 42 | void setIsActive( bool isActive ); 43 | 44 | virtual bool isEmptyOrSolid() const; 45 | 46 | virtual glm::detail::int32 getGridX() const; 47 | virtual glm::detail::int32 getGridY() const; 48 | virtual glm::detail::int32 getGridZ() const; 49 | 50 | // TODO: Something other than this? 51 | void setMesh(std::unique_ptr mesh); 52 | void setModel(std::unique_ptr model); 53 | 54 | TerrainMesh* getData(); 55 | virtual models::IModel* getModel() const; 56 | 57 | virtual void prepareOrUpdateGraphics(); 58 | void initializeShaderLocations(); 59 | 60 | private: 61 | glmd::int32 gridX_; 62 | glmd::int32 gridY_; 63 | glmd::int32 gridZ_; 64 | glmd::int32 length_; 65 | glmd::int32 width_; 66 | glmd::int32 height_; 67 | 68 | IFieldFunction* fieldFunction_; 69 | IVoxelChunkMeshGenerator* voxelChunkMeshGenerator_; 70 | 71 | std::atomic isActive_; 72 | std::atomic isEmptyOrSolid_; 73 | LevelOfDetail levelOfDetail_; 74 | 75 | std::atomic isDirty_; 76 | 77 | // The terrain object manages the memory for it's mesh 78 | std::unique_ptr meshData_; 79 | // The terrain object manages the memory for it's model 80 | std::unique_ptr modelPtr_; 81 | 82 | glm::detail::uint32 vaoId_; 83 | glm::detail::uint32 vboId_; 84 | 85 | std::vector texBlendingValues_; 86 | 87 | void initialize(); 88 | void initialize(glmd::int32 x, glmd::int32 y); 89 | }; 90 | 91 | } 92 | } 93 | 94 | #endif /* TERRAIN_H_ */ 95 | -------------------------------------------------------------------------------- /include/terrain/Terrain.md: -------------------------------------------------------------------------------- 1 | Terrain 2 | ======= 3 | 4 | Noise Generator 5 | --------------- 6 | GLR uses density fields to generate terrain, and uses simplex noise to populate the density fields. 7 | 8 | Smoothing the Density Field 9 | --------------------------- 10 | Each density 'point' is a value between -1.0 and 1.0, where anything above 0 is considered 'air', and anything 11 | below 0 is considered 'solid'. There is an [Isosurface](http://en.wikipedia.org/wiki/Isosurface) that exists where neighbouring density values transition across 12 | the 0 boundary. This Isosurface will become our terrain. 13 | 14 | Two algorithms are used for generating terrain: Dual Contouring and Marching Cubes. At this point, Marching Cubes is preferred, as it 15 | only uses the field function (i.e. noise generator) during the initial generation of density values, whereas Dual Contouring requires 16 | the field function during smoothing. Also, I think saving data and later editing it would be very difficult with Dual Contouring. 17 | 18 | Density Field 19 | ------------- 20 | Currently, the density field is a giant 3-dimensional array (implemented using std::vector). 21 | 22 | You will notice that the density field is bigger than the actual 'area' that is being turned into an Isosurface. This is because 23 | the algorithms used for smoothing will often need to look outside the specified Isosurface boundaries in order to calculate normals (using, for 24 | example, interpolation). 25 | 26 | The variables that define how many 'extra' dimensions the 3d array has are glr::terrain::constants::POINT_FIELD_OFFSET and glr::terrain::constants::POINT_FIELD_OVERSET, 27 | which are located in terrain/Constants.hpp. 28 | -------------------------------------------------------------------------------- /include/terrain/TerrainMesh.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TERRAINMESH_H_ 2 | #define TERRAINMESH_H_ 3 | 4 | #include "glw/Mesh.hpp" 5 | 6 | namespace glr 7 | { 8 | namespace terrain 9 | { 10 | 11 | /* 12 | * This extends the glw Mesh class to include texture blending data for voxel terrain. 13 | */ 14 | class TerrainMesh : public glr::glw::Mesh 15 | { 16 | public: 17 | /** 18 | * Basic constructor. The creator of the Mesh will have to set the data, and then call 19 | * 'allocateVideoMemory()' and 'pushToVideoMemory()' before this mesh will render properly. 20 | */ 21 | TerrainMesh(glw::IOpenGlDevice* openGlDevice, std::string name); 22 | 23 | /** 24 | * Standard constructor. Once called, the Mesh will be ready for rendering (with no further action 25 | * required by the creator). 26 | */ 27 | TerrainMesh(glw::IOpenGlDevice* openGlDevice, 28 | std::string name, 29 | std::vector< glm::vec3 > vertices, 30 | std::vector< glm::vec3 > normals, 31 | std::vector< glm::vec2 > textureCoordinates, 32 | std::vector< glm::vec4 > colors, 33 | std::vector< glm::vec4 > texBlendingData, 34 | GLint shaderVariableLocation, 35 | bool initialize = true 36 | ); 37 | virtual ~TerrainMesh(); 38 | 39 | virtual void pushToVideoMemory(); 40 | virtual void pullFromVideoMemory(); 41 | virtual void freeLocalData(); 42 | virtual void freeVideoMemory(); 43 | virtual void allocateVideoMemory(); 44 | 45 | void setTextureBlendingData(std::vector< glm::vec4 > texBlendingData); 46 | void setShaderVariableLocation(GLint shaderVariableLocation); 47 | 48 | std::vector< glm::vec4 >& getTextureBlendingData(); 49 | GLint getShaderVariableLocation() const; 50 | 51 | protected: 52 | std::vector< glm::vec4 > texBlendingData_; 53 | GLint shaderVariableLocation_; 54 | 55 | glm::detail::uint32 texBlendVboId_; 56 | }; 57 | 58 | } 59 | } 60 | 61 | #endif /* TERRAINMESH_H_ */ 62 | -------------------------------------------------------------------------------- /include/terrain/TerrainMeshSerializer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TERRAINMESHSERIALIZER_H_ 2 | #define TERRAINMESHSERIALIZER_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include "TerrainMesh.hpp" 8 | 9 | namespace glr 10 | { 11 | namespace terrain 12 | { 13 | 14 | /** 15 | * 16 | */ 17 | void serialize(const std::string& filename, TerrainMesh& terrainMesh); 18 | void deserialize(const std::string& filename, TerrainMesh& terrainMesh); 19 | 20 | void serialize(std::ofstream& stream, TerrainMesh& terrainMesh); 21 | void deserialize(std::ifstream& stream, TerrainMesh& terrainMesh); 22 | 23 | } 24 | } 25 | 26 | #endif /* TERRAINMESHSERIALIZER_H_ */ 27 | -------------------------------------------------------------------------------- /include/terrain/TerrainSettings.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TERRAINSETTINGS_H_ 2 | #define TERRAINSETTINGS_H_ 3 | 4 | namespace glr 5 | { 6 | namespace terrain 7 | { 8 | 9 | enum SmoothingAlgorithm 10 | { 11 | ALGORITHM_UNKNOWN = -1, 12 | ALGORITHM_MARCHING_CUBES, 13 | ALGORITHM_DUAL_CONTOURING 14 | }; 15 | 16 | enum LevelOfDetail 17 | { 18 | LOD_UNKNOWN = -1, 19 | LOD_LOWEST, 20 | LOD_LOW, 21 | LOD_MEDIUM, 22 | LOD_HIGH, 23 | LOD_HIGHEST 24 | }; 25 | 26 | /** 27 | * Used to pass in Terrain settings. 28 | */ 29 | struct TerrainSettings 30 | { 31 | TerrainSettings() 32 | : smoothingAlgorithm(ALGORITHM_MARCHING_CUBES), length(8), width(8), height(8), 33 | maxViewDistance(256.0f), maxLevelOfDetail(LOD_HIGHEST), minLevelOfDetail(LOD_LOWEST), 34 | lodHighestRadius(32.0f), lodHighRadius(64.0f), lodMediumRadius(128.0f), lodLowRadius(256.0f), resolution(1.0f), chunkSize(16), blockSize((glm::detail::int32)(chunkSize / resolution)) 35 | { 36 | } 37 | 38 | SmoothingAlgorithm smoothingAlgorithm; 39 | glm::detail::int32 length; 40 | glm::detail::int32 width; 41 | glm::detail::int32 height; 42 | glm::detail::float32 maxViewDistance; 43 | LevelOfDetail maxLevelOfDetail; 44 | LevelOfDetail minLevelOfDetail; 45 | 46 | glm::detail::float32 lodHighestRadius; 47 | glm::detail::float32 lodHighRadius; 48 | glm::detail::float32 lodMediumRadius; 49 | glm::detail::float32 lodLowRadius; 50 | 51 | glm::detail::float32 resolution; 52 | glm::detail::int32 chunkSize; 53 | glm::detail::int32 blockSize; 54 | }; 55 | 56 | } 57 | } 58 | 59 | #endif /* TERRAINSETTINGS_H_ */ 60 | -------------------------------------------------------------------------------- /include/terrain/Voxel.hpp: -------------------------------------------------------------------------------- 1 | #ifndef VOXEL_H_ 2 | #define VOXEL_H_ 3 | 4 | #define GLM_FORCE_RADIANS 5 | #include 6 | 7 | namespace glr 8 | { 9 | namespace terrain 10 | { 11 | 12 | struct Voxel 13 | { 14 | glm::detail::float32 density; 15 | }; 16 | 17 | } 18 | } 19 | 20 | #endif /* VOXEL_H_ */ 21 | -------------------------------------------------------------------------------- /include/terrain/VoxelChunk.hpp: -------------------------------------------------------------------------------- 1 | #ifndef VOXELCHUNK_H_ 2 | #define VOXELCHUNK_H_ 3 | 4 | #include 5 | 6 | #define GLM_FORCE_RADIANS 7 | #include 8 | 9 | namespace glmd = glm::detail; 10 | 11 | namespace glr 12 | { 13 | namespace terrain 14 | { 15 | 16 | typedef std::vector< std::vector< std::vector > > Points; 17 | 18 | struct VoxelChunk 19 | { 20 | glmd::int32 gridX; 21 | glmd::int32 gridY; 22 | glmd::int32 gridZ; 23 | Points points; 24 | 25 | VoxelChunk() : gridX(0), gridY(0), gridZ(0) 26 | {}; 27 | VoxelChunk(glmd::int32 gridX, glmd::int32 gridY, glmd::int32 gridZ) : gridX(gridX), gridY(gridY), gridZ(gridZ) 28 | {}; 29 | }; 30 | 31 | } 32 | } 33 | 34 | #endif /* VOXELCHUNK_H_ */ 35 | -------------------------------------------------------------------------------- /include/terrain/VoxelChunkCache.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jarrettchisholm/glr/79a57b12e26fe84595e833cace3528cb9c82bc20/include/terrain/VoxelChunkCache.hpp -------------------------------------------------------------------------------- /include/terrain/VoxelChunkNoiseGenerator.hpp: -------------------------------------------------------------------------------- 1 | #ifndef VOXELCHUNKNOISEGENERATOR_H_ 2 | #define VOXELCHUNKNOISEGENERATOR_H_ 3 | 4 | #define GLM_FORCE_RADIANS 5 | #include 6 | 7 | namespace glr 8 | { 9 | namespace terrain 10 | { 11 | 12 | class IFieldFunction; 13 | class VoxelChunk; 14 | 15 | /** 16 | * Will fill the VoxelChunk with noise generated using the field function. 17 | * 18 | * Once the method is finished, the VoxelChunk will have the following dimensions: 19 | * (SIZE + POINT_FIELD_OFFSET + POINT_FIELD_OVERSET) x (SIZE + POINT_FIELD_OFFSET + POINT_FIELD_OVERSET) 20 | * 21 | * We generate 'extra' dimensions of density data for the benefit of the smoothing functions - it allows them to use the extra data 22 | * for interpolation, etc. 23 | * 24 | */ 25 | void generateNoise(VoxelChunk& chunk, glm::detail::int32 length, glm::detail::int32 width, glm::detail::int32 height, glr::terrain::IFieldFunction& fieldFunction); 26 | 27 | /** 28 | * 29 | */ 30 | bool determineIfEmptyOrSolid(VoxelChunk& chunk); 31 | 32 | } 33 | } 34 | 35 | #endif /* VOXELCHUNKNOISEGENERATOR_H_ */ 36 | -------------------------------------------------------------------------------- /include/terrain/dual_contouring/LICENSE: -------------------------------------------------------------------------------- 1 | THE AUTHOR MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR 2 | IMPLIED WARRANTY OF ANY KIND. THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF 3 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, OR 4 | CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 5 | OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. 6 | -------------------------------------------------------------------------------- /include/terrain/dual_contouring/README: -------------------------------------------------------------------------------- 1 | This source code has been adapted from the code from http://www.sandboxie.com/misc/isosurf/isosurfaces.html. 2 | The code was published into the public domain. 3 | 4 | Original author: Ronen Tzur 5 | 6 | The license for the code: 7 | 8 | THE AUTHOR MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR 9 | IMPLIED WARRANTY OF ANY KIND. THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF 10 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, OR 11 | CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 12 | OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. 13 | -------------------------------------------------------------------------------- /include/terrain/marching_cubes/README: -------------------------------------------------------------------------------- 1 | This source code has been adapted from the code from http://paulbourke.net/geometry/polygonise/. 2 | This code is used with permission. 3 | 4 | Original author: Paul Bourke 5 | -------------------------------------------------------------------------------- /samples/SConstruct: -------------------------------------------------------------------------------- 1 | #! /bin/python 2 | import subprocess, os 3 | import shlex 4 | 5 | 6 | # TODO: Make this SConstruct file more robust (i.e. allow setting the compiler, etc) 7 | os.chdir( 'simple' ) 8 | result = subprocess.call( shlex.split('scons'), shell=True ) 9 | 10 | os.chdir( '../lights' ) 11 | result = subprocess.call( shlex.split('scons'), shell=True ) 12 | -------------------------------------------------------------------------------- /samples/lights/src/Main.hpp: -------------------------------------------------------------------------------- 1 | #include "glm/glm.hpp" 2 | #include 3 | 4 | #include "GlrInclude.hpp" 5 | #include "extras/FpsCamera.hpp" 6 | 7 | #ifndef MAIN_H 8 | #define MAIN_H 9 | 10 | class Main { 11 | public: 12 | Main(); 13 | virtual ~Main(); 14 | 15 | void run(); 16 | 17 | private: 18 | std::unique_ptr< glr::GlrProgram > glrProgram_; 19 | glr::IWindow* window_; 20 | 21 | std::unique_ptr< glr::extras::FpsCamera > camera_; 22 | 23 | void tick(); 24 | void destroy(); 25 | }; 26 | #endif /* MAIN_H */ 27 | -------------------------------------------------------------------------------- /samples/lights/src/extras/FpsCamera.cpp: -------------------------------------------------------------------------------- 1 | #include "FpsCamera.hpp" 2 | 3 | namespace glr 4 | { 5 | namespace extras 6 | { 7 | 8 | FpsCamera::FpsCamera(ICamera* camera, glmd::float32 speed) : camera_(camera), speed_(speed) 9 | { 10 | initialize(); 11 | } 12 | 13 | FpsCamera::~FpsCamera() 14 | { 15 | } 16 | 17 | void FpsCamera::initialize() 18 | { 19 | } 20 | 21 | bool FpsCamera::isActive() 22 | { 23 | return true; 24 | } 25 | 26 | void FpsCamera::moveForward() 27 | { 28 | camera_->move( glm::vec3(0.0f, 0.0f, -speed_) ); 29 | } 30 | 31 | void FpsCamera::moveBack() 32 | { 33 | camera_->move( glm::vec3(0.0f, 0.0f, speed_) ); 34 | } 35 | 36 | void FpsCamera::moveLeft() 37 | { 38 | camera_->move( glm::vec3(-speed_, 0.0f, 0.0f) ); 39 | } 40 | 41 | void FpsCamera::moveRight() 42 | { 43 | camera_->move( glm::vec3(speed_, 0.0f, 0.0f) ); 44 | } 45 | 46 | ICamera* FpsCamera::getCamera() 47 | { 48 | return camera_; 49 | } 50 | 51 | void FpsCamera::rotate(const glm::detail::float32& degrees, const glm::vec3& axis) 52 | { 53 | if ( axis == glm::vec3(0.0f, 1.0f, 0.0f) ) 54 | camera_->rotate(degrees, axis, ISceneNode::TransformSpace::TS_LOCAL); 55 | else 56 | camera_->rotate(degrees, axis, ISceneNode::TransformSpace::TS_WORLD); 57 | } 58 | 59 | void FpsCamera::tick(glm::detail::float32 time) 60 | { 61 | camera_->tick(time); 62 | } 63 | 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /samples/lights/src/extras/FpsCamera.hpp: -------------------------------------------------------------------------------- 1 | #ifndef FPSCAMERA_H_ 2 | #define FPSCAMERA_H_ 3 | 4 | #define GLM_FORCE_RADIANS 5 | #include "glm/glm.hpp" 6 | 7 | #include "GlrInclude.hpp" 8 | 9 | namespace glr 10 | { 11 | namespace extras 12 | { 13 | 14 | class FpsCamera 15 | { 16 | public: 17 | FpsCamera(ICamera* camera, glmd::float32 speed); 18 | virtual ~FpsCamera(); 19 | 20 | bool isActive(); 21 | 22 | void moveForward(); 23 | void moveBack(); 24 | void moveLeft(); 25 | void moveRight(); 26 | 27 | ICamera* getCamera(); 28 | 29 | void rotate(const glm::detail::float32& degrees, const glm::vec3& axis); 30 | 31 | /** 32 | * 33 | */ 34 | void tick(glmd::float32 time); 35 | 36 | private: 37 | ICamera* camera_; 38 | glmd::float32 speed_; 39 | 40 | void initialize(); 41 | }; 42 | 43 | } 44 | } 45 | 46 | #endif /* FPSCAMERA_H_ */ 47 | -------------------------------------------------------------------------------- /samples/resources/models/StickMan_0/README.md: -------------------------------------------------------------------------------- 1 | Model from: http://opengameart.org/content/creomotos-stick-man-fixed-up 2 | 3 | License: Creative Commons 0 (CC0) 4 | More Information: http://creativecommons.org/publicdomain/zero/1.0/ 5 | -------------------------------------------------------------------------------- /samples/resources/models/StickMan_0/StickMan_0.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jarrettchisholm/glr/79a57b12e26fe84595e833cace3528cb9c82bc20/samples/resources/models/StickMan_0/StickMan_0.blend -------------------------------------------------------------------------------- /samples/simple/src/Main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * This is a simple example showing how to: 3 | * 4 | * - Create the basic GLR program 5 | * - Create a camera 6 | * 7 | * It is the minimum required code for a working scene. 8 | */ 9 | 10 | #include "Main.hpp" 11 | 12 | Main::Main() 13 | { 14 | // Create the GLR program 15 | glrProgram_ = std::unique_ptr( new glr::GlrProgram() ); 16 | 17 | // Create our window 18 | window_ = glrProgram_->createWindow("Test Name", "Simple Glr Project", 800, 600, 32, false, false); 19 | 20 | // Get the scene manager 21 | auto smgr = glrProgram_->getSceneManager(); 22 | 23 | // Create camera 24 | auto camera = smgr->createCamera(); 25 | camera->setPosition(0.0f, 0.0f, 1.0f); 26 | camera->lookAt( glm::vec3(0.0f, 0.0f, 0.0f) ); 27 | } 28 | 29 | Main::~Main() 30 | { 31 | destroy(); 32 | } 33 | 34 | void Main::run() 35 | { 36 | bool done = false; 37 | 38 | 39 | while ( !done ) 40 | { 41 | window_->handleEvents(); 42 | 43 | glrProgram_->render(); 44 | 45 | if ( sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) 46 | { 47 | done = true; 48 | } 49 | } 50 | } 51 | 52 | void Main::tick() 53 | { 54 | } 55 | 56 | void Main::destroy() 57 | { 58 | window_->destroy(); 59 | } 60 | 61 | int main() 62 | { 63 | Main main; 64 | 65 | main.run(); 66 | 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /samples/simple/src/Main.hpp: -------------------------------------------------------------------------------- 1 | #define GLM_FORCE_RADIANS 2 | #include 3 | 4 | #include 5 | 6 | #include "GlrInclude.hpp" 7 | #include "extras/FpsCamera.hpp" 8 | 9 | #ifndef MAIN_H 10 | #define MAIN_H 11 | 12 | class Main 13 | { 14 | public: 15 | Main(); 16 | virtual ~Main(); 17 | 18 | void run(); 19 | 20 | private: 21 | std::unique_ptr< glr::GlrProgram > glrProgram_; 22 | glr::IWindow* window_; 23 | 24 | void tick(); 25 | void destroy(); 26 | }; 27 | 28 | #endif /* MAIN_H */ 29 | -------------------------------------------------------------------------------- /samples/simple/src/extras/FpsCamera.cpp: -------------------------------------------------------------------------------- 1 | #include "FpsCamera.hpp" 2 | 3 | namespace glr 4 | { 5 | namespace extras 6 | { 7 | 8 | FpsCamera::FpsCamera(ICamera* camera, glmd::float32 speed) : camera_(camera), speed_(speed) 9 | { 10 | initialize(); 11 | } 12 | 13 | FpsCamera::~FpsCamera() 14 | { 15 | } 16 | 17 | void FpsCamera::initialize() 18 | { 19 | } 20 | 21 | bool FpsCamera::isActive() 22 | { 23 | return true; 24 | } 25 | 26 | void FpsCamera::moveForward() 27 | { 28 | camera_->move( glm::vec3(0.0f, 0.0f, -speed_) ); 29 | } 30 | 31 | void FpsCamera::moveBack() 32 | { 33 | camera_->move( glm::vec3(0.0f, 0.0f, speed_) ); 34 | } 35 | 36 | void FpsCamera::moveLeft() 37 | { 38 | camera_->move( glm::vec3(-speed_, 0.0f, 0.0f) ); 39 | } 40 | 41 | void FpsCamera::moveRight() 42 | { 43 | camera_->move( glm::vec3(speed_, 0.0f, 0.0f) ); 44 | } 45 | 46 | ICamera* FpsCamera::getCamera() 47 | { 48 | return camera_; 49 | } 50 | 51 | void FpsCamera::rotate(const glm::detail::float32& degrees, const glm::vec3& axis) 52 | { 53 | if ( axis == glm::vec3(0.0f, 1.0f, 0.0f) ) 54 | camera_->rotate(degrees, axis, ISceneNode::TransformSpace::TS_LOCAL); 55 | else 56 | camera_->rotate(degrees, axis, ISceneNode::TransformSpace::TS_WORLD); 57 | } 58 | 59 | void FpsCamera::tick(glm::detail::float32 time) 60 | { 61 | camera_->tick(time); 62 | } 63 | 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /samples/simple/src/extras/FpsCamera.hpp: -------------------------------------------------------------------------------- 1 | #ifndef FPSCAMERA_H_ 2 | #define FPSCAMERA_H_ 3 | 4 | #define GLM_FORCE_RADIANS 5 | #include "glm/glm.hpp" 6 | 7 | #include "GlrInclude.hpp" 8 | 9 | namespace glr 10 | { 11 | namespace extras 12 | { 13 | 14 | class FpsCamera 15 | { 16 | public: 17 | FpsCamera(ICamera* camera, glmd::float32 speed); 18 | virtual ~FpsCamera(); 19 | 20 | bool isActive(); 21 | 22 | void moveForward(); 23 | void moveBack(); 24 | void moveLeft(); 25 | void moveRight(); 26 | 27 | ICamera* getCamera(); 28 | 29 | void rotate(const glm::detail::float32& degrees, const glm::vec3& axis); 30 | 31 | /** 32 | * 33 | */ 34 | void tick(glmd::float32 time); 35 | 36 | private: 37 | ICamera* camera_; 38 | glmd::float32 speed_; 39 | 40 | void initialize(); 41 | }; 42 | 43 | } 44 | } 45 | 46 | #endif /* FPSCAMERA_H_ */ 47 | -------------------------------------------------------------------------------- /src/Camera.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #define GLM_FORCE_RADIANS 6 | #include "glm/gtc/type_ptr.hpp" 7 | #include 8 | 9 | #include "Configure.hpp" 10 | 11 | #ifdef OS_WINDOWS 12 | #include 13 | #endif 14 | 15 | #include "Camera.hpp" 16 | 17 | #include "common/logger/Logger.hpp" 18 | 19 | #include "common/math/Math.hpp" 20 | 21 | #include "exceptions/Exception.hpp" 22 | 23 | namespace glr 24 | { 25 | 26 | Camera::Camera(Id id, glw::IOpenGlDevice* openGlDevice) : BasicSceneNode(id, openGlDevice) 27 | { 28 | setPosition(0.0f, 0.0f, 0.0f); 29 | setScale(1.0f, 1.0f, 1.0f); 30 | 31 | initialize(); 32 | } 33 | 34 | Camera::~Camera() 35 | { 36 | } 37 | 38 | void Camera::initialize() 39 | { 40 | clearMovementBuffer(); 41 | 42 | xRot_ = 0.0f; 43 | yRot_ = 0.0f; 44 | 45 | moveSpeed_ = 0.05f; 46 | rotSpeed_ = 18.0f; 47 | 48 | orientationQuaternion_ = glm::quat(); 49 | orientationQuaternion_ = glm::normalize(orientationQuaternion_); 50 | 51 | viewMatrix_ = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, 0.0f)); 52 | 53 | LOG_DEBUG( "Camera initialized." ); 54 | } 55 | 56 | void Camera::render() 57 | { 58 | if ( isActive() ) 59 | { 60 | glm::quat temp = glm::conjugate(orientationQuaternion_); 61 | 62 | viewMatrix_ = glm::mat4_cast(temp); 63 | viewMatrix_ = glm::translate(viewMatrix_, glm::vec3(-pos_.x, -pos_.y, -pos_.z)); 64 | } 65 | } 66 | 67 | const glm::mat4& Camera::getViewMatrix() const 68 | { 69 | return viewMatrix_; 70 | } 71 | 72 | bool Camera::isActive() const 73 | { 74 | return active_; 75 | } 76 | 77 | /** 78 | * Does nothing in the Camera. 79 | */ 80 | void Camera::attach(models::IModel* model) 81 | { 82 | std::string msg = std::string("__FILE__(__LINE__): Cannot attach a model to a Camera."); 83 | LOG_ERROR( msg ); 84 | throw new exception::Exception( msg ); 85 | } 86 | 87 | /** 88 | * 89 | */ 90 | void Camera::clearMovementBuffer() 91 | { 92 | movementBuffer_ = glm::vec3(0.0f, 0.0f, 0.0f); 93 | } 94 | 95 | /** 96 | * 97 | */ 98 | void Camera::move(const glm::vec3& moveVector) 99 | { 100 | movementBuffer_ += moveVector; 101 | } 102 | 103 | /** 104 | * 105 | */ 106 | void Camera::tick(glm::detail::float32 time) 107 | { 108 | pos_ += orientationQuaternion_ * movementBuffer_; 109 | 110 | clearMovementBuffer(); 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /src/Id.cpp: -------------------------------------------------------------------------------- 1 | #include "Id.hpp" 2 | 3 | namespace glr 4 | { 5 | 6 | const Id Id::INVALID = Id(); 7 | 8 | Id::Id() : id_(0) 9 | { 10 | } 11 | 12 | Id::Id(glm::detail::uint32 id) : id_(id) 13 | { 14 | } 15 | 16 | Id::~Id() 17 | { 18 | } 19 | 20 | glm::detail::uint32 Id::getId() const 21 | { 22 | return id_; 23 | } 24 | 25 | bool Id::operator == (const Id &other) const 26 | { 27 | return id_ == other.id_; 28 | } 29 | 30 | bool Id::operator != (const Id &other) const 31 | { 32 | return id_ != other.id_; 33 | } 34 | 35 | bool Id::operator < (const Id &other) const 36 | { 37 | return id_ < other.id_; 38 | } 39 | 40 | bool Id::operator > (const Id &other) const 41 | { 42 | return other.id_ < id_; 43 | } 44 | 45 | bool Id::operator <= (const Id &other) const 46 | { 47 | return !(id_ > other.id_); 48 | } 49 | 50 | bool Id::operator >= (const Id &other) const 51 | { 52 | return !(id_ < other.id_); 53 | } 54 | 55 | std::ostream& operator << (std::ostream& os, const Id& id) 56 | { 57 | os << id.id_; 58 | return os; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/IdManager.cpp: -------------------------------------------------------------------------------- 1 | #include "IdManager.hpp" 2 | 3 | namespace glr 4 | { 5 | 6 | IdManager::IdManager() : currentId_(1) 7 | { 8 | } 9 | 10 | IdManager::~IdManager() 11 | { 12 | } 13 | 14 | Id IdManager::createId() 15 | { 16 | return Id(++currentId_); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/Light.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "Configure.hpp" 4 | 5 | #ifdef OS_WINDOWS 6 | #include 7 | #endif 8 | 9 | #include 10 | 11 | #define GLM_FORCE_RADIANS 12 | #include "glm/gtc/type_ptr.hpp" 13 | #include 14 | 15 | #include "Light.hpp" 16 | 17 | #include "common/logger/Logger.hpp" 18 | 19 | #include "common/math/Math.hpp" 20 | 21 | namespace glr 22 | { 23 | 24 | Light::Light(Id id, glw::IOpenGlDevice* openGlDevice) : BasicSceneNode(id, openGlDevice) 25 | { 26 | setPosition(0, 0, 0); 27 | setScale(1, 1, 1); 28 | 29 | initialize(); 30 | } 31 | 32 | Light::Light(Id id, std::string name, glw::IOpenGlDevice* openGlDevice) : BasicSceneNode(id, name, openGlDevice) 33 | { 34 | setPosition(0, 0, 0); 35 | setScale(1, 1, 1); 36 | 37 | initialize(); 38 | } 39 | 40 | Light::~Light() 41 | { 42 | } 43 | 44 | void Light::initialize() 45 | { 46 | LOG_DEBUG( "Light initialized." ); 47 | } 48 | 49 | void Light::render() 50 | { 51 | 52 | glm::quat temp = glm::conjugate(orientationQuaternion_); 53 | glm::mat4 rotMatrix = glm::mat4_cast(temp); 54 | //rotMatrix = glm::translate(rotMatrix, glm::vec3(-pos_.x, -pos_.y, -pos_.z)); 55 | 56 | lightData_.direction = rotMatrix * lightData_.direction; 57 | } 58 | 59 | /** 60 | * Does nothing in the Light. 61 | */ 62 | void Light::attach(models::IModel* model) 63 | { 64 | } 65 | 66 | void Light::setLightData(LightData data) 67 | { 68 | lightData_ = data; 69 | 70 | //pos_ = lightData_.position; 71 | } 72 | 73 | const LightData& Light::getLightData() const 74 | { 75 | return lightData_; 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/environment/EnvironmentManager.cpp: -------------------------------------------------------------------------------- 1 | #include "environment/EnvironmentManager.hpp" 2 | 3 | namespace glr 4 | { 5 | namespace env 6 | { 7 | 8 | EnvironmentManager::EnvironmentManager(glw::IOpenGlDevice* openGlDevice, models::IModelManager* modelManager) 9 | : openGlDevice_(openGlDevice), modelManager_(modelManager), followTarget_(nullptr) 10 | { 11 | assert(openGlDevice_ != nullptr); 12 | assert(modelManager_ != nullptr); 13 | 14 | idManager_ = IdManager(); 15 | skyBoxes_ = std::vector< std::unique_ptr >(); 16 | } 17 | 18 | EnvironmentManager::~EnvironmentManager() 19 | { 20 | } 21 | 22 | ISky* EnvironmentManager::createSkyBox() 23 | { 24 | skyBoxes_.push_back( std::unique_ptr(new SkyBox(idManager_.createId(), openGlDevice_, modelManager_)) ); 25 | 26 | return skyBoxes_.back().get(); 27 | } 28 | 29 | ISky* EnvironmentManager::getSkyBox(Id id) 30 | { 31 | auto findFunction = [&id](const std::unique_ptr& node) { return node->getId() == id; }; 32 | 33 | auto it = std::find_if(skyBoxes_.begin(), skyBoxes_.end(), findFunction); 34 | 35 | if (it != skyBoxes_.end()) 36 | return it->get(); 37 | 38 | return nullptr; 39 | } 40 | 41 | ISky* EnvironmentManager::getSkyBox(const std::string& name) 42 | { 43 | auto findFunction = [&name](const std::unique_ptr& node) { return node->getName() == name; }; 44 | 45 | auto it = std::find_if(skyBoxes_.begin(), skyBoxes_.end(), findFunction); 46 | 47 | if (it != skyBoxes_.end()) 48 | return it->get(); 49 | 50 | return nullptr; 51 | } 52 | 53 | void EnvironmentManager::destroySkyBox(Id id) 54 | { 55 | auto findFunction = [&id](const std::unique_ptr& node) { return node->getId() == id; }; 56 | 57 | auto it = std::find_if(skyBoxes_.begin(), skyBoxes_.end(), findFunction); 58 | 59 | if (it != skyBoxes_.end()) 60 | skyBoxes_.erase(it); 61 | } 62 | 63 | void EnvironmentManager::destroySkyBox(const std::string& name) 64 | { 65 | auto findFunction = [&name](const std::unique_ptr& node) { return node->getName() == name; }; 66 | 67 | auto it = std::find_if(skyBoxes_.begin(), skyBoxes_.end(), findFunction); 68 | 69 | if (it != skyBoxes_.end()) 70 | skyBoxes_.erase(it); 71 | } 72 | 73 | void EnvironmentManager::destroySkyBox(ISky* skybox) 74 | { 75 | auto findFunction = [skybox](const std::unique_ptr& node) { return node.get() == skybox; }; 76 | 77 | auto it = std::find_if(skyBoxes_.begin(), skyBoxes_.end(), findFunction); 78 | 79 | if (it != skyBoxes_.end()) 80 | skyBoxes_.erase(it); 81 | } 82 | 83 | void EnvironmentManager::render() 84 | { 85 | for ( auto& skybox : skyBoxes_ ) 86 | { 87 | if (followTarget_ != nullptr) 88 | skybox->move( followTarget_->getPosition() ); 89 | skybox->render(); 90 | } 91 | } 92 | 93 | void EnvironmentManager::setFollowTarget(ISceneNode* target) 94 | { 95 | followTarget_ = target; 96 | } 97 | 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/environment/SkyBoxPlane.cpp: -------------------------------------------------------------------------------- 1 | #include "environment/SkyBoxPlane.hpp" 2 | 3 | namespace glr 4 | { 5 | namespace env 6 | { 7 | 8 | SkyBoxPlane::SkyBoxPlane(Id id, std::string name, glw::IOpenGlDevice* openGlDevice) : BasicSceneNode( id, std::move(name), openGlDevice ) 9 | { 10 | nodePos_ = glm::vec3(); 11 | cameraPos_ = glm::vec3(); 12 | } 13 | 14 | SkyBoxPlane::~SkyBoxPlane() 15 | { 16 | } 17 | 18 | void SkyBoxPlane::move( const glm::vec3& movement ) 19 | { 20 | cameraPos_ = movement; 21 | cameraPos_ *= 2.0f; 22 | pos_ = glm::vec3( nodePos_ ) + glm::vec3( cameraPos_ ); 23 | } 24 | 25 | void SkyBoxPlane::setPosition(glm::vec3& newPos) 26 | { 27 | nodePos_ = newPos; 28 | pos_ = glm::vec3( nodePos_ ) + glm::vec3( cameraPos_ ); 29 | } 30 | 31 | void SkyBoxPlane::setPosition(glm::detail::float32 x, glm::detail::float32 y, glm::detail::float32 z) 32 | { 33 | nodePos_ = glm::vec3(x, y, z); 34 | pos_ = glm::vec3( nodePos_ ) + glm::vec3( cameraPos_ ); 35 | } 36 | 37 | void SkyBoxPlane::translate(const glm::vec3& trans, TransformSpace relativeTo) 38 | { 39 | nodePos_ += trans; 40 | pos_ = glm::vec3( nodePos_ ) + glm::vec3( cameraPos_ ); 41 | } 42 | 43 | void SkyBoxPlane::translate(glm::detail::float32 x, glm::detail::float32 y, glm::detail::float32 z, TransformSpace relativeTo) 44 | { 45 | nodePos_ += glm::vec3(x, y, z); 46 | pos_ = glm::vec3( nodePos_ ) + glm::vec3( cameraPos_ ); 47 | } 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/exceptions/Exception.cpp: -------------------------------------------------------------------------------- 1 | #include "exceptions/Exception.hpp" 2 | 3 | namespace glr 4 | { 5 | namespace exception 6 | { 7 | 8 | Exception::Exception(const std::string& message) : message_(message) 9 | { 10 | } 11 | 12 | 13 | Exception::~Exception() throw() 14 | { 15 | } 16 | 17 | const char* Exception::what() const throw() 18 | { 19 | return message_.c_str(); 20 | } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/exceptions/FormatException.cpp: -------------------------------------------------------------------------------- 1 | #include "exceptions/FormatException.hpp" 2 | 3 | namespace glr 4 | { 5 | namespace exception 6 | { 7 | 8 | FormatException::FormatException(const std::string& message) : Exception(message) 9 | { 10 | } 11 | 12 | FormatException::~FormatException() throw() 13 | { 14 | } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/exceptions/GlException.cpp: -------------------------------------------------------------------------------- 1 | #include "exceptions/GlException.hpp" 2 | 3 | namespace glr 4 | { 5 | namespace exception 6 | { 7 | 8 | GlException::GlException(const std::string& message) : Exception(message) 9 | { 10 | } 11 | 12 | GlException::~GlException() throw() 13 | { 14 | } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/exceptions/InvalidArgumentException.cpp: -------------------------------------------------------------------------------- 1 | #include "exceptions/InvalidArgumentException.hpp" 2 | 3 | namespace glr 4 | { 5 | namespace exception 6 | { 7 | 8 | InvalidArgumentException::InvalidArgumentException(const std::string& message) : LogicException(message) 9 | { 10 | } 11 | 12 | InvalidArgumentException::~InvalidArgumentException() throw() 13 | { 14 | } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/exceptions/IoException.cpp: -------------------------------------------------------------------------------- 1 | #include "exceptions/IoException.hpp" 2 | 3 | namespace glr 4 | { 5 | namespace exception 6 | { 7 | 8 | IoException::IoException(const std::string& message) : Exception(message) 9 | { 10 | } 11 | 12 | IoException::~IoException() throw() 13 | { 14 | } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/exceptions/LogicException.cpp: -------------------------------------------------------------------------------- 1 | #include "exceptions/LogicException.hpp" 2 | 3 | namespace glr 4 | { 5 | namespace exception 6 | { 7 | 8 | LogicException::LogicException(const std::string& message) : std::logic_error(message), message_(message) 9 | { 10 | } 11 | 12 | LogicException::~LogicException() throw() 13 | { 14 | } 15 | 16 | const char* LogicException::what() throw() 17 | { 18 | return message_.c_str(); 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/exceptions/RuntimeException.cpp: -------------------------------------------------------------------------------- 1 | #include "exceptions/RuntimeException.hpp" 2 | 3 | namespace glr 4 | { 5 | namespace exception 6 | { 7 | 8 | RuntimeException::RuntimeException(const std::string& message) : std::runtime_error(message), message_(message) 9 | { 10 | } 11 | 12 | RuntimeException::~RuntimeException() throw() 13 | { 14 | } 15 | 16 | const char* RuntimeException::what() throw() 17 | { 18 | return message_.c_str(); 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/glw/Constants.cpp: -------------------------------------------------------------------------------- 1 | #include "glw/Constants.hpp" 2 | 3 | namespace glr 4 | { 5 | namespace glw 6 | { 7 | 8 | const std::string Constants::MODEL_DIRECTORY = std::string("."); 9 | 10 | const glmd::uint32 Constants::MAX_NUMBER_OF_BONES_PER_MESH = 100; 11 | 12 | const std::string Constants::GLR_IDENTITY_BONES = std::string("GLR_IDENTITY_BONES"); 13 | 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /src/glw/shaders/GlrParser.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include "glw/shaders/GlrParser.hpp" 6 | 7 | #include "exceptions/Exception.hpp" 8 | #include "exceptions/GlException.hpp" 9 | 10 | #include "common/logger/Logger.hpp" 11 | 12 | namespace glr 13 | { 14 | namespace shaders 15 | { 16 | 17 | GlrParser::GlrParser(std::string source) : source_(source) 18 | { 19 | } 20 | 21 | 22 | GlrParser::~GlrParser() 23 | { 24 | } 25 | 26 | void GlrParser::parse() 27 | { 28 | parseBind(source_.begin(), source_.end()); 29 | parseLocation(source_.begin(), source_.end()); 30 | } 31 | 32 | template void GlrParser::parseBind(It f, It l) 33 | { 34 | // Parse @bind bindings 35 | { 36 | bindGrammar g; 37 | 38 | std::vector< std::pair > mappings; 39 | bool hasResults = qi::phrase_parse(f, l, g, qi::blank, mappings); 40 | 41 | if ( hasResults ) 42 | { 43 | bindBindings_ = mappings; 44 | } 45 | } 46 | } 47 | 48 | template void GlrParser::parseLocation(It f, It l) 49 | { 50 | // Parse @location bindings 51 | { 52 | locationGrammar g; 53 | 54 | std::vector< std::pair > mappings; 55 | bool hasResults = qi::phrase_parse(f, l, g, qi::blank, mappings); 56 | 57 | if ( hasResults ) 58 | { 59 | GLint maxNumLocations = 0; 60 | glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxNumLocations); 61 | 62 | for ( auto& it : mappings ) 63 | { 64 | auto p = std::pair(); 65 | p.first = std::atoi(it.first.c_str()); 66 | p.second = it.second; 67 | 68 | locationBindings_.push_back(p); 69 | } 70 | } 71 | } 72 | } 73 | 74 | std::vector< std::pair > GlrParser::getBindBindings() 75 | { 76 | return bindBindings_; 77 | } 78 | 79 | std::vector< std::pair > GlrParser::getLocationBindings() 80 | { 81 | return locationBindings_; 82 | } 83 | 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/glw/shaders/GlrPreProcessor.cpp: -------------------------------------------------------------------------------- 1 | #include "glw/shaders/GlrPreProcessor.hpp" 2 | 3 | #include "glw/shaders/ShaderData.hpp" 4 | 5 | namespace glr 6 | { 7 | namespace shaders 8 | { 9 | 10 | GlrPreProcessor::GlrPreProcessor(std::string source, std::string baseDirectory) : CPreProcessor(source, baseDirectory) 11 | { 12 | CPreProcessor::files_ = SHADER_DATA; 13 | } 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/glw/shaders/GlrShader.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include "glw/shaders/GlrShader.hpp" 6 | 7 | #include "common/logger/Logger.hpp" 8 | 9 | #include "glw/shaders/GlrPreProcessor.hpp" 10 | 11 | namespace glr 12 | { 13 | namespace shaders 14 | { 15 | 16 | GlrShader::GlrShader(std::string source, std::string baseDirectory) : source_(std::move(source)), baseDirectory_(std::move(baseDirectory)) 17 | { 18 | } 19 | 20 | GlrShader::GlrShader(std::string name, std::string source, std::string baseDirectory) : name_(std::move(name)), source_(std::move(source)), baseDirectory_(std::move(baseDirectory)) 21 | { 22 | } 23 | 24 | 25 | GlrShader::~GlrShader() 26 | { 27 | } 28 | 29 | void GlrShader::process(std::map< std::string, std::string > defineMap) 30 | { 31 | LOG_DEBUG( "Processing shader '" + name_ + "'." ); 32 | 33 | GlrPreProcessor pp(source_, baseDirectory_); 34 | pp.process(defineMap); 35 | 36 | processedSource_ = pp.getProcessedSource(); 37 | type_ = IShader::parseType(pp.getType()); 38 | 39 | GlrParser op(processedSource_); 40 | op.parse(); 41 | bindBindings_ = op.getBindBindings(); 42 | locationBindings_ = op.getLocationBindings(); 43 | 44 | // Remove all '@bind' and '@location' lines 45 | { 46 | const boost::regex e("@bind(\\s+)(\\S+)\\n+"); 47 | processedSource_ = boost::regex_replace(processedSource_, e, "\n"); 48 | } 49 | { 50 | const boost::regex e("@location(\\s+)(\\S+)\\n+"); 51 | processedSource_ = boost::regex_replace(processedSource_, e, "\n"); 52 | } 53 | } 54 | 55 | const std::string& GlrShader::getName() const 56 | { 57 | return name_; 58 | } 59 | 60 | IShader::Type GlrShader::getType() const 61 | { 62 | return type_; 63 | } 64 | 65 | std::string GlrShader::getProcessedSource() const 66 | { 67 | return processedSource_; 68 | } 69 | 70 | std::string GlrShader::getSource() const 71 | { 72 | return source_; 73 | } 74 | 75 | std::vector< std::pair > GlrShader::getBindings() 76 | { 77 | return bindBindings_; 78 | } 79 | 80 | std::vector< std::pair > GlrShader::getLocationBindings() 81 | { 82 | return locationBindings_; 83 | } 84 | 85 | bool GlrShader::containsPreProcessorCommands() const 86 | { 87 | // TODO: implement 88 | return true; 89 | } 90 | 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/glw/shaders/GlrShaderProgram.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "glw/shaders/GlrShaderProgram.hpp" 4 | 5 | #include "glw/shaders/GlrPreProcessor.hpp" 6 | 7 | #include "common/logger/Logger.hpp" 8 | 9 | #include "exceptions/GlException.hpp" 10 | 11 | namespace glr 12 | { 13 | namespace shaders 14 | { 15 | 16 | GlrShaderProgram::GlrShaderProgram(std::string source, std::string baseDirectory) : source_(std::move(source)), baseDirectory_(std::move(baseDirectory)) 17 | { 18 | } 19 | 20 | GlrShaderProgram::GlrShaderProgram(std::string name, std::string source, std::string baseDirectory) : name_(std::move(name)), source_(std::move(source)), baseDirectory_(std::move(baseDirectory)) 21 | { 22 | } 23 | 24 | 25 | GlrShaderProgram::~GlrShaderProgram() 26 | { 27 | } 28 | 29 | void GlrShaderProgram::process(const std::map< std::string, std::unique_ptr >& glrShaderMap) 30 | { 31 | LOG_DEBUG( "Processing shader program '" + name_ + "'." ); 32 | 33 | // Pre-Process shaders 34 | GlrPreProcessor pp(source_, baseDirectory_); 35 | 36 | pp.process(); 37 | 38 | name_ = pp.getName(); 39 | LOG_DEBUG( "name: " + name_ ); 40 | std::vector shaders = pp.getShaders(); 41 | 42 | LOG_DEBUG( "Initializing " << shaders.size() << " shaders." ); 43 | 44 | for ( CPreProcessor::ShaderData& s : shaders ) 45 | { 46 | auto it = glrShaderMap.find(s.name); 47 | if ( it != glrShaderMap.end() ) 48 | { 49 | // Found shader 50 | shaders_.push_back(it->second.get()); 51 | shaders_.back()->process(s.defineMap); 52 | } 53 | else 54 | { 55 | LOG_ERROR( "Name requested: " + s.name ); 56 | LOG_ERROR( "Names available: " ); 57 | for ( auto& s : glrShaderMap ) 58 | { 59 | LOG_ERROR( s.first ); 60 | } 61 | 62 | std::string msg("Could not find shader '" + name_ + "'."); 63 | LOG_ERROR( msg ); 64 | throw exception::GlException(msg); 65 | } 66 | } 67 | } 68 | 69 | const std::string& GlrShaderProgram::getName() const 70 | { 71 | return name_; 72 | } 73 | 74 | std::vector< GlrShader* > GlrShaderProgram::getShaders() 75 | { 76 | return shaders_; 77 | } 78 | 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/gui/cef/RenderHandler.cpp: -------------------------------------------------------------------------------- 1 | #ifdef USE_CEF 2 | 3 | #include 4 | 5 | #include "gui/cef/RenderHandler.hpp" 6 | 7 | #include "common/logger/Logger.hpp" 8 | 9 | #include "exceptions/ExceptionInclude.hpp" 10 | 11 | namespace glr 12 | { 13 | namespace gui 14 | { 15 | namespace cef 16 | { 17 | 18 | namespace glmd = glm::detail; 19 | 20 | RenderHandler::RenderHandler(glmd::uint32 webTexture, glmd::uint32 width, glmd::uint32 height) : webTexture_(webTexture), width_(width), height_(height) 21 | { 22 | if (webTexture_ == 0) 23 | { 24 | std::string msg = "Error - Cef 3 texture id is invalid."; 25 | LOG_ERROR( msg ); 26 | throw exception::GlException( msg ); 27 | } 28 | } 29 | 30 | // CefRenderHandler interface 31 | bool RenderHandler::GetViewRect(CefRefPtr browser, CefRect& rect) 32 | { 33 | rect = CefRect(0, 0, width_, height_); 34 | return true; 35 | } 36 | 37 | void RenderHandler::OnPaint(CefRefPtr browser, PaintElementType type, const RectList& dirtyRects, const void* buffer, int width, int height) 38 | { 39 | //std::cout << "painting!: " << width << " " << height << std::endl; 40 | //memcpy(texBuf->getCurrentLock().data, buffer, width*height*4); 41 | 42 | // TODO: make this use a shader 43 | // TODO: make this paint only sections that have changed (do I really want/need to do this?) 44 | glBindTexture(GL_TEXTURE_2D, webTexture_); 45 | 46 | // Finally, we perform the main update, just copying the rect that is 47 | // marked as dirty but not from scrolled data. 48 | /* 49 | glTexSubImage2D(GL_TEXTURE_2D, 0, 50 | 0, 0, 51 | width, height, 52 | GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 53 | buffer 54 | ); 55 | */ 56 | glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); 57 | glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); 58 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, buffer); 59 | 60 | glBindTexture(GL_TEXTURE_2D, 0); 61 | } 62 | 63 | void RenderHandler::windowSizeUpdate(glmd::uint32 width, glmd::uint32 height) 64 | { 65 | width_ = width; 66 | height_ = height; 67 | } 68 | 69 | } 70 | } 71 | } 72 | 73 | #endif /* USE_CEF */ 74 | -------------------------------------------------------------------------------- /src/models/AssImpLoader.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jarrettchisholm/glr/79a57b12e26fe84595e833cace3528cb9c82bc20/src/models/AssImpLoader.cpp -------------------------------------------------------------------------------- /src/models/Billboard.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "models/Billboard.hpp" 4 | 5 | namespace glr 6 | { 7 | namespace models 8 | { 9 | 10 | Billboard::Billboard(Id id, std::string name, glw::IMesh* mesh, glw::ITexture* texture, glw::IMaterial* material, glw::IOpenGlDevice* openGlDevice) 11 | : id_(id), name_(std::move(name)), mesh_(mesh), texture_(texture), material_(material), openGlDevice_(openGlDevice) 12 | { 13 | } 14 | 15 | Billboard::~Billboard() 16 | { 17 | } 18 | 19 | const Id& Billboard::getId() const 20 | { 21 | return id_; 22 | } 23 | 24 | const std::string& Billboard::getName() const 25 | { 26 | return name_; 27 | } 28 | 29 | void Billboard::render(shaders::IShaderProgram& shader) 30 | { 31 | // TODO: Implement 32 | } 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/refactor.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | REPLACE_FROM=$1 4 | REPLACE_TO=$2 5 | 6 | FILES=$(find . -name "*.cpp") 7 | 8 | for f in $FILES 9 | do 10 | sed -i "s/${REPLACE_FROM}/${REPLACE_TO}/g" ${f} 11 | done 12 | 13 | 14 | FILES=$(find . -name "*.h") 15 | 16 | for f in $FILES 17 | do 18 | sed -i "s/${REPLACE_FROM}/${REPLACE_TO}/g" ${f} 19 | done 20 | -------------------------------------------------------------------------------- /src/serialize/TextInArchive.cpp: -------------------------------------------------------------------------------- 1 | #include "serialize/TextInArchive.hpp" 2 | 3 | namespace glr 4 | { 5 | namespace serialize 6 | { 7 | 8 | TextInArchive::TextInArchive(std::ifstream& ifstream) : boost::archive::text_iarchive(ifstream) 9 | { 10 | } 11 | 12 | TextInArchive::~TextInArchive() 13 | { 14 | } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/serialize/TextOutArchive.cpp: -------------------------------------------------------------------------------- 1 | #include "serialize/TextOutArchive.hpp" 2 | 3 | namespace glr 4 | { 5 | namespace serialize 6 | { 7 | 8 | TextOutArchive::TextOutArchive(std::ofstream& ofstream) : boost::archive::text_oarchive(ofstream) 9 | { 10 | } 11 | 12 | TextOutArchive::~TextOutArchive() 13 | { 14 | } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/terrain/TerrainMeshSerializer.cpp: -------------------------------------------------------------------------------- 1 | #include "terrain/TerrainMeshSerializer.hpp" 2 | 3 | namespace glr 4 | { 5 | namespace terrain 6 | { 7 | 8 | /** 9 | * 10 | */ 11 | void serialize(const std::string& filename, TerrainMesh& terrainMesh) 12 | { 13 | std::ofstream stream(filename, std::ios::out | std::ios::binary); 14 | serialize(stream, terrainMesh); 15 | } 16 | 17 | void deserialize(const std::string& filename, TerrainMesh& terrainMesh) 18 | { 19 | std::ifstream stream(filename, std::ios::in | std::ios::binary); 20 | deserialize(stream, terrainMesh); 21 | } 22 | 23 | void serialize(std::ofstream& stream, TerrainMesh& terrainMesh) 24 | { 25 | auto vertices = terrainMesh.getVertices(); 26 | 27 | glmd::int32 size = vertices.size(); 28 | stream.write((char*)&size, sizeof(glmd::int32)); 29 | 30 | for ( auto& v : vertices) 31 | stream.write((char*)&v, sizeof(glm::vec3)); 32 | } 33 | 34 | void deserialize(std::ifstream& stream, TerrainMesh& terrainMesh) 35 | { 36 | glmd::int32 size = 0; 37 | stream.read((char*)&size, sizeof(glmd::int32)); 38 | 39 | auto vertices = std::vector( size ); 40 | 41 | for ( auto& v : vertices) 42 | stream.read((char*)&v, sizeof(glm::vec3)); 43 | 44 | terrainMesh.setVertices( vertices ); 45 | } 46 | 47 | /* 48 | void TerrainMesh::serialize(const std::string& filename) 49 | { 50 | std::ofstream stream(filename, std::ios::out | std::ios::binary); 51 | serialize(stream); 52 | } 53 | 54 | void TerrainMesh::deserialize(const std::string& filename) 55 | { 56 | std::ifstream stream(filename, std::ios::in | std::ios::binary); 57 | deserialize(stream); 58 | } 59 | 60 | void TerrainMesh::serialize(std::ofstream& stream) 61 | { 62 | glmd::int32 size = vertices_.size(); 63 | stream.write((char*)&size, sizeof(glmd::int32)); 64 | 65 | for ( auto& v : vertices_) 66 | stream.write((char*)&v, sizeof(glm::vec3)); 67 | } 68 | 69 | void TerrainMesh::deserialize(std::ifstream& stream) 70 | { 71 | glmd::int32 size = 0; 72 | stream.read((char*)&size, sizeof(glmd::int32)); 73 | 74 | vertices_ = std::vector( size ); 75 | 76 | for ( auto& v : vertices_) 77 | stream.read((char*)&v, sizeof(glm::vec3)); 78 | } 79 | */ 80 | 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/terrain/Voxel.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jarrettchisholm/glr/79a57b12e26fe84595e833cace3528cb9c82bc20/src/terrain/Voxel.cpp -------------------------------------------------------------------------------- /src/terrain/VoxelChunk.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jarrettchisholm/glr/79a57b12e26fe84595e833cace3528cb9c82bc20/src/terrain/VoxelChunk.cpp -------------------------------------------------------------------------------- /src/terrain/VoxelChunkCache.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jarrettchisholm/glr/79a57b12e26fe84595e833cace3528cb9c82bc20/src/terrain/VoxelChunkCache.cpp -------------------------------------------------------------------------------- /tests/build_and_run.py: -------------------------------------------------------------------------------- 1 | import subprocess, sys, os 2 | import shlex 3 | 4 | args = '' 5 | for arg in sys.argv: 6 | if (arg != 'tests/build_and_run.py' and arg != 'build_and_run.py'): 7 | args += ' ' + arg 8 | 9 | subprocess.call( 'scons ' + args, shell=True) 10 | 11 | print("Running Tests") 12 | 13 | os.chdir( 'build/' ) 14 | subprocess.call( "./glr_tests" ) 15 | 16 | -------------------------------------------------------------------------------- /tests/src/FpsCameraTests.cpp: -------------------------------------------------------------------------------- 1 | #define BOOST_TEST_DYN_LINK 2 | #ifdef STAND_ALONE 3 | # define BOOST_TEST_MODULE Main 4 | #endif 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #define GLM_FORCE_RADIANS 11 | #include "glm/glm.hpp" 12 | 13 | #include "GlrInclude.hpp" 14 | 15 | #include "../extras/FpsCamera.cpp" 16 | 17 | BOOST_AUTO_TEST_SUITE(fpsCamera) 18 | 19 | BOOST_AUTO_TEST_CASE(createFpsCamera) 20 | { 21 | auto p = std::unique_ptr( new glr::GlrProgram() ); 22 | 23 | p->createWindow(); 24 | 25 | glr::ISceneManager* smgr = p->getSceneManager(); 26 | glr::ICamera* camera = smgr->createCamera(); 27 | camera->setPosition(0, 0, 0); 28 | 29 | auto fpsCamera = std::unique_ptr< glr::extras::FpsCamera >( new glr::extras::FpsCamera(camera, 0.060f) ); 30 | 31 | glm::vec3 pos = camera->getPosition(); 32 | BOOST_CHECK_EQUAL( pos.x, 0.0f ); 33 | BOOST_CHECK_EQUAL( pos.y, 0.0f ); 34 | BOOST_CHECK_EQUAL( pos.z, 0.0f ); 35 | } 36 | 37 | BOOST_AUTO_TEST_SUITE_END() 38 | -------------------------------------------------------------------------------- /tests/src/GlrProgramTests.cpp: -------------------------------------------------------------------------------- 1 | #define BOOST_TEST_DYN_LINK 2 | #ifdef STAND_ALONE 3 | # define BOOST_TEST_MODULE Main 4 | #endif 5 | #include 6 | 7 | #include "GlrInclude.hpp" 8 | 9 | BOOST_AUTO_TEST_SUITE(glrProgram) 10 | 11 | BOOST_AUTO_TEST_CASE(bindBuffer) 12 | { 13 | glr::GlrProgram* p = new glr::GlrProgram(); 14 | 15 | p->createWindow(); 16 | 17 | // Using a less complicated algorithm for now... 18 | /* 19 | BOOST_CHECK_EQUAL( p->bindBuffer(1), 1 ); 20 | BOOST_CHECK_EQUAL( p->bindBuffer(1), 1 ); 21 | BOOST_CHECK_EQUAL( p->bindBuffer(4), 2 ); 22 | BOOST_CHECK_EQUAL( p->bindBuffer(99), 3 ); 23 | BOOST_CHECK_EQUAL( p->bindBuffer(4), 2 ); 24 | */ 25 | 26 | /* 27 | BOOST_CHECK_EQUAL( p->bindBuffer(1), 1 ); 28 | BOOST_CHECK_EQUAL( p->bindBuffer(1), 2 ); 29 | BOOST_CHECK_EQUAL( p->bindBuffer(2), 3 ); 30 | BOOST_CHECK_EQUAL( p->bindBuffer(99), 4 ); 31 | BOOST_CHECK_EQUAL( p->bindBuffer(7), 5 ); 32 | */ 33 | 34 | delete p; 35 | } 36 | 37 | BOOST_AUTO_TEST_SUITE_END() 38 | -------------------------------------------------------------------------------- /tests/src/Main.cpp: -------------------------------------------------------------------------------- 1 | #define BOOST_TEST_DYN_LINK 2 | #define BOOST_TEST_MODULE Main 3 | #include 4 | -------------------------------------------------------------------------------- /tests/src/SceneManagerTests.cpp: -------------------------------------------------------------------------------- 1 | #define BOOST_TEST_DYN_LINK 2 | #ifdef STAND_ALONE 3 | # define BOOST_TEST_MODULE Main 4 | #endif 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #define GLM_FORCE_RADIANS 12 | #include "glm/glm.hpp" 13 | #include "glm/gtc/quaternion.hpp" 14 | 15 | #include "GlrInclude.hpp" 16 | 17 | 18 | BOOST_AUTO_TEST_SUITE(sceneNodeManager) 19 | 20 | BOOST_AUTO_TEST_CASE(createSceneNodeManager) 21 | { 22 | //auto snm = std::make_unique( nullptr, nullptr, nullptr, nullptr ); 23 | 24 | auto p = std::unique_ptr( new glr::GlrProgram() ); 25 | 26 | p->createWindow(); 27 | 28 | glr::ISceneManager* smgr = p->getSceneManager(); 29 | 30 | 31 | // Single create/destroy test 32 | glr::ISceneNode* node = smgr->createSceneNode( std::string("test") ); 33 | 34 | BOOST_REQUIRE( node != nullptr ); 35 | BOOST_CHECK_EQUAL( smgr->getNumSceneNodes(), 1u ); 36 | 37 | smgr->destroySceneNode( node ); 38 | 39 | BOOST_CHECK_EQUAL( smgr->getNumSceneNodes(), 0u ); 40 | 41 | // Make sure node was actually deleted 42 | node = smgr->getSceneNode( std::string("test") ); 43 | 44 | BOOST_REQUIRE( node == nullptr ); 45 | BOOST_CHECK_EQUAL( smgr->getNumSceneNodes(), 0u ); 46 | 47 | 48 | // Create/destroy multiple scene nodes 49 | for ( int i=0; i < 30; i++ ) 50 | { 51 | std::stringstream ss; 52 | ss << std::string("test_node_") << i; 53 | smgr->createSceneNode( ss.str() ); 54 | } 55 | 56 | BOOST_CHECK_EQUAL( smgr->getNumSceneNodes(), 30u ); 57 | 58 | // Make sure we can get all of the scene nodes by name 59 | for ( int i=0; i < 30; i++ ) 60 | { 61 | std::stringstream ss; 62 | ss << std::string("test_node_") << i; 63 | node = smgr->getSceneNode( ss.str() ); 64 | BOOST_REQUIRE( node != nullptr ); 65 | } 66 | 67 | // Make sure we don't get an erroneous node 68 | node = smgr->getSceneNode( std::string("test_node_30") ); 69 | BOOST_REQUIRE( node == nullptr ); 70 | 71 | // Test destroying one of the nodes 72 | smgr->destroySceneNode( std::string("test_node_4") ); 73 | node = smgr->getSceneNode( std::string("test_node_4") ); 74 | BOOST_REQUIRE( node == nullptr ); 75 | 76 | BOOST_CHECK_EQUAL( smgr->getNumSceneNodes(), 29u ); 77 | 78 | // Test destroying the remaining nodes 79 | smgr->destroyAllSceneNodes(); 80 | 81 | BOOST_CHECK_EQUAL( smgr->getNumSceneNodes(), 0u ); 82 | } 83 | 84 | BOOST_AUTO_TEST_SUITE_END() 85 | -------------------------------------------------------------------------------- /tests/src/shaders/glr.glsl: -------------------------------------------------------------------------------- 1 | #type na 2 | 3 | uniform mat4 projectionMatrix; 4 | uniform mat4 viewMatrix; 5 | uniform mat4 modelMatrix; 6 | uniform mat4 pvmMatrix; 7 | uniform mat3 normalMatrix; 8 | -------------------------------------------------------------------------------- /tests/src/shaders/glr_basic.program: -------------------------------------------------------------------------------- 1 | #name glr_basic 2 | #type program 3 | 4 | #include "shader.vert" 5 | #include "shader.frag" 6 | -------------------------------------------------------------------------------- /tests/src/shaders/light.glsl: -------------------------------------------------------------------------------- 1 | #type na 2 | 3 | struct LightSource { 4 | vec4 ambient; 5 | vec4 diffuse; 6 | vec4 specular; 7 | vec4 position; 8 | vec4 direction; 9 | }; 10 | -------------------------------------------------------------------------------- /tests/src/shaders/material.glsl: -------------------------------------------------------------------------------- 1 | #type na 2 | 3 | struct Material { 4 | vec4 ambient; 5 | vec4 diffuse; 6 | vec4 specular; 7 | float shininess; 8 | }; 9 | -------------------------------------------------------------------------------- /tests/src/shaders/shader.frag: -------------------------------------------------------------------------------- 1 | #version 150 core 2 | 3 | #type fragment 4 | 5 | @bind texture0 6 | uniform sampler2D texture; 7 | 8 | in vec4 pass_Color; 9 | in vec2 textureCoord; 10 | 11 | void main() { 12 | vec4 out_Color = texture2D(texture, textureCoord); 13 | 14 | gl_FragColor = pass_Color; 15 | 16 | //gl_FragColor = out_Color; 17 | } 18 | -------------------------------------------------------------------------------- /tests/src/shaders/shader.vert: -------------------------------------------------------------------------------- 1 | #version 150 core 2 | 3 | #ifndef NUM_LIGHTS 4 | #define NUM_LIGHTS 1 5 | #endif 6 | 7 | #type vertex 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | in vec3 in_Position; 14 | in vec2 in_Texture; 15 | in vec3 in_Normal; 16 | 17 | out vec2 textureCoord; 18 | out vec4 pass_Color; 19 | 20 | 21 | //@bind texture0 22 | uniform sampler2D texture; 23 | 24 | //@bind texture0 25 | uniform 26 | sampler2D 27 | texture2 28 | ; 29 | 30 | @bind Light 31 | layout(std140) 32 | uniform 33 | LightSources 34 | { 35 | LightSource lightSources[ NUM_LIGHTS ]; 36 | }; 37 | 38 | @bind Light2 39 | layout(std140) uniform LightSources2 { 40 | LightSource lightSources2[ NUM_LIGHTS ]; 41 | }; 42 | 43 | 44 | @bind Light2 45 | uniform LightSources3 46 | { 47 | LightSource lightSources3[ NUM_LIGHTS ]; 48 | }; 49 | 50 | @bind Material 51 | Material material = Material( 52 | vec4(1.0, 0.8, 0.8, 1.0), 53 | vec4(1.0, 0.8, 0.8, 1.0), 54 | vec4(1.0, 0.8, 0.8, 1.0), 55 | 0.995 56 | ); 57 | 58 | @bind Color 59 | Material color = Material ( 60 | vec4(1.0, 0.8, 0.8, 1.0), 61 | vec4(1.0, 0.8, 0.8, 1.0), 62 | vec4(1.0, 0.8, 0.8, 1.0), 63 | 0.995 64 | ); 65 | 66 | @bind Color 67 | Material color2 = Material ( 68 | vec4(1.0, 0.8, 0.8, 1.0), 69 | vec4(1.0, 0.8, 0.8, 1.0), 70 | vec4(1.0, 0.8, 0.8, 1.0), 71 | 0.995 72 | ) 73 | ; 74 | 75 | 76 | void main() { 77 | gl_Position = pvmMatrix * vec4(in_Position, 1.0); 78 | 79 | textureCoord = in_Texture; 80 | 81 | vec3 normalDirection = normalize(normalMatrix * in_Normal); 82 | vec3 lightDirection = normalize(vec3(lightSources[0].direction)); 83 | 84 | vec3 diffuseReflection = vec3(lightSources[0].diffuse) * vec3(material.diffuse) * max(0.0, dot(normalDirection, lightDirection)); 85 | 86 | /* 87 | float bug = 0.0; 88 | bvec3 result = equal( diffuseReflection, vec3(0.0, 0.0, 0.0) ); 89 | if(result[0] && result[1] && result[2]) bug = 1.0; 90 | diffuseReflection.x += bug; 91 | */ 92 | 93 | /* 94 | float bug2 = 0.0; 95 | bool result2 = dot(normalDirection, lightDirection) > 0.0; 96 | if(result2) bug2 = 1.0; 97 | diffuseReflection.x += bug2; 98 | */ 99 | 100 | pass_Color = vec4(diffuseReflection, 1.0); 101 | //pass_Color = vec4((0.5 * normalDirection) + vec3(0.5), 1.0); 102 | //pass_Color = ambient; 103 | } 104 | --------------------------------------------------------------------------------