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) {
|
void Chunk::addObject(Object* object) {
|
||||||
objects.push_back(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,
|
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 enqueueObjects(std::vector<std::vector<Object*>>* renderQueue);
|
void sortObjects(int textureUnits);
|
||||||
|
std::vector<std::vector<Object*>>* getSortedObjects();
|
||||||
private:
|
private:
|
||||||
std::vector<Object*> objects;
|
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("fogColorNight", level->getFogColourNight());
|
||||||
lightingShader->setUniform("ambientColor", level->getAmbientLight());
|
lightingShader->setUniform("ambientColor", level->getAmbientLight());
|
||||||
|
|
||||||
renderQueue = std::vector<std::vector<Object*>>(Material::getAllTextures()->size());
|
level->sortObjects(Material::getAllMaterials()->size());
|
||||||
for (unsigned int i = 0; i<renderQueue.size(); i++) {
|
#ifdef SAXUM_DEBUG
|
||||||
renderQueue.at(i) = std::vector<Object*>();
|
std::cout << "There were " << Material::getAllMaterials()->size()
|
||||||
}
|
<< " materials used in this level." << std::endl;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::bindTextureUnits(){
|
void Graphics::bindTextureUnits(){
|
||||||
@ -491,23 +492,24 @@ void Graphics::render(double time)
|
|||||||
|
|
||||||
if (renderWorld) {
|
if (renderWorld) {
|
||||||
// render the level
|
// render the level
|
||||||
level->enqueueObjects(&renderQueue);
|
level->enqueueObjects(this);
|
||||||
for (unsigned int i = 0; i<renderQueue.size(); i++) {
|
for (unsigned int i = 0; i<Material::getAllTextures()->size(); i++) {
|
||||||
if (renderQueue.at(i).size() != 0) {
|
Material* material = &Material::getAllTextures()->at(i);
|
||||||
Material* material = renderQueue.at(i).at(0)->getMaterial();
|
if (material->isMoving()) {
|
||||||
if (material->isMoving()) {
|
lightingShader->setUniform("movingTexture", true);
|
||||||
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() {
|
bool Graphics::getRenderWorld() {
|
||||||
return renderWorld;
|
return renderWorld;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Graphics::enqueueObjects(std::vector<std::vector<Object*>>* queue){
|
||||||
|
renderQueue.push_back(queue);
|
||||||
|
}
|
||||||
|
@ -33,6 +33,7 @@ class Graphics {
|
|||||||
bool getRenderFlames();
|
bool getRenderFlames();
|
||||||
bool getRenderDebug();
|
bool getRenderDebug();
|
||||||
bool getRenderWorld();
|
bool getRenderWorld();
|
||||||
|
void enqueueObjects(std::vector<std::vector<Object*>>* queue);
|
||||||
private:
|
private:
|
||||||
void bindTextureUnits();
|
void bindTextureUnits();
|
||||||
void updateLights();
|
void updateLights();
|
||||||
@ -88,7 +89,7 @@ class Graphics {
|
|||||||
SharedArrayBuffer debug_ab;
|
SharedArrayBuffer debug_ab;
|
||||||
SharedVertexArrayObject debug_vao;
|
SharedVertexArrayObject debug_vao;
|
||||||
SharedShaderProgram debugShader;
|
SharedShaderProgram debugShader;
|
||||||
std::vector<std::vector<Object*>> renderQueue;
|
std::vector<std::vector<std::vector<Object*>>*> renderQueue;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "level.hh"
|
#include "level.hh"
|
||||||
#include "loader.hh"
|
#include "loader.hh"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "graphics.hh"
|
||||||
|
|
||||||
Level::Level(std::string xmlFilePath) {
|
Level::Level(std::string xmlFilePath) {
|
||||||
// default value
|
// 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;
|
int renderDistance = 0;
|
||||||
if ((int)farPlane % chunkSize == 0) {
|
if ((int)farPlane % chunkSize == 0) {
|
||||||
renderDistance = (((int)skydomeSize)+chunkSize/2)/chunkSize;
|
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 i = xStart; i<=xEnd; i++) {
|
||||||
for(unsigned int j = zStart; j<=zEnd; j++) {
|
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++) {
|
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"
|
#include "LuaBridge.h"
|
||||||
|
|
||||||
|
// forward declaration
|
||||||
|
class Graphics;
|
||||||
|
|
||||||
class Level {
|
class Level {
|
||||||
public:
|
public:
|
||||||
Level(std::string xmlFilePath);
|
Level(std::string xmlFilePath);
|
||||||
@ -77,10 +80,12 @@ class Level {
|
|||||||
void generateChunks(int chunkSize);
|
void generateChunks(int chunkSize);
|
||||||
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(std::vector<std::vector<Object*>>* renderQueue);
|
void enqueueObjects(Graphics* graphics);
|
||||||
|
void sortObjects(int materialCount);
|
||||||
private:
|
private:
|
||||||
lua_State* luaState=nullptr;
|
lua_State* luaState=nullptr;
|
||||||
std::vector<Object*> crossChunkObjects;
|
std::vector<Object*> crossChunkObjects;
|
||||||
|
std::vector<std::vector<Object*>> sortedCrossChunkObjects;
|
||||||
std::vector<Object*> allObjects;
|
std::vector<Object*> allObjects;
|
||||||
std::vector<Object*> physicsObjects;
|
std::vector<Object*> physicsObjects;
|
||||||
std::vector<std::vector<Chunk>> chunks;
|
std::vector<std::vector<Chunk>> chunks;
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
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) {
|
||||||
@ -14,15 +16,24 @@ Material::Material(std::string filePath, float ambientFactor, float diffuseFacto
|
|||||||
this->specularFactor = specularFactor;
|
this->specularFactor = specularFactor;
|
||||||
this->shininess = shininess;
|
this->shininess = shininess;
|
||||||
this->movingTexture = movingTexture;
|
this->movingTexture = movingTexture;
|
||||||
unsigned int count = allTexturesSet.size();
|
unsigned int textureCount = allTexturesSet.size();
|
||||||
allTexturesSet.insert(reference);
|
allTexturesSet.insert(reference);
|
||||||
if (allTexturesSet.size() != count) {
|
if (allTexturesSet.size() != textureCount) {
|
||||||
allTexturesVector.push_back(reference);
|
allTexturesVector.push_back(reference);
|
||||||
}
|
}
|
||||||
textureUnit = std::distance(Material::getAllTextures()->begin(),
|
textureUnit = std::distance(Material::getAllTextures()->begin(),
|
||||||
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() {
|
||||||
|
@ -22,10 +22,13 @@ class Material{
|
|||||||
float getShininess();
|
float getShininess();
|
||||||
bool isMoving();
|
bool isMoving();
|
||||||
static std::vector<SharedTexture2D>* getAllTextures();
|
static std::vector<SharedTexture2D>* getAllTextures();
|
||||||
|
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;
|
||||||
@ -34,6 +37,8 @@ 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