Expose texture_get_rd_texture

This commit is contained in:
Patrick Dawson 2022-11-01 18:50:36 +01:00
parent 754552b34d
commit 71d8de2763
10 changed files with 31 additions and 0 deletions

View File

@ -3024,6 +3024,14 @@
<description> <description>
</description> </description>
</method> </method>
<method name="texture_get_rd_texture" qualifiers="const">
<return type="RID" />
<param index="0" name="texture" type="RID" />
<param index="1" name="srgb" type="bool" default="false" />
<description>
Returns a texture [RID] that can be used with [RenderingDevice].
</description>
</method>
<method name="texture_proxy_create"> <method name="texture_proxy_create">
<return type="RID" /> <return type="RID" />
<param index="0" name="base" type="RID" /> <param index="0" name="base" type="RID" />

View File

@ -991,6 +991,10 @@ Size2 TextureStorage::texture_size_with_proxy(RID p_texture) {
} }
} }
RID TextureStorage::texture_get_rd_texture_rid(RID p_texture, bool p_srgb) const {
return RID();
}
void TextureStorage::texture_set_data(RID p_texture, const Ref<Image> &p_image, int p_layer) { void TextureStorage::texture_set_data(RID p_texture, const Ref<Image> &p_image, int p_layer) {
Texture *texture = texture_owner.get_or_null(p_texture); Texture *texture = texture_owner.get_or_null(p_texture);

View File

@ -484,6 +484,8 @@ public:
virtual Size2 texture_size_with_proxy(RID p_proxy) override; virtual Size2 texture_size_with_proxy(RID p_proxy) override;
virtual RID texture_get_rd_texture_rid(RID p_texture, bool p_srgb = false) const override;
void texture_set_data(RID p_texture, const Ref<Image> &p_image, int p_layer = 0); void texture_set_data(RID p_texture, const Ref<Image> &p_image, int p_layer = 0);
void texture_set_data_partial(RID p_texture, const Ref<Image> &p_image, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int p_dst_mip, int p_layer = 0); void texture_set_data_partial(RID p_texture, const Ref<Image> &p_image, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int p_dst_mip, int p_layer = 0);
//Ref<Image> texture_get_data(RID p_texture, int p_layer = 0) const; //Ref<Image> texture_get_data(RID p_texture, int p_layer = 0) const;

View File

@ -126,6 +126,8 @@ public:
virtual Size2 texture_size_with_proxy(RID p_proxy) override { return Size2(); }; virtual Size2 texture_size_with_proxy(RID p_proxy) override { return Size2(); };
virtual RID texture_get_rd_texture_rid(RID p_texture, bool p_srgb = false) const override { return RID(); };
/* DECAL API */ /* DECAL API */
virtual RID decal_allocate() override { return RID(); } virtual RID decal_allocate() override { return RID(); }
virtual void decal_initialize(RID p_rid) override {} virtual void decal_initialize(RID p_rid) override {}

View File

@ -1336,6 +1336,13 @@ Size2 TextureStorage::texture_size_with_proxy(RID p_proxy) {
return texture_2d_get_size(p_proxy); return texture_2d_get_size(p_proxy);
} }
RID TextureStorage::texture_get_rd_texture_rid(RID p_texture, bool p_srgb) const {
Texture *tex = texture_owner.get_or_null(p_texture);
ERR_FAIL_COND_V(!tex, RID());
return (p_srgb && tex->rd_texture_srgb.is_valid()) ? tex->rd_texture_srgb : tex->rd_texture;
}
Ref<Image> TextureStorage::_validate_texture_format(const Ref<Image> &p_image, TextureToRDFormat &r_format) { Ref<Image> TextureStorage::_validate_texture_format(const Ref<Image> &p_image, TextureToRDFormat &r_format) {
Ref<Image> image = p_image->duplicate(); Ref<Image> image = p_image->duplicate();

View File

@ -491,6 +491,8 @@ public:
virtual Size2 texture_size_with_proxy(RID p_proxy) override; virtual Size2 texture_size_with_proxy(RID p_proxy) override;
virtual RID texture_get_rd_texture_rid(RID p_texture, bool p_srgb = false) const override;
//internal usage //internal usage
_FORCE_INLINE_ TextureType texture_get_type(RID p_texture) { _FORCE_INLINE_ TextureType texture_get_type(RID p_texture) {
RendererRD::TextureStorage::Texture *tex = texture_owner.get_or_null(p_texture); RendererRD::TextureStorage::Texture *tex = texture_owner.get_or_null(p_texture);

View File

@ -212,6 +212,7 @@ public:
FUNC1(texture_debug_usage, List<TextureInfo> *) FUNC1(texture_debug_usage, List<TextureInfo> *)
FUNC2(texture_set_force_redraw_if_visible, RID, bool) FUNC2(texture_set_force_redraw_if_visible, RID, bool)
FUNC2RC(RID, texture_get_rd_texture_rid, RID, bool)
/* SHADER API */ /* SHADER API */

View File

@ -100,6 +100,8 @@ public:
virtual Size2 texture_size_with_proxy(RID p_proxy) = 0; virtual Size2 texture_size_with_proxy(RID p_proxy) = 0;
virtual RID texture_get_rd_texture_rid(RID p_texture, bool p_srgb = false) const = 0;
/* Decal API */ /* Decal API */
virtual RID decal_allocate() = 0; virtual RID decal_allocate() = 0;
virtual void decal_initialize(RID p_rid) = 0; virtual void decal_initialize(RID p_rid) = 0;

View File

@ -1691,6 +1691,7 @@ void RenderingServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("texture_get_path", "texture"), &RenderingServer::texture_get_path); ClassDB::bind_method(D_METHOD("texture_get_path", "texture"), &RenderingServer::texture_get_path);
ClassDB::bind_method(D_METHOD("texture_set_force_redraw_if_visible", "texture", "enable"), &RenderingServer::texture_set_force_redraw_if_visible); ClassDB::bind_method(D_METHOD("texture_set_force_redraw_if_visible", "texture", "enable"), &RenderingServer::texture_set_force_redraw_if_visible);
ClassDB::bind_method(D_METHOD("texture_get_rd_texture", "texture", "srgb"), &RenderingServer::texture_get_rd_texture_rid, DEFVAL(false));
BIND_ENUM_CONSTANT(TEXTURE_LAYERED_2D_ARRAY); BIND_ENUM_CONSTANT(TEXTURE_LAYERED_2D_ARRAY);
BIND_ENUM_CONSTANT(TEXTURE_LAYERED_CUBEMAP); BIND_ENUM_CONSTANT(TEXTURE_LAYERED_CUBEMAP);

View File

@ -157,6 +157,8 @@ public:
virtual void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) = 0; virtual void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) = 0;
virtual RID texture_get_rd_texture_rid(RID p_texture, bool p_srgb = false) const = 0;
/* SHADER API */ /* SHADER API */
enum ShaderMode { enum ShaderMode {