postprocessing_shader_glsl.h (2032B)
1 // SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com> 2 // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) 3 4 #pragma once 5 6 #include "postprocessing_shader.h" 7 8 namespace PostProcessing { 9 10 class GLSLShader final : public Shader 11 { 12 public: 13 GLSLShader(); 14 GLSLShader(std::string name, std::string code); 15 ~GLSLShader(); 16 17 ALWAYS_INLINE const std::string& GetCode() const { return m_code; } 18 19 bool IsValid() const override; 20 bool WantsDepthBuffer() const override; 21 22 bool LoadFromFile(std::string name, const char* filename, Error* error); 23 bool LoadFromString(std::string name, std::string code, Error* error); 24 25 bool ResizeOutput(GPUTexture::Format format, u32 width, u32 height) override; 26 bool CompilePipeline(GPUTexture::Format format, u32 width, u32 height, ProgressCallback* progress) override; 27 bool Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUTexture* final_target, GSVector4i final_rect, 28 s32 orig_width, s32 orig_height, s32 native_width, s32 native_height, u32 target_width, 29 u32 target_height) override; 30 31 private: 32 struct CommonUniforms 33 { 34 float src_rect[4]; 35 float src_size[2]; 36 float window_size[2]; 37 float rcp_window_size[2]; 38 float viewport_size[2]; 39 float window_to_viewport_ratio[2]; 40 float internal_size[2]; 41 float internal_pixel_size[2]; 42 float norm_internal_pixel_size[2]; 43 float native_size[2]; 44 float native_pixel_size[2]; 45 float norm_native_pixel_size[2]; 46 float upscale_multiplier; 47 float time; 48 }; 49 50 void LoadOptions(); 51 52 u32 GetUniformsSize() const; 53 void FillUniformBuffer(void* buffer, s32 viewport_x, s32 viewport_y, s32 viewport_width, s32 viewport_height, 54 u32 window_width, u32 window_height, s32 original_width, s32 original_height, s32 native_width, 55 s32 native_height, float time) const; 56 57 std::string m_code; 58 59 std::unique_ptr<GPUPipeline> m_pipeline; 60 std::unique_ptr<GPUSampler> m_sampler; 61 }; 62 63 } // namespace PostProcessing