1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-06-25 22:09:35 +00:00

Refactor: remove usesT0 usesT1 usesShadeColor from CombinerInfo class and make them

methods of ShaderCombiner.
This commit is contained in:
Sergey Lipskiy 2014-09-02 21:59:48 +07:00
parent 7b3423d7de
commit 3de0809322
5 changed files with 49 additions and 61 deletions

View File

@ -126,13 +126,11 @@ void SimplifyCycle( CombineCycle *cc, CombinerStage *stage )
stage->numOps = 1;
// If we're just subtracting zero, skip it
if (cc->sb != ZERO)
{
if (cc->sb != ZERO) {
// Subtracting a number from itself is zero
if (cc->sb == stage->op[0].param1)
stage->op[0].param1 = ZERO;
else
{
else {
stage->op[1].op = SUB;
stage->op[1].param1 = cc->sb;
stage->numOps++;
@ -140,22 +138,17 @@ void SimplifyCycle( CombineCycle *cc, CombinerStage *stage )
}
// If we either subtracted, or didn't load a zero
if ((stage->numOps > 1) || (stage->op[0].param1 != ZERO))
{
if ((stage->numOps > 1) || (stage->op[0].param1 != ZERO)) {
// Multiplying by zero is zero
if (cc->m == ZERO)
{
if (cc->m == ZERO) {
stage->numOps = 1;
stage->op[0].op = LOAD;
stage->op[0].param1 = ZERO;
}
else
{
} else {
// Multiplying by one, so just do a load
if ((stage->numOps == 1) && (stage->op[0].param1 == ONE))
stage->op[0].param1 = cc->m;
else
{
else {
stage->op[stage->numOps].op = MUL;
stage->op[stage->numOps].param1 = cc->m;
stage->numOps++;
@ -164,13 +157,11 @@ void SimplifyCycle( CombineCycle *cc, CombinerStage *stage )
}
// Don't bother adding zero
if (cc->a != ZERO)
{
if (cc->a != ZERO) {
// If all we have so far is zero, then load this instead
if ((stage->numOps == 1) && (stage->op[0].param1 == ZERO))
stage->op[0].param1 = cc->a;
else
{
else {
stage->op[stage->numOps].op = ADD;
stage->op[stage->numOps].param1 = cc->a;
stage->numOps++;
@ -178,8 +169,7 @@ void SimplifyCycle( CombineCycle *cc, CombinerStage *stage )
}
// Handle interpolation
if ((stage->numOps == 4) && (stage->op[1].param1 == stage->op[3].param1))
{
if ((stage->numOps == 4) && (stage->op[1].param1 == stage->op[3].param1)) {
stage->numOps = 1;
stage->op[0].op = INTER;
stage->op[0].param2 = stage->op[1].param1;
@ -197,14 +187,11 @@ ShaderCombiner * CombinerInfo::_compile(u64 mux) const
Combiner color, alpha;
if (gDP.otherMode.cycleType == G_CYC_2CYCLE)
{
if (gDP.otherMode.cycleType == G_CYC_2CYCLE) {
numCycles = 2;
color.numStages = 2;
alpha.numStages = 2;
}
else
{
} else {
numCycles = 1;
color.numStages = 1;
alpha.numStages = 1;
@ -232,8 +219,7 @@ ShaderCombiner * CombinerInfo::_compile(u64 mux) const
ac[1].m = mAExpanded[combine.mA1];
ac[1].a = aAExpanded[combine.aA1];
for (int i = 0; i < numCycles; i++)
{
for (int i = 0; i < numCycles; i++) {
// Simplify each RDP combiner cycle into a combiner stage
SimplifyCycle( &cc[i], &color.stage[i] );
SimplifyCycle( &ac[i], &alpha.stage[i] );
@ -242,22 +228,22 @@ ShaderCombiner * CombinerInfo::_compile(u64 mux) const
return new ShaderCombiner( color, alpha, combine );
}
void CombinerInfo::setCombine( u64 mux )
void CombinerInfo::setCombine(u64 _mux )
{
if (m_pCurrent != NULL && m_pCurrent->getMux() == mux) {
changed = false;
if (m_pCurrent != NULL && m_pCurrent->getMux() == _mux) {
m_bChanged = false;
m_pCurrent->Update();
return;
}
Combiners::const_iterator iter = m_combiners.find(mux);
Combiners::const_iterator iter = m_combiners.find(_mux);
if (iter != m_combiners.end())
m_pCurrent = iter->second;
else {
m_pCurrent = _compile(mux);
m_combiners[mux] = m_pCurrent;
m_pCurrent = _compile(_mux);
m_combiners[_mux] = m_pCurrent;
}
m_pCurrent->Update();
changed = true;
m_bChanged = true;
gDP.changed |= CHANGED_COMBINE_COLORS;
}

View File

@ -118,24 +118,24 @@ class CombinerInfo
{
public:
void init();
void setCombine( u64 mux );
void destroy();
void setCombine(u64 _mux);
ShaderCombiner * getCurrent() const {return m_pCurrent;}
bool isChanged() const {return m_bChanged;}
static CombinerInfo & get() {
static CombinerInfo info;
return info;
}
ShaderCombiner * getCurrent() const {return m_pCurrent;}
bool usesT0, usesT1, usesLOD, usesShadeColor, changed;
private:
CombinerInfo() :
m_pCurrent(NULL), usesT0(false), usesT1(false),
usesShadeColor(false), changed(false) {}
CombinerInfo() : m_pCurrent(NULL), m_bChanged(false) {}
CombinerInfo(const CombinerInfo &);
ShaderCombiner * _compile(u64 mux) const;
bool m_bChanged;
ShaderCombiner * m_pCurrent;
typedef std::map<u64, ShaderCombiner *> Combiners;
Combiners m_combiners;

View File

@ -555,11 +555,6 @@ void ShaderCombiner::_locate_attributes() const {
}
void ShaderCombiner::Update() {
CombinerInfo::get().usesT0 = (m_nInputs & ((1<<TEXEL0)|(1<<TEXEL0_ALPHA))) != 0;
CombinerInfo::get().usesT1 = (m_nInputs & ((1<<TEXEL1)|(1<<TEXEL1_ALPHA))) != 0;
CombinerInfo::get().usesLOD = (m_nInputs & (1<<LOD_FRACTION)) != 0;
CombinerInfo::get().usesShadeColor = (m_nInputs & ((1<<SHADE)|(1<<SHADE_ALPHA))) != 0;
glUseProgram(m_program);
_setIUniform(m_uniforms.uTex0, 0, true);
@ -602,7 +597,7 @@ void ShaderCombiner::UpdateColors(bool _bForce) {
_setFUniform(m_uniforms.uK4, gDP.convert.k4*0.0039215689f, _bForce);
_setFUniform(m_uniforms.uK5, gDP.convert.k5*0.0039215689f, _bForce);
if (CombinerInfo::get().usesLOD) {
if (usesLOD()) {
int uCalcLOD = (config.enableLOD && gDP.otherMode.textureLOD == G_TL_LOD) ? 1 : 0;
_setIUniform(m_uniforms.uEnableLod, uCalcLOD, _bForce);
if (uCalcLOD) {
@ -629,7 +624,7 @@ void ShaderCombiner::UpdateTextureInfo(bool _bForce) {
_setIUniform(m_uniforms.uTexturePersp, gDP.otherMode.texturePersp, _bForce);
_setFV2Uniform(m_uniforms.uTexScale, gSP.texture.scales, gSP.texture.scalet, _bForce);
int nFB0 = 0, nFB1 = 0;
if (CombinerInfo::get().usesT0) {
if (usesT0()) {
if (gSP.textureTile[0]) {
_setFV2Uniform(m_uniforms.uTexOffset[0], gSP.textureTile[0]->fuls, gSP.textureTile[0]->fult, _bForce);
_setFV2Uniform(m_uniforms.uTexMask[0],
@ -645,7 +640,7 @@ void ShaderCombiner::UpdateTextureInfo(bool _bForce) {
}
}
if (CombinerInfo::get().usesT1) {
if (usesT1()) {
if (gSP.textureTile[1]) {
_setFV2Uniform(m_uniforms.uTexOffset[1], gSP.textureTile[1]->fuls, gSP.textureTile[1]->fult, _bForce);
_setFV2Uniform(m_uniforms.uTexMask[1],

View File

@ -7,6 +7,7 @@ class ShaderCombiner {
public:
ShaderCombiner(Combiner & _color, Combiner & _alpha, const gDPCombine & _combine);
~ShaderCombiner();
void Update();
void UpdateColors(bool _bForce = false);
void UpdateFBInfo(bool _bForce = false);
@ -15,8 +16,14 @@ public:
void UpdateTextureInfo(bool _bForce = false);
void UpdateRenderState(bool _bForce = false);
void UpdateLight(bool _bForce = false);
u64 getMux() const {return m_combine.mux;}
bool usesT0() const {return (m_nInputs & ((1<<TEXEL0)|(1<<TEXEL0_ALPHA))) != 0;}
bool usesT1() const {return (m_nInputs & ((1<<TEXEL1)|(1<<TEXEL1_ALPHA))) != 0;}
bool usesLOD() const {return (m_nInputs & (1<<LOD_FRACTION)) != 0;}
bool usesShadeColor() const {return (m_nInputs & ((1<<SHADE)|(1<<SHADE_ALPHA))) != 0;}
private:
struct iUniform {GLint loc; int val;};
struct fUniform {GLint loc; float val;};

View File

@ -811,14 +811,14 @@ void OGL_UpdateStates()
//For some reason updating the texture cache on the first frame of LOZ:OOT causes a NULL Pointer exception...
if (CombinerInfo::get().getCurrent() != NULL)
{
if (CombinerInfo::get().usesT0)
if (CombinerInfo::get().getCurrent()->usesT0())
TextureCache_Update(0);
else
TextureCache_ActivateDummy(0);
//Note: enabling dummies makes some F-zero X textures flicker.... strange.
if (CombinerInfo::get().usesT1)
if (CombinerInfo::get().getCurrent()->usesT1())
TextureCache_Update(1);
else
TextureCache_ActivateDummy(1);
@ -900,7 +900,7 @@ void OGL_AddTriangle(int v0, int v1, int v2)
void OGL_SetColorArray()
{
if (CombinerInfo::get().usesShadeColor)
if (CombinerInfo::get().getCurrent()->usesShadeColor())
glEnableVertexAttribArray(SC_COLOR);
else
glDisableVertexAttribArray(SC_COLOR);
@ -908,17 +908,17 @@ void OGL_SetColorArray()
void OGL_SetTexCoordArrays()
{
if (CombinerInfo::get().usesT0)
if (CombinerInfo::get().getCurrent()->usesT0())
glEnableVertexAttribArray(SC_TEXCOORD0);
else
glDisableVertexAttribArray(SC_TEXCOORD0);
if (CombinerInfo::get().usesT1)
if (CombinerInfo::get().getCurrent()->usesT1())
glEnableVertexAttribArray(SC_TEXCOORD1);
else
glDisableVertexAttribArray(SC_TEXCOORD1);
if (OGL.renderState == GLInfo::rsTriangle && (CombinerInfo::get().usesT0 || CombinerInfo::get().usesT1))
if (OGL.renderState == GLInfo::rsTriangle && (CombinerInfo::get().getCurrent()->usesT0() || CombinerInfo::get().getCurrent()->usesT1()))
glEnableVertexAttribArray(SC_STSCALED);
else
glDisableVertexAttribArray(SC_STSCALED);
@ -937,7 +937,7 @@ void OGL_DrawTriangles()
OGL_UpdateStates();
const bool updateArrays = OGL.renderState != GLInfo::rsTriangle;
if (updateArrays || CombinerInfo::get().changed) {
if (updateArrays || CombinerInfo::get().isChanged()) {
OGL.renderState = GLInfo::rsTriangle;
OGL_SetColorArray();
OGL_SetTexCoordArrays();
@ -975,7 +975,7 @@ void OGL_DrawLine(int v0, int v1, float width )
if (gSP.changed || gDP.changed)
OGL_UpdateStates();
if (OGL.renderState != GLInfo::rsLine || CombinerInfo::get().changed) {
if (OGL.renderState != GLInfo::rsLine || CombinerInfo::get().isChanged()) {
OGL_SetColorArray();
glDisableVertexAttribArray(SC_TEXCOORD0);
glDisableVertexAttribArray(SC_TEXCOORD1);
@ -1001,7 +1001,7 @@ void OGL_DrawRect( int ulx, int uly, int lrx, int lry, float *color )
OGL_UpdateStates();
const bool updateArrays = OGL.renderState != GLInfo::rsRect;
if (updateArrays || CombinerInfo::get().changed) {
if (updateArrays || CombinerInfo::get().isChanged()) {
OGL.renderState = GLInfo::rsRect;
glDisableVertexAttribArray(SC_COLOR);
glDisableVertexAttribArray(SC_TEXCOORD0);
@ -1047,7 +1047,7 @@ void OGL_DrawTexturedRect( float ulx, float uly, float lrx, float lry, float uls
OGL_UpdateStates();
const bool updateArrays = OGL.renderState != GLInfo::rsTexRect;
if (updateArrays || CombinerInfo::get().changed) {
if (updateArrays || CombinerInfo::get().isChanged()) {
OGL.renderState = GLInfo::rsTexRect;
glDisableVertexAttribArray(SC_COLOR);
OGL_SetTexCoordArrays();
@ -1088,7 +1088,7 @@ void OGL_DrawTexturedRect( float ulx, float uly, float lrx, float lry, float uls
OGL.rect[3].x = OGL.rect[1].x;
OGL.rect[3].y = OGL.rect[2].y;
if (CombinerInfo::get().usesT0 && cache.current[0] && gSP.textureTile[0]) {
if (CombinerInfo::get().getCurrent()->usesT0() && cache.current[0] && gSP.textureTile[0]) {
OGL.rect[0].s0 = uls * cache.current[0]->shiftScaleS - gSP.textureTile[0]->fuls;
OGL.rect[0].t0 = ult * cache.current[0]->shiftScaleT - gSP.textureTile[0]->fult;
OGL.rect[3].s0 = (lrs + 1.0f) * cache.current[0]->shiftScaleS - gSP.textureTile[0]->fuls;
@ -1126,7 +1126,7 @@ void OGL_DrawTexturedRect( float ulx, float uly, float lrx, float lry, float uls
OGL.rect[3].t0 *= cache.current[0]->scaleT;
}
if (CombinerInfo::get().usesT1 && cache.current[1] && gSP.textureTile[1])
if (CombinerInfo::get().getCurrent()->usesT1() && cache.current[1] && gSP.textureTile[1])
{
OGL.rect[0].s1 = uls * cache.current[1]->shiftScaleS - gSP.textureTile[1]->fuls;
OGL.rect[0].t1 = ult * cache.current[1]->shiftScaleT - gSP.textureTile[1]->fult;