Path: blob/master/servers/rendering/renderer_rd/renderer_compositor_rd.h
21689 views
/**************************************************************************/1/* renderer_compositor_rd.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "core/io/image.h"33#include "servers/rendering/renderer_compositor.h"34#include "servers/rendering/renderer_rd/environment/fog.h"35#include "servers/rendering/renderer_rd/framebuffer_cache_rd.h"36#include "servers/rendering/renderer_rd/renderer_canvas_render_rd.h"37#include "servers/rendering/renderer_rd/renderer_scene_render_rd.h"38#include "servers/rendering/renderer_rd/shaders/blit.glsl.gen.h"39#include "servers/rendering/renderer_rd/storage_rd/light_storage.h"40#include "servers/rendering/renderer_rd/storage_rd/material_storage.h"41#include "servers/rendering/renderer_rd/storage_rd/mesh_storage.h"42#include "servers/rendering/renderer_rd/storage_rd/particles_storage.h"43#include "servers/rendering/renderer_rd/storage_rd/texture_storage.h"44#include "servers/rendering/renderer_rd/storage_rd/utilities.h"45#include "servers/rendering/renderer_rd/uniform_set_cache_rd.h"4647class RendererCompositorRD : public RendererCompositor {48protected:49UniformSetCacheRD *uniform_set_cache = nullptr;50FramebufferCacheRD *framebuffer_cache = nullptr;51RendererCanvasRenderRD *canvas = nullptr;52RendererRD::Utilities *utilities = nullptr;53RendererRD::LightStorage *light_storage = nullptr;54RendererRD::MaterialStorage *material_storage = nullptr;55RendererRD::MeshStorage *mesh_storage = nullptr;56RendererRD::ParticlesStorage *particles_storage = nullptr;57RendererRD::TextureStorage *texture_storage = nullptr;58RendererRD::Fog *fog = nullptr;59RendererSceneRenderRD *scene = nullptr;6061enum BlitMode {62BLIT_MODE_NORMAL,63BLIT_MODE_USE_LAYER,64BLIT_MODE_LENS,65BLIT_MODE_NORMAL_ALPHA,66BLIT_MODE_MAX67};6869struct BlitPushConstant {70float src_rect[4]; // 16 - 1671float dst_rect[4]; // 16 - 327273float rotation_sin; // 4 - 3674float rotation_cos; // 4 - 4075float eye_center[2]; // 8 - 487677float k1; // 4 - 5278float k2; // 4 - 5679float upscale; // 4 - 6080float aspect_ratio; // 4 - 648182uint32_t layer; // 4 - 6883uint32_t source_is_srgb; // 4 - 7284uint32_t use_debanding; // 4 - 7685uint32_t target_color_space; // 4 - 808687float reference_multiplier; // 4 - 8488float output_max_value; // 4 - 8889uint32_t pad[2]; // 8 - 96 (padding to reach 16-byte boundary)90};9192struct BlitPipelines {93RID pipelines[BLIT_MODE_MAX];94};9596struct Blit {97BlitPushConstant push_constant;98BlitShaderRD shader;99RID shader_version;100HashMap<RenderingDevice::FramebufferFormatID, BlitPipelines> pipelines_by_format;101RID index_buffer;102RID array;103RID sampler;104} blit;105106HashMap<RID, RID> render_target_descriptors;107108double time = 0.0;109double delta = 0.0;110111static uint64_t frame;112static RendererCompositorRD *singleton;113114BlitPipelines _get_blit_pipelines_for_format(RenderingDevice::FramebufferFormatID format);115float _compute_reference_multiplier(RD::ColorSpace p_color_space, const float p_reference_luminance, const float p_linear_luminance_scale);116117public:118virtual RendererUtilities *get_utilities() override { return utilities; }119virtual RendererLightStorage *get_light_storage() override { return light_storage; }120virtual RendererMaterialStorage *get_material_storage() override { return material_storage; }121virtual RendererMeshStorage *get_mesh_storage() override { return mesh_storage; }122virtual RendererParticlesStorage *get_particles_storage() override { return particles_storage; }123virtual RendererTextureStorage *get_texture_storage() override { return texture_storage; }124virtual RendererGI *get_gi() override {125ERR_FAIL_NULL_V(scene, nullptr);126return scene->get_gi();127}128virtual RendererFog *get_fog() override { return fog; }129virtual RendererCanvasRender *get_canvas() override { return canvas; }130virtual RendererSceneRender *get_scene() override { return scene; }131132virtual void set_boot_image_with_stretch(const Ref<Image> &p_image, const Color &p_color, RenderingServer::SplashStretchMode p_stretch_mode, bool p_use_filter) override;133134virtual void initialize() override;135virtual void begin_frame(double frame_step) override;136virtual void blit_render_targets_to_screen(DisplayServer::WindowID p_screen, const BlitToScreen *p_render_targets, int p_amount) override;137138virtual bool is_opengl() override { return false; }139virtual void gl_end_frame(bool p_swap_buffers) override {}140virtual void end_frame(bool p_present) override;141virtual void finalize() override;142143_ALWAYS_INLINE_ virtual uint64_t get_frame_number() const override { return frame; }144_ALWAYS_INLINE_ virtual double get_frame_delta_time() const override { return delta; }145_ALWAYS_INLINE_ virtual double get_total_time() const override { return time; }146_ALWAYS_INLINE_ virtual bool can_create_resources_async() const override { return true; }147148virtual bool is_xr_enabled() const override { return RendererCompositor::is_xr_enabled(); }149150static Error is_viable() {151return OK;152}153154static RendererCompositor *_create_current() {155return memnew(RendererCompositorRD);156}157158static void make_current() {159_create_func = _create_current;160low_end = false;161}162163static RendererCompositorRD *get_singleton() { return singleton; }164RendererCompositorRD();165~RendererCompositorRD();166};167168169