mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-04 10:03:36 +00:00
Remove OpenGL from DepthBuffer.
This commit is contained in:
parent
84b96aabd1
commit
f64136ff3b
|
@ -22,14 +22,13 @@ const GLuint depthImageUnit = 2;
|
||||||
using namespace graphics;
|
using namespace graphics;
|
||||||
|
|
||||||
DepthBuffer::DepthBuffer() : m_address(0), m_width(0), m_ulx(0), m_uly(0), m_lrx(0), m_lry(0),
|
DepthBuffer::DepthBuffer() : m_address(0), m_width(0), m_ulx(0), m_uly(0), m_lrx(0), m_lry(0),
|
||||||
m_depthImageFBO(0), m_pDepthImageTexture(nullptr), m_pDepthBufferTexture(nullptr),
|
m_pDepthImageTexture(nullptr), m_pDepthBufferTexture(nullptr), m_depthRenderbufferWidth(0),
|
||||||
m_depthRenderbuffer(0), m_depthRenderbufferWidth(0),
|
|
||||||
m_cleared(false), m_pResolveDepthBufferTexture(nullptr), m_resolved(false),
|
m_cleared(false), m_pResolveDepthBufferTexture(nullptr), m_resolved(false),
|
||||||
m_pDepthBufferCopyTexture(nullptr), m_copied(false)
|
m_pDepthBufferCopyTexture(nullptr), m_copied(false)
|
||||||
{
|
{
|
||||||
m_copyFBO = GLuint(gfxContext.createFramebuffer());
|
m_copyFBO = gfxContext.createFramebuffer();
|
||||||
if (Context::imageTextures && config.frameBufferEmulation.N64DepthCompare != 0)
|
if (Context::imageTextures && config.frameBufferEmulation.N64DepthCompare != 0)
|
||||||
m_depthImageFBO = GLuint(gfxContext.createFramebuffer());
|
m_depthImageFBO = gfxContext.createFramebuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
DepthBuffer::DepthBuffer(DepthBuffer && _other) :
|
DepthBuffer::DepthBuffer(DepthBuffer && _other) :
|
||||||
|
@ -40,10 +39,10 @@ DepthBuffer::DepthBuffer(DepthBuffer && _other) :
|
||||||
m_cleared(_other.m_cleared), m_pResolveDepthBufferTexture(_other.m_pResolveDepthBufferTexture), m_resolved(_other.m_resolved),
|
m_cleared(_other.m_cleared), m_pResolveDepthBufferTexture(_other.m_pResolveDepthBufferTexture), m_resolved(_other.m_resolved),
|
||||||
m_pDepthBufferCopyTexture(_other.m_pDepthBufferCopyTexture), m_copied(_other.m_copied)
|
m_pDepthBufferCopyTexture(_other.m_pDepthBufferCopyTexture), m_copied(_other.m_copied)
|
||||||
{
|
{
|
||||||
_other.m_depthImageFBO = 0;
|
_other.m_depthImageFBO = ObjectHandle();
|
||||||
_other.m_pDepthImageTexture = nullptr;
|
_other.m_pDepthImageTexture = nullptr;
|
||||||
_other.m_pDepthBufferTexture = nullptr;
|
_other.m_pDepthBufferTexture = nullptr;
|
||||||
_other.m_depthRenderbuffer = 0;
|
_other.m_depthRenderbuffer = ObjectHandle();
|
||||||
_other.m_pResolveDepthBufferTexture = nullptr;
|
_other.m_pResolveDepthBufferTexture = nullptr;
|
||||||
_other.m_resolved = false;
|
_other.m_resolved = false;
|
||||||
_other.m_pDepthBufferCopyTexture = nullptr;
|
_other.m_pDepthBufferCopyTexture = nullptr;
|
||||||
|
@ -52,9 +51,9 @@ DepthBuffer::DepthBuffer(DepthBuffer && _other) :
|
||||||
|
|
||||||
DepthBuffer::~DepthBuffer()
|
DepthBuffer::~DepthBuffer()
|
||||||
{
|
{
|
||||||
gfxContext.deleteFramebuffer(graphics::ObjectHandle(m_depthImageFBO));
|
gfxContext.deleteFramebuffer(m_depthImageFBO);
|
||||||
gfxContext.deleteFramebuffer(graphics::ObjectHandle(m_depthRenderbuffer));
|
gfxContext.deleteFramebuffer(m_depthRenderbuffer);
|
||||||
gfxContext.deleteFramebuffer(graphics::ObjectHandle(m_copyFBO));
|
gfxContext.deleteFramebuffer(m_copyFBO);
|
||||||
|
|
||||||
textureCache().removeFrameBufferTexture(m_pDepthImageTexture);
|
textureCache().removeFrameBufferTexture(m_pDepthImageTexture);
|
||||||
textureCache().removeFrameBufferTexture(m_pDepthBufferTexture);
|
textureCache().removeFrameBufferTexture(m_pDepthBufferTexture);
|
||||||
|
@ -67,7 +66,7 @@ void DepthBuffer::initDepthImageTexture(FrameBuffer * _pBuffer)
|
||||||
if (!Context::imageTextures || config.frameBufferEmulation.N64DepthCompare == 0 || m_pDepthImageTexture != nullptr)
|
if (!Context::imageTextures || config.frameBufferEmulation.N64DepthCompare == 0 || m_pDepthImageTexture != nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const graphics::FramebufferTextureFormats & fbTexFormat = gfxContext.getFramebufferTextureFormats();
|
const FramebufferTextureFormats & fbTexFormat = gfxContext.getFramebufferTextureFormats();
|
||||||
m_pDepthImageTexture = textureCache().addFrameBufferTexture(false);
|
m_pDepthImageTexture = textureCache().addFrameBufferTexture(false);
|
||||||
|
|
||||||
m_pDepthImageTexture->width = (u32)(_pBuffer->m_pTexture->width);
|
m_pDepthImageTexture->width = (u32)(_pBuffer->m_pTexture->width);
|
||||||
|
@ -90,8 +89,8 @@ void DepthBuffer::initDepthImageTexture(FrameBuffer * _pBuffer)
|
||||||
textureCache().addFrameBufferTextureSize(m_pDepthImageTexture->textureBytes);
|
textureCache().addFrameBufferTextureSize(m_pDepthImageTexture->textureBytes);
|
||||||
|
|
||||||
{
|
{
|
||||||
graphics::Context::InitTextureParams params;
|
Context::InitTextureParams params;
|
||||||
params.handle = graphics::ObjectHandle(m_pDepthImageTexture->glName);
|
params.handle = ObjectHandle(m_pDepthImageTexture->glName);
|
||||||
params.width = m_pDepthImageTexture->realWidth;
|
params.width = m_pDepthImageTexture->realWidth;
|
||||||
params.height = m_pDepthImageTexture->realHeight;
|
params.height = m_pDepthImageTexture->realHeight;
|
||||||
params.internalFormat = fbTexFormat.depthImageInternalFormat;
|
params.internalFormat = fbTexFormat.depthImageInternalFormat;
|
||||||
|
@ -100,32 +99,32 @@ void DepthBuffer::initDepthImageTexture(FrameBuffer * _pBuffer)
|
||||||
gfxContext.init2DTexture(params);
|
gfxContext.init2DTexture(params);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
graphics::Context::TexParameters params;
|
Context::TexParameters params;
|
||||||
params.handle = graphics::ObjectHandle(m_pDepthImageTexture->glName);
|
params.handle = ObjectHandle(m_pDepthImageTexture->glName);
|
||||||
params.target = graphics::target::TEXTURE_2D;
|
params.target = target::TEXTURE_2D;
|
||||||
params.textureUnitIndex = graphics::textureIndices::Tex[0];
|
params.textureUnitIndex = textureIndices::Tex[0];
|
||||||
params.minFilter = graphics::textureParameters::FILTER_NEAREST;
|
params.minFilter = textureParameters::FILTER_NEAREST;
|
||||||
params.magFilter = graphics::textureParameters::FILTER_NEAREST;
|
params.magFilter = textureParameters::FILTER_NEAREST;
|
||||||
gfxContext.setTextureParameters(params);
|
gfxContext.setTextureParameters(params);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
graphics::Context::FrameBufferRenderTarget bufTarget;
|
Context::FrameBufferRenderTarget bufTarget;
|
||||||
bufTarget.bufferHandle = graphics::ObjectHandle(m_depthImageFBO);
|
bufTarget.bufferHandle = m_depthImageFBO;
|
||||||
bufTarget.bufferTarget = graphics::bufferTarget::DRAW_FRAMEBUFFER;
|
bufTarget.bufferTarget = bufferTarget::DRAW_FRAMEBUFFER;
|
||||||
bufTarget.attachment = graphics::bufferAttachment::COLOR_ATTACHMENT0;
|
bufTarget.attachment = bufferAttachment::COLOR_ATTACHMENT0;
|
||||||
bufTarget.textureTarget = graphics::target::TEXTURE_2D;
|
bufTarget.textureTarget = target::TEXTURE_2D;
|
||||||
bufTarget.textureHandle = graphics::ObjectHandle(m_pDepthImageTexture->glName);
|
bufTarget.textureHandle = ObjectHandle(m_pDepthImageTexture->glName);
|
||||||
gfxContext.addFrameBufferRenderTarget(bufTarget);
|
gfxContext.addFrameBufferRenderTarget(bufTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, GLuint(_pBuffer->m_FBO));
|
gfxContext.bindFramebuffer(bufferTarget::DRAW_FRAMEBUFFER, _pBuffer->m_FBO);
|
||||||
|
|
||||||
depthBufferList().clearBuffer(0, 0, VI.width, VI.height);
|
depthBufferList().clearBuffer(0, 0, VI.width, VI.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DepthBuffer::_initDepthBufferTexture(FrameBuffer * _pBuffer, CachedTexture * _pTexture, bool _multisample)
|
void DepthBuffer::_initDepthBufferTexture(FrameBuffer * _pBuffer, CachedTexture * _pTexture, bool _multisample)
|
||||||
{
|
{
|
||||||
const graphics::FramebufferTextureFormats & fbTexFormat = gfxContext.getFramebufferTextureFormats();
|
const FramebufferTextureFormats & fbTexFormat = gfxContext.getFramebufferTextureFormats();
|
||||||
|
|
||||||
if (_pBuffer != nullptr) {
|
if (_pBuffer != nullptr) {
|
||||||
_pTexture->width = (u32)(_pBuffer->m_pTexture->width);
|
_pTexture->width = (u32)(_pBuffer->m_pTexture->width);
|
||||||
|
@ -160,8 +159,8 @@ void DepthBuffer::_initDepthBufferTexture(FrameBuffer * _pBuffer, CachedTexture
|
||||||
textureCache().addFrameBufferTextureSize(_pTexture->textureBytes);
|
textureCache().addFrameBufferTextureSize(_pTexture->textureBytes);
|
||||||
|
|
||||||
{
|
{
|
||||||
graphics::Context::InitTextureParams params;
|
Context::InitTextureParams params;
|
||||||
params.handle = graphics::ObjectHandle(_pTexture->glName);
|
params.handle = ObjectHandle(_pTexture->glName);
|
||||||
params.msaaLevel = _multisample ? config.video.multisampling : 0U;
|
params.msaaLevel = _multisample ? config.video.multisampling : 0U;
|
||||||
params.width = _pTexture->realWidth;
|
params.width = _pTexture->realWidth;
|
||||||
params.height = _pTexture->realHeight;
|
params.height = _pTexture->realHeight;
|
||||||
|
@ -172,12 +171,12 @@ void DepthBuffer::_initDepthBufferTexture(FrameBuffer * _pBuffer, CachedTexture
|
||||||
}
|
}
|
||||||
_pTexture->frameBufferTexture = _multisample ? CachedTexture::fbMultiSample : CachedTexture::fbOneSample;
|
_pTexture->frameBufferTexture = _multisample ? CachedTexture::fbMultiSample : CachedTexture::fbOneSample;
|
||||||
{
|
{
|
||||||
graphics::Context::TexParameters params;
|
Context::TexParameters params;
|
||||||
params.handle = graphics::ObjectHandle(_pTexture->glName);
|
params.handle = ObjectHandle(_pTexture->glName);
|
||||||
params.target = _multisample ? graphics::target::TEXTURE_2D_MULTISAMPLE : graphics::target::TEXTURE_2D;
|
params.target = _multisample ? target::TEXTURE_2D_MULTISAMPLE : target::TEXTURE_2D;
|
||||||
params.textureUnitIndex = graphics::textureIndices::Tex[0];
|
params.textureUnitIndex = textureIndices::Tex[0];
|
||||||
params.minFilter = graphics::textureParameters::FILTER_NEAREST;
|
params.minFilter = textureParameters::FILTER_NEAREST;
|
||||||
params.magFilter = graphics::textureParameters::FILTER_NEAREST;
|
params.magFilter = textureParameters::FILTER_NEAREST;
|
||||||
gfxContext.setTextureParameters(params);
|
gfxContext.setTextureParameters(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +184,7 @@ void DepthBuffer::_initDepthBufferTexture(FrameBuffer * _pBuffer, CachedTexture
|
||||||
|
|
||||||
void DepthBuffer::_initDepthBufferRenderbuffer(FrameBuffer * _pBuffer)
|
void DepthBuffer::_initDepthBufferRenderbuffer(FrameBuffer * _pBuffer)
|
||||||
{
|
{
|
||||||
if (m_depthRenderbuffer != 0)
|
if (m_depthRenderbuffer.isNotNull())
|
||||||
return;
|
return;
|
||||||
u32 height;
|
u32 height;
|
||||||
if (_pBuffer != NULL) {
|
if (_pBuffer != NULL) {
|
||||||
|
@ -201,30 +200,29 @@ void DepthBuffer::_initDepthBufferRenderbuffer(FrameBuffer * _pBuffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
graphics::ObjectHandle renderbufHandle = gfxContext.createRenderbuffer();
|
m_depthRenderbuffer = gfxContext.createRenderbuffer();
|
||||||
m_depthRenderbuffer = GLuint(renderbufHandle);
|
Context::InitRenderbufferParams params;
|
||||||
graphics::Context::InitRenderbufferParams params;
|
params.handle = m_depthRenderbuffer;
|
||||||
params.handle = renderbufHandle;
|
params.target = target::RENDERBUFFER;
|
||||||
params.target = graphics::target::RENDERBUFFER;
|
|
||||||
params.format = gfxContext.getFramebufferTextureFormats().depthInternalFormat;
|
params.format = gfxContext.getFramebufferTextureFormats().depthInternalFormat;
|
||||||
params.width = m_depthRenderbufferWidth;
|
params.width = m_depthRenderbufferWidth;
|
||||||
params.height = height;
|
params.height = height;
|
||||||
gfxContext.initRenderbuffer(params);
|
gfxContext.initRenderbuffer(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DepthBuffer::setDepthAttachment(GLuint _fbo, GLenum _target)
|
void DepthBuffer::setDepthAttachment(ObjectHandle _fbo, Parameter _target)
|
||||||
{
|
{
|
||||||
graphics::Context::FrameBufferRenderTarget params;
|
Context::FrameBufferRenderTarget params;
|
||||||
params.attachment = graphics::bufferAttachment::DEPTH_ATTACHMENT;
|
params.attachment = bufferAttachment::DEPTH_ATTACHMENT;
|
||||||
params.bufferHandle = graphics::ObjectHandle(_fbo);
|
params.bufferHandle = _fbo;
|
||||||
params.bufferTarget = _target;
|
params.bufferTarget = _target;
|
||||||
#ifndef USE_DEPTH_RENDERBUFFER
|
if (gfxContext.isSupported(SpecialFeatures::DepthFramebufferTextures)) {
|
||||||
params.textureHandle = graphics::ObjectHandle(m_pDepthBufferTexture->glName);
|
params.textureHandle = ObjectHandle(m_pDepthBufferTexture->glName);
|
||||||
params.textureTarget = config.video.multisampling != 0 ? graphics::target::TEXTURE_2D_MULTISAMPLE : graphics::target::TEXTURE_2D;
|
params.textureTarget = config.video.multisampling != 0 ? target::TEXTURE_2D_MULTISAMPLE : target::TEXTURE_2D;
|
||||||
#else
|
} else {
|
||||||
params.textureHandle = graphics::ObjectHandle(m_depthRenderbuffer);
|
params.textureHandle = m_depthRenderbuffer;
|
||||||
params.textureTarget = graphics::target::RENDERBUFFER;
|
params.textureTarget = target::RENDERBUFFER;
|
||||||
#endif // USE_DEPTH_RENDERBUFFER
|
}
|
||||||
gfxContext.addFrameBufferRenderTarget(params);
|
gfxContext.addFrameBufferRenderTarget(params);
|
||||||
|
|
||||||
m_copied = false;
|
m_copied = false;
|
||||||
|
@ -233,55 +231,60 @@ void DepthBuffer::setDepthAttachment(GLuint _fbo, GLenum _target)
|
||||||
|
|
||||||
void DepthBuffer::initDepthBufferTexture(FrameBuffer * _pBuffer)
|
void DepthBuffer::initDepthBufferTexture(FrameBuffer * _pBuffer)
|
||||||
{
|
{
|
||||||
#ifndef USE_DEPTH_RENDERBUFFER
|
if (gfxContext.isSupported(SpecialFeatures::DepthFramebufferTextures)) {
|
||||||
if (m_pDepthBufferTexture == nullptr) {
|
if (m_pDepthBufferTexture == nullptr) {
|
||||||
m_pDepthBufferTexture = textureCache().addFrameBufferTexture(config.video.multisampling != 0);
|
m_pDepthBufferTexture = textureCache().addFrameBufferTexture(config.video.multisampling != 0);
|
||||||
_initDepthBufferTexture(_pBuffer, m_pDepthBufferTexture, config.video.multisampling != 0);
|
_initDepthBufferTexture(_pBuffer, m_pDepthBufferTexture, config.video.multisampling != 0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_initDepthBufferRenderbuffer(_pBuffer);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
_initDepthBufferRenderbuffer(_pBuffer);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GL_MULTISAMPLING_SUPPORT
|
|
||||||
if (config.video.multisampling != 0 && m_pResolveDepthBufferTexture == nullptr) {
|
if (config.video.multisampling != 0 && m_pResolveDepthBufferTexture == nullptr) {
|
||||||
m_pResolveDepthBufferTexture = textureCache().addFrameBufferTexture(false);
|
m_pResolveDepthBufferTexture = textureCache().addFrameBufferTexture(false);
|
||||||
_initDepthBufferTexture(_pBuffer, m_pResolveDepthBufferTexture, false);
|
_initDepthBufferTexture(_pBuffer, m_pResolveDepthBufferTexture, false);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CachedTexture * DepthBuffer::resolveDepthBufferTexture(FrameBuffer * _pBuffer)
|
CachedTexture * DepthBuffer::resolveDepthBufferTexture(FrameBuffer * _pBuffer)
|
||||||
{
|
{
|
||||||
#ifdef GL_MULTISAMPLING_SUPPORT
|
|
||||||
if (config.video.multisampling == 0)
|
if (config.video.multisampling == 0)
|
||||||
return m_pDepthBufferTexture;
|
return m_pDepthBufferTexture;
|
||||||
|
|
||||||
if (m_resolved)
|
if (m_resolved)
|
||||||
return m_pResolveDepthBufferTexture;
|
return m_pResolveDepthBufferTexture;
|
||||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, GLuint(_pBuffer->m_FBO));
|
|
||||||
glReadBuffer(GL_COLOR_ATTACHMENT0);
|
Context::FrameBufferRenderTarget targetParams;
|
||||||
GLuint attachment = GL_COLOR_ATTACHMENT0;
|
targetParams.attachment = bufferAttachment::DEPTH_ATTACHMENT;
|
||||||
glDrawBuffers(1, &attachment);
|
targetParams.bufferHandle = _pBuffer->m_resolveFBO;
|
||||||
assert(checkFBO());
|
targetParams.bufferTarget = bufferTarget::DRAW_FRAMEBUFFER;
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, GLuint(_pBuffer->m_resolveFBO));
|
targetParams.textureHandle = ObjectHandle(m_pResolveDepthBufferTexture->glName);
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_pResolveDepthBufferTexture->glName, 0);
|
targetParams.textureTarget = target::TEXTURE_2D;
|
||||||
assert(checkFBO());
|
gfxContext.addFrameBufferRenderTarget(targetParams);
|
||||||
glDisable(GL_SCISSOR_TEST);
|
|
||||||
glBlitFramebuffer(
|
Context::BlitFramebuffersParams blitParams;
|
||||||
0, 0, m_pDepthBufferTexture->realWidth, m_pDepthBufferTexture->realHeight,
|
blitParams.readBuffer = _pBuffer->m_FBO;
|
||||||
0, 0, m_pResolveDepthBufferTexture->realWidth, m_pResolveDepthBufferTexture->realHeight,
|
blitParams.drawBuffer = _pBuffer->m_resolveFBO;
|
||||||
GL_DEPTH_BUFFER_BIT, GL_NEAREST
|
blitParams.srcX0 = 0;
|
||||||
);
|
blitParams.srcY0 = 0;
|
||||||
glEnable(GL_SCISSOR_TEST);
|
blitParams.srcX1 = m_pDepthBufferTexture->realWidth;
|
||||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
blitParams.srcY1 = m_pDepthBufferTexture->realHeight;
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, GLuint(_pBuffer->m_FBO));
|
blitParams.dstX0 = 0;
|
||||||
|
blitParams.dstY0 = 0;
|
||||||
|
blitParams.dstX1 = m_pResolveDepthBufferTexture->realWidth;
|
||||||
|
blitParams.dstY1 = m_pResolveDepthBufferTexture->realHeight;
|
||||||
|
blitParams.mask = blitMask::DEPTH_BUFFER;
|
||||||
|
blitParams.filter = textureParameters::FILTER_NEAREST;
|
||||||
|
|
||||||
|
gfxContext.blitFramebuffers(blitParams);
|
||||||
|
|
||||||
|
gfxContext.bindFramebuffer(bufferTarget::READ_FRAMEBUFFER, ObjectHandle());
|
||||||
|
gfxContext.bindFramebuffer(bufferTarget::DRAW_FRAMEBUFFER, _pBuffer->m_FBO);
|
||||||
|
|
||||||
m_resolved = true;
|
m_resolved = true;
|
||||||
return m_pResolveDepthBufferTexture;
|
return m_pResolveDepthBufferTexture;
|
||||||
#else
|
|
||||||
return m_pDepthBufferTexture;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef GLES2
|
|
||||||
CachedTexture * DepthBuffer::copyDepthBufferTexture(FrameBuffer * _pBuffer)
|
CachedTexture * DepthBuffer::copyDepthBufferTexture(FrameBuffer * _pBuffer)
|
||||||
{
|
{
|
||||||
if (m_copied)
|
if (m_copied)
|
||||||
|
@ -292,30 +295,46 @@ CachedTexture * DepthBuffer::copyDepthBufferTexture(FrameBuffer * _pBuffer)
|
||||||
_initDepthBufferTexture(_pBuffer, m_pDepthBufferCopyTexture, false);
|
_initDepthBufferTexture(_pBuffer, m_pDepthBufferCopyTexture, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, GLuint(_pBuffer->m_FBO));
|
|
||||||
glReadBuffer(GL_COLOR_ATTACHMENT0);
|
|
||||||
assert(checkFBO());
|
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_copyFBO);
|
|
||||||
|
|
||||||
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
Context::FrameBufferRenderTarget targetParams;
|
||||||
_pBuffer->m_pTexture->frameBufferTexture == CachedTexture::fbMultiSample ? _pBuffer->m_pResolveTexture->glName : _pBuffer->m_pTexture->glName,
|
targetParams.bufferHandle = m_copyFBO;
|
||||||
0);
|
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);
|
||||||
|
targetParams.textureTarget = target::TEXTURE_2D;
|
||||||
|
|
||||||
|
gfxContext.addFrameBufferRenderTarget(targetParams);
|
||||||
|
|
||||||
|
targetParams.attachment = bufferAttachment::DEPTH_ATTACHMENT;
|
||||||
|
targetParams.textureHandle = ObjectHandle(m_pDepthBufferCopyTexture->glName);
|
||||||
|
|
||||||
|
gfxContext.addFrameBufferRenderTarget(targetParams);
|
||||||
|
|
||||||
|
|
||||||
|
Context::BlitFramebuffersParams blitParams;
|
||||||
|
blitParams.readBuffer = _pBuffer->m_FBO;
|
||||||
|
blitParams.drawBuffer = m_copyFBO;
|
||||||
|
blitParams.srcX0 = 0;
|
||||||
|
blitParams.srcY0 = 0;
|
||||||
|
blitParams.srcX1 = m_pDepthBufferTexture->realWidth;
|
||||||
|
blitParams.srcY1 = m_pDepthBufferTexture->realHeight;
|
||||||
|
blitParams.dstX0 = 0;
|
||||||
|
blitParams.dstY0 = 0;
|
||||||
|
blitParams.dstX1 = m_pDepthBufferTexture->realWidth;
|
||||||
|
blitParams.dstY1 = m_pDepthBufferTexture->realHeight;
|
||||||
|
blitParams.mask = blitMask::DEPTH_BUFFER;
|
||||||
|
blitParams.filter = textureParameters::FILTER_NEAREST;
|
||||||
|
|
||||||
|
gfxContext.blitFramebuffers(blitParams);
|
||||||
|
|
||||||
|
gfxContext.bindFramebuffer(bufferTarget::READ_FRAMEBUFFER, ObjectHandle());
|
||||||
|
gfxContext.bindFramebuffer(bufferTarget::DRAW_FRAMEBUFFER, _pBuffer->m_FBO);
|
||||||
|
|
||||||
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_pDepthBufferCopyTexture->glName, 0);
|
|
||||||
assert(checkFBO());
|
|
||||||
glDisable(GL_SCISSOR_TEST);
|
|
||||||
glBlitFramebuffer(
|
|
||||||
0, 0, m_pDepthBufferTexture->realWidth, m_pDepthBufferTexture->realHeight,
|
|
||||||
0, 0, m_pDepthBufferTexture->realWidth, m_pDepthBufferTexture->realHeight,
|
|
||||||
GL_DEPTH_BUFFER_BIT, GL_NEAREST
|
|
||||||
);
|
|
||||||
glEnable(GL_SCISSOR_TEST);
|
|
||||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, GLuint(_pBuffer->m_FBO));
|
|
||||||
m_copied = true;
|
m_copied = true;
|
||||||
return m_pDepthBufferCopyTexture;
|
return m_pDepthBufferCopyTexture;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void DepthBuffer::activateDepthBufferTexture(FrameBuffer * _pBuffer)
|
void DepthBuffer::activateDepthBufferTexture(FrameBuffer * _pBuffer)
|
||||||
{
|
{
|
||||||
|
@ -324,10 +343,16 @@ void DepthBuffer::activateDepthBufferTexture(FrameBuffer * _pBuffer)
|
||||||
|
|
||||||
void DepthBuffer::bindDepthImageTexture()
|
void DepthBuffer::bindDepthImageTexture()
|
||||||
{
|
{
|
||||||
#ifdef GL_IMAGE_TEXTURES_SUPPORT
|
if (!Context::imageTextures)
|
||||||
glBindImageTexture(depthImageUnit, m_pDepthImageTexture->glName, 0, GL_FALSE, 0, GL_READ_WRITE,
|
return;
|
||||||
GLenum(gfxContext.getFramebufferTextureFormats().depthImageInternalFormat));
|
|
||||||
#endif
|
Context::BindImageTextureParameters bindParams;
|
||||||
|
bindParams.imageUnit = textureImageUnits::Depth;
|
||||||
|
bindParams.texture = ObjectHandle(m_pDepthImageTexture->glName);
|
||||||
|
bindParams.accessMode = textureImageAccessMode::READ_WRITE;
|
||||||
|
bindParams.textureFormat = gfxContext.getFramebufferTextureFormats().depthImageInternalFormat;
|
||||||
|
|
||||||
|
gfxContext.bindImageTexture(bindParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
DepthBufferList::DepthBufferList() : m_pCurrent(nullptr), m_pzLUT(nullptr)
|
DepthBufferList::DepthBufferList() : m_pCurrent(nullptr), m_pzLUT(nullptr)
|
||||||
|
@ -443,7 +468,7 @@ void DepthBufferList::clearBuffer(u32 _ulx, u32 _uly, u32 _lrx, u32 _lry)
|
||||||
if (m_pCurrent == nullptr)
|
if (m_pCurrent == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const graphics::FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats();
|
const FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats();
|
||||||
|
|
||||||
m_pCurrent->m_cleared = true;
|
m_pCurrent->m_cleared = true;
|
||||||
m_pCurrent->m_ulx = _ulx;
|
m_pCurrent->m_ulx = _ulx;
|
||||||
|
@ -451,17 +476,28 @@ void DepthBufferList::clearBuffer(u32 _ulx, u32 _uly, u32 _lrx, u32 _lry)
|
||||||
m_pCurrent->m_lrx = _lrx;
|
m_pCurrent->m_lrx = _lrx;
|
||||||
m_pCurrent->m_lry = _lry;
|
m_pCurrent->m_lry = _lry;
|
||||||
|
|
||||||
if (m_pCurrent->m_depthImageFBO == 0 || !Context::imageTextures || config.frameBufferEmulation.N64DepthCompare == 0)
|
if (!m_pCurrent->m_depthImageFBO.isNotNull() || !Context::imageTextures || config.frameBufferEmulation.N64DepthCompare == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
float color[4] = {1.0f, 1.0f, 0.0f, 1.0f};
|
|
||||||
glBindImageTexture(depthImageUnit, 0, 0, GL_FALSE, 0, GL_READ_WRITE, GLenum(fbTexFormats.depthImageInternalFormat));
|
Context::BindImageTextureParameters bindParams;
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_pCurrent->m_depthImageFBO);
|
bindParams.imageUnit = textureImageUnits::Depth;
|
||||||
|
bindParams.texture = ObjectHandle();
|
||||||
|
bindParams.accessMode = textureImageAccessMode::READ_WRITE;
|
||||||
|
bindParams.textureFormat = gfxContext.getFramebufferTextureFormats().depthImageInternalFormat;
|
||||||
|
gfxContext.bindImageTexture(bindParams);
|
||||||
|
|
||||||
|
gfxContext.bindFramebuffer(bufferTarget::DRAW_FRAMEBUFFER, m_pCurrent->m_depthImageFBO);
|
||||||
|
|
||||||
const u32 cycleType = gDP.otherMode.cycleType;
|
const u32 cycleType = gDP.otherMode.cycleType;
|
||||||
gDP.otherMode.cycleType = G_CYC_FILL;
|
gDP.otherMode.cycleType = G_CYC_FILL;
|
||||||
|
float color[4] = { 1.0f, 1.0f, 0.0f, 1.0f };
|
||||||
dwnd().getDrawer().drawRect(_ulx, _uly, _lrx, _lry, color);
|
dwnd().getDrawer().drawRect(_ulx, _uly, _lrx, _lry, color);
|
||||||
gDP.otherMode.cycleType = cycleType;
|
gDP.otherMode.cycleType = cycleType;
|
||||||
glBindImageTexture(depthImageUnit, m_pCurrent->m_pDepthImageTexture->glName, 0, GL_FALSE, 0, GL_READ_WRITE, GLenum(fbTexFormats.depthImageInternalFormat));
|
|
||||||
|
bindParams.texture = ObjectHandle(m_pCurrent->m_pDepthImageTexture->glName);
|
||||||
|
gfxContext.bindImageTexture(bindParams);
|
||||||
|
|
||||||
frameBufferList().setCurrentDrawBuffer();
|
frameBufferList().setCurrentDrawBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,11 @@
|
||||||
|
|
||||||
#include "Types.h"
|
#include "Types.h"
|
||||||
#include "Textures.h"
|
#include "Textures.h"
|
||||||
|
#include "Graphics/ObjectHandle.h"
|
||||||
|
#include "Graphics/Parameter.h"
|
||||||
|
|
||||||
struct FrameBuffer;
|
struct FrameBuffer;
|
||||||
|
|
||||||
struct DepthBuffer
|
struct DepthBuffer
|
||||||
{
|
{
|
||||||
DepthBuffer();
|
DepthBuffer();
|
||||||
|
@ -15,24 +18,24 @@ struct DepthBuffer
|
||||||
CachedTexture * resolveDepthBufferTexture(FrameBuffer * _pBuffer);
|
CachedTexture * resolveDepthBufferTexture(FrameBuffer * _pBuffer);
|
||||||
CachedTexture * copyDepthBufferTexture(FrameBuffer * _pBuffer);
|
CachedTexture * copyDepthBufferTexture(FrameBuffer * _pBuffer);
|
||||||
|
|
||||||
void setDepthAttachment(GLuint _fbo, GLenum _target);
|
void setDepthAttachment(graphics::ObjectHandle _fbo, graphics::Parameter _target);
|
||||||
void activateDepthBufferTexture(FrameBuffer * _pBuffer);
|
void activateDepthBufferTexture(FrameBuffer * _pBuffer);
|
||||||
|
|
||||||
void bindDepthImageTexture();
|
void bindDepthImageTexture();
|
||||||
|
|
||||||
u32 m_address, m_width;
|
u32 m_address, m_width;
|
||||||
u32 m_ulx, m_uly, m_lrx, m_lry; // Parameters of fillrect command.
|
u32 m_ulx, m_uly, m_lrx, m_lry; // Parameters of fillrect command.
|
||||||
GLuint m_depthImageFBO;
|
graphics::ObjectHandle m_depthImageFBO;
|
||||||
CachedTexture *m_pDepthImageTexture;
|
CachedTexture *m_pDepthImageTexture;
|
||||||
CachedTexture *m_pDepthBufferTexture;
|
CachedTexture *m_pDepthBufferTexture;
|
||||||
GLuint m_depthRenderbuffer;
|
graphics::ObjectHandle m_depthRenderbuffer;
|
||||||
u32 m_depthRenderbufferWidth;
|
u32 m_depthRenderbufferWidth;
|
||||||
bool m_cleared;
|
bool m_cleared;
|
||||||
// multisampling
|
// multisampling
|
||||||
CachedTexture *m_pResolveDepthBufferTexture;
|
CachedTexture *m_pResolveDepthBufferTexture;
|
||||||
bool m_resolved;
|
bool m_resolved;
|
||||||
// render to depth buffer
|
// render to depth buffer
|
||||||
GLuint m_copyFBO;
|
graphics::ObjectHandle m_copyFBO;
|
||||||
CachedTexture *m_pDepthBufferCopyTexture;
|
CachedTexture *m_pDepthBufferCopyTexture;
|
||||||
bool m_copied;
|
bool m_copied;
|
||||||
|
|
||||||
|
@ -75,10 +78,6 @@ DepthBufferList & depthBufferList()
|
||||||
return DepthBufferList::get();
|
return DepthBufferList::get();
|
||||||
}
|
}
|
||||||
|
|
||||||
extern const GLuint ZlutImageUnit;
|
|
||||||
extern const GLuint TlutImageUnit;
|
|
||||||
extern const GLuint depthImageUnit;
|
|
||||||
|
|
||||||
void DepthBuffer_Init();
|
void DepthBuffer_Init();
|
||||||
void DepthBuffer_Destroy();
|
void DepthBuffer_Destroy();
|
||||||
|
|
||||||
|
|
|
@ -784,7 +784,7 @@ void FrameBufferList::attachDepthBuffer()
|
||||||
if (goodDepthBufferTexture) {
|
if (goodDepthBufferTexture) {
|
||||||
#endif // USE_DEPTH_RENDERBUFFER
|
#endif // USE_DEPTH_RENDERBUFFER
|
||||||
m_pCurrent->m_pDepthBuffer = pDepthBuffer;
|
m_pCurrent->m_pDepthBuffer = pDepthBuffer;
|
||||||
pDepthBuffer->setDepthAttachment(GLuint(m_pCurrent->m_FBO), GL_DRAW_FRAMEBUFFER);
|
pDepthBuffer->setDepthAttachment(m_pCurrent->m_FBO, GL_DRAW_FRAMEBUFFER);
|
||||||
if (Context::imageTextures && config.frameBufferEmulation.N64DepthCompare != 0)
|
if (Context::imageTextures && config.frameBufferEmulation.N64DepthCompare != 0)
|
||||||
pDepthBuffer->bindDepthImageTexture();
|
pDepthBuffer->bindDepthImageTexture();
|
||||||
} else
|
} else
|
||||||
|
|
|
@ -19,6 +19,7 @@ namespace graphics {
|
||||||
FragmentDepthWrite,
|
FragmentDepthWrite,
|
||||||
BlitFramebuffer,
|
BlitFramebuffer,
|
||||||
WeakBlitFramebuffer,
|
WeakBlitFramebuffer,
|
||||||
|
DepthFramebufferTextures,
|
||||||
ImageTextures
|
ImageTextures
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -344,6 +344,12 @@ bool ContextImpl::isSupported(graphics::SpecialFeatures _feature) const
|
||||||
return m_glInfo.msaa;
|
return m_glInfo.msaa;
|
||||||
case graphics::SpecialFeatures::ImageTextures:
|
case graphics::SpecialFeatures::ImageTextures:
|
||||||
return m_glInfo.imageTextures;
|
return m_glInfo.imageTextures;
|
||||||
|
case graphics::SpecialFeatures::DepthFramebufferTextures:
|
||||||
|
#ifndef USE_DEPTH_RENDERBUFFER
|
||||||
|
return true;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user