summaryrefslogtreecommitdiff
path: root/src/engine/octarender.cpp
diff options
context:
space:
mode:
authorxolatile2025-08-05 10:40:01 +0200
committerxolatile2025-08-05 10:40:01 +0200
commita2a16b85572b1d28b0cd4901ea7348750732a740 (patch)
tree6287cdf8331e821f9fe1e0adadc664a59634a812 /src/engine/octarender.cpp
parent6762e292d02e37a69a807e01493d4e14319cca33 (diff)
downloadxolatile-badassbug-a2a16b85572b1d28b0cd4901ea7348750732a740.tar.xz
xolatile-badassbug-a2a16b85572b1d28b0cd4901ea7348750732a740.tar.zst
Few more changes, please do not compile...
Diffstat (limited to 'src/engine/octarender.cpp')
-rw-r--r--src/engine/octarender.cpp200
1 files changed, 8 insertions, 192 deletions
diff --git a/src/engine/octarender.cpp b/src/engine/octarender.cpp
index daa82ea..d577193 100644
--- a/src/engine/octarender.cpp
+++ b/src/engine/octarender.cpp
@@ -16,7 +16,6 @@ enum
{
VBO_VBUF = 0,
VBO_EBUF,
- VBO_SKYBUF,
NUMVBO
};
@@ -65,9 +64,6 @@ void genvbo(int type, void *buf, int len, vtxarray **vas, int numva)
case VBO_EBUF:
va->ebuf = vbo;
break;
- case VBO_SKYBUF:
- va->skybuf = vbo;
- break;
}
}
}
@@ -210,24 +206,16 @@ struct vacollect : verthash
vector<sortkey> texs;
vector<materialsurface> matsurfs;
vector<octaentities *> mapmodels;
- vector<ushort> skyindices, explicitskyindices;
- vector<facebounds> skyfaces[6];
- int worldtris, skytris, skymask, skyclip, skyarea;
+ int worldtris;
void clear()
{
clearverts();
- worldtris = skytris = 0;
- skymask = 0;
- skyclip = INT_MAX;
- skyarea = 0;
+ worldtris = 0;
indices.clear();
- skyindices.setsize(0);
- explicitskyindices.setsize(0);
matsurfs.setsize(0);
mapmodels.setsize(0);
texs.setsize(0);
- loopi(6) skyfaces[i].setsize(0);
}
void remapunlit(vector<sortkey> &remap)
@@ -404,8 +392,7 @@ struct vacollect : verthash
if(va->verts)
{
if(vbosize[VBO_VBUF] + verts.length() > maxvbosize ||
- vbosize[VBO_EBUF] + worldtris > USHRT_MAX ||
- vbosize[VBO_SKYBUF] + skytris > USHRT_MAX)
+ vbosize[VBO_EBUF] + worldtris > USHRT_MAX)
flushvbo();
va->voffset = vbosize[VBO_VBUF];
@@ -423,19 +410,6 @@ struct vacollect : verthash
memcpy(va->matbuf, matsurfs.getbuf(), matsurfs.length()*sizeof(materialsurface));
}
- va->skybuf = 0;
- va->skydata = 0;
- va->sky = skyindices.length();
- va->explicitsky = explicitskyindices.length();
- if(va->sky + va->explicitsky)
- {
- va->skydata += vbosize[VBO_SKYBUF];
- ushort *skydata = (ushort *)addvbo(va, VBO_SKYBUF, va->sky+va->explicitsky, sizeof(ushort));
- memcpy(skydata, skyindices.getbuf(), va->sky*sizeof(ushort));
- memcpy(skydata+va->sky, explicitskyindices.getbuf(), va->explicitsky*sizeof(ushort));
- if(va->voffset) loopi(va->sky+va->explicitsky) skydata[i] += va->voffset;
- }
-
va->eslist = NULL;
va->texs = texs.length();
va->blendtris = 0;
@@ -500,7 +474,7 @@ struct vacollect : verthash
bool emptyva()
{
- return verts.empty() && matsurfs.empty() && skyindices.empty() && explicitskyindices.empty() && mapmodels.empty();
+ return verts.empty() && matsurfs.empty() && mapmodels.empty();
}
} vc;
@@ -580,11 +554,11 @@ extern const vec orientation_bitangent[8][3] =
void addtris(const sortkey &key, int orient, vertex *verts, int *index, int numverts, int convex, int shadowmask, int tj)
{
- int &total = key.tex==DEFAULT_SKY ? vc.skytris : vc.worldtris;
+ int &total = vc.worldtris;
int edge = orient*(MAXFACEVERTS+1);
loopi(numverts-2) if(index[0]!=index[i+1] && index[i+1]!=index[i+2] && index[i+2]!=index[0])
{
- vector<ushort> &idxs = key.tex==DEFAULT_SKY ? vc.explicitskyindices : vc.indices[key].tris[(shadowmask>>i)&1];
+ vector<ushort> &idxs = vc.indices[key].tris[(shadowmask>>i)&1];
int left = index[0], mid = index[i+1], right = index[i+2], start = left, i0 = left, i1 = -1;
loopk(4)
{
@@ -742,7 +716,7 @@ void addcubeverts(VSlot &vslot, int orient, int size, vec *pos, int convex, usho
{
(void) grassy;
int dim = dimension(orient);
- int shadowmask = texture==DEFAULT_SKY || alpha ? 0 : calcshadowmask(pos, numverts);
+ int shadowmask = alpha ? 0 : calcshadowmask(pos, numverts);
LightMap *lm = NULL;
LightMapTexture *lmtex = NULL;
@@ -788,12 +762,6 @@ void addcubeverts(VSlot &vslot, int orient, int size, vec *pos, int convex, usho
if(index[k] < 0) return;
}
- if(texture == DEFAULT_SKY)
- {
- loopk(numverts) vc.skyclip = min(vc.skyclip, int(pos[k].z*8)>>3);
- vc.skymask |= 0x3F&~(1<<orient);
- }
-
if(lmid >= LMID_RESERVED) lmid = lm ? lm->tex : LMID_AMBIENT;
sortkey key(texture, lmid, !vslot.scroll.iszero() ? dim : 3, layer == LAYER_BLEND ? LAYER_BLEND : LAYER_TOP, envmap, alpha ? (vslot.alphaback ? ALPHA_BACK : (vslot.alphafront ? ALPHA_FRONT : NO_ALPHA)) : NO_ALPHA);
@@ -1003,109 +971,6 @@ void gencubeverts(cube &c, const ivec &co, int size, int csi)
}
}
-static inline bool skyoccluded(cube &c, int orient)
-{
- return touchingface(c, orient) && faceedges(c, orient) == F_SOLID;
-}
-
-static int dummyskyfaces[6];
-static inline int hasskyfaces(cube &c, const ivec &co, int size, int faces[6] = dummyskyfaces)
-{
- int numfaces = 0;
- if(isempty(c) || c.material&MAT_ALPHA)
- {
- if(co.x == 0) faces[numfaces++] = O_LEFT;
- if(co.x + size == worldsize) faces[numfaces++] = O_RIGHT;
- if(co.y == 0) faces[numfaces++] = O_BACK;
- if(co.y + size == worldsize) faces[numfaces++] = O_FRONT;
- if(co.z == 0) faces[numfaces++] = O_BOTTOM;
- if(co.z + size == worldsize) faces[numfaces++] = O_TOP;
- }
- else if(!isentirelysolid(c))
- {
- if(co.x == 0 && !skyoccluded(c, O_LEFT)) faces[numfaces++] = O_LEFT;
- if(co.x + size == worldsize && !skyoccluded(c, O_RIGHT)) faces[numfaces++] = O_RIGHT;
- if(co.y == 0 && !skyoccluded(c, O_BACK)) faces[numfaces++] = O_BACK;
- if(co.y + size == worldsize && !skyoccluded(c, O_FRONT)) faces[numfaces++] = O_FRONT;
- if(co.z == 0 && !skyoccluded(c, O_BOTTOM)) faces[numfaces++] = O_BOTTOM;
- if(co.z + size == worldsize && !skyoccluded(c, O_TOP)) faces[numfaces++] = O_TOP;
- }
- return numfaces;
-}
-
-void minskyface(cube &cu, int orient, const ivec &co, int size, facebounds &orig)
-{
- facebounds mincf;
- mincf.u1 = orig.u2;
- mincf.u2 = orig.u1;
- mincf.v1 = orig.v2;
- mincf.v2 = orig.v1;
- mincubeface(cu, orient, co, size, orig, mincf, MAT_ALPHA, MAT_ALPHA);
- orig.u1 = max(mincf.u1, orig.u1);
- orig.u2 = min(mincf.u2, orig.u2);
- orig.v1 = max(mincf.v1, orig.v1);
- orig.v2 = min(mincf.v2, orig.v2);
-}
-
-void genskyfaces(cube &c, const ivec &o, int size)
-{
- int faces[6], numfaces = hasskyfaces(c, o, size, faces);
- if(!numfaces) return;
-
- loopi(numfaces)
- {
- int orient = faces[i], dim = dimension(orient);
- facebounds m;
- m.u1 = (o[C[dim]]&0xFFF)<<3;
- m.u2 = m.u1 + (size<<3);
- m.v1 = (o[R[dim]]&0xFFF)<<3;
- m.v2 = m.v1 + (size<<3);
- minskyface(c, orient, o, size, m);
- if(m.u1 >= m.u2 || m.v1 >= m.v2) continue;
- vc.skyarea += (int(m.u2-m.u1)*int(m.v2-m.v1) + (1<<(2*3))-1)>>(2*3);
- vc.skyfaces[orient].add(m);
- }
-}
-
-void addskyverts(const ivec &o, int size)
-{
- loopi(6)
- {
- int dim = dimension(i), c = C[dim], r = R[dim];
- vector<facebounds> &sf = vc.skyfaces[i];
- if(sf.empty()) continue;
- vc.skymask |= 0x3F&~(1<<opposite(i));
- sf.setsize(mergefaces(i, sf.getbuf(), sf.length()));
- loopvj(sf)
- {
- facebounds &m = sf[j];
- int index[4];
- loopk(4)
- {
- const ivec &coords = facecoords[opposite(i)][k];
- vec v;
- v[dim] = o[dim];
- if(coords[dim]) v[dim] += size;
- v[c] = (o[c]&~0xFFF) + (coords[c] ? m.u2 : m.u1)/8.0f;
- v[r] = (o[r]&~0xFFF) + (coords[r] ? m.v2 : m.v1)/8.0f;
- index[k] = vc.addvert(v);
- if(index[k] < 0) goto nextskyface;
- vc.skyclip = min(vc.skyclip, int(v.z*8)>>3);
- }
- if(vc.skytris + 6 > USHRT_MAX) break;
- vc.skytris += 6;
- vc.skyindices.add(index[0]);
- vc.skyindices.add(index[1]);
- vc.skyindices.add(index[2]);
-
- vc.skyindices.add(index[0]);
- vc.skyindices.add(index[2]);
- vc.skyindices.add(index[3]);
- nextskyface:;
- }
- }
-}
-
////////// Vertex Arrays //////////////
int allocva = 0;
@@ -1120,9 +985,6 @@ vtxarray *newva(const ivec &co, int size)
va->parent = NULL;
va->o = co;
va->size = size;
- va->skyarea = vc.skyarea;
- va->skyfaces = vc.skymask;
- va->skyclip = vc.skyclip < INT_MAX ? vc.skyclip : INT_MAX;
va->curvfc = VFC_NOT_VISIBLE;
va->occluded = OCCLUDE_NOTHING;
va->query = NULL;
@@ -1160,7 +1022,6 @@ void destroyva(vtxarray *va, bool reparent)
}
if(va->vbuf) destroyvbo(va->vbuf);
if(va->ebuf) destroyvbo(va->ebuf);
- if(va->skybuf) destroyvbo(va->skybuf);
if(va->eslist) delete[] va->eslist;
if(va->matbuf) delete[] va->matbuf;
delete va;
@@ -1203,23 +1064,6 @@ void updatevabb(vtxarray *va, bool force)
}
va->bbmin.max(va->o);
va->bbmax.min(ivec(va->o).add(va->size));
-
- if(va->skyfaces)
- {
- va->skyfaces |= 0x80;
- if(va->sky) loop(dim, 3) if(va->skyfaces&(3<<(2*dim)))
- {
- int r = R[dim], c = C[dim];
- if((va->skyfaces&(1<<(2*dim)) && va->o[dim] < va->bbmin[dim]) ||
- (va->skyfaces&(2<<(2*dim)) && va->o[dim]+va->size > va->bbmax[dim]) ||
- va->o[r] < va->bbmin[r] || va->o[r]+va->size > va->bbmax[r] ||
- va->o[c] < va->bbmin[c] || va->o[c]+va->size > va->bbmax[c])
- {
- va->skyfaces &= ~0x80;
- break;
- }
- }
- }
}
void updatevabbs(bool force)
@@ -1368,8 +1212,6 @@ void rendercube(cube &c, const ivec &co, int size, int csi, int &maxlevel) // c
return;
}
- genskyfaces(c, co, size);
-
if(!isempty(c))
{
gencubeverts(c, co, size, csi);
@@ -1408,16 +1250,6 @@ void calcmatbb(const ivec &co, int size, ivec &bbmin, ivec &bbmax)
loopv(vc.matsurfs)
{
materialsurface &m = vc.matsurfs[i];
- switch(m.material&MATF_VOLUME)
- {
- case MAT_WATER:
- case MAT_GLASS:
- case MAT_LAVA:
- break;
-
- default:
- continue;
- }
int dim = dimension(m.orient),
r = R[dim],
@@ -1453,8 +1285,6 @@ void setva(cube &c, const ivec &co, int size, int csi)
calcgeombb(co, size, bbmin, bbmax);
- addskyverts(co, size);
-
if(size == min(0x1000, worldsize/2) || !vc.emptyva())
{
vtxarray *va = newva(co, size);
@@ -1491,7 +1321,7 @@ static inline int setcubevisibility(cube &c, const ivec &co, int size)
else
{
numvis++;
- if(c.texture[i] != DEFAULT_SKY && !(c.ext && c.ext->surfaces[i].numverts&MAXFACEVERTS)) checkmask |= 1<<i;
+ if(!(c.ext && c.ext->surfaces[i].numverts&MAXFACEVERTS)) checkmask |= 1<<i;
}
}
if(facemask&2 && collideface(c, i)) collidemask |= 1<<i;
@@ -1526,7 +1356,6 @@ int updateva(cube *c, const ivec &co, int size, int csi)
else
{
if(!isempty(c[i])) count += setcubevisibility(c[i], o, size);
- count += hasskyfaces(c[i], o, size);
}
int tcount = count + (csi <= MAXMERGELEVEL ? vamerges[csi].length() : 0);
if(tcount > vafacemax || (tcount >= vafacemin && size >= vacubesize) || size == min(0x1000, worldsize/2))
@@ -1648,15 +1477,6 @@ void octarender() // creates va s for all leaf cubes that don't already
loadprogress = 0;
flushvbo();
- explicitsky = 0;
- skyarea = 0;
- loopv(valist)
- {
- vtxarray *va = valist[i];
- explicitsky += va->explicitsky;
- skyarea += va->skyarea;
- }
-
visibleva = NULL;
}
@@ -1682,10 +1502,6 @@ void allchanged(bool load)
clearvas(worldroot);
resetqueries();
resetclipplanes();
- if(load)
- {
- setupsky();
- }
guessshadowdir();
entitiesinoctanodes();
tjoints.setsize(0);