├── .gitignore ├── InkingTextureLoader ├── CMakeLists.txt ├── TextureLoader │ ├── CMakeLists.txt │ └── Source │ │ ├── ColorSpace.h │ │ ├── Common.h │ │ ├── ITextureLoader.h │ │ ├── RefCounter.h │ │ ├── Texture.cpp │ │ ├── Texture.h │ │ ├── Texture2D.h │ │ ├── TextureLoadAsyncOperation.h │ │ ├── TextureLoadAsyncOperationState.h │ │ ├── TextureLoadMode.h │ │ ├── TextureLoaderD3D11.cpp │ │ ├── TextureLoaderD3D11.h │ │ ├── TextureLoaderOpenGLES.cpp │ │ ├── TextureLoaderOpenGLES.h │ │ ├── TextureLoaderOpenGLES2.h │ │ ├── TextureLoaderOpenGLES3.h │ │ ├── Typedef.h │ │ ├── UnityTextureLoader.cpp │ │ ├── UnityTextureLoader.h │ │ ├── UnityTextureLoaderExports.cpp │ │ └── UnityTextureLoaderExports.h ├── ThirdParty │ ├── UnityPluginAPI │ │ ├── IUnityEventQueue.h │ │ ├── IUnityGraphics.h │ │ ├── IUnityGraphicsD3D11.h │ │ ├── IUnityGraphicsD3D12.h │ │ ├── IUnityGraphicsMetal.h │ │ ├── IUnityGraphicsVulkan.h │ │ ├── IUnityInterface.h │ │ ├── IUnityProfilerCallbacks.h │ │ ├── IUnityRenderingExtensions.h │ │ ├── IUnityShaderCompilerAccess.h │ │ └── LICENSE.md │ └── stb_image │ │ ├── CMakeLists.txt │ │ └── source │ │ ├── stb.h │ │ ├── stb_c_lexer.h │ │ ├── stb_connected_components.h │ │ ├── stb_divide.h │ │ ├── stb_ds.h │ │ ├── stb_dxt.h │ │ ├── stb_easy_font.h │ │ ├── stb_herringbone_wang_tile.h │ │ ├── stb_image.h │ │ ├── stb_image_exports.cpp │ │ ├── stb_image_resize.h │ │ ├── stb_image_write.h │ │ ├── stb_include.h │ │ ├── stb_leakcheck.h │ │ ├── stb_perlin.h │ │ ├── stb_rect_pack.h │ │ ├── stb_sprintf.h │ │ ├── stb_textedit.h │ │ ├── stb_tilemap_editor.h │ │ ├── stb_truetype.h │ │ ├── stb_vorbis.c │ │ ├── stb_voxel_render.h │ │ └── stretchy_buffer.h └── build_android.bat ├── LICENSE ├── README.md └── UnityTextureLoader └── Assets ├── Inking.meta ├── Inking ├── TextureLoader.meta └── TextureLoader │ ├── Plugins.meta │ ├── Plugins │ ├── Android.meta │ ├── Android │ │ ├── libs.meta │ │ └── libs │ │ │ ├── arm64-v8a.meta │ │ │ ├── arm64-v8a │ │ │ ├── libInkingTextureLoader.so │ │ │ └── libInkingTextureLoader.so.meta │ │ │ ├── armeabi-v7a.meta │ │ │ └── armeabi-v7a │ │ │ ├── libInkingTextureLoader.so │ │ │ └── libInkingTextureLoader.so.meta │ ├── x86_64.meta │ └── x86_64 │ │ ├── InkingTextureLoader.dll │ │ └── InkingTextureLoader.dll.meta │ ├── Scripts.meta │ └── Scripts │ ├── Texture2D.cs │ ├── Texture2D.cs.meta │ ├── TextureLoadAsyncOperation.cs │ ├── TextureLoadAsyncOperation.cs.meta │ ├── TextureLoadAsyncOperationState.cs │ ├── TextureLoadAsyncOperationState.cs.meta │ ├── TextureLoadResult.cs │ ├── TextureLoadResult.cs.meta │ ├── TextureLoader.cs │ └── TextureLoader.cs.meta ├── Plugins.meta ├── Plugins ├── NativeGallery.meta └── NativeGallery │ ├── Android.meta │ ├── Android │ ├── NGCallbackHelper.cs │ ├── NGCallbackHelper.cs.meta │ ├── NGMediaReceiveCallbackAndroid.cs │ ├── NGMediaReceiveCallbackAndroid.cs.meta │ ├── NGPermissionCallbackAndroid.cs │ ├── NGPermissionCallbackAndroid.cs.meta │ ├── NativeGallery.aar │ └── NativeGallery.aar.meta │ ├── Editor.meta │ ├── Editor │ ├── NGPostProcessBuild.cs │ ├── NGPostProcessBuild.cs.meta │ ├── NativeGallery.Editor.asmdef │ └── NativeGallery.Editor.asmdef.meta │ ├── NativeGallery.Runtime.asmdef │ ├── NativeGallery.Runtime.asmdef.meta │ ├── NativeGallery.cs │ ├── NativeGallery.cs.meta │ ├── README.txt │ ├── README.txt.meta │ ├── iOS.meta │ └── iOS │ ├── NGMediaReceiveCallbackiOS.cs │ ├── NGMediaReceiveCallbackiOS.cs.meta │ ├── NGMediaSaveCallbackiOS.cs │ ├── NGMediaSaveCallbackiOS.cs.meta │ ├── NativeGallery.mm │ └── NativeGallery.mm.meta ├── Scenes.meta └── Scenes ├── TextureLoader.unity ├── TextureLoader.unity.meta ├── TextureLoaderTest.cs └── TextureLoaderTest.cs.meta /.gitignore: -------------------------------------------------------------------------------- 1 | InkingTextureLoader/.vs/ 2 | InkingTextureLoader/Library/ 3 | InkingTextureLoader/obj/ 4 | InkingTextureLoader/Temp/ 5 | NativeCode/build_android/ 6 | NativeCode/build_windows/ 7 | NativeCode/lib/ 8 | InkingTextureLoader/Assembly* 9 | InkingTextureLoader/Logs/ 10 | UnityTextureLoader/Library/ 11 | UnityTextureLoader/Temp/ 12 | UnityTextureLoader/ProjectSettings/ 13 | UnityTextureLoader/obj/ 14 | UnityTextureLoader/.vs/ 15 | InkingTextureLoader/lib/ 16 | InkingTextureLoader/build_windows/ 17 | InkingTextureLoader/build_android/ 18 | UnityTextureLoader/Logs/ 19 | UnityTextureLoader/Packages/ 20 | UnityTextureLoader/Assembly* 21 | UnityTextureLoader/build_android/ 22 | UnityTextureLoader/.vsconfig 23 | InkingTextureLoader/_build_android/ 24 | InkingTextureLoader/_build_windows/ 25 | UnityTextureLoader/_build_android/ 26 | -------------------------------------------------------------------------------- /InkingTextureLoader/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Sets the minimum version of CMake required to build your native library. 2 | # This ensures that a certain set of CMake features is available to 3 | # your build. 4 | 5 | cmake_minimum_required(VERSION 3.4.1) 6 | 7 | # Specifies a library name, specifies whether the library is STATIC or 8 | # SHARED, and provides relative paths to the source code. You can 9 | # define multiple libraries by adding multiple add.library() commands, 10 | # and CMake builds them for you. When you build your app, Gradle 11 | # automatically packages shared libraries with your APK. 12 | 13 | 14 | 15 | macro(source_group_by_dir source_files) 16 | if(MSVC) 17 | set(sgbd_cur_dir ${CMAKE_CURRENT_SOURCE_DIR}) 18 | foreach(sgbd_file ${${source_files}}) 19 | 20 | string(REGEX REPLACE ${sgbd_cur_dir}/.∗.∗ \\1 sgbd_fpath ${sgbd_file}) 21 | string(REGEX REPLACE ".∗.∗/.*" \\1 sgbd_group_name ${sgbd_fpath}) 22 | string(REPLACE "${sgbd_cur_dir}/" "" sgbd_group_name ${sgbd_group_name}) 23 | get_filename_component( FULL_NAME "${sgbd_group_name}" PATH) 24 | 25 | if(FULL_NAME) 26 | string(REPLACE "/" "\\" FULL_NAME ${FULL_NAME}) 27 | source_group(${FULL_NAME} FILES ${sgbd_file}) 28 | endif(FULL_NAME) 29 | 30 | #message(STATUS "group = [${FULL_NAME}] file = [${sgbd_file}]") 31 | 32 | endforeach(sgbd_file) 33 | endif(MSVC) 34 | endmacro(source_group_by_dir) 35 | 36 | project(Inking) 37 | 38 | add_subdirectory(TextureLoader) -------------------------------------------------------------------------------- /InkingTextureLoader/TextureLoader/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Sets the minimum version of CMake required to build your native library. 2 | # This ensures that a certain set of CMake features is available to 3 | # your build. 4 | 5 | cmake_minimum_required(VERSION 3.4.1) 6 | 7 | # Specifies a library name, specifies whether the library is STATIC or 8 | # SHARED, and provides relative paths to the source code. You can 9 | # define multiple libraries by adding multiple add.library() commands, 10 | # and CMake builds them for you. When you build your app, Gradle 11 | # automatically packages shared libraries with your APK. 12 | 13 | include_directories("${PROJECT_SOURCE_DIR}/ThirdParty/stb_image/source") 14 | include_directories("${PROJECT_SOURCE_DIR}/ThirdParty/UnityPluginAPI") 15 | 16 | 17 | if(MSVC) 18 | add_definitions(-D _D3D11_) 19 | else() 20 | add_definitions(-D _OPENGLES_) 21 | endif() 22 | 23 | file(GLOB_RECURSE source_files "Source/*.h" "Source/*.cpp") 24 | source_group_by_dir(source_files) 25 | 26 | add_library(TextureLoader SHARED ${source_files} ) 27 | # add_library(TextureLoader ${source_files} ) 28 | 29 | set_target_properties(TextureLoader PROPERTIES 30 | OUTPUT_NAME "InkingTextureLoader" 31 | ) 32 | 33 | SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) 34 | 35 | if(MSVC) 36 | target_link_libraries(TextureLoader 37 | winmm.lib 38 | ) 39 | else() 40 | target_link_libraries(TextureLoader 41 | -lEGL 42 | -lGLESv2 43 | ) 44 | endif() 45 | -------------------------------------------------------------------------------- /InkingTextureLoader/TextureLoader/Source/ColorSpace.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Inking 4 | { 5 | enum class ColorSpace 6 | { 7 | Gamma = 0, 8 | Linear, 9 | }; 10 | } 11 | -------------------------------------------------------------------------------- /InkingTextureLoader/TextureLoader/Source/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | -------------------------------------------------------------------------------- /InkingTextureLoader/TextureLoader/Source/ITextureLoader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | using namespace std; 5 | #include "RefCounter.h" 6 | #include "IUnityGraphics.h" 7 | #include "ColorSpace.h" 8 | 9 | struct IUnityInterfaces; 10 | 11 | namespace Inking 12 | { 13 | class TextureLoadAsyncOperation; 14 | 15 | class ITextureLoader : public RefCounter 16 | { 17 | public: 18 | virtual TextureLoadAsyncOperation* LoadAsync(const Char* fileName, ColorSpace colorSpace = ColorSpace::Linear) = 0; 19 | 20 | virtual void Update() = 0; 21 | 22 | virtual void Unload(void* nativeTex) = 0; 23 | 24 | virtual void OnUnityPluginLoad(IUnityInterfaces* unityInterfaces) = 0; 25 | 26 | virtual void OnUnityRenderingEvent(int eventID) = 0; 27 | 28 | virtual void OnGraphicsDeviceEvent(UnityGfxDeviceEventType eventType) = 0; 29 | 30 | virtual void OnUnityPluginUnload() = 0; 31 | 32 | virtual TextureLoadAsyncOperation* LoadAsyncFromMemory(const void* buffer, int bufferLen, ColorSpace colorSpace) = 0; 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /InkingTextureLoader/TextureLoader/Source/RefCounter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Typedef.h" 4 | namespace Inking 5 | { 6 | class RefCounter 7 | { 8 | int _refCount = 1; 9 | public: 10 | RefCounter() { 11 | 12 | } 13 | 14 | virtual ~RefCounter() { 15 | 16 | } 17 | void AddRef() { 18 | _refCount++; 19 | } 20 | 21 | void Release() { 22 | --_refCount; 23 | if (_refCount == 0) 24 | delete this; 25 | } 26 | 27 | int GetRecCount() { 28 | return _refCount; 29 | } 30 | 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /InkingTextureLoader/TextureLoader/Source/Texture.cpp: -------------------------------------------------------------------------------- 1 | #include "Texture.h" 2 | #include "ITextureLoader.h" 3 | 4 | namespace Inking 5 | { 6 | Texture::Texture(ITextureLoader* textureLoader) 7 | :_textureLoader(textureLoader) 8 | { 9 | 10 | } 11 | 12 | Texture::~Texture() 13 | { 14 | if (_textureLoader != nullptr) 15 | { 16 | _textureLoader->Unload(_native); 17 | } 18 | } 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /InkingTextureLoader/TextureLoader/Source/Texture.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "RefCounter.h" 3 | 4 | namespace Inking 5 | { 6 | class ITextureLoader; 7 | 8 | class Texture : public RefCounter 9 | { 10 | protected: 11 | void* _native = nullptr; 12 | ITextureLoader* _textureLoader = nullptr; 13 | public: 14 | Texture(ITextureLoader* textureLoader); 15 | 16 | virtual ~Texture(); 17 | 18 | void* GetNative() 19 | { 20 | return _native; 21 | } 22 | 23 | void SetNative(void* value) 24 | { 25 | _native = value; 26 | } 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /InkingTextureLoader/TextureLoader/Source/Texture2D.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Typedef.h" 3 | #include "Texture.h" 4 | 5 | namespace Inking 6 | { 7 | class Texture2D : public Texture 8 | { 9 | protected: 10 | int _width = 0; 11 | int _height = 0; 12 | public: 13 | Texture2D(ITextureLoader* textureLoader) 14 | :Texture(textureLoader) 15 | { 16 | 17 | } 18 | 19 | virtual ~Texture2D() 20 | { 21 | 22 | } 23 | 24 | int GetWidth() 25 | { 26 | return _width; 27 | } 28 | 29 | int GetHeight() 30 | { 31 | return _height; 32 | } 33 | 34 | void SetWidth(int value) { 35 | _width = value; 36 | } 37 | 38 | void SetHeight(int value) { 39 | _height = value; 40 | } 41 | }; 42 | } 43 | -------------------------------------------------------------------------------- /InkingTextureLoader/TextureLoader/Source/TextureLoadAsyncOperation.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "RefCounter.h" 3 | #include "TextureLoadAsyncOperationState.h" 4 | #include "Texture.h" 5 | #include "ColorSpace.h" 6 | #include "TextureLoadMode.h" 7 | 8 | namespace Inking 9 | { 10 | 11 | class TextureLoadAsyncOperation : public RefCounter 12 | { 13 | String _fileName; 14 | Texture* _texture = nullptr; 15 | 16 | TextureLoadMode _loadMode = TextureLoadMode::File; 17 | ColorSpace _colorSpace = ColorSpace::Linear; 18 | 19 | TextureLoadAsyncOperationState _state = TextureLoadAsyncOperationState::None; 20 | public: 21 | TextureLoadAsyncOperation() 22 | { 23 | 24 | } 25 | 26 | TextureLoadAsyncOperationState GetState() 27 | { 28 | return _state; 29 | } 30 | 31 | void SetState(TextureLoadAsyncOperationState state) 32 | { 33 | _state = state; 34 | } 35 | 36 | Texture* GetTexture() const 37 | { 38 | return _texture; 39 | } 40 | 41 | void SetTexture(Texture* value) 42 | { 43 | _texture = value; 44 | } 45 | 46 | const Char* GetFileName() { 47 | return _fileName.c_str(); 48 | } 49 | 50 | void SetFileName(const Char* fileName) { 51 | _loadMode = TextureLoadMode::File; 52 | _fileName = fileName; 53 | } 54 | 55 | void OnLoadFailed() { 56 | SetState(TextureLoadAsyncOperationState::LoadFailed); 57 | SetTexture(nullptr); 58 | } 59 | 60 | void SetColorSpace(ColorSpace colorSpace) 61 | { 62 | _colorSpace = colorSpace; 63 | } 64 | 65 | ColorSpace GetColorSpace()const 66 | { 67 | return _colorSpace; 68 | } 69 | 70 | 71 | 72 | void SetBuffer(void* buffer, int bufferLen) 73 | { 74 | _loadMode = TextureLoadMode::Memory; 75 | _buffer = buffer; 76 | _bufferLen = bufferLen; 77 | } 78 | 79 | void* _buffer = nullptr; 80 | int _bufferLen = 0; 81 | 82 | TextureLoadMode GetLoadMode() 83 | { 84 | return _loadMode; 85 | } 86 | 87 | void* GetBuffer() 88 | { 89 | return _buffer; 90 | } 91 | 92 | int GetBufferLen() 93 | { 94 | return _bufferLen; 95 | } 96 | }; 97 | } 98 | -------------------------------------------------------------------------------- /InkingTextureLoader/TextureLoader/Source/TextureLoadAsyncOperationState.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Inking 4 | { 5 | enum class TextureLoadAsyncOperationState 6 | { 7 | None, 8 | Loading, 9 | LoadSucceed, 10 | LoadFailed, 11 | }; 12 | } 13 | -------------------------------------------------------------------------------- /InkingTextureLoader/TextureLoader/Source/TextureLoadMode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Inking 4 | { 5 | enum class TextureLoadMode 6 | { 7 | File, 8 | Memory, 9 | }; 10 | } 11 | -------------------------------------------------------------------------------- /InkingTextureLoader/TextureLoader/Source/TextureLoaderD3D11.cpp: -------------------------------------------------------------------------------- 1 | #ifdef _D3D11_ 2 | 3 | #include "TextureLoaderD3D11.h" 4 | #include "Texture2D.h" 5 | 6 | #define STBI_WINDOWS_UTF8 7 | #include "stb_image.h" 8 | #include "IUnityGraphicsD3D11.h" 9 | 10 | namespace Inking 11 | { 12 | 13 | TextureLoaderD3D11::TextureLoaderD3D11() 14 | { 15 | 16 | } 17 | 18 | TextureLoaderD3D11::~TextureLoaderD3D11() 19 | { 20 | isLoadThreadRuning = false; 21 | this->_thread.join(); 22 | } 23 | 24 | void TextureLoaderD3D11::AsyncLoadThreadFunc(TextureLoaderD3D11* _this) 25 | { 26 | _this->_AsyncLoadThreadFunc(); 27 | } 28 | 29 | void TextureLoaderD3D11::LoadShared(TextureLoadAsyncOperation* operation) 30 | { 31 | operation->SetState(TextureLoadAsyncOperationState::Loading); 32 | 33 | 34 | ID3D11Texture2D* d3d11Texture2D = nullptr; 35 | 36 | int width = 0; 37 | int height = 0; 38 | int comp = 0; 39 | 40 | stbi_set_flip_vertically_on_load(1); 41 | unsigned char* pixels = nullptr; 42 | 43 | switch (operation->GetLoadMode()) 44 | { 45 | case TextureLoadMode::File: 46 | { 47 | char fileName2[1024] = ""; 48 | const Char* fileName = operation->GetFileName(); 49 | stbi_convert_wchar_to_utf8(fileName2, 1024, fileName); 50 | 51 | pixels = stbi_load(fileName2, &width, &height, &comp, 4); 52 | } 53 | break;; 54 | case TextureLoadMode::Memory: 55 | { 56 | auto buffer = operation->GetBuffer(); 57 | auto bufferLen = operation->GetBufferLen(); 58 | pixels = stbi_load_from_memory((const stbi_uc*)buffer, bufferLen, &width, &height, &comp, 4); 59 | } 60 | break; 61 | default: 62 | break; 63 | } 64 | 65 | if (pixels == nullptr) { 66 | operation->OnLoadFailed(); 67 | return; 68 | } 69 | auto colorSpace = operation->GetColorSpace(); 70 | 71 | D3D11_TEXTURE2D_DESC desc; 72 | ZeroMemory(&desc, sizeof(desc)); 73 | desc.Width = width; 74 | desc.Height = height; 75 | desc.MipLevels = 1; 76 | desc.ArraySize = 1; 77 | desc.Format = (colorSpace == ColorSpace::Gamma) ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB : DXGI_FORMAT_R8G8B8A8_UNORM; 78 | desc.SampleDesc.Count = 1; 79 | desc.SampleDesc.Quality = 0; 80 | desc.Usage = D3D11_USAGE_DEFAULT; 81 | desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;; 82 | desc.CPUAccessFlags = 0; 83 | desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED; 84 | 85 | D3D11_SUBRESOURCE_DATA data = {}; 86 | data.pSysMem = pixels; 87 | data.SysMemPitch = width * 4; 88 | data.SysMemSlicePitch = 1; 89 | 90 | HRESULT hr = _device->CreateTexture2D(&desc, &data, &d3d11Texture2D); 91 | 92 | stbi_image_free(pixels); 93 | 94 | if (FAILED(hr)) 95 | { 96 | operation->OnLoadFailed(); 97 | return; 98 | } 99 | 100 | IDXGIResource* pResource = nullptr; 101 | hr = d3d11Texture2D->QueryInterface(__uuidof(IDXGIResource), reinterpret_cast(&pResource)); 102 | if (FAILED(hr)) { 103 | operation->OnLoadFailed(); 104 | return; 105 | } 106 | 107 | HANDLE textureSharedHandle = INVALID_HANDLE_VALUE; 108 | if (SUCCEEDED(hr)) 109 | { 110 | pResource->GetSharedHandle(&textureSharedHandle); 111 | 112 | Texture2D* texture2D = new Texture2D(this); 113 | texture2D->SetNative(textureSharedHandle); 114 | texture2D->SetWidth(width); 115 | texture2D->SetHeight(height); 116 | 117 | operation->SetTexture(texture2D); 118 | } 119 | 120 | d3d11Texture2D->Release(); 121 | } 122 | 123 | void TextureLoaderD3D11::Load(TextureLoadAsyncOperation* operation) 124 | { 125 | LoadShared(operation); 126 | 127 | _stage2Mutex.lock(); 128 | _stage2Operations.push_front(operation); 129 | _stage2Mutex.unlock(); 130 | } 131 | 132 | void TextureLoaderD3D11::_AsyncLoadThreadFunc() 133 | { 134 | while (isLoadThreadRuning) 135 | { 136 | Sleep(0); 137 | 138 | _stage1Mutex.lock(); 139 | 140 | auto size = this->_stage1Operations.size(); 141 | 142 | if (size == 0) 143 | { 144 | _stage1Mutex.unlock(); 145 | continue; 146 | } 147 | 148 | auto operation = this->_stage1Operations.front(); 149 | this->_stage1Operations.pop_front(); 150 | _stage1Mutex.unlock(); 151 | 152 | Load(operation); 153 | 154 | } 155 | } 156 | 157 | TextureLoadAsyncOperation* TextureLoaderD3D11::LoadAsync(const Char* fileName, ColorSpace colorSpace) 158 | { 159 | _stage1Mutex.lock(); 160 | auto operation = new TextureLoadAsyncOperation(); 161 | _stage1Operations.push_back(operation); 162 | operation->SetFileName(fileName); 163 | operation->SetColorSpace(colorSpace); 164 | _stage1Mutex.unlock(); 165 | 166 | return operation; 167 | } 168 | 169 | void TextureLoaderD3D11::Update() 170 | { 171 | _stage2Mutex.lock(); 172 | if (_stage2Operations.size() != 0) 173 | { 174 | for (auto operation : _stage2Operations) 175 | { 176 | if (operation->GetState() == TextureLoadAsyncOperationState::LoadFailed) 177 | { 178 | operation->SetTexture(nullptr); 179 | continue; 180 | } 181 | 182 | Texture2D* texture2D = (Texture2D*)operation->GetTexture(); 183 | 184 | HANDLE handle = (HANDLE)texture2D->GetNative(); 185 | if (handle != INVALID_HANDLE_VALUE) 186 | { 187 | ID3D11Texture2D* d3d11Texture2D = nullptr; 188 | ID3D11ShaderResourceView* srv = nullptr; 189 | 190 | HRESULT hr = _device->OpenSharedResource(handle, __uuidof(ID3D11Texture2D), (void**)&d3d11Texture2D); 191 | if (SUCCEEDED(hr)) 192 | { 193 | hr = _device->CreateShaderResourceView(d3d11Texture2D, NULL, &srv); 194 | if (SUCCEEDED(hr)) 195 | { 196 | texture2D->SetNative(srv); 197 | operation->SetState(TextureLoadAsyncOperationState::LoadSucceed); 198 | d3d11Texture2D->Release(); 199 | continue; 200 | } 201 | } 202 | 203 | operation->SetTexture(nullptr); 204 | operation->SetState(TextureLoadAsyncOperationState::LoadFailed); 205 | } 206 | } 207 | 208 | _stage2Operations.clear(); 209 | } 210 | 211 | _stage2Mutex.unlock(); 212 | } 213 | 214 | void TextureLoaderD3D11::Unload(void* nativeTex) 215 | { 216 | ID3D11ShaderResourceView * srv = (ID3D11ShaderResourceView *)nativeTex; 217 | if(srv) 218 | srv->Release(); 219 | } 220 | 221 | void TextureLoaderD3D11::OnUnityPluginLoad(IUnityInterfaces* unityInterfaces) 222 | { 223 | IUnityGraphics* graphics = unityInterfaces->Get(); 224 | auto renderer = graphics->GetRenderer(); 225 | switch (renderer) 226 | { 227 | case kUnityGfxRendererD3D11: 228 | { 229 | auto graphicsD3D11 = unityInterfaces->Get(); 230 | _device = graphicsD3D11->GetDevice(); 231 | _thread = thread(AsyncLoadThreadFunc, this); 232 | break; 233 | } 234 | default: 235 | break; 236 | } 237 | } 238 | 239 | void TextureLoaderD3D11::OnUnityRenderingEvent(int eventID) 240 | { 241 | 242 | } 243 | 244 | TextureLoadAsyncOperation* TextureLoaderD3D11::LoadAsyncFromMemory(const void* buffer, int bufferLen, ColorSpace colorSpace) 245 | { 246 | _stage1Mutex.lock(); 247 | TextureLoadAsyncOperation* operation = new TextureLoadAsyncOperation(); 248 | _stage1Operations.push_back(operation); 249 | operation->SetBuffer((void*)buffer, bufferLen); 250 | operation->SetColorSpace(colorSpace); 251 | _stage1Mutex.unlock(); 252 | return operation; 253 | } 254 | 255 | } 256 | 257 | #endif -------------------------------------------------------------------------------- /InkingTextureLoader/TextureLoader/Source/TextureLoaderD3D11.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef _D3D11_ 4 | 5 | #include "ITextureLoader.h" 6 | #include 7 | #include 8 | #include "TextureLoadAsyncOperation.h" 9 | #include 10 | #include 11 | using namespace std; 12 | namespace Inking 13 | { 14 | class TextureLoaderD3D11 : public ITextureLoader 15 | { 16 | ID3D11Device* _device = NULL; 17 | 18 | void Load(TextureLoadAsyncOperation* operation); 19 | 20 | void _AsyncLoadThreadFunc(); 21 | 22 | thread _thread; 23 | 24 | list _stage1Operations; 25 | list _stage2Operations; 26 | 27 | mutex _stage1Mutex; 28 | mutex _stage2Mutex; 29 | bool isLoadThreadRuning = true; 30 | public: 31 | TextureLoaderD3D11(); 32 | 33 | virtual ~TextureLoaderD3D11(); 34 | 35 | static void AsyncLoadThreadFunc(TextureLoaderD3D11* _this); 36 | 37 | void LoadShared(TextureLoadAsyncOperation* operation); 38 | 39 | TextureLoadAsyncOperation* LoadAsync(const Char* fileName, ColorSpace colorSpace = ColorSpace::Linear); 40 | 41 | virtual void Update(); 42 | 43 | virtual void Unload(void* nativeTex); 44 | 45 | virtual void OnUnityPluginLoad(IUnityInterfaces* unityInterfaces); 46 | 47 | virtual void OnUnityRenderingEvent(int eventID); 48 | 49 | virtual void OnGraphicsDeviceEvent(UnityGfxDeviceEventType eventType) {}; 50 | 51 | virtual void OnUnityPluginUnload() {} 52 | 53 | virtual TextureLoadAsyncOperation* LoadAsyncFromMemory(const void* buffer, int bufferLen, ColorSpace colorSpace); 54 | }; 55 | 56 | } 57 | 58 | 59 | #endif -------------------------------------------------------------------------------- /InkingTextureLoader/TextureLoader/Source/TextureLoaderOpenGLES.cpp: -------------------------------------------------------------------------------- 1 | #ifdef _OPENGLES_ 2 | 3 | #include "TextureLoaderOpenGLES.h" 4 | #include "Texture2D.h" 5 | 6 | #include "stb_image.h" 7 | 8 | #include 9 | 10 | #include "TextureLoadAsyncOperation.h" 11 | #include "TextureLoadAsyncOperationState.h" 12 | 13 | namespace Inking 14 | { 15 | void TextureLoaderOpenGLES::LoadAsyncThreadFunc(TextureLoaderOpenGLES* _this) 16 | { 17 | _this->_LoadAsyncThreadFunc(); 18 | } 19 | 20 | TextureLoaderOpenGLES::TextureLoaderOpenGLES(int version) 21 | :_version(version) 22 | { 23 | 24 | } 25 | 26 | TextureLoaderOpenGLES::~TextureLoaderOpenGLES() 27 | { 28 | isLoadThreadRuning = false; 29 | this->_thread.join(); 30 | } 31 | 32 | void TextureLoaderOpenGLES::_LoadAsyncThreadFunc() 33 | { 34 | EGLConfig configs[512] = {}; 35 | EGLint numConfigs = 0; 36 | eglGetConfigs(_display, configs, 512, &numConfigs); 37 | EGLConfig contextConfig = 0; 38 | for (int i = 0; i < numConfigs; i++) 39 | { 40 | EGLint tmpConfigId; 41 | eglGetConfigAttrib(_display, configs[i], EGL_CONFIG_ID, &tmpConfigId); 42 | if (tmpConfigId == _configID) 43 | { 44 | contextConfig = configs[i]; 45 | break; 46 | } 47 | } 48 | 49 | //Check if the incoming configuration supports GLES3 50 | EGLint renderableType = 0; 51 | eglGetConfigAttrib(_display, contextConfig, EGL_RENDERABLE_TYPE, &renderableType); 52 | 53 | //Log the surface channel bit depths (prefer an 888 surface with no depth) 54 | EGLint r, g, b, d, s; 55 | eglGetConfigAttrib(_display, contextConfig, EGL_RED_SIZE, &r); 56 | eglGetConfigAttrib(_display, contextConfig, EGL_GREEN_SIZE, &g); 57 | eglGetConfigAttrib(_display, contextConfig, EGL_BLUE_SIZE, &b); 58 | eglGetConfigAttrib(_display, contextConfig, EGL_DEPTH_SIZE, &d); 59 | eglGetConfigAttrib(_display, contextConfig, EGL_SAMPLES, &s); 60 | 61 | EGLint contextAttribs[] = 62 | { 63 | EGL_CONTEXT_CLIENT_VERSION, TextureLoaderOpenGLES::_version, 64 | EGL_NONE 65 | }; 66 | 67 | _context = eglCreateContext(_display, contextConfig, _shareContext, contextAttribs); 68 | 69 | eglMakeCurrent(_display, EGL_NO_SURFACE, EGL_NO_SURFACE, _context); 70 | 71 | while (isLoadThreadRuning) 72 | { 73 | sleep(0); 74 | 75 | DoUnload(); 76 | 77 | _mutexStage1.lock(); 78 | 79 | auto size = _stage1Operations.size(); 80 | if (size == 0) { 81 | _mutexStage1.unlock(); 82 | continue; 83 | } 84 | 85 | auto operation = _stage1Operations.front(); 86 | _stage1Operations.pop_front(); 87 | 88 | _mutexStage1.unlock(); 89 | 90 | Load(operation); 91 | } 92 | } 93 | 94 | void TextureLoaderOpenGLES::Load(TextureLoadAsyncOperation* operation) 95 | { 96 | operation->SetState(TextureLoadAsyncOperationState::Loading); 97 | int width = 0; 98 | int height = 0; 99 | int comp = 0; 100 | 101 | stbi_set_flip_vertically_on_load(1); 102 | unsigned char* pixels = nullptr; 103 | 104 | switch (operation->GetLoadMode()) 105 | { 106 | case TextureLoadMode::File: 107 | { 108 | const Char* fileName = operation->GetFileName(); 109 | pixels = stbi_load(fileName, &width, &height, &comp, 4); 110 | } 111 | break; 112 | case TextureLoadMode::Memory: 113 | { 114 | auto buffer = operation->GetBuffer(); 115 | auto bufferLen = operation->GetBufferLen(); 116 | pixels = stbi_load_from_memory((const stbi_uc*)buffer, bufferLen, &width, &height, &comp, 4); 117 | } 118 | break; 119 | default: 120 | break; 121 | } 122 | 123 | if (pixels == nullptr) { 124 | operation->OnLoadFailed(); 125 | return; 126 | } 127 | 128 | Texture2D* texture2D = new Texture2D(this); 129 | operation->SetTexture(texture2D); 130 | GLuint texID = 0; 131 | glGenTextures(1, &texID); 132 | if (texID == 0) 133 | { 134 | operation->OnLoadFailed(); 135 | return; 136 | } 137 | 138 | glBindTexture(GL_TEXTURE_2D, texID); 139 | 140 | auto colorSpace = operation->GetColorSpace(); 141 | if(colorSpace == ColorSpace::Gamma) 142 | glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 143 | else 144 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 145 | 146 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 147 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 148 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 149 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 150 | 151 | glBindTexture(GL_TEXTURE_2D, 0); 152 | 153 | stbi_image_free(pixels); 154 | 155 | texture2D->SetNative((void*)(GLuint64)(texID)); 156 | texture2D->SetWidth(width); 157 | texture2D->SetHeight(height); 158 | operation->SetState(TextureLoadAsyncOperationState::LoadSucceed); 159 | } 160 | 161 | TextureLoadAsyncOperation* TextureLoaderOpenGLES::LoadAsync(const Char * fileName, ColorSpace colorSpace) 162 | { 163 | TextureLoadAsyncOperation* operation = new TextureLoadAsyncOperation(); 164 | if (fileName == nullptr) 165 | { 166 | operation->OnLoadFailed(); 167 | return operation; 168 | } 169 | _mutexStage1.lock(); 170 | _stage1Operations.push_back(operation); 171 | operation->SetFileName(fileName); 172 | operation->SetColorSpace(colorSpace); 173 | _mutexStage1.unlock(); 174 | return operation; 175 | } 176 | 177 | TextureLoadAsyncOperation* TextureLoaderOpenGLES::LoadAsyncFromMemory(const void* buffer, int bufferLen, ColorSpace colorSpace) 178 | { 179 | _mutexStage1.lock(); 180 | TextureLoadAsyncOperation* operation = new TextureLoadAsyncOperation(); 181 | _stage1Operations.push_back(operation); 182 | operation->SetBuffer((void*)buffer, bufferLen); 183 | operation->SetColorSpace(colorSpace); 184 | _mutexStage1.unlock(); 185 | return operation; 186 | } 187 | 188 | 189 | void TextureLoaderOpenGLES::Update() 190 | { 191 | 192 | } 193 | 194 | void TextureLoaderOpenGLES::Unload(void* native) 195 | { 196 | Unload((GLuint)(GLuint64)native); 197 | } 198 | 199 | void TextureLoaderOpenGLES::Unload(GLuint native) 200 | { 201 | _mutexUnloadTex.lock(); 202 | _unloadTexIDs.push_back(native); 203 | _mutexUnloadTex.unlock(); 204 | } 205 | 206 | void TextureLoaderOpenGLES::DoUnload() 207 | { 208 | _mutexUnloadTex.lock(); 209 | auto size = _unloadTexIDs.size(); 210 | 211 | if (size != 0) 212 | { 213 | glDeleteTextures(size, _unloadTexIDs.data()); 214 | _unloadTexIDs.clear(); 215 | } 216 | 217 | _mutexUnloadTex.unlock(); 218 | } 219 | 220 | void TextureLoaderOpenGLES::OnUnityPluginLoad(IUnityInterfaces* unityInterfaces) 221 | { 222 | 223 | } 224 | 225 | void TextureLoaderOpenGLES::OnUnityRenderingEvent(int eventID) 226 | { 227 | switch (eventID) 228 | { 229 | case 1: 230 | { 231 | _display = eglGetCurrentDisplay(); 232 | 233 | _surface = eglGetCurrentSurface(EGL_DRAW); 234 | 235 | eglQueryContext(_display, _shareContext, EGL_CONFIG_ID, &_configID); 236 | 237 | _shareContext = eglGetCurrentContext(); 238 | 239 | _thread = thread(LoadAsyncThreadFunc, this); 240 | break; 241 | } 242 | default: 243 | break; 244 | } 245 | 246 | } 247 | } 248 | 249 | #endif 250 | -------------------------------------------------------------------------------- /InkingTextureLoader/TextureLoader/Source/TextureLoaderOpenGLES.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef _OPENGLES_ 4 | 5 | #include "ITextureLoader.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | using namespace std; 14 | 15 | namespace Inking 16 | { 17 | 18 | class TextureLoadAsyncOperation; 19 | 20 | class TextureLoaderOpenGLES : public ITextureLoader 21 | { 22 | protected: 23 | EGLContext _shareContext; 24 | EGLContext _context; 25 | EGLDisplay _display = nullptr; 26 | EGLConfig _config = nullptr; 27 | EGLint _configID = 0; 28 | EGLSurface _surface = nullptr; 29 | 30 | thread _thread; 31 | mutex _mutexStage1; 32 | mutex _mutexStage2; 33 | 34 | static void LoadAsyncThreadFunc(TextureLoaderOpenGLES* _this); 35 | 36 | void _LoadAsyncThreadFunc(); 37 | 38 | void Load(TextureLoadAsyncOperation* operation); 39 | 40 | list< TextureLoadAsyncOperation*> _stage1Operations; 41 | list< TextureLoadAsyncOperation*> _stage2Operations; 42 | 43 | int _version; 44 | bool isLoadThreadRuning = true; 45 | public: 46 | TextureLoaderOpenGLES(int version); 47 | 48 | virtual ~TextureLoaderOpenGLES(); 49 | 50 | virtual TextureLoadAsyncOperation* LoadAsync(const Char * fileName, ColorSpace colorSpace); 51 | 52 | virtual TextureLoadAsyncOperation* LoadAsyncFromMemory(const void* buffer, int bufferLen, ColorSpace colorSpace); 53 | 54 | virtual void Update(); 55 | 56 | EGLContext GetShareContext() 57 | { 58 | return _shareContext; 59 | } 60 | 61 | EGLContext GetContext() 62 | { 63 | return _context; 64 | } 65 | 66 | virtual void Unload(void* native); 67 | 68 | void Unload(GLuint native); 69 | 70 | void DoUnload(); 71 | 72 | mutex _mutexUnloadTex; 73 | vector _unloadTexIDs; 74 | 75 | virtual void OnUnityPluginLoad(IUnityInterfaces* unityInterfaces); 76 | 77 | virtual void OnUnityRenderingEvent(int eventID); 78 | 79 | virtual void OnGraphicsDeviceEvent(UnityGfxDeviceEventType eventType) {}; 80 | 81 | virtual void OnUnityPluginUnload() {} 82 | }; 83 | } 84 | 85 | 86 | #endif -------------------------------------------------------------------------------- /InkingTextureLoader/TextureLoader/Source/TextureLoaderOpenGLES2.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef _OPENGLES_ 4 | 5 | #include "TextureLoaderOpenGLES.h" 6 | 7 | namespace Inking 8 | { 9 | class TextureLoaderOpenGLES2 : public TextureLoaderOpenGLES 10 | { 11 | public: 12 | TextureLoaderOpenGLES2() 13 | :TextureLoaderOpenGLES(2) 14 | { 15 | 16 | } 17 | }; 18 | } 19 | 20 | #endif 21 | 22 | -------------------------------------------------------------------------------- /InkingTextureLoader/TextureLoader/Source/TextureLoaderOpenGLES3.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "TextureLoaderOpenGLES.h" 3 | 4 | #ifdef _OPENGLES_ 5 | 6 | namespace Inking 7 | { 8 | 9 | class TextureLoaderOpenGLES3 : public TextureLoaderOpenGLES 10 | { 11 | public: 12 | 13 | TextureLoaderOpenGLES3() 14 | :TextureLoaderOpenGLES(3) 15 | { 16 | 17 | } 18 | 19 | virtual ~TextureLoaderOpenGLES3() {} 20 | 21 | }; 22 | } 23 | 24 | 25 | #endif -------------------------------------------------------------------------------- /InkingTextureLoader/TextureLoader/Source/Typedef.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | using namespace std; 5 | 6 | #ifdef _WIN64 7 | typedef wchar_t Char; 8 | typedef wstring String; 9 | #else 10 | typedef char Char; 11 | typedef string String; 12 | #endif -------------------------------------------------------------------------------- /InkingTextureLoader/TextureLoader/Source/UnityTextureLoader.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xingfa-peng/UnityTextureLoader/df7edcc38c7c6ae40846c94ff903a7e743feab51/InkingTextureLoader/TextureLoader/Source/UnityTextureLoader.cpp -------------------------------------------------------------------------------- /InkingTextureLoader/TextureLoader/Source/UnityTextureLoader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #ifdef _WIN32 5 | #include 6 | #include "IUnityGraphicsD3D11.h" 7 | #endif 8 | #include "IUnityInterface.h" 9 | #include "IUnityGraphics.h" 10 | 11 | 12 | #include "ITextureLoader.h" 13 | 14 | namespace Inking 15 | { 16 | class UnityTextureLoader : public ITextureLoader 17 | { 18 | ITextureLoader* _impl = nullptr; 19 | 20 | UnityTextureLoader(); 21 | public: 22 | static IUnityInterfaces* g_unityInterfaces; 23 | 24 | virtual TextureLoadAsyncOperation* LoadAsync(const Char * fileName, ColorSpace colorSpace) 25 | { 26 | if (_impl == nullptr) 27 | return nullptr; 28 | 29 | return _impl->LoadAsync(fileName, colorSpace); 30 | } 31 | 32 | virtual void Update() 33 | { 34 | if (_impl != nullptr) 35 | { 36 | _impl->Update(); 37 | } 38 | } 39 | 40 | static UnityTextureLoader* GetInstance() 41 | { 42 | static UnityTextureLoader inst; 43 | return &inst; 44 | } 45 | 46 | virtual void Unload(void* native) 47 | { 48 | if (_impl != nullptr) 49 | { 50 | _impl->Unload(native); 51 | } 52 | } 53 | 54 | virtual void OnUnityPluginLoad(IUnityInterfaces* unityInterfaces); 55 | 56 | virtual void OnUnityRenderingEvent(int eventID); 57 | 58 | virtual void OnGraphicsDeviceEvent(UnityGfxDeviceEventType eventType);; 59 | 60 | virtual void OnUnityPluginUnload() {} 61 | 62 | 63 | virtual TextureLoadAsyncOperation* LoadAsyncFromMemory(const void* buffer, int bufferLen, ColorSpace colorSpace); 64 | }; 65 | 66 | } 67 | -------------------------------------------------------------------------------- /InkingTextureLoader/TextureLoader/Source/UnityTextureLoaderExports.cpp: -------------------------------------------------------------------------------- 1 | #include "UnityTextureLoaderExports.h" 2 | #include "UnityTextureLoader.h" 3 | #include "Texture2D.h" 4 | #include "TextureLoaderOpenGLES.h" 5 | #include "TextureLoadAsyncOperation.h" 6 | 7 | #define STB_IMAGE_IMPLEMENTATION 8 | #define STBI_WINDOWS_UTF8 9 | #include 10 | 11 | extern "C" 12 | { 13 | int Inking_Texture2D_GetWidth(Inking::Texture2D* _this) 14 | { 15 | if (_this == nullptr) 16 | return 0; 17 | 18 | return _this->GetWidth(); 19 | } 20 | 21 | int Inking_Texture2D_GetHeight(Inking::Texture2D* _this) 22 | { 23 | if (_this == nullptr) 24 | return 0; 25 | 26 | return _this->GetHeight(); 27 | } 28 | 29 | void Inking_Texture2D_Release(Inking::Texture2D* _this) 30 | { 31 | if (_this != nullptr) 32 | { 33 | _this->Release(); 34 | } 35 | } 36 | 37 | void* Inking_Texture2D_GetNative(Inking::Texture2D* _this) 38 | { 39 | if (_this == nullptr) 40 | return nullptr; 41 | 42 | return _this->GetNative(); 43 | } 44 | 45 | Inking::TextureLoadAsyncOperation* Inking_TextureLoadAsyncOperation_New() { 46 | return new Inking::TextureLoadAsyncOperation(); 47 | } 48 | 49 | void Inking_TextureLoadAsyncOperation_Release(Inking::TextureLoadAsyncOperation* _this) 50 | { 51 | if (_this) 52 | _this->Release(); 53 | } 54 | 55 | int Inking_TextureLoadAsyncOperation_GetState(Inking::TextureLoadAsyncOperation* _this) 56 | { 57 | if (_this == nullptr) 58 | return 0; 59 | 60 | return (int)_this->GetState(); 61 | } 62 | 63 | const Inking::Texture* Inking_TextureLoadAsyncOperation_GetTexture(Inking::TextureLoadAsyncOperation* _this) 64 | { 65 | if (_this == nullptr) 66 | return nullptr; 67 | 68 | return _this->GetTexture(); 69 | } 70 | 71 | Inking::UnityTextureLoader* Inking_TextureLoader_GetInstance() 72 | { 73 | return Inking::UnityTextureLoader::GetInstance(); 74 | } 75 | 76 | Inking::TextureLoadAsyncOperation* Inking_TextureLoader_LoadAsync(Inking::UnityTextureLoader* _this, const Char* fileName, Inking::ColorSpace colorSpace) 77 | { 78 | if (_this == nullptr) 79 | return nullptr; 80 | return _this->LoadAsync(fileName, colorSpace); 81 | } 82 | 83 | void Inking_TextureLoader_Update(Inking::UnityTextureLoader* _this) 84 | { 85 | if (_this) 86 | _this->Update(); 87 | } 88 | 89 | void Inking_TextureLoader_Unload(Inking::UnityTextureLoader* _this, void* native) 90 | { 91 | if (_this) 92 | _this->Unload(native); 93 | } 94 | 95 | Inking::TextureLoadAsyncOperation* Inking_TextureLoader_LoadAsyncFromMemory(Inking::UnityTextureLoader* _this, const void* buffer, int bufferLen, Inking::ColorSpace colorSpace) 96 | { 97 | if (_this == nullptr) 98 | return nullptr; 99 | 100 | return _this->LoadAsyncFromMemory(buffer, bufferLen, colorSpace); 101 | } 102 | } 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /InkingTextureLoader/TextureLoader/Source/UnityTextureLoaderExports.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Typedef.h" 3 | #include "ColorSpace.h" 4 | 5 | 6 | #ifdef _WIN32 7 | #define EXPORT __declspec(dllexport) 8 | #else 9 | #define EXPORT 10 | #endif 11 | 12 | namespace Inking 13 | { 14 | class UnityTextureLoader; 15 | class TextureLoadAsyncOperation; 16 | class Texture; 17 | class Texture2D; 18 | } 19 | 20 | extern "C" 21 | { 22 | EXPORT void* Inking_Texture2D_GetNative(Inking::Texture2D* _this); 23 | 24 | EXPORT int Inking_Texture2D_GetWidth(Inking::Texture2D* _this); 25 | 26 | EXPORT int Inking_Texture2D_GetHeight(Inking::Texture2D* _this); 27 | 28 | EXPORT void Inking_Texture2D_Release(Inking::Texture2D* _this); 29 | 30 | EXPORT Inking::TextureLoadAsyncOperation* Inking_TextureLoadAsyncOperation_New(); 31 | 32 | EXPORT void Inking_TextureLoadAsyncOperation_Release(Inking::TextureLoadAsyncOperation* _this); 33 | 34 | EXPORT int Inking_TextureLoadAsyncOperation_GetState(Inking::TextureLoadAsyncOperation* _this); 35 | 36 | EXPORT const Inking::Texture* Inking_TextureLoadAsyncOperation_GetTexture(Inking::TextureLoadAsyncOperation* _this); 37 | 38 | EXPORT Inking::UnityTextureLoader* Inking_TextureLoader_GetInstance(); 39 | 40 | EXPORT Inking::TextureLoadAsyncOperation* Inking_TextureLoader_LoadAsync(Inking::UnityTextureLoader* _this, const Char* fileName, Inking::ColorSpace colorSpace); 41 | 42 | EXPORT void Inking_TextureLoader_Update(Inking::UnityTextureLoader* _this); 43 | 44 | EXPORT void Inking_TextureLoader_Unload(Inking::UnityTextureLoader* _this, void* native); 45 | 46 | EXPORT Inking::TextureLoadAsyncOperation* Inking_TextureLoader_LoadAsyncFromMemory(Inking::UnityTextureLoader* _this, const void* buffer, int bufferLen, Inking::ColorSpace colorSpace); 47 | } 48 | -------------------------------------------------------------------------------- /InkingTextureLoader/ThirdParty/UnityPluginAPI/IUnityGraphics.h: -------------------------------------------------------------------------------- 1 | // Unity Native Plugin API copyright © 2015 Unity Technologies ApS 2 | // 3 | // Licensed under the Unity Companion License for Unity - dependent projects--see[Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License). 4 | // 5 | // Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.Please review the license for details on these and other terms and conditions. 6 | 7 | #pragma once 8 | #include "IUnityInterface.h" 9 | 10 | typedef enum UnityGfxRenderer 11 | { 12 | //kUnityGfxRendererOpenGL = 0, // Legacy OpenGL, removed 13 | //kUnityGfxRendererD3D9 = 1, // Direct3D 9, removed 14 | kUnityGfxRendererD3D11 = 2, // Direct3D 11 15 | kUnityGfxRendererNull = 4, // "null" device (used in batch mode) 16 | kUnityGfxRendererOpenGLES20 = 8, // OpenGL ES 2.0 17 | kUnityGfxRendererOpenGLES30 = 11, // OpenGL ES 3.0 18 | //kUnityGfxRendererGXM = 12, // PlayStation Vita, removed 19 | kUnityGfxRendererPS4 = 13, // PlayStation 4 20 | kUnityGfxRendererXboxOne = 14, // Xbox One 21 | kUnityGfxRendererMetal = 16, // iOS Metal 22 | kUnityGfxRendererOpenGLCore = 17, // OpenGL core 23 | kUnityGfxRendererD3D12 = 18, // Direct3D 12 24 | kUnityGfxRendererVulkan = 21, // Vulkan 25 | kUnityGfxRendererNvn = 22, // Nintendo Switch NVN API 26 | kUnityGfxRendererXboxOneD3D12 = 23 // MS XboxOne Direct3D 12 27 | } UnityGfxRenderer; 28 | 29 | typedef enum UnityGfxDeviceEventType 30 | { 31 | kUnityGfxDeviceEventInitialize = 0, 32 | kUnityGfxDeviceEventShutdown = 1, 33 | kUnityGfxDeviceEventBeforeReset = 2, 34 | kUnityGfxDeviceEventAfterReset = 3, 35 | } UnityGfxDeviceEventType; 36 | 37 | typedef void (UNITY_INTERFACE_API * IUnityGraphicsDeviceEventCallback)(UnityGfxDeviceEventType eventType); 38 | 39 | // Should only be used on the rendering thread unless noted otherwise. 40 | UNITY_DECLARE_INTERFACE(IUnityGraphics) 41 | { 42 | UnityGfxRenderer(UNITY_INTERFACE_API * GetRenderer)(); // Thread safe 43 | 44 | // This callback will be called when graphics device is created, destroyed, reset, etc. 45 | // It is possible to miss the kUnityGfxDeviceEventInitialize event in case plugin is loaded at a later time, 46 | // when the graphics device is already created. 47 | void(UNITY_INTERFACE_API * RegisterDeviceEventCallback)(IUnityGraphicsDeviceEventCallback callback); 48 | void(UNITY_INTERFACE_API * UnregisterDeviceEventCallback)(IUnityGraphicsDeviceEventCallback callback); 49 | int(UNITY_INTERFACE_API * ReserveEventIDRange)(int count); // reserves 'count' event IDs. Plugins should use the result as a base index when issuing events back and forth to avoid event id clashes. 50 | }; 51 | UNITY_REGISTER_INTERFACE_GUID(0x7CBA0A9CA4DDB544ULL, 0x8C5AD4926EB17B11ULL, IUnityGraphics) 52 | 53 | 54 | // Certain Unity APIs (GL.IssuePluginEvent, CommandBuffer.IssuePluginEvent) can callback into native plugins. 55 | // Provide them with an address to a function of this signature. 56 | typedef void (UNITY_INTERFACE_API * UnityRenderingEvent)(int eventId); 57 | typedef void (UNITY_INTERFACE_API * UnityRenderingEventAndData)(int eventId, void* data); 58 | -------------------------------------------------------------------------------- /InkingTextureLoader/ThirdParty/UnityPluginAPI/IUnityGraphicsD3D11.h: -------------------------------------------------------------------------------- 1 | // Unity Native Plugin API copyright © 2015 Unity Technologies ApS 2 | // 3 | // Licensed under the Unity Companion License for Unity - dependent projects--see[Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License). 4 | // 5 | // Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.Please review the license for details on these and other terms and conditions. 6 | 7 | #pragma once 8 | #include "IUnityInterface.h" 9 | 10 | 11 | // Should only be used on the rendering thread unless noted otherwise. 12 | UNITY_DECLARE_INTERFACE(IUnityGraphicsD3D11) 13 | { 14 | ID3D11Device* (UNITY_INTERFACE_API * GetDevice)(); 15 | 16 | ID3D11Resource* (UNITY_INTERFACE_API * TextureFromRenderBuffer)(UnityRenderBuffer buffer); 17 | ID3D11Resource* (UNITY_INTERFACE_API * TextureFromNativeTexture)(UnityTextureID texture); 18 | 19 | ID3D11RenderTargetView* (UNITY_INTERFACE_API * RTVFromRenderBuffer)(UnityRenderBuffer surface); 20 | ID3D11ShaderResourceView* (UNITY_INTERFACE_API * SRVFromNativeTexture)(UnityTextureID texture); 21 | }; 22 | 23 | UNITY_REGISTER_INTERFACE_GUID(0xAAB37EF87A87D748ULL, 0xBF76967F07EFB177ULL, IUnityGraphicsD3D11) 24 | -------------------------------------------------------------------------------- /InkingTextureLoader/ThirdParty/UnityPluginAPI/IUnityGraphicsD3D12.h: -------------------------------------------------------------------------------- 1 | // Unity Native Plugin API copyright © 2015 Unity Technologies ApS 2 | // 3 | // Licensed under the Unity Companion License for Unity - dependent projects--see[Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License). 4 | // 5 | // Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.Please review the license for details on these and other terms and conditions. 6 | 7 | #pragma once 8 | #include "IUnityInterface.h" 9 | #ifndef __cplusplus 10 | #include 11 | #endif 12 | 13 | struct RenderSurfaceBase; 14 | typedef struct RenderSurfaceBase* UnityRenderBuffer; 15 | 16 | typedef struct UnityGraphicsD3D12ResourceState UnityGraphicsD3D12ResourceState; 17 | struct UnityGraphicsD3D12ResourceState 18 | { 19 | ID3D12Resource* resource; // Resource to barrier. 20 | D3D12_RESOURCE_STATES expected; // Expected resource state before this command list is executed. 21 | D3D12_RESOURCE_STATES current; // State this resource will be in after this command list is executed. 22 | }; 23 | 24 | typedef struct UnityGraphicsD3D12PhysicalVideoMemoryControlValues UnityGraphicsD3D12PhysicalVideoMemoryControlValues; 25 | struct UnityGraphicsD3D12PhysicalVideoMemoryControlValues // all values in bytes 26 | { 27 | UINT64 reservation; // Minimum required physical memory for an application [default = 64MB]. 28 | UINT64 systemMemoryThreshold; // If free physical video memory drops below this threshold, resources will be allocated in system memory. [default = 64MB] 29 | UINT64 residencyThreshold; // Minimum free physical video memory needed to start bringing evicted resources back after shrunken video memory budget expands again. [default = 128MB] 30 | }; 31 | 32 | // Should only be used on the rendering/submission thread. 33 | UNITY_DECLARE_INTERFACE(IUnityGraphicsD3D12v5) 34 | { 35 | ID3D12Device* (UNITY_INTERFACE_API * GetDevice)(); 36 | 37 | ID3D12Fence* (UNITY_INTERFACE_API * GetFrameFence)(); 38 | // Returns the value set on the frame fence once the current frame completes or the GPU is flushed 39 | UINT64(UNITY_INTERFACE_API * GetNextFrameFenceValue)(); 40 | 41 | // Executes a given command list on a worker thread. 42 | // [Optional] Declares expected and post-execution resource states. 43 | // Returns the fence value. 44 | UINT64(UNITY_INTERFACE_API * ExecuteCommandList)(ID3D12GraphicsCommandList * commandList, int stateCount, UnityGraphicsD3D12ResourceState * states); 45 | 46 | void(UNITY_INTERFACE_API * SetPhysicalVideoMemoryControlValues)(const UnityGraphicsD3D12PhysicalVideoMemoryControlValues * memInfo); 47 | 48 | ID3D12CommandQueue* (UNITY_INTERFACE_API * GetCommandQueue)(); 49 | 50 | ID3D12Resource* (UNITY_INTERFACE_API * TextureFromRenderBuffer)(UnityRenderBuffer * rb); 51 | }; 52 | UNITY_REGISTER_INTERFACE_GUID(0xF5C8D8A37D37BC42ULL, 0xB02DFE93B5064A27ULL, IUnityGraphicsD3D12v5) 53 | 54 | // Should only be used on the rendering/submission thread. 55 | UNITY_DECLARE_INTERFACE(IUnityGraphicsD3D12v4) 56 | { 57 | ID3D12Device* (UNITY_INTERFACE_API * GetDevice)(); 58 | 59 | ID3D12Fence* (UNITY_INTERFACE_API * GetFrameFence)(); 60 | // Returns the value set on the frame fence once the current frame completes or the GPU is flushed 61 | UINT64(UNITY_INTERFACE_API * GetNextFrameFenceValue)(); 62 | 63 | // Executes a given command list on a worker thread. 64 | // [Optional] Declares expected and post-execution resource states. 65 | // Returns the fence value. 66 | UINT64(UNITY_INTERFACE_API * ExecuteCommandList)(ID3D12GraphicsCommandList * commandList, int stateCount, UnityGraphicsD3D12ResourceState * states); 67 | 68 | void(UNITY_INTERFACE_API * SetPhysicalVideoMemoryControlValues)(const UnityGraphicsD3D12PhysicalVideoMemoryControlValues * memInfo); 69 | 70 | ID3D12CommandQueue* (UNITY_INTERFACE_API * GetCommandQueue)(); 71 | }; 72 | UNITY_REGISTER_INTERFACE_GUID(0X498FFCC13EC94006ULL, 0XB18F8B0FF67778C8ULL, IUnityGraphicsD3D12v4) 73 | 74 | // Should only be used on the rendering/submission thread. 75 | UNITY_DECLARE_INTERFACE(IUnityGraphicsD3D12v3) 76 | { 77 | ID3D12Device* (UNITY_INTERFACE_API * GetDevice)(); 78 | 79 | ID3D12Fence* (UNITY_INTERFACE_API * GetFrameFence)(); 80 | // Returns the value set on the frame fence once the current frame completes or the GPU is flushed 81 | UINT64(UNITY_INTERFACE_API * GetNextFrameFenceValue)(); 82 | 83 | // Executes a given command list on a worker thread. 84 | // [Optional] Declares expected and post-execution resource states. 85 | // Returns the fence value. 86 | UINT64(UNITY_INTERFACE_API * ExecuteCommandList)(ID3D12GraphicsCommandList * commandList, int stateCount, UnityGraphicsD3D12ResourceState * states); 87 | 88 | void(UNITY_INTERFACE_API * SetPhysicalVideoMemoryControlValues)(const UnityGraphicsD3D12PhysicalVideoMemoryControlValues * memInfo); 89 | }; 90 | UNITY_REGISTER_INTERFACE_GUID(0x57C3FAFE59E5E843ULL, 0xBF4F5998474BB600ULL, IUnityGraphicsD3D12v3) 91 | 92 | // Should only be used on the rendering/submission thread. 93 | UNITY_DECLARE_INTERFACE(IUnityGraphicsD3D12v2) 94 | { 95 | ID3D12Device* (UNITY_INTERFACE_API * GetDevice)(); 96 | 97 | ID3D12Fence* (UNITY_INTERFACE_API * GetFrameFence)(); 98 | // Returns the value set on the frame fence once the current frame completes or the GPU is flushed 99 | UINT64(UNITY_INTERFACE_API * GetNextFrameFenceValue)(); 100 | 101 | // Executes a given command list on a worker thread. 102 | // [Optional] Declares expected and post-execution resource states. 103 | // Returns the fence value. 104 | UINT64(UNITY_INTERFACE_API * ExecuteCommandList)(ID3D12GraphicsCommandList * commandList, int stateCount, UnityGraphicsD3D12ResourceState * states); 105 | }; 106 | UNITY_REGISTER_INTERFACE_GUID(0xEC39D2F18446C745ULL, 0xB1A2626641D6B11FULL, IUnityGraphicsD3D12v2) 107 | 108 | 109 | // Obsolete 110 | UNITY_DECLARE_INTERFACE(IUnityGraphicsD3D12) 111 | { 112 | ID3D12Device* (UNITY_INTERFACE_API * GetDevice)(); 113 | ID3D12CommandQueue* (UNITY_INTERFACE_API * GetCommandQueue)(); 114 | 115 | ID3D12Fence* (UNITY_INTERFACE_API * GetFrameFence)(); 116 | // Returns the value set on the frame fence once the current frame completes or the GPU is flushed 117 | UINT64(UNITY_INTERFACE_API * GetNextFrameFenceValue)(); 118 | 119 | // Returns the state a resource will be in after the last command list is executed 120 | bool(UNITY_INTERFACE_API * GetResourceState)(ID3D12Resource * resource, D3D12_RESOURCE_STATES * outState); 121 | // Specifies the state a resource will be in after a plugin command list with resource barriers is executed 122 | void(UNITY_INTERFACE_API * SetResourceState)(ID3D12Resource * resource, D3D12_RESOURCE_STATES state); 123 | }; 124 | UNITY_REGISTER_INTERFACE_GUID(0xEF4CEC88A45F4C4CULL, 0xBD295B6F2A38D9DEULL, IUnityGraphicsD3D12) 125 | -------------------------------------------------------------------------------- /InkingTextureLoader/ThirdParty/UnityPluginAPI/IUnityGraphicsMetal.h: -------------------------------------------------------------------------------- 1 | // Unity Native Plugin API copyright © 2015 Unity Technologies ApS 2 | // 3 | // Licensed under the Unity Companion License for Unity - dependent projects--see[Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License). 4 | // 5 | // Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.Please review the license for details on these and other terms and conditions. 6 | 7 | #pragma once 8 | #include "IUnityInterface.h" 9 | 10 | #ifndef __OBJC__ 11 | #error metal plugin is objc code. 12 | #endif 13 | #ifndef __clang__ 14 | #error only clang compiler is supported. 15 | #endif 16 | 17 | @class NSBundle; 18 | @protocol MTLDevice; 19 | @protocol MTLCommandBuffer; 20 | @protocol MTLCommandEncoder; 21 | @protocol MTLTexture; 22 | @class MTLRenderPassDescriptor; 23 | 24 | 25 | UNITY_DECLARE_INTERFACE(IUnityGraphicsMetalV1) 26 | { 27 | NSBundle* (UNITY_INTERFACE_API * MetalBundle)(); 28 | id(UNITY_INTERFACE_API * MetalDevice)(); 29 | 30 | id(UNITY_INTERFACE_API * CurrentCommandBuffer)(); 31 | 32 | // for custom rendering support there are two scenarios: 33 | // you want to use current in-flight MTLCommandEncoder (NB: it might be nil) 34 | id(UNITY_INTERFACE_API * CurrentCommandEncoder)(); 35 | // or you might want to create your own encoder. 36 | // In that case you should end unity's encoder before creating your own and end yours before returning control to unity 37 | void(UNITY_INTERFACE_API * EndCurrentCommandEncoder)(); 38 | 39 | // returns MTLRenderPassDescriptor used to create current MTLCommandEncoder 40 | MTLRenderPassDescriptor* (UNITY_INTERFACE_API * CurrentRenderPassDescriptor)(); 41 | 42 | // converting trampoline UnityRenderBufferHandle into native RenderBuffer 43 | UnityRenderBuffer(UNITY_INTERFACE_API * RenderBufferFromHandle)(void* bufferHandle); 44 | 45 | // access to RenderBuffer's texure 46 | // NB: you pass here *native* RenderBuffer, acquired by calling (C#) RenderBuffer.GetNativeRenderBufferPtr 47 | // AAResolvedTextureFromRenderBuffer will return nil in case of non-AA RenderBuffer or if called for depth RenderBuffer 48 | // StencilTextureFromRenderBuffer will return nil in case of no-stencil RenderBuffer or if called for color RenderBuffer 49 | id(UNITY_INTERFACE_API * TextureFromRenderBuffer)(UnityRenderBuffer buffer); 50 | id(UNITY_INTERFACE_API * AAResolvedTextureFromRenderBuffer)(UnityRenderBuffer buffer); 51 | id(UNITY_INTERFACE_API * StencilTextureFromRenderBuffer)(UnityRenderBuffer buffer); 52 | }; 53 | UNITY_REGISTER_INTERFACE_GUID(0x29F8F3D03833465EULL, 0x92138551C15D823DULL, IUnityGraphicsMetalV1) 54 | 55 | 56 | // deprecated: please use versioned interface above 57 | 58 | UNITY_DECLARE_INTERFACE(IUnityGraphicsMetal) 59 | { 60 | NSBundle* (UNITY_INTERFACE_API * MetalBundle)(); 61 | id(UNITY_INTERFACE_API * MetalDevice)(); 62 | 63 | id(UNITY_INTERFACE_API * CurrentCommandBuffer)(); 64 | id(UNITY_INTERFACE_API * CurrentCommandEncoder)(); 65 | void(UNITY_INTERFACE_API * EndCurrentCommandEncoder)(); 66 | MTLRenderPassDescriptor* (UNITY_INTERFACE_API * CurrentRenderPassDescriptor)(); 67 | 68 | UnityRenderBuffer(UNITY_INTERFACE_API * RenderBufferFromHandle)(void* bufferHandle); 69 | 70 | id(UNITY_INTERFACE_API * TextureFromRenderBuffer)(UnityRenderBuffer buffer); 71 | id(UNITY_INTERFACE_API * AAResolvedTextureFromRenderBuffer)(UnityRenderBuffer buffer); 72 | id(UNITY_INTERFACE_API * StencilTextureFromRenderBuffer)(UnityRenderBuffer buffer); 73 | }; 74 | UNITY_REGISTER_INTERFACE_GUID(0x992C8EAEA95811E5ULL, 0x9A62C4B5B9876117ULL, IUnityGraphicsMetal) 75 | -------------------------------------------------------------------------------- /InkingTextureLoader/ThirdParty/UnityPluginAPI/IUnityGraphicsVulkan.h: -------------------------------------------------------------------------------- 1 | // Unity Native Plugin API copyright © 2015 Unity Technologies ApS 2 | // 3 | // Licensed under the Unity Companion License for Unity - dependent projects--see[Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License). 4 | // 5 | // Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.Please review the license for details on these and other terms and conditions. 6 | 7 | #pragma once 8 | #include "IUnityInterface.h" 9 | 10 | #ifndef UNITY_VULKAN_HEADER 11 | #define UNITY_VULKAN_HEADER 12 | #endif 13 | 14 | #include UNITY_VULKAN_HEADER 15 | 16 | struct UnityVulkanInstance 17 | { 18 | VkPipelineCache pipelineCache; // Unity's pipeline cache is serialized to disk 19 | VkInstance instance; 20 | VkPhysicalDevice physicalDevice; 21 | VkDevice device; 22 | VkQueue graphicsQueue; 23 | PFN_vkGetInstanceProcAddr getInstanceProcAddr; // vkGetInstanceProcAddr of the Vulkan loader, same as the one passed to UnityVulkanInitCallback 24 | unsigned int queueFamilyIndex; 25 | 26 | void* reserved[8]; 27 | }; 28 | 29 | struct UnityVulkanMemory 30 | { 31 | VkDeviceMemory memory; // Vulkan memory handle 32 | VkDeviceSize offset; // offset within memory 33 | VkDeviceSize size; // size in bytes, may be less than the total size of memory; 34 | void* mapped; // pointer to mapped memory block, NULL if not mappable, offset is already applied, remaining block still has at least the given size. 35 | VkMemoryPropertyFlags flags; // Vulkan memory properties 36 | unsigned int memoryTypeIndex; // index into VkPhysicalDeviceMemoryProperties::memoryTypes 37 | 38 | void* reserved[4]; 39 | }; 40 | 41 | enum UnityVulkanResourceAccessMode 42 | { 43 | // Does not imply any pipeline barriers, should only be used to query resource attributes 44 | kUnityVulkanResourceAccess_ObserveOnly, 45 | 46 | // Handles layout transition and barriers 47 | kUnityVulkanResourceAccess_PipelineBarrier, 48 | 49 | // Recreates the backing resource (VkBuffer/VkImage) but keeps the previous one alive if it's in use 50 | kUnityVulkanResourceAccess_Recreate, 51 | }; 52 | 53 | struct UnityVulkanImage 54 | { 55 | UnityVulkanMemory memory; // memory that backs the image 56 | VkImage image; // Vulkan image handle 57 | VkImageLayout layout; // current layout, may change resource access 58 | VkImageAspectFlags aspect; 59 | VkImageUsageFlags usage; 60 | VkFormat format; 61 | VkExtent3D extent; 62 | VkImageTiling tiling; 63 | VkImageType type; 64 | VkSampleCountFlagBits samples; 65 | int layers; 66 | int mipCount; 67 | 68 | void* reserved[4]; 69 | }; 70 | 71 | struct UnityVulkanBuffer 72 | { 73 | UnityVulkanMemory memory; // memory that backs the buffer 74 | VkBuffer buffer; // Vulkan buffer handle 75 | size_t sizeInBytes; // size of the buffer in bytes, may be less than memory size 76 | VkBufferUsageFlags usage; 77 | 78 | void* reserved[4]; 79 | }; 80 | 81 | struct UnityVulkanRecordingState 82 | { 83 | VkCommandBuffer commandBuffer; // Vulkan command buffer that is currently recorded by Unity 84 | VkCommandBufferLevel commandBufferLevel; 85 | VkRenderPass renderPass; // Current render pass, a compatible one or VK_NULL_HANDLE 86 | VkFramebuffer framebuffer; // Current framebuffer or VK_NULL_HANDLE 87 | int subPassIndex; // index of the current sub pass, -1 if not inside a render pass 88 | 89 | // Resource life-time tracking counters, only relevant for resources allocated by the plugin 90 | unsigned long long currentFrameNumber; // can be used to track lifetime of own resources 91 | unsigned long long safeFrameNumber; // all resources that were used in this frame (or before) are safe to be released 92 | 93 | void* reserved[4]; 94 | }; 95 | 96 | enum UnityVulkanEventRenderPassPreCondition 97 | { 98 | // Don't care about the state on Unity's current command buffer 99 | // This is the default precondition 100 | kUnityVulkanRenderPass_DontCare, 101 | 102 | // Make sure that there is currently no RenderPass in progress. 103 | // This allows e.g. resource uploads. 104 | // There are no guarantees about the currently bound descriptor sets, vertex buffers, index buffers and pipeline objects 105 | // Unity does however set dynamic pipeline set VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR based on the current settings 106 | // If used in combination with the SRP RenderPass API the resuls is undefined 107 | kUnityVulkanRenderPass_EnsureInside, 108 | 109 | // Make sure that there is currently no RenderPass in progress. 110 | // Ends the current render pass (and resumes it afterwards if needed) 111 | // If used in combination with the SRP RenderPass API the resuls is undefined. 112 | kUnityVulkanRenderPass_EnsureOutside 113 | }; 114 | 115 | enum UnityVulkanGraphicsQueueAccess 116 | { 117 | // No queue acccess, no work must be submitted to UnityVulkanInstance::graphicsQueue from the plugin event callback 118 | kUnityVulkanGraphicsQueueAccess_DontCare, 119 | 120 | // Make sure that Unity worker threads don't access the Vulkan graphics queue 121 | // This disables access to the current Unity command buffer 122 | kUnityVulkanGraphicsQueueAccess_Allow, 123 | }; 124 | 125 | enum UnityVulkanEventConfigFlagBits 126 | { 127 | kUnityVulkanEventConfigFlag_EnsurePreviousFrameSubmission = (1 << 0), // default: set 128 | kUnityVulkanEventConfigFlag_FlushCommandBuffers = (1 << 1), // submit existing command buffers, default: not set 129 | kUnityVulkanEventConfigFlag_SyncWorkerThreads = (1 << 2), // wait for worker threads to finish, default: not set 130 | kUnityVulkanEventConfigFlag_ModifiesCommandBuffersState = (1 << 3), // should be set when descriptor set bindings, vertex buffer bindings, etc are changed (default: set) 131 | }; 132 | 133 | struct UnityVulkanPluginEventConfig 134 | { 135 | UnityVulkanEventRenderPassPreCondition renderPassPrecondition; 136 | UnityVulkanGraphicsQueueAccess graphicsQueueAccess; 137 | uint32_t flags; 138 | }; 139 | 140 | // Constant that can be used to reference the whole image 141 | const VkImageSubresource* const UnityVulkanWholeImage = NULL; 142 | 143 | // callback function, see InterceptInitialization 144 | typedef PFN_vkGetInstanceProcAddr(UNITY_INTERFACE_API * UnityVulkanInitCallback)(PFN_vkGetInstanceProcAddr getInstanceProcAddr, void* userdata); 145 | 146 | enum UnityVulkanSwapchainMode 147 | { 148 | kUnityVulkanSwapchainMode_Default, 149 | kUnityVulkanSwapchainMode_Offscreen 150 | }; 151 | 152 | struct UnityVulkanSwapchainConfiguration 153 | { 154 | UnityVulkanSwapchainMode mode; 155 | }; 156 | 157 | UNITY_DECLARE_INTERFACE(IUnityGraphicsVulkan) 158 | { 159 | // Vulkan API hooks 160 | // 161 | // Must be called before kUnityGfxDeviceEventInitialize (preload plugin) 162 | // Unity will call 'func' when initializing the Vulkan API 163 | // The 'getInstanceProcAddr' passed to the callback is the function pointer from the Vulkan Loader 164 | // The function pointer returned from UnityVulkanInitCallback may be a different implementation 165 | // This allows intercepting all Vulkan API calls 166 | // 167 | // Most rules/restrictions for implementing a Vulkan layer apply 168 | // Returns true on success, false on failure (typically because it is used too late) 169 | bool(UNITY_INTERFACE_API * InterceptInitialization)(UnityVulkanInitCallback func, void* userdata); 170 | 171 | // Intercept Vulkan API function of the given name with the given function 172 | // In contrast to InterceptInitialization this interface can be used at any time 173 | // The user must handle all synchronization 174 | // Generally this cannot be used to wrap Vulkan object because there might because there may already be non-wrapped instances 175 | // returns the previous function pointer 176 | PFN_vkVoidFunction(UNITY_INTERFACE_API * InterceptVulkanAPI)(const char* name, PFN_vkVoidFunction func); 177 | 178 | // Change the precondition for a specific user-defined event 179 | // Should be called during initialization 180 | void(UNITY_INTERFACE_API * ConfigureEvent)(int eventID, const UnityVulkanPluginEventConfig * pluginEventConfig); 181 | 182 | // Access the Vulkan instance and render queue created by Unity 183 | // UnityVulkanInstance does not change between kUnityGfxDeviceEventInitialize and kUnityGfxDeviceEventShutdown 184 | UnityVulkanInstance(UNITY_INTERFACE_API * Instance)(); 185 | 186 | // Access the current command buffer 187 | // 188 | // outCommandRecordingState is invalidated by any resource access calls. 189 | // queueAccess must be kUnityVulkanGraphicsQueueAccess_Allow when called from from a AccessQueue callback or from a event that is configured for queue access. 190 | // Otherwise queueAccess must be kUnityVulkanGraphicsQueueAccess_DontCare. 191 | bool(UNITY_INTERFACE_API * CommandRecordingState)(UnityVulkanRecordingState * outCommandRecordingState, UnityVulkanGraphicsQueueAccess queueAccess); 192 | 193 | // Resource access 194 | // 195 | // Using the following resource query APIs will mark the resources as used for the current frame. 196 | // Pipeline barriers will be inserted when needed. 197 | // 198 | // Resource access APIs may record commands, so the current UnityVulkanRecordingState is invalidated 199 | // Must not be called from event callbacks configured for queue access (UnityVulkanGraphicsQueueAccess_Allow) 200 | // or from a AccessQueue callback of an event 201 | bool(UNITY_INTERFACE_API * AccessTexture)(void* nativeTexture, const VkImageSubresource * subResource, VkImageLayout layout, 202 | VkPipelineStageFlags pipelineStageFlags, VkAccessFlags accessFlags, UnityVulkanResourceAccessMode accessMode, UnityVulkanImage * outImage); 203 | 204 | bool(UNITY_INTERFACE_API * AccessRenderBufferTexture)(UnityRenderBuffer nativeRenderBuffer, const VkImageSubresource * subResource, VkImageLayout layout, 205 | VkPipelineStageFlags pipelineStageFlags, VkAccessFlags accessFlags, UnityVulkanResourceAccessMode accessMode, UnityVulkanImage * outImage); 206 | 207 | bool(UNITY_INTERFACE_API * AccessRenderBufferResolveTexture)(UnityRenderBuffer nativeRenderBuffer, const VkImageSubresource * subResource, VkImageLayout layout, 208 | VkPipelineStageFlags pipelineStageFlags, VkAccessFlags accessFlags, UnityVulkanResourceAccessMode accessMode, UnityVulkanImage * outImage); 209 | 210 | bool(UNITY_INTERFACE_API * AccessBuffer)(void* nativeBuffer, VkPipelineStageFlags pipelineStageFlags, VkAccessFlags accessFlags, UnityVulkanResourceAccessMode accessMode, UnityVulkanBuffer * outBuffer); 211 | 212 | // Control current state of render pass 213 | // 214 | // Must not be called from event callbacks configured for queue access (UnityVulkanGraphicsQueueAccess_Allow, UnityVulkanGraphicsQueueAccess_FlushAndAllow) 215 | // or from a AccessQueue callback of an event 216 | // See kUnityVulkanRenderPass_EnsureInside, kUnityVulkanRenderPass_EnsureOutside 217 | void(UNITY_INTERFACE_API * EnsureOutsideRenderPass)(); 218 | void(UNITY_INTERFACE_API * EnsureInsideRenderPass)(); 219 | 220 | // Allow command buffer submission to the the Vulkan graphics queue from the given UnityRenderingEventAndData callback. 221 | // This is an alternative to using ConfigureEvent with kUnityVulkanGraphicsQueueAccess_Allow. 222 | // 223 | // eventId and userdata are passed to the callback 224 | // This may or may not be called synchronously or from the submission thread. 225 | // If flush is true then all Unity command buffers of this frame are submitted before UnityQueueAccessCallback 226 | void(UNITY_INTERFACE_API * AccessQueue)(UnityRenderingEventAndData, int eventId, void* userData, bool flush); 227 | 228 | // Configure swapchains that are created by Unity. 229 | // Must be called before kUnityGfxDeviceEventInitialize (preload plugin) 230 | bool(UNITY_INTERFACE_API * ConfigureSwapchain)(const UnityVulkanSwapchainConfiguration * swapChainConfig); 231 | 232 | // see AccessTexture 233 | // Accepts UnityTextureID (UnityRenderingExtTextureUpdateParamsV2::textureID, UnityRenderingExtCustomBlitParams::source) 234 | bool(UNITY_INTERFACE_API * AccessTextureByID)(UnityTextureID textureID, const VkImageSubresource * subResource, VkImageLayout layout, 235 | VkPipelineStageFlags pipelineStageFlags, VkAccessFlags accessFlags, UnityVulkanResourceAccessMode accessMode, UnityVulkanImage * outImage); 236 | }; 237 | UNITY_REGISTER_INTERFACE_GUID(0x95355348d4ef4e11ULL, 0x9789313dfcffcc87ULL, IUnityGraphicsVulkan) 238 | -------------------------------------------------------------------------------- /InkingTextureLoader/ThirdParty/UnityPluginAPI/IUnityInterface.h: -------------------------------------------------------------------------------- 1 | // Unity Native Plugin API copyright © 2015 Unity Technologies ApS 2 | // 3 | // Licensed under the Unity Companion License for Unity - dependent projects--see[Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License). 4 | // 5 | // Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.Please review the license for details on these and other terms and conditions. 6 | 7 | #pragma once 8 | 9 | // Unity native plugin API 10 | // Compatible with C99 11 | 12 | #if defined(__CYGWIN32__) 13 | #define UNITY_INTERFACE_API __stdcall 14 | #define UNITY_INTERFACE_EXPORT __declspec(dllexport) 15 | #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) || defined(WINAPI_FAMILY) 16 | #define UNITY_INTERFACE_API __stdcall 17 | #define UNITY_INTERFACE_EXPORT __declspec(dllexport) 18 | #elif defined(__MACH__) || defined(__ANDROID__) || defined(__linux__) || defined(LUMIN) 19 | #define UNITY_INTERFACE_API 20 | #define UNITY_INTERFACE_EXPORT __attribute__ ((visibility ("default"))) 21 | #else 22 | #define UNITY_INTERFACE_API 23 | #define UNITY_INTERFACE_EXPORT 24 | #endif 25 | 26 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 27 | // IUnityInterface is a registry of interfaces we choose to expose to plugins. 28 | // 29 | // USAGE: 30 | // --------- 31 | // To retrieve an interface a user can do the following from a plugin, assuming they have the header file for the interface: 32 | // 33 | // IMyInterface * ptr = registry->Get(); 34 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 35 | 36 | // Unity Interface GUID 37 | // Ensures global uniqueness. 38 | // 39 | // Template specialization is used to produce a means of looking up a GUID from its interface type at compile time. 40 | // The net result should compile down to passing around the GUID. 41 | // 42 | // UNITY_REGISTER_INTERFACE_GUID should be placed in the header file of any interface definition outside of all namespaces. 43 | // The interface structure and the registration GUID are all that is required to expose the interface to other systems. 44 | struct UnityInterfaceGUID 45 | { 46 | #ifdef __cplusplus 47 | UnityInterfaceGUID(unsigned long long high, unsigned long long low) 48 | : m_GUIDHigh(high) 49 | , m_GUIDLow(low) 50 | { 51 | } 52 | 53 | UnityInterfaceGUID(const UnityInterfaceGUID& other) 54 | { 55 | m_GUIDHigh = other.m_GUIDHigh; 56 | m_GUIDLow = other.m_GUIDLow; 57 | } 58 | 59 | UnityInterfaceGUID& operator=(const UnityInterfaceGUID& other) 60 | { 61 | m_GUIDHigh = other.m_GUIDHigh; 62 | m_GUIDLow = other.m_GUIDLow; 63 | return *this; 64 | } 65 | 66 | bool Equals(const UnityInterfaceGUID& other) const { return m_GUIDHigh == other.m_GUIDHigh && m_GUIDLow == other.m_GUIDLow; } 67 | bool LessThan(const UnityInterfaceGUID& other) const { return m_GUIDHigh < other.m_GUIDHigh || (m_GUIDHigh == other.m_GUIDHigh && m_GUIDLow < other.m_GUIDLow); } 68 | #endif 69 | unsigned long long m_GUIDHigh; 70 | unsigned long long m_GUIDLow; 71 | }; 72 | #ifdef __cplusplus 73 | inline bool operator==(const UnityInterfaceGUID& left, const UnityInterfaceGUID& right) { return left.Equals(right); } 74 | inline bool operator!=(const UnityInterfaceGUID& left, const UnityInterfaceGUID& right) { return !left.Equals(right); } 75 | inline bool operator<(const UnityInterfaceGUID& left, const UnityInterfaceGUID& right) { return left.LessThan(right); } 76 | inline bool operator>(const UnityInterfaceGUID& left, const UnityInterfaceGUID& right) { return right.LessThan(left); } 77 | inline bool operator>=(const UnityInterfaceGUID& left, const UnityInterfaceGUID& right) { return !operator<(left, right); } 78 | inline bool operator<=(const UnityInterfaceGUID& left, const UnityInterfaceGUID& right) { return !operator>(left, right); } 79 | #else 80 | typedef struct UnityInterfaceGUID UnityInterfaceGUID; 81 | #endif 82 | 83 | 84 | #ifdef __cplusplus 85 | #define UNITY_DECLARE_INTERFACE(NAME) \ 86 | struct NAME : IUnityInterface 87 | 88 | // Generic version of GetUnityInterfaceGUID to allow us to specialize it 89 | // per interface below. The generic version has no actual implementation 90 | // on purpose. 91 | // 92 | // If you get errors about return values related to this method then 93 | // you have forgotten to include UNITY_REGISTER_INTERFACE_GUID with 94 | // your interface, or it is not visible at some point when you are 95 | // trying to retrieve or add an interface. 96 | template 97 | inline const UnityInterfaceGUID GetUnityInterfaceGUID(); 98 | 99 | // This is the macro you provide in your public interface header 100 | // outside of a namespace to allow us to map between type and GUID 101 | // without the user having to worry about it when attempting to 102 | // add or retrieve and interface from the registry. 103 | #define UNITY_REGISTER_INTERFACE_GUID(HASHH, HASHL, TYPE) \ 104 | template<> \ 105 | inline const UnityInterfaceGUID GetUnityInterfaceGUID() \ 106 | { \ 107 | return UnityInterfaceGUID(HASHH,HASHL); \ 108 | } 109 | 110 | // Same as UNITY_REGISTER_INTERFACE_GUID but allows the interface to live in 111 | // a particular namespace. As long as the namespace is visible at the time you call 112 | // GetUnityInterfaceGUID< INTERFACETYPE >() or you explicitly qualify it in the template 113 | // calls this will work fine, only the macro here needs to have the additional parameter 114 | #define UNITY_REGISTER_INTERFACE_GUID_IN_NAMESPACE(HASHH, HASHL, TYPE, NAMESPACE) \ 115 | const UnityInterfaceGUID TYPE##_GUID(HASHH, HASHL); \ 116 | template<> \ 117 | inline const UnityInterfaceGUID GetUnityInterfaceGUID< NAMESPACE :: TYPE >() \ 118 | { \ 119 | return UnityInterfaceGUID(HASHH,HASHL); \ 120 | } 121 | 122 | // These macros allow for C compatibility in user code. 123 | #define UNITY_GET_INTERFACE_GUID(TYPE) GetUnityInterfaceGUID< TYPE >() 124 | 125 | 126 | #else 127 | #define UNITY_DECLARE_INTERFACE(NAME) \ 128 | typedef struct NAME NAME; \ 129 | struct NAME 130 | 131 | // NOTE: This has the downside that one some compilers it will not get stripped from all compilation units that 132 | // can see a header containing this constant. However, it's only for C compatibility and thus should have 133 | // minimal impact. 134 | #define UNITY_REGISTER_INTERFACE_GUID(HASHH, HASHL, TYPE) \ 135 | const UnityInterfaceGUID TYPE##_GUID = {HASHH, HASHL}; 136 | 137 | // In general namespaces are going to be a problem for C code any interfaces we expose in a namespace are 138 | // not going to be usable from C. 139 | #define UNITY_REGISTER_INTERFACE_GUID_IN_NAMESPACE(HASHH, HASHL, TYPE, NAMESPACE) 140 | 141 | // These macros allow for C compatibility in user code. 142 | #define UNITY_GET_INTERFACE_GUID(TYPE) TYPE##_GUID 143 | #endif 144 | 145 | // Using this in user code rather than INTERFACES->Get() will be C compatible for those places in plugins where 146 | // this may be needed. Unity code itself does not need this. 147 | #define UNITY_GET_INTERFACE(INTERFACES, TYPE) (TYPE*)INTERFACES->GetInterfaceSplit (UNITY_GET_INTERFACE_GUID(TYPE).m_GUIDHigh, UNITY_GET_INTERFACE_GUID(TYPE).m_GUIDLow); 148 | 149 | 150 | #ifdef __cplusplus 151 | struct IUnityInterface 152 | { 153 | }; 154 | #else 155 | typedef void IUnityInterface; 156 | #endif 157 | 158 | 159 | typedef struct IUnityInterfaces 160 | { 161 | // Returns an interface matching the guid. 162 | // Returns nullptr if the given interface is unavailable in the active Unity runtime. 163 | IUnityInterface* (UNITY_INTERFACE_API * GetInterface)(UnityInterfaceGUID guid); 164 | 165 | // Registers a new interface. 166 | void(UNITY_INTERFACE_API * RegisterInterface)(UnityInterfaceGUID guid, IUnityInterface * ptr); 167 | 168 | // Split APIs for C 169 | IUnityInterface* (UNITY_INTERFACE_API * GetInterfaceSplit)(unsigned long long guidHigh, unsigned long long guidLow); 170 | void(UNITY_INTERFACE_API * RegisterInterfaceSplit)(unsigned long long guidHigh, unsigned long long guidLow, IUnityInterface * ptr); 171 | 172 | #ifdef __cplusplus 173 | // Helper for GetInterface. 174 | template 175 | INTERFACE* Get() 176 | { 177 | return static_cast(GetInterface(GetUnityInterfaceGUID())); 178 | } 179 | 180 | // Helper for RegisterInterface. 181 | template 182 | void Register(IUnityInterface* ptr) 183 | { 184 | RegisterInterface(GetUnityInterfaceGUID(), ptr); 185 | } 186 | 187 | #endif 188 | } IUnityInterfaces; 189 | 190 | 191 | #ifdef __cplusplus 192 | extern "C" { 193 | #endif 194 | 195 | // If exported by a plugin, this function will be called when the plugin is loaded. 196 | void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfaces); 197 | // If exported by a plugin, this function will be called when the plugin is about to be unloaded. 198 | void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginUnload(); 199 | 200 | #ifdef __cplusplus 201 | } 202 | #endif 203 | 204 | struct RenderSurfaceBase; 205 | typedef struct RenderSurfaceBase* UnityRenderBuffer; 206 | typedef unsigned int UnityTextureID; 207 | -------------------------------------------------------------------------------- /InkingTextureLoader/ThirdParty/UnityPluginAPI/IUnityProfilerCallbacks.h: -------------------------------------------------------------------------------- 1 | // Unity Native Plugin API copyright © 2015 Unity Technologies ApS 2 | // 3 | // Licensed under the Unity Companion License for Unity - dependent projects--see[Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License). 4 | // 5 | // Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.Please review the license for details on these and other terms and conditions. 6 | 7 | #pragma once 8 | #include "IUnityInterface.h" 9 | 10 | #include 11 | 12 | // Unity Profiler Native plugin API provides an ability to register callbacks for Unity Profiler events. 13 | // The basic functionality includes: 14 | // 1. Category callback - provides information about category name and color. 15 | // 2. Profiler marker callback - provides information about new marker which is created internally or with C# API. 16 | // 3. Marker event callback - allows to intercept begin/end events for the particular marker. 17 | // 4. Frame event callback - provides information about logical CPU frame. 18 | // 19 | // Usage example: 20 | // 21 | // #include 22 | // #include 23 | // 24 | // static IUnityProfilerCallbacks* s_UnityProfilerCallbacks = NULL; 25 | // 26 | // static void UNITY_INTERFACE_API MyProfilerEventCallback(const UnityProfilerMarkerDesc* markerDesc, UnityProfilerMarkerEventType eventType, unsigned short eventDataCount, const UnityProfilerMarkerData* eventData, void* userData) 27 | // { 28 | // switch (eventType) 29 | // { 30 | // case kUnityProfilerMarkerEventTypeBegin: 31 | // { 32 | // MyProfilerPushMarker(markerDesc->name); 33 | // break; 34 | // } 35 | // case kUnityProfilerMarkerEventTypeEnd: 36 | // { 37 | // MyProfilerPopMarker(markerDesc->name); 38 | // break; 39 | // } 40 | // } 41 | // } 42 | // 43 | // static void UNITY_INTERFACE_API MyProfilerCreateEventCallback(const UnityProfilerMarkerDesc* markerDesc, void* userData) 44 | // { 45 | // s_UnityProfilerCallbacks->RegisterEventCallback(markerDesc, MyProfilerEventCallback, NULL); 46 | // } 47 | // 48 | // extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfaces) 49 | // { 50 | // s_UnityProfilerCallbacks = unityInterfaces->Get(); 51 | // s_UnityProfilerCallbacks->RegisterCreateEventCallback(&MyProfilerCreateEventCallback, NULL); 52 | // } 53 | // 54 | // extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginUnload() 55 | // { 56 | // s_UnityProfilerCallbacks->UnregisterCreateEventCallback(&MyProfilerCreateEventCallback, NULL); 57 | // s_UnityProfilerCallbacks->UnregisterEventCallback(NULL, &MyProfilerEventCallback, NULL); 58 | // } 59 | 60 | 61 | typedef uint32_t UnityProfilerMarkerId; 62 | typedef uint16_t UnityProfilerCategoryId; 63 | typedef uint64_t UnityProfilerThreadId; 64 | 65 | typedef struct UnityProfilerCategoryDesc 66 | { 67 | // Incremental category index. 68 | UnityProfilerCategoryId id; 69 | // Reserved. 70 | uint16_t reserved0; 71 | // Internally associated category color which is in 0xRRGGBBAA format. 72 | uint32_t rgbaColor; 73 | // NULL-terminated string which is associated with the category. 74 | const char* name; 75 | } UnityProfilerCategoryDesc; 76 | 77 | enum UnityProfilerMarkerFlag_ 78 | { 79 | kUnityProfilerMarkerFlagDefault = 0, 80 | 81 | kUnityProfilerMarkerFlagScriptUser = 1 << 1, // Markers created with C# API. 82 | kUnityProfilerMarkerFlagScriptInvoke = 1 << 5, // Runtime invocations with ScriptingInvocation::Invoke. 83 | kUnityProfilerMarkerFlagScriptEnterLeave = 1 << 6, // Deep profiler. 84 | 85 | kUnityProfilerMarkerFlagAvailabilityEditor = 1 << 2, // Editor-only marker, doesn't present in dev and non-dev players. 86 | kUnityProfilerMarkerFlagAvailabilityNonDev = 1 << 3, // Non-dev marker, present everywhere. 87 | 88 | kUnityProfilerMarkerFlagWarning = 1 << 4, // Indicates undesirable, performance-wise suboptimal code path. 89 | 90 | kUnityProfilerMarkerFlagVerbosityDebug = 1 << 10, // Internal debug markers - e.g. JobSystem Idle. 91 | kUnityProfilerMarkerFlagVerbosityInternal = 1 << 11, // Internal markers - e.g. Mutex/semaphore waits. 92 | kUnityProfilerMarkerFlagVerbosityAdvanced = 1 << 12 // Markers which are useful for advanced users - e.g. Loading. 93 | }; 94 | typedef uint16_t UnityProfilerMarkerFlags; 95 | 96 | enum UnityProfilerMarkerEventType_ 97 | { 98 | kUnityProfilerMarkerEventTypeBegin = 0, 99 | kUnityProfilerMarkerEventTypeEnd = 1, 100 | kUnityProfilerMarkerEventTypeSingle = 2 101 | }; 102 | typedef uint16_t UnityProfilerMarkerEventType; 103 | 104 | typedef struct UnityProfilerMarkerDesc 105 | { 106 | // Per-marker callback chain pointer. Don't use. 107 | const void* callback; 108 | // Event id. 109 | UnityProfilerMarkerId id; 110 | // UnityProfilerMarkerFlag_ value. 111 | UnityProfilerMarkerFlags flags; 112 | // Category index the marker belongs to. 113 | UnityProfilerCategoryId categoryId; 114 | // NULL-terminated string which is associated with the marker. 115 | const char* name; 116 | // Metadata descriptions chain. Don't use. 117 | const void* metaDataDesc; 118 | } UnityProfilerMarkerDesc; 119 | 120 | enum UnityProfilerMarkerDataType_ 121 | { 122 | kUnityProfilerMarkerDataTypeNone = 0, 123 | kUnityProfilerMarkerDataTypeInstanceId = 1, 124 | kUnityProfilerMarkerDataTypeInt32 = 2, 125 | kUnityProfilerMarkerDataTypeUInt32 = 3, 126 | kUnityProfilerMarkerDataTypeInt64 = 4, 127 | kUnityProfilerMarkerDataTypeUInt64 = 5, 128 | kUnityProfilerMarkerDataTypeFloat = 6, 129 | kUnityProfilerMarkerDataTypeDouble = 7, 130 | kUnityProfilerMarkerDataTypeString = 8, 131 | kUnityProfilerMarkerDataTypeString16 = 9, 132 | kUnityProfilerMarkerDataTypeBlob8 = 11 133 | }; 134 | typedef uint8_t UnityProfilerMarkerDataType; 135 | 136 | typedef struct UnityProfilerMarkerData 137 | { 138 | UnityProfilerMarkerDataType type; 139 | uint8_t reserved0; 140 | uint16_t reserved1; 141 | uint32_t size; 142 | const void* ptr; 143 | } UnityProfilerMarkerData; 144 | 145 | enum UnityProfilerFlowEventType_ 146 | { 147 | // The flow began withing a current marker scope (enclosed scope). 148 | kUnityProfilerFlowEventTypeBegin = 0, 149 | // The flow continues with the next sample. 150 | kUnityProfilerFlowEventTypeNext = 1, 151 | // The flow ends with the next sample. 152 | kUnityProfilerFlowEventTypeEnd = 2, 153 | }; 154 | typedef uint8_t UnityProfilerFlowEventType; 155 | 156 | typedef struct UnityProfilerThreadDesc 157 | { 158 | // Thread id c-casted to uint64_t. 159 | uint64_t threadId; 160 | // Thread group name. NULL-terminated. 161 | const char* groupName; 162 | // Thread name. NULL-terminated. 163 | const char* name; 164 | } UnityProfilerThreadDesc; 165 | 166 | // Called when a new category is created. Up to 4 installed callbacks are supported. 167 | // \param categoryDesc is a pointer to category description. 168 | // \param userData is an optional context pointer passed with RegisterCreateCategoryCallback call. 169 | typedef void (UNITY_INTERFACE_API * IUnityProfilerCreateCategoryCallback)(const UnityProfilerCategoryDesc* categoryDesc, void* userData); 170 | 171 | // Called when a new profiler marker is created. Up to 4 installed callbacks are supported. 172 | // \param markerDesc is a pointer to marker description. 173 | // \param userData is an optional context pointer passed with RegisterCreateEventCallback call. 174 | typedef void (UNITY_INTERFACE_API * IUnityProfilerCreateMarkerCallback)(const UnityProfilerMarkerDesc* markerDesc, void* userData); 175 | 176 | // Called when a profiler event occurs. 177 | // \param markerDesc is an marker description struct. 178 | // \param eventType is an event type - UnityProfilerMarkerEventType_. 179 | // \param eventDataCount is an event metadata count. 180 | // \param eventData is a metadata array of eventDataCount elements. 181 | // \param userData is an optional context pointer passed with RegisterCreateEventCallback call. 182 | typedef void (UNITY_INTERFACE_API * IUnityProfilerMarkerEventCallback)(const UnityProfilerMarkerDesc* markerDesc, UnityProfilerMarkerEventType eventType, uint16_t eventDataCount, const UnityProfilerMarkerData* eventData, void* userData); 183 | 184 | // Called when a profiler frame change occurs. Up to 4 installed callbacks are supported. 185 | // \param userData is an optional context pointer passed with RegisterCreateEventCallback call. 186 | typedef void (UNITY_INTERFACE_API * IUnityProfilerFrameCallback)(void* userData); 187 | 188 | // Called when a profiler frame change occurs. Up to 4 installed callbacks are supported. 189 | // \param userData is an optional context pointer passed with RegisterCreateEventCallback call. 190 | typedef void (UNITY_INTERFACE_API * IUnityProfilerThreadCallback)(const UnityProfilerThreadDesc* threadDesc, void* userData); 191 | 192 | // Called when a profiler flow event occurs. 193 | // Flow events connect events across threads allowing to trace related activities initiated from a control(main) thread. 194 | // \param flowEventType is a flow event type. 195 | // \param flowId is an unique incremental identifier for the flow chain. 196 | // \param userData is an optional context pointer passed with RegisterCreateEventCallback call. 197 | typedef void (UNITY_INTERFACE_API * IUnityProfilerFlowEventCallback)(UnityProfilerFlowEventType flowEventType, uint32_t flowId, void* userData); 198 | 199 | // Available since 2019.1 200 | UNITY_DECLARE_INTERFACE(IUnityProfilerCallbacksV2) 201 | { 202 | // Register a callback which is called when a new category is created. 203 | // Returns 0 on success and non-zero in case of error. 204 | // Only up to 4 callbacks can be registered. 205 | int(UNITY_INTERFACE_API * RegisterCreateCategoryCallback)(IUnityProfilerCreateCategoryCallback callback, void* userData); 206 | int(UNITY_INTERFACE_API * UnregisterCreateCategoryCallback)(IUnityProfilerCreateCategoryCallback callback, void* userData); 207 | 208 | // Register a callback which is called when a new marker is created. 209 | // E.g. dynamically created in C# with "new PerformanceMarker(string)" or internally. 210 | // Also is called for all existing markers when the callback is registered. 211 | // Returns 0 on success and non-zero in case of error. 212 | // Only up to 4 callbacks can be registered. 213 | int(UNITY_INTERFACE_API * RegisterCreateMarkerCallback)(IUnityProfilerCreateMarkerCallback callback, void* userData); 214 | int(UNITY_INTERFACE_API * UnregisterCreateMarkerCallback)(IUnityProfilerCreateMarkerCallback callback, void* userData); 215 | 216 | // Register a callback which is called every time "PerformanceMarker.Begin(string)" is called or equivalent internal native counterpart. 217 | // Returns 0 on success and non-zero in case of error. 218 | // \param markerDesc is a pointer to marker description you want to install callback for. 219 | int(UNITY_INTERFACE_API * RegisterMarkerEventCallback)(const UnityProfilerMarkerDesc * markerDesc, IUnityProfilerMarkerEventCallback callback, void* userData); 220 | // Unregister per-marker callback. 221 | // \param markerDesc is a pointer to marker description you want to remove callback from. 222 | // \param userData optional context pointer. 223 | // If markerDesc is NULL, callback is removed from all events which have (callback, userData) pair. 224 | // If both markerDesc and userData are NULL, callback is removed from all events which have callback function pointer. 225 | int(UNITY_INTERFACE_API * UnregisterMarkerEventCallback)(const UnityProfilerMarkerDesc * markerDesc, IUnityProfilerMarkerEventCallback callback, void* userData); 226 | 227 | // Register a callback which is called every time Profiler.BeginSample is called or equivalent internal native counterpart. 228 | // Returns 0 on success and non-zero in case of error. 229 | // Only up to 4 callbacks can be registered. 230 | int(UNITY_INTERFACE_API * RegisterFrameCallback)(IUnityProfilerFrameCallback callback, void* userData); 231 | int(UNITY_INTERFACE_API * UnregisterFrameCallback)(IUnityProfilerFrameCallback callback, void* userData); 232 | 233 | // Register a callback which is called every time a new thread is registered with profiler. 234 | // Returns 0 on success and non-zero in case of error. 235 | // Only up to 4 callbacks can be registered. 236 | int(UNITY_INTERFACE_API * RegisterCreateThreadCallback)(IUnityProfilerThreadCallback callback, void* userData); 237 | int(UNITY_INTERFACE_API * UnregisterCreateThreadCallback)(IUnityProfilerThreadCallback callback, void* userData); 238 | 239 | // Register a callback which is called every time Unity generates a flow event. 240 | // Returns 0 on success and non-zero in case of error. 241 | // Note: Flow events are supported only in Development Players and Editor. 242 | int(UNITY_INTERFACE_API * RegisterFlowEventCallback)(IUnityProfilerFlowEventCallback callback, void* userData); 243 | // Unregister flow event callback. 244 | // \param userData optional context pointer. 245 | int(UNITY_INTERFACE_API * UnregisterFlowEventCallback)(IUnityProfilerFlowEventCallback callback, void* userData); 246 | }; 247 | UNITY_REGISTER_INTERFACE_GUID(0x5DEB59E88F2D4571ULL, 0x81E8583069A5E33CULL, IUnityProfilerCallbacksV2) 248 | 249 | // Available since 2018.2 250 | UNITY_DECLARE_INTERFACE(IUnityProfilerCallbacks) 251 | { 252 | int(UNITY_INTERFACE_API * RegisterCreateCategoryCallback)(IUnityProfilerCreateCategoryCallback callback, void* userData); 253 | int(UNITY_INTERFACE_API * UnregisterCreateCategoryCallback)(IUnityProfilerCreateCategoryCallback callback, void* userData); 254 | 255 | int(UNITY_INTERFACE_API * RegisterCreateMarkerCallback)(IUnityProfilerCreateMarkerCallback callback, void* userData); 256 | int(UNITY_INTERFACE_API * UnregisterCreateMarkerCallback)(IUnityProfilerCreateMarkerCallback callback, void* userData); 257 | 258 | int(UNITY_INTERFACE_API * RegisterMarkerEventCallback)(const UnityProfilerMarkerDesc * markerDesc, IUnityProfilerMarkerEventCallback callback, void* userData); 259 | int(UNITY_INTERFACE_API * UnregisterMarkerEventCallback)(const UnityProfilerMarkerDesc * markerDesc, IUnityProfilerMarkerEventCallback callback, void* userData); 260 | 261 | int(UNITY_INTERFACE_API * RegisterFrameCallback)(IUnityProfilerFrameCallback callback, void* userData); 262 | int(UNITY_INTERFACE_API * UnregisterFrameCallback)(IUnityProfilerFrameCallback callback, void* userData); 263 | 264 | int(UNITY_INTERFACE_API * RegisterCreateThreadCallback)(IUnityProfilerThreadCallback callback, void* userData); 265 | int(UNITY_INTERFACE_API * UnregisterCreateThreadCallback)(IUnityProfilerThreadCallback callback, void* userData); 266 | }; 267 | UNITY_REGISTER_INTERFACE_GUID(0x572FDB38CE3C4B1FULL, 0xA6071A9A7C4F52D8ULL, IUnityProfilerCallbacks) 268 | -------------------------------------------------------------------------------- /InkingTextureLoader/ThirdParty/UnityPluginAPI/IUnityShaderCompilerAccess.h: -------------------------------------------------------------------------------- 1 | // Unity Native Plugin API copyright © 2015 Unity Technologies ApS 2 | // 3 | // Licensed under the Unity Companion License for Unity - dependent projects--see[Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License). 4 | // 5 | // Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.Please review the license for details on these and other terms and conditions. 6 | 7 | #pragma once 8 | 9 | 10 | #include "IUnityGraphics.h" 11 | 12 | 13 | /* 14 | Low-level Native Plugin Shader Compiler Access 15 | ============================================== 16 | 17 | On top of the Low-level native plugin interface, Unity also supports low level access to the shader compiler, allowing the user to inject different variants into a shader. 18 | It is also an event driven approach in which the plugin will receive callbacks when certain builtin events happen. 19 | */ 20 | 21 | 22 | enum UnityShaderCompilerExtCompilerPlatform 23 | { 24 | kUnityShaderCompilerExtCompPlatformUnused0 = 0, 25 | kUnityShaderCompilerExtCompPlatformUnused1, 26 | kUnityShaderCompilerExtCompPlatformUnused2, 27 | kUnityShaderCompilerExtCompPlatformUnused3, 28 | kUnityShaderCompilerExtCompPlatformD3D11, // Direct3D 11 (FL10.0 and up), compiled with MS D3DCompiler 29 | kUnityShaderCompilerExtCompPlatformGLES20, // OpenGL ES 2.0 / WebGL 1.0, compiled with MS D3DCompiler + HLSLcc 30 | kUnityShaderCompilerExtCompPlatformUnused6, 31 | kUnityShaderCompilerExtCompPlatformUnused7, 32 | kUnityShaderCompilerExtCompPlatformUnused8, 33 | kUnityShaderCompilerExtCompPlatformGLES3Plus, // OpenGL ES 3.0+ / WebGL 2.0, compiled with MS D3DCompiler + HLSLcc 34 | kUnityShaderCompilerExtCompPlatformUnused10, 35 | kUnityShaderCompilerExtCompPlatformPS4, // Sony PS4 36 | kUnityShaderCompilerExtCompPlatformXboxOne, // MS XboxOne 37 | kUnityShaderCompilerExtCompPlatformUnused13, 38 | kUnityShaderCompilerExtCompPlatformMetal, // Apple Metal, compiled with MS D3DCompiler + HLSLcc 39 | kUnityShaderCompilerExtCompPlatformOpenGLCore, // Desktop OpenGL 3+, compiled with MS D3DCompiler + HLSLcc 40 | kUnityShaderCompilerExtCompPlatformUnused16, 41 | kUnityShaderCompilerExtCompPlatformUnused17, 42 | kUnityShaderCompilerExtCompPlatformVulkan, // Vulkan SPIR-V, compiled with MS D3DCompiler + HLSLcc 43 | kUnityShaderCompilerExtCompPlatformSwitch, // Nintendo Switch (NVN) 44 | kUnityShaderCompilerExtCompPlatformXboxOneD3D12, // Xbox One D3D12 45 | kUnityShaderCompilerExtCompPlatformCount 46 | }; 47 | 48 | 49 | enum UnityShaderCompilerExtShaderType 50 | { 51 | kUnityShaderCompilerExtShaderNone = 0, 52 | kUnityShaderCompilerExtShaderVertex = 1, 53 | kUnityShaderCompilerExtShaderFragment = 2, 54 | kUnityShaderCompilerExtShaderGeometry = 3, 55 | kUnityShaderCompilerExtShaderHull = 4, 56 | kUnityShaderCompilerExtShaderDomain = 5, 57 | kUnityShaderCompilerExtShaderRayTracing = 6, 58 | kUnityShaderCompilerExtShaderTypeCount // keep this last! 59 | }; 60 | 61 | 62 | enum UnityShaderCompilerExtGPUProgramType 63 | { 64 | kUnityShaderCompilerExtGPUProgramTargetUnknown = 0, 65 | 66 | kUnityShaderCompilerExtGPUProgramTargetGLLegacy = 1, // removed 67 | kUnityShaderCompilerExtGPUProgramTargetGLES31AEP = 2, 68 | kUnityShaderCompilerExtGPUProgramTargetGLES31 = 3, 69 | kUnityShaderCompilerExtGPUProgramTargetGLES3 = 4, 70 | kUnityShaderCompilerExtGPUProgramTargetGLES = 5, 71 | kUnityShaderCompilerExtGPUProgramTargetGLCore32 = 6, 72 | kUnityShaderCompilerExtGPUProgramTargetGLCore41 = 7, 73 | kUnityShaderCompilerExtGPUProgramTargetGLCore43 = 8, 74 | kUnityShaderCompilerExtGPUProgramTargetDX9VertexSM20 = 9, // removed 75 | kUnityShaderCompilerExtGPUProgramTargetDX9VertexSM30 = 10, // removed 76 | kUnityShaderCompilerExtGPUProgramTargetDX9PixelSM20 = 11, // removed 77 | kUnityShaderCompilerExtGPUProgramTargetDX9PixelSM30 = 12, // removed 78 | kUnityShaderCompilerExtGPUProgramTargetDX10Level9Vertex = 13, 79 | kUnityShaderCompilerExtGPUProgramTargetDX10Level9Pixel = 14, 80 | kUnityShaderCompilerExtGPUProgramTargetDX11VertexSM40 = 15, 81 | kUnityShaderCompilerExtGPUProgramTargetDX11VertexSM50 = 16, 82 | kUnityShaderCompilerExtGPUProgramTargetDX11PixelSM40 = 17, 83 | kUnityShaderCompilerExtGPUProgramTargetDX11PixelSM50 = 18, 84 | kUnityShaderCompilerExtGPUProgramTargetDX11GeometrySM40 = 19, 85 | kUnityShaderCompilerExtGPUProgramTargetDX11GeometrySM50 = 20, 86 | kUnityShaderCompilerExtGPUProgramTargetDX11HullSM50 = 21, 87 | kUnityShaderCompilerExtGPUProgramTargetDX11DomainSM50 = 22, 88 | kUnityShaderCompilerExtGPUProgramTargetMetalVS = 23, 89 | kUnityShaderCompilerExtGPUProgramTargetMetalFS = 24, 90 | kUnityShaderCompilerExtGPUProgramTargetSPIRV = 25, 91 | kUnityShaderCompilerExtGPUProgramTargetUnused1 = 26, 92 | kUnityShaderCompilerExtGPUProgramTargetUnused2 = 27, 93 | kUnityShaderCompilerExtGPUProgramTargetUnused3 = 28, 94 | kUnityShaderCompilerExtGPUProgramTargetUnused4 = 29, 95 | kUnityShaderCompilerExtGPUProgramTargetUnused5 = 30, 96 | kUnityShaderCompilerExtGPUProgramTargetRayTracing = 31, 97 | 98 | kUnityShaderCompilerExtGPUProgramTargetCount 99 | }; 100 | 101 | 102 | enum UnityShaderCompilerExtGPUProgram 103 | { 104 | kUnityShaderCompilerExtGPUProgramVS = 1 << kUnityShaderCompilerExtShaderVertex, 105 | kUnityShaderCompilerExtGPUProgramPS = 1 << kUnityShaderCompilerExtShaderFragment, 106 | kUnityShaderCompilerExtGPUProgramGS = 1 << kUnityShaderCompilerExtShaderGeometry, 107 | kUnityShaderCompilerExtGPUProgramHS = 1 << kUnityShaderCompilerExtShaderHull, 108 | kUnityShaderCompilerExtGPUProgramDS = 1 << kUnityShaderCompilerExtShaderDomain, 109 | kUnityShaderCompilerExtGPUProgramCustom = 1 << kUnityShaderCompilerExtShaderTypeCount 110 | }; 111 | 112 | 113 | enum UnityShaderCompilerExtEventType 114 | { 115 | kUnityShaderCompilerExtEventCreateCustomSourceVariant, // The plugin can create a new variant based on the initial snippet. The callback will receive UnityShaderCompilerExtCustomSourceVariantParams as data. 116 | kUnityShaderCompilerExtEventCreateCustomSourceVariantCleanup, // Typically received after the kUnityShaderCompilerExtEventCreateCustomVariant event so the plugin has a chance to cleanup after itself. (outputSnippet & outputKeyword) 117 | 118 | kUnityShaderCompilerExtEventCreateCustomBinaryVariant, // The plugin can create a new variant based on the initial snippet. The callback will receive UnityShaderCompilerExtCustomBinaryVariantParams as data. 119 | kUnityShaderCompilerExtEventCreateCustomBinaryVariantCleanup, // Typically received after the kUnityShaderCompilerExtEventCreateCustomVariant event so the plugin has a chance to cleanup after itself. (outputSnippet & outputKeyword) 120 | kUnityShaderCompilerExtEventPluginConfigure, // Event sent so the plugin can configure itself. It receives IUnityShaderCompilerExtPluginConfigure* as data 121 | 122 | // keep these last 123 | kUnityShaderCompilerExtEventCount, 124 | kUnityShaderCompilerExtUserEventsStart = kUnityShaderCompilerExtEventCount 125 | }; 126 | 127 | 128 | struct UnityShaderCompilerExtCustomSourceVariantParams 129 | { 130 | char* outputSnippet; // snippet after the plugin has finished processing it. 131 | char* outputKeywords; // keywords exported by the plugin for this specific variant 132 | const char* inputSnippet; // the source shader snippet 133 | bool vr; // is VR enabled / supported ? 134 | UnityShaderCompilerExtCompilerPlatform platform; // compiler platform 135 | UnityShaderCompilerExtShaderType shaderType; // source code type 136 | }; 137 | 138 | 139 | struct UnityShaderCompilerExtCustomBinaryVariantParams 140 | { 141 | void** outputBinaryShader; // output of the plugin generated binary shader (platform dependent) 142 | const unsigned char* inputByteCode; // the shader byteCode (platform dependent) 143 | unsigned int inputByteCodeSize; // shader bytecode size 144 | unsigned int programTypeMask; // a mask of UnityShaderCompilerExtGPUProgram values 145 | UnityShaderCompilerExtCompilerPlatform platform; // compiler platform 146 | }; 147 | 148 | 149 | /* 150 | This class is queried by unity to get information about the plugin. 151 | The plugin has to set all the relevant values during the kUnityShaderCompilerExtEventPluginConfigure event. 152 | 153 | 154 | 155 | extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API 156 | UnityShaderCompilerExtEvent(UnityShaderCompilerExtEventType event, void* data) 157 | { 158 | switch (event) 159 | { 160 | 161 | ... 162 | 163 | case kUnityShaderCompilerExtEventPluginConfigure: 164 | { 165 | unsigned int GPUCompilerMask = (1 << kUnityShaderCompilerExtGPUProgramTargetDX11VertexSM40) 166 | | (1 << kUnityShaderCompilerExtGPUProgramTargetDX11VertexSM50) 167 | | (1 << kUnityShaderCompilerExtGPUProgramTargetDX11PixelSM40) 168 | | (1 << kUnityShaderCompilerExtGPUProgramTargetDX11PixelSM50) 169 | | (1 << kUnityShaderCompilerExtGPUProgramTargetDX11GeometrySM40) 170 | | (1 << kUnityShaderCompilerExtGPUProgramTargetDX11GeometrySM50) 171 | | (1 << kUnityShaderCompilerExtGPUProgramTargetDX11HullSM50) 172 | | (1 << kUnityShaderCompilerExtGPUProgramTargetDX11DomainSM50); 173 | 174 | unsigned int ShaderMask = kUnityShaderCompilerExtGPUProgramVS | kUnityShaderCompilerExtGPUProgramDS; 175 | 176 | IUnityShaderCompilerExtPluginConfigure* pluginConfig = (IUnityShaderCompilerExtPluginConfigure*)data; 177 | pluginConfig->ReserveKeyword(SHADER_KEYWORDS); 178 | pluginConfig->SetGPUProgramCompilerMask(GPUCompilerMask); 179 | pluginConfig->SetShaderProgramMask(ShaderMask); 180 | break; 181 | } 182 | } 183 | } 184 | 185 | 186 | */ 187 | 188 | class IUnityShaderCompilerExtPluginConfigure 189 | { 190 | public: 191 | virtual ~IUnityShaderCompilerExtPluginConfigure() {} 192 | virtual void ReserveKeyword(const char* keyword) = 0; // Allow the plugin to reserve its keyword so unity can include it in calculating the variants 193 | virtual void SetGPUProgramCompilerMask(unsigned int mask) = 0; // Specifies a bit mask of UnityShaderCompilerExtGPUProgramType programs the plugin supports compiling 194 | virtual void SetShaderProgramMask(unsigned int mask) = 0; // Specifies a bit mask of UnityShaderCompilerExtGPUProgram programs the plugin supports compiling 195 | }; 196 | 197 | 198 | // Interface to help setup / configure both unity and the plugin. 199 | 200 | 201 | #ifdef __cplusplus 202 | extern "C" { 203 | #endif 204 | 205 | // If exported by a plugin, this function will be called for all the events in UnityShaderCompilerExtEventType 206 | void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityShaderCompilerExtEvent(UnityShaderCompilerExtEventType event, void* data); 207 | 208 | #ifdef __cplusplus 209 | } 210 | #endif 211 | -------------------------------------------------------------------------------- /InkingTextureLoader/ThirdParty/UnityPluginAPI/LICENSE.md: -------------------------------------------------------------------------------- 1 | Unity Native Plugin API copyright © 2015 Unity Technologies ApS 2 | 3 | Licensed under the Unity Companion License for Unity-dependent projects--see [Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License). 4 | 5 | Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Please review the license for details on these and other terms and conditions. 6 | -------------------------------------------------------------------------------- /InkingTextureLoader/ThirdParty/stb_image/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.2.3) 2 | # Set project name 3 | project (STB_image) 4 | 5 | FILE (GLOB ALL_FILES "source/*.c" "source/*.h" "source/*.cpp") 6 | 7 | add_library("stb_image" ${ALL_FILES}) -------------------------------------------------------------------------------- /InkingTextureLoader/ThirdParty/stb_image/source/stb_easy_font.h: -------------------------------------------------------------------------------- 1 | // stb_easy_font.h - v1.1 - bitmap font for 3D rendering - public domain 2 | // Sean Barrett, Feb 2015 3 | // 4 | // Easy-to-deploy, 5 | // reasonably compact, 6 | // extremely inefficient performance-wise, 7 | // crappy-looking, 8 | // ASCII-only, 9 | // bitmap font for use in 3D APIs. 10 | // 11 | // Intended for when you just want to get some text displaying 12 | // in a 3D app as quickly as possible. 13 | // 14 | // Doesn't use any textures, instead builds characters out of quads. 15 | // 16 | // DOCUMENTATION: 17 | // 18 | // int stb_easy_font_width(char *text) 19 | // int stb_easy_font_height(char *text) 20 | // 21 | // Takes a string and returns the horizontal size and the 22 | // vertical size (which can vary if 'text' has newlines). 23 | // 24 | // int stb_easy_font_print(float x, float y, 25 | // char *text, unsigned char color[4], 26 | // void *vertex_buffer, int vbuf_size) 27 | // 28 | // Takes a string (which can contain '\n') and fills out a 29 | // vertex buffer with renderable data to draw the string. 30 | // Output data assumes increasing x is rightwards, increasing y 31 | // is downwards. 32 | // 33 | // The vertex data is divided into quads, i.e. there are four 34 | // vertices in the vertex buffer for each quad. 35 | // 36 | // The vertices are stored in an interleaved format: 37 | // 38 | // x:float 39 | // y:float 40 | // z:float 41 | // color:uint8[4] 42 | // 43 | // You can ignore z and color if you get them from elsewhere 44 | // This format was chosen in the hopes it would make it 45 | // easier for you to reuse existing vertex-buffer-drawing code. 46 | // 47 | // If you pass in NULL for color, it becomes 255,255,255,255. 48 | // 49 | // Returns the number of quads. 50 | // 51 | // If the buffer isn't large enough, it will truncate. 52 | // Expect it to use an average of ~270 bytes per character. 53 | // 54 | // If your API doesn't draw quads, build a reusable index 55 | // list that allows you to render quads as indexed triangles. 56 | // 57 | // void stb_easy_font_spacing(float spacing) 58 | // 59 | // Use positive values to expand the space between characters, 60 | // and small negative values (no smaller than -1.5) to contract 61 | // the space between characters. 62 | // 63 | // E.g. spacing = 1 adds one "pixel" of spacing between the 64 | // characters. spacing = -1 is reasonable but feels a bit too 65 | // compact to me; -0.5 is a reasonable compromise as long as 66 | // you're scaling the font up. 67 | // 68 | // LICENSE 69 | // 70 | // See end of file for license information. 71 | // 72 | // VERSION HISTORY 73 | // 74 | // (2020-02-02) 1.1 make everything static so can compile it in more than one src file 75 | // (2017-01-15) 1.0 space character takes same space as numbers; fix bad spacing of 'f' 76 | // (2016-01-22) 0.7 width() supports multiline text; add height() 77 | // (2015-09-13) 0.6 #include ; updated license 78 | // (2015-02-01) 0.5 First release 79 | // 80 | // CONTRIBUTORS 81 | // 82 | // github:vassvik -- bug report 83 | // github:podsvirov -- fix multiple definition errors 84 | 85 | #if 0 86 | // SAMPLE CODE: 87 | // 88 | // Here's sample code for old OpenGL; it's a lot more complicated 89 | // to make work on modern APIs, and that's your problem. 90 | // 91 | void print_string(float x, float y, char *text, float r, float g, float b) 92 | { 93 | static char buffer[99999]; // ~500 chars 94 | int num_quads; 95 | 96 | num_quads = stb_easy_font_print(x, y, text, NULL, buffer, sizeof(buffer)); 97 | 98 | glColor3f(r,g,b); 99 | glEnableClientState(GL_VERTEX_ARRAY); 100 | glVertexPointer(2, GL_FLOAT, 16, buffer); 101 | glDrawArrays(GL_QUADS, 0, num_quads*4); 102 | glDisableClientState(GL_VERTEX_ARRAY); 103 | } 104 | #endif 105 | 106 | #ifndef INCLUDE_STB_EASY_FONT_H 107 | #define INCLUDE_STB_EASY_FONT_H 108 | 109 | #include 110 | #include 111 | 112 | static struct stb_easy_font_info_struct { 113 | unsigned char advance; 114 | unsigned char h_seg; 115 | unsigned char v_seg; 116 | } stb_easy_font_charinfo[96] = { 117 | { 6, 0, 0 }, { 3, 0, 0 }, { 5, 1, 1 }, { 7, 1, 4 }, 118 | { 7, 3, 7 }, { 7, 6, 12 }, { 7, 8, 19 }, { 4, 16, 21 }, 119 | { 4, 17, 22 }, { 4, 19, 23 }, { 23, 21, 24 }, { 23, 22, 31 }, 120 | { 20, 23, 34 }, { 22, 23, 36 }, { 19, 24, 36 }, { 21, 25, 36 }, 121 | { 6, 25, 39 }, { 6, 27, 43 }, { 6, 28, 45 }, { 6, 30, 49 }, 122 | { 6, 33, 53 }, { 6, 34, 57 }, { 6, 40, 58 }, { 6, 46, 59 }, 123 | { 6, 47, 62 }, { 6, 55, 64 }, { 19, 57, 68 }, { 20, 59, 68 }, 124 | { 21, 61, 69 }, { 22, 66, 69 }, { 21, 68, 69 }, { 7, 73, 69 }, 125 | { 9, 75, 74 }, { 6, 78, 81 }, { 6, 80, 85 }, { 6, 83, 90 }, 126 | { 6, 85, 91 }, { 6, 87, 95 }, { 6, 90, 96 }, { 7, 92, 97 }, 127 | { 6, 96,102 }, { 5, 97,106 }, { 6, 99,107 }, { 6,100,110 }, 128 | { 6,100,115 }, { 7,101,116 }, { 6,101,121 }, { 6,101,125 }, 129 | { 6,102,129 }, { 7,103,133 }, { 6,104,140 }, { 6,105,145 }, 130 | { 7,107,149 }, { 6,108,151 }, { 7,109,155 }, { 7,109,160 }, 131 | { 7,109,165 }, { 7,118,167 }, { 6,118,172 }, { 4,120,176 }, 132 | { 6,122,177 }, { 4,122,181 }, { 23,124,182 }, { 22,129,182 }, 133 | { 4,130,182 }, { 22,131,183 }, { 6,133,187 }, { 22,135,191 }, 134 | { 6,137,192 }, { 22,139,196 }, { 6,144,197 }, { 22,147,198 }, 135 | { 6,150,202 }, { 19,151,206 }, { 21,152,207 }, { 6,155,209 }, 136 | { 3,160,210 }, { 23,160,211 }, { 22,164,216 }, { 22,165,220 }, 137 | { 22,167,224 }, { 22,169,228 }, { 21,171,232 }, { 21,173,233 }, 138 | { 5,178,233 }, { 22,179,234 }, { 23,180,238 }, { 23,180,243 }, 139 | { 23,180,248 }, { 22,189,248 }, { 22,191,252 }, { 5,196,252 }, 140 | { 3,203,252 }, { 5,203,253 }, { 22,210,253 }, { 0,214,253 }, 141 | }; 142 | 143 | static unsigned char stb_easy_font_hseg[214] = { 144 | 97,37,69,84,28,51,2,18,10,49,98,41,65,25,81,105,33,9,97,1,97,37,37,36, 145 | 81,10,98,107,3,100,3,99,58,51,4,99,58,8,73,81,10,50,98,8,73,81,4,10,50, 146 | 98,8,25,33,65,81,10,50,17,65,97,25,33,25,49,9,65,20,68,1,65,25,49,41, 147 | 11,105,13,101,76,10,50,10,50,98,11,99,10,98,11,50,99,11,50,11,99,8,57, 148 | 58,3,99,99,107,10,10,11,10,99,11,5,100,41,65,57,41,65,9,17,81,97,3,107, 149 | 9,97,1,97,33,25,9,25,41,100,41,26,82,42,98,27,83,42,98,26,51,82,8,41, 150 | 35,8,10,26,82,114,42,1,114,8,9,73,57,81,41,97,18,8,8,25,26,26,82,26,82, 151 | 26,82,41,25,33,82,26,49,73,35,90,17,81,41,65,57,41,65,25,81,90,114,20, 152 | 84,73,57,41,49,25,33,65,81,9,97,1,97,25,33,65,81,57,33,25,41,25, 153 | }; 154 | 155 | static unsigned char stb_easy_font_vseg[253] = { 156 | 4,2,8,10,15,8,15,33,8,15,8,73,82,73,57,41,82,10,82,18,66,10,21,29,1,65, 157 | 27,8,27,9,65,8,10,50,97,74,66,42,10,21,57,41,29,25,14,81,73,57,26,8,8, 158 | 26,66,3,8,8,15,19,21,90,58,26,18,66,18,105,89,28,74,17,8,73,57,26,21, 159 | 8,42,41,42,8,28,22,8,8,30,7,8,8,26,66,21,7,8,8,29,7,7,21,8,8,8,59,7,8, 160 | 8,15,29,8,8,14,7,57,43,10,82,7,7,25,42,25,15,7,25,41,15,21,105,105,29, 161 | 7,57,57,26,21,105,73,97,89,28,97,7,57,58,26,82,18,57,57,74,8,30,6,8,8, 162 | 14,3,58,90,58,11,7,74,43,74,15,2,82,2,42,75,42,10,67,57,41,10,7,2,42, 163 | 74,106,15,2,35,8,8,29,7,8,8,59,35,51,8,8,15,35,30,35,8,8,30,7,8,8,60, 164 | 36,8,45,7,7,36,8,43,8,44,21,8,8,44,35,8,8,43,23,8,8,43,35,8,8,31,21,15, 165 | 20,8,8,28,18,58,89,58,26,21,89,73,89,29,20,8,8,30,7, 166 | }; 167 | 168 | typedef struct 169 | { 170 | unsigned char c[4]; 171 | } stb_easy_font_color; 172 | 173 | static int stb_easy_font_draw_segs(float x, float y, unsigned char *segs, int num_segs, int vertical, stb_easy_font_color c, char *vbuf, int vbuf_size, int offset) 174 | { 175 | int i,j; 176 | for (i=0; i < num_segs; ++i) { 177 | int len = segs[i] & 7; 178 | x += (float) ((segs[i] >> 3) & 1); 179 | if (len && offset+64 <= vbuf_size) { 180 | float y0 = y + (float) (segs[i]>>4); 181 | for (j=0; j < 4; ++j) { 182 | * (float *) (vbuf+offset+0) = x + (j==1 || j==2 ? (vertical ? 1 : len) : 0); 183 | * (float *) (vbuf+offset+4) = y0 + ( j >= 2 ? (vertical ? len : 1) : 0); 184 | * (float *) (vbuf+offset+8) = 0.f; 185 | * (stb_easy_font_color *) (vbuf+offset+12) = c; 186 | offset += 16; 187 | } 188 | } 189 | } 190 | return offset; 191 | } 192 | 193 | static float stb_easy_font_spacing_val = 0; 194 | static void stb_easy_font_spacing(float spacing) 195 | { 196 | stb_easy_font_spacing_val = spacing; 197 | } 198 | 199 | static int stb_easy_font_print(float x, float y, char *text, unsigned char color[4], void *vertex_buffer, int vbuf_size) 200 | { 201 | char *vbuf = (char *) vertex_buffer; 202 | float start_x = x; 203 | int offset = 0; 204 | 205 | stb_easy_font_color c = { 255,255,255,255 }; // use structure copying to avoid needing depending on memcpy() 206 | if (color) { c.c[0] = color[0]; c.c[1] = color[1]; c.c[2] = color[2]; c.c[3] = color[3]; } 207 | 208 | while (*text && offset < vbuf_size) { 209 | if (*text == '\n') { 210 | y += 12; 211 | x = start_x; 212 | } else { 213 | unsigned char advance = stb_easy_font_charinfo[*text-32].advance; 214 | float y_ch = advance & 16 ? y+1 : y; 215 | int h_seg, v_seg, num_h, num_v; 216 | h_seg = stb_easy_font_charinfo[*text-32 ].h_seg; 217 | v_seg = stb_easy_font_charinfo[*text-32 ].v_seg; 218 | num_h = stb_easy_font_charinfo[*text-32+1].h_seg - h_seg; 219 | num_v = stb_easy_font_charinfo[*text-32+1].v_seg - v_seg; 220 | offset = stb_easy_font_draw_segs(x, y_ch, &stb_easy_font_hseg[h_seg], num_h, 0, c, vbuf, vbuf_size, offset); 221 | offset = stb_easy_font_draw_segs(x, y_ch, &stb_easy_font_vseg[v_seg], num_v, 1, c, vbuf, vbuf_size, offset); 222 | x += advance & 15; 223 | x += stb_easy_font_spacing_val; 224 | } 225 | ++text; 226 | } 227 | return (unsigned) offset/64; 228 | } 229 | 230 | static int stb_easy_font_width(char *text) 231 | { 232 | float len = 0; 233 | float max_len = 0; 234 | while (*text) { 235 | if (*text == '\n') { 236 | if (len > max_len) max_len = len; 237 | len = 0; 238 | } else { 239 | len += stb_easy_font_charinfo[*text-32].advance & 15; 240 | len += stb_easy_font_spacing_val; 241 | } 242 | ++text; 243 | } 244 | if (len > max_len) max_len = len; 245 | return (int) ceil(max_len); 246 | } 247 | 248 | static int stb_easy_font_height(char *text) 249 | { 250 | float y = 0; 251 | int nonempty_line=0; 252 | while (*text) { 253 | if (*text == '\n') { 254 | y += 12; 255 | nonempty_line = 0; 256 | } else { 257 | nonempty_line = 1; 258 | } 259 | ++text; 260 | } 261 | return (int) ceil(y + (nonempty_line ? 12 : 0)); 262 | } 263 | #endif 264 | 265 | /* 266 | ------------------------------------------------------------------------------ 267 | This software is available under 2 licenses -- choose whichever you prefer. 268 | ------------------------------------------------------------------------------ 269 | ALTERNATIVE A - MIT License 270 | Copyright (c) 2017 Sean Barrett 271 | Permission is hereby granted, free of charge, to any person obtaining a copy of 272 | this software and associated documentation files (the "Software"), to deal in 273 | the Software without restriction, including without limitation the rights to 274 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 275 | of the Software, and to permit persons to whom the Software is furnished to do 276 | so, subject to the following conditions: 277 | The above copyright notice and this permission notice shall be included in all 278 | copies or substantial portions of the Software. 279 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 280 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 281 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 282 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 283 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 284 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 285 | SOFTWARE. 286 | ------------------------------------------------------------------------------ 287 | ALTERNATIVE B - Public Domain (www.unlicense.org) 288 | This is free and unencumbered software released into the public domain. 289 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute this 290 | software, either in source code form or as a compiled binary, for any purpose, 291 | commercial or non-commercial, and by any means. 292 | In jurisdictions that recognize copyright laws, the author or authors of this 293 | software dedicate any and all copyright interest in the software to the public 294 | domain. We make this dedication for the benefit of the public at large and to 295 | the detriment of our heirs and successors. We intend this dedication to be an 296 | overt act of relinquishment in perpetuity of all present and future rights to 297 | this software under copyright law. 298 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 299 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 300 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 301 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 302 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 303 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 304 | ------------------------------------------------------------------------------ 305 | */ 306 | -------------------------------------------------------------------------------- /InkingTextureLoader/ThirdParty/stb_image/source/stb_image_exports.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define STB_IMAGE_IMPLEMENTATION 4 | #include "stb_image.h" 5 | #define STB_IMAGE_WRITE_IMPLEMENTATION 6 | #include "stb_image_write.h" 7 | 8 | #define STB_IMAGE_RESIZE_IMPLEMENTATION 9 | #include "stb_image_resize.h" 10 | 11 | #if TARGET_OS_IPHONE 12 | #import 13 | #endif 14 | 15 | #if __cplusplus 16 | extern "C" { 17 | #endif 18 | #if TARGET_OS_IPHONE 19 | STBIDEF unsigned char *_stbi_load_from_memory(unsigned char const *buffer, int len, int *x, int *y, int *comp, int req_comp) 20 | { 21 | return stbi_load_from_memory(buffer, len, x, y, comp, req_comp); 22 | } 23 | 24 | STBIDEF void _stbi_image_free(void* ptr) 25 | { 26 | stbi_image_free(ptr); 27 | } 28 | #endif 29 | 30 | #if defined(_WIN32) || defined(_WIN64) 31 | 32 | _declspec(dllexport) unsigned char *_stbi_load_from_memory(unsigned char const *buffer, int len, int *x, int *y, int *comp, int req_comp) 33 | { 34 | return stbi_load_from_memory(buffer, len, x, y, comp, req_comp); 35 | } 36 | 37 | _declspec(dllexport) void _stbi_image_free(void* ptr) 38 | { 39 | stbi_image_free(ptr); 40 | } 41 | 42 | _declspec(dllexport) void _stbi_resize(const unsigned char* input, int input_width, int input_height, unsigned char* output, int output_width, int output_height, int comp) 43 | { 44 | stbir_resize_uint8(input, input_width, input_height, 0, 45 | output, output_width, output_height, 0, comp); 46 | } 47 | #endif 48 | 49 | #if ANDROID 50 | unsigned char *_stbi_load_from_memory(unsigned char const *buffer, int len, int *x, int *y, int *comp, int req_comp) 51 | { 52 | return stbi_load_from_memory(buffer, len, x, y, comp, req_comp); 53 | } 54 | 55 | void _stbi_image_free(void* ptr) 56 | { 57 | stbi_image_free(ptr); 58 | } 59 | 60 | void _stbi_resize(const unsigned char* input, int input_width, int input_height, unsigned char* output, int output_width, int output_height, int comp) 61 | { 62 | stbir_resize_uint8(input, input_width, input_height, 0, 63 | output, output_width, output_height, 0, comp); 64 | } 65 | #endif 66 | #if __cplusplus 67 | } 68 | #endif 69 | -------------------------------------------------------------------------------- /InkingTextureLoader/ThirdParty/stb_image/source/stb_include.h: -------------------------------------------------------------------------------- 1 | // stb_include.h - v0.02 - parse and process #include directives - public domain 2 | // 3 | // To build this, in one source file that includes this file do 4 | // #define STB_INCLUDE_IMPLEMENTATION 5 | // 6 | // This program parses a string and replaces lines of the form 7 | // #include "foo" 8 | // with the contents of a file named "foo". It also embeds the 9 | // appropriate #line directives. Note that all include files must 10 | // reside in the location specified in the path passed to the API; 11 | // it does not check multiple directories. 12 | // 13 | // If the string contains a line of the form 14 | // #inject 15 | // then it will be replaced with the contents of the string 'inject' passed to the API. 16 | // 17 | // Options: 18 | // 19 | // Define STB_INCLUDE_LINE_GLSL to get GLSL-style #line directives 20 | // which use numbers instead of filenames. 21 | // 22 | // Define STB_INCLUDE_LINE_NONE to disable output of #line directives. 23 | // 24 | // Standard libraries: 25 | // 26 | // stdio.h FILE, fopen, fclose, fseek, ftell 27 | // stdlib.h malloc, realloc, free 28 | // string.h strcpy, strncmp, memcpy 29 | // 30 | // Credits: 31 | // 32 | // Written by Sean Barrett. 33 | // 34 | // Fixes: 35 | // Michal Klos 36 | 37 | #ifndef STB_INCLUDE_STB_INCLUDE_H 38 | #define STB_INCLUDE_STB_INCLUDE_H 39 | 40 | // Do include-processing on the string 'str'. To free the return value, pass it to free() 41 | char *stb_include_string(char *str, char *inject, char *path_to_includes, char *filename_for_line_directive, char error[256]); 42 | 43 | // Concatenate the strings 'strs' and do include-processing on the result. To free the return value, pass it to free() 44 | char *stb_include_strings(char **strs, int count, char *inject, char *path_to_includes, char *filename_for_line_directive, char error[256]); 45 | 46 | // Load the file 'filename' and do include-processing on the string therein. note that 47 | // 'filename' is opened directly; 'path_to_includes' is not used. To free the return value, pass it to free() 48 | char *stb_include_file(char *filename, char *inject, char *path_to_includes, char error[256]); 49 | 50 | #endif 51 | 52 | 53 | #ifdef STB_INCLUDE_IMPLEMENTATION 54 | 55 | #include 56 | #include 57 | #include 58 | 59 | static char *stb_include_load_file(char *filename, size_t *plen) 60 | { 61 | char *text; 62 | size_t len; 63 | FILE *f = fopen(filename, "rb"); 64 | if (f == 0) return 0; 65 | fseek(f, 0, SEEK_END); 66 | len = (size_t) ftell(f); 67 | if (plen) *plen = len; 68 | text = (char *) malloc(len+1); 69 | if (text == 0) return 0; 70 | fseek(f, 0, SEEK_SET); 71 | fread(text, 1, len, f); 72 | fclose(f); 73 | text[len] = 0; 74 | return text; 75 | } 76 | 77 | typedef struct 78 | { 79 | int offset; 80 | int end; 81 | char *filename; 82 | int next_line_after; 83 | } include_info; 84 | 85 | static include_info *stb_include_append_include(include_info *array, int len, int offset, int end, char *filename, int next_line) 86 | { 87 | include_info *z = (include_info *) realloc(array, sizeof(*z) * (len+1)); 88 | z[len].offset = offset; 89 | z[len].end = end; 90 | z[len].filename = filename; 91 | z[len].next_line_after = next_line; 92 | return z; 93 | } 94 | 95 | static void stb_include_free_includes(include_info *array, int len) 96 | { 97 | int i; 98 | for (i=0; i < len; ++i) 99 | free(array[i].filename); 100 | free(array); 101 | } 102 | 103 | static int stb_include_isspace(int ch) 104 | { 105 | return (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n'); 106 | } 107 | 108 | // find location of all #include and #inject 109 | static int stb_include_find_includes(char *text, include_info **plist) 110 | { 111 | int line_count = 1; 112 | int inc_count = 0; 113 | char *s = text, *start; 114 | include_info *list = NULL; 115 | while (*s) { 116 | // parse is always at start of line when we reach here 117 | start = s; 118 | while (*s == ' ' || *s == '\t') 119 | ++s; 120 | if (*s == '#') { 121 | ++s; 122 | while (*s == ' ' || *s == '\t') 123 | ++s; 124 | if (0==strncmp(s, "include", 7) && stb_include_isspace(s[7])) { 125 | s += 7; 126 | while (*s == ' ' || *s == '\t') 127 | ++s; 128 | if (*s == '"') { 129 | char *t = ++s; 130 | while (*t != '"' && *t != '\n' && *t != '\r' && *t != 0) 131 | ++t; 132 | if (*t == '"') { 133 | char *filename = (char *) malloc(t-s+1); 134 | memcpy(filename, s, t-s); 135 | filename[t-s] = 0; 136 | s=t; 137 | while (*s != '\r' && *s != '\n' && *s != 0) 138 | ++s; 139 | // s points to the newline, so s-start is everything except the newline 140 | list = stb_include_append_include(list, inc_count++, start-text, s-text, filename, line_count+1); 141 | } 142 | } 143 | } else if (0==strncmp(s, "inject", 6) && (stb_include_isspace(s[6]) || s[6]==0)) { 144 | while (*s != '\r' && *s != '\n' && *s != 0) 145 | ++s; 146 | list = stb_include_append_include(list, inc_count++, start-text, s-text, NULL, line_count+1); 147 | } 148 | } 149 | while (*s != '\r' && *s != '\n' && *s != 0) 150 | ++s; 151 | if (*s == '\r' || *s == '\n') { 152 | s = s + (s[0] + s[1] == '\r' + '\n' ? 2 : 1); 153 | } 154 | ++line_count; 155 | } 156 | *plist = list; 157 | return inc_count; 158 | } 159 | 160 | // avoid dependency on sprintf() 161 | static void stb_include_itoa(char str[9], int n) 162 | { 163 | int i; 164 | for (i=0; i < 8; ++i) 165 | str[i] = ' '; 166 | str[i] = 0; 167 | 168 | for (i=1; i < 8; ++i) { 169 | str[7-i] = '0' + (n % 10); 170 | n /= 10; 171 | if (n == 0) 172 | break; 173 | } 174 | } 175 | 176 | static char *stb_include_append(char *str, size_t *curlen, char *addstr, size_t addlen) 177 | { 178 | str = (char *) realloc(str, *curlen + addlen); 179 | memcpy(str + *curlen, addstr, addlen); 180 | *curlen += addlen; 181 | return str; 182 | } 183 | 184 | char *stb_include_string(char *str, char *inject, char *path_to_includes, char *filename, char error[256]) 185 | { 186 | char temp[4096]; 187 | include_info *inc_list; 188 | int i, num = stb_include_find_includes(str, &inc_list); 189 | size_t source_len = strlen(str); 190 | char *text=0; 191 | size_t textlen=0, last=0; 192 | for (i=0; i < num; ++i) { 193 | text = stb_include_append(text, &textlen, str+last, inc_list[i].offset - last); 194 | // write out line directive for the include 195 | #ifndef STB_INCLUDE_LINE_NONE 196 | #ifdef STB_INCLUDE_LINE_GLSL 197 | if (textlen != 0) // GLSL #version must appear first, so don't put a #line at the top 198 | #endif 199 | { 200 | strcpy(temp, "#line "); 201 | stb_include_itoa(temp+6, 1); 202 | strcat(temp, " "); 203 | #ifdef STB_INCLUDE_LINE_GLSL 204 | stb_include_itoa(temp+15, i+1); 205 | #else 206 | strcat(temp, "\""); 207 | if (inc_list[i].filename == 0) 208 | strcmp(temp, "INJECT"); 209 | else 210 | strcat(temp, inc_list[i].filename); 211 | strcat(temp, "\""); 212 | #endif 213 | strcat(temp, "\n"); 214 | text = stb_include_append(text, &textlen, temp, strlen(temp)); 215 | } 216 | #endif 217 | if (inc_list[i].filename == 0) { 218 | if (inject != 0) 219 | text = stb_include_append(text, &textlen, inject, strlen(inject)); 220 | } else { 221 | char *inc; 222 | strcpy(temp, path_to_includes); 223 | strcat(temp, "/"); 224 | strcat(temp, inc_list[i].filename); 225 | inc = stb_include_file(temp, inject, path_to_includes, error); 226 | if (inc == NULL) { 227 | stb_include_free_includes(inc_list, num); 228 | return NULL; 229 | } 230 | text = stb_include_append(text, &textlen, inc, strlen(inc)); 231 | free(inc); 232 | } 233 | // write out line directive 234 | #ifndef STB_INCLUDE_LINE_NONE 235 | strcpy(temp, "\n#line "); 236 | stb_include_itoa(temp+6, inc_list[i].next_line_after); 237 | strcat(temp, " "); 238 | #ifdef STB_INCLUDE_LINE_GLSL 239 | stb_include_itoa(temp+15, 0); 240 | #else 241 | strcat(temp, filename != 0 ? filename : "source-file"); 242 | #endif 243 | text = stb_include_append(text, &textlen, temp, strlen(temp)); 244 | // no newlines, because we kept the #include newlines, which will get appended next 245 | #endif 246 | last = inc_list[i].end; 247 | } 248 | text = stb_include_append(text, &textlen, str+last, source_len - last + 1); // append '\0' 249 | stb_include_free_includes(inc_list, num); 250 | return text; 251 | } 252 | 253 | char *stb_include_strings(char **strs, int count, char *inject, char *path_to_includes, char *filename, char error[256]) 254 | { 255 | char *text; 256 | char *result; 257 | int i; 258 | size_t length=0; 259 | for (i=0; i < count; ++i) 260 | length += strlen(strs[i]); 261 | text = (char *) malloc(length+1); 262 | length = 0; 263 | for (i=0; i < count; ++i) { 264 | strcpy(text + length, strs[i]); 265 | length += strlen(strs[i]); 266 | } 267 | result = stb_include_string(text, inject, path_to_includes, filename, error); 268 | free(text); 269 | return result; 270 | } 271 | 272 | char *stb_include_file(char *filename, char *inject, char *path_to_includes, char error[256]) 273 | { 274 | size_t len; 275 | char *result; 276 | char *text = stb_include_load_file(filename, &len); 277 | if (text == NULL) { 278 | strcpy(error, "Error: couldn't load '"); 279 | strcat(error, filename); 280 | strcat(error, "'"); 281 | return 0; 282 | } 283 | result = stb_include_string(text, inject, path_to_includes, filename, error); 284 | free(text); 285 | return result; 286 | } 287 | 288 | #if 0 // @TODO, GL_ARB_shader_language_include-style system that doesn't touch filesystem 289 | char *stb_include_preloaded(char *str, char *inject, char *includes[][2], char error[256]) 290 | { 291 | 292 | } 293 | #endif 294 | 295 | #endif // STB_INCLUDE_IMPLEMENTATION 296 | -------------------------------------------------------------------------------- /InkingTextureLoader/ThirdParty/stb_image/source/stb_leakcheck.h: -------------------------------------------------------------------------------- 1 | // stb_leakcheck.h - v0.6 - quick & dirty malloc leak-checking - public domain 2 | // LICENSE 3 | // 4 | // See end of file. 5 | 6 | #ifdef STB_LEAKCHECK_IMPLEMENTATION 7 | #undef STB_LEAKCHECK_IMPLEMENTATION // don't implement more than once 8 | 9 | // if we've already included leakcheck before, undefine the macros 10 | #ifdef malloc 11 | #undef malloc 12 | #undef free 13 | #undef realloc 14 | #endif 15 | 16 | #ifndef STB_LEAKCHECK_OUTPUT_PIPE 17 | #define STB_LEAKCHECK_OUTPUT_PIPE stdout 18 | #endif 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | typedef struct malloc_info stb_leakcheck_malloc_info; 26 | 27 | struct malloc_info 28 | { 29 | const char *file; 30 | int line; 31 | size_t size; 32 | stb_leakcheck_malloc_info *next,*prev; 33 | }; 34 | 35 | static stb_leakcheck_malloc_info *mi_head; 36 | 37 | void *stb_leakcheck_malloc(size_t sz, const char *file, int line) 38 | { 39 | stb_leakcheck_malloc_info *mi = (stb_leakcheck_malloc_info *) malloc(sz + sizeof(*mi)); 40 | if (mi == NULL) return mi; 41 | mi->file = file; 42 | mi->line = line; 43 | mi->next = mi_head; 44 | if (mi_head) 45 | mi->next->prev = mi; 46 | mi->prev = NULL; 47 | mi->size = (int) sz; 48 | mi_head = mi; 49 | return mi+1; 50 | } 51 | 52 | void stb_leakcheck_free(void *ptr) 53 | { 54 | if (ptr != NULL) { 55 | stb_leakcheck_malloc_info *mi = (stb_leakcheck_malloc_info *) ptr - 1; 56 | mi->size = ~mi->size; 57 | #ifndef STB_LEAKCHECK_SHOWALL 58 | if (mi->prev == NULL) { 59 | assert(mi_head == mi); 60 | mi_head = mi->next; 61 | } else 62 | mi->prev->next = mi->next; 63 | if (mi->next) 64 | mi->next->prev = mi->prev; 65 | free(mi); 66 | #endif 67 | } 68 | } 69 | 70 | void *stb_leakcheck_realloc(void *ptr, size_t sz, const char *file, int line) 71 | { 72 | if (ptr == NULL) { 73 | return stb_leakcheck_malloc(sz, file, line); 74 | } else if (sz == 0) { 75 | stb_leakcheck_free(ptr); 76 | return NULL; 77 | } else { 78 | stb_leakcheck_malloc_info *mi = (stb_leakcheck_malloc_info *) ptr - 1; 79 | if (sz <= mi->size) 80 | return ptr; 81 | else { 82 | #ifdef STB_LEAKCHECK_REALLOC_PRESERVE_MALLOC_FILELINE 83 | void *q = stb_leakcheck_malloc(sz, mi->file, mi->line); 84 | #else 85 | void *q = stb_leakcheck_malloc(sz, file, line); 86 | #endif 87 | if (q) { 88 | memcpy(q, ptr, mi->size); 89 | stb_leakcheck_free(ptr); 90 | } 91 | return q; 92 | } 93 | } 94 | } 95 | 96 | static void stblkck_internal_print(const char *reason, stb_leakcheck_malloc_info *mi) 97 | { 98 | #if defined(_MSC_VER) && _MSC_VER < 1900 // 1900=VS 2015 99 | // Compilers that use the old MS C runtime library don't have %zd 100 | // and the older ones don't even have %lld either... however, the old compilers 101 | // without "long long" don't support 64-bit targets either, so here's the 102 | // compromise: 103 | #if _MSC_VER < 1400 // before VS 2005 104 | fprintf(STB_LEAKCHECK_OUTPUT_PIPE, "%s: %s (%4d): %8d bytes at %p\n", reason, mi->file, mi->line, (int)mi->size, (void*)(mi+1)); 105 | #else 106 | fprintf(STB_LEAKCHECK_OUTPUT_PIPE, "%s: %s (%4d): %16lld bytes at %p\n", reason, mi->file, mi->line, (long long)mi->size, (void*)(mi+1)); 107 | #endif 108 | #else 109 | // Assume we have %zd on other targets. 110 | #ifdef __MINGW32__ 111 | __mingw_fprintf(STB_LEAKCHECK_OUTPUT_PIPE, "%s: %s (%4d): %zd bytes at %p\n", reason, mi->file, mi->line, mi->size, (void*)(mi+1)); 112 | #else 113 | fprintf(STB_LEAKCHECK_OUTPUT_PIPE, "%s: %s (%4d): %zd bytes at %p\n", reason, mi->file, mi->line, mi->size, (void*)(mi+1)); 114 | #endif 115 | #endif 116 | } 117 | 118 | void stb_leakcheck_dumpmem(void) 119 | { 120 | stb_leakcheck_malloc_info *mi = mi_head; 121 | while (mi) { 122 | if ((ptrdiff_t) mi->size >= 0) 123 | stblkck_internal_print("LEAKED", mi); 124 | mi = mi->next; 125 | } 126 | #ifdef STB_LEAKCHECK_SHOWALL 127 | mi = mi_head; 128 | while (mi) { 129 | if ((ptrdiff_t) mi->size < 0) 130 | stblkck_internal_print("FREED ", mi); 131 | mi = mi->next; 132 | } 133 | #endif 134 | } 135 | #endif // STB_LEAKCHECK_IMPLEMENTATION 136 | 137 | #if !defined(INCLUDE_STB_LEAKCHECK_H) || !defined(malloc) 138 | #define INCLUDE_STB_LEAKCHECK_H 139 | 140 | #include // we want to define the macros *after* stdlib to avoid a slew of errors 141 | 142 | #define malloc(sz) stb_leakcheck_malloc(sz, __FILE__, __LINE__) 143 | #define free(p) stb_leakcheck_free(p) 144 | #define realloc(p,sz) stb_leakcheck_realloc(p,sz, __FILE__, __LINE__) 145 | 146 | extern void * stb_leakcheck_malloc(size_t sz, const char *file, int line); 147 | extern void * stb_leakcheck_realloc(void *ptr, size_t sz, const char *file, int line); 148 | extern void stb_leakcheck_free(void *ptr); 149 | extern void stb_leakcheck_dumpmem(void); 150 | 151 | #endif // INCLUDE_STB_LEAKCHECK_H 152 | 153 | 154 | /* 155 | ------------------------------------------------------------------------------ 156 | This software is available under 2 licenses -- choose whichever you prefer. 157 | ------------------------------------------------------------------------------ 158 | ALTERNATIVE A - MIT License 159 | Copyright (c) 2017 Sean Barrett 160 | Permission is hereby granted, free of charge, to any person obtaining a copy of 161 | this software and associated documentation files (the "Software"), to deal in 162 | the Software without restriction, including without limitation the rights to 163 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 164 | of the Software, and to permit persons to whom the Software is furnished to do 165 | so, subject to the following conditions: 166 | The above copyright notice and this permission notice shall be included in all 167 | copies or substantial portions of the Software. 168 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 169 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 170 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 171 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 172 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 173 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 174 | SOFTWARE. 175 | ------------------------------------------------------------------------------ 176 | ALTERNATIVE B - Public Domain (www.unlicense.org) 177 | This is free and unencumbered software released into the public domain. 178 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute this 179 | software, either in source code form or as a compiled binary, for any purpose, 180 | commercial or non-commercial, and by any means. 181 | In jurisdictions that recognize copyright laws, the author or authors of this 182 | software dedicate any and all copyright interest in the software to the public 183 | domain. We make this dedication for the benefit of the public at large and to 184 | the detriment of our heirs and successors. We intend this dedication to be an 185 | overt act of relinquishment in perpetuity of all present and future rights to 186 | this software under copyright law. 187 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 188 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 189 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 190 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 191 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 192 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 193 | ------------------------------------------------------------------------------ 194 | */ 195 | -------------------------------------------------------------------------------- /InkingTextureLoader/ThirdParty/stb_image/source/stretchy_buffer.h: -------------------------------------------------------------------------------- 1 | // stretchy_buffer.h - v1.04 - public domain - nothings.org/stb 2 | // a vector<>-like dynamic array for C 3 | // 4 | // version history: 5 | // 1.04 - fix warning 6 | // 1.03 - compile as C++ maybe 7 | // 1.02 - tweaks to syntax for no good reason 8 | // 1.01 - added a "common uses" documentation section 9 | // 1.0 - fixed bug in the version I posted prematurely 10 | // 0.9 - rewrite to try to avoid strict-aliasing optimization 11 | // issues, but won't compile as C++ 12 | // 13 | // Will probably not work correctly with strict-aliasing optimizations. 14 | // 15 | // The idea: 16 | // 17 | // This implements an approximation to C++ vector<> for C, in that it 18 | // provides a generic definition for dynamic arrays which you can 19 | // still access in a typesafe way using arr[i] or *(arr+i). However, 20 | // it is simply a convenience wrapper around the common idiom of 21 | // of keeping a set of variables (in a struct or globals) which store 22 | // - pointer to array 23 | // - the length of the "in-use" part of the array 24 | // - the current size of the allocated array 25 | // 26 | // I find it to be the single most useful non-built-in-structure when 27 | // programming in C (hash tables a close second), but to be clear 28 | // it lacks many of the capabilities of C++ vector<>: there is no 29 | // range checking, the object address isn't stable (see next section 30 | // for details), the set of methods available is small (although 31 | // the file stb.h has another implementation of stretchy buffers 32 | // called 'stb_arr' which provides more methods, e.g. for insertion 33 | // and deletion). 34 | // 35 | // How to use: 36 | // 37 | // Unlike other stb header file libraries, there is no need to 38 | // define an _IMPLEMENTATION symbol. Every #include creates as 39 | // much implementation is needed. 40 | // 41 | // stretchy_buffer.h does not define any types, so you do not 42 | // need to #include it to before defining data types that are 43 | // stretchy buffers, only in files that *manipulate* stretchy 44 | // buffers. 45 | // 46 | // If you want a stretchy buffer aka dynamic array containing 47 | // objects of TYPE, declare such an array as: 48 | // 49 | // TYPE *myarray = NULL; 50 | // 51 | // (There is no typesafe way to distinguish between stretchy 52 | // buffers and regular arrays/pointers; this is necessary to 53 | // make ordinary array indexing work on these objects.) 54 | // 55 | // Unlike C++ vector<>, the stretchy_buffer has the same 56 | // semantics as an object that you manually malloc and realloc. 57 | // The pointer may relocate every time you add a new object 58 | // to it, so you: 59 | // 60 | // 1. can't take long-term pointers to elements of the array 61 | // 2. have to return the pointer from functions which might expand it 62 | // (either as a return value or by storing it to a ptr-to-ptr) 63 | // 64 | // Now you can do the following things with this array: 65 | // 66 | // sb_free(TYPE *a) free the array 67 | // sb_count(TYPE *a) the number of elements in the array 68 | // sb_push(TYPE *a, TYPE v) adds v on the end of the array, a la push_back 69 | // sb_add(TYPE *a, int n) adds n uninitialized elements at end of array & returns pointer to first added 70 | // sb_last(TYPE *a) returns an lvalue of the last item in the array 71 | // a[n] access the nth (counting from 0) element of the array 72 | // 73 | // #define STRETCHY_BUFFER_NO_SHORT_NAMES to only export 74 | // names of the form 'stb_sb_' if you have a name that would 75 | // otherwise collide. 76 | // 77 | // Note that these are all macros and many of them evaluate 78 | // their arguments more than once, so the arguments should 79 | // be side-effect-free. 80 | // 81 | // Note that 'TYPE *a' in sb_push and sb_add must be lvalues 82 | // so that the library can overwrite the existing pointer if 83 | // the object has to be reallocated. 84 | // 85 | // In an out-of-memory condition, the code will try to 86 | // set up a null-pointer or otherwise-invalid-pointer 87 | // exception to happen later. It's possible optimizing 88 | // compilers could detect this write-to-null statically 89 | // and optimize away some of the code, but it should only 90 | // be along the failure path. Nevertheless, for more security 91 | // in the face of such compilers, #define STRETCHY_BUFFER_OUT_OF_MEMORY 92 | // to a statement such as assert(0) or exit(1) or something 93 | // to force a failure when out-of-memory occurs. 94 | // 95 | // Common use: 96 | // 97 | // The main application for this is when building a list of 98 | // things with an unknown quantity, either due to loading from 99 | // a file or through a process which produces an unpredictable 100 | // number. 101 | // 102 | // My most common idiom is something like: 103 | // 104 | // SomeStruct *arr = NULL; 105 | // while (something) 106 | // { 107 | // SomeStruct new_one; 108 | // new_one.whatever = whatever; 109 | // new_one.whatup = whatup; 110 | // new_one.foobar = barfoo; 111 | // sb_push(arr, new_one); 112 | // } 113 | // 114 | // and various closely-related factorings of that. For example, 115 | // you might have several functions to create/init new SomeStructs, 116 | // and if you use the above idiom, you might prefer to make them 117 | // return structs rather than take non-const-pointers-to-structs, 118 | // so you can do things like: 119 | // 120 | // SomeStruct *arr = NULL; 121 | // while (something) 122 | // { 123 | // if (case_A) { 124 | // sb_push(arr, some_func1()); 125 | // } else if (case_B) { 126 | // sb_push(arr, some_func2()); 127 | // } else { 128 | // sb_push(arr, some_func3()); 129 | // } 130 | // } 131 | // 132 | // Note that the above relies on the fact that sb_push doesn't 133 | // evaluate its second argument more than once. The macros do 134 | // evaluate the *array* argument multiple times, and numeric 135 | // arguments may be evaluated multiple times, but you can rely 136 | // on the second argument of sb_push being evaluated only once. 137 | // 138 | // Of course, you don't have to store bare objects in the array; 139 | // if you need the objects to have stable pointers, store an array 140 | // of pointers instead: 141 | // 142 | // SomeStruct **arr = NULL; 143 | // while (something) 144 | // { 145 | // SomeStruct *new_one = malloc(sizeof(*new_one)); 146 | // new_one->whatever = whatever; 147 | // new_one->whatup = whatup; 148 | // new_one->foobar = barfoo; 149 | // sb_push(arr, new_one); 150 | // } 151 | // 152 | // How it works: 153 | // 154 | // A long-standing tradition in things like malloc implementations 155 | // is to store extra data before the beginning of the block returned 156 | // to the user. The stretchy buffer implementation here uses the 157 | // same trick; the current-count and current-allocation-size are 158 | // stored before the beginning of the array returned to the user. 159 | // (This means you can't directly free() the pointer, because the 160 | // allocated pointer is different from the type-safe pointer provided 161 | // to the user.) 162 | // 163 | // The details are trivial and implementation is straightforward; 164 | // the main trick is in realizing in the first place that it's 165 | // possible to do this in a generic, type-safe way in C. 166 | // 167 | // Contributors: 168 | // 169 | // Timothy Wright (github:ZenToad) 170 | // 171 | // LICENSE 172 | // 173 | // See end of file for license information. 174 | 175 | #ifndef STB_STRETCHY_BUFFER_H_INCLUDED 176 | #define STB_STRETCHY_BUFFER_H_INCLUDED 177 | 178 | #ifndef NO_STRETCHY_BUFFER_SHORT_NAMES 179 | #define sb_free stb_sb_free 180 | #define sb_push stb_sb_push 181 | #define sb_count stb_sb_count 182 | #define sb_add stb_sb_add 183 | #define sb_last stb_sb_last 184 | #endif 185 | 186 | #define stb_sb_free(a) ((a) ? free(stb__sbraw(a)),0 : 0) 187 | #define stb_sb_push(a,v) (stb__sbmaybegrow(a,1), (a)[stb__sbn(a)++] = (v)) 188 | #define stb_sb_count(a) ((a) ? stb__sbn(a) : 0) 189 | #define stb_sb_add(a,n) (stb__sbmaybegrow(a,n), stb__sbn(a)+=(n), &(a)[stb__sbn(a)-(n)]) 190 | #define stb_sb_last(a) ((a)[stb__sbn(a)-1]) 191 | 192 | #define stb__sbraw(a) ((int *) (void *) (a) - 2) 193 | #define stb__sbm(a) stb__sbraw(a)[0] 194 | #define stb__sbn(a) stb__sbraw(a)[1] 195 | 196 | #define stb__sbneedgrow(a,n) ((a)==0 || stb__sbn(a)+(n) >= stb__sbm(a)) 197 | #define stb__sbmaybegrow(a,n) (stb__sbneedgrow(a,(n)) ? stb__sbgrow(a,n) : 0) 198 | #define stb__sbgrow(a,n) (*((void **)&(a)) = stb__sbgrowf((a), (n), sizeof(*(a)))) 199 | 200 | #include 201 | 202 | static void * stb__sbgrowf(void *arr, int increment, int itemsize) 203 | { 204 | int dbl_cur = arr ? 2*stb__sbm(arr) : 0; 205 | int min_needed = stb_sb_count(arr) + increment; 206 | int m = dbl_cur > min_needed ? dbl_cur : min_needed; 207 | int *p = (int *) realloc(arr ? stb__sbraw(arr) : 0, itemsize * m + sizeof(int)*2); 208 | if (p) { 209 | if (!arr) 210 | p[1] = 0; 211 | p[0] = m; 212 | return p+2; 213 | } else { 214 | #ifdef STRETCHY_BUFFER_OUT_OF_MEMORY 215 | STRETCHY_BUFFER_OUT_OF_MEMORY ; 216 | #endif 217 | return (void *) (2*sizeof(int)); // try to force a NULL pointer exception later 218 | } 219 | } 220 | #endif // STB_STRETCHY_BUFFER_H_INCLUDED 221 | 222 | 223 | /* 224 | ------------------------------------------------------------------------------ 225 | This software is available under 2 licenses -- choose whichever you prefer. 226 | ------------------------------------------------------------------------------ 227 | ALTERNATIVE A - MIT License 228 | Copyright (c) 2017 Sean Barrett 229 | Permission is hereby granted, free of charge, to any person obtaining a copy of 230 | this software and associated documentation files (the "Software"), to deal in 231 | the Software without restriction, including without limitation the rights to 232 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 233 | of the Software, and to permit persons to whom the Software is furnished to do 234 | so, subject to the following conditions: 235 | The above copyright notice and this permission notice shall be included in all 236 | copies or substantial portions of the Software. 237 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 238 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 239 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 240 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 241 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 242 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 243 | SOFTWARE. 244 | ------------------------------------------------------------------------------ 245 | ALTERNATIVE B - Public Domain (www.unlicense.org) 246 | This is free and unencumbered software released into the public domain. 247 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute this 248 | software, either in source code form or as a compiled binary, for any purpose, 249 | commercial or non-commercial, and by any means. 250 | In jurisdictions that recognize copyright laws, the author or authors of this 251 | software dedicate any and all copyright interest in the software to the public 252 | domain. We make this dedication for the benefit of the public at large and to 253 | the detriment of our heirs and successors. We intend this dedication to be an 254 | overt act of relinquishment in perpetuity of all present and future rights to 255 | this software under copyright law. 256 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 257 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 258 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 259 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 260 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 261 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 262 | ------------------------------------------------------------------------------ 263 | */ 264 | -------------------------------------------------------------------------------- /InkingTextureLoader/build_android.bat: -------------------------------------------------------------------------------- 1 | :: cmake ... 2 | 3 | cmake.exe ^ 4 | -H"." ^ 5 | -B"./_build_android/armeabi-v7a" ^ 6 | -DANDROID_ABI=armeabi-v7a ^ 7 | -DANDROID_PLATFORM=android-16 ^ 8 | -DCMAKE_LIBRARY_OUTPUT_DIRECTORY="../../../lib/Android/libs/armeabi-v7a" ^ 9 | -DCMAKE_BUILD_TYPE=Release ^ 10 | -DANDROID_NDK=D:\Documents\Android\NDK\android-ndk-r16b\ ^ 11 | -DCMAKE_CXX_FLAGS= ^ 12 | -DCMAKE_SYSTEM_NAME=Android ^ 13 | -DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a ^ 14 | -DCMAKE_SYSTEM_VERSION=16 ^ 15 | -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ^ 16 | -DCMAKE_ANDROID_NDK=D:\Documents\Android\NDK\android-ndk-r16b\ ^ 17 | -DANDROID_STL=c++_static ^ 18 | -DCMAKE_TOOLCHAIN_FILE=D:\Documents\Android\NDK\android-ndk-r16b\build\cmake\android.toolchain.cmake -G Ninja 19 | 20 | 21 | :: make ... 22 | ninja all -C _build_android/armeabi-v7a 23 | 24 | :: cmake ... 25 | cmake.exe ^ 26 | -H"." ^ 27 | -B"./_build_android/arm64-v8a" ^ 28 | -DANDROID_ABI=arm64-v8a ^ 29 | -DANDROID_PLATFORM=android-16 ^ 30 | -DCMAKE_LIBRARY_OUTPUT_DIRECTORY="../../../lib/Android/libs/arm64-v8a" ^ 31 | -DCMAKE_BUILD_TYPE=Release ^ 32 | -DANDROID_NDK=D:\Documents\Android\NDK\android-ndk-r16b ^ 33 | -DCMAKE_CXX_FLAGS= ^ 34 | -DCMAKE_SYSTEM_NAME=Android ^ 35 | -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a ^ 36 | -DCMAKE_SYSTEM_VERSION=16 ^ 37 | -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ^ 38 | -DCMAKE_ANDROID_NDK=D:\Documents\Android\NDK\android-ndk-r16b ^ 39 | -DANDROID_STL=c++_static ^ 40 | -DCMAKE_TOOLCHAIN_FILE=D:\Documents\Android\NDK\android-ndk-r16b\build\cmake\android.toolchain.cmake -G Ninja 41 | 42 | 43 | :: make ... 44 | ninja all -C _build_android/arm64-v8a 45 | 46 | 47 | :: xcopy /Y /E "build_android/Android" "UnityResourceLoader\Assets\Inking\ResourceLoader\Plugins\Android" 48 | 49 | pause -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 xingfa-peng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UnityTextureLoader 2 | 3 | Load texture asynchronously for Unity 4 | 5 | ## support platforms And GraphicsType 6 | 7 | ### Windows 8 | Architectures: x86_64 9 | GraphicsType : D3D11 10 | 11 | ### android 12 | Architectures : armv7a, arm64 13 | GraphicsType : OpenGLES2, OpenGLES3 14 | 15 | Unity 2019.1.0 16 | 17 | ANDROID_PLATFORM=android-16 18 | 19 | ANDROID_NDK=android-ndk-r16b 20 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Inking.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 03cc929062b0b0a478b08d2e5ddf2252 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Inking/TextureLoader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bb9398d8d8c4d2e419e9c83b3940babc 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Inking/TextureLoader/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 34aa1a7d90b841649a0d5d568884c62a 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Inking/TextureLoader/Plugins/Android.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b0894929a3b0ea447a68309bd36aebe1 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Inking/TextureLoader/Plugins/Android/libs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 16551ffec853e25469bc8216ce6c3b32 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Inking/TextureLoader/Plugins/Android/libs/arm64-v8a.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5ae68d06d04e9864ea8feaf680ce88c5 3 | folderAsset: yes 4 | timeCreated: 1635052175 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Inking/TextureLoader/Plugins/Android/libs/arm64-v8a/libInkingTextureLoader.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xingfa-peng/UnityTextureLoader/df7edcc38c7c6ae40846c94ff903a7e743feab51/UnityTextureLoader/Assets/Inking/TextureLoader/Plugins/Android/libs/arm64-v8a/libInkingTextureLoader.so -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Inking/TextureLoader/Plugins/Android/libs/arm64-v8a/libInkingTextureLoader.so.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1263e3101f614a14bb639a3644564b9d 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | isPreloaded: 0 9 | isOverridable: 0 10 | platformData: 11 | - first: 12 | '': Any 13 | second: 14 | enabled: 0 15 | settings: 16 | Exclude Android: 0 17 | Exclude Editor: 1 18 | Exclude Linux: 1 19 | Exclude Linux64: 1 20 | Exclude LinuxUniversal: 1 21 | Exclude OSXUniversal: 1 22 | Exclude Win: 1 23 | Exclude Win64: 1 24 | - first: 25 | Android: Android 26 | second: 27 | enabled: 1 28 | settings: 29 | CPU: ARM64 30 | - first: 31 | Any: 32 | second: 33 | enabled: 0 34 | settings: {} 35 | - first: 36 | Editor: Editor 37 | second: 38 | enabled: 0 39 | settings: 40 | CPU: AnyCPU 41 | DefaultValueInitialized: true 42 | OS: AnyOS 43 | - first: 44 | Facebook: Win 45 | second: 46 | enabled: 0 47 | settings: 48 | CPU: AnyCPU 49 | - first: 50 | Facebook: Win64 51 | second: 52 | enabled: 0 53 | settings: 54 | CPU: AnyCPU 55 | - first: 56 | Standalone: Linux 57 | second: 58 | enabled: 0 59 | settings: 60 | CPU: x86 61 | - first: 62 | Standalone: Linux64 63 | second: 64 | enabled: 0 65 | settings: 66 | CPU: x86_64 67 | - first: 68 | Standalone: LinuxUniversal 69 | second: 70 | enabled: 0 71 | settings: 72 | CPU: None 73 | - first: 74 | Standalone: OSXUniversal 75 | second: 76 | enabled: 0 77 | settings: 78 | CPU: AnyCPU 79 | - first: 80 | Standalone: Win 81 | second: 82 | enabled: 0 83 | settings: 84 | CPU: AnyCPU 85 | - first: 86 | Standalone: Win64 87 | second: 88 | enabled: 0 89 | settings: 90 | CPU: AnyCPU 91 | userData: 92 | assetBundleName: 93 | assetBundleVariant: 94 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Inking/TextureLoader/Plugins/Android/libs/armeabi-v7a.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 91bda7f0653dd7e439397d07ccff4b2c 3 | folderAsset: yes 4 | timeCreated: 1635052175 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Inking/TextureLoader/Plugins/Android/libs/armeabi-v7a/libInkingTextureLoader.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xingfa-peng/UnityTextureLoader/df7edcc38c7c6ae40846c94ff903a7e743feab51/UnityTextureLoader/Assets/Inking/TextureLoader/Plugins/Android/libs/armeabi-v7a/libInkingTextureLoader.so -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Inking/TextureLoader/Plugins/Android/libs/armeabi-v7a/libInkingTextureLoader.so.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9a5fda4fff021e444afe212363333658 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | isPreloaded: 0 9 | isOverridable: 0 10 | platformData: 11 | - first: 12 | '': Any 13 | second: 14 | enabled: 0 15 | settings: 16 | Exclude Android: 0 17 | Exclude Editor: 1 18 | Exclude Linux: 1 19 | Exclude Linux64: 1 20 | Exclude LinuxUniversal: 1 21 | Exclude OSXUniversal: 1 22 | Exclude Win: 1 23 | Exclude Win64: 1 24 | - first: 25 | Android: Android 26 | second: 27 | enabled: 1 28 | settings: 29 | CPU: ARMv7 30 | - first: 31 | Any: 32 | second: 33 | enabled: 0 34 | settings: {} 35 | - first: 36 | Editor: Editor 37 | second: 38 | enabled: 0 39 | settings: 40 | CPU: AnyCPU 41 | DefaultValueInitialized: true 42 | OS: AnyOS 43 | - first: 44 | Facebook: Win 45 | second: 46 | enabled: 0 47 | settings: 48 | CPU: AnyCPU 49 | - first: 50 | Facebook: Win64 51 | second: 52 | enabled: 0 53 | settings: 54 | CPU: AnyCPU 55 | - first: 56 | Standalone: Linux 57 | second: 58 | enabled: 0 59 | settings: 60 | CPU: x86 61 | - first: 62 | Standalone: Linux64 63 | second: 64 | enabled: 0 65 | settings: 66 | CPU: x86_64 67 | - first: 68 | Standalone: LinuxUniversal 69 | second: 70 | enabled: 0 71 | settings: 72 | CPU: None 73 | - first: 74 | Standalone: OSXUniversal 75 | second: 76 | enabled: 0 77 | settings: 78 | CPU: AnyCPU 79 | - first: 80 | Standalone: Win 81 | second: 82 | enabled: 0 83 | settings: 84 | CPU: AnyCPU 85 | - first: 86 | Standalone: Win64 87 | second: 88 | enabled: 0 89 | settings: 90 | CPU: AnyCPU 91 | userData: 92 | assetBundleName: 93 | assetBundleVariant: 94 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Inking/TextureLoader/Plugins/x86_64.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 02c24a5e30748e54bba313e6218e743d 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Inking/TextureLoader/Plugins/x86_64/InkingTextureLoader.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xingfa-peng/UnityTextureLoader/df7edcc38c7c6ae40846c94ff903a7e743feab51/UnityTextureLoader/Assets/Inking/TextureLoader/Plugins/x86_64/InkingTextureLoader.dll -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Inking/TextureLoader/Plugins/x86_64/InkingTextureLoader.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2303b3a820ce79b40a4e641b34cf25de 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 0 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | Any: 16 | second: 17 | enabled: 1 18 | settings: {} 19 | - first: 20 | Editor: Editor 21 | second: 22 | enabled: 0 23 | settings: 24 | CPU: x86_64 25 | DefaultValueInitialized: true 26 | - first: 27 | Standalone: Linux64 28 | second: 29 | enabled: 1 30 | settings: 31 | CPU: AnyCPU 32 | - first: 33 | Standalone: OSXUniversal 34 | second: 35 | enabled: 0 36 | settings: 37 | CPU: x86_64 38 | - first: 39 | Standalone: Win 40 | second: 41 | enabled: 0 42 | settings: 43 | CPU: None 44 | - first: 45 | Standalone: Win64 46 | second: 47 | enabled: 1 48 | settings: 49 | CPU: AnyCPU 50 | userData: 51 | assetBundleName: 52 | assetBundleVariant: 53 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Inking/TextureLoader/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 93118612fa338014b8c6311f3f98d2f0 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Inking/TextureLoader/Scripts/Texture2D.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | using System.Runtime.InteropServices; 4 | using UnityEngine; 5 | 6 | namespace Inking 7 | { 8 | public class Texture2D 9 | { 10 | [DllImport(TextureLoader.DllName)] 11 | static extern int Inking_Texture2D_GetWidth(IntPtr native); 12 | 13 | [DllImport(TextureLoader.DllName)] 14 | static extern int Inking_Texture2D_GetHeight(IntPtr native); 15 | 16 | [DllImport(TextureLoader.DllName)] 17 | static extern IntPtr Inking_Texture2D_GetNative(IntPtr native); 18 | 19 | [DllImport(TextureLoader.DllName)] 20 | static extern void Inking_Texture2D_Release(IntPtr native); 21 | 22 | public string Name; 23 | 24 | IntPtr _native; 25 | 26 | public Texture2D(IntPtr native) 27 | { 28 | _native = native; 29 | } 30 | 31 | ~Texture2D() 32 | { 33 | Inking_Texture2D_Release(_native); 34 | } 35 | 36 | public IntPtr Native 37 | { 38 | get 39 | { 40 | return Inking_Texture2D_GetNative(_native); 41 | } 42 | } 43 | 44 | public int Width 45 | { 46 | get 47 | { 48 | return Inking_Texture2D_GetWidth(_native); 49 | } 50 | } 51 | 52 | public int Height 53 | { 54 | get 55 | { 56 | return Inking_Texture2D_GetHeight(_native); 57 | } 58 | } 59 | 60 | public TextureFormat Format 61 | { 62 | get 63 | { 64 | return TextureFormat.RGBA32; 65 | } 66 | } 67 | 68 | public UnityEngine.Texture2D ToUnityTexture2D() 69 | { 70 | var texture = UnityEngine.Texture2D.CreateExternalTexture(Width, 71 | Height, 72 | Format, 73 | false, 74 | true, 75 | Native); 76 | 77 | texture.name = this.Name; 78 | 79 | return texture; 80 | } 81 | }; 82 | } 83 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Inking/TextureLoader/Scripts/Texture2D.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 57678269dcfc90646b9a9d22bbca814f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Inking/TextureLoader/Scripts/TextureLoadAsyncOperation.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | using System.Runtime.InteropServices; 5 | using UnityEngine; 6 | 7 | namespace Inking 8 | { 9 | public class TextureLoadAsyncOperation : CustomYieldInstruction 10 | { 11 | [DllImport(TextureLoader.DllName)] 12 | static extern IntPtr Inking_TextureLoadAsyncOperation_New(); 13 | 14 | [DllImport(TextureLoader.DllName)] 15 | static extern IntPtr Inking_TextureLoadAsyncOperation_Release(IntPtr native); 16 | 17 | [DllImport(TextureLoader.DllName)] 18 | static extern int Inking_TextureLoadAsyncOperation_GetState(IntPtr native); 19 | 20 | [DllImport(TextureLoader.DllName)] 21 | static extern IntPtr Inking_TextureLoadAsyncOperation_GetTexture(IntPtr native); 22 | 23 | IntPtr _native; 24 | 25 | public TextureLoadAsyncOperation() 26 | { 27 | _native = Inking_TextureLoadAsyncOperation_New(); 28 | } 29 | 30 | public TextureLoadAsyncOperation(IntPtr native) 31 | { 32 | _native = native; 33 | } 34 | 35 | ~TextureLoadAsyncOperation() 36 | { 37 | Inking_TextureLoadAsyncOperation_Release(_native); 38 | } 39 | 40 | public TextureLoadAsyncOperationState state 41 | { 42 | get 43 | { 44 | return (TextureLoadAsyncOperationState)Inking_TextureLoadAsyncOperation_GetState(_native); 45 | } 46 | } 47 | 48 | public override bool keepWaiting 49 | { 50 | get 51 | { 52 | return state == TextureLoadAsyncOperationState.None 53 | || state == TextureLoadAsyncOperationState.Loading; 54 | } 55 | } 56 | 57 | public string fileName; 58 | 59 | Texture2D _texture2D; 60 | 61 | public Texture2D texture2D 62 | { 63 | get 64 | { 65 | if (_texture2D == null) 66 | { 67 | IntPtr nativeTex = Inking_TextureLoadAsyncOperation_GetTexture(_native); 68 | _texture2D = new Inking.Texture2D(nativeTex); 69 | _texture2D.Name = this.fileName; 70 | } 71 | return _texture2D; 72 | } 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Inking/TextureLoader/Scripts/TextureLoadAsyncOperation.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 44cac523f0ca51c4bb7b892f6ec397bf 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Inking/TextureLoader/Scripts/TextureLoadAsyncOperationState.cs: -------------------------------------------------------------------------------- 1 | namespace Inking 2 | { 3 | public enum TextureLoadAsyncOperationState 4 | { 5 | None, 6 | Loading, 7 | LoadSucceed, 8 | LoadFailed, 9 | }; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Inking/TextureLoader/Scripts/TextureLoadAsyncOperationState.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 75ec240eb1000674cb9888ebfc20d362 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Inking/TextureLoader/Scripts/TextureLoadResult.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Inking 3 | { 4 | public enum TextureLoaderResult 5 | { 6 | Succeed, 7 | NoFile, 8 | } 9 | } -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Inking/TextureLoader/Scripts/TextureLoadResult.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fadf25f12dfc6ea4ab79dab2894c71e4 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Inking/TextureLoader/Scripts/TextureLoader.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | using System.Collections; 5 | using System.Collections.Generic; 6 | using System.Runtime.InteropServices; 7 | using UnityEngine; 8 | 9 | namespace Inking 10 | { 11 | public class TextureLoader : MonoBehaviour 12 | { 13 | #if UNITY_IOS && !UNITY_EDITOR 14 | public const string DllName = "__Internal"; 15 | #else 16 | public const string DllName = "InkingTextureLoader"; 17 | #endif 18 | 19 | [DllImport(DllName)] 20 | static extern IntPtr Inking_TextureLoader_GetInstance(); 21 | 22 | #if UNITY_STANDALONE_WIN || UNITY_EDITOR 23 | [DllImport(DllName)] 24 | static extern IntPtr Inking_TextureLoader_LoadAsync(IntPtr _native, [MarshalAs(UnmanagedType.LPWStr)]string fileName, ColorSpace colorSpace); 25 | 26 | #else 27 | [DllImport(DllName)] 28 | static extern IntPtr Inking_TextureLoader_LoadAsync(IntPtr _native, string fileName, ColorSpace colorSpace); 29 | #endif 30 | 31 | [DllImport(DllName)] 32 | static extern IntPtr Inking_TextureLoader_LoadAsyncFromMemory(IntPtr _native, byte[] buffer, int bufferLen, ColorSpace colorSpace); 33 | 34 | [DllImport(DllName)] 35 | static extern void Inking_TextureLoader_Update(IntPtr native); 36 | 37 | [DllImport(DllName)] 38 | static extern IntPtr GetRenderEventFunc(); 39 | 40 | IntPtr _native; 41 | 42 | public TextureLoader() 43 | { 44 | } 45 | 46 | ~TextureLoader() 47 | { 48 | } 49 | 50 | static TextureLoader _instance; 51 | public static TextureLoader Instance 52 | { 53 | get 54 | { 55 | if (_instance == null) 56 | { 57 | var obj = new GameObject(typeof(TextureLoader).Name); 58 | DontDestroyOnLoad(obj); 59 | _instance = obj.AddComponent(); 60 | } 61 | return _instance; 62 | } 63 | } 64 | 65 | private void Awake() 66 | { 67 | _native = Inking_TextureLoader_GetInstance(); 68 | } 69 | 70 | public void Start() 71 | { 72 | GL.IssuePluginEvent(GetRenderEventFunc(), 1); 73 | } 74 | 75 | public TextureLoadAsyncOperation LoadAsync(string fileName, ColorSpace colorSpace) 76 | { 77 | IntPtr ptr = Inking_TextureLoader_LoadAsync(_native, fileName, colorSpace); 78 | var operation = new TextureLoadAsyncOperation(ptr); 79 | operation.fileName = fileName; 80 | return operation; 81 | } 82 | 83 | public TextureLoadAsyncOperation LoadAsyncFromMemory(ref byte[] bytes, ColorSpace colorSpace) 84 | { 85 | IntPtr ptr = Inking_TextureLoader_LoadAsyncFromMemory(_native, bytes, bytes.Length, colorSpace); 86 | return new TextureLoadAsyncOperation(ptr); 87 | } 88 | 89 | 90 | public void Update() 91 | { 92 | Inking_TextureLoader_Update(_native); 93 | } 94 | 95 | IEnumerator _LoadAsync(string fileName, ColorSpace colorSpace, Action onLoadSucceed, Action onLoadFailed) 96 | { 97 | var operation = LoadAsync(fileName, colorSpace); 98 | 99 | yield return operation; 100 | 101 | if (operation != null 102 | && operation.state == TextureLoadAsyncOperationState.LoadSucceed) 103 | { 104 | if(onLoadSucceed != null) 105 | onLoadSucceed.Invoke(operation.texture2D); 106 | } 107 | else 108 | { 109 | if(onLoadFailed != null) 110 | onLoadFailed.Invoke(); 111 | } 112 | } 113 | 114 | public void LoadAsync(string fileName, ColorSpace colorSpace, Action onLoadSucceed, Action onLoadFailed) 115 | { 116 | StartCoroutine(_LoadAsync(fileName, colorSpace, onLoadSucceed, onLoadFailed)); 117 | } 118 | 119 | IEnumerator _LoadAsyncFromMemory(byte[] bytes, ColorSpace colorSpace, Action onLoadSucceed, Action onLoadFailed) 120 | { 121 | var operation = LoadAsyncFromMemory(ref bytes, colorSpace); 122 | yield return operation; 123 | 124 | if (operation.state == TextureLoadAsyncOperationState.LoadSucceed) 125 | { 126 | onLoadSucceed?.Invoke(operation.texture2D); 127 | } 128 | else 129 | { 130 | onLoadFailed?.Invoke(); 131 | } 132 | } 133 | 134 | public void LoadAsyncFromMemory(byte[] buffer, ColorSpace colorSpace, Action onLoadSucceed, Action onLoadFailed) 135 | { 136 | StartCoroutine(_LoadAsyncFromMemory(buffer, colorSpace, onLoadSucceed, onLoadFailed)); 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Inking/TextureLoader/Scripts/TextureLoader.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dfb39f0e4c529cd4bb9104b9d8c44b3b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b8863a06575304e4ba81199d7a70656b 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins/NativeGallery.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5e05ed2bddbccb94e9650efb5742e452 3 | folderAsset: yes 4 | timeCreated: 1518877529 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins/NativeGallery/Android.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0a607dcda26e7614f86300c6ca717295 3 | folderAsset: yes 4 | timeCreated: 1498722617 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins/NativeGallery/Android/NGCallbackHelper.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR || UNITY_ANDROID 2 | using UnityEngine; 3 | 4 | namespace NativeGalleryNamespace 5 | { 6 | public class NGCallbackHelper : MonoBehaviour 7 | { 8 | private System.Action mainThreadAction = null; 9 | 10 | private void Awake() 11 | { 12 | DontDestroyOnLoad( gameObject ); 13 | } 14 | 15 | private void Update() 16 | { 17 | if( mainThreadAction != null ) 18 | { 19 | System.Action temp = mainThreadAction; 20 | mainThreadAction = null; 21 | temp(); 22 | } 23 | } 24 | 25 | public void CallOnMainThread( System.Action function ) 26 | { 27 | mainThreadAction = function; 28 | } 29 | } 30 | } 31 | #endif -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins/NativeGallery/Android/NGCallbackHelper.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2d517fd0f2f85f24698df2775bee58e9 3 | timeCreated: 1544889149 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins/NativeGallery/Android/NGMediaReceiveCallbackAndroid.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR || UNITY_ANDROID 2 | using UnityEngine; 3 | 4 | namespace NativeGalleryNamespace 5 | { 6 | public class NGMediaReceiveCallbackAndroid : AndroidJavaProxy 7 | { 8 | private readonly NativeGallery.MediaPickCallback callback; 9 | private readonly NativeGallery.MediaPickMultipleCallback callbackMultiple; 10 | 11 | private readonly NGCallbackHelper callbackHelper; 12 | 13 | public NGMediaReceiveCallbackAndroid( NativeGallery.MediaPickCallback callback, NativeGallery.MediaPickMultipleCallback callbackMultiple ) : base( "com.yasirkula.unity.NativeGalleryMediaReceiver" ) 14 | { 15 | this.callback = callback; 16 | this.callbackMultiple = callbackMultiple; 17 | callbackHelper = new GameObject( "NGCallbackHelper" ).AddComponent(); 18 | } 19 | 20 | public void OnMediaReceived( string path ) 21 | { 22 | callbackHelper.CallOnMainThread( () => MediaReceiveCallback( path ) ); 23 | } 24 | 25 | public void OnMultipleMediaReceived( string paths ) 26 | { 27 | string[] result = null; 28 | if( !string.IsNullOrEmpty( paths ) ) 29 | { 30 | string[] pathsSplit = paths.Split( '>' ); 31 | 32 | int validPathCount = 0; 33 | for( int i = 0; i < pathsSplit.Length; i++ ) 34 | { 35 | if( !string.IsNullOrEmpty( pathsSplit[i] ) ) 36 | validPathCount++; 37 | } 38 | 39 | if( validPathCount == 0 ) 40 | pathsSplit = new string[0]; 41 | else if( validPathCount != pathsSplit.Length ) 42 | { 43 | string[] validPaths = new string[validPathCount]; 44 | for( int i = 0, j = 0; i < pathsSplit.Length; i++ ) 45 | { 46 | if( !string.IsNullOrEmpty( pathsSplit[i] ) ) 47 | validPaths[j++] = pathsSplit[i]; 48 | } 49 | 50 | pathsSplit = validPaths; 51 | } 52 | 53 | result = pathsSplit; 54 | } 55 | 56 | callbackHelper.CallOnMainThread( () => MediaReceiveMultipleCallback( result ) ); 57 | } 58 | 59 | private void MediaReceiveCallback( string path ) 60 | { 61 | if( string.IsNullOrEmpty( path ) ) 62 | path = null; 63 | 64 | try 65 | { 66 | if( callback != null ) 67 | callback( path ); 68 | } 69 | finally 70 | { 71 | Object.Destroy( callbackHelper.gameObject ); 72 | } 73 | } 74 | 75 | private void MediaReceiveMultipleCallback( string[] paths ) 76 | { 77 | if( paths != null && paths.Length == 0 ) 78 | paths = null; 79 | 80 | try 81 | { 82 | if( callbackMultiple != null ) 83 | callbackMultiple( paths ); 84 | } 85 | finally 86 | { 87 | Object.Destroy( callbackHelper.gameObject ); 88 | } 89 | } 90 | } 91 | } 92 | #endif -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins/NativeGallery/Android/NGMediaReceiveCallbackAndroid.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4c18d702b07a63945968db47201b95c9 3 | timeCreated: 1519060539 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins/NativeGallery/Android/NGPermissionCallbackAndroid.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR || UNITY_ANDROID 2 | using System.Threading; 3 | using UnityEngine; 4 | 5 | namespace NativeGalleryNamespace 6 | { 7 | public class NGPermissionCallbackAndroid : AndroidJavaProxy 8 | { 9 | private object threadLock; 10 | public int Result { get; private set; } 11 | 12 | public NGPermissionCallbackAndroid( object threadLock ) : base( "com.yasirkula.unity.NativeGalleryPermissionReceiver" ) 13 | { 14 | Result = -1; 15 | this.threadLock = threadLock; 16 | } 17 | 18 | public void OnPermissionResult( int result ) 19 | { 20 | Result = result; 21 | 22 | lock( threadLock ) 23 | { 24 | Monitor.Pulse( threadLock ); 25 | } 26 | } 27 | } 28 | } 29 | #endif -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins/NativeGallery/Android/NGPermissionCallbackAndroid.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a07afac614af1294d8e72a3c083be028 3 | timeCreated: 1519060539 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins/NativeGallery/Android/NativeGallery.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xingfa-peng/UnityTextureLoader/df7edcc38c7c6ae40846c94ff903a7e743feab51/UnityTextureLoader/Assets/Plugins/NativeGallery/Android/NativeGallery.aar -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins/NativeGallery/Android/NativeGallery.aar.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: db4d55e1212537e4baa84cac66eb6645 3 | timeCreated: 1569764737 4 | licenseType: Free 5 | PluginImporter: 6 | serializedVersion: 2 7 | iconMap: {} 8 | executionOrder: {} 9 | isPreloaded: 0 10 | isOverridable: 0 11 | platformData: 12 | data: 13 | first: 14 | Android: Android 15 | second: 16 | enabled: 1 17 | settings: {} 18 | data: 19 | first: 20 | Any: 21 | second: 22 | enabled: 0 23 | settings: {} 24 | data: 25 | first: 26 | Editor: Editor 27 | second: 28 | enabled: 0 29 | settings: 30 | DefaultValueInitialized: true 31 | userData: 32 | assetBundleName: 33 | assetBundleVariant: 34 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins/NativeGallery/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 19fc6b8ce781591438a952d8aa9104f8 3 | folderAsset: yes 4 | timeCreated: 1521452097 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins/NativeGallery/Editor/NGPostProcessBuild.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using UnityEditor; 3 | using UnityEngine; 4 | #if UNITY_IOS 5 | using UnityEditor.Callbacks; 6 | using UnityEditor.iOS.Xcode; 7 | #endif 8 | 9 | namespace NativeGalleryNamespace 10 | { 11 | [System.Serializable] 12 | public class Settings 13 | { 14 | private const string SAVE_PATH = "ProjectSettings/NativeGallery.json"; 15 | 16 | public bool AutomatedSetup = true; 17 | #if !UNITY_2018_1_OR_NEWER 18 | public bool MinimumiOSTarget8OrAbove = false; 19 | #endif 20 | public string PhotoLibraryUsageDescription = "The app requires access to Photos to interact with it."; 21 | public string PhotoLibraryAdditionsUsageDescription = "The app requires access to Photos to save media to it."; 22 | public bool DontAskLimitedPhotosPermissionAutomaticallyOnIos14 = true; // See: https://mackuba.eu/2020/07/07/photo-library-changes-ios-14/ 23 | 24 | private static Settings m_instance = null; 25 | public static Settings Instance 26 | { 27 | get 28 | { 29 | if( m_instance == null ) 30 | { 31 | try 32 | { 33 | if( File.Exists( SAVE_PATH ) ) 34 | m_instance = JsonUtility.FromJson( File.ReadAllText( SAVE_PATH ) ); 35 | else 36 | m_instance = new Settings(); 37 | } 38 | catch( System.Exception e ) 39 | { 40 | Debug.LogException( e ); 41 | m_instance = new Settings(); 42 | } 43 | } 44 | 45 | return m_instance; 46 | } 47 | } 48 | 49 | public void Save() 50 | { 51 | File.WriteAllText( SAVE_PATH, JsonUtility.ToJson( this, true ) ); 52 | } 53 | 54 | #if UNITY_2018_3_OR_NEWER 55 | [SettingsProvider] 56 | public static SettingsProvider CreatePreferencesGUI() 57 | { 58 | return new SettingsProvider( "Project/yasirkula/Native Gallery", SettingsScope.Project ) 59 | { 60 | guiHandler = ( searchContext ) => PreferencesGUI(), 61 | keywords = new System.Collections.Generic.HashSet() { "Native", "Gallery", "Android", "iOS" } 62 | }; 63 | } 64 | #endif 65 | 66 | #if !UNITY_2018_3_OR_NEWER 67 | [PreferenceItem( "Native Gallery" )] 68 | #endif 69 | public static void PreferencesGUI() 70 | { 71 | EditorGUI.BeginChangeCheck(); 72 | 73 | Instance.AutomatedSetup = EditorGUILayout.Toggle( "Automated Setup", Instance.AutomatedSetup ); 74 | 75 | EditorGUI.BeginDisabledGroup( !Instance.AutomatedSetup ); 76 | #if !UNITY_2018_1_OR_NEWER 77 | Instance.MinimumiOSTarget8OrAbove = EditorGUILayout.Toggle( "Deployment Target Is 8.0 Or Above", Instance.MinimumiOSTarget8OrAbove ); 78 | #endif 79 | Instance.PhotoLibraryUsageDescription = EditorGUILayout.DelayedTextField( "Photo Library Usage Description", Instance.PhotoLibraryUsageDescription ); 80 | Instance.PhotoLibraryAdditionsUsageDescription = EditorGUILayout.DelayedTextField( "Photo Library Additions Usage Description", Instance.PhotoLibraryAdditionsUsageDescription ); 81 | Instance.DontAskLimitedPhotosPermissionAutomaticallyOnIos14 = EditorGUILayout.Toggle( new GUIContent( "Don't Ask Limited Photos Permission Automatically", "See: https://mackuba.eu/2020/07/07/photo-library-changes-ios-14/. It's recommended to keep this setting enabled" ), Instance.DontAskLimitedPhotosPermissionAutomaticallyOnIos14 ); 82 | EditorGUI.EndDisabledGroup(); 83 | 84 | if( EditorGUI.EndChangeCheck() ) 85 | Instance.Save(); 86 | } 87 | } 88 | 89 | public class NGPostProcessBuild 90 | { 91 | #if UNITY_IOS 92 | [PostProcessBuild( 1 )] 93 | public static void OnPostprocessBuild( BuildTarget target, string buildPath ) 94 | { 95 | if( !Settings.Instance.AutomatedSetup ) 96 | return; 97 | 98 | if( target == BuildTarget.iOS ) 99 | { 100 | string pbxProjectPath = PBXProject.GetPBXProjectPath( buildPath ); 101 | string plistPath = Path.Combine( buildPath, "Info.plist" ); 102 | 103 | PBXProject pbxProject = new PBXProject(); 104 | pbxProject.ReadFromFile( pbxProjectPath ); 105 | 106 | #if UNITY_2019_3_OR_NEWER 107 | string targetGUID = pbxProject.GetUnityFrameworkTargetGuid(); 108 | #else 109 | string targetGUID = pbxProject.TargetGuidByName( PBXProject.GetUnityTargetName() ); 110 | #endif 111 | 112 | // Minimum supported iOS version on Unity 2018.1 and later is 8.0 113 | #if !UNITY_2018_1_OR_NEWER 114 | if( !Settings.Instance.MinimumiOSTarget8OrAbove ) 115 | { 116 | pbxProject.AddBuildProperty( targetGUID, "OTHER_LDFLAGS", "-weak_framework Photos" ); 117 | pbxProject.AddBuildProperty( targetGUID, "OTHER_LDFLAGS", "-weak_framework PhotosUI" ); 118 | pbxProject.AddBuildProperty( targetGUID, "OTHER_LDFLAGS", "-framework AssetsLibrary" ); 119 | pbxProject.AddBuildProperty( targetGUID, "OTHER_LDFLAGS", "-framework MobileCoreServices" ); 120 | pbxProject.AddBuildProperty( targetGUID, "OTHER_LDFLAGS", "-framework ImageIO" ); 121 | } 122 | else 123 | #endif 124 | { 125 | pbxProject.AddBuildProperty( targetGUID, "OTHER_LDFLAGS", "-weak_framework PhotosUI" ); 126 | pbxProject.AddBuildProperty( targetGUID, "OTHER_LDFLAGS", "-framework Photos" ); 127 | pbxProject.AddBuildProperty( targetGUID, "OTHER_LDFLAGS", "-framework MobileCoreServices" ); 128 | pbxProject.AddBuildProperty( targetGUID, "OTHER_LDFLAGS", "-framework ImageIO" ); 129 | } 130 | 131 | pbxProject.RemoveFrameworkFromProject( targetGUID, "Photos.framework" ); 132 | 133 | File.WriteAllText( pbxProjectPath, pbxProject.WriteToString() ); 134 | 135 | PlistDocument plist = new PlistDocument(); 136 | plist.ReadFromString( File.ReadAllText( plistPath ) ); 137 | 138 | PlistElementDict rootDict = plist.root; 139 | rootDict.SetString( "NSPhotoLibraryUsageDescription", Settings.Instance.PhotoLibraryUsageDescription ); 140 | rootDict.SetString( "NSPhotoLibraryAddUsageDescription", Settings.Instance.PhotoLibraryAdditionsUsageDescription ); 141 | if( Settings.Instance.DontAskLimitedPhotosPermissionAutomaticallyOnIos14 ) 142 | rootDict.SetBoolean( "PHPhotoLibraryPreventAutomaticLimitedAccessAlert", true ); 143 | 144 | File.WriteAllText( plistPath, plist.WriteToString() ); 145 | } 146 | } 147 | #endif 148 | } 149 | } -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins/NativeGallery/Editor/NGPostProcessBuild.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dff1540cf22bfb749a2422f445cf9427 3 | timeCreated: 1521452119 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins/NativeGallery/Editor/NativeGallery.Editor.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "NativeGallery.Editor", 3 | "references": [], 4 | "includePlatforms": [ 5 | "Editor" 6 | ], 7 | "excludePlatforms": [], 8 | "allowUnsafeCode": false, 9 | "overrideReferences": false, 10 | "precompiledReferences": [], 11 | "autoReferenced": true, 12 | "defineConstraints": [], 13 | "versionDefines": [], 14 | "noEngineReferences": false 15 | } -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins/NativeGallery/Editor/NativeGallery.Editor.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3dffc8e654f00c545a82d0a5274d51eb 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins/NativeGallery/NativeGallery.Runtime.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "NativeGallery.Runtime" 3 | } 4 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins/NativeGallery/NativeGallery.Runtime.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6e5063adab271564ba0098a06a8cebda 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins/NativeGallery/NativeGallery.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ce1403606c3629046a0147d3e705f7cc 3 | timeCreated: 1498722610 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins/NativeGallery/README.txt: -------------------------------------------------------------------------------- 1 | = Native Gallery for Android & iOS = 2 | 3 | Online documentation & example code available at: https://github.com/yasirkula/UnityNativeGallery 4 | E-mail: yasirkula@gmail.com 5 | 6 | 7 | 1. ABOUT 8 | This plugin helps you interact with Gallery/Photos on Android & iOS. 9 | 10 | 11 | 2. HOW TO 12 | for Android: set "Write Permission" to "External (SDCard)" in Player Settings 13 | for iOS: there are two ways to set up the plugin on iOS: 14 | 15 | a. Automated Setup for iOS 16 | - (optional) change the values of 'Photo Library Usage Description' and 'Photo Library Additions Usage Description' at 'Project Settings/yasirkula/Native Gallery' 17 | - (Unity 2017.4 or earlier) if your minimum Deployment Target (iOS Version) is at least 8.0, set the value of 'Deployment Target Is 8.0 Or Above' to true at 'Project Settings/yasirkula/Native Gallery' 18 | 19 | b. Manual Setup for iOS 20 | - set the value of 'Automated Setup' to false at 'Project Settings/yasirkula/Native Gallery' 21 | - build your project 22 | - enter a Photo Library Usage Description to Info.plist in Xcode 23 | - also enter a "Photo Library Additions Usage Description" to Info.plist in Xcode, if exists 24 | - set Info.plist's "Prevent limited photos access alert" property's value to 1 in Xcode, if exists 25 | - insert "-weak_framework PhotosUI -weak_framework Photos -framework AssetsLibrary -framework MobileCoreServices -framework ImageIO" to the "Other Linker Flags" of Unity-iPhone Target (and UnityFramework Target on Unity 2019.3 or newer) (if your Deployment Target is at least 8.0, it is sufficient to insert "-weak_framework PhotosUI -framework Photos -framework MobileCoreServices -framework ImageIO") 26 | - lastly, remove Photos.framework and PhotosUI.framework from Link Binary With Libraries of Unity-iPhone Target (and UnityFramework Target on Unity 2019.3 or newer) in Build Phases, if exists 27 | 28 | IMPORTANT: If you are targeting iOS 14 or later, you need to build your app with Xcode 12 or later to avoid any permission issues. 29 | 30 | 31 | 3. FAQ 32 | - How can I fetch the path of the saved image or the original path of the picked image on iOS? 33 | You can't. On iOS, these files are stored in an internal directory that we have no access to (I don't think there is even a way to fetch that internal path). 34 | 35 | - Android build fails, it says "error: attribute android:requestLegacyExternalStorage not found" in Console 36 | "android:requestLegacyExternalStorage" attribute in AndroidManifest.xml fixes a rare UnauthorizedAccessException on Android 10 but requires you to update your Android SDK to at least SDK 29. If this isn't possible for you, you should open NativeGallery.aar with WinRAR or 7-Zip and then remove the "" tag from AndroidManifest.xml. 37 | 38 | - Can't access the Gallery, it says "java.lang.ClassNotFoundException: com.yasirkula.unity.NativeGallery" in Logcat 39 | If you are sure that your plugin is up-to-date, then enable "Custom Proguard File" option from Player Settings and add the following line to that file: -keep class com.yasirkula.unity.* { *; } 40 | 41 | - Nothing happens when I try to access the Gallery on Android 42 | Make sure that you've set the "Write Permission" to "External (SDCard)" in Player Settings. 43 | 44 | - NativeGallery functions return Permission.Denied even though I've set "Write Permission" to "External (SDCard)" 45 | Declare the WRITE_EXTERNAL_STORAGE permission manually in your Plugins/Android/AndroidManifest.xml file as follows: 46 | You'll need to add the following attribute to the '' element: xmlns:tools="http://schemas.android.com/tools" 47 | 48 | - Saving image/video doesn't work properly 49 | Make sure that the "filename" parameter of the Save function includes the file's extension, as well 50 | 51 | 52 | 4. SCRIPTING API 53 | Please see the online documentation for a more in-depth documentation of the Scripting API: https://github.com/yasirkula/UnityNativeGallery 54 | 55 | enum NativeGallery.PermissionType { Read = 0, Write = 1 }; 56 | enum NativeGallery.Permission { Denied = 0, Granted = 1, ShouldAsk = 2 }; 57 | enum NativeGallery.ImageOrientation { Unknown = -1, Normal = 0, Rotate90 = 1, Rotate180 = 2, Rotate270 = 3, FlipHorizontal = 4, Transpose = 5, FlipVertical = 6, Transverse = 7 }; // EXIF orientation: http://sylvana.net/jpegcrop/exif_orientation.html (indices are reordered) 58 | enum MediaType { Image = 1, Video = 2, Audio = 4 }; 59 | 60 | delegate void MediaSaveCallback( bool success, string path ); 61 | delegate void NativeGallery.MediaPickCallback( string path ); 62 | delegate void MediaPickMultipleCallback( string[] paths ); 63 | 64 | //// Saving Media To Gallery/Photos //// 65 | 66 | // On Android, your images/videos are saved at DCIM/album/filename. On iOS 14+, the image/video will be saved to the default Photos album (i.e. album parameter will be ignored). On earlier iOS versions, the image/video will be saved to the target album. 67 | // NOTE: Make sure that the filename parameter includes the file's extension, as well 68 | // IMPORTANT: NativeGallery will never overwrite existing media on the Gallery. If there is a name conflict, NativeGallery will ensure a unique filename. So don't put '{0}' in filename anymore (for new users, putting {0} in filename was recommended in order to ensure unique filenames in earlier versions, this is no longer necessary). 69 | // MediaSaveCallback takes "bool success" and "string path" parameters. If the image/video is saved successfully, success becomes true. On Android, path stores where the image/video was saved to (is null on iOS). If the raw filepath can't be determined, an abstract Storage Access Framework path will be returned (File.Exists returns false for that path) 70 | NativeGallery.Permission NativeGallery.SaveImageToGallery( byte[] mediaBytes, string album, string filename, MediaSaveCallback callback = null ); 71 | NativeGallery.Permission NativeGallery.SaveImageToGallery( string existingMediaPath, string album, string filename, MediaSaveCallback callback = null ); 72 | NativeGallery.Permission NativeGallery.SaveImageToGallery( Texture2D image, string album, string filename, MediaSaveCallback callback = null ); 73 | NativeGallery.Permission NativeGallery.SaveVideoToGallery( byte[] mediaBytes, string album, string filename, MediaSaveCallback callback = null ); 74 | NativeGallery.Permission NativeGallery.SaveVideoToGallery( string existingMediaPath, string album, string filename, MediaSaveCallback callback = null ); 75 | 76 | 77 | //// Retrieving Media From Gallery/Photos //// 78 | 79 | // This operation is asynchronous! After user selects an image/video or cancels the operation, the callback is called (on main thread) 80 | // MediaPickCallback takes a string parameter which stores the path of the selected image/video, or null if nothing is selected 81 | // MediaPickMultipleCallback takes a string[] parameter which stores the path(s) of the selected image(s)/video(s), or null if nothing is selected 82 | // title: determines the title of the image picker dialog on Android. Has no effect on iOS 83 | // mime: filters the available images/videos on Android. For example, to request a JPEG image from the user, mime can be set as "image/jpeg". Setting multiple mime types is not possible (in that case, you should leave mime as is). Has no effect on iOS 84 | NativeGallery.Permission NativeGallery.GetImageFromGallery( MediaPickCallback callback, string title = "", string mime = "image/*" ); 85 | NativeGallery.Permission NativeGallery.GetVideoFromGallery( MediaPickCallback callback, string title = "", string mime = "video/*" ); 86 | NativeGallery.Permission NativeGallery.GetImagesFromGallery( MediaPickMultipleCallback callback, string title = "", string mime = "image/*" ); 87 | NativeGallery.Permission NativeGallery.GetVideosFromGallery( MediaPickMultipleCallback callback, string title = "", string mime = "video/*" ); 88 | 89 | // Picking audio files is supported on Android only 90 | NativeGallery.Permission NativeGallery.GetAudioFromGallery( MediaPickCallback callback, string title = "", string mime = "audio/*" ); 91 | NativeGallery.Permission NativeGallery.GetAudiosFromGallery( MediaPickMultipleCallback callback, string title = "", string mime = "audio/*" ); 92 | 93 | // Allows you to pick images/videos/audios at the same time 94 | // mediaTypes: bitwise OR'ed media types to pick from (e.g. to pick an image or video, use 'MediaType.Image | MediaType.Video') 95 | NativeGallery.Permission NativeGallery.GetMixedMediaFromGallery( MediaPickCallback callback, MediaType mediaTypes, string title = "" ); 96 | NativeGallery.Permission NativeGallery.GetMixedMediasFromGallery( MediaPickMultipleCallback callback, MediaType mediaTypes, string title = "" ); 97 | 98 | 99 | // Returns true if selecting multiple images/videos from Gallery/Photos is possible on this device (only available on Android 18 and later and iOS 14 and later) 100 | bool NativeGallery.CanSelectMultipleFilesFromGallery(); 101 | 102 | // Returns true if GetMixedMediaFromGallery/GetMixedMediasFromGallery functions are supported (available on Android 19 and later and all iOS versions) 103 | bool NativeGallery.CanSelectMultipleMediaTypesFromGallery(); 104 | 105 | // Returns true if the user is currently picking media from Gallery/Photos. In that case, another GetImageFromGallery, GetVideoFromGallery or GetAudioFromGallery request will simply be ignored 106 | bool NativeGallery.IsMediaPickerBusy(); 107 | 108 | 109 | //// Runtime Permissions //// 110 | 111 | // Interacting with Gallery/Photos is only possible when permission state is Permission.Granted. Most of the functions request permission internally (and return the result) but you can also check/request the permissions manually 112 | NativeGallery.Permission NativeGallery.CheckPermission( PermissionType permissionType ); 113 | NativeGallery.Permission NativeGallery.RequestPermission( PermissionType permissionType ); 114 | 115 | // If permission state is Permission.Denied, user must grant the necessary permission (Storage on Android and Photos on iOS) manually from the Settings. These functions help you open the Settings directly from within the app 116 | void NativeGallery.OpenSettings(); 117 | bool NativeGallery.CanOpenSettings(); 118 | 119 | 120 | //// Utility Functions //// 121 | 122 | // Creates a Texture2D from the specified image file in correct orientation and returns it. Returns null, if something goes wrong 123 | // maxSize: determines the maximum size of the returned Texture2D in pixels. Larger textures will be down-scaled. If untouched, its value will be set to SystemInfo.maxTextureSize. It is recommended to set a proper maxSize for better performance 124 | // markTextureNonReadable: marks the generated texture as non-readable for better memory usage. If you plan to modify the texture later (e.g. GetPixels/SetPixels), set its value to false 125 | // generateMipmaps: determines whether texture should have mipmaps or not 126 | // linearColorSpace: determines whether texture should be in linear color space or sRGB color space 127 | Texture2D NativeGallery.LoadImageAtPath( string imagePath, int maxSize = -1, bool markTextureNonReadable = true, bool generateMipmaps = true, bool linearColorSpace = false ); 128 | 129 | // Creates a Texture2D thumbnail from a video file and returns it. Returns null, if something goes wrong 130 | // maxSize: determines the maximum size of the returned Texture2D in pixels. Larger thumbnails will be down-scaled. If untouched, its value will be set to SystemInfo.maxTextureSize. It is recommended to set a proper maxSize for better performance 131 | // captureTimeInSeconds: determines the frame of the video that the thumbnail is captured from. If untouched, OS will decide this value 132 | // markTextureNonReadable: see LoadImageAtPath 133 | Texture2D NativeGallery.GetVideoThumbnail( string videoPath, int maxSize = -1, double captureTimeInSeconds = -1.0, bool markTextureNonReadable = true ); 134 | 135 | // Returns an ImageProperties instance that holds the width, height and mime type information of an image file without creating a Texture2D object. Mime type will be null, if it can't be determined 136 | NativeGallery.ImageProperties NativeGallery.GetImageProperties( string imagePath ); 137 | 138 | // Returns a VideoProperties instance that holds the width, height, duration (in milliseconds) and rotation information of a video file. To play a video in correct orientation, you should rotate it by rotation degrees clockwise. For a 90-degree or 270-degree rotated video, values of width and height should be swapped to get the display size of the video 139 | NativeGallery.VideoProperties NativeGallery.GetVideoProperties( string videoPath ); 140 | 141 | // Returns the media type of the file at the specified path: Image, Video, Audio or neither of these (if media type can't be determined) 142 | NativeGallery.MediaType NativeGallery.GetMediaTypeOfFile( string path ); -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins/NativeGallery/README.txt.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: be769f45b807c40459e5bafb18e887d6 3 | timeCreated: 1563308465 4 | licenseType: Free 5 | TextScriptImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins/NativeGallery/iOS.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9c623599351a41a4c84c20f73c9d8976 3 | folderAsset: yes 4 | timeCreated: 1498722622 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins/NativeGallery/iOS/NGMediaReceiveCallbackiOS.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR || UNITY_IOS 2 | using UnityEngine; 3 | 4 | namespace NativeGalleryNamespace 5 | { 6 | public class NGMediaReceiveCallbackiOS : MonoBehaviour 7 | { 8 | private static NGMediaReceiveCallbackiOS instance; 9 | 10 | private NativeGallery.MediaPickCallback callback; 11 | private NativeGallery.MediaPickMultipleCallback callbackMultiple; 12 | 13 | private float nextBusyCheckTime; 14 | 15 | public static bool IsBusy { get; private set; } 16 | 17 | [System.Runtime.InteropServices.DllImport( "__Internal" )] 18 | private static extern int _NativeGallery_IsMediaPickerBusy(); 19 | 20 | public static void Initialize( NativeGallery.MediaPickCallback callback, NativeGallery.MediaPickMultipleCallback callbackMultiple ) 21 | { 22 | if( IsBusy ) 23 | return; 24 | 25 | if( instance == null ) 26 | { 27 | instance = new GameObject( "NGMediaReceiveCallbackiOS" ).AddComponent(); 28 | DontDestroyOnLoad( instance.gameObject ); 29 | } 30 | 31 | instance.callback = callback; 32 | instance.callbackMultiple = callbackMultiple; 33 | 34 | instance.nextBusyCheckTime = Time.realtimeSinceStartup + 1f; 35 | IsBusy = true; 36 | } 37 | 38 | private void Update() 39 | { 40 | if( IsBusy ) 41 | { 42 | if( Time.realtimeSinceStartup >= nextBusyCheckTime ) 43 | { 44 | nextBusyCheckTime = Time.realtimeSinceStartup + 1f; 45 | 46 | if( _NativeGallery_IsMediaPickerBusy() == 0 ) 47 | { 48 | IsBusy = false; 49 | 50 | NativeGallery.MediaPickCallback _callback = callback; 51 | callback = null; 52 | 53 | NativeGallery.MediaPickMultipleCallback _callbackMultiple = callbackMultiple; 54 | callbackMultiple = null; 55 | 56 | if( _callback != null ) 57 | _callback( null ); 58 | 59 | if( _callbackMultiple != null ) 60 | _callbackMultiple( null ); 61 | } 62 | } 63 | } 64 | } 65 | 66 | public void OnMediaReceived( string path ) 67 | { 68 | IsBusy = false; 69 | 70 | if( string.IsNullOrEmpty( path ) ) 71 | path = null; 72 | 73 | NativeGallery.MediaPickCallback _callback = callback; 74 | callback = null; 75 | 76 | if( _callback != null ) 77 | _callback( path ); 78 | } 79 | 80 | public void OnMultipleMediaReceived( string paths ) 81 | { 82 | IsBusy = false; 83 | 84 | string[] _paths = SplitPaths( paths ); 85 | if( _paths != null && _paths.Length == 0 ) 86 | _paths = null; 87 | 88 | NativeGallery.MediaPickMultipleCallback _callbackMultiple = callbackMultiple; 89 | callbackMultiple = null; 90 | 91 | if( _callbackMultiple != null ) 92 | _callbackMultiple( _paths ); 93 | } 94 | 95 | private string[] SplitPaths( string paths ) 96 | { 97 | string[] result = null; 98 | if( !string.IsNullOrEmpty( paths ) ) 99 | { 100 | string[] pathsSplit = paths.Split( '>' ); 101 | 102 | int validPathCount = 0; 103 | for( int i = 0; i < pathsSplit.Length; i++ ) 104 | { 105 | if( !string.IsNullOrEmpty( pathsSplit[i] ) ) 106 | validPathCount++; 107 | } 108 | 109 | if( validPathCount == 0 ) 110 | pathsSplit = new string[0]; 111 | else if( validPathCount != pathsSplit.Length ) 112 | { 113 | string[] validPaths = new string[validPathCount]; 114 | for( int i = 0, j = 0; i < pathsSplit.Length; i++ ) 115 | { 116 | if( !string.IsNullOrEmpty( pathsSplit[i] ) ) 117 | validPaths[j++] = pathsSplit[i]; 118 | } 119 | 120 | pathsSplit = validPaths; 121 | } 122 | 123 | result = pathsSplit; 124 | } 125 | 126 | return result; 127 | } 128 | } 129 | } 130 | #endif -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins/NativeGallery/iOS/NGMediaReceiveCallbackiOS.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 71fb861c149c2d1428544c601e52a33c 3 | timeCreated: 1519060539 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins/NativeGallery/iOS/NGMediaSaveCallbackiOS.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR || UNITY_IOS 2 | using UnityEngine; 3 | 4 | namespace NativeGalleryNamespace 5 | { 6 | public class NGMediaSaveCallbackiOS : MonoBehaviour 7 | { 8 | private static NGMediaSaveCallbackiOS instance; 9 | private NativeGallery.MediaSaveCallback callback; 10 | 11 | public static void Initialize( NativeGallery.MediaSaveCallback callback ) 12 | { 13 | if( instance == null ) 14 | { 15 | instance = new GameObject( "NGMediaSaveCallbackiOS" ).AddComponent(); 16 | DontDestroyOnLoad( instance.gameObject ); 17 | } 18 | else if( instance.callback != null ) 19 | instance.callback( false, null ); 20 | 21 | instance.callback = callback; 22 | } 23 | 24 | public void OnMediaSaveCompleted( string message ) 25 | { 26 | NativeGallery.MediaSaveCallback _callback = callback; 27 | callback = null; 28 | 29 | if( _callback != null ) 30 | _callback( true, null ); 31 | } 32 | 33 | public void OnMediaSaveFailed( string error ) 34 | { 35 | NativeGallery.MediaSaveCallback _callback = callback; 36 | callback = null; 37 | 38 | if( _callback != null ) 39 | _callback( false, null ); 40 | } 41 | } 42 | } 43 | #endif -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins/NativeGallery/iOS/NGMediaSaveCallbackiOS.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9cbb865d0913a0d47bb6d2eb3ad04c4f 3 | timeCreated: 1519060539 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Plugins/NativeGallery/iOS/NativeGallery.mm.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 953e0b740eb03144883db35f72cad8a6 3 | timeCreated: 1498722774 4 | licenseType: Pro 5 | PluginImporter: 6 | serializedVersion: 2 7 | iconMap: {} 8 | executionOrder: {} 9 | isPreloaded: 0 10 | isOverridable: 0 11 | platformData: 12 | data: 13 | first: 14 | Any: 15 | second: 16 | enabled: 0 17 | settings: {} 18 | data: 19 | first: 20 | Editor: Editor 21 | second: 22 | enabled: 0 23 | settings: 24 | DefaultValueInitialized: true 25 | data: 26 | first: 27 | iPhone: iOS 28 | second: 29 | enabled: 1 30 | settings: {} 31 | userData: 32 | assetBundleName: 33 | assetBundleVariant: 34 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 41ec867214d3dd44fabda0675216a570 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Scenes/TextureLoader.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d53003955d303d54f91d9969ce5c8333 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Scenes/TextureLoaderTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using UnityEngine; 6 | using UnityEngine.UI; 7 | 8 | namespace Inking 9 | { 10 | 11 | public class TextureLoaderTest : MonoBehaviour 12 | { 13 | [SerializeField] 14 | RawImage rawImage; 15 | 16 | // Start is called before the first frame update 17 | void Start() 18 | { 19 | } 20 | 21 | public void LoadFromFile_Linear() 22 | { 23 | NativeGallery.GetImageFromGallery((filePath) => 24 | { 25 | if (filePath == null) 26 | return; 27 | 28 | Inking.TextureLoader.Instance.LoadAsync(filePath 29 | , ColorSpace.Linear 30 | , (texture2D) => 31 | { 32 | rawImage.texture = texture2D.ToUnityTexture2D(); 33 | _texture = texture2D; 34 | } 35 | , () => 36 | { 37 | Debug.LogError("load failed..."); 38 | }); 39 | }); 40 | } 41 | 42 | public void LoadFromFile_Gamma() 43 | { 44 | NativeGallery.GetImageFromGallery((filePath) => 45 | { 46 | if (filePath == null) 47 | return; 48 | 49 | Inking.TextureLoader.Instance.LoadAsync(filePath 50 | , ColorSpace.Gamma 51 | , (texture2D) => 52 | { 53 | rawImage.texture = texture2D.ToUnityTexture2D(); 54 | _texture = texture2D; 55 | } 56 | , () => 57 | { 58 | Debug.LogError("load failed..."); 59 | }); 60 | }); 61 | } 62 | 63 | public void LoadFromMemory_Linear() 64 | { 65 | NativeGallery.GetImageFromGallery((filePath) => 66 | { 67 | if (filePath == null) 68 | return; 69 | 70 | var bytes = File.ReadAllBytes(filePath); 71 | Inking.TextureLoader.Instance.LoadAsyncFromMemory(bytes 72 | , ColorSpace.Linear 73 | , (texture2D) => 74 | { 75 | rawImage.texture = texture2D.ToUnityTexture2D(); 76 | _texture = texture2D; 77 | } 78 | , () => 79 | { 80 | Debug.LogError("load failed..."); 81 | }); 82 | }); 83 | } 84 | 85 | public void LoadFromMemory_Gamma() 86 | { 87 | NativeGallery.GetImageFromGallery((filePath) => 88 | { 89 | if (filePath == null) 90 | return; 91 | 92 | var bytes = File.ReadAllBytes(filePath); 93 | Inking.TextureLoader.Instance.LoadAsyncFromMemory(bytes 94 | , ColorSpace.Gamma 95 | , (texture2D) => 96 | { 97 | rawImage.texture = texture2D.ToUnityTexture2D(); 98 | _texture = texture2D; 99 | } 100 | , () => 101 | { 102 | Debug.LogError("load failed..."); 103 | }); 104 | }); 105 | } 106 | 107 | 108 | // Update is called once per frame 109 | void Update() 110 | { 111 | } 112 | 113 | string _path; 114 | 115 | Inking.Texture2D _texture; 116 | 117 | private void LateUpdate() 118 | { 119 | GC.Collect(); 120 | } 121 | 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /UnityTextureLoader/Assets/Scenes/TextureLoaderTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7b07a58d48a366848859c7bd66cdd1c7 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | --------------------------------------------------------------------------------