summaryrefslogtreecommitdiff
path: root/scene/resources/texture.h
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources/texture.h')
-rw-r--r--scene/resources/texture.h237
1 files changed, 107 insertions, 130 deletions
diff --git a/scene/resources/texture.h b/scene/resources/texture.h
index cae77ad5cf..0092fee836 100644
--- a/scene/resources/texture.h
+++ b/scene/resources/texture.h
@@ -29,76 +29,73 @@
#ifndef TEXTURE_H
#define TEXTURE_H
-#include "resource.h"
-#include "servers/visual_server.h"
#include "io/resource_loader.h"
#include "math_2d.h"
+#include "resource.h"
+#include "servers/visual_server.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
-
-
class Texture : public Resource {
- GDCLASS( Texture, Resource );
- OBJ_SAVE_TYPE( Texture ); //children are all saved as Texture, so they can be exchanged
+ GDCLASS(Texture, Resource);
+ OBJ_SAVE_TYPE(Texture); //children are all saved as Texture, so they can be exchanged
protected:
-
static void _bind_methods();
-public:
+public:
enum Flags {
- FLAG_MIPMAPS=VisualServer::TEXTURE_FLAG_MIPMAPS,
- FLAG_REPEAT=VisualServer::TEXTURE_FLAG_REPEAT,
- FLAG_FILTER=VisualServer::TEXTURE_FLAG_FILTER,
- FLAG_ANISOTROPIC_FILTER=VisualServer::TEXTURE_FLAG_ANISOTROPIC_FILTER,
- FLAG_CONVERT_TO_LINEAR=VisualServer::TEXTURE_FLAG_CONVERT_TO_LINEAR,
- FLAG_VIDEO_SURFACE=VisualServer::TEXTURE_FLAG_USED_FOR_STREAMING,
- FLAGS_DEFAULT=FLAG_MIPMAPS|FLAG_REPEAT|FLAG_FILTER,
- FLAG_MIRRORED_REPEAT=VisualServer::TEXTURE_FLAG_MIRRORED_REPEAT
+ FLAG_MIPMAPS = VisualServer::TEXTURE_FLAG_MIPMAPS,
+ FLAG_REPEAT = VisualServer::TEXTURE_FLAG_REPEAT,
+ FLAG_FILTER = VisualServer::TEXTURE_FLAG_FILTER,
+ FLAG_ANISOTROPIC_FILTER = VisualServer::TEXTURE_FLAG_ANISOTROPIC_FILTER,
+ FLAG_CONVERT_TO_LINEAR = VisualServer::TEXTURE_FLAG_CONVERT_TO_LINEAR,
+ FLAG_VIDEO_SURFACE = VisualServer::TEXTURE_FLAG_USED_FOR_STREAMING,
+ FLAGS_DEFAULT = FLAG_MIPMAPS | FLAG_REPEAT | FLAG_FILTER,
+ FLAG_MIRRORED_REPEAT = VisualServer::TEXTURE_FLAG_MIRRORED_REPEAT
};
-
- virtual int get_width() const=0;
- virtual int get_height() const=0;
+ virtual int get_width() const = 0;
+ virtual int get_height() const = 0;
virtual Size2 get_size() const;
- virtual RID get_rid() const=0;
+ virtual RID get_rid() const = 0;
- virtual bool has_alpha() const=0;
+ virtual bool has_alpha() const = 0;
- virtual void set_flags(uint32_t p_flags)=0;
- virtual uint32_t get_flags() const=0;
+ virtual void set_flags(uint32_t p_flags) = 0;
+ virtual uint32_t get_flags() const = 0;
- virtual void draw(RID p_canvas_item, const Point2& p_pos, const Color& p_modulate=Color(1,1,1), bool p_transpose=false) const;
- virtual 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;
- virtual 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) const;
- virtual bool get_rect_region(const Rect2& p_rect, const Rect2& p_src_rect,Rect2& r_rect,Rect2& r_src_rect) const;
+ virtual void draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false) const;
+ virtual 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;
+ virtual 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) const;
+ virtual bool get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const;
virtual Image get_data() const { return Image(); }
Texture();
};
-VARIANT_ENUM_CAST( Texture::Flags );
-
+VARIANT_ENUM_CAST(Texture::Flags);
class ImageTexture : public Texture {
- GDCLASS( ImageTexture, Texture );
+ GDCLASS(ImageTexture, Texture);
RES_BASE_EXTENSION("tex");
+
public:
enum Storage {
STORAGE_RAW,
STORAGE_COMPRESS_LOSSY,
STORAGE_COMPRESS_LOSSLESS
};
+
private:
RID texture;
Image::Format format;
uint32_t flags;
- int w,h;
+ int w, h;
Storage storage;
Size2 size_override;
float lossy_storage_quality;
@@ -106,28 +103,25 @@ private:
protected:
virtual void reload_from_file();
- bool _set(const StringName& p_name, const Variant& p_value);
- bool _get(const StringName& p_name,Variant &r_ret) const;
- void _get_property_list( List<PropertyInfo> *p_list) const;
+ bool _set(const StringName &p_name, const Variant &p_value);
+ bool _get(const StringName &p_name, Variant &r_ret) const;
+ void _get_property_list(List<PropertyInfo> *p_list) const;
- void _reload_hook(const RID& p_hook);
+ void _reload_hook(const RID &p_hook);
virtual void _resource_path_changed();
static void _bind_methods();
void _set_data(Dictionary p_data);
public:
-
-
- void create(int p_width, int p_height,Image::Format p_format,uint32_t p_flags=FLAGS_DEFAULT);
- void create_from_image(const Image& p_image, uint32_t p_flags=FLAGS_DEFAULT);
-
+ void create(int p_width, int p_height, Image::Format p_format, uint32_t p_flags = FLAGS_DEFAULT);
+ void create_from_image(const Image &p_image, uint32_t p_flags = FLAGS_DEFAULT);
void set_flags(uint32_t p_flags);
uint32_t get_flags() const;
Image::Format get_format() const;
- void load(const String& p_path);
- void set_data(const Image& p_image);
+ void load(const String &p_path);
+ void set_data(const Image &p_image);
Image get_data() const;
int get_width() const;
@@ -136,9 +130,9 @@ public:
virtual RID get_rid() const;
bool has_alpha() const;
- virtual void draw(RID p_canvas_item, const Point2& p_pos, const Color& p_modulate=Color(1,1,1), bool p_transpose=false) const;
- virtual 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;
- virtual 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) const;
+ virtual void draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false) const;
+ virtual 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;
+ virtual 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) const;
void set_storage(Storage p_storage);
Storage get_storage() const;
@@ -150,21 +144,18 @@ public:
void normal_to_xy();
void shrink_x2_and_keep_size();
+ void set_size_override(const Size2 &p_size);
- void set_size_override(const Size2& p_size);
-
- virtual void set_path(const String& p_path,bool p_take_over=false);
+ virtual void set_path(const String &p_path, bool p_take_over = false);
ImageTexture();
~ImageTexture();
-
};
-
-
class StreamTexture : public Texture {
- GDCLASS( StreamTexture, Texture );
+ GDCLASS(StreamTexture, Texture);
+
public:
enum DataFormat {
DATA_FORMAT_IMAGE,
@@ -173,53 +164,49 @@ public:
};
enum FormatBits {
- FORMAT_MASK_IMAGE_FORMAT=(1<<20)-1,
- FORMAT_BIT_LOSSLESS=1<<20,
- FORMAT_BIT_LOSSY=1<<21,
- FORMAT_BIT_STREAM=1<<22,
- FORMAT_BIT_HAS_MIPMAPS=1<<23,
- FORMAT_BIT_DETECT_3D=1<<24,
- FORMAT_BIT_DETECT_SRGB=1<<25,
+ FORMAT_MASK_IMAGE_FORMAT = (1 << 20) - 1,
+ FORMAT_BIT_LOSSLESS = 1 << 20,
+ FORMAT_BIT_LOSSY = 1 << 21,
+ FORMAT_BIT_STREAM = 1 << 22,
+ FORMAT_BIT_HAS_MIPMAPS = 1 << 23,
+ FORMAT_BIT_DETECT_3D = 1 << 24,
+ FORMAT_BIT_DETECT_SRGB = 1 << 25,
};
private:
-
- Error _load_data(const String &p_path, int &tw, int &th, int& flags, Image& image, int p_size_limit=0);
+ Error _load_data(const String &p_path, int &tw, int &th, int &flags, Image &image, int p_size_limit = 0);
String path_to_file;
RID texture;
Image::Format format;
uint32_t flags;
- int w,h;
+ int w, h;
virtual void reload_from_file();
- static void _requested_3d(void* p_ud);
- static void _requested_srgb(void* p_ud);
+ static void _requested_3d(void *p_ud);
+ static void _requested_srgb(void *p_ud);
protected:
-
static void _bind_methods();
public:
-
-
- typedef void (*TextureFormatRequestCallback)(const Ref<StreamTexture>&);
+ typedef void (*TextureFormatRequestCallback)(const Ref<StreamTexture> &);
static TextureFormatRequestCallback request_3d_callback;
static TextureFormatRequestCallback request_srgb_callback;
uint32_t get_flags() const;
Image::Format get_format() const;
- Error load(const String& p_path);
+ Error load(const String &p_path);
String get_load_path() const;
int get_width() const;
int get_height() const;
virtual RID get_rid() const;
- virtual void draw(RID p_canvas_item, const Point2& p_pos, const Color& p_modulate=Color(1,1,1), bool p_transpose=false) const;
- virtual 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;
- virtual 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) const;
+ virtual void draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false) const;
+ virtual 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;
+ virtual 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) const;
virtual bool has_alpha() const;
virtual void set_flags(uint32_t p_flags);
@@ -228,37 +215,31 @@ public:
StreamTexture();
~StreamTexture();
-
};
-
class ResourceFormatLoaderStreamTexture : public ResourceFormatLoader {
public:
- virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL);
+ virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
- virtual bool handles_type(const String& p_type) const;
+ virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
-
};
-
-
-VARIANT_ENUM_CAST( ImageTexture::Storage );
+VARIANT_ENUM_CAST(ImageTexture::Storage);
class AtlasTexture : public Texture {
- GDCLASS( AtlasTexture, Texture );
+ GDCLASS(AtlasTexture, Texture);
RES_BASE_EXTENSION("atex");
-protected:
-
+protected:
Ref<Texture> atlas;
Rect2 region;
Rect2 margin;
static void _bind_methods();
-public:
+public:
virtual int get_width() const;
virtual int get_height() const;
virtual RID get_rid() const;
@@ -268,30 +249,29 @@ public:
virtual void set_flags(uint32_t p_flags);
virtual uint32_t get_flags() const;
- void set_atlas(const Ref<Texture>& p_atlas);
+ void set_atlas(const Ref<Texture> &p_atlas);
Ref<Texture> get_atlas() const;
- void set_region(const Rect2& p_region);
- Rect2 get_region() const ;
-
- void set_margin(const Rect2& p_margin);
- Rect2 get_margin() const ;
+ void set_region(const Rect2 &p_region);
+ Rect2 get_region() const;
- virtual void draw(RID p_canvas_item, const Point2& p_pos, const Color& p_modulate=Color(1,1,1), bool p_transpose=false) const;
- virtual 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;
- virtual 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) const;
- virtual bool get_rect_region(const Rect2& p_rect, const Rect2& p_src_rect,Rect2& r_rect,Rect2& r_src_rect) const;
+ void set_margin(const Rect2 &p_margin);
+ Rect2 get_margin() const;
+ virtual void draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false) const;
+ virtual 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;
+ virtual 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) const;
+ virtual bool get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const;
AtlasTexture();
};
class LargeTexture : public Texture {
- GDCLASS( LargeTexture, Texture );
+ GDCLASS(LargeTexture, Texture);
RES_BASE_EXTENSION("ltex");
-protected:
+protected:
struct Piece {
Point2 offset;
@@ -301,12 +281,11 @@ protected:
Vector<Piece> pieces;
Size2i size;
-
Array _get_data() const;
- void _set_data(const Array& p_array);
+ void _set_data(const Array &p_array);
static void _bind_methods();
-public:
+public:
virtual int get_width() const;
virtual int get_height() const;
virtual RID get_rid() const;
@@ -316,31 +295,29 @@ public:
virtual void set_flags(uint32_t p_flags);
virtual uint32_t get_flags() const;
- int add_piece(const Point2& p_offset,const Ref<Texture>& p_texture);
- void set_piece_offset(int p_idx, const Point2& p_offset);
- void set_piece_texture(int p_idx, const Ref<Texture>& p_texture);
+ int add_piece(const Point2 &p_offset, const Ref<Texture> &p_texture);
+ void set_piece_offset(int p_idx, const Point2 &p_offset);
+ void set_piece_texture(int p_idx, const Ref<Texture> &p_texture);
- void set_size(const Size2& p_size);
+ void set_size(const Size2 &p_size);
void clear();
int get_piece_count() const;
Vector2 get_piece_offset(int p_idx) const;
Ref<Texture> get_piece_texture(int p_idx) const;
- virtual void draw(RID p_canvas_item, const Point2& p_pos, const Color& p_modulate=Color(1,1,1), bool p_transpose=false) const;
- virtual 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;
- virtual 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) const;
-
+ virtual void draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false) const;
+ virtual 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;
+ virtual 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) const;
LargeTexture();
};
-
-
class CubeMap : public Resource {
- GDCLASS( CubeMap, Resource );
+ GDCLASS(CubeMap, Resource);
RES_BASE_EXTENSION("cbm");
+
public:
enum Storage {
STORAGE_RAW,
@@ -359,37 +336,40 @@ public:
};
enum Flags {
- FLAG_MIPMAPS=VisualServer::TEXTURE_FLAG_MIPMAPS,
- FLAG_REPEAT=VisualServer::TEXTURE_FLAG_REPEAT,
- FLAG_FILTER=VisualServer::TEXTURE_FLAG_FILTER,
- FLAGS_DEFAULT=FLAG_MIPMAPS|FLAG_REPEAT|FLAG_FILTER,
+ FLAG_MIPMAPS = VisualServer::TEXTURE_FLAG_MIPMAPS,
+ FLAG_REPEAT = VisualServer::TEXTURE_FLAG_REPEAT,
+ FLAG_FILTER = VisualServer::TEXTURE_FLAG_FILTER,
+ FLAGS_DEFAULT = FLAG_MIPMAPS | FLAG_REPEAT | FLAG_FILTER,
};
private:
-
bool valid[6];
RID cubemap;
Image::Format format;
uint32_t flags;
- int w,h;
+ int w, h;
Storage storage;
Size2 size_override;
float lossy_storage_quality;
- _FORCE_INLINE_ bool _is_valid() const { for(int i=0;i<6;i++) { if (valid[i]) return true; } return false; }
+ _FORCE_INLINE_ bool _is_valid() const {
+ for (int i = 0; i < 6; i++) {
+ if (valid[i]) return true;
+ }
+ return false;
+ }
protected:
-
- bool _set(const StringName& p_name, const Variant& p_value);
- bool _get(const StringName& p_name,Variant &r_ret) const;
- void _get_property_list( List<PropertyInfo> *p_list) const;
+ bool _set(const StringName &p_name, const Variant &p_value);
+ bool _get(const StringName &p_name, Variant &r_ret) const;
+ void _get_property_list(List<PropertyInfo> *p_list) const;
static void _bind_methods();
-public:
+public:
void set_flags(uint32_t p_flags);
uint32_t get_flags() const;
- void set_side(Side p_side,const Image& p_image);
+ void set_side(Side p_side, const Image &p_image);
Image get_side(Side p_side) const;
Image::Format get_format() const;
@@ -404,17 +384,15 @@ public:
void set_lossy_storage_quality(float p_lossy_storage_quality);
float get_lossy_storage_quality() const;
- virtual void set_path(const String& p_path,bool p_take_over=false);
+ virtual void set_path(const String &p_path, bool p_take_over = false);
CubeMap();
~CubeMap();
-
};
-VARIANT_ENUM_CAST( CubeMap::Flags );
-VARIANT_ENUM_CAST( CubeMap::Side );
-VARIANT_ENUM_CAST( CubeMap::Storage );
-
+VARIANT_ENUM_CAST(CubeMap::Flags);
+VARIANT_ENUM_CAST(CubeMap::Side);
+VARIANT_ENUM_CAST(CubeMap::Storage);
/*
enum CubeMapSide {
@@ -430,5 +408,4 @@ VARIANT_ENUM_CAST( CubeMap::Storage );
*/
//VARIANT_ENUM_CAST( Texture::CubeMapSide );
-
#endif