Skip to content

Commit

Permalink
move changeshader() to renderstate for #241
Browse files Browse the repository at this point in the history
  • Loading branch information
no-lex committed Nov 27, 2022
1 parent 49bf56c commit e294c89
Showing 1 changed file with 99 additions and 97 deletions.
196 changes: 99 additions & 97 deletions src/engine/render/renderva.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,98 @@ namespace

octaentities *shadowmms = nullptr;

struct geombatch
{
const elementset &es;
VSlot &vslot;
int offset;
const vtxarray * const va;
int next, batch;

geombatch(const elementset &es, int offset, const vtxarray *va)
: es(es), vslot(lookupvslot(es.texture)), offset(offset), va(va),
next(-1), batch(-1)
{}

void renderbatch();

int compare(const geombatch &b) const
{
if(va->vbuf < b.va->vbuf)
{
return -1;
}
if(va->vbuf > b.va->vbuf)
{
return 1;
}
if(es.layer&BlendLayer_Bottom)
{
if(!(b.es.layer&BlendLayer_Bottom))
{
return 1;
}
int x1 = va->o.x&~0xFFF,
x2 = b.va->o.x&~0xFFF;
if(x1 < x2)
{
return -1;
}
if(x1 > x2)
{
return 1;
}
int y1 = va->o.y&~0xFFF,
y2 = b.va->o.y&~0xFFF;
if(y1 < y2)
{
return -1;
}
if(y1 > y2)
{
return 1;
}
}
else if(b.es.layer&BlendLayer_Bottom)
{
return -1;
}
if(vslot.slot->shader < b.vslot.slot->shader)
{
return -1;
}
if(vslot.slot->shader > b.vslot.slot->shader)
{
return 1;
}
if(es.texture < b.es.texture)
{
return -1;
}
if(es.texture > b.es.texture)
{
return 1;
}
if(vslot.slot->params.size() < b.vslot.slot->params.size())
{
return -1;
}
if(vslot.slot->params.size() > b.vslot.slot->params.size())
{
return 1;
}
if(es.orient < b.es.orient)
{
return -1;
}
if(es.orient > b.es.orient)
{
return 1;
}
return 0;
}
};

class renderstate
{
public:
Expand Down Expand Up @@ -666,6 +758,8 @@ namespace
void changebatchtmus();
void changeslottmus(int pass, Slot &newslot, VSlot &newvslot);
void bindslottex(int type, Texture *tex, GLenum target = GL_TEXTURE_2D);
void changeshader(int pass, const geombatch &b);

};

void renderstate::disablevbuf()
Expand Down Expand Up @@ -725,98 +819,6 @@ namespace
RenderPass_ReflectiveShadowMapBlend
};

struct geombatch
{
const elementset &es;
VSlot &vslot;
int offset;
const vtxarray * const va;
int next, batch;

geombatch(const elementset &es, int offset, const vtxarray *va)
: es(es), vslot(lookupvslot(es.texture)), offset(offset), va(va),
next(-1), batch(-1)
{}

void renderbatch();

int compare(const geombatch &b) const
{
if(va->vbuf < b.va->vbuf)
{
return -1;
}
if(va->vbuf > b.va->vbuf)
{
return 1;
}
if(es.layer&BlendLayer_Bottom)
{
if(!(b.es.layer&BlendLayer_Bottom))
{
return 1;
}
int x1 = va->o.x&~0xFFF,
x2 = b.va->o.x&~0xFFF;
if(x1 < x2)
{
return -1;
}
if(x1 > x2)
{
return 1;
}
int y1 = va->o.y&~0xFFF,
y2 = b.va->o.y&~0xFFF;
if(y1 < y2)
{
return -1;
}
if(y1 > y2)
{
return 1;
}
}
else if(b.es.layer&BlendLayer_Bottom)
{
return -1;
}
if(vslot.slot->shader < b.vslot.slot->shader)
{
return -1;
}
if(vslot.slot->shader > b.vslot.slot->shader)
{
return 1;
}
if(es.texture < b.es.texture)
{
return -1;
}
if(es.texture > b.es.texture)
{
return 1;
}
if(vslot.slot->params.size() < b.vslot.slot->params.size())
{
return -1;
}
if(vslot.slot->params.size() > b.vslot.slot->params.size())
{
return 1;
}
if(es.orient < b.es.orient)
{
return -1;
}
if(es.orient > b.es.orient)
{
return 1;
}
return 0;
}
};

std::vector<geombatch> geombatches;
int firstbatch = -1,
numbatches = 0;
Expand Down Expand Up @@ -1109,7 +1111,7 @@ namespace
texgenorient = orient;
}

void changeshader(renderstate &cur, int pass, geombatch &b)
void renderstate::changeshader(int pass, const geombatch &b)
{
VSlot &vslot = b.vslot;
Slot &slot = *vslot.slot;
Expand All @@ -1124,9 +1126,9 @@ namespace
rsmworldshader->set(slot, vslot);
}
}
else if(cur.alphaing)
else if(alphaing)
{
slot.shader->setvariant(cur.alphaing > 1 && vslot.refractscale > 0 ? 1 : 0, 1, slot, vslot);
slot.shader->setvariant(alphaing > 1 && vslot.refractscale > 0 ? 1 : 0, 1, slot, vslot);
}
else if(b.es.layer&BlendLayer_Bottom)
{
Expand All @@ -1136,7 +1138,7 @@ namespace
{
slot.shader->set(slot, vslot);
}
cur.globals = GlobalShaderParamState::nextversion;
globals = GlobalShaderParamState::nextversion;
}

template<class T>
Expand Down Expand Up @@ -1223,7 +1225,7 @@ namespace
{
changetexgen(b.es.orient, *b.vslot.slot, b.vslot);
}
changeshader(*this, pass, b);
changeshader(pass, b);
}
else
{
Expand Down

0 comments on commit e294c89

Please sign in to comment.