FileTexture.cpp 580 B

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