Класс 3D кубической текстуры

This commit is contained in:
parent c7097e78d5
commit 6ab8e166bc
2 changed files with 64 additions and 0 deletions

View File

@ -67,4 +67,16 @@ class TextureCube : public BaseTexture
virtual void use(); // Привязка текстуры
};
// Класс 3D кубической текстуры
class TextureCubeArray : public BaseTexture
{
public:
TextureCubeArray(GLuint levels, GLuint width, GLuint height, GLuint attachment, GLuint texType = TEX_DIFFUSE, GLint internalformat = GL_RGBA, GLint format = GL_RGBA, GLenum dataType = GL_FLOAT); // Конструктор текстуры заданного размера для использования в буфере
TextureCubeArray(const TextureCubeArray& other); // Конструктор копирования
TextureCubeArray& operator=(const TextureCubeArray& other); // Оператор присваивания
virtual void use(); // Привязка текстуры
};
#endif // TEXTURE_H

View File

@ -305,3 +305,55 @@ void TextureCube::use()
glActiveTexture(type + GL_TEXTURE0);
glBindTexture(GL_TEXTURE_CUBE_MAP, handler); // Привязка текстуры как активной
}
// Конструктор текстуры заданного размера для использования в буфере
TextureCubeArray::TextureCubeArray(GLuint levels, GLuint width, GLuint height, GLuint attachment, GLuint texType, GLint internalformat, GLint format, GLenum dataType)
{
type = texType;
// Генерация текстуры заданного размера
glGenTextures(1, &handler);
glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, handler);
glTexImage3D(
GL_TEXTURE_CUBE_MAP_ARRAY, 0, internalformat, width, height, 6*levels, 0, format, dataType, 0);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
// Привязка к буферу кадра
glFramebufferTexture(GL_FRAMEBUFFER, attachment, handler, 0);
// Создаем счетчик использований дескриптора
handler_count[handler] = 1;
}
// Конструктор копирования
TextureCubeArray::TextureCubeArray(const TextureCubeArray& other)
{
handler = other.handler;
type = other.type;
// Делаем копию и увеличиваем счетчик
handler_count[handler]++;
}
// Оператор присваивания
TextureCubeArray& TextureCubeArray::operator=(const TextureCubeArray& other)
{
// Если это разные текстуры
if (handler != other.handler)
{
this->~TextureCubeArray(); // Уничтожаем имеющуюся
// Заменяем новой
handler = other.handler;
handler_count[handler]++;
}
type = other.type;
return *this;
}
// Привязка текстуры
void TextureCubeArray::use()
{
glActiveTexture(type + GL_TEXTURE0);
glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, handler); // Привязка текстуры как активной
}