mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-04 10:03:36 +00:00
Add Context::bindImageTexture
This commit is contained in:
parent
f147927af9
commit
84b96aabd1
|
@ -110,6 +110,11 @@ void Context::setTextureParameters(const TexParameters & _parameters)
|
|||
m_impl->setTextureParameters(_parameters);
|
||||
}
|
||||
|
||||
void Context::bindImageTexture(const BindImageTextureParameters & _params)
|
||||
{
|
||||
m_impl->bindImageTexture(_params);
|
||||
}
|
||||
|
||||
/*---------------Framebuffer-------------*/
|
||||
|
||||
const FramebufferTextureFormats & Context::getFramebufferTextureFormats()
|
||||
|
|
|
@ -109,6 +109,15 @@ namespace graphics {
|
|||
|
||||
void setTextureParameters(const TexParameters & _parameters);
|
||||
|
||||
struct BindImageTextureParameters {
|
||||
Parameter imageUnit;
|
||||
ObjectHandle texture;
|
||||
Parameter accessMode;
|
||||
Parameter textureFormat;
|
||||
};
|
||||
|
||||
void bindImageTexture(const BindImageTextureParameters & _params);
|
||||
|
||||
/*---------------Framebuffer-------------*/
|
||||
|
||||
const FramebufferTextureFormats & getFramebufferTextureFormats();
|
||||
|
|
|
@ -28,6 +28,7 @@ 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 bindImageTexture(const Context::BindImageTextureParameters & _params) = 0;
|
||||
virtual FramebufferTextureFormats * getFramebufferTextureFormats() = 0;
|
||||
virtual ObjectHandle createFramebuffer() = 0;
|
||||
virtual void deleteFramebuffer(ObjectHandle _name) = 0;
|
||||
|
|
|
@ -178,6 +178,12 @@ void ContextImpl::setTextureParameters(const graphics::Context::TexParameters &
|
|||
m_set2DTextureParameters->setTextureParameters(_parameters);
|
||||
}
|
||||
|
||||
void ContextImpl::bindImageTexture(const graphics::Context::BindImageTextureParameters & _params)
|
||||
{
|
||||
if (glBindImageTexture != nullptr)
|
||||
glBindImageTexture(GLuint(_params.imageUnit), GLuint(_params.texture), 0, GL_FALSE, 0, GLenum(_params.accessMode), GLenum(_params.textureFormat));
|
||||
}
|
||||
|
||||
/*---------------Framebuffer-------------*/
|
||||
|
||||
graphics::FramebufferTextureFormats * ContextImpl::getFramebufferTextureFormats()
|
||||
|
|
|
@ -59,6 +59,8 @@ namespace opengl {
|
|||
|
||||
void setTextureParameters(const graphics::Context::TexParameters & _parameters) override;
|
||||
|
||||
void bindImageTexture(const graphics::Context::BindImageTextureParameters & _params) override;
|
||||
|
||||
/*---------------Framebuffer-------------*/
|
||||
|
||||
graphics::FramebufferTextureFormats * getFramebufferTextureFormats() override;
|
||||
|
|
|
@ -68,6 +68,12 @@ namespace graphics {
|
|||
Parameter Depth(2U);
|
||||
}
|
||||
|
||||
namespace textureImageAccessMode {
|
||||
Parameter READ_ONLY(GL_READ_ONLY);
|
||||
Parameter WRITE_ONLY(GL_WRITE_ONLY);
|
||||
Parameter READ_WRITE(GL_READ_WRITE);
|
||||
}
|
||||
|
||||
namespace textureParameters {
|
||||
Parameter FILTER_NEAREST(GL_NEAREST);
|
||||
Parameter FILTER_LINEAR(GL_LINEAR);
|
||||
|
|
|
@ -68,6 +68,12 @@ namespace graphics {
|
|||
extern Parameter Depth;
|
||||
}
|
||||
|
||||
namespace textureImageAccessMode {
|
||||
extern Parameter READ_ONLY;
|
||||
extern Parameter WRITE_ONLY;
|
||||
extern Parameter READ_WRITE;
|
||||
}
|
||||
|
||||
namespace textureParameters {
|
||||
extern Parameter FILTER_NEAREST;
|
||||
extern Parameter FILTER_LINEAR;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
|
||||
PaletteTexture g_paletteTexture;
|
||||
using namespace graphics;
|
||||
|
||||
PaletteTexture::PaletteTexture()
|
||||
: m_pTexture(nullptr)
|
||||
|
@ -38,10 +39,10 @@ void PaletteTexture::init()
|
|||
#endif
|
||||
textureCache().addFrameBufferTextureSize(m_pTexture->textureBytes);
|
||||
|
||||
const graphics::FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats();
|
||||
graphics::Context::InitTextureParams initParams;
|
||||
initParams.handle = graphics::ObjectHandle(m_pTexture->glName);
|
||||
initParams.ImageUnit = graphics::textureImageUnits::Tlut;
|
||||
const FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats();
|
||||
Context::InitTextureParams initParams;
|
||||
initParams.handle = ObjectHandle(m_pTexture->glName);
|
||||
initParams.ImageUnit = textureImageUnits::Tlut;
|
||||
initParams.width = m_pTexture->realWidth;
|
||||
initParams.height = m_pTexture->realHeight;
|
||||
initParams.internalFormat = fbTexFormats.lutInternalFormat;
|
||||
|
@ -49,14 +50,14 @@ void PaletteTexture::init()
|
|||
initParams.dataType = fbTexFormats.lutType;
|
||||
gfxContext.init2DTexture(initParams);
|
||||
|
||||
graphics::Context::TexParameters setParams;
|
||||
setParams.handle = graphics::ObjectHandle(m_pTexture->glName);
|
||||
setParams.target = graphics::target::TEXTURE_2D;
|
||||
setParams.textureUnitIndex = graphics::textureIndices::PaletteTex;
|
||||
setParams.minFilter = graphics::textureParameters::FILTER_NEAREST;
|
||||
setParams.magFilter = graphics::textureParameters::FILTER_NEAREST;
|
||||
setParams.wrapS = graphics::textureParameters::WRAP_CLAMP_TO_EDGE;
|
||||
setParams.wrapT = graphics::textureParameters::WRAP_CLAMP_TO_EDGE;
|
||||
Context::TexParameters setParams;
|
||||
setParams.handle = ObjectHandle(m_pTexture->glName);
|
||||
setParams.target = target::TEXTURE_2D;
|
||||
setParams.textureUnitIndex = textureIndices::PaletteTex;
|
||||
setParams.minFilter = textureParameters::FILTER_NEAREST;
|
||||
setParams.magFilter = textureParameters::FILTER_NEAREST;
|
||||
setParams.wrapS = textureParameters::WRAP_CLAMP_TO_EDGE;
|
||||
setParams.wrapT = textureParameters::WRAP_CLAMP_TO_EDGE;
|
||||
gfxContext.setTextureParameters(setParams);
|
||||
|
||||
// Generate Pixel Buffer Object. Initialize it with max buffer size.
|
||||
|
@ -66,8 +67,16 @@ void PaletteTexture::init()
|
|||
|
||||
void PaletteTexture::destroy()
|
||||
{
|
||||
const graphics::FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats();
|
||||
glBindImageTexture(TlutImageUnit, 0, 0, GL_FALSE, 0, GL_READ_ONLY, GLenum(fbTexFormats.lutInternalFormat));
|
||||
const FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats();
|
||||
|
||||
Context::BindImageTextureParameters bindParams;
|
||||
bindParams.imageUnit = textureImageUnits::Tlut;
|
||||
bindParams.texture = ObjectHandle();
|
||||
bindParams.accessMode = textureImageAccessMode::READ_ONLY;
|
||||
bindParams.textureFormat = fbTexFormats.lutInternalFormat;
|
||||
|
||||
gfxContext.bindImageTexture(bindParams);
|
||||
|
||||
textureCache().removeFrameBufferTexture(m_pTexture);
|
||||
m_pTexture = nullptr;
|
||||
m_pbuf.reset();
|
||||
|
@ -80,7 +89,7 @@ void PaletteTexture::update()
|
|||
|
||||
m_paletteCRC256 = gDP.paletteCRC256;
|
||||
|
||||
graphics::PixelBufferBinder<graphics::PixelWriteBuffer> binder(m_pbuf.get());
|
||||
PixelBufferBinder<PixelWriteBuffer> binder(m_pbuf.get());
|
||||
GLubyte* ptr = (GLubyte*)m_pbuf->getWriteBuffer(m_pTexture->textureBytes);
|
||||
#ifdef GLESX
|
||||
u32 * palette = (u32*)ptr;
|
||||
|
@ -92,17 +101,16 @@ void PaletteTexture::update()
|
|||
palette[i] = swapword(src[i * 4]);
|
||||
m_pbuf->closeWriteBuffer();
|
||||
|
||||
const graphics::FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats();
|
||||
graphics::Context::UpdateTextureDataParams params;
|
||||
params.handle = graphics::ObjectHandle(m_pTexture->glName);
|
||||
params.ImageUnit = graphics::textureImageUnits::Tlut;
|
||||
params.textureUnitIndex = graphics::textureIndices::PaletteTex;
|
||||
const FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats();
|
||||
Context::UpdateTextureDataParams params;
|
||||
params.handle = ObjectHandle(m_pTexture->glName);
|
||||
params.ImageUnit = textureImageUnits::Tlut;
|
||||
params.textureUnitIndex = textureIndices::PaletteTex;
|
||||
params.width = m_pTexture->realWidth;
|
||||
params.height = m_pTexture->realHeight;
|
||||
params.format = fbTexFormats.lutFormat;
|
||||
params.internalFormat = fbTexFormats.lutInternalFormat;
|
||||
params.dataType = fbTexFormats.lutType;
|
||||
params.data = m_pbuf->getData();
|
||||
glBindImageTexture(TlutImageUnit, 0, 0, GL_FALSE, 0, GL_READ_ONLY, GLenum(fbTexFormats.lutInternalFormat));
|
||||
gfxContext.update2DTexture(params);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "Textures.h"
|
||||
#include "ZlutTexture.h"
|
||||
|
||||
using namespace graphics;
|
||||
|
||||
ZlutTexture g_zlutTexture;
|
||||
|
||||
|
@ -40,10 +41,10 @@ void ZlutTexture::init()
|
|||
m_pTexture->textureBytes = m_pTexture->realWidth * m_pTexture->realHeight * sizeof(zLUT[0]);
|
||||
textureCache().addFrameBufferTextureSize(m_pTexture->textureBytes);
|
||||
|
||||
const graphics::FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats();
|
||||
graphics::Context::InitTextureParams initParams;
|
||||
initParams.handle = graphics::ObjectHandle(m_pTexture->glName);
|
||||
initParams.ImageUnit = graphics::textureImageUnits::Zlut;
|
||||
const FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats();
|
||||
Context::InitTextureParams initParams;
|
||||
initParams.handle = ObjectHandle(m_pTexture->glName);
|
||||
initParams.ImageUnit = textureImageUnits::Zlut;
|
||||
initParams.width = m_pTexture->realWidth;
|
||||
initParams.height = m_pTexture->realHeight;
|
||||
initParams.internalFormat = fbTexFormats.lutInternalFormat;
|
||||
|
@ -52,20 +53,28 @@ void ZlutTexture::init()
|
|||
initParams.data = zLUT;
|
||||
gfxContext.init2DTexture(initParams);
|
||||
|
||||
graphics::Context::TexParameters setParams;
|
||||
setParams.handle = graphics::ObjectHandle(m_pTexture->glName);
|
||||
setParams.target = graphics::target::TEXTURE_2D;
|
||||
setParams.textureUnitIndex = graphics::textureIndices::ZLUTTex;
|
||||
setParams.minFilter = graphics::textureParameters::FILTER_NEAREST;
|
||||
setParams.magFilter = graphics::textureParameters::FILTER_NEAREST;
|
||||
setParams.wrapS = graphics::textureParameters::WRAP_CLAMP_TO_EDGE;
|
||||
setParams.wrapT = graphics::textureParameters::WRAP_CLAMP_TO_EDGE;
|
||||
Context::TexParameters setParams;
|
||||
setParams.handle = ObjectHandle(m_pTexture->glName);
|
||||
setParams.target = target::TEXTURE_2D;
|
||||
setParams.textureUnitIndex = textureIndices::ZLUTTex;
|
||||
setParams.minFilter = textureParameters::FILTER_NEAREST;
|
||||
setParams.magFilter = textureParameters::FILTER_NEAREST;
|
||||
setParams.wrapS = textureParameters::WRAP_CLAMP_TO_EDGE;
|
||||
setParams.wrapT = textureParameters::WRAP_CLAMP_TO_EDGE;
|
||||
gfxContext.setTextureParameters(setParams);
|
||||
}
|
||||
|
||||
void ZlutTexture::destroy() {
|
||||
const graphics::FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats();
|
||||
glBindImageTexture(ZlutImageUnit, 0, 0, GL_FALSE, GL_FALSE, GL_READ_ONLY, GLenum(fbTexFormats.lutInternalFormat));
|
||||
const FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats();
|
||||
|
||||
Context::BindImageTextureParameters bindParams;
|
||||
bindParams.imageUnit = textureImageUnits::Zlut;
|
||||
bindParams.texture = ObjectHandle();
|
||||
bindParams.accessMode = textureImageAccessMode::READ_ONLY;
|
||||
bindParams.textureFormat = fbTexFormats.lutInternalFormat;
|
||||
|
||||
gfxContext.bindImageTexture(bindParams);
|
||||
|
||||
textureCache().removeFrameBufferTexture(m_pTexture);
|
||||
m_pTexture = nullptr;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user