1/**************************************************************************/
2/* texture_storage.h */
3/**************************************************************************/
4/* This file is part of: */
5/* GODOT ENGINE */
6/* https://godotengine.org */
7/**************************************************************************/
8/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10/* */
11/* Permission is hereby granted, free of charge, to any person obtaining */
12/* a copy of this software and associated documentation files (the */
13/* "Software"), to deal in the Software without restriction, including */
14/* without limitation the rights to use, copy, modify, merge, publish, */
15/* distribute, sublicense, and/or sell copies of the Software, and to */
16/* permit persons to whom the Software is furnished to do so, subject to */
17/* the following conditions: */
18/* */
19/* The above copyright notice and this permission notice shall be */
20/* included in all copies or substantial portions of the Software. */
21/* */
22/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29/**************************************************************************/
30
31#ifndef TEXTURE_STORAGE_DUMMY_H
32#define TEXTURE_STORAGE_DUMMY_H
33
34#include "servers/rendering/rendering_server_globals.h"
35#include "servers/rendering/storage/texture_storage.h"
36
37namespace RendererDummy {
38
39class TextureStorage : public RendererTextureStorage {
40private:
41 static TextureStorage *singleton;
42
43 struct DummyTexture {
44 Ref<Image> image;
45 };
46 mutable RID_PtrOwner<DummyTexture> texture_owner;
47
48public:
49 static TextureStorage *get_singleton() {
50 return singleton;
51 };
52
53 TextureStorage();
54 ~TextureStorage();
55
56 virtual bool can_create_resources_async() const override { return false; }
57
58 /* Canvas Texture API */
59
60 virtual RID canvas_texture_allocate() override { return RID(); };
61 virtual void canvas_texture_initialize(RID p_rid) override{};
62 virtual void canvas_texture_free(RID p_rid) override{};
63
64 virtual void canvas_texture_set_channel(RID p_canvas_texture, RS::CanvasTextureChannel p_channel, RID p_texture) override{};
65 virtual void canvas_texture_set_shading_parameters(RID p_canvas_texture, const Color &p_base_color, float p_shininess) override{};
66
67 virtual void canvas_texture_set_texture_filter(RID p_item, RS::CanvasItemTextureFilter p_filter) override{};
68 virtual void canvas_texture_set_texture_repeat(RID p_item, RS::CanvasItemTextureRepeat p_repeat) override{};
69
70 /* Texture API */
71
72 bool owns_texture(RID p_rid) { return texture_owner.owns(p_rid); };
73
74 virtual RID texture_allocate() override {
75 DummyTexture *texture = memnew(DummyTexture);
76 ERR_FAIL_COND_V(!texture, RID());
77 return texture_owner.make_rid(texture);
78 };
79
80 virtual void texture_free(RID p_rid) override {
81 // delete the texture
82 DummyTexture *texture = texture_owner.get_or_null(p_rid);
83 ERR_FAIL_COND(!texture);
84 texture_owner.free(p_rid);
85 memdelete(texture);
86 };
87
88 virtual void texture_2d_initialize(RID p_texture, const Ref<Image> &p_image) override {
89 DummyTexture *t = texture_owner.get_or_null(p_texture);
90 ERR_FAIL_COND(!t);
91 t->image = p_image->duplicate();
92 };
93 virtual void texture_2d_layered_initialize(RID p_texture, const Vector<Ref<Image>> &p_layers, RS::TextureLayeredType p_layered_type) override{};
94 virtual 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{};
95 virtual void texture_proxy_initialize(RID p_texture, RID p_base) override{}; //all slices, then all the mipmaps, must be coherent
96
97 virtual void texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) override{};
98 virtual void texture_3d_update(RID p_texture, const Vector<Ref<Image>> &p_data) override{};
99 virtual void texture_proxy_update(RID p_proxy, RID p_base) override{};
100
101 //these two APIs can be used together or in combination with the others.
102 virtual void texture_2d_placeholder_initialize(RID p_texture) override{};
103 virtual void texture_2d_layered_placeholder_initialize(RID p_texture, RenderingServer::TextureLayeredType p_layered_type) override{};
104 virtual void texture_3d_placeholder_initialize(RID p_texture) override{};
105
106 virtual Ref<Image> texture_2d_get(RID p_texture) const override {
107 DummyTexture *t = texture_owner.get_or_null(p_texture);
108 ERR_FAIL_COND_V(!t, Ref<Image>());
109 return t->image;
110 };
111 virtual Ref<Image> texture_2d_layer_get(RID p_texture, int p_layer) const override { return Ref<Image>(); };
112 virtual Vector<Ref<Image>> texture_3d_get(RID p_texture) const override { return Vector<Ref<Image>>(); };
113
114 virtual void texture_replace(RID p_texture, RID p_by_texture) override { texture_free(p_by_texture); };
115 virtual void texture_set_size_override(RID p_texture, int p_width, int p_height) override{};
116
117 virtual void texture_set_path(RID p_texture, const String &p_path) override{};
118 virtual String texture_get_path(RID p_texture) const override { return String(); };
119
120 virtual Image::Format texture_get_format(RID p_texture) const override { return Image::FORMAT_MAX; }
121
122 virtual void texture_set_detect_3d_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) override{};
123 virtual void texture_set_detect_normal_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) override{};
124 virtual void texture_set_detect_roughness_callback(RID p_texture, RS::TextureDetectRoughnessCallback p_callback, void *p_userdata) override{};
125
126 virtual void texture_debug_usage(List<RS::TextureInfo> *r_info) override{};
127
128 virtual void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) override{};
129
130 virtual Size2 texture_size_with_proxy(RID p_proxy) override { return Size2(); };
131
132 virtual void texture_rd_initialize(RID p_texture, const RID &p_rd_texture, const RS::TextureLayeredType p_layer_type = RS::TEXTURE_LAYERED_2D_ARRAY) override{};
133 virtual RID texture_get_rd_texture(RID p_texture, bool p_srgb = false) const override { return RID(); };
134 virtual uint64_t texture_get_native_handle(RID p_texture, bool p_srgb = false) const override { return 0; };
135
136 /* DECAL API */
137 virtual RID decal_allocate() override { return RID(); }
138 virtual void decal_initialize(RID p_rid) override {}
139 virtual void decal_free(RID p_rid) override{};
140
141 virtual void decal_set_size(RID p_decal, const Vector3 &p_size) override {}
142 virtual void decal_set_texture(RID p_decal, RS::DecalTexture p_type, RID p_texture) override {}
143 virtual void decal_set_emission_energy(RID p_decal, float p_energy) override {}
144 virtual void decal_set_albedo_mix(RID p_decal, float p_mix) override {}
145 virtual void decal_set_modulate(RID p_decal, const Color &p_modulate) override {}
146 virtual void decal_set_cull_mask(RID p_decal, uint32_t p_layers) override {}
147 virtual void decal_set_distance_fade(RID p_decal, bool p_enabled, float p_begin, float p_length) override {}
148 virtual void decal_set_fade(RID p_decal, float p_above, float p_below) override {}
149 virtual void decal_set_normal_fade(RID p_decal, float p_fade) override {}
150
151 virtual AABB decal_get_aabb(RID p_decal) const override { return AABB(); }
152 virtual uint32_t decal_get_cull_mask(RID p_decal) const override { return 0; }
153
154 virtual void texture_add_to_decal_atlas(RID p_texture, bool p_panorama_to_dp = false) override {}
155 virtual void texture_remove_from_decal_atlas(RID p_texture, bool p_panorama_to_dp = false) override {}
156
157 /* DECAL INSTANCE */
158
159 virtual RID decal_instance_create(RID p_decal) override { return RID(); }
160 virtual void decal_instance_free(RID p_decal_instance) override {}
161 virtual void decal_instance_set_transform(RID p_decal, const Transform3D &p_transform) override {}
162 virtual void decal_instance_set_sorting_offset(RID p_decal_instance, float p_sorting_offset) override {}
163
164 /* RENDER TARGET */
165
166 virtual RID render_target_create() override { return RID(); }
167 virtual void render_target_free(RID p_rid) override {}
168 virtual void render_target_set_position(RID p_render_target, int p_x, int p_y) override {}
169 virtual Point2i render_target_get_position(RID p_render_target) const override { return Point2i(); }
170 virtual void render_target_set_size(RID p_render_target, int p_width, int p_height, uint32_t p_view_count) override {}
171 virtual Size2i render_target_get_size(RID p_render_target) const override { return Size2i(); }
172 virtual void render_target_set_transparent(RID p_render_target, bool p_is_transparent) override {}
173 virtual bool render_target_get_transparent(RID p_render_target) const override { return false; }
174 virtual void render_target_set_direct_to_screen(RID p_render_target, bool p_direct_to_screen) override {}
175 virtual bool render_target_get_direct_to_screen(RID p_render_target) const override { return false; }
176 virtual bool render_target_was_used(RID p_render_target) const override { return false; }
177 virtual void render_target_set_as_unused(RID p_render_target) override {}
178 virtual void render_target_set_msaa(RID p_render_target, RS::ViewportMSAA p_msaa) override {}
179 virtual RS::ViewportMSAA render_target_get_msaa(RID p_render_target) const override { return RS::VIEWPORT_MSAA_DISABLED; }
180 virtual void render_target_set_use_hdr(RID p_render_target, bool p_use_hdr_2d) override {}
181 virtual bool render_target_is_using_hdr(RID p_render_target) const override { return false; }
182
183 virtual void render_target_request_clear(RID p_render_target, const Color &p_clear_color) override {}
184 virtual bool render_target_is_clear_requested(RID p_render_target) override { return false; }
185 virtual Color render_target_get_clear_request_color(RID p_render_target) override { return Color(); }
186 virtual void render_target_disable_clear_request(RID p_render_target) override {}
187 virtual void render_target_do_clear_request(RID p_render_target) override {}
188
189 virtual void render_target_set_sdf_size_and_scale(RID p_render_target, RS::ViewportSDFOversize p_size, RS::ViewportSDFScale p_scale) override {}
190 virtual Rect2i render_target_get_sdf_rect(RID p_render_target) const override { return Rect2i(); }
191 virtual void render_target_mark_sdf_enabled(RID p_render_target, bool p_enabled) override {}
192
193 virtual void render_target_set_vrs_mode(RID p_render_target, RS::ViewportVRSMode p_mode) override {}
194 virtual RS::ViewportVRSMode render_target_get_vrs_mode(RID p_render_target) const override { return RS::VIEWPORT_VRS_DISABLED; }
195 virtual void render_target_set_vrs_texture(RID p_render_target, RID p_texture) override {}
196 virtual RID render_target_get_vrs_texture(RID p_render_target) const override { return RID(); }
197
198 virtual void render_target_set_override(RID p_render_target, RID p_color_texture, RID p_depth_texture, RID p_velocity_texture) override {}
199 virtual RID render_target_get_override_color(RID p_render_target) const override { return RID(); }
200 virtual RID render_target_get_override_depth(RID p_render_target) const override { return RID(); }
201 virtual RID render_target_get_override_velocity(RID p_render_target) const override { return RID(); }
202
203 virtual RID render_target_get_texture(RID p_render_target) override { return RID(); }
204};
205
206} // namespace RendererDummy
207
208#endif // TEXTURE_STORAGE_DUMMY_H
209