Move drawing of wield tool into a dedicated step of the pipeline (#13338)

This commit is contained in:
x2048 2023-03-19 21:31:15 +01:00 committed by GitHub
parent 09342c0811
commit 6cd2eea487
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 9 deletions

View File

@ -635,11 +635,14 @@ void Camera::wield(const ItemStack &item)
void Camera::drawWieldedTool(irr::core::matrix4* translation)
{
// Clear Z buffer so that the wielded tool stays in front of world geometry
m_wieldmgr->getVideoDriver()->clearBuffers(video::ECBF_DEPTH);
// Draw the wielded node (in a separate scene manager)
scene::ICameraSceneNode* cam = m_wieldmgr->getActiveCamera();
cam->setAspectRatio(m_cameranode->getAspectRatio());
cam->setFOV(72.0*M_PI/180.0);
cam->setNearValue(40); // give wield tool smaller z-depth than the world in most cases.
cam->setNearValue(10);
cam->setFarValue(1000);
if (translation != NULL)
{

View File

@ -73,19 +73,20 @@ void populateAnaglyphPipeline(RenderPipeline *pipeline, Client *client)
step3D->setRenderTarget(enable_override_material);
// left eye
pipeline->addStep(pipeline->createOwned<OffsetCameraStep>(false));
pipeline->addStep(pipeline->createOwned<SetColorMaskStep>(video::ECP_RED));
pipeline->addStep<OffsetCameraStep>(false);
pipeline->addStep<SetColorMaskStep>(video::ECP_RED);
pipeline->addStep(step3D);
// right eye
pipeline->addStep(pipeline->createOwned<OffsetCameraStep>(true));
pipeline->addStep(pipeline->createOwned<SetColorMaskStep>(video::ECP_GREEN | video::ECP_BLUE));
pipeline->addStep<OffsetCameraStep>(true);
pipeline->addStep<SetColorMaskStep>(video::ECP_GREEN | video::ECP_BLUE);
pipeline->addStep(step3D);
// reset
pipeline->addStep(pipeline->createOwned<OffsetCameraStep>(0.0f));
pipeline->addStep(pipeline->createOwned<SetColorMaskStep>(video::ECP_ALL));
pipeline->addStep<OffsetCameraStep>(0.0f);
pipeline->addStep<SetColorMaskStep>(video::ECP_ALL);
pipeline->addStep(pipeline->createOwned<MapPostFxStep>());
pipeline->addStep(pipeline->createOwned<DrawHUD>());
pipeline->addStep<DrawWield>();
pipeline->addStep<MapPostFxStep>();
pipeline->addStep<DrawHUD>();
}

View File

@ -69,6 +69,7 @@ void populateInterlacedPipeline(RenderPipeline *pipeline, Client *client)
auto output = pipeline->createOwned<TextureBufferOutput>(buffer, right ? TEXTURE_RIGHT : TEXTURE_LEFT);
pipeline->addStep<SetRenderTargetStep>(step3D, output);
pipeline->addStep(step3D);
pipeline->addStep<DrawWield>();
pipeline->addStep<MapPostFxStep>();
}

View File

@ -39,6 +39,13 @@ void Draw3D::run(PipelineContext &context)
return;
context.hud->drawBlockBounds();
context.hud->drawSelectionMesh();
}
void DrawWield::run(PipelineContext &context)
{
if (m_target)
m_target->activate(context);
if (context.draw_wield_tool)
context.client->getCamera()->drawWieldedTool();
}
@ -144,6 +151,7 @@ void populatePlainPipeline(RenderPipeline *pipeline, Client *client)
auto downscale_factor = getDownscaleFactor();
auto step3D = pipeline->own(create3DStage(client, downscale_factor));
pipeline->addStep(step3D);
pipeline->addStep<DrawWield>();
pipeline->addStep<MapPostFxStep>();
step3D = addUpscaling(pipeline, step3D, downscale_factor);

View File

@ -38,6 +38,19 @@ private:
RenderTarget *m_target {nullptr};
};
class DrawWield : public RenderStep
{
public:
virtual void setRenderSource(RenderSource *) override {}
virtual void setRenderTarget(RenderTarget *target) override { m_target = target; }
virtual void reset(PipelineContext &context) override {}
virtual void run(PipelineContext &context) override;
private:
RenderTarget *m_target {nullptr};
};
/**
* Implements a pipeline step that renders the game HUD
*/

View File

@ -73,6 +73,7 @@ void populateSideBySidePipeline(RenderPipeline *pipeline, Client *client, bool h
auto output = pipeline->createOwned<TextureBufferOutput>(buffer, right ? TEXTURE_RIGHT : TEXTURE_LEFT);
pipeline->addStep<SetRenderTargetStep>(step3D, output);
pipeline->addStep(step3D);
pipeline->addStep<DrawWield>();
pipeline->addStep<MapPostFxStep>();
pipeline->addStep<DrawHUD>();
}