├── .clang-format ├── .gitignore ├── CMakeLists.txt ├── LICENSE.md ├── README.md ├── applications └── vsgconv │ ├── CMakeLists.txt │ └── vsgconv.cpp ├── include └── vsgXchange │ ├── 3DTiles.h │ ├── Export.h │ ├── all.h │ ├── bin.h │ ├── cpp.h │ ├── curl.h │ ├── freetype.h │ ├── gdal.h │ ├── gltf.h │ ├── images.h │ └── models.h └── src ├── 3DTiles ├── 3DTiles.cpp ├── SceneGraphBuilder.cpp ├── b3dm.cpp ├── build_vars.cmake ├── cmpt.cpp └── i3dm.cpp ├── CMakeLists.txt ├── all ├── Version.cpp ├── Version.h.in └── all.cpp ├── assimp ├── SceneConverter.cpp ├── SceneConverter.h ├── assimp.cpp ├── assimp_fallback.cpp └── build_vars.cmake ├── bin └── bin.cpp ├── cpp └── cpp.cpp ├── curl ├── build_vars.cmake ├── curl.cpp └── curl_fallback.cpp ├── dds ├── dds.cpp └── tinyddsloader.h ├── freetype ├── build_vars.cmake ├── freetype.cpp └── freetype_fallback.cpp ├── gdal ├── GDAL.cpp ├── GDAL_fallback.cpp ├── build_vars.cmake ├── gdal_utils.cpp └── meta_utils.cpp ├── gltf ├── SceneGraphBuilder.cpp ├── build_vars.cmake └── gltf.cpp ├── images └── images.cpp ├── ktx ├── build_vars.cmake ├── ktx.cpp └── libktx │ ├── GL │ └── glcorearb.h │ ├── KHR │ ├── khr_df.h │ └── khrplatform.h │ ├── basis_sgd.h │ ├── checkheader.c │ ├── dfdutils │ ├── colourspaces.c │ ├── createdfd.c │ ├── dfd.h │ ├── dfd2vk.inl │ ├── interpretdfd.c │ ├── printdfd.c │ ├── queries.c │ ├── vk2dfd.c │ ├── vk2dfd.inl │ └── vulkan │ │ ├── vk_platform.h │ │ └── vulkan_core.h │ ├── etcdec.cxx │ ├── etcunpack.cxx │ ├── filestream.c │ ├── filestream.h │ ├── formatsize.h │ ├── gl_format.h │ ├── gl_funclist.inl │ ├── gl_funcs.c │ ├── gl_funcs.h │ ├── glloader.c │ ├── hashlist.c │ ├── info.c │ ├── ktx.h │ ├── ktx_zstd.h │ ├── ktx_zstd_errors.h │ ├── ktxint.h │ ├── ktxvulkan.h │ ├── memstream.c │ ├── memstream.h │ ├── strings.c │ ├── swap.c │ ├── texture.c │ ├── texture.h │ ├── texture1.c │ ├── texture1.h │ ├── texture2.c │ ├── texture2.h │ ├── texture_funcs.inl │ ├── unused.h │ ├── uthash.h │ ├── vk_format.h │ ├── vk_funclist.inl │ ├── vk_funcs.c │ ├── vk_funcs.h │ ├── vkformat_check.c │ ├── vkformat_enum.h │ ├── vkformat_str.c │ ├── vkloader.c │ └── zstddeclib.c ├── models └── models.cpp ├── openexr ├── build_vars.cmake ├── openexr.cpp └── openexr_fallback.cpp ├── stbi ├── stb_image.h ├── stb_image_write.h └── stbi.cpp └── vsgXchangeConfig.cmake.in /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | # BasedOnStyle: LLVM 4 | AccessModifierOffset: -4 5 | AlignAfterOpenBracket: Align 6 | AlignConsecutiveAssignments: false 7 | AlignConsecutiveDeclarations: false 8 | AlignEscapedNewlines: Right 9 | AlignOperands: true 10 | AlignTrailingComments: true 11 | AllowAllParametersOfDeclarationOnNextLine: true 12 | AllowShortBlocksOnASingleLine: true 13 | AllowShortCaseLabelsOnASingleLine: true 14 | AllowShortFunctionsOnASingleLine: InlineOnly 15 | AllowShortIfStatementsOnASingleLine: true 16 | AllowShortLoopsOnASingleLine: true 17 | AlwaysBreakAfterDefinitionReturnType: None 18 | AlwaysBreakAfterReturnType: None 19 | AlwaysBreakBeforeMultilineStrings: false 20 | AlwaysBreakTemplateDeclarations: false 21 | BinPackArguments: true 22 | BinPackParameters: true 23 | BraceWrapping: 24 | AfterClass: true 25 | AfterControlStatement: true 26 | AfterEnum: true 27 | AfterFunction: true 28 | AfterNamespace: true 29 | AfterObjCDeclaration: true 30 | AfterStruct: true 31 | AfterUnion: true 32 | AfterExternBlock: true 33 | BeforeCatch: true 34 | BeforeElse: true 35 | IndentBraces: false 36 | SplitEmptyFunction: true 37 | SplitEmptyRecord: true 38 | SplitEmptyNamespace: true 39 | BreakBeforeBinaryOperators: None 40 | BreakBeforeBraces: Custom 41 | BreakBeforeInheritanceComma: false 42 | BreakBeforeTernaryOperators: true 43 | BreakConstructorInitializersBeforeComma: true 44 | BreakConstructorInitializers: AfterColon 45 | BreakAfterJavaFieldAnnotations: false 46 | BreakStringLiterals: true 47 | ColumnLimit: 0 48 | CommentPragmas: '^ IWYU pragma:' 49 | CompactNamespaces: false 50 | ConstructorInitializerAllOnOneLineOrOnePerLine: true 51 | ConstructorInitializerIndentWidth: 4 52 | ContinuationIndentWidth: 4 53 | Cpp11BracedListStyle: true 54 | DerivePointerAlignment: false 55 | DisableFormat: false 56 | ExperimentalAutoDetectBinPacking: false 57 | FixNamespaceComments: true 58 | ForEachMacros: 59 | - foreach 60 | - Q_FOREACH 61 | - BOOST_FOREACH 62 | IncludeBlocks: Preserve 63 | IncludeCategories: 64 | - Regex: '^"(llvm|llvm-c|clang|clang-c)/' 65 | Priority: 2 66 | - Regex: '^(<|"(gtest|gmock|isl|json)/)' 67 | Priority: 3 68 | - Regex: '.*' 69 | Priority: 1 70 | IncludeIsMainRegex: '(Test)?$' 71 | IndentCaseLabels: false 72 | IndentPPDirectives: AfterHash 73 | IndentWidth: 4 74 | IndentWrappedFunctionNames: false 75 | JavaScriptQuotes: Leave 76 | JavaScriptWrapImports: true 77 | KeepEmptyLinesAtTheStartOfBlocks: true 78 | MacroBlockBegin: '' 79 | MacroBlockEnd: '' 80 | MaxEmptyLinesToKeep: 1 81 | NamespaceIndentation: All 82 | ObjCBlockIndentWidth: 4 83 | ObjCSpaceAfterProperty: false 84 | ObjCSpaceBeforeProtocolList: true 85 | PenaltyBreakAssignment: 2 86 | PenaltyBreakBeforeFirstCallParameter: 19 87 | PenaltyBreakComment: 300 88 | PenaltyBreakFirstLessLess: 120 89 | PenaltyBreakString: 1000 90 | PenaltyExcessCharacter: 1000000 91 | PenaltyReturnTypeOnItsOwnLine: 60 92 | PointerAlignment: Left 93 | ReflowComments: false 94 | SortIncludes: true 95 | SortUsingDeclarations: true 96 | SpaceAfterCStyleCast: false 97 | SpaceAfterTemplateKeyword: false 98 | SpaceBeforeAssignmentOperators: true 99 | SpaceBeforeParens: ControlStatements 100 | SpaceInEmptyParentheses: false 101 | SpacesBeforeTrailingComments: 1 102 | SpacesInAngles: false 103 | SpacesInContainerLiterals: true 104 | SpacesInCStyleCastParentheses: false 105 | SpacesInParentheses: false 106 | SpacesInSquareBrackets: false 107 | Standard: Cpp11 108 | TabWidth: 8 109 | UseTab: Never 110 | ... 111 | 112 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | cmake_uninstall.cmake 3 | 4 | lib/ 5 | bin/ 6 | 7 | # Autogenerated files 8 | include/vsgXchange/Version.h 9 | 10 | *.pc 11 | *.conf 12 | *.backup 13 | CMakeCache.txt 14 | CMakeFiles 15 | CMakeScripts 16 | Makefile 17 | cmake_install.cmake 18 | install_manifest.txt 19 | CMakeDoxyfile.in 20 | CMakeDoxygenDefaults.cmake 21 | Doxyfile.docs 22 | vsgXchangeConfig.cmake 23 | vsgXchangeConfigVersion.cmake 24 | Doxyfile.docs-vsgXchange 25 | 26 | html/ 27 | 28 | 29 | # Compiled Object files 30 | *.slo 31 | *.lo 32 | *.o 33 | *.obj 34 | 35 | # Precompiled Headers 36 | *.gch 37 | *.pch 38 | 39 | # Compiled Dynamic libraries 40 | *.so 41 | *.dylib 42 | *.dll 43 | 44 | # Fortran module files 45 | *.mod 46 | 47 | # Compiled Static libraries 48 | *.lai 49 | *.la 50 | *.a 51 | *.lib 52 | 53 | # Executables 54 | *.exe 55 | *.out 56 | *.app 57 | 58 | # Visual Studio files 59 | *.sln 60 | *.vcxproj 61 | *.vcxproj.filters 62 | *.vcxproj.user 63 | .vs/ 64 | x64/ 65 | src/vsg/vsg.dir/ 66 | *.pdb 67 | *.tlog 68 | *.log 69 | 70 | # Xcode 71 | DerivedData/ 72 | *.build 73 | *.xcodeproj 74 | 75 | # Gradle 76 | .gradle/ 77 | .idea/ 78 | .externalNativeBuild/ 79 | *.iml 80 | build/ 81 | local.properties 82 | 83 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.7) 2 | 3 | project(vsgXchange 4 | VERSION 1.1.6 5 | DESCRIPTION "VulkanSceneGraph 3rd party data integration library" 6 | LANGUAGES CXX C 7 | ) 8 | set(VSGXCHANGE_SOVERSION 1) 9 | SET(VSGXCHANGE_RELEASE_CANDIDATE 0) 10 | 11 | set(VSGXCHANGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "Root source directory of vsgXchange.") 12 | set(VSGXCHANGE_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}" CACHE INTERNAL "Root binary directory of vsgXchange.") 13 | 14 | 15 | # set the use of C++17 globally as all examples require it 16 | set(CMAKE_CXX_STANDARD 17) 17 | 18 | # Find Vulkan and the VSG 19 | if (VULKAN_SDK) 20 | set(ENV{VULKAN_SDK} ${VULKAN_SDK}) 21 | endif() 22 | 23 | set(VSG_MIN_VERSION 1.1.11) 24 | find_package(vsg ${VSG_MIN_VERSION}) 25 | 26 | vsg_setup_dir_vars() 27 | vsg_setup_build_vars() 28 | 29 | # find optional osg2vsg package for loading image/nodes using OpenSceneGraph 30 | find_package(osg2vsg QUIET) 31 | if(osg2vsg_FOUND) 32 | OPTION(vsgXchange_OSG "OSG support provided" ON) 33 | endif() 34 | 35 | if (vsgXchange_OSG) 36 | set(EXTRA_LIBRARIES ${EXTRA_LIBRARIES} osg2vsg::osg2vsg) 37 | if(NOT BUILD_SHARED_LIBS) 38 | set(FIND_DEPENDENCY ${FIND_DEPENDENCY} "find_dependency(osg2vsg)") 39 | endif() 40 | endif() 41 | 42 | # for generated cmake support files 43 | set(FIND_DEPENDENCY ${FIND_DEPENDENCY} "find_dependency(vsg ${VSG_MIN_VERSION} REQUIRED)") 44 | 45 | vsg_add_target_clang_format( 46 | FILES 47 | ${VSGXCHANGE_SOURCE_DIR}/include/*/*.h 48 | ${VSGXCHANGE_SOURCE_DIR}/src/*/*.h 49 | ${VSGXCHANGE_SOURCE_DIR}/src/*/*.cpp 50 | ${VSGXCHANGE_SOURCE_DIR}/applications/*/*.h 51 | ${VSGXCHANGE_SOURCE_DIR}/applications/*/*.cpp 52 | EXCLUDES 53 | ${VSGXCHANGE_SOURCE_DIR}/src/stbi/stb_image.h 54 | ${VSGXCHANGE_SOURCE_DIR}/src/stbi/stb_image_write.h 55 | ${VSGXCHANGE_SOURCE_DIR}/src/dds/tinyddsloader.h 56 | ) 57 | vsg_add_target_clobber() 58 | vsg_add_target_cppcheck( 59 | FILES 60 | ${VSGXCHANGE_SOURCE_DIR}/include/*/*.h 61 | ${VSGXCHANGE_SOURCE_DIR}/src/*/*.h 62 | ${VSGXCHANGE_SOURCE_DIR}/src/*/*.cpp 63 | ${VSGXCHANGE_SOURCE_DIR}/applications/*/*.h 64 | ${VSGXCHANGE_SOURCE_DIR}/applications/*/*.cpp 65 | ) 66 | vsg_add_target_docs( 67 | FILES 68 | ${VSGXCHANGE_SOURCE_DIR}/include 69 | ) 70 | vsg_add_target_uninstall() 71 | 72 | # only provide custom targets if not building as a submodule/FetchContent 73 | if (${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR}) 74 | 75 | vsg_add_option_maintainer( 76 | PREFIX v 77 | RCLEVEL ${VSGXCHANGE_RELEASE_CANDIDATE} 78 | ) 79 | 80 | endif() 81 | 82 | # source directory for main vsgXchange library 83 | add_subdirectory(src) 84 | add_subdirectory(applications/vsgconv) 85 | 86 | vsg_add_feature_summary() 87 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Robert Osfield 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /applications/vsgconv/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(NOT ANDROID) 2 | find_package(Threads) 3 | endif() 4 | 5 | if (UNIX) 6 | find_library(DL_LIBRARY dl) 7 | endif() 8 | 9 | set(SOURCES 10 | vsgconv.cpp 11 | ) 12 | 13 | add_executable(vsgconv ${SOURCES}) 14 | 15 | target_include_directories(vsgconv PRIVATE 16 | $ 17 | ) 18 | 19 | set_target_properties(vsgconv PROPERTIES OUTPUT_NAME vsgconv DEBUG_POSTFIX "d") 20 | 21 | target_link_libraries(vsgconv 22 | vsgXchange 23 | vsg::vsg 24 | ) 25 | 26 | install(TARGETS vsgconv 27 | RUNTIME DESTINATION bin 28 | ) 29 | -------------------------------------------------------------------------------- /include/vsgXchange/Export.h: -------------------------------------------------------------------------------- 1 | #ifndef VSGXCHANGE_EXPORT_H 2 | #define VSGXCHANGE_EXPORT_H 3 | 4 | /* 5 | 6 | Copyright(c) 2018 Robert Osfield 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 11 | 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | 14 | */ 15 | 16 | #if (defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__)) 17 | # if defined(vsgXchange_EXPORTS) 18 | # define VSGXCHANGE_DECLSPEC __declspec(dllexport) 19 | # elif defined(VSGXCHANGE_SHARED_LIBRARY) 20 | # define VSGXCHANGE_DECLSPEC __declspec(dllimport) 21 | # else 22 | # define VSGXCHANGE_DECLSPEC 23 | # endif 24 | #else 25 | # define VSGXCHANGE_DECLSPEC 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /include/vsgXchange/all.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | 5 | Copyright(c) 2021 Robert Osfield 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | this software and associated documentation files (the "Software"), to deal in 9 | the Software without restriction, including without limitation the rights to 10 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | the Software, and to permit persons to whom the Software is furnished to do so, 12 | subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | namespace vsgXchange 30 | { 31 | /// initialize any statics, such as registering all the ReaderWriters with vsg::ObjectFactory::instance(), 32 | /// so that any serialization that includes vsgXchange ReaderWriters will be able to load them. 33 | extern VSGXCHANGE_DECLSPEC void init(); 34 | 35 | /// ReaderWriter that has all the ReaderWriter implementations that vsgXchange provides. 36 | class VSGXCHANGE_DECLSPEC all : public vsg::Inherit 37 | { 38 | public: 39 | all(); 40 | }; 41 | } // namespace vsgXchange 42 | 43 | EVSG_type_name(vsgXchange::all); 44 | -------------------------------------------------------------------------------- /include/vsgXchange/bin.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | 5 | Copyright(c) 2025 Robert Osfield 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | this software and associated documentation files (the "Software"), to deal in 9 | the Software without restriction, including without limitation the rights to 10 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | the Software, and to permit persons to whom the Software is furnished to do so, 12 | subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shimages be included in images 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | namespace vsgXchange 31 | { 32 | 33 | /// .bin ReaderWriter 34 | class VSGXCHANGE_DECLSPEC bin : public vsg::Inherit 35 | { 36 | public: 37 | bin(); 38 | 39 | vsg::ref_ptr read(const vsg::Path&, vsg::ref_ptr) const override; 40 | vsg::ref_ptr read(std::istream&, vsg::ref_ptr) const override; 41 | vsg::ref_ptr read(const uint8_t* ptr, size_t size, vsg::ref_ptr options = {}) const override; 42 | 43 | vsg::ref_ptr _read(std::istream&) const; 44 | 45 | bool supportedExtension(const vsg::Path& ext) const; 46 | 47 | bool getFeatures(Features& features) const override; 48 | }; 49 | 50 | } 51 | 52 | EVSG_type_name(vsgXchange::bin) 53 | 54 | -------------------------------------------------------------------------------- /include/vsgXchange/cpp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | 5 | Copyright(c) 2021 Robert Osfield 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | this software and associated documentation files (the "Software"), to deal in 9 | the Software without restriction, including without limitation the rights to 10 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | the Software, and to permit persons to whom the Software is furnished to do so, 12 | subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | namespace vsgXchange 32 | { 33 | 34 | class VSGXCHANGE_DECLSPEC cpp : public vsg::Inherit 35 | { 36 | public: 37 | cpp(); 38 | 39 | bool write(const vsg::Object* object, const vsg::Path& filename, vsg::ref_ptr options = {}) const override; 40 | 41 | bool getFeatures(Features& features) const override; 42 | 43 | protected: 44 | void write(std::ostream& out, const std::string& str) const; 45 | }; 46 | 47 | } // namespace vsgXchange 48 | 49 | EVSG_type_name(vsgXchange::cpp); 50 | -------------------------------------------------------------------------------- /include/vsgXchange/curl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | 5 | Copyright(c) 2021 Robert Osfield 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | this software and associated documentation files (the "Software"), to deal in 9 | the Software without restriction, including without limitation the rights to 10 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | the Software, and to permit persons to whom the Software is furnished to do so, 12 | subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | namespace vsgXchange 32 | { 33 | 34 | /// optional curl ReaderWriter. 35 | /// depends upon libcurl for reading data from http and https. 36 | class VSGXCHANGE_DECLSPEC curl : public vsg::Inherit 37 | { 38 | public: 39 | curl(); 40 | vsg::ref_ptr read(const vsg::Path& filename, vsg::ref_ptr options = {}) const override; 41 | 42 | bool getFeatures(Features& features) const override; 43 | 44 | // vsg::Options::setValue(str, value) supported options: 45 | static constexpr const char* SSL_OPTIONS = "CURLOPT_SSL_OPTIONS"; /// uint32_t 46 | 47 | /// specify whether libcurl should be initialized and cleaned up by vsgXchange::curl. 48 | static bool s_do_curl_global_init_and_cleanup; // defaults to true 49 | 50 | protected: 51 | ~curl(); 52 | 53 | class Implementation; 54 | mutable std::mutex _mutex; 55 | mutable Implementation* _implementation; 56 | }; 57 | 58 | } // namespace vsgXchange 59 | 60 | EVSG_type_name(vsgXchange::curl); 61 | -------------------------------------------------------------------------------- /include/vsgXchange/freetype.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | 5 | Copyright(c) 2021 Robert Osfield 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | this software and associated documentation files (the "Software"), to deal in 9 | the Software without restriction, including without limitation the rights to 10 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | the Software, and to permit persons to whom the Software is furnished to do so, 12 | subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | namespace vsgXchange 32 | { 33 | 34 | class VSGXCHANGE_DECLSPEC freetype : public vsg::Inherit 35 | { 36 | public: 37 | freetype(); 38 | vsg::ref_ptr read(const vsg::Path& filename, vsg::ref_ptr options = {}) const override; 39 | 40 | bool getFeatures(Features& features) const override; 41 | 42 | // vsg::Options::setValue(str, value) supported options: 43 | static constexpr const char* texel_margin_ratio = "texel_margin_ratio"; 44 | static constexpr const char* quad_margin_ratio = "quad_margin_ratio"; 45 | 46 | bool readOptions(vsg::Options& options, vsg::CommandLine& arguments) const override; 47 | 48 | protected: 49 | ~freetype(); 50 | 51 | class Implementation; 52 | Implementation* _implementation; 53 | }; 54 | 55 | } // namespace vsgXchange 56 | 57 | EVSG_type_name(vsgXchange::freetype); 58 | -------------------------------------------------------------------------------- /include/vsgXchange/gdal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | 5 | Copyright(c) 2021 Robert Osfield 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | this software and associated documentation files (the "Software"), to deal in 9 | the Software without restriction, including without limitation the rights to 10 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | the Software, and to permit persons to whom the Software is furnished to do so, 12 | subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shimages be included in images 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | namespace vsgXchange 34 | { 35 | /// optional GDAL ReaderWriter 36 | class VSGXCHANGE_DECLSPEC GDAL : public vsg::Inherit 37 | { 38 | public: 39 | GDAL(); 40 | vsg::ref_ptr read(const vsg::Path& filename, vsg::ref_ptr options) const override; 41 | vsg::ref_ptr read(std::istream& fin, vsg::ref_ptr options = {}) const override; 42 | vsg::ref_ptr read(const uint8_t* ptr, size_t size, vsg::ref_ptr options = {}) const override; 43 | 44 | bool getFeatures(Features& features) const override; 45 | 46 | protected: 47 | ~GDAL(); 48 | 49 | class Implementation; 50 | Implementation* _implementation; 51 | }; 52 | 53 | } // namespace vsgXchange 54 | 55 | EVSG_type_name(vsgXchange::GDAL); 56 | 57 | #ifdef vsgXchange_GDAL 58 | 59 | # include "gdal_priv.h" 60 | # include "ogr_spatialref.h" 61 | 62 | # include 63 | # include 64 | # include 65 | 66 | # include 67 | # include 68 | 69 | namespace vsgXchange 70 | { 71 | /// call GDALAllRegister() etc. if it hasn't already been called. Return true if this call to initGDAL() invoked GDAL setup, or false if it has previously been done. 72 | extern VSGXCHANGE_DECLSPEC bool initGDAL(); 73 | 74 | /// Call GDALOpen(..) to open specified file returning a std::shared_ptr to reboustly manage the lifetime of the GDALDataSet, automatiically call GDALClose. 75 | inline std::shared_ptr openDataSet(const vsg::Path& filename, GDALAccess access) 76 | { 77 | // GDAL doesn't support wide string filenames so convert vsg::Path to std::string and then pass to GDALOpen 78 | return std::shared_ptr(static_cast(GDALOpen(filename.string().c_str(), access)), [](GDALDataset* dataset) { GDALClose(dataset); }); 79 | } 80 | 81 | /// Call GDALOpenShared(..) to open specified file returning a std::shared_ptr to reboustly manage the lifetime of the GDALDataSet, automatiically call GDALClose. 82 | inline std::shared_ptr openSharedDataSet(const vsg::Path& filename, GDALAccess access) 83 | { 84 | // GDAL doesn't support wide string filenames so convert vsg::Path to std::string and then pass to GDALOpenShared 85 | return std::shared_ptr(static_cast(GDALOpenShared(filename.string().c_str(), access)), [](GDALDataset* dataset) { GDALClose(dataset); }); 86 | } 87 | 88 | /// return true if two GDALDataset has the same projection reference string/ 89 | extern VSGXCHANGE_DECLSPEC bool compatibleDatasetProjections(const GDALDataset& lhs, const GDALDataset& rhs); 90 | 91 | /// return true if two GDALDataset has the same projection, geo transform and dimensions indicating they are perfectly pixel aliged and matched in size. 92 | extern VSGXCHANGE_DECLSPEC bool compatibleDatasetProjectionsTransformAndSizes(const GDALDataset& lhs, const GDALDataset& rhs); 93 | 94 | /// create a vsg::Image2D of the approrpiate type that maps to specified dimensions and GDALDataType 95 | extern VSGXCHANGE_DECLSPEC vsg::ref_ptr createImage2D(int width, int height, int numComponents, GDALDataType dataType, vsg::dvec4 def = {0.0, 0.0, 0.0, 1.0}); 96 | 97 | /// copy a RasterBand onto a target RGBA component of a vsg::Data. Dimensions and datatypes must be compatble between RasterBand and vsg::Data. Return true on success, false on failure to copy. 98 | extern VSGXCHANGE_DECLSPEC bool copyRasterBandToImage(GDALRasterBand& band, vsg::Data& image, int component); 99 | 100 | /// assign GDAL MetaData mapping the "key=value" entries to vsg::Object as setValue(key, std::string(value)). 101 | extern VSGXCHANGE_DECLSPEC bool assignMetaData(GDALDataset& dataset, vsg::Object& object); 102 | 103 | /// call binary comparison operators on dereferenced items in specified range. 104 | template 105 | bool all_equal(Iterator first, Iterator last, BinaryPredicate compare) 106 | { 107 | if (first == last) return true; 108 | Iterator itr = first; 109 | ++itr; 110 | 111 | for (; itr != last; ++itr) 112 | { 113 | if (!compare(**first, **itr)) return false; 114 | } 115 | 116 | return true; 117 | } 118 | 119 | /// collect the set of GDALDataType of all the RansterBand is the specified GDALDataset 120 | inline std::set dataTypes(GDALDataset& dataset) 121 | { 122 | std::set types; 123 | for (int i = 1; i <= dataset.GetRasterCount(); ++i) 124 | { 125 | GDALRasterBand* band = dataset.GetRasterBand(i); 126 | types.insert(band->GetRasterDataType()); 127 | } 128 | 129 | return types; 130 | } 131 | 132 | /// collect the set of GDALDataType of all the RansterBand is the specified range of GDALDataset 133 | template 134 | std::set dataTypes(Iterator first, Iterator last) 135 | { 136 | std::set types; 137 | for (Iterator itr = first; itr != last; ++itr) 138 | { 139 | GDALDataset& dataset = **itr; 140 | for (int i = 1; i <= dataset.GetRasterCount(); ++i) 141 | { 142 | GDALRasterBand* band = dataset.GetRasterBand(i); 143 | types.insert(band->GetRasterDataType()); 144 | } 145 | } 146 | return types; 147 | } 148 | 149 | /// get the latitude, longitude and altitude values from the GDALDataSet's EXIF_GPSLatitude, EXIF_GPSLongitude and EXIF_GPSAltitude meta data fields, return true on success, 150 | extern VSGXCHANGE_DECLSPEC bool getEXIF_LatitudeLongitudeAlititude(GDALDataset& dataset, double& latitude, double& longitude, double& altitude); 151 | 152 | /// get the latitude, longitude and altitude values from the vsg::Object's EXIF_GPSLatitude, EXIF_GPSLongitude and EXIF_GPSAltitude meta data fields, return true on success, 153 | extern VSGXCHANGE_DECLSPEC bool getEXIF_LatitudeLongitudeAlititude(const vsg::Object& object, double& latitude, double& longitude, double& altitude); 154 | 155 | template 156 | struct in_brackets 157 | { 158 | in_brackets(T& v) : 159 | value(v) {} 160 | T& value; 161 | }; 162 | 163 | template 164 | std::istream& operator>>(std::istream& input, in_brackets field) 165 | { 166 | while (input.peek() == ' ') input.get(); 167 | 168 | std::string str; 169 | if (input.peek() == '(') 170 | { 171 | input.ignore(); 172 | 173 | input >> field.value; 174 | 175 | if constexpr (std::is_same_v) 176 | { 177 | if (!field.value.empty() && field.value[field.value.size() - 1] == ')') 178 | { 179 | field.value.erase(field.value.size() - 1); 180 | return input; 181 | } 182 | else 183 | { 184 | while (input.peek() != ')') 185 | { 186 | int c = input.get(); 187 | if (input.eof()) return input; 188 | 189 | field.value.push_back(c); 190 | } 191 | } 192 | } 193 | 194 | if (input.peek() == ')') 195 | { 196 | input.ignore(); 197 | } 198 | } 199 | else 200 | { 201 | input >> field.value; 202 | } 203 | 204 | return input; 205 | } 206 | 207 | /// helper class for reading decimal degree in the form of (degrees) (minutes) (seconds) as used with EXIF_GPSLatitude and EXIF_GPSLongitude tags. 208 | /// usage: 209 | /// std::stringstream str(EXIF_GPSLatitude_String); 210 | /// double latitude; 211 | /// str >> dms_in_brackets(latitude); 212 | struct dms_in_brackets 213 | { 214 | dms_in_brackets(double& angle) : 215 | value(angle) {} 216 | double& value; 217 | }; 218 | 219 | inline std::istream& operator>>(std::istream& input, dms_in_brackets field) 220 | { 221 | double degrees = 0.0, minutes = 0.0, seconds = 0.0; 222 | input >> in_brackets(degrees) >> in_brackets(minutes) >> in_brackets(seconds); 223 | field.value = degrees + (minutes + seconds / 60.0) / 60.0; 224 | return input; 225 | } 226 | 227 | } // namespace vsgXchange 228 | 229 | #endif 230 | -------------------------------------------------------------------------------- /include/vsgXchange/images.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | 5 | Copyright(c) 2021 Robert Osfield 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | this software and associated documentation files (the "Software"), to deal in 9 | the Software without restriction, including without limitation the rights to 10 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | the Software, and to permit persons to whom the Software is furnished to do so, 12 | subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shimages be included in images 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | namespace vsgXchange 33 | { 34 | /// Composite ReaderWriter that holds the used 3rd party image format loaders. 35 | /// By default utilizes the stbi, dds and ktx ReaderWriters so that users only need to create vsgXchange::images::create() to utilize them all. 36 | class VSGXCHANGE_DECLSPEC images : public vsg::Inherit 37 | { 38 | public: 39 | images(); 40 | }; 41 | 42 | /// add png, jpeg and gif support using local build of stbi. 43 | class VSGXCHANGE_DECLSPEC stbi : public vsg::Inherit 44 | { 45 | public: 46 | stbi(); 47 | 48 | vsg::ref_ptr read(const vsg::Path& filename, vsg::ref_ptr options = {}) const override; 49 | vsg::ref_ptr read(std::istream& fin, vsg::ref_ptr options = {}) const override; 50 | vsg::ref_ptr read(const uint8_t* ptr, size_t size, vsg::ref_ptr options = {}) const override; 51 | bool write(const vsg::Object* object, const vsg::Path& filename, vsg::ref_ptr = {}) const override; 52 | bool write(const vsg::Object* object, std::ostream& stream, vsg::ref_ptr = {}) const override; 53 | 54 | bool getFeatures(Features& features) const override; 55 | 56 | // vsg::Options::setValue(str, value) supported options: 57 | static constexpr const char* jpeg_quality = "jpeg_quality"; /// set the int quality value when writing out to image as jpeg file. 58 | static constexpr const char* image_format = "image_format"; /// Override read image format (8bit RGB/RGBA default to sRGB) to be specified class of CoordinateSpace (sRGB or LINEAR). 59 | 60 | bool readOptions(vsg::Options& options, vsg::CommandLine& arguments) const override; 61 | 62 | private: 63 | std::set _supportedExtensions; 64 | }; 65 | 66 | /// add dds support using local build of tinydds. 67 | class VSGXCHANGE_DECLSPEC dds : public vsg::Inherit 68 | { 69 | public: 70 | dds(); 71 | 72 | vsg::ref_ptr read(const vsg::Path& filename, vsg::ref_ptr options = {}) const override; 73 | vsg::ref_ptr read(std::istream& fin, vsg::ref_ptr options = {}) const override; 74 | vsg::ref_ptr read(const uint8_t* ptr, size_t size, vsg::ref_ptr options = {}) const override; 75 | 76 | bool getFeatures(Features& features) const override; 77 | 78 | private: 79 | std::set _supportedExtensions; 80 | }; 81 | 82 | /// add ktx using using local build of libktx 83 | class VSGXCHANGE_DECLSPEC ktx : public vsg::Inherit 84 | { 85 | public: 86 | ktx(); 87 | 88 | vsg::ref_ptr read(const vsg::Path& filename, vsg::ref_ptr options = {}) const override; 89 | vsg::ref_ptr read(std::istream& fin, vsg::ref_ptr options = {}) const override; 90 | vsg::ref_ptr read(const uint8_t* ptr, size_t size, vsg::ref_ptr options = {}) const override; 91 | 92 | bool getFeatures(Features& features) const override; 93 | 94 | private: 95 | std::set _supportedExtensions; 96 | }; 97 | 98 | /// optional .exr support using OpenEXR library 99 | class openexr : public vsg::Inherit 100 | { 101 | public: 102 | openexr(); 103 | 104 | vsg::ref_ptr read(const vsg::Path& filename, vsg::ref_ptr options = {}) const override; 105 | vsg::ref_ptr read(std::istream& fin, vsg::ref_ptr options = {}) const override; 106 | vsg::ref_ptr read(const uint8_t* ptr, size_t size, vsg::ref_ptr options = {}) const override; 107 | 108 | bool write(const vsg::Object* object, const vsg::Path& filename, vsg::ref_ptr = {}) const override; 109 | bool write(const vsg::Object* object, std::ostream& fout, vsg::ref_ptr = {}) const override; 110 | 111 | bool getFeatures(Features& features) const override; 112 | 113 | private: 114 | std::set _supportedExtensions; 115 | }; 116 | 117 | } // namespace vsgXchange 118 | 119 | EVSG_type_name(vsgXchange::images); 120 | EVSG_type_name(vsgXchange::stbi); 121 | EVSG_type_name(vsgXchange::dds); 122 | EVSG_type_name(vsgXchange::ktx); 123 | EVSG_type_name(vsgXchange::openexr); 124 | -------------------------------------------------------------------------------- /include/vsgXchange/models.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | 5 | Copyright(c) 2021 Robert Osfield 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | this software and associated documentation files (the "Software"), to deal in 9 | the Software without restriction, including without limitation the rights to 10 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | the Software, and to permit persons to whom the Software is furnished to do so, 12 | subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shimages be included in images 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | namespace vsgXchange 32 | { 33 | /// Composite ReaderWriter that holds the used 3rd party model format loaders. 34 | class VSGXCHANGE_DECLSPEC models : public vsg::Inherit 35 | { 36 | public: 37 | models(); 38 | }; 39 | 40 | /// optional assimp ReaderWriter 41 | class VSGXCHANGE_DECLSPEC assimp : public vsg::Inherit 42 | { 43 | public: 44 | assimp(); 45 | vsg::ref_ptr read(const vsg::Path&, vsg::ref_ptr) const override; 46 | vsg::ref_ptr read(std::istream&, vsg::ref_ptr) const override; 47 | vsg::ref_ptr read(const uint8_t* ptr, size_t size, vsg::ref_ptr options = {}) const override; 48 | 49 | bool getFeatures(Features& features) const override; 50 | 51 | // vsg::Options::setValue(str, value) supported options: 52 | static constexpr const char* generate_smooth_normals = "generate_smooth_normals"; 53 | static constexpr const char* generate_sharp_normals = "generate_sharp_normals"; 54 | static constexpr const char* crease_angle = "crease_angle"; /// float 55 | static constexpr const char* two_sided = "two_sided"; /// bool 56 | static constexpr const char* discard_empty_nodes = "discard_empty_nodes"; /// bool 57 | static constexpr const char* print_assimp = "print_assimp"; /// int 58 | static constexpr const char* external_textures = "external_textures"; /// bool 59 | static constexpr const char* external_texture_format = "external_texture_format"; /// TextureFormat enum 60 | static constexpr const char* culling = "culling"; /// bool, insert cull nodes, defaults to true 61 | static constexpr const char* vertex_color_space = "vertex_color_space"; /// CoordinateSpace {sRGB or LINEAR} to assume when reading vertex colors 62 | static constexpr const char* material_color_space = "material_color_space"; /// CoordinateSpace {sRGB or LINEAR} to assume when reading materials colors 63 | 64 | bool readOptions(vsg::Options& options, vsg::CommandLine& arguments) const override; 65 | 66 | protected: 67 | ~assimp(); 68 | 69 | class Implementation; 70 | Implementation* _implementation; 71 | }; 72 | 73 | } // namespace vsgXchange 74 | 75 | EVSG_type_name(vsgXchange::models); 76 | EVSG_type_name(vsgXchange::assimp); 77 | -------------------------------------------------------------------------------- /src/3DTiles/b3dm.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright(c) 2025 Robert Osfield 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | 11 | */ 12 | 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | using namespace vsgXchange; 28 | 29 | // b3dm_FeatureTable 30 | // 31 | void Tiles3D::b3dm_FeatureTable::read_array(vsg::JSONParser& parser, const std::string_view& property) 32 | { 33 | if (property=="RTC_CENTER") parser.read_array(RTC_CENTER); 34 | else parser.warning(); 35 | } 36 | 37 | void Tiles3D::b3dm_FeatureTable::read_object(vsg::JSONParser& parser, const std::string_view& property) 38 | { 39 | if (property=="RTC_CENTER") parser.read_object(RTC_CENTER); 40 | else parser.warning(); 41 | } 42 | 43 | void Tiles3D::b3dm_FeatureTable::read_number(vsg::JSONParser& parser, const std::string_view& property, std::istream& input) 44 | { 45 | if (property=="BATCH_LENGTH") input >> BATCH_LENGTH; 46 | else parser.warning(); 47 | } 48 | 49 | void Tiles3D::b3dm_FeatureTable::convert() 50 | { 51 | if (!binary) return; 52 | 53 | RTC_CENTER.assign(*binary, 3); 54 | } 55 | 56 | void Tiles3D::b3dm_FeatureTable::report(vsg::LogOutput& output) 57 | { 58 | output("b3dm_FeatureTable { "); 59 | output(" RTC_CENTER ", RTC_CENTER.values); 60 | output(" BATCH_LENGTH ", BATCH_LENGTH); 61 | output("}"); 62 | } 63 | 64 | //////////////////////////////////////////////////////////////////////////////////////////////////// 65 | // 66 | // read_b3dm 67 | // 68 | vsg::ref_ptr Tiles3D::read_b3dm(std::istream& fin, vsg::ref_ptr options, const vsg::Path& filename) const 69 | { 70 | 71 | fin.seekg(0); 72 | 73 | // https://github.com/CesiumGS/3d-tiles/tree/1.0/specification/TileFormats/Batched3DModel 74 | struct Header 75 | { 76 | char magic[4] = {0,0,0,0}; 77 | uint32_t version = 0; 78 | uint32_t byteLength = 0; 79 | uint32_t featureTableJSONByteLength = 0; 80 | uint32_t featureTableBinaryByteLength = 0; 81 | uint32_t batchTableJSONByteLength = 0; 82 | uint32_t batchTableBinaryLength = 0; 83 | }; 84 | 85 | Header header; 86 | fin.read(reinterpret_cast(&header), sizeof(Header)); 87 | 88 | if (!fin.good()) 89 | { 90 | vsg::warn("IO error reading bd3m file."); 91 | return {}; 92 | } 93 | 94 | if (strncmp(header.magic, "b3dm", 4) != 0) 95 | { 96 | vsg::warn("magic number not b3dm"); 97 | return {}; 98 | } 99 | 100 | // Feature table 101 | // Batch table 102 | // Binary glTF 103 | 104 | vsg::ref_ptr featureTable = b3dm_FeatureTable::create(); 105 | if (header.featureTableJSONByteLength > 0) 106 | { 107 | featureTable = b3dm_FeatureTable::create(); 108 | 109 | vsg::JSONParser parser; 110 | parser.buffer.resize(header.featureTableJSONByteLength); 111 | fin.read(parser.buffer.data(), header.featureTableJSONByteLength); 112 | 113 | if (header.featureTableBinaryByteLength > 0) 114 | { 115 | featureTable->binary = vsg::ubyteArray::create(header.featureTableBinaryByteLength); 116 | fin.read(reinterpret_cast(featureTable->binary->dataPointer()), header.featureTableBinaryByteLength); 117 | } 118 | 119 | parser.read_object(*featureTable); 120 | } 121 | 122 | vsg::ref_ptr batchTable = BatchTable::create(); 123 | 124 | if (header.batchTableJSONByteLength > 0) 125 | { 126 | vsg::JSONParser parser; 127 | parser.buffer.resize(header.batchTableJSONByteLength); 128 | fin.read(parser.buffer.data(), header.batchTableJSONByteLength); 129 | 130 | if (header.batchTableBinaryLength > 0 ) 131 | { 132 | batchTable->binary = vsg::ubyteArray::create(header.batchTableBinaryLength); 133 | fin.read(reinterpret_cast(batchTable->binary->dataPointer()), header.batchTableBinaryLength); 134 | } 135 | 136 | parser.read_object(*batchTable); 137 | 138 | batchTable->length = featureTable->BATCH_LENGTH; 139 | batchTable->convert(); 140 | } 141 | 142 | if (vsg::value(false, gltf::report, options)) 143 | { 144 | vsg::LogOutput output; 145 | 146 | output("Tiles3D::read_b3dm()"); 147 | output("magic = ", header.magic); 148 | output("version = ", header.version); 149 | output("byteLength = ", header.byteLength); 150 | output("featureTableJSONByteLength = ", header.featureTableJSONByteLength); 151 | output("featureTableBinaryByteLength = ", header.featureTableBinaryByteLength); 152 | output("batchTableJSONByteLength = ", header.batchTableJSONByteLength); 153 | output("batchTableBinaryLength = ", header.batchTableBinaryLength); 154 | 155 | vsg::LogOutput log; 156 | 157 | if (featureTable) featureTable->report(output); 158 | if (batchTable) batchTable->report(output); 159 | } 160 | 161 | 162 | uint32_t size_of_feature_and_batch_tables = header.featureTableJSONByteLength + header.featureTableBinaryByteLength + header.batchTableJSONByteLength + header.batchTableBinaryLength; 163 | uint32_t size_of_gltfField = header.byteLength - sizeof(Header) - size_of_feature_and_batch_tables; 164 | 165 | // TODO: need to modify glTF loader to handle batched value assessor. 166 | // https://github.com/CesiumGS/3d-tiles/tree/1.0/specification/TileFormats/Batched3DModel#batch-table 167 | 168 | std::string binary; 169 | binary.resize(size_of_gltfField); 170 | fin.read(binary.data(), size_of_gltfField); 171 | 172 | vsg::mem_stream binary_fin(reinterpret_cast(binary.data()), binary.size()); 173 | 174 | auto opt = vsg::clone(options); 175 | opt->extensionHint = ".glb"; 176 | 177 | auto model = vsg::read_cast(binary_fin, opt); 178 | 179 | if (model && filename) model->setValue("b3dm", filename); 180 | 181 | return model; 182 | } 183 | 184 | -------------------------------------------------------------------------------- /src/3DTiles/build_vars.cmake: -------------------------------------------------------------------------------- 1 | set(SOURCES ${SOURCES} 2 | 3DTiles/3DTiles.cpp 3 | 3DTiles/i3dm.cpp 4 | 3DTiles/b3dm.cpp 5 | 3DTiles/cmpt.cpp 6 | 3DTiles/SceneGraphBuilder.cpp 7 | ) 8 | -------------------------------------------------------------------------------- /src/3DTiles/cmpt.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright(c) 2025 Robert Osfield 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | 11 | */ 12 | 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | using namespace vsgXchange; 28 | 29 | vsg::ref_ptr Tiles3D::read_cmpt(std::istream& fin, vsg::ref_ptr options, const vsg::Path& filename) const 30 | { 31 | fin.seekg(0); 32 | 33 | // https://github.com/CesiumGS/3d-tiles/blob/main/specification/TileFormats/Composite/README.adoc 34 | struct Header 35 | { 36 | char magic[4] = {0,0,0,0}; 37 | uint32_t version = 0; 38 | uint32_t byteLength = 0; 39 | uint32_t tilesLength = 0; 40 | }; 41 | 42 | struct InnerHeader 43 | { 44 | char magic[4] = {0,0,0,0}; 45 | uint32_t version = 0; 46 | uint32_t byteLength = 0; 47 | }; 48 | 49 | Header header; 50 | fin.read(reinterpret_cast(&header), sizeof(Header)); 51 | 52 | if (!fin.good()) 53 | { 54 | vsg::warn("IO error reading cmpt file."); 55 | return {}; 56 | } 57 | 58 | if (strncmp(header.magic, "cmpt", 4) != 0) 59 | { 60 | vsg::warn("magic number not cmpt"); 61 | return {}; 62 | } 63 | 64 | uint32_t sizeOfTiles = header.byteLength - sizeof(Header); 65 | std::string binary; 66 | binary.resize(sizeOfTiles); 67 | fin.read(binary.data(), sizeOfTiles); 68 | if (!fin.good()) 69 | { 70 | vsg::warn("IO error reading cmpt file."); 71 | return {}; 72 | } 73 | 74 | auto group = vsg::Group::create(); 75 | std::list innerHeaders; 76 | uint32_t pos = 0; 77 | for(uint32_t i=0; i < header.tilesLength; ++i) 78 | { 79 | InnerHeader* tile = reinterpret_cast(&binary[pos]); 80 | innerHeaders.push_back(*tile); 81 | 82 | vsg::mem_stream binary_fin(reinterpret_cast(&binary[pos]), tile->byteLength); 83 | pos += tile->byteLength; 84 | 85 | std::string ext = "."; 86 | for(int c = 0; c<4; ++c) 87 | { 88 | if (tile->magic[c] != 0) ext.push_back(tile->magic[c]); 89 | else break; 90 | } 91 | 92 | auto opt = vsg::clone(options); 93 | opt->extensionHint = ext; 94 | 95 | #if 0 96 | // force axis to Z up. 97 | auto upAxis = vsg::CoordinateConvention::Z_UP; 98 | opt->formatCoordinateConventions[".gltf"] = upAxis; 99 | opt->formatCoordinateConventions[".glb"] = upAxis; 100 | #endif 101 | 102 | if (auto model = vsg::read_cast(binary_fin, opt)) 103 | { 104 | group->addChild(model); 105 | } 106 | } 107 | 108 | if (vsg::value(false, gltf::report, options)) 109 | { 110 | vsg::LogOutput output; 111 | 112 | output("Tiles3D::read_cmpt(..)"); 113 | output("magic = ", header.magic); 114 | output("version = ", header.version); 115 | output("byteLength = ", header.byteLength); 116 | output("tilesLength = ", header.tilesLength); 117 | 118 | output("innerHeaders.size() = ", innerHeaders.size()); 119 | for(auto& innerHeader : innerHeaders) 120 | { 121 | output(" {", innerHeader.magic, ", ", innerHeader.version, ", ", innerHeader.byteLength, " }"); 122 | } 123 | } 124 | 125 | vsg::ref_ptr model; 126 | 127 | if (group->children.size()==1) model = group->children[0]; 128 | else if (!group->children.empty()) model = group; 129 | 130 | if (model && filename) model->setValue("b3dm", filename); 131 | 132 | return model; 133 | } 134 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # vars used to enable subdirectories to extend the build of the vsgXchange library in a loosely coupled way 3 | set(EXTRA_DEFINES) 4 | set(EXTRA_INCLUDES) 5 | 6 | SET(HEADER_PATH ${VSGXCHANGE_SOURCE_DIR}/include/vsgXchange) 7 | 8 | set(HEADERS 9 | ${VSGXCHANGE_VERSION_HEADER} 10 | ${HEADER_PATH}/Export.h 11 | ${HEADER_PATH}/all.h 12 | ${HEADER_PATH}/cpp.h 13 | ${HEADER_PATH}/freetype.h 14 | ${HEADER_PATH}/images.h 15 | ${HEADER_PATH}/models.h 16 | ${HEADER_PATH}/gltf.h 17 | ${HEADER_PATH}/3DTiles.h 18 | ) 19 | 20 | set(SOURCES 21 | all/Version.cpp 22 | all/all.cpp 23 | cpp/cpp.cpp 24 | stbi/stbi.cpp 25 | dds/dds.cpp 26 | images/images.cpp 27 | bin/bin.cpp 28 | ) 29 | 30 | # add gltf 31 | include(gltf/build_vars.cmake) 32 | 33 | # add 3D Tiles 34 | include(3DTiles/build_vars.cmake) 35 | 36 | # add freetype if available 37 | include(freetype/build_vars.cmake) 38 | 39 | # add assimp if available 40 | include(assimp/build_vars.cmake) 41 | 42 | # add ktx 43 | include(ktx/build_vars.cmake) 44 | 45 | # add optional GDAL component 46 | include(gdal/build_vars.cmake) 47 | 48 | # add optional CURL component 49 | include(curl/build_vars.cmake) 50 | 51 | # add optional OpenEXR component 52 | include(openexr/build_vars.cmake) 53 | 54 | # create the version header 55 | set(VSGXCHANGE_VERSION_HEADER "${VSGXCHANGE_BINARY_DIR}/include/vsgXchange/Version.h") 56 | configure_file("${VSGXCHANGE_SOURCE_DIR}/src/all/Version.h.in" "${VSGXCHANGE_VERSION_HEADER}") 57 | 58 | 59 | # create the vsgXchange library 60 | add_library(vsgXchange ${HEADERS} ${SOURCES}) 61 | 62 | # add definitions to enable building vsgXchange as part of submodule 63 | add_library(vsgXchange::vsgXchange ALIAS vsgXchange) 64 | set(vsgXchange_FOUND TRUE CACHE INTERNAL "vsgXchange found.") 65 | set(CMAKE_DISABLE_FIND_PACKAGE_vsgXchange TRUE CACHE INTERNAL "Disable find_package(vsgXchange) as it's not necessary.") 66 | 67 | 68 | set_property(TARGET vsgXchange PROPERTY VERSION ${VSGXCHANGE_VERSION_MAJOR}.${VSGXCHANGE_VERSION_MINOR}.${VSGXCHANGE_VERSION_PATCH}) 69 | set_property(TARGET vsgXchange PROPERTY SOVERSION ${VSGXCHANGE_SOVERSION}) 70 | set_property(TARGET vsgXchange PROPERTY POSITION_INDEPENDENT_CODE ON) 71 | set_property(TARGET vsgXchange PROPERTY CXX_STANDARD 17) 72 | 73 | target_compile_definitions(vsgXchange PRIVATE ${EXTRA_DEFINES}) 74 | 75 | target_include_directories(vsgXchange 76 | PUBLIC 77 | $ 78 | $ 79 | $ 80 | PRIVATE 81 | ${EXTRA_INCLUDES} 82 | ) 83 | 84 | target_link_libraries(vsgXchange 85 | PUBLIC 86 | vsg::vsg 87 | PRIVATE 88 | ${EXTRA_LIBRARIES} 89 | ) 90 | 91 | install(TARGETS vsgXchange ${INSTALL_TARGETS_DEFAULT_FLAGS}) 92 | 93 | if (BUILD_SHARED_LIBS) 94 | target_compile_definitions(vsgXchange INTERFACE VSGXCHANGE_SHARED_LIBRARY) 95 | endif() 96 | 97 | install(DIRECTORY ${VSGXCHANGE_SOURCE_DIR}/include/vsgXchange DESTINATION include) 98 | if (NOT(${VSGXCHANGE_BINARY_DIR} STREQUAL ${VSGXCHANGE_SOURCE_DIR})) 99 | install(DIRECTORY ${VSGXCHANGE_BINARY_DIR}/include/vsgXchange DESTINATION include) 100 | endif() 101 | 102 | string(REPLACE ";" "\n" FIND_DEPENDENCY_OUT "${FIND_DEPENDENCY}") 103 | vsg_add_cmake_support_files( 104 | CONFIG_TEMPLATE 105 | vsgXchangeConfig.cmake.in 106 | ) 107 | -------------------------------------------------------------------------------- /src/all/Version.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright(c) 2018 Robert Osfield 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | 11 | */ 12 | 13 | #include 14 | 15 | extern "C" 16 | { 17 | 18 | VsgVersion vsgXchangeGetVersion() 19 | { 20 | VsgVersion version; 21 | version.major = VSGXCHANGE_VERSION_MAJOR; 22 | version.minor = VSGXCHANGE_VERSION_MINOR; 23 | version.patch = VSGXCHANGE_VERSION_PATCH; 24 | version.soversion = VSGXCHANGE_SOVERSION; 25 | return version; 26 | } 27 | 28 | const char* vsgXchangeGetVersionString() 29 | { 30 | return VSGXCHANGE_VERSION_STRING; 31 | } 32 | 33 | const char* vsgXchangeGetSOVersionString() 34 | { 35 | return VSGXCHANGE_SOVERSION_STRING; 36 | } 37 | 38 | int vsgXchangeBuiltAsSharedLibrary() 39 | { 40 | #ifdef vsgXchange_EXPORTS 41 | return 1; 42 | #else 43 | return 0; 44 | #endif 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/all/Version.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright(c) 2021 Robert Osfield 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | 11 | */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | #define VSGXCHANGE_VERSION_MAJOR @VSGXCHANGE_VERSION_MAJOR@ 24 | #define VSGXCHANGE_VERSION_MINOR @VSGXCHANGE_VERSION_MINOR@ 25 | #define VSGXCHANGE_VERSION_PATCH @VSGXCHANGE_VERSION_PATCH@ 26 | #define VSGXCHANGE_SOVERSION @VSGXCHANGE_SOVERSION@ 27 | 28 | #define VSGXCHANGE_VERSION_STRING "@VSGXCHANGE_VERSION_MAJOR@.@VSGXCHANGE_VERSION_MINOR@.@VSGXCHANGE_VERSION_PATCH@" 29 | #define VSGXCHANGE_SOVERSION_STRING "@VSGXCHANGE_SOVERSION@" 30 | 31 | extern VSGXCHANGE_DECLSPEC struct VsgVersion vsgXchangeGetVersion(); 32 | extern VSGXCHANGE_DECLSPEC const char* vsgXchangeGetVersionString(); 33 | extern VSGXCHANGE_DECLSPEC const char* vsgXchangeGetSOVersionString(); 34 | 35 | /// return 0 if the linked vsgXchange was built as static library (default), 1 if the linked vsgXchange library was built as shared/dynamic library. 36 | /// When building against a shared library, to ensure the correct selection of VSGXCHANGE_DECLSPEC (provided in vsgXchange/Export.h) one must compile with the define VSGXCHANGE_SHARED_LIBRARY 37 | extern VSGXCHANGE_DECLSPEC int vsgXchangeBuiltAsSharedLibrary(); 38 | 39 | /// standard Features 40 | #define vsgXchange_all 41 | #define vsgXchange_images 42 | #define vsgXchange_models 43 | #define vsgXchange_stbi 44 | #define vsgXchange_dds 45 | #define vsgXchange_ktx 46 | #define vsgXchange_spv 47 | #define vsgXchange_cpp 48 | #define vsgXchange_gltf 49 | #define vsgXchange_3DTiles 50 | 51 | /// optional Features 52 | #cmakedefine vsgXchange_curl 53 | #cmakedefine vsgXchange_draco 54 | #cmakedefine vsgXchange_openexr 55 | #cmakedefine vsgXchange_freetype 56 | #cmakedefine vsgXchange_assimp 57 | #cmakedefine vsgXchange_GDAL 58 | #cmakedefine vsgXchange_OSG 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | -------------------------------------------------------------------------------- /src/all/all.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright(c) 2021 Robert Osfield 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #ifdef vsgXchange_OSG 32 | # include 33 | #endif 34 | 35 | using namespace vsgXchange; 36 | 37 | void vsgXchange::init() 38 | { 39 | static bool s_vsgXchange_initialized = false; 40 | if (s_vsgXchange_initialized) return; 41 | s_vsgXchange_initialized = true; 42 | 43 | vsg::debug("vsgXchange::init()"); 44 | 45 | vsg::ObjectFactory::instance()->add(); 46 | vsg::ObjectFactory::instance()->add(); 47 | 48 | vsg::ObjectFactory::instance()->add(); 49 | 50 | vsg::ObjectFactory::instance()->add(); 51 | vsg::ObjectFactory::instance()->add(); 52 | vsg::ObjectFactory::instance()->add(); 53 | 54 | vsg::ObjectFactory::instance()->add(); 55 | vsg::ObjectFactory::instance()->add(); 56 | vsg::ObjectFactory::instance()->add(); 57 | 58 | vsg::ObjectFactory::instance()->add(); 59 | vsg::ObjectFactory::instance()->add(); 60 | vsg::ObjectFactory::instance()->add(); 61 | vsg::ObjectFactory::instance()->add(); 62 | // vsg::ObjectFactory::instance()->add(); 63 | } 64 | 65 | all::all() 66 | { 67 | // for convenience make sure the init() method is called 68 | vsgXchange::init(); 69 | 70 | #ifdef vsgXchange_curl 71 | add(curl::create()); 72 | #endif 73 | 74 | add(vsg::VSG::create()); 75 | add(vsg::spirv::create()); 76 | add(vsg::glsl::create()); 77 | 78 | add(bin::create()); 79 | add(gltf::create()); 80 | add(Tiles3D::create()); 81 | 82 | add(vsg::json::create()); 83 | 84 | add(cpp::create()); 85 | 86 | add(vsg::txt::create()); 87 | 88 | add(stbi::create()); 89 | add(dds::create()); 90 | add(ktx::create()); 91 | 92 | #ifdef vsgXchange_openexr 93 | add(openexr::create()); 94 | #endif 95 | 96 | #ifdef vsgXchange_freetype 97 | add(freetype::create()); 98 | #endif 99 | 100 | #ifdef vsgXchange_assimp 101 | add(assimp::create()); 102 | #endif 103 | 104 | #ifdef vsgXchange_GDAL 105 | add(GDAL::create()); 106 | #endif 107 | 108 | #ifdef vsgXchange_OSG 109 | add(osg2vsg::OSG::create()); 110 | #endif 111 | } 112 | -------------------------------------------------------------------------------- /src/assimp/assimp_fallback.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright(c) 2021 Robert Osfield 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | 11 | */ 12 | 13 | #include 14 | 15 | using namespace vsgXchange; 16 | 17 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 18 | // 19 | // assimp ReaderWriter fallback 20 | // 21 | class assimp::Implementation 22 | { 23 | }; 24 | assimp::assimp() : 25 | _implementation(nullptr) 26 | { 27 | } 28 | assimp::~assimp() 29 | { 30 | } 31 | vsg::ref_ptr assimp::read(const vsg::Path&, vsg::ref_ptr) const 32 | { 33 | return {}; 34 | } 35 | vsg::ref_ptr assimp::read(std::istream&, vsg::ref_ptr) const 36 | { 37 | return {}; 38 | } 39 | vsg::ref_ptr assimp::read(const uint8_t*, size_t, vsg::ref_ptr) const 40 | { 41 | return {}; 42 | } 43 | bool assimp::getFeatures(Features&) const 44 | { 45 | return false; 46 | } 47 | bool assimp::readOptions(vsg::Options&, vsg::CommandLine&) const 48 | { 49 | return false; 50 | } 51 | -------------------------------------------------------------------------------- /src/assimp/build_vars.cmake: -------------------------------------------------------------------------------- 1 | # add assimp if available 2 | find_package(assimp 5.1 QUIET) 3 | 4 | if(assimp_FOUND) 5 | OPTION(vsgXchange_assimp "Optional Assimp support provided" ON) 6 | endif() 7 | 8 | if (${vsgXchange_assimp}) 9 | 10 | string(REPLACE "." ";" ASSIMP_VERSION_LIST ${assimp_VERSION}) 11 | list(GET ASSIMP_VERSION_LIST 0 ASSIMP_VERSION_MAJOR) 12 | list(GET ASSIMP_VERSION_LIST 1 ASSIMP_VERSION_MINOR) 13 | list(GET ASSIMP_VERSION_LIST 2 ASSIMP_VERSION_PATCH) 14 | 15 | set(EXTRA_DEFINES ${EXTRA_DEFINES} "ASSIMP_VERSION_MAJOR=${ASSIMP_VERSION_MAJOR}" "ASSIMP_VERSION_MINOR=${ASSIMP_VERSION_MINOR}" "ASSIMP_VERSION_PATCH=${ASSIMP_VERSION_PATCH}" ) 16 | 17 | set(SOURCES ${SOURCES} 18 | assimp/assimp.cpp 19 | assimp/SceneConverter.cpp 20 | ) 21 | set(EXTRA_INCLUDES ${EXTRA_INCLUDES} ${assimp_INCLUDE_DIRS}) 22 | set(EXTRA_LIBRARIES ${EXTRA_LIBRARIES} assimp::assimp) 23 | if(NOT BUILD_SHARED_LIBS) 24 | set(FIND_DEPENDENCY ${FIND_DEPENDENCY} "find_dependency(assimp)") 25 | endif() 26 | else() 27 | set(SOURCES ${SOURCES} 28 | assimp/assimp_fallback.cpp 29 | ) 30 | endif() 31 | -------------------------------------------------------------------------------- /src/bin/bin.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright(c) 2025 Robert Osfield 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | 11 | */ 12 | 13 | //#include 14 | 15 | #include 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | using namespace vsgXchange; 25 | 26 | 27 | 28 | bin::bin() 29 | { 30 | } 31 | 32 | vsg::ref_ptr bin::_read(std::istream& fin) const 33 | { 34 | fin.seekg(0, fin.end); 35 | size_t fileSize = fin.tellg(); 36 | 37 | if (fileSize==0) return {}; 38 | 39 | auto data = vsg::ubyteArray::create(fileSize); 40 | 41 | fin.seekg(0); 42 | fin.read(reinterpret_cast(data->dataPointer()), fileSize); 43 | 44 | return data; 45 | } 46 | 47 | 48 | vsg::ref_ptr bin::read(const vsg::Path& filename, vsg::ref_ptr options) const 49 | { 50 | vsg::Path ext = (options && options->extensionHint) ? options->extensionHint : vsg::lowerCaseFileExtension(filename); 51 | if (!supportedExtension(ext)) return {}; 52 | 53 | vsg::Path filenameToUse = vsg::findFile(filename, options); 54 | if (!filenameToUse) return {}; 55 | 56 | std::ifstream fin(filenameToUse, std::ios::ate | std::ios::binary); 57 | return _read(fin); 58 | } 59 | 60 | vsg::ref_ptr bin::read(std::istream& fin, vsg::ref_ptr options) const 61 | { 62 | if (!options || !options->extensionHint) return {}; 63 | if (!supportedExtension(options->extensionHint)) return {}; 64 | 65 | return _read(fin); 66 | } 67 | 68 | vsg::ref_ptr bin::read(const uint8_t* ptr, size_t size, vsg::ref_ptr options) const 69 | { 70 | if (!options || !options->extensionHint) return {}; 71 | if (!supportedExtension(options->extensionHint)) return {}; 72 | 73 | vsg::mem_stream fin(ptr, size); 74 | return _read(fin); 75 | } 76 | 77 | bool bin::supportedExtension(const vsg::Path& ext) const 78 | { 79 | return (ext == ".bin"); 80 | } 81 | 82 | bool bin::getFeatures(Features& features) const 83 | { 84 | vsg::ReaderWriter::FeatureMask supported_features = static_cast(vsg::ReaderWriter::READ_FILENAME | vsg::ReaderWriter::READ_ISTREAM | vsg::ReaderWriter::READ_MEMORY); 85 | features.extensionFeatureMap[".bin"] = supported_features; 86 | 87 | return true; 88 | } 89 | -------------------------------------------------------------------------------- /src/cpp/cpp.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright(c) 2018 Robert Osfield 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | 11 | */ 12 | 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | using namespace vsgXchange; 22 | 23 | cpp::cpp() 24 | { 25 | } 26 | 27 | bool cpp::write(const vsg::Object* object, const vsg::Path& filename, vsg::ref_ptr options) const 28 | { 29 | auto ext = vsg::lowerCaseFileExtension(filename); 30 | if (ext != ".cpp") return false; 31 | 32 | std::cout << "cpp::write(" << object->className() << ", " << filename << ")" << std::endl; 33 | 34 | auto funcname = vsg::simpleFilename(filename); 35 | 36 | bool binary = options ? (options->extensionHint == ".vsgb") : false; 37 | 38 | auto local_options = vsg::Options::create(); 39 | local_options->extensionHint = binary ? ".vsgb" : ".vsgt"; 40 | 41 | // serialize object(s) to string 42 | std::ostringstream str; 43 | vsg::VSG io; 44 | io.write(object, str, local_options); 45 | std::string s = str.str(); 46 | 47 | std::ofstream fout(filename); 48 | fout << "#include \n"; 49 | fout << "#include \n"; 50 | fout << "static auto " << funcname << " = []() {\n"; 51 | 52 | if (binary || s.size() > 65535) 53 | { 54 | // long string has to be handled as a byte array as VisualStudio can't handle long strings. 55 | fout << "static const uint8_t data[] = {\n"; 56 | fout << uint32_t(uint8_t(s[0])); 57 | for (size_t i = 1; i < s.size(); ++i) 58 | { 59 | if ((i % 32) == 0) 60 | fout << ",\n"; 61 | else 62 | fout << ", "; 63 | fout << uint32_t(uint8_t(s[i])); 64 | } 65 | fout << " };\n"; 66 | //fout<<"vsg::mem_stream str(data, sizeof(data));\n"; 67 | fout << "vsg::VSG io;\n"; 68 | fout << "return io.read_cast<" << object->className() << ">(data, sizeof(data));\n"; 69 | } 70 | else 71 | { 72 | fout << "static const char str[] = \n"; 73 | write(fout, str.str()); 74 | fout << ";\n"; 75 | fout << "vsg::VSG io;\n"; 76 | fout << "return io.read_cast<" << object->className() << ">(reinterpret_cast(str), sizeof(str));\n"; 77 | } 78 | 79 | fout << "};\n"; 80 | fout.close(); 81 | 82 | return true; 83 | } 84 | 85 | void cpp::write(std::ostream& out, const std::string& str) const 86 | { 87 | std::size_t max_string_literal_length = 16360; 88 | if (str.size() > max_string_literal_length) 89 | { 90 | std::size_t n = 0; 91 | while ((n + max_string_literal_length) < str.size()) 92 | { 93 | auto pos_previous_end_of_line = str.find_last_of("\n", n + max_string_literal_length); 94 | if (pos_previous_end_of_line > n) 95 | { 96 | out << "R\"(" << str.substr(n, pos_previous_end_of_line + 1 - n) << ")\"\n"; 97 | n = pos_previous_end_of_line + 1; 98 | } 99 | else 100 | { 101 | out << "R\"(" << str.substr(n, max_string_literal_length) << ")\" "; 102 | n += max_string_literal_length; 103 | } 104 | } 105 | 106 | if (n < str.size()) 107 | { 108 | out << "R\"(" << str.substr(n, std::string::npos) << ")\""; 109 | } 110 | } 111 | else 112 | { 113 | out << "R\"(" << str << ")\""; 114 | } 115 | } 116 | 117 | bool cpp::getFeatures(Features& features) const 118 | { 119 | features.extensionFeatureMap[".cpp"] = vsg::ReaderWriter::WRITE_FILENAME; 120 | return true; 121 | } 122 | -------------------------------------------------------------------------------- /src/curl/build_vars.cmake: -------------------------------------------------------------------------------- 1 | # add CURL if available 2 | find_package(CURL) 3 | 4 | if(CURL_FOUND) 5 | OPTION(vsgXchange_curl "Optional CURL support provided" ON) 6 | endif() 7 | 8 | if(${vsgXchange_curl}) 9 | set(SOURCES ${SOURCES} 10 | curl/curl.cpp 11 | ) 12 | if(TARGET CURL::libcurl) 13 | set(EXTRA_LIBRARIES ${EXTRA_LIBRARIES} CURL::libcurl) 14 | else() 15 | set(EXTRA_LIBRARIES ${EXTRA_LIBRARIES} ${CURL_LIBRARIES}) 16 | set(EXTRA_INCLUDES ${EXTRA_INCLUDES} ${CURL_INCLUDE_DIR}) 17 | endif() 18 | if(NOT BUILD_SHARED_LIBS) 19 | set(FIND_DEPENDENCY ${FIND_DEPENDENCY} "find_dependency(CURL)") 20 | endif() 21 | else() 22 | set(SOURCES ${SOURCES} 23 | curl/curl_fallback.cpp 24 | ) 25 | endif() 26 | -------------------------------------------------------------------------------- /src/curl/curl_fallback.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright(c) 2021 Robert Osfield 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | 11 | */ 12 | 13 | #include 14 | 15 | using namespace vsgXchange; 16 | 17 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 18 | // 19 | // curl ReaderWriter fallback 20 | // 21 | class curl::Implementation 22 | { 23 | }; 24 | curl::curl() : 25 | _implementation(nullptr) 26 | { 27 | } 28 | curl::~curl() 29 | { 30 | } 31 | vsg::ref_ptr curl::read(const vsg::Path&, vsg::ref_ptr) const 32 | { 33 | return {}; 34 | } 35 | bool curl::getFeatures(Features&) const 36 | { 37 | return false; 38 | } 39 | -------------------------------------------------------------------------------- /src/freetype/build_vars.cmake: -------------------------------------------------------------------------------- 1 | # add freetype if available 2 | find_package(Freetype) 3 | 4 | if(FREETYPE_FOUND) 5 | OPTION(vsgXchange_freetype "Freetype support provided" ON) 6 | endif() 7 | 8 | if(${vsgXchange_freetype}) 9 | set(SOURCES ${SOURCES} 10 | freetype/freetype.cpp 11 | ) 12 | set(EXTRA_INCLUDES ${EXTRA_INCLUDES} ${FREETYPE_INCLUDE_DIRS}) 13 | set(EXTRA_LIBRARIES ${EXTRA_LIBRARIES} ${FREETYPE_LIBRARIES}) 14 | set(EXTRA_DEFINES ${EXTRA_DEFINES} USE_FREETYPE) 15 | 16 | if(NOT BUILD_SHARED_LIBS) 17 | set(FIND_DEPENDENCY ${FIND_DEPENDENCY} "find_dependency(Freetype)") 18 | endif() 19 | else() 20 | set(SOURCES ${SOURCES} 21 | freetype/freetype_fallback.cpp 22 | ) 23 | endif() 24 | -------------------------------------------------------------------------------- /src/freetype/freetype_fallback.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright(c) 2020 Robert Osfield 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | 11 | */ 12 | 13 | #include 14 | 15 | using namespace vsgXchange; 16 | 17 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 18 | // 19 | // freetype ReaderWriter fallback 20 | // 21 | class freetype::Implementation 22 | { 23 | }; 24 | freetype::freetype() : 25 | _implementation(nullptr) 26 | { 27 | } 28 | freetype::~freetype(){}; 29 | vsg::ref_ptr freetype::read(const vsg::Path&, vsg::ref_ptr) const 30 | { 31 | return {}; 32 | } 33 | bool freetype::getFeatures(Features&) const 34 | { 35 | return false; 36 | } 37 | bool freetype::readOptions(vsg::Options&, vsg::CommandLine&) const 38 | { 39 | return false; 40 | } 41 | -------------------------------------------------------------------------------- /src/gdal/GDAL.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright(c) 2021 Robert Osfield 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | using namespace vsgXchange; 20 | 21 | namespace vsgXchange 22 | { 23 | 24 | class GDAL::Implementation 25 | { 26 | public: 27 | Implementation(); 28 | 29 | vsg::ref_ptr read(const vsg::Path& filename, vsg::ref_ptr options = {}) const; 30 | vsg::ref_ptr read(std::istream& fin, vsg::ref_ptr options) const; 31 | vsg::ref_ptr read(const uint8_t* ptr, size_t size, vsg::ref_ptr options) const; 32 | 33 | protected: 34 | }; 35 | 36 | } // namespace vsgXchange 37 | 38 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 39 | // 40 | // GDAL ReaderWriter facade 41 | // 42 | GDAL::GDAL() : 43 | _implementation(new GDAL::Implementation()) 44 | { 45 | } 46 | 47 | GDAL::~GDAL() 48 | { 49 | delete _implementation; 50 | } 51 | 52 | vsg::ref_ptr GDAL::read(const vsg::Path& filename, vsg::ref_ptr options) const 53 | { 54 | return _implementation->read(filename, options); 55 | } 56 | 57 | vsg::ref_ptr GDAL::read(std::istream& fin, vsg::ref_ptr options) const 58 | { 59 | return _implementation->read(fin, options); 60 | } 61 | vsg::ref_ptr GDAL::read(const uint8_t* ptr, size_t size, vsg::ref_ptr options) const 62 | { 63 | return _implementation->read(ptr, size, options); 64 | } 65 | 66 | bool GDAL::getFeatures(Features& features) const 67 | { 68 | vsgXchange::initGDAL(); 69 | 70 | auto driverManager = GetGDALDriverManager(); 71 | int driverCount = driverManager->GetDriverCount(); 72 | 73 | vsg::ReaderWriter::FeatureMask rasterFeatureMask = vsg::ReaderWriter::READ_FILENAME; 74 | 75 | const std::string dotPrefix = "."; 76 | 77 | for (int i = 0; i < driverCount; ++i) 78 | { 79 | auto driver = driverManager->GetDriver(i); 80 | auto raster_meta = driver->GetMetadataItem(GDAL_DCAP_RASTER); 81 | auto extensions_meta = driver->GetMetadataItem(GDAL_DMD_EXTENSIONS); 82 | // auto longname_meta = driver->GetMetadataItem( GDAL_DMD_LONGNAME ); 83 | if (raster_meta && extensions_meta) 84 | { 85 | std::string extensions = extensions_meta; 86 | std::string ext; 87 | 88 | std::string::size_type start_pos = 0; 89 | for (;;) 90 | { 91 | start_pos = extensions.find_first_not_of(" .", start_pos); 92 | if (start_pos == std::string::npos) break; 93 | 94 | std::string::size_type delimiter_pos = extensions.find_first_of(" /", start_pos); 95 | if (delimiter_pos != std::string::npos) 96 | { 97 | ext = extensions.substr(start_pos, delimiter_pos - start_pos); 98 | features.extensionFeatureMap[dotPrefix + ext] = rasterFeatureMask; 99 | start_pos = delimiter_pos + 1; 100 | if (start_pos == extensions.length()) break; 101 | } 102 | else 103 | { 104 | ext = extensions.substr(start_pos, std::string::npos); 105 | features.extensionFeatureMap[dotPrefix + ext] = rasterFeatureMask; 106 | break; 107 | } 108 | } 109 | } 110 | } 111 | 112 | return true; 113 | } 114 | 115 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 116 | // 117 | // GDAL ReaderWriter implementation 118 | // 119 | GDAL::Implementation::Implementation() 120 | { 121 | } 122 | 123 | vsg::ref_ptr GDAL::Implementation::read(const vsg::Path& filename, vsg::ref_ptr options) const 124 | { 125 | // GDAL tries to load all datatypes so up front catch VSG and OSG native formats. 126 | vsg::Path ext = vsg::lowerCaseFileExtension(filename); 127 | if (ext == ".vsgb" || ext == ".vsgt" || ext == ".osgb" || ext == ".osgt" || ext == ".osg" || ext == ".tile") return {}; 128 | 129 | vsg::Path filenameToUse = (vsg::filePath(filename) == "/vsimem") ? filename : vsg::findFile(filename, options); 130 | 131 | if (!filenameToUse) return {}; 132 | 133 | vsgXchange::initGDAL(); 134 | 135 | auto dataset = vsgXchange::openSharedDataSet(filenameToUse, GA_ReadOnly); 136 | if (!dataset) 137 | { 138 | return {}; 139 | } 140 | 141 | auto types = vsgXchange::dataTypes(*dataset); 142 | if (types.size() > 1) 143 | { 144 | vsg::info("GDAL::read(", filename, ") multiple input data types not supported."); 145 | for (auto& type : types) 146 | { 147 | vsg::info(" GDALDataType ", GDALGetDataTypeName(type)); 148 | } 149 | return {}; 150 | } 151 | if (types.empty()) 152 | { 153 | vsg::info("GDAL::read(", filename, ") types set empty."); 154 | 155 | return {}; 156 | } 157 | 158 | GDALDataType dataType = *types.begin(); 159 | 160 | std::vector rasterBands; 161 | for (int i = 1; i <= dataset->GetRasterCount(); ++i) 162 | { 163 | GDALRasterBand* band = dataset->GetRasterBand(i); 164 | GDALColorInterp classification = band->GetColorInterpretation(); 165 | 166 | if (classification != GCI_Undefined) 167 | { 168 | rasterBands.push_back(band); 169 | } 170 | else 171 | { 172 | vsg::info("GDAL::read(", filename, ") Undefined classification on raster band ", i); 173 | } 174 | } 175 | 176 | int numComponents = static_cast(rasterBands.size()); 177 | if (numComponents == 0) 178 | { 179 | vsg::info("GDAL::read(", filename, ") failed numComponents = ", numComponents); 180 | return {}; 181 | } 182 | 183 | bool mapRGBtoRGBAHint = !options || options->mapRGBtoRGBAHint; 184 | if (mapRGBtoRGBAHint && numComponents == 3) 185 | { 186 | //std::cout<<"Remapping RGB to RGBA "< 4) 191 | { 192 | vsg::info("GDAL::read(", filename, ") Too many raster bands to merge into a single output, maximum of 4 raster bands supported."); 193 | return {}; 194 | } 195 | 196 | int width = dataset->GetRasterXSize(); 197 | int height = dataset->GetRasterYSize(); 198 | 199 | auto image = vsgXchange::createImage2D(width, height, numComponents, dataType, vsg::dvec4(0.0, 0.0, 0.0, 1.0)); 200 | if (!image) return {}; 201 | 202 | for (int component = 0; component < static_cast(rasterBands.size()); ++component) 203 | { 204 | vsgXchange::copyRasterBandToImage(*rasterBands[component], *image, component); 205 | } 206 | 207 | vsgXchange::assignMetaData(*dataset, *image); 208 | 209 | if (dataset->GetProjectionRef() && std::strlen(dataset->GetProjectionRef()) > 0) 210 | { 211 | image->setValue("ProjectionRef", std::string(dataset->GetProjectionRef())); 212 | } 213 | 214 | auto transform = vsg::doubleArray::create(6); 215 | if (dataset->GetGeoTransform(transform->data()) == CE_None) 216 | { 217 | image->setObject("GeoTransform", transform); 218 | } 219 | 220 | return image; 221 | } 222 | 223 | vsg::ref_ptr GDAL::Implementation::read(std::istream& fin, vsg::ref_ptr options) const 224 | { 225 | // if (!vsg::compatibleExtension(options, _supportedExtensions)) return {}; 226 | 227 | std::string input; 228 | std::stringstream* sstr = dynamic_cast(&fin); 229 | if (sstr) 230 | { 231 | input = sstr->str(); 232 | } 233 | else 234 | { 235 | std::string buffer(1 << 16, 0); // 64kB 236 | while (!fin.eof()) 237 | { 238 | fin.read(&buffer[0], buffer.size()); 239 | const auto bytes_readed = fin.gcount(); 240 | input.append(&buffer[0], bytes_readed); 241 | } 242 | } 243 | 244 | return read(reinterpret_cast(input.data()), input.size(), options); 245 | } 246 | 247 | vsg::ref_ptr GDAL::Implementation::read(const uint8_t* ptr, size_t size, vsg::ref_ptr options) const 248 | { 249 | std::string temp_filename("/vsimem/temp"); 250 | temp_filename.append(options->extensionHint.string()); 251 | 252 | // create a GDAL Virtual File for memory block. 253 | VSILFILE* vsFile = VSIFileFromMemBuffer(temp_filename.c_str(), static_cast(const_cast(ptr)), static_cast(size), 0); 254 | 255 | auto result = GDAL::Implementation::read(temp_filename, options); 256 | 257 | VSIFCloseL(vsFile); 258 | 259 | return result; 260 | } 261 | -------------------------------------------------------------------------------- /src/gdal/GDAL_fallback.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright(c) 2021 Robert Osfield 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | 11 | */ 12 | 13 | #include 14 | 15 | using namespace vsgXchange; 16 | 17 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 18 | // 19 | // GDAL ReaderWriter fallback 20 | // 21 | class GDAL::Implementation 22 | { 23 | }; 24 | GDAL::GDAL() : 25 | _implementation(nullptr) 26 | { 27 | } 28 | GDAL::~GDAL() 29 | { 30 | } 31 | vsg::ref_ptr GDAL::read(const vsg::Path&, vsg::ref_ptr) const 32 | { 33 | return {}; 34 | } 35 | vsg::ref_ptr GDAL::read(std::istream&, vsg::ref_ptr) const 36 | { 37 | return {}; 38 | } 39 | vsg::ref_ptr GDAL::read(const uint8_t*, size_t, vsg::ref_ptr) const 40 | { 41 | return {}; 42 | } 43 | bool GDAL::getFeatures(Features&) const 44 | { 45 | return false; 46 | } 47 | -------------------------------------------------------------------------------- /src/gdal/build_vars.cmake: -------------------------------------------------------------------------------- 1 | # add GDAL if available 2 | find_package(GDAL QUIET) 3 | 4 | if(GDAL_FOUND) 5 | OPTION(vsgXchange_GDAL "GDAL support provided" ON) 6 | endif() 7 | 8 | if(${vsgXchange_GDAL}) 9 | set(SOURCES ${SOURCES} 10 | gdal/gdal_utils.cpp 11 | gdal/meta_utils.cpp 12 | gdal/GDAL.cpp 13 | ) 14 | 15 | set(EXTRA_INCLUDES ${EXTRA_INCLUDES} ${GDAL_INCLUDE_DIR}) 16 | set(EXTRA_LIBRARIES ${EXTRA_LIBRARIES} ${GDAL_LIBRARY}) 17 | set(EXTRA_DEFINES ${EXTRA_DEFINES} USE_GDAL) 18 | if(NOT BUILD_SHARED_LIBS) 19 | set(FIND_DEPENDENCY ${FIND_DEPENDENCY} "find_dependency(GDAL)") 20 | endif() 21 | else() 22 | set(SOURCES ${SOURCES} 23 | gdal/GDAL_fallback.cpp 24 | ) 25 | endif() 26 | -------------------------------------------------------------------------------- /src/gdal/meta_utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright(c) 2021 Robert Osfield 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | */ 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include 30 | 31 | using namespace vsgXchange; 32 | 33 | bool vsgXchange::getEXIF_LatitudeLongitudeAlititude(GDALDataset& dataset, double& latitude, double& longitude, double& altitude) 34 | { 35 | auto metaData = dataset.GetMetadata(); 36 | if (!metaData) return false; 37 | 38 | auto match = [](const char* lhs, const char* rhs) -> const char* { 39 | auto len = std::strlen(rhs); 40 | if (strncmp(lhs, rhs, len) == 0) 41 | return lhs + len; 42 | else 43 | return nullptr; 44 | }; 45 | 46 | bool success = false; 47 | 48 | const char* value_str = nullptr; 49 | std::stringstream str; 50 | str.imbue(std::locale::classic()); 51 | 52 | for (auto ptr = metaData; *ptr != 0; ++ptr) 53 | { 54 | if (value_str = match(*ptr, "EXIF_GPSLatitude="); value_str) 55 | { 56 | str.clear(); 57 | str.str(value_str); 58 | str >> vsgXchange::dms_in_brackets(latitude); 59 | success = true; 60 | } 61 | else if (value_str = match(*ptr, "EXIF_GPSLongitude="); value_str) 62 | { 63 | str.clear(); 64 | str.str(value_str); 65 | str >> vsgXchange::dms_in_brackets(longitude); 66 | success = true; 67 | } 68 | else if (value_str = match(*ptr, "EXIF_GPSAltitude="); value_str) 69 | { 70 | str.clear(); 71 | str.str(value_str); 72 | str >> vsgXchange::dms_in_brackets(altitude); 73 | success = true; 74 | } 75 | } 76 | 77 | return success; 78 | } 79 | 80 | bool vsgXchange::getEXIF_LatitudeLongitudeAlititude(const vsg::Object& object, double& latitude, double& longitude, double& altitude) 81 | { 82 | bool success = false; 83 | 84 | std::string value_str; 85 | std::stringstream str; 86 | str.imbue(std::locale::classic()); 87 | 88 | if (object.getValue("EXIF_GPSLatitude", value_str)) 89 | { 90 | str.clear(); 91 | str.str(value_str); 92 | str >> vsgXchange::dms_in_brackets(latitude); 93 | vsg::info("vsgXchange::getEXIF_.. EXIF_GPSLatitude = ", value_str, " degrees = ", latitude); 94 | success = true; 95 | } 96 | if (object.getValue("EXIF_GPSLongitude", value_str)) 97 | { 98 | str.clear(); 99 | str.str(value_str); 100 | str >> vsgXchange::dms_in_brackets(longitude); 101 | vsg::info("vsgXchange::getEXIF_.. EXIF_GPSLongitude = ", value_str, " degrees = ", longitude); 102 | success = true; 103 | } 104 | if (object.getValue("EXIF_GPSAltitude", value_str)) 105 | { 106 | str.clear(); 107 | str.str(value_str); 108 | str >> vsgXchange::in_brackets(altitude); 109 | vsg::info("vsgXchange::getEXIF_.. EXIF_GPSAltitude = ", value_str, " altitude = ", altitude); 110 | success = true; 111 | } 112 | return success; 113 | } 114 | -------------------------------------------------------------------------------- /src/gltf/build_vars.cmake: -------------------------------------------------------------------------------- 1 | # add draco support if available 2 | find_package(draco) 3 | 4 | if(draco_FOUND) 5 | OPTION(vsgXchange_draco "Optional glTF draco support provided" ON) 6 | endif() 7 | 8 | set(SOURCES ${SOURCES} 9 | gltf/gltf.cpp 10 | gltf/SceneGraphBuilder.cpp 11 | ) 12 | 13 | if (draco_FOUND AND vsgXchange_draco) 14 | set(EXTRA_INCLUDES ${EXTRA_INCLUDES} ${draco_INCLUDE_DIRS}) 15 | set(EXTRA_LIBRARIES ${EXTRA_LIBRARIES} draco::draco) 16 | if(NOT BUILD_SHARED_LIBS) 17 | set(FIND_DEPENDENCY ${FIND_DEPENDENCY} "find_dependency(draco)") 18 | endif() 19 | endif() 20 | -------------------------------------------------------------------------------- /src/images/images.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright(c) 2021 Robert Osfield 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | 11 | */ 12 | 13 | #include 14 | 15 | using namespace vsgXchange; 16 | 17 | images::images() 18 | { 19 | add(stbi::create()); 20 | add(dds::create()); 21 | add(ktx::create()); 22 | } 23 | -------------------------------------------------------------------------------- /src/ktx/build_vars.cmake: -------------------------------------------------------------------------------- 1 | # Compile ktx read library 2 | set(KTX_SOURCES 3 | ktx/libktx/ktx.h 4 | # ktx/libktx/basis_sgd.h 5 | ktx/libktx/checkheader.c 6 | ktx/libktx/dfdutils/createdfd.c 7 | # ktx/libktx/dfdutils/colourspaces.c 8 | ktx/libktx/dfdutils/dfd.h 9 | ktx/libktx/dfdutils/dfd2vk.inl 10 | ktx/libktx/dfdutils/interpretdfd.c 11 | ktx/libktx/dfdutils/printdfd.c 12 | ktx/libktx/dfdutils/queries.c 13 | ktx/libktx/dfdutils/vk2dfd.c 14 | # ktx/libktx/dfdutils/vulkan/vk_platform.h 15 | # ktx/libktx/dfdutils/vulkan/vulkan_core.h 16 | # ktx/libktx/etcdec.cxx 17 | # ktx/libktx/etcunpack.cxx 18 | ktx/libktx/filestream.c 19 | ktx/libktx/filestream.h 20 | # ktx/libktx/formatsize.h 21 | # ktx/libktx/gl_format.h 22 | # ktx/libktx/gl_funcs.c 23 | # ktx/libktx/gl_funcs.h 24 | # ktx/libktx/glloader.c 25 | ktx/libktx/hashlist.c 26 | # ktx/libktx/info.c 27 | ktx/libktx/ktxint.h 28 | ktx/libktx/memstream.c 29 | ktx/libktx/memstream.h 30 | # ktx/libktx/stream.h 31 | # ktx/libktx/strings.c 32 | ktx/libktx/swap.c 33 | ktx/libktx/texture.c 34 | ktx/libktx/texture.h 35 | ktx/libktx/texture1.c 36 | ktx/libktx/texture1.h 37 | ktx/libktx/texture2.c 38 | ktx/libktx/texture2.h 39 | # ktx/libktx/uthash.h 40 | # ktx/libktx/vk_format.h 41 | # ktx/libktx/vkformat_check.c 42 | # ktx/libktx/vkformat_enum.h 43 | # ktx/libktx/vkformat_str.c 44 | # ktx/libktx/ktxvulkan.h 45 | ktx/libktx/vkloader.c 46 | ktx/libktx/zstddeclib.c 47 | ) 48 | source_group(libktx FILES ${KTX_SOURCES}) 49 | set(SOURCES ${SOURCES} ${KTX_SOURCES} ktx/ktx.cpp) 50 | set(EXTRA_DEFINES ${EXTRA_DEFINES} KHRONOS_STATIC LIBKTX BASISD_SUPPORT_FXT1=0 BASISU_NO_ITERATOR_DEBUG_LEVEL KTX_FEATURE_KTX1 KTX_FEATURE_KTX2) 51 | set(EXTRA_INCLUDES ${EXTRA_INCLUDES} $) 52 | -------------------------------------------------------------------------------- /src/ktx/libktx/basis_sgd.h: -------------------------------------------------------------------------------- 1 | /* -*- tab-width: 4; -*- */ 2 | /* vi: set sw=2 ts=4 expandtab textwidth=70: */ 3 | 4 | /* 5 | * Copyright 2019-2020 The Khronos Group Inc. 6 | * SPDX-License-Identifier: Apache-2.0 7 | */ 8 | 9 | /** 10 | * @internal 11 | * @file basisu_sgd.h 12 | * @~English 13 | * 14 | * @brief Declare global data for Basis LZ supercompression with ETC1S. 15 | * 16 | * These functions are private and should not be used outside the library. 17 | */ 18 | 19 | #ifndef _BASIS_SGD_H_ 20 | #define _BASIS_SGD_H_ 21 | 22 | #include 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | // This must be the same value as cSliceDescFlagsFrameIsIFrame so we can just 29 | // invert the bit when passing back & forth. As FrameIsIFrame is within 30 | // a C namespace it can't easily be accessed from a c header. 31 | enum bu_image_flags__bits_e { eBUImageIsPframe = 0x02 }; 32 | 33 | typedef uint32_t buFlags; 34 | 35 | typedef struct ktxBasisLzGlobalHeader { 36 | uint16_t endpointCount; 37 | uint16_t selectorCount; 38 | uint32_t endpointsByteLength; 39 | uint32_t selectorsByteLength; 40 | uint32_t tablesByteLength; 41 | uint32_t extendedByteLength; 42 | } ktxBasisLzGlobalHeader; 43 | 44 | // This header is followed by imageCount "slice" descriptions. 45 | 46 | // 1, or 2 slices per image (i.e. layer, face & slice). 47 | // These offsets are relative to start of a mip level as given by the 48 | // main levelIndex. 49 | typedef struct ktxBasisLzEtc1sImageDesc { 50 | buFlags imageFlags; 51 | uint32_t rgbSliceByteOffset; 52 | uint32_t rgbSliceByteLength; 53 | uint32_t alphaSliceByteOffset; 54 | uint32_t alphaSliceByteLength; 55 | } ktxBasisLzEtc1sImageDesc; 56 | 57 | #define BGD_ETC1S_IMAGE_DESCS(bgd) \ 58 | reinterpret_cast(bgd + sizeof(ktxBasisLzGlobalHeader)) 59 | 60 | // The are followed in the global data by these ... 61 | // uint8_t[endpointsByteLength] endpointsData; 62 | // uint8_t[selectorsByteLength] selectorsData; 63 | // uint8_t[tablesByteLength] tablesData; 64 | 65 | #define BGD_ENDPOINTS_ADDR(bgd, imageCount) \ 66 | (bgd + sizeof(ktxBasisLzGlobalHeader) + sizeof(ktxBasisLzEtc1sImageDesc) * imageCount) 67 | 68 | #define BGD_SELECTORS_ADDR(bgd, bgdh, imageCount) (BGD_ENDPOINTS_ADDR(bgd, imageCount) + bgdh.endpointsByteLength) 69 | 70 | #define BGD_TABLES_ADDR(bgd, bgdh, imageCount) (BGD_SELECTORS_ADDR(bgd, bgdh, imageCount) + bgdh.selectorsByteLength) 71 | 72 | #define BGD_EXTENDED_ADDR(bgd, bgdh, imageCount) (BGD_TABLES_ADDR(bgd, bgdh, imageCount) + bgdh.tablesByteLength) 73 | 74 | // Just because this is a convenient place to put it for basis_{en,trans}code. 75 | enum alpha_content_e { 76 | eNone, 77 | eAlpha, 78 | eGreen 79 | }; 80 | 81 | #ifdef __cplusplus 82 | } 83 | #endif 84 | 85 | #endif /* _BASIS_SGD_H_ */ 86 | -------------------------------------------------------------------------------- /src/ktx/libktx/checkheader.c: -------------------------------------------------------------------------------- 1 | /* -*- tab-width: 4; -*- */ 2 | /* vi: set sw=2 ts=4 expandtab: */ 3 | 4 | /* $Id: ee6f7be4d43390de78e1815ed158012c78ddeff1 $ */ 5 | 6 | /* 7 | * Copyright 2010-2020 The Khronos Group Inc. 8 | * SPDX-License-Identifier: Apache-2.0 9 | */ 10 | 11 | /** 12 | * @internal 13 | * @file checkheader.c 14 | * @~English 15 | * 16 | * @brief Function to verify a KTX file header 17 | * 18 | * @author Mark Callow, HI Corporation 19 | */ 20 | 21 | /* 22 | * Author: Georg Kolling, Imagination Technology with modifications 23 | * by Mark Callow, HI Corporation. 24 | */ 25 | #include 26 | #include 27 | 28 | #include "ktx.h" 29 | #include "ktxint.h" 30 | 31 | /** 32 | * @internal 33 | * @~English 34 | * @brief Check a KTX file header. 35 | * 36 | * As well as checking that the header identifies a KTX file, the function 37 | * sanity checks the values and returns information about the texture in a 38 | * struct KTX_supplementary_info. 39 | * 40 | * @param pHeader pointer to the KTX header to check 41 | * @param pSuppInfo pointer to a KTX_supplementary_info structure in which to 42 | * return information about the texture. 43 | * 44 | * @author Georg Kolling, Imagination Technology 45 | * @author Mark Callow, HI Corporation 46 | */ 47 | 48 | KTX_error_code ktxCheckHeader1_(KTX_header* pHeader, 49 | KTX_supplemental_info* pSuppInfo) 50 | { 51 | ktx_uint8_t identifier_reference[12] = KTX_IDENTIFIER_REF; 52 | ktx_uint32_t max_dim; 53 | 54 | assert(pHeader != NULL && pSuppInfo != NULL); 55 | 56 | /* Compare identifier, is this a KTX file? */ 57 | if (memcmp(pHeader->identifier, identifier_reference, 12) != 0) 58 | { 59 | return KTX_UNKNOWN_FILE_FORMAT; 60 | } 61 | 62 | if (pHeader->endianness == KTX_ENDIAN_REF_REV) 63 | { 64 | /* Convert endianness of pHeader fields. */ 65 | _ktxSwapEndian32(&pHeader->glType, 12); 66 | 67 | if (pHeader->glTypeSize != 1 && 68 | pHeader->glTypeSize != 2 && 69 | pHeader->glTypeSize != 4) 70 | { 71 | /* Only 8-, 16-, and 32-bit types supported so far. */ 72 | return KTX_FILE_DATA_ERROR; 73 | } 74 | } 75 | else if (pHeader->endianness != KTX_ENDIAN_REF) 76 | { 77 | return KTX_FILE_DATA_ERROR; 78 | } 79 | 80 | /* Check glType and glFormat */ 81 | pSuppInfo->compressed = 0; 82 | if (pHeader->glType == 0 || pHeader->glFormat == 0) 83 | { 84 | if (pHeader->glType + pHeader->glFormat != 0) 85 | { 86 | /* either both or none of glType, glFormat must be zero */ 87 | return KTX_FILE_DATA_ERROR; 88 | } 89 | pSuppInfo->compressed = 1; 90 | } 91 | 92 | if (pHeader->glFormat == pHeader->glInternalformat) { 93 | // glInternalFormat is either unsized (which is no longer and should 94 | // never have been supported by libktx) or glFormat is sized. 95 | return KTX_FILE_DATA_ERROR; 96 | } 97 | 98 | /* Check texture dimensions. KTX files can store 8 types of textures: 99 | 1D, 2D, 3D, cube, and array variants of these. There is currently 100 | no GL extension for 3D array textures. */ 101 | if ((pHeader->pixelWidth == 0) || 102 | (pHeader->pixelDepth > 0 && pHeader->pixelHeight == 0)) 103 | { 104 | /* texture must have width */ 105 | /* texture must have height if it has depth */ 106 | return KTX_FILE_DATA_ERROR; 107 | } 108 | 109 | 110 | if (pHeader->pixelDepth > 0) 111 | { 112 | if (pHeader->numberOfArrayElements > 0) 113 | { 114 | /* No 3D array textures yet. */ 115 | return KTX_UNSUPPORTED_TEXTURE_TYPE; 116 | } 117 | pSuppInfo->textureDimension = 3; 118 | } 119 | else if (pHeader->pixelHeight > 0) 120 | { 121 | pSuppInfo->textureDimension = 2; 122 | } 123 | else 124 | { 125 | pSuppInfo->textureDimension = 1; 126 | } 127 | 128 | if (pHeader->numberOfFaces == 6) 129 | { 130 | if (pSuppInfo->textureDimension != 2) 131 | { 132 | /* cube map needs 2D faces */ 133 | return KTX_FILE_DATA_ERROR; 134 | } 135 | } 136 | else if (pHeader->numberOfFaces != 1) 137 | { 138 | /* numberOfFaces must be either 1 or 6 */ 139 | return KTX_FILE_DATA_ERROR; 140 | } 141 | 142 | /* Check number of mipmap levels */ 143 | if (pHeader->numberOfMipLevels == 0) 144 | { 145 | pSuppInfo->generateMipmaps = 1; 146 | pHeader->numberOfMipLevels = 1; 147 | } 148 | else 149 | { 150 | pSuppInfo->generateMipmaps = 0; 151 | } 152 | 153 | /* This test works for arrays too because height or depth will be 0. */ 154 | max_dim = MAX(MAX(pHeader->pixelWidth, pHeader->pixelHeight), pHeader->pixelDepth); 155 | if (max_dim < ((ktx_uint32_t)1 << (pHeader->numberOfMipLevels - 1))) 156 | { 157 | /* Can't have more mip levels than 1 + log2(max(width, height, depth)) */ 158 | return KTX_FILE_DATA_ERROR; 159 | } 160 | 161 | return KTX_SUCCESS; 162 | } 163 | 164 | /** 165 | * @internal 166 | * @~English 167 | * @brief Check a KTX2 file header. 168 | * 169 | * As well as checking that the header identifies a KTX 2 file, the function 170 | * sanity checks the values and returns information about the texture in a 171 | * struct KTX_supplementary_info. 172 | * 173 | * @param pHeader pointer to the KTX header to check 174 | * @param pSuppInfo pointer to a KTX_supplementary_info structure in which to 175 | * return information about the texture. 176 | * 177 | * @author Mark Callow, HI Corporation 178 | */ 179 | KTX_error_code ktxCheckHeader2_(KTX_header2* pHeader, 180 | KTX_supplemental_info* pSuppInfo) 181 | { 182 | // supp info is compressed, generateMipmaps and num dimensions. Don't need 183 | // compressed as formatSize gives us that. I think the other 2 aren't needed. 184 | ktx_uint8_t identifier_reference[12] = KTX2_IDENTIFIER_REF; 185 | 186 | assert(pHeader != NULL && pSuppInfo != NULL); 187 | ktx_uint32_t max_dim; 188 | 189 | /* Compare identifier, is this a KTX file? */ 190 | if (memcmp(pHeader->identifier, identifier_reference, 12) != 0) 191 | { 192 | return KTX_UNKNOWN_FILE_FORMAT; 193 | } 194 | 195 | /* Check texture dimensions. KTX files can store 8 types of textures: 196 | 1D, 2D, 3D, cube, and array variants of these. There is currently 197 | no extension for 3D array textures in any 3D API. */ 198 | if ((pHeader->pixelWidth == 0) || 199 | (pHeader->pixelDepth > 0 && pHeader->pixelHeight == 0)) 200 | { 201 | /* texture must have width */ 202 | /* texture must have height if it has depth */ 203 | return KTX_FILE_DATA_ERROR; 204 | } 205 | 206 | if (pHeader->pixelDepth > 0) 207 | { 208 | if (pHeader->layerCount > 0) 209 | { 210 | /* No 3D array textures yet. */ 211 | return KTX_UNSUPPORTED_TEXTURE_TYPE; 212 | } 213 | pSuppInfo->textureDimension = 3; 214 | } 215 | else if (pHeader->pixelHeight > 0) 216 | { 217 | pSuppInfo->textureDimension = 2; 218 | } 219 | else 220 | { 221 | pSuppInfo->textureDimension = 1; 222 | } 223 | 224 | if (pHeader->faceCount == 6) 225 | { 226 | if (pSuppInfo->textureDimension != 2) 227 | { 228 | /* cube map needs 2D faces */ 229 | return KTX_FILE_DATA_ERROR; 230 | } 231 | } 232 | else if (pHeader->faceCount != 1) 233 | { 234 | /* numberOfFaces must be either 1 or 6 */ 235 | return KTX_FILE_DATA_ERROR; 236 | } 237 | 238 | // Check number of mipmap levels 239 | if (pHeader->levelCount == 0) 240 | { 241 | pSuppInfo->generateMipmaps = 1; 242 | pHeader->levelCount = 1; 243 | } 244 | else 245 | { 246 | pSuppInfo->generateMipmaps = 0; 247 | } 248 | 249 | // This test works for arrays too because height or depth will be 0. 250 | max_dim = MAX(MAX(pHeader->pixelWidth, pHeader->pixelHeight), pHeader->pixelDepth); 251 | if (max_dim < ((ktx_uint32_t)1 << (pHeader->levelCount - 1))) 252 | { 253 | // Can't have more mip levels than 1 + log2(max(width, height, depth)) 254 | return KTX_FILE_DATA_ERROR; 255 | } 256 | 257 | return KTX_SUCCESS; 258 | 259 | } 260 | -------------------------------------------------------------------------------- /src/ktx/libktx/dfdutils/colourspaces.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2019-2020 The Khronos Group Inc. 2 | * SPDX-License-Identifier: Apache-2.0 3 | */ 4 | 5 | /** 6 | * @file 7 | * @~English 8 | * @brief Helper functions for colourspaces. 9 | */ 10 | 11 | #include 12 | #include "dfd.h" 13 | 14 | typedef struct s_PrimaryMapping { 15 | khr_df_primaries_e dfPrimaryEnum; 16 | Primaries primaries; 17 | } sPrimaryMapping; 18 | 19 | sPrimaryMapping primaryMap[] = { 20 | { KHR_DF_PRIMARIES_BT709, { 0.640f,0.330f, 0.300f,0.600f, 0.150f,0.060f, 0.3127f,0.3290f}}, 21 | { KHR_DF_PRIMARIES_BT601_EBU, { 0.640f,0.330f, 0.290f,0.600f, 0.150f,0.060f, 0.3127f,0.3290f}}, 22 | { KHR_DF_PRIMARIES_BT601_SMPTE, { 0.630f,0.340f, 0.310f,0.595f, 0.155f,0.070f, 0.3127f,0.3290f}}, 23 | { KHR_DF_PRIMARIES_BT2020, { 0.708f,0.292f, 0.170f,0.797f, 0.131f,0.046f, 0.3127f,0.3290f}}, 24 | { KHR_DF_PRIMARIES_CIEXYZ, { 1.0f,0.0f, 0.0f,1.0f, 0.0f,0.0f, 0.0f,1.0f}}, 25 | { KHR_DF_PRIMARIES_ACES, { 0.7347f,0.2653f, 0.0f,1.0f, 0.0001f,-0.077f, 0.32168f,0.33767f}}, 26 | { KHR_DF_PRIMARIES_ACESCC, { 0.713f,0.293f, 0.165f,0.830f, 0.128f,0.044f, 0.32168f,0.33767f}}, 27 | { KHR_DF_PRIMARIES_NTSC1953, { 0.67f,0.33f, 0.21f,0.71f, 0.14f,0.08f, 0.310f,0.316f}}, 28 | { KHR_DF_PRIMARIES_PAL525, { 0.630f,0.340f, 0.310f,0.595f, 0.155f,0.070f, 0.3101f,0.3162f}}, 29 | { KHR_DF_PRIMARIES_DISPLAYP3, { 0.6800f,0.3200f, 0.2650f,0.69f, 0.1500f,0.0600f, 0.3127f,0.3290f}}, 30 | { KHR_DF_PRIMARIES_ADOBERGB, { 0.6400f,0.3300f, 0.2100f,0.71f, 0.1500f,0.0600f, 0.3127f,0.3290f}}}; 31 | 32 | /** 33 | * @brief Map a set of primaries to a KDFS primaries enum. 34 | * 35 | * @param[in] p pointer to a Primaries struct filled in with the primary values. 36 | * @param[in] latitude tolerance to use while matching. A suitable value might be 0.002 37 | * but it depends on the application. 38 | */ 39 | khr_df_primaries_e findMapping(Primaries *p, float latitude) { 40 | unsigned int i; 41 | for (i = 0; i < sizeof(primaryMap)/sizeof(sPrimaryMapping); ++i) { 42 | if (primaryMap[i].primaries.Rx - p->Rx <= latitude && p->Rx - primaryMap[i].primaries.Rx <= latitude && 43 | primaryMap[i].primaries.Gx - p->Gx <= latitude && p->Gx - primaryMap[i].primaries.Gx <= latitude && 44 | primaryMap[i].primaries.Bx - p->Bx <= latitude && p->Bx - primaryMap[i].primaries.Bx <= latitude && 45 | primaryMap[i].primaries.Wx - p->Wx <= latitude && p->Wx - primaryMap[i].primaries.Wx <= latitude) { 46 | return primaryMap[i].dfPrimaryEnum; 47 | } 48 | } 49 | /* No match */ 50 | return KHR_DF_PRIMARIES_UNSPECIFIED; 51 | } 52 | -------------------------------------------------------------------------------- /src/ktx/libktx/dfdutils/dfd.h: -------------------------------------------------------------------------------- 1 | /* -*- tab-width: 4; -*- */ 2 | /* vi: set sw=2 ts=4 expandtab: */ 3 | 4 | /* Copyright 2019-2020 The Khronos Group Inc. 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | /** 9 | * @file 10 | * @~English 11 | * @brief Header file defining the data format descriptor utilities API. 12 | */ 13 | 14 | /* 15 | * Author: Andrew Garrard 16 | */ 17 | 18 | #ifndef _DFD_H_ 19 | #define _DFD_H_ 20 | 21 | #include 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /** Qualifier suffix to the format, in Vulkan terms. */ 28 | enum VkSuffix { 29 | s_UNORM, /*!< Unsigned normalized format. */ 30 | s_SNORM, /*!< Signed normalized format. */ 31 | s_USCALED, /*!< Unsigned scaled format. */ 32 | s_SSCALED, /*!< Signed scaled format. */ 33 | s_UINT, /*!< Unsigned integer format. */ 34 | s_SINT, /*!< Signed integer format. */ 35 | s_SFLOAT, /*!< Signed float format. */ 36 | s_UFLOAT, /*!< Unsigned float format. */ 37 | s_SRGB /*!< sRGB normalized format. */ 38 | }; 39 | 40 | /** Compression scheme, in Vulkan terms. */ 41 | enum VkCompScheme { 42 | c_BC1_RGB, /*!< BC1, aka DXT1, no alpha. */ 43 | c_BC1_RGBA, /*!< BC1, aka DXT1, punch-through alpha. */ 44 | c_BC2, /*!< BC2, aka DXT2 and DXT3. */ 45 | c_BC3, /*!< BC3, aka DXT4 and DXT5. */ 46 | c_BC4, /*!< BC4. */ 47 | c_BC5, /*!< BC5. */ 48 | c_BC6H, /*!< BC6h HDR format. */ 49 | c_BC7, /*!< BC7. */ 50 | c_ETC2_R8G8B8, /*!< ETC2 no alpha. */ 51 | c_ETC2_R8G8B8A1, /*!< ETC2 punch-through alpha. */ 52 | c_ETC2_R8G8B8A8, /*!< ETC2 independent alpha. */ 53 | c_EAC_R11, /*!< R11 ETC2 single-channel. */ 54 | c_EAC_R11G11, /*!< R11G11 ETC2 dual-channel. */ 55 | c_ASTC, /*!< ASTC. */ 56 | c_ETC1S, /*!< ETC1S. */ 57 | c_PVRTC, /*!< PVRTC(1). */ 58 | c_PVRTC2 /*!< PVRTC2. */ 59 | }; 60 | 61 | typedef unsigned int uint32_t; 62 | 63 | #if !defined(LIBKTX) 64 | #include 65 | #else 66 | #include "../vkformat_enum.h" 67 | #endif 68 | 69 | uint32_t* vk2dfd(enum VkFormat format); 70 | 71 | /* Create a Data Format Descriptor for an unpacked format. */ 72 | uint32_t *createDFDUnpacked(int bigEndian, int numChannels, int bytes, 73 | int redBlueSwap, enum VkSuffix suffix); 74 | 75 | /* Create a Data Format Descriptor for a packed format. */ 76 | uint32_t *createDFDPacked(int bigEndian, int numChannels, 77 | int bits[], int channels[], 78 | enum VkSuffix suffix); 79 | 80 | /* Create a Data Format Descriptor for a compressed format. */ 81 | uint32_t *createDFDCompressed(enum VkCompScheme compScheme, 82 | int bwidth, int bheight, int bdepth, 83 | enum VkSuffix suffix); 84 | 85 | /* Create a Data Format Descriptor for a depth/stencil format. */ 86 | uint32_t *createDFDDepthStencil(int depthBits, 87 | int stencilBits, 88 | int sizeBytes); 89 | 90 | /** @brief Result of interpreting the data format descriptor. */ 91 | enum InterpretDFDResult { 92 | i_LITTLE_ENDIAN_FORMAT_BIT = 0, /*!< Confirmed little-endian (default for 8bpc). */ 93 | i_BIG_ENDIAN_FORMAT_BIT = 1, /*!< Confirmed big-endian. */ 94 | i_PACKED_FORMAT_BIT = 2, /*!< Packed format. */ 95 | i_SRGB_FORMAT_BIT = 4, /*!< sRGB transfer function. */ 96 | i_NORMALIZED_FORMAT_BIT = 8, /*!< Normalized (UNORM or SNORM). */ 97 | i_SIGNED_FORMAT_BIT = 16, /*!< Format is signed. */ 98 | i_FLOAT_FORMAT_BIT = 32, /*!< Format is floating point. */ 99 | i_UNSUPPORTED_ERROR_BIT = 64, /*!< Format not successfully interpreted. */ 100 | /** "NONTRIVIAL_ENDIANNESS" means not big-endian, not little-endian 101 | * (a channel has bits that are not consecutive in either order). **/ 102 | i_UNSUPPORTED_NONTRIVIAL_ENDIANNESS = i_UNSUPPORTED_ERROR_BIT, 103 | /** "MULTIPLE_SAMPLE_LOCATIONS" is an error because only single-sample 104 | * texel blocks (with coordinates 0,0,0,0 for all samples) are supported. **/ 105 | i_UNSUPPORTED_MULTIPLE_SAMPLE_LOCATIONS = i_UNSUPPORTED_ERROR_BIT + 1, 106 | /** "MULTIPLE_PLANES" is an error because only contiguous data is supported. */ 107 | i_UNSUPPORTED_MULTIPLE_PLANES = i_UNSUPPORTED_ERROR_BIT + 2, 108 | /** Only channels R, G, B and A are supported. */ 109 | i_UNSUPPORTED_CHANNEL_TYPES = i_UNSUPPORTED_ERROR_BIT + 3, 110 | /** Only channels with the same flags are supported 111 | * (e.g. we don't support float red with integer green). */ 112 | i_UNSUPPORTED_MIXED_CHANNELS = i_UNSUPPORTED_ERROR_BIT + 4 113 | }; 114 | 115 | /** @brief Interpretation of a channel from the data format descriptor. */ 116 | typedef struct _InterpretedDFDChannel { 117 | uint32_t offset; /*!< Offset in bits for packed, bytes for unpacked. */ 118 | uint32_t size; /*!< Size in bits for packed, bytes for unpacked. */ 119 | } InterpretedDFDChannel; 120 | 121 | /* Interpret a Data Format Descriptor. */ 122 | enum InterpretDFDResult interpretDFD(const uint32_t *DFD, 123 | InterpretedDFDChannel *R, 124 | InterpretedDFDChannel *G, 125 | InterpretedDFDChannel *B, 126 | InterpretedDFDChannel *A, 127 | uint32_t *wordBytes); 128 | 129 | /* Print a human-readable interpretation of a data format descriptor. */ 130 | void printDFD(uint32_t *DFD); 131 | 132 | /* Get the number of components & component size from a DFD for an 133 | * unpacked format. 134 | */ 135 | void 136 | getDFDComponentInfoUnpacked(const uint32_t* DFD, uint32_t* numComponents, 137 | uint32_t* componentByteLength); 138 | 139 | /* Return the number of components described by a DFD. */ 140 | uint32_t getDFDNumComponents(const uint32_t* DFD); 141 | 142 | /* Recreate and return the value of bytesPlane0 as it should be for the data 143 | * post-inflation from variable-rate compression. 144 | */ 145 | void 146 | recreateBytesPlane0FromSampleInfo(const uint32_t* DFD, uint32_t* bytesPlane0); 147 | 148 | /** @brief Colourspace primaries information. 149 | * 150 | * Structure to store the 1931 CIE x,y chromaticities of the red, green, and blue 151 | * display primaries and the reference white point of a colourspace. 152 | */ 153 | typedef struct _Primaries { 154 | float Rx; /*!< Red x. */ 155 | float Ry; /*!< Red y. */ 156 | float Gx; /*!< Green x. */ 157 | float Gy; /*!< Green y. */ 158 | float Bx; /*!< Blue x. */ 159 | float By; /*!< Blue y. */ 160 | float Wx; /*!< White x. */ 161 | float Wy; /*!< White y. */ 162 | } Primaries; 163 | 164 | khr_df_primaries_e findMapping(Primaries *p, float latitude); 165 | 166 | #ifdef __cplusplus 167 | } 168 | #endif 169 | 170 | #endif /* _DFD_H_ */ 171 | -------------------------------------------------------------------------------- /src/ktx/libktx/dfdutils/printdfd.c: -------------------------------------------------------------------------------- 1 | /* -*- tab-width: 4; -*- */ 2 | /* vi: set sw=2 ts=4 expandtab: */ 3 | 4 | /* Copyright 2019-2020 The Khronos Group Inc. 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | /** 9 | * @file 10 | * @~English 11 | * @brief Utilities for printing data format descriptors. 12 | */ 13 | 14 | /* 15 | * Author: Andrew Garrard 16 | */ 17 | 18 | #include 19 | #include 20 | #include "dfd.h" 21 | 22 | /** 23 | * @~English 24 | * @brief Print a human-readable interpretation of a data format descriptor. 25 | * 26 | * @param DFD Pointer to a data format descriptor. 27 | **/ 28 | void printDFD(uint32_t *DFD) 29 | { 30 | uint32_t *BDB = DFD+1; 31 | int samples = (KHR_DFDVAL(BDB, DESCRIPTORBLOCKSIZE) - 4 * KHR_DF_WORD_SAMPLESTART) / (4 * KHR_DF_WORD_SAMPLEWORDS); 32 | int sample; 33 | int model = KHR_DFDVAL(BDB, MODEL); 34 | printf("DFD total bytes: %d\n", DFD[0]); 35 | printf("BDB descriptor type 0x%04x vendor id = 0x%05x\n", 36 | KHR_DFDVAL(BDB, DESCRIPTORTYPE), 37 | KHR_DFDVAL(BDB, VENDORID)); 38 | printf("Descriptor block size %d (%d samples) versionNumber = 0x%04x\n", 39 | KHR_DFDVAL(BDB, DESCRIPTORBLOCKSIZE), 40 | samples, 41 | KHR_DFDVAL(BDB, VERSIONNUMBER)); 42 | printf("Flags 0x%02x Xfer %02d Primaries %02d Model %03d\n", 43 | KHR_DFDVAL(BDB, FLAGS), 44 | KHR_DFDVAL(BDB, TRANSFER), 45 | KHR_DFDVAL(BDB, PRIMARIES), 46 | model); 47 | printf("Dimensions: %d,%d,%d,%d\n", 48 | KHR_DFDVAL(BDB, TEXELBLOCKDIMENSION0) + 1, 49 | KHR_DFDVAL(BDB, TEXELBLOCKDIMENSION1) + 1, 50 | KHR_DFDVAL(BDB, TEXELBLOCKDIMENSION2) + 1, 51 | KHR_DFDVAL(BDB, TEXELBLOCKDIMENSION3) + 1); 52 | printf("Plane bytes: %d,%d,%d,%d,%d,%d,%d,%d\n", 53 | KHR_DFDVAL(BDB, BYTESPLANE0), 54 | KHR_DFDVAL(BDB, BYTESPLANE1), 55 | KHR_DFDVAL(BDB, BYTESPLANE2), 56 | KHR_DFDVAL(BDB, BYTESPLANE3), 57 | KHR_DFDVAL(BDB, BYTESPLANE4), 58 | KHR_DFDVAL(BDB, BYTESPLANE5), 59 | KHR_DFDVAL(BDB, BYTESPLANE6), 60 | KHR_DFDVAL(BDB, BYTESPLANE7)); 61 | for (sample = 0; sample < samples; ++sample) { 62 | int channelId = KHR_DFDSVAL(BDB, sample, CHANNELID); 63 | printf(" Sample %d\n", sample); 64 | printf("Qualifiers %x", KHR_DFDSVAL(BDB, sample, QUALIFIERS) >> 4); 65 | printf(" Channel 0x%x", channelId); 66 | if (model == KHR_DF_MODEL_UASTC) { 67 | printf(" (%s)", 68 | channelId == KHR_DF_CHANNEL_UASTC_RRRG ? "RRRG" 69 | : channelId == KHR_DF_CHANNEL_UASTC_RGBA ? "RGBA" 70 | : channelId == KHR_DF_CHANNEL_UASTC_RRR ? "RRR" 71 | : channelId == KHR_DF_CHANNEL_UASTC_RGB ? "RGB" 72 | : channelId == KHR_DF_CHANNEL_UASTC_RG ? "RG" 73 | : "unknown"); 74 | } else if (model == KHR_DF_MODEL_ETC1S) { 75 | printf(" (%s)", 76 | channelId == KHR_DF_CHANNEL_ETC1S_AAA ? "AAA" 77 | : channelId == KHR_DF_CHANNEL_ETC1S_GGG ? "GGG" 78 | : channelId == KHR_DF_CHANNEL_ETC1S_RRR ? "RRR" 79 | : channelId == KHR_DF_CHANNEL_ETC1S_RGB ? "RGB" 80 | : "unknown"); 81 | } else { 82 | printf(" (%c)", 83 | "RGB3456789abcdeA"[channelId]); 84 | } 85 | printf(" Length %d bits Offset %d\n", 86 | KHR_DFDSVAL(BDB, sample, BITLENGTH) + 1, 87 | KHR_DFDSVAL(BDB, sample, BITOFFSET)); 88 | printf("Position: %d,%d,%d,%d\n", 89 | KHR_DFDSVAL(BDB, sample, SAMPLEPOSITION0), 90 | KHR_DFDSVAL(BDB, sample, SAMPLEPOSITION1), 91 | KHR_DFDSVAL(BDB, sample, SAMPLEPOSITION2), 92 | KHR_DFDSVAL(BDB, sample, SAMPLEPOSITION3)); 93 | printf("Lower 0x%08x\nUpper 0x%08x\n", 94 | KHR_DFDSVAL(BDB, sample, SAMPLELOWER), 95 | KHR_DFDSVAL(BDB, sample, SAMPLEUPPER)); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/ktx/libktx/dfdutils/queries.c: -------------------------------------------------------------------------------- 1 | /* -*- tab-width: 4; -*- */ 2 | /* vi: set sw=2 ts=4 expandtab: */ 3 | 4 | /* Copyright 2019-2020 The Khronos Group Inc. 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | /** 9 | * @file 10 | * @~English 11 | * @brief Utilities for querying info from a data format descriptor. 12 | * @author Mark Callow 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "dfd.h" 21 | 22 | /** 23 | * @~English 24 | * @brief Get the number and size of the image components from a DFD. 25 | * 26 | * This simplified function is for use only with the DFDs for unpacked 27 | * formats which means all components have the same size. 28 | * 29 | * @param DFD Pointer to a Data Format Descriptor to interpret, 30 | described as 32-bit words in native endianness. 31 | Note that this is the whole descriptor, not just 32 | the basic descriptor block. 33 | * @param numComponents pointer to a 32-bit word in which the number of 34 | components will be written. 35 | * @param componentByteLength pointer to a 32-bit word in which the size of 36 | a component in bytes will be written. 37 | */ 38 | void 39 | getDFDComponentInfoUnpacked(const uint32_t* DFD, uint32_t* numComponents, 40 | uint32_t* componentByteLength) 41 | { 42 | const uint32_t *BDFDB = DFD+1; 43 | uint32_t numSamples = KHR_DFDSAMPLECOUNT(BDFDB); 44 | uint32_t sampleCounter; 45 | uint32_t currentChannel = ~0U; /* Don't start matched. */ 46 | 47 | /* This is specifically for unpacked formats which means the size of */ 48 | /* each component is the same. */ 49 | *numComponents = 0; 50 | for (sampleCounter = 0; sampleCounter < numSamples; ++sampleCounter) { 51 | uint32_t sampleByteLength = (KHR_DFDSVAL(BDFDB, sampleCounter, BITLENGTH) + 1) >> 3U; 52 | uint32_t sampleChannel = KHR_DFDSVAL(BDFDB, sampleCounter, CHANNELID); 53 | 54 | if (sampleChannel == currentChannel) { 55 | /* Continuation of the same channel. */ 56 | /* Accumulate the byte length. */ 57 | *componentByteLength += sampleByteLength; 58 | } else { 59 | /* Everything is new. Hopefully. */ 60 | currentChannel = sampleChannel; 61 | (*numComponents)++; 62 | *componentByteLength = sampleByteLength; 63 | } 64 | } 65 | } 66 | 67 | /** 68 | * @~English 69 | * @brief Return the number of "components" in the data. 70 | * 71 | * Calculates the number of uniques samples in the DFD by combining 72 | * multiple samples for the same channel. For uncompressed colorModels 73 | * this is the same as the number of components in the image data. For 74 | * block-compressed color models this is the number of samples in 75 | * the color model, typically 1 and in a few cases 2. 76 | * 77 | * @param DFD Pointer to a Data Format Descriptor for which, 78 | * described as 32-bit words in native endianness. 79 | * Note that this is the whole descriptor, not just 80 | * the basic descriptor block. 81 | */ 82 | uint32_t getDFDNumComponents(const uint32_t* DFD) 83 | { 84 | const uint32_t *BDFDB = DFD+1; 85 | uint32_t currentChannel = ~0U; /* Don't start matched. */ 86 | uint32_t numComponents = 0; 87 | uint32_t numSamples = KHR_DFDSAMPLECOUNT(BDFDB); 88 | uint32_t sampleCounter; 89 | 90 | for (sampleCounter = 0; sampleCounter < numSamples; ++sampleCounter) { 91 | uint32_t sampleChannel = KHR_DFDSVAL(BDFDB, sampleCounter, CHANNELID); 92 | if (sampleChannel != currentChannel) { 93 | numComponents++; 94 | currentChannel = sampleChannel; 95 | } 96 | } 97 | return numComponents; 98 | } 99 | 100 | /** 101 | * @~English 102 | * @brief Recreate the value of bytesPlane0 from sample info. 103 | * 104 | * This can be use to recreate the value of bytesPlane0 for data that 105 | * has been variable-rate compressed so has bytesPlane0 = 0. For DFDs 106 | * that are valid for KTX files. Little-endian data only and no multi-plane 107 | * formats. 108 | * 109 | * @param DFD Pointer to a Data Format Descriptor for which, 110 | * described as 32-bit words in native endianness. 111 | * Note that this is the whole descriptor, not just 112 | * the basic descriptor block. 113 | * @param bytesPlane0 pointer to a 32-bit word in which the recreated 114 | * value of bytesPlane0 will be written. 115 | */ 116 | void 117 | recreateBytesPlane0FromSampleInfo(const uint32_t* DFD, uint32_t* bytesPlane0) 118 | { 119 | const uint32_t *BDFDB = DFD+1; 120 | uint32_t numSamples = KHR_DFDSAMPLECOUNT(BDFDB); 121 | uint32_t sampleCounter; 122 | 123 | uint32_t bitsPlane0 = 0; 124 | uint32_t* bitOffsets = malloc(sizeof(uint32_t) * numSamples); 125 | memset(bitOffsets, -1, sizeof(uint32_t) * numSamples); 126 | for (sampleCounter = 0; sampleCounter < numSamples; ++sampleCounter) { 127 | uint32_t sampleBitOffset = KHR_DFDSVAL(BDFDB, sampleCounter, BITOFFSET); 128 | /* The sample bitLength field stores the bit length - 1. */ 129 | uint32_t sampleBitLength = KHR_DFDSVAL(BDFDB, sampleCounter, BITLENGTH) + 1; 130 | uint32_t i; 131 | for (i = 0; i < numSamples; i++) { 132 | if (sampleBitOffset == bitOffsets[i]) { 133 | // This sample is being repeated as in e.g. RGB9E5. 134 | break; 135 | } 136 | } 137 | if (i == numSamples) { 138 | // Previously unseen bitOffset. Bump size. 139 | bitsPlane0 += sampleBitLength; 140 | bitOffsets[sampleCounter] = sampleBitOffset; 141 | } 142 | } 143 | free(bitOffsets); 144 | *bytesPlane0 = bitsPlane0 >> 3U; 145 | } 146 | 147 | -------------------------------------------------------------------------------- /src/ktx/libktx/dfdutils/vk2dfd.c: -------------------------------------------------------------------------------- 1 | /* -*- tab-width: 4; -*- */ 2 | /* vi: set sw=2 ts=4 expandtab: */ 3 | 4 | /* Copyright 2019-2020 Mark Callow 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | /** 9 | * @file 10 | * @~English 11 | * @brief Create a DFD for a VkFormat. 12 | */ 13 | 14 | #include "dfd.h" 15 | 16 | /** 17 | * @~English 18 | * @brief Create a DFD matching a VkFormat. 19 | * 20 | * @param[in] format VkFormat for which to create a DFD. 21 | * 22 | * @return pointer to the created DFD or 0 if format not supported or 23 | * unrecognized. Caller is responsible for freeing the created 24 | * DFD. 25 | */ 26 | uint32_t* 27 | vk2dfd(enum VkFormat format) 28 | { 29 | switch (format) { 30 | #include "vk2dfd.inl" 31 | default: return 0; 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /src/ktx/libktx/dfdutils/vulkan/vk_platform.h: -------------------------------------------------------------------------------- 1 | // 2 | // File: vk_platform.h 3 | // 4 | /* 5 | ** Copyright (c) 2014-2020 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | 11 | #ifndef VK_PLATFORM_H_ 12 | #define VK_PLATFORM_H_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 17 | #endif // __cplusplus 18 | 19 | /* 20 | *************************************************************************************************** 21 | * Platform-specific directives and type declarations 22 | *************************************************************************************************** 23 | */ 24 | 25 | /* Platform-specific calling convention macros. 26 | * 27 | * Platforms should define these so that Vulkan clients call Vulkan commands 28 | * with the same calling conventions that the Vulkan implementation expects. 29 | * 30 | * VKAPI_ATTR - Placed before the return type in function declarations. 31 | * Useful for C++11 and GCC/Clang-style function attribute syntax. 32 | * VKAPI_CALL - Placed after the return type in function declarations. 33 | * Useful for MSVC-style calling convention syntax. 34 | * VKAPI_PTR - Placed between the '(' and '*' in function pointer types. 35 | * 36 | * Function declaration: VKAPI_ATTR void VKAPI_CALL vkCommand(void); 37 | * Function pointer type: typedef void (VKAPI_PTR *PFN_vkCommand)(void); 38 | */ 39 | #if defined(_WIN32) 40 | // On Windows, Vulkan commands use the stdcall convention 41 | #define VKAPI_ATTR 42 | #define VKAPI_CALL __stdcall 43 | #define VKAPI_PTR VKAPI_CALL 44 | #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH < 7 45 | #error "Vulkan isn't supported for the 'armeabi' NDK ABI" 46 | #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH >= 7 && defined(__ARM_32BIT_STATE) 47 | // On Android 32-bit ARM targets, Vulkan functions use the "hardfloat" 48 | // calling convention, i.e. float parameters are passed in registers. This 49 | // is true even if the rest of the application passes floats on the stack, 50 | // as it does by default when compiling for the armeabi-v7a NDK ABI. 51 | #define VKAPI_ATTR __attribute__((pcs("aapcs-vfp"))) 52 | #define VKAPI_CALL 53 | #define VKAPI_PTR VKAPI_ATTR 54 | #else 55 | // On other platforms, use the default calling convention 56 | #define VKAPI_ATTR 57 | #define VKAPI_CALL 58 | #define VKAPI_PTR 59 | #endif 60 | 61 | #include 62 | 63 | #if !defined(VK_NO_STDINT_H) 64 | #if defined(_MSC_VER) && (_MSC_VER < 1600) 65 | typedef signed __int8 int8_t; 66 | typedef unsigned __int8 uint8_t; 67 | typedef signed __int16 int16_t; 68 | typedef unsigned __int16 uint16_t; 69 | typedef signed __int32 int32_t; 70 | typedef unsigned __int32 uint32_t; 71 | typedef signed __int64 int64_t; 72 | typedef unsigned __int64 uint64_t; 73 | #else 74 | #include 75 | #endif 76 | #endif // !defined(VK_NO_STDINT_H) 77 | 78 | #ifdef __cplusplus 79 | } // extern "C" 80 | #endif // __cplusplus 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /src/ktx/libktx/etcunpack.cxx: -------------------------------------------------------------------------------- 1 | /* -*- tab-width: 4; -*- */ 2 | /* vi: set sw=2 ts=4: */ 3 | 4 | /* $Id: b84f0063f86e9f20473d5a900eecbf1bf57b399c $ */ 5 | 6 | /* 7 | * Copyright 2010-2020 The Khronos Group Inc. 8 | * SPDX-License-Identifier: Apache-2.0 9 | */ 10 | 11 | /* @internal 12 | * @~English 13 | * @file 14 | * 15 | * Unpack a texture compressed with ETC1 16 | * 17 | * @author Mark Callow, HI Corporation. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #include "GL/glcorearb.h" 24 | // Not defined in glcorearb.h. 25 | #define GL_ETC1_RGB8_OES 0x8D64 26 | #include "ktx.h" 27 | #include "ktxint.h" 28 | 29 | #if SUPPORT_SOFTWARE_ETC_UNPACK 30 | typedef unsigned int uint; 31 | typedef unsigned char uint8; 32 | 33 | extern void decompressBlockETC2c(uint block_part1, uint block_part2, uint8* img, 34 | int width, int height, int startx, int starty, int channels); 35 | extern void decompressBlockETC21BitAlphaC(uint block_part1, uint block_part2, uint8* img, uint8* alphaimg, 36 | int width, int height, int startx, int starty, int channels); 37 | extern void decompressBlockAlphaC(uint8* data, uint8* img, 38 | int width, int height, int startx, int starty, int channels); 39 | extern void decompressBlockAlpha16bitC(uint8* data, uint8* img, 40 | int width, int height, int startx, int starty, int channels); 41 | 42 | extern void setupAlphaTable(); 43 | 44 | // This global variable affects the behaviour of decompressBlockAlpha16bitC. 45 | extern int formatSigned; 46 | 47 | static void 48 | readBigEndian4byteWord(ktx_uint32_t* pBlock, const GLubyte *s) 49 | { 50 | *pBlock = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | s[3]; 51 | } 52 | 53 | 54 | /* Unpack an ETC1_RGB8_OES format compressed texture */ 55 | extern "C" KTX_error_code 56 | _ktxUnpackETC(const GLubyte* srcETC, const GLenum srcFormat, 57 | ktx_uint32_t activeWidth, ktx_uint32_t activeHeight, 58 | GLubyte** dstImage, 59 | GLenum* format, GLenum* internalFormat, GLenum* type, 60 | GLint R16Formats, GLboolean supportsSRGB) 61 | { 62 | unsigned int width, height; 63 | unsigned int block_part1, block_part2; 64 | unsigned int x, y; 65 | /*const*/ GLubyte* src = (GLubyte*)srcETC; 66 | // AF_11BIT is used to compress R11 & RG11 though its not alpha data. 67 | enum {AF_NONE, AF_1BIT, AF_8BIT, AF_11BIT} alphaFormat = AF_NONE; 68 | int dstChannels, dstChannelBytes; 69 | 70 | switch (srcFormat) { 71 | case GL_COMPRESSED_SIGNED_R11_EAC: 72 | if (R16Formats & _KTX_R16_FORMATS_SNORM) { 73 | dstChannelBytes = sizeof(GLshort); 74 | dstChannels = 1; 75 | formatSigned = GL_TRUE; 76 | *internalFormat = GL_R16_SNORM; 77 | *format = GL_RED; 78 | *type = GL_SHORT; 79 | alphaFormat = AF_11BIT; 80 | } else 81 | return KTX_UNSUPPORTED_TEXTURE_TYPE; 82 | break; 83 | 84 | case GL_COMPRESSED_R11_EAC: 85 | if (R16Formats & _KTX_R16_FORMATS_NORM) { 86 | dstChannelBytes = sizeof(GLshort); 87 | dstChannels = 1; 88 | formatSigned = GL_FALSE; 89 | *internalFormat = GL_R16; 90 | *format = GL_RED; 91 | *type = GL_UNSIGNED_SHORT; 92 | alphaFormat = AF_11BIT; 93 | } else 94 | return KTX_UNSUPPORTED_TEXTURE_TYPE; 95 | break; 96 | 97 | case GL_COMPRESSED_SIGNED_RG11_EAC: 98 | if (R16Formats & _KTX_R16_FORMATS_SNORM) { 99 | dstChannelBytes = sizeof(GLshort); 100 | dstChannels = 2; 101 | formatSigned = GL_TRUE; 102 | *internalFormat = GL_RG16_SNORM; 103 | *format = GL_RG; 104 | *type = GL_SHORT; 105 | alphaFormat = AF_11BIT; 106 | } else 107 | return KTX_UNSUPPORTED_TEXTURE_TYPE; 108 | break; 109 | 110 | case GL_COMPRESSED_RG11_EAC: 111 | if (R16Formats & _KTX_R16_FORMATS_NORM) { 112 | dstChannelBytes = sizeof(GLshort); 113 | dstChannels = 2; 114 | formatSigned = GL_FALSE; 115 | *internalFormat = GL_RG16; 116 | *format = GL_RG; 117 | *type = GL_UNSIGNED_SHORT; 118 | alphaFormat = AF_11BIT; 119 | } else 120 | return KTX_UNSUPPORTED_TEXTURE_TYPE; 121 | break; 122 | 123 | case GL_ETC1_RGB8_OES: 124 | case GL_COMPRESSED_RGB8_ETC2: 125 | dstChannelBytes = sizeof(GLubyte); 126 | dstChannels = 3; 127 | *internalFormat = GL_RGB8; 128 | *format = GL_RGB; 129 | *type = GL_UNSIGNED_BYTE; 130 | break; 131 | 132 | case GL_COMPRESSED_RGBA8_ETC2_EAC: 133 | dstChannelBytes = sizeof(GLubyte); 134 | dstChannels = 4; 135 | *internalFormat = GL_RGBA8; 136 | *format = GL_RGBA; 137 | *type = GL_UNSIGNED_BYTE; 138 | alphaFormat = AF_8BIT; 139 | break; 140 | 141 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: 142 | dstChannelBytes = sizeof(GLubyte); 143 | dstChannels = 4; 144 | *internalFormat = GL_RGBA8; 145 | *format = GL_RGBA; 146 | *type = GL_UNSIGNED_BYTE; 147 | alphaFormat = AF_1BIT; 148 | break; 149 | 150 | case GL_COMPRESSED_SRGB8_ETC2: 151 | if (supportsSRGB) { 152 | dstChannelBytes = sizeof(GLubyte); 153 | dstChannels = 3; 154 | *internalFormat = GL_SRGB8; 155 | *format = GL_RGB; 156 | *type = GL_UNSIGNED_BYTE; 157 | } else 158 | return KTX_UNSUPPORTED_TEXTURE_TYPE; 159 | break; 160 | 161 | case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: 162 | if (supportsSRGB) { 163 | dstChannelBytes = sizeof(GLubyte); 164 | dstChannels = 4; 165 | *internalFormat = GL_SRGB8_ALPHA8; 166 | *format = GL_RGBA; 167 | *type = GL_UNSIGNED_BYTE; 168 | alphaFormat = AF_8BIT; 169 | } else 170 | return KTX_UNSUPPORTED_TEXTURE_TYPE; 171 | break; 172 | 173 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: 174 | if (supportsSRGB) { 175 | dstChannelBytes = sizeof(GLubyte); 176 | dstChannels = 4; 177 | *internalFormat = GL_SRGB8_ALPHA8; 178 | *format = GL_RGBA; 179 | *type = GL_UNSIGNED_BYTE; 180 | alphaFormat = AF_1BIT; 181 | } else 182 | return KTX_UNSUPPORTED_TEXTURE_TYPE; 183 | break; 184 | 185 | default: 186 | assert(0); // Upper levels should pass only one of the above srcFormats. 187 | return KTX_UNSUPPORTED_TEXTURE_TYPE; // For Release configurations. 188 | } 189 | 190 | /* active_{width,height} show how many pixels contain active data, 191 | * (the rest are just for making sure we have a 2*a x 4*b size). 192 | */ 193 | 194 | /* Compute the full width & height. */ 195 | width = ((activeWidth+3)/4)*4; 196 | height = ((activeHeight+3)/4)*4; 197 | 198 | /* printf("Width = %d, Height = %d\n", width, height); */ 199 | /* printf("active pixel area: top left %d x %d area.\n", activeWidth, activeHeight); */ 200 | 201 | *dstImage = (GLubyte*)malloc(dstChannels*dstChannelBytes*width*height); 202 | if (!*dstImage) { 203 | return KTX_OUT_OF_MEMORY; 204 | } 205 | 206 | if (alphaFormat != AF_NONE) 207 | setupAlphaTable(); 208 | 209 | // NOTE: none of the decompress functions actually use the parameter 210 | if (alphaFormat == AF_11BIT) { 211 | // One or two 11-bit alpha channels for R or RG. 212 | for (y=0; y < height/4; y++) { 213 | for (x=0; x < width/4; x++) { 214 | decompressBlockAlpha16bitC(src, *dstImage, width, height, 4*x, 4*y, dstChannels); 215 | src += 8; 216 | if (srcFormat == GL_COMPRESSED_RG11_EAC || srcFormat == GL_COMPRESSED_SIGNED_RG11_EAC) { 217 | decompressBlockAlpha16bitC(src, *dstImage + dstChannelBytes, width, height, 4*x, 4*y, dstChannels); 218 | src += 8; 219 | } 220 | } 221 | } 222 | } else { 223 | for (y=0; y < height/4; y++) { 224 | for (x=0; x < width/4; x++) { 225 | // Decode alpha channel for RGBA 226 | if (alphaFormat == AF_8BIT) { 227 | decompressBlockAlphaC(src, *dstImage + 3, width, height, 4*x, 4*y, dstChannels); 228 | src += 8; 229 | } 230 | // Decode color dstChannels 231 | readBigEndian4byteWord(&block_part1, src); 232 | src += 4; 233 | readBigEndian4byteWord(&block_part2, src); 234 | src += 4; 235 | if (alphaFormat == AF_1BIT) 236 | decompressBlockETC21BitAlphaC(block_part1, block_part2, *dstImage, 0, width, height, 4*x, 4*y, dstChannels); 237 | else 238 | decompressBlockETC2c(block_part1, block_part2, *dstImage, width, height, 4*x, 4*y, dstChannels); 239 | } 240 | } 241 | } 242 | 243 | /* Ok, now write out the active pixels to the destination image. 244 | * (But only if the active pixels differ from the total pixels) 245 | */ 246 | 247 | if( !(height == activeHeight && width == activeWidth) ) { 248 | int dstPixelBytes = dstChannels * dstChannelBytes; 249 | int dstRowBytes = dstPixelBytes * width; 250 | int activeRowBytes = activeWidth * dstPixelBytes; 251 | GLubyte *newimg = (GLubyte*)malloc(dstPixelBytes * activeWidth * activeHeight); 252 | unsigned int xx, yy; 253 | int zz; 254 | 255 | if (!newimg) { 256 | free(*dstImage); 257 | return KTX_OUT_OF_MEMORY; 258 | } 259 | 260 | /* Convert from total area to active area: */ 261 | 262 | for (yy = 0; yy < activeHeight; yy++) { 263 | for (xx = 0; xx < activeWidth; xx++) { 264 | for (zz = 0; zz < dstPixelBytes; zz++) { 265 | newimg[ yy*activeRowBytes + xx*dstPixelBytes + zz ] = (*dstImage)[ yy*dstRowBytes + xx*dstPixelBytes + zz]; 266 | } 267 | } 268 | } 269 | 270 | free(*dstImage); 271 | *dstImage = newimg; 272 | } 273 | 274 | return KTX_SUCCESS; 275 | } 276 | 277 | #endif /* SUPPORT_SOFTWARE_ETC_UNPACK */ 278 | -------------------------------------------------------------------------------- /src/ktx/libktx/filestream.h: -------------------------------------------------------------------------------- 1 | /* -*- tab-width: 4; -*- */ 2 | /* vi: set sw=2 ts=4 expandtab: */ 3 | 4 | /* 5 | * Copyright 2010-2020 The Khronos Group Inc. 6 | * SPDX-License-Identifier: Apache-2.0 7 | */ 8 | 9 | /* 10 | * Author: Maksim Kolesin from original code 11 | * by Mark Callow and Georg Kolling 12 | */ 13 | 14 | #ifndef FILESTREAM_H 15 | #define FILESTREAM_H 16 | 17 | #include "ktx.h" 18 | 19 | /* 20 | * ktxFileInit: Initialize a ktxStream to a ktxFileStream with a FILE object 21 | */ 22 | KTX_error_code ktxFileStream_construct(ktxStream* str, FILE* file, 23 | ktx_bool_t closeFileOnDestruct); 24 | 25 | void ktxFileStream_destruct(ktxStream* str); 26 | 27 | #endif /* FILESTREAM_H */ 28 | -------------------------------------------------------------------------------- /src/ktx/libktx/formatsize.h: -------------------------------------------------------------------------------- 1 | /* -*- tab-width: 4; -*- */ 2 | /* vi: set sw=2 ts=4 expandtab: */ 3 | 4 | /* 5 | * Copyright 2019-2020 The Khronos Group Inc. 6 | * SPDX-License-Identifier: Apache-2.0 7 | */ 8 | 9 | /** 10 | * @internal 11 | * @file 12 | * @~English 13 | * 14 | * @brief Struct for returning size information about an image format. 15 | * 16 | * @author Mark Callow, www.edgewise-consulting.com 17 | */ 18 | 19 | #ifndef _FORMATSIZE_H_ 20 | #define _FORMATSIZE_H_ 21 | 22 | #include "ktx.h" 23 | 24 | typedef enum ktxFormatSizeFlagBits { 25 | KTX_FORMAT_SIZE_PACKED_BIT = 0x00000001, 26 | KTX_FORMAT_SIZE_COMPRESSED_BIT = 0x00000002, 27 | KTX_FORMAT_SIZE_PALETTIZED_BIT = 0x00000004, 28 | KTX_FORMAT_SIZE_DEPTH_BIT = 0x00000008, 29 | KTX_FORMAT_SIZE_STENCIL_BIT = 0x00000010, 30 | } ktxFormatSizeFlagBits; 31 | 32 | typedef ktx_uint32_t ktxFormatSizeFlags; 33 | 34 | /** 35 | * @brief Structure for holding size information for a texture format. 36 | */ 37 | typedef struct ktxFormatSize { 38 | ktxFormatSizeFlags flags; 39 | unsigned int paletteSizeInBits; // For KTX1. 40 | unsigned int blockSizeInBits; 41 | unsigned int blockWidth; // in texels 42 | unsigned int blockHeight; // in texels 43 | unsigned int blockDepth; // in texels 44 | unsigned int minBlocksX; // Minimum required number of blocks 45 | unsigned int minBlocksY; 46 | } ktxFormatSize; 47 | 48 | #ifdef __cplusplus 49 | extern "C" { 50 | #endif 51 | 52 | bool ktxFormatSize_initFromDfd(ktxFormatSize* This, ktx_uint32_t* pDfd); 53 | 54 | #ifdef __cplusplus 55 | } // extern "C" 56 | #endif 57 | 58 | #endif /* _FORMATSIZE_H_ */ 59 | -------------------------------------------------------------------------------- /src/ktx/libktx/gl_funclist.inl: -------------------------------------------------------------------------------- 1 | /* -*- tab-width: 4; -*- */ 2 | /* vi: set sw=2 ts=4 expandtab textwidth=70: */ 3 | 4 | /* 5 | * Copyright 2017-2020 Mark Callow. 6 | * SPDX-License-Identifier: Apache-2.0 7 | */ 8 | 9 | /** 10 | * @internal 11 | * @file gl_funclist.h 12 | * @~English 13 | * 14 | * @brief List of OpenGL {,ES} functions used by libktx. 15 | */ 16 | 17 | // There is no way for the pre-processor to uppercase stringized macro args 18 | // so we have to explicitly give the types. 19 | 20 | #define required 1 // Present in all GL versions. Load failure is an error. 21 | #define not_required 0 // May not be present. Code must check before calling. 22 | 23 | GL_FUNCTION(PFNGLBINDTEXTUREPROC, glBindTexture, required) 24 | GL_FUNCTION(PFNGLCOMPRESSEDTEXIMAGE1DPROC, glCompressedTexImage1D, not_required) 25 | GL_FUNCTION(PFNGLCOMPRESSEDTEXIMAGE2DPROC, glCompressedTexImage2D, required) 26 | GL_FUNCTION(PFNGLCOMPRESSEDTEXIMAGE3DPROC, glCompressedTexImage3D, not_required) 27 | GL_FUNCTION(PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC, glCompressedTexSubImage1D, not_required) 28 | GL_FUNCTION(PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC, glCompressedTexSubImage2D, required) 29 | GL_FUNCTION(PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC, glCompressedTexSubImage3D, not_required) 30 | GL_FUNCTION(PFNGLDELETETEXTURESPROC, glDeleteTextures, required) 31 | GL_FUNCTION(PFNGLGENERATEMIPMAPPROC, glGenerateMipmap, not_required) 32 | GL_FUNCTION(PFNGLGENTEXTURESPROC, glGenTextures, required) 33 | GL_FUNCTION(PFNGLGETERRORPROC, glGetError, required) 34 | GL_FUNCTION(PFNGLGETINTEGERVPROC, glGetIntegerv, required) 35 | GL_FUNCTION(PFNGLGETSTRINGPROC, glGetString, required) 36 | GL_FUNCTION(PFNGLGETSTRINGIPROC, glGetStringi, not_required) 37 | GL_FUNCTION(PFNGLPIXELSTOREIPROC, glPixelStorei, required) 38 | GL_FUNCTION(PFNGLTEXIMAGE1DPROC, glTexImage1D, not_required) 39 | GL_FUNCTION(PFNGLTEXIMAGE2DPROC, glTexImage2D, required) 40 | GL_FUNCTION(PFNGLTEXIMAGE3DPROC, glTexImage3D, not_required) 41 | GL_FUNCTION(PFNGLTEXPARAMETERIPROC, glTexParameteri, required) 42 | GL_FUNCTION(PFNGLTEXPARAMETERIVPROC, glTexParameteriv, required) 43 | GL_FUNCTION(PFNGLTEXSTORAGE1DPROC, glTexStorage1D, not_required) 44 | GL_FUNCTION(PFNGLTEXSTORAGE2DPROC, glTexStorage2D, not_required) 45 | GL_FUNCTION(PFNGLTEXSTORAGE3DPROC, glTexStorage3D, not_required) 46 | GL_FUNCTION(PFNGLTEXSUBIMAGE1DPROC, glTexSubImage1D, not_required) 47 | GL_FUNCTION(PFNGLTEXSUBIMAGE2DPROC, glTexSubImage2D, required) 48 | GL_FUNCTION(PFNGLTEXSUBIMAGE3DPROC, glTexSubImage3D, not_required) 49 | 50 | #undef required 51 | #undef not_required 52 | -------------------------------------------------------------------------------- /src/ktx/libktx/gl_funcs.c: -------------------------------------------------------------------------------- 1 | /* -*- tab-width: 4; -*- */ 2 | /* vi: set sw=2 ts=4 expandtab textwidth=70: */ 3 | 4 | /* 5 | * Copyright 2017-2020 Mark Callow. 6 | * SPDX-License-Identifier: Apache-2.0 7 | */ 8 | 9 | /** 10 | * @internal 11 | * @file gl_funcs.c 12 | * @~English 13 | * 14 | * @brief Retrieve OpenGL function pointers needed by libktx 15 | */ 16 | 17 | #define UNIX 0 18 | #define MACOS 0 19 | #define WINDOWS 0 20 | #define IOS 0 21 | 22 | #if defined(_WIN32) 23 | #undef WINDOWS 24 | #define WINDOWS 1 25 | #endif 26 | #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__) 27 | #undef UNIX 28 | #define UNIX 1 29 | #endif 30 | #if defined(linux) || defined(__linux) || defined(__linux__) 31 | #undef UNIX 32 | #define UNIX 1 33 | #endif 34 | #if defined(__APPLE__) && defined(__x86_64__) 35 | #undef MACOS 36 | #define MACOS 1 37 | #endif 38 | #if defined(__APPLE__) && (defined(__arm64__) || defined (__arm__)) 39 | #undef IOS 40 | #define IOS 1 41 | #endif 42 | #if defined(__EMSCRIPTEN__) 43 | #define WEB 1 44 | #endif 45 | #if (IOS + MACOS + UNIX + WINDOWS + WEB) > 1 46 | #error "Multiple OS\'s defined" 47 | #endif 48 | 49 | #if WINDOWS 50 | #define WINDOWS_LEAN_AND_MEAN 51 | #include 52 | #else 53 | #include 54 | #include 55 | #define WINAPI 56 | #endif 57 | #define NO_SHORTCUTS 58 | #include "gl_funcs.h" 59 | 60 | #if WINDOWS 61 | #define GetOpenGLModuleHandle(flags) ktxFindOpenGL() 62 | #define LoadProcAddr GetProcAddress 63 | HMODULE ktxOpenGLModuleHandle; 64 | #elif MACOS || UNIX || IOS 65 | // Using NULL returns a handle that can be used to search the process that 66 | // loaded us and any other libraries it has loaded. That's all we need to 67 | // search as the app is responsible for creating the GL context so it must 68 | // be there. 69 | #define GetOpenGLModuleHandle(flags) dlopen(NULL, flags) 70 | #define LoadProcAddr dlsym 71 | #define LIBRARY_NAME NULL 72 | void* ktxOpenGLModuleHandle; 73 | #elif WEB 74 | extern void* emscripten_GetProcAddress(const char *name_); 75 | #define GetOpenGLModuleHandle(flag) (void*)0x0000ffff // Value doesn't matter. 76 | #define LoadProcAddr(lib, proc) emscripten_GetProcAddress(proc) 77 | #define LIBRARY_NAME "unused" 78 | void* ktxOpenGLModuleHandle; 79 | #else 80 | #error "Don\'t know how to load symbols on this OS." 81 | #endif 82 | 83 | typedef void (WINAPI *PFNVOIDFUNCTION)(void); 84 | typedef PFNVOIDFUNCTION *(WINAPI * PFNWGLGETPROCADDRESS) (const char *proc); 85 | static PFNWGLGETPROCADDRESS wglGetProcAddressPtr; 86 | static const char* noloadmsg = "Could not load OpenGL command: %s!\n"; 87 | 88 | /* Define pointers for functions libktx is using. */ 89 | struct glFuncPtrs gl; 90 | 91 | #if defined(__GNUC__) 92 | // This strange casting is because dlsym returns a void* thus is not 93 | // compatible with ISO C which forbids conversion of object pointers 94 | // to function pointers. The cast masks the conversion from the 95 | // compiler thus no warning even though -pedantic is set. Since the 96 | // platform supports dlsym, conversion to function pointers must 97 | // work, despite the mandated ISO C warning. 98 | #define GL_FUNCTION(type, func, required) \ 99 | if ( wglGetProcAddressPtr ) \ 100 | *(void **)(&gl.func) = wglGetProcAddressPtr(#func); \ 101 | if ( !gl.func ) \ 102 | *(void **)(&gl.func) = LoadProcAddr(ktxOpenGLModuleHandle, #func); \ 103 | if ( !gl.func && required ) { \ 104 | fprintf(stderr, noloadmsg, #func); \ 105 | return KTX_FALSE; \ 106 | } 107 | #else 108 | #define GL_FUNCTION(type, func, required) \ 109 | if ( wglGetProcAddressPtr ) \ 110 | gl.func = (type)wglGetProcAddressPtr(#func); \ 111 | if ( !gl.##func) \ 112 | gl.func = (type)LoadProcAddr(ktxOpenGLModuleHandle, #func); \ 113 | if ( !gl.func && required) { \ 114 | fprintf(stderr, noloadmsg, #func); \ 115 | return KTX_FALSE; \ 116 | } 117 | #endif 118 | 119 | #if WINDOWS 120 | static HMODULE 121 | ktxFindOpenGL() { 122 | HMODULE module = 0; 123 | BOOL found; 124 | // Use GetModule not LoadLibrary so we only succeed if the process 125 | // has already loaded some OpenGL library. 126 | // Check current module to see if we are statically linked to GL. 127 | found = GetModuleHandleExA( 128 | GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, 129 | (LPCSTR)ktxFindOpenGL, 130 | &module 131 | ); 132 | if (found) { 133 | if (LoadProcAddr(module, "glGetError") != NULL) 134 | return module; 135 | } 136 | // Not statically linked. See what dll the process has loaded. 137 | // Emulators probably also have opengl32.lib loaded so check that last. 138 | found = GetModuleHandleExA( 139 | 0, 140 | "libGLESv2.dll", 141 | &module 142 | ); 143 | if (found) return module; 144 | found = GetModuleHandleExA( 145 | 0, 146 | "libGLES_CM.dll", 147 | &module 148 | ); 149 | if (found) return module; 150 | found = GetModuleHandleExA( 151 | 0, 152 | "opengl32.dll", 153 | &module 154 | ); 155 | if (found) { 156 | // Need wglGetProcAddr for non-OpenGL-2 functions. 157 | wglGetProcAddressPtr = 158 | (PFNWGLGETPROCADDRESS)LoadProcAddr(module, 159 | "wglGetProcAddress"); 160 | if (wglGetProcAddressPtr != NULL) 161 | return module; 162 | } 163 | return module; // Keep the compiler happy! 164 | } 165 | #endif 166 | 167 | ktx_error_code_e 168 | ktxLoadOpenGLLibrary(void) 169 | { 170 | if (ktxOpenGLModuleHandle) 171 | return KTX_SUCCESS; 172 | 173 | ktxOpenGLModuleHandle = GetOpenGLModuleHandle(RTLD_LAZY); 174 | if (ktxOpenGLModuleHandle == NULL) { 175 | fprintf(stderr, "OpenGL lib not linked or loaded by application.\n"); 176 | // Normal use is for this constructor to be called by an 177 | // application that has completed OpenGL initialization. In that 178 | // case the only cause for failure would be a coding error in our 179 | // library loading. The only other cause would be an application 180 | // calling GLUpload without having initialized OpenGL. 181 | #if defined(DEBUG) 182 | abort(); 183 | #else 184 | return KTX_LIBRARY_NOT_LINKED; // So release version doesn't crash. 185 | #endif 186 | } 187 | 188 | #include "gl_funclist.inl" 189 | 190 | return KTX_SUCCESS; 191 | } 192 | 193 | #undef GL_FUNCTION 194 | 195 | -------------------------------------------------------------------------------- /src/ktx/libktx/gl_funcs.h: -------------------------------------------------------------------------------- 1 | /* -*- tab-width: 4; -*- */ 2 | /* vi: set sw=2 ts=4 expandtab textwidth=70: */ 3 | 4 | /* 5 | * Copyright 2017-2020 Mark Callow. 6 | * SPDX-License-Identifier: Apache-2.0 7 | */ 8 | 9 | /** 10 | * @internal 11 | * @file vk_funcs.h 12 | * @~English 13 | * 14 | * @brief Declare pointers for OpenGL {,ES} functions. 15 | * 16 | * Dynamically retrieving pointers avoids apps or shared library builds having to link with OpenGL {,ES} 17 | * and avoids the need for compiling different versions of the libary for different OpenGL {,ES} versions. 18 | */ 19 | 20 | #ifndef _GL_FUNCS_H_ 21 | #define _GL_FUNCS_H_ 22 | 23 | #undef GL_GLEXT_PROTOTYPES // Just to be sure. 24 | #include "GL/glcorearb.h" 25 | #include "ktx.h" 26 | 27 | #if WINDOWS 28 | #define WINDOWS_LEAN_AND_MEAN 29 | #include 30 | extern HMODULE ktxOpenGLModuleHandle; 31 | #else 32 | extern void* ktxOpenGLModuleHandle; 33 | #endif 34 | 35 | extern ktx_error_code_e ktxLoadOpenGLLibrary(void); 36 | 37 | #define GL_FUNCTION(type, fun, required) type fun; 38 | 39 | extern struct glFuncPtrs { 40 | #include "gl_funclist.inl" 41 | } gl; 42 | 43 | #undef GL_FUNCTION 44 | 45 | #if !defined(NO_SHORTCUTS) 46 | // Macros to allow standard, i.e always present functions, to be called 47 | // by their prototype names. 48 | #define glBindTexture gl.glBindTexture 49 | #define glCompressedTexImage2D gl.glCompressedTexImage2D 50 | #define glCompressedTexSubImage2D gl.glCompressedTexSubImage2D 51 | #define glDeleteTextures gl.glDeleteTextures 52 | #define glGenTextures gl.glGenTextures 53 | #define glGetError gl.glGetError 54 | #define glGetIntegerv gl.glGetIntegerv 55 | #define glGetString(x) (const char*)gl.glGetString(x) 56 | #define glPixelStorei gl.glPixelStorei 57 | #define glTexImage2D gl.glTexImage2D 58 | #define glTexSubImage2D gl.glTexSubImage2D 59 | #define glTexParameteri gl.glTexParameteri 60 | #define glTexParameteriv gl.glTexParameteriv 61 | #endif 62 | 63 | #endif /* _GL_FUNCS_H_ */ 64 | 65 | -------------------------------------------------------------------------------- /src/ktx/libktx/ktx_zstd_errors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020, Yann Collet, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under both the BSD-style license (found in the 6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found 7 | * in the COPYING file in the root directory of this source tree). 8 | * You may select, at your option, one of the above-listed licenses. 9 | */ 10 | 11 | #ifndef ZSTD_ERRORS_H_398273423 12 | #define ZSTD_ERRORS_H_398273423 13 | 14 | #if defined (__cplusplus) 15 | extern "C" { 16 | #endif 17 | 18 | /*===== dependency =====*/ 19 | #include /* size_t */ 20 | 21 | 22 | /* ===== ZSTDERRORLIB_API : control library symbols visibility ===== */ 23 | #ifndef ZSTDERRORLIB_VISIBILITY 24 | # if defined(__GNUC__) && (__GNUC__ >= 4) 25 | # define ZSTDERRORLIB_VISIBILITY __attribute__ ((visibility ("hidden"))) 26 | # else 27 | # define ZSTDERRORLIB_VISIBILITY 28 | # endif 29 | #endif 30 | #if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1) 31 | # define ZSTDERRORLIB_API __declspec(dllexport) ZSTDERRORLIB_VISIBILITY 32 | #elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1) 33 | # define ZSTDERRORLIB_API __declspec(dllimport) ZSTDERRORLIB_VISIBILITY /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/ 34 | #else 35 | # define ZSTDERRORLIB_API ZSTDERRORLIB_VISIBILITY 36 | #endif 37 | 38 | /*-********************************************* 39 | * Error codes list 40 | *-********************************************* 41 | * Error codes _values_ are pinned down since v1.3.1 only. 42 | * Therefore, don't rely on values if you may link to any version < v1.3.1. 43 | * 44 | * Only values < 100 are considered stable. 45 | * 46 | * note 1 : this API shall be used with static linking only. 47 | * dynamic linking is not yet officially supported. 48 | * note 2 : Prefer relying on the enum than on its value whenever possible 49 | * This is the only supported way to use the error list < v1.3.1 50 | * note 3 : ZSTD_isError() is always correct, whatever the library version. 51 | **********************************************/ 52 | typedef enum { 53 | ZSTD_error_no_error = 0, 54 | ZSTD_error_GENERIC = 1, 55 | ZSTD_error_prefix_unknown = 10, 56 | ZSTD_error_version_unsupported = 12, 57 | ZSTD_error_frameParameter_unsupported = 14, 58 | ZSTD_error_frameParameter_windowTooLarge = 16, 59 | ZSTD_error_corruption_detected = 20, 60 | ZSTD_error_checksum_wrong = 22, 61 | ZSTD_error_dictionary_corrupted = 30, 62 | ZSTD_error_dictionary_wrong = 32, 63 | ZSTD_error_dictionaryCreation_failed = 34, 64 | ZSTD_error_parameter_unsupported = 40, 65 | ZSTD_error_parameter_outOfBound = 42, 66 | ZSTD_error_tableLog_tooLarge = 44, 67 | ZSTD_error_maxSymbolValue_tooLarge = 46, 68 | ZSTD_error_maxSymbolValue_tooSmall = 48, 69 | ZSTD_error_stage_wrong = 60, 70 | ZSTD_error_init_missing = 62, 71 | ZSTD_error_memory_allocation = 64, 72 | ZSTD_error_workSpace_tooSmall= 66, 73 | ZSTD_error_dstSize_tooSmall = 70, 74 | ZSTD_error_srcSize_wrong = 72, 75 | ZSTD_error_dstBuffer_null = 74, 76 | /* following error codes are __NOT STABLE__, they can be removed or changed in future versions */ 77 | ZSTD_error_frameIndex_tooLarge = 100, 78 | ZSTD_error_seekableIO = 102, 79 | ZSTD_error_maxCode = 120 /* never EVER use this value directly, it can change in future versions! Use ZSTD_isError() instead */ 80 | } ZSTD_ErrorCode; 81 | 82 | /*! ZSTD_getErrorCode() : 83 | convert a `size_t` function result into a `ZSTD_ErrorCode` enum type, 84 | which can be used to compare with enum list published above */ 85 | ZSTDERRORLIB_API ZSTD_ErrorCode ZSTD_getErrorCode(size_t functionResult); 86 | ZSTDERRORLIB_API const char* ZSTD_getErrorString(ZSTD_ErrorCode code); /**< Same as ZSTD_getErrorName, but using a `ZSTD_ErrorCode` enum argument */ 87 | 88 | 89 | #if defined (__cplusplus) 90 | } 91 | #endif 92 | 93 | #endif /* ZSTD_ERRORS_H_398273423 */ 94 | -------------------------------------------------------------------------------- /src/ktx/libktx/ktxint.h: -------------------------------------------------------------------------------- 1 | /* -*- tab-width: 4; -*- */ 2 | /* vi: set sw=2 ts=4 expandtab: */ 3 | 4 | /* $Id: e36ad79b5eac8ea237d6a05602c71aadab575519 $ */ 5 | 6 | /* 7 | * Copyright 2010-2020 The Khronos Group Inc. 8 | * SPDX-License-Identifier: Apache-2.0 9 | */ 10 | 11 | 12 | /* 13 | * Author: Mark Callow from original code by Georg Kolling 14 | */ 15 | 16 | #ifndef KTXINT_H 17 | #define KTXINT_H 18 | 19 | #include 20 | 21 | /* Define this to include the ETC unpack software in the library. */ 22 | #ifndef SUPPORT_SOFTWARE_ETC_UNPACK 23 | /* Include for all GL versions because have seen OpenGL ES 3 24 | * implementaions that do not support ETC1 (ARM Mali emulator v1.0)! 25 | */ 26 | #define SUPPORT_SOFTWARE_ETC_UNPACK 1 27 | #endif 28 | 29 | #ifndef MAX 30 | #define MAX(x, y) (((x) > (y)) ? (x) : (y)) 31 | #endif 32 | 33 | #define QUOTE(x) #x 34 | #define STR(x) QUOTE(x) 35 | 36 | #define KTX2_IDENTIFIER_REF { 0xAB, 0x4B, 0x54, 0x58, 0x20, 0x32, 0x30, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A } 37 | #define KTX2_HEADER_SIZE (80) 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /** 44 | * @internal 45 | * @brief used to pass GL context capabilites to subroutines. 46 | */ 47 | #define _KTX_NO_R16_FORMATS 0x0 48 | #define _KTX_R16_FORMATS_NORM 0x1 49 | #define _KTX_R16_FORMATS_SNORM 0x2 50 | #define _KTX_ALL_R16_FORMATS (_KTX_R16_FORMATS_NORM | _KTX_R16_FORMATS_SNORM) 51 | extern GLint _ktxR16Formats; 52 | extern GLboolean _ktxSupportsSRGB; 53 | 54 | /** 55 | * @internal 56 | * @~English 57 | * @brief KTX file header. 58 | * 59 | * See the KTX specification for descriptions. 60 | */ 61 | typedef struct KTX_header { 62 | ktx_uint8_t identifier[12]; 63 | ktx_uint32_t endianness; 64 | ktx_uint32_t glType; 65 | ktx_uint32_t glTypeSize; 66 | ktx_uint32_t glFormat; 67 | ktx_uint32_t glInternalformat; 68 | ktx_uint32_t glBaseInternalformat; 69 | ktx_uint32_t pixelWidth; 70 | ktx_uint32_t pixelHeight; 71 | ktx_uint32_t pixelDepth; 72 | ktx_uint32_t numberOfArrayElements; 73 | ktx_uint32_t numberOfFaces; 74 | ktx_uint32_t numberOfMipLevels; 75 | ktx_uint32_t bytesOfKeyValueData; 76 | } KTX_header; 77 | 78 | /* This will cause compilation to fail if the struct size doesn't match */ 79 | typedef int KTX_header_SIZE_ASSERT [sizeof(KTX_header) == KTX_HEADER_SIZE]; 80 | 81 | /** 82 | * @internal 83 | * @~English 84 | * @brief 32-bit KTX 2 index entry. 85 | */ 86 | typedef struct ktxIndexEntry32 { 87 | ktx_uint32_t byteOffset; /*!< Offset of item from start of file. */ 88 | ktx_uint32_t byteLength; /*!< Number of bytes of data in the item. */ 89 | } ktxIndexEntry32; 90 | /** 91 | * @internal 92 | * @~English 93 | * @brief 64-bit KTX 2 index entry. 94 | */ 95 | typedef struct ktxIndexEntry64 { 96 | ktx_uint64_t byteOffset; /*!< Offset of item from start of file. */ 97 | ktx_uint64_t byteLength; /*!< Number of bytes of data in the item. */ 98 | } ktxIndexEntry64; 99 | 100 | /** 101 | * @internal 102 | * @~English 103 | * @brief KTX 2 file header. 104 | * 105 | * See the KTX 2 specification for descriptions. 106 | */ 107 | typedef struct KTX_header2 { 108 | ktx_uint8_t identifier[12]; 109 | ktx_uint32_t vkFormat; 110 | ktx_uint32_t typeSize; 111 | ktx_uint32_t pixelWidth; 112 | ktx_uint32_t pixelHeight; 113 | ktx_uint32_t pixelDepth; 114 | ktx_uint32_t layerCount; 115 | ktx_uint32_t faceCount; 116 | ktx_uint32_t levelCount; 117 | ktx_uint32_t supercompressionScheme; 118 | ktxIndexEntry32 dataFormatDescriptor; 119 | ktxIndexEntry32 keyValueData; 120 | ktxIndexEntry64 supercompressionGlobalData; 121 | } KTX_header2; 122 | 123 | /* This will cause compilation to fail if the struct size doesn't match */ 124 | typedef int KTX_header2_SIZE_ASSERT [sizeof(KTX_header2) == KTX2_HEADER_SIZE]; 125 | 126 | /** 127 | * @internal 128 | * @~English 129 | * @brief KTX 2 level index entry. 130 | */ 131 | typedef struct ktxLevelIndexEntry { 132 | ktx_uint64_t byteOffset; /*!< Offset of level from start of file. */ 133 | ktx_uint64_t byteLength; 134 | /*!< Number of bytes of compressed image data in the level. */ 135 | ktx_uint64_t uncompressedByteLength; 136 | /*!< Number of bytes of uncompressed image data in the level. */ 137 | } ktxLevelIndexEntry; 138 | 139 | /** 140 | * @internal 141 | * @~English 142 | * @brief Structure for supplemental information about the texture. 143 | * 144 | * _ktxCheckHeader returns supplemental information about the texture in this 145 | * structure that is derived during checking of the file header. 146 | */ 147 | typedef struct KTX_supplemental_info 148 | { 149 | ktx_uint8_t compressed; 150 | ktx_uint8_t generateMipmaps; 151 | ktx_uint16_t textureDimension; 152 | } KTX_supplemental_info; 153 | /** 154 | * @internal 155 | * @var ktx_uint8_t KTX_supplemental_info::compressed 156 | * @~English 157 | * @brief KTX_TRUE, if this a compressed texture, KTX_FALSE otherwise? 158 | */ 159 | /** 160 | * @internal 161 | * @var ktx_uint8_t KTX_supplemental_info::generateMipmaps 162 | * @~English 163 | * @brief KTX_TRUE, if mipmap generation is required, KTX_FALSE otherwise. 164 | */ 165 | /** 166 | * @internal 167 | * @var ktx_uint16_t KTX_supplemental_info::textureDimension 168 | * @~English 169 | * @brief The number of dimensions, 1, 2 or 3, of data in the texture image. 170 | */ 171 | 172 | /* 173 | * @internal 174 | * CheckHeader1 175 | * 176 | * Reads the KTX file header and performs some sanity checking on the values 177 | */ 178 | KTX_error_code ktxCheckHeader1_(KTX_header* pHeader, 179 | KTX_supplemental_info* pSuppInfo); 180 | 181 | /* 182 | * @internal 183 | * CheckHeader2 184 | * 185 | * Reads the KTX 2 file header and performs some sanity checking on the values 186 | */ 187 | KTX_error_code ktxCheckHeader2_(KTX_header2* pHeader, 188 | KTX_supplemental_info* pSuppInfo); 189 | 190 | /* 191 | * SwapEndian16: Swaps endianness in an array of 16-bit values 192 | */ 193 | void _ktxSwapEndian16(ktx_uint16_t* pData16, ktx_size_t count); 194 | 195 | /* 196 | * SwapEndian32: Swaps endianness in an array of 32-bit values 197 | */ 198 | void _ktxSwapEndian32(ktx_uint32_t* pData32, ktx_size_t count); 199 | 200 | /* 201 | * SwapEndian32: Swaps endianness in an array of 64-bit values 202 | */ 203 | void _ktxSwapEndian64(ktx_uint64_t* pData64, ktx_size_t count); 204 | 205 | /* 206 | * UnpackETC: uncompresses an ETC compressed texture image 207 | */ 208 | KTX_error_code _ktxUnpackETC(const GLubyte* srcETC, const GLenum srcFormat, 209 | ktx_uint32_t active_width, ktx_uint32_t active_height, 210 | GLubyte** dstImage, 211 | GLenum* format, GLenum* internalFormat, GLenum* type, 212 | GLint R16Formats, GLboolean supportsSRGB); 213 | 214 | /* 215 | * Pad nbytes to next multiple of n 216 | */ 217 | #define _KTX_PADN(n, nbytes) (ktx_uint32_t)(n * ceilf((float)(nbytes) / n)) 218 | /* 219 | * Calculate bytes of of padding needed to reach next multiple of n. 220 | */ 221 | /* Equivalent to (n * ceil(nbytes / n)) - nbytes */ 222 | #define _KTX_PADN_LEN(n, nbytes) \ 223 | (ktx_uint32_t)((n * ceilf((float)(nbytes) / n)) - (nbytes)) 224 | 225 | /* 226 | * Pad nbytes to next multiple of 4 227 | */ 228 | #define _KTX_PAD4(nbytes) _KTX_PADN(4, nbytes) 229 | /* 230 | * Calculate bytes of of padding needed to reach next multiple of 4. 231 | */ 232 | #define _KTX_PAD4_LEN(nbytes) _KTX_PADN_LEN(4, nbytes) 233 | 234 | /* 235 | * Pad nbytes to next multiple of 8 236 | */ 237 | #define _KTX_PAD8(nbytes) _KTX_PADN(8, nbytes) 238 | /* 239 | * Calculate bytes of of padding needed to reach next multiple of 8. 240 | */ 241 | #define _KTX_PAD8_LEN(nbytes) _KTX_PADN_LEN(8, nbytes) 242 | 243 | /* 244 | * Pad nbytes to KTX_GL_UNPACK_ALIGNMENT 245 | */ 246 | #define _KTX_PAD_UNPACK_ALIGN(nbytes) \ 247 | _KTX_PADN(KTX_GL_UNPACK_ALIGNMENT, nbytes) 248 | /* 249 | * Calculate bytes of of padding needed to reach KTX_GL_UNPACK_ALIGNMENT. 250 | */ 251 | #define _KTX_PAD_UNPACK_ALIGN_LEN(nbytes) \ 252 | _KTX_PADN_LEN(KTX_GL_UNPACK_ALIGNMENT, nbytes) 253 | 254 | /* 255 | ====================================== 256 | Internal utility functions 257 | ====================================== 258 | */ 259 | 260 | void printKTX2Info2(ktxStream* src, KTX_header2* header); 261 | 262 | #ifdef __cplusplus 263 | } 264 | #endif 265 | 266 | #endif /* KTXINT_H */ 267 | -------------------------------------------------------------------------------- /src/ktx/libktx/ktxvulkan.h: -------------------------------------------------------------------------------- 1 | /* -*- tab-width: 4; -*- */ 2 | /* vi: set sw=2 ts=4 expandtab: */ 3 | 4 | #ifndef KTX_H_C54B42AEE39611E68E1E4FF8C51D1C66 5 | #define KTX_H_C54B42AEE39611E68E1E4FF8C51D1C66 6 | 7 | /* 8 | * Copyright 2017-2020 The Khronos Group, Inc. 9 | * SPDX-License-Identifier: Apache-2.0 10 | */ 11 | 12 | /** 13 | * @internal 14 | * @file 15 | * @~English 16 | * 17 | * @brief Declares the public functions and structures of the 18 | * KTX Vulkan texture loading API. 19 | * 20 | * A separate header file is used to avoid extra dependencies for those not 21 | * using Vulkan. The nature of the Vulkan API, rampant structures and enums, 22 | * means that vulkan.h must be included @e before including this file. The 23 | * alternative is duplicating unattractively large parts of it. 24 | * 25 | * @author Mark Callow, Edgewise Consulting 26 | * 27 | * $Date$ 28 | */ 29 | 30 | #include 31 | 32 | #if 0 33 | /* Avoid Vulkan include file */ 34 | #define VK_DEFINE_HANDLE(object) typedef struct object##_T* object; 35 | 36 | #if defined(__LP64__) || defined(_WIN64) || defined(__x86_64__) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__) 37 | #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef struct object##_T *object; 38 | #else 39 | #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object; 40 | #endif 41 | 42 | VK_DEFINE_HANDLE(VkPhysicalDevice) 43 | VK_DEFINE_HANDLE(VkDevice) 44 | VK_DEFINE_HANDLE(VkQueue) 45 | VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkCommandPool) 46 | VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDeviceMemory) 47 | VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkImage) 48 | VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkImageView) 49 | VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSampler) 50 | #endif 51 | 52 | #ifdef __cplusplus 53 | extern "C" { 54 | #endif 55 | 56 | /** 57 | * @class ktxVulkanTexture 58 | * @brief Struct for returning information about the Vulkan texture image 59 | * created by the ktxTexture_VkUpload* functions. 60 | * 61 | * Creation of these objects is internal to the upload functions. 62 | */ 63 | typedef struct ktxVulkanTexture 64 | { 65 | VkImage image; /*!< Handle to the Vulkan image created by the loader. */ 66 | VkFormat imageFormat; /*!< Format of the image data. */ 67 | VkImageLayout imageLayout; /*!< Layout of the created image. Has the same 68 | value as @p layout parameter passed to the 69 | loader. */ 70 | VkDeviceMemory deviceMemory; /*!< The memory allocated for the image on 71 | the Vulkan device. */ 72 | VkImageViewType viewType; /*!< ViewType corresponding to @p image. Reflects 73 | the dimensionality, cubeness and arrayness 74 | of the image. */ 75 | uint32_t width; /*!< The width of the image. */ 76 | uint32_t height; /*!< The height of the image. */ 77 | uint32_t depth; /*!< The depth of the image. */ 78 | uint32_t levelCount; /*!< The number of MIP levels in the image. */ 79 | uint32_t layerCount; /*!< The number of array layers in the image. */ 80 | } ktxVulkanTexture; 81 | 82 | KTX_API void KTX_APIENTRY 83 | ktxVulkanTexture_Destruct(ktxVulkanTexture* This, VkDevice device, 84 | const VkAllocationCallbacks* pAllocator); 85 | 86 | /** 87 | * @class ktxVulkanDeviceInfo 88 | * @brief Struct for passing information about the Vulkan device on which 89 | * to create images to the texture image loading functions. 90 | * 91 | * Avoids passing a large number of parameters to each loading function. 92 | * Use of ktxVulkanDeviceInfo_create() or ktxVulkanDeviceInfo_construct() to 93 | * populate this structure is highly recommended. 94 | * 95 | * @code 96 | ktxVulkanDeviceInfo vdi; 97 | ktxVulkanTexture texture; 98 | 99 | vdi = ktxVulkanDeviceInfo_create(physicalDevice, 100 | device, 101 | queue, 102 | cmdPool, 103 | &allocator); 104 | ktxLoadVkTextureN("texture_1.ktx", vdi, &texture, NULL, NULL); 105 | // ... 106 | ktxLoadVkTextureN("texture_n.ktx", vdi, &texture, NULL, NULL); 107 | ktxVulkanDeviceInfo_destroy(vdi); 108 | * @endcode 109 | */ 110 | typedef struct ktxVulkanDeviceInfo { 111 | VkPhysicalDevice physicalDevice; /*!< Handle of the physical device. */ 112 | VkDevice device; /*!< Handle of the logical device. */ 113 | VkQueue queue; /*!< Handle to the queue to which to submit commands. */ 114 | VkCommandBuffer cmdBuffer; /*!< Handle of the cmdBuffer to use. */ 115 | /** Handle of the command pool from which to allocate the command buffer. */ 116 | VkCommandPool cmdPool; 117 | /** Pointer to the allocator to use for the command buffer and created 118 | * images. 119 | */ 120 | const VkAllocationCallbacks* pAllocator; 121 | /** Memory properties of the Vulkan physical device. */ 122 | VkPhysicalDeviceMemoryProperties deviceMemoryProperties; 123 | } ktxVulkanDeviceInfo; 124 | 125 | KTX_API ktxVulkanDeviceInfo* KTX_APIENTRY 126 | ktxVulkanDeviceInfo_Create(VkPhysicalDevice physicalDevice, VkDevice device, 127 | VkQueue queue, VkCommandPool cmdPool, 128 | const VkAllocationCallbacks* pAllocator); 129 | KTX_API KTX_error_code KTX_APIENTRY 130 | ktxVulkanDeviceInfo_Construct(ktxVulkanDeviceInfo* This, 131 | VkPhysicalDevice physicalDevice, VkDevice device, 132 | VkQueue queue, VkCommandPool cmdPool, 133 | const VkAllocationCallbacks* pAllocator); 134 | KTX_API void KTX_APIENTRY 135 | ktxVulkanDeviceInfo_Destruct(ktxVulkanDeviceInfo* This); 136 | KTX_API void KTX_APIENTRY 137 | ktxVulkanDeviceInfo_Destroy(ktxVulkanDeviceInfo* This); 138 | KTX_API KTX_error_code KTX_APIENTRY 139 | ktxTexture_VkUploadEx(ktxTexture* This, ktxVulkanDeviceInfo* vdi, 140 | ktxVulkanTexture* vkTexture, 141 | VkImageTiling tiling, 142 | VkImageUsageFlags usageFlags, 143 | VkImageLayout finalLayout); 144 | KTX_API KTX_error_code KTX_APIENTRY 145 | ktxTexture_VkUpload(ktxTexture* texture, ktxVulkanDeviceInfo* vdi, 146 | ktxVulkanTexture *vkTexture); 147 | KTX_API KTX_error_code KTX_APIENTRY 148 | ktxTexture1_VkUploadEx(ktxTexture1* This, ktxVulkanDeviceInfo* vdi, 149 | ktxVulkanTexture* vkTexture, 150 | VkImageTiling tiling, 151 | VkImageUsageFlags usageFlags, 152 | VkImageLayout finalLayout); 153 | KTX_API KTX_error_code KTX_APIENTRY 154 | ktxTexture1_VkUpload(ktxTexture1* texture, ktxVulkanDeviceInfo* vdi, 155 | ktxVulkanTexture *vkTexture); 156 | KTX_API KTX_error_code KTX_APIENTRY 157 | ktxTexture2_VkUploadEx(ktxTexture2* This, ktxVulkanDeviceInfo* vdi, 158 | ktxVulkanTexture* vkTexture, 159 | VkImageTiling tiling, 160 | VkImageUsageFlags usageFlags, 161 | VkImageLayout finalLayout); 162 | KTX_API KTX_error_code KTX_APIENTRY 163 | ktxTexture2_VkUpload(ktxTexture2* texture, ktxVulkanDeviceInfo* vdi, 164 | ktxVulkanTexture *vkTexture); 165 | 166 | KTX_API VkFormat KTX_APIENTRY 167 | ktxTexture_GetVkFormat(ktxTexture* This); 168 | 169 | KTX_API VkFormat KTX_APIENTRY 170 | ktxTexture1_GetVkFormat(ktxTexture1* This); 171 | 172 | KTX_API VkFormat KTX_APIENTRY 173 | ktxTexture2_GetVkFormat(ktxTexture2* This); 174 | 175 | #ifdef __cplusplus 176 | } 177 | #endif 178 | 179 | #endif /* KTX_H_A55A6F00956F42F3A137C11929827FE1 */ 180 | -------------------------------------------------------------------------------- /src/ktx/libktx/memstream.h: -------------------------------------------------------------------------------- 1 | /* -*- tab-width: 4; -*- */ 2 | /* vi: set sw=2 ts=4 expandtab: */ 3 | 4 | /* 5 | * Copyright 2010-2020 The Khronos Group Inc. 6 | * SPDX-License-Identifier: Apache-2.0 7 | */ 8 | 9 | /** 10 | * @internal 11 | * @file 12 | * @~English 13 | * 14 | * @brief Interface of ktxStream for memory. 15 | * 16 | * @author Maksim Kolesin 17 | * @author Georg Kolling, Imagination Technology 18 | * @author Mark Callow, HI Corporation 19 | */ 20 | 21 | #ifndef MEMSTREAM_H 22 | #define MEMSTREAM_H 23 | 24 | #include "ktx.h" 25 | 26 | /* 27 | * Initialize a ktxStream to a ktxMemStream with internally 28 | * allocated memory. Can be read or written. 29 | */ 30 | KTX_error_code ktxMemStream_construct(ktxStream* str, 31 | ktx_bool_t freeOnDestruct); 32 | /* 33 | * Initialize a ktxStream to a read-only ktxMemStream reading 34 | * from an array of bytes. 35 | */ 36 | KTX_error_code ktxMemStream_construct_ro(ktxStream* str, 37 | const ktx_uint8_t* pBytes, 38 | const ktx_size_t size); 39 | void ktxMemStream_destruct(ktxStream* str); 40 | 41 | KTX_error_code ktxMemStream_getdata(ktxStream* str, ktx_uint8_t** ppBytes); 42 | 43 | #endif /* MEMSTREAM_H */ 44 | -------------------------------------------------------------------------------- /src/ktx/libktx/strings.c: -------------------------------------------------------------------------------- 1 | /* -*- tab-width: 4; -*- */ 2 | /* vi: set sw=2 ts=4 expandtab: */ 3 | 4 | /* 5 | * Copyright 2010-2020 The Khronos Group Inc. 6 | * SPDX-License-Identifier: Apache-2.0 7 | */ 8 | 9 | /** 10 | * @file strings.c 11 | * @~English 12 | * 13 | * @brief Functions to return a string corresponding to various enumerations. 14 | * 15 | * @author Mark Callow, HI Corporation 16 | */ 17 | 18 | #include "ktx.h" 19 | 20 | static const char* const errorStrings[] = { 21 | "Operation succeeded.", /* KTX_SUCCESS */ 22 | "File data is inconsistent with KTX spec.", /* KTX_FILE_DATA_ERROR */ 23 | "File is a pipe; seek operations not possible.", /* KTX_FILE_ISPIPE */ 24 | "File open failed.", /* KTX_FILE_OPEN_FAILED */ 25 | "Operation would exceed the max file size.", /* KTX_FILE_OVERFLOW */ 26 | "File read error.", /* KTX_FILE_READ_ERROR */ 27 | "File seek error.", /* KTX_FILE_SEEK_ERROR */ 28 | "File does not have enough data for request.", /* KTX_FILE_UNEXPECTED_EOF */ 29 | "File write error.", /* KTX_FILE_WRITE_ERROR */ 30 | "GL error occurred.", /* KTX_GL_ERROR */ 31 | "Operation not allowed in the current state.", /* KTX_INVALID_OPERATION */ 32 | "Invalid parameter value.", /* KTX_INVALID_VALUE */ 33 | "Key not found.", /* KTX_NOT_FOUND */ 34 | "Out of memory.", /* KTX_OUT_OF_MEMORY */ 35 | "Transcoding of block compressed texture failed.",/* KTX_TRANSCODE_FAILED */ 36 | "Not a KTX file.", /* KTX_UNKNOWN_FILE_FORMAT */ 37 | "Texture type not supported.", /* KTX_UNSUPPORTED_TEXTURE_TYPE */ 38 | "Feature not included in in-use library or not yet implemented.", /* KTX_UNSUPPORTED_FEATURE */ 39 | "Library dependency (OpenGL or Vulkan) not linked into application." /* KTX_LIBRARY_NOT_LINKED */ 40 | }; 41 | /* This will cause compilation to fail if number of messages and codes doesn't match */ 42 | typedef int errorStrings_SIZE_ASSERT[sizeof(errorStrings) / sizeof(char*) - 1 == KTX_ERROR_MAX_ENUM]; 43 | 44 | /** 45 | * @~English 46 | * @brief Return a string corresponding to a KTX error code. 47 | * 48 | * @param error the error code for which to return a string 49 | * 50 | * @return pointer to the message string. 51 | * 52 | * @internal Use UTF-8 for translated message strings. 53 | * 54 | * @author Mark Callow 55 | */ 56 | const char* ktxErrorString(KTX_error_code error) 57 | { 58 | if (error > KTX_ERROR_MAX_ENUM) 59 | return "Unrecognized error code"; 60 | return errorStrings[error]; 61 | } 62 | 63 | /** 64 | * @~English 65 | * @brief Return a string corresponding to a transcode format enumeration. 66 | * 67 | * @param format the transcode format for which to return a string. 68 | * 69 | * @return pointer to the message string. 70 | * 71 | * @internal Use UTF-8 for translated message strings. 72 | * 73 | * @author Mark Callow 74 | */ 75 | const char* ktxTranscodeFormatString(ktx_transcode_fmt_e format) 76 | { 77 | switch (format) { 78 | case KTX_TTF_ETC1_RGB: return "ETC1_RGB"; 79 | case KTX_TTF_ETC2_RGBA: return "ETC2_RGBA"; 80 | case KTX_TTF_BC1_RGB: return "BC1_RGB"; 81 | case KTX_TTF_BC3_RGBA: return "BC3_RGBA"; 82 | case KTX_TTF_BC4_R: return "BC4_R"; 83 | case KTX_TTF_BC5_RG: return "BC5_RG"; 84 | case KTX_TTF_BC7_RGBA: return "BC7_RGBA"; 85 | case KTX_TTF_PVRTC1_4_RGB: return "PVRTC1_4_RGB"; 86 | case KTX_TTF_PVRTC1_4_RGBA: return "PVRTC1_4_RGBA"; 87 | case KTX_TTF_ASTC_4x4_RGBA: return "ASTC_4x4_RGBA"; 88 | case KTX_TTF_RGBA32: return "RGBA32"; 89 | case KTX_TTF_RGB565: return "RGB565"; 90 | case KTX_TTF_BGR565: return "BGR565"; 91 | case KTX_TTF_RGBA4444: return "RGBA4444"; 92 | case KTX_TTF_PVRTC2_4_RGB: return "PVRTC2_4_RGB"; 93 | case KTX_TTF_PVRTC2_4_RGBA: return "PVRTC2_4_RGBA"; 94 | case KTX_TTF_ETC2_EAC_R11: return "ETC2_EAC_R11"; 95 | case KTX_TTF_ETC2_EAC_RG11: return "ETC2_EAC_RG11"; 96 | case KTX_TTF_ETC: return "ETC"; 97 | case KTX_TTF_BC1_OR_3: return "BC1 or BC3"; 98 | default: return "Unrecognized format"; 99 | } 100 | } 101 | 102 | /** 103 | * @~English 104 | * @brief Return a string corresponding to a supercompressionScheme enumeration. 105 | * 106 | * @param scheme the supercompression scheme for which to return a string. 107 | * 108 | * @return pointer to the message string. 109 | * 110 | * @internal Use UTF-8 for translated message strings. 111 | * 112 | * @author Mark Callow 113 | */ 114 | const char * 115 | ktxSupercompressionSchemeString(ktxSupercmpScheme scheme) 116 | { 117 | switch (scheme) { 118 | case KTX_SS_NONE: return "KTX_SS_NONE"; 119 | case KTX_SS_BASIS_LZ: return "KTX_SS_BASIS_LZ"; 120 | case KTX_SS_ZSTD: return "KTX_SS_ZSTD"; 121 | default: 122 | if (scheme < KTX_SS_BEGIN_VENDOR_RANGE 123 | || scheme >= KTX_SS_BEGIN_RESERVED) 124 | return "Invalid scheme value"; 125 | else 126 | return "Vendor scheme"; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/ktx/libktx/swap.c: -------------------------------------------------------------------------------- 1 | /* -*- tab-width: 4; -*- */ 2 | /* vi: set sw=2 ts=4 expandtab: */ 3 | 4 | /* $Id: 02ea6de2d8db512ca3af08f48b98ab5f6c35e7e5 $ */ 5 | 6 | /* 7 | * Copyright 2010-2020 The Khronos Group Inc. 8 | * SPDX-License-Identifier: Apache-2.0 9 | */ 10 | 11 | #include 12 | #include "ktx.h" 13 | 14 | /* 15 | * SwapEndian16: Swaps endianness in an array of 16-bit values 16 | */ 17 | void 18 | _ktxSwapEndian16(khronos_uint16_t* pData16, ktx_size_t count) 19 | { 20 | for (ktx_size_t i = 0; i < count; ++i) 21 | { 22 | khronos_uint16_t x = *pData16; 23 | *pData16++ = (x << 8) | (x >> 8); 24 | } 25 | } 26 | 27 | /* 28 | * SwapEndian32: Swaps endianness in an array of 32-bit values 29 | */ 30 | void 31 | _ktxSwapEndian32(khronos_uint32_t* pData32, ktx_size_t count) 32 | { 33 | for (ktx_size_t i = 0; i < count; ++i) 34 | { 35 | khronos_uint32_t x = *pData32; 36 | *pData32++ = (x << 24) | ((x & 0xFF00) << 8) | ((x & 0xFF0000) >> 8) | (x >> 24); 37 | } 38 | } 39 | 40 | /* 41 | * SwapEndian364: Swaps endianness in an array of 32-bit values 42 | */ 43 | void 44 | _ktxSwapEndian64(khronos_uint64_t* pData64, ktx_size_t count) 45 | { 46 | for (ktx_size_t i = 0; i < count; ++i) 47 | { 48 | khronos_uint64_t x = *pData64; 49 | *pData64++ = (x << 56) | ((x & 0xFF00) << 40) | ((x & 0xFF0000) << 24) 50 | | ((x & 0xFF000000) << 8 ) | ((x & 0xFF00000000) >> 8) 51 | | ((x & 0xFF0000000000) >> 24) 52 | | ((x & 0xFF000000000000) << 40) | (x >> 56); 53 | } 54 | } 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /src/ktx/libktx/texture.h: -------------------------------------------------------------------------------- 1 | /* -*- tab-width: 4; -*- */ 2 | /* vi: set sw=2 ts=4 expandtab textwidth=70: */ 3 | 4 | /* 5 | * Copyright 2019-2020 The Khronos Group Inc. 6 | * SPDX-License-Identifier: Apache-2.0 7 | */ 8 | 9 | /** 10 | * @internal 11 | * @file texture.h 12 | * @~English 13 | * 14 | * @brief Declare internal ktxTexture functions for sharing between 15 | * compilation units. 16 | * 17 | * These functions are private and should not be used outside the library. 18 | */ 19 | 20 | #ifndef _TEXTURE_H_ 21 | #define _TEXTURE_H_ 22 | 23 | #include "ktx.h" 24 | #include "formatsize.h" 25 | 26 | #define DECLARE_PRIVATE(class) class ## _private* private = This->_private 27 | #define DECLARE_PROTECTED(class) class ## _protected* prtctd = This->_protected; 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | typedef enum { 34 | KTX_FORMAT_VERSION_ONE = 1, 35 | KTX_FORMAT_VERSION_TWO = 2 36 | } ktxFormatVersionEnum; 37 | 38 | typedef ktx_size_t (* PFNCALCDATASIZELEVELS)(ktxTexture* This, 39 | ktx_uint32_t levels); 40 | typedef ktx_size_t (* PFNCALCFACELODSIZE)(ktxTexture* This, ktx_uint32_t level); 41 | typedef ktx_size_t (* PFNCALCLEVELOFFSET)(ktxTexture* This, ktx_uint32_t level); 42 | typedef struct ktxTexture_vtblInt { 43 | PFNCALCDATASIZELEVELS calcDataSizeLevels; 44 | PFNCALCFACELODSIZE calcFaceLodSize; 45 | PFNCALCLEVELOFFSET calcLevelOffset; 46 | } ktxTexture_vtblInt; 47 | 48 | #define ktxTexture_calcDataSizeLevels(This, levels) \ 49 | This->_protected->_vtbl.calcDataSizeLevels(This, levels); 50 | #define ktxTexture_calcFaceLodSize(This, level) \ 51 | This->_protected->_vtbl.calcFaceLodSize(This, level); 52 | #define ktxTexture_calcLevelOffset(This, level) \ 53 | This->_protected->_vtbl.calcLevelOffset(This, level); 54 | 55 | /** 56 | * @memberof ktxTexture 57 | * @~English 58 | * 59 | * @brief protected members of ktxTexture. 60 | */ 61 | typedef struct ktxTexture_protected { 62 | ktxTexture_vtblInt _vtbl; 63 | ktxFormatSize _formatSize; 64 | ktx_uint32_t _typeSize; 65 | ktxStream _stream; 66 | } ktxTexture_protected; 67 | 68 | #define ktxTexture_getStream(t) ((ktxStream*)(&(t)->_protected->_stream)) 69 | #define ktxTexture1_getStream(t1) ktxTexture_getStream((ktxTexture*)t1) 70 | #define ktxTexture2_getStream(t2) ktxTexture_getStream((ktxTexture*)t2) 71 | 72 | KTX_error_code 73 | ktxTexture_iterateLoadedImages(ktxTexture* This, PFNKTXITERCB iterCb, 74 | void* userdata); 75 | KTX_error_code 76 | ktxTexture_iterateSourceImages(ktxTexture* This, PFNKTXITERCB iterCb, 77 | void* userdata); 78 | 79 | ktx_size_t ktxTexture_calcDataSizeTexture(ktxTexture* This); 80 | ktx_size_t ktxTexture_calcImageSize(ktxTexture* This, ktx_uint32_t level, 81 | ktxFormatVersionEnum fv); 82 | ktx_bool_t ktxTexture_isActiveStream(ktxTexture* This); 83 | ktx_size_t ktxTexture_calcLevelSize(ktxTexture* This, ktx_uint32_t level, 84 | ktxFormatVersionEnum fv); 85 | ktx_size_t ktxTexture_doCalcFaceLodSize(ktxTexture* This, ktx_uint32_t level, 86 | ktxFormatVersionEnum fv); 87 | ktx_size_t ktxTexture_layerSize(ktxTexture* This, ktx_uint32_t level, 88 | ktxFormatVersionEnum fv); 89 | void ktxTexture_rowInfo(ktxTexture* This, ktx_uint32_t level, 90 | ktx_uint32_t* numRows, ktx_uint32_t* rowBytes, 91 | ktx_uint32_t* rowPadding); 92 | KTX_error_code 93 | ktxTexture_construct(ktxTexture* This, ktxTextureCreateInfo* createInfo, 94 | ktxFormatSize* formatSize); 95 | 96 | KTX_error_code 97 | ktxTexture_constructFromStream(ktxTexture* This, ktxStream* pStream, 98 | ktxTextureCreateFlags createFlags); 99 | 100 | void 101 | ktxTexture_destruct(ktxTexture* This); 102 | 103 | #ifdef __cplusplus 104 | } 105 | #endif 106 | 107 | #endif /* _TEXTURE_H_ */ 108 | -------------------------------------------------------------------------------- /src/ktx/libktx/texture1.h: -------------------------------------------------------------------------------- 1 | /* -*- tab-width: 4; -*- */ 2 | /* vi: set sw=2 ts=4 expandtab textwidth=70: */ 3 | 4 | /* 5 | * Copyright 2019-2020 The Khronos Group Inc. 6 | * SPDX-License-Identifier: Apache-2.0 7 | */ 8 | 9 | /** 10 | * @internal 11 | * @file texture1.h 12 | * @~English 13 | * 14 | * @brief Declare internal ktxTexture1 functions for sharing between 15 | * compilation units. 16 | * 17 | * These functions are private and should not be used outside the library. 18 | */ 19 | 20 | #ifndef _TEXTURE1_H_ 21 | #define _TEXTURE1_H_ 22 | 23 | #include "texture.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | #define CLASS ktxTexture1 30 | #include "texture_funcs.inl" 31 | #undef CLASS 32 | 33 | KTX_error_code 34 | ktxTexture1_constructFromStreamAndHeader(ktxTexture1* This, ktxStream* pStream, 35 | KTX_header* pHeader, 36 | ktxTextureCreateFlags createFlags); 37 | 38 | ktx_uint64_t ktxTexture1_calcDataSizeTexture(ktxTexture1* This); 39 | ktx_size_t ktxTexture1_calcLevelOffset(ktxTexture1* This, ktx_uint32_t level); 40 | ktx_uint32_t ktxTexture1_glTypeSize(ktxTexture1* This); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif /* _TEXTURE1_H_ */ 47 | -------------------------------------------------------------------------------- /src/ktx/libktx/texture2.h: -------------------------------------------------------------------------------- 1 | /* -*- tab-width: 4; -*- */ 2 | /* vi: set sw=2 ts=4 expandtab textwidth=70: */ 3 | 4 | /* 5 | * Copyright 2019-2020 The Khronos Group Inc. 6 | * SPDX-License-Identifier: Apache-2.0 7 | */ 8 | 9 | /** 10 | * @internal 11 | * @file texture2.h 12 | * @~English 13 | * 14 | * @brief Declare internal ktxTexture2 functions for sharing between 15 | * compilation units. 16 | * 17 | * These functions are private and should not be used outside the library. 18 | */ 19 | 20 | #ifndef _TEXTURE2_H_ 21 | #define _TEXTURE2_H_ 22 | 23 | #include "texture.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | #define CLASS ktxTexture2 30 | #include "texture_funcs.inl" 31 | #undef CLASS 32 | 33 | typedef struct ktxTexture2_private { 34 | ktx_uint8_t* _supercompressionGlobalData; 35 | ktx_uint32_t _requiredLevelAlignment; 36 | ktx_uint64_t _sgdByteLength; 37 | ktx_uint64_t _firstLevelFileOffset; /*!< Always 0, unless the texture was 38 | created from a stream and the image 39 | data is not yet loaded. */ 40 | // Must be last so it can grow. 41 | ktxLevelIndexEntry _levelIndex[1]; /*!< Offsets in this index are from the 42 | start of the image data. Use 43 | ktxTexture_levelStreamOffset() and 44 | ktxTexture_levelDataOffset(). The former 45 | will add the above file offset to the 46 | index offset. */ 47 | } ktxTexture2_private; 48 | 49 | KTX_error_code 50 | ktxTexture2_LoadImageData(ktxTexture2* This, 51 | ktx_uint8_t* pBuffer, ktx_size_t bufSize); 52 | 53 | KTX_error_code 54 | ktxTexture2_constructFromStreamAndHeader(ktxTexture2* This, ktxStream* pStream, 55 | KTX_header2* pHeader, 56 | ktxTextureCreateFlags createFlags); 57 | 58 | ktx_uint64_t ktxTexture2_calcDataSizeTexture(ktxTexture2* This); 59 | ktx_size_t ktxTexture2_calcLevelOffset(ktxTexture2* This, ktx_uint32_t level); 60 | ktx_uint32_t ktxTexture2_calcRequiredLevelAlignment(ktxTexture2* This); 61 | ktx_uint64_t ktxTexture2_levelFileOffset(ktxTexture2* This, ktx_uint32_t level); 62 | ktx_uint64_t ktxTexture2_levelDataOffset(ktxTexture2* This, ktx_uint32_t level); 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | #endif /* _TEXTURE2_H_ */ 69 | -------------------------------------------------------------------------------- /src/ktx/libktx/texture_funcs.inl: -------------------------------------------------------------------------------- 1 | /* -*- tab-width: 4; -*- */ 2 | /* vi: set sw=2 ts=4 expandtab textwidth=70: */ 3 | 4 | /* 5 | * Copyright 2019-2020 The Khronos Group Inc. 6 | * SPDX-License-Identifier: Apache-2.0 7 | */ 8 | 9 | /** 10 | * @internal 11 | * @file texture_funcs.h 12 | * @~English 13 | * 14 | * @brief Templates for functions common to base & derived ktxTexture classes. 15 | * 16 | * Define CLASS before including this file. 17 | */ 18 | 19 | #define CAT(c, n) PRIMITIVE_CAT(c, n) 20 | #define PRIMITIVE_CAT(c, n) c ## _ ## n 21 | 22 | #define CLASS_FUNC(name) CAT(CLASS, name) 23 | 24 | /* 25 | ====================================== 26 | Virtual ktxTexture functions 27 | ====================================== 28 | */ 29 | 30 | 31 | void CLASS_FUNC(Destroy)(CLASS* This); 32 | KTX_error_code CLASS_FUNC(GetImageOffset)(CLASS* This, ktx_uint32_t level, 33 | ktx_uint32_t layer, 34 | ktx_uint32_t faceSlice, 35 | ktx_size_t* pOffset); 36 | ktx_size_t CLASS_FUNC(GetImageSize)(CLASS* This, ktx_uint32_t level); 37 | KTX_error_code CLASS_FUNC(GLUpload)(CLASS* This, GLuint* pTexture, 38 | GLenum* pTarget, GLenum* pGlerror); 39 | KTX_error_code CLASS_FUNC(IterateLevels)(CLASS* This, 40 | PFNKTXITERCB iterCb, 41 | void* userdata); 42 | KTX_error_code CLASS_FUNC(IterateLevelFaces)(CLASS* This, 43 | PFNKTXITERCB iterCb, 44 | void* userdata); 45 | KTX_error_code CLASS_FUNC(IterateLoadLevelFaces)(CLASS* This, 46 | PFNKTXITERCB iterCb, 47 | void* userdata); 48 | KTX_error_code CLASS_FUNC(LoadImageData)(CLASS* This, 49 | ktx_uint8_t* pBuffer, 50 | ktx_size_t bufSize); 51 | KTX_error_code CLASS_FUNC(SetImageFromStdioStream)(CLASS* This, 52 | ktx_uint32_t level,ktx_uint32_t layer, 53 | ktx_uint32_t faceSlice, 54 | FILE* src, ktx_size_t srcSize); 55 | KTX_error_code CLASS_FUNC(SetImageFromMemory)(CLASS* This, 56 | ktx_uint32_t level, ktx_uint32_t layer, 57 | ktx_uint32_t faceSlice, 58 | const ktx_uint8_t* src, ktx_size_t srcSize); 59 | 60 | KTX_error_code CLASS_FUNC(WriteToStdioStream)(CLASS* This, FILE* dstsstr); 61 | KTX_error_code CLASS_FUNC(WriteToNamedFile)(CLASS* This, 62 | const char* const dstname); 63 | KTX_error_code CLASS_FUNC(WriteToMemory)(CLASS* This, 64 | ktx_uint8_t** ppDstBytes, ktx_size_t* pSize); 65 | KTX_error_code CLASS_FUNC(WriteToStream)(CLASS* This, 66 | ktxStream* dststr); 67 | 68 | /* 69 | ====================================== 70 | Internal ktxTexture functions 71 | ====================================== 72 | */ 73 | 74 | 75 | void CLASS_FUNC(destruct)(CLASS* This); 76 | 77 | -------------------------------------------------------------------------------- /src/ktx/libktx/unused.h: -------------------------------------------------------------------------------- 1 | /* -*- tab-width: 4; -*- */ 2 | /* vi: set sw=2 ts=4 expandtab: */ 3 | 4 | /* Copyright 2019-2018 The Khronos Group Inc. 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | /* I'm extending this beyond the purpose implied by its name rather than creating 9 | * a new file to hold the FALLTHROUGH declaration as this 10 | * file is already included in most places FALLTHROUGH 11 | * is needed. 12 | */ 13 | 14 | #ifndef _UNUSED_H 15 | #define _UNUSED_H 16 | 17 | #if (__cplusplus == 201703L) 18 | #define MAYBE_UNUSED [[maybe_unused]] 19 | #elif __GNUC__ || __clang__ 20 | #define MAYBE_UNUSED __attribute__((unused)) 21 | #else 22 | // Boohoo. VC++ has no equivalent 23 | #define MAYBE_UNUSED 24 | #endif 25 | 26 | #define U_ASSERT_ONLY MAYBE_UNUSED 27 | 28 | // For unused parameters of c functions. Portable. 29 | #define UNUSED(x) (void)(x) 30 | 31 | #if !__clang__ && __GNUC__ // grumble ... clang ... grumble 32 | #define FALLTHROUGH __attribute__((fallthrough)) 33 | #else 34 | #define FALLTHROUGH 35 | #endif 36 | 37 | #endif /* UNUSED_H */ 38 | -------------------------------------------------------------------------------- /src/ktx/libktx/vk_funclist.inl: -------------------------------------------------------------------------------- 1 | /* -*- tab-width: 4; -*- */ 2 | /* vi: set sw=2 ts=4 expandtab textwidth=70: */ 3 | 4 | /* 5 | * Copyright 2017-2020 Mark Callow. 6 | * SPDX-License-Identifier: Apache-2.0 7 | */ 8 | 9 | /** 10 | * @internal 11 | * @file vk_funclist.h 12 | * @~English 13 | * 14 | * @brief List of Vulkan functions used by libktx. 15 | */ 16 | 17 | VK_FUNCTION(vkAllocateCommandBuffers) 18 | VK_FUNCTION(vkAllocateMemory) 19 | VK_FUNCTION(vkBeginCommandBuffer) 20 | VK_FUNCTION(vkBindBufferMemory) 21 | VK_FUNCTION(vkBindImageMemory) 22 | VK_FUNCTION(vkCmdBlitImage) 23 | VK_FUNCTION(vkCmdCopyBufferToImage) 24 | VK_FUNCTION(vkCmdPipelineBarrier) 25 | VK_FUNCTION(vkCreateBuffer) 26 | VK_FUNCTION(vkCreateFence) 27 | VK_FUNCTION(vkCreateImage) 28 | VK_FUNCTION(vkDestroyBuffer) 29 | VK_FUNCTION(vkDestroyFence) 30 | VK_FUNCTION(vkDestroyImage) 31 | VK_FUNCTION(vkEndCommandBuffer) 32 | VK_FUNCTION(vkFreeCommandBuffers) 33 | VK_FUNCTION(vkFreeMemory) 34 | VK_FUNCTION(vkGetBufferMemoryRequirements) 35 | VK_FUNCTION(vkGetImageMemoryRequirements) 36 | VK_FUNCTION(vkGetImageSubresourceLayout) 37 | VK_FUNCTION(vkGetPhysicalDeviceImageFormatProperties) 38 | VK_FUNCTION(vkGetPhysicalDeviceFormatProperties) 39 | VK_FUNCTION(vkGetPhysicalDeviceMemoryProperties) 40 | VK_FUNCTION(vkMapMemory) 41 | VK_FUNCTION(vkQueueSubmit) 42 | VK_FUNCTION(vkQueueWaitIdle) 43 | VK_FUNCTION(vkUnmapMemory) 44 | VK_FUNCTION(vkWaitForFences) 45 | -------------------------------------------------------------------------------- /src/ktx/libktx/vk_funcs.c: -------------------------------------------------------------------------------- 1 | /* -*- tab-width: 4; -*- */ 2 | /* vi: set sw=2 ts=4 expandtab textwidth=70: */ 3 | 4 | /* 5 | * Copyright 2017-2020 Mark Callow. 6 | * SPDX-License-Identifier: Apache-2.0 7 | */ 8 | 9 | /** 10 | * @internal 11 | * @file vk_funcs.c 12 | * @~English 13 | * 14 | * @brief Retrieve Vulkan function pointers needed by libktx 15 | */ 16 | 17 | #define UNIX 0 18 | #define MACOS 0 19 | #define WINDOWS 0 20 | #define IOS 0 21 | 22 | #if defined(_WIN32) 23 | #undef WINDOWS 24 | #define WINDOWS 1 25 | #endif 26 | #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__) 27 | #undef UNIX 28 | #define UNIX 1 29 | #endif 30 | #if defined(linux) || defined(__linux) || defined(__linux__) 31 | #undef UNIX 32 | #define UNIX 1 33 | #endif 34 | #if defined(__APPLE__) && defined(__x86_64__) 35 | #undef MACOS 36 | #define MACOS 1 37 | #endif 38 | #if defined(__APPLE__) && (defined(__arm64__) || defined (__arm__)) 39 | #undef IOS 40 | #define IOS 1 41 | #endif 42 | #if (IOS + MACOS + UNIX + WINDOWS) > 1 43 | #error "Multiple OS\'s defined" 44 | #endif 45 | 46 | #include "vk_funcs.h" 47 | 48 | #if defined(KTX_USE_FUNCPTRS_FOR_VULKAN) 49 | 50 | #if WINDOWS 51 | #define WINDOWS_LEAN_AND_MEAN 52 | #include 53 | #else 54 | #include 55 | #include 56 | #endif 57 | #include "ktx.h" 58 | 59 | #if WINDOWS 60 | HMODULE ktxVulkanModuleHandle; 61 | #define GetVulkanModuleHandle(flags) ktxGetVulkanModuleHandle() 62 | #define LoadProcAddr GetProcAddress 63 | #elif MACOS || UNIX || IOS 64 | // Using NULL returns a handle that can be used to search the process that 65 | // loaded us and any other libraries it has loaded. That's all we need to 66 | // search as the app is responsible for creating the GL context so it must 67 | // be there. 68 | #define GetVulkanModuleHandle(flags) dlopen(NULL, flags) 69 | #define LoadProcAddr dlsym 70 | void* ktxVulkanModuleHandle; 71 | #else 72 | #error "Don\'t know how to load symbols on this OS." 73 | #endif 74 | 75 | #if 0 76 | static PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr; 77 | #endif 78 | 79 | /* Define pointers for functions libktx is using. */ 80 | #define VK_FUNCTION(fun) PFN_##fun ktx_##fun; 81 | 82 | #include "vk_funclist.inl" 83 | 84 | #undef VK_FUNCTION 85 | 86 | #if 0 87 | // The Vulkan spec. recommends using vkGetInstanceProcAddr over dlsym 88 | // (or whatever). Doing so would require a backward incompatible 89 | // change to the libktx API to provide the VkInstance. We have no 90 | // choice but dlsym. We can't use vkGetDeviceProcAddr because libktx 91 | // also uses none-device-level functions. 92 | #define VK_FUNCTION(fun) \ 93 | if ( !(ktx_##fun = (PFN_##fun)vkGetInstanceProcAddr(instance, #fun )) ) { \ 94 | fprintf(stderr, "Could not load Vulkan command: %s!\n", #fun); \ 95 | return KTX_FALSE; \ 96 | } 97 | #else 98 | #if defined(__GNUC__) 99 | // This strange casting is because dlsym returns a void* thus is not 100 | // compatible with ISO C which forbids conversion of object pointers 101 | // to function pointers. The cast masks the conversion from the 102 | // compiler thus no warning even though -pedantic is set. Since the 103 | // platform supports dlsym, conversion to function pointers must 104 | // work, despite the mandated ISO C warning. 105 | #define VK_FUNCTION(fun) \ 106 | if (!(*(void **)(&ktx_##fun) = LoadProcAddr(ktxVulkanModuleHandle, #fun))) { \ 107 | fprintf(stderr, "Could not load Vulkan command: %s!\n", #fun); \ 108 | return KTX_FALSE; \ 109 | } 110 | #else 111 | #define VK_FUNCTION(fun) \ 112 | if ((ktx_##fun=(PFN_##fun)LoadProcAddr(ktxVulkanModuleHandle, #fun)) == 0) { \ 113 | fprintf(stderr, "Could not load Vulkan command: %s!\n", #fun); \ 114 | return KTX_FALSE; \ 115 | } 116 | #endif 117 | #endif 118 | 119 | #if WINDOWS 120 | #define VULKANLIB "vulkan-1.dll" 121 | static HMODULE 122 | ktxGetVulkanModuleHandle() 123 | { 124 | HMODULE module = NULL; 125 | BOOL found; 126 | found = GetModuleHandleExA( 127 | 0, 128 | VULKANLIB, 129 | &module 130 | ); 131 | return module; 132 | } 133 | #endif 134 | 135 | ktx_error_code_e 136 | ktxLoadVulkanLibrary(void) 137 | { 138 | if (ktxVulkanModuleHandle) 139 | return KTX_SUCCESS; 140 | 141 | ktxVulkanModuleHandle = GetVulkanModuleHandle(RTLD_LAZY); 142 | if (ktxVulkanModuleHandle == NULL) { 143 | fprintf(stderr, "Vulkan lib not linked or loaded by application.\n"); 144 | // Normal use is for this constructor to be called by an 145 | // application that has completed OpenGL initialization. In that 146 | // case the only cause for failure would be a coding error in our 147 | // library loading. The only other cause would be an application 148 | // calling GLUpload without having initialized OpenGL. 149 | #if defined(DEBUG) 150 | abort(); 151 | #else 152 | return KTX_LIBRARY_NOT_LINKED; // So release version doesn't crash. 153 | #endif 154 | } 155 | 156 | #if 0 157 | vkGetInstanceProcAddr = 158 | (PFN_vkGetInstanceProcAddr)LoadProcAddr(ktxVulkanLibrary, 159 | "vkGetInstanceProcAddr"); 160 | if (!vkGetInstanceProcAddr) { 161 | fprintf(stderr, "Could not load Vulkan command: %s!\n", 162 | "vkGetInstanceProcAddr"); 163 | return(KTX_FALSE); 164 | } 165 | #endif 166 | 167 | #include "vk_funclist.inl" 168 | 169 | return KTX_SUCCESS; 170 | } 171 | 172 | #undef VK_FUNCTION 173 | 174 | #else 175 | 176 | extern 177 | #if defined(__GNUC__) 178 | __attribute__((unused)) 179 | #endif 180 | int keepISOCompilersHappy; 181 | 182 | #endif /* !KTX_OMIT_VULKAN && KTX_USE_FUNCPTRS_FOR_VULKAN */ 183 | -------------------------------------------------------------------------------- /src/ktx/libktx/vk_funcs.h: -------------------------------------------------------------------------------- 1 | /* -*- tab-width: 4; -*- */ 2 | /* vi: set sw=2 ts=4 expandtab textwidth=70: */ 3 | 4 | /* 5 | * Copyright 2017-2020 Mark Callow. 6 | * SPDX-License-Identifier: Apache-2.0 7 | */ 8 | 9 | /** 10 | * @internal 11 | * @file vk_funcs.h 12 | * @~English 13 | * 14 | * @brief Declare pointers for Vulkan functions. 15 | * 16 | * Dynamically retrieving pointers avoids apps having to make sure a 17 | * Vulkan library is available when using a shared libktx, even if 18 | * not using libktx's Vulkan loader. 19 | */ 20 | 21 | #ifndef _VK_FUNCS_H_ 22 | #define _VK_FUNCS_H_ 23 | 24 | #if !defined(KTX_USE_FUNCPTRS_FOR_VULKAN) 25 | #define KTX_USE_FUNCPTRS_FOR_VULKAN 1 26 | #endif 27 | 28 | #if defined(KTX_USE_FUNCPTRS_FOR_VULKAN) 29 | #define VK_NO_PROTOTYPES 30 | #endif 31 | 32 | #include "vulkan/vk_platform.h" 33 | #include "vulkan/vulkan_core.h" 34 | #include "ktx.h" 35 | 36 | #if defined(KTX_USE_FUNCPTRS_FOR_VULKAN) 37 | 38 | #if WINDOWS 39 | #define WINDOWS_LEAN_AND_MEAN 40 | #include 41 | extern HMODULE ktxVulkanModuleHandle; 42 | #else 43 | extern void* ktxVulkanModuleHandle; 44 | #endif 45 | 46 | extern ktx_error_code_e ktxLoadVulkanLibrary(void); 47 | 48 | /* Declare pointers for functions libktx is using. */ 49 | #define VK_FUNCTION(fun) extern PFN_##fun ktx_##fun; 50 | 51 | #include "vk_funclist.inl" 52 | 53 | #undef VK_FUNCTION 54 | 55 | /* 56 | * Define prefixed names to prevent collisions with other libraries or apps 57 | * finding our pointers when searching the module for function addresses. 58 | */ 59 | #define vkAllocateCommandBuffers ktx_vkAllocateCommandBuffers 60 | #define vkAllocateMemory ktx_vkAllocateMemory 61 | #define vkBeginCommandBuffer ktx_vkBeginCommandBuffer 62 | #define vkBindBufferMemory ktx_vkBindBufferMemory 63 | #define vkBindImageMemory ktx_vkBindImageMemory 64 | #define vkCmdBlitImage ktx_vkCmdBlitImage 65 | #define vkCmdCopyBufferToImage ktx_vkCmdCopyBufferToImage 66 | #define vkCmdPipelineBarrier ktx_vkCmdPipelineBarrier 67 | #define vkCreateBuffer ktx_vkCreateBuffer 68 | #define vkCreateFence ktx_vkCreateFence 69 | #define vkCreateImage ktx_vkCreateImage 70 | #define vkDestroyBuffer ktx_vkDestroyBuffer 71 | #define vkDestroyFence ktx_vkDestroyFence 72 | #define vkDestroyImage ktx_vkDestroyImage 73 | #define vkEndCommandBuffer ktx_vkEndCommandBuffer 74 | #define vkFreeCommandBuffers ktx_vkFreeCommandBuffers 75 | #define vkFreeMemory ktx_vkFreeMemory 76 | #define vkGetBufferMemoryRequirements ktx_vkGetBufferMemoryRequirements 77 | #define vkGetImageMemoryRequirements ktx_vkGetImageMemoryRequirements 78 | #define vkGetImageSubresourceLayout ktx_vkGetImageSubresourceLayout 79 | #define vkGetPhysicalDeviceImageFormatProperties ktx_vkGetPhysicalDeviceImageFormatProperties 80 | #define vkGetPhysicalDeviceFormatProperties ktx_vkGetPhysicalDeviceFormatProperties 81 | #define vkGetPhysicalDeviceMemoryProperties ktx_vkGetPhysicalDeviceMemoryProperties 82 | #define vkMapMemory ktx_vkMapMemory 83 | #define vkQueueSubmit ktx_vkQueueSubmit 84 | #define vkQueueWaitIdle ktx_vkQueueWaitIdle 85 | #define vkUnmapMemory ktx_vkUnmapMemory 86 | #define vkWaitForFences ktx_vkWaitForFences 87 | 88 | #undef VK_FUNCTION 89 | 90 | #endif /* KTX_USE_FUNCPTRS_FOR_VULKAN */ 91 | 92 | #endif /* _VK_FUNCS_H_ */ 93 | 94 | -------------------------------------------------------------------------------- /src/ktx/libktx/vkformat_check.c: -------------------------------------------------------------------------------- 1 | 2 | /***************************** Do not edit. ***************************** 3 | Automatically generated from vulkan_core.h version 151 by mkvkformatfiles. 4 | *************************************************************************/ 5 | 6 | /* 7 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 8 | ** 9 | ** SPDX-License-Identifier: Apache-2.0 10 | */ 11 | 12 | #include 13 | #include 14 | 15 | #include "vkformat_enum.h" 16 | 17 | bool 18 | isProhibitedFormat(VkFormat format) 19 | { 20 | switch (format) { 21 | case VK_FORMAT_R8_USCALED: 22 | case VK_FORMAT_R8_SSCALED: 23 | case VK_FORMAT_R8G8_USCALED: 24 | case VK_FORMAT_R8G8_SSCALED: 25 | case VK_FORMAT_R8G8B8_USCALED: 26 | case VK_FORMAT_R8G8B8_SSCALED: 27 | case VK_FORMAT_B8G8R8_USCALED: 28 | case VK_FORMAT_B8G8R8_SSCALED: 29 | case VK_FORMAT_R8G8B8A8_USCALED: 30 | case VK_FORMAT_R8G8B8A8_SSCALED: 31 | case VK_FORMAT_B8G8R8A8_USCALED: 32 | case VK_FORMAT_B8G8R8A8_SSCALED: 33 | case VK_FORMAT_A8B8G8R8_UNORM_PACK32: 34 | case VK_FORMAT_A8B8G8R8_SNORM_PACK32: 35 | case VK_FORMAT_A8B8G8R8_USCALED_PACK32: 36 | case VK_FORMAT_A8B8G8R8_SSCALED_PACK32: 37 | case VK_FORMAT_A8B8G8R8_UINT_PACK32: 38 | case VK_FORMAT_A8B8G8R8_SINT_PACK32: 39 | case VK_FORMAT_A8B8G8R8_SRGB_PACK32: 40 | case VK_FORMAT_A2R10G10B10_USCALED_PACK32: 41 | case VK_FORMAT_A2R10G10B10_SSCALED_PACK32: 42 | case VK_FORMAT_A2B10G10R10_USCALED_PACK32: 43 | case VK_FORMAT_A2B10G10R10_SSCALED_PACK32: 44 | case VK_FORMAT_R16_USCALED: 45 | case VK_FORMAT_R16_SSCALED: 46 | case VK_FORMAT_R16G16_USCALED: 47 | case VK_FORMAT_R16G16_SSCALED: 48 | case VK_FORMAT_R16G16B16_USCALED: 49 | case VK_FORMAT_R16G16B16_SSCALED: 50 | case VK_FORMAT_R16G16B16A16_USCALED: 51 | case VK_FORMAT_R16G16B16A16_SSCALED: 52 | case VK_FORMAT_G8B8G8R8_422_UNORM: 53 | case VK_FORMAT_B8G8R8G8_422_UNORM: 54 | case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM: 55 | case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM: 56 | case VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM: 57 | case VK_FORMAT_G8_B8R8_2PLANE_422_UNORM: 58 | case VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM: 59 | case VK_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16: 60 | case VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16: 61 | case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16: 62 | case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16: 63 | case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16: 64 | case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16: 65 | case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16: 66 | case VK_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16: 67 | case VK_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16: 68 | case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16: 69 | case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16: 70 | case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16: 71 | case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16: 72 | case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16: 73 | case VK_FORMAT_G16B16G16R16_422_UNORM: 74 | case VK_FORMAT_B16G16R16G16_422_UNORM: 75 | case VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM: 76 | case VK_FORMAT_G16_B16R16_2PLANE_420_UNORM: 77 | case VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM: 78 | case VK_FORMAT_G16_B16R16_2PLANE_422_UNORM: 79 | case VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM: 80 | return true; 81 | default: 82 | return false; 83 | } 84 | } 85 | 86 | bool 87 | isValidFormat(VkFormat format) 88 | { 89 | if (format <= VK_FORMAT_MAX_STANDARD_ENUM) 90 | return true; 91 | else switch(format) { 92 | case VK_FORMAT_R10X6_UNORM_PACK16: 93 | case VK_FORMAT_R10X6G10X6_UNORM_2PACK16: 94 | case VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16: 95 | case VK_FORMAT_R12X4_UNORM_PACK16: 96 | case VK_FORMAT_R12X4G12X4_UNORM_2PACK16: 97 | case VK_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16: 98 | case VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG: 99 | case VK_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG: 100 | case VK_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG: 101 | case VK_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG: 102 | case VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG: 103 | case VK_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG: 104 | case VK_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG: 105 | case VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG: 106 | case VK_FORMAT_ASTC_4x4_SFLOAT_BLOCK_EXT: 107 | case VK_FORMAT_ASTC_5x4_SFLOAT_BLOCK_EXT: 108 | case VK_FORMAT_ASTC_5x5_SFLOAT_BLOCK_EXT: 109 | case VK_FORMAT_ASTC_6x5_SFLOAT_BLOCK_EXT: 110 | case VK_FORMAT_ASTC_6x6_SFLOAT_BLOCK_EXT: 111 | case VK_FORMAT_ASTC_8x5_SFLOAT_BLOCK_EXT: 112 | case VK_FORMAT_ASTC_8x6_SFLOAT_BLOCK_EXT: 113 | case VK_FORMAT_ASTC_8x8_SFLOAT_BLOCK_EXT: 114 | case VK_FORMAT_ASTC_10x5_SFLOAT_BLOCK_EXT: 115 | case VK_FORMAT_ASTC_10x6_SFLOAT_BLOCK_EXT: 116 | case VK_FORMAT_ASTC_10x8_SFLOAT_BLOCK_EXT: 117 | case VK_FORMAT_ASTC_10x10_SFLOAT_BLOCK_EXT: 118 | case VK_FORMAT_ASTC_12x10_SFLOAT_BLOCK_EXT: 119 | case VK_FORMAT_ASTC_12x12_SFLOAT_BLOCK_EXT: 120 | case VK_FORMAT_ASTC_3x3x3_UNORM_BLOCK_EXT: 121 | case VK_FORMAT_ASTC_3x3x3_SRGB_BLOCK_EXT: 122 | case VK_FORMAT_ASTC_3x3x3_SFLOAT_BLOCK_EXT: 123 | case VK_FORMAT_ASTC_4x3x3_UNORM_BLOCK_EXT: 124 | case VK_FORMAT_ASTC_4x3x3_SRGB_BLOCK_EXT: 125 | case VK_FORMAT_ASTC_4x3x3_SFLOAT_BLOCK_EXT: 126 | case VK_FORMAT_ASTC_4x4x3_UNORM_BLOCK_EXT: 127 | case VK_FORMAT_ASTC_4x4x3_SRGB_BLOCK_EXT: 128 | case VK_FORMAT_ASTC_4x4x3_SFLOAT_BLOCK_EXT: 129 | case VK_FORMAT_ASTC_4x4x4_UNORM_BLOCK_EXT: 130 | case VK_FORMAT_ASTC_4x4x4_SRGB_BLOCK_EXT: 131 | case VK_FORMAT_ASTC_4x4x4_SFLOAT_BLOCK_EXT: 132 | case VK_FORMAT_ASTC_5x4x4_UNORM_BLOCK_EXT: 133 | case VK_FORMAT_ASTC_5x4x4_SRGB_BLOCK_EXT: 134 | case VK_FORMAT_ASTC_5x4x4_SFLOAT_BLOCK_EXT: 135 | case VK_FORMAT_ASTC_5x5x4_UNORM_BLOCK_EXT: 136 | case VK_FORMAT_ASTC_5x5x4_SRGB_BLOCK_EXT: 137 | case VK_FORMAT_ASTC_5x5x4_SFLOAT_BLOCK_EXT: 138 | case VK_FORMAT_ASTC_5x5x5_UNORM_BLOCK_EXT: 139 | case VK_FORMAT_ASTC_5x5x5_SRGB_BLOCK_EXT: 140 | case VK_FORMAT_ASTC_5x5x5_SFLOAT_BLOCK_EXT: 141 | case VK_FORMAT_ASTC_6x5x5_UNORM_BLOCK_EXT: 142 | case VK_FORMAT_ASTC_6x5x5_SRGB_BLOCK_EXT: 143 | case VK_FORMAT_ASTC_6x5x5_SFLOAT_BLOCK_EXT: 144 | case VK_FORMAT_ASTC_6x6x5_UNORM_BLOCK_EXT: 145 | case VK_FORMAT_ASTC_6x6x5_SRGB_BLOCK_EXT: 146 | case VK_FORMAT_ASTC_6x6x5_SFLOAT_BLOCK_EXT: 147 | case VK_FORMAT_ASTC_6x6x6_UNORM_BLOCK_EXT: 148 | case VK_FORMAT_ASTC_6x6x6_SRGB_BLOCK_EXT: 149 | case VK_FORMAT_ASTC_6x6x6_SFLOAT_BLOCK_EXT: 150 | case VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT: 151 | case VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT: 152 | return true; 153 | default: 154 | return false; 155 | } 156 | } 157 | 158 | -------------------------------------------------------------------------------- /src/models/models.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright(c) 2021 Robert Osfield 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | using namespace vsgXchange; 17 | 18 | models::models() 19 | { 20 | add(gltf::create()); 21 | 22 | #ifdef vsgXchange_assimp 23 | add(assimp::create()); 24 | #endif 25 | 26 | #ifdef vsgXchange_OSG 27 | add(OSG::create()); 28 | #endif 29 | } 30 | -------------------------------------------------------------------------------- /src/openexr/build_vars.cmake: -------------------------------------------------------------------------------- 1 | # add openexr if available 2 | find_package(OpenEXR QUIET) 3 | 4 | if(OpenEXR_FOUND) 5 | OPTION(vsgXchange_openexr "Optional OpenEXR support provided" ON) 6 | endif() 7 | 8 | if (${vsgXchange_openexr}) 9 | set(SOURCES ${SOURCES} 10 | openexr/openexr.cpp 11 | ) 12 | if(OpenEXR_VERSION VERSION_LESS "3.0") 13 | set(EXTRA_LIBRARIES ${EXTRA_LIBRARIES} OpenEXR::IlmImf) 14 | else() 15 | add_compile_definitions(EXRVERSION3) 16 | set(EXTRA_LIBRARIES ${EXTRA_LIBRARIES} OpenEXR::OpenEXR) 17 | endif() 18 | set(EXTRA_INCLUDES ${EXTRA_INCLUDES} ${OpenEXR_INCLUDE_DIRS}) 19 | 20 | if(NOT BUILD_SHARED_LIBS) 21 | set(FIND_DEPENDENCY ${FIND_DEPENDENCY} "find_dependency(OpenEXR)") 22 | endif() 23 | else() 24 | set(SOURCES ${SOURCES} 25 | openexr/openexr_fallback.cpp 26 | ) 27 | endif() 28 | -------------------------------------------------------------------------------- /src/openexr/openexr_fallback.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace vsgXchange; 4 | 5 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 6 | // 7 | // openEXR ReaderWriter fallback 8 | // 9 | openexr::openexr() 10 | { 11 | } 12 | 13 | vsg::ref_ptr openexr::read(const vsg::Path&, vsg::ref_ptr) const 14 | { 15 | return {}; 16 | } 17 | 18 | vsg::ref_ptr openexr::read(std::istream&, vsg::ref_ptr) const 19 | { 20 | return {}; 21 | } 22 | 23 | vsg::ref_ptr openexr::read(const uint8_t*, size_t, vsg::ref_ptr) const 24 | { 25 | return {}; 26 | } 27 | 28 | bool openexr::write(const vsg::Object*, const vsg::Path&, vsg::ref_ptr) const 29 | { 30 | return false; 31 | } 32 | 33 | bool openexr::write(const vsg::Object*, std::ostream&, vsg::ref_ptr) const 34 | { 35 | return false; 36 | } 37 | 38 | bool openexr::getFeatures(Features&) const 39 | { 40 | return false; 41 | } 42 | -------------------------------------------------------------------------------- /src/vsgXchangeConfig.cmake.in: -------------------------------------------------------------------------------- 1 | include(CMakeFindDependencyMacro) 2 | 3 | @FIND_DEPENDENCY_OUT@ 4 | 5 | include("${CMAKE_CURRENT_LIST_DIR}/vsgXchangeTargets.cmake") 6 | --------------------------------------------------------------------------------