summaryrefslogtreecommitdiff
path: root/drivers/gles3/storage/texture_storage.h
diff options
context:
space:
mode:
authorclayjohn <claynjohn@gmail.com>2022-10-12 17:55:01 -0700
committerclayjohn <claynjohn@gmail.com>2022-10-12 17:55:01 -0700
commite600fb93a5e5cb6bdbc496393f9d96dd9a664292 (patch)
treeda2ec2d73610664662697fa1a354227e186bebf6 /drivers/gles3/storage/texture_storage.h
parent1baefceababe8a0d63434a231c3799555a45d8e3 (diff)
Add 2D lights to OpenGL3 canvas renderer
This is an initial implementation using the same single-pass approach as the RenderingDevice.
Diffstat (limited to 'drivers/gles3/storage/texture_storage.h')
-rw-r--r--drivers/gles3/storage/texture_storage.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/drivers/gles3/storage/texture_storage.h b/drivers/gles3/storage/texture_storage.h
index 7e083e48e8..39a74236e5 100644
--- a/drivers/gles3/storage/texture_storage.h
+++ b/drivers/gles3/storage/texture_storage.h
@@ -371,6 +371,38 @@ private:
Ref<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;
+ /* TEXTURE ATLAS API */
+
+ struct TextureAtlas {
+ struct Texture {
+ int users;
+ Rect2 uv_rect;
+ };
+
+ struct SortItem {
+ RID texture;
+ Size2i pixel_size;
+ Size2i size;
+ Point2i pos;
+
+ bool operator<(const SortItem &p_item) const {
+ //sort larger to smaller
+ if (size.height == p_item.size.height) {
+ return size.width > p_item.size.width;
+ } else {
+ return size.height > p_item.size.height;
+ }
+ }
+ };
+
+ HashMap<RID, Texture> textures;
+ bool dirty = true;
+
+ GLuint texture = 0;
+ GLuint framebuffer = 0;
+ Size2i size;
+ } texture_atlas;
+
/* Render Target API */
mutable RID_Owner<RenderTarget> render_target_owner;
@@ -473,6 +505,25 @@ public:
void texture_bind(RID p_texture, uint32_t p_texture_no);
RID texture_create_radiance_cubemap(RID p_source, int p_resolution = -1) const;
+ /* TEXTURE ATLAS API */
+
+ void update_texture_atlas();
+
+ GLuint texture_atlas_get_texture() const;
+ _FORCE_INLINE_ Rect2 texture_atlas_get_texture_rect(RID p_texture) {
+ TextureAtlas::Texture *t = texture_atlas.textures.getptr(p_texture);
+ if (!t) {
+ return Rect2();
+ }
+
+ return t->uv_rect;
+ }
+
+ void texture_add_to_texture_atlas(RID p_texture);
+ void texture_remove_from_texture_atlas(RID p_texture);
+ void texture_atlas_mark_dirty_on_texture(RID p_texture);
+ void texture_atlas_remove_texture(RID p_texture);
+
/* DECAL API */
virtual RID decal_allocate() override;