// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
#pragma once
#include "RendererPass.h"
///
/// Luminance histogram rendering pass. Uses compute shaders.
///
class HistogramPass : public RendererPass
{
private:
AssetReference _shader;
GPUShaderProgramCS* _csClearHistogram;
GPUShaderProgramCS* _csGenerateHistogram;
GPUBuffer* _histogramBuffer = nullptr;
bool _isSupported;
public:
///
/// Performs the histogram rendering.
///
/// The rendering context.
/// The input color buffer to use as a luminance source.
/// The created histogram, or null if failed or not supported.
GPUBuffer* Render(RenderContext& renderContext, GPUTexture* colorBuffer);
///
/// Gets the multiply and add value to pack or unpack data for histogram buffer.
///
/// The multiply factor.
/// The add factor.
void GetHistogramMad(float& multiply, float& add);
private:
#if COMPILE_WITH_DEV_ENV
void OnShaderReloading(Asset* obj)
{
_csClearHistogram = nullptr;
_csGenerateHistogram = nullptr;
invalidateResources();
}
#endif
public:
// [RendererPass]
String ToString() const override;
bool Init() override;
void Dispose() override;
protected:
// [RendererPass]
bool setupResources() override;
};