1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-02 09:03:37 +00:00

Remove direct calls of glBindTexture and GL_UNPACK_ALIGNMENT related functions.

This commit is contained in:
Sergey Lipskiy 2017-01-22 18:10:52 +07:00
parent 40f051deab
commit 663f696d8f
9 changed files with 92 additions and 14 deletions

View File

@ -110,6 +110,21 @@ void Context::setTextureParameters(const TexParameters & _parameters)
m_impl->setTextureParameters(_parameters);
}
void Context::bindTexture(const BindTextureParameters & _params)
{
m_impl->bindTexture(_params);
}
void Context::setTextureUnpackAlignment(s32 _param)
{
m_impl->setTextureUnpackAlignment(_param);
}
s32 Context::getTextureUnpackAlignment() const
{
return m_impl->getTextureUnpackAlignment();
}
void Context::bindImageTexture(const BindImageTextureParameters & _params)
{
m_impl->bindImageTexture(_params);

View File

@ -110,6 +110,18 @@ namespace graphics {
void setTextureParameters(const TexParameters & _parameters);
struct BindTextureParameters {
ObjectHandle texture;
Parameter textureUnitIndex;
Parameter target;
};
void bindTexture(const BindTextureParameters & _params);
void setTextureUnpackAlignment(s32 _param);
s32 getTextureUnpackAlignment() const;
struct BindImageTextureParameters {
Parameter imageUnit;
ObjectHandle texture;

View File

@ -28,6 +28,9 @@ namespace graphics {
virtual void init2DTexture(const Context::InitTextureParams & _params) = 0;
virtual void update2DTexture(const Context::UpdateTextureDataParams & _params) = 0;
virtual void setTextureParameters(const Context::TexParameters & _parameters) = 0;
virtual void bindTexture(const Context::BindTextureParameters & _params) = 0;
virtual void setTextureUnpackAlignment(s32 _param) = 0;
virtual s32 getTextureUnpackAlignment() const = 0;
virtual void bindImageTexture(const Context::BindImageTextureParameters & _params) = 0;
virtual FramebufferTextureFormats * getFramebufferTextureFormats() = 0;
virtual ObjectHandle createFramebuffer() = 0;

View File

@ -133,6 +133,14 @@ void CachedUseProgram::useProgram(graphics::ObjectHandle _program)
glUseProgram(GLuint(_program));
}
/*---------------CachedTextureUnpackAlignment-------------*/
void CachedTextureUnpackAlignment::setTextureUnpackAlignment(s32 _param)
{
if (update(_param))
glPixelStorei(GL_UNPACK_ALIGNMENT, _param);
}
/*---------------CachedFunctions-------------*/
CachedFunctions::CachedFunctions(const GLInfo & _glinfo)
@ -258,3 +266,8 @@ CachedUseProgram * CachedFunctions::getCachedUseProgram()
{
return &m_useProgram;
}
CachedTextureUnpackAlignment * CachedFunctions::getCachedTextureUnpackAlignment()
{
return &m_unpackAlignment;
}

View File

@ -201,6 +201,12 @@ namespace opengl {
void useProgram(graphics::ObjectHandle _program);
};
class CachedTextureUnpackAlignment : public Cached1<s32>
{
public:
void setTextureUnpackAlignment(s32 _param);
};
/*---------------CachedFunctions-------------*/
class CachedFunctions
@ -243,6 +249,8 @@ namespace opengl {
CachedUseProgram * getCachedUseProgram();
CachedTextureUnpackAlignment * getCachedTextureUnpackAlignment();
private:
typedef std::unordered_map<u32, CachedEnable> EnableParameters;
@ -262,6 +270,7 @@ namespace opengl {
CachedClearColor m_clearColor;
CachedVertexAttribArray m_attribArray;
CachedUseProgram m_useProgram;
CachedTextureUnpackAlignment m_unpackAlignment;
};
}

View File

@ -178,6 +178,23 @@ void ContextImpl::setTextureParameters(const graphics::Context::TexParameters &
m_set2DTextureParameters->setTextureParameters(_parameters);
}
void ContextImpl::bindTexture(const graphics::Context::BindTextureParameters & _params) {
m_cachedFunctions->getCachedActiveTexture()->setActiveTexture(_params.textureUnitIndex);
m_cachedFunctions->getCachedBindTexture()->bind(_params.target, _params.texture);
}
void ContextImpl::setTextureUnpackAlignment(s32 _param)
{
m_cachedFunctions->getCachedTextureUnpackAlignment()->setTextureUnpackAlignment(_param);
}
s32 ContextImpl::getTextureUnpackAlignment() const
{
GLint unpackAlignment;
glGetIntegerv(GL_UNPACK_ALIGNMENT, &unpackAlignment);
return unpackAlignment;
}
void ContextImpl::bindImageTexture(const graphics::Context::BindImageTextureParameters & _params)
{
if (glBindImageTexture != nullptr)

View File

@ -59,6 +59,12 @@ namespace opengl {
void setTextureParameters(const graphics::Context::TexParameters & _parameters) override;
void bindTexture(const graphics::Context::BindTextureParameters & _params) override;
void setTextureUnpackAlignment(s32 _param) override;
s32 getTextureUnpackAlignment() const override;
void bindImageTexture(const graphics::Context::BindImageTextureParameters & _params) override;
/*---------------Framebuffer-------------*/

View File

@ -562,7 +562,7 @@ void TextureCache::_checkCacheSize()
CachedTexture * TextureCache::_addTexture(u32 _crc32)
{
if (m_curUnpackAlignment == 0)
glGetIntegerv(GL_UNPACK_ALIGNMENT, &m_curUnpackAlignment);
m_curUnpackAlignment = gfxContext.getTextureUnpackAlignment();
_checkCacheSize();
m_textures.emplace_front(gfxContext.createTexture(target::TEXTURE_2D));
Textures::iterator new_iter = m_textures.begin();
@ -833,9 +833,9 @@ void TextureCache::_loadBackground(CachedTexture *pTexture)
glInternalFormat, (uint64)pTexture->crc, &ghqTexInfo) != 0 &&
ghqTexInfo.data != nullptr) {
if (ghqTexInfo.width % 2 != 0 &&
ghqTexInfo.format != GL_RGBA &&
m_curUnpackAlignment > 1)
glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
ghqTexInfo.format != GL_RGBA &&
m_curUnpackAlignment > 1)
gfxContext.setTextureUnpackAlignment(2);
Context::InitTextureParams params;
params.handle = pTexture->name;
params.mipMapLevel = 0;
@ -867,7 +867,7 @@ void TextureCache::_loadBackground(CachedTexture *pTexture)
gfxContext.init2DTexture(params);
}
if (m_curUnpackAlignment > 1)
glPixelStorei(GL_UNPACK_ALIGNMENT, m_curUnpackAlignment);
gfxContext.setTextureUnpackAlignment(m_curUnpackAlignment);
free(pSwapped);
free(pDest);
}
@ -1111,7 +1111,7 @@ void TextureCache::_load(u32 _tile, CachedTexture *_pTexture)
pDest = (u32*)malloc(_pTexture->textureBytes);
assert(pDest != nullptr);
GLint mipLevel = 0;
s32 mipLevel = 0;
_pTexture->max_level = 0;
if (config.generalEmulation.enableLOD != 0 && gSP.texture.level > 1)
@ -1168,9 +1168,9 @@ void TextureCache::_load(u32 _tile, CachedTexture *_pTexture)
}
if (!bLoaded) {
if (tmptex.realWidth % 2 != 0 &&
glInternalFormat != GL_RGBA &&
m_curUnpackAlignment > 1)
glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
glInternalFormat != GL_RGBA &&
m_curUnpackAlignment > 1)
gfxContext.setTextureUnpackAlignment(2);
Context::InitTextureParams params;
params.handle = _pTexture->name;
params.mipMapLevel = mipLevel;
@ -1208,7 +1208,7 @@ void TextureCache::_load(u32 _tile, CachedTexture *_pTexture)
_pTexture->textureBytes += (tmptex.realWidth * tmptex.realHeight) << sizeShift;
}
if (m_curUnpackAlignment > 1)
glPixelStorei(GL_UNPACK_ALIGNMENT, m_curUnpackAlignment);
gfxContext.setTextureUnpackAlignment(m_curUnpackAlignment);
free(pDest);
}
@ -1263,7 +1263,7 @@ void TextureCache::activateTexture(u32 _t, CachedTexture *_pTexture)
const bool bUseBilinear = (gDP.otherMode.textureFilter | (gSP.objRendermode&G_OBJRM_BILERP)) != 0;
const bool bUseLOD = currentCombiner()->usesLOD();
const GLint texLevel = bUseLOD ? _pTexture->max_level : 0;
const s32 texLevel = bUseLOD ? _pTexture->max_level : 0;
params.maxMipmapLevel = Parameter(texLevel);
if (config.texture.bilinearMode == BILINEAR_STANDARD) {
@ -1377,10 +1377,13 @@ void TextureCache::_updateBackground()
m_misses++;
glActiveTexture( GL_TEXTURE0 );
CachedTexture * pCurrent = _addTexture(crc);
glBindTexture( GL_TEXTURE_2D, GLuint(pCurrent->name) );
Context::BindTextureParameters bindParams;
bindParams.target = target::TEXTURE_2D;
bindParams.texture = pCurrent->name;
bindParams.textureUnitIndex = textureIndices::Tex[0];
gfxContext.bindTexture(bindParams);
pCurrent->address = gSP.bgImage.address;

View File

@ -93,7 +93,7 @@ private:
u32 m_hits, m_misses;
u32 m_maxBytes;
u32 m_cachedBytes;
GLint m_curUnpackAlignment;
s32 m_curUnpackAlignment;
bool m_toggleDumpTex;
};