├── .gitattributes ├── CMakeLists.txt ├── README.md ├── Sandbox ├── CMakeLists.txt ├── res │ ├── config │ │ ├── Config.lua │ │ └── Imgui.ini │ ├── devlog │ │ ├── 2019-12-13 15-09-52.mkv │ │ ├── SponzaLight.png │ │ ├── TerrainFog.png │ │ ├── deferred.png │ │ ├── forward.png │ │ ├── terrain.png │ │ ├── terrainWithTrees.png │ │ └── water.png │ └── scene │ │ ├── particles.lua │ │ ├── sponza.lua │ │ ├── start.lua │ │ ├── terrain.lua │ │ └── water.lua └── src │ ├── ClientLog.h │ ├── EmptyState.cpp │ ├── EmptyState.h │ ├── Sandbox.cpp │ └── new │ ├── NewState.cpp │ └── NewState.h ├── SgOglLib ├── CMakeLists.txt ├── res │ └── shader │ │ ├── compute │ │ ├── normalmap.comp │ │ └── splatmap.comp │ │ ├── dome │ │ ├── Fragment.frag │ │ └── Vertex.vert │ │ ├── gbuffer_pass │ │ ├── Fragment.frag │ │ └── Vertex.vert │ │ ├── gui │ │ ├── Fragment.frag │ │ └── Vertex.vert │ │ ├── gui_depth_map │ │ ├── Fragment.frag │ │ └── Vertex.vert │ │ ├── instancing │ │ ├── Fragment.frag │ │ └── Vertex.vert │ │ ├── lighting_pass │ │ ├── Fragment.frag │ │ └── Vertex.vert │ │ ├── model │ │ ├── Fragment.frag │ │ └── Vertex.vert │ │ ├── normal │ │ ├── Fragment.frag │ │ ├── Geometry.geom │ │ └── Vertex.vert │ │ ├── particle │ │ ├── Fragment.frag │ │ └── Vertex.vert │ │ ├── particle_inst │ │ ├── Fragment.frag │ │ └── Vertex.vert │ │ ├── skeletal_model │ │ ├── Fragment.frag │ │ └── Vertex.vert │ │ ├── skybox │ │ ├── Fragment.frag │ │ └── Vertex.vert │ │ ├── sun │ │ ├── Fragment.frag │ │ └── Vertex.vert │ │ ├── terrain_quadtree │ │ ├── Fragment.frag │ │ ├── Geometry.geom │ │ ├── TessControl.tesc │ │ ├── TessEval.tese │ │ └── Vertex.vert │ │ ├── terrain_quadtree_wireframe │ │ ├── Fragment.frag │ │ ├── Geometry.geom │ │ ├── TessControl.tesc │ │ ├── TessEval.tese │ │ └── Vertex.vert │ │ ├── text │ │ ├── Fragment.frag │ │ └── Vertex.vert │ │ └── water │ │ ├── Fragment.frag │ │ └── Vertex.vert ├── src │ ├── SgOgl.h │ ├── SgOglEntryPoint.h │ └── SgOglLib │ │ ├── Application.cpp │ │ ├── Application.h │ │ ├── Color.cpp │ │ ├── Color.h │ │ ├── Config.cpp │ │ ├── Config.h │ │ ├── Core.h │ │ ├── EntryPoint.h │ │ ├── Log.h │ │ ├── LuaScript.cpp │ │ ├── LuaScript.h │ │ ├── OpenGl.cpp │ │ ├── OpenGl.h │ │ ├── Random.cpp │ │ ├── Random.h │ │ ├── SgOglException.cpp │ │ ├── SgOglException.h │ │ ├── Window.cpp │ │ ├── Window.h │ │ ├── buffer │ │ ├── BufferLayout.cpp │ │ ├── BufferLayout.h │ │ ├── Fbo.cpp │ │ ├── Fbo.h │ │ ├── GBufferFbo.cpp │ │ ├── GBufferFbo.h │ │ ├── Vao.cpp │ │ ├── Vao.h │ │ ├── Vbo.cpp │ │ ├── Vbo.h │ │ ├── VertexAttribute.h │ │ ├── WaterFbos.cpp │ │ └── WaterFbos.h │ │ ├── camera │ │ ├── Camera.cpp │ │ ├── Camera.h │ │ ├── FirstPersonCamera.cpp │ │ ├── FirstPersonCamera.h │ │ ├── ThirdPersonCamera.cpp │ │ └── ThirdPersonCamera.h │ │ ├── ecs │ │ ├── component │ │ │ └── Components.h │ │ └── system │ │ │ ├── DeferredRenderSystem.h │ │ │ ├── ForwardRenderSystem.h │ │ │ ├── GuiRenderSystem.h │ │ │ ├── InstancingRenderSystem.h │ │ │ ├── ParticleSystemRenderer.h │ │ │ ├── RenderSystem.h │ │ │ ├── RenderSystemInterface.h │ │ │ ├── SkeletalModelRenderSystem.h │ │ │ ├── SkyboxRenderSystem.h │ │ │ ├── SkydomeRenderSystem.h │ │ │ ├── SunRenderSystem.h │ │ │ ├── TerrainQuadtreeRenderSystem.h │ │ │ ├── TerrainQuadtreeWfRenderSystem.h │ │ │ ├── TextRenderSystem.h │ │ │ └── WaterRenderSystem.h │ │ ├── event │ │ ├── CircularEventQueue.cpp │ │ ├── CircularEventQueue.h │ │ └── EventCategories.h │ │ ├── imgui │ │ ├── imgui_impl_glfw.cpp │ │ ├── imgui_impl_glfw.h │ │ ├── imgui_impl_opengl3.cpp │ │ └── imgui_impl_opengl3.h │ │ ├── input │ │ ├── MouseInput.cpp │ │ ├── MouseInput.h │ │ ├── MousePicker.cpp │ │ └── MousePicker.h │ │ ├── light │ │ ├── DirectionalLight.h │ │ ├── PointLight.h │ │ └── Sun.h │ │ ├── math │ │ ├── Plane.cpp │ │ ├── Plane.h │ │ └── Transform.h │ │ ├── particle │ │ ├── Particle.h │ │ ├── ParticleSystem.cpp │ │ └── ParticleSystem.h │ │ ├── resource │ │ ├── Material.cpp │ │ ├── Material.h │ │ ├── Mesh.cpp │ │ ├── Mesh.h │ │ ├── Model.cpp │ │ ├── Model.h │ │ ├── ModelManager.cpp │ │ ├── ModelManager.h │ │ ├── ShaderManager.cpp │ │ ├── ShaderManager.h │ │ ├── ShaderProgram.cpp │ │ ├── ShaderProgram.h │ │ ├── ShaderUtil.h │ │ ├── SkeletalModel.cpp │ │ ├── SkeletalModel.h │ │ ├── TextureManager.cpp │ │ ├── TextureManager.h │ │ ├── shaderprogram │ │ │ ├── ComputeNormalmap.h │ │ │ ├── ComputeSplatmap.h │ │ │ ├── DomeShaderProgram.h │ │ │ ├── GBufferPassShaderProgram.h │ │ │ ├── GuiShaderProgram.h │ │ │ ├── InstancingShaderProgram.h │ │ │ ├── LightingPassShaderProgram.h │ │ │ ├── ModelShaderProgram.h │ │ │ ├── ParticleSystemInstShaderProgram.h │ │ │ ├── ParticleSystemShaderProgram.h │ │ │ ├── SkeletalModelShaderProgram.h │ │ │ ├── SkyboxShaderProgram.h │ │ │ ├── SunShaderProgram.h │ │ │ ├── TerrainQuadtreeShaderProgram.h │ │ │ ├── TerrainQuadtreeWfShaderProgram.h │ │ │ ├── TextShaderProgram.h │ │ │ └── WaterShaderProgram.h │ │ └── stb_image.h │ │ ├── scene │ │ ├── Scene.cpp │ │ └── Scene.h │ │ ├── state │ │ ├── State.cpp │ │ ├── State.h │ │ ├── StateStack.cpp │ │ └── StateStack.h │ │ ├── terrain │ │ ├── Node.cpp │ │ ├── Node.h │ │ ├── TerrainConfig.cpp │ │ ├── TerrainConfig.h │ │ └── TerrainQuadtree.h │ │ └── water │ │ ├── Water.cpp │ │ └── Water.h └── vendor │ └── gli │ ├── gli │ ├── clear.hpp │ ├── comparison.hpp │ ├── convert.hpp │ ├── copy.hpp │ ├── core │ │ ├── bc.hpp │ │ ├── bc.inl │ │ ├── clear.hpp │ │ ├── clear.inl │ │ ├── comparison.inl │ │ ├── convert.inl │ │ ├── convert_func.hpp │ │ ├── coord.hpp │ │ ├── copy.inl │ │ ├── dummy.cpp │ │ ├── duplicate.inl │ │ ├── dx.inl │ │ ├── file.hpp │ │ ├── file.inl │ │ ├── filter.hpp │ │ ├── filter.inl │ │ ├── filter_compute.hpp │ │ ├── flip.hpp │ │ ├── flip.inl │ │ ├── format.inl │ │ ├── generate_mipmaps.inl │ │ ├── gl.inl │ │ ├── image.inl │ │ ├── levels.inl │ │ ├── load.inl │ │ ├── load_dds.inl │ │ ├── load_kmg.inl │ │ ├── load_ktx.inl │ │ ├── make_texture.inl │ │ ├── mipmaps_compute.hpp │ │ ├── reduce.inl │ │ ├── s3tc.hpp │ │ ├── s3tc.inl │ │ ├── sampler.inl │ │ ├── sampler1d.inl │ │ ├── sampler1d_array.inl │ │ ├── sampler2d.inl │ │ ├── sampler2d_array.inl │ │ ├── sampler3d.inl │ │ ├── sampler_cube.inl │ │ ├── sampler_cube_array.inl │ │ ├── save.inl │ │ ├── save_dds.inl │ │ ├── save_kmg.inl │ │ ├── save_ktx.inl │ │ ├── storage.hpp │ │ ├── storage.inl │ │ ├── storage_linear.hpp │ │ ├── storage_linear.inl │ │ ├── texture.inl │ │ ├── texture1d.inl │ │ ├── texture1d_array.inl │ │ ├── texture2d.inl │ │ ├── texture2d_array.inl │ │ ├── texture3d.inl │ │ ├── texture_cube.inl │ │ ├── texture_cube_array.inl │ │ ├── transform.inl │ │ ├── view.inl │ │ └── workaround.hpp │ ├── duplicate.hpp │ ├── dx.hpp │ ├── format.hpp │ ├── generate_mipmaps.hpp │ ├── gl.hpp │ ├── gli.hpp │ ├── image.hpp │ ├── levels.hpp │ ├── load.hpp │ ├── load_dds.hpp │ ├── load_kmg.hpp │ ├── load_ktx.hpp │ ├── make_texture.hpp │ ├── reduce.hpp │ ├── sampler.hpp │ ├── sampler1d.hpp │ ├── sampler1d_array.hpp │ ├── sampler2d.hpp │ ├── sampler2d_array.hpp │ ├── sampler3d.hpp │ ├── sampler_cube.hpp │ ├── sampler_cube_array.hpp │ ├── save.hpp │ ├── save_dds.hpp │ ├── save_kmg.hpp │ ├── save_ktx.hpp │ ├── target.hpp │ ├── texture.hpp │ ├── texture1d.hpp │ ├── texture1d_array.hpp │ ├── texture2d.hpp │ ├── texture2d_array.hpp │ ├── texture3d.hpp │ ├── texture_cube.hpp │ ├── texture_cube_array.hpp │ ├── transform.hpp │ ├── type.hpp │ └── view.hpp │ ├── manual.md │ └── readme.md ├── conanfile_cmake.txt ├── conanfile_premake.txt └── premake5.lua /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | SgOglLib/vendor/* linguist-vendored 7 | SgOglLib/src/SgOglLib/resource/*.h linguist-vendored 8 | 9 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.12) 2 | 3 | project(SgOgl) 4 | 5 | set(CMAKE_CXX_STANDARD 17) 6 | 7 | add_subdirectory(Sandbox) 8 | add_subdirectory(SgOglLib) 9 | -------------------------------------------------------------------------------- /Sandbox/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.12) 2 | 3 | project(Sandbox) 4 | 5 | set(CMAKE_CXX_STANDARD 17) 6 | 7 | file(GLOB_RECURSE SANDBOX_SRC_FILES 8 | "*.h" 9 | "*.cpp" 10 | ) 11 | 12 | include(../conanbuildinfo.cmake) 13 | conan_basic_setup() 14 | 15 | add_executable(${PROJECT_NAME} ${SANDBOX_SRC_FILES}) 16 | 17 | target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/src) 18 | 19 | target_link_libraries(${PROJECT_NAME} SgOglLib) 20 | -------------------------------------------------------------------------------- /Sandbox/res/config/Config.lua: -------------------------------------------------------------------------------- 1 | 2 | libResFolder = "E:/Dev/SgOgl/SgOglLib/res" 3 | 4 | window = { 5 | title = "Sandbox", 6 | compatibleProfile = false, 7 | debugContext = true, 8 | antialiasing = true, 9 | printFrameRate = true, 10 | glMajor = 4, 11 | glMinor = 3, 12 | fps = 60.0 13 | } 14 | 15 | projection = { 16 | fovDeg = 70.0, 17 | width = 1024, 18 | height = 768, 19 | near = 0.1, 20 | far = 10000.0 21 | } 22 | -------------------------------------------------------------------------------- /Sandbox/res/config/Imgui.ini: -------------------------------------------------------------------------------- 1 | [Window][Debug##Default] 2 | Pos=60,60 3 | Size=400,400 4 | Collapsed=0 5 | 6 | [Window][Animation] 7 | Pos=557,40 8 | Size=460,188 9 | Collapsed=0 10 | 11 | [Window][Sun] 12 | Pos=8,13 13 | Size=372,346 14 | Collapsed=0 15 | 16 | [Window][Water] 17 | Pos=12,14 18 | Size=484,140 19 | Collapsed=0 20 | 21 | [Window][Debug] 22 | Pos=617,36 23 | Size=377,176 24 | Collapsed=0 25 | 26 | -------------------------------------------------------------------------------- /Sandbox/res/devlog/2019-12-13 15-09-52.mkv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwe/SgOgl/f26959a08a65654dbf417f81810bc7b2a4f828ea/Sandbox/res/devlog/2019-12-13 15-09-52.mkv -------------------------------------------------------------------------------- /Sandbox/res/devlog/SponzaLight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwe/SgOgl/f26959a08a65654dbf417f81810bc7b2a4f828ea/Sandbox/res/devlog/SponzaLight.png -------------------------------------------------------------------------------- /Sandbox/res/devlog/TerrainFog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwe/SgOgl/f26959a08a65654dbf417f81810bc7b2a4f828ea/Sandbox/res/devlog/TerrainFog.png -------------------------------------------------------------------------------- /Sandbox/res/devlog/deferred.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwe/SgOgl/f26959a08a65654dbf417f81810bc7b2a4f828ea/Sandbox/res/devlog/deferred.png -------------------------------------------------------------------------------- /Sandbox/res/devlog/forward.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwe/SgOgl/f26959a08a65654dbf417f81810bc7b2a4f828ea/Sandbox/res/devlog/forward.png -------------------------------------------------------------------------------- /Sandbox/res/devlog/terrain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwe/SgOgl/f26959a08a65654dbf417f81810bc7b2a4f828ea/Sandbox/res/devlog/terrain.png -------------------------------------------------------------------------------- /Sandbox/res/devlog/terrainWithTrees.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwe/SgOgl/f26959a08a65654dbf417f81810bc7b2a4f828ea/Sandbox/res/devlog/terrainWithTrees.png -------------------------------------------------------------------------------- /Sandbox/res/devlog/water.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stwe/SgOgl/f26959a08a65654dbf417f81810bc7b2a4f828ea/Sandbox/res/devlog/water.png -------------------------------------------------------------------------------- /Sandbox/res/scene/particles.lua: -------------------------------------------------------------------------------- 1 | ------------------ 2 | -- Create Scene -- 3 | ------------------ 4 | 5 | scene = Scene.new(applicationContext) 6 | 7 | ----------------------------- 8 | -- Create and add Renderer -- 9 | ----------------------------- 10 | 11 | ForwardRenderer.new(1, scene) 12 | ParticleSystemRenderer.new(0, scene) 13 | 14 | ---------------------------- 15 | -- Create and add Cameras -- 16 | ---------------------------- 17 | 18 | firstPersonCamera = FirstPersonCamera.new("first_person_camera1", applicationContext, Vec3.new(6.0, 20.0, -27.0), 102.0, -16.0, scene) 19 | firstPersonCamera:SetCameraVelocity(48.0) 20 | firstPersonCamera:SetMouseSensitivity(0.1) 21 | 22 | ------------------ 23 | -- Config Scene -- 24 | ------------------ 25 | 26 | scene:SetCurrentCamera("first_person_camera1") 27 | 28 | -------------------- 29 | -- Load resources -- 30 | -------------------- 31 | 32 | plane = modelManager:GetModel("res/primitive/plane1/plane1.obj") 33 | 34 | --------------------------- 35 | -- Create ParticleSystem -- 36 | --------------------------- 37 | 38 | textureId = textureManager:LoadTexture("res/particle/fire.png") 39 | 40 | particleSystem = ParticleSystem.new("fire", textureId, 8, scene) 41 | particleSystem:SetParticlesPerSecond(24.0) 42 | particleSystem:SetSpeed(1.0) 43 | particleSystem:SetGravityEffect(-0.1) 44 | particleSystem:SetLifeTime(2.0) 45 | particleSystem:SetMaxScale(10.0) 46 | particleSystem.instancing = true 47 | 48 | --particleSystem = ParticleSystem.new("fire", textureId, 8, 24.0, 1.0, -0.1, 2.0, 10.0, scene) 49 | 50 | --------------------- 51 | -- Create Entities -- 52 | --------------------- 53 | 54 | particleSystemEntity = ecs:CreateEntity() 55 | ecs:AddParticleSystemComponent(particleSystemEntity, particleSystem) 56 | ecs:AddUpdateComponent(particleSystemEntity, "GenerateParticles") 57 | 58 | planeEntity = ecs:CreateEntity() 59 | ecs:AddModelComponent(planeEntity, plane, false) 60 | ecs:AddTransformComponent(planeEntity, Vec3.new(0.0, 0.0, 0.0), Vec3.new(0.0, 0.0, 0.0), Vec3.new(250.0, 1.0, 250.0)) 61 | 62 | --------------- 63 | -- Functions -- 64 | --------------- 65 | 66 | function GenerateParticles(entity, dt) 67 | particleSystem:GenerateParticles(dt, Vec3.new(0.0, 20.0, 0.0)) 68 | end 69 | -------------------------------------------------------------------------------- /Sandbox/res/scene/water.lua: -------------------------------------------------------------------------------- 1 | ------------------ 2 | -- Create Scene -- 3 | ------------------ 4 | 5 | scene = Scene.new(applicationContext) 6 | 7 | ----------------------------- 8 | -- Create and add Renderer -- 9 | ----------------------------- 10 | 11 | skyboxRenderer = SkyboxRenderer.new(2, scene) 12 | sunRenderer = SunRenderer.new(1, scene) 13 | WaterRenderer.new(0, scene) 14 | 15 | ---------------------------- 16 | -- Create and add Cameras -- 17 | ---------------------------- 18 | 19 | firstPersonCamera = FirstPersonCamera.new("first_person_camera1", applicationContext, Vec3.new(1334.0, 820.0, 227.0), -178.0, -22.0, scene) 20 | firstPersonCamera:SetCameraVelocity(128.0) 21 | firstPersonCamera:SetMouseSensitivity(0.025) 22 | 23 | ------------------ 24 | -- Config Scene -- 25 | ------------------ 26 | 27 | scene:SetCurrentCamera("first_person_camera1") 28 | scene:SetAmbientIntensity(Vec3.new(0.2, 0.2, 0.2)) 29 | 30 | -------------------- 31 | -- Load resources -- 32 | -------------------- 33 | 34 | -- sun 35 | 36 | sunTextureId = textureManager:LoadTexture("res/sun/sun.png") 37 | 38 | -- skybox 39 | 40 | a = {} 41 | a[1] = "res/skybox/sky1/sRight.png" 42 | a[2] = "res/skybox/sky1/sLeft.png" 43 | a[3] = "res/skybox/sky1/sUp.png" 44 | a[4] = "res/skybox/sky1/sDown.png" 45 | a[5] = "res/skybox/sky1/sBack.png" 46 | a[6] = "res/skybox/sky1/sFront.png" 47 | 48 | skyboxCubemapId = textureManager:GetCubemapId(a) 49 | 50 | -- water 51 | 52 | local xWaterPos = 0.0 53 | local zWaterPos = 0.0 54 | local waterHeight = 0.0 55 | local waterTileSize = 5000.0 56 | 57 | ocean = Water.new( 58 | "ocean", 59 | applicationContext, 60 | xWaterPos, zWaterPos, 61 | waterHeight, 62 | Vec3.new(waterTileSize, 1.0, waterTileSize), 63 | "res/water/waterDUDV.png", "res/water/normal.png", 64 | scene 65 | ) 66 | 67 | ocean:AddRendererToReflectionTexture(skyboxRenderer) 68 | ocean:AddRendererToReflectionTexture(sunRenderer) 69 | 70 | ocean:AddRendererToRefractionTexture(skyboxRenderer) 71 | ocean:AddRendererToRefractionTexture(sunRenderer) 72 | 73 | --------------------- 74 | -- Create Entities -- 75 | --------------------- 76 | 77 | -- sun 78 | 79 | sunEntity = ecs:CreateEntity() 80 | ecs:AddSunComponent(sunEntity, 81 | Vec3.new(1.0, -0.2, -0.4), -- direction 82 | Vec3.new(1.0, 0.8, 0.6), -- diffuseIntensity 83 | Vec3.new(1.0, 0.8, 0.6), -- specularIntensity 84 | sunTextureId, 85 | 10.0 86 | ) 87 | 88 | -- skybox 89 | 90 | skyboxEntity = ecs:CreateEntity() 91 | ecs:AddCubemapComponent(skyboxEntity, skyboxCubemapId) 92 | 93 | -- water 94 | 95 | oceanEntity = ecs:CreateEntity() 96 | ecs:AddWaterComponent(oceanEntity, ocean) 97 | ecs:AddTransformComponent(oceanEntity, Vec3.new(xWaterPos, waterHeight, zWaterPos), Vec3.new(0.0, 0.0, 0.0), Vec3.new(waterTileSize, 1.0, waterTileSize)) 98 | -------------------------------------------------------------------------------- /Sandbox/src/ClientLog.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: ClientLog.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | class ClientLog 16 | { 17 | public: 18 | using LoggerSharedPtr = std::shared_ptr; 19 | 20 | static void Init() 21 | { 22 | spdlog::set_pattern("%^[%T] %n: %v%$"); 23 | 24 | m_logger = spdlog::stdout_color_mt("Sandbox"); 25 | 26 | #ifdef SG_OGL_DEBUG_BUILD 27 | m_logger->set_level(spdlog::level::trace); 28 | #else 29 | m_logger->set_level(spdlog::level::info); 30 | #endif 31 | } 32 | 33 | template 34 | static void SG_SANDBOX_LOG_TRACE(T ...t_args) 35 | { 36 | m_logger->trace(t_args...); 37 | } 38 | 39 | template 40 | static void SG_SANDBOX_LOG_DEBUG(T ...t_args) 41 | { 42 | m_logger->debug(t_args...); 43 | } 44 | 45 | template 46 | static void SG_SANDBOX_LOG_INFO(T ...t_args) 47 | { 48 | m_logger->info(t_args...); 49 | } 50 | 51 | template 52 | static void SG_SANDBOX_LOG_WARN(T ...t_args) 53 | { 54 | m_logger->warn(t_args...); 55 | } 56 | 57 | template 58 | static void SG_SANDBOX_LOG_ERROR(T ...t_args) 59 | { 60 | m_logger->error(t_args...); 61 | } 62 | 63 | template 64 | static void SG_SANDBOX_LOG_FATAL(T ...t_args) 65 | { 66 | m_logger->critical(t_args...); 67 | } 68 | 69 | protected: 70 | 71 | private: 72 | inline static LoggerSharedPtr m_logger; 73 | }; 74 | 75 | -------------------------------------------------------------------------------- /Sandbox/src/EmptyState.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: EmptyState.cpp 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2019 (c) stwe 9 | 10 | #include "EmptyState.h" 11 | 12 | //------------------------------------------------- 13 | // Logic 14 | //------------------------------------------------- 15 | 16 | bool EmptyState::Input() 17 | { 18 | return true; 19 | } 20 | 21 | bool EmptyState::Update(double t_dt) 22 | { 23 | return true; 24 | } 25 | 26 | void EmptyState::Render() 27 | { 28 | } 29 | 30 | //------------------------------------------------- 31 | // Helper 32 | //------------------------------------------------- 33 | 34 | void EmptyState::Init() 35 | { 36 | // set clear color 37 | sg::ogl::OpenGl::SetClearColor(sg::ogl::Color::CornflowerBlue()); 38 | } 39 | -------------------------------------------------------------------------------- /Sandbox/src/EmptyState.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: EmptyState.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2019 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include "SgOgl.h" 13 | #include "ClientLog.h" 14 | 15 | class EmptyState : public sg::ogl::state::State 16 | { 17 | public: 18 | //------------------------------------------------- 19 | // Ctors. / Dtor. 20 | //------------------------------------------------- 21 | 22 | EmptyState() = delete; 23 | 24 | explicit EmptyState(sg::ogl::state::StateStack* t_stateStack) 25 | : State{ t_stateStack, "EmptyState" } 26 | { 27 | Init(); 28 | } 29 | 30 | EmptyState(const EmptyState& t_other) = delete; 31 | EmptyState(EmptyState&& t_other) noexcept = delete; 32 | EmptyState& operator=(const EmptyState& t_other) = delete; 33 | EmptyState& operator=(EmptyState&& t_other) noexcept = delete; 34 | 35 | ~EmptyState() noexcept override 36 | { 37 | ClientLog::SG_SANDBOX_LOG_DEBUG("[EmptyState::~EmptyState()] Destruct EmptyState."); 38 | } 39 | 40 | //------------------------------------------------- 41 | // Logic 42 | //------------------------------------------------- 43 | 44 | bool Input() override; 45 | bool Update(double t_dt) override; 46 | void Render() override; 47 | 48 | protected: 49 | 50 | private: 51 | //------------------------------------------------- 52 | // Helper 53 | //------------------------------------------------- 54 | 55 | void Init(); 56 | }; 57 | -------------------------------------------------------------------------------- /Sandbox/src/Sandbox.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: Sandbox.cpp 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2019 (c) stwe 9 | 10 | #include "SgOgl.h" 11 | #include "SgOglEntryPoint.h" 12 | #include "ClientLog.h" 13 | #include "new/NewState.h" 14 | 15 | class Sandbox final : public sg::ogl::Application 16 | { 17 | public: 18 | //------------------------------------------------- 19 | // Ctors. / Dtor. 20 | //------------------------------------------------- 21 | 22 | Sandbox() = delete; 23 | 24 | explicit Sandbox(const std::string& t_configFileName) 25 | : Application{ t_configFileName } 26 | { 27 | ClientLog::Init(); 28 | ClientLog::SG_SANDBOX_LOG_DEBUG("[Sandbox::Sandbox()] Create Sandbox."); 29 | } 30 | 31 | Sandbox(const Sandbox& t_other) = delete; 32 | Sandbox(Sandbox&& t_other) noexcept = delete; 33 | Sandbox& operator=(const Sandbox& t_other) = delete; 34 | Sandbox& operator=(Sandbox&& t_other) noexcept = delete; 35 | 36 | ~Sandbox() noexcept override 37 | { 38 | ClientLog::SG_SANDBOX_LOG_DEBUG("[Sandbox::~Sandbox()] Destruct Sandbox."); 39 | } 40 | 41 | protected: 42 | //------------------------------------------------- 43 | // Override 44 | //------------------------------------------------- 45 | 46 | void RegisterStates() override 47 | { 48 | ClientLog::SG_SANDBOX_LOG_DEBUG("[Sandbox::RegisterStates()] Register State: NewState as Game."); 49 | GetStateStack().RegisterState(sg::ogl::state::GAME); 50 | } 51 | 52 | void Init() override 53 | { 54 | ClientLog::SG_SANDBOX_LOG_DEBUG("[Sandbox::Init()] Init (Push) Game State."); 55 | GetStateStack().PushState(sg::ogl::state::GAME); 56 | } 57 | 58 | private: 59 | 60 | }; 61 | 62 | //------------------------------------------------- 63 | // EntryPoint 64 | //------------------------------------------------- 65 | 66 | std::unique_ptr sg::ogl::create_application() 67 | { 68 | return std::make_unique("res/config/Config.lua"); 69 | } 70 | -------------------------------------------------------------------------------- /Sandbox/src/new/NewState.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: NewState.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include "SgOgl.h" 13 | #include "ClientLog.h" 14 | 15 | class NewState : public sg::ogl::state::State 16 | { 17 | public: 18 | using LuaScriptUniquePtr = std::unique_ptr; 19 | 20 | //------------------------------------------------- 21 | // Ctors. / Dtor. 22 | //------------------------------------------------- 23 | 24 | NewState() = delete; 25 | 26 | explicit NewState(sg::ogl::state::StateStack* t_stateStack) 27 | : State{ t_stateStack, "NewState" } 28 | { 29 | Init(); 30 | } 31 | 32 | NewState(const NewState& t_other) = delete; 33 | NewState(NewState&& t_other) noexcept = delete; 34 | NewState& operator=(const NewState& t_other) = delete; 35 | NewState& operator=(NewState&& t_other) noexcept = delete; 36 | 37 | ~NewState() noexcept override 38 | { 39 | ClientLog::SG_SANDBOX_LOG_DEBUG("[NewState::~NewState()] Destruct NewState."); 40 | CleanUpImGui(); 41 | } 42 | 43 | //------------------------------------------------- 44 | // Logic 45 | //------------------------------------------------- 46 | 47 | bool Input() override; 48 | bool Update(double t_dt) override; 49 | void Render() override; 50 | 51 | protected: 52 | 53 | private: 54 | LuaScriptUniquePtr m_luaScript; 55 | 56 | //------------------------------------------------- 57 | // Helper 58 | //------------------------------------------------- 59 | 60 | void Init(); 61 | 62 | //------------------------------------------------- 63 | // ImGui 64 | //------------------------------------------------- 65 | 66 | void InitImGui() const; 67 | void RenderImGui() const; 68 | static void CleanUpImGui(); 69 | }; 70 | -------------------------------------------------------------------------------- /SgOglLib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.12) 2 | 3 | project(SgOglLib) 4 | 5 | set(CMAKE_CXX_STANDARD 17) 6 | 7 | file(GLOB_RECURSE LIB_SRC_FILES 8 | "*.h" 9 | "*.cpp" 10 | ) 11 | 12 | include(../conanbuildinfo.cmake) 13 | conan_basic_setup() 14 | 15 | add_library(${PROJECT_NAME} STATIC ${LIB_SRC_FILES}) 16 | 17 | target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/src) 18 | target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/src/SgOglLib) 19 | target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/vendor/gli) 20 | 21 | if (CMAKE_BUILD_TYPE MATCHES Debug) 22 | message("-- USE STATIC DEBUG SETUP --") 23 | target_compile_definitions(${PROJECT_NAME} PUBLIC SG_OGL_DEBUG_BUILD GLFW_INCLUDE_NONE) 24 | else() 25 | message("-- USE STATIC RELEASE SETUP --") 26 | target_compile_definitions(${PROJECT_NAME} PUBLIC GLFW_INCLUDE_NONE) 27 | endif() 28 | 29 | target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) 30 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/compute/normalmap.comp: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | // normalmap.comp 4 | 5 | layout (local_size_x = 16, local_size_y = 16) in; 6 | 7 | layout (binding = 0, rgba32f) uniform writeonly image2D normalmap; 8 | 9 | uniform sampler2D heightmap; 10 | uniform int heightmapWidth; 11 | uniform float normalStrength; 12 | 13 | void main() 14 | { 15 | // t0 -- t1 -- t2 16 | // | | | 17 | // t3 -- h -- t4 18 | // | | | 19 | // t5 -- t6 -- t7 20 | 21 | ivec2 xy = ivec2(gl_GlobalInvocationID.xy); 22 | vec2 texCoord = gl_GlobalInvocationID.xy / float(heightmapWidth); 23 | 24 | float texelSize = 1.0 / heightmapWidth; 25 | 26 | float t0 = texture(heightmap, texCoord + vec2(-texelSize, -texelSize)).r; 27 | float t1 = texture(heightmap, texCoord + vec2(0.0, -texelSize)).r; 28 | float t2 = texture(heightmap, texCoord + vec2(texelSize, -texelSize)).r; 29 | float t3 = texture(heightmap, texCoord + vec2(-texelSize, 0.0)).r; 30 | float t4 = texture(heightmap, texCoord + vec2(texelSize, 0.0)).r; 31 | float t5 = texture(heightmap, texCoord + vec2(-texelSize, texelSize)).r; 32 | float t6 = texture(heightmap, texCoord + vec2(0.0, texelSize)).r; 33 | float t7 = texture(heightmap, texCoord + vec2(texelSize, texelSize)).r; 34 | 35 | vec3 normal; 36 | 37 | normal.z = 1.0 / normalStrength; 38 | normal.x = t0 + 2 * t3 + t5 - t2 - 2 * t4 - t7; 39 | normal.y = t0 + 2 * t1 + t2 - t5 - 2 * t6 - t7; 40 | 41 | // Compute x using Sobel: 42 | // -1 0 1 43 | // -2 0 2 44 | // -1 0 1 45 | //float x = t2 + 2 * t4 + t7 - t0 - 2 * t3 - t5; 46 | 47 | // Compute y using Sobel: 48 | // -1 -2 -1 49 | // 0 0 0 50 | // 1 2 1 51 | //float y = t5 + 2 * t6 + t7 - t0 - 2 * t1 - t2; 52 | 53 | // Build the normalized normal 54 | //vec4 n = vec4(normalize(vec3(x, y, 1.0 / normalStrength)), 1.0); 55 | 56 | // Convert (-1.0, 1.0) to (0.0, 1.0) 57 | //n = n * 0.5 + 0.5; 58 | 59 | //imageStore(normalmap, xy, vec4((normalize(normal) + 1.0) / 2.0, 1.0)); 60 | imageStore(normalmap, xy, vec4(normalize(normal), 1.0)); 61 | } 62 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/compute/splatmap.comp: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | // splatmap.comp 4 | 5 | layout (local_size_x = 16, local_size_y = 16) in; 6 | 7 | layout (binding = 0, rgba32f) uniform writeonly image2D splatmap; 8 | 9 | uniform sampler2D normalmap; 10 | uniform int heightmapWidth; 11 | 12 | void main() 13 | { 14 | ivec2 xy = ivec2(gl_GlobalInvocationID.xy); 15 | vec2 texCoord = gl_GlobalInvocationID.xy / float(heightmapWidth); 16 | 17 | vec3 normalizedNormal = normalize(texture(normalmap, texCoord).rgb); 18 | 19 | vec4 color = vec4(0.0, 0.0, 0.0, 0.0); 20 | 21 | float slope = normalizedNormal.z; 22 | 23 | if (slope > 0.82) 24 | { 25 | color.x = 1.0; // r -> Sand or snow 26 | } 27 | else if (slope > 0.62) 28 | { 29 | color.y = 1.0; // g -> grass 30 | } 31 | else if (slope > 0.32) 32 | { 33 | color.z = 1.0; // b -> rock 34 | } 35 | else 36 | { 37 | color.w = 1.0; // a -> snow 38 | } 39 | 40 | imageStore(splatmap, xy, color); 41 | } 42 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/dome/Fragment.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // dome/Fragment.frag 4 | 5 | // In 6 | 7 | in vec3 worldPosition; 8 | 9 | // Out 10 | 11 | out vec4 fragColor; 12 | 13 | // Main 14 | 15 | const vec3 baseColor = vec3(0.18, 0.27, 0.47); 16 | 17 | void main() 18 | { 19 | float red = -0.00022 * (abs(worldPosition.y)-2800) + 0.18; 20 | float green = -0.00025 * (abs(worldPosition.y)-2800) + 0.27; 21 | float blue = -0.00019 * (abs(worldPosition.y)-2800) + 0.47; 22 | 23 | fragColor = vec4(red, green, blue, 1.0); 24 | } 25 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/dome/Vertex.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // dome/Vertex.vert 4 | 5 | // In 6 | 7 | layout (location = 0) in vec3 aPosition; 8 | 9 | // Out 10 | 11 | out vec3 worldPosition; 12 | 13 | // Uniforms 14 | 15 | uniform mat4 mvpMatrix; 16 | uniform mat4 worldMatrix; 17 | 18 | // Main 19 | 20 | void main() 21 | { 22 | gl_Position = mvpMatrix * vec4(aPosition, 1.0); 23 | worldPosition = (worldMatrix * vec4(aPosition, 1.0)).xyz; 24 | } 25 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/gbuffer_pass/Fragment.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // gbuffer/Fragment.frag 4 | 5 | // Out 6 | 7 | layout (location = 0) out vec3 gPosition; 8 | layout (location = 1) out vec3 gNormal; 9 | layout (location = 2) out vec4 gAlbedoSpec; 10 | 11 | // In 12 | 13 | in vec3 vPosition; 14 | in vec3 vNormal; 15 | in vec2 vUv; 16 | in vec3 vTangent; 17 | 18 | // Uniforms 19 | 20 | uniform vec3 diffuseColor; 21 | uniform float hasDiffuseMap; 22 | uniform sampler2D diffuseMap; 23 | 24 | uniform vec3 specularColor; 25 | uniform float hasSpecularMap; 26 | uniform sampler2D specularMap; 27 | 28 | uniform float hasNormalMap; 29 | uniform sampler2D normalMap; 30 | 31 | // Function 32 | 33 | vec3 GetDiffuse() 34 | { 35 | vec4 diffuse = vec4(diffuseColor, 1.0); 36 | if (hasDiffuseMap > 0.5) 37 | { 38 | diffuse = texture(diffuseMap, vUv); 39 | } 40 | 41 | return diffuse.rgb; 42 | } 43 | 44 | float GetSpecularIntensity() 45 | { 46 | vec4 specular = vec4(specularColor, 1.0); 47 | if (hasSpecularMap > 0.5) 48 | { 49 | specular = texture(specularMap, vUv); 50 | } 51 | 52 | return specular.r; 53 | } 54 | 55 | vec3 GetNormal() 56 | { 57 | if (hasNormalMap > 0.5) 58 | { 59 | vec3 N = normalize(vNormal); 60 | vec3 T = normalize(vTangent); 61 | vec3 B = cross(N, T); 62 | mat3 TBN = mat3(T, B, N); 63 | 64 | vec3 normal = texture(normalMap, vUv).xyz * 2.0 - vec3(1.0); 65 | return TBN * normalize(normal); 66 | } 67 | 68 | return normalize(vNormal); 69 | } 70 | 71 | // Main 72 | 73 | void main() 74 | { 75 | gPosition = vPosition; 76 | gNormal = GetNormal(); 77 | gAlbedoSpec.rgb = GetDiffuse(); 78 | gAlbedoSpec.a = GetSpecularIntensity(); 79 | } 80 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/gbuffer_pass/Vertex.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // gbuffer/Vertex.vert 4 | 5 | // In 6 | 7 | layout (location = 0) in vec3 aPosition; 8 | layout (location = 1) in vec3 aNormal; 9 | layout (location = 2) in vec2 aUv; 10 | layout (location = 3) in vec3 aTangent; 11 | layout (location = 4) in vec3 aBiTangent; 12 | 13 | // Out 14 | 15 | out vec3 vPosition; 16 | out vec3 vNormal; 17 | out vec2 vUv; 18 | out vec3 vTangent; 19 | 20 | // Uniforms 21 | 22 | uniform mat4 modelMatrix; 23 | uniform mat4 mvpMatrix; 24 | uniform vec4 plane; 25 | 26 | // Main 27 | 28 | void main() 29 | { 30 | gl_Position = mvpMatrix * vec4(aPosition, 1.0); 31 | 32 | vec4 worldPosition = modelMatrix * vec4(aPosition, 1.0); 33 | gl_ClipDistance[0] = dot(worldPosition, plane); 34 | 35 | vPosition = vec3(worldPosition); 36 | vNormal = mat3(transpose(inverse(modelMatrix))) * aNormal; 37 | vUv = aUv; 38 | vTangent = aTangent; 39 | } 40 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/gui/Fragment.frag: -------------------------------------------------------------------------------- 1 | #version 400 2 | 3 | // gui/Fragment.frag 4 | 5 | // In 6 | 7 | in vec2 vUv; 8 | 9 | // Out 10 | 11 | out vec4 fragColor; 12 | 13 | // Uniforms 14 | 15 | uniform sampler2D guiTexture; 16 | 17 | // Main 18 | 19 | void main() 20 | { 21 | fragColor = texture(guiTexture, vUv); 22 | } 23 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/gui/Vertex.vert: -------------------------------------------------------------------------------- 1 | #version 400 2 | 3 | // gui/Vertex.vert 4 | 5 | // In 6 | 7 | layout (location = 0) in vec2 aPosition; 8 | 9 | // Out 10 | 11 | out vec2 vUv; 12 | 13 | // Uniforms 14 | 15 | uniform mat4 transformationMatrix; 16 | 17 | // Main 18 | 19 | void main() 20 | { 21 | gl_Position = transformationMatrix * vec4(aPosition, 0.0, 1.0); 22 | vUv = vec2((aPosition.x + 1.0) / 2.0, 1.0 - (aPosition.y + 1.0) / 2.0); 23 | } 24 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/gui_depth_map/Fragment.frag: -------------------------------------------------------------------------------- 1 | #version 400 2 | 3 | // gui_depth_map/Fragment.frag 4 | 5 | // In 6 | 7 | in vec2 vUv; 8 | 9 | // Out 10 | 11 | out vec4 fragColor; 12 | 13 | // Uniforms 14 | 15 | uniform sampler2D guiTexture; 16 | uniform float near_plane; 17 | uniform float far_plane; 18 | 19 | // Main 20 | 21 | float LinearizeDepth(float depth) 22 | { 23 | float z = depth * 2.0 - 1.0; 24 | return (2.0 * near_plane * far_plane) / (far_plane + near_plane - z * (far_plane - near_plane)); 25 | } 26 | 27 | void main() 28 | { 29 | float depthValue = texture(guiTexture, vUv).r; 30 | fragColor = vec4(vec3(LinearizeDepth(depthValue) / far_plane), 1.0); 31 | } 32 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/gui_depth_map/Vertex.vert: -------------------------------------------------------------------------------- 1 | #version 400 2 | 3 | // gui_depth_map/Vertex.vert 4 | 5 | // In 6 | 7 | layout (location = 0) in vec2 aPosition; 8 | 9 | // Out 10 | 11 | out vec2 vUv; 12 | 13 | // Uniforms 14 | 15 | uniform mat4 transformationMatrix; 16 | 17 | // Main 18 | 19 | void main() 20 | { 21 | gl_Position = transformationMatrix * vec4(aPosition, 0.0, 1.0); 22 | vUv = vec2((aPosition.x + 1.0) / 2.0, 1.0 - (aPosition.y + 1.0) / 2.0); 23 | 24 | float y = vUv.y; 25 | vUv.y = 1 - y; 26 | } 27 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/instancing/Vertex.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // instancing/Vertex.vert 4 | 5 | // In 6 | 7 | layout (location = 0) in vec3 aPosition; 8 | layout (location = 1) in vec3 aNormal; 9 | layout (location = 2) in vec2 aUv; 10 | layout (location = 3) in vec3 aTangent; 11 | layout (location = 4) in vec3 aBiTangent; 12 | layout (location = 5) in mat4 aInstanceMatrix; 13 | 14 | // Out 15 | 16 | out vec3 vPosition; 17 | out vec3 vNormal; 18 | out vec2 vUv; 19 | 20 | // Uniforms 21 | 22 | uniform mat4 projectionMatrix; 23 | uniform mat4 viewMatrix; 24 | uniform float fakeNormals; 25 | 26 | // Main 27 | 28 | void main() 29 | { 30 | vec3 position = vec3(aInstanceMatrix * vec4(aPosition, 1.0)); 31 | 32 | vPosition = position; 33 | 34 | vNormal = vec3(0.0, 1.0, 0.0); 35 | if (fakeNormals < 0.5) 36 | { 37 | vNormal = mat3(transpose(inverse(aInstanceMatrix))) * aNormal; 38 | } 39 | 40 | vUv = aUv; 41 | 42 | gl_Position = projectionMatrix * viewMatrix * vec4(position, 1.0); 43 | } 44 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/lighting_pass/Vertex.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // lighting_pass/Vertex.vert 4 | 5 | // In 6 | 7 | layout (location = 0) in vec3 aPosition; 8 | layout (location = 1) in vec2 aUv; 9 | 10 | // Out 11 | 12 | out vec2 vUv; 13 | 14 | // Main 15 | 16 | void main() 17 | { 18 | vUv = aUv; 19 | gl_Position = vec4(aPosition, 1.0); 20 | } 21 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/model/Vertex.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // model/Vertex.vert 4 | 5 | // In 6 | 7 | layout (location = 0) in vec3 aPosition; 8 | layout (location = 1) in vec3 aNormal; 9 | layout (location = 2) in vec2 aUv; 10 | layout (location = 3) in vec3 aTangent; 11 | layout (location = 4) in vec3 aBiTangent; 12 | 13 | // Out 14 | 15 | out vec3 vPosition; 16 | out vec3 vNormal; 17 | out vec2 vUv; 18 | out mat3 vTbnMatrix; 19 | 20 | // Uniforms 21 | 22 | uniform mat4 modelMatrix; 23 | uniform mat4 mvpMatrix; 24 | uniform vec4 plane; 25 | 26 | // Function 27 | 28 | mat3 GetTbnMatrix() 29 | { 30 | mat3 normalMatrix = transpose(inverse(mat3(modelMatrix))); 31 | vec3 T = normalize(normalMatrix * aTangent); 32 | vec3 N = normalize(normalMatrix * aNormal); 33 | T = normalize(T - dot(T, N) * N); 34 | vec3 B = cross(N, T); 35 | 36 | return transpose(mat3(T, B, N)); 37 | } 38 | 39 | // Main 40 | 41 | void main() 42 | { 43 | gl_Position = mvpMatrix * vec4(aPosition, 1.0); 44 | 45 | vec4 worldPosition = modelMatrix * vec4(aPosition, 1.0); 46 | gl_ClipDistance[0] = dot(worldPosition, plane); 47 | 48 | vPosition = vec3(worldPosition); 49 | vNormal = mat3(transpose(inverse(modelMatrix))) * aNormal; 50 | vUv = aUv; 51 | vTbnMatrix = GetTbnMatrix(); 52 | } 53 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/normal/Fragment.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // In 4 | 5 | in vec3 gNormal; 6 | 7 | // Out 8 | 9 | out vec4 fragColor; 10 | 11 | // Main 12 | 13 | void main() 14 | { 15 | fragColor = vec4(normalize(gNormal) * 0.5 + 0.5, 1.0); 16 | } 17 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/normal/Geometry.geom: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout(triangles) in; 4 | layout(line_strip, max_vertices = 6) out; 5 | 6 | // In 7 | 8 | in vec3 vNormal[]; 9 | 10 | // Out 11 | 12 | out vec3 gNormal; 13 | 14 | // Uniforms 15 | 16 | uniform mat4 transform; 17 | uniform float normalLength; 18 | 19 | // Main 20 | 21 | void main() 22 | { 23 | for (int i = 0; i < 3; i++) 24 | { 25 | gl_Position = gl_in[i].gl_Position; 26 | gNormal = vNormal[i]; 27 | EmitVertex(); 28 | 29 | gl_Position = gl_in[i].gl_Position + transform * vec4(vNormal[i] * normalLength, 0.0); 30 | gNormal = vNormal[i]; 31 | EmitVertex(); 32 | 33 | EndPrimitive(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/normal/Vertex.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // In 4 | 5 | layout (location = 0) in vec3 aPosition; 6 | layout (location = 1) in vec3 aNormal; 7 | 8 | // Out 9 | 10 | out vec3 vNormal; 11 | 12 | // Uniforms 13 | 14 | uniform mat4 transform; 15 | 16 | // Main 17 | 18 | void main() 19 | { 20 | gl_Position = transform * vec4(aPosition, 1.0); 21 | vNormal = aNormal; 22 | } 23 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/particle/Fragment.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // particle/Fragment.frag 4 | 5 | // In 6 | 7 | in vec2 vUvCurrent; 8 | in vec2 vUvNext; 9 | in float vBlend; 10 | 11 | // Out 12 | 13 | out vec4 fragColor; 14 | 15 | // Uniforms 16 | 17 | uniform sampler2D particleTexture; 18 | 19 | // Main 20 | 21 | void main() 22 | { 23 | vec4 col0 = texture(particleTexture, vUvCurrent); 24 | vec4 col1 = texture(particleTexture, vUvNext); 25 | 26 | fragColor = mix(col0, col1, vBlend); 27 | } 28 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/particle/Vertex.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // particle/Vertex.vert 4 | 5 | // In 6 | 7 | layout (location = 0) in vec2 aPosition; 8 | 9 | // Out 10 | 11 | out vec2 vUvCurrent; 12 | out vec2 vUvNext; 13 | out float vBlend; 14 | 15 | // Uniforms 16 | 17 | uniform mat4 projectionMatrix; 18 | uniform mat4 modelViewMatrix; 19 | uniform vec2 texOffsetCurrent; 20 | uniform vec2 texOffsetNext; 21 | uniform int textureRows; 22 | uniform float blendFactor; 23 | 24 | // Main 25 | 26 | void main() 27 | { 28 | vec2 uv = aPosition + vec2(0.5, 0.5); 29 | uv.y = 1.0 - uv.y; 30 | 31 | uv /= textureRows; 32 | 33 | vUvCurrent = uv + texOffsetCurrent; 34 | vUvNext = uv + texOffsetNext; 35 | vBlend = blendFactor; 36 | 37 | gl_Position = projectionMatrix * modelViewMatrix * vec4(aPosition, 0.0, 1.0); 38 | } 39 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/particle_inst/Fragment.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // particle_inst/Fragment.frag 4 | 5 | // In 6 | 7 | in vec2 vUvCurrent; 8 | in vec2 vUvNext; 9 | in float vBlend; 10 | 11 | // Out 12 | 13 | out vec4 fragColor; 14 | 15 | // Uniforms 16 | 17 | uniform sampler2D particleTexture; 18 | 19 | // Main 20 | 21 | void main() 22 | { 23 | vec4 col0 = texture(particleTexture, vUvCurrent); 24 | vec4 col1 = texture(particleTexture, vUvNext); 25 | 26 | fragColor = mix(col0, col1, vBlend); 27 | } 28 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/particle_inst/Vertex.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // particle_inst/Vertex.vert 4 | 5 | // In 6 | 7 | layout (location = 0) in vec2 aPosition; 8 | 9 | // In - per instance vars 10 | 11 | layout (location = 1) in mat4 modelViewMatrix; 12 | layout (location = 5) in vec4 texOffsets; 13 | layout (location = 6) in float blendFactor; 14 | 15 | // Out 16 | 17 | out vec2 vUvCurrent; 18 | out vec2 vUvNext; 19 | out float vBlend; 20 | 21 | // Uniforms 22 | 23 | uniform mat4 projectionMatrix; 24 | uniform int textureRows; 25 | 26 | // Main 27 | 28 | void main() 29 | { 30 | vec2 uv = aPosition + vec2(0.5, 0.5); 31 | uv.y = 1.0 - uv.y; 32 | 33 | uv /= textureRows; 34 | 35 | vUvCurrent = uv + texOffsets.xy; 36 | vUvNext = uv + texOffsets.zw; 37 | vBlend = blendFactor; 38 | 39 | gl_Position = projectionMatrix * modelViewMatrix * vec4(aPosition, 0.0, 1.0); 40 | } 41 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/skeletal_model/Vertex.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // skeletal_model/Vertex.vert 4 | 5 | // In 6 | 7 | layout (location = 0) in vec3 aPosition; 8 | layout (location = 1) in vec3 aNormal; 9 | layout (location = 2) in vec2 aUv; 10 | layout (location = 3) in vec3 aTangent; 11 | layout (location = 4) in vec3 aBiTangent; 12 | layout (location = 5) in ivec4 aBoneIds; 13 | layout (location = 6) in vec4 aWeights; 14 | 15 | // Out 16 | 17 | out vec3 vPosition; 18 | out vec3 vNormal; 19 | out vec2 vUv; 20 | out mat3 vTbnMatrix; 21 | 22 | // Uniforms 23 | 24 | uniform mat4 modelMatrix; 25 | uniform mat4 mvpMatrix; 26 | uniform vec4 plane; 27 | uniform mat4 bones[200]; 28 | 29 | // Function 30 | 31 | mat3 GetTbnMatrix() 32 | { 33 | mat3 normalMatrix = transpose(inverse(mat3(modelMatrix))); 34 | vec3 T = normalize(normalMatrix * aTangent); 35 | vec3 N = normalize(normalMatrix * aNormal); 36 | T = normalize(T - dot(T, N) * N); 37 | vec3 B = cross(N, T); 38 | 39 | return transpose(mat3(T, B, N)); 40 | } 41 | 42 | // Main 43 | 44 | void main() 45 | { 46 | mat4 boneTransform = bones[aBoneIds[0]] * aWeights[0]; 47 | boneTransform += bones[aBoneIds[1]] * aWeights[1]; 48 | boneTransform += bones[aBoneIds[2]] * aWeights[2]; 49 | boneTransform += bones[aBoneIds[3]] * aWeights[3]; 50 | 51 | vec4 bonedPosition = boneTransform * vec4(aPosition, 1.0); 52 | gl_Position = mvpMatrix * bonedPosition; 53 | 54 | vPosition = vec3(modelMatrix * bonedPosition); 55 | vNormal = mat3(transpose(inverse(modelMatrix))) * aNormal; 56 | vUv = aUv; 57 | vTbnMatrix = GetTbnMatrix(); 58 | } 59 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/skybox/Fragment.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // skybox/Fragment.frag 4 | 5 | // In 6 | 7 | in vec3 vUv; 8 | 9 | // Out 10 | 11 | out vec4 fragColor; 12 | 13 | // Uniforms 14 | 15 | uniform samplerCube cubeSampler; 16 | 17 | // Main 18 | 19 | void main() 20 | { 21 | fragColor = texture(cubeSampler, vUv); 22 | } 23 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/skybox/Vertex.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // skybox/Vertex.vert 4 | 5 | // In 6 | 7 | layout (location = 0) in vec3 aPosition; 8 | 9 | // Out 10 | 11 | out vec3 vUv; 12 | 13 | // Uniforms 14 | 15 | uniform mat4 projectionMatrix; 16 | uniform mat4 viewMatrix; 17 | 18 | // Main 19 | 20 | void main() 21 | { 22 | vUv = aPosition; 23 | vec4 position = projectionMatrix * viewMatrix * vec4(aPosition, 1.0); 24 | gl_Position = position.xyww; 25 | } 26 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/sun/Fragment.frag: -------------------------------------------------------------------------------- 1 | #version 400 2 | 3 | // sun/Fragment.frag 4 | 5 | // In 6 | 7 | in vec2 vUv; 8 | 9 | // Out 10 | 11 | out vec4 fragColor; 12 | 13 | // Uniforms 14 | 15 | uniform sampler2D sunTexture; 16 | 17 | // Main 18 | 19 | void main() 20 | { 21 | vec4 diffuse = texture(sunTexture, vUv); 22 | fragColor = diffuse; 23 | } 24 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/sun/Vertex.vert: -------------------------------------------------------------------------------- 1 | #version 400 2 | 3 | // sun/Vertex.vert 4 | 5 | // In 6 | 7 | layout (location = 0) in vec2 aPosition; 8 | 9 | // Out 10 | 11 | out vec2 vUv; 12 | 13 | // Uniforms 14 | 15 | uniform mat4 mvpMatrix; 16 | 17 | // Main 18 | 19 | void main() 20 | { 21 | gl_Position = mvpMatrix * vec4(aPosition, 0.0, 1.0); 22 | 23 | vUv = aPosition + vec2(0.5, 0.5); 24 | vUv.y = 1.0 - vUv.y; 25 | } 26 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/terrain_quadtree/Fragment.frag: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | // terrain_quadtree/Fragment.frag 4 | 5 | // In 6 | 7 | in vec2 mapCoord_FS; 8 | in vec3 viewPosition_FS; 9 | in vec3 worldPosition_FS; 10 | 11 | // Out 12 | 13 | out vec4 fragColor; 14 | 15 | // Types 16 | 17 | struct DirectionalLight 18 | { 19 | vec3 direction; 20 | vec3 diffuseIntensity; 21 | vec3 specularIntensity; 22 | }; 23 | 24 | // Uniforms 25 | 26 | uniform sampler2D normalmap; 27 | uniform sampler2D splatmap; 28 | 29 | uniform sampler2D sand; 30 | uniform sampler2D grass; 31 | uniform sampler2D rock; 32 | uniform sampler2D snow; 33 | 34 | uniform vec3 ambientIntensity; 35 | uniform int numDirectionalLights; 36 | uniform DirectionalLight directionalLights[2]; // max 2 directional lights 37 | 38 | // Function 39 | 40 | vec3 CalcDirectionalLight(DirectionalLight t_directionalLight, vec3 t_normal) 41 | { 42 | vec3 lightDir = normalize(-t_directionalLight.direction); 43 | float diffuseFactor = max(0.0, dot(t_normal, lightDir)); 44 | 45 | return diffuseFactor * t_directionalLight.diffuseIntensity; 46 | } 47 | 48 | // Fog 49 | 50 | const vec3 fogColor = vec3(0.5, 0.6, 0.7); 51 | const float fogDensity = 0.00025; // 0.0 ... 0.1 52 | 53 | vec4 Fog(vec4 t_color) 54 | { 55 | float fogFactor = 1.0 / exp(length(viewPosition_FS.xyz) * fogDensity); 56 | fogFactor = clamp(fogFactor, 0.0, 1.0 ); 57 | 58 | vec3 result = mix(fogColor, t_color.xyz, fogFactor); 59 | 60 | return vec4(result.xyz, t_color.w); 61 | } 62 | 63 | // Main 64 | 65 | void main() 66 | { 67 | vec3 normal = normalize(texture(normalmap, mapCoord_FS).rgb); 68 | vec4 blendValues = texture(splatmap, mapCoord_FS); 69 | 70 | vec4 sand = texture(sand, mapCoord_FS * 48.0); 71 | vec4 grass = texture(grass, mapCoord_FS * 100.0); 72 | vec4 rock = texture(rock, mapCoord_FS * 24.0); 73 | vec4 snow = texture(snow, mapCoord_FS * 48.0); 74 | 75 | vec4 color = vec4(0.0, 0.0, 0.0, 0.0); 76 | 77 | if (worldPosition_FS.y < 300.0) 78 | { 79 | color = blendValues.r * sand; 80 | } 81 | else 82 | { 83 | color = blendValues.r * snow; 84 | } 85 | 86 | color += blendValues.g * grass; 87 | color += blendValues.b * rock; 88 | color += blendValues.a * snow; 89 | 90 | vec4 ambient = vec4(ambientIntensity, 1.0) * color; 91 | 92 | vec3 diffuse = vec3(0.0, 0.0, 0.0); 93 | for(int i = 0; i < numDirectionalLights; ++i) 94 | { 95 | diffuse += CalcDirectionalLight(directionalLights[i], normal); 96 | } 97 | 98 | vec4 lightColor = ambient + vec4(diffuse, 1.0); 99 | 100 | fragColor = Fog(lightColor); 101 | } 102 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/terrain_quadtree/Geometry.geom: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | // terrain_quadtree/Geometry.geom 4 | 5 | layout(triangles) in; 6 | layout(triangle_strip, max_vertices = 3) out; 7 | 8 | // In 9 | 10 | in vec2 mapCoord_GS[]; 11 | 12 | // Out 13 | 14 | out vec2 mapCoord_FS; 15 | out vec3 viewPosition_FS; 16 | out vec3 worldPosition_FS; 17 | 18 | // Uniforms 19 | 20 | uniform mat4 viewMatrix; 21 | uniform mat4 viewProjectionMatrix; 22 | 23 | // Main 24 | 25 | void main() 26 | { 27 | for (int i = 0; i < gl_in.length(); ++i) 28 | { 29 | vec4 position = gl_in[i].gl_Position; 30 | 31 | gl_Position = viewProjectionMatrix * position; 32 | vec4 viewPosition = viewMatrix * position; 33 | 34 | mapCoord_FS = mapCoord_GS[i]; 35 | viewPosition_FS = viewPosition.xyz; 36 | worldPosition_FS = position.xyz; 37 | 38 | EmitVertex(); 39 | } 40 | 41 | EndPrimitive(); 42 | } 43 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/terrain_quadtree/TessEval.tese: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | // terrain_quadtree/TessEval.tese 4 | 5 | layout(quads, fractional_odd_spacing, cw) in; 6 | 7 | // In 8 | 9 | in vec2 mapCoord_TE[]; 10 | 11 | // Out 12 | 13 | out vec2 mapCoord_GS; 14 | 15 | // Uniforms 16 | 17 | uniform sampler2D heightmap; 18 | uniform float scaleXz; 19 | uniform float scaleY; 20 | 21 | // Function 22 | 23 | vec4 worldPosition; 24 | vec2 mapCoord; 25 | 26 | void SetHeight() 27 | { 28 | float height = texture(heightmap, mapCoord).r; 29 | height *= scaleY; 30 | 31 | worldPosition.y = height; 32 | } 33 | 34 | void ZeroHeightAtTheEdges() 35 | { 36 | float hScaleXz = scaleXz * 0.5 - 16.0; 37 | if (worldPosition.x < -hScaleXz || worldPosition.x > hScaleXz) 38 | { 39 | worldPosition.y = 0.0; 40 | } 41 | 42 | if (worldPosition.z < -hScaleXz || worldPosition.z > hScaleXz) 43 | { 44 | worldPosition.y = 0.0; 45 | } 46 | } 47 | 48 | // Main 49 | 50 | void main() 51 | { 52 | float u = gl_TessCoord.x; 53 | float v = gl_TessCoord.y; 54 | 55 | worldPosition = 56 | ((1 - u) * (1 - v) * gl_in[12].gl_Position + 57 | u * (1 - v) * gl_in[0].gl_Position + 58 | u * v * gl_in[3].gl_Position + 59 | (1 - u) * v * gl_in[15].gl_Position); 60 | 61 | mapCoord = 62 | ((1 - u) * (1 - v) * mapCoord_TE[12] + 63 | u * (1 - v) * mapCoord_TE[0] + 64 | u * v * mapCoord_TE[3] + 65 | (1 - u) * v * mapCoord_TE[15]); 66 | 67 | SetHeight(); 68 | ZeroHeightAtTheEdges(); 69 | 70 | mapCoord_GS = mapCoord; 71 | 72 | gl_Position = worldPosition; 73 | } 74 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/terrain_quadtree_wireframe/Fragment.frag: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | // terrain_quadtree_wireframe/Fragment.frag 4 | 5 | // In 6 | 7 | // Out 8 | 9 | out vec4 fragColor; 10 | 11 | // Uniforms 12 | 13 | // Main 14 | 15 | void main() 16 | { 17 | fragColor = vec4(0.0, 0.8, 0.0, 1.0); 18 | } 19 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/terrain_quadtree_wireframe/Geometry.geom: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | // terrain_quadtree_wireframe/Geometry.geom 4 | 5 | layout(triangles) in; 6 | layout(line_strip, max_vertices = 4) out; 7 | 8 | // In 9 | 10 | // Out 11 | 12 | // Uniforms 13 | 14 | uniform mat4 viewProjectionMatrix; 15 | 16 | // Main 17 | 18 | void main() 19 | { 20 | for (int i = 0; i < gl_in.length(); ++i) 21 | { 22 | vec4 position = gl_in[i].gl_Position; 23 | gl_Position = viewProjectionMatrix * position; 24 | EmitVertex(); 25 | } 26 | 27 | vec4 position = gl_in[0].gl_Position; 28 | gl_Position = viewProjectionMatrix * position; 29 | EmitVertex(); 30 | 31 | EndPrimitive(); 32 | } 33 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/terrain_quadtree_wireframe/TessEval.tese: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | // terrain_quadtree_wireframe/TessEval.tese 4 | 5 | layout(quads, fractional_odd_spacing, cw) in; 6 | 7 | // In 8 | 9 | in vec2 mapCoord_TE[]; 10 | 11 | // Out 12 | 13 | out vec2 mapCoord_GS; 14 | 15 | // Uniforms 16 | 17 | uniform sampler2D heightmap; 18 | uniform float scaleXz; 19 | uniform float scaleY; 20 | 21 | // Function 22 | 23 | vec4 worldPosition; 24 | vec2 mapCoord; 25 | 26 | void SetHeight() 27 | { 28 | float height = texture(heightmap, mapCoord).r; 29 | height *= scaleY; 30 | 31 | worldPosition.y = height; 32 | } 33 | 34 | void ZeroHeightAtTheEdges() 35 | { 36 | float hScaleXz = scaleXz * 0.5 - 16.0; 37 | if (worldPosition.x < -hScaleXz || worldPosition.x > hScaleXz) 38 | { 39 | worldPosition.y = 0.0; 40 | } 41 | 42 | if (worldPosition.z < -hScaleXz || worldPosition.z > hScaleXz) 43 | { 44 | worldPosition.y = 0.0; 45 | } 46 | } 47 | 48 | // Main 49 | 50 | void main() 51 | { 52 | float u = gl_TessCoord.x; 53 | float v = gl_TessCoord.y; 54 | 55 | worldPosition = 56 | ((1 - u) * (1 - v) * gl_in[12].gl_Position + 57 | u * (1 - v) * gl_in[0].gl_Position + 58 | u * v * gl_in[3].gl_Position + 59 | (1 - u) * v * gl_in[15].gl_Position); 60 | 61 | mapCoord = 62 | ((1 - u) * (1 - v) * mapCoord_TE[12] + 63 | u * (1 - v) * mapCoord_TE[0] + 64 | u * v * mapCoord_TE[3] + 65 | (1 - u) * v * mapCoord_TE[15]); 66 | 67 | SetHeight(); 68 | ZeroHeightAtTheEdges(); 69 | 70 | mapCoord_GS = mapCoord; 71 | 72 | gl_Position = worldPosition; 73 | } 74 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/text/Fragment.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // text/Fragment.frag 4 | 5 | // In 6 | 7 | in vec2 vUv; 8 | 9 | // Out 10 | 11 | out vec4 fragColor; 12 | 13 | // Uniforms 14 | 15 | uniform sampler2D textTexture; 16 | uniform vec3 textColor; 17 | 18 | // Main 19 | 20 | void main() 21 | { 22 | vec4 sampled = vec4(1.0, 1.0, 1.0, texture(textTexture, vUv).r); 23 | fragColor = vec4(textColor, 1.0) * sampled; 24 | } 25 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/text/Vertex.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // text/Vertex.vert 4 | 5 | // In 6 | 7 | layout (location = 0) in vec4 aVertex; // 8 | 9 | // Out 10 | 11 | out vec2 vUv; 12 | 13 | // Uniforms 14 | 15 | uniform mat4 projectionMatrix; 16 | 17 | // Main 18 | 19 | void main() 20 | { 21 | gl_Position = projectionMatrix * vec4(aVertex.xy, 0.0, 1.0); 22 | vUv = aVertex.zw; 23 | } 24 | -------------------------------------------------------------------------------- /SgOglLib/res/shader/water/Vertex.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // water/Vertex.vert 4 | 5 | // In 6 | 7 | layout (location = 0) in vec2 aPosition; 8 | 9 | // Out 10 | 11 | out vec3 vWorldPosition; 12 | out vec4 vClipSpace; 13 | out vec2 vUv; 14 | 15 | // Uniforms 16 | 17 | uniform mat4 modelMatrix; 18 | uniform mat4 vpMatrix; 19 | 20 | // Main 21 | 22 | const float tiling = 4.0; 23 | 24 | void main() 25 | { 26 | vec4 worldPosition = modelMatrix * vec4(aPosition.x, 0.0, aPosition.y, 1.0); 27 | 28 | vWorldPosition = worldPosition.xyz; 29 | vClipSpace = vpMatrix * worldPosition; 30 | vUv = vec2(aPosition.x / 2.0 + 0.5, aPosition.y / 2.0 + 0.5) * tiling; 31 | 32 | gl_Position = vClipSpace; 33 | } 34 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglEntryPoint.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: SgOglEntryPoint.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include "SgOglLib/EntryPoint.h" 13 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/Color.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: Color.cpp 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2019 (c) stwe 9 | 10 | #include "Color.h" 11 | 12 | sg::ogl::Color::Color(const uint8_t t_red, const uint8_t t_green, const uint8_t t_blue, const uint8_t t_alpha) 13 | : r{ t_red } 14 | , g{ t_green } 15 | , b{ t_blue } 16 | , a{ t_alpha } 17 | {} 18 | 19 | sg::ogl::Color::Color(const uint32_t t_color) 20 | : r( (t_color & 0xff000000) >> 24 ) 21 | , g( (t_color & 0x00ff0000) >> 16 ) 22 | , b( (t_color & 0x0000ff00) >> 8 ) 23 | , a( (t_color & 0x000000ff) >> 0 ) 24 | {} 25 | 26 | uint32_t sg::ogl::Color::ToInteger() const 27 | { 28 | return (r << 24) | (g << 16) | (b << 8) | a; 29 | } 30 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/Config.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: Config.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2019 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | struct lua_State; 16 | 17 | namespace sg::ogl 18 | { 19 | //------------------------------------------------- 20 | // Window options 21 | //------------------------------------------------- 22 | 23 | struct WindowOptions 24 | { 25 | std::string title{ "" }; 26 | bool compatibleProfile{ false }; 27 | bool debugContext{ false }; 28 | bool antialiasing{ false }; 29 | bool printFrameRate{ false }; 30 | int glMajor{ 4 }; 31 | int glMinor{ 3 }; 32 | double fps{ 60.0 }; 33 | }; 34 | 35 | //------------------------------------------------- 36 | // Projection options 37 | //------------------------------------------------- 38 | 39 | struct ProjectionOptions 40 | { 41 | float fovDeg{ 0.0f }; 42 | int width{ 0 }; 43 | int height{ 0 }; 44 | float nearPlane{ 0.0f }; 45 | float farPlane{ 0.0f }; 46 | }; 47 | 48 | //------------------------------------------------- 49 | // Terrain options 50 | //------------------------------------------------- 51 | 52 | struct TerrainOptions 53 | { 54 | using TextureKeyName = std::string; 55 | using TexturePath = std::string; 56 | using TextureContainer = std::map; 57 | 58 | float xPos{ 0.0f }; 59 | float zPos{ 0.0f }; 60 | float scaleXz{ 1.0f }; 61 | float scaleY{ 1.0f }; 62 | std::string heightmapPath; 63 | TextureContainer textureContainer; 64 | std::string normalmapShaderName; 65 | std::string splatmapShaderName; 66 | std::string normalmapTextureName; 67 | std::string splatmapTextureName; 68 | float normalStrength{ 60.0f }; 69 | }; 70 | 71 | //------------------------------------------------- 72 | // Config 73 | //------------------------------------------------- 74 | 75 | class Config 76 | { 77 | public: 78 | static void LoadOptions( 79 | const std::string& t_fileName, 80 | std::string& t_libResFolder, 81 | WindowOptions& t_windowOptions, 82 | ProjectionOptions& t_projectionOptions 83 | ); 84 | 85 | protected: 86 | 87 | private: 88 | static void PrintLuaErrorMessage(lua_State* t_luaState); 89 | }; 90 | } 91 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/Core.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: Core.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include "Log.h" 13 | 14 | #if defined(_WIN64) && defined(_MSC_VER) 15 | #define SG_OGL_DEBUG_BREAK __debugbreak() 16 | #elif defined(__linux__) && defined(__GNUC__) && (__GNUC__ >= 7) 17 | #include 18 | #define SG_OGL_DEBUG_BREAK raise(SIGTRAP) 19 | #else 20 | #error Unsupported platform or compiler! 21 | #endif 22 | 23 | #ifdef SG_OGL_DEBUG_BUILD 24 | #define SG_OGL_ENABLE_ASSERTS 25 | #endif 26 | 27 | #ifdef SG_OGL_ENABLE_ASSERTS 28 | 29 | inline auto SG_OGL_CORE_ASSERT = [](auto&& t_expr, std::string_view t_str) -> void 30 | { 31 | if (!(t_expr)) 32 | { 33 | sg::ogl::Log::SG_OGL_CORE_LOG_ERROR("Assertion Failed: {}", t_str); 34 | SG_OGL_DEBUG_BREAK; 35 | } 36 | }; 37 | 38 | #else 39 | 40 | inline auto SG_OGL_CORE_ASSERT = [](auto&& t_expr, std::string_view t_str) -> void 41 | {}; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/EntryPoint.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: EntryPoint.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include "SgOglException.h" 13 | #include "Log.h" 14 | 15 | int main() 16 | { 17 | sg::ogl::Log::Init(); 18 | 19 | sg::ogl::Log::SG_OGL_CORE_LOG_DEBUG("[main()] Starting main."); 20 | sg::ogl::Log::SG_OGL_CORE_LOG_DEBUG("[main()] Logger was initialized."); 21 | 22 | try 23 | { 24 | auto appUniquePtr{ sg::ogl::create_application() }; 25 | appUniquePtr->Run(); 26 | return EXIT_SUCCESS; 27 | } 28 | catch (const sg::ogl::SgOglException& e) 29 | { 30 | sg::ogl::Log::SG_OGL_CORE_LOG_ERROR("SgOglException {}", e.what()); 31 | } 32 | catch (const std::exception& e) 33 | { 34 | sg::ogl::Log::SG_OGL_CORE_LOG_ERROR("Standard Exception: {}", e.what()); 35 | } 36 | catch ( ... ) 37 | { 38 | sg::ogl::Log::SG_OGL_CORE_LOG_ERROR("Unknown Exception. No details available."); 39 | } 40 | 41 | return EXIT_FAILURE; 42 | } 43 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/Log.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: Log.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | namespace sg::ogl 16 | { 17 | class Log 18 | { 19 | public: 20 | using LoggerSharedPtr = std::shared_ptr; 21 | 22 | static void Init() 23 | { 24 | spdlog::set_pattern("%^[%T] %n: %v%$"); 25 | 26 | m_libLogger = spdlog::stdout_color_mt("SgOglLib"); 27 | 28 | #ifdef SG_OGL_DEBUG_BUILD 29 | m_libLogger->set_level(spdlog::level::trace); 30 | #else 31 | m_libLogger->set_level(spdlog::level::info); 32 | #endif 33 | } 34 | 35 | template 36 | static void SG_OGL_CORE_LOG_TRACE(T ...t_args) 37 | { 38 | m_libLogger->trace(t_args...); 39 | } 40 | 41 | template 42 | static void SG_OGL_CORE_LOG_DEBUG(T ...t_args) 43 | { 44 | m_libLogger->debug(t_args...); 45 | } 46 | 47 | template 48 | static void SG_OGL_CORE_LOG_INFO(T ...t_args) 49 | { 50 | m_libLogger->info(t_args...); 51 | } 52 | 53 | template 54 | static void SG_OGL_CORE_LOG_WARN(T ...t_args) 55 | { 56 | m_libLogger->warn(t_args...); 57 | } 58 | 59 | template 60 | static void SG_OGL_CORE_LOG_ERROR(T ...t_args) 61 | { 62 | m_libLogger->error(t_args...); 63 | } 64 | 65 | template 66 | static void SG_OGL_CORE_LOG_FATAL(T ...t_args) 67 | { 68 | m_libLogger->critical(t_args...); 69 | } 70 | 71 | protected: 72 | 73 | private: 74 | inline static LoggerSharedPtr m_libLogger; 75 | }; 76 | } 77 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/OpenGl.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: OpenGl.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #pragma once 11 | 12 | // include Windows.h before glfw3.h 13 | #ifdef _WIN64 14 | #ifndef NOMINMAX 15 | #define NOMINMAX 16 | #endif 17 | 18 | #include 19 | #endif 20 | 21 | //------------------------------------------------- 22 | // Stb Image 23 | //------------------------------------------------- 24 | 25 | #include "resource/stb_image.h" 26 | 27 | //------------------------------------------------- 28 | // Glew 29 | //------------------------------------------------- 30 | 31 | #include 32 | 33 | //------------------------------------------------- 34 | // GLFW3 35 | //------------------------------------------------- 36 | 37 | #include 38 | 39 | //------------------------------------------------- 40 | // Debug output 41 | //------------------------------------------------- 42 | 43 | void APIENTRY gl_debug_output( 44 | uint32_t t_source, 45 | uint32_t t_type, 46 | uint32_t t_id, 47 | uint32_t t_severity, 48 | int32_t t_length, 49 | const char* t_message, 50 | const void* t_userParam 51 | ); 52 | 53 | //------------------------------------------------- 54 | // OpenGL States 55 | //------------------------------------------------- 56 | 57 | namespace sg::ogl 58 | { 59 | struct Color; 60 | 61 | class OpenGl 62 | { 63 | public: 64 | static void SetClearColor(const Color& t_color); 65 | static void Clear(); 66 | static void ClearColorAndDepthBuffer(); 67 | 68 | static void EnableDepthTesting(); 69 | static void DisableDepthTesting(); 70 | static void EnableDepthAndStencilTesting(); 71 | 72 | static void EnableWritingIntoDepthBuffer(); 73 | static void DisableWritingIntoDepthBuffer(); 74 | 75 | static void EnableFaceCulling(); 76 | static void DisableFaceCulling(); 77 | 78 | static void EnableAlphaBlending(); 79 | static void EnableAdditiveBlending(); 80 | static void DisableBlending(); 81 | 82 | static void EnableClipping(uint32_t t_nrOfClipDistances = 0); 83 | static void DisableClipping(uint32_t t_nrOfClipDistances = 0); 84 | 85 | static void EnableWireframeMode(); 86 | static void DisableWireframeMode(); 87 | 88 | static void SetDepthFunc(uint32_t t_func); 89 | 90 | protected: 91 | 92 | private: 93 | 94 | }; 95 | } 96 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/Random.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: Random.cpp 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #include 11 | #include "Random.h" 12 | 13 | static std::random_device rd; 14 | static std::mt19937 generator(rd()); 15 | 16 | float sg::ogl::Random::Float(const float t_min, const float t_max) 17 | { 18 | std::uniform_real_distribution distr(t_min, t_max); 19 | 20 | return distr(generator); 21 | } 22 | 23 | int sg::ogl::Random::Int(const int t_min, const int t_max) 24 | { 25 | std::uniform_int_distribution distr(t_min, t_max); 26 | 27 | return distr(generator); 28 | } 29 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/Random.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: Random.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #pragma once 11 | 12 | namespace sg::ogl 13 | { 14 | class Random 15 | { 16 | public: 17 | static float Float(float t_min = 0.0f, float t_max = 1.0f); 18 | static int Int(int t_min = 0, int t_max = std::numeric_limits::max()); 19 | 20 | protected: 21 | 22 | private: 23 | }; 24 | } 25 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/SgOglException.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: SgOglException.cpp 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #include 11 | #include "SgOglException.h" 12 | 13 | sg::ogl::SgOglException::SgOglException(const int t_line, const char* t_file, std::string t_message) 14 | : m_line{ t_line } 15 | , m_file{ t_file } 16 | , m_message{ std::move(t_message) } 17 | { 18 | } 19 | 20 | const char* sg::ogl::SgOglException::what() const noexcept 21 | { 22 | std::ostringstream oss; 23 | 24 | oss << "occurred: \n"; 25 | oss << "[Type]: " << GetType() << "\n"; 26 | oss << GetOriginString(); 27 | 28 | m_whatBuffer = oss.str(); 29 | 30 | return m_whatBuffer.c_str(); 31 | } 32 | 33 | const char* sg::ogl::SgOglException::GetType() const noexcept 34 | { 35 | return "SgOgl Exception"; 36 | } 37 | 38 | int sg::ogl::SgOglException::GetLine() const noexcept 39 | { 40 | return m_line; 41 | } 42 | 43 | const std::string& sg::ogl::SgOglException::GetFile() const noexcept 44 | { 45 | return m_file; 46 | } 47 | 48 | std::string sg::ogl::SgOglException::GetOriginString() const noexcept 49 | { 50 | std::ostringstream oss; 51 | 52 | oss << "[Message]: " << m_message << "\n"; 53 | oss << "[File]: " << m_file << "\n"; 54 | oss << "[Line]: " << m_line; 55 | 56 | return oss.str(); 57 | } 58 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/SgOglException.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: SgOglException.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | namespace sg::ogl 16 | { 17 | #if defined(_WIN64) && defined(_MSC_VER) 18 | #pragma warning(push) 19 | #pragma warning(disable: 4275) 20 | #endif 21 | class SgOglException : public std::exception 22 | { 23 | #if defined(_WIN64) && defined(_MSC_VER) 24 | #pragma warning(pop) 25 | #endif 26 | public: 27 | SgOglException(int t_line, const char* t_file, std::string t_message); 28 | 29 | const char* what() const noexcept override; 30 | 31 | virtual const char* GetType() const noexcept; 32 | 33 | int GetLine() const noexcept ; 34 | const std::string& GetFile() const noexcept; 35 | std::string GetOriginString() const noexcept; 36 | 37 | protected: 38 | mutable std::string m_whatBuffer; 39 | 40 | private: 41 | int m_line; 42 | std::string m_file; 43 | std::string m_message; 44 | }; 45 | } 46 | 47 | #define SG_OGL_EXCEPTION(message) sg::ogl::SgOglException(__LINE__, __FILE__, message) 48 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/buffer/BufferLayout.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: BufferLayout.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2019 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include "VertexAttribute.h" 15 | 16 | namespace sg::ogl::buffer 17 | { 18 | class BufferLayout 19 | { 20 | public: 21 | using AttributeContainer = std::vector; 22 | 23 | //------------------------------------------------- 24 | // Ctors. / Dtor. 25 | //------------------------------------------------- 26 | 27 | BufferLayout() = default; 28 | 29 | BufferLayout(const std::initializer_list& t_vertexAttributes); 30 | 31 | BufferLayout(const BufferLayout& t_other) = delete; 32 | BufferLayout(BufferLayout&& t_other) noexcept = delete; 33 | BufferLayout& operator=(const BufferLayout& t_other) = delete; 34 | BufferLayout& operator=(BufferLayout&& t_other) noexcept = delete; 35 | 36 | ~BufferLayout() noexcept = default; 37 | 38 | //------------------------------------------------- 39 | // Getter 40 | //------------------------------------------------- 41 | 42 | [[nodiscard]] const AttributeContainer& GetAttributes() const noexcept; 43 | [[nodiscard]] int32_t GetStride() const; 44 | [[nodiscard]] uint32_t GetNumberOfFloats() const; 45 | 46 | static uint32_t GetVertexAttributeTypeSize(VertexAttributeType t_vertexAttributeType); 47 | static uint32_t GetOpenGlType(VertexAttributeType t_vertexAttributeType); 48 | 49 | protected: 50 | 51 | private: 52 | AttributeContainer m_vertexAttributes; 53 | int32_t m_stride{ 0 }; 54 | uint32_t m_numberOfFloats{ 0 }; 55 | 56 | //------------------------------------------------- 57 | // Helper 58 | //------------------------------------------------- 59 | 60 | void Init(); 61 | }; 62 | } 63 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/buffer/Fbo.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: Fbo.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include 13 | 14 | namespace sg::ogl 15 | { 16 | class Application; 17 | } 18 | 19 | namespace sg::ogl::buffer 20 | { 21 | class Fbo 22 | { 23 | public: 24 | //------------------------------------------------- 25 | // Ctors. / Dtor. 26 | //------------------------------------------------- 27 | 28 | Fbo() = delete; 29 | 30 | Fbo(Application* t_application, int32_t t_width, int32_t t_height); 31 | 32 | Fbo(const Fbo& t_other) = delete; 33 | Fbo(Fbo&& t_other) noexcept = delete; 34 | Fbo& operator=(const Fbo& t_other) = delete; 35 | Fbo& operator=(Fbo&& t_other) noexcept = delete; 36 | 37 | ~Fbo() noexcept; 38 | 39 | //------------------------------------------------- 40 | // Getter 41 | //------------------------------------------------- 42 | 43 | uint32_t GetDepthTextureId() const; 44 | 45 | //------------------------------------------------- 46 | // Fbo 47 | //------------------------------------------------- 48 | 49 | void GenerateFbo(); 50 | void BindFbo() const; 51 | static void UnbindFbo(); 52 | 53 | //------------------------------------------------- 54 | // Fbo - Render Target 55 | //------------------------------------------------- 56 | 57 | void BindAsRenderTarget() const; 58 | void UnbindRenderTarget() const; 59 | 60 | protected: 61 | 62 | private: 63 | Application* m_application{ nullptr }; 64 | 65 | uint32_t m_fboId{ 0 }; 66 | 67 | uint32_t m_depthTexture{ 0 }; 68 | 69 | int32_t m_width{ 0 }; 70 | int32_t m_height{ 0 }; 71 | 72 | //------------------------------------------------- 73 | // Attachment 74 | //------------------------------------------------- 75 | 76 | void Attach(); 77 | 78 | //------------------------------------------------- 79 | // CleanUp 80 | //------------------------------------------------- 81 | 82 | void CleanUp() const; 83 | }; 84 | } 85 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/buffer/GBufferFbo.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: GBufferFbo.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2019 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include 13 | 14 | namespace sg::ogl 15 | { 16 | class Application; 17 | } 18 | 19 | namespace sg::ogl::buffer 20 | { 21 | class GBufferFbo 22 | { 23 | public: 24 | //------------------------------------------------- 25 | // Ctors. / Dtor. 26 | //------------------------------------------------- 27 | 28 | GBufferFbo() = delete; 29 | 30 | explicit GBufferFbo(Application* t_application); 31 | 32 | GBufferFbo(const GBufferFbo& t_other) = delete; 33 | GBufferFbo(GBufferFbo&& t_other) noexcept = delete; 34 | GBufferFbo& operator=(const GBufferFbo& t_other) = delete; 35 | GBufferFbo& operator=(GBufferFbo&& t_other) noexcept = delete; 36 | 37 | ~GBufferFbo() noexcept; 38 | 39 | //------------------------------------------------- 40 | // Getter 41 | //------------------------------------------------- 42 | 43 | [[nodiscard]] uint32_t GetFboId() const; 44 | 45 | [[nodiscard]] uint32_t GetPositionTextureId() const; 46 | [[nodiscard]] uint32_t GetNormalTextureId() const; 47 | [[nodiscard]] uint32_t GetAlbedoSpecTextureId() const; 48 | 49 | //------------------------------------------------- 50 | // Fbo 51 | //------------------------------------------------- 52 | 53 | void BindFbo() const; 54 | static void UnbindFbo(); 55 | void CopyDepthBufferToDefaultFramebuffer() const; 56 | 57 | protected: 58 | 59 | private: 60 | Application* m_application{ nullptr }; 61 | 62 | int32_t m_width{ 0 }; 63 | int32_t m_height{ 0 }; 64 | 65 | uint32_t m_fboId{ 0 }; 66 | 67 | uint32_t m_positionTextureId{ 0 }; 68 | uint32_t m_normalTextureId{ 0 }; 69 | uint32_t m_albedoSpecTextureId{ 0 }; 70 | 71 | //------------------------------------------------- 72 | // Fbo 73 | //------------------------------------------------- 74 | 75 | void GenerateFbo(); 76 | 77 | //------------------------------------------------- 78 | // Attachment 79 | //------------------------------------------------- 80 | 81 | void Attach(); 82 | 83 | //------------------------------------------------- 84 | // CleanUp 85 | //------------------------------------------------- 86 | 87 | void CleanUp() const; 88 | }; 89 | } 90 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/buffer/VertexAttribute.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: VertexAttribute.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2019 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include 13 | #include "SgOglException.h" 14 | 15 | namespace sg::ogl::buffer 16 | { 17 | enum class VertexAttributeType 18 | { 19 | NONE, POSITION, POSITION_2D, COLOR, UV, NORMAL, TANGENT, BITANGENT, BONE_IDS, WEIGHTS 20 | }; 21 | 22 | struct VertexAttributeMeta 23 | { 24 | static int32_t GetComponentCount(const VertexAttributeType t_vertexAttributeType) 25 | { 26 | switch (t_vertexAttributeType) 27 | { 28 | case VertexAttributeType::POSITION: return 3; 29 | case VertexAttributeType::POSITION_2D: return 2; 30 | case VertexAttributeType::COLOR: return 3; 31 | case VertexAttributeType::UV: return 2; 32 | case VertexAttributeType::NORMAL: return 3; 33 | case VertexAttributeType::TANGENT: return 3; 34 | case VertexAttributeType::BITANGENT: return 3; 35 | case VertexAttributeType::BONE_IDS: return 4; 36 | case VertexAttributeType::WEIGHTS: return 4; 37 | default:; 38 | 39 | throw SG_OGL_EXCEPTION("[VertexAttributeMeta::GetComponentCount()] Unknown VertexAttributeType."); 40 | } 41 | } 42 | }; 43 | 44 | struct VertexAttribute 45 | { 46 | VertexAttributeType vertexAttributeType{ VertexAttributeType::NONE }; 47 | std::string name; 48 | bool normalized{ false }; 49 | uint32_t size{ 0 }; 50 | uint64_t offset{ 0 }; 51 | }; 52 | } 53 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/camera/FirstPersonCamera.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: FirstPersonCamera.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2019 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include "Camera.h" 13 | 14 | namespace sg::ogl::camera 15 | { 16 | class FirstPersonCamera : public Camera 17 | { 18 | public: 19 | //------------------------------------------------- 20 | // Ctors. / Dtor. 21 | //------------------------------------------------- 22 | 23 | FirstPersonCamera() = delete; 24 | 25 | FirstPersonCamera(const std::string& t_name, Application* t_application); 26 | FirstPersonCamera(const std::string& t_name, Application* t_application, const glm::vec3& t_position, float t_yaw, float t_pitch); 27 | 28 | FirstPersonCamera(const FirstPersonCamera& t_other) = delete; 29 | FirstPersonCamera(FirstPersonCamera&& t_other) noexcept = delete; 30 | FirstPersonCamera& operator=(const FirstPersonCamera& t_other) = delete; 31 | FirstPersonCamera& operator=(FirstPersonCamera&& t_other) noexcept = delete; 32 | 33 | ~FirstPersonCamera() noexcept; 34 | 35 | //------------------------------------------------- 36 | // Getter 37 | //------------------------------------------------- 38 | 39 | [[nodiscard]] float GetMouseSensitivity() const; 40 | 41 | //------------------------------------------------- 42 | // Setter 43 | //------------------------------------------------- 44 | 45 | void SetMouseSensitivity(float t_sensitivity); 46 | 47 | //------------------------------------------------- 48 | // Override 49 | //------------------------------------------------- 50 | 51 | [[nodiscard]] glm::mat4 GetViewMatrix() const override; 52 | 53 | void Input() override; 54 | void Update(double t_dt) override; 55 | 56 | protected: 57 | 58 | private: 59 | float m_mouseSensitivity{ 0.1f }; 60 | 61 | //------------------------------------------------- 62 | // Helper 63 | //------------------------------------------------- 64 | 65 | void ProcessKeyboard(CameraMovement t_direction, double t_dt); 66 | void ProcessMouse(); 67 | }; 68 | } 69 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/ecs/system/GuiRenderSystem.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: GuiRenderSystem.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2019 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include "RenderSystem.h" 13 | #include "resource/shaderprogram/GuiShaderProgram.h" 14 | #include "resource/ShaderManager.h" 15 | #include "resource/Mesh.h" 16 | #include "ecs/component/Components.h" 17 | #include "math/Transform.h" 18 | 19 | namespace sg::ogl::ecs::system 20 | { 21 | class GuiRenderSystem : public RenderSystem 22 | { 23 | public: 24 | using MeshSharedPtr = std::shared_ptr; 25 | 26 | //------------------------------------------------- 27 | // Ctors. / Dtor. 28 | //------------------------------------------------- 29 | 30 | explicit GuiRenderSystem(scene::Scene* t_scene) 31 | : RenderSystem(t_scene) 32 | { 33 | m_guiMesh = m_scene->GetApplicationContext()->GetModelManager().GetStaticMeshByName(resource::ModelManager::GUI_MESH); 34 | name = "GuiRenderer"; 35 | } 36 | 37 | GuiRenderSystem(const int t_priority, scene::Scene* t_scene) 38 | : RenderSystem(t_priority, t_scene) 39 | { 40 | m_guiMesh = m_scene->GetApplicationContext()->GetModelManager().GetStaticMeshByName(resource::ModelManager::GUI_MESH); 41 | name = "GuiRenderer"; 42 | } 43 | 44 | //------------------------------------------------- 45 | // Override 46 | //------------------------------------------------- 47 | 48 | void Update(double t_dt) override {} 49 | 50 | void Render() override 51 | { 52 | auto& shaderProgram{ m_scene->GetApplicationContext()->GetShaderManager().GetShaderProgram() }; 53 | shaderProgram.Bind(); 54 | 55 | m_scene->GetApplicationContext()->registry.view().each( 56 | [&](auto t_entity, auto&, auto&) 57 | { 58 | m_guiMesh->InitDraw(); 59 | shaderProgram.UpdateUniforms(*m_scene, t_entity, *m_guiMesh); 60 | m_guiMesh->DrawPrimitives(GL_TRIANGLE_STRIP); 61 | m_guiMesh->EndDraw(); 62 | }); 63 | 64 | resource::ShaderProgram::Unbind(); 65 | } 66 | 67 | void PrepareRendering() override 68 | { 69 | OpenGl::EnableAlphaBlending(); 70 | OpenGl::DisableDepthTesting(); 71 | } 72 | 73 | void FinishRendering() override 74 | { 75 | OpenGl::EnableDepthTesting(); 76 | OpenGl::DisableBlending(); 77 | } 78 | 79 | protected: 80 | 81 | private: 82 | MeshSharedPtr m_guiMesh; 83 | }; 84 | } 85 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/ecs/system/RenderSystem.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: RenderSystem.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2019 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include "Core.h" 13 | #include "Application.h" 14 | #include "RenderSystemInterface.h" 15 | #include "scene/Scene.h" 16 | #include "resource/ShaderManager.h" 17 | 18 | namespace sg::ogl::ecs::system 19 | { 20 | template 21 | class RenderSystem : public RenderSystemInterface 22 | { 23 | public: 24 | //------------------------------------------------- 25 | // Ctors. / Dtor. 26 | //------------------------------------------------- 27 | 28 | RenderSystem() = delete; 29 | 30 | explicit RenderSystem(scene::Scene* t_scene) 31 | : m_scene{ t_scene } 32 | { 33 | SG_OGL_CORE_ASSERT(m_scene, "[RenderSystem::RenderSystem()] Null pointer."); 34 | 35 | LoadShader(); 36 | } 37 | 38 | RenderSystem(const int t_priority, scene::Scene* t_scene) 39 | : m_scene{ t_scene } 40 | { 41 | SG_OGL_CORE_ASSERT(m_scene, "[RenderSystem::RenderSystem()] Null pointer."); 42 | 43 | priority = t_priority; 44 | 45 | LoadShader(); 46 | } 47 | 48 | RenderSystem(const RenderSystem& t_other) = delete; 49 | RenderSystem(RenderSystem&& t_other) noexcept = delete; 50 | RenderSystem& operator=(const RenderSystem& t_other) = delete; 51 | RenderSystem& operator=(RenderSystem&& t_other) noexcept = delete; 52 | 53 | virtual ~RenderSystem() noexcept = default; 54 | 55 | //------------------------------------------------- 56 | // Logic 57 | //------------------------------------------------- 58 | 59 | void Update(double t_dt) override {} 60 | void Render() override {}; 61 | void PrepareRendering() override {} 62 | void FinishRendering() override {} 63 | 64 | protected: 65 | scene::Scene* m_scene{ nullptr }; 66 | 67 | private: 68 | //------------------------------------------------- 69 | // Helper 70 | //------------------------------------------------- 71 | 72 | void LoadShader() const 73 | { 74 | (m_scene->GetApplicationContext()->GetShaderManager().AddShaderProgram(), ...); 75 | } 76 | }; 77 | } 78 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/ecs/system/RenderSystemInterface.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: RenderSystemInterface.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include 13 | 14 | namespace sg::ogl::ecs::system 15 | { 16 | class RenderSystemInterface 17 | { 18 | public: 19 | //------------------------------------------------- 20 | // Public member 21 | //------------------------------------------------- 22 | 23 | int priority{ 100 }; 24 | std::string name; 25 | 26 | //------------------------------------------------- 27 | // Ctors. / Dtor. 28 | //------------------------------------------------- 29 | 30 | RenderSystemInterface() = default; 31 | 32 | RenderSystemInterface(const RenderSystemInterface& t_other) = delete; 33 | RenderSystemInterface(RenderSystemInterface&& t_other) noexcept = delete; 34 | RenderSystemInterface& operator=(const RenderSystemInterface& t_other) = delete; 35 | RenderSystemInterface& operator=(RenderSystemInterface&& t_other) noexcept = delete; 36 | 37 | virtual ~RenderSystemInterface() 38 | { 39 | Log::SG_OGL_CORE_LOG_DEBUG("[RenderSystemInterface::~RenderSystemInterface()] Destruct RenderSystem {}.", name); 40 | } 41 | 42 | //------------------------------------------------- 43 | // Interface 44 | //------------------------------------------------- 45 | 46 | virtual void Update(double t_dt) = 0; 47 | virtual void Render() = 0; 48 | virtual void PrepareRendering() = 0; 49 | virtual void FinishRendering() = 0; 50 | 51 | protected: 52 | 53 | private: 54 | 55 | }; 56 | } 57 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/ecs/system/SkyboxRenderSystem.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: SkyboxRenderSystem.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2019 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include "RenderSystem.h" 13 | #include "resource/shaderprogram/SkyboxShaderProgram.h" 14 | #include "resource/ShaderManager.h" 15 | #include "resource/Mesh.h" 16 | #include "ecs/component/Components.h" 17 | 18 | namespace sg::ogl::ecs::system 19 | { 20 | class SkyboxRenderSystem : public RenderSystem 21 | { 22 | public: 23 | using MeshSharedPtr = std::shared_ptr; 24 | 25 | //------------------------------------------------- 26 | // Ctors. / Dtor. 27 | //------------------------------------------------- 28 | 29 | explicit SkyboxRenderSystem(scene::Scene* t_scene) 30 | : RenderSystem(t_scene) 31 | { 32 | m_skyboxMesh = m_scene->GetApplicationContext()->GetModelManager().GetStaticMeshByName(resource::ModelManager::SKYBOX_MESH); 33 | name = "SkyboxRenderer"; 34 | } 35 | 36 | SkyboxRenderSystem(const int t_priority, scene::Scene* t_scene) 37 | : RenderSystem(t_priority, t_scene) 38 | { 39 | m_skyboxMesh = m_scene->GetApplicationContext()->GetModelManager().GetStaticMeshByName(resource::ModelManager::SKYBOX_MESH); 40 | name = "SkyboxRenderer"; 41 | } 42 | 43 | //------------------------------------------------- 44 | // Override 45 | //------------------------------------------------- 46 | 47 | void Update(double t_dt) override {} 48 | 49 | void Render() override 50 | { 51 | auto view{ m_scene->GetApplicationContext()->registry.view() }; 52 | 53 | auto& shaderProgram{ m_scene->GetApplicationContext()->GetShaderManager().GetShaderProgram() }; 54 | shaderProgram.Bind(); 55 | 56 | for (auto entity : view) 57 | { 58 | m_skyboxMesh->InitDraw(); 59 | shaderProgram.UpdateUniforms(*m_scene, entity, *m_skyboxMesh); 60 | m_skyboxMesh->DrawPrimitives(); 61 | m_skyboxMesh->EndDraw(); 62 | } 63 | 64 | resource::ShaderProgram::Unbind(); 65 | } 66 | 67 | void PrepareRendering() override 68 | { 69 | OpenGl::SetDepthFunc(GL_LEQUAL); 70 | } 71 | 72 | void FinishRendering() override 73 | { 74 | // GL_LESS is the initial depth comparison function 75 | OpenGl::SetDepthFunc(GL_LESS); 76 | } 77 | 78 | protected: 79 | 80 | private: 81 | MeshSharedPtr m_skyboxMesh; 82 | }; 83 | } 84 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/ecs/system/SunRenderSystem.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: SunRenderSystem.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include "RenderSystem.h" 13 | #include "resource/shaderprogram/SunShaderProgram.h" 14 | #include "resource/ShaderManager.h" 15 | #include "resource/Mesh.h" 16 | #include "light/Sun.h" 17 | 18 | namespace sg::ogl::ecs::system 19 | { 20 | class SunRenderSystem : public RenderSystem 21 | { 22 | public: 23 | using MeshSharedPtr = std::shared_ptr; 24 | 25 | //------------------------------------------------- 26 | // Ctors. / Dtor. 27 | //------------------------------------------------- 28 | 29 | explicit SunRenderSystem(scene::Scene* t_scene) 30 | : RenderSystem(t_scene) 31 | { 32 | m_sunQuadMesh = m_scene->GetApplicationContext()->GetModelManager().GetStaticMeshByName(resource::ModelManager::SUN_QUAD_MESH); 33 | name = "SunRenderer"; 34 | } 35 | 36 | SunRenderSystem(const int t_priority, scene::Scene* t_scene) 37 | : RenderSystem(t_priority, t_scene) 38 | { 39 | m_sunQuadMesh = m_scene->GetApplicationContext()->GetModelManager().GetStaticMeshByName(resource::ModelManager::SUN_QUAD_MESH); 40 | name = "SunRenderer"; 41 | } 42 | 43 | //------------------------------------------------- 44 | // Override 45 | //------------------------------------------------- 46 | 47 | void Update(double t_dt) override {} 48 | 49 | void Render() override 50 | { 51 | auto view{ m_scene->GetApplicationContext()->registry.view() }; 52 | 53 | auto& shaderProgram{ m_scene->GetApplicationContext()->GetShaderManager().GetShaderProgram() }; 54 | shaderProgram.Bind(); 55 | 56 | for (auto entity : view) 57 | { 58 | m_sunQuadMesh->InitDraw(); 59 | shaderProgram.UpdateUniforms(*m_scene, entity, *m_sunQuadMesh); 60 | m_sunQuadMesh->DrawPrimitives(GL_TRIANGLE_STRIP); 61 | m_sunQuadMesh->EndDraw(); 62 | } 63 | 64 | resource::ShaderProgram::Unbind(); 65 | } 66 | 67 | void PrepareRendering() override 68 | { 69 | OpenGl::EnableAlphaBlending(); 70 | OpenGl::DisableDepthTesting(); 71 | } 72 | 73 | void FinishRendering() override 74 | { 75 | OpenGl::DisableBlending(); 76 | OpenGl::EnableDepthTesting(); 77 | } 78 | 79 | protected: 80 | 81 | private: 82 | MeshSharedPtr m_sunQuadMesh; 83 | }; 84 | } 85 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/imgui/imgui_impl_glfw.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Binding for GLFW 2 | // This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan..) 3 | // (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) 4 | 5 | // Implemented features: 6 | // [X] Platform: Clipboard support. 7 | // [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 8 | // [x] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. FIXME: 3 cursors types are missing from GLFW. 9 | // [X] Platform: Keyboard arrays indexed using GLFW_KEY_* codes, e.g. ImGui::IsKeyPressed(GLFW_KEY_SPACE). 10 | 11 | // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. 12 | // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. 13 | // https://github.com/ocornut/imgui 14 | 15 | // About GLSL version: 16 | // The 'glsl_version' initialization parameter defaults to "#version 150" if NULL. 17 | // Only override if your GL version doesn't handle this GLSL version. Keep NULL if unsure! 18 | 19 | #pragma once 20 | 21 | struct GLFWwindow; 22 | 23 | #include 24 | 25 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks); 26 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks); 27 | IMGUI_IMPL_API void ImGui_ImplGlfw_Shutdown(); 28 | IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame(); 29 | 30 | // InitXXX function with 'install_callbacks=true': install GLFW callbacks. They will call user's previously installed callbacks, if any. 31 | // InitXXX function with 'install_callbacks=false': do not install GLFW callbacks. You will need to call them yourself from your own GLFW callbacks. 32 | IMGUI_IMPL_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods); 33 | IMGUI_IMPL_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset); 34 | IMGUI_IMPL_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); 35 | IMGUI_IMPL_API void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c); 36 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/light/DirectionalLight.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: DirectionalLight.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2019 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include 13 | 14 | namespace sg::ogl::light 15 | { 16 | struct DirectionalLight 17 | { 18 | //------------------------------------------------- 19 | // Ctors. / Dtor. 20 | //------------------------------------------------- 21 | 22 | DirectionalLight() = default; 23 | 24 | DirectionalLight( 25 | const glm::vec3& t_direction, 26 | const glm::vec3& t_diffuseIntensity, 27 | const glm::vec3& t_specularIntensity 28 | ) 29 | : direction{ t_direction } 30 | , diffuseIntensity{ t_diffuseIntensity } 31 | , specularIntensity{ t_specularIntensity } 32 | {} 33 | 34 | DirectionalLight(const DirectionalLight& t_other) = default; 35 | DirectionalLight(DirectionalLight&& t_other) noexcept = default; 36 | DirectionalLight& operator=(const DirectionalLight& t_other) = default; 37 | DirectionalLight& operator=(DirectionalLight&& t_other) noexcept = default; 38 | 39 | virtual ~DirectionalLight() noexcept = default; 40 | 41 | //------------------------------------------------- 42 | // Member 43 | //------------------------------------------------- 44 | 45 | /** 46 | * @brief Direction as a direction from the light source. 47 | */ 48 | glm::vec3 direction{ glm::vec3(0.0f, -1.0f, 0.0f) }; 49 | 50 | glm::vec3 diffuseIntensity{ glm::vec3(1.0f, 1.0f, 1.0f) }; 51 | glm::vec3 specularIntensity{ glm::vec3(1.0f, 1.0f, 1.0f) }; 52 | }; 53 | } 54 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/light/PointLight.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: PointLight.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2019 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include 13 | 14 | /** 15 | * Distance Constant Linear Quadratic 16 | * 7 1.0 0.7 1.8 17 | * 13 1.0 0.35 0.44 18 | * 20 1.0 0.22 0.20 19 | * 32 1.0 0.14 0.07 20 | * 50 1.0 0.09 0.032 21 | * 65 1.0 0.07 0.017 22 | * 100 1.0 0.045 0.0075 23 | * 160 1.0 0.027 0.0028 24 | * 200 1.0 0.022 0.0019 25 | * 325 1.0 0.014 0.0007 26 | * 600 1.0 0.007 0.0002 27 | * 3250 1.0 0.0014 0.000007 28 | */ 29 | 30 | namespace sg::ogl::light 31 | { 32 | struct PointLight 33 | { 34 | glm::vec3 position{ glm::vec3(0.0f) }; 35 | 36 | glm::vec3 ambientIntensity{ glm::vec3(0.2f) }; 37 | glm::vec3 diffuseIntensity{ glm::vec3(1.0f) }; 38 | glm::vec3 specularIntensity{ glm::vec3(1.0f) }; 39 | 40 | // Attenuation default distance = 200 41 | float constant{ 1.0f }; 42 | float linear{ 0.022f }; 43 | float quadratic{ 0.0019f }; 44 | }; 45 | } 46 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/light/Sun.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: Sun.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include 13 | 14 | namespace sg::ogl::light 15 | { 16 | struct Sun : DirectionalLight 17 | { 18 | static constexpr auto SUN_DISTANCE{ 60.0f }; 19 | 20 | //------------------------------------------------- 21 | // Ctors. / Dtor. 22 | //------------------------------------------------- 23 | 24 | Sun() = default; 25 | 26 | Sun( 27 | const glm::vec3& t_direction, 28 | const glm::vec3& t_diffuseIntensity, 29 | const glm::vec3& t_specularIntensity, 30 | const uint32_t t_textureId, const float t_scale 31 | ) 32 | : DirectionalLight(t_direction, t_diffuseIntensity, t_specularIntensity) 33 | , textureId{ t_textureId } 34 | , scale{ t_scale } 35 | {} 36 | 37 | Sun(const Sun& t_other) = default; 38 | Sun(Sun&& t_other) noexcept = default; 39 | Sun& operator=(const Sun& t_other) = default; 40 | Sun& operator=(Sun&& t_other) noexcept = default; 41 | 42 | virtual ~Sun() noexcept = default; 43 | 44 | //------------------------------------------------- 45 | // Member 46 | //------------------------------------------------- 47 | 48 | uint32_t textureId{ 0 }; 49 | float scale{ 1.0f }; 50 | 51 | //------------------------------------------------- 52 | // Sun position 53 | //------------------------------------------------- 54 | 55 | [[nodiscard]] glm::vec3 GetWorldPosition(const glm::vec3& t_cameraPosition) const 56 | { 57 | auto sunPosition{ normalize(direction) }; 58 | sunPosition = -sunPosition; 59 | sunPosition *= SUN_DISTANCE; 60 | 61 | return t_cameraPosition + sunPosition; 62 | } 63 | }; 64 | } 65 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/math/Plane.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: Plane.cpp 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #include 11 | #include "Plane.h" 12 | 13 | sg::ogl::math::Plane sg::ogl::math::Plane::FromPoints(const glm::vec3& t_v1, const glm::vec3& t_v2, const glm::vec3& t_v3) 14 | { 15 | Plane plane; 16 | 17 | const auto e1 = t_v2 - t_v1; 18 | const auto e2 = t_v3 - t_v1; 19 | 20 | plane.normal = normalize(cross(e1, e2)); 21 | plane.distance = -dot(plane.normal, t_v1); 22 | 23 | return plane; 24 | } 25 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/math/Plane.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: Plane.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include 13 | 14 | namespace sg::ogl::math 15 | { 16 | class Plane 17 | { 18 | public: 19 | glm::vec3 normal{ glm::vec3(0.0f, 1.0f, 0.0f) }; 20 | float distance{ 0.0f }; 21 | 22 | static Plane FromPoints(const glm::vec3& t_v1, const glm::vec3& t_v2, const glm::vec3& t_v3); 23 | 24 | protected: 25 | 26 | private: 27 | 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/math/Transform.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: Transform.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include 13 | 14 | namespace sg::ogl::math 15 | { 16 | struct Transform 17 | { 18 | glm::vec3 position{ glm::vec3(0.0f, 0.0f, 0.0f) }; 19 | glm::vec3 rotation{ glm::vec3(0.0f, 0.0f, 0.0f) }; 20 | glm::vec3 scale{ glm::vec3(1.0f, 1.0f, 1.0f) }; 21 | 22 | explicit operator glm::mat4() const 23 | { 24 | auto modelMatrix{ glm::mat4(1.0f) }; 25 | 26 | modelMatrix = translate(modelMatrix, position); 27 | modelMatrix = rotate(modelMatrix, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f)); 28 | modelMatrix = rotate(modelMatrix, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f)); 29 | modelMatrix = rotate(modelMatrix, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f)); 30 | modelMatrix = glm::scale(modelMatrix, scale); 31 | 32 | return modelMatrix; 33 | } 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/particle/Particle.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: Particle.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | namespace sg::ogl::particle 16 | { 17 | struct Particle 18 | { 19 | /** 20 | * @brief The position in our world. 21 | */ 22 | glm::vec3 position{ glm::vec3(0.0f) }; 23 | 24 | /** 25 | * @brief The speed (= length of vec) and the direction. 26 | */ 27 | glm::vec3 velocity{ glm::vec3(0.0f) }; 28 | 29 | /** 30 | * @brief Determine how much the Particle is affected by gravity. 31 | * (value 1.0f = affected normal by gravity; less then one means the Particle is more floaty) 32 | */ 33 | float gravityEffect{ 1.0f }; 34 | 35 | /** 36 | * @brief Specifies how long the Particle should stay alive. 37 | */ 38 | float lifeTime{ 1.0f }; 39 | 40 | /** 41 | * @brief The Particle can rotate. 42 | */ 43 | float rotation{ 0.0f }; 44 | 45 | /** 46 | * @brief The size of the Particle. 47 | */ 48 | float scale{ 1.0f }; 49 | 50 | /** 51 | * @brief The rest of the life. 52 | */ 53 | float lifeRemaining{ 1.0f }; 54 | 55 | /** 56 | * @brief Indicates whether the Particle is still alive. 57 | */ 58 | bool active{ false }; 59 | 60 | /** 61 | * @brief The current texture stage in the texture atlas. 62 | */ 63 | int currentTextureIndex{ 0 }; 64 | 65 | /** 66 | * @brief The next texture stage in the texture atlas. 67 | */ 68 | int nextTextureIndex{ 0 }; 69 | 70 | /** 71 | * @brief The blend factor between textures. 72 | */ 73 | float blendFactor{ 0.0f }; 74 | }; 75 | } 76 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/resource/Material.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: Material.cpp 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2019 (c) stwe 9 | 10 | #include "Material.h" 11 | 12 | bool sg::ogl::resource::Material::HasAmbientMap() const 13 | { 14 | return mapKa != 0; 15 | } 16 | 17 | bool sg::ogl::resource::Material::HasDiffuseMap() const 18 | { 19 | return mapKd != 0; 20 | } 21 | 22 | bool sg::ogl::resource::Material::HasSpecularMap() const 23 | { 24 | return mapKs != 0; 25 | } 26 | 27 | bool sg::ogl::resource::Material::HasBumpMap() const 28 | { 29 | return mapBump != 0; 30 | } 31 | 32 | bool sg::ogl::resource::Material::HasNormalMap() const 33 | { 34 | return mapKn != 0; 35 | } 36 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/resource/Material.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: Material.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2019 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | namespace sg::ogl::resource 16 | { 17 | struct Material 18 | { 19 | /** 20 | * @brief The material name statement. 21 | */ 22 | std::string newmtl; 23 | 24 | /** 25 | * @brief The ambient color of the material. 26 | */ 27 | glm::vec3 ka{ glm::vec3(0.0f) }; 28 | 29 | /** 30 | * @brief The diffuse color of the material. 31 | */ 32 | glm::vec3 kd{ glm::vec3(0.0f) }; 33 | 34 | /** 35 | * @brief The specular color of the material. 36 | */ 37 | glm::vec3 ks{ glm::vec3(0.0f) }; 38 | 39 | /** 40 | * @brief Can be a number from 0 to 10 which represents 41 | * various material lighting and shading effects. 42 | * illum = 1 indicates a flat material with no specular highlights, so the value of Ks is not used. 43 | * illum = 2 denotes the presence of specular highlights, and so a specification for Ks is required. 44 | */ 45 | int illum{ 2 }; 46 | 47 | /** 48 | * @brief Specifies the specular exponent (shininess) for the material. 49 | * Ns values normally range from 0 to 1000. 50 | */ 51 | float ns{ 0.0f }; 52 | 53 | /** 54 | * @brief The transparency of the material. 55 | * A factor of 1.0 is fully opaque. 56 | * A factor of 0.0 is fully dissolved (completely transparent). 57 | */ 58 | float d{ 1.0f }; 59 | 60 | /** 61 | * @brief The ambientmap texture Id. 62 | */ 63 | uint32_t mapKa{ 0 }; 64 | 65 | /** 66 | * @brief The diffusemap texture Id. Most of time, it will be the same as 67 | * ambient texture map. 68 | */ 69 | uint32_t mapKd{ 0 }; 70 | 71 | /** 72 | * @brief The specularmap texture Id. 73 | */ 74 | uint32_t mapKs{ 0 }; 75 | 76 | /** 77 | * @brief The bumpmap texture Id. 78 | */ 79 | uint32_t mapBump{ 0 }; 80 | 81 | /** 82 | * @brief The normalmap texture Id. 83 | */ 84 | uint32_t mapKn{ 0 }; 85 | 86 | [[nodiscard]] bool HasAmbientMap() const; 87 | [[nodiscard]] bool HasDiffuseMap() const; 88 | [[nodiscard]] bool HasSpecularMap() const; 89 | [[nodiscard]] bool HasBumpMap() const; 90 | [[nodiscard]] bool HasNormalMap() const; 91 | }; 92 | } 93 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/resource/Mesh.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: Mesh.cpp 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2019 (c) stwe 9 | 10 | #include "Mesh.h" 11 | #include "Core.h" 12 | 13 | //------------------------------------------------- 14 | // Ctors. / Dtor. 15 | //------------------------------------------------- 16 | 17 | sg::ogl::resource::Mesh::Mesh() 18 | : m_vao{ std::make_unique() } 19 | { 20 | SG_OGL_CORE_ASSERT(m_vao, "[Mesh::Mesh()] Null pointer."); 21 | Log::SG_OGL_CORE_LOG_DEBUG("[Mesh::Mesh()] Create Mesh."); 22 | } 23 | 24 | sg::ogl::resource::Mesh::Mesh(const std::string& t_name) 25 | : m_vao{ std::make_unique() } 26 | , m_name{ t_name } 27 | { 28 | SG_OGL_CORE_ASSERT(m_vao, "[Mesh::Mesh()] Null pointer."); 29 | Log::SG_OGL_CORE_LOG_DEBUG("[Mesh::Mesh()] Create Mesh with name {}.", t_name); 30 | } 31 | 32 | sg::ogl::resource::Mesh::~Mesh() noexcept 33 | { 34 | Log::SG_OGL_CORE_LOG_DEBUG("[Mesh::Mesh()] Destruct Mesh."); 35 | } 36 | 37 | //------------------------------------------------- 38 | // Getter 39 | //------------------------------------------------- 40 | 41 | std::string sg::ogl::resource::Mesh::GetName() const 42 | { 43 | return m_name; 44 | } 45 | 46 | sg::ogl::resource::Mesh::MaterialSharedPtr sg::ogl::resource::Mesh::GetDefaultMaterial() const 47 | { 48 | SG_OGL_CORE_ASSERT(m_defaultMaterial, "[Mesh::GetDefaultMaterial()] Null pointer."); 49 | return m_defaultMaterial; 50 | } 51 | 52 | sg::ogl::buffer::Vao& sg::ogl::resource::Mesh::GetVao() const 53 | { 54 | return *m_vao; 55 | } 56 | 57 | //------------------------------------------------- 58 | // Setter 59 | //------------------------------------------------- 60 | 61 | void sg::ogl::resource::Mesh::SetName(const std::string& t_name) 62 | { 63 | m_name = t_name; 64 | } 65 | 66 | void sg::ogl::resource::Mesh::SetDefaultMaterial(const MaterialSharedPtr& t_defaultMaterial) 67 | { 68 | SG_OGL_CORE_ASSERT(!m_defaultMaterial, "[Mesh::SetDefaultMaterial()] Default material already exist."); 69 | m_defaultMaterial = t_defaultMaterial; 70 | } 71 | 72 | //------------------------------------------------- 73 | // Draw - methods created for convenience 74 | //------------------------------------------------- 75 | 76 | void sg::ogl::resource::Mesh::InitDraw() const 77 | { 78 | m_vao->BindVao(); 79 | } 80 | 81 | void sg::ogl::resource::Mesh::DrawPrimitives(const uint32_t t_drawMode) const 82 | { 83 | m_vao->DrawPrimitives(t_drawMode); 84 | } 85 | 86 | void sg::ogl::resource::Mesh::DrawInstanced(const int32_t t_instanceCount, const uint32_t t_drawMode) const 87 | { 88 | m_vao->DrawInstanced(t_instanceCount, t_drawMode); 89 | } 90 | 91 | void sg::ogl::resource::Mesh::EndDraw() 92 | { 93 | buffer::Vao::UnbindVao(); 94 | } 95 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/resource/Model.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: Model.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2019 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include "math/Transform.h" 18 | 19 | namespace sg::ogl 20 | { 21 | class Application; 22 | } 23 | 24 | namespace sg::ogl::resource 25 | { 26 | class Mesh; 27 | 28 | class Model 29 | { 30 | public: 31 | using VertexContainer = std::vector; 32 | using IndexContainer = std::vector; 33 | using TextureContainer = std::vector; 34 | using MeshUniquePtr = std::unique_ptr; 35 | using MeshSharedPtr = std::shared_ptr; 36 | using MeshContainer = std::vector; 37 | 38 | //------------------------------------------------- 39 | // Ctors. / Dtor. 40 | //------------------------------------------------- 41 | 42 | Model() = delete; 43 | 44 | Model(const std::string& t_fullFilePath, Application* t_application, unsigned int t_pFlags = aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_CalcTangentSpace | aiProcess_GenSmoothNormals); 45 | 46 | Model(const Model& t_other) = delete; 47 | Model(Model&& t_other) noexcept = delete; 48 | Model& operator=(const Model& t_other) = delete; 49 | Model& operator=(Model&& t_other) noexcept = delete; 50 | 51 | ~Model() noexcept; 52 | 53 | //------------------------------------------------- 54 | // Getter 55 | //------------------------------------------------- 56 | 57 | [[nodiscard]] const MeshContainer& GetMeshes() const noexcept; 58 | 59 | //------------------------------------------------- 60 | // Instancing 61 | //------------------------------------------------- 62 | 63 | void AddTransformVbo(const std::vector& t_transforms); 64 | 65 | protected: 66 | 67 | private: 68 | Application* m_application{ nullptr }; 69 | 70 | MeshContainer m_meshes; 71 | 72 | std::string m_fullFilePath; 73 | std::string m_directory; 74 | 75 | //------------------------------------------------- 76 | // Load Model 77 | //------------------------------------------------- 78 | 79 | void LoadModel(unsigned int t_pFlags); 80 | void ProcessNode(aiNode* t_node, const aiScene* t_scene); 81 | MeshUniquePtr ProcessMesh(aiMesh* t_mesh, const aiScene* t_scene) const; 82 | TextureContainer LoadMaterialTextures(aiMaterial* t_mat, aiTextureType t_type) const; 83 | }; 84 | } 85 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/resource/ShaderManager.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: ShaderManager.cpp 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2019 (c) stwe 9 | 10 | #include "ShaderManager.h" 11 | 12 | //------------------------------------------------- 13 | // Ctors. / Dtor. 14 | //------------------------------------------------- 15 | 16 | sg::ogl::resource::ShaderManager::ShaderManager(const std::string& t_libResFolder) 17 | : m_libResFolder{ t_libResFolder } 18 | { 19 | Log::SG_OGL_CORE_LOG_DEBUG("[ShaderManager::ShaderManager()] Create ShaderManager."); 20 | } 21 | 22 | sg::ogl::resource::ShaderManager::~ShaderManager() noexcept 23 | { 24 | Log::SG_OGL_CORE_LOG_DEBUG("[ShaderManager::~ShaderManager()] Destruct ShaderManager."); 25 | } 26 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/resource/ShaderUtil.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: ShaderUtil.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include "SgOglException.h" 17 | 18 | namespace sg::ogl::resource 19 | { 20 | class ShaderUtil 21 | { 22 | public: 23 | static auto ReadShaderFile(const std::string& t_fileName) 24 | { 25 | std::string content; 26 | std::ifstream shaderFile; 27 | 28 | // Ensure ifstream objects can throw exceptions. 29 | shaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit); 30 | 31 | try 32 | { 33 | // Open file. 34 | shaderFile.open(t_fileName); 35 | std::stringstream shaderStream; 36 | 37 | // Read file buffer content into stream. 38 | shaderStream << shaderFile.rdbuf(); 39 | 40 | // Close file. 41 | shaderFile.close(); 42 | 43 | // Convert stream into string. 44 | content = shaderStream.str(); 45 | } 46 | catch (const std::ifstream::failure&) 47 | { 48 | throw SG_OGL_EXCEPTION("[ShaderUtil::ReadShaderFile()] Exception caught while loading of file " + t_fileName + "."); 49 | } 50 | 51 | return content; 52 | } 53 | 54 | /** 55 | * @brief Find all positions of the a SubString in given String. 56 | * @param t_positions The found positions. 57 | * @param t_data The given string. 58 | * @param t_toSearch The search string. 59 | */ 60 | static void FindAllOccurances(std::vector& t_positions, const std::string& t_data, const std::string& t_toSearch) 61 | { 62 | // Get the first occurrence. 63 | auto pos{ t_data.find(t_toSearch) }; 64 | 65 | // Repeat till end is reached. 66 | while (pos != std::string::npos) 67 | { 68 | // Add position to the vector. 69 | t_positions.push_back(pos); 70 | 71 | // Get the next occurrence from the current position. 72 | pos = t_data.find(t_toSearch, pos + t_toSearch.size()); 73 | } 74 | } 75 | 76 | protected: 77 | 78 | private: 79 | 80 | }; 81 | } 82 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/resource/shaderprogram/ComputeNormalmap.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: ComputeNormalmap.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2019 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include "OpenGl.h" 13 | #include "terrain/TerrainConfig.h" 14 | #include "resource/ShaderProgram.h" 15 | #include "resource/TextureManager.h" 16 | 17 | namespace sg::ogl::resource::shaderprogram 18 | { 19 | class ComputeNormalmap : public ShaderProgram 20 | { 21 | public: 22 | void UpdateUniforms(const terrain::TerrainConfig& t_terrainConfig) override 23 | { 24 | SetUniform("heightmap", 0); 25 | TextureManager::BindForReading(t_terrainConfig.GetHeightmapTextureId(), GL_TEXTURE0); 26 | TextureManager::UseBilinearFilter(); 27 | 28 | SetUniform("heightmapWidth", t_terrainConfig.GetHeightmapWidth()); 29 | SetUniform("normalStrength", t_terrainConfig.normalStrength); 30 | } 31 | 32 | [[nodiscard]] std::string GetFolderName() const override 33 | { 34 | return "normalmap"; 35 | } 36 | 37 | [[nodiscard]] bool IsBuiltIn() const override 38 | { 39 | return true; 40 | } 41 | 42 | protected: 43 | 44 | private: 45 | 46 | }; 47 | } 48 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/resource/shaderprogram/ComputeSplatmap.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: ComputeSplatmap.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2019 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include "OpenGl.h" 13 | #include "terrain/TerrainConfig.h" 14 | #include "resource/ShaderProgram.h" 15 | #include "resource/TextureManager.h" 16 | 17 | namespace sg::ogl::resource::shaderprogram 18 | { 19 | class ComputeSplatmap : public ShaderProgram 20 | { 21 | public: 22 | void UpdateUniforms(const terrain::TerrainConfig& t_terrainConfig) override 23 | { 24 | SetUniform("normalmap", 0); 25 | TextureManager::BindForReading(t_terrainConfig.GetNormalmapTextureId(), GL_TEXTURE0); 26 | TextureManager::UseBilinearFilter(); 27 | 28 | SetUniform("heightmapWidth", t_terrainConfig.GetHeightmapWidth()); 29 | } 30 | 31 | [[nodiscard]] std::string GetFolderName() const override 32 | { 33 | return "splatmap"; 34 | } 35 | 36 | [[nodiscard]] bool IsBuiltIn() const override 37 | { 38 | return true; 39 | } 40 | 41 | protected: 42 | 43 | private: 44 | 45 | }; 46 | } 47 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/resource/shaderprogram/DomeShaderProgram.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: DomeShaderProgram.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2019 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include "Application.h" 13 | #include "Window.h" 14 | #include "math/Transform.h" 15 | #include "scene/Scene.h" 16 | #include "camera/Camera.h" 17 | #include "resource/ShaderProgram.h" 18 | 19 | namespace sg::ogl::resource::shaderprogram 20 | { 21 | class DomeShaderProgram : public ShaderProgram 22 | { 23 | public: 24 | void UpdateUniforms(const scene::Scene& t_scene, const entt::entity t_entity, const Mesh& t_currentMesh) override 25 | { 26 | auto& transformComponent{ t_scene.GetApplicationContext()->registry.get(t_entity) }; 27 | 28 | const auto projectionMatrix{ t_scene.GetApplicationContext()->GetWindow().GetProjectionMatrix() }; 29 | const auto mvp{ projectionMatrix * t_scene.GetCurrentCamera().GetViewMatrix() * static_cast(transformComponent) }; 30 | 31 | SetUniform("mvpMatrix", mvp); 32 | SetUniform("worldMatrix", static_cast(transformComponent)); 33 | } 34 | 35 | [[nodiscard]] std::string GetFolderName() const override 36 | { 37 | return "dome"; 38 | } 39 | 40 | [[nodiscard]] bool IsBuiltIn() const override 41 | { 42 | return true; 43 | } 44 | 45 | protected: 46 | 47 | private: 48 | 49 | }; 50 | } 51 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/resource/shaderprogram/GuiShaderProgram.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: GuiShaderProgram.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2019 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include "OpenGl.h" 13 | #include "Application.h" 14 | #include "math/Transform.h" 15 | #include "scene/Scene.h" 16 | #include "resource/ShaderProgram.h" 17 | #include "resource/TextureManager.h" 18 | #include "ecs/component/Components.h" 19 | 20 | namespace sg::ogl::resource::shaderprogram 21 | { 22 | class GuiShaderProgram : public ShaderProgram 23 | { 24 | public: 25 | void UpdateUniforms(const scene::Scene& t_scene, const entt::entity t_entity, const Mesh& t_currentMesh) override 26 | { 27 | auto& transformComponent{ t_scene.GetApplicationContext()->registry.get(t_entity) }; 28 | SetUniform("transformationMatrix", static_cast(transformComponent)); 29 | 30 | auto& guiComponent{ t_scene.GetApplicationContext()->registry.get(t_entity) }; 31 | SetUniform("guiTexture", 0); 32 | TextureManager::BindForReading(guiComponent.textureId, GL_TEXTURE0); 33 | } 34 | 35 | [[nodiscard]] std::string GetFolderName() const override 36 | { 37 | return "gui"; 38 | } 39 | 40 | [[nodiscard]] bool IsBuiltIn() const override 41 | { 42 | return true; 43 | } 44 | 45 | protected: 46 | 47 | private: 48 | 49 | }; 50 | } 51 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/resource/shaderprogram/ParticleSystemInstShaderProgram.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: ParticleSystemInstShaderProgram.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include "resource/ShaderProgram.h" 13 | #include "particle/ParticleSystem.h" 14 | 15 | namespace sg::ogl::resource::shaderprogram 16 | { 17 | class ParticleSystemInstShaderProgram : public ShaderProgram 18 | { 19 | public: 20 | void UpdateUniforms(const scene::Scene& t_scene, entt::entity t_entity, void* t_object) override 21 | { 22 | auto& particleSystemComponent{ t_scene.GetApplicationContext()->registry.get(t_entity) }; 23 | 24 | SetUniform("projectionMatrix", t_scene.GetApplicationContext()->GetWindow().GetProjectionMatrix()); 25 | SetUniform("textureRows", particleSystemComponent.particleSystem->GetTextureRows()); 26 | SetUniform("particleTexture", 0); 27 | TextureManager::BindForReading(particleSystemComponent.particleSystem->GetTextureId(), GL_TEXTURE0); 28 | } 29 | 30 | [[nodiscard]] std::string GetFolderName() const override 31 | { 32 | return "particle_inst"; 33 | } 34 | 35 | [[nodiscard]] bool IsBuiltIn() const override 36 | { 37 | return true; 38 | } 39 | 40 | protected: 41 | 42 | private: 43 | }; 44 | } 45 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/resource/shaderprogram/ParticleSystemShaderProgram.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: ParticleSystemShaderProgram.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include 13 | #include "resource/ShaderProgram.h" 14 | #include "particle/Particle.h" 15 | #include "particle/ParticleSystem.h" 16 | 17 | namespace sg::ogl::resource::shaderprogram 18 | { 19 | class ParticleSystemShaderProgram : public ShaderProgram 20 | { 21 | public: 22 | void UpdateUniforms(const scene::Scene& t_scene, entt::entity t_entity, void* t_object) override 23 | { 24 | auto& particleSystemComponent{ t_scene.GetApplicationContext()->registry.get(t_entity) }; 25 | SetUniform("particleTexture", 0); 26 | TextureManager::BindForReading(particleSystemComponent.particleSystem->GetTextureId(), GL_TEXTURE0); 27 | 28 | SetUniform("projectionMatrix", t_scene.GetApplicationContext()->GetWindow().GetProjectionMatrix()); 29 | 30 | const auto viewMatrix{ t_scene.GetCurrentCamera().GetViewMatrix() }; 31 | 32 | auto* p{ static_cast(t_object) }; 33 | 34 | auto modelMatrix = translate(glm::mat4(1.0f), p->position); 35 | modelMatrix[0][0] = viewMatrix[0][0]; 36 | modelMatrix[0][1] = viewMatrix[1][0]; 37 | modelMatrix[0][2] = viewMatrix[2][0]; 38 | modelMatrix[1][0] = viewMatrix[0][1]; 39 | modelMatrix[1][1] = viewMatrix[1][1]; 40 | modelMatrix[1][2] = viewMatrix[2][1]; 41 | modelMatrix[2][0] = viewMatrix[0][2]; 42 | modelMatrix[2][1] = viewMatrix[1][2]; 43 | modelMatrix[2][2] = viewMatrix[2][2]; 44 | 45 | modelMatrix = rotate(modelMatrix, glm::radians(p->rotation), glm::vec3(0.0f, 0.0f, 1.0f)); 46 | modelMatrix = scale(modelMatrix, glm::vec3(p->scale)); 47 | 48 | SetUniform("modelViewMatrix", viewMatrix * modelMatrix); 49 | 50 | SetUniform("texOffsetCurrent", particleSystemComponent.particleSystem->GetTextureOffset(p->currentTextureIndex)); 51 | SetUniform("texOffsetNext", particleSystemComponent.particleSystem->GetTextureOffset(p->nextTextureIndex)); 52 | SetUniform("textureRows", particleSystemComponent.particleSystem->GetTextureRows()); 53 | SetUniform("blendFactor", p->blendFactor); 54 | } 55 | 56 | [[nodiscard]] std::string GetFolderName() const override 57 | { 58 | return "particle"; 59 | } 60 | 61 | [[nodiscard]] bool IsBuiltIn() const override 62 | { 63 | return true; 64 | } 65 | 66 | protected: 67 | 68 | private: 69 | 70 | }; 71 | } 72 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/resource/shaderprogram/SkyboxShaderProgram.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: SkyboxShaderProgram.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2019 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include "OpenGl.h" 13 | #include "Application.h" 14 | #include "Window.h" 15 | #include "scene/Scene.h" 16 | #include "camera/Camera.h" 17 | #include "resource/ShaderProgram.h" 18 | #include "resource/TextureManager.h" 19 | #include "ecs/component/Components.h" 20 | 21 | namespace sg::ogl::resource::shaderprogram 22 | { 23 | class SkyboxShaderProgram : public ShaderProgram 24 | { 25 | public: 26 | void UpdateUniforms(const scene::Scene& t_scene, const entt::entity t_entity, const Mesh& t_currentMesh) override 27 | { 28 | // remove translation from the view matrix 29 | const auto skyboxViewMatrix{ glm::mat4(glm::mat3(t_scene.GetCurrentCamera().GetViewMatrix())) }; 30 | 31 | // get projection matrix 32 | const auto projectionMatrix{ t_scene.GetApplicationContext()->GetWindow().GetProjectionMatrix() }; 33 | 34 | // set shader uniforms 35 | SetUniform("projectionMatrix", projectionMatrix); 36 | SetUniform("viewMatrix", skyboxViewMatrix); 37 | SetUniform("cubeSampler", 0); 38 | 39 | // get cubemap component 40 | auto& cubemapComponent{ t_scene.GetApplicationContext()->registry.get(t_entity) }; 41 | 42 | // bind cubemap 43 | TextureManager::BindForReading(cubemapComponent.cubemapId, GL_TEXTURE0, GL_TEXTURE_CUBE_MAP); 44 | } 45 | 46 | [[nodiscard]] std::string GetFolderName() const override 47 | { 48 | return "skybox"; 49 | } 50 | 51 | [[nodiscard]] bool IsBuiltIn() const override 52 | { 53 | return true; 54 | } 55 | 56 | protected: 57 | 58 | private: 59 | 60 | }; 61 | } 62 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/resource/shaderprogram/SunShaderProgram.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: SunShaderProgram.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include "OpenGl.h" 13 | #include "Application.h" 14 | #include "light/Sun.h" 15 | #include "scene/Scene.h" 16 | #include "resource/ShaderProgram.h" 17 | #include "resource/TextureManager.h" 18 | 19 | namespace sg::ogl::resource::shaderprogram 20 | { 21 | class SunShaderProgram : public ShaderProgram 22 | { 23 | public: 24 | void UpdateUniforms(const scene::Scene& t_scene, const entt::entity t_entity, const Mesh& t_currentMesh) override 25 | { 26 | auto& sunComponent{ t_scene.GetApplicationContext()->registry.get(t_entity) }; 27 | const auto sunPosition{ sunComponent.GetWorldPosition(t_scene.GetCurrentCamera().GetPosition()) }; 28 | 29 | auto modelMatrix{ glm::mat4(1.0f) }; 30 | modelMatrix = translate(modelMatrix, sunPosition); 31 | auto mvMatrix{ ApplyViewMatrix(modelMatrix, t_scene.GetCurrentCamera().GetViewMatrix()) }; 32 | mvMatrix = scale(mvMatrix, glm::vec3(sunComponent.scale)); 33 | 34 | const auto projectionMatrix{ t_scene.GetApplicationContext()->GetWindow().GetProjectionMatrix() }; 35 | 36 | SetUniform("mvpMatrix", projectionMatrix * mvMatrix); 37 | 38 | SetUniform("sunTexture", 0); 39 | TextureManager::BindForReading(sunComponent.textureId, GL_TEXTURE0); 40 | } 41 | 42 | [[nodiscard]] std::string GetFolderName() const override 43 | { 44 | return "sun"; 45 | } 46 | 47 | [[nodiscard]] bool IsBuiltIn() const override 48 | { 49 | return true; 50 | } 51 | 52 | protected: 53 | 54 | private: 55 | static glm::mat4 ApplyViewMatrix(glm::mat4& t_modelMatrix, glm::mat4&& t_viewMatrix) 56 | { 57 | t_modelMatrix[0][0] = t_viewMatrix[0][0]; 58 | t_modelMatrix[0][1] = t_viewMatrix[1][0]; 59 | t_modelMatrix[0][2] = t_viewMatrix[2][0]; 60 | t_modelMatrix[1][0] = t_viewMatrix[0][1]; 61 | t_modelMatrix[1][1] = t_viewMatrix[1][1]; 62 | t_modelMatrix[1][2] = t_viewMatrix[2][1]; 63 | t_modelMatrix[2][0] = t_viewMatrix[0][2]; 64 | t_modelMatrix[2][1] = t_viewMatrix[1][2]; 65 | t_modelMatrix[2][2] = t_viewMatrix[2][2]; 66 | 67 | return t_viewMatrix * t_modelMatrix; 68 | } 69 | }; 70 | } 71 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/resource/shaderprogram/TerrainQuadtreeShaderProgram.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: TerrainQuadtreeShaderProgram.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include "resource/ShaderProgram.h" 13 | 14 | namespace sg::ogl::resource::shaderprogram 15 | { 16 | class TerrainQuadtreeShaderProgram : public ShaderProgram 17 | { 18 | public: 19 | void UpdateUniforms(const scene::Scene& t_scene, const entt::entity t_entity, const Mesh& t_currentMesh) override 20 | { 21 | 22 | } 23 | 24 | [[nodiscard]] Options GetOptions() const override 25 | { 26 | return VERTEX_SHADER | TESSELLATION_CONTROL_SHADER |TESSELLATION_EVALUATION_SHADER | GEOMETRY_SHADER | FRAGMENT_SHADER; 27 | } 28 | 29 | [[nodiscard]] std::string GetFolderName() const override 30 | { 31 | return "terrain_quadtree"; 32 | } 33 | 34 | [[nodiscard]] bool IsBuiltIn() const override 35 | { 36 | return true; 37 | } 38 | 39 | protected: 40 | 41 | private: 42 | 43 | }; 44 | } 45 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/resource/shaderprogram/TerrainQuadtreeWfShaderProgram.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: TerrainQuadtreeWfShaderProgram.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include "resource/ShaderProgram.h" 13 | 14 | namespace sg::ogl::resource::shaderprogram 15 | { 16 | class TerrainQuadtreeWfShaderProgram : public ShaderProgram 17 | { 18 | public: 19 | void UpdateUniforms(const scene::Scene& t_scene, const entt::entity t_entity, const Mesh& t_currentMesh) override 20 | { 21 | 22 | } 23 | 24 | [[nodiscard]] Options GetOptions() const override 25 | { 26 | return VERTEX_SHADER | TESSELLATION_CONTROL_SHADER | TESSELLATION_EVALUATION_SHADER | GEOMETRY_SHADER | FRAGMENT_SHADER; 27 | } 28 | 29 | [[nodiscard]] std::string GetFolderName() const override 30 | { 31 | return "terrain_quadtree_wireframe"; 32 | } 33 | 34 | [[nodiscard]] bool IsBuiltIn() const override 35 | { 36 | return true; 37 | } 38 | 39 | protected: 40 | 41 | private: 42 | 43 | }; 44 | } 45 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/resource/shaderprogram/TextShaderProgram.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: TextShaderProgram.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include "Application.h" 13 | #include "Window.h" 14 | #include "resource/ShaderProgram.h" 15 | 16 | namespace sg::ogl::resource::shaderprogram 17 | { 18 | class TextShaderProgram : public ShaderProgram 19 | { 20 | public: 21 | void UpdateUniforms(const scene::Scene& t_scene, const glm::vec3& t_vec3) override 22 | { 23 | SetUniform("projectionMatrix", t_scene.GetApplicationContext()->GetWindow().GetOrthographicProjectionMatrix()); 24 | SetUniform("textTexture", 0); 25 | SetUniform("textColor", t_vec3); 26 | } 27 | 28 | [[nodiscard]] std::string GetFolderName() const override 29 | { 30 | return "text"; 31 | } 32 | 33 | [[nodiscard]] bool IsBuiltIn() const override 34 | { 35 | return true; 36 | } 37 | 38 | protected: 39 | 40 | private: 41 | 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/state/State.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: State.cpp 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #include "State.h" 11 | #include "StateStack.h" 12 | #include "Core.h" 13 | 14 | //------------------------------------------------- 15 | // Ctors. / Dtor. 16 | //------------------------------------------------- 17 | 18 | sg::ogl::state::State::State(StateStack* const t_stateStack, std::string t_debugName) 19 | : m_stateStack{ t_stateStack } 20 | , m_debugName{ std::move(t_debugName) } 21 | { 22 | SG_OGL_CORE_ASSERT(m_stateStack, "[State::State()] Null pointer."); 23 | 24 | Log::SG_OGL_CORE_LOG_DEBUG("[State::State()] Create State: " + m_debugName); 25 | } 26 | 27 | sg::ogl::state::State::~State() noexcept 28 | { 29 | Log::SG_OGL_CORE_LOG_DEBUG("[State::~State()] Destruct State: " + m_debugName); 30 | } 31 | 32 | //------------------------------------------------- 33 | // Operations 34 | //------------------------------------------------- 35 | 36 | void sg::ogl::state::State::RequestStackPush(const StateId t_stateId) const 37 | { 38 | m_stateStack->PushState(t_stateId); 39 | } 40 | 41 | void sg::ogl::state::State::RequestStackPop() const 42 | { 43 | m_stateStack->PopState(); 44 | } 45 | 46 | void sg::ogl::state::State::RequestStateClear() const 47 | { 48 | m_stateStack->ClearStates(); 49 | } 50 | 51 | //------------------------------------------------- 52 | // Getter 53 | //------------------------------------------------- 54 | 55 | sg::ogl::Application* sg::ogl::state::State::GetApplicationContext() const 56 | { 57 | return m_stateStack->GetApplication(); 58 | } 59 | -------------------------------------------------------------------------------- /SgOglLib/src/SgOglLib/state/State.h: -------------------------------------------------------------------------------- 1 | // This file is part of the SgOgl package. 2 | // 3 | // Filename: State.h 4 | // Author: stwe 5 | // 6 | // License: MIT 7 | // 8 | // 2020 (c) stwe 9 | 10 | #pragma once 11 | 12 | #include 13 | 14 | namespace sg::ogl 15 | { 16 | class Application; 17 | } 18 | 19 | namespace sg::ogl::state 20 | { 21 | /** 22 | * @brief All States have a unique Id. 23 | */ 24 | enum StateId 25 | { 26 | NONE, 27 | TITLE, 28 | MENU, 29 | GAME, 30 | LOADING, 31 | PAUSE 32 | }; 33 | 34 | class StateStack; 35 | 36 | class State 37 | { 38 | public: 39 | //------------------------------------------------- 40 | // Ctors. / Dtor. 41 | //------------------------------------------------- 42 | 43 | State() = delete; 44 | 45 | explicit State(StateStack* t_stateStack, std::string t_debugName = "State"); 46 | 47 | State(const State& t_other) = delete; 48 | State(State&& t_other) noexcept = delete; 49 | State& operator=(const State& t_other) = delete; 50 | State& operator=(State&& t_other) noexcept = delete; 51 | 52 | virtual ~State() noexcept; 53 | 54 | //------------------------------------------------- 55 | // State logic 56 | //------------------------------------------------- 57 | 58 | virtual bool Input() = 0; 59 | virtual bool Update(double t_dt) = 0; 60 | virtual void Render() = 0; 61 | 62 | protected: 63 | //------------------------------------------------- 64 | // Operations 65 | //------------------------------------------------- 66 | 67 | void RequestStackPush(StateId t_stateId) const; 68 | void RequestStackPop() const; 69 | void RequestStateClear() const; 70 | 71 | //------------------------------------------------- 72 | // Getter 73 | //------------------------------------------------- 74 | 75 | Application* GetApplicationContext() const; 76 | 77 | private: 78 | /** 79 | * @brief Pointer to the parent StateStack. 80 | */ 81 | StateStack* m_stateStack{ nullptr }; 82 | 83 | std::string m_debugName; 84 | }; 85 | } 86 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/clear.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Include to copy textures or a subset of either textures. These operations are performed without memory allocations. 2 | /// @file gli/clear.hpp 3 | 4 | #pragma once 5 | 6 | namespace gli 7 | { 8 | /// Clear a complete texture 9 | template 10 | void clear(texture_type& Texture); 11 | 12 | /// Clear a complete texture 13 | template 14 | void clear(texture_type& Texture, gen_type const& BlockData); 15 | 16 | /// Clear a specific image of a texture 17 | template 18 | void clear(texture_type& Texture, size_t Layer, size_t Face, size_t Level, gen_type const& BlockData); 19 | 20 | // Clear an entire level of a texture 21 | template 22 | void clear_level(texture_type& Texture, size_t BaseLevel, gen_type const& BlockData); 23 | 24 | // Clear multiple levels of a texture 25 | template 26 | void clear_level(texture_type& Texture, size_t BaseLevel, size_t LevelCount, gen_type const& BlockData); 27 | 28 | // Clear an entire face of a texture 29 | template 30 | void clear_face(texture_type& Texture, size_t BaseFace, gen_type const& BlockData); 31 | 32 | // Clear multiple faces of a texture 33 | template 34 | void clear_face(texture_type& Texture, size_t BaseFace, size_t FaceCount, gen_type const& BlockData); 35 | 36 | // Clear an entire layer of a texture 37 | template 38 | void clear_layer(texture_type& Texture, size_t BaseLayer, gen_type const& BlockData); 39 | 40 | // Clear multiple layers of a texture 41 | template 42 | void clear_layer(texture_type& Texture, size_t BaseLayer, size_t LayerCount, gen_type const& BlockData); 43 | }//namespace gli 44 | 45 | #include "./core/clear.inl" 46 | 47 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/comparison.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Include to use operators to compare whether two textures or images are equal 2 | /// @file gli/comparison.hpp 3 | 4 | #pragma once 5 | 6 | #include "image.hpp" 7 | #include "texture1d.hpp" 8 | #include "texture1d_array.hpp" 9 | #include "texture2d.hpp" 10 | #include "texture2d_array.hpp" 11 | #include "texture3d.hpp" 12 | #include "texture_cube.hpp" 13 | #include "texture_cube_array.hpp" 14 | 15 | namespace gli 16 | { 17 | /// Compare two images. Two images are equal when the date is the same. 18 | bool operator==(image const& ImageA, image const& ImageB); 19 | 20 | /// Compare two images. Two images are equal when the date is the same. 21 | bool operator!=(image const& ImageA, image const& ImageB); 22 | 23 | /// Compare two textures. Two textures are the same when the data, the format and the targets are the same. 24 | bool operator==(texture const& A, texture const& B); 25 | 26 | /// Compare two textures. Two textures are the same when the data, the format and the targets are the same. 27 | bool operator!=(texture const& A, texture const& B); 28 | }//namespace gli 29 | 30 | #include "./core/comparison.inl" 31 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/convert.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Include to copy textures, images or a subset of either textures or an images. These operations will cause memory allocations. 2 | /// @file gli/convert.hpp 3 | 4 | #pragma once 5 | 6 | #include "texture1d.hpp" 7 | #include "texture1d_array.hpp" 8 | #include "texture2d.hpp" 9 | #include "texture2d_array.hpp" 10 | #include "texture3d.hpp" 11 | #include "texture_cube.hpp" 12 | #include "texture_cube_array.hpp" 13 | 14 | namespace gli 15 | { 16 | /// Convert texture data to a new format 17 | /// 18 | /// @param Texture Source texture, the format must be uncompressed. 19 | /// @param Format Destination Texture format, it must be uncompressed. 20 | template 21 | texture_type convert(texture_type const& Texture, format Format); 22 | }//namespace gli 23 | 24 | #include "./core/convert.inl" 25 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/copy.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Include to copy textures or a subset of either textures. These operations are performed without memory allocations. 2 | /// @file gli/copy.hpp 3 | 4 | #pragma once 5 | 6 | #include "type.hpp" 7 | 8 | namespace gli 9 | { 10 | /// Copy a specific image of a texture 11 | template 12 | void copy( 13 | texture_src_type const& TextureSrc, size_t LayerSrc, size_t FaceSrc, size_t LevelSrc, 14 | texture_dst_type& TextureDst, size_t LayerDst, size_t FaceDst, size_t LevelDst); 15 | 16 | /// Copy a texture 17 | template 18 | void copy( 19 | texture_src_type const& TextureSrc, 20 | texture_dst_type& TextureDst); 21 | 22 | // Copy an entire level of a texture 23 | template 24 | void copy_level( 25 | texture_src_type const& TextureSrc, size_t BaseLevelSrc, 26 | texture_dst_type& TextureDst, size_t BaseLevelDst); 27 | 28 | // Copy multiple levels of a texture 29 | template 30 | void copy_level( 31 | texture_src_type const& TextureSrc, size_t BaseLevelSrc, 32 | texture_dst_type& TextureDst, size_t BaseLevelDst, 33 | size_t LevelCount); 34 | 35 | // Copy an entire face of a texture 36 | template 37 | void copy_face( 38 | texture_src_type const& TextureSrc, size_t BaseFaceSrc, 39 | texture_dst_type& TextureDst, size_t BaseFaceDst); 40 | 41 | // Copy multiple faces of a texture 42 | template 43 | void copy_face( 44 | texture_src_type const& TextureSrc, size_t BaseFaceSrc, 45 | texture_dst_type& TextureDst, size_t BaseFaceDst, 46 | size_t FaceCount); 47 | 48 | // Copy an entire layer of a texture 49 | template 50 | void copy_layer( 51 | texture_src_type const& TextureSrc, size_t BaseLayerSrc, 52 | texture_dst_type& TextureDst, size_t BaseLayerDst); 53 | 54 | // Copy multiple layers of a texture 55 | template 56 | void copy_layer( 57 | texture_src_type const& TextureSrc, size_t BaseLayerSrc, 58 | texture_dst_type& TextureDst, size_t BaseLayerDst, 59 | size_t LayerCount); 60 | }//namespace gli 61 | 62 | #include "./core/copy.inl" 63 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/core/bc.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Include to compress and decompress the BC compression scheme 2 | /// @file gli/bc.hpp 3 | 4 | #pragma once 5 | 6 | #include "./s3tc.hpp" 7 | 8 | namespace gli 9 | { 10 | namespace detail 11 | { 12 | typedef dxt1_block bc1_block; 13 | typedef dxt3_block bc2_block; 14 | typedef dxt5_block bc3_block; 15 | 16 | struct bc4_block { 17 | uint8_t Red0; 18 | uint8_t Red1; 19 | uint8_t Bitmap[6]; 20 | }; 21 | 22 | struct bc5_block { 23 | uint8_t Red0; 24 | uint8_t Red1; 25 | uint8_t RedBitmap[6]; 26 | uint8_t Green0; 27 | uint8_t Green1; 28 | uint8_t GreenBitmap[6]; 29 | }; 30 | 31 | glm::vec4 decompress_bc1(const bc1_block &Block, const extent2d &BlockTexelCoord); 32 | texel_block4x4 decompress_dxt1_block(const dxt1_block &Block); 33 | 34 | glm::vec4 decompress_bc2(const bc2_block &Block, const extent2d &BlockTexelCoord); 35 | texel_block4x4 decompress_dxt3_block(const bc2_block &Block); 36 | 37 | glm::vec4 decompress_bc3(const bc3_block &Block, const extent2d &BlockTexelCoord); 38 | texel_block4x4 decompress_bc3_block(const dxt5_block &Block); 39 | 40 | glm::vec4 decompress_bc4unorm(const bc4_block &Block, const extent2d &BlockTexelCoord); 41 | glm::vec4 decompress_bc4snorm(const bc4_block &Block, const extent2d &BlockTexelCoord); 42 | texel_block4x4 decompress_bc4unorm_block(const bc4_block &Block); 43 | texel_block4x4 decompress_bc4snorm_block(const bc4_block &Block); 44 | 45 | glm::vec4 decompress_bc5unorm(const bc5_block &Block, const extent2d &BlockTexelCoord); 46 | glm::vec4 decompress_bc5snorm(const bc5_block &Block, const extent2d &BlockTexelCoord); 47 | texel_block4x4 decompress_bc5unorm_block(const bc5_block &Block); 48 | texel_block4x4 decompress_bc5snorm_block(const bc5_block &Block); 49 | }//namespace detail 50 | }//namespace gli 51 | 52 | #include "./bc.inl" 53 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/core/clear.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "convert_func.hpp" 4 | 5 | namespace gli{ 6 | namespace detail 7 | { 8 | template 9 | struct clear 10 | { 11 | static void call(textureType & Texture, typename convert::writeFunc Write, vec<4, T, P> const& Color) 12 | { 13 | GLI_ASSERT(Write); 14 | 15 | texture const ConvertTexel(Texture.target(), Texture.format(), texture::extent_type(1), 1, 1, 1); 16 | textureType Texel(ConvertTexel); 17 | Write(Texel, typename textureType::extent_type(0), 0, 0, 0, Color); 18 | 19 | size_t const BlockSize(block_size(Texture.format())); 20 | for(size_t BlockIndex = 0, BlockCount = Texture.size() / BlockSize; BlockIndex < BlockCount; ++BlockIndex) 21 | memcpy(static_cast(Texture.data()) + BlockSize * BlockIndex, Texel.data(), BlockSize); 22 | } 23 | }; 24 | }//namespace detail 25 | }//namespace gli 26 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/core/convert.inl: -------------------------------------------------------------------------------- 1 | #include "../core/convert_func.hpp" 2 | 3 | namespace gli 4 | { 5 | template 6 | inline texture_type convert(texture_type const& Texture, format Format) 7 | { 8 | typedef float T; 9 | typedef typename texture::extent_type extent_type; 10 | typedef typename texture_type::size_type size_type; 11 | typedef typename extent_type::value_type component_type; 12 | typedef typename detail::convert::fetchFunc fetch_type; 13 | typedef typename detail::convert::writeFunc write_type; 14 | 15 | GLI_ASSERT(!Texture.empty()); 16 | GLI_ASSERT(!is_compressed(Texture.format()) && !is_compressed(Format)); 17 | 18 | fetch_type Fetch = detail::convert::call(Texture.format()).Fetch; 19 | write_type Write = detail::convert::call(Format).Write; 20 | 21 | texture Storage(Texture.target(), Format, Texture.texture::extent(), Texture.layers(), Texture.faces(), Texture.levels(), Texture.swizzles()); 22 | texture_type Copy(Storage); 23 | 24 | for(size_type Layer = 0; Layer < Texture.layers(); ++Layer) 25 | for(size_type Face = 0; Face < Texture.faces(); ++Face) 26 | for(size_type Level = 0; Level < Texture.levels(); ++Level) 27 | { 28 | extent_type const& Dimensions = Texture.texture::extent(Level); 29 | 30 | for(component_type k = 0; k < Dimensions.z; ++k) 31 | for(component_type j = 0; j < Dimensions.y; ++j) 32 | for(component_type i = 0; i < Dimensions.x; ++i) 33 | { 34 | typename texture_type::extent_type const Texelcoord(extent_type(i, j, k)); 35 | Write( 36 | Copy, Texelcoord, Layer, Face, Level, 37 | Fetch(Texture, Texelcoord, Layer, Face, Level)); 38 | } 39 | } 40 | 41 | return texture_type(Copy); 42 | } 43 | 44 | }//namespace gli 45 | 46 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/core/dummy.cpp: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | 4 | } 5 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/core/file.hpp: -------------------------------------------------------------------------------- 1 | /// @brief File helper functions 2 | /// @file gli/core/file.hpp 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | namespace gli{ 9 | namespace detail 10 | { 11 | FILE* open_file(const char *Filename, const char *mode); 12 | }//namespace detail 13 | }//namespace gli 14 | 15 | #include "./file.inl" 16 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/core/file.inl: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace gli{ 6 | namespace detail 7 | { 8 | inline FILE* open_file(const char *Filename, const char *Mode) 9 | { 10 | # if GLM_COMPILER & GLM_COMPILER_VC 11 | FILE *File = nullptr; 12 | fopen_s(&File, Filename, Mode); 13 | return File; 14 | # else 15 | return std::fopen(Filename, Mode); 16 | # endif 17 | } 18 | }//namespace detail 19 | }//namespace gli 20 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/core/filter.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Include to use filter enum, to select filtering methods. 2 | /// @file gli/core/filter.hpp 3 | 4 | #pragma once 5 | 6 | namespace gli 7 | { 8 | /// Texture filtring modes 9 | enum filter 10 | { 11 | FILTER_NONE = 0, 12 | FILTER_NEAREST, FILTER_FIRST = FILTER_NEAREST, 13 | FILTER_LINEAR, FILTER_LAST = FILTER_LINEAR 14 | }; 15 | 16 | enum 17 | { 18 | FILTER_COUNT = FILTER_LAST - FILTER_FIRST + 1, 19 | FILTER_INVALID = -1 20 | }; 21 | }//namespace gli 22 | 23 | #include "filter.inl" 24 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/core/filter.inl: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace gli{ 4 | namespace detail 5 | { 6 | 7 | }//namespace detail 8 | }//namespace gli 9 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/core/flip.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../texture2d.hpp" 6 | #include "../texture2d_array.hpp" 7 | #include "../texture_cube.hpp" 8 | #include "../texture_cube_array.hpp" 9 | 10 | namespace gli 11 | { 12 | template 13 | texture flip(texture const & Texture); 14 | 15 | }//namespace gli 16 | 17 | #include "flip.inl" 18 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/core/levels.inl: -------------------------------------------------------------------------------- 1 | #include 2 | #define GLM_ENABLE_EXPERIMENTAL 3 | #include 4 | 5 | namespace gli 6 | { 7 | template 8 | inline T levels(vec const& Extent) 9 | { 10 | return glm::log2(compMax(Extent)) + static_cast(1); 11 | } 12 | 13 | template 14 | inline T levels(T Extent) 15 | { 16 | return static_cast(glm::log2(Extent) + static_cast(1)); 17 | } 18 | /* 19 | inline int levels(int Extent) 20 | { 21 | return glm::log2(Extent) + static_cast(1); 22 | } 23 | */ 24 | }//namespace gli 25 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/core/load.inl: -------------------------------------------------------------------------------- 1 | #include "../load_dds.hpp" 2 | #include "../load_kmg.hpp" 3 | #include "../load_ktx.hpp" 4 | #include "file.hpp" 5 | 6 | namespace gli 7 | { 8 | /// Load a texture (DDS, KTX or KMG) from memory 9 | inline texture load(char const * Data, std::size_t Size) 10 | { 11 | { 12 | texture Texture = load_dds(Data, Size); 13 | if(!Texture.empty()) 14 | return Texture; 15 | } 16 | { 17 | texture Texture = load_kmg(Data, Size); 18 | if(!Texture.empty()) 19 | return Texture; 20 | } 21 | { 22 | texture Texture = load_ktx(Data, Size); 23 | if(!Texture.empty()) 24 | return Texture; 25 | } 26 | 27 | return texture(); 28 | } 29 | 30 | /// Load a texture (DDS, KTX or KMG) from file 31 | inline texture load(char const * Filename) 32 | { 33 | FILE* File = detail::open_file(Filename, "rb"); 34 | if(!File) 35 | return texture(); 36 | 37 | long Beg = std::ftell(File); 38 | std::fseek(File, 0, SEEK_END); 39 | long End = std::ftell(File); 40 | std::fseek(File, 0, SEEK_SET); 41 | 42 | std::vector Data(static_cast(End - Beg)); 43 | 44 | std::fread(&Data[0], 1, Data.size(), File); 45 | std::fclose(File); 46 | 47 | return load(&Data[0], Data.size()); 48 | } 49 | 50 | /// Load a texture (DDS, KTX or KMG) from file 51 | inline texture load(std::string const & Filename) 52 | { 53 | return load(Filename.c_str()); 54 | } 55 | }//namespace gli 56 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/core/s3tc.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Include to compress and decompress s3tc blocks 2 | /// @file gli/s3tc.hpp 3 | 4 | #pragma once 5 | 6 | namespace gli 7 | { 8 | namespace detail 9 | { 10 | struct dxt1_block { 11 | uint16_t Color0; 12 | uint16_t Color1; 13 | uint8_t Row[4]; 14 | }; 15 | 16 | struct dxt3_block { 17 | uint16_t AlphaRow[4]; 18 | uint16_t Color0; 19 | uint16_t Color1; 20 | uint8_t Row[4]; 21 | }; 22 | 23 | struct dxt5_block { 24 | uint8_t Alpha[2]; 25 | uint8_t AlphaBitmap[6]; 26 | uint16_t Color0; 27 | uint16_t Color1; 28 | uint8_t Row[4]; 29 | }; 30 | 31 | struct texel_block4x4 { 32 | // row x col 33 | glm::vec4 Texel[4][4]; 34 | }; 35 | 36 | glm::vec4 decompress_dxt1(const dxt1_block &Block, const extent2d &BlockTexelCoord); 37 | texel_block4x4 decompress_dxt1_block(const dxt1_block &Block); 38 | 39 | glm::vec4 decompress_dxt3(const dxt3_block &Block, const extent2d &BlockTexelCoord); 40 | texel_block4x4 decompress_dxt3_block(const dxt3_block &Block); 41 | 42 | glm::vec4 decompress_dxt5(const dxt5_block &Block, const extent2d &BlockTexelCoord); 43 | texel_block4x4 decompress_dxt5_block(const dxt5_block &Block); 44 | 45 | }//namespace detail 46 | }//namespace gli 47 | 48 | #include "./s3tc.inl" 49 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/core/sampler.inl: -------------------------------------------------------------------------------- 1 | #define GLM_ENABLE_EXPERIMENTAL 2 | #include 3 | 4 | namespace gli{ 5 | namespace detail 6 | { 7 | template 8 | inline T passThrought(T const & SampleCoord) 9 | { 10 | return SampleCoord; 11 | } 12 | }//namespace detail 13 | 14 | inline sampler::sampler(wrap Wrap, filter Mip, filter Min) 15 | : Wrap(get_func(Wrap)) 16 | , Mip(Mip) 17 | , Min(Min) 18 | {} 19 | 20 | inline sampler::wrap_type sampler::get_func(wrap WrapMode) const 21 | { 22 | static wrap_type Table[] = 23 | { 24 | glm::clamp, 25 | detail::passThrought, 26 | glm::repeat, 27 | glm::mirrorRepeat, 28 | glm::mirrorClamp, 29 | glm::mirrorClamp 30 | }; 31 | static_assert(sizeof(Table) / sizeof(Table[0]) == WRAP_COUNT, "Table needs to be updated"); 32 | 33 | return Table[WrapMode]; 34 | } 35 | }//namespace gli 36 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/core/save.inl: -------------------------------------------------------------------------------- 1 | #include "../save_dds.hpp" 2 | #include "../save_kmg.hpp" 3 | #include "../save_ktx.hpp" 4 | 5 | namespace gli 6 | { 7 | inline bool save(texture const & Texture, char const * Path) 8 | { 9 | return save(Texture, std::string(Path)); 10 | } 11 | 12 | inline bool save(texture const & Texture, std::string const & Path) 13 | { 14 | if(Path.rfind(".dds") != std::string::npos) 15 | return save_dds(Texture, Path); 16 | if(Path.rfind(".kmg") != std::string::npos) 17 | return save_kmg(Texture, Path); 18 | if(Path.rfind(".ktx") != std::string::npos) 19 | return save_ktx(Texture, Path); 20 | return false; 21 | } 22 | }//namespace gli 23 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/core/save_kmg.inl: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "../load_kmg.hpp" 4 | #include "filter.hpp" 5 | #include "file.hpp" 6 | 7 | namespace gli 8 | { 9 | inline bool save_kmg(texture const & Texture, std::vector & Memory) 10 | { 11 | if(Texture.empty()) 12 | return false; 13 | 14 | Memory.resize(sizeof(detail::FOURCC_KMG100) + sizeof(detail::kmgHeader10) + Texture.size()); 15 | 16 | std::memcpy(&Memory[0], detail::FOURCC_KMG100, sizeof(detail::FOURCC_KMG100)); 17 | 18 | std::size_t Offset = sizeof(detail::FOURCC_KMG100); 19 | 20 | texture::swizzles_type Swizzle = Texture.swizzles(); 21 | 22 | detail::kmgHeader10 & Header = *reinterpret_cast(&Memory[0] + Offset); 23 | Header.Endianness = 0x04030201; 24 | Header.Format = Texture.format(); 25 | Header.Target = Texture.target(); 26 | Header.SwizzleRed = Swizzle[0]; 27 | Header.SwizzleGreen = Swizzle[1]; 28 | Header.SwizzleBlue = Swizzle[2]; 29 | Header.SwizzleAlpha = Swizzle[3]; 30 | Header.PixelWidth = static_cast(Texture.extent().x); 31 | Header.PixelHeight = static_cast(Texture.extent().y); 32 | Header.PixelDepth = static_cast(Texture.extent().z); 33 | Header.Layers = static_cast(Texture.layers()); 34 | Header.Levels = static_cast(Texture.levels()); 35 | Header.Faces = static_cast(Texture.faces()); 36 | Header.GenerateMipmaps = FILTER_NONE; 37 | Header.BaseLevel = static_cast(Texture.base_level()); 38 | Header.MaxLevel = static_cast(Texture.max_level()); 39 | 40 | Offset += sizeof(detail::kmgHeader10); 41 | 42 | for(texture::size_type Layer = 0, Layers = Texture.layers(); Layer < Layers; ++Layer) 43 | for(texture::size_type Level = 0, Levels = Texture.levels(); Level < Levels; ++Level) 44 | { 45 | texture::size_type const FaceSize = Texture.size(Level); 46 | for(texture::size_type Face = 0, Faces = Texture.faces(); Face < Faces; ++Face) 47 | { 48 | std::memcpy(&Memory[0] + Offset, Texture.data(Layer, Face, Level), FaceSize); 49 | 50 | Offset += FaceSize; 51 | GLI_ASSERT(Offset <= Memory.size()); 52 | } 53 | } 54 | 55 | return true; 56 | } 57 | 58 | inline bool save_kmg(texture const & Texture, char const * Filename) 59 | { 60 | if(Texture.empty()) 61 | return false; 62 | 63 | FILE* File = detail::open_file(Filename, "wb"); 64 | if(!File) 65 | return false; 66 | 67 | std::vector Memory; 68 | bool const Result = save_kmg(Texture, Memory); 69 | 70 | std::fwrite(&Memory[0], 1, Memory.size(), File); 71 | std::fclose(File); 72 | 73 | return Result; 74 | } 75 | 76 | inline bool save_kmg(texture const & Texture, std::string const & Filename) 77 | { 78 | return save_kmg(Texture, Filename.c_str()); 79 | } 80 | }//namespace gli 81 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/core/storage.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // STD 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "../type.hpp" 13 | #include "../format.hpp" 14 | 15 | // GLM 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | static_assert(GLM_VERSION >= 97, "GLI requires at least GLM 0.9.7"); 24 | 25 | namespace gli 26 | { 27 | class storage_linear 28 | { 29 | public: 30 | typedef extent3d extent_type; 31 | typedef size_t size_type; 32 | typedef gli::format format_type; 33 | typedef glm::byte data_type; 34 | 35 | public: 36 | storage_linear(); 37 | 38 | storage_linear( 39 | format_type Format, 40 | extent_type const & Extent, 41 | size_type Layers, 42 | size_type Faces, 43 | size_type Levels); 44 | 45 | bool empty() const; 46 | size_type size() const; // Express is bytes 47 | size_type layers() const; 48 | size_type levels() const; 49 | size_type faces() const; 50 | 51 | size_type block_size() const; 52 | extent_type block_extent() const; 53 | extent_type block_count(size_type Level) const; 54 | extent_type extent(size_type Level) const; 55 | 56 | data_type* data(); 57 | data_type const* const data() const; 58 | 59 | /// Compute the relative memory offset to access the data for a specific layer, face and level 60 | size_type base_offset( 61 | size_type Layer, 62 | size_type Face, 63 | size_type Level) const; 64 | 65 | /// Copy a subset of a specific image of a texture 66 | void copy( 67 | storage_linear const& StorageSrc, 68 | size_t LayerSrc, size_t FaceSrc, size_t LevelSrc, extent_type const& BlockIndexSrc, 69 | size_t LayerDst, size_t FaceDst, size_t LevelDst, extent_type const& BlockIndexDst, 70 | extent_type const& BlockCount); 71 | 72 | size_type level_size( 73 | size_type Level) const; 74 | size_type face_size( 75 | size_type BaseLevel, size_type MaxLevel) const; 76 | size_type layer_size( 77 | size_type BaseFace, size_type MaxFace, 78 | size_type BaseLevel, size_type MaxLevel) const; 79 | 80 | private: 81 | size_type const Layers; 82 | size_type const Faces; 83 | size_type const Levels; 84 | size_type const BlockSize; 85 | extent_type const BlockCount; 86 | extent_type const BlockExtent; 87 | extent_type const Extent; 88 | std::vector Data; 89 | }; 90 | }//namespace gli 91 | 92 | #include "storage_linear.inl" 93 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/core/storage_linear.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // STD 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "../type.hpp" 13 | #include "../format.hpp" 14 | 15 | // GLM 16 | #include 17 | #include 18 | #include 19 | //#include 20 | //#include 21 | //#include 22 | 23 | static_assert(GLM_VERSION >= 97, "GLI requires at least GLM 0.9.7"); 24 | 25 | namespace gli 26 | { 27 | class storage_linear 28 | { 29 | public: 30 | typedef extent3d extent_type; 31 | typedef size_t size_type; 32 | typedef gli::format format_type; 33 | typedef gli::byte data_type; 34 | 35 | public: 36 | storage_linear(); 37 | 38 | storage_linear( 39 | format_type Format, 40 | extent_type const & Extent, 41 | size_type Layers, 42 | size_type Faces, 43 | size_type Levels); 44 | 45 | bool empty() const; 46 | size_type size() const; // Express is bytes 47 | size_type layers() const; 48 | size_type levels() const; 49 | size_type faces() const; 50 | 51 | size_type block_size() const; 52 | extent_type block_extent() const; 53 | extent_type block_count(size_type Level) const; 54 | extent_type extent(size_type Level) const; 55 | 56 | data_type* data(); 57 | data_type const* const data() const; 58 | 59 | /// Compute the relative memory offset to access the data for a specific layer, face and level 60 | size_type base_offset( 61 | size_type Layer, 62 | size_type Face, 63 | size_type Level) const; 64 | 65 | size_type image_offset(extent1d const& Coord, extent1d const& Extent) const; 66 | 67 | size_type image_offset(extent2d const& Coord, extent2d const& Extent) const; 68 | 69 | size_type image_offset(extent3d const& Coord, extent3d const& Extent) const; 70 | 71 | /// Copy a subset of a specific image of a texture 72 | void copy( 73 | storage_linear const& StorageSrc, 74 | size_t LayerSrc, size_t FaceSrc, size_t LevelSrc, extent_type const& BlockIndexSrc, 75 | size_t LayerDst, size_t FaceDst, size_t LevelDst, extent_type const& BlockIndexDst, 76 | extent_type const& BlockCount); 77 | 78 | size_type level_size( 79 | size_type Level) const; 80 | size_type face_size( 81 | size_type BaseLevel, size_type MaxLevel) const; 82 | size_type layer_size( 83 | size_type BaseFace, size_type MaxFace, 84 | size_type BaseLevel, size_type MaxLevel) const; 85 | 86 | private: 87 | size_type const Layers; 88 | size_type const Faces; 89 | size_type const Levels; 90 | size_type const BlockSize; 91 | extent_type const BlockCount; 92 | extent_type const BlockExtent; 93 | extent_type const Extent; 94 | std::vector Data; 95 | }; 96 | }//namespace gli 97 | 98 | #include "storage_linear.inl" 99 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/core/texture1d.inl: -------------------------------------------------------------------------------- 1 | #include "../levels.hpp" 2 | 3 | namespace gli 4 | { 5 | inline texture1d::texture1d() 6 | {} 7 | 8 | inline texture1d::texture1d(format_type Format, extent_type const& Extent, swizzles_type const& Swizzles) 9 | : texture(TARGET_1D, Format, texture::extent_type(Extent.x, 1, 1), 1, 1, gli::levels(Extent), Swizzles) 10 | {} 11 | 12 | inline texture1d::texture1d(format_type Format, extent_type const& Extent, size_type Levels, swizzles_type const& Swizzles) 13 | : texture(TARGET_1D, Format, texture::extent_type(Extent.x, 1, 1), 1, 1, Levels, Swizzles) 14 | {} 15 | 16 | inline texture1d::texture1d(texture const& Texture) 17 | : texture(Texture, TARGET_1D, Texture.format()) 18 | {} 19 | 20 | inline texture1d::texture1d 21 | ( 22 | texture const& Texture, 23 | format_type Format, 24 | size_type BaseLayer, size_type MaxLayer, 25 | size_type BaseFace, size_type MaxFace, 26 | size_type BaseLevel, size_type MaxLevel, 27 | swizzles_type const& Swizzles 28 | ) 29 | : texture( 30 | Texture, TARGET_1D, 31 | Format, 32 | BaseLayer, MaxLayer, 33 | BaseFace, MaxFace, 34 | BaseLevel, MaxLevel, 35 | Swizzles) 36 | {} 37 | 38 | inline texture1d::texture1d 39 | ( 40 | texture1d const& Texture, 41 | size_type BaseLevel, size_type MaxLevel 42 | ) 43 | : texture( 44 | Texture, TARGET_1D, 45 | Texture.format(), 46 | Texture.base_layer(), Texture.max_layer(), 47 | Texture.base_face(), Texture.max_face(), 48 | Texture.base_level() + BaseLevel, Texture.base_level() + MaxLevel) 49 | {} 50 | 51 | inline image texture1d::operator[](texture1d::size_type Level) const 52 | { 53 | GLI_ASSERT(Level < this->levels()); 54 | 55 | return image( 56 | this->Storage, 57 | this->format(), 58 | this->base_layer(), 59 | this->base_face(), 60 | this->base_level() + Level); 61 | } 62 | 63 | inline texture1d::extent_type texture1d::extent(size_type Level) const 64 | { 65 | return extent_type(this->texture::extent(Level)); 66 | } 67 | 68 | template 69 | inline gen_type texture1d::load(extent_type const& TexelCoord, size_type Level) const 70 | { 71 | return this->texture::load(texture::extent_type(TexelCoord.x, 0, 0), 0, 0, Level); 72 | } 73 | 74 | template 75 | inline void texture1d::store(extent_type const& TexelCoord, size_type Level, gen_type const& Texel) 76 | { 77 | this->texture::store(texture::extent_type(TexelCoord.x, 0, 0), 0, 0, Level, Texel); 78 | } 79 | }//namespace gli 80 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/core/texture1d_array.inl: -------------------------------------------------------------------------------- 1 | #include "../levels.hpp" 2 | 3 | namespace gli 4 | { 5 | inline texture1d_array::texture1d_array() 6 | {} 7 | 8 | inline texture1d_array::texture1d_array(format_type Format, extent_type const& Extent, size_type Layers, swizzles_type const& Swizzles) 9 | : texture(TARGET_1D_ARRAY, Format, texture::extent_type(Extent.x, 1, 1), Layers, 1, gli::levels(Extent), Swizzles) 10 | {} 11 | 12 | inline texture1d_array::texture1d_array(format_type Format, extent_type const& Extent, size_type Layers, size_type Levels, swizzles_type const& Swizzles) 13 | : texture(TARGET_1D_ARRAY, Format, texture::extent_type(Extent.x, 1, 1), Layers, 1, Levels, Swizzles) 14 | {} 15 | 16 | inline texture1d_array::texture1d_array(texture const& Texture) 17 | : texture(Texture, TARGET_1D_ARRAY, Texture.format()) 18 | {} 19 | 20 | inline texture1d_array::texture1d_array 21 | ( 22 | texture const& Texture, 23 | format_type Format, 24 | size_type BaseLayer, size_type MaxLayer, 25 | size_type BaseFace, size_type MaxFace, 26 | size_type BaseLevel, size_type MaxLevel, 27 | swizzles_type const& Swizzles 28 | ) 29 | : texture( 30 | Texture, TARGET_1D_ARRAY, Format, 31 | BaseLayer, MaxLayer, 32 | BaseFace, MaxFace, 33 | BaseLevel, MaxLevel, 34 | Swizzles) 35 | {} 36 | 37 | inline texture1d_array::texture1d_array 38 | ( 39 | texture1d_array const& Texture, 40 | size_type BaseLayer, size_type MaxLayer, 41 | size_type BaseLevel, size_type MaxLevel 42 | ) 43 | : texture( 44 | Texture, TARGET_1D_ARRAY, 45 | Texture.format(), 46 | Texture.base_layer() + BaseLayer, Texture.base_layer() + MaxLayer, 47 | Texture.base_face(), Texture.max_face(), 48 | Texture.base_level() + BaseLevel, Texture.base_level() + MaxLevel) 49 | {} 50 | 51 | inline texture1d texture1d_array::operator[](size_type Layer) const 52 | { 53 | GLI_ASSERT(!this->empty()); 54 | GLI_ASSERT(Layer < this->layers()); 55 | 56 | return texture1d( 57 | *this, this->format(), 58 | this->base_layer() + Layer, this->base_layer() + Layer, 59 | this->base_face(), this->max_face(), 60 | this->base_level(), this->max_level()); 61 | } 62 | 63 | inline texture1d_array::extent_type texture1d_array::extent(size_type Level) const 64 | { 65 | return extent_type(this->texture::extent(Level)); 66 | } 67 | 68 | template 69 | inline gen_type texture1d_array::load(extent_type const& TexelCoord, size_type Layer, size_type Level) const 70 | { 71 | return this->texture::load(texture::extent_type(TexelCoord.x, 0, 0), Layer, 0, Level); 72 | } 73 | 74 | template 75 | inline void texture1d_array::store(extent_type const& TexelCoord, size_type Layer, size_type Level, gen_type const& Texel) 76 | { 77 | this->texture::store(texture::extent_type(TexelCoord.x, 0, 0), Layer, 0, Level, Texel); 78 | } 79 | }//namespace gli 80 | 81 | 82 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/core/texture2d.inl: -------------------------------------------------------------------------------- 1 | #include "../levels.hpp" 2 | 3 | namespace gli 4 | { 5 | inline texture2d::texture2d() 6 | {} 7 | 8 | inline texture2d::texture2d(format_type Format, extent_type const& Extent, swizzles_type const& Swizzles) 9 | : texture(TARGET_2D, Format, texture::extent_type(Extent, 1), 1, 1, gli::levels(Extent), Swizzles) 10 | {} 11 | 12 | inline texture2d::texture2d(format_type Format, extent_type const& Extent, size_type Levels, swizzles_type const& Swizzles) 13 | : texture(TARGET_2D, Format, texture::extent_type(Extent, 1), 1, 1, Levels, Swizzles) 14 | {} 15 | 16 | inline texture2d::texture2d(texture const& Texture) 17 | : texture(Texture, TARGET_2D, Texture.format()) 18 | {} 19 | 20 | inline texture2d::texture2d 21 | ( 22 | texture const& Texture, 23 | format_type Format, 24 | size_type BaseLayer, size_type MaxLayer, 25 | size_type BaseFace, size_type MaxFace, 26 | size_type BaseLevel, size_type MaxLevel, 27 | swizzles_type const& Swizzles 28 | ) 29 | : texture( 30 | Texture, TARGET_2D, Format, 31 | BaseLayer, MaxLayer, 32 | BaseFace, MaxFace, 33 | BaseLevel, MaxLevel, 34 | Swizzles) 35 | {} 36 | 37 | inline texture2d::texture2d 38 | ( 39 | texture2d const& Texture, 40 | size_type BaseLevel, size_type MaxLevel 41 | ) 42 | : texture( 43 | Texture, TARGET_2D, Texture.format(), 44 | Texture.base_layer(), Texture.max_layer(), 45 | Texture.base_face(), Texture.max_face(), 46 | Texture.base_level() + BaseLevel, Texture.base_level() + MaxLevel) 47 | {} 48 | 49 | inline image texture2d::operator[](size_type Level) const 50 | { 51 | GLI_ASSERT(Level < this->levels()); 52 | 53 | return image( 54 | this->Storage, 55 | this->format(), 56 | this->base_layer(), 57 | this->base_face(), 58 | this->base_level() + Level); 59 | } 60 | 61 | inline texture2d::extent_type texture2d::extent(size_type Level) const 62 | { 63 | return extent_type(this->texture::extent(Level)); 64 | } 65 | 66 | template 67 | inline gen_type texture2d::load(extent_type const& TexelCoord, size_type Level) const 68 | { 69 | return this->texture::load(texture::extent_type(TexelCoord, 0), 0, 0, Level); 70 | } 71 | 72 | template 73 | inline void texture2d::store(extent_type const& TexelCoord, size_type Level, gen_type const& Texel) 74 | { 75 | this->texture::store(texture::extent_type(TexelCoord, 0), 0, 0, Level, Texel); 76 | } 77 | }//namespace gli 78 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/core/texture2d_array.inl: -------------------------------------------------------------------------------- 1 | #include "../levels.hpp" 2 | 3 | namespace gli 4 | { 5 | inline texture2d_array::texture2d_array() 6 | {} 7 | 8 | inline texture2d_array::texture2d_array(format_type Format, extent_type const& Extent, size_type Layers, swizzles_type const& Swizzles) 9 | : texture(TARGET_2D_ARRAY, Format, texture::extent_type(Extent, 1), Layers, 1, gli::levels(Extent), Swizzles) 10 | {} 11 | 12 | inline texture2d_array::texture2d_array(format_type Format, extent_type const& Extent, size_type Layers, size_type Levels, swizzles_type const& Swizzles) 13 | : texture(TARGET_2D_ARRAY, Format, texture::extent_type(Extent, 1), Layers, 1, Levels, Swizzles) 14 | {} 15 | 16 | inline texture2d_array::texture2d_array(texture const& Texture) 17 | : texture(Texture, TARGET_2D_ARRAY, Texture.format()) 18 | {} 19 | 20 | inline texture2d_array::texture2d_array 21 | ( 22 | texture const& Texture, 23 | format_type Format, 24 | size_type BaseLayer, size_type MaxLayer, 25 | size_type BaseFace, size_type MaxFace, 26 | size_type BaseLevel, size_type MaxLevel, 27 | swizzles_type const& Swizzles 28 | ) 29 | : texture( 30 | Texture, TARGET_2D_ARRAY, 31 | Format, 32 | BaseLayer, MaxLayer, 33 | BaseFace, MaxFace, 34 | BaseLevel, MaxLevel, 35 | Swizzles) 36 | {} 37 | 38 | inline texture2d_array::texture2d_array 39 | ( 40 | texture2d_array const& Texture, 41 | size_type BaseLayer, size_type MaxLayer, 42 | size_type BaseLevel, size_type MaxLevel 43 | ) 44 | : texture( 45 | Texture, TARGET_2D_ARRAY, 46 | Texture.format(), 47 | Texture.base_layer() + BaseLayer, Texture.base_layer() + MaxLayer, 48 | Texture.base_face(), Texture.max_face(), 49 | Texture.base_level() + BaseLevel, Texture.base_level() + MaxLevel) 50 | {} 51 | 52 | inline texture2d texture2d_array::operator[](size_type Layer) const 53 | { 54 | GLI_ASSERT(Layer < this->layers()); 55 | 56 | return texture2d( 57 | *this, this->format(), 58 | this->base_layer() + Layer, this->base_layer() + Layer, 59 | this->base_face(), this->max_face(), 60 | this->base_level(), this->max_level()); 61 | } 62 | 63 | inline texture2d_array::extent_type texture2d_array::extent(size_type Level) const 64 | { 65 | return extent_type(this->texture::extent(Level)); 66 | } 67 | 68 | template 69 | inline gen_type texture2d_array::load(extent_type const& TexelCoord, size_type Layer, size_type Level) const 70 | { 71 | return this->texture::load(texture::extent_type(TexelCoord, 0), Layer, 0, Level); 72 | } 73 | 74 | template 75 | inline void texture2d_array::store(extent_type const& TexelCoord, size_type Layer, size_type Level, gen_type const& Texel) 76 | { 77 | this->texture::store(texture::extent_type(TexelCoord, 0), Layer, 0, Level, Texel); 78 | } 79 | }//namespace gli 80 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/core/texture3d.inl: -------------------------------------------------------------------------------- 1 | #include "../levels.hpp" 2 | 3 | namespace gli 4 | { 5 | inline texture3d::texture3d() 6 | {} 7 | 8 | inline texture3d::texture3d(format_type Format, extent_type const& Extent, swizzles_type const& Swizzles) 9 | : texture(TARGET_3D, Format, Extent, 1, 1, gli::levels(Extent), Swizzles) 10 | {} 11 | 12 | inline texture3d::texture3d(format_type Format, extent_type const& Extent, size_type Levels, swizzles_type const& Swizzles) 13 | : texture(TARGET_3D, Format, Extent, 1, 1, Levels, Swizzles) 14 | {} 15 | 16 | inline texture3d::texture3d(texture const& Texture) 17 | : texture(Texture, TARGET_3D, Texture.format()) 18 | {} 19 | 20 | inline texture3d::texture3d 21 | ( 22 | texture const& Texture, 23 | format_type Format, 24 | size_type BaseLayer, size_type MaxLayer, 25 | size_type BaseFace, size_type MaxFace, 26 | size_type BaseLevel, size_type MaxLevel, 27 | swizzles_type const& Swizzles 28 | ) 29 | : texture( 30 | Texture, TARGET_3D, Format, 31 | BaseLayer, MaxLayer, 32 | BaseFace, MaxFace, 33 | BaseLevel, MaxLevel, 34 | Swizzles) 35 | {} 36 | 37 | inline texture3d::texture3d 38 | ( 39 | texture3d const& Texture, 40 | size_type BaseLevel, size_type MaxLevel 41 | ) 42 | : texture( 43 | Texture, TARGET_3D, Texture.format(), 44 | Texture.base_layer(), Texture.max_layer(), 45 | Texture.base_face(), Texture.max_face(), 46 | Texture.base_level() + BaseLevel, Texture.base_level() + MaxLevel) 47 | {} 48 | 49 | inline image texture3d::operator[](size_type Level) const 50 | { 51 | GLI_ASSERT(Level < this->levels()); 52 | 53 | return image( 54 | this->Storage, 55 | this->format(), 56 | this->base_layer(), 57 | this->base_face(), 58 | this->base_level() + Level); 59 | } 60 | 61 | inline texture3d::extent_type texture3d::extent(size_type Level) const 62 | { 63 | return extent_type(this->texture::extent(Level)); 64 | } 65 | 66 | template 67 | inline gen_type texture3d::load(extent_type const& TexelCoord, size_type Level) const 68 | { 69 | return this->texture::load(texture::extent_type(TexelCoord), 0, 0, Level); 70 | } 71 | 72 | template 73 | inline void texture3d::store(extent_type const& TexelCoord, size_type Level, gen_type const& Texel) 74 | { 75 | this->texture::store(texture::extent_type(TexelCoord), 0, 0, Level, Texel); 76 | } 77 | }//namespace gli 78 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/core/texture_cube.inl: -------------------------------------------------------------------------------- 1 | namespace gli 2 | { 3 | inline texture_cube::texture_cube() 4 | {} 5 | 6 | inline texture_cube::texture_cube(format_type Format, extent_type const& Extent, swizzles_type const& Swizzles) 7 | : texture(TARGET_CUBE, Format, texture::extent_type(Extent, 1), 1, 6, gli::levels(Extent), Swizzles) 8 | {} 9 | 10 | inline texture_cube::texture_cube(format_type Format, extent_type const& Extent, size_type Levels, swizzles_type const& Swizzles) 11 | : texture(TARGET_CUBE, Format, texture::extent_type(Extent, 1), 1, 6, Levels, Swizzles) 12 | {} 13 | 14 | inline texture_cube::texture_cube(texture const& Texture) 15 | : texture(Texture, TARGET_CUBE, Texture.format()) 16 | {} 17 | 18 | inline texture_cube::texture_cube 19 | ( 20 | texture const& Texture, 21 | format_type Format, 22 | size_type BaseLayer, size_type MaxLayer, 23 | size_type BaseFace, size_type MaxFace, 24 | size_type BaseLevel, size_type MaxLevel, 25 | swizzles_type const& Swizzles 26 | ) 27 | : texture( 28 | Texture, TARGET_CUBE, Format, 29 | BaseLayer, MaxLayer, 30 | BaseFace, MaxFace, 31 | BaseLevel, MaxLevel, 32 | Swizzles) 33 | {} 34 | 35 | inline texture_cube::texture_cube 36 | ( 37 | texture_cube const& Texture, 38 | size_type BaseFace, size_type MaxFace, 39 | size_type BaseLevel, size_type MaxLevel 40 | ) 41 | : texture( 42 | Texture, TARGET_CUBE, Texture.format(), 43 | Texture.base_layer(), Texture.max_layer(), 44 | Texture.base_face() + BaseFace, Texture.base_face() + MaxFace, 45 | Texture.base_level() + BaseLevel, Texture.base_level() + MaxLevel) 46 | {} 47 | 48 | inline texture2d texture_cube::operator[](size_type Face) const 49 | { 50 | GLI_ASSERT(Face < this->faces()); 51 | 52 | return texture2d( 53 | *this, this->format(), 54 | this->base_layer(), this->max_layer(), 55 | this->base_face() + Face, this->base_face() + Face, 56 | this->base_level(), this->max_level()); 57 | } 58 | 59 | inline texture_cube::extent_type texture_cube::extent(size_type Level) const 60 | { 61 | return extent_type(this->texture::extent(Level)); 62 | } 63 | 64 | template 65 | inline gen_type texture_cube::load(extent_type const& TexelCoord, size_type Face, size_type Level) const 66 | { 67 | return this->texture::load(texture::extent_type(TexelCoord, 0), 0, Face, Level); 68 | } 69 | 70 | template 71 | inline void texture_cube::store(extent_type const& TexelCoord, size_type Face, size_type Level, gen_type const& Texel) 72 | { 73 | this->texture::store(texture::extent_type(TexelCoord, 0), 0, Face, Level, Texel); 74 | } 75 | }//namespace gli 76 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/levels.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Include to compute the number of mipmaps levels necessary to create a mipmap complete texture. 2 | /// @file gli/levels.hpp 3 | 4 | #pragma once 5 | 6 | #include "type.hpp" 7 | 8 | namespace gli 9 | { 10 | /// Compute the number of mipmaps levels necessary to create a mipmap complete texture 11 | /// 12 | /// @param Extent Extent of the texture base level mipmap 13 | /// @tparam vecType Vector type used to express the dimensions of a texture of any kind. 14 | /// @code 15 | /// #include 16 | /// #include 17 | /// ... 18 | /// gli::texture2d::extent_type Extent(32, 10); 19 | /// gli::texture2d Texture(gli::levels(Extent)); 20 | /// @endcode 21 | template 22 | T levels(vec const& Extent); 23 | /* 24 | /// Compute the number of mipmaps levels necessary to create a mipmap complete texture 25 | /// 26 | /// @param Extent Extent of the texture base level mipmap 27 | /// @code 28 | /// #include 29 | /// #include 30 | /// ... 31 | /// gli::texture2d Texture(32); 32 | /// @endcode 33 | size_t levels(size_t Extent); 34 | 35 | /// Compute the number of mipmaps levels necessary to create a mipmap complete texture 36 | /// 37 | /// @param Extent Extent of the texture base level mipmap 38 | /// @code 39 | /// #include 40 | /// #include 41 | /// ... 42 | /// gli::texture2d Texture(32); 43 | /// @endcode 44 | int levels(int Extent); 45 | */ 46 | }//namespace gli 47 | 48 | #include "./core/levels.inl" 49 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/load.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Include to load DDS, KTX or KMG textures from files or memory. 2 | /// @file gli/load.hpp 3 | 4 | #pragma once 5 | 6 | #include "texture.hpp" 7 | 8 | namespace gli 9 | { 10 | /// Loads a texture storage_linear from file. Returns an empty storage_linear in case of failure. 11 | /// 12 | /// @param Path Path of the file to open including filaname and filename extension 13 | texture load(char const* Path); 14 | 15 | /// Loads a texture storage_linear from file. Returns an empty storage_linear in case of failure. 16 | /// 17 | /// @param Path Path of the file to open including filaname and filename extension 18 | texture load(std::string const& Path); 19 | 20 | /// Loads a texture storage_linear from memory. Returns an empty storage_linear in case of failure. 21 | /// 22 | /// @param Data Data of a texture 23 | /// @param Size Size of the data 24 | texture load(char const* Data, std::size_t Size); 25 | }//namespace gli 26 | 27 | #include "./core/load.inl" 28 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/load_dds.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Include to load DDS textures from files or memory. 2 | /// @file gli/load_dds.hpp 3 | 4 | #pragma once 5 | 6 | #include "texture.hpp" 7 | 8 | namespace gli 9 | { 10 | /// Loads a texture storage_linear from DDS file. Returns an empty storage_linear in case of failure. 11 | /// 12 | /// @param Path Path of the file to open including filaname and filename extension 13 | texture load_dds(char const* Path); 14 | 15 | /// Loads a texture storage_linear from DDS file. Returns an empty storage_linear in case of failure. 16 | /// 17 | /// @param Path Path of the file to open including filaname and filename extension 18 | texture load_dds(std::string const& Path); 19 | 20 | /// Loads a texture storage_linear from DDS memory. Returns an empty storage_linear in case of failure. 21 | /// 22 | /// @param Data Pointer to the beginning of the texture container data to read 23 | /// @param Size Size of texture container Data to read 24 | texture load_dds(char const* Data, std::size_t Size); 25 | }//namespace gli 26 | 27 | #include "./core/load_dds.inl" 28 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/load_kmg.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Include to load KMG textures from files or memory. 2 | /// @file gli/load_kmg.hpp 3 | 4 | #pragma once 5 | 6 | #include "texture.hpp" 7 | 8 | namespace gli 9 | { 10 | /// Loads a texture storage_linear from KMG (Khronos Image) file. Returns an empty storage_linear in case of failure. 11 | /// 12 | /// @param Path Path of the file to open including filaname and filename extension 13 | texture load_kmg(char const* Path); 14 | 15 | /// Loads a texture storage_linear from KMG (Khronos Image) file. Returns an empty storage_linear in case of failure. 16 | /// 17 | /// @param Path Path of the file to open including filaname and filename extension 18 | texture load_kmg(std::string const& Path); 19 | 20 | /// Loads a texture storage_linear from KMG (Khronos Image) memory. Returns an empty storage_linear in case of failure. 21 | /// 22 | /// @param Data Pointer to the beginning of the texture container data to read 23 | /// @param Size Size of texture container Data to read 24 | texture load_kmg(char const* Data, std::size_t Size); 25 | }//namespace gli 26 | 27 | #include "./core/load_kmg.inl" 28 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/load_ktx.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Include to load KTX textures from files or memory. 2 | /// @file gli/load_ktx.hpp 3 | 4 | #pragma once 5 | 6 | #include "texture.hpp" 7 | 8 | namespace gli 9 | { 10 | /// Loads a texture storage_linear from KTX file. Returns an empty storage_linear in case of failure. 11 | /// 12 | /// @param Path Path of the file to open including filaname and filename extension 13 | texture load_ktx(char const* Path); 14 | 15 | /// Loads a texture storage_linear from KTX file. Returns an empty storage_linear in case of failure. 16 | /// 17 | /// @param Path Path of the file to open including filaname and filename extension 18 | texture load_ktx(std::string const& Path); 19 | 20 | /// Loads a texture storage_linear from KTX memory. Returns an empty storage_linear in case of failure. 21 | /// 22 | /// @param Data Pointer to the beginning of the texture container data to read 23 | /// @param Size Size of texture container Data to read 24 | texture load_ktx(char const* Data, std::size_t Size); 25 | }//namespace gli 26 | 27 | #include "./core/load_ktx.inl" 28 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/make_texture.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Helper functions to create generic texture 2 | /// @file gli/make_texture.hpp 3 | 4 | #pragma once 5 | 6 | namespace gli 7 | { 8 | // Helper function to create a 1d texture with a specific number of levels 9 | gli::texture make_texture1d(format Format, extent1d const& Extent, size_t Levels); 10 | 11 | // Helper function to create a 1d texture with a complete mipmap chain 12 | gli::texture make_texture1d(format Format, extent1d const& Extent); 13 | 14 | // Helper function to create a 1d array texture with a specific number of levels 15 | gli::texture make_texture1d_array(format Format, extent1d const& Extent, size_t Layers, size_t Levels); 16 | 17 | // Helper function to create a 1d array texture with a complete mipmap chain 18 | gli::texture make_texture1d_array(format Format, extent1d const& Extent, size_t Layers); 19 | 20 | // Helper function to create a 2d texture with a specific number of levels 21 | gli::texture make_texture2d(format Format, extent2d const& Extent, size_t Levels); 22 | 23 | // Helper function to create a 2d texture with a complete mipmap chain 24 | gli::texture make_texture2d(format Format, extent2d const& Extent); 25 | 26 | // Helper function to create a 2d array texture with a specific number of levels 27 | gli::texture make_texture2d_array(format Format, extent2d const& Extent, size_t Layer, size_t Levels); 28 | 29 | // Helper function to create a 2d array texture with a complete mipmap chain 30 | gli::texture make_texture2d_array(format Format, extent2d const& Extent, size_t Layer); 31 | 32 | // Helper function to create a 3d texture with a specific number of levels 33 | gli::texture make_texture3d(format Format, extent3d const& Extent, size_t Levels); 34 | 35 | // Helper function to create a 3d texture with a complete mipmap chain 36 | gli::texture make_texture3d(format Format, extent3d const& Extent); 37 | 38 | // Helper function to create a cube texture with a specific number of levels 39 | gli::texture make_texture_cube(format Format, extent2d const& Extent, size_t Levels); 40 | 41 | // Helper function to create a cube texture with a complete mipmap chain 42 | gli::texture make_texture_cube(format Format, extent2d const& Extent); 43 | 44 | // Helper function to create a cube array texture with a specific number of levels 45 | gli::texture make_texture_cube_array(format Format, extent2d const& Extent, size_t Layer, size_t Levels); 46 | 47 | // Helper function to create a cube array texture with a complete mipmap chain 48 | gli::texture make_texture_cube_array(format Format, extent2d const& Extent, size_t Layer); 49 | }//namespace gli 50 | 51 | #include "./core/make_texture.inl" 52 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/sampler.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Include to use wrap modes and the sampler base class. 2 | /// @file gli/sampler.hpp 3 | 4 | #pragma once 5 | 6 | #include "core/filter.hpp" 7 | 8 | namespace gli 9 | { 10 | /// Texture coordinate wrapping mode 11 | enum wrap 12 | { 13 | WRAP_CLAMP_TO_EDGE, WRAP_FIRST = WRAP_CLAMP_TO_EDGE, 14 | WRAP_CLAMP_TO_BORDER, 15 | WRAP_REPEAT, 16 | WRAP_MIRROR_REPEAT, 17 | WRAP_MIRROR_CLAMP_TO_EDGE, 18 | WRAP_MIRROR_CLAMP_TO_BORDER, WRAP_LAST = WRAP_MIRROR_CLAMP_TO_BORDER 19 | }; 20 | 21 | enum 22 | { 23 | WRAP_COUNT = WRAP_LAST - WRAP_FIRST + 1 24 | }; 25 | 26 | /// Evaluate whether the texture coordinate wrapping mode relies on border color 27 | inline bool is_border(wrap Wrap) 28 | { 29 | return Wrap == WRAP_CLAMP_TO_BORDER || Wrap == WRAP_MIRROR_CLAMP_TO_BORDER; 30 | } 31 | 32 | /// Genetic sampler class. 33 | class sampler 34 | { 35 | public: 36 | sampler(wrap Wrap, filter Mip, filter Min); 37 | virtual ~sampler() = default; 38 | 39 | protected: 40 | typedef float(*wrap_type)(float const & SamplerCoord); 41 | 42 | wrap_type get_func(wrap WrapMode) const; 43 | 44 | wrap_type Wrap; 45 | filter Mip; 46 | filter Min; 47 | }; 48 | }//namespace gli 49 | 50 | #include "./core/sampler.inl" 51 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/save.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Include to save DDS, KTX or KMG textures to files or memory. 2 | /// @file gli/save.hpp 3 | 4 | #pragma once 5 | 6 | #include "save_dds.hpp" 7 | #include "save_ktx.hpp" 8 | 9 | namespace gli 10 | { 11 | /// Save a texture storage_linear to file. 12 | /// 13 | /// @param Texture Source texture to save 14 | /// @param Path Path for where to save the file. It must include the filaname and filename extension. 15 | /// The function use the filename extension included in the path to figure out the file container to use. 16 | /// @return Returns false if the function fails to save the file. 17 | bool save(texture const & Texture, char const * Path); 18 | 19 | /// Save a texture storage_linear to file. 20 | /// 21 | /// @param Texture Source texture to save 22 | /// @param Path Path for where to save the file. It must include the filaname and filename extension. 23 | /// The function use the filename extension included in the path to figure out the file container to use. 24 | /// @return Returns false if the function fails to save the file. 25 | bool save(texture const & Texture, std::string const & Path); 26 | }//namespace gli 27 | 28 | #include "./core/save.inl" 29 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/save_dds.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Include to save DDS textures to files or memory. 2 | /// @file gli/save_dds.hpp 3 | 4 | #pragma once 5 | 6 | #include "texture.hpp" 7 | 8 | namespace gli 9 | { 10 | /// Save a texture storage_linear to a DDS file. 11 | /// 12 | /// @param Texture Source texture to save 13 | /// @param Path Path for where to save the file. It must include the filaname and filename extension. 14 | /// This function ignores the filename extension in the path and save to DDS anyway but keep the requested filename extension. 15 | /// @return Returns false if the function fails to save the file. 16 | bool save_dds(texture const & Texture, char const* Path); 17 | 18 | /// Save a texture storage_linear to a DDS file. 19 | /// 20 | /// @param Texture Source texture to save 21 | /// @param Path Path for where to save the file. It must include the filaname and filename extension. 22 | /// This function ignores the filename extension in the path and save to DDS anyway but keep the requested filename extension. 23 | /// @return Returns false if the function fails to save the file. 24 | bool save_dds(texture const & Texture, std::string const & Path); 25 | 26 | /// Save a texture storage_linear to a DDS file. 27 | /// 28 | /// @param Texture Source texture to save 29 | /// @param Memory Storage for the DDS container. The function resizes the containers to fit the necessary storage_linear. 30 | /// @return Returns false if the function fails to save the file. 31 | bool save_dds(texture const & Texture, std::vector & Memory); 32 | }//namespace gli 33 | 34 | #include "./core/save_dds.inl" 35 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/save_kmg.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Include to save KMG textures to files or memory. 2 | /// @file gli/save_kmg.hpp 3 | 4 | #pragma once 5 | 6 | #include "texture.hpp" 7 | 8 | namespace gli 9 | { 10 | /// Save a texture storage_linear to a KMG (Khronos Image) file. 11 | /// 12 | /// @param Texture Source texture to save 13 | /// @param Path Path for where to save the file. It must include the filaname and filename extension. 14 | /// This function ignores the filename extension in the path and save to KMG anyway but keep the requested filename extension. 15 | /// @return Returns false if the function fails to save the file. 16 | bool save_kmg(texture const & Texture, char const * Path); 17 | 18 | /// Save a texture storage_linear to a KMG (Khronos Image) file. 19 | /// 20 | /// @param Texture Source texture to save 21 | /// @param Path Path for where to save the file. It must include the filaname and filename extension. 22 | /// This function ignores the filename extension in the path and save to KMG anyway but keep the requested filename extension. 23 | /// @return Returns false if the function fails to save the file. 24 | bool save_kmg(texture const & Texture, std::string const & Path); 25 | 26 | /// Save a texture storage_linear to a KMG (Khronos Image) file. 27 | /// 28 | /// @param Texture Source texture to save 29 | /// @param Memory Storage for the KMG container. The function resizes the containers to fit the necessary storage_linear. 30 | /// @return Returns false if the function fails to save the file. 31 | bool save_kmg(texture const & Texture, std::vector & Memory); 32 | }//namespace gli 33 | 34 | #include "./core/save_kmg.inl" 35 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/save_ktx.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Include to save KTX textures to files or memory. 2 | /// @file gli/save_ktx.hpp 3 | 4 | #pragma once 5 | 6 | #include "texture.hpp" 7 | 8 | namespace gli 9 | { 10 | /// Save a texture storage_linear to a KTX file. 11 | /// 12 | /// @param Texture Source texture to save 13 | /// @param Path Path for where to save the file. It must include the filaname and filename extension. 14 | /// This function ignores the filename extension in the path and save to KTX anyway but keep the requested filename extension. 15 | /// @return Returns false if the function fails to save the file. 16 | bool save_ktx(texture const & Texture, char const * Path); 17 | 18 | /// Save a texture storage_linear to a KTX file. 19 | /// 20 | /// @param Texture Source texture to save 21 | /// @param Path Path for where to save the file. It must include the filaname and filename extension. 22 | /// This function ignores the filename extension in the path and save to KTX anyway but keep the requested filename extension. 23 | /// @return Returns false if the function fails to save the file. 24 | bool save_ktx(texture const & Texture, std::string const & Path); 25 | 26 | /// Save a texture storage_linear to a KTX file. 27 | /// 28 | /// @param Texture Source texture to save 29 | /// @param Memory Storage for the KTX container. The function resizes the containers to fit the necessary storage_linear. 30 | /// @return Returns false if the function fails to save the file. 31 | bool save_ktx(texture const & Texture, std::vector & Memory); 32 | }//namespace gli 33 | 34 | #include "./core/save_ktx.inl" 35 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/target.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Include to use the target enum and query properties of targets. 2 | /// @file gli/target.hpp 3 | 4 | #pragma once 5 | 6 | namespace gli 7 | { 8 | /// Texture target: type/shape of the texture storage_linear 9 | enum target 10 | { 11 | TARGET_1D = 0, TARGET_FIRST = TARGET_1D, 12 | TARGET_1D_ARRAY, 13 | TARGET_2D, 14 | TARGET_2D_ARRAY, 15 | TARGET_3D, 16 | TARGET_RECT, 17 | TARGET_RECT_ARRAY, 18 | TARGET_CUBE, 19 | TARGET_CUBE_ARRAY, TARGET_LAST = TARGET_CUBE_ARRAY 20 | }; 21 | 22 | enum 23 | { 24 | TARGET_COUNT = TARGET_LAST - TARGET_FIRST + 1, 25 | TARGET_INVALID = -1 26 | }; 27 | 28 | /// Check whether a target is a 1D target 29 | inline bool is_target_1d(target Target) 30 | { 31 | return Target == TARGET_1D || Target == TARGET_1D_ARRAY; 32 | } 33 | 34 | /// Check whether a target is an array target 35 | inline bool is_target_array(target Target) 36 | { 37 | return Target == TARGET_1D_ARRAY || Target == TARGET_2D_ARRAY || Target == TARGET_CUBE_ARRAY; 38 | } 39 | 40 | /// Check whether a target is a cube map target 41 | inline bool is_target_cube(target Target) 42 | { 43 | return Target == TARGET_CUBE || Target == TARGET_CUBE_ARRAY; 44 | } 45 | 46 | /// Check whether a target is a rectangle target 47 | inline bool is_target_rect(target Target) 48 | { 49 | return Target == TARGET_RECT || Target == TARGET_RECT_ARRAY; 50 | } 51 | }//namespace gli 52 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/texture1d.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Include to use 1d textures. 2 | /// @file gli/texture1d.hpp 3 | 4 | #pragma once 5 | 6 | #include "texture.hpp" 7 | #include "image.hpp" 8 | 9 | namespace gli 10 | { 11 | /// 1d texture 12 | class texture1d : public texture 13 | { 14 | public: 15 | typedef extent1d extent_type; 16 | 17 | /// Create an empty texture 1D 18 | texture1d(); 19 | 20 | /// Create a texture1d and allocate a new storage_linear 21 | texture1d( 22 | format_type Format, 23 | extent_type const& Extent, 24 | size_type Levels, 25 | swizzles_type const& Swizzles = swizzles_type(SWIZZLE_RED, SWIZZLE_GREEN, SWIZZLE_BLUE, SWIZZLE_ALPHA)); 26 | 27 | /// Create a texture1d and allocate a new storage_linear with a complete mipmap chain 28 | texture1d( 29 | format_type Format, 30 | extent_type const& Extent, 31 | swizzles_type const& Swizzles = swizzles_type(SWIZZLE_RED, SWIZZLE_GREEN, SWIZZLE_BLUE, SWIZZLE_ALPHA)); 32 | 33 | /// Create a texture1d view with an existing storage_linear 34 | explicit texture1d( 35 | texture const& Texture); 36 | 37 | /// Create a texture1d view with an existing storage_linear 38 | texture1d( 39 | texture const& Texture, 40 | format_type Format, 41 | size_type BaseLayer, size_type MaxLayer, 42 | size_type BaseFace, size_type MaxFace, 43 | size_type BaseLevel, size_type MaxLevel, 44 | swizzles_type const& Swizzles = swizzles_type(SWIZZLE_RED, SWIZZLE_GREEN, SWIZZLE_BLUE, SWIZZLE_ALPHA)); 45 | 46 | /// Create a texture1d view, reference a subset of an existing texture1d instance 47 | texture1d( 48 | texture1d const& Texture, 49 | size_type BaseLevel, size_type MaxLevel); 50 | 51 | /// Create a view of the image identified by Level in the mipmap chain of the texture 52 | image operator[](size_type Level) const; 53 | 54 | /// Return the width of a texture instance 55 | extent_type extent(size_type Level = 0) const; 56 | 57 | /// Fetch a texel from a texture. The texture format must be uncompressed. 58 | template 59 | gen_type load(extent_type const& TexelCoord, size_type Level) const; 60 | 61 | /// Write a texel to a texture. The texture format must be uncompressed. 62 | template 63 | void store(extent_type const& TexelCoord, size_type Level, gen_type const& Texel); 64 | }; 65 | }//namespace gli 66 | 67 | #include "./core/texture1d.inl" 68 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/texture1d_array.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Include to use 1d array textures. 2 | /// @file gli/texture1d_array.hpp 3 | 4 | #pragma once 5 | 6 | #include "texture1d.hpp" 7 | 8 | namespace gli 9 | { 10 | /// 1d array texture 11 | class texture1d_array : public texture 12 | { 13 | public: 14 | typedef extent1d extent_type; 15 | 16 | public: 17 | /// Create an empty texture 1D array 18 | texture1d_array(); 19 | 20 | /// Create a texture1d_array and allocate a new storage_linear 21 | texture1d_array( 22 | format_type Format, 23 | extent_type const& Extent, 24 | size_type Layers, 25 | size_type Levels, 26 | swizzles_type const& Swizzles = swizzles_type(SWIZZLE_RED, SWIZZLE_GREEN, SWIZZLE_BLUE, SWIZZLE_ALPHA)); 27 | 28 | /// Create a texture1d_array and allocate a new storage_linear with a complete mipmap chain 29 | texture1d_array( 30 | format_type Format, 31 | extent_type const& Extent, 32 | size_type Layers, 33 | swizzles_type const& Swizzles = swizzles_type(SWIZZLE_RED, SWIZZLE_GREEN, SWIZZLE_BLUE, SWIZZLE_ALPHA)); 34 | 35 | /// Create a texture1d_array view with an existing storage_linear 36 | explicit texture1d_array( 37 | texture const& Texture); 38 | 39 | /// Create a texture1d_array view with an existing storage_linear 40 | texture1d_array( 41 | texture const& Texture, 42 | format_type Format, 43 | size_type BaseLayer, size_type MaxLayer, 44 | size_type BaseFace, size_type MaxFace, 45 | size_type BaseLevel, size_type MaxLevel, 46 | swizzles_type const& Swizzles = swizzles_type(SWIZZLE_RED, SWIZZLE_GREEN, SWIZZLE_BLUE, SWIZZLE_ALPHA)); 47 | 48 | /// Create a texture view, reference a subset of an exiting storage_linear 49 | texture1d_array( 50 | texture1d_array const& Texture, 51 | size_type BaseLayer, size_type MaxLayer, 52 | size_type BaseLevel, size_type MaxLevel); 53 | 54 | /// Create a view of the texture identified by Layer in the texture array 55 | texture1d operator[](size_type Layer) const; 56 | 57 | /// Return the width of a texture instance 58 | extent_type extent(size_type Level = 0) const; 59 | 60 | /// Fetch a texel from a texture. The texture format must be uncompressed. 61 | template 62 | gen_type load(extent_type const& TexelCoord, size_type Layer, size_type Level) const; 63 | 64 | /// Write a texel to a texture. The texture format must be uncompressed. 65 | template 66 | void store(extent_type const& TexelCoord, size_type Layer, size_type Level, gen_type const& Texel); 67 | }; 68 | }//namespace gli 69 | 70 | #include "./core/texture1d_array.inl" 71 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/texture2d.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Include to use 2d textures. 2 | /// @file gli/texture2d.hpp 3 | 4 | #pragma once 5 | 6 | #include "texture.hpp" 7 | #include "image.hpp" 8 | 9 | namespace gli 10 | { 11 | /// 2d texture 12 | class texture2d : public texture 13 | { 14 | public: 15 | typedef extent2d extent_type; 16 | 17 | /// Create an empty texture 2D. 18 | texture2d(); 19 | 20 | /// Create a texture2d and allocate a new storage_linear. 21 | texture2d( 22 | format_type Format, 23 | extent_type const& Extent, 24 | size_type Levels, 25 | swizzles_type const& Swizzles = swizzles_type(SWIZZLE_RED, SWIZZLE_GREEN, SWIZZLE_BLUE, SWIZZLE_ALPHA)); 26 | 27 | /// Create a texture2d and allocate a new storage_linear with a complete mipmap chain. 28 | texture2d( 29 | format_type Format, 30 | extent_type const& Extent, 31 | swizzles_type const& Swizzles = swizzles_type(SWIZZLE_RED, SWIZZLE_GREEN, SWIZZLE_BLUE, SWIZZLE_ALPHA)); 32 | 33 | /// Create a texture2d view with an existing storage_linear. 34 | explicit texture2d( 35 | texture const& Texture); 36 | 37 | /// Create a texture2d view with an existing storage_linear. 38 | texture2d( 39 | texture const& Texture, 40 | format_type Format, 41 | size_type BaseLayer, size_type MaxLayer, 42 | size_type BaseFace, size_type MaxFace, 43 | size_type BaseLevel, size_type MaxLevel, 44 | swizzles_type const& Swizzles = swizzles_type(SWIZZLE_RED, SWIZZLE_GREEN, SWIZZLE_BLUE, SWIZZLE_ALPHA)); 45 | 46 | /// Create a texture2d view, reference a subset of an existing texture2d instance. 47 | texture2d( 48 | texture2d const& Texture, 49 | size_type BaseLevel, size_type MaxLevel); 50 | 51 | /// Create a view of the image identified by Level in the mipmap chain of the texture. 52 | image operator[](size_type Level) const; 53 | 54 | /// Return the dimensions of a texture instance: width and height. 55 | extent_type extent(size_type Level = 0) const; 56 | 57 | /// Fetch a texel from a texture. The texture format must be uncompressed. 58 | template 59 | gen_type load(extent_type const& TexelCoord, size_type Level) const; 60 | 61 | /// Write a texel to a texture. The texture format must be uncompressed. 62 | template 63 | void store(extent_type const& TexelCoord, size_type Level, gen_type const& Texel); 64 | }; 65 | }//namespace gli 66 | 67 | #include "./core/texture2d.inl" 68 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/texture2d_array.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Include to use 2d array textures. 2 | /// @file gli/texture2d_array.hpp 3 | 4 | #pragma once 5 | 6 | #include "texture2d.hpp" 7 | 8 | namespace gli 9 | { 10 | /// 2d array texture 11 | class texture2d_array : public texture 12 | { 13 | public: 14 | typedef extent2d extent_type; 15 | 16 | public: 17 | /// Create an empty texture 2D array 18 | texture2d_array(); 19 | 20 | /// Create a texture2d_array and allocate a new storage_linear 21 | texture2d_array( 22 | format_type Format, 23 | extent_type const& Extent, 24 | size_type Layers, 25 | size_type Levels, 26 | swizzles_type const& Swizzles = swizzles_type(SWIZZLE_RED, SWIZZLE_GREEN, SWIZZLE_BLUE, SWIZZLE_ALPHA)); 27 | 28 | /// Create a texture2d_array and allocate a new storage_linear with a complete mipmap chain 29 | texture2d_array( 30 | format_type Format, 31 | extent_type const& Extent, 32 | size_type Layers, 33 | swizzles_type const& Swizzles = swizzles_type(SWIZZLE_RED, SWIZZLE_GREEN, SWIZZLE_BLUE, SWIZZLE_ALPHA)); 34 | 35 | /// Create a texture2d_array view with an existing storage_linear 36 | explicit texture2d_array( 37 | texture const& Texture); 38 | 39 | /// Create a texture2d_array view with an existing storage_linear 40 | texture2d_array( 41 | texture const& Texture, 42 | format_type Format, 43 | size_type BaseLayer, size_type MaxLayer, 44 | size_type BaseFace, size_type MaxFace, 45 | size_type BaseLevel, size_type MaxLevel, 46 | swizzles_type const& Swizzles = swizzles_type(SWIZZLE_RED, SWIZZLE_GREEN, SWIZZLE_BLUE, SWIZZLE_ALPHA)); 47 | 48 | /// Create a texture view, reference a subset of an exiting texture2d_array instance 49 | texture2d_array( 50 | texture2d_array const& Texture, 51 | size_type BaseLayer, size_type MaxLayer, 52 | size_type BaseLevel, size_type MaxLevel); 53 | 54 | /// Create a view of the texture identified by Layer in the texture array 55 | texture2d operator[](size_type Layer) const; 56 | 57 | /// Return the dimensions of a texture instance: width and height 58 | extent_type extent(size_type Level = 0) const; 59 | 60 | /// Fetch a texel from a texture. The texture format must be uncompressed. 61 | template 62 | gen_type load(extent_type const& TexelCoord, size_type Layer, size_type Level) const; 63 | 64 | /// Write a texel to a texture. The texture format must be uncompressed. 65 | template 66 | void store(extent_type const& TexelCoord, size_type Layer, size_type Level, gen_type const& Texel); 67 | }; 68 | }//namespace gli 69 | 70 | #include "./core/texture2d_array.inl" 71 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/texture3d.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Include to use 3d textures. 2 | /// @file gli/texture3d.hpp 3 | 4 | #pragma once 5 | 6 | #include "texture.hpp" 7 | #include "image.hpp" 8 | 9 | namespace gli 10 | { 11 | /// 3d texture 12 | class texture3d : public texture 13 | { 14 | public: 15 | typedef extent3d extent_type; 16 | 17 | public: 18 | /// Create an empty texture 3D 19 | texture3d(); 20 | 21 | /// Create a texture3d and allocate a new storage_linear 22 | texture3d( 23 | format_type Format, 24 | extent_type const& Extent, 25 | size_type Levels, 26 | swizzles_type const& Swizzles = swizzles_type(SWIZZLE_RED, SWIZZLE_GREEN, SWIZZLE_BLUE, SWIZZLE_ALPHA)); 27 | 28 | /// Create a texture3d and allocate a new storage_linear with a complete mipmap chain 29 | texture3d( 30 | format_type Format, 31 | extent_type const& Extent, 32 | swizzles_type const& Swizzles = swizzles_type(SWIZZLE_RED, SWIZZLE_GREEN, SWIZZLE_BLUE, SWIZZLE_ALPHA)); 33 | 34 | /// Create a texture3d view with an existing storage_linear 35 | explicit texture3d( 36 | texture const & Texture); 37 | 38 | /// Create a texture3d view with an existing storage_linear 39 | texture3d( 40 | texture const& Texture, 41 | format_type Format, 42 | size_type BaseLayer, size_type MaxLayer, 43 | size_type BaseFace, size_type MaxFace, 44 | size_type BaseLevel, size_type MaxLevel, 45 | swizzles_type const& Swizzles = swizzles_type(SWIZZLE_RED, SWIZZLE_GREEN, SWIZZLE_BLUE, SWIZZLE_ALPHA)); 46 | 47 | /// Create a texture3d view, reference a subset of an existing texture3d instance 48 | texture3d( 49 | texture3d const & Texture, 50 | size_type BaseLevel, size_type MaxLevel); 51 | 52 | /// Create a view of the image identified by Level in the mipmap chain of the texture 53 | image operator[](size_type Level) const; 54 | 55 | /// Return the dimensions of a texture instance: width, height and depth 56 | extent_type extent(size_type Level = 0) const; 57 | 58 | /// Fetch a texel from a texture. The texture format must be uncompressed. 59 | template 60 | gen_type load(extent_type const& TexelCoord, size_type Level) const; 61 | 62 | /// Write a texel to a texture. The texture format must be uncompressed. 63 | template 64 | void store(extent_type const& TexelCoord, size_type Level, gen_type const& Texel); 65 | }; 66 | }//namespace gli 67 | 68 | #include "./core/texture3d.inl" 69 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/texture_cube.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Include to use cube map textures. 2 | /// @file gli/texture_cube.hpp 3 | 4 | #pragma once 5 | 6 | #include "texture2d.hpp" 7 | 8 | namespace gli 9 | { 10 | /// Cube map texture 11 | class texture_cube : public texture 12 | { 13 | public: 14 | typedef extent2d extent_type; 15 | 16 | public: 17 | /// Create an empty texture cube 18 | texture_cube(); 19 | 20 | /// Create a texture_cube and allocate a new storage_linear 21 | texture_cube( 22 | format_type Format, 23 | extent_type const & Extent, 24 | size_type Levels, 25 | swizzles_type const& Swizzles = swizzles_type(SWIZZLE_RED, SWIZZLE_GREEN, SWIZZLE_BLUE, SWIZZLE_ALPHA)); 26 | 27 | /// Create a texture_cube and allocate a new storage_linear with a complete mipmap chain 28 | texture_cube( 29 | format_type Format, 30 | extent_type const & Extent, 31 | swizzles_type const& Swizzles = swizzles_type(SWIZZLE_RED, SWIZZLE_GREEN, SWIZZLE_BLUE, SWIZZLE_ALPHA)); 32 | 33 | /// Create a texture_cube view with an existing storage_linear 34 | explicit texture_cube( 35 | texture const& Texture); 36 | 37 | /// Create a texture_cube view with an existing storage_linear 38 | texture_cube( 39 | texture const& Texture, 40 | format_type Format, 41 | size_type BaseLayer, size_type MaxLayer, 42 | size_type BaseFace, size_type MaxFace, 43 | size_type BaseLevel, size_type MaxLevel, 44 | swizzles_type const& Swizzles = swizzles_type(SWIZZLE_RED, SWIZZLE_GREEN, SWIZZLE_BLUE, SWIZZLE_ALPHA)); 45 | 46 | /// Create a texture_cube view, reference a subset of an existing texture_cube instance 47 | texture_cube( 48 | texture_cube const& Texture, 49 | size_type BaseFace, size_type MaxFace, 50 | size_type BaseLevel, size_type MaxLevel); 51 | 52 | /// Create a view of the texture identified by Face in the texture cube 53 | texture2d operator[](size_type Face) const; 54 | 55 | /// Return the dimensions of a texture instance: width and height where both should be equal. 56 | extent_type extent(size_type Level = 0) const; 57 | 58 | /// Fetch a texel from a texture. The texture format must be uncompressed. 59 | template 60 | gen_type load(extent_type const& TexelCoord, size_type Face, size_type Level) const; 61 | 62 | /// Write a texel to a texture. The texture format must be uncompressed. 63 | template 64 | void store(extent_type const& TexelCoord, size_type Face, size_type Level, gen_type const& Texel); 65 | }; 66 | }//namespace gli 67 | 68 | #include "./core/texture_cube.inl" 69 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/texture_cube_array.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Include to use cube map array textures. 2 | /// @file gli/texture_cube_array.hpp 3 | 4 | #pragma once 5 | 6 | #include "texture_cube.hpp" 7 | 8 | namespace gli 9 | { 10 | /// Cube map array texture 11 | class texture_cube_array : public texture 12 | { 13 | public: 14 | typedef extent2d extent_type; 15 | 16 | public: 17 | /// Create an empty texture cube array 18 | texture_cube_array(); 19 | 20 | /// Create a texture_cube_array and allocate a new storage_linear 21 | texture_cube_array( 22 | format_type Format, 23 | extent_type const& Extent, 24 | size_type Layers, 25 | size_type Levels, 26 | swizzles_type const& Swizzles = swizzles_type(SWIZZLE_RED, SWIZZLE_GREEN, SWIZZLE_BLUE, SWIZZLE_ALPHA)); 27 | 28 | /// Create a texture_cube_array and allocate a new storage_linear with a complete mipmap chain 29 | texture_cube_array( 30 | format_type Format, 31 | extent_type const& Extent, 32 | size_type Layers, 33 | swizzles_type const& Swizzles = swizzles_type(SWIZZLE_RED, SWIZZLE_GREEN, SWIZZLE_BLUE, SWIZZLE_ALPHA)); 34 | 35 | /// Create a texture_cube_array view with an existing storage_linear 36 | explicit texture_cube_array( 37 | texture const& Texture); 38 | 39 | /// Reference a subset of an exiting storage_linear constructor 40 | texture_cube_array( 41 | texture const& Texture, 42 | format_type Format, 43 | size_type BaseLayer, size_type MaxLayer, 44 | size_type BaseFace, size_type MaxFace, 45 | size_type BaseLevel, size_type MaxLevel, 46 | swizzles_type const& Swizzles = swizzles_type(SWIZZLE_RED, SWIZZLE_GREEN, SWIZZLE_BLUE, SWIZZLE_ALPHA)); 47 | 48 | /// Create a texture view, reference a subset of an exiting texture_cube_array instance 49 | texture_cube_array( 50 | texture_cube_array const& Texture, 51 | size_type BaseLayer, size_type MaxLayer, 52 | size_type BaseFace, size_type MaxFace, 53 | size_type BaseLevel, size_type MaxLevel); 54 | 55 | /// Create a view of the texture identified by Layer in the texture array 56 | texture_cube operator[](size_type Layer) const; 57 | 58 | /// Return the dimensions of a texture instance: width and height where both should be equal. 59 | extent_type extent(size_type Level = 0) const; 60 | 61 | /// Fetch a texel from a texture. The texture format must be uncompressed. 62 | template 63 | gen_type load(extent_type const & TexelCoord, size_type Layer, size_type Face, size_type Level) const; 64 | 65 | /// Write a texel to a texture. The texture format must be uncompressed. 66 | template 67 | void store(extent_type const& TexelCoord, size_type Layer, size_type Face, size_type Level, gen_type const& Texel); 68 | }; 69 | }//namespace gli 70 | 71 | #include "./core/texture_cube_array.inl" 72 | 73 | -------------------------------------------------------------------------------- /SgOglLib/vendor/gli/gli/type.hpp: -------------------------------------------------------------------------------- 1 | /// @brief Include to use basic GLI types. 2 | /// @file gli/type.hpp 3 | 4 | #pragma once 5 | 6 | // STD 7 | #include 8 | 9 | // GLM 10 | #define GLM_FORCE_EXPLICIT_CTOR 11 | #include 12 | #include 13 | #define GLM_ENABLE_EXPERIMENTAL 14 | 15 | #if GLM_COMPILER & GLM_COMPILER_VC 16 | # define GLI_FORCE_INLINE __forceinline 17 | #elif GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_APPLE_CLANG | GLM_COMPILER_LLVM) 18 | # define GLI_FORCE_INLINE inline __attribute__((__always_inline__)) 19 | #else 20 | # define GLI_FORCE_INLINE inline 21 | #endif//GLM_COMPILER 22 | 23 | #define GLI_DISABLE_ASSERT 0 24 | 25 | #if defined(NDEBUG) || GLI_DISABLE_ASSERT 26 | # define GLI_ASSERT(test) 27 | #else 28 | # define GLI_ASSERT(test) assert((test)) 29 | #endif 30 | 31 | namespace gli 32 | { 33 | using namespace glm; 34 | 35 | using std::size_t; 36 | typedef glm::uint8 byte; 37 | 38 | typedef ivec1 extent1d; 39 | typedef ivec2 extent2d; 40 | typedef ivec3 extent3d; 41 | typedef ivec4 extent4d; 42 | 43 | template 44 | inline vec<4, T, P> make_vec4(vec<1, T, P> const & v) 45 | { 46 | return vec<4, T, P>(v.x, static_cast(0), static_cast(0), static_cast(1)); 47 | } 48 | 49 | template 50 | inline vec<4, T, P> make_vec4(vec<2, T, P> const & v) 51 | { 52 | return vec<4, T, P>(v.x, v.y, static_cast(0), static_cast(1)); 53 | } 54 | 55 | template 56 | inline vec<4, T, P> make_vec4(vec<3, T, P> const & v) 57 | { 58 | return vec<4, T, P>(v.x, v.y, v.z, static_cast(1)); 59 | } 60 | 61 | template 62 | inline vec<4, T, P> make_vec4(vec<4, T, P> const & v) 63 | { 64 | return v; 65 | } 66 | }//namespace gli 67 | -------------------------------------------------------------------------------- /conanfile_cmake.txt: -------------------------------------------------------------------------------- 1 | [requires] 2 | glm/0.9.9.7 3 | glfw/3.3.2 4 | glew/2.1.0@bincrafters/stable 5 | spdlog/1.5.0 6 | entt/3.4.0 7 | assimp/5.0.1 8 | freetype/2.10.1 9 | imgui/1.75 10 | fmt/6.2.0 11 | lua/5.3.5 12 | sol2/3.2.1 13 | 14 | [generators] 15 | cmake 16 | -------------------------------------------------------------------------------- /conanfile_premake.txt: -------------------------------------------------------------------------------- 1 | [requires] 2 | glm/0.9.9.7 3 | glfw/3.3.2 4 | glew/2.1.0@bincrafters/stable 5 | spdlog/1.5.0 6 | entt/3.4.0 7 | assimp/5.0.1 8 | freetype/2.10.1 9 | imgui/1.75 10 | fmt/6.2.0 11 | lua/5.3.5 12 | sol2/3.2.1 13 | 14 | [generators] 15 | premake 16 | -------------------------------------------------------------------------------- /premake5.lua: -------------------------------------------------------------------------------- 1 | include("conanbuildinfo.premake.lua") 2 | 3 | workspace "SgOgl" 4 | conan_basic_setup() 5 | 6 | architecture "x64" 7 | startproject "Sandbox" 8 | 9 | configurations 10 | { 11 | "Debug", 12 | "Release" 13 | } 14 | 15 | platforms 16 | { 17 | "StaticLib" 18 | } 19 | 20 | floatingpoint "Fast" 21 | flags "MultiProcessorCompile" 22 | 23 | outputdir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}" 24 | 25 | project "SgOglLib" 26 | location "SgOglLib" 27 | architecture "x64" 28 | language "C++" 29 | cppdialect "C++17" 30 | 31 | targetdir ("bin/" .. outputdir .. "/%{prj.name}") 32 | objdir ("obj/" .. outputdir .. "/%{prj.name}") 33 | 34 | files 35 | { 36 | "%{prj.name}/src/**.h", 37 | "%{prj.name}/src/**.cpp" 38 | } 39 | 40 | includedirs 41 | { 42 | "%{prj.name}/src", 43 | "%{prj.name}/src/SgOglLib", 44 | "%{prj.name}/vendor", 45 | "%{prj.name}/vendor/gli", 46 | } 47 | 48 | linkoptions 49 | { 50 | "/IGNORE:4099" 51 | } 52 | 53 | filter "system:windows" 54 | systemversion "latest" 55 | defines 56 | { 57 | "GLFW_INCLUDE_NONE" 58 | } 59 | 60 | filter "platforms:StaticLib" 61 | kind "StaticLib" 62 | 63 | filter "configurations:Debug" 64 | defines "SG_OGL_DEBUG_BUILD" 65 | runtime "Debug" 66 | symbols "on" 67 | buildoptions 68 | { 69 | "/bigobj" 70 | } 71 | 72 | filter "configurations:Release" 73 | runtime "Release" 74 | optimize "on" 75 | buildoptions 76 | { 77 | "/bigobj" 78 | } 79 | 80 | project "Sandbox" 81 | location "Sandbox" 82 | architecture "x64" 83 | kind "ConsoleApp" 84 | language "C++" 85 | cppdialect "C++17" 86 | 87 | targetdir ("bin/" .. outputdir .. "/%{prj.name}") 88 | objdir ("obj/" .. outputdir .. "/%{prj.name}") 89 | 90 | files 91 | { 92 | "%{prj.name}/src/**.h", 93 | "%{prj.name}/src/**.cpp" 94 | } 95 | 96 | includedirs 97 | { 98 | "%{prj.name}/src", 99 | "SgOglLib/src", 100 | "SgOglLib/src/SgOglLib", 101 | "SgOglLib/vendor", 102 | } 103 | 104 | links 105 | { 106 | "SgOglLib" 107 | } 108 | 109 | linkoptions 110 | { 111 | "/IGNORE:4099" 112 | } 113 | 114 | filter "system:windows" 115 | systemversion "latest" 116 | 117 | filter "configurations:Debug" 118 | defines "SG_OGL_DEBUG_BUILD" 119 | runtime "Debug" 120 | symbols "On" 121 | 122 | filter "configurations:Release" 123 | runtime "Release" 124 | optimize "On" 125 | --------------------------------------------------------------------------------