ref: a8a766f53153710122d2fd1d9a8f53059d254c38
parent: d1fec3d8bcbd0e2d1ec505e45fbf59bb5676ce83
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Sun Dec 10 17:40:39 EST 2023
textures: data -> pixels and reduce "offsets"-related noise
--- a/d_edge.c
+++ b/d_edge.c
@@ -129,7 +129,7 @@
}else if(s->flags & SURF_DRAWTURB){
pface = s->data;
miplevel = 0;
- cacheblock = (pixel_t *)((byte *)pface->texinfo->texture + pface->texinfo->texture->offsets[0]);
+ cacheblock = pface->texinfo->texture->pixels + pface->texinfo->texture->offsets[0];
cachewidth = 64;
if(s->insubmodel){
@@ -183,7 +183,7 @@
// FIXME: make this passed in to D_CacheSurface
pcurrentcache = D_CacheSurface(pface, miplevel);
- cacheblock = (pixel_t *)pcurrentcache->data;
+ cacheblock = pcurrentcache->pixels;
cachewidth = pcurrentcache->width;
D_CalcGradients(pface, transformed_modelorg);
--- a/d_local.h
+++ b/d_local.h
@@ -24,7 +24,7 @@
int height; // DEBUG only needed for debug
float mipscale;
struct texture_s *texture; // checked for animating textures
- pixel_t data[]; // width*height elements
+ pixel_t pixels[]; // width*height elements
} surfcache_t;
// !!! if this is changed, it must be changed in asm_draw.h too !!!
--- a/d_surf.c
+++ b/d_surf.c
@@ -222,7 +222,7 @@
cache->dlight = surface->dlightframe == r_framecount;
- r_drawsurf.surfdat = (pixel_t *)cache->data;
+ r_drawsurf.surfdat = cache->pixels;
cache->texture = r_drawsurf.texture;
cache->lightadj[0] = r_drawsurf.lightadj[0];
--- a/draw.c
+++ b/draw.c
@@ -64,7 +64,7 @@
q->height = LittleLong(q->height);
n = q->width*q->height;
q = Cache_Realloc(&pic->cache, sizeof(*q)+n*sizeof(pixel_t));
- torgbx((byte*)q->data, q->data, n);
+ torgbx((byte*)q->pixels, q->pixels, n);
return q;
}
@@ -96,7 +96,7 @@
fatal("Draw_Init: %s", lerr());
r_rectdesc.width = draw_backtile->width;
r_rectdesc.height = draw_backtile->height;
- r_rectdesc.ptexpixels = draw_backtile->data;
+ r_rectdesc.ptexpixels = draw_backtile->pixels;
r_rectdesc.rowbytes = draw_backtile->width;
}
@@ -185,7 +185,7 @@
{
fatal ("Draw_Pic: bad coordinates");
}
- source = pic->data;
+ source = pic->pixels;
dest = vid.buffer + y * vid.rowbytes + x;
for(py = 0; py < pic->height; py++){
for(px = 0; px < pic->width; px++){
@@ -211,7 +211,7 @@
if (x < 0 || y < 0 || x+pic->width > vid.width || y+pic->height > vid.height)
fatal ("Draw_TransPic: bad coordinates");
- source = pic->data;
+ source = pic->pixels;
dest = vid.buffer + y * vid.rowbytes + x;
if(pic->width & 7){ // general
for(v=0; v<pic->height; v++){
@@ -261,7 +261,7 @@
if (x < 0 || y < 0 || x+pic->width > vid.width || y+pic->height > vid.height)
fatal ("Draw_TransPic: bad coordinates");
- source = pic->data;
+ source = pic->pixels;
dest = vid.buffer + y * vid.rowbytes + x;
if (pic->width & 7){ // general
for(v=0; v<pic->height; v++){
@@ -338,7 +338,7 @@
// hack the version number directly into the pic
sprint (ver, "(9)quake %4.2f", (float)VERSION);
- dest = conback->data + 320*186 + 320 - 11 - 8*strlen(ver);
+ dest = conback->pixels + 320*186 + 320 - 11 - 8*strlen(ver);
n = strlen(ver);
for (x=0 ; x<n ; x++)
@@ -346,7 +346,7 @@
dest = vid.conbuffer;
for(y=0; y<lines; y++, dest+=vid.conrowbytes){
v = (vid.conheight - lines + y) * 200 / vid.conheight;
- src = conback->data + v * 320;
+ src = conback->pixels + v * 320;
if(vid.conwidth == 320)
memcpy(dest, src, vid.conwidth*sizeof(pixel_t));
else{
--- a/model.h
+++ b/model.h
@@ -53,7 +53,7 @@
struct texture_s *anim_next; // in the animation sequence
struct texture_s *alternate_anims; // bmodels in frmae 1 use these
int offsets[MIPLEVELS]; // four mip maps stored
- pixel_t data[];
+ pixel_t pixels[];
} texture_t;
enum {
--- a/model_bsp.c
+++ b/model_bsp.c
@@ -110,12 +110,12 @@
strncpy(tx->name, (char*)in0+off, sizeof(tx->name)-1);
tx->name[sizeof(tx->name)-1] = 0;
for(j = 0; j < MIPLEVELS; j++)
- tx->offsets[j] = sizeof(texture_t) + (le32(p) - (16+2*4+4*4))*sizeof(pixel_t);
+ tx->offsets[j] = le32(p) - (16+2*4+4*4);
mod->textures[i] = tx;
tx->width = w;
tx->height = h;
// the pixels immediately follow the structures
- torgbx(p, (pixel_t*)(tx+1), pixels);
+ torgbx(p, tx->pixels, pixels);
if(strncmp(tx->name, "sky", 3) == 0)
R_InitSky(tx);
}
--- a/model_bsp30.c
+++ b/model_bsp30.c
@@ -153,16 +153,16 @@
strncpy(tx->name, (char*)in0+off, sizeof(tx->name)-1);
tx->name[sizeof(tx->name)-1] = 0;
for(j = 0; j < MIPLEVELS; j++)
- tx->offsets[j] = sizeof(texture_t) + (le32(p) - (16+2*4+4*4))*sizeof(pixel_t);
+ tx->offsets[j] = le32(p) - (16+2*4+4*4);
mod->textures[i] = tx;
tx->width = w;
tx->height = h;
- if(tx->offsets[0] > 0){
+ if(tx->offsets[0] >= 0){
// the pixels immediately follow the structures
x = p + pixels;
palsz = le16(x);
if(palsz == 256)
- pal3torgbx(p, tx->data, pixels, x);
+ pal3torgbx(p, tx->pixels, pixels, x);
}else{
// alternative: outside, in a wad
for(j = 0; j < mod->numwads; j++){
--- a/r_main.c
+++ b/r_main.c
@@ -109,14 +109,14 @@
r_notexture_mip = Hunk_Alloc((16*16+8*8+4*4+2*2)*sizeof(pixel_t) + sizeof *r_notexture_mip);
r_notexture_mip->width = r_notexture_mip->height = 16;
- r_notexture_mip->offsets[0] = sizeof(*r_notexture_mip);
- r_notexture_mip->offsets[1] = r_notexture_mip->offsets[0] + 16*16*sizeof(pixel_t);
- r_notexture_mip->offsets[2] = r_notexture_mip->offsets[1] + 8*8*sizeof(pixel_t);
- r_notexture_mip->offsets[3] = r_notexture_mip->offsets[2] + 4*4*sizeof(pixel_t);
+ r_notexture_mip->offsets[0] = 0;
+ r_notexture_mip->offsets[1] = r_notexture_mip->offsets[0] + 16*16;
+ r_notexture_mip->offsets[2] = r_notexture_mip->offsets[1] + 8*8;
+ r_notexture_mip->offsets[3] = r_notexture_mip->offsets[2] + 4*4;
for (m=0 ; m<4 ; m++)
{
- dest = (pixel_t*)((byte*)r_notexture_mip + r_notexture_mip->offsets[m]);
+ dest = r_notexture_mip->pixels + r_notexture_mip->offsets[m];
for (y=0 ; y< (16>>m) ; y++)
for (x=0 ; x< (16>>m) ; x++, dest++)
{
--- a/r_sky.c
+++ b/r_sky.c
@@ -26,7 +26,7 @@
return;
}
- src = mt->data + mt->offsets[0];
+ src = mt->pixels + mt->offsets[0];
w = mt->width;
skyh = mt->height;
if(w == skyh){ // probably without a mask?
@@ -34,7 +34,7 @@
n = skyw*skyh;
r_skysource[0] = Hunk_Alloc(n*sizeof(pixel_t));
r_skysource[1] = r_skysource[0];
- memmove(r_skysource[0], src, n);
+ memmove(r_skysource[0], src, n*sizeof(pixel_t));
return;
}
skyw = w/2;
--- a/r_surf.c
+++ b/r_surf.c
@@ -220,7 +220,7 @@
mt = r_drawsurf.texture;
- r_source = (pixel_t*)((byte*)mt + mt->offsets[r_drawsurf.surfmip]);
+ r_source = mt->pixels + mt->offsets[r_drawsurf.surfmip];
// the fractional light values should range from 0 to (VID_GRADES - 1) << 16
// from a source range of 0 - 255
--- a/wad.c
+++ b/wad.c
@@ -142,11 +142,11 @@
if(wad->ver == WAD_VER2){
for(i = 0; i < n; i++)
- q->data[i] = q1pal[p[i]];
+ q->pixels[i] = q1pal[p[i]];
}else if(wad->ver == WAD_VER3 && palsz > 0){
for(i = 0; i < n; i++){
j = (*p++)*3;
- q->data[i] = j < palsz*3 ? (0xff<<24 | pal[j+0]<<16 | pal[j+1]<<8 | pal[j+2]) : 0;
+ q->pixels[i] = j < palsz*3 ? (0xff<<24 | pal[j+0]<<16 | pal[j+1]<<8 | pal[j+2]) : 0;
}
}
@@ -208,7 +208,7 @@
}
n = w*h*85/64;
for(i = 0; i < nelem(t->offsets); i++)
- t->offsets[i] = sizeof(texture_t) + (le32(p) - (16+2*4+4*4))*sizeof(pixel_t);
+ t->offsets[i] = le32(p) - (16+2*4+4*4);
off = p - wad->in;
if((n = W_ReadPixelsAt(wad, off, lmp->off+lmp->sz-off, (pixel_t*)(t+1), n)) < 0)
werrstr("%s: %s", name, lerr());
--- a/wad.h
+++ b/wad.h
@@ -5,7 +5,7 @@
{
int width;
int height;
- pixel_t data[];
+ pixel_t pixels[];
}qpic_t;
struct texture_s;