refactor WorldRenderer

This commit is contained in:
MihailRis 2024-11-14 06:13:53 +03:00
parent f9f4d2037f
commit e9163f4228
6 changed files with 19 additions and 17 deletions

View File

@ -216,15 +216,20 @@ void WorldRenderer::renderLevel(
const Camera& camera, const Camera& camera,
const EngineSettings& settings, const EngineSettings& settings,
float delta, 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(); bool culling = engine->getSettings().graphics.frustumCulling.get();
float fogFactor = float fogFactor =
15.0f / static_cast<float>(settings.chunks.loadDistance.get() - 2); 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); setupWorldShader(entityShader, camera, settings, fogFactor);
skybox->bind(); skybox->bind();
@ -238,7 +243,7 @@ void WorldRenderer::renderLevel(
particles->render(camera, delta * !pause); particles->render(camera, delta * !pause);
modelBatch->render(); modelBatch->render();
auto& shader = assets->require<Shader>("main"); auto& shader = assets.require<Shader>("main");
setupWorldShader(shader, camera, settings, fogFactor); setupWorldShader(shader, camera, settings, fogFactor);
drawChunks(level->chunks.get(), camera, shader); drawChunks(level->chunks.get(), camera, shader);
@ -389,15 +394,11 @@ void WorldRenderer::draw(
// Drawing background sky plane // Drawing background sky plane
skybox->draw(pctx, camera, assets, worldInfo.daytime, worldInfo.fog); skybox->draw(pctx, camera, assets, worldInfo.daytime, worldInfo.fog);
/* Actually world render with depth buffer on */ { /* Actually world render with depth buffer on */ {
DrawContext ctx = wctx.sub(); DrawContext ctx = wctx.sub();
ctx.setDepthTest(true); ctx.setDepthTest(true);
ctx.setCullFace(true); ctx.setCullFace(true);
texts->renderTexts( renderLevel(ctx, camera, settings, delta, pause, hudVisible);
*batch3d, ctx, assets, camera, settings, hudVisible, false
);
renderLevel(ctx, camera, settings, delta, pause);
// Debug lines // Debug lines
if (hudVisible) { if (hudVisible) {
if (player->debug) { if (player->debug) {

View File

@ -112,7 +112,8 @@ public:
const Camera& camera, const Camera& camera,
const EngineSettings& settings, const EngineSettings& settings,
float delta, float delta,
bool pause bool pause,
bool hudVisible
); );
void clear(); void clear();

View File

@ -550,7 +550,7 @@ void Entities::renderDebug(
} }
void Entities::render( void Entities::render(
Assets* assets, const Assets& assets,
ModelBatch& batch, ModelBatch& batch,
const Frustum* frustum, const Frustum* frustum,
float delta, float delta,

View File

@ -194,7 +194,7 @@ public:
LineBatch& batch, const Frustum* frustum, const DrawContext& ctx LineBatch& batch, const Frustum* frustum, const DrawContext& ctx
); );
void render( void render(
Assets* assets, const Assets& assets,
ModelBatch& batch, ModelBatch& batch,
const Frustum* frustum, const Frustum* frustum,
float delta, float delta,

View File

@ -12,9 +12,9 @@
using namespace rigging; using namespace rigging;
void ModelReference::refresh(const Assets* assets) { void ModelReference::refresh(const Assets& assets) {
if (updateFlag) { if (updateFlag) {
model = assets->get<model::Model>(name); model = assets.get<model::Model>(name);
updateFlag = false; updateFlag = false;
} }
} }
@ -95,7 +95,7 @@ void SkeletonConfig::update(Skeleton& skeleton, glm::mat4 matrix) const {
} }
void SkeletonConfig::render( void SkeletonConfig::render(
Assets* assets, const Assets& assets,
ModelBatch& batch, ModelBatch& batch,
Skeleton& skeleton, Skeleton& skeleton,
const glm::mat4& matrix const glm::mat4& matrix

View File

@ -32,7 +32,7 @@ namespace rigging {
model::Model* model; model::Model* model;
bool updateFlag; bool updateFlag;
void refresh(const Assets* assets); void refresh(const Assets& assets);
}; };
class Bone { class Bone {
@ -111,7 +111,7 @@ namespace rigging {
void update(Skeleton& skeleton, glm::mat4 matrix) const; void update(Skeleton& skeleton, glm::mat4 matrix) const;
void render( void render(
Assets* assets, const Assets& assets,
ModelBatch& batch, ModelBatch& batch,
Skeleton& skeleton, Skeleton& skeleton,
const glm::mat4& matrix const glm::mat4& matrix