aa
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace openceg {
|
||||
|
||||
// 渲染组件:描述 Actor 的几何形状、颜色和纹理占位。
|
||||
class Mesh {
|
||||
public:
|
||||
struct Vertex {
|
||||
std::array<float, 2> position;
|
||||
std::array<float, 4> color;
|
||||
};
|
||||
|
||||
std::vector<Vertex> vertices;
|
||||
std::vector<uint32_t> indices;
|
||||
std::string texture; // 纹理路径占位,暂未采样。
|
||||
|
||||
std::array<float, 4> color() const {
|
||||
std::lock_guard<std::mutex> lock(*color_mutex_);
|
||||
return color_;
|
||||
}
|
||||
|
||||
void set_color(std::array<float, 4> color) {
|
||||
std::lock_guard<std::mutex> lock(*color_mutex_);
|
||||
color_ = color;
|
||||
}
|
||||
|
||||
static Mesh quad() {
|
||||
Mesh mesh;
|
||||
mesh.vertices = {
|
||||
{{-1.0F, -1.0F}, {1.0F, 1.0F, 1.0F, 1.0F}},
|
||||
{{1.0F, -1.0F}, {1.0F, 1.0F, 1.0F, 1.0F}},
|
||||
{{1.0F, 1.0F}, {1.0F, 1.0F, 1.0F, 1.0F}},
|
||||
{{-1.0F, 1.0F}, {1.0F, 1.0F, 1.0F, 1.0F}},
|
||||
};
|
||||
mesh.indices = {0, 1, 2, 2, 3, 0};
|
||||
return mesh;
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<std::mutex> color_mutex_ = std::make_unique<std::mutex>();
|
||||
std::array<float, 4> color_{1.0F, 1.0F, 1.0F, 1.0F};
|
||||
};
|
||||
|
||||
} // namespace openceg
|
||||
Reference in New Issue
Block a user