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

Make CombinerInfo sigleton.

This commit is contained in:
Sergey Lipskiy 2014-09-01 19:50:12 +07:00
parent fd63ee2b64
commit 5b48a5db49
4 changed files with 57 additions and 52 deletions

View File

@ -4,8 +4,6 @@
#include "Debug.h"
#include "gDP.h"
CombinerInfo combiner;
static int saRGBExpanded[] =
{
COMBINED, TEXEL0, TEXEL1, PRIMITIVE,
@ -107,43 +105,43 @@ static DWORD64 ACEncodeD[] =
void Combiner_Init()
{
InitGLSLCombiner();
combiner.root = NULL;
combiner.current = NULL;
CombinerInfo::get().root = NULL;
CombinerInfo::get().current = NULL;
}
void Combiner_UpdateCombineColors()
{
combiner.current->compiled->UpdateColors();
CombinerInfo::get().current->compiled->UpdateColors();
gDP.changed &= ~CHANGED_COMBINE_COLORS;
}
void Combiner_UpdateCombineFBInfo()
{
combiner.current->compiled->UpdateFBInfo(true);
CombinerInfo::get().current->compiled->UpdateFBInfo(true);
gDP.changed &= ~CHANGED_FB_TEXTURE;
}
void Combiner_UpdateCombineDepthInfo()
{
if (combiner.current != NULL)
combiner.current->compiled->UpdateDepthInfo(true);
if (CombinerInfo::get().current != NULL)
CombinerInfo::get().current->compiled->UpdateDepthInfo(true);
}
void Combiner_UpdateAlphaTestInfo()
{
if (combiner.current != NULL)
combiner.current->compiled->UpdateAlphaTestInfo();
if (CombinerInfo::get().current != NULL)
CombinerInfo::get().current->compiled->UpdateAlphaTestInfo();
}
void Combiner_UpdateTextureInfo()
{
if (combiner.current != NULL)
combiner.current->compiled->UpdateTextureInfo();
if (CombinerInfo::get().current != NULL)
CombinerInfo::get().current->compiled->UpdateTextureInfo();
}
void Combiner_UpdateRenderState() {
if (combiner.current != NULL)
combiner.current->compiled->UpdateRenderState();
if (CombinerInfo::get().current != NULL)
CombinerInfo::get().current->compiled->UpdateRenderState();
}
void Combiner_SimplifyCycle( CombineCycle *cc, CombinerStage *stage )
@ -291,10 +289,10 @@ void Combiner_Destroy()
{
DestroyGLSLCombiner();
if (combiner.root)
if (CombinerInfo::get().root)
{
Combiner_DeleteCombiner( combiner.root );
combiner.root = NULL;
Combiner_DeleteCombiner( CombinerInfo::get().root );
CombinerInfo::get().root = NULL;
}
}
@ -311,11 +309,11 @@ DWORD64 Combiner_EncodeCombineMode( WORD saRGB0, WORD sbRGB0, WORD mRGB0, WORD a
void Combiner_SelectCombine( u64 mux )
{
if (combiner.current != NULL && combiner.current->combine.mux == mux) {
combiner.changed = false;
if (CombinerInfo::get().current != NULL && CombinerInfo::get().current->combine.mux == mux) {
CombinerInfo::get().changed = false;
return;
}
CachedCombiner *current = combiner.root;
CachedCombiner *current = CombinerInfo::get().root;
CachedCombiner *parent = current;
while (current)
@ -335,22 +333,22 @@ void Combiner_SelectCombine( u64 mux )
current = Combiner_Compile( mux );
if (parent == NULL)
combiner.root = current;
CombinerInfo::get().root = current;
else if (parent->combine.mux > current->combine.mux)
parent->left = current;
else
parent->right = current;
}
combiner.current = current;
combiner.changed = true;
CombinerInfo::get().current = current;
CombinerInfo::get().changed = true;
gDP.changed |= CHANGED_COMBINE_COLORS;
}
void Combiner_SetCombineStates()
{
combiner.current->compiled->Set();
CombinerInfo::get().current->compiled->Set();
}
void Combiner_SetCombine( u64 mux )

View File

@ -131,16 +131,23 @@ struct CachedCombiner
CachedCombiner *left, *right;
};
extern struct CombinerInfo
class CombinerInfo
{
public:
CachedCombiner *root, *current;
bool usesT0, usesT1, usesLOD, usesShadeColor, changed;
static CombinerInfo & get() {
static CombinerInfo info;
return info;
}
private:
CombinerInfo() :
root(NULL), current(NULL), usesT0(false), usesT1(false),
usesShadeColor(false), changed(false) {}
} combiner;
};
void Combiner_Init();
void Combiner_UpdateCombineColors();

