texture_loader_dummy.cpp 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*************************************************************************/
  2. /* texture_loader_dummy.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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_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("png");
  56. p_extensions->push_back("hdr");
  57. p_extensions->push_back("jpg");
  58. p_extensions->push_back("tga");
  59. }
  60. bool ResourceFormatDummyTexture::handles_type(const String &p_type) const {
  61. return ClassDB::is_parent_class(p_type, "Texture");
  62. }
  63. String ResourceFormatDummyTexture::get_resource_type(const String &p_path) const {
  64. String extension = p_path.get_extension().to_lower();
  65. if (extension == "png" || extension == "hdr" || extension == "jpg" || extension == "tga")
  66. return "ImageTexture";
  67. return "";
  68. }