├── .gitignore ├── LICENSE ├── README.md ├── docs ├── sample_delay.gif ├── sample_dialog.gif └── sample_tweener.gif ├── include ├── CoTaskLib.hpp └── CoTaskLib │ ├── Core.hpp │ ├── Ease.hpp │ ├── LazyDeletionFlatMap.hpp │ ├── License.hpp │ ├── S3dAsyncTask.hpp │ ├── Scene.hpp │ ├── ScreenFade.hpp │ ├── Sequence.hpp │ ├── SimpleDialog.hpp │ ├── Tween.hpp │ └── Typewriter.hpp └── tests ├── .gitignore ├── CoTaskLibTests.sln └── CoTaskLibTests ├── .editorconfig ├── App ├── Resource.rc ├── dll │ └── soundtouch │ │ └── COPYING.TXT ├── engine │ ├── font │ │ └── min │ │ │ ├── LICENSE │ │ │ └── siv3d-min.woff │ ├── shader │ │ ├── d3d11 │ │ │ ├── apply_srgb_curve.ps │ │ │ ├── bitmapfont.ps │ │ │ ├── copy.ps │ │ │ ├── forward3d.ps │ │ │ ├── forward3d.vs │ │ │ ├── fullscreen_triangle.ps │ │ │ ├── fullscreen_triangle.vs │ │ │ ├── gaussian_blur_13.ps │ │ │ ├── gaussian_blur_5.ps │ │ │ ├── gaussian_blur_9.ps │ │ │ ├── line3d.ps │ │ │ ├── line3d.vs │ │ │ ├── msdffont.ps │ │ │ ├── msdffont_outline.ps │ │ │ ├── msdffont_outlineshadow.ps │ │ │ ├── msdffont_shadow.ps │ │ │ ├── msdfprint.ps │ │ │ ├── quad_warp.ps │ │ │ ├── quad_warp.vs │ │ │ ├── round_dot.ps │ │ │ ├── sdffont.ps │ │ │ ├── sdffont_outline.ps │ │ │ ├── sdffont_outlineshadow.ps │ │ │ ├── sdffont_shadow.ps │ │ │ ├── shape.ps │ │ │ ├── sky.ps │ │ │ ├── sprite.vs │ │ │ ├── square_dot.ps │ │ │ └── texture.ps │ │ └── glsl │ │ │ ├── apply_srgb_curve.frag │ │ │ ├── bitmapfont.frag │ │ │ ├── copy.frag │ │ │ ├── forward3d.frag │ │ │ ├── forward3d.vert │ │ │ ├── fullscreen_triangle.frag │ │ │ ├── fullscreen_triangle.vert │ │ │ ├── gaussian_blur_13.frag │ │ │ ├── gaussian_blur_5.frag │ │ │ ├── gaussian_blur_9.frag │ │ │ ├── line3d.frag │ │ │ ├── line3d.vert │ │ │ ├── msdffont.frag │ │ │ ├── msdffont_outline.frag │ │ │ ├── msdffont_outlineshadow.frag │ │ │ ├── msdffont_shadow.frag │ │ │ ├── msdfprint.frag │ │ │ ├── quad_warp.frag │ │ │ ├── quad_warp.vert │ │ │ ├── round_dot.frag │ │ │ ├── sdffont.frag │ │ │ ├── sdffont_outline.frag │ │ │ ├── sdffont_outlineshadow.frag │ │ │ ├── sdffont_shadow.frag │ │ │ ├── shape.frag │ │ │ ├── sky.frag │ │ │ ├── sprite.vert │ │ │ ├── square_dot.frag │ │ │ └── texture.frag │ └── texture │ │ └── box-shadow │ │ ├── 128.png │ │ ├── 16.png │ │ ├── 256.png │ │ ├── 32.png │ │ ├── 64.png │ │ └── 8.png └── icon.ico ├── CMakeLists.txt ├── CoTaskLibTests.vcxproj ├── CoTaskLibTests.vcxproj.filters ├── Main.cpp ├── resources └── engine │ ├── font │ └── min │ │ ├── LICENSE │ │ └── siv3d-min.woff │ ├── shader │ ├── d3d11 │ │ ├── apply_srgb_curve.ps │ │ ├── bitmapfont.ps │ │ ├── copy.ps │ │ ├── forward3d.ps │ │ ├── forward3d.vs │ │ ├── fullscreen_triangle.ps │ │ ├── fullscreen_triangle.vs │ │ ├── gaussian_blur_13.ps │ │ ├── gaussian_blur_5.ps │ │ ├── gaussian_blur_9.ps │ │ ├── line3d.ps │ │ ├── line3d.vs │ │ ├── msdffont.ps │ │ ├── msdffont_outline.ps │ │ ├── msdffont_outlineshadow.ps │ │ ├── msdffont_shadow.ps │ │ ├── msdfprint.ps │ │ ├── quad_warp.ps │ │ ├── quad_warp.vs │ │ ├── round_dot.ps │ │ ├── sdffont.ps │ │ ├── sdffont_outline.ps │ │ ├── sdffont_outlineshadow.ps │ │ ├── sdffont_shadow.ps │ │ ├── shape.ps │ │ ├── sky.ps │ │ ├── sprite.vs │ │ ├── square_dot.ps │ │ └── texture.ps │ └── glsl │ │ ├── apply_srgb_curve.frag │ │ ├── bitmapfont.frag │ │ ├── copy.frag │ │ ├── forward3d.frag │ │ ├── forward3d.vert │ │ ├── fullscreen_triangle.frag │ │ ├── fullscreen_triangle.vert │ │ ├── gaussian_blur_13.frag │ │ ├── gaussian_blur_5.frag │ │ ├── gaussian_blur_9.frag │ │ ├── line3d.frag │ │ ├── line3d.vert │ │ ├── msdffont.frag │ │ ├── msdffont_outline.frag │ │ ├── msdffont_outlineshadow.frag │ │ ├── msdffont_shadow.frag │ │ ├── msdfprint.frag │ │ ├── quad_warp.frag │ │ ├── quad_warp.vert │ │ ├── round_dot.frag │ │ ├── sdffont.frag │ │ ├── sdffont_outline.frag │ │ ├── sdffont_outlineshadow.frag │ │ ├── sdffont_shadow.frag │ │ ├── shape.frag │ │ ├── sky.frag │ │ ├── sprite.vert │ │ ├── square_dot.frag │ │ └── texture.frag │ └── texture │ └── box-shadow │ ├── 128.png │ ├── 16.png │ ├── 256.png │ ├── 32.png │ ├── 64.png │ └── 8.png ├── stdafx.cpp └── stdafx.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024-2025 masaka 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 | -------------------------------------------------------------------------------- /docs/sample_delay.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/docs/sample_delay.gif -------------------------------------------------------------------------------- /docs/sample_dialog.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/docs/sample_dialog.gif -------------------------------------------------------------------------------- /docs/sample_tweener.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/docs/sample_tweener.gif -------------------------------------------------------------------------------- /include/CoTaskLib.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------------------- 2 | // 3 | // CoTaskLib 4 | // 5 | // Copyright (c) 2024-2025 masaka 6 | // 7 | // Licensed under the MIT License. 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in all 17 | // copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | // SOFTWARE. 26 | // 27 | //---------------------------------------------------------------------------------------- 28 | 29 | #pragma once 30 | #include "CoTaskLib/License.hpp" 31 | #include "CoTaskLib/Core.hpp" 32 | #include "CoTaskLib/Scene.hpp" 33 | #include "CoTaskLib/Ease.hpp" 34 | #include "CoTaskLib/Typewriter.hpp" 35 | #include "CoTaskLib/Tween.hpp" 36 | #include "CoTaskLib/Sequence.hpp" 37 | #include "CoTaskLib/ScreenFade.hpp" 38 | #include "CoTaskLib/SimpleDialog.hpp" 39 | #include "CoTaskLib/S3dAsyncTask.hpp" 40 | -------------------------------------------------------------------------------- /include/CoTaskLib/Ease.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------------------- 2 | // 3 | // CoTaskLib 4 | // 5 | // Copyright (c) 2024-2025 masaka 6 | // 7 | // Licensed under the MIT License. 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in all 17 | // copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | // SOFTWARE. 26 | // 27 | //---------------------------------------------------------------------------------------- 28 | 29 | #pragma once 30 | #include "Core.hpp" 31 | 32 | namespace cotasklib::Co 33 | { 34 | namespace detail 35 | { 36 | template 37 | concept StdLerpable = requires(T a, T b, double t) 38 | { 39 | { std::lerp(a, b, t) } -> std::convertible_to; 40 | }; 41 | 42 | template 43 | concept MemberFuncLerpable = requires(T a, const T& b, double t) 44 | { 45 | { a.lerp(b, t) } -> std::convertible_to; 46 | }; 47 | 48 | template 49 | concept Lerpable = StdLerpable || MemberFuncLerpable; 50 | 51 | template 52 | T GenericLerp(const T& a, const T& b, double t) 53 | { 54 | return static_cast(std::lerp(a, b, t)); 55 | } 56 | 57 | template 58 | T GenericLerp(const T& a, const T& b, double t) 59 | { 60 | return a.lerp(b, t); 61 | } 62 | 63 | [[nodiscard]] 64 | inline Task EaseTask(std::function callback, const Duration duration, double easeFunc(double), ISteadyClock* pSteadyClock) 65 | { 66 | detail::DeltaAggregateTimer timer{ duration, pSteadyClock }; 67 | while (true) 68 | { 69 | const double progress = timer.progress0_1(); 70 | callback(easeFunc(progress)); 71 | if (progress >= 1.0) 72 | { 73 | co_return; 74 | } 75 | co_await NextFrame(); 76 | timer.update(); 77 | } 78 | } 79 | 80 | template 81 | struct IsVector2D : std::false_type {}; 82 | 83 | template 84 | struct IsVector2D> : std::true_type {}; 85 | 86 | template 87 | struct IsVector3D : std::false_type {}; 88 | 89 | template 90 | struct IsVector3D> : std::true_type {}; 91 | 92 | template 93 | concept Vector2DConvertibleFrom = detail::IsVector2D::value && std::is_convertible_v; 94 | 95 | template 96 | concept Vector3DConvertibleFrom = detail::IsVector2D::value && std::is_convertible_v; 97 | 98 | template 99 | concept VectorConvertibleFrom = (detail::IsVector2D::value || detail::IsVector3D::value) && std::is_convertible_v; 100 | } 101 | 102 | template 103 | class [[nodiscard]] EaseTaskBuilder 104 | { 105 | private: 106 | std::function m_callback; 107 | Duration m_duration; 108 | T m_from; 109 | T m_to; 110 | double(*m_easeFunc)(double); 111 | ISteadyClock* m_pSteadyClock; 112 | 113 | public: 114 | explicit EaseTaskBuilder(std::function callback, Duration duration, T from, T to, double(*easeFunc)(double), ISteadyClock* pSteadyClock) 115 | : m_callback(std::move(callback)) 116 | , m_duration(duration) 117 | , m_from(std::move(from)) 118 | , m_to(std::move(to)) 119 | , m_easeFunc(easeFunc) 120 | , m_pSteadyClock(pSteadyClock) 121 | { 122 | } 123 | 124 | EaseTaskBuilder(const EaseTaskBuilder&) = default; 125 | EaseTaskBuilder& operator=(const EaseTaskBuilder&) = default; 126 | EaseTaskBuilder(EaseTaskBuilder&&) = default; 127 | EaseTaskBuilder& operator=(EaseTaskBuilder&&) = default; 128 | 129 | EaseTaskBuilder& duration(Duration duration) 130 | { 131 | m_duration = duration; 132 | return *this; 133 | } 134 | 135 | EaseTaskBuilder& from(T from) 136 | { 137 | m_from = std::move(from); 138 | return *this; 139 | } 140 | 141 | template 142 | EaseTaskBuilder& from(U from) requires detail::VectorConvertibleFrom 143 | { 144 | m_from = T::All(from); 145 | return *this; 146 | } 147 | 148 | template 149 | EaseTaskBuilder& from(U x, U y) requires detail::Vector2DConvertibleFrom 150 | { 151 | m_from = T{ x, y }; 152 | return *this; 153 | } 154 | 155 | template 156 | EaseTaskBuilder& from(U x, U y, U z) requires detail::Vector3DConvertibleFrom 157 | { 158 | m_from = T{ x, y, z }; 159 | return *this; 160 | } 161 | 162 | EaseTaskBuilder& to(T to) 163 | { 164 | m_to = std::move(to); 165 | return *this; 166 | } 167 | 168 | template 169 | EaseTaskBuilder& to(U to) requires detail::VectorConvertibleFrom 170 | { 171 | m_to = T::All(to); 172 | return *this; 173 | } 174 | 175 | template 176 | EaseTaskBuilder& to(U x, U y) requires detail::Vector2DConvertibleFrom 177 | { 178 | m_to = T{ x, y }; 179 | return *this; 180 | } 181 | 182 | template 183 | EaseTaskBuilder& to(U x, U y, U z) requires detail::Vector3DConvertibleFrom 184 | { 185 | m_to = T{ x, y, z }; 186 | return *this; 187 | } 188 | 189 | EaseTaskBuilder& fromTo(T from, T to) 190 | { 191 | m_from = std::move(from); 192 | m_to = std::move(to); 193 | return *this; 194 | } 195 | 196 | EaseTaskBuilder& setEase(double(*easeFunc)(double)) 197 | { 198 | m_easeFunc = easeFunc; 199 | return *this; 200 | } 201 | 202 | EaseTaskBuilder& setClock(ISteadyClock* pSteadyClock) 203 | { 204 | m_pSteadyClock = pSteadyClock; 205 | return *this; 206 | } 207 | 208 | Task play() 209 | { 210 | auto lerpedCallback = [from = m_from, to = m_to, callback = m_callback](double t) 211 | { 212 | callback(detail::GenericLerp(from, to, t)); 213 | }; 214 | return detail::EaseTask(std::move(lerpedCallback), m_duration, m_easeFunc, m_pSteadyClock); 215 | } 216 | 217 | ScopedTaskRunner playScoped() 218 | { 219 | return play().runScoped(); 220 | } 221 | 222 | void playAddTo(MultiRunner& mr) 223 | { 224 | play().runAddTo(mr); 225 | } 226 | }; 227 | 228 | template 229 | [[nodiscard]] 230 | EaseTaskBuilder Ease(T* pValue, Duration duration = 0s, double easeFunc(double) = EaseOutQuad, ISteadyClock* pSteadyClock = nullptr) 231 | { 232 | return EaseTaskBuilder([pValue](T value) { *pValue = value; }, duration, *pValue, *pValue, easeFunc, pSteadyClock); 233 | } 234 | 235 | template 236 | [[nodiscard]] 237 | EaseTaskBuilder Ease(std::function callback, Duration duration = 0s, double easeFunc(double) = EaseOutQuad, ISteadyClock* pSteadyClock = nullptr) 238 | { 239 | return EaseTaskBuilder(std::move(callback), duration, T{}, T{}, easeFunc, pSteadyClock); 240 | } 241 | 242 | template 243 | [[nodiscard]] 244 | EaseTaskBuilder LinearEase(T* pValue, Duration duration = 0s, ISteadyClock* pSteadyClock = nullptr) 245 | { 246 | return EaseTaskBuilder([pValue](T value) { *pValue = value; }, duration, *pValue, *pValue, Easing::Linear, pSteadyClock); 247 | } 248 | 249 | template 250 | [[nodiscard]] 251 | EaseTaskBuilder LinearEase(std::function callback, Duration duration = 0s, ISteadyClock* pSteadyClock = nullptr) 252 | { 253 | return EaseTaskBuilder(std::move(callback), duration, T{}, T{}, Easing::Linear, pSteadyClock); 254 | } 255 | } 256 | 257 | #ifndef NO_COTASKLIB_USING 258 | using namespace cotasklib; 259 | #endif 260 | -------------------------------------------------------------------------------- /include/CoTaskLib/LazyDeletionFlatMap.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------------------- 2 | // 3 | // CoTaskLib 4 | // 5 | // Copyright (c) 2024-2025 masaka 6 | // 7 | // Licensed under the MIT License. 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in all 17 | // copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | // SOFTWARE. 26 | // 27 | //---------------------------------------------------------------------------------------- 28 | 29 | #pragma once 30 | #include 31 | 32 | namespace cotasklib::Co::detail 33 | { 34 | // 遅延削除付きのflat_map 35 | template 36 | class LazyDeletionFlatMap 37 | { 38 | public: 39 | using pair_type = std::pair>; 40 | using container_type = Array; 41 | 42 | private: 43 | container_type m_data; 44 | size_t m_nulloptCount = 0; 45 | 46 | template 47 | friend class FilteredIterator; 48 | 49 | public: 50 | template 51 | class FilteredIterator 52 | { 53 | public: 54 | using iterator_type = std::conditional_t; 57 | 58 | using ContainerPtr = std::conditional_t*, 60 | LazyDeletionFlatMap*>; 61 | 62 | private: 63 | ContainerPtr m_containerPtr; 64 | size_t m_index; 65 | 66 | void skipNullopt() 67 | { 68 | while (m_index < m_containerPtr->m_data.size() && !m_containerPtr->m_data[m_index].second.has_value()) 69 | { 70 | ++m_index; 71 | } 72 | } 73 | 74 | public: 75 | using value_type = std::conditional_t; 76 | using reference = std::conditional_t; 77 | using pointer = std::conditional_t; 78 | using difference_type = std::ptrdiff_t; 79 | using iterator_category = std::forward_iterator_tag; // 逆方向は実装を省略 80 | 81 | explicit FilteredIterator(ContainerPtr containerPtr, size_t index) 82 | : m_containerPtr(containerPtr) 83 | , m_index(index) 84 | { 85 | skipNullopt(); 86 | } 87 | 88 | reference operator*() const 89 | { 90 | return *(m_containerPtr->m_data[m_index].second); 91 | } 92 | 93 | pointer operator->() const 94 | { 95 | return &*(m_containerPtr->m_data[m_index].second); 96 | } 97 | 98 | // 前置インクリメント 99 | FilteredIterator& operator++() 100 | { 101 | ++m_index; 102 | skipNullopt(); 103 | return *this; 104 | } 105 | 106 | // 後置インクリメント 107 | FilteredIterator operator++(int) 108 | { 109 | FilteredIterator tmp = *this; 110 | ++(*this); 111 | return tmp; 112 | } 113 | 114 | bool operator==(const FilteredIterator& other) const 115 | { 116 | if (m_containerPtr != other.m_containerPtr) 117 | { 118 | throw Error{ U"LazyDeletionFlatMap: Cannot compare iterators of different containers" }; 119 | } 120 | return m_index == other.m_index; 121 | } 122 | 123 | bool operator!=(const FilteredIterator& other) const 124 | { 125 | if (m_containerPtr != other.m_containerPtr) 126 | { 127 | throw Error{ U"LazyDeletionFlatMap: Cannot compare iterators of different containers" }; 128 | } 129 | return m_index != other.m_index; 130 | } 131 | 132 | size_t index() const 133 | { 134 | return m_index; 135 | } 136 | 137 | const KeyType& key() const 138 | { 139 | return m_containerPtr->m_data[m_index].first; 140 | } 141 | }; 142 | using iterator = FilteredIterator; 143 | using const_iterator = FilteredIterator; 144 | 145 | LazyDeletionFlatMap() = default; 146 | LazyDeletionFlatMap(const LazyDeletionFlatMap&) = default; 147 | LazyDeletionFlatMap& operator=(const LazyDeletionFlatMap&) = default; 148 | LazyDeletionFlatMap(LazyDeletionFlatMap&&) = default; 149 | LazyDeletionFlatMap& operator=(LazyDeletionFlatMap&&) = default; 150 | 151 | T& at(const KeyType& key) 152 | { 153 | const auto it = std::lower_bound(m_data.begin(), m_data.end(), key, 154 | [](const pair_type& p, const KeyType& key) { return p.first < key; }); 155 | if (it != m_data.end() && it->first == key && it->second.has_value()) 156 | { 157 | return *(it->second); 158 | } 159 | throw Error{ U"LazyDeletionFlatMap: Key not found" }; 160 | } 161 | 162 | const T& at(const KeyType& key) const 163 | { 164 | const auto it = std::lower_bound(m_data.begin(), m_data.end(), key, 165 | [](const pair_type& p, const KeyType& key) { return p.first < key; }); 166 | if (it != m_data.end() && it->first == key && it->second.has_value()) 167 | { 168 | return *(it->second); 169 | } 170 | throw Error{ U"LazyDeletionFlatMap: Key not found" }; 171 | } 172 | 173 | void emplace(const KeyType& key, const T& value) 174 | { 175 | if constexpr (IsMonotonic) 176 | { 177 | if (!m_data.empty()) 178 | { 179 | const KeyType& lastKey = m_data.back().first; 180 | if (lastKey >= key) 181 | { 182 | // キーが昇順で挿入されていない場合は例外を投げる 183 | throw Error{ U"LazyDeletionFlatMap: Keys must be inserted in increasing order" }; 184 | } 185 | } 186 | m_data.emplace_back(pair_type{ key, std::make_optional(value) }); 187 | } 188 | else 189 | { 190 | const auto it = std::lower_bound(m_data.begin(), m_data.end(), key, 191 | [](const pair_type& p, const KeyType& key) { return p.first < key; }); 192 | if (it != m_data.end() && it->first == key) 193 | { 194 | if (!it->second.has_value()) 195 | { 196 | --m_nulloptCount; 197 | } 198 | it->second = value; 199 | } 200 | else 201 | { 202 | m_data.emplace(it, pair_type{ key, std::make_optional(value) }); 203 | } 204 | } 205 | } 206 | 207 | void emplace(const KeyType& key, T&& value) 208 | { 209 | if constexpr (IsMonotonic) 210 | { 211 | if (!m_data.empty()) 212 | { 213 | const KeyType& lastKey = m_data.back().first; 214 | if (lastKey >= key) 215 | { 216 | // キーが昇順で挿入されていない場合は例外を投げる 217 | throw Error{ U"LazyDeletionFlatMap: Keys must be inserted in increasing order" }; 218 | } 219 | } 220 | m_data.emplace_back(pair_type{ key, std::make_optional(std::move(value)) }); 221 | } 222 | else 223 | { 224 | const auto it = std::lower_bound(m_data.begin(), m_data.end(), key, 225 | [](const pair_type& p, const KeyType& key) { return p.first < key; }); 226 | if (it != m_data.end() && it->first == key) 227 | { 228 | if (!it->second.has_value()) 229 | { 230 | --m_nulloptCount; 231 | } 232 | it->second = std::move(value); 233 | } 234 | else 235 | { 236 | m_data.emplace(it, pair_type{ key, std::make_optional(std::move(value)) }); 237 | } 238 | } 239 | } 240 | 241 | void erase(const KeyType& key) 242 | { 243 | const auto it = std::lower_bound(m_data.begin(), m_data.end(), key, 244 | [](const pair_type& p, const KeyType& key) { return p.first < key; }); 245 | if (it != m_data.end() && it->first == key) 246 | { 247 | if (it->second.has_value()) 248 | { 249 | it->second = std::nullopt; 250 | ++m_nulloptCount; 251 | } 252 | } 253 | } 254 | 255 | iterator erase(iterator it) 256 | { 257 | if (it == end()) 258 | { 259 | return it; 260 | } 261 | if (m_data[it.index()].second.has_value()) 262 | { 263 | m_data[it.index()].second = std::nullopt; 264 | ++m_nulloptCount; 265 | } 266 | return ++it; 267 | } 268 | 269 | iterator find(const KeyType& key) 270 | { 271 | const auto it = std::lower_bound(m_data.begin(), m_data.end(), key, 272 | [](const pair_type& p, const KeyType& key) { return p.first < key; }); 273 | if (it != m_data.end() && it->first == key && it->second.has_value()) 274 | { 275 | return iterator{ this, static_cast(std::distance(m_data.begin(), it)) }; 276 | } 277 | return end(); 278 | } 279 | 280 | const_iterator find(const KeyType& key) const 281 | { 282 | const auto it = std::lower_bound(m_data.begin(), m_data.end(), key, 283 | [](const pair_type& p, const KeyType& key) { return p.first < key; }); 284 | if (it != m_data.end() && it->first == key && it->second.has_value()) 285 | { 286 | return const_iterator{ this, static_cast(std::distance(m_data.begin(), it)) }; 287 | } 288 | return end(); 289 | } 290 | 291 | void clear() 292 | { 293 | m_data.clear(); 294 | m_nulloptCount = 0; 295 | } 296 | 297 | void compact() 298 | { 299 | m_data.erase( 300 | std::remove_if(m_data.begin(), m_data.end(), 301 | [](const pair_type& p) { return !p.second.has_value(); }), 302 | m_data.end()); 303 | m_nulloptCount = 0; 304 | } 305 | 306 | void reserve(size_t newCapacity) 307 | { 308 | m_data.reserve(newCapacity); 309 | } 310 | 311 | iterator begin() 312 | { 313 | return iterator{ this, 0 }; 314 | } 315 | 316 | iterator end() 317 | { 318 | return iterator{ this, m_data.size() }; 319 | } 320 | 321 | const_iterator begin() const 322 | { 323 | return const_iterator{ this, 0 }; 324 | } 325 | 326 | const_iterator end() const 327 | { 328 | return const_iterator{ this, m_data.size() }; 329 | } 330 | 331 | const_iterator cbegin() const 332 | { 333 | return const_iterator{ this, 0 }; 334 | } 335 | 336 | const_iterator cend() const 337 | { 338 | return const_iterator{ this, m_data.size() }; 339 | } 340 | 341 | std::size_t size() const 342 | { 343 | return m_data.size() - m_nulloptCount; 344 | } 345 | 346 | bool empty() const 347 | { 348 | return size() == 0; 349 | } 350 | 351 | size_t nulloptCount() const 352 | { 353 | return m_nulloptCount; 354 | } 355 | }; 356 | } 357 | -------------------------------------------------------------------------------- /include/CoTaskLib/License.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------------------- 2 | // 3 | // CoTaskLib 4 | // 5 | // Copyright (c) 2024-2025 masaka 6 | // 7 | // Licensed under the MIT License. 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in all 17 | // copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | // SOFTWARE. 26 | // 27 | //---------------------------------------------------------------------------------------- 28 | 29 | #pragma once 30 | #include 31 | 32 | namespace cotasklib::Co 33 | { 34 | inline void AddLicense() 35 | { 36 | LicenseManager::AddLicense( 37 | LicenseInfo 38 | { 39 | UR"-(CoTaskLib)-", 40 | UR"-(Copyright (c) 2024-2025 masaka)-", 41 | UR"-(Permission is hereby granted, free of charge, to any person obtaining a copy 42 | of this software and associated documentation files (the "Software"), to deal 43 | in the Software without restriction, including without limitation the rights 44 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 45 | copies of the Software, and to permit persons to whom the Software is 46 | furnished to do so, subject to the following conditions: 47 | 48 | The above copyright notice and this permission notice shall be included in all 49 | copies or substantial portions of the Software. 50 | 51 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 52 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 53 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 54 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 55 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 56 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 57 | SOFTWARE.)-", 58 | }); 59 | } 60 | } 61 | 62 | #ifndef NO_COTASKLIB_USING 63 | using namespace cotasklib; 64 | #endif 65 | -------------------------------------------------------------------------------- /include/CoTaskLib/S3dAsyncTask.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------------------- 2 | // 3 | // CoTaskLib 4 | // 5 | // Copyright (c) 2024-2025 masaka 6 | // 7 | // Licensed under the MIT License. 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in all 17 | // copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | // SOFTWARE. 26 | // 27 | //---------------------------------------------------------------------------------------- 28 | 29 | #pragma once 30 | #include "Core.hpp" 31 | 32 | namespace cotasklib::Co 33 | { 34 | namespace detail 35 | { 36 | template 37 | class S3dAsyncTaskAwaiter : public IAwaiter 38 | { 39 | private: 40 | AsyncTask m_asyncTask; 41 | bool m_isDone = false; 42 | 43 | public: 44 | explicit S3dAsyncTaskAwaiter(AsyncTask&& asyncTask) 45 | : m_asyncTask(std::move(asyncTask)) 46 | { 47 | } 48 | 49 | S3dAsyncTaskAwaiter(const S3dAsyncTaskAwaiter&) = delete; 50 | 51 | S3dAsyncTaskAwaiter& operator=(const S3dAsyncTaskAwaiter&) = delete; 52 | 53 | S3dAsyncTaskAwaiter(S3dAsyncTaskAwaiter&&) noexcept = default; 54 | 55 | S3dAsyncTaskAwaiter& operator=(S3dAsyncTaskAwaiter&&) = delete; 56 | 57 | void resume() override 58 | { 59 | if (m_isDone) 60 | { 61 | return; 62 | } 63 | m_isDone = m_asyncTask.isReady(); 64 | } 65 | 66 | bool done() const override 67 | { 68 | return m_isDone; 69 | } 70 | 71 | bool await_ready() const 72 | { 73 | return m_isDone; 74 | } 75 | 76 | template 77 | bool await_suspend(std::coroutine_handle> handle) 78 | { 79 | resume(); 80 | if (m_isDone) 81 | { 82 | // フレーム待ちなしで終了した場合は登録不要 83 | return false; 84 | } 85 | handle.promise().setSubAwaiter(this); 86 | return true; 87 | } 88 | 89 | TResult await_resume() 90 | { 91 | return m_asyncTask.get(); 92 | } 93 | }; 94 | 95 | class S3dAsyncHTTPTaskAwaiter : public IAwaiter 96 | { 97 | private: 98 | AsyncHTTPTask m_asyncHTTPTask; 99 | bool m_isDone = false; 100 | 101 | public: 102 | explicit S3dAsyncHTTPTaskAwaiter(AsyncHTTPTask&& asyncHTTPTask) 103 | : m_asyncHTTPTask(std::move(asyncHTTPTask)) 104 | { 105 | } 106 | 107 | explicit S3dAsyncHTTPTaskAwaiter(const AsyncHTTPTask& asyncHTTPTask) 108 | : m_asyncHTTPTask(asyncHTTPTask) 109 | { 110 | } 111 | 112 | // AwaitHTTPTaskはコピー可能だが、他に合わせて保守的にコピー・ムーブ代入禁止にしている 113 | 114 | S3dAsyncHTTPTaskAwaiter(const S3dAsyncHTTPTaskAwaiter&) = delete; 115 | 116 | S3dAsyncHTTPTaskAwaiter& operator=(const S3dAsyncHTTPTaskAwaiter&) = delete; 117 | 118 | S3dAsyncHTTPTaskAwaiter(S3dAsyncHTTPTaskAwaiter&&) = default; 119 | 120 | S3dAsyncHTTPTaskAwaiter& operator=(S3dAsyncHTTPTaskAwaiter&&) = delete; 121 | 122 | void resume() override 123 | { 124 | if (m_isDone) 125 | { 126 | return; 127 | } 128 | m_isDone = m_asyncHTTPTask.isReady(); 129 | } 130 | 131 | bool done() const override 132 | { 133 | return m_isDone; 134 | } 135 | 136 | bool await_ready() const 137 | { 138 | return m_isDone; 139 | } 140 | 141 | template 142 | bool await_suspend(std::coroutine_handle> handle) 143 | { 144 | resume(); 145 | if (m_isDone) 146 | { 147 | // フレーム待ちなしで終了した場合は登録不要 148 | return false; 149 | } 150 | handle.promise().setSubAwaiter(this); 151 | return true; 152 | } 153 | 154 | HTTPResponse await_resume() 155 | { 156 | return m_asyncHTTPTask.getResponse(); 157 | } 158 | }; 159 | } 160 | } 161 | 162 | namespace cotasklib 163 | { 164 | template 165 | [[nodiscard]] 166 | auto operator co_await(AsyncTask&& asyncTask) 167 | { 168 | return Co::detail::S3dAsyncTaskAwaiter{ std::move(asyncTask) }; 169 | } 170 | 171 | [[nodiscard]] 172 | inline auto operator co_await(AsyncHTTPTask&& asyncHTTPTask) 173 | { 174 | return Co::detail::S3dAsyncHTTPTaskAwaiter{ std::move(asyncHTTPTask) }; 175 | } 176 | 177 | [[nodiscard]] 178 | inline auto operator co_await(const AsyncHTTPTask& asyncHTTPTask) 179 | { 180 | return Co::detail::S3dAsyncHTTPTaskAwaiter{ asyncHTTPTask }; 181 | } 182 | } 183 | 184 | #ifndef NO_COTASKLIB_USING 185 | using namespace cotasklib; 186 | using cotasklib::operator co_await; 187 | #endif 188 | -------------------------------------------------------------------------------- /include/CoTaskLib/Scene.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------------------- 2 | // 3 | // CoTaskLib 4 | // 5 | // Copyright (c) 2024-2025 masaka 6 | // 7 | // Licensed under the MIT License. 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in all 17 | // copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | // SOFTWARE. 26 | // 27 | //---------------------------------------------------------------------------------------- 28 | 29 | #pragma once 30 | #include 31 | #include "Core.hpp" 32 | 33 | namespace cotasklib::Co 34 | { 35 | class SceneBase; 36 | 37 | using SceneFactory = std::function()>; 38 | 39 | namespace detail 40 | { 41 | template 42 | concept IsBasicStringView = std::is_same_v>; 43 | 44 | template 45 | concept IsSpan = std::is_same_v>; 46 | 47 | template 48 | concept SceneConcept = std::derived_from; 49 | } 50 | 51 | template 52 | [[nodiscard]] 53 | SceneFactory MakeSceneFactory(Args&&... args) 54 | { 55 | // Args...はコピー構築可能である必要がある 56 | static_assert((std::is_copy_constructible_v && ...), 57 | "Scene constructor arguments must be copy-constructible."); 58 | 59 | // std::basic_string_viewは許可しない 60 | static_assert(!(detail::IsBasicStringView || ...), 61 | "std::basic_string_view is not allowed as a scene constructor argument because it is not deep-copied, risking dangling references. Use std::basic_string instead."); 62 | 63 | // StringViewは許可しない 64 | static_assert(!(std::is_same_v, StringView> || ...), 65 | "StringView is not allowed as a scene constructor argument because it is not deep-copied, risking dangling references. Use String instead."); 66 | 67 | // std::spanは許可しない 68 | static_assert(!(detail::IsSpan || ...), 69 | "std::span is not allowed as a scene constructor argument because it is not deep-copied, risking dangling references. Use std::vector or similar."); 70 | 71 | return [=] { return std::make_unique(args...); }; 72 | } 73 | 74 | class [[nodiscard]] SceneBase : public detail::IDrawerInternal 75 | { 76 | private: 77 | Layer m_layer; 78 | int32 m_drawIndex; 79 | detail::ScopedDrawerInternal* m_pCurrentScopedDrawer = nullptr; 80 | bool m_isPreStart = true; 81 | bool m_isFadingIn = false; 82 | bool m_isFadingOut = false; 83 | bool m_isPostFadeOut = false; 84 | 85 | TaskFinishSource m_taskFinishSource; 86 | 87 | [[nodiscard]] 88 | Task startAndFadeOut() 89 | { 90 | co_await start(); 91 | m_isFadingOut = true; 92 | co_await fadeOut(); 93 | m_isFadingOut = false; 94 | } 95 | 96 | [[nodiscard]] 97 | Task fadeInInternal() 98 | { 99 | m_isFadingIn = true; 100 | co_await fadeIn(); 101 | m_isFadingIn = false; 102 | } 103 | 104 | void drawInternal() const 105 | { 106 | if (m_isPreStart) 107 | { 108 | preStartDraw(); 109 | } 110 | else if (m_isPostFadeOut) 111 | { 112 | postFadeOutDraw(); 113 | } 114 | else 115 | { 116 | draw(); 117 | } 118 | } 119 | 120 | protected: 121 | [[nodiscard]] 122 | virtual Task preStart() 123 | { 124 | return EmptyTask(); 125 | } 126 | 127 | virtual void preStartDraw() const 128 | { 129 | } 130 | 131 | [[nodiscard]] 132 | virtual Task start() = 0; 133 | 134 | virtual void draw() const 135 | { 136 | } 137 | 138 | [[nodiscard]] 139 | virtual Task fadeIn() 140 | { 141 | return EmptyTask(); 142 | } 143 | 144 | [[nodiscard]] 145 | virtual Task fadeOut() 146 | { 147 | return EmptyTask(); 148 | } 149 | 150 | [[nodiscard]] 151 | virtual Task postFadeOut() 152 | { 153 | return EmptyTask(); 154 | } 155 | 156 | virtual void postFadeOutDraw() const 157 | { 158 | } 159 | 160 | [[nodiscard]] 161 | Task waitForFadeIn() 162 | { 163 | if (m_isPreStart) 164 | { 165 | throw Error{ U"waitForFadeIn() must not be called in preStart()" }; 166 | } 167 | 168 | if (m_isPostFadeOut) 169 | { 170 | throw Error{ U"waitForFadeIn() must not be called in postFadeOut()" }; 171 | } 172 | 173 | while (m_isFadingIn) 174 | { 175 | co_await NextFrame(); 176 | } 177 | } 178 | 179 | template 180 | bool requestNextScene(Args&&... args) 181 | { 182 | return m_taskFinishSource.requestFinish(MakeSceneFactory(std::forward(args)...)); 183 | } 184 | 185 | bool requestNextScene(SceneFactory sceneFactory) 186 | { 187 | return m_taskFinishSource.requestFinish(std::move(sceneFactory)); 188 | } 189 | 190 | bool requestSceneFinish() 191 | { 192 | return m_taskFinishSource.requestFinish(nullptr); 193 | } 194 | 195 | [[nodiscard]] 196 | bool nextActionRequested() const 197 | { 198 | return m_taskFinishSource.done(); 199 | } 200 | 201 | void setLayer(Layer layer) 202 | { 203 | m_layer = layer; 204 | if (m_pCurrentScopedDrawer) 205 | { 206 | m_pCurrentScopedDrawer->setLayer(layer); 207 | } 208 | } 209 | 210 | void setDrawIndex(int32 drawIndex) 211 | { 212 | m_drawIndex = drawIndex; 213 | if (m_pCurrentScopedDrawer) 214 | { 215 | m_pCurrentScopedDrawer->setDrawIndex(drawIndex); 216 | } 217 | } 218 | 219 | public: 220 | explicit SceneBase(Layer layer = Layer::Default, int32 drawIndex = DrawIndex::Default) 221 | : m_layer(layer) 222 | , m_drawIndex(drawIndex) 223 | { 224 | } 225 | 226 | // thisポインタをキャプチャするためコピー・ムーブ禁止 227 | SceneBase(const SceneBase&) = delete; 228 | SceneBase& operator=(const SceneBase&) = delete; 229 | SceneBase(SceneBase&&) = delete; 230 | SceneBase& operator=(SceneBase&&) = delete; 231 | 232 | virtual ~SceneBase() = default; 233 | 234 | [[nodiscard]] 235 | bool isPreStart() const 236 | { 237 | return m_isPreStart; 238 | } 239 | 240 | [[nodiscard]] 241 | bool isFadingIn() const 242 | { 243 | return m_isFadingIn; 244 | } 245 | 246 | [[nodiscard]] 247 | bool isFadingOut() const 248 | { 249 | return m_isFadingOut; 250 | } 251 | 252 | // ライブラリ内部で使用するためのタスク実行関数 253 | [[nodiscard]] 254 | Task playInternal()& 255 | { 256 | detail::ScopedDrawerInternal drawer{ this, m_layer, m_drawIndex, &m_pCurrentScopedDrawer }; 257 | 258 | { 259 | m_isPreStart = true; 260 | co_await preStart(); 261 | m_isPreStart = false; 262 | } 263 | 264 | co_await startAndFadeOut().with(fadeInInternal(), WithTiming::Before); 265 | 266 | { 267 | m_isPostFadeOut = true; 268 | co_await postFadeOut(); 269 | m_isPostFadeOut = false; 270 | } 271 | 272 | if (m_taskFinishSource.hasResult()) 273 | { 274 | co_return m_taskFinishSource.result(); 275 | } 276 | else 277 | { 278 | co_return nullptr; 279 | } 280 | } 281 | 282 | // 右辺値参照の場合はタスク実行中にthisがダングリングポインタになるため、使用しようとした場合はコンパイルエラーとする 283 | Task playInternal() && = delete; 284 | }; 285 | 286 | // 毎フレーム呼ばれるupdate関数を記述するタイプのシーン基底クラス 287 | class [[nodiscard]] UpdaterSceneBase : public SceneBase 288 | { 289 | private: 290 | [[nodiscard]] 291 | virtual Task start() override final 292 | { 293 | if (nextActionRequested()) 294 | { 295 | // コンストラクタやpreStart内で次シーンが指定済みの場合は即座に終了 296 | co_return; 297 | } 298 | 299 | // 次シーンが指定されるまでループ 300 | while (true) 301 | { 302 | update(); 303 | if (nextActionRequested()) 304 | { 305 | co_return; 306 | } 307 | co_await NextFrame(); 308 | } 309 | } 310 | 311 | protected: 312 | virtual void update() = 0; 313 | 314 | public: 315 | UpdaterSceneBase() = default; 316 | 317 | UpdaterSceneBase(const UpdaterSceneBase&) = delete; 318 | 319 | UpdaterSceneBase& operator=(const UpdaterSceneBase&) = delete; 320 | 321 | UpdaterSceneBase(UpdaterSceneBase&&) = delete; 322 | 323 | UpdaterSceneBase& operator=(UpdaterSceneBase&&) = delete; 324 | 325 | virtual ~UpdaterSceneBase() = default; 326 | }; 327 | 328 | namespace detail 329 | { 330 | [[nodiscard]] 331 | inline Task ScenePtrToTask(std::unique_ptr scene) 332 | { 333 | std::unique_ptr currentScene = std::move(scene); 334 | 335 | while (true) 336 | { 337 | const SceneFactory nextSceneFactory = co_await currentScene->playInternal(); 338 | 339 | // 次シーンがなければ抜ける 340 | if (nextSceneFactory == nullptr) 341 | { 342 | break; 343 | } 344 | 345 | // 次シーンを生成 346 | currentScene.reset(); // 前シーンのデストラクタを次シーンのコンストラクタより先に呼ぶため、先にresetが必要 347 | currentScene = nextSceneFactory(); 348 | if (!currentScene) 349 | { 350 | break; 351 | } 352 | } 353 | } 354 | } 355 | 356 | template 357 | [[nodiscard]] 358 | Task PlaySceneFrom(Args&&... args) 359 | { 360 | return detail::ScenePtrToTask(std::make_unique(std::forward(args)...)); 361 | } 362 | 363 | inline Task PlaySceneFrom(SceneFactory sceneFactory) 364 | { 365 | auto scenePtr = sceneFactory(); 366 | return detail::ScenePtrToTask(std::move(scenePtr)); 367 | } 368 | 369 | #ifdef __cpp_deleted_function_with_reason 370 | template 371 | auto operator co_await(TScene&& scene) = delete("To co_await a Scene, use Co::PlaySceneFrom() instead."); 372 | 373 | template 374 | auto operator co_await(TScene& scene) = delete("To co_await a Scene, use Co::PlaySceneFrom() instead."); 375 | 376 | auto operator co_await(SceneFactory sceneFactory) = delete("To co_await a Scene created by a SceneFactory, use Co::PlaySceneFrom(SceneFactory) instead."); 377 | #else 378 | template 379 | auto operator co_await(TScene&& scene) = delete; 380 | 381 | template 382 | auto operator co_await(TScene& scene) = delete; 383 | 384 | auto operator co_await(SceneFactory sceneFactory) = delete; 385 | #endif 386 | } 387 | 388 | #ifndef NO_COTASKLIB_USING 389 | using namespace cotasklib; 390 | #endif 391 | -------------------------------------------------------------------------------- /include/CoTaskLib/ScreenFade.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------------------- 2 | // 3 | // CoTaskLib 4 | // 5 | // Copyright (c) 2024-2025 masaka 6 | // 7 | // Licensed under the MIT License. 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in all 17 | // copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | // SOFTWARE. 26 | // 27 | //---------------------------------------------------------------------------------------- 28 | 29 | #pragma once 30 | #include "Core.hpp" 31 | #include "Sequence.hpp" 32 | #include "Ease.hpp" 33 | 34 | namespace cotasklib::Co 35 | { 36 | namespace detail 37 | { 38 | inline void ScreenFill(const ColorF& color) 39 | { 40 | const Transformer2D transform{ Mat3x2::Identity(), Transformer2D::Target::SetLocal }; 41 | 42 | Scene::Rect().draw(color); 43 | } 44 | 45 | class [[nodiscard]] ScreenFadeSequence : public SequenceBase 46 | { 47 | private: 48 | Duration m_duration; 49 | ColorF m_color; 50 | ColorF m_toColor; 51 | double(*m_easeFunc)(double); 52 | ISteadyClock* m_pSteadyClock; 53 | 54 | public: 55 | explicit ScreenFadeSequence(Duration duration, const ColorF& fromColor, const ColorF& toColor, double easeFunc(double), Layer layer, int32 drawIndex, ISteadyClock* pSteadyClock) 56 | : SequenceBase(layer, drawIndex) 57 | , m_duration(duration) 58 | , m_color(fromColor) 59 | , m_toColor(toColor) 60 | , m_easeFunc(easeFunc) 61 | , m_pSteadyClock(pSteadyClock) 62 | { 63 | } 64 | 65 | [[nodiscard]] 66 | Task start() override 67 | { 68 | return Ease(&m_color, m_duration, m_easeFunc, m_pSteadyClock).fromTo(m_color, m_toColor).play(); 69 | } 70 | 71 | void draw() const override 72 | { 73 | ScreenFill(m_color); 74 | } 75 | }; 76 | } 77 | 78 | [[nodiscard]] 79 | inline Task ScreenFadeIn(const Duration& duration, const ColorF& color = Palette::Black, double easeFunc(double) = Easing::Linear, Layer layer = Layer::Transition_FadeIn, int32 drawIndex = DrawIndex::Default, ISteadyClock* pSteadyClock = nullptr) 80 | { 81 | return Play(duration, color, ColorF{ color, 0.0 }, easeFunc, layer, drawIndex, pSteadyClock); 82 | } 83 | 84 | [[nodiscard]] 85 | inline Task ScreenFadeOut(const Duration& duration, const ColorF& color = Palette::Black, double easeFunc(double) = Easing::Linear, Layer layer = Layer::Transition_FadeOut, int32 drawIndex = DrawIndex::Default, ISteadyClock* pSteadyClock = nullptr) 86 | { 87 | return Play(duration, ColorF{ color, 0.0 }, color, easeFunc, layer, drawIndex, pSteadyClock); 88 | } 89 | } 90 | 91 | #ifndef NO_COTASKLIB_USING 92 | using namespace cotasklib; 93 | #endif 94 | -------------------------------------------------------------------------------- /include/CoTaskLib/Sequence.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------------------- 2 | // 3 | // CoTaskLib 4 | // 5 | // Copyright (c) 2024-2025 masaka 6 | // 7 | // Licensed under the MIT License. 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in all 17 | // copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | // SOFTWARE. 26 | // 27 | //---------------------------------------------------------------------------------------- 28 | 29 | #pragma once 30 | #include "Core.hpp" 31 | 32 | namespace cotasklib::Co 33 | { 34 | template 35 | class [[nodiscard]] SequenceBase : public detail::IDrawerInternal 36 | { 37 | static_assert(!std::is_reference_v, "TResult must not be a reference type"); 38 | static_assert(std::is_move_constructible_v || std::is_void_v, "TResult must be move constructible"); 39 | static_assert(!std::is_const_v, "TResult must not have 'const' qualifier"); 40 | 41 | public: 42 | using result_type = TResult; 43 | using result_type_void_replaced = detail::VoidResultTypeReplace; 44 | using finish_callback_type = FinishCallbackType; 45 | 46 | private: 47 | Layer m_layer; 48 | int32 m_drawIndex; 49 | detail::ScopedDrawerInternal* m_pCurrentScopedDrawer = nullptr; 50 | bool m_onceRun = false; 51 | bool m_isPreStart = true; 52 | bool m_isFadingIn = false; 53 | bool m_isFadingOut = false; 54 | bool m_isPostFadeOut = false; 55 | bool m_isDone = false; 56 | TaskFinishSource m_taskFinishSource; 57 | 58 | [[nodiscard]] 59 | Task startAndFadeOut() 60 | { 61 | if constexpr (std::is_void_v) 62 | { 63 | co_await start(); 64 | m_taskFinishSource.requestFinish(); 65 | m_isFadingOut = true; 66 | co_await fadeOut(); 67 | m_isFadingOut = false; 68 | } 69 | else 70 | { 71 | TResult result = co_await start(); 72 | m_taskFinishSource.requestFinish(std::move(result)); 73 | m_isFadingOut = true; 74 | co_await fadeOut(); 75 | m_isFadingOut = false; 76 | } 77 | } 78 | 79 | [[nodiscard]] 80 | Task fadeInInternal() 81 | { 82 | m_isFadingIn = true; 83 | co_await fadeIn(); 84 | m_isFadingIn = false; 85 | } 86 | 87 | void drawInternal() const override 88 | { 89 | if (m_isPreStart) 90 | { 91 | preStartDraw(); 92 | } 93 | else if (m_isPostFadeOut) 94 | { 95 | postFadeOutDraw(); 96 | } 97 | else 98 | { 99 | draw(); 100 | } 101 | } 102 | 103 | protected: 104 | [[nodiscard]] 105 | virtual Task preStart() 106 | { 107 | return EmptyTask(); 108 | } 109 | 110 | virtual void preStartDraw() const 111 | { 112 | } 113 | 114 | [[nodiscard]] 115 | virtual Task start() = 0; 116 | 117 | virtual void draw() const 118 | { 119 | } 120 | 121 | [[nodiscard]] 122 | virtual Task fadeIn() 123 | { 124 | return EmptyTask(); 125 | } 126 | 127 | [[nodiscard]] 128 | virtual Task fadeOut() 129 | { 130 | return EmptyTask(); 131 | } 132 | 133 | [[nodiscard]] 134 | virtual Task postFadeOut() 135 | { 136 | return EmptyTask(); 137 | } 138 | 139 | virtual void postFadeOutDraw() const 140 | { 141 | } 142 | 143 | [[nodiscard]] 144 | Task waitForFadeIn() 145 | { 146 | if (m_isPreStart) 147 | { 148 | throw Error{ U"waitForFadeIn() must not be called in preStart()" }; 149 | } 150 | 151 | if (m_isPostFadeOut) 152 | { 153 | throw Error{ U"waitForFadeIn() must not be called in postFadeOut()" }; 154 | } 155 | 156 | while (m_isFadingIn) 157 | { 158 | co_await NextFrame(); 159 | } 160 | } 161 | 162 | void setLayer(Layer layer) 163 | { 164 | m_layer = layer; 165 | if (m_pCurrentScopedDrawer) 166 | { 167 | m_pCurrentScopedDrawer->setLayer(layer); 168 | } 169 | } 170 | 171 | void setDrawIndex(int32 drawIndex) 172 | { 173 | m_drawIndex = drawIndex; 174 | if (m_pCurrentScopedDrawer) 175 | { 176 | m_pCurrentScopedDrawer->setDrawIndex(drawIndex); 177 | } 178 | } 179 | 180 | public: 181 | explicit SequenceBase(Layer layer = Layer::Default, int32 drawIndex = DrawIndex::Default) 182 | : m_layer(layer) 183 | , m_drawIndex(drawIndex) 184 | { 185 | } 186 | 187 | // thisポインタをキャプチャするためコピー・ムーブ禁止 188 | SequenceBase(const SequenceBase&) = delete; 189 | SequenceBase& operator=(const SequenceBase&) = delete; 190 | SequenceBase(SequenceBase&&) = delete; 191 | SequenceBase& operator=(SequenceBase&&) = delete; 192 | 193 | virtual ~SequenceBase() = default; 194 | 195 | [[nodiscard]] 196 | bool isPreStart() const 197 | { 198 | return m_isPreStart; 199 | } 200 | 201 | [[nodiscard]] 202 | bool isFadingIn() const 203 | { 204 | return m_isFadingIn; 205 | } 206 | 207 | [[nodiscard]] 208 | bool isFadingOut() const 209 | { 210 | return m_isFadingOut; 211 | } 212 | 213 | [[nodiscard]] 214 | bool isPostFadeOut() const 215 | { 216 | return m_isPostFadeOut; 217 | } 218 | 219 | [[nodiscard]] 220 | Layer layer() const 221 | { 222 | return m_layer; 223 | } 224 | 225 | [[nodiscard]] 226 | int32 drawIndex() const 227 | { 228 | return m_drawIndex; 229 | } 230 | 231 | [[nodiscard]] 232 | Task play()& 233 | { 234 | if (m_onceRun) 235 | { 236 | // 2回以上の実行は許可しないため例外を投げる 237 | throw Error{ U"Cannot play the same Sequence multiple times" }; 238 | } 239 | m_onceRun = true; 240 | 241 | detail::ScopedDrawerInternal drawer{ this, m_layer, m_drawIndex, &m_pCurrentScopedDrawer }; 242 | 243 | { 244 | m_isPreStart = true; 245 | co_await preStart(); 246 | m_isPreStart = false; 247 | } 248 | 249 | co_await startAndFadeOut().with(fadeInInternal(), WithTiming::Before); 250 | 251 | { 252 | m_isPostFadeOut = true; 253 | co_await postFadeOut(); 254 | m_isPostFadeOut = false; 255 | } 256 | 257 | m_isDone = true; 258 | 259 | if constexpr (std::is_void_v) 260 | { 261 | co_return; 262 | } 263 | else 264 | { 265 | // m_resultにはstartAndFadeOut内で結果が代入済みなのでそれを返す 266 | co_return m_taskFinishSource.result(); 267 | } 268 | } 269 | 270 | // 右辺値参照の場合はタスク実行中にthisがダングリングポインタになるため、使用しようとした場合はコンパイルエラーとする 271 | Task play() && = delete; 272 | 273 | [[nodiscard]] 274 | ScopedTaskRunner playScoped(FinishCallbackType finishCallback = nullptr, std::function cancelCallback = nullptr)& 275 | { 276 | return play().runScoped(std::move(finishCallback), std::move(cancelCallback)); 277 | } 278 | 279 | [[nodiscard]] 280 | ScopedTaskRunner playScoped(FinishCallbackType finishCallback = nullptr, std::function cancelCallback = nullptr) && = delete; 281 | 282 | void playAddTo(MultiRunner& mr, FinishCallbackType finishCallback = nullptr, std::function cancelCallback = nullptr)& 283 | { 284 | play().runAddTo(mr, std::move(finishCallback), std::move(cancelCallback)); 285 | } 286 | 287 | void playAddTo(MultiRunner& mr, FinishCallbackType finishCallback = nullptr, std::function cancelCallback = nullptr) && = delete; 288 | 289 | [[nodiscard]] 290 | bool done() const 291 | { 292 | return m_isDone; 293 | } 294 | }; 295 | 296 | namespace detail 297 | { 298 | template 299 | concept SequenceConcept = std::derived_from>; 300 | 301 | template 302 | [[nodiscard]] 303 | Task SequencePtrToTask(std::unique_ptr> sequence) 304 | { 305 | co_return co_await sequence->play(); 306 | } 307 | } 308 | 309 | template 310 | [[nodiscard]] 311 | Task Play(Args&&... args) 312 | { 313 | std::unique_ptr> sequence = std::make_unique(std::forward(args)...); 314 | return detail::SequencePtrToTask(std::move(sequence)); 315 | } 316 | 317 | // 毎フレーム呼ばれるupdate関数を記述するタイプのシーケンス基底クラス 318 | template 319 | class [[nodiscard]] UpdaterSequenceBase : public SequenceBase 320 | { 321 | private: 322 | TaskFinishSource m_taskFinishSource; 323 | 324 | [[nodiscard]] 325 | virtual Task start() override final 326 | { 327 | // コンストラクタやpreStart内でrequestFinishが呼ばれた場合は即座に終了 328 | if (m_taskFinishSource.hasResult()) 329 | { 330 | co_return m_taskFinishSource.result(); 331 | } 332 | 333 | while (true) 334 | { 335 | update(); 336 | if (m_taskFinishSource.hasResult()) 337 | { 338 | break; 339 | } 340 | co_await NextFrame(); 341 | } 342 | co_return m_taskFinishSource.result(); 343 | } 344 | 345 | protected: 346 | virtual void update() = 0; 347 | 348 | void requestFinish(const TResult& result) 349 | { 350 | m_taskFinishSource.requestFinish(result); 351 | } 352 | 353 | void requestFinish(TResult&& result) 354 | { 355 | m_taskFinishSource.requestFinish(std::move(result)); 356 | } 357 | 358 | [[nodiscard]] 359 | bool finishRequested() const 360 | { 361 | return m_taskFinishSource.done(); 362 | } 363 | 364 | public: 365 | explicit UpdaterSequenceBase(Layer layer = Layer::Default, int32 drawIndex = DrawIndex::Default) 366 | : SequenceBase(layer, drawIndex) 367 | { 368 | } 369 | 370 | UpdaterSequenceBase(const UpdaterSequenceBase&) = delete; 371 | 372 | UpdaterSequenceBase& operator=(const UpdaterSequenceBase&) = delete; 373 | 374 | UpdaterSequenceBase(UpdaterSequenceBase&&) = default; 375 | 376 | UpdaterSequenceBase& operator=(UpdaterSequenceBase&&) = default; 377 | 378 | virtual ~UpdaterSequenceBase() = default; 379 | }; 380 | 381 | // 毎フレーム呼ばれるupdate関数を記述するタイプのシーケンス基底クラス(void特殊化) 382 | template <> 383 | class [[nodiscard]] UpdaterSequenceBase : public SequenceBase 384 | { 385 | private: 386 | TaskFinishSource m_taskFinishSource; 387 | 388 | [[nodiscard]] 389 | virtual Task start() override final 390 | { 391 | if (m_taskFinishSource.done()) 392 | { 393 | // コンストラクタやpreStart内でrequestFinishが呼ばれた場合は即座に終了 394 | co_return; 395 | } 396 | 397 | while (true) 398 | { 399 | update(); 400 | if (m_taskFinishSource.done()) 401 | { 402 | co_return; 403 | } 404 | co_await NextFrame(); 405 | } 406 | } 407 | 408 | protected: 409 | virtual void update() = 0; 410 | 411 | void requestFinish() 412 | { 413 | m_taskFinishSource.requestFinish(); 414 | } 415 | 416 | [[nodiscard]] 417 | bool finishRequested() const 418 | { 419 | return m_taskFinishSource.done(); 420 | } 421 | 422 | public: 423 | UpdaterSequenceBase() = default; 424 | }; 425 | 426 | #ifdef __cpp_deleted_function_with_reason 427 | template 428 | auto operator co_await(TSequence&& sequence) = delete("To co_await a Sequence, use Co::Play() instead."); 429 | 430 | template 431 | auto operator co_await(TSequence& sequence) = delete("To co_await a Sequence, use Co::Play() instead."); 432 | #else 433 | template 434 | auto operator co_await(TSequence&& sequence) = delete; 435 | 436 | template 437 | auto operator co_await(TSequence& sequence) = delete; 438 | #endif 439 | } 440 | 441 | #ifndef NO_COTASKLIB_USING 442 | using namespace cotasklib; 443 | #endif 444 | -------------------------------------------------------------------------------- /include/CoTaskLib/SimpleDialog.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------------------- 2 | // 3 | // CoTaskLib 4 | // 5 | // Copyright (c) 2024-2025 masaka 6 | // 7 | // Licensed under the MIT License. 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in all 17 | // copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | // SOFTWARE. 26 | // 27 | //---------------------------------------------------------------------------------------- 28 | 29 | #pragma once 30 | #include "Core.hpp" 31 | #include "Sequence.hpp" 32 | #include "Tween.hpp" 33 | 34 | namespace cotasklib::Co 35 | { 36 | namespace detail 37 | { 38 | constexpr Vec2 SimpleDialogSize{ 600, 240 }; 39 | constexpr Vec2 FadeInScaleFrom{ 0.8, 0.8 }; 40 | constexpr Vec2 FadeInScaleTo{ 1.0, 1.0 }; 41 | constexpr Vec2 ButtonSize{ 120, 40 }; 42 | constexpr double ButtonMargin = 20; 43 | constexpr double ButtonOffsetY = 50; 44 | constexpr double FooterOffsetY = 60; 45 | constexpr ColorF BackgroundColor{ 1.0 }; 46 | constexpr ColorF BackgroundColorFooter{ 0.8 }; 47 | constexpr ColorF FrameColor{ 0.67 }; 48 | constexpr ColorF ButtonMouseOverColor{ 0.9, 0.95, 1.0 }; 49 | constexpr ColorF ButtonPressedColor{ 0.8, 0.85, 0.9 }; 50 | constexpr double ButtonRoundSize = 4.8; 51 | constexpr double ButtonFrameThickness = 1; 52 | constexpr double ButtonFrameThicknessPressed = 2; 53 | constexpr ColorF ButtonTextColor = Palette::Black; 54 | constexpr double SimpleDialogRoundSize = 8; 55 | constexpr ColorF TextColor = Palette::Black; 56 | constexpr Duration FadeDuration = 0.25s; 57 | 58 | struct SimpleButton 59 | { 60 | private: 61 | String m_text; 62 | RectF m_rect; 63 | s3d::RoundRect m_roundRect; 64 | bool m_interactable; 65 | bool m_isPressed = false; 66 | bool m_isClicked = false; 67 | 68 | public: 69 | SimpleButton(StringView text, RectF rect, bool interactable = true) 70 | : m_text(text) 71 | , m_rect(rect) 72 | , m_roundRect(rect.rounded(ButtonRoundSize)) 73 | , m_interactable(interactable) 74 | { 75 | } 76 | 77 | void update() 78 | { 79 | if (m_rect.mouseOver()) 80 | { 81 | if (MouseL.down() && !m_isPressed) 82 | { 83 | // 領域内でクリック開始 84 | m_isPressed = true; 85 | } 86 | } 87 | else 88 | { 89 | if (MouseL.down()) 90 | { 91 | // 領域外でクリックが開始 92 | m_isPressed = false; 93 | } 94 | } 95 | 96 | if (MouseL.up()) 97 | { 98 | if (m_isPressed && m_rect.mouseOver()) 99 | { 100 | // 領域内でクリック終了 101 | m_isClicked = true; 102 | } 103 | m_isPressed = false; 104 | } 105 | else 106 | { 107 | m_isClicked = false; 108 | } 109 | } 110 | 111 | void draw() const 112 | { 113 | ColorF color; 114 | if (m_interactable && m_rect.mouseOver()) 115 | { 116 | if (m_isPressed) 117 | { 118 | color = ButtonPressedColor; 119 | Cursor::RequestStyle(CursorStyle::Hand); 120 | } 121 | else if (MouseL.pressed()) 122 | { 123 | // 領域外でクリック開始された場合のマウスオーバーでは色を変えない 124 | color = BackgroundColor; 125 | } 126 | else 127 | { 128 | color = ButtonMouseOverColor; 129 | Cursor::RequestStyle(CursorStyle::Hand); 130 | } 131 | } 132 | else 133 | { 134 | color = BackgroundColor; 135 | } 136 | 137 | m_roundRect 138 | .draw(color) 139 | .drawFrame(m_isPressed ? ButtonFrameThicknessPressed : ButtonFrameThickness, 0, FrameColor); 140 | 141 | const auto& font = SimpleGUI::GetFont(); 142 | font(m_text).drawAt(m_rect.center(), ButtonTextColor); 143 | } 144 | 145 | [[nodiscard]] 146 | const String& text() const 147 | { 148 | return m_text; 149 | } 150 | 151 | [[nodiscard]] 152 | bool isClicked() const 153 | { 154 | return m_isClicked; 155 | } 156 | 157 | [[nodiscard]] 158 | bool interactable() const 159 | { 160 | return m_interactable; 161 | } 162 | 163 | void setInteractable(bool interactable) 164 | { 165 | m_interactable = interactable; 166 | } 167 | }; 168 | 169 | class SimpleDialogSequence : public UpdaterSequenceBase 170 | { 171 | private: 172 | String m_text; 173 | Array m_buttons; 174 | Tweener m_tweener; 175 | 176 | void update() override 177 | { 178 | for (auto& button : m_buttons) 179 | { 180 | button.update(); 181 | } 182 | for (const auto& button : m_buttons) 183 | { 184 | if (button.isClicked()) 185 | { 186 | requestFinish(button.text()); 187 | break; 188 | } 189 | } 190 | } 191 | 192 | void draw() const override 193 | { 194 | const Transformer2D m_tr{ Mat3x2::Identity(), Mat3x2::Identity(), Transformer2D::Target::SetLocal }; 195 | 196 | // メッセージボックスの背景 197 | Scene::Rect().draw(ColorF{ 0.0, m_tweener.alpha() * 0.5 }); 198 | 199 | // メッセージボックス本体を上下に分けて描画 200 | const auto scopedTween = m_tweener.applyScoped(); 201 | const auto boxPos = BoxPos(); 202 | RectF{ boxPos, { SimpleDialogSize.x, SimpleDialogSize.y - FooterOffsetY } }.rounded(SimpleDialogRoundSize, SimpleDialogRoundSize, 0, 0).draw(BackgroundColor); 203 | RectF{ boxPos + Vec2{ 0, SimpleDialogSize.y - FooterOffsetY }, { SimpleDialogSize.x, FooterOffsetY } }.rounded(0, 0, SimpleDialogRoundSize, SimpleDialogRoundSize).draw(BackgroundColorFooter); 204 | 205 | // メッセージ 206 | const auto& font = SimpleGUI::GetFont(); 207 | font(m_text).drawAt(boxPos + (SimpleDialogSize - Vec2{ 0, FooterOffsetY }) / 2, TextColor); 208 | 209 | // ボタン 210 | for (const auto& button : m_buttons) 211 | { 212 | button.draw(); 213 | } 214 | } 215 | 216 | [[nodiscard]] 217 | Task fadeIn() override 218 | { 219 | co_await All( 220 | m_tweener.fadeInAlpha(FadeDuration).play(), 221 | m_tweener.tweenScale(FadeDuration).fromTo(FadeInScaleFrom, FadeInScaleTo).play()); 222 | setButtonInteractable(true); 223 | } 224 | 225 | [[nodiscard]] 226 | Task fadeOut() override 227 | { 228 | setButtonInteractable(false); 229 | co_await All( 230 | m_tweener.fadeOutAlpha(FadeDuration).play(), 231 | m_tweener.tweenScale(FadeDuration).fromTo(FadeInScaleTo, FadeInScaleFrom).play()); 232 | } 233 | 234 | void setButtonInteractable(bool interactable) 235 | { 236 | for (auto& button : m_buttons) 237 | { 238 | button.setInteractable(interactable); 239 | } 240 | } 241 | 242 | [[nodiscard]] 243 | static Vec2 BoxPos() 244 | { 245 | return Scene::Center() - SimpleDialogSize / 2; 246 | } 247 | 248 | [[nodiscard]] 249 | static RectF ButtonRect(std::size_t index, std::size_t numButtons) 250 | { 251 | const auto boxPos = BoxPos(); 252 | const auto buttonPos = boxPos + Vec2{ SimpleDialogSize.x / 2, SimpleDialogSize.y - ButtonOffsetY } + Vec2{ (ButtonSize.x + ButtonMargin / 2) * (index - static_cast(numButtons) / 2), 0 }; 253 | return RectF{ buttonPos, ButtonSize }; 254 | } 255 | 256 | [[nodiscard]] 257 | static Array CreateButtons(const Array& buttonTexts) 258 | { 259 | const std::size_t numButtons = buttonTexts.size(); 260 | Array buttons; 261 | buttons.reserve(numButtons); 262 | for (std::size_t i = 0; i < numButtons; ++i) 263 | { 264 | buttons.emplace_back(buttonTexts[i], ButtonRect(i, numButtons), false); 265 | } 266 | return buttons; 267 | } 268 | 269 | public: 270 | explicit SimpleDialogSequence(StringView text, const Array& buttonTexts, Layer layer, int32 drawIndex) 271 | : UpdaterSequenceBase(layer, drawIndex) 272 | , m_text(text) 273 | , m_buttons(CreateButtons(buttonTexts)) 274 | { 275 | // フォントのテクスチャ生成にかかる時間によりフェードインアニメーションが飛ばないよう、プリロードしておく 276 | SimpleGUI::GetFont().preload(m_text); 277 | for (const auto& buttonText : buttonTexts) 278 | { 279 | SimpleGUI::GetFont().preload(buttonText); 280 | } 281 | } 282 | }; 283 | } 284 | 285 | [[nodiscard]] 286 | inline Task SimpleDialog(StringView text, const Array& buttonTexts, Layer layer = Layer::Modal, int32 drawIndex = DrawIndex::Default) 287 | { 288 | return Play(text, buttonTexts, layer, drawIndex); 289 | } 290 | 291 | [[nodiscard]] 292 | inline Task SimpleDialog(StringView text, Layer layer = Layer::Modal, int32 drawIndex = DrawIndex::Default) 293 | { 294 | return SimpleDialog(text, { U"OK" }, layer, drawIndex).discardResult(); 295 | } 296 | } 297 | 298 | #ifndef NO_COTASKLIB_USING 299 | using namespace cotasklib; 300 | #endif 301 | -------------------------------------------------------------------------------- /include/CoTaskLib/Tween.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------------------- 2 | // 3 | // CoTaskLib 4 | // 5 | // Copyright (c) 2024-2025 masaka 6 | // 7 | // Licensed under the MIT License. 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in all 17 | // copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | // SOFTWARE. 26 | // 27 | //---------------------------------------------------------------------------------------- 28 | 29 | #pragma once 30 | #include "Core.hpp" 31 | #include "Ease.hpp" 32 | 33 | namespace cotasklib::Co 34 | { 35 | #pragma warning(push) 36 | #pragma warning(disable : 4324) 37 | struct ScopedTween 38 | { 39 | Optional transformer = none; 40 | Optional color = none; 41 | Optional colorAdd = none; 42 | }; 43 | #pragma warning(pop) 44 | 45 | class Tweener 46 | { 47 | private: 48 | Vec2 m_pivot = Vec2::Zero(); 49 | Vec2 m_position = Vec2::Zero(); 50 | double(*m_easeFuncPosition)(double); 51 | Vec2 m_scale = Vec2::One(); 52 | double(*m_easeFuncScale)(double); 53 | double m_rotation = 0.0; 54 | double(*m_easeFuncRotation)(double); 55 | ColorF m_color = Palette::White; 56 | double(*m_easeFuncColor)(double); 57 | ColorF m_colorAdd = Palette::Black; 58 | double(*m_easeFuncColorAdd)(double); 59 | double m_alpha = 1.0; 60 | double(*m_easeFuncAlpha)(double); 61 | ISteadyClock* m_pSteadyClock = nullptr; 62 | 63 | public: 64 | explicit Tweener(Vec2 pivot = Scene::CenterF(), double defaultEaseFunc(double) = EaseOutQuad, ISteadyClock* pSteadyClock = nullptr) 65 | : m_pivot(pivot) 66 | , m_easeFuncPosition(defaultEaseFunc) 67 | , m_easeFuncScale(defaultEaseFunc) 68 | , m_easeFuncRotation(defaultEaseFunc) 69 | , m_easeFuncColor(defaultEaseFunc) 70 | , m_easeFuncColorAdd(defaultEaseFunc) 71 | , m_easeFuncAlpha(defaultEaseFunc) 72 | , m_pSteadyClock(pSteadyClock) 73 | { 74 | } 75 | 76 | ~Tweener() = default; 77 | 78 | Tweener(const Tweener&) = default; 79 | Tweener& operator=(const Tweener&) = default; 80 | Tweener(Tweener&&) = default; 81 | Tweener& operator=(Tweener&&) = default; 82 | 83 | const Vec2& pivot() const 84 | { 85 | return m_pivot; 86 | } 87 | 88 | void setPivot(const Vec2& pivot) 89 | { 90 | m_pivot = pivot; 91 | } 92 | 93 | void setPivot(double x, double y) 94 | { 95 | m_pivot = Vec2{ x, y }; 96 | } 97 | 98 | EaseTaskBuilder tweenPosition(Duration duration) 99 | { 100 | return Ease(&m_position, duration, m_easeFuncPosition, m_pSteadyClock).fromTo(m_position, m_position); 101 | } 102 | 103 | const Vec2& position() const 104 | { 105 | return m_position; 106 | } 107 | 108 | void setPosition(const Vec2& position) 109 | { 110 | m_position = position; 111 | } 112 | 113 | void setPosition(double x, double y) 114 | { 115 | m_position = Vec2{ x, y }; 116 | } 117 | 118 | void setPositionEase(double easeFunc(double)) 119 | { 120 | m_easeFuncPosition = easeFunc; 121 | } 122 | 123 | EaseTaskBuilder tweenScale(Duration duration) 124 | { 125 | return Ease(&m_scale, duration, m_easeFuncScale, m_pSteadyClock).fromTo(m_scale, m_scale); 126 | } 127 | 128 | const Vec2& scale() const 129 | { 130 | return m_scale; 131 | } 132 | 133 | void setScale(const Vec2& scale) 134 | { 135 | m_scale = scale; 136 | } 137 | 138 | void setScale(double scale) 139 | { 140 | m_scale = Vec2::All(scale); 141 | } 142 | 143 | void setScale(double x, double y) 144 | { 145 | m_scale = Vec2{ x, y }; 146 | } 147 | 148 | void setScaleEase(double easeFunc(double)) 149 | { 150 | m_easeFuncScale = easeFunc; 151 | } 152 | 153 | EaseTaskBuilder tweenRotation(Duration duration) 154 | { 155 | return Ease(&m_rotation, duration, m_easeFuncRotation, m_pSteadyClock).fromTo(m_rotation, m_rotation); 156 | } 157 | 158 | double rotation() const 159 | { 160 | return m_rotation; 161 | } 162 | 163 | void setRotation(double rotation) 164 | { 165 | m_rotation = rotation; 166 | } 167 | 168 | void setRotationEase(double easeFunc(double)) 169 | { 170 | m_easeFuncRotation = easeFunc; 171 | } 172 | 173 | EaseTaskBuilder tweenColor(Duration duration) 174 | { 175 | return Ease(&m_color, duration, m_easeFuncColor, m_pSteadyClock).fromTo(m_color, m_color); 176 | } 177 | 178 | const ColorF& color() const 179 | { 180 | return m_color; 181 | } 182 | 183 | void setColor(const ColorF& color) 184 | { 185 | m_color = color; 186 | } 187 | 188 | void setColorEase(double easeFunc(double)) 189 | { 190 | m_easeFuncColor = easeFunc; 191 | } 192 | 193 | EaseTaskBuilder tweenColorAdd(Duration duration) 194 | { 195 | return Ease(&m_colorAdd, duration, m_easeFuncColorAdd, m_pSteadyClock).fromTo(m_colorAdd, m_colorAdd); 196 | } 197 | 198 | const ColorF& colorAdd() const 199 | { 200 | return m_colorAdd; 201 | } 202 | 203 | void setColorAdd(const ColorF& colorAdd) 204 | { 205 | m_colorAdd = colorAdd; 206 | } 207 | 208 | void setColorAddEase(double easeFunc(double)) 209 | { 210 | m_easeFuncColorAdd = easeFunc; 211 | } 212 | 213 | EaseTaskBuilder tweenAlpha(Duration duration) 214 | { 215 | return Ease(&m_alpha, duration, m_easeFuncAlpha, m_pSteadyClock).fromTo(m_alpha, m_alpha); 216 | } 217 | 218 | EaseTaskBuilder fadeInAlpha(Duration duration) 219 | { 220 | return Ease(&m_alpha, duration, m_easeFuncAlpha, m_pSteadyClock).fromTo(0.0, 1.0); 221 | } 222 | 223 | EaseTaskBuilder fadeOutAlpha(Duration duration) 224 | { 225 | return Ease(&m_alpha, duration, m_easeFuncAlpha, m_pSteadyClock).fromTo(m_alpha, 0.0); 226 | } 227 | 228 | double alpha() const 229 | { 230 | return m_alpha; 231 | } 232 | 233 | void setAlpha(double alpha) 234 | { 235 | m_alpha = alpha; 236 | } 237 | 238 | void setAlphaEase(double easeFunc(double)) 239 | { 240 | m_easeFuncAlpha = easeFunc; 241 | } 242 | 243 | ScopedTween applyScoped() const 244 | { 245 | ScopedTween scopedTween; 246 | 247 | bool hasTransform = false; 248 | Mat3x2 mat = Mat3x2::Identity(); 249 | 250 | // Easeの最終フレームは必ず目標値がそのまま代入されており誤差は出ないため、ここでは計算機イプシロンを考慮した比較はしない 251 | 252 | if (m_rotation != 0.0) 253 | { 254 | hasTransform = true; 255 | mat = mat.rotated(m_rotation, m_pivot); 256 | } 257 | 258 | if (m_scale != Vec2::One()) 259 | { 260 | hasTransform = true; 261 | mat = mat.scaled(m_scale, m_pivot); 262 | } 263 | 264 | if (m_position != Vec2::Zero()) 265 | { 266 | hasTransform = true; 267 | mat = mat.translated(m_position); 268 | } 269 | 270 | if (hasTransform && mat != Mat3x2::Identity()) 271 | { 272 | scopedTween.transformer.emplace(mat); 273 | } 274 | 275 | if (m_alpha != 1.0 || m_color != ColorF{ Palette::White }) 276 | { 277 | scopedTween.color.emplace(ColorF{ m_color, m_color.a * m_alpha }); 278 | } 279 | 280 | if (m_colorAdd != ColorF{ Palette::Black }) 281 | { 282 | scopedTween.colorAdd.emplace(m_colorAdd); 283 | } 284 | 285 | return scopedTween; 286 | } 287 | }; 288 | } 289 | 290 | #ifndef NO_COTASKLIB_USING 291 | using namespace cotasklib; 292 | #endif 293 | -------------------------------------------------------------------------------- /include/CoTaskLib/Typewriter.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------------------- 2 | // 3 | // CoTaskLib 4 | // 5 | // Copyright (c) 2024-2025 masaka 6 | // 7 | // Licensed under the MIT License. 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in all 17 | // copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | // SOFTWARE. 26 | // 27 | //---------------------------------------------------------------------------------------- 28 | 29 | #pragma once 30 | #include "Core.hpp" 31 | #include "Ease.hpp" 32 | 33 | namespace cotasklib::Co 34 | { 35 | namespace detail 36 | { 37 | [[nodiscard]] 38 | inline Task TypewriterTask(std::function callback, const Duration totalDuration, const String text, ISteadyClock* pSteadyClock) 39 | { 40 | Optional prevLength = none; // textが空文字列の場合の初回コールバック呼び出しを考慮するためOptionalを使用 41 | detail::DeltaAggregateTimer timer{ totalDuration, pSteadyClock }; 42 | while (true) 43 | { 44 | const double progress = timer.progress0_1(); 45 | const std::size_t length = Min(static_cast(1 + text.length() * progress), text.length()); 46 | if (length != prevLength) 47 | { 48 | callback(text.substr(0, length)); 49 | prevLength = length; 50 | } 51 | if (progress >= 1.0) 52 | { 53 | co_return; 54 | } 55 | co_await NextFrame(); 56 | timer.update(); 57 | } 58 | } 59 | } 60 | 61 | class [[nodiscard]] TypewriterTaskBuilder 62 | { 63 | private: 64 | std::function m_callback; 65 | Duration m_duration; 66 | bool m_isOneLetterDuration; 67 | String m_text; 68 | ISteadyClock* m_pSteadyClock; 69 | 70 | [[nodiscard]] 71 | Duration calcTotalDuration() const 72 | { 73 | return m_isOneLetterDuration ? m_duration * m_text.length() : m_duration; 74 | } 75 | 76 | public: 77 | explicit TypewriterTaskBuilder(std::function callback, Duration oneLetterDuration, StringView text, ISteadyClock* pSteadyClock) 78 | : m_callback(std::move(callback)) 79 | , m_duration(oneLetterDuration) 80 | , m_isOneLetterDuration(true) 81 | , m_text(text) 82 | , m_pSteadyClock(pSteadyClock) 83 | { 84 | } 85 | 86 | TypewriterTaskBuilder(const TypewriterTaskBuilder&) = default; 87 | TypewriterTaskBuilder(TypewriterTaskBuilder&&) = default; 88 | TypewriterTaskBuilder& operator=(const TypewriterTaskBuilder&) = default; 89 | TypewriterTaskBuilder& operator=(TypewriterTaskBuilder&&) = default; 90 | 91 | TypewriterTaskBuilder& oneLetterDuration(Duration oneLetterDuration) 92 | { 93 | m_duration = oneLetterDuration; 94 | m_isOneLetterDuration = true; 95 | return *this; 96 | } 97 | 98 | TypewriterTaskBuilder& totalDuration(Duration duration) 99 | { 100 | m_duration = duration; 101 | m_isOneLetterDuration = false; 102 | return *this; 103 | } 104 | 105 | TypewriterTaskBuilder& text(StringView text) 106 | { 107 | m_text = text; 108 | return *this; 109 | } 110 | 111 | TypewriterTaskBuilder& setClock(ISteadyClock* pSteadyClock) 112 | { 113 | m_pSteadyClock = pSteadyClock; 114 | return *this; 115 | } 116 | 117 | Task play() 118 | { 119 | return detail::TypewriterTask(m_callback, calcTotalDuration(), m_text, m_pSteadyClock); 120 | } 121 | 122 | ScopedTaskRunner playScoped() 123 | { 124 | return play().runScoped(); 125 | } 126 | 127 | void playAddTo(MultiRunner& mr) 128 | { 129 | play().runAddTo(mr); 130 | } 131 | }; 132 | 133 | [[nodiscard]] 134 | inline TypewriterTaskBuilder Typewriter(String* pText, Duration oneLetterDuration = 0s, StringView text = U"", ISteadyClock* pSteadyClock = nullptr) 135 | { 136 | return TypewriterTaskBuilder([pText](const String& text) { *pText = text; }, oneLetterDuration, text, pSteadyClock); 137 | } 138 | 139 | [[nodiscard]] 140 | inline TypewriterTaskBuilder Typewriter(std::function callback, Duration oneLetterDuration = 0s, StringView text = U"", ISteadyClock* pSteadyClock = nullptr) 141 | { 142 | return TypewriterTaskBuilder(std::move(callback), oneLetterDuration, text, pSteadyClock); 143 | } 144 | } 145 | 146 | #ifndef NO_COTASKLIB_USING 147 | using namespace cotasklib; 148 | #endif 149 | -------------------------------------------------------------------------------- /tests/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore Visual Studio temporary files, build results, and 2 | # files generated by popular Visual Studio add-ons. 3 | # https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 4 | 5 | # User-specific files 6 | *.rsuser 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Mono auto generated files 16 | mono_crash.* 17 | 18 | # Build results 19 | [Dd]ebug/ 20 | [Dd]ebugPublic/ 21 | [Rr]elease/ 22 | [Rr]eleases/ 23 | x64/ 24 | x86/ 25 | [Aa][Rr][Mm]/ 26 | [Aa][Rr][Mm]64/ 27 | bld/ 28 | [Bb]in/ 29 | [Oo]bj/ 30 | [Ll]og/ 31 | [Ll]ogs/ 32 | 33 | # Visual Studio 2015/2017 cache/options directory 34 | .vs/ 35 | # Uncomment if you have tasks that create the project's static files in wwwroot 36 | #wwwroot/ 37 | 38 | # Visual Studio 2017 auto generated files 39 | Generated\ Files/ 40 | 41 | # MSTest test Results 42 | [Tt]est[Rr]esult*/ 43 | [Bb]uild[Ll]og.* 44 | 45 | # NUnit 46 | *.VisualState.xml 47 | TestResult.xml 48 | nunit-*.xml 49 | 50 | # Build Results of an ATL Project 51 | [Dd]ebugPS/ 52 | [Rr]eleasePS/ 53 | dlldata.c 54 | 55 | # Benchmark Results 56 | BenchmarkDotNet.Artifacts/ 57 | 58 | # .NET Core 59 | project.lock.json 60 | project.fragment.lock.json 61 | artifacts/ 62 | 63 | # StyleCop 64 | StyleCopReport.xml 65 | 66 | # Files built by Visual Studio 67 | *_i.c 68 | *_p.c 69 | *_h.h 70 | *.ilk 71 | *.meta 72 | *.obj 73 | *.iobj 74 | *.pch 75 | *.pdb 76 | *.ipdb 77 | *.pgc 78 | *.pgd 79 | *.rsp 80 | *.sbr 81 | *.tlb 82 | *.tli 83 | *.tlh 84 | *.tmp 85 | *.tmp_proj 86 | *_wpftmp.csproj 87 | *.log 88 | *.vspscc 89 | *.vssscc 90 | .builds 91 | *.pidb 92 | *.svclog 93 | *.scc 94 | *.lastcodeanalysissucceeded 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Coverlet is a free, cross platform Code Coverage Tool 141 | coverage*[.json, .xml, .info] 142 | 143 | # Visual Studio code coverage results 144 | *.coverage 145 | *.coveragexml 146 | 147 | # NCrunch 148 | _NCrunch_* 149 | .*crunch*.local.xml 150 | nCrunchTemp_* 151 | 152 | # MightyMoose 153 | *.mm.* 154 | AutoTest.Net/ 155 | 156 | # Web workbench (sass) 157 | .sass-cache/ 158 | 159 | # Installshield output folder 160 | [Ee]xpress/ 161 | 162 | # DocProject is a documentation generator add-in 163 | DocProject/buildhelp/ 164 | DocProject/Help/*.HxT 165 | DocProject/Help/*.HxC 166 | DocProject/Help/*.hhc 167 | DocProject/Help/*.hhk 168 | DocProject/Help/*.hhp 169 | DocProject/Help/Html2 170 | DocProject/Help/html 171 | 172 | # Click-Once directory 173 | publish/ 174 | 175 | # Publish Web Output 176 | *.[Pp]ublish.xml 177 | *.azurePubxml 178 | # Note: Comment the next line if you want to checkin your web deploy settings, 179 | # but database connection strings (with potential passwords) will be unencrypted 180 | *.pubxml 181 | *.publishproj 182 | 183 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 184 | # checkin your Azure Web App publish settings, but sensitive information contained 185 | # in these scripts will be unencrypted 186 | PublishScripts/ 187 | 188 | # NuGet Packages 189 | *.nupkg 190 | # NuGet Symbol Packages 191 | *.snupkg 192 | # The packages folder can be ignored because of Package Restore 193 | **/[Pp]ackages/* 194 | # except build/, which is used as an MSBuild target. 195 | !**/[Pp]ackages/build/ 196 | # Uncomment if necessary however generally it will be regenerated when needed 197 | #!**/[Pp]ackages/repositories.config 198 | # NuGet v3's project.json files produces more ignorable files 199 | *.nuget.props 200 | *.nuget.targets 201 | 202 | # Microsoft Azure Build Output 203 | csx/ 204 | *.build.csdef 205 | 206 | # Microsoft Azure Emulator 207 | ecf/ 208 | rcf/ 209 | 210 | # Windows Store app package directories and files 211 | AppPackages/ 212 | BundleArtifacts/ 213 | Package.StoreAssociation.xml 214 | _pkginfo.txt 215 | *.appx 216 | *.appxbundle 217 | *.appxupload 218 | 219 | # Visual Studio cache files 220 | # files ending in .cache can be ignored 221 | *.[Cc]ache 222 | # but keep track of directories ending in .cache 223 | !?*.[Cc]ache/ 224 | 225 | # Others 226 | ClientBin/ 227 | ~$* 228 | *~ 229 | *.dbmdl 230 | *.dbproj.schemaview 231 | *.jfm 232 | *.pfx 233 | *.publishsettings 234 | orleans.codegen.cs 235 | 236 | # Including strong name files can present a security risk 237 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 238 | #*.snk 239 | 240 | # Since there are multiple workflows, uncomment next line to ignore bower_components 241 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 242 | #bower_components/ 243 | 244 | # RIA/Silverlight projects 245 | Generated_Code/ 246 | 247 | # Backup & report files from converting an old project file 248 | # to a newer Visual Studio version. Backup files are not needed, 249 | # because we have git ;-) 250 | _UpgradeReport_Files/ 251 | Backup*/ 252 | UpgradeLog*.XML 253 | UpgradeLog*.htm 254 | ServiceFabricBackup/ 255 | *.rptproj.bak 256 | 257 | # SQL Server files 258 | *.mdf 259 | *.ldf 260 | *.ndf 261 | 262 | # Business Intelligence projects 263 | *.rdl.data 264 | *.bim.layout 265 | *.bim_*.settings 266 | *.rptproj.rsuser 267 | *- [Bb]ackup.rdl 268 | *- [Bb]ackup ([0-9]).rdl 269 | *- [Bb]ackup ([0-9][0-9]).rdl 270 | 271 | # Microsoft Fakes 272 | FakesAssemblies/ 273 | 274 | # GhostDoc plugin setting file 275 | *.GhostDoc.xml 276 | 277 | # Node.js Tools for Visual Studio 278 | .ntvs_analysis.dat 279 | node_modules/ 280 | 281 | # Visual Studio 6 build log 282 | *.plg 283 | 284 | # Visual Studio 6 workspace options file 285 | *.opt 286 | 287 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 288 | *.vbw 289 | 290 | # Visual Studio LightSwitch build output 291 | **/*.HTMLClient/GeneratedArtifacts 292 | **/*.DesktopClient/GeneratedArtifacts 293 | **/*.DesktopClient/ModelManifest.xml 294 | **/*.Server/GeneratedArtifacts 295 | **/*.Server/ModelManifest.xml 296 | _Pvt_Extensions 297 | 298 | # Paket dependency manager 299 | .paket/paket.exe 300 | paket-files/ 301 | 302 | # FAKE - F# Make 303 | .fake/ 304 | 305 | # CodeRush personal settings 306 | .cr/personal 307 | 308 | # Python Tools for Visual Studio (PTVS) 309 | __pycache__/ 310 | *.pyc 311 | 312 | # Cake - Uncomment if you are using it 313 | # tools/** 314 | # !tools/packages.config 315 | 316 | # Tabs Studio 317 | *.tss 318 | 319 | # Telerik's JustMock configuration file 320 | *.jmconfig 321 | 322 | # BizTalk build output 323 | *.btp.cs 324 | *.btm.cs 325 | *.odx.cs 326 | *.xsd.cs 327 | 328 | # OpenCover UI analysis results 329 | OpenCover/ 330 | 331 | # Azure Stream Analytics local run output 332 | ASALocalRun/ 333 | 334 | # MSBuild Binary and Structured Log 335 | *.binlog 336 | 337 | # NVidia Nsight GPU debugger configuration file 338 | *.nvuser 339 | 340 | # MFractors (Xamarin productivity tool) working folder 341 | .mfractor/ 342 | 343 | # Local History for Visual Studio 344 | .localhistory/ 345 | 346 | # BeatPulse healthcheck temp database 347 | healthchecksdb 348 | 349 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 350 | MigrationBackup/ 351 | 352 | # Ionide (cross platform F# VS Code tools) working folder 353 | .ionide/ 354 | 355 | 356 | # Xcode 357 | xcshareddata/ 358 | xcuserdata/ 359 | *.dSYM 360 | *.xcworkspacedata 361 | 362 | 363 | # macOS 364 | # https://github.com/github/gitignore/blob/master/Global/macOS.gitignore 365 | .DS_Store 366 | .AppleDouble 367 | .LSOverride 368 | 369 | 370 | # CMake 371 | # https://github.com/github/gitignore/blob/master/CMake.gitignore 372 | CMakeLists.txt.user 373 | CMakeCache.txt 374 | CMakeFiles 375 | CMakeScripts 376 | Testing 377 | Makefile 378 | cmake_install.cmake 379 | install_manifest.txt 380 | compile_commands.json 381 | CTestTestfile.cmake 382 | _deps 383 | 384 | 385 | # Ninja 386 | # https://github.com/github/gitignore/blob/master/Global/Ninja.gitignore 387 | .ninja_deps 388 | .ninja_log 389 | build.ninja 390 | rules.ninja 391 | 392 | 393 | # 394 | gmon.out 395 | .vscode/ 396 | *.PVS-Studio.stacktrace.txt 397 | 398 | 399 | # Siv3D 400 | # example Wavefront .obj files 401 | !**/example/obj/ 402 | !**/example/obj/*.obj 403 | 404 | # Ignore compiled binaries 405 | **/App/*.app 406 | **/App/*.exe 407 | 408 | # Ignore any saved local files 409 | **/App/AS_DEBUG/ 410 | **/App/Screenshot/ 411 | 412 | # Ignore resource files 413 | #**/App/example 414 | #**/App/engine 415 | #**/App/dll 416 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.9.34902.65 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CoTaskLibTests", "CoTaskLibTests\CoTaskLibTests.vcxproj", "{8ED53144-D800-407A-A812-156DB6E01C07}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {8ED53144-D800-407A-A812-156DB6E01C07}.Debug|x64.ActiveCfg = Debug|x64 15 | {8ED53144-D800-407A-A812-156DB6E01C07}.Debug|x64.Build.0 = Debug|x64 16 | {8ED53144-D800-407A-A812-156DB6E01C07}.Release|x64.ActiveCfg = Release|x64 17 | {8ED53144-D800-407A-A812-156DB6E01C07}.Release|x64.Build.0 = Release|x64 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {1199D29D-4940-420B-A9B5-07EEDECAA756} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*.{c++,cc,cpp,cppm,cxx,h,h++,hh,hpp,hxx,inl,ipp,ixx,tlh,tli}] 4 | charset = utf-8-bom 5 | insert_final_newline = true 6 | indent_size = 4 7 | indent_style = tab 8 | trim_trailing_whitespace = true 9 | 10 | cpp_generate_documentation_comments = doxygen_triple_slash 11 | cpp_indent_braces = false 12 | cpp_indent_multi_line_relative_to = innermost_parenthesis 13 | cpp_indent_within_parentheses = indent 14 | cpp_indent_preserve_within_parentheses = true 15 | cpp_indent_case_contents = true 16 | cpp_indent_case_labels = false 17 | cpp_indent_case_contents_when_block = false 18 | cpp_indent_lambda_braces_when_parameter = true 19 | cpp_indent_goto_labels = one_left 20 | cpp_indent_preprocessor = leftmost_column 21 | cpp_indent_access_specifiers = false 22 | cpp_indent_namespace_contents = true 23 | cpp_indent_preserve_comments = false 24 | cpp_new_line_before_open_brace_namespace = ignore 25 | cpp_new_line_before_open_brace_type = ignore 26 | cpp_new_line_before_open_brace_function = ignore 27 | cpp_new_line_before_open_brace_block = ignore 28 | cpp_new_line_before_open_brace_lambda = ignore 29 | cpp_new_line_scope_braces_on_separate_lines = false 30 | cpp_new_line_close_brace_same_line_empty_type = false 31 | cpp_new_line_close_brace_same_line_empty_function = false 32 | cpp_new_line_before_catch = true 33 | cpp_new_line_before_else = true 34 | cpp_new_line_before_while_in_do_while = false 35 | cpp_space_before_function_open_parenthesis = remove 36 | cpp_space_within_parameter_list_parentheses = false 37 | cpp_space_between_empty_parameter_list_parentheses = false 38 | cpp_space_after_keywords_in_control_flow_statements = true 39 | cpp_space_within_control_flow_statement_parentheses = false 40 | cpp_space_before_lambda_open_parenthesis = false 41 | cpp_space_within_cast_parentheses = false 42 | cpp_space_after_cast_close_parenthesis = false 43 | cpp_space_within_expression_parentheses = false 44 | cpp_space_before_block_open_brace = true 45 | cpp_space_between_empty_braces = false 46 | cpp_space_before_initializer_list_open_brace = false 47 | cpp_space_within_initializer_list_braces = true 48 | cpp_space_preserve_in_initializer_list = true 49 | cpp_space_before_open_square_bracket = false 50 | cpp_space_within_square_brackets = false 51 | cpp_space_before_empty_square_brackets = false 52 | cpp_space_between_empty_square_brackets = false 53 | cpp_space_group_square_brackets = true 54 | cpp_space_within_lambda_brackets = false 55 | cpp_space_between_empty_lambda_brackets = false 56 | cpp_space_before_comma = false 57 | cpp_space_after_comma = true 58 | cpp_space_remove_around_member_operators = true 59 | cpp_space_before_inheritance_colon = true 60 | cpp_space_before_constructor_colon = true 61 | cpp_space_remove_before_semicolon = true 62 | cpp_space_after_semicolon = true 63 | cpp_space_remove_around_unary_operator = true 64 | cpp_space_around_binary_operator = insert 65 | cpp_space_around_assignment_operator = insert 66 | cpp_space_pointer_reference_alignment = left 67 | cpp_space_around_ternary_operator = insert 68 | cpp_wrap_preserve_blocks = one_liners 69 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/Resource.rc: -------------------------------------------------------------------------------- 1 | # include 2 | 3 | ////////////////////////////////////////////////////// 4 | // 5 | // Siv3D Engine Resources (DO NOT REMOVE) 6 | // 7 | ////////////////////////////////////////////////////// 8 | DefineResource(100, ICON, icon.ico) 9 | 10 | // 11 | // Shaders 12 | // 13 | Resource(engine/shader/d3d11/sprite.vs) 14 | Resource(engine/shader/d3d11/shape.ps) 15 | Resource(engine/shader/d3d11/square_dot.ps) 16 | Resource(engine/shader/d3d11/round_dot.ps) 17 | Resource(engine/shader/d3d11/texture.ps) 18 | Resource(engine/shader/d3d11/bitmapfont.ps) 19 | Resource(engine/shader/d3d11/sdffont.ps) 20 | Resource(engine/shader/d3d11/sdffont_outline.ps) 21 | Resource(engine/shader/d3d11/sdffont_shadow.ps) 22 | Resource(engine/shader/d3d11/sdffont_outlineshadow.ps) 23 | Resource(engine/shader/d3d11/msdffont.ps) 24 | Resource(engine/shader/d3d11/msdffont_outline.ps) 25 | Resource(engine/shader/d3d11/msdffont_shadow.ps) 26 | Resource(engine/shader/d3d11/msdffont_outlineshadow.ps) 27 | Resource(engine/shader/d3d11/msdfprint.ps) 28 | Resource(engine/shader/d3d11/fullscreen_triangle.vs) 29 | Resource(engine/shader/d3d11/fullscreen_triangle.ps) 30 | Resource(engine/shader/d3d11/forward3d.vs) 31 | Resource(engine/shader/d3d11/line3d.vs) 32 | Resource(engine/shader/d3d11/forward3d.ps) 33 | Resource(engine/shader/d3d11/line3d.ps) 34 | Resource(engine/shader/d3d11/copy.ps) 35 | Resource(engine/shader/d3d11/gaussian_blur_5.ps) 36 | Resource(engine/shader/d3d11/gaussian_blur_9.ps) 37 | Resource(engine/shader/d3d11/gaussian_blur_13.ps) 38 | Resource(engine/shader/d3d11/apply_srgb_curve.ps) 39 | Resource(engine/shader/d3d11/quad_warp.vs) 40 | Resource(engine/shader/d3d11/quad_warp.ps) 41 | Resource(engine/shader/d3d11/sky.ps) 42 | Resource(engine/shader/glsl/sprite.vert) 43 | Resource(engine/shader/glsl/shape.frag) 44 | Resource(engine/shader/glsl/square_dot.frag) 45 | Resource(engine/shader/glsl/round_dot.frag) 46 | Resource(engine/shader/glsl/texture.frag) 47 | Resource(engine/shader/glsl/bitmapfont.frag) 48 | Resource(engine/shader/glsl/sdffont.frag) 49 | Resource(engine/shader/glsl/sdffont_outline.frag) 50 | Resource(engine/shader/glsl/sdffont_shadow.frag) 51 | Resource(engine/shader/glsl/sdffont_outlineshadow.frag) 52 | Resource(engine/shader/glsl/msdffont.frag) 53 | Resource(engine/shader/glsl/msdffont_outline.frag) 54 | Resource(engine/shader/glsl/msdffont_shadow.frag) 55 | Resource(engine/shader/glsl/msdffont_outlineshadow.frag) 56 | Resource(engine/shader/glsl/msdfprint.frag) 57 | Resource(engine/shader/glsl/fullscreen_triangle.vert) 58 | Resource(engine/shader/glsl/fullscreen_triangle.frag) 59 | Resource(engine/shader/glsl/forward3d.vert) 60 | Resource(engine/shader/glsl/line3d.vert) 61 | Resource(engine/shader/glsl/forward3d.frag) 62 | Resource(engine/shader/glsl/line3d.frag) 63 | Resource(engine/shader/glsl/copy.frag) 64 | Resource(engine/shader/glsl/gaussian_blur_5.frag) 65 | Resource(engine/shader/glsl/gaussian_blur_9.frag) 66 | Resource(engine/shader/glsl/gaussian_blur_13.frag) 67 | Resource(engine/shader/glsl/apply_srgb_curve.frag) 68 | Resource(engine/shader/glsl/quad_warp.vert) 69 | Resource(engine/shader/glsl/quad_warp.frag) 70 | Resource(engine/shader/glsl/sky.frag) 71 | 72 | // 73 | // Fonts 74 | // 75 | Resource(engine/font/min/siv3d-min.woff) 76 | 77 | // 78 | // Box-shadow Textures 79 | // 80 | Resource(engine/texture/box-shadow/256.png) 81 | Resource(engine/texture/box-shadow/128.png) 82 | Resource(engine/texture/box-shadow/64.png) 83 | Resource(engine/texture/box-shadow/32.png) 84 | Resource(engine/texture/box-shadow/16.png) 85 | Resource(engine/texture/box-shadow/8.png) 86 | 87 | ////////////////////////////////////////////////////// 88 | // 89 | // Siv3D Engine Optional Resources (Can be removed if not required) 90 | // 91 | ////////////////////////////////////////////////////// 92 | 93 | /* 94 | // 95 | // Fonts 96 | // 97 | Resource(engine/font/mplus/mplus-1p-thin.ttf.zstdcmp) 98 | Resource(engine/font/mplus/mplus-1p-light.ttf.zstdcmp) 99 | Resource(engine/font/mplus/mplus-1p-regular.ttf.zstdcmp) 100 | Resource(engine/font/mplus/mplus-1p-medium.ttf.zstdcmp) 101 | Resource(engine/font/mplus/mplus-1p-bold.ttf.zstdcmp) 102 | Resource(engine/font/mplus/mplus-1p-heavy.ttf.zstdcmp) 103 | Resource(engine/font/mplus/mplus-1p-black.ttf.zstdcmp) 104 | Resource(engine/font/noto-cjk/NotoSansCJK-Regular.ttc.zstdcmp) 105 | //Resource(engine/font/noto-cjk/NotoSansJP-Regular.otf.zstdcmp) 106 | 107 | // 108 | // Emoji Fonts 109 | // 110 | Resource(engine/font/noto-emoji/NotoColorEmoji.ttf.zstdcmp) 111 | Resource(engine/font/noto-emoji/NotoEmoji-Regular.ttf.zstdcmp) 112 | 113 | // 114 | // Icons 115 | // 116 | Resource(engine/font/fontawesome/fontawesome-brands.otf.zstdcmp) 117 | Resource(engine/font/fontawesome/fontawesome-solid.otf.zstdcmp) 118 | Resource(engine/font/materialdesignicons/materialdesignicons-webfont.ttf.zstdcmp) 119 | 120 | // 121 | // Sound Font 122 | // 123 | Resource(engine/soundfont/GMGSx.sf2.zstdcmp) 124 | */ 125 | 126 | ////////////////////////////////////////////////////// 127 | // 128 | // Siv3D App Resources (Your application resources here) 129 | // 130 | ////////////////////////////////////////////////////// 131 | 132 | 133 | 134 | /* examples 135 | 136 | // 137 | // Define your resource path inside `Resource()` macro. 138 | // No double quotation marks and white spaces may appear. 139 | // 140 | Resource(example/siv3d-kun.png) // ok 141 | Resource(example/windmill.png) // ok 142 | Resource(assets/a b c.txt) // error: contains white spaces 143 | Resource("example/windmill.png") // error: contains double quotation marks 144 | 145 | // 146 | // If your file contains a white space, define the identifier without using Resource() macro. 147 | // 148 | MYIDENTIFIER_1 FILE "assets/a b c.txt" 149 | MYIDENTIFIER_2 FILE "level 1/map.dat" 150 | */ 151 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/font/min/LICENSE: -------------------------------------------------------------------------------- 1 | This Font Software is licensed under the SIL Open Font License, 2 | Version 1.1. 3 | 4 | This license is copied below, and is also available with a FAQ at: 5 | http://scripts.sil.org/OFL 6 | 7 | ----------------------------------------------------------- 8 | SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 9 | ----------------------------------------------------------- 10 | 11 | PREAMBLE 12 | The goals of the Open Font License (OFL) are to stimulate worldwide 13 | development of collaborative font projects, to support the font 14 | creation efforts of academic and linguistic communities, and to 15 | provide a free and open framework in which fonts may be shared and 16 | improved in partnership with others. 17 | 18 | The OFL allows the licensed fonts to be used, studied, modified and 19 | redistributed freely as long as they are not sold by themselves. The 20 | fonts, including any derivative works, can be bundled, embedded, 21 | redistributed and/or sold with any software provided that any reserved 22 | names are not used by derivative works. The fonts and derivatives, 23 | however, cannot be released under any other type of license. The 24 | requirement for fonts to remain under this license does not apply to 25 | any document created using the fonts or their derivatives. 26 | 27 | DEFINITIONS 28 | "Font Software" refers to the set of files released by the Copyright 29 | Holder(s) under this license and clearly marked as such. This may 30 | include source files, build scripts and documentation. 31 | 32 | "Reserved Font Name" refers to any names specified as such after the 33 | copyright statement(s). 34 | 35 | "Original Version" refers to the collection of Font Software 36 | components as distributed by the Copyright Holder(s). 37 | 38 | "Modified Version" refers to any derivative made by adding to, 39 | deleting, or substituting -- in part or in whole -- any of the 40 | components of the Original Version, by changing formats or by porting 41 | the Font Software to a new environment. 42 | 43 | "Author" refers to any designer, engineer, programmer, technical 44 | writer or other person who contributed to the Font Software. 45 | 46 | PERMISSION & CONDITIONS 47 | Permission is hereby granted, free of charge, to any person obtaining 48 | a copy of the Font Software, to use, study, copy, merge, embed, 49 | modify, redistribute, and sell modified and unmodified copies of the 50 | Font Software, subject to the following conditions: 51 | 52 | 1) Neither the Font Software nor any of its individual components, in 53 | Original or Modified Versions, may be sold by itself. 54 | 55 | 2) Original or Modified Versions of the Font Software may be bundled, 56 | redistributed and/or sold with any software, provided that each copy 57 | contains the above copyright notice and this license. These can be 58 | included either as stand-alone text files, human-readable headers or 59 | in the appropriate machine-readable metadata fields within text or 60 | binary files as long as those fields can be easily viewed by the user. 61 | 62 | 3) No Modified Version of the Font Software may use the Reserved Font 63 | Name(s) unless explicit written permission is granted by the 64 | corresponding Copyright Holder. This restriction only applies to the 65 | primary font name as presented to the users. 66 | 67 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 68 | Software shall not be used to promote, endorse or advertise any 69 | Modified Version, except to acknowledge the contribution(s) of the 70 | Copyright Holder(s) and the Author(s) or with their explicit written 71 | permission. 72 | 73 | 5) The Font Software, modified or unmodified, in part or in whole, 74 | must be distributed entirely under this license, and must not be 75 | distributed under any other license. The requirement for fonts to 76 | remain under this license does not apply to any document created using 77 | the Font Software. 78 | 79 | TERMINATION 80 | This license becomes null and void if any of the above conditions are 81 | not met. 82 | 83 | DISCLAIMER 84 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 85 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 86 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 87 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 88 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 89 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 90 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 91 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 92 | OTHER DEALINGS IN THE FONT SOFTWARE. 93 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/font/min/siv3d-min.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/font/min/siv3d-min.woff -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/apply_srgb_curve.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/apply_srgb_curve.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/bitmapfont.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/bitmapfont.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/copy.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/copy.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/forward3d.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/forward3d.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/forward3d.vs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/forward3d.vs -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/fullscreen_triangle.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/fullscreen_triangle.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/fullscreen_triangle.vs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/fullscreen_triangle.vs -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/gaussian_blur_13.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/gaussian_blur_13.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/gaussian_blur_5.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/gaussian_blur_5.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/gaussian_blur_9.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/gaussian_blur_9.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/line3d.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/line3d.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/line3d.vs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/line3d.vs -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/msdffont.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/msdffont.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/msdffont_outline.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/msdffont_outline.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/msdffont_outlineshadow.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/msdffont_outlineshadow.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/msdffont_shadow.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/msdffont_shadow.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/msdfprint.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/msdfprint.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/quad_warp.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/quad_warp.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/quad_warp.vs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/quad_warp.vs -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/round_dot.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/round_dot.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/sdffont.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/sdffont.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/sdffont_outline.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/sdffont_outline.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/sdffont_outlineshadow.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/sdffont_outlineshadow.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/sdffont_shadow.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/sdffont_shadow.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/shape.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/shape.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/sky.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/sky.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/sprite.vs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/sprite.vs -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/square_dot.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/square_dot.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/d3d11/texture.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/shader/d3d11/texture.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/apply_srgb_curve.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Functions 25 | // 26 | 27 | // 28 | // https://github.com/microsoft/DirectX-Graphics-Samples/blob/master/MiniEngine/Core/Shaders/ColorSpaceUtility.hlsli 29 | // 30 | // Copyright(c) 2015 Microsoft 31 | // 32 | // Permission is hereby granted, free of charge, to any person obtaining a copy 33 | // of this software and associated documentation files(the "Software"), to deal 34 | // in the Software without restriction, including without limitation the rights 35 | // to use, copy, modify, merge, publish, distribute, sublicense, and / or sell 36 | // copies of the Software, and to permit persons to whom the Software is 37 | // furnished to do so, subject to the following conditions : 38 | // 39 | // The above copyright notice and this permission notice shall be included in 40 | // all copies or substantial portions of the Software. 41 | // 42 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 43 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 44 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE 45 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 46 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 47 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 48 | // THE SOFTWARE. 49 | float ApplySRGBCurve_Fast(float x) 50 | { 51 | return x < 0.0031308f ? 12.92f * x : 1.13005f * sqrt(x - 0.00228f) - 0.13448f * x + 0.005719f; 52 | } 53 | 54 | float ApplySRGBCurve(float x) 55 | { 56 | return x < 0.0031308f ? 12.92f * x : 1.055f * pow(x, 1.0f / 2.4f) - 0.055f; 57 | } 58 | 59 | vec3 ApplySRGBCurve0(vec3 color) 60 | { 61 | return pow(color, vec3(1.0f / 2.2f)); 62 | } 63 | 64 | vec3 ApplySRGBCurve1(vec3 color) 65 | { 66 | float r = ApplySRGBCurve_Fast(color.r); 67 | float g = ApplySRGBCurve_Fast(color.g); 68 | float b = ApplySRGBCurve_Fast(color.b); 69 | return vec3(r, g, b); 70 | } 71 | 72 | vec3 ApplySRGBCurve2(vec3 color) 73 | { 74 | float r = ApplySRGBCurve(color.r); 75 | float g = ApplySRGBCurve(color.g); 76 | float b = ApplySRGBCurve(color.b); 77 | return vec3(r, g, b); 78 | } 79 | 80 | void main() 81 | { 82 | vec3 texColor = texture(Texture0, UV).rgb; 83 | 84 | FragColor = vec4(ApplySRGBCurve2(texColor), 1.0f); 85 | } 86 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/bitmapfont.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec4 g_internal; 33 | }; 34 | 35 | // 36 | // Functions 37 | // 38 | void main() 39 | { 40 | float textAlpha = texture(Texture0, UV).a; 41 | 42 | vec4 color = vec4(Color.rgb, Color.a * textAlpha); 43 | 44 | FragColor = (color + g_colorAdd); 45 | } 46 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/copy.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec4 g_internal; 33 | }; 34 | 35 | // 36 | // Functions 37 | // 38 | void main() 39 | { 40 | vec4 texColor = texture(Texture0, UV); 41 | 42 | FragColor = texColor; 43 | } 44 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/forward3d.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2023 Ryo Suzuki. 2 | // Copyright (c) 2016-2023 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec3 WorldPosition; 16 | layout(location = 1) in vec2 UV; 17 | layout(location = 2) in vec3 Normal; 18 | 19 | // 20 | // PSOutput 21 | // 22 | layout(location = 0) out vec4 FragColor; 23 | 24 | // 25 | // Constant Buffer 26 | // 27 | layout(std140) uniform PSPerFrame 28 | { 29 | vec3 g_globalAmbientColor; 30 | vec3 g_sunColor; 31 | vec3 g_sunDirection; 32 | }; 33 | 34 | layout(std140) uniform PSPerView 35 | { 36 | vec3 g_eyePosition; 37 | }; 38 | 39 | layout(std140) uniform PSPerMaterial 40 | { 41 | vec3 g_ambientColor; 42 | uint g_hasTexture; 43 | vec4 g_diffuseColor; 44 | vec3 g_specularColor; 45 | float g_shininess; 46 | vec3 g_emissionColor; 47 | }; 48 | 49 | // 50 | // Functions 51 | // 52 | vec4 GetDiffuseColor(vec2 uv) 53 | { 54 | vec4 diffuseColor = g_diffuseColor; 55 | 56 | if (g_hasTexture == 1) 57 | { 58 | diffuseColor *= texture(Texture0, uv); 59 | } 60 | 61 | return diffuseColor; 62 | } 63 | 64 | vec3 CalculateDiffuseReflection(vec3 n, vec3 l, vec3 lightColor, vec3 diffuseColor, vec3 ambientColor) 65 | { 66 | vec3 directColor = lightColor * max(dot(n, l), 0.0f); 67 | return ((ambientColor + directColor) * diffuseColor); 68 | } 69 | 70 | vec3 CalculateSpecularReflection(vec3 n, vec3 h, float shininess, float nl, vec3 lightColor, vec3 specularColor) 71 | { 72 | float highlight = pow(max(dot(n, h), 0.0f), shininess) * float(0.0f < nl); 73 | return (lightColor * specularColor * highlight); 74 | } 75 | 76 | void main() 77 | { 78 | vec3 lightColor = g_sunColor; 79 | vec3 lightDirection = g_sunDirection; 80 | 81 | vec3 n = normalize(Normal); 82 | vec3 l = lightDirection; 83 | vec4 diffuseColor = GetDiffuseColor(UV); 84 | vec3 ambientColor = (g_ambientColor * g_globalAmbientColor); 85 | 86 | // Diffuse 87 | vec3 diffuseReflection = CalculateDiffuseReflection(n, l, lightColor, diffuseColor.rgb, ambientColor); 88 | 89 | // Specular 90 | vec3 v = normalize(g_eyePosition - WorldPosition); 91 | vec3 h = normalize(v + lightDirection); 92 | vec3 specularReflection = CalculateSpecularReflection(n, h, g_shininess, dot(n, l), lightColor, g_specularColor); 93 | 94 | FragColor = vec4(diffuseReflection + specularReflection + g_emissionColor, diffuseColor.a); 95 | } 96 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/forward3d.vert: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // VSInput 9 | // 10 | layout(location = 0) in vec4 VertexPosition; 11 | layout(location = 1) in vec3 VertexNormal; 12 | layout(location = 2) in vec2 VertexUV; 13 | 14 | // 15 | // VSOutput 16 | // 17 | layout(location = 0) out vec3 WorldPosition; 18 | layout(location = 1) out vec2 UV; 19 | layout(location = 2) out vec3 Normal; 20 | out gl_PerVertex 21 | { 22 | vec4 gl_Position; 23 | }; 24 | 25 | // 26 | // Constant Buffer 27 | // 28 | layout(std140) uniform VSPerView 29 | { 30 | mat4x4 g_worldToProjected; 31 | }; 32 | 33 | layout(std140) uniform VSPerObject 34 | { 35 | mat4x4 g_localToWorld; 36 | }; 37 | 38 | layout(std140) uniform VSPerMaterial 39 | { 40 | vec4 g_uvTransform; 41 | }; 42 | 43 | // 44 | // Functions 45 | // 46 | void main() 47 | { 48 | vec4 worldPosition = VertexPosition * g_localToWorld; 49 | 50 | gl_Position = worldPosition * g_worldToProjected; 51 | WorldPosition = worldPosition.xyz; 52 | UV = (VertexUV * g_uvTransform.xy + g_uvTransform.zw); 53 | Normal = VertexNormal * mat3x3(g_localToWorld); 54 | } 55 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/fullscreen_triangle.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec2 UV; 16 | 17 | // 18 | // PSOutput 19 | // 20 | layout(location = 0) out vec4 FragColor; 21 | 22 | // 23 | // Functions 24 | // 25 | void main() 26 | { 27 | FragColor = texture(Texture0, UV); 28 | } 29 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/fullscreen_triangle.vert: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // VSOutput 9 | // 10 | layout(location = 0) out vec2 UV; 11 | out gl_PerVertex 12 | { 13 | vec4 gl_Position; 14 | }; 15 | 16 | // 17 | // Functions 18 | // 19 | void main() 20 | { 21 | float x = -1.0 + float((gl_VertexID & 1) << 2); 22 | float y = -1.0 + float((gl_VertexID & 2) << 1); 23 | gl_Position = vec4(x, y, 0, 1); 24 | 25 | UV.x = (x + 1.0) * 0.5; 26 | UV.y = (-y + 1.0) * 0.5; 27 | } 28 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/gaussian_blur_13.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2023 Ryo Suzuki. 2 | // Copyright (c) 2016-2023 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec2 g_pixelSize; 33 | vec2 g_direction; 34 | }; 35 | 36 | // 37 | // Functions 38 | // 39 | void main() 40 | { 41 | vec2 offset1 = (1.41176470588235 * g_direction); 42 | vec2 offset2 = (3.29411764705882 * g_direction); 43 | vec2 offset3 = (5.17647058823529 * g_direction); 44 | 45 | vec4 color = (texture(Texture0, UV) * 0.196482550151140); 46 | color += (texture(Texture0, UV + (offset1 * g_pixelSize)) * 0.296906964672834); 47 | color += (texture(Texture0, UV - (offset1 * g_pixelSize)) * 0.296906964672834); 48 | color += (texture(Texture0, UV + (offset2 * g_pixelSize)) * 0.0944703978504473); 49 | color += (texture(Texture0, UV - (offset2 * g_pixelSize)) * 0.0944703978504473); 50 | color += (texture(Texture0, UV + (offset3 * g_pixelSize)) * 0.0103813624011481); 51 | color += (texture(Texture0, UV - (offset3 * g_pixelSize)) * 0.0103813624011481); 52 | 53 | FragColor = color; 54 | } 55 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/gaussian_blur_5.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2023 Ryo Suzuki. 2 | // Copyright (c) 2016-2023 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec2 g_pixelSize; 33 | vec2 g_direction; 34 | }; 35 | 36 | // 37 | // Functions 38 | // 39 | void main() 40 | { 41 | vec2 offset1 = (1.33333333333333 * g_direction); 42 | 43 | vec4 color = (texture(Texture0, UV) * 0.294117647058824); 44 | color += (texture(Texture0, UV + (offset1 * g_pixelSize)) * 0.352941176470588); 45 | color += (texture(Texture0, UV - (offset1 * g_pixelSize)) * 0.352941176470588); 46 | 47 | FragColor = color; 48 | } 49 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/gaussian_blur_9.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2023 Ryo Suzuki. 2 | // Copyright (c) 2016-2023 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec2 g_pixelSize; 33 | vec2 g_direction; 34 | }; 35 | 36 | // 37 | // Functions 38 | // 39 | void main() 40 | { 41 | vec2 offset1 = (1.38461538461538 * g_direction); 42 | vec2 offset2 = (3.23076923076923 * g_direction); 43 | 44 | vec4 color = (texture(Texture0, UV) * 0.227027027027027); 45 | color += (texture(Texture0, UV + (offset1 * g_pixelSize)) * 0.316216216216216); 46 | color += (texture(Texture0, UV - (offset1 * g_pixelSize)) * 0.316216216216216); 47 | color += (texture(Texture0, UV + (offset2 * g_pixelSize)) * 0.070270270270270); 48 | color += (texture(Texture0, UV - (offset2 * g_pixelSize)) * 0.070270270270270); 49 | 50 | FragColor = color; 51 | } 52 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/line3d.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // PSInput 9 | // 10 | layout(location = 0) in vec3 WorldPosition; 11 | layout(location = 1) in vec4 Color; 12 | 13 | // 14 | // PSOutput 15 | // 16 | layout(location = 0) out vec4 FragColor; 17 | 18 | // 19 | // Functions 20 | // 21 | void main() 22 | { 23 | FragColor = Color; 24 | } 25 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/line3d.vert: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // VSInput 9 | // 10 | layout(location = 0) in vec4 VertexPosition; 11 | layout(location = 1) in vec4 VertexColor; 12 | 13 | // 14 | // VSOutput 15 | // 16 | layout(location = 0) out vec3 WorldPosition; 17 | layout(location = 1) out vec4 Color; 18 | out gl_PerVertex 19 | { 20 | vec4 gl_Position; 21 | }; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform VSPerView 27 | { 28 | mat4x4 g_worldToProjected; 29 | }; 30 | 31 | layout(std140) uniform VSPerObject 32 | { 33 | mat4x4 g_localToWorld; 34 | }; 35 | 36 | // 37 | // Functions 38 | // 39 | void main() 40 | { 41 | vec4 worldPosition = VertexPosition * g_localToWorld; 42 | 43 | gl_Position = worldPosition * g_worldToProjected; 44 | WorldPosition = worldPosition.xyz; 45 | Color = VertexColor; 46 | } 47 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/msdffont.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec4 g_internal; 33 | }; 34 | 35 | // 36 | // Functions 37 | // 38 | float median(float r, float g, float b) 39 | { 40 | return max(min(r, g), min(max(r, g), b)); 41 | } 42 | 43 | void main() 44 | { 45 | vec2 size = textureSize(Texture0, 0); 46 | const float pxRange = 4.0; 47 | vec2 msdfUnit = (pxRange / size); 48 | 49 | vec3 s = texture(Texture0, UV).rgb; 50 | float d = median(s.r, s.g, s.b); 51 | 52 | float td = (d - 0.5); 53 | float textAlpha = clamp(td * dot(msdfUnit, 0.5 / fwidth(UV)) + 0.5, 0.0, 1.0); 54 | 55 | vec4 color = vec4(Color.rgb, Color.a * textAlpha); 56 | 57 | FragColor = (color + g_colorAdd); 58 | } 59 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/msdffont_outline.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec4 g_internal; 33 | }; 34 | 35 | // 36 | // Functions 37 | // 38 | float median(float r, float g, float b) 39 | { 40 | return max(min(r, g), min(max(r, g), b)); 41 | } 42 | 43 | void main() 44 | { 45 | vec2 size = textureSize(Texture0, 0); 46 | const float pxRange = 4.0; 47 | vec2 msdfUnit = (pxRange / size); 48 | 49 | vec3 s = texture(Texture0, UV).rgb; 50 | float d = median(s.r, s.g, s.b); 51 | 52 | float od = (d - g_sdfParam.y); 53 | float outlineAlpha = clamp(od * dot(msdfUnit, 0.5 / fwidth(UV)) + 0.5, 0.0, 1.0); 54 | 55 | float td = (d - g_sdfParam.x); 56 | float textAlpha = clamp(td * dot(msdfUnit, 0.5 / fwidth(UV)) + 0.5, 0.0, 1.0); 57 | 58 | float baseAlpha = (outlineAlpha - textAlpha); 59 | 60 | vec4 color; 61 | color.rgb = mix(g_sdfOutlineColor.rgb, Color.rgb, textAlpha); 62 | color.a = baseAlpha * g_sdfOutlineColor.a + textAlpha * Color.a; 63 | 64 | FragColor = (color + g_colorAdd); 65 | } 66 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/msdffont_outlineshadow.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec4 g_internal; 33 | }; 34 | 35 | // 36 | // Functions 37 | // 38 | float median(float r, float g, float b) 39 | { 40 | return max(min(r, g), min(max(r, g), b)); 41 | } 42 | 43 | void main() 44 | { 45 | vec2 size = textureSize(Texture0, 0); 46 | const float pxRange = 4.0; 47 | vec2 msdfUnit = (pxRange / size); 48 | 49 | vec3 s = texture(Texture0, UV).rgb; 50 | float d = median(s.r, s.g, s.b); 51 | 52 | float od = (d - g_sdfParam.y); 53 | float outlineAlpha = clamp(od * dot(msdfUnit, 0.5 / fwidth(UV)) + 0.5, 0.0, 1.0); 54 | 55 | float td = (d - g_sdfParam.x); 56 | float textAlpha = clamp(td * dot(msdfUnit, 0.5 / fwidth(UV)) + 0.5, 0.0, 1.0); 57 | 58 | float baseAlpha = (outlineAlpha - textAlpha); 59 | 60 | vec4 textColor; 61 | textColor.rgb = mix(g_sdfOutlineColor.rgb, Color.rgb, textAlpha); 62 | textColor.a = baseAlpha * g_sdfOutlineColor.a + textAlpha * Color.a; 63 | 64 | 65 | vec2 shadowOffset = (g_sdfParam.zw / size); 66 | vec3 s2 = texture(Texture0, UV - shadowOffset).rgb; 67 | float d2 = median(s2.r, s2.g, s2.b); 68 | 69 | float sd = (d2 - 0.5); 70 | float shadowAlpha = clamp(sd * dot(msdfUnit, 0.5 / fwidth(UV)) + 0.5, 0.0, 1.0); 71 | float sBase = shadowAlpha * (1.0 - textColor.a); 72 | 73 | vec4 color; 74 | if (textColor.a == 0.0) 75 | { 76 | color.rgb = g_sdfShadowColor.rgb; 77 | } 78 | else 79 | { 80 | color.rgb = mix(textColor.rgb, g_sdfShadowColor.rgb, sBase); 81 | } 82 | color.a = (sBase * g_sdfShadowColor.a) + textColor.a; 83 | 84 | FragColor = (color + g_colorAdd); 85 | } 86 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/msdffont_shadow.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec4 g_internal; 33 | }; 34 | 35 | // 36 | // Functions 37 | // 38 | float median(float r, float g, float b) 39 | { 40 | return max(min(r, g), min(max(r, g), b)); 41 | } 42 | 43 | void main() 44 | { 45 | vec2 size = textureSize(Texture0, 0); 46 | const float pxRange = 4.0; 47 | vec2 msdfUnit = (pxRange / size); 48 | 49 | vec3 s = texture(Texture0, UV).rgb; 50 | float d = median(s.r, s.g, s.b); 51 | 52 | float td = (d - 0.5); 53 | float textAlpha = clamp(td * dot(msdfUnit, 0.5 / fwidth(UV)) + 0.5, 0.0, 1.0); 54 | 55 | vec2 shadowOffset = (g_sdfParam.zw / size); 56 | vec3 s2 = texture(Texture0, UV - shadowOffset).rgb; 57 | float d2 = median(s2.r, s2.g, s2.b); 58 | 59 | float sd = (d2 - 0.5); 60 | float shadowAlpha = clamp(sd * dot(msdfUnit, 0.5 / fwidth(UV)) + 0.5, 0.0, 1.0); 61 | float sBase = shadowAlpha * (1.0 - textAlpha); 62 | 63 | vec4 color; 64 | if (textAlpha == 0.0) 65 | { 66 | color.rgb = g_sdfShadowColor.rgb; 67 | } 68 | else 69 | { 70 | color.rgb = mix(Color.rgb, g_sdfShadowColor.rgb, sBase); 71 | } 72 | color.a = (sBase * g_sdfShadowColor.a) + (textAlpha * Color.a); 73 | 74 | FragColor = (color + g_colorAdd); 75 | } 76 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/msdfprint.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec4 g_internal; 33 | }; 34 | 35 | // 36 | // Functions 37 | // 38 | float median(float r, float g, float b) 39 | { 40 | return max(min(r, g), min(max(r, g), b)); 41 | } 42 | 43 | void main() 44 | { 45 | vec2 size = textureSize(Texture0, 0); 46 | const float pxRange = 4.0; 47 | vec2 msdfUnit = (pxRange / size); 48 | 49 | vec3 s = texture(Texture0, UV).rgb; 50 | float d = median(s.r, s.g, s.b); 51 | 52 | float td = (d - 0.5); 53 | float textAlpha = sqrt(clamp(td * dot(msdfUnit, 0.5 / fwidth(UV)) + 0.5, 0.0, 1.0)); 54 | 55 | vec2 shadowOffset = vec2(0.875, 0.875) / size; 56 | vec3 s2 = texture(Texture0, UV - shadowOffset).rgb; 57 | float d2 = median(s2.r, s2.g, s2.b); 58 | float sd = (d2 - 0.5); 59 | float shadowAlpha = sqrt(clamp(sd * dot(msdfUnit, 0.5 / fwidth(UV)) + 0.5, 0.0, 1.0)); 60 | 61 | FragColor = vec4(textAlpha, textAlpha, textAlpha, max(textAlpha, shadowAlpha)); 62 | } 63 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/quad_warp.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2023 Ryo Suzuki. 2 | // Copyright (c) 2016-2023 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec4 g_internal; 33 | }; 34 | 35 | layout(std140) uniform PSQuadWarp 36 | { 37 | mat3x3 g_invHomography; 38 | vec4 g_uvTransform; 39 | }; 40 | 41 | vec2 Transform(vec2 pos, mat3x3 mat) 42 | { 43 | float s = (mat[0][2] * pos.x + mat[1][2] * pos.y + mat[2][2]); 44 | float x = (mat[0][0] * pos.x + mat[1][0] * pos.y + mat[2][0]) / s; 45 | float y = (mat[0][1] * pos.x + mat[1][1] * pos.y + mat[2][1]) / s; 46 | return vec2(x, y); 47 | } 48 | 49 | // 50 | // Functions 51 | // 52 | void main() 53 | { 54 | vec2 uv = (Transform(UV, g_invHomography) * g_uvTransform.xy + g_uvTransform.zw); 55 | 56 | vec4 texColor = texture(Texture0, uv); 57 | 58 | FragColor = ((texColor * Color) + g_colorAdd); 59 | } 60 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/quad_warp.vert: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2023 Ryo Suzuki. 2 | // Copyright (c) 2016-2023 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // VSInput 9 | // 10 | layout(location = 0) in vec2 VertexPosition; 11 | layout(location = 1) in vec2 VertexUV; 12 | layout(location = 2) in vec4 VertexColor; 13 | 14 | // 15 | // VSOutput 16 | // 17 | layout(location = 0) out vec4 Color; 18 | layout(location = 1) out vec2 UV; 19 | out gl_PerVertex 20 | { 21 | vec4 gl_Position; 22 | }; 23 | 24 | // 25 | // Siv3D Functions 26 | // 27 | vec4 s3d_Transform2D(const vec2 pos, const vec4 t[2]) 28 | { 29 | return vec4(t[0].zw + (pos.x * t[0].xy) + (pos.y * t[1].xy), t[1].zw); 30 | } 31 | 32 | // 33 | // Constant Buffer 34 | // 35 | layout(std140) uniform VSConstants2D 36 | { 37 | vec4 g_transform[2]; 38 | vec4 g_colorMul; 39 | }; 40 | 41 | layout(std140) uniform VSQuadWarp 42 | { 43 | mat3x3 g_homography; 44 | }; 45 | 46 | vec2 Transform(vec2 pos, mat3x3 mat) 47 | { 48 | float s = (mat[0][2] * pos.x + mat[1][2] * pos.y + mat[2][2]); 49 | float x = (mat[0][0] * pos.x + mat[1][0] * pos.y + mat[2][0]) / s; 50 | float y = (mat[0][1] * pos.x + mat[1][1] * pos.y + mat[2][1]) / s; 51 | return vec2(x, y); 52 | } 53 | 54 | // 55 | // Functions 56 | // 57 | void main() 58 | { 59 | vec2 position = Transform(VertexPosition, g_homography); 60 | 61 | gl_Position = s3d_Transform2D(position, g_transform); 62 | 63 | Color = (VertexColor * g_colorMul); 64 | 65 | UV = position; 66 | } 67 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/round_dot.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // PSInput 9 | // 10 | layout(location = 0) in vec4 Color; 11 | layout(location = 1) in vec2 UV; 12 | 13 | // 14 | // PSOutput 15 | // 16 | layout(location = 0) out vec4 FragColor; 17 | 18 | // 19 | // Constant Buffer 20 | // 21 | layout(std140) uniform PSConstants2D 22 | { 23 | vec4 g_colorAdd; 24 | vec4 g_sdfParam; 25 | vec4 g_sdfOutlineColor; 26 | vec4 g_sdfShadowColor; 27 | vec4 g_internal; 28 | }; 29 | 30 | // 31 | // Functions 32 | // 33 | void main() 34 | { 35 | float t = mod(UV.x, 2.0); 36 | vec2 tex = UV; 37 | tex.x = abs(1 - t) * 2.0; 38 | vec4 color = Color; 39 | 40 | float dist = dot(tex, tex) * 0.5; 41 | float delta = fwidth(dist); 42 | float alpha = smoothstep(0.5 - delta, 0.5, dist); 43 | color.a *= 1.0 - alpha; 44 | 45 | FragColor = (color + g_colorAdd); 46 | } 47 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/sdffont.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec4 g_internal; 33 | }; 34 | 35 | // 36 | // Functions 37 | // 38 | void main() 39 | { 40 | float d = texture(Texture0, UV).a; 41 | 42 | float td = (d - 0.5); 43 | float textAlpha = clamp(td / fwidth(td) + 0.5, 0.0, 1.0); 44 | 45 | vec4 color = vec4(Color.rgb, Color.a * textAlpha); 46 | 47 | FragColor = (color + g_colorAdd); 48 | } 49 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/sdffont_outline.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec4 g_internal; 33 | }; 34 | 35 | // 36 | // Functions 37 | // 38 | void main() 39 | { 40 | float d = texture(Texture0, UV).a; 41 | 42 | float od = (d - g_sdfParam.y); 43 | float outlineAlpha = clamp(od / fwidth(od) + 0.5, 0.0, 1.0); 44 | 45 | float td = (d - g_sdfParam.x); 46 | float textAlpha = clamp(td / fwidth(td) + 0.5, 0.0, 1.0); 47 | 48 | float baseAlpha = (outlineAlpha - textAlpha); 49 | 50 | vec4 color; 51 | color.rgb = mix(g_sdfOutlineColor.rgb, Color.rgb, textAlpha); 52 | color.a = baseAlpha * g_sdfOutlineColor.a + textAlpha * Color.a; 53 | 54 | FragColor = (color + g_colorAdd); 55 | } 56 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/sdffont_outlineshadow.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec4 g_internal; 33 | }; 34 | 35 | // 36 | // Functions 37 | // 38 | void main() 39 | { 40 | float d = texture(Texture0, UV).a; 41 | 42 | float od = (d - g_sdfParam.y); 43 | float outlineAlpha = clamp(od / fwidth(od) + 0.5, 0.0, 1.0); 44 | 45 | float td = (d - g_sdfParam.x); 46 | float textAlpha = clamp(td / fwidth(td) + 0.5, 0.0, 1.0); 47 | 48 | float baseAlpha = (outlineAlpha - textAlpha); 49 | 50 | vec4 textColor; 51 | textColor.rgb = mix(g_sdfOutlineColor.rgb, Color.rgb, textAlpha); 52 | textColor.a = baseAlpha * g_sdfOutlineColor.a + textAlpha * Color.a; 53 | 54 | 55 | vec2 size = textureSize(Texture0, 0); 56 | vec2 shadowOffset = (g_sdfParam.zw / size); 57 | float d2 = texture(Texture0, UV - shadowOffset).a; 58 | 59 | float sd = (d2 - g_sdfParam.y); 60 | float shadowAlpha = clamp(sd / fwidth(sd) + 0.5, 0.0, 1.0); 61 | float sBase = shadowAlpha * (1.0 - textColor.a); 62 | 63 | vec4 color; 64 | if (textColor.a == 0.0) 65 | { 66 | color.rgb = g_sdfShadowColor.rgb; 67 | } 68 | else 69 | { 70 | color.rgb = mix(textColor.rgb, g_sdfShadowColor.rgb, sBase); 71 | } 72 | color.a = (sBase * g_sdfShadowColor.a) + textColor.a; 73 | 74 | FragColor = (color + g_colorAdd); 75 | } 76 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/sdffont_shadow.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec4 g_internal; 33 | }; 34 | 35 | // 36 | // Functions 37 | // 38 | void main() 39 | { 40 | float d = texture(Texture0, UV).a; 41 | 42 | float td = (d - 0.5); 43 | float textAlpha = clamp(td / fwidth(td) + 0.5, 0.0, 1.0); 44 | 45 | vec2 size = textureSize(Texture0, 0); 46 | vec2 shadowOffset = (g_sdfParam.zw / size); 47 | float d2 = texture(Texture0, UV - shadowOffset).a; 48 | 49 | float sd = (d2 - 0.5); 50 | float shadowAlpha = clamp(sd / fwidth(sd) + 0.5, 0.0, 1.0); 51 | float sBase = shadowAlpha * (1.0 - textAlpha); 52 | 53 | vec4 color; 54 | if (textAlpha == 0.0) 55 | { 56 | color.rgb = g_sdfShadowColor.rgb; 57 | } 58 | else 59 | { 60 | color.rgb = mix(Color.rgb, g_sdfShadowColor.rgb, sBase); 61 | } 62 | color.a = (sBase * g_sdfShadowColor.a) + (textAlpha * Color.a); 63 | 64 | FragColor = (color + g_colorAdd); 65 | } 66 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/shape.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // PSInput 9 | // 10 | layout(location = 0) in vec4 Color; 11 | 12 | // 13 | // PSOutput 14 | // 15 | layout(location = 0) out vec4 FragColor; 16 | 17 | // 18 | // Constant Buffer 19 | // 20 | layout(std140) uniform PSConstants2D 21 | { 22 | vec4 g_colorAdd; 23 | vec4 g_sdfParam; 24 | vec4 g_sdfOutlineColor; 25 | vec4 g_sdfShadowColor; 26 | vec4 g_internal; 27 | }; 28 | 29 | // 30 | // Functions 31 | // 32 | void main() 33 | { 34 | FragColor = (Color + g_colorAdd); 35 | } 36 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/sky.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2023 Ryo Suzuki. 2 | // Copyright (c) 2016-2023 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | // 6 | // https://github.com/turanszkij/WickedEngine/blob/master/WickedEngine/shaders/skyHF.hlsli 7 | // 8 | // Copyright(c) 2021 Turanszki Janos 9 | // 10 | // Permission is hereby granted, free of charge, to any person obtaining a copy 11 | // of this software and associated documentation files(the "Software"), to deal 12 | // in the Software without restriction, including without limitation the rights 13 | // to use, copy, modify, merge, publish, distribute, sublicense, and / or sell 14 | // copies of the Software, and to permit persons to whom the Software is 15 | // furnished to do so, subject to the following conditions : 16 | // 17 | // The above copyright notice and this permission notice shall be included in 18 | // all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE 23 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 26 | // THE SOFTWARE. 27 | 28 | // Atmosphere based on: https://www.shadertoy.com/view/Ml2cWG 29 | // Cloud noise based on: https://www.shadertoy.com/view/4tdSWr 30 | 31 | # version 410 32 | 33 | // 34 | // PSInput 35 | // 36 | layout(location = 0) in vec3 WorldPosition; 37 | layout(location = 1) in vec2 UV; 38 | layout(location = 2) in vec3 Normal; 39 | 40 | // 41 | // PSOutput 42 | // 43 | layout(location = 0) out vec4 FragColor; 44 | 45 | // 46 | // Constant Buffer 47 | // 48 | layout(std140) uniform PSPerFrame 49 | { 50 | vec3 g_globalAmbientColor; 51 | vec3 g_sunColor; 52 | vec3 g_sunDirection; 53 | }; 54 | 55 | layout(std140) uniform PSPerView 56 | { 57 | vec3 g_eyePosition; 58 | }; 59 | 60 | layout(std140) uniform PSSky 61 | { 62 | vec3 g_zenithColor; 63 | float g_fogHeightSky; 64 | 65 | vec3 g_horizonColor; 66 | float g_cloudiness; 67 | 68 | vec3 g_cloudUVTransform; // cos(theta), -sin(thita), sin(theta) 69 | float g_cloudScale; 70 | 71 | float g_cloudTime; 72 | float g_cloudPlaneHeight; 73 | float g_starBrightness; 74 | uint g_option; 75 | 76 | vec3 g_cloudColor; 77 | float g_skyExposure; 78 | 79 | mat3x3 g_starsRotation; 80 | 81 | vec3 g_starOffset; 82 | float g_starSaturation; 83 | }; 84 | 85 | // 86 | // Functions 87 | // 88 | 89 | # define OPTION_SUN_ENABLED (1u << 0) 90 | # define OPTION_CLOUDS_ENABLED (1u << 1) 91 | # define OPTION_CLOUDS_LIGHTING_ENABLED (1u << 2) 92 | # define PI (3.14159265f) 93 | 94 | // o : ray origin 95 | // d : ray direction 96 | // returns distance on the ray to the object if hit, 0 otherwise 97 | float Trace_plane(vec3 o, vec3 d, vec3 planeOrigin,vec3 planeNormal) 98 | { 99 | return dot(planeNormal, (planeOrigin - o) / dot(planeNormal, d)); 100 | } 101 | 102 | vec2 hash(vec2 p) 103 | { 104 | p = vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3))); 105 | return -1.0 + 2.0 * fract(sin(p) * 43758.5453123); 106 | } 107 | 108 | float noise(in vec2 p) 109 | { 110 | const float K1 = 0.366025404; // (sqrt(3)-1)/2; 111 | const float K2 = 0.211324865; // (3-sqrt(3))/6; 112 | vec2 i = floor(p + (p.x + p.y) * K1); 113 | vec2 a = p - i + (i.x + i.y) * K2; 114 | vec2 o = (a.x > a.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0); //float2 of = 0.5 + 0.5*float2(sign(a.x-a.y), sign(a.y-a.x)); 115 | vec2 b = a - o + K2; 116 | vec2 c = a - 1.0 + 2.0 * K2; 117 | vec3 h = max(0.5 - vec3(dot(a, a), dot(b, b), dot(c, c)), 0.0); 118 | vec3 n = h * h * h * h * vec3(dot(a, hash(i + 0.0)), dot(b, hash(i + o)), dot(c, hash(i + 1.0))); 119 | return dot(n, vec3(70.0, 70.0, 70.0)); 120 | } 121 | 122 | vec3 CustomAtmosphericScattering(vec3 V, vec3 sunDirection, vec3 sunColor, bool sun_enabled, bool dark_enabled) 123 | { 124 | vec3 skyColor = g_zenithColor; 125 | bool sunDisc = sun_enabled; 126 | 127 | float zenith = V.y; // how much is above (0: horizon, 1: directly above) 128 | float sunScatter = clamp(sunDirection.y + 0.1f, 0.0f, 1.0f); // how much the sun is directly above. Even if sunis at horizon, we add a constant scattering amount so that light still scatters at horizon 129 | 130 | float atmosphereDensity = 0.5 + g_fogHeightSky; // constant of air density, or "fog height" as interpreted here (bigger is more obstruction of sun) 131 | float zenithDensity = atmosphereDensity / pow(max(0.000001f, zenith), 0.75f); 132 | float sunScatterDensity = atmosphereDensity / pow(max(0.000001f, sunScatter), 0.75f); 133 | 134 | vec3 aberration = vec3(0.39, 0.57, 1.0); // the chromatic aberration effect on the horizon-zenith fade line 135 | vec3 skyAbsorption = clamp(exp2(aberration * -zenithDensity) * 2.0f, 0.0f, 1.0f); // gradient on horizon 136 | vec3 sunAbsorption = clamp(sunColor * exp2(aberration * -sunScatterDensity) * 2.0f, 0.0f, 1.0f); // gradient of sun when it's getting below horizon 137 | 138 | float sunAmount = distance(V, sunDirection); // sun falloff descreasing from mid point 139 | float rayleigh = 1.0 + pow(1.0 - clamp(sunAmount, 0.0f, 1.0f), 2.0) * PI * 0.5; 140 | float mie_disk = clamp(1.0 - pow(sunAmount, 0.1), 0.0f, 1.0f); 141 | vec3 mie = mie_disk * mie_disk * (3.0 - 2.0 * mie_disk) * 2.0 * PI * sunAbsorption; 142 | 143 | vec3 totalColor = mix(g_horizonColor, g_zenithColor * zenithDensity * rayleigh, skyAbsorption); 144 | totalColor = mix(totalColor * skyAbsorption, totalColor, sunScatter); // when sun goes below horizon, absorb sky color 145 | if (sunDisc) 146 | { 147 | vec3 sun = smoothstep(0.03, 0.026, sunAmount) * sunColor * 50.0 * skyAbsorption; // sun disc 148 | totalColor += sun; 149 | totalColor += mie; 150 | } 151 | totalColor *= (sunAbsorption + length(sunAbsorption)) * 0.5f; // when sun goes below horizon, fade out whole sky 152 | totalColor *= 0.25; // exposure level 153 | 154 | if (dark_enabled) 155 | { 156 | totalColor = max(pow(clamp(dot(sunDirection, V), 0.0f, 1.0f), 64) * sunColor, 0) * skyAbsorption; 157 | } 158 | 159 | return totalColor; 160 | } 161 | 162 | void CalculateClouds(inout vec3 sky, vec3 V, bool cloudsLightingEnabled, bool dark_enabled) 163 | { 164 | if (g_cloudiness <= 0) 165 | { 166 | return; 167 | } 168 | 169 | // Trace a cloud layer plane: 170 | vec3 o = g_eyePosition; 171 | vec3 d = V; 172 | vec3 planeOrigin = vec3(0, g_cloudPlaneHeight, 0); 173 | vec3 planeNormal = vec3(0, -1, 0); 174 | float t = Trace_plane(o, d, planeOrigin, planeNormal); 175 | 176 | if (t < 0) 177 | { 178 | return; 179 | } 180 | 181 | mat2x2 cloudUVTransform = mat2x2(g_cloudUVTransform.xy, g_cloudUVTransform.zx); 182 | vec2 cloudPos = o.xz + (d.xz * cloudUVTransform) * t; 183 | vec2 cloudUV = cloudPos * g_cloudScale; 184 | float cloudTime = g_cloudTime; 185 | mat2x2 m = mat2x2(1.6, 1.2, -1.2, 1.6); 186 | uint quality = 8; 187 | 188 | // rotate uvs like a flow effect: 189 | float flow = 0; 190 | { 191 | vec2 uv = cloudUV * 0.5f; 192 | float amount = 0.1; 193 | for (uint i = 0; i < quality; i++) 194 | { 195 | flow += noise(uv) * amount; 196 | uv = (uv * m); 197 | amount *= 0.4; 198 | } 199 | } 200 | 201 | // Main shape: 202 | float clouds = 0.0; 203 | { 204 | float time = cloudTime * 0.2f; 205 | float density = 1.1f; 206 | vec2 uv = cloudUV * 0.8f; 207 | uv -= flow - time; 208 | for (uint i = 0; i < quality; i++) 209 | { 210 | clouds += density * noise(uv); 211 | uv = (uv * m) + time; 212 | density *= 0.6f; 213 | } 214 | } 215 | 216 | // Detail shape: 217 | { 218 | float detail_shape = 0.0; 219 | float time = cloudTime * 0.1f; 220 | float density = 0.8f; 221 | vec2 uv = cloudUV; 222 | uv -= flow - time; 223 | for (uint i = 0; i < quality; i++) 224 | { 225 | detail_shape += abs(density * noise(uv)); 226 | uv = (uv * m) + time; 227 | density *= 0.7f; 228 | } 229 | clouds *= detail_shape + clouds; 230 | clouds *= detail_shape; 231 | } 232 | 233 | // lerp between "choppy clouds" and "uniform clouds". Lower cloudiness will produce choppy clouds, but very high cloudiness will switch to overcast unfiform clouds: 234 | clouds = mix(clouds * 9.0f * g_cloudiness + 0.3f, clouds * 0.5f + 0.5f, pow(clamp(g_cloudiness, 0.0f, 1.0f), 8)); 235 | clouds = clamp(clouds - (1 - g_cloudiness), 0.0f, 1.0f); // modulate constant cloudiness 236 | clouds *= pow(1 - clamp(length(abs(cloudPos * 0.00001f)), 0.0f, 1.0f), 16); //fade close to horizon 237 | 238 | if (dark_enabled) 239 | { 240 | sky *= pow(clamp(1 - clouds, 0.0f, 1.0f), 16.0f); // only sun and clouds. Boost clouds to have nicer sun shafts occlusion 241 | } 242 | else if (cloudsLightingEnabled) 243 | { 244 | vec3 cloudLighting = (dot(-V, g_sunDirection) * 0.5f + 0.5f) * g_sunColor * (1 - g_cloudiness); 245 | sky = mix(min(sky, 1.0f), g_cloudColor + cloudLighting, clouds); // sky and clouds on top 246 | } 247 | else 248 | { 249 | sky = mix(sky, g_cloudColor, clouds); // sky and clouds on top 250 | } 251 | } 252 | 253 | // Copyright(c) Pablo Roman Andrioli 254 | // 255 | // Permission is hereby granted, free of charge, to any person obtaining a copy 256 | // of this software and associated documentation files(the "Software"), to deal 257 | // in the Software without restriction, including without limitation the rights 258 | // to use, copy, modify, merge, publish, distribute, sublicense, and / or sell 259 | // copies of the Software, and to permit persons to whom the Software is 260 | // furnished to do so, subject to the following conditions : 261 | // 262 | // The above copyright notice and this permission notice shall be included in 263 | // all copies or substantial portions of the Software. 264 | // 265 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 266 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 267 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE 268 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 269 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 270 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 271 | // THE SOFTWARE. 272 | 273 | // Star Nest based on: https://www.shadertoy.com/view/XlfGRj 274 | 275 | #define iterations 22 276 | #define formuparam 0.53 277 | #define volsteps 3 278 | #define stepsize 0.1 279 | #define tile 0.850 280 | #define brightness 0.0015 281 | #define darkmatter 0.300 282 | #define distfading 0.730 283 | 284 | vec3 GetStars(vec3 V, float starBrightness) 285 | { 286 | vec3 dir = (V * g_starsRotation); 287 | vec3 from = g_starOffset; 288 | 289 | //volumetric rendering 290 | float s = 0.1f, fade = 1.0f; 291 | vec3 v = vec3(0.0f); 292 | 293 | for (uint r = 0; r < volsteps; ++r) 294 | { 295 | vec3 p = from + s * dir * 0.5f; 296 | p = abs(vec3(tile) - mod(p, vec3(tile * 2.0f))); // tiling fold 297 | float pa = 0.0f, a = 0.0f; 298 | 299 | for (uint i = 0; i < iterations; ++i) 300 | { 301 | p = abs(p) / dot(p, p) - formuparam; // the magic formula 302 | a += abs(length(p) - pa); // absolute sum of average change 303 | pa = length(p); 304 | } 305 | 306 | float dm = max(0.0f, darkmatter - a * a * 0.001f); //dark matter 307 | a *= a * a; // add contrast 308 | 309 | if (6 < r) 310 | { 311 | fade*=1.-dm; // dark matter, don't render near 312 | } 313 | 314 | v += fade; 315 | v += vec3(s, s*s, s*s*s*s ) * a * brightness * fade; // coloring based on distance 316 | fade *= distfading; // distance fading 317 | s += stepsize; 318 | } 319 | 320 | v = mix(vec3(length(v)), v, g_starSaturation); //color adjust 321 | 322 | return clamp(v * V.y * 0.02f * starBrightness, 0.0f, 1.0f); 323 | } 324 | 325 | // Returns sky color modulated by the sun and clouds 326 | // V : view direction 327 | vec3 GetDynamicSkyColor(in vec3 V, bool sun_enabled, bool clouds_enabled, bool dark_enabled) 328 | { 329 | vec3 sunDirection = g_sunDirection; 330 | vec3 sunColor = g_sunColor; 331 | 332 | vec3 sky = CustomAtmosphericScattering 333 | ( 334 | V, // normalized ray direction 335 | sunDirection, // position of the sun 336 | sunColor, // color of the sun, for disc 337 | sun_enabled, // use sun and total 338 | dark_enabled // enable dark mode for light shafts etc. 339 | ); 340 | 341 | if (0.0 < g_starBrightness) 342 | { 343 | float starBrightness = g_starBrightness * (1 - g_cloudiness) * (1 - g_cloudiness); 344 | sky += GetStars(V, starBrightness); 345 | } 346 | 347 | sky *= g_skyExposure; 348 | 349 | if (clouds_enabled) 350 | { 351 | bool cloudsLightingEnabled = (g_option & OPTION_CLOUDS_LIGHTING_ENABLED) != 0; 352 | CalculateClouds(sky, V, cloudsLightingEnabled, dark_enabled); 353 | } 354 | 355 | return sky; 356 | } 357 | 358 | void main() 359 | { 360 | vec3 dir = normalize(WorldPosition - g_eyePosition); 361 | 362 | bool sunEnabled = (g_option & OPTION_SUN_ENABLED) != 0; 363 | 364 | bool cloudsEnabled = (g_option & OPTION_CLOUDS_ENABLED) != 0; 365 | 366 | vec3 skyColor = GetDynamicSkyColor(dir, sunEnabled, cloudsEnabled, false); 367 | 368 | FragColor = vec4(skyColor, 1.0f); 369 | } 370 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/sprite.vert: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // VSInput 9 | // 10 | layout(location = 0) in vec2 VertexPosition; 11 | layout(location = 1) in vec2 VertexUV; 12 | layout(location = 2) in vec4 VertexColor; 13 | 14 | // 15 | // VSOutput 16 | // 17 | layout(location = 0) out vec4 Color; 18 | layout(location = 1) out vec2 UV; 19 | out gl_PerVertex 20 | { 21 | vec4 gl_Position; 22 | }; 23 | 24 | // 25 | // Siv3D Functions 26 | // 27 | vec4 s3d_Transform2D(const vec2 pos, const vec4 t[2]) 28 | { 29 | return vec4(t[0].zw + (pos.x * t[0].xy) + (pos.y * t[1].xy), t[1].zw); 30 | } 31 | 32 | // 33 | // Constant Buffer 34 | // 35 | layout(std140) uniform VSConstants2D 36 | { 37 | vec4 g_transform[2]; 38 | vec4 g_colorMul; 39 | }; 40 | 41 | // 42 | // Functions 43 | // 44 | void main() 45 | { 46 | gl_Position = s3d_Transform2D(VertexPosition, g_transform); 47 | 48 | Color = (VertexColor * g_colorMul); 49 | 50 | UV = VertexUV; 51 | } 52 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/square_dot.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // PSInput 9 | // 10 | layout(location = 0) in vec4 Color; 11 | layout(location = 1) in vec2 UV; 12 | 13 | // 14 | // PSOutput 15 | // 16 | layout(location = 0) out vec4 FragColor; 17 | 18 | // 19 | // Constant Buffer 20 | // 21 | layout(std140) uniform PSConstants2D 22 | { 23 | vec4 g_colorAdd; 24 | vec4 g_sdfParam; 25 | vec4 g_sdfOutlineColor; 26 | vec4 g_sdfShadowColor; 27 | vec4 g_internal; 28 | }; 29 | 30 | // 31 | // Functions 32 | // 33 | void main() 34 | { 35 | float tr = UV.y; 36 | float d = abs(mod(UV.x, 3.0) - 1.0); 37 | float range = 1.0 - tr; 38 | vec4 color = Color; 39 | color.a *= (d < range) ? 1.0 : (d < 1.0) ? ((1.0 - d) / tr) : 0.0; 40 | 41 | FragColor = (color + g_colorAdd); 42 | } 43 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/shader/glsl/texture.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec4 g_internal; 33 | }; 34 | 35 | // 36 | // Functions 37 | // 38 | void main() 39 | { 40 | vec4 texColor = texture(Texture0, UV); 41 | 42 | FragColor = ((texColor * Color) + g_colorAdd); 43 | } 44 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/texture/box-shadow/128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/texture/box-shadow/128.png -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/texture/box-shadow/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/texture/box-shadow/16.png -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/texture/box-shadow/256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/texture/box-shadow/256.png -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/texture/box-shadow/32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/texture/box-shadow/32.png -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/texture/box-shadow/64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/texture/box-shadow/64.png -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/engine/texture/box-shadow/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/engine/texture/box-shadow/8.png -------------------------------------------------------------------------------- /tests/CoTaskLibTests/App/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/App/icon.ico -------------------------------------------------------------------------------- /tests/CoTaskLibTests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.12) 2 | project(OpenSiv3D_Linux_App CXX) 3 | 4 | if (NOT CMAKE_CONFIGURATION_TYPES AND 5 | NOT CMAKE_NO_BUILD_TYPE AND 6 | NOT CMAKE_BUILD_TYPE AND 7 | CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) 8 | message(STATUS "[!] Setting build type to 'Release' as none was specified.") 9 | set(CMAKE_BUILD_TYPE Release) 10 | endif() 11 | 12 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}) 13 | 14 | add_executable(CoTaskLibTest 15 | Main.cpp 16 | ) 17 | 18 | target_include_directories(CoTaskLibTest PRIVATE 19 | ../../include 20 | ) 21 | 22 | find_package(Siv3D) 23 | target_link_libraries(CoTaskLibTest PUBLIC Siv3D::Siv3D) 24 | 25 | target_compile_features(CoTaskLibTest PRIVATE cxx_std_20) 26 | 27 | if(BUILD_TESTING) 28 | enable_testing() 29 | add_test( 30 | NAME Test 31 | COMMAND CoTaskLibTest 32 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 33 | ) 34 | endif() 35 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/font/min/LICENSE: -------------------------------------------------------------------------------- 1 | This Font Software is licensed under the SIL Open Font License, 2 | Version 1.1. 3 | 4 | This license is copied below, and is also available with a FAQ at: 5 | http://scripts.sil.org/OFL 6 | 7 | ----------------------------------------------------------- 8 | SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 9 | ----------------------------------------------------------- 10 | 11 | PREAMBLE 12 | The goals of the Open Font License (OFL) are to stimulate worldwide 13 | development of collaborative font projects, to support the font 14 | creation efforts of academic and linguistic communities, and to 15 | provide a free and open framework in which fonts may be shared and 16 | improved in partnership with others. 17 | 18 | The OFL allows the licensed fonts to be used, studied, modified and 19 | redistributed freely as long as they are not sold by themselves. The 20 | fonts, including any derivative works, can be bundled, embedded, 21 | redistributed and/or sold with any software provided that any reserved 22 | names are not used by derivative works. The fonts and derivatives, 23 | however, cannot be released under any other type of license. The 24 | requirement for fonts to remain under this license does not apply to 25 | any document created using the fonts or their derivatives. 26 | 27 | DEFINITIONS 28 | "Font Software" refers to the set of files released by the Copyright 29 | Holder(s) under this license and clearly marked as such. This may 30 | include source files, build scripts and documentation. 31 | 32 | "Reserved Font Name" refers to any names specified as such after the 33 | copyright statement(s). 34 | 35 | "Original Version" refers to the collection of Font Software 36 | components as distributed by the Copyright Holder(s). 37 | 38 | "Modified Version" refers to any derivative made by adding to, 39 | deleting, or substituting -- in part or in whole -- any of the 40 | components of the Original Version, by changing formats or by porting 41 | the Font Software to a new environment. 42 | 43 | "Author" refers to any designer, engineer, programmer, technical 44 | writer or other person who contributed to the Font Software. 45 | 46 | PERMISSION & CONDITIONS 47 | Permission is hereby granted, free of charge, to any person obtaining 48 | a copy of the Font Software, to use, study, copy, merge, embed, 49 | modify, redistribute, and sell modified and unmodified copies of the 50 | Font Software, subject to the following conditions: 51 | 52 | 1) Neither the Font Software nor any of its individual components, in 53 | Original or Modified Versions, may be sold by itself. 54 | 55 | 2) Original or Modified Versions of the Font Software may be bundled, 56 | redistributed and/or sold with any software, provided that each copy 57 | contains the above copyright notice and this license. These can be 58 | included either as stand-alone text files, human-readable headers or 59 | in the appropriate machine-readable metadata fields within text or 60 | binary files as long as those fields can be easily viewed by the user. 61 | 62 | 3) No Modified Version of the Font Software may use the Reserved Font 63 | Name(s) unless explicit written permission is granted by the 64 | corresponding Copyright Holder. This restriction only applies to the 65 | primary font name as presented to the users. 66 | 67 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 68 | Software shall not be used to promote, endorse or advertise any 69 | Modified Version, except to acknowledge the contribution(s) of the 70 | Copyright Holder(s) and the Author(s) or with their explicit written 71 | permission. 72 | 73 | 5) The Font Software, modified or unmodified, in part or in whole, 74 | must be distributed entirely under this license, and must not be 75 | distributed under any other license. The requirement for fonts to 76 | remain under this license does not apply to any document created using 77 | the Font Software. 78 | 79 | TERMINATION 80 | This license becomes null and void if any of the above conditions are 81 | not met. 82 | 83 | DISCLAIMER 84 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 85 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 86 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 87 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 88 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 89 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 90 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 91 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 92 | OTHER DEALINGS IN THE FONT SOFTWARE. 93 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/font/min/siv3d-min.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/font/min/siv3d-min.woff -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/apply_srgb_curve.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/apply_srgb_curve.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/bitmapfont.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/bitmapfont.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/copy.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/copy.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/forward3d.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/forward3d.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/forward3d.vs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/forward3d.vs -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/fullscreen_triangle.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/fullscreen_triangle.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/fullscreen_triangle.vs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/fullscreen_triangle.vs -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/gaussian_blur_13.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/gaussian_blur_13.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/gaussian_blur_5.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/gaussian_blur_5.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/gaussian_blur_9.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/gaussian_blur_9.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/line3d.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/line3d.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/line3d.vs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/line3d.vs -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/msdffont.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/msdffont.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/msdffont_outline.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/msdffont_outline.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/msdffont_outlineshadow.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/msdffont_outlineshadow.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/msdffont_shadow.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/msdffont_shadow.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/msdfprint.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/msdfprint.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/quad_warp.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/quad_warp.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/quad_warp.vs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/quad_warp.vs -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/round_dot.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/round_dot.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/sdffont.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/sdffont.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/sdffont_outline.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/sdffont_outline.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/sdffont_outlineshadow.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/sdffont_outlineshadow.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/sdffont_shadow.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/sdffont_shadow.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/shape.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/shape.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/sky.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/sky.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/sprite.vs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/sprite.vs -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/square_dot.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/square_dot.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/d3d11/texture.ps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/shader/d3d11/texture.ps -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/apply_srgb_curve.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Functions 25 | // 26 | 27 | // 28 | // https://github.com/microsoft/DirectX-Graphics-Samples/blob/master/MiniEngine/Core/Shaders/ColorSpaceUtility.hlsli 29 | // 30 | // Copyright(c) 2015 Microsoft 31 | // 32 | // Permission is hereby granted, free of charge, to any person obtaining a copy 33 | // of this software and associated documentation files(the "Software"), to deal 34 | // in the Software without restriction, including without limitation the rights 35 | // to use, copy, modify, merge, publish, distribute, sublicense, and / or sell 36 | // copies of the Software, and to permit persons to whom the Software is 37 | // furnished to do so, subject to the following conditions : 38 | // 39 | // The above copyright notice and this permission notice shall be included in 40 | // all copies or substantial portions of the Software. 41 | // 42 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 43 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 44 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE 45 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 46 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 47 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 48 | // THE SOFTWARE. 49 | float ApplySRGBCurve_Fast(float x) 50 | { 51 | return x < 0.0031308f ? 12.92f * x : 1.13005f * sqrt(x - 0.00228f) - 0.13448f * x + 0.005719f; 52 | } 53 | 54 | float ApplySRGBCurve(float x) 55 | { 56 | return x < 0.0031308f ? 12.92f * x : 1.055f * pow(x, 1.0f / 2.4f) - 0.055f; 57 | } 58 | 59 | vec3 ApplySRGBCurve0(vec3 color) 60 | { 61 | return pow(color, vec3(1.0f / 2.2f)); 62 | } 63 | 64 | vec3 ApplySRGBCurve1(vec3 color) 65 | { 66 | float r = ApplySRGBCurve_Fast(color.r); 67 | float g = ApplySRGBCurve_Fast(color.g); 68 | float b = ApplySRGBCurve_Fast(color.b); 69 | return vec3(r, g, b); 70 | } 71 | 72 | vec3 ApplySRGBCurve2(vec3 color) 73 | { 74 | float r = ApplySRGBCurve(color.r); 75 | float g = ApplySRGBCurve(color.g); 76 | float b = ApplySRGBCurve(color.b); 77 | return vec3(r, g, b); 78 | } 79 | 80 | void main() 81 | { 82 | vec3 texColor = texture(Texture0, UV).rgb; 83 | 84 | FragColor = vec4(ApplySRGBCurve2(texColor), 1.0f); 85 | } 86 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/bitmapfont.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec4 g_internal; 33 | }; 34 | 35 | // 36 | // Functions 37 | // 38 | void main() 39 | { 40 | float textAlpha = texture(Texture0, UV).a; 41 | 42 | vec4 color = vec4(Color.rgb, Color.a * textAlpha); 43 | 44 | FragColor = (color + g_colorAdd); 45 | } 46 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/copy.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec4 g_internal; 33 | }; 34 | 35 | // 36 | // Functions 37 | // 38 | void main() 39 | { 40 | vec4 texColor = texture(Texture0, UV); 41 | 42 | FragColor = texColor; 43 | } 44 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/forward3d.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2023 Ryo Suzuki. 2 | // Copyright (c) 2016-2023 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec3 WorldPosition; 16 | layout(location = 1) in vec2 UV; 17 | layout(location = 2) in vec3 Normal; 18 | 19 | // 20 | // PSOutput 21 | // 22 | layout(location = 0) out vec4 FragColor; 23 | 24 | // 25 | // Constant Buffer 26 | // 27 | layout(std140) uniform PSPerFrame 28 | { 29 | vec3 g_globalAmbientColor; 30 | vec3 g_sunColor; 31 | vec3 g_sunDirection; 32 | }; 33 | 34 | layout(std140) uniform PSPerView 35 | { 36 | vec3 g_eyePosition; 37 | }; 38 | 39 | layout(std140) uniform PSPerMaterial 40 | { 41 | vec3 g_ambientColor; 42 | uint g_hasTexture; 43 | vec4 g_diffuseColor; 44 | vec3 g_specularColor; 45 | float g_shininess; 46 | vec3 g_emissionColor; 47 | }; 48 | 49 | // 50 | // Functions 51 | // 52 | vec4 GetDiffuseColor(vec2 uv) 53 | { 54 | vec4 diffuseColor = g_diffuseColor; 55 | 56 | if (g_hasTexture == 1) 57 | { 58 | diffuseColor *= texture(Texture0, uv); 59 | } 60 | 61 | return diffuseColor; 62 | } 63 | 64 | vec3 CalculateDiffuseReflection(vec3 n, vec3 l, vec3 lightColor, vec3 diffuseColor, vec3 ambientColor) 65 | { 66 | vec3 directColor = lightColor * max(dot(n, l), 0.0f); 67 | return ((ambientColor + directColor) * diffuseColor); 68 | } 69 | 70 | vec3 CalculateSpecularReflection(vec3 n, vec3 h, float shininess, float nl, vec3 lightColor, vec3 specularColor) 71 | { 72 | float highlight = pow(max(dot(n, h), 0.0f), shininess) * float(0.0f < nl); 73 | return (lightColor * specularColor * highlight); 74 | } 75 | 76 | void main() 77 | { 78 | vec3 lightColor = g_sunColor; 79 | vec3 lightDirection = g_sunDirection; 80 | 81 | vec3 n = normalize(Normal); 82 | vec3 l = lightDirection; 83 | vec4 diffuseColor = GetDiffuseColor(UV); 84 | vec3 ambientColor = (g_ambientColor * g_globalAmbientColor); 85 | 86 | // Diffuse 87 | vec3 diffuseReflection = CalculateDiffuseReflection(n, l, lightColor, diffuseColor.rgb, ambientColor); 88 | 89 | // Specular 90 | vec3 v = normalize(g_eyePosition - WorldPosition); 91 | vec3 h = normalize(v + lightDirection); 92 | vec3 specularReflection = CalculateSpecularReflection(n, h, g_shininess, dot(n, l), lightColor, g_specularColor); 93 | 94 | FragColor = vec4(diffuseReflection + specularReflection + g_emissionColor, diffuseColor.a); 95 | } 96 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/forward3d.vert: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // VSInput 9 | // 10 | layout(location = 0) in vec4 VertexPosition; 11 | layout(location = 1) in vec3 VertexNormal; 12 | layout(location = 2) in vec2 VertexUV; 13 | 14 | // 15 | // VSOutput 16 | // 17 | layout(location = 0) out vec3 WorldPosition; 18 | layout(location = 1) out vec2 UV; 19 | layout(location = 2) out vec3 Normal; 20 | out gl_PerVertex 21 | { 22 | vec4 gl_Position; 23 | }; 24 | 25 | // 26 | // Constant Buffer 27 | // 28 | layout(std140) uniform VSPerView 29 | { 30 | mat4x4 g_worldToProjected; 31 | }; 32 | 33 | layout(std140) uniform VSPerObject 34 | { 35 | mat4x4 g_localToWorld; 36 | }; 37 | 38 | layout(std140) uniform VSPerMaterial 39 | { 40 | vec4 g_uvTransform; 41 | }; 42 | 43 | // 44 | // Functions 45 | // 46 | void main() 47 | { 48 | vec4 worldPosition = VertexPosition * g_localToWorld; 49 | 50 | gl_Position = worldPosition * g_worldToProjected; 51 | WorldPosition = worldPosition.xyz; 52 | UV = (VertexUV * g_uvTransform.xy + g_uvTransform.zw); 53 | Normal = VertexNormal * mat3x3(g_localToWorld); 54 | } 55 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/fullscreen_triangle.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec2 UV; 16 | 17 | // 18 | // PSOutput 19 | // 20 | layout(location = 0) out vec4 FragColor; 21 | 22 | // 23 | // Functions 24 | // 25 | void main() 26 | { 27 | FragColor = texture(Texture0, UV); 28 | } 29 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/fullscreen_triangle.vert: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // VSOutput 9 | // 10 | layout(location = 0) out vec2 UV; 11 | out gl_PerVertex 12 | { 13 | vec4 gl_Position; 14 | }; 15 | 16 | // 17 | // Functions 18 | // 19 | void main() 20 | { 21 | float x = -1.0 + float((gl_VertexID & 1) << 2); 22 | float y = -1.0 + float((gl_VertexID & 2) << 1); 23 | gl_Position = vec4(x, y, 0, 1); 24 | 25 | UV.x = (x + 1.0) * 0.5; 26 | UV.y = (-y + 1.0) * 0.5; 27 | } 28 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/gaussian_blur_13.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2023 Ryo Suzuki. 2 | // Copyright (c) 2016-2023 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec2 g_pixelSize; 33 | vec2 g_direction; 34 | }; 35 | 36 | // 37 | // Functions 38 | // 39 | void main() 40 | { 41 | vec2 offset1 = (1.41176470588235 * g_direction); 42 | vec2 offset2 = (3.29411764705882 * g_direction); 43 | vec2 offset3 = (5.17647058823529 * g_direction); 44 | 45 | vec4 color = (texture(Texture0, UV) * 0.196482550151140); 46 | color += (texture(Texture0, UV + (offset1 * g_pixelSize)) * 0.296906964672834); 47 | color += (texture(Texture0, UV - (offset1 * g_pixelSize)) * 0.296906964672834); 48 | color += (texture(Texture0, UV + (offset2 * g_pixelSize)) * 0.0944703978504473); 49 | color += (texture(Texture0, UV - (offset2 * g_pixelSize)) * 0.0944703978504473); 50 | color += (texture(Texture0, UV + (offset3 * g_pixelSize)) * 0.0103813624011481); 51 | color += (texture(Texture0, UV - (offset3 * g_pixelSize)) * 0.0103813624011481); 52 | 53 | FragColor = color; 54 | } 55 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/gaussian_blur_5.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2023 Ryo Suzuki. 2 | // Copyright (c) 2016-2023 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec2 g_pixelSize; 33 | vec2 g_direction; 34 | }; 35 | 36 | // 37 | // Functions 38 | // 39 | void main() 40 | { 41 | vec2 offset1 = (1.33333333333333 * g_direction); 42 | 43 | vec4 color = (texture(Texture0, UV) * 0.294117647058824); 44 | color += (texture(Texture0, UV + (offset1 * g_pixelSize)) * 0.352941176470588); 45 | color += (texture(Texture0, UV - (offset1 * g_pixelSize)) * 0.352941176470588); 46 | 47 | FragColor = color; 48 | } 49 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/gaussian_blur_9.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2023 Ryo Suzuki. 2 | // Copyright (c) 2016-2023 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec2 g_pixelSize; 33 | vec2 g_direction; 34 | }; 35 | 36 | // 37 | // Functions 38 | // 39 | void main() 40 | { 41 | vec2 offset1 = (1.38461538461538 * g_direction); 42 | vec2 offset2 = (3.23076923076923 * g_direction); 43 | 44 | vec4 color = (texture(Texture0, UV) * 0.227027027027027); 45 | color += (texture(Texture0, UV + (offset1 * g_pixelSize)) * 0.316216216216216); 46 | color += (texture(Texture0, UV - (offset1 * g_pixelSize)) * 0.316216216216216); 47 | color += (texture(Texture0, UV + (offset2 * g_pixelSize)) * 0.070270270270270); 48 | color += (texture(Texture0, UV - (offset2 * g_pixelSize)) * 0.070270270270270); 49 | 50 | FragColor = color; 51 | } 52 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/line3d.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // PSInput 9 | // 10 | layout(location = 0) in vec3 WorldPosition; 11 | layout(location = 1) in vec4 Color; 12 | 13 | // 14 | // PSOutput 15 | // 16 | layout(location = 0) out vec4 FragColor; 17 | 18 | // 19 | // Functions 20 | // 21 | void main() 22 | { 23 | FragColor = Color; 24 | } 25 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/line3d.vert: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // VSInput 9 | // 10 | layout(location = 0) in vec4 VertexPosition; 11 | layout(location = 1) in vec4 VertexColor; 12 | 13 | // 14 | // VSOutput 15 | // 16 | layout(location = 0) out vec3 WorldPosition; 17 | layout(location = 1) out vec4 Color; 18 | out gl_PerVertex 19 | { 20 | vec4 gl_Position; 21 | }; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform VSPerView 27 | { 28 | mat4x4 g_worldToProjected; 29 | }; 30 | 31 | layout(std140) uniform VSPerObject 32 | { 33 | mat4x4 g_localToWorld; 34 | }; 35 | 36 | // 37 | // Functions 38 | // 39 | void main() 40 | { 41 | vec4 worldPosition = VertexPosition * g_localToWorld; 42 | 43 | gl_Position = worldPosition * g_worldToProjected; 44 | WorldPosition = worldPosition.xyz; 45 | Color = VertexColor; 46 | } 47 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/msdffont.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec4 g_internal; 33 | }; 34 | 35 | // 36 | // Functions 37 | // 38 | float median(float r, float g, float b) 39 | { 40 | return max(min(r, g), min(max(r, g), b)); 41 | } 42 | 43 | void main() 44 | { 45 | vec2 size = textureSize(Texture0, 0); 46 | const float pxRange = 4.0; 47 | vec2 msdfUnit = (pxRange / size); 48 | 49 | vec3 s = texture(Texture0, UV).rgb; 50 | float d = median(s.r, s.g, s.b); 51 | 52 | float td = (d - 0.5); 53 | float textAlpha = clamp(td * dot(msdfUnit, 0.5 / fwidth(UV)) + 0.5, 0.0, 1.0); 54 | 55 | vec4 color = vec4(Color.rgb, Color.a * textAlpha); 56 | 57 | FragColor = (color + g_colorAdd); 58 | } 59 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/msdffont_outline.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec4 g_internal; 33 | }; 34 | 35 | // 36 | // Functions 37 | // 38 | float median(float r, float g, float b) 39 | { 40 | return max(min(r, g), min(max(r, g), b)); 41 | } 42 | 43 | void main() 44 | { 45 | vec2 size = textureSize(Texture0, 0); 46 | const float pxRange = 4.0; 47 | vec2 msdfUnit = (pxRange / size); 48 | 49 | vec3 s = texture(Texture0, UV).rgb; 50 | float d = median(s.r, s.g, s.b); 51 | 52 | float od = (d - g_sdfParam.y); 53 | float outlineAlpha = clamp(od * dot(msdfUnit, 0.5 / fwidth(UV)) + 0.5, 0.0, 1.0); 54 | 55 | float td = (d - g_sdfParam.x); 56 | float textAlpha = clamp(td * dot(msdfUnit, 0.5 / fwidth(UV)) + 0.5, 0.0, 1.0); 57 | 58 | float baseAlpha = (outlineAlpha - textAlpha); 59 | 60 | vec4 color; 61 | color.rgb = mix(g_sdfOutlineColor.rgb, Color.rgb, textAlpha); 62 | color.a = baseAlpha * g_sdfOutlineColor.a + textAlpha * Color.a; 63 | 64 | FragColor = (color + g_colorAdd); 65 | } 66 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/msdffont_outlineshadow.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec4 g_internal; 33 | }; 34 | 35 | // 36 | // Functions 37 | // 38 | float median(float r, float g, float b) 39 | { 40 | return max(min(r, g), min(max(r, g), b)); 41 | } 42 | 43 | void main() 44 | { 45 | vec2 size = textureSize(Texture0, 0); 46 | const float pxRange = 4.0; 47 | vec2 msdfUnit = (pxRange / size); 48 | 49 | vec3 s = texture(Texture0, UV).rgb; 50 | float d = median(s.r, s.g, s.b); 51 | 52 | float od = (d - g_sdfParam.y); 53 | float outlineAlpha = clamp(od * dot(msdfUnit, 0.5 / fwidth(UV)) + 0.5, 0.0, 1.0); 54 | 55 | float td = (d - g_sdfParam.x); 56 | float textAlpha = clamp(td * dot(msdfUnit, 0.5 / fwidth(UV)) + 0.5, 0.0, 1.0); 57 | 58 | float baseAlpha = (outlineAlpha - textAlpha); 59 | 60 | vec4 textColor; 61 | textColor.rgb = mix(g_sdfOutlineColor.rgb, Color.rgb, textAlpha); 62 | textColor.a = baseAlpha * g_sdfOutlineColor.a + textAlpha * Color.a; 63 | 64 | 65 | vec2 shadowOffset = (g_sdfParam.zw / size); 66 | vec3 s2 = texture(Texture0, UV - shadowOffset).rgb; 67 | float d2 = median(s2.r, s2.g, s2.b); 68 | 69 | float sd = (d2 - 0.5); 70 | float shadowAlpha = clamp(sd * dot(msdfUnit, 0.5 / fwidth(UV)) + 0.5, 0.0, 1.0); 71 | float sBase = shadowAlpha * (1.0 - textColor.a); 72 | 73 | vec4 color; 74 | if (textColor.a == 0.0) 75 | { 76 | color.rgb = g_sdfShadowColor.rgb; 77 | } 78 | else 79 | { 80 | color.rgb = mix(textColor.rgb, g_sdfShadowColor.rgb, sBase); 81 | } 82 | color.a = (sBase * g_sdfShadowColor.a) + textColor.a; 83 | 84 | FragColor = (color + g_colorAdd); 85 | } 86 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/msdffont_shadow.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec4 g_internal; 33 | }; 34 | 35 | // 36 | // Functions 37 | // 38 | float median(float r, float g, float b) 39 | { 40 | return max(min(r, g), min(max(r, g), b)); 41 | } 42 | 43 | void main() 44 | { 45 | vec2 size = textureSize(Texture0, 0); 46 | const float pxRange = 4.0; 47 | vec2 msdfUnit = (pxRange / size); 48 | 49 | vec3 s = texture(Texture0, UV).rgb; 50 | float d = median(s.r, s.g, s.b); 51 | 52 | float td = (d - 0.5); 53 | float textAlpha = clamp(td * dot(msdfUnit, 0.5 / fwidth(UV)) + 0.5, 0.0, 1.0); 54 | 55 | vec2 shadowOffset = (g_sdfParam.zw / size); 56 | vec3 s2 = texture(Texture0, UV - shadowOffset).rgb; 57 | float d2 = median(s2.r, s2.g, s2.b); 58 | 59 | float sd = (d2 - 0.5); 60 | float shadowAlpha = clamp(sd * dot(msdfUnit, 0.5 / fwidth(UV)) + 0.5, 0.0, 1.0); 61 | float sBase = shadowAlpha * (1.0 - textAlpha); 62 | 63 | vec4 color; 64 | if (textAlpha == 0.0) 65 | { 66 | color.rgb = g_sdfShadowColor.rgb; 67 | } 68 | else 69 | { 70 | color.rgb = mix(Color.rgb, g_sdfShadowColor.rgb, sBase); 71 | } 72 | color.a = (sBase * g_sdfShadowColor.a) + (textAlpha * Color.a); 73 | 74 | FragColor = (color + g_colorAdd); 75 | } 76 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/msdfprint.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec4 g_internal; 33 | }; 34 | 35 | // 36 | // Functions 37 | // 38 | float median(float r, float g, float b) 39 | { 40 | return max(min(r, g), min(max(r, g), b)); 41 | } 42 | 43 | void main() 44 | { 45 | vec2 size = textureSize(Texture0, 0); 46 | const float pxRange = 4.0; 47 | vec2 msdfUnit = (pxRange / size); 48 | 49 | vec3 s = texture(Texture0, UV).rgb; 50 | float d = median(s.r, s.g, s.b); 51 | 52 | float td = (d - 0.5); 53 | float textAlpha = sqrt(clamp(td * dot(msdfUnit, 0.5 / fwidth(UV)) + 0.5, 0.0, 1.0)); 54 | 55 | vec2 shadowOffset = vec2(0.875, 0.875) / size; 56 | vec3 s2 = texture(Texture0, UV - shadowOffset).rgb; 57 | float d2 = median(s2.r, s2.g, s2.b); 58 | float sd = (d2 - 0.5); 59 | float shadowAlpha = sqrt(clamp(sd * dot(msdfUnit, 0.5 / fwidth(UV)) + 0.5, 0.0, 1.0)); 60 | 61 | FragColor = vec4(textAlpha, textAlpha, textAlpha, max(textAlpha, shadowAlpha)); 62 | } 63 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/quad_warp.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2023 Ryo Suzuki. 2 | // Copyright (c) 2016-2023 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec4 g_internal; 33 | }; 34 | 35 | layout(std140) uniform PSQuadWarp 36 | { 37 | mat3x3 g_invHomography; 38 | vec4 g_uvTransform; 39 | }; 40 | 41 | vec2 Transform(vec2 pos, mat3x3 mat) 42 | { 43 | float s = (mat[0][2] * pos.x + mat[1][2] * pos.y + mat[2][2]); 44 | float x = (mat[0][0] * pos.x + mat[1][0] * pos.y + mat[2][0]) / s; 45 | float y = (mat[0][1] * pos.x + mat[1][1] * pos.y + mat[2][1]) / s; 46 | return vec2(x, y); 47 | } 48 | 49 | // 50 | // Functions 51 | // 52 | void main() 53 | { 54 | vec2 uv = (Transform(UV, g_invHomography) * g_uvTransform.xy + g_uvTransform.zw); 55 | 56 | vec4 texColor = texture(Texture0, uv); 57 | 58 | FragColor = ((texColor * Color) + g_colorAdd); 59 | } 60 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/quad_warp.vert: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2023 Ryo Suzuki. 2 | // Copyright (c) 2016-2023 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // VSInput 9 | // 10 | layout(location = 0) in vec2 VertexPosition; 11 | layout(location = 1) in vec2 VertexUV; 12 | layout(location = 2) in vec4 VertexColor; 13 | 14 | // 15 | // VSOutput 16 | // 17 | layout(location = 0) out vec4 Color; 18 | layout(location = 1) out vec2 UV; 19 | out gl_PerVertex 20 | { 21 | vec4 gl_Position; 22 | }; 23 | 24 | // 25 | // Siv3D Functions 26 | // 27 | vec4 s3d_Transform2D(const vec2 pos, const vec4 t[2]) 28 | { 29 | return vec4(t[0].zw + (pos.x * t[0].xy) + (pos.y * t[1].xy), t[1].zw); 30 | } 31 | 32 | // 33 | // Constant Buffer 34 | // 35 | layout(std140) uniform VSConstants2D 36 | { 37 | vec4 g_transform[2]; 38 | vec4 g_colorMul; 39 | }; 40 | 41 | layout(std140) uniform VSQuadWarp 42 | { 43 | mat3x3 g_homography; 44 | }; 45 | 46 | vec2 Transform(vec2 pos, mat3x3 mat) 47 | { 48 | float s = (mat[0][2] * pos.x + mat[1][2] * pos.y + mat[2][2]); 49 | float x = (mat[0][0] * pos.x + mat[1][0] * pos.y + mat[2][0]) / s; 50 | float y = (mat[0][1] * pos.x + mat[1][1] * pos.y + mat[2][1]) / s; 51 | return vec2(x, y); 52 | } 53 | 54 | // 55 | // Functions 56 | // 57 | void main() 58 | { 59 | vec2 position = Transform(VertexPosition, g_homography); 60 | 61 | gl_Position = s3d_Transform2D(position, g_transform); 62 | 63 | Color = (VertexColor * g_colorMul); 64 | 65 | UV = position; 66 | } 67 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/round_dot.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // PSInput 9 | // 10 | layout(location = 0) in vec4 Color; 11 | layout(location = 1) in vec2 UV; 12 | 13 | // 14 | // PSOutput 15 | // 16 | layout(location = 0) out vec4 FragColor; 17 | 18 | // 19 | // Constant Buffer 20 | // 21 | layout(std140) uniform PSConstants2D 22 | { 23 | vec4 g_colorAdd; 24 | vec4 g_sdfParam; 25 | vec4 g_sdfOutlineColor; 26 | vec4 g_sdfShadowColor; 27 | vec4 g_internal; 28 | }; 29 | 30 | // 31 | // Functions 32 | // 33 | void main() 34 | { 35 | float t = mod(UV.x, 2.0); 36 | vec2 tex = UV; 37 | tex.x = abs(1 - t) * 2.0; 38 | vec4 color = Color; 39 | 40 | float dist = dot(tex, tex) * 0.5; 41 | float delta = fwidth(dist); 42 | float alpha = smoothstep(0.5 - delta, 0.5, dist); 43 | color.a *= 1.0 - alpha; 44 | 45 | FragColor = (color + g_colorAdd); 46 | } 47 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/sdffont.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec4 g_internal; 33 | }; 34 | 35 | // 36 | // Functions 37 | // 38 | void main() 39 | { 40 | float d = texture(Texture0, UV).a; 41 | 42 | float td = (d - 0.5); 43 | float textAlpha = clamp(td / fwidth(td) + 0.5, 0.0, 1.0); 44 | 45 | vec4 color = vec4(Color.rgb, Color.a * textAlpha); 46 | 47 | FragColor = (color + g_colorAdd); 48 | } 49 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/sdffont_outline.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec4 g_internal; 33 | }; 34 | 35 | // 36 | // Functions 37 | // 38 | void main() 39 | { 40 | float d = texture(Texture0, UV).a; 41 | 42 | float od = (d - g_sdfParam.y); 43 | float outlineAlpha = clamp(od / fwidth(od) + 0.5, 0.0, 1.0); 44 | 45 | float td = (d - g_sdfParam.x); 46 | float textAlpha = clamp(td / fwidth(td) + 0.5, 0.0, 1.0); 47 | 48 | float baseAlpha = (outlineAlpha - textAlpha); 49 | 50 | vec4 color; 51 | color.rgb = mix(g_sdfOutlineColor.rgb, Color.rgb, textAlpha); 52 | color.a = baseAlpha * g_sdfOutlineColor.a + textAlpha * Color.a; 53 | 54 | FragColor = (color + g_colorAdd); 55 | } 56 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/sdffont_outlineshadow.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec4 g_internal; 33 | }; 34 | 35 | // 36 | // Functions 37 | // 38 | void main() 39 | { 40 | float d = texture(Texture0, UV).a; 41 | 42 | float od = (d - g_sdfParam.y); 43 | float outlineAlpha = clamp(od / fwidth(od) + 0.5, 0.0, 1.0); 44 | 45 | float td = (d - g_sdfParam.x); 46 | float textAlpha = clamp(td / fwidth(td) + 0.5, 0.0, 1.0); 47 | 48 | float baseAlpha = (outlineAlpha - textAlpha); 49 | 50 | vec4 textColor; 51 | textColor.rgb = mix(g_sdfOutlineColor.rgb, Color.rgb, textAlpha); 52 | textColor.a = baseAlpha * g_sdfOutlineColor.a + textAlpha * Color.a; 53 | 54 | 55 | vec2 size = textureSize(Texture0, 0); 56 | vec2 shadowOffset = (g_sdfParam.zw / size); 57 | float d2 = texture(Texture0, UV - shadowOffset).a; 58 | 59 | float sd = (d2 - g_sdfParam.y); 60 | float shadowAlpha = clamp(sd / fwidth(sd) + 0.5, 0.0, 1.0); 61 | float sBase = shadowAlpha * (1.0 - textColor.a); 62 | 63 | vec4 color; 64 | if (textColor.a == 0.0) 65 | { 66 | color.rgb = g_sdfShadowColor.rgb; 67 | } 68 | else 69 | { 70 | color.rgb = mix(textColor.rgb, g_sdfShadowColor.rgb, sBase); 71 | } 72 | color.a = (sBase * g_sdfShadowColor.a) + textColor.a; 73 | 74 | FragColor = (color + g_colorAdd); 75 | } 76 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/sdffont_shadow.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec4 g_internal; 33 | }; 34 | 35 | // 36 | // Functions 37 | // 38 | void main() 39 | { 40 | float d = texture(Texture0, UV).a; 41 | 42 | float td = (d - 0.5); 43 | float textAlpha = clamp(td / fwidth(td) + 0.5, 0.0, 1.0); 44 | 45 | vec2 size = textureSize(Texture0, 0); 46 | vec2 shadowOffset = (g_sdfParam.zw / size); 47 | float d2 = texture(Texture0, UV - shadowOffset).a; 48 | 49 | float sd = (d2 - 0.5); 50 | float shadowAlpha = clamp(sd / fwidth(sd) + 0.5, 0.0, 1.0); 51 | float sBase = shadowAlpha * (1.0 - textAlpha); 52 | 53 | vec4 color; 54 | if (textAlpha == 0.0) 55 | { 56 | color.rgb = g_sdfShadowColor.rgb; 57 | } 58 | else 59 | { 60 | color.rgb = mix(Color.rgb, g_sdfShadowColor.rgb, sBase); 61 | } 62 | color.a = (sBase * g_sdfShadowColor.a) + (textAlpha * Color.a); 63 | 64 | FragColor = (color + g_colorAdd); 65 | } 66 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/shape.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // PSInput 9 | // 10 | layout(location = 0) in vec4 Color; 11 | 12 | // 13 | // PSOutput 14 | // 15 | layout(location = 0) out vec4 FragColor; 16 | 17 | // 18 | // Constant Buffer 19 | // 20 | layout(std140) uniform PSConstants2D 21 | { 22 | vec4 g_colorAdd; 23 | vec4 g_sdfParam; 24 | vec4 g_sdfOutlineColor; 25 | vec4 g_sdfShadowColor; 26 | vec4 g_internal; 27 | }; 28 | 29 | // 30 | // Functions 31 | // 32 | void main() 33 | { 34 | FragColor = (Color + g_colorAdd); 35 | } 36 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/sprite.vert: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // VSInput 9 | // 10 | layout(location = 0) in vec2 VertexPosition; 11 | layout(location = 1) in vec2 VertexUV; 12 | layout(location = 2) in vec4 VertexColor; 13 | 14 | // 15 | // VSOutput 16 | // 17 | layout(location = 0) out vec4 Color; 18 | layout(location = 1) out vec2 UV; 19 | out gl_PerVertex 20 | { 21 | vec4 gl_Position; 22 | }; 23 | 24 | // 25 | // Siv3D Functions 26 | // 27 | vec4 s3d_Transform2D(const vec2 pos, const vec4 t[2]) 28 | { 29 | return vec4(t[0].zw + (pos.x * t[0].xy) + (pos.y * t[1].xy), t[1].zw); 30 | } 31 | 32 | // 33 | // Constant Buffer 34 | // 35 | layout(std140) uniform VSConstants2D 36 | { 37 | vec4 g_transform[2]; 38 | vec4 g_colorMul; 39 | }; 40 | 41 | // 42 | // Functions 43 | // 44 | void main() 45 | { 46 | gl_Position = s3d_Transform2D(VertexPosition, g_transform); 47 | 48 | Color = (VertexColor * g_colorMul); 49 | 50 | UV = VertexUV; 51 | } 52 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/square_dot.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // PSInput 9 | // 10 | layout(location = 0) in vec4 Color; 11 | layout(location = 1) in vec2 UV; 12 | 13 | // 14 | // PSOutput 15 | // 16 | layout(location = 0) out vec4 FragColor; 17 | 18 | // 19 | // Constant Buffer 20 | // 21 | layout(std140) uniform PSConstants2D 22 | { 23 | vec4 g_colorAdd; 24 | vec4 g_sdfParam; 25 | vec4 g_sdfOutlineColor; 26 | vec4 g_sdfShadowColor; 27 | vec4 g_internal; 28 | }; 29 | 30 | // 31 | // Functions 32 | // 33 | void main() 34 | { 35 | float tr = UV.y; 36 | float d = abs(mod(UV.x, 3.0) - 1.0); 37 | float range = 1.0 - tr; 38 | vec4 color = Color; 39 | color.a *= (d < range) ? 1.0 : (d < 1.0) ? ((1.0 - d) / tr) : 0.0; 40 | 41 | FragColor = (color + g_colorAdd); 42 | } 43 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/shader/glsl/texture.frag: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2022 Ryo Suzuki. 2 | // Copyright (c) 2016-2022 OpenSiv3D Project. 3 | // Licensed under the MIT License. 4 | 5 | # version 410 6 | 7 | // 8 | // Textures 9 | // 10 | uniform sampler2D Texture0; 11 | 12 | // 13 | // PSInput 14 | // 15 | layout(location = 0) in vec4 Color; 16 | layout(location = 1) in vec2 UV; 17 | 18 | // 19 | // PSOutput 20 | // 21 | layout(location = 0) out vec4 FragColor; 22 | 23 | // 24 | // Constant Buffer 25 | // 26 | layout(std140) uniform PSConstants2D 27 | { 28 | vec4 g_colorAdd; 29 | vec4 g_sdfParam; 30 | vec4 g_sdfOutlineColor; 31 | vec4 g_sdfShadowColor; 32 | vec4 g_internal; 33 | }; 34 | 35 | // 36 | // Functions 37 | // 38 | void main() 39 | { 40 | vec4 texColor = texture(Texture0, UV); 41 | 42 | FragColor = ((texColor * Color) + g_colorAdd); 43 | } 44 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/texture/box-shadow/128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/texture/box-shadow/128.png -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/texture/box-shadow/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/texture/box-shadow/16.png -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/texture/box-shadow/256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/texture/box-shadow/256.png -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/texture/box-shadow/32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/texture/box-shadow/32.png -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/texture/box-shadow/64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/texture/box-shadow/64.png -------------------------------------------------------------------------------- /tests/CoTaskLibTests/resources/engine/texture/box-shadow/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m4saka/CoTaskLib/4f4f328abbac2af23e927eac647f1339b62faac0/tests/CoTaskLibTests/resources/engine/texture/box-shadow/8.png -------------------------------------------------------------------------------- /tests/CoTaskLibTests/stdafx.cpp: -------------------------------------------------------------------------------- 1 | # include "stdafx.h" 2 | -------------------------------------------------------------------------------- /tests/CoTaskLibTests/stdafx.h: -------------------------------------------------------------------------------- 1 | # pragma once 2 | //# define NO_S3D_USING 3 | # include 4 | --------------------------------------------------------------------------------