Fastness with integers

This commit is contained in:
Carlos Sanchez 2024-07-22 20:44:09 -04:00
parent fdde5353c2
commit 4768169ea2

13
main.c
View File

@ -9,6 +9,7 @@
#include "texture.h" #include "texture.h"
typedef uint8_t u8; typedef uint8_t u8;
typedef int32_t i32;
#define CDEPTH 255 #define CDEPTH 255
@ -53,18 +54,18 @@ void drawTexInto(struct texture tex, struct texture buffer, struct rect texbound
rect_dims(bufbounds, &outwidth, &outheight); rect_dims(bufbounds, &outwidth, &outheight);
// We precalculate the step through the texture to avoid division and // We precalculate the step through the texture to avoid division and
// multiplication per pixel // multiplication per pixel
float stepx = (float)texwidth / outwidth; i32 stepx = 256 * (float)texwidth / outwidth;
float stepy = (float)texheight / outheight; i32 stepy = 256 * (float)texheight / outheight;
float texx = texbounds.x1 * 3; i32 texx = 256 * texbounds.x1;
float texy = texbounds.y1 * 3; i32 texy = 256 * texbounds.y1;
//log("%f,%f step %f,%f", texx, texy, stepx, stepy); //log("%f,%f step %f,%f", texx, texy, stepx, stepy);
// Buffer is R G B for each pixel, then across then down. If you want X, Y, // Buffer is R G B for each pixel, then across then down. If you want X, Y,
// it's: 3 * (x + y * width) // it's: 3 * (x + y * width)
for(int y = bufbounds.y1; y < bufbounds.y2; y++) { for(int y = bufbounds.y1; y < bufbounds.y2; y++) {
texx = texbounds.x1; texx = texbounds.x1;
for(int x = bufbounds.x1; x < bufbounds.x2; x++) { for(int x = bufbounds.x1; x < bufbounds.x2; x++) {
int texi = 3 * (floor(texx) + tex.width * floor(texy)); i32 texi = 3 * ((texx >> 8) + tex.width * (texy >> 8));
int bufi = 3 * (x + buffer.width * y); i32 bufi = 3 * (x + buffer.width * y);
// You can get rid of this for loop for more performance, but probably // You can get rid of this for loop for more performance, but probably
// not a big deal with -O3, it'll be unrolled // not a big deal with -O3, it'll be unrolled
for(int i = 0; i < 3; i++) { for(int i = 0; i < 3; i++) {