├── .editorconfig ├── .github └── workflows │ ├── build_release.yml │ └── main.yml ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── LICENSE ├── README.md ├── Shaders ├── basic_specgloss.fs ├── basic_specgloss.vs ├── pbr.fs └── pbr.vs ├── Skyboxes ├── Barce_Rooftop_C_3k.hdr ├── Barce_Rooftop_C_Env.hdr ├── Barcelona_Rooftops.ibl ├── GCanyon_C_YumaPoint_3k.hdr ├── GCanyon_C_YumaPoint_Env.hdr ├── GrandCanyon_C_YumaPoint.ibl ├── Tokyo_BigSight.ibl ├── Tokyo_BigSight_3k.hdr ├── Tokyo_BigSight_Env.hdr ├── brdf256.bin ├── skysphere.fbx ├── skysphere.fs └── skysphere.vs ├── cmake_all.bat ├── config.json ├── data └── windows │ ├── SetupDialog.rc │ └── resource.h ├── externals └── glew │ ├── GL │ ├── glew.h │ ├── glxew.h │ └── wglew.h │ ├── LICENSE.txt │ └── glew.c ├── file_id.diz └── src ├── Geometry.cpp ├── Geometry.h ├── Main.cpp ├── Renderer.cpp ├── Renderer.h ├── SetupDialog.h ├── platform_common └── SetupDialog.cpp └── platform_w32 └── SetupDialog.cpp /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | indent_style = space 3 | indent_size = 2 4 | tab_width = 2 -------------------------------------------------------------------------------- /.github/workflows/build_release.yml: -------------------------------------------------------------------------------- 1 | name: build-release 2 | on: [workflow_dispatch] 3 | jobs: 4 | create_release: 5 | runs-on: windows-latest 6 | steps: 7 | - name: Get date 8 | id: date 9 | run: | 10 | echo "date=$(date +"%Y-%m-%d")" >> $env:GITHUB_OUTPUT 11 | - name: Checkout 12 | uses: actions/checkout@v4 13 | with: 14 | submodules: recursive 15 | - name: Create subdirs 16 | run: | 17 | mkdir ./build.x64/ 18 | mkdir ./build.w32/ 19 | mkdir ./package/ 20 | - name: CMake X64 21 | working-directory: ./build.x64 22 | run: cmake -DFOXOTRON_64BIT="YES" -G "Visual Studio 17 2022" -A x64 ../ 23 | - name: Build X64 24 | working-directory: ./build.x64 25 | run: cmake --build . --config Release 26 | - name: CMake W32 27 | working-directory: ./build.w32 28 | run: cmake -DFOXOTRON_64BIT="NO" -G "Visual Studio 17 2022" -A Win32 ../ 29 | - name: Build W32 30 | working-directory: ./build.w32 31 | run: cmake --build . --config Release 32 | - name: Collect package 33 | working-directory: ./package/ 34 | run: | 35 | cp ../build.x64/Release/Foxotron.exe ./Foxotron_W64.exe 36 | cp ../build.w32/Release/Foxotron.exe ./Foxotron_W32.exe 37 | cp ../LICENSE ./ 38 | cp ../config.json ./ 39 | cp ../README.md ./ 40 | cp ../file_id.diz ./ 41 | cp -r ../Shaders ./ 42 | cp -r ../Skyboxes ./ 43 | - name: ZIP package 44 | working-directory: ./package/ 45 | run: 7z a -r -tzip archive.zip * -mx9 46 | - name: Create Release 47 | id: create_release 48 | uses: actions/create-release@v1 49 | env: 50 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 51 | with: 52 | tag_name: ${{ steps.date.outputs.date }} 53 | release_name: ${{ steps.date.outputs.date }} 54 | draft: true 55 | - name: Upload Release Asset 56 | id: upload-release-asset 57 | uses: actions/upload-release-asset@v1 58 | env: 59 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 60 | with: 61 | upload_url: ${{ steps.create_release.outputs.upload_url }} 62 | asset_path: ./package//archive.zip 63 | asset_name: Foxotron_${{ steps.date.outputs.date }}.zip 64 | asset_content_type: application/zip 65 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: build-on-push 2 | on: [push] 3 | jobs: 4 | build_w32: 5 | runs-on: windows-latest 6 | steps: 7 | - name: Checkout 8 | uses: actions/checkout@v4 9 | with: 10 | submodules: recursive 11 | - name: CMake 12 | run: cmake -DFOXOTRON_64BIT="NO" -G "Visual Studio 17 2022" -A Win32 . 13 | - name: Build 14 | run: cmake --build . --config Release 15 | build_w64: 16 | runs-on: windows-latest 17 | steps: 18 | - name: Checkout 19 | uses: actions/checkout@v4 20 | with: 21 | submodules: recursive 22 | - name: CMake 23 | run: cmake -DFOXOTRON_64BIT="YES" -G "Visual Studio 17 2022" -A x64 . 24 | - name: Build 25 | run: cmake --build . --config Release 26 | build_linux: 27 | runs-on: ubuntu-latest 28 | steps: 29 | - name: Install deps 30 | run: sudo apt-get update && sudo apt-get install -q -y xorg-dev libasound2-dev libfontconfig1-dev libgl1-mesa-dev libglu1-mesa-dev 31 | - name: Checkout 32 | uses: actions/checkout@v4 33 | with: 34 | submodules: recursive 35 | - name: Build 36 | run: cmake . && cmake --build . 37 | build_osx: 38 | runs-on: macOS-latest 39 | steps: 40 | - name: Checkout 41 | uses: actions/checkout@v4 42 | with: 43 | submodules: recursive 44 | - name: Build 45 | run: cmake . && cmake --build . 46 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build.* 2 | .vs 3 | *.aps 4 | imgui.ini -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "externals/assimp"] 2 | path = externals/assimp 3 | url = https://github.com/assimp/assimp.git 4 | [submodule "externals/imgui"] 5 | path = externals/imgui 6 | url = https://github.com/ocornut/imgui.git 7 | [submodule "externals/stb"] 8 | path = externals/stb 9 | url = https://github.com/nothings/stb.git 10 | [submodule "externals/glfw"] 11 | path = externals/glfw 12 | url = https://github.com/glfw/glfw.git 13 | [submodule "externals/glm"] 14 | path = externals/glm 15 | url = https://github.com/g-truc/glm.git 16 | [submodule "externals/imgui-addons"] 17 | path = externals/imgui-addons 18 | url = https://github.com/gallickgunner/ImGui-Addons.git 19 | [submodule "externals/jsonxx"] 20 | path = externals/jsonxx 21 | url = https://github.com/hjiang/jsonxx.git 22 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | set(VERSION_MAJOR "1") 4 | set(VERSION_MINOR "0") 5 | string(TIMESTAMP VERSION_PATCH "%Y%m%d") 6 | 7 | project(Foxotron VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) 8 | 9 | set(CMAKE_OSX_ARCHITECTURES x86_64) 10 | 11 | if (APPLE OR WIN32) 12 | set(FXTRN_EXE_NAME "Foxotron") 13 | else () 14 | set(FXTRN_EXE_NAME "Foxotron") 15 | endif () 16 | 17 | if (WIN32) 18 | option(FOXOTRON_64BIT "Compile for 64 bit target?" ON) 19 | 20 | if (CMAKE_GENERATOR MATCHES "64") 21 | set(FOXOTRON_64BIT ON CACHE BOOL "Compile for 64 bit target?") 22 | else () 23 | set(FOXOTRON_64BIT OFF CACHE BOOL "Compile for 64 bit target?") 24 | endif () 25 | endif () 26 | 27 | if (NOT (UNIX AND (NOT APPLE))) #if not linux 28 | set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}) 29 | endif () 30 | 31 | if (APPLE) 32 | set(CMAKE_FIND_FRAMEWORK LAST) 33 | endif () 34 | 35 | add_definitions(-DSCI_LEXER -DSCI_NAMESPACE) 36 | if (UNIX) 37 | add_definitions(-DGTK) 38 | endif () 39 | 40 | if (APPLE) 41 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++14") 42 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++") 43 | set(CMAKE_XCODE_ATTRIBUTE_GCC_ENABLE_CPP_EXCEPTIONS "No") 44 | set(CMAKE_XCODE_ATTRIBUTE_GCC_ENABLE_CPP_RTTI "No") 45 | set(CMAKE_CXX_STANDARD 11) 46 | endif () 47 | 48 | ############################################################################## 49 | # Global settings 50 | set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) 51 | 52 | ############################################################################## 53 | # ASSIMP 54 | add_subdirectory(${CMAKE_SOURCE_DIR}/externals/assimp/) 55 | set(FXTRN_PROJECT_INCLUDES ${FXTRN_PROJECT_INCLUDES} ${CMAKE_SOURCE_DIR}/externals/assimp/include ${CMAKE_CURRENT_BINARY_DIR}/externals/assimp/include) 56 | set(FXTRN_PROJECT_LIBS ${FXTRN_PROJECT_LIBS} assimp) 57 | if (MSVC) 58 | target_compile_options(assimp PUBLIC "$<$:/MT>") 59 | target_compile_options(zlibstatic PUBLIC "$<$:/MT>") 60 | endif () 61 | 62 | ############################################################################## 63 | # GLM 64 | add_subdirectory(${CMAKE_SOURCE_DIR}/externals/glm/) 65 | set(FXTRN_PROJECT_INCLUDES ${FXTRN_PROJECT_INCLUDES} ${CMAKE_SOURCE_DIR}/externals/glm/glm) 66 | set(FXTRN_PROJECT_LIBS ${FXTRN_PROJECT_LIBS} glm) 67 | 68 | ############################################################################## 69 | # JSONXX 70 | set(JSONXX_SRCS 71 | ${CMAKE_SOURCE_DIR}/externals/jsonxx/jsonxx.cc 72 | ) 73 | add_library(FXTRN_jsonxx STATIC ${JSONXX_SRCS}) 74 | target_include_directories(FXTRN_jsonxx PUBLIC ${CMAKE_SOURCE_DIR}/externals/jsonxx) 75 | if (MSVC) 76 | target_compile_options(FXTRN_jsonxx PUBLIC "$<$:/MT>") 77 | endif () 78 | set(FXTRN_PROJECT_INCLUDES ${FXTRN_PROJECT_INCLUDES} ${CMAKE_SOURCE_DIR}/externals/jsonxx) 79 | set(FXTRN_PROJECT_LIBS ${FXTRN_PROJECT_LIBS} FXTRN_jsonxx) 80 | 81 | ############################################################################## 82 | # GLFW 83 | # GLFW settings and project inclusion 84 | set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) 85 | set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) 86 | set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) 87 | set(GLFW_INSTALL OFF CACHE BOOL "" FORCE) 88 | set(GLFW_VULKAN_STATIC OFF CACHE BOOL "" FORCE) 89 | mark_as_advanced(BUILD_SHARED_LIBS GLFW_BUILD_EXAMPLES GLFW_BUILD_TESTS GLFW_BUILD_DOCS GLFW_INSTALL GLFW_VULKAN_STATIC) 90 | if (UNIX) 91 | set(GLFW_USE_OSMESA OFF CACHE BOOL "" FORCE) 92 | mark_as_advanced(GLFW_USE_OSMESA) 93 | endif() 94 | if (WIN32) 95 | set(USE_MSVC_RUNTIME_LIBRARY_DLL OFF CACHE BOOL "" FORCE) 96 | mark_as_advanced(USE_MSVC_RUNTIME_LIBRARY_DLL) 97 | endif() 98 | add_subdirectory(${CMAKE_SOURCE_DIR}/externals/glfw/) 99 | set(FXTRN_PROJECT_INCLUDES ${FXTRN_PROJECT_INCLUDES} ${CMAKE_SOURCE_DIR}/externals/glfw/include) 100 | set(FXTRN_PROJECT_LIBS ${FXTRN_PROJECT_LIBS} glfw ${GLFW_LIBRARIES}) 101 | 102 | ############################################################################## 103 | # GLEW 104 | set(GLEW_SRCS 105 | ${CMAKE_SOURCE_DIR}/externals/glew/glew.c 106 | ) 107 | add_library(FXTRN_glew STATIC ${GLEW_SRCS}) 108 | target_include_directories(FXTRN_glew PUBLIC ${CMAKE_SOURCE_DIR}/externals/glew) 109 | target_compile_definitions(FXTRN_glew PUBLIC -DGLEW_STATIC) 110 | if (MSVC) 111 | target_compile_options(FXTRN_glew PUBLIC "$<$:/MT>") 112 | endif () 113 | set(FXTRN_PROJECT_INCLUDES ${FXTRN_PROJECT_INCLUDES} ${CMAKE_SOURCE_DIR}/externals/glew) 114 | set(FXTRN_PROJECT_LIBS ${FXTRN_PROJECT_LIBS} FXTRN_glew) 115 | 116 | ############################################################################## 117 | # STB 118 | set(FXTRN_PROJECT_INCLUDES ${FXTRN_PROJECT_INCLUDES} 119 | ${CMAKE_SOURCE_DIR}/externals/stb 120 | ) 121 | 122 | ############################################################################## 123 | # IMGUI 124 | file(GLOB IMGUI_INCLUDES ${IMGUI_INCLUDES} 125 | ${CMAKE_SOURCE_DIR}/externals/imgui/*.h 126 | ) 127 | file(GLOB IMGUI_SRCS 128 | ${CMAKE_SOURCE_DIR}/externals/imgui/*.cpp 129 | ) 130 | set(IMGUI_INCLUDES ${IMGUI_INCLUDES} 131 | ${CMAKE_SOURCE_DIR}/externals/imgui/backends/imgui_impl_glfw.h 132 | ${CMAKE_SOURCE_DIR}/externals/imgui/backends/imgui_impl_opengl3.h 133 | ) 134 | set(IMGUI_SRCS ${IMGUI_SRCS} 135 | ${CMAKE_SOURCE_DIR}/externals/imgui/backends/imgui_impl_glfw.cpp 136 | ${CMAKE_SOURCE_DIR}/externals/imgui/backends/imgui_impl_opengl3.cpp 137 | ) 138 | add_library(FXTRN_ImGui STATIC ${IMGUI_SRCS}) 139 | target_include_directories(FXTRN_ImGui PUBLIC 140 | ${CMAKE_SOURCE_DIR}/externals/imgui 141 | ${CMAKE_SOURCE_DIR}/externals/glfw/include 142 | ${CMAKE_SOURCE_DIR}/externals/glew 143 | ) 144 | if (MSVC) 145 | target_compile_options(FXTRN_ImGui PUBLIC "$<$:/MT>") 146 | endif () 147 | set(FXTRN_PROJECT_INCLUDES ${FXTRN_PROJECT_INCLUDES} ${CMAKE_SOURCE_DIR}/externals/imgui) 148 | set(FXTRN_PROJECT_LIBS ${FXTRN_PROJECT_LIBS} FXTRN_ImGui) 149 | 150 | 151 | ############################################################################## 152 | # IMGUI ADDONS 153 | file(GLOB IMGUIADDONS_INCLUDES 154 | ${CMAKE_SOURCE_DIR}/externals/imgui-addons/FileBrowser/ImGuiFileBrowser.h 155 | ) 156 | file(GLOB IMGUIADDONS_SRCS 157 | ${CMAKE_SOURCE_DIR}/externals/imgui-addons/FileBrowser/ImGuiFileBrowser.cpp 158 | ) 159 | add_library(FXTRN_ImGuiAddons STATIC ${IMGUIADDONS_SRCS}) 160 | target_include_directories(FXTRN_ImGuiAddons PUBLIC 161 | ${CMAKE_SOURCE_DIR}/externals/imgui 162 | ) 163 | if (MSVC) 164 | target_compile_options(FXTRN_ImGuiAddons PUBLIC "$<$:/MT>") 165 | endif () 166 | set(FXTRN_PROJECT_INCLUDES ${FXTRN_PROJECT_INCLUDES} ${CMAKE_SOURCE_DIR}/externals/imgui-addons/FileBrowser) 167 | set(FXTRN_PROJECT_LIBS ${FXTRN_PROJECT_LIBS} FXTRN_ImGuiAddons) 168 | 169 | ############################################################################## 170 | # Foxotron 171 | file(GLOB FXTRN_PROJECT_SRCS 172 | ${CMAKE_SOURCE_DIR}/src/*.cpp 173 | ${CMAKE_SOURCE_DIR}/src/*.h 174 | ) 175 | 176 | if (WIN32) 177 | set(FXTRN_PROJECT_SRCS 178 | ${FXTRN_PROJECT_SRCS} 179 | ${CMAKE_SOURCE_DIR}/src/platform_w32/SetupDialog.cpp 180 | ) 181 | set(FXTRN_RESOURCES_DATA 182 | ${CMAKE_SOURCE_DIR}/data/windows/SetupDialog.rc 183 | ) 184 | source_group("Data" FILES ${FXTRN_RESOURCES_DATA}) 185 | set(FXTRN_PROJECT_INCLUDES ${CMAKE_SOURCE_DIR}/data/windows ${FXTRN_PROJECT_INCLUDES}) 186 | else () 187 | set(FXTRN_PROJECT_SRCS 188 | ${FXTRN_PROJECT_SRCS} 189 | ${CMAKE_SOURCE_DIR}/src/platform_common/SetupDialog.cpp 190 | ) 191 | endif () 192 | 193 | source_group("Foxotron" FILES ${FXTRN_PROJECT_SRCS}) 194 | 195 | set(FXTRN_PROJECT_SRCS ${FXTRN_PROJECT_SRCS} ${FXTRN_PLATFORM_SRCS} ${FXTRN_RESOURCES_DATA} ${FXTRN_CAPTURE_SRCS}) 196 | 197 | set(FXTRN_PROJECT_INCLUDES ${CMAKE_SOURCE_DIR}/src ${FXTRN_PROJECT_INCLUDES}) 198 | 199 | ############################################################################## 200 | #### APPLE BUNDLE, RESSOURCES AND DYNAMIC LIBS 201 | if (APPLE) 202 | set(GUI_TYPE MACOSX_BUNDLE) 203 | 204 | # Define some settings for the Bundle 205 | set(MACOSX_BUNDLE_BUNDLE_NAME ${FXTRN_EXE_NAME}) 206 | set(MACOSX_BUNDLE_GUI_IDENTIFIER "${FXTRN_EXE_NAME}") 207 | set(MACOSX_BUNDLE_ICON_FILE icon.icns) 208 | set(MACOSX_BUNDLE_INFO_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH},Copyright © 2021 The Foxotron Contributors") 209 | set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") 210 | set(MACOSX_BUNDLE_LONG_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") 211 | set(MACOSX_BUNDLE_BUNDLE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") 212 | set(MACOSX_BUNDLE_COPYRIGHT "Copyright © 2020-2021 The Foxotron Contributors. All rights reserved.") 213 | 214 | set_source_files_properties(${FXTRN_RESOURCES_DATA} PROPERTIES MACOSX_PACKAGE_LOCATION Resources) 215 | 216 | set_source_files_properties(${OSX_LIB_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION MacOS) 217 | set(FXTRN_PROJECT_SRCS ${FXTRN_PROJECT_SRCS} ${OSX_LIB_FILES}) 218 | 219 | set(FXTRN_PROJECT_SRCS ${GUI_TYPE} ${FXTRN_PROJECT_SRCS}) 220 | 221 | find_library(COCOA_FRAMEWORK Cocoa) 222 | find_library(OPENGL_FRAMEWORK OpenGL) 223 | find_library(CARBON_FRAMEWORK Carbon) 224 | find_library(COREAUDIO_FRAMEWORK CoreAudio) 225 | find_library(AVFOUNDATION_FRAMEWORK AVFoundation) 226 | mark_as_advanced(COCOA_FRAMEWORK OPENGL_FRAMEWORK CARBON_FRAMEWORK COREAUDIO_FRAMEWORK AVFOUNDATION_FRAMEWORK) 227 | set(PLATFORM_LIBS ${COCOA_FRAMEWORK} ${OPENGL_FRAMEWORK} ${CARBON_FRAMEWORK} ${COREAUDIO_FRAMEWORK} ${AVFOUNDATION_FRAMEWORK}) 228 | elseif (UNIX) 229 | set(PLATFORM_LIBS GL asound fontconfig) 230 | elseif (WIN32) 231 | set(PLATFORM_LIBS opengl32 glu32 winmm shlwapi) 232 | endif () 233 | set(FXTRN_PROJECT_LIBS ${FXTRN_PROJECT_LIBS} ${PLATFORM_LIBS}) 234 | 235 | ############################################################################## 236 | # create the executable 237 | link_directories(${FXTRN_LINK_DIRS}) 238 | if (UNIX AND (NOT APPLE)) 239 | set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib") 240 | endif () 241 | 242 | add_executable(${FXTRN_EXE_NAME} ${FXTRN_PROJECT_SRCS}) 243 | 244 | ############################################################################## 245 | # Set compiler specific flags 246 | if (APPLE) 247 | # set_target_properties(${FXTRN_EXE_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/data/macosx/MacOSXBundleInfo.plist.in) 248 | elseif (UNIX AND (NOT APPLE)) 249 | target_compile_options(${FXTRN_EXE_NAME} PUBLIC -std=c++11) 250 | elseif (WIN32) 251 | if (MSVC) 252 | set_target_properties(${FXTRN_EXE_NAME} PROPERTIES LINK_FLAGS "/SUBSYSTEM:CONSOLE") 253 | target_compile_options(${FXTRN_EXE_NAME} PUBLIC "$<$:/MT>") 254 | endif () 255 | endif () 256 | target_include_directories(${FXTRN_EXE_NAME} PUBLIC ${FXTRN_PROJECT_INCLUDES}) 257 | target_link_libraries(${FXTRN_EXE_NAME} ${FXTRN_PROJECT_LIBS}) 258 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The following license covers parts of the code 2 | not covered in the acknowledgements section of README.md: 3 | ---------------------------------------------- 4 | 5 | This is free and unencumbered software released into the public domain. 6 | 7 | Anyone is free to copy, modify, publish, use, compile, sell, or 8 | distribute this software, either in source code form or as a compiled 9 | binary, for any purpose, commercial or non-commercial, and by any 10 | means. 11 | 12 | In jurisdictions that recognize copyright laws, the author or authors 13 | of this software dedicate any and all copyright interest in the 14 | software to the public domain. We make this dedication for the benefit 15 | of the public at large and to the detriment of our heirs and 16 | successors. We intend this dedication to be an overt act of 17 | relinquishment in perpetuity of all present and future rights to this 18 | software under copyright law. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 24 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 25 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | OTHER DEALINGS IN THE SOFTWARE. 27 | 28 | For more information, please refer to 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Foxotron 2 | 3 | [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/Gargaj/Foxotron/build-on-push?logo=github)](https://github.com/Gargaj/Foxotron/actions) 4 | 5 | ASSIMP based general purpose model viewer ("turntable") created for the Revision 2021 3D Graphics Competition 6 | 7 | ![image](https://user-images.githubusercontent.com/1702533/109347365-5d7d5880-7873-11eb-98ff-743cb26e9606.png) 8 | 9 | ## Usage 10 | Check [the wiki](https://github.com/Gargaj/Foxotron/wiki) for information on how to use it. 11 | 12 | ### Keyboard shortcuts 13 | * F11: Toggle menu 14 | * F: Refocus camera on mesh 15 | * W: Toggle wireframe / edged faces 16 | * C: Toggle auto camera 17 | * PgUp / PgDn: Cycle through shaders 18 | * Alt-F4: Enter hyberwormtunnel 19 | 20 | ### Mouse operations 21 | * Left click & drag: Rotate camera 22 | * Right click & drag: Rotate light / skybox 23 | * Middle click & drag: Pan camera 24 | 25 | ## Requirements 26 | OpenGL 4.1 is required. 27 | 28 | ## Building 29 | You're gonna need [CMAKE](https://cmake.org/) 30 | 31 | ## Credits 32 | 33 | ### Libraries and other included software 34 | - Open Asset Import Library by the ASSIMP dev team (https://www.assimp.org) 35 | - Dear ImGui by Omar Cornut (http://www.dearimgui.com) 36 | - ImGui Addons by gallickgunner (https://github.com/gallickgunner/ImGui-Addons) 37 | - OpenGL Extension Wrangler Library by Nigel Stewart (http://glew.sourceforge.net) 38 | - STB Image library by Sean Barrett (https://nothings.org) 39 | - GLFW by whoever made GLFW (https://www.glfw.org/faq.html) 40 | 41 | These software are available under their respective licenses. 42 | 43 | The remainder of this project code was (mostly) written by Gargaj / Conspiracy and is public domain; PBR lighting shaders by cce / Peisik. 44 | Large portions of the code were cannibalized from [Bonzomatic](https://github.com/Gargaj/Bonzomatic). 45 | 46 | ### Textures and cube maps 47 | 48 | All HDR textures are courtesy of the [HDRLabs sIBL archive](http://www.hdrlabs.com/sibl/archive.html). 49 | 50 | ## Contact / discussion forum 51 | If you have anything to say, do it at https://www.pouet.net/topic.php?which=12347 52 | -------------------------------------------------------------------------------- /Shaders/basic_specgloss.fs: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | struct Light 4 | { 5 | vec3 direction; 6 | vec3 color; 7 | }; 8 | 9 | struct ColorMap 10 | { 11 | bool has_tex; 12 | sampler2D tex; 13 | vec4 color; 14 | }; 15 | 16 | in vec3 out_normal; 17 | in vec3 out_tangent; 18 | in vec3 out_binormal; 19 | in vec2 out_texcoord; 20 | in vec3 out_worldpos; 21 | in vec3 out_to_camera; 22 | 23 | 24 | uniform float specular_shininess; 25 | 26 | uniform float skysphere_rotation; 27 | uniform float skysphere_mip_count; 28 | uniform float exposure; 29 | 30 | uniform vec3 camera_position; 31 | uniform Light lights[3]; 32 | 33 | uniform vec4 global_ambient; 34 | 35 | uniform bool has_tex_skysphere; 36 | uniform bool has_tex_skyenv; 37 | 38 | uniform sampler2D tex_skysphere; 39 | uniform sampler2D tex_skyenv; 40 | 41 | uniform ColorMap map_albedo; 42 | uniform ColorMap map_diffuse; 43 | uniform ColorMap map_specular; 44 | uniform ColorMap map_normals; 45 | uniform ColorMap map_roughness; 46 | uniform ColorMap map_metallic; 47 | uniform ColorMap map_ao; 48 | uniform ColorMap map_ambient; 49 | uniform ColorMap map_emissive; 50 | 51 | out vec4 frag_color; 52 | 53 | const float PI = 3.1415926536; 54 | 55 | vec4 sample_colormap( ColorMap map, vec2 uv) 56 | { 57 | return map.has_tex ? texture( map.tex, uv ) : map.color; 58 | } 59 | 60 | vec2 sphere_to_polar( vec3 normal ) 61 | { 62 | normal = normalize( normal ); 63 | return vec2( ( atan( normal.z, normal.x ) + skysphere_rotation ) / PI / 2.0 + 0.5, acos( normal.y ) / PI ); 64 | } 65 | 66 | vec3 sample_irradiance_fast( vec3 normal ) 67 | { 68 | // Sample the irradiance map if it exists, otherwise fall back to blurred reflection map. 69 | if ( has_tex_skyenv ) 70 | { 71 | vec2 polar = sphere_to_polar( normal ); 72 | // HACK: Sample a smaller mip here to avoid high frequency color variations on detailed normal 73 | // mapped areas. 74 | float miplevel = 5.5; // tweaked for a 360x180 irradiance texture 75 | return textureLod( tex_skyenv, polar, miplevel ).rgb * exposure; 76 | } 77 | else 78 | { 79 | vec2 polar = sphere_to_polar( normal ); 80 | return textureLod( tex_skysphere, polar, 0.80 * skysphere_mip_count ).rgb * exposure; 81 | } 82 | } 83 | 84 | float calculate_specular( vec3 normal, vec3 light_direction ) 85 | { 86 | vec3 V = normalize( out_to_camera ); 87 | vec3 L = -normalize( light_direction ); 88 | vec3 H = normalize( V + L ); 89 | float rdotv = clamp( dot( normal, H ), 0.0, 1.0 ); 90 | float total_specular = pow( rdotv, specular_shininess ); 91 | 92 | return total_specular; 93 | } 94 | 95 | void main(void) 96 | { 97 | vec3 ambient = sample_colormap( map_ambient, out_texcoord ).xyz; 98 | vec4 diffusemap_alpha = sample_colormap( map_diffuse, out_texcoord ); 99 | vec3 diffusemap = diffusemap_alpha.xyz; 100 | float alpha = diffusemap_alpha.w; 101 | if (alpha < 0.001) 102 | { 103 | discard; 104 | } 105 | 106 | vec3 normalmap = normalize(texture( map_normals.tex, out_texcoord ).xyz * vec3(2.0) - vec3(1.0)); 107 | vec4 specularmap = sample_colormap( map_specular, out_texcoord ); 108 | 109 | vec3 normal = out_normal; 110 | if ( map_normals.has_tex ) 111 | { 112 | // Mikkelsen's tangent space normal map decoding. See http://mikktspace.com/ for rationale. 113 | vec3 bi = cross( out_normal, out_tangent ); 114 | vec3 nmap = normalmap.xyz; 115 | normal = nmap.x * out_tangent + nmap.y * bi + nmap.z * out_normal; 116 | } 117 | 118 | normal = normalize( normal ); 119 | 120 | vec3 irradiance = sample_irradiance_fast( normal ); 121 | ambient *= irradiance; 122 | 123 | vec3 color = ambient * global_ambient.rgb; 124 | for ( int i = 0; i < lights.length(); i++ ) 125 | { 126 | float ndotl = clamp( dot( normal, -normalize( lights[ i ].direction ) ), 0.0, 1.0 ); 127 | 128 | vec3 specular = specularmap.rgb * calculate_specular( normal, lights[ i ].direction ) * specularmap.a; 129 | color += (diffusemap + specular) * ndotl * lights[ i ].color; 130 | } 131 | 132 | color += sample_colormap( map_emissive, out_texcoord ).rgb; 133 | 134 | frag_color = vec4( pow( color * exposure, vec3(1. / 2.2) ), alpha ); 135 | } 136 | -------------------------------------------------------------------------------- /Shaders/basic_specgloss.vs: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | in vec3 in_pos; 4 | in vec3 in_normal; 5 | in vec3 in_tangent; 6 | in vec3 in_binormal; 7 | in vec2 in_texcoord; 8 | 9 | out vec3 out_normal; 10 | out vec3 out_tangent; 11 | out vec3 out_binormal; 12 | out vec2 out_texcoord; 13 | out vec3 out_worldpos; 14 | out vec3 out_viewpos; 15 | out vec3 out_to_camera; 16 | 17 | uniform mat4x4 mat_projection; 18 | uniform mat4x4 mat_view; 19 | uniform mat4x4 mat_view_inverse; 20 | uniform mat4x4 mat_world; 21 | 22 | void main() 23 | { 24 | vec4 o = vec4( in_pos.x, in_pos.y, in_pos.z, 1.0 ); 25 | o = mat_world * o; 26 | out_worldpos = o.xyz; 27 | o = mat_view * o; 28 | out_viewpos = o.xyz; 29 | 30 | vec3 to_camera = normalize( -o.xyz ); 31 | out_to_camera = mat3( mat_view_inverse ) * to_camera; 32 | 33 | o = mat_projection * o; 34 | gl_Position = o; 35 | 36 | out_normal = normalize( mat3( mat_world ) * in_normal ); 37 | out_tangent = normalize( mat3( mat_world ) * in_tangent ); 38 | out_binormal = normalize( mat3( mat_world ) * in_binormal ); 39 | out_texcoord = in_texcoord; 40 | } 41 | -------------------------------------------------------------------------------- /Shaders/pbr.fs: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | // Samples irradiance from tex_skysphere when enabled. 4 | const bool use_bruteforce_irradiance = false; 5 | // Makes silhouettes more reflective to avoid black pixels. 6 | const bool use_wraparound_specular = true; 7 | // Dampens IBL specular ambient with AO if enabled. 8 | const bool use_specular_ao_attenuation = true; 9 | // Increases roughness if normal map has variation and was minified. 10 | const bool use_normal_variation_to_roughness = true; 11 | // Shows all ColorMaps as horizontal bars 12 | const bool use_map_debugging = false; 13 | // Splits the screen in two and shows image-based specular (left) and diffuse (right) shading. 14 | const bool use_ambient_debugging = false; 15 | // Multiplies analytic light's color with this constant because otherwise they look really pathetic. 16 | const float lighting_boost = 2.0f; 17 | 18 | struct Light 19 | { 20 | vec3 direction; 21 | vec3 color; 22 | }; 23 | 24 | struct ColorMap 25 | { 26 | bool has_tex; 27 | sampler2D tex; 28 | vec4 color; 29 | }; 30 | 31 | in vec3 out_normal; 32 | in vec3 out_tangent; 33 | in vec3 out_binormal; 34 | in vec2 out_texcoord; 35 | in vec3 out_worldpos; 36 | in vec3 out_to_camera; 37 | 38 | uniform float skysphere_rotation; 39 | uniform float skysphere_mip_count; 40 | uniform float exposure; 41 | uniform uint frame_count; 42 | 43 | uniform vec3 camera_position; 44 | uniform Light lights[3]; 45 | 46 | uniform sampler2D tex_skysphere; 47 | uniform sampler2D tex_skyenv; 48 | uniform sampler2D tex_brdf_lut; 49 | 50 | uniform bool has_tex_skysphere; 51 | uniform bool has_tex_skyenv; 52 | 53 | uniform ColorMap map_albedo; 54 | uniform ColorMap map_diffuse; 55 | uniform ColorMap map_specular; 56 | uniform ColorMap map_normals; 57 | uniform ColorMap map_roughness; 58 | uniform ColorMap map_metallic; 59 | uniform ColorMap map_ao; 60 | uniform ColorMap map_ambient; 61 | uniform ColorMap map_emissive; 62 | 63 | out vec4 frag_color; 64 | 65 | const float PI = 3.1415926536; 66 | 67 | // MurMurHash 3 finalizer. Implementation is in public domain. 68 | uint hash( uint h ) 69 | { 70 | h ^= h >> 16; 71 | h *= 0x85ebca6b; 72 | h ^= h >> 13; 73 | h *= 0xc2b2ae35; 74 | h ^= h >> 16; 75 | return h; 76 | } 77 | 78 | // Random function using the idea of StackOverflow user "Spatial" https://stackoverflow.com/a/17479300 79 | // Creates random 23 bits and puts them into the fraction bits of an 32-bit float. 80 | float random( uvec3 h ) 81 | { 82 | uint m = hash(h.x ^ hash( h.y ) ^ hash( h.z )); 83 | return uintBitsToFloat( ( m & 0x007FFFFFu ) | 0x3f800000u ) - 1.; 84 | } 85 | 86 | float random( vec3 v ) 87 | { 88 | return random(floatBitsToUint( v )); 89 | } 90 | 91 | vec4 sample_colormap( ColorMap map, vec2 uv ) 92 | { 93 | return map.has_tex ? texture( map.tex, uv ) : map.color; 94 | } 95 | 96 | vec3 fresnel_schlick( vec3 H, vec3 V, vec3 F0 ) 97 | { 98 | float cosTheta = clamp( dot( H, V ), 0., 1. ); 99 | return F0 + ( vec3( 1.0 ) - F0 ) * pow( 1. - cosTheta, 5.0 ); 100 | } 101 | 102 | // A Fresnel term that dampens rough specular reflections. 103 | // https://seblagarde.wordpress.com/2011/08/17/hello-world/ 104 | vec3 fresnel_schlick_roughness( vec3 H, vec3 V, vec3 F0, float roughness ) 105 | { 106 | float cosTheta = clamp( dot( H, V ), 0., 1. ); 107 | return F0 + ( max( vec3( 1.0 - roughness ), F0 ) - F0 ) * pow( 1. - cosTheta, 5.0 ); 108 | } 109 | 110 | float distribution_ggx( vec3 N, vec3 H, float roughness ) 111 | { 112 | float a = roughness * roughness; 113 | float a2 = a * a; 114 | float NdotH = max( 0., dot( N, H ) ); 115 | float factor = NdotH * NdotH * ( a2 - 1. ) + 1.; 116 | 117 | return a2 / ( PI * factor * factor ); 118 | } 119 | 120 | float geometry_schlick_ggx( vec3 N, vec3 V, float k ) 121 | { 122 | float NdotV = max( 0., dot( N, V ) ); 123 | return NdotV / (NdotV * ( 1. - k ) + k ); 124 | } 125 | 126 | float geometry_smith( vec3 N, vec3 V, vec3 L, float roughness ) 127 | { 128 | float r = roughness + 1.; 129 | float k = (r * r) / 8.; 130 | return geometry_schlick_ggx( N, V, k ) * geometry_schlick_ggx( N, L, k ); 131 | } 132 | 133 | vec2 sphere_to_polar( vec3 normal ) 134 | { 135 | normal = normalize( normal ); 136 | return vec2( ( atan( normal.z, normal.x ) + skysphere_rotation ) / PI / 2.0 + 0.5, acos( normal.y ) / PI ); 137 | } 138 | 139 | // Our vertically GL_CLAMPed textures seem to blend towards black when sampling the half-pixel edge. 140 | // Not sure if it has a border, or this if is a driver bug, but can repro on multiple nvidia cards. 141 | // Knowing the texture height we can limit sampling to the centers of the top and bottom pixel rows. 142 | vec2 sphere_to_polar_clamp_y( vec3 normal, float texture_height ) 143 | { 144 | normal = normalize( normal ); 145 | return vec2( ( atan( normal.z, normal.x ) + skysphere_rotation ) / PI / 2.0 + 0.5, clamp(acos( normal.y ) / PI, 0.5 / texture_height, 1.0 - 0.5 / texture_height) ); 146 | } 147 | 148 | vec3 sample_sky( vec3 normal ) 149 | { 150 | vec2 polar = sphere_to_polar( normal ); 151 | return texture( tex_skysphere, polar ).rgb * exposure; 152 | } 153 | 154 | // Takes samples around the hemisphere, converts them to radiances via weighting and 155 | // returns a normalized sum. 156 | vec3 sample_irradiance_slow( vec3 normal, vec3 vertex_tangent ) 157 | { 158 | float delta = 0.10; 159 | 160 | vec3 up = abs( normal.y ) < 0.999 ? vec3( 0., 1., 0. ) : vec3( 0., 0., 1. ); 161 | vec3 tangent_x = normalize( cross( up, normal ) ); 162 | vec3 tangent_y = cross( normal, tangent_x ); 163 | 164 | int numIrradianceSamples = 0; 165 | 166 | vec3 irradiance = vec3(0.); 167 | 168 | for ( float phi = 0.; phi < 2. * PI ; phi += delta ) 169 | { 170 | for ( float theta = 0.; theta < 0.5 * PI; theta += delta ) 171 | { 172 | vec3 tangent_space = vec3( 173 | sin( theta ) * cos( phi ), 174 | sin( theta ) * sin( phi ), 175 | cos( theta ) ); 176 | 177 | vec3 world_space = tangent_space.x * tangent_x + tangent_space.y + tangent_y + tangent_space.z * normal; 178 | 179 | vec3 color = sample_sky( world_space ); 180 | irradiance += color * cos( theta ) * sin( theta ); 181 | numIrradianceSamples++; 182 | } 183 | } 184 | 185 | irradiance = PI * irradiance / float( numIrradianceSamples ); 186 | return irradiance; 187 | } 188 | 189 | vec3 sample_irradiance_fast( vec3 normal, vec3 vertex_tangent ) 190 | { 191 | // Sample the irradiance map if it exists, otherwise fall back to blurred reflection map. 192 | if ( has_tex_skyenv ) 193 | { 194 | vec2 polar = sphere_to_polar_clamp_y( normal, 180.0 ); 195 | return textureLod( tex_skyenv, polar, 0.0 ).rgb * exposure; 196 | } 197 | else 198 | { 199 | vec2 polar = sphere_to_polar( normal ); 200 | return textureLod( tex_skysphere, polar, 0.80 * skysphere_mip_count ).rgb * exposure; 201 | } 202 | } 203 | 204 | 205 | vec3 specular_ibl( vec3 V, vec3 N, float roughness, vec3 fresnel ) 206 | { 207 | // What we'd like to do here is take a LOT of skybox samples around the reflection 208 | // vector R according to the BRDF lobe. 209 | // 210 | // Unfortunately it's not possible in real time so we use the following UE4 style approximations: 211 | // 1. Integrate incoming light and BRDF separately ("split sum approximation") 212 | // 2. Assume V = R = N so that we can just blur the skybox and sample that. 213 | // 3. Bake the BRDF integral into a lookup texture so that it can be computed in constant time. 214 | // 215 | // Here we also simplify approximation #2 by using bilinear mipmaps with a magic formula instead 216 | // of properly convolving it with a GGX lobe. 217 | // 218 | // For details, see Brian Karis, "Real Shading in Unreal Engine 4", 2013. 219 | 220 | vec3 R = 2. * dot( V, N ) * N - V; 221 | 222 | vec2 polar = sphere_to_polar( R ); 223 | 224 | // Map roughness from range [0, 1] into a mip LOD [0, skysphere_mip_count]. 225 | // The magic numbers were chosen empirically. 226 | 227 | float mip = 0.9 * skysphere_mip_count * pow(roughness, 0.25); 228 | 229 | vec3 prefiltered = textureLod( tex_skysphere, polar, mip ).rgb * exposure; 230 | 231 | float NdotV = dot( N, V ); 232 | 233 | // dot( N, V ) seems to produce negative values so we can try to stretch it a bit behind the silhouette 234 | // to avoid black pixels. 235 | if (use_wraparound_specular) 236 | { 237 | NdotV = NdotV * 0.9 + 0.1; 238 | } 239 | 240 | NdotV = min(0.99, max(0.01, NdotV)); 241 | 242 | // A precomputed lookup table contains a scale and a bias term for specular intensity (called "fresnel" here). 243 | // See equation (8) in Karis' course notes mentioned above. 244 | vec2 envBRDF = texture( tex_brdf_lut, vec2(NdotV, roughness) ).xy; 245 | vec3 specular = prefiltered * (fresnel * envBRDF.x + vec3(envBRDF.y)); 246 | 247 | return specular; 248 | } 249 | 250 | 251 | void main(void) 252 | { 253 | vec3 baseColor = vec3( 0.5, 0.5, 0.5 ); 254 | float roughness = 1.0; 255 | float metallic = 0.0; 256 | float ao = 1.0; 257 | float alpha = 1.0; 258 | 259 | vec4 baseColor_alpha; 260 | if ( map_albedo.has_tex ) 261 | baseColor_alpha = sample_colormap( map_albedo, out_texcoord ); 262 | else 263 | baseColor_alpha = sample_colormap( map_diffuse, out_texcoord ); 264 | baseColor = baseColor_alpha.xyz; 265 | alpha = baseColor_alpha.w; 266 | if (alpha < 0.001) 267 | { 268 | discard; 269 | } 270 | 271 | roughness = sample_colormap( map_roughness, out_texcoord ).x; 272 | metallic = sample_colormap( map_metallic, out_texcoord ).x; 273 | 274 | if ( map_ao.has_tex ) 275 | ao = sample_colormap( map_ao, out_texcoord ).x; 276 | else if ( map_ambient.has_tex ) 277 | ao = sample_colormap( map_ambient, out_texcoord ).x; 278 | 279 | vec3 emissive = sample_colormap( map_emissive, out_texcoord ).rgb; 280 | 281 | vec3 normalmap = texture( map_normals.tex, out_texcoord ).xyz * vec3(2.0) - vec3(1.0); 282 | float normalmap_mip = textureQueryLod( map_normals.tex, out_texcoord ).x; 283 | float normalmap_length = length(normalmap); 284 | normalmap /= normalmap_length; 285 | 286 | vec3 normal = out_normal; 287 | 288 | if ( map_normals.has_tex ) 289 | { 290 | // Mikkelsen's tangent space normal map decoding. See http://mikktspace.com/ for rationale. 291 | vec3 bi = cross( out_normal, out_tangent ); 292 | vec3 nmap = normalmap.xyz; 293 | normal = nmap.x * out_tangent + nmap.y * bi + nmap.z * out_normal; 294 | } 295 | 296 | normal = normalize( normal ); 297 | 298 | if ( use_map_debugging ) 299 | { 300 | vec3 c = vec3(1., 0., 0.); 301 | float y = gl_FragCoord.y / 1000.; 302 | if ( y < 0.7 ) c = vec3(.5) + .5*out_normal; 303 | if ( y < 0.6 ) c = vec3(.5) + .5*normalmap; 304 | if ( y < 0.5 ) c = vec3(emissive); 305 | if ( y < 0.4 ) c = vec3(ao); 306 | if ( y < 0.3 ) c = vec3(metallic); 307 | if ( y < 0.2 ) c = vec3(roughness); 308 | if ( y < 0.1 ) c = baseColor; 309 | frag_color = vec4(c, 1.); 310 | return; 311 | } 312 | 313 | if (use_normal_variation_to_roughness) 314 | { 315 | // Try to reduce specular aliasing by increasing roughness when minified normal maps have high variation. 316 | float variation = 1. - pow( normalmap_length, 8. ); 317 | float minification = clamp( normalmap_mip - 2., 0., 1. ); 318 | roughness = mix( roughness, 1.0, variation * minification ); 319 | } 320 | 321 | 322 | vec3 N = normal; 323 | vec3 V = normalize( out_to_camera ); 324 | 325 | vec3 Lo = vec3(0.); 326 | vec3 F0 = vec3(0.04); 327 | F0 = mix( F0, baseColor, metallic ); 328 | 329 | bool use_ibl = has_tex_skysphere; 330 | 331 | // Add contributions from analytic lights only if we don't have a skybox. 332 | 333 | { 334 | int num_lights = use_ibl ? 1 : lights.length(); 335 | for ( int i = 0; i < num_lights; i++ ) 336 | { 337 | vec3 radiance = lights[ i ].color * lighting_boost; 338 | 339 | vec3 L = -normalize( lights[ i ].direction ); 340 | vec3 H = normalize( V + L ); 341 | 342 | vec3 F = fresnel_schlick( H, V, F0 ); 343 | vec3 kS = F; 344 | vec3 kD = vec3(1.0) - kS; 345 | kD *= 1.0 - metallic; 346 | 347 | // Premultiplied alpha applied to the diffuse component only 348 | kD *= alpha; 349 | 350 | float D = distribution_ggx( N, H, roughness ); 351 | float G = geometry_smith( N, V, L, roughness ); 352 | 353 | vec3 num = D * F * G; 354 | float denom = 4. * max( 0., dot( N, V ) ) * max( 0., dot( N, L ) ); 355 | 356 | vec3 specular = kS * (num / max( 0.001, denom )); 357 | 358 | float NdotL = max( 0., dot( N, L ) ); 359 | 360 | Lo += ( kD * ( baseColor / PI ) + specular ) * radiance * NdotL; 361 | } 362 | } 363 | 364 | vec3 ambient = sample_colormap( map_ambient, out_texcoord ).xyz; 365 | vec3 diffuse_ambient; 366 | vec3 specular_ambient; 367 | 368 | if ( use_ibl ) 369 | { 370 | // Image based lighting. 371 | // Based on https://learnopengl.com/PBR/IBL/Diffuse-irradiance 372 | 373 | vec3 irradiance = vec3(0.); 374 | 375 | if ( use_bruteforce_irradiance ) 376 | { 377 | irradiance = sample_irradiance_slow( normal, out_tangent ); 378 | } 379 | else 380 | { 381 | irradiance = sample_irradiance_fast( normal, out_tangent ); 382 | } 383 | 384 | // Compute the Fresnel term for a perfect mirror reflection with L = R. 385 | // In this case the halfway vector H = N. 386 | // 387 | // We use a modified Fresnel function that dampens specular reflections of very 388 | // rough surfaces to avoid too bright pixels at grazing angles. 389 | vec3 F = fresnel_schlick_roughness( N, V, F0, roughness ); 390 | vec3 kS = F; 391 | 392 | // Subtract the amount of reflected light (specular) to get the energy left for 393 | // absorbed (diffuse) light. 394 | vec3 kD = vec3(1.) - kS; 395 | 396 | // Metallic surfaces have only a specular reflection. 397 | kD *= 1.0 - metallic; 398 | 399 | // Premultiplied alpha applied to the diffuse component only 400 | kD *= alpha; 401 | 402 | // Modulate the incoming lighting with the diffuse color: some wavelengths get absorbed. 403 | diffuse_ambient = irradiance * baseColor; 404 | 405 | // Ambient light also has a specular part. 406 | specular_ambient = specular_ibl( V, normal, roughness, F ); 407 | 408 | // Ambient occlusion tells us the fraction of sky light that reaches this point. 409 | 410 | if (use_specular_ao_attenuation) 411 | { 412 | ambient = ao * (kD * diffuse_ambient + specular_ambient); 413 | } 414 | else 415 | { 416 | // We don't attenuate specular_ambient ambient here with AO which might cause flickering in dark cavities. 417 | ambient = ao * (kD * diffuse_ambient) + specular_ambient; 418 | } 419 | } 420 | 421 | vec3 color = (ambient + Lo) + emissive; 422 | 423 | if ( use_ambient_debugging ) 424 | { 425 | float x = gl_FragCoord.x / 1280.; 426 | if ( x > 0.5 ) 427 | color = diffuse_ambient; 428 | else 429 | color = specular_ambient; 430 | } 431 | 432 | 433 | // Tonemap, apply gamma correction and dither with noise. 434 | color = color / ( vec3(1.) + color ); 435 | color = pow( color, vec3(1. / 2.2) ); 436 | float dither = random( uvec3( floatBitsToUint( gl_FragCoord.xy ), frame_count ) ); 437 | color += vec3( (-1.0/256.) + (2./256.) * dither ); 438 | 439 | // Technically this alpha may be too transparent, if there is a lot of reflected light we wouldn't see the background, maybe we can approximate it well enough by adding a fresnel term 440 | frag_color = vec4( color, alpha ); 441 | } 442 | -------------------------------------------------------------------------------- /Shaders/pbr.vs: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | in vec3 in_pos; 4 | in vec3 in_normal; 5 | in vec3 in_tangent; 6 | in vec3 in_binormal; 7 | in vec2 in_texcoord; 8 | 9 | out vec3 out_normal; 10 | out vec3 out_tangent; 11 | out vec3 out_binormal; 12 | out vec2 out_texcoord; 13 | out vec3 out_worldpos; 14 | out vec3 out_viewpos; 15 | out vec3 out_to_camera; 16 | 17 | uniform mat4x4 mat_projection; 18 | uniform mat4x4 mat_view; 19 | uniform mat4x4 mat_view_inverse; 20 | uniform mat4x4 mat_world; 21 | 22 | void main() 23 | { 24 | vec4 o = vec4( in_pos.x, in_pos.y, in_pos.z, 1.0 ); 25 | o = mat_world * o; 26 | out_worldpos = o.xyz; 27 | o = mat_view * o; 28 | out_viewpos = o.xyz; 29 | 30 | vec3 to_camera = normalize( -o.xyz ); 31 | out_to_camera = mat3( mat_view_inverse ) * to_camera; 32 | 33 | o = mat_projection * o; 34 | gl_Position = o; 35 | 36 | out_normal = normalize( mat3( mat_world ) * in_normal ); 37 | out_tangent = normalize( mat3( mat_world ) * in_tangent ); 38 | out_binormal = normalize( mat3( mat_world ) * in_binormal ); 39 | out_texcoord = in_texcoord; 40 | } 41 | -------------------------------------------------------------------------------- /Skyboxes/Barce_Rooftop_C_3k.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gargaj/Foxotron/df7175dd3aa717800528bdd6802502c0426ebfc1/Skyboxes/Barce_Rooftop_C_3k.hdr -------------------------------------------------------------------------------- /Skyboxes/Barce_Rooftop_C_Env.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gargaj/Foxotron/df7175dd3aa717800528bdd6802502c0426ebfc1/Skyboxes/Barce_Rooftop_C_Env.hdr -------------------------------------------------------------------------------- /Skyboxes/Barcelona_Rooftops.ibl: -------------------------------------------------------------------------------- 1 | [Header] 2 | ICOfile = "Barce_Rooftop_C_thumb.jpg" 3 | PREVIEWfile = "Barce_Rooftop_C_preview.jpg" 4 | Name = "Barcelona Rooftops" 5 | Author = "Blochi" 6 | Location = "Barcelona" 7 | Comment = "Sunrise at the Hotel Pool, urban area, high above the rooftops" 8 | GEOlat = 41.38503265 9 | GEOlong = 2.17812109 10 | Link = "http://www.hdrlabs.com/sibl/archive.html" 11 | Date = "2009:10:02" 12 | Time = "07:15:00" 13 | Height = 1.754386 14 | North = 0.38 15 | 16 | [Background] 17 | BGfile = "Barce_Rooftop_C_8k.jpg" 18 | BGmap = 1 19 | BGu = 0.000000 20 | BGv = 0.000000 21 | BGheight = 4096 22 | 23 | [Enviroment] 24 | EVfile = "Barce_Rooftop_C_Env.hdr" 25 | EVmap = 1 26 | EVu = 0.000000 27 | EVv = 0.000000 28 | EVheight = 180 29 | EVmulti = 1.000000 30 | EVgamma = 1.400000 31 | 32 | [Reflection] 33 | REFfile = "Barce_Rooftop_C_3k.hdr" 34 | REFmap = 1 35 | REFu = 0.000000 36 | REFv = 0.000000 37 | REFheight = 1500 38 | REFmulti = 1.000000 39 | REFgamma = 1.400000 40 | 41 | [Sun] 42 | SUNcolor = 255,244,221 43 | SUNmulti = 1.020 44 | SUNu = 0.646000 45 | SUNv = 0.468000 46 | 47 | -------------------------------------------------------------------------------- /Skyboxes/GCanyon_C_YumaPoint_3k.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gargaj/Foxotron/df7175dd3aa717800528bdd6802502c0426ebfc1/Skyboxes/GCanyon_C_YumaPoint_3k.hdr -------------------------------------------------------------------------------- /Skyboxes/GCanyon_C_YumaPoint_Env.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gargaj/Foxotron/df7175dd3aa717800528bdd6802502c0426ebfc1/Skyboxes/GCanyon_C_YumaPoint_Env.hdr -------------------------------------------------------------------------------- /Skyboxes/GrandCanyon_C_YumaPoint.ibl: -------------------------------------------------------------------------------- 1 | [Header] 2 | ICOfile = "GCanyon_C_YumaPoint_Thumb.jpg" 3 | PREVIEWfile = "GCanyon_C_YumaPoint_preview.jpg" 4 | Name = "Grand Canyon C" 5 | Author = "Blochi" 6 | Location = "Grand Canyon" 7 | Comment = "Bright daylight, high altitude, great for airplane renders" 8 | GEOlat = 36.08038998435272 9 | GEOlong = -112.22920417785645 10 | Link = "http://www.hdrlabs.com/sibl/archive.html" 11 | Date = "2008:11:28" 12 | Time = "12:55:00" 13 | Height = 100 14 | North = 0.41 15 | 16 | [Background] 17 | BGfile = "GCanyon_C_YumaPoint_8k.jpg" 18 | BGmap = 1 19 | BGu = 0.000000 20 | BGv = 0.000000 21 | BGheight = 4000 22 | 23 | [Enviroment] 24 | EVfile = "GCanyon_C_YumaPoint_Env.hdr" 25 | EVmap = 1 26 | EVu = 0.000000 27 | EVv = 0.000000 28 | EVheight = 180 29 | EVmulti = 1.000000 30 | EVgamma = 1.600000 31 | 32 | [Reflection] 33 | REFfile = "GCanyon_C_YumaPoint_3k.hdr" 34 | REFmap = 1 35 | REFu = 0.000000 36 | REFv = 0.000000 37 | REFheight = 1600 38 | REFmulti = 1.000000 39 | REFgamma = 1.600000 40 | 41 | [Sun] 42 | SUNcolor = 250,247,235 43 | SUNmulti = 1.000000 44 | SUNu = 0.824000 45 | SUNv = 0.376000 46 | 47 | -------------------------------------------------------------------------------- /Skyboxes/Tokyo_BigSight.ibl: -------------------------------------------------------------------------------- 1 | [Header] 2 | ICOfile = "Tokyo_BigSight_thumb.jpg" 3 | PREVIEWfile = "Tokyo_BigSight_preview.jpg" 4 | Name = "Tokyo BigSight" 5 | Author = "Blochi" 6 | Location = "Tokyo" 7 | Comment = "Conference center main entrance at night, big patterns on floor and ceiling" 8 | GEOlat = 35.6174260000000020 9 | GEOlong = 139.7786560000000100 10 | Link = "http://www.hdrlabs.com/sibl/archive.html" 11 | Date = "2009:12:165" 12 | Time = "20:00:00" 13 | Height = 1.600000 14 | 15 | [Background] 16 | BGfile = "Tokyo_BigSight_8k.jpg" 17 | BGmap = 1 18 | BGu = 0.000000 19 | BGv = 0.000000 20 | BGheight = 4096 21 | 22 | [Enviroment] 23 | EVfile = "Tokyo_BigSight_Env.hdr" 24 | EVmap = 1 25 | EVu = 0.000000 26 | EVv = 0.000000 27 | EVheight = 180 28 | EVmulti = 1.000000 29 | EVgamma = 1.800000 30 | 31 | [Reflection] 32 | REFfile = "Tokyo_BigSight_3k.hdr" 33 | REFmap = 1 34 | REFu = 0.000000 35 | REFv = 0.000000 36 | REFheight = 1600 37 | REFmulti = 1.000000 38 | REFgamma = 1.800000 39 | 40 | -------------------------------------------------------------------------------- /Skyboxes/Tokyo_BigSight_3k.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gargaj/Foxotron/df7175dd3aa717800528bdd6802502c0426ebfc1/Skyboxes/Tokyo_BigSight_3k.hdr -------------------------------------------------------------------------------- /Skyboxes/Tokyo_BigSight_Env.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gargaj/Foxotron/df7175dd3aa717800528bdd6802502c0426ebfc1/Skyboxes/Tokyo_BigSight_Env.hdr -------------------------------------------------------------------------------- /Skyboxes/brdf256.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gargaj/Foxotron/df7175dd3aa717800528bdd6802502c0426ebfc1/Skyboxes/brdf256.bin -------------------------------------------------------------------------------- /Skyboxes/skysphere.fbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gargaj/Foxotron/df7175dd3aa717800528bdd6802502c0426ebfc1/Skyboxes/skysphere.fbx -------------------------------------------------------------------------------- /Skyboxes/skysphere.fs: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | in vec3 out_worldpos; 4 | 5 | uniform float texture_lod; 6 | uniform sampler2D tex_skysphere; 7 | uniform sampler2D tex_skyenv; 8 | uniform bool has_tex_skyenv; 9 | uniform float skysphere_rotation; 10 | uniform float skysphere_blur; 11 | uniform float skysphere_opacity; 12 | uniform float skysphere_mip_count; 13 | uniform float exposure; 14 | uniform uint frame_count; 15 | uniform vec4 background_color; 16 | 17 | out vec4 frag_color; 18 | 19 | const float PI = 3.1415926536; 20 | 21 | // MurMurHash 3 finalizer. Implementation is in public domain. 22 | uint hash( uint h ) 23 | { 24 | h ^= h >> 16; 25 | h *= 0x85ebca6b; 26 | h ^= h >> 13; 27 | h *= 0xc2b2ae35; 28 | h ^= h >> 16; 29 | return h; 30 | } 31 | 32 | // Random function using the idea of StackOverflow user "Spatial" https://stackoverflow.com/a/17479300 33 | // Creates random 23 bits and puts them into the fraction bits of an 32-bit float. 34 | float random( uvec3 h ) 35 | { 36 | uint m = hash(h.x ^ hash( h.y ) ^ hash( h.z )); 37 | return uintBitsToFloat( ( m & 0x007FFFFFu ) | 0x3f800000u ) - 1.; 38 | } 39 | 40 | float random( vec3 v ) 41 | { 42 | return random(floatBitsToUint( v )); 43 | } 44 | 45 | vec2 sphere_to_polar( vec3 normal ) 46 | { 47 | normal = normalize( normal ); 48 | return vec2( ( atan( normal.z, normal.x ) + skysphere_rotation ) / PI / 2.0 + 0.5, acos( normal.y ) / PI ); 49 | } 50 | 51 | void main(void) 52 | { 53 | vec3 sky_env = textureLod( tex_skyenv, sphere_to_polar( normalize( out_worldpos ) ), 0.0f ).rgb; 54 | vec3 sky_color = textureLod( tex_skysphere, sphere_to_polar( normalize( out_worldpos ) ), skysphere_blur * skysphere_mip_count ).rgb; 55 | 56 | vec3 color = mix( background_color.rgb, mix( sky_color, sky_env, skysphere_blur ) , skysphere_opacity ); 57 | color *= exposure; 58 | color = color / (vec3(1.) + color); 59 | color = pow( color, vec3( 1. / 2.2 )); 60 | float dither = random( uvec3( floatBitsToUint( gl_FragCoord.xy ), frame_count ) ); 61 | color += vec3( (-1.5/256.) + (3./256.) * dither ); 62 | 63 | frag_color = vec4( color, 1.0f ); 64 | } 65 | -------------------------------------------------------------------------------- /Skyboxes/skysphere.vs: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | in vec3 in_pos; 4 | 5 | out vec3 out_worldpos; 6 | 7 | uniform mat4x4 mat_projection; 8 | uniform mat4x4 mat_view; 9 | 10 | void main() 11 | { 12 | vec4 o = vec4( in_pos.x, in_pos.y, in_pos.z, 1.0 ); 13 | out_worldpos = o.xyz; 14 | o = mat_view * o; 15 | o = mat_projection * o; 16 | gl_Position = o; 17 | } -------------------------------------------------------------------------------- /cmake_all.bat: -------------------------------------------------------------------------------- 1 | mkdir _package 2 | 3 | set X64=ON 4 | call :build 5 | set X64=OFF 6 | call :build 7 | 8 | copy LICENSE _package 9 | copy README.md _package 10 | copy config.json _package 11 | 12 | mkdir _package\Shaders 13 | copy Shaders _package\Shaders\ 14 | mkdir _package\Skyboxes 15 | copy Skyboxes _package\Skyboxes\ 16 | 17 | cd _package 18 | set FN=Foxotron_%date:~0,4%-%date:~5,2%-%date:~8,2%.zip 19 | zip -r -9 %FN% * 20 | move %FN% ../ 21 | cd .. 22 | 23 | rmdir /s /q _package 24 | goto :eof 25 | 26 | REM --------------------- BUILD TIME ------------------------------- 27 | 28 | :build 29 | 30 | set COMPILER=Visual Studio 16 2019 31 | set ARCH=Win32 32 | if not "%X64%"=="ON" goto skipvs 33 | set ARCH=x64 34 | :skipvs 35 | 36 | set OUT_DIR=x86 37 | set PLATFORM=W32 38 | if not "%X64%"=="ON" goto skipme 39 | set OUT_DIR=x64 40 | set PLATFORM=W64 41 | :skipme 42 | 43 | mkdir build.vs16.%OUT_DIR% 44 | cd build.vs16.%OUT_DIR% 45 | cmake -DFOXOTRON_64BIT="%X64%" -G "%COMPILER%" -A "%ARCH%" ../ 46 | cmake --build . --config Release 47 | mkdir ..\_package\ 48 | del ..\_package\Foxotron_%PLATFORM%.exe 49 | copy .\Release\Foxotron.exe ..\_package\Foxotron_%PLATFORM%.exe 50 | cd .. 51 | goto :eof 52 | -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "shaders":[ 3 | { 4 | "name": "Physically Based", 5 | "vertexShader": "Shaders/pbr.vs", 6 | "fragmentShader": "Shaders/pbr.fs", 7 | "showSkybox": true 8 | }, 9 | { 10 | "name": "Basic SpecGloss", 11 | "vertexShader": "Shaders/basic_specgloss.vs", 12 | "fragmentShader": "Shaders/basic_specgloss.fs", 13 | "showSkybox": true 14 | } 15 | ], 16 | "skyImages":[ 17 | { 18 | "reflection": "Skyboxes/Barce_Rooftop_C_3k.hdr", 19 | "env": "Skyboxes/Barce_Rooftop_C_Env.hdr", 20 | "metadata": "Skyboxes/Barcelona_Rooftops.ibl" 21 | }, 22 | { 23 | "reflection": "Skyboxes/GCanyon_C_YumaPoint_3k.hdr", 24 | "env": "Skyboxes/GCanyon_C_YumaPoint_Env.hdr", 25 | "metadata": "Skyboxes/GrandCanyon_C_YumaPoint.ibl" 26 | }, 27 | { 28 | "reflection": "Skyboxes/Tokyo_BigSight_3k.hdr", 29 | "env": "Skyboxes/Tokyo_BigSight_Env.hdr", 30 | "metadata": "Skyboxes/Tokyo_BigSight.iblr" 31 | } 32 | ] 33 | } 34 | -------------------------------------------------------------------------------- /data/windows/SetupDialog.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gargaj/Foxotron/df7175dd3aa717800528bdd6802502c0426ebfc1/data/windows/SetupDialog.rc -------------------------------------------------------------------------------- /data/windows/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by SetupDialog.rc 4 | // 5 | #define IDD_SETUP 101 6 | #define IDC_RESOLUTION 1001 7 | #define IDC_FULLSCREEN 1002 8 | #define IDC_VSYNC 1003 9 | #define IDC_MULTISAMPLING 1004 10 | 11 | // Next default values for new objects 12 | // 13 | #ifdef APSTUDIO_INVOKED 14 | #ifndef APSTUDIO_READONLY_SYMBOLS 15 | #define _APS_NEXT_RESOURCE_VALUE 102 16 | #define _APS_NEXT_COMMAND_VALUE 40001 17 | #define _APS_NEXT_CONTROL_VALUE 1008 18 | #define _APS_NEXT_SYMED_VALUE 101 19 | #endif 20 | #endif 21 | -------------------------------------------------------------------------------- /externals/glew/GL/wglew.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** The OpenGL Extension Wrangler Library 3 | ** Copyright (C) 2008-2015, Nigel Stewart 4 | ** Copyright (C) 2002-2008, Milan Ikits 5 | ** Copyright (C) 2002-2008, Marcelo E. Magallon 6 | ** Copyright (C) 2002, Lev Povalahev 7 | ** All rights reserved. 8 | ** 9 | ** Redistribution and use in source and binary forms, with or without 10 | ** modification, are permitted provided that the following conditions are met: 11 | ** 12 | ** * Redistributions of source code must retain the above copyright notice, 13 | ** this list of conditions and the following disclaimer. 14 | ** * Redistributions in binary form must reproduce the above copyright notice, 15 | ** this list of conditions and the following disclaimer in the documentation 16 | ** and/or other materials provided with the distribution. 17 | ** * The name of the author may be used to endorse or promote products 18 | ** derived from this software without specific prior written permission. 19 | ** 20 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24 | ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30 | ** THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | /* 34 | ** Copyright (c) 2007 The Khronos Group Inc. 35 | ** 36 | ** Permission is hereby granted, free of charge, to any person obtaining a 37 | ** copy of this software and/or associated documentation files (the 38 | ** "Materials"), to deal in the Materials without restriction, including 39 | ** without limitation the rights to use, copy, modify, merge, publish, 40 | ** distribute, sublicense, and/or sell copies of the Materials, and to 41 | ** permit persons to whom the Materials are furnished to do so, subject to 42 | ** the following conditions: 43 | ** 44 | ** The above copyright notice and this permission notice shall be included 45 | ** in all copies or substantial portions of the Materials. 46 | ** 47 | ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 48 | ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 49 | ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 50 | ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 51 | ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 52 | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 53 | ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 54 | */ 55 | 56 | #ifndef __wglew_h__ 57 | #define __wglew_h__ 58 | #define __WGLEW_H__ 59 | 60 | #ifdef __wglext_h_ 61 | #error wglext.h included before wglew.h 62 | #endif 63 | 64 | #define __wglext_h_ 65 | 66 | #if !defined(WINAPI) 67 | # ifndef WIN32_LEAN_AND_MEAN 68 | # define WIN32_LEAN_AND_MEAN 1 69 | # endif 70 | #include 71 | # undef WIN32_LEAN_AND_MEAN 72 | #endif 73 | 74 | /* 75 | * GLEW_STATIC needs to be set when using the static version. 76 | * GLEW_BUILD is set when building the DLL version. 77 | */ 78 | #ifdef GLEW_STATIC 79 | # define GLEWAPI extern 80 | #else 81 | # ifdef GLEW_BUILD 82 | # define GLEWAPI extern __declspec(dllexport) 83 | # else 84 | # define GLEWAPI extern __declspec(dllimport) 85 | # endif 86 | #endif 87 | 88 | #ifdef __cplusplus 89 | extern "C" { 90 | #endif 91 | 92 | /* -------------------------- WGL_3DFX_multisample ------------------------- */ 93 | 94 | #ifndef WGL_3DFX_multisample 95 | #define WGL_3DFX_multisample 1 96 | 97 | #define WGL_SAMPLE_BUFFERS_3DFX 0x2060 98 | #define WGL_SAMPLES_3DFX 0x2061 99 | 100 | #define WGLEW_3DFX_multisample WGLEW_GET_VAR(__WGLEW_3DFX_multisample) 101 | 102 | #endif /* WGL_3DFX_multisample */ 103 | 104 | /* ------------------------- WGL_3DL_stereo_control ------------------------ */ 105 | 106 | #ifndef WGL_3DL_stereo_control 107 | #define WGL_3DL_stereo_control 1 108 | 109 | #define WGL_STEREO_EMITTER_ENABLE_3DL 0x2055 110 | #define WGL_STEREO_EMITTER_DISABLE_3DL 0x2056 111 | #define WGL_STEREO_POLARITY_NORMAL_3DL 0x2057 112 | #define WGL_STEREO_POLARITY_INVERT_3DL 0x2058 113 | 114 | typedef BOOL (WINAPI * PFNWGLSETSTEREOEMITTERSTATE3DLPROC) (HDC hDC, UINT uState); 115 | 116 | #define wglSetStereoEmitterState3DL WGLEW_GET_FUN(__wglewSetStereoEmitterState3DL) 117 | 118 | #define WGLEW_3DL_stereo_control WGLEW_GET_VAR(__WGLEW_3DL_stereo_control) 119 | 120 | #endif /* WGL_3DL_stereo_control */ 121 | 122 | /* ------------------------ WGL_AMD_gpu_association ------------------------ */ 123 | 124 | #ifndef WGL_AMD_gpu_association 125 | #define WGL_AMD_gpu_association 1 126 | 127 | #define WGL_GPU_VENDOR_AMD 0x1F00 128 | #define WGL_GPU_RENDERER_STRING_AMD 0x1F01 129 | #define WGL_GPU_OPENGL_VERSION_STRING_AMD 0x1F02 130 | #define WGL_GPU_FASTEST_TARGET_GPUS_AMD 0x21A2 131 | #define WGL_GPU_RAM_AMD 0x21A3 132 | #define WGL_GPU_CLOCK_AMD 0x21A4 133 | #define WGL_GPU_NUM_PIPES_AMD 0x21A5 134 | #define WGL_GPU_NUM_SIMD_AMD 0x21A6 135 | #define WGL_GPU_NUM_RB_AMD 0x21A7 136 | #define WGL_GPU_NUM_SPI_AMD 0x21A8 137 | 138 | typedef VOID (WINAPI * PFNWGLBLITCONTEXTFRAMEBUFFERAMDPROC) (HGLRC dstCtx, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); 139 | typedef HGLRC (WINAPI * PFNWGLCREATEASSOCIATEDCONTEXTAMDPROC) (UINT id); 140 | typedef HGLRC (WINAPI * PFNWGLCREATEASSOCIATEDCONTEXTATTRIBSAMDPROC) (UINT id, HGLRC hShareContext, const int* attribList); 141 | typedef BOOL (WINAPI * PFNWGLDELETEASSOCIATEDCONTEXTAMDPROC) (HGLRC hglrc); 142 | typedef UINT (WINAPI * PFNWGLGETCONTEXTGPUIDAMDPROC) (HGLRC hglrc); 143 | typedef HGLRC (WINAPI * PFNWGLGETCURRENTASSOCIATEDCONTEXTAMDPROC) (void); 144 | typedef UINT (WINAPI * PFNWGLGETGPUIDSAMDPROC) (UINT maxCount, UINT* ids); 145 | typedef INT (WINAPI * PFNWGLGETGPUINFOAMDPROC) (UINT id, INT property, GLenum dataType, UINT size, void* data); 146 | typedef BOOL (WINAPI * PFNWGLMAKEASSOCIATEDCONTEXTCURRENTAMDPROC) (HGLRC hglrc); 147 | 148 | #define wglBlitContextFramebufferAMD WGLEW_GET_FUN(__wglewBlitContextFramebufferAMD) 149 | #define wglCreateAssociatedContextAMD WGLEW_GET_FUN(__wglewCreateAssociatedContextAMD) 150 | #define wglCreateAssociatedContextAttribsAMD WGLEW_GET_FUN(__wglewCreateAssociatedContextAttribsAMD) 151 | #define wglDeleteAssociatedContextAMD WGLEW_GET_FUN(__wglewDeleteAssociatedContextAMD) 152 | #define wglGetContextGPUIDAMD WGLEW_GET_FUN(__wglewGetContextGPUIDAMD) 153 | #define wglGetCurrentAssociatedContextAMD WGLEW_GET_FUN(__wglewGetCurrentAssociatedContextAMD) 154 | #define wglGetGPUIDsAMD WGLEW_GET_FUN(__wglewGetGPUIDsAMD) 155 | #define wglGetGPUInfoAMD WGLEW_GET_FUN(__wglewGetGPUInfoAMD) 156 | #define wglMakeAssociatedContextCurrentAMD WGLEW_GET_FUN(__wglewMakeAssociatedContextCurrentAMD) 157 | 158 | #define WGLEW_AMD_gpu_association WGLEW_GET_VAR(__WGLEW_AMD_gpu_association) 159 | 160 | #endif /* WGL_AMD_gpu_association */ 161 | 162 | /* ------------------------- WGL_ARB_buffer_region ------------------------- */ 163 | 164 | #ifndef WGL_ARB_buffer_region 165 | #define WGL_ARB_buffer_region 1 166 | 167 | #define WGL_FRONT_COLOR_BUFFER_BIT_ARB 0x00000001 168 | #define WGL_BACK_COLOR_BUFFER_BIT_ARB 0x00000002 169 | #define WGL_DEPTH_BUFFER_BIT_ARB 0x00000004 170 | #define WGL_STENCIL_BUFFER_BIT_ARB 0x00000008 171 | 172 | typedef HANDLE (WINAPI * PFNWGLCREATEBUFFERREGIONARBPROC) (HDC hDC, int iLayerPlane, UINT uType); 173 | typedef VOID (WINAPI * PFNWGLDELETEBUFFERREGIONARBPROC) (HANDLE hRegion); 174 | typedef BOOL (WINAPI * PFNWGLRESTOREBUFFERREGIONARBPROC) (HANDLE hRegion, int x, int y, int width, int height, int xSrc, int ySrc); 175 | typedef BOOL (WINAPI * PFNWGLSAVEBUFFERREGIONARBPROC) (HANDLE hRegion, int x, int y, int width, int height); 176 | 177 | #define wglCreateBufferRegionARB WGLEW_GET_FUN(__wglewCreateBufferRegionARB) 178 | #define wglDeleteBufferRegionARB WGLEW_GET_FUN(__wglewDeleteBufferRegionARB) 179 | #define wglRestoreBufferRegionARB WGLEW_GET_FUN(__wglewRestoreBufferRegionARB) 180 | #define wglSaveBufferRegionARB WGLEW_GET_FUN(__wglewSaveBufferRegionARB) 181 | 182 | #define WGLEW_ARB_buffer_region WGLEW_GET_VAR(__WGLEW_ARB_buffer_region) 183 | 184 | #endif /* WGL_ARB_buffer_region */ 185 | 186 | /* --------------------- WGL_ARB_context_flush_control --------------------- */ 187 | 188 | #ifndef WGL_ARB_context_flush_control 189 | #define WGL_ARB_context_flush_control 1 190 | 191 | #define WGL_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB 0x0000 192 | #define WGL_CONTEXT_RELEASE_BEHAVIOR_ARB 0x2097 193 | #define WGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB 0x2098 194 | 195 | #define WGLEW_ARB_context_flush_control WGLEW_GET_VAR(__WGLEW_ARB_context_flush_control) 196 | 197 | #endif /* WGL_ARB_context_flush_control */ 198 | 199 | /* ------------------------- WGL_ARB_create_context ------------------------ */ 200 | 201 | #ifndef WGL_ARB_create_context 202 | #define WGL_ARB_create_context 1 203 | 204 | #define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001 205 | #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002 206 | #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091 207 | #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092 208 | #define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093 209 | #define WGL_CONTEXT_FLAGS_ARB 0x2094 210 | #define ERROR_INVALID_VERSION_ARB 0x2095 211 | #define ERROR_INVALID_PROFILE_ARB 0x2096 212 | 213 | typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC, HGLRC hShareContext, const int* attribList); 214 | 215 | #define wglCreateContextAttribsARB WGLEW_GET_FUN(__wglewCreateContextAttribsARB) 216 | 217 | #define WGLEW_ARB_create_context WGLEW_GET_VAR(__WGLEW_ARB_create_context) 218 | 219 | #endif /* WGL_ARB_create_context */ 220 | 221 | /* --------------------- WGL_ARB_create_context_profile -------------------- */ 222 | 223 | #ifndef WGL_ARB_create_context_profile 224 | #define WGL_ARB_create_context_profile 1 225 | 226 | #define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 227 | #define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002 228 | #define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126 229 | 230 | #define WGLEW_ARB_create_context_profile WGLEW_GET_VAR(__WGLEW_ARB_create_context_profile) 231 | 232 | #endif /* WGL_ARB_create_context_profile */ 233 | 234 | /* ------------------- WGL_ARB_create_context_robustness ------------------- */ 235 | 236 | #ifndef WGL_ARB_create_context_robustness 237 | #define WGL_ARB_create_context_robustness 1 238 | 239 | #define WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004 240 | #define WGL_LOSE_CONTEXT_ON_RESET_ARB 0x8252 241 | #define WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256 242 | #define WGL_NO_RESET_NOTIFICATION_ARB 0x8261 243 | 244 | #define WGLEW_ARB_create_context_robustness WGLEW_GET_VAR(__WGLEW_ARB_create_context_robustness) 245 | 246 | #endif /* WGL_ARB_create_context_robustness */ 247 | 248 | /* ----------------------- WGL_ARB_extensions_string ----------------------- */ 249 | 250 | #ifndef WGL_ARB_extensions_string 251 | #define WGL_ARB_extensions_string 1 252 | 253 | typedef const char* (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc); 254 | 255 | #define wglGetExtensionsStringARB WGLEW_GET_FUN(__wglewGetExtensionsStringARB) 256 | 257 | #define WGLEW_ARB_extensions_string WGLEW_GET_VAR(__WGLEW_ARB_extensions_string) 258 | 259 | #endif /* WGL_ARB_extensions_string */ 260 | 261 | /* ------------------------ WGL_ARB_framebuffer_sRGB ----------------------- */ 262 | 263 | #ifndef WGL_ARB_framebuffer_sRGB 264 | #define WGL_ARB_framebuffer_sRGB 1 265 | 266 | #define WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20A9 267 | 268 | #define WGLEW_ARB_framebuffer_sRGB WGLEW_GET_VAR(__WGLEW_ARB_framebuffer_sRGB) 269 | 270 | #endif /* WGL_ARB_framebuffer_sRGB */ 271 | 272 | /* ----------------------- WGL_ARB_make_current_read ----------------------- */ 273 | 274 | #ifndef WGL_ARB_make_current_read 275 | #define WGL_ARB_make_current_read 1 276 | 277 | #define ERROR_INVALID_PIXEL_TYPE_ARB 0x2043 278 | #define ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB 0x2054 279 | 280 | typedef HDC (WINAPI * PFNWGLGETCURRENTREADDCARBPROC) (VOID); 281 | typedef BOOL (WINAPI * PFNWGLMAKECONTEXTCURRENTARBPROC) (HDC hDrawDC, HDC hReadDC, HGLRC hglrc); 282 | 283 | #define wglGetCurrentReadDCARB WGLEW_GET_FUN(__wglewGetCurrentReadDCARB) 284 | #define wglMakeContextCurrentARB WGLEW_GET_FUN(__wglewMakeContextCurrentARB) 285 | 286 | #define WGLEW_ARB_make_current_read WGLEW_GET_VAR(__WGLEW_ARB_make_current_read) 287 | 288 | #endif /* WGL_ARB_make_current_read */ 289 | 290 | /* -------------------------- WGL_ARB_multisample -------------------------- */ 291 | 292 | #ifndef WGL_ARB_multisample 293 | #define WGL_ARB_multisample 1 294 | 295 | #define WGL_SAMPLE_BUFFERS_ARB 0x2041 296 | #define WGL_SAMPLES_ARB 0x2042 297 | 298 | #define WGLEW_ARB_multisample WGLEW_GET_VAR(__WGLEW_ARB_multisample) 299 | 300 | #endif /* WGL_ARB_multisample */ 301 | 302 | /* ---------------------------- WGL_ARB_pbuffer ---------------------------- */ 303 | 304 | #ifndef WGL_ARB_pbuffer 305 | #define WGL_ARB_pbuffer 1 306 | 307 | #define WGL_DRAW_TO_PBUFFER_ARB 0x202D 308 | #define WGL_MAX_PBUFFER_PIXELS_ARB 0x202E 309 | #define WGL_MAX_PBUFFER_WIDTH_ARB 0x202F 310 | #define WGL_MAX_PBUFFER_HEIGHT_ARB 0x2030 311 | #define WGL_PBUFFER_LARGEST_ARB 0x2033 312 | #define WGL_PBUFFER_WIDTH_ARB 0x2034 313 | #define WGL_PBUFFER_HEIGHT_ARB 0x2035 314 | #define WGL_PBUFFER_LOST_ARB 0x2036 315 | 316 | DECLARE_HANDLE(HPBUFFERARB); 317 | 318 | typedef HPBUFFERARB (WINAPI * PFNWGLCREATEPBUFFERARBPROC) (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int* piAttribList); 319 | typedef BOOL (WINAPI * PFNWGLDESTROYPBUFFERARBPROC) (HPBUFFERARB hPbuffer); 320 | typedef HDC (WINAPI * PFNWGLGETPBUFFERDCARBPROC) (HPBUFFERARB hPbuffer); 321 | typedef BOOL (WINAPI * PFNWGLQUERYPBUFFERARBPROC) (HPBUFFERARB hPbuffer, int iAttribute, int* piValue); 322 | typedef int (WINAPI * PFNWGLRELEASEPBUFFERDCARBPROC) (HPBUFFERARB hPbuffer, HDC hDC); 323 | 324 | #define wglCreatePbufferARB WGLEW_GET_FUN(__wglewCreatePbufferARB) 325 | #define wglDestroyPbufferARB WGLEW_GET_FUN(__wglewDestroyPbufferARB) 326 | #define wglGetPbufferDCARB WGLEW_GET_FUN(__wglewGetPbufferDCARB) 327 | #define wglQueryPbufferARB WGLEW_GET_FUN(__wglewQueryPbufferARB) 328 | #define wglReleasePbufferDCARB WGLEW_GET_FUN(__wglewReleasePbufferDCARB) 329 | 330 | #define WGLEW_ARB_pbuffer WGLEW_GET_VAR(__WGLEW_ARB_pbuffer) 331 | 332 | #endif /* WGL_ARB_pbuffer */ 333 | 334 | /* -------------------------- WGL_ARB_pixel_format ------------------------- */ 335 | 336 | #ifndef WGL_ARB_pixel_format 337 | #define WGL_ARB_pixel_format 1 338 | 339 | #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000 340 | #define WGL_DRAW_TO_WINDOW_ARB 0x2001 341 | #define WGL_DRAW_TO_BITMAP_ARB 0x2002 342 | #define WGL_ACCELERATION_ARB 0x2003 343 | #define WGL_NEED_PALETTE_ARB 0x2004 344 | #define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005 345 | #define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006 346 | #define WGL_SWAP_METHOD_ARB 0x2007 347 | #define WGL_NUMBER_OVERLAYS_ARB 0x2008 348 | #define WGL_NUMBER_UNDERLAYS_ARB 0x2009 349 | #define WGL_TRANSPARENT_ARB 0x200A 350 | #define WGL_SHARE_DEPTH_ARB 0x200C 351 | #define WGL_SHARE_STENCIL_ARB 0x200D 352 | #define WGL_SHARE_ACCUM_ARB 0x200E 353 | #define WGL_SUPPORT_GDI_ARB 0x200F 354 | #define WGL_SUPPORT_OPENGL_ARB 0x2010 355 | #define WGL_DOUBLE_BUFFER_ARB 0x2011 356 | #define WGL_STEREO_ARB 0x2012 357 | #define WGL_PIXEL_TYPE_ARB 0x2013 358 | #define WGL_COLOR_BITS_ARB 0x2014 359 | #define WGL_RED_BITS_ARB 0x2015 360 | #define WGL_RED_SHIFT_ARB 0x2016 361 | #define WGL_GREEN_BITS_ARB 0x2017 362 | #define WGL_GREEN_SHIFT_ARB 0x2018 363 | #define WGL_BLUE_BITS_ARB 0x2019 364 | #define WGL_BLUE_SHIFT_ARB 0x201A 365 | #define WGL_ALPHA_BITS_ARB 0x201B 366 | #define WGL_ALPHA_SHIFT_ARB 0x201C 367 | #define WGL_ACCUM_BITS_ARB 0x201D 368 | #define WGL_ACCUM_RED_BITS_ARB 0x201E 369 | #define WGL_ACCUM_GREEN_BITS_ARB 0x201F 370 | #define WGL_ACCUM_BLUE_BITS_ARB 0x2020 371 | #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021 372 | #define WGL_DEPTH_BITS_ARB 0x2022 373 | #define WGL_STENCIL_BITS_ARB 0x2023 374 | #define WGL_AUX_BUFFERS_ARB 0x2024 375 | #define WGL_NO_ACCELERATION_ARB 0x2025 376 | #define WGL_GENERIC_ACCELERATION_ARB 0x2026 377 | #define WGL_FULL_ACCELERATION_ARB 0x2027 378 | #define WGL_SWAP_EXCHANGE_ARB 0x2028 379 | #define WGL_SWAP_COPY_ARB 0x2029 380 | #define WGL_SWAP_UNDEFINED_ARB 0x202A 381 | #define WGL_TYPE_RGBA_ARB 0x202B 382 | #define WGL_TYPE_COLORINDEX_ARB 0x202C 383 | #define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037 384 | #define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038 385 | #define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039 386 | #define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A 387 | #define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B 388 | 389 | typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats); 390 | typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBFVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int* piAttributes, FLOAT *pfValues); 391 | typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int* piAttributes, int *piValues); 392 | 393 | #define wglChoosePixelFormatARB WGLEW_GET_FUN(__wglewChoosePixelFormatARB) 394 | #define wglGetPixelFormatAttribfvARB WGLEW_GET_FUN(__wglewGetPixelFormatAttribfvARB) 395 | #define wglGetPixelFormatAttribivARB WGLEW_GET_FUN(__wglewGetPixelFormatAttribivARB) 396 | 397 | #define WGLEW_ARB_pixel_format WGLEW_GET_VAR(__WGLEW_ARB_pixel_format) 398 | 399 | #endif /* WGL_ARB_pixel_format */ 400 | 401 | /* ----------------------- WGL_ARB_pixel_format_float ---------------------- */ 402 | 403 | #ifndef WGL_ARB_pixel_format_float 404 | #define WGL_ARB_pixel_format_float 1 405 | 406 | #define WGL_TYPE_RGBA_FLOAT_ARB 0x21A0 407 | 408 | #define WGLEW_ARB_pixel_format_float WGLEW_GET_VAR(__WGLEW_ARB_pixel_format_float) 409 | 410 | #endif /* WGL_ARB_pixel_format_float */ 411 | 412 | /* ------------------------- WGL_ARB_render_texture ------------------------ */ 413 | 414 | #ifndef WGL_ARB_render_texture 415 | #define WGL_ARB_render_texture 1 416 | 417 | #define WGL_BIND_TO_TEXTURE_RGB_ARB 0x2070 418 | #define WGL_BIND_TO_TEXTURE_RGBA_ARB 0x2071 419 | #define WGL_TEXTURE_FORMAT_ARB 0x2072 420 | #define WGL_TEXTURE_TARGET_ARB 0x2073 421 | #define WGL_MIPMAP_TEXTURE_ARB 0x2074 422 | #define WGL_TEXTURE_RGB_ARB 0x2075 423 | #define WGL_TEXTURE_RGBA_ARB 0x2076 424 | #define WGL_NO_TEXTURE_ARB 0x2077 425 | #define WGL_TEXTURE_CUBE_MAP_ARB 0x2078 426 | #define WGL_TEXTURE_1D_ARB 0x2079 427 | #define WGL_TEXTURE_2D_ARB 0x207A 428 | #define WGL_MIPMAP_LEVEL_ARB 0x207B 429 | #define WGL_CUBE_MAP_FACE_ARB 0x207C 430 | #define WGL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x207D 431 | #define WGL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x207E 432 | #define WGL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x207F 433 | #define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x2080 434 | #define WGL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x2081 435 | #define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x2082 436 | #define WGL_FRONT_LEFT_ARB 0x2083 437 | #define WGL_FRONT_RIGHT_ARB 0x2084 438 | #define WGL_BACK_LEFT_ARB 0x2085 439 | #define WGL_BACK_RIGHT_ARB 0x2086 440 | #define WGL_AUX0_ARB 0x2087 441 | #define WGL_AUX1_ARB 0x2088 442 | #define WGL_AUX2_ARB 0x2089 443 | #define WGL_AUX3_ARB 0x208A 444 | #define WGL_AUX4_ARB 0x208B 445 | #define WGL_AUX5_ARB 0x208C 446 | #define WGL_AUX6_ARB 0x208D 447 | #define WGL_AUX7_ARB 0x208E 448 | #define WGL_AUX8_ARB 0x208F 449 | #define WGL_AUX9_ARB 0x2090 450 | 451 | typedef BOOL (WINAPI * PFNWGLBINDTEXIMAGEARBPROC) (HPBUFFERARB hPbuffer, int iBuffer); 452 | typedef BOOL (WINAPI * PFNWGLRELEASETEXIMAGEARBPROC) (HPBUFFERARB hPbuffer, int iBuffer); 453 | typedef BOOL (WINAPI * PFNWGLSETPBUFFERATTRIBARBPROC) (HPBUFFERARB hPbuffer, const int* piAttribList); 454 | 455 | #define wglBindTexImageARB WGLEW_GET_FUN(__wglewBindTexImageARB) 456 | #define wglReleaseTexImageARB WGLEW_GET_FUN(__wglewReleaseTexImageARB) 457 | #define wglSetPbufferAttribARB WGLEW_GET_FUN(__wglewSetPbufferAttribARB) 458 | 459 | #define WGLEW_ARB_render_texture WGLEW_GET_VAR(__WGLEW_ARB_render_texture) 460 | 461 | #endif /* WGL_ARB_render_texture */ 462 | 463 | /* ---------------- WGL_ARB_robustness_application_isolation --------------- */ 464 | 465 | #ifndef WGL_ARB_robustness_application_isolation 466 | #define WGL_ARB_robustness_application_isolation 1 467 | 468 | #define WGL_CONTEXT_RESET_ISOLATION_BIT_ARB 0x00000008 469 | 470 | #define WGLEW_ARB_robustness_application_isolation WGLEW_GET_VAR(__WGLEW_ARB_robustness_application_isolation) 471 | 472 | #endif /* WGL_ARB_robustness_application_isolation */ 473 | 474 | /* ---------------- WGL_ARB_robustness_share_group_isolation --------------- */ 475 | 476 | #ifndef WGL_ARB_robustness_share_group_isolation 477 | #define WGL_ARB_robustness_share_group_isolation 1 478 | 479 | #define WGL_CONTEXT_RESET_ISOLATION_BIT_ARB 0x00000008 480 | 481 | #define WGLEW_ARB_robustness_share_group_isolation WGLEW_GET_VAR(__WGLEW_ARB_robustness_share_group_isolation) 482 | 483 | #endif /* WGL_ARB_robustness_share_group_isolation */ 484 | 485 | /* ----------------------- WGL_ATI_pixel_format_float ---------------------- */ 486 | 487 | #ifndef WGL_ATI_pixel_format_float 488 | #define WGL_ATI_pixel_format_float 1 489 | 490 | #define WGL_TYPE_RGBA_FLOAT_ATI 0x21A0 491 | #define GL_RGBA_FLOAT_MODE_ATI 0x8820 492 | #define GL_COLOR_CLEAR_UNCLAMPED_VALUE_ATI 0x8835 493 | 494 | #define WGLEW_ATI_pixel_format_float WGLEW_GET_VAR(__WGLEW_ATI_pixel_format_float) 495 | 496 | #endif /* WGL_ATI_pixel_format_float */ 497 | 498 | /* -------------------- WGL_ATI_render_texture_rectangle ------------------- */ 499 | 500 | #ifndef WGL_ATI_render_texture_rectangle 501 | #define WGL_ATI_render_texture_rectangle 1 502 | 503 | #define WGL_TEXTURE_RECTANGLE_ATI 0x21A5 504 | 505 | #define WGLEW_ATI_render_texture_rectangle WGLEW_GET_VAR(__WGLEW_ATI_render_texture_rectangle) 506 | 507 | #endif /* WGL_ATI_render_texture_rectangle */ 508 | 509 | /* ------------------- WGL_EXT_create_context_es2_profile ------------------ */ 510 | 511 | #ifndef WGL_EXT_create_context_es2_profile 512 | #define WGL_EXT_create_context_es2_profile 1 513 | 514 | #define WGL_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004 515 | 516 | #define WGLEW_EXT_create_context_es2_profile WGLEW_GET_VAR(__WGLEW_EXT_create_context_es2_profile) 517 | 518 | #endif /* WGL_EXT_create_context_es2_profile */ 519 | 520 | /* ------------------- WGL_EXT_create_context_es_profile ------------------- */ 521 | 522 | #ifndef WGL_EXT_create_context_es_profile 523 | #define WGL_EXT_create_context_es_profile 1 524 | 525 | #define WGL_CONTEXT_ES_PROFILE_BIT_EXT 0x00000004 526 | 527 | #define WGLEW_EXT_create_context_es_profile WGLEW_GET_VAR(__WGLEW_EXT_create_context_es_profile) 528 | 529 | #endif /* WGL_EXT_create_context_es_profile */ 530 | 531 | /* -------------------------- WGL_EXT_depth_float -------------------------- */ 532 | 533 | #ifndef WGL_EXT_depth_float 534 | #define WGL_EXT_depth_float 1 535 | 536 | #define WGL_DEPTH_FLOAT_EXT 0x2040 537 | 538 | #define WGLEW_EXT_depth_float WGLEW_GET_VAR(__WGLEW_EXT_depth_float) 539 | 540 | #endif /* WGL_EXT_depth_float */ 541 | 542 | /* ---------------------- WGL_EXT_display_color_table ---------------------- */ 543 | 544 | #ifndef WGL_EXT_display_color_table 545 | #define WGL_EXT_display_color_table 1 546 | 547 | typedef GLboolean (WINAPI * PFNWGLBINDDISPLAYCOLORTABLEEXTPROC) (GLushort id); 548 | typedef GLboolean (WINAPI * PFNWGLCREATEDISPLAYCOLORTABLEEXTPROC) (GLushort id); 549 | typedef void (WINAPI * PFNWGLDESTROYDISPLAYCOLORTABLEEXTPROC) (GLushort id); 550 | typedef GLboolean (WINAPI * PFNWGLLOADDISPLAYCOLORTABLEEXTPROC) (GLushort* table, GLuint length); 551 | 552 | #define wglBindDisplayColorTableEXT WGLEW_GET_FUN(__wglewBindDisplayColorTableEXT) 553 | #define wglCreateDisplayColorTableEXT WGLEW_GET_FUN(__wglewCreateDisplayColorTableEXT) 554 | #define wglDestroyDisplayColorTableEXT WGLEW_GET_FUN(__wglewDestroyDisplayColorTableEXT) 555 | #define wglLoadDisplayColorTableEXT WGLEW_GET_FUN(__wglewLoadDisplayColorTableEXT) 556 | 557 | #define WGLEW_EXT_display_color_table WGLEW_GET_VAR(__WGLEW_EXT_display_color_table) 558 | 559 | #endif /* WGL_EXT_display_color_table */ 560 | 561 | /* ----------------------- WGL_EXT_extensions_string ----------------------- */ 562 | 563 | #ifndef WGL_EXT_extensions_string 564 | #define WGL_EXT_extensions_string 1 565 | 566 | typedef const char* (WINAPI * PFNWGLGETEXTENSIONSSTRINGEXTPROC) (void); 567 | 568 | #define wglGetExtensionsStringEXT WGLEW_GET_FUN(__wglewGetExtensionsStringEXT) 569 | 570 | #define WGLEW_EXT_extensions_string WGLEW_GET_VAR(__WGLEW_EXT_extensions_string) 571 | 572 | #endif /* WGL_EXT_extensions_string */ 573 | 574 | /* ------------------------ WGL_EXT_framebuffer_sRGB ----------------------- */ 575 | 576 | #ifndef WGL_EXT_framebuffer_sRGB 577 | #define WGL_EXT_framebuffer_sRGB 1 578 | 579 | #define WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20A9 580 | 581 | #define WGLEW_EXT_framebuffer_sRGB WGLEW_GET_VAR(__WGLEW_EXT_framebuffer_sRGB) 582 | 583 | #endif /* WGL_EXT_framebuffer_sRGB */ 584 | 585 | /* ----------------------- WGL_EXT_make_current_read ----------------------- */ 586 | 587 | #ifndef WGL_EXT_make_current_read 588 | #define WGL_EXT_make_current_read 1 589 | 590 | #define ERROR_INVALID_PIXEL_TYPE_EXT 0x2043 591 | 592 | typedef HDC (WINAPI * PFNWGLGETCURRENTREADDCEXTPROC) (VOID); 593 | typedef BOOL (WINAPI * PFNWGLMAKECONTEXTCURRENTEXTPROC) (HDC hDrawDC, HDC hReadDC, HGLRC hglrc); 594 | 595 | #define wglGetCurrentReadDCEXT WGLEW_GET_FUN(__wglewGetCurrentReadDCEXT) 596 | #define wglMakeContextCurrentEXT WGLEW_GET_FUN(__wglewMakeContextCurrentEXT) 597 | 598 | #define WGLEW_EXT_make_current_read WGLEW_GET_VAR(__WGLEW_EXT_make_current_read) 599 | 600 | #endif /* WGL_EXT_make_current_read */ 601 | 602 | /* -------------------------- WGL_EXT_multisample -------------------------- */ 603 | 604 | #ifndef WGL_EXT_multisample 605 | #define WGL_EXT_multisample 1 606 | 607 | #define WGL_SAMPLE_BUFFERS_EXT 0x2041 608 | #define WGL_SAMPLES_EXT 0x2042 609 | 610 | #define WGLEW_EXT_multisample WGLEW_GET_VAR(__WGLEW_EXT_multisample) 611 | 612 | #endif /* WGL_EXT_multisample */ 613 | 614 | /* ---------------------------- WGL_EXT_pbuffer ---------------------------- */ 615 | 616 | #ifndef WGL_EXT_pbuffer 617 | #define WGL_EXT_pbuffer 1 618 | 619 | #define WGL_DRAW_TO_PBUFFER_EXT 0x202D 620 | #define WGL_MAX_PBUFFER_PIXELS_EXT 0x202E 621 | #define WGL_MAX_PBUFFER_WIDTH_EXT 0x202F 622 | #define WGL_MAX_PBUFFER_HEIGHT_EXT 0x2030 623 | #define WGL_OPTIMAL_PBUFFER_WIDTH_EXT 0x2031 624 | #define WGL_OPTIMAL_PBUFFER_HEIGHT_EXT 0x2032 625 | #define WGL_PBUFFER_LARGEST_EXT 0x2033 626 | #define WGL_PBUFFER_WIDTH_EXT 0x2034 627 | #define WGL_PBUFFER_HEIGHT_EXT 0x2035 628 | 629 | DECLARE_HANDLE(HPBUFFEREXT); 630 | 631 | typedef HPBUFFEREXT (WINAPI * PFNWGLCREATEPBUFFEREXTPROC) (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int* piAttribList); 632 | typedef BOOL (WINAPI * PFNWGLDESTROYPBUFFEREXTPROC) (HPBUFFEREXT hPbuffer); 633 | typedef HDC (WINAPI * PFNWGLGETPBUFFERDCEXTPROC) (HPBUFFEREXT hPbuffer); 634 | typedef BOOL (WINAPI * PFNWGLQUERYPBUFFEREXTPROC) (HPBUFFEREXT hPbuffer, int iAttribute, int* piValue); 635 | typedef int (WINAPI * PFNWGLRELEASEPBUFFERDCEXTPROC) (HPBUFFEREXT hPbuffer, HDC hDC); 636 | 637 | #define wglCreatePbufferEXT WGLEW_GET_FUN(__wglewCreatePbufferEXT) 638 | #define wglDestroyPbufferEXT WGLEW_GET_FUN(__wglewDestroyPbufferEXT) 639 | #define wglGetPbufferDCEXT WGLEW_GET_FUN(__wglewGetPbufferDCEXT) 640 | #define wglQueryPbufferEXT WGLEW_GET_FUN(__wglewQueryPbufferEXT) 641 | #define wglReleasePbufferDCEXT WGLEW_GET_FUN(__wglewReleasePbufferDCEXT) 642 | 643 | #define WGLEW_EXT_pbuffer WGLEW_GET_VAR(__WGLEW_EXT_pbuffer) 644 | 645 | #endif /* WGL_EXT_pbuffer */ 646 | 647 | /* -------------------------- WGL_EXT_pixel_format ------------------------- */ 648 | 649 | #ifndef WGL_EXT_pixel_format 650 | #define WGL_EXT_pixel_format 1 651 | 652 | #define WGL_NUMBER_PIXEL_FORMATS_EXT 0x2000 653 | #define WGL_DRAW_TO_WINDOW_EXT 0x2001 654 | #define WGL_DRAW_TO_BITMAP_EXT 0x2002 655 | #define WGL_ACCELERATION_EXT 0x2003 656 | #define WGL_NEED_PALETTE_EXT 0x2004 657 | #define WGL_NEED_SYSTEM_PALETTE_EXT 0x2005 658 | #define WGL_SWAP_LAYER_BUFFERS_EXT 0x2006 659 | #define WGL_SWAP_METHOD_EXT 0x2007 660 | #define WGL_NUMBER_OVERLAYS_EXT 0x2008 661 | #define WGL_NUMBER_UNDERLAYS_EXT 0x2009 662 | #define WGL_TRANSPARENT_EXT 0x200A 663 | #define WGL_TRANSPARENT_VALUE_EXT 0x200B 664 | #define WGL_SHARE_DEPTH_EXT 0x200C 665 | #define WGL_SHARE_STENCIL_EXT 0x200D 666 | #define WGL_SHARE_ACCUM_EXT 0x200E 667 | #define WGL_SUPPORT_GDI_EXT 0x200F 668 | #define WGL_SUPPORT_OPENGL_EXT 0x2010 669 | #define WGL_DOUBLE_BUFFER_EXT 0x2011 670 | #define WGL_STEREO_EXT 0x2012 671 | #define WGL_PIXEL_TYPE_EXT 0x2013 672 | #define WGL_COLOR_BITS_EXT 0x2014 673 | #define WGL_RED_BITS_EXT 0x2015 674 | #define WGL_RED_SHIFT_EXT 0x2016 675 | #define WGL_GREEN_BITS_EXT 0x2017 676 | #define WGL_GREEN_SHIFT_EXT 0x2018 677 | #define WGL_BLUE_BITS_EXT 0x2019 678 | #define WGL_BLUE_SHIFT_EXT 0x201A 679 | #define WGL_ALPHA_BITS_EXT 0x201B 680 | #define WGL_ALPHA_SHIFT_EXT 0x201C 681 | #define WGL_ACCUM_BITS_EXT 0x201D 682 | #define WGL_ACCUM_RED_BITS_EXT 0x201E 683 | #define WGL_ACCUM_GREEN_BITS_EXT 0x201F 684 | #define WGL_ACCUM_BLUE_BITS_EXT 0x2020 685 | #define WGL_ACCUM_ALPHA_BITS_EXT 0x2021 686 | #define WGL_DEPTH_BITS_EXT 0x2022 687 | #define WGL_STENCIL_BITS_EXT 0x2023 688 | #define WGL_AUX_BUFFERS_EXT 0x2024 689 | #define WGL_NO_ACCELERATION_EXT 0x2025 690 | #define WGL_GENERIC_ACCELERATION_EXT 0x2026 691 | #define WGL_FULL_ACCELERATION_EXT 0x2027 692 | #define WGL_SWAP_EXCHANGE_EXT 0x2028 693 | #define WGL_SWAP_COPY_EXT 0x2029 694 | #define WGL_SWAP_UNDEFINED_EXT 0x202A 695 | #define WGL_TYPE_RGBA_EXT 0x202B 696 | #define WGL_TYPE_COLORINDEX_EXT 0x202C 697 | 698 | typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATEXTPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats); 699 | typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBFVEXTPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int* piAttributes, FLOAT *pfValues); 700 | typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVEXTPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int* piAttributes, int *piValues); 701 | 702 | #define wglChoosePixelFormatEXT WGLEW_GET_FUN(__wglewChoosePixelFormatEXT) 703 | #define wglGetPixelFormatAttribfvEXT WGLEW_GET_FUN(__wglewGetPixelFormatAttribfvEXT) 704 | #define wglGetPixelFormatAttribivEXT WGLEW_GET_FUN(__wglewGetPixelFormatAttribivEXT) 705 | 706 | #define WGLEW_EXT_pixel_format WGLEW_GET_VAR(__WGLEW_EXT_pixel_format) 707 | 708 | #endif /* WGL_EXT_pixel_format */ 709 | 710 | /* ------------------- WGL_EXT_pixel_format_packed_float ------------------- */ 711 | 712 | #ifndef WGL_EXT_pixel_format_packed_float 713 | #define WGL_EXT_pixel_format_packed_float 1 714 | 715 | #define WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT 0x20A8 716 | 717 | #define WGLEW_EXT_pixel_format_packed_float WGLEW_GET_VAR(__WGLEW_EXT_pixel_format_packed_float) 718 | 719 | #endif /* WGL_EXT_pixel_format_packed_float */ 720 | 721 | /* -------------------------- WGL_EXT_swap_control ------------------------- */ 722 | 723 | #ifndef WGL_EXT_swap_control 724 | #define WGL_EXT_swap_control 1 725 | 726 | typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void); 727 | typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval); 728 | 729 | #define wglGetSwapIntervalEXT WGLEW_GET_FUN(__wglewGetSwapIntervalEXT) 730 | #define wglSwapIntervalEXT WGLEW_GET_FUN(__wglewSwapIntervalEXT) 731 | 732 | #define WGLEW_EXT_swap_control WGLEW_GET_VAR(__WGLEW_EXT_swap_control) 733 | 734 | #endif /* WGL_EXT_swap_control */ 735 | 736 | /* ----------------------- WGL_EXT_swap_control_tear ----------------------- */ 737 | 738 | #ifndef WGL_EXT_swap_control_tear 739 | #define WGL_EXT_swap_control_tear 1 740 | 741 | #define WGLEW_EXT_swap_control_tear WGLEW_GET_VAR(__WGLEW_EXT_swap_control_tear) 742 | 743 | #endif /* WGL_EXT_swap_control_tear */ 744 | 745 | /* --------------------- WGL_I3D_digital_video_control --------------------- */ 746 | 747 | #ifndef WGL_I3D_digital_video_control 748 | #define WGL_I3D_digital_video_control 1 749 | 750 | #define WGL_DIGITAL_VIDEO_CURSOR_ALPHA_FRAMEBUFFER_I3D 0x2050 751 | #define WGL_DIGITAL_VIDEO_CURSOR_ALPHA_VALUE_I3D 0x2051 752 | #define WGL_DIGITAL_VIDEO_CURSOR_INCLUDED_I3D 0x2052 753 | #define WGL_DIGITAL_VIDEO_GAMMA_CORRECTED_I3D 0x2053 754 | 755 | typedef BOOL (WINAPI * PFNWGLGETDIGITALVIDEOPARAMETERSI3DPROC) (HDC hDC, int iAttribute, int* piValue); 756 | typedef BOOL (WINAPI * PFNWGLSETDIGITALVIDEOPARAMETERSI3DPROC) (HDC hDC, int iAttribute, const int* piValue); 757 | 758 | #define wglGetDigitalVideoParametersI3D WGLEW_GET_FUN(__wglewGetDigitalVideoParametersI3D) 759 | #define wglSetDigitalVideoParametersI3D WGLEW_GET_FUN(__wglewSetDigitalVideoParametersI3D) 760 | 761 | #define WGLEW_I3D_digital_video_control WGLEW_GET_VAR(__WGLEW_I3D_digital_video_control) 762 | 763 | #endif /* WGL_I3D_digital_video_control */ 764 | 765 | /* ----------------------------- WGL_I3D_gamma ----------------------------- */ 766 | 767 | #ifndef WGL_I3D_gamma 768 | #define WGL_I3D_gamma 1 769 | 770 | #define WGL_GAMMA_TABLE_SIZE_I3D 0x204E 771 | #define WGL_GAMMA_EXCLUDE_DESKTOP_I3D 0x204F 772 | 773 | typedef BOOL (WINAPI * PFNWGLGETGAMMATABLEI3DPROC) (HDC hDC, int iEntries, USHORT* puRed, USHORT *puGreen, USHORT *puBlue); 774 | typedef BOOL (WINAPI * PFNWGLGETGAMMATABLEPARAMETERSI3DPROC) (HDC hDC, int iAttribute, int* piValue); 775 | typedef BOOL (WINAPI * PFNWGLSETGAMMATABLEI3DPROC) (HDC hDC, int iEntries, const USHORT* puRed, const USHORT *puGreen, const USHORT *puBlue); 776 | typedef BOOL (WINAPI * PFNWGLSETGAMMATABLEPARAMETERSI3DPROC) (HDC hDC, int iAttribute, const int* piValue); 777 | 778 | #define wglGetGammaTableI3D WGLEW_GET_FUN(__wglewGetGammaTableI3D) 779 | #define wglGetGammaTableParametersI3D WGLEW_GET_FUN(__wglewGetGammaTableParametersI3D) 780 | #define wglSetGammaTableI3D WGLEW_GET_FUN(__wglewSetGammaTableI3D) 781 | #define wglSetGammaTableParametersI3D WGLEW_GET_FUN(__wglewSetGammaTableParametersI3D) 782 | 783 | #define WGLEW_I3D_gamma WGLEW_GET_VAR(__WGLEW_I3D_gamma) 784 | 785 | #endif /* WGL_I3D_gamma */ 786 | 787 | /* ---------------------------- WGL_I3D_genlock ---------------------------- */ 788 | 789 | #ifndef WGL_I3D_genlock 790 | #define WGL_I3D_genlock 1 791 | 792 | #define WGL_GENLOCK_SOURCE_MULTIVIEW_I3D 0x2044 793 | #define WGL_GENLOCK_SOURCE_EXTERNAL_SYNC_I3D 0x2045 794 | #define WGL_GENLOCK_SOURCE_EXTERNAL_FIELD_I3D 0x2046 795 | #define WGL_GENLOCK_SOURCE_EXTERNAL_TTL_I3D 0x2047 796 | #define WGL_GENLOCK_SOURCE_DIGITAL_SYNC_I3D 0x2048 797 | #define WGL_GENLOCK_SOURCE_DIGITAL_FIELD_I3D 0x2049 798 | #define WGL_GENLOCK_SOURCE_EDGE_FALLING_I3D 0x204A 799 | #define WGL_GENLOCK_SOURCE_EDGE_RISING_I3D 0x204B 800 | #define WGL_GENLOCK_SOURCE_EDGE_BOTH_I3D 0x204C 801 | 802 | typedef BOOL (WINAPI * PFNWGLDISABLEGENLOCKI3DPROC) (HDC hDC); 803 | typedef BOOL (WINAPI * PFNWGLENABLEGENLOCKI3DPROC) (HDC hDC); 804 | typedef BOOL (WINAPI * PFNWGLGENLOCKSAMPLERATEI3DPROC) (HDC hDC, UINT uRate); 805 | typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEDELAYI3DPROC) (HDC hDC, UINT uDelay); 806 | typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEEDGEI3DPROC) (HDC hDC, UINT uEdge); 807 | typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEI3DPROC) (HDC hDC, UINT uSource); 808 | typedef BOOL (WINAPI * PFNWGLGETGENLOCKSAMPLERATEI3DPROC) (HDC hDC, UINT* uRate); 809 | typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEDELAYI3DPROC) (HDC hDC, UINT* uDelay); 810 | typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEEDGEI3DPROC) (HDC hDC, UINT* uEdge); 811 | typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEI3DPROC) (HDC hDC, UINT* uSource); 812 | typedef BOOL (WINAPI * PFNWGLISENABLEDGENLOCKI3DPROC) (HDC hDC, BOOL* pFlag); 813 | typedef BOOL (WINAPI * PFNWGLQUERYGENLOCKMAXSOURCEDELAYI3DPROC) (HDC hDC, UINT* uMaxLineDelay, UINT *uMaxPixelDelay); 814 | 815 | #define wglDisableGenlockI3D WGLEW_GET_FUN(__wglewDisableGenlockI3D) 816 | #define wglEnableGenlockI3D WGLEW_GET_FUN(__wglewEnableGenlockI3D) 817 | #define wglGenlockSampleRateI3D WGLEW_GET_FUN(__wglewGenlockSampleRateI3D) 818 | #define wglGenlockSourceDelayI3D WGLEW_GET_FUN(__wglewGenlockSourceDelayI3D) 819 | #define wglGenlockSourceEdgeI3D WGLEW_GET_FUN(__wglewGenlockSourceEdgeI3D) 820 | #define wglGenlockSourceI3D WGLEW_GET_FUN(__wglewGenlockSourceI3D) 821 | #define wglGetGenlockSampleRateI3D WGLEW_GET_FUN(__wglewGetGenlockSampleRateI3D) 822 | #define wglGetGenlockSourceDelayI3D WGLEW_GET_FUN(__wglewGetGenlockSourceDelayI3D) 823 | #define wglGetGenlockSourceEdgeI3D WGLEW_GET_FUN(__wglewGetGenlockSourceEdgeI3D) 824 | #define wglGetGenlockSourceI3D WGLEW_GET_FUN(__wglewGetGenlockSourceI3D) 825 | #define wglIsEnabledGenlockI3D WGLEW_GET_FUN(__wglewIsEnabledGenlockI3D) 826 | #define wglQueryGenlockMaxSourceDelayI3D WGLEW_GET_FUN(__wglewQueryGenlockMaxSourceDelayI3D) 827 | 828 | #define WGLEW_I3D_genlock WGLEW_GET_VAR(__WGLEW_I3D_genlock) 829 | 830 | #endif /* WGL_I3D_genlock */ 831 | 832 | /* -------------------------- WGL_I3D_image_buffer ------------------------- */ 833 | 834 | #ifndef WGL_I3D_image_buffer 835 | #define WGL_I3D_image_buffer 1 836 | 837 | #define WGL_IMAGE_BUFFER_MIN_ACCESS_I3D 0x00000001 838 | #define WGL_IMAGE_BUFFER_LOCK_I3D 0x00000002 839 | 840 | typedef BOOL (WINAPI * PFNWGLASSOCIATEIMAGEBUFFEREVENTSI3DPROC) (HDC hdc, HANDLE* pEvent, LPVOID *pAddress, DWORD *pSize, UINT count); 841 | typedef LPVOID (WINAPI * PFNWGLCREATEIMAGEBUFFERI3DPROC) (HDC hDC, DWORD dwSize, UINT uFlags); 842 | typedef BOOL (WINAPI * PFNWGLDESTROYIMAGEBUFFERI3DPROC) (HDC hDC, LPVOID pAddress); 843 | typedef BOOL (WINAPI * PFNWGLRELEASEIMAGEBUFFEREVENTSI3DPROC) (HDC hdc, LPVOID* pAddress, UINT count); 844 | 845 | #define wglAssociateImageBufferEventsI3D WGLEW_GET_FUN(__wglewAssociateImageBufferEventsI3D) 846 | #define wglCreateImageBufferI3D WGLEW_GET_FUN(__wglewCreateImageBufferI3D) 847 | #define wglDestroyImageBufferI3D WGLEW_GET_FUN(__wglewDestroyImageBufferI3D) 848 | #define wglReleaseImageBufferEventsI3D WGLEW_GET_FUN(__wglewReleaseImageBufferEventsI3D) 849 | 850 | #define WGLEW_I3D_image_buffer WGLEW_GET_VAR(__WGLEW_I3D_image_buffer) 851 | 852 | #endif /* WGL_I3D_image_buffer */ 853 | 854 | /* ------------------------ WGL_I3D_swap_frame_lock ------------------------ */ 855 | 856 | #ifndef WGL_I3D_swap_frame_lock 857 | #define WGL_I3D_swap_frame_lock 1 858 | 859 | typedef BOOL (WINAPI * PFNWGLDISABLEFRAMELOCKI3DPROC) (VOID); 860 | typedef BOOL (WINAPI * PFNWGLENABLEFRAMELOCKI3DPROC) (VOID); 861 | typedef BOOL (WINAPI * PFNWGLISENABLEDFRAMELOCKI3DPROC) (BOOL* pFlag); 862 | typedef BOOL (WINAPI * PFNWGLQUERYFRAMELOCKMASTERI3DPROC) (BOOL* pFlag); 863 | 864 | #define wglDisableFrameLockI3D WGLEW_GET_FUN(__wglewDisableFrameLockI3D) 865 | #define wglEnableFrameLockI3D WGLEW_GET_FUN(__wglewEnableFrameLockI3D) 866 | #define wglIsEnabledFrameLockI3D WGLEW_GET_FUN(__wglewIsEnabledFrameLockI3D) 867 | #define wglQueryFrameLockMasterI3D WGLEW_GET_FUN(__wglewQueryFrameLockMasterI3D) 868 | 869 | #define WGLEW_I3D_swap_frame_lock WGLEW_GET_VAR(__WGLEW_I3D_swap_frame_lock) 870 | 871 | #endif /* WGL_I3D_swap_frame_lock */ 872 | 873 | /* ------------------------ WGL_I3D_swap_frame_usage ----------------------- */ 874 | 875 | #ifndef WGL_I3D_swap_frame_usage 876 | #define WGL_I3D_swap_frame_usage 1 877 | 878 | typedef BOOL (WINAPI * PFNWGLBEGINFRAMETRACKINGI3DPROC) (void); 879 | typedef BOOL (WINAPI * PFNWGLENDFRAMETRACKINGI3DPROC) (void); 880 | typedef BOOL (WINAPI * PFNWGLGETFRAMEUSAGEI3DPROC) (float* pUsage); 881 | typedef BOOL (WINAPI * PFNWGLQUERYFRAMETRACKINGI3DPROC) (DWORD* pFrameCount, DWORD *pMissedFrames, float *pLastMissedUsage); 882 | 883 | #define wglBeginFrameTrackingI3D WGLEW_GET_FUN(__wglewBeginFrameTrackingI3D) 884 | #define wglEndFrameTrackingI3D WGLEW_GET_FUN(__wglewEndFrameTrackingI3D) 885 | #define wglGetFrameUsageI3D WGLEW_GET_FUN(__wglewGetFrameUsageI3D) 886 | #define wglQueryFrameTrackingI3D WGLEW_GET_FUN(__wglewQueryFrameTrackingI3D) 887 | 888 | #define WGLEW_I3D_swap_frame_usage WGLEW_GET_VAR(__WGLEW_I3D_swap_frame_usage) 889 | 890 | #endif /* WGL_I3D_swap_frame_usage */ 891 | 892 | /* --------------------------- WGL_NV_DX_interop --------------------------- */ 893 | 894 | #ifndef WGL_NV_DX_interop 895 | #define WGL_NV_DX_interop 1 896 | 897 | #define WGL_ACCESS_READ_ONLY_NV 0x0000 898 | #define WGL_ACCESS_READ_WRITE_NV 0x0001 899 | #define WGL_ACCESS_WRITE_DISCARD_NV 0x0002 900 | 901 | typedef BOOL (WINAPI * PFNWGLDXCLOSEDEVICENVPROC) (HANDLE hDevice); 902 | typedef BOOL (WINAPI * PFNWGLDXLOCKOBJECTSNVPROC) (HANDLE hDevice, GLint count, HANDLE* hObjects); 903 | typedef BOOL (WINAPI * PFNWGLDXOBJECTACCESSNVPROC) (HANDLE hObject, GLenum access); 904 | typedef HANDLE (WINAPI * PFNWGLDXOPENDEVICENVPROC) (void* dxDevice); 905 | typedef HANDLE (WINAPI * PFNWGLDXREGISTEROBJECTNVPROC) (HANDLE hDevice, void* dxObject, GLuint name, GLenum type, GLenum access); 906 | typedef BOOL (WINAPI * PFNWGLDXSETRESOURCESHAREHANDLENVPROC) (void* dxObject, HANDLE shareHandle); 907 | typedef BOOL (WINAPI * PFNWGLDXUNLOCKOBJECTSNVPROC) (HANDLE hDevice, GLint count, HANDLE* hObjects); 908 | typedef BOOL (WINAPI * PFNWGLDXUNREGISTEROBJECTNVPROC) (HANDLE hDevice, HANDLE hObject); 909 | 910 | #define wglDXCloseDeviceNV WGLEW_GET_FUN(__wglewDXCloseDeviceNV) 911 | #define wglDXLockObjectsNV WGLEW_GET_FUN(__wglewDXLockObjectsNV) 912 | #define wglDXObjectAccessNV WGLEW_GET_FUN(__wglewDXObjectAccessNV) 913 | #define wglDXOpenDeviceNV WGLEW_GET_FUN(__wglewDXOpenDeviceNV) 914 | #define wglDXRegisterObjectNV WGLEW_GET_FUN(__wglewDXRegisterObjectNV) 915 | #define wglDXSetResourceShareHandleNV WGLEW_GET_FUN(__wglewDXSetResourceShareHandleNV) 916 | #define wglDXUnlockObjectsNV WGLEW_GET_FUN(__wglewDXUnlockObjectsNV) 917 | #define wglDXUnregisterObjectNV WGLEW_GET_FUN(__wglewDXUnregisterObjectNV) 918 | 919 | #define WGLEW_NV_DX_interop WGLEW_GET_VAR(__WGLEW_NV_DX_interop) 920 | 921 | #endif /* WGL_NV_DX_interop */ 922 | 923 | /* --------------------------- WGL_NV_DX_interop2 -------------------------- */ 924 | 925 | #ifndef WGL_NV_DX_interop2 926 | #define WGL_NV_DX_interop2 1 927 | 928 | #define WGLEW_NV_DX_interop2 WGLEW_GET_VAR(__WGLEW_NV_DX_interop2) 929 | 930 | #endif /* WGL_NV_DX_interop2 */ 931 | 932 | /* --------------------------- WGL_NV_copy_image --------------------------- */ 933 | 934 | #ifndef WGL_NV_copy_image 935 | #define WGL_NV_copy_image 1 936 | 937 | typedef BOOL (WINAPI * PFNWGLCOPYIMAGESUBDATANVPROC) (HGLRC hSrcRC, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, HGLRC hDstRC, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth); 938 | 939 | #define wglCopyImageSubDataNV WGLEW_GET_FUN(__wglewCopyImageSubDataNV) 940 | 941 | #define WGLEW_NV_copy_image WGLEW_GET_VAR(__WGLEW_NV_copy_image) 942 | 943 | #endif /* WGL_NV_copy_image */ 944 | 945 | /* ------------------------ WGL_NV_delay_before_swap ----------------------- */ 946 | 947 | #ifndef WGL_NV_delay_before_swap 948 | #define WGL_NV_delay_before_swap 1 949 | 950 | typedef BOOL (WINAPI * PFNWGLDELAYBEFORESWAPNVPROC) (HDC hDC, GLfloat seconds); 951 | 952 | #define wglDelayBeforeSwapNV WGLEW_GET_FUN(__wglewDelayBeforeSwapNV) 953 | 954 | #define WGLEW_NV_delay_before_swap WGLEW_GET_VAR(__WGLEW_NV_delay_before_swap) 955 | 956 | #endif /* WGL_NV_delay_before_swap */ 957 | 958 | /* -------------------------- WGL_NV_float_buffer -------------------------- */ 959 | 960 | #ifndef WGL_NV_float_buffer 961 | #define WGL_NV_float_buffer 1 962 | 963 | #define WGL_FLOAT_COMPONENTS_NV 0x20B0 964 | #define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV 0x20B1 965 | #define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV 0x20B2 966 | #define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV 0x20B3 967 | #define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV 0x20B4 968 | #define WGL_TEXTURE_FLOAT_R_NV 0x20B5 969 | #define WGL_TEXTURE_FLOAT_RG_NV 0x20B6 970 | #define WGL_TEXTURE_FLOAT_RGB_NV 0x20B7 971 | #define WGL_TEXTURE_FLOAT_RGBA_NV 0x20B8 972 | 973 | #define WGLEW_NV_float_buffer WGLEW_GET_VAR(__WGLEW_NV_float_buffer) 974 | 975 | #endif /* WGL_NV_float_buffer */ 976 | 977 | /* -------------------------- WGL_NV_gpu_affinity -------------------------- */ 978 | 979 | #ifndef WGL_NV_gpu_affinity 980 | #define WGL_NV_gpu_affinity 1 981 | 982 | #define WGL_ERROR_INCOMPATIBLE_AFFINITY_MASKS_NV 0x20D0 983 | #define WGL_ERROR_MISSING_AFFINITY_MASK_NV 0x20D1 984 | 985 | DECLARE_HANDLE(HGPUNV); 986 | typedef struct _GPU_DEVICE { 987 | DWORD cb; 988 | CHAR DeviceName[32]; 989 | CHAR DeviceString[128]; 990 | DWORD Flags; 991 | RECT rcVirtualScreen; 992 | } GPU_DEVICE, *PGPU_DEVICE; 993 | 994 | typedef HDC (WINAPI * PFNWGLCREATEAFFINITYDCNVPROC) (const HGPUNV *phGpuList); 995 | typedef BOOL (WINAPI * PFNWGLDELETEDCNVPROC) (HDC hdc); 996 | typedef BOOL (WINAPI * PFNWGLENUMGPUDEVICESNVPROC) (HGPUNV hGpu, UINT iDeviceIndex, PGPU_DEVICE lpGpuDevice); 997 | typedef BOOL (WINAPI * PFNWGLENUMGPUSFROMAFFINITYDCNVPROC) (HDC hAffinityDC, UINT iGpuIndex, HGPUNV *hGpu); 998 | typedef BOOL (WINAPI * PFNWGLENUMGPUSNVPROC) (UINT iGpuIndex, HGPUNV *phGpu); 999 | 1000 | #define wglCreateAffinityDCNV WGLEW_GET_FUN(__wglewCreateAffinityDCNV) 1001 | #define wglDeleteDCNV WGLEW_GET_FUN(__wglewDeleteDCNV) 1002 | #define wglEnumGpuDevicesNV WGLEW_GET_FUN(__wglewEnumGpuDevicesNV) 1003 | #define wglEnumGpusFromAffinityDCNV WGLEW_GET_FUN(__wglewEnumGpusFromAffinityDCNV) 1004 | #define wglEnumGpusNV WGLEW_GET_FUN(__wglewEnumGpusNV) 1005 | 1006 | #define WGLEW_NV_gpu_affinity WGLEW_GET_VAR(__WGLEW_NV_gpu_affinity) 1007 | 1008 | #endif /* WGL_NV_gpu_affinity */ 1009 | 1010 | /* ---------------------- WGL_NV_multisample_coverage ---------------------- */ 1011 | 1012 | #ifndef WGL_NV_multisample_coverage 1013 | #define WGL_NV_multisample_coverage 1 1014 | 1015 | #define WGL_COVERAGE_SAMPLES_NV 0x2042 1016 | #define WGL_COLOR_SAMPLES_NV 0x20B9 1017 | 1018 | #define WGLEW_NV_multisample_coverage WGLEW_GET_VAR(__WGLEW_NV_multisample_coverage) 1019 | 1020 | #endif /* WGL_NV_multisample_coverage */ 1021 | 1022 | /* -------------------------- WGL_NV_present_video ------------------------- */ 1023 | 1024 | #ifndef WGL_NV_present_video 1025 | #define WGL_NV_present_video 1 1026 | 1027 | #define WGL_NUM_VIDEO_SLOTS_NV 0x20F0 1028 | 1029 | DECLARE_HANDLE(HVIDEOOUTPUTDEVICENV); 1030 | 1031 | typedef BOOL (WINAPI * PFNWGLBINDVIDEODEVICENVPROC) (HDC hDc, unsigned int uVideoSlot, HVIDEOOUTPUTDEVICENV hVideoDevice, const int* piAttribList); 1032 | typedef int (WINAPI * PFNWGLENUMERATEVIDEODEVICESNVPROC) (HDC hDc, HVIDEOOUTPUTDEVICENV* phDeviceList); 1033 | typedef BOOL (WINAPI * PFNWGLQUERYCURRENTCONTEXTNVPROC) (int iAttribute, int* piValue); 1034 | 1035 | #define wglBindVideoDeviceNV WGLEW_GET_FUN(__wglewBindVideoDeviceNV) 1036 | #define wglEnumerateVideoDevicesNV WGLEW_GET_FUN(__wglewEnumerateVideoDevicesNV) 1037 | #define wglQueryCurrentContextNV WGLEW_GET_FUN(__wglewQueryCurrentContextNV) 1038 | 1039 | #define WGLEW_NV_present_video WGLEW_GET_VAR(__WGLEW_NV_present_video) 1040 | 1041 | #endif /* WGL_NV_present_video */ 1042 | 1043 | /* ---------------------- WGL_NV_render_depth_texture ---------------------- */ 1044 | 1045 | #ifndef WGL_NV_render_depth_texture 1046 | #define WGL_NV_render_depth_texture 1 1047 | 1048 | #define WGL_NO_TEXTURE_ARB 0x2077 1049 | #define WGL_BIND_TO_TEXTURE_DEPTH_NV 0x20A3 1050 | #define WGL_BIND_TO_TEXTURE_RECTANGLE_DEPTH_NV 0x20A4 1051 | #define WGL_DEPTH_TEXTURE_FORMAT_NV 0x20A5 1052 | #define WGL_TEXTURE_DEPTH_COMPONENT_NV 0x20A6 1053 | #define WGL_DEPTH_COMPONENT_NV 0x20A7 1054 | 1055 | #define WGLEW_NV_render_depth_texture WGLEW_GET_VAR(__WGLEW_NV_render_depth_texture) 1056 | 1057 | #endif /* WGL_NV_render_depth_texture */ 1058 | 1059 | /* -------------------- WGL_NV_render_texture_rectangle -------------------- */ 1060 | 1061 | #ifndef WGL_NV_render_texture_rectangle 1062 | #define WGL_NV_render_texture_rectangle 1 1063 | 1064 | #define WGL_BIND_TO_TEXTURE_RECTANGLE_RGB_NV 0x20A0 1065 | #define WGL_BIND_TO_TEXTURE_RECTANGLE_RGBA_NV 0x20A1 1066 | #define WGL_TEXTURE_RECTANGLE_NV 0x20A2 1067 | 1068 | #define WGLEW_NV_render_texture_rectangle WGLEW_GET_VAR(__WGLEW_NV_render_texture_rectangle) 1069 | 1070 | #endif /* WGL_NV_render_texture_rectangle */ 1071 | 1072 | /* --------------------------- WGL_NV_swap_group --------------------------- */ 1073 | 1074 | #ifndef WGL_NV_swap_group 1075 | #define WGL_NV_swap_group 1 1076 | 1077 | typedef BOOL (WINAPI * PFNWGLBINDSWAPBARRIERNVPROC) (GLuint group, GLuint barrier); 1078 | typedef BOOL (WINAPI * PFNWGLJOINSWAPGROUPNVPROC) (HDC hDC, GLuint group); 1079 | typedef BOOL (WINAPI * PFNWGLQUERYFRAMECOUNTNVPROC) (HDC hDC, GLuint* count); 1080 | typedef BOOL (WINAPI * PFNWGLQUERYMAXSWAPGROUPSNVPROC) (HDC hDC, GLuint* maxGroups, GLuint *maxBarriers); 1081 | typedef BOOL (WINAPI * PFNWGLQUERYSWAPGROUPNVPROC) (HDC hDC, GLuint* group, GLuint *barrier); 1082 | typedef BOOL (WINAPI * PFNWGLRESETFRAMECOUNTNVPROC) (HDC hDC); 1083 | 1084 | #define wglBindSwapBarrierNV WGLEW_GET_FUN(__wglewBindSwapBarrierNV) 1085 | #define wglJoinSwapGroupNV WGLEW_GET_FUN(__wglewJoinSwapGroupNV) 1086 | #define wglQueryFrameCountNV WGLEW_GET_FUN(__wglewQueryFrameCountNV) 1087 | #define wglQueryMaxSwapGroupsNV WGLEW_GET_FUN(__wglewQueryMaxSwapGroupsNV) 1088 | #define wglQuerySwapGroupNV WGLEW_GET_FUN(__wglewQuerySwapGroupNV) 1089 | #define wglResetFrameCountNV WGLEW_GET_FUN(__wglewResetFrameCountNV) 1090 | 1091 | #define WGLEW_NV_swap_group WGLEW_GET_VAR(__WGLEW_NV_swap_group) 1092 | 1093 | #endif /* WGL_NV_swap_group */ 1094 | 1095 | /* ----------------------- WGL_NV_vertex_array_range ----------------------- */ 1096 | 1097 | #ifndef WGL_NV_vertex_array_range 1098 | #define WGL_NV_vertex_array_range 1 1099 | 1100 | typedef void * (WINAPI * PFNWGLALLOCATEMEMORYNVPROC) (GLsizei size, GLfloat readFrequency, GLfloat writeFrequency, GLfloat priority); 1101 | typedef void (WINAPI * PFNWGLFREEMEMORYNVPROC) (void *pointer); 1102 | 1103 | #define wglAllocateMemoryNV WGLEW_GET_FUN(__wglewAllocateMemoryNV) 1104 | #define wglFreeMemoryNV WGLEW_GET_FUN(__wglewFreeMemoryNV) 1105 | 1106 | #define WGLEW_NV_vertex_array_range WGLEW_GET_VAR(__WGLEW_NV_vertex_array_range) 1107 | 1108 | #endif /* WGL_NV_vertex_array_range */ 1109 | 1110 | /* -------------------------- WGL_NV_video_capture ------------------------- */ 1111 | 1112 | #ifndef WGL_NV_video_capture 1113 | #define WGL_NV_video_capture 1 1114 | 1115 | #define WGL_UNIQUE_ID_NV 0x20CE 1116 | #define WGL_NUM_VIDEO_CAPTURE_SLOTS_NV 0x20CF 1117 | 1118 | DECLARE_HANDLE(HVIDEOINPUTDEVICENV); 1119 | 1120 | typedef BOOL (WINAPI * PFNWGLBINDVIDEOCAPTUREDEVICENVPROC) (UINT uVideoSlot, HVIDEOINPUTDEVICENV hDevice); 1121 | typedef UINT (WINAPI * PFNWGLENUMERATEVIDEOCAPTUREDEVICESNVPROC) (HDC hDc, HVIDEOINPUTDEVICENV* phDeviceList); 1122 | typedef BOOL (WINAPI * PFNWGLLOCKVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice); 1123 | typedef BOOL (WINAPI * PFNWGLQUERYVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice, int iAttribute, int* piValue); 1124 | typedef BOOL (WINAPI * PFNWGLRELEASEVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice); 1125 | 1126 | #define wglBindVideoCaptureDeviceNV WGLEW_GET_FUN(__wglewBindVideoCaptureDeviceNV) 1127 | #define wglEnumerateVideoCaptureDevicesNV WGLEW_GET_FUN(__wglewEnumerateVideoCaptureDevicesNV) 1128 | #define wglLockVideoCaptureDeviceNV WGLEW_GET_FUN(__wglewLockVideoCaptureDeviceNV) 1129 | #define wglQueryVideoCaptureDeviceNV WGLEW_GET_FUN(__wglewQueryVideoCaptureDeviceNV) 1130 | #define wglReleaseVideoCaptureDeviceNV WGLEW_GET_FUN(__wglewReleaseVideoCaptureDeviceNV) 1131 | 1132 | #define WGLEW_NV_video_capture WGLEW_GET_VAR(__WGLEW_NV_video_capture) 1133 | 1134 | #endif /* WGL_NV_video_capture */ 1135 | 1136 | /* -------------------------- WGL_NV_video_output -------------------------- */ 1137 | 1138 | #ifndef WGL_NV_video_output 1139 | #define WGL_NV_video_output 1 1140 | 1141 | #define WGL_BIND_TO_VIDEO_RGB_NV 0x20C0 1142 | #define WGL_BIND_TO_VIDEO_RGBA_NV 0x20C1 1143 | #define WGL_BIND_TO_VIDEO_RGB_AND_DEPTH_NV 0x20C2 1144 | #define WGL_VIDEO_OUT_COLOR_NV 0x20C3 1145 | #define WGL_VIDEO_OUT_ALPHA_NV 0x20C4 1146 | #define WGL_VIDEO_OUT_DEPTH_NV 0x20C5 1147 | #define WGL_VIDEO_OUT_COLOR_AND_ALPHA_NV 0x20C6 1148 | #define WGL_VIDEO_OUT_COLOR_AND_DEPTH_NV 0x20C7 1149 | #define WGL_VIDEO_OUT_FRAME 0x20C8 1150 | #define WGL_VIDEO_OUT_FIELD_1 0x20C9 1151 | #define WGL_VIDEO_OUT_FIELD_2 0x20CA 1152 | #define WGL_VIDEO_OUT_STACKED_FIELDS_1_2 0x20CB 1153 | #define WGL_VIDEO_OUT_STACKED_FIELDS_2_1 0x20CC 1154 | 1155 | DECLARE_HANDLE(HPVIDEODEV); 1156 | 1157 | typedef BOOL (WINAPI * PFNWGLBINDVIDEOIMAGENVPROC) (HPVIDEODEV hVideoDevice, HPBUFFERARB hPbuffer, int iVideoBuffer); 1158 | typedef BOOL (WINAPI * PFNWGLGETVIDEODEVICENVPROC) (HDC hDC, int numDevices, HPVIDEODEV* hVideoDevice); 1159 | typedef BOOL (WINAPI * PFNWGLGETVIDEOINFONVPROC) (HPVIDEODEV hpVideoDevice, unsigned long* pulCounterOutputPbuffer, unsigned long *pulCounterOutputVideo); 1160 | typedef BOOL (WINAPI * PFNWGLRELEASEVIDEODEVICENVPROC) (HPVIDEODEV hVideoDevice); 1161 | typedef BOOL (WINAPI * PFNWGLRELEASEVIDEOIMAGENVPROC) (HPBUFFERARB hPbuffer, int iVideoBuffer); 1162 | typedef BOOL (WINAPI * PFNWGLSENDPBUFFERTOVIDEONVPROC) (HPBUFFERARB hPbuffer, int iBufferType, unsigned long* pulCounterPbuffer, BOOL bBlock); 1163 | 1164 | #define wglBindVideoImageNV WGLEW_GET_FUN(__wglewBindVideoImageNV) 1165 | #define wglGetVideoDeviceNV WGLEW_GET_FUN(__wglewGetVideoDeviceNV) 1166 | #define wglGetVideoInfoNV WGLEW_GET_FUN(__wglewGetVideoInfoNV) 1167 | #define wglReleaseVideoDeviceNV WGLEW_GET_FUN(__wglewReleaseVideoDeviceNV) 1168 | #define wglReleaseVideoImageNV WGLEW_GET_FUN(__wglewReleaseVideoImageNV) 1169 | #define wglSendPbufferToVideoNV WGLEW_GET_FUN(__wglewSendPbufferToVideoNV) 1170 | 1171 | #define WGLEW_NV_video_output WGLEW_GET_VAR(__WGLEW_NV_video_output) 1172 | 1173 | #endif /* WGL_NV_video_output */ 1174 | 1175 | /* -------------------------- WGL_OML_sync_control ------------------------- */ 1176 | 1177 | #ifndef WGL_OML_sync_control 1178 | #define WGL_OML_sync_control 1 1179 | 1180 | typedef BOOL (WINAPI * PFNWGLGETMSCRATEOMLPROC) (HDC hdc, INT32* numerator, INT32 *denominator); 1181 | typedef BOOL (WINAPI * PFNWGLGETSYNCVALUESOMLPROC) (HDC hdc, INT64* ust, INT64 *msc, INT64 *sbc); 1182 | typedef INT64 (WINAPI * PFNWGLSWAPBUFFERSMSCOMLPROC) (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder); 1183 | typedef INT64 (WINAPI * PFNWGLSWAPLAYERBUFFERSMSCOMLPROC) (HDC hdc, INT fuPlanes, INT64 target_msc, INT64 divisor, INT64 remainder); 1184 | typedef BOOL (WINAPI * PFNWGLWAITFORMSCOMLPROC) (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder, INT64* ust, INT64 *msc, INT64 *sbc); 1185 | typedef BOOL (WINAPI * PFNWGLWAITFORSBCOMLPROC) (HDC hdc, INT64 target_sbc, INT64* ust, INT64 *msc, INT64 *sbc); 1186 | 1187 | #define wglGetMscRateOML WGLEW_GET_FUN(__wglewGetMscRateOML) 1188 | #define wglGetSyncValuesOML WGLEW_GET_FUN(__wglewGetSyncValuesOML) 1189 | #define wglSwapBuffersMscOML WGLEW_GET_FUN(__wglewSwapBuffersMscOML) 1190 | #define wglSwapLayerBuffersMscOML WGLEW_GET_FUN(__wglewSwapLayerBuffersMscOML) 1191 | #define wglWaitForMscOML WGLEW_GET_FUN(__wglewWaitForMscOML) 1192 | #define wglWaitForSbcOML WGLEW_GET_FUN(__wglewWaitForSbcOML) 1193 | 1194 | #define WGLEW_OML_sync_control WGLEW_GET_VAR(__WGLEW_OML_sync_control) 1195 | 1196 | #endif /* WGL_OML_sync_control */ 1197 | 1198 | /* ------------------------------------------------------------------------- */ 1199 | 1200 | #ifdef GLEW_MX 1201 | #define WGLEW_FUN_EXPORT 1202 | #define WGLEW_VAR_EXPORT 1203 | #else 1204 | #define WGLEW_FUN_EXPORT GLEW_FUN_EXPORT 1205 | #define WGLEW_VAR_EXPORT GLEW_VAR_EXPORT 1206 | #endif /* GLEW_MX */ 1207 | 1208 | #ifdef GLEW_MX 1209 | struct WGLEWContextStruct 1210 | { 1211 | #endif /* GLEW_MX */ 1212 | 1213 | WGLEW_FUN_EXPORT PFNWGLSETSTEREOEMITTERSTATE3DLPROC __wglewSetStereoEmitterState3DL; 1214 | 1215 | WGLEW_FUN_EXPORT PFNWGLBLITCONTEXTFRAMEBUFFERAMDPROC __wglewBlitContextFramebufferAMD; 1216 | WGLEW_FUN_EXPORT PFNWGLCREATEASSOCIATEDCONTEXTAMDPROC __wglewCreateAssociatedContextAMD; 1217 | WGLEW_FUN_EXPORT PFNWGLCREATEASSOCIATEDCONTEXTATTRIBSAMDPROC __wglewCreateAssociatedContextAttribsAMD; 1218 | WGLEW_FUN_EXPORT PFNWGLDELETEASSOCIATEDCONTEXTAMDPROC __wglewDeleteAssociatedContextAMD; 1219 | WGLEW_FUN_EXPORT PFNWGLGETCONTEXTGPUIDAMDPROC __wglewGetContextGPUIDAMD; 1220 | WGLEW_FUN_EXPORT PFNWGLGETCURRENTASSOCIATEDCONTEXTAMDPROC __wglewGetCurrentAssociatedContextAMD; 1221 | WGLEW_FUN_EXPORT PFNWGLGETGPUIDSAMDPROC __wglewGetGPUIDsAMD; 1222 | WGLEW_FUN_EXPORT PFNWGLGETGPUINFOAMDPROC __wglewGetGPUInfoAMD; 1223 | WGLEW_FUN_EXPORT PFNWGLMAKEASSOCIATEDCONTEXTCURRENTAMDPROC __wglewMakeAssociatedContextCurrentAMD; 1224 | 1225 | WGLEW_FUN_EXPORT PFNWGLCREATEBUFFERREGIONARBPROC __wglewCreateBufferRegionARB; 1226 | WGLEW_FUN_EXPORT PFNWGLDELETEBUFFERREGIONARBPROC __wglewDeleteBufferRegionARB; 1227 | WGLEW_FUN_EXPORT PFNWGLRESTOREBUFFERREGIONARBPROC __wglewRestoreBufferRegionARB; 1228 | WGLEW_FUN_EXPORT PFNWGLSAVEBUFFERREGIONARBPROC __wglewSaveBufferRegionARB; 1229 | 1230 | WGLEW_FUN_EXPORT PFNWGLCREATECONTEXTATTRIBSARBPROC __wglewCreateContextAttribsARB; 1231 | 1232 | WGLEW_FUN_EXPORT PFNWGLGETEXTENSIONSSTRINGARBPROC __wglewGetExtensionsStringARB; 1233 | 1234 | WGLEW_FUN_EXPORT PFNWGLGETCURRENTREADDCARBPROC __wglewGetCurrentReadDCARB; 1235 | WGLEW_FUN_EXPORT PFNWGLMAKECONTEXTCURRENTARBPROC __wglewMakeContextCurrentARB; 1236 | 1237 | WGLEW_FUN_EXPORT PFNWGLCREATEPBUFFERARBPROC __wglewCreatePbufferARB; 1238 | WGLEW_FUN_EXPORT PFNWGLDESTROYPBUFFERARBPROC __wglewDestroyPbufferARB; 1239 | WGLEW_FUN_EXPORT PFNWGLGETPBUFFERDCARBPROC __wglewGetPbufferDCARB; 1240 | WGLEW_FUN_EXPORT PFNWGLQUERYPBUFFERARBPROC __wglewQueryPbufferARB; 1241 | WGLEW_FUN_EXPORT PFNWGLRELEASEPBUFFERDCARBPROC __wglewReleasePbufferDCARB; 1242 | 1243 | WGLEW_FUN_EXPORT PFNWGLCHOOSEPIXELFORMATARBPROC __wglewChoosePixelFormatARB; 1244 | WGLEW_FUN_EXPORT PFNWGLGETPIXELFORMATATTRIBFVARBPROC __wglewGetPixelFormatAttribfvARB; 1245 | WGLEW_FUN_EXPORT PFNWGLGETPIXELFORMATATTRIBIVARBPROC __wglewGetPixelFormatAttribivARB; 1246 | 1247 | WGLEW_FUN_EXPORT PFNWGLBINDTEXIMAGEARBPROC __wglewBindTexImageARB; 1248 | WGLEW_FUN_EXPORT PFNWGLRELEASETEXIMAGEARBPROC __wglewReleaseTexImageARB; 1249 | WGLEW_FUN_EXPORT PFNWGLSETPBUFFERATTRIBARBPROC __wglewSetPbufferAttribARB; 1250 | 1251 | WGLEW_FUN_EXPORT PFNWGLBINDDISPLAYCOLORTABLEEXTPROC __wglewBindDisplayColorTableEXT; 1252 | WGLEW_FUN_EXPORT PFNWGLCREATEDISPLAYCOLORTABLEEXTPROC __wglewCreateDisplayColorTableEXT; 1253 | WGLEW_FUN_EXPORT PFNWGLDESTROYDISPLAYCOLORTABLEEXTPROC __wglewDestroyDisplayColorTableEXT; 1254 | WGLEW_FUN_EXPORT PFNWGLLOADDISPLAYCOLORTABLEEXTPROC __wglewLoadDisplayColorTableEXT; 1255 | 1256 | WGLEW_FUN_EXPORT PFNWGLGETEXTENSIONSSTRINGEXTPROC __wglewGetExtensionsStringEXT; 1257 | 1258 | WGLEW_FUN_EXPORT PFNWGLGETCURRENTREADDCEXTPROC __wglewGetCurrentReadDCEXT; 1259 | WGLEW_FUN_EXPORT PFNWGLMAKECONTEXTCURRENTEXTPROC __wglewMakeContextCurrentEXT; 1260 | 1261 | WGLEW_FUN_EXPORT PFNWGLCREATEPBUFFEREXTPROC __wglewCreatePbufferEXT; 1262 | WGLEW_FUN_EXPORT PFNWGLDESTROYPBUFFEREXTPROC __wglewDestroyPbufferEXT; 1263 | WGLEW_FUN_EXPORT PFNWGLGETPBUFFERDCEXTPROC __wglewGetPbufferDCEXT; 1264 | WGLEW_FUN_EXPORT PFNWGLQUERYPBUFFEREXTPROC __wglewQueryPbufferEXT; 1265 | WGLEW_FUN_EXPORT PFNWGLRELEASEPBUFFERDCEXTPROC __wglewReleasePbufferDCEXT; 1266 | 1267 | WGLEW_FUN_EXPORT PFNWGLCHOOSEPIXELFORMATEXTPROC __wglewChoosePixelFormatEXT; 1268 | WGLEW_FUN_EXPORT PFNWGLGETPIXELFORMATATTRIBFVEXTPROC __wglewGetPixelFormatAttribfvEXT; 1269 | WGLEW_FUN_EXPORT PFNWGLGETPIXELFORMATATTRIBIVEXTPROC __wglewGetPixelFormatAttribivEXT; 1270 | 1271 | WGLEW_FUN_EXPORT PFNWGLGETSWAPINTERVALEXTPROC __wglewGetSwapIntervalEXT; 1272 | WGLEW_FUN_EXPORT PFNWGLSWAPINTERVALEXTPROC __wglewSwapIntervalEXT; 1273 | 1274 | WGLEW_FUN_EXPORT PFNWGLGETDIGITALVIDEOPARAMETERSI3DPROC __wglewGetDigitalVideoParametersI3D; 1275 | WGLEW_FUN_EXPORT PFNWGLSETDIGITALVIDEOPARAMETERSI3DPROC __wglewSetDigitalVideoParametersI3D; 1276 | 1277 | WGLEW_FUN_EXPORT PFNWGLGETGAMMATABLEI3DPROC __wglewGetGammaTableI3D; 1278 | WGLEW_FUN_EXPORT PFNWGLGETGAMMATABLEPARAMETERSI3DPROC __wglewGetGammaTableParametersI3D; 1279 | WGLEW_FUN_EXPORT PFNWGLSETGAMMATABLEI3DPROC __wglewSetGammaTableI3D; 1280 | WGLEW_FUN_EXPORT PFNWGLSETGAMMATABLEPARAMETERSI3DPROC __wglewSetGammaTableParametersI3D; 1281 | 1282 | WGLEW_FUN_EXPORT PFNWGLDISABLEGENLOCKI3DPROC __wglewDisableGenlockI3D; 1283 | WGLEW_FUN_EXPORT PFNWGLENABLEGENLOCKI3DPROC __wglewEnableGenlockI3D; 1284 | WGLEW_FUN_EXPORT PFNWGLGENLOCKSAMPLERATEI3DPROC __wglewGenlockSampleRateI3D; 1285 | WGLEW_FUN_EXPORT PFNWGLGENLOCKSOURCEDELAYI3DPROC __wglewGenlockSourceDelayI3D; 1286 | WGLEW_FUN_EXPORT PFNWGLGENLOCKSOURCEEDGEI3DPROC __wglewGenlockSourceEdgeI3D; 1287 | WGLEW_FUN_EXPORT PFNWGLGENLOCKSOURCEI3DPROC __wglewGenlockSourceI3D; 1288 | WGLEW_FUN_EXPORT PFNWGLGETGENLOCKSAMPLERATEI3DPROC __wglewGetGenlockSampleRateI3D; 1289 | WGLEW_FUN_EXPORT PFNWGLGETGENLOCKSOURCEDELAYI3DPROC __wglewGetGenlockSourceDelayI3D; 1290 | WGLEW_FUN_EXPORT PFNWGLGETGENLOCKSOURCEEDGEI3DPROC __wglewGetGenlockSourceEdgeI3D; 1291 | WGLEW_FUN_EXPORT PFNWGLGETGENLOCKSOURCEI3DPROC __wglewGetGenlockSourceI3D; 1292 | WGLEW_FUN_EXPORT PFNWGLISENABLEDGENLOCKI3DPROC __wglewIsEnabledGenlockI3D; 1293 | WGLEW_FUN_EXPORT PFNWGLQUERYGENLOCKMAXSOURCEDELAYI3DPROC __wglewQueryGenlockMaxSourceDelayI3D; 1294 | 1295 | WGLEW_FUN_EXPORT PFNWGLASSOCIATEIMAGEBUFFEREVENTSI3DPROC __wglewAssociateImageBufferEventsI3D; 1296 | WGLEW_FUN_EXPORT PFNWGLCREATEIMAGEBUFFERI3DPROC __wglewCreateImageBufferI3D; 1297 | WGLEW_FUN_EXPORT PFNWGLDESTROYIMAGEBUFFERI3DPROC __wglewDestroyImageBufferI3D; 1298 | WGLEW_FUN_EXPORT PFNWGLRELEASEIMAGEBUFFEREVENTSI3DPROC __wglewReleaseImageBufferEventsI3D; 1299 | 1300 | WGLEW_FUN_EXPORT PFNWGLDISABLEFRAMELOCKI3DPROC __wglewDisableFrameLockI3D; 1301 | WGLEW_FUN_EXPORT PFNWGLENABLEFRAMELOCKI3DPROC __wglewEnableFrameLockI3D; 1302 | WGLEW_FUN_EXPORT PFNWGLISENABLEDFRAMELOCKI3DPROC __wglewIsEnabledFrameLockI3D; 1303 | WGLEW_FUN_EXPORT PFNWGLQUERYFRAMELOCKMASTERI3DPROC __wglewQueryFrameLockMasterI3D; 1304 | 1305 | WGLEW_FUN_EXPORT PFNWGLBEGINFRAMETRACKINGI3DPROC __wglewBeginFrameTrackingI3D; 1306 | WGLEW_FUN_EXPORT PFNWGLENDFRAMETRACKINGI3DPROC __wglewEndFrameTrackingI3D; 1307 | WGLEW_FUN_EXPORT PFNWGLGETFRAMEUSAGEI3DPROC __wglewGetFrameUsageI3D; 1308 | WGLEW_FUN_EXPORT PFNWGLQUERYFRAMETRACKINGI3DPROC __wglewQueryFrameTrackingI3D; 1309 | 1310 | WGLEW_FUN_EXPORT PFNWGLDXCLOSEDEVICENVPROC __wglewDXCloseDeviceNV; 1311 | WGLEW_FUN_EXPORT PFNWGLDXLOCKOBJECTSNVPROC __wglewDXLockObjectsNV; 1312 | WGLEW_FUN_EXPORT PFNWGLDXOBJECTACCESSNVPROC __wglewDXObjectAccessNV; 1313 | WGLEW_FUN_EXPORT PFNWGLDXOPENDEVICENVPROC __wglewDXOpenDeviceNV; 1314 | WGLEW_FUN_EXPORT PFNWGLDXREGISTEROBJECTNVPROC __wglewDXRegisterObjectNV; 1315 | WGLEW_FUN_EXPORT PFNWGLDXSETRESOURCESHAREHANDLENVPROC __wglewDXSetResourceShareHandleNV; 1316 | WGLEW_FUN_EXPORT PFNWGLDXUNLOCKOBJECTSNVPROC __wglewDXUnlockObjectsNV; 1317 | WGLEW_FUN_EXPORT PFNWGLDXUNREGISTEROBJECTNVPROC __wglewDXUnregisterObjectNV; 1318 | 1319 | WGLEW_FUN_EXPORT PFNWGLCOPYIMAGESUBDATANVPROC __wglewCopyImageSubDataNV; 1320 | 1321 | WGLEW_FUN_EXPORT PFNWGLDELAYBEFORESWAPNVPROC __wglewDelayBeforeSwapNV; 1322 | 1323 | WGLEW_FUN_EXPORT PFNWGLCREATEAFFINITYDCNVPROC __wglewCreateAffinityDCNV; 1324 | WGLEW_FUN_EXPORT PFNWGLDELETEDCNVPROC __wglewDeleteDCNV; 1325 | WGLEW_FUN_EXPORT PFNWGLENUMGPUDEVICESNVPROC __wglewEnumGpuDevicesNV; 1326 | WGLEW_FUN_EXPORT PFNWGLENUMGPUSFROMAFFINITYDCNVPROC __wglewEnumGpusFromAffinityDCNV; 1327 | WGLEW_FUN_EXPORT PFNWGLENUMGPUSNVPROC __wglewEnumGpusNV; 1328 | 1329 | WGLEW_FUN_EXPORT PFNWGLBINDVIDEODEVICENVPROC __wglewBindVideoDeviceNV; 1330 | WGLEW_FUN_EXPORT PFNWGLENUMERATEVIDEODEVICESNVPROC __wglewEnumerateVideoDevicesNV; 1331 | WGLEW_FUN_EXPORT PFNWGLQUERYCURRENTCONTEXTNVPROC __wglewQueryCurrentContextNV; 1332 | 1333 | WGLEW_FUN_EXPORT PFNWGLBINDSWAPBARRIERNVPROC __wglewBindSwapBarrierNV; 1334 | WGLEW_FUN_EXPORT PFNWGLJOINSWAPGROUPNVPROC __wglewJoinSwapGroupNV; 1335 | WGLEW_FUN_EXPORT PFNWGLQUERYFRAMECOUNTNVPROC __wglewQueryFrameCountNV; 1336 | WGLEW_FUN_EXPORT PFNWGLQUERYMAXSWAPGROUPSNVPROC __wglewQueryMaxSwapGroupsNV; 1337 | WGLEW_FUN_EXPORT PFNWGLQUERYSWAPGROUPNVPROC __wglewQuerySwapGroupNV; 1338 | WGLEW_FUN_EXPORT PFNWGLRESETFRAMECOUNTNVPROC __wglewResetFrameCountNV; 1339 | 1340 | WGLEW_FUN_EXPORT PFNWGLALLOCATEMEMORYNVPROC __wglewAllocateMemoryNV; 1341 | WGLEW_FUN_EXPORT PFNWGLFREEMEMORYNVPROC __wglewFreeMemoryNV; 1342 | 1343 | WGLEW_FUN_EXPORT PFNWGLBINDVIDEOCAPTUREDEVICENVPROC __wglewBindVideoCaptureDeviceNV; 1344 | WGLEW_FUN_EXPORT PFNWGLENUMERATEVIDEOCAPTUREDEVICESNVPROC __wglewEnumerateVideoCaptureDevicesNV; 1345 | WGLEW_FUN_EXPORT PFNWGLLOCKVIDEOCAPTUREDEVICENVPROC __wglewLockVideoCaptureDeviceNV; 1346 | WGLEW_FUN_EXPORT PFNWGLQUERYVIDEOCAPTUREDEVICENVPROC __wglewQueryVideoCaptureDeviceNV; 1347 | WGLEW_FUN_EXPORT PFNWGLRELEASEVIDEOCAPTUREDEVICENVPROC __wglewReleaseVideoCaptureDeviceNV; 1348 | 1349 | WGLEW_FUN_EXPORT PFNWGLBINDVIDEOIMAGENVPROC __wglewBindVideoImageNV; 1350 | WGLEW_FUN_EXPORT PFNWGLGETVIDEODEVICENVPROC __wglewGetVideoDeviceNV; 1351 | WGLEW_FUN_EXPORT PFNWGLGETVIDEOINFONVPROC __wglewGetVideoInfoNV; 1352 | WGLEW_FUN_EXPORT PFNWGLRELEASEVIDEODEVICENVPROC __wglewReleaseVideoDeviceNV; 1353 | WGLEW_FUN_EXPORT PFNWGLRELEASEVIDEOIMAGENVPROC __wglewReleaseVideoImageNV; 1354 | WGLEW_FUN_EXPORT PFNWGLSENDPBUFFERTOVIDEONVPROC __wglewSendPbufferToVideoNV; 1355 | 1356 | WGLEW_FUN_EXPORT PFNWGLGETMSCRATEOMLPROC __wglewGetMscRateOML; 1357 | WGLEW_FUN_EXPORT PFNWGLGETSYNCVALUESOMLPROC __wglewGetSyncValuesOML; 1358 | WGLEW_FUN_EXPORT PFNWGLSWAPBUFFERSMSCOMLPROC __wglewSwapBuffersMscOML; 1359 | WGLEW_FUN_EXPORT PFNWGLSWAPLAYERBUFFERSMSCOMLPROC __wglewSwapLayerBuffersMscOML; 1360 | WGLEW_FUN_EXPORT PFNWGLWAITFORMSCOMLPROC __wglewWaitForMscOML; 1361 | WGLEW_FUN_EXPORT PFNWGLWAITFORSBCOMLPROC __wglewWaitForSbcOML; 1362 | WGLEW_VAR_EXPORT GLboolean __WGLEW_3DFX_multisample; 1363 | WGLEW_VAR_EXPORT GLboolean __WGLEW_3DL_stereo_control; 1364 | WGLEW_VAR_EXPORT GLboolean __WGLEW_AMD_gpu_association; 1365 | WGLEW_VAR_EXPORT GLboolean __WGLEW_ARB_buffer_region; 1366 | WGLEW_VAR_EXPORT GLboolean __WGLEW_ARB_context_flush_control; 1367 | WGLEW_VAR_EXPORT GLboolean __WGLEW_ARB_create_context; 1368 | WGLEW_VAR_EXPORT GLboolean __WGLEW_ARB_create_context_profile; 1369 | WGLEW_VAR_EXPORT GLboolean __WGLEW_ARB_create_context_robustness; 1370 | WGLEW_VAR_EXPORT GLboolean __WGLEW_ARB_extensions_string; 1371 | WGLEW_VAR_EXPORT GLboolean __WGLEW_ARB_framebuffer_sRGB; 1372 | WGLEW_VAR_EXPORT GLboolean __WGLEW_ARB_make_current_read; 1373 | WGLEW_VAR_EXPORT GLboolean __WGLEW_ARB_multisample; 1374 | WGLEW_VAR_EXPORT GLboolean __WGLEW_ARB_pbuffer; 1375 | WGLEW_VAR_EXPORT GLboolean __WGLEW_ARB_pixel_format; 1376 | WGLEW_VAR_EXPORT GLboolean __WGLEW_ARB_pixel_format_float; 1377 | WGLEW_VAR_EXPORT GLboolean __WGLEW_ARB_render_texture; 1378 | WGLEW_VAR_EXPORT GLboolean __WGLEW_ARB_robustness_application_isolation; 1379 | WGLEW_VAR_EXPORT GLboolean __WGLEW_ARB_robustness_share_group_isolation; 1380 | WGLEW_VAR_EXPORT GLboolean __WGLEW_ATI_pixel_format_float; 1381 | WGLEW_VAR_EXPORT GLboolean __WGLEW_ATI_render_texture_rectangle; 1382 | WGLEW_VAR_EXPORT GLboolean __WGLEW_EXT_create_context_es2_profile; 1383 | WGLEW_VAR_EXPORT GLboolean __WGLEW_EXT_create_context_es_profile; 1384 | WGLEW_VAR_EXPORT GLboolean __WGLEW_EXT_depth_float; 1385 | WGLEW_VAR_EXPORT GLboolean __WGLEW_EXT_display_color_table; 1386 | WGLEW_VAR_EXPORT GLboolean __WGLEW_EXT_extensions_string; 1387 | WGLEW_VAR_EXPORT GLboolean __WGLEW_EXT_framebuffer_sRGB; 1388 | WGLEW_VAR_EXPORT GLboolean __WGLEW_EXT_make_current_read; 1389 | WGLEW_VAR_EXPORT GLboolean __WGLEW_EXT_multisample; 1390 | WGLEW_VAR_EXPORT GLboolean __WGLEW_EXT_pbuffer; 1391 | WGLEW_VAR_EXPORT GLboolean __WGLEW_EXT_pixel_format; 1392 | WGLEW_VAR_EXPORT GLboolean __WGLEW_EXT_pixel_format_packed_float; 1393 | WGLEW_VAR_EXPORT GLboolean __WGLEW_EXT_swap_control; 1394 | WGLEW_VAR_EXPORT GLboolean __WGLEW_EXT_swap_control_tear; 1395 | WGLEW_VAR_EXPORT GLboolean __WGLEW_I3D_digital_video_control; 1396 | WGLEW_VAR_EXPORT GLboolean __WGLEW_I3D_gamma; 1397 | WGLEW_VAR_EXPORT GLboolean __WGLEW_I3D_genlock; 1398 | WGLEW_VAR_EXPORT GLboolean __WGLEW_I3D_image_buffer; 1399 | WGLEW_VAR_EXPORT GLboolean __WGLEW_I3D_swap_frame_lock; 1400 | WGLEW_VAR_EXPORT GLboolean __WGLEW_I3D_swap_frame_usage; 1401 | WGLEW_VAR_EXPORT GLboolean __WGLEW_NV_DX_interop; 1402 | WGLEW_VAR_EXPORT GLboolean __WGLEW_NV_DX_interop2; 1403 | WGLEW_VAR_EXPORT GLboolean __WGLEW_NV_copy_image; 1404 | WGLEW_VAR_EXPORT GLboolean __WGLEW_NV_delay_before_swap; 1405 | WGLEW_VAR_EXPORT GLboolean __WGLEW_NV_float_buffer; 1406 | WGLEW_VAR_EXPORT GLboolean __WGLEW_NV_gpu_affinity; 1407 | WGLEW_VAR_EXPORT GLboolean __WGLEW_NV_multisample_coverage; 1408 | WGLEW_VAR_EXPORT GLboolean __WGLEW_NV_present_video; 1409 | WGLEW_VAR_EXPORT GLboolean __WGLEW_NV_render_depth_texture; 1410 | WGLEW_VAR_EXPORT GLboolean __WGLEW_NV_render_texture_rectangle; 1411 | WGLEW_VAR_EXPORT GLboolean __WGLEW_NV_swap_group; 1412 | WGLEW_VAR_EXPORT GLboolean __WGLEW_NV_vertex_array_range; 1413 | WGLEW_VAR_EXPORT GLboolean __WGLEW_NV_video_capture; 1414 | WGLEW_VAR_EXPORT GLboolean __WGLEW_NV_video_output; 1415 | WGLEW_VAR_EXPORT GLboolean __WGLEW_OML_sync_control; 1416 | 1417 | #ifdef GLEW_MX 1418 | }; /* WGLEWContextStruct */ 1419 | #endif /* GLEW_MX */ 1420 | 1421 | /* ------------------------------------------------------------------------- */ 1422 | 1423 | #ifdef GLEW_MX 1424 | 1425 | typedef struct WGLEWContextStruct WGLEWContext; 1426 | GLEWAPI GLenum GLEWAPIENTRY wglewContextInit (WGLEWContext *ctx); 1427 | GLEWAPI GLboolean GLEWAPIENTRY wglewContextIsSupported (const WGLEWContext *ctx, const char *name); 1428 | 1429 | #define wglewInit() wglewContextInit(wglewGetContext()) 1430 | #define wglewIsSupported(x) wglewContextIsSupported(wglewGetContext(), x) 1431 | 1432 | #define WGLEW_GET_VAR(x) (*(const GLboolean*)&(wglewGetContext()->x)) 1433 | #define WGLEW_GET_FUN(x) wglewGetContext()->x 1434 | 1435 | #else /* GLEW_MX */ 1436 | 1437 | GLEWAPI GLenum GLEWAPIENTRY wglewInit (); 1438 | GLEWAPI GLboolean GLEWAPIENTRY wglewIsSupported (const char *name); 1439 | 1440 | #define WGLEW_GET_VAR(x) (*(const GLboolean*)&x) 1441 | #define WGLEW_GET_FUN(x) x 1442 | 1443 | #endif /* GLEW_MX */ 1444 | 1445 | GLEWAPI GLboolean GLEWAPIENTRY wglewGetExtension (const char *name); 1446 | 1447 | #ifdef __cplusplus 1448 | } 1449 | #endif 1450 | 1451 | #undef GLEWAPI 1452 | 1453 | #endif /* __wglew_h__ */ 1454 | -------------------------------------------------------------------------------- /externals/glew/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The OpenGL Extension Wrangler Library 2 | Copyright (C) 2002-2007, Milan Ikits 3 | Copyright (C) 2002-2007, Marcelo E. Magallon 4 | Copyright (C) 2002, Lev Povalahev 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | * The name of the author may be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | 31 | Mesa 3-D graphics library 32 | Version: 7.0 33 | 34 | Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 35 | 36 | Permission is hereby granted, free of charge, to any person obtaining a 37 | copy of this software and associated documentation files (the "Software"), 38 | to deal in the Software without restriction, including without limitation 39 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 40 | and/or sell copies of the Software, and to permit persons to whom the 41 | Software is furnished to do so, subject to the following conditions: 42 | 43 | The above copyright notice and this permission notice shall be included 44 | in all copies or substantial portions of the Software. 45 | 46 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 47 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 48 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 49 | BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 50 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 51 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 52 | 53 | 54 | Copyright (c) 2007 The Khronos Group Inc. 55 | 56 | Permission is hereby granted, free of charge, to any person obtaining a 57 | copy of this software and/or associated documentation files (the 58 | "Materials"), to deal in the Materials without restriction, including 59 | without limitation the rights to use, copy, modify, merge, publish, 60 | distribute, sublicense, and/or sell copies of the Materials, and to 61 | permit persons to whom the Materials are furnished to do so, subject to 62 | the following conditions: 63 | 64 | The above copyright notice and this permission notice shall be included 65 | in all copies or substantial portions of the Materials. 66 | 67 | THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 68 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 69 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 70 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 71 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 72 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 73 | MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 74 | -------------------------------------------------------------------------------- /file_id.diz: -------------------------------------------------------------------------------- 1 | 2 | FOXOTRON 3 | 4 | General purpose model viewer 5 | 6 | https://github.com/Gargaj/Foxotron/ -------------------------------------------------------------------------------- /src/Geometry.cpp: -------------------------------------------------------------------------------- 1 | #include "Geometry.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | #ifdef min 17 | #undef min 18 | #endif 19 | #ifdef max 20 | #undef max 21 | #endif 22 | 23 | Assimp::Importer gImporter; 24 | 25 | #pragma pack(1) 26 | struct Vertex 27 | { 28 | glm::vec3 v3Vector; 29 | glm::vec3 v3Normal; 30 | glm::vec3 v3Tangent; 31 | glm::vec3 v3Binormal; 32 | glm::vec2 fTexcoord; 33 | }; 34 | #pragma pack() 35 | 36 | // Transform an AABB into an OBB, and return its AABB 37 | void TransformBoundingBox( const glm::vec3 & inMin, const glm::vec3 & inMax, const glm::mat4x4 & m, glm::vec3 & outMin, glm::vec3 & outMax ) 38 | { 39 | static glm::vec3 xa; xa = glm::vec3( m[ 1 - 1 ][ 1 - 1 ], m[ 1 - 1 ][ 2 - 1 ], m[ 1 - 1 ][ 3 - 1 ] ) * inMin.x; 40 | static glm::vec3 xb; xb = glm::vec3( m[ 1 - 1 ][ 1 - 1 ], m[ 1 - 1 ][ 2 - 1 ], m[ 1 - 1 ][ 3 - 1 ] ) * inMax.x; 41 | 42 | static glm::vec3 ya; ya = glm::vec3( m[ 2 - 1 ][ 1 - 1 ], m[ 2 - 1 ][ 2 - 1 ], m[ 2 - 1 ][ 3 - 1 ] ) * inMin.y; 43 | static glm::vec3 yb; yb = glm::vec3( m[ 2 - 1 ][ 1 - 1 ], m[ 2 - 1 ][ 2 - 1 ], m[ 2 - 1 ][ 3 - 1 ] ) * inMax.y; 44 | 45 | static glm::vec3 za; za = glm::vec3( m[ 3 - 1 ][ 1 - 1 ], m[ 3 - 1 ][ 2 - 1 ], m[ 3 - 1 ][ 3 - 1 ] ) * inMin.z; 46 | static glm::vec3 zb; zb = glm::vec3( m[ 3 - 1 ][ 1 - 1 ], m[ 3 - 1 ][ 2 - 1 ], m[ 3 - 1 ][ 3 - 1 ] ) * inMax.z; 47 | 48 | outMin = glm::min( xa, xb ) + glm::min( ya, yb ) + glm::min( za, zb ) + glm::vec3( m[ 4 - 1 ][ 1 - 1 ], m[ 4 - 1 ][ 2 - 1 ], m[ 4 - 1 ][ 3 - 1 ] ); 49 | outMax = glm::max( xa, xb ) + glm::max( ya, yb ) + glm::max( za, zb ) + glm::vec3( m[ 4 - 1 ][ 1 - 1 ], m[ 4 - 1 ][ 2 - 1 ], m[ 4 - 1 ][ 3 - 1 ] ); 50 | } 51 | 52 | Renderer::Texture * LoadTexture( Geometry * _geometry, const char * _type, const aiString & _path, const std::string & _folder, const bool _loadAsSRGB = false ) 53 | { 54 | std::string filename( _path.data, _path.length ); 55 | 56 | if ( filename[ 0 ] == '*' ) 57 | { 58 | int index = 0; 59 | sscanf( filename.c_str(), "*%d", &index ); 60 | 61 | printf( "[geometry] Using embedded texture %d: '%s'\n", index, filename.c_str() ); 62 | 63 | if ( _geometry->mEmbeddedTextures[ index ] ) 64 | { 65 | _geometry->mEmbeddedTextures[ index ]->mRefCount++; 66 | return _geometry->mEmbeddedTextures[ index ]; 67 | } 68 | return NULL; 69 | } 70 | 71 | if ( filename.find( '\\' ) != -1 ) 72 | { 73 | filename = filename.substr( filename.find_last_of( '\\' ) + 1 ); 74 | } 75 | if ( filename.find( '/' ) != -1 ) 76 | { 77 | filename = filename.substr( filename.find_last_of( '/' ) + 1 ); 78 | } 79 | 80 | printf( "[geometry] Loading %s texture: '%s'\n", _type, filename.c_str() ); 81 | 82 | Renderer::Texture * texture = Renderer::CreateRGBA8TextureFromFile( filename.c_str(), _loadAsSRGB ); 83 | if ( texture ) 84 | { 85 | return texture; 86 | } 87 | 88 | std::string filenameWithPath = _folder + filename; 89 | 90 | texture = Renderer::CreateRGBA8TextureFromFile( filenameWithPath.c_str(), _loadAsSRGB ); 91 | if ( texture ) 92 | { 93 | return texture; 94 | } 95 | 96 | std::string extless = filenameWithPath.substr( 0, filenameWithPath.find_last_of( '.' ) ); 97 | 98 | const char * extensions[] = { ".hdr", ".png", ".tga", ".jpg", ".jpeg", ".bmp", NULL }; 99 | for ( int i = 0; extensions[ i ]; i++ ) 100 | { 101 | std::string replacementFilename = extless + extensions[ i ]; 102 | texture = Renderer::CreateRGBA8TextureFromFile( replacementFilename.c_str(), _loadAsSRGB ); 103 | if ( texture ) 104 | { 105 | printf( "[geometry] Replacement %s texture found: '%s'\n", _type, replacementFilename.c_str() ); 106 | return texture; 107 | } 108 | } 109 | 110 | for ( int i = 0; i < _geometry->mEmbeddedTextures.size(); i++ ) 111 | { 112 | if ( _geometry->mEmbeddedTextures[ i ] && filename == _geometry->mEmbeddedTextures[ i ]->mFilename ) 113 | { 114 | printf( "[geometry] Using embedded texture: '%s'\n", filename.c_str() ); 115 | 116 | _geometry->mEmbeddedTextures[ i ]->mRefCount++; 117 | return _geometry->mEmbeddedTextures[ i ]; 118 | } 119 | } 120 | 121 | printf( "[geometry] WARNING: Texture loading (%s) failed: '%s'\n", _type, filename.c_str() ); 122 | return NULL; 123 | } 124 | 125 | bool LoadColorMap( Geometry * _geometry, aiMaterial * _material, Geometry::ColorMap & _colorMap, aiTextureType _semantic, const char * _semanticText, const std::string & _folder, bool _loadAsSRGB = false ) 126 | { 127 | bool success = false; 128 | _colorMap.mTexture = NULL; 129 | 130 | aiString str; 131 | if ( aiGetMaterialString( _material, AI_MATKEY_TEXTURE( _semantic, 0 ), &str ) == AI_SUCCESS ) 132 | { 133 | _colorMap.mTexture = LoadTexture( _geometry, _semanticText, str, _folder, _loadAsSRGB ); 134 | _colorMap.mValid = true; 135 | success = true; 136 | } 137 | 138 | aiColor4D color; 139 | aiColor4D translucentColor; 140 | aiReturn result = AI_FAILURE, result2 = AI_FAILURE; 141 | switch ( _semantic ) 142 | { 143 | case aiTextureType_AMBIENT: 144 | result = aiGetMaterialColor( _material, AI_MATKEY_COLOR_AMBIENT, &color ); 145 | break; 146 | case aiTextureType_DIFFUSE: 147 | case aiTextureType_BASE_COLOR: 148 | result = aiGetMaterialColor( _material, AI_MATKEY_COLOR_DIFFUSE, &color ); 149 | result2 = aiGetMaterialColor( _material, AI_MATKEY_COLOR_TRANSPARENT, &translucentColor ); 150 | if ( result2 == AI_SUCCESS ) 151 | color.a = ( 1.0f - translucentColor.r ); 152 | break; 153 | case aiTextureType_SPECULAR: 154 | result = aiGetMaterialColor( _material, AI_MATKEY_COLOR_SPECULAR, &color ); 155 | break; 156 | case aiTextureType_EMISSIVE: 157 | result = aiGetMaterialColor( _material, AI_MATKEY_COLOR_EMISSIVE, &color ); 158 | break; 159 | }; 160 | if ( result == AI_SUCCESS ) 161 | { 162 | memcpy( &_colorMap.mColor, &color.r, sizeof( float ) * 4 ); 163 | _colorMap.mValid = true; 164 | } 165 | 166 | return success; 167 | } 168 | 169 | int gNodeCount = 0; 170 | void ParseNode( Geometry * _geometry, const aiScene * scene, aiNode * sceneNode, int nParentIndex ) 171 | { 172 | Geometry::Node node; 173 | node.mID = gNodeCount++; 174 | node.mParentID = nParentIndex; 175 | node.mName = std::string( sceneNode->mName.data, sceneNode->mName.length ); 176 | 177 | for ( unsigned int i = 0; i < sceneNode->mNumMeshes; i++ ) 178 | { 179 | node.mMeshes.push_back( sceneNode->mMeshes[ i ] ); 180 | } 181 | 182 | aiMatrix4x4 m = sceneNode->mTransformation.Transpose(); 183 | memcpy( &node.mTransformation, &m.a1, sizeof( float ) * 16 ); 184 | 185 | _geometry->mNodes.insert( { node.mID, node } ); 186 | 187 | for ( unsigned int i = 0; i < sceneNode->mNumChildren; i++ ) 188 | { 189 | ParseNode( _geometry, scene, sceneNode->mChildren[ i ], node.mID ); 190 | } 191 | } 192 | 193 | class GeometryLogging : public Assimp::LogStream 194 | { 195 | public: 196 | void write( const char * message ) 197 | { 198 | printf( "[assimp] %s", message ); 199 | } 200 | }; 201 | 202 | Geometry::Geometry() 203 | : mMatrices( NULL ) 204 | , mAABBMin( 0.0f ) 205 | , mAABBMax( 0.0f ) 206 | , mModelDiagonal( 0.0f ) 207 | { 208 | } 209 | 210 | Geometry::~Geometry() 211 | { 212 | UnloadMesh(); 213 | } 214 | 215 | bool Geometry::LoadMesh( const char * _path ) 216 | { 217 | UnloadMesh(); 218 | 219 | std::string path = _path; 220 | std::string folder; 221 | if ( path.find( '\\' ) != -1 ) 222 | { 223 | folder = path.substr( 0, path.find_last_of( '\\' ) + 1 ); 224 | } 225 | if ( path.find( '/' ) != -1 ) 226 | { 227 | folder = path.substr( 0, path.find_last_of( '/' ) + 1 ); 228 | } 229 | 230 | gImporter.SetPropertyInteger( AI_CONFIG_PP_SBBC_MAX_BONES, 24 ); 231 | 232 | unsigned int loadFlags = 233 | aiProcess_CalcTangentSpace | 234 | aiProcess_Triangulate | 235 | aiProcess_JoinIdenticalVertices | 236 | aiProcess_SortByPType | 237 | aiProcess_FlipWindingOrder | 238 | aiProcess_TransformUVCoords | 239 | aiProcess_FlipUVs | 240 | aiProcess_SplitByBoneCount | 241 | 0; 242 | 243 | Assimp::DefaultLogger::create( "", Assimp::Logger::DEBUGGING ); 244 | Assimp::DefaultLogger::get()->attachStream( new GeometryLogging(), Assimp::Logger::Info | Assimp::Logger::Err | Assimp::Logger::Warn ); 245 | 246 | const aiScene * scene = gImporter.ReadFile( _path, loadFlags ); 247 | if ( !scene ) 248 | { 249 | return false; 250 | } 251 | 252 | Assimp::DefaultLogger::kill(); 253 | 254 | gNodeCount = 0; 255 | ParseNode( this, scene, scene->mRootNode, -1 ); 256 | 257 | mMatrices = mNodes.size() ? new glm::mat4x4[ mNodes.size() ] : nullptr; 258 | 259 | ////////////////////////////////////////////////////////////////////////// 260 | // Load embedded textures, if any 261 | for ( unsigned int i = 0; i < scene->mNumTextures; i++ ) 262 | { 263 | aiTexture * texture = scene->mTextures[ i ]; 264 | Renderer::Texture * renderTexture = NULL; 265 | printf( "[geometry] Loading embedded texture #%d: %s\n", i, texture->mFilename.C_Str() ); 266 | if ( texture->mHeight == 0 ) 267 | { 268 | // Data is a file 269 | renderTexture = Renderer::CreateRGBA8TextureFromMemory( (unsigned char *) texture->pcData, texture->mWidth, true ); // TODO: currently forced to sRGB (problematic) 270 | renderTexture->mFilename = texture->mFilename.C_Str(); 271 | } 272 | else 273 | { 274 | // Data is a set of pixels 275 | unsigned int * rgba = new unsigned int[ texture->mWidth * texture->mHeight ]; 276 | for ( unsigned int j = 0; j < texture->mWidth * texture->mHeight; j++ ) 277 | { 278 | rgba[ j ] = 279 | texture->pcData[ j ].r | 280 | ( texture->pcData[ j ].g << 8 ) | 281 | ( texture->pcData[ j ].b << 16 ) | 282 | ( texture->pcData[ j ].a << 24 ); 283 | } 284 | renderTexture = Renderer::CreateRGBA8TextureFromRawData( rgba, texture->mWidth, texture->mHeight ); 285 | renderTexture->mFilename = texture->mFilename.C_Str(); 286 | delete[] rgba; 287 | } 288 | mEmbeddedTextures.push_back( renderTexture ); 289 | } 290 | 291 | ////////////////////////////////////////////////////////////////////////// 292 | // Calculate node transforms 293 | if ( mMatrices ) 294 | { 295 | for ( std::map::iterator it = mNodes.begin(); it != mNodes.end(); it++ ) 296 | { 297 | const Geometry::Node & node = it->second; 298 | 299 | glm::mat4x4 matParent; 300 | if ( node.mParentID == -1 || !mMatrices ) 301 | { 302 | matParent = glm::mat4x4( 1.0f ); 303 | } 304 | else 305 | { 306 | matParent = mMatrices[ node.mParentID ]; 307 | } 308 | 309 | mMatrices[ node.mID ] = matParent * node.mTransformation; 310 | } 311 | } 312 | 313 | printf( "[geometry] Loading %d materials\n", scene->mNumMaterials ); 314 | for ( unsigned int i = 0; i < scene->mNumMaterials; i++ ) 315 | { 316 | Material material; 317 | 318 | aiString str = scene->mMaterials[ i ]->GetName(); 319 | material.mName = std::string( str.data, str.length ); 320 | printf( "[geometry] Loading material #%d: '%s'\n", i + 1, material.mName.c_str() ); 321 | 322 | material.mColorMapDiffuse.mColor = glm::vec4( 0.5f ); 323 | material.mColorMapNormals.mColor = glm::vec4( 0.0f ); 324 | material.mColorMapSpecular.mColor = glm::vec4( 0.0f ); 325 | material.mColorMapAlbedo.mColor = glm::vec4( 0.5f ); 326 | material.mColorMapRoughness.mColor = glm::vec4( 1.0f ); 327 | material.mColorMapMetallic.mColor = glm::vec4( 0.0f ); 328 | material.mColorMapAO.mColor = glm::vec4( 1.0f ); 329 | material.mColorMapAmbient.mColor = glm::vec4( 1.0f ); 330 | material.mColorMapEmissive.mColor = glm::vec4( 0.0f ); 331 | 332 | LoadColorMap( this, scene->mMaterials[ i ], material.mColorMapDiffuse, aiTextureType_DIFFUSE, "diffuse", folder, true ); 333 | if ( !LoadColorMap( this, scene->mMaterials[ i ], material.mColorMapNormals, aiTextureType_NORMAL_CAMERA, "normals", folder ) ) 334 | { 335 | LoadColorMap( this, scene->mMaterials[ i ], material.mColorMapNormals, aiTextureType_NORMALS, "normals", folder ); 336 | } 337 | LoadColorMap( this, scene->mMaterials[ i ], material.mColorMapAlbedo, aiTextureType_BASE_COLOR, "albedo", folder ); 338 | LoadColorMap( this, scene->mMaterials[ i ], material.mColorMapSpecular, aiTextureType_SPECULAR, "specular", folder ); 339 | if ( !LoadColorMap( this, scene->mMaterials[ i ], material.mColorMapRoughness, aiTextureType_DIFFUSE_ROUGHNESS, "roughness", folder ) ) 340 | { 341 | LoadColorMap( this, scene->mMaterials[ i ], material.mColorMapRoughness, aiTextureType_SHININESS, "roughness (from shininess)", folder ); 342 | } 343 | LoadColorMap( this, scene->mMaterials[ i ], material.mColorMapMetallic, aiTextureType_METALNESS, "metallic", folder ); 344 | LoadColorMap( this, scene->mMaterials[ i ], material.mColorMapAO, aiTextureType_AMBIENT_OCCLUSION, "AO", folder ); 345 | LoadColorMap( this, scene->mMaterials[ i ], material.mColorMapAmbient, aiTextureType_AMBIENT, "ambient", folder ); 346 | LoadColorMap( this, scene->mMaterials[ i ], material.mColorMapEmissive, aiTextureType_EMISSIVE, "emissive", folder, true ); 347 | 348 | float f = 0.0f; 349 | 350 | material.mSpecularShininess = 1.0f; 351 | if ( aiGetMaterialFloat( scene->mMaterials[ i ], AI_MATKEY_SHININESS, &f ) == AI_SUCCESS ) 352 | { 353 | material.mSpecularShininess = f; 354 | } 355 | 356 | mMaterials.insert( { i, material } ); 357 | } 358 | 359 | printf( "[geometry] Loading %d meshes\n", scene->mNumMeshes ); 360 | for ( unsigned int i = 0; i < scene->mNumMeshes; i++ ) 361 | { 362 | aiMesh * sceneMesh = scene->mMeshes[ i ]; 363 | 364 | if ( !sceneMesh->mNumVertices || !sceneMesh->mNumFaces ) 365 | { 366 | continue; 367 | } 368 | 369 | Mesh mesh; 370 | 371 | glGenVertexArrays( 1, &mesh.mVertexArrayObject ); 372 | glGenBuffers( 1, &mesh.mVertexBufferObject ); 373 | glGenBuffers( 1, &mesh.mIndexBufferObject ); 374 | 375 | glBindVertexArray( mesh.mVertexArrayObject ); 376 | glBindBuffer( GL_ARRAY_BUFFER, mesh.mVertexBufferObject ); 377 | glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, mesh.mIndexBufferObject ); 378 | 379 | mesh.mVertexCount = sceneMesh->mNumVertices; 380 | 381 | Vertex * vertices = new Vertex[ mesh.mVertexCount ]; 382 | for ( unsigned int j = 0; j < sceneMesh->mNumVertices; j++ ) 383 | { 384 | vertices[ j ].v3Vector.x = sceneMesh->mVertices[ j ].x; 385 | vertices[ j ].v3Vector.y = sceneMesh->mVertices[ j ].y; 386 | vertices[ j ].v3Vector.z = sceneMesh->mVertices[ j ].z; 387 | vertices[ j ].v3Normal.x = 0.0f; 388 | vertices[ j ].v3Normal.y = 0.0f; 389 | vertices[ j ].v3Normal.z = 0.0f; 390 | if( sceneMesh->mNormals ) 391 | { 392 | vertices[ j ].v3Normal.x = sceneMesh->mNormals[ j ].x; 393 | vertices[ j ].v3Normal.y = sceneMesh->mNormals[ j ].y; 394 | vertices[ j ].v3Normal.z = sceneMesh->mNormals[ j ].z; 395 | } 396 | vertices[ j ].v3Tangent.x = 0.0f; 397 | vertices[ j ].v3Tangent.y = 0.0f; 398 | vertices[ j ].v3Tangent.z = 0.0f; 399 | if ( sceneMesh->mTangents ) 400 | { 401 | vertices[ j ].v3Tangent.x = sceneMesh->mTangents[ j ].x; 402 | vertices[ j ].v3Tangent.y = sceneMesh->mTangents[ j ].y; 403 | vertices[ j ].v3Tangent.z = sceneMesh->mTangents[ j ].z; 404 | } 405 | vertices[ j ].v3Binormal.x = 0.0f; 406 | vertices[ j ].v3Binormal.y = 0.0f; 407 | vertices[ j ].v3Binormal.z = 0.0f; 408 | if ( sceneMesh->mBitangents ) 409 | { 410 | vertices[ j ].v3Binormal.x = sceneMesh->mBitangents[ j ].x; 411 | vertices[ j ].v3Binormal.y = sceneMesh->mBitangents[ j ].y; 412 | vertices[ j ].v3Binormal.z = sceneMesh->mBitangents[ j ].z; 413 | } 414 | if ( sceneMesh->GetNumUVChannels() ) 415 | { 416 | vertices[ j ].fTexcoord.x = sceneMesh->mTextureCoords[ 0 ][ j ].x; 417 | vertices[ j ].fTexcoord.y = sceneMesh->mTextureCoords[ 0 ][ j ].y; 418 | } 419 | else 420 | { 421 | vertices[ j ].fTexcoord.x = 0.0f; 422 | vertices[ j ].fTexcoord.y = 0.0f; 423 | } 424 | 425 | if ( j == 0 ) 426 | { 427 | mesh.mAABBMin = mesh.mAABBMax = vertices[ j ].v3Vector; 428 | } 429 | else 430 | { 431 | mesh.mAABBMin = glm::min( mesh.mAABBMin, vertices[ j ].v3Vector ); 432 | mesh.mAABBMax = glm::max( mesh.mAABBMax, vertices[ j ].v3Vector ); 433 | } 434 | } 435 | 436 | glBufferData( GL_ARRAY_BUFFER, sizeof( Vertex ) * mesh.mVertexCount, vertices, GL_STATIC_DRAW ); 437 | 438 | delete[] vertices; 439 | 440 | mesh.mTriangleCount = sceneMesh->mNumFaces; 441 | 442 | unsigned int * faces = new unsigned int[ sceneMesh->mNumFaces * 3 ]; 443 | 444 | for ( unsigned int j = 0; j < sceneMesh->mNumFaces; j++ ) 445 | { 446 | faces[ j * 3 + 0 ] = sceneMesh->mFaces[ j ].mIndices[ 0 ]; 447 | faces[ j * 3 + 1 ] = sceneMesh->mFaces[ j ].mIndices[ 1 ]; 448 | faces[ j * 3 + 2 ] = sceneMesh->mFaces[ j ].mIndices[ 2 ]; 449 | } 450 | 451 | glBufferData( GL_ELEMENT_ARRAY_BUFFER, sizeof( unsigned int ) * sceneMesh->mNumFaces * 3, faces, GL_STATIC_DRAW ); 452 | 453 | delete[] faces; 454 | 455 | mesh.mMaterialIndex = sceneMesh->mMaterialIndex; 456 | 457 | // By importing materials before meshes we can investigate whether a mesh is transparent and flag it as such. 458 | const Geometry::Material & mtl = mMaterials[ mesh.mMaterialIndex ]; 459 | mesh.mTransparent = false; 460 | mesh.mTransparent |= ( mtl.mColorMapAlbedo.mTexture != nullptr ) ? ( mtl.mColorMapAlbedo.mTexture->mTransparent ) : ( mtl.mColorMapAlbedo.mColor.a != 1.0f ); 461 | mesh.mTransparent |= ( mtl.mColorMapDiffuse.mTexture != nullptr ) ? ( mtl.mColorMapDiffuse.mTexture->mTransparent ) : ( mtl.mColorMapDiffuse.mColor.a != 1.0f ); 462 | 463 | mMeshes.insert( { i, mesh } ); 464 | } 465 | 466 | printf( "[geometry] Calculating AABB\n" ); 467 | bool aabbSet = false; 468 | for ( std::map::iterator it = mNodes.begin(); it != mNodes.end(); it++ ) 469 | { 470 | const Geometry::Node & node = it->second; 471 | for ( int i = 0; i < it->second.mMeshes.size(); i++ ) 472 | { 473 | const Geometry::Mesh & mesh = mMeshes[ it->second.mMeshes[ i ] ]; 474 | 475 | glm::vec3 aabbMin; 476 | glm::vec3 aabbMax; 477 | TransformBoundingBox( mesh.mAABBMin, mesh.mAABBMax, mMatrices[ node.mID ], aabbMin, aabbMax ); 478 | 479 | if ( !aabbSet ) 480 | { 481 | mAABBMin = aabbMin; 482 | mAABBMax = aabbMax; 483 | aabbSet = true; 484 | } 485 | mAABBMin = glm::min( aabbMin, mAABBMin ); 486 | mAABBMax = glm::max( aabbMax, mAABBMax ); 487 | } 488 | } 489 | printf( "[geometry] Calculated AABB: (%.3f, %.3f, %.3f), (%.3f, %.3f, %.3f)\n", mAABBMin.x, mAABBMin.y, mAABBMin.z, mAABBMax.x, mAABBMax.y, mAABBMax.z ); 490 | 491 | mModelDiagonal = glm::length( mAABBMax - mAABBMin ); 492 | 493 | mGlobalAmbient = glm::vec4( 0.3f ); 494 | for ( unsigned int i = 0; i < scene->mNumLights; i++ ) 495 | { 496 | switch ( scene->mLights[ i ]->mType ) 497 | { 498 | case aiLightSource_AMBIENT: 499 | { 500 | memcpy( &mGlobalAmbient, &scene->mLights[ i ]->mColorAmbient.r, sizeof( float ) * 4 ); 501 | } break; 502 | default: 503 | { 504 | // todo 505 | } break; 506 | } 507 | } 508 | 509 | return true; 510 | } 511 | 512 | void Geometry::UnloadMesh() 513 | { 514 | if ( mMatrices ) 515 | { 516 | delete[] mMatrices; 517 | mMatrices = NULL; 518 | } 519 | 520 | mNodes.clear(); 521 | 522 | for ( unsigned int i = 0; i < mEmbeddedTextures.size(); i++ ) 523 | { 524 | Renderer::ReleaseTexture( mEmbeddedTextures[ i ] ); 525 | } 526 | mEmbeddedTextures.clear(); 527 | 528 | for ( std::map::iterator it = mMaterials.begin(); it != mMaterials.end(); it++ ) 529 | { 530 | if ( it->second.mColorMapDiffuse.mTexture ) 531 | { 532 | Renderer::ReleaseTexture( it->second.mColorMapDiffuse.mTexture ); 533 | } 534 | if ( it->second.mColorMapNormals.mTexture ) 535 | { 536 | Renderer::ReleaseTexture( it->second.mColorMapNormals.mTexture ); 537 | } 538 | if ( it->second.mColorMapSpecular.mTexture ) 539 | { 540 | Renderer::ReleaseTexture( it->second.mColorMapSpecular.mTexture ); 541 | } 542 | if ( it->second.mColorMapAlbedo.mTexture ) 543 | { 544 | Renderer::ReleaseTexture( it->second.mColorMapAlbedo.mTexture ); 545 | } 546 | if ( it->second.mColorMapRoughness.mTexture ) 547 | { 548 | Renderer::ReleaseTexture( it->second.mColorMapRoughness.mTexture ); 549 | } 550 | if ( it->second.mColorMapMetallic.mTexture ) 551 | { 552 | Renderer::ReleaseTexture( it->second.mColorMapMetallic.mTexture ); 553 | } 554 | if ( it->second.mColorMapAO.mTexture ) 555 | { 556 | Renderer::ReleaseTexture( it->second.mColorMapAO.mTexture ); 557 | } 558 | if ( it->second.mColorMapAmbient.mTexture ) 559 | { 560 | Renderer::ReleaseTexture( it->second.mColorMapAmbient.mTexture ); 561 | } 562 | } 563 | mMaterials.clear(); 564 | 565 | for ( std::map::iterator it = mMeshes.begin(); it != mMeshes.end(); it++ ) 566 | { 567 | glDeleteBuffers( 1, &it->second.mIndexBufferObject ); 568 | glDeleteBuffers( 1, &it->second.mVertexBufferObject ); 569 | glDeleteVertexArrays( 1, &it->second.mVertexArrayObject ); 570 | } 571 | mMeshes.clear(); 572 | 573 | gImporter.FreeScene(); 574 | } 575 | 576 | void Geometry::Render( const glm::mat4x4 & _worldRootMatrix, Renderer::Shader * _shader ) 577 | { 578 | Renderer::SetShader( _shader ); 579 | 580 | _shader->SetConstant( "global_ambient", mGlobalAmbient ); 581 | 582 | // TODO: Maybe we can cache the world matrices & 2 queues for opaque and transparent in LoadMesh 583 | // but that depends if we want to add animation support (in which case we can't). 584 | for ( int j = 0; j < 3; ++j ) // opaque, transparent backface, transparent frontface 585 | { 586 | bool transparentPass = j > 0; 587 | if ( transparentPass ) 588 | { 589 | glEnable( GL_BLEND ); 590 | glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); 591 | glCullFace( j == 1 ? GL_FRONT : GL_BACK ); 592 | } 593 | for ( std::map::iterator it = mNodes.begin(); it != mNodes.end(); it++ ) 594 | { 595 | const Geometry::Node & node = it->second; 596 | 597 | _shader->SetConstant( "mat_world", mMatrices[ node.mID ] * _worldRootMatrix ); 598 | 599 | for ( int i = 0; i < it->second.mMeshes.size(); i++ ) 600 | { 601 | const Geometry::Mesh & mesh = mMeshes[ it->second.mMeshes[ i ] ]; 602 | // Postpone rendering transparent meshes 603 | if ( mesh.mTransparent != transparentPass ) 604 | { 605 | continue; 606 | } 607 | const Geometry::Material & material = mMaterials[ mesh.mMaterialIndex ]; 608 | 609 | _shader->SetConstant( "specular_shininess", material.mSpecularShininess ); 610 | 611 | SetColorMap( _shader, "map_diffuse", material.mColorMapDiffuse ); 612 | SetColorMap( _shader, "map_normals", material.mColorMapNormals ); 613 | SetColorMap( _shader, "map_specular", material.mColorMapSpecular ); 614 | SetColorMap( _shader, "map_albedo", material.mColorMapAlbedo ); 615 | SetColorMap( _shader, "map_roughness", material.mColorMapRoughness ); 616 | SetColorMap( _shader, "map_metallic", material.mColorMapMetallic ); 617 | SetColorMap( _shader, "map_ao", material.mColorMapAO ); 618 | SetColorMap( _shader, "map_ambient", material.mColorMapAmbient ); 619 | SetColorMap( _shader, "map_emissive", material.mColorMapEmissive ); 620 | 621 | glBindVertexArray( mesh.mVertexArrayObject ); 622 | 623 | glDrawElements( GL_TRIANGLES, mesh.mTriangleCount * 3, GL_UNSIGNED_INT, NULL ); 624 | } 625 | } 626 | if ( transparentPass ) 627 | { 628 | glDisable( GL_BLEND ); 629 | glDepthMask( GL_TRUE ); 630 | } 631 | } 632 | } 633 | 634 | void Geometry::__SetupVertexArray( Renderer::Shader * _shader, const char * name, int sizeInFloats, int & offsetInFloats ) 635 | { 636 | unsigned int stride = sizeof( float ) * 14; 637 | 638 | GLint location = glGetAttribLocation( _shader->mProgram, name ); 639 | if ( location >= 0 ) 640 | { 641 | glVertexAttribPointer( location, sizeInFloats, GL_FLOAT, GL_FALSE, stride, (GLvoid *) ( offsetInFloats * sizeof( GLfloat ) ) ); 642 | glEnableVertexAttribArray( location ); 643 | } 644 | 645 | offsetInFloats += sizeInFloats; 646 | } 647 | 648 | void Geometry::RebindVertexArray( Renderer::Shader * _shader ) 649 | { 650 | for ( int i = 0; i < mMeshes.size(); i++ ) 651 | { 652 | const Geometry::Mesh & mesh = mMeshes[ i ]; 653 | 654 | glBindVertexArray( mesh.mVertexArrayObject ); 655 | glBindBuffer( GL_ARRAY_BUFFER, mesh.mVertexBufferObject ); 656 | glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, mesh.mIndexBufferObject ); 657 | 658 | int offset = 0; 659 | __SetupVertexArray( _shader, "in_pos", 3, offset ); 660 | __SetupVertexArray( _shader, "in_normal", 3, offset ); 661 | __SetupVertexArray( _shader, "in_tangent", 3, offset ); 662 | __SetupVertexArray( _shader, "in_binormal", 3, offset ); 663 | __SetupVertexArray( _shader, "in_texcoord", 2, offset ); 664 | } 665 | } 666 | 667 | void Geometry::SetColorMap( Renderer::Shader * _shader, const char * _name, const ColorMap & _colorMap ) 668 | { 669 | char sz[ 64 ]; 670 | 671 | snprintf( sz, 64, "%s.color", _name ); 672 | _shader->SetConstant( sz, _colorMap.mColor ); 673 | 674 | snprintf( sz, 64, "%s.has_tex", _name ); 675 | _shader->SetConstant( sz, _colorMap.mTexture != NULL ); 676 | 677 | if ( _colorMap.mTexture ) 678 | { 679 | snprintf( sz, 64, "%s.tex", _name ); 680 | _shader->SetTexture( sz, _colorMap.mTexture ); 681 | } 682 | 683 | } 684 | 685 | std::string Geometry::GetSupportedExtensions() 686 | { 687 | std::string out; 688 | gImporter.GetExtensionList( out ); 689 | 690 | for ( int i = 0; i < out.length(); i++ ) 691 | { 692 | if ( out[ i ] == '*' ) 693 | { 694 | out = out.substr( 0, i ) + out.substr( i + 1 ); 695 | i--; 696 | } 697 | else if ( out[ i ] == ';' ) 698 | { 699 | out[ i ] = ','; 700 | } 701 | } 702 | 703 | return out; 704 | } 705 | -------------------------------------------------------------------------------- /src/Geometry.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "Renderer.h" 6 | 7 | #define GLEW_NO_GLU 8 | #include "GL/glew.h" 9 | #ifdef _WIN32 10 | #include 11 | #endif 12 | 13 | class Geometry 14 | { 15 | public: 16 | struct Node 17 | { 18 | unsigned int mID; 19 | std::string mName; 20 | std::vector mMeshes; 21 | unsigned int mParentID; 22 | glm::mat4x4 mTransformation; 23 | }; 24 | struct Mesh 25 | { 26 | int mVertexCount; 27 | GLuint mVertexBufferObject; 28 | int mTriangleCount; 29 | GLuint mIndexBufferObject; 30 | int mMaterialIndex; 31 | GLuint mVertexArrayObject; 32 | 33 | glm::vec3 mAABBMin; 34 | glm::vec3 mAABBMax; 35 | 36 | bool mTransparent; 37 | }; 38 | struct ColorMap 39 | { 40 | ColorMap() : mValid( false ), mTexture( nullptr ), mColor( 0.0f ) {} 41 | bool mValid; 42 | Renderer::Texture * mTexture; 43 | glm::vec4 mColor; 44 | }; 45 | struct Material 46 | { 47 | std::string mName; 48 | ColorMap mColorMapDiffuse; 49 | ColorMap mColorMapNormals; 50 | ColorMap mColorMapSpecular; 51 | ColorMap mColorMapAlbedo; 52 | ColorMap mColorMapRoughness; 53 | ColorMap mColorMapMetallic; 54 | ColorMap mColorMapAO; 55 | ColorMap mColorMapAmbient; 56 | ColorMap mColorMapEmissive; 57 | 58 | float mSpecularShininess; 59 | }; 60 | 61 | Geometry(); 62 | ~Geometry(); 63 | 64 | bool LoadMesh( const char * _path ); 65 | void UnloadMesh(); 66 | 67 | void Render( const glm::mat4x4 & _worldRootMatrix, Renderer::Shader * _shader ); 68 | 69 | void __SetupVertexArray( Renderer::Shader * _shader, const char * name, int sizeInFloats, int & offsetInFloats); 70 | void RebindVertexArray( Renderer::Shader * _shader ); 71 | 72 | void SetColorMap( Renderer::Shader * _shader, const char * _name, const ColorMap & _colorMap ); 73 | 74 | static std::string GetSupportedExtensions(); 75 | 76 | std::map mNodes; 77 | std::map mMeshes; 78 | std::map mMaterials; 79 | std::vector mEmbeddedTextures; 80 | glm::mat4x4 * mMatrices; 81 | glm::vec3 mAABBMin; 82 | glm::vec3 mAABBMax; 83 | float mModelDiagonal; 84 | glm::vec4 mGlobalAmbient; 85 | }; -------------------------------------------------------------------------------- /src/Main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define _USE_MATH_DEFINES 3 | #include 4 | #include 5 | 6 | #include "Geometry.h" 7 | #include "SetupDialog.h" 8 | 9 | #define IMGUI_IMPL_OPENGL_LOADER_GLEW 10 | #include 11 | #include 12 | #include 13 | 14 | #include "ImGuiFileBrowser.h" 15 | 16 | #include "ext.hpp" 17 | #include "gtx/rotate_vector.hpp" 18 | 19 | #include 20 | 21 | Renderer::Shader * LoadShader( const char * vsPath, const char * fsPath ) 22 | { 23 | char vertexShader[ 16 * 1024 ] = { 0 }; 24 | FILE * fileVS = fopen( vsPath, "rb" ); 25 | if ( !fileVS ) 26 | { 27 | printf( "Vertex shader load failed: '%s'\n", vsPath ); 28 | return NULL; 29 | } 30 | fread( vertexShader, 1, 16 * 1024, fileVS ); 31 | fclose( fileVS ); 32 | 33 | char fragmentShader[ 16 * 1024 ] = { 0 }; 34 | FILE * fileFS = fopen( fsPath, "rb" ); 35 | if ( !fileFS ) 36 | { 37 | printf( "Fragment shader load failed: '%s'\n", fsPath ); 38 | return NULL; 39 | } 40 | fread( fragmentShader, 1, 16 * 1024, fileFS ); 41 | fclose( fileFS ); 42 | 43 | char error[ 4096 ]; 44 | Renderer::Shader * shader = Renderer::CreateShader( vertexShader, (int) strlen( vertexShader ), fragmentShader, (int) strlen( fragmentShader ), error, 4096 ); 45 | if ( !shader ) 46 | { 47 | printf( "Shader build failed: %s\n", error ); 48 | } 49 | 50 | return shader; 51 | } 52 | 53 | const jsonxx::Object * gCurrentSkyImageConfig = NULL; 54 | const jsonxx::Object * gCurrentShaderConfig = NULL; 55 | Renderer::Shader * gCurrentShader = NULL; 56 | bool LoadShaderConfig( const jsonxx::Object * _shader ) 57 | { 58 | Renderer::Shader * newShader = LoadShader( _shader->get( "vertexShader" ).c_str(), _shader->get( "fragmentShader" ).c_str() ); 59 | if ( !newShader ) 60 | { 61 | return false; 62 | } 63 | 64 | gCurrentShaderConfig = _shader; 65 | 66 | if ( gCurrentShader ) 67 | { 68 | Renderer::ReleaseShader( gCurrentShader ); 69 | delete gCurrentShader; 70 | } 71 | gCurrentShader = newShader; 72 | 73 | return true; 74 | } 75 | 76 | jsonxx::Object gOptions; 77 | 78 | glm::vec3 gCameraTarget( 0.0f, 0.0f, 0.0f ); 79 | float gCameraDistance = 500.0f; 80 | Geometry gModel; 81 | 82 | float gCameraYaw = glm::pi() / 4.0f; 83 | float gCameraPitch = 0.25f; 84 | float gLightYaw = 0.0f; 85 | float gLightPitch = 0.0f; 86 | float gSkysphereOpacity = 1.0f; 87 | float gSkysphereBlur = 0.0f; 88 | glm::vec4 gClearColor( 0.5f, 0.5f, 0.5f, 1.0f ); 89 | void LoadSkyImageConfig( const jsonxx::Object & obj ); 90 | 91 | void LoadMeshConfig( const char * path ) 92 | { 93 | FILE * configFile = fopen( path, "rb" ); 94 | if ( !configFile ) 95 | { 96 | return; 97 | } 98 | 99 | char meshconfigString[ 4096 ] = { 0 }; 100 | memset( meshconfigString, 0, 4096 ); 101 | fread( meshconfigString, 1, 4096, configFile ); 102 | fclose( configFile ); 103 | 104 | jsonxx::Object meshconfigRoot; 105 | if ( !meshconfigRoot.parse( meshconfigString ) ) 106 | { 107 | return; 108 | } 109 | if ( !meshconfigRoot.has( "config" ) ) 110 | { 111 | return; 112 | } 113 | 114 | const jsonxx::Object & meshconfig = meshconfigRoot.get( "config" ); 115 | if ( meshconfig.has( "shader" ) ) 116 | { 117 | const std::string & shaderName = meshconfig.get( "shader" ); 118 | const int shaderCount = gOptions.get( "shaders" ).size(); 119 | for ( int i = 0; i < shaderCount; i++ ) 120 | { 121 | const jsonxx::Object & shaderConfig = gOptions.get( "shaders" ).get( i ); 122 | if ( shaderConfig.get( "name" ) == shaderName ) 123 | { 124 | LoadShaderConfig( &shaderConfig ); 125 | gModel.RebindVertexArray( gCurrentShader ); 126 | break; 127 | } 128 | } 129 | } 130 | if ( meshconfig.has( "skyImage" ) ) 131 | { 132 | const std::string & skyImageName = meshconfig.get( "skyImage" ); 133 | const int skyImageCount = gOptions.get( "skyImages" ).size(); 134 | for ( int i = 0; i < skyImageCount; i++ ) 135 | { 136 | const jsonxx::Object & skyImageConfig = gOptions.get( "skyImages" ).get( i ); 137 | if ( skyImageConfig.get( "reflection" ) == skyImageName ) 138 | { 139 | LoadSkyImageConfig( skyImageConfig ); 140 | break; 141 | } 142 | } 143 | } 144 | if ( meshconfig.has( "cameraDistance" ) ) 145 | { 146 | gCameraDistance = (float) meshconfig.get( "cameraDistance" ); 147 | } 148 | if ( meshconfig.has( "cameraYaw" ) ) 149 | { 150 | gCameraYaw = (float) meshconfig.get( "cameraYaw" ); 151 | } 152 | if ( meshconfig.has( "cameraPitch" ) ) 153 | { 154 | gCameraPitch = (float) meshconfig.get( "cameraPitch" ); 155 | } 156 | if ( meshconfig.has( "lightYaw" ) ) 157 | { 158 | gLightYaw = (float) meshconfig.get( "lightYaw" ); 159 | } 160 | if ( meshconfig.has( "lightPitch" ) ) 161 | { 162 | gLightPitch = (float) meshconfig.get( "lightPitch" ); 163 | } 164 | if ( meshconfig.has( "skysphereOpacity" ) ) 165 | { 166 | gSkysphereOpacity = (float) meshconfig.get( "skysphereOpacity" ); 167 | } 168 | if ( meshconfig.has( "skysphereBlur" ) ) 169 | { 170 | gSkysphereBlur = (float) meshconfig.get( "skysphereBlur" ); 171 | } 172 | if ( meshconfig.has( "clearColor" ) ) 173 | { 174 | gClearColor.x = (float) meshconfig.get( "clearColor" ).get( 0 ); 175 | gClearColor.y = (float) meshconfig.get( "clearColor" ).get( 1 ); 176 | gClearColor.z = (float) meshconfig.get( "clearColor" ).get( 2 ); 177 | gClearColor.w = (float) meshconfig.get( "clearColor" ).get( 3 ); 178 | } 179 | if ( meshconfig.has( "cameraTarget" ) ) 180 | { 181 | gCameraTarget.x = (float) meshconfig.get( "cameraTarget" ).get( 0 ); 182 | gCameraTarget.y = (float) meshconfig.get( "cameraTarget" ).get( 1 ); 183 | gCameraTarget.z = (float) meshconfig.get( "cameraTarget" ).get( 2 ); 184 | } 185 | } 186 | 187 | void SaveMeshConfig( const char * path ) 188 | { 189 | FILE * configFile = fopen( path, "wb" ); 190 | if ( !configFile ) 191 | { 192 | printf( "Unable to write mesh config file '%s'\n", path ); 193 | return; 194 | } 195 | 196 | jsonxx::Object meshconfig; 197 | 198 | meshconfig << "shader" << gCurrentShaderConfig->get( "name" ); 199 | meshconfig << "skyImage" << gCurrentSkyImageConfig->get( "reflection" ); 200 | meshconfig << "cameraDistance" << gCameraDistance; 201 | meshconfig << "cameraYaw" << gCameraYaw; 202 | meshconfig << "cameraPitch" << gCameraPitch; 203 | meshconfig << "lightYaw" << gLightYaw; 204 | meshconfig << "lightPitch" << gLightPitch; 205 | meshconfig << "skysphereOpacity" << gSkysphereOpacity; 206 | meshconfig << "skysphereBlur" << gSkysphereBlur; 207 | 208 | jsonxx::Array clearColorArray; 209 | clearColorArray << gClearColor.x; 210 | clearColorArray << gClearColor.y; 211 | clearColorArray << gClearColor.z; 212 | clearColorArray << gClearColor.w; 213 | meshconfig << "clearColor" << clearColorArray; 214 | 215 | jsonxx::Array cameraTargetArray; 216 | cameraTargetArray << gCameraTarget.x; 217 | cameraTargetArray << gCameraTarget.y; 218 | cameraTargetArray << gCameraTarget.z; 219 | meshconfig << "cameraTarget" << cameraTargetArray; 220 | 221 | jsonxx::Object meshconfigRoot; 222 | meshconfigRoot << "config" << meshconfig; 223 | 224 | std::string meshconfigString = meshconfigRoot.json(); 225 | fwrite( meshconfigString.c_str(), 1, meshconfigString.length(), configFile ); 226 | fclose( configFile ); 227 | 228 | printf( "Saved mesh config file to '%s'\n", path ); 229 | } 230 | 231 | std::string gMeshPath; 232 | bool LoadMesh( const char * path ) 233 | { 234 | if ( !gModel.LoadMesh( path ) ) 235 | { 236 | return false; 237 | } 238 | 239 | gMeshPath = path; 240 | gModel.RebindVertexArray( gCurrentShader ); 241 | 242 | gCameraTarget = ( gModel.mAABBMin + gModel.mAABBMax ) / 2.0f; 243 | gCameraDistance = glm::length( gCameraTarget - gModel.mAABBMin ) * 4.0f; 244 | 245 | char meshConfigPath[ 512 ]; 246 | snprintf( meshConfigPath, 512, "%s.foxocfg", gMeshPath.c_str() ); 247 | LoadMeshConfig( meshConfigPath ); 248 | 249 | return true; 250 | } 251 | 252 | void ShowNodeInImGui( int _parentID ) 253 | { 254 | for ( std::map::iterator it = gModel.mNodes.begin(); it != gModel.mNodes.end(); it++ ) 255 | { 256 | if ( it->second.mParentID == _parentID ) 257 | { 258 | ImGui::Text( "%s", it->second.mName.c_str() ); 259 | ImGui::Indent(); 260 | for ( int i = 0; i < it->second.mMeshes.size(); i++ ) 261 | { 262 | const Geometry::Mesh & mesh = gModel.mMeshes[ it->second.mMeshes[ i ] ]; 263 | ImGui::TextColored( ImVec4( 1.0f, 0.5f, 1.0f, 1.0f ), "Mesh %d: %d vertices, %d triangles", i + 1, mesh.mVertexCount, mesh.mTriangleCount ); 264 | ImGui::SameLine(); 265 | ImGui::TextColored( ImVec4( 1.0f, 0.75f, 1.0f, 1.0f ), "Material: %s", gModel.mMaterials[ mesh.mMaterialIndex ].mName.c_str() ); 266 | } 267 | 268 | ShowNodeInImGui( it->second.mID ); 269 | ImGui::Unindent(); 270 | } 271 | } 272 | } 273 | 274 | void ShowColorMapInImGui( const char * _channel, Geometry::ColorMap & _colorMap ) 275 | { 276 | if ( !_colorMap.mValid ) 277 | { 278 | return; 279 | } 280 | 281 | if ( ImGui::BeginTabItem( _channel ) ) 282 | { 283 | ImGui::ColorEdit4( "Color", (float *) &_colorMap.mColor, ImGuiColorEditFlags_AlphaPreviewHalf ); 284 | if ( _colorMap.mTexture ) 285 | { 286 | ImGui::Text( "Texture: %s", _colorMap.mTexture->mFilename.c_str() ); 287 | ImGui::Text( "Is transparent: %s", _colorMap.mTexture->mTransparent ? "yes" : "no" ); 288 | ImGui::Text( "Is SRGB: %s", _colorMap.mTexture->mSRGB ? "yes" : "no" ); 289 | ImGui::Text( "Dimensions: %d x %d", _colorMap.mTexture->mWidth, _colorMap.mTexture->mHeight ); 290 | ImGui::Image( (void *) (intptr_t) _colorMap.mTexture->mGLTextureID, ImVec2( 512.0f, 512.0f ) ); 291 | } 292 | ImGui::EndTabItem(); 293 | } 294 | } 295 | 296 | Renderer::Texture* gBrdfLookupTable = NULL; 297 | 298 | void loadBrdfLookupTable() 299 | { 300 | const int width = 256; 301 | const int height = 256; 302 | const int comp = 2; 303 | const char* filename = "Skyboxes/brdf256.bin"; 304 | 305 | if ( gBrdfLookupTable ) 306 | { 307 | Renderer::ReleaseTexture( gBrdfLookupTable ); 308 | delete gBrdfLookupTable; 309 | gBrdfLookupTable = NULL; 310 | } 311 | 312 | gBrdfLookupTable = Renderer::CreateRG32FTextureFromRawFile( filename, width, height ); 313 | 314 | if ( !gBrdfLookupTable ) 315 | { 316 | printf( "Couldn't load %dx%d BRDF lookup table '%s'!\n", width, height, filename ); 317 | } 318 | } 319 | 320 | // Reads a single string value from an HDRLabs IBL file. 321 | // Returns an empty string on error. 322 | static std::string parseIblField( const char* szPath, const char* szTargetSection, const char* szTargetKey ) 323 | { 324 | FILE* fp = fopen( szPath, "r" ); 325 | if ( !fp ) return ""; 326 | 327 | char section[ 100 ] = { '\0' }; 328 | std::string found; 329 | 330 | while ( true ) 331 | { 332 | char key[ 100 ] = { '\0' }; 333 | char value[ 100 ] = { '\0' }; 334 | 335 | int sectionRead = fscanf( fp, "[%[^]]\n", section ); 336 | int keyValueRead = fscanf( fp, "%s = %s\n", key, value ); 337 | 338 | if ( sectionRead == EOF || keyValueRead == EOF ) 339 | { 340 | break; 341 | } 342 | 343 | if ( keyValueRead < 2 ) continue; 344 | 345 | if ( !strncmp( section, szTargetSection, sizeof( section ) ) && !strncmp( key, szTargetKey, sizeof( key ) ) ) 346 | { 347 | found = value; 348 | break; 349 | } 350 | } 351 | 352 | fclose( fp ); 353 | return found; 354 | } 355 | 356 | struct SkyImages 357 | { 358 | Renderer::Texture* reflection = NULL; 359 | Renderer::Texture* env = NULL; 360 | float sunYaw = 0.f; 361 | float sunPitch = 0.f; 362 | glm::vec3 sunColor{ 1.f, 1.f, 1.f }; 363 | }; 364 | SkyImages gCurrentSkyImage; 365 | 366 | void LoadSkyImageConfig( const jsonxx::Object & obj ) 367 | { 368 | gCurrentSkyImageConfig = &obj; 369 | 370 | const char* reflectionPath = obj.get( "reflection" ).c_str(); 371 | 372 | // Reflection map 373 | 374 | if ( gCurrentSkyImage.reflection ) 375 | { 376 | Renderer::ReleaseTexture( gCurrentSkyImage.reflection ); 377 | gCurrentSkyImage.reflection = NULL; 378 | } 379 | gCurrentSkyImage.reflection = Renderer::CreateRGBA8TextureFromFile( reflectionPath ); 380 | 381 | if ( gCurrentSkyImage.reflection ) 382 | { 383 | glBindTexture( GL_TEXTURE_2D, gCurrentSkyImage.reflection->mGLTextureID ); 384 | 385 | glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); 386 | glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); 387 | } 388 | 389 | if ( gCurrentSkyImage.env ) 390 | { 391 | Renderer::ReleaseTexture( gCurrentSkyImage.env ); 392 | gCurrentSkyImage.env = NULL; 393 | } 394 | 395 | // Irradiance map 396 | 397 | if ( obj.has( "env" ) ) 398 | { 399 | const char* envPath = obj.get( "env" ).c_str(); 400 | gCurrentSkyImage.env = Renderer::CreateRGBA8TextureFromFile( envPath ); 401 | 402 | if ( gCurrentSkyImage.env ) 403 | { 404 | glBindTexture( GL_TEXTURE_2D, gCurrentSkyImage.env->mGLTextureID ); 405 | 406 | glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); 407 | glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); 408 | } 409 | else 410 | { 411 | printf( "Couldn't load environment map '%s'!\n", envPath ); 412 | } 413 | } 414 | 415 | // Sun direction 416 | 417 | if ( obj.has( "metadata" ) ) 418 | { 419 | const char* iblPath = obj.get( "metadata" ).c_str(); 420 | glm::vec2 uv( 421 | atof( parseIblField( iblPath, "Sun", "SUNu" ).c_str() ), 422 | atof( parseIblField( iblPath, "Sun", "SUNv" ).c_str() ) ); 423 | 424 | if ( uv != glm::vec2( 0.f, 0.f ) ) 425 | { 426 | gCurrentSkyImage.sunYaw = M_PI * (-2. * uv.x + 0.5f); 427 | gCurrentSkyImage.sunPitch = (.5f - uv.y) * M_PI; 428 | } 429 | } 430 | } 431 | 432 | int main( int argc, const char * argv[] ) 433 | { 434 | FILE * configFile = fopen( "config.json", "rb" ); 435 | if ( !configFile ) 436 | { 437 | printf( "Config file not found!\n" ); 438 | return -10; 439 | } 440 | 441 | char configData[ 4096 ]; 442 | memset( configData, 0, 4096 ); 443 | fread( configData, 1, 4096, configFile ); 444 | fclose( configFile ); 445 | 446 | gOptions.parse( configData ); 447 | if ( !gOptions.has( "shaders" ) || !gOptions.has( "skyImages" ) ) 448 | { 449 | printf( "Config file broken!\n" ); 450 | return -11; 451 | } 452 | 453 | ////////////////////////////////////////////////////////////////////////// 454 | // Init renderer 455 | RENDERER_SETTINGS settings; 456 | settings.mVsync = false; 457 | settings.mWidth = 1280; 458 | settings.mHeight = 720; 459 | settings.mWindowMode = RENDERER_WINDOWMODE_WINDOWED; 460 | settings.mMultisampling = false; 461 | #ifndef _DEBUG 462 | settings.mWidth = 1920; // TODO maybe replace this with actual screen size? 463 | settings.mHeight = 1080; 464 | settings.mWindowMode = RENDERER_WINDOWMODE_FULLSCREEN; 465 | settings.mMultisampling = true; 466 | if ( !SetupDialog::Open( &settings ) ) 467 | { 468 | return -14; 469 | } 470 | #endif 471 | 472 | if ( !Renderer::Open( &settings ) ) 473 | { 474 | printf( "Renderer::Open failed\n" ); 475 | return -1; 476 | } 477 | 478 | ////////////////////////////////////////////////////////////////////////// 479 | // Start up ImGui 480 | IMGUI_CHECKVERSION(); 481 | ImGui::CreateContext(); 482 | ImGuiIO & io = ImGui::GetIO(); 483 | 484 | ImGui::StyleColorsDark(); 485 | 486 | ImGui_ImplGlfw_InitForOpenGL( Renderer::mWindow, true ); 487 | ImGui_ImplOpenGL3_Init(); 488 | 489 | imgui_addons::ImGuiFileBrowser file_dialog; 490 | 491 | ////////////////////////////////////////////////////////////////////////// 492 | // Bootstrap 493 | if ( !LoadShaderConfig( &gOptions.get( "shaders" ).get( 0 ) ) ) 494 | { 495 | return -4; 496 | } 497 | 498 | auto firstSkyImageConfig = gOptions.get( "skyImages" ).get( 0 ); 499 | LoadSkyImageConfig( firstSkyImageConfig ); 500 | gLightYaw = gCurrentSkyImage.sunYaw; 501 | gLightPitch = gCurrentSkyImage.sunPitch; 502 | 503 | if ( argc >= 2 ) 504 | { 505 | LoadMesh( argv[ 1 ] ); 506 | } 507 | 508 | ////////////////////////////////////////////////////////////////////////// 509 | // Mainloop 510 | bool appWantsToQuit = false; 511 | bool automaticCamera = false; 512 | uint32_t frameCount = 0; 513 | glm::mat4x4 viewMatrix; 514 | glm::mat4x4 projectionMatrix; 515 | bool rotatingCamera = false; 516 | bool movingCamera = false; 517 | bool movingLight = false; 518 | float mouseClickPosX = 0.0f; 519 | float mouseClickPosY = 0.0f; 520 | std::string supportedExtensions = Geometry::GetSupportedExtensions(); 521 | float exposure = 1.0f; 522 | bool showImGui = true; 523 | bool edgedFaces = false; 524 | float hideCursorTimer = 0.0f; 525 | bool showModelInfo = false; 526 | bool xzySpace = false; 527 | const glm::mat4x4 xzyMatrix( 528 | 1.0f, 0.0f, 0.0f, 0.0f, 529 | 0.0f, 0.0f, 1.0f, 0.0f, 530 | 0.0f,-1.0f, 0.0f, 0.0f, 531 | 0.0f, 0.0f, 0.0f, 1.0f ); 532 | 533 | loadBrdfLookupTable(); 534 | 535 | Geometry skysphere; 536 | skysphere.LoadMesh( "Skyboxes/skysphere.fbx" ); 537 | 538 | Renderer::Shader * skysphereShader = LoadShader( "Skyboxes/skysphere.vs", "Skyboxes/skysphere.fs" ); 539 | if ( !skysphereShader ) 540 | { 541 | return -8; 542 | } 543 | skysphere.RebindVertexArray( skysphereShader ); 544 | 545 | while ( !Renderer::WantsToQuit() && !appWantsToQuit ) 546 | { 547 | Renderer::StartFrame( gClearColor ); 548 | 549 | ////////////////////////////////////////////////////////////////////////// 550 | // ImGui windows etc. 551 | ImGui_ImplOpenGL3_NewFrame(); 552 | ImGui_ImplGlfw_NewFrame(); 553 | ImGui::NewFrame(); 554 | 555 | bool openFileDialog = false; 556 | bool reloadMeshConfig = false; 557 | bool saveMeshConfig = false; 558 | 559 | ImGui::SetMouseCursor( hideCursorTimer <= 5.0f ? ImGuiMouseCursor_Arrow : ImGuiMouseCursor_None ); 560 | 561 | if ( ImGui::IsKeyPressed( GLFW_KEY_F, false ) ) 562 | { 563 | gCameraTarget = ( gModel.mAABBMin + gModel.mAABBMax ) / 2.0f; 564 | gCameraDistance = glm::length( gCameraTarget - gModel.mAABBMin ) * 4.0f; 565 | gCameraYaw = glm::pi() / 4.0f; 566 | gCameraPitch = 0.25f; 567 | } 568 | if ( ImGui::IsKeyPressed( GLFW_KEY_F11, false ) ) 569 | { 570 | showImGui = !showImGui; 571 | } 572 | if ( ImGui::IsKeyPressed( GLFW_KEY_W, false ) ) 573 | { 574 | edgedFaces = !edgedFaces; 575 | } 576 | if ( ImGui::IsKeyPressed( GLFW_KEY_C, false ) ) 577 | { 578 | automaticCamera = !automaticCamera; 579 | } 580 | if ( ImGui::IsKeyPressed( GLFW_KEY_O, false ) && ( ImGui::IsKeyDown( GLFW_KEY_LEFT_CONTROL ) || ImGui::IsKeyDown( GLFW_KEY_RIGHT_CONTROL ) ) ) 581 | { 582 | openFileDialog = true; 583 | } 584 | if ( ImGui::IsKeyPressed( GLFW_KEY_S, false ) && ( ImGui::IsKeyDown( GLFW_KEY_LEFT_CONTROL ) || ImGui::IsKeyDown( GLFW_KEY_RIGHT_CONTROL ) ) ) 585 | { 586 | saveMeshConfig = true; 587 | } 588 | if ( ImGui::IsKeyPressed( GLFW_KEY_L, false ) && ( ImGui::IsKeyDown( GLFW_KEY_LEFT_CONTROL ) || ImGui::IsKeyDown( GLFW_KEY_RIGHT_CONTROL ) ) ) 589 | { 590 | reloadMeshConfig = true; 591 | } 592 | if ( ImGui::IsKeyPressed( GLFW_KEY_ENTER, false ) && ( ImGui::IsKeyDown( GLFW_KEY_LEFT_ALT ) || ImGui::IsKeyDown( GLFW_KEY_RIGHT_ALT ) ) ) 593 | { 594 | Renderer::SwitchFullscreen( Renderer::eMode == RENDERER_WINDOWMODE_WINDOWED ? RENDERER_WINDOWMODE_FULLSCREEN : RENDERER_WINDOWMODE_WINDOWED ); 595 | } 596 | if ( ImGui::IsKeyPressed( GLFW_KEY_PAGE_UP, false ) ) 597 | { 598 | const int shaderCount = gOptions.get( "shaders" ).size(); 599 | for ( int i = 0; i < shaderCount; i++ ) 600 | { 601 | const jsonxx::Object & shaderConfig = gOptions.get( "shaders" ).get( i ); 602 | if ( &shaderConfig == gCurrentShaderConfig ) 603 | { 604 | const jsonxx::Object & newShaderConfig = gOptions.get( "shaders" ).get( ( i - 1 + shaderCount ) % shaderCount ); 605 | LoadShaderConfig( &newShaderConfig ); 606 | gModel.RebindVertexArray( gCurrentShader ); 607 | break; 608 | } 609 | } 610 | } 611 | if ( ImGui::IsKeyPressed( GLFW_KEY_PAGE_DOWN, false ) ) 612 | { 613 | const int shaderCount = gOptions.get( "shaders" ).size(); 614 | for ( int i = 0; i < shaderCount; i++ ) 615 | { 616 | const jsonxx::Object & shaderConfig = gOptions.get( "shaders" ).get( i ); 617 | if ( &shaderConfig == gCurrentShaderConfig ) 618 | { 619 | const jsonxx::Object & newShaderConfig = gOptions.get( "shaders" ).get( ( i + 1 + shaderCount ) % shaderCount ); 620 | LoadShaderConfig( &newShaderConfig ); 621 | gModel.RebindVertexArray( gCurrentShader ); 622 | break; 623 | } 624 | } 625 | } 626 | 627 | if ( showImGui ) 628 | { 629 | if ( ImGui::BeginMainMenuBar() ) 630 | { 631 | if ( ImGui::BeginMenu( "File" ) ) 632 | { 633 | if ( ImGui::MenuItem( "Open model...", "Ctrl-O" ) ) 634 | { 635 | openFileDialog = true; 636 | } 637 | ImGui::Separator(); 638 | if ( ImGui::MenuItem( "Reload model config", "Ctrl-L" ) ) 639 | { 640 | reloadMeshConfig = true; 641 | } 642 | if ( ImGui::MenuItem( "Save model config", "Ctrl-S" ) ) 643 | { 644 | saveMeshConfig = true; 645 | } 646 | ImGui::Separator(); 647 | if ( ImGui::MenuItem( "Exit", "Alt-F4" ) ) 648 | { 649 | appWantsToQuit = true; 650 | } 651 | ImGui::EndMenu(); 652 | } 653 | if ( ImGui::BeginMenu( "Model" ) ) 654 | { 655 | ImGui::MenuItem( "Show model info", NULL, &showModelInfo ); 656 | ImGui::Separator(); 657 | 658 | bool xyzSpace = !xzySpace; 659 | if ( ImGui::MenuItem( "XYZ space", NULL, &xyzSpace ) ) 660 | { 661 | xzySpace = !xzySpace; 662 | } 663 | ImGui::MenuItem( "XZY space", NULL, &xzySpace ); 664 | ImGui::EndMenu(); 665 | } 666 | if ( ImGui::BeginMenu( "View" ) ) 667 | { 668 | if ( ImGui::MenuItem( "Windowed", "Alt-Enter", Renderer::eMode == RENDERER_WINDOWMODE_WINDOWED ) ) 669 | { 670 | Renderer::SwitchFullscreen( RENDERER_WINDOWMODE_WINDOWED ); 671 | } 672 | if ( ImGui::MenuItem( "Fullscreen", "Alt-Enter", Renderer::eMode == RENDERER_WINDOWMODE_FULLSCREEN ) ) 673 | { 674 | Renderer::SwitchFullscreen( RENDERER_WINDOWMODE_FULLSCREEN ); 675 | } 676 | ImGui::Separator(); 677 | 678 | ImGui::MenuItem( "Wireframe / Edged faces", "W", &edgedFaces ); 679 | ImGui::MenuItem( "Show menu", "F11", &showImGui ); 680 | ImGui::Separator(); 681 | 682 | ImGui::MenuItem( "Enable idle camera", "C", &automaticCamera ); 683 | if ( ImGui::MenuItem( "Re-center camera", "F" ) ) 684 | { 685 | gCameraTarget = ( gModel.mAABBMin + gModel.mAABBMax ) / 2.0f; 686 | gCameraDistance = glm::length( gCameraTarget - gModel.mAABBMin ) * 4.0f; 687 | gCameraYaw = glm::pi() / 4.0f; 688 | gCameraPitch = 0.25f; 689 | } 690 | ImGui::Separator(); 691 | 692 | ImGui::ColorEdit4( "Background", (float *) &gClearColor, ImGuiColorEditFlags_AlphaPreviewHalf ); 693 | ImGui::Separator(); 694 | 695 | ImGui::DragFloat( "Environment exposure", &exposure, 0.01f, 0.1f, 4.0f ); 696 | ImGui::DragFloat( "Sky blur", &gSkysphereBlur, 0.01f, 0.0f, 1.0f ); 697 | ImGui::DragFloat( "Sky opacity", &gSkysphereOpacity, 0.02f, 0.0f, 1.0f ); 698 | #ifdef _DEBUG 699 | ImGui::Separator(); 700 | ImGui::DragFloat( "Camera Yaw", &gCameraYaw, 0.01f ); 701 | ImGui::DragFloat( "Camera Pitch", &gCameraPitch, 0.01f ); 702 | ImGui::DragFloat3( "Camera Target", (float *) &gCameraTarget ); 703 | ImGui::DragFloat( "Light Yaw", &gLightYaw, 0.01f ); 704 | ImGui::DragFloat( "Light Pitch", &gLightPitch, 0.01f ); 705 | #endif 706 | ImGui::EndMenu(); 707 | } 708 | if ( ImGui::BeginMenu( "Shaders" ) ) 709 | { 710 | for ( int i = 0; i < gOptions.get( "shaders" ).size(); i++ ) 711 | { 712 | const jsonxx::Object & shaderConfig = gOptions.get( "shaders" ).get( i ); 713 | const std::string & name = gOptions.get( "shaders" ).get( i ).get( "name" ); 714 | 715 | bool selected = &shaderConfig == gCurrentShaderConfig; 716 | if ( ImGui::MenuItem( name.c_str(), NULL, &selected ) ) 717 | { 718 | LoadShaderConfig( &shaderConfig ); 719 | gModel.RebindVertexArray( gCurrentShader ); 720 | } 721 | } 722 | if ( gCurrentShaderConfig && gCurrentShaderConfig->get( "showSkybox" ) ) 723 | { 724 | ImGui::Separator(); 725 | for ( int i = 0; i < gOptions.get( "skyImages" ).size(); i++ ) 726 | { 727 | const auto & images = gOptions.get( "skyImages" ).get( i ); 728 | const std::string & filename = images.get( "reflection" ); 729 | 730 | bool selected = ( gCurrentSkyImage.reflection && gCurrentSkyImage.reflection->mFilename == filename ); 731 | if ( ImGui::MenuItem( filename.c_str(), NULL, &selected ) ) 732 | { 733 | LoadSkyImageConfig( images ); 734 | gLightYaw = gCurrentSkyImage.sunYaw; 735 | gLightPitch = gCurrentSkyImage.sunPitch; 736 | } 737 | } 738 | } 739 | ImGui::EndMenu(); 740 | } 741 | 742 | ImGui::EndMainMenuBar(); 743 | } 744 | } 745 | 746 | if ( openFileDialog ) 747 | { 748 | ImGui::OpenPopup( "Open model" ); 749 | } 750 | if ( reloadMeshConfig ) 751 | { 752 | char meshConfigPath[ 512 ]; 753 | snprintf( meshConfigPath, 512, "%s.foxocfg", gMeshPath.c_str() ); 754 | LoadMeshConfig( meshConfigPath ); 755 | } 756 | if ( saveMeshConfig ) 757 | { 758 | char meshConfigPath[ 512 ]; 759 | snprintf( meshConfigPath, 512, "%s.foxocfg", gMeshPath.c_str() ); 760 | SaveMeshConfig( meshConfigPath ); 761 | } 762 | 763 | if ( file_dialog.showFileDialog( "Open model", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, ImVec2( 700, 310 ), supportedExtensions.c_str() ) ) 764 | { 765 | LoadMesh( file_dialog.selected_path.c_str() ); 766 | } 767 | 768 | if ( showModelInfo ) 769 | { 770 | ImGui::Begin( "Model info", &showModelInfo ); 771 | ImGui::BeginTabBar( "model" ); 772 | if ( ImGui::BeginTabItem( "Summary" ) ) 773 | { 774 | int triCount = 0; 775 | for ( std::map::iterator it = gModel.mMeshes.begin(); it != gModel.mMeshes.end(); it++ ) 776 | { 777 | triCount += it->second.mTriangleCount; 778 | } 779 | 780 | ImGui::Text( "Triangle count: %d", triCount ); 781 | ImGui::Text( "Mesh count: %d", gModel.mMeshes.size() ); 782 | 783 | ImGui::EndTabItem(); 784 | } 785 | if ( ImGui::BeginTabItem( "Node tree" ) ) 786 | { 787 | ShowNodeInImGui( -1 ); 788 | 789 | ImGui::EndTabItem(); 790 | } 791 | if ( ImGui::BeginTabItem( "Textures / Materials" ) ) 792 | { 793 | ImGui::Text( "Material count: %d", gModel.mMaterials.size() ); 794 | 795 | for ( std::map::iterator it = gModel.mMaterials.begin(); it != gModel.mMaterials.end(); it++ ) 796 | { 797 | if ( ImGui::CollapsingHeader( it->second.mName.c_str() ) ) 798 | { 799 | ImGui::Indent(); 800 | ImGui::Text( "Specular shininess: %g", it->second.mSpecularShininess ); 801 | if ( ImGui::BeginTabBar( it->second.mName.c_str() ) ) 802 | { 803 | ShowColorMapInImGui( "Ambient", it->second.mColorMapAmbient ); 804 | ShowColorMapInImGui( "Diffuse", it->second.mColorMapDiffuse ); 805 | ShowColorMapInImGui( "Normals", it->second.mColorMapNormals ); 806 | ShowColorMapInImGui( "Specular", it->second.mColorMapSpecular ); 807 | ShowColorMapInImGui( "Albedo", it->second.mColorMapAlbedo ); 808 | ShowColorMapInImGui( "Metallic", it->second.mColorMapMetallic ); 809 | ShowColorMapInImGui( "Roughness", it->second.mColorMapRoughness ); 810 | ShowColorMapInImGui( "AO", it->second.mColorMapAO ); 811 | ShowColorMapInImGui( "Emissive", it->second.mColorMapEmissive ); 812 | ImGui::EndTabBar(); 813 | } 814 | ImGui::Unindent(); 815 | } 816 | } 817 | 818 | ImGui::EndTabItem(); 819 | } 820 | ImGui::EndTabBar(); 821 | ImGui::End(); 822 | } 823 | 824 | bool showHelpText = ( gModel.mNodes.size() == 0 ); 825 | if ( showHelpText ) 826 | { 827 | ImGui::SetNextWindowPos( ImVec2( io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f ), ImGuiCond_Appearing, ImVec2( 0.5f, 0.5f ) ); 828 | ImGui::SetNextWindowSize( ImVec2( 380.0f, 190.0f ) ); 829 | ImGui::SetNextWindowBgAlpha( 0.5f ); 830 | 831 | ImGui::Begin( "HelpText", &showHelpText, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove ); 832 | ImGui::TextColored( ImColor( 255, 127, 0 ), "Welcome to FOXOTRON!" ); 833 | ImGui::NewLine(); 834 | ImGui::Text( "To load a model:" ); 835 | ImGui::BulletText( "Use File > Open in the menu in the top left" ); 836 | ImGui::BulletText( "Or drag'n'drop a model here" ); 837 | ImGui::NewLine(); 838 | ImGui::Text( "Once a model is loaded:" ); 839 | ImGui::BulletText( "Left mouse button to rotate" ); 840 | ImGui::BulletText( "Right mouse button to move light / rotate sky" ); 841 | ImGui::BulletText( "Middle mouse button to pan camera" ); 842 | ImGui::End(); 843 | } 844 | 845 | ////////////////////////////////////////////////////////////////////////// 846 | // Drag'n'drop 847 | 848 | for ( int i = 0; i < Renderer::dropEventBufferCount; i++ ) 849 | { 850 | std::string & path = Renderer::dropEventBuffer[ i ]; 851 | LoadMesh( path.c_str() ); 852 | } 853 | Renderer::dropEventBufferCount = 0; 854 | 855 | ////////////////////////////////////////////////////////////////////////// 856 | // Mouse rotation 857 | 858 | if ( !io.WantCaptureMouse ) 859 | { 860 | ImVec2 mouseEvent = ImGui::GetMousePos(); 861 | 862 | if ( ImGui::IsMouseClicked( ImGuiMouseButton_Left ) ) 863 | { 864 | rotatingCamera = true; 865 | automaticCamera = false; 866 | mouseClickPosX = mouseEvent.x; 867 | mouseClickPosY = mouseEvent.y; 868 | } 869 | if ( !ImGui::IsMouseDown( ImGuiMouseButton_Left ) ) 870 | { 871 | rotatingCamera = false; 872 | } 873 | 874 | if ( ImGui::IsMouseClicked( ImGuiMouseButton_Right ) ) 875 | { 876 | movingLight = true; 877 | mouseClickPosX = mouseEvent.x; 878 | mouseClickPosY = mouseEvent.y; 879 | } 880 | if ( !ImGui::IsMouseDown( ImGuiMouseButton_Right ) ) 881 | { 882 | movingLight = false; 883 | } 884 | 885 | if ( ImGui::IsMouseClicked( ImGuiMouseButton_Middle ) ) 886 | { 887 | movingCamera = true; 888 | mouseClickPosX = mouseEvent.x; 889 | mouseClickPosY = mouseEvent.y; 890 | } 891 | if ( !ImGui::IsMouseDown( ImGuiMouseButton_Middle ) ) 892 | { 893 | movingCamera = false; 894 | } 895 | 896 | const float panSpeed = 1000.0f; 897 | const float rotationSpeed = 130.0f; 898 | if ( rotatingCamera ) 899 | { 900 | gCameraYaw -= ( mouseEvent.x - mouseClickPosX ) / rotationSpeed; 901 | gCameraPitch += ( mouseEvent.y - mouseClickPosY ) / rotationSpeed; 902 | 903 | // Clamp to avoid gimbal lock 904 | gCameraPitch = std::min( gCameraPitch, 1.5f ); 905 | gCameraPitch = std::max( gCameraPitch, -1.5f ); 906 | 907 | mouseClickPosX = mouseEvent.x; 908 | mouseClickPosY = mouseEvent.y; 909 | } 910 | if ( movingLight ) 911 | { 912 | gLightYaw += ( mouseEvent.x - mouseClickPosX ) / rotationSpeed; 913 | gLightPitch -= ( mouseEvent.y - mouseClickPosY ) / rotationSpeed; 914 | 915 | // Clamp to avoid gimbal lock 916 | gLightPitch = std::min( gLightPitch, 1.5f ); 917 | gLightPitch = std::max( gLightPitch, -1.5f ); 918 | 919 | mouseClickPosX = mouseEvent.x; 920 | mouseClickPosY = mouseEvent.y; 921 | } 922 | if ( movingCamera ) 923 | { 924 | const float moveX = ( mouseEvent.x - mouseClickPosX ) / panSpeed; 925 | const float moveY = ( mouseEvent.y - mouseClickPosY ) / panSpeed; 926 | 927 | glm::vec3 newBaseZ( 0.0f, 0.0f, -1.0f ); 928 | newBaseZ = glm::rotateX( newBaseZ, gCameraPitch ); 929 | newBaseZ = glm::rotateY( newBaseZ, gCameraYaw ); 930 | newBaseZ = -newBaseZ; 931 | 932 | glm::vec3 up( 0.0f, 1.0f, 0.0f ); 933 | glm::vec3 newBaseX = glm::cross( up, newBaseZ ); 934 | glm::vec3 newBaseY = glm::cross( newBaseZ, newBaseX ); 935 | 936 | gCameraTarget += newBaseX * moveX * gCameraDistance; 937 | gCameraTarget += newBaseY * moveY * gCameraDistance; 938 | 939 | mouseClickPosX = mouseEvent.x; 940 | mouseClickPosY = mouseEvent.y; 941 | } 942 | if ( io.MouseWheel != 0.0f ) 943 | { 944 | const float aspect = 1.1f; 945 | gCameraDistance *= io.MouseWheel < 0 ? aspect : 1 / aspect; 946 | } 947 | 948 | if ( io.MouseDelta.x != 0.0f && io.MouseDelta.y != 0.0f ) 949 | { 950 | hideCursorTimer = 0.0f; 951 | } 952 | } 953 | else 954 | { 955 | hideCursorTimer = 0.0f; 956 | } 957 | hideCursorTimer += io.DeltaTime; 958 | 959 | ImGui::Render(); 960 | 961 | ////////////////////////////////////////////////////////////////////////// 962 | // Camera and lights 963 | 964 | if ( automaticCamera ) 965 | { 966 | gCameraYaw += io.DeltaTime * 0.3f; 967 | } 968 | 969 | ////////////////////////////////////////////////////////////////////////// 970 | // Skysphere render 971 | 972 | glm::vec3 cameraPosition( 0.0f, 0.0f, -1.0f ); 973 | cameraPosition = glm::rotateX( cameraPosition, gCameraPitch ); 974 | cameraPosition = glm::rotateY( cameraPosition, gCameraYaw ); 975 | 976 | static glm::mat4x4 worldRootXYZ( 1.0f ); 977 | if ( gCurrentShaderConfig->get( "showSkybox" ) ) 978 | { 979 | float verticalFovInRadian = 0.5f; 980 | projectionMatrix = glm::perspective( verticalFovInRadian, settings.mWidth / (float) settings.mHeight, 0.001f, 2.0f ); 981 | skysphereShader->SetConstant( "mat_projection", projectionMatrix ); 982 | 983 | viewMatrix = glm::lookAtRH( cameraPosition * 0.15f, glm::vec3( 0.0f, 0.0f, 0.0f ), glm::vec3( 0.0f, 1.0f, 0.0f ) ); 984 | skysphereShader->SetConstant( "mat_view", viewMatrix ); 985 | 986 | skysphereShader->SetConstant( "has_tex_skysphere", gCurrentSkyImage.reflection != NULL ); 987 | skysphereShader->SetConstant( "has_tex_skyenv", gCurrentSkyImage.env != NULL ); 988 | 989 | if ( gCurrentSkyImage.reflection ) 990 | { 991 | const float mipCount = floor( log2( gCurrentSkyImage.reflection->mHeight ) ); 992 | skysphereShader->SetTexture( "tex_skysphere", gCurrentSkyImage.reflection ); 993 | skysphereShader->SetConstant( "skysphere_mip_count", mipCount ); 994 | } 995 | 996 | if ( gCurrentSkyImage.env ) 997 | { 998 | skysphereShader->SetTexture( "tex_skyenv", gCurrentSkyImage.env ); 999 | } 1000 | 1001 | skysphereShader->SetConstant( "background_color", gClearColor ); 1002 | skysphereShader->SetConstant( "skysphere_blur", gSkysphereBlur ); 1003 | skysphereShader->SetConstant( "skysphere_opacity", gSkysphereOpacity ); 1004 | skysphereShader->SetConstant( "skysphere_rotation", gLightYaw - gCurrentSkyImage.sunYaw ); 1005 | skysphereShader->SetConstant( "exposure", exposure ); 1006 | skysphereShader->SetConstant( "frame_count", frameCount ); 1007 | 1008 | skysphere.Render( worldRootXYZ, skysphereShader ); 1009 | 1010 | glClear( GL_DEPTH_BUFFER_BIT ); 1011 | } 1012 | 1013 | ////////////////////////////////////////////////////////////////////////// 1014 | // Mesh render 1015 | 1016 | const float verticalFovInRadian = 0.5f; 1017 | const float nearPlane = std::max( gModel.mModelDiagonal / 10000.0f, gCameraDistance / 1000.0f ); 1018 | const float farPlane = std::max( gModel.mModelDiagonal, gCameraDistance + gModel.mModelDiagonal ); 1019 | projectionMatrix = glm::perspective( verticalFovInRadian, settings.mWidth / (float) settings.mHeight, nearPlane, farPlane ); 1020 | gCurrentShader->SetConstant( "mat_projection", projectionMatrix ); 1021 | 1022 | cameraPosition *= gCameraDistance; 1023 | gCurrentShader->SetConstant( "camera_position", cameraPosition ); 1024 | 1025 | glm::vec3 lightDirection( 0.0f, 0.0f, 1.0f ); 1026 | lightDirection = glm::rotateX( lightDirection, gLightPitch ); 1027 | lightDirection = glm::rotateY( lightDirection, gLightYaw ); 1028 | 1029 | glm::vec3 fillLightDirection( 0.0f, 0.0f, 1.0f ); 1030 | fillLightDirection = glm::rotateX( fillLightDirection, gLightPitch - 0.4f ); 1031 | fillLightDirection = glm::rotateY( fillLightDirection, gLightYaw + 0.8f ); 1032 | 1033 | gCurrentShader->SetConstant( "lights[0].direction", lightDirection ); 1034 | gCurrentShader->SetConstant( "lights[0].color", gCurrentSkyImage.sunColor ); 1035 | gCurrentShader->SetConstant( "lights[1].direction", fillLightDirection ); 1036 | gCurrentShader->SetConstant( "lights[1].color", glm::vec3( 0.5f ) ); 1037 | gCurrentShader->SetConstant( "lights[2].direction", -fillLightDirection ); 1038 | gCurrentShader->SetConstant( "lights[2].color", glm::vec3( 0.25f ) ); 1039 | 1040 | gCurrentShader->SetConstant( "skysphere_rotation", gLightYaw - gCurrentSkyImage.sunYaw ); 1041 | 1042 | viewMatrix = glm::lookAtRH( cameraPosition + gCameraTarget, gCameraTarget, glm::vec3( 0.0f, 1.0f, 0.0f ) ); 1043 | gCurrentShader->SetConstant( "mat_view", viewMatrix ); 1044 | gCurrentShader->SetConstant( "mat_view_inverse", glm::inverse( viewMatrix ) ); 1045 | 1046 | gCurrentShader->SetConstant( "has_tex_skysphere", gCurrentSkyImage.reflection != NULL ); 1047 | gCurrentShader->SetConstant( "has_tex_skyenv", gCurrentSkyImage.env != NULL ); 1048 | if ( gCurrentSkyImage.reflection ) 1049 | { 1050 | float mipCount = floor( log2( gCurrentSkyImage.reflection->mHeight ) ); 1051 | gCurrentShader->SetTexture( "tex_skysphere", gCurrentSkyImage.reflection ); 1052 | gCurrentShader->SetConstant( "skysphere_mip_count", mipCount ); 1053 | } 1054 | if ( gCurrentSkyImage.env ) 1055 | { 1056 | gCurrentShader->SetTexture( "tex_skyenv", gCurrentSkyImage.env ); 1057 | } 1058 | gCurrentShader->SetTexture( "tex_brdf_lut", gBrdfLookupTable ); 1059 | gCurrentShader->SetConstant( "exposure", exposure ); 1060 | gCurrentShader->SetConstant( "frame_count", frameCount ); 1061 | 1062 | ////////////////////////////////////////////////////////////////////////// 1063 | // Mesh render 1064 | 1065 | gModel.Render( xzySpace ? xzyMatrix : worldRootXYZ, gCurrentShader ); 1066 | 1067 | if ( edgedFaces ) 1068 | { 1069 | glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); 1070 | glDepthFunc( GL_LEQUAL ); 1071 | 1072 | gCurrentShader->SetConstant( "exposure", 100.0f ); 1073 | gModel.Render( xzySpace ? xzyMatrix : worldRootXYZ, gCurrentShader ); 1074 | 1075 | glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); 1076 | glDepthFunc( GL_LESS ); 1077 | } 1078 | 1079 | ////////////////////////////////////////////////////////////////////////// 1080 | // End frame 1081 | ImGui_ImplOpenGL3_RenderDrawData( ImGui::GetDrawData() ); 1082 | Renderer::EndFrame(); 1083 | frameCount++; 1084 | } 1085 | 1086 | ////////////////////////////////////////////////////////////////////////// 1087 | // Cleanup 1088 | 1089 | if ( gCurrentShader ) 1090 | { 1091 | Renderer::ReleaseShader( gCurrentShader ); 1092 | delete gCurrentShader; 1093 | } 1094 | if ( skysphereShader ) 1095 | { 1096 | Renderer::ReleaseShader( skysphereShader ); 1097 | delete skysphereShader; 1098 | } 1099 | if ( gCurrentSkyImage.reflection ) 1100 | { 1101 | Renderer::ReleaseTexture( gCurrentSkyImage.reflection ); 1102 | gCurrentSkyImage.reflection = NULL; 1103 | } 1104 | if ( gCurrentSkyImage.env ) 1105 | { 1106 | Renderer::ReleaseTexture( gCurrentSkyImage.env ); 1107 | gCurrentSkyImage.env = NULL; 1108 | } 1109 | 1110 | ImGui_ImplOpenGL3_Shutdown(); 1111 | ImGui_ImplGlfw_Shutdown(); 1112 | ImGui::DestroyContext(); 1113 | 1114 | gModel.UnloadMesh(); 1115 | 1116 | Renderer::Close(); 1117 | 1118 | return 0; 1119 | } -------------------------------------------------------------------------------- /src/Renderer.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #ifdef _WIN32 6 | #include 7 | #endif 8 | 9 | #define GLEW_NO_GLU 10 | #include "GL/glew.h" 11 | #ifdef _WIN32 12 | #include 13 | #endif 14 | 15 | #include "Renderer.h" 16 | #include 17 | 18 | #include "stb_image.h" 19 | 20 | namespace Renderer 21 | { 22 | 23 | GLFWwindow * mWindow = NULL; 24 | bool run = true; 25 | 26 | int nWidth = 0; 27 | int nHeight = 0; 28 | RENDERER_WINDOWMODE eMode = RENDERER_WINDOWMODE_FULLSCREEN; 29 | 30 | static void error_callback( int error, const char * description ) 31 | { 32 | switch ( error ) 33 | { 34 | case GLFW_API_UNAVAILABLE: 35 | printf( "OpenGL is unavailable: " ); 36 | break; 37 | case GLFW_VERSION_UNAVAILABLE: 38 | printf( "OpenGL 4.1 (the minimum requirement) is not available: " ); 39 | break; 40 | } 41 | printf( "%s\n", description ); 42 | } 43 | void drop_callback( GLFWwindow * window, int path_count, const char * paths[] ); 44 | 45 | bool Open( RENDERER_SETTINGS * _settings ) 46 | { 47 | glfwSetErrorCallback( error_callback ); 48 | 49 | #ifdef __APPLE__ 50 | glfwInitHint( GLFW_COCOA_CHDIR_RESOURCES, GLFW_FALSE ); 51 | #endif 52 | 53 | if ( !glfwInit() ) 54 | { 55 | printf( "[Renderer] GLFW init failed\n" ); 56 | return false; 57 | } 58 | printf( "[GLFW] Version String: %s\n", glfwGetVersionString() ); 59 | 60 | nWidth = _settings->mWidth; 61 | nHeight = _settings->mHeight; 62 | eMode = _settings->mWindowMode; 63 | 64 | glfwWindowHint( GLFW_RED_BITS, 8 ); 65 | glfwWindowHint( GLFW_GREEN_BITS, 8 ); 66 | glfwWindowHint( GLFW_BLUE_BITS, 8 ); 67 | glfwWindowHint( GLFW_ALPHA_BITS, 8 ); 68 | glfwWindowHint( GLFW_DEPTH_BITS, 24 ); 69 | glfwWindowHint( GLFW_STENCIL_BITS, 8 ); 70 | 71 | glfwWindowHint( GLFW_DOUBLEBUFFER, GLFW_TRUE ); 72 | 73 | if ( _settings->mMultisampling ) 74 | { 75 | glfwWindowHint( GLFW_SAMPLES, 4 ); 76 | } 77 | 78 | glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 4 ); 79 | glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 1 ); 80 | glfwWindowHint( GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE ); 81 | glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE ); 82 | 83 | #ifdef __APPLE__ 84 | glfwWindowHint( GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_FALSE ); 85 | glfwWindowHint( GLFW_COCOA_GRAPHICS_SWITCHING, GLFW_FALSE ); 86 | #endif 87 | 88 | // TODO: change in case of resize support 89 | glfwWindowHint( GLFW_RESIZABLE, GLFW_FALSE ); 90 | 91 | // Prevent fullscreen window minimize on focus loss 92 | glfwWindowHint( GLFW_AUTO_ICONIFY, GL_FALSE ); 93 | 94 | GLFWmonitor * monitor = _settings->mWindowMode == RENDERER_WINDOWMODE_FULLSCREEN ? glfwGetPrimaryMonitor() : NULL; 95 | 96 | mWindow = glfwCreateWindow( nWidth, nHeight, "FOXOTRON is a thing", monitor, NULL ); 97 | if ( !mWindow ) 98 | { 99 | printf( "[GLFW] Window creation failed\n" ); 100 | glfwTerminate(); 101 | return false; 102 | } 103 | 104 | if ( _settings->mWindowMode == RENDERER_WINDOWMODE_WINDOWED ) 105 | { 106 | const GLFWvidmode * mode = glfwGetVideoMode( glfwGetPrimaryMonitor() ); 107 | if ( mode ) 108 | { 109 | int monitorX, monitorY; 110 | glfwGetMonitorPos( glfwGetPrimaryMonitor(), &monitorX, &monitorY ); 111 | 112 | int windowWidth, windowHeight; 113 | glfwGetWindowSize( mWindow, &windowWidth, &windowHeight ); 114 | 115 | glfwSetWindowPos( mWindow, 116 | monitorX + ( mode->width - windowWidth ) / 2, 117 | monitorY + ( mode->height - windowHeight ) / 2 ); 118 | } 119 | } 120 | 121 | glfwMakeContextCurrent( mWindow ); 122 | 123 | glfwSetDropCallback( mWindow, drop_callback ); 124 | 125 | glewExperimental = GL_TRUE; 126 | GLenum err = glewInit(); 127 | if ( GLEW_OK != err ) 128 | { 129 | printf( "[GLFW] glewInit failed: %s\n", glewGetErrorString( err ) ); 130 | glfwTerminate(); 131 | return false; 132 | } 133 | printf( "[GLFW] Using GLEW %s\n", glewGetString( GLEW_VERSION ) ); 134 | glGetError(); // reset glew error 135 | 136 | glfwSwapInterval( 1 ); 137 | 138 | #ifdef _WIN32 139 | if ( _settings->mVsync ) 140 | { 141 | wglSwapIntervalEXT( 1 ); 142 | } 143 | #endif 144 | 145 | printf( "[GLFW] OpenGL Version %s, GLSL %s\n", glGetString( GL_VERSION ), glGetString( GL_SHADING_LANGUAGE_VERSION ) ); 146 | 147 | // Now, since OpenGL is behaving a lot in fullscreen modes, lets collect the real obtained size! 148 | printf( "[GLFW] Requested framebuffer size: %d x %d\n", nWidth, nHeight ); 149 | int fbWidth = 1; 150 | int fbHeight = 1; 151 | glfwGetFramebufferSize( mWindow, &fbWidth, &fbHeight ); 152 | nWidth = _settings->mWidth = fbWidth; 153 | nHeight = _settings->mHeight = fbHeight; 154 | printf( "[GLFW] Obtained framebuffer size: %d x %d\n", fbWidth, fbHeight ); 155 | 156 | glViewport( 0, 0, nWidth, nHeight ); 157 | 158 | run = true; 159 | 160 | return true; 161 | } 162 | 163 | void SwitchFullscreen( RENDERER_WINDOWMODE newMode ) 164 | { 165 | if ( eMode == newMode ) 166 | { 167 | return; 168 | } 169 | 170 | eMode = newMode; 171 | 172 | switch ( eMode ) 173 | { 174 | case RENDERER_WINDOWMODE_WINDOWED: 175 | { 176 | glfwSetWindowMonitor( mWindow, nullptr, 0, 0, nWidth, nHeight, 0 ); 177 | 178 | const GLFWvidmode * mode = glfwGetVideoMode( glfwGetPrimaryMonitor() ); 179 | if ( mode ) 180 | { 181 | int monitorX, monitorY; 182 | glfwGetMonitorPos( glfwGetPrimaryMonitor(), &monitorX, &monitorY ); 183 | 184 | int windowWidth, windowHeight; 185 | glfwGetWindowSize( mWindow, &windowWidth, &windowHeight ); 186 | 187 | glfwSetWindowPos( mWindow, 188 | monitorX + ( mode->width - windowWidth ) / 2, 189 | monitorY + ( mode->height - windowHeight ) / 2 ); 190 | } 191 | } 192 | break; 193 | case RENDERER_WINDOWMODE_FULLSCREEN: 194 | { 195 | glfwSetWindowMonitor( mWindow, glfwGetPrimaryMonitor(), 0, 0, nWidth, nHeight, GLFW_DONT_CARE ); 196 | } 197 | break; 198 | default: 199 | break; 200 | 201 | } 202 | } 203 | 204 | std::string dropEventBuffer[ 512 ]; 205 | int dropEventBufferCount = 0; 206 | void drop_callback( GLFWwindow * window, int path_count, const char * paths[] ) 207 | { 208 | for ( int i = 0; i < path_count; i++ ) 209 | { 210 | dropEventBuffer[ dropEventBufferCount ] = paths[ i ]; 211 | dropEventBufferCount++; 212 | } 213 | } 214 | 215 | void StartFrame( glm::vec4 & clearColor ) 216 | { 217 | glClearColor( clearColor.r, clearColor.g, clearColor.b, clearColor.a ); 218 | glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); 219 | 220 | glEnable( GL_DEPTH_TEST ); 221 | } 222 | 223 | void EndFrame() 224 | { 225 | dropEventBufferCount = 0; 226 | glfwSwapBuffers( mWindow ); 227 | glfwPollEvents(); 228 | } 229 | 230 | bool WantsToQuit() 231 | { 232 | return glfwWindowShouldClose( mWindow ) || !run; 233 | } 234 | 235 | void Close() 236 | { 237 | glfwDestroyWindow( mWindow ); 238 | glfwTerminate(); 239 | } 240 | 241 | Shader * CreateShader( const char * szVertexShaderCode, int nVertexShaderCodeSize, const char * szFragmentShaderCode, int nFragmentShaderCodeSize, char * szErrorBuffer, int nErrorBufferSize ) 242 | { 243 | Shader * shader = new Shader; 244 | 245 | shader->mProgram = glCreateProgram(); 246 | 247 | shader->mVertexShader = glCreateShader( GL_VERTEX_SHADER ); 248 | GLint size = 0; 249 | GLint result = 0; 250 | 251 | ////////////////////////////////////////////////////////////////////////// 252 | // Vertex shader 253 | glShaderSource( shader->mVertexShader, 1, (const GLchar **) &szVertexShaderCode, &nVertexShaderCodeSize ); 254 | glCompileShader( shader->mVertexShader ); 255 | glGetShaderInfoLog( shader->mVertexShader, nErrorBufferSize, &size, szErrorBuffer ); 256 | glGetShaderiv( shader->mVertexShader, GL_COMPILE_STATUS, &result ); 257 | if ( !result ) 258 | { 259 | glDeleteShader( shader->mVertexShader ); 260 | glDeleteProgram( shader->mProgram ); 261 | delete shader; 262 | return NULL; 263 | } 264 | 265 | shader->mFragmentShader = glCreateShader( GL_FRAGMENT_SHADER ); 266 | 267 | ////////////////////////////////////////////////////////////////////////// 268 | // Fragment shader 269 | glShaderSource( shader->mFragmentShader, 1, (const GLchar **) &szFragmentShaderCode, &nFragmentShaderCodeSize ); 270 | glCompileShader( shader->mFragmentShader ); 271 | glGetShaderInfoLog( shader->mFragmentShader, nErrorBufferSize, &size, szErrorBuffer ); 272 | glGetShaderiv( shader->mFragmentShader, GL_COMPILE_STATUS, &result ); 273 | if ( !result ) 274 | { 275 | glDeleteShader( shader->mVertexShader ); 276 | glDeleteShader( shader->mFragmentShader ); 277 | glDeleteProgram( shader->mProgram ); 278 | delete shader; 279 | return NULL; 280 | } 281 | 282 | ////////////////////////////////////////////////////////////////////////// 283 | // Link shaders to program 284 | glAttachShader( shader->mProgram, shader->mVertexShader ); 285 | glAttachShader( shader->mProgram, shader->mFragmentShader ); 286 | glLinkProgram( shader->mProgram ); 287 | glGetProgramInfoLog( shader->mProgram, nErrorBufferSize - size, &size, szErrorBuffer + size ); 288 | glGetProgramiv( shader->mProgram, GL_LINK_STATUS, &result ); 289 | if ( !result ) 290 | { 291 | glDeleteShader( shader->mVertexShader ); 292 | glDeleteShader( shader->mFragmentShader ); 293 | glDeleteProgram( shader->mProgram ); 294 | delete shader; 295 | return NULL; 296 | } 297 | 298 | return shader; 299 | } 300 | 301 | void ReleaseShader( Shader * _shader ) 302 | { 303 | glDeleteShader( _shader->mVertexShader ); 304 | glDeleteShader( _shader->mFragmentShader ); 305 | glDeleteProgram( _shader->mProgram ); 306 | } 307 | 308 | void Shader::SetConstant( const char * szConstName, bool x ) 309 | { 310 | GLint location = glGetUniformLocation( mProgram, szConstName ); 311 | if ( location != -1 ) 312 | { 313 | glProgramUniform1i( mProgram, location, x ? 1 : 0 ); 314 | } 315 | } 316 | 317 | void Shader::SetConstant( const char * szConstName, uint32_t x ) 318 | { 319 | GLint location = glGetUniformLocation( mProgram, szConstName ); 320 | if ( location != -1 ) 321 | { 322 | glProgramUniform1ui( mProgram, location, x ); 323 | } 324 | } 325 | 326 | void Shader::SetConstant( const char * szConstName, float x ) 327 | { 328 | GLint location = glGetUniformLocation( mProgram, szConstName ); 329 | if ( location != -1 ) 330 | { 331 | glProgramUniform1f( mProgram, location, x ); 332 | } 333 | } 334 | 335 | void Shader::SetConstant( const char * szConstName, float x, float y ) 336 | { 337 | GLint location = glGetUniformLocation( mProgram, szConstName ); 338 | if ( location != -1 ) 339 | { 340 | glProgramUniform2f( mProgram, location, x, y ); 341 | } 342 | } 343 | 344 | void Shader::SetConstant( const char * szConstName, const glm::vec3 & vector ) 345 | { 346 | GLint location = glGetUniformLocation( mProgram, szConstName ); 347 | if ( location != -1 ) 348 | { 349 | glProgramUniform3f( mProgram, location, vector.x, vector.y, vector.z ); 350 | } 351 | } 352 | 353 | void Shader::SetConstant( const char * szConstName, const glm::vec4 & vector ) 354 | { 355 | GLint location = glGetUniformLocation( mProgram, szConstName ); 356 | if ( location != -1 ) 357 | { 358 | glProgramUniform4f( mProgram, location, vector.x, vector.y, vector.z, vector.w ); 359 | } 360 | } 361 | 362 | void Shader::SetConstant( const char * szConstName, const glm::mat4x4 & matrix ) 363 | { 364 | GLint location = glGetUniformLocation( mProgram, szConstName ); 365 | if ( location != -1 ) 366 | { 367 | glProgramUniformMatrix4fv( mProgram, location, 1, 0, (float*)&matrix ); 368 | } 369 | } 370 | 371 | void Shader::SetTexture( const char * szTextureName, Texture * tex ) 372 | { 373 | if ( !tex ) 374 | return; 375 | 376 | GLint location = glGetUniformLocation( mProgram, szTextureName ); 377 | if ( location != -1 ) 378 | { 379 | glProgramUniform1i( mProgram, location, ( (Texture *) tex )->mGLTextureUnit ); 380 | glActiveTexture( GL_TEXTURE0 + ( (Texture *) tex )->mGLTextureUnit ); 381 | switch ( tex->mType ) 382 | { 383 | case TEXTURETYPE_1D: glBindTexture( GL_TEXTURE_1D, ( (Texture *) tex )->mGLTextureID ); break; 384 | case TEXTURETYPE_2D: glBindTexture( GL_TEXTURE_2D, ( (Texture *) tex )->mGLTextureID ); break; 385 | } 386 | } 387 | } 388 | 389 | int textureUnit = 0; 390 | 391 | Texture * CreateRGBA8TextureFromFile( const char * szFilename, const bool _loadAsSRGB /*= false*/ ) 392 | { 393 | int comp = 0; 394 | int width = 0; 395 | int height = 0; 396 | void * data = NULL; 397 | GLenum internalFormat = _loadAsSRGB ? GL_SRGB8_ALPHA8 : GL_RGBA8; 398 | GLenum srcFormat = GL_RGBA; 399 | GLenum format = GL_UNSIGNED_BYTE; 400 | bool hasTransparentPixels = false; 401 | if ( stbi_is_hdr( szFilename ) ) 402 | { 403 | internalFormat = GL_RGBA32F; 404 | format = GL_FLOAT; 405 | data = stbi_loadf( szFilename, &width, &height, &comp, STBI_rgb_alpha ); 406 | if (!data) return NULL; 407 | float* bytes = (float*)data; 408 | for (int i = 3; i < width * height * 4; i += 4) 409 | { 410 | if (bytes[i] != 1.0f) 411 | { 412 | hasTransparentPixels = true; 413 | break; 414 | } 415 | } 416 | } 417 | else 418 | { 419 | data = stbi_load( szFilename, &width, &height, &comp, STBI_rgb_alpha ); 420 | if (!data) return NULL; 421 | unsigned char* bytes = (unsigned char*)data; 422 | for(int i = 3 ; i < width * height * 4; i += 4) 423 | { 424 | if (bytes[i] != 0xFF) 425 | { 426 | hasTransparentPixels = true; 427 | break; 428 | } 429 | } 430 | } 431 | 432 | GLuint glTexId = 0; 433 | glGenTextures( 1, &glTexId ); 434 | glBindTexture( GL_TEXTURE_2D, glTexId ); 435 | 436 | glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); 437 | glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); 438 | glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); 439 | glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR ); 440 | 441 | glTexImage2D( GL_TEXTURE_2D, 0, internalFormat, width, height, 0, srcFormat, format, data ); 442 | glGenerateMipmap( GL_TEXTURE_2D ); 443 | 444 | stbi_image_free( data ); 445 | 446 | Texture * tex = new Texture(); 447 | tex->mWidth = width; 448 | tex->mHeight = height; 449 | tex->mType = TEXTURETYPE_2D; 450 | tex->mFilename = szFilename; 451 | tex->mGLTextureID = glTexId; 452 | tex->mGLTextureUnit = textureUnit++; 453 | tex->mTransparent = hasTransparentPixels; 454 | tex->mSRGB = _loadAsSRGB; 455 | tex->mRefCount = 1; 456 | return tex; 457 | } 458 | 459 | Texture * CreateRGBA8TextureFromMemory( const unsigned char * pMemory, unsigned int nMemorySize, const bool _loadAsSRGB /*= false */ ) 460 | { 461 | int comp = 0; 462 | int width = 0; 463 | int height = 0; 464 | void * data = NULL; 465 | GLenum internalFormat = _loadAsSRGB ? GL_SRGB8_ALPHA8 : GL_RGBA8; 466 | GLenum srcFormat = GL_RGBA; 467 | GLenum format = GL_UNSIGNED_BYTE; 468 | bool hasTransparentPixels = false; 469 | if ( stbi_is_hdr_from_memory( pMemory, nMemorySize ) ) 470 | { 471 | internalFormat = GL_RGBA32F; 472 | format = GL_FLOAT; 473 | data = stbi_loadf_from_memory( pMemory, nMemorySize, &width, &height, &comp, STBI_rgb_alpha ); 474 | if ( !data ) return NULL; 475 | float * bytes = (float *) data; 476 | for ( int i = 3; i < width * height * 4; i += 4 ) 477 | { 478 | if ( bytes[ i ] != 1.0f ) 479 | { 480 | hasTransparentPixels = true; 481 | break; 482 | } 483 | } 484 | } 485 | else 486 | { 487 | data = stbi_load_from_memory( pMemory, nMemorySize, &width, &height, &comp, STBI_rgb_alpha ); 488 | if ( !data ) return NULL; 489 | unsigned char * bytes = (unsigned char *) data; 490 | for ( int i = 3; i < width * height * 4; i += 4 ) 491 | { 492 | if ( bytes[ i ] != 0xFF ) 493 | { 494 | hasTransparentPixels = true; 495 | break; 496 | } 497 | } 498 | } 499 | 500 | GLuint glTexId = 0; 501 | glGenTextures( 1, &glTexId ); 502 | glBindTexture( GL_TEXTURE_2D, glTexId ); 503 | 504 | glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); 505 | glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); 506 | glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); 507 | glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR ); 508 | 509 | glTexImage2D( GL_TEXTURE_2D, 0, internalFormat, width, height, 0, srcFormat, format, data ); 510 | glGenerateMipmap( GL_TEXTURE_2D ); 511 | 512 | stbi_image_free( data ); 513 | 514 | Texture * tex = new Texture(); 515 | tex->mWidth = width; 516 | tex->mHeight = height; 517 | tex->mType = TEXTURETYPE_2D; 518 | tex->mGLTextureID = glTexId; 519 | tex->mGLTextureUnit = textureUnit++; 520 | tex->mTransparent = hasTransparentPixels; 521 | tex->mSRGB = _loadAsSRGB; 522 | tex->mRefCount = 1; 523 | return tex; 524 | } 525 | 526 | Texture * CreateRGBA8TextureFromRawData( const unsigned int * pRGBA, unsigned int nWidth, unsigned int nHeight, const bool _loadAsSRGB /*= false */ ) 527 | { 528 | GLenum internalFormat = _loadAsSRGB ? GL_SRGB8_ALPHA8 : GL_RGBA8; 529 | GLenum srcFormat = GL_RGBA; 530 | GLenum format = GL_UNSIGNED_BYTE; 531 | 532 | bool hasTransparentPixels = false; 533 | unsigned char * bytes = (unsigned char *) pRGBA; 534 | for ( int i = 3; i < nWidth * nHeight * 4; i += 4 ) 535 | { 536 | if ( bytes[ i ] != 0xFF ) 537 | { 538 | hasTransparentPixels = true; 539 | break; 540 | } 541 | } 542 | 543 | GLuint glTexId = 0; 544 | glGenTextures( 1, &glTexId ); 545 | glBindTexture( GL_TEXTURE_2D, glTexId ); 546 | 547 | glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); 548 | glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); 549 | glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); 550 | glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR ); 551 | 552 | glTexImage2D( GL_TEXTURE_2D, 0, internalFormat, nWidth, nHeight, 0, srcFormat, format, pRGBA ); 553 | glGenerateMipmap( GL_TEXTURE_2D ); 554 | 555 | Texture * tex = new Texture(); 556 | tex->mWidth = nWidth; 557 | tex->mHeight = nHeight; 558 | tex->mType = TEXTURETYPE_2D; 559 | tex->mGLTextureID = glTexId; 560 | tex->mGLTextureUnit = textureUnit++; 561 | tex->mTransparent = hasTransparentPixels; 562 | tex->mSRGB = _loadAsSRGB; 563 | tex->mRefCount = 1; 564 | return tex; 565 | } 566 | 567 | Texture * CreateRG32FTextureFromRawFile( const char * szFilename, int width, int height) 568 | { 569 | const int comp = 2; 570 | 571 | FILE* fp = fopen( szFilename, "rb" ); 572 | if ( !fp ) 573 | { 574 | return NULL; 575 | } 576 | 577 | int size = width * height * comp; 578 | float* bytes = new float[ size ]; 579 | size_t read = fread( bytes, sizeof( float ), size, fp ); 580 | fclose( fp ); 581 | 582 | if ( read != size ) 583 | { 584 | delete[] bytes; 585 | return NULL; 586 | } 587 | 588 | GLenum internalFormat = GL_RG32F; 589 | GLenum srcFormat = GL_RG; 590 | GLenum format = GL_FLOAT; 591 | 592 | GLuint glTexId = 0; 593 | glGenTextures( 1, &glTexId ); 594 | glBindTexture( GL_TEXTURE_2D, glTexId ); 595 | 596 | glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); 597 | glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); 598 | glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 599 | glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 600 | 601 | glTexImage2D( GL_TEXTURE_2D, 0, internalFormat, width, height, 0, srcFormat, format, (const void*)bytes ); 602 | 603 | delete[] bytes; 604 | 605 | Renderer::Texture * tex = new Renderer::Texture(); 606 | tex->mWidth = width; 607 | tex->mHeight = height; 608 | tex->mType = Renderer::TEXTURETYPE_2D; 609 | tex->mFilename = szFilename; 610 | tex->mGLTextureID = glTexId; 611 | tex->mGLTextureUnit = textureUnit++; 612 | tex->mRefCount = 1; 613 | return tex; 614 | } 615 | 616 | void ReleaseTexture( Texture *& tex ) 617 | { 618 | tex->mRefCount--; 619 | if ( tex->mRefCount == 0 ) 620 | { 621 | glDeleteTextures( 1, &( (Texture *) tex )->mGLTextureID ); 622 | delete tex; 623 | tex = NULL; 624 | } 625 | } 626 | 627 | void SetShader( Shader * _shader ) 628 | { 629 | glUseProgram( _shader->mProgram ); 630 | } 631 | 632 | void CopyBackbufferToTexture( Texture * tex ) 633 | { 634 | glActiveTexture( GL_TEXTURE0 + ( (Texture *) tex )->mGLTextureUnit ); 635 | glBindTexture( GL_TEXTURE_2D, ( (Texture *) tex )->mGLTextureID ); 636 | glCopyTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 0, 0, nWidth, nHeight, 0 ); 637 | } 638 | 639 | }// namespace Renderer 640 | -------------------------------------------------------------------------------- /src/Renderer.h: -------------------------------------------------------------------------------- 1 | #define GLFW_INCLUDE_NONE 2 | #include "GLFW/glfw3.h" 3 | 4 | #include 5 | #include 6 | 7 | typedef enum 8 | { 9 | RENDERER_WINDOWMODE_WINDOWED = 0, 10 | RENDERER_WINDOWMODE_FULLSCREEN, 11 | RENDERER_WINDOWMODE_BORDERLESS 12 | } RENDERER_WINDOWMODE; 13 | 14 | typedef struct 15 | { 16 | int mWidth; 17 | int mHeight; 18 | RENDERER_WINDOWMODE mWindowMode; 19 | bool mVsync; 20 | bool mMultisampling; 21 | } RENDERER_SETTINGS; 22 | 23 | namespace Renderer 24 | { 25 | enum TEXTURETYPE 26 | { 27 | TEXTURETYPE_1D = 1, 28 | TEXTURETYPE_2D = 2, 29 | }; 30 | 31 | struct Texture 32 | { 33 | int mWidth; 34 | int mHeight; 35 | TEXTURETYPE mType; 36 | std::string mFilename; 37 | unsigned int mGLTextureID; 38 | int mGLTextureUnit; 39 | bool mTransparent; 40 | bool mSRGB; 41 | int mRefCount; 42 | }; 43 | 44 | struct Shader 45 | { 46 | unsigned int mProgram; 47 | unsigned int mVertexShader; 48 | unsigned int mFragmentShader; 49 | void SetConstant( const char * szConstName, bool x ); 50 | void SetConstant( const char * szConstName, uint32_t x ); 51 | void SetConstant( const char * szConstName, float x ); 52 | void SetConstant( const char * szConstName, float x, float y ); 53 | void SetConstant( const char * szConstName, const glm::vec3 & vector ); 54 | void SetConstant( const char * szConstName, const glm::vec4 & vector ); 55 | void SetConstant( const char * szConstName, const glm::mat4x4 & matrix ); 56 | void SetTexture( const char * szTextureName, Texture * tex ); 57 | }; 58 | 59 | extern const char * defaultShaderFilename; 60 | extern const char defaultShader[ 65536 ]; 61 | 62 | extern int nWidth; 63 | extern int nHeight; 64 | extern GLFWwindow * mWindow; 65 | extern RENDERER_WINDOWMODE eMode; 66 | 67 | bool Open( RENDERER_SETTINGS * settings ); 68 | void SwitchFullscreen( RENDERER_WINDOWMODE newMode ); 69 | 70 | void StartFrame( glm::vec4 & clearColor ); 71 | void RebindVertexArray(); 72 | void EndFrame(); 73 | bool WantsToQuit(); 74 | 75 | void RenderFullscreenQuad(); 76 | 77 | Shader * CreateShader( const char * szVertexShaderCode, int nVertexShaderCodeSize, const char * szFragmentShaderCode, int nFragmentShaderCodeSize, char * szErrorBuffer, int nErrorBufferSize ); 78 | void ReleaseShader( Shader * _shader ); 79 | 80 | void Close(); 81 | 82 | Texture * CreateRGBA8TextureFromFile( const char * szFilename, const bool _loadAsSRGB = false ); 83 | Texture * CreateRGBA8TextureFromMemory( const unsigned char * pMemory, unsigned int nMemorySize, const bool _loadAsSRGB = false ); 84 | Texture * CreateRGBA8TextureFromRawData( const unsigned int * pRGBA, unsigned int nWidth, unsigned int nHeight, const bool _loadAsSRGB = false ); 85 | Texture * CreateRG32FTextureFromRawFile( const char* szFilename, int width, int height ); 86 | void ReleaseTexture( Texture *& tex ); 87 | 88 | void SetShader( Shader * _shader ); 89 | 90 | extern std::string dropEventBuffer[ 512 ]; 91 | extern int dropEventBufferCount; 92 | } // namespace 93 | -------------------------------------------------------------------------------- /src/SetupDialog.h: -------------------------------------------------------------------------------- 1 | namespace SetupDialog 2 | { 3 | bool Open( RENDERER_SETTINGS * _settings ); 4 | } -------------------------------------------------------------------------------- /src/platform_common/SetupDialog.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../Renderer.h" 3 | #include "../SetupDialog.h" 4 | 5 | namespace SetupDialog 6 | { 7 | 8 | bool Open( RENDERER_SETTINGS * settings ) 9 | { 10 | std::cerr << __FUNCTION__ << " STUB" << std::endl; 11 | return true; 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /src/platform_w32/SetupDialog.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef __MINGW32__ 3 | #include 4 | #endif 5 | #include 6 | #include "../Renderer.h" 7 | #include "../SetupDialog.h" 8 | #include "resource.h" 9 | 10 | #include 11 | #include 12 | 13 | namespace SetupDialog 14 | { 15 | class CSetupDialog; 16 | 17 | CSetupDialog * pGlobal = NULL; 18 | 19 | INT_PTR CALLBACK DlgFunc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); 20 | 21 | class CSetupDialog 22 | { 23 | public: 24 | typedef struct 25 | { 26 | int mWidth; 27 | int mHeight; 28 | } RESOLUTION; 29 | 30 | std::vector mResolutions; 31 | HWND mHWndSetupDialog; 32 | 33 | CSetupDialog( void ) 34 | { 35 | mHWndSetupDialog = NULL; 36 | } 37 | 38 | ~CSetupDialog( void ) 39 | { 40 | } 41 | 42 | RENDERER_SETTINGS * mSetup; 43 | 44 | int __cdecl ResolutionSort( const void * a, const void * b ) 45 | { 46 | RESOLUTION * aa = (RESOLUTION *) a; 47 | RESOLUTION * bb = (RESOLUTION *) b; 48 | if ( aa->mWidth < bb->mWidth ) return -1; 49 | if ( aa->mWidth > bb->mWidth ) return 1; 50 | if ( aa->mHeight < bb->mHeight ) return -1; 51 | if ( aa->mHeight > bb->mHeight ) return 1; 52 | return 0; 53 | } 54 | 55 | bool DialogProcedure( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) 56 | { 57 | switch ( uMsg ) 58 | { 59 | case WM_INITDIALOG: 60 | { 61 | mHWndSetupDialog = hWnd; 62 | 63 | int i = 0; 64 | while ( 1 ) 65 | { 66 | DEVMODE d; 67 | BOOL h = EnumDisplaySettings( NULL, i++, &d ); 68 | if ( !h ) break; 69 | 70 | //if ((d.dmPelsWidth * 9) / 16 != d.dmPelsHeight) continue; 71 | if ( d.dmBitsPerPel != 32 ) continue; 72 | 73 | if ( !mResolutions.size() 74 | || mResolutions[ mResolutions.size() - 1 ].mWidth != d.dmPelsWidth 75 | || mResolutions[ mResolutions.size() - 1 ].mHeight != d.dmPelsHeight ) 76 | { 77 | RESOLUTION res; 78 | res.mWidth = d.dmPelsWidth; 79 | res.mHeight = d.dmPelsHeight; 80 | mResolutions.push_back( res ); 81 | 82 | } 83 | } 84 | //std::sort(gaResolutions.begin(),gaResolutions.end(),&CSetupDialog::ResolutionSort); 85 | 86 | bool bFoundBest = false; 87 | for ( i = 0; i < mResolutions.size(); i++ ) 88 | { 89 | TCHAR s[ 50 ]; 90 | _sntprintf( s, 50, _T( "%d * %d" ), mResolutions[ i ].mWidth, mResolutions[ i ].mHeight ); 91 | SendDlgItemMessage( hWnd, IDC_RESOLUTION, CB_ADDSTRING, 0, (LPARAM) s ); 92 | 93 | if ( mResolutions[ i ].mWidth == mSetup->mWidth && mResolutions[ i ].mHeight == mSetup->mHeight ) 94 | { 95 | SendDlgItemMessage( hWnd, IDC_RESOLUTION, CB_SETCURSEL, i, 0 ); 96 | bFoundBest = true; 97 | } 98 | if ( !bFoundBest && mResolutions[ i ].mWidth == GetSystemMetrics( SM_CXSCREEN ) && mResolutions[ i ].mHeight == GetSystemMetrics( SM_CYSCREEN ) ) 99 | { 100 | SendDlgItemMessage( hWnd, IDC_RESOLUTION, CB_SETCURSEL, i, 0 ); 101 | } 102 | } 103 | 104 | if ( mSetup->mWindowMode == RENDERER_WINDOWMODE_FULLSCREEN ) 105 | { 106 | SendDlgItemMessage( hWnd, IDC_FULLSCREEN, BM_SETCHECK, 1, 1 ); 107 | } 108 | if ( mSetup->mVsync ) 109 | { 110 | SendDlgItemMessage( hWnd, IDC_VSYNC, BM_SETCHECK, 1, 1 ); 111 | } 112 | if ( mSetup->mMultisampling ) 113 | { 114 | SendDlgItemMessage( hWnd, IDC_MULTISAMPLING, BM_SETCHECK, 1, 1 ); 115 | } 116 | 117 | return true; 118 | } break; 119 | 120 | case WM_COMMAND: 121 | { 122 | switch ( LOWORD( wParam ) ) 123 | { 124 | case IDOK: 125 | { 126 | mSetup->mWidth = mResolutions[ SendDlgItemMessage( hWnd, IDC_RESOLUTION, CB_GETCURSEL, 0, 0 ) ].mWidth; 127 | mSetup->mHeight = mResolutions[ SendDlgItemMessage( hWnd, IDC_RESOLUTION, CB_GETCURSEL, 0, 0 ) ].mHeight; 128 | mSetup->mWindowMode = SendDlgItemMessage( hWnd, IDC_FULLSCREEN, BM_GETCHECK, 0, 0 ) ? RENDERER_WINDOWMODE_FULLSCREEN : RENDERER_WINDOWMODE_WINDOWED; 129 | mSetup->mVsync = SendDlgItemMessage( hWnd, IDC_VSYNC, BM_GETCHECK, 0, 0 ) > 0; 130 | mSetup->mMultisampling = SendDlgItemMessage( hWnd, IDC_MULTISAMPLING, BM_GETCHECK, 0, 0 ) > 0; 131 | 132 | EndDialog( hWnd, TRUE ); 133 | } break; 134 | case IDCANCEL: 135 | { 136 | EndDialog( hWnd, FALSE ); 137 | } break; 138 | } 139 | } break; 140 | } 141 | return false; 142 | } 143 | 144 | bool Open( HINSTANCE hInstance, HWND hWnd ) 145 | { 146 | return DialogBoxParam( hInstance, MAKEINTRESOURCE( IDD_SETUP ), hWnd, DlgFunc, (LPARAM) this ) != NULL; 147 | } 148 | }; 149 | 150 | INT_PTR CALLBACK DlgFunc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) 151 | { 152 | if ( uMsg == WM_INITDIALOG ) 153 | { 154 | pGlobal = (CSetupDialog *) lParam; // todo: split to multiple hWnd-s! (if needed) 155 | } 156 | return pGlobal->DialogProcedure( hWnd, uMsg, wParam, lParam ); 157 | } 158 | 159 | bool Open( RENDERER_SETTINGS * _settings ) 160 | { 161 | CSetupDialog dlg; 162 | dlg.mSetup = _settings; 163 | return dlg.Open( GetModuleHandle( NULL ), NULL ); 164 | } 165 | 166 | } 167 | --------------------------------------------------------------------------------