cache optimized rectangle drawing and made sure the methods could be inlined

This commit is contained in:
2026-07-08 13:33:43 -07:00
parent 85cfdaab49
commit 04afd9eee0
9 changed files with 143 additions and 36 deletions
+27 -10
View File
@@ -18,10 +18,10 @@
#include "primatives/triangle.cpp"
// #include "draw.cpp"
#include "shaders/shader.cpp"
#include "shaders/colorshader.cpp"
// #include "shaders/colorshader.cpp"
// #include "shaders/gradientshader.cpp"
#include "shaders/hgradientshader.cpp"
#include "shaders/vgradientshader.cpp"
// #include "shaders/hgradientshader.cpp"
// #include "shaders/vgradientshader.cpp"
// #include "mapper.cpp"
#include <time.h>
@@ -40,8 +40,9 @@ int main(void) {
uint16_t w = 800, h = 480;
// UwU::GradientShader fuchsia = UwU::GradientShader(UwU::Color(0xb00b69ff), UwU::Color(0xb00b6940));
// UwU::ColorShader fuchsia = UwU::ColorShader(UwU::Color(0xb00b69ff));
UwU::VGradientShader fuchsia = UwU::VGradientShader(69, UwU::Color(0xb00b69ff), 420, UwU::Color(0x00000000));
int32_t rectScale = (255 * 65536) / 351;
UwU::Shader fuchsia = UwU::Shader(UwU::Direction::H, 69, 420, UwU::Color(0xb00b69ff), UwU::Color(0x00000000));
UwU::Shader warmup = UwU::Shader(UwU::Color(0xb00b69ff));
// int32_t rectScale = (255 * 65536) / 351;
// rectScale = 41233; //-23806
// UwU::Mapper rectMapper = UwU::Mapper(UwU::Vec2(0, 0), UwU::Vec2(0, 0), UwU::Matrix4(0, 0, 0, 0));
UwU::Color red = UwU::Color(0xff000080);
@@ -57,14 +58,30 @@ int main(void) {
// draw.rectangleGradient(UwU::Coord2(200, 200), UwU::Coord2(600, 400), red, blue, alpha, red);
struct timespec start, end;
const int WARMUP = 100;
const int BATCH = 1000;
const int SAMPLES = 10;
for (int i = 0; i < WARMUP; i++) {
UwU::Trapezoid trapezoid = UwU::Trapezoid(300, 400, 360, 380, 600, 480);
}
long times[SAMPLES];
for (int s = 0; s < SAMPLES; s++) {
clock_gettime(CLOCK_MONOTONIC, &start);
rectangle.draw(surface.buffer, fuchsia);
for (int i = 0; i < BATCH; i++) rectangle.draw(surface.buffer, warmup);
UwU::Trapezoid trapezoid = UwU::Trapezoid(300, 400, 360, 380, 600, 480);
clock_gettime(CLOCK_MONOTONIC, &end);
long elapsed_ns = (end.tv_sec - start.tv_sec) * 1000000000L +
(end.tv_nsec - start.tv_nsec);
printf("Elapsed: %ld ns\n", elapsed_ns);
times[s] = (end.tv_sec - start.tv_sec) * 1000000000L + (end.tv_nsec - start.tv_nsec);
}
long timeAvg = 0;
for (int i = 0; i < SAMPLES; i++) {
timeAvg += times[i];
}
timeAvg /= SAMPLES;
timeAvg /= BATCH;
printf("Elapsed: %ld ns\n", timeAvg);
UwU::Trapezoid trapezoid = UwU::Trapezoid(300, 400, 360, 380, 600, 480);
trapezoid.draw(surface.buffer, red);