mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-02-01 14:20:55 +00:00
-got rid of shared_ptr in postprocessing system
This commit is contained in:
parent
c7798d5503
commit
40872a2b21
4 changed files with 42 additions and 28 deletions
|
@ -807,8 +807,8 @@ PPGLTextureBackend *GLPPRenderState::GetGLTexture(PPTexture *texture)
|
|||
case PixelFormat::Rgba16_snorm: glformat = GL_RGBA16_SNORM; break;
|
||||
}
|
||||
|
||||
if (texture->Data)
|
||||
backend->Tex = buffers->Create2DTexture("PPTexture", glformat, texture->Width, texture->Height, texture->Data.get());
|
||||
if (texture->Data.Size())
|
||||
backend->Tex = buffers->Create2DTexture("PPTexture", glformat, texture->Width, texture->Height, texture->Data.Data());
|
||||
else
|
||||
backend->Tex = buffers->Create2DTexture("PPTexture", glformat, texture->Width, texture->Height);
|
||||
|
||||
|
@ -990,4 +990,4 @@ int FGLRenderBuffers::NextEye(int eyeCount)
|
|||
return mCurrentEye;
|
||||
}
|
||||
|
||||
} // namespace OpenGLRenderer
|
||||
} // namespace OpenGLRenderer
|
||||
|
|
|
@ -570,11 +570,9 @@ void PPColormap::Render(PPRenderState *renderstate, int fixedcm, float flash)
|
|||
|
||||
void PPTonemap::UpdateTextures()
|
||||
{
|
||||
if (gl_tonemap == Palette && !PaletteTexture.Data)
|
||||
if (gl_tonemap == Palette && !PaletteTexture.Data.Size())
|
||||
{
|
||||
std::shared_ptr<void> data(new uint32_t[512 * 512], [](void *p) { delete[](uint32_t*)p; });
|
||||
|
||||
uint8_t *lut = (uint8_t *)data.get();
|
||||
uint8_t *lut = PaletteTexture.SetBuffer(512, 512, PixelFormat::Rgba8);
|
||||
for (int r = 0; r < 64; r++)
|
||||
{
|
||||
for (int g = 0; g < 64; g++)
|
||||
|
@ -591,8 +589,6 @@ void PPTonemap::UpdateTextures()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
PaletteTexture = { 512, 512, PixelFormat::Rgba8, data };
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -642,8 +638,7 @@ PPAmbientOcclusion::PPAmbientOcclusion()
|
|||
std::uniform_real_distribution<double> distribution(0.0, 1.0);
|
||||
for (int quality = 0; quality < NumAmbientRandomTextures; quality++)
|
||||
{
|
||||
std::shared_ptr<void> data(new int16_t[16 * 4], [](void *p) { delete[](int16_t*)p; });
|
||||
int16_t *randomValues = (int16_t *)data.get();
|
||||
int16_t *randomValues = (int16_t *)AmbientRandomTexture[quality].SetBuffer(4, 4, PixelFormat::Rgba16_snorm);
|
||||
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
|
@ -658,8 +653,6 @@ PPAmbientOcclusion::PPAmbientOcclusion()
|
|||
randomValues[i * 4 + 2] = (int16_t)clamp(z * 32767.0, -32768.0, 32767.0);
|
||||
randomValues[i * 4 + 3] = (int16_t)clamp(w * 32767.0, -32768.0, 32767.0);
|
||||
}
|
||||
|
||||
AmbientRandomTexture[quality] = { 4, 4, PixelFormat::Rgba16_snorm, data };
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -864,9 +857,8 @@ PPPresent::PPPresent()
|
|||
.8515625, .6015625, .9765625, .7265625, .8671875, .6171875, .9921875, .7421875,
|
||||
};
|
||||
|
||||
std::shared_ptr<void> pixels(new float[64], [](void *p) { delete[](float*)p; });
|
||||
memcpy(pixels.get(), data, 64 * sizeof(float));
|
||||
Dither = { 8, 8, PixelFormat::R32f, pixels };
|
||||
auto p = Dither.SetBuffer(8, 8, PixelFormat::R32f);
|
||||
memcpy(p, data, 64 * sizeof(float));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -1023,11 +1015,10 @@ void PPCustomShaderInstance::SetTextures(PPRenderState *renderstate)
|
|||
if (!pptex)
|
||||
{
|
||||
auto buffer = tex->CreateTexBuffer(0);
|
||||
|
||||
std::shared_ptr<void> data(new uint32_t[buffer.mWidth * buffer.mHeight], [](void *p) { delete[](uint32_t*)p; });
|
||||
pptex = std::make_unique<PPTexture>();
|
||||
auto pixels = pptex->SetBuffer(buffer.mWidth, buffer.mHeight, PixelFormat::Rgba8);
|
||||
|
||||
int count = buffer.mWidth * buffer.mHeight;
|
||||
uint8_t *pixels = (uint8_t *)data.get();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
int pos = i << 2;
|
||||
|
@ -1037,7 +1028,6 @@ void PPCustomShaderInstance::SetTextures(PPRenderState *renderstate)
|
|||
pixels[pos + 3] = buffer.mBuffer[pos + 3];
|
||||
}
|
||||
|
||||
pptex = std::make_unique<PPTexture>(buffer.mWidth, buffer.mHeight, PixelFormat::Rgba8, data);
|
||||
}
|
||||
|
||||
renderstate->SetInputTexture(textureIndex, pptex.get(), PPFilterMode::Linear, PPWrapMode::Repeat);
|
||||
|
|
|
@ -277,17 +277,41 @@ public:
|
|||
class PPTexture : public PPResource
|
||||
{
|
||||
public:
|
||||
PPTexture() = default;
|
||||
PPTexture(int width, int height, PixelFormat format, std::shared_ptr<void> data = {}) : Width(width), Height(height), Format(format), Data(data) { }
|
||||
|
||||
void ResetBackend() override { Backend.reset(); }
|
||||
|
||||
int Width;
|
||||
int Height;
|
||||
PixelFormat Format;
|
||||
std::shared_ptr<void> Data;
|
||||
TArray<uint8_t> Data;
|
||||
|
||||
std::unique_ptr<PPTextureBackend> Backend;
|
||||
|
||||
explicit PPTexture() = default;
|
||||
|
||||
PPTexture(int w, int h, PixelFormat f)
|
||||
{
|
||||
Width = w;
|
||||
Height = h;
|
||||
Format = f;
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
Width = Height = 0;
|
||||
Format = PixelFormat::Rgba8;
|
||||
Data.Reset();
|
||||
}
|
||||
|
||||
uint8_t* SetBuffer(int w, int h, PixelFormat f)
|
||||
{
|
||||
Width = w;
|
||||
Height = h;
|
||||
Format = f;
|
||||
unsigned size = f == PixelFormat::Rgba16f || f == PixelFormat::Rgba16_snorm? 8 : 4;
|
||||
Data.Resize(w * h * size);
|
||||
return Data.Data();
|
||||
}
|
||||
};
|
||||
|
||||
class PPShaderBackend
|
||||
|
@ -497,7 +521,7 @@ class PPCameraExposure
|
|||
public:
|
||||
void Render(PPRenderState *renderstate, int sceneWidth, int sceneHeight);
|
||||
|
||||
PPTexture CameraTexture = { 1, 1, PixelFormat::R32f };
|
||||
PPTexture CameraTexture;// = { 1, 1, PixelFormat::R32f };
|
||||
|
||||
private:
|
||||
void UpdateTextures(int width, int height);
|
||||
|
@ -542,7 +566,7 @@ class PPTonemap
|
|||
{
|
||||
public:
|
||||
void Render(PPRenderState *renderstate);
|
||||
void ClearTonemapPalette() { PaletteTexture = {}; }
|
||||
void ClearTonemapPalette() { PaletteTexture.Clear(); }
|
||||
|
||||
private:
|
||||
void UpdateTextures();
|
||||
|
|
|
@ -364,7 +364,7 @@ VkPPTexture::VkPPTexture(PPTexture *texture)
|
|||
ImageBuilder imgbuilder;
|
||||
imgbuilder.setFormat(format);
|
||||
imgbuilder.setSize(texture->Width, texture->Height);
|
||||
if (texture->Data)
|
||||
if (texture->Data.Size())
|
||||
imgbuilder.setUsage(VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT);
|
||||
else
|
||||
imgbuilder.setUsage(VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
|
||||
|
@ -379,7 +379,7 @@ VkPPTexture::VkPPTexture(PPTexture *texture)
|
|||
TexImage.View = viewbuilder.create(fb->device);
|
||||
TexImage.View->SetDebugName("VkPPTextureView");
|
||||
|
||||
if (texture->Data)
|
||||
if (texture->Data.Size())
|
||||
{
|
||||
size_t totalsize = texture->Width * texture->Height * pixelsize;
|
||||
BufferBuilder stagingbuilder;
|
||||
|
@ -393,7 +393,7 @@ VkPPTexture::VkPPTexture(PPTexture *texture)
|
|||
barrier0.execute(fb->GetTransferCommands());
|
||||
|
||||
void *data = Staging->Map(0, totalsize);
|
||||
memcpy(data, texture->Data.get(), totalsize);
|
||||
memcpy(data, texture->Data.Data(), totalsize);
|
||||
Staging->Unmap();
|
||||
|
||||
VkBufferImageCopy region = {};
|
||||
|
|
Loading…
Reference in a new issue