Skip to content

Commit

Permalink
refactor WorldRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Nov 14, 2024
1 parent f9f4d20 commit e9163f4
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
19 changes: 10 additions & 9 deletions src/graphics/render/WorldRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,20 @@ void WorldRenderer::renderLevel(
const Camera& camera,
const EngineSettings& settings,
float delta,
bool pause
bool pause,
bool hudVisible
) {
auto assets = engine->getAssets();
const auto& assets = *engine->getAssets();

texts->renderTexts(
*batch3d, ctx, assets, camera, settings, hudVisible, false
);

bool culling = engine->getSettings().graphics.frustumCulling.get();
float fogFactor =
15.0f / static_cast<float>(settings.chunks.loadDistance.get() - 2);

auto& entityShader = assets->require<Shader>("entity");
auto& entityShader = assets.require<Shader>("entity");
setupWorldShader(entityShader, camera, settings, fogFactor);
skybox->bind();

Expand All @@ -238,7 +243,7 @@ void WorldRenderer::renderLevel(
particles->render(camera, delta * !pause);
modelBatch->render();

auto& shader = assets->require<Shader>("main");
auto& shader = assets.require<Shader>("main");
setupWorldShader(shader, camera, settings, fogFactor);

drawChunks(level->chunks.get(), camera, shader);
Expand Down Expand Up @@ -388,16 +393,12 @@ void WorldRenderer::draw(

// Drawing background sky plane
skybox->draw(pctx, camera, assets, worldInfo.daytime, worldInfo.fog);


/* Actually world render with depth buffer on */ {
DrawContext ctx = wctx.sub();
ctx.setDepthTest(true);
ctx.setCullFace(true);
texts->renderTexts(
*batch3d, ctx, assets, camera, settings, hudVisible, false
);
renderLevel(ctx, camera, settings, delta, pause);
renderLevel(ctx, camera, settings, delta, pause, hudVisible);
// Debug lines
if (hudVisible) {
if (player->debug) {
Expand Down
3 changes: 2 additions & 1 deletion src/graphics/render/WorldRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ class WorldRenderer {
const Camera& camera,
const EngineSettings& settings,
float delta,
bool pause
bool pause,
bool hudVisible
);

void clear();
Expand Down
2 changes: 1 addition & 1 deletion src/objects/Entities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ void Entities::renderDebug(
}

void Entities::render(
Assets* assets,
const Assets& assets,
ModelBatch& batch,
const Frustum* frustum,
float delta,
Expand Down
2 changes: 1 addition & 1 deletion src/objects/Entities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class Entities {
LineBatch& batch, const Frustum* frustum, const DrawContext& ctx
);
void render(
Assets* assets,
const Assets& assets,
ModelBatch& batch,
const Frustum* frustum,
float delta,
Expand Down
6 changes: 3 additions & 3 deletions src/objects/rigging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

using namespace rigging;

void ModelReference::refresh(const Assets* assets) {
void ModelReference::refresh(const Assets& assets) {
if (updateFlag) {
model = assets->get<model::Model>(name);
model = assets.get<model::Model>(name);
updateFlag = false;
}
}
Expand Down Expand Up @@ -95,7 +95,7 @@ void SkeletonConfig::update(Skeleton& skeleton, glm::mat4 matrix) const {
}

void SkeletonConfig::render(
Assets* assets,
const Assets& assets,
ModelBatch& batch,
Skeleton& skeleton,
const glm::mat4& matrix
Expand Down
4 changes: 2 additions & 2 deletions src/objects/rigging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace rigging {
model::Model* model;
bool updateFlag;

void refresh(const Assets* assets);
void refresh(const Assets& assets);
};

class Bone {
Expand Down Expand Up @@ -111,7 +111,7 @@ namespace rigging {

void update(Skeleton& skeleton, glm::mat4 matrix) const;
void render(
Assets* assets,
const Assets& assets,
ModelBatch& batch,
Skeleton& skeleton,
const glm::mat4& matrix
Expand Down

0 comments on commit e9163f4

Please sign in to comment.