From d598b26845c0d8659afb643bcf7640d2d598c638 Mon Sep 17 00:00:00 2001 From: ternaryop8479 Date: Sun, 15 Feb 2026 00:19:34 +0800 Subject: [PATCH] =?UTF-8?q?fix&style:=20=E4=BF=AE=E5=A4=8Dscreen=5Fblit?= =?UTF-8?q?=E5=B4=A9=E6=BA=83=E9=97=AE=E9=A2=98=EF=BC=8C=E5=BE=AE=E8=B0=83?= =?UTF-8?q?raytracer=E5=86=85=E9=83=A8=E6=8E=A5=E5=8F=A3=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/core/raytracer.h | 6 +----- include/core/screen_blit.h | 2 +- src/core/raytracer.cpp | 9 +++------ src/core/renderer.cpp | 15 +++++---------- src/core/screen_blit.cpp | 4 +++- 5 files changed, 13 insertions(+), 23 deletions(-) diff --git a/include/core/raytracer.h b/include/core/raytracer.h index 4f60abf..370989b 100644 --- a/include/core/raytracer.h +++ b/include/core/raytracer.h @@ -35,7 +35,7 @@ public: /// @brief Initialize ray tracer /// @return True if initialization succeeded - bool initialize(); + bool initialize(const std::shared_ptr &shader); /// @brief Release resources void release(); @@ -69,10 +69,6 @@ public: /// @return True if build succeeded bool rebuild_bvh(const Scene &scene); - /// @brief Set compute shader (called by renderer) - /// @param shader Compute shader - void set_compute_shader(const std::shared_ptr &shader); - private: uint width_; uint height_; diff --git a/include/core/screen_blit.h b/include/core/screen_blit.h index 3646d02..3805957 100644 --- a/include/core/screen_blit.h +++ b/include/core/screen_blit.h @@ -18,7 +18,7 @@ public: /// @brief Initialize screen blit /// @return True if initialization succeeded - bool initialize(); + bool initialize(const std::shared_ptr &screen_blit_shader); /// @brief Release resources void release(); diff --git a/src/core/raytracer.cpp b/src/core/raytracer.cpp index 03ecbf8..b056d77 100644 --- a/src/core/raytracer.cpp +++ b/src/core/raytracer.cpp @@ -37,12 +37,14 @@ RayTracer::~RayTracer() { release(); } -bool RayTracer::initialize() { +bool RayTracer::initialize(const std::shared_ptr &shader) { if (initialized_) { ARE_LOG_WARN("RayTracer already initialized"); return true; } + compute_shader_ = shader; + // Create accumulation texture glGenTextures(1, &accumulation_texture_); glBindTexture(GL_TEXTURE_2D, accumulation_texture_); @@ -345,9 +347,4 @@ void RayTracer::bind_gbuffer_(const GBuffer &gbuffer) { glBindImageTexture(6, gbuffer.get_texture(GBUFFER_MATERIAL_ID), 0, GL_FALSE, 0, GL_READ_ONLY, GL_R32UI); } -void RayTracer::set_compute_shader(const std::shared_ptr &shader) { - compute_shader_ = shader; - ARE_LOG_INFO("Compute shader set for RayTracer"); -} - } // namespace are diff --git a/src/core/renderer.cpp b/src/core/renderer.cpp index a580371..5ee3de2 100644 --- a/src/core/renderer.cpp +++ b/src/core/renderer.cpp @@ -46,23 +46,18 @@ bool Renderer::initialize() { rt_config.enable_accumulation_ = config_.enable_accumulation_; rt_config.use_bvh_ = true; + // Initialize ray tracer raytracer_ = std::make_unique(config_.width_, config_.height_, rt_config); - if (!raytracer_->initialize()) { + const auto& rt_shader = shader_manager_->get_raytracing_shader(); + if (!raytracer_->initialize(rt_shader)) { ARE_LOG_ERROR("Failed to initialize ray tracer"); return false; } - - // Pass compute shader to ray tracer - const auto& rt_shader = shader_manager_->get_raytracing_shader(); - if (!rt_shader || !rt_shader->is_valid()) { - ARE_LOG_ERROR("Ray tracing shader is invalid"); - return false; - } - raytracer_->set_compute_shader(rt_shader); // Initialize screen blit screen_blit_ = std::make_unique(); - if (!screen_blit_->initialize()) { + const auto& screen_blit_shader = shader_manager_->get_screen_blit_shader(); + if (!screen_blit_->initialize(screen_blit_shader)) { ARE_LOG_ERROR("Failed to initialize screen blit"); return false; } diff --git a/src/core/screen_blit.cpp b/src/core/screen_blit.cpp index eb7df58..54ddb2c 100644 --- a/src/core/screen_blit.cpp +++ b/src/core/screen_blit.cpp @@ -14,11 +14,13 @@ ScreenBlit::~ScreenBlit() { release(); } -bool ScreenBlit::initialize() { +bool ScreenBlit::initialize(const std::shared_ptr &screen_blit_shader) { if (initialized_) { ARE_LOG_WARN("ScreenBlit already initialized"); return true; } + + shader_ = screen_blit_shader; // Create fullscreen quad create_quad_();