From 7671506333579dbba4cde89e74faec82b389464e Mon Sep 17 00:00:00 2001 From: wada Date: Tue, 26 Mar 2024 11:10:45 +0900 Subject: [PATCH] Update to Cubism 5 SDK for Native R1 --- CHANGELOG.md | 28 ++++ Core/CHANGELOG.md | 8 + Framework | 2 +- NOTICE.ja.md | 21 +++ NOTICE.md | 21 +++ README.ja.md | 36 +++-- README.md | 36 +++-- .../Cocos2d-x/Demo/Classes/AppDelegate.cpp | 2 +- .../Demo/Classes/LAppLive2DManager.cpp | 12 +- Samples/Cocos2d-x/Demo/Classes/LAppModel.cpp | 24 +-- Samples/Cocos2d-x/Demo/Classes/LAppPal.cpp | 19 ++- Samples/Cocos2d-x/Demo/Classes/LAppPal.hpp | 12 +- Samples/Cocos2d-x/Demo/Classes/LAppView.cpp | 6 +- .../Cocos2d-x/Demo/Classes/SampleScene.cpp | 6 +- .../src/CubismDirectXRenderer.cpp | 20 +-- .../proj.d3d11.cmake/src/CubismSprite.cpp | 4 +- .../src/CubismTextureManager.cpp | 2 +- .../proj.d3d11.cmake/src/LAppDelegate.cpp | 32 ++-- .../src/LAppLive2DManager.cpp | 12 +- .../Demo/proj.d3d11.cmake/src/LAppModel.cpp | 22 +-- .../Demo/proj.d3d11.cmake/src/LAppPal.cpp | 48 +++++- .../Demo/proj.d3d11.cmake/src/LAppPal.hpp | 32 ++++ .../Demo/proj.d3d11.cmake/src/LAppSprite.cpp | 101 ++----------- .../Demo/proj.d3d11.cmake/src/LAppSprite.hpp | 18 +-- .../src/LAppTextureManager.cpp | 2 +- .../Demo/proj.d3d11.cmake/src/LAppView.cpp | 65 +++++++-- .../Demo/proj.d3d11.cmake/src/mainMinimum.cpp | 12 +- .../src/CubismDirectXRenderer.cpp | 6 +- .../src/CubismTextureManager.cpp | 2 +- .../Demo/proj.d3d9.cmake/src/LAppDelegate.cpp | 14 +- .../proj.d3d9.cmake/src/LAppLive2DManager.cpp | 14 +- .../Demo/proj.d3d9.cmake/src/LAppModel.cpp | 22 +-- .../D3D9/Demo/proj.d3d9.cmake/src/LAppPal.cpp | 48 +++++- .../D3D9/Demo/proj.d3d9.cmake/src/LAppPal.hpp | 32 ++++ .../Demo/proj.d3d9.cmake/src/LAppSprite.cpp | 137 ++++-------------- .../Demo/proj.d3d9.cmake/src/LAppSprite.hpp | 23 ++- .../src/LAppTextureManager.cpp | 2 +- .../Demo/proj.d3d9.cmake/src/LAppView.cpp | 74 ++++++++-- .../Demo/proj.d3d9.cmake/src/mainMinimum.cpp | 8 +- .../Demo/proj.ios.cmake/src/AppDelegate.mm | 2 +- .../proj.ios.cmake/src/LAppLive2DManager.mm | 18 ++- .../Demo/proj.ios.cmake/src/LAppModel.mm | 22 +-- .../Metal/Demo/proj.ios.cmake/src/LAppPal.h | 12 +- .../Metal/Demo/proj.ios.cmake/src/LAppPal.mm | 18 ++- .../Demo/proj.ios.cmake/src/LAppSprite.h | 11 +- .../Demo/proj.ios.cmake/src/LAppSprite.mm | 18 +-- .../Demo/proj.ios.cmake/src/ViewController.mm | 19 ++- .../Full/app/src/main/cpp/LAppDelegate.cpp | 2 +- .../app/src/main/cpp/LAppLive2DManager.cpp | 12 +- .../Full/app/src/main/cpp/LAppModel.cpp | 22 +-- .../Full/app/src/main/cpp/LAppPal.cpp | 8 +- .../Full/app/src/main/cpp/LAppPal.hpp | 12 +- .../Full/app/src/main/cpp/LAppView.cpp | 11 +- .../java/com/live2d/demo/JniBridgeJava.java | 26 ++-- .../java/com/live2d/demo/MainActivity.java | 60 ++++---- .../proj.android.cmake/Full/gradle.properties | 6 +- .../app/src/main/cpp/LAppMinimumDelegate.cpp | 2 +- .../app/src/main/cpp/LAppMinimumModel.cpp | 14 +- .../app/src/main/cpp/LAppMinimumView.cpp | 17 ++- .../Minimum/app/src/main/cpp/LAppPal.cpp | 8 +- .../Minimum/app/src/main/cpp/LAppPal.hpp | 12 +- .../java/com/live2d/demo/JniBridgeJava.java | 25 ++-- .../java/com/live2d/demo/MainActivity.java | 60 ++++---- .../Minimum/gradle.properties | 6 +- .../Demo/proj.ios.cmake/src/AppDelegate.mm | 2 +- .../proj.ios.cmake/src/LAppLive2DManager.mm | 12 +- .../Demo/proj.ios.cmake/src/LAppModel.mm | 22 +-- .../OpenGL/Demo/proj.ios.cmake/src/LAppPal.h | 34 ++--- .../OpenGL/Demo/proj.ios.cmake/src/LAppPal.mm | 16 +- .../Demo/proj.ios.cmake/src/ViewController.mm | 2 +- .../proj.ios.cmake/src/minimum/MinLAppPal.mm | 8 + .../Demo/proj.linux.cmake/scripts/make_gcc | 3 +- .../proj.linux.cmake/src/LAppDelegate.cpp | 18 +-- .../proj.linux.cmake/src/LAppDelegate.hpp | 10 +- .../src/LAppLive2DManager.cpp | 18 +-- .../Demo/proj.linux.cmake/src/LAppModel.cpp | 22 +-- .../Demo/proj.linux.cmake/src/LAppPal.cpp | 41 +++++- .../Demo/proj.linux.cmake/src/LAppPal.hpp | 21 +++ .../Demo/proj.linux.cmake/src/LAppView.cpp | 4 +- .../Demo/proj.linux.cmake/src/mainMinimum.cpp | 24 +-- .../Demo/proj.mac.cmake/src/LAppDelegate.cpp | 20 +-- .../Demo/proj.mac.cmake/src/LAppDelegate.hpp | 10 +- .../proj.mac.cmake/src/LAppLive2DManager.cpp | 16 +- .../Demo/proj.mac.cmake/src/LAppModel.cpp | 22 +-- .../Demo/proj.mac.cmake/src/LAppPal.cpp | 32 +++- .../Demo/proj.mac.cmake/src/LAppPal.hpp | 12 +- .../Demo/proj.mac.cmake/src/LAppView.cpp | 11 +- .../Demo/proj.mac.cmake/src/mainMinimum.cpp | 26 ++-- .../Demo/proj.win.cmake/src/LAppDelegate.cpp | 8 +- .../proj.win.cmake/src/LAppLive2DManager.cpp | 12 +- .../Demo/proj.win.cmake/src/LAppModel.cpp | 22 +-- .../Demo/proj.win.cmake/src/LAppPal.cpp | 45 +++++- .../Demo/proj.win.cmake/src/LAppPal.hpp | 21 +++ .../Demo/proj.win.cmake/src/LAppView.cpp | 9 +- .../Demo/proj.win.cmake/src/mainMinimum.cpp | 8 +- Samples/OpenGL/README.ja.md | 4 +- Samples/OpenGL/README.md | 4 +- .../OpenGL/thirdParty/scripts/setup_glew_glfw | 2 +- .../thirdParty/scripts/setup_glew_glfw.bat | 2 +- .../scripts/setup_glew_glfw_vs2013.bat | 4 +- .../Vulkan/Demo/proj.win.cmake/CMakeLists.txt | 4 +- .../Demo/proj.win.cmake/src/LAppDelegate.cpp | 6 +- .../proj.win.cmake/src/LAppLive2DManager.cpp | 12 +- .../Demo/proj.win.cmake/src/LAppModel.cpp | 22 +-- .../Demo/proj.win.cmake/src/LAppPal.cpp | 44 +++++- .../Demo/proj.win.cmake/src/LAppPal.hpp | 21 +++ .../Demo/proj.win.cmake/src/LAppSprite.cpp | 48 +++--- .../Demo/proj.win.cmake/src/LAppSprite.hpp | 40 ++++- .../proj.win.cmake/src/LAppTextureManager.cpp | 2 +- .../Demo/proj.win.cmake/src/LAppView.cpp | 55 ++++--- .../proj.win.cmake/src/SwapchainManager.cpp | 4 +- .../Demo/proj.win.cmake/src/VulkanManager.cpp | 20 +-- Samples/Vulkan/README.ja.md | 4 +- Samples/Vulkan/README.md | 4 +- Samples/Vulkan/Shaders/CMakeLists.txt | 6 +- 115 files changed, 1332 insertions(+), 915 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 993366d8..e82bc5fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,32 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [5-r.1] - 2024-03-26 + +### Added + +* Add x86_64 architecture to target platforms in Android. + +### Changed + +* Rename "rootDirectory" to "executeAbsolutePath". +* The log function was changed because it was ambiguous whether or not a newline was inserted. +* Change so that `LAppSprite` is not depend on `LAppDelegate` in D3D11 and D3D9, Metal, Vulkan. +* Some function arguments in `LAppSprite` are changed in D3D11 and D3D9, Metal, Vulkan. + +### Fixed + +* Fixed undefined behavior and memory leak in `LAppPal`. +* Modify code to more closely resemble Java coding style. +* Fix model drawing disappearing when defining `USE_RENDER_TARGET` and `USE_MODEL_RENDER_TARGET`. +* Fix an issue where the OpenGL sample for Visual Studio 2013 was not functioning correctly. +* Fix shader build error when running nmake in Vulkan. + +### Removed + +* Remove unnecessary pre-API 21 processing. + + ## [5-r.1-beta.4] - 2024-01-25 ### Added @@ -32,6 +58,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). * Fix an issue that caused incorrect selection of depth format in Vulkan. * Fix errors that occurs when building with x86 in vulkan. + ## [5-r.1-beta.3] - 2023-10-12 ### Added @@ -380,6 +407,7 @@ See [Core Changelog] for details. * What was `Package.json` is currently being changed to`cubism-info.yml`. +[5-r.1]: https://github.com/Live2D/CubismNativeSamples/compare/5-r.1-beta.4...5-r.1 [5-r.1-beta.4]: https://github.com/Live2D/CubismNativeSamples/compare/5-r.1-beta.3...5-r.1-beta.4 [5-r.1-beta.3]: https://github.com/Live2D/CubismNativeSamples/compare/5-r.1-beta.2...5-r.1-beta.3 [5-r.1-beta.2]: https://github.com/Live2D/CubismNativeSamples/compare/5-r.1-beta.1...5-r.1-beta.2 diff --git a/Core/CHANGELOG.md b/Core/CHANGELOG.md index 0d7a4a18..afe4260c 100644 --- a/Core/CHANGELOG.md +++ b/Core/CHANGELOG.md @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## 2024-03-26 + +### Remove + +* [Unity] Remove built with Emscripten 1.38.48. + * Unity 2021.2 or later uses only Core under `Assets/Live2D/Cubism/Plugins/Experimental/Emscripten/latest`. + + ## 2023-09-28 ### Remove diff --git a/Framework b/Framework index bebb8e04..3d9f82a4 160000 --- a/Framework +++ b/Framework @@ -1 +1 @@ -Subproject commit bebb8e041af1b41ccb89e93dd048666f29eb048c +Subproject commit 3d9f82a47f3f9c8c89ae692703f2dad79296b61a diff --git a/NOTICE.ja.md b/NOTICE.ja.md index 148ff458..2bc598e6 100644 --- a/NOTICE.ja.md +++ b/NOTICE.ja.md @@ -4,6 +4,27 @@ # お知らせ +## [注意事項] Apple社のPrivacy Manifest Policy対応について + +Apple社が対応を必要としているPrivacy Manifest Policyについて、本製品では指定されているAPI及びサードパーティ製品を使用しておりません。 +もし本製品で対応が必要と判断した場合、今後のアップデートにて順次対応する予定です。 +詳しくはApple社が公開しているドキュメントをご確認ください。 + +* [Privacy updates for App Store submissions](https://developer.apple.com/news/?id=3d8a9yyh) + + +## [注意事項] Linux OpenGL環境でのWaylandのサポートについて (2024-03-26) + +本製品がLinux OpenGL環境で利用している `GLFW 3.4` が、Wayland向けにコンパイルできるようになりました。 +しかし、 `GLEW 2.2.0` では現在Wayland(EGL)向けのコンパイルを行うと `glewInit` が正常に動作しない状態であるため、本サンプルはWaylandに対応しておりません。 + +Linux OpenGL環境をご利用の方は、引き続き通常通りX11向けビルドをご利用ください。 + +詳しくは以下のissueを参照ください。 + +* [GLEW issue](https://github.com/nigels-com/glew/issues/172) + + ## [注意事項] Metal の Mac Catalyst のビルドエラーについて (2024-01-25) MetalのMac Catalystのビルド時にエラーが発生する場合がございます。 diff --git a/NOTICE.md b/NOTICE.md index c6a50f27..36f2b7e6 100644 --- a/NOTICE.md +++ b/NOTICE.md @@ -4,6 +4,27 @@ # Notices +## [Caution] Support for Apple's Privacy Manifest Policy + +This product does not use the APIs or third-party products specified in Apple's privacy manifest policy. +This will be addressed in future updates if this product requires such support. +Please check the documentation published by Apple for details. + +* [Privacy updates for App Store submissions](https://developer.apple.com/news/?id=3d8a9yyh) + + +## [Caution] Support for Wayland in Linux OpenGL Environment (2024-03-26) + +`GLFW 3.4`, which this product uses in the Linux OpenGL environment, can now be compiled for Wayland. +However, this sample is not compatible with Wayland because `glewInit` is currently not working properly when compiling for Wayland (EGL) in `GLEW 2.2.0`. + +If you are using the Linux OpenGL environment, please continue to use the X11 build as usual. + +Please refer to the issue below for details. + +* [GLEW issue](https://github.com/nigels-com/glew/issues/172) + + ## [Caution] Mac Catalyst build error for Metal (2024-01-25) There is an error when building Mac Catalyst for Metal. diff --git a/README.ja.md b/README.ja.md index e9f94840..0143fc25 100644 --- a/README.ja.md +++ b/README.ja.md @@ -100,27 +100,31 @@ Demo ## 変更履歴 -当リポジトリの変更履歴については [CHANGELOG.md](CHANGELOG.md) を参照ください。 +Samples : [CHANGELOG.md](CHANGELOG.md) + +Framework : [CHANGELOG.md](Framework/CHANGELOG.md) + +Core : [CHANGELOG.md](Core/CHANGELOG.md) ## 開発環境 | 開発ツール | バージョン | | --- | --- | -| Android Studio | Hedgehog 2023.1.1 | -| CMake | 3.28.1 | +| Android Studio | Iguana 2023.2.1 | +| CMake | 3.28.3 | | Visual Studio 2013 | Update 5 | | Visual Studio 2015 | Update 3 | -| Visual Studio 2017 | 15.9.59 | -| Visual Studio 2019 | 16.11.33 | -| Visual Studio 2022 | 17.8.4 | -| Xcode | 15.1 | +| Visual Studio 2017 | 15.9.60 | +| Visual Studio 2019 | 16.11.34 | +| Visual Studio 2022 | 17.9.4 | +| Xcode | 15.3 | ### Android | Android SDK tools | バージョン | | --- | --- | -| Android NDK | 25.2.9519653 | +| Android NDK | 26.2.11394342 | | Android SDK | 34.0.0 | | CMake | 3.22.1 | @@ -131,9 +135,10 @@ Demo | Red Hat | Amazon Linux 2 | `amazonlinux:2` | 7.3.1 | | Red Hat | CentOS 7 | `centos:7` | 4.8.5 | | Red Hat | CentOS Stream 8 *1 | `centos:latest` | 8.5.0 | -| Red Hat | CentOS Stream 9 | - | 11.3.1 | +| Red Hat | CentOS Stream 9 | - | 12.2.1 | +| Red Hat | AlmaLinux | `almalinux:latest` | 11.4.1 | | Debian | Ubuntu 18.04 | `ubuntu:18.04` | 7.5.0 | -| Debian | Ubuntu 22.04.3 | `ubuntu:22.04.3` | 11.3.0 | +| Debian | Ubuntu 22.04.4 | `ubuntu:22.04` | 11.4.0 | *1 CentOS 8はサポートしておりません @@ -151,8 +156,8 @@ Demo | プラットフォーム | バージョン | | --- | --- | -| iOS / iPadOS | 16.6.1 | -| macOS | 14.1.1 | +| iOS / iPadOS | 17.4 | +| macOS | 14.4 | | Windows 10 | 22H2 | | Windows 11 | 22H2 | @@ -168,9 +173,8 @@ Demo | 系統 | ディストリビューション | バージョン | | --- | --- | --- | | Red Hat | Amazon Linux | 2 | -| Red Hat | CentOS Stream | 8 | -| Red Hat | CentOS Stream | 9 | -| Debian | Ubuntu | 22.04.3 | +| Red Hat | AlmaLinux | 9 | +| Debian | Ubuntu | 22.04.4 | ## プロジェクトへの貢献 @@ -178,7 +182,7 @@ Demo ### フォークとプルリクエスト -修正、改善、さらには新機能をもたらすかどうかにかかわらず、プルリクエストに感謝します。ただし、ラッパーは可能な限り軽量で浅くなるように設計されているため、バグ修正とメモリ/パフォーマンスの改善のみを行う必要があることに注意してください。メインリポジトリを可能な限りクリーンに保つために、必要に応じて個人用フォークと機能ブランチを作成してください。 +修正、改善、さらには新機能をもたらすかどうかにかかわらず、プルリクエストに感謝します。メインリポジトリを可能な限りクリーンに保つために、必要に応じて個人用フォークと機能ブランチを作成してください。 ### バグ diff --git a/README.md b/README.md index f6a49f54..f047544b 100644 --- a/README.md +++ b/README.md @@ -99,27 +99,31 @@ Please refer to 'LAppLive2DManager.cpp' in the sample directory for details. ## Changelog -Please refer to [CHANGELOG.md](CHANGELOG.md) for the changelog of this repository. +Samples : [CHANGELOG.md](CHANGELOG.md) + +Framework : [CHANGELOG.md](Framework/CHANGELOG.md) + +Core : [CHANGELOG.md](Core/CHANGELOG.md) ## Development environment | Development Tool | Version | | --- | --- | -| Android Studio | Hedgehog 2023.1.1 | -| CMake | 3.28.1 | +| Android Studio | Iguana 2023.2.1 | +| CMake | 3.28.3 | | Visual Studio 2013 | Update 5 | | Visual Studio 2015 | Update 3 | -| Visual Studio 2017 | 15.9.59 | -| Visual Studio 2019 | 16.11.33 | -| Visual Studio 2022 | 17.8.4 | -| Xcode | 15.1 | +| Visual Studio 2017 | 15.9.60 | +| Visual Studio 2019 | 16.11.34 | +| Visual Studio 2022 | 17.9.4 | +| Xcode | 15.3 | ### Android | Android SDK tools | Version | | --- | --- | -| Android NDK | 25.2.9519653 | +| Android NDK | 26.2.11394342 | | Android SDK | 34.0.0 | | CMake | 3.22.1 | @@ -130,9 +134,10 @@ Please refer to [CHANGELOG.md](CHANGELOG.md) for the changelog of this repositor | Red Hat | Amazon Linux 2 | `amazonlinux:2` | 7.3.1 | | Red Hat | CentOS 7 | `centos:7` | 4.8.5 | | Red Hat | CentOS Stream 8 *1 | `centos:latest` | 8.5.0 | -| Red Hat | CentOS Stream 9 | - | 11.3.1 | +| Red Hat | CentOS Stream 9 | - | 12.2.1 | +| Red Hat | AlmaLinux | `almalinux:latest` | 11.4.1 | | Debian | Ubuntu 18.04 | `ubuntu:18.04` | 7.5.0 | -| Debian | Ubuntu 22.04.3 | `ubuntu:22.04.3` | 11.3.0 | +| Debian | Ubuntu 22.04.4 | `ubuntu:22.04` | 11.4.0 | *1 CentOS 8 is not supported @@ -150,8 +155,8 @@ Please refer to [CHANGELOG.md](CHANGELOG.md) for the changelog of this repositor | Platform | Version | | --- | --- | -| iOS / iPadOS | 16.6.1 | -| macOS | 14.1.1 | +| iOS / iPadOS | 17.4 | +| macOS | 14.4 | | Windows 10 | 22H2 | | Windows 11 | 22H2 | @@ -167,9 +172,8 @@ Please refer to [CHANGELOG.md](CHANGELOG.md) for the changelog of this repositor | System | Distribution | Version | | --- | --- | --- | | Red Hat | Amazon Linux | 2 | -| Red Hat | CentOS Stream | 8 | -| Red Hat | CentOS Stream | 9 | -| Debian | Ubuntu | 22.04.3 | +| Red Hat | AlmaLinux | 9 | +| Debian | Ubuntu | 22.04.4 | ## Contributing @@ -177,7 +181,7 @@ There are many ways to contribute to the project: logging bugs, submitting pull ### Forking And Pull Requests -We very much appreciate your pull requests, whether they bring fixes, improvements, or even new features. Note, however, that the wrapper is designed to be as lightweight and shallow as possible and should therefore only be subject to bug fixes and memory/performance improvements. To keep the main repository as clean as possible, create a personal fork and feature branches there as needed. +We very much appreciate your pull requests, whether they bring fixes, improvements, or even new features. To keep the main repository as clean as possible, create a personal fork and feature branches there as needed. ### Bugs diff --git a/Samples/Cocos2d-x/Demo/Classes/AppDelegate.cpp b/Samples/Cocos2d-x/Demo/Classes/AppDelegate.cpp index ce16d213..175b72c1 100644 --- a/Samples/Cocos2d-x/Demo/Classes/AppDelegate.cpp +++ b/Samples/Cocos2d-x/Demo/Classes/AppDelegate.cpp @@ -107,7 +107,7 @@ bool AppDelegate::applicationDidFinishLaunching() register_all_packages(); // prepare for Cubism Framework API. - _cubismOption.LogFunction = LAppPal::PrintMessage; + _cubismOption.LogFunction = LAppPal::PrintMessageLn; _cubismOption.LoggingLevel = LAppDefine::CubismLoggingLevel; Csm::CubismFramework::StartUp(&_cubismAllocator, &_cubismOption); diff --git a/Samples/Cocos2d-x/Demo/Classes/LAppLive2DManager.cpp b/Samples/Cocos2d-x/Demo/Classes/LAppLive2DManager.cpp index b0a55a89..c2d0f9db 100644 --- a/Samples/Cocos2d-x/Demo/Classes/LAppLive2DManager.cpp +++ b/Samples/Cocos2d-x/Demo/Classes/LAppLive2DManager.cpp @@ -41,7 +41,7 @@ namespace { void FinishedMotion(ACubismMotion* self) { - LAppPal::PrintLog("Motion Finished: %x", self); + LAppPal::PrintLogLn("Motion Finished: %x", self); } int CompareCsmString(const void* a, const void* b) @@ -188,18 +188,18 @@ void LAppLive2DManager::OnDrag(csmFloat32 x, csmFloat32 y) const void LAppLive2DManager::OnTap(csmFloat32 x, csmFloat32 y) { - if (DebugLogEnable) LAppPal::PrintLog("[APP]tap point: {x:%.2f y:%.2f}", x, y); + if (DebugLogEnable) LAppPal::PrintLogLn("[APP]tap point: {x:%.2f y:%.2f}", x, y); for (csmUint32 i = 0; i < _models.GetSize(); i++) { if (_models[i]->HitTest(HitAreaNameHead, x, y)) { - if (DebugLogEnable) LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameHead); + if (DebugLogEnable) LAppPal::PrintLogLn("[APP]hit area: [%s]", HitAreaNameHead); _models[i]->SetRandomExpression(); } else if (_models[i]->HitTest(HitAreaNameBody, x, y)) { - if (DebugLogEnable) LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameBody); + if (DebugLogEnable) LAppPal::PrintLogLn("[APP]hit area: [%s]", HitAreaNameBody); _models[i]->StartRandomMotion(MotionGroupTapBody, PriorityNormal, FinishedMotion); } } @@ -219,7 +219,7 @@ void LAppLive2DManager::OnUpdate(Csm::Rendering::CubismCommandBuffer_Cocos2dx* c if (model->GetModel() == NULL) { - LAppPal::PrintLog("Failed to model->GetModel()."); + LAppPal::PrintLogLn("Failed to model->GetModel()."); continue; } @@ -294,7 +294,7 @@ void LAppLive2DManager::NextScene() void LAppLive2DManager::ChangeScene(Csm::csmInt32 index) { _sceneIndex = index; - if (DebugLogEnable) LAppPal::PrintLog("[APP]model index: %d", _sceneIndex); + if (DebugLogEnable) LAppPal::PrintLogLn("[APP]model index: %d", _sceneIndex); // ModelDir[]に保持したディレクトリ名から // model3.jsonのパスを決定する. diff --git a/Samples/Cocos2d-x/Demo/Classes/LAppModel.cpp b/Samples/Cocos2d-x/Demo/Classes/LAppModel.cpp index a6280115..73c89923 100644 --- a/Samples/Cocos2d-x/Demo/Classes/LAppModel.cpp +++ b/Samples/Cocos2d-x/Demo/Classes/LAppModel.cpp @@ -44,13 +44,13 @@ USING_NS_CC; namespace { csmByte* CreateBuffer(const csmChar* path, csmSizeInt* size) { - if (DebugLogEnable)LAppPal::PrintLog("[APP]create buffer: %s ", path); + if (DebugLogEnable)LAppPal::PrintLogLn("[APP]create buffer: %s ", path); return LAppPal::LoadFileAsBytes(path, size); } void DeleteBuffer(csmByte* buffer, const csmChar* path = "") { - if (DebugLogEnable) LAppPal::PrintLog("[APP]delete buffer: %s", path); + if (DebugLogEnable) LAppPal::PrintLogLn("[APP]delete buffer: %s", path); LAppPal::ReleaseBytes(buffer); } } @@ -91,7 +91,7 @@ LAppModel::LAppModel() LAppModel::~LAppModel() { - if (_debugMode)LAppPal::PrintLog("[APP]delete model: %s", _modelSetting->GetModelFileName()); + if (_debugMode)LAppPal::PrintLogLn("[APP]delete model: %s", _modelSetting->GetModelFileName()); if (_renderSprite) { @@ -124,7 +124,7 @@ void LAppModel::LoadAssets(const csmChar* dir, const csmChar* fileName) { _modelHomeDir = dir; - if (_debugMode)LAppPal::PrintLog("[APP]load model setting: %s", fileName); + if (_debugMode)LAppPal::PrintLogLn("[APP]load model setting: %s", fileName); csmSizeInt size; const csmString path = csmString(dir) + fileName; @@ -137,7 +137,7 @@ void LAppModel::LoadAssets(const csmChar* dir, const csmChar* fileName) if (_model == NULL) { - LAppPal::PrintLog("Failed to LoadAssets()."); + LAppPal::PrintLogLn("Failed to LoadAssets()."); return; } @@ -163,7 +163,7 @@ void LAppModel::SetupModel(ICubismModelSetting* setting) csmString path = _modelSetting->GetModelFileName(); path = _modelHomeDir + path; - if (_debugMode)LAppPal::PrintLog("[APP]create model: %s", setting->GetModelFileName()); + if (_debugMode)LAppPal::PrintLogLn("[APP]create model: %s", setting->GetModelFileName()); buffer = CreateBuffer(path.GetRawString(), &size); LoadModel(buffer, size, _mocConsistency); @@ -271,7 +271,7 @@ void LAppModel::SetupModel(ICubismModelSetting* setting) if (_modelSetting == NULL || _modelMatrix == NULL) { - LAppPal::PrintLog("Failed to SetupModel()."); + LAppPal::PrintLogLn("Failed to SetupModel()."); return; } @@ -305,7 +305,7 @@ void LAppModel::PreloadMotionGroup(const csmChar* group) csmString path = _modelSetting->GetMotionFileName(group, i); path = _modelHomeDir + path; - if (_debugMode)LAppPal::PrintLog("[APP]load motion: %s => [%s_%d] ", path.GetRawString(), group, i); + if (_debugMode)LAppPal::PrintLogLn("[APP]load motion: %s => [%s_%d] ", path.GetRawString(), group, i); csmByte* buffer; csmSizeInt size; @@ -499,7 +499,7 @@ CubismMotionQueueEntryHandle LAppModel::StartMotion(const csmChar* group, csmInt } else if (!_motionManager->ReserveMotion(priority)) { - if (_debugMode) LAppPal::PrintLog("[APP]can't start motion."); + if (_debugMode) LAppPal::PrintLogLn("[APP]can't start motion."); return InvalidMotionQueueEntryHandleValue; } @@ -557,7 +557,7 @@ CubismMotionQueueEntryHandle LAppModel::StartMotion(const csmChar* group, csmInt #endif } - if (_debugMode)LAppPal::PrintLog("[APP]start motion: [%s_%d]", group, no); + if (_debugMode)LAppPal::PrintLogLn("[APP]start motion: [%s_%d]", group, no); return _motionManager->StartMotionPriority(motion, autoDelete, priority); } @@ -626,14 +626,14 @@ csmBool LAppModel::HitTest(const csmChar* hitAreaName, csmFloat32 x, csmFloat32 void LAppModel::SetExpression(const csmChar* expressionID) { ACubismMotion* motion = _expressions[expressionID]; - if (_debugMode) LAppPal::PrintLog("[APP]expression: [%s]", expressionID); + if (_debugMode) LAppPal::PrintLogLn("[APP]expression: [%s]", expressionID); if (motion != NULL) { _expressionManager->StartMotionPriority(motion, false, PriorityForce); } else { - if (_debugMode) LAppPal::PrintLog("[APP]expression[%s] is null ", expressionID); + if (_debugMode) LAppPal::PrintLogLn("[APP]expression[%s] is null ", expressionID); } } diff --git a/Samples/Cocos2d-x/Demo/Classes/LAppPal.cpp b/Samples/Cocos2d-x/Demo/Classes/LAppPal.cpp index 053a618a..00d466b4 100644 --- a/Samples/Cocos2d-x/Demo/Classes/LAppPal.cpp +++ b/Samples/Cocos2d-x/Demo/Classes/LAppPal.cpp @@ -8,6 +8,7 @@ #include "LAppPal.hpp" #include #include "cocos2d.h" +#include "LAppDefine.hpp" using namespace Csm; USING_NS_CC; @@ -16,6 +17,16 @@ csmByte* LAppPal::LoadFileAsBytes(const csmChar* filePath, csmSizeInt* outSize) { ssize_t size = 0; csmByte* buf = FileUtils::getInstance()->getDataFromFile(filePath).takeBuffer(&size); + + if (buf == NULL) + { + if (LAppDefine::DebugLogEnable) + { + PrintLogLn("File load failed : %s", filePath); + } + return NULL; + } + *outSize = static_cast(size); return buf; } @@ -34,17 +45,17 @@ csmFloat32 LAppPal::GetDeltaTime() return 0.0f; } -void LAppPal::PrintLog(const csmChar* format, ...) +void LAppPal::PrintLogLn(const csmChar* format, ...) { va_list args; csmChar buf[256]; va_start(args, format); vsnprintf(buf, sizeof(buf), format, args); // 標準出力でレンダリング - cocos2d::log("%s", buf); // cocos2dのログ関数で出力 + cocos2d::log("%s", buf); // cocos2dのログ関数で出力(関数で改行される) va_end(args); } -void LAppPal::PrintMessage(const csmChar* message) +void LAppPal::PrintMessageLn(const csmChar* message) { - PrintLog("%s", message); + PrintLogLn("%s", message); } diff --git a/Samples/Cocos2d-x/Demo/Classes/LAppPal.hpp b/Samples/Cocos2d-x/Demo/Classes/LAppPal.hpp index 28225838..bbf793d5 100644 --- a/Samples/Cocos2d-x/Demo/Classes/LAppPal.hpp +++ b/Samples/Cocos2d-x/Demo/Classes/LAppPal.hpp @@ -48,25 +48,25 @@ class LAppPal static Csm::csmFloat32 GetDeltaTime(); /** - * @brief ログを出力する + * @brief ログを出力し最後に改行する * - * ログを出力する + * ログを出力し最後に改行する * * @param[in] format 書式付文字列 * @param[in] ... (可変長引数)文字列 * */ - static void PrintLog(const Csm::csmChar* format, ...); + static void PrintLogLn(const Csm::csmChar* format, ...); /** - * @brief メッセージを出力する + * @brief メッセージを出力し最後に改行する * - * メッセージを出力する + * メッセージを出力し最後に改行する * * @param[in] message 文字列 * */ - static void PrintMessage(const Csm::csmChar* message); + static void PrintMessageLn(const Csm::csmChar* message); private: LAppPal(); diff --git a/Samples/Cocos2d-x/Demo/Classes/LAppView.cpp b/Samples/Cocos2d-x/Demo/Classes/LAppView.cpp index be5bc5ec..2d29192e 100644 --- a/Samples/Cocos2d-x/Demo/Classes/LAppView.cpp +++ b/Samples/Cocos2d-x/Demo/Classes/LAppView.cpp @@ -132,7 +132,7 @@ void LAppView::onTouchesBegan(const std::vector& touches, Event* event) if (touchNum == 1) { Point pt = touches[0]->getLocationInView(); - if (DebugTouchLogEnable)LAppPal::PrintLog("[APP]touchesBegan x:%.0f y:%.0f", pt.x, pt.y); + if (DebugTouchLogEnable)LAppPal::PrintLogLn("[APP]touchesBegan x:%.0f y:%.0f", pt.x, pt.y); touchMgr->touchesBegan(pt.x, pt.y); } } @@ -152,7 +152,7 @@ void LAppView::onTouchesMoved(const std::vector& touches, Event* event) Point pt = touches[0]->getLocationInView(); if (DebugTouchLogEnable) - LAppPal::PrintLog("[APP]touchesMoved device{x:%.0f y:%.0f} screen{x:%.2f y:%.2f} view{x:%.2f y:%.2f}", pt.x, pt.y, screenX, screenY, viewX, viewY); + LAppPal::PrintLogLn("[APP]touchesMoved device{x:%.0f y:%.0f} screen{x:%.2f y:%.2f} view{x:%.2f y:%.2f}", pt.x, pt.y, screenX, screenY, viewX, viewY); touchMgr->touchesMoved(pt.x, pt.y); } @@ -171,7 +171,7 @@ void LAppView::onTouchesEnded(const std::vector& touches, cocos // シングルタップ float x = deviceToScreen->TransformX(touchMgr->getX()); // 論理座標変換した座標を取得。 float y = deviceToScreen->TransformY(touchMgr->getY()); // 論理座標変換した座標を取得。 - if (DebugTouchLogEnable) LAppPal::PrintLog("[APP]touchesEnded x:%.2f y:%.2f", x, y); + if (DebugTouchLogEnable) LAppPal::PrintLogLn("[APP]touchesEnded x:%.2f y:%.2f", x, y); live2DMgr->OnTap(x, y); } } diff --git a/Samples/Cocos2d-x/Demo/Classes/SampleScene.cpp b/Samples/Cocos2d-x/Demo/Classes/SampleScene.cpp index b4ee2ed5..76468a38 100644 --- a/Samples/Cocos2d-x/Demo/Classes/SampleScene.cpp +++ b/Samples/Cocos2d-x/Demo/Classes/SampleScene.cpp @@ -131,9 +131,9 @@ bool SampleScene::init() if (LAppDefine::DebugLogEnable) { - LAppPal::PrintLog("=============================================="); - LAppPal::PrintLog(" Live2D SDK Sample App "); - LAppPal::PrintLog("=============================================="); + LAppPal::PrintLogLn("=============================================="); + LAppPal::PrintLogLn(" Live2D SDK Sample App "); + LAppPal::PrintLogLn("=============================================="); } if (LAppDefine::DebugDrawRectEnable) diff --git a/Samples/D3D11/Demo/proj.d3d11.cmake/src/CubismDirectXRenderer.cpp b/Samples/D3D11/Demo/proj.d3d11.cmake/src/CubismDirectXRenderer.cpp index 0e9ea49d..d3628ae4 100644 --- a/Samples/D3D11/Demo/proj.d3d11.cmake/src/CubismDirectXRenderer.cpp +++ b/Samples/D3D11/Demo/proj.d3d11.cmake/src/CubismDirectXRenderer.cpp @@ -165,7 +165,7 @@ bool CubismDirectXRenderer::CreateRenderTarget(UINT width, UINT height) hr = _instance->_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBuffer); if (FAILED(hr)) { - LAppPal::PrintLog("Fail SwapChain GetBuffer 0x%x", hr); + LAppPal::PrintLogLn("Fail SwapChain GetBuffer 0x%x", hr); return false; } hr = _instance->_device->CreateRenderTargetView(backBuffer, NULL, &_instance->_renderTargetView); @@ -173,7 +173,7 @@ bool CubismDirectXRenderer::CreateRenderTarget(UINT width, UINT height) backBuffer->Release(); if (FAILED(hr)) { - LAppPal::PrintLog("Fail CreateRenderTargetView 0x%x", hr); + LAppPal::PrintLogLn("Fail CreateRenderTargetView 0x%x", hr); return false; } @@ -194,7 +194,7 @@ bool CubismDirectXRenderer::CreateRenderTarget(UINT width, UINT height) hr = _instance->_device->CreateTexture2D(&depthDesc, NULL, &_instance->_depthTexture); if (FAILED(hr)) { - LAppPal::PrintLog("Fail Create DepthTarget 0x%x", hr); + LAppPal::PrintLogLn("Fail Create DepthTarget 0x%x", hr); return false; } // DepthView @@ -206,7 +206,7 @@ bool CubismDirectXRenderer::CreateRenderTarget(UINT width, UINT height) hr = _instance->_device->CreateDepthStencilView(_instance->_depthTexture, &depthViewDesc, &_instance->_depthStencilView); if (FAILED(hr)) { - LAppPal::PrintLog("Fail Create DepthTargetView 0x%x", hr); + LAppPal::PrintLogLn("Fail Create DepthTargetView 0x%x", hr); return false; } @@ -281,13 +281,13 @@ bool CubismDirectXRenderer::CreateShader() &vertexError); // エラーが出る場合はここで if (FAILED(hr)) { - LAppPal::PrintLog("Fail Compile Vertex Shader"); + LAppPal::PrintLogLn("Fail Compile Vertex Shader"); break; } hr = _device->CreateVertexShader(vertexBlob->GetBufferPointer(), vertexBlob->GetBufferSize(), nullptr, &_vertexShader); if (FAILED(hr)) { - LAppPal::PrintLog("Fail Create Vertex Shader"); + LAppPal::PrintLogLn("Fail Create Vertex Shader"); break; } @@ -305,14 +305,14 @@ bool CubismDirectXRenderer::CreateShader() &pixelError); // エラーが出る場合はここで if (FAILED(hr)) { - LAppPal::PrintLog("Fail Compile Pixel Shader"); + LAppPal::PrintLogLn("Fail Compile Pixel Shader"); break; } hr = _device->CreatePixelShader(pixelBlob->GetBufferPointer(), pixelBlob->GetBufferSize(), NULL, &_pixelShader); if (FAILED(hr)) { - LAppPal::PrintLog("Fail Create Pixel Shader"); + LAppPal::PrintLogLn("Fail Create Pixel Shader"); break; } @@ -325,7 +325,7 @@ bool CubismDirectXRenderer::CreateShader() if (FAILED(hr)) { - LAppPal::PrintLog("CreateVertexDeclaration failed"); + LAppPal::PrintLogLn("CreateVertexDeclaration failed"); break; } @@ -550,7 +550,7 @@ void CubismDirectXRenderer::EndFrame(CubismUserModel* userModel) if (_deviceStep == DeviceStep_Lost) {// ロストした - LAppPal::PrintLog("Device Lost Abort"); + LAppPal::PrintLogLn("Device Lost Abort"); // アプリケーション終了フラグを立てる _isEnd = true; } diff --git a/Samples/D3D11/Demo/proj.d3d11.cmake/src/CubismSprite.cpp b/Samples/D3D11/Demo/proj.d3d11.cmake/src/CubismSprite.cpp index e3d43dc0..140e8194 100644 --- a/Samples/D3D11/Demo/proj.d3d11.cmake/src/CubismSprite.cpp +++ b/Samples/D3D11/Demo/proj.d3d11.cmake/src/CubismSprite.cpp @@ -60,7 +60,7 @@ CubismSprite::CubismSprite(float x, float y, float width, float height, Csm::csm { if (LAppDefine::DebugLogEnable) { - LAppPal::PrintLog("Cannot allocate vertex data in LAppSprite"); + LAppPal::PrintLogLn("Cannot allocate vertex data in LAppSprite"); } return; } @@ -104,7 +104,7 @@ CubismSprite::CubismSprite(float x, float y, float width, float height, Csm::csm { if (LAppDefine::DebugLogEnable) { - LAppPal::PrintLog("Cannot allocate index data in LAppSprite"); + LAppPal::PrintLogLn("Cannot allocate index data in LAppSprite"); } return; } diff --git a/Samples/D3D11/Demo/proj.d3d11.cmake/src/CubismTextureManager.cpp b/Samples/D3D11/Demo/proj.d3d11.cmake/src/CubismTextureManager.cpp index 33768559..0f2a95d8 100644 --- a/Samples/D3D11/Demo/proj.d3d11.cmake/src/CubismTextureManager.cpp +++ b/Samples/D3D11/Demo/proj.d3d11.cmake/src/CubismTextureManager.cpp @@ -172,7 +172,7 @@ CubismTextureManager::TextureInfo* CubismTextureManager::CreateTextureFromPngFil // 失敗 if (LAppDefine::DebugLogEnable) { - LAppPal::PrintLog("Texture Load Error : %s", fileName.c_str()); + LAppPal::PrintLogLn("Texture Load Error : %s", fileName.c_str()); } return nullptr; diff --git a/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppDelegate.cpp b/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppDelegate.cpp index ae1b89cd..a4c14ee1 100644 --- a/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppDelegate.cpp +++ b/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppDelegate.cpp @@ -52,7 +52,7 @@ bool LAppDelegate::Initialize() { if (DebugLogEnable) { - LAppPal::PrintLog("START"); + LAppPal::PrintLogLn("START"); } // ウィンドウクラス @@ -76,7 +76,7 @@ bool LAppDelegate::Initialize() CW_USEDEFAULT, CW_USEDEFAULT, rect.right, rect.bottom, NULL, NULL, _windowClass.hInstance, NULL); if(_windowHandle==NULL) { - LAppPal::PrintLog("Fail Create Window"); + LAppPal::PrintLogLn("Fail Create Window"); return false; } @@ -123,7 +123,7 @@ bool LAppDelegate::Initialize() &_deviceContext); if (FAILED(result)) { - LAppPal::PrintLog("Fail Direct3D Create Device 0x%x", result); + LAppPal::PrintLogLn("Fail Direct3D Create Device 0x%x", result); return false; } @@ -140,7 +140,7 @@ bool LAppDelegate::Initialize() result = _device->CreateDepthStencilState(&depthDesc, &_depthState); if (FAILED(result)) { - LAppPal::PrintLog("Fail Create Depth 0x%x", result); + LAppPal::PrintLogLn("Fail Create Depth 0x%x", result); return false; } @@ -157,7 +157,7 @@ bool LAppDelegate::Initialize() result = _device->CreateRasterizerState(&rasterDesc, &_rasterizer); if (FAILED(result)) { - LAppPal::PrintLog("Fail Create Rasterizer 0x%x", result); + LAppPal::PrintLogLn("Fail Create Rasterizer 0x%x", result); return false; } @@ -175,7 +175,7 @@ bool LAppDelegate::Initialize() _device->CreateSamplerState(&samplerDesc, &_samplerState); if (FAILED(result)) { - LAppPal::PrintLog("Fail Create Sampler 0x%x", result); + LAppPal::PrintLogLn("Fail Create Sampler 0x%x", result); return false; } @@ -207,7 +207,7 @@ bool LAppDelegate::CreateRenderTarget(UINT width, UINT height) hr = _swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBuffer); if (FAILED(hr)) { - LAppPal::PrintLog("Fail SwapChain GetBuffer 0x%x", hr); + LAppPal::PrintLogLn("Fail SwapChain GetBuffer 0x%x", hr); return false; } hr = _device->CreateRenderTargetView(backBuffer, NULL, &_renderTargetView); @@ -215,7 +215,7 @@ bool LAppDelegate::CreateRenderTarget(UINT width, UINT height) backBuffer->Release(); if (FAILED(hr)) { - LAppPal::PrintLog("Fail CreateRenderTargetView 0x%x", hr); + LAppPal::PrintLogLn("Fail CreateRenderTargetView 0x%x", hr); return false; } @@ -236,7 +236,7 @@ bool LAppDelegate::CreateRenderTarget(UINT width, UINT height) hr = _device->CreateTexture2D(&depthDesc, NULL, &_depthTexture); if (FAILED(hr)) { - LAppPal::PrintLog("Fail Create DepthTarget 0x%x", hr); + LAppPal::PrintLogLn("Fail Create DepthTarget 0x%x", hr); return false; } // DepthView @@ -248,7 +248,7 @@ bool LAppDelegate::CreateRenderTarget(UINT width, UINT height) hr = _device->CreateDepthStencilView(_depthTexture, &depthViewDesc, &_depthStencilView); if (FAILED(hr)) { - LAppPal::PrintLog("Fail Create DepthTargetView 0x%x", hr); + LAppPal::PrintLogLn("Fail Create DepthTargetView 0x%x", hr); return false; } @@ -481,13 +481,13 @@ bool LAppDelegate::CreateShader() &vertexError); // エラーが出る場合はここで if (FAILED(hr)) { - LAppPal::PrintLog("Fail Compile Vertex Shader"); + LAppPal::PrintLogLn("Fail Compile Vertex Shader"); break; } hr = _device->CreateVertexShader(vertexBlob->GetBufferPointer(), vertexBlob->GetBufferSize(), NULL, &_vertexShader); if (FAILED(hr)) { - LAppPal::PrintLog("Fail Create Vertex Shader"); + LAppPal::PrintLogLn("Fail Create Vertex Shader"); break; } @@ -505,14 +505,14 @@ bool LAppDelegate::CreateShader() &pixelError); // エラーが出る場合はここで if (FAILED(hr)) { - LAppPal::PrintLog("Fail Compile Pixel Shader"); + LAppPal::PrintLogLn("Fail Compile Pixel Shader"); break; } hr = _device->CreatePixelShader(pixelBlob->GetBufferPointer(), pixelBlob->GetBufferSize(), NULL, &_pixelShader); if (FAILED(hr)) { - LAppPal::PrintLog("Fail Create Pixel Shader"); + LAppPal::PrintLogLn("Fail Create Pixel Shader"); break; } @@ -525,7 +525,7 @@ bool LAppDelegate::CreateShader() if (FAILED(hr)) { - LAppPal::PrintLog("CreateVertexDeclaration failed"); + LAppPal::PrintLogLn("CreateVertexDeclaration failed"); break; } @@ -678,7 +678,7 @@ void LAppDelegate::EndFrame() if(_deviceStep == DeviceStep_Lost) {// ロストした - LAppPal::PrintLog("Device Lost Abort"); + LAppPal::PrintLogLn("Device Lost Abort"); // アプリケーション終了 AppEnd(); } diff --git a/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppLive2DManager.cpp b/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppLive2DManager.cpp index 20c4ba67..1e1bf39d 100644 --- a/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppLive2DManager.cpp +++ b/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppLive2DManager.cpp @@ -26,7 +26,7 @@ namespace { void FinishedMotion(ACubismMotion* self) { - LAppPal::PrintLog("Motion Finished: %x", self); + LAppPal::PrintLogLn("Motion Finished: %x", self); } int CompareCsmString(const void* a, const void* b) @@ -170,7 +170,7 @@ void LAppLive2DManager::OnTap(csmFloat32 x, csmFloat32 y) { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]tap point: {x:%.2f y:%.2f}", x, y); + LAppPal::PrintLogLn("[APP]tap point: {x:%.2f y:%.2f}", x, y); } for (csmUint32 i = 0; i < _models.GetSize(); i++) @@ -179,7 +179,7 @@ void LAppLive2DManager::OnTap(csmFloat32 x, csmFloat32 y) { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameHead); + LAppPal::PrintLogLn("[APP]hit area: [%s]", HitAreaNameHead); } _models[i]->SetRandomExpression(); } @@ -187,7 +187,7 @@ void LAppLive2DManager::OnTap(csmFloat32 x, csmFloat32 y) { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameBody); + LAppPal::PrintLogLn("[APP]hit area: [%s]", HitAreaNameBody); } _models[i]->StartRandomMotion(MotionGroupTapBody, PriorityNormal, FinishedMotion); } @@ -212,7 +212,7 @@ void LAppLive2DManager::OnUpdate() const if (model->GetModel() == NULL) { - LAppPal::PrintLog("Failed to model->GetModel()."); + LAppPal::PrintLogLn("Failed to model->GetModel()."); continue; } @@ -260,7 +260,7 @@ void LAppLive2DManager::ChangeScene(Csm::csmInt32 index) _sceneIndex = index; if (DebugLogEnable) { - LAppPal::PrintLog("[APP]model index: %d", _sceneIndex); + LAppPal::PrintLogLn("[APP]model index: %d", _sceneIndex); } // model3.jsonのパスを決定する. diff --git a/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppModel.cpp b/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppModel.cpp index 62d267e9..dc54d053 100644 --- a/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppModel.cpp +++ b/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppModel.cpp @@ -30,7 +30,7 @@ namespace { { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]create buffer: %s ", path); + LAppPal::PrintLogLn("[APP]create buffer: %s ", path); } return LAppPal::LoadFileAsBytes(path, size); } @@ -39,7 +39,7 @@ namespace { { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]delete buffer: %s", path); + LAppPal::PrintLogLn("[APP]delete buffer: %s", path); } LAppPal::ReleaseBytes(buffer); } @@ -98,7 +98,7 @@ void LAppModel::LoadAssets(const csmChar* dir, const csmChar* fileName) if (_debugMode) { - LAppPal::PrintLog("[APP]load model setting: %s", fileName); + LAppPal::PrintLogLn("[APP]load model setting: %s", fileName); } csmSizeInt size; @@ -112,7 +112,7 @@ void LAppModel::LoadAssets(const csmChar* dir, const csmChar* fileName) if (_model == NULL) { - LAppPal::PrintLog("Failed to LoadAssets()."); + LAppPal::PrintLogLn("Failed to LoadAssets()."); return; } @@ -140,7 +140,7 @@ void LAppModel::SetupModel(ICubismModelSetting* setting) if (_debugMode) { - LAppPal::PrintLog("[APP]create model: %s", setting->GetModelFileName()); + LAppPal::PrintLogLn("[APP]create model: %s", setting->GetModelFileName()); } buffer = CreateBuffer(path.GetRawString(), &size); @@ -248,7 +248,7 @@ void LAppModel::SetupModel(ICubismModelSetting* setting) if (_modelSetting == NULL || _modelMatrix == NULL) { - LAppPal::PrintLog("Failed to SetupModel()."); + LAppPal::PrintLogLn("Failed to SetupModel()."); return; } @@ -284,7 +284,7 @@ void LAppModel::PreloadMotionGroup(const csmChar* group) if (_debugMode) { - LAppPal::PrintLog("[APP]load motion: %s => [%s_%d] ", path.GetRawString(), group, i); + LAppPal::PrintLogLn("[APP]load motion: %s => [%s_%d] ", path.GetRawString(), group, i); } csmByte* buffer; @@ -457,7 +457,7 @@ CubismMotionQueueEntryHandle LAppModel::StartMotion(const csmChar* group, csmInt { if (_debugMode) { - LAppPal::PrintLog("[APP]can't start motion."); + LAppPal::PrintLogLn("[APP]can't start motion."); } return InvalidMotionQueueEntryHandleValue; } @@ -514,7 +514,7 @@ CubismMotionQueueEntryHandle LAppModel::StartMotion(const csmChar* group, csmInt if (_debugMode) { - LAppPal::PrintLog("[APP]start motion: [%s_%d]", group, no); + LAppPal::PrintLogLn("[APP]start motion: [%s_%d]", group, no); } return _motionManager->StartMotionPriority(motion, autoDelete, priority); } @@ -577,7 +577,7 @@ void LAppModel::SetExpression(const csmChar* expressionID) ACubismMotion* motion = _expressions[expressionID]; if (_debugMode) { - LAppPal::PrintLog("[APP]expression: [%s]", expressionID); + LAppPal::PrintLogLn("[APP]expression: [%s]", expressionID); } if (motion != NULL) @@ -588,7 +588,7 @@ void LAppModel::SetExpression(const csmChar* expressionID) { if (_debugMode) { - LAppPal::PrintLog("[APP]expression[%s] is null ", expressionID); + LAppPal::PrintLogLn("[APP]expression[%s] is null ", expressionID); } } } diff --git a/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppPal.cpp b/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppPal.cpp index 691afd14..d64781ad 100644 --- a/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppPal.cpp +++ b/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppPal.cpp @@ -37,20 +37,37 @@ csmByte* LAppPal::LoadFileAsBytes(const string filePath, csmSizeInt* outSize) if (stat(path, &statBuf) == 0) { size = statBuf.st_size; + + if (size == 0) + { + if (DebugLogEnable) + { + PrintLogLn("Stat succeeded but file size is zero. path:%s", path); + } + return NULL; + } + } + else + { + if (DebugLogEnable) + { + PrintLogLn("Stat failed. errno:%d path:%s", errno, path); + } + return NULL; } std::fstream file; - char* buf = new char[size]; - file.open(path, std::ios::in | std::ios::binary); if (!file.is_open()) { if (DebugLogEnable) { - PrintLog("file open error"); + PrintLogLn("File open failed. path:%s", path); } return NULL; } + + char* buf = new char[size]; file.read(buf, size); file.close(); @@ -88,6 +105,16 @@ void LAppPal::UpdateTime() } void LAppPal::PrintLog(const char* format, ...) +{ + va_list args; + char buf[256]; + va_start(args, format); + _vsnprintf_s(buf, sizeof(buf), format, args); + OutputDebugStringA((LPCSTR)buf); + va_end(args); +} + +void LAppPal::PrintLogLn(const char* format, ...) { va_list args; char buf[256]; @@ -99,6 +126,16 @@ void LAppPal::PrintLog(const char* format, ...) } void LAppPal::PrintLogW(const wchar_t* format, ...) +{ + va_list args; + wchar_t buf[256]; + va_start(args, format); + _vsnwprintf_s(buf, sizeof(buf), format, args); + OutputDebugString((LPCSTR)buf); + va_end(args); +} + +void LAppPal::PrintLogLnW(const wchar_t* format, ...) { va_list args; wchar_t buf[256]; @@ -114,6 +151,11 @@ void LAppPal::PrintMessage(const csmChar* message) PrintLog("%s", message); } +void LAppPal::PrintMessageLn(const csmChar* message) +{ + PrintLogLn("%s", message); +} + void LAppPal::CoordinateFullScreenToWindow(float clientWidth, float clientHeight, float fullScreenX, float fullScreenY, float& retWindowX, float& retWindowY) { retWindowX = retWindowY = 0.0f; diff --git a/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppPal.hpp b/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppPal.hpp index 7a7f8757..8eee246a 100644 --- a/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppPal.hpp +++ b/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppPal.hpp @@ -74,6 +74,17 @@ class LAppPal */ static void PrintLog(const char*, ...); + /** + * @brief ログを出力し最後に改行する + * + * ログを出力し最後に改行する + * + * @param[in] format 書式付文字列 + * @param[in] ... (可変長引数)文字列 + * + */ + static void PrintLogLn(const char*, ...); + /** * @brief ログを出力する wchar版 * @@ -85,6 +96,17 @@ class LAppPal */ static void PrintLogW(const wchar_t*, ...); + /** + * @brief ログを出力し最後に改行する wchar版 + * + * ログを出力し最後に改行する + * + * @param[in] format 書式付文字列 + * @param[in] ... (可変長引数)文字列 + * + */ + static void PrintLogLnW(const wchar_t*, ...); + /** * @brief メッセージを出力する * @@ -95,6 +117,16 @@ class LAppPal */ static void PrintMessage(const Csm::csmChar* message); + /** + * @brief メッセージを出力し最後に改行する + * + * メッセージを出力し最後に改行する + * + * @param[in] message 文字列 + * + */ + static void PrintMessageLn(const Csm::csmChar* message); + /** * @brief 座標変換 * フルスクリーン LT(-bufferX, bufferY) RB(bufferX, -bufferY) → ウィンドウ・マウス LT(0, 0) RB(bufferX, bufferY) diff --git a/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppSprite.cpp b/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppSprite.cpp index 2bea0b7b..a97ef437 100644 --- a/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppSprite.cpp +++ b/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppSprite.cpp @@ -9,7 +9,6 @@ #include "LAppPal.hpp" #include "LAppDefine.hpp" -#include "LAppDelegate.hpp" #include "LAppTextureManager.hpp" #include "Rendering/D3D11/CubismType_D3D11.hpp" @@ -25,7 +24,7 @@ LAppSprite::LAppSprite() _color = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f); } -LAppSprite::LAppSprite(float x, float y, float width, float height, Csm::csmUint64 textureId) +LAppSprite::LAppSprite(float x, float y, float width, float height, Csm::csmUint64 textureId, ID3D11Device* device) : _rect(), _vertexBuffer(NULL), _indexBuffer(NULL), @@ -39,8 +38,6 @@ LAppSprite::LAppSprite(float x, float y, float width, float height, Csm::csmUint _rect.down = (y - height * 0.5f); _textureId = textureId; - ID3D11Device* device = LAppDelegate::GetInstance()->GetD3dDevice(); - if (!device) { return; @@ -65,7 +62,7 @@ LAppSprite::LAppSprite(float x, float y, float width, float height, Csm::csmUint { if (DebugLogEnable) { - LAppPal::PrintLog("Cannot allocate vertex data in LAppSprite"); + LAppPal::PrintLogLn("Cannot allocate vertex data in LAppSprite"); } return; } @@ -109,7 +106,7 @@ LAppSprite::LAppSprite(float x, float y, float width, float height, Csm::csmUint { if (DebugLogEnable) { - LAppPal::PrintLog("Cannot allocate index data in LAppSprite"); + LAppPal::PrintLogLn("Cannot allocate index data in LAppSprite"); } return; } @@ -133,8 +130,6 @@ LAppSprite::LAppSprite(float x, float y, float width, float height, Csm::csmUint LAppSprite::~LAppSprite() { - LAppDelegate::GetInstance()->GetTextureManager()->ReleaseTexture(_textureId); - if(_constantBuffer) { _constantBuffer->Release(); @@ -152,77 +147,7 @@ LAppSprite::~LAppSprite() } } -void LAppSprite::Render(int width, int height) const -{ - if (width == 0 || height == 0) - { - return; // この際は描画できず - } - - LAppDelegate* appDelegate = LAppDelegate::GetInstance(); - ID3D11DeviceContext* renderContext = LAppDelegate::GetD3dContext(); - - SpriteVertex vtx[VERTEX_NUM] = { - { 0.0f, 0.0f, 0.0f, 0.0f }, - { 0.5f, 0.0f, 1.0f, 0.0f }, - { 0.0f, 0.5f, 0.0f, 1.0f }, - { 0.5f, 0.5f, 1.0f, 1.0f }, - }; - - vtx[0].x = (_rect.left - width * 0.5f) / (width * 0.5f); vtx[0].y = (_rect.down - height * 0.5f) / (height * 0.5f); - vtx[1].x = (_rect.right - width * 0.5f) / (width * 0.5f); vtx[1].y = (_rect.down - height * 0.5f) / (height * 0.5f); - vtx[2].x = (_rect.left - width * 0.5f) / (width * 0.5f); vtx[2].y = (_rect.up - height * 0.5f) / (height * 0.5f); - vtx[3].x = (_rect.right - width * 0.5f) / (width * 0.5f); vtx[3].y = (_rect.up - height * 0.5f) / (height * 0.5f); - - // 頂点書き込み - if (_vertexBuffer) - { - D3D11_MAPPED_SUBRESOURCE subRes; - if (SUCCEEDED(renderContext->Map(_vertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &subRes))) - { - memcpy(subRes.pData, vtx, sizeof(SpriteVertex) * VERTEX_NUM); - renderContext->Unmap(_vertexBuffer, 0); - } - } - - // 定数バッファ設定 - if(_constantBuffer) - { - CubismConstantBufferD3D11 cb; - memset(&cb, 0, sizeof(cb)); - cb.baseColor = _color; - DirectX::XMMATRIX proj = XMMatrixIdentity(); - XMStoreFloat4x4(&cb.projectMatrix, XMMatrixTranspose(proj)); - renderContext->UpdateSubresource(_constantBuffer, 0, NULL, &cb, 0, 0); - - renderContext->VSSetConstantBuffers(0, 1, &_constantBuffer); - renderContext->PSSetConstantBuffers(0, 1, &_constantBuffer); - } - - { - UINT strides = sizeof(LAppSprite::SpriteVertex); - UINT offsets = 0; - - renderContext->IASetVertexBuffers(0, 1, &_vertexBuffer, &strides, &offsets); - renderContext->IASetIndexBuffer(_indexBuffer, DXGI_FORMAT_R16_UINT, 0); - renderContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); - - // 描画用設定 - appDelegate->SetupShader(); - - // テクスチャセット - ID3D11ShaderResourceView* textureView = NULL; - if (LAppDelegate::GetInstance()->GetTextureManager()->GetTexture(_textureId, textureView)) - { - renderContext->PSSetShaderResources(0, 1, &textureView); - } - - // 描画実行 - renderContext->DrawIndexed(INDEX_NUM, 0, 0); - } -} - -void LAppSprite::RenderImmidiate(int width, int height, ID3D11ShaderResourceView* resourceView) const +void LAppSprite::RenderImmidiate(int width, int height, ID3D11ShaderResourceView* resourceView, ID3D11DeviceContext* renderContext) const { if (!resourceView) return; @@ -231,9 +156,6 @@ void LAppSprite::RenderImmidiate(int width, int height, ID3D11ShaderResourceView return; // この際は描画できず } - LAppDelegate* appDelegate = LAppDelegate::GetInstance(); - ID3D11DeviceContext* renderContext = LAppDelegate::GetD3dContext(); - SpriteVertex vtx[VERTEX_NUM] = { { 0.0f, 0.0f, 0.0f, 0.0f }, { 0.5f, 0.0f, 1.0f, 0.0f }, @@ -279,9 +201,6 @@ void LAppSprite::RenderImmidiate(int width, int height, ID3D11ShaderResourceView renderContext->IASetIndexBuffer(_indexBuffer, DXGI_FORMAT_R16_UINT, 0); renderContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); - // 描画用設定 - appDelegate->SetupShader(); - // テクスチャセット { renderContext->PSSetShaderResources(0, 1, &resourceView); @@ -292,19 +211,17 @@ void LAppSprite::RenderImmidiate(int width, int height, ID3D11ShaderResourceView } } -bool LAppSprite::IsHit(float pointX, float pointY) const +bool LAppSprite::IsHit(float pointX, float pointY, int clientWidth, int clientHeight) const { - // フルスクリーン座標に変換 - float coordX = 0.0f, coordY = 0.0f; - int clientWidth = 0, clientHeight = 0; - LAppDelegate::GetClientSize(clientWidth, clientHeight); - LAppPal::CoordinateWindowToFullScreen(static_cast(clientWidth), static_cast(clientHeight), pointX, pointY, coordX, coordY); - if(clientWidth==0 || clientHeight==0) {// この際はヒットしない return false; } + // フルスクリーン座標に変換 + float coordX = 0.0f, coordY = 0.0f; + LAppPal::CoordinateWindowToFullScreen(static_cast(clientWidth), static_cast(clientHeight), pointX, pointY, coordX, coordY); + coordX = (clientWidth+coordX)/(2.0f*clientWidth) * clientWidth; coordY = (clientHeight+coordY)/(2.0f*clientHeight) * clientHeight; diff --git a/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppSprite.hpp b/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppSprite.hpp index d67f0084..9f882a69 100644 --- a/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppSprite.hpp +++ b/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppSprite.hpp @@ -51,8 +51,9 @@ class LAppSprite * @param[in] width 横幅 * @param[in] height 高さ * @param[in] textureId テクスチャID + * @param[in] device D3Dデバイス */ - LAppSprite(float x, float y, float width, float height, Csm::csmUint64 textureId); + LAppSprite(float x, float y, float width, float height, Csm::csmUint64 textureId, ID3D11Device* device); /** * @brief デストラクタ @@ -65,28 +66,24 @@ class LAppSprite */ Csm::csmUint64 GetTextureId() { return _textureId; } - /** - * @brief 描画する - * @param[in] width 幅 - * @param[in] height 高さ - */ - void Render(int width, int height) const; - /** * @brief テクスチャを指定しての描画 * @param[in] width 幅 * @param[in] height 高さ * @param[in] resourceView 使用テクスチャ + * @param[in] renderContext デバイスコンテキスト */ - void RenderImmidiate(int width, int height, ID3D11ShaderResourceView* resourceView) const; + void RenderImmidiate(int width, int height, ID3D11ShaderResourceView* resourceView, ID3D11DeviceContext* renderContext) const; /** * @brief ヒットチェック * * @param[in] pointX x座標 * @param[in] pointY y座標 + * @param[in] clientWidth クライアントウィンドウ幅 + * @param[in] clientHeight クライアントウィンドウ高さ */ - bool IsHit(float pointX, float pointY) const; + bool IsHit(float pointX, float pointY, int clientWidth, int clientHeight) const; /** * @brief サイズ再設定 @@ -123,4 +120,3 @@ class LAppSprite DirectX::XMFLOAT4 _color; ///< スプライトカラー }; - diff --git a/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppTextureManager.cpp b/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppTextureManager.cpp index 4ce3b3bf..a3327511 100644 --- a/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppTextureManager.cpp +++ b/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppTextureManager.cpp @@ -168,7 +168,7 @@ LAppTextureManager::TextureInfo* LAppTextureManager::CreateTextureFromPngFile(st // 失敗 if (DebugLogEnable) { - LAppPal::PrintLog("Texture Load Error : %s", fileName.c_str()); + LAppPal::PrintLogLn("Texture Load Error : %s", fileName.c_str()); } return NULL; diff --git a/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppView.cpp b/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppView.cpp index 45d4ac19..9769c511 100644 --- a/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppView.cpp +++ b/Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppView.cpp @@ -46,13 +46,11 @@ LAppView::~LAppView() { _renderBuffer.DestroyOffscreenSurface(); - delete _renderSprite; + ReleaseSprite(); + delete _viewMatrix; delete _deviceToScreen; delete _touchManager; - delete _back; - delete _gear; - delete _power; } void LAppView::Initialize() @@ -109,21 +107,33 @@ void LAppView::Render() return; } + // シェーダー設定 + LAppDelegate::GetInstance()->SetupShader(); + // スプライト描画 int width, height; LAppDelegate::GetInstance()->GetClientSize(width, height); + // デバイスコンテキスト取得 + ID3D11DeviceContext* renderContext = LAppDelegate::GetD3dContext(); + if (_back) { - _back->Render(width, height); + ID3D11ShaderResourceView* textureView = NULL; + LAppDelegate::GetInstance()->GetTextureManager()->GetTexture(_back->GetTextureId(), textureView); + _back->RenderImmidiate(width, height, textureView, renderContext); } if (_gear) { - _gear->Render(width, height); + ID3D11ShaderResourceView* textureView = NULL; + LAppDelegate::GetInstance()->GetTextureManager()->GetTexture(_gear->GetTextureId(), textureView); + _gear->RenderImmidiate(width, height, textureView, renderContext); } if (_power) { - _power->Render(width, height); + ID3D11ShaderResourceView* textureView = NULL; + LAppDelegate::GetInstance()->GetTextureManager()->GetTexture(_power->GetTextureId(), textureView); + _power->RenderImmidiate(width, height, textureView, renderContext); } live2DManager->SetViewMatrix(_viewMatrix); @@ -142,7 +152,7 @@ void LAppView::Render() if (model) { - _renderSprite->RenderImmidiate(width, height, model->GetRenderBuffer().GetTextureView()); + _renderSprite->RenderImmidiate(width, height, model->GetRenderBuffer().GetTextureView(), renderContext); } } } @@ -157,6 +167,8 @@ void LAppView::InitializeSprite() LAppTextureManager* textureManager = LAppDelegate::GetInstance()->GetTextureManager(); const string resourcesPath = ResourcesPath; + ID3D11Device* device = LAppDelegate::GetInstance()->GetD3dDevice(); + float x = 0.0f; float y = 0.0f; float fWidth = 0.0f; @@ -168,7 +180,7 @@ void LAppView::InitializeSprite() y = height * 0.5f; fWidth = static_cast(backgroundTexture->width * 2); fHeight = static_cast(height) * 0.95f; - _back = new LAppSprite(x, y, fWidth, fHeight, backgroundTexture->id); + _back = new LAppSprite(x, y, fWidth, fHeight, backgroundTexture->id, device); imageName = resourcesPath + GearImageName; LAppTextureManager::TextureInfo* gearTexture = textureManager->CreateTextureFromPngFile(imageName, false); @@ -176,7 +188,7 @@ void LAppView::InitializeSprite() y = static_cast(height - gearTexture->height * 0.5f); fWidth = static_cast(gearTexture->width); fHeight = static_cast(gearTexture->height); - _gear = new LAppSprite(x, y, fWidth, fHeight, gearTexture->id); + _gear = new LAppSprite(x, y, fWidth, fHeight, gearTexture->id, device); imageName = resourcesPath + PowerImageName; LAppTextureManager::TextureInfo* powerTexture = textureManager->CreateTextureFromPngFile(imageName, false); @@ -184,24 +196,42 @@ void LAppView::InitializeSprite() y = static_cast(powerTexture->height * 0.5f); fWidth = static_cast(powerTexture->width); fHeight = static_cast(powerTexture->height); - _power = new LAppSprite(x, y, fWidth, fHeight, powerTexture->id); + _power = new LAppSprite(x, y, fWidth, fHeight, powerTexture->id, device); x = width * 0.5f; y = height * 0.5f; - _renderSprite = new LAppSprite(x, y, static_cast(width), static_cast(height), 0); + _renderSprite = new LAppSprite(x, y, static_cast(width), static_cast(height), 0, device); } void LAppView::ReleaseSprite() { + LAppTextureManager* textureManager = LAppDelegate::GetInstance()->GetTextureManager(); + + if (_renderSprite) + { + textureManager->ReleaseTexture(_renderSprite->GetTextureId()); + } delete _renderSprite; _renderSprite = NULL; + if (_gear) + { + textureManager->ReleaseTexture(_gear->GetTextureId()); + } delete _gear; _gear = NULL; + if (_power) + { + textureManager->ReleaseTexture(_power->GetTextureId()); + } delete _power; _power = NULL; + if (_back) + { + textureManager->ReleaseTexture(_back->GetTextureId()); + } delete _back; _back = NULL; } @@ -303,18 +333,18 @@ void LAppView::OnTouchesEnded(float px, float py) const float y = _deviceToScreen->TransformY(py); // 論理座標変換した座標を取得。 if (DebugTouchLogEnable) { - LAppPal::PrintLog("[APP]touchesEnded x:%.2f y:%.2f", x, y); + LAppPal::PrintLogLn("[APP]touchesEnded x:%.2f y:%.2f", x, y); } live2DManager->OnTap(x, y); // 歯車にタップしたか - if (_gear->IsHit(px, py)) + if (_gear->IsHit(px, py, width, height)) { live2DManager->NextScene(); } // 電源ボタンにタップしたか - if (_power->IsHit(px, py)) + if (_power->IsHit(px, py, width, height)) { LAppDelegate::GetInstance()->AppEnd(); } @@ -390,12 +420,15 @@ void LAppView::PostModelDraw(LAppModel& refModel) // LAppViewの持つフレームバッファを使うなら、スプライトへの描画はここ if (_renderTarget == SelectTarget_ViewFrameBuffer && _renderSprite) { + // シェーダー設定 + LAppDelegate::GetInstance()->SetupShader(); + // スプライト描画 int width, height; LAppDelegate::GetInstance()->GetClientSize(width, height); _renderSprite->SetColor(1.0f, 1.0f, 1.0f, GetSpriteAlpha(0)); - _renderSprite->RenderImmidiate(width, height, useTarget->GetTextureView()); + _renderSprite->RenderImmidiate(width, height, useTarget->GetTextureView(), LAppDelegate::GetInstance()->GetD3dContext()); } } } diff --git a/Samples/D3D11/Demo/proj.d3d11.cmake/src/mainMinimum.cpp b/Samples/D3D11/Demo/proj.d3d11.cmake/src/mainMinimum.cpp index 3f571fb7..eae63a43 100644 --- a/Samples/D3D11/Demo/proj.d3d11.cmake/src/mainMinimum.cpp +++ b/Samples/D3D11/Demo/proj.d3d11.cmake/src/mainMinimum.cpp @@ -172,7 +172,7 @@ LRESULT WINAPI MsgProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) */ static bool InitializeSystem() { - LAppPal::PrintLog("START"); + LAppPal::PrintLogLn("START"); CubismDirectXRenderer* directXRenderer = CubismDirectXRenderer::GetInstance(); @@ -197,7 +197,7 @@ static bool InitializeSystem() CW_USEDEFAULT, CW_USEDEFAULT, rect.right, rect.bottom, NULL, NULL, directXRenderer->_windowClass.hInstance, NULL); if (directXRenderer->_windowHandle == nullptr) { - LAppPal::PrintLog("Fail Create Window"); + LAppPal::PrintLogLn("Fail Create Window"); return false; } @@ -247,7 +247,7 @@ static bool InitializeSystem() &directXRenderer->_deviceContext); if (FAILED(result)) { - LAppPal::PrintLog("Fail Direct3D Create Device 0x%x", result); + LAppPal::PrintLogLn("Fail Direct3D Create Device 0x%x", result); return false; } @@ -264,7 +264,7 @@ static bool InitializeSystem() result = directXRenderer->_device->CreateDepthStencilState(&depthDesc, &directXRenderer->_depthState); if (FAILED(result)) { - LAppPal::PrintLog("Fail Create Depth 0x%x", result); + LAppPal::PrintLogLn("Fail Create Depth 0x%x", result); return false; } @@ -281,7 +281,7 @@ static bool InitializeSystem() result = directXRenderer->_device->CreateRasterizerState(&rasterDesc, &directXRenderer->_rasterizer); if (FAILED(result)) { - LAppPal::PrintLog("Fail Create Rasterizer 0x%x", result); + LAppPal::PrintLogLn("Fail Create Rasterizer 0x%x", result); return false; } @@ -299,7 +299,7 @@ static bool InitializeSystem() directXRenderer->_device->CreateSamplerState(&samplerDesc, &directXRenderer->_samplerState); if (FAILED(result)) { - LAppPal::PrintLog("Fail Create Sampler 0x%x", result); + LAppPal::PrintLogLn("Fail Create Sampler 0x%x", result); return false; } diff --git a/Samples/D3D9/Demo/proj.d3d9.cmake/src/CubismDirectXRenderer.cpp b/Samples/D3D9/Demo/proj.d3d9.cmake/src/CubismDirectXRenderer.cpp index d4399908..6ad81dc5 100644 --- a/Samples/D3D9/Demo/proj.d3d9.cmake/src/CubismDirectXRenderer.cpp +++ b/Samples/D3D9/Demo/proj.d3d9.cmake/src/CubismDirectXRenderer.cpp @@ -154,7 +154,7 @@ bool CubismDirectXRenderer::CreateShader() ID3DXBuffer* error = 0; if (FAILED(D3DXCreateEffect(_device, SpriteShaderEffectSrc, static_cast(strlen(SpriteShaderEffectSrc)), 0, 0, 0, 0, &_shaderEffect, &error))) { - LAppPal::PrintLog("Cannot load the shaders"); + LAppPal::PrintLogLn("Cannot load the shaders"); return false; } @@ -166,7 +166,7 @@ bool CubismDirectXRenderer::CreateShader() }; if (_device->CreateVertexDeclaration(elems, &_vertexFormat)) { - LAppPal::PrintLog("CreateVertexDeclaration failed"); + LAppPal::PrintLogLn("CreateVertexDeclaration failed"); CSM_ASSERT(0); } @@ -358,7 +358,7 @@ void CubismDirectXRenderer::EndFrame(CubismUserModel* userModel) D3DCREATE_HARDWARE_VERTEXPROCESSING, presentParam, &_device))) { - LAppPal::PrintLog("Fail Direct3D Create Device"); + LAppPal::PrintLogLn("Fail Direct3D Create Device"); _device = NULL; } else diff --git a/Samples/D3D9/Demo/proj.d3d9.cmake/src/CubismTextureManager.cpp b/Samples/D3D9/Demo/proj.d3d9.cmake/src/CubismTextureManager.cpp index a163eec0..50efb1e3 100644 --- a/Samples/D3D9/Demo/proj.d3d9.cmake/src/CubismTextureManager.cpp +++ b/Samples/D3D9/Demo/proj.d3d9.cmake/src/CubismTextureManager.cpp @@ -104,7 +104,7 @@ CubismTextureManager::TextureInfo* CubismTextureManager::CreateTextureFromPngFil // 失敗 if (LAppDefine::DebugLogEnable) { - LAppPal::PrintLog("Texture Load Error : %s", fileName.c_str()); + LAppPal::PrintLogLn("Texture Load Error : %s", fileName.c_str()); } delete textureInfo; diff --git a/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppDelegate.cpp b/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppDelegate.cpp index df8dc798..0860c4f4 100644 --- a/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppDelegate.cpp +++ b/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppDelegate.cpp @@ -51,7 +51,7 @@ bool LAppDelegate::Initialize() { if (DebugLogEnable) { - LAppPal::PrintLog("START"); + LAppPal::PrintLogLn("START"); } // ウィンドウクラス @@ -75,7 +75,7 @@ bool LAppDelegate::Initialize() CW_USEDEFAULT, CW_USEDEFAULT, rect.right, rect.bottom, NULL, NULL, _windowClass.hInstance, NULL); if(_windowHandle==NULL) { - LAppPal::PrintLog("Fail Create Window"); + LAppPal::PrintLogLn("Fail Create Window"); return false; } @@ -86,7 +86,7 @@ bool LAppDelegate::Initialize() // Direct3D9 init if ((_direct3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL) { - LAppPal::PrintLog("Fail Direct3D Initialize"); + LAppPal::PrintLogLn("Fail Direct3D Initialize"); return false; } @@ -111,7 +111,7 @@ bool LAppDelegate::Initialize() if(FAILED(createResult)) { - LAppPal::PrintLog("Fail Direct3D Create Device %x", createResult); + LAppPal::PrintLogLn("Fail Direct3D Create Device %x", createResult); return false; } @@ -291,7 +291,7 @@ bool LAppDelegate::CreateShader() ID3DXBuffer* error = 0; if (FAILED(D3DXCreateEffect(_device, SpriteShaderEffectSrc, static_cast(strlen(SpriteShaderEffectSrc)), 0, 0, 0, 0, &_shaderEffect, &error))) { - LAppPal::PrintLog("Cannot load the shaders"); + LAppPal::PrintLogLn("Cannot load the shaders"); return false; } @@ -303,7 +303,7 @@ bool LAppDelegate::CreateShader() }; if (_device->CreateVertexDeclaration(elems, &_vertexFormat)) { - LAppPal::PrintLog("CreateVertexDeclaration failed"); + LAppPal::PrintLogLn("CreateVertexDeclaration failed"); CSM_ASSERT(0); } @@ -475,7 +475,7 @@ void LAppDelegate::EndFrame() D3DCREATE_HARDWARE_VERTEXPROCESSING, presentParam, &_device))) { - LAppPal::PrintLog("Fail Direct3D Create Device"); + LAppPal::PrintLogLn("Fail Direct3D Create Device"); _device = NULL; } else diff --git a/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppLive2DManager.cpp b/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppLive2DManager.cpp index f289bce0..81df6e49 100644 --- a/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppLive2DManager.cpp +++ b/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppLive2DManager.cpp @@ -26,7 +26,7 @@ namespace { void FinishedMotion(ACubismMotion* self) { - LAppPal::PrintLog("Motion Finished: %x", self); + LAppPal::PrintLogLn("Motion Finished: %x", self); } int CompareCsmString(const void* a, const void* b) @@ -170,7 +170,7 @@ void LAppLive2DManager::OnTap(csmFloat32 x, csmFloat32 y) { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]tap point: {x:%.2f y:%.2f}", x, y); + LAppPal::PrintLogLn("[APP]tap point: {x:%.2f y:%.2f}", x, y); } for (csmUint32 i = 0; i < _models.GetSize(); i++) @@ -179,7 +179,7 @@ void LAppLive2DManager::OnTap(csmFloat32 x, csmFloat32 y) { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameHead); + LAppPal::PrintLogLn("[APP]hit area: [%s]", HitAreaNameHead); } _models[i]->SetRandomExpression(); } @@ -187,7 +187,7 @@ void LAppLive2DManager::OnTap(csmFloat32 x, csmFloat32 y) { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameBody); + LAppPal::PrintLogLn("[APP]hit area: [%s]", HitAreaNameBody); } _models[i]->StartRandomMotion(MotionGroupTapBody, PriorityNormal, FinishedMotion); } @@ -211,7 +211,7 @@ void LAppLive2DManager::OnUpdate() const if (model->GetModel() == NULL) { - LAppPal::PrintLog("Failed to model->GetModel()."); + LAppPal::PrintLogLn("Failed to model->GetModel()."); continue; } @@ -259,7 +259,7 @@ void LAppLive2DManager::ChangeScene(Csm::csmInt32 index) _sceneIndex = index; if (DebugLogEnable) { - LAppPal::PrintLog("[APP]model index: %d", _sceneIndex); + LAppPal::PrintLogLn("[APP]model index: %d", _sceneIndex); } // model3.jsonのパスを決定する. @@ -353,7 +353,7 @@ void LAppLive2DManager::RestoreDeviceLost(LPDIRECT3DDEVICE9 device) { if (_models[i]->GetModel() == NULL) { - LAppPal::PrintLog("Failed to model->GetModel()."); + LAppPal::PrintLogLn("Failed to model->GetModel()."); continue; } diff --git a/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppModel.cpp b/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppModel.cpp index bf8ec43c..ea840395 100644 --- a/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppModel.cpp +++ b/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppModel.cpp @@ -30,7 +30,7 @@ namespace { { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]create buffer: %s ", path); + LAppPal::PrintLogLn("[APP]create buffer: %s ", path); } return LAppPal::LoadFileAsBytes(path, size); } @@ -39,7 +39,7 @@ namespace { { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]delete buffer: %s", path); + LAppPal::PrintLogLn("[APP]delete buffer: %s", path); } LAppPal::ReleaseBytes(buffer); } @@ -98,7 +98,7 @@ void LAppModel::LoadAssets(const csmChar* dir, const csmChar* fileName) if (_debugMode) { - LAppPal::PrintLog("[APP]load model setting: %s", fileName); + LAppPal::PrintLogLn("[APP]load model setting: %s", fileName); } csmSizeInt size; @@ -112,7 +112,7 @@ void LAppModel::LoadAssets(const csmChar* dir, const csmChar* fileName) if (_model == NULL) { - LAppPal::PrintLog("Failed to LoadAssets()."); + LAppPal::PrintLogLn("Failed to LoadAssets()."); return; } @@ -140,7 +140,7 @@ void LAppModel::SetupModel(ICubismModelSetting* setting) if (_debugMode) { - LAppPal::PrintLog("[APP]create model: %s", setting->GetModelFileName()); + LAppPal::PrintLogLn("[APP]create model: %s", setting->GetModelFileName()); } buffer = CreateBuffer(path.GetRawString(), &size); @@ -248,7 +248,7 @@ void LAppModel::SetupModel(ICubismModelSetting* setting) if (_modelSetting == NULL || _modelMatrix == NULL) { - LAppPal::PrintLog("Failed to SetupModel()."); + LAppPal::PrintLogLn("Failed to SetupModel()."); return; } @@ -284,7 +284,7 @@ void LAppModel::PreloadMotionGroup(const csmChar* group) if (_debugMode) { - LAppPal::PrintLog("[APP]load motion: %s => [%s_%d] ", path.GetRawString(), group, i); + LAppPal::PrintLogLn("[APP]load motion: %s => [%s_%d] ", path.GetRawString(), group, i); } csmByte* buffer; @@ -467,7 +467,7 @@ CubismMotionQueueEntryHandle LAppModel::StartMotion(const csmChar* group, csmInt { if (_debugMode) { - LAppPal::PrintLog("[APP]can't start motion."); + LAppPal::PrintLogLn("[APP]can't start motion."); } return InvalidMotionQueueEntryHandleValue; } @@ -524,7 +524,7 @@ CubismMotionQueueEntryHandle LAppModel::StartMotion(const csmChar* group, csmInt if (_debugMode) { - LAppPal::PrintLog("[APP]start motion: [%s_%d]", group, no); + LAppPal::PrintLogLn("[APP]start motion: [%s_%d]", group, no); } return _motionManager->StartMotionPriority(motion, autoDelete, priority); } @@ -590,7 +590,7 @@ void LAppModel::SetExpression(const csmChar* expressionID) ACubismMotion* motion = _expressions[expressionID]; if (_debugMode) { - LAppPal::PrintLog("[APP]expression: [%s]", expressionID); + LAppPal::PrintLogLn("[APP]expression: [%s]", expressionID); } if (motion != NULL) @@ -599,7 +599,7 @@ void LAppModel::SetExpression(const csmChar* expressionID) } else { - if (_debugMode) LAppPal::PrintLog("[APP]expression[%s] is null ", expressionID); + if (_debugMode) LAppPal::PrintLogLn("[APP]expression[%s] is null ", expressionID); } } diff --git a/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppPal.cpp b/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppPal.cpp index 3a7f7b65..ab9dc715 100644 --- a/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppPal.cpp +++ b/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppPal.cpp @@ -37,20 +37,37 @@ csmByte* LAppPal::LoadFileAsBytes(const string filePath, csmSizeInt* outSize) if (stat(path, &statBuf) == 0) { size = statBuf.st_size; + + if (size == 0) + { + if (DebugLogEnable) + { + PrintLogLn("Stat succeeded but file size is zero. path:%s", path); + } + return NULL; + } + } + else + { + if (DebugLogEnable) + { + PrintLogLn("Stat failed. errno:%d path:%s", errno, path); + } + return NULL; } std::fstream file; - char* buf = new char[size]; - file.open(path, std::ios::in | std::ios::binary); if (!file.is_open()) { if (DebugLogEnable) { - PrintLog("file open error"); + PrintLogLn("File open failed. path:%s", path); } return NULL; } + + char* buf = new char[size]; file.read(buf, size); file.close(); @@ -88,6 +105,16 @@ void LAppPal::UpdateTime() } void LAppPal::PrintLog(const char* format, ...) +{ + va_list args; + char buf[256]; + va_start(args, format); + _vsnprintf_s(buf, sizeof(buf), format, args); + OutputDebugStringA((LPCSTR)buf); + va_end(args); +} + +void LAppPal::PrintLogLn(const char* format, ...) { va_list args; char buf[256]; @@ -99,6 +126,16 @@ void LAppPal::PrintLog(const char* format, ...) } void LAppPal::PrintLogW(const wchar_t* format, ...) +{ + va_list args; + wchar_t buf[256]; + va_start(args, format); + _vsnwprintf_s(buf, sizeof(buf), format, args); + OutputDebugString((LPCSTR)buf); + va_end(args); +} + +void LAppPal::PrintLogLnW(const wchar_t* format, ...) { va_list args; wchar_t buf[256]; @@ -114,6 +151,11 @@ void LAppPal::PrintMessage(const csmChar* message) PrintLog("%s", message); } +void LAppPal::PrintMessageLn(const csmChar* message) +{ + PrintLogLn("%s", message); +} + void LAppPal::CoordinateFullScreenToWindow(float clientWidth, float clientHeight, float fullScreenX, float fullScreenY, float& retWindowX, float& retWindowY) { retWindowX = retWindowY = 0.0f; diff --git a/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppPal.hpp b/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppPal.hpp index c3bf8648..9afa6915 100644 --- a/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppPal.hpp +++ b/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppPal.hpp @@ -74,6 +74,17 @@ class LAppPal */ static void PrintLog(const char*, ...); + /** + * @brief ログを出力し最後に改行する + * + * ログを出力し最後に改行する + * + * @param[in] format 書式付文字列 + * @param[in] ... (可変長引数)文字列 + * + */ + static void PrintLogLn(const char*, ...); + /** * @brief ログを出力する wchar版 * @@ -85,6 +96,17 @@ class LAppPal */ static void PrintLogW(const wchar_t*, ...); + /** + * @brief ログを出力し最後に改行する wchar版 + * + * ログを出力し最後に改行する + * + * @param[in] format 書式付文字列 + * @param[in] ... (可変長引数)文字列 + * + */ + static void PrintLogLnW(const wchar_t*, ...); + /** * @brief メッセージを出力する * @@ -95,6 +117,16 @@ class LAppPal */ static void PrintMessage(const Csm::csmChar* message); + /** + * @brief メッセージを出力し最後に改行する + * + * メッセージを出力し最後に改行する + * + * @param[in] message 文字列 + * + */ + static void PrintMessageLn(const Csm::csmChar* message); + /** * @brief 座標変換 * フルスクリーン LT(-bufferX, bufferY) RB(bufferX, -bufferY) → ウィンドウ・マウス LT(0, 0) RB(bufferX, bufferY) diff --git a/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppSprite.cpp b/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppSprite.cpp index 32b548ff..7ea9c1f8 100644 --- a/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppSprite.cpp +++ b/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppSprite.cpp @@ -9,7 +9,6 @@ #include "LAppPal.hpp" #include "LAppDefine.hpp" -#include "LAppDelegate.hpp" #include "LAppTextureManager.hpp" using namespace LAppDefine; @@ -35,11 +34,6 @@ LAppSprite::LAppSprite(float x, float y, float width, float height, Csm::csmUint _color = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f); - if (!LAppDelegate::GetInstance()->GetD3dDevice()) - { - return; - } - _vertexStore = static_cast(CSM_MALLOC(sizeof(SpriteVertex) * VERTEX_NUM)); _indexStore = static_cast(CSM_MALLOC(sizeof(csmUint16) * INDEX_NUM)); @@ -65,8 +59,6 @@ LAppSprite::LAppSprite(float x, float y, float width, float height, Csm::csmUint LAppSprite::~LAppSprite() { - LAppDelegate::GetInstance()->GetTextureManager()->ReleaseTexture(_textureId); - // インデックス if (_indexStore) { @@ -81,9 +73,9 @@ LAppSprite::~LAppSprite() _vertexStore = NULL; } -void LAppSprite::Render(LPDIRECT3DDEVICE9 device, int maxWidth, int maxHeight) const +void LAppSprite::RenderImmidiate(LPDIRECT3DDEVICE9 device, ID3DXEffect* shaderEffect, int maxWidth, int maxHeight, LPDIRECT3DTEXTURE9 texture) const { - if(!_vertexStore) + if (!_vertexStore) { return; } @@ -93,75 +85,11 @@ void LAppSprite::Render(LPDIRECT3DDEVICE9 device, int maxWidth, int maxHeight) c return; // この際は描画できず } - // 頂点設定 - _vertexStore[0].x = (_rect.left - maxWidth * 0.5f) / (maxWidth * 0.5f); _vertexStore[0].y = (_rect.down - maxHeight * 0.5f) / (maxHeight * 0.5f); _vertexStore[0].u = 0.0f; _vertexStore[0].v = 0.0f; - _vertexStore[1].x = (_rect.right - maxWidth * 0.5f) / (maxWidth * 0.5f); _vertexStore[1].y = (_rect.down - maxHeight * 0.5f) / (maxHeight * 0.5f); _vertexStore[1].u = 1.0f; _vertexStore[1].v = 0.0f; - _vertexStore[2].x = (_rect.left - maxWidth * 0.5f) / (maxWidth * 0.5f); _vertexStore[2].y = (_rect.up - maxHeight * 0.5f) / (maxHeight * 0.5f); _vertexStore[2].u = 0.0f; _vertexStore[2].v = 1.0f; - _vertexStore[3].x = (_rect.right - maxWidth * 0.5f) / (maxWidth * 0.5f); _vertexStore[3].y = (_rect.up - maxHeight * 0.5f) / (maxHeight * 0.5f); _vertexStore[3].u = 1.0f; _vertexStore[3].v = 1.0f; - - { - D3DXMATRIX proj( - 1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 1.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f - ); - - // このエフェクトで描画 - ID3DXEffect* shaderEffect = LAppDelegate::GetInstance()->SetupShader(); - if (shaderEffect) - { - // レンダーステート - device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); - device->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD); - device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); - - device->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, false); - device->SetRenderState(D3DRS_ALPHABLENDENABLE, true); - - - UINT numPass = 0; - shaderEffect->SetTechnique("ShaderNames_Normal"); - - // numPassには指定のtechnique内に含まれるpassの数が返る - shaderEffect->Begin(&numPass, 0); - shaderEffect->BeginPass(0); - - shaderEffect->SetMatrix("projectMatrix", &proj); - - shaderEffect->SetVector("baseColor", &_color); - - IDirect3DTexture9* texture = NULL; - if (LAppDelegate::GetInstance()->GetTextureManager()->GetTexture(_textureId, texture)) - { - shaderEffect->SetTexture("mainTexture", texture); - } - shaderEffect->CommitChanges(); - - - { - // 描画 - device->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, VERTEX_NUM, 2, _indexStore, D3DFMT_INDEX16, _vertexStore, sizeof(SpriteVertex)); - } - - shaderEffect->EndPass(); - shaderEffect->End(); - } - } -} - -void LAppSprite::RenderImmidiate(LPDIRECT3DDEVICE9 device, int maxWidth, int maxHeight, LPDIRECT3DTEXTURE9 texture) const -{ - if (!_vertexStore) + if (shaderEffect == NULL) { return; } - if (maxWidth == 0 || maxHeight == 0) - { - return; // この際は描画できず - } - // 頂点設定 _vertexStore[0].x = (_rect.left - maxWidth * 0.5f) / (maxWidth * 0.5f); _vertexStore[0].y = (_rect.down - maxHeight * 0.5f) / (maxHeight * 0.5f); _vertexStore[0].u = 0.0f; _vertexStore[0].v = 0.0f; _vertexStore[1].x = (_rect.right - maxWidth * 0.5f) / (maxWidth * 0.5f); _vertexStore[1].y = (_rect.down - maxHeight * 0.5f) / (maxHeight * 0.5f); _vertexStore[1].u = 1.0f; _vertexStore[1].v = 0.0f; @@ -176,60 +104,49 @@ void LAppSprite::RenderImmidiate(LPDIRECT3DDEVICE9 device, int maxWidth, int max 0.0f, 0.0f, 0.0f, 1.0f ); - // このエフェクトで描画 - ID3DXEffect* shaderEffect = LAppDelegate::GetInstance()->SetupShader(); - if (shaderEffect) - { - // レンダーステート - device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); - device->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD); - device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); + // レンダーステート + device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); + device->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD); + device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); - device->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, false); - device->SetRenderState(D3DRS_ALPHABLENDENABLE, true); + device->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, false); + device->SetRenderState(D3DRS_ALPHABLENDENABLE, true); - UINT numPass = 0; - shaderEffect->SetTechnique("ShaderNames_Normal"); + UINT numPass = 0; + shaderEffect->SetTechnique("ShaderNames_Normal"); - // numPassには指定のtechnique内に含まれるpassの数が返る - shaderEffect->Begin(&numPass, 0); - shaderEffect->BeginPass(0); + // numPassには指定のtechnique内に含まれるpassの数が返る + shaderEffect->Begin(&numPass, 0); + shaderEffect->BeginPass(0); - shaderEffect->SetMatrix("projectMatrix", &proj); + shaderEffect->SetMatrix("projectMatrix", &proj); - shaderEffect->SetVector("baseColor", &_color); + shaderEffect->SetVector("baseColor", &_color); - { - shaderEffect->SetTexture("mainTexture", texture); - } - shaderEffect->CommitChanges(); + shaderEffect->SetTexture("mainTexture", texture); + shaderEffect->CommitChanges(); - { - // 描画 - device->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, VERTEX_NUM, 2, _indexStore, D3DFMT_INDEX16, _vertexStore, sizeof(SpriteVertex)); - } + // 描画 + device->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, VERTEX_NUM, 2, _indexStore, D3DFMT_INDEX16, _vertexStore, sizeof(SpriteVertex)); - shaderEffect->EndPass(); - shaderEffect->End(); - } + shaderEffect->EndPass(); + shaderEffect->End(); } } -bool LAppSprite::IsHit(float pointX, float pointY) const +bool LAppSprite::IsHit(float pointX, float pointY, int clientWidth, int clientHeight) const { - // フルスクリーン座標に変換 - float coordX = 0.0f, coordY = 0.0f; - int clientWidth = 0, clientHeight = 0; - LAppDelegate::GetClientSize(clientWidth, clientHeight); - LAppPal::CoordinateWindowToFullScreen(static_cast(clientWidth), static_cast(clientHeight), pointX, pointY, coordX, coordY); - if (clientWidth == 0 || clientHeight == 0) {// この際はヒットしない return false; } + // フルスクリーン座標に変換 + float coordX = 0.0f, coordY = 0.0f; + LAppPal::CoordinateWindowToFullScreen(static_cast(clientWidth), static_cast(clientHeight), pointX, pointY, coordX, coordY); + coordX = (clientWidth+coordX)/(2.0f*clientWidth) * clientWidth; coordY = (clientHeight+coordY)/(2.0f*clientHeight) * clientHeight; diff --git a/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppSprite.hpp b/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppSprite.hpp index 616adde2..63e3d40c 100644 --- a/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppSprite.hpp +++ b/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppSprite.hpp @@ -67,29 +67,25 @@ class LAppSprite */ Csm::csmUint64 GetTextureId() { return _textureId; } - /** - * @brief 描画する - * @param[in] device 描画デバイス - * @param[in] width 幅 - * @param[in] height 高さ - */ - void Render(LPDIRECT3DDEVICE9 device, int width, int height) const; - /** * @brief テクスチャを指定しての描画 - * @param[in] width 幅 - * @param[in] height 高さ - * @param[in] resourceView 使用テクスチャ + * @param[in] device D3D9デバイス + * @param[in] shaderEffect シェーダーエフェクト + * @param[in] width 幅 + * @param[in] height 高さ + * @param[in] texture 使用テクスチャ */ - void RenderImmidiate(LPDIRECT3DDEVICE9 device, int maxWidth, int maxHeight, LPDIRECT3DTEXTURE9 texture) const; + void RenderImmidiate(LPDIRECT3DDEVICE9 device, ID3DXEffect* shaderEffect, int maxWidth, int maxHeight, LPDIRECT3DTEXTURE9 texture) const; /** * @brief ヒットチェック * * @param[in] pointX x座標 * @param[in] pointY y座標 + * @param[in] clientWidth クライアントウィンドウ幅 + * @param[in] clientHeight クライアントウィンドウ高さ */ - bool IsHit(float pointX, float pointY) const; + bool IsHit(float pointX, float pointY, int clientWidth, int clientHeight) const; /** * @brief 色設定 @@ -114,4 +110,3 @@ class LAppSprite Live2D::Cubism::Framework::csmUint16* _indexStore; ///< インデックスをストアしておく領域 D3DXVECTOR4 _color; ///< 描画色 }; - diff --git a/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppTextureManager.cpp b/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppTextureManager.cpp index ecf96373..eb096515 100644 --- a/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppTextureManager.cpp +++ b/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppTextureManager.cpp @@ -103,7 +103,7 @@ LAppTextureManager::TextureInfo* LAppTextureManager::CreateTextureFromPngFile(st // 失敗 if (DebugLogEnable) { - LAppPal::PrintLog("Texture Load Error : %s", fileName.c_str()); + LAppPal::PrintLogLn("Texture Load Error : %s", fileName.c_str()); } delete textureInfo; diff --git a/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppView.cpp b/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppView.cpp index 3be8e7c6..c8148b5c 100644 --- a/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppView.cpp +++ b/Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppView.cpp @@ -45,14 +45,12 @@ LAppView::LAppView(): LAppView::~LAppView() { _renderBuffer.DestroyOffscreenSurface(); - delete _renderSprite; + + ReleaseSprite(); delete _viewMatrix; delete _deviceToScreen; delete _touchManager; - delete _back; - delete _gear; - delete _power; } void LAppView::Initialize() @@ -115,22 +113,38 @@ void LAppView::Render() return; } + LAppTextureManager* textureManager = LAppDelegate::GetInstance()->GetTextureManager(); + if (!textureManager) + { + return; + } + + ID3DXEffect* shaderEffect = LAppDelegate::GetInstance()->SetupShader(); + if (!shaderEffect) + { + return; + } + // スプライト描画 int width, height; LAppDelegate::GetInstance()->GetClientSize(width, height); { + IDirect3DTexture9* texture = NULL; if (_back) { - _back->Render(device, width, height); + textureManager->GetTexture(_back->GetTextureId(), texture); + _back->RenderImmidiate(device, shaderEffect, width, height, texture); } if (_gear) { - _gear->Render(device, width, height); + textureManager->GetTexture(_gear->GetTextureId(), texture); + _gear->RenderImmidiate(device, shaderEffect, width, height, texture); } if (_power) { - _power->Render(device, width, height); + textureManager->GetTexture(_power->GetTextureId(), texture); + _power->RenderImmidiate(device, shaderEffect, width, height, texture); } } @@ -150,7 +164,7 @@ void LAppView::Render() if (model) { - _renderSprite->RenderImmidiate(LAppDelegate::GetInstance()->GetD3dDevice(), width, height, model->GetRenderBuffer().GetTexture()); + _renderSprite->RenderImmidiate(device, shaderEffect, width, height, model->GetRenderBuffer().GetTexture()); } } } @@ -205,10 +219,35 @@ void LAppView::InitializeSprite() void LAppView::ReleaseSprite() { - delete _renderSprite; _renderSprite = NULL; - delete _power; _power = NULL; - delete _gear; _gear = NULL; - delete _back; _back = NULL; + LAppTextureManager* textureManager = LAppDelegate::GetInstance()->GetTextureManager(); + + if (_renderSprite) + { + textureManager->ReleaseTexture(_renderSprite->GetTextureId()); + } + delete _renderSprite; + _renderSprite = NULL; + + if (_power) + { + textureManager->ReleaseTexture(_power->GetTextureId()); + } + delete _power; + _power = NULL; + + if (_gear) + { + textureManager->ReleaseTexture(_gear->GetTextureId()); + } + delete _gear; + _gear = NULL; + + if (_back) + { + textureManager->ReleaseTexture(_back->GetTextureId()); + } + delete _back; + _back = NULL; // スプライト用のシェーダ・頂点宣言も開放 LAppDelegate::GetInstance()->ReleaseShader(); @@ -253,18 +292,18 @@ void LAppView::OnTouchesEnded(float px, float py) const float y = _deviceToScreen->TransformY(py); // 論理座標変換した座標を取得。 if (DebugTouchLogEnable) { - LAppPal::PrintLog("[APP]touchesEnded x:%.2f y:%.2f", x, y); + LAppPal::PrintLogLn("[APP]touchesEnded x:%.2f y:%.2f", x, y); } live2DManager->OnTap(x, y); // 歯車にタップしたか - if (_gear && _gear->IsHit(px, py)) + if (_gear && _gear->IsHit(px, py, width, height)) { live2DManager->NextScene(); } // 電源ボタンにタップしたか - if (_power && _power->IsHit(px, py)) + if (_power && _power->IsHit(px, py, width, height)) { LAppDelegate::GetInstance()->AppEnd(); } @@ -340,12 +379,15 @@ void LAppView::PostModelDraw(LAppModel &refModel) // LAppViewの持つフレームバッファを使うなら、スプライトへの描画はここ if (_renderTarget == SelectTarget_ViewFrameBuffer && _renderSprite) { + ID3DXEffect* shaderEffect = LAppDelegate::GetInstance()->SetupShader(); + // スプライト描画 int width, height; LAppDelegate::GetInstance()->GetClientSize(width, height); _renderSprite->SetColor(1.0f, 1.0f, 1.0f, GetSpriteAlpha(0)); - _renderSprite->RenderImmidiate(LAppDelegate::GetInstance()->GetD3dDevice(), width, height, useTarget->GetTexture()); + _renderSprite->RenderImmidiate(LAppDelegate::GetInstance()->GetD3dDevice(), + shaderEffect, width, height, useTarget->GetTexture()); } } } diff --git a/Samples/D3D9/Demo/proj.d3d9.cmake/src/mainMinimum.cpp b/Samples/D3D9/Demo/proj.d3d9.cmake/src/mainMinimum.cpp index 559e318b..a3183fd5 100644 --- a/Samples/D3D9/Demo/proj.d3d9.cmake/src/mainMinimum.cpp +++ b/Samples/D3D9/Demo/proj.d3d9.cmake/src/mainMinimum.cpp @@ -172,7 +172,7 @@ LRESULT WINAPI MsgProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) */ static bool InitializeSystem() { - LAppPal::PrintLog("START"); + LAppPal::PrintLogLn("START"); CubismDirectXRenderer* directXRenderer = CubismDirectXRenderer::GetInstance(); @@ -197,7 +197,7 @@ static bool InitializeSystem() CW_USEDEFAULT, CW_USEDEFAULT, rect.right, rect.bottom, NULL, NULL, directXRenderer->_windowClass.hInstance, NULL); if (directXRenderer->_windowHandle == NULL) { - LAppPal::PrintLog("Fail Create Window"); + LAppPal::PrintLogLn("Fail Create Window"); return false; } @@ -208,7 +208,7 @@ static bool InitializeSystem() // Direct3D9 init if (!(directXRenderer->_direct3D = Direct3DCreate9(D3D_SDK_VERSION))) { - LAppPal::PrintLog("Fail Direct3D Initialize"); + LAppPal::PrintLogLn("Fail Direct3D Initialize"); return false; } @@ -236,7 +236,7 @@ static bool InitializeSystem() if (FAILED(createResult)) { - LAppPal::PrintLog("Fail Direct3D Create Device %x", createResult); + LAppPal::PrintLogLn("Fail Direct3D Create Device %x", createResult); return false; } diff --git a/Samples/Metal/Demo/proj.ios.cmake/src/AppDelegate.mm b/Samples/Metal/Demo/proj.ios.cmake/src/AppDelegate.mm index 9d60c54f..c518cc23 100644 --- a/Samples/Metal/Demo/proj.ios.cmake/src/AppDelegate.mm +++ b/Samples/Metal/Demo/proj.ios.cmake/src/AppDelegate.mm @@ -75,7 +75,7 @@ - (void)applicationWillTerminate:(UIApplication *)application { - (void)initializeCubism { - _cubismOption.LogFunction = LAppPal::PrintMessage; + _cubismOption.LogFunction = LAppPal::PrintMessageLn; _cubismOption.LoggingLevel = LAppDefine::CubismLoggingLevel; Csm::CubismFramework::StartUp(&_cubismAllocator,&_cubismOption); diff --git a/Samples/Metal/Demo/proj.ios.cmake/src/LAppLive2DManager.mm b/Samples/Metal/Demo/proj.ios.cmake/src/LAppLive2DManager.mm index 301f5d52..656333a4 100644 --- a/Samples/Metal/Demo/proj.ios.cmake/src/LAppLive2DManager.mm +++ b/Samples/Metal/Demo/proj.ios.cmake/src/LAppLive2DManager.mm @@ -29,7 +29,7 @@ @implementation LAppLive2DManager void FinishedMotion(Csm::ACubismMotion* self) { - LAppPal::PrintLog("Motion Finished: %x", self); + LAppPal::PrintLogLn("Motion Finished: %x", self); } int CompareCsmString(const void* a, const void* b) @@ -179,7 +179,7 @@ - (void)onTap:(Csm::csmFloat32)x floatY:(Csm::csmFloat32)y; { if (LAppDefine::DebugLogEnable) { - LAppPal::PrintLog("[APP]tap point: {x:%.2f y:%.2f}", x, y); + LAppPal::PrintLogLn("[APP]tap point: {x:%.2f y:%.2f}", x, y); } for (Csm::csmUint32 i = 0; i < _models.GetSize(); i++) @@ -188,7 +188,7 @@ - (void)onTap:(Csm::csmFloat32)x floatY:(Csm::csmFloat32)y; { if (LAppDefine::DebugLogEnable) { - LAppPal::PrintLog("[APP]hit area: [%s]", LAppDefine::HitAreaNameHead); + LAppPal::PrintLogLn("[APP]hit area: [%s]", LAppDefine::HitAreaNameHead); } _models[i]->SetRandomExpression(); } @@ -196,7 +196,7 @@ - (void)onTap:(Csm::csmFloat32)x floatY:(Csm::csmFloat32)y; { if (LAppDefine::DebugLogEnable) { - LAppPal::PrintLog("[APP]hit area: [%s]", LAppDefine::HitAreaNameBody); + LAppPal::PrintLogLn("[APP]hit area: [%s]", LAppDefine::HitAreaNameBody); } _models[i]->StartRandomMotion(LAppDefine::MotionGroupTapBody, LAppDefine::PriorityNormal, FinishedMotion); } @@ -231,7 +231,8 @@ - (void)onUpdate:(id )commandBuffer currentDrawable:(idGetColorBuffer()]; + _sprite = [[LAppSprite alloc] initWithMyVar:width * 0.5f Y:height * 0.5f Width:width Height:height + MaxWidth:width MaxHeight:height Texture:_renderBuffer->GetColorBuffer()]; } } @@ -254,7 +255,7 @@ - (void)onUpdate:(id )commandBuffer currentDrawable:(idGetModel() == NULL) { - LAppPal::PrintLog("Failed to model->GetModel()."); + LAppPal::PrintLogLn("Failed to model->GetModel()."); continue; } @@ -323,7 +324,8 @@ - (void)onUpdate:(id )commandBuffer currentDrawable:(id renderEncoder = [commandBuffer renderCommandEncoderWithDescriptor:renderPassDescriptor]; Csm::Rendering::CubismOffscreenSurface_Metal& useTarget = model->GetRenderBuffer(); - LAppSprite* depthSprite = [[LAppSprite alloc] initWithMyVar:width * 0.5f Y:height * 0.5f Width:width Height:height Texture:useTarget.GetColorBuffer()]; + LAppSprite* depthSprite = [[LAppSprite alloc] initWithMyVar:width * 0.5f Y:height * 0.5f Width:width Height:height + MaxWidth:width MaxHeight:height Texture:useTarget.GetColorBuffer()]; float a = i < 1 ? 1.0f : model->GetOpacity(); // 片方のみ不透明度を取得できるようにする [depthSprite SetColor:1.0f g:1.0f b:1.0f a:a]; [depthSprite renderImmidiate:renderEncoder]; @@ -344,7 +346,7 @@ - (void)changeScene:(Csm::csmInt32)index; _sceneIndex = index; if (LAppDefine::DebugLogEnable) { - LAppPal::PrintLog("[APP]model index: %d", _sceneIndex); + LAppPal::PrintLogLn("[APP]model index: %d", _sceneIndex); } // model3.jsonのパスを決定する. diff --git a/Samples/Metal/Demo/proj.ios.cmake/src/LAppModel.mm b/Samples/Metal/Demo/proj.ios.cmake/src/LAppModel.mm index e2bb4a4b..702278af 100644 --- a/Samples/Metal/Demo/proj.ios.cmake/src/LAppModel.mm +++ b/Samples/Metal/Demo/proj.ios.cmake/src/LAppModel.mm @@ -31,7 +31,7 @@ { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]create buffer: %s ", path); + LAppPal::PrintLogLn("[APP]create buffer: %s ", path); } return LAppPal::LoadFileAsBytes(path,size); } @@ -40,7 +40,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]delete buffer: %s", path); + LAppPal::PrintLogLn("[APP]delete buffer: %s", path); } LAppPal::ReleaseBytes(buffer); } @@ -108,7 +108,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") if (_debugMode) { - LAppPal::PrintLog("[APP]load model setting: %s", fileName); + LAppPal::PrintLogLn("[APP]load model setting: %s", fileName); } csmSizeInt size; @@ -122,7 +122,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") if (_model == NULL) { - LAppPal::PrintLog("Failed to LoadAssets()."); + LAppPal::PrintLogLn("Failed to LoadAssets()."); return; } @@ -150,7 +150,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") if (_debugMode) { - LAppPal::PrintLog("[APP]create model: %s", setting->GetModelFileName()); + LAppPal::PrintLogLn("[APP]create model: %s", setting->GetModelFileName()); } buffer = CreateBuffer(path.GetRawString(), &size); @@ -258,7 +258,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") if (_modelSetting == NULL || _modelMatrix == NULL) { - LAppPal::PrintLog("Failed to SetupModel()."); + LAppPal::PrintLogLn("Failed to SetupModel()."); return; } @@ -294,7 +294,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") if (_debugMode) { - LAppPal::PrintLog("[APP]load motion: %s => [%s_%d] ", path.GetRawString(), group, i); + LAppPal::PrintLogLn("[APP]load motion: %s => [%s_%d] ", path.GetRawString(), group, i); } csmByte* buffer; @@ -462,7 +462,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") { if (_debugMode) { - LAppPal::PrintLog("[APP]can't start motion."); + LAppPal::PrintLogLn("[APP]can't start motion."); } return InvalidMotionQueueEntryHandleValue; } @@ -518,7 +518,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") if (_debugMode) { - LAppPal::PrintLog("[APP]start motion: [%s_%d]", group, no); + LAppPal::PrintLogLn("[APP]start motion: [%s_%d]", group, no); } return _motionManager->StartMotionPriority(motion, autoDelete, priority); } @@ -583,7 +583,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") ACubismMotion* motion = _expressions[expressionID]; if (_debugMode) { - LAppPal::PrintLog("[APP]expression: [%s]", expressionID); + LAppPal::PrintLogLn("[APP]expression: [%s]", expressionID); } if (motion != NULL) @@ -594,7 +594,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") { if (_debugMode) { - LAppPal::PrintLog("[APP]expression[%s] is null ", expressionID); + LAppPal::PrintLogLn("[APP]expression[%s] is null ", expressionID); } } } diff --git a/Samples/Metal/Demo/proj.ios.cmake/src/LAppPal.h b/Samples/Metal/Demo/proj.ios.cmake/src/LAppPal.h index 5666240a..006ad61e 100644 --- a/Samples/Metal/Demo/proj.ios.cmake/src/LAppPal.h +++ b/Samples/Metal/Demo/proj.ios.cmake/src/LAppPal.h @@ -55,25 +55,25 @@ class LAppPal static void UpdateTime(); /** - * @brief ログを出力する + * @brief ログを出力し最後に改行する * - * ログを出力する + * ログを出力し最後に改行する * * @param[in] format 書式付文字列 * @param[in] ... (可変長引数)文字列 * */ - static void PrintLog(const Csm::csmChar* format, ...); + static void PrintLogLn(const Csm::csmChar* format, ...); /** - * @brief メッセージを出力する + * @brief メッセージを出力し最後に改行する * - * メッセージを出力する + * メッセージを出力し最後に改行する * * @param[in] message 文字列 * */ - static void PrintMessage(const Csm::csmChar* message); + static void PrintMessageLn(const Csm::csmChar* message); private: static double s_currentFrame; diff --git a/Samples/Metal/Demo/proj.ios.cmake/src/LAppPal.mm b/Samples/Metal/Demo/proj.ios.cmake/src/LAppPal.mm index 6254df41..7a25c52e 100644 --- a/Samples/Metal/Demo/proj.ios.cmake/src/LAppPal.mm +++ b/Samples/Metal/Demo/proj.ios.cmake/src/LAppPal.mm @@ -37,6 +37,18 @@ inDirectory:[NSString stringWithUTF8String:pathname.c_str()]]; NSData *data = [NSData dataWithContentsOfFile:castFilePath]; + + if (data == nil) + { + PrintLogLn("File load failed : %s", filePath.c_str()); + return NULL; + } + else if (data.length == 0) + { + PrintLogLn("File is loaded but file size is zero : %s", filePath.c_str()); + return NULL; + } + NSUInteger len = [data length]; Byte *byteData = (Byte*)malloc(len); memcpy(byteData, [data bytes], len); @@ -59,7 +71,7 @@ s_lastFrame = s_currentFrame; } -void LAppPal::PrintLog(const csmChar* format, ...) +void LAppPal::PrintLogLn(const csmChar* format, ...) { va_list args; Csm::csmChar buf[256]; @@ -69,7 +81,7 @@ va_end(args); } -void LAppPal::PrintMessage(const csmChar* message) +void LAppPal::PrintMessageLn(const csmChar* message) { - PrintLog("%s", message); + PrintLogLn("%s", message); } diff --git a/Samples/Metal/Demo/proj.ios.cmake/src/LAppSprite.h b/Samples/Metal/Demo/proj.ios.cmake/src/LAppSprite.h index 7218fa7c..e1962b6d 100644 --- a/Samples/Metal/Demo/proj.ios.cmake/src/LAppSprite.h +++ b/Samples/Metal/Demo/proj.ios.cmake/src/LAppSprite.h @@ -35,9 +35,12 @@ typedef struct * @param[in] y y座標 * @param[in] width 横幅 * @param[in] height 高さ - * @param[in] texture テクスチャ + * @param[in] maxWidth 最大幅 + * @param[in] maxHeight 最大高さ + * @param[in] texture テクスチャ */ -- (id)initWithMyVar:(float)x Y:(float)y Width:(float)width Height:(float)height Texture:(id ) texture; +- (id)initWithMyVar:(float)x Y:(float)y Width:(float)width Height:(float)height + MaxWidth:(float)maxWidth MaxHeight:(float)maxHeight Texture:(id ) texture; /** * @brief 解放処理 @@ -56,8 +59,10 @@ typedef struct * @param[in] y y座標 * @param[in] width 横幅 * @param[in] height 高さ + * @param[in] maxWidth 最大幅 + * @param[in] maxHeight 最大高さ */ -- (void)resizeImmidiate:(float)x Y:(float)y Width:(float)width Height:(float)height; +- (void)resizeImmidiate:(float)x Y:(float)y Width:(float)width Height:(float)height MaxWidth:(float)maxWidth MaxHeight:(float)maxHeight; /** * @brief コンストラクタ diff --git a/Samples/Metal/Demo/proj.ios.cmake/src/LAppSprite.mm b/Samples/Metal/Demo/proj.ios.cmake/src/LAppSprite.mm index c6e52be0..0684703c 100644 --- a/Samples/Metal/Demo/proj.ios.cmake/src/LAppSprite.mm +++ b/Samples/Metal/Demo/proj.ios.cmake/src/LAppSprite.mm @@ -7,7 +7,6 @@ #import "LAppSprite.h" #import -#import "AppDelegate.h" #import #import #import "Rendering/Metal/CubismRenderingInstanceSingleton_Metal.h" @@ -32,7 +31,8 @@ @implementation LAppSprite } BaseColor; -- (id)initWithMyVar:(float)x Y:(float)y Width:(float)width Height:(float)height Texture:(id ) texture +- (id)initWithMyVar:(float)x Y:(float)y Width:(float)width Height:(float)height + MaxWidth:(float)maxWidth MaxHeight:(float)maxHeight Texture:(id ) texture { self = [super self]; @@ -53,7 +53,7 @@ - (id)initWithMyVar:(float)x Y:(float)y Width:(float)width Height:(float)height CubismRenderingInstanceSingleton_Metal *single = [CubismRenderingInstanceSingleton_Metal sharedManager]; id device = [single getMTLDevice]; - [self SetMTLBffer:device]; + [self SetMTLBuffer:device MaxWidth:maxWidth MaxHeight:maxHeight]; [self SetMTLFunction:device]; } @@ -110,7 +110,7 @@ - (void)renderImmidiate:(id)renderEncoder [renderEncoder drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4]; } -- (void)resizeImmidiate:(float)x Y:(float)y Width:(float)width Height:(float)height +- (void)resizeImmidiate:(float)x Y:(float)y Width:(float)width Height:(float)height MaxWidth:(float)maxWidth MaxHeight:(float)maxHeight { _rect.left = (x - width * 0.5f); _rect.right = (x + width * 0.5f); @@ -119,7 +119,7 @@ - (void)resizeImmidiate:(float)x Y:(float)y Width:(float)width Height:(float)hei CubismRenderingInstanceSingleton_Metal *single = [CubismRenderingInstanceSingleton_Metal sharedManager]; id device = [single getMTLDevice]; - [self SetMTLBffer:device]; + [self SetMTLBuffer:device MaxWidth:maxWidth MaxHeight:maxHeight]; return self; } @@ -175,13 +175,8 @@ - (NSString*)GetMetalShader { return string; } -- (void)SetMTLBffer:(id )device +- (void)SetMTLBuffer:(id )device MaxWidth:(float)maxWidth MaxHeight:(float)maxHeight { - AppDelegate* delegate = (AppDelegate*) [[UIApplication sharedApplication] delegate]; - ViewController* view = [delegate viewController]; - float maxWidth = view.view.frame.size.width; - float maxHeight = view.view.frame.size.height; - vector_float4 positionVertex[] = { {(_rect.left - maxWidth * 0.5f) / (maxWidth * 0.5f), (_rect.down - maxHeight * 0.5f) / (maxHeight * 0.5f), 0, 1}, @@ -282,4 +277,3 @@ - (void)SetMTLRenderPipelineState:(id )device pipelineDescriptor:(MTL } } @end - diff --git a/Samples/Metal/Demo/proj.ios.cmake/src/ViewController.mm b/Samples/Metal/Demo/proj.ios.cmake/src/ViewController.mm index 03749017..86c898b2 100644 --- a/Samples/Metal/Demo/proj.ios.cmake/src/ViewController.mm +++ b/Samples/Metal/Demo/proj.ios.cmake/src/ViewController.mm @@ -226,7 +226,7 @@ - (void)initializeSprite float y = height * 0.5f; float fWidth = static_cast(backgroundTexture->width * 2.0f); float fHeight = static_cast(height) * 0.95f; - _back = [[LAppSprite alloc] initWithMyVar:x Y:y Width:fWidth Height:fHeight Texture:backgroundTexture->id]; + _back = [[LAppSprite alloc] initWithMyVar:x Y:y Width:fWidth Height:fHeight MaxWidth:width MaxHeight:height Texture:backgroundTexture->id]; //モデル変更ボタン imageName = GearImageName; @@ -235,7 +235,7 @@ - (void)initializeSprite y = static_cast(height - gearTexture->height * 0.5f); fWidth = static_cast(gearTexture->width); fHeight = static_cast(gearTexture->height); - _gear = [[LAppSprite alloc] initWithMyVar:x Y:y Width:fWidth Height:fHeight Texture:gearTexture->id]; + _gear = [[LAppSprite alloc] initWithMyVar:x Y:y Width:fWidth Height:fHeight MaxWidth:width MaxHeight:height Texture:gearTexture->id]; //電源ボタン imageName = PowerImageName; @@ -244,31 +244,36 @@ - (void)initializeSprite y = static_cast(powerTexture->height * 0.5f); fWidth = static_cast(powerTexture->width); fHeight = static_cast(powerTexture->height); - _power = [[LAppSprite alloc] initWithMyVar:x Y:y Width:fWidth Height:fHeight Texture:powerTexture->id]; + _power = [[LAppSprite alloc] initWithMyVar:x Y:y Width:fWidth Height:fHeight MaxWidth:width MaxHeight:height Texture:powerTexture->id]; } - (void)resizeSprite:(float)width Height:(float)height { + AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; + ViewController* view = [delegate viewController]; + float maxWidth = view.view.frame.size.width; + float maxHeight = view.view.frame.size.height; + //背景 float x = width * 0.5f; float y = height * 0.5f; float fWidth = static_cast(_back.GetTextureId.width * 2.0f); float fHeight = static_cast(height) * 0.95f; - [_back resizeImmidiate:x Y:y Width:fWidth Height:fHeight]; + [_back resizeImmidiate:x Y:y Width:fWidth Height:fHeight MaxWidth:maxWidth MaxHeight:maxHeight]; //モデル変更ボタン x = static_cast(width - _gear.GetTextureId.width * 0.5f); y = static_cast(height - _gear.GetTextureId.height * 0.5f); fWidth = static_cast(_gear.GetTextureId.width); fHeight = static_cast(_gear.GetTextureId.height); - [_gear resizeImmidiate:x Y:y Width:fWidth Height:fHeight]; + [_gear resizeImmidiate:x Y:y Width:fWidth Height:fHeight MaxWidth:maxWidth MaxHeight:maxHeight]; //電源ボタン x = static_cast(width - _power.GetTextureId.width * 0.5f); y = static_cast(_power.GetTextureId.height * 0.5f); fWidth = static_cast(_power.GetTextureId.width); fHeight = static_cast(_power.GetTextureId.height); - [_power resizeImmidiate:x Y:y Width:fWidth Height:fHeight]; + [_power resizeImmidiate:x Y:y Width:fWidth Height:fHeight MaxWidth:maxWidth MaxHeight:maxHeight]; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event @@ -311,7 +316,7 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event if (DebugTouchLogEnable) { - LAppPal::PrintLog("[APP]touchesEnded x:%.2f y:%.2f", x, y); + LAppPal::PrintLogLn("[APP]touchesEnded x:%.2f y:%.2f", x, y); } [live2DManager onTap:x floatY:y]; diff --git a/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/cpp/LAppDelegate.cpp b/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/cpp/LAppDelegate.cpp index 6cdf8719..77327f09 100644 --- a/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/cpp/LAppDelegate.cpp +++ b/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/cpp/LAppDelegate.cpp @@ -148,7 +148,7 @@ LAppDelegate::LAppDelegate(): _view(NULL) { // Setup Cubism - _cubismOption.LogFunction = LAppPal::PrintMessage; + _cubismOption.LogFunction = LAppPal::PrintMessageLn; _cubismOption.LoggingLevel = LAppDefine::CubismLoggingLevel; CubismFramework::CleanUp(); CubismFramework::StartUp(&_cubismAllocator, &_cubismOption); diff --git a/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/cpp/LAppLive2DManager.cpp b/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/cpp/LAppLive2DManager.cpp index a7c7e209..429f4f1e 100644 --- a/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/cpp/LAppLive2DManager.cpp +++ b/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/cpp/LAppLive2DManager.cpp @@ -25,7 +25,7 @@ namespace { void FinishedMotion(ACubismMotion* self) { - LAppPal::PrintLog("Motion Finished: %x", self); + LAppPal::PrintLogLn("Motion Finished: %x", self); } int CompareCsmString(const void* a, const void* b) @@ -127,7 +127,7 @@ void LAppLive2DManager::OnTap(csmFloat32 x, csmFloat32 y) { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]tap point: {x:%.2f y:%.2f}", x, y); + LAppPal::PrintLogLn("[APP]tap point: {x:%.2f y:%.2f}", x, y); } for (csmUint32 i = 0; i < _models.GetSize(); i++) @@ -136,7 +136,7 @@ void LAppLive2DManager::OnTap(csmFloat32 x, csmFloat32 y) { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameHead); + LAppPal::PrintLogLn("[APP]hit area: [%s]", HitAreaNameHead); } _models[i]->SetRandomExpression(); } @@ -144,7 +144,7 @@ void LAppLive2DManager::OnTap(csmFloat32 x, csmFloat32 y) { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameBody); + LAppPal::PrintLogLn("[APP]hit area: [%s]", HitAreaNameBody); } _models[i]->StartRandomMotion(MotionGroupTapBody, PriorityNormal, FinishedMotion); } @@ -164,7 +164,7 @@ void LAppLive2DManager::OnUpdate() const if (model->GetModel() == NULL) { - LAppPal::PrintLog("Failed to model->GetModel()."); + LAppPal::PrintLogLn("Failed to model->GetModel()."); continue; } @@ -207,7 +207,7 @@ void LAppLive2DManager::ChangeScene(Csm::csmInt32 index) _sceneIndex = index; if (DebugLogEnable) { - LAppPal::PrintLog("[APP]model index: %d", _sceneIndex); + LAppPal::PrintLogLn("[APP]model index: %d", _sceneIndex); } // model3.jsonのパスを決定する. diff --git a/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/cpp/LAppModel.cpp b/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/cpp/LAppModel.cpp index e444e03c..ab659ba6 100644 --- a/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/cpp/LAppModel.cpp +++ b/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/cpp/LAppModel.cpp @@ -30,7 +30,7 @@ namespace { { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]create buffer: %s ", path); + LAppPal::PrintLogLn("[APP]create buffer: %s ", path); } return LAppPal::LoadFileAsBytes(path, size); } @@ -39,7 +39,7 @@ namespace { { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]delete buffer: %s", path); + LAppPal::PrintLogLn("[APP]delete buffer: %s", path); } LAppPal::ReleaseBytes(buffer); } @@ -84,7 +84,7 @@ void LAppModel::LoadAssets(const csmChar* dir, const csmChar* fileName) if (_debugMode) { - LAppPal::PrintLog("[APP]load model setting: %s", fileName); + LAppPal::PrintLogLn("[APP]load model setting: %s", fileName); } csmSizeInt size; @@ -98,7 +98,7 @@ void LAppModel::LoadAssets(const csmChar* dir, const csmChar* fileName) if (_model == NULL) { - LAppPal::PrintLog("Failed to LoadAssets()."); + LAppPal::PrintLogLn("Failed to LoadAssets()."); return; } @@ -126,7 +126,7 @@ void LAppModel::SetupModel(ICubismModelSetting* setting) if (_debugMode) { - LAppPal::PrintLog("[APP]create model: %s", setting->GetModelFileName()); + LAppPal::PrintLogLn("[APP]create model: %s", setting->GetModelFileName()); } buffer = CreateBuffer(path.GetRawString(), &size); @@ -234,7 +234,7 @@ void LAppModel::SetupModel(ICubismModelSetting* setting) if (_modelSetting == NULL || _modelMatrix == NULL) { - LAppPal::PrintLog("Failed to SetupModel()."); + LAppPal::PrintLogLn("Failed to SetupModel()."); return; } @@ -270,7 +270,7 @@ void LAppModel::PreloadMotionGroup(const csmChar* group) if (_debugMode) { - LAppPal::PrintLog("[APP]load motion: %s => [%s_%d] ", path.GetRawString(), group, i); + LAppPal::PrintLogLn("[APP]load motion: %s => [%s_%d] ", path.GetRawString(), group, i); } csmByte* buffer; @@ -448,7 +448,7 @@ CubismMotionQueueEntryHandle LAppModel::StartMotion(const csmChar* group, csmInt { if (_debugMode) { - LAppPal::PrintLog("[APP]can't start motion."); + LAppPal::PrintLogLn("[APP]can't start motion."); } return InvalidMotionQueueEntryHandleValue; } @@ -504,7 +504,7 @@ CubismMotionQueueEntryHandle LAppModel::StartMotion(const csmChar* group, csmInt if (_debugMode) { - LAppPal::PrintLog("[APP]start motion: [%s_%d]", group, no); + LAppPal::PrintLogLn("[APP]start motion: [%s_%d]", group, no); } return _motionManager->StartMotionPriority(motion, autoDelete, priority); } @@ -569,7 +569,7 @@ void LAppModel::SetExpression(const csmChar* expressionID) ACubismMotion* motion = _expressions[expressionID]; if (_debugMode) { - LAppPal::PrintLog("[APP]expression: [%s]", expressionID); + LAppPal::PrintLogLn("[APP]expression: [%s]", expressionID); } if (motion != NULL) @@ -578,7 +578,7 @@ void LAppModel::SetExpression(const csmChar* expressionID) } else { - if (_debugMode) LAppPal::PrintLog("[APP]expression[%s] is null ", expressionID); + if (_debugMode) LAppPal::PrintLogLn("[APP]expression[%s] is null ", expressionID); } } diff --git a/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/cpp/LAppPal.cpp b/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/cpp/LAppPal.cpp index 5a003a73..27534cfc 100644 --- a/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/cpp/LAppPal.cpp +++ b/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/cpp/LAppPal.cpp @@ -56,19 +56,17 @@ void LAppPal::UpdateTime() s_lastFrame = s_currentFrame; } -void LAppPal::PrintLog(const csmChar* format, ...) +void LAppPal::PrintLogLn(const csmChar* format, ...) { va_list args; - csmChar buf[256]; va_start(args, format); __android_log_vprint(ANDROID_LOG_DEBUG, "NativePrint", format, args); // 標準出力でレンダリング - std::cerr << buf << std::endl; va_end(args); } -void LAppPal::PrintMessage(const csmChar* message) +void LAppPal::PrintMessageLn(const csmChar* message) { - PrintLog("%s", message); + PrintLogLn("%s", message); } double LAppPal::GetSystemTime() diff --git a/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/cpp/LAppPal.hpp b/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/cpp/LAppPal.hpp index 69168911..451d21ed 100644 --- a/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/cpp/LAppPal.hpp +++ b/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/cpp/LAppPal.hpp @@ -55,25 +55,25 @@ class LAppPal static void UpdateTime(); /** - * @brief ログを出力する + * @brief ログを出力し最後に改行する * - * ログを出力する + * ログを出力し最後に改行する * * @param[in] format 書式付文字列 * @param[in] ... (可変長引数)文字列 * */ - static void PrintLog(const Csm::csmChar* format, ...); + static void PrintLogLn(const Csm::csmChar* format, ...); /** - * @brief メッセージを出力する + * @brief メッセージを出力し最後に改行する * - * メッセージを出力する + * メッセージを出力し最後に改行する * * @param[in] message 文字列 * */ - static void PrintMessage(const Csm::csmChar* message); + static void PrintMessageLn(const Csm::csmChar* message); private: /** diff --git a/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/cpp/LAppView.cpp b/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/cpp/LAppView.cpp index cbdda107..9e8bcac8 100644 --- a/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/cpp/LAppView.cpp +++ b/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/cpp/LAppView.cpp @@ -211,8 +211,6 @@ void LAppView::Render() // 各モデルが持つ描画ターゲットをテクスチャとする場合 if (_renderTarget == SelectTarget_ModelFrameBuffer && _renderSprite) { - _renderSprite->SetWindowSize(maxWidth, maxHeight); - const GLfloat uvVertex[] = { 1.0f, 1.0f, @@ -229,6 +227,7 @@ void LAppView::Render() if (model) { + _renderSprite->SetWindowSize(maxWidth, maxHeight); _renderSprite->RenderImmidiate(model->GetRenderBuffer().GetColorBuffer(), uvVertex); } } @@ -262,7 +261,7 @@ void LAppView::OnTouchesEnded(float pointX, float pointY) float y = _deviceToScreen->TransformY(_touchManager->GetY()); // 論理座標変換した座標を取得。 if (DebugTouchLogEnable) { - LAppPal::PrintLog("[APP]touchesEnded x:%.2f y:%.2f", x, y); + LAppPal::PrintLogLn("[APP]touchesEnded x:%.2f y:%.2f", x, y); } live2DManager->OnTap(x, y); @@ -354,6 +353,12 @@ void LAppView::PostModelDraw(LAppModel &refModel) }; _renderSprite->SetColor(1.0f, 1.0f, 1.0f, GetSpriteAlpha(0)); + + // 画面サイズを取得する + int maxWidth = LAppDelegate::GetInstance()->GetWindowWidth(); + int maxHeight = LAppDelegate::GetInstance()->GetWindowHeight(); + _renderSprite->SetWindowSize(maxWidth, maxHeight); + _renderSprite->RenderImmidiate(useTarget->GetColorBuffer(), uvVertex); } } diff --git a/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/java/com/live2d/demo/JniBridgeJava.java b/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/java/com/live2d/demo/JniBridgeJava.java index 90df49e4..f3e013b9 100644 --- a/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/java/com/live2d/demo/JniBridgeJava.java +++ b/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/java/com/live2d/demo/JniBridgeJava.java @@ -14,15 +14,6 @@ import java.io.InputStream; public class JniBridgeJava { - - private static final String LIBRARY_NAME = "Demo"; - private static Activity _activityInstance; - private static Context _context; - - static { - System.loadLibrary(LIBRARY_NAME); - } - // Native ----------------------------------------------------------------- public static native void nativeOnStart(); @@ -48,16 +39,16 @@ public class JniBridgeJava { // Java ----------------------------------------------------------------- public static void SetContext(Context context) { - _context = context; + JniBridgeJava.context = context; } public static void SetActivityInstance(Activity activity) { - _activityInstance = activity; + activityInstance = activity; } public static String[] GetAssetList(String dirPath) { try { - return _context.getAssets().list(dirPath); + return context.getAssets().list(dirPath); } catch (IOException e) { e.printStackTrace(); return new String[0]; @@ -67,7 +58,7 @@ public static String[] GetAssetList(String dirPath) { public static byte[] LoadFile(String filePath) { InputStream fileData = null; try { - fileData = _context.getAssets().open(filePath); + fileData = context.getAssets().open(filePath); int fileSize = fileData.available(); byte[] fileBuffer = new byte[fileSize]; fileData.read(fileBuffer, 0, fileSize); @@ -87,7 +78,14 @@ public static byte[] LoadFile(String filePath) { } public static void MoveTaskToBack() { - _activityInstance.moveTaskToBack(true); + activityInstance.moveTaskToBack(true); } + private static Activity activityInstance; + private static Context context; + private static final String LIBRARY_NAME = "Demo"; + + static { + System.loadLibrary(LIBRARY_NAME); + } } diff --git a/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/java/com/live2d/demo/MainActivity.java b/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/java/com/live2d/demo/MainActivity.java index 079fbca2..6b4210be 100644 --- a/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/java/com/live2d/demo/MainActivity.java +++ b/Samples/OpenGL/Demo/proj.android.cmake/Full/app/src/main/java/com/live2d/demo/MainActivity.java @@ -17,21 +17,35 @@ import android.view.WindowInsetsController; public class MainActivity extends Activity { - - private GLSurfaceView _glSurfaceView; - private GLRenderer _glRenderer; + @Override + public boolean onTouchEvent(MotionEvent event) { + float pointX = event.getX(); + float pointY = event.getY(); + switch (event.getAction()) { + case MotionEvent.ACTION_DOWN: + JniBridgeJava.nativeOnTouchesBegan(pointX, pointY); + break; + case MotionEvent.ACTION_UP: + JniBridgeJava.nativeOnTouchesEnded(pointX, pointY); + break; + case MotionEvent.ACTION_MOVE: + JniBridgeJava.nativeOnTouchesMoved(pointX, pointY); + break; + } + return super.onTouchEvent(event); + } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); JniBridgeJava.SetActivityInstance(this); JniBridgeJava.SetContext(this); - _glSurfaceView = new GLSurfaceView(this); - _glSurfaceView.setEGLContextClientVersion(2); - _glRenderer = new GLRenderer(); - _glSurfaceView.setRenderer(_glRenderer); - _glSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY); - setContentView(_glSurfaceView); + glSurfaceView = new GLSurfaceView(this); + glSurfaceView.setEGLContextClientVersion(2); + glRenderer = new GLRenderer(); + glSurfaceView.setRenderer(glRenderer); + glSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY); + setContentView(glSurfaceView); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { getWindow().getDecorView().setSystemUiVisibility( @@ -40,9 +54,7 @@ protected void onCreate(Bundle savedInstanceState) { | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN - | (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT - ? View.SYSTEM_UI_FLAG_LOW_PROFILE - : View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) + | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY ); } else { @@ -62,13 +74,13 @@ protected void onStart() { @Override protected void onResume() { super.onResume(); - _glSurfaceView.onResume(); + glSurfaceView.onResume(); } @Override protected void onPause() { super.onPause(); - _glSurfaceView.onPause(); + glSurfaceView.onPause(); JniBridgeJava.nativeOnPause(); } @@ -84,22 +96,6 @@ protected void onDestroy() { JniBridgeJava.nativeOnDestroy(); } - @Override - public boolean onTouchEvent(MotionEvent event) { - float pointX = event.getX(); - float pointY = event.getY(); - switch (event.getAction()) { - case MotionEvent.ACTION_DOWN: - JniBridgeJava.nativeOnTouchesBegan(pointX, pointY); - break; - case MotionEvent.ACTION_UP: - JniBridgeJava.nativeOnTouchesEnded(pointX, pointY); - break; - case MotionEvent.ACTION_MOVE: - JniBridgeJava.nativeOnTouchesMoved(pointX, pointY); - break; - } - return super.onTouchEvent(event); - } - + private GLSurfaceView glSurfaceView; + private GLRenderer glRenderer; } diff --git a/Samples/OpenGL/Demo/proj.android.cmake/Full/gradle.properties b/Samples/OpenGL/Demo/proj.android.cmake/Full/gradle.properties index 4b9c4f9c..90aa5318 100644 --- a/Samples/OpenGL/Demo/proj.android.cmake/Full/gradle.properties +++ b/Samples/OpenGL/Demo/proj.android.cmake/Full/gradle.properties @@ -29,7 +29,7 @@ PROP_TARGET_SDK_VERSION=34 # List of CPU Archtexture to build that application with -# Available architextures (armeabi-v7a | arm64-v8a | x86) +# Available architextures (armeabi-v7a | arm64-v8a | x86 | x86_64) # To build for multiple architexture, use the `:` between them -# Example - PROP_APP_ABI=armeabi-v7a:arm64-v8a:x86 -PROP_APP_ABI=armeabi-v7a:arm64-v8a:x86 +# Example - PROP_APP_ABI=armeabi-v7a:arm64-v8a:x86:x86_64 +PROP_APP_ABI=armeabi-v7a:arm64-v8a:x86:x86_64 diff --git a/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/cpp/LAppMinimumDelegate.cpp b/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/cpp/LAppMinimumDelegate.cpp index 70a59441..0e40270f 100644 --- a/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/cpp/LAppMinimumDelegate.cpp +++ b/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/cpp/LAppMinimumDelegate.cpp @@ -147,7 +147,7 @@ LAppMinimumDelegate::LAppMinimumDelegate(): _height = height; // Setup Cubism - _cubismOption.LogFunction = LAppPal::PrintMessage; + _cubismOption.LogFunction = LAppPal::PrintMessageLn; _cubismOption.LoggingLevel = LAppDefine::CubismLoggingLevel; CubismFramework::CleanUp(); CubismFramework::StartUp(&_cubismAllocator, &_cubismOption); diff --git a/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/cpp/LAppMinimumModel.cpp b/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/cpp/LAppMinimumModel.cpp index 93c00427..9c1a25fd 100644 --- a/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/cpp/LAppMinimumModel.cpp +++ b/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/cpp/LAppMinimumModel.cpp @@ -30,7 +30,7 @@ namespace { { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]create buffer: %s ", path); + LAppPal::PrintLogLn("[APP]create buffer: %s ", path); } return LAppPal::LoadFileAsBytes(path, size); } @@ -39,7 +39,7 @@ namespace { { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]delete buffer: %s", path); + LAppPal::PrintLogLn("[APP]delete buffer: %s", path); } LAppPal::ReleaseBytes(buffer); } @@ -204,7 +204,7 @@ void LAppMinimumModel::PreloadMotionGroup(const csmChar* group) if (_debugMode) { - LAppPal::PrintLog("[APP]load motion: %s => [%s_%d] ", path.GetRawString(), group, i); + LAppPal::PrintLogLn("[APP]load motion: %s => [%s_%d] ", path.GetRawString(), group, i); } csmByte* buffer; @@ -371,7 +371,7 @@ CubismMotionQueueEntryHandle LAppMinimumModel::StartMotion(const csmChar* group, { if (_debugMode) { - LAppPal::PrintLog("[APP]can't start motion."); + LAppPal::PrintLogLn("[APP]can't start motion."); } return InvalidMotionQueueEntryHandleValue; } @@ -426,7 +426,7 @@ CubismMotionQueueEntryHandle LAppMinimumModel::StartMotion(const csmChar* group, if (_debugMode) { - LAppPal::PrintLog("[APP]start motion: [%s_%d]", group, no); + LAppPal::PrintLogLn("[APP]start motion: [%s_%d]", group, no); } return _motionManager->StartMotionPriority(motion, autoDelete, priority); } @@ -449,7 +449,7 @@ void LAppMinimumModel::SetExpression(const csmChar* expressionID) ACubismMotion* motion = _expressions[expressionID]; if (_debugMode) { - LAppPal::PrintLog("[APP]expression: [%s]", expressionID); + LAppPal::PrintLogLn("[APP]expression: [%s]", expressionID); } if (motion) @@ -458,7 +458,7 @@ void LAppMinimumModel::SetExpression(const csmChar* expressionID) } else { - if (_debugMode) LAppPal::PrintLog("[APP]expression[%s] is null ", expressionID); + if (_debugMode) LAppPal::PrintLogLn("[APP]expression[%s] is null ", expressionID); } } diff --git a/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/cpp/LAppMinimumView.cpp b/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/cpp/LAppMinimumView.cpp index 6186b633..65369207 100644 --- a/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/cpp/LAppMinimumView.cpp +++ b/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/cpp/LAppMinimumView.cpp @@ -133,10 +133,6 @@ void LAppMinimumView::Render() // 各モデルが持つ描画ターゲットをテクスチャとする場合 if (_renderTarget == SelectTarget_ModelFrameBuffer && _renderSprite) { - // 画面サイズを取得する - int maxWidth = LAppMinimumDelegate::GetInstance()->GetWindowWidth(); - int maxHeight = LAppMinimumDelegate::GetInstance()->GetWindowHeight(); - _renderSprite->SetWindowSize(maxWidth, maxHeight); const GLfloat uvVertex[] = { 1.0f, 1.0f, @@ -151,6 +147,11 @@ void LAppMinimumView::Render() LAppMinimumModel *model = Live2DManager->GetModel(); if (model) { + // 画面サイズを取得する + int maxWidth = LAppMinimumDelegate::GetInstance()->GetWindowWidth(); + int maxHeight = LAppMinimumDelegate::GetInstance()->GetWindowHeight(); + _renderSprite->SetWindowSize(maxWidth, maxHeight); + _renderSprite->RenderImmidiate(model->GetRenderBuffer().GetColorBuffer(), uvVertex); } } @@ -183,7 +184,7 @@ void LAppMinimumView::OnTouchesEnded(float pointX, float pointY) float y = _deviceToScreen->TransformY(_touchManager->GetY()); // 論理座標変換した座標を取得。 if (DebugTouchLogEnable) { - LAppPal::PrintLog("[APP]touchesEnded x:%.2f y:%.2f", x, y); + LAppPal::PrintLogLn("[APP]touchesEnded x:%.2f y:%.2f", x, y); } } } @@ -262,6 +263,12 @@ void LAppMinimumView::PostModelDraw(LAppMinimumModel &refModel) }; _renderSprite->SetColor(1.0f, 1.0f, 1.0f, GetSpriteAlpha(0)); + + // 画面サイズを取得する + int maxWidth = LAppMinimumDelegate::GetInstance()->GetWindowWidth(); + int maxHeight = LAppMinimumDelegate::GetInstance()->GetWindowHeight(); + _renderSprite->SetWindowSize(maxWidth, maxHeight); + _renderSprite->RenderImmidiate(useTarget->GetColorBuffer(), uvVertex); } } diff --git a/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/cpp/LAppPal.cpp b/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/cpp/LAppPal.cpp index 5a003a73..27534cfc 100644 --- a/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/cpp/LAppPal.cpp +++ b/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/cpp/LAppPal.cpp @@ -56,19 +56,17 @@ void LAppPal::UpdateTime() s_lastFrame = s_currentFrame; } -void LAppPal::PrintLog(const csmChar* format, ...) +void LAppPal::PrintLogLn(const csmChar* format, ...) { va_list args; - csmChar buf[256]; va_start(args, format); __android_log_vprint(ANDROID_LOG_DEBUG, "NativePrint", format, args); // 標準出力でレンダリング - std::cerr << buf << std::endl; va_end(args); } -void LAppPal::PrintMessage(const csmChar* message) +void LAppPal::PrintMessageLn(const csmChar* message) { - PrintLog("%s", message); + PrintLogLn("%s", message); } double LAppPal::GetSystemTime() diff --git a/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/cpp/LAppPal.hpp b/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/cpp/LAppPal.hpp index 69168911..451d21ed 100644 --- a/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/cpp/LAppPal.hpp +++ b/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/cpp/LAppPal.hpp @@ -55,25 +55,25 @@ class LAppPal static void UpdateTime(); /** - * @brief ログを出力する + * @brief ログを出力し最後に改行する * - * ログを出力する + * ログを出力し最後に改行する * * @param[in] format 書式付文字列 * @param[in] ... (可変長引数)文字列 * */ - static void PrintLog(const Csm::csmChar* format, ...); + static void PrintLogLn(const Csm::csmChar* format, ...); /** - * @brief メッセージを出力する + * @brief メッセージを出力し最後に改行する * - * メッセージを出力する + * メッセージを出力し最後に改行する * * @param[in] message 文字列 * */ - static void PrintMessage(const Csm::csmChar* message); + static void PrintMessageLn(const Csm::csmChar* message); private: /** diff --git a/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/java/com/live2d/demo/JniBridgeJava.java b/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/java/com/live2d/demo/JniBridgeJava.java index 20ded6b5..5465886a 100644 --- a/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/java/com/live2d/demo/JniBridgeJava.java +++ b/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/java/com/live2d/demo/JniBridgeJava.java @@ -14,15 +14,6 @@ import java.io.InputStream; public class JniBridgeJava { - - private static final String LIBRARY_NAME = "Demo"; - private static Activity _activityInstance; - private static Context _context; - - static { - System.loadLibrary(LIBRARY_NAME); - } - // Native ----------------------------------------------------------------- public static native void nativeOnStart(); @@ -48,17 +39,17 @@ public class JniBridgeJava { // Java ----------------------------------------------------------------- public static void SetContext(Context context) { - _context = context; + JniBridgeJava.context = context; } public static void SetActivityInstance(Activity activity) { - _activityInstance = activity; + activityInstance = activity; } public static byte[] LoadFile(String filePath) { InputStream fileData = null; try { - fileData = _context.getAssets().open(filePath); + fileData = context.getAssets().open(filePath); int fileSize = fileData.available(); byte[] fileBuffer = new byte[fileSize]; fileData.read(fileBuffer, 0, fileSize); @@ -78,7 +69,15 @@ public static byte[] LoadFile(String filePath) { } public static void MoveTaskToBack() { - _activityInstance.moveTaskToBack(true); + activityInstance.moveTaskToBack(true); } + private static Activity activityInstance; + private static Context context; + private static final String LIBRARY_NAME = "Demo"; + + + static { + System.loadLibrary(LIBRARY_NAME); + } } diff --git a/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/java/com/live2d/demo/MainActivity.java b/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/java/com/live2d/demo/MainActivity.java index 079fbca2..6b4210be 100644 --- a/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/java/com/live2d/demo/MainActivity.java +++ b/Samples/OpenGL/Demo/proj.android.cmake/Minimum/app/src/main/java/com/live2d/demo/MainActivity.java @@ -17,21 +17,35 @@ import android.view.WindowInsetsController; public class MainActivity extends Activity { - - private GLSurfaceView _glSurfaceView; - private GLRenderer _glRenderer; + @Override + public boolean onTouchEvent(MotionEvent event) { + float pointX = event.getX(); + float pointY = event.getY(); + switch (event.getAction()) { + case MotionEvent.ACTION_DOWN: + JniBridgeJava.nativeOnTouchesBegan(pointX, pointY); + break; + case MotionEvent.ACTION_UP: + JniBridgeJava.nativeOnTouchesEnded(pointX, pointY); + break; + case MotionEvent.ACTION_MOVE: + JniBridgeJava.nativeOnTouchesMoved(pointX, pointY); + break; + } + return super.onTouchEvent(event); + } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); JniBridgeJava.SetActivityInstance(this); JniBridgeJava.SetContext(this); - _glSurfaceView = new GLSurfaceView(this); - _glSurfaceView.setEGLContextClientVersion(2); - _glRenderer = new GLRenderer(); - _glSurfaceView.setRenderer(_glRenderer); - _glSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY); - setContentView(_glSurfaceView); + glSurfaceView = new GLSurfaceView(this); + glSurfaceView.setEGLContextClientVersion(2); + glRenderer = new GLRenderer(); + glSurfaceView.setRenderer(glRenderer); + glSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY); + setContentView(glSurfaceView); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { getWindow().getDecorView().setSystemUiVisibility( @@ -40,9 +54,7 @@ protected void onCreate(Bundle savedInstanceState) { | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN - | (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT - ? View.SYSTEM_UI_FLAG_LOW_PROFILE - : View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) + | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY ); } else { @@ -62,13 +74,13 @@ protected void onStart() { @Override protected void onResume() { super.onResume(); - _glSurfaceView.onResume(); + glSurfaceView.onResume(); } @Override protected void onPause() { super.onPause(); - _glSurfaceView.onPause(); + glSurfaceView.onPause(); JniBridgeJava.nativeOnPause(); } @@ -84,22 +96,6 @@ protected void onDestroy() { JniBridgeJava.nativeOnDestroy(); } - @Override - public boolean onTouchEvent(MotionEvent event) { - float pointX = event.getX(); - float pointY = event.getY(); - switch (event.getAction()) { - case MotionEvent.ACTION_DOWN: - JniBridgeJava.nativeOnTouchesBegan(pointX, pointY); - break; - case MotionEvent.ACTION_UP: - JniBridgeJava.nativeOnTouchesEnded(pointX, pointY); - break; - case MotionEvent.ACTION_MOVE: - JniBridgeJava.nativeOnTouchesMoved(pointX, pointY); - break; - } - return super.onTouchEvent(event); - } - + private GLSurfaceView glSurfaceView; + private GLRenderer glRenderer; } diff --git a/Samples/OpenGL/Demo/proj.android.cmake/Minimum/gradle.properties b/Samples/OpenGL/Demo/proj.android.cmake/Minimum/gradle.properties index 4b9c4f9c..90aa5318 100644 --- a/Samples/OpenGL/Demo/proj.android.cmake/Minimum/gradle.properties +++ b/Samples/OpenGL/Demo/proj.android.cmake/Minimum/gradle.properties @@ -29,7 +29,7 @@ PROP_TARGET_SDK_VERSION=34 # List of CPU Archtexture to build that application with -# Available architextures (armeabi-v7a | arm64-v8a | x86) +# Available architextures (armeabi-v7a | arm64-v8a | x86 | x86_64) # To build for multiple architexture, use the `:` between them -# Example - PROP_APP_ABI=armeabi-v7a:arm64-v8a:x86 -PROP_APP_ABI=armeabi-v7a:arm64-v8a:x86 +# Example - PROP_APP_ABI=armeabi-v7a:arm64-v8a:x86:x86_64 +PROP_APP_ABI=armeabi-v7a:arm64-v8a:x86:x86_64 diff --git a/Samples/OpenGL/Demo/proj.ios.cmake/src/AppDelegate.mm b/Samples/OpenGL/Demo/proj.ios.cmake/src/AppDelegate.mm index b580f745..d2bd4abe 100644 --- a/Samples/OpenGL/Demo/proj.ios.cmake/src/AppDelegate.mm +++ b/Samples/OpenGL/Demo/proj.ios.cmake/src/AppDelegate.mm @@ -87,7 +87,7 @@ - (void)applicationWillTerminate:(UIApplication *)application { - (void)initializeCubism { - _cubismOption.LogFunction = LAppPal::PrintMessage; + _cubismOption.LogFunction = LAppPal::PrintMessageLn; _cubismOption.LoggingLevel = LAppDefine::CubismLoggingLevel; Csm::CubismFramework::StartUp(&_cubismAllocator,&_cubismOption); diff --git a/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppLive2DManager.mm b/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppLive2DManager.mm index d64c6bea..a1be10d9 100644 --- a/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppLive2DManager.mm +++ b/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppLive2DManager.mm @@ -27,7 +27,7 @@ @implementation LAppLive2DManager void FinishedMotion(Csm::ACubismMotion* self) { - LAppPal::PrintLog("Motion Finished: %x", self); + LAppPal::PrintLogLn("Motion Finished: %x", self); } int CompareCsmString(const void* a, const void* b) @@ -147,7 +147,7 @@ - (void)onTap:(Csm::csmFloat32)x floatY:(Csm::csmFloat32)y; { if (LAppDefine::DebugLogEnable) { - LAppPal::PrintLog("[APP]tap point: {x:%.2f y:%.2f}", x, y); + LAppPal::PrintLogLn("[APP]tap point: {x:%.2f y:%.2f}", x, y); } for (Csm::csmUint32 i = 0; i < _models.GetSize(); i++) @@ -156,7 +156,7 @@ - (void)onTap:(Csm::csmFloat32)x floatY:(Csm::csmFloat32)y; { if (LAppDefine::DebugLogEnable) { - LAppPal::PrintLog("[APP]hit area: [%s]", LAppDefine::HitAreaNameHead); + LAppPal::PrintLogLn("[APP]hit area: [%s]", LAppDefine::HitAreaNameHead); } _models[i]->SetRandomExpression(); } @@ -164,7 +164,7 @@ - (void)onTap:(Csm::csmFloat32)x floatY:(Csm::csmFloat32)y; { if (LAppDefine::DebugLogEnable) { - LAppPal::PrintLog("[APP]hit area: [%s]", LAppDefine::HitAreaNameBody); + LAppPal::PrintLogLn("[APP]hit area: [%s]", LAppDefine::HitAreaNameBody); } _models[i]->StartRandomMotion(LAppDefine::MotionGroupTapBody, LAppDefine::PriorityNormal, FinishedMotion); } @@ -188,7 +188,7 @@ - (void)onUpdate; if (model->GetModel() == NULL) { - LAppPal::PrintLog("Failed to model->GetModel()."); + LAppPal::PrintLogLn("Failed to model->GetModel()."); continue; } @@ -229,7 +229,7 @@ - (void)changeScene:(Csm::csmInt32)index; _sceneIndex = index; if (LAppDefine::DebugLogEnable) { - LAppPal::PrintLog("[APP]model index: %d", _sceneIndex); + LAppPal::PrintLogLn("[APP]model index: %d", _sceneIndex); } // model3.jsonのパスを決定する. diff --git a/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppModel.mm b/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppModel.mm index 65baff3f..14d3317e 100644 --- a/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppModel.mm +++ b/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppModel.mm @@ -31,7 +31,7 @@ { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]create buffer: %s ", path); + LAppPal::PrintLogLn("[APP]create buffer: %s ", path); } return LAppPal::LoadFileAsBytes(path,size); } @@ -40,7 +40,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]delete buffer: %s", path); + LAppPal::PrintLogLn("[APP]delete buffer: %s", path); } LAppPal::ReleaseBytes(buffer); } @@ -85,7 +85,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") if (_debugMode) { - LAppPal::PrintLog("[APP]load model setting: %s", fileName); + LAppPal::PrintLogLn("[APP]load model setting: %s", fileName); } csmSizeInt size; @@ -99,7 +99,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") if (_model == NULL) { - LAppPal::PrintLog("Failed to LoadAssets()."); + LAppPal::PrintLogLn("Failed to LoadAssets()."); return; } @@ -126,7 +126,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") if (_debugMode) { - LAppPal::PrintLog("[APP]create model: %s", setting->GetModelFileName()); + LAppPal::PrintLogLn("[APP]create model: %s", setting->GetModelFileName()); } buffer = CreateBuffer(path.GetRawString(), &size); @@ -234,7 +234,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") if (_modelSetting == NULL || _modelMatrix == NULL) { - LAppPal::PrintLog("Failed to SetupModel()."); + LAppPal::PrintLogLn("Failed to SetupModel()."); return; } @@ -270,7 +270,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") if (_debugMode) { - LAppPal::PrintLog("[APP]load motion: %s => [%s_%d] ", path.GetRawString(), group, i); + LAppPal::PrintLogLn("[APP]load motion: %s => [%s_%d] ", path.GetRawString(), group, i); } csmByte* buffer; @@ -438,7 +438,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") { if (_debugMode) { - LAppPal::PrintLog("[APP]can't start motion."); + LAppPal::PrintLogLn("[APP]can't start motion."); } return InvalidMotionQueueEntryHandleValue; } @@ -494,7 +494,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") if (_debugMode) { - LAppPal::PrintLog("[APP]start motion: [%s_%d]", group, no); + LAppPal::PrintLogLn("[APP]start motion: [%s_%d]", group, no); } return _motionManager->StartMotionPriority(motion, autoDelete, priority); } @@ -559,7 +559,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") ACubismMotion* motion = _expressions[expressionID]; if (_debugMode) { - LAppPal::PrintLog("[APP]expression: [%s]", expressionID); + LAppPal::PrintLogLn("[APP]expression: [%s]", expressionID); } if (motion != NULL) @@ -570,7 +570,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") { if (_debugMode) { - LAppPal::PrintLog("[APP]expression[%s] is null ", expressionID); + LAppPal::PrintLogLn("[APP]expression[%s] is null ", expressionID); } } } diff --git a/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppPal.h b/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppPal.h index 6d9dec86..bc67f6b2 100644 --- a/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppPal.h +++ b/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppPal.h @@ -55,25 +55,25 @@ class LAppPal static void UpdateTime(); /** - * @brief ログを出力する - * - * ログを出力する - * - * @param[in] format 書式付文字列 - * @param[in] ... (可変長引数)文字列 - * - */ - static void PrintLog(const Csm::csmChar* format, ...); + * @brief ログを出力し最後に改行する + * + * ログを出力し最後に改行する + * + * @param[in] format 書式付文字列 + * @param[in] ... (可変長引数)文字列 + * + */ + static void PrintLogLn(const Csm::csmChar* format, ...); /** - * @brief メッセージを出力する - * - * メッセージを出力する - * - * @param[in] message 文字列 - * - */ - static void PrintMessage(const Csm::csmChar* message); + * @brief メッセージを出力し最後に改行する + * + * メッセージを出力し最後に改行する + * + * @param[in] message 文字列 + * + */ + static void PrintMessageLn(const Csm::csmChar* message); private: static double s_currentFrame; diff --git a/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppPal.mm b/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppPal.mm index c8db54a9..c9031be7 100644 --- a/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppPal.mm +++ b/Samples/OpenGL/Demo/proj.ios.cmake/src/LAppPal.mm @@ -38,7 +38,15 @@ ofType:[NSString stringWithUTF8String:extname.c_str()] inDirectory:[NSString stringWithUTF8String:pathname.c_str()]]; - NSData *data = [NSData dataWithContentsOfFile:castFilePath]; + NSError *errorMsg = nil; + NSData *data = [NSData dataWithContentsOfFile:castFilePath options:NULL error: &errorMsg]; + + if (data == nil) + { + PrintLogLn("Failed to read file"); + return NULL; + } + NSUInteger len = [data length]; Byte *byteData = (Byte*)malloc(len); memcpy(byteData, [data bytes], len); @@ -61,7 +69,7 @@ s_lastFrame = s_currentFrame; } -void LAppPal::PrintLog(const csmChar* format, ...) +void LAppPal::PrintLogLn(const csmChar* format, ...) { va_list args; Csm::csmChar buf[256]; @@ -71,7 +79,7 @@ va_end(args); } -void LAppPal::PrintMessage(const csmChar* message) +void LAppPal::PrintMessageLn(const csmChar* message) { - PrintLog("%s", message); + PrintLogLn("%s", message); } diff --git a/Samples/OpenGL/Demo/proj.ios.cmake/src/ViewController.mm b/Samples/OpenGL/Demo/proj.ios.cmake/src/ViewController.mm index 139a9e31..9d9e4774 100644 --- a/Samples/OpenGL/Demo/proj.ios.cmake/src/ViewController.mm +++ b/Samples/OpenGL/Demo/proj.ios.cmake/src/ViewController.mm @@ -288,7 +288,7 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event if (DebugTouchLogEnable) { - LAppPal::PrintLog("[APP]touchesEnded x:%.2f y:%.2f", x, y); + LAppPal::PrintLogLn("[APP]touchesEnded x:%.2f y:%.2f", x, y); } [live2DManager onTap:x floatY:y]; diff --git a/Samples/OpenGL/Demo/proj.ios.cmake/src/minimum/MinLAppPal.mm b/Samples/OpenGL/Demo/proj.ios.cmake/src/minimum/MinLAppPal.mm index 8e2e779a..53c4eea1 100644 --- a/Samples/OpenGL/Demo/proj.ios.cmake/src/minimum/MinLAppPal.mm +++ b/Samples/OpenGL/Demo/proj.ios.cmake/src/minimum/MinLAppPal.mm @@ -38,7 +38,15 @@ ofType:[NSString stringWithUTF8String:extname.c_str()] inDirectory:[NSString stringWithUTF8String:pathname.c_str()]]; + NSError *errorMsg = nil; NSData *data = [NSData dataWithContentsOfFile:castFilePath]; + + if (data == nil) + { + NSLog(@"Failed to read file, error %@", errorMsg); + return NULL; + } + NSUInteger len = [data length]; Byte *byteData = (Byte*)malloc(len); memcpy(byteData, [data bytes], len); diff --git a/Samples/OpenGL/Demo/proj.linux.cmake/scripts/make_gcc b/Samples/OpenGL/Demo/proj.linux.cmake/scripts/make_gcc index 65ee134a..4441a911 100644 --- a/Samples/OpenGL/Demo/proj.linux.cmake/scripts/make_gcc +++ b/Samples/OpenGL/Demo/proj.linux.cmake/scripts/make_gcc @@ -41,5 +41,6 @@ done cmake -S "$CMAKE_PATH" \ -B "$BUILD_PATH" \ -D CMAKE_BUILD_TYPE=Release \ - -D CSM_MINIMUM_DEMO=$MINIMUM_DEMO + -D CSM_MINIMUM_DEMO=$MINIMUM_DEMO \ + -D GLFW_BUILD_WAYLAND=OFF cd "$BUILD_PATH" && make diff --git a/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppDelegate.cpp b/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppDelegate.cpp index 0987aca3..1f8bd85b 100644 --- a/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppDelegate.cpp +++ b/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppDelegate.cpp @@ -50,7 +50,7 @@ bool LAppDelegate::Initialize() { if (DebugLogEnable) { - LAppPal::PrintLog("START"); + LAppPal::PrintLogLn("START"); } // GLFWの初期化 @@ -58,7 +58,7 @@ bool LAppDelegate::Initialize() { if (DebugLogEnable) { - LAppPal::PrintLog("Can't initilize GLFW"); + LAppPal::PrintLogLn("Can't initilize GLFW"); } return GL_FALSE; } @@ -69,7 +69,7 @@ bool LAppDelegate::Initialize() { if (DebugLogEnable) { - LAppPal::PrintLog("Can't create GLFW window."); + LAppPal::PrintLogLn("Can't create GLFW window."); } glfwTerminate(); return GL_FALSE; @@ -82,7 +82,7 @@ bool LAppDelegate::Initialize() if (glewInit() != GLEW_OK) { if (DebugLogEnable) { - LAppPal::PrintLog("Can't initilize glew."); + LAppPal::PrintLogLn("Can't initilize glew."); } glfwTerminate(); return GL_FALSE; @@ -113,7 +113,7 @@ bool LAppDelegate::Initialize() // Cubism3の初期化 InitializeCubism(); - SetRootDirectory(); + SetExecuteAbsolutePath(); //load model LAppLive2DManager::GetInstance(); @@ -191,7 +191,7 @@ LAppDelegate::LAppDelegate(): _windowWidth(0), _windowHeight(0) { - _rootDirectory = ""; + _executeAbsolutePath = ""; _view = new LAppView(); _textureManager = new LAppTextureManager(); } @@ -302,7 +302,7 @@ GLuint LAppDelegate::CreateShader() return programId; } -void LAppDelegate::SetRootDirectory() +void LAppDelegate::SetExecuteAbsolutePath() { char path[1024]; ssize_t len = readlink("/proc/self/exe", path, 1024 - 1); @@ -312,6 +312,6 @@ void LAppDelegate::SetRootDirectory() path[len] = '\0'; } - this->_rootDirectory = dirname(path); - this->_rootDirectory += "/"; + this->_executeAbsolutePath = dirname(path); + this->_executeAbsolutePath += "/"; } diff --git a/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppDelegate.hpp b/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppDelegate.hpp index 21f357e5..cac0f996 100644 --- a/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppDelegate.hpp +++ b/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppDelegate.hpp @@ -97,14 +97,14 @@ class LAppDelegate void AppEnd() { _isEnd = true; } /** - * @brief ルートディレクトリを設定する。 + * @brief アプリケーションの実行パスを設定する。 */ - void SetRootDirectory(); + void SetExecuteAbsolutePath(); /** - * @brief ルートディレクトリを取得する。 + * @brief アプリケーションの実行パスを取得する。 */ - std::string GetRootDirectory(){ return _rootDirectory;} + std::string GetExecuteAbsolutePath(){ return _executeAbsolutePath;} /** * @brief テクスチャマネージャーを取得する。 @@ -136,7 +136,7 @@ class LAppDelegate float _mouseY; ///< マウスY座標 bool _isEnd; ///< APP終了しているか LAppTextureManager* _textureManager; ///< テクスチャマネージャー - std::string _rootDirectory; ///< ルートディレクトリ + std::string _executeAbsolutePath; ///< アプリケーションの実行パス int _windowWidth; ///< Initialize関数で設定したウィンドウ幅 int _windowHeight; ///< Initialize関数で設定したウィンドウ高さ diff --git a/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppLive2DManager.cpp b/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppLive2DManager.cpp index 9bb59134..b9c5c73d 100644 --- a/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppLive2DManager.cpp +++ b/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppLive2DManager.cpp @@ -31,7 +31,7 @@ namespace { void FinishedMotion(ACubismMotion* self) { - LAppPal::PrintLog("Motion Finished: %x", self); + LAppPal::PrintLogLn("Motion Finished: %x", self); } int CompareCsmString(const void* a, const void* b) @@ -92,7 +92,7 @@ void LAppLive2DManager::SetUpModel() // ResourcesPathの中にあるフォルダ名を全てクロールし、モデルが存在するフォルダを定義する。 // フォルダはあるが同名の.model3.jsonが見つからなかった場合はリストに含めない。 struct dirent *dirent; - csmString crawlPath(LAppDelegate::GetInstance()->GetRootDirectory().c_str()); + csmString crawlPath(LAppDelegate::GetInstance()->GetExecuteAbsolutePath().c_str()); crawlPath += ResourcesPath; DIR *pDir = opendir(crawlPath.GetRawString()); @@ -165,7 +165,7 @@ void LAppLive2DManager::OnTap(csmFloat32 x, csmFloat32 y) { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]tap point: {x:%.2f y:%.2f}", x, y); + LAppPal::PrintLogLn("[APP]tap point: {x:%.2f y:%.2f}", x, y); } for (csmUint32 i = 0; i < _models.GetSize(); i++) @@ -174,7 +174,7 @@ void LAppLive2DManager::OnTap(csmFloat32 x, csmFloat32 y) { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameHead); + LAppPal::PrintLogLn("[APP]hit area: [%s]", HitAreaNameHead); } _models[i]->SetRandomExpression(); } @@ -182,7 +182,7 @@ void LAppLive2DManager::OnTap(csmFloat32 x, csmFloat32 y) { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameBody); + LAppPal::PrintLogLn("[APP]hit area: [%s]", HitAreaNameBody); } _models[i]->StartRandomMotion(MotionGroupTapBody, PriorityNormal, FinishedMotion); } @@ -202,7 +202,7 @@ void LAppLive2DManager::OnUpdate() const if (model->GetModel() == NULL) { - LAppPal::PrintLog("Failed to model->GetModel()."); + LAppPal::PrintLogLn("Failed to model->GetModel()."); continue; } @@ -243,16 +243,16 @@ void LAppLive2DManager::ChangeScene(Csm::csmInt32 index) _sceneIndex = index; if (DebugLogEnable) { - LAppPal::PrintLog("[APP]model index: %d", _sceneIndex); + LAppPal::PrintLogLn("[APP]model index: %d", _sceneIndex); } // ModelDir[]に保持したディレクトリ名から // model3.jsonのパスを決定する. // ディレクトリ名とmodel3.jsonの名前を一致させておくこと. const csmString& model = _modelDir[index]; - LAppPal::PrintLog("[APP]_modelDir: %s", model.GetRawString()); + LAppPal::PrintLogLn("[APP]_modelDir: %s", model.GetRawString()); - csmString modelPath(LAppDelegate::GetInstance()->GetRootDirectory().c_str()); + csmString modelPath(LAppDelegate::GetInstance()->GetExecuteAbsolutePath().c_str()); modelPath += ResourcesPath; modelPath += model; modelPath.Append(1, '/'); diff --git a/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppModel.cpp b/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppModel.cpp index b98d5cad..739d1a88 100644 --- a/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppModel.cpp +++ b/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppModel.cpp @@ -30,7 +30,7 @@ namespace { { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]create buffer: %s ", path); + LAppPal::PrintLogLn("[APP]create buffer: %s ", path); } return LAppPal::LoadFileAsBytes(path, size); } @@ -39,7 +39,7 @@ namespace { { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]delete buffer: %s", path); + LAppPal::PrintLogLn("[APP]delete buffer: %s", path); } LAppPal::ReleaseBytes(buffer); } @@ -84,7 +84,7 @@ void LAppModel::LoadAssets(const csmChar* dir, const csmChar* fileName) if (_debugMode) { - LAppPal::PrintLog("[APP]load model setting: %s", fileName); + LAppPal::PrintLogLn("[APP]load model setting: %s", fileName); } csmSizeInt size; @@ -98,7 +98,7 @@ void LAppModel::LoadAssets(const csmChar* dir, const csmChar* fileName) if (_model == NULL) { - LAppPal::PrintLog("Failed to LoadAssets()."); + LAppPal::PrintLogLn("Failed to LoadAssets()."); return; } @@ -126,7 +126,7 @@ void LAppModel::SetupModel(ICubismModelSetting* setting) if (_debugMode) { - LAppPal::PrintLog("[APP]create model: %s", setting->GetModelFileName()); + LAppPal::PrintLogLn("[APP]create model: %s", setting->GetModelFileName()); } buffer = CreateBuffer(path.GetRawString(), &size); @@ -234,7 +234,7 @@ void LAppModel::SetupModel(ICubismModelSetting* setting) if (_modelSetting == NULL || _modelMatrix == NULL) { - LAppPal::PrintLog("Failed to SetupModel()."); + LAppPal::PrintLogLn("Failed to SetupModel()."); return; } @@ -270,7 +270,7 @@ void LAppModel::PreloadMotionGroup(const csmChar* group) if (_debugMode) { - LAppPal::PrintLog("[APP]load motion: %s => [%s_%d] ", path.GetRawString(), group, i); + LAppPal::PrintLogLn("[APP]load motion: %s => [%s_%d] ", path.GetRawString(), group, i); } csmByte* buffer; @@ -453,7 +453,7 @@ CubismMotionQueueEntryHandle LAppModel::StartMotion(const csmChar* group, csmInt { if (_debugMode) { - LAppPal::PrintLog("[APP]can't start motion."); + LAppPal::PrintLogLn("[APP]can't start motion."); } return InvalidMotionQueueEntryHandleValue; } @@ -510,7 +510,7 @@ CubismMotionQueueEntryHandle LAppModel::StartMotion(const csmChar* group, csmInt if (_debugMode) { - LAppPal::PrintLog("[APP]start motion: [%s_%d]", group, no); + LAppPal::PrintLogLn("[APP]start motion: [%s_%d]", group, no); } return _motionManager->StartMotionPriority(motion, autoDelete, priority); } @@ -575,7 +575,7 @@ void LAppModel::SetExpression(const csmChar* expressionID) ACubismMotion* motion = _expressions[expressionID]; if (_debugMode) { - LAppPal::PrintLog("[APP]expression: [%s]", expressionID); + LAppPal::PrintLogLn("[APP]expression: [%s]", expressionID); } if (motion != NULL) @@ -584,7 +584,7 @@ void LAppModel::SetExpression(const csmChar* expressionID) } else { - if (_debugMode) LAppPal::PrintLog("[APP]expression[%s] is null ", expressionID); + if (_debugMode) LAppPal::PrintLogLn("[APP]expression[%s] is null ", expressionID); } } diff --git a/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppPal.cpp b/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppPal.cpp index a66093a6..e3f08cc5 100644 --- a/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppPal.cpp +++ b/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppPal.cpp @@ -36,21 +36,37 @@ csmByte* LAppPal::LoadFileAsBytes(const string filePath, csmSizeInt* outSize) if (stat(path, &statBuf) == 0) { size = statBuf.st_size; - PrintLog(path); + + if (size == 0) + { + if (DebugLogEnable) + { + PrintLogLn("Stat succeeded but file size is zero. path:%s", path); + } + return NULL; + } + } + else + { + if (DebugLogEnable) + { + PrintLogLn("Stat failed. errno:%d path:%s", errno, path); + } + return NULL; } std::fstream file; - char* buf = new char[size]; - file.open(path, std::ios::in | std::ios::binary); if (!file.is_open()) { if (DebugLogEnable) { - PrintLog("file open error"); + PrintLogLn("File open failed. path:%s", path); } return NULL; } + + char* buf = new char[size]; file.read(buf, size); file.close(); @@ -81,7 +97,17 @@ void LAppPal::PrintLog(const csmChar* format, ...) csmChar buf[256]; va_start(args, format); vsnprintf(buf, sizeof(buf), format, args); // 標準出力でレンダリング - std::cerr << buf << std::endl; + std::cout << buf; + va_end(args); +} + +void LAppPal::PrintLogLn(const csmChar* format, ...) +{ + va_list args; + csmChar buf[256]; + va_start(args, format); + vsnprintf(buf, sizeof(buf), format, args); // 標準出力でレンダリング + std::cout << buf << std::endl; va_end(args); } @@ -89,3 +115,8 @@ void LAppPal::PrintMessage(const csmChar* message) { PrintLog("%s", message); } + +void LAppPal::PrintMessageLn(const csmChar* message) +{ + PrintLogLn("%s", message); +} diff --git a/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppPal.hpp b/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppPal.hpp index 902abb9a..5b1ee036 100644 --- a/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppPal.hpp +++ b/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppPal.hpp @@ -62,6 +62,17 @@ class LAppPal */ static void PrintLog(const Csm::csmChar* format, ...); + /** + * @brief ログを出力し最後に改行する + * + * ログを出力し最後に改行する + * + * @param[in] format 書式付文字列 + * @param[in] ... (可変長引数)文字列 + * + */ + static void PrintLogLn(const Csm::csmChar* format, ...); + /** * @brief メッセージを出力する * @@ -72,6 +83,16 @@ class LAppPal */ static void PrintMessage(const Csm::csmChar* message); + /** + * @brief メッセージを出力し最後に改行する + * + * メッセージを出力し最後に改行する + * + * @param[in] message 文字列 + * + */ + static void PrintMessageLn(const Csm::csmChar* message); + private: static double s_currentFrame; static double s_lastFrame; diff --git a/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppView.cpp b/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppView.cpp index c15bebf3..48e727d4 100644 --- a/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppView.cpp +++ b/Samples/OpenGL/Demo/proj.linux.cmake/src/LAppView.cpp @@ -151,7 +151,7 @@ void LAppView::InitializeSprite() glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height); LAppTextureManager* textureManager = LAppDelegate::GetInstance()->GetTextureManager(); - const string resourcesPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath; + const string resourcesPath = LAppDelegate::GetInstance()->GetExecuteAbsolutePath() + ResourcesPath; string imageName = BackImageName; LAppTextureManager::TextureInfo* backgroundTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName); @@ -215,7 +215,7 @@ void LAppView::OnTouchesEnded(float px, float py) const float y = _deviceToScreen->TransformY(_touchManager->GetY()); // 論理座標変換した座標を取得。 if (DebugTouchLogEnable) { - LAppPal::PrintLog("[APP]touchesEnded x:%.2f y:%.2f", x, y); + LAppPal::PrintLogLn("[APP]touchesEnded x:%.2f y:%.2f", x, y); } live2DManager->OnTap(x, y); diff --git a/Samples/OpenGL/Demo/proj.linux.cmake/src/mainMinimum.cpp b/Samples/OpenGL/Demo/proj.linux.cmake/src/mainMinimum.cpp index fb06228b..20d9f2e9 100644 --- a/Samples/OpenGL/Demo/proj.linux.cmake/src/mainMinimum.cpp +++ b/Samples/OpenGL/Demo/proj.linux.cmake/src/mainMinimum.cpp @@ -62,7 +62,7 @@ static LAppAllocator _cubismAllocator; ///< メモリのアロケーター static LAppTextureManager* _textureManager; ///< テクスチャの管理 -static std::string _rootDirectory; ///< ルートディレクトリ +static std::string _executeAbsolutePath; ///< アプリケーションの実行パス static std::string _currentModelDirectory; ///< 現在のモデルのディレクトリ名 static GLFWwindow* _window; ///< ウィンドウオブジェクト @@ -86,11 +86,11 @@ static void InitializeCubism() } /** -* @brief ルートディレクトリの設定 +* @brief アプリケーションの実行パスの設定 * -* Linuxのルートディレクトリを確認し、パスを取得する +* Linuxのアプリケーションの実行パスを確認し、パスを取得する */ -void SetRootDirectory() +void SetExecuteAbsolutePath() { const int maximumPathBufferSize = 1024; char path[maximumPathBufferSize]; @@ -101,8 +101,8 @@ void SetRootDirectory() path[len] = '\0'; } - _rootDirectory = dirname(path); - _rootDirectory += "/"; + _executeAbsolutePath = dirname(path); + _executeAbsolutePath += "/"; } /** @@ -112,12 +112,12 @@ void SetRootDirectory() */ static bool InitializeSystem() { - LAppPal::PrintLog("START"); + LAppPal::PrintLogLn("START"); // GLFWの初期化 if (glfwInit() == GL_FALSE) { - LAppPal::PrintLog("Can't initilize GLFW"); + LAppPal::PrintLogLn("Can't initilize GLFW"); return GL_FALSE; } @@ -126,7 +126,7 @@ static bool InitializeSystem() _window = glfwCreateWindow(LAppDefine::RenderTargetWidth, LAppDefine::RenderTargetHeight, "SIMPLE_SAMPLE", NULL, NULL); if (_window == NULL) { - LAppPal::PrintLog("Can't create GLFW window."); + LAppPal::PrintLogLn("Can't create GLFW window."); glfwTerminate(); return GL_FALSE; @@ -137,7 +137,7 @@ static bool InitializeSystem() glfwSwapInterval(1); if (glewInit() != GLEW_OK) { - LAppPal::PrintLog("Can't initilize glew."); + LAppPal::PrintLogLn("Can't initilize glew."); glfwTerminate(); return GL_FALSE; @@ -165,7 +165,7 @@ static bool InitializeSystem() // ドラッグ入力管理クラスの初期化 MouseActionManager::GetInstance()->Initialize(windowWidth, windowHeight); - SetRootDirectory(); + SetExecuteAbsolutePath(); return GL_TRUE; } @@ -209,7 +209,7 @@ void Release() void LoadModel(const std::string modelDirectoryName) { // モデルのディレクトリを指定 - _currentModelDirectory = _rootDirectory + LAppDefine::ResourcesPath + modelDirectoryName + "/"; + _currentModelDirectory = _executeAbsolutePath + LAppDefine::ResourcesPath + modelDirectoryName + "/"; // モデルデータの新規生成 _userModel = new CubismUserModelExtend(modelDirectoryName, _currentModelDirectory); diff --git a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppDelegate.cpp b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppDelegate.cpp index b0c22cb3..4a14a258 100644 --- a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppDelegate.cpp +++ b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppDelegate.cpp @@ -50,7 +50,7 @@ bool LAppDelegate::Initialize() { if (DebugLogEnable) { - LAppPal::PrintLog("START"); + LAppPal::PrintLogLn("START"); } // GLFWの初期化 @@ -58,7 +58,7 @@ bool LAppDelegate::Initialize() { if (DebugLogEnable) { - LAppPal::PrintLog("Can't initilize GLFW"); + LAppPal::PrintLogLn("Can't initilize GLFW"); } return GL_FALSE; } @@ -69,7 +69,7 @@ bool LAppDelegate::Initialize() { if (DebugLogEnable) { - LAppPal::PrintLog("Can't create GLFW window."); + LAppPal::PrintLogLn("Can't create GLFW window."); } glfwTerminate(); return GL_FALSE; @@ -82,7 +82,7 @@ bool LAppDelegate::Initialize() if (glewInit() != GLEW_OK) { if (DebugLogEnable) { - LAppPal::PrintLog("Can't initilize glew."); + LAppPal::PrintLogLn("Can't initilize glew."); } glfwTerminate(); return GL_FALSE; @@ -112,7 +112,7 @@ bool LAppDelegate::Initialize() // Cubism SDK の初期化 InitializeCubism(); - SetRootDirectory(); + SetExecuteAbsolutePath(); //load model LAppLive2DManager::GetInstance(); @@ -189,7 +189,7 @@ LAppDelegate::LAppDelegate(): _windowWidth(0), _windowHeight(0) { - _rootDirectory = ""; + _executeAbsolutePath = ""; _view = new LAppView(); _textureManager = new LAppTextureManager(); } @@ -202,7 +202,7 @@ LAppDelegate::~LAppDelegate() void LAppDelegate::InitializeCubism() { //setup cubism - _cubismOption.LogFunction = LAppPal::PrintMessage; + _cubismOption.LogFunction = LAppPal::PrintMessageLn; _cubismOption.LoggingLevel = LAppDefine::CubismLoggingLevel; Csm::CubismFramework::StartUp(&_cubismAllocator, &_cubismOption); @@ -300,11 +300,11 @@ GLuint LAppDelegate::CreateShader() return programId; } -void LAppDelegate::SetRootDirectory() +void LAppDelegate::SetExecuteAbsolutePath() { char path[1024]; uint32_t size = sizeof(path); _NSGetExecutablePath(path, &size); - this->_rootDirectory = dirname(path); - this->_rootDirectory += "/"; + this->_executeAbsolutePath = dirname(path); + this->_executeAbsolutePath += "/"; } diff --git a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppDelegate.hpp b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppDelegate.hpp index dd427435..9b94810d 100644 --- a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppDelegate.hpp +++ b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppDelegate.hpp @@ -97,14 +97,14 @@ class LAppDelegate void AppEnd() { _isEnd = true; } /** - * @brief ルートディレクトリを設定する。 + * @brief アプリケーションの実行パスを設定する。 */ - void SetRootDirectory(); + void SetExecuteAbsolutePath(); /** - * @brief ルートディレクトリを取得する。 + * @brief アプリケーションの実行パスを取得する。 */ - std::string GetRootDirectory(){ return _rootDirectory;} + std::string GetExecuteAbsolutePath(){ return _executeAbsolutePath;} /** * @brief テクスチャマネージャーを取得する。 @@ -136,7 +136,7 @@ class LAppDelegate float _mouseY; ///< マウスY座標 bool _isEnd; ///< APP終了しているか LAppTextureManager* _textureManager; ///< テクスチャマネージャー - std::string _rootDirectory; ///< ルートディレクトリ + std::string _executeAbsolutePath; ///< アプリケーションの実行パス int _windowWidth; ///< Initialize関数で設定したウィンドウ幅 int _windowHeight; ///< Initialize関数で設定したウィンドウ高さ diff --git a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppLive2DManager.cpp b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppLive2DManager.cpp index 92c31174..b4527f05 100644 --- a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppLive2DManager.cpp +++ b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppLive2DManager.cpp @@ -32,7 +32,7 @@ namespace { void FinishedMotion(ACubismMotion* self) { - LAppPal::PrintLog("Motion Finished: %x", self); + LAppPal::PrintLogLn("Motion Finished: %x", self); } int CompareCsmString(const void* a, const void* b) @@ -104,7 +104,7 @@ void LAppLive2DManager::SetUpModel() // フォルダはあるが同名の.model3.jsonが見つからなかった場合はリストに含めない。 struct dirent *dirent; - csmString crawlPath(LAppDelegate::GetInstance()->GetRootDirectory().c_str()); + csmString crawlPath(LAppDelegate::GetInstance()->GetExecuteAbsolutePath().c_str()); crawlPath += ResourcesPath; DIR *pDir = opendir(crawlPath.GetRawString()); @@ -167,7 +167,7 @@ void LAppLive2DManager::OnTap(csmFloat32 x, csmFloat32 y) { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]tap point: {x:%.2f y:%.2f}", x, y); + LAppPal::PrintLogLn("[APP]tap point: {x:%.2f y:%.2f}", x, y); } for (csmUint32 i = 0; i < _models.GetSize(); i++) @@ -176,7 +176,7 @@ void LAppLive2DManager::OnTap(csmFloat32 x, csmFloat32 y) { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameHead); + LAppPal::PrintLogLn("[APP]hit area: [%s]", HitAreaNameHead); } _models[i]->SetRandomExpression(); } @@ -184,7 +184,7 @@ void LAppLive2DManager::OnTap(csmFloat32 x, csmFloat32 y) { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameBody); + LAppPal::PrintLogLn("[APP]hit area: [%s]", HitAreaNameBody); } _models[i]->StartRandomMotion(MotionGroupTapBody, PriorityNormal, FinishedMotion); } @@ -204,7 +204,7 @@ void LAppLive2DManager::OnUpdate() const if (model->GetModel() == NULL) { - LAppPal::PrintLog("Failed to model->GetModel()."); + LAppPal::PrintLogLn("Failed to model->GetModel()."); continue; } @@ -245,14 +245,14 @@ void LAppLive2DManager::ChangeScene(Csm::csmInt32 index) _sceneIndex = index; if (DebugLogEnable) { - LAppPal::PrintLog("[APP]model index: %d", _sceneIndex); + LAppPal::PrintLogLn("[APP]model index: %d", _sceneIndex); } // model3.jsonのパスを決定する. // ディレクトリ名とmodel3.jsonの名前を一致させておくこと. const csmString& model = _modelDir[index]; - csmString modelPath(LAppDelegate::GetInstance()->GetRootDirectory().c_str()); + csmString modelPath(LAppDelegate::GetInstance()->GetExecuteAbsolutePath().c_str()); modelPath += ResourcesPath; modelPath += model; modelPath.Append(1, '/'); diff --git a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppModel.cpp b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppModel.cpp index b98d5cad..739d1a88 100644 --- a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppModel.cpp +++ b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppModel.cpp @@ -30,7 +30,7 @@ namespace { { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]create buffer: %s ", path); + LAppPal::PrintLogLn("[APP]create buffer: %s ", path); } return LAppPal::LoadFileAsBytes(path, size); } @@ -39,7 +39,7 @@ namespace { { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]delete buffer: %s", path); + LAppPal::PrintLogLn("[APP]delete buffer: %s", path); } LAppPal::ReleaseBytes(buffer); } @@ -84,7 +84,7 @@ void LAppModel::LoadAssets(const csmChar* dir, const csmChar* fileName) if (_debugMode) { - LAppPal::PrintLog("[APP]load model setting: %s", fileName); + LAppPal::PrintLogLn("[APP]load model setting: %s", fileName); } csmSizeInt size; @@ -98,7 +98,7 @@ void LAppModel::LoadAssets(const csmChar* dir, const csmChar* fileName) if (_model == NULL) { - LAppPal::PrintLog("Failed to LoadAssets()."); + LAppPal::PrintLogLn("Failed to LoadAssets()."); return; } @@ -126,7 +126,7 @@ void LAppModel::SetupModel(ICubismModelSetting* setting) if (_debugMode) { - LAppPal::PrintLog("[APP]create model: %s", setting->GetModelFileName()); + LAppPal::PrintLogLn("[APP]create model: %s", setting->GetModelFileName()); } buffer = CreateBuffer(path.GetRawString(), &size); @@ -234,7 +234,7 @@ void LAppModel::SetupModel(ICubismModelSetting* setting) if (_modelSetting == NULL || _modelMatrix == NULL) { - LAppPal::PrintLog("Failed to SetupModel()."); + LAppPal::PrintLogLn("Failed to SetupModel()."); return; } @@ -270,7 +270,7 @@ void LAppModel::PreloadMotionGroup(const csmChar* group) if (_debugMode) { - LAppPal::PrintLog("[APP]load motion: %s => [%s_%d] ", path.GetRawString(), group, i); + LAppPal::PrintLogLn("[APP]load motion: %s => [%s_%d] ", path.GetRawString(), group, i); } csmByte* buffer; @@ -453,7 +453,7 @@ CubismMotionQueueEntryHandle LAppModel::StartMotion(const csmChar* group, csmInt { if (_debugMode) { - LAppPal::PrintLog("[APP]can't start motion."); + LAppPal::PrintLogLn("[APP]can't start motion."); } return InvalidMotionQueueEntryHandleValue; } @@ -510,7 +510,7 @@ CubismMotionQueueEntryHandle LAppModel::StartMotion(const csmChar* group, csmInt if (_debugMode) { - LAppPal::PrintLog("[APP]start motion: [%s_%d]", group, no); + LAppPal::PrintLogLn("[APP]start motion: [%s_%d]", group, no); } return _motionManager->StartMotionPriority(motion, autoDelete, priority); } @@ -575,7 +575,7 @@ void LAppModel::SetExpression(const csmChar* expressionID) ACubismMotion* motion = _expressions[expressionID]; if (_debugMode) { - LAppPal::PrintLog("[APP]expression: [%s]", expressionID); + LAppPal::PrintLogLn("[APP]expression: [%s]", expressionID); } if (motion != NULL) @@ -584,7 +584,7 @@ void LAppModel::SetExpression(const csmChar* expressionID) } else { - if (_debugMode) LAppPal::PrintLog("[APP]expression[%s] is null ", expressionID); + if (_debugMode) LAppPal::PrintLogLn("[APP]expression[%s] is null ", expressionID); } } diff --git a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppPal.cpp b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppPal.cpp index 8d16b0e0..cf8d03ff 100644 --- a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppPal.cpp +++ b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppPal.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -36,20 +37,37 @@ csmByte* LAppPal::LoadFileAsBytes(const string filePath, csmSizeInt* outSize) if (stat(path, &statBuf) == 0) { size = statBuf.st_size; + + if (size == 0) + { + if (DebugLogEnable) + { + PrintLogLn("Stat succeeded but file size is zero. path:%s", path); + } + return NULL; + } + } + else + { + if (DebugLogEnable) + { + PrintLogLn("Stat failed. errno:%d path:%s", errno, path); + } + return NULL; } std::fstream file; - char* buf = new char[size]; - file.open(path, std::ios::in | std::ios::binary); if (!file.is_open()) { if (DebugLogEnable) { - PrintLog("file open error"); + PrintLogLn("File open failed. path:%s", path); } return NULL; } + + char* buf = new char[size]; file.read(buf, size); file.close(); @@ -74,17 +92,17 @@ void LAppPal::UpdateTime() s_lastFrame = s_currentFrame; } -void LAppPal::PrintLog(const csmChar* format, ...) +void LAppPal::PrintLogLn(const csmChar* format, ...) { va_list args; csmChar buf[256]; va_start(args, format); vsnprintf(buf, sizeof(buf), format, args); // 標準出力でレンダリング - std::cerr << buf << std::endl; + os_log(OS_LOG_DEFAULT, "%s", buf); va_end(args); } -void LAppPal::PrintMessage(const csmChar* message) +void LAppPal::PrintMessageLn(const csmChar* message) { - PrintLog("%s", message); + PrintLogLn("%s", message); } diff --git a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppPal.hpp b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppPal.hpp index fc8bf414..c7c36dbf 100644 --- a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppPal.hpp +++ b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppPal.hpp @@ -51,25 +51,25 @@ class LAppPal static void UpdateTime(); /** - * @brief ログを出力する + * @brief ログを出力し最後に改行する * - * ログを出力する + * ログを出力し最後に改行する * * @param[in] format 書式付文字列 * @param[in] ... (可変長引数)文字列 * */ - static void PrintLog(const Csm::csmChar* format, ...); + static void PrintLogLn(const Csm::csmChar* format, ...); /** - * @brief メッセージを出力する + * @brief メッセージを出力し最後に改行する * - * メッセージを出力する + * メッセージを出力し最後に改行する * * @param[in] message 文字列 * */ - static void PrintMessage(const Csm::csmChar* message); + static void PrintMessageLn(const Csm::csmChar* message); private: static double s_currentFrame; diff --git a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppView.cpp b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppView.cpp index 80c77ab1..6c48cf05 100644 --- a/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppView.cpp +++ b/Samples/OpenGL/Demo/proj.mac.cmake/src/LAppView.cpp @@ -144,6 +144,7 @@ void LAppView::Render() if (model) { + _renderSprite->SetWindowSize(maxWidth, maxHeight); _renderSprite->RenderImmidiate(model->GetRenderBuffer().GetColorBuffer(), uvVertex); } } @@ -158,7 +159,7 @@ void LAppView::InitializeSprite() glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height); LAppTextureManager* textureManager = LAppDelegate::GetInstance()->GetTextureManager(); - const string resourcesPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath; + const string resourcesPath = LAppDelegate::GetInstance()->GetExecuteAbsolutePath() + ResourcesPath; string imageName = BackImageName; LAppTextureManager::TextureInfo* backgroundTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName); @@ -222,7 +223,7 @@ void LAppView::OnTouchesEnded(float px, float py) const float y = _deviceToScreen->TransformY(_touchManager->GetY()); // 論理座標変換した座標を取得。 if (DebugTouchLogEnable) { - LAppPal::PrintLog("[APP]touchesEnded x:%.2f y:%.2f", x, y); + LAppPal::PrintLogLn("[APP]touchesEnded x:%.2f y:%.2f", x, y); } live2DManager->OnTap(x, y); @@ -317,6 +318,12 @@ void LAppView::PostModelDraw(LAppModel &refModel) }; _renderSprite->SetColor(1.0f, 1.0f, 1.0f, GetSpriteAlpha(0)); + + // 画面サイズを取得する + int maxWidth, maxHeight; + glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &maxWidth, &maxHeight); + _renderSprite->SetWindowSize(maxWidth, maxHeight); + _renderSprite->RenderImmidiate(useTarget->GetColorBuffer(), uvVertex); } } diff --git a/Samples/OpenGL/Demo/proj.mac.cmake/src/mainMinimum.cpp b/Samples/OpenGL/Demo/proj.mac.cmake/src/mainMinimum.cpp index c0baaf4d..de386692 100644 --- a/Samples/OpenGL/Demo/proj.mac.cmake/src/mainMinimum.cpp +++ b/Samples/OpenGL/Demo/proj.mac.cmake/src/mainMinimum.cpp @@ -63,7 +63,7 @@ static LAppAllocator _cubismAllocator; ///< メモリのアロケーター static LAppTextureManager* _textureManager; ///< テクスチャの管理 -static std::string _rootDirectory; ///< ルートディレクトリ +static std::string _executeAbsolutePath; ///< アプリケーションの実行パス static std::string _currentModelDirectory; ///< 現在のモデルのディレクトリ名 static GLFWwindow* _window; ///< ウィンドウオブジェクト @@ -78,7 +78,7 @@ int windowWidth, windowHeight; ///< ウィンドウサイズの保存 static void InitializeCubism() { //setup cubism - _cubismOption.LogFunction = LAppPal::PrintMessage; + _cubismOption.LogFunction = LAppPal::PrintMessageLn; _cubismOption.LoggingLevel = Csm::CubismFramework::Option::LogLevel_Verbose; Csm::CubismFramework::StartUp(&_cubismAllocator, &_cubismOption); @@ -87,17 +87,17 @@ static void InitializeCubism() } /** -* @brief ルートディレクトリの設定 +* @brief アプリケーションの実行パスの設定 * -* Linuxのルートディレクトリを確認し、パスを取得する +* アプリケーションの実行パスを確認し、パスを取得する */ -void SetRootDirectory() +void SetExecuteAbsolutePath() { char path[1024]; uint32_t size = sizeof(path); _NSGetExecutablePath(path, &size); - _rootDirectory = dirname(path); - _rootDirectory += "/"; + _executeAbsolutePath = dirname(path); + _executeAbsolutePath += "/"; } /** @@ -107,12 +107,12 @@ void SetRootDirectory() */ static bool InitializeSystem() { - LAppPal::PrintLog("START"); + LAppPal::PrintLogLn("START"); // GLFWの初期化 if (glfwInit() == GL_FALSE) { - LAppPal::PrintLog("Can't initilize GLFW"); + LAppPal::PrintLogLn("Can't initilize GLFW"); return GL_FALSE; } @@ -121,7 +121,7 @@ static bool InitializeSystem() _window = glfwCreateWindow(LAppDefine::RenderTargetWidth, LAppDefine::RenderTargetHeight, "SIMPLE_SAMPLE", NULL, NULL); if (_window == NULL) { - LAppPal::PrintLog("Can't create GLFW window."); + LAppPal::PrintLogLn("Can't create GLFW window."); glfwTerminate(); return GL_FALSE; @@ -132,7 +132,7 @@ static bool InitializeSystem() glfwSwapInterval(1); if (glewInit() != GLEW_OK) { - LAppPal::PrintLog("Can't initilize glew."); + LAppPal::PrintLogLn("Can't initilize glew."); glfwTerminate(); return GL_FALSE; @@ -159,7 +159,7 @@ static bool InitializeSystem() // ドラッグ入力管理クラスの初期化 MouseActionManager::GetInstance()->Initialize(windowWidth, windowHeight); - SetRootDirectory(); + SetExecuteAbsolutePath(); return GL_TRUE; } @@ -203,7 +203,7 @@ void Release() void LoadModel(const std::string modelDirectoryName) { // モデルのディレクトリを指定 - _currentModelDirectory = _rootDirectory + LAppDefine::ResourcesPath + modelDirectoryName + "/"; + _currentModelDirectory = _executeAbsolutePath + LAppDefine::ResourcesPath + modelDirectoryName + "/"; // モデルデータの新規生成 _userModel = new CubismUserModelExtend(modelDirectoryName, _currentModelDirectory); diff --git a/Samples/OpenGL/Demo/proj.win.cmake/src/LAppDelegate.cpp b/Samples/OpenGL/Demo/proj.win.cmake/src/LAppDelegate.cpp index 4df032ea..65595ad6 100644 --- a/Samples/OpenGL/Demo/proj.win.cmake/src/LAppDelegate.cpp +++ b/Samples/OpenGL/Demo/proj.win.cmake/src/LAppDelegate.cpp @@ -47,7 +47,7 @@ bool LAppDelegate::Initialize() { if (DebugLogEnable) { - LAppPal::PrintLog("START"); + LAppPal::PrintLogLn("START"); } // GLFWの初期化 @@ -55,7 +55,7 @@ bool LAppDelegate::Initialize() { if (DebugLogEnable) { - LAppPal::PrintLog("Can't initilize GLFW"); + LAppPal::PrintLogLn("Can't initilize GLFW"); } return GL_FALSE; } @@ -66,7 +66,7 @@ bool LAppDelegate::Initialize() { if (DebugLogEnable) { - LAppPal::PrintLog("Can't create GLFW window."); + LAppPal::PrintLogLn("Can't create GLFW window."); } glfwTerminate(); return GL_FALSE; @@ -79,7 +79,7 @@ bool LAppDelegate::Initialize() if (glewInit() != GLEW_OK) { if (DebugLogEnable) { - LAppPal::PrintLog("Can't initilize glew."); + LAppPal::PrintLogLn("Can't initilize glew."); } glfwTerminate(); return GL_FALSE; diff --git a/Samples/OpenGL/Demo/proj.win.cmake/src/LAppLive2DManager.cpp b/Samples/OpenGL/Demo/proj.win.cmake/src/LAppLive2DManager.cpp index 276645e9..f03ce031 100644 --- a/Samples/OpenGL/Demo/proj.win.cmake/src/LAppLive2DManager.cpp +++ b/Samples/OpenGL/Demo/proj.win.cmake/src/LAppLive2DManager.cpp @@ -27,7 +27,7 @@ namespace { void FinishedMotion(ACubismMotion* self) { - LAppPal::PrintLog("Motion Finished: %x", self); + LAppPal::PrintLogLn("Motion Finished: %x", self); } int CompareCsmString(const void* a, const void* b) @@ -151,7 +151,7 @@ void LAppLive2DManager::OnTap(csmFloat32 x, csmFloat32 y) { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]tap point: {x:%.2f y:%.2f}", x, y); + LAppPal::PrintLogLn("[APP]tap point: {x:%.2f y:%.2f}", x, y); } for (csmUint32 i = 0; i < _models.GetSize(); i++) @@ -160,7 +160,7 @@ void LAppLive2DManager::OnTap(csmFloat32 x, csmFloat32 y) { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameHead); + LAppPal::PrintLogLn("[APP]hit area: [%s]", HitAreaNameHead); } _models[i]->SetRandomExpression(); } @@ -168,7 +168,7 @@ void LAppLive2DManager::OnTap(csmFloat32 x, csmFloat32 y) { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameBody); + LAppPal::PrintLogLn("[APP]hit area: [%s]", HitAreaNameBody); } _models[i]->StartRandomMotion(MotionGroupTapBody, PriorityNormal, FinishedMotion); } @@ -188,7 +188,7 @@ void LAppLive2DManager::OnUpdate() const if (model->GetModel() == NULL) { - LAppPal::PrintLog("Failed to model->GetModel()."); + LAppPal::PrintLogLn("Failed to model->GetModel()."); continue; } @@ -231,7 +231,7 @@ void LAppLive2DManager::ChangeScene(Csm::csmInt32 index) _sceneIndex = index; if (DebugLogEnable) { - LAppPal::PrintLog("[APP]model index: %d", _sceneIndex); + LAppPal::PrintLogLn("[APP]model index: %d", _sceneIndex); } // model3.jsonのパスを決定する. diff --git a/Samples/OpenGL/Demo/proj.win.cmake/src/LAppModel.cpp b/Samples/OpenGL/Demo/proj.win.cmake/src/LAppModel.cpp index 44ff8b47..68dafd06 100644 --- a/Samples/OpenGL/Demo/proj.win.cmake/src/LAppModel.cpp +++ b/Samples/OpenGL/Demo/proj.win.cmake/src/LAppModel.cpp @@ -30,7 +30,7 @@ namespace { { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]create buffer: %s ", path); + LAppPal::PrintLogLn("[APP]create buffer: %s ", path); } return LAppPal::LoadFileAsBytes(path, size); } @@ -39,7 +39,7 @@ namespace { { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]delete buffer: %s", path); + LAppPal::PrintLogLn("[APP]delete buffer: %s", path); } LAppPal::ReleaseBytes(buffer); } @@ -89,7 +89,7 @@ void LAppModel::LoadAssets(const csmChar* dir, const csmChar* fileName) if (_debugMode) { - LAppPal::PrintLog("[APP]load model setting: %s", fileName); + LAppPal::PrintLogLn("[APP]load model setting: %s", fileName); } csmSizeInt size; @@ -103,7 +103,7 @@ void LAppModel::LoadAssets(const csmChar* dir, const csmChar* fileName) if (_model == NULL) { - LAppPal::PrintLog("Failed to LoadAssets()."); + LAppPal::PrintLogLn("Failed to LoadAssets()."); return; } @@ -130,7 +130,7 @@ void LAppModel::SetupModel(ICubismModelSetting* setting) if (_debugMode) { - LAppPal::PrintLog("[APP]create model: %s", setting->GetModelFileName()); + LAppPal::PrintLogLn("[APP]create model: %s", setting->GetModelFileName()); } buffer = CreateBuffer(path.GetRawString(), &size); @@ -238,7 +238,7 @@ void LAppModel::SetupModel(ICubismModelSetting* setting) if (_modelSetting == NULL || _modelMatrix == NULL) { - LAppPal::PrintLog("Failed to SetupModel()."); + LAppPal::PrintLogLn("Failed to SetupModel()."); return; } @@ -274,7 +274,7 @@ void LAppModel::PreloadMotionGroup(const csmChar* group) if (_debugMode) { - LAppPal::PrintLog("[APP]load motion: %s => [%s_%d] ", path.GetRawString(), group, i); + LAppPal::PrintLogLn("[APP]load motion: %s => [%s_%d] ", path.GetRawString(), group, i); } csmByte* buffer; @@ -457,7 +457,7 @@ CubismMotionQueueEntryHandle LAppModel::StartMotion(const csmChar* group, csmInt { if (_debugMode) { - LAppPal::PrintLog("[APP]can't start motion."); + LAppPal::PrintLogLn("[APP]can't start motion."); } return InvalidMotionQueueEntryHandleValue; } @@ -514,7 +514,7 @@ CubismMotionQueueEntryHandle LAppModel::StartMotion(const csmChar* group, csmInt if (_debugMode) { - LAppPal::PrintLog("[APP]start motion: [%s_%d]", group, no); + LAppPal::PrintLogLn("[APP]start motion: [%s_%d]", group, no); } return _motionManager->StartMotionPriority(motion, autoDelete, priority); } @@ -579,7 +579,7 @@ void LAppModel::SetExpression(const csmChar* expressionID) ACubismMotion* motion = _expressions[expressionID]; if (_debugMode) { - LAppPal::PrintLog("[APP]expression: [%s]", expressionID); + LAppPal::PrintLogLn("[APP]expression: [%s]", expressionID); } if (motion != NULL) @@ -588,7 +588,7 @@ void LAppModel::SetExpression(const csmChar* expressionID) } else { - if (_debugMode) LAppPal::PrintLog("[APP]expression[%s] is null ", expressionID); + if (_debugMode) LAppPal::PrintLogLn("[APP]expression[%s] is null ", expressionID); } } diff --git a/Samples/OpenGL/Demo/proj.win.cmake/src/LAppPal.cpp b/Samples/OpenGL/Demo/proj.win.cmake/src/LAppPal.cpp index c192e424..8e0f7cc0 100644 --- a/Samples/OpenGL/Demo/proj.win.cmake/src/LAppPal.cpp +++ b/Samples/OpenGL/Demo/proj.win.cmake/src/LAppPal.cpp @@ -35,20 +35,37 @@ csmByte* LAppPal::LoadFileAsBytes(const string filePath, csmSizeInt* outSize) if (stat(path, &statBuf) == 0) { size = statBuf.st_size; + + if (size == 0) + { + if (DebugLogEnable) + { + PrintLogLn("Stat succeeded but file size is zero. path:%s", path); + } + return NULL; + } + } + else + { + if (DebugLogEnable) + { + PrintLogLn("Stat failed. errno:%d path:%s", errno, path); + } + return NULL; } std::fstream file; - char* buf = new char[size]; - file.open(path, std::ios::in | std::ios::binary); if (!file.is_open()) { if (DebugLogEnable) { - PrintLog("file open error"); + PrintLogLn("File open failed. path:%s", path); } return NULL; } + + char* buf = new char[size]; file.read(buf, size); file.close(); @@ -83,7 +100,22 @@ void LAppPal::PrintLog(const csmChar* format, ...) // メモリリークチェック時は大量の標準出力がはしり重いのでprintfを利用する std::printf(buf); #else - std::cerr << buf << std::endl; + std::cout << buf; +#endif + va_end(args); +} + +void LAppPal::PrintLogLn(const Csm::csmChar* format, ...) +{ + va_list args; + csmChar buf[256]; + va_start(args, format); + vsnprintf_s(buf, sizeof(buf), format, args); // 標準出力でレンダリング +#ifdef CSM_DEBUG_MEMORY_LEAKING + // メモリリークチェック時は大量の標準出力がはしり重いのでprintfを利用する + std::printf("%s\n", buf); +#else + std::cout << buf << std::endl; #endif va_end(args); } @@ -92,3 +124,8 @@ void LAppPal::PrintMessage(const csmChar* message) { PrintLog("%s", message); } + +void LAppPal::PrintMessageLn(const csmChar* message) +{ + PrintLogLn("%s", message); +} diff --git a/Samples/OpenGL/Demo/proj.win.cmake/src/LAppPal.hpp b/Samples/OpenGL/Demo/proj.win.cmake/src/LAppPal.hpp index 83f17ec7..ac365794 100644 --- a/Samples/OpenGL/Demo/proj.win.cmake/src/LAppPal.hpp +++ b/Samples/OpenGL/Demo/proj.win.cmake/src/LAppPal.hpp @@ -61,6 +61,17 @@ class LAppPal */ static void PrintLog(const Csm::csmChar* format, ...); + /** + * @brief ログを出力し最後に改行する + * + * ログを出力し最後に改行する + * + * @param[in] format 書式付文字列 + * @param[in] ... (可変長引数)文字列 + * + */ + static void PrintLogLn(const Csm::csmChar* format, ...); + /** * @brief メッセージを出力する * @@ -71,6 +82,16 @@ class LAppPal */ static void PrintMessage(const Csm::csmChar* message); + /** + * @brief メッセージを出力し最後に改行する + * + * メッセージを出力し最後に改行する + * + * @param[in] message 文字列 + * + */ + static void PrintMessageLn(const Csm::csmChar* message); + private: static double s_currentFrame; static double s_lastFrame; diff --git a/Samples/OpenGL/Demo/proj.win.cmake/src/LAppView.cpp b/Samples/OpenGL/Demo/proj.win.cmake/src/LAppView.cpp index 0e9c7c8d..12cc7533 100644 --- a/Samples/OpenGL/Demo/proj.win.cmake/src/LAppView.cpp +++ b/Samples/OpenGL/Demo/proj.win.cmake/src/LAppView.cpp @@ -140,6 +140,7 @@ void LAppView::Render() if (model) { + _renderSprite->SetWindowSize(maxWidth, maxHeight); _renderSprite->RenderImmidiate( model->GetRenderBuffer().GetColorBuffer(), uvVertex); } } @@ -217,7 +218,7 @@ void LAppView::OnTouchesEnded(float px, float py) const float y = _deviceToScreen->TransformY(_touchManager->GetY()); // 論理座標変換した座標を取得。 if (DebugTouchLogEnable) { - LAppPal::PrintLog("[APP]touchesEnded x:%.2f y:%.2f", x, y); + LAppPal::PrintLogLn("[APP]touchesEnded x:%.2f y:%.2f", x, y); } live2DManager->OnTap(x, y); @@ -311,6 +312,12 @@ void LAppView::PostModelDraw(LAppModel& refModel) }; _renderSprite->SetColor(1.0f, 1.0f, 1.0f, GetSpriteAlpha(0)); + + // 画面サイズを取得する + int maxWidth, maxHeight; + glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &maxWidth, &maxHeight); + _renderSprite->SetWindowSize(maxWidth, maxHeight); + _renderSprite->RenderImmidiate(useTarget->GetColorBuffer(), uvVertex); } } diff --git a/Samples/OpenGL/Demo/proj.win.cmake/src/mainMinimum.cpp b/Samples/OpenGL/Demo/proj.win.cmake/src/mainMinimum.cpp index c3193970..b6c4b42d 100644 --- a/Samples/OpenGL/Demo/proj.win.cmake/src/mainMinimum.cpp +++ b/Samples/OpenGL/Demo/proj.win.cmake/src/mainMinimum.cpp @@ -96,12 +96,12 @@ static void InitializeCubism() */ static bool InitializeSystem() { - LAppPal::PrintLog("START"); + LAppPal::PrintLogLn("START"); // GLFWの初期化 if (glfwInit() == GL_FALSE) { - LAppPal::PrintLog("Can't initilize GLFW"); + LAppPal::PrintLogLn("Can't initilize GLFW"); return GL_FALSE; } @@ -110,7 +110,7 @@ static bool InitializeSystem() _window = glfwCreateWindow(LAppDefine::RenderTargetWidth, LAppDefine::RenderTargetHeight, "SIMPLE_SAMPLE", NULL, NULL); if (_window == NULL) { - LAppPal::PrintLog("Can't create GLFW window."); + LAppPal::PrintLogLn("Can't create GLFW window."); glfwTerminate(); return GL_FALSE; @@ -121,7 +121,7 @@ static bool InitializeSystem() glfwSwapInterval(1); if (glewInit() != GLEW_OK) { - LAppPal::PrintLog("Can't initilize glew."); + LAppPal::PrintLogLn("Can't initilize glew."); glfwTerminate(); return GL_FALSE; diff --git a/Samples/OpenGL/README.ja.md b/Samples/OpenGL/README.ja.md index a0216144..ff97206a 100644 --- a/Samples/OpenGL/README.ja.md +++ b/Samples/OpenGL/README.ja.md @@ -12,7 +12,7 @@ OpenGL で実装したアプリケーションのサンプル実装です。 | サードパーティ | バージョン | | --- | --- | | [GLEW] | 2.2.0 | -| [GLFW] | 3.3.9 | +| [GLFW] | 3.4 | | [ios-cmake] | 4.4.1 | | [stb_image.h] | 2.29 | @@ -100,6 +100,8 @@ Linux 用の CMake プロジェクトです。 追加ライブラリとして [GLEW] と [GLFW] を使用しています。 [thirdParty](#thirdParty) の項目を参照して事前にダウンロードを行なってください。 +ビルド時、これ以外に`libpng`やX Windows System依存ライブラリ等必要なパッケージのインストールを求められる場合がございますので、その際は求められたパッケージをインストールしてください。 + ### proj.mac.cmake diff --git a/Samples/OpenGL/README.md b/Samples/OpenGL/README.md index f928e558..f820e95a 100644 --- a/Samples/OpenGL/README.md +++ b/Samples/OpenGL/README.md @@ -12,7 +12,7 @@ This is a sample implementation of an application implemented with OpenGL. | Third Party | Version | | --- | --- | | [GLEW] | 2.2.0 | -| [GLFW] | 3.3.9 | +| [GLFW] | 3.4 | | [ios-cmake] | 4.4.1 | | [stb_image.h] | 2.29 | @@ -100,6 +100,8 @@ When you run these scripts, you can choose to generate the full version or the m [GLEW] and [GLFW] are used as additional libraries. Please refer to the [thirdParty](#thirdParty) section and download in advance. +During the build process, you may be prompted to install additional packages such as `libpng` or X Windows System dependent libraries. If prompted, please install the required packages. + ### proj.mac.cmake diff --git a/Samples/OpenGL/thirdParty/scripts/setup_glew_glfw b/Samples/OpenGL/thirdParty/scripts/setup_glew_glfw index e57ed842..21b061d2 100644 --- a/Samples/OpenGL/thirdParty/scripts/setup_glew_glfw +++ b/Samples/OpenGL/thirdParty/scripts/setup_glew_glfw @@ -3,7 +3,7 @@ set -ue GLEW_VERSION=2.2.0 -GLFW_VERSION=3.3.9 +GLFW_VERSION=3.4 SCRIPT_PATH=$(cd $(dirname $0) && pwd) diff --git a/Samples/OpenGL/thirdParty/scripts/setup_glew_glfw.bat b/Samples/OpenGL/thirdParty/scripts/setup_glew_glfw.bat index e78c98f5..d1a1977d 100644 --- a/Samples/OpenGL/thirdParty/scripts/setup_glew_glfw.bat +++ b/Samples/OpenGL/thirdParty/scripts/setup_glew_glfw.bat @@ -1,7 +1,7 @@ @echo off set GLEW_VERSION=2.2.0 -set GLFW_VERSION=3.3.9 +set GLFW_VERSION=3.4 set SCRIPT_PATH=%~dp0 diff --git a/Samples/OpenGL/thirdParty/scripts/setup_glew_glfw_vs2013.bat b/Samples/OpenGL/thirdParty/scripts/setup_glew_glfw_vs2013.bat index e78c98f5..9dc97117 100644 --- a/Samples/OpenGL/thirdParty/scripts/setup_glew_glfw_vs2013.bat +++ b/Samples/OpenGL/thirdParty/scripts/setup_glew_glfw_vs2013.bat @@ -1,7 +1,7 @@ @echo off -set GLEW_VERSION=2.2.0 -set GLFW_VERSION=3.3.9 +set GLEW_VERSION=2.1.0 +set GLFW_VERSION=3.4 set SCRIPT_PATH=%~dp0 diff --git a/Samples/Vulkan/Demo/proj.win.cmake/CMakeLists.txt b/Samples/Vulkan/Demo/proj.win.cmake/CMakeLists.txt index 6bce0ace..d4395186 100644 --- a/Samples/Vulkan/Demo/proj.win.cmake/CMakeLists.txt +++ b/Samples/Vulkan/Demo/proj.win.cmake/CMakeLists.txt @@ -118,8 +118,8 @@ add_subdirectory(src) # Add shader files. add_subdirectory(${SAMPLE_SHADER_PATH} ${CMAKE_CURRENT_BINARY_DIR}/SampleShaders) add_subdirectory(${FRAMEWORK_SHADER_PATH} ${CMAKE_CURRENT_BINARY_DIR}/FrameworkShaders) -add_dependencies(${APP_NAME} SampleShaders) -add_dependencies(${APP_NAME} FrameworkShaders) +add_dependencies(Framework SampleShaders) +add_dependencies(Framework FrameworkShaders) # Link libraries to app. target_link_libraries(${APP_NAME} diff --git a/Samples/Vulkan/Demo/proj.win.cmake/src/LAppDelegate.cpp b/Samples/Vulkan/Demo/proj.win.cmake/src/LAppDelegate.cpp index bb356317..dc12838f 100644 --- a/Samples/Vulkan/Demo/proj.win.cmake/src/LAppDelegate.cpp +++ b/Samples/Vulkan/Demo/proj.win.cmake/src/LAppDelegate.cpp @@ -49,7 +49,7 @@ bool LAppDelegate::Initialize() { if (DebugLogEnable) { - LAppPal::PrintLog("START"); + LAppPal::PrintLogLn("START"); } // GLFWの初期化 @@ -57,7 +57,7 @@ bool LAppDelegate::Initialize() { if (DebugLogEnable) { - LAppPal::PrintLog("Can't initilize GLFW"); + LAppPal::PrintLogLn("Can't initilize GLFW"); } return GL_FALSE; } @@ -71,7 +71,7 @@ bool LAppDelegate::Initialize() { if (DebugLogEnable) { - LAppPal::PrintLog("Can't create GLFW window."); + LAppPal::PrintLogLn("Can't create GLFW window."); } glfwTerminate(); return GL_FALSE; diff --git a/Samples/Vulkan/Demo/proj.win.cmake/src/LAppLive2DManager.cpp b/Samples/Vulkan/Demo/proj.win.cmake/src/LAppLive2DManager.cpp index 14795f30..f139ffd4 100644 --- a/Samples/Vulkan/Demo/proj.win.cmake/src/LAppLive2DManager.cpp +++ b/Samples/Vulkan/Demo/proj.win.cmake/src/LAppLive2DManager.cpp @@ -25,7 +25,7 @@ LAppLive2DManager* s_instance = NULL; void FinishedMotion(ACubismMotion* self) { - LAppPal::PrintLog("Motion Finished: %x", self); + LAppPal::PrintLogLn("Motion Finished: %x", self); } int CompareCsmString(const void* a, const void* b) @@ -149,7 +149,7 @@ void LAppLive2DManager::OnTap(csmFloat32 x, csmFloat32 y) { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]tap point: {x:%.2f y:%.2f}", x, y); + LAppPal::PrintLogLn("[APP]tap point: {x:%.2f y:%.2f}", x, y); } for (csmUint32 i = 0; i < _models.GetSize(); i++) @@ -158,7 +158,7 @@ void LAppLive2DManager::OnTap(csmFloat32 x, csmFloat32 y) { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameHead); + LAppPal::PrintLogLn("[APP]hit area: [%s]", HitAreaNameHead); } _models[i]->SetRandomExpression(); } @@ -166,7 +166,7 @@ void LAppLive2DManager::OnTap(csmFloat32 x, csmFloat32 y) { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameBody); + LAppPal::PrintLogLn("[APP]hit area: [%s]", HitAreaNameBody); } _models[i]->StartRandomMotion(MotionGroupTapBody, PriorityNormal, FinishedMotion); } @@ -189,7 +189,7 @@ void LAppLive2DManager::OnUpdate() const if (model->GetModel() == NULL) { - LAppPal::PrintLog("Failed to model->GetModel()."); + LAppPal::PrintLogLn("Failed to model->GetModel()."); continue; } @@ -228,7 +228,7 @@ void LAppLive2DManager::ChangeScene(Csm::csmInt32 index) _sceneIndex = index; if (DebugLogEnable) { - LAppPal::PrintLog("[APP]model index: %d", _sceneIndex); + LAppPal::PrintLogLn("[APP]model index: %d", _sceneIndex); } // model3.jsonのパスを決定する. diff --git a/Samples/Vulkan/Demo/proj.win.cmake/src/LAppModel.cpp b/Samples/Vulkan/Demo/proj.win.cmake/src/LAppModel.cpp index 8d1443e8..66c8493f 100644 --- a/Samples/Vulkan/Demo/proj.win.cmake/src/LAppModel.cpp +++ b/Samples/Vulkan/Demo/proj.win.cmake/src/LAppModel.cpp @@ -28,7 +28,7 @@ csmByte* CreateBuffer(const csmChar* path, csmSizeInt* size) { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]create buffer: %s ", path); + LAppPal::PrintLogLn("[APP]create buffer: %s ", path); } return LAppPal::LoadFileAsBytes(path, size); } @@ -37,7 +37,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "") { if (DebugLogEnable) { - LAppPal::PrintLog("[APP]delete buffer: %s", path); + LAppPal::PrintLogLn("[APP]delete buffer: %s", path); } LAppPal::ReleaseBytes(buffer); } @@ -89,7 +89,7 @@ void LAppModel::LoadAssets(VkDevice device, VkFormat imageFormat, const csmChar* if (_debugMode) { - LAppPal::PrintLog("[APP]load model setting: %s", fileName); + LAppPal::PrintLogLn("[APP]load model setting: %s", fileName); } csmSizeInt size; @@ -103,7 +103,7 @@ void LAppModel::LoadAssets(VkDevice device, VkFormat imageFormat, const csmChar* if (_model == NULL) { - LAppPal::PrintLog("Failed to LoadAssets()."); + LAppPal::PrintLogLn("Failed to LoadAssets()."); return; } @@ -129,7 +129,7 @@ void LAppModel::SetupModel(ICubismModelSetting* setting) if (_debugMode) { - LAppPal::PrintLog("[APP]create model: %s", setting->GetModelFileName()); + LAppPal::PrintLogLn("[APP]create model: %s", setting->GetModelFileName()); } buffer = CreateBuffer(path.GetRawString(), &size); @@ -239,7 +239,7 @@ void LAppModel::SetupModel(ICubismModelSetting* setting) if (_modelSetting == NULL || _modelMatrix == NULL) { - LAppPal::PrintLog("Failed to SetupModel()."); + LAppPal::PrintLogLn("Failed to SetupModel()."); return; } @@ -275,7 +275,7 @@ void LAppModel::PreloadMotionGroup(const csmChar* group) if (_debugMode) { - LAppPal::PrintLog("[APP]load motion: %s => [%s_%d] ", path.GetRawString(), group, i); + LAppPal::PrintLogLn("[APP]load motion: %s => [%s_%d] ", path.GetRawString(), group, i); } csmByte* buffer; @@ -459,7 +459,7 @@ CubismMotionQueueEntryHandle LAppModel::StartMotion(const csmChar* group, csmInt { if (_debugMode) { - LAppPal::PrintLog("[APP]can't start motion."); + LAppPal::PrintLogLn("[APP]can't start motion."); } return InvalidMotionQueueEntryHandleValue; } @@ -516,7 +516,7 @@ CubismMotionQueueEntryHandle LAppModel::StartMotion(const csmChar* group, csmInt if (_debugMode) { - LAppPal::PrintLog("[APP]start motion: [%s_%d]", group, no); + LAppPal::PrintLogLn("[APP]start motion: [%s_%d]", group, no); } return _motionManager->StartMotionPriority(motion, autoDelete, priority); } @@ -581,7 +581,7 @@ void LAppModel::SetExpression(const csmChar* expressionID) ACubismMotion* motion = _expressions[expressionID]; if (_debugMode) { - LAppPal::PrintLog("[APP]expression: [%s]", expressionID); + LAppPal::PrintLogLn("[APP]expression: [%s]", expressionID); } if (motion != NULL) @@ -590,7 +590,7 @@ void LAppModel::SetExpression(const csmChar* expressionID) } else { - if (_debugMode) LAppPal::PrintLog("[APP]expression[%s] is null ", expressionID); + if (_debugMode) LAppPal::PrintLogLn("[APP]expression[%s] is null ", expressionID); } } diff --git a/Samples/Vulkan/Demo/proj.win.cmake/src/LAppPal.cpp b/Samples/Vulkan/Demo/proj.win.cmake/src/LAppPal.cpp index 4fc4ceca..48587675 100644 --- a/Samples/Vulkan/Demo/proj.win.cmake/src/LAppPal.cpp +++ b/Samples/Vulkan/Demo/proj.win.cmake/src/LAppPal.cpp @@ -34,20 +34,38 @@ csmByte* LAppPal::LoadFileAsBytes(const string filePath, csmSizeInt* outSize) if (stat(path, &statBuf) == 0) { size = statBuf.st_size; + + if (size == 0) + { + if (DebugLogEnable) + { + PrintLogLn("Stat succeeded but file size is zero. path:%s", path); + } + return NULL; + } + } + else + { + if (DebugLogEnable) + { + PrintLogLn("Stat failed. errno:%d path:%s", errno, path); + } + return NULL; } std::fstream file; - char* buf = new char[size]; file.open(path, std::ios::in | std::ios::binary); if (!file.is_open()) { if (DebugLogEnable) { - PrintLog("file open error"); + PrintLogLn("File open failed. path:%s", path); } return NULL; } + + char* buf = new char[size]; file.read(buf, size); file.close(); @@ -82,7 +100,22 @@ void LAppPal::PrintLog(const csmChar* format, ...) // メモリリークチェック時は大量の標準出力がはしり重いのでprintfを利用する std::printf(buf); #else - std::cerr << buf << std::endl; + std::cout << buf; +#endif + va_end(args); +} + +void LAppPal::PrintLogLn(const csmChar* format, ...) +{ + va_list args; + csmChar buf[256]; + va_start(args, format); + vsnprintf_s(buf, sizeof(buf), format, args); // 標準出力でレンダリング +#ifdef CSM_DEBUG_MEMORY_LEAKING + // メモリリークチェック時は大量の標準出力がはしり重いのでprintfを利用する + std::printf("%s\n", buf); +#else + std::cout << buf << std::endl; #endif va_end(args); } @@ -91,3 +124,8 @@ void LAppPal::PrintMessage(const csmChar* message) { PrintLog("%s", message); } + +void LAppPal::PrintMessageLn(const csmChar* message) +{ + PrintLogLn("%s", message); +} diff --git a/Samples/Vulkan/Demo/proj.win.cmake/src/LAppPal.hpp b/Samples/Vulkan/Demo/proj.win.cmake/src/LAppPal.hpp index dcf7cd87..f65e11fb 100644 --- a/Samples/Vulkan/Demo/proj.win.cmake/src/LAppPal.hpp +++ b/Samples/Vulkan/Demo/proj.win.cmake/src/LAppPal.hpp @@ -60,6 +60,17 @@ class LAppPal */ static void PrintLog(const Csm::csmChar* format, ...); + /** + * @brief ログを出力し最後に改行する + * + * ログを出力し最後に改行する + * + * @param[in] format 書式付文字列 + * @param[in] ... (可変長引数)文字列 + * + */ + static void PrintLogLn(const Csm::csmChar* format, ...); + /** * @brief メッセージを出力する * @@ -70,6 +81,16 @@ class LAppPal */ static void PrintMessage(const Csm::csmChar* message); + /** + * @brief メッセージを出力し最後に改行する + * + * メッセージを出力し最後に改行する + * + * @param[in] message 文字列 + * + */ + static void PrintMessageLn(const Csm::csmChar* message); + private: static double s_currentFrame; static double s_lastFrame; diff --git a/Samples/Vulkan/Demo/proj.win.cmake/src/LAppSprite.cpp b/Samples/Vulkan/Demo/proj.win.cmake/src/LAppSprite.cpp index d968557c..d7233121 100644 --- a/Samples/Vulkan/Demo/proj.win.cmake/src/LAppSprite.cpp +++ b/Samples/Vulkan/Demo/proj.win.cmake/src/LAppSprite.cpp @@ -7,14 +7,13 @@ #include "LAppSprite.hpp" #include "LAppTextureManager.hpp" -#include "LAppDelegate.hpp" +#include "VulkanManager.hpp" using namespace Csm; LAppSprite::LAppSprite( - VkDevice device, VkPhysicalDevice physicalDevice, - float x, float y, float width, float height, - Csm::csmUint32 textureId, VkDescriptorSetLayout descriptorSetLayout) + VkDevice device, VkPhysicalDevice physicalDevice, VulkanManager* vkManager, float x, float y, float width, float height, + Csm::csmUint32 textureId, VkImageView view, VkSampler sampler, VkDescriptorSetLayout descriptorSetLayout) : _rect() { _rect.left = (x - width * 0.5f); @@ -59,11 +58,11 @@ LAppSprite::LAppSprite( VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); - VkCommandBuffer commandBuffer = LAppDelegate::GetInstance()->GetVulkanManager()->BeginSingleTimeCommands(); + VkCommandBuffer commandBuffer = vkManager->BeginSingleTimeCommands(); VkBufferCopy copyRegion{}; copyRegion.size = bufferSize; vkCmdCopyBuffer(commandBuffer, stagingBuffer.GetBuffer(), _indexBuffer.GetBuffer(), 1, ©Region); - LAppDelegate::GetInstance()->GetVulkanManager()->SubmitCommand(commandBuffer); + vkManager->SubmitCommand(commandBuffer); stagingBuffer.Destroy(device); } @@ -89,23 +88,22 @@ LAppSprite::LAppSprite( if (vkCreateDescriptorPool(device, &poolInfo, nullptr, &_descriptorPool) != VK_SUCCESS) { - LAppPal::PrintLog("failed to create descriptor pool!"); + LAppPal::PrintLogLn("failed to create descriptor pool!"); } CreateDescriptorSet(device, descriptorSetLayout); - if (textureId != 0) + if (view != NULL && sampler != NULL) { - CubismImageVulkan image; - LAppDelegate::GetInstance()->GetTextureManager()->GetTexture(_textureId, image); SetDescriptorUpdated(false); - UpdateDescriptorSet(device, image.GetView(), image.GetSampler()); + UpdateDescriptorSet(device, view, sampler); } } LAppSprite::~LAppSprite() +{} + +void LAppSprite::Release(VkDevice device) { - LAppDelegate::GetInstance()->GetTextureManager()->ReleaseTexture(_textureId); - VkDevice device = LAppDelegate::GetInstance()->GetVulkanManager()->GetDevice(); _vertexBuffer.Destroy(device); _stagingBuffer.Destroy(device); _indexBuffer.Destroy(device); @@ -122,16 +120,12 @@ void LAppSprite::CreateDescriptorSet(VkDevice device, VkDescriptorSetLayout desc allocInfo.pSetLayouts = &descriptorSetLayout; if (vkAllocateDescriptorSets(device, &allocInfo, &_descriptorSet) != VK_SUCCESS) { - LAppPal::PrintLog("failed to allocate descriptor sets!"); + LAppPal::PrintLogLn("failed to allocate descriptor sets!"); } } -void LAppSprite::UpdateData() const +void LAppSprite::UpdateData(VulkanManager* vkManager, int maxWidth, int maxHeight) const { - // 画面サイズを取得する - int maxWidth, maxHeight; - glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &maxWidth, &maxHeight); - if (maxWidth == 0 || maxHeight == 0) { return; // この際は描画できず @@ -164,7 +158,7 @@ void LAppSprite::UpdateData() const vertices.PushBack(vertex); } - VkCommandBuffer commandBuffer = LAppDelegate::GetInstance()->GetVulkanManager()->BeginSingleTimeCommands(); + VkCommandBuffer commandBuffer = vkManager->BeginSingleTimeCommands(); csmUint32 bufferSize = sizeof(SpriteVertex) * vertices.GetSize(); _stagingBuffer.MemCpy(vertices.GetPtr(), bufferSize); @@ -173,7 +167,7 @@ void LAppSprite::UpdateData() const copyRegion.size = bufferSize; vkCmdCopyBuffer(commandBuffer, _stagingBuffer.GetBuffer(), _vertexBuffer.GetBuffer(), 1, ©Region); - LAppDelegate::GetInstance()->GetVulkanManager()->SubmitCommand(commandBuffer); + vkManager->SubmitCommand(commandBuffer); //ユニフォームバッファ設定 SpriteUBO _ubo; @@ -225,9 +219,9 @@ void LAppSprite::SetDescriptorUpdated(bool frag) isDescriptorUpdated = frag; } -void LAppSprite::Render(VkCommandBuffer commandBuffer, VkPipelineLayout pipelineLayout) +void LAppSprite::Render(VkCommandBuffer commandBuffer, VkPipelineLayout pipelineLayout, VulkanManager* vkManager, int windowWidth, int windowHeight) { - UpdateData(); + UpdateData(vkManager, windowWidth, windowHeight); VkBuffer vertexBuffers[] = {_vertexBuffer.GetBuffer()}; VkDeviceSize offsets[] = {0}; vkCmdBindVertexBuffers(commandBuffer, 0, 1, vertexBuffers, offsets); @@ -236,13 +230,9 @@ void LAppSprite::Render(VkCommandBuffer commandBuffer, VkPipelineLayout pipeline vkCmdDrawIndexed(commandBuffer, IndexNum, 1, 0, 0, 0); } -bool LAppSprite::IsHit(float pointX, float pointY) const +bool LAppSprite::IsHit(int windowWidth, int windowHeight, float pointX, float pointY) const { - // 画面サイズを取得する - int maxWidth, maxHeight; - glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &maxWidth, &maxHeight); - - if (maxWidth == 0 || maxHeight == 0) + if (windowWidth == 0 || windowHeight == 0) { return false; // この際は描画できず } diff --git a/Samples/Vulkan/Demo/proj.win.cmake/src/LAppSprite.hpp b/Samples/Vulkan/Demo/proj.win.cmake/src/LAppSprite.hpp index 8d2ac121..f0ddd7b0 100644 --- a/Samples/Vulkan/Demo/proj.win.cmake/src/LAppSprite.hpp +++ b/Samples/Vulkan/Demo/proj.win.cmake/src/LAppSprite.hpp @@ -8,6 +8,9 @@ #pragma once #include +// 前方宣言 +class VulkanManager; + /** * @brief スプライトを実装するクラス。 * @@ -78,17 +81,21 @@ class LAppSprite /** * @brief コンストラクタ * + * @param[in] device デバイス + * @param[in] physicalDevice 物理デバイス + * @param[in] vkManager Vulkanリソースマネージャ * @param[in] x x座標 * @param[in] y y座標 * @param[in] width 横幅 * @param[in] height 高さ * @param[in] textureId テクスチャID + * @param[in] view テクスチャビュー + * @param[in] sampler テクスチャサンプラー * @param[in] descriptorSetLayout ディスクリプタセット */ LAppSprite( - VkDevice device, VkPhysicalDevice physicalDevice, - float x, float y, float width, float height, - uint32_t textureId, VkDescriptorSetLayout descriptorSetLayout + VkDevice device, VkPhysicalDevice physicalDevice, VulkanManager* vkManager, float x, float y, float width, float height, + uint32_t textureId, VkImageView view, VkSampler sampler, VkDescriptorSetLayout descriptorSetLayout ); /** @@ -96,8 +103,16 @@ class LAppSprite */ ~LAppSprite(); + /** + * @brief リソースを開放する + * + * @param[in] device デバイス + */ + void Release(VkDevice device); + /** * @brief ディスクリプタセットを作成する + * * @param[in] device デバイス * @param[in] descriptorSetLayout ディスクリプタセットレイアウト */ @@ -105,8 +120,12 @@ class LAppSprite /** * @brief ユニフォームバッファを更新する + * + * @param[in] vkManager Vulkanリソースマネージャ + * @param[in] maxWidth 最大幅 + * @param[in] maxHeight 最大高さ */ - void UpdateData() const; + void UpdateData(VulkanManager* vkManager, int maxWidth, int maxHeight) const; /** * @brief ディスクリプタセットを更新する @@ -129,16 +148,21 @@ class LAppSprite * * @param[in] commandBuffer コマンドバッファ * @param[in] pipelineLayout パイプラインレイアウト + * @param[in] vkManager Vulkanリソースマネージャ + * @param[in] windowWidth ウィンドウ幅 + * @param[in] windowHeight ウィンドウ高さ */ - void Render(VkCommandBuffer commandBuffer, VkPipelineLayout pipelineLayout); + void Render(VkCommandBuffer commandBuffer, VkPipelineLayout pipelineLayout, VulkanManager* vkManager, int windowWidth, int windowHeight); /** * @brief コンストラクタ * - * @param[in] pointX x座標 - * @param[in] pointY y座標 + * @param[in] windowWidth ウィンドウ幅 + * @param[in] windowHeight ウィンドウ高さ + * @param[in] pointX x座標 + * @param[in] pointY y座標 */ - bool IsHit(float pointX, float pointY) const; + bool IsHit(int windowWidth, int windowHeight, float pointX, float pointY) const; /** * @brief 色設定 diff --git a/Samples/Vulkan/Demo/proj.win.cmake/src/LAppTextureManager.cpp b/Samples/Vulkan/Demo/proj.win.cmake/src/LAppTextureManager.cpp index 2c4d8a13..10bf4639 100644 --- a/Samples/Vulkan/Demo/proj.win.cmake/src/LAppTextureManager.cpp +++ b/Samples/Vulkan/Demo/proj.win.cmake/src/LAppTextureManager.cpp @@ -174,7 +174,7 @@ LAppTextureManager::TextureInfo* LAppTextureManager::CreateTextureFromPngFile( VkDeviceSize imageSize = static_cast(width * height * 4); if (!png) { - LAppPal::PrintLog("could'nt load texture image."); + LAppPal::PrintLogLn("could'nt load texture image."); } CubismBufferVulkan stagingBuffer; diff --git a/Samples/Vulkan/Demo/proj.win.cmake/src/LAppView.cpp b/Samples/Vulkan/Demo/proj.win.cmake/src/LAppView.cpp index 50f1695d..95054aeb 100644 --- a/Samples/Vulkan/Demo/proj.win.cmake/src/LAppView.cpp +++ b/Samples/Vulkan/Demo/proj.win.cmake/src/LAppView.cpp @@ -59,6 +59,13 @@ LAppView::~LAppView() delete _viewMatrix; delete _deviceToScreen; delete _touchManager; + + LAppDelegate::GetInstance()->GetTextureManager()->ReleaseTexture(_back->GetTextureId()); + LAppDelegate::GetInstance()->GetTextureManager()->ReleaseTexture(_gear->GetTextureId()); + LAppDelegate::GetInstance()->GetTextureManager()->ReleaseTexture(_power->GetTextureId()); + _back->Release(device); + _gear->Release(device); + _power->Release(device); delete _back; delete _gear; delete _power; @@ -152,15 +159,17 @@ void LAppView::Render() } //スプライト描画 + int width, height; + glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height); VulkanManager* vkManager = LAppDelegate::GetInstance()->GetVulkanManager(); VkCommandBufferBeginInfo beginInfo{}; beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; VkCommandBuffer commandBuffer = vkManager->BeginSingleTimeCommands(); BeginRendering(commandBuffer, 0.0, 0.0, 0.0, 1.0, true); vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, _pipeline); - _back->Render(commandBuffer, _pipelineLayout); - _gear->Render(commandBuffer, _pipelineLayout); - _power->Render(commandBuffer, _pipelineLayout); + _back->Render(commandBuffer, _pipelineLayout, vkManager, width, height); + _gear->Render(commandBuffer, _pipelineLayout, vkManager, width, height); + _power->Render(commandBuffer, _pipelineLayout, vkManager, width, height); EndRendering(commandBuffer); vkManager->SubmitCommand(commandBuffer, true); @@ -187,7 +196,7 @@ void LAppView::Render() _renderSprite->SetColor(1.0f, 1.0f, 1.0f, alpha); if (model) { - _renderSprite->Render(commandBuffer, _pipelineLayout); + _renderSprite->Render(commandBuffer, _pipelineLayout, vkManager, width, height); } EndRendering(commandBuffer); vkManager->SubmitCommand(commandBuffer); @@ -248,7 +257,7 @@ void LAppView::CreateDescriptorSetLayout(VkDevice device) if (vkCreateDescriptorSetLayout(device, &layoutInfo, nullptr, &_descriptorSetLayout) != VK_SUCCESS) { - LAppPal::PrintLog("failed to create descriptor set layout!"); + LAppPal::PrintLogLn("failed to create descriptor set layout!"); } } @@ -344,7 +353,7 @@ void LAppView::CreateSpriteGraphicsPipeline(VkDevice device, VkExtent2D extent, if (vkCreatePipelineLayout(device, &pipelineLayoutInfo, nullptr, &_pipelineLayout) != VK_SUCCESS) { - LAppPal::PrintLog("failed to create pipeline layout!"); + LAppPal::PrintLogLn("failed to create pipeline layout!"); } VkPipelineRenderingCreateInfo renderingInfo{}; @@ -369,7 +378,7 @@ void LAppView::CreateSpriteGraphicsPipeline(VkDevice device, VkExtent2D extent, if (vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &_pipeline) != VK_SUCCESS) { - LAppPal::PrintLog("failed to create graphics pipeline!"); + LAppPal::PrintLogLn("failed to create graphics pipeline!"); } } @@ -392,6 +401,7 @@ void LAppView::InitializeSprite() const string resourcesPath = ResourcesPath; string imageName; + CubismImageVulkan textureImage; float x; float y; float fWidth; @@ -402,45 +412,50 @@ void LAppView::InitializeSprite() resourcesPath + imageName, vkManager->GetImageFormat(), VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); + LAppDelegate::GetInstance()->GetTextureManager()->GetTexture(backgroundTexture->id, textureImage); x = width * 0.5f; y = height * 0.5f; fWidth = static_cast(backgroundTexture->width * 2.0f); fHeight = static_cast(height * 0.95f); - _back = new LAppSprite(device, physicalDevice, x, y, fWidth, fHeight, backgroundTexture->id, _descriptorSetLayout); + _back = new LAppSprite(device, physicalDevice, vkManager, x, y, fWidth, fHeight, backgroundTexture->id, + textureImage.GetView(), textureImage.GetSampler(), _descriptorSetLayout); imageName = GearImageName; LAppTextureManager::TextureInfo* gearTexture = textureManager->CreateTextureFromPngFile( resourcesPath + imageName, vkManager->GetImageFormat(), VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); + LAppDelegate::GetInstance()->GetTextureManager()->GetTexture(gearTexture->id, textureImage); //X:右向き正、Y:下向き正 x = static_cast(width - gearTexture->width * 0.5f); y = static_cast(gearTexture->height * 0.5f); fWidth = static_cast(gearTexture->width); fHeight = static_cast(gearTexture->height); - _gear = new LAppSprite(device, physicalDevice, x, y, fWidth, fHeight, gearTexture->id, _descriptorSetLayout); + _gear = new LAppSprite(device, physicalDevice, vkManager, x, y, fWidth, fHeight, gearTexture->id, + textureImage.GetView(), textureImage.GetSampler(), _descriptorSetLayout); imageName = PowerImageName; LAppTextureManager::TextureInfo* powerTexture = textureManager->CreateTextureFromPngFile( resourcesPath + imageName, vkManager->GetImageFormat(), VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, - VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT - ); + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); + LAppDelegate::GetInstance()->GetTextureManager()->GetTexture(powerTexture->id, textureImage); //X:右向き正、Y:下向き正 x = static_cast(width - powerTexture->width * 0.5f); y = static_cast(height - powerTexture->height * 0.5f); fWidth = static_cast(powerTexture->width); fHeight = static_cast(powerTexture->height); - _power = new LAppSprite(device, physicalDevice, x, y, fWidth, fHeight, powerTexture->id, _descriptorSetLayout); + _power = new LAppSprite(device, physicalDevice, vkManager, x, y, fWidth, fHeight, powerTexture->id, + textureImage.GetView(), textureImage.GetSampler(), _descriptorSetLayout); // 画面全体を覆うサイズ x = width * 0.5f; y = height * 0.5f; LAppLive2DManager* live2DManager = LAppLive2DManager::GetInstance(); - _renderSprite = new LAppSprite(device, physicalDevice, x, y, static_cast(width), static_cast(height),0, _descriptorSetLayout); + _renderSprite = new LAppSprite(device, physicalDevice, vkManager, x, y, static_cast(width), static_cast(height),0, NULL, NULL, _descriptorSetLayout); } void LAppView::OnTouchesBegan(float px, float py) const @@ -470,18 +485,22 @@ void LAppView::OnTouchesEnded(float px, float py) const float y = _deviceToScreen->TransformY(_touchManager->GetY()); // 論理座標変換した座標を取得。 if (DebugTouchLogEnable) { - LAppPal::PrintLog("[APP]touchesEnded x:%.2f y:%.2f", x, y); + LAppPal::PrintLogLn("[APP]touchesEnded x:%.2f y:%.2f", x, y); } live2DManager->OnTap(x, y); + // 画面サイズの取得 + int windowWidth, windowHeight; + glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &windowWidth, &windowHeight); + // 歯車にタップしたか - if (_gear->IsHit(px, py)) + if (_gear->IsHit(windowWidth, windowHeight, px, py)) { live2DManager->NextScene(); } // 電源ボタンにタップしたか - if (_power->IsHit(px, py)) + if (_power->IsHit(windowWidth, windowHeight, px, py)) { LAppDelegate::GetInstance()->AppEnd(); } @@ -555,6 +574,8 @@ void LAppView::PostModelDraw(LAppModel& refModel, csmInt32 modelIndex) // LAppViewの持つフレームバッファを使うなら、スプライトへの描画はここ if (_renderTarget == SelectTarget_ViewFrameBuffer && _renderSprite) { + int width, height; + glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height); VulkanManager* vkManager = LAppDelegate::GetInstance()->GetVulkanManager(); VkCommandBuffer commandBuffer = vkManager->BeginSingleTimeCommands(); _renderSprite->UpdateDescriptorSet(vkManager->GetDevice(), useTarget->GetTextureView(), @@ -562,7 +583,7 @@ void LAppView::PostModelDraw(LAppModel& refModel, csmInt32 modelIndex) BeginRendering(commandBuffer, 0.f, 0.f, 0.3, 1.f, false); vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, _pipeline); _renderSprite->SetColor(1.0f, 1.0f, 1.0f, GetSpriteAlpha(0)); - _renderSprite->Render(commandBuffer, _pipelineLayout); + _renderSprite->Render(commandBuffer, _pipelineLayout, vkManager, width, height); EndRendering(commandBuffer); vkManager->SubmitCommand(commandBuffer); } diff --git a/Samples/Vulkan/Demo/proj.win.cmake/src/SwapchainManager.cpp b/Samples/Vulkan/Demo/proj.win.cmake/src/SwapchainManager.cpp index c8ae81db..cae6c229 100644 --- a/Samples/Vulkan/Demo/proj.win.cmake/src/SwapchainManager.cpp +++ b/Samples/Vulkan/Demo/proj.win.cmake/src/SwapchainManager.cpp @@ -145,7 +145,7 @@ void SwapchainManager::CreateSwapchain(GLFWwindow* window, VkPhysicalDevice phys createInfo.oldSwapchain = VK_NULL_HANDLE; if (vkCreateSwapchainKHR(device, &createInfo, nullptr, &swapchain) != VK_SUCCESS) { - LAppPal::PrintLog("failed to create swap chain"); + LAppPal::PrintLogLn("failed to create swap chain"); } // swapchain imageを取得する @@ -173,7 +173,7 @@ void SwapchainManager::CreateSwapchain(GLFWwindow* window, VkPhysicalDevice phys if (vkCreateImageView(device, &viewInfo, nullptr, &imageViews[i]) != VK_SUCCESS) { - LAppPal::PrintLog("failed to create texture image view"); + LAppPal::PrintLogLn("failed to create texture image view"); } } } diff --git a/Samples/Vulkan/Demo/proj.win.cmake/src/VulkanManager.cpp b/Samples/Vulkan/Demo/proj.win.cmake/src/VulkanManager.cpp index 198d4647..ca410dd7 100644 --- a/Samples/Vulkan/Demo/proj.win.cmake/src/VulkanManager.cpp +++ b/Samples/Vulkan/Demo/proj.win.cmake/src/VulkanManager.cpp @@ -141,7 +141,7 @@ void VulkanManager::CreateInstance() //検証レイヤーが有効のときに使えるか確認 if (_enableValidationLayers && !CheckValidationLayerSupport()) { - LAppPal::PrintLog("validation layers requested, but not available!"); + LAppPal::PrintLogLn("validation layers requested, but not available!"); } VkApplicationInfo appInfo{}; @@ -174,7 +174,7 @@ void VulkanManager::CreateInstance() } if (vkCreateInstance(&createInfo, nullptr, &_instance) != VK_SUCCESS) { - LAppPal::PrintLog("failed to create _instance!"); + LAppPal::PrintLogLn("failed to create _instance!"); } } @@ -187,7 +187,7 @@ void VulkanManager::SetupDebugMessenger() if (CreateDebugUtilsMessengerEXT(_instance, &createInfo, nullptr, &_debugMessenger) != VK_SUCCESS) { - LAppPal::PrintLog("failed to set up debug messenger!"); + LAppPal::PrintLogLn("failed to set up debug messenger!"); } } @@ -222,7 +222,7 @@ void VulkanManager::CreateSurface() { if (glfwCreateWindowSurface(_instance, _window, nullptr, &_surface) != VK_SUCCESS) { - LAppPal::PrintLog("failed to create _window _surface!"); + LAppPal::PrintLogLn("failed to create _window _surface!"); } } @@ -281,7 +281,7 @@ void VulkanManager::PickPhysicalDevice() if (deviceCount == 0) { - LAppPal::PrintLog("failed to find GPUs with Vulkan support!"); + LAppPal::PrintLogLn("failed to find GPUs with Vulkan support!"); } csmVector devices; @@ -300,7 +300,7 @@ void VulkanManager::PickPhysicalDevice() if (_physicalDevice == VK_NULL_HANDLE) { - LAppPal::PrintLog("failed to find a suitable GPU!"); + LAppPal::PrintLogLn("failed to find a suitable GPU!"); } } @@ -365,7 +365,7 @@ void VulkanManager::CreateLogicalDevice() if (vkCreateDevice(_physicalDevice, &createInfo, nullptr, &_device) != VK_SUCCESS) { - LAppPal::PrintLog("failed to create logical _device!"); + LAppPal::PrintLogLn("failed to create logical _device!"); } // キューハンドルを取得 @@ -407,7 +407,7 @@ void VulkanManager::CreateCommandPool() if (vkCreateCommandPool(_device, &poolInfo, nullptr, &_commandPool) != VK_SUCCESS) { - LAppPal::PrintLog("failed to create graphics command pool!"); + LAppPal::PrintLogLn("failed to create graphics command pool!"); } } @@ -485,7 +485,7 @@ void VulkanManager::UpdateDrawFrame() } else if (result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR) { - LAppPal::PrintLog("failed to acquire swap chain image!"); + LAppPal::PrintLogLn("failed to acquire swap chain image!"); } } @@ -497,7 +497,7 @@ void VulkanManager::PostDraw() _isSwapchainInvalid = true; } else if (result != VK_SUCCESS) { - LAppPal::PrintLog("failed to present swap chain image!"); + LAppPal::PrintLogLn("failed to present swap chain image!"); } } diff --git a/Samples/Vulkan/README.ja.md b/Samples/Vulkan/README.ja.md index 323d8306..d8268505 100644 --- a/Samples/Vulkan/README.ja.md +++ b/Samples/Vulkan/README.ja.md @@ -7,9 +7,9 @@ Vulkan で実装したアプリケーションのサンプル実装です。 | サードパーティ | バージョン | | --- | --- | -| [GLFW] | 3.3.9 | +| [GLFW] | 3.4 | | [stb_image.h] | 2.29 | -| [Vulkan SDK] |1.3| +| [Vulkan SDK] | 1.3 | その他の開発環境・動作確認環境はトップディレクトリにある [README.ja.md](/README.ja.md) を参照してください。 diff --git a/Samples/Vulkan/README.md b/Samples/Vulkan/README.md index 467300db..a07b60b7 100644 --- a/Samples/Vulkan/README.md +++ b/Samples/Vulkan/README.md @@ -7,9 +7,9 @@ This is a sample implementation of an application implemented with Vulkan. | Third Party | Version | | --- | --- | -| [GLFW] | 3.3.9 | +| [GLFW] | 3.4 | | [stb_image.h] | 2.29 | -| [Vulkan SDK] |1.3| +| [Vulkan SDK] | 1.3 | For other development environment and operation environment, refer to [README.md](/README.md) in the top directory. diff --git a/Samples/Vulkan/Shaders/CMakeLists.txt b/Samples/Vulkan/Shaders/CMakeLists.txt index f0720ccc..3a8f7297 100644 --- a/Samples/Vulkan/Shaders/CMakeLists.txt +++ b/Samples/Vulkan/Shaders/CMakeLists.txt @@ -10,8 +10,8 @@ foreach(shader ${shader_files}) set(output_dir ${CMAKE_CURRENT_BINARY_DIR}/compiledShaders) string(REGEX REPLACE \\.frag|\\.vert "" output_file ${file_name}) set(output_file ${output_dir}/${output_file}.spv) - set(compiled_shaders ${compiled_shaders} ${output_file}) - set(compiled_shaders ${compiled_shaders} PARENT_SCOPE) + set(compiled_shaders_app ${compiled_shaders_app} ${output_file}) + set(compiled_shaders_app ${compiled_shaders_app} PARENT_SCOPE) set_source_files_properties(${shader} PROPERTIES HEADER_FILE_ONLY TRUE) add_custom_command( @@ -25,6 +25,6 @@ endforeach() source_group("shaders" FILES ${shader_files}) add_custom_target( SampleShaders ALL - DEPENDS ${compiled_shaders} + DEPENDS ${compiled_shaders_app} SOURCES ${shader_files} )