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-29 14:58:43 +00:00
|
|
|
#include <cstdlib>
|
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()
|
2017-02-01 20:38:02 +00:00
|
|
|
: m_DList(0)
|
2017-01-05 12:37:14 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void NoiseTexture::init()
|
|
|
|
{
|
|
|
|
if (config.generalEmulation.enableNoise == 0)
|
|
|
|
return;
|
2017-02-19 07:46:47 +00:00
|
|
|
|
|
|
|
std::vector<u16> ptr(640 * 580 / 2);
|
|
|
|
|
2017-02-01 20:38:02 +00:00
|
|
|
for (u32 i = 0; i < NOISE_TEX_NUM; ++i) {
|
|
|
|
m_pTexture[i] = textureCache().addFrameBufferTexture(false);
|
|
|
|
m_pTexture[i]->format = G_IM_FMT_RGBA;
|
|
|
|
m_pTexture[i]->clampS = 1;
|
|
|
|
m_pTexture[i]->clampT = 1;
|
|
|
|
m_pTexture[i]->frameBufferTexture = CachedTexture::fbOneSample;
|
|
|
|
m_pTexture[i]->maskS = 0;
|
|
|
|
m_pTexture[i]->maskT = 0;
|
|
|
|
m_pTexture[i]->mirrorS = 0;
|
|
|
|
m_pTexture[i]->mirrorT = 0;
|
|
|
|
m_pTexture[i]->realWidth = 640;
|
|
|
|
m_pTexture[i]->realHeight = 580;
|
|
|
|
m_pTexture[i]->textureBytes = m_pTexture[i]->realWidth * m_pTexture[i]->realHeight;
|
|
|
|
textureCache().addFrameBufferTextureSize(m_pTexture[i]->textureBytes);
|
2017-01-05 12:37:14 +00:00
|
|
|
|
2017-02-05 06:47:36 +00:00
|
|
|
const FramebufferTextureFormats & fbTexFormats = gfxContext.getFramebufferTextureFormats();
|
2017-02-01 20:38:02 +00:00
|
|
|
{
|
|
|
|
Context::InitTextureParams params;
|
|
|
|
params.handle = m_pTexture[i]->name;
|
|
|
|
params.width = m_pTexture[i]->realWidth;
|
|
|
|
params.height = m_pTexture[i]->realHeight;
|
2017-02-05 06:47:36 +00:00
|
|
|
params.internalFormat = fbTexFormats.noiseInternalFormat;
|
|
|
|
params.format = fbTexFormats.noiseFormat;
|
|
|
|
params.dataType = fbTexFormats.noiseType;
|
2017-02-01 20:38:02 +00:00
|
|
|
gfxContext.init2DTexture(params);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
Context::TexParameters params;
|
|
|
|
params.handle = m_pTexture[i]->name;
|
|
|
|
params.target = textureTarget::TEXTURE_2D;
|
|
|
|
params.textureUnitIndex = textureIndices::NoiseTex;
|
|
|
|
params.minFilter = textureParameters::FILTER_NEAREST;
|
|
|
|
params.magFilter = textureParameters::FILTER_NEAREST;
|
|
|
|
gfxContext.setTextureParameters(params);
|
|
|
|
}
|
2017-02-19 07:46:47 +00:00
|
|
|
const u32 widthWords = m_pTexture[i]->realWidth / 2;
|
2017-02-01 20:38:02 +00:00
|
|
|
for (u32 y = 0; y < m_pTexture[i]->realHeight; ++y) {
|
2017-02-19 07:46:47 +00:00
|
|
|
for (u32 x = 0; x < widthWords; ++x)
|
|
|
|
ptr[x + y*widthWords] = rand() & 0xFFFF;
|
2017-02-01 20:38:02 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
Context::UpdateTextureDataParams params;
|
|
|
|
params.handle = m_pTexture[i]->name;
|
|
|
|
params.textureUnitIndex = textureIndices::NoiseTex;
|
2017-02-19 07:46:47 +00:00
|
|
|
params.width = m_pTexture[i]->realWidth;
|
|
|
|
params.height = m_pTexture[i]->realHeight;
|
2017-02-05 06:47:36 +00:00
|
|
|
params.format = fbTexFormats.noiseFormat;
|
|
|
|
params.dataType = fbTexFormats.noiseType;
|
2017-02-03 14:10:08 +00:00
|
|
|
params.data = ptr.data();
|
2017-02-01 20:38:02 +00:00
|
|
|
gfxContext.update2DTexture(params);
|
|
|
|
}
|
2017-01-05 12:37:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NoiseTexture::destroy()
|
|
|
|
{
|
2017-02-01 20:38:02 +00:00
|
|
|
for (u32 i = 0; i < NOISE_TEX_NUM; ++i) {
|
|
|
|
textureCache().removeFrameBufferTexture(m_pTexture[i]);
|
|
|
|
m_pTexture[i] = nullptr;
|
|
|
|
}
|
2017-01-05 12:37:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NoiseTexture::update()
|
|
|
|
{
|
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;
|
2017-01-06 07:33:49 +00:00
|
|
|
|
2017-02-01 20:38:02 +00:00
|
|
|
while (m_currTex == m_prevTex)
|
|
|
|
m_currTex = rand() % NOISE_TEX_NUM;
|
|
|
|
m_prevTex = m_currTex;
|
|
|
|
if (m_pTexture[m_currTex] == nullptr)
|
2017-01-05 12:37:14 +00:00
|
|
|
return;
|
2017-02-01 20:38:02 +00:00
|
|
|
{
|
|
|
|
Context::BindTextureParameters params;
|
|
|
|
params.texture = m_pTexture[m_currTex]->name;
|
|
|
|
params.textureUnitIndex = textureIndices::NoiseTex;
|
|
|
|
params.target = textureTarget::TEXTURE_2D;
|
|
|
|
gfxContext.bindTexture(params);
|
2017-01-06 07:33:49 +00:00
|
|
|
}
|
2017-01-15 07:57:25 +00:00
|
|
|
m_DList = dwnd().getBuffersSwapCount();
|
2017-01-05 12:37:14 +00:00
|
|
|
}
|