- Fix playersprite offset being wrong in softpoly

- Remove DFrameBuffer::GetCanvas as it always returned null
This commit is contained in:
Magnus Norddahl 2018-04-08 15:49:06 +02:00
parent 4a730f6dd5
commit c4768441b4
7 changed files with 24 additions and 16 deletions

View file

@ -89,7 +89,7 @@ void PolyRenderer::RenderViewToCanvas(AActor *actor, DCanvas *canvas, int x, int
Threads.MainThread()->FlushDrawQueue();
DrawerThreads::WaitForWorkers();
RenderTarget = screen->GetCanvas();
RenderTarget = nullptr;
RenderToCanvas = false;
R_ExecuteSetViewSize(Viewpoint, Viewwindow);
float trueratio;

View file

@ -218,6 +218,11 @@ void RenderPolyPlayerSprites::RenderSprite(PolyRenderThread *thread, DPSprite *p
const auto &viewwindow = PolyRenderer::Instance()->Viewwindow;
DCanvas *renderTarget = PolyRenderer::Instance()->RenderTarget;
// Force it to use software rendering.
// To do: Fix that Draw2D() is never called by SWSceneDrawer::RenderView. Make sure to adjust the similar comment in r_playersprite.cpp
bool renderToCanvas = true;
//bool renderToCanvas = PolyRenderer::Instance()->RenderToCanvas;
sprframe = &SpriteFrames[sprdef->spriteframes + pspr->GetFrame()];
picnum = sprframe->Texture[0];
@ -288,16 +293,14 @@ void RenderPolyPlayerSprites::RenderSprite(PolyRenderThread *thread, DPSprite *p
vis.texturemid = (BASEYCENTER - sy) * tex->Scale.Y + tex->GetTopOffsetPo();
auto screencanvas = screen->GetCanvas();
if (viewpoint.camera->player && (renderTarget != screencanvas ||
if (viewpoint.camera->player && (renderToCanvas ||
viewheight == renderTarget->GetHeight() ||
(renderTarget->GetWidth() > (BASEXCENTER * 2))))
{ // Adjust PSprite for fullscreen views
AWeapon *weapon = dyn_cast<AWeapon>(pspr->GetCaller());
if (weapon != nullptr && weapon->YAdjust != 0)
{
if (renderTarget != screencanvas || viewheight == renderTarget->GetHeight())
if (renderToCanvas || viewheight == renderTarget->GetHeight())
{
vis.texturemid -= weapon->YAdjust;
}
@ -412,7 +415,7 @@ void RenderPolyPlayerSprites::RenderSprite(PolyRenderThread *thread, DPSprite *p
// Check for hardware-assisted 2D. If it's available, and this sprite is not
// fuzzy, don't draw it until after the switch to 2D mode.
if (!noaccel && renderTarget == screencanvas)
if (!noaccel && !renderToCanvas)
{
FRenderStyle style = vis.RenderStyle;
style.CheckFuzz();
@ -500,7 +503,7 @@ void PolyNoAccelPlayerSprite::Render(PolyRenderThread *thread)
y1 = centerY - texturemid * yscale;
y2 = y1 + pic->GetHeight() * yscale;
}
args.Draw(thread, x1, x2, y1, y2, 0.0f, 1.0f, 0.0f, 1.0f);
args.Draw(thread, viewwindowx + x1, viewwindowx + x2, viewwindowy + y1, viewwindowy + y2, 0.0f, 1.0f, 0.0f, 1.0f);
}
/////////////////////////////////////////////////////////////////////////////

View file

@ -91,6 +91,7 @@ namespace swrenderer
{
auto viewport = MainThread()->Viewport.get();
viewport->RenderTarget = target;
viewport->RenderingToCanvas = false;
int width = SCREENWIDTH;
int height = SCREENHEIGHT;
@ -339,6 +340,7 @@ namespace swrenderer
viewwidth = width;
viewport->RenderTarget = canvas;
viewport->RenderingToCanvas = true;
R_SetWindow(MainThread()->Viewport->viewpoint, MainThread()->Viewport->viewwindow, 12, width, height, height, true);
viewwindowx = x;
@ -351,7 +353,8 @@ namespace swrenderer
DrawerThreads::WaitForWorkers();
DrawerWaitCycles.Unclock();
viewport->RenderTarget = screen->GetCanvas();
viewport->RenderTarget = nullptr;
viewport->RenderingToCanvas = false;
R_ExecuteSetViewSize(MainThread()->Viewport->viewpoint, MainThread()->Viewport->viewwindow);
float trueratio;

View file

@ -289,15 +289,19 @@ namespace swrenderer
vis.texturemid = (BASEYCENTER - sy) * tex->Scale.Y + tex->GetTopOffset(0);
auto screencanvas = screen->GetCanvas();
if (Thread->Viewport->viewpoint.camera->player && (viewport->RenderTarget != screencanvas ||
// Force it to use software rendering.
// To do: Fix that Draw2D() is never called by SWSceneDrawer::RenderView. Also make sure to adjust the similar comment in poly_playersprite.cpp
bool renderToCanvas = true;
//bool renderToCanvas = viewport->RenderingToCanvas;
if (Thread->Viewport->viewpoint.camera->player && (renderToCanvas ||
viewheight == viewport->RenderTarget->GetHeight() ||
(viewport->RenderTarget->GetWidth() > (BASEXCENTER * 2))))
{ // Adjust PSprite for fullscreen views
AWeapon *weapon = dyn_cast<AWeapon>(pspr->GetCaller());
if (weapon != nullptr && weapon->YAdjust != 0)
{
if (viewport->RenderTarget != screencanvas || viewheight == viewport->RenderTarget->GetHeight())
if (renderToCanvas || viewheight == viewport->RenderTarget->GetHeight())
{
vis.texturemid -= weapon->YAdjust;
}
@ -414,7 +418,7 @@ namespace swrenderer
// Check for hardware-assisted 2D. If it's available, and this sprite is not
// fuzzy, don't draw it until after the switch to 2D mode.
if (!noaccel && viewport->RenderTarget == screencanvas)
if (!noaccel && !renderToCanvas)
{
FRenderStyle style = vis.RenderStyle;
style.CheckFuzz();

View file

@ -74,7 +74,7 @@ namespace swrenderer
{
int virtheight, virtwidth, virtwidth2, virtheight2;
if (!RenderingToCanvas())
if (!RenderingToCanvas)
{ // Set r_viewsize cvar to reflect the current view size
UCVarValue value;
char temp[16];

View file

@ -27,6 +27,7 @@ namespace swrenderer
TriMatrix WorldToClip;
DCanvas *RenderTarget = nullptr;
bool RenderingToCanvas = false;
FViewWindow viewwindow;
FRenderViewpoint viewpoint;
@ -52,8 +53,6 @@ namespace swrenderer
uint8_t *GetDest(int x, int y);
bool RenderingToCanvas() const { return RenderTarget != screen->GetCanvas(); }
DVector3 PointWorldToView(const DVector3 &worldPos) const;
DVector3 PointWorldToScreen(const DVector3 &worldPos) const;
DVector3 PointViewToScreen(const DVector3 &viewPos) const;

View file

@ -309,7 +309,6 @@ public:
inline int GetWidth() const { return Width; }
inline int GetHeight() const { return Height; }
virtual DCanvas *GetCanvas() { return nullptr; }
// Make the surface visible.
virtual void Update () = 0;