├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── apps ├── 00_triangle │ ├── CMakeLists.txt │ └── demo_triangle.cpp ├── 01_indexed_plane │ ├── CMakeLists.txt │ └── demo_indexed_plane.cpp ├── 02_depth_buffer │ ├── CMakeLists.txt │ └── demo_depth_buffer.cpp ├── 03_texture │ ├── CMakeLists.txt │ ├── assets │ │ └── grid.png │ └── demo_texture.cpp ├── 04_framebuffer │ ├── CMakeLists.txt │ └── demo_framebuffer.cpp ├── 05_viewer │ ├── CMakeLists.txt │ └── demo_viewer.cpp ├── 06_model │ ├── CMakeLists.txt │ ├── assets │ │ └── sad_toaster │ │ │ ├── Licence_BY_NC.txt │ │ │ ├── color.png │ │ │ ├── sad_toaster.mtl │ │ │ └── sad_toaster.obj │ └── demo_model.cpp ├── 07_blinn_phong │ ├── CMakeLists.txt │ ├── assets │ │ └── sphere │ │ │ ├── sphere.mtl │ │ │ └── sphere.obj │ └── demo_blinn_phong.cpp ├── 08_normal_mapping │ ├── CMakeLists.txt │ ├── assets │ │ └── cartridge │ │ │ ├── Material.001_baseColor.png │ │ │ ├── Material.001_metallicRoughness.png │ │ │ ├── Material.001_normal.png │ │ │ ├── cartridge.mtl │ │ │ ├── cartridge.obj │ │ │ └── license.txt │ └── demo_normal_mapping.cpp ├── 09_shadow_mapping │ ├── CMakeLists.txt │ ├── assets │ │ └── low_poly_house │ │ │ ├── license.txt │ │ │ ├── low_poly_house.mtl │ │ │ └── low_poly_house.obj │ └── demo_shadow_mapping.cpp ├── 10_ambient_occlussion │ ├── CMakeLists.txt │ ├── assets │ │ └── firered_room │ │ │ ├── fireRed_material_baseColor.png │ │ │ ├── license.txt │ │ │ ├── room.mtl │ │ │ └── room.obj │ └── demo_ssao.cpp ├── 11_physically_based │ ├── CMakeLists.txt │ ├── assets │ │ ├── camera │ │ │ ├── camera.mtl │ │ │ ├── camera.obj │ │ │ ├── license.txt │ │ │ └── textures │ │ │ │ ├── lambert1_baseColor.png │ │ │ │ ├── lambert1_metallicRoughness.png │ │ │ │ ├── lambert1_normal.png │ │ │ │ └── standardSurface2_metallicRoughness.png │ │ ├── drakefire │ │ │ ├── drakefire.mtl │ │ │ ├── drakefire.obj │ │ │ ├── license.txt │ │ │ └── textures │ │ │ │ ├── base_baseColor.jpeg │ │ │ │ ├── base_metallicRoughness.png │ │ │ │ └── base_normal.jpeg │ │ ├── pbr │ │ │ ├── 0_precomputed_radiance.hdr │ │ │ ├── 10_precomputed_radiance.hdr │ │ │ ├── 1_precomputed_radiance.hdr │ │ │ ├── 2_precomputed_radiance.hdr │ │ │ ├── 3_precomputed_radiance.hdr │ │ │ ├── 4_precomputed_radiance.hdr │ │ │ ├── 5_precomputed_radiance.hdr │ │ │ ├── 6_precomputed_radiance.hdr │ │ │ ├── 7_precomputed_radiance.hdr │ │ │ ├── 8_precomputed_radiance.hdr │ │ │ ├── 9_precomputed_radiance.hdr │ │ │ ├── precomputed_brdf.hdr │ │ │ └── precomputed_irradiance.hdr │ │ └── rural_asphalt_road_1k.hdr │ ├── demo_pbr.cpp │ └── pbr_precompute.cpp ├── 12_cel_shading │ ├── CMakeLists.txt │ ├── assets │ │ └── bird │ │ │ ├── bird.mtl │ │ │ ├── bird.obj │ │ │ ├── license.txt │ │ │ └── textures │ │ │ ├── MAT_Bird_baseColor.png │ │ │ ├── MAT_Bird_metallicRoughness.png │ │ │ ├── MAT_Bird_normal.png │ │ │ ├── MAT_branch_baseColor.png │ │ │ ├── MAT_branch_metallicRoughness.png │ │ │ └── MAT_branch_normal.png │ └── demo_cel_shading.cpp ├── CMakeLists.txt └── utility │ ├── CMakeLists.txt │ ├── detail │ ├── mesh.h │ ├── shader.h │ └── texture.h │ ├── gl_window.cpp │ ├── gl_window.h │ ├── model.h │ ├── objload.h │ └── timing.h ├── external ├── glad │ ├── CMakeLists.txt │ ├── include │ │ ├── KHR │ │ │ └── khrplatform.h │ │ └── glad │ │ │ └── glad.h │ └── src │ │ └── glad.cpp ├── glfw │ ├── .appveyor.yml │ ├── .gitattributes │ ├── .github │ │ └── CONTRIBUTING.md │ ├── .gitignore │ ├── .travis.yml │ ├── CMake │ │ └── MacOSXBundleInfo.plist.in │ ├── CMakeLists.txt │ ├── LICENSE.md │ ├── README.md │ ├── cmake_uninstall.cmake.in │ ├── deps │ │ ├── getopt.c │ │ ├── getopt.h │ │ ├── glad │ │ │ ├── gl.h │ │ │ ├── khrplatform.h │ │ │ ├── vk_platform.h │ │ │ └── vulkan.h │ │ ├── glad_gl.c │ │ ├── glad_vulkan.c │ │ ├── linmath.h │ │ ├── mingw │ │ │ ├── _mingw_dxhelper.h │ │ │ ├── dinput.h │ │ │ └── xinput.h │ │ ├── nuklear.h │ │ ├── nuklear_glfw_gl2.h │ │ ├── stb_image_write.h │ │ ├── tinycthread.c │ │ ├── tinycthread.h │ │ └── vs2008 │ │ │ └── stdint.h │ ├── docs │ │ ├── CMakeLists.txt │ │ ├── CODEOWNERS │ │ ├── CONTRIBUTING.md │ │ ├── Doxyfile.in │ │ ├── DoxygenLayout.xml │ │ ├── SUPPORT.md │ │ ├── extra.css │ │ ├── extra.less │ │ ├── footer.html │ │ ├── header.html │ │ └── spaces.svg │ ├── examples │ │ ├── CMakeLists.txt │ │ ├── boing.c │ │ ├── gears.c │ │ ├── glfw.icns │ │ ├── glfw.ico │ │ ├── glfw.rc │ │ ├── heightmap.c │ │ ├── offscreen.c │ │ ├── particles.c │ │ ├── sharing.c │ │ ├── simple.c │ │ ├── splitview.c │ │ └── wave.c │ ├── include │ │ └── GLFW │ │ │ ├── glfw3.h │ │ │ └── glfw3native.h │ ├── src │ │ ├── CMakeLists.txt │ │ ├── cocoa_init.m │ │ ├── cocoa_joystick.h │ │ ├── cocoa_joystick.m │ │ ├── cocoa_monitor.m │ │ ├── cocoa_platform.h │ │ ├── cocoa_time.c │ │ ├── cocoa_window.m │ │ ├── context.c │ │ ├── egl_context.c │ │ ├── egl_context.h │ │ ├── glfw3.pc.in │ │ ├── glfw3Config.cmake.in │ │ ├── glfw_config.h.in │ │ ├── glx_context.c │ │ ├── glx_context.h │ │ ├── init.c │ │ ├── input.c │ │ ├── internal.h │ │ ├── linux_joystick.c │ │ ├── linux_joystick.h │ │ ├── mappings.h │ │ ├── mappings.h.in │ │ ├── monitor.c │ │ ├── nsgl_context.h │ │ ├── nsgl_context.m │ │ ├── null_init.c │ │ ├── null_joystick.c │ │ ├── null_joystick.h │ │ ├── null_monitor.c │ │ ├── null_platform.h │ │ ├── null_window.c │ │ ├── osmesa_context.c │ │ ├── osmesa_context.h │ │ ├── posix_thread.c │ │ ├── posix_thread.h │ │ ├── posix_time.c │ │ ├── posix_time.h │ │ ├── vulkan.c │ │ ├── wgl_context.c │ │ ├── wgl_context.h │ │ ├── win32_init.c │ │ ├── win32_joystick.c │ │ ├── win32_joystick.h │ │ ├── win32_monitor.c │ │ ├── win32_platform.h │ │ ├── win32_thread.c │ │ ├── win32_time.c │ │ ├── win32_window.c │ │ ├── window.c │ │ ├── wl_init.c │ │ ├── wl_monitor.c │ │ ├── wl_platform.h │ │ ├── wl_window.c │ │ ├── x11_init.c │ │ ├── x11_monitor.c │ │ ├── x11_platform.h │ │ ├── x11_window.c │ │ ├── xkb_unicode.c │ │ └── xkb_unicode.h │ └── tests │ │ ├── CMakeLists.txt │ │ ├── clipboard.c │ │ ├── cursor.c │ │ ├── empty.c │ │ ├── events.c │ │ ├── gamma.c │ │ ├── glfwinfo.c │ │ ├── icon.c │ │ ├── iconify.c │ │ ├── inputlag.c │ │ ├── joysticks.c │ │ ├── monitors.c │ │ ├── msaa.c │ │ ├── opacity.c │ │ ├── reopen.c │ │ ├── tearing.c │ │ ├── threads.c │ │ ├── timeout.c │ │ ├── title.c │ │ ├── triangle-vulkan.c │ │ └── windows.c ├── stb_image │ ├── CMakeLists.txt │ ├── stb_image.h │ ├── stb_image_resize.h │ ├── stb_image_write.h │ └── stb_impl.cpp └── tiny_obj_loader │ ├── CMakeLists.txt │ ├── tiny_obj_loader.cpp │ └── tiny_obj_loader.h ├── img ├── 00_triangle.png ├── banner.png ├── example_ao_map.png ├── example_blinn_phong.jpg ├── example_cel_shading.png ├── example_model.jpg ├── example_normal_mapping.png ├── example_pbr.png ├── example_shadow_mapping.png └── example_ssao.png └── rasterizer ├── CMakeLists.txt ├── buffer.h ├── detail ├── test_member.h └── tuple_helper.h ├── framebuffer.h ├── math ├── base.h ├── matrix3.h ├── matrix4.h ├── rectangle.h ├── utility.cpp ├── utility.h ├── vector2.h ├── vector3.h └── vector4.h ├── program.h ├── renderer.cpp ├── renderer.h ├── sampler.h ├── texture.cpp └── texture.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by MacOS 2 | .DS_Store 3 | 4 | # Generated by Windows 5 | Thumbs.db 6 | 7 | # Applications 8 | *.app 9 | *.exe 10 | *.war 11 | 12 | # Large media files 13 | *.mp4 14 | *.tiff 15 | *.avi 16 | *.flv 17 | *.mov 18 | *.wmv 19 | 20 | # cmake and building stuff 21 | dist/ 22 | build/ 23 | debug/ 24 | compile_commands.json 25 | CMakeLists.txt.user 26 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ############################################ 2 | # Software Rasterizer # 3 | #------------------------------------------# 4 | # @author Nikolaus Rauch # 5 | # @date 14.12.2021 # 6 | #------------------------------------------# 7 | ############################################ 8 | cmake_minimum_required( VERSION 3.9 ) 9 | project( software-rasterizer ) 10 | 11 | message("\n * CPU Software Rasterizer ") 12 | 13 | message(STATUS "${PROJECT_NAME} build environment --") 14 | message(STATUS "Build system: ${CMAKE_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}") 15 | 16 | 17 | ######################################### 18 | # CMake-Stuff # 19 | ######################################### 20 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) 21 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) 22 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin) 23 | 24 | 25 | ######################################### 26 | # Global Compiler Options # 27 | ######################################### 28 | set(GCC_COMPILE_OPTIONS "-W;-Wall;-Wno-unused-variable;-Wno-unused-parameter") 29 | set(GCC_COMPILE_DEBUG_OPTIONS "${GCC_COMPILE_OPTIONS};-ggdb;-O0") 30 | set(GCC_COMPILE_RELEASE_OPTIONS "${GCC_COMPILE_OPTIONS};-O3;-march=native;-ffast-math;") 31 | set(GCC_COMPILE_SUPPRESS_WARING "-w") 32 | 33 | set(MSVC_COMPILE_OPTIONS "/W3;/wd4244;/wd4305") 34 | set(MSVC_COMPILE_DEBUG_OPTIONS "${MSVC_COMPILE_OPTIONS};/Zi") 35 | set(MSVC_COMPILE_RELEASE_OPTIONS "${MSVC_COMPILE_OPTIONS};/O2;/fp:fast;/arch") 36 | set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) 37 | 38 | add_compile_options("$<$,$>:${GCC_COMPILE_DEBUG_OPTIONS}>") 39 | add_compile_options("$<$,$>:${GCC_COMPILE_RELEASE_OPTIONS}>") 40 | 41 | add_compile_options("$<$,$>:${MSVC_COMPILE_DEBUG_OPTIONS}>") 42 | add_compile_options("$<$,$>:${MSVC_COMPILE_RELEASE_OPTIONS}>") 43 | 44 | 45 | ######################################### 46 | # Build External-Libraries # 47 | ######################################### 48 | set( OpenGL_GL_PREFERENCE GLVND ) 49 | find_package( OpenGL 3.0 REQUIRED ) 50 | 51 | add_subdirectory(external/glad) 52 | target_compile_options(glad_static PRIVATE "$<$:${GCC_COMPILE_SUPPRESS_WARING}>") 53 | target_include_directories( glad_static PUBLIC 54 | $ 55 | ) 56 | 57 | add_subdirectory(external/glfw) 58 | target_compile_options(glfw PRIVATE "$<$:${GCC_COMPILE_SUPPRESS_WARING}>") 59 | target_include_directories( glfw PUBLIC 60 | $ 61 | ) 62 | 63 | add_subdirectory(external/stb_image) 64 | target_compile_options(stb_image PRIVATE "$<$:${GCC_COMPILE_SUPPRESS_WARING}>") 65 | 66 | add_subdirectory(external/tiny_obj_loader) 67 | target_compile_options(tiny_obj PRIVATE "$<$:${GCC_COMPILE_SUPPRESS_WARING}>") 68 | 69 | 70 | ######################################### 71 | # Build Software Rasterizer # 72 | ######################################### 73 | add_subdirectory(rasterizer) 74 | 75 | ######################################### 76 | # Build Examples # 77 | ######################################### 78 | add_subdirectory(apps) 79 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 iamthegreengoblin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /apps/00_triangle/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable( 00_triangle ${CMAKE_CURRENT_SOURCE_DIR}/demo_triangle.cpp) 2 | target_link_libraries( 00_triangle PRIVATE rasterizer_static ) 3 | 4 | target_compile_features( 00_triangle PUBLIC cxx_std_20 ) 5 | set_target_properties( 00_triangle PROPERTIES CXX_EXTENSIONS OFF ) 6 | -------------------------------------------------------------------------------- /apps/00_triangle/demo_triangle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | /* vertex data -> input to draw call (via Buffer) */ 7 | struct Vertex 8 | { 9 | Vec3 pos; 10 | Vec3 color; 11 | }; 12 | 13 | /* 14 | * Output of vertex stage, Input to fragment stage 15 | * -> position is mandatory 16 | * -> members to interpolate are declared by VARYING and VAL Macros (member need scalar multiplication, and addition) 17 | */ 18 | struct Varying 19 | { 20 | Vec4 position; 21 | Vec3 color; 22 | 23 | VARYING(position, color); 24 | }; 25 | 26 | /* uniform struct accessable from both "shaders" */ 27 | struct Uniforms 28 | { 29 | 30 | }; 31 | 32 | int main(int argc, char** argv) 33 | { 34 | /*========== Setup Shader Program ========*/ 35 | Program program; 36 | program.onVertex([](const Uniforms& uniform, const Vertex& in, Varying& out) 37 | { 38 | out.position = Vec4(in.pos, 1.0f); 39 | out.color = in.color; 40 | }); 41 | 42 | program.onFragment([](const Uniforms& uniform, const Varying& in, Vec4& out) 43 | { 44 | out = Vec4(in.color, 1.0f); 45 | }); 46 | 47 | /*========== Setup Buffer Data ========*/ 48 | Buffer buffer; 49 | buffer.primitive = ePrimitive::TRIANGLES; 50 | buffer.vertices = { { {-0.5, -0.5, 0.5}, {1.0, 0.0, 0.0} }, 51 | { { 0.5, -0.5, 0.5}, {0.0, 1.0, 0.0} }, 52 | { { 0.0, 0.5, 0.5}, {0.0, 0.0, 1.0} } }; 53 | 54 | 55 | 56 | /* rasterizer with framebuffer size */ 57 | Renderer rasterizer(480, 480); 58 | 59 | /* clear framebuffer */ 60 | rasterizer.framebuffer().clear(Vec4(0, 0, 0, 1)); 61 | 62 | /* submit draw call */ 63 | rasterizer.draw(program, buffer); 64 | 65 | /* save framebuffer as .png */ 66 | rasterizer.framebuffer().color().save("00_triangle.png"); 67 | 68 | return EXIT_SUCCESS; 69 | } 70 | -------------------------------------------------------------------------------- /apps/01_indexed_plane/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable( 01_indexed_plane ${CMAKE_CURRENT_SOURCE_DIR}/demo_indexed_plane.cpp) 2 | target_link_libraries( 01_indexed_plane PRIVATE rasterizer_static ) 3 | 4 | target_compile_features( 01_indexed_plane PUBLIC cxx_std_20 ) 5 | set_target_properties( 01_indexed_plane PROPERTIES CXX_EXTENSIONS OFF ) 6 | -------------------------------------------------------------------------------- /apps/01_indexed_plane/demo_indexed_plane.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | /* vertex data -> input to draw call (via Buffer) */ 7 | struct Vertex 8 | { 9 | Vec3 pos; 10 | Vec3 color; 11 | }; 12 | 13 | /* 14 | * Output of vertex stage, Input to fragment stage 15 | * -> position is mandatory 16 | * -> members to interpolate are declared by VARYING and VAL Macros (member need scalar multiplication, and addition) 17 | */ 18 | struct Varying 19 | { 20 | Vec4 position; 21 | Vec3 color; 22 | 23 | VARYING( position, color ); 24 | }; 25 | 26 | /* uniform struct accessable from both "shaders" */ 27 | struct Uniforms 28 | { 29 | Mat4 view; 30 | Mat4 proj; 31 | }; 32 | 33 | int main(int argc, char** argv) 34 | { 35 | /*========== Setup Shader Program ========*/ 36 | Program program; 37 | program.onVertex([](const Uniforms& uniform, const Vertex& in, Varying& out) 38 | { 39 | out.position = uniform.proj * uniform.view * Vec4(in.pos, 1.0f); 40 | out.color = in.color; 41 | }); 42 | 43 | program.onFragment([](const Uniforms& uniform, const Varying& in, Vec4& out) 44 | { 45 | out = Vec4(in.color, 1.0); 46 | }); 47 | 48 | /* set uniforms */ 49 | auto& uniforms = program.uniforms(); 50 | uniforms.proj = Mat4::perspective(radians(45.0f), 1280.0f/720.0f, 1.0f, 7.0f); 51 | uniforms.view = Mat4::translation(-Vec3{0.0f, 0.25f, 3.5f}) * Mat4::rotationX(radians(10.0f)); 52 | 53 | /*========== Setup Buffer Data ========*/ 54 | BufferIndexed buffer; 55 | buffer.primitive = ePrimitive::TRIANGLES; 56 | buffer.vertices = { {{-1.0, 0.0, -1.0}, {1.0, 0.0, 0.0} }, 57 | {{-1.0, 0.0, 1.0}, {1.0, 1.0, 1.0} }, 58 | {{ 1.0, 0.0, 1.0}, {0.0, 0.0, 1.0} }, 59 | {{ 1.0, 0.0, -1.0}, {0.0, 1.0, 0.0} } }; 60 | buffer.indices = { 0, 1, 2, 2, 3, 0 }; 61 | 62 | 63 | /* rasterizer with framebuffer size */ 64 | Renderer rasterizer(1280, 720); 65 | 66 | /* clear framebuffer */ 67 | rasterizer.framebuffer().clear(Vec4(0, 0, 0, 1)); 68 | 69 | /* submit draw call */ 70 | rasterizer.draw(program, buffer); 71 | 72 | /* save framebuffer as .png */ 73 | rasterizer.framebuffer().color().save("01_indexed_plane.png"); 74 | 75 | return EXIT_SUCCESS; 76 | } 77 | -------------------------------------------------------------------------------- /apps/02_depth_buffer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable( 02_depth_buffer ${CMAKE_CURRENT_SOURCE_DIR}/demo_depth_buffer.cpp) 2 | target_link_libraries( 02_depth_buffer PRIVATE rasterizer_static ) 3 | 4 | target_compile_features( 02_depth_buffer PUBLIC cxx_std_20 ) 5 | set_target_properties( 02_depth_buffer PROPERTIES CXX_EXTENSIONS OFF ) 6 | -------------------------------------------------------------------------------- /apps/02_depth_buffer/demo_depth_buffer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | /* vertex data -> input to draw call (via Buffer) */ 7 | struct Vertex 8 | { 9 | Vec3 pos; 10 | Vec3 color; 11 | }; 12 | 13 | /* 14 | * Output of vertex stage, Input to fragment stage 15 | * -> position is mandatory 16 | * -> members to interpolate are declared by VARYING and VAL Macros (member need scalar multiplication, and addition) 17 | */ 18 | struct Varying 19 | { 20 | Vec4 position; 21 | Vec3 color; 22 | 23 | VARYING(position, color); 24 | }; 25 | 26 | /* uniform struct accessable from both "shaders" */ 27 | struct Uniforms 28 | { 29 | Mat4 model; 30 | Mat4 view; 31 | Mat4 proj; 32 | }; 33 | 34 | int main(int argc, char** argv) 35 | { 36 | /*========== Setup Shader Program ========*/ 37 | Program program; 38 | program.onVertex([](const Uniforms& uniform, const Vertex& in, Varying& out) 39 | { 40 | out.position = uniform.proj * uniform.view * uniform.model * Vec4(in.pos, 1.0f); 41 | out.color = in.color; 42 | }); 43 | 44 | program.onFragment([](const Uniforms& uniform, const Varying& in, Vec4& out) 45 | { 46 | out = Vec4(in.color, 1.0); 47 | }); 48 | 49 | /* set uniforms */ 50 | auto& uniforms = program.uniforms(); 51 | uniforms.proj = Mat4::perspective(radians(45.0f), 1280.0f/720.0f, 1.0, 7.0); 52 | uniforms.view = Mat4::translation(-Vec3{0, 0.25, 3.5}) * Mat4::rotationX(radians(10.0f)); 53 | 54 | 55 | /*========== Setup Buffer Data ========*/ 56 | /* plane */ 57 | BufferIndexed buffer_plane; 58 | buffer_plane.primitive = ePrimitive::TRIANGLES; 59 | buffer_plane.vertices = 60 | { 61 | {{-1.0, 0.0, -1.0}, {1.0, 0.0, 0.0} }, 62 | {{-1.0, 0.0, 1.0}, {1.0, 1.0, 1.0} }, 63 | {{ 1.0, 0.0, 1.0}, {0.0, 0.0, 1.0} }, 64 | {{ 1.0, 0.0, -1.0}, {0.0, 1.0, 0.0} } 65 | }; 66 | buffer_plane.indices = { 0, 1, 2, 2, 3, 0 }; 67 | 68 | /* cube */ 69 | BufferIndexed buffer_cube; 70 | buffer_cube.primitive = ePrimitive::TRIANGLES; 71 | buffer_cube.vertices = 72 | { 73 | {{-1.0, -1.0, 1.0}, {1.0, 0.0, 0.0}}, 74 | {{-1.0, 1.0, 1.0}, {0.0, 1.0, 0.0}}, 75 | {{ 1.0, 1.0, 1.0}, {0.0, 0.0, 1.0}}, 76 | {{ 1.0, -1.0, 1.0}, {1.0, 0.0, 1.0}}, 77 | 78 | {{-1.0, -1.0, -1.0}, {1.0, 0.0, 0.0}}, 79 | {{-1.0, 1.0, -1.0}, {0.0, 1.0, 0.0}}, 80 | {{ 1.0, 1.0, -1.0}, {0.0, 0.0, 1.0}}, 81 | {{ 1.0, -1.0, -1.0}, {1.0, 0.0, 1.0}} 82 | }; 83 | buffer_cube.indices = 84 | { 85 | 2, 1, 0, 86 | 0, 3, 2, 87 | 88 | 4, 5, 6, 89 | 6, 7, 4, 90 | 91 | 0, 1, 5, 92 | 5, 4, 0, 93 | 94 | 6, 2, 3, 95 | 3, 7, 6, 96 | 97 | 6, 5, 1, 98 | 1, 2, 6, 99 | 100 | 0, 4, 7, 101 | 7, 3, 0 102 | }; 103 | 104 | 105 | /* rasterizer with framebuffer size */ 106 | Renderer rasterizer(1280, 720); 107 | 108 | /* clear framebuffer */ 109 | rasterizer.framebuffer().clear(Vec4(0, 0, 0, 1)); 110 | 111 | /* submit draw call */ 112 | uniforms.model = Mat4::translation({-0.5, 0.2, 1.5}) * Mat4::scale(0.2, 0.2, 0.2); 113 | rasterizer.draw(program, buffer_cube); 114 | 115 | uniforms.model = Mat4::translation({0.5, 0.2, 1.0}) * Mat4::scale(0.2, 0.2, 0.2); 116 | rasterizer.draw(program, buffer_cube); 117 | 118 | uniforms.model = Mat4::translation({-0.4, 0.2, -0.3}) * Mat4::scale(0.2, 0.2, 0.2); 119 | rasterizer.draw(program, buffer_cube); 120 | 121 | uniforms.model = Mat4::scale(3.0, 2.0, 3.0); 122 | rasterizer.draw(program, buffer_plane); 123 | 124 | /* save framebuffer as .png */ 125 | rasterizer.framebuffer().color().save("02_color_buffer.png"); 126 | rasterizer.framebuffer().depth().save("02_depth_buffer.png"); 127 | 128 | return EXIT_SUCCESS; 129 | } 130 | -------------------------------------------------------------------------------- /apps/03_texture/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable( 03_texture ${CMAKE_CURRENT_SOURCE_DIR}/demo_texture.cpp) 2 | target_link_libraries( 03_texture PRIVATE rasterizer_static ) 3 | 4 | target_compile_features( 03_texture PUBLIC cxx_std_20 ) 5 | set_target_properties( 03_texture PROPERTIES CXX_EXTENSIONS OFF ) 6 | 7 | add_custom_target( 03_texture_copy_asset ALL 8 | COMMAND ${CMAKE_COMMAND} -E copy_directory 9 | ${CMAKE_CURRENT_SOURCE_DIR}/assets 10 | $/assets ) 11 | -------------------------------------------------------------------------------- /apps/03_texture/assets/grid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/03_texture/assets/grid.png -------------------------------------------------------------------------------- /apps/03_texture/demo_texture.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | struct Vertex 8 | { 9 | Vec3 pos; 10 | Vec2 uv; 11 | }; 12 | 13 | struct Varying 14 | { 15 | Vec4 position; 16 | Vec2 uv; 17 | 18 | VARYING( position, uv ); 19 | }; 20 | 21 | struct Uniforms 22 | { 23 | Sampler texture; 24 | }; 25 | 26 | 27 | int main(int argc, char** argv) 28 | { 29 | /*========== Setup Shader Program ========*/ 30 | Program program; 31 | program.onVertex([](const Uniforms& uniform, const Vertex& in, Varying& out) 32 | { 33 | out.position = Vec4(in.pos, 1.0f); 34 | out.uv = in.uv; 35 | }); 36 | 37 | program.onFragment([](const Uniforms& uniform, const Varying& in, Vec4& out) 38 | { 39 | Vec4 color = texture(uniform.texture, in.uv) / 255.0f; 40 | out = color; 41 | }); 42 | 43 | 44 | /*========== Setup Buffer Data ========*/ 45 | Buffer buffer_quad; 46 | buffer_quad.primitive = ePrimitive::TRIANGLES; 47 | buffer_quad.vertices = { { {-1.0, -1.0, 0.0}, {-1.0, -1.0} }, 48 | { { 1.0, -1.0, 0.0}, { 2.0, -1.0} }, 49 | { { 1.0, 1.0, 0.0}, { 2.0, 2.0} }, 50 | 51 | { {-1.0, -1.0, 0.0}, {-1.0, -1.0} }, 52 | { { 1.0, 1.0, 0.0}, { 2.0, 2.0} }, 53 | { {-1.0, 1.0, 0.0}, {-1.0, 2.0} } }; 54 | 55 | 56 | /*========== Load Texture and set uniform ========*/ 57 | Texture texture; 58 | texture.load("assets/grid.png"); 59 | program.uniforms().texture = texture; 60 | program.uniforms().texture.filter = eFilter::NEAREST; 61 | program.uniforms().texture.wrap = eWrap::CLAMP_EDGE; 62 | 63 | 64 | Renderer rasterizer(480, 480); 65 | 66 | /* clear framebuffer */ 67 | rasterizer.framebuffer().clear(Vec4(0.2, 0.2, 0.2, 1)); 68 | 69 | /* submit draw call */ 70 | rasterizer.draw(program, buffer_quad); 71 | 72 | /* save framebuffer as .png */ 73 | rasterizer.framebuffer().color().save("03_texture.png"); 74 | 75 | return EXIT_SUCCESS; 76 | } 77 | -------------------------------------------------------------------------------- /apps/04_framebuffer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable( 04_framebuffer ${CMAKE_CURRENT_SOURCE_DIR}/demo_framebuffer.cpp) 2 | target_link_libraries( 04_framebuffer PRIVATE rasterizer_static ) 3 | 4 | target_compile_features( 04_framebuffer PUBLIC cxx_std_20 ) 5 | set_target_properties( 04_framebuffer PROPERTIES CXX_EXTENSIONS OFF ) 6 | -------------------------------------------------------------------------------- /apps/04_framebuffer/demo_framebuffer.cpp: -------------------------------------------------------------------------------- 1 | #include "sampler.h" 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | /* vertex, fragment data for triangle pass */ 8 | namespace triangle 9 | { 10 | 11 | struct Vertex 12 | { 13 | Vec3 pos; 14 | Vec3 color; 15 | }; 16 | 17 | struct Varying 18 | { 19 | Vec4 position; 20 | Vec3 color; 21 | 22 | VARYING(position, color); 23 | }; 24 | 25 | struct Uniforms 26 | { 27 | 28 | }; 29 | 30 | } 31 | 32 | 33 | /* vertex, fragment data for fullscreen quad pass */ 34 | namespace quad 35 | { 36 | 37 | struct Vertex 38 | { 39 | Vec3 pos; 40 | Vec2 uv; 41 | }; 42 | 43 | struct Varying 44 | { 45 | Vec4 position; 46 | Vec2 uv; 47 | 48 | VARYING(position, uv); 49 | }; 50 | 51 | struct Uniforms 52 | { 53 | Sampler color; 54 | }; 55 | 56 | } 57 | 58 | 59 | int main(int argc, char** argv) 60 | { 61 | /* "offscreen" framebuffer */ 62 | Framebuffer framebuffer(480, 480); 63 | 64 | 65 | /*========== Setup Shader Program (1. render pass to custom framebuffer) ========*/ 66 | Program> program_triangle; 67 | program_triangle.onVertex([](const auto& uniform, const auto& in, auto& out) 68 | { 69 | out.position = Vec4(in.pos, 1.0f); 70 | out.color = in.color; 71 | }); 72 | 73 | program_triangle.onFragment([](const auto& uniform, const auto& in, auto& out) 74 | { 75 | auto& [out_color] = out; /* or std::get<0>(out) */ 76 | out_color = RGBA8(255.0f * Vec4(in.color, 1.0f)); 77 | }); 78 | 79 | /*========== Setup Shader Program (2. render pass) ========*/ 80 | Program program_quad; 81 | program_quad.onVertex([](const auto& uniform, const auto& in, auto& out) 82 | { 83 | out.position = Vec4(in.pos, 1.0f); 84 | out.uv = in.uv; 85 | }); 86 | 87 | program_quad.onFragment([](const auto& uniform, const auto& in, auto& out) 88 | { 89 | out = texture(uniform.color, in.uv) / 255.0f; 90 | }); 91 | 92 | /* use framebuffer of first render pass in second shader */ 93 | program_quad.uniforms().color.filter = eFilter::NEAREST; 94 | program_quad.uniforms().color = framebuffer.target<0>(); 95 | 96 | 97 | /*========== Setup Buffer Data ========*/ 98 | Buffer buffer_triangle; 99 | buffer_triangle.primitive = ePrimitive::TRIANGLES; 100 | buffer_triangle.vertices = { { {-0.5, -0.5, 0.5}, {1.0, 0.0, 0.0} }, 101 | { { 0.5, -0.5, 0.5}, {0.0, 1.0, 0.0} }, 102 | { { 0.0, 0.5, 0.5}, {0.0, 0.0, 1.0} } }; 103 | 104 | Buffer buffer_quad; 105 | buffer_quad.primitive = ePrimitive::TRIANGLES; 106 | buffer_quad.vertices = { { {-1.0, -1.0, 0.0}, {0.0, 0.0} }, 107 | { { 1.0, -1.0, 0.0}, {1.0, 0.0} }, 108 | { { 1.0, 1.0, 0.0}, {1.0, 1.0} }, 109 | 110 | { {-1.0, -1.0, 0.0}, {0.0, 0.0} }, 111 | { { 1.0, 1.0, 0.0}, {1.0, 1.0} }, 112 | { {-1.0, 1.0, 0.0}, {0.0, 1.0} } }; 113 | 114 | 115 | 116 | /* rasterizer with framebuffer size */ 117 | Renderer rasterizer(480, 480); 118 | 119 | /* clear framebuffers */ 120 | framebuffer.clear(Vec4(1, 1, 0, 1)); 121 | rasterizer.framebuffer().clear(Vec4(0, 0, 0, 1)); 122 | 123 | /* first render pass to draw triangle into custom framebuffer */ 124 | rasterizer.draw(program_triangle, buffer_triangle, framebuffer); 125 | 126 | /* second render pass to blur previous framebuffer */ 127 | rasterizer.draw(program_quad, buffer_quad); 128 | 129 | /* save framebuffer as .png */ 130 | rasterizer.framebuffer().color().save("04_framebuffer.png"); 131 | 132 | return EXIT_SUCCESS; 133 | } 134 | -------------------------------------------------------------------------------- /apps/05_viewer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable( 05_viewer ${CMAKE_CURRENT_SOURCE_DIR}/demo_viewer.cpp) 2 | target_link_libraries( 05_viewer PRIVATE rasterizer_static utility ) 3 | 4 | target_compile_features( 05_viewer PUBLIC cxx_std_20 ) 5 | set_target_properties( 05_viewer PROPERTIES CXX_EXTENSIONS OFF ) 6 | -------------------------------------------------------------------------------- /apps/05_viewer/demo_viewer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | 10 | 11 | struct Vertex 12 | { 13 | Vec3 pos; 14 | Vec3 color; 15 | }; 16 | 17 | struct Varying 18 | { 19 | Vec4 position; 20 | Vec3 color; 21 | 22 | VARYING( position, color ); 23 | }; 24 | 25 | struct Uniforms 26 | { 27 | Mat4 model; 28 | Mat4 view; 29 | Mat4 proj; 30 | }; 31 | 32 | int main(int argc, char** argv) 33 | { 34 | Renderer rasterizer(1280, 720); 35 | 36 | /*========== Setup Shader Program ========*/ 37 | Program program; 38 | program.onVertex([](const Uniforms& uniform, const Vertex& in, Varying& out) 39 | { 40 | out.position = uniform.proj * uniform.view * uniform.model * Vec4(in.pos, 1.0f); 41 | out.color = in.color; 42 | }); 43 | 44 | program.onFragment([](const Uniforms& uniform, const Varying& in, Vec4& out) 45 | { 46 | out = Vec4(in.color, 1.0); 47 | }); 48 | 49 | /* set uniforms */ 50 | auto& uniforms = program.uniforms(); 51 | uniforms.proj = Mat4::perspective(radians(45.0f), 1280.0f/720.0f, 1.0, 7.0); 52 | uniforms.view = Mat4::translation(-Vec3{0, 0.0, 3.5}); 53 | 54 | /* cube */ 55 | BufferIndexed buffer_cube; 56 | buffer_cube.primitive = ePrimitive::TRIANGLES; 57 | buffer_cube.vertices = 58 | { 59 | {{-1.0, -1.0, 1.0}, {1.0, 0.0, 0.0}}, 60 | {{-1.0, 1.0, 1.0}, {0.0, 1.0, 0.0}}, 61 | {{ 1.0, 1.0, 1.0}, {0.0, 0.0, 1.0}}, 62 | {{ 1.0, -1.0, 1.0}, {1.0, 0.0, 1.0}}, 63 | 64 | {{-1.0, -1.0, -1.0}, {1.0, 0.0, 0.0}}, 65 | {{-1.0, 1.0, -1.0}, {0.0, 1.0, 0.0}}, 66 | {{ 1.0, 1.0, -1.0}, {0.0, 0.0, 1.0}}, 67 | {{ 1.0, -1.0, -1.0}, {1.0, 0.0, 1.0}} 68 | }; 69 | buffer_cube.indices = 70 | { 71 | 2, 1, 0, 72 | 0, 3, 2, 73 | 74 | 4, 5, 6, 75 | 6, 7, 4, 76 | 77 | 0, 1, 5, 78 | 5, 4, 0, 79 | 80 | 6, 2, 3, 81 | 3, 7, 6, 82 | 83 | 6, 5, 1, 84 | 1, 2, 6, 85 | 86 | 0, 4, 7, 87 | 7, 3, 0 88 | }; 89 | 90 | 91 | /*========== OpenGL/GLFW Viewer ========*/ 92 | Window window("Software-Rasterizer Viewer", 1280, 720); 93 | 94 | window.onDraw([&](Window& window, float dt) 95 | { 96 | rasterizer.framebuffer().clear(Vec4(0, 0, 0, 1)); 97 | 98 | static float time = 0.0; 99 | time += dt; 100 | 101 | uniforms.model = Mat4::rotationY(radians(time*20.0f)) * Mat4::rotationX(radians(45.0f)) * Mat4::scale(0.75, 0.75, 0.75); 102 | TIME_MS(rasterizer.draw(program, buffer_cube)); 103 | 104 | window.swap(rasterizer.framebuffer()); 105 | }); 106 | 107 | window.run(); 108 | 109 | return EXIT_SUCCESS; 110 | } 111 | -------------------------------------------------------------------------------- /apps/06_model/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable( 06_model ${CMAKE_CURRENT_SOURCE_DIR}/demo_model.cpp) 2 | target_link_libraries( 06_model PRIVATE rasterizer_static utility ) 3 | 4 | target_compile_features( 06_model PUBLIC cxx_std_20 ) 5 | set_target_properties( 06_model PROPERTIES CXX_EXTENSIONS OFF ) 6 | 7 | add_custom_target( 06_model_copy_assets ALL 8 | COMMAND ${CMAKE_COMMAND} -E copy_directory 9 | ${CMAKE_CURRENT_SOURCE_DIR}/assets 10 | $/assets ) -------------------------------------------------------------------------------- /apps/06_model/assets/sad_toaster/color.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/06_model/assets/sad_toaster/color.png -------------------------------------------------------------------------------- /apps/06_model/assets/sad_toaster/sad_toaster.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'None' 2 | # Material Count: 1 3 | 4 | newmtl Material.001 5 | Ns 225.000000 6 | Ka 1.000000 1.000000 1.000000 7 | Kd 0.800000 0.800000 0.800000 8 | Ks 0.500000 0.500000 0.500000 9 | Ke 0.000000 0.000000 0.000000 10 | Ni 1.450000 11 | d 1.000000 12 | illum 2 13 | map_Kd color.png 14 | -------------------------------------------------------------------------------- /apps/06_model/demo_model.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | struct Vertex 15 | { 16 | Vec3 position; 17 | Vec3 normal; 18 | Vec2 texcoord; 19 | }; 20 | 21 | struct Material 22 | { 23 | Texture map_diffuse; 24 | }; 25 | 26 | /* Mesh definition (Vertex and Material --> see model.h for all possible members) */ 27 | using Mesh = asset::Mesh; 28 | 29 | 30 | struct Varying 31 | { 32 | Vec4 position; 33 | Vec2 uv; 34 | 35 | VARYING( position, uv ); 36 | }; 37 | 38 | struct Uniforms 39 | { 40 | Mat4 model; 41 | Mat4 view; 42 | Mat4 proj; 43 | 44 | struct 45 | { 46 | Sampler diffuse; 47 | } material; 48 | }; 49 | 50 | 51 | int main(int argc, char** argv) 52 | { 53 | Renderer rasterizer(1280, 720); 54 | 55 | /*========== Setup Shader Program ========*/ 56 | Program program; 57 | program.onVertex([](const Uniforms& uniform, const Vertex& in, Varying& out) 58 | { 59 | out.position = uniform.proj * uniform.view * uniform.model * Vec4(in.position, 1.0f); 60 | out.uv = in.texcoord; 61 | }); 62 | 63 | program.onFragment([](const Uniforms& uniform, const Varying& in, Vec4& out) 64 | { 65 | out = texture(uniform.material.diffuse, in.uv) / 255.0f; 66 | }); 67 | 68 | /* model */ 69 | auto model = asset::loadObj("assets/sad_toaster/sad_toaster.obj"); 70 | auto& mesh = model.meshes().front(); 71 | BufferIndexed buffer; 72 | buffer.vertices = mesh.vertices(); 73 | buffer.indices = mesh.materialGroups().front().indices; 74 | 75 | 76 | /* set uniforms */ 77 | auto& uniforms = program.uniforms(); 78 | uniforms.proj = Mat4::perspective(radians(45.0f), 1280.0f/720.0f, 1.0, 7.0); 79 | uniforms.view = Mat4::translation(-Vec3{0, 0.0, 3.5}); 80 | uniforms.material.diffuse = mesh.materialGroups().front().material.map_diffuse; 81 | uniforms.material.diffuse.filter = eFilter::LINEAR; 82 | 83 | /*========== OpenGL/GLFW Viewer ========*/ 84 | Window window("Software-Rasterizer Model", 1280, 720); 85 | 86 | window.onDraw([&](Window& window, float dt) 87 | { 88 | rasterizer.framebuffer().clear(Vec4(0, 0, 0, 1)); 89 | 90 | static float time = 0.0; 91 | time += dt; 92 | 93 | uniforms.model = Mat4::translation(Vec3{0, -0.75, 0}) * Mat4::rotationY(-radians(time*20.0f)); 94 | TIME_MS(rasterizer.draw(program, buffer)); 95 | 96 | window.swap(rasterizer.framebuffer()); 97 | }); 98 | 99 | 100 | window.onKeyboard([&](Window &window, int key, int mod, bool press) 101 | { 102 | if(key == GLFW_KEY_W && press) 103 | { 104 | rasterizer.options().wireframe = !rasterizer.options().wireframe; 105 | } 106 | }); 107 | 108 | window.run(); 109 | 110 | return EXIT_SUCCESS; 111 | } 112 | -------------------------------------------------------------------------------- /apps/07_blinn_phong/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable( 07_blinn_phong ${CMAKE_CURRENT_SOURCE_DIR}/demo_blinn_phong.cpp) 2 | target_link_libraries( 07_blinn_phong PRIVATE rasterizer_static utility ) 3 | 4 | target_compile_features( 07_blinn_phong PUBLIC cxx_std_20 ) 5 | set_target_properties( 07_blinn_phong PROPERTIES CXX_EXTENSIONS OFF ) 6 | 7 | add_custom_target( 07_blinn_phong_copy_asset ALL 8 | COMMAND ${CMAKE_COMMAND} -E copy_directory 9 | ${CMAKE_CURRENT_SOURCE_DIR}/assets 10 | $/assets ) -------------------------------------------------------------------------------- /apps/07_blinn_phong/assets/sphere/sphere.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'None' 2 | # Material Count: 1 3 | 4 | newmtl Default_OBJ 5 | Ns 225.000000 6 | Ka 1.000000 1.000000 1.000000 7 | Kd 0.800000 0.800000 0.800000 8 | Ks 0.500000 0.500000 0.500000 9 | Ke 0.000000 0.000000 0.000000 10 | Ni 1.450000 11 | d 1.000000 12 | illum 2 13 | -------------------------------------------------------------------------------- /apps/07_blinn_phong/demo_blinn_phong.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | struct Vertex 15 | { 16 | Vec3 position; 17 | Vec3 normal; 18 | Vec2 texcoord; 19 | }; 20 | 21 | struct Material 22 | { 23 | float shininess; 24 | Vec3 ambient; 25 | Vec3 diffuse; 26 | Vec3 specular; 27 | }; 28 | 29 | /* Mesh definition (Vertex and Material --> see model.h for all possible members (names must match)) */ 30 | using Mesh = asset::Mesh; 31 | 32 | struct Light 33 | { 34 | Vec3 position; 35 | 36 | Vec3 ambient; 37 | Vec3 color; 38 | }; 39 | 40 | 41 | 42 | struct Varying 43 | { 44 | Vec4 position; 45 | Vec2 uv; 46 | Vec3 normal; 47 | Vec3 world_position; 48 | 49 | VARYING( position, uv, normal, world_position ); 50 | }; 51 | 52 | struct Uniforms 53 | { 54 | Mat4 model; 55 | Mat4 view; 56 | Mat4 proj; 57 | 58 | Vec3 viewPos; 59 | Material material; 60 | Light light; 61 | }; 62 | 63 | Vec3 blinn_phong(const Vec3& lightDir, const Vec3& viewDir, const Vec3& normal, const Vec3& diffuse, const Vec3& specular, float shininess) 64 | { 65 | auto halfwayDir = normalize(lightDir + viewDir); 66 | 67 | float diff = std::max(dot(normal, lightDir), 0.0); 68 | float spec = std::pow(std::max(dot(normal, halfwayDir), 0.0), shininess); 69 | 70 | return (diff * diffuse) + (spec * specular); 71 | } 72 | 73 | int main(int argc, char** argv) 74 | { 75 | Renderer rasterizer(1280, 720); 76 | 77 | /*========== Setup Shader Program ========*/ 78 | Program program; 79 | program.onVertex([](const Uniforms& uniform, const Vertex& in, Varying& out) 80 | { 81 | auto word_pos = uniform.model * Vec4(in.position, 1.0f); 82 | out.position = uniform.proj * uniform.view * word_pos; 83 | out.world_position = Vec3(word_pos); 84 | out.normal = Mat3(uniform.model) * in.normal; 85 | out.uv = in.texcoord; 86 | }); 87 | 88 | program.onFragment([](const Uniforms& uniform, const Varying& in, Vec4& out) 89 | { 90 | auto normal = normalize(in.normal); 91 | auto viewDir = normalize(uniform.viewPos - in.world_position); 92 | auto lightDir = normalize(uniform.light.position - in.world_position); 93 | 94 | Vec3 illuminance = uniform.light.ambient * uniform.material.ambient * uniform.material.diffuse; 95 | illuminance += uniform.light.color 96 | * blinn_phong(lightDir, viewDir, normal, uniform.material.diffuse, uniform.material.specular, uniform.material.shininess); 97 | 98 | out = Vec4(illuminance, 1.0); 99 | }); 100 | 101 | /* load model */ 102 | auto model = asset::loadObj("assets/sphere/sphere.obj"); 103 | auto& mesh = model.meshes().front(); 104 | 105 | /* create draw buffer */ 106 | BufferIndexed buffer; 107 | buffer.vertices = mesh.vertices(); 108 | buffer.indices = mesh.materialGroups().front().indices; 109 | 110 | /* set uniforms */ 111 | auto& uniforms = program.uniforms(); 112 | uniforms.model = Mat4::identity(); 113 | uniforms.proj = Mat4::perspective(radians(45.0f), 1280.0f/720.0f, 1.0, 7.0); 114 | uniforms.view = Mat4::translation(-Vec3{0, 0.0, 3.5}); 115 | uniforms.viewPos = Vec3(0, 0.0, 3.5); 116 | 117 | uniforms.material = mesh.materialGroups().front().material; 118 | 119 | uniforms.light.position = Vec3(3, 2, 3); 120 | uniforms.light.color = Vec3(1, 1, 1); 121 | uniforms.light.ambient = Vec3(0.2, 0.2, 0.2); 122 | 123 | 124 | /*========== OpenGL/GLFW Viewer ========*/ 125 | Window window("Software-Rasterizer Blinn Phong", 1280, 720); 126 | 127 | window.onDraw([&](Window& window, float dt) 128 | { 129 | rasterizer.framebuffer().clear(Vec4(0, 0, 0, 1)); 130 | 131 | uniforms.light.position = Mat3::rotationY(-radians(dt*20.0f)) * uniforms.light.position; 132 | TIME_MS(rasterizer.draw(program, buffer)); 133 | 134 | window.swap(rasterizer.framebuffer()); 135 | }); 136 | 137 | window.run(); 138 | 139 | return EXIT_SUCCESS; 140 | } 141 | -------------------------------------------------------------------------------- /apps/08_normal_mapping/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable( 08_normal_mapping ${CMAKE_CURRENT_SOURCE_DIR}/demo_normal_mapping.cpp) 2 | target_link_libraries( 08_normal_mapping PRIVATE rasterizer_static utility ) 3 | 4 | target_compile_features( 08_normal_mapping PUBLIC cxx_std_20 ) 5 | set_target_properties( 08_normal_mapping PROPERTIES CXX_EXTENSIONS OFF ) 6 | 7 | add_custom_target( 08_normal_mapping_copy_assets ALL 8 | COMMAND ${CMAKE_COMMAND} -E copy_directory 9 | ${CMAKE_CURRENT_SOURCE_DIR}/assets 10 | $/assets ) 11 | -------------------------------------------------------------------------------- /apps/08_normal_mapping/assets/cartridge/Material.001_baseColor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/08_normal_mapping/assets/cartridge/Material.001_baseColor.png -------------------------------------------------------------------------------- /apps/08_normal_mapping/assets/cartridge/Material.001_metallicRoughness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/08_normal_mapping/assets/cartridge/Material.001_metallicRoughness.png -------------------------------------------------------------------------------- /apps/08_normal_mapping/assets/cartridge/Material.001_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/08_normal_mapping/assets/cartridge/Material.001_normal.png -------------------------------------------------------------------------------- /apps/08_normal_mapping/assets/cartridge/cartridge.mtl: -------------------------------------------------------------------------------- 1 | # Blender 3.3.1 MTL File: 'None' 2 | # www.blender.org 3 | 4 | newmtl Material.001 5 | Ns 250.000000 6 | Ka 1.000000 1.000000 1.000000 7 | Ks 0.500000 0.500000 0.500000 8 | Ke 0.000000 0.000000 0.000000 9 | Ni 1.500000 10 | d 1.000000 11 | illum 2 12 | map_Kd Material.001_baseColor.png 13 | map_Bump -bm 1.000000 Material.001_normal.png 14 | -------------------------------------------------------------------------------- /apps/08_normal_mapping/assets/cartridge/license.txt: -------------------------------------------------------------------------------- 1 | Model Information: 2 | * title: Gameboy Cartridge 3 | * source: https://sketchfab.com/3d-models/gameboy-cartridge-7c0160c8097a43e0a5e146bf4d7e01a1 4 | * author: Karolina D (https://sketchfab.com/KarolinaArts) 5 | 6 | Model License: 7 | * license type: CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/) 8 | * requirements: Author must be credited. Commercial use is allowed. 9 | 10 | If you use this 3D model in your project be sure to copy paste this credit wherever you share it: 11 | This work is based on "Gameboy Cartridge" (https://sketchfab.com/3d-models/gameboy-cartridge-7c0160c8097a43e0a5e146bf4d7e01a1) by Karolina D (https://sketchfab.com/KarolinaArts) licensed under CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/) -------------------------------------------------------------------------------- /apps/09_shadow_mapping/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable( 09_shadow_mapping ${CMAKE_CURRENT_SOURCE_DIR}/demo_shadow_mapping.cpp) 2 | target_link_libraries( 09_shadow_mapping PRIVATE rasterizer_static utility ) 3 | 4 | target_compile_features( 09_shadow_mapping PUBLIC cxx_std_20 ) 5 | set_target_properties( 09_shadow_mapping PROPERTIES CXX_EXTENSIONS OFF ) 6 | 7 | add_custom_target( 09_shadow_mapping_copy_asset ALL 8 | COMMAND ${CMAKE_COMMAND} -E copy_directory 9 | ${CMAKE_CURRENT_SOURCE_DIR}/assets 10 | $/assets ) -------------------------------------------------------------------------------- /apps/09_shadow_mapping/assets/low_poly_house/license.txt: -------------------------------------------------------------------------------- 1 | This model was modified by Nikolaus Rauch (stripped of detailed geometry and reduced material properties). 2 | 3 | Model Information: 4 | * title: low poly house 5 | * source: https://sketchfab.com/3d-models/low-poly-house-02635c7c191848699e88085c2ab27538 6 | * author: cofitelle (https://sketchfab.com/cofitelle) 7 | 8 | Model License: 9 | * license type: CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/) 10 | * requirements: Author must be credited. Commercial use is allowed. 11 | 12 | If you use this 3D model in your project be sure to copy paste this credit wherever you share it: 13 | This work is based on "low poly house" (https://sketchfab.com/3d-models/low-poly-house-02635c7c191848699e88085c2ab27538) by cofitelle (https://sketchfab.com/cofitelle) licensed under CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/) -------------------------------------------------------------------------------- /apps/09_shadow_mapping/assets/low_poly_house/low_poly_house.mtl: -------------------------------------------------------------------------------- 1 | # Blender 3.3.1 MTL File: 'None' 2 | # www.blender.org 3 | 4 | newmtl blue 5 | Ns 21.839581 6 | Ka 1.000000 1.000000 1.000000 7 | Kd 0.043993 0.017173 0.911793 8 | Ks 0.500000 0.500000 0.500000 9 | Ke 0.000000 0.000000 0.000000 10 | Ni 1.500000 11 | d 1.000000 12 | illum 2 13 | 14 | newmtl brown 15 | Ns 1.068296 16 | Ka 1.000000 1.000000 1.000000 17 | Kd 0.233016 0.134060 0.010414 18 | Ks 0.500000 0.500000 0.500000 19 | Ke 0.000000 0.000000 0.000000 20 | Ni 1.500000 21 | d 1.000000 22 | illum 2 23 | 24 | newmtl green 25 | Ns 18.512468 26 | Ka 1.000000 1.000000 1.000000 27 | Kd 0.215630 0.902280 0.116912 28 | Ks 0.500000 0.500000 0.500000 29 | Ke 0.000000 0.000000 0.000000 30 | Ni 1.500000 31 | d 1.000000 32 | illum 2 33 | 34 | newmtl grey 35 | Ns 250.000000 36 | Ka 1.000000 1.000000 1.000000 37 | Kd 0.800000 0.800000 0.800000 38 | Ks 0.500000 0.500000 0.500000 39 | Ke 0.000000 0.000000 0.000000 40 | Ni 1.450000 41 | d 1.000000 42 | illum 2 43 | 44 | newmtl light_brown 45 | Ns 16.638357 46 | Ka 1.000000 1.000000 1.000000 47 | Kd 0.950408 0.631874 0.431054 48 | Ks 0.500000 0.500000 0.500000 49 | Ke 0.000000 0.000000 0.000000 50 | Ni 1.500000 51 | d 1.000000 52 | illum 2 53 | 54 | newmtl orange 55 | Ns 2.229474 56 | Ka 1.000000 1.000000 1.000000 57 | Kd 0.575719 0.213282 0.002682 58 | Ks 0.500000 0.500000 0.500000 59 | Ke 0.000000 0.000000 0.000000 60 | Ni 1.500000 61 | d 1.000000 62 | illum 2 63 | 64 | newmtl reddishpink 65 | Ns 7.080754 66 | Ka 1.000000 1.000000 1.000000 67 | Kd 1.000000 0.207922 0.207922 68 | Ks 0.500000 0.500000 0.500000 69 | Ke 0.000000 0.000000 0.000000 70 | Ni 1.500000 71 | d 1.000000 72 | illum 2 73 | -------------------------------------------------------------------------------- /apps/10_ambient_occlussion/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable( 10_ssao ${CMAKE_CURRENT_SOURCE_DIR}/demo_ssao.cpp) 2 | target_link_libraries( 10_ssao PRIVATE rasterizer_static utility ) 3 | 4 | target_compile_features( 10_ssao PUBLIC cxx_std_20 ) 5 | set_target_properties( 10_ssao PROPERTIES CXX_EXTENSIONS OFF ) 6 | 7 | add_custom_target( 10_ssao_copy_assets ALL 8 | COMMAND ${CMAKE_COMMAND} -E copy_directory 9 | ${CMAKE_CURRENT_SOURCE_DIR}/assets 10 | $/assets ) 11 | -------------------------------------------------------------------------------- /apps/10_ambient_occlussion/assets/firered_room/fireRed_material_baseColor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/10_ambient_occlussion/assets/firered_room/fireRed_material_baseColor.png -------------------------------------------------------------------------------- /apps/10_ambient_occlussion/assets/firered_room/license.txt: -------------------------------------------------------------------------------- 1 | Model Information: 2 | * title: Pokemon FireRed - Player's Room 3 | * source: https://sketchfab.com/3d-models/pokemon-firered-players-room-b23b6b253207463c97db2a7092adff74 4 | * author: Wesai (https://sketchfab.com/Wesai) 5 | 6 | Model License: 7 | * license type: CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/) 8 | * requirements: Author must be credited. Commercial use is allowed. 9 | 10 | If you use this 3D model in your project be sure to copy paste this credit wherever you share it: 11 | This work is based on "Pokemon FireRed - Player's Room" (https://sketchfab.com/3d-models/pokemon-firered-players-room-b23b6b253207463c97db2a7092adff74) by Wesai (https://sketchfab.com/Wesai) licensed under CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/) -------------------------------------------------------------------------------- /apps/10_ambient_occlussion/assets/firered_room/room.mtl: -------------------------------------------------------------------------------- 1 | # Blender 3.3.1 MTL File: 'None' 2 | # www.blender.org 3 | 4 | newmtl fireRed_material 5 | Ns 360.000000 6 | Ka 1.000000 1.000000 1.000000 7 | Kd 0.800000 0.800000 0.800000 8 | Ks 0.500000 0.500000 0.500000 9 | Ke 0.000000 0.000000 0.000000 10 | Ni 1.000000 11 | d 1.000000 12 | illum 2 13 | map_Kd fireRed_material_baseColor.png -------------------------------------------------------------------------------- /apps/11_physically_based/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable( 11_pbr ${CMAKE_CURRENT_SOURCE_DIR}/demo_pbr.cpp) 2 | target_link_libraries( 11_pbr PRIVATE rasterizer_static utility ) 3 | 4 | target_compile_features( 11_pbr PUBLIC cxx_std_20 ) 5 | set_target_properties( 11_pbr PROPERTIES CXX_EXTENSIONS OFF ) 6 | 7 | add_custom_target( 11_pbr_copy_assets ALL 8 | COMMAND ${CMAKE_COMMAND} -E copy_directory 9 | ${CMAKE_CURRENT_SOURCE_DIR}/assets 10 | $/assets ) 11 | 12 | 13 | 14 | add_executable( 11_pbr_precompute ${CMAKE_CURRENT_SOURCE_DIR}/pbr_precompute.cpp) 15 | target_link_libraries( 11_pbr_precompute PRIVATE rasterizer_static utility ) 16 | 17 | target_compile_features( 11_pbr_precompute PUBLIC cxx_std_20 ) 18 | set_target_properties( 11_pbr_precompute PROPERTIES CXX_EXTENSIONS OFF ) 19 | -------------------------------------------------------------------------------- /apps/11_physically_based/assets/camera/camera.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'Camera_01_1k.blend' 2 | # Material Count: 2 3 | 4 | newmtl material_1 5 | Ns 250.000000 6 | Ka 1.000000 1.000000 1.000000 7 | Kd 0.800000 0.800000 0.800000 8 | Ks 0.500000 0.500000 0.500000 9 | Ke 0.000000 0.000000 0.000000 10 | Ni 1.500000 11 | d 1.000000 12 | illum 2 13 | map_Kd textures\\lambert1_baseColor.png 14 | map_Pm textures\\lambert1_metallicRoughness.png 15 | norm textures\\lambert1_normal.png 16 | 17 | newmtl material_2 18 | Ns 250.000000 19 | Ka 1.000000 1.000000 1.000000 20 | Kd 0.015876 0.015876 0.015876 21 | Ks 0.500000 0.500000 0.500000 22 | Ke 0.000000 0.000000 0.000000 23 | Ni 1.500000 24 | d 0.506364 25 | illum 9 26 | -------------------------------------------------------------------------------- /apps/11_physically_based/assets/camera/license.txt: -------------------------------------------------------------------------------- 1 | Model Information: 2 | * title: DAE - Bilora Bella 46 Camera - Game Ready Asset 3 | * source: https://sketchfab.com/3d-models/dae-bilora-bella-46-camera-game-ready-asset-eeb9d9f0627f4783b5d16a8732f0d1a4 4 | * author: Martijn Vaes (https://sketchfab.com/MartijnVaes) 5 | 6 | Model License: 7 | * license type: CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/) 8 | * requirements: Author must be credited. Commercial use is allowed. 9 | 10 | If you use this 3D model in your project be sure to copy paste this credit wherever you share it: 11 | This work is based on "DAE - Bilora Bella 46 Camera - Game Ready Asset" (https://sketchfab.com/3d-models/dae-bilora-bella-46-camera-game-ready-asset-eeb9d9f0627f4783b5d16a8732f0d1a4) by Martijn Vaes (https://sketchfab.com/MartijnVaes) licensed under CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/) 12 | 13 | obj, mat file created by Niko -------------------------------------------------------------------------------- /apps/11_physically_based/assets/camera/textures/lambert1_baseColor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/11_physically_based/assets/camera/textures/lambert1_baseColor.png -------------------------------------------------------------------------------- /apps/11_physically_based/assets/camera/textures/lambert1_metallicRoughness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/11_physically_based/assets/camera/textures/lambert1_metallicRoughness.png -------------------------------------------------------------------------------- /apps/11_physically_based/assets/camera/textures/lambert1_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/11_physically_based/assets/camera/textures/lambert1_normal.png -------------------------------------------------------------------------------- /apps/11_physically_based/assets/camera/textures/standardSurface2_metallicRoughness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/11_physically_based/assets/camera/textures/standardSurface2_metallicRoughness.png -------------------------------------------------------------------------------- /apps/11_physically_based/assets/drakefire/drakefire.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'None' 2 | # Material Count: 1 3 | 4 | newmtl base 5 | Ns 250.000000 6 | Ka 1.000000 1.000000 1.000000 7 | Kd 0.800000 0.800000 0.800000 8 | Ks 0.500000 0.500000 0.500000 9 | Ke 0.000000 0.000000 0.000000 10 | Ni 1.500000 11 | d 1.000000 12 | illum 2 13 | norm textures\\base_normal.jpeg 14 | map_Kd textures\\base_baseColor.jpeg 15 | map_Pm textures\\base_metallicRoughness.png -------------------------------------------------------------------------------- /apps/11_physically_based/assets/drakefire/license.txt: -------------------------------------------------------------------------------- 1 | Model Information: 2 | * title: Drakefire Pistol 3 | * source: https://sketchfab.com/3d-models/drakefire-pistol-bee02e85f22d4eaaa3c0144f11204843 4 | * author: Teliri (https://sketchfab.com/Teliri) 5 | 6 | Model License: 7 | * license type: CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/) 8 | * requirements: Author must be credited. Commercial use is allowed. 9 | 10 | If you use this 3D model in your project be sure to copy paste this credit wherever you share it: 11 | This work is based on "Drakefire Pistol" (https://sketchfab.com/3d-models/drakefire-pistol-bee02e85f22d4eaaa3c0144f11204843) by Teliri (https://sketchfab.com/Teliri) licensed under CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/) 12 | 13 | obj, mat file created by Niko -------------------------------------------------------------------------------- /apps/11_physically_based/assets/drakefire/textures/base_baseColor.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/11_physically_based/assets/drakefire/textures/base_baseColor.jpeg -------------------------------------------------------------------------------- /apps/11_physically_based/assets/drakefire/textures/base_metallicRoughness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/11_physically_based/assets/drakefire/textures/base_metallicRoughness.png -------------------------------------------------------------------------------- /apps/11_physically_based/assets/drakefire/textures/base_normal.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/11_physically_based/assets/drakefire/textures/base_normal.jpeg -------------------------------------------------------------------------------- /apps/11_physically_based/assets/pbr/0_precomputed_radiance.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/11_physically_based/assets/pbr/0_precomputed_radiance.hdr -------------------------------------------------------------------------------- /apps/11_physically_based/assets/pbr/10_precomputed_radiance.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/11_physically_based/assets/pbr/10_precomputed_radiance.hdr -------------------------------------------------------------------------------- /apps/11_physically_based/assets/pbr/1_precomputed_radiance.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/11_physically_based/assets/pbr/1_precomputed_radiance.hdr -------------------------------------------------------------------------------- /apps/11_physically_based/assets/pbr/2_precomputed_radiance.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/11_physically_based/assets/pbr/2_precomputed_radiance.hdr -------------------------------------------------------------------------------- /apps/11_physically_based/assets/pbr/3_precomputed_radiance.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/11_physically_based/assets/pbr/3_precomputed_radiance.hdr -------------------------------------------------------------------------------- /apps/11_physically_based/assets/pbr/4_precomputed_radiance.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/11_physically_based/assets/pbr/4_precomputed_radiance.hdr -------------------------------------------------------------------------------- /apps/11_physically_based/assets/pbr/5_precomputed_radiance.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/11_physically_based/assets/pbr/5_precomputed_radiance.hdr -------------------------------------------------------------------------------- /apps/11_physically_based/assets/pbr/6_precomputed_radiance.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/11_physically_based/assets/pbr/6_precomputed_radiance.hdr -------------------------------------------------------------------------------- /apps/11_physically_based/assets/pbr/7_precomputed_radiance.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/11_physically_based/assets/pbr/7_precomputed_radiance.hdr -------------------------------------------------------------------------------- /apps/11_physically_based/assets/pbr/8_precomputed_radiance.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/11_physically_based/assets/pbr/8_precomputed_radiance.hdr -------------------------------------------------------------------------------- /apps/11_physically_based/assets/pbr/9_precomputed_radiance.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/11_physically_based/assets/pbr/9_precomputed_radiance.hdr -------------------------------------------------------------------------------- /apps/11_physically_based/assets/pbr/precomputed_brdf.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/11_physically_based/assets/pbr/precomputed_brdf.hdr -------------------------------------------------------------------------------- /apps/11_physically_based/assets/pbr/precomputed_irradiance.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/11_physically_based/assets/pbr/precomputed_irradiance.hdr -------------------------------------------------------------------------------- /apps/11_physically_based/assets/rural_asphalt_road_1k.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/11_physically_based/assets/rural_asphalt_road_1k.hdr -------------------------------------------------------------------------------- /apps/12_cel_shading/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable( 12_cel_shading ${CMAKE_CURRENT_SOURCE_DIR}/demo_cel_shading.cpp) 2 | target_link_libraries( 12_cel_shading PRIVATE rasterizer_static utility ) 3 | 4 | target_compile_features( 12_cel_shading PUBLIC cxx_std_20 ) 5 | set_target_properties( 12_cel_shading PROPERTIES CXX_EXTENSIONS OFF ) 6 | 7 | add_custom_target( 12_cel_shading_copy_assets ALL 8 | COMMAND ${CMAKE_COMMAND} -E copy_directory 9 | ${CMAKE_CURRENT_SOURCE_DIR}/assets 10 | $/assets ) -------------------------------------------------------------------------------- /apps/12_cel_shading/assets/bird/bird.mtl: -------------------------------------------------------------------------------- 1 | # Blender 4.0.2 MTL File: 'None' 2 | # www.blender.org 3 | 4 | newmtl MAT_Bird 5 | Ns 250.000000 6 | Ka 1.000000 1.000000 1.000000 7 | Ks 0.500000 0.500000 0.500000 8 | Ke 0.000000 0.000000 0.000000 9 | Ni 1.500000 10 | d 1.000000 11 | illum 2 12 | map_Kd textures/MAT_Bird_baseColor.png 13 | map_Bump textures/MAT_Bird_normal.png 14 | 15 | newmtl MAT_branch 16 | Ns 250.000000 17 | Ka 1.000000 1.000000 1.000000 18 | Ks 0.500000 0.500000 0.500000 19 | Ke 0.000000 0.000000 0.000000 20 | Ni 1.500000 21 | d 1.000000 22 | illum 2 23 | map_Kd textures/MAT_branch_baseColor.png 24 | map_Bump textures/MAT_branch_normal.png 25 | -------------------------------------------------------------------------------- /apps/12_cel_shading/assets/bird/license.txt: -------------------------------------------------------------------------------- 1 | Model Information: 2 | * title: Bird 3 | * source: https://sketchfab.com/3d-models/bird-e63479b07d8c4ae6a69b34247d572299 4 | * author: Václav Pleticha (https://sketchfab.com/klidas8) 5 | 6 | Model License: 7 | * license type: CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/) 8 | * requirements: Author must be credited. Commercial use is allowed. 9 | 10 | If you use this 3D model in your project be sure to copy paste this credit wherever you share it: 11 | This work is based on "Bird" (https://sketchfab.com/3d-models/bird-e63479b07d8c4ae6a69b34247d572299) by Václav Pleticha (https://sketchfab.com/klidas8) licensed under CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/) -------------------------------------------------------------------------------- /apps/12_cel_shading/assets/bird/textures/MAT_Bird_baseColor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/12_cel_shading/assets/bird/textures/MAT_Bird_baseColor.png -------------------------------------------------------------------------------- /apps/12_cel_shading/assets/bird/textures/MAT_Bird_metallicRoughness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/12_cel_shading/assets/bird/textures/MAT_Bird_metallicRoughness.png -------------------------------------------------------------------------------- /apps/12_cel_shading/assets/bird/textures/MAT_Bird_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/12_cel_shading/assets/bird/textures/MAT_Bird_normal.png -------------------------------------------------------------------------------- /apps/12_cel_shading/assets/bird/textures/MAT_branch_baseColor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/12_cel_shading/assets/bird/textures/MAT_branch_baseColor.png -------------------------------------------------------------------------------- /apps/12_cel_shading/assets/bird/textures/MAT_branch_metallicRoughness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/12_cel_shading/assets/bird/textures/MAT_branch_metallicRoughness.png -------------------------------------------------------------------------------- /apps/12_cel_shading/assets/bird/textures/MAT_branch_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/apps/12_cel_shading/assets/bird/textures/MAT_branch_normal.png -------------------------------------------------------------------------------- /apps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(utility) 2 | 3 | add_subdirectory(00_triangle) 4 | add_subdirectory(01_indexed_plane) 5 | add_subdirectory(02_depth_buffer) 6 | add_subdirectory(03_texture) 7 | add_subdirectory(04_framebuffer) 8 | add_subdirectory(05_viewer) 9 | add_subdirectory(06_model) 10 | add_subdirectory(07_blinn_phong) 11 | add_subdirectory(08_normal_mapping) 12 | add_subdirectory(09_shadow_mapping) 13 | add_subdirectory(10_ambient_occlussion) 14 | add_subdirectory(11_physically_based) 15 | add_subdirectory(12_cel_shading) 16 | -------------------------------------------------------------------------------- /apps/utility/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set( UTILITY_SRC 2 | "${CMAKE_CURRENT_SOURCE_DIR}/gl_window.cpp" 3 | ) 4 | 5 | set( UTILITY_HDR 6 | "${CMAKE_CURRENT_SOURCE_DIR}/gl_window.h" 7 | 8 | "${CMAKE_CURRENT_SOURCE_DIR}/detail/shader.h" 9 | "${CMAKE_CURRENT_SOURCE_DIR}/detail/mesh.h" 10 | "${CMAKE_CURRENT_SOURCE_DIR}/detail/texture.h" 11 | 12 | "${CMAKE_CURRENT_SOURCE_DIR}/timing.h" 13 | 14 | "${CMAKE_CURRENT_SOURCE_DIR}/model.h" 15 | "${CMAKE_CURRENT_SOURCE_DIR}/objload.h" 16 | ) 17 | 18 | source_group( TREE ${CMAKE_CURRENT_SOURCE_DIR} 19 | FILES ${UTILITY_SRC} ${UTILITY_HDR} ) 20 | 21 | add_library( utility STATIC ${UTILITY_SRC} ${UTILITY_HDR} ) 22 | target_link_libraries( utility PUBLIC rasterizer_static tiny_obj glfw glad_static OpenGL::GL ) 23 | target_include_directories( utility PUBLIC 24 | $ 25 | ) 26 | -------------------------------------------------------------------------------- /apps/utility/detail/mesh.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | enum eDataIdx { Position = 0, UV = 1 }; 9 | 10 | struct GLVertex 11 | { 12 | GLfloat pos[3]; 13 | GLfloat uv[2]; 14 | }; 15 | 16 | std::pair meshCreate(const std::vector& vertices) 17 | { 18 | GLuint vao = 0, vbo = 0; 19 | 20 | glGenVertexArrays(1, &vao); 21 | glGenBuffers(1, &vbo); 22 | 23 | glBindVertexArray(vao); 24 | { 25 | glBindBuffer(GL_ARRAY_BUFFER, vbo); 26 | glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(GLVertex), vertices.data(), GL_STATIC_DRAW); 27 | 28 | glEnableVertexAttribArray(eDataIdx::Position); 29 | glEnableVertexAttribArray(eDataIdx::UV); 30 | glVertexAttribPointer(eDataIdx::Position, 3, GL_FLOAT, GL_FALSE, sizeof(GLVertex), (void*) offsetof(GLVertex, pos)); 31 | glVertexAttribPointer(eDataIdx::UV, 2, GL_FLOAT, GL_FALSE, sizeof(GLVertex), (void*) offsetof(GLVertex, uv)); 32 | } 33 | 34 | glBindVertexArray(0); 35 | glBindBuffer(GL_ARRAY_BUFFER, 0); 36 | 37 | return std::make_pair(vao, vbo); 38 | } 39 | -------------------------------------------------------------------------------- /apps/utility/detail/shader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace detail 10 | { 11 | void compile(GLuint handle, const char* source, const int size) 12 | { 13 | GLint compileResult = 0; 14 | 15 | glShaderSource(handle, 1, &source, &size); 16 | glCompileShader(handle); 17 | glGetShaderiv(handle, GL_COMPILE_STATUS, &compileResult); 18 | 19 | if(compileResult == GL_FALSE) 20 | { 21 | GLint infoLength = 0; 22 | std::string shaderLog; 23 | 24 | glGetShaderiv(handle, GL_INFO_LOG_LENGTH, &infoLength); 25 | shaderLog.resize(static_cast(infoLength)); 26 | glGetShaderInfoLog(handle, infoLength, nullptr, &shaderLog[0]); 27 | 28 | std::cerr << shaderLog << std::endl; 29 | std::cerr.flush(); 30 | 31 | throw std::runtime_error("[Shader] ERROR compiling shader:\n" + shaderLog); 32 | } 33 | } 34 | 35 | void link(GLuint handle) 36 | { 37 | glLinkProgram(handle); 38 | 39 | GLint result; 40 | glGetProgramiv(handle, GL_LINK_STATUS, &result); 41 | 42 | if(result == GL_FALSE) 43 | { 44 | GLint messageLength = 0; 45 | std::string programLog; 46 | 47 | glGetProgramiv(handle, GL_INFO_LOG_LENGTH, &messageLength); 48 | 49 | if(messageLength > 0) 50 | { 51 | programLog.resize(static_cast(messageLength)); 52 | glGetProgramInfoLog(handle, messageLength, nullptr, &programLog[0]); 53 | 54 | std::cerr << programLog << std::endl; 55 | std::cerr.flush(); 56 | } 57 | 58 | throw std::runtime_error((std::string("[Shader] ERROR link shaderprogram: \n") + programLog)); 59 | } 60 | } 61 | } 62 | 63 | GLuint shaderCreate(const std::string &vertexSource, const std::string &fragmentSource) 64 | { 65 | GLuint program = glCreateProgram(); 66 | GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER); 67 | GLuint frag_shader = glCreateShader(GL_FRAGMENT_SHADER); 68 | 69 | if(!program || !vertex_shader || !frag_shader) 70 | { 71 | throw std::runtime_error("[Shader] Couldn't create shader program!"); 72 | } 73 | 74 | detail::compile(vertex_shader, vertexSource.c_str(), vertexSource.size()); 75 | glAttachShader(program, vertex_shader); 76 | 77 | detail::compile(frag_shader, fragmentSource.c_str(), fragmentSource.size()); 78 | glAttachShader(program, frag_shader); 79 | 80 | detail::link(program); 81 | 82 | glDetachShader(program, vertex_shader); 83 | glDetachShader(program, frag_shader); 84 | glDeleteShader(vertex_shader); 85 | glDeleteShader(frag_shader); 86 | 87 | return program; 88 | } 89 | -------------------------------------------------------------------------------- /apps/utility/detail/texture.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | GLuint textureCreate(unsigned int width, unsigned int height) 7 | { 8 | /* upload data */ 9 | GLuint id = 0; 10 | glGenTextures(1, &id); 11 | glBindTexture(GL_TEXTURE_2D, id); 12 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); 13 | 14 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 15 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 16 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 17 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 18 | 19 | glBindTexture(GL_TEXTURE_2D, 0); 20 | 21 | return id; 22 | } 23 | -------------------------------------------------------------------------------- /apps/utility/gl_window.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | struct Window 12 | { 13 | typedef std::function KeyboardCallback; 14 | typedef std::function MouseCallback; 15 | typedef std::function DrawCallback; 16 | typedef std::function UpdateCallback; 17 | typedef std::function ResizeCallback; 18 | 19 | 20 | Window(const std::string &title, unsigned int width, unsigned int height); 21 | Window(const std::string &title, unsigned int width, unsigned int height, unsigned int fb_width, unsigned int fb_height); 22 | ~Window(); 23 | 24 | void onKeyboard(const KeyboardCallback& cb); 25 | void onMouse(const MouseCallback& cb); 26 | void onDraw(const DrawCallback& cb); 27 | void onUpdate(const UpdateCallback& cb); 28 | void onResize(const ResizeCallback& cb); 29 | 30 | void swap(DefaultFramebuffer& framebuffer); 31 | 32 | void run(); 33 | 34 | Vec2 mousePosition() const; 35 | 36 | private: 37 | GLFWwindow* m_window; 38 | 39 | GLuint m_program; 40 | GLuint m_quad_vao; 41 | GLuint m_quad_vbo; 42 | GLuint m_texture; 43 | 44 | KeyboardCallback m_keyboard_cb; 45 | MouseCallback m_mouse_cb; 46 | DrawCallback m_draw_cb; 47 | UpdateCallback m_update_cb; 48 | ResizeCallback m_resize_cb; 49 | 50 | struct 51 | { 52 | float accumTime; 53 | unsigned int frames; 54 | float fps; 55 | } m_fps_counter; 56 | 57 | struct 58 | { 59 | Vec2 mousePosition; 60 | } m_input; 61 | 62 | friend void key_callback(GLFWwindow* handle, int key, int scancode, int action, int mods); 63 | friend void window_resize_callback(GLFWwindow* handle, int width, int height); 64 | friend void window_mouse_position(GLFWwindow* handle, double x, double y); 65 | friend void window_mouse_button(GLFWwindow* handle, int button, int action, int mods); 66 | }; 67 | -------------------------------------------------------------------------------- /apps/utility/timing.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace profile 7 | { 8 | 9 | typedef std::conditional::type HighResClock; 10 | typedef HighResClock::time_point TimePoint; 11 | typedef HighResClock::duration Time; 12 | 13 | 14 | typedef std::chrono::nanoseconds NanoSeconds; 15 | typedef std::chrono::microseconds MicroSeconds; 16 | typedef std::chrono::milliseconds MilliSeconds; 17 | typedef std::chrono::seconds Seconds; 18 | 19 | template 20 | double time_cast(const Time& time) 21 | { 22 | return std::chrono::duration_cast(time).count(); 23 | } 24 | 25 | template<> 26 | double time_cast(const Time& t) 27 | { 28 | return std::chrono::duration_cast(t).count(); 29 | } 30 | 31 | template<> 32 | double time_cast(const Time& t) 33 | { 34 | return std::chrono::duration_cast(t).count(); 35 | } 36 | 37 | template<> 38 | double time_cast(const Time& t) 39 | { 40 | return std::chrono::duration>(t).count(); 41 | } 42 | 43 | template<> 44 | double time_cast(const Time& t) 45 | { 46 | return std::chrono::duration>(t).count(); 47 | } 48 | 49 | } 50 | 51 | #define TIME_MS(func) { auto start = profile::HighResClock::now(); func; auto end = profile::HighResClock::now(); std::cout << profile::time_cast(end - start) << std::endl; } 52 | #define TIME_NS(func) { auto start = profile::HighResClock::now(); func; auto end = profile::HighResClock::now(); std::cout << profile::time_cast(end - start) << std::endl; } 53 | -------------------------------------------------------------------------------- /external/glad/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(GLAD_HDR 2 | "${CMAKE_CURRENT_SOURCE_DIR}/include/glad/glad.h" 3 | "${CMAKE_CURRENT_SOURCE_DIR}/include/KHR/khrplatform.h" 4 | ) 5 | 6 | set(GLAD_SRC 7 | "${CMAKE_CURRENT_SOURCE_DIR}/src/glad.cpp" 8 | ) 9 | 10 | source_group( TREE ${CMAKE_CURRENT_SOURCE_DIR} 11 | FILES ${GLAD_SRC} ${GLAD_HDR} ) 12 | 13 | add_library(glad_static STATIC ${GLAD_SRC} ${GLAD_HDR} ) 14 | target_include_directories( glad_static PUBLIC 15 | $ 16 | ) 17 | 18 | target_compile_features( glad_static PUBLIC cxx_std_17 ) 19 | set_target_properties( glad_static PROPERTIES CXX_EXTENSIONS OFF ) 20 | -------------------------------------------------------------------------------- /external/glfw/.appveyor.yml: -------------------------------------------------------------------------------- 1 | branches: 2 | only: 3 | - ci 4 | - master 5 | skip_tags: true 6 | environment: 7 | matrix: 8 | - BUILD_SHARED_LIBS: ON 9 | - BUILD_SHARED_LIBS: OFF 10 | matrix: 11 | fast_finish: true 12 | build_script: 13 | - mkdir build 14 | - cd build 15 | - cmake -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% .. 16 | - cmake --build . 17 | notifications: 18 | - provider: Email 19 | to: 20 | - ci@glfw.org 21 | - on_build_failure: true 22 | - on_build_success: false 23 | -------------------------------------------------------------------------------- /external/glfw/.gitattributes: -------------------------------------------------------------------------------- 1 | *.m linguist-language=Objective-C 2 | -------------------------------------------------------------------------------- /external/glfw/.gitignore: -------------------------------------------------------------------------------- 1 | # External junk 2 | .DS_Store 3 | _ReSharper* 4 | *.opensdf 5 | *.sdf 6 | *.suo 7 | *.dir 8 | *.vcxproj* 9 | *.sln 10 | Win32 11 | x64 12 | Debug 13 | Release 14 | MinSizeRel 15 | RelWithDebInfo 16 | *.xcodeproj 17 | 18 | # CMake files 19 | Makefile 20 | CMakeCache.txt 21 | CMakeFiles 22 | CMakeScripts 23 | cmake_install.cmake 24 | cmake_uninstall.cmake 25 | 26 | # Generated files 27 | docs/Doxyfile 28 | docs/html 29 | docs/warnings.txt 30 | docs/doxygen_sqlite3.db 31 | src/glfw_config.h 32 | src/glfw3.pc 33 | src/glfw3Config.cmake 34 | src/glfw3ConfigVersion.cmake 35 | src/wayland-pointer-constraints-unstable-v1-client-protocol.h 36 | src/wayland-pointer-constraints-unstable-v1-protocol.c 37 | src/wayland-relative-pointer-unstable-v1-client-protocol.h 38 | src/wayland-relative-pointer-unstable-v1-protocol.c 39 | 40 | # Compiled binaries 41 | src/libglfw.so 42 | src/libglfw.so.3 43 | src/libglfw.so.3.3 44 | src/libglfw.dylib 45 | src/libglfw.dylib 46 | src/libglfw.3.dylib 47 | src/libglfw.3.3.dylib 48 | src/libglfw3.a 49 | src/glfw3.lib 50 | src/glfw3.dll 51 | src/glfw3dll.lib 52 | src/libglfw3dll.a 53 | examples/*.app 54 | examples/*.exe 55 | examples/boing 56 | examples/gears 57 | examples/heightmap 58 | examples/offscreen 59 | examples/particles 60 | examples/splitview 61 | examples/sharing 62 | examples/simple 63 | examples/wave 64 | tests/*.app 65 | tests/*.exe 66 | tests/clipboard 67 | tests/cursor 68 | tests/empty 69 | tests/events 70 | tests/gamma 71 | tests/glfwinfo 72 | tests/icon 73 | tests/iconify 74 | tests/joysticks 75 | tests/monitors 76 | tests/msaa 77 | tests/reopen 78 | tests/tearing 79 | tests/threads 80 | tests/timeout 81 | tests/title 82 | tests/vulkan 83 | tests/windows 84 | 85 | -------------------------------------------------------------------------------- /external/glfw/.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | compiler: clang 3 | branches: 4 | only: 5 | - ci 6 | - master 7 | os: 8 | - linux 9 | - osx 10 | sudo: false 11 | addons: 12 | apt: 13 | sources: 14 | - kubuntu-backports 15 | packages: 16 | - cmake 17 | env: 18 | - BUILD_SHARED_LIBS=ON 19 | - BUILD_SHARED_LIBS=OFF 20 | script: 21 | - mkdir build 22 | - cd build 23 | - cmake -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} .. 24 | - cmake --build . 25 | notifications: 26 | email: 27 | recipients: 28 | - ci@glfw.org 29 | on_success: never 30 | on_failure: always 31 | -------------------------------------------------------------------------------- /external/glfw/CMake/MacOSXBundleInfo.plist.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${MACOSX_BUNDLE_EXECUTABLE_NAME} 9 | CFBundleGetInfoString 10 | ${MACOSX_BUNDLE_INFO_STRING} 11 | CFBundleIconFile 12 | ${MACOSX_BUNDLE_ICON_FILE} 13 | CFBundleIdentifier 14 | ${MACOSX_BUNDLE_GUI_IDENTIFIER} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleLongVersionString 18 | ${MACOSX_BUNDLE_LONG_VERSION_STRING} 19 | CFBundleName 20 | ${MACOSX_BUNDLE_BUNDLE_NAME} 21 | CFBundlePackageType 22 | APPL 23 | CFBundleShortVersionString 24 | ${MACOSX_BUNDLE_SHORT_VERSION_STRING} 25 | CFBundleSignature 26 | ???? 27 | CFBundleVersion 28 | ${MACOSX_BUNDLE_BUNDLE_VERSION} 29 | CSResourcesFileMapped 30 | 31 | LSRequiresCarbon 32 | 33 | NSHumanReadableCopyright 34 | ${MACOSX_BUNDLE_COPYRIGHT} 35 | NSHighResolutionCapable 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /external/glfw/LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2002-2006 Marcus Geelnard 2 | 3 | Copyright (c) 2006-2019 Camilla Löwy 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would 16 | be appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and must not 19 | be misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | 24 | -------------------------------------------------------------------------------- /external/glfw/cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | 2 | if (NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 3 | message(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"") 4 | endif() 5 | 6 | file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) 7 | string(REGEX REPLACE "\n" ";" files "${files}") 8 | 9 | foreach (file ${files}) 10 | message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"") 11 | if (EXISTS "$ENV{DESTDIR}${file}") 12 | exec_program("@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" 13 | OUTPUT_VARIABLE rm_out 14 | RETURN_VALUE rm_retval) 15 | if (NOT "${rm_retval}" STREQUAL 0) 16 | MESSAGE(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") 17 | endif() 18 | elseif (IS_SYMLINK "$ENV{DESTDIR}${file}") 19 | EXEC_PROGRAM("@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" 20 | OUTPUT_VARIABLE rm_out 21 | RETURN_VALUE rm_retval) 22 | if (NOT "${rm_retval}" STREQUAL 0) 23 | message(FATAL_ERROR "Problem when removing symlink \"$ENV{DESTDIR}${file}\"") 24 | endif() 25 | else() 26 | message(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.") 27 | endif() 28 | endforeach() 29 | 30 | -------------------------------------------------------------------------------- /external/glfw/deps/getopt.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012, Kim Gräsman 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright notice, 7 | * this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright notice, 9 | * this list of conditions and the following disclaimer in the documentation 10 | * and/or other materials provided with the distribution. 11 | * * Neither the name of Kim Gräsman nor the names of contributors may be used 12 | * to endorse or promote products derived from this software without specific 13 | * prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL KIM GRÄSMAN BE LIABLE FOR ANY DIRECT, 19 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef INCLUDED_GETOPT_PORT_H 28 | #define INCLUDED_GETOPT_PORT_H 29 | 30 | #if defined(__cplusplus) 31 | extern "C" { 32 | #endif 33 | 34 | extern const int no_argument; 35 | extern const int required_argument; 36 | extern const int optional_argument; 37 | 38 | extern char* optarg; 39 | extern int optind, opterr, optopt; 40 | 41 | struct option { 42 | const char* name; 43 | int has_arg; 44 | int* flag; 45 | int val; 46 | }; 47 | 48 | int getopt(int argc, char* const argv[], const char* optstring); 49 | 50 | int getopt_long(int argc, char* const argv[], 51 | const char* optstring, const struct option* longopts, int* longindex); 52 | 53 | #if defined(__cplusplus) 54 | } 55 | #endif 56 | 57 | #endif // INCLUDED_GETOPT_PORT_H 58 | -------------------------------------------------------------------------------- /external/glfw/deps/glad/vk_platform.h: -------------------------------------------------------------------------------- 1 | /* */ 2 | /* File: vk_platform.h */ 3 | /* */ 4 | /* 5 | ** Copyright (c) 2014-2017 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | 21 | #ifndef VK_PLATFORM_H_ 22 | #define VK_PLATFORM_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" 26 | { 27 | #endif /* __cplusplus */ 28 | 29 | /* 30 | *************************************************************************************************** 31 | * Platform-specific directives and type declarations 32 | *************************************************************************************************** 33 | */ 34 | 35 | /* Platform-specific calling convention macros. 36 | * 37 | * Platforms should define these so that Vulkan clients call Vulkan commands 38 | * with the same calling conventions that the Vulkan implementation expects. 39 | * 40 | * VKAPI_ATTR - Placed before the return type in function declarations. 41 | * Useful for C++11 and GCC/Clang-style function attribute syntax. 42 | * VKAPI_CALL - Placed after the return type in function declarations. 43 | * Useful for MSVC-style calling convention syntax. 44 | * VKAPI_PTR - Placed between the '(' and '*' in function pointer types. 45 | * 46 | * Function declaration: VKAPI_ATTR void VKAPI_CALL vkCommand(void); 47 | * Function pointer type: typedef void (VKAPI_PTR *PFN_vkCommand)(void); 48 | */ 49 | #if defined(_WIN32) 50 | /* On Windows, Vulkan commands use the stdcall convention */ 51 | #define VKAPI_ATTR 52 | #define VKAPI_CALL __stdcall 53 | #define VKAPI_PTR VKAPI_CALL 54 | #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH < 7 55 | #error "Vulkan isn't supported for the 'armeabi' NDK ABI" 56 | #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH >= 7 && defined(__ARM_32BIT_STATE) 57 | /* On Android 32-bit ARM targets, Vulkan functions use the "hardfloat" */ 58 | /* calling convention, i.e. float parameters are passed in registers. This */ 59 | /* is true even if the rest of the application passes floats on the stack, */ 60 | /* as it does by default when compiling for the armeabi-v7a NDK ABI. */ 61 | #define VKAPI_ATTR __attribute__((pcs("aapcs-vfp"))) 62 | #define VKAPI_CALL 63 | #define VKAPI_PTR VKAPI_ATTR 64 | #else 65 | /* On other platforms, use the default calling convention */ 66 | #define VKAPI_ATTR 67 | #define VKAPI_CALL 68 | #define VKAPI_PTR 69 | #endif 70 | 71 | #include 72 | 73 | #if !defined(VK_NO_STDINT_H) 74 | #if defined(_MSC_VER) && (_MSC_VER < 1600) 75 | typedef signed __int8 int8_t; 76 | typedef unsigned __int8 uint8_t; 77 | typedef signed __int16 int16_t; 78 | typedef unsigned __int16 uint16_t; 79 | typedef signed __int32 int32_t; 80 | typedef unsigned __int32 uint32_t; 81 | typedef signed __int64 int64_t; 82 | typedef unsigned __int64 uint64_t; 83 | #else 84 | #include 85 | #endif 86 | #endif /* !defined(VK_NO_STDINT_H) */ 87 | 88 | #ifdef __cplusplus 89 | } /* extern "C" */ 90 | #endif /* __cplusplus */ 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /external/glfw/deps/mingw/_mingw_dxhelper.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the mingw-w64 runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | 7 | #if defined(_MSC_VER) && !defined(_MSC_EXTENSIONS) 8 | #define NONAMELESSUNION 1 9 | #endif 10 | #if defined(NONAMELESSSTRUCT) && \ 11 | !defined(NONAMELESSUNION) 12 | #define NONAMELESSUNION 1 13 | #endif 14 | #if defined(NONAMELESSUNION) && \ 15 | !defined(NONAMELESSSTRUCT) 16 | #define NONAMELESSSTRUCT 1 17 | #endif 18 | #if !defined(__GNU_EXTENSION) 19 | #if defined(__GNUC__) || defined(__GNUG__) 20 | #define __GNU_EXTENSION __extension__ 21 | #else 22 | #define __GNU_EXTENSION 23 | #endif 24 | #endif /* __extension__ */ 25 | 26 | #ifndef __ANONYMOUS_DEFINED 27 | #define __ANONYMOUS_DEFINED 28 | #if defined(__GNUC__) || defined(__GNUG__) 29 | #define _ANONYMOUS_UNION __extension__ 30 | #define _ANONYMOUS_STRUCT __extension__ 31 | #else 32 | #define _ANONYMOUS_UNION 33 | #define _ANONYMOUS_STRUCT 34 | #endif 35 | #ifndef NONAMELESSUNION 36 | #define _UNION_NAME(x) 37 | #define _STRUCT_NAME(x) 38 | #else /* NONAMELESSUNION */ 39 | #define _UNION_NAME(x) x 40 | #define _STRUCT_NAME(x) x 41 | #endif 42 | #endif /* __ANONYMOUS_DEFINED */ 43 | 44 | #ifndef DUMMYUNIONNAME 45 | # ifdef NONAMELESSUNION 46 | # define DUMMYUNIONNAME u 47 | # define DUMMYUNIONNAME1 u1 /* Wine uses this variant */ 48 | # define DUMMYUNIONNAME2 u2 49 | # define DUMMYUNIONNAME3 u3 50 | # define DUMMYUNIONNAME4 u4 51 | # define DUMMYUNIONNAME5 u5 52 | # define DUMMYUNIONNAME6 u6 53 | # define DUMMYUNIONNAME7 u7 54 | # define DUMMYUNIONNAME8 u8 55 | # define DUMMYUNIONNAME9 u9 56 | # else /* NONAMELESSUNION */ 57 | # define DUMMYUNIONNAME 58 | # define DUMMYUNIONNAME1 /* Wine uses this variant */ 59 | # define DUMMYUNIONNAME2 60 | # define DUMMYUNIONNAME3 61 | # define DUMMYUNIONNAME4 62 | # define DUMMYUNIONNAME5 63 | # define DUMMYUNIONNAME6 64 | # define DUMMYUNIONNAME7 65 | # define DUMMYUNIONNAME8 66 | # define DUMMYUNIONNAME9 67 | # endif 68 | #endif /* DUMMYUNIONNAME */ 69 | 70 | #if !defined(DUMMYUNIONNAME1) /* MinGW does not define this one */ 71 | # ifdef NONAMELESSUNION 72 | # define DUMMYUNIONNAME1 u1 /* Wine uses this variant */ 73 | # else 74 | # define DUMMYUNIONNAME1 /* Wine uses this variant */ 75 | # endif 76 | #endif /* DUMMYUNIONNAME1 */ 77 | 78 | #ifndef DUMMYSTRUCTNAME 79 | # ifdef NONAMELESSUNION 80 | # define DUMMYSTRUCTNAME s 81 | # define DUMMYSTRUCTNAME1 s1 /* Wine uses this variant */ 82 | # define DUMMYSTRUCTNAME2 s2 83 | # define DUMMYSTRUCTNAME3 s3 84 | # define DUMMYSTRUCTNAME4 s4 85 | # define DUMMYSTRUCTNAME5 s5 86 | # else 87 | # define DUMMYSTRUCTNAME 88 | # define DUMMYSTRUCTNAME1 /* Wine uses this variant */ 89 | # define DUMMYSTRUCTNAME2 90 | # define DUMMYSTRUCTNAME3 91 | # define DUMMYSTRUCTNAME4 92 | # define DUMMYSTRUCTNAME5 93 | # endif 94 | #endif /* DUMMYSTRUCTNAME */ 95 | 96 | /* These are for compatibility with the Wine source tree */ 97 | 98 | #ifndef WINELIB_NAME_AW 99 | # ifdef __MINGW_NAME_AW 100 | # define WINELIB_NAME_AW __MINGW_NAME_AW 101 | # else 102 | # ifdef UNICODE 103 | # define WINELIB_NAME_AW(func) func##W 104 | # else 105 | # define WINELIB_NAME_AW(func) func##A 106 | # endif 107 | # endif 108 | #endif /* WINELIB_NAME_AW */ 109 | 110 | #ifndef DECL_WINELIB_TYPE_AW 111 | # ifdef __MINGW_TYPEDEF_AW 112 | # define DECL_WINELIB_TYPE_AW __MINGW_TYPEDEF_AW 113 | # else 114 | # define DECL_WINELIB_TYPE_AW(type) typedef WINELIB_NAME_AW(type) type; 115 | # endif 116 | #endif /* DECL_WINELIB_TYPE_AW */ 117 | 118 | -------------------------------------------------------------------------------- /external/glfw/docs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # NOTE: The order of this list determines the order of items in the Guides 3 | # (i.e. Pages) list in the generated documentation 4 | set(GLFW_DOXYGEN_SOURCES 5 | "include/GLFW/glfw3.h" 6 | "include/GLFW/glfw3native.h" 7 | "docs/main.dox" 8 | "docs/news.dox" 9 | "docs/quick.dox" 10 | "docs/moving.dox" 11 | "docs/compile.dox" 12 | "docs/build.dox" 13 | "docs/intro.dox" 14 | "docs/context.dox" 15 | "docs/monitor.dox" 16 | "docs/window.dox" 17 | "docs/input.dox" 18 | "docs/vulkan.dox" 19 | "docs/compat.dox" 20 | "docs/internal.dox") 21 | 22 | # Format the source list into a Doxyfile INPUT value that Doxygen can parse 23 | foreach(path IN LISTS GLFW_DOXYGEN_SOURCES) 24 | set(GLFW_DOXYGEN_INPUT "${GLFW_DOXYGEN_INPUT} \\\n\"${GLFW_SOURCE_DIR}/${path}\"") 25 | endforeach() 26 | 27 | configure_file(Doxyfile.in Doxyfile @ONLY) 28 | 29 | add_custom_target(docs ALL "${DOXYGEN_EXECUTABLE}" 30 | WORKING_DIRECTORY "${GLFW_BINARY_DIR}/docs" 31 | COMMENT "Generating HTML documentation" VERBATIM) 32 | 33 | -------------------------------------------------------------------------------- /external/glfw/docs/CODEOWNERS: -------------------------------------------------------------------------------- 1 | 2 | * @elmindreda 3 | 4 | src/wl_* @linkmauve 5 | 6 | docs/*.css @glfw/webdev 7 | docs/*.less @glfw/webdev 8 | docs/*.html @glfw/webdev 9 | docs/*.xml @glfw/webdev 10 | 11 | -------------------------------------------------------------------------------- /external/glfw/docs/DoxygenLayout.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /external/glfw/docs/SUPPORT.md: -------------------------------------------------------------------------------- 1 | # Support resources 2 | 3 | See the [latest documentation](http://www.glfw.org/docs/latest/) for tutorials, 4 | guides and the API reference. 5 | 6 | If you have questions about using GLFW, we have a 7 | [forum](https://discourse.glfw.org/), and the `#glfw` IRC channel on 8 | [Freenode](http://freenode.net/). 9 | 10 | Bugs are reported to our [issue tracker](https://github.com/glfw/glfw/issues). 11 | Please check the [contribution 12 | guide](https://github.com/glfw/glfw/blob/master/docs/CONTRIBUTING.md) for 13 | information on what to include when reporting a bug. 14 | 15 | -------------------------------------------------------------------------------- /external/glfw/docs/footer.html: -------------------------------------------------------------------------------- 1 |

