Finshed work now sorting objects after loading.
This commit is contained in:
parent
a07a4bbb91
commit
1fd6058eaf
@ -20,14 +20,14 @@ void Chunk::addObject(Object* object) {
|
|||||||
objects.push_back(object);
|
objects.push_back(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Chunk::sortObjects(int materialCount) {
|
void Chunk::sortObjects(int textureCount) {
|
||||||
// init
|
// init
|
||||||
sortedObjects = std::vector<std::vector<Object*>>(materialCount);
|
sortedObjects = std::vector<std::vector<Object*>>(textureCount);
|
||||||
for(unsigned int i = 0; i<sortedObjects.size(); i++) {
|
for(unsigned int i = 0; i<sortedObjects.size(); i++) {
|
||||||
sortedObjects.at(i) = std::vector<Object*>();
|
sortedObjects.at(i) = std::vector<Object*>();
|
||||||
}
|
}
|
||||||
for(unsigned int i = 0; i<objects.size(); i++){
|
for(unsigned int i = 0; i<objects.size(); i++){
|
||||||
sortedObjects.at(objects.at(i)->getMaterial()->getMaterialId()).push_back(objects.at(i));
|
sortedObjects.at(objects.at(i)->getMaterial()->getTextureUnit() - 2).push_back(objects.at(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ class Chunk {
|
|||||||
void render(SharedShaderProgram shader, bool lightingPass, bool texturePass,
|
void render(SharedShaderProgram shader, bool lightingPass, bool texturePass,
|
||||||
glm::mat4* viewProjcetionMatrix, std::vector<glm::mat4>* additionalMatrices=0);
|
glm::mat4* viewProjcetionMatrix, std::vector<glm::mat4>* additionalMatrices=0);
|
||||||
void addObject(Object* object);
|
void addObject(Object* object);
|
||||||
void sortObjects(int textureUnits);
|
void sortObjects(int textureCount);
|
||||||
std::vector<std::vector<Object*>>* getSortedObjects();
|
std::vector<std::vector<Object*>>* getSortedObjects();
|
||||||
private:
|
private:
|
||||||
std::vector<Object*> objects;
|
std::vector<Object*> objects;
|
||||||
|
@ -198,9 +198,9 @@ void Graphics::init(Level* level) {
|
|||||||
lightingShader->setUniform("fogColorNight", level->getFogColourNight());
|
lightingShader->setUniform("fogColorNight", level->getFogColourNight());
|
||||||
lightingShader->setUniform("ambientColor", level->getAmbientLight());
|
lightingShader->setUniform("ambientColor", level->getAmbientLight());
|
||||||
|
|
||||||
level->sortObjects(Material::getAllMaterials()->size());
|
level->sortObjects(Material::getAllTextures()->size());
|
||||||
#ifdef SAXUM_DEBUG
|
#ifdef SAXUM_DEBUG
|
||||||
std::cout << "There were " << Material::getAllMaterials()->size()
|
std::cout << "There were " << Material::getAllTextures()->size()
|
||||||
<< " materials used in this level." << std::endl;
|
<< " materials used in this level." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -494,26 +494,32 @@ void Graphics::render(double time)
|
|||||||
// render the level
|
// render the level
|
||||||
level->enqueueObjects(this);
|
level->enqueueObjects(this);
|
||||||
for (unsigned int i = 0; i<Material::getAllTextures()->size(); i++) {
|
for (unsigned int i = 0; i<Material::getAllTextures()->size(); i++) {
|
||||||
Material* material = &Material::getAllTextures()->at(i);
|
bool parametersSet = false;
|
||||||
if (material->isMoving()) {
|
|
||||||
lightingShader->setUniform("movingTexture", true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
lightingShader->setUniform("movingTexture", false);
|
|
||||||
}
|
|
||||||
lightingShader->setUniform("uTexture", material->getTextureUnit());
|
|
||||||
lightingShader->setUniform("ambientFactor", material->getAmbientFactor());
|
|
||||||
lightingShader->setUniform("diffuseFactor", material->getDiffuseFactor());
|
|
||||||
lightingShader->setUniform("specularFactor", material->getSpecularFactor());
|
|
||||||
lightingShader->setUniform("shininess", material->getShininess());
|
|
||||||
for(unsigned int j = 0; j<renderQueue.size(); j++) {
|
for(unsigned int j = 0; j<renderQueue.size(); j++) {
|
||||||
for(unsigned int k = 0; k<renderQueue.at(j)->at(i).size(); k++) {
|
if(renderQueue.at(j)->at(i).size() != 0) {
|
||||||
|
if (!parametersSet) {
|
||||||
|
parametersSet = true;
|
||||||
|
Material* material = renderQueue.at(j)->at(i).at(0)->getMaterial();
|
||||||
|
if (material->isMoving()) {
|
||||||
|
lightingShader->setUniform("movingTexture", true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lightingShader->setUniform("movingTexture", false);
|
||||||
|
}
|
||||||
|
lightingShader->setUniform("uTexture", material->getTextureUnit());
|
||||||
|
lightingShader->setUniform("ambientFactor", material->getAmbientFactor());
|
||||||
|
lightingShader->setUniform("diffuseFactor", material->getDiffuseFactor());
|
||||||
|
lightingShader->setUniform("specularFactor", material->getSpecularFactor());
|
||||||
|
lightingShader->setUniform("shininess", material->getShininess());
|
||||||
|
}
|
||||||
|
for(unsigned int k = 0; k<renderQueue.at(j)->at(i).size(); k++) {
|
||||||
renderQueue.at(j)->at(i).at(k)->render(lightingShader, true, false, &lightingViewProjectionMatrix, &depthBiasVPs);
|
renderQueue.at(j)->at(i).at(k)->render(lightingShader, true, false, &lightingViewProjectionMatrix, &depthBiasVPs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
renderQueue.clear();
|
||||||
|
|
||||||
if (renderDebug) {
|
if (renderDebug) {
|
||||||
debugDrawer.setDebugMode(btIDebugDraw::DBG_DrawWireframe);
|
debugDrawer.setDebugMode(btIDebugDraw::DBG_DrawWireframe);
|
||||||
|
@ -136,19 +136,19 @@ void Level::enqueueObjects(Graphics* graphics) {
|
|||||||
graphics->enqueueObjects(&sortedCrossChunkObjects);
|
graphics->enqueueObjects(&sortedCrossChunkObjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Level::sortObjects(int materialCount) {
|
void Level::sortObjects(int textureCount) {
|
||||||
for(unsigned int i = 0; i<chunks.size(); i++) {
|
for(unsigned int i = 0; i<chunks.size(); i++) {
|
||||||
for(unsigned int j = 0; j<chunks.at(i).size(); j++) {
|
for(unsigned int j = 0; j<chunks.at(i).size(); j++) {
|
||||||
chunks.at(i).at(j).sortObjects(materialCount);
|
chunks.at(i).at(j).sortObjects(textureCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// init
|
// init
|
||||||
sortedCrossChunkObjects = std::vector<std::vector<Object*>>(materialCount);
|
sortedCrossChunkObjects = std::vector<std::vector<Object*>>(textureCount);
|
||||||
for(unsigned int i = 0; i<sortedCrossChunkObjects.size(); i++) {
|
for(unsigned int i = 0; i<sortedCrossChunkObjects.size(); i++) {
|
||||||
sortedCrossChunkObjects.at(i) = std::vector<Object*>();
|
sortedCrossChunkObjects.at(i) = std::vector<Object*>();
|
||||||
}
|
}
|
||||||
for(unsigned int i = 0; i<crossChunkObjects.size(); i++) {
|
for(unsigned int i = 0; i<crossChunkObjects.size(); i++) {
|
||||||
sortedCrossChunkObjects.at(crossChunkObjects.at(i)->getMaterial()->getMaterialId())
|
sortedCrossChunkObjects.at(crossChunkObjects.at(i)->getMaterial()->getTextureUnit() - 2)
|
||||||
.push_back(crossChunkObjects.at(i));
|
.push_back(crossChunkObjects.at(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ class Level {
|
|||||||
std::vector<std::vector<Chunk>>* getChunks();
|
std::vector<std::vector<Chunk>>* getChunks();
|
||||||
void addToSpecificChunk(Object* object, int xPosition, int zPosition);
|
void addToSpecificChunk(Object* object, int xPosition, int zPosition);
|
||||||
void enqueueObjects(Graphics* graphics);
|
void enqueueObjects(Graphics* graphics);
|
||||||
void sortObjects(int materialCount);
|
void sortObjects(int textureCount);
|
||||||
private:
|
private:
|
||||||
lua_State* luaState=nullptr;
|
lua_State* luaState=nullptr;
|
||||||
std::vector<Object*> crossChunkObjects;
|
std::vector<Object*> crossChunkObjects;
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
std::set<SharedTexture2D> Material::allTexturesSet = std::set<SharedTexture2D>();
|
std::set<SharedTexture2D> Material::allTexturesSet = std::set<SharedTexture2D>();
|
||||||
std::vector<SharedTexture2D> Material::allTexturesVector = std::vector<SharedTexture2D>();
|
std::vector<SharedTexture2D> Material::allTexturesVector = std::vector<SharedTexture2D>();
|
||||||
std::set<Material> Material::allMaterialsSet = std::set<Material>();
|
|
||||||
std::vector<Material> Material::allMaterialsVector = std::vector<Material*>();
|
|
||||||
|
|
||||||
Material::Material(std::string filePath, float ambientFactor, float diffuseFactor,
|
Material::Material(std::string filePath, float ambientFactor, float diffuseFactor,
|
||||||
float specularFactor, float shininess, bool movingTexture) {
|
float specularFactor, float shininess, bool movingTexture) {
|
||||||
@ -25,15 +23,6 @@ Material::Material(std::string filePath, float ambientFactor, float diffuseFacto
|
|||||||
std::find(std::begin(*Material::getAllTextures()),
|
std::find(std::begin(*Material::getAllTextures()),
|
||||||
// first two texture units are used by the loading screen
|
// first two texture units are used by the loading screen
|
||||||
std::end(*Material::getAllTextures()), reference)) + 2;
|
std::end(*Material::getAllTextures()), reference)) + 2;
|
||||||
|
|
||||||
unsigned int materialCount = allMaterialsSet.size();
|
|
||||||
allMaterialsSet.insert(*this);
|
|
||||||
if (allMaterialsSet.size() != materialCount) {
|
|
||||||
allMaterialsVector.push_back(*this);
|
|
||||||
}
|
|
||||||
materialId = std::distance(Material::getAllMaterials()->begin(),
|
|
||||||
std::find(std::begin(*Material::getAllMaterials()),
|
|
||||||
std::end(*Material::getAllMaterials()), *this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Material::Material() {
|
Material::Material() {
|
||||||
|
@ -24,11 +24,9 @@ class Material{
|
|||||||
static std::vector<SharedTexture2D>* getAllTextures();
|
static std::vector<SharedTexture2D>* getAllTextures();
|
||||||
static std::vector<Material*>* getAllMaterials();
|
static std::vector<Material*>* getAllMaterials();
|
||||||
int getTextureUnit();
|
int getTextureUnit();
|
||||||
int getMaterialId();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int textureUnit;
|
int textureUnit;
|
||||||
int materialId;
|
|
||||||
ACGL::OpenGL::SharedTexture2D reference;
|
ACGL::OpenGL::SharedTexture2D reference;
|
||||||
float ambientFactor;
|
float ambientFactor;
|
||||||
float diffuseFactor;
|
float diffuseFactor;
|
||||||
@ -37,8 +35,6 @@ class Material{
|
|||||||
bool movingTexture;
|
bool movingTexture;
|
||||||
static std::set<SharedTexture2D> allTexturesSet;
|
static std::set<SharedTexture2D> allTexturesSet;
|
||||||
static std::vector<SharedTexture2D> allTexturesVector;
|
static std::vector<SharedTexture2D> allTexturesVector;
|
||||||
static std::set<Material> allMaterialsSet;
|
|
||||||
static std::vector<Material> allMaterialsVector;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user