Возможность рендера части индексного буфера

This commit is contained in:
Ковалев Роман Евгеньевич 2022-11-14 19:54:10 +03:00 committed by R.E. Kovalev
parent a3e98f8418
commit ce660278a8
2 changed files with 12 additions and 4 deletions

View File

@ -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(GLuint beg, GLuint count); // Ограничение диапазона из буфера индексов
glm::vec3 position; // позиция модели glm::vec3 position; // позиция модели
glm::vec3 rotation; // поворот модели glm::vec3 rotation; // поворот модели
@ -29,7 +30,7 @@ class Model
VBO *vertex_vbo, *index_vbo; // вершинный и индексный VBO *vertex_vbo, *index_vbo; // вершинный и индексный
VBO *normals_vbo, *texCoords_vbo; // буферы с нормалями и текстурными координатами VBO *normals_vbo, *texCoords_vbo; // буферы с нормалями и текстурными координатами
GLuint verteces_count; // Количество вершин GLuint verteces_count; // Количество вершин
GLuint indices_count; // Количество индексов GLuint first_index, indices_count; // Первый и количество индексов
Texture texture_diffuse; // Диффузная текстура Texture texture_diffuse; // Диффузная текстура
}; };

View File

@ -10,7 +10,7 @@ std::map<GLuint, GLuint> vaos_count;
// Конструктор без параметров // Конструктор без параметров
Model::Model() : Model::Model() :
verteces_count(0), indices_count(0), verteces_count(0), first_index(0), indices_count(0),
vertex_vbo(0), index_vbo(0), normals_vbo(0), texCoords_vbo(0), vertex_vbo(0), index_vbo(0), normals_vbo(0), texCoords_vbo(0),
position(0), rotation(0), scale(1) position(0), rotation(0), scale(1)
{ {
@ -23,7 +23,7 @@ position(0), rotation(0), scale(1)
// Конструктор копирования // Конструктор копирования
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(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), 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)
@ -63,7 +63,7 @@ void Model::render(const GLuint &mvp_uniform)
vao->use(); vao->use();
// Если есть индексы - рисуем с их использованием // Если есть индексы - рисуем с их использованием
if (indices_count) if (indices_count)
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) else if (verteces_count)
glDrawArrays(GL_TRIANGLES, 0, verteces_count); glDrawArrays(GL_TRIANGLES, 0, verteces_count);
@ -213,3 +213,10 @@ void Model::set_texture(Texture& texture)
break; break;
}; };
} }
// Ограничение диапазона из буфера индексов
void Model::set_index_range(GLuint beg, GLuint count)
{
first_index = beg;
indices_count = count;
}