3 | Last update on $date for $projectname $projectnumber 4 |

5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /external/glfw/docs/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | $projectname: $title 8 | $title 9 | 10 | 11 | 12 | $treeview 13 | $search 14 | $mathjax 15 | 16 | $extrastylesheet 17 | 18 | 19 |
20 | 21 | 22 |
23 |
24 | GLFW 25 | 30 |
31 |
32 | 33 | 34 | -------------------------------------------------------------------------------- /external/glfw/examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | link_libraries(glfw) 3 | 4 | include_directories("${GLFW_SOURCE_DIR}/deps") 5 | 6 | if (MATH_LIBRARY) 7 | link_libraries("${MATH_LIBRARY}") 8 | endif() 9 | 10 | if (MSVC) 11 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) 12 | endif() 13 | 14 | if (WIN32) 15 | set(ICON glfw.rc) 16 | elseif (APPLE) 17 | set(ICON glfw.icns) 18 | endif() 19 | 20 | if (${CMAKE_VERSION} VERSION_EQUAL "3.1.0" OR 21 | ${CMAKE_VERSION} VERSION_GREATER "3.1.0") 22 | set(CMAKE_C_STANDARD 99) 23 | else() 24 | # Remove this fallback when removing support for CMake version less than 3.1 25 | add_compile_options("$<$:-std=c99>" 26 | "$<$:-std=c99>" 27 | "$<$:-std=c99>") 28 | 29 | endif() 30 | 31 | set(GLAD_GL "${GLFW_SOURCE_DIR}/deps/glad/gl.h" 32 | "${GLFW_SOURCE_DIR}/deps/glad_gl.c") 33 | set(GETOPT "${GLFW_SOURCE_DIR}/deps/getopt.h" 34 | "${GLFW_SOURCE_DIR}/deps/getopt.c") 35 | set(TINYCTHREAD "${GLFW_SOURCE_DIR}/deps/tinycthread.h" 36 | "${GLFW_SOURCE_DIR}/deps/tinycthread.c") 37 | 38 | add_executable(boing WIN32 MACOSX_BUNDLE boing.c ${ICON} ${GLAD_GL}) 39 | add_executable(gears WIN32 MACOSX_BUNDLE gears.c ${ICON} ${GLAD_GL}) 40 | add_executable(heightmap WIN32 MACOSX_BUNDLE heightmap.c ${ICON} ${GLAD_GL}) 41 | add_executable(offscreen offscreen.c ${ICON} ${GLAD_GL}) 42 | add_executable(particles WIN32 MACOSX_BUNDLE particles.c ${ICON} ${TINYCTHREAD} ${GETOPT} ${GLAD_GL}) 43 | add_executable(sharing WIN32 MACOSX_BUNDLE sharing.c ${ICON} ${GLAD_GL}) 44 | add_executable(simple WIN32 MACOSX_BUNDLE simple.c ${ICON} ${GLAD_GL}) 45 | add_executable(splitview WIN32 MACOSX_BUNDLE splitview.c ${ICON} ${GLAD_GL}) 46 | add_executable(wave WIN32 MACOSX_BUNDLE wave.c ${ICON} ${GLAD_GL}) 47 | 48 | target_link_libraries(particles "${CMAKE_THREAD_LIBS_INIT}") 49 | if (RT_LIBRARY) 50 | target_link_libraries(particles "${RT_LIBRARY}") 51 | endif() 52 | 53 | set(GUI_ONLY_BINARIES boing gears heightmap particles sharing simple splitview 54 | wave) 55 | set(CONSOLE_BINARIES offscreen) 56 | 57 | set_target_properties(${GUI_ONLY_BINARIES} ${CONSOLE_BINARIES} PROPERTIES 58 | FOLDER "GLFW3/Examples") 59 | 60 | if (GLFW_USE_OSMESA) 61 | target_compile_definitions(offscreen PRIVATE USE_NATIVE_OSMESA) 62 | endif() 63 | 64 | if (MSVC) 65 | # Tell MSVC to use main instead of WinMain for Windows subsystem executables 66 | set_target_properties(${GUI_ONLY_BINARIES} PROPERTIES 67 | LINK_FLAGS "/ENTRY:mainCRTStartup") 68 | endif() 69 | 70 | if (APPLE) 71 | set_target_properties(boing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Boing") 72 | set_target_properties(gears PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Gears") 73 | set_target_properties(heightmap PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Heightmap") 74 | set_target_properties(particles PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Particles") 75 | set_target_properties(sharing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Sharing") 76 | set_target_properties(simple PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Simple") 77 | set_target_properties(splitview PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "SplitView") 78 | set_target_properties(wave PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Wave") 79 | 80 | set_source_files_properties(glfw.icns PROPERTIES 81 | MACOSX_PACKAGE_LOCATION "Resources") 82 | set_target_properties(${GUI_ONLY_BINARIES} PROPERTIES 83 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${GLFW_VERSION} 84 | MACOSX_BUNDLE_LONG_VERSION_STRING ${GLFW_VERSION} 85 | MACOSX_BUNDLE_ICON_FILE glfw.icns 86 | MACOSX_BUNDLE_INFO_PLIST "${GLFW_SOURCE_DIR}/CMake/MacOSXBundleInfo.plist.in") 87 | endif() 88 | 89 | -------------------------------------------------------------------------------- /external/glfw/examples/glfw.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/external/glfw/examples/glfw.icns -------------------------------------------------------------------------------- /external/glfw/examples/glfw.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/external/glfw/examples/glfw.ico -------------------------------------------------------------------------------- /external/glfw/examples/glfw.rc: -------------------------------------------------------------------------------- 1 | 2 | GLFW_ICON ICON "glfw.ico" 3 | 4 | -------------------------------------------------------------------------------- /external/glfw/examples/simple.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Simple GLFW example 3 | // Copyright (c) Camilla Löwy 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | //! [code] 26 | 27 | #include 28 | #define GLFW_INCLUDE_NONE 29 | #include 30 | 31 | #include "linmath.h" 32 | 33 | #include 34 | #include 35 | 36 | static const struct 37 | { 38 | float x, y; 39 | float r, g, b; 40 | } vertices[3] = 41 | { 42 | { -0.6f, -0.4f, 1.f, 0.f, 0.f }, 43 | { 0.6f, -0.4f, 0.f, 1.f, 0.f }, 44 | { 0.f, 0.6f, 0.f, 0.f, 1.f } 45 | }; 46 | 47 | static const char* vertex_shader_text = 48 | "#version 110\n" 49 | "uniform mat4 MVP;\n" 50 | "attribute vec3 vCol;\n" 51 | "attribute vec2 vPos;\n" 52 | "varying vec3 color;\n" 53 | "void main()\n" 54 | "{\n" 55 | " gl_Position = MVP * vec4(vPos, 0.0, 1.0);\n" 56 | " color = vCol;\n" 57 | "}\n"; 58 | 59 | static const char* fragment_shader_text = 60 | "#version 110\n" 61 | "varying vec3 color;\n" 62 | "void main()\n" 63 | "{\n" 64 | " gl_FragColor = vec4(color, 1.0);\n" 65 | "}\n"; 66 | 67 | static void error_callback(int error, const char* description) 68 | { 69 | fprintf(stderr, "Error: %s\n", description); 70 | } 71 | 72 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 73 | { 74 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) 75 | glfwSetWindowShouldClose(window, GLFW_TRUE); 76 | } 77 | 78 | int main(void) 79 | { 80 | GLFWwindow* window; 81 | GLuint vertex_buffer, vertex_shader, fragment_shader, program; 82 | GLint mvp_location, vpos_location, vcol_location; 83 | 84 | glfwSetErrorCallback(error_callback); 85 | 86 | if (!glfwInit()) 87 | exit(EXIT_FAILURE); 88 | 89 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); 90 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); 91 | 92 | window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL); 93 | if (!window) 94 | { 95 | glfwTerminate(); 96 | exit(EXIT_FAILURE); 97 | } 98 | 99 | glfwSetKeyCallback(window, key_callback); 100 | 101 | glfwMakeContextCurrent(window); 102 | gladLoadGL(glfwGetProcAddress); 103 | glfwSwapInterval(1); 104 | 105 | // NOTE: OpenGL error checks have been omitted for brevity 106 | 107 | glGenBuffers(1, &vertex_buffer); 108 | glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); 109 | glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); 110 | 111 | vertex_shader = glCreateShader(GL_VERTEX_SHADER); 112 | glShaderSource(vertex_shader, 1, &vertex_shader_text, NULL); 113 | glCompileShader(vertex_shader); 114 | 115 | fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); 116 | glShaderSource(fragment_shader, 1, &fragment_shader_text, NULL); 117 | glCompileShader(fragment_shader); 118 | 119 | program = glCreateProgram(); 120 | glAttachShader(program, vertex_shader); 121 | glAttachShader(program, fragment_shader); 122 | glLinkProgram(program); 123 | 124 | mvp_location = glGetUniformLocation(program, "MVP"); 125 | vpos_location = glGetAttribLocation(program, "vPos"); 126 | vcol_location = glGetAttribLocation(program, "vCol"); 127 | 128 | glEnableVertexAttribArray(vpos_location); 129 | glVertexAttribPointer(vpos_location, 2, GL_FLOAT, GL_FALSE, 130 | sizeof(vertices[0]), (void*) 0); 131 | glEnableVertexAttribArray(vcol_location); 132 | glVertexAttribPointer(vcol_location, 3, GL_FLOAT, GL_FALSE, 133 | sizeof(vertices[0]), (void*) (sizeof(float) * 2)); 134 | 135 | while (!glfwWindowShouldClose(window)) 136 | { 137 | float ratio; 138 | int width, height; 139 | mat4x4 m, p, mvp; 140 | 141 | glfwGetFramebufferSize(window, &width, &height); 142 | ratio = width / (float) height; 143 | 144 | glViewport(0, 0, width, height); 145 | glClear(GL_COLOR_BUFFER_BIT); 146 | 147 | mat4x4_identity(m); 148 | mat4x4_rotate_Z(m, m, (float) glfwGetTime()); 149 | mat4x4_ortho(p, -ratio, ratio, -1.f, 1.f, 1.f, -1.f); 150 | mat4x4_mul(mvp, p, m); 151 | 152 | glUseProgram(program); 153 | glUniformMatrix4fv(mvp_location, 1, GL_FALSE, (const GLfloat*) mvp); 154 | glDrawArrays(GL_TRIANGLES, 0, 3); 155 | 156 | glfwSwapBuffers(window); 157 | glfwPollEvents(); 158 | } 159 | 160 | glfwDestroyWindow(window); 161 | 162 | glfwTerminate(); 163 | exit(EXIT_SUCCESS); 164 | } 165 | 166 | //! [code] 167 | -------------------------------------------------------------------------------- /external/glfw/src/cocoa_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 Cocoa - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2017 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickNS ns 33 | #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE struct { int dummyJoystick; } 34 | 35 | #define _GLFW_PLATFORM_MAPPING_NAME "Mac OS X" 36 | 37 | // Cocoa-specific per-joystick data 38 | // 39 | typedef struct _GLFWjoystickNS 40 | { 41 | IOHIDDeviceRef device; 42 | CFMutableArrayRef axes; 43 | CFMutableArrayRef buttons; 44 | CFMutableArrayRef hats; 45 | } _GLFWjoystickNS; 46 | 47 | 48 | void _glfwInitJoysticksNS(void); 49 | void _glfwTerminateJoysticksNS(void); 50 | 51 | -------------------------------------------------------------------------------- /external/glfw/src/cocoa_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 macOS - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2009-2016 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // It is fine to use C99 in this file because it will not be built with VS 27 | //======================================================================== 28 | 29 | #include "internal.h" 30 | 31 | #include 32 | 33 | 34 | ////////////////////////////////////////////////////////////////////////// 35 | ////// GLFW internal API ////// 36 | ////////////////////////////////////////////////////////////////////////// 37 | 38 | // Initialise timer 39 | // 40 | void _glfwInitTimerNS(void) 41 | { 42 | mach_timebase_info_data_t info; 43 | mach_timebase_info(&info); 44 | 45 | _glfw.timer.ns.frequency = (info.denom * 1e9) / info.numer; 46 | } 47 | 48 | 49 | ////////////////////////////////////////////////////////////////////////// 50 | ////// GLFW platform API ////// 51 | ////////////////////////////////////////////////////////////////////////// 52 | 53 | uint64_t _glfwPlatformGetTimerValue(void) 54 | { 55 | return mach_absolute_time(); 56 | } 57 | 58 | uint64_t _glfwPlatformGetTimerFrequency(void) 59 | { 60 | return _glfw.timer.ns.frequency; 61 | } 62 | 63 | -------------------------------------------------------------------------------- /external/glfw/src/glfw3.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ 4 | libdir=@CMAKE_INSTALL_FULL_LIBDIR@ 5 | 6 | Name: GLFW 7 | Description: A multi-platform library for OpenGL, window and input 8 | Version: @GLFW_VERSION@ 9 | URL: https://www.glfw.org/ 10 | Requires.private: @GLFW_PKG_DEPS@ 11 | Libs: -L${libdir} -l@GLFW_LIB_NAME@ 12 | Libs.private: @GLFW_PKG_LIBS@ 13 | Cflags: -I${includedir} 14 | -------------------------------------------------------------------------------- /external/glfw/src/glfw3Config.cmake.in: -------------------------------------------------------------------------------- 1 | include("${CMAKE_CURRENT_LIST_DIR}/glfw3Targets.cmake") 2 | -------------------------------------------------------------------------------- /external/glfw/src/glfw_config.h.in: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2010-2016 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // As glfw_config.h.in, this file is used by CMake to produce the 27 | // glfw_config.h configuration header file. If you are adding a feature 28 | // requiring conditional compilation, this is where to add the macro. 29 | //======================================================================== 30 | // As glfw_config.h, this file defines compile-time option macros for a 31 | // specific platform and development environment. If you are using the 32 | // GLFW CMake files, modify glfw_config.h.in instead of this file. If you 33 | // are using your own build system, make this file define the appropriate 34 | // macros in whatever way is suitable. 35 | //======================================================================== 36 | 37 | // Define this to 1 if building GLFW for X11 38 | #cmakedefine _GLFW_X11 39 | // Define this to 1 if building GLFW for Win32 40 | #cmakedefine _GLFW_WIN32 41 | // Define this to 1 if building GLFW for Cocoa 42 | #cmakedefine _GLFW_COCOA 43 | // Define this to 1 if building GLFW for Wayland 44 | #cmakedefine _GLFW_WAYLAND 45 | // Define this to 1 if building GLFW for OSMesa 46 | #cmakedefine _GLFW_OSMESA 47 | 48 | // Define this to 1 if building as a shared library / dynamic library / DLL 49 | #cmakedefine _GLFW_BUILD_DLL 50 | // Define this to 1 to use Vulkan loader linked statically into application 51 | #cmakedefine _GLFW_VULKAN_STATIC 52 | 53 | // Define this to 1 to force use of high-performance GPU on hybrid systems 54 | #cmakedefine _GLFW_USE_HYBRID_HPG 55 | 56 | // Define this to 1 if xkbcommon supports the compose key 57 | #cmakedefine HAVE_XKBCOMMON_COMPOSE_H 58 | // Define this to 1 if the libc supports memfd_create() 59 | #cmakedefine HAVE_MEMFD_CREATE 60 | 61 | -------------------------------------------------------------------------------- /external/glfw/src/linux_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 Linux - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014 Jonas Ådahl 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickLinux linjs 32 | #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE _GLFWlibraryLinux linjs 33 | 34 | #define _GLFW_PLATFORM_MAPPING_NAME "Linux" 35 | 36 | // Linux-specific joystick data 37 | // 38 | typedef struct _GLFWjoystickLinux 39 | { 40 | int fd; 41 | char path[PATH_MAX]; 42 | int keyMap[KEY_CNT - BTN_MISC]; 43 | int absMap[ABS_CNT]; 44 | struct input_absinfo absInfo[ABS_CNT]; 45 | int hats[4][2]; 46 | } _GLFWjoystickLinux; 47 | 48 | // Linux-specific joystick API data 49 | // 50 | typedef struct _GLFWlibraryLinux 51 | { 52 | int inotify; 53 | int watch; 54 | regex_t regex; 55 | GLFWbool dropped; 56 | } _GLFWlibraryLinux; 57 | 58 | 59 | GLFWbool _glfwInitJoysticksLinux(void); 60 | void _glfwTerminateJoysticksLinux(void); 61 | void _glfwDetectJoystickConnectionLinux(void); 62 | 63 | -------------------------------------------------------------------------------- /external/glfw/src/mappings.h.in: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2018 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // As mappings.h.in, this file is used by CMake to produce the mappings.h 27 | // header file. If you are adding a GLFW specific gamepad mapping, this is 28 | // where to put it. 29 | //======================================================================== 30 | // As mappings.h, this provides all pre-defined gamepad mappings, including 31 | // all available in SDL_GameControllerDB. Do not edit this file. Any gamepad 32 | // mappings not specific to GLFW should be submitted to SDL_GameControllerDB. 33 | // This file can be re-generated from mappings.h.in and the upstream 34 | // gamecontrollerdb.txt with the GenerateMappings.cmake script. 35 | //======================================================================== 36 | 37 | // All gamepad mappings not labeled GLFW are copied from the 38 | // SDL_GameControllerDB project under the following license: 39 | // 40 | // Simple DirectMedia Layer 41 | // Copyright (C) 1997-2013 Sam Lantinga 42 | // 43 | // This software is provided 'as-is', without any express or implied warranty. 44 | // In no event will the authors be held liable for any damages arising from the 45 | // use of this software. 46 | // 47 | // Permission is granted to anyone to use this software for any purpose, 48 | // including commercial applications, and to alter it and redistribute it 49 | // freely, subject to the following restrictions: 50 | // 51 | // 1. The origin of this software must not be misrepresented; you must not 52 | // claim that you wrote the original software. If you use this software 53 | // in a product, an acknowledgment in the product documentation would 54 | // be appreciated but is not required. 55 | // 56 | // 2. Altered source versions must be plainly marked as such, and must not be 57 | // misrepresented as being the original software. 58 | // 59 | // 3. This notice may not be removed or altered from any source distribution. 60 | 61 | const char* _glfwDefaultMappings[] = 62 | { 63 | @GLFW_GAMEPAD_MAPPINGS@ 64 | "78696e70757401000000000000000000,XInput Gamepad (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 65 | "78696e70757402000000000000000000,XInput Wheel (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 66 | "78696e70757403000000000000000000,XInput Arcade Stick (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 67 | "78696e70757404000000000000000000,XInput Flight Stick (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 68 | "78696e70757405000000000000000000,XInput Dance Pad (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 69 | "78696e70757406000000000000000000,XInput Guitar (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 70 | "78696e70757408000000000000000000,XInput Drum Kit (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 71 | NULL 72 | }; 73 | 74 | -------------------------------------------------------------------------------- /external/glfw/src/nsgl_context.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 macOS - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2009-2019 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | // NOTE: Many Cocoa enum values have been renamed and we need to build across 28 | // SDK versions where one is unavailable or the other deprecated 29 | // We use the newer names in code and these macros to handle compatibility 30 | #if MAC_OS_X_VERSION_MAX_ALLOWED < 101400 31 | #define NSOpenGLContextParameterSwapInterval NSOpenGLCPSwapInterval 32 | #define NSOpenGLContextParameterSurfaceOpacity NSOpenGLCPSurfaceOpacity 33 | #endif 34 | 35 | #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextNSGL nsgl 36 | #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE _GLFWlibraryNSGL nsgl 37 | 38 | #include 39 | 40 | 41 | // NSGL-specific per-context data 42 | // 43 | typedef struct _GLFWcontextNSGL 44 | { 45 | id pixelFormat; 46 | id object; 47 | 48 | } _GLFWcontextNSGL; 49 | 50 | // NSGL-specific global data 51 | // 52 | typedef struct _GLFWlibraryNSGL 53 | { 54 | // dlopen handle for OpenGL.framework (for glfwGetProcAddress) 55 | CFBundleRef framework; 56 | 57 | } _GLFWlibraryNSGL; 58 | 59 | 60 | GLFWbool _glfwInitNSGL(void); 61 | void _glfwTerminateNSGL(void); 62 | GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window, 63 | const _GLFWctxconfig* ctxconfig, 64 | const _GLFWfbconfig* fbconfig); 65 | void _glfwDestroyContextNSGL(_GLFWwindow* window); 66 | 67 | -------------------------------------------------------------------------------- /external/glfw/src/null_init.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2016-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // It is fine to use C99 in this file because it will not be built with VS 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | ////// GLFW platform API ////// 35 | ////////////////////////////////////////////////////////////////////////// 36 | 37 | int _glfwPlatformInit(void) 38 | { 39 | _glfwInitTimerPOSIX(); 40 | return GLFW_TRUE; 41 | } 42 | 43 | void _glfwPlatformTerminate(void) 44 | { 45 | _glfwTerminateOSMesa(); 46 | } 47 | 48 | const char* _glfwPlatformGetVersionString(void) 49 | { 50 | return _GLFW_VERSION_NUMBER " null OSMesa"; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /external/glfw/src/null_joystick.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016-2017 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // It is fine to use C99 in this file because it will not be built with VS 27 | //======================================================================== 28 | 29 | #include "internal.h" 30 | 31 | 32 | ////////////////////////////////////////////////////////////////////////// 33 | ////// GLFW platform API ////// 34 | ////////////////////////////////////////////////////////////////////////// 35 | 36 | int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode) 37 | { 38 | return GLFW_FALSE; 39 | } 40 | 41 | void _glfwPlatformUpdateGamepadGUID(char* guid) 42 | { 43 | } 44 | 45 | -------------------------------------------------------------------------------- /external/glfw/src/null_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2017 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #define _GLFW_PLATFORM_JOYSTICK_STATE struct { int dummyJoystick; } 28 | #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE struct { int dummyLibraryJoystick; } 29 | 30 | #define _GLFW_PLATFORM_MAPPING_NAME "" 31 | 32 | -------------------------------------------------------------------------------- /external/glfw/src/null_monitor.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2016-2019 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // It is fine to use C99 in this file because it will not be built with VS 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | ////// GLFW platform API ////// 35 | ////////////////////////////////////////////////////////////////////////// 36 | 37 | void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor) 38 | { 39 | } 40 | 41 | void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) 42 | { 43 | } 44 | 45 | void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor, 46 | float* xscale, float* yscale) 47 | { 48 | if (xscale) 49 | *xscale = 1.f; 50 | if (yscale) 51 | *yscale = 1.f; 52 | } 53 | 54 | void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor, 55 | int* xpos, int* ypos, 56 | int* width, int* height) 57 | { 58 | } 59 | 60 | GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) 61 | { 62 | return NULL; 63 | } 64 | 65 | void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) 66 | { 67 | } 68 | 69 | GLFWbool _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) 70 | { 71 | return GLFW_FALSE; 72 | } 73 | 74 | void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) 75 | { 76 | } 77 | 78 | -------------------------------------------------------------------------------- /external/glfw/src/null_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2016-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include 29 | 30 | #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNull null 31 | 32 | #define _GLFW_PLATFORM_CONTEXT_STATE struct { int dummyContext; } 33 | #define _GLFW_PLATFORM_MONITOR_STATE struct { int dummyMonitor; } 34 | #define _GLFW_PLATFORM_CURSOR_STATE struct { int dummyCursor; } 35 | #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE struct { int dummyLibraryWindow; } 36 | #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE struct { int dummyLibraryContext; } 37 | #define _GLFW_EGL_CONTEXT_STATE struct { int dummyEGLContext; } 38 | #define _GLFW_EGL_LIBRARY_CONTEXT_STATE struct { int dummyEGLLibraryContext; } 39 | 40 | #include "osmesa_context.h" 41 | #include "posix_time.h" 42 | #include "posix_thread.h" 43 | #include "null_joystick.h" 44 | 45 | #if defined(_GLFW_WIN32) 46 | #define _glfw_dlopen(name) LoadLibraryA(name) 47 | #define _glfw_dlclose(handle) FreeLibrary((HMODULE) handle) 48 | #define _glfw_dlsym(handle, name) GetProcAddress((HMODULE) handle, name) 49 | #else 50 | #define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL) 51 | #define _glfw_dlclose(handle) dlclose(handle) 52 | #define _glfw_dlsym(handle, name) dlsym(handle, name) 53 | #endif 54 | 55 | // Null-specific per-window data 56 | // 57 | typedef struct _GLFWwindowNull 58 | { 59 | int width; 60 | int height; 61 | } _GLFWwindowNull; 62 | 63 | -------------------------------------------------------------------------------- /external/glfw/src/osmesa_context.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 OSMesa - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2016-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #define OSMESA_RGBA 0x1908 29 | #define OSMESA_FORMAT 0x22 30 | #define OSMESA_DEPTH_BITS 0x30 31 | #define OSMESA_STENCIL_BITS 0x31 32 | #define OSMESA_ACCUM_BITS 0x32 33 | #define OSMESA_PROFILE 0x33 34 | #define OSMESA_CORE_PROFILE 0x34 35 | #define OSMESA_COMPAT_PROFILE 0x35 36 | #define OSMESA_CONTEXT_MAJOR_VERSION 0x36 37 | #define OSMESA_CONTEXT_MINOR_VERSION 0x37 38 | 39 | typedef void* OSMesaContext; 40 | typedef void (*OSMESAproc)(void); 41 | 42 | typedef OSMesaContext (GLAPIENTRY * PFN_OSMesaCreateContextExt)(GLenum,GLint,GLint,GLint,OSMesaContext); 43 | typedef OSMesaContext (GLAPIENTRY * PFN_OSMesaCreateContextAttribs)(const int*,OSMesaContext); 44 | typedef void (GLAPIENTRY * PFN_OSMesaDestroyContext)(OSMesaContext); 45 | typedef int (GLAPIENTRY * PFN_OSMesaMakeCurrent)(OSMesaContext,void*,int,int,int); 46 | typedef int (GLAPIENTRY * PFN_OSMesaGetColorBuffer)(OSMesaContext,int*,int*,int*,void**); 47 | typedef int (GLAPIENTRY * PFN_OSMesaGetDepthBuffer)(OSMesaContext,int*,int*,int*,void**); 48 | typedef GLFWglproc (GLAPIENTRY * PFN_OSMesaGetProcAddress)(const char*); 49 | #define OSMesaCreateContextExt _glfw.osmesa.CreateContextExt 50 | #define OSMesaCreateContextAttribs _glfw.osmesa.CreateContextAttribs 51 | #define OSMesaDestroyContext _glfw.osmesa.DestroyContext 52 | #define OSMesaMakeCurrent _glfw.osmesa.MakeCurrent 53 | #define OSMesaGetColorBuffer _glfw.osmesa.GetColorBuffer 54 | #define OSMesaGetDepthBuffer _glfw.osmesa.GetDepthBuffer 55 | #define OSMesaGetProcAddress _glfw.osmesa.GetProcAddress 56 | 57 | #define _GLFW_OSMESA_CONTEXT_STATE _GLFWcontextOSMesa osmesa 58 | #define _GLFW_OSMESA_LIBRARY_CONTEXT_STATE _GLFWlibraryOSMesa osmesa 59 | 60 | 61 | // OSMesa-specific per-context data 62 | // 63 | typedef struct _GLFWcontextOSMesa 64 | { 65 | OSMesaContext handle; 66 | int width; 67 | int height; 68 | void* buffer; 69 | 70 | } _GLFWcontextOSMesa; 71 | 72 | // OSMesa-specific global data 73 | // 74 | typedef struct _GLFWlibraryOSMesa 75 | { 76 | void* handle; 77 | 78 | PFN_OSMesaCreateContextExt CreateContextExt; 79 | PFN_OSMesaCreateContextAttribs CreateContextAttribs; 80 | PFN_OSMesaDestroyContext DestroyContext; 81 | PFN_OSMesaMakeCurrent MakeCurrent; 82 | PFN_OSMesaGetColorBuffer GetColorBuffer; 83 | PFN_OSMesaGetDepthBuffer GetDepthBuffer; 84 | PFN_OSMesaGetProcAddress GetProcAddress; 85 | 86 | } _GLFWlibraryOSMesa; 87 | 88 | 89 | GLFWbool _glfwInitOSMesa(void); 90 | void _glfwTerminateOSMesa(void); 91 | GLFWbool _glfwCreateContextOSMesa(_GLFWwindow* window, 92 | const _GLFWctxconfig* ctxconfig, 93 | const _GLFWfbconfig* fbconfig); 94 | 95 | -------------------------------------------------------------------------------- /external/glfw/src/posix_thread.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // It is fine to use C99 in this file because it will not be built with VS 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | #include 34 | 35 | 36 | ////////////////////////////////////////////////////////////////////////// 37 | ////// GLFW platform API ////// 38 | ////////////////////////////////////////////////////////////////////////// 39 | 40 | GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls) 41 | { 42 | assert(tls->posix.allocated == GLFW_FALSE); 43 | 44 | if (pthread_key_create(&tls->posix.key, NULL) != 0) 45 | { 46 | _glfwInputError(GLFW_PLATFORM_ERROR, 47 | "POSIX: Failed to create context TLS"); 48 | return GLFW_FALSE; 49 | } 50 | 51 | tls->posix.allocated = GLFW_TRUE; 52 | return GLFW_TRUE; 53 | } 54 | 55 | void _glfwPlatformDestroyTls(_GLFWtls* tls) 56 | { 57 | if (tls->posix.allocated) 58 | pthread_key_delete(tls->posix.key); 59 | memset(tls, 0, sizeof(_GLFWtls)); 60 | } 61 | 62 | void* _glfwPlatformGetTls(_GLFWtls* tls) 63 | { 64 | assert(tls->posix.allocated == GLFW_TRUE); 65 | return pthread_getspecific(tls->posix.key); 66 | } 67 | 68 | void _glfwPlatformSetTls(_GLFWtls* tls, void* value) 69 | { 70 | assert(tls->posix.allocated == GLFW_TRUE); 71 | pthread_setspecific(tls->posix.key, value); 72 | } 73 | 74 | GLFWbool _glfwPlatformCreateMutex(_GLFWmutex* mutex) 75 | { 76 | assert(mutex->posix.allocated == GLFW_FALSE); 77 | 78 | if (pthread_mutex_init(&mutex->posix.handle, NULL) != 0) 79 | { 80 | _glfwInputError(GLFW_PLATFORM_ERROR, "POSIX: Failed to create mutex"); 81 | return GLFW_FALSE; 82 | } 83 | 84 | return mutex->posix.allocated = GLFW_TRUE; 85 | } 86 | 87 | void _glfwPlatformDestroyMutex(_GLFWmutex* mutex) 88 | { 89 | if (mutex->posix.allocated) 90 | pthread_mutex_destroy(&mutex->posix.handle); 91 | memset(mutex, 0, sizeof(_GLFWmutex)); 92 | } 93 | 94 | void _glfwPlatformLockMutex(_GLFWmutex* mutex) 95 | { 96 | assert(mutex->posix.allocated == GLFW_TRUE); 97 | pthread_mutex_lock(&mutex->posix.handle); 98 | } 99 | 100 | void _glfwPlatformUnlockMutex(_GLFWmutex* mutex) 101 | { 102 | assert(mutex->posix.allocated == GLFW_TRUE); 103 | pthread_mutex_unlock(&mutex->posix.handle); 104 | } 105 | 106 | -------------------------------------------------------------------------------- /external/glfw/src/posix_thread.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include 29 | 30 | #define _GLFW_PLATFORM_TLS_STATE _GLFWtlsPOSIX posix 31 | #define _GLFW_PLATFORM_MUTEX_STATE _GLFWmutexPOSIX posix 32 | 33 | 34 | // POSIX-specific thread local storage data 35 | // 36 | typedef struct _GLFWtlsPOSIX 37 | { 38 | GLFWbool allocated; 39 | pthread_key_t key; 40 | 41 | } _GLFWtlsPOSIX; 42 | 43 | // POSIX-specific mutex data 44 | // 45 | typedef struct _GLFWmutexPOSIX 46 | { 47 | GLFWbool allocated; 48 | pthread_mutex_t handle; 49 | 50 | } _GLFWmutexPOSIX; 51 | 52 | -------------------------------------------------------------------------------- /external/glfw/src/posix_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // It is fine to use C99 in this file because it will not be built with VS 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | #include 34 | 35 | 36 | ////////////////////////////////////////////////////////////////////////// 37 | ////// GLFW internal API ////// 38 | ////////////////////////////////////////////////////////////////////////// 39 | 40 | // Initialise timer 41 | // 42 | void _glfwInitTimerPOSIX(void) 43 | { 44 | #if defined(CLOCK_MONOTONIC) 45 | struct timespec ts; 46 | 47 | if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) 48 | { 49 | _glfw.timer.posix.monotonic = GLFW_TRUE; 50 | _glfw.timer.posix.frequency = 1000000000; 51 | } 52 | else 53 | #endif 54 | { 55 | _glfw.timer.posix.monotonic = GLFW_FALSE; 56 | _glfw.timer.posix.frequency = 1000000; 57 | } 58 | } 59 | 60 | 61 | ////////////////////////////////////////////////////////////////////////// 62 | ////// GLFW platform API ////// 63 | ////////////////////////////////////////////////////////////////////////// 64 | 65 | uint64_t _glfwPlatformGetTimerValue(void) 66 | { 67 | #if defined(CLOCK_MONOTONIC) 68 | if (_glfw.timer.posix.monotonic) 69 | { 70 | struct timespec ts; 71 | clock_gettime(CLOCK_MONOTONIC, &ts); 72 | return (uint64_t) ts.tv_sec * (uint64_t) 1000000000 + (uint64_t) ts.tv_nsec; 73 | } 74 | else 75 | #endif 76 | { 77 | struct timeval tv; 78 | gettimeofday(&tv, NULL); 79 | return (uint64_t) tv.tv_sec * (uint64_t) 1000000 + (uint64_t) tv.tv_usec; 80 | } 81 | } 82 | 83 | uint64_t _glfwPlatformGetTimerFrequency(void) 84 | { 85 | return _glfw.timer.posix.frequency; 86 | } 87 | 88 | -------------------------------------------------------------------------------- /external/glfw/src/posix_time.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #define _GLFW_PLATFORM_LIBRARY_TIMER_STATE _GLFWtimerPOSIX posix 29 | 30 | #include 31 | 32 | 33 | // POSIX-specific global timer data 34 | // 35 | typedef struct _GLFWtimerPOSIX 36 | { 37 | GLFWbool monotonic; 38 | uint64_t frequency; 39 | 40 | } _GLFWtimerPOSIX; 41 | 42 | 43 | void _glfwInitTimerPOSIX(void); 44 | 45 | -------------------------------------------------------------------------------- /external/glfw/src/win32_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2017 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickWin32 win32 28 | #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE struct { int dummyLibraryJoystick; } 29 | 30 | #define _GLFW_PLATFORM_MAPPING_NAME "Windows" 31 | 32 | // Joystick element (axis, button or slider) 33 | // 34 | typedef struct _GLFWjoyobjectWin32 35 | { 36 | int offset; 37 | int type; 38 | } _GLFWjoyobjectWin32; 39 | 40 | // Win32-specific per-joystick data 41 | // 42 | typedef struct _GLFWjoystickWin32 43 | { 44 | _GLFWjoyobjectWin32* objects; 45 | int objectCount; 46 | IDirectInputDevice8W* device; 47 | DWORD index; 48 | GUID guid; 49 | } _GLFWjoystickWin32; 50 | 51 | 52 | void _glfwInitJoysticksWin32(void); 53 | void _glfwTerminateJoysticksWin32(void); 54 | void _glfwDetectJoystickConnectionWin32(void); 55 | void _glfwDetectJoystickDisconnectionWin32(void); 56 | 57 | -------------------------------------------------------------------------------- /external/glfw/src/win32_thread.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // Please use C89 style variable declarations in this file because VS 2010 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | 34 | 35 | ////////////////////////////////////////////////////////////////////////// 36 | ////// GLFW platform API ////// 37 | ////////////////////////////////////////////////////////////////////////// 38 | 39 | GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls) 40 | { 41 | assert(tls->win32.allocated == GLFW_FALSE); 42 | 43 | tls->win32.index = TlsAlloc(); 44 | if (tls->win32.index == TLS_OUT_OF_INDEXES) 45 | { 46 | _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, 47 | "Win32: Failed to allocate TLS index"); 48 | return GLFW_FALSE; 49 | } 50 | 51 | tls->win32.allocated = GLFW_TRUE; 52 | return GLFW_TRUE; 53 | } 54 | 55 | void _glfwPlatformDestroyTls(_GLFWtls* tls) 56 | { 57 | if (tls->win32.allocated) 58 | TlsFree(tls->win32.index); 59 | memset(tls, 0, sizeof(_GLFWtls)); 60 | } 61 | 62 | void* _glfwPlatformGetTls(_GLFWtls* tls) 63 | { 64 | assert(tls->win32.allocated == GLFW_TRUE); 65 | return TlsGetValue(tls->win32.index); 66 | } 67 | 68 | void _glfwPlatformSetTls(_GLFWtls* tls, void* value) 69 | { 70 | assert(tls->win32.allocated == GLFW_TRUE); 71 | TlsSetValue(tls->win32.index, value); 72 | } 73 | 74 | GLFWbool _glfwPlatformCreateMutex(_GLFWmutex* mutex) 75 | { 76 | assert(mutex->win32.allocated == GLFW_FALSE); 77 | InitializeCriticalSection(&mutex->win32.section); 78 | return mutex->win32.allocated = GLFW_TRUE; 79 | } 80 | 81 | void _glfwPlatformDestroyMutex(_GLFWmutex* mutex) 82 | { 83 | if (mutex->win32.allocated) 84 | DeleteCriticalSection(&mutex->win32.section); 85 | memset(mutex, 0, sizeof(_GLFWmutex)); 86 | } 87 | 88 | void _glfwPlatformLockMutex(_GLFWmutex* mutex) 89 | { 90 | assert(mutex->win32.allocated == GLFW_TRUE); 91 | EnterCriticalSection(&mutex->win32.section); 92 | } 93 | 94 | void _glfwPlatformUnlockMutex(_GLFWmutex* mutex) 95 | { 96 | assert(mutex->win32.allocated == GLFW_TRUE); 97 | LeaveCriticalSection(&mutex->win32.section); 98 | } 99 | 100 | -------------------------------------------------------------------------------- /external/glfw/src/win32_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // Please use C89 style variable declarations in this file because VS 2010 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | ////// GLFW internal API ////// 35 | ////////////////////////////////////////////////////////////////////////// 36 | 37 | // Initialise timer 38 | // 39 | void _glfwInitTimerWin32(void) 40 | { 41 | uint64_t frequency; 42 | 43 | if (QueryPerformanceFrequency((LARGE_INTEGER*) &frequency)) 44 | { 45 | _glfw.timer.win32.hasPC = GLFW_TRUE; 46 | _glfw.timer.win32.frequency = frequency; 47 | } 48 | else 49 | { 50 | _glfw.timer.win32.hasPC = GLFW_FALSE; 51 | _glfw.timer.win32.frequency = 1000; 52 | } 53 | } 54 | 55 | 56 | ////////////////////////////////////////////////////////////////////////// 57 | ////// GLFW platform API ////// 58 | ////////////////////////////////////////////////////////////////////////// 59 | 60 | uint64_t _glfwPlatformGetTimerValue(void) 61 | { 62 | if (_glfw.timer.win32.hasPC) 63 | { 64 | uint64_t value; 65 | QueryPerformanceCounter((LARGE_INTEGER*) &value); 66 | return value; 67 | } 68 | else 69 | return (uint64_t) timeGetTime(); 70 | } 71 | 72 | uint64_t _glfwPlatformGetTimerFrequency(void) 73 | { 74 | return _glfw.timer.win32.frequency; 75 | } 76 | 77 | -------------------------------------------------------------------------------- /external/glfw/src/xkb_unicode.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 Linux - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014 Jonas Ådahl 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | long _glfwKeySym2Unicode(unsigned int keysym); 28 | 29 | -------------------------------------------------------------------------------- /external/glfw/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | link_libraries(glfw) 3 | 4 | include_directories("${GLFW_SOURCE_DIR}/deps") 5 | 6 | if (MATH_LIBRARY) 7 | link_libraries("${MATH_LIBRARY}") 8 | endif() 9 | 10 | if (MSVC) 11 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) 12 | endif() 13 | 14 | set(GLAD_GL "${GLFW_SOURCE_DIR}/deps/glad/gl.h" 15 | "${GLFW_SOURCE_DIR}/deps/glad_gl.c") 16 | set(GLAD_VULKAN "${GLFW_SOURCE_DIR}/deps/glad/vulkan.h" 17 | "${GLFW_SOURCE_DIR}/deps/glad_vulkan.c") 18 | set(GETOPT "${GLFW_SOURCE_DIR}/deps/getopt.h" 19 | "${GLFW_SOURCE_DIR}/deps/getopt.c") 20 | set(TINYCTHREAD "${GLFW_SOURCE_DIR}/deps/tinycthread.h" 21 | "${GLFW_SOURCE_DIR}/deps/tinycthread.c") 22 | 23 | if (${CMAKE_VERSION} VERSION_EQUAL "3.1.0" OR 24 | ${CMAKE_VERSION} VERSION_GREATER "3.1.0") 25 | set(CMAKE_C_STANDARD 99) 26 | else() 27 | # Remove this fallback when removing support for CMake version less than 3.1 28 | add_compile_options("$<$:-std=c99>" 29 | "$<$:-std=c99>" 30 | "$<$:-std=c99>") 31 | 32 | endif() 33 | 34 | add_executable(clipboard clipboard.c ${GETOPT} ${GLAD_GL}) 35 | add_executable(events events.c ${GETOPT} ${GLAD_GL}) 36 | add_executable(msaa msaa.c ${GETOPT} ${GLAD_GL}) 37 | add_executable(glfwinfo glfwinfo.c ${GETOPT} ${GLAD_GL} ${GLAD_VULKAN}) 38 | add_executable(iconify iconify.c ${GETOPT} ${GLAD_GL}) 39 | add_executable(monitors monitors.c ${GETOPT} ${GLAD_GL}) 40 | add_executable(reopen reopen.c ${GLAD_GL}) 41 | add_executable(cursor cursor.c ${GLAD_GL}) 42 | 43 | add_executable(empty WIN32 MACOSX_BUNDLE empty.c ${TINYCTHREAD} ${GLAD_GL}) 44 | add_executable(gamma WIN32 MACOSX_BUNDLE gamma.c ${GLAD_GL}) 45 | add_executable(icon WIN32 MACOSX_BUNDLE icon.c ${GLAD_GL}) 46 | add_executable(inputlag WIN32 MACOSX_BUNDLE inputlag.c ${GETOPT} ${GLAD_GL}) 47 | add_executable(joysticks WIN32 MACOSX_BUNDLE joysticks.c ${GLAD_GL}) 48 | add_executable(opacity WIN32 MACOSX_BUNDLE opacity.c ${GLAD_GL}) 49 | add_executable(tearing WIN32 MACOSX_BUNDLE tearing.c ${GLAD_GL}) 50 | add_executable(threads WIN32 MACOSX_BUNDLE threads.c ${TINYCTHREAD} ${GLAD_GL}) 51 | add_executable(timeout WIN32 MACOSX_BUNDLE timeout.c ${GLAD_GL}) 52 | add_executable(title WIN32 MACOSX_BUNDLE title.c ${GLAD_GL}) 53 | add_executable(triangle-vulkan WIN32 triangle-vulkan.c ${GLAD_VULKAN}) 54 | add_executable(windows WIN32 MACOSX_BUNDLE windows.c ${GETOPT} ${GLAD_GL}) 55 | 56 | target_link_libraries(empty "${CMAKE_THREAD_LIBS_INIT}") 57 | target_link_libraries(threads "${CMAKE_THREAD_LIBS_INIT}") 58 | if (RT_LIBRARY) 59 | target_link_libraries(empty "${RT_LIBRARY}") 60 | target_link_libraries(threads "${RT_LIBRARY}") 61 | endif() 62 | 63 | set(GUI_ONLY_BINARIES empty gamma icon inputlag joysticks opacity tearing 64 | threads timeout title triangle-vulkan windows) 65 | set(CONSOLE_BINARIES clipboard events msaa glfwinfo iconify monitors reopen 66 | cursor) 67 | 68 | set_target_properties(${GUI_ONLY_BINARIES} ${CONSOLE_BINARIES} PROPERTIES 69 | FOLDER "GLFW3/Tests") 70 | 71 | if (MSVC) 72 | # Tell MSVC to use main instead of WinMain for Windows subsystem executables 73 | set_target_properties(${GUI_ONLY_BINARIES} PROPERTIES 74 | LINK_FLAGS "/ENTRY:mainCRTStartup") 75 | endif() 76 | 77 | if (APPLE) 78 | set_target_properties(empty PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Empty Event") 79 | set_target_properties(gamma PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Gamma") 80 | set_target_properties(inputlag PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Input Lag") 81 | set_target_properties(joysticks PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Joysticks") 82 | set_target_properties(opacity PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Opacity") 83 | set_target_properties(tearing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Tearing") 84 | set_target_properties(threads PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Threads") 85 | set_target_properties(timeout PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Timeout") 86 | set_target_properties(title PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Title") 87 | set_target_properties(windows PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Windows") 88 | 89 | set_target_properties(${GUI_ONLY_BINARIES} PROPERTIES 90 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${GLFW_VERSION} 91 | MACOSX_BUNDLE_LONG_VERSION_STRING ${GLFW_VERSION} 92 | MACOSX_BUNDLE_INFO_PLIST "${GLFW_SOURCE_DIR}/CMake/MacOSXBundleInfo.plist.in") 93 | endif() 94 | 95 | -------------------------------------------------------------------------------- /external/glfw/tests/clipboard.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Clipboard test program 3 | // Copyright (c) Camilla Löwy 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This program is used to test the clipboard functionality. 27 | // 28 | //======================================================================== 29 | 30 | #include 31 | #define GLFW_INCLUDE_NONE 32 | #include 33 | 34 | #include 35 | #include 36 | 37 | #include "getopt.h" 38 | 39 | #if defined(__APPLE__) 40 | #define MODIFIER GLFW_MOD_SUPER 41 | #else 42 | #define MODIFIER GLFW_MOD_CONTROL 43 | #endif 44 | 45 | static void usage(void) 46 | { 47 | printf("Usage: clipboard [-h]\n"); 48 | } 49 | 50 | static void error_callback(int error, const char* description) 51 | { 52 | fprintf(stderr, "Error: %s\n", description); 53 | } 54 | 55 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 56 | { 57 | if (action != GLFW_PRESS) 58 | return; 59 | 60 | switch (key) 61 | { 62 | case GLFW_KEY_ESCAPE: 63 | glfwSetWindowShouldClose(window, GLFW_TRUE); 64 | break; 65 | 66 | case GLFW_KEY_V: 67 | if (mods == MODIFIER) 68 | { 69 | const char* string; 70 | 71 | string = glfwGetClipboardString(NULL); 72 | if (string) 73 | printf("Clipboard contains \"%s\"\n", string); 74 | else 75 | printf("Clipboard does not contain a string\n"); 76 | } 77 | break; 78 | 79 | case GLFW_KEY_C: 80 | if (mods == MODIFIER) 81 | { 82 | const char* string = "Hello GLFW World!"; 83 | glfwSetClipboardString(NULL, string); 84 | printf("Setting clipboard to \"%s\"\n", string); 85 | } 86 | break; 87 | } 88 | } 89 | 90 | int main(int argc, char** argv) 91 | { 92 | int ch; 93 | GLFWwindow* window; 94 | 95 | while ((ch = getopt(argc, argv, "h")) != -1) 96 | { 97 | switch (ch) 98 | { 99 | case 'h': 100 | usage(); 101 | exit(EXIT_SUCCESS); 102 | 103 | default: 104 | usage(); 105 | exit(EXIT_FAILURE); 106 | } 107 | } 108 | 109 | glfwSetErrorCallback(error_callback); 110 | 111 | if (!glfwInit()) 112 | { 113 | fprintf(stderr, "Failed to initialize GLFW\n"); 114 | exit(EXIT_FAILURE); 115 | } 116 | 117 | window = glfwCreateWindow(200, 200, "Clipboard Test", NULL, NULL); 118 | if (!window) 119 | { 120 | glfwTerminate(); 121 | 122 | fprintf(stderr, "Failed to open GLFW window\n"); 123 | exit(EXIT_FAILURE); 124 | } 125 | 126 | glfwMakeContextCurrent(window); 127 | gladLoadGL(glfwGetProcAddress); 128 | glfwSwapInterval(1); 129 | 130 | glfwSetKeyCallback(window, key_callback); 131 | 132 | glClearColor(0.5f, 0.5f, 0.5f, 0); 133 | 134 | while (!glfwWindowShouldClose(window)) 135 | { 136 | glClear(GL_COLOR_BUFFER_BIT); 137 | 138 | glfwSwapBuffers(window); 139 | glfwWaitEvents(); 140 | } 141 | 142 | glfwTerminate(); 143 | exit(EXIT_SUCCESS); 144 | } 145 | 146 | -------------------------------------------------------------------------------- /external/glfw/tests/empty.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Empty event test 3 | // Copyright (c) Camilla Löwy 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test is intended to verify that posting of empty events works 27 | // 28 | //======================================================================== 29 | 30 | #include "tinycthread.h" 31 | 32 | #include 33 | #define GLFW_INCLUDE_NONE 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | static volatile int running = GLFW_TRUE; 41 | 42 | static void error_callback(int error, const char* description) 43 | { 44 | fprintf(stderr, "Error: %s\n", description); 45 | } 46 | 47 | static int thread_main(void* data) 48 | { 49 | struct timespec time; 50 | 51 | while (running) 52 | { 53 | clock_gettime(CLOCK_REALTIME, &time); 54 | time.tv_sec += 1; 55 | thrd_sleep(&time, NULL); 56 | 57 | glfwPostEmptyEvent(); 58 | } 59 | 60 | return 0; 61 | } 62 | 63 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 64 | { 65 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) 66 | glfwSetWindowShouldClose(window, GLFW_TRUE); 67 | } 68 | 69 | static float nrand(void) 70 | { 71 | return (float) rand() / (float) RAND_MAX; 72 | } 73 | 74 | int main(void) 75 | { 76 | int result; 77 | thrd_t thread; 78 | GLFWwindow* window; 79 | 80 | srand((unsigned int) time(NULL)); 81 | 82 | glfwSetErrorCallback(error_callback); 83 | 84 | if (!glfwInit()) 85 | exit(EXIT_FAILURE); 86 | 87 | window = glfwCreateWindow(640, 480, "Empty Event Test", NULL, NULL); 88 | if (!window) 89 | { 90 | glfwTerminate(); 91 | exit(EXIT_FAILURE); 92 | } 93 | 94 | glfwMakeContextCurrent(window); 95 | gladLoadGL(glfwGetProcAddress); 96 | glfwSetKeyCallback(window, key_callback); 97 | 98 | if (thrd_create(&thread, thread_main, NULL) != thrd_success) 99 | { 100 | fprintf(stderr, "Failed to create secondary thread\n"); 101 | 102 | glfwTerminate(); 103 | exit(EXIT_FAILURE); 104 | } 105 | 106 | while (running) 107 | { 108 | int width, height; 109 | float r = nrand(), g = nrand(), b = nrand(); 110 | float l = (float) sqrt(r * r + g * g + b * b); 111 | 112 | glfwGetFramebufferSize(window, &width, &height); 113 | 114 | glViewport(0, 0, width, height); 115 | glClearColor(r / l, g / l, b / l, 1.f); 116 | glClear(GL_COLOR_BUFFER_BIT); 117 | glfwSwapBuffers(window); 118 | 119 | glfwWaitEvents(); 120 | 121 | if (glfwWindowShouldClose(window)) 122 | running = GLFW_FALSE; 123 | } 124 | 125 | glfwHideWindow(window); 126 | thrd_join(thread, &result); 127 | glfwDestroyWindow(window); 128 | 129 | glfwTerminate(); 130 | exit(EXIT_SUCCESS); 131 | } 132 | 133 | -------------------------------------------------------------------------------- /external/glfw/tests/icon.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Window icon test program 3 | // Copyright (c) Camilla Löwy 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This program is used to test the icon feature. 27 | // 28 | //======================================================================== 29 | 30 | #include 31 | #define GLFW_INCLUDE_NONE 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | // a simple glfw logo 39 | const char* const logo[] = 40 | { 41 | "................", 42 | "................", 43 | "...0000..0......", 44 | "...0.....0......", 45 | "...0.00..0......", 46 | "...0..0..0......", 47 | "...0000..0000...", 48 | "................", 49 | "................", 50 | "...000..0...0...", 51 | "...0....0...0...", 52 | "...000..0.0.0...", 53 | "...0....0.0.0...", 54 | "...0....00000...", 55 | "................", 56 | "................" 57 | }; 58 | 59 | const unsigned char icon_colors[5][4] = 60 | { 61 | { 0, 0, 0, 255 }, // black 62 | { 255, 0, 0, 255 }, // red 63 | { 0, 255, 0, 255 }, // green 64 | { 0, 0, 255, 255 }, // blue 65 | { 255, 255, 255, 255 } // white 66 | }; 67 | 68 | static int cur_icon_color = 0; 69 | 70 | static void set_icon(GLFWwindow* window, int icon_color) 71 | { 72 | int x, y; 73 | unsigned char pixels[16 * 16 * 4]; 74 | unsigned char* target = pixels; 75 | GLFWimage img = { 16, 16, pixels }; 76 | 77 | for (y = 0; y < img.width; y++) 78 | { 79 | for (x = 0; x < img.height; x++) 80 | { 81 | if (logo[y][x] == '0') 82 | memcpy(target, icon_colors[icon_color], 4); 83 | else 84 | memset(target, 0, 4); 85 | 86 | target += 4; 87 | } 88 | } 89 | 90 | glfwSetWindowIcon(window, 1, &img); 91 | } 92 | 93 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 94 | { 95 | if (action != GLFW_PRESS) 96 | return; 97 | 98 | switch (key) 99 | { 100 | case GLFW_KEY_ESCAPE: 101 | glfwSetWindowShouldClose(window, GLFW_TRUE); 102 | break; 103 | case GLFW_KEY_SPACE: 104 | cur_icon_color = (cur_icon_color + 1) % 5; 105 | set_icon(window, cur_icon_color); 106 | break; 107 | case GLFW_KEY_X: 108 | glfwSetWindowIcon(window, 0, NULL); 109 | break; 110 | } 111 | } 112 | 113 | int main(int argc, char** argv) 114 | { 115 | GLFWwindow* window; 116 | 117 | if (!glfwInit()) 118 | { 119 | fprintf(stderr, "Failed to initialize GLFW\n"); 120 | exit(EXIT_FAILURE); 121 | } 122 | 123 | window = glfwCreateWindow(200, 200, "Window Icon", NULL, NULL); 124 | if (!window) 125 | { 126 | glfwTerminate(); 127 | 128 | fprintf(stderr, "Failed to open GLFW window\n"); 129 | exit(EXIT_FAILURE); 130 | } 131 | 132 | glfwMakeContextCurrent(window); 133 | gladLoadGL(glfwGetProcAddress); 134 | 135 | glfwSetKeyCallback(window, key_callback); 136 | set_icon(window, cur_icon_color); 137 | 138 | while (!glfwWindowShouldClose(window)) 139 | { 140 | glClear(GL_COLOR_BUFFER_BIT); 141 | glfwSwapBuffers(window); 142 | glfwWaitEvents(); 143 | } 144 | 145 | glfwDestroyWindow(window); 146 | glfwTerminate(); 147 | exit(EXIT_SUCCESS); 148 | } 149 | 150 | -------------------------------------------------------------------------------- /external/glfw/tests/opacity.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Window opacity test program 3 | // Copyright (c) Camilla Löwy 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | 26 | #include 27 | #define GLFW_INCLUDE_NONE 28 | #include 29 | 30 | #define NK_IMPLEMENTATION 31 | #define NK_INCLUDE_FIXED_TYPES 32 | #define NK_INCLUDE_FONT_BAKING 33 | #define NK_INCLUDE_DEFAULT_FONT 34 | #define NK_INCLUDE_DEFAULT_ALLOCATOR 35 | #define NK_INCLUDE_VERTEX_BUFFER_OUTPUT 36 | #define NK_INCLUDE_STANDARD_VARARGS 37 | #include 38 | 39 | #define NK_GLFW_GL2_IMPLEMENTATION 40 | #include 41 | 42 | #include 43 | #include 44 | 45 | static void error_callback(int error, const char* description) 46 | { 47 | fprintf(stderr, "Error: %s\n", description); 48 | } 49 | 50 | int main(int argc, char** argv) 51 | { 52 | GLFWwindow* window; 53 | struct nk_context* nk; 54 | struct nk_font_atlas* atlas; 55 | 56 | glfwSetErrorCallback(error_callback); 57 | 58 | if (!glfwInit()) 59 | exit(EXIT_FAILURE); 60 | 61 | glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE); 62 | 63 | window = glfwCreateWindow(400, 400, "Opacity", NULL, NULL); 64 | if (!window) 65 | { 66 | glfwTerminate(); 67 | exit(EXIT_FAILURE); 68 | } 69 | 70 | glfwMakeContextCurrent(window); 71 | gladLoadGL(glfwGetProcAddress); 72 | glfwSwapInterval(1); 73 | 74 | nk = nk_glfw3_init(window, NK_GLFW3_INSTALL_CALLBACKS); 75 | nk_glfw3_font_stash_begin(&atlas); 76 | nk_glfw3_font_stash_end(); 77 | 78 | while (!glfwWindowShouldClose(window)) 79 | { 80 | int width, height; 81 | struct nk_rect area; 82 | 83 | glfwGetWindowSize(window, &width, &height); 84 | area = nk_rect(0.f, 0.f, (float) width, (float) height); 85 | 86 | glClear(GL_COLOR_BUFFER_BIT); 87 | nk_glfw3_new_frame(); 88 | if (nk_begin(nk, "", area, 0)) 89 | { 90 | float opacity = glfwGetWindowOpacity(window); 91 | nk_layout_row_dynamic(nk, 30, 2); 92 | if (nk_slider_float(nk, 0.f, &opacity, 1.f, 0.001f)) 93 | glfwSetWindowOpacity(window, opacity); 94 | nk_labelf(nk, NK_TEXT_LEFT, "%0.3f", opacity); 95 | } 96 | 97 | nk_end(nk); 98 | nk_glfw3_render(NK_ANTI_ALIASING_ON); 99 | 100 | glfwSwapBuffers(window); 101 | glfwWaitEventsTimeout(1.0); 102 | } 103 | 104 | nk_glfw3_shutdown(); 105 | glfwTerminate(); 106 | exit(EXIT_SUCCESS); 107 | } 108 | 109 | -------------------------------------------------------------------------------- /external/glfw/tests/threads.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Multi-threading test 3 | // Copyright (c) Camilla Löwy 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test is intended to verify whether the OpenGL context part of 27 | // the GLFW API is able to be used from multiple threads 28 | // 29 | //======================================================================== 30 | 31 | #include "tinycthread.h" 32 | 33 | #include 34 | #define GLFW_INCLUDE_NONE 35 | #include 36 | 37 | #include 38 | #include 39 | #include 40 | 41 | typedef struct 42 | { 43 | GLFWwindow* window; 44 | const char* title; 45 | float r, g, b; 46 | thrd_t id; 47 | } Thread; 48 | 49 | static volatile int running = GLFW_TRUE; 50 | 51 | static void error_callback(int error, const char* description) 52 | { 53 | fprintf(stderr, "Error: %s\n", description); 54 | } 55 | 56 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 57 | { 58 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) 59 | glfwSetWindowShouldClose(window, GLFW_TRUE); 60 | } 61 | 62 | static int thread_main(void* data) 63 | { 64 | const Thread* thread = data; 65 | 66 | glfwMakeContextCurrent(thread->window); 67 | glfwSwapInterval(1); 68 | 69 | while (running) 70 | { 71 | const float v = (float) fabs(sin(glfwGetTime() * 2.f)); 72 | glClearColor(thread->r * v, thread->g * v, thread->b * v, 0.f); 73 | 74 | glClear(GL_COLOR_BUFFER_BIT); 75 | glfwSwapBuffers(thread->window); 76 | } 77 | 78 | glfwMakeContextCurrent(NULL); 79 | return 0; 80 | } 81 | 82 | int main(void) 83 | { 84 | int i, result; 85 | Thread threads[] = 86 | { 87 | { NULL, "Red", 1.f, 0.f, 0.f, 0 }, 88 | { NULL, "Green", 0.f, 1.f, 0.f, 0 }, 89 | { NULL, "Blue", 0.f, 0.f, 1.f, 0 } 90 | }; 91 | const int count = sizeof(threads) / sizeof(Thread); 92 | 93 | glfwSetErrorCallback(error_callback); 94 | 95 | if (!glfwInit()) 96 | exit(EXIT_FAILURE); 97 | 98 | glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); 99 | 100 | for (i = 0; i < count; i++) 101 | { 102 | threads[i].window = glfwCreateWindow(200, 200, 103 | threads[i].title, 104 | NULL, NULL); 105 | if (!threads[i].window) 106 | { 107 | glfwTerminate(); 108 | exit(EXIT_FAILURE); 109 | } 110 | 111 | glfwSetKeyCallback(threads[i].window, key_callback); 112 | 113 | glfwSetWindowPos(threads[i].window, 200 + 250 * i, 200); 114 | glfwShowWindow(threads[i].window); 115 | } 116 | 117 | glfwMakeContextCurrent(threads[0].window); 118 | gladLoadGL(glfwGetProcAddress); 119 | glfwMakeContextCurrent(NULL); 120 | 121 | for (i = 0; i < count; i++) 122 | { 123 | if (thrd_create(&threads[i].id, thread_main, threads + i) != 124 | thrd_success) 125 | { 126 | fprintf(stderr, "Failed to create secondary thread\n"); 127 | 128 | glfwTerminate(); 129 | exit(EXIT_FAILURE); 130 | } 131 | } 132 | 133 | while (running) 134 | { 135 | glfwWaitEvents(); 136 | 137 | for (i = 0; i < count; i++) 138 | { 139 | if (glfwWindowShouldClose(threads[i].window)) 140 | running = GLFW_FALSE; 141 | } 142 | } 143 | 144 | for (i = 0; i < count; i++) 145 | glfwHideWindow(threads[i].window); 146 | 147 | for (i = 0; i < count; i++) 148 | thrd_join(threads[i].id, &result); 149 | 150 | exit(EXIT_SUCCESS); 151 | } 152 | 153 | -------------------------------------------------------------------------------- /external/glfw/tests/timeout.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Event wait timeout test 3 | // Copyright (c) Camilla Löwy 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test is intended to verify that waiting for events with timeout works 27 | // 28 | //======================================================================== 29 | 30 | #include 31 | #define GLFW_INCLUDE_NONE 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | static void error_callback(int error, const char* description) 40 | { 41 | fprintf(stderr, "Error: %s\n", description); 42 | } 43 | 44 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 45 | { 46 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) 47 | glfwSetWindowShouldClose(window, GLFW_TRUE); 48 | } 49 | 50 | static float nrand(void) 51 | { 52 | return (float) rand() / (float) RAND_MAX; 53 | } 54 | 55 | int main(void) 56 | { 57 | GLFWwindow* window; 58 | 59 | srand((unsigned int) time(NULL)); 60 | 61 | glfwSetErrorCallback(error_callback); 62 | 63 | if (!glfwInit()) 64 | exit(EXIT_FAILURE); 65 | 66 | window = glfwCreateWindow(640, 480, "Event Wait Timeout Test", NULL, NULL); 67 | if (!window) 68 | { 69 | glfwTerminate(); 70 | exit(EXIT_FAILURE); 71 | } 72 | 73 | glfwMakeContextCurrent(window); 74 | gladLoadGL(glfwGetProcAddress); 75 | glfwSetKeyCallback(window, key_callback); 76 | 77 | while (!glfwWindowShouldClose(window)) 78 | { 79 | int width, height; 80 | float r = nrand(), g = nrand(), b = nrand(); 81 | float l = (float) sqrt(r * r + g * g + b * b); 82 | 83 | glfwGetFramebufferSize(window, &width, &height); 84 | 85 | glViewport(0, 0, width, height); 86 | glClearColor(r / l, g / l, b / l, 1.f); 87 | glClear(GL_COLOR_BUFFER_BIT); 88 | glfwSwapBuffers(window); 89 | 90 | glfwWaitEventsTimeout(1.0); 91 | } 92 | 93 | glfwDestroyWindow(window); 94 | 95 | glfwTerminate(); 96 | exit(EXIT_SUCCESS); 97 | } 98 | 99 | -------------------------------------------------------------------------------- /external/glfw/tests/title.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // UTF-8 window title test 3 | // Copyright (c) Camilla Löwy 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test sets a UTF-8 window title 27 | // 28 | //======================================================================== 29 | 30 | #include 31 | #define GLFW_INCLUDE_NONE 32 | #include 33 | 34 | #include 35 | #include 36 | 37 | static void error_callback(int error, const char* description) 38 | { 39 | fprintf(stderr, "Error: %s\n", description); 40 | } 41 | 42 | int main(void) 43 | { 44 | GLFWwindow* window; 45 | 46 | glfwSetErrorCallback(error_callback); 47 | 48 | if (!glfwInit()) 49 | exit(EXIT_FAILURE); 50 | 51 | window = glfwCreateWindow(400, 400, "English 日本語 русский язык 官話", NULL, NULL); 52 | if (!window) 53 | { 54 | glfwTerminate(); 55 | exit(EXIT_FAILURE); 56 | } 57 | 58 | glfwMakeContextCurrent(window); 59 | gladLoadGL(glfwGetProcAddress); 60 | glfwSwapInterval(1); 61 | 62 | while (!glfwWindowShouldClose(window)) 63 | { 64 | glClear(GL_COLOR_BUFFER_BIT); 65 | glfwSwapBuffers(window); 66 | glfwWaitEvents(); 67 | } 68 | 69 | glfwTerminate(); 70 | exit(EXIT_SUCCESS); 71 | } 72 | 73 | -------------------------------------------------------------------------------- /external/glfw/tests/windows.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Simple multi-window test 3 | // Copyright (c) Camilla Löwy 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test creates four windows and clears each in a different color 27 | // 28 | //======================================================================== 29 | 30 | #include 31 | #define GLFW_INCLUDE_NONE 32 | #include 33 | 34 | #include 35 | #include 36 | 37 | #include "getopt.h" 38 | 39 | static const char* titles[] = 40 | { 41 | "Red", 42 | "Green", 43 | "Blue", 44 | "Yellow" 45 | }; 46 | 47 | static const struct 48 | { 49 | float r, g, b; 50 | } colors[] = 51 | { 52 | { 0.95f, 0.32f, 0.11f }, 53 | { 0.50f, 0.80f, 0.16f }, 54 | { 0.f, 0.68f, 0.94f }, 55 | { 0.98f, 0.74f, 0.04f } 56 | }; 57 | 58 | static void usage(void) 59 | { 60 | printf("Usage: windows [-h] [-b] [-f] \n"); 61 | printf("Options:\n"); 62 | printf(" -b create decorated windows\n"); 63 | printf(" -f set focus on show off for all but first window\n"); 64 | printf(" -h show this help\n"); 65 | } 66 | 67 | static void error_callback(int error, const char* description) 68 | { 69 | fprintf(stderr, "Error: %s\n", description); 70 | } 71 | 72 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 73 | { 74 | if (action != GLFW_PRESS) 75 | return; 76 | 77 | switch (key) 78 | { 79 | case GLFW_KEY_SPACE: 80 | { 81 | int xpos, ypos; 82 | glfwGetWindowPos(window, &xpos, &ypos); 83 | glfwSetWindowPos(window, xpos, ypos); 84 | break; 85 | } 86 | 87 | case GLFW_KEY_ESCAPE: 88 | glfwSetWindowShouldClose(window, GLFW_TRUE); 89 | break; 90 | } 91 | } 92 | 93 | int main(int argc, char** argv) 94 | { 95 | int i, ch; 96 | int decorated = GLFW_FALSE; 97 | int focusOnShow = GLFW_TRUE; 98 | int running = GLFW_TRUE; 99 | GLFWwindow* windows[4]; 100 | 101 | while ((ch = getopt(argc, argv, "bfh")) != -1) 102 | { 103 | switch (ch) 104 | { 105 | case 'b': 106 | decorated = GLFW_TRUE; 107 | break; 108 | case 'f': 109 | focusOnShow = GLFW_FALSE; 110 | break; 111 | case 'h': 112 | usage(); 113 | exit(EXIT_SUCCESS); 114 | default: 115 | usage(); 116 | exit(EXIT_FAILURE); 117 | } 118 | } 119 | 120 | glfwSetErrorCallback(error_callback); 121 | 122 | if (!glfwInit()) 123 | exit(EXIT_FAILURE); 124 | 125 | glfwWindowHint(GLFW_DECORATED, decorated); 126 | glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); 127 | 128 | for (i = 0; i < 4; i++) 129 | { 130 | int left, top, right, bottom; 131 | if (i) 132 | glfwWindowHint(GLFW_FOCUS_ON_SHOW, focusOnShow); 133 | 134 | windows[i] = glfwCreateWindow(200, 200, titles[i], NULL, NULL); 135 | if (!windows[i]) 136 | { 137 | glfwTerminate(); 138 | exit(EXIT_FAILURE); 139 | } 140 | 141 | glfwSetKeyCallback(windows[i], key_callback); 142 | 143 | glfwMakeContextCurrent(windows[i]); 144 | gladLoadGL(glfwGetProcAddress); 145 | glClearColor(colors[i].r, colors[i].g, colors[i].b, 1.f); 146 | 147 | glfwGetWindowFrameSize(windows[i], &left, &top, &right, &bottom); 148 | glfwSetWindowPos(windows[i], 149 | 100 + (i & 1) * (200 + left + right), 150 | 100 + (i >> 1) * (200 + top + bottom)); 151 | } 152 | 153 | for (i = 0; i < 4; i++) 154 | glfwShowWindow(windows[i]); 155 | 156 | while (running) 157 | { 158 | for (i = 0; i < 4; i++) 159 | { 160 | glfwMakeContextCurrent(windows[i]); 161 | glClear(GL_COLOR_BUFFER_BIT); 162 | glfwSwapBuffers(windows[i]); 163 | 164 | if (glfwWindowShouldClose(windows[i])) 165 | running = GLFW_FALSE; 166 | } 167 | 168 | glfwWaitEvents(); 169 | } 170 | 171 | glfwTerminate(); 172 | exit(EXIT_SUCCESS); 173 | } 174 | 175 | -------------------------------------------------------------------------------- /external/stb_image/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(STB_SRC 2 | "${CMAKE_CURRENT_SOURCE_DIR}/stb_impl.cpp" 3 | ) 4 | 5 | set(STB_HDR 6 | "${CMAKE_CURRENT_SOURCE_DIR}/stb_image_write.h" 7 | "${CMAKE_CURRENT_SOURCE_DIR}/stb_image.h" 8 | ) 9 | 10 | source_group( TREE ${CMAKE_CURRENT_SOURCE_DIR} 11 | FILES ${STB_SRC} ${STB_HDR} ) 12 | 13 | add_library(stb_image STATIC ${STB_SRC} ${STB_HDR} ) 14 | target_include_directories( stb_image PUBLIC 15 | $ 16 | ) 17 | 18 | target_compile_features( stb_image PUBLIC cxx_std_20 ) 19 | set_target_properties( stb_image PROPERTIES CXX_EXTENSIONS OFF ) 20 | -------------------------------------------------------------------------------- /external/stb_image/stb_impl.cpp: -------------------------------------------------------------------------------- 1 | #define STB_IMAGE_WRITE_IMPLEMENTATION 2 | #include "stb_image_write.h" 3 | 4 | #define STB_IMAGE_IMPLEMENTATION 5 | #include "stb_image.h" 6 | 7 | -------------------------------------------------------------------------------- /external/tiny_obj_loader/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(TINY_OBJ_SRC 2 | "${CMAKE_CURRENT_SOURCE_DIR}/tiny_obj_loader.cpp" 3 | ) 4 | 5 | set(TINY_OBJ_HDR 6 | "${CMAKE_CURRENT_SOURCE_DIR}/tiny_obj_loader.h" 7 | ) 8 | 9 | source_group( TREE ${CMAKE_CURRENT_SOURCE_DIR} 10 | FILES ${TINY_OBJ_SRC} ${TINY_OBJ_HDR} ) 11 | 12 | add_library(tiny_obj STATIC ${TINY_OBJ_SRC} ${TINY_OBJ_HDR} ) 13 | target_include_directories( tiny_obj PUBLIC 14 | $ 15 | ) 16 | 17 | target_compile_features( tiny_obj PUBLIC cxx_std_17 ) 18 | set_target_properties( tiny_obj PROPERTIES CXX_EXTENSIONS OFF ) 19 | -------------------------------------------------------------------------------- /external/tiny_obj_loader/tiny_obj_loader.cpp: -------------------------------------------------------------------------------- 1 | #define TINYOBJLOADER_IMPLEMENTATION 2 | #include "tiny_obj_loader.h" -------------------------------------------------------------------------------- /img/00_triangle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/img/00_triangle.png -------------------------------------------------------------------------------- /img/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/img/banner.png -------------------------------------------------------------------------------- /img/example_ao_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/img/example_ao_map.png -------------------------------------------------------------------------------- /img/example_blinn_phong.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/img/example_blinn_phong.jpg -------------------------------------------------------------------------------- /img/example_cel_shading.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/img/example_cel_shading.png -------------------------------------------------------------------------------- /img/example_model.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/img/example_model.jpg -------------------------------------------------------------------------------- /img/example_normal_mapping.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/img/example_normal_mapping.png -------------------------------------------------------------------------------- /img/example_pbr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/img/example_pbr.png -------------------------------------------------------------------------------- /img/example_shadow_mapping.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/img/example_shadow_mapping.png -------------------------------------------------------------------------------- /img/example_ssao.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikolausrauch/software-rasterizer/1637c50297316ede45af529e24cdf09e004c43af/img/example_ssao.png -------------------------------------------------------------------------------- /rasterizer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ######################################### 2 | # CPU Software Rasterizer # 3 | #---------------------------------------# 4 | # @author Nikolaus Rauch # 5 | # @date 14.12.2021 # 6 | ######################################### 7 | project( rasterizer ) 8 | 9 | ################################# 10 | # Viewer Source Files # 11 | ################################# 12 | set( SRC 13 | "${CMAKE_CURRENT_SOURCE_DIR}/renderer.cpp" 14 | "${CMAKE_CURRENT_SOURCE_DIR}/texture.cpp" 15 | 16 | "${CMAKE_CURRENT_SOURCE_DIR}/math/utility.cpp" 17 | ) 18 | 19 | set( HDR 20 | "${CMAKE_CURRENT_SOURCE_DIR}/renderer.h" 21 | 22 | "${CMAKE_CURRENT_SOURCE_DIR}/buffer.h" 23 | "${CMAKE_CURRENT_SOURCE_DIR}/program.h" 24 | "${CMAKE_CURRENT_SOURCE_DIR}/texture.h" 25 | "${CMAKE_CURRENT_SOURCE_DIR}/sampler.h" 26 | "${CMAKE_CURRENT_SOURCE_DIR}/framebuffer.h" 27 | 28 | "${CMAKE_CURRENT_SOURCE_DIR}/math/base.h" 29 | "${CMAKE_CURRENT_SOURCE_DIR}/math/vector2.h" 30 | "${CMAKE_CURRENT_SOURCE_DIR}/math/vector3.h" 31 | "${CMAKE_CURRENT_SOURCE_DIR}/math/vector4.h" 32 | "${CMAKE_CURRENT_SOURCE_DIR}/math/matrix3.h" 33 | "${CMAKE_CURRENT_SOURCE_DIR}/math/matrix4.h" 34 | "${CMAKE_CURRENT_SOURCE_DIR}/math/utility.h" 35 | "${CMAKE_CURRENT_SOURCE_DIR}/math/rectangle.h" 36 | 37 | "${CMAKE_CURRENT_SOURCE_DIR}/detail/test_member.h" 38 | "${CMAKE_CURRENT_SOURCE_DIR}/detail/tuple_helper.h" 39 | ) 40 | 41 | set( RASTERIZER_SRC ${SRC} ) 42 | set( RASTERIZER_HDR ${HDR} ) 43 | 44 | source_group( TREE ${CMAKE_CURRENT_SOURCE_DIR} 45 | FILES ${VIEWER_SRC} ${VIEWER_HDR} ) 46 | 47 | 48 | ################################# 49 | # Build Viewer Library # 50 | ################################# 51 | add_library( rasterizer_static STATIC ${RASTERIZER_SRC} ${RASTERIZER_HDR} ) 52 | 53 | target_link_libraries( rasterizer_static PUBLIC stb_image ) 54 | 55 | target_include_directories( rasterizer_static PUBLIC 56 | $ 57 | ) 58 | 59 | target_compile_features( rasterizer_static PUBLIC cxx_std_20 ) 60 | set_target_properties( rasterizer_static PROPERTIES CXX_EXTENSIONS OFF ) 61 | -------------------------------------------------------------------------------- /rasterizer/buffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | enum class ePrimitive 6 | { 7 | TRIANGLES, 8 | LINES 9 | }; 10 | 11 | template 12 | struct Buffer 13 | { 14 | ePrimitive primitive = ePrimitive::TRIANGLES; 15 | std::vector vertices; 16 | }; 17 | 18 | 19 | template 20 | struct BufferIndexed : public Buffer 21 | { 22 | std::vector indices; 23 | }; 24 | -------------------------------------------------------------------------------- /rasterizer/detail/test_member.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace detail 4 | { 5 | 6 | template 7 | struct has_member 8 | { 9 | typedef char one; 10 | struct two { char _x[2]; }; 11 | 12 | #define test_one(name) template static one test_##name( decltype (&C::name) ); 13 | #define test_two(name) template static two test_##name(...); 14 | #define test_value(name) struct name{ enum { value = sizeof( test_##name(0) ) == sizeof(char) }; }; 15 | #define property(name) test_one(name) test_two(name) test_value(name) 16 | 17 | /* vertex members */ 18 | property(position) 19 | property(_reflect) 20 | 21 | 22 | #undef test_one 23 | #undef test_two 24 | #undef test_value 25 | #undef property 26 | }; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /rasterizer/detail/tuple_helper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace detail 10 | { 11 | 12 | template 13 | void tuple_iter_impl(const Func& func, const T& v0, const T& v1, const T& v2, T& result, std::index_sequence) 14 | { 15 | (func(std::get(v0), std::get(v1), std::get(v2), std::get(result)), ...); 16 | } 17 | 18 | template > 19 | void tuple_iter(const Func& func, const T& v0, const T& v1, const T& v2, T& res) 20 | { 21 | tuple_iter_impl(func, v0, v1, v2, res, std::make_index_sequence{}); 22 | } 23 | 24 | 25 | template 26 | void tuple_iter_impl(const Func& func, const T& v0, const T& v1, T& result, std::index_sequence) 27 | { 28 | (func(std::get(v0), std::get(v1), std::get(result)), ...); 29 | } 30 | 31 | template > 32 | void tuple_iter(const Func& func, const T& v0, const T& v1, T& res) 33 | { 34 | tuple_iter_impl(func, v0, v1, res, std::make_index_sequence{}); 35 | } 36 | 37 | 38 | template 39 | void tuple_iter_impl(const Func& func, T& value, std::index_sequence) 40 | { 41 | (func(std::get(value)), ...); 42 | } 43 | 44 | template > 45 | void tuple_iter(const Func& func, T& value) 46 | { 47 | tuple_iter_impl(func, value, std::make_index_sequence{}); 48 | } 49 | 50 | 51 | template 52 | struct tuple_has_type; 53 | 54 | template 55 | struct tuple_has_type> : std::disjunction...> {}; 56 | 57 | 58 | 59 | template 60 | struct tuple_index; 61 | 62 | template 63 | struct tuple_index> 64 | { 65 | static constexpr std::size_t index = []() 66 | { 67 | static_assert(tuple_has_type>::value, "Couldn't find searched type in tuple!" ); 68 | 69 | constexpr std::array a{{ std::is_same::value... }}; 70 | const auto it = std::find(a.begin(), a.end(), true); 71 | return std::distance(a.begin(), it); 72 | }(); 73 | }; 74 | 75 | 76 | template 77 | auto tuple_construct(const Func& func, T& t, std::index_sequence) 78 | { 79 | return std::forward_as_tuple( func(std::get(t))... ); 80 | } 81 | 82 | template > 83 | auto tuple_construct(const Func& func, T& value) 84 | { 85 | return tuple_construct(func, value, std::make_index_sequence{}); 86 | } 87 | 88 | 89 | } 90 | -------------------------------------------------------------------------------- /rasterizer/framebuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "texture.h" 4 | #include "math/vector4.h" 5 | #include "detail/tuple_helper.h" 6 | 7 | #include 8 | 9 | 10 | template 11 | struct Framebuffer 12 | { 13 | using TargetStorage = std::tuple< Texture... >; 14 | using TargetFragments = std::tuple< Targets&... >; 15 | 16 | template using HasTarget = std::enable_if_t< detail::tuple_has_type::value >; 17 | 18 | static constexpr bool has_color = detail::tuple_has_type< Texture, TargetStorage>::value; 19 | static constexpr bool has_depth = detail::tuple_has_type< Texture, TargetStorage>::value; 20 | 21 | 22 | Framebuffer(unsigned int width, unsigned int height) 23 | : m_width(width), m_height(height), m_targets(Texture(width, height)...) 24 | { 25 | 26 | } 27 | 28 | template 29 | auto& target() 30 | { 31 | return std::get(m_targets); 32 | } 33 | 34 | TargetStorage& targets() 35 | { 36 | return m_targets; 37 | } 38 | 39 | TargetFragments targets(int x, int y) 40 | { 41 | return detail::tuple_construct([x, y](auto& ts) -> auto& { return ts(x,y); }, m_targets); 42 | } 43 | 44 | template, typename = HasTarget> Texture& color() 45 | { 46 | return std::get< detail::tuple_index, TargetStorage>::index >(m_targets); 47 | } 48 | 49 | template, typename = HasTarget> Texture& depth() 50 | { 51 | return std::get< detail::tuple_index, TargetStorage>::index >(m_targets); 52 | } 53 | 54 | void clear(const RGBA8& color) 55 | { 56 | detail::tuple_iter([color](auto& target) 57 | { 58 | if constexpr (std::is_same_v::type, Texture>) 59 | { 60 | target.fill(color); 61 | } 62 | 63 | if constexpr (std::is_same_v::type, Texture>) 64 | { 65 | target.fill({ std::numeric_limits::max() }); 66 | } 67 | 68 | }, m_targets); 69 | } 70 | 71 | void clear(const Vec4& color) 72 | { 73 | clear(RGBA8(color * 255)); 74 | } 75 | 76 | void clear() 77 | { 78 | clear(RGBA8()); 79 | } 80 | 81 | private: 82 | int m_width; 83 | int m_height; 84 | TargetStorage m_targets; 85 | }; 86 | 87 | using DefaultFramebuffer = Framebuffer; 88 | -------------------------------------------------------------------------------- /rasterizer/math/base.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define _USE_MATH_DEFINES 4 | #include /* c-header as msvc seems to have an issue with cmath */ 5 | #include 6 | #include 7 | 8 | inline constexpr float PI = 3.1415926535897932384626433832795; 9 | inline constexpr float PI_two = 6.2831853071795864769252867665590; 10 | inline constexpr float PI_half = 1.5707963267948966192313216916398; 11 | 12 | #define degrees(x) (x * 180.0 / PI) 13 | #define radians(x) (x * PI / 180.0) 14 | -------------------------------------------------------------------------------- /rasterizer/math/rectangle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "base.h" 4 | 5 | #include "vector2.h" 6 | 7 | template 8 | struct Rectangle 9 | { 10 | Vector2 min; 11 | Vector2 max; 12 | 13 | Rectangle(T min_x, T min_y, T max_x, T max_y) 14 | : min(min_x, min_y), max(max_x, max_y) 15 | { 16 | 17 | } 18 | 19 | Rectangle(const Vector2& min, const Vector2& max) 20 | : min(min), max(max) 21 | { 22 | 23 | } 24 | 25 | Rectangle(const Vector2& p_0, const Vector2& p_1, const Vector2& p_2) 26 | : Rectangle(std::numeric_limits::max(), std::numeric_limits::max(), std::numeric_limits::min(), std::numeric_limits::min()) 27 | { 28 | merge(p_0); 29 | merge(p_1); 30 | merge(p_2); 31 | } 32 | 33 | template 34 | bool contains(const Vector2& point) 35 | { 36 | return (point.x >= min.x && point.x < max.x ) && 37 | (point.y >= min.y && point.y < max.y ); 38 | } 39 | 40 | template 41 | void merge(const Vector2& p) 42 | { 43 | min.x = std::min(min.x, p.x); 44 | min.y = std::min(min.y, p.y); 45 | 46 | max.x = std::max(max.x, p.x); 47 | max.y = std::max(max.y, p.y); 48 | } 49 | 50 | template 51 | void merge(const Vector2& p_0, const Vector2& p_1, const Vector2& p_2) 52 | { 53 | merge(p_0); 54 | merge(p_1); 55 | merge(p_2); 56 | } 57 | 58 | template 59 | void clamp(const Rectangle& border, T pad_min = 0, T pad_max = 0) 60 | { 61 | min.x = std::max(border.min.x + pad_min, min.x); 62 | min.y = std::max(border.min.y + pad_min, min.y); 63 | 64 | max.x = std::min(border.max.x + pad_max, max.x); 65 | max.y = std::min(border.max.y + pad_max, max.y); 66 | } 67 | 68 | friend std::ostream& operator<<(std::ostream& os, const Rectangle& rec) 69 | { 70 | return os << "{" << rec.min.x << ", " << rec.min.y << " | " << rec.max.x << ", " << rec.max.y << "}"; 71 | } 72 | }; 73 | 74 | template 75 | Vector2 clamp(const Rectangle& border, const Vector2& point, T pad_min = 0, T pad_max = 0) 76 | { 77 | return { std::clamp(point.x, border.min.x + pad_min, border.max.x + pad_max), std::clamp(point.y, border.min.y + pad_min, border.max.y + pad_max) }; 78 | } 79 | 80 | typedef Rectangle Recti; 81 | typedef Rectangle Rectf; 82 | -------------------------------------------------------------------------------- /rasterizer/math/utility.cpp: -------------------------------------------------------------------------------- 1 | #include "utility.h" 2 | 3 | Vec2 equirectangularUV(const Vec3& dir) 4 | { 5 | float phi = atan2(dir.x, dir.z); 6 | float theta = asin(dir.y); 7 | return Vec2((phi + PI) / (2.0 * PI), (theta + 0.5 * PI) / PI); 8 | } 9 | 10 | Vec3 equirectangulatDir(Vec2 pixel, Vec2i size) 11 | { 12 | float phi = ( pixel.x / size.x * 2.0 * PI ) - PI; 13 | float theta = ( pixel.y / size.y * PI) - 0.5 * PI; 14 | return Vec3{std::cos(theta) * std::sin(phi), std::sin(theta), std::cos(theta) * std::cos(phi)}; 15 | } 16 | -------------------------------------------------------------------------------- /rasterizer/math/utility.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "vector2.h" 4 | #include "vector3.h" 5 | #include "vector4.h" 6 | 7 | Vec2 equirectangularUV(const Vec3& dir); 8 | Vec3 equirectangulatDir(Vec2 pixel, Vec2i size); 9 | 10 | 11 | template 12 | Vec3 barycentric(const Vector2& a, const Vector2& b, const Vector2& c, const Vector2& p) 13 | { 14 | auto v_0 = b - a; 15 | auto v_1 = c - a; 16 | auto v_2 = p - a; 17 | 18 | float D = v_0.x * v_1.y - v_1.x * v_0.y; 19 | 20 | float v = (v_2.x * v_1.y - v_1.x * v_2.y) / D; 21 | float w = (v_0.x * v_2.y - v_2.x * v_0.y) / D; 22 | float u = 1.0f - v - w; 23 | 24 | return {u, v, w}; 25 | } 26 | 27 | template 28 | Vec3 barycentric(const Vector3& a, const Vector3& b, const Vector3& c, const Vector3& p) 29 | { 30 | auto v_0 = b - a; 31 | auto v_1 = c - a; 32 | auto v_2 = p - a; 33 | 34 | float d_00 = dot(v_0, v_0); 35 | float d_01 = dot(v_0, v_1); 36 | float d_11 = dot(v_1, v_1); 37 | float d_20 = dot(v_2, v_0); 38 | float d_21 = dot(v_2, v_1); 39 | 40 | float D = d_00 * d_11 - d_01 * d_01; 41 | 42 | float v = (d_11 * d_20 - d_01 * d_21) / D; 43 | float w = (d_00 * d_21 - d_01 * d_20) / D; 44 | float u = 1.0f - v - w; 45 | 46 | return {u, v, w}; 47 | } 48 | -------------------------------------------------------------------------------- /rasterizer/program.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "detail/test_member.h" 4 | 5 | #include "math/vector4.h" 6 | 7 | #include "framebuffer.h" 8 | 9 | #include 10 | 11 | template 12 | struct Program 13 | { 14 | static_assert (detail::has_member::position::value, "Output of Vertex Stage needs Vec4 position!"); 15 | static_assert (detail::has_member::_reflect::value, "Output of Vertex Stage needs interpolated positional values. Did you forget to set VARYING(position) macro? "); 16 | 17 | 18 | using VertexShader = std::function< void (const Uniforms& uniforms, const Vertex& in, Varying& out) >; 19 | 20 | using FragmentShader = std::conditional_t, 21 | std::function< void (const Uniforms& uniforms, const Varying& in, Vec4& out) >, 22 | std::function< void (const Uniforms& uniforms, const Varying& in, typename FrameTargets::TargetFragments& out) >>; 23 | 24 | 25 | void onVertex(const VertexShader& shader) { m_vertShader = shader; } 26 | void onFragment(const FragmentShader& shader) { m_fragShader = shader; } 27 | Uniforms& uniforms() { return m_uniforms; } 28 | 29 | private: 30 | VertexShader m_vertShader; 31 | FragmentShader m_fragShader; 32 | Uniforms m_uniforms; 33 | 34 | friend struct Renderer; 35 | }; 36 | -------------------------------------------------------------------------------- /rasterizer/renderer.cpp: -------------------------------------------------------------------------------- 1 | #include "renderer.h" 2 | 3 | Renderer::Renderer(unsigned int width, unsigned int height) 4 | : m_framebuffer(width, height), 5 | m_options{ {0, 0, static_cast(width), static_cast(height)}, true, false } 6 | { 7 | m_framebuffer.clear(RGBA8(0, 0, 0, 0)); 8 | } 9 | 10 | DefaultFramebuffer &Renderer::framebuffer() 11 | { 12 | return m_framebuffer; 13 | } 14 | 15 | Renderer::Options& Renderer::options() 16 | { 17 | return m_options; 18 | } 19 | -------------------------------------------------------------------------------- /rasterizer/sampler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "texture.h" 4 | 5 | #include 6 | 7 | template struct Sampler; 8 | template T texture(const Sampler& sampler, const Vec2& uv); 9 | 10 | 11 | enum class eFilter 12 | { 13 | NEAREST, 14 | LINEAR, 15 | NEAREST_MIPMAP_LINEAR, 16 | LINEAR_MIPMAP_NEAREST, 17 | }; 18 | 19 | enum class eWrap 20 | { 21 | REPEAT, 22 | CLAMP_EDGE 23 | }; 24 | 25 | 26 | template 27 | struct Sampler 28 | { 29 | Sampler() : m_texture(nullptr) {} 30 | 31 | Sampler(Texture& texture) : m_texture(&texture) {} 32 | 33 | Sampler& operator =(Texture& texture) 34 | { 35 | m_texture = &texture; 36 | return *this; 37 | } 38 | 39 | Sampler& operator =(const Texture& texture) 40 | { 41 | m_texture = &texture; 42 | } 43 | 44 | 45 | public: 46 | eFilter filter = eFilter::LINEAR; 47 | eWrap wrap = eWrap::CLAMP_EDGE; 48 | 49 | public: 50 | const Texture* m_texture; 51 | 52 | friend T texture<>(const Sampler& sampler, const Vec2& uv); 53 | }; 54 | 55 | template 56 | T sample_texture(const TextureStorage& textureStorage, const Vec2& uv, eWrap wrap, eFilter filter) 57 | { 58 | /* map based on wrap option to new uv coordinates */ 59 | auto proj_uv = uv; 60 | if(wrap == eWrap::CLAMP_EDGE) 61 | { 62 | proj_uv = clamp(uv, {0.0f, 0.0f}, {1.0f, 1.0f}); 63 | } 64 | else if(wrap == eWrap::REPEAT) 65 | { 66 | proj_uv = { std::fmod(uv.x, 1.0f), std::fmod(uv.y, 1.0f) }; 67 | proj_uv = { std::fmod(1.0 + proj_uv.x, 1.0f), std::fmod(1.0 + proj_uv.y, 1.0f) }; 68 | } 69 | 70 | /* query texture data with filter */ 71 | int width = textureStorage.width(); 72 | int height = textureStorage.height(); 73 | 74 | if(filter == eFilter::NEAREST || filter == eFilter::LINEAR_MIPMAP_NEAREST) 75 | { 76 | Vec2i coord(std::round(proj_uv.x * width - 0.5f), std::round(proj_uv.y * height - 0.5f) ); 77 | coord.x = std::clamp(coord.x, 0, width - 1); 78 | coord.y = std::clamp(coord.y, 0, height - 1); 79 | 80 | return textureStorage(coord.x, coord.y); 81 | } 82 | else if(filter == eFilter::LINEAR || filter == eFilter::NEAREST_MIPMAP_LINEAR) 83 | { 84 | /* TODO: apply wrapping for interpolation coords */ 85 | Vec2 coord = Vec2(proj_uv.x * width - 0.5f, proj_uv.y * height - 0.5f); 86 | Vec2 lower(int(coord.x), int(coord.y)); 87 | Vec2 upper(lower.x + 1, lower.y + 1); 88 | 89 | upper.x = std::clamp(upper.x, 0, width - 1); 90 | upper.y = std::clamp(upper.y, 0, height - 1); 91 | 92 | coord = coord - lower; 93 | 94 | auto color_00 = textureStorage(lower.x, lower.y); 95 | auto color_10 = textureStorage(upper.x, lower.y); 96 | auto color_01 = textureStorage(lower.x, upper.y); 97 | auto color_11 = textureStorage(upper.x, upper.y); 98 | 99 | auto color_0 = color_00 * (1.0f - coord.x) + color_10 * coord.x; 100 | auto color_1 = color_01 * (1.0f - coord.x) + color_11 * coord.x; 101 | 102 | return color_0 * (1.0f - coord.y) + color_1 * coord.y; 103 | } 104 | 105 | return T(); 106 | } 107 | 108 | template 109 | T texture(const Sampler& sampler, const Vec2& uv) 110 | { 111 | assert(sampler.m_texture != nullptr); 112 | return sample_texture(sampler.m_texture->mipmaps().front(), uv, sampler.wrap, sampler.filter); 113 | } 114 | 115 | template 116 | T textureLod(const Sampler& sampler, const Vec2& uv, float level) 117 | { 118 | float sample_level = std::clamp(level, 0.0f, static_cast(sampler.m_texture->num_mipmaps() - 1)); 119 | if(sampler.filter == eFilter::NEAREST || sampler.filter == eFilter::NEAREST_MIPMAP_LINEAR) 120 | { 121 | sample_level = std::round(sample_level); 122 | return sample_texture(sampler.m_texture->mipmaps().at(sample_level), uv, sampler.wrap, sampler.filter); 123 | } 124 | else 125 | { 126 | float floor_level = std::floor(sample_level); 127 | float ceil_level = std::ceil(sample_level); 128 | float weight = ceil_level - sample_level; 129 | 130 | auto floor_sample = sample_texture(sampler.m_texture->mipmaps().at(floor_level), uv, sampler.wrap, sampler.filter); 131 | auto ceil_sample = sample_texture(sampler.m_texture->mipmaps().at(ceil_level), uv, sampler.wrap, sampler.filter); 132 | return weight * ceil_sample + (1.0f - weight) * floor_sample; 133 | } 134 | } 135 | 136 | template 137 | Vec2i textureSize( const Sampler& sampler ) 138 | { 139 | return Vec2i( sampler.m_texture->width(), sampler.m_texture->height() ); 140 | } 141 | 142 | template 143 | Vec2 textureInvSize( const Sampler& sampler ) 144 | { 145 | return Vec2( 1.0f / sampler.m_texture->width(), 1.0f / sampler.m_texture->height() ); 146 | } 147 | --------------------------------------------------------------------------------