From 43f16ac62596765dd4e135d019603709c8993602 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 10 Mar 2026 19:30:09 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20[performance=20improvement]?= =?UTF-8?q?=20Optimize=20texture=20sampling=20std::floor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/soft_render/core/texture.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/soft_render/core/texture.hpp b/include/soft_render/core/texture.hpp index e7ee146..fd54895 100644 --- a/include/soft_render/core/texture.hpp +++ b/include/soft_render/core/texture.hpp @@ -34,8 +34,8 @@ class Texture { if (width_ == 0 || height_ == 0) return {1, 1, 1}; // Wrap - u = u - std::floor(u); - v = v - std::floor(v); + int iu = static_cast(u); u = u - static_cast(iu - (iu > u)); + int iv = static_cast(v); v = v - static_cast(iv - (iv > v)); float fx = u * (width_ - 1); float fy = v * (height_ - 1); @@ -58,8 +58,8 @@ class Texture { // Nearest-neighbor (faster) math::Color sampleNearest(float u, float v) const { if (width_ == 0 || height_ == 0) return {1, 1, 1}; - u = u - std::floor(u); - v = v - std::floor(v); + int iu = static_cast(u); u = u - static_cast(iu - (iu > u)); + int iv = static_cast(v); v = v - static_cast(iv - (iv > v)); int x = static_cast(u * width_) % width_; int y = static_cast(v * height_) % height_; return fetch(x, y);