- fix null drawers

- slightly better renderstyle drawer selection
This commit is contained in:
Magnus Norddahl 2019-05-22 21:23:10 +02:00
parent d724b623d1
commit 0cb3605c70
5 changed files with 32 additions and 10 deletions

View file

@ -17,6 +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(); }
const DrawerCommandQueuePtr &GetDrawCommands(); const DrawerCommandQueuePtr &GetDrawCommands();
void FlushDrawCommands(); void FlushDrawCommands();

View file

@ -13,6 +13,7 @@
#include "hwrenderer/data/flatvertices.h" #include "hwrenderer/data/flatvertices.h"
#include "hwrenderer/data/hw_viewpointbuffer.h" #include "hwrenderer/data/hw_viewpointbuffer.h"
#include "hwrenderer/data/shaderuniforms.h" #include "hwrenderer/data/shaderuniforms.h"
#include "swrenderer/r_swcolormaps.h"
static PolyDrawMode dtToDrawMode[] = static PolyDrawMode dtToDrawMode[] =
{ {
@ -79,6 +80,7 @@ void PolyRenderState::SetDepthRange(float min, float max)
void PolyRenderState::SetColorMask(bool r, bool g, bool b, bool a) void PolyRenderState::SetColorMask(bool r, bool g, bool b, bool a)
{ {
args.SetWriteColor(r || g || b || a);
} }
void PolyRenderState::SetStencil(int offs, int op, int flags) void PolyRenderState::SetStencil(int offs, int op, int flags)
@ -113,6 +115,8 @@ void PolyRenderState::SetScissor(int x, int y, int w, int h)
void PolyRenderState::SetViewport(int x, int y, int w, int h) void PolyRenderState::SetViewport(int x, int y, int w, int h)
{ {
auto fb = GetPolyFrameBuffer();
PolyTriangleDrawer::SetViewport(fb->GetDrawCommands(), x, y, w, h, fb->GetCanvas());
} }
void PolyRenderState::EnableDepthTest(bool on) void PolyRenderState::EnableDepthTest(bool on)
@ -138,7 +142,10 @@ void PolyRenderState::Apply()
args.SetStencilTest(false); args.SetStencilTest(false);
args.SetWriteStencil(false); args.SetWriteStencil(false);
args.SetNoColormap();
FColormap cm;
cm.Clear();
args.SetLight(GetColorTable(cm), (int)(mLightParms[3] * 255.0f), mViewpointUniforms->mGlobVis, true);
args.SetColor(MAKEARGB( args.SetColor(MAKEARGB(
static_cast<uint32_t>(mStreamData.uVertexColor.W * 255.0f + 0.5f), static_cast<uint32_t>(mStreamData.uVertexColor.W * 255.0f + 0.5f),
@ -153,6 +160,14 @@ void PolyRenderState::Apply()
{ {
DCanvas *texcanvas = base->GetImage(mMaterial); DCanvas *texcanvas = base->GetImage(mMaterial);
args.SetTexture(texcanvas->GetPixels(), texcanvas->GetHeight(), texcanvas->GetWidth()); args.SetTexture(texcanvas->GetPixels(), texcanvas->GetHeight(), texcanvas->GetWidth());
if (mRenderStyle == LegacyRenderStyles[STYLE_Normal])
args.SetStyle(TriBlendMode::Normal);
else if (mRenderStyle == LegacyRenderStyles[STYLE_Add])
args.SetStyle(TriBlendMode::Add);
else if (mRenderStyle == LegacyRenderStyles[STYLE_Translucent])
args.SetStyle(TriBlendMode::Translucent);
else
args.SetStyle(TriBlendMode::Opaque); args.SetStyle(TriBlendMode::Opaque);
} }
else else
@ -173,10 +188,10 @@ void PolyRenderState::Bind(PolyDataBuffer *buffer, uint32_t offset, uint32_t len
{ {
if (buffer->bindingpoint == VIEWPOINT_BINDINGPOINT) if (buffer->bindingpoint == VIEWPOINT_BINDINGPOINT)
{ {
HWViewpointUniforms *uniforms = reinterpret_cast<HWViewpointUniforms*>(static_cast<uint8_t*>(buffer->Memory()) + offset); mViewpointUniforms = reinterpret_cast<HWViewpointUniforms*>(static_cast<uint8_t*>(buffer->Memory()) + offset);
Mat4f viewToProj = Mat4f::FromValues(uniforms->mProjectionMatrix.get()); Mat4f viewToProj = Mat4f::FromValues(mViewpointUniforms->mProjectionMatrix.get());
Mat4f worldToView = Mat4f::FromValues(uniforms->mViewMatrix.get()); Mat4f worldToView = Mat4f::FromValues(mViewpointUniforms->mViewMatrix.get());
auto fb = GetPolyFrameBuffer(); auto fb = GetPolyFrameBuffer();
PolyTriangleDrawer::SetTransform(fb->GetDrawCommands(), fb->GetFrameMemory()->NewObject<Mat4f>(viewToProj * worldToView), nullptr); PolyTriangleDrawer::SetTransform(fb->GetDrawCommands(), fb->GetFrameMemory()->NewObject<Mat4f>(viewToProj * worldToView), nullptr);

View file

@ -10,7 +10,7 @@
#include "hwrenderer/scene/hw_renderstate.h" #include "hwrenderer/scene/hw_renderstate.h"
#include "hwrenderer/textures/hw_material.h" #include "hwrenderer/textures/hw_material.h"
class PolyRenderPassSetup; struct HWViewpointUniforms;
class PolyRenderState : public FRenderState class PolyRenderState : public FRenderState
{ {
@ -45,6 +45,8 @@ public:
private: private:
void Apply(); void Apply();
HWViewpointUniforms *mViewpointUniforms = nullptr;
bool mDepthClamp = true; bool mDepthClamp = true;
PolyDrawArgs args; PolyDrawArgs args;
}; };

View file

@ -2250,10 +2250,10 @@ void(*ScreenTriangle::RectDrawers32[])(const void *, int, int, int, const RectDr
void(*ScreenTriangle::TriangleDrawers[])(const TriDrawTriangleArgs *args, PolyTriangleThreadData *thread, int16_t *edges, int topY, int bottomY) = void(*ScreenTriangle::TriangleDrawers[])(const TriDrawTriangleArgs *args, PolyTriangleThreadData *thread, int16_t *edges, int topY, int bottomY) =
{ {
nullptr, &DrawTriangle<TriScreenDrawerModes::TriangleOpt0>,
nullptr, &DrawTriangle<TriScreenDrawerModes::TriangleOpt1>,
nullptr, &DrawTriangle<TriScreenDrawerModes::TriangleOpt2>,
nullptr, &DrawTriangle<TriScreenDrawerModes::TriangleOpt3>,
&DrawTriangle<TriScreenDrawerModes::TriangleOpt4>, &DrawTriangle<TriScreenDrawerModes::TriangleOpt4>,
&DrawTriangle<TriScreenDrawerModes::TriangleOpt5>, &DrawTriangle<TriScreenDrawerModes::TriangleOpt5>,
&DrawTriangle<TriScreenDrawerModes::TriangleOpt6>, &DrawTriangle<TriScreenDrawerModes::TriangleOpt6>,

View file

@ -223,6 +223,10 @@ namespace TriScreenDrawerModes
SWTRI_WriteStencil = 16 SWTRI_WriteStencil = 16
}; };
struct TriangleOpt0 { static const int Flags = 0; };
struct TriangleOpt1 { static const int Flags = 1; };
struct TriangleOpt2 { static const int Flags = 2; };
struct TriangleOpt3 { static const int Flags = 3; };
struct TriangleOpt4 { static const int Flags = 4; }; struct TriangleOpt4 { static const int Flags = 4; };
struct TriangleOpt5 { static const int Flags = 5; }; struct TriangleOpt5 { static const int Flags = 5; };
struct TriangleOpt6 { static const int Flags = 6; }; struct TriangleOpt6 { static const int Flags = 6; };