From d724b623d1a34de6f4fc7eded3d835c1c2fd614c Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Wed, 22 May 2019 17:56:29 +0200 Subject: [PATCH] - enable the depth buffer - support vid_scalefactor --- .../polyrenderer/backend/poly_framebuffer.cpp | 3 +- .../polyrenderer/backend/poly_renderstate.cpp | 10 ++++-- .../polyrenderer/drawers/poly_triangle.cpp | 35 +++++++++++++++++++ .../polyrenderer/drawers/poly_triangle.h | 13 +++++++ src/win32/win32polyvideo.cpp | 8 ++++- 5 files changed, 65 insertions(+), 4 deletions(-) diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index 0a261462d..513936d3e 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -105,6 +105,7 @@ void PolyFrameBuffer::CheckCanvas() mCanvas.reset(new DCanvas(0, 0, true)); mCanvas->Resize(GetWidth(), GetHeight(), false); + PolyTriangleDrawer::ResizeBuffers(mCanvas.get()); PolyTriangleDrawer::SetViewport(GetDrawCommands(), 0, 0, mCanvas->GetWidth(), mCanvas->GetHeight(), mCanvas.get()); } } @@ -141,7 +142,7 @@ void PolyFrameBuffer::Update() DrawerThreads::WaitForWorkers(); mFrameMemory.Clear(); - if (mCanvas && GetClientWidth() == mCanvas->GetWidth() && GetClientHeight() == mCanvas->GetHeight()) + if (mCanvas) { I_PresentPolyImage(mCanvas->GetWidth(), mCanvas->GetHeight(), mCanvas->GetPixels()); } diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.cpp b/src/rendering/polyrenderer/backend/poly_renderstate.cpp index 527f3e433..60e7a74f9 100644 --- a/src/rendering/polyrenderer/backend/poly_renderstate.cpp +++ b/src/rendering/polyrenderer/backend/poly_renderstate.cpp @@ -66,6 +66,7 @@ bool PolyRenderState::SetDepthClamp(bool on) void PolyRenderState::SetDepthMask(bool on) { + args.SetWriteDepth(on); } void PolyRenderState::SetDepthFunc(int func) @@ -94,6 +95,12 @@ void PolyRenderState::EnableClipDistance(int num, bool state) void PolyRenderState::Clear(int targets) { + //if (targets & CT_Color) + // PolyTriangleDrawer::ClearColor(GetPolyFrameBuffer()->GetDrawCommands()); + if (targets & CT_Depth) + PolyTriangleDrawer::ClearDepth(GetPolyFrameBuffer()->GetDrawCommands(), 0.0f); + if (targets & CT_Stencil) + PolyTriangleDrawer::ClearStencil(GetPolyFrameBuffer()->GetDrawCommands(), 0); } void PolyRenderState::EnableStencil(bool on) @@ -110,6 +117,7 @@ void PolyRenderState::SetViewport(int x, int y, int w, int h) void PolyRenderState::EnableDepthTest(bool on) { + args.SetDepthTest(on); } void PolyRenderState::EnableMultisampling(bool on) @@ -129,9 +137,7 @@ void PolyRenderState::Apply() drawcalls.Clock(); args.SetStencilTest(false); - args.SetDepthTest(false); args.SetWriteStencil(false); - args.SetWriteDepth(false); args.SetNoColormap(); args.SetColor(MAKEARGB( diff --git a/src/rendering/polyrenderer/drawers/poly_triangle.cpp b/src/rendering/polyrenderer/drawers/poly_triangle.cpp index 53676532a..564c0f6f8 100644 --- a/src/rendering/polyrenderer/drawers/poly_triangle.cpp +++ b/src/rendering/polyrenderer/drawers/poly_triangle.cpp @@ -52,6 +52,11 @@ bool PolyTriangleDrawer::IsBgra() return isBgraRenderTarget; } +void PolyTriangleDrawer::ClearDepth(const DrawerCommandQueuePtr &queue, float value) +{ + queue->Push(value); +} + void PolyTriangleDrawer::ClearStencil(const DrawerCommandQueuePtr &queue, uint8_t value) { queue->Push(value); @@ -118,6 +123,25 @@ void PolyTriangleDrawer::DrawElements(const DrawerCommandQueuePtr &queue, const ///////////////////////////////////////////////////////////////////////////// +void PolyTriangleThreadData::ClearDepth(float value) +{ + auto buffer = PolyZBuffer::Instance(); + int width = buffer->Width(); + int height = buffer->Height(); + float *data = buffer->Values(); + + int skip = skipped_by_thread(0); + int count = count_for_thread(0, height); + + data += skip * width; + for (int i = 0; i < count; i++) + { + for (int x = 0; x < width; x++) + data[x] = value; + data += num_cores * width; + } +} + void PolyTriangleThreadData::ClearStencil(uint8_t value) { auto buffer = PolyStencilBuffer::Instance(); @@ -686,6 +710,17 @@ void PolySetModelVertexShaderCommand::Execute(DrawerThread *thread) ///////////////////////////////////////////////////////////////////////////// +PolyClearDepthCommand::PolyClearDepthCommand(float value) : value(value) +{ +} + +void PolyClearDepthCommand::Execute(DrawerThread *thread) +{ + PolyTriangleThreadData::Get(thread)->ClearDepth(value); +} + +///////////////////////////////////////////////////////////////////////////// + PolyClearStencilCommand::PolyClearStencilCommand(uint8_t value) : value(value) { } diff --git a/src/rendering/polyrenderer/drawers/poly_triangle.h b/src/rendering/polyrenderer/drawers/poly_triangle.h index 99a54585e..10b17f067 100644 --- a/src/rendering/polyrenderer/drawers/poly_triangle.h +++ b/src/rendering/polyrenderer/drawers/poly_triangle.h @@ -36,6 +36,7 @@ class PolyTriangleDrawer { public: static void ResizeBuffers(DCanvas *canvas); + static void ClearDepth(const DrawerCommandQueuePtr &queue, float value); static void ClearStencil(const DrawerCommandQueuePtr &queue, uint8_t value); static void SetViewport(const DrawerCommandQueuePtr &queue, int x, int y, int width, int height, DCanvas *canvas); static void SetCullCCW(const DrawerCommandQueuePtr &queue, bool ccw); @@ -53,6 +54,7 @@ class PolyTriangleThreadData public: PolyTriangleThreadData(int32_t core, int32_t num_cores, int32_t numa_node, int32_t num_numa_nodes, int numa_start_y, int numa_end_y) : core(core), num_cores(num_cores), numa_node(numa_node), num_numa_nodes(num_numa_nodes), numa_start_y(numa_start_y), numa_end_y(numa_end_y) { } + void ClearDepth(float value); void ClearStencil(uint8_t value); void SetViewport(int x, int y, int width, int height, uint8_t *dest, int dest_width, int dest_height, int dest_pitch, bool dest_bgra); void SetTransform(const Mat4f *objectToClip, const Mat4f *objectToWorld); @@ -195,6 +197,17 @@ private: float interpolationFactor; }; +class PolyClearDepthCommand : public PolyDrawerCommand +{ +public: + PolyClearDepthCommand(float value); + + void Execute(DrawerThread *thread) override; + +private: + float value; +}; + class PolyClearStencilCommand : public PolyDrawerCommand { public: diff --git a/src/win32/win32polyvideo.cpp b/src/win32/win32polyvideo.cpp index faf6c937a..cb7638fdf 100644 --- a/src/win32/win32polyvideo.cpp +++ b/src/win32/win32polyvideo.cpp @@ -17,7 +17,13 @@ void I_PresentPolyImage(int w, int h, const void *pixels) info.bV5SizeImage = 0; info.bV5CSType = LCS_WINDOWS_COLOR_SPACE; + RECT box = {}; + GetClientRect(Window, &box); + HDC dc = GetDC(Window); - SetDIBitsToDevice(dc, 0, 0, w, h, 0, 0, 0, h, pixels, (const BITMAPINFO *)&info, DIB_RGB_COLORS); + if (box.right == w && box.bottom == h) + SetDIBitsToDevice(dc, 0, 0, w, h, 0, 0, 0, h, pixels, (const BITMAPINFO *)&info, DIB_RGB_COLORS); + else + StretchDIBits(dc, 0, 0, box.right, box.bottom, 0, 0, w, h, pixels, (const BITMAPINFO *)&info, DIB_RGB_COLORS, SRCCOPY); ReleaseDC(Window, dc); }