Path: blob/master/drivers/gles3/storage/texture_storage.h
21643 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#ifdef GLES3_ENABLED3334#include "platform_gl.h"3536#include "config.h"37#include "core/io/image.h"38#include "core/os/os.h"39#include "core/templates/rid_owner.h"40#include "servers/rendering/renderer_compositor.h"41#include "servers/rendering/storage/texture_storage.h"4243#include "drivers/gles3/shaders/canvas_sdf.glsl.gen.h"4445namespace GLES3 {4647#define _GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE48#define _GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF4950#define _EXT_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F051#define _EXT_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F152#define _EXT_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F253#define _EXT_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F35455#define _EXT_COMPRESSED_RED_RGTC1_EXT 0x8DBB56#define _EXT_COMPRESSED_RED_RGTC1 0x8DBB57#define _EXT_COMPRESSED_SIGNED_RED_RGTC1 0x8DBC58#define _EXT_COMPRESSED_RG_RGTC2 0x8DBD59#define _EXT_COMPRESSED_SIGNED_RG_RGTC2 0x8DBE60#define _EXT_COMPRESSED_SIGNED_RED_RGTC1_EXT 0x8DBC61#define _EXT_COMPRESSED_RED_GREEN_RGTC2_EXT 0x8DBD62#define _EXT_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT 0x8DBE63#define _EXT_ETC1_RGB8_OES 0x8D646465#define _EXT_COMPRESSED_RGBA_BPTC_UNORM 0x8E8C66#define _EXT_COMPRESSED_SRGB_ALPHA_BPTC_UNORM 0x8E8D67#define _EXT_COMPRESSED_RGB_BPTC_SIGNED_FLOAT 0x8E8E68#define _EXT_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT 0x8E8F6970#define _EXT_COMPRESSED_R11_EAC 0x927071#define _EXT_COMPRESSED_SIGNED_R11_EAC 0x927172#define _EXT_COMPRESSED_RG11_EAC 0x927273#define _EXT_COMPRESSED_SIGNED_RG11_EAC 0x927374#define _EXT_COMPRESSED_RGB8_ETC2 0x927475#define _EXT_COMPRESSED_SRGB8_ETC2 0x927576#define _EXT_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x927677#define _EXT_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x927778#define _EXT_COMPRESSED_RGBA8_ETC2_EAC 0x927879#define _EXT_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC 0x92798081#define _EXT_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B082#define _EXT_COMPRESSED_RGBA_ASTC_5x4_KHR 0x93B183#define _EXT_COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B284#define _EXT_COMPRESSED_RGBA_ASTC_6x5_KHR 0x93B385#define _EXT_COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B486#define _EXT_COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B587#define _EXT_COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B688#define _EXT_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B789#define _EXT_COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B890#define _EXT_COMPRESSED_RGBA_ASTC_10x6_KHR 0x93B991#define _EXT_COMPRESSED_RGBA_ASTC_10x8_KHR 0x93BA92#define _EXT_COMPRESSED_RGBA_ASTC_10x10_KHR 0x93BB93#define _EXT_COMPRESSED_RGBA_ASTC_12x10_KHR 0x93BC94#define _EXT_COMPRESSED_RGBA_ASTC_12x12_KHR 0x93BD9596#define _EXT_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR 0x93D097#define _EXT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR 0x93D198#define _EXT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR 0x93D299#define _EXT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR 0x93D3100#define _EXT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR 0x93D4101#define _EXT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR 0x93D5102#define _EXT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR 0x93D6103#define _EXT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR 0x93D7104#define _EXT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR 0x93D8105#define _EXT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR 0x93D9106#define _EXT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR 0x93DA107#define _EXT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR 0x93DB108#define _EXT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR 0x93DC109#define _EXT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR 0x93DD110111#define _GL_TEXTURE_EXTERNAL_OES 0x8D65112113#define _EXT_TEXTURE_CUBE_MAP_SEAMLESS 0x884F114115#define _EXT_R16 0x822A116#define _EXT_RG16 0x822C117#define _EXT_RGB16 0x8054118#define _EXT_RGBA16 0x805B119120enum DefaultGLTexture {121DEFAULT_GL_TEXTURE_WHITE,122DEFAULT_GL_TEXTURE_BLACK,123DEFAULT_GL_TEXTURE_TRANSPARENT,124DEFAULT_GL_TEXTURE_NORMAL,125DEFAULT_GL_TEXTURE_ANISO,126DEFAULT_GL_TEXTURE_DEPTH,127DEFAULT_GL_TEXTURE_CUBEMAP_BLACK,128//DEFAULT_GL_TEXTURE_CUBEMAP_ARRAY_BLACK, // Cubemap Arrays not supported in GL 3.3 or GL ES 3.0129DEFAULT_GL_TEXTURE_CUBEMAP_WHITE,130DEFAULT_GL_TEXTURE_CUBEMAP_TRANSPARENT,131DEFAULT_GL_TEXTURE_3D_WHITE,132DEFAULT_GL_TEXTURE_3D_BLACK,133DEFAULT_GL_TEXTURE_3D_TRANSPARENT,134DEFAULT_GL_TEXTURE_2D_ARRAY_WHITE,135DEFAULT_GL_TEXTURE_2D_ARRAY_BLACK,136DEFAULT_GL_TEXTURE_2D_ARRAY_TRANSPARENT,137DEFAULT_GL_TEXTURE_2D_UINT,138DEFAULT_GL_TEXTURE_EXT,139DEFAULT_GL_TEXTURE_MAX140};141142struct CanvasTexture {143RID diffuse;144RID normal_map;145RID specular;146Color specular_color = Color(1, 1, 1, 1);147float shininess = 1.0;148149RS::CanvasItemTextureFilter texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT;150RS::CanvasItemTextureRepeat texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT;151};152153struct RenderTarget;154155struct Texture {156RID self;157158bool is_proxy = false;159bool is_from_native_handle = false;160bool is_render_target = false;161162RID proxy_to;163LocalVector<RID> proxies;164165String path;166int width = 0;167int height = 0;168int depth = 0;169int mipmaps = 1;170int layers = 1;171int alloc_width = 0;172int alloc_height = 0;173Image::Format format = Image::FORMAT_R8;174Image::Format real_format = Image::FORMAT_R8;175176enum Type {177TYPE_2D,178TYPE_LAYERED,179TYPE_3D180};181182Type type = TYPE_2D;183RS::TextureLayeredType layered_type = RS::TEXTURE_LAYERED_2D_ARRAY;184RS::TextureDrawableFormat drawable_type = RS::TEXTURE_DRAWABLE_FORMAT_RGBA8;185186GLenum target = GL_TEXTURE_2D;187GLenum gl_format_cache = 0;188GLenum gl_internal_format_cache = 0;189GLenum gl_type_cache = 0;190191int total_data_size = 0;192193bool compressed = false;194195bool resize_to_po2 = false;196197bool active = false;198GLuint tex_id = 0;199200uint16_t stored_cube_sides = 0;201202RenderTarget *render_target = nullptr;203204Ref<Image> image_cache_2d;205Vector<Ref<Image>> image_cache_3d;206207bool redraw_if_visible = false;208209RS::TextureDetectCallback detect_3d_callback = nullptr;210void *detect_3d_callback_ud = nullptr;211212RS::TextureDetectCallback detect_normal_callback = nullptr;213void *detect_normal_callback_ud = nullptr;214215RS::TextureDetectRoughnessCallback detect_roughness_callback = nullptr;216void *detect_roughness_callback_ud = nullptr;217218CanvasTexture *canvas_texture = nullptr;219220void copy_from(const Texture &o) {221proxy_to = o.proxy_to;222is_proxy = o.is_proxy;223is_from_native_handle = o.is_from_native_handle;224width = o.width;225height = o.height;226alloc_width = o.alloc_width;227alloc_height = o.alloc_height;228format = o.format;229type = o.type;230layered_type = o.layered_type;231target = o.target;232total_data_size = o.total_data_size;233compressed = o.compressed;234mipmaps = o.mipmaps;235resize_to_po2 = o.resize_to_po2;236active = o.active;237tex_id = o.tex_id;238stored_cube_sides = o.stored_cube_sides;239render_target = o.render_target;240is_render_target = o.is_render_target;241redraw_if_visible = o.redraw_if_visible;242detect_3d_callback = o.detect_3d_callback;243detect_3d_callback_ud = o.detect_3d_callback_ud;244detect_normal_callback = o.detect_normal_callback;245detect_normal_callback_ud = o.detect_normal_callback_ud;246detect_roughness_callback = o.detect_roughness_callback;247detect_roughness_callback_ud = o.detect_roughness_callback_ud;248}249250// texture state251void gl_set_filter(RS::CanvasItemTextureFilter p_filter) {252if (p_filter == state_filter) {253return;254}255Config *config = Config::get_singleton();256state_filter = p_filter;257GLenum pmin = GL_NEAREST;258GLenum pmag = GL_NEAREST;259GLint max_lod = 0;260GLfloat anisotropy = 1.0f;261switch (state_filter) {262case RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST: {263pmin = GL_NEAREST;264pmag = GL_NEAREST;265max_lod = 0;266} break;267case RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR: {268pmin = GL_LINEAR;269pmag = GL_LINEAR;270max_lod = 0;271} break;272case RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC: {273anisotropy = config->anisotropic_level;274};275[[fallthrough]];276case RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS: {277pmag = GL_NEAREST;278if (mipmaps <= 1) {279pmin = GL_NEAREST;280max_lod = 0;281} else if (config->use_nearest_mip_filter) {282pmin = GL_NEAREST_MIPMAP_NEAREST;283max_lod = mipmaps - 1;284} else {285pmin = GL_NEAREST_MIPMAP_LINEAR;286max_lod = mipmaps - 1;287}288} break;289case RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC: {290anisotropy = config->anisotropic_level;291};292[[fallthrough]];293case RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS: {294pmag = GL_LINEAR;295if (mipmaps <= 1) {296pmin = GL_LINEAR;297max_lod = 0;298} else if (config->use_nearest_mip_filter) {299pmin = GL_LINEAR_MIPMAP_NEAREST;300max_lod = mipmaps - 1;301} else {302pmin = GL_LINEAR_MIPMAP_LINEAR;303max_lod = mipmaps - 1;304}305} break;306default: {307return;308} break;309}310glTexParameteri(target, GL_TEXTURE_MIN_FILTER, pmin);311glTexParameteri(target, GL_TEXTURE_MAG_FILTER, pmag);312glTexParameteri(target, GL_TEXTURE_BASE_LEVEL, 0);313glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, max_lod);314if (config->support_anisotropic_filter) {315glTexParameterf(target, _GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy);316}317}318void gl_set_repeat(RS::CanvasItemTextureRepeat p_repeat) {319if (p_repeat == state_repeat) {320return;321}322state_repeat = p_repeat;323GLenum prep = GL_CLAMP_TO_EDGE;324switch (state_repeat) {325case RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED: {326prep = GL_CLAMP_TO_EDGE;327} break;328case RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED: {329prep = GL_REPEAT;330} break;331case RS::CANVAS_ITEM_TEXTURE_REPEAT_MIRROR: {332prep = GL_MIRRORED_REPEAT;333} break;334default: {335return;336} break;337}338glTexParameteri(target, GL_TEXTURE_WRAP_T, prep);339glTexParameteri(target, GL_TEXTURE_WRAP_R, prep);340glTexParameteri(target, GL_TEXTURE_WRAP_S, prep);341}342343private:344RS::CanvasItemTextureFilter state_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_MAX;345RS::CanvasItemTextureRepeat state_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_MAX;346};347348struct RenderTarget {349Point2i position = Point2i(0, 0);350Size2i size = Size2i(0, 0);351uint32_t view_count = 1;352int mipmap_count = 1;353RID self;354GLuint fbo = 0;355GLuint color = 0;356GLuint depth = 0;357GLuint backbuffer_fbo = 0;358GLuint backbuffer = 0;359GLuint backbuffer_depth = 0;360bool depth_has_stencil = true;361362Size2i velocity_target_size;363364bool hdr = false; // For Compatibility this effects both 2D and 3D rendering!365GLuint color_internal_format = GL_RGBA8;366GLuint color_format = GL_RGBA;367GLuint color_type = GL_UNSIGNED_BYTE;368uint32_t color_format_size = 4;369Image::Format image_format = Image::FORMAT_RGBA8;370371GLuint sdf_texture_write = 0;372GLuint sdf_texture_write_fb = 0;373GLuint sdf_texture_process[2] = { 0, 0 };374GLuint sdf_texture_read = 0;375RS::ViewportSDFOversize sdf_oversize = RS::VIEWPORT_SDF_OVERSIZE_120_PERCENT;376RS::ViewportSDFScale sdf_scale = RS::VIEWPORT_SDF_SCALE_50_PERCENT;377Size2i process_size;378bool sdf_enabled = false;379380bool is_transparent = false;381bool direct_to_screen = false;382383bool used_in_frame = false;384RS::ViewportMSAA msaa = RS::VIEWPORT_MSAA_DISABLED;385bool reattach_textures = false;386387Rect2i render_region;388389struct RTOverridden {390bool is_overridden = false;391bool depth_has_stencil = false;392RID color;393RID depth;394RID velocity;395RID velocity_depth;396397struct FBOCacheEntry {398GLuint fbo;399GLuint color;400GLuint depth;401Size2i size;402Vector<GLuint> allocated_textures;403bool depth_has_stencil;404};405RBMap<uint32_t, FBOCacheEntry> fbo_cache;406407GLuint velocity_fbo = 0;408RBMap<uint32_t, GLuint> velocity_fbo_cache;409} overridden;410411RID texture;412413Color clear_color = Color(1, 1, 1, 1);414bool clear_requested = false;415416RenderTarget() {417}418};419420class TextureStorage : public RendererTextureStorage {421private:422static TextureStorage *singleton;423424RID default_gl_textures[DEFAULT_GL_TEXTURE_MAX];425426/* Canvas Texture API */427428RID_Owner<CanvasTexture, true> canvas_texture_owner;429430/* Texture API */431// Textures can be created from threads, so this RID_Owner is thread safe.432mutable RID_Owner<Texture, true> texture_owner;433434Ref<Image> _get_gl_image_and_format(const Ref<Image> &p_image, Image::Format p_format, Image::Format &r_real_format, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_gl_type, bool &r_compressed, bool p_force_decompress) const;435436/* TEXTURE ATLAS API */437438struct TextureAtlas {439struct Texture {440int users;441Rect2 uv_rect;442};443444struct SortItem {445RID texture;446Size2i pixel_size;447Size2i size;448Point2i pos;449450bool operator<(const SortItem &p_item) const {451//sort larger to smaller452if (size.height == p_item.size.height) {453return size.width > p_item.size.width;454} else {455return size.height > p_item.size.height;456}457}458};459460HashMap<RID, Texture> textures;461bool dirty = true;462463GLuint texture = 0;464GLuint framebuffer = 0;465Size2i size;466} texture_atlas;467468/* Render Target API */469470mutable RID_Owner<RenderTarget> render_target_owner;471472void _clear_render_target(RenderTarget *rt);473void _update_render_target_color(RenderTarget *rt);474void _update_render_target_velocity(RenderTarget *rt);475void _create_render_target_backbuffer(RenderTarget *rt);476void _render_target_allocate_sdf(RenderTarget *rt);477void _render_target_clear_sdf(RenderTarget *rt);478Rect2i _render_target_get_sdf_rect(const RenderTarget *rt) const;479480void _texture_set_data(RID p_texture, const Ref<Image> &p_image, int p_layer, bool p_initialize);481void _texture_set_3d_data(RID p_texture, const Vector<Ref<Image>> &p_data, bool p_initialize);482void _texture_set_swizzle(Texture *p_texture, Image::Format p_real_format);483Vector<Ref<Image>> _texture_3d_read_framebuffer(Texture *p_texture) const;484485struct RenderTargetSDF {486CanvasSdfShaderGLES3 shader;487RID shader_version;488} sdf_shader;489490/* Texture Blit Shader API */491492struct TexBlitShader {493bool initialized = false;494RID default_shader;495RID default_material;496RID default_shader_version;497} tex_blit_shader;498499GLuint tex_blit_fbo;500GLuint tex_blit_quad;501GLuint tex_blit_quad_array;502503public:504static TextureStorage *get_singleton();505506void _tex_blit_shader_initialize();507void _tex_blit_shader_free();508509TextureStorage();510virtual ~TextureStorage();511512_FORCE_INLINE_ RID texture_gl_get_default(DefaultGLTexture p_texture) {513return default_gl_textures[p_texture];514}515516/* Canvas Texture API */517518CanvasTexture *get_canvas_texture(RID p_rid) { return canvas_texture_owner.get_or_null(p_rid); }519bool owns_canvas_texture(RID p_rid) { return canvas_texture_owner.owns(p_rid); }520521virtual RID canvas_texture_allocate() override;522virtual void canvas_texture_initialize(RID p_rid) override;523virtual void canvas_texture_free(RID p_rid) override;524525virtual void canvas_texture_set_channel(RID p_canvas_texture, RS::CanvasTextureChannel p_channel, RID p_texture) override;526virtual void canvas_texture_set_shading_parameters(RID p_canvas_texture, const Color &p_base_color, float p_shininess) override;527528virtual void canvas_texture_set_texture_filter(RID p_item, RS::CanvasItemTextureFilter p_filter) override;529virtual void canvas_texture_set_texture_repeat(RID p_item, RS::CanvasItemTextureRepeat p_repeat) override;530531/* Texture API */532533Texture *get_texture(RID p_rid) const {534Texture *texture = texture_owner.get_or_null(p_rid);535if (texture && texture->is_proxy) {536return texture_owner.get_or_null(texture->proxy_to);537}538return texture;539}540bool owns_texture(RID p_rid) { return texture_owner.owns(p_rid); }541542void texture_2d_initialize_from_texture(RID p_texture, Texture &p_tex) {543texture_owner.initialize_rid(p_texture, p_tex);544}545546virtual RID texture_allocate() override;547virtual void texture_free(RID p_rid) override;548549virtual void texture_2d_initialize(RID p_texture, const Ref<Image> &p_image) override;550virtual void texture_2d_layered_initialize(RID p_texture, const Vector<Ref<Image>> &p_layers, RS::TextureLayeredType p_layered_type) override;551virtual 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;552virtual void texture_external_initialize(RID p_texture, int p_width, int p_height, uint64_t p_external_buffer) override;553virtual void texture_proxy_initialize(RID p_texture, RID p_base) override; //all slices, then all the mipmaps, must be coherent554virtual 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;555556virtual 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;557558virtual void texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) override;559virtual void texture_3d_update(RID p_texture, const Vector<Ref<Image>> &p_data) override;560virtual void texture_external_update(RID p_texture, int p_width, int p_height, uint64_t p_external_buffer) override;561virtual void texture_proxy_update(RID p_proxy, RID p_base) override;562void texture_remap_proxies(RID p_from_texture, RID p_to_texture);563564virtual 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;565566Ref<Image> texture_2d_placeholder;567Vector<Ref<Image>> texture_2d_array_placeholder;568Vector<Ref<Image>> cubemap_placeholder;569Vector<Ref<Image>> texture_3d_placeholder;570571//these two APIs can be used together or in combination with the others.572virtual void texture_2d_placeholder_initialize(RID p_texture) override;573virtual void texture_2d_layered_placeholder_initialize(RID p_texture, RenderingServer::TextureLayeredType p_layered_type) override;574virtual void texture_3d_placeholder_initialize(RID p_texture) override;575576virtual Ref<Image> texture_2d_get(RID p_texture) const override;577virtual Ref<Image> texture_2d_layer_get(RID p_texture, int p_layer) const override;578virtual Vector<Ref<Image>> texture_3d_get(RID p_texture) const override;579580virtual void texture_drawable_generate_mipmaps(RID p_texture) override;581virtual RID texture_drawable_get_default_material() const override;582583virtual void texture_replace(RID p_texture, RID p_by_texture) override;584virtual void texture_set_size_override(RID p_texture, int p_width, int p_height) override;585586virtual void texture_set_path(RID p_texture, const String &p_path) override;587virtual String texture_get_path(RID p_texture) const override;588589virtual void texture_set_detect_3d_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) override;590void texture_set_detect_srgb_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata);591virtual void texture_set_detect_normal_callback(RID p_texture, RS::TextureDetectCallback p_callback, void *p_userdata) override;592virtual void texture_set_detect_roughness_callback(RID p_texture, RS::TextureDetectRoughnessCallback p_callback, void *p_userdata) override;593594virtual void texture_debug_usage(List<RS::TextureInfo> *r_info) override;595596virtual void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) override;597598virtual Size2 texture_size_with_proxy(RID p_proxy) override;599600virtual void texture_rd_initialize(RID p_texture, const RID &p_rd_texture, const RS::TextureLayeredType p_layer_type = RS::TEXTURE_LAYERED_2D_ARRAY) override;601virtual RID texture_get_rd_texture(RID p_texture, bool p_srgb = false) const override;602virtual uint64_t texture_get_native_handle(RID p_texture, bool p_srgb = false) const override;603604void texture_set_data(RID p_texture, const Ref<Image> &p_image, int p_layer = 0);605virtual Image::Format texture_get_format(RID p_texture) const override;606uint32_t texture_get_texid(RID p_texture) const;607Vector3i texture_get_size(RID p_texture) const;608uint32_t texture_get_width(RID p_texture) const;609uint32_t texture_get_height(RID p_texture) const;610uint32_t texture_get_depth(RID p_texture) const;611void texture_bind(RID p_texture, uint32_t p_texture_no);612613/* TEXTURE ATLAS API */614615void update_texture_atlas();616617GLuint texture_atlas_get_texture() const;618_FORCE_INLINE_ Rect2 texture_atlas_get_texture_rect(RID p_texture) {619TextureAtlas::Texture *t = texture_atlas.textures.getptr(p_texture);620if (!t) {621return Rect2();622}623624return t->uv_rect;625}626627void texture_add_to_texture_atlas(RID p_texture);628void texture_remove_from_texture_atlas(RID p_texture);629void texture_atlas_mark_dirty_on_texture(RID p_texture);630void texture_atlas_remove_texture(RID p_texture);631632/* DECAL API */633634virtual RID decal_allocate() override;635virtual void decal_initialize(RID p_rid) override;636virtual void decal_free(RID p_rid) override {}637638virtual void decal_set_size(RID p_decal, const Vector3 &p_size) override;639virtual void decal_set_texture(RID p_decal, RS::DecalTexture p_type, RID p_texture) override;640virtual void decal_set_emission_energy(RID p_decal, float p_energy) override;641virtual void decal_set_albedo_mix(RID p_decal, float p_mix) override;642virtual void decal_set_modulate(RID p_decal, const Color &p_modulate) override;643virtual void decal_set_cull_mask(RID p_decal, uint32_t p_layers) override;644virtual void decal_set_distance_fade(RID p_decal, bool p_enabled, float p_begin, float p_length) override;645virtual void decal_set_fade(RID p_decal, float p_above, float p_below) override;646virtual void decal_set_normal_fade(RID p_decal, float p_fade) override;647648virtual AABB decal_get_aabb(RID p_decal) const override;649virtual uint32_t decal_get_cull_mask(RID p_decal) const override { return 0; }650651virtual void texture_add_to_decal_atlas(RID p_texture, bool p_panorama_to_dp = false) override {}652virtual void texture_remove_from_decal_atlas(RID p_texture, bool p_panorama_to_dp = false) override {}653654/* DECAL INSTANCE */655656virtual RID decal_instance_create(RID p_decal) override { return RID(); }657virtual void decal_instance_free(RID p_decal_instance) override {}658virtual void decal_instance_set_transform(RID p_decal, const Transform3D &p_transform) override {}659virtual void decal_instance_set_sorting_offset(RID p_decal_instance, float p_sorting_offset) override {}660661/* RENDER TARGET API */662663static GLuint system_fbo;664665RenderTarget *get_render_target(RID p_rid) { return render_target_owner.get_or_null(p_rid); }666bool owns_render_target(RID p_rid) { return render_target_owner.owns(p_rid); }667668virtual RID render_target_create() override;669virtual void render_target_free(RID p_rid) override;670671virtual void render_target_set_position(RID p_render_target, int p_x, int p_y) override;672virtual Point2i render_target_get_position(RID p_render_target) const override;673virtual void render_target_set_size(RID p_render_target, int p_width, int p_height, uint32_t p_view_count) override;674virtual Size2i render_target_get_size(RID p_render_target) const override;675virtual void render_target_set_transparent(RID p_render_target, bool p_is_transparent) override;676virtual bool render_target_get_transparent(RID p_render_target) const override;677virtual void render_target_set_direct_to_screen(RID p_render_target, bool p_direct_to_screen) override;678virtual bool render_target_get_direct_to_screen(RID p_render_target) const override;679virtual bool render_target_was_used(RID p_render_target) const override;680void render_target_clear_used(RID p_render_target);681virtual void render_target_set_msaa(RID p_render_target, RS::ViewportMSAA p_msaa) override;682virtual RS::ViewportMSAA render_target_get_msaa(RID p_render_target) const override;683virtual void render_target_set_msaa_needs_resolve(RID p_render_target, bool p_needs_resolve) override {}684virtual bool render_target_get_msaa_needs_resolve(RID p_render_target) const override { return false; }685virtual void render_target_do_msaa_resolve(RID p_render_target) override {}686virtual void render_target_set_use_hdr(RID p_render_target, bool p_use_hdr_2d) override;687virtual bool render_target_is_using_hdr(RID p_render_target) const override;688virtual void render_target_set_use_debanding(RID p_render_target, bool p_use_debanding) override {}689virtual bool render_target_is_using_debanding(RID p_render_target) const override { return false; }690691// new692void render_target_set_as_unused(RID p_render_target) override {693render_target_clear_used(p_render_target);694}695696GLuint render_target_get_color_internal_format(RID p_render_target) const;697GLuint render_target_get_color_format(RID p_render_target) const;698GLuint render_target_get_color_type(RID p_render_target) const;699uint32_t render_target_get_color_format_size(RID p_render_target) const;700701void render_target_request_clear(RID p_render_target, const Color &p_clear_color) override;702bool render_target_is_clear_requested(RID p_render_target) override;703Color render_target_get_clear_request_color(RID p_render_target) override;704void render_target_disable_clear_request(RID p_render_target) override;705void render_target_do_clear_request(RID p_render_target) override;706707GLuint render_target_get_fbo(RID p_render_target) const;708GLuint render_target_get_color(RID p_render_target) const;709GLuint render_target_get_depth(RID p_render_target) const;710bool render_target_get_depth_has_stencil(RID p_render_target) const;711void render_target_set_reattach_textures(RID p_render_target, bool p_reattach_textures) const;712bool render_target_is_reattach_textures(RID p_render_target) const;713714virtual void render_target_set_sdf_size_and_scale(RID p_render_target, RS::ViewportSDFOversize p_size, RS::ViewportSDFScale p_scale) override;715virtual Rect2i render_target_get_sdf_rect(RID p_render_target) const override;716GLuint render_target_get_sdf_texture(RID p_render_target);717GLuint render_target_get_sdf_framebuffer(RID p_render_target);718void render_target_sdf_process(RID p_render_target);719virtual void render_target_mark_sdf_enabled(RID p_render_target, bool p_enabled) override;720bool render_target_is_sdf_enabled(RID p_render_target) const;721722void render_target_copy_to_back_buffer(RID p_render_target, const Rect2i &p_region, bool p_gen_mipmaps);723void render_target_clear_back_buffer(RID p_render_target, const Rect2i &p_region, const Color &p_color);724void render_target_gen_back_buffer_mipmaps(RID p_render_target, const Rect2i &p_region);725726virtual void render_target_set_vrs_mode(RID p_render_target, RS::ViewportVRSMode p_mode) override {}727virtual RS::ViewportVRSMode render_target_get_vrs_mode(RID p_render_target) const override { return RS::VIEWPORT_VRS_DISABLED; }728virtual void render_target_set_vrs_update_mode(RID p_render_target, RS::ViewportVRSUpdateMode p_mode) override {}729virtual RS::ViewportVRSUpdateMode render_target_get_vrs_update_mode(RID p_render_target) const override { return RS::VIEWPORT_VRS_UPDATE_DISABLED; }730virtual void render_target_set_vrs_texture(RID p_render_target, RID p_texture) override {}731virtual RID render_target_get_vrs_texture(RID p_render_target) const override { return RID(); }732733virtual 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;734virtual RID render_target_get_override_color(RID p_render_target) const override;735virtual RID render_target_get_override_depth(RID p_render_target) const override;736virtual RID render_target_get_override_velocity(RID p_render_target) const override;737virtual RID render_target_get_override_velocity_depth(RID p_render_target) const override;738739virtual void render_target_set_render_region(RID p_render_target, const Rect2i &p_render_region) override;740virtual Rect2i render_target_get_render_region(RID p_render_target) const override;741742virtual RID render_target_get_texture(RID p_render_target) override;743744virtual void render_target_set_velocity_target_size(RID p_render_target, const Size2i &p_target_size) override;745virtual Size2i render_target_get_velocity_target_size(RID p_render_target) const override;746747void bind_framebuffer(GLuint framebuffer) {748glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);749}750751void bind_framebuffer_system() {752glBindFramebuffer(GL_FRAMEBUFFER, GLES3::TextureStorage::system_fbo);753}754755String get_framebuffer_error(GLenum p_status);756};757758inline String TextureStorage::get_framebuffer_error(GLenum p_status) {759#if defined(DEBUG_ENABLED) && defined(GL_API_ENABLED)760if (p_status == GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT) {761return "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT";762} else if (p_status == GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT) {763return "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";764} else if (p_status == GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER) {765return "GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER";766} else if (p_status == GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER) {767return "GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER";768}769#endif770return itos(p_status);771}772773} // namespace GLES3774775#endif // GLES3_ENABLED776777778