Возможность рендера части индексного буфера
This commit is contained in:
		
							parent
							
								
									61d61c04f5
								
							
						
					
					
						commit
						062b5e28d7
					
				| @ -18,6 +18,7 @@ class Model | |||||||
|         void load_texCoords(glm::vec2* texCoords, GLuint count); // Загрузка текстурных координат в буфер
 |         void load_texCoords(glm::vec2* texCoords, GLuint count); // Загрузка текстурных координат в буфер
 | ||||||
|         void load_normals(glm::vec3* normals, GLuint count); // Загрузка нормалей в буфер
 |         void load_normals(glm::vec3* normals, GLuint count); // Загрузка нормалей в буфер
 | ||||||
|         void set_texture(Texture& texture); // Привязка текстуры к модели
 |         void set_texture(Texture& texture); // Привязка текстуры к модели
 | ||||||
|  |         void set_index_range(size_t first_byteOffset, size_t count); // Ограничение диапазона из буфера индексов
 | ||||||
| 
 | 
 | ||||||
|         glm::vec3 position; // позиция модели
 |         glm::vec3 position; // позиция модели
 | ||||||
|         glm::vec3 rotation; // поворот модели
 |         glm::vec3 rotation; // поворот модели
 | ||||||
| @ -28,8 +29,8 @@ class Model | |||||||
|         VAO vao; |         VAO vao; | ||||||
|         BO vertex_vbo, index_vbo; // вершинный и индексный буферы
 |         BO vertex_vbo, index_vbo; // вершинный и индексный буферы
 | ||||||
|         BO normals_vbo, texCoords_vbo; // буферы с нормалями и текстурными координатами
 |         BO normals_vbo, texCoords_vbo; // буферы с нормалями и текстурными координатами
 | ||||||
|         GLuint verteces_count; // Количество вершин
 |         size_t verteces_count; // Количество вершин
 | ||||||
|         GLuint indices_count; // Количество индексов
 |         size_t first_index_byteOffset, indices_count; // Сдвиг в байтах для первого и количество индексов
 | ||||||
|         Texture texture_diffuse; // Диффузная текстура
 |         Texture texture_diffuse; // Диффузная текстура
 | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -3,7 +3,9 @@ | |||||||
| extern Camera camera; | extern Camera camera; | ||||||
| 
 | 
 | ||||||
| // Конструктор без параметров
 | // Конструктор без параметров
 | ||||||
| Model::Model() : verteces_count(0), indices_count(0), vertex_vbo(VERTEX), index_vbo(ELEMENT), normals_vbo(VERTEX), texCoords_vbo(VERTEX), position(0), rotation(0), scale(1) | Model::Model() : verteces_count(0), first_index_byteOffset(0), indices_count(0),  | ||||||
|  | vertex_vbo(VERTEX), index_vbo(ELEMENT), normals_vbo(VERTEX), texCoords_vbo(VERTEX),  | ||||||
|  | position(0), rotation(0), scale(1) | ||||||
| { | { | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
| @ -11,7 +13,7 @@ Model::Model() : verteces_count(0), indices_count(0), vertex_vbo(VERTEX), index_ | |||||||
| // Конструктор копирования
 | // Конструктор копирования
 | ||||||
| Model::Model(const Model& copy) :  | Model::Model(const Model& copy) :  | ||||||
| vao(copy.vao),  | vao(copy.vao),  | ||||||
| verteces_count(copy.verteces_count), indices_count(copy.indices_count),  | verteces_count(copy.verteces_count), first_index_byteOffset(copy.first_index_byteOffset), indices_count(copy.indices_count),  | ||||||
| vertex_vbo(copy.vertex_vbo), index_vbo(copy.index_vbo), normals_vbo(copy.normals_vbo), texCoords_vbo(copy.texCoords_vbo),  | vertex_vbo(copy.vertex_vbo), index_vbo(copy.index_vbo), normals_vbo(copy.normals_vbo), texCoords_vbo(copy.texCoords_vbo),  | ||||||
| texture_diffuse(copy.texture_diffuse),  | texture_diffuse(copy.texture_diffuse),  | ||||||
| position(copy.position), rotation(copy.rotation), scale(copy.scale) | position(copy.position), rotation(copy.rotation), scale(copy.scale) | ||||||
| @ -40,7 +42,7 @@ void Model::render(const GLuint &mvp_uniform) | |||||||
|     if (indices_count) |     if (indices_count) | ||||||
|     { |     { | ||||||
|         index_vbo.use(); |         index_vbo.use(); | ||||||
|         glDrawElements(GL_TRIANGLES, indices_count, GL_UNSIGNED_INT, (void*)0); |         glDrawElements(GL_TRIANGLES, indices_count, GL_UNSIGNED_INT, (void*)(first_index_byteOffset)); | ||||||
|     } |     } | ||||||
|     // Если есть вершины - рисуем на основании массива вершин
 |     // Если есть вершины - рисуем на основании массива вершин
 | ||||||
|     else if (verteces_count) |     else if (verteces_count) | ||||||
| @ -174,3 +176,10 @@ void Model::set_texture(Texture& texture) | |||||||
|             break; |             break; | ||||||
|     }; |     }; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | // Ограничение диапазона из буфера индексов
 | ||||||
|  | void Model::set_index_range(size_t first_byteOffset, size_t count) | ||||||
|  | { | ||||||
|  |     first_index_byteOffset = first_byteOffset; | ||||||
|  |     indices_count = count; | ||||||
|  | }  | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user