Path: blob/master/scene/resources/compressed_texture_resource_format.cpp
45987 views
/**************************************************************************/1/* compressed_texture_resource_format.cpp */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#include "compressed_texture_resource_format.h"3132#include "scene/resources/compressed_texture.h"3334Ref<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) {35Ref<CompressedTexture2D> st;36st.instantiate();37Error err = st->load(p_path);38if (r_error) {39*r_error = err;40}41if (err != OK) {42return Ref<Resource>();43}4445return st;46}4748void ResourceFormatLoaderCompressedTexture2D::get_recognized_extensions(List<String> *p_extensions) const {49p_extensions->push_back("ctex");50}5152bool ResourceFormatLoaderCompressedTexture2D::handles_type(const String &p_type) const {53return p_type == "CompressedTexture2D";54}5556String ResourceFormatLoaderCompressedTexture2D::get_resource_type(const String &p_path) const {57if (p_path.has_extension("ctex")) {58return "CompressedTexture2D";59}60return "";61}6263Ref<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) {64Ref<CompressedTextureLayered> ct;65if (p_path.has_extension("ctexarray")) {66Ref<CompressedTexture2DArray> c;67c.instantiate();68ct = c;69} else if (p_path.has_extension("ccube")) {70Ref<CompressedCubemap> c;71c.instantiate();72ct = c;73} else if (p_path.has_extension("ccubearray")) {74Ref<CompressedCubemapArray> c;75c.instantiate();76ct = c;77} else {78if (r_error) {79*r_error = ERR_FILE_UNRECOGNIZED;80}81return Ref<Resource>();82}83Error err = ct->load(p_path);84if (r_error) {85*r_error = err;86}87if (err != OK) {88return Ref<Resource>();89}9091return ct;92}9394void ResourceFormatLoaderCompressedTextureLayered::get_recognized_extensions(List<String> *p_extensions) const {95p_extensions->push_back("ctexarray");96p_extensions->push_back("ccube");97p_extensions->push_back("ccubearray");98}99100bool ResourceFormatLoaderCompressedTextureLayered::handles_type(const String &p_type) const {101return p_type == "CompressedTexture2DArray" || p_type == "CompressedCubemap" || p_type == "CompressedCubemapArray";102}103104String ResourceFormatLoaderCompressedTextureLayered::get_resource_type(const String &p_path) const {105if (p_path.has_extension("ctexarray")) {106return "CompressedTexture2DArray";107}108if (p_path.has_extension("ccube")) {109return "CompressedCubemap";110}111if (p_path.has_extension("ccubearray")) {112return "CompressedCubemapArray";113}114return "";115}116117Ref<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) {118Ref<CompressedTexture3D> st;119st.instantiate();120Error err = st->load(p_path);121if (r_error) {122*r_error = err;123}124if (err != OK) {125return Ref<Resource>();126}127128return st;129}130131void ResourceFormatLoaderCompressedTexture3D::get_recognized_extensions(List<String> *p_extensions) const {132p_extensions->push_back("ctex3d");133}134135bool ResourceFormatLoaderCompressedTexture3D::handles_type(const String &p_type) const {136return p_type == "CompressedTexture3D";137}138139String ResourceFormatLoaderCompressedTexture3D::get_resource_type(const String &p_path) const {140if (p_path.has_extension("ctex3d")) {141return "CompressedTexture3D";142}143return "";144}145146147