diff --git a/include/Model.h b/include/Model.h index 23fbe0d..2219e29 100644 --- a/include/Model.h +++ b/include/Model.h @@ -18,6 +18,7 @@ class Model void load_texCoords(glm::vec2* texCoords, GLuint count); // Загрузка текстурных координат в буфер void load_normals(glm::vec3* normals, GLuint count); // Загрузка нормалей в буфер void set_texture(Texture& texture); // Привязка текстуры к модели + void set_index_range(GLuint beg, GLuint count); // Ограничение диапазона из буфера индексов glm::vec3 position; // позиция модели glm::vec3 rotation; // поворот модели @@ -29,7 +30,7 @@ class Model BO vertex_vbo, index_vbo; // вершинный и индексный буферы BO normals_vbo, texCoords_vbo; // буферы с нормалями и текстурными координатами GLuint verteces_count; // Количество вершин - GLuint indices_count; // Количество индексов + GLuint first_index, indices_count; // Первый и количество индексов Texture texture_diffuse; // Диффузная текстура }; diff --git a/src/Model.cpp b/src/Model.cpp index 0fb4522..8cff3a2 100644 --- a/src/Model.cpp +++ b/src/Model.cpp @@ -3,7 +3,9 @@ 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(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) : vao(copy.vao), -verteces_count(copy.verteces_count), indices_count(copy.indices_count), +verteces_count(copy.verteces_count), first_index(copy.first_index), 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), texture_diffuse(copy.texture_diffuse), position(copy.position), rotation(copy.rotation), scale(copy.scale) @@ -40,7 +42,7 @@ void Model::render(const GLuint &mvp_uniform) if (indices_count) { index_vbo.use(); - glDrawElements(GL_TRIANGLES, indices_count, GL_UNSIGNED_INT, (void*)0); + glDrawElements(GL_TRIANGLES, indices_count, GL_UNSIGNED_INT, (void*)(first_index*sizeof(GLuint))); } // Если есть вершины - рисуем на основании массива вершин else if (verteces_count) @@ -174,3 +176,10 @@ void Model::set_texture(Texture& texture) break; }; } + +// Ограничение диапазона из буфера индексов +void Model::set_index_range(GLuint beg, GLuint count) +{ + first_index = beg; + indices_count = count; +}