Возможность рендера части индексного буфера
This commit is contained in:
parent
61d61c04f5
commit
30753723ba
@ -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
|
|||||||
BO vertex_vbo, index_vbo; // вершинный и индексный буферы
|
BO vertex_vbo, index_vbo; // вершинный и индексный буферы
|
||||||
BO normals_vbo, texCoords_vbo; // буферы с нормалями и текстурными координатами
|
BO normals_vbo, texCoords_vbo; // буферы с нормалями и текстурными координатами
|
||||||
GLuint verteces_count; // Количество вершин
|
GLuint verteces_count; // Количество вершин
|
||||||
GLuint indices_count; // Количество индексов
|
GLuint first_index, 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(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(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)
|
||||||
@ -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*sizeof(GLuint)));
|
||||||
}
|
}
|
||||||
// Если есть вершины - рисуем на основании массива вершин
|
// Если есть вершины - рисуем на основании массива вершин
|
||||||
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(GLuint beg, GLuint count)
|
||||||
|
{
|
||||||
|
first_index = beg;
|
||||||
|
indices_count = count;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user