From d6c8e222055e7ad387e60b443d00ec3a6bdb1296 Mon Sep 17 00:00:00 2001 From: "re.kovalev" Date: Wed, 23 Nov 2022 14:23:44 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A2=D0=B5=D0=BA=D1=81=D1=82=D1=83=D1=80?= =?UTF-8?q?=D0=B0=20=D0=B4=D0=BB=D1=8F=20=D0=B1=D1=83=D1=84=D0=B5=D1=80?= =?UTF-8?q?=D0=B0=20=D0=BA=D0=B0=D0=B4=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/Texture.h | 2 ++ src/Texture.cpp | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) 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; +}