Path: blob/master/servers/rendering/renderer_rd/framebuffer_cache_rd.cpp
10279 views
/**************************************************************************/1/* framebuffer_cache_rd.cpp */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#include "framebuffer_cache_rd.h"3132FramebufferCacheRD *FramebufferCacheRD::singleton = nullptr;3334void FramebufferCacheRD::_bind_methods() {35ClassDB::bind_static_method("FramebufferCacheRD", D_METHOD("get_cache_multipass", "textures", "passes", "views"), &FramebufferCacheRD::get_cache_multipass_array);36}3738void FramebufferCacheRD::_invalidate(Cache *p_cache) {39if (p_cache->prev) {40p_cache->prev->next = p_cache->next;41} else {42// At beginning of table43uint32_t table_idx = p_cache->hash % HASH_TABLE_SIZE;44hash_table[table_idx] = p_cache->next;45}4647if (p_cache->next) {48p_cache->next->prev = p_cache->prev;49}5051cache_allocator.free(p_cache);52cache_instances_used--;53}54void FramebufferCacheRD::_framebuffer_invalidation_callback(void *p_userdata) {55singleton->_invalidate(reinterpret_cast<Cache *>(p_userdata));56}5758RID FramebufferCacheRD::get_cache_multipass_array(const TypedArray<RID> &p_textures, const TypedArray<RDFramebufferPass> &p_passes, uint32_t p_views) {59Vector<RID> textures;60Vector<RD::FramebufferPass> passes;6162for (int i = 0; i < p_textures.size(); i++) {63RID texture = p_textures[i];64textures.push_back(texture); // store even if NULL65}6667for (int i = 0; i < p_passes.size(); i++) {68Ref<RDFramebufferPass> pass = p_passes[i];69if (pass.is_valid()) {70passes.push_back(pass->base);71}72}7374return FramebufferCacheRD::get_singleton()->get_cache_multipass(textures, passes, p_views);75}7677FramebufferCacheRD::FramebufferCacheRD() {78ERR_FAIL_COND(singleton != nullptr);79singleton = this;80}8182FramebufferCacheRD::~FramebufferCacheRD() {83if (cache_instances_used > 0) {84ERR_PRINT("At exit: " + itos(cache_instances_used) + " framebuffer cache instance(s) still in use.");85}86}878889