Path: blob/master/servers/rendering/renderer_rd/renderer_compositor_rd.h
10278 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];71float dst_rect[4];7273float rotation_sin;74float rotation_cos;7576float eye_center[2];77float k1;78float k2;7980float upscale;81float aspect_ratio;82uint32_t layer;83uint32_t convert_to_srgb;84uint32_t use_debanding;85float pad;86};8788struct Blit {89BlitPushConstant push_constant;90BlitShaderRD shader;91RID shader_version;92RID pipelines[BLIT_MODE_MAX];93RID index_buffer;94RID array;95RID sampler;96} blit;9798HashMap<RID, RID> render_target_descriptors;99100double time = 0.0;101double delta = 0.0;102103static uint64_t frame;104static RendererCompositorRD *singleton;105106public:107RendererUtilities *get_utilities() { return utilities; }108RendererLightStorage *get_light_storage() { return light_storage; }109RendererMaterialStorage *get_material_storage() { return material_storage; }110RendererMeshStorage *get_mesh_storage() { return mesh_storage; }111RendererParticlesStorage *get_particles_storage() { return particles_storage; }112RendererTextureStorage *get_texture_storage() { return texture_storage; }113RendererGI *get_gi() {114ERR_FAIL_NULL_V(scene, nullptr);115return scene->get_gi();116}117RendererFog *get_fog() { return fog; }118RendererCanvasRender *get_canvas() { return canvas; }119RendererSceneRender *get_scene() { return scene; }120121void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter);122123void initialize();124void begin_frame(double frame_step);125void blit_render_targets_to_screen(DisplayServer::WindowID p_screen, const BlitToScreen *p_render_targets, int p_amount);126127bool is_opengl() { return false; }128void gl_end_frame(bool p_swap_buffers) {}129void end_frame(bool p_present);130void finalize();131132_ALWAYS_INLINE_ uint64_t get_frame_number() const { return frame; }133_ALWAYS_INLINE_ double get_frame_delta_time() const { return delta; }134_ALWAYS_INLINE_ double get_total_time() const { return time; }135_ALWAYS_INLINE_ bool can_create_resources_async() const { return true; }136137virtual bool is_xr_enabled() const { return RendererCompositor::is_xr_enabled(); }138139static Error is_viable() {140return OK;141}142143static RendererCompositor *_create_current() {144return memnew(RendererCompositorRD);145}146147static void make_current() {148_create_func = _create_current;149low_end = false;150}151152static RendererCompositorRD *get_singleton() { return singleton; }153RendererCompositorRD();154~RendererCompositorRD();155};156157158