mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-07 03:13:49 +00:00
Merge CachedActiveTexture and CachedBindTexture into one function.
This commit is contained in:
parent
6cc60c24ae
commit
2196bf644b
|
@ -70,6 +70,7 @@ namespace graphics {
|
|||
struct InitTextureParams {
|
||||
ObjectHandle handle;
|
||||
Parameter ImageUnit;
|
||||
Parameter textureUnitIndex = Parameter(0U);
|
||||
u32 msaaLevel = 0;
|
||||
u32 width = 0;
|
||||
u32 height = 0;
|
||||
|
|
|
@ -29,17 +29,12 @@ void CachedEnable::enable(bool _enable)
|
|||
|
||||
/*---------------CachedBindTexture-------------*/
|
||||
|
||||
void CachedBindTexture::bind(Parameter _target, ObjectHandle _name)
|
||||
void CachedBindTexture::bind(Parameter _tmuIndex, Parameter _target, ObjectHandle _name)
|
||||
{
|
||||
if (update(_name))
|
||||
if (update(_tmuIndex, _name)) {
|
||||
glActiveTexture(GL_TEXTURE0 + GLuint(_tmuIndex));
|
||||
glBindTexture(GLenum(_target), GLuint(_name));
|
||||
}
|
||||
|
||||
/*---------------CachedActiveTexture-------------*/
|
||||
|
||||
void CachedActiveTexture::setActiveTexture(Parameter _index) {
|
||||
if (update(_index))
|
||||
glActiveTexture(GL_TEXTURE0 + GLuint(_index));
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------CachedCullFace-------------*/
|
||||
|
@ -162,7 +157,6 @@ void CachedFunctions::reset()
|
|||
for (auto it : m_enables)
|
||||
it.second.reset();
|
||||
|
||||
m_activeTexture.reset();
|
||||
m_bindTexture.reset();
|
||||
m_bindFramebuffer.reset();
|
||||
m_bindRenderbuffer.reset();
|
||||
|
@ -197,11 +191,6 @@ CachedBindTexture * CachedFunctions::getCachedBindTexture()
|
|||
return &m_bindTexture;
|
||||
}
|
||||
|
||||
CachedActiveTexture * CachedFunctions::getCachedActiveTexture()
|
||||
{
|
||||
return &m_activeTexture;
|
||||
}
|
||||
|
||||
CachedBindFramebuffer * CachedFunctions::getCachedBindFramebuffer()
|
||||
{
|
||||
return &m_bindFramebuffer;
|
||||
|
|
|
@ -35,74 +35,11 @@ namespace opengl {
|
|||
T m_cached;
|
||||
};
|
||||
|
||||
class CachedEnable : public Cached1<graphics::Parameter>
|
||||
{
|
||||
public:
|
||||
CachedEnable(graphics::Parameter _parameter);
|
||||
|
||||
void enable(bool _enable);
|
||||
|
||||
private:
|
||||
const graphics::Parameter m_parameter;
|
||||
};
|
||||
|
||||
|
||||
template<typename Bind>
|
||||
class CachedBind : public Cached1<graphics::ObjectHandle>
|
||||
{
|
||||
public:
|
||||
CachedBind(Bind _bind) : m_bind(_bind) {}
|
||||
|
||||
void bind(graphics::Parameter _target, graphics::ObjectHandle _name) {
|
||||
if (update(_name))
|
||||
m_bind(GLenum(_target), GLuint(_name));
|
||||
}
|
||||
|
||||
private:
|
||||
Bind m_bind;
|
||||
};
|
||||
|
||||
typedef CachedBind<decltype(glBindFramebuffer)> CachedBindFramebuffer;
|
||||
|
||||
typedef CachedBind<decltype(glBindRenderbuffer)> CachedBindRenderbuffer;
|
||||
|
||||
typedef CachedBind<decltype(glBindBuffer)> CachedBindBuffer;
|
||||
|
||||
class CachedBindTexture : public Cached1<graphics::ObjectHandle>
|
||||
{
|
||||
public:
|
||||
void bind(graphics::Parameter _target, graphics::ObjectHandle _name);
|
||||
};
|
||||
|
||||
class CachedActiveTexture : public Cached1<graphics::Parameter>
|
||||
{
|
||||
public:
|
||||
void setActiveTexture(graphics::Parameter _index);
|
||||
};
|
||||
|
||||
class CachedCullFace : public Cached1<graphics::Parameter>
|
||||
{
|
||||
public:
|
||||
void setCullFace(graphics::Parameter _mode);
|
||||
};
|
||||
|
||||
class CachedDepthMask : public Cached1<graphics::Parameter>
|
||||
{
|
||||
public:
|
||||
void setDepthMask(bool _enable);
|
||||
};
|
||||
|
||||
class CachedDepthCompare : public Cached1<graphics::Parameter>
|
||||
{
|
||||
public:
|
||||
void setDepthCompare(graphics::Parameter m_mode);
|
||||
};
|
||||
|
||||
template<class T1, class T2>
|
||||
class Cached2
|
||||
{
|
||||
public:
|
||||
bool update(graphics::Parameter _p1,
|
||||
graphics::Parameter _p2)
|
||||
bool update(T1 _p1, T2 _p2)
|
||||
{
|
||||
#ifdef CACHED_USE_CACHE2
|
||||
if (_p1 == m_p1 &&
|
||||
|
@ -121,7 +58,8 @@ namespace opengl {
|
|||
}
|
||||
|
||||
protected:
|
||||
graphics::Parameter m_p1, m_p2;
|
||||
T1 m_p1;
|
||||
T2 m_p2;
|
||||
};
|
||||
|
||||
class Cached4
|
||||
|
@ -158,6 +96,63 @@ namespace opengl {
|
|||
graphics::Parameter m_p1, m_p2, m_p3, m_p4;
|
||||
};
|
||||
|
||||
class CachedEnable : public Cached1<graphics::Parameter>
|
||||
{
|
||||
public:
|
||||
CachedEnable(graphics::Parameter _parameter);
|
||||
|
||||
void enable(bool _enable);
|
||||
|
||||
private:
|
||||
const graphics::Parameter m_parameter;
|
||||
};
|
||||
|
||||
|
||||
template<typename Bind>
|
||||
class CachedBind : public Cached1<graphics::ObjectHandle>
|
||||
{
|
||||
public:
|
||||
CachedBind(Bind _bind) : m_bind(_bind) {}
|
||||
|
||||
void bind(graphics::Parameter _target, graphics::ObjectHandle _name) {
|
||||
if (update(_name))
|
||||
m_bind(GLenum(_target), GLuint(_name));
|
||||
}
|
||||
|
||||
private:
|
||||
Bind m_bind;
|
||||
};
|
||||
|
||||
typedef CachedBind<decltype(glBindFramebuffer)> CachedBindFramebuffer;
|
||||
|
||||
typedef CachedBind<decltype(glBindRenderbuffer)> CachedBindRenderbuffer;
|
||||
|
||||
typedef CachedBind<decltype(glBindBuffer)> CachedBindBuffer;
|
||||
|
||||
class CachedBindTexture : public Cached2<graphics::Parameter, graphics::ObjectHandle>
|
||||
{
|
||||
public:
|
||||
void bind(graphics::Parameter _tmuIndex, graphics::Parameter _target, graphics::ObjectHandle _name);
|
||||
};
|
||||
|
||||
class CachedCullFace : public Cached1<graphics::Parameter>
|
||||
{
|
||||
public:
|
||||
void setCullFace(graphics::Parameter _mode);
|
||||
};
|
||||
|
||||
class CachedDepthMask : public Cached1<graphics::Parameter>
|
||||
{
|
||||
public:
|
||||
void setDepthMask(bool _enable);
|
||||
};
|
||||
|
||||
class CachedDepthCompare : public Cached1<graphics::Parameter>
|
||||
{
|
||||
public:
|
||||
void setDepthCompare(graphics::Parameter m_mode);
|
||||
};
|
||||
|
||||
class CachedViewport : public Cached4
|
||||
{
|
||||
public:
|
||||
|
@ -170,7 +165,7 @@ namespace opengl {
|
|||
void setScissor(s32 _x, s32 _y, s32 _width, s32 _height);
|
||||
};
|
||||
|
||||
class CachedBlending : public Cached2
|
||||
class CachedBlending : public Cached2<graphics::Parameter, graphics::Parameter>
|
||||
{
|
||||
public:
|
||||
void setBlending(graphics::Parameter _sfactor, graphics::Parameter _dfactor);
|
||||
|
@ -223,8 +218,6 @@ namespace opengl {
|
|||
|
||||
CachedBindTexture * getCachedBindTexture();
|
||||
|
||||
CachedActiveTexture * getCachedActiveTexture();
|
||||
|
||||
CachedBindFramebuffer * getCachedBindFramebuffer();
|
||||
|
||||
CachedBindRenderbuffer * getCachedBindRenderbuffer();
|
||||
|
@ -258,7 +251,6 @@ namespace opengl {
|
|||
|
||||
EnableParameters m_enables;
|
||||
CachedBindTexture m_bindTexture;
|
||||
CachedActiveTexture m_activeTexture;
|
||||
CachedBindFramebuffer m_bindFramebuffer;
|
||||
CachedBindRenderbuffer m_bindRenderbuffer;
|
||||
CachedBindBuffer m_bindBuffer;
|
||||
|
|
|
@ -183,8 +183,7 @@ void ContextImpl::setTextureParameters(const graphics::Context::TexParameters &
|
|||
}
|
||||
|
||||
void ContextImpl::bindTexture(const graphics::Context::BindTextureParameters & _params) {
|
||||
m_cachedFunctions->getCachedActiveTexture()->setActiveTexture(_params.textureUnitIndex);
|
||||
m_cachedFunctions->getCachedBindTexture()->bind(_params.target, _params.texture);
|
||||
m_cachedFunctions->getCachedBindTexture()->bind(_params.textureUnitIndex, _params.target, _params.texture);
|
||||
}
|
||||
|
||||
void ContextImpl::setTextureUnpackAlignment(s32 _param)
|
||||
|
|
|
@ -61,7 +61,7 @@ namespace opengl {
|
|||
glBindImageTexture(GLuint(_params.ImageUnit), 0,
|
||||
0, GL_FALSE, GL_FALSE, GL_READ_ONLY, GLuint(_params.internalFormat));
|
||||
|
||||
m_bind->bind(graphics::target::TEXTURE_2D, _params.handle);
|
||||
m_bind->bind(_params.textureUnitIndex, graphics::target::TEXTURE_2D, _params.handle);
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
_params.mipMapLevel,
|
||||
GLuint(_params.internalFormat),
|
||||
|
@ -77,7 +77,7 @@ namespace opengl {
|
|||
0, GL_FALSE, GL_FALSE, GL_READ_ONLY, GLuint(_params.internalFormat));
|
||||
} else {
|
||||
//glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, GLuint(_name));
|
||||
m_bind->bind(graphics::target::TEXTURE_2D_MULTISAMPLE, _params.handle);
|
||||
m_bind->bind(_params.textureUnitIndex, graphics::target::TEXTURE_2D_MULTISAMPLE, _params.handle);
|
||||
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE,
|
||||
_params.msaaLevel,
|
||||
GLenum(_params.internalFormat),
|
||||
|
@ -109,7 +109,7 @@ namespace opengl {
|
|||
void init2DTexture(const graphics::Context::InitTextureParams & _params) override
|
||||
{
|
||||
if (_params.msaaLevel == 0) {
|
||||
m_bind->bind(graphics::target::TEXTURE_2D, _params.handle);
|
||||
m_bind->bind(_params.textureUnitIndex, graphics::target::TEXTURE_2D, _params.handle);
|
||||
if (m_handle != _params.handle) {
|
||||
m_handle = _params.handle;
|
||||
glTexStorage2D(GL_TEXTURE_2D,
|
||||
|
@ -135,7 +135,7 @@ namespace opengl {
|
|||
0, GL_FALSE, GL_FALSE, GL_READ_ONLY, GLuint(_params.internalFormat));
|
||||
}
|
||||
else {
|
||||
m_bind->bind(graphics::target::TEXTURE_2D_MULTISAMPLE, _params.handle);
|
||||
m_bind->bind(_params.textureUnitIndex, graphics::target::TEXTURE_2D_MULTISAMPLE, _params.handle);
|
||||
glTexStorage2DMultisample(
|
||||
GL_TEXTURE_2D_MULTISAMPLE,
|
||||
_params.msaaLevel,
|
||||
|
@ -221,15 +221,13 @@ namespace opengl {
|
|||
class Update2DTexSubImage : public Update2DTexture
|
||||
{
|
||||
public:
|
||||
Update2DTexSubImage(CachedActiveTexture * _activeTexture, CachedBindTexture* _bind)
|
||||
: m_activeTexture(_activeTexture)
|
||||
, m_bind(_bind) {
|
||||
Update2DTexSubImage(CachedBindTexture* _bind)
|
||||
: m_bind(_bind) {
|
||||
}
|
||||
|
||||
void update2DTexture(const graphics::Context::UpdateTextureDataParams & _params) override
|
||||
{
|
||||
m_activeTexture->setActiveTexture(_params.textureUnitIndex);
|
||||
m_bind->bind(GL_TEXTURE_2D, _params.handle);
|
||||
m_bind->bind(_params.textureUnitIndex, GL_TEXTURE_2D, _params.handle);
|
||||
|
||||
glTexSubImage2D(GL_TEXTURE_2D,
|
||||
_params.mipMapLevel,
|
||||
|
@ -247,7 +245,6 @@ namespace opengl {
|
|||
}
|
||||
|
||||
private:
|
||||
CachedActiveTexture * m_activeTexture;
|
||||
CachedBindTexture* m_bind;
|
||||
};
|
||||
|
||||
|
@ -285,16 +282,14 @@ namespace opengl {
|
|||
class SetTexParameters : public Set2DTextureParameters
|
||||
{
|
||||
public:
|
||||
SetTexParameters(CachedActiveTexture * _activeTexture, CachedBindTexture* _bind, bool _supportMipmapLevel)
|
||||
: m_activeTexture(_activeTexture)
|
||||
, m_bind(_bind)
|
||||
SetTexParameters(CachedBindTexture* _bind, bool _supportMipmapLevel)
|
||||
: m_bind(_bind)
|
||||
, m_supportMipmapLevel(_supportMipmapLevel) {
|
||||
}
|
||||
|
||||
void setTextureParameters(const graphics::Context::TexParameters & _parameters) override
|
||||
{
|
||||
m_activeTexture->setActiveTexture(_parameters.textureUnitIndex);
|
||||
m_bind->bind(_parameters.target, _parameters.handle);
|
||||
m_bind->bind(_parameters.textureUnitIndex, _parameters.target, _parameters.handle);
|
||||
const GLenum target(_parameters.target);
|
||||
if (_parameters.magFilter.isValid())
|
||||
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GLint(_parameters.magFilter));
|
||||
|
@ -311,7 +306,6 @@ namespace opengl {
|
|||
}
|
||||
|
||||
private:
|
||||
CachedActiveTexture * m_activeTexture;
|
||||
CachedBindTexture* m_bind;
|
||||
bool m_supportMipmapLevel;
|
||||
};
|
||||
|
@ -397,8 +391,7 @@ namespace opengl {
|
|||
if (Update2DTextureSubImage::Check(m_glInfo))
|
||||
return new Update2DTextureSubImage;
|
||||
|
||||
return new Update2DTexSubImage(m_cachedFunctions.getCachedActiveTexture(),
|
||||
m_cachedFunctions.getCachedBindTexture());
|
||||
return new Update2DTexSubImage(m_cachedFunctions.getCachedBindTexture());
|
||||
}
|
||||
|
||||
Set2DTextureParameters * TextureManipulationObjectFactory::getSet2DTextureParameters() const
|
||||
|
@ -406,8 +399,7 @@ namespace opengl {
|
|||
if (SetTextureParameters::Check(m_glInfo))
|
||||
return new SetTextureParameters;
|
||||
|
||||
return new SetTexParameters(m_cachedFunctions.getCachedActiveTexture(),
|
||||
m_cachedFunctions.getCachedBindTexture(), !m_glInfo.isGLES2);
|
||||
return new SetTexParameters(m_cachedFunctions.getCachedBindTexture(), !m_glInfo.isGLES2);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user