- hook up software renderer

This commit is contained in:
Magnus Norddahl 2019-07-24 22:13:00 +02:00
parent 9da46d0e0a
commit ec82f994f7
3 changed files with 47 additions and 30 deletions

View file

@ -17,7 +17,7 @@ class PolyFrameBuffer : public SystemBaseFrameBuffer
public: public:
RenderMemory *GetFrameMemory() { return &mFrameMemory; } RenderMemory *GetFrameMemory() { return &mFrameMemory; }
PolyRenderState *GetRenderState() { return mRenderState.get(); } PolyRenderState *GetRenderState() { return mRenderState.get(); }
DCanvas *GetCanvas() { return mCanvas.get(); } DCanvas *GetCanvas() override { return mCanvas.get(); }
PolyDepthStencil *GetDepthStencil() { return mDepthStencil.get(); } PolyDepthStencil *GetDepthStencil() { return mDepthStencil.get(); }
const DrawerCommandQueuePtr &GetDrawCommands(); const DrawerCommandQueuePtr &GetDrawCommands();
void FlushDrawCommands(); void FlushDrawCommands();
@ -31,6 +31,8 @@ public:
void Update(); void Update();
bool IsPoly() override { return true; }
void InitializeState() override; void InitializeState() override;
void CleanForRestart() override; void CleanForRestart() override;

View file

@ -86,41 +86,53 @@ SWSceneDrawer::~SWSceneDrawer()
sector_t *SWSceneDrawer::RenderView(player_t *player) sector_t *SWSceneDrawer::RenderView(player_t *player)
{ {
// Avoid using the pixel buffer from the last frame if (!screen->IsPoly())
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())
{ {
// This manually constructs its own material here. // Avoid using the pixel buffer from the last frame
fbtex.reset(); FBTextureIndex = (FBTextureIndex + 1) % 2;
fbtex.reset(new FWrapperTexture(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor())); auto &fbtex = FBTexture[FBTextureIndex];
fbtex->GetSystemTexture()->AllocateBuffer(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor() ? 4 : 1);
auto mat = FMaterial::ValidateTexture(fbtex.get(), false);
mat->AddTextureLayer(PaletteTexture);
Canvas.reset(); if (fbtex == nullptr || fbtex->GetSystemTexture() == nullptr ||
Canvas.reset(new DCanvas(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor())); 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();
});
} }
else
IHardwareTexture *systemTexture = fbtex->GetSystemTexture(); {
auto buf = systemTexture->MapBuffer(); DCanvas *canvas = screen->GetCanvas();
if (!buf) I_FatalError("Unable to map buffer for software rendering"); SWRenderer->RenderView(player, canvas, canvas->GetPixels(), canvas->GetPitch());
SWRenderer->RenderView(player, Canvas.get(), buf, systemTexture->GetBufferPitch()); // To do: apply swrenderer::CameraLight::Instance()->ShaderColormap();
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(); SWRenderer->DrawRemainingPlayerSprites();
screen->Draw2D(); screen->Draw2D();
screen->Clear2D(); screen->Clear2D();
}); }
return r_viewpoint.sector; return r_viewpoint.sector;
} }

View file

@ -394,6 +394,9 @@ public:
virtual ~DFrameBuffer(); virtual ~DFrameBuffer();
virtual void InitializeState() = 0; // For stuff that needs 'screen' set. virtual void InitializeState() = 0; // For stuff that needs 'screen' set.
virtual bool IsVulkan() { return false; } virtual bool IsVulkan() { return false; }
virtual bool IsPoly() { return false; }
virtual DCanvas* GetCanvas() { return nullptr; }
void SetSize(int width, int height); void SetSize(int width, int height);
void SetVirtualSize(int width, int height) void SetVirtualSize(int width, int height)