texture_loader_gles3.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*************************************************************************/
  2. /* texture_loader_gles3.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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_gles3.h"
  31. #ifdef GLES3_ENABLED
  32. #include "core/io/file_access.h"
  33. #include "core/string/print_string.h"
  34. #include <string.h>
  35. RES ResourceFormatGLES2Texture::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. unsigned int width = 8;
  37. unsigned int height = 8;
  38. //We just use some format
  39. Image::Format fmt = Image::FORMAT_RGB8;
  40. int rowsize = 3 * width;
  41. Vector<uint8_t> dstbuff;
  42. dstbuff.resize(rowsize * height);
  43. uint8_t **row_p = memnew_arr(uint8_t *, height);
  44. for (unsigned int i = 0; i < height; i++) {
  45. row_p[i] = 0; //No colors any more, I want them to turn black
  46. }
  47. memdelete_arr(row_p);
  48. Ref<Image> img = memnew(Image(width, height, 0, fmt, dstbuff));
  49. Ref<ImageTexture> texture = memnew(ImageTexture);
  50. texture->create_from_image(img);
  51. if (r_error) {
  52. *r_error = OK;
  53. }
  54. return texture;
  55. }
  56. void ResourceFormatGLES2Texture::get_recognized_extensions(List<String> *p_extensions) const {
  57. p_extensions->push_back("bmp");
  58. p_extensions->push_back("dds");
  59. p_extensions->push_back("exr");
  60. p_extensions->push_back("jpeg");
  61. p_extensions->push_back("jpg");
  62. p_extensions->push_back("hdr");
  63. p_extensions->push_back("pkm");
  64. p_extensions->push_back("png");
  65. p_extensions->push_back("pvr");
  66. p_extensions->push_back("svg");
  67. p_extensions->push_back("tga");
  68. p_extensions->push_back("webp");
  69. }
  70. bool ResourceFormatGLES2Texture::handles_type(const String &p_type) const {
  71. return ClassDB::is_parent_class(p_type, "Texture2D");
  72. }
  73. String ResourceFormatGLES2Texture::get_resource_type(const String &p_path) const {
  74. String extension = p_path.get_extension().to_lower();
  75. if (
  76. extension == "bmp" ||
  77. extension == "dds" ||
  78. extension == "exr" ||
  79. extension == "jpeg" ||
  80. extension == "jpg" ||
  81. extension == "hdr" ||
  82. extension == "pkm" ||
  83. extension == "png" ||
  84. extension == "pvr" ||
  85. extension == "svg" ||
  86. extension == "tga" ||
  87. extension == "webp") {
  88. return "ImageTexture";
  89. }
  90. return "";
  91. }
  92. #endif