Path: blob/master/servers/rendering/dummy/storage/texture_storage.h
21318 views
/**************************************************************************/1/* texture_storage.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 "servers/rendering/storage/texture_storage.h"3334namespace RendererDummy {3536class TextureStorage : public RendererTextureStorage {37private:38static inline TextureStorage *singleton = nullptr;3940struct DummyTexture {41Ref<Image> image;42};43mutable RID_PtrOwner<DummyTexture> texture_owner;4445public:46static TextureStorage *get_singleton() { return singleton; }4748TextureStorage() { singleton = this; }49~TextureStorage() { singleton = nullptr; }5051/* Canvas Texture API */5253virtual RID canvas_texture_allocate() override { return RID(); }54virtual void canvas_texture_initialize(RID p_rid) override {}55virtual void canvas_texture_free(RID p_rid) override {}5657virtual void canvas_texture_set_channel(RID p_canvas_texture, RS::CanvasTextureChannel p_channel, RID p_texture) override {}58virtual void canvas_texture_set_shading_parameters(RID p_canvas_texture, const Color &p_base_color, float p_shininess) override {}5960virtual void canvas_texture_set_texture_filter(RID p_item, RS::CanvasItemTextureFilter p_filter) override {}61virtual void canvas_texture_set_texture_repeat(RID p_item, RS::CanvasItemTextureRepeat p_repeat) override {}6263/* Texture API */6465bool owns_texture(RID p_rid) { return texture_owner.owns(p_rid); }6667virtual RID texture_allocate() override {68DummyTexture *texture = memnew(DummyTexture);69ERR_FAIL_NULL_V(texture, RID());70return texture_owner.make_rid(texture);71}7273virtual void texture_free(RID p_rid) override {74// delete the texture75DummyTexture *texture = texture_owner.get_or_null(p_rid);76ERR_FAIL_NULL(texture);77texture_owner.free(p_rid);78memdelete(texture);79}8081virtual void texture_2d_initialize(RID p_texture, const Ref<Image> &p_image) override {82DummyTexture *t = texture_owner.get_or_null(p_texture);83ERR_FAIL_NULL(t);84t->image = p_image->duplicate();85}86virtual void texture_2d_layered_initialize(RID p_texture, const Vector<Ref<Image>> &p_layers, RS::TextureLayeredType p_layered_type) override {}87virtual void texture_3d_initialize(RID p_texture, Image::Format, int p_width, int p_height, int p_depth, bool p_mipmaps, const Vector<Ref<Image>> &p_data) override {}88virtual void texture_external_initialize(RID p_texture, int p_width, int p_height, uint64_t p_external_buffer) override {}89virtual void texture_proxy_initialize(RID p_texture, RID p_base) override {} //all slices, then all the mipmaps, must be coherent90virtual void texture_drawable_initialize(RID p_texture, int p_width, int p_height, RS::TextureDrawableFormat p_format, const Color &p_color, bool p_with_mipmaps) override {}9192virtual RID texture_create_from_native_handle(RS::TextureType p_type, Image::Format p_format, uint64_t p_native_handle, int p_width, int p_height, int p_depth, int p_layers = 1, RS::TextureLayeredType p_layered_type = RS::TEXTURE_LAYERED_2D_ARRAY) override { return RID(); }9394virtual void texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) override {}95virtual void texture_3d_update(RID p_texture, const Vector<Ref<Image>> &p_data) override {}96virtual void texture_external_update(RID p_texture, int p_width, int p_height, uint64_t p_external_buffer) override {}97virtual void texture_proxy_update(RID p_proxy, RID p_base) override {}9899virtual void texture_drawable_blit_rect(const TypedArray<RID> &p_textures, const Rect2i &p_rect, RID p_material, const Color &p_modulate, const TypedArray<RID> &p_source_textures, int p_to_mipmap) override {}100101//these two APIs can be used together or in combination with the others.102virtual void texture_2d_placeholder_initialize(RID p_texture) override {}103virtual void texture_2d_layered_placeholder_initialize(RID p_texture, RenderingServer::TextureLayeredType p_layered_type) override {}104virtual void texture_3d_placeholder_initialize(RID p_texture) override {}105106virtual Ref<Image> texture_2d_get(RID p_texture) const override {107DummyTexture *t = texture_owner.get_or_null(p_texture);108ERR_FAIL_NULL_V(t, Ref<Image>());109return t->image;110}111virtual Ref<Image> texture_2d_layer_get(RID p_texture, int p_layer) const override { return Ref<Image>(); }112virtual Vector<Ref<Image>> texture_3d_get(RID p_texture) const override { return Vector<Ref<Image>>(); }113114virtual void texture_drawable_generate_mipmaps(RID p_texture) override {}115virtual RID texture_drawable_get_default_material() const override { return RID(); }116117virtual void texture_replace(RID p_texture, RID p_by_texture) override { texture_free(p_by_texture); }118virtual void texture_set_size_override(RID p_texture, int p_width, int p_height) override {}119120virtual void texture_set_path(RID p_texture, const String &p_path) override {}121virtual String texture_get_path(RID p_texture) const override { return String(); }122123virtual Image::Format texture_get_format(RID p_texture) const override { return Image::FORMAT_MAX; }124125virtual void texture_set_detect_3d_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) override {}126virtual void texture_set_detect_normal_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) override {}127virtual void texture_set_detect_roughness_callback(RID p_texture, RS::TextureDetectRoughnessCallback p_callback, void *p_userdata) override {}128129virtual void texture_debug_usage(List<RS::TextureInfo> *r_info) override {}130131virtual void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) override {}132133virtual Size2 texture_size_with_proxy(RID p_proxy) override { return Size2(); }134135virtual void texture_rd_initialize(RID p_texture, const RID &p_rd_texture, const RS::TextureLayeredType p_layer_type = RS::TEXTURE_LAYERED_2D_ARRAY) override {}136virtual RID texture_get_rd_texture(RID p_texture, bool p_srgb = false) const override { return RID(); }137virtual uint64_t texture_get_native_handle(RID p_texture, bool p_srgb = false) const override { return 0; }138139/* DECAL API */140virtual RID decal_allocate() override { return RID(); }141virtual void decal_initialize(RID p_rid) override {}142virtual void decal_free(RID p_rid) override {}143144virtual void decal_set_size(RID p_decal, const Vector3 &p_size) override {}145virtual void decal_set_texture(RID p_decal, RS::DecalTexture p_type, RID p_texture) override {}146virtual void decal_set_emission_energy(RID p_decal, float p_energy) override {}147virtual void decal_set_albedo_mix(RID p_decal, float p_mix) override {}148virtual void decal_set_modulate(RID p_decal, const Color &p_modulate) override {}149virtual void decal_set_cull_mask(RID p_decal, uint32_t p_layers) override {}150virtual void decal_set_distance_fade(RID p_decal, bool p_enabled, float p_begin, float p_length) override {}151virtual void decal_set_fade(RID p_decal, float p_above, float p_below) override {}152virtual void decal_set_normal_fade(RID p_decal, float p_fade) override {}153154virtual AABB decal_get_aabb(RID p_decal) const override { return AABB(); }155virtual uint32_t decal_get_cull_mask(RID p_decal) const override { return 0; }156157virtual void texture_add_to_decal_atlas(RID p_texture, bool p_panorama_to_dp = false) override {}158virtual void texture_remove_from_decal_atlas(RID p_texture, bool p_panorama_to_dp = false) override {}159160/* DECAL INSTANCE */161162virtual RID decal_instance_create(RID p_decal) override { return RID(); }163virtual void decal_instance_free(RID p_decal_instance) override {}164virtual void decal_instance_set_transform(RID p_decal, const Transform3D &p_transform) override {}165virtual void decal_instance_set_sorting_offset(RID p_decal_instance, float p_sorting_offset) override {}166167/* RENDER TARGET */168169virtual RID render_target_create() override { return RID(); }170virtual void render_target_free(RID p_rid) override {}171virtual void render_target_set_position(RID p_render_target, int p_x, int p_y) override {}172virtual Point2i render_target_get_position(RID p_render_target) const override { return Point2i(); }173virtual void render_target_set_size(RID p_render_target, int p_width, int p_height, uint32_t p_view_count) override {}174virtual Size2i render_target_get_size(RID p_render_target) const override { return Size2i(); }175virtual void render_target_set_transparent(RID p_render_target, bool p_is_transparent) override {}176virtual bool render_target_get_transparent(RID p_render_target) const override { return false; }177virtual void render_target_set_direct_to_screen(RID p_render_target, bool p_direct_to_screen) override {}178virtual bool render_target_get_direct_to_screen(RID p_render_target) const override { return false; }179virtual bool render_target_was_used(RID p_render_target) const override { return false; }180virtual void render_target_set_as_unused(RID p_render_target) override {}181virtual void render_target_set_msaa(RID p_render_target, RS::ViewportMSAA p_msaa) override {}182virtual RS::ViewportMSAA render_target_get_msaa(RID p_render_target) const override { return RS::VIEWPORT_MSAA_DISABLED; }183virtual void render_target_set_msaa_needs_resolve(RID p_render_target, bool p_needs_resolve) override {}184virtual bool render_target_get_msaa_needs_resolve(RID p_render_target) const override { return false; }185virtual void render_target_do_msaa_resolve(RID p_render_target) override {}186virtual void render_target_set_use_hdr(RID p_render_target, bool p_use_hdr_2d) override {}187virtual bool render_target_is_using_hdr(RID p_render_target) const override { return false; }188virtual void render_target_set_use_debanding(RID p_render_target, bool p_use_debanding) override {}189virtual bool render_target_is_using_debanding(RID p_render_target) const override { return false; }190191virtual void render_target_request_clear(RID p_render_target, const Color &p_clear_color) override {}192virtual bool render_target_is_clear_requested(RID p_render_target) override { return false; }193virtual Color render_target_get_clear_request_color(RID p_render_target) override { return Color(); }194virtual void render_target_disable_clear_request(RID p_render_target) override {}195virtual void render_target_do_clear_request(RID p_render_target) override {}196197virtual void render_target_set_sdf_size_and_scale(RID p_render_target, RS::ViewportSDFOversize p_size, RS::ViewportSDFScale p_scale) override {}198virtual Rect2i render_target_get_sdf_rect(RID p_render_target) const override { return Rect2i(); }199virtual void render_target_mark_sdf_enabled(RID p_render_target, bool p_enabled) override {}200201virtual void render_target_set_vrs_mode(RID p_render_target, RS::ViewportVRSMode p_mode) override {}202virtual RS::ViewportVRSMode render_target_get_vrs_mode(RID p_render_target) const override { return RS::VIEWPORT_VRS_DISABLED; }203virtual void render_target_set_vrs_update_mode(RID p_render_target, RS::ViewportVRSUpdateMode p_mode) override {}204virtual RS::ViewportVRSUpdateMode render_target_get_vrs_update_mode(RID p_render_target) const override { return RS::VIEWPORT_VRS_UPDATE_DISABLED; }205virtual void render_target_set_vrs_texture(RID p_render_target, RID p_texture) override {}206virtual RID render_target_get_vrs_texture(RID p_render_target) const override { return RID(); }207208virtual void render_target_set_override(RID p_render_target, RID p_color_texture, RID p_depth_texture, RID p_velocity_texture, RID p_velocity_depth_texture) override {}209virtual RID render_target_get_override_color(RID p_render_target) const override { return RID(); }210virtual RID render_target_get_override_depth(RID p_render_target) const override { return RID(); }211virtual RID render_target_get_override_velocity(RID p_render_target) const override { return RID(); }212virtual RID render_target_get_override_velocity_depth(RID p_render_target) const override { return RID(); }213214virtual void render_target_set_render_region(RID p_render_target, const Rect2i &p_render_region) override {}215virtual Rect2i render_target_get_render_region(RID p_render_target) const override { return Rect2i(); }216217virtual RID render_target_get_texture(RID p_render_target) override { return RID(); }218219virtual void render_target_set_velocity_target_size(RID p_render_target, const Size2i &p_target_size) override {}220virtual Size2i render_target_get_velocity_target_size(RID p_render_target) const override { return Size2i(0, 0); }221};222223} // namespace RendererDummy224225226