1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-02 09:03:37 +00:00
GLideN64/src/NoiseTexture.cpp

100 lines
2.9 KiB
C++
Raw Normal View History

2017-01-05 12:37:14 +00:00
#include <Graphics/Context.h>
#include <Graphics/Parameters.h>
#include "FrameBuffer.h"
#include "Config.h"
2017-01-05 12:37:14 +00:00
#include "GBI.h"
#include "VI.h"
2017-01-05 12:37:14 +00:00
#include "Textures.h"
#include "NoiseTexture.h"
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);
{
graphics::Context::InitTextureParams params;
params.handle = graphics::ObjectHandle(m_pTexture->glName);
params.width = m_pTexture->realWidth;
params.height = m_pTexture->realHeight;
params.internalFormat = graphics::internalcolor::RED;
params.format = graphics::color::RED;
params.dataType = graphics::datatype::UNSIGNED_BYTE;
gfxContext.init2DTexture(params);
}
{
graphics::Context::TexParameters params;
params.handle = graphics::ObjectHandle(m_pTexture->glName);
params.target = graphics::target::TEXTURE_2D;
2017-01-06 08:19:35 +00:00
params.textureUnitIndex = graphics::textureIndices::NoiseTex;
2017-01-05 12:37:14 +00:00
params.minFilter = graphics::textureParameters::FILTER_NEAREST;
params.magFilter = graphics::textureParameters::FILTER_NEAREST;
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;
if (m_DList == video().getBuffersSwapCount() || config.generalEmulation.enableNoise == 0)
return;
const u32 dataSize = VI.width*VI.height;
if (dataSize == 0)
return;
2017-01-06 07:33:49 +00:00
graphics::PixelBufferBinder<graphics::PixelWriteBuffer> binder(m_pbuf.get());
GLubyte* ptr = (GLubyte*)m_pbuf->getWriteBuffer(dataSize);
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();
graphics::Context::UpdateTextureDataParams params;
params.handle = graphics::ObjectHandle(m_pTexture->glName);
2017-01-06 08:19:35 +00:00
params.textureUnitIndex = graphics::textureIndices::NoiseTex;
2017-01-06 07:33:49 +00:00
params.width = VI.width;
params.height = VI.height;
params.format = graphics::color::RED;
params.dataType = graphics::datatype::UNSIGNED_BYTE;
params.data = m_pbuf->getData();
gfxContext.update2DTexture(params);
2017-01-05 12:37:14 +00:00
m_DList = video().getBuffersSwapCount();
}