Класс 3D текстуры
This commit is contained in:
		
							parent
							
								
									9c42edaac2
								
							
						
					
					
						commit
						8b2c87f329
					
				| @ -42,4 +42,16 @@ class Texture : public BaseTexture | ||||
|         virtual void use(); // Привязка текстуры       
 | ||||
| }; | ||||
| 
 | ||||
| // Класс 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); // Оператор присваивания
 | ||||
| 
 | ||||
|         virtual void use(); // Привязка текстуры       
 | ||||
| }; | ||||
| 
 | ||||
| #endif // TEXTURE_H
 | ||||
|  | ||||
| @ -144,3 +144,55 @@ void BaseTexture::setType(GLuint type) | ||||
| { | ||||
|     this->type = type; | ||||
| } | ||||
| 
 | ||||
| // Конструктор текстуры заданного размера для использования в буфере
 | ||||
| TextureArray::TextureArray(GLuint levels, GLuint width, GLuint height, GLuint attachment, GLuint texType, GLint internalformat, GLint format, GLenum dataType) | ||||
| { | ||||
|     type = texType; | ||||
|     // Генерация текстуры заданного размера
 | ||||
|     glGenTextures(1, &handler); | ||||
|     glBindTexture(GL_TEXTURE_2D_ARRAY, handler); | ||||
|     glTexImage3D( | ||||
|         GL_TEXTURE_2D_ARRAY, 0, internalformat, width, height, levels, 0, format, dataType, 0); | ||||
| 
 | ||||
|     glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | ||||
|     glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | ||||
| 
 | ||||
|     // Привязка к буферу кадра
 | ||||
|     glFramebufferTexture(GL_FRAMEBUFFER, attachment, handler, 0); | ||||
| 
 | ||||
|     // Создаем счетчик использований дескриптора
 | ||||
|     handler_count[handler] = 1; | ||||
| } | ||||
| 
 | ||||
| // Конструктор копирования
 | ||||
| TextureArray::TextureArray(const TextureArray& other) | ||||
| { | ||||
|     handler = other.handler;  | ||||
|     type = other.type; | ||||
|     // Делаем копию и увеличиваем счетчик
 | ||||
|     handler_count[handler]++; | ||||
| } | ||||
| 
 | ||||
| // Оператор присваивания
 | ||||
| TextureArray& TextureArray::operator=(const TextureArray& other) | ||||
| { | ||||
|     // Если это разные текстуры
 | ||||
|     if (handler != other.handler) | ||||
|     { | ||||
|         this->~TextureArray(); // Уничтожаем имеющуюся
 | ||||
|         // Заменяем новой
 | ||||
|         handler = other.handler; | ||||
|         handler_count[handler]++; | ||||
|     } | ||||
|     type = other.type; | ||||
| 
 | ||||
|     return *this; | ||||
| } | ||||
| 
 | ||||
| // Привязка текстуры
 | ||||
| void TextureArray::use() | ||||
| { | ||||
|     glActiveTexture(type + GL_TEXTURE0); | ||||
|     glBindTexture(GL_TEXTURE_2D_ARRAY, handler); // Привязка текстуры как активной
 | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user