From 40fd75ffef0bba230eeadc7d78e8cabce50b954f Mon Sep 17 00:00:00 2001 From: copi143 Date: Tue, 28 Jan 2025 22:23:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 9 ++++++++- cmake/disable-warning | 1 - doc/src/index.md | 9 +++++++++ include/pl2d/pixel/mix.hpp | 2 -- include/pl2d/texture/paste.hpp | 8 +++++--- src/pl2d/fb/flush-bgr.hpp | 32 ++++++++++++++------------------ src/pl2d/fb/flush-cases.hpp | 4 ++-- src/pl2d/fb/flush-loop.hpp | 20 ++++++++++---------- src/pl2d/fb/flush-rgb.hpp | 32 ++++++++++++++------------------ src/pl2d/fb/flush-rgb565.hpp | 32 ++++++++++++++------------------ src/pl2d/fb/private.hpp | 14 ++++++++------ test/plui/main.c | 9 +++++++-- test/plui/main.cpp | 8 ++++---- 13 files changed, 95 insertions(+), 85 deletions(-) diff --git a/README.md b/README.md index aebbca12..88e1e44b 100755 --- a/README.md +++ b/README.md @@ -4,7 +4,14 @@ -A simple OS used to study made by several students。 +A simple OS used to study made by several students. + +

+Happy New Year!
+新年快乐! +

+ +

今年是 蛇 年!

