2017-01-05 12:37:14 +00:00
|
|
|
#include <Graphics/Context.h>
|
|
|
|
#include <Graphics/Parameters.h>
|
|
|
|
#include "FrameBuffer.h"
|
2017-01-10 15:22:32 +00:00
|
|
|
#include "Config.h"
|
2017-01-05 12:37:14 +00:00
|
|
|
#include "GBI.h"
|
2017-01-10 15:22:32 +00:00
|
|
|
#include "VI.h"
|
2017-01-05 12:37:14 +00:00
|
|
|
#include "Textures.h"
|
|
|
|
#include "NoiseTexture.h"
|
2017-01-15 07:57:25 +00:00
|
|
|
#include "DisplayWindow.h"
|
2017-01-05 12:37:14 +00:00
|
|
|
|
2017-01-21 12:48:02 +00:00
|
|
|
using namespace graphics;
|
|
|
|
|
2017-01-05 12:37:14 +00:00
|
|
|
NoiseTexture g_noiseTexture;
|
|
|
|
|
|
|
|
NoiseTexture::NoiseTexture()
|
|
|
|
: m_pTexture(nullptr)
|
|
|
|
, m_DList(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void NoiseTexture::init()
|
|
|
|
{
|
|
|
|
if (config.generalEmulation.enableNoise == 0)
|
|
|
|
return;
|
|
|
|
m_pTexture = textureCache().addFrameBufferTexture(false);
|
|
|
|
m_pTexture->format = G_IM_FMT_RGBA;
|
|
|
|
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;
|
|
|
|
m_pTexture->realWidth = 640;
|
|
|
|
m_pTexture->realHeight = 580;
|
|
|
|
m_pTexture->textureBytes = m_pTexture->realWidth * m_pTexture->realHeight;
|
|
|
|
textureCache().addFrameBufferTextureSize(m_pTexture->textureBytes);
|
|
|
|
|
|
|
|
{
|
2017-01-21 12:48:02 +00:00
|
|
|
Context::InitTextureParams params;
|
|
|
|
params.handle = m_pTexture->name;
|
2017-01-05 12:37:14 +00:00
|
|
|
params.width = m_pTexture->realWidth;
|
|
|
|
params.height = m_pTexture->realHeight;
|
2017-01-28 09:52:09 +00:00
|
|
|
params.internalFormat = internalcolorFormat::RED;
|
|
|
|
params.format = colorFormat::RED;
|
2017-01-21 12:48:02 +00:00
|
|
|
params.dataType = datatype::UNSIGNED_BYTE;
|
2017-01-05 12:37:14 +00:00
|
|
|
gfxContext.init2DTexture(params);
|
|
|
|
}
|
|
|
|
{
|
2017-01-21 12:48:02 +00:00
|
|
|
Context::TexParameters params;
|
|
|
|
params.handle = m_pTexture->name;
|
2017-01-28 09:52:09 +00:00
|
|
|
params.target = textureTarget::TEXTURE_2D;
|
2017-01-21 12:48:02 +00:00
|
|
|
params.textureUnitIndex = textureIndices::NoiseTex;
|
|
|
|
params.minFilter = textureParameters::FILTER_NEAREST;
|
|
|
|
params.magFilter = textureParameters::FILTER_NEAREST;
|
2017-01-05 12:37:14 +00:00
|
|
|
gfxContext.setTextureParameters(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate Pixel Buffer Object. Initialize it with max buffer size.
|
2017-01-07 09:40:50 +00:00
|
|
|
m_pbuf.reset(gfxContext.createPixelWriteBuffer(m_pTexture->textureBytes));
|
2017-01-05 12:37:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NoiseTexture::destroy()
|
|
|
|
{
|
2017-01-06 07:33:49 +00:00
|
|
|
textureCache().removeFrameBufferTexture(m_pTexture);
|
|
|
|
m_pTexture = nullptr;
|
|
|
|
m_pbuf.reset();
|
2017-01-05 12:37:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NoiseTexture::update()
|
|
|
|
{
|
2017-01-06 07:33:49 +00:00
|
|
|
if (!m_pbuf || m_pTexture == nullptr)
|
2017-01-05 12:37:14 +00:00
|
|
|
return;
|
2017-01-15 07:57:25 +00:00
|
|
|
if (m_DList == dwnd().getBuffersSwapCount() || config.generalEmulation.enableNoise == 0)
|
2017-01-05 12:37:14 +00:00
|
|
|
return;
|
|
|
|
const u32 dataSize = VI.width*VI.height;
|
|
|
|
if (dataSize == 0)
|
|
|
|
return;
|
2017-01-06 07:33:49 +00:00
|
|
|
|
2017-01-21 12:48:02 +00:00
|
|
|
PixelBufferBinder<PixelWriteBuffer> binder(m_pbuf.get());
|
2017-01-22 13:43:05 +00:00
|
|
|
u8* ptr = (u8*)m_pbuf->getWriteBuffer(dataSize);
|
2017-01-06 07:33:49 +00:00
|
|
|
if (ptr == nullptr) {
|
2017-01-05 12:37:14 +00:00
|
|
|
return;
|
2017-01-06 07:33:49 +00:00
|
|
|
}
|
2017-01-05 12:37:14 +00:00
|
|
|
for (u32 y = 0; y < VI.height; ++y) {
|
|
|
|
for (u32 x = 0; x < VI.width; ++x)
|
|
|
|
ptr[x + y*VI.width] = rand() & 0xFF;
|
|
|
|
}
|
2017-01-06 07:33:49 +00:00
|
|
|
m_pbuf->closeWriteBuffer();
|
|
|
|
|
2017-01-21 12:48:02 +00:00
|
|
|
Context::UpdateTextureDataParams params;
|
|
|
|
params.handle = m_pTexture->name;
|
|
|
|
params.textureUnitIndex = textureIndices::NoiseTex;
|
2017-01-06 07:33:49 +00:00
|
|
|
params.width = VI.width;
|
|
|
|
params.height = VI.height;
|
2017-01-28 09:52:09 +00:00
|
|
|
params.format = colorFormat::RED;
|
2017-01-21 12:48:02 +00:00
|
|
|
params.dataType = datatype::UNSIGNED_BYTE;
|
2017-01-06 07:33:49 +00:00
|
|
|
params.data = m_pbuf->getData();
|
|
|
|
gfxContext.update2DTexture(params);
|
2017-01-05 12:37:14 +00:00
|
|
|
|
2017-01-15 07:57:25 +00:00
|
|
|
m_DList = dwnd().getBuffersSwapCount();
|
2017-01-05 12:37:14 +00:00
|
|
|
}
|