2021-11-27 19:16:41 +00:00
|
|
|
#pragma once
|
2021-11-27 18:52:48 +00:00
|
|
|
|
2022-09-27 04:26:50 +00:00
|
|
|
#include <cstdint>
|
2021-12-02 21:56:49 +00:00
|
|
|
#ifdef __linux__
|
|
|
|
#include <GL/glew.h>
|
|
|
|
#include <GL/gl.h>
|
2021-12-13 03:17:59 +00:00
|
|
|
#else
|
2021-11-27 18:52:48 +00:00
|
|
|
#include <gl/glew.h>
|
|
|
|
#include <gl/gl.h>
|
2021-12-02 21:56:49 +00:00
|
|
|
#endif
|
2021-11-27 18:52:48 +00:00
|
|
|
|
2022-09-22 04:11:12 +00:00
|
|
|
#include <assimp/material.h>
|
2021-11-27 18:52:48 +00:00
|
|
|
|
|
|
|
#include <glm/glm.hpp>
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
|
|
|
|
2021-11-27 19:11:07 +00:00
|
|
|
namespace simpleengine::gfx {
|
2022-10-13 03:27:14 +00:00
|
|
|
enum TextureFlags {
|
|
|
|
TexFlags_IMG_2D = 0x1,
|
|
|
|
TexFlags_FLIP_VERTICALLY = 0x2,
|
|
|
|
TexFlags_FLIP_HORIZONTALLY = 0x4,
|
|
|
|
TexFlags_MIPMAP = 0x8
|
2022-09-27 04:26:50 +00:00
|
|
|
};
|
|
|
|
|
2021-11-27 18:52:48 +00:00
|
|
|
class Texture {
|
|
|
|
private:
|
2022-10-12 03:16:52 +00:00
|
|
|
//unsigned char* img_data; // TODO Free this if its not used anymore
|
2021-11-27 18:52:48 +00:00
|
|
|
unsigned int texture_id;
|
|
|
|
|
2022-09-22 02:52:06 +00:00
|
|
|
unsigned int image_type_gl;
|
|
|
|
|
|
|
|
Texture() = default;
|
2021-11-27 18:52:48 +00:00
|
|
|
public:
|
2022-09-29 01:21:47 +00:00
|
|
|
/**
|
|
|
|
* @brief The default Texture flags including the color.
|
|
|
|
*
|
2022-10-12 03:16:52 +00:00
|
|
|
* The default flags are `TexFlags_IMG_2D | TexFlags_MIPMAP`
|
2022-09-29 01:21:47 +00:00
|
|
|
*
|
|
|
|
* @see simpleengine::gfx::Texture::default_flags_no_color
|
|
|
|
*
|
|
|
|
*/
|
2022-10-12 03:16:52 +00:00
|
|
|
static constexpr int default_flags = TexFlags_IMG_2D | TexFlags_MIPMAP;
|
2022-09-29 01:21:47 +00:00
|
|
|
|
2021-11-27 18:52:48 +00:00
|
|
|
int height;
|
|
|
|
int width;
|
|
|
|
int channels;
|
2022-09-22 04:11:12 +00:00
|
|
|
aiTextureType type;
|
2022-09-27 03:43:08 +00:00
|
|
|
std::string path;
|
2021-11-27 18:52:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Construct a new Texture object from a path.
|
|
|
|
*
|
|
|
|
* @param path The path of the image for the Texture.
|
|
|
|
* @param img_2d Whether or not the texture is 2D.
|
|
|
|
* @param mipmap Whether or not to generate mipmaps for this texture.
|
|
|
|
*/
|
2022-09-29 01:21:47 +00:00
|
|
|
Texture(const char* path, aiTextureType type = aiTextureType::aiTextureType_DIFFUSE, int flags = Texture::default_flags);
|
2021-11-27 18:52:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Construct a new Texture object from the loaded file buffer.
|
|
|
|
*
|
|
|
|
* @param buffer The bytes of the loaded file.
|
|
|
|
* @param buffer_length The length of the buffer.
|
|
|
|
* @param img_2d Whether or not the texture is 2D.
|
|
|
|
* @param mipmap Whether or not to generate mipmaps for this texture.
|
|
|
|
*/
|
2022-09-29 01:21:47 +00:00
|
|
|
Texture(const unsigned char *const buffer, int buffer_length, aiTextureType type = aiTextureType::aiTextureType_DIFFUSE, int flags = Texture::default_flags);
|
2021-11-27 18:52:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Construct a new Texture object from the loaded file buffer.
|
|
|
|
*
|
|
|
|
* @param buffer The bytes of the loaded file.
|
|
|
|
* @param img_2d Whether or not the texture is 2D.
|
|
|
|
* @param mipmap Whether or not to generate mipmaps for this texture.
|
|
|
|
*/
|
2022-09-29 01:21:47 +00:00
|
|
|
Texture(std::vector<unsigned char> buffer, aiTextureType type = aiTextureType::aiTextureType_DIFFUSE, int flags = Texture::default_flags);
|
2022-09-22 02:52:06 +00:00
|
|
|
|
|
|
|
static Texture white_texture();
|
2021-11-27 18:52:48 +00:00
|
|
|
|
2021-11-27 19:11:07 +00:00
|
|
|
void bind() const;
|
2022-09-17 23:41:38 +00:00
|
|
|
void unbind() const;
|
2022-08-18 15:34:05 +00:00
|
|
|
|
|
|
|
unsigned int get_texture_id() const;
|
2021-11-27 18:52:48 +00:00
|
|
|
};
|
2021-11-27 19:16:41 +00:00
|
|
|
}
|