From 4e459c764594d60cbe430fb72d74f1a131f1122f Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Sat, 21 Jan 2017 19:48:02 +0700 Subject: [PATCH] Change type of CachedTexture name to graphics::ObjectHandle --- src/BufferCopy/ColorBufferToRDRAM.cpp | 46 +++--- src/BufferCopy/DepthBufferToRDRAM.cpp | 42 +++--- src/BufferCopy/RDRAMtoColorBuffer.cpp | 24 +-- src/DepthBuffer.cpp | 24 +-- src/FrameBuffer.cpp | 6 +- src/Graphics/ObjectHandle.h | 2 +- src/GraphicsDrawer.cpp | 32 ++-- src/NoiseTexture.cpp | 36 ++--- src/OpenGL.cpp | 8 +- src/PaletteTexture.cpp | 6 +- src/PostProcessor.cpp | 64 ++++---- src/Textures.cpp | 205 +++++++++++++------------- src/Textures.h | 7 +- src/ZlutTexture.cpp | 4 +- 14 files changed, 258 insertions(+), 248 deletions(-) diff --git a/src/BufferCopy/ColorBufferToRDRAM.cpp b/src/BufferCopy/ColorBufferToRDRAM.cpp index d7cbb652..ce72c23f 100644 --- a/src/BufferCopy/ColorBufferToRDRAM.cpp +++ b/src/BufferCopy/ColorBufferToRDRAM.cpp @@ -21,6 +21,8 @@ #include #include +using namespace graphics; + ColorBufferToRDRAM::ColorBufferToRDRAM() : m_FBO(0) , m_pTexture(nullptr) @@ -76,9 +78,9 @@ void ColorBufferToRDRAM::_initFBTexture(void) textureCache().addFrameBufferTextureSize(m_pTexture->textureBytes); { - const graphics::FramebufferTextureFormats & fbTexFormat = gfxContext.getFramebufferTextureFormats(); - graphics::Context::InitTextureParams params; - params.handle = graphics::ObjectHandle(m_pTexture->glName); + const FramebufferTextureFormats & fbTexFormat = gfxContext.getFramebufferTextureFormats(); + Context::InitTextureParams params; + params.handle = m_pTexture->name; params.width = m_pTexture->realWidth; params.height = m_pTexture->realHeight; params.internalFormat = fbTexFormat.colorInternalFormat; @@ -87,21 +89,21 @@ void ColorBufferToRDRAM::_initFBTexture(void) gfxContext.init2DTexture(params); } { - graphics::Context::TexParameters params; - params.handle = graphics::ObjectHandle(m_pTexture->glName); - params.target = graphics::target::TEXTURE_2D; - params.textureUnitIndex = graphics::textureIndices::Tex[0]; - params.minFilter = graphics::textureParameters::FILTER_LINEAR; - params.magFilter = graphics::textureParameters::FILTER_LINEAR; + Context::TexParameters params; + params.handle = m_pTexture->name; + params.target = target::TEXTURE_2D; + params.textureUnitIndex = textureIndices::Tex[0]; + params.minFilter = textureParameters::FILTER_LINEAR; + params.magFilter = textureParameters::FILTER_LINEAR; gfxContext.setTextureParameters(params); } { - graphics::Context::FrameBufferRenderTarget bufTarget; - bufTarget.bufferHandle = graphics::ObjectHandle(m_FBO); - bufTarget.bufferTarget = graphics::bufferTarget::DRAW_FRAMEBUFFER; - bufTarget.attachment = graphics::bufferAttachment::COLOR_ATTACHMENT0; - bufTarget.textureTarget = graphics::target::TEXTURE_2D; - bufTarget.textureHandle = graphics::ObjectHandle(m_pTexture->glName); + Context::FrameBufferRenderTarget bufTarget; + bufTarget.bufferHandle = ObjectHandle(m_FBO); + bufTarget.bufferTarget = bufferTarget::DRAW_FRAMEBUFFER; + bufTarget.attachment = bufferAttachment::COLOR_ATTACHMENT0; + bufTarget.textureTarget = target::TEXTURE_2D; + bufTarget.textureHandle = m_pTexture->name; gfxContext.addFrameBufferRenderTarget(bufTarget); } @@ -164,21 +166,21 @@ bool ColorBufferToRDRAM::_prepareCopy(u32 _startAddress) return false; } - graphics::ObjectHandle readBuffer; + ObjectHandle readBuffer; if (config.video.multisampling != 0) { m_pCurFrameBuffer->resolveMultisampledTexture(); //glBindFramebuffer(GL_READ_FRAMEBUFFER, m_pCurFrameBuffer->m_resolveFBO); - readBuffer = graphics::ObjectHandle(m_pCurFrameBuffer->m_resolveFBO); + readBuffer = ObjectHandle(m_pCurFrameBuffer->m_resolveFBO); } else { // glBindFramebuffer(GL_READ_FRAMEBUFFER, m_pCurFrameBuffer->m_FBO); - readBuffer = graphics::ObjectHandle(m_pCurFrameBuffer->m_FBO); + readBuffer = ObjectHandle(m_pCurFrameBuffer->m_FBO); } if (m_pCurFrameBuffer->m_scaleX != 1.0f || m_pCurFrameBuffer->m_scaleY != 1.0f) { // glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_FBO); - graphics::ObjectHandle drawBuffer(m_FBO); + ObjectHandle drawBuffer(m_FBO); u32 x0 = 0; u32 width, height; @@ -210,15 +212,15 @@ bool ColorBufferToRDRAM::_prepareCopy(u32 _startAddress) blitParams.dstY1 = VI.height; blitParams.dstWidth = m_pTexture->realWidth; blitParams.dstHeight = m_pTexture->realHeight; - blitParams.filter = graphics::textureParameters::FILTER_NEAREST; + blitParams.filter = textureParameters::FILTER_NEAREST; blitParams.tex[0] = pInputTexture; blitParams.combiner = CombinerInfo::get().getTexrectCopyProgram(); blitParams.readBuffer = readBuffer; blitParams.drawBuffer = drawBuffer; - blitParams.mask = graphics::blitMask::COLOR_BUFFER; + blitParams.mask = blitMask::COLOR_BUFFER; wnd.getDrawer().blitOrCopyTexturedRect(blitParams); - gfxContext.bindFramebuffer(graphics::bufferTarget::READ_FRAMEBUFFER, graphics::ObjectHandle(m_FBO)); + gfxContext.bindFramebuffer(bufferTarget::READ_FRAMEBUFFER, ObjectHandle(m_FBO)); // glBindFramebuffer(GL_READ_FRAMEBUFFER, m_FBO); } diff --git a/src/BufferCopy/DepthBufferToRDRAM.cpp b/src/BufferCopy/DepthBufferToRDRAM.cpp index 00e44a00..0c83cdf1 100644 --- a/src/BufferCopy/DepthBufferToRDRAM.cpp +++ b/src/BufferCopy/DepthBufferToRDRAM.cpp @@ -16,6 +16,8 @@ #include #include +using namespace graphics; + #ifndef GLES2 DepthBufferToRDRAM::DepthBufferToRDRAM() @@ -68,9 +70,9 @@ void DepthBufferToRDRAM::init() m_pDepthTexture->textureBytes = m_pDepthTexture->realWidth * m_pDepthTexture->realHeight * sizeof(float); textureCache().addFrameBufferTextureSize(m_pDepthTexture->textureBytes); - const graphics::FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats(); - graphics::Context::InitTextureParams initParams; - initParams.handle = graphics::ObjectHandle(m_pColorTexture->glName); + const FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats(); + Context::InitTextureParams initParams; + initParams.handle = m_pColorTexture->name; initParams.width = m_pColorTexture->realWidth; initParams.height = m_pColorTexture->realHeight; initParams.internalFormat = fbTexFormats.monochromeInternalFormat; @@ -78,15 +80,15 @@ void DepthBufferToRDRAM::init() initParams.dataType = fbTexFormats.monochromeType; gfxContext.init2DTexture(initParams); - graphics::Context::TexParameters setParams; - setParams.handle = graphics::ObjectHandle(m_pColorTexture->glName); - setParams.target = graphics::target::TEXTURE_2D; - setParams.textureUnitIndex = graphics::textureIndices::Tex[0]; - setParams.minFilter = graphics::textureParameters::FILTER_NEAREST; - setParams.magFilter = graphics::textureParameters::FILTER_NEAREST; + Context::TexParameters setParams; + setParams.handle = m_pColorTexture->name; + setParams.target = target::TEXTURE_2D; + setParams.textureUnitIndex = textureIndices::Tex[0]; + setParams.minFilter = textureParameters::FILTER_NEAREST; + setParams.magFilter = textureParameters::FILTER_NEAREST; gfxContext.setTextureParameters(setParams); - initParams.handle = graphics::ObjectHandle(m_pDepthTexture->glName); + initParams.handle = m_pDepthTexture->name; initParams.width = m_pDepthTexture->realWidth; initParams.height = m_pDepthTexture->realHeight; initParams.internalFormat = fbTexFormats.depthInternalFormat; @@ -94,21 +96,21 @@ void DepthBufferToRDRAM::init() initParams.dataType = fbTexFormats.depthType; gfxContext.init2DTexture(initParams); - setParams.handle = graphics::ObjectHandle(m_pDepthTexture->glName); + setParams.handle = m_pDepthTexture->name; gfxContext.setTextureParameters(setParams); - graphics::ObjectHandle fboHandle = gfxContext.createFramebuffer(); + ObjectHandle fboHandle = gfxContext.createFramebuffer(); m_FBO = GLuint(fboHandle); - graphics::Context::FrameBufferRenderTarget bufTarget; + Context::FrameBufferRenderTarget bufTarget; bufTarget.bufferHandle = fboHandle; - bufTarget.bufferTarget = graphics::bufferTarget::DRAW_FRAMEBUFFER; - bufTarget.attachment = graphics::bufferAttachment::COLOR_ATTACHMENT0; - bufTarget.textureTarget = graphics::target::TEXTURE_2D; - bufTarget.textureHandle = graphics::ObjectHandle(m_pColorTexture->glName); + bufTarget.bufferTarget = bufferTarget::DRAW_FRAMEBUFFER; + bufTarget.attachment = bufferAttachment::COLOR_ATTACHMENT0; + bufTarget.textureTarget = target::TEXTURE_2D; + bufTarget.textureHandle = m_pColorTexture->name; gfxContext.addFrameBufferRenderTarget(bufTarget); - bufTarget.attachment = graphics::bufferAttachment::DEPTH_ATTACHMENT; - bufTarget.textureHandle = graphics::ObjectHandle(m_pDepthTexture->glName); + bufTarget.attachment = bufferAttachment::DEPTH_ATTACHMENT; + bufTarget.textureHandle = m_pDepthTexture->name; gfxContext.addFrameBufferRenderTarget(bufTarget); // check if everything is OK @@ -212,7 +214,7 @@ bool DepthBufferToRDRAM::_copy(u32 _startAddress, u32 _endAddress) PBOBinder binder(GL_PIXEL_PACK_BUFFER, m_PBO); glBindFramebuffer(GL_READ_FRAMEBUFFER, m_FBO); - const graphics::FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats(); + const FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats(); glReadPixels(x0, y0, width, height, GLenum(fbTexFormats.depthFormat), GLenum(fbTexFormats.depthType), 0); GLubyte* pixelData = (GLubyte*)glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0, width * height * fbTexFormats.depthFormatBytes, GL_MAP_READ_BIT); diff --git a/src/BufferCopy/RDRAMtoColorBuffer.cpp b/src/BufferCopy/RDRAMtoColorBuffer.cpp index b764fd0e..aa2753e7 100644 --- a/src/BufferCopy/RDRAMtoColorBuffer.cpp +++ b/src/BufferCopy/RDRAMtoColorBuffer.cpp @@ -12,6 +12,8 @@ #include #include +using namespace graphics; + RDRAMtoColorBuffer::RDRAMtoColorBuffer() : m_pCurBuffer(nullptr) , m_pTexture(nullptr) @@ -40,9 +42,9 @@ void RDRAMtoColorBuffer::init() m_pTexture->textureBytes = m_pTexture->realWidth * m_pTexture->realHeight * 4; textureCache().addFrameBufferTextureSize(m_pTexture->textureBytes); - const graphics::FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats(); - graphics::Context::InitTextureParams initParams; - initParams.handle = graphics::ObjectHandle(m_pTexture->glName); + const FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats(); + Context::InitTextureParams initParams; + initParams.handle = m_pTexture->name; initParams.width = m_pTexture->realWidth; initParams.height = m_pTexture->realHeight; initParams.internalFormat = fbTexFormats.colorInternalFormat; @@ -50,12 +52,12 @@ void RDRAMtoColorBuffer::init() initParams.dataType = fbTexFormats.colorType; gfxContext.init2DTexture(initParams); - graphics::Context::TexParameters setParams; - setParams.handle = graphics::ObjectHandle(m_pTexture->glName); - setParams.target = graphics::target::TEXTURE_2D; - setParams.textureUnitIndex = graphics::textureIndices::Tex[0]; - setParams.minFilter = graphics::textureParameters::FILTER_LINEAR; - setParams.magFilter = graphics::textureParameters::FILTER_LINEAR; + Context::TexParameters setParams; + setParams.handle = m_pTexture->name; + setParams.target = target::TEXTURE_2D; + setParams.textureUnitIndex = textureIndices::Tex[0]; + setParams.minFilter = textureParameters::FILTER_LINEAR; + setParams.magFilter = textureParameters::FILTER_LINEAR; gfxContext.setTextureParameters(setParams); // Generate Pixel Buffer Object. Initialize it later @@ -254,8 +256,8 @@ void RDRAMtoColorBuffer::copyFromRDRAM(u32 _address, bool _bCFB) glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glBindTexture(GL_TEXTURE_2D, m_pTexture->glName); - const graphics::FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats(); + glBindTexture(GL_TEXTURE_2D, GLuint(m_pTexture->name)); + const FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats(); #ifndef GLES2 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GLenum(fbTexFormats.colorFormat), GLenum(fbTexFormats.colorType), 0); #else diff --git a/src/DepthBuffer.cpp b/src/DepthBuffer.cpp index 432c7f07..1f8ecd22 100644 --- a/src/DepthBuffer.cpp +++ b/src/DepthBuffer.cpp @@ -90,7 +90,7 @@ void DepthBuffer::initDepthImageTexture(FrameBuffer * _pBuffer) { Context::InitTextureParams params; - params.handle = ObjectHandle(m_pDepthImageTexture->glName); + params.handle = m_pDepthImageTexture->name; params.width = m_pDepthImageTexture->realWidth; params.height = m_pDepthImageTexture->realHeight; params.internalFormat = fbTexFormat.depthImageInternalFormat; @@ -100,7 +100,7 @@ void DepthBuffer::initDepthImageTexture(FrameBuffer * _pBuffer) } { Context::TexParameters params; - params.handle = ObjectHandle(m_pDepthImageTexture->glName); + params.handle =m_pDepthImageTexture->name; params.target = target::TEXTURE_2D; params.textureUnitIndex = textureIndices::Tex[0]; params.minFilter = textureParameters::FILTER_NEAREST; @@ -113,7 +113,7 @@ void DepthBuffer::initDepthImageTexture(FrameBuffer * _pBuffer) bufTarget.bufferTarget = bufferTarget::DRAW_FRAMEBUFFER; bufTarget.attachment = bufferAttachment::COLOR_ATTACHMENT0; bufTarget.textureTarget = target::TEXTURE_2D; - bufTarget.textureHandle = ObjectHandle(m_pDepthImageTexture->glName); + bufTarget.textureHandle = m_pDepthImageTexture->name; gfxContext.addFrameBufferRenderTarget(bufTarget); } @@ -160,7 +160,7 @@ void DepthBuffer::_initDepthBufferTexture(FrameBuffer * _pBuffer, CachedTexture { Context::InitTextureParams params; - params.handle = ObjectHandle(_pTexture->glName); + params.handle = _pTexture->name; params.msaaLevel = _multisample ? config.video.multisampling : 0U; params.width = _pTexture->realWidth; params.height = _pTexture->realHeight; @@ -172,7 +172,7 @@ void DepthBuffer::_initDepthBufferTexture(FrameBuffer * _pBuffer, CachedTexture _pTexture->frameBufferTexture = _multisample ? CachedTexture::fbMultiSample : CachedTexture::fbOneSample; { Context::TexParameters params; - params.handle = ObjectHandle(_pTexture->glName); + params.handle = _pTexture->name; params.target = _multisample ? target::TEXTURE_2D_MULTISAMPLE : target::TEXTURE_2D; params.textureUnitIndex = textureIndices::Tex[0]; params.minFilter = textureParameters::FILTER_NEAREST; @@ -217,7 +217,7 @@ void DepthBuffer::setDepthAttachment(ObjectHandle _fbo, Parameter _target) params.bufferHandle = _fbo; params.bufferTarget = _target; if (gfxContext.isSupported(SpecialFeatures::DepthFramebufferTextures)) { - params.textureHandle = ObjectHandle(m_pDepthBufferTexture->glName); + params.textureHandle = m_pDepthBufferTexture->name; params.textureTarget = config.video.multisampling != 0 ? target::TEXTURE_2D_MULTISAMPLE : target::TEXTURE_2D; } else { params.textureHandle = m_depthRenderbuffer; @@ -258,7 +258,7 @@ CachedTexture * DepthBuffer::resolveDepthBufferTexture(FrameBuffer * _pBuffer) targetParams.attachment = bufferAttachment::DEPTH_ATTACHMENT; targetParams.bufferHandle = _pBuffer->m_resolveFBO; targetParams.bufferTarget = bufferTarget::DRAW_FRAMEBUFFER; - targetParams.textureHandle = ObjectHandle(m_pResolveDepthBufferTexture->glName); + targetParams.textureHandle = m_pResolveDepthBufferTexture->name; targetParams.textureTarget = target::TEXTURE_2D; gfxContext.addFrameBufferRenderTarget(targetParams); @@ -301,14 +301,14 @@ CachedTexture * DepthBuffer::copyDepthBufferTexture(FrameBuffer * _pBuffer) targetParams.bufferTarget = bufferTarget::DRAW_FRAMEBUFFER; targetParams.attachment = bufferAttachment::COLOR_ATTACHMENT0; targetParams.textureHandle = _pBuffer->m_pTexture->frameBufferTexture == CachedTexture::fbMultiSample ? - ObjectHandle(_pBuffer->m_pResolveTexture->glName) : - ObjectHandle(_pBuffer->m_pTexture->glName); + _pBuffer->m_pResolveTexture->name : + _pBuffer->m_pTexture->name; targetParams.textureTarget = target::TEXTURE_2D; gfxContext.addFrameBufferRenderTarget(targetParams); targetParams.attachment = bufferAttachment::DEPTH_ATTACHMENT; - targetParams.textureHandle = ObjectHandle(m_pDepthBufferCopyTexture->glName); + targetParams.textureHandle = m_pDepthBufferCopyTexture->name; gfxContext.addFrameBufferRenderTarget(targetParams); @@ -348,7 +348,7 @@ void DepthBuffer::bindDepthImageTexture() Context::BindImageTextureParameters bindParams; bindParams.imageUnit = textureImageUnits::Depth; - bindParams.texture = ObjectHandle(m_pDepthImageTexture->glName); + bindParams.texture = m_pDepthImageTexture->name; bindParams.accessMode = textureImageAccessMode::READ_WRITE; bindParams.textureFormat = gfxContext.getFramebufferTextureFormats().depthImageInternalFormat; @@ -495,7 +495,7 @@ void DepthBufferList::clearBuffer(u32 _ulx, u32 _uly, u32 _lrx, u32 _lry) dwnd().getDrawer().drawRect(_ulx, _uly, _lrx, _lry, color); gDP.otherMode.cycleType = cycleType; - bindParams.texture = ObjectHandle(m_pCurrent->m_pDepthImageTexture->glName); + bindParams.texture = m_pCurrent->m_pDepthImageTexture->name; gfxContext.bindImageTexture(bindParams); frameBufferList().setCurrentDrawBuffer(); diff --git a/src/FrameBuffer.cpp b/src/FrameBuffer.cpp index 18c19717..66bdb0f3 100644 --- a/src/FrameBuffer.cpp +++ b/src/FrameBuffer.cpp @@ -89,7 +89,7 @@ void FrameBuffer::_setAndAttachTexture(ObjectHandle _fbo, CachedTexture *_pTextu { const FramebufferTextureFormats & fbTexFormat = gfxContext.getFramebufferTextureFormats(); Context::InitTextureParams params; - params.handle = ObjectHandle(_pTexture->glName); + params.handle = _pTexture->name; if (_multisampling) params.msaaLevel = config.video.multisampling; params.width = _pTexture->realWidth; @@ -108,7 +108,7 @@ void FrameBuffer::_setAndAttachTexture(ObjectHandle _fbo, CachedTexture *_pTextu } { Context::TexParameters params; - params.handle = ObjectHandle(_pTexture->glName); + params.handle = _pTexture->name; params.target = _multisampling ? target::TEXTURE_2D_MULTISAMPLE : target::TEXTURE_2D; params.textureUnitIndex = textureIndices::Tex[_t]; params.minFilter = textureParameters::FILTER_NEAREST; @@ -121,7 +121,7 @@ void FrameBuffer::_setAndAttachTexture(ObjectHandle _fbo, CachedTexture *_pTextu bufTarget.bufferTarget = bufferTarget::FRAMEBUFFER; bufTarget.attachment = bufferAttachment::COLOR_ATTACHMENT0; bufTarget.textureTarget = _multisampling ? target::TEXTURE_2D_MULTISAMPLE : target::TEXTURE_2D; - bufTarget.textureHandle = ObjectHandle(_pTexture->glName); + bufTarget.textureHandle = _pTexture->name; gfxContext.addFrameBufferRenderTarget(bufTarget); } assert(checkFBO()); diff --git a/src/Graphics/ObjectHandle.h b/src/Graphics/ObjectHandle.h index f9e66edc..4a503f00 100644 --- a/src/Graphics/ObjectHandle.h +++ b/src/Graphics/ObjectHandle.h @@ -11,7 +11,7 @@ namespace graphics { explicit operator u32() const { return m_name; } bool operator==(const ObjectHandle & _other) const { return m_name == _other.m_name; } bool operator!=(const ObjectHandle & _other) const { return m_name != _other.m_name; } - + bool operator<(const ObjectHandle & _other) const { return m_name < _other.m_name; } bool isNotNull() const { return m_name != 0; } diff --git a/src/GraphicsDrawer.cpp b/src/GraphicsDrawer.cpp index 302e9458..0fee1643 100644 --- a/src/GraphicsDrawer.cpp +++ b/src/GraphicsDrawer.cpp @@ -584,12 +584,12 @@ void GraphicsDrawer::_updateStates(DrawingState _drawingState) const if (pDepthTexture == nullptr) return; Context::TexParameters params; - params.handle = graphics::ObjectHandle(pDepthTexture->glName); - params.target = graphics::target::TEXTURE_2D; - params.textureUnitIndex = graphics::textureIndices::DepthTex; + params.handle = pDepthTexture->name; + params.target = target::TEXTURE_2D; + params.textureUnitIndex = textureIndices::DepthTex; params.maxMipmapLevel = 0; - params.minFilter = graphics::textureParameters::FILTER_NEAREST; - params.magFilter = graphics::textureParameters::FILTER_NEAREST; + params.minFilter = textureParameters::FILTER_NEAREST; + params.magFilter = textureParameters::FILTER_NEAREST; gfxContext.setTextureParameters(params); } } @@ -1180,7 +1180,7 @@ void GraphicsDrawer::drawTexturedRect(const TexturedRectParams & _params) texParams.wrapT = textureParameters::WRAP_CLAMP_TO_EDGE; if (texParams.wrapS.isValid() || texParams.wrapT.isValid()) { - texParams.handle = ObjectHandle(cache.current[t]->glName); + texParams.handle = cache.current[t]->name; texParams.target = cache.current[t]->frameBufferTexture == CachedTexture::fbMultiSample ? target::TEXTURE_2D_MULTISAMPLE : target::TEXTURE_2D; texParams.textureUnitIndex = textureIndices::Tex[t]; @@ -1196,7 +1196,7 @@ void GraphicsDrawer::drawTexturedRect(const TexturedRectParams & _params) if (gDP.otherMode.cycleType == G_CYC_COPY) { Context::TexParameters texParams; - texParams.handle = ObjectHandle(cache.current[0]->glName); + texParams.handle = cache.current[0]->name; texParams.target = cache.current[0]->frameBufferTexture == CachedTexture::fbMultiSample ? target::TEXTURE_2D_MULTISAMPLE : target::TEXTURE_2D; texParams.textureUnitIndex = textureIndices::Tex[0]; @@ -1446,22 +1446,22 @@ void GraphicsDrawer::copyTexturedRect(const CopyRectParams & _params) continue; Context::TexParameters texParams; - texParams.handle = graphics::ObjectHandle(tex->glName); - texParams.textureUnitIndex = graphics::textureIndices::Tex[i]; + texParams.handle = tex->name; + texParams.textureUnitIndex = textureIndices::Tex[i]; texParams.target = tex->frameBufferTexture == CachedTexture::fbMultiSample ? - graphics::target::TEXTURE_2D_MULTISAMPLE : graphics::target::TEXTURE_2D; + target::TEXTURE_2D_MULTISAMPLE : target::TEXTURE_2D; texParams.minFilter = _params.filter; texParams.magFilter = _params.filter; - texParams.wrapS = graphics::textureParameters::WRAP_CLAMP_TO_EDGE; - texParams.wrapT = graphics::textureParameters::WRAP_CLAMP_TO_EDGE; + texParams.wrapS = textureParameters::WRAP_CLAMP_TO_EDGE; + texParams.wrapT = textureParameters::WRAP_CLAMP_TO_EDGE; gfxContext.setTextureParameters(texParams); } gfxContext.setViewport(0, 0, _params.dstWidth, _params.dstHeight); - gfxContext.enable(graphics::enable::CULL_FACE, false); - gfxContext.enable(graphics::enable::BLEND, false); - gfxContext.enable(graphics::enable::DEPTH_TEST, false); - gfxContext.enable(graphics::enable::SCISSOR_TEST, false); + gfxContext.enable(enable::CULL_FACE, false); + gfxContext.enable(enable::BLEND, false); + gfxContext.enable(enable::DEPTH_TEST, false); + gfxContext.enable(enable::SCISSOR_TEST, false); gfxContext.enableDepthWrite(false); Context::DrawRectParameters rectParams; diff --git a/src/NoiseTexture.cpp b/src/NoiseTexture.cpp index c88c7446..b81a1ca1 100644 --- a/src/NoiseTexture.cpp +++ b/src/NoiseTexture.cpp @@ -8,6 +8,8 @@ #include "NoiseTexture.h" #include "DisplayWindow.h" +using namespace graphics; + NoiseTexture g_noiseTexture; NoiseTexture::NoiseTexture() @@ -35,22 +37,22 @@ void NoiseTexture::init() textureCache().addFrameBufferTextureSize(m_pTexture->textureBytes); { - graphics::Context::InitTextureParams params; - params.handle = graphics::ObjectHandle(m_pTexture->glName); + Context::InitTextureParams params; + params.handle = m_pTexture->name; params.width = m_pTexture->realWidth; params.height = m_pTexture->realHeight; - params.internalFormat = graphics::internalcolor::RED; - params.format = graphics::color::RED; - params.dataType = graphics::datatype::UNSIGNED_BYTE; + params.internalFormat = internalcolor::RED; + params.format = color::RED; + params.dataType = datatype::UNSIGNED_BYTE; gfxContext.init2DTexture(params); } { - graphics::Context::TexParameters params; - params.handle = graphics::ObjectHandle(m_pTexture->glName); - params.target = graphics::target::TEXTURE_2D; - params.textureUnitIndex = graphics::textureIndices::NoiseTex; - params.minFilter = graphics::textureParameters::FILTER_NEAREST; - params.magFilter = graphics::textureParameters::FILTER_NEAREST; + Context::TexParameters params; + params.handle = m_pTexture->name; + params.target = target::TEXTURE_2D; + params.textureUnitIndex = textureIndices::NoiseTex; + params.minFilter = textureParameters::FILTER_NEAREST; + params.magFilter = textureParameters::FILTER_NEAREST; gfxContext.setTextureParameters(params); } @@ -75,7 +77,7 @@ void NoiseTexture::update() if (dataSize == 0) return; - graphics::PixelBufferBinder binder(m_pbuf.get()); + PixelBufferBinder binder(m_pbuf.get()); GLubyte* ptr = (GLubyte*)m_pbuf->getWriteBuffer(dataSize); if (ptr == nullptr) { return; @@ -86,13 +88,13 @@ void NoiseTexture::update() } m_pbuf->closeWriteBuffer(); - graphics::Context::UpdateTextureDataParams params; - params.handle = graphics::ObjectHandle(m_pTexture->glName); - params.textureUnitIndex = graphics::textureIndices::NoiseTex; + Context::UpdateTextureDataParams params; + params.handle = m_pTexture->name; + params.textureUnitIndex = textureIndices::NoiseTex; params.width = VI.width; params.height = VI.height; - params.format = graphics::color::RED; - params.dataType = graphics::datatype::UNSIGNED_BYTE; + params.format = color::RED; + params.dataType = datatype::UNSIGNED_BYTE; params.data = m_pbuf->getData(); gfxContext.update2DTexture(params); diff --git a/src/OpenGL.cpp b/src/OpenGL.cpp index 37a63267..d7d483ce 100644 --- a/src/OpenGL.cpp +++ b/src/OpenGL.cpp @@ -405,7 +405,7 @@ void OGLRender::TexrectDrawer::init() const graphics::FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats(); graphics::Context::InitTextureParams initParams; - initParams.handle = graphics::ObjectHandle(m_pTexture->glName); + initParams.handle = m_pTexture->name; initParams.width = m_pTexture->realWidth; initParams.height = m_pTexture->realHeight; initParams.internalFormat = fbTexFormats.colorInternalFormat; @@ -414,7 +414,7 @@ void OGLRender::TexrectDrawer::init() gfxContext.init2DTexture(initParams); graphics::Context::TexParameters setParams; - setParams.handle = graphics::ObjectHandle(m_pTexture->glName); + setParams.handle = m_pTexture->name; setParams.target = graphics::target::TEXTURE_2D; setParams.minFilter = graphics::textureParameters::FILTER_LINEAR; setParams.magFilter = graphics::textureParameters::FILTER_LINEAR; @@ -427,7 +427,7 @@ void OGLRender::TexrectDrawer::init() bufTarget.bufferTarget = graphics::bufferTarget::DRAW_FRAMEBUFFER; bufTarget.attachment = graphics::bufferAttachment::COLOR_ATTACHMENT0; bufTarget.textureTarget = graphics::target::TEXTURE_2D; - bufTarget.textureHandle = graphics::ObjectHandle(m_pTexture->glName); + bufTarget.textureHandle = m_pTexture->name; gfxContext.addFrameBufferRenderTarget(bufTarget); // check if everything is OK @@ -1210,7 +1210,7 @@ void OGLRender::_updateStates(RENDER_STATE _renderState) const if (pDepthTexture == nullptr) return; glActiveTexture(GL_TEXTURE0 + g_depthTexIndex); - glBindTexture(GL_TEXTURE_2D, pDepthTexture->glName); + glBindTexture(GL_TEXTURE_2D, GLuint(pDepthTexture->name)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); diff --git a/src/PaletteTexture.cpp b/src/PaletteTexture.cpp index c0c5511a..cc5efbf2 100644 --- a/src/PaletteTexture.cpp +++ b/src/PaletteTexture.cpp @@ -41,7 +41,7 @@ void PaletteTexture::init() const FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats(); Context::InitTextureParams initParams; - initParams.handle = ObjectHandle(m_pTexture->glName); + initParams.handle = m_pTexture->name; initParams.ImageUnit = textureImageUnits::Tlut; initParams.width = m_pTexture->realWidth; initParams.height = m_pTexture->realHeight; @@ -51,7 +51,7 @@ void PaletteTexture::init() gfxContext.init2DTexture(initParams); Context::TexParameters setParams; - setParams.handle = ObjectHandle(m_pTexture->glName); + setParams.handle = m_pTexture->name; setParams.target = target::TEXTURE_2D; setParams.textureUnitIndex = textureIndices::PaletteTex; setParams.minFilter = textureParameters::FILTER_NEAREST; @@ -103,7 +103,7 @@ void PaletteTexture::update() const FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats(); Context::UpdateTextureDataParams params; - params.handle = ObjectHandle(m_pTexture->glName); + params.handle = m_pTexture->name; params.ImageUnit = textureImageUnits::Tlut; params.textureUnitIndex = textureIndices::PaletteTex; params.width = m_pTexture->realWidth; diff --git a/src/PostProcessor.cpp b/src/PostProcessor.cpp index ccad4187..391e582c 100644 --- a/src/PostProcessor.cpp +++ b/src/PostProcessor.cpp @@ -11,6 +11,8 @@ #include #include "DisplayWindow.h" +using namespace graphics; + #define NEW_POST_PROCESSOR #ifdef ANDROID @@ -252,20 +254,20 @@ void _initTexture(CachedTexture * pTexture) pTexture->textureBytes = pTexture->realWidth * pTexture->realHeight * 4; textureCache().addFrameBufferTextureSize(pTexture->textureBytes); - graphics::Context::InitTextureParams initParams; - initParams.handle = graphics::ObjectHandle(pTexture->glName); + Context::InitTextureParams initParams; + initParams.handle = pTexture->name; initParams.width = pTexture->realWidth; initParams.height = pTexture->realHeight; - initParams.internalFormat = graphics::internalcolor::RGBA; - initParams.format = graphics::color::RGBA; - initParams.dataType = graphics::datatype::UNSIGNED_BYTE; + initParams.internalFormat = internalcolor::RGBA; + initParams.format = color::RGBA; + initParams.dataType = datatype::UNSIGNED_BYTE; gfxContext.init2DTexture(initParams); - graphics::Context::TexParameters setParams; - setParams.handle = graphics::ObjectHandle(pTexture->glName); - setParams.target = graphics::target::TEXTURE_2D; - setParams.minFilter = graphics::textureParameters::FILTER_NEAREST; - setParams.magFilter = graphics::textureParameters::FILTER_NEAREST; + Context::TexParameters setParams; + setParams.handle = pTexture->name; + setParams.target = target::TEXTURE_2D; + setParams.minFilter = textureParameters::FILTER_NEAREST; + setParams.magFilter = textureParameters::FILTER_NEAREST; gfxContext.setTextureParameters(setParams); } @@ -278,22 +280,22 @@ CachedTexture * _createTexture() } static -void _initFBO(graphics::ObjectHandle _FBO, CachedTexture * _pTexture) +void _initFBO(ObjectHandle _FBO, CachedTexture * _pTexture) { - graphics::Context::FrameBufferRenderTarget bufTarget; + Context::FrameBufferRenderTarget bufTarget; bufTarget.bufferHandle = _FBO; - bufTarget.bufferTarget = graphics::bufferTarget::DRAW_FRAMEBUFFER; - bufTarget.attachment = graphics::bufferAttachment::COLOR_ATTACHMENT0; - bufTarget.textureTarget = graphics::target::TEXTURE_2D; - bufTarget.textureHandle = graphics::ObjectHandle(_pTexture->glName); + bufTarget.bufferTarget = bufferTarget::DRAW_FRAMEBUFFER; + bufTarget.attachment = bufferAttachment::COLOR_ATTACHMENT0; + bufTarget.textureTarget = target::TEXTURE_2D; + bufTarget.textureHandle = _pTexture->name; gfxContext.addFrameBufferRenderTarget(bufTarget); assert(checkFBO()); } static -graphics::ObjectHandle _createFBO(CachedTexture * _pTexture) +ObjectHandle _createFBO(CachedTexture * _pTexture) { - graphics::ObjectHandle FBO = gfxContext.createFramebuffer(); + ObjectHandle FBO = gfxContext.createFramebuffer(); _initFBO(FBO, _pTexture); return FBO; } @@ -311,10 +313,10 @@ void PostProcessor::_initCommon() { m_pResultBuffer = new FrameBuffer(); _initTexture(m_pResultBuffer->m_pTexture); - _initFBO(graphics::ObjectHandle(m_pResultBuffer->m_FBO), m_pResultBuffer->m_pTexture); + _initFBO(ObjectHandle(m_pResultBuffer->m_FBO), m_pResultBuffer->m_pTexture); - gfxContext.bindFramebuffer(graphics::bufferTarget::DRAW_FRAMEBUFFER, - graphics::ObjectHandle()); + gfxContext.bindFramebuffer(bufferTarget::DRAW_FRAMEBUFFER, + ObjectHandle()); } void PostProcessor::_initGammaCorrection() @@ -478,14 +480,14 @@ void PostProcessor::_preDraw(FrameBuffer * _pBuffer) } else m_pTextureOriginal = _pBuffer->m_pTexture; - gfxContext.bindFramebuffer(graphics::bufferTarget::READ_FRAMEBUFFER, - graphics::ObjectHandle()); + gfxContext.bindFramebuffer(bufferTarget::READ_FRAMEBUFFER, + ObjectHandle()); } void PostProcessor::_postDraw() { - gfxContext.bindFramebuffer(graphics::bufferTarget::DRAW_FRAMEBUFFER, - graphics::ObjectHandle()); + gfxContext.bindFramebuffer(bufferTarget::DRAW_FRAMEBUFFER, + ObjectHandle()); gfxContext.resetShaderProgram(); } @@ -578,8 +580,8 @@ FrameBuffer * PostProcessor::doGammaCorrection(FrameBuffer * _pBuffer) _preDraw(_pBuffer); - gfxContext.bindFramebuffer(graphics::bufferTarget::DRAW_FRAMEBUFFER, - graphics::ObjectHandle(m_pResultBuffer->m_FBO)); + gfxContext.bindFramebuffer(bufferTarget::DRAW_FRAMEBUFFER, + ObjectHandle(m_pResultBuffer->m_FBO)); CachedTexture * pDstTex = m_pResultBuffer->m_pTexture; GraphicsDrawer::CopyRectParams copyParams; @@ -597,7 +599,7 @@ FrameBuffer * PostProcessor::doGammaCorrection(FrameBuffer * _pBuffer) copyParams.dstWidth = pDstTex->realWidth; copyParams.dstHeight = pDstTex->realHeight; copyParams.tex[0] = m_pTextureOriginal; - copyParams.filter = graphics::textureParameters::FILTER_NEAREST; + copyParams.filter = textureParameters::FILTER_NEAREST; copyParams.combiner = m_gammaCorrectionProgram.get(); dwnd().getDrawer().copyTexturedRect(copyParams); @@ -617,8 +619,8 @@ FrameBuffer * PostProcessor::doOrientationCorrection(FrameBuffer * _pBuffer) _preDraw(_pBuffer); - gfxContext.bindFramebuffer(graphics::bufferTarget::DRAW_FRAMEBUFFER, - graphics::ObjectHandle(m_pResultBuffer->m_FBO)); + gfxContext.bindFramebuffer(bufferTarget::DRAW_FRAMEBUFFER, + ObjectHandle(m_pResultBuffer->m_FBO)); CachedTexture * pDstTex = m_pResultBuffer->m_pTexture; GraphicsDrawer::CopyRectParams copyParams; @@ -636,7 +638,7 @@ FrameBuffer * PostProcessor::doOrientationCorrection(FrameBuffer * _pBuffer) copyParams.dstWidth = pDstTex->realWidth; copyParams.dstHeight = pDstTex->realHeight; copyParams.tex[0] = m_pTextureOriginal; - copyParams.filter = graphics::textureParameters::FILTER_NEAREST; + copyParams.filter = textureParameters::FILTER_NEAREST; copyParams.combiner = m_orientationCorrectionProgram.get(); dwnd().getDrawer().copyTexturedRect(copyParams); diff --git a/src/Textures.cpp b/src/Textures.cpp index 0602922b..4a35d6ef 100644 --- a/src/Textures.cpp +++ b/src/Textures.cpp @@ -21,6 +21,7 @@ #include "DisplayWindow.h" using namespace std; +using namespace graphics; inline u32 GetNone( u64 *src, u16 x, u16 i, u8 palette ) { @@ -472,15 +473,15 @@ void TextureCache::init() m_pDummy = addFrameBufferTexture(false); // we don't want to remove dummy texture _initDummyTexture(m_pDummy); - graphics::Context::InitTextureParams params; - params.handle = graphics::ObjectHandle(m_pDummy->glName); + Context::InitTextureParams params; + params.handle = m_pDummy->name; params.mipMapLevel = 0; params.msaaLevel = 0; params.width = m_pDummy->realWidth; params.height = m_pDummy->realHeight; - params.format = graphics::color::RGBA; - params.internalFormat = graphics::internalcolor::RGBA; - params.dataType = graphics::datatype::UNSIGNED_BYTE; + params.format = color::RGBA; + params.internalFormat = internalcolor::RGBA; + params.dataType = datatype::UNSIGNED_BYTE; params.data = dummyTexture; gfxContext.init2DTexture(params); @@ -491,19 +492,19 @@ void TextureCache::init() m_pMSDummy = nullptr; - if (config.video.multisampling != 0 && gfxContext.isSupported(graphics::SpecialFeatures::Multisampling)) { + if (config.video.multisampling != 0 && gfxContext.isSupported(SpecialFeatures::Multisampling)) { m_pMSDummy = addFrameBufferTexture(true); // we don't want to remove dummy texture _initDummyTexture(m_pMSDummy); - graphics::Context::InitTextureParams params; - params.handle = graphics::ObjectHandle(m_pMSDummy->glName); + Context::InitTextureParams params; + params.handle = m_pMSDummy->name; params.mipMapLevel = 0; params.msaaLevel = config.video.multisampling; params.width = m_pMSDummy->realWidth; params.height = m_pMSDummy->realHeight; - params.format = graphics::color::RGBA; - params.internalFormat = graphics::internalcolor::RGBA; - params.dataType = graphics::datatype::UNSIGNED_BYTE; + params.format = color::RGBA; + params.internalFormat = internalcolor::RGBA; + params.dataType = datatype::UNSIGNED_BYTE; gfxContext.init2DTexture(params); activateMSDummy(0); @@ -518,12 +519,12 @@ void TextureCache::destroy() current[0] = current[1] = nullptr; for (Textures::const_iterator cur = m_textures.cbegin(); cur != m_textures.cend(); ++cur) - glDeleteTextures( 1, &cur->glName ); + gfxContext.deleteTexture(cur->name); m_textures.clear(); m_lruTextureLocations.clear(); for (FBTextures::const_iterator cur = m_fbTextures.cbegin(); cur != m_fbTextures.cend(); ++cur) - glDeleteTextures( 1, &cur->second.glName ); + gfxContext.deleteTexture(cur->second.name); m_fbTextures.clear(); m_cachedBytes = 0; @@ -539,7 +540,7 @@ void TextureCache::_checkCacheSize() if (m_textures.size() >= maxCacheSize) { CachedTexture& clsTex = m_textures.back(); m_cachedBytes -= clsTex.textureBytes; - glDeleteTextures(1, &clsTex.glName); + gfxContext.deleteTexture(clsTex.name); m_lruTextureLocations.erase(clsTex.crc); m_textures.pop_back(); } @@ -552,7 +553,7 @@ void TextureCache::_checkCacheSize() --iter; CachedTexture& tex = *iter; m_cachedBytes -= tex.textureBytes; - glDeleteTextures(1, &tex.glName); + gfxContext.deleteTexture(tex.name); m_lruTextureLocations.erase(tex.crc); } while (m_cachedBytes > m_maxBytes && iter != m_textures.cbegin()); m_textures.erase(iter, m_textures.end()); @@ -563,7 +564,7 @@ CachedTexture * TextureCache::_addTexture(u32 _crc32) if (m_curUnpackAlignment == 0) glGetIntegerv(GL_UNPACK_ALIGNMENT, &m_curUnpackAlignment); _checkCacheSize(); - m_textures.emplace_front(u32(gfxContext.createTexture(graphics::target::TEXTURE_2D))); + m_textures.emplace_front(gfxContext.createTexture(target::TEXTURE_2D)); Textures::iterator new_iter = m_textures.begin(); new_iter->crc = _crc32; m_lruTextureLocations.insert(std::pair(_crc32, new_iter)); @@ -574,18 +575,18 @@ void TextureCache::removeFrameBufferTexture(CachedTexture * _pTexture) { if (_pTexture == nullptr) return; - FBTextures::const_iterator iter = m_fbTextures.find(_pTexture->glName); + FBTextures::const_iterator iter = m_fbTextures.find(_pTexture->name); assert(iter != m_fbTextures.cend()); m_cachedBytes -= iter->second.textureBytes; - gfxContext.deleteTexture(graphics::ObjectHandle(iter->second.glName)); + gfxContext.deleteTexture(ObjectHandle(iter->second.name)); m_fbTextures.erase(iter); } CachedTexture * TextureCache::addFrameBufferTexture(bool _multisample) { _checkCacheSize(); - u32 texName(gfxContext.createTexture(_multisample ? - graphics::target::TEXTURE_2D_MULTISAMPLE : graphics::target::TEXTURE_2D)); + ObjectHandle texName(gfxContext.createTexture(_multisample ? + target::TEXTURE_2D_MULTISAMPLE : target::TEXTURE_2D)); m_fbTextures.emplace(texName, texName); return &m_fbTextures.at(texName); } @@ -748,15 +749,15 @@ bool TextureCache::_loadHiresBackground(CachedTexture *_pTexture) bpl, paladdr); GHQTexInfo ghqTexInfo; if (txfilter_hirestex(_pTexture->crc, ricecrc, palette, &ghqTexInfo)) { - graphics::Context::InitTextureParams params; - params.handle = graphics::ObjectHandle(_pTexture->glName); + Context::InitTextureParams params; + params.handle = _pTexture->name; params.mipMapLevel = 0; params.msaaLevel = 0; params.width = ghqTexInfo.width; params.height = ghqTexInfo.height; - params.format = graphics::Parameter(ghqTexInfo.texture_format); - params.internalFormat = graphics::Parameter(ghqTexInfo.format); - params.dataType = graphics::Parameter(ghqTexInfo.pixel_type); + params.format = Parameter(ghqTexInfo.texture_format); + params.internalFormat = Parameter(ghqTexInfo.format); + params.dataType = Parameter(ghqTexInfo.pixel_type); params.data = ghqTexInfo.data; gfxContext.init2DTexture(params); @@ -835,15 +836,15 @@ void TextureCache::_loadBackground(CachedTexture *pTexture) ghqTexInfo.format != GL_RGBA && m_curUnpackAlignment > 1) glPixelStorei(GL_UNPACK_ALIGNMENT, 2); - graphics::Context::InitTextureParams params; - params.handle = graphics::ObjectHandle(pTexture->glName); + Context::InitTextureParams params; + params.handle = pTexture->name; params.mipMapLevel = 0; params.msaaLevel = 0; params.width = ghqTexInfo.width; params.height = ghqTexInfo.height; - params.format = graphics::Parameter(ghqTexInfo.texture_format); - params.internalFormat = graphics::Parameter(ghqTexInfo.format); - params.dataType = graphics::Parameter(ghqTexInfo.pixel_type); + params.format = Parameter(ghqTexInfo.texture_format); + params.internalFormat = Parameter(ghqTexInfo.format); + params.dataType = Parameter(ghqTexInfo.pixel_type); params.data = ghqTexInfo.data; gfxContext.init2DTexture(params); _updateCachedTexture(ghqTexInfo, pTexture); @@ -853,15 +854,15 @@ void TextureCache::_loadBackground(CachedTexture *pTexture) if (!bLoaded) { if (pTexture->realWidth % 2 != 0 && glInternalFormat != GL_RGBA) glPixelStorei(GL_UNPACK_ALIGNMENT, 2); - graphics::Context::InitTextureParams params; - params.handle = graphics::ObjectHandle(pTexture->glName); + Context::InitTextureParams params; + params.handle = pTexture->name; params.mipMapLevel = 0; params.msaaLevel = 0; params.width = pTexture->realWidth; params.height = pTexture->realHeight; - params.format = graphics::color::RGBA; - params.internalFormat = graphics::Parameter(glInternalFormat); - params.dataType = graphics::Parameter(glType); + params.format = color::RGBA; + params.internalFormat = Parameter(glInternalFormat); + params.dataType = Parameter(glType); params.data = pDest; gfxContext.init2DTexture(params); } @@ -915,15 +916,15 @@ bool TextureCache::_loadHiresTexture(u32 _tile, CachedTexture *_pTexture, u64 & _ricecrc = txfilter_checksum(addr, tile_width, tile_height, (unsigned short)(_pTexture->format << 8 | _pTexture->size), bpl, paladdr); GHQTexInfo ghqTexInfo; if (txfilter_hirestex(_pTexture->crc, _ricecrc, palette, &ghqTexInfo)) { - graphics::Context::InitTextureParams params; - params.handle = graphics::ObjectHandle(_pTexture->glName); + Context::InitTextureParams params; + params.handle = _pTexture->name; params.mipMapLevel = 0; params.msaaLevel = 0; params.width = ghqTexInfo.width; params.height = ghqTexInfo.height; - params.internalFormat = graphics::Parameter(ghqTexInfo.format); - params.format = graphics::Parameter(ghqTexInfo.texture_format); - params.dataType = graphics::Parameter(ghqTexInfo.pixel_type); + params.internalFormat = Parameter(ghqTexInfo.format); + params.format = Parameter(ghqTexInfo.texture_format); + params.dataType = Parameter(ghqTexInfo.pixel_type); params.data = ghqTexInfo.data; gfxContext.init2DTexture(params); assert(!isGLError()); @@ -945,15 +946,15 @@ void TextureCache::_loadDepthTexture(CachedTexture * _pTexture, u16* _pDest) for (u32 t = 0; t < numTexels; ++t) pDestF[t] = _pDest[t] / 65535.0f; - graphics::Context::InitTextureParams params; - params.handle = graphics::ObjectHandle(_pTexture->glName); + Context::InitTextureParams params; + params.handle = _pTexture->name; params.mipMapLevel = 0; params.msaaLevel = 0; params.width = _pTexture->realWidth; params.height = _pTexture->realHeight; - params.internalFormat = graphics::internalcolor::RED; - params.format = graphics::color::RED; - params.dataType = graphics::datatype::FLOAT; + params.internalFormat = internalcolor::RED; + params.format = color::RED; + params.dataType = datatype::FLOAT; params.data = pDestF; gfxContext.init2DTexture(params); free(pDestF); @@ -1116,7 +1117,8 @@ void TextureCache::_load(u32 _tile, CachedTexture *_pTexture) if (config.generalEmulation.enableLOD != 0 && gSP.texture.level > 1) _pTexture->max_level = static_cast(_tile == 0 ? 0 : gSP.texture.level - 1); - CachedTexture tmptex(0); + ObjectHandle name; + CachedTexture tmptex(name); memcpy(&tmptex, _pTexture, sizeof(CachedTexture)); line = tmptex.line; @@ -1149,15 +1151,15 @@ void TextureCache::_load(u32 _tile, CachedTexture *_pTexture) if (txfilter_filter((u8*)pDest, tmptex.realWidth, tmptex.realHeight, glInternalFormat, (uint64)_pTexture->crc, &ghqTexInfo) != 0 && ghqTexInfo.data != nullptr) { - graphics::Context::InitTextureParams params; - params.handle = graphics::ObjectHandle(_pTexture->glName); + Context::InitTextureParams params; + params.handle = _pTexture->name; params.mipMapLevel = 0; params.msaaLevel = 0; params.width = ghqTexInfo.width; params.height = ghqTexInfo.height; - params.internalFormat = graphics::Parameter(ghqTexInfo.format); - params.format = graphics::Parameter(ghqTexInfo.texture_format); - params.dataType = graphics::Parameter(ghqTexInfo.pixel_type); + params.internalFormat = Parameter(ghqTexInfo.format); + params.format = Parameter(ghqTexInfo.texture_format); + params.dataType = Parameter(ghqTexInfo.pixel_type); params.data = ghqTexInfo.data; gfxContext.init2DTexture(params); _updateCachedTexture(ghqTexInfo, _pTexture); @@ -1169,16 +1171,16 @@ void TextureCache::_load(u32 _tile, CachedTexture *_pTexture) glInternalFormat != GL_RGBA && m_curUnpackAlignment > 1) glPixelStorei(GL_UNPACK_ALIGNMENT, 2); - graphics::Context::InitTextureParams params; - params.handle = graphics::ObjectHandle(_pTexture->glName); + Context::InitTextureParams params; + params.handle = _pTexture->name; params.mipMapLevel = mipLevel; params.mipMapLevels = _pTexture->max_level + 1; params.msaaLevel = 0; params.width = tmptex.realWidth; params.height = tmptex.realHeight; - params.internalFormat = graphics::Parameter(glInternalFormat); - params.format = graphics::color::RGBA; - params.dataType = graphics::Parameter(glType); + params.internalFormat = Parameter(glInternalFormat); + params.format = color::RGBA; + params.dataType = Parameter(glType); params.data = pDest; gfxContext.init2DTexture(params); } @@ -1249,69 +1251,69 @@ u32 _calculateCRC(u32 _t, const TextureParams & _params, u32 _bytes) void TextureCache::activateTexture(u32 _t, CachedTexture *_pTexture) { - graphics::Context::TexParameters params; - params.handle = graphics::ObjectHandle(_pTexture->glName); + Context::TexParameters params; + params.handle = _pTexture->name; if (config.video.multisampling > 0 && _pTexture->frameBufferTexture == CachedTexture::fbMultiSample) { - params.target = graphics::target::TEXTURE_2D_MULTISAMPLE; - params.textureUnitIndex = graphics::textureIndices::MSTex[_t]; + params.target = target::TEXTURE_2D_MULTISAMPLE; + params.textureUnitIndex = textureIndices::MSTex[_t]; } else { - params.target = graphics::target::TEXTURE_2D; - params.textureUnitIndex = graphics::textureIndices::Tex[_t]; + params.target = target::TEXTURE_2D; + params.textureUnitIndex = textureIndices::Tex[_t]; } 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; - params.maxMipmapLevel = graphics::Parameter(texLevel); + params.maxMipmapLevel = Parameter(texLevel); if (config.texture.bilinearMode == BILINEAR_STANDARD) { if (bUseBilinear) { if (texLevel > 0) - params.minFilter = graphics::textureParameters::FILTER_LINEAR_MIPMAP_NEAREST; + params.minFilter = textureParameters::FILTER_LINEAR_MIPMAP_NEAREST; else - params.minFilter = graphics::textureParameters::FILTER_LINEAR; - params.magFilter = graphics::textureParameters::FILTER_LINEAR; + params.minFilter = textureParameters::FILTER_LINEAR; + params.magFilter = textureParameters::FILTER_LINEAR; } else { if (texLevel > 0) - params.minFilter = graphics::textureParameters::FILTER_NEAREST_MIPMAP_NEAREST; + params.minFilter = textureParameters::FILTER_NEAREST_MIPMAP_NEAREST; else - params.minFilter = graphics::textureParameters::FILTER_NEAREST; - params.magFilter = graphics::textureParameters::FILTER_NEAREST; + params.minFilter = textureParameters::FILTER_NEAREST; + params.magFilter = textureParameters::FILTER_NEAREST; } } else { // 3 point filter if (texLevel > 0) { // Apply standard bilinear to mipmap textures if (bUseBilinear) { - params.minFilter = graphics::textureParameters::FILTER_LINEAR_MIPMAP_NEAREST; - params.magFilter = graphics::textureParameters::FILTER_LINEAR; + params.minFilter = textureParameters::FILTER_LINEAR_MIPMAP_NEAREST; + params.magFilter = textureParameters::FILTER_LINEAR; } else { - params.minFilter = graphics::textureParameters::FILTER_NEAREST_MIPMAP_NEAREST; - params.magFilter = graphics::textureParameters::FILTER_NEAREST; + params.minFilter = textureParameters::FILTER_NEAREST_MIPMAP_NEAREST; + params.magFilter = textureParameters::FILTER_NEAREST; } } else if (bUseBilinear && config.generalEmulation.enableLOD != 0 && bUseLOD) { // Apply standard bilinear to first tile of mipmap texture - params.minFilter = graphics::textureParameters::FILTER_LINEAR; - params.magFilter = graphics::textureParameters::FILTER_LINEAR; + params.minFilter = textureParameters::FILTER_LINEAR; + params.magFilter = textureParameters::FILTER_LINEAR; } else { // Don't use texture filter. Texture will be filtered by 3 point filter shader - params.minFilter = graphics::textureParameters::FILTER_NEAREST; - params.magFilter = graphics::textureParameters::FILTER_NEAREST; + params.minFilter = textureParameters::FILTER_NEAREST; + params.magFilter = textureParameters::FILTER_NEAREST; } } // Set clamping modes - params.wrapS = _pTexture->clampS ? graphics::textureParameters::WRAP_CLAMP_TO_EDGE : - _pTexture->mirrorS ? graphics::textureParameters::WRAP_MIRRORED_REPEAT - : graphics::textureParameters::WRAP_REPEAT; - params.wrapT = _pTexture->clampT ? graphics::textureParameters::WRAP_CLAMP_TO_EDGE : - _pTexture->mirrorT ? graphics::textureParameters::WRAP_MIRRORED_REPEAT - : graphics::textureParameters::WRAP_REPEAT; + params.wrapS = _pTexture->clampS ? textureParameters::WRAP_CLAMP_TO_EDGE : + _pTexture->mirrorS ? textureParameters::WRAP_MIRRORED_REPEAT + : textureParameters::WRAP_REPEAT; + params.wrapT = _pTexture->clampT ? textureParameters::WRAP_CLAMP_TO_EDGE : + _pTexture->mirrorT ? textureParameters::WRAP_MIRRORED_REPEAT + : textureParameters::WRAP_REPEAT; if (dwnd().getDrawer().getDrawingState() == DrawingState::Triangle && config.texture.maxAnisotropyF > 0.0f) - params.maxAnisotropy = graphics::Parameter(config.texture.maxAnisotropyF); + params.maxAnisotropy = Parameter(config.texture.maxAnisotropyF); gfxContext.setTextureParameters(params); @@ -1320,23 +1322,23 @@ void TextureCache::activateTexture(u32 _t, CachedTexture *_pTexture) void TextureCache::activateDummy(u32 _t) { - graphics::Context::TexParameters params; - params.handle = graphics::ObjectHandle(m_pDummy->glName); - params.target = graphics::target::TEXTURE_2D; - params.textureUnitIndex = graphics::textureIndices::Tex[_t]; - params.minFilter = graphics::textureParameters::FILTER_NEAREST; - params.magFilter = graphics::textureParameters::FILTER_NEAREST; + Context::TexParameters params; + params.handle = m_pDummy->name; + params.target = target::TEXTURE_2D; + params.textureUnitIndex = textureIndices::Tex[_t]; + params.minFilter = textureParameters::FILTER_NEAREST; + params.magFilter = textureParameters::FILTER_NEAREST; gfxContext.setTextureParameters(params); } void TextureCache::activateMSDummy(u32 _t) { - graphics::Context::TexParameters params; - params.handle = graphics::ObjectHandle(m_pMSDummy->glName); - params.target = graphics::target::TEXTURE_2D_MULTISAMPLE; - params.textureUnitIndex = graphics::textureIndices::MSTex[_t]; - params.minFilter = graphics::textureParameters::FILTER_NEAREST; - params.magFilter = graphics::textureParameters::FILTER_NEAREST; + Context::TexParameters params; + params.handle = m_pMSDummy->name; + params.target = target::TEXTURE_2D_MULTISAMPLE; + params.textureUnitIndex = textureIndices::MSTex[_t]; + params.minFilter = textureParameters::FILTER_NEAREST; + params.magFilter = textureParameters::FILTER_NEAREST; gfxContext.setTextureParameters(params); } @@ -1378,7 +1380,7 @@ void TextureCache::_updateBackground() glActiveTexture( GL_TEXTURE0 ); CachedTexture * pCurrent = _addTexture(crc); - glBindTexture( GL_TEXTURE_2D, pCurrent->glName ); + glBindTexture( GL_TEXTURE_2D, GLuint(pCurrent->name) ); pCurrent->address = gSP.bgImage.address; @@ -1424,13 +1426,10 @@ void TextureCache::_clear() { current[0] = current[1] = nullptr; - std::vector textureNames; - textureNames.reserve(m_textures.size()); - for (Textures::const_iterator cur = m_textures.cbegin(); cur != m_textures.cend(); ++cur) { + for (auto cur = m_textures.cbegin(); cur != m_textures.cend(); ++cur) { m_cachedBytes -= cur->textureBytes; - textureNames.push_back(cur->glName); + gfxContext.deleteTexture(cur->name); } - glDeleteTextures(textureNames.size(), textureNames.data()); m_textures.clear(); m_lruTextureLocations.clear(); } @@ -1531,7 +1530,7 @@ void TextureCache::update(u32 _t) CachedTexture * pCurrent = _addTexture(crc); - glBindTexture( GL_TEXTURE_2D, pCurrent->glName ); + glBindTexture( GL_TEXTURE_2D, GLuint(pCurrent->name) ); pCurrent->address = gDP.loadInfo[pTile->tmem].texAddress; diff --git a/src/Textures.h b/src/Textures.h index 054e7394..5068bae1 100644 --- a/src/Textures.h +++ b/src/Textures.h @@ -6,14 +6,15 @@ #include "CRC.h" #include "convert.h" +#include "Graphics/ObjectHandle.h" typedef u32 (*GetTexelFunc)( u64 *src, u16 x, u16 i, u8 palette ); struct CachedTexture { - CachedTexture(u32 _glName) : glName(_glName), max_level(0), frameBufferTexture(fbNone), bHDTexture(false) {} + CachedTexture(graphics::ObjectHandle _name) : name(_name), max_level(0), frameBufferTexture(fbNone), bHDTexture(false) {} - u32 glName; + graphics::ObjectHandle name; u32 crc; // float fulS, fulT; // WORD ulS, ulT, lrS, lrT; @@ -83,7 +84,7 @@ private: typedef std::list Textures; typedef std::map Texture_Locations; - typedef std::map FBTextures; + typedef std::map FBTextures; Textures m_textures; Texture_Locations m_lruTextureLocations; FBTextures m_fbTextures; diff --git a/src/ZlutTexture.cpp b/src/ZlutTexture.cpp index 670ac830..2d70b39d 100644 --- a/src/ZlutTexture.cpp +++ b/src/ZlutTexture.cpp @@ -43,7 +43,7 @@ void ZlutTexture::init() const FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats(); Context::InitTextureParams initParams; - initParams.handle = ObjectHandle(m_pTexture->glName); + initParams.handle = m_pTexture->name; initParams.ImageUnit = textureImageUnits::Zlut; initParams.width = m_pTexture->realWidth; initParams.height = m_pTexture->realHeight; @@ -54,7 +54,7 @@ void ZlutTexture::init() gfxContext.init2DTexture(initParams); Context::TexParameters setParams; - setParams.handle = ObjectHandle(m_pTexture->glName); + setParams.handle = m_pTexture->name; setParams.target = target::TEXTURE_2D; setParams.textureUnitIndex = textureIndices::ZLUTTex; setParams.minFilter = textureParameters::FILTER_NEAREST;