mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 06:08:30 +09:00
[Feat] (MG_State/GLState): Implement BufferObject.
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
namespace MobileGL {
|
||||
template <typename IndexType>
|
||||
class IndexGenerator {
|
||||
public:
|
||||
IndexGenerator() : next_index_(1) {}
|
||||
explicit IndexGenerator(IndexType n) : next_index_(1) {
|
||||
is_valid_.reserve(n);
|
||||
}
|
||||
|
||||
void Generate(size_t n, IndexType* indices) {
|
||||
if (n <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
size_t count_from_freed = std::min(n, freed_indices_.size());
|
||||
for (size_t i = 0; i < count_from_freed; ++i) {
|
||||
indices[i] = freed_indices_.back();
|
||||
freed_indices_.pop_back();
|
||||
if (indices[i] >= is_valid_.size()) {
|
||||
is_valid_.resize(static_cast<size_t>(indices[i]) + 1, false);
|
||||
}
|
||||
is_valid_[indices[i]] = true;
|
||||
}
|
||||
|
||||
for (size_t i = count_from_freed; i < n; ++i) {
|
||||
indices[i] = next_index_++;
|
||||
if (indices[i] >= is_valid_.size()) {
|
||||
is_valid_.resize(static_cast<size_t>(indices[i]) + 1, false);
|
||||
}
|
||||
is_valid_[indices[i]] = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Delete(IndexType index) {
|
||||
if (index < is_valid_.size() && is_valid_[index] == true) {
|
||||
is_valid_[index] = false;
|
||||
freed_indices_.push_back(index);
|
||||
}
|
||||
}
|
||||
|
||||
bool IsValid(IndexType index) const {
|
||||
return index < is_valid_.size() && is_valid_[index] == true;
|
||||
}
|
||||
|
||||
private:
|
||||
IndexType next_index_;
|
||||
std::vector<IndexType> freed_indices_;
|
||||
std::vector<bool> is_valid_;
|
||||
};
|
||||
}
|
||||
@@ -58,6 +58,41 @@ namespace MobileGL {
|
||||
SizeT size;
|
||||
};
|
||||
|
||||
enum class DataType {
|
||||
Int8,
|
||||
Uint8,
|
||||
Int16,
|
||||
Uint16,
|
||||
Int32,
|
||||
Uint32,
|
||||
Float16,
|
||||
Float32,
|
||||
Float64,
|
||||
Fixed32
|
||||
};
|
||||
|
||||
struct Range1D {
|
||||
const SizeT maxEnd;
|
||||
const SizeT minStart;
|
||||
SizeT start;
|
||||
SizeT end;
|
||||
|
||||
Range1D(SizeT minStart_, SizeT maxEnd_)
|
||||
: minStart(minStart_), maxEnd(maxEnd_), start(minStart_), end(minStart_) {
|
||||
if (minStart_ >= maxEnd_) {
|
||||
throw RuntimeError("Invalid range: minStart must be less than maxEnd");
|
||||
}
|
||||
}
|
||||
|
||||
void Extend(SizeT newStart, SizeT newEnd) {
|
||||
if (newStart < minStart || newEnd > maxEnd) {
|
||||
throw RuntimeError("Range exceeds bounds");
|
||||
}
|
||||
start = std::min(start, newStart);
|
||||
end = std::max(end, newEnd);
|
||||
}
|
||||
};
|
||||
|
||||
struct Version {
|
||||
Int Major;
|
||||
Int Minor;
|
||||
|
||||
Reference in New Issue
Block a user