Path: blob/master/scene/resources/drawable_texture_2d.h
20959 views
/**************************************************************************/1/* drawable_texture_2d.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 "scene/resources/atlas_texture.h"33#include "scene/resources/image_texture.h"34#include "scene/resources/material.h"3536class DrawableTexture2D : public Texture2D {37GDCLASS(DrawableTexture2D, Texture2D);38RES_BASE_EXTENSION("tex");3940public:41enum DrawableFormat {42DRAWABLE_FORMAT_RGBA8,43DRAWABLE_FORMAT_RGBA8_SRGB,44DRAWABLE_FORMAT_RGBAH,45DRAWABLE_FORMAT_RGBAF,46};4748private:49mutable RID texture;50int width = 64;51int height = 64;52bool mipmaps = false;53DrawableFormat format = DRAWABLE_FORMAT_RGBA8;5455Color base_color = Color(1, 1, 1, 1);5657RID default_material;5859void _initialize();6061protected:62static void _bind_methods();6364public:65void set_width(int p_width);66int get_width() const override;67void set_height(int p_height);68int get_height() const override;6970void set_format(DrawableFormat p_format);71DrawableFormat get_format() const;72void set_use_mipmaps(bool p_mipmaps);73bool get_use_mipmaps() const;7475virtual RID get_rid() const override;7677virtual void draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false) const override;78virtual void draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false) const override;79virtual void draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, bool p_clip_uv = true) const override;8081void setup(int p_width, int p_height, DrawableFormat p_format, const Color &p_modulate = Color(1, 1, 1, 1), bool p_use_mipmaps = false);8283void blit_rect(const Rect2i p_rect, const Ref<Texture2D> &p_source, const Color &p_modulate = Color(1, 1, 1, 1), int p_mipmap = 0, const Ref<Material> &p_material = Ref<Material>());84void blit_rect_multi(const Rect2i p_rect, const TypedArray<Texture2D> &p_sources, const TypedArray<DrawableTexture2D> &p_extra_targets, const Color &p_modulate = Color(1, 1, 1, 1), int p_mipmap = 0, const Ref<Material> &p_material = Ref<Material>());8586virtual Ref<Image> get_image() const override;8788void generate_mipmaps();8990DrawableTexture2D();91~DrawableTexture2D();92};9394VARIANT_ENUM_CAST(DrawableTexture2D::DrawableFormat)959697