├── .clang-format ├── .gitignore ├── .gitmodules ├── .travis.yml ├── CMakeLists.txt ├── CPPLINT.cfg ├── README.md ├── cmake └── TestWrapValgrind.cmake ├── cpp ├── examples │ ├── deck.gl │ │ ├── CMakeLists.txt │ │ ├── flight-paths.cc │ │ ├── manhattan-population.cc │ │ ├── stdinout.cc │ │ ├── texture-render.cc │ │ └── vancouver-blocks.cc │ └── luma.gl │ │ ├── CMakeLists.txt │ │ └── animometer.cc ├── modules │ ├── deck.gl │ │ ├── CMakeLists.txt │ │ ├── core.h │ │ ├── core │ │ │ ├── src │ │ │ │ ├── arrow │ │ │ │ │ ├── arrow-mapper.cc │ │ │ │ │ ├── arrow-mapper.h │ │ │ │ │ ├── doc │ │ │ │ │ │ └── README.md │ │ │ │ │ ├── row.cc │ │ │ │ │ └── row.h │ │ │ │ ├── core.cc │ │ │ │ ├── core.h │ │ │ │ ├── lib │ │ │ │ │ ├── attribute │ │ │ │ │ │ ├── attribute-manager.cc │ │ │ │ │ │ └── attribute-manager.h │ │ │ │ │ ├── component.cc │ │ │ │ │ ├── component.h │ │ │ │ │ ├── constants.cc │ │ │ │ │ ├── constants.h │ │ │ │ │ ├── deck.cc │ │ │ │ │ ├── deck.h │ │ │ │ │ ├── earcut.hpp │ │ │ │ │ ├── layer-context.h │ │ │ │ │ ├── layer-manager.cc │ │ │ │ │ ├── layer-manager.h │ │ │ │ │ ├── layer-state.h │ │ │ │ │ ├── layer.cc │ │ │ │ │ ├── layer.h │ │ │ │ │ ├── view-manager.cc │ │ │ │ │ └── view-manager.h │ │ │ │ ├── shaderlib │ │ │ │ │ ├── lighting │ │ │ │ │ │ ├── lighting.glsl.h │ │ │ │ │ │ └── phong-lighting.glsl.h │ │ │ │ │ ├── misc │ │ │ │ │ │ └── geometry.glsl.h │ │ │ │ │ └── project │ │ │ │ │ │ ├── project.glsl.h │ │ │ │ │ │ ├── project32.glsl.h │ │ │ │ │ │ ├── viewport-uniforms.cc │ │ │ │ │ │ └── viewport-uniforms.h │ │ │ │ ├── viewports │ │ │ │ │ ├── viewport.cc │ │ │ │ │ ├── viewport.h │ │ │ │ │ ├── web-mercator-viewport.cc │ │ │ │ │ └── web-mercator-viewport.h │ │ │ │ └── views │ │ │ │ │ ├── map-view.cc │ │ │ │ │ ├── map-view.h │ │ │ │ │ ├── view-state.cc │ │ │ │ │ ├── view-state.h │ │ │ │ │ ├── view.cc │ │ │ │ │ └── view.h │ │ │ └── test │ │ │ │ ├── arrow │ │ │ │ └── row-test.cc │ │ │ │ ├── lib │ │ │ │ ├── attribute │ │ │ │ │ └── attribute-manager-test.cc │ │ │ │ ├── earcut-test.cc │ │ │ │ ├── layer-manager-test.cc │ │ │ │ ├── layer-test.cc │ │ │ │ └── view-manager-test.cc │ │ │ │ ├── shaderlib │ │ │ │ └── project │ │ │ │ │ └── viewport-uniforms-test.cc │ │ │ │ ├── viewports │ │ │ │ ├── viewport-test.cc │ │ │ │ └── web-mercator-viewport-test.cc │ │ │ │ └── views │ │ │ │ ├── map-view-json-data.h │ │ │ │ ├── map-view-test.cc │ │ │ │ ├── view-json-data.h │ │ │ │ ├── view-state-test.cc │ │ │ │ └── view-test.cc │ │ ├── json.h │ │ ├── json │ │ │ ├── src │ │ │ │ ├── converter │ │ │ │ │ ├── json-converter.cc │ │ │ │ │ ├── json-converter.h │ │ │ │ │ ├── json-types-mathgl.h │ │ │ │ │ ├── json-types.cc │ │ │ │ │ └── json-types.h │ │ │ │ ├── json-object │ │ │ │ │ ├── json-object.cc │ │ │ │ │ └── json-object.h │ │ │ │ └── json.h │ │ │ └── test │ │ │ │ ├── json-converter-test.cc │ │ │ │ ├── json-data.h │ │ │ │ ├── json-object-test.cc │ │ │ │ └── json-types-test.cc │ │ ├── layers.h │ │ └── layers │ │ │ ├── README.md │ │ │ ├── src │ │ │ ├── layers.cc │ │ │ ├── layers.h │ │ │ ├── line-layer │ │ │ │ ├── line-layer-fragment.glsl.h │ │ │ │ ├── line-layer-vertex.glsl.h │ │ │ │ ├── line-layer.cc │ │ │ │ └── line-layer.h │ │ │ ├── scatterplot-layer │ │ │ │ ├── scatterplot-layer-fragment.glsl.h │ │ │ │ ├── scatterplot-layer-vertex.glsl.h │ │ │ │ ├── scatterplot-layer.cc │ │ │ │ └── scatterplot-layer.h │ │ │ └── solid-polygon-layer │ │ │ │ ├── solid-polygon-layer-fragment.glsl.h │ │ │ │ ├── solid-polygon-layer-vertex-main.glsl.h │ │ │ │ ├── solid-polygon-layer-vertex-side.glsl.h │ │ │ │ ├── solid-polygon-layer-vertex-top.glsl.h │ │ │ │ ├── solid-polygon-layer.cc │ │ │ │ └── solid-polygon-layer.h │ │ │ └── test │ │ │ ├── line-layer-test.cc │ │ │ ├── scatterplot-layer-test.cc │ │ │ └── solid-polygon-layer-test.cc │ ├── loaders.gl │ │ ├── CMakeLists.txt │ │ ├── csv.h │ │ ├── csv │ │ │ ├── src │ │ │ │ ├── csv-loader.cc │ │ │ │ └── csv-loader.h │ │ │ └── test │ │ │ │ ├── csv-data.h │ │ │ │ └── csv-loader-test.cc │ │ ├── json.h │ │ └── json │ │ │ ├── src │ │ │ ├── json-loader.cc │ │ │ └── json-loader.h │ │ │ └── test │ │ │ ├── json-loader-data.h │ │ │ └── json-loader-test.cc │ ├── luma.gl │ │ ├── CMakeLists.txt │ │ ├── core.h │ │ ├── core │ │ │ ├── src │ │ │ │ ├── animation-loop │ │ │ │ │ ├── animation-loop-factory.cc │ │ │ │ │ ├── animation-loop-factory.h │ │ │ │ │ ├── animation-loop.cc │ │ │ │ │ ├── animation-loop.h │ │ │ │ │ ├── glfw-animation-loop.cc │ │ │ │ │ ├── glfw-animation-loop.h │ │ │ │ │ ├── metal-animation-loop.h │ │ │ │ │ └── metal-animation-loop.mm │ │ │ │ ├── blit-model.cc │ │ │ │ ├── blit-model.h │ │ │ │ ├── model.cc │ │ │ │ ├── model.h │ │ │ │ ├── size.cc │ │ │ │ └── size.h │ │ │ └── test │ │ │ │ ├── animation-loop-test.cc │ │ │ │ └── model-test.cc │ │ ├── garrow.h │ │ ├── garrow │ │ │ ├── docs │ │ │ │ ├── arrow-mapping.md │ │ │ │ └── gpu-table-guide.md │ │ │ ├── src │ │ │ │ ├── array.cc │ │ │ │ ├── array.h │ │ │ │ ├── field.cc │ │ │ │ ├── field.h │ │ │ │ ├── key-value-metadata.cc │ │ │ │ ├── key-value-metadata.h │ │ │ │ ├── schema.cc │ │ │ │ ├── schema.h │ │ │ │ ├── table.cc │ │ │ │ ├── table.h │ │ │ │ └── util │ │ │ │ │ ├── arrow-utils.cc │ │ │ │ │ ├── arrow-utils.h │ │ │ │ │ ├── webgpu-utils.cc │ │ │ │ │ └── webgpu-utils.h │ │ │ └── test │ │ │ │ └── util │ │ │ │ └── arrow-utils-test.cc │ │ ├── webgpu.h │ │ └── webgpu │ │ │ ├── src │ │ │ ├── backends │ │ │ │ ├── glfw │ │ │ │ │ ├── backend-binding.cc │ │ │ │ │ ├── backend-binding.h │ │ │ │ │ ├── d3d12-binding.cc │ │ │ │ │ ├── metal-binding.mm │ │ │ │ │ ├── null-binding.cc │ │ │ │ │ ├── opengl-binding.cc │ │ │ │ │ └── vulkan-binding.cc │ │ │ │ ├── metal-binding.h │ │ │ │ └── metal-binding.mm │ │ │ ├── combo-render-pipeline-descriptor.cc │ │ │ ├── combo-render-pipeline-descriptor.h │ │ │ ├── shaderc-utils.cc │ │ │ ├── shaderc-utils.h │ │ │ ├── swap-chain-utils.h │ │ │ ├── webgpu-constants.h │ │ │ ├── webgpu-helpers.cc │ │ │ ├── webgpu-helpers.h │ │ │ ├── webgpu-utils.cc │ │ │ └── webgpu-utils.h │ │ │ └── test │ │ │ └── webgpu-test.cc │ ├── math.gl │ │ ├── CMakeLists.txt │ │ ├── core.h │ │ ├── core │ │ │ ├── src │ │ │ │ ├── core.h │ │ │ │ └── rectangle.h │ │ │ └── test │ │ │ │ └── core-test.cc │ │ ├── web-mercator.h │ │ └── web-mercator │ │ │ ├── src │ │ │ ├── web-mercator-utils.cc │ │ │ └── web-mercator-utils.h │ │ │ └── test │ │ │ ├── sample-viewports.h │ │ │ └── web-mercator-utils-test.cc │ └── probe.gl │ │ ├── CMakeLists.txt │ │ ├── core.h │ │ └── core │ │ ├── src │ │ ├── assert.cc │ │ ├── assert.h │ │ ├── compiler.h │ │ ├── error.cc │ │ ├── error.h │ │ ├── log.cc │ │ ├── log.h │ │ ├── platform.h │ │ ├── system-utils.cc │ │ ├── system-utils.h │ │ ├── timer.cc │ │ └── timer.h │ │ └── test │ │ └── timer-test.cc └── tests │ └── main.cc ├── deck.gl-native.xcodeproj ├── project.pbxproj └── xcshareddata │ └── xcschemes │ ├── animometer.xcscheme │ ├── deck.gl-native-tests.xcscheme │ ├── deck.gl-native.xcscheme │ ├── make.xcscheme │ ├── manhattan-population.xcscheme │ └── texture-render.xcscheme ├── docs └── dev │ ├── coding-style.md │ └── visual-studio-code.md └── scripts ├── bootstrap.sh ├── build-clang.sh ├── build-cpplint.sh ├── build-gcc.sh ├── build-ios.sh └── coverage.sh.in /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io/api/c++,xcode,macos,visualstudiocode 2 | # Edit at https://www.gitignore.io/?templates=c++,xcode,macos,visualstudiocode 3 | 4 | ### C++ ### 5 | # Prerequisites 6 | *.d 7 | 8 | # Compiled Object files 9 | *.slo 10 | *.lo 11 | *.o 12 | *.obj 13 | 14 | # Precompiled Headers 15 | *.gch 16 | *.pch 17 | 18 | # Compiled Dynamic libraries 19 | *.so 20 | *.dylib 21 | *.dll 22 | 23 | # Fortran module files 24 | *.mod 25 | *.smod 26 | 27 | # Compiled Static libraries 28 | *.lai 29 | *.la 30 | *.a 31 | *.lib 32 | 33 | # Executables 34 | *.exe 35 | *.out 36 | *.app 37 | 38 | ### macOS ### 39 | # General 40 | .DS_Store 41 | .AppleDouble 42 | .LSOverride 43 | 44 | # Icon must end with two \r 45 | Icon 46 | 47 | # Thumbnails 48 | ._* 49 | 50 | # Files that might appear in the root of a volume 51 | .DocumentRevisions-V100 52 | .fseventsd 53 | .Spotlight-V100 54 | .TemporaryItems 55 | .Trashes 56 | .VolumeIcon.icns 57 | .com.apple.timemachine.donotpresent 58 | 59 | # Directories potentially created on remote AFP share 60 | .AppleDB 61 | .AppleDesktop 62 | Network Trash Folder 63 | Temporary Items 64 | .apdisk 65 | 66 | ### VisualStudioCode ### 67 | .vscode/* 68 | !.vscode/settings.json 69 | !.vscode/tasks.json 70 | !.vscode/launch.json 71 | !.vscode/extensions.json 72 | 73 | ### VisualStudioCode Patch ### 74 | # Ignore all local history of files 75 | .history 76 | 77 | ### Xcode ### 78 | # Xcode 79 | # 80 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 81 | 82 | ## User settings 83 | xcuserdata/ 84 | 85 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 86 | *.xcscmblueprint 87 | *.xccheckout 88 | 89 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 90 | build/ 91 | DerivedData/ 92 | *.moved-aside 93 | *.pbxuser 94 | !default.pbxuser 95 | *.mode1v3 96 | !default.mode1v3 97 | *.mode2v3 98 | !default.mode2v3 99 | *.perspectivev3 100 | !default.perspectivev3 101 | 102 | ## Xcode Patch 103 | *.xcodeproj/* 104 | !*.xcodeproj/project.pbxproj 105 | !*.xcodeproj/xcshareddata/ 106 | !*.xcworkspace/contents.xcworkspacedata 107 | /*.gcno 108 | 109 | ### Xcode Patch ### 110 | **/xcshareddata/WorkspaceSettings.xcsettings 111 | 112 | # End of https://www.gitignore.io/api/c++,xcode,macos,visualstudiocode 113 | 114 | ## Ignore Xcode project settings completely 115 | #*.xcodeproj 116 | #*.xcworkspace 117 | 118 | .vscode 119 | 120 | /build*/ 121 | /install*/ 122 | Testing 123 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "cpp/deps"] 2 | path = cpp/deps 3 | url = https://github.com/UnfoldedInc/deck.gl-native-dependencies.git 4 | [submodule "data"] 5 | path = data 6 | url = https://github.com/UnfoldedInc/deck.gl-data.git 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Inspired by https://github.com/uber/h3/blob/master/.travis.yml 2 | # and https://github.com/google/s2geometry/blob/master/.travis.yml 3 | 4 | language: c 5 | 6 | os: linux 7 | dist: bionic 8 | 9 | matrix: 10 | include: 11 | # Check that clang-format doesn't detect some files are not formatted. 12 | - name: "Formatting check" 13 | compiler: clang 14 | addons: 15 | apt: 16 | sources: 17 | - sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main' 18 | key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' 19 | packages: 20 | - clang-format-9 21 | script: make format && git diff --exit-code 22 | - name: "macOS (Xcode 11.3)" 23 | os: osx 24 | osx_image: xcode11.3 25 | # TODO: Does not build on Linux currently due to dependency issues 26 | # - name: "Linux (Clang)" 27 | # os: linux 28 | # compiler: clang 29 | - name: "Linux (GCC 9) with Valgrind" 30 | os: linux 31 | compiler: gcc 32 | addons: 33 | apt: 34 | sources: 35 | - ubuntu-toolchain-r-test 36 | packages: 37 | - valgrind 38 | - libglu1-mesa-dev 39 | - g++-9 40 | before_script: 41 | - mkdir build 42 | - cd build 43 | - cmake -DWARNINGS_AS_ERRORS=OFF -DDECK_ENABLE_GRAPHICS=OFF -DDECK_ENABLE_FORMAT=OFF -DCMAKE_C_COMPILER=gcc-9 -DCMAKE_CXX_COMPILER=g++-9 .. 44 | script: 45 | - make -j 46 | - valgrind --error-exitcode=99 ./deckgl-bundle-tests 47 | 48 | before_script: 49 | # Build out of source 50 | - mkdir build 51 | - cd build 52 | - cmake -DWARNINGS_AS_ERRORS=ON -DDECK_ENABLE_GRAPHICS=OFF .. 53 | 54 | script: 55 | - make -j 16 56 | - CTEST_OUTPUT_ON_FAILURE=1 make test 57 | -------------------------------------------------------------------------------- /CPPLINT.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Unfolded, Inc. 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to deal 5 | # in the Software without restriction, including without limitation the rights 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | # copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | # THE SOFTWARE. 20 | 21 | # Coding style and rule exceptions are documented at 22 | # https://github.com/UnfoldedInc/deck.gl-native/tree/master/docs/dev/coding-style.md 23 | 24 | # Stop searching for additional config files. 25 | set noparent 26 | 27 | linelength=120 28 | 29 | # To disable a rule: 30 | filter=-build/header_guard,-build/namespaces,-runtime/references 31 | 32 | # To enable a rule: 33 | #filter=+[RULE] 34 | 35 | # For a list of rules run cpplint --filter= 36 | -------------------------------------------------------------------------------- /cmake/TestWrapValgrind.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Unfolded, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Support code for wrapping tests or other executables with Valgrind. 16 | 17 | if(__test_wrap_valgrind) 18 | return() 19 | endif() 20 | set(__test_wrap_valgrind 1) 21 | 22 | include(CMakeDependentOption) 23 | 24 | find_program(VALGRIND valgrind) 25 | cmake_dependent_option(WRAP_VALGRIND "Wrap tests in valgrind" OFF 26 | "VALGRIND" OFF) 27 | if(WRAP_VALGRIND) 28 | # TEST_WRAPPER could be used to configure the Valgrind parameters, or 29 | # to use a different wrapper entirely. 30 | set(TEST_WRAPPER ${VALGRIND} --track-origins=yes --leak-check=full --error-exitcode=99 CACHE STRING 31 | "Wrapper executable for tests and benchmarks") 32 | mark_as_advanced(TEST_WRAPPER) 33 | # Convert from semicolon separated list of values to a form 34 | # that can be used by a shell. 35 | string(REPLACE ";" " " TEST_WRAPPER_STR "${TEST_WRAPPER}") 36 | endif() 37 | 38 | -------------------------------------------------------------------------------- /cpp/examples/deck.gl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Unfolded Inc. 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to deal 5 | # in the Software without restriction, including without limitation the rights 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | # copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | # THE SOFTWARE. 20 | 21 | set(EXAMPLE_SOURCE_FILES 22 | stdinout.cc 23 | flight-paths.cc 24 | manhattan-population.cc 25 | texture-render.cc 26 | vancouver-blocks.cc 27 | ) 28 | set(EXAMPLE_DATA_FILES 29 | ${DECK_DATA_PATH}/examples/flight-paths/heathrow-flights.ndjson 30 | ${DECK_DATA_PATH}/examples/flight-paths/airports.ndjson 31 | ${DECK_DATA_PATH}/examples/manhattan-population/manhattan.ndjson 32 | ${DECK_DATA_PATH}/examples/vancouver-blocks/vancouver-blocks-simplified.ndjson 33 | ) 34 | 35 | # Create an executable for each example from the list 36 | foreach(EXAMPLE_SOURCE_FILE ${EXAMPLE_SOURCE_FILES}) 37 | get_filename_component(TARGET_NAME ${EXAMPLE_SOURCE_FILE} NAME_WE) 38 | add_executable(${TARGET_NAME} ${EXAMPLE_SOURCE_FILE}) 39 | 40 | target_link_libraries(${TARGET_NAME} PRIVATE ${DECK_LINK_FLAGS} deck.gl loaders.gl) 41 | 42 | # Installation 43 | install(TARGETS ${TARGET_NAME} 44 | RUNTIME 45 | DESTINATION examples/deck.gl 46 | COMPONENT Examples 47 | BUNDLE 48 | DESTINATION examples/deck.gl 49 | COMPONENT Examples 50 | ) 51 | endforeach() 52 | 53 | # Copy supporting data files 54 | foreach(EXAMPLE_DATA_FILE ${EXAMPLE_DATA_FILES}) 55 | get_filename_component(EXAMPLE_DATA_FILE_NAME ${EXAMPLE_DATA_FILE} NAME) 56 | configure_file(${EXAMPLE_DATA_FILE} ${CMAKE_CURRENT_BINARY_DIR}/data/${EXAMPLE_DATA_FILE_NAME} COPYONLY) 57 | endforeach() 58 | 59 | # Add example files to global DECK_EXAMPLE_FILES property 60 | # NOTE: We transform relative paths to absolute paths before appending 61 | set(FILES_TO_ADD ${EXAMPLE_SOURCE_FILES}) 62 | list(TRANSFORM FILES_TO_ADD PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/) 63 | set_property(GLOBAL APPEND PROPERTY DECK_EXAMPLE_FILES ${FILES_TO_ADD}) 64 | -------------------------------------------------------------------------------- /cpp/examples/deck.gl/stdinout.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include 22 | 23 | #include "deck.gl/core.h" 24 | #include "deck.gl/json.h" 25 | #include "deck.gl/layers.h" 26 | 27 | using namespace std; 28 | using namespace deckgl; 29 | 30 | // Simple application that reads deck.gl configurations from standard in 31 | // (one configuration per line) and applies them to the deck.gl state. 32 | int main(int argc, char** argv) { 33 | auto jsonConverter = unique_ptr(new JSONConverter()); 34 | registerJSONConvertersForDeckCore(jsonConverter.get()); 35 | registerJSONConvertersForDeckLayers(jsonConverter.get()); 36 | 37 | auto deck = make_unique(); 38 | 39 | while (true) { 40 | cout << "> "; 41 | string jsonStr; 42 | getline(cin, jsonStr); 43 | 44 | if (cin.eof()) { 45 | return 0; 46 | } 47 | 48 | auto newProps = jsonConverter->convertJson(jsonStr, "Deck"); 49 | auto deckProps = dynamic_pointer_cast(newProps); 50 | 51 | deck->setProps(deckProps); 52 | 53 | cout << deck->viewManager->getNeedsRedraw(true).value_or("no redraw needed") << endl; 54 | } 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /cpp/examples/luma.gl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Unfolded Inc. 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to deal 5 | # in the Software without restriction, including without limitation the rights 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | # copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | # THE SOFTWARE. 20 | 21 | set(EXAMPLE_SOURCE_FILES 22 | animometer.cc 23 | ) 24 | 25 | # Create an executable for each example from the list 26 | foreach(EXAMPLE_SOURCE_FILE ${EXAMPLE_SOURCE_FILES}) 27 | get_filename_component(TARGET_NAME ${EXAMPLE_SOURCE_FILE} NAME_WE) 28 | add_executable(${TARGET_NAME} ${EXAMPLE_SOURCE_FILE}) 29 | 30 | target_link_libraries(${TARGET_NAME} PUBLIC ${DECK_LINK_FLAGS} luma.gl probe.gl math.gl) 31 | 32 | # Installation 33 | install(TARGETS ${TARGET_NAME} 34 | RUNTIME 35 | DESTINATION examples/luma.gl 36 | COMPONENT Examples 37 | BUNDLE 38 | DESTINATION examples/luma.gl 39 | COMPONENT Examples 40 | ) 41 | endforeach() 42 | 43 | # Add example files to global DECK_EXAMPLE_FILES property 44 | # NOTE: We transform relative paths to absolute paths before appending 45 | set(FILES_TO_ADD ${EXAMPLE_SOURCE_FILES}) 46 | list(TRANSFORM FILES_TO_ADD PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/) 47 | set_property(GLOBAL APPEND PROPERTY DECK_EXAMPLE_FILES ${FILES_TO_ADD}) 48 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef DECKGL_CORE_H 22 | #define DECKGL_CORE_H 23 | 24 | #include "./core/src/core.h" 25 | 26 | #endif // DECKGL_CORE_H 27 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core/src/arrow/doc/README.md: -------------------------------------------------------------------------------- 1 | ## Arrow Utilities 2 | 3 | ### Row 4 | 5 | Provides an easy way to extract typed row data out of a table column. Below are the available accessors, together with Arrow types that they map from. 6 | 7 | | C++ | Arrow | Notes | 8 | |--------------------- |---------------------------------------------- |---------------------------------------------------- | 9 | | getInt | DOUBLE, FLOAT, INT64, INT32 | | 10 | | getFloat | DOUBLE, FLOAT, INT64, INT32 | | 11 | | getDouble | DOUBLE, FLOAT, INT64, INT32 | | 12 | | getBool | BOOL, DOUBLE, FLOAT, INT64, INT32 | | 13 | | getString | String | | 14 | | getFloatVector2 | FIXED_SIZE_LIST, LIST | Must contain only 2 elements of type float | 15 | | getDoubleVector2 | FIXED_SIZE_LIST, LIST | Must contain only 2 elements of type double | 16 | | getFloatVector3 | FIXED_SIZE_LIST, LIST | Must contain only 3 elements of type float | 17 | | getDoubleVector3 | FIXED_SIZE_LIST, LIST | Must contain only 3 elements of type double | 18 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core/src/core.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Unfolded Inc 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "./core.h" // NOLINT(build/include) 22 | 23 | using namespace deckgl; 24 | 25 | void deckgl::registerJSONConvertersForDeckCore(JSONConverter *jsonConverter) { 26 | jsonConverter->classes["Deck"] = [](const Json::Value &) { return std::make_shared(); }; 27 | 28 | jsonConverter->classes["ViewState"] = [](const Json::Value &) { return std::make_shared(); }; 29 | 30 | jsonConverter->classes["View"] = [](const Json::Value &) { return std::make_shared(); }; 31 | 32 | jsonConverter->classes["MapView"] = [](const Json::Value &) { return std::make_shared(); }; 33 | } 34 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core/src/core.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef DECKGL_CORE_CORE_H 22 | #define DECKGL_CORE_CORE_H 23 | 24 | #include "./arrow/arrow-mapper.h" 25 | #include "./arrow/row.h" 26 | #include "./lib/attribute/attribute-manager.h" 27 | #include "./lib/constants.h" 28 | #include "./lib/deck.h" 29 | #include "./lib/layer.h" 30 | #include "./shaderlib/project/viewport-uniforms.h" 31 | #include "./viewports/viewport.h" 32 | #include "./viewports/web-mercator-viewport.h" 33 | #include "./views/map-view.h" 34 | #include "./views/view-state.h" 35 | #include "./views/view.h" 36 | 37 | namespace deckgl { 38 | 39 | void registerJSONConvertersForDeckCore(JSONConverter *); 40 | 41 | } // namespace deckgl 42 | 43 | #endif // DECKGL_CORE_CORE_H 44 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core/src/lib/attribute/attribute-manager.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "./attribute-manager.h" // NOLINT(build/include) 22 | 23 | #include "probe.gl/core.h" 24 | 25 | using namespace deckgl; 26 | using namespace lumagl; 27 | 28 | auto AttributeManager::getNeedsRedraw(bool clearRedrawFlags) -> bool { 29 | bool redraw = this->_needsRedraw; 30 | this->_needsRedraw = this->_needsRedraw && !clearRedrawFlags; 31 | return redraw; 32 | } 33 | 34 | void AttributeManager::setNeedsRedraw() { this->_needsRedraw = true; } 35 | 36 | void AttributeManager::add(const lumagl::garrow::ColumnBuilder& builder) { this->_builders.push_back(builder); } 37 | 38 | void AttributeManager::invalidate(const std::string& attributeName) { 39 | // TODO(ilija@unfolded.ai): Implement 40 | this->invalidateAll(); 41 | } 42 | 43 | void AttributeManager::invalidateAll() { 44 | // TODO(ilija@unfolded.ai): Implement 45 | probegl::DebugLog() << "AttributeManager: invalidating all attributes"; 46 | } 47 | 48 | auto AttributeManager::update(const std::shared_ptr& table) -> std::shared_ptr { 49 | return garrow::transformTable(table, this->_builders, this->device); 50 | } 51 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core/src/lib/component.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "./component.h" // NOLINT(build/include) 22 | 23 | using namespace deckgl; 24 | 25 | // Setters and getters for properties 26 | // TODO(ib@unfolded.ai): Auto generate from language-independent prop definition schema 27 | // TODO(ilija@unfolded.ai): Generate a unique id instead of an empty string for default value of id? 28 | static const std::vector> propTypeDefs = {std::make_shared>( 29 | "id", [](const JSONObject* props) { return dynamic_cast(props)->id; }, 30 | [](JSONObject* props, std::string value) { return dynamic_cast(props)->id = value; }, "")}; 31 | 32 | auto Component::Props::getProperties() const -> const std::shared_ptr { 33 | static auto properties = Properties::from(propTypeDefs); 34 | return properties; 35 | } 36 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core/src/lib/component.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef DECKGL_CORE_LIB_COMPONENT_H 22 | #define DECKGL_CORE_LIB_COMPONENT_H 23 | 24 | #include 25 | #include 26 | 27 | #include "deck.gl/json.h" 28 | 29 | namespace deckgl { 30 | 31 | /// \brief A root class for JSON-serialzed components of the API. 32 | class Component { 33 | public: 34 | class Props; 35 | explicit Component(std::shared_ptr props) : _props{props} {} 36 | virtual ~Component() {} 37 | 38 | protected: 39 | std::shared_ptr _props; 40 | }; 41 | 42 | class Component::Props : public JSONObject { 43 | public: 44 | using super = JSONObject; 45 | 46 | static constexpr const char* getTypeName() { return "Component"; } 47 | auto getProperties() const -> const std::shared_ptr override; 48 | virtual auto makeComponent(std::shared_ptr props) const -> std::shared_ptr { 49 | return std::make_shared(std::dynamic_pointer_cast(props)); 50 | } 51 | 52 | std::string id; 53 | }; 54 | 55 | } // namespace deckgl 56 | 57 | #endif // DECKGL_CORE_LIB_COMPONENT_H 58 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core/src/lib/constants.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "./constants.h" // NOLINT(build/include) 22 | 23 | using namespace deckgl; 24 | 25 | auto deckgl::operator<<(std::ostream& os, COORDINATE_SYSTEM cs) -> std::ostream& { 26 | switch (cs) { 27 | case COORDINATE_SYSTEM::DEFAULT: 28 | os << "DEFAULT"; 29 | break; 30 | case COORDINATE_SYSTEM::CARTESIAN: 31 | os << "CARTESIAN"; 32 | break; 33 | case COORDINATE_SYSTEM::LNGLAT: 34 | os << "LNGLAT"; 35 | break; 36 | case COORDINATE_SYSTEM::METER_OFFSETS: 37 | os << "METER_OFFSETS"; 38 | break; 39 | case COORDINATE_SYSTEM::LNGLAT_OFFSETS: 40 | os << "LNGLAT_OFFSETS"; 41 | break; 42 | default: 43 | os << "Unknown"; 44 | break; 45 | } 46 | return os; 47 | } 48 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core/src/lib/constants.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef DECKGL_CORE_CONSTANTS_H 22 | #define DECKGL_CORE_CONSTANTS_H 23 | 24 | #include "deck.gl/json.h" 25 | 26 | namespace deckgl { 27 | 28 | // NOTE: The numeric values here are matched by shader code in the 29 | // "project" and "project64" shader modules. Both places need to be updated. 30 | 31 | /// \brief Describes how positions are interpreted. Can be specified per layer 32 | enum class COORDINATE_SYSTEM { 33 | DEFAULT = -1, // `LNGLAT` if rendering into a geospatial viewport, 34 | // `CARTESIAN` otherwise 35 | 36 | // Non-geospatial coordinates 37 | CARTESIAN = 0, 38 | 39 | // Geospatial coordinates 40 | LNGLAT = 1, // Positions interpreted as [lng, lat, elevation]. lng + lat in 41 | // degrees, elevation + distances in meters. 42 | METER_OFFSETS = 2, // Positions are interpreted as meter offsets, distances as meters 43 | LNGLAT_OFFSETS = 3, // Positions are lng lat offsets: [deltaLng, deltaLat, 44 | // elevation]. elevation+distances are meters. 45 | }; 46 | 47 | auto operator<<(std::ostream& os, COORDINATE_SYSTEM cs) -> std::ostream&; 48 | 49 | // TODO(ib@unfolded.ai): Decide how to deserialize enum constants 50 | template <> 51 | inline auto fromJson(const Json::Value& jsonValue) -> COORDINATE_SYSTEM { 52 | return static_cast(fromJson(jsonValue)); 53 | } 54 | 55 | /// \brief Describes the common space. 56 | enum class PROJECTION_MODE { 57 | IDENTITY = 0, 58 | WEB_MERCATOR = 1, 59 | WEB_MERCATOR_AUTO_OFFSET = 4 // This is automatically assigned by the project module 60 | }; 61 | 62 | } // namespace deckgl 63 | 64 | #endif // DECKGL_CORE_CONSTANTS_H 65 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core/src/lib/layer-context.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef DECKGL_CORE_LAYER_CONTEXT_H 22 | #define DECKGL_CORE_LAYER_CONTEXT_H 23 | 24 | #include 25 | 26 | #include "deck.gl/core/src/viewports/web-mercator-viewport.h" 27 | #include "luma.gl/webgpu.h" 28 | 29 | namespace deckgl { 30 | 31 | class Deck; 32 | class LayerManager; 33 | class Viewport; 34 | 35 | /// \brief LayerContext contains data shared between all layers. 36 | class LayerContext { 37 | public: 38 | // TODO(ilija@unfolded.ai): Do we need to have this circular dependency here? 39 | Deck* deck; 40 | wgpu::Device device; 41 | float devicePixelRatio; 42 | 43 | // TODO(ilija@unfolded.ai): Do we need to have this circular dependency here? 44 | std::shared_ptr layerManager; 45 | // Make sure context.viewport is not empty on the first layer initialization 46 | std::shared_ptr viewport{new WebMercatorViewport{{}}}; 47 | 48 | LayerContext(Deck* deck, wgpu::Device device, float devicePixelRatio = 1.0) 49 | : deck{deck}, device{device}, devicePixelRatio{devicePixelRatio} {} 50 | }; 51 | 52 | } // namespace deckgl 53 | 54 | #endif // DECKGL_CORE_LAYER_CONTEXT_H 55 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core/src/lib/layer-state.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef DECKGL_CORE_LAYER_STATE_H 22 | #define DECKGL_CORE_LAYER_STATE_H 23 | 24 | #include 25 | 26 | namespace deckgl { 27 | 28 | class Layer; 29 | class AttributeManager; 30 | 31 | class LayerState { 32 | public: 33 | LayerState(const std::shared_ptr& layer, const std::shared_ptr& attributeManager) 34 | : layer{layer}, attributeManager{attributeManager}, needsRedraw{true} {} 35 | 36 | std::shared_ptr layer; 37 | std::shared_ptr attributeManager; 38 | bool needsRedraw; 39 | } 40 | 41 | } // namespace deckgl 42 | 43 | #endif // DECKGL_CORE_LAYER_STATE_H 44 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core/src/shaderlib/lighting/lighting.glsl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef DECKGL_CORE_SHADERLIB_LIGHTING_LIGHTING_GLSL_H 22 | #define DECKGL_CORE_SHADERLIB_LIGHTING_LIGHTING_GLSL_H 23 | 24 | #include 25 | 26 | // NOLINTNEXTLINE(runtime/string) 27 | static const std::string lighting = R"GLSL( 28 | //#if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX)) 29 | 30 | #define MAX_LIGHTS 3 31 | 32 | struct AmbientLight { 33 | vec3 color; 34 | }; 35 | 36 | struct PointLight { 37 | vec3 color; 38 | vec3 position; 39 | // Constant-Linear-Exponential 40 | vec3 attenuation; 41 | }; 42 | 43 | struct DirectionalLight { 44 | vec3 color; 45 | vec3 direction; 46 | }; 47 | 48 | // TODO(ilija@unfolded.ai): These should be uniforms 49 | AmbientLight lighting_uAmbientLight; 50 | PointLight lighting_uPointLight[MAX_LIGHTS]; 51 | DirectionalLight lighting_uDirectionalLight[MAX_LIGHTS]; 52 | int lighting_uPointLightCount; 53 | int lighting_uDirectionalLightCount; 54 | 55 | bool lighting_uEnabled; 56 | 57 | float getPointLightAttenuation(PointLight pointLight, float distance) { 58 | return pointLight.attenuation.x 59 | + pointLight.attenuation.y * distance 60 | + pointLight.attenuation.z * distance * distance; 61 | } 62 | 63 | //#endif 64 | )GLSL"; 65 | 66 | #endif // DECKGL_CORE_SHADERLIB_LIGHTING_LIGHTING_GLSL_H 67 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core/src/shaderlib/misc/geometry.glsl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef DECKGL_CORE_SHADERLIB_MISC_GEOMETRY_GLSL_H 22 | #define DECKGL_CORE_SHADERLIB_MISC_GEOMETRY_GLSL_H 23 | 24 | #include 25 | 26 | // NOLINTNEXTLINE(runtime/string) 27 | static const std::string geometryVS = R"GLSL( 28 | struct VertexGeometry { 29 | vec4 position; 30 | vec3 worldPosition; 31 | vec3 worldPositionAlt; 32 | vec3 normal; 33 | vec2 uv; 34 | vec3 pickingColor; 35 | } geometry; 36 | )GLSL"; 37 | 38 | // NOLINTNEXTLINE(runtime/string) 39 | static const std::string geometryFS = R"GLSL( 40 | #define SMOOTH_EDGE_RADIUS 0.5 41 | 42 | struct FragmentGeometry { 43 | vec2 uv; 44 | } geometry; 45 | 46 | float smoothedge(float edge, float x) { 47 | return smoothstep(edge - SMOOTH_EDGE_RADIUS, edge + SMOOTH_EDGE_RADIUS, x); 48 | } 49 | )GLSL"; 50 | 51 | #endif // DECKGL_CORE_SHADERLIB_MISC_GEOMETRY_GLSL_H 52 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core/src/shaderlib/project/project32.glsl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef DECKGL_CORE_SHADERLIB_PROJECT_PROJECT32_GLSL_H 22 | #define DECKGL_CORE_SHADERLIB_PROJECT_PROJECT32_GLSL_H 23 | 24 | #include 25 | 26 | #include "./project.glsl.h" 27 | 28 | // NOLINTNEXTLINE(runtime/string) 29 | static const std::string project32VS = projectVS + "\n" + R"GLSL( 30 | vec4 project_position_to_clipspace( 31 | vec3 position, vec3 position64Low, vec3 offset, out vec4 commonPosition 32 | ) { 33 | vec3 projectedPosition = project_position(position, position64Low); 34 | commonPosition = vec4(projectedPosition + offset, 1.0); 35 | return project_common_position_to_clipspace(commonPosition); 36 | } 37 | 38 | vec4 project_position_to_clipspace( 39 | vec3 position, vec3 position64Low, vec3 offset 40 | ) { 41 | vec4 commonPosition; 42 | return project_position_to_clipspace(position, position64Low, offset, commonPosition); 43 | } 44 | )GLSL"; 45 | 46 | #endif // DECKGL_CORE_SHADERLIB_PROJECT_PROJECT32_GLSL_H 47 | 48 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core/src/views/map-view.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Unfolded Inc 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "./map-view.h" // {MapView} NOLINT(build/include) 22 | 23 | #include 24 | 25 | #include "../viewports/web-mercator-viewport.h" // {WebMercatorViewport} 26 | 27 | using namespace std; 28 | using namespace deckgl; 29 | using namespace mathgl; 30 | 31 | auto MapView::getProperties() const -> const std::shared_ptr { 32 | static auto properties = Properties::from(); 33 | return properties; 34 | } 35 | 36 | auto MapView::_getViewport(const Rectangle& rect, const shared_ptr& viewState) const 37 | -> shared_ptr { 38 | WebMercatorViewport::Options opts; 39 | opts.width = rect.w; 40 | opts.height = rect.h; 41 | if (viewState->longitude) { 42 | opts.longitude = viewState->longitude.value(); 43 | } 44 | if (viewState->latitude) { 45 | opts.latitude = viewState->latitude.value(); 46 | } 47 | if (viewState->zoom) { 48 | opts.zoom = viewState->zoom.value(); 49 | } 50 | if (viewState->pitch) { 51 | opts.pitch = viewState->pitch.value(); 52 | } 53 | if (viewState->bearing) { 54 | opts.bearing = viewState->bearing.value(); 55 | } 56 | 57 | return make_shared(opts); 58 | } 59 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core/src/views/map-view.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Unfolded Inc 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef DECKGL_CORE_VIEWS_MAP_VIEW_H 22 | #define DECKGL_CORE_VIEWS_MAP_VIEW_H 23 | 24 | #include 25 | 26 | #include "./view.h" 27 | #include "math.gl/core.h" 28 | 29 | namespace deckgl { 30 | 31 | /// \brief View which uses WebMercatorViewport instance as its viewport. 32 | class MapView : public View { 33 | public: 34 | using super = View; 35 | 36 | // Property Type Machinery 37 | static constexpr const char* getTypeName() { return "MapView"; } 38 | auto getProperties() const -> const std::shared_ptr override; 39 | 40 | protected: 41 | auto _getViewport(const mathgl::Rectangle& rect, const std::shared_ptr& viewState) const 42 | -> std::shared_ptr override; 43 | }; 44 | 45 | } // namespace deckgl 46 | 47 | #endif // DECKGL_CORE_VIEWS_MAP_VIEW_H 48 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core/src/views/view-state.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Unfolded Inc 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "./view-state.h" // NOLINT(build/include) 22 | 23 | using namespace deckgl; 24 | 25 | const std::vector> propTypeDefs = { 26 | std::make_shared>>( 27 | "longitude", [](const JSONObject* props) { return dynamic_cast(props)->longitude; }, 28 | [](JSONObject* props, const double& value) { return dynamic_cast(props)->longitude = value; }, 0.0), 29 | std::make_shared>>( 30 | "latitude", [](const JSONObject* props) { return dynamic_cast(props)->latitude; }, 31 | [](JSONObject* props, const double& value) { return dynamic_cast(props)->latitude = value; }, 0.0), 32 | std::make_shared>>( 33 | "zoom", [](const JSONObject* props) { return dynamic_cast(props)->zoom; }, 34 | [](JSONObject* props, const double& value) { return dynamic_cast(props)->zoom = value; }, 10), 35 | std::make_shared>>( 36 | "bearing", [](const JSONObject* props) { return dynamic_cast(props)->bearing; }, 37 | [](JSONObject* props, const double& value) { return dynamic_cast(props)->bearing = value; }, 0.0), 38 | std::make_shared>>( 39 | "pitch", [](const JSONObject* props) { return dynamic_cast(props)->pitch; }, 40 | [](JSONObject* props, const double& value) { return dynamic_cast(props)->pitch = value; }, 0.0)}; 41 | 42 | auto ViewState::getProperties() const -> const std::shared_ptr { 43 | static auto properties = Properties::from(propTypeDefs); 44 | return properties; 45 | } 46 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core/src/views/view-state.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Unfolded Inc 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef DECKGL_CORE_VIEWS_VIEW_STATE_H 22 | #define DECKGL_CORE_VIEWS_VIEW_STATE_H 23 | 24 | #include 25 | #include 26 | 27 | #include "deck.gl/json.h" 28 | 29 | namespace deckgl { 30 | 31 | /// \brief Utility struct that encapsulates view metadata. 32 | class ViewState : public JSONObject { 33 | public: 34 | using super = JSONObject; 35 | 36 | virtual ~ViewState() {} 37 | 38 | // Map view states 39 | std::optional longitude; 40 | std::optional latitude; 41 | std::optional zoom; 42 | std::optional bearing; 43 | std::optional pitch; 44 | 45 | // Property Type Machinery 46 | static constexpr const char* getTypeName() { return "ViewState"; } 47 | auto getProperties() const -> const std::shared_ptr override; 48 | }; 49 | 50 | } // namespace deckgl 51 | 52 | #endif // DECKGL_CORE_VIEWS_VIEW_STATE_H 53 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core/test/lib/earcut-test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Unfolded Inc 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "deck.gl/core/src/lib/earcut.hpp" 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | TEST(Earcut, IndicesLength) { 30 | using Coord = double; 31 | using N = uint16_t; 32 | 33 | using Point = std::array; 34 | std::vector> polygon; 35 | std::vector mainPolygon = {{100, 0}, {100, 100}, {0, 100}, {0, 0}}; 36 | std::vector holes = {{75, 25}, {75, 75}, {25, 75}, {25, 25}}; 37 | 38 | polygon.push_back(mainPolygon); 39 | polygon.push_back(holes); 40 | 41 | std::vector indices = mapbox::earcut(polygon); 42 | 43 | // Length of indices list should be 3* that of the input polygon list 44 | EXPECT_EQ(indices.size() / 3, (mainPolygon.size() + holes.size())); 45 | } 46 | 47 | TEST(Earcut, IndicesLength3) { 48 | using Coord = double; 49 | using N = uint16_t; 50 | 51 | using Point = std::array; 52 | std::vector> polygon; 53 | std::vector mainPolygon = {{100, 0, 1}, {100, 100, 2}, {0, 100, 3}, {0, 0, 4}}; 54 | std::vector holes = {{75, 25, 1}, {75, 75, 2}, {25, 75, 3}, {25, 25, 4}}; 55 | 56 | polygon.push_back(mainPolygon); 57 | polygon.push_back(holes); 58 | 59 | std::vector indices = mapbox::earcut(polygon); 60 | 61 | // Length of indices list should be 3* that of the input polygon list 62 | EXPECT_EQ(indices.size() / 3, (mainPolygon.size() + holes.size())); 63 | } 64 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core/test/lib/layer-manager-test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Unfolded Inc 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "deck.gl/core/src/lib/layer-manager.h" 22 | 23 | #include 24 | 25 | #include 26 | 27 | using namespace deckgl; 28 | 29 | namespace { 30 | 31 | TEST(LayerManager, Construct) { 32 | auto layerManager = std::unique_ptr(new LayerManager(nullptr)); 33 | 34 | EXPECT_TRUE(layerManager != nullptr); 35 | } 36 | 37 | } // namespace 38 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core/test/lib/layer-test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Unfolded Inc 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include 22 | 23 | #include 24 | 25 | #include "deck.gl/core.h" 26 | 27 | using namespace deckgl; 28 | 29 | namespace { 30 | 31 | TEST(Layer, Props) { 32 | auto layerProps1 = std::unique_ptr(new Layer::Props()); 33 | auto layerProps2 = std::unique_ptr(new Layer::Props()); 34 | 35 | EXPECT_TRUE(layerProps1->equals(layerProps2.get())); 36 | layerProps2->opacity = 0.5; 37 | EXPECT_FALSE(layerProps1->equals(layerProps2.get())); 38 | 39 | auto properties = layerProps1->getProperties(); 40 | 41 | EXPECT_TRUE(properties->hasProp("opacity")); 42 | EXPECT_FALSE(properties->hasProp("radiusScale")); 43 | } 44 | 45 | } // namespace 46 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core/test/viewports/viewport-test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Unfolded Inc 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include 22 | 23 | #include 24 | 25 | #include "deck.gl/core.h" 26 | 27 | using namespace mathgl; 28 | using namespace deckgl; 29 | 30 | /// \brief Fixture for testing Viewport implementation. 31 | class ViewportTest : public ::testing::Test { 32 | protected: 33 | ViewportTest() {} 34 | }; 35 | 36 | TEST_F(ViewportTest, Simple) { 37 | ViewMatrixOptions viewMatrixOptions; 38 | ProjectionMatrixOptions projectionMatrixOptions; 39 | Viewport viewport{"my-viewport-id", viewMatrixOptions, projectionMatrixOptions, 0, 0, 0, 0}; 40 | EXPECT_FALSE(viewport.containsPixel(0, 0)); 41 | viewport.width = 10; 42 | viewport.height = 10; 43 | EXPECT_TRUE(viewport.containsPixel(2, 1, 5, 5)); 44 | } 45 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core/test/views/map-view-json-data.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Unfolded Inc 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | static auto viewJsonDataWidth = R"JSON( 22 | { 23 | "@@type": "View", 24 | "width": 1000 25 | } 26 | )JSON"; 27 | 28 | static auto mapViewJsonDataWidth = R"JSON( 29 | { 30 | "@@type": "MapView", 31 | "width": 1000 32 | } 33 | )JSON"; 34 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core/test/views/map-view-test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Unfolded Inc 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include 22 | 23 | #include 24 | 25 | #include "./map-view-json-data.h" 26 | #include "deck.gl/core.h" 27 | 28 | using namespace mathgl; 29 | using namespace deckgl; 30 | 31 | class MapViewTest : public ::testing::Test { 32 | protected: 33 | MapViewTest() { 34 | jsonConverter = std::unique_ptr(new JSONConverter()); 35 | 36 | registerJSONConvertersForDeckCore(jsonConverter.get()); 37 | } 38 | 39 | std::unique_ptr jsonConverter; 40 | }; 41 | 42 | TEST_F(MapViewTest, JSONParse) { 43 | auto mapView = std::dynamic_pointer_cast(jsonConverter->convertJson(mapViewJsonDataWidth)); 44 | auto view = jsonConverter->convertJson(viewJsonDataWidth); 45 | 46 | EXPECT_FALSE(mapView->equals(view)); 47 | EXPECT_EQ(mapView->width, 1000); 48 | } 49 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core/test/views/view-json-data.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Unfolded Inc 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | static auto viewJsonData = R"JSON( 22 | { 23 | "@@type": "View" 24 | } 25 | )JSON"; 26 | 27 | static auto viewJsonDataWidth = R"JSON( 28 | { 29 | "@@type": "View", 30 | "width": 1000 31 | } 32 | )JSON"; 33 | 34 | static auto viewJsonDataWidthAndHeight = R"JSON( 35 | { 36 | "@@type": "View", 37 | "width": 1000, 38 | "height": 1000 39 | } 40 | )JSON"; 41 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core/test/views/view-state-test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Unfolded Inc 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include 22 | 23 | #include "deck.gl/core.h" 24 | 25 | using namespace std; 26 | using namespace deckgl; 27 | 28 | TEST(ViewStateTest, Equality) { 29 | auto vs1 = make_shared(); 30 | auto vs2 = make_shared(); 31 | 32 | vs1->latitude = 10; 33 | vs2->latitude = 10; 34 | EXPECT_TRUE(*vs1 == *vs2); 35 | 36 | vs2->longitude = 10; 37 | EXPECT_TRUE(*vs1 != *vs2); 38 | } 39 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/core/test/views/view-test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Unfolded Inc 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include 22 | 23 | #include 24 | 25 | #include "./view-json-data.h" 26 | #include "deck.gl/core.h" 27 | 28 | using namespace mathgl; 29 | using namespace deckgl; 30 | 31 | class ViewTest : public ::testing::Test { 32 | protected: 33 | ViewTest() { 34 | jsonConverter = std::unique_ptr(new JSONConverter()); 35 | 36 | registerJSONConvertersForDeckCore(jsonConverter.get()); 37 | } 38 | 39 | std::unique_ptr jsonConverter; 40 | }; 41 | 42 | TEST_F(ViewTest, JSONParse) { 43 | auto view1 = jsonConverter->convertJson(viewJsonData); 44 | auto view1copy = jsonConverter->convertJson(viewJsonData); 45 | 46 | // Tests for equality 47 | EXPECT_TRUE(view1->equals(view1)); 48 | EXPECT_TRUE(view1->equals(view1copy)); 49 | // pointers should not be the same even though the objects are equal 50 | EXPECT_FALSE(view1.get() == view1copy.get()); 51 | EXPECT_FALSE(view1->equals(nullptr)); 52 | EXPECT_EQ(view1->compare(view1), std::nullopt); 53 | EXPECT_EQ(view1->compare(view1copy), std::nullopt); 54 | EXPECT_NE(view1->compare(nullptr), std::nullopt); 55 | 56 | auto view2 = jsonConverter->convertJson(viewJsonDataWidth); 57 | 58 | EXPECT_FALSE(view1->equals(view2)); 59 | EXPECT_NE(view1->compare(view2), std::nullopt); 60 | } 61 | 62 | TEST_F(ViewTest, JSONProps) { 63 | auto view = std::dynamic_pointer_cast(jsonConverter->convertJson(viewJsonDataWidthAndHeight)); 64 | 65 | EXPECT_EQ(view->x, 0); 66 | EXPECT_EQ(view->y, 0); 67 | EXPECT_EQ(view->width, 1000); 68 | EXPECT_EQ(view->height, 1000); 69 | } 70 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/json.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Unfolded Inc 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef DECKGL_JSON_H 22 | #define DECKGL_JSON_H 23 | 24 | #include "./json/src/json.h" 25 | 26 | #endif // DECKGL_JSON_H 27 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/json/src/converter/json-types-mathgl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef DECKGL_JSON_JSON_TYPES_MATHGL_H 22 | #define DECKGL_JSON_JSON_TYPES_MATHGL_H 23 | 24 | #include "./json-types.h" 25 | #include "math.gl/core.h" 26 | 27 | namespace deckgl { 28 | 29 | template <> 30 | auto fromJson>(const Json::Value &jsonValue) -> mathgl::Vector3; 31 | 32 | template <> 33 | auto fromJson>(const Json::Value &jsonValue) -> mathgl::Vector3; 34 | 35 | template <> 36 | auto fromJson>(const Json::Value &jsonValue) -> mathgl::Matrix4; 37 | 38 | template <> 39 | auto fromJson>(const Json::Value &jsonValue) -> mathgl::Matrix4; 40 | 41 | } // namespace deckgl 42 | 43 | #endif // DECKGL_JSON_JSON_TYPES_H 44 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/json/src/converter/json-types.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef DECKGL_JSON_JSON_TYPES_H 22 | #define DECKGL_JSON_JSON_TYPES_H 23 | 24 | #include 25 | 26 | #include 27 | 28 | namespace deckgl { 29 | 30 | // TODO(ib) - mathgl types 31 | 32 | // template 33 | // struct Type {}; 34 | 35 | // template <> 36 | // struct Type { 37 | // static constexpr const char *name{"bool"}; 38 | // }; 39 | 40 | // template <> 41 | // struct Type { 42 | // static constexpr const char *name{"int"}; 43 | // }; 44 | 45 | template 46 | auto fromJson(const Json::Value &) -> T; 47 | 48 | template <> 49 | auto fromJson(const Json::Value &jsonValue) -> bool; 50 | 51 | template <> 52 | auto fromJson(const Json::Value &jsonValue) -> int; 53 | 54 | template <> 55 | auto fromJson(const Json::Value &jsonValue) -> double; 56 | 57 | template <> 58 | auto fromJson(const Json::Value &jsonValue) -> float; 59 | 60 | template <> 61 | auto fromJson(const Json::Value &jsonValue) -> std::string; 62 | 63 | } // namespace deckgl 64 | 65 | #endif // DECKGL_JSON_JSON_TYPES_H 66 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/json/src/json.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef DECKGL_JSON_JSON_H 22 | #define DECKGL_JSON_JSON_H 23 | 24 | #include "./converter/json-converter.h" 25 | #include "./converter/json-types-mathgl.h" 26 | #include "./converter/json-types.h" 27 | 28 | #endif // DECKGL_JSON_JSON_H 29 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/json/test/json-object-test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Unfolded Inc 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "deck.gl/json.h" 28 | 29 | using namespace deckgl; 30 | 31 | namespace { 32 | 33 | /** 34 | * The fixture for testing class JSONObject. 35 | */ 36 | class JSONObjectTest : public ::testing::Test { 37 | protected: 38 | JSONObjectTest() {} 39 | }; 40 | 41 | TEST_F(JSONObjectTest, JSONConfig) { EXPECT_NO_THROW({}); } 42 | 43 | } // namespace 44 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/json/test/json-types-test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Unfolded Inc 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | #include "deck.gl/json.h" 27 | 28 | using namespace deckgl; 29 | 30 | namespace { 31 | 32 | /** 33 | * The fixture for testing class Foo. 34 | */ 35 | class JSONTypeConverterTest : public ::testing::Test { 36 | protected: 37 | // You can remove any or all of the following functions if their bodies would 38 | // be empty. 39 | std::unique_ptr jsonConverter; 40 | 41 | JSONTypeConverterTest() { 42 | // You can do set-up work for each test here. 43 | jsonConverter = std::unique_ptr(new JSONConverter()); 44 | } 45 | 46 | ~JSONTypeConverterTest() override { 47 | // You can do clean-up work that doesn't throw exceptions here. 48 | } 49 | 50 | // If the constructor and destructor are not enough for setting up 51 | // and cleaning up each test, you can define the following methods: 52 | 53 | void SetUp() override { 54 | // Code here will be called immediately after the constructor (right 55 | // before each test). 56 | } 57 | 58 | void TearDown() override { 59 | // Code here will be called immediately after each test (right 60 | // before the destructor). 61 | } 62 | 63 | // Class members declared here can be used by all tests in the test suite 64 | // for Foo. 65 | }; 66 | 67 | TEST_F(JSONTypeConverterTest, JSONParse) { 68 | Json::Value jsonValue = jsonConverter->parseJson("[1, 2, 3]"); 69 | auto vector3 = fromJson>(jsonValue); 70 | EXPECT_EQ(vector3.x, 1); 71 | EXPECT_EQ(vector3.y, 2); 72 | EXPECT_EQ(vector3.z, 3); 73 | } 74 | 75 | } // namespace 76 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/layers.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef DECKGL_LAYERS_H 22 | #define DECKGL_LAYERS_H 23 | 24 | #include "./layers/src/layers.h" 25 | 26 | #endif // DECKGL_LAYERS_H 27 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/layers/README.md: -------------------------------------------------------------------------------- 1 | # @deck.gl-native layers.h 2 | 3 | This is the C++ version of the core layer catalog for deck.gl. 4 | 5 | See [deck.gl](http://deck.gl) for documentation. 6 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/layers/src/layers.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "./layers.h" // NOLINT(build/include) 22 | 23 | using namespace deckgl; 24 | 25 | void deckgl::registerJSONConvertersForDeckLayers(JSONConverter *jsonConverter) { 26 | jsonConverter->classes["LineLayer"] = [](const Json::Value &) { return std::make_shared(); }; 27 | 28 | jsonConverter->classes["ScatterplotLayer"] = [](const Json::Value &) { 29 | return std::make_shared(); 30 | }; 31 | 32 | jsonConverter->classes["SolidPolygonLayer"] = [](const Json::Value &) { 33 | return std::make_shared(); 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/layers/src/layers.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef DECKGL_LAYERS_LAYERS_H 22 | #define DECKGL_LAYERS_LAYERS_H 23 | 24 | #include "./line-layer/line-layer.h" 25 | #include "./scatterplot-layer/scatterplot-layer.h" 26 | #include "./solid-polygon-layer/solid-polygon-layer.h" 27 | 28 | namespace deckgl { 29 | 30 | void registerJSONConvertersForDeckLayers(JSONConverter *); 31 | 32 | } // namespace deckgl 33 | 34 | #endif // DECKGL_LAYERS_LAYERS_H 35 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/layers/src/line-layer/line-layer-fragment.glsl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef DECKGL_LAYERS_LINE_LAYER_FRAGMENT_H 22 | #define DECKGL_LAYERS_LINE_LAYER_FRAGMENT_H 23 | 24 | #include 25 | 26 | #include "deck.gl/core/src/shaderlib/misc/geometry.glsl.h" 27 | 28 | namespace { 29 | 30 | // NOLINTNEXTLINE(runtime/string) 31 | static const std::string lineLayerFS = R"GLSL( 32 | layout(location = 0) in vec4 vColor; 33 | layout(location = 1) in vec2 uv; 34 | 35 | layout(location = 0) out vec4 fragColor; 36 | 37 | void main(void) { 38 | geometry.uv = uv; 39 | 40 | fragColor = vColor; 41 | } 42 | )GLSL"; 43 | 44 | } // anonymous namespace 45 | 46 | // NOLINTNEXTLINE(runtime/string) 47 | static const std::string fs = "#version 450\n" + geometryFS + "\n" + lineLayerFS; 48 | 49 | #endif // DECKGL_LAYERS_LINE_LAYER_FRAGMENT_H 50 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/layers/src/solid-polygon-layer/solid-polygon-layer-fragment.glsl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef DECKGL_LAYERS_SOLID_POLYGON_LAYER_FRAGMENT_H 22 | #define DECKGL_LAYERS_SOLID_POLYGON_LAYER_FRAGMENT_H 23 | 24 | #include 25 | 26 | namespace { 27 | 28 | // NOLINTNEXTLINE(runtime/string) 29 | static const std::string solidPolygonLayerFS = R"GLSL( 30 | layout(std140, set = 0, binding = 1) uniform SolidPolygonLayerOptions { 31 | bool extruded; 32 | bool wireframe; 33 | float elevationScale; 34 | float opacity; 35 | } layerOptions; 36 | 37 | layout(location = 0) in vec4 vColor; 38 | layout(location = 1) in float isValid; 39 | 40 | layout(location = 0) out vec4 fragColor; 41 | 42 | void main(void) { 43 | if (isValid < 0.5) { 44 | discard; 45 | } 46 | fragColor = vColor; 47 | } 48 | 49 | )GLSL"; 50 | 51 | // NOLINTNEXTLINE(runtime/string) 52 | static const std::string fs = "#version 450\n" + solidPolygonLayerFS; 53 | 54 | } // anonymous namespace 55 | 56 | #endif 57 | 58 | -------------------------------------------------------------------------------- /cpp/modules/deck.gl/layers/src/solid-polygon-layer/solid-polygon-layer-vertex-top.glsl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef DECKGL_LAYERS_SOLID_POLYGON_LAYER_VERTEX_TOP_H 22 | #define DECKGL_LAYERS_SOLID_POLYGON_LAYER_VERTEX_TOP_H 23 | 24 | #include 25 | 26 | #include "./solid-polygon-layer-vertex-main.glsl.h" 27 | #include "deck.gl/core/src/shaderlib/project/project32.glsl.h" 28 | #include "deck.gl/core/src/shaderlib/lighting/phong-lighting.glsl.h" 29 | #include "deck.gl/core/src/shaderlib/misc/geometry.glsl.h" 30 | 31 | namespace { 32 | 33 | // NOLINTNEXTLINE(runtime/string) 34 | static const std::string solidPolygonLayerVST1 = R"GLSL( 35 | layout(location = 2) in vec3 positions; 36 | layout(location = 3) in float elevations; 37 | layout(location = 4) in vec4 fillColors; 38 | layout(location = 5) in vec4 lineColors; 39 | 40 | // TODO(ilija@unfolded.ai): Revisit once double splitting is in place 41 | vec3 positions64Low = vec3(0.); 42 | 43 | )GLSL"; 44 | 45 | // NOLINTNEXTLINE(runtime/string) 46 | static const std::string solidPolygonLayerVST2 = R"GLSL( 47 | void main(void) { 48 | PolygonProps props; 49 | props.positions = positions; 50 | props.positions64Low = positions64Low; 51 | props.elevations = elevations; 52 | props.fillColors = fillColors; 53 | props.lineColors = lineColors; 54 | calculatePosition(props); 55 | } 56 | )GLSL"; 57 | 58 | // NOLINTNEXTLINE(runtime/string) 59 | static const std::string solidPolygonLayerVST = solidPolygonLayerVST1 + solidPolygonLayerVSM + solidPolygonLayerVST2; 60 | // NOLINTNEXTLINE(runtime/string 61 | static const std::string vst = 62 | "#version 450\n" + geometryVS + "\n" + project32VS + "\n" + phongLighting + "\n" + solidPolygonLayerVST; 63 | 64 | } // anonymous namespace 65 | 66 | #endif // DECKGL_LAYERS_SOLID_POLYGON_LAYER_VERTEX_TOP_H 67 | -------------------------------------------------------------------------------- /cpp/modules/loaders.gl/csv.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "./csv/src/csv-loader.h" 22 | -------------------------------------------------------------------------------- /cpp/modules/loaders.gl/csv/src/csv-loader.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Unfolded Inc 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "./csv-loader.h" // NOLINT(build/include) 22 | 23 | #include 24 | #include 25 | 26 | using namespace loadersgl; 27 | 28 | auto CSVLoader::loadTable(const std::shared_ptr input, probegl::Error& error) noexcept 29 | -> std::shared_ptr { 30 | return probegl::catchError([&]() { return this->loadTable(input); }, error); 31 | } 32 | 33 | auto CSVLoader::loadTable(const std::shared_ptr input) -> std::shared_ptr { 34 | arrow::MemoryPool* pool = arrow::default_memory_pool(); 35 | 36 | auto readOptions = arrow::csv::ReadOptions::Defaults(); 37 | auto parseOptions = arrow::csv::ParseOptions::Defaults(); 38 | auto convertOptions = arrow::csv::ConvertOptions::Defaults(); 39 | 40 | // Instantiate TableReader from input stream and options 41 | auto makeResult = arrow::csv::TableReader::Make(pool, input, readOptions, parseOptions, convertOptions); 42 | if (!makeResult.ok()) { 43 | // TODO(ilija@unfolded.ai): Ideally we provide additional context here somehow... 44 | throw std::runtime_error("Cannot instantiate TableReader"); 45 | } 46 | 47 | std::shared_ptr reader = makeResult.ValueOrDie(); 48 | 49 | // Read table from CSV file 50 | auto readResult = reader->Read(); 51 | if (!readResult.ok()) { 52 | // TODO(ilija@unfolded.ai): Ideally we provide additional context here somehow... 53 | throw std::runtime_error("An error has occured while parsing CSV data"); 54 | } 55 | std::shared_ptr table = readResult.ValueOrDie(); 56 | 57 | return table; 58 | } 59 | -------------------------------------------------------------------------------- /cpp/modules/loaders.gl/csv/src/csv-loader.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef LOADERSGL_CSV_CSV_LOADER_H 22 | #define LOADERSGL_CSV_CSV_LOADER_H 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include "probe.gl/core.h" 30 | 31 | namespace loadersgl { 32 | 33 | class CSVLoader { 34 | public: 35 | #pragma mark - Exception-free API 36 | 37 | auto loadTable(const std::shared_ptr input, probegl::Error& error) noexcept 38 | -> std::shared_ptr; 39 | 40 | #pragma mark - 41 | 42 | auto loadTable(const std::shared_ptr input) -> std::shared_ptr; 43 | }; 44 | 45 | } // namespace loadersgl 46 | 47 | #endif // LOADERSGL_CSV_CSV_LOADER_H 48 | -------------------------------------------------------------------------------- /cpp/modules/loaders.gl/json.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Unfolded Inc 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "./json/src/json-loader.h" 22 | -------------------------------------------------------------------------------- /cpp/modules/loaders.gl/json/src/json-loader.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "./json-loader.h" // NOLINT(build/include) 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | using namespace loadersgl; 30 | 31 | auto JSONLoader::loadTable(const std::shared_ptr input, probegl::Error& error) noexcept 32 | -> std::shared_ptr { 33 | return probegl::catchError([&]() { return this->loadTable(input); }, error); 34 | } 35 | 36 | auto JSONLoader::loadTable(const std::shared_ptr input) -> std::shared_ptr { 37 | arrow::Status status; 38 | arrow::MemoryPool* pool = arrow::default_memory_pool(); 39 | 40 | auto readOptions = arrow::json::ReadOptions::Defaults(); 41 | auto parseOptions = arrow::json::ParseOptions::Defaults(); 42 | 43 | // Instantiate TableReader from input stream and options 44 | std::shared_ptr reader; 45 | status = arrow::json::TableReader::Make(pool, input, readOptions, parseOptions, &reader); 46 | if (!status.ok()) { 47 | // Ideally we provide additional context here somehow... 48 | throw std::runtime_error("Cannot instantiate TableReader"); 49 | } 50 | 51 | std::shared_ptr table; 52 | // Read table from JSON file 53 | status = reader->Read(&table); 54 | if (!status.ok()) { 55 | // Ideally we provide additional context here somehow... 56 | throw std::runtime_error("An error has occured while parsing JSON data"); 57 | } 58 | 59 | return table; 60 | } 61 | -------------------------------------------------------------------------------- /cpp/modules/loaders.gl/json/src/json-loader.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef LOADERSGL_JSON_JSON_CONVERTER_H 22 | #define LOADERSGL_JSON_JSON_CONVERTER_H 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include "probe.gl/core.h" 30 | 31 | namespace loadersgl { 32 | 33 | class JSONLoader { 34 | public: 35 | #pragma mark - Exception-free API 36 | 37 | auto loadTable(const std::shared_ptr input, probegl::Error& error) noexcept 38 | -> std::shared_ptr; 39 | 40 | #pragma mark - 41 | 42 | auto loadTable(const std::shared_ptr input) -> std::shared_ptr; 43 | }; 44 | 45 | } // namespace loadersgl 46 | 47 | #endif // LOADERSGL_JSON_JSON_CONVERTER_H 48 | -------------------------------------------------------------------------------- /cpp/modules/loaders.gl/json/test/json-loader-data.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | static auto ndjsonDataSimple = R"JSON( 22 | {"@@type":"Deck","description":"Test","layers":[{"@@type":"ScatterplotLayer","data":[{"position1":[-155.25, 122.3],"position2":[23.1,522.21]}],"getFillColor":[255,0,0,255],"getRadius":1000},{"@@type":"LineLayer","data":[{"position1":[-122.45, 37.8],"position2":[-122.45,37.8]}]}]} 23 | )JSON"; 24 | 25 | static auto jsonDataTypes = R"JSON( 26 | {"string":"sample1","int":-3351,"double":65630.5,"double_array":[0.2,0.8]} 27 | {"string":"sample2","int":21,"double":5} 28 | )JSON"; 29 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/core.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef LUMAGL_CORE_H 22 | #define LUMAGL_CORE_H 23 | 24 | #include "./core/src/animation-loop/animation-loop.h" 25 | #include "./core/src/blit-model.h" 26 | #include "./core/src/model.h" 27 | #include "./core/src/size.h" 28 | 29 | #if defined(LUMAGL_USES_GLFW) 30 | #include "./core/src/animation-loop/glfw-animation-loop.h" 31 | #endif 32 | 33 | #if defined(LUMAGL_ENABLE_BACKEND_METAL) 34 | #include "./core/src/animation-loop/metal-animation-loop.h" 35 | #endif 36 | 37 | #include "./core/src/animation-loop/animation-loop-factory.h" 38 | 39 | #endif // LUMAGL_CORE_CORE_H 40 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/core/src/animation-loop/animation-loop-factory.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "./animation-loop-factory.h" // NOLINT(build/include) 22 | 23 | using namespace lumagl; 24 | 25 | auto AnimationLoopFactory::createAnimationLoop(const std::shared_ptr& options, 26 | probegl::Error& error) noexcept -> std::shared_ptr { 27 | return probegl::catchError([options]() { return createAnimationLoop(options); }, error); 28 | } 29 | 30 | auto AnimationLoopFactory::createAnimationLoop(probegl::Error& error) noexcept -> std::shared_ptr { 31 | return probegl::catchError([]() { return createAnimationLoop(); }, error); 32 | } 33 | 34 | auto AnimationLoopFactory::createAnimationLoop(const std::shared_ptr& options) 35 | -> std::shared_ptr { 36 | // If no options are passed, try and initialize the only setup which requires no arguments, which is GLFW 37 | if (!options) { 38 | #if defined(LUMAGL_USES_GLFW) 39 | GLFWAnimationLoop::Options opts; 40 | return std::make_shared(opts); 41 | #else 42 | return nullptr; 43 | #endif 44 | } 45 | 46 | #if defined(LUMAGL_USES_GLFW) 47 | if (auto glfwOptions = std::dynamic_pointer_cast(options)) { 48 | return std::make_shared(*glfwOptions.get()); 49 | } 50 | #endif 51 | 52 | #if defined(LUMAGL_ENABLE_BACKEND_METAL) 53 | if (auto metalOptions = std::dynamic_pointer_cast(options)) { 54 | return std::make_shared(*metalOptions.get()); 55 | } 56 | #endif 57 | 58 | return std::make_shared(*options.get()); 59 | } 60 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/core/src/animation-loop/animation-loop-factory.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef LUMAGL_CORE_ANIMATION_LOOP_FACTORY_H 22 | #define LUMAGL_CORE_ANIMATION_LOOP_FACTORY_H 23 | 24 | #include 25 | #include 26 | 27 | #include "luma.gl/core.h" 28 | #include "probe.gl/core.h" 29 | 30 | namespace lumagl { 31 | 32 | // TODO(ilija@unfolded.ai): Revisit this API 33 | struct AnimationLoopFactory { 34 | public: 35 | #pragma mark - Exception-free API 36 | 37 | static auto createAnimationLoop(const std::shared_ptr& options, 38 | probegl::Error& error) noexcept -> std::shared_ptr; 39 | static auto createAnimationLoop(probegl::Error& error) noexcept -> std::shared_ptr; 40 | 41 | #pragma mark - 42 | 43 | static auto createAnimationLoop(const std::shared_ptr& options = nullptr) 44 | -> std::shared_ptr; 45 | }; 46 | 47 | } // namespace lumagl 48 | 49 | #endif // LUMAGL_CORE_ANIMATION_LOOP_FACTORY_H 50 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/core/src/animation-loop/metal-animation-loop.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef LUMAGL_CORE_METAL_ANIMATION_LOOP_H 22 | #define LUMAGL_CORE_METAL_ANIMATION_LOOP_H 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | #include "./animation-loop.h" 30 | #include "luma.gl/webgpu/src/backends/metal-binding.h" 31 | 32 | namespace lumagl { 33 | 34 | class MetalAnimationLoop : public AnimationLoop { 35 | public: 36 | using super = AnimationLoop; 37 | struct Options; 38 | 39 | explicit MetalAnimationLoop(const Options& options); 40 | ~MetalAnimationLoop(); 41 | 42 | void draw(std::function onRender) override; 43 | 44 | auto getPreferredSwapChainTextureFormat() -> wgpu::TextureFormat override; 45 | auto devicePixelRatio() -> float override; 46 | void setSize(const Size& size) override; 47 | 48 | private: 49 | auto _createDevice() -> wgpu::Device; 50 | auto _createSwapchain(wgpu::Device device) -> wgpu::SwapChain; 51 | 52 | /// \brief Instance used for adapter discovery and device creation. It has to be kept around as Dawn objects' 53 | /// lifecycle seems to depend on it. 54 | /// \note From Dawn docs: This is an RAII class for Dawn instances and also controls the lifetime of all adapters 55 | /// for this instance. 56 | std::unique_ptr _instance{nullptr}; 57 | std::unique_ptr _binding; 58 | wgpu::SwapChain _swapchain; 59 | 60 | MTKView* _view; 61 | }; 62 | 63 | struct MetalAnimationLoop::Options : public AnimationLoop::Options { 64 | public: 65 | using super = AnimationLoop::Options; 66 | 67 | explicit Options(MTKView* view, const wgpu::Device& device = nullptr, const wgpu::Queue& queue = nullptr); 68 | 69 | MTKView* view; 70 | }; 71 | 72 | } // namespace lumagl 73 | 74 | #endif // LUMAGL_CORE_METAL_ANIMATION_LOOP_H 75 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/core/src/blit-model.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef LUMAGL_CORE_BLIT_MODEL_H 22 | #define LUMAGL_CORE_BLIT_MODEL_H 23 | 24 | #include "./model.h" 25 | #include "./size.h" 26 | 27 | namespace lumagl { 28 | 29 | /// Model subclass that provides an easy way to render draw a given texture. 30 | class BlitModel : public Model { 31 | public: 32 | BlitModel(const wgpu::Device& device, const wgpu::TextureView& textureView, const Size& textureSize); 33 | 34 | void setTextureSize(const Size& textureSize); 35 | 36 | private: 37 | auto _uniformBufferFromSize(const Size& size) -> wgpu::Buffer; 38 | }; 39 | 40 | } // namespace lumagl 41 | 42 | #endif // LUMAGL_CORE_BLIT_MODEL_H 43 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/core/src/size.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "./size.h" // NOLINT(build/include) 22 | 23 | using namespace lumagl; 24 | 25 | auto operator==(const Size& s1, const Size& s2) -> bool { return s1.width == s2.width && s1.height == s2.height; } 26 | 27 | auto operator!=(const Size& s1, const Size& s2) -> bool { return !(s1 == s2); } 28 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/core/src/size.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef LUMAGL_CORE_SIZE_H 22 | #define LUMAGL_CORE_SIZE_H 23 | 24 | namespace lumagl { 25 | 26 | struct Size { 27 | public: 28 | Size() : width{0}, height{0} {} 29 | Size(int width, int height) : width{width}, height{height} {} 30 | 31 | template 32 | auto operator*(const T& value) -> Size { 33 | return Size{static_cast(this->width * value), static_cast(this->height * value)}; 34 | } 35 | 36 | int width; 37 | int height; 38 | }; 39 | 40 | } // namespace lumagl 41 | 42 | auto operator==(const lumagl::Size& s1, const lumagl::Size& s2) -> bool; 43 | auto operator!=(const lumagl::Size& s1, const lumagl::Size& s2) -> bool; 44 | 45 | #endif // LUMAGL_CORE_SIZE_H 46 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/core/test/animation-loop-test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/core/test/model-test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/garrow.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef LUMAGL_GARROW_H 22 | #define LUMAGL_GARROW_H 23 | 24 | #include "./garrow/src/array.h" 25 | #include "./garrow/src/field.h" 26 | #include "./garrow/src/schema.h" 27 | #include "./garrow/src/table.h" 28 | #include "./garrow/src/util/arrow-utils.h" 29 | #include "./garrow/src/util/webgpu-utils.h" 30 | 31 | #endif // LUMAGL_GARROW_H 32 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/garrow/docs/arrow-mapping.md: -------------------------------------------------------------------------------- 1 | # Storing GPU Attributes in Arrow Tables 2 | 3 | Columnar tables typically have columns one value per row (say `longitude`, `latitude` and `height`) while GPU shaders typically work on columns (i.e. vertex attributes) with one short vector (`[longitude, latitude, height]`) per row. 4 | 5 | While it is possible to efficiently combine the invidual columns to a new column after loading, to maximize efficiency and to avoid using memory to store the temporary, throw-away individual columns, it can be desirable to generate the table with a pre-interleaved column with a short fixed-size array in each row. 6 | 7 | Thus, to represent typical GPU attributes as Arrow table columns, we need columns that contains short fixed-size arrays of numbers, e.g. three 32-bit floats per row (representing positions) or four 8-bit unsigned integers per row (representing colors). Arrow API provides `FixedSizeArray` type which can be used for this exact purpose. 8 | 9 | `GArrow` provides a simple interface that maps an existing `arrow::Table` into a `garrow::Table`, mapping supported data types to their WebGPU counterparts appropriately while copying data into GPU memory. 10 | 11 | ## Arrow to WebGPU Type Map 12 | 13 | | Arrow Type | WebGPU Vertex Type | 14 | |-------------------------------- |-------------------- | 15 | | UINT32 | UInt | 16 | | INT32 | Int | 17 | | FLOAT | Float | 18 | | FIXED_SIZE_LIST(BOOL, 2) | Char2 | 19 | | FIXED_SIZE_LIST(BOOL, 4) | Char4 | 20 | | FIXED_SIZE_LIST(UINT16, 2) | UShort2 | 21 | | FIXED_SIZE_LIST(UINT16, 4) | UShort4 | 22 | | FIXED_SIZE_LIST(INT16, 2) | Short2 | 23 | | FIXED_SIZE_LIST(INT16, 4) | Short4 | 24 | | FIXED_SIZE_LIST(UINT32, 2) | UInt2 | 25 | | FIXED_SIZE_LIST(UINT32, 3) | UInt3 | 26 | | FIXED_SIZE_LIST(UINT32, 4) | UInt4 | 27 | | FIXED_SIZE_LIST(INT32, 2) | Int2 | 28 | | FIXED_SIZE_LIST(INT32, 3) | Int3 | 29 | | FIXED_SIZE_LIST(INT32, 4) | Int4 | 30 | | FIXED_SIZE_LIST(HALF_FLOAT, 2) | Half2 | 31 | | FIXED_SIZE_LIST(HALF_FLOAT, 4) | Half4 | 32 | | FIXED_SIZE_LIST(FLOAT, 2) | Float2 | 33 | | FIXED_SIZE_LIST(FLOAT, 3) | Float3 | 34 | | FIXED_SIZE_LIST(FLOAT, 4) | Float4 | 35 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/garrow/docs/gpu-table-guide.md: -------------------------------------------------------------------------------- 1 | # Using garrow::Table 2 | 3 | The `Table` manages GPU buffer(s) representing a table of binary columns, where "table" implies that the columns have the same number of "rows" (though not necessarily the same byte length). 4 | 5 | The `Table` class carefully designed to support Apache Arrow formatted tables: 6 | - Supports initialization from arrow tables, building GPU buffer(s) from the chunked columns) 7 | - Attempts to cover a large subset of the data types that can be represented as columns in Arrow tables. 8 | - Defines mapping between Arrow data types and WebGPU 9 | - Defines transformations 10 | 11 | `garrow` API is modeled after `arrow`, and currently is identical when it comes to the key functionality, including `Table`. As this is a work in progress, only a subset of API has been implemented thus far for usage by `luma.gl` native implementation. As of right now, the goal is to provide complete functionality defined by `arrow` API reference that can be found [here](https://arrow.apache.org/docs/cpp/api/table.html#tables). 12 | 13 | ## References 14 | 15 | This guide describes basic usage of `Table`, see separate article for more advanced use cases, including: 16 | - Variable Length Rows 17 | - Constant columns... 18 | - Index column... 19 | 20 | It can be useful to understand how `GPUTable` compares with other similar APIs: 21 | - The Apache Arrow `Table` class. 22 | - The Python pandas [`DataFrame`](https://pandas.pydata.org/pandas-docs/stable/reference/frame.html) class. 23 | - The [GPU Data Frame](http://gpuopenanalytics.com/#/PROJECTS) in the [GoAi](http://gpuopenanalytics.com/#/) GPU Open Analytics Initiative. 24 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/garrow/src/field.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "./schema.h" // NOLINT(build/include) 22 | 23 | using namespace lumagl::garrow; 24 | 25 | Field::Field(const std::string& name, wgpu::VertexFormat type, bool nullable, 26 | const std::shared_ptr& metadata) 27 | : _name{name}, _type{type}, _nullable{nullable}, _metadata{metadata} { 28 | if (nullable) { 29 | throw std::runtime_error("Nullable fields currently not supported"); 30 | } 31 | } 32 | 33 | auto Field::Equals(const Field& other, bool check_metadata) const -> bool { 34 | if (this == &other) { 35 | return true; 36 | } 37 | 38 | if (this->_name == other._name && this->_nullable == other._nullable && this->_type == other._type) { 39 | if (!check_metadata) { 40 | return true; 41 | } else if (this->HasMetadata() && other.HasMetadata()) { 42 | return this->_metadata->Equals(*other._metadata); 43 | } else if (!this->HasMetadata() && !other.HasMetadata()) { 44 | return true; 45 | } else { 46 | return false; 47 | } 48 | } 49 | 50 | return false; 51 | } 52 | 53 | auto Field::Equals(const std::shared_ptr& other, bool check_metadata) const -> bool { 54 | return Equals(*other.get(), check_metadata); 55 | } 56 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/garrow/src/key-value-metadata.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "./key-value-metadata.h" // NOLINT(build/include) 22 | 23 | #include 24 | 25 | using namespace lumagl::garrow; 26 | 27 | KeyValueMetadata::KeyValueMetadata() {} 28 | 29 | KeyValueMetadata::KeyValueMetadata(const std::vector& keys, const std::vector& values) 30 | : _keys{keys}, _values{values} { 31 | if (keys.size() != values.size()) { 32 | throw std::runtime_error("keys and values vectors must have the same size"); 33 | } 34 | } 35 | 36 | KeyValueMetadata::KeyValueMetadata(const std::unordered_map& map) { 37 | std::vector keys; 38 | std::vector values; 39 | for (std::pair element : map) { 40 | keys.push_back(element.first); 41 | values.push_back(element.second); 42 | } 43 | 44 | this->_keys = keys; 45 | this->_values = values; 46 | } 47 | 48 | void KeyValueMetadata::ToUnorderedMap(std::unordered_map* out) const { 49 | for (int i = 0; i < this->size(); i++) { 50 | out->insert(std::make_pair(this->_keys[i], this->_values[i])); 51 | } 52 | } 53 | 54 | void KeyValueMetadata::Append(const std::string& key, const std::string& value) { 55 | this->_keys.push_back(key); 56 | this->_values.push_back(value); 57 | } 58 | 59 | auto KeyValueMetadata::FindKey(const std::string& key) const -> int { 60 | for (int i = 0; i < this->size(); i++) { 61 | if (key == this->_keys[i]) { 62 | return i; 63 | } 64 | } 65 | 66 | return -1; 67 | } 68 | 69 | auto KeyValueMetadata::Equals(const KeyValueMetadata& other) const -> bool { 70 | if (size() != other.size()) { 71 | return false; 72 | } 73 | 74 | // TODO(ilija@unfolded.ai): Sort these before comparing 75 | return this->_keys == other._keys && this->_values == other._values; 76 | } 77 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/garrow/src/schema.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "./schema.h" // NOLINT(build/include) 22 | 23 | using namespace lumagl::garrow; 24 | 25 | // TODO(ilija@unfolded.ai): Metadata and fingerprinting not implemented 26 | auto Schema::Equals(const Schema& other, bool check_metadata) const -> bool { 27 | if (this == &other) { 28 | return true; 29 | } 30 | 31 | if (num_fields() != other.num_fields()) { 32 | return false; 33 | } 34 | 35 | for (int i = 0; i < num_fields(); ++i) { 36 | if (!field(i)->Equals(*other.field(i).get(), check_metadata)) { 37 | return false; 38 | } 39 | } 40 | 41 | return true; 42 | } 43 | 44 | auto Schema::Equals(const std::shared_ptr& other, bool check_metadata) const -> bool { 45 | if (other == nullptr) { 46 | return false; 47 | } 48 | 49 | return this->Equals(*other, check_metadata); 50 | } 51 | 52 | auto Schema::field_names() const -> std::vector { 53 | std::vector names; 54 | std::transform(this->_fields.begin(), this->_fields.end(), std::back_inserter(names), 55 | [](std::shared_ptr field) { return field->name(); }); 56 | return names; 57 | }; 58 | 59 | auto Schema::GetFieldByName(const std::string& name) const -> std::shared_ptr { 60 | for (auto const& field : this->_fields) { 61 | if (field->name() == name) { 62 | return field; 63 | } 64 | } 65 | return nullptr; 66 | } 67 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/garrow/src/schema.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef LUMAGL_GARROW_SCHEMA_H 22 | #define LUMAGL_GARROW_SCHEMA_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "./field.h" 30 | 31 | namespace lumagl { 32 | namespace garrow { 33 | 34 | /// \brief Sequence of Field objects describing the columns of a table data structure. 35 | class Schema { 36 | public: 37 | explicit Schema(const std::vector>& fields) : _fields{fields} {} 38 | 39 | /// \brief Returns true if all of the schema fields are equal. 40 | auto Equals(const Schema& other, bool check_metadata = true) const -> bool; 41 | auto Equals(const std::shared_ptr& other, bool check_metadata = true) const -> bool; 42 | 43 | /// \brief Returns number of fields that this schema contains. 44 | auto num_fields() const -> int { return static_cast(this->_fields.size()); } 45 | 46 | /// \brief Returns the ith schema element. Does not boundscheck. 47 | auto field(int i) const -> std::shared_ptr { return this->_fields[i]; }; 48 | 49 | /// \brief Returns a collection of fields that are part of this schema. 50 | auto fields() const -> const std::vector>& { return this->_fields; }; 51 | 52 | /// \brief Returns a collection of field names that are part of this schema. 53 | auto field_names() const -> std::vector; 54 | 55 | /// \brief Attempts to get a field by its name, returns nullptr if it could not be found. 56 | auto GetFieldByName(const std::string& name) const -> std::shared_ptr; 57 | 58 | private: 59 | // TODO(ilija@unfolded.ai): Use a map if field_names/GetFieldByName are used commonly 60 | std::vector> _fields; 61 | }; 62 | 63 | } // namespace garrow 64 | } // namespace lumagl 65 | 66 | #endif // LUMAGL_GARROW_SCHEMA_H 67 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/garrow/src/table.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "./table.h" // NOLINT(build/include) 22 | 23 | using namespace lumagl::garrow; 24 | 25 | auto Table::ColumnNames() const -> std::vector { 26 | std::vector names; 27 | std::transform(this->_schema->fields().begin(), this->_schema->fields().end(), std::back_inserter(names), 28 | [](std::shared_ptr field) { return field->name(); }); 29 | return names; 30 | }; 31 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/garrow/src/util/arrow-utils.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef LUMAGL_GARROW_UTIL_ARROW_UTILS_H 22 | #define LUMAGL_GARROW_UTIL_ARROW_UTILS_H 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | namespace lumagl { 32 | namespace garrow { 33 | 34 | class Table; 35 | struct AttributeDescriptor; 36 | 37 | struct ColumnBuilder { 38 | using ColumnMapping = auto(const std::shared_ptr&) -> std::shared_ptr; 39 | 40 | ColumnBuilder(const std::shared_ptr& field, const std::function& mapColumn) 41 | : field{field}, mapColumn{mapColumn} {} 42 | 43 | std::shared_ptr field; 44 | std::function mapColumn; 45 | }; 46 | 47 | auto arrowTypeFromVertexFormat(wgpu::VertexFormat format) -> std::shared_ptr; 48 | auto vertexFormatFromArrowType(const std::shared_ptr& type) -> std::optional; 49 | 50 | auto transformTable(const std::shared_ptr& table, const std::vector& builders, 51 | wgpu::Device device) -> std::shared_ptr; 52 | 53 | } // namespace garrow 54 | } // namespace lumagl 55 | 56 | #endif // LUMAGL_GARROW_UTIL_ARROW_UTILS_H 57 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/garrow/src/util/webgpu-utils.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "./webgpu-utils.h" // NOLINT(build/include) 22 | 23 | #include 24 | 25 | namespace lumagl { 26 | namespace garrow { 27 | 28 | auto getVertexFormatSize(wgpu::VertexFormat format) -> size_t { 29 | // Based on https://gpuweb.github.io/gpuweb/#vertex-formats 30 | // uchar = unsigned 8-bit value 31 | // char = signed 8-bit value 32 | // ushort = unsigned 16-bit value 33 | // short = signed 16-bit value 34 | // half = half-precision 16-bit floating point value 35 | // float = 32-bit floating point value 36 | // uint = unsigned 32-bit integer value 37 | // int = signed 32-bit integer value 38 | 39 | using Format = wgpu::VertexFormat; 40 | switch (format) { 41 | case Format::UChar2: 42 | case Format::Char2: 43 | case Format::UChar2Norm: 44 | case Format::Char2Norm: 45 | return 2; 46 | case Format::UChar4: 47 | case Format::Char4: 48 | case Format::UChar4Norm: 49 | case Format::Char4Norm: 50 | case Format::UShort2: 51 | case Format::Short2: 52 | case Format::UShort2Norm: 53 | case Format::Short2Norm: 54 | case Format::Half2: 55 | case Format::Float: 56 | case Format::UInt: 57 | case Format::Int: 58 | return 4; 59 | case Format::UShort4: 60 | case Format::Short4: 61 | case Format::UShort4Norm: 62 | case Format::Short4Norm: 63 | case Format::Half4: 64 | case Format::Float2: 65 | case Format::UInt2: 66 | case Format::Int2: 67 | return 8; 68 | case Format::Float3: 69 | case Format::UInt3: 70 | case Format::Int3: 71 | return 12; 72 | case Format::Float4: 73 | case Format::UInt4: 74 | case Format::Int4: 75 | return 16; 76 | } 77 | throw std::logic_error("Invalid vertex format"); 78 | } 79 | 80 | } // namespace garrow 81 | } // namespace lumagl 82 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/garrow/src/util/webgpu-utils.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded, Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef LUMAGL_GARROW_UTIL_WEBGPU_UTILS_H 22 | #define LUMAGL_GARROW_UTIL_WEBGPU_UTILS_H 23 | 24 | #include 25 | 26 | namespace lumagl { 27 | namespace garrow { 28 | 29 | /// \brief Returns size of the given format in bytes. 30 | auto getVertexFormatSize(wgpu::VertexFormat format) -> size_t; 31 | 32 | } // namespace garrow 33 | } // namespace lumagl 34 | 35 | #endif // LUMAGL_GARROW_UTIL_WEBGPU_UTILS_H 36 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/garrow/test/util/arrow-utils-test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Unfolded Inc 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "luma.gl/garrow/src/util/arrow-utils.h" 22 | 23 | #include 24 | 25 | using namespace lumagl::garrow; 26 | 27 | namespace { 28 | 29 | /// \brief LineLayer test suite. 30 | class ArrowUtilsTestSuite : public ::testing::Test { 31 | protected: 32 | ArrowUtilsTestSuite() {} 33 | }; 34 | 35 | TEST_F(ArrowUtilsTestSuite, ArrowTypeFromWebGPUFormat) { 36 | EXPECT_EQ(arrowTypeFromVertexFormat(wgpu::VertexFormat::Int), arrow::int32()); 37 | EXPECT_EQ(arrowTypeFromVertexFormat(wgpu::VertexFormat::Float), arrow::float32()); 38 | 39 | auto float4Format = arrowTypeFromVertexFormat(wgpu::VertexFormat::Float4); 40 | EXPECT_EQ(float4Format->id(), arrow::Type::type::FIXED_SIZE_LIST); 41 | EXPECT_EQ(float4Format->child(0)->type()->id(), arrow::Type::type::FLOAT); 42 | } 43 | 44 | TEST_F(ArrowUtilsTestSuite, VertexFormatFromArrowType) { 45 | EXPECT_EQ(vertexFormatFromArrowType(arrow::int32()).value(), wgpu::VertexFormat::Int); 46 | EXPECT_EQ(vertexFormatFromArrowType(arrow::float32()).value(), wgpu::VertexFormat::Float); 47 | EXPECT_EQ(vertexFormatFromArrowType(arrow::fixed_size_list(arrow::float32(), 4)).value(), wgpu::VertexFormat::Float4); 48 | EXPECT_EQ(vertexFormatFromArrowType(arrow::fixed_size_list(arrow::float32(), 5)), std::nullopt); 49 | } 50 | 51 | } // anonymous namespace 52 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/webgpu.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef LUMAGL_WEBGPU_H 22 | #define LUMAGL_WEBGPU_H 23 | 24 | #include 25 | 26 | #include "./webgpu/src/combo-render-pipeline-descriptor.h" 27 | #include "./webgpu/src/shaderc-utils.h" 28 | #include "./webgpu/src/swap-chain-utils.h" 29 | #include "./webgpu/src/webgpu-constants.h" 30 | #include "./webgpu/src/webgpu-helpers.h" 31 | #include "./webgpu/src/webgpu-utils.h" 32 | 33 | #if defined(LUMAGL_USES_GLFW) 34 | #include "./webgpu/src/backends/glfw/backend-binding.h" 35 | #endif 36 | 37 | #endif // LUMAGL_WEBGPU_H 38 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/webgpu/src/backends/glfw/backend-binding.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | // Note: This file was inspired by the Dawn codebase at https://dawn.googlesource.com/dawn/ 22 | // Copyright 2017 The Dawn Authors http://www.apache.org/licenses/LICENSE-2.0 23 | 24 | #ifndef LUMAGL_WEBGPU_BACKENDS_GLFW_BACKEND_BINDING_H 25 | #define LUMAGL_WEBGPU_BACKENDS_GLFW_BACKEND_BINDING_H 26 | 27 | #include 28 | #include 29 | 30 | struct GLFWwindow; 31 | 32 | namespace lumagl { 33 | namespace utils { 34 | namespace glfw { 35 | 36 | class BackendBinding { 37 | public: 38 | virtual ~BackendBinding() = default; 39 | 40 | virtual uint64_t GetSwapChainImplementation() = 0; 41 | virtual WGPUTextureFormat GetPreferredSwapChainTextureFormat() = 0; 42 | 43 | protected: 44 | BackendBinding(GLFWwindow* window, WGPUDevice device); 45 | 46 | GLFWwindow* mWindow{nullptr}; 47 | WGPUDevice mDevice{nullptr}; 48 | }; 49 | 50 | void DiscoverAdapter(dawn_native::Instance* instance, GLFWwindow* window, wgpu::BackendType type); 51 | BackendBinding* CreateBinding(wgpu::BackendType type, GLFWwindow* window, WGPUDevice device); 52 | 53 | } // namespace glfw 54 | } // namespace utils 55 | } // namespace lumagl 56 | 57 | #endif // LUMAGL_WEBGPU_BACKENDS_GLFW_BACKEND_BINDING_H 58 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/webgpu/src/backends/glfw/d3d12-binding.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | // Note: This file was inspired by the Dawn codebase at https://dawn.googlesource.com/dawn/ 22 | // Copyright 2017 The Dawn Authors http://www.apache.org/licenses/LICENSE-2.0 23 | 24 | // Ignore documentation warnings coming from glfw3.h 25 | #pragma clang diagnostic push 26 | #pragma clang diagnostic ignored "-Wdocumentation" 27 | #include 28 | #pragma clang diagnostic pop 29 | #include 30 | #define GLFW_EXPOSE_NATIVE_WIN32 31 | #include 32 | 33 | #include 34 | 35 | #include "./backend-binding.h" 36 | #include "probe.gl/core.h" 37 | 38 | namespace lumagl { 39 | namespace utils { 40 | namespace glfw { 41 | 42 | class D3D12Binding : public BackendBinding { 43 | public: 44 | D3D12Binding(GLFWwindow* window, WGPUDevice device) : BackendBinding(window, device) {} 45 | 46 | uint64_t GetSwapChainImplementation() override { 47 | if (mSwapchainImpl.userData == nullptr) { 48 | HWND win32Window = glfwGetWin32Window(mWindow); 49 | mSwapchainImpl = dawn_native::d3d12::CreateNativeSwapChainImpl(mDevice, win32Window); 50 | } 51 | return reinterpret_cast(&mSwapchainImpl); 52 | } 53 | 54 | WGPUTextureFormat GetPreferredSwapChainTextureFormat() override { 55 | ASSERT(mSwapchainImpl.userData != nullptr); 56 | return dawn_native::d3d12::GetNativeSwapChainPreferredFormat(&mSwapchainImpl); 57 | } 58 | 59 | private: 60 | DawnSwapChainImplementation mSwapchainImpl = {}; 61 | }; 62 | 63 | BackendBinding* CreateD3D12Binding(GLFWwindow* window, WGPUDevice device) { return new D3D12Binding(window, device); } 64 | 65 | } // namespace glfw 66 | } // namespace utils 67 | } // namespace lumagl 68 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/webgpu/src/backends/glfw/null-binding.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | // Note: This file was inspired by the Dawn codebase at https://dawn.googlesource.com/dawn/ 22 | // Copyright 2017 The Dawn Authors http://www.apache.org/licenses/LICENSE-2.0 23 | 24 | #include 25 | 26 | #include "./backend-binding.h" 27 | #include "dawn_native/NullBackend.h" 28 | #include "probe.gl/core.h" 29 | 30 | namespace lumagl { 31 | namespace utils { 32 | namespace glfw { 33 | 34 | class NullBinding : public BackendBinding { 35 | public: 36 | NullBinding(GLFWwindow* window, WGPUDevice device) : BackendBinding(window, device) {} 37 | 38 | uint64_t GetSwapChainImplementation() override { 39 | if (mSwapchainImpl.userData == nullptr) { 40 | mSwapchainImpl = dawn_native::null::CreateNativeSwapChainImpl(); 41 | } 42 | return reinterpret_cast(&mSwapchainImpl); 43 | } 44 | WGPUTextureFormat GetPreferredSwapChainTextureFormat() override { return WGPUTextureFormat_RGBA8Unorm; } 45 | 46 | private: 47 | DawnSwapChainImplementation mSwapchainImpl = {}; 48 | }; 49 | 50 | BackendBinding* CreateNullBinding(GLFWwindow* window, WGPUDevice device) { return new NullBinding(window, device); } 51 | 52 | } // namespace glfw 53 | } // namespace utils 54 | } // namespace lumagl 55 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/webgpu/src/backends/glfw/opengl-binding.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | // Note: This file was inspired by the Dawn codebase at https://dawn.googlesource.com/dawn/ 22 | // Copyright 2017 The Dawn Authors http://www.apache.org/licenses/LICENSE-2.0 23 | 24 | // Ignore documentation warnings coming from glfw3.h 25 | #pragma clang diagnostic push 26 | #pragma clang diagnostic ignored "-Wdocumentation" 27 | #include 28 | #pragma clang diagnostic pop 29 | #include 30 | #include 31 | 32 | #include 33 | 34 | #include "./backend-binding.h" 35 | #include "luma.gl/core.h" 36 | 37 | namespace lumagl { 38 | namespace utils { 39 | namespace glfw { 40 | 41 | class OpenGLBinding : public BackendBinding { 42 | public: 43 | OpenGLBinding(GLFWwindow* window, WGPUDevice device) : BackendBinding(window, device) {} 44 | 45 | uint64_t GetSwapChainImplementation() override { 46 | if (mSwapchainImpl.userData == nullptr) { 47 | mSwapchainImpl = dawn_native::opengl::CreateNativeSwapChainImpl( 48 | mDevice, [](void* userdata) { glfwSwapBuffers(static_cast(userdata)); }, mWindow); 49 | } 50 | return reinterpret_cast(&mSwapchainImpl); 51 | } 52 | 53 | WGPUTextureFormat GetPreferredSwapChainTextureFormat() override { 54 | return dawn_native::opengl::GetNativeSwapChainPreferredFormat(&mSwapchainImpl); 55 | } 56 | 57 | private: 58 | DawnSwapChainImplementation mSwapchainImpl = {}; 59 | }; 60 | 61 | BackendBinding* CreateOpenGLBinding(GLFWwindow* window, WGPUDevice device) { return new OpenGLBinding(window, device); } 62 | 63 | } // namespace glfw 64 | } // namespace utils 65 | } // namespace lumagl 66 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/webgpu/src/backends/glfw/vulkan-binding.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | // Note: This file was inspired by the Dawn codebase at https://dawn.googlesource.com/dawn/ 22 | // Copyright 2017 The Dawn Authors http://www.apache.org/licenses/LICENSE-2.0 23 | 24 | #include 25 | // Include GLFW after VulkanBackend so that it declares the Vulkan-specific functions 26 | // Ignore documentation warnings coming from glfw3.h 27 | #pragma clang diagnostic push 28 | #pragma clang diagnostic ignored "-Wdocumentation" 29 | #include 30 | #pragma clang diagnostic pop 31 | 32 | #include 33 | 34 | #include "./backend-binding.h" 35 | 36 | namespace lumagl { 37 | namespace utils { 38 | namespace glfw { 39 | 40 | class VulkanBinding : public BackendBinding { 41 | public: 42 | VulkanBinding(GLFWwindow* window, WGPUDevice device) : BackendBinding(window, device) {} 43 | 44 | uint64_t GetSwapChainImplementation() override { 45 | if (mSwapchainImpl.userData == nullptr) { 46 | VkSurfaceKHR surface = VK_NULL_HANDLE; 47 | if (glfwCreateWindowSurface(dawn_native::vulkan::GetInstance(mDevice), mWindow, nullptr, &surface) != 48 | VK_SUCCESS) { 49 | ASSERT(false); 50 | } 51 | 52 | mSwapchainImpl = dawn_native::vulkan::CreateNativeSwapChainImpl(mDevice, surface); 53 | } 54 | return reinterpret_cast(&mSwapchainImpl); 55 | } 56 | WGPUTextureFormat GetPreferredSwapChainTextureFormat() override { 57 | ASSERT(mSwapchainImpl.userData != nullptr); 58 | return dawn_native::vulkan::GetNativeSwapChainPreferredFormat(&mSwapchainImpl); 59 | } 60 | 61 | private: 62 | DawnSwapChainImplementation mSwapchainImpl = {}; 63 | }; 64 | 65 | BackendBinding* CreateVulkanBinding(GLFWwindow* window, WGPUDevice device) { return new VulkanBinding(window, device); } 66 | 67 | } // namespace glfw 68 | } // namespace utils 69 | } // namespace lumagl 70 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/webgpu/src/backends/metal-binding.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef LUMAGL_WEBGPU_BACKENDS_METAL_BINDING_H 22 | #define LUMAGL_WEBGPU_BACKENDS_METAL_BINDING_H 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #ifdef __OBJC__ 29 | @class MTKView; 30 | #else 31 | using MTKView = void*; 32 | #endif 33 | 34 | namespace lumagl { 35 | namespace util { 36 | 37 | class MetalBinding { 38 | public: 39 | MetalBinding(MTKView* view, const wgpu::Device device) : _view{view}, _device{device} {} 40 | 41 | auto GetSwapChainImplementation() -> uint64_t; 42 | WGPUTextureFormat GetPreferredSwapChainTextureFormat() { return WGPUTextureFormat_BGRA8Unorm; } 43 | 44 | private: 45 | DawnSwapChainImplementation _swapchainImpl = {}; 46 | 47 | MTKView* _view; 48 | wgpu::Device _device; 49 | }; 50 | 51 | } // namespace util 52 | } // namespace lumagl 53 | 54 | #endif // LUMAGL_WEBGPU_BACKENDS_METAL_BINDING_H 55 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/webgpu/src/combo-render-pipeline-descriptor.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Dawn Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef LUMAGL_WEBGPU_COMBORENDERPIPELINEDESCRIPTOR_H 16 | #define LUMAGL_WEBGPU_COMBORENDERPIPELINEDESCRIPTOR_H 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include "./webgpu-constants.h" 23 | 24 | namespace lumagl { 25 | namespace utils { 26 | 27 | class ComboVertexStateDescriptor : public wgpu::VertexStateDescriptor { 28 | public: 29 | ComboVertexStateDescriptor(); 30 | 31 | std::array cVertexBuffers; 32 | std::array cAttributes; 33 | }; 34 | 35 | class ComboRenderPipelineDescriptor : public wgpu::RenderPipelineDescriptor { 36 | public: 37 | explicit ComboRenderPipelineDescriptor(const wgpu::Device& device); 38 | 39 | ComboRenderPipelineDescriptor(const ComboRenderPipelineDescriptor&) = delete; 40 | ComboRenderPipelineDescriptor& operator=(const ComboRenderPipelineDescriptor&) = delete; 41 | ComboRenderPipelineDescriptor(ComboRenderPipelineDescriptor&&) = delete; 42 | ComboRenderPipelineDescriptor& operator=(ComboRenderPipelineDescriptor&&) = delete; 43 | 44 | wgpu::ProgrammableStageDescriptor cFragmentStage; 45 | 46 | ComboVertexStateDescriptor cVertexState; 47 | wgpu::RasterizationStateDescriptor cRasterizationState; 48 | std::array cColorStates; 49 | wgpu::DepthStencilStateDescriptor cDepthStencilState; 50 | }; 51 | 52 | } // namespace utils 53 | } // namespace lumagl 54 | 55 | #endif // LUMAGL_WEBGPU_COMBORENDERPIPELINEDESCRIPTOR_H 56 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/webgpu/src/shaderc-utils.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | // Note: This file was inspired by the Dawn codebase at https://dawn.googlesource.com/dawn/ 22 | // Copyright 2017 The Dawn Authors http://www.apache.org/licenses/LICENSE-2.0 23 | 24 | #ifndef LUMAGL_WEBGPU_SHADERC_UTILS_H 25 | #define LUMAGL_WEBGPU_SHADERC_UTILS_H 26 | 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | #include "./webgpu-constants.h" 33 | 34 | namespace lumagl { 35 | namespace utils { 36 | 37 | enum class SingleShaderStage { Vertex, Fragment, Compute }; 38 | 39 | wgpu::ShaderModule createShaderModule(const wgpu::Device& device, SingleShaderStage stage, const char* source); 40 | wgpu::ShaderModule createShaderModuleFromASM(const wgpu::Device& device, const char* source); 41 | 42 | } // namespace utils 43 | } // namespace lumagl 44 | 45 | #endif // LUMAGL_WEBGPU_SHADERC_UTILS_H 46 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/webgpu/src/swap-chain-utils.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | // Note: This file was inspired by the Dawn codebase at https://dawn.googlesource.com/dawn/ 22 | // Copyright 2017 The Dawn Authors http://www.apache.org/licenses/LICENSE-2.0 23 | 24 | #ifndef LUMAGL_WEBGPU_SWAPCHAINUTILS_H_ 25 | #define LUMAGL_WEBGPU_SWAPCHAINUTILS_H_ 26 | 27 | #include "dawn/dawn_wsi.h" 28 | 29 | template 30 | DawnSwapChainImplementation CreateSwapChainImplementation(T* swapChain) { 31 | DawnSwapChainImplementation impl = {}; 32 | impl.userData = swapChain; 33 | impl.Init = [](void* userData, void* wsiContext) { 34 | auto* ctx = static_cast(wsiContext); 35 | reinterpret_cast(userData)->Init(ctx); 36 | }; 37 | impl.Destroy = [](void* userData) { delete reinterpret_cast(userData); }; 38 | impl.Configure = [](void* userData, WGPUTextureFormat format, WGPUTextureUsage allowedUsage, uint32_t width, 39 | uint32_t height) { 40 | return static_cast(userData)->Configure(format, allowedUsage, width, height); 41 | }; 42 | impl.GetNextTexture = [](void* userData, DawnSwapChainNextTexture* nextTexture) { 43 | return static_cast(userData)->GetNextTexture(nextTexture); 44 | }; 45 | impl.Present = [](void* userData) { return static_cast(userData)->Present(); }; 46 | return impl; 47 | } 48 | 49 | #endif // LUMAGL_WEBGPU_SWAPCHAINUTILS_H_ 50 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/webgpu/src/webgpu-utils.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | /// \file This file contains utilities for the WebGPU C++ API 22 | 23 | #include "./webgpu-utils.h" // NOLINT(build/include) 24 | 25 | #include 26 | 27 | namespace lumagl { 28 | namespace utils { 29 | 30 | auto getDefaultWebGPUBackendType() -> wgpu::BackendType { 31 | #if defined(LUMAGL_ENABLE_BACKEND_D3D12) 32 | return wgpu::BackendType::D3D12; 33 | #elif defined(LUMAGL_ENABLE_BACKEND_METAL) 34 | return wgpu::BackendType::Metal; 35 | #elif defined(LUMAGL_ENABLE_BACKEND_VULKAN) 36 | return wgpu::BackendType::Vulkan; 37 | #elif defined(LUMAGL_ENABLE_BACKEND_OPENGL) 38 | return wgpu::BackendType::OpenGL; 39 | #elif defined(LUMAGL_ENABLE_BACKEND_NULL) 40 | return wgpu::BackendType::Null; 41 | #else 42 | #error No backends enabled 43 | #endif 44 | } 45 | 46 | const std::map nameToBackendTypeMap = { 47 | {"d3d12", wgpu::BackendType::D3D12}, {"metal", wgpu::BackendType::Metal}, {"null", wgpu::BackendType::Null}, 48 | {"opengl", wgpu::BackendType::OpenGL}, {"vulkan", wgpu::BackendType::Vulkan}, 49 | }; 50 | 51 | auto getWebGPUBackendType(const std::string &backendName) -> wgpu::BackendType { 52 | if (nameToBackendTypeMap.count(backendName) == 0) { 53 | throw std::runtime_error("invalid backend name (opengl, metal, d3d12, null, vulkan)"); 54 | } 55 | return nameToBackendTypeMap.at(backendName); 56 | } 57 | 58 | std::map errorTypeToNameMap = { 59 | {WGPUErrorType_Validation, "Validation"}, 60 | {WGPUErrorType_OutOfMemory, "Out of memory"}, 61 | {WGPUErrorType_Unknown, "Unknown"}, 62 | {WGPUErrorType_DeviceLost, "Device lost"}, 63 | }; 64 | 65 | auto getWebGPUErrorName(WGPUErrorType errorType) -> const char * { return errorTypeToNameMap[errorType]; } 66 | 67 | } // namespace utils 68 | } // namespace lumagl 69 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/webgpu/src/webgpu-utils.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef LUMAGL_WEBGPU_UTILS_H 22 | #define LUMAGL_WEBGPU_UTILS_H 23 | 24 | #include 25 | 26 | #include 27 | 28 | namespace lumagl { 29 | namespace utils { 30 | 31 | /// \brief Get the default WebGPU/Dawn backend type for this platform 32 | /// Default to D3D12, Metal, Vulkan, OpenGL in that order as D3D12 and Metal are the preferred on 33 | /// their respective platforms, and Vulkan is preferred to OpenGL 34 | auto getDefaultWebGPUBackendType() -> wgpu::BackendType; 35 | 36 | /// \brief Get a WebGPU/Dawn backend type from a string 37 | auto getWebGPUBackendType(const std::string &backendType) -> wgpu::BackendType; 38 | 39 | /// \brief Get a string representation of a WebGPU Error 40 | auto getWebGPUErrorName(WGPUErrorType errorType) -> const char *; 41 | 42 | } // namespace utils 43 | } // namespace lumagl 44 | 45 | #endif // LUMAGL_WEBGPU_UTILS_H 46 | -------------------------------------------------------------------------------- /cpp/modules/luma.gl/webgpu/test/webgpu-test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "luma.gl/webgpu.h" 22 | -------------------------------------------------------------------------------- /cpp/modules/math.gl/core.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef MATHGL_CORE 22 | #define MATHGL_CORE 23 | 24 | // TODO(ib@unfolded.ai): Split into matrix.h, vector.h etc? 25 | #include "./core/src/core.h" 26 | #include "./core/src/rectangle.h" 27 | 28 | #endif // MATHGL_CORE 29 | -------------------------------------------------------------------------------- /cpp/modules/math.gl/core/src/rectangle.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Unfolded Inc 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef MATHGL_CORE_RECTANGLE_H 22 | #define MATHGL_CORE_RECTANGLE_H 23 | 24 | #include 25 | 26 | namespace mathgl { 27 | 28 | template 29 | class Rectangle { 30 | public: 31 | Rectangle() : x(0), y(0), w(0), h(0) {} 32 | Rectangle(coord x1, coord y1, coord w1, coord h1) : x(x1), y(y1), w(w1), h(h1) {} 33 | 34 | auto operator==(const Rectangle &r) const -> bool { return x == r.x && y == r.y && w == r.w && h == r.h; } 35 | 36 | coord x, y, w, h; 37 | }; 38 | 39 | template 40 | auto operator<<(std::ostream &os, const Rectangle &r) -> std::ostream & { 41 | os << "Rect(x=" << r.x << ", y=" << r.y << ", width=" << r.w << ", height=" << r.h << ")"; 42 | return os; 43 | } 44 | 45 | } // namespace mathgl 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /cpp/modules/math.gl/core/test/core-test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Unfolded Inc 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "math.gl/core.h" 22 | 23 | #include 24 | 25 | namespace { 26 | 27 | /// \brief The fixture for testing core math classes. 28 | class MathTest : public ::testing::Test { 29 | protected: 30 | MathTest() {} 31 | }; 32 | 33 | TEST_F(MathTest, Vector3Sum) { 34 | mathgl::Vector3 vector1{0.1, 0.3, 0.5}; 35 | mathgl::Vector3 vector2{0.6, 0.2, 0.1}; 36 | 37 | mathgl::Vector3 vectorSum = vector1 + vector2; 38 | 39 | EXPECT_FLOAT_EQ(vectorSum.x, 0.7); 40 | EXPECT_FLOAT_EQ(vectorSum.y, 0.5); 41 | EXPECT_FLOAT_EQ(vectorSum.z, 0.6); 42 | } 43 | 44 | } // namespace 45 | -------------------------------------------------------------------------------- /cpp/modules/math.gl/web-mercator.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Unfolded Inc 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "./web-mercator/src/web-mercator-utils.h" 22 | -------------------------------------------------------------------------------- /cpp/modules/probe.gl/core.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PROBEGL_CORE 22 | #define PROBEGL_CORE 23 | 24 | #include "./core/src/assert.h" 25 | #include "./core/src/compiler.h" 26 | #include "./core/src/error.h" 27 | #include "./core/src/log.h" 28 | #include "./core/src/platform.h" 29 | #include "./core/src/system-utils.h" 30 | #include "./core/src/timer.h" 31 | 32 | #endif // PROBEGL_CORE 33 | -------------------------------------------------------------------------------- /cpp/modules/probe.gl/core/src/assert.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | // Note: This file was inspired by the Dawn codebase at https://dawn.googlesource.com/dawn/ 22 | // Copyright 2017 The Dawn Authors http://www.apache.org/licenses/LICENSE-2.0 23 | 24 | #include "./assert.h" // NOLINT(build/include) 25 | 26 | #include 27 | 28 | #include "./compiler.h" 29 | #include "./log.h" 30 | 31 | void HandleAssertionFailure(const char* file, const char* function, int line, const char* condition) { 32 | probegl::ErrorLog() << "Assertion failure at " << file << ":" << line << " (" << function << "): " << condition; 33 | #if defined(PROBEGL_ABORT_ON_ASSERT) 34 | abort(); 35 | #else 36 | PROBEGL_BREAKPOINT(); 37 | #endif 38 | } 39 | -------------------------------------------------------------------------------- /cpp/modules/probe.gl/core/src/error.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "./error.h" // NOLINT(build/include) 22 | 23 | namespace probegl { 24 | 25 | void catchError(std::function expression, Error& error) noexcept { 26 | error.reset(); 27 | 28 | try { 29 | expression(); 30 | } catch (const std::exception& ex) { 31 | error = ex.what(); 32 | } catch (...) { 33 | error = "Operation failed with unknown error"; 34 | } 35 | } 36 | 37 | } // namespace probegl 38 | -------------------------------------------------------------------------------- /cpp/modules/probe.gl/core/src/error.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PROBEGL_CORE_ERROR_H 22 | #define PROBEGL_CORE_ERROR_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | namespace probegl { 30 | 31 | using Error = std::optional; 32 | 33 | template 34 | auto catchError(std::function()> expression, Error& error) noexcept -> std::shared_ptr { 35 | error.reset(); 36 | 37 | try { 38 | return expression(); 39 | } catch (const std::exception& ex) { 40 | error = ex.what(); 41 | return nullptr; 42 | } catch (...) { 43 | error = "Operation failed with unknown error"; 44 | return nullptr; 45 | } 46 | } 47 | 48 | template 49 | auto catchError(std::function expression, Error& error) noexcept -> std::shared_ptr { 50 | return catchError([expression]() { return std::make_shared(expression()); }, error); 51 | } 52 | 53 | void catchError(std::function expression, Error& error) noexcept; 54 | 55 | } // namespace probegl 56 | 57 | #endif // PROBEGL_CORE_ERROR_H 58 | -------------------------------------------------------------------------------- /cpp/modules/probe.gl/core/src/platform.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | // Note: This file was inspired by the Dawn codebase at https://dawn.googlesource.com/dawn/ 22 | // Copyright 2017 The Dawn Authors http://www.apache.org/licenses/LICENSE-2.0 23 | 24 | #ifndef PROBEGL_CORE_PLATFORM_H 25 | #define PROBEGL_CORE_PLATFORM_H 26 | 27 | // TODO(ib) - something in the include chain sets _WIN32, comment out for now 28 | // #if defined(_WIN32) || defined(_WIN64) 29 | // #define PROBEGL_PLATFORM_WINDOWS 1 30 | // #elif defined(__linux__) 31 | 32 | #if defined(__linux__) 33 | #define PROBEGL_PLATFORM_LINUX 1 34 | #define PROBEGL_PLATFORM_POSIX 1 35 | #if defined(__ANDROID__) 36 | #define PROBEGL_PLATFORM_ANDROID 1 37 | #endif 38 | 39 | #elif defined(__APPLE__) 40 | #define PROBEGL_PLATFORM_APPLE 1 41 | #define PROBEGL_PLATFORM_POSIX 1 42 | #include 43 | #if TARGET_OS_IPHONE 44 | #define PROBEGL_PLATFORM_IOS 45 | #elif TARGET_OS_MAC 46 | #define PROBEGL_PLATFORM_MACOS 47 | #else 48 | #error "Unsupported Apple platform." 49 | #endif 50 | 51 | #elif defined(__Fuchsia__) 52 | #define PROBEGL_PLATFORM_FUCHSIA 1 53 | #define PROBEGL_PLATFORM_POSIX 1 54 | 55 | #else 56 | #error "Unsupported platform." 57 | #endif 58 | 59 | #if defined(_WIN64) || defined(__aarch64__) || defined(__x86_64__) || defined(__mips64__) || defined(__s390x__) || \ 60 | defined(__PPC64__) 61 | #define PROBEGL_PLATFORM_64_BIT 1 62 | static_assert(sizeof(sizeof(char)) == 8, "Expect sizeof(size_t) == 8"); 63 | #elif defined(_WIN32) || defined(__arm__) || defined(__i386__) || defined(__mips32__) || defined(__s390__) 64 | #define PROBEGL_PLATFORM_32_BIT 1 65 | static_assert(sizeof(sizeof(char)) == 4, "Expect sizeof(size_t) == 4"); 66 | #else 67 | #error "Unsupported platform" 68 | #endif 69 | 70 | #endif // PROBEGL_CORE_PLATFORM_H 71 | -------------------------------------------------------------------------------- /cpp/modules/probe.gl/core/src/system-utils.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | // Note: This file was inspired by the Dawn codebase at https://dawn.googlesource.com/dawn/ 22 | // Copyright 2017 The Dawn Authors http://www.apache.org/licenses/LICENSE-2.0 23 | 24 | #include "./system-utils.h" // NOLINT(build/include) 25 | 26 | #include "./platform.h" 27 | 28 | #if defined(PROBEGL_PLATFORM_POSIX) 29 | #include 30 | #elif defined(PROBEGL_PLATFORM_WINDOWS) 31 | #include 32 | #error "Unsupported platform." 33 | #endif 34 | 35 | #if defined(PROBEGL_PLATFORM_POSIX) 36 | 37 | void probegl::uSleep(unsigned int usecs) { usleep(usecs); } 38 | 39 | #elif defined(PROBGL_PLATFORM_WINDOWS) 40 | 41 | void probegl::uSleep(unsigned int usecs) { Sleep(static_cast(usecs / 1000)); } 42 | 43 | #else 44 | #error "Implement uSleep for your platform." 45 | #endif 46 | -------------------------------------------------------------------------------- /cpp/modules/probe.gl/core/src/system-utils.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Unfolded Inc. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | // Note: This file was inspired by the Dawn codebase at https://dawn.googlesource.com/dawn/ 22 | // Copyright 2017 The Dawn Authors http://www.apache.org/licenses/LICENSE-2.0 23 | 24 | #ifndef PROBEGL_CORE_SYSTEMUTILS_H 25 | #define PROBEGL_CORE_SYSTEMUTILS_H 26 | 27 | namespace probegl { 28 | 29 | void uSleep(unsigned int usecs); 30 | 31 | } // namespace probegl 32 | 33 | #endif // PROBEGL_CORE_SYSTEMUTILS_H 34 | -------------------------------------------------------------------------------- /cpp/modules/probe.gl/core/src/timer.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Dawn Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef PROBEGL_CORE_TIMER_H 16 | #define PROBEGL_CORE_TIMER_H 17 | 18 | #include "./platform.h" 19 | 20 | #if defined(PROBEGL_PLATFORM_APPLE) 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #elif defined(PROBEGL_PLATFORM_POSIX) 27 | 28 | #include 29 | #include 30 | 31 | #elif defined(PROBEGL_PLATFORM_WINDOWS) 32 | 33 | #include 34 | 35 | #else 36 | 37 | #warning "No timer implementation for current platform" 38 | 39 | #endif 40 | 41 | namespace probegl { 42 | 43 | class Timer { 44 | public: 45 | virtual ~Timer() {} 46 | 47 | // Timer functionality: Use start() and stop() to record the duration and use 48 | // getElapsedTime() to query that duration. If getElapsedTime() is called in between, it 49 | // will report the elapsed time since start(). 50 | void start(); 51 | void stop(); 52 | double getElapsedTime() const; 53 | 54 | // Timestamp functionality: Use getAbsoluteTime() to get an absolute time with an unknown 55 | // origin. This time moves forward regardless of start()/stop(). 56 | double getAbsoluteTime(); 57 | 58 | private: 59 | bool running{false}; 60 | #if defined(PROBEGL_PLATFORM_APPLE) 61 | // APPLE 62 | uint64_t startTime; 63 | uint64_t stopTime; 64 | double secondCoeff{0}; 65 | auto _getSecondCoeff() -> double; 66 | #elif defined(PROBEGL_PLATFORM_POSIX) 67 | // POSIX 68 | uint64_t startTimeNs; 69 | uint64_t stopTimeNs; 70 | #elif defined(PROBEGL_PLATFORM_WINDOWS) 71 | // WINDOWS 72 | LONGLONG startTime; 73 | LONGLONG stopTime; 74 | LONGLONG frequency{0}; 75 | #endif 76 | }; 77 | 78 | } // namespace probegl 79 | 80 | #endif // PROBEGL_CORE_TIMER_H 81 | -------------------------------------------------------------------------------- /cpp/modules/probe.gl/core/test/timer-test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Unfolded Inc 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include 22 | 23 | #include 24 | 25 | #include "probe.gl/core.h" 26 | 27 | using namespace probegl; 28 | 29 | TEST(ProbeGL, Timer) { 30 | Timer timer; 31 | timer.start(); 32 | uSleep(10); 33 | timer.stop(); 34 | EXPECT_GE(timer.getElapsedTime(), 0); 35 | } 36 | -------------------------------------------------------------------------------- /cpp/tests/main.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Unfolded Inc 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include 22 | 23 | int main(int argc, char **argv) { 24 | // Runs all the tests specified in *-test.cc files that have been registered using TEST or TEST_F macros 25 | ::testing::InitGoogleTest(&argc, argv); 26 | return RUN_ALL_TESTS(); 27 | } 28 | -------------------------------------------------------------------------------- /deck.gl-native.xcodeproj/xcshareddata/xcschemes/make.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 44 | 50 | 51 | 57 | 58 | 59 | 60 | 62 | 63 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /docs/dev/coding-style.md: -------------------------------------------------------------------------------- 1 | # Style Guide 2 | 3 | ### **deck.gl-native** follows [Google C++ Style Guide]([https://google.github.io/styleguide/cppguide.html](https://google.github.io/styleguide/cppguide.html)) with a few notable updates: 4 | 5 | - [Trailing Return Syntax](https://google.github.io/styleguide/cppguide.html#trailing_return) - we make use of trailing return syntax across the board 6 | - [Exceptions](https://google.github.io/styleguide/cppguide.html#Exceptions) - our code is exception-tolerant, so it is encouraged to use exceptions wherever it is appropriate. Top-level API provides exception-safe implementations for core functionality 7 | - [File Names](https://google.github.io/styleguide/cppguide.html#File_Names) - file names should use hyphens (`-`) and not underscores (`_`) as delimiters 8 | - [Variable Names](https://google.github.io/styleguide/cppguide.html#Variable_Names) - we use camelCase and not snake_case for variable names. Private variables use a leading underscore instead of a trailing underscore 9 | - [Constant_Names](https://google.github.io/styleguide/cppguide.html#Constant_Names) - constants are declared as UPPERCASE_UNDERSCORED 10 | - [Function Names](https://google.github.io/styleguide/cppguide.html#Function_Names) - function names use camelCase, and do not start with a capitalized case 11 | - [Enumerator_Names](https://google.github.io/styleguide/cppguide.html#Enumerator_Names) - enumerator values are to use the same format as constant names 12 | - [Line Length](https://google.github.io/styleguide/cppguide.html#Line_Length) - allowed line length is 120 characters, up from 80 13 | - [Pointer_and_Reference_Expressions](https://google.github.io/styleguide/cppguide.html#Pointer_and_Reference_Expressions) - */& should be next to type name i.e `int* variable` 14 | 15 | 16 | ### Assertions and Exceptions 17 | 18 | - `throw std::logic_error(string)` should be used for when a coding error is detected 19 | - `throw std::runtime_error(string)` should be used for when there is a validation error 20 | -------------------------------------------------------------------------------- /docs/dev/visual-studio-code.md: -------------------------------------------------------------------------------- 1 | # Visual Studio Code development instructions 2 | 3 | Our preferred IDE is VS Code. 4 | 5 | ## To setup debugging 6 | 7 | These instructions were written for Linux, where the key binding is CTRL+SHIFT+P. 8 | On Mac OSX it's probably something like COMMAND+SHIFT+P. 9 | 10 | * Install the "C/C++" and "CMake Tools" extensions, both from Microsoft. 11 | * Open the deck.gl-native folder and accept the suggestions. 12 | * CTRL+SHIFT+P "CMake: Scan for kits" 13 | * CTRL+SHIFT+P "CMake: Edit User-Local CMake Kits" 14 | * Add a kit based on the highest version of Clang already present: 15 | 16 | Relace the C and CXX with the appropriate paths. Replace the toolchainFile 17 | with the path to the toolchain file from your vcpkg installation. 18 | ``` 19 | { 20 | "name": "Clang 6.0.0 with VCPKG", 21 | "compilers": { 22 | "C": "/usr/bin/clang-6.0", 23 | "CXX": "/usr/bin/clang++-6.0" 24 | }, 25 | "toolchainFile": "/scripts/buildsystems/vcpkg.cmake" 26 | }, 27 | ``` 28 | 29 | * CTRL+SHIFT+P "CMake: Select a Kit" 30 | * Select the name of the kit you added. 31 | * CTRL+SHIFT+P "CMake: Set Debug Target" 32 | * CTRL+SHIFT+P "CMake: Debug". Should build and launch the tests under debugger. 33 | -------------------------------------------------------------------------------- /scripts/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | git submodule update --init --recursive 4 | -------------------------------------------------------------------------------- /scripts/build-clang.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Note when switching compiler: `rm -fr build` 4 | 5 | cmake -S . -B build/clang -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ 6 | cmake --build build/clang -j 16 7 | build/clang/deckgl-bundle-tests 8 | -------------------------------------------------------------------------------- /scripts/build-cpplint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Note when switching compiler: `rm -fr build` 4 | 5 | cmake -S . -B build/cpplint -DCMAKE_C_COMPILER=gcc-9 -DCMAKE_CXX_COMPILER=g++-9 -DCMAKE_CXX_CPPLINT=cpplint 6 | cmake --build build/cpplint -j 16 7 | build/clang/deckgl-bundle-tests 8 | -------------------------------------------------------------------------------- /scripts/build-gcc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Note when switching compiler: `rm -fr build` 4 | 5 | cmake -S . -B build/gcc -DCMAKE_C_COMPILER=gcc-9 -DCMAKE_CXX_COMPILER=g++-9 6 | cmake --build build/gcc -j 16 7 | build/clang/deckgl-bundle-tests 8 | -------------------------------------------------------------------------------- /scripts/build-ios.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | # The following are paired together in order to form a build target 6 | declare -a archs=("arm64" "arm64e" "x86_64") 7 | declare -a sysroots=("iphoneos" "iphoneos" "iphonesimulator") 8 | declare -a deployment_targets=("12.0" "12.0" "13.0") 9 | 10 | install_dir="`pwd`/install" 11 | 12 | # Build for each architecture individually 13 | for i in $(seq 0 $((${#archs[@]}-1))) 14 | do 15 | cmake -S . -B build/${archs[$i]} -GXcode -DCMAKE_INSTALL_PREFIX=$install_dir/${archs[$i]} -DDECK_BUILD_EXAMPLES=OFF -DDECK_BUILD_TESTS=OFF -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_ARCHITECTURES=${archs[$i]} -DCMAKE_OSX_SYSROOT=${sysroots[$i]} -DCMAKE_OSX_DEPLOYMENT_TARGET=${deployment_targets[$i]} -DCMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH=NO -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED=NO -DCMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE=NO 16 | cmake --build build/${archs[$i]} --config Release --target install -j 16 17 | done 18 | 19 | # Copy over a set of frameworks we'll use as a base 20 | mkdir -p install/combined/lib 21 | cp -r install/${archs[0]}/lib/* install/combined/lib 22 | 23 | ## Declare the modules we're building, and iterate over them to combine the framework architectures 24 | declare -a modules=("deck.gl" "luma.gl" "loaders.gl" "math.gl" "probe.gl") 25 | for module in ${modules[@]} 26 | do 27 | command="lipo -create " 28 | for arch in ${archs[@]} 29 | do 30 | command="$command $install_dir/$arch/lib/$module.framework/$module " 31 | done 32 | command="$command -output $install_dir/combined/lib/$module.framework/$module" 33 | eval $command 34 | done 35 | -------------------------------------------------------------------------------- /scripts/coverage.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2018-2019 Unfolded, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # To invoke this script, use `bash coverage.sh `, 18 | # where `source-dir` corresponds to CMake source directory and `binary-dir` 19 | # corresponds to the CMake build directory. This script is used to run the 20 | # `coverage` target. In order to guarantee that `coverage` is only a valid 21 | # target in debug builds, we must know the build mode. However, CMake tries to 22 | # delay the selection of the build mode until the build itself. This allows 23 | # tools like Xcode to choose to build in debug mode or release mode without 24 | # rerunning CMake. In order to control the `coverage` target based on the build 25 | # mode, this script is regenerated whenever a new build mode is selected, 26 | # regardless of whether or not the `cmake` command is invoked again. 27 | # 28 | # Example: 29 | # 30 | # ``` 31 | # $ cmake -DCMAKE_BUILD_TYPE=Debug .. 32 | # $ xcodebuild -configuration Release # coverage.sh generated 33 | # $ xcodebuild -configuration Release # coverage.sh not regenerated 34 | # $ xcodebuild -configuration Debug # coverage.sh regenerated 35 | # ``` 36 | 37 | set -ex 38 | 39 | if [[ $> != 1 ]]; then 40 | echo "Cannot run coverage for non-debug build" 1>&2 41 | exit 1 42 | fi 43 | 44 | src_dir=${1:-"Missing source directory"} 45 | binary_dir=${2:-"Missing binary directory"} 46 | 47 | # Exclude the usual LCOV exclusion comment, and also 48 | # do not require branch coverage for assertions. 49 | br_exclusion='LCOV_EXCL_BR_LINE|assert\(' 50 | 51 | cd "${binary_dir}" 52 | lcov --rc lcov_branch_coverage=1 --rc "lcov_excl_br_line=$br_exclusion" --directory . --capture --output-file coverage.info 53 | lcov --rc lcov_branch_coverage=1 --rc "lcov_excl_br_line=$br_exclusion" --extract coverage.info "${src_dir}/cpp/src/*" --output-file coverage.cleaned.info 54 | genhtml --branch-coverage -o coverage coverage.cleaned.info --title 'deck.gl coverage' 55 | 56 | --------------------------------------------------------------------------------