From cbf7d23623b5bb2d2092cb6c86bc965138b4ea75 Mon Sep 17 00:00:00 2001 From: vimene Date: Tue, 3 Feb 2026 20:26:01 +0100 Subject: added mipmaps for the hw renderer, improvements This commit add mipmaps, but for now, mipmaps are generated on the gpu at runtime. We should generate them in advance. - added mipmaps for the hardware renderer - renamed stb_image.c to stb_image.cpp - add compiler flag to stb_image.cpp to prevent warning - added pipe notation for various objects to have all clipping functions be left to right. We need this for the time being because dot notation would considerably complicate the current implementation - small improvements --- src/shaders/simple_shaders.hpp | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) (limited to 'src/shaders/simple_shaders.hpp') diff --git a/src/shaders/simple_shaders.hpp b/src/shaders/simple_shaders.hpp index c308ab3..831f969 100644 --- a/src/shaders/simple_shaders.hpp +++ b/src/shaders/simple_shaders.hpp @@ -3,6 +3,7 @@ #include #include +#include #include "fb/pixfb.hpp" #include "math/vector.hpp" #include "math/mat4.hpp" @@ -16,7 +17,7 @@ class SimpleShaders { engine::math::Matrix4 model_mat, view_mat, proj_mat, final_mat; int w, h; - unsigned char* pixels; + std::vector pixels; SimpleShaders(int w, int h, unsigned char* pixels); void set_view(const engine::math::Matrix4& view_mat, const engine::math::Matrix4& proj_mat); @@ -54,27 +55,11 @@ class SimpleShaders { int tx1 = std::clamp(static_cast(txf) + 1, 0, w); int ty0 = std::clamp(static_cast(tyf) + 0, 0, h); int ty1 = std::clamp(static_cast(tyf) + 1, 0, h); - float r00 = static_cast(pixels[(tx0 + ty0 * w) * 4 + 0]) / 255.f; - float r10 = static_cast(pixels[(tx1 + ty0 * w) * 4 + 0]) / 255.f; - float r01 = static_cast(pixels[(tx0 + ty1 * w) * 4 + 0]) / 255.f; - float r11 = static_cast(pixels[(tx1 + ty1 * w) * 4 + 0]) / 255.f; - float r = (1.f - fac_x) * (1.f - fac_y) * r00 + fac_x * (1.f - fac_y) * r10 + (1.f - fac_x) * fac_y * r01 + fac_x * fac_y * r11; - float g00 = static_cast(pixels[(tx0 + ty0 * w) * 4 + 1]) / 255.f; - float g10 = static_cast(pixels[(tx1 + ty0 * w) * 4 + 1]) / 255.f; - float g01 = static_cast(pixels[(tx0 + ty1 * w) * 4 + 1]) / 255.f; - float g11 = static_cast(pixels[(tx1 + ty1 * w) * 4 + 1]) / 255.f; - float g = (1.f - fac_x) * (1.f - fac_y) * g00 + fac_x * (1.f - fac_y) * g10 + (1.f - fac_x) * fac_y * g01 + fac_x * fac_y * g11; - float b00 = static_cast(pixels[(tx0 + ty0 * w) * 4 + 2]) / 255.f; - float b10 = static_cast(pixels[(tx1 + ty0 * w) * 4 + 2]) / 255.f; - float b01 = static_cast(pixels[(tx0 + ty1 * w) * 4 + 2]) / 255.f; - float b11 = static_cast(pixels[(tx1 + ty1 * w) * 4 + 2]) / 255.f; - float b = (1.f - fac_x) * (1.f - fac_y) * b00 + fac_x * (1.f - fac_y) * b10 + (1.f - fac_x) * fac_y * b01 + fac_x * fac_y * b11; - float a00 = static_cast(pixels[(tx0 + ty0 * w) * 4 + 3]) / 255.f; - float a10 = static_cast(pixels[(tx1 + ty0 * w) * 4 + 3]) / 255.f; - float a01 = static_cast(pixels[(tx0 + ty1 * w) * 4 + 3]) / 255.f; - float a11 = static_cast(pixels[(tx1 + ty1 * w) * 4 + 3]) / 255.f; - float a = (1.f - fac_x) * (1.f - fac_y) * a00 + fac_x * (1.f - fac_y) * a10 + (1.f - fac_x) * fac_y * a01 + fac_x * fac_y * a11; - return engine::math::Vector4 { r, g, b, a }; + return + ((1.f - fac_x) * (1.f - fac_y)) * pixels[tx0 + ty0 * w] + + (fac_x * (1.f - fac_y)) * pixels[tx1 + ty0 * w] + + ((1.f - fac_x) * fac_y ) * pixels[tx0 + ty1 * w] + + (fac_x * fac_y ) * pixels[tx1 + ty1 * w]; } }; -- cgit v1.2.3