feat(渲染): 添加内置着色器管理和安装功能
- 移除font.shader中u_smoothing的默认值 - 添加xmake.lua中的着色器安装函数,支持不同平台 - 在渲染模块初始化时初始化ShaderManager并加载内置着色器 - 在渲染模块关闭时清理ShaderManager资源
This commit is contained in:
parent
475ae50d2a
commit
f8ecf7e03a
|
|
@ -41,7 +41,7 @@ in vec2 v_texCoord;
|
|||
in vec4 v_color;
|
||||
|
||||
uniform sampler2D u_texture;
|
||||
uniform float u_smoothing = 0.1;
|
||||
uniform float u_smoothing;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#include <extra2d/graphics/render_module.h>
|
||||
#include <extra2d/config/module_registry.h>
|
||||
#include <extra2d/graphics/opengl/gl_shader_new.h>
|
||||
#include <extra2d/graphics/shader_manager.h>
|
||||
#include <extra2d/platform/iwindow.h>
|
||||
#include <extra2d/utils/logger.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
|
@ -145,6 +147,15 @@ bool RenderModuleInitializer::initialize(const IModuleConfig* config) {
|
|||
E2D_LOG_ERROR("Render module requires window to be set");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto shaderFactory = std::make_shared<GLShaderFactory>();
|
||||
if (!ShaderManager::getInstance().init(shaderFactory, "extra2d")) {
|
||||
E2D_LOG_WARN("Failed to initialize ShaderManager with default paths");
|
||||
}
|
||||
|
||||
if (!ShaderManager::getInstance().loadBuiltinShaders()) {
|
||||
E2D_LOG_WARN("Failed to load some builtin shaders");
|
||||
}
|
||||
|
||||
renderer_ = RenderBackend::create(renderConfig->backend);
|
||||
if (!renderer_) {
|
||||
|
|
@ -171,6 +182,8 @@ void RenderModuleInitializer::shutdown() {
|
|||
renderer_.reset();
|
||||
}
|
||||
|
||||
ShaderManager::getInstance().shutdown();
|
||||
|
||||
initialized_ = false;
|
||||
E2D_LOG_INFO("Render module shutdown");
|
||||
}
|
||||
|
|
|
|||
30
xmake.lua
30
xmake.lua
|
|
@ -95,6 +95,32 @@ includes("xmake/engine.lua")
|
|||
-- 定义引擎库
|
||||
define_extra2d_engine()
|
||||
|
||||
-- ==============================================
|
||||
-- Shader文件安装函数
|
||||
-- ==============================================
|
||||
|
||||
function install_shaders(target)
|
||||
local plat = get_config("plat") or os.host()
|
||||
local targetdir = target:targetdir()
|
||||
|
||||
local shader_src = "Extra2D/shaders"
|
||||
|
||||
if plat == "switch" then
|
||||
local romfs_dir = path.join(targetdir, "romfs")
|
||||
local shader_dest = path.join(romfs_dir, "shaders")
|
||||
|
||||
os.rm(shader_dest)
|
||||
os.cp(shader_src, shader_dest)
|
||||
print("Shaders installed to romfs: " .. shader_dest)
|
||||
else
|
||||
local shader_dest = path.join(targetdir, "shaders")
|
||||
|
||||
os.rm(shader_dest)
|
||||
os.cp(shader_src, shader_dest)
|
||||
print("Shaders installed to: " .. shader_dest)
|
||||
end
|
||||
end
|
||||
|
||||
-- ==============================================
|
||||
-- 示例程序
|
||||
-- ==============================================
|
||||
|
|
@ -113,5 +139,7 @@ target("demo_basic")
|
|||
add_packages("glm", "nlohmann_json", "libsdl2")
|
||||
add_syslinks("opengl32", "glu32", "winmm", "imm32", "version", "setupapi")
|
||||
end
|
||||
|
||||
-- 构建后安装Shader文件
|
||||
after_build(install_shaders)
|
||||
target_end()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue