2015-03-16 15:58:50 +00:00
|
|
|
#include "chunk.hh"
|
|
|
|
|
|
|
|
Chunk::Chunk() {
|
|
|
|
}
|
|
|
|
|
|
|
|
Chunk::~Chunk() {
|
|
|
|
for(unsigned int i = 0; i<objects.size(); i++) {
|
|
|
|
delete objects.at(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-12 19:06:59 +00:00
|
|
|
void Chunk::render(SharedShaderProgram shader, bool lightingPass,
|
2015-03-16 15:58:50 +00:00
|
|
|
glm::mat4* viewProjcetionMatrix, std::vector<glm::mat4>* additionalMatrices) {
|
|
|
|
for(unsigned int i = 0; i<objects.size(); i++) {
|
2015-04-12 19:06:59 +00:00
|
|
|
objects.at(i)->render(shader, lightingPass, viewProjcetionMatrix, additionalMatrices);
|
2015-03-16 15:58:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-21 14:05:22 +00:00
|
|
|
void Chunk::addObject(Object* object) {
|
|
|
|
objects.push_back(object);
|
|
|
|
}
|
|
|
|
|
2015-03-21 17:44:08 +00:00
|
|
|
void Chunk::sortObjects(int textureCount) {
|
2015-03-21 14:05:22 +00:00
|
|
|
// init
|
2015-03-21 17:44:08 +00:00
|
|
|
sortedObjects = std::vector<std::vector<Object*>>(textureCount);
|
2015-03-21 14:05:22 +00:00
|
|
|
for(unsigned int i = 0; i<sortedObjects.size(); i++) {
|
|
|
|
sortedObjects.at(i) = std::vector<Object*>();
|
|
|
|
}
|
|
|
|
for(unsigned int i = 0; i<objects.size(); i++){
|
2015-03-21 17:44:08 +00:00
|
|
|
sortedObjects.at(objects.at(i)->getMaterial()->getTextureUnit() - 2).push_back(objects.at(i));
|
2015-03-20 22:45:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-21 14:05:22 +00:00
|
|
|
std::vector<std::vector<Object*>>* Chunk::getSortedObjects() {
|
|
|
|
return &sortedObjects;
|
2015-03-16 15:58:50 +00:00
|
|
|
}
|