FileTexture.cpp 642 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. StackAllocator::Array<ColorChannel> buffer(png.getBufferSize());
  12. if(buffer.getLength() == png.getBufferSize() && !png.readData(buffer)) {
  13. texture.setFormat(TextureFormat::color8(png.getChannels()));
  14. texture.setData(png.getWidth(), png.getHeight(), buffer);
  15. }
  16. }
  17. void FileTexture::bindTo(int index) const {
  18. texture.bindTo(index);
  19. }