2014-10-13 12:38:51 +00:00
|
|
|
#ifdef OS_MAC_OS_X
|
|
|
|
#include <malloc/malloc.h>
|
|
|
|
#else
|
2013-04-05 06:13:26 +00:00
|
|
|
#include <malloc.h>
|
2014-10-13 12:38:51 +00:00
|
|
|
#endif
|
2013-06-04 16:00:03 +00:00
|
|
|
#include <assert.h>
|
2013-06-01 13:10:30 +00:00
|
|
|
#include "OpenGL.h"
|
2013-12-14 14:30:20 +00:00
|
|
|
#include "Combiner.h"
|
2013-06-01 13:10:30 +00:00
|
|
|
#include "FrameBuffer.h"
|
2013-04-05 06:13:26 +00:00
|
|
|
#include "DepthBuffer.h"
|
2013-06-04 16:00:03 +00:00
|
|
|
#include "VI.h"
|
2014-04-05 02:57:00 +00:00
|
|
|
#include "Config.h"
|
2013-06-01 13:10:30 +00:00
|
|
|
#include "Debug.h"
|
2013-04-05 06:13:26 +00:00
|
|
|
|
2013-12-14 14:30:20 +00:00
|
|
|
const GLuint ZlutImageUnit = 0;
|
|
|
|
const GLuint TlutImageUnit = 1;
|
|
|
|
const GLuint depthImageUnit = 2;
|
2013-04-05 06:13:26 +00:00
|
|
|
|
2015-04-29 16:14:57 +00:00
|
|
|
DepthBuffer::DepthBuffer() : m_address(0), m_width(0), m_uly(0), m_lry(0),
|
|
|
|
m_FBO(0), m_pDepthImageTexture(NULL), m_pDepthBufferTexture(NULL),
|
|
|
|
m_cleared(false), m_pResolveDepthBufferTexture(NULL), m_resolved(false)
|
2013-04-05 06:13:26 +00:00
|
|
|
{
|
2014-09-08 11:00:13 +00:00
|
|
|
glGenFramebuffers(1, &m_FBO);
|
2013-04-05 06:13:26 +00:00
|
|
|
}
|
|
|
|
|
2014-09-08 11:00:13 +00:00
|
|
|
DepthBuffer::DepthBuffer(DepthBuffer && _other) :
|
2015-04-29 16:14:57 +00:00
|
|
|
m_address(_other.m_address), m_width(_other.m_width), m_uly(_other.m_uly), m_lry(_other.m_lry),
|
2015-02-13 12:06:59 +00:00
|
|
|
m_FBO(_other.m_FBO), m_pDepthImageTexture(_other.m_pDepthImageTexture), m_pDepthBufferTexture(_other.m_pDepthBufferTexture),
|
2015-10-10 16:36:25 +00:00
|
|
|
m_cleared(_other.m_cleared), m_pResolveDepthBufferTexture(_other.m_pResolveDepthBufferTexture), m_resolved(_other.m_resolved)
|
2013-04-05 06:13:26 +00:00
|
|
|
{
|
2014-09-08 11:00:13 +00:00
|
|
|
_other.m_FBO = 0;
|
2015-01-27 16:00:06 +00:00
|
|
|
_other.m_pDepthImageTexture = NULL;
|
|
|
|
_other.m_pDepthBufferTexture = NULL;
|
2015-02-13 12:06:59 +00:00
|
|
|
_other.m_pResolveDepthBufferTexture = NULL;
|
|
|
|
_other.m_resolved = false;
|
2013-04-05 06:13:26 +00:00
|
|
|
}
|
|
|
|
|
2014-09-08 11:00:13 +00:00
|
|
|
DepthBuffer::~DepthBuffer()
|
2013-04-05 06:13:26 +00:00
|
|
|
{
|
2014-09-08 11:00:13 +00:00
|
|
|
if (m_FBO != 0)
|
|
|
|
glDeleteFramebuffers(1, &m_FBO);
|
2015-01-27 16:00:06 +00:00
|
|
|
if (m_pDepthImageTexture != NULL)
|
|
|
|
textureCache().removeFrameBufferTexture(m_pDepthImageTexture);
|
|
|
|
if (m_pDepthBufferTexture != NULL)
|
|
|
|
textureCache().removeFrameBufferTexture(m_pDepthBufferTexture);
|
2015-02-13 12:06:59 +00:00
|
|
|
if (m_pResolveDepthBufferTexture != NULL)
|
|
|
|
textureCache().removeFrameBufferTexture(m_pResolveDepthBufferTexture);
|
2013-04-05 06:13:26 +00:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:00:06 +00:00
|
|
|
void DepthBuffer::initDepthImageTexture(FrameBuffer * _pBuffer)
|
2013-04-05 06:13:26 +00:00
|
|
|
{
|
2014-10-13 12:37:43 +00:00
|
|
|
#ifdef GL_IMAGE_TEXTURES_SUPPORT
|
2015-01-27 14:18:18 +00:00
|
|
|
if (!video().getRender().isImageTexturesSupported() || config.frameBufferEmulation.N64DepthCompare == 0 || m_pDepthImageTexture != NULL)
|
2015-01-27 16:00:06 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
m_pDepthImageTexture = textureCache().addFrameBufferTexture();
|
|
|
|
|
|
|
|
m_pDepthImageTexture->width = (u32)(_pBuffer->m_pTexture->width);
|
|
|
|
m_pDepthImageTexture->height = (u32)(_pBuffer->m_pTexture->height);
|
|
|
|
m_pDepthImageTexture->format = 0;
|
|
|
|
m_pDepthImageTexture->size = 2;
|
|
|
|
m_pDepthImageTexture->clampS = 1;
|
|
|
|
m_pDepthImageTexture->clampT = 1;
|
|
|
|
m_pDepthImageTexture->address = _pBuffer->m_startAddress;
|
|
|
|
m_pDepthImageTexture->clampWidth = _pBuffer->m_width;
|
|
|
|
m_pDepthImageTexture->clampHeight = _pBuffer->m_height;
|
2015-05-06 13:47:12 +00:00
|
|
|
m_pDepthImageTexture->frameBufferTexture = CachedTexture::fbOneSample;
|
2015-01-27 16:00:06 +00:00
|
|
|
m_pDepthImageTexture->maskS = 0;
|
|
|
|
m_pDepthImageTexture->maskT = 0;
|
|
|
|
m_pDepthImageTexture->mirrorS = 0;
|
|
|
|
m_pDepthImageTexture->mirrorT = 0;
|
|
|
|
m_pDepthImageTexture->realWidth = m_pDepthImageTexture->width;
|
|
|
|
m_pDepthImageTexture->realHeight = m_pDepthImageTexture->height;
|
2015-06-10 17:23:53 +00:00
|
|
|
m_pDepthImageTexture->textureBytes = m_pDepthImageTexture->realWidth * m_pDepthImageTexture->realHeight * fboFormats.depthImageFormatBytes;
|
2015-01-27 16:00:06 +00:00
|
|
|
textureCache().addFrameBufferTextureSize(m_pDepthImageTexture->textureBytes);
|
|
|
|
|
2015-01-27 14:07:30 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, m_pDepthImageTexture->glName);
|
2015-06-10 17:23:53 +00:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, fboFormats.depthImageInternalFormat, m_pDepthImageTexture->realWidth, m_pDepthImageTexture->realHeight, 0, fboFormats.depthImageFormat, fboFormats.depthImageType, NULL);
|
2015-01-27 14:07:30 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
2015-01-27 16:00:06 +00:00
|
|
|
|
2014-09-08 11:00:13 +00:00
|
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
|
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_FBO);
|
2015-01-27 16:00:06 +00:00
|
|
|
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_pDepthImageTexture->glName, 0);
|
2014-09-08 11:00:13 +00:00
|
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
|
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _pBuffer->m_FBO);
|
2015-01-27 16:00:06 +00:00
|
|
|
|
2015-04-29 16:14:57 +00:00
|
|
|
depthBufferList().clearBuffer(0, VI.height);
|
2014-10-13 12:37:43 +00:00
|
|
|
#endif // GL_IMAGE_TEXTURES_SUPPORT
|
2013-04-05 06:13:26 +00:00
|
|
|
}
|
|
|
|
|
2015-02-13 12:06:59 +00:00
|
|
|
void DepthBuffer::_initDepthBufferTexture(FrameBuffer * _pBuffer, CachedTexture * _pTexture, bool _multisample)
|
2015-01-27 16:00:06 +00:00
|
|
|
{
|
|
|
|
if (_pBuffer != NULL) {
|
2015-02-13 12:06:59 +00:00
|
|
|
_pTexture->width = (u32)(_pBuffer->m_pTexture->width);
|
|
|
|
_pTexture->height = (u32)(_pBuffer->m_pTexture->height);
|
|
|
|
_pTexture->address = _pBuffer->m_startAddress;
|
|
|
|
_pTexture->clampWidth = _pBuffer->m_width;
|
|
|
|
_pTexture->clampHeight = _pBuffer->m_height;
|
2015-01-27 16:00:06 +00:00
|
|
|
}
|
|
|
|
else {
|
2015-02-13 12:06:59 +00:00
|
|
|
_pTexture->width = video().getWidth();
|
|
|
|
_pTexture->height = video().getHeight();
|
2015-04-08 17:06:17 +00:00
|
|
|
_pTexture->address = gDP.depthImageAddress;
|
2015-02-13 12:06:59 +00:00
|
|
|
_pTexture->clampWidth = VI.width;
|
|
|
|
_pTexture->clampHeight = VI.height;
|
2015-01-27 16:00:06 +00:00
|
|
|
}
|
2015-02-13 12:06:59 +00:00
|
|
|
_pTexture->format = 0;
|
|
|
|
_pTexture->size = 2;
|
|
|
|
_pTexture->clampS = 1;
|
|
|
|
_pTexture->clampT = 1;
|
2015-05-06 13:47:12 +00:00
|
|
|
_pTexture->frameBufferTexture = CachedTexture::fbOneSample;
|
2015-02-13 12:06:59 +00:00
|
|
|
_pTexture->maskS = 0;
|
|
|
|
_pTexture->maskT = 0;
|
|
|
|
_pTexture->mirrorS = 0;
|
|
|
|
_pTexture->mirrorT = 0;
|
|
|
|
_pTexture->realWidth = _pTexture->width;
|
|
|
|
_pTexture->realHeight = _pTexture->height;
|
2015-06-02 12:57:24 +00:00
|
|
|
_pTexture->textureBytes = _pTexture->realWidth * _pTexture->realHeight * fboFormats.depthFormatBytes;
|
2015-02-13 12:06:59 +00:00
|
|
|
textureCache().addFrameBufferTextureSize(_pTexture->textureBytes);
|
2015-01-27 16:00:06 +00:00
|
|
|
|
2015-05-04 14:32:58 +00:00
|
|
|
#ifdef GL_MULTISAMPLING_SUPPORT
|
2015-02-13 12:06:59 +00:00
|
|
|
if (_multisample) {
|
|
|
|
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _pTexture->glName);
|
2015-05-04 14:32:58 +00:00
|
|
|
#if defined(GLES3_1)
|
2015-04-23 08:51:35 +00:00
|
|
|
if (_pBuffer != NULL)
|
|
|
|
glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, config.video.multisampling, GL_DEPTH_COMPONENT, _pBuffer->m_pTexture->realWidth, _pBuffer->m_pTexture->realHeight, false);
|
|
|
|
else
|
|
|
|
glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, config.video.multisampling, GL_DEPTH_COMPONENT, video().getWidth(), video().getHeight(), false);
|
2015-05-04 14:32:58 +00:00
|
|
|
#else
|
|
|
|
if (_pBuffer != NULL)
|
|
|
|
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, config.video.multisampling, GL_DEPTH_COMPONENT, _pBuffer->m_pTexture->realWidth, _pBuffer->m_pTexture->realHeight, false);
|
|
|
|
else
|
|
|
|
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, config.video.multisampling, GL_DEPTH_COMPONENT, video().getWidth(), video().getHeight(), false);
|
2015-04-23 08:51:35 +00:00
|
|
|
#endif
|
2015-05-06 13:47:12 +00:00
|
|
|
_pTexture->frameBufferTexture = CachedTexture::fbMultiSample;
|
2015-05-04 14:32:58 +00:00
|
|
|
} else
|
|
|
|
#endif // GL_MULTISAMPLING_SUPPORT
|
|
|
|
{
|
2015-02-13 12:06:59 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, _pTexture->glName);
|
2015-02-09 05:36:20 +00:00
|
|
|
if (_pBuffer != NULL)
|
2015-06-02 12:57:24 +00:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, fboFormats.depthInternalFormat, _pBuffer->m_pTexture->realWidth, _pBuffer->m_pTexture->realHeight, 0, GL_DEPTH_COMPONENT, fboFormats.depthType, NULL);
|
2015-02-09 05:36:20 +00:00
|
|
|
else
|
2015-06-02 12:57:24 +00:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, fboFormats.depthInternalFormat, video().getWidth(), video().getHeight(), 0, GL_DEPTH_COMPONENT, fboFormats.depthType, NULL);
|
2015-02-09 05:36:20 +00:00
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
}
|
2015-02-13 12:06:59 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
2015-01-27 16:00:06 +00:00
|
|
|
}
|
|
|
|
|
2015-04-01 09:08:17 +00:00
|
|
|
void DepthBuffer::setDepthAttachment(GLenum _target)
|
2015-02-13 12:06:59 +00:00
|
|
|
{
|
2015-05-04 14:32:58 +00:00
|
|
|
#ifdef GL_MULTISAMPLING_SUPPORT
|
2015-02-09 05:36:20 +00:00
|
|
|
if (config.video.multisampling != 0)
|
2015-04-01 09:08:17 +00:00
|
|
|
glFramebufferTexture2D(_target, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D_MULTISAMPLE, m_pDepthBufferTexture->glName, 0);
|
2015-02-09 05:36:20 +00:00
|
|
|
else
|
2015-05-04 14:32:58 +00:00
|
|
|
#endif
|
2015-04-01 09:08:17 +00:00
|
|
|
glFramebufferTexture2D(_target, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_pDepthBufferTexture->glName, 0);
|
2015-02-13 12:06:59 +00:00
|
|
|
m_resolved = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DepthBuffer::initDepthBufferTexture(FrameBuffer * _pBuffer)
|
|
|
|
{
|
|
|
|
if (m_pDepthBufferTexture == NULL) {
|
|
|
|
m_pDepthBufferTexture = textureCache().addFrameBufferTexture();
|
|
|
|
_initDepthBufferTexture(_pBuffer, m_pDepthBufferTexture, config.video.multisampling != 0);
|
|
|
|
}
|
|
|
|
|
2015-05-16 08:55:07 +00:00
|
|
|
#ifdef GL_MULTISAMPLING_SUPPORT
|
2015-02-13 12:06:59 +00:00
|
|
|
if (config.video.multisampling != 0 && m_pResolveDepthBufferTexture == NULL) {
|
|
|
|
m_pResolveDepthBufferTexture = textureCache().addFrameBufferTexture();
|
|
|
|
_initDepthBufferTexture(_pBuffer, m_pResolveDepthBufferTexture, false);
|
|
|
|
}
|
2015-05-16 08:55:07 +00:00
|
|
|
#endif
|
2015-02-13 12:06:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CachedTexture * DepthBuffer::resolveDepthBufferTexture(FrameBuffer * _pBuffer)
|
|
|
|
{
|
2015-05-14 13:47:25 +00:00
|
|
|
#ifdef GL_MULTISAMPLING_SUPPORT
|
2015-02-13 12:06:59 +00:00
|
|
|
if (config.video.multisampling == 0)
|
|
|
|
return m_pDepthBufferTexture;
|
|
|
|
if (m_resolved)
|
|
|
|
return m_pResolveDepthBufferTexture;
|
2015-04-03 14:58:45 +00:00
|
|
|
glScissor(0, 0, m_pDepthBufferTexture->realWidth, m_pDepthBufferTexture->realHeight);
|
2015-02-13 12:06:59 +00:00
|
|
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, _pBuffer->m_FBO);
|
|
|
|
glReadBuffer(GL_COLOR_ATTACHMENT0);
|
|
|
|
GLuint attachment = GL_COLOR_ATTACHMENT0;
|
|
|
|
glDrawBuffers(1, &attachment);
|
|
|
|
assert(checkFBO());
|
|
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _pBuffer->m_resolveFBO);
|
|
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_pResolveDepthBufferTexture->glName, 0);
|
|
|
|
assert(checkFBO());
|
|
|
|
glBlitFramebuffer(
|
|
|
|
0, 0, m_pDepthBufferTexture->realWidth, m_pDepthBufferTexture->realHeight,
|
|
|
|
0, 0, m_pResolveDepthBufferTexture->realWidth, m_pResolveDepthBufferTexture->realHeight,
|
|
|
|
GL_DEPTH_BUFFER_BIT, GL_NEAREST
|
|
|
|
);
|
|
|
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
|
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _pBuffer->m_FBO);
|
|
|
|
m_resolved = true;
|
2015-04-03 14:58:45 +00:00
|
|
|
gDP.changed |= CHANGED_SCISSOR;
|
2015-02-13 12:06:59 +00:00
|
|
|
return m_pResolveDepthBufferTexture;
|
2015-05-14 13:47:25 +00:00
|
|
|
#else
|
|
|
|
return m_pDepthBufferTexture;
|
|
|
|
#endif
|
2015-01-27 16:00:06 +00:00
|
|
|
}
|
|
|
|
|
2015-02-13 12:06:59 +00:00
|
|
|
void DepthBuffer::activateDepthBufferTexture(FrameBuffer * _pBuffer)
|
|
|
|
{
|
|
|
|
textureCache().activateTexture(0, resolveDepthBufferTexture(_pBuffer));
|
2015-01-27 16:00:06 +00:00
|
|
|
}
|
|
|
|
|
2015-02-13 12:06:59 +00:00
|
|
|
void DepthBuffer::bindDepthImageTexture()
|
|
|
|
{
|
2015-01-27 16:00:06 +00:00
|
|
|
#ifdef GL_IMAGE_TEXTURES_SUPPORT
|
2015-06-10 17:23:53 +00:00
|
|
|
glBindImageTexture(depthImageUnit, m_pDepthImageTexture->glName, 0, GL_FALSE, 0, GL_READ_WRITE, fboFormats.depthImageInternalFormat);
|
2015-01-27 16:00:06 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-03-26 15:24:51 +00:00
|
|
|
DepthBufferList::DepthBufferList() : m_pCurrent(NULL), m_pzLUT(NULL)
|
2013-04-05 06:13:26 +00:00
|
|
|
{
|
2015-01-27 11:56:22 +00:00
|
|
|
m_pzLUT = new u16[0x40000];
|
|
|
|
for (int i = 0; i<0x40000; i++) {
|
|
|
|
u32 exponent = 0;
|
|
|
|
u32 testbit = 1 << 17;
|
|
|
|
while ((i & testbit) && (exponent < 7)) {
|
|
|
|
exponent++;
|
|
|
|
testbit = 1 << (17 - exponent);
|
|
|
|
}
|
|
|
|
|
|
|
|
const u32 mantissa = (i >> (6 - (6 < exponent ? 6 : exponent))) & 0x7ff;
|
|
|
|
m_pzLUT[i] = (u16)(((exponent << 11) | mantissa) << 2);
|
|
|
|
}
|
2013-04-05 06:13:26 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 15:24:51 +00:00
|
|
|
DepthBufferList::~DepthBufferList()
|
2013-04-05 06:13:26 +00:00
|
|
|
{
|
2015-01-27 11:56:22 +00:00
|
|
|
delete[] m_pzLUT;
|
|
|
|
m_pzLUT = NULL;
|
2015-03-26 15:24:51 +00:00
|
|
|
m_list.clear();
|
|
|
|
}
|
|
|
|
|
2015-03-31 12:44:41 +00:00
|
|
|
DepthBufferList & DepthBufferList::get()
|
|
|
|
{
|
|
|
|
static DepthBufferList depthBufferList;
|
|
|
|
return depthBufferList;
|
|
|
|
}
|
|
|
|
|
2015-03-26 15:24:51 +00:00
|
|
|
void DepthBufferList::init()
|
|
|
|
{
|
|
|
|
m_pCurrent = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DepthBufferList::destroy()
|
|
|
|
{
|
2014-09-08 11:00:13 +00:00
|
|
|
m_pCurrent = NULL;
|
|
|
|
m_list.clear();
|
2013-04-05 06:13:26 +00:00
|
|
|
}
|
|
|
|
|
2015-02-17 16:10:44 +00:00
|
|
|
void DepthBufferList::setNotCleared()
|
|
|
|
{
|
|
|
|
for (DepthBuffers::iterator iter = m_list.begin(); iter != m_list.end(); ++iter)
|
|
|
|
iter->m_cleared = false;
|
|
|
|
}
|
|
|
|
|
2014-09-08 11:00:13 +00:00
|
|
|
DepthBuffer * DepthBufferList::findBuffer(u32 _address)
|
2013-04-05 06:13:26 +00:00
|
|
|
{
|
2014-09-08 11:00:13 +00:00
|
|
|
for (DepthBuffers::iterator iter = m_list.begin(); iter != m_list.end(); ++iter)
|
|
|
|
if (iter->m_address == _address)
|
|
|
|
return &(*iter);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-04-05 06:13:26 +00:00
|
|
|
|
2014-09-08 11:00:13 +00:00
|
|
|
void DepthBufferList::removeBuffer(u32 _address )
|
|
|
|
{
|
|
|
|
for (DepthBuffers::iterator iter = m_list.begin(); iter != m_list.end(); ++iter)
|
|
|
|
if (iter->m_address == _address) {
|
|
|
|
m_list.erase(iter);
|
|
|
|
return;
|
|
|
|
}
|
2013-04-05 06:13:26 +00:00
|
|
|
}
|
|
|
|
|
2014-09-08 11:00:13 +00:00
|
|
|
void DepthBufferList::saveBuffer(u32 _address)
|
2013-04-05 06:13:26 +00:00
|
|
|
{
|
2014-09-08 11:00:13 +00:00
|
|
|
if (!config.frameBufferEmulation.enable)
|
|
|
|
return;
|
|
|
|
|
|
|
|
FrameBuffer * pFrameBuffer = frameBufferList().findBuffer(_address);
|
2015-04-08 17:06:17 +00:00
|
|
|
if (pFrameBuffer != NULL)
|
2015-02-19 12:50:02 +00:00
|
|
|
pFrameBuffer->m_isDepthBuffer = true;
|
2013-06-02 15:20:44 +00:00
|
|
|
|
2014-09-08 11:00:13 +00:00
|
|
|
if (m_pCurrent == NULL || m_pCurrent->m_address != _address)
|
|
|
|
m_pCurrent = findBuffer(_address);
|
|
|
|
|
|
|
|
if (m_pCurrent != NULL && pFrameBuffer != NULL && m_pCurrent->m_width != pFrameBuffer->m_width) {
|
|
|
|
removeBuffer(_address);
|
|
|
|
m_pCurrent = NULL;
|
2013-04-05 06:13:26 +00:00
|
|
|
}
|
|
|
|
|
2014-09-08 11:00:13 +00:00
|
|
|
if (m_pCurrent == NULL) {
|
|
|
|
m_list.emplace_front();
|
|
|
|
DepthBuffer & buffer = m_list.front();
|
2013-06-04 16:00:03 +00:00
|
|
|
|
2014-09-08 11:00:13 +00:00
|
|
|
buffer.m_address = _address;
|
|
|
|
buffer.m_width = pFrameBuffer != NULL ? pFrameBuffer->m_width : VI.width;
|
2015-01-27 16:00:06 +00:00
|
|
|
|
|
|
|
buffer.initDepthBufferTexture(pFrameBuffer);
|
2014-09-08 11:00:13 +00:00
|
|
|
|
|
|
|
m_pCurrent = &buffer;
|
2013-06-04 16:00:03 +00:00
|
|
|
}
|
2013-04-05 06:13:26 +00:00
|
|
|
|
2014-09-08 11:00:13 +00:00
|
|
|
frameBufferList().attachDepthBuffer();
|
2013-06-01 13:10:30 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
DebugMsg( DEBUG_HIGH | DEBUG_HANDLED, "DepthBuffer_SetBuffer( 0x%08X ); color buffer is 0x%08X\n",
|
2014-09-08 11:01:22 +00:00
|
|
|
address, ( pFrameBuffer != NULL && pFrameBuffer->m_FBO > 0) ? pFrameBuffer->m_startAddress : 0
|
2013-06-01 13:10:30 +00:00
|
|
|
);
|
|
|
|
#endif
|
2013-04-05 06:13:26 +00:00
|
|
|
|
|
|
|
}
|
2014-01-08 16:22:42 +00:00
|
|
|
|
2015-04-29 16:14:57 +00:00
|
|
|
void DepthBufferList::clearBuffer(u32 _uly, u32 _lry)
|
2013-04-05 06:13:26 +00:00
|
|
|
{
|
2015-02-17 16:10:44 +00:00
|
|
|
if (m_pCurrent == NULL)
|
2013-12-15 17:20:12 +00:00
|
|
|
return;
|
2015-04-29 13:31:04 +00:00
|
|
|
m_pCurrent->m_cleared = true;
|
2015-04-29 16:14:57 +00:00
|
|
|
m_pCurrent->m_uly = _uly;
|
|
|
|
m_pCurrent->m_lry = _lry;
|
2015-02-17 16:10:44 +00:00
|
|
|
#ifdef GL_IMAGE_TEXTURES_SUPPORT
|
|
|
|
if (m_pCurrent->m_FBO == 0 || !video().getRender().isImageTexturesSupported() || config.frameBufferEmulation.N64DepthCompare == 0)
|
2013-12-14 14:30:20 +00:00
|
|
|
return;
|
2014-05-15 16:54:29 +00:00
|
|
|
float color[4] = {1.0f, 1.0f, 0.0f, 1.0f};
|
2015-06-10 17:23:53 +00:00
|
|
|
glBindImageTexture(depthImageUnit, 0, 0, GL_FALSE, 0, GL_READ_WRITE, fboFormats.depthImageInternalFormat);
|
2014-09-08 11:00:13 +00:00
|
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_pCurrent->m_FBO);
|
2014-11-04 11:02:48 +00:00
|
|
|
const u32 cycleType = gDP.otherMode.cycleType;
|
2014-11-08 18:02:50 +00:00
|
|
|
gDP.otherMode.cycleType = G_CYC_FILL;
|
2014-09-21 12:15:22 +00:00
|
|
|
video().getRender().drawRect(0,0,VI.width, VI.height, color);
|
2014-11-04 11:02:48 +00:00
|
|
|
gDP.otherMode.cycleType = cycleType;
|
2015-06-10 17:23:53 +00:00
|
|
|
glBindImageTexture(depthImageUnit, m_pCurrent->m_pDepthImageTexture->glName, 0, GL_FALSE, 0, GL_READ_WRITE, fboFormats.depthImageInternalFormat);
|
2014-09-08 11:01:22 +00:00
|
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBufferList().getCurrent()->m_FBO);
|
2014-10-13 12:37:43 +00:00
|
|
|
#endif // GL_IMAGE_TEXTURES_SUPPORT
|
2013-12-14 14:30:20 +00:00
|
|
|
}
|
2014-09-08 11:00:13 +00:00
|
|
|
|
|
|
|
void DepthBuffer_Init()
|
|
|
|
{
|
|
|
|
depthBufferList().init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DepthBuffer_Destroy()
|
|
|
|
{
|
|
|
|
depthBufferList().destroy();
|
|
|
|
}
|