2022-12-20 13:46:38 +00:00
# ifndef TEXTURE_H
# define TEXTURE_H
# include <glad/glad.h>
# include <map>
# include <string>
enum TexType {
TEX_DIFFUSE ,
TEX_AMBIENT ,
TEX_SPECULAR ,
TEX_AVAILABLE_COUNT
} ;
2023-10-31 10:16:35 +00:00
// Абстрактный класс базовой текстуры
class BaseTexture
{
public :
~ BaseTexture ( ) ;
virtual void use ( ) = 0 ; // Привязка текстуры
static void disable ( GLuint type ) ; // Отвязка текстуры по типу
GLuint getType ( ) ; // Возвращает тип текстуры
void setType ( GLuint type ) ; // Задает тип текстуры
protected :
GLuint handler ; // Дескриптор текстуры
GLuint type ; // Тип текстуры, соответствует её слоту
static std : : map < std : : string , int > filename_handler ; // Получение дескриптора текстуры по её имени
static std : : map < int , int > handler_count ; // Получение количества использований по дескриптору текстуры (Shared pointer)
} ;
// Класс 2D текстуры
class Texture : public BaseTexture
2022-12-20 13:46:38 +00:00
{
public :
Texture ( GLuint type = TEX_AVAILABLE_COUNT , const std : : string & filename = " " ) ; // Загрузка текстуры с диска или использование "пустой"
Texture ( GLuint width , GLuint height , GLuint attachment , GLuint texType = TEX_DIFFUSE , GLint internalformat = GL_RGBA , GLint format = GL_RGBA , GLenum dataType = GL_FLOAT ) ; // Конструктор текстуры заданного размера для использования в буфере
Texture ( const Texture & other ) ; // Конструктор копирования
Texture & operator = ( const Texture & other ) ; // Оператор присваивания
void reallocate ( GLuint width , GLuint height , GLuint texType = TEX_DIFFUSE , GLint internalformat = GL_RGBA , GLint format = GL_RGBA , GLenum dataType = GL_FLOAT ) ; // Пересоздает текстуру для имеющегося дескриптора
2023-10-31 10:16:35 +00:00
virtual void use ( ) ; // Привязка текстуры
2022-12-20 13:46:38 +00:00
} ;
2023-10-31 10:19:47 +00:00
// Класс 3D текстуры
class TextureArray : public BaseTexture
{
public :
TextureArray ( GLuint levels , GLuint width , GLuint height , GLuint attachment , GLuint texType = TEX_DIFFUSE , GLint internalformat = GL_RGBA , GLint format = GL_RGBA , GLenum dataType = GL_FLOAT ) ; // Конструктор текстуры заданного размера для использования в буфере
TextureArray ( const TextureArray & other ) ; // Конструктор копирования
TextureArray & operator = ( const TextureArray & other ) ; // Оператор присваивания
void reallocate ( GLuint levels , GLuint width , GLuint height , GLuint texType = TEX_DIFFUSE , GLint internalformat = GL_RGBA , GLint format = GL_RGBA , GLenum dataType = GL_FLOAT ) ; // Пересоздает текстуру для имеющегося дескриптора
virtual void use ( ) ; // Привязка текстуры
} ;
2022-12-20 13:46:38 +00:00
# endif // TEXTURE_H