View File

@ -554,10 +554,10 @@ void GLSLCombiner::_locate_attributes() const {
}
void GLSLCombiner::Set() {
combiner.usesT0 = (m_nInputs & ((1<<TEXEL0)|(1<<TEXEL0_ALPHA))) != 0;
combiner.usesT1 = (m_nInputs & ((1<<TEXEL1)|(1<<TEXEL1_ALPHA))) != 0;
combiner.usesLOD = (m_nInputs & (1<<LOD_FRACTION)) != 0;
combiner.usesShadeColor = (m_nInputs & ((1<<SHADE)|(1<<SHADE_ALPHA))) != 0;
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);
@ -601,7 +601,7 @@ void GLSLCombiner::UpdateColors(bool _bForce) {
_setFUniform(m_uniforms.uK4, gDP.convert.k4*0.0039215689f, _bForce);
_setFUniform(m_uniforms.uK5, gDP.convert.k5*0.0039215689f, _bForce);
if (combiner.usesLOD) {
if (CombinerInfo::get().usesLOD) {
int uCalcLOD = (config.enableLOD && gDP.otherMode.textureLOD == G_TL_LOD) ? 1 : 0;
_setIUniform(m_uniforms.uEnableLod, uCalcLOD, _bForce);
if (uCalcLOD) {
@ -626,7 +626,7 @@ void GLSLCombiner::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 (combiner.usesT0) {
if (CombinerInfo::get().usesT0) {
if (gSP.textureTile[0]) {
_setFV2Uniform(m_uniforms.uTexOffset[0], gSP.textureTile[0]->fuls, gSP.textureTile[0]->fult, _bForce);
_setFV2Uniform(m_uniforms.uTexMask[0],
@ -642,7 +642,7 @@ void GLSLCombiner::UpdateTextureInfo(bool _bForce) {
}
}
if (combiner.usesT1) {
if (CombinerInfo::get().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

@ -765,7 +765,7 @@ void OGL_UpdateStates()
OGL_UpdateCullFace();
if (gSP.changed & CHANGED_LIGHT)
combiner.current->compiled->UpdateLight();
CombinerInfo::get().current->compiled->UpdateLight();
if (config.frameBufferEmulation.N64DepthCompare) {
glDisable( GL_DEPTH_TEST );
@ -807,20 +807,20 @@ void OGL_UpdateStates()
if ((gSP.changed & CHANGED_TEXTURE) || (gDP.changed & CHANGED_TILE) || (gDP.changed & CHANGED_TMEM))
{
//For some reason updating the texture cache on the first frame of LOZ:OOT causes a NULL Pointer exception...
if (combiner.current != NULL)
if (CombinerInfo::get().current != NULL)
{
if (combiner.usesT0)
if (CombinerInfo::get().usesT0)
TextureCache_Update(0);
else
TextureCache_ActivateDummy(0);
//Note: enabling dummies makes some F-zero X textures flicker.... strange.
if (combiner.usesT1)
if (CombinerInfo::get().usesT1)
TextureCache_Update(1);
else
TextureCache_ActivateDummy(1);
combiner.current->compiled->UpdateTextureInfo(true);
CombinerInfo::get().current->compiled->UpdateTextureInfo(true);
}
}
@ -898,7 +898,7 @@ void OGL_AddTriangle(int v0, int v1, int v2)
void OGL_SetColorArray()
{
if (combiner.usesShadeColor)
if (CombinerInfo::get().usesShadeColor)
glEnableVertexAttribArray(SC_COLOR);
else
glDisableVertexAttribArray(SC_COLOR);
@ -906,17 +906,17 @@ void OGL_SetColorArray()
void OGL_SetTexCoordArrays()
{
if (combiner.usesT0)
if (CombinerInfo::get().usesT0)
glEnableVertexAttribArray(SC_TEXCOORD0);
else
glDisableVertexAttribArray(SC_TEXCOORD0);
if (combiner.usesT1)
if (CombinerInfo::get().usesT1)
glEnableVertexAttribArray(SC_TEXCOORD1);
else
glDisableVertexAttribArray(SC_TEXCOORD1);
if (OGL.renderState == GLInfo::rsTriangle && (combiner.usesT0 || combiner.usesT1))
if (OGL.renderState == GLInfo::rsTriangle && (CombinerInfo::get().usesT0 || CombinerInfo::get().usesT1))
glEnableVertexAttribArray(SC_STSCALED);
else
glDisableVertexAttribArray(SC_STSCALED);
@ -935,7 +935,7 @@ void OGL_DrawTriangles()
OGL_UpdateStates();
const bool updateArrays = OGL.renderState != GLInfo::rsTriangle;
if (updateArrays || combiner.changed) {
if (updateArrays || CombinerInfo::get().changed) {
OGL.renderState = GLInfo::rsTriangle;
OGL_SetColorArray();
OGL_SetTexCoordArrays();
@ -958,8 +958,8 @@ void OGL_DrawTriangles()
Combiner_UpdateRenderState();
}
combiner.current->compiled->UpdateColors(true);
combiner.current->compiled->UpdateLight(true);
CombinerInfo::get().current->compiled->UpdateColors(true);
CombinerInfo::get().current->compiled->UpdateLight(true);
glDrawElements(GL_TRIANGLES, OGL.triangles.num, GL_UNSIGNED_BYTE, OGL.triangles.elements);
OGL.triangles.num = 0;
@ -973,7 +973,7 @@ void OGL_DrawLine(int v0, int v1, float width )
if (gSP.changed || gDP.changed)
OGL_UpdateStates();
if (OGL.renderState != GLInfo::rsLine || combiner.changed) {
if (OGL.renderState != GLInfo::rsLine || CombinerInfo::get().changed) {
OGL_SetColorArray();
glDisableVertexAttribArray(SC_TEXCOORD0);
glDisableVertexAttribArray(SC_TEXCOORD1);
@ -999,7 +999,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 || combiner.changed) {
if (updateArrays || CombinerInfo::get().changed) {
OGL.renderState = GLInfo::rsRect;
glDisableVertexAttribArray(SC_COLOR);
glDisableVertexAttribArray(SC_TEXCOORD0);
@ -1011,7 +1011,7 @@ void OGL_DrawRect( int ulx, int uly, int lrx, int lry, float *color )
glVertexAttrib4f(SC_COLOR, 0, 0, 0, 0);
glVertexAttrib4f(SC_POSITION, 0, 0, (gDP.otherMode.depthSource == G_ZS_PRIM) ? gDP.primDepth.z : gSP.viewport.nearz, 1.0);
glVertexAttribPointer(SC_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(GLVertex), &OGL.rect[0].x);
combiner.current->compiled->UpdateRenderState();
CombinerInfo::get().current->compiled->UpdateRenderState();
}
if (frameBuffer.drawBuffer != GL_FRAMEBUFFER)
@ -1045,7 +1045,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 || combiner.changed) {
if (updateArrays || CombinerInfo::get().changed) {
OGL.renderState = GLInfo::rsTexRect;
glDisableVertexAttribArray(SC_COLOR);
OGL_SetTexCoordArrays();
@ -1060,7 +1060,7 @@ void OGL_DrawTexturedRect( float ulx, float uly, float lrx, float lry, float uls
glVertexAttribPointer(SC_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(GLVertex), &OGL.rect[0].x);
glVertexAttribPointer(SC_TEXCOORD0, 2, GL_FLOAT, GL_FALSE, sizeof(GLVertex), &OGL.rect[0].s0);
glVertexAttribPointer(SC_TEXCOORD1, 2, GL_FLOAT, GL_FALSE, sizeof(GLVertex), &OGL.rect[0].s1);
combiner.current->compiled->UpdateRenderState();
CombinerInfo::get().current->compiled->UpdateRenderState();
}
#ifndef GLES2
@ -1086,7 +1086,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 (combiner.usesT0 && cache.current[0] && gSP.textureTile[0]) {
if (CombinerInfo::get().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;
@ -1124,7 +1124,7 @@ void OGL_DrawTexturedRect( float ulx, float uly, float lrx, float lry, float uls
OGL.rect[3].t0 *= cache.current[0]->scaleT;
}
if (combiner.usesT1 && cache.current[1] && gSP.textureTile[1])
if (CombinerInfo::get().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;