完成在Android上渲染三角形

This commit is contained in:
xsl
2025-10-18 21:13:03 +08:00
parent 2db7194305
commit 4237213658
7 changed files with 59 additions and 34 deletions
+24 -2
View File
@@ -1,14 +1,23 @@
#include "AppBase.h"
#include <assert.h>
#ifdef _WIN32
#else
#include <android/asset_manager.h>
extern AAssetManager* g_assetManager;
#endif // _WIN32
void VK_CHECK(VkResult ret)
{
assert(ret == VK_SUCCESS);
}
std::vector<char> AppBase::readFile(const std::string& enginePath)
std::vector<char> AppBase::readFile(const std::string& path)
{
std::vector<char> buffer;
#ifdef _WIN32
std::string enginePath = "app/src/main/assets/" + path;
std::ifstream file{ enginePath, std::ios::ate | std::ios::binary };
if (!file.is_open())
@@ -17,13 +26,26 @@ std::vector<char> AppBase::readFile(const std::string& enginePath)
}
size_t fileSize = static_cast<size_t>(file.tellg());
std::vector<char> buffer(fileSize);
buffer.resize(fileSize);
file.seekg(0);
file.read(buffer.data(), fileSize);
file.close();
#else
AAsset* asset = AAssetManager_open(g_assetManager, path.c_str(), AASSET_MODE_BUFFER);
if (!asset) {
logOut << "Failed to load file: " << path.c_str() << std::endl;
return buffer;
}
size_t length = AAsset_getLength(asset);
buffer.resize(length);
AAsset_read(asset, buffer.data(), length);
AAsset_close(asset);
#endif // _WIN32
return buffer;
}
VkShaderModule AppBase::createShaderModule(VkDevice& device, const std::vector<char>& code)
{
VkShaderModuleCreateInfo createInfo{};