Commiting unfinished work.
This commit is contained in:
parent
2a0cb3ca1d
commit
a07a4bbb91
@ -16,12 +16,21 @@ void Chunk::render(SharedShaderProgram shader, bool lightingPass, bool texturePa
|
||||
}
|
||||
}
|
||||
|
||||
void Chunk::enqueueObjects(std::vector<std::vector<Object*>>* renderQueue) {
|
||||
for(unsigned int i = 0; i<objects.size(); i++) {
|
||||
renderQueue->at(objects.at(i)->getMaterial()->getTextureUnit() - 2).push_back(objects.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
void Chunk::addObject(Object* object) {
|
||||
objects.push_back(object);
|
||||
}
|
||||
|
||||
void Chunk::sortObjects(int materialCount) {
|
||||
// init
|
||||
sortedObjects = std::vector<std::vector<Object*>>(materialCount);
|
||||
for(unsigned int i = 0; i<sortedObjects.size(); i++) {
|
||||
sortedObjects.at(i) = std::vector<Object*>();
|
||||
}
|
||||
for(unsigned int i = 0; i<objects.size(); i++){
|
||||
sortedObjects.at(objects.at(i)->getMaterial()->getMaterialId()).push_back(objects.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::vector<Object*>>* Chunk::getSortedObjects() {
|
||||
return &sortedObjects;
|
||||
}
|
||||
|
@ -12,7 +12,9 @@ class Chunk {
|
||||
void render(SharedShaderProgram shader, bool lightingPass, bool texturePass,
|
||||
glm::mat4* viewProjcetionMatrix, std::vector<glm::mat4>* additionalMatrices=0);
|
||||
void addObject(Object* object);
|
||||
void enqueueObjects(std::vector<std::vector<Object*>>* renderQueue);
|
||||
void sortObjects(int textureUnits);
|
||||
std::vector<std::vector<Object*>>* getSortedObjects();
|
||||
private:
|
||||
std::vector<Object*> objects;
|
||||
std::vector<std::vector<Object*>> sortedObjects;
|
||||
};
|
||||
|
@ -198,10 +198,11 @@ void Graphics::init(Level* level) {
|
||||
lightingShader->setUniform("fogColorNight", level->getFogColourNight());
|
||||
lightingShader->setUniform("ambientColor", level->getAmbientLight());
|
||||
|
||||
renderQueue = std::vector<std::vector<Object*>>(Material::getAllTextures()->size());
|
||||
for (unsigned int i = 0; i<renderQueue.size(); i++) {
|
||||
renderQueue.at(i) = std::vector<Object*>();
|
||||
}
|
||||
level->sortObjects(Material::getAllMaterials()->size());
|
||||
#ifdef SAXUM_DEBUG
|
||||
std::cout << "There were " << Material::getAllMaterials()->size()
|
||||
<< " materials used in this level." << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Graphics::bindTextureUnits(){
|
||||
@ -491,23 +492,24 @@ void Graphics::render(double time)
|
||||
|
||||
if (renderWorld) {
|
||||
// render the level
|
||||
level->enqueueObjects(&renderQueue);
|
||||
for (unsigned int i = 0; i<renderQueue.size(); i++) {
|
||||
if (renderQueue.at(i).size() != 0) {
|
||||
Material* material = renderQueue.at(i).at(0)->getMaterial();
|
||||
if (material->isMoving()) {
|
||||
lightingShader->setUniform("movingTexture", true);
|
||||
level->enqueueObjects(this);
|
||||
for (unsigned int i = 0; i<Material::getAllTextures()->size(); i++) {
|
||||
Material* material = &Material::getAllTextures()->at(i);
|
||||
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 k = 0; k<renderQueue.at(j)->at(i).size(); k++) {
|
||||
renderQueue.at(j)->at(i).at(k)->render(lightingShader, true, false, &lightingViewProjectionMatrix, &depthBiasVPs);
|
||||
}
|
||||
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.at(i).size(); j++) {
|
||||
renderQueue.at(i).at(j)->render(lightingShader, true, false, &lightingViewProjectionMatrix, &depthBiasVPs);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -750,3 +752,7 @@ void Graphics::setRenderWorld(bool state) {
|
||||
bool Graphics::getRenderWorld() {
|
||||
return renderWorld;
|
||||
}
|
||||
|
||||
void Graphics::enqueueObjects(std::vector<std::vector<Object*>>* queue){
|
||||
renderQueue.push_back(queue);
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ class Graphics {
|
||||
bool getRenderFlames();
|
||||
bool getRenderDebug();
|
||||
bool getRenderWorld();
|
||||
void enqueueObjects(std::vector<std::vector<Object*>>* queue);
|
||||
private:
|
||||
void bindTextureUnits();
|
||||
void updateLights();
|
||||
@ -88,7 +89,7 @@ class Graphics {
|
||||
SharedArrayBuffer debug_ab;
|
||||
SharedVertexArrayObject debug_vao;
|
||||
SharedShaderProgram debugShader;
|
||||
std::vector<std::vector<Object*>> renderQueue;
|
||||
std::vector<std::vector<std::vector<Object*>>*> renderQueue;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "level.hh"
|
||||
#include "loader.hh"
|
||||
#include <string>
|
||||
#include "graphics.hh"
|
||||
|
||||
Level::Level(std::string xmlFilePath) {
|
||||
// default value
|
||||
@ -101,7 +102,7 @@ void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
|
||||
}
|
||||
}
|
||||
|
||||
void Level::enqueueObjects(std::vector<std::vector<Object*>>* renderQueue) {
|
||||
void Level::enqueueObjects(Graphics* graphics) {
|
||||
int renderDistance = 0;
|
||||
if ((int)farPlane % chunkSize == 0) {
|
||||
renderDistance = (((int)skydomeSize)+chunkSize/2)/chunkSize;
|
||||
@ -129,11 +130,26 @@ void Level::enqueueObjects(std::vector<std::vector<Object*>>* renderQueue) {
|
||||
}
|
||||
for(unsigned int i = xStart; i<=xEnd; i++) {
|
||||
for(unsigned int j = zStart; j<=zEnd; j++) {
|
||||
chunks.at(i).at(j).enqueueObjects(renderQueue);
|
||||
graphics->enqueueObjects(chunks.at(i).at(j).getSortedObjects());
|
||||
}
|
||||
}
|
||||
graphics->enqueueObjects(&sortedCrossChunkObjects);
|
||||
}
|
||||
|
||||
void Level::sortObjects(int materialCount) {
|
||||
for(unsigned int i = 0; i<chunks.size(); i++) {
|
||||
for(unsigned int j = 0; j<chunks.at(i).size(); j++) {
|
||||
chunks.at(i).at(j).sortObjects(materialCount);
|
||||
}
|
||||
}
|
||||
// init
|
||||
sortedCrossChunkObjects = std::vector<std::vector<Object*>>(materialCount);
|
||||
for(unsigned int i = 0; i<sortedCrossChunkObjects.size(); i++) {
|
||||
sortedCrossChunkObjects.at(i) = std::vector<Object*>();
|
||||
}
|
||||
for(unsigned int i = 0; i<crossChunkObjects.size(); i++) {
|
||||
renderQueue->at(crossChunkObjects.at(i)->getMaterial()->getTextureUnit() - 2).push_back(crossChunkObjects.at(i));
|
||||
sortedCrossChunkObjects.at(crossChunkObjects.at(i)->getMaterial()->getMaterialId())
|
||||
.push_back(crossChunkObjects.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,9 @@ extern "C" {
|
||||
}
|
||||
#include "LuaBridge.h"
|
||||
|
||||
// forward declaration
|
||||
class Graphics;
|
||||
|
||||
class Level {
|
||||
public:
|
||||
Level(std::string xmlFilePath);
|
||||
@ -77,10 +80,12 @@ class Level {
|
||||
void generateChunks(int chunkSize);
|
||||
std::vector<std::vector<Chunk>>* getChunks();
|
||||
void addToSpecificChunk(Object* object, int xPosition, int zPosition);
|
||||
void enqueueObjects(std::vector<std::vector<Object*>>* renderQueue);
|
||||
void enqueueObjects(Graphics* graphics);
|
||||
void sortObjects(int materialCount);
|
||||
private:
|
||||
lua_State* luaState=nullptr;
|
||||
std::vector<Object*> crossChunkObjects;
|
||||
std::vector<std::vector<Object*>> sortedCrossChunkObjects;
|
||||
std::vector<Object*> allObjects;
|
||||
std::vector<Object*> physicsObjects;
|
||||
std::vector<std::vector<Chunk>> chunks;
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
std::set<SharedTexture2D> Material::allTexturesSet = std::set<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,
|
||||
float specularFactor, float shininess, bool movingTexture) {
|
||||
@ -14,15 +16,24 @@ Material::Material(std::string filePath, float ambientFactor, float diffuseFacto
|
||||
this->specularFactor = specularFactor;
|
||||
this->shininess = shininess;
|
||||
this->movingTexture = movingTexture;
|
||||
unsigned int count = allTexturesSet.size();
|
||||
unsigned int textureCount = allTexturesSet.size();
|
||||
allTexturesSet.insert(reference);
|
||||
if (allTexturesSet.size() != count) {
|
||||
if (allTexturesSet.size() != textureCount) {
|
||||
allTexturesVector.push_back(reference);
|
||||
}
|
||||
textureUnit = std::distance(Material::getAllTextures()->begin(),
|
||||
std::find(std::begin(*Material::getAllTextures()),
|
||||
// first two texture units are used by the loading screen
|
||||
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() {
|
||||
|
@ -22,10 +22,13 @@ class Material{
|
||||
float getShininess();
|
||||
bool isMoving();
|
||||
static std::vector<SharedTexture2D>* getAllTextures();
|
||||
static std::vector<Material*>* getAllMaterials();
|
||||
int getTextureUnit();
|
||||
int getMaterialId();
|
||||
|
||||
private:
|
||||
int textureUnit;
|
||||
int materialId;
|
||||
ACGL::OpenGL::SharedTexture2D reference;
|
||||
float ambientFactor;
|
||||
float diffuseFactor;
|
||||
@ -34,6 +37,8 @@ class Material{
|
||||
bool movingTexture;
|
||||
static std::set<SharedTexture2D> allTexturesSet;
|
||||
static std::vector<SharedTexture2D> allTexturesVector;
|
||||
static std::set<Material> allMaterialsSet;
|
||||
static std::vector<Material> allMaterialsVector;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user