59 lines
1.3 KiB
C
59 lines
1.3 KiB
C
|
|
#pragma once
|
|||
|
|
|
|||
|
|
#include <scene/node.h>
|
|||
|
|
#include <renderer/instance_buffer.h>
|
|||
|
|
#include <renderer/material.h>
|
|||
|
|
#include <renderer/mesh.h>
|
|||
|
|
#include <renderer/texture.h>
|
|||
|
|
#include <assets/handle.h>
|
|||
|
|
#include <vector>
|
|||
|
|
|
|||
|
|
namespace extra2d {
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 实例化渲染测试节点
|
|||
|
|
*
|
|||
|
|
* 测试实例化渲染功能,渲染大量相同精灵但使用不同变换
|
|||
|
|
*/
|
|||
|
|
class InstancedTestNode : public Node {
|
|||
|
|
public:
|
|||
|
|
InstancedTestNode();
|
|||
|
|
~InstancedTestNode() override;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 初始化实例化渲染资源
|
|||
|
|
* @param instanceCount 实例数量
|
|||
|
|
* @return 初始化是否成功
|
|||
|
|
*/
|
|||
|
|
bool initialize(uint32_t instanceCount = 1000);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 每帧更新实例数据
|
|||
|
|
* @param dt 时间增量
|
|||
|
|
*/
|
|||
|
|
void update(float dt);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 渲染实例(收集渲染命令)
|
|||
|
|
*/
|
|||
|
|
void render() override;
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
InstanceBuffer instanceBuffer_; // 实例缓冲区
|
|||
|
|
std::vector<InstanceData> instanceData_; // CPU端实例数据
|
|||
|
|
uint32_t instanceCount_ = 0; // 实例数量
|
|||
|
|
float time_ = 0.0f; // 时间累积
|
|||
|
|
|
|||
|
|
// 资源句柄
|
|||
|
|
Handle<Material> material_;
|
|||
|
|
Handle<Mesh> mesh_;
|
|||
|
|
Handle<Texture> texture_;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 更新实例变换
|
|||
|
|
*/
|
|||
|
|
void updateInstances();
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
} // namespace extra2d
|