mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-12-02 08:52:12 +00:00
- hook up software renderer
This commit is contained in:
parent
9da46d0e0a
commit
ec82f994f7
3 changed files with 47 additions and 30 deletions
|
@ -17,7 +17,7 @@ class PolyFrameBuffer : public SystemBaseFrameBuffer
|
|||
public:
|
||||
RenderMemory *GetFrameMemory() { return &mFrameMemory; }
|
||||
PolyRenderState *GetRenderState() { return mRenderState.get(); }
|
||||
DCanvas *GetCanvas() { return mCanvas.get(); }
|
||||
DCanvas *GetCanvas() override { return mCanvas.get(); }
|
||||
PolyDepthStencil *GetDepthStencil() { return mDepthStencil.get(); }
|
||||
const DrawerCommandQueuePtr &GetDrawCommands();
|
||||
void FlushDrawCommands();
|
||||
|
@ -31,6 +31,8 @@ public:
|
|||
|
||||
void Update();
|
||||
|
||||
bool IsPoly() override { return true; }
|
||||
|
||||
void InitializeState() override;
|
||||
|
||||
void CleanForRestart() override;
|
||||
|
|
|
@ -86,41 +86,53 @@ SWSceneDrawer::~SWSceneDrawer()
|
|||
|
||||
sector_t *SWSceneDrawer::RenderView(player_t *player)
|
||||
{
|
||||
// Avoid using the pixel buffer from the last frame
|
||||
FBTextureIndex = (FBTextureIndex + 1) % 2;
|
||||
auto &fbtex = FBTexture[FBTextureIndex];
|
||||
|
||||
if (fbtex == nullptr || fbtex->GetSystemTexture() == nullptr ||
|
||||
fbtex->GetDisplayWidth() != screen->GetWidth() ||
|
||||
fbtex->GetDisplayHeight() != screen->GetHeight() ||
|
||||
(V_IsTrueColor() ? 1:0) != fbtex->GetColorFormat())
|
||||
if (!screen->IsPoly())
|
||||
{
|
||||
// This manually constructs its own material here.
|
||||
fbtex.reset();
|
||||
fbtex.reset(new FWrapperTexture(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor()));
|
||||
fbtex->GetSystemTexture()->AllocateBuffer(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor() ? 4 : 1);
|
||||
auto mat = FMaterial::ValidateTexture(fbtex.get(), false);
|
||||
mat->AddTextureLayer(PaletteTexture);
|
||||
// Avoid using the pixel buffer from the last frame
|
||||
FBTextureIndex = (FBTextureIndex + 1) % 2;
|
||||
auto &fbtex = FBTexture[FBTextureIndex];
|
||||
|
||||
Canvas.reset();
|
||||
Canvas.reset(new DCanvas(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor()));
|
||||
if (fbtex == nullptr || fbtex->GetSystemTexture() == nullptr ||
|
||||
fbtex->GetDisplayWidth() != screen->GetWidth() ||
|
||||
fbtex->GetDisplayHeight() != screen->GetHeight() ||
|
||||
(V_IsTrueColor() ? 1:0) != fbtex->GetColorFormat())
|
||||
{
|
||||
// This manually constructs its own material here.
|
||||
fbtex.reset();
|
||||
fbtex.reset(new FWrapperTexture(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor()));
|
||||
fbtex->GetSystemTexture()->AllocateBuffer(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor() ? 4 : 1);
|
||||
auto mat = FMaterial::ValidateTexture(fbtex.get(), false);
|
||||
mat->AddTextureLayer(PaletteTexture);
|
||||
|
||||
Canvas.reset();
|
||||
Canvas.reset(new DCanvas(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor()));
|
||||
}
|
||||
|
||||
IHardwareTexture *systemTexture = fbtex->GetSystemTexture();
|
||||
auto buf = systemTexture->MapBuffer();
|
||||
if (!buf) I_FatalError("Unable to map buffer for software rendering");
|
||||
SWRenderer->RenderView(player, Canvas.get(), buf, systemTexture->GetBufferPitch());
|
||||
systemTexture->CreateTexture(nullptr, screen->GetWidth(), screen->GetHeight(), 0, false, 0, "swbuffer");
|
||||
|
||||
auto map = swrenderer::CameraLight::Instance()->ShaderColormap();
|
||||
screen->DrawTexture(fbtex.get(), 0, 0, DTA_SpecialColormap, map, TAG_DONE);
|
||||
screen->Draw2D();
|
||||
screen->Clear2D();
|
||||
screen->PostProcessScene(CM_DEFAULT, [&]() {
|
||||
SWRenderer->DrawRemainingPlayerSprites();
|
||||
screen->Draw2D();
|
||||
screen->Clear2D();
|
||||
});
|
||||
}
|
||||
|
||||
IHardwareTexture *systemTexture = fbtex->GetSystemTexture();
|
||||
auto buf = systemTexture->MapBuffer();
|
||||
if (!buf) I_FatalError("Unable to map buffer for software rendering");
|
||||
SWRenderer->RenderView(player, Canvas.get(), buf, systemTexture->GetBufferPitch());
|
||||
systemTexture->CreateTexture(nullptr, screen->GetWidth(), screen->GetHeight(), 0, false, 0, "swbuffer");
|
||||
|
||||
auto map = swrenderer::CameraLight::Instance()->ShaderColormap();
|
||||
screen->DrawTexture(fbtex.get(), 0, 0, DTA_SpecialColormap, map, TAG_DONE);
|
||||
screen->Draw2D();
|
||||
screen->Clear2D();
|
||||
screen->PostProcessScene(CM_DEFAULT, [&]() {
|
||||
else
|
||||
{
|
||||
DCanvas *canvas = screen->GetCanvas();
|
||||
SWRenderer->RenderView(player, canvas, canvas->GetPixels(), canvas->GetPitch());
|
||||
// To do: apply swrenderer::CameraLight::Instance()->ShaderColormap();
|
||||
SWRenderer->DrawRemainingPlayerSprites();
|
||||
screen->Draw2D();
|
||||
screen->Clear2D();
|
||||
});
|
||||
}
|
||||
|
||||
return r_viewpoint.sector;
|
||||
}
|
||||
|
|
|
@ -394,6 +394,9 @@ public:
|
|||
virtual ~DFrameBuffer();
|
||||
virtual void InitializeState() = 0; // For stuff that needs 'screen' set.
|
||||
virtual bool IsVulkan() { return false; }
|
||||
virtual bool IsPoly() { return false; }
|
||||
|
||||
virtual DCanvas* GetCanvas() { return nullptr; }
|
||||
|
||||
void SetSize(int width, int height);
|
||||
void SetVirtualSize(int width, int height)
|
||||
|
|
Loading…
Reference in a new issue