Возможность рендера части индексного буфера
This commit is contained in:
parent
a3e98f8418
commit
ce660278a8
@ -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
|
||||
VBO *vertex_vbo, *index_vbo; // вершинный и индексный
|
||||
VBO *normals_vbo, *texCoords_vbo; // буферы с нормалями и текстурными координатами
|
||||
GLuint verteces_count; // Количество вершин
|
||||
GLuint indices_count; // Количество индексов
|
||||
GLuint first_index, indices_count; // Первый и количество индексов
|
||||
Texture texture_diffuse; // Диффузная текстура
|
||||
};
|
||||
|
||||
|
@ -10,7 +10,7 @@ std::map<GLuint, GLuint> vaos_count;
|
||||
|
||||
// Конструктор без параметров
|
||||
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),
|
||||
position(0), rotation(0), scale(1)
|
||||
{
|
||||
@ -23,7 +23,7 @@ position(0), rotation(0), scale(1)
|
||||
// Конструктор копирования
|
||||
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)
|
||||
@ -63,7 +63,7 @@ void Model::render(const GLuint &mvp_uniform)
|
||||
vao->use();
|
||||
// Если есть индексы - рисуем с их использованием
|
||||
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)
|
||||
glDrawArrays(GL_TRIANGLES, 0, verteces_count);
|
||||
@ -213,3 +213,10 @@ void Model::set_texture(Texture& texture)
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
// Ограничение диапазона из буфера индексов
|
||||
void Model::set_index_range(GLuint beg, GLuint count)
|
||||
{
|
||||
first_index = beg;
|
||||
indices_count = count;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user