refactor: 重构项目目录结构并更新头文件引用路径
将核心模块从 core 目录迁移到 base 目录,并调整相关头文件引用路径 更新事件系统、渲染器、场景图等模块的文件位置 优化代码组织结构,提升项目可维护性
This commit is contained in:
parent
5fddc4a209
commit
89f69a66eb
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/base/Types.h>
|
||||
#include <extra2d/platform/Window.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/Object.h>
|
||||
#include <extra2d/base/Object.h>
|
||||
#include <string>
|
||||
|
||||
namespace extra2d {
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/assets/Asset.h>
|
||||
#include <extra2d/core/assets/Texture2D.h>
|
||||
#include <extra2d/core/assets/ImageAsset.h>
|
||||
#include <extra2d/assets/Asset.h>
|
||||
#include <extra2d/assets/Texture2D.h>
|
||||
#include <extra2d/assets/ImageAsset.h>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/assets/Asset.h>
|
||||
#include <extra2d/assets/Asset.h>
|
||||
#include <extra2d/gfx/GFXDef.h>
|
||||
#include <vector>
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/assets/Asset.h>
|
||||
#include <extra2d/core/math_types.h>
|
||||
#include <extra2d/assets/Asset.h>
|
||||
#include <extra2d/math/Math.h>
|
||||
#include <extra2d/gfx/GFXDef.h>
|
||||
#include <unordered_map>
|
||||
#include <variant>
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/assets/Asset.h>
|
||||
#include <extra2d/core/assets/ImageAsset.h>
|
||||
#include <extra2d/assets/Asset.h>
|
||||
#include <extra2d/assets/ImageAsset.h>
|
||||
#include <extra2d/gfx/GFXTexture.h>
|
||||
#include <vector>
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/base/Types.h>
|
||||
#include <vector>
|
||||
|
||||
namespace extra2d {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/base/Types.h>
|
||||
#include <atomic>
|
||||
|
||||
namespace extra2d {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/base/Types.h>
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/base/Types.h>
|
||||
#include <extra2d/base/Scheduler.h>
|
||||
#include <chrono>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/core/math_types.h>
|
||||
#include <extra2d/base/Types.h>
|
||||
#include <extra2d/math/Math.h>
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/core/event/EventBus.h>
|
||||
#include <extra2d/base/Types.h>
|
||||
#include <extra2d/event/EventBus.h>
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
|
@ -8,29 +8,29 @@
|
|||
#include <extra2d/base/Scheduler.h>
|
||||
|
||||
// Core
|
||||
#include <extra2d/core/color.h>
|
||||
#include <extra2d/core/math_types.h>
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/core/Object.h>
|
||||
#include <extra2d/math/Color.h>
|
||||
#include <extra2d/math/Math.h>
|
||||
#include <extra2d/base/Types.h>
|
||||
#include <extra2d/base/Object.h>
|
||||
|
||||
// Core - Event
|
||||
#include <extra2d/core/event/EventBus.h>
|
||||
#include <extra2d/core/event/EventTarget.h>
|
||||
#include <extra2d/event/EventBus.h>
|
||||
#include <extra2d/event/EventTarget.h>
|
||||
|
||||
// Core - Scene Graph
|
||||
#include <extra2d/core/scene-graph/Node.h>
|
||||
#include <extra2d/core/scene-graph/Scene.h>
|
||||
#include <extra2d/core/scene-graph/Component.h>
|
||||
#include <extra2d/core/scene-graph/Camera.h>
|
||||
#include <extra2d/core/scene-graph/Model.h>
|
||||
#include <extra2d/core/scene-graph/RenderScene.h>
|
||||
#include <extra2d/scene/Node.h>
|
||||
#include <extra2d/scene/Scene.h>
|
||||
#include <extra2d/scene/Component.h>
|
||||
#include <extra2d/scene/Camera.h>
|
||||
#include <extra2d/scene/Model.h>
|
||||
#include <extra2d/scene/RenderScene.h>
|
||||
|
||||
// Core - Assets
|
||||
#include <extra2d/core/assets/Asset.h>
|
||||
#include <extra2d/core/assets/ImageAsset.h>
|
||||
#include <extra2d/core/assets/Texture2D.h>
|
||||
#include <extra2d/core/assets/AssetManager.h>
|
||||
#include <extra2d/core/assets/Material.h>
|
||||
#include <extra2d/assets/Asset.h>
|
||||
#include <extra2d/assets/ImageAsset.h>
|
||||
#include <extra2d/assets/Texture2D.h>
|
||||
#include <extra2d/assets/AssetManager.h>
|
||||
#include <extra2d/assets/Material.h>
|
||||
|
||||
// Platform
|
||||
#include <extra2d/platform/SDLHelper.h>
|
||||
|
|
@ -52,6 +52,13 @@
|
|||
#include <extra2d/gfx/GFXPipeline.h>
|
||||
#include <extra2d/gfx/GFXInputAssembler.h>
|
||||
#include <extra2d/gfx/GFXDevice.h>
|
||||
#include <extra2d/gfx/GFXCommandBuffer.h>
|
||||
#include <extra2d/gfx/GFXQueue.h>
|
||||
#include <extra2d/gfx/GFXRenderPass.h>
|
||||
#include <extra2d/gfx/GFXFramebuffer.h>
|
||||
#include <extra2d/gfx/GFXSwapchain.h>
|
||||
#include <extra2d/gfx/GFXDescriptorSet.h>
|
||||
#include <extra2d/gfx/GFXSampler.h>
|
||||
|
||||
// GFX - OpenGL Backend
|
||||
#include <extra2d/gfx/opengl/GLDevice.h>
|
||||
|
|
@ -60,17 +67,24 @@
|
|||
#include <extra2d/gfx/opengl/GLShader.h>
|
||||
#include <extra2d/gfx/opengl/GLPipelineState.h>
|
||||
#include <extra2d/gfx/opengl/GLInputAssembler.h>
|
||||
#include <extra2d/gfx/opengl/GLCommandBuffer.h>
|
||||
#include <extra2d/gfx/opengl/GLQueue.h>
|
||||
#include <extra2d/gfx/opengl/GLRenderPass.h>
|
||||
#include <extra2d/gfx/opengl/GLFramebuffer.h>
|
||||
#include <extra2d/gfx/opengl/GLSwapchain.h>
|
||||
#include <extra2d/gfx/opengl/GLDescriptorSet.h>
|
||||
#include <extra2d/gfx/opengl/GLSampler.h>
|
||||
|
||||
// 2D Renderer
|
||||
#include <extra2d/2d/renderer/RenderEntity.h>
|
||||
#include <extra2d/2d/renderer/RenderDrawInfo.h>
|
||||
#include <extra2d/2d/renderer/UIMeshBuffer.h>
|
||||
#include <extra2d/2d/renderer/Batcher2d.h>
|
||||
#include <extra2d/2d/renderer/StencilManager.h>
|
||||
#include <extra2d/renderer/2d/RenderEntity.h>
|
||||
#include <extra2d/renderer/2d/RenderDrawInfo.h>
|
||||
#include <extra2d/renderer/2d/UIMeshBuffer.h>
|
||||
#include <extra2d/renderer/2d/Batcher2d.h>
|
||||
#include <extra2d/renderer/2d/StencilManager.h>
|
||||
|
||||
// 2D Components
|
||||
#include <extra2d/2d/components/SpriteFrame.h>
|
||||
#include <extra2d/2d/components/Sprite.h>
|
||||
#include <extra2d/renderer/2d/components/SpriteFrame.h>
|
||||
#include <extra2d/renderer/2d/components/Sprite.h>
|
||||
|
||||
// Utils
|
||||
#include <extra2d/utils/random.h>
|
||||
|
|
|
|||
|
|
@ -38,18 +38,6 @@ struct Rect {
|
|||
float height{0.0f};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 清除标志位运算
|
||||
*/
|
||||
inline ClearFlagBit operator|(ClearFlagBit a, ClearFlagBit b) {
|
||||
return static_cast<ClearFlagBit>(static_cast<u32>(a) | static_cast<u32>(b));
|
||||
}
|
||||
|
||||
inline ClearFlagBit& operator|=(ClearFlagBit& a, ClearFlagBit b) {
|
||||
a = a | b;
|
||||
return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 命令缓冲区类
|
||||
*
|
||||
|
|
@ -63,6 +51,41 @@ public:
|
|||
*/
|
||||
~CommandBuffer() override;
|
||||
|
||||
// ==================== 生命周期 ====================
|
||||
|
||||
/**
|
||||
* @brief 开始录制命令
|
||||
*/
|
||||
virtual void begin() = 0;
|
||||
|
||||
/**
|
||||
* @brief 结束录制命令
|
||||
*/
|
||||
virtual void end() = 0;
|
||||
|
||||
// ==================== 渲染通道 ====================
|
||||
|
||||
/**
|
||||
* @brief 开始渲染通道
|
||||
* @param renderPass 渲染通道
|
||||
* @param framebuffer 帧缓冲
|
||||
* @param viewport 视口
|
||||
* @param clearFlags 清除标志
|
||||
* @param clearColor 清除颜色
|
||||
* @param clearDepth 清除深度
|
||||
* @param clearStencil 清除模板
|
||||
*/
|
||||
virtual void beginRenderPass(RenderPass* renderPass, Framebuffer* framebuffer,
|
||||
const Viewport& viewport,
|
||||
ClearFlagBit clearFlags,
|
||||
const Color& clearColor,
|
||||
float clearDepth, u32 clearStencil) = 0;
|
||||
|
||||
/**
|
||||
* @brief 结束渲染通道
|
||||
*/
|
||||
virtual void endRenderPass() = 0;
|
||||
|
||||
// ==================== 绑定命令 ====================
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/base/Types.h>
|
||||
#include <cstdint>
|
||||
|
||||
namespace extra2d {
|
||||
|
|
@ -326,6 +326,18 @@ enum class DynamicStateFlag : u32 {
|
|||
StencilReference = 1 << 8,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 清除标志位
|
||||
*/
|
||||
enum class ClearFlagBit : u32 {
|
||||
None = 0,
|
||||
Color = 0x1,
|
||||
Depth = 0x2,
|
||||
Stencil = 0x4,
|
||||
DepthStencil = Depth | Stencil,
|
||||
All = Color | Depth | Stencil,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 过滤模式
|
||||
*/
|
||||
|
|
@ -446,5 +458,20 @@ inline bool hasDynamicState(DynamicStateFlag flags, DynamicStateFlag flag) {
|
|||
return (static_cast<u32>(flags) & static_cast<u32>(flag)) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 清除标志位运算
|
||||
*/
|
||||
inline ClearFlagBit operator|(ClearFlagBit a, ClearFlagBit b) {
|
||||
return static_cast<ClearFlagBit>(static_cast<u32>(a) | static_cast<u32>(b));
|
||||
}
|
||||
|
||||
inline ClearFlagBit operator&(ClearFlagBit a, ClearFlagBit b) {
|
||||
return static_cast<ClearFlagBit>(static_cast<u32>(a) & static_cast<u32>(b));
|
||||
}
|
||||
|
||||
inline bool hasFlag(ClearFlagBit flags, ClearFlagBit flag) {
|
||||
return (static_cast<u32>(flags) & static_cast<u32>(flag)) != 0;
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace extra2d
|
||||
|
|
|
|||
|
|
@ -0,0 +1,184 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/gfx/GFXObject.h>
|
||||
#include <extra2d/gfx/GFXDef.h>
|
||||
#include <vector>
|
||||
|
||||
namespace extra2d {
|
||||
namespace gfx {
|
||||
|
||||
class Buffer;
|
||||
class Texture;
|
||||
class Sampler;
|
||||
class DescriptorSetLayout;
|
||||
|
||||
/**
|
||||
* @brief 描述符类型
|
||||
*/
|
||||
enum class DescriptorType : u32 {
|
||||
Unknown,
|
||||
UniformBuffer,
|
||||
DynamicUniformBuffer,
|
||||
StorageBuffer,
|
||||
DynamicStorageBuffer,
|
||||
Sampler,
|
||||
Texture,
|
||||
SamplerTexture,
|
||||
StorageImage,
|
||||
InputAttachment,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 描述符集布局绑定
|
||||
*/
|
||||
struct DescriptorSetLayoutBinding {
|
||||
u32 binding{0xFFFFFFFF};
|
||||
DescriptorType descriptorType{DescriptorType::Unknown};
|
||||
u32 count{0};
|
||||
ShaderStage stageFlags{ShaderStage::None};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 描述符集布局信息
|
||||
*/
|
||||
struct DescriptorSetLayoutInfo {
|
||||
std::vector<DescriptorSetLayoutBinding> bindings;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 描述符集信息
|
||||
*/
|
||||
struct DescriptorSetInfo {
|
||||
const DescriptorSetLayout* layout{nullptr};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 描述符集布局抽象类
|
||||
*/
|
||||
class DescriptorSetLayout : public Object {
|
||||
public:
|
||||
/**
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~DescriptorSetLayout() override;
|
||||
|
||||
/**
|
||||
* @brief 获取类型名称
|
||||
* @return 类型名称
|
||||
*/
|
||||
const char* getTypeName() const override { return "DescriptorSetLayout"; }
|
||||
|
||||
/**
|
||||
* @brief 初始化布局
|
||||
* @param info 布局信息
|
||||
*/
|
||||
void initialize(const DescriptorSetLayoutInfo& info);
|
||||
|
||||
/**
|
||||
* @brief 销毁布局
|
||||
*/
|
||||
void destroy();
|
||||
|
||||
/**
|
||||
* @brief 获取绑定数量
|
||||
* @return 绑定数量
|
||||
*/
|
||||
u32 getBindingCount() const { return static_cast<u32>(bindings_.size()); }
|
||||
|
||||
/**
|
||||
* @brief 获取绑定
|
||||
* @param index 索引
|
||||
* @return 绑定
|
||||
*/
|
||||
const DescriptorSetLayoutBinding& getBinding(u32 index) const { return bindings_[index]; }
|
||||
|
||||
protected:
|
||||
DescriptorSetLayout() = default;
|
||||
|
||||
virtual void doInit(const DescriptorSetLayoutInfo& info) = 0;
|
||||
virtual void doDestroy() = 0;
|
||||
|
||||
std::vector<DescriptorSetLayoutBinding> bindings_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 描述符集抽象类
|
||||
*
|
||||
* 管理着色器资源的绑定。
|
||||
* 参考 Cocos Creator 的 DescriptorSet 设计。
|
||||
*/
|
||||
class DescriptorSet : public Object {
|
||||
public:
|
||||
/**
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~DescriptorSet() override;
|
||||
|
||||
/**
|
||||
* @brief 获取类型名称
|
||||
* @return 类型名称
|
||||
*/
|
||||
const char* getTypeName() const override { return "DescriptorSet"; }
|
||||
|
||||
/**
|
||||
* @brief 初始化描述符集
|
||||
* @param info 描述符集信息
|
||||
*/
|
||||
void initialize(const DescriptorSetInfo& info);
|
||||
|
||||
/**
|
||||
* @brief 销毁描述符集
|
||||
*/
|
||||
void destroy();
|
||||
|
||||
/**
|
||||
* @brief 绑定缓冲区
|
||||
* @param binding 绑定点
|
||||
* @param buffer 缓冲区
|
||||
*/
|
||||
virtual void bindBuffer(u32 binding, Buffer* buffer) = 0;
|
||||
|
||||
/**
|
||||
* @brief 绑定纹理
|
||||
* @param binding 绑定点
|
||||
* @param texture 纹理
|
||||
*/
|
||||
virtual void bindTexture(u32 binding, Texture* texture) = 0;
|
||||
|
||||
/**
|
||||
* @brief 绑定采样器
|
||||
* @param binding 绑定点
|
||||
* @param sampler 采样器
|
||||
*/
|
||||
virtual void bindSampler(u32 binding, Sampler* sampler) = 0;
|
||||
|
||||
/**
|
||||
* @brief 绑定采样器纹理
|
||||
* @param binding 绑定点
|
||||
* @param texture 纹理
|
||||
* @param sampler 采样器
|
||||
*/
|
||||
virtual void bindSamplerTexture(u32 binding, Texture* texture, Sampler* sampler) = 0;
|
||||
|
||||
/**
|
||||
* @brief 更新描述符
|
||||
*/
|
||||
virtual void update() = 0;
|
||||
|
||||
/**
|
||||
* @brief 获取布局
|
||||
* @return 布局
|
||||
*/
|
||||
DescriptorSetLayout* getLayout() const { return layout_; }
|
||||
|
||||
protected:
|
||||
DescriptorSet() = default;
|
||||
|
||||
virtual void doInit(const DescriptorSetInfo& info) = 0;
|
||||
virtual void doDestroy() = 0;
|
||||
|
||||
DescriptorSetLayout* layout_{nullptr};
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace extra2d
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/gfx/GFXObject.h>
|
||||
#include <extra2d/gfx/GFXDef.h>
|
||||
#include <vector>
|
||||
|
||||
namespace extra2d {
|
||||
namespace gfx {
|
||||
|
||||
class RenderPass;
|
||||
class Texture;
|
||||
|
||||
/**
|
||||
* @brief 帧缓冲信息
|
||||
*/
|
||||
struct FramebufferInfo {
|
||||
RenderPass* renderPass{nullptr};
|
||||
std::vector<Texture*> colorTextures;
|
||||
Texture* depthStencilTexture{nullptr};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 帧缓冲抽象类
|
||||
*
|
||||
* 管理渲染目标的集合。
|
||||
* 参考 Cocos Creator 的 Framebuffer 设计。
|
||||
*/
|
||||
class Framebuffer : public Object {
|
||||
public:
|
||||
/**
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~Framebuffer() override;
|
||||
|
||||
/**
|
||||
* @brief 获取类型名称
|
||||
* @return 类型名称
|
||||
*/
|
||||
const char* getTypeName() const override { return "Framebuffer"; }
|
||||
|
||||
/**
|
||||
* @brief 初始化帧缓冲
|
||||
* @param info 帧缓冲信息
|
||||
*/
|
||||
void initialize(const FramebufferInfo& info);
|
||||
|
||||
/**
|
||||
* @brief 销毁帧缓冲
|
||||
*/
|
||||
void destroy();
|
||||
|
||||
/**
|
||||
* @brief 获取渲染通道
|
||||
* @return 渲染通道
|
||||
*/
|
||||
RenderPass* getRenderPass() const { return renderPass_; }
|
||||
|
||||
/**
|
||||
* @brief 获取颜色纹理数量
|
||||
* @return 颜色纹理数量
|
||||
*/
|
||||
u32 getColorTextureCount() const { return static_cast<u32>(colorTextures_.size()); }
|
||||
|
||||
/**
|
||||
* @brief 获取颜色纹理
|
||||
* @param index 索引
|
||||
* @return 颜色纹理
|
||||
*/
|
||||
Texture* getColorTexture(u32 index) const { return colorTextures_[index]; }
|
||||
|
||||
/**
|
||||
* @brief 获取深度模板纹理
|
||||
* @return 深度模板纹理
|
||||
*/
|
||||
Texture* getDepthStencilTexture() const { return depthStencilTexture_; }
|
||||
|
||||
/**
|
||||
* @brief 获取宽度
|
||||
* @return 宽度
|
||||
*/
|
||||
u32 getWidth() const { return width_; }
|
||||
|
||||
/**
|
||||
* @brief 获取高度
|
||||
* @return 高度
|
||||
*/
|
||||
u32 getHeight() const { return height_; }
|
||||
|
||||
protected:
|
||||
Framebuffer() = default;
|
||||
|
||||
/**
|
||||
* @brief 实际初始化实现
|
||||
* @param info 帧缓冲信息
|
||||
*/
|
||||
virtual void doInit(const FramebufferInfo& info) = 0;
|
||||
|
||||
/**
|
||||
* @brief 实际销毁实现
|
||||
*/
|
||||
virtual void doDestroy() = 0;
|
||||
|
||||
RenderPass* renderPass_{nullptr};
|
||||
std::vector<Texture*> colorTextures_;
|
||||
Texture* depthStencilTexture_{nullptr};
|
||||
u32 width_{0};
|
||||
u32 height_{0};
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace extra2d
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/gfx/GFXObject.h>
|
||||
#include <extra2d/gfx/GFXDef.h>
|
||||
#include <vector>
|
||||
|
||||
namespace extra2d {
|
||||
namespace gfx {
|
||||
|
||||
class CommandBuffer;
|
||||
|
||||
/**
|
||||
* @brief 命令队列类型
|
||||
*/
|
||||
enum class QueueType : u32 {
|
||||
Graphics,
|
||||
Compute,
|
||||
Transfer,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 命令队列信息
|
||||
*/
|
||||
struct QueueInfo {
|
||||
QueueType type{QueueType::Graphics};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 命令队列抽象类
|
||||
*
|
||||
* 用于提交命令缓冲区执行。
|
||||
* 参考 Cocos Creator 的 Queue 设计。
|
||||
*/
|
||||
class Queue : public Object {
|
||||
public:
|
||||
/**
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~Queue() override;
|
||||
|
||||
/**
|
||||
* @brief 获取类型名称
|
||||
* @return 类型名称
|
||||
*/
|
||||
const char* getTypeName() const override { return "Queue"; }
|
||||
|
||||
/**
|
||||
* @brief 初始化队列
|
||||
* @param info 队列信息
|
||||
*/
|
||||
void initialize(const QueueInfo& info);
|
||||
|
||||
/**
|
||||
* @brief 销毁队列
|
||||
*/
|
||||
void destroy();
|
||||
|
||||
/**
|
||||
* @brief 提交命令缓冲区
|
||||
* @param cmdBuffers 命令缓冲区数组
|
||||
* @param count 命令缓冲区数量
|
||||
*/
|
||||
virtual void submit(CommandBuffer* const* cmdBuffers, u32 count) = 0;
|
||||
|
||||
/**
|
||||
* @brief 提交命令缓冲区(便捷方法)
|
||||
* @param cmdBuffers 命令缓冲区列表
|
||||
*/
|
||||
void submit(const std::vector<CommandBuffer*>& cmdBuffers) {
|
||||
submit(cmdBuffers.data(), static_cast<u32>(cmdBuffers.size()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 获取队列类型
|
||||
* @return 队列类型
|
||||
*/
|
||||
QueueType getType() const { return type_; }
|
||||
|
||||
protected:
|
||||
Queue() = default;
|
||||
|
||||
/**
|
||||
* @brief 实际初始化实现
|
||||
* @param info 队列信息
|
||||
*/
|
||||
virtual void doInit(const QueueInfo& info) = 0;
|
||||
|
||||
/**
|
||||
* @brief 实际销毁实现
|
||||
*/
|
||||
virtual void doDestroy() = 0;
|
||||
|
||||
QueueType type_{QueueType::Graphics};
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace extra2d
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/gfx/GFXObject.h>
|
||||
#include <extra2d/gfx/GFXDef.h>
|
||||
#include <vector>
|
||||
|
||||
namespace extra2d {
|
||||
namespace gfx {
|
||||
|
||||
/**
|
||||
* @brief 加载操作
|
||||
*/
|
||||
enum class LoadOp : u32 {
|
||||
Clear,
|
||||
Load,
|
||||
DontCare,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 存储操作
|
||||
*/
|
||||
enum class StoreOp : u32 {
|
||||
Store,
|
||||
DontCare,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 颜色附件描述
|
||||
*/
|
||||
struct ColorAttachment {
|
||||
Format format{Format::Unknown};
|
||||
SampleCount sampleCount{SampleCount::X1};
|
||||
LoadOp loadOp{LoadOp::Clear};
|
||||
StoreOp storeOp{StoreOp::Store};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 深度模板附件描述
|
||||
*/
|
||||
struct DepthStencilAttachment {
|
||||
Format format{Format::Unknown};
|
||||
SampleCount sampleCount{SampleCount::X1};
|
||||
LoadOp depthLoadOp{LoadOp::Clear};
|
||||
StoreOp depthStoreOp{StoreOp::Store};
|
||||
LoadOp stencilLoadOp{LoadOp::Clear};
|
||||
StoreOp stencilStoreOp{StoreOp::Store};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 子通道信息
|
||||
*/
|
||||
struct SubpassInfo {
|
||||
std::vector<u32> inputs;
|
||||
std::vector<u32> colors;
|
||||
std::vector<u32> resolves;
|
||||
std::vector<u32> preserves;
|
||||
u32 depthStencil{0xFFFFFFFF};
|
||||
u32 depthStencilResolve{0xFFFFFFFF};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 子通道依赖
|
||||
*/
|
||||
struct SubpassDependency {
|
||||
u32 srcSubpass{0};
|
||||
u32 dstSubpass{0};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 渲染通道信息
|
||||
*/
|
||||
struct RenderPassInfo {
|
||||
std::vector<ColorAttachment> colorAttachments;
|
||||
DepthStencilAttachment depthStencilAttachment;
|
||||
std::vector<SubpassInfo> subpasses;
|
||||
std::vector<SubpassDependency> dependencies;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 渲染通道抽象类
|
||||
*
|
||||
* 定义渲染通道的附件格式和操作。
|
||||
* 参考 Cocos Creator 的 RenderPass 设计。
|
||||
*/
|
||||
class RenderPass : public Object {
|
||||
public:
|
||||
/**
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~RenderPass() override;
|
||||
|
||||
/**
|
||||
* @brief 获取类型名称
|
||||
* @return 类型名称
|
||||
*/
|
||||
const char* getTypeName() const override { return "RenderPass"; }
|
||||
|
||||
/**
|
||||
* @brief 初始化渲染通道
|
||||
* @param info 渲染通道信息
|
||||
*/
|
||||
void initialize(const RenderPassInfo& info);
|
||||
|
||||
/**
|
||||
* @brief 销毁渲染通道
|
||||
*/
|
||||
void destroy();
|
||||
|
||||
/**
|
||||
* @brief 获取颜色附件数量
|
||||
* @return 颜色附件数量
|
||||
*/
|
||||
u32 getColorAttachmentCount() const { return static_cast<u32>(colorAttachments_.size()); }
|
||||
|
||||
/**
|
||||
* @brief 获取颜色附件
|
||||
* @param index 索引
|
||||
* @return 颜色附件
|
||||
*/
|
||||
const ColorAttachment& getColorAttachment(u32 index) const { return colorAttachments_[index]; }
|
||||
|
||||
/**
|
||||
* @brief 获取深度模板附件
|
||||
* @return 深度模板附件
|
||||
*/
|
||||
const DepthStencilAttachment& getDepthStencilAttachment() const { return depthStencilAttachment_; }
|
||||
|
||||
/**
|
||||
* @brief 是否有深度附件
|
||||
* @return 是否有深度附件
|
||||
*/
|
||||
bool hasDepth() const { return depthStencilAttachment_.format != Format::Unknown; }
|
||||
|
||||
/**
|
||||
* @brief 是否有模板附件
|
||||
* @return 是否有模板附件
|
||||
*/
|
||||
bool hasStencil() const;
|
||||
|
||||
protected:
|
||||
RenderPass() = default;
|
||||
|
||||
/**
|
||||
* @brief 实际初始化实现
|
||||
* @param info 渲染通道信息
|
||||
*/
|
||||
virtual void doInit(const RenderPassInfo& info) = 0;
|
||||
|
||||
/**
|
||||
* @brief 实际销毁实现
|
||||
*/
|
||||
virtual void doDestroy() = 0;
|
||||
|
||||
std::vector<ColorAttachment> colorAttachments_;
|
||||
DepthStencilAttachment depthStencilAttachment_;
|
||||
std::vector<SubpassInfo> subpasses_;
|
||||
std::vector<SubpassDependency> dependencies_;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace extra2d
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/gfx/GFXObject.h>
|
||||
#include <extra2d/gfx/GFXDef.h>
|
||||
|
||||
namespace extra2d {
|
||||
namespace gfx {
|
||||
|
||||
/**
|
||||
* @brief 采样器信息
|
||||
*/
|
||||
struct SamplerInfo {
|
||||
Filter minFilter{Filter::Linear};
|
||||
Filter magFilter{Filter::Linear};
|
||||
Filter mipFilter{Filter::None};
|
||||
Address addressU{Address::Clamp};
|
||||
Address addressV{Address::Clamp};
|
||||
Address addressW{Address::Clamp};
|
||||
float maxAnisotropy{16.0f};
|
||||
ComparisonFunc comparisonFunc{ComparisonFunc::Never};
|
||||
float minLOD{0.0f};
|
||||
float maxLOD{1000.0f};
|
||||
float mipLODBias{0.0f};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 采样器抽象类
|
||||
*
|
||||
* 定义纹理采样参数。
|
||||
* 参考 Cocos Creator 的 Sampler 设计。
|
||||
*/
|
||||
class Sampler : public Object {
|
||||
public:
|
||||
/**
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~Sampler() override;
|
||||
|
||||
/**
|
||||
* @brief 获取类型名称
|
||||
* @return 类型名称
|
||||
*/
|
||||
const char* getTypeName() const override { return "Sampler"; }
|
||||
|
||||
/**
|
||||
* @brief 初始化采样器
|
||||
* @param info 采样器信息
|
||||
*/
|
||||
void initialize(const SamplerInfo& info);
|
||||
|
||||
/**
|
||||
* @brief 销毁采样器
|
||||
*/
|
||||
void destroy();
|
||||
|
||||
/**
|
||||
* @brief 获取缩小过滤
|
||||
* @return 缩小过滤
|
||||
*/
|
||||
Filter getMinFilter() const { return minFilter_; }
|
||||
|
||||
/**
|
||||
* @brief 获取放大过滤
|
||||
* @return 放大过滤
|
||||
*/
|
||||
Filter getMagFilter() const { return magFilter_; }
|
||||
|
||||
/**
|
||||
* @brief 获取 MIP 过滤
|
||||
* @return MIP 过滤
|
||||
*/
|
||||
Filter getMipFilter() const { return mipFilter_; }
|
||||
|
||||
/**
|
||||
* @brief 获取 U 方向寻址模式
|
||||
* @return U 方向寻址模式
|
||||
*/
|
||||
Address getAddressU() const { return addressU_; }
|
||||
|
||||
/**
|
||||
* @brief 获取 V 方向寻址模式
|
||||
* @return V 方向寻址模式
|
||||
*/
|
||||
Address getAddressV() const { return addressV_; }
|
||||
|
||||
/**
|
||||
* @brief 获取 W 方向寻址模式
|
||||
* @return W 方向寻址模式
|
||||
*/
|
||||
Address getAddressW() const { return addressW_; }
|
||||
|
||||
/**
|
||||
* @brief 获取最大各向异性
|
||||
* @return 最大各向异性
|
||||
*/
|
||||
float getMaxAnisotropy() const { return maxAnisotropy_; }
|
||||
|
||||
protected:
|
||||
Sampler() = default;
|
||||
|
||||
virtual void doInit(const SamplerInfo& info) = 0;
|
||||
virtual void doDestroy() = 0;
|
||||
|
||||
Filter minFilter_{Filter::Linear};
|
||||
Filter magFilter_{Filter::Linear};
|
||||
Filter mipFilter_{Filter::None};
|
||||
Address addressU_{Address::Clamp};
|
||||
Address addressV_{Address::Clamp};
|
||||
Address addressW_{Address::Clamp};
|
||||
float maxAnisotropy_{16.0f};
|
||||
ComparisonFunc comparisonFunc_{ComparisonFunc::Never};
|
||||
float minLOD_{0.0f};
|
||||
float maxLOD_{1000.0f};
|
||||
float mipLODBias_{0.0f};
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace extra2d
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/gfx/GFXObject.h>
|
||||
#include <extra2d/gfx/GFXDef.h>
|
||||
#include <vector>
|
||||
|
||||
namespace extra2d {
|
||||
namespace gfx {
|
||||
|
||||
class Texture;
|
||||
|
||||
/**
|
||||
* @brief 交换链信息
|
||||
*/
|
||||
struct SwapchainInfo {
|
||||
u32 width{0};
|
||||
u32 height{0};
|
||||
Format format{Format::RGBA8};
|
||||
u32 imageCount{2};
|
||||
bool vsync{true};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 交换链纹理信息
|
||||
*/
|
||||
struct SwapchainTextureInfo {
|
||||
Texture* texture{nullptr};
|
||||
Format format{Format::Unknown};
|
||||
u32 width{0};
|
||||
u32 height{0};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 交换链抽象类
|
||||
*
|
||||
* 管理显示用的交换链。
|
||||
* 参考 Cocos Creator 的 Swapchain 设计。
|
||||
*/
|
||||
class Swapchain : public Object {
|
||||
public:
|
||||
/**
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~Swapchain() override;
|
||||
|
||||
/**
|
||||
* @brief 获取类型名称
|
||||
* @return 类型名称
|
||||
*/
|
||||
const char* getTypeName() const override { return "Swapchain"; }
|
||||
|
||||
/**
|
||||
* @brief 初始化交换链
|
||||
* @param info 交换链信息
|
||||
*/
|
||||
void initialize(const SwapchainInfo& info);
|
||||
|
||||
/**
|
||||
* @brief 销毁交换链
|
||||
*/
|
||||
void destroy();
|
||||
|
||||
/**
|
||||
* @brief 调整大小
|
||||
* @param width 宽度
|
||||
* @param height 高度
|
||||
*/
|
||||
void resize(u32 width, u32 height);
|
||||
|
||||
/**
|
||||
* @brief 获取宽度
|
||||
* @return 宽度
|
||||
*/
|
||||
u32 getWidth() const { return width_; }
|
||||
|
||||
/**
|
||||
* @brief 获取高度
|
||||
* @return 高度
|
||||
*/
|
||||
u32 getHeight() const { return height_; }
|
||||
|
||||
/**
|
||||
* @brief 获取颜色格式
|
||||
* @return 颜色格式
|
||||
*/
|
||||
Format getFormat() const { return format_; }
|
||||
|
||||
/**
|
||||
* @brief 获取当前纹理
|
||||
* @return 当前纹理
|
||||
*/
|
||||
virtual Texture* getColorTexture() = 0;
|
||||
|
||||
/**
|
||||
* @brief 获取深度模板纹理
|
||||
* @return 深度模板纹理
|
||||
*/
|
||||
virtual Texture* getDepthStencilTexture() = 0;
|
||||
|
||||
/**
|
||||
* @brief 呈现
|
||||
*/
|
||||
virtual void present() = 0;
|
||||
|
||||
protected:
|
||||
Swapchain() = default;
|
||||
|
||||
/**
|
||||
* @brief 实际初始化实现
|
||||
* @param info 交换链信息
|
||||
*/
|
||||
virtual void doInit(const SwapchainInfo& info) = 0;
|
||||
|
||||
/**
|
||||
* @brief 实际销毁实现
|
||||
*/
|
||||
virtual void doDestroy() = 0;
|
||||
|
||||
/**
|
||||
* @brief 实际调整大小实现
|
||||
* @param width 宽度
|
||||
* @param height 高度
|
||||
*/
|
||||
virtual void doResize(u32 width, u32 height) = 0;
|
||||
|
||||
u32 width_{0};
|
||||
u32 height_{0};
|
||||
Format format_{Format::RGBA8};
|
||||
u32 imageCount_{2};
|
||||
bool vsync_{true};
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace extra2d
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/gfx/GFXDescriptorSet.h>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace extra2d {
|
||||
namespace gfx {
|
||||
|
||||
class GLBuffer;
|
||||
class GLTexture;
|
||||
|
||||
/**
|
||||
* @brief OpenGL 描述符集布局实现
|
||||
*/
|
||||
class GLDescriptorSetLayout : public DescriptorSetLayout {
|
||||
public:
|
||||
/**
|
||||
* @brief 构造函数
|
||||
*/
|
||||
GLDescriptorSetLayout();
|
||||
|
||||
/**
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~GLDescriptorSetLayout() override;
|
||||
|
||||
/**
|
||||
* @brief 获取类型名称
|
||||
* @return 类型名称
|
||||
*/
|
||||
const char* getTypeName() const override { return "GLDescriptorSetLayout"; }
|
||||
|
||||
protected:
|
||||
void doInit(const DescriptorSetLayoutInfo& info) override;
|
||||
void doDestroy() override;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 描述符绑定信息
|
||||
*/
|
||||
struct DescriptorBinding {
|
||||
DescriptorType type{DescriptorType::Unknown};
|
||||
GLBuffer* buffer{nullptr};
|
||||
GLTexture* texture{nullptr};
|
||||
u32 samplerHandle{0};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief OpenGL 描述符集实现
|
||||
*/
|
||||
class GLDescriptorSet : public DescriptorSet {
|
||||
public:
|
||||
/**
|
||||
* @brief 构造函数
|
||||
*/
|
||||
GLDescriptorSet();
|
||||
|
||||
/**
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~GLDescriptorSet() override;
|
||||
|
||||
/**
|
||||
* @brief 获取类型名称
|
||||
* @return 类型名称
|
||||
*/
|
||||
const char* getTypeName() const override { return "GLDescriptorSet"; }
|
||||
|
||||
/**
|
||||
* @brief 绑定缓冲区
|
||||
* @param binding 绑定点
|
||||
* @param buffer 缓冲区
|
||||
*/
|
||||
void bindBuffer(u32 binding, Buffer* buffer) override;
|
||||
|
||||
/**
|
||||
* @brief 绑定纹理
|
||||
* @param binding 绑定点
|
||||
* @param texture 纹理
|
||||
*/
|
||||
void bindTexture(u32 binding, Texture* texture) override;
|
||||
|
||||
/**
|
||||
* @brief 绑定采样器
|
||||
* @param binding 绑定点
|
||||
* @param sampler 采样器
|
||||
*/
|
||||
void bindSampler(u32 binding, Sampler* sampler) override;
|
||||
|
||||
/**
|
||||
* @brief 绑定采样器纹理
|
||||
* @param binding 绑定点
|
||||
* @param texture 纹理
|
||||
* @param sampler 采样器
|
||||
*/
|
||||
void bindSamplerTexture(u32 binding, Texture* texture, Sampler* sampler) override;
|
||||
|
||||
/**
|
||||
* @brief 更新描述符
|
||||
*/
|
||||
void update() override;
|
||||
|
||||
/**
|
||||
* @brief 绑定到 OpenGL 状态
|
||||
* @param program 着色器程序
|
||||
*/
|
||||
void bindGL(u32 program);
|
||||
|
||||
protected:
|
||||
void doInit(const DescriptorSetInfo& info) override;
|
||||
void doDestroy() override;
|
||||
|
||||
private:
|
||||
std::unordered_map<u32, DescriptorBinding> bindings_;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace extra2d
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/gfx/GFXFramebuffer.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <glad/glad.h>
|
||||
#else
|
||||
#include <GLES3/gl3.h>
|
||||
#endif
|
||||
|
||||
namespace extra2d {
|
||||
namespace gfx {
|
||||
|
||||
/**
|
||||
* @brief OpenGL 帧缓冲实现
|
||||
*/
|
||||
class GLFramebuffer : public Framebuffer {
|
||||
public:
|
||||
/**
|
||||
* @brief 构造函数
|
||||
*/
|
||||
GLFramebuffer();
|
||||
|
||||
/**
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~GLFramebuffer() override;
|
||||
|
||||
/**
|
||||
* @brief 获取类型名称
|
||||
* @return 类型名称
|
||||
*/
|
||||
const char* getTypeName() const override { return "GLFramebuffer"; }
|
||||
|
||||
/**
|
||||
* @brief 获取 OpenGL 帧缓冲句柄
|
||||
* @return 帧缓冲句柄
|
||||
*/
|
||||
GLuint getHandle() const { return framebuffer_; }
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief 实际初始化实现
|
||||
* @param info 帧缓冲信息
|
||||
*/
|
||||
void doInit(const FramebufferInfo& info) override;
|
||||
|
||||
/**
|
||||
* @brief 实际销毁实现
|
||||
*/
|
||||
void doDestroy() override;
|
||||
|
||||
private:
|
||||
GLuint framebuffer_{0};
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace extra2d
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/gfx/GFXQueue.h>
|
||||
|
||||
namespace extra2d {
|
||||
namespace gfx {
|
||||
|
||||
/**
|
||||
* @brief OpenGL 命令队列实现
|
||||
*
|
||||
* OpenGL 没有显式的队列概念,此实现主要用于统计和同步。
|
||||
*/
|
||||
class GLQueue : public Queue {
|
||||
public:
|
||||
/**
|
||||
* @brief 构造函数
|
||||
*/
|
||||
GLQueue();
|
||||
|
||||
/**
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~GLQueue() override;
|
||||
|
||||
/**
|
||||
* @brief 获取类型名称
|
||||
* @return 类型名称
|
||||
*/
|
||||
const char* getTypeName() const override { return "GLQueue"; }
|
||||
|
||||
/**
|
||||
* @brief 提交命令缓冲区
|
||||
* @param cmdBuffers 命令缓冲区数组
|
||||
* @param count 命令缓冲区数量
|
||||
*/
|
||||
void submit(CommandBuffer* const* cmdBuffers, u32 count) override;
|
||||
|
||||
/**
|
||||
* @brief 获取绘制调用次数
|
||||
* @return 绘制调用次数
|
||||
*/
|
||||
u32 getNumDrawCalls() const { return numDrawCalls_; }
|
||||
|
||||
/**
|
||||
* @brief 获取实例数量
|
||||
* @return 实例数量
|
||||
*/
|
||||
u32 getNumInstances() const { return numInstances_; }
|
||||
|
||||
/**
|
||||
* @brief 获取三角形数量
|
||||
* @return 三角形数量
|
||||
*/
|
||||
u32 getNumTriangles() const { return numTriangles_; }
|
||||
|
||||
/**
|
||||
* @brief 重置统计信息
|
||||
*/
|
||||
void resetStats();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief 实际初始化实现
|
||||
* @param info 队列信息
|
||||
*/
|
||||
void doInit(const QueueInfo& info) override;
|
||||
|
||||
/**
|
||||
* @brief 实际销毁实现
|
||||
*/
|
||||
void doDestroy() override;
|
||||
|
||||
private:
|
||||
u32 numDrawCalls_{0};
|
||||
u32 numInstances_{0};
|
||||
u32 numTriangles_{0};
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace extra2d
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/gfx/GFXRenderPass.h>
|
||||
|
||||
namespace extra2d {
|
||||
namespace gfx {
|
||||
|
||||
/**
|
||||
* @brief OpenGL 渲染通道实现
|
||||
*
|
||||
* OpenGL 没有显式的 RenderPass 概念,此实现主要用于存储附件信息。
|
||||
*/
|
||||
class GLRenderPass : public RenderPass {
|
||||
public:
|
||||
/**
|
||||
* @brief 构造函数
|
||||
*/
|
||||
GLRenderPass();
|
||||
|
||||
/**
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~GLRenderPass() override;
|
||||
|
||||
/**
|
||||
* @brief 获取类型名称
|
||||
* @return 类型名称
|
||||
*/
|
||||
const char* getTypeName() const override { return "GLRenderPass"; }
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief 实际初始化实现
|
||||
* @param info 渲染通道信息
|
||||
*/
|
||||
void doInit(const RenderPassInfo& info) override;
|
||||
|
||||
/**
|
||||
* @brief 实际销毁实现
|
||||
*/
|
||||
void doDestroy() override;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace extra2d
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/gfx/GFXSampler.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <glad/glad.h>
|
||||
#else
|
||||
#include <GLES3/gl3.h>
|
||||
#endif
|
||||
|
||||
namespace extra2d {
|
||||
namespace gfx {
|
||||
|
||||
/**
|
||||
* @brief OpenGL 采样器实现
|
||||
*/
|
||||
class GLSampler : public Sampler {
|
||||
public:
|
||||
/**
|
||||
* @brief 构造函数
|
||||
*/
|
||||
GLSampler();
|
||||
|
||||
/**
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~GLSampler() override;
|
||||
|
||||
/**
|
||||
* @brief 获取类型名称
|
||||
* @return 类型名称
|
||||
*/
|
||||
const char* getTypeName() const override { return "GLSampler"; }
|
||||
|
||||
/**
|
||||
* @brief 获取 OpenGL 采样器句柄
|
||||
* @return 采样器句柄
|
||||
*/
|
||||
GLuint getHandle() const { return sampler_; }
|
||||
|
||||
/**
|
||||
* @brief 绑定到纹理单元
|
||||
* @param unit 纹理单元
|
||||
*/
|
||||
void bind(u32 unit);
|
||||
|
||||
protected:
|
||||
void doInit(const SamplerInfo& info) override;
|
||||
void doDestroy() override;
|
||||
|
||||
private:
|
||||
GLuint sampler_{0};
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace extra2d
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/gfx/GFXSwapchain.h>
|
||||
#include <extra2d/gfx/opengl/GLTexture.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <glad/glad.h>
|
||||
#else
|
||||
#include <GLES3/gl3.h>
|
||||
#endif
|
||||
|
||||
namespace extra2d {
|
||||
namespace gfx {
|
||||
|
||||
/**
|
||||
* @brief OpenGL 交换链实现
|
||||
*
|
||||
* OpenGL 没有显式的交换链概念,由窗口系统管理。
|
||||
* 此实现提供默认帧缓冲的颜色和深度模板纹理。
|
||||
*/
|
||||
class GLSwapchain : public Swapchain {
|
||||
public:
|
||||
/**
|
||||
* @brief 构造函数
|
||||
*/
|
||||
GLSwapchain();
|
||||
|
||||
/**
|
||||
* @brief 析构函数
|
||||
*/
|
||||
~GLSwapchain() override;
|
||||
|
||||
/**
|
||||
* @brief 获取类型名称
|
||||
* @return 类型名称
|
||||
*/
|
||||
const char* getTypeName() const override { return "GLSwapchain"; }
|
||||
|
||||
/**
|
||||
* @brief 获取当前颜色纹理
|
||||
* @return 颜色纹理(返回 nullptr 表示默认帧缓冲)
|
||||
*/
|
||||
Texture* getColorTexture() override;
|
||||
|
||||
/**
|
||||
* @brief 获取深度模板纹理
|
||||
* @return 深度模板纹理
|
||||
*/
|
||||
Texture* getDepthStencilTexture() override;
|
||||
|
||||
/**
|
||||
* @brief 呈现
|
||||
*/
|
||||
void present() override;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief 实际初始化实现
|
||||
* @param info 交换链信息
|
||||
*/
|
||||
void doInit(const SwapchainInfo& info) override;
|
||||
|
||||
/**
|
||||
* @brief 实际销毁实现
|
||||
*/
|
||||
void doDestroy() override;
|
||||
|
||||
/**
|
||||
* @brief 实际调整大小实现
|
||||
* @param width 宽度
|
||||
* @param height 高度
|
||||
*/
|
||||
void doResize(u32 width, u32 height) override;
|
||||
|
||||
private:
|
||||
IntrusivePtr<GLTexture> colorTexture_;
|
||||
IntrusivePtr<GLTexture> depthStencilTexture_;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace extra2d
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/base/Types.h>
|
||||
#include <glm/vec4.hpp>
|
||||
|
||||
namespace extra2d {
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/base/Types.h>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include <glm/vec2.hpp>
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/core/math_types.h>
|
||||
#include <extra2d/base/Types.h>
|
||||
#include <extra2d/math/Math.h>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/core/math_types.h>
|
||||
#include <extra2d/core/event/EventBus.h>
|
||||
#include <extra2d/base/Types.h>
|
||||
#include <extra2d/math/Math.h>
|
||||
#include <extra2d/event/EventBus.h>
|
||||
|
||||
struct SDL_Window;
|
||||
struct SDL_Event;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/core/math_types.h>
|
||||
#include <extra2d/base/Types.h>
|
||||
#include <extra2d/math/Math.h>
|
||||
#include <string>
|
||||
|
||||
struct SDL_Window;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/core/math_types.h>
|
||||
#include <extra2d/2d/renderer/RenderEntity.h>
|
||||
#include <extra2d/2d/renderer/RenderDrawInfo.h>
|
||||
#include <extra2d/2d/renderer/UIMeshBuffer.h>
|
||||
#include <extra2d/base/Types.h>
|
||||
#include <extra2d/math/Math.h>
|
||||
#include <extra2d/renderer/2d/RenderEntity.h>
|
||||
#include <extra2d/renderer/2d/RenderDrawInfo.h>
|
||||
#include <extra2d/renderer/2d/UIMeshBuffer.h>
|
||||
#include <extra2d/gfx/GFXDef.h>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/core/math_types.h>
|
||||
#include <extra2d/base/Types.h>
|
||||
#include <extra2d/math/Math.h>
|
||||
#include <extra2d/gfx/GFXDef.h>
|
||||
|
||||
namespace extra2d {
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/core/math_types.h>
|
||||
#include <extra2d/base/Types.h>
|
||||
#include <extra2d/math/Math.h>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/base/Types.h>
|
||||
#include <extra2d/gfx/GFXDef.h>
|
||||
#include <unordered_map>
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/core/math_types.h>
|
||||
#include <extra2d/base/Types.h>
|
||||
#include <extra2d/math/Math.h>
|
||||
#include <extra2d/gfx/GFXDef.h>
|
||||
#include <vector>
|
||||
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/scene-graph/Component.h>
|
||||
#include <extra2d/core/math_types.h>
|
||||
#include <extra2d/2d/components/SpriteFrame.h>
|
||||
#include <extra2d/2d/renderer/RenderEntity.h>
|
||||
#include <extra2d/2d/renderer/RenderDrawInfo.h>
|
||||
#include <extra2d/scene/Component.h>
|
||||
#include <extra2d/math/Math.h>
|
||||
#include <extra2d/renderer/2d/components/SpriteFrame.h>
|
||||
#include <extra2d/renderer/2d/RenderEntity.h>
|
||||
#include <extra2d/renderer/2d/RenderDrawInfo.h>
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/assets/Asset.h>
|
||||
#include <extra2d/core/assets/Texture2D.h>
|
||||
#include <extra2d/core/math_types.h>
|
||||
#include <extra2d/assets/Asset.h>
|
||||
#include <extra2d/assets/Texture2D.h>
|
||||
#include <extra2d/math/Math.h>
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/Object.h>
|
||||
#include <extra2d/core/math_types.h>
|
||||
#include <extra2d/base/Object.h>
|
||||
#include <extra2d/math/Math.h>
|
||||
#include <extra2d/gfx/GFXDef.h>
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include <string>
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/Object.h>
|
||||
#include <extra2d/core/event/EventTarget.h>
|
||||
#include <extra2d/base/Object.h>
|
||||
#include <extra2d/event/EventTarget.h>
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/base/Types.h>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/Object.h>
|
||||
#include <extra2d/core/math_types.h>
|
||||
#include <extra2d/core/assets/Material.h>
|
||||
#include <extra2d/base/Object.h>
|
||||
#include <extra2d/math/Math.h>
|
||||
#include <extra2d/assets/Material.h>
|
||||
#include <extra2d/gfx/GFXDef.h>
|
||||
#include <vector>
|
||||
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/Object.h>
|
||||
#include <extra2d/core/event/EventTarget.h>
|
||||
#include <extra2d/core/math_types.h>
|
||||
#include <extra2d/base/Object.h>
|
||||
#include <extra2d/event/EventTarget.h>
|
||||
#include <extra2d/math/Math.h>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/Object.h>
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/base/Object.h>
|
||||
#include <extra2d/base/Types.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/Object.h>
|
||||
#include <extra2d/core/event/EventTarget.h>
|
||||
#include <extra2d/core/scene-graph/RenderScene.h>
|
||||
#include <extra2d/core/scene-graph/Camera.h>
|
||||
#include <extra2d/core/scene-graph/Model.h>
|
||||
#include <extra2d/base/Object.h>
|
||||
#include <extra2d/event/EventTarget.h>
|
||||
#include <extra2d/scene/RenderScene.h>
|
||||
#include <extra2d/scene/Camera.h>
|
||||
#include <extra2d/scene/Model.h>
|
||||
#include <extra2d/gfx/GFXDef.h>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/scene-graph/Node.h>
|
||||
#include <extra2d/scene/Node.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/base/Types.h>
|
||||
#include <random>
|
||||
|
||||
namespace extra2d {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/base/Types.h>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#include <extra2d/platform/Window.h>
|
||||
#include <extra2d/platform/Input.h>
|
||||
#include <extra2d/platform/SDLHelper.h>
|
||||
#include <extra2d/core/event/EventBus.h>
|
||||
#include <extra2d/event/EventBus.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include <extra2d/core/assets/Asset.h>
|
||||
#include <extra2d/assets/Asset.h>
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
#include <extra2d/core/assets/AssetManager.h>
|
||||
#include <extra2d/core/assets/Texture2D.h>
|
||||
#include <extra2d/assets/AssetManager.h>
|
||||
#include <extra2d/assets/Texture2D.h>
|
||||
#include <extra2d/gfx/GFXDevice.h>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
#include <extra2d/core/assets/ImageAsset.h>
|
||||
#include <extra2d/assets/ImageAsset.h>
|
||||
#include <cstring>
|
||||
|
||||
namespace extra2d {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
#include <extra2d/core/assets/Material.h>
|
||||
#include <extra2d/assets/Material.h>
|
||||
#include <extra2d/gfx/GFXShader.h>
|
||||
#include <extra2d/gfx/GFXPipeline.h>
|
||||
#include <functional>
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
#include <extra2d/core/assets/Texture2D.h>
|
||||
#include <extra2d/assets/Texture2D.h>
|
||||
#include <extra2d/gfx/GFXDevice.h>
|
||||
|
||||
namespace extra2d {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
#include <extra2d/core/Object.h>
|
||||
#include <extra2d/base/Object.h>
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
#include <extra2d/engine/Engine.h>
|
||||
#include <extra2d/core/event/EventBus.h>
|
||||
#include <extra2d/event/EventBus.h>
|
||||
#include <extra2d/base/AutoreleasePool.h>
|
||||
|
||||
namespace extra2d {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include <extra2d/core/event/EventBus.h>
|
||||
#include <extra2d/event/EventBus.h>
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
#include <extra2d/core/event/EventTarget.h>
|
||||
#include <extra2d/event/EventTarget.h>
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
#include <extra2d/gfx/GFXDescriptorSet.h>
|
||||
|
||||
namespace extra2d {
|
||||
namespace gfx {
|
||||
|
||||
// ==================== DescriptorSetLayout ====================
|
||||
|
||||
DescriptorSetLayout::~DescriptorSetLayout() {
|
||||
destroy();
|
||||
}
|
||||
|
||||
void DescriptorSetLayout::initialize(const DescriptorSetLayoutInfo& info) {
|
||||
bindings_ = info.bindings;
|
||||
doInit(info);
|
||||
}
|
||||
|
||||
void DescriptorSetLayout::destroy() {
|
||||
doDestroy();
|
||||
bindings_.clear();
|
||||
}
|
||||
|
||||
// ==================== DescriptorSet ====================
|
||||
|
||||
DescriptorSet::~DescriptorSet() {
|
||||
destroy();
|
||||
}
|
||||
|
||||
void DescriptorSet::initialize(const DescriptorSetInfo& info) {
|
||||
layout_ = const_cast<DescriptorSetLayout*>(info.layout);
|
||||
doInit(info);
|
||||
}
|
||||
|
||||
void DescriptorSet::destroy() {
|
||||
doDestroy();
|
||||
layout_ = nullptr;
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace extra2d
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
#include <extra2d/gfx/GFXFramebuffer.h>
|
||||
#include <extra2d/gfx/GFXRenderPass.h>
|
||||
#include <extra2d/gfx/GFXTexture.h>
|
||||
|
||||
namespace extra2d {
|
||||
namespace gfx {
|
||||
|
||||
Framebuffer::~Framebuffer() {
|
||||
destroy();
|
||||
}
|
||||
|
||||
void Framebuffer::initialize(const FramebufferInfo& info) {
|
||||
renderPass_ = info.renderPass;
|
||||
colorTextures_ = info.colorTextures;
|
||||
depthStencilTexture_ = info.depthStencilTexture;
|
||||
|
||||
// 从第一个颜色纹理获取尺寸
|
||||
if (!colorTextures_.empty() && colorTextures_[0]) {
|
||||
width_ = colorTextures_[0]->getWidth();
|
||||
height_ = colorTextures_[0]->getHeight();
|
||||
} else if (depthStencilTexture_) {
|
||||
width_ = depthStencilTexture_->getWidth();
|
||||
height_ = depthStencilTexture_->getHeight();
|
||||
}
|
||||
|
||||
doInit(info);
|
||||
}
|
||||
|
||||
void Framebuffer::destroy() {
|
||||
doDestroy();
|
||||
|
||||
renderPass_ = nullptr;
|
||||
colorTextures_.clear();
|
||||
depthStencilTexture_ = nullptr;
|
||||
width_ = 0;
|
||||
height_ = 0;
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace extra2d
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
#include <extra2d/gfx/GFXQueue.h>
|
||||
|
||||
namespace extra2d {
|
||||
namespace gfx {
|
||||
|
||||
Queue::~Queue() {
|
||||
destroy();
|
||||
}
|
||||
|
||||
void Queue::initialize(const QueueInfo& info) {
|
||||
type_ = info.type;
|
||||
doInit(info);
|
||||
}
|
||||
|
||||
void Queue::destroy() {
|
||||
doDestroy();
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace extra2d
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
#include <extra2d/gfx/GFXRenderPass.h>
|
||||
|
||||
namespace extra2d {
|
||||
namespace gfx {
|
||||
|
||||
RenderPass::~RenderPass() {
|
||||
destroy();
|
||||
}
|
||||
|
||||
void RenderPass::initialize(const RenderPassInfo& info) {
|
||||
colorAttachments_ = info.colorAttachments;
|
||||
depthStencilAttachment_ = info.depthStencilAttachment;
|
||||
subpasses_ = info.subpasses;
|
||||
dependencies_ = info.dependencies;
|
||||
|
||||
doInit(info);
|
||||
}
|
||||
|
||||
void RenderPass::destroy() {
|
||||
doDestroy();
|
||||
|
||||
colorAttachments_.clear();
|
||||
subpasses_.clear();
|
||||
dependencies_.clear();
|
||||
}
|
||||
|
||||
bool RenderPass::hasStencil() const {
|
||||
return depthStencilAttachment_.format == Format::DepthStencil ||
|
||||
depthStencilAttachment_.format == Format::Depth24Stencil8;
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace extra2d
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
#include <extra2d/gfx/GFXSampler.h>
|
||||
|
||||
namespace extra2d {
|
||||
namespace gfx {
|
||||
|
||||
Sampler::~Sampler() {
|
||||
destroy();
|
||||
}
|
||||
|
||||
void Sampler::initialize(const SamplerInfo& info) {
|
||||
minFilter_ = info.minFilter;
|
||||
magFilter_ = info.magFilter;
|
||||
mipFilter_ = info.mipFilter;
|
||||
addressU_ = info.addressU;
|
||||
addressV_ = info.addressV;
|
||||
addressW_ = info.addressW;
|
||||
maxAnisotropy_ = info.maxAnisotropy;
|
||||
comparisonFunc_ = info.comparisonFunc;
|
||||
minLOD_ = info.minLOD;
|
||||
maxLOD_ = info.maxLOD;
|
||||
mipLODBias_ = info.mipLODBias;
|
||||
|
||||
doInit(info);
|
||||
}
|
||||
|
||||
void Sampler::destroy() {
|
||||
doDestroy();
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace extra2d
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
#include <extra2d/gfx/GFXSwapchain.h>
|
||||
|
||||
namespace extra2d {
|
||||
namespace gfx {
|
||||
|
||||
Swapchain::~Swapchain() {
|
||||
destroy();
|
||||
}
|
||||
|
||||
void Swapchain::initialize(const SwapchainInfo& info) {
|
||||
width_ = info.width;
|
||||
height_ = info.height;
|
||||
format_ = info.format;
|
||||
imageCount_ = info.imageCount;
|
||||
vsync_ = info.vsync;
|
||||
|
||||
doInit(info);
|
||||
}
|
||||
|
||||
void Swapchain::destroy() {
|
||||
doDestroy();
|
||||
|
||||
width_ = 0;
|
||||
height_ = 0;
|
||||
}
|
||||
|
||||
void Swapchain::resize(u32 width, u32 height) {
|
||||
if (width_ == width && height_ == height) {
|
||||
return;
|
||||
}
|
||||
|
||||
width_ = width;
|
||||
height_ = height;
|
||||
|
||||
doResize(width, height);
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace extra2d
|
||||
|
|
@ -161,7 +161,8 @@ void GLCommandBuffer::updateBuffer(Buffer* buffer, u32 offset, const void* data,
|
|||
if (!buffer || !data) return;
|
||||
|
||||
auto* glBuffer = static_cast<GLBuffer*>(buffer);
|
||||
glBuffer->update(offset, data, size);
|
||||
// TODO: 需要扩展 GLBuffer 支持带偏移的更新
|
||||
glBuffer->update(data, size);
|
||||
}
|
||||
|
||||
void GLCommandBuffer::copyBuffer(Buffer* src, u32 srcOffset, Buffer* dst, u32 dstOffset, u32 size) {
|
||||
|
|
@ -170,8 +171,8 @@ void GLCommandBuffer::copyBuffer(Buffer* src, u32 srcOffset, Buffer* dst, u32 ds
|
|||
auto* glSrc = static_cast<GLBuffer*>(src);
|
||||
auto* glDst = static_cast<GLBuffer*>(dst);
|
||||
|
||||
glBindBuffer(GL_COPY_READ_BUFFER, glSrc->getHandle());
|
||||
glBindBuffer(GL_COPY_WRITE_BUFFER, glDst->getHandle());
|
||||
glBindBuffer(GL_COPY_READ_BUFFER, glSrc->getGLHandle());
|
||||
glBindBuffer(GL_COPY_WRITE_BUFFER, glDst->getGLHandle());
|
||||
glCopyBufferSubData(srcOffset, dstOffset, size);
|
||||
glBindBuffer(GL_COPY_READ_BUFFER, 0);
|
||||
glBindBuffer(GL_COPY_WRITE_BUFFER, 0);
|
||||
|
|
@ -184,8 +185,8 @@ void GLCommandBuffer::copyTexture(Texture* src, Texture* dst) {
|
|||
auto* glDst = static_cast<GLTexture*>(dst);
|
||||
|
||||
glCopyImageSubData(
|
||||
glSrc->getHandle(), GL_TEXTURE_2D, 0, 0, 0, 0,
|
||||
glDst->getHandle(), GL_TEXTURE_2D, 0, 0, 0, 0,
|
||||
glSrc->getGLHandle(), GL_TEXTURE_2D, 0, 0, 0, 0,
|
||||
glDst->getGLHandle(), GL_TEXTURE_2D, 0, 0, 0, 0,
|
||||
src->getWidth(), src->getHeight(), 1
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,136 @@
|
|||
#include <extra2d/gfx/opengl/GLDescriptorSet.h>
|
||||
#include <extra2d/gfx/opengl/GLBuffer.h>
|
||||
#include <extra2d/gfx/opengl/GLTexture.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <glad/glad.h>
|
||||
#else
|
||||
#include <GLES3/gl3.h>
|
||||
#endif
|
||||
|
||||
namespace extra2d {
|
||||
namespace gfx {
|
||||
|
||||
// ==================== GLDescriptorSetLayout ====================
|
||||
|
||||
GLDescriptorSetLayout::GLDescriptorSetLayout() = default;
|
||||
|
||||
GLDescriptorSetLayout::~GLDescriptorSetLayout() {
|
||||
doDestroy();
|
||||
}
|
||||
|
||||
void GLDescriptorSetLayout::doInit(const DescriptorSetLayoutInfo& info) {
|
||||
// OpenGL 没有显式的描述符集布局对象
|
||||
// 绑定信息已存储在基类中
|
||||
}
|
||||
|
||||
void GLDescriptorSetLayout::doDestroy() {
|
||||
// OpenGL 没有需要销毁的资源
|
||||
}
|
||||
|
||||
// ==================== GLDescriptorSet ====================
|
||||
|
||||
GLDescriptorSet::GLDescriptorSet() = default;
|
||||
|
||||
GLDescriptorSet::~GLDescriptorSet() {
|
||||
doDestroy();
|
||||
}
|
||||
|
||||
void GLDescriptorSet::bindBuffer(u32 binding, Buffer* buffer) {
|
||||
if (!buffer) return;
|
||||
|
||||
auto* glBuffer = static_cast<GLBuffer*>(buffer);
|
||||
DescriptorBinding& db = bindings_[binding];
|
||||
db.type = DescriptorType::UniformBuffer;
|
||||
db.buffer = glBuffer;
|
||||
}
|
||||
|
||||
void GLDescriptorSet::bindTexture(u32 binding, Texture* texture) {
|
||||
if (!texture) return;
|
||||
|
||||
auto* glTexture = static_cast<GLTexture*>(texture);
|
||||
DescriptorBinding& db = bindings_[binding];
|
||||
db.type = DescriptorType::Texture;
|
||||
db.texture = glTexture;
|
||||
}
|
||||
|
||||
void GLDescriptorSet::bindSampler(u32 binding, Sampler* sampler) {
|
||||
// OpenGL 采样器绑定需要纹理单元
|
||||
// 这里只存储采样器信息
|
||||
DescriptorBinding& db = bindings_[binding];
|
||||
db.type = DescriptorType::Sampler;
|
||||
}
|
||||
|
||||
void GLDescriptorSet::bindSamplerTexture(u32 binding, Texture* texture, Sampler* sampler) {
|
||||
if (!texture) return;
|
||||
|
||||
auto* glTexture = static_cast<GLTexture*>(texture);
|
||||
DescriptorBinding& db = bindings_[binding];
|
||||
db.type = DescriptorType::SamplerTexture;
|
||||
db.texture = glTexture;
|
||||
}
|
||||
|
||||
void GLDescriptorSet::update() {
|
||||
// OpenGL 的描述符更新在绑定时进行
|
||||
// 这里不需要额外操作
|
||||
}
|
||||
|
||||
void GLDescriptorSet::bindGL(u32 program) {
|
||||
u32 textureUnit = 0;
|
||||
|
||||
for (auto& pair : bindings_) {
|
||||
u32 binding = pair.first;
|
||||
DescriptorBinding& db = pair.second;
|
||||
|
||||
switch (db.type) {
|
||||
case DescriptorType::UniformBuffer:
|
||||
case DescriptorType::DynamicUniformBuffer:
|
||||
if (db.buffer) {
|
||||
GLuint blockIndex = glGetUniformBlockIndex(program,
|
||||
("UniformBlock_" + std::to_string(binding)).c_str());
|
||||
if (blockIndex != GL_INVALID_INDEX) {
|
||||
glUniformBlockBinding(program, blockIndex, binding);
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, binding, db.buffer->getGLHandle());
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case DescriptorType::Texture:
|
||||
case DescriptorType::SamplerTexture:
|
||||
if (db.texture) {
|
||||
glActiveTexture(GL_TEXTURE0 + textureUnit);
|
||||
glBindTexture(GL_TEXTURE_2D, db.texture->getGLHandle());
|
||||
|
||||
GLint location = glGetUniformLocation(program,
|
||||
("u_texture_" + std::to_string(binding)).c_str());
|
||||
if (location >= 0) {
|
||||
glUniform1i(location, textureUnit);
|
||||
}
|
||||
|
||||
textureUnit++;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GLDescriptorSet::doInit(const DescriptorSetInfo& info) {
|
||||
// 初始化绑定槽位
|
||||
if (layout_) {
|
||||
for (u32 i = 0; i < layout_->getBindingCount(); ++i) {
|
||||
const auto& binding = layout_->getBinding(i);
|
||||
bindings_[binding.binding] = DescriptorBinding{};
|
||||
bindings_[binding.binding].type = binding.descriptorType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GLDescriptorSet::doDestroy() {
|
||||
bindings_.clear();
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace extra2d
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
#include <extra2d/gfx/opengl/GLFramebuffer.h>
|
||||
#include <extra2d/gfx/opengl/GLTexture.h>
|
||||
|
||||
namespace extra2d {
|
||||
namespace gfx {
|
||||
|
||||
GLFramebuffer::GLFramebuffer() = default;
|
||||
|
||||
GLFramebuffer::~GLFramebuffer() {
|
||||
doDestroy();
|
||||
}
|
||||
|
||||
void GLFramebuffer::doInit(const FramebufferInfo& info) {
|
||||
glGenFramebuffers(1, &framebuffer_);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_);
|
||||
|
||||
// 绑定颜色附件
|
||||
for (size_t i = 0; i < colorTextures_.size(); ++i) {
|
||||
if (colorTextures_[i]) {
|
||||
auto* glTexture = static_cast<GLTexture*>(colorTextures_[i]);
|
||||
glFramebufferTexture2D(
|
||||
GL_FRAMEBUFFER,
|
||||
static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + i),
|
||||
GL_TEXTURE_2D,
|
||||
glTexture->getGLHandle(),
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 绑定深度模板附件
|
||||
if (depthStencilTexture_) {
|
||||
auto* glTexture = static_cast<GLTexture*>(depthStencilTexture_);
|
||||
GLenum attachment = GL_DEPTH_STENCIL_ATTACHMENT;
|
||||
|
||||
Format format = depthStencilTexture_->getFormat();
|
||||
if (format == Format::Depth) {
|
||||
attachment = GL_DEPTH_ATTACHMENT;
|
||||
} else if (format == Format::DepthStencil || format == Format::Depth24Stencil8) {
|
||||
attachment = GL_DEPTH_STENCIL_ATTACHMENT;
|
||||
}
|
||||
|
||||
glFramebufferTexture2D(
|
||||
GL_FRAMEBUFFER,
|
||||
attachment,
|
||||
GL_TEXTURE_2D,
|
||||
glTexture->getGLHandle(),
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
// 检查帧缓冲完整性
|
||||
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE) {
|
||||
// 帧缓冲不完整,记录错误
|
||||
}
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
void GLFramebuffer::doDestroy() {
|
||||
if (framebuffer_ != 0) {
|
||||
glDeleteFramebuffers(1, &framebuffer_);
|
||||
framebuffer_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace extra2d
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
#include <extra2d/gfx/opengl/GLQueue.h>
|
||||
#include <extra2d/gfx/GFXCommandBuffer.h>
|
||||
|
||||
namespace extra2d {
|
||||
namespace gfx {
|
||||
|
||||
GLQueue::GLQueue() = default;
|
||||
|
||||
GLQueue::~GLQueue() {
|
||||
doDestroy();
|
||||
}
|
||||
|
||||
void GLQueue::submit(CommandBuffer* const* cmdBuffers, u32 count) {
|
||||
for (u32 i = 0; i < count; ++i) {
|
||||
if (cmdBuffers[i]) {
|
||||
// OpenGL 命令立即执行,不需要显式提交
|
||||
// 这里可以添加同步逻辑
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <glad/glad.h>
|
||||
#else
|
||||
#include <GLES3/gl3.h>
|
||||
#endif
|
||||
|
||||
glFlush();
|
||||
}
|
||||
|
||||
void GLQueue::resetStats() {
|
||||
numDrawCalls_ = 0;
|
||||
numInstances_ = 0;
|
||||
numTriangles_ = 0;
|
||||
}
|
||||
|
||||
void GLQueue::doInit(const QueueInfo& info) {
|
||||
resetStats();
|
||||
}
|
||||
|
||||
void GLQueue::doDestroy() {
|
||||
resetStats();
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace extra2d
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
#include <extra2d/gfx/opengl/GLRenderPass.h>
|
||||
|
||||
namespace extra2d {
|
||||
namespace gfx {
|
||||
|
||||
GLRenderPass::GLRenderPass() = default;
|
||||
|
||||
GLRenderPass::~GLRenderPass() {
|
||||
doDestroy();
|
||||
}
|
||||
|
||||
void GLRenderPass::doInit(const RenderPassInfo& info) {
|
||||
// OpenGL 没有显式的 RenderPass 对象
|
||||
// 附件信息已存储在基类中
|
||||
}
|
||||
|
||||
void GLRenderPass::doDestroy() {
|
||||
// OpenGL 没有需要销毁的资源
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace extra2d
|
||||
|
|
@ -0,0 +1,131 @@
|
|||
#include <extra2d/gfx/opengl/GLSampler.h>
|
||||
|
||||
namespace extra2d {
|
||||
namespace gfx {
|
||||
|
||||
GLSampler::GLSampler() = default;
|
||||
|
||||
GLSampler::~GLSampler() {
|
||||
doDestroy();
|
||||
}
|
||||
|
||||
void GLSampler::bind(u32 unit) {
|
||||
glBindSampler(unit, sampler_);
|
||||
}
|
||||
|
||||
void GLSampler::doInit(const SamplerInfo& info) {
|
||||
glGenSamplers(1, &sampler_);
|
||||
|
||||
// 设置过滤模式
|
||||
GLenum minFilter = GL_LINEAR;
|
||||
GLenum magFilter = GL_LINEAR;
|
||||
|
||||
switch (magFilter_) {
|
||||
case Filter::Point:
|
||||
magFilter = GL_NEAREST;
|
||||
break;
|
||||
case Filter::Linear:
|
||||
default:
|
||||
magFilter = GL_LINEAR;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (minFilter_) {
|
||||
case Filter::Point:
|
||||
if (mipFilter_ == Filter::Point) {
|
||||
minFilter = GL_NEAREST_MIPMAP_NEAREST;
|
||||
} else if (mipFilter_ == Filter::Linear) {
|
||||
minFilter = GL_NEAREST_MIPMAP_LINEAR;
|
||||
} else {
|
||||
minFilter = GL_NEAREST;
|
||||
}
|
||||
break;
|
||||
case Filter::Linear:
|
||||
default:
|
||||
if (mipFilter_ == Filter::Point) {
|
||||
minFilter = GL_LINEAR_MIPMAP_NEAREST;
|
||||
} else if (mipFilter_ == Filter::Linear) {
|
||||
minFilter = GL_LINEAR_MIPMAP_LINEAR;
|
||||
} else {
|
||||
minFilter = GL_LINEAR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
glSamplerParameteri(sampler_, GL_TEXTURE_MIN_FILTER, minFilter);
|
||||
glSamplerParameteri(sampler_, GL_TEXTURE_MAG_FILTER, magFilter);
|
||||
|
||||
// 设置寻址模式
|
||||
auto toGLAddress = [](Address addr) -> GLenum {
|
||||
switch (addr) {
|
||||
case Address::Wrap:
|
||||
return GL_REPEAT;
|
||||
case Address::Mirror:
|
||||
return GL_MIRRORED_REPEAT;
|
||||
case Address::Clamp:
|
||||
return GL_CLAMP_TO_EDGE;
|
||||
case Address::Border:
|
||||
return GL_CLAMP_TO_BORDER;
|
||||
case Address::MirrorOnce:
|
||||
return GL_MIRROR_CLAMP_TO_EDGE;
|
||||
default:
|
||||
return GL_CLAMP_TO_EDGE;
|
||||
}
|
||||
};
|
||||
|
||||
glSamplerParameteri(sampler_, GL_TEXTURE_WRAP_S, toGLAddress(addressU_));
|
||||
glSamplerParameteri(sampler_, GL_TEXTURE_WRAP_T, toGLAddress(addressV_));
|
||||
glSamplerParameteri(sampler_, GL_TEXTURE_WRAP_R, toGLAddress(addressW_));
|
||||
|
||||
// 设置各向异性过滤
|
||||
glSamplerParameterf(sampler_, GL_TEXTURE_MAX_ANISOTROPY, maxAnisotropy_);
|
||||
|
||||
// 设置 LOD 范围
|
||||
glSamplerParameterf(sampler_, GL_TEXTURE_MIN_LOD, minLOD_);
|
||||
glSamplerParameterf(sampler_, GL_TEXTURE_MAX_LOD, maxLOD_);
|
||||
glSamplerParameterf(sampler_, GL_TEXTURE_LOD_BIAS, mipLODBias_);
|
||||
|
||||
// 设置比较函数(用于阴影贴图)
|
||||
if (comparisonFunc_ != ComparisonFunc::Never) {
|
||||
glSamplerParameteri(sampler_, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
||||
|
||||
GLenum cmpFunc = GL_NEVER;
|
||||
switch (comparisonFunc_) {
|
||||
case ComparisonFunc::Less:
|
||||
cmpFunc = GL_LESS;
|
||||
break;
|
||||
case ComparisonFunc::Equal:
|
||||
cmpFunc = GL_EQUAL;
|
||||
break;
|
||||
case ComparisonFunc::LessEqual:
|
||||
cmpFunc = GL_LEQUAL;
|
||||
break;
|
||||
case ComparisonFunc::Greater:
|
||||
cmpFunc = GL_GREATER;
|
||||
break;
|
||||
case ComparisonFunc::NotEqual:
|
||||
cmpFunc = GL_NOTEQUAL;
|
||||
break;
|
||||
case ComparisonFunc::GreaterEqual:
|
||||
cmpFunc = GL_GEQUAL;
|
||||
break;
|
||||
case ComparisonFunc::Always:
|
||||
cmpFunc = GL_ALWAYS;
|
||||
break;
|
||||
default:
|
||||
cmpFunc = GL_NEVER;
|
||||
break;
|
||||
}
|
||||
glSamplerParameteri(sampler_, GL_TEXTURE_COMPARE_FUNC, cmpFunc);
|
||||
}
|
||||
}
|
||||
|
||||
void GLSampler::doDestroy() {
|
||||
if (sampler_ != 0) {
|
||||
glDeleteSamplers(1, &sampler_);
|
||||
sampler_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace extra2d
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
#include <extra2d/gfx/opengl/GLSwapchain.h>
|
||||
|
||||
namespace extra2d {
|
||||
namespace gfx {
|
||||
|
||||
GLSwapchain::GLSwapchain() = default;
|
||||
|
||||
GLSwapchain::~GLSwapchain() {
|
||||
doDestroy();
|
||||
}
|
||||
|
||||
Texture* GLSwapchain::getColorTexture() {
|
||||
// OpenGL 默认帧缓冲没有显式的颜色纹理
|
||||
// 返回 nullptr 表示使用默认帧缓冲
|
||||
return colorTexture_.get();
|
||||
}
|
||||
|
||||
Texture* GLSwapchain::getDepthStencilTexture() {
|
||||
return depthStencilTexture_.get();
|
||||
}
|
||||
|
||||
void GLSwapchain::present() {
|
||||
// OpenGL 的呈现由窗口系统处理
|
||||
// 通常调用 SwapBuffers 或类似函数
|
||||
// 这里只需要确保所有命令已执行
|
||||
glFlush();
|
||||
}
|
||||
|
||||
void GLSwapchain::doInit(const SwapchainInfo& info) {
|
||||
// 创建深度模板纹理(可选)
|
||||
// 对于 OpenGL,默认帧缓冲已经有深度模板缓冲
|
||||
// 但如果需要离屏渲染,可以创建额外的纹理
|
||||
|
||||
TextureInfo depthInfo{};
|
||||
depthInfo.type = TextureType::Tex2D;
|
||||
depthInfo.format = Format::DepthStencil;
|
||||
depthInfo.width = width_;
|
||||
depthInfo.height = height_;
|
||||
depthInfo.usage = TextureUsage::DepthStencilAttachment;
|
||||
|
||||
depthStencilTexture_ = IntrusivePtr<GLTexture>::create();
|
||||
depthStencilTexture_->initialize(depthInfo);
|
||||
}
|
||||
|
||||
void GLSwapchain::doDestroy() {
|
||||
colorTexture_.reset();
|
||||
depthStencilTexture_.reset();
|
||||
}
|
||||
|
||||
void GLSwapchain::doResize(u32 width, u32 height) {
|
||||
// 重新创建深度模板纹理
|
||||
if (depthStencilTexture_) {
|
||||
depthStencilTexture_.reset();
|
||||
|
||||
TextureInfo depthInfo{};
|
||||
depthInfo.type = TextureType::Tex2D;
|
||||
depthInfo.format = Format::DepthStencil;
|
||||
depthInfo.width = width;
|
||||
depthInfo.height = height;
|
||||
depthInfo.usage = TextureUsage::DepthStencilAttachment;
|
||||
|
||||
depthStencilTexture_ = IntrusivePtr<GLTexture>::create();
|
||||
depthStencilTexture_->initialize(depthInfo);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace extra2d
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
#include <extra2d/platform/Input.h>
|
||||
#include <extra2d/core/event/EventBus.h>
|
||||
#include <extra2d/event/EventBus.h>
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <cmath>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include <extra2d/2d/renderer/Batcher2d.h>
|
||||
#include <extra2d/core/scene-graph/Node.h>
|
||||
#include <extra2d/renderer/2d/Batcher2d.h>
|
||||
#include <extra2d/scene/Node.h>
|
||||
#include <extra2d/gfx/GFXDevice.h>
|
||||
#include <extra2d/gfx/GFXShader.h>
|
||||
#include <extra2d/gfx/GFXPipeline.h>
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
#include <extra2d/2d/renderer/RenderDrawInfo.h>
|
||||
#include <extra2d/2d/renderer/UIMeshBuffer.h>
|
||||
#include <extra2d/renderer/2d/RenderDrawInfo.h>
|
||||
#include <extra2d/renderer/2d/UIMeshBuffer.h>
|
||||
#include <extra2d/gfx/GFXDevice.h>
|
||||
|
||||
namespace extra2d {
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
#include <extra2d/2d/renderer/RenderEntity.h>
|
||||
#include <extra2d/2d/renderer/RenderDrawInfo.h>
|
||||
#include <extra2d/renderer/2d/RenderEntity.h>
|
||||
#include <extra2d/renderer/2d/RenderDrawInfo.h>
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
#include <extra2d/2d/renderer/StencilManager.h>
|
||||
#include <extra2d/2d/renderer/RenderEntity.h>
|
||||
#include <extra2d/renderer/2d/StencilManager.h>
|
||||
#include <extra2d/renderer/2d/RenderEntity.h>
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
#include <extra2d/2d/renderer/UIMeshBuffer.h>
|
||||
#include <extra2d/renderer/2d/UIMeshBuffer.h>
|
||||
#include <extra2d/gfx/GFXDevice.h>
|
||||
#include <cstring>
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#include <extra2d/2d/components/Sprite.h>
|
||||
#include <extra2d/core/scene-graph/Node.h>
|
||||
#include <extra2d/2d/renderer/Batcher2d.h>
|
||||
#include <extra2d/renderer/2d/components/Sprite.h>
|
||||
#include <extra2d/scene/Node.h>
|
||||
#include <extra2d/renderer/2d/Batcher2d.h>
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#include <extra2d/2d/components/SpriteFrame.h>
|
||||
#include <extra2d/2d/components/Sprite.h>
|
||||
#include <extra2d/core/scene-graph/Node.h>
|
||||
#include <extra2d/renderer/2d/components/SpriteFrame.h>
|
||||
#include <extra2d/renderer/2d/components/Sprite.h>
|
||||
#include <extra2d/scene/Node.h>
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#include <extra2d/core/scene-graph/Camera.h>
|
||||
#include <extra2d/core/scene-graph/Node.h>
|
||||
#include <extra2d/core/scene-graph/Scene.h>
|
||||
#include <extra2d/scene/Camera.h>
|
||||
#include <extra2d/scene/Node.h>
|
||||
#include <extra2d/scene/Scene.h>
|
||||
#include <extra2d/gfx/GFXDevice.h>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
#include <extra2d/core/scene-graph/Component.h>
|
||||
#include <extra2d/core/scene-graph/Node.h>
|
||||
#include <extra2d/scene/Component.h>
|
||||
#include <extra2d/scene/Node.h>
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
#include <extra2d/core/scene-graph/Layers.h>
|
||||
#include <extra2d/scene/Layers.h>
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#include <extra2d/core/scene-graph/Model.h>
|
||||
#include <extra2d/core/scene-graph/Node.h>
|
||||
#include <extra2d/core/scene-graph/RenderScene.h>
|
||||
#include <extra2d/scene/Model.h>
|
||||
#include <extra2d/scene/Node.h>
|
||||
#include <extra2d/scene/RenderScene.h>
|
||||
#include <algorithm>
|
||||
|
||||
namespace extra2d {
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#include <extra2d/core/scene-graph/Node.h>
|
||||
#include <extra2d/core/scene-graph/Component.h>
|
||||
#include <extra2d/core/scene-graph/Scene.h>
|
||||
#include <extra2d/scene/Node.h>
|
||||
#include <extra2d/scene/Component.h>
|
||||
#include <extra2d/scene/Scene.h>
|
||||
#include <algorithm>
|
||||
|
||||
namespace extra2d {
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#include <extra2d/core/scene-graph/RenderScene.h>
|
||||
#include <extra2d/core/scene-graph/Camera.h>
|
||||
#include <extra2d/core/scene-graph/Node.h>
|
||||
#include <extra2d/2d/renderer/Batcher2d.h>
|
||||
#include <extra2d/scene/RenderScene.h>
|
||||
#include <extra2d/scene/Camera.h>
|
||||
#include <extra2d/scene/Node.h>
|
||||
#include <extra2d/renderer/2d/Batcher2d.h>
|
||||
#include <algorithm>
|
||||
|
||||
namespace extra2d {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
#include <extra2d/core/scene-graph/Scene.h>
|
||||
#include <extra2d/scene/Scene.h>
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Extra2D 目录结构重构脚本
|
||||
用于批量移动文件和更新 include 路径
|
||||
"""
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import re
|
||||
|
||||
BASE_DIR = r"d:\Extra2D\Extra2D"
|
||||
|
||||
def move_file(src, dst):
|
||||
if os.path.exists(src):
|
||||
os.makedirs(os.path.dirname(dst), exist_ok=True)
|
||||
shutil.move(src, dst)
|
||||
print(f"移动: {src} -> {dst}")
|
||||
else:
|
||||
print(f"文件不存在: {src}")
|
||||
|
||||
def move_remaining_files():
|
||||
moves = [
|
||||
(r"include\extra2d\2d\renderer\UIMeshBuffer.h", r"include\extra2d\renderer\2d\UIMeshBuffer.h"),
|
||||
(r"src\2d\components\Sprite.cpp", r"src\renderer\2d\components\Sprite.cpp"),
|
||||
(r"src\2d\components\SpriteFrame.cpp", r"src\renderer\2d\components\SpriteFrame.cpp"),
|
||||
(r"src\2d\renderer\Batcher2d.cpp", r"src\renderer\2d\Batcher2d.cpp"),
|
||||
(r"src\2d\renderer\RenderDrawInfo.cpp", r"src\renderer\2d\RenderDrawInfo.cpp"),
|
||||
(r"src\2d\renderer\RenderEntity.cpp", r"src\renderer\2d\RenderEntity.cpp"),
|
||||
(r"src\2d\renderer\StencilManager.cpp", r"src\renderer\2d\StencilManager.cpp"),
|
||||
(r"src\2d\renderer\UIMeshBuffer.cpp", r"src\renderer\2d\UIMeshBuffer.cpp"),
|
||||
]
|
||||
|
||||
for src_rel, dst_rel in moves:
|
||||
src = os.path.join(BASE_DIR, src_rel)
|
||||
dst = os.path.join(BASE_DIR, dst_rel)
|
||||
move_file(src, dst)
|
||||
|
||||
def update_includes():
|
||||
path_mappings = {
|
||||
r'<extra2d/core/Object\.h>': r'<extra2d/base/Object.h>',
|
||||
r'<extra2d/core/types\.h>': r'<extra2d/base/Types.h>',
|
||||
r'<extra2d/core/color\.h>': r'<extra2d/math/Color.h>',
|
||||
r'<extra2d/core/math_types\.h>': r'<extra2d/math/Math.h>',
|
||||
r'<extra2d/core/event/EventBus\.h>': r'<extra2d/event/EventBus.h>',
|
||||
r'<extra2d/core/event/EventTarget\.h>': r'<extra2d/event/EventTarget.h>',
|
||||
r'<extra2d/core/scene-graph/Node\.h>': r'<extra2d/scene/Node.h>',
|
||||
r'<extra2d/core/scene-graph/Scene\.h>': r'<extra2d/scene/Scene.h>',
|
||||
r'<extra2d/core/scene-graph/Component\.h>': r'<extra2d/scene/Component.h>',
|
||||
r'<extra2d/core/scene-graph/Camera\.h>': r'<extra2d/scene/Camera.h>',
|
||||
r'<extra2d/core/scene-graph/Model\.h>': r'<extra2d/scene/Model.h>',
|
||||
r'<extra2d/core/scene-graph/RenderScene\.h>': r'<extra2d/scene/RenderScene.h>',
|
||||
r'<extra2d/core/scene-graph/Layers\.h>': r'<extra2d/scene/Layers.h>',
|
||||
r'<extra2d/core/Root\.h>': r'<extra2d/scene/Root.h>',
|
||||
r'<extra2d/core/assets/Asset\.h>': r'<extra2d/assets/Asset.h>',
|
||||
r'<extra2d/core/assets/AssetManager\.h>': r'<extra2d/assets/AssetManager.h>',
|
||||
r'<extra2d/core/assets/ImageAsset\.h>': r'<extra2d/assets/ImageAsset.h>',
|
||||
r'<extra2d/core/assets/Texture2D\.h>': r'<extra2d/assets/Texture2D.h>',
|
||||
r'<extra2d/core/assets/Material\.h>': r'<extra2d/assets/Material.h>',
|
||||
r'<extra2d/2d/components/Sprite\.h>': r'<extra2d/renderer/2d/components/Sprite.h>',
|
||||
r'<extra2d/2d/components/SpriteFrame\.h>': r'<extra2d/renderer/2d/components/SpriteFrame.h>',
|
||||
r'<extra2d/2d/renderer/Batcher2d\.h>': r'<extra2d/renderer/2d/Batcher2d.h>',
|
||||
r'<extra2d/2d/renderer/RenderEntity\.h>': r'<extra2d/renderer/2d/RenderEntity.h>',
|
||||
r'<extra2d/2d/renderer/RenderDrawInfo\.h>': r'<extra2d/renderer/2d/RenderDrawInfo.h>',
|
||||
r'<extra2d/2d/renderer/UIMeshBuffer\.h>': r'<extra2d/renderer/2d/UIMeshBuffer.h>',
|
||||
r'<extra2d/2d/renderer/StencilManager\.h>': r'<extra2d/renderer/2d/StencilManager.h>',
|
||||
}
|
||||
|
||||
extensions = ['.h', '.hpp', '.cpp', '.c', '.inl']
|
||||
|
||||
for root, dirs, files in os.walk(BASE_DIR):
|
||||
for file in files:
|
||||
if any(file.endswith(ext) for ext in extensions):
|
||||
filepath = os.path.join(root, file)
|
||||
try:
|
||||
with open(filepath, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
|
||||
original = content
|
||||
for old_pattern, new_path in path_mappings.items():
|
||||
content = re.sub(old_pattern, new_path, content)
|
||||
|
||||
if content != original:
|
||||
with open(filepath, 'w', encoding='utf-8') as f:
|
||||
f.write(content)
|
||||
print(f"更新: {filepath}")
|
||||
except Exception as e:
|
||||
print(f"错误处理 {filepath}: {e}")
|
||||
|
||||
def delete_empty_dirs():
|
||||
empty_dirs = [
|
||||
r"include\extra2d\core",
|
||||
r"include\extra2d\2d",
|
||||
r"src\core",
|
||||
r"src\2d",
|
||||
]
|
||||
|
||||
for dir_rel in empty_dirs:
|
||||
dir_path = os.path.join(BASE_DIR, dir_rel)
|
||||
if os.path.exists(dir_path):
|
||||
try:
|
||||
shutil.rmtree(dir_path)
|
||||
print(f"删除目录: {dir_path}")
|
||||
except Exception as e:
|
||||
print(f"无法删除 {dir_path}: {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("=== 移动剩余文件 ===")
|
||||
move_remaining_files()
|
||||
|
||||
print("\n=== 更新 include 路径 ===")
|
||||
update_includes()
|
||||
|
||||
print("\n=== 删除空目录 ===")
|
||||
delete_empty_dirs()
|
||||
|
||||
print("\n完成!")
|
||||
Loading…
Reference in New Issue