diff --git a/include/Texture.h b/include/Texture.h index e76b15f..e64599c 100644 --- a/include/Texture.h +++ b/include/Texture.h @@ -17,6 +17,7 @@ class Texture { 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(); @@ -25,6 +26,7 @@ class Texture void use(); // Привязка текстуры static void disable(GLuint type); // Отвязка текстуры по типу GLuint getType(); // Возвращает тип текстуры + void setType(GLuint type); // Задает тип текстуры private: GLuint handler; // Дескриптор текстуры GLuint type; // Тип текстуры, соответствует её слоту diff --git a/src/Texture.cpp b/src/Texture.cpp index 9384658..e08ecb8 100644 --- a/src/Texture.cpp +++ b/src/Texture.cpp @@ -59,6 +59,23 @@ Texture::Texture(GLuint t, const std::string& filename) : type(t) handler_count[handler]++; } +// Конструктор текстуры заданного размера для использования в буфере +Texture::Texture(GLuint width, GLuint height, GLuint attachment, GLuint texType, GLint internalformat, GLint format, GLenum dataType) : type(texType) +{ + // Генерация текстуры заданного размера + glGenTextures(1, &handler); + glBindTexture(GL_TEXTURE_2D, handler); + glTexImage2D(GL_TEXTURE_2D, 0, internalformat, width, height, 0, format, dataType, NULL); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + // Привязка к буферу кадра + glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, handler, 0); + + // Создаем счетчик использований дескриптора + handler_count[handler] = 1; +} + // Конструктор копирования Texture::Texture(const Texture& other) : handler(other.handler), type(other.type) { @@ -117,3 +134,9 @@ GLuint Texture::getType() { return type; } + +// Задает тип текстуры +void Texture::setType(GLuint type) +{ + this->type = type; +}