Ignore:
Timestamp:
Aug 3, 2015, 7:07:03 PM (9 years ago)
Author:
guerin
Message:

raycast: mirror textures

Mirror textures internally to use cache more efficiently. Instead of
accessing columns, we are now accessing rows which are contiguous.

2453934 -> 2364988 cycles/frame (-3.7%) w/ 4 cpus, 512x512

File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/applications/raycast/disp.c

    r683 r684  
    3434// Local functions
    3535
    36 static void dispDrawColumnTex(int x, int y0, int y1, unsigned char *tex, int tx)
     36static void dispDrawColumnTex(int x, int y0, int y1, unsigned char *line)
    3737{
    3838    int y;
     
    4747        int ty = (y - y0) * TEX_SIZE / (y1 - y0);
    4848
    49         buf[cur_buf][y * FBUF_X_SIZE + x] = tex[ty * TEX_SIZE + tx];
     49        buf[cur_buf][y * FBUF_X_SIZE + x] = line[ty];
    5050    }
    5151}
     
    6666}
    6767
    68 static void dispDrawSlice(Game *game, int x, int height, int type, float tx)
     68static void dispDrawSlice(Game *game, int x, int height, int type, int tx)
    6969{
    7070    // Ceiling
     
    8282                          (FBUF_Y_SIZE - height) / 2,
    8383                          (FBUF_Y_SIZE + height) / 2,
    84                           tex,
    85                           (int)(tx * TEX_SIZE));
     84                          &tex[tx * TEX_SIZE]);
    8685    }
    8786    else {
     
    172171}
    173172
     173static void dispMirror(unsigned char *buf, unsigned int size)
     174{
     175    int i, j;
     176    unsigned char pixel;
     177
     178    for (i = 0; i < size; i++) {
     179        for (j = i + 1; j < size; j++) {
     180            int ai = i * size + j;
     181            int bi = j * size + i;
     182
     183            pixel = buf[ai];
     184            buf[ai] = buf[bi];
     185            buf[bi] = pixel;
     186        }
     187    }
     188}
     189
    174190static unsigned char *dispLoadTexture(char *path)
    175191{
     
    186202    giet_fat_read(fd, tex, TEX_SIZE * TEX_SIZE);
    187203    giet_fat_close(fd);
     204
     205    dispMirror(tex, TEX_SIZE);
     206
    188207    giet_tty_printf("[RAYCAST] loaded tex %s\n", path);
    189208
     
    253272
    254273    // Draw ceiling, wall and floor
    255     dispDrawSlice(game, x, FBUF_Y_SIZE / dist, type, tx);
     274    dispDrawSlice(game, x, FBUF_Y_SIZE / dist, type, tx * TEX_SIZE);
    256275
    257276    // Signal this slice is done
Note: See TracChangeset for help on using the changeset viewer.