![Static Badge](https://img.shields.io/badge/License-MIT-blue) ![Static Badge](https://img.shields.io/badge/Language-3-orange) diff --git a/cmake/disable-warning b/cmake/disable-warning index b6795e46..c290227a 100755 --- a/cmake/disable-warning +++ b/cmake/disable-warning @@ -8,7 +8,6 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") endif() add_compile_flag("-Wno-address-of-packed-member") add_compile_flag("-Wno-attributes") -add_compile_flag("-Wno-explicit-specialization-storage-class") # add_compile_flag("-w") # 如果你不想编译器输出 warning add_link_flag("-w") # 可恶的链接器警告 diff --git a/doc/src/index.md b/doc/src/index.md index 067ad04b..f6cfc5c9 100644 --- a/doc/src/index.md +++ b/doc/src/index.md @@ -8,6 +8,15 @@ title: 主页 # Welcome to the Plant-OS Document / 欢迎来到 Plant-OS 文档页 +Plant-OS is a simple OS used to study made by several students. + +

+Happy New Year!
+新年快乐! +

+ +

今年是 蛇 年!

+ [The history / Plant-OS 史书](history.md) ## 其它自制 OS 项目 diff --git a/include/pl2d/pixel/mix.hpp b/include/pl2d/pixel/mix.hpp index cf4c2c9f..b5d32fd1 100755 --- a/include/pl2d/pixel/mix.hpp +++ b/include/pl2d/pixel/mix.hpp @@ -102,7 +102,6 @@ auto BasePixelT::mix(const BasePixelT &c1, const BasePixelT &c2) -> BasePixelT { // 假如源和目标都有透明度 template void BasePixelT::mix(const BasePixelT &s) { - if (a == T_MAX) return mix_opaque(s); T2 _a = (T2)T_MAX * (a + s.a) - a * s.a; T2 sw = (T2)T_MAX * s.a; T2 dw = a * ((T2)T_MAX - s.a); @@ -115,7 +114,6 @@ void BasePixelT::mix(const BasePixelT &s) { // 假如源和目标都有透明度 template auto BasePixelT::mix(const BasePixelT &c1, const BasePixelT &c2) -> BasePixelT { - if (c1.a == T_MAX) return mix_opaque(c1, c2); T2 _a = (T2)T_MAX * (c1.a + c2.a) - c1.a * c2.a; T2 w1 = (T2)T_MAX * c1.a; T2 w2 = (T2)T_MAX * c2.a; diff --git a/include/pl2d/texture/paste.hpp b/include/pl2d/texture/paste.hpp index f28d26d9..cd01528f 100755 --- a/include/pl2d/texture/paste.hpp +++ b/include/pl2d/texture/paste.hpp @@ -5,7 +5,8 @@ namespace pl2d { template template -auto BaseTexture::paste_from(const BaseTexture &tex, i32 dx, i32 dy) -> BaseTexture & { +FLATTEN auto BaseTexture::paste_from(const BaseTexture &tex, i32 dx, i32 dy) + -> BaseTexture & { Rect rect = {(i32)tex.width, (i32)tex.height}; rect.trunc(-dx, -dy, (i32)width - dx - 1, (i32)height - dy - 1); #if USE_ITERATOR @@ -24,7 +25,8 @@ auto BaseTexture::paste_from(const BaseTexture &tex, i32 dx, i32 dy) -> B template template -auto BaseTexture::paste_from_mix(const BaseTexture &tex, i32 dx, i32 dy) -> BaseTexture & { +FLATTEN auto BaseTexture::paste_from_mix(const BaseTexture &tex, i32 dx, i32 dy) + -> BaseTexture & { Rect rect = {(i32)tex.width, (i32)tex.height}; rect.trunc(-dx, -dy, (i32)width - dx - 1, (i32)height - dy - 1); #if USE_ITERATOR @@ -43,7 +45,7 @@ auto BaseTexture::paste_from_mix(const BaseTexture &tex, i32 dx, i32 dy) template template -auto BaseTexture::paste_from_opaque(const BaseTexture &tex, i32 dx, i32 dy) +FLATTEN auto BaseTexture::paste_from_opaque(const BaseTexture &tex, i32 dx, i32 dy) -> BaseTexture & { Rect rect = {(i32)tex.width, (i32)tex.height}; rect.trunc(-dx, -dy, (i32)width - dx - 1, (i32)height - dy - 1); diff --git a/src/pl2d/fb/flush-bgr.hpp b/src/pl2d/fb/flush-bgr.hpp index 5c158c06..652e267a 100755 --- a/src/pl2d/fb/flush-bgr.hpp +++ b/src/pl2d/fb/flush-bgr.hpp @@ -1,10 +1,10 @@ #pragma once #include "private.hpp" -namespace pl2d::framebuffer { +namespace { template <> -finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureB &tex, u32 x, u32 y) { +INLINE void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureB &tex, u32 x, u32 y) { byte *_rest fb_p = &fb.pix8[0][y * fb.pitch + x * fb.padding]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; fb_p[0] = tex_p->b; @@ -12,7 +12,7 @@ finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureB &te fb_p[2] = tex_p->r; } template <> -finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureF &tex, u32 x, u32 y) { +INLINE void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureF &tex, u32 x, u32 y) { byte *_rest fb_p = &fb.pix8[0][y * fb.pitch + x * fb.padding]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; fb_p[0] = tex_p->b * 255.f; @@ -20,7 +20,7 @@ finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureF &te fb_p[2] = tex_p->r * 255.f; } template <> -finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureB &tex, u32 x, u32 y) { +INLINE void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureB &tex, u32 x, u32 y) { byte *_rest fb_p = &fb.pix8[0][y * fb.pitch + x * fb.padding]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; tex_p->b = fb_p[0]; @@ -29,7 +29,7 @@ finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureB & tex_p->a = 255; } template <> -finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureF &tex, u32 x, u32 y) { +INLINE void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureF &tex, u32 x, u32 y) { byte *_rest fb_p = &fb.pix8[0][y * fb.pitch + x * fb.padding]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; tex_p->b = fb_p[0] / 255.f; @@ -39,7 +39,7 @@ finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureF & } template <> -finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureB &tex, u32 x, u32 y) { +INLINE void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureB &tex, u32 x, u32 y) { byte *_rest fb_p = &fb.pix8[0][y * fb.pitch + x * fb.padding]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; fb_p[0] = tex_p->b; @@ -48,7 +48,7 @@ finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureB &t fb_p[3] = tex_p->a; } template <> -finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureF &tex, u32 x, u32 y) { +INLINE void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureF &tex, u32 x, u32 y) { byte *_rest fb_p = &fb.pix8[0][y * fb.pitch + x * fb.padding]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; fb_p[0] = tex_p->b * 255.f; @@ -57,8 +57,7 @@ finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureF &t fb_p[3] = tex_p->a * 255.f; } template <> -finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureB &tex, u32 x, - u32 y) { +INLINE void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureB &tex, u32 x, u32 y) { byte *_rest fb_p = &fb.pix8[0][y * fb.pitch + x * fb.padding]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; tex_p->b = fb_p[0]; @@ -67,8 +66,7 @@ finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureB tex_p->a = fb_p[3]; } template <> -finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureF &tex, u32 x, - u32 y) { +INLINE void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureF &tex, u32 x, u32 y) { byte *_rest fb_p = &fb.pix8[0][y * fb.pitch + x * fb.padding]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; tex_p->b = fb_p[0] / 255.f; @@ -78,7 +76,7 @@ finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureF } template <> -finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureB &tex, u32 x, u32 y) { +INLINE void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureB &tex, u32 x, u32 y) { byte *_rest fb_p = &fb.pix8[0][y * fb.pitch + x * fb.padding]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; fb_p[0] = tex_p->a; @@ -87,7 +85,7 @@ finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureB &t fb_p[3] = tex_p->r; } template <> -finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureF &tex, u32 x, u32 y) { +INLINE void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureF &tex, u32 x, u32 y) { byte *_rest fb_p = &fb.pix8[0][y * fb.pitch + x * fb.padding]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; fb_p[0] = tex_p->a * 255.f; @@ -96,8 +94,7 @@ finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureF &t fb_p[3] = tex_p->r * 255.f; } template <> -finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureB &tex, u32 x, - u32 y) { +INLINE void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureB &tex, u32 x, u32 y) { byte *_rest fb_p = &fb.pix8[0][y * fb.pitch + x * fb.padding]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; tex_p->a = fb_p[0]; @@ -106,8 +103,7 @@ finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureB tex_p->r = fb_p[3]; } template <> -finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureF &tex, u32 x, - u32 y) { +INLINE void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureF &tex, u32 x, u32 y) { byte *_rest fb_p = &fb.pix8[0][y * fb.pitch + x * fb.padding]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; tex_p->a = fb_p[0] / 255.f; @@ -116,4 +112,4 @@ finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureF tex_p->r = fb_p[3] / 255.f; } -} // namespace pl2d::framebuffer +} // namespace diff --git a/src/pl2d/fb/flush-cases.hpp b/src/pl2d/fb/flush-cases.hpp index 2f44578a..186879dc 100755 --- a/src/pl2d/fb/flush-cases.hpp +++ b/src/pl2d/fb/flush-cases.hpp @@ -20,7 +20,7 @@ namespace pl2d { } while (0) #define CASE(_name_) \ - case PixFmt::_name_: framebuffer::fb_flush(*this, tex, rect); break + case PixFmt::_name_: ::fb_flush(*this, tex, rect); break auto FrameBuffer::flush(const pl2d::TextureB &tex, const pl2d::Rect &rect) -> int { RUN; } @@ -30,7 +30,7 @@ auto FrameBuffer::flush(const pl2d::TextureF &tex, const pl2d::Rect &rect) -> in #undef CASE #define CASE(_name_) \ - case PixFmt::_name_: framebuffer::fb_copy_to(*this, tex, rect); break + case PixFmt::_name_: ::fb_copy_to(*this, tex, rect); break auto FrameBuffer::copy_to(pl2d::TextureB &tex, const pl2d::Rect &rect) const -> int { RUN; } diff --git a/src/pl2d/fb/flush-loop.hpp b/src/pl2d/fb/flush-loop.hpp index 8b95e235..1f3784ea 100755 --- a/src/pl2d/fb/flush-loop.hpp +++ b/src/pl2d/fb/flush-loop.hpp @@ -1,11 +1,11 @@ #pragma once #include "private.hpp" -namespace pl2d::framebuffer { +namespace { template -static vectorize FLATTEN void fb_flush(FrameBuffer &fb, const pl2d::TextureB &tex, - const pl2d::Rect &rect) { +vectorize FLATTEN void fb_flush(FrameBuffer &fb, const pl2d::TextureB &tex, + const pl2d::Rect &rect) { for (u32 y = rect.y1; y <= rect.y2; y++) { for (u32 x = rect.x1; x <= rect.x2; x++) { fb_flush_pix(fb, tex, x, y); @@ -13,8 +13,8 @@ static vectorize FLATTEN void fb_flush(FrameBuffer &fb, const pl2d::TextureB &te } } template -static vectorize FLATTEN void fb_flush(FrameBuffer &fb, const pl2d::TextureF &tex, - const pl2d::Rect &rect) { +vectorize FLATTEN void fb_flush(FrameBuffer &fb, const pl2d::TextureF &tex, + const pl2d::Rect &rect) { for (u32 y = rect.y1; y <= rect.y2; y++) { for (u32 x = rect.x1; x <= rect.x2; x++) { fb_flush_pix(fb, tex, x, y); @@ -22,8 +22,8 @@ static vectorize FLATTEN void fb_flush(FrameBuffer &fb, const pl2d::TextureF &te } } template -static vectorize FLATTEN void fb_copy_to(const FrameBuffer &fb, pl2d::TextureB &tex, - const pl2d::Rect &rect) { +vectorize FLATTEN void fb_copy_to(const FrameBuffer &fb, pl2d::TextureB &tex, + const pl2d::Rect &rect) { for (u32 y = rect.y1; y <= rect.y2; y++) { for (u32 x = rect.x1; x <= rect.x2; x++) { fb_copy_to_pix(fb, tex, x, y); @@ -31,8 +31,8 @@ static vectorize FLATTEN void fb_copy_to(const FrameBuffer &fb, pl2d::TextureB & } } template -static vectorize FLATTEN void fb_copy_to(const FrameBuffer &fb, pl2d::TextureF &tex, - const pl2d::Rect &rect) { +vectorize FLATTEN void fb_copy_to(const FrameBuffer &fb, pl2d::TextureF &tex, + const pl2d::Rect &rect) { for (u32 y = rect.y1; y <= rect.y2; y++) { for (u32 x = rect.x1; x <= rect.x2; x++) { fb_copy_to_pix(fb, tex, x, y); @@ -40,4 +40,4 @@ static vectorize FLATTEN void fb_copy_to(const FrameBuffer &fb, pl2d::TextureF & } } -} // namespace pl2d::framebuffer +} // namespace diff --git a/src/pl2d/fb/flush-rgb.hpp b/src/pl2d/fb/flush-rgb.hpp index 22e6ab72..b0826a50 100755 --- a/src/pl2d/fb/flush-rgb.hpp +++ b/src/pl2d/fb/flush-rgb.hpp @@ -1,10 +1,10 @@ #pragma once #include "private.hpp" -namespace pl2d::framebuffer { +namespace { template <> -finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureB &tex, u32 x, u32 y) { +INLINE void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureB &tex, u32 x, u32 y) { byte *_rest fb_p = &fb.pix8[0][y * fb.pitch + x * fb.padding]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; fb_p[0] = tex_p->r; @@ -12,7 +12,7 @@ finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureB &te fb_p[2] = tex_p->b; } template <> -finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureF &tex, u32 x, u32 y) { +INLINE void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureF &tex, u32 x, u32 y) { byte *_rest fb_p = &fb.pix8[0][y * fb.pitch + x * fb.padding]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; fb_p[0] = tex_p->r * 255.f; @@ -20,7 +20,7 @@ finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureF &te fb_p[2] = tex_p->b * 255.f; } template <> -finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureB &tex, u32 x, u32 y) { +INLINE void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureB &tex, u32 x, u32 y) { byte *_rest fb_p = &fb.pix8[0][y * fb.pitch + x * fb.padding]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; tex_p->r = fb_p[0]; @@ -29,7 +29,7 @@ finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureB & tex_p->a = 255; } template <> -finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureF &tex, u32 x, u32 y) { +INLINE void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureF &tex, u32 x, u32 y) { byte *_rest fb_p = &fb.pix8[0][y * fb.pitch + x * fb.padding]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; tex_p->r = fb_p[0] / 255.f; @@ -39,7 +39,7 @@ finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureF & } template <> -finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureB &tex, u32 x, u32 y) { +INLINE void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureB &tex, u32 x, u32 y) { byte *_rest fb_p = &fb.pix8[0][y * fb.pitch + x * fb.padding]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; fb_p[0] = tex_p->r; @@ -48,7 +48,7 @@ finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureB &t fb_p[3] = tex_p->a; } template <> -finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureF &tex, u32 x, u32 y) { +INLINE void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureF &tex, u32 x, u32 y) { byte *_rest fb_p = &fb.pix8[0][y * fb.pitch + x * fb.padding]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; fb_p[0] = tex_p->r * 255.f; @@ -57,8 +57,7 @@ finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureF &t fb_p[3] = tex_p->a * 255.f; } template <> -finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureB &tex, u32 x, - u32 y) { +INLINE void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureB &tex, u32 x, u32 y) { byte *_rest fb_p = &fb.pix8[0][y * fb.pitch + x * fb.padding]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; tex_p->r = fb_p[0]; @@ -67,8 +66,7 @@ finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureB tex_p->a = fb_p[3]; } template <> -finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureF &tex, u32 x, - u32 y) { +INLINE void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureF &tex, u32 x, u32 y) { byte *_rest fb_p = &fb.pix8[0][y * fb.pitch + x * fb.padding]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; tex_p->r = fb_p[0] / 255.f; @@ -78,7 +76,7 @@ finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureF } template <> -finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureB &tex, u32 x, u32 y) { +INLINE void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureB &tex, u32 x, u32 y) { byte *_rest fb_p = &fb.pix8[0][y * fb.pitch + x * fb.padding]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; fb_p[0] = tex_p->a; @@ -87,7 +85,7 @@ finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureB &t fb_p[3] = tex_p->b; } template <> -finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureF &tex, u32 x, u32 y) { +INLINE void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureF &tex, u32 x, u32 y) { byte *_rest fb_p = &fb.pix8[0][y * fb.pitch + x * fb.padding]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; fb_p[0] = tex_p->a * 255.f; @@ -96,8 +94,7 @@ finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureF &t fb_p[3] = tex_p->b * 255.f; } template <> -finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureB &tex, u32 x, - u32 y) { +INLINE void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureB &tex, u32 x, u32 y) { byte *_rest fb_p = &fb.pix8[0][y * fb.pitch + x * fb.padding]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; tex_p->a = fb_p[0]; @@ -106,8 +103,7 @@ finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureB tex_p->b = fb_p[3]; } template <> -finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureF &tex, u32 x, - u32 y) { +INLINE void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureF &tex, u32 x, u32 y) { byte *_rest fb_p = &fb.pix8[0][y * fb.pitch + x * fb.padding]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; tex_p->a = fb_p[0] / 255.f; @@ -116,4 +112,4 @@ finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureF tex_p->b = fb_p[3] / 255.f; } -} // namespace pl2d::framebuffer +} // namespace diff --git a/src/pl2d/fb/flush-rgb565.hpp b/src/pl2d/fb/flush-rgb565.hpp index d992ed02..9ed87dcb 100755 --- a/src/pl2d/fb/flush-rgb565.hpp +++ b/src/pl2d/fb/flush-rgb565.hpp @@ -1,11 +1,10 @@ #pragma once #include "private.hpp" -namespace pl2d::framebuffer { +namespace { template <> -finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureB &tex, u32 x, - u32 y) { +INLINE void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureB &tex, u32 x, u32 y) { auto *_rest fb_p = &fb.pix16[0][y * fb.pitch + x]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; u16 r = tex_p->r >> 3; @@ -14,8 +13,7 @@ finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureB *fb_p = little_endian((b << 11) | (g << 5) | r); } template <> -finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureF &tex, u32 x, - u32 y) { +INLINE void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureF &tex, u32 x, u32 y) { auto *_rest fb_p = &fb.pix16[0][y * fb.pitch + x]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; u16 r = (u8)(tex_p->r * 255.f) >> 3; @@ -24,8 +22,8 @@ finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureF *fb_p = little_endian((b << 11) | (g << 5) | r); } template <> -finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureB &tex, u32 x, - u32 y) { +INLINE void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureB &tex, u32 x, + u32 y) { auto value = little_endian(fb.pix16[0][y * fb.pitch + x]); auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; tex_p->r = (value & 0b11111) << 3; @@ -34,8 +32,8 @@ finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::Texture tex_p->a = 255; } template <> -finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureF &tex, u32 x, - u32 y) { +INLINE void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureF &tex, u32 x, + u32 y) { auto value = little_endian(fb.pix16[0][y * fb.pitch + x]); auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; tex_p->r = (value & 0b11111) / 31.f; @@ -45,8 +43,7 @@ finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::Texture } template <> -finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureB &tex, u32 x, - u32 y) { +INLINE void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureB &tex, u32 x, u32 y) { auto *_rest fb_p = &fb.pix16[0][y * fb.pitch + x]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; u16 r = tex_p->r >> 3; @@ -55,8 +52,7 @@ finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureB *fb_p = little_endian((r << 11) | (g << 5) | b); } template <> -finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureF &tex, u32 x, - u32 y) { +INLINE void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureF &tex, u32 x, u32 y) { auto *_rest fb_p = &fb.pix16[0][y * fb.pitch + x]; auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; u16 r = (u8)(tex_p->r * 255.f) >> 3; @@ -65,8 +61,8 @@ finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureF *fb_p = little_endian((r << 11) | (g << 5) | b); } template <> -finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureB &tex, u32 x, - u32 y) { +INLINE void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureB &tex, u32 x, + u32 y) { auto value = little_endian(fb.pix16[0][y * fb.pitch + x]); auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; tex_p->b = (value & 0b11111) << 3; @@ -75,8 +71,8 @@ finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::Texture tex_p->a = 255; } template <> -finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureF &tex, u32 x, - u32 y) { +INLINE void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureF &tex, u32 x, + u32 y) { auto value = little_endian(fb.pix16[0][y * fb.pitch + x]); auto *_rest tex_p = &tex.pixels[y * tex.pitch + x]; tex_p->b = (value & 0b11111) / 31.f; @@ -85,4 +81,4 @@ finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::Texture tex_p->a = 1; } -} // namespace pl2d::framebuffer +} // namespace diff --git a/src/pl2d/fb/private.hpp b/src/pl2d/fb/private.hpp index 12d28849..f5954175 100755 --- a/src/pl2d/fb/private.hpp +++ b/src/pl2d/fb/private.hpp @@ -1,16 +1,18 @@ #pragma once #include -namespace pl2d::framebuffer { +namespace { + +using namespace ::pl2d; template -finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureB &tex, u32 x, u32 y); +INLINE void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureB &tex, u32 x, u32 y); template -finline void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureF &tex, u32 x, u32 y); +INLINE void fb_flush_pix(FrameBuffer &fb, const pl2d::TextureF &tex, u32 x, u32 y); template -finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureB &tex, u32 x, u32 y); +INLINE void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureB &tex, u32 x, u32 y); template -finline void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureF &tex, u32 x, u32 y); +INLINE void fb_copy_to_pix(const FrameBuffer &fb, pl2d::TextureF &tex, u32 x, u32 y); template static void fb_flush(FrameBuffer &fb, const pl2d::TextureB &tex, const pl2d::Rect &rect); @@ -21,4 +23,4 @@ static void fb_copy_to(const FrameBuffer &fb, pl2d::TextureB &tex, const pl2d::R template static void fb_copy_to(const FrameBuffer &fb, pl2d::TextureF &tex, const pl2d::Rect &rect); -} // namespace pl2d::framebuffer +} // namespace diff --git a/test/plui/main.c b/test/plui/main.c index 2e75c707..f6545e81 100755 --- a/test/plui/main.c +++ b/test/plui/main.c @@ -94,6 +94,8 @@ static void init_xlib(u32 width, u32 height) { create_img(width, height); } +static int _cnt = 0; + void screen_flush() { XShmPutImage(display, window, DefaultGC(display, screen), image, 0, 0, 0, 0, screen_width, screen_height, true); @@ -115,8 +117,11 @@ void screen_flush() { old_time = monotonic_us(); } else { u64 time = monotonic_us(); - printf("%lf\n", 1e6 / (time - old_time)); - old_time = time; + if (++_cnt == 10) { + printf("%lf\n", 1e6 / (time - old_time) * 10); + old_time = time; + _cnt = 0; + } } } diff --git a/test/plui/main.cpp b/test/plui/main.cpp index f3d34345..a03ff9df 100755 --- a/test/plui/main.cpp +++ b/test/plui/main.cpp @@ -75,10 +75,10 @@ void flush() { float i = (f32)nframe * .01f; pl2d::PixelF p = {.8f, cpp::cos(i) * .1f, cpp::sin(i) * .1f, 1}; tex.fill(p.copy().LAB2RGB()); - tex.transform([](auto &pix, i32 x, i32 y) INLINE { - f32 k = cpp::sin((x - y + nframe * 4) / 25.f) / 5.f + .8f; - if ((x + y) / 25 % 2 == 0) pix.mix_ratio(pl2d::PixelF{k, k, k}, 64); - }); + // tex.transform([](auto &pix, i32 x, i32 y) INLINE { + // f32 k = cpp::sin((x - y + nframe * 4) / 25.f) / 5.f + .8f; + // if ((x + y) / 25 % 2 == 0) pix.mix_ratio(pl2d::PixelF{k, k, k}, 64); + // }); frame_tex[nframe / 60 % 19].paste_to_mix(tex, 20, 20); image_tex.paste_to_mix(tex, 900, 0); tex.fill_trangle({100, 100}, {200, 200}, {100, 200},