replace view with texture, move plugin to Swift implementation

This commit is contained in:
Nick Fisher
2022-08-19 12:39:55 +08:00
parent 21fef19359
commit c6e429bcba
20 changed files with 658 additions and 491 deletions

View File

@@ -1,52 +1,21 @@
#pragma once
#include <functional>
#include <memory>
#include "ResourceBuffer.hpp"
namespace polyvox {
//
// Pairs a memory buffer with an ID that can be used to unload the backing asset if needed.
// Use this when you want to load an asset from a resource that requires more than just `free` on the underlying buffer.
// e.g.
// ```
// uint64_t id = get_next_resource_id();
// AAsset *asset = AAssetManager_open(am, name, AASSET_MODE_BUFFER);
// off_t length = AAsset_getLength(asset);
// const void * buffer = AAsset_getBuffer(asset);
// uint8_t *buf = new uint8_t[length ];
// memcpy(buf,buffer, length);
// ResourceBuffer rb(buf, length, id);
// ...
// ...
// (elsewhere)
// AAsset* asset = get_asset_from_id(rb.id);
// AAsset_close(asset);
// free_asset_id(rb.id);
//
struct ResourceBuffer {
ResourceBuffer(const void* data, const uint32_t size, const uint32_t id) : data(data), size(size), id(id) {};
ResourceBuffer& operator=(ResourceBuffer other)
{
data = other.data;
size = other.size;
id = other.id;
return *this;
}
const void* data;
uint32_t size;
uint32_t id;
};
using namespace std;
//
// Typedef for any function that loads a resource into a ResourceBuffer from an asset URI.
// Typedef for a function that loads a resource into a ResourceBuffer from an asset URI.
//
using LoadResource = std::function<ResourceBuffer(const char* uri)>;
using LoadResource = function<ResourceBuffer(const char* uri)>;
//
// Typedef for any function that frees a ResourceBuffer.
// Typedef for a function that frees an ID associated with a ResourceBuffer.
//
using FreeResource = std::function<void (ResourceBuffer)>;
using FreeResource = function<void (uint32_t)>;
typedef std::chrono::time_point<std::chrono::high_resolution_clock> time_point_t;
@@ -110,4 +79,5 @@ namespace polyvox {
float* frameData;
int numWeights;
};
}
}