2017-01-07 09:40:50 +00:00
|
|
|
#include "Graphics/Context.h"
|
|
|
|
#include "Graphics/Parameters.h"
|
|
|
|
#include "DepthBuffer.h"
|
2017-01-10 15:22:32 +00:00
|
|
|
#include "Config.h"
|
2017-01-07 09:40:50 +00:00
|
|
|
#include "Textures.h"
|
|
|
|
#include "ZlutTexture.h"
|
|
|
|
|
2017-01-21 11:44:56 +00:00
|
|
|
using namespace graphics;
|
2017-01-07 09:40:50 +00:00
|
|
|
|
|
|
|
ZlutTexture g_zlutTexture;
|
|
|
|
|
|
|
|
ZlutTexture::ZlutTexture()
|
|
|
|
: m_pTexture(nullptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZlutTexture::init()
|
|
|
|
{
|
2018-04-06 17:17:04 +00:00
|
|
|
if (!Context::IntegerTextures)
|
2017-02-04 15:44:31 +00:00
|
|
|
return;
|
|
|
|
|
2017-01-25 10:14:17 +00:00
|
|
|
const FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats();
|
|
|
|
|
2017-02-04 15:41:09 +00:00
|
|
|
std::vector<u32> vecZLUT(0x40000);
|
|
|
|
const u16 * const zLUT16 = depthBufferList().getZLUT();
|
|
|
|
for (u32 i = 0; i < 0x40000; ++i)
|
|
|
|
vecZLUT[i] = zLUT16[i];
|
2017-01-07 09:40:50 +00:00
|
|
|
|
2019-11-29 22:09:09 +00:00
|
|
|
m_pTexture = textureCache().addFrameBufferTexture(textureTarget::TEXTURE_2D);
|
2017-01-07 09:40:50 +00:00
|
|
|
m_pTexture->format = G_IM_FMT_IA;
|
|
|
|
m_pTexture->clampS = 1;
|
|
|
|
m_pTexture->clampT = 1;
|
|
|
|
m_pTexture->frameBufferTexture = CachedTexture::fbOneSample;
|
|
|
|
m_pTexture->maskS = 0;
|
|
|
|
m_pTexture->maskT = 0;
|
|
|
|
m_pTexture->mirrorS = 0;
|
|
|
|
m_pTexture->mirrorT = 0;
|
2019-05-08 14:04:24 +00:00
|
|
|
m_pTexture->width = 512;
|
|
|
|
m_pTexture->height = 512;
|
|
|
|
m_pTexture->textureBytes = m_pTexture->width * m_pTexture->height * fbTexFormats.lutFormatBytes;
|
2017-01-07 09:40:50 +00:00
|
|
|
|
2017-01-21 11:44:56 +00:00
|
|
|
Context::InitTextureParams initParams;
|
2017-01-21 12:48:02 +00:00
|
|
|
initParams.handle = m_pTexture->name;
|
2019-05-08 14:04:24 +00:00
|
|
|
initParams.width = m_pTexture->width;
|
|
|
|
initParams.height = m_pTexture->height;
|
2017-01-14 12:26:02 +00:00
|
|
|
initParams.internalFormat = fbTexFormats.lutInternalFormat;
|
|
|
|
initParams.format = fbTexFormats.lutFormat;
|
|
|
|
initParams.dataType = fbTexFormats.lutType;
|
2017-02-04 15:41:09 +00:00
|
|
|
initParams.data = vecZLUT.data();
|
2017-01-07 09:40:50 +00:00
|
|
|
gfxContext.init2DTexture(initParams);
|
|
|
|
|
2017-01-21 11:44:56 +00:00
|
|
|
Context::TexParameters setParams;
|
2017-01-21 12:48:02 +00:00
|
|
|
setParams.handle = m_pTexture->name;
|
2017-01-28 09:52:09 +00:00
|
|
|
setParams.target = textureTarget::TEXTURE_2D;
|
2017-01-21 11:44:56 +00:00
|
|
|
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;
|
2017-01-07 09:40:50 +00:00
|
|
|
gfxContext.setTextureParameters(setParams);
|
|
|
|
}
|
|
|
|
|
2018-04-05 14:43:30 +00:00
|
|
|
void ZlutTexture::destroy()
|
|
|
|
{
|
2018-04-06 17:17:04 +00:00
|
|
|
if (!Context::IntegerTextures)
|
2017-02-04 15:44:31 +00:00
|
|
|
return;
|
|
|
|
|
2017-01-21 11:44:56 +00:00
|
|
|
const FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats();
|
|
|
|
|
2017-01-07 09:40:50 +00:00
|
|
|
textureCache().removeFrameBufferTexture(m_pTexture);
|
|
|
|
m_pTexture = nullptr;
|
|
|
|
}
|