world render refactor
This commit is contained in:
parent
dda9c40c41
commit
6c70bb531b
@ -301,7 +301,7 @@ void MenuScreen::draw(float delta) {
|
|||||||
LevelScreen::LevelScreen(Engine* engine, Level* level)
|
LevelScreen::LevelScreen(Engine* engine, Level* level)
|
||||||
: Screen(engine),
|
: Screen(engine),
|
||||||
level(level) {
|
level(level) {
|
||||||
worldRenderer = new WorldRenderer(level, engine->getAssets());
|
worldRenderer = new WorldRenderer(engine, level);
|
||||||
hud = new HudRenderer(engine, level);
|
hud = new HudRenderer(engine, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,11 +351,9 @@ void LevelScreen::update(float delta) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LevelScreen::draw(float delta) {
|
void LevelScreen::draw(float delta) {
|
||||||
EngineSettings& settings = engine->getSettings();
|
|
||||||
Camera* camera = level->player->camera;
|
Camera* camera = level->player->camera;
|
||||||
|
|
||||||
float fogFactor = 18.0f / (float)settings.chunks.loadDistance;
|
worldRenderer->draw(camera, occlusion);
|
||||||
worldRenderer->draw(camera, occlusion, fogFactor, settings.graphics.fogCurve);
|
|
||||||
hud->draw();
|
hud->draw();
|
||||||
if (level->player->debug) {
|
if (level->player->debug) {
|
||||||
hud->drawDebug( 1 / delta, occlusion);
|
hud->drawDebug( 1 / delta, occlusion);
|
||||||
|
|||||||
@ -11,7 +11,6 @@
|
|||||||
#include "../graphics/Shader.h"
|
#include "../graphics/Shader.h"
|
||||||
#include "../graphics/Texture.h"
|
#include "../graphics/Texture.h"
|
||||||
#include "../graphics/LineBatch.h"
|
#include "../graphics/LineBatch.h"
|
||||||
#include "../graphics/Batch3D.h"
|
|
||||||
#include "../voxels/Chunks.h"
|
#include "../voxels/Chunks.h"
|
||||||
#include "../voxels/Chunk.h"
|
#include "../voxels/Chunk.h"
|
||||||
#include "../voxels/Block.h"
|
#include "../voxels/Block.h"
|
||||||
@ -22,13 +21,15 @@
|
|||||||
#include "../assets/Assets.h"
|
#include "../assets/Assets.h"
|
||||||
#include "../objects/player_control.h"
|
#include "../objects/player_control.h"
|
||||||
#include "../maths/FrustumCulling.h"
|
#include "../maths/FrustumCulling.h"
|
||||||
|
#include "../settings.h"
|
||||||
|
#include "../engine.h"
|
||||||
|
|
||||||
using glm::vec3;
|
using glm::vec3;
|
||||||
using std::shared_ptr;
|
using std::shared_ptr;
|
||||||
|
|
||||||
WorldRenderer::WorldRenderer(Level* level, Assets* assets) : assets(assets), level(level) {
|
WorldRenderer::WorldRenderer(Engine* engine, Level* level)
|
||||||
|
: engine(engine), level(level) {
|
||||||
lineBatch = new LineBatch(4096);
|
lineBatch = new LineBatch(4096);
|
||||||
batch3d = new Batch3D(1024);
|
|
||||||
renderer = new ChunksRenderer(level);
|
renderer = new ChunksRenderer(level);
|
||||||
frustumCulling = new Frustum();
|
frustumCulling = new Frustum();
|
||||||
level->events->listen(EVT_CHUNK_HIDDEN, [this](lvl_event_type type, Chunk* chunk) {
|
level->events->listen(EVT_CHUNK_HIDDEN, [this](lvl_event_type type, Chunk* chunk) {
|
||||||
@ -37,7 +38,6 @@ WorldRenderer::WorldRenderer(Level* level, Assets* assets) : assets(assets), lev
|
|||||||
}
|
}
|
||||||
|
|
||||||
WorldRenderer::~WorldRenderer() {
|
WorldRenderer::~WorldRenderer() {
|
||||||
delete batch3d;
|
|
||||||
delete lineBatch;
|
delete lineBatch;
|
||||||
delete renderer;
|
delete renderer;
|
||||||
delete frustumCulling;
|
delete frustumCulling;
|
||||||
@ -65,7 +65,9 @@ bool WorldRenderer::drawChunk(size_t index, Camera* camera, Shader* shader, bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WorldRenderer::draw(Camera* camera, bool occlusion, float fogFactor, float fogCurve){
|
void WorldRenderer::draw(Camera* camera, bool occlusion){
|
||||||
|
EngineSettings& settings = engine->getSettings();
|
||||||
|
Assets* assets = engine->getAssets();
|
||||||
Chunks* chunks = level->chunks;
|
Chunks* chunks = level->chunks;
|
||||||
|
|
||||||
vec3 skyColor(0.7f, 0.81f, 1.0f);
|
vec3 skyColor(0.7f, 0.81f, 1.0f);
|
||||||
@ -77,6 +79,8 @@ void WorldRenderer::draw(Camera* camera, bool occlusion, float fogFactor, float
|
|||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
|
|
||||||
|
float fogFactor = 18.0f / (float)settings.chunks.loadDistance;
|
||||||
|
|
||||||
Texture* texture = assets->getTexture("block");
|
Texture* texture = assets->getTexture("block");
|
||||||
Shader* shader = assets->getShader("main");
|
Shader* shader = assets->getShader("main");
|
||||||
Shader* linesShader = assets->getShader("lines");
|
Shader* linesShader = assets->getShader("lines");
|
||||||
@ -87,7 +91,7 @@ void WorldRenderer::draw(Camera* camera, bool occlusion, float fogFactor, float
|
|||||||
shader->uniform3f("u_skyLightColor", 1.1f,1.1f,1.1f);
|
shader->uniform3f("u_skyLightColor", 1.1f,1.1f,1.1f);
|
||||||
shader->uniform3f("u_fogColor", skyColor);
|
shader->uniform3f("u_fogColor", skyColor);
|
||||||
shader->uniform1f("u_fogFactor", fogFactor);
|
shader->uniform1f("u_fogFactor", fogFactor);
|
||||||
shader->uniform1f("u_fogCurve", fogCurve);
|
shader->uniform1f("u_fogCurve", settings.graphics.fogCurve);
|
||||||
shader->uniform3f("u_cameraPos", camera->position);
|
shader->uniform3f("u_cameraPos", camera->position);
|
||||||
|
|
||||||
Block* cblock = Block::blocks[level->player->choosenBlock];
|
Block* cblock = Block::blocks[level->player->choosenBlock];
|
||||||
@ -124,9 +128,6 @@ void WorldRenderer::draw(Camera* camera, bool occlusion, float fogFactor, float
|
|||||||
}
|
}
|
||||||
|
|
||||||
shader->uniformMatrix("u_model", mat4(1.0f));
|
shader->uniformMatrix("u_model", mat4(1.0f));
|
||||||
batch3d->begin();
|
|
||||||
// draw 3D stuff here
|
|
||||||
batch3d->render();
|
|
||||||
|
|
||||||
if (level->playerController->selectedBlockId != -1){
|
if (level->playerController->selectedBlockId != -1){
|
||||||
Block* selectedBlock = Block::blocks[level->playerController->selectedBlockId];
|
Block* selectedBlock = Block::blocks[level->playerController->selectedBlockId];
|
||||||
@ -142,6 +143,8 @@ void WorldRenderer::draw(Camera* camera, bool occlusion, float fogFactor, float
|
|||||||
lineBatch->render();
|
lineBatch->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
if (level->player->debug) {
|
if (level->player->debug) {
|
||||||
float length = 40.f;
|
float length = 40.f;
|
||||||
|
|
||||||
@ -153,16 +156,13 @@ void WorldRenderer::draw(Camera* camera, bool occlusion, float fogFactor, float
|
|||||||
-(float)Window::height, 0.f,
|
-(float)Window::height, 0.f,
|
||||||
-length, length) * model * glm::inverse(camera->rotation));
|
-length, length) * model * glm::inverse(camera->rotation));
|
||||||
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
lineBatch->lineWidth(4.0f);
|
||||||
|
|
||||||
glLineWidth(4.0f);
|
|
||||||
lineBatch->line(0.f, 0.f, 0.f, length, 0.f, 0.f, 0.f, 0.f, 0.f, 1.f);
|
lineBatch->line(0.f, 0.f, 0.f, length, 0.f, 0.f, 0.f, 0.f, 0.f, 1.f);
|
||||||
lineBatch->line(0.f, 0.f, 0.f, 0.f, length, 0.f, 0.f, 0.f, 0.f, 1.f);
|
lineBatch->line(0.f, 0.f, 0.f, 0.f, length, 0.f, 0.f, 0.f, 0.f, 1.f);
|
||||||
lineBatch->line(0.f, 0.f, 0.f, 0.f, 0.f, length, 0.f, 0.f, 0.f, 1.f);
|
lineBatch->line(0.f, 0.f, 0.f, 0.f, 0.f, length, 0.f, 0.f, 0.f, 1.f);
|
||||||
lineBatch->render();
|
lineBatch->render();
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
|
|
||||||
glLineWidth(2.0f);
|
lineBatch->lineWidth(2.0f);
|
||||||
lineBatch->line(0.f, 0.f, 0.f, length, 0.f, 0.f, 1.f, 0.f, 0.f, 1.f);
|
lineBatch->line(0.f, 0.f, 0.f, length, 0.f, 0.f, 1.f, 0.f, 0.f, 1.f);
|
||||||
lineBatch->line(0.f, 0.f, 0.f, 0.f, length, 0.f, 0.f, 1.f, 0.f, 1.f);
|
lineBatch->line(0.f, 0.f, 0.f, 0.f, length, 0.f, 0.f, 1.f, 0.f, 1.f);
|
||||||
lineBatch->line(0.f, 0.f, 0.f, 0.f, 0.f, length, 0.f, 0.f, 1.f, 1.f);
|
lineBatch->line(0.f, 0.f, 0.f, 0.f, 0.f, length, 0.f, 0.f, 1.f, 1.f);
|
||||||
|
|||||||
@ -10,32 +10,28 @@
|
|||||||
#include <glm/ext.hpp>
|
#include <glm/ext.hpp>
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
|
||||||
class World;
|
|
||||||
class Level;
|
class Level;
|
||||||
class Camera;
|
class Camera;
|
||||||
class Assets;
|
|
||||||
class LineBatch;
|
class LineBatch;
|
||||||
class Batch3D;
|
|
||||||
class ChunksRenderer;
|
class ChunksRenderer;
|
||||||
class Shader;
|
class Shader;
|
||||||
class Texture;
|
class Texture;
|
||||||
class Framebuffer;
|
|
||||||
class Frustum;
|
class Frustum;
|
||||||
|
class Engine;
|
||||||
|
|
||||||
class WorldRenderer {
|
class WorldRenderer {
|
||||||
Batch3D* batch3d;
|
Engine* engine;
|
||||||
Assets* assets;
|
|
||||||
Level* level;
|
Level* level;
|
||||||
Frustum* frustumCulling;
|
Frustum* frustumCulling;
|
||||||
|
LineBatch* lineBatch;
|
||||||
|
ChunksRenderer* renderer;
|
||||||
bool drawChunk(size_t index, Camera* camera, Shader* shader, bool occlusion);
|
bool drawChunk(size_t index, Camera* camera, Shader* shader, bool occlusion);
|
||||||
public:
|
public:
|
||||||
ChunksRenderer* renderer;
|
|
||||||
LineBatch* lineBatch;
|
|
||||||
|
|
||||||
WorldRenderer(Level* level, Assets* assets);
|
WorldRenderer(Engine* engine, Level* level);
|
||||||
~WorldRenderer();
|
~WorldRenderer();
|
||||||
|
|
||||||
void draw(Camera* camera, bool occlusion, float fogFactor, float fogCurve);
|
void draw(Camera* camera, bool occlusion);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,3 @@
|
|||||||
/*
|
|
||||||
* LineBatch.cpp
|
|
||||||
*
|
|
||||||
* Created on: Jun 25, 2020
|
|
||||||
* Author: MihailRis
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "LineBatch.h"
|
#include "LineBatch.h"
|
||||||
#include "Mesh.h"
|
#include "Mesh.h"
|
||||||
|
|
||||||
@ -67,7 +60,6 @@ void LineBatch::box(float x, float y, float z, float w, float h, float d,
|
|||||||
line(x+w, y+h, z-d, x+w, y+h, z+d, r,g,b,a);
|
line(x+w, y+h, z-d, x+w, y+h, z+d, r,g,b,a);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
void LineBatch::render(){
|
void LineBatch::render(){
|
||||||
if (index == 0)
|
if (index == 0)
|
||||||
return;
|
return;
|
||||||
@ -75,3 +67,7 @@ void LineBatch::render(){
|
|||||||
mesh->draw(GL_LINES);
|
mesh->draw(GL_LINES);
|
||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LineBatch::lineWidth(float width) {
|
||||||
|
glLineWidth(width);
|
||||||
|
}
|
||||||
@ -1,10 +1,3 @@
|
|||||||
/*
|
|
||||||
* LineBatch.h
|
|
||||||
*
|
|
||||||
* Created on: Jun 25, 2020
|
|
||||||
* Author: MihailRis
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef GRAPHICS_LINEBATCH_H_
|
#ifndef GRAPHICS_LINEBATCH_H_
|
||||||
#define GRAPHICS_LINEBATCH_H_
|
#define GRAPHICS_LINEBATCH_H_
|
||||||
|
|
||||||
@ -27,6 +20,7 @@ public:
|
|||||||
float r, float g, float b, float a);
|
float r, float g, float b, float a);
|
||||||
|
|
||||||
void render();
|
void render();
|
||||||
|
void lineWidth(float width);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* GRAPHICS_LINEBATCH_H_ */
|
#endif /* GRAPHICS_LINEBATCH_H_ */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user