FileTexture.cpp 584 B

123456789101112131415161718192021
  1. #include "rendering/FileTexture.h"
  2. #include "images/PNGReader.h"
  3. #include "utils/List.h"
  4. FileTexture::FileTexture(const char* path, int maxMipMaps)
  5. : texture(maxMipMaps) {
  6. PNGReader png(path);
  7. if(png.hasError()) {
  8. return;
  9. }
  10. List<ColorChannel> buffer;
  11. buffer.resize(png.getBufferSize());
  12. if(!png.readData(buffer.begin())) {
  13. texture.setFormat(TextureFormat::color8(png.getChannels()));
  14. texture.setData(png.getWidth(), png.getHeight(), buffer.begin());
  15. }
  16. }
  17. void FileTexture::bindTo(int index) const {
  18. texture.bindTo(index);
  19. }