|
@@ -1,4 +1,5 @@
|
|
|
#include "rendering/Texture.h"
|
|
|
+#include "io/ImageReader.h"
|
|
|
|
|
|
Texture::Texture()
|
|
|
: format(TextureFormat::unknown()), texture(0), maxMipMaps(0) {
|
|
@@ -62,4 +63,26 @@ void Texture::bind() const {
|
|
|
void Texture::bindTo(int index) const {
|
|
|
GL::activeTexture(index);
|
|
|
bind();
|
|
|
+}
|
|
|
+
|
|
|
+Error Texture::load(const char* path, int maxMipMaps) {
|
|
|
+ ImageReader::Image image;
|
|
|
+ Error error = ImageReader::load(image, path);
|
|
|
+ if(error.has()) {
|
|
|
+ return error;
|
|
|
+ }
|
|
|
+ if(image.channels < 1 || image.channels > 4) {
|
|
|
+ Error error = {"'"};
|
|
|
+ error.message.append(path)
|
|
|
+ .append("' has unsupported number of channels: ")
|
|
|
+ .append(image.channels);
|
|
|
+ return error;
|
|
|
+ } else if(image.bitdepth != 8) {
|
|
|
+ Error error = {"bit depth of '"};
|
|
|
+ error.message.append(path).append("' is not 8");
|
|
|
+ return error;
|
|
|
+ }
|
|
|
+ init(TextureFormat::color8(image.channels), maxMipMaps);
|
|
|
+ setData(image.width, image.height, image.data);
|
|
|
+ return {};
|
|
|
}
|