texture_loader_dummy.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**************************************************************************/
  2. /* texture_loader_dummy.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. #include "texture_loader_dummy.h"
  31. #include "core/os/file_access.h"
  32. #include "core/print_string.h"
  33. #include <string.h>
  34. RES ResourceFormatDummyTexture::load(const String &p_path, const String &p_original_path, Error *r_error) {
  35. unsigned int width = 8;
  36. unsigned int height = 8;
  37. //We just use some format
  38. Image::Format fmt = Image::FORMAT_RGB8;
  39. int rowsize = 3 * width;
  40. PoolVector<uint8_t> dstbuff;
  41. dstbuff.resize(rowsize * height);
  42. uint8_t **row_p = memnew_arr(uint8_t *, height);
  43. for (unsigned int i = 0; i < height; i++) {
  44. row_p[i] = 0; //No colors any more, I want them to turn black
  45. }
  46. memdelete_arr(row_p);
  47. Ref<Image> img = memnew(Image(width, height, 0, fmt, dstbuff));
  48. Ref<ImageTexture> texture = memnew(ImageTexture);
  49. texture->create_from_image(img);
  50. if (r_error)
  51. *r_error = OK;
  52. return texture;
  53. }
  54. void ResourceFormatDummyTexture::get_recognized_extensions(List<String> *p_extensions) const {
  55. p_extensions->push_back("bmp");
  56. p_extensions->push_back("dds");
  57. p_extensions->push_back("exr");
  58. p_extensions->push_back("jpeg");
  59. p_extensions->push_back("jpg");
  60. p_extensions->push_back("hdr");
  61. p_extensions->push_back("pkm");
  62. p_extensions->push_back("png");
  63. p_extensions->push_back("pvr");
  64. p_extensions->push_back("svg");
  65. p_extensions->push_back("tga");
  66. p_extensions->push_back("webp");
  67. }
  68. bool ResourceFormatDummyTexture::handles_type(const String &p_type) const {
  69. return ClassDB::is_parent_class(p_type, "Texture");
  70. }
  71. String ResourceFormatDummyTexture::get_resource_type(const String &p_path) const {
  72. String extension = p_path.get_extension().to_lower();
  73. if (
  74. extension == "bmp" ||
  75. extension == "dds" ||
  76. extension == "exr" ||
  77. extension == "jpeg" ||
  78. extension == "jpg" ||
  79. extension == "hdr" ||
  80. extension == "pkm" ||
  81. extension == "png" ||
  82. extension == "pvr" ||
  83. extension == "svg" ||
  84. extension == "tga" ||
  85. extension == "webp") {
  86. return "ImageTexture";
  87. }
  88. return "";
  89. }