diff --git a/example/src/main.cpp b/example/src/main.cpp index c538de3..98597be 100644 --- a/example/src/main.cpp +++ b/example/src/main.cpp @@ -31,8 +31,15 @@ int main(int argc, char* argv[]) { auto image = std::make_shared(); image->set_image(i); + auto hbox = std::make_shared(); + hbox->add_child() + .auto_size() + [ + image + ]; + const auto& window = mwindow::create({ 800, 600 }, L"Hello, World!"); - window->set_content(image); + window->set_content(hbox); mirage_app::get().run(); return 0; diff --git a/src/mirage_render/render/texture2d.h b/src/mirage_render/render/texture2d.h index f93a869..6330134 100644 --- a/src/mirage_render/render/texture2d.h +++ b/src/mirage_render/render/texture2d.h @@ -23,7 +23,9 @@ public: [[nodiscard]] const auto& get_image() const { return image_; } [[nodiscard]] const auto& get_size() const { return size_; } + [[nodiscard]] const auto& get_pixel_format() const { return pixel_format_; } private: sg_image image_{}; + sg_pixel_format pixel_format_{}; Eigen::Vector2i size_{}; }; diff --git a/src/mirage_render/render/texture_sampler.h b/src/mirage_render/render/texture_sampler.h index 89a5b8a..c28c30b 100644 --- a/src/mirage_render/render/texture_sampler.h +++ b/src/mirage_render/render/texture_sampler.h @@ -80,7 +80,7 @@ public: * @param anisotropy 各向异性程度(1-16) * @return 具有各向异性过滤的采样器 */ - static texture_sampler_builder create_anisotropic(uint32_t anisotropy = 4); + static texture_sampler_builder create_anisotropic(uint32_t anisotropy = 16); /** * @brief 设置缩小过滤器 diff --git a/src/mirage_render/render/windows/texture2d.cpp b/src/mirage_render/render/windows/texture2d.cpp index 2279e5c..bbb6b6c 100644 --- a/src/mirage_render/render/windows/texture2d.cpp +++ b/src/mirage_render/render/windows/texture2d.cpp @@ -7,6 +7,8 @@ void texture2d::create(void* in_data, const Eigen::Vector2i& in_size, sg_pixel_format in_pixel_format) { auto format_info = sg_query_pixelformat(in_pixel_format); + pixel_format_ = in_pixel_format; + size_ = in_size; sg_image_desc sg_desc{}; sg_desc.type = SG_IMAGETYPE_2D; diff --git a/src/mirage_widget/widget/leaf_widget/mimage.cpp b/src/mirage_widget/widget/leaf_widget/mimage.cpp index 5219f4b..e425a5e 100644 --- a/src/mirage_widget/widget/leaf_widget/mimage.cpp +++ b/src/mirage_widget/widget/leaf_widget/mimage.cpp @@ -12,11 +12,28 @@ void mimage::on_paint(mirage_paint_context& in_context) { in_context.geo().get_local_size(), in_context.geo(), image_->get_image(), - sampler_type::default_, + sampler_type::anisotropic, { color_ } ); } +void mimage::set_image(const std::shared_ptr& in_image) { + image_ = in_image; + auto image_format = image_->get_pixel_format(); + // 根据像素格式选择合适的过滤器 + if (image_format == sg_pixel_format::SG_PIXELFORMAT_BC1_RGBA || + image_format == sg_pixel_format::SG_PIXELFORMAT_BC2_RGBA || + image_format == sg_pixel_format::SG_PIXELFORMAT_BC3_RGBA || + image_format == sg_pixel_format::SG_PIXELFORMAT_BC4_R || + image_format == sg_pixel_format::SG_PIXELFORMAT_BC5_RG || + image_format == sg_pixel_format::SG_PIXELFORMAT_BC6H_RGBF || + image_format == sg_pixel_format::SG_PIXELFORMAT_BC7_RGBA) { + filter_ = sg_filter::SG_FILTER_NEAREST; + } else { + filter_ = sg_filter::SG_FILTER_LINEAR; + } +} + Eigen::Vector2f mimage::compute_desired_size(float in_layout_scale_multiplier) const { if (image_) { return image_->get_size().cast(); diff --git a/src/mirage_widget/widget/leaf_widget/mimage.h b/src/mirage_widget/widget/leaf_widget/mimage.h index 01ca961..cab66dd 100644 --- a/src/mirage_widget/widget/leaf_widget/mimage.h +++ b/src/mirage_widget/widget/leaf_widget/mimage.h @@ -10,7 +10,7 @@ public: Eigen::Vector2f compute_desired_size(float in_layout_scale_multiplier) const override; const auto& get_image() const { return image_; } - void set_image(const std::shared_ptr& in_image) { image_ = in_image; } + void set_image(const std::shared_ptr& in_image); const auto& get_color() const { return color_; } void set_color(const linear_color& in_color) { color_ = in_color; } @@ -18,4 +18,5 @@ private: std::shared_ptr image_; std::shared_ptr sampler_; linear_color color_ = { 1, 1, 1, 1 }; + sg_filter filter_{}; }; diff --git a/src/mirage_widget/widget/mpanel_widget.h b/src/mirage_widget/widget/mpanel_widget.h index dc91bf4..bcc0d76 100644 --- a/src/mirage_widget/widget/mpanel_widget.h +++ b/src/mirage_widget/widget/mpanel_widget.h @@ -72,14 +72,13 @@ public: * * 创建并添加一个新的子组件插槽到面板中。 */ - template auto add_slot() -> SlotType& { auto& slot = slots_.emplace_back(); slot.slot_owner = shared_from_this(); invalidate(invalidate_reason::all); return slot; } - template + template auto add_child(Args&&... in_args) -> SlotType& { auto& slot = slots_.emplace_back(std::forward(in_args)...); slot.slot_owner = shared_from_this(); diff --git a/tools/win_mirage_shdc.exe b/tools/win_mirage_shdc.exe index 0dc377b..68f5f6b 100644 Binary files a/tools/win_mirage_shdc.exe and b/tools/win_mirage_shdc.exe differ