feat(渲染): 实现2D渲染风格系统

添加渲染风格预设配置,支持像素风、平滑2D和混合模式
新增纹理采样控制、顶点像素对齐和UV收缩优化
为相机和场景添加渲染风格覆盖功能
This commit is contained in:
2026-04-07 00:15:48 +08:00
parent 62b0f6dafd
commit 875af43f88
18 changed files with 414 additions and 51 deletions

View File

@@ -3,6 +3,7 @@
#include <frostbite2D/graphics/batch.h>
#include <frostbite2D/graphics/camera.h>
#include <frostbite2D/graphics/render_resolution.h>
#include <frostbite2D/graphics/render_style.h>
#include <frostbite2D/graphics/shader.h>
#include <frostbite2D/graphics/shader_manager.h>
#include <frostbite2D/graphics/texture.h>
@@ -31,6 +32,26 @@ public:
void setClearColor(float r, float g, float b, float a = 1.0f);
void setClearColor(const Color& color);
void clear(uint32_t flags);
/**
* @brief 设置应用默认渲染风格预设
*/
void setDefaultRenderStyleProfile(RenderStyleProfileId profile);
/**
* @brief 获取应用默认渲染风格预设
*/
RenderStyleProfileId getDefaultRenderStyleProfile() const {
return defaultRenderStyleProfile_;
}
/**
* @brief 切换当前正在使用的渲染风格上下文
*/
void setActiveRenderStyleProfile(RenderStyleProfileId profile,
RenderStyleLayerRole role);
/**
* @brief 将指定风格作用到某个相机
*/
void applyRenderStyleToCamera(Camera* camera, RenderStyleProfileId profile,
RenderStyleLayerRole role) const;
void setCamera(Camera* camera);
Camera* getCamera() { return camera_; }
@@ -53,6 +74,28 @@ public:
Ptr<Texture> texture,
const Color& color = Color(1, 1, 1, 1));
void setupBlendMode(BlendMode mode);
/**
* @brief 获取当前激活的层级风格设置
*/
const RenderStyleLayerSettings& getActiveRenderStyle() const {
return activeRenderStyle_;
}
/**
* @brief 当前风格是否要求顶点像素对齐
*/
bool shouldSnapVertices() const { return activeRenderStyle_.vertexPixelSnap; }
/**
* @brief 当前风格是否优先使用像素风采样
*/
bool shouldUsePixelArtSampling() const {
return activeRenderStyle_.pixelArtSampling;
}
/**
* @brief 当前风格是否需要对子纹理 UV 做向内收缩
*/
bool shouldShrinkSubTextureUVs() const {
return activeRenderStyle_.shrinkSubTextureUVs;
}
ShaderManager& getShaderManager() { return shaderManager_; }
Batch& getBatch() { return batch_; }
@@ -67,6 +110,10 @@ private:
ShaderManager shaderManager_;
Batch batch_;
Camera* camera_ = nullptr;
RenderStyleProfileId defaultRenderStyleProfile_ = RenderStyleProfileId::Hybrid2D;
RenderStyleProfileId activeRenderStyleProfile_ = RenderStyleProfileId::Hybrid2D;
RenderStyleLayerRole activeRenderStyleRole_ = RenderStyleLayerRole::World;
RenderStyleLayerSettings activeRenderStyle_;
uint32_t clearColor_[4] = {0, 0, 0, 255};
bool useVirtualResolution_ = false;