mirror of
https://github.com/blawar/GLideN64.git
synced 2024-06-25 05:49:34 +00:00
Incapsulate combiner key logic in class CombinerKey.
This commit is contained in:
parent
ac747e6309
commit
ccde41b7de
|
@ -89,6 +89,60 @@ void Combiner_Destroy() {
|
|||
CombinerInfo::get().destroy();
|
||||
}
|
||||
|
||||
/*---------------CombinerKey-------------*/
|
||||
|
||||
CombinerKey::CombinerKey(u64 _mux)
|
||||
{
|
||||
m_key.mux = _mux;
|
||||
|
||||
// High byte of muxs0 is zero. We can use it for addtional combiner flags:
|
||||
// [0 - 0] polygon type: 0 - triangle, 1 - rect
|
||||
// [1 - 2] cycle type
|
||||
u32 flags;
|
||||
if (gDP.otherMode.cycleType >= G_CYC_COPY) {
|
||||
flags = 1U;
|
||||
}
|
||||
else {
|
||||
const OGLRender::RENDER_STATE rs = video().getRender().getRenderState();
|
||||
flags = (rs == OGLRender::rsRect || rs == OGLRender::rsTexRect) ? 1U : 0U;
|
||||
}
|
||||
flags |= (gDP.otherMode.cycleType << 1);
|
||||
|
||||
m_key.muxs0 |= (flags << 24);
|
||||
}
|
||||
|
||||
CombinerKey::CombinerKey(const CombinerKey & _other)
|
||||
{
|
||||
m_key.mux = _other.m_key.mux;
|
||||
}
|
||||
|
||||
void CombinerKey::operator=(u64 _mux)
|
||||
{
|
||||
m_key.mux = _mux;
|
||||
}
|
||||
|
||||
void CombinerKey::operator=(const CombinerKey & _other)
|
||||
{
|
||||
m_key.mux = _other.m_key.mux;
|
||||
}
|
||||
|
||||
bool CombinerKey::operator==(const CombinerKey & _other) const
|
||||
{
|
||||
return m_key.mux == _other.m_key.mux;
|
||||
}
|
||||
|
||||
bool CombinerKey::operator<(const CombinerKey & _other) const
|
||||
{
|
||||
return m_key.mux < _other.m_key.mux;
|
||||
}
|
||||
|
||||
bool CombinerKey::isRectKey() const
|
||||
{
|
||||
return ((m_key.muxs0 >> 24) & 1) != 0;
|
||||
}
|
||||
|
||||
/*---------------CombinerInfo-------------*/
|
||||
|
||||
CombinerInfo & CombinerInfo::get()
|
||||
{
|
||||
static CombinerInfo info;
|
||||
|
@ -261,7 +315,7 @@ void CombinerInfo::update()
|
|||
|
||||
void CombinerInfo::setCombine(u64 _mux )
|
||||
{
|
||||
const u64 key = getCombinerKey(_mux);
|
||||
const CombinerKey key(_mux);
|
||||
if (m_pCurrent != nullptr && m_pCurrent->getKey() == key) {
|
||||
m_bChanged = false;
|
||||
m_pCurrent->update(false);
|
||||
|
|
|
@ -114,6 +114,25 @@ struct CombineCycle
|
|||
int sa, sb, m, a;
|
||||
};
|
||||
|
||||
class CombinerKey {
|
||||
public:
|
||||
CombinerKey() = default;
|
||||
explicit CombinerKey(u64 _mux);
|
||||
CombinerKey(const CombinerKey & _other);
|
||||
|
||||
void operator=(u64 _mux);
|
||||
void operator=(const CombinerKey & _other);
|
||||
|
||||
bool operator==(const CombinerKey & _other) const;
|
||||
bool operator<(const CombinerKey & _other) const;
|
||||
|
||||
bool isRectKey() const;
|
||||
u64 getMux() const { return m_key.mux; }
|
||||
|
||||
private:
|
||||
gDPCombine m_key;
|
||||
};
|
||||
|
||||
class ShaderCombiner;
|
||||
class UniformCollection;
|
||||
class CombinerInfo
|
||||
|
@ -163,7 +182,7 @@ private:
|
|||
u32 m_configOptionsBitSet;
|
||||
|
||||
ShaderCombiner * m_pCurrent;
|
||||
typedef std::map<u64, ShaderCombiner *> Combiners;
|
||||
typedef std::map<CombinerKey, ShaderCombiner *> Combiners;
|
||||
Combiners m_combiners;
|
||||
UniformCollection * m_pUniformCollection;
|
||||
};
|
||||
|
@ -176,14 +195,5 @@ ShaderCombiner * currentCombiner() {
|
|||
void Combiner_Init();
|
||||
void Combiner_Destroy();
|
||||
|
||||
inline
|
||||
u64 getCombinerKey(u64 _mux)
|
||||
{
|
||||
gDPCombine cmb;
|
||||
cmb.mux = _mux;
|
||||
cmb.muxs0 |= (gDP.otherMode.cycleType<<24);
|
||||
return cmb.mux;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
void updateBlendMode(bool _bForce = false);
|
||||
void disableBlending();
|
||||
|
||||
u64 getKey() const {return m_key;}
|
||||
const CombinerKey & getKey() const { return m_key; }
|
||||
|
||||
bool usesTile(u32 _t) const {
|
||||
if (_t == 0)
|
||||
|
@ -143,7 +143,7 @@ private:
|
|||
void _locate_attributes() const;
|
||||
void _locateUniforms();
|
||||
|
||||
u64 m_key;
|
||||
CombinerKey m_key;
|
||||
UniformLocation m_uniforms;
|
||||
GLuint m_program;
|
||||
int m_nInputs;
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
|
||||
void UniformSet::bindWithShaderCombiner(ShaderCombiner * _pCombiner)
|
||||
{
|
||||
const u64 mux = _pCombiner->getKey();
|
||||
const CombinerKey key = _pCombiner->getKey();
|
||||
const GLuint program = _pCombiner->m_program;
|
||||
m_uniforms.emplace(mux, program);
|
||||
UniformSetLocation & location = m_uniforms.at(mux);
|
||||
m_uniforms.emplace(key, program);
|
||||
UniformSetLocation & location = m_uniforms.at(key);
|
||||
|
||||
// Texture parameters
|
||||
if (_pCombiner->usesTexture()) {
|
||||
|
|
|
@ -64,7 +64,7 @@ private:
|
|||
void _updateTextureSize(UniformSetLocation & _location, bool _bUsesT0, bool _bUsesT1, bool _bForce);
|
||||
void _updateLightUniforms(UniformSetLocation & _location, bool _bForce);
|
||||
|
||||
typedef std::map<u64, UniformSetLocation> Uniforms;
|
||||
typedef std::map<CombinerKey, UniformSetLocation> Uniforms;
|
||||
Uniforms m_uniforms;
|
||||
};
|
||||
|
||||
|
|
|
@ -285,7 +285,7 @@ ShaderCombiner::ShaderCombiner() : m_bNeedUpdate(true)
|
|||
_locate_attributes();
|
||||
}
|
||||
|
||||
ShaderCombiner::ShaderCombiner(Combiner & _color, Combiner & _alpha, const gDPCombine & _combine) : m_key(getCombinerKey(_combine.mux)), m_bNeedUpdate(true)
|
||||
ShaderCombiner::ShaderCombiner(Combiner & _color, Combiner & _alpha, const gDPCombine & _combine) : m_key(_combine.mux), m_bNeedUpdate(true)
|
||||
{
|
||||
std::string strCombiner;
|
||||
m_nInputs = compileCombiner(_combine, _color, _alpha, strCombiner);
|
||||
|
@ -834,7 +834,8 @@ std::ostream & operator<< (std::ostream & _os, const ShaderCombiner & _combiner)
|
|||
if (isGLError())
|
||||
return _os;
|
||||
|
||||
_os.write((char*)&_combiner.m_key, sizeof(_combiner.m_key));
|
||||
const u64 key = _combiner.m_key.getMux();
|
||||
_os.write((char*)&key, sizeof(key));
|
||||
_os.write((char*)&_combiner.m_nInputs, sizeof(_combiner.m_nInputs));
|
||||
_os.write((char*)&binaryFormat, sizeof(binaryFormat));
|
||||
_os.write((char*)&binaryLength, sizeof(binaryLength));
|
||||
|
@ -844,7 +845,9 @@ std::ostream & operator<< (std::ostream & _os, const ShaderCombiner & _combiner)
|
|||
|
||||
std::istream & operator>> (std::istream & _is, ShaderCombiner & _combiner)
|
||||
{
|
||||
_is.read((char*)&_combiner.m_key, sizeof(_combiner.m_key));
|
||||
u64 key;
|
||||
_is.read((char*)&key, sizeof(key));
|
||||
_combiner.m_key = key;
|
||||
_is.read((char*)&_combiner.m_nInputs, sizeof(_combiner.m_nInputs));
|
||||
GLenum binaryFormat;
|
||||
GLint binaryLength;
|
||||
|
|
|
@ -1749,7 +1749,7 @@ void OGLRender::drawTexturedRect(const TexturedRectParams & _params)
|
|||
GLfloat alpha = 0.0f;
|
||||
if (currentCombiner()->usesShade()) {
|
||||
gDPCombine combine;
|
||||
combine.mux = currentCombiner()->getKey();
|
||||
combine.mux = currentCombiner()->getKey().getMux();
|
||||
if (combine.mA0 == G_ACMUX_0 && combine.aA0 == G_ACMUX_SHADE)
|
||||
alpha = 1.0f;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user