Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/resources/compressed_texture_resource_format.cpp
45987 views
1
/**************************************************************************/
2
/* compressed_texture_resource_format.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "compressed_texture_resource_format.h"
32
33
#include "scene/resources/compressed_texture.h"
34
35
Ref<Resource> ResourceFormatLoaderCompressedTexture2D::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) {
36
Ref<CompressedTexture2D> st;
37
st.instantiate();
38
Error err = st->load(p_path);
39
if (r_error) {
40
*r_error = err;
41
}
42
if (err != OK) {
43
return Ref<Resource>();
44
}
45
46
return st;
47
}
48
49
void ResourceFormatLoaderCompressedTexture2D::get_recognized_extensions(List<String> *p_extensions) const {
50
p_extensions->push_back("ctex");
51
}
52
53
bool ResourceFormatLoaderCompressedTexture2D::handles_type(const String &p_type) const {
54
return p_type == "CompressedTexture2D";
55
}
56
57
String ResourceFormatLoaderCompressedTexture2D::get_resource_type(const String &p_path) const {
58
if (p_path.has_extension("ctex")) {
59
return "CompressedTexture2D";
60
}
61
return "";
62
}
63
64
Ref<Resource> ResourceFormatLoaderCompressedTextureLayered::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) {
65
Ref<CompressedTextureLayered> ct;
66
if (p_path.has_extension("ctexarray")) {
67
Ref<CompressedTexture2DArray> c;
68
c.instantiate();
69
ct = c;
70
} else if (p_path.has_extension("ccube")) {
71
Ref<CompressedCubemap> c;
72
c.instantiate();
73
ct = c;
74
} else if (p_path.has_extension("ccubearray")) {
75
Ref<CompressedCubemapArray> c;
76
c.instantiate();
77
ct = c;
78
} else {
79
if (r_error) {
80
*r_error = ERR_FILE_UNRECOGNIZED;
81
}
82
return Ref<Resource>();
83
}
84
Error err = ct->load(p_path);
85
if (r_error) {
86
*r_error = err;
87
}
88
if (err != OK) {
89
return Ref<Resource>();
90
}
91
92
return ct;
93
}
94
95
void ResourceFormatLoaderCompressedTextureLayered::get_recognized_extensions(List<String> *p_extensions) const {
96
p_extensions->push_back("ctexarray");
97
p_extensions->push_back("ccube");
98
p_extensions->push_back("ccubearray");
99
}
100
101
bool ResourceFormatLoaderCompressedTextureLayered::handles_type(const String &p_type) const {
102
return p_type == "CompressedTexture2DArray" || p_type == "CompressedCubemap" || p_type == "CompressedCubemapArray";
103
}
104
105
String ResourceFormatLoaderCompressedTextureLayered::get_resource_type(const String &p_path) const {
106
if (p_path.has_extension("ctexarray")) {
107
return "CompressedTexture2DArray";
108
}
109
if (p_path.has_extension("ccube")) {
110
return "CompressedCubemap";
111
}
112
if (p_path.has_extension("ccubearray")) {
113
return "CompressedCubemapArray";
114
}
115
return "";
116
}
117
118
Ref<Resource> ResourceFormatLoaderCompressedTexture3D::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) {
119
Ref<CompressedTexture3D> st;
120
st.instantiate();
121
Error err = st->load(p_path);
122
if (r_error) {
123
*r_error = err;
124
}
125
if (err != OK) {
126
return Ref<Resource>();
127
}
128
129
return st;
130
}
131
132
void ResourceFormatLoaderCompressedTexture3D::get_recognized_extensions(List<String> *p_extensions) const {
133
p_extensions->push_back("ctex3d");
134
}
135
136
bool ResourceFormatLoaderCompressedTexture3D::handles_type(const String &p_type) const {
137
return p_type == "CompressedTexture3D";
138
}
139
140
String ResourceFormatLoaderCompressedTexture3D::get_resource_type(const String &p_path) const {
141
if (p_path.has_extension("ctex3d")) {
142
return "CompressedTexture3D";
143
}
144
return "";
145
}
146
147