FileTexture.cpp 945 B

1234567891011121314151617181920212223242526272829303132
  1. #include "rendering/FileTexture.h"
  2. #include "io/ImageReader.h"
  3. Error FileTexture::load(const char* path, int maxMipMaps) {
  4. ImageReader::Image image;
  5. Error error = ImageReader::load(image, path);
  6. if(error.has()) {
  7. return error;
  8. }
  9. if(image.channels < 1 || image.channels > 4) {
  10. Error error = {"'"};
  11. error.message.append(path)
  12. .append("' has unsupported number of channels: ")
  13. .append(image.channels);
  14. return error;
  15. } else if(image.bitdepth != 8) {
  16. Error error = {"bit depth of '"};
  17. error.message.append(path).append("' is not 8");
  18. return error;
  19. }
  20. texture.init(TextureFormat::color8(image.channels), maxMipMaps);
  21. texture.setData(image.width, image.height, image.data);
  22. return {};
  23. }
  24. void FileTexture::bindTo(int index) const {
  25. texture.bindTo(index);
  26. }
  27. void FileTexture::setLinearFilter() {
  28. texture.setLinearFilter();
  29. }