- Simplify the PolyDrawArgs interface

This commit is contained in:
Magnus Norddahl 2017-03-26 10:10:55 +02:00
parent 7b58eab332
commit ffc90f16ab
16 changed files with 373 additions and 543 deletions

View file

@ -39,21 +39,21 @@
void PolyDrawArgs::SetClipPlane(float a, float b, float c, float d) void PolyDrawArgs::SetClipPlane(float a, float b, float c, float d)
{ {
clipPlane[0] = a; mClipPlane[0] = a;
clipPlane[1] = b; mClipPlane[1] = b;
clipPlane[2] = c; mClipPlane[2] = c;
clipPlane[3] = d; mClipPlane[3] = d;
} }
void PolyDrawArgs::SetTexture(FTexture *texture) void PolyDrawArgs::SetTexture(FTexture *texture)
{ {
textureWidth = texture->GetWidth(); mTextureWidth = texture->GetWidth();
textureHeight = texture->GetHeight(); mTextureHeight = texture->GetHeight();
if (PolyRenderer::Instance()->RenderTarget->IsBgra()) if (PolyRenderer::Instance()->RenderTarget->IsBgra())
texturePixels = (const uint8_t *)texture->GetPixelsBgra(); mTexturePixels = (const uint8_t *)texture->GetPixelsBgra();
else else
texturePixels = texture->GetPixels(); mTexturePixels = texture->GetPixels();
translation = nullptr; mTranslation = nullptr;
} }
void PolyDrawArgs::SetTexture(FTexture *texture, uint32_t translationID, bool forcePal) void PolyDrawArgs::SetTexture(FTexture *texture, uint32_t translationID, bool forcePal)
@ -64,22 +64,22 @@ void PolyDrawArgs::SetTexture(FTexture *texture, uint32_t translationID, bool fo
if (table != nullptr && !table->Inactive) if (table != nullptr && !table->Inactive)
{ {
if (PolyRenderer::Instance()->RenderTarget->IsBgra()) if (PolyRenderer::Instance()->RenderTarget->IsBgra())
translation = (uint8_t*)table->Palette; mTranslation = (uint8_t*)table->Palette;
else else
translation = table->Remap; mTranslation = table->Remap;
textureWidth = texture->GetWidth(); mTextureWidth = texture->GetWidth();
textureHeight = texture->GetHeight(); mTextureHeight = texture->GetHeight();
texturePixels = texture->GetPixels(); mTexturePixels = texture->GetPixels();
return; return;
} }
} }
if (forcePal) if (forcePal)
{ {
textureWidth = texture->GetWidth(); mTextureWidth = texture->GetWidth();
textureHeight = texture->GetHeight(); mTextureHeight = texture->GetHeight();
texturePixels = texture->GetPixels(); mTexturePixels = texture->GetPixels();
} }
else else
{ {
@ -87,21 +87,48 @@ void PolyDrawArgs::SetTexture(FTexture *texture, uint32_t translationID, bool fo
} }
} }
void PolyDrawArgs::SetColormap(FSWColormap *base_colormap) void PolyDrawArgs::SetLight(FSWColormap *base_colormap, uint32_t lightlevel, double globVis, bool fixed)
{ {
uniforms.light_red = base_colormap->Color.r * 256 / 255; mGlobVis = (float)globVis;
uniforms.light_green = base_colormap->Color.g * 256 / 255;
uniforms.light_blue = base_colormap->Color.b * 256 / 255; PolyCameraLight *cameraLight = PolyCameraLight::Instance();
uniforms.light_alpha = base_colormap->Color.a * 256 / 255; if (cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap())
uniforms.fade_red = base_colormap->Fade.r; {
uniforms.fade_green = base_colormap->Fade.g; lightlevel = cameraLight->FixedLightLevel() >= 0 ? cameraLight->FixedLightLevel() : 255;
uniforms.fade_blue = base_colormap->Fade.b; fixed = true;
uniforms.fade_alpha = base_colormap->Fade.a; }
uniforms.desaturate = MIN(abs(base_colormap->Desaturate), 255) * 255 / 256;
bool simple_shade = (base_colormap->Color.d == 0x00ffffff && base_colormap->Fade.d == 0x00000000 && base_colormap->Desaturate == 0); mLight = clamp<uint32_t>(lightlevel, 0, 255);
if (simple_shade) mFixedLight = fixed;
uniforms.flags |= TriUniforms::simple_shade; mLightRed = base_colormap->Color.r * 256 / 255;
else mLightGreen = base_colormap->Color.g * 256 / 255;
uniforms.flags &= ~TriUniforms::simple_shade; mLightBlue = base_colormap->Color.b * 256 / 255;
colormaps = base_colormap->Maps; mLightAlpha = base_colormap->Color.a * 256 / 255;
mFadeRed = base_colormap->Fade.r;
mFadeGreen = base_colormap->Fade.g;
mFadeBlue = base_colormap->Fade.b;
mFadeAlpha = base_colormap->Fade.a;
mDesaturate = MIN(abs(base_colormap->Desaturate), 255) * 255 / 256;
mSimpleShade = (base_colormap->Color.d == 0x00ffffff && base_colormap->Fade.d == 0x00000000 && base_colormap->Desaturate == 0);
mColormaps = base_colormap->Maps;
}
void PolyDrawArgs::SetColor(uint32_t bgra, uint8_t palindex)
{
if (PolyRenderer::Instance()->RenderTarget->IsBgra())
{
mColor = bgra;
}
else
{
mColor = palindex;
}
}
void PolyDrawArgs::DrawArray(const TriVertex *vertices, int vcount, PolyDrawMode mode)
{
mVertices = vertices;
mVertexCount = vcount;
mDrawMode = mode;
PolyRenderer::Instance()->DrawQueue->Push<DrawPolyTrianglesCommand>(*this, PolyTriangleDrawer::is_mirror());
} }

View file

@ -27,43 +27,114 @@
#include "screen_triangle.h" #include "screen_triangle.h"
class FTexture; class FTexture;
enum class TriangleDrawMode
{
Normal,
Fan,
Strip
};
struct TriDrawTriangleArgs;
struct TriMatrix; struct TriMatrix;
enum class PolyDrawMode
{
Triangles,
TriangleFan,
TriangleStrip
};
class PolyDrawArgs class PolyDrawArgs
{ {
public: public:
TriUniforms uniforms;
const TriMatrix *objectToClip = nullptr;
const TriVertex *vinput = nullptr;
int vcount = 0;
TriangleDrawMode mode = TriangleDrawMode::Normal;
bool ccw = false;
// bool stencilTest = true; // Always true for now
bool subsectorTest = false;
bool writeStencil = true;
bool writeColor = true;
bool writeSubsector = true;
const uint8_t *texturePixels = nullptr;
int textureWidth = 0;
int textureHeight = 0;
const uint8_t *translation = nullptr;
uint8_t stenciltestvalue = 0;
uint8_t stencilwritevalue = 0;
const uint8_t *colormaps = nullptr;
float clipPlane[4];
TriBlendMode blendmode = TriBlendMode::Copy;
void SetClipPlane(float a, float b, float c, float d); void SetClipPlane(float a, float b, float c, float d);
void SetTexture(FTexture *texture); void SetTexture(FTexture *texture);
void SetTexture(FTexture *texture, uint32_t translationID, bool forcePal = false); void SetTexture(FTexture *texture, uint32_t translationID, bool forcePal = false);
void SetColormap(FSWColormap *base_colormap); void SetLight(FSWColormap *basecolormap, uint32_t lightlevel, double globVis, bool fixed);
void SetSubsectorDepth(uint32_t subsectorDepth) { mSubsectorDepth = subsectorDepth; }
void SetSubsectorDepthTest(bool enable) { mSubsectorTest = enable; }
void SetStencilTestValue(uint8_t stencilTestValue) { mStencilTestValue = stencilTestValue; }
void SetWriteColor(bool enable) { mWriteColor = enable; }
void SetWriteStencil(bool enable, uint8_t stencilWriteValue = 0) { mWriteStencil = enable; mStencilWriteValue = stencilWriteValue; }
void SetWriteSubsectorDepth(bool enable) { mWriteSubsector = enable; }
void SetFaceCullCCW(bool counterclockwise) { mFaceCullCCW = counterclockwise; }
void SetStyle(TriBlendMode blendmode, double srcalpha = 1.0, double destalpha = 1.0) { mBlendMode = blendmode; mSrcAlpha = (uint32_t)(srcalpha * 256.0 + 0.5); mDestAlpha = (uint32_t)(destalpha * 256.0 + 0.5); }
void SetTransform(const TriMatrix *objectToClip) { mObjectToClip = objectToClip; }
void SetColor(uint32_t bgra, uint8_t palindex);
void DrawArray(const TriVertex *vertices, int vcount, PolyDrawMode mode = PolyDrawMode::Triangles);
const TriMatrix *ObjectToClip() const { return mObjectToClip; }
const float *ClipPlane() const { return mClipPlane; }
const TriVertex *Vertices() const { return mVertices; }
int VertexCount() const { return mVertexCount; }
PolyDrawMode DrawMode() const { return mDrawMode; }
bool FaceCullCCW() const { return mFaceCullCCW; }
bool WriteColor() const { return mWriteColor; }
const uint8_t *TexturePixels() const { return mTexturePixels; }
int TextureWidth() const { return mTextureWidth; }
int TextureHeight() const { return mTextureHeight; }
const uint8_t *Translation() const { return mTranslation; }
bool WriteStencil() const { return mWriteStencil; }
uint8_t StencilTestValue() const { return mStencilTestValue; }
uint8_t StencilWriteValue() const { return mStencilWriteValue; }
bool SubsectorTest() const { return mSubsectorTest; }
bool WriteSubsector() const { return mWriteSubsector; }
uint32_t SubsectorDepth() const { return mSubsectorDepth; }
TriBlendMode BlendMode() const { return mBlendMode; }
uint32_t Color() const { return mColor; }
uint32_t SrcAlpha() const { return mSrcAlpha; }
uint32_t DestAlpha() const { return mDestAlpha; }
float GlobVis() const { return mGlobVis; }
uint32_t Light() const { return mLight; }
const uint8_t *BaseColormap() const { return mColormaps; }
uint16_t ShadeLightAlpha() const { return mLightAlpha; }
uint16_t ShadeLightRed() const { return mLightRed; }
uint16_t ShadeLightGreen() const { return mLightGreen; }
uint16_t ShadeLightBlue() const { return mLightBlue; }
uint16_t ShadeFadeAlpha() const { return mFadeAlpha; }
uint16_t ShadeFadeRed() const { return mFadeRed; }
uint16_t ShadeFadeGreen() const { return mFadeGreen; }
uint16_t ShadeFadeBlue() const { return mFadeBlue; }
uint16_t ShadeDesaturate() const { return mDesaturate; }
bool SimpleShade() const { return mSimpleShade; }
bool NearestFilter() const { return mNearestFilter; }
bool FixedLight() const { return mFixedLight; }
private:
const TriMatrix *mObjectToClip = nullptr;
const TriVertex *mVertices = nullptr;
int mVertexCount = 0;
PolyDrawMode mDrawMode = PolyDrawMode::Triangles;
bool mFaceCullCCW = false;
bool mSubsectorTest = false;
bool mWriteStencil = true;
bool mWriteColor = true;
bool mWriteSubsector = true;
const uint8_t *mTexturePixels = nullptr;
int mTextureWidth = 0;
int mTextureHeight = 0;
const uint8_t *mTranslation = nullptr;
uint8_t mStencilTestValue = 0;
uint8_t mStencilWriteValue = 0;
const uint8_t *mColormaps = nullptr;
float mClipPlane[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
TriBlendMode mBlendMode = TriBlendMode::Copy;
uint32_t mLight = 0;
uint32_t mSubsectorDepth = 0;
uint32_t mColor = 0;
uint32_t mSrcAlpha = 0;
uint32_t mDestAlpha = 0;
uint16_t mLightAlpha = 0;
uint16_t mLightRed = 0;
uint16_t mLightGreen = 0;
uint16_t mLightBlue = 0;
uint16_t mFadeAlpha = 0;
uint16_t mFadeRed = 0;
uint16_t mFadeGreen = 0;
uint16_t mFadeBlue = 0;
uint16_t mDesaturate = 0;
float mGlobVis = 0.0f;
bool mSimpleShade = true;
bool mNearestFilter = true;
bool mFixedLight = false;
}; };

View file

@ -32,12 +32,11 @@ public:
{ {
using namespace TriScreenDrawerModes; using namespace TriScreenDrawerModes;
auto flags = args->uniforms->flags; bool is_simple_shade = args->uniforms->SimpleShade();
bool is_simple_shade = (flags & TriUniforms::simple_shade) == TriUniforms::simple_shade;
if (SamplerT::Mode == (int)Samplers::Texture) if (SamplerT::Mode == (int)Samplers::Texture)
{ {
bool is_nearest_filter = (flags & TriUniforms::nearest_filter) == TriUniforms::nearest_filter; bool is_nearest_filter = args->uniforms->NearestFilter();
if (is_simple_shade) if (is_simple_shade)
{ {
@ -79,11 +78,10 @@ public:
int startX = thread->StartX; int startX = thread->StartX;
int startY = thread->StartY; int startY = thread->StartY;
auto flags = args->uniforms->flags; bool is_fixed_light = args->uniforms->FixedLight();
bool is_fixed_light = (flags & TriUniforms::fixed_light) == TriUniforms::fixed_light;
uint32_t lightmask = is_fixed_light ? 0 : 0xffffffff; uint32_t lightmask = is_fixed_light ? 0 : 0xffffffff;
uint32_t srcalpha = args->uniforms->srcalpha; uint32_t srcalpha = args->uniforms->SrcAlpha();
uint32_t destalpha = args->uniforms->destalpha; uint32_t destalpha = args->uniforms->DestAlpha();
// Calculate gradients // Calculate gradients
const TriVertex &v1 = *args->v1; const TriVertex &v1 = *args->v1;
@ -107,17 +105,17 @@ public:
int pitch = args->pitch; int pitch = args->pitch;
// Light // Light
uint32_t light = args->uniforms->light; uint32_t light = args->uniforms->Light();
float shade = 2.0f - (light + 12.0f) / 128.0f; float shade = 2.0f - (light + 12.0f) / 128.0f;
float globVis = args->uniforms->globvis * (1.0f / 32.0f); float globVis = args->uniforms->GlobVis() * (1.0f / 32.0f);
light += (light >> 7); // 255 -> 256 light += (light >> 7); // 255 -> 256
// Sampling stuff // Sampling stuff
uint32_t color = args->uniforms->color; uint32_t color = args->uniforms->Color();
const uint32_t * RESTRICT translation = (const uint32_t *)args->translation; const uint32_t * RESTRICT translation = (const uint32_t *)args->uniforms->Translation();
const uint32_t * RESTRICT texPixels = (const uint32_t *)args->texturePixels; const uint32_t * RESTRICT texPixels = (const uint32_t *)args->uniforms->TexturePixels();
uint32_t texWidth = args->textureWidth; uint32_t texWidth = args->uniforms->TextureWidth();
uint32_t texHeight = args->textureHeight; uint32_t texHeight = args->uniforms->TextureHeight();
uint32_t oneU, oneV; uint32_t oneU, oneV;
if (SamplerT::Mode != (int)Samplers::Fill) if (SamplerT::Mode != (int)Samplers::Fill)
{ {
@ -135,10 +133,10 @@ public:
int desaturate; int desaturate;
if (ShadeModeT::Mode == (int)ShadeMode::Advanced) if (ShadeModeT::Mode == (int)ShadeMode::Advanced)
{ {
inv_desaturate = _mm_setr_epi16(256, 256 - args->uniforms->desaturate, 256 - args->uniforms->desaturate, 256 - args->uniforms->desaturate, 256, 256 - args->uniforms->desaturate, 256 - args->uniforms->desaturate, 256 - args->uniforms->desaturate); inv_desaturate = _mm_setr_epi16(256, 256 - args->uniforms->ShadeDesaturate(), 256 - args->uniforms->ShadeDesaturate(), 256 - args->uniforms->ShadeDesaturate(), 256, 256 - args->uniforms->ShadeDesaturate(), 256 - args->uniforms->ShadeDesaturate(), 256 - args->uniforms->ShadeDesaturate());
shade_fade = _mm_set_epi16(args->uniforms->fade_alpha, args->uniforms->fade_red, args->uniforms->fade_green, args->uniforms->fade_blue, args->uniforms->fade_alpha, args->uniforms->fade_red, args->uniforms->fade_green, args->uniforms->fade_blue); shade_fade = _mm_set_epi16(args->uniforms->ShadeFadeAlpha(), args->uniforms->ShadeFadeRed(), args->uniforms->ShadeFadeGreen(), args->uniforms->ShadeFadeBlue(), args->uniforms->ShadeFadeAlpha(), args->uniforms->ShadeFadeRed(), args->uniforms->ShadeFadeGreen(), args->uniforms->ShadeFadeBlue());
shade_light = _mm_set_epi16(args->uniforms->light_alpha, args->uniforms->light_red, args->uniforms->light_green, args->uniforms->light_blue, args->uniforms->light_alpha, args->uniforms->light_red, args->uniforms->light_green, args->uniforms->light_blue); shade_light = _mm_set_epi16(args->uniforms->ShadeLightAlpha(), args->uniforms->ShadeLightRed(), args->uniforms->ShadeLightGreen(), args->uniforms->ShadeLightBlue(), args->uniforms->ShadeLightAlpha(), args->uniforms->ShadeLightRed(), args->uniforms->ShadeLightGreen(), args->uniforms->ShadeLightBlue());
desaturate = args->uniforms->desaturate; desaturate = args->uniforms->ShadeDesaturate();
} }
else else
{ {

View file

@ -39,12 +39,11 @@ public:
int startX = thread->StartX; int startX = thread->StartX;
int startY = thread->StartY; int startY = thread->StartY;
auto flags = args->uniforms->flags; bool is_fixed_light = args->uniforms->FixedLight();
bool is_fixed_light = (flags & TriUniforms::fixed_light) == TriUniforms::fixed_light;
uint32_t lightmask = is_fixed_light ? 0 : 0xffffffff; uint32_t lightmask = is_fixed_light ? 0 : 0xffffffff;
auto colormaps = args->colormaps; auto colormaps = args->uniforms->BaseColormap();
uint32_t srcalpha = args->uniforms->srcalpha; uint32_t srcalpha = args->uniforms->SrcAlpha();
uint32_t destalpha = args->uniforms->destalpha; uint32_t destalpha = args->uniforms->DestAlpha();
// Calculate gradients // Calculate gradients
const TriVertex &v1 = *args->v1; const TriVertex &v1 = *args->v1;
@ -68,17 +67,17 @@ public:
int pitch = args->pitch; int pitch = args->pitch;
// Light // Light
uint32_t light = args->uniforms->light; uint32_t light = args->uniforms->Light();
float shade = 2.0f - (light + 12.0f) / 128.0f; float shade = 2.0f - (light + 12.0f) / 128.0f;
float globVis = args->uniforms->globvis * (1.0f / 32.0f); float globVis = args->uniforms->GlobVis() * (1.0f / 32.0f);
light += light >> 7; // 255 -> 256 light += light >> 7; // 255 -> 256
// Sampling stuff // Sampling stuff
uint32_t color = args->uniforms->color; uint32_t color = args->uniforms->Color();
const uint8_t * RESTRICT translation = args->translation; const uint8_t * RESTRICT translation = args->uniforms->Translation();
const uint8_t * RESTRICT texPixels = args->texturePixels; const uint8_t * RESTRICT texPixels = args->uniforms->TexturePixels();
uint32_t texWidth = args->textureWidth; uint32_t texWidth = args->uniforms->TextureWidth();
uint32_t texHeight = args->textureHeight; uint32_t texHeight = args->uniforms->TextureHeight();
for (int i = 0; i < numSpans; i++) for (int i = 0; i < numSpans; i++)
{ {

View file

@ -80,35 +80,35 @@ void PolyTriangleDrawer::toggle_mirror()
mirror = !mirror; mirror = !mirror;
} }
void PolyTriangleDrawer::draw(const PolyDrawArgs &args) bool PolyTriangleDrawer::is_mirror()
{ {
PolyRenderer::Instance()->DrawQueue->Push<DrawPolyTrianglesCommand>(args, mirror); return mirror;
} }
void PolyTriangleDrawer::draw_arrays(const PolyDrawArgs &drawargs, WorkerThreadData *thread) void PolyTriangleDrawer::draw_arrays(const PolyDrawArgs &drawargs, WorkerThreadData *thread)
{ {
if (drawargs.vcount < 3) if (drawargs.VertexCount() < 3)
return; return;
PolyDrawFuncPtr drawfuncs[4]; PolyDrawFuncPtr drawfuncs[4];
int num_drawfuncs = 0; int num_drawfuncs = 0;
drawfuncs[num_drawfuncs++] = drawargs.subsectorTest ? &ScreenTriangle::SetupSubsector : &ScreenTriangle::SetupNormal; drawfuncs[num_drawfuncs++] = drawargs.SubsectorTest() ? &ScreenTriangle::SetupSubsector : &ScreenTriangle::SetupNormal;
if (!r_debug_trisetup) // For profiling how much time is spent in setup vs drawal if (!r_debug_trisetup) // For profiling how much time is spent in setup vs drawal
{ {
int bmode = (int)drawargs.blendmode; int bmode = (int)drawargs.BlendMode();
if (drawargs.writeColor && drawargs.texturePixels) if (drawargs.WriteColor() && drawargs.TexturePixels())
drawfuncs[num_drawfuncs++] = dest_bgra ? ScreenTriangle::TriDraw32[bmode] : ScreenTriangle::TriDraw8[bmode]; drawfuncs[num_drawfuncs++] = dest_bgra ? ScreenTriangle::TriDraw32[bmode] : ScreenTriangle::TriDraw8[bmode];
else if (drawargs.writeColor) else if (drawargs.WriteColor())
drawfuncs[num_drawfuncs++] = dest_bgra ? ScreenTriangle::TriFill32[bmode] : ScreenTriangle::TriFill8[bmode]; drawfuncs[num_drawfuncs++] = dest_bgra ? ScreenTriangle::TriFill32[bmode] : ScreenTriangle::TriFill8[bmode];
} }
if (drawargs.writeStencil) if (drawargs.WriteStencil())
drawfuncs[num_drawfuncs++] = &ScreenTriangle::StencilWrite; drawfuncs[num_drawfuncs++] = &ScreenTriangle::StencilWrite;
if (drawargs.writeSubsector) if (drawargs.WriteSubsector())
drawfuncs[num_drawfuncs++] = &ScreenTriangle::SubsectorWrite; drawfuncs[num_drawfuncs++] = &ScreenTriangle::SubsectorWrite;
TriDrawTriangleArgs args; TriDrawTriangleArgs args;
@ -118,53 +118,44 @@ void PolyTriangleDrawer::draw_arrays(const PolyDrawArgs &drawargs, WorkerThreadD
args.clipright = dest_width; args.clipright = dest_width;
args.cliptop = 0; args.cliptop = 0;
args.clipbottom = dest_height; args.clipbottom = dest_height;
args.texturePixels = drawargs.texturePixels; args.uniforms = &drawargs;
args.textureWidth = drawargs.textureWidth;
args.textureHeight = drawargs.textureHeight;
args.translation = drawargs.translation;
args.uniforms = &drawargs.uniforms;
args.stencilTestValue = drawargs.stenciltestvalue;
args.stencilWriteValue = drawargs.stencilwritevalue;
args.stencilPitch = PolyStencilBuffer::Instance()->BlockWidth(); args.stencilPitch = PolyStencilBuffer::Instance()->BlockWidth();
args.stencilValues = PolyStencilBuffer::Instance()->Values(); args.stencilValues = PolyStencilBuffer::Instance()->Values();
args.stencilMasks = PolyStencilBuffer::Instance()->Masks(); args.stencilMasks = PolyStencilBuffer::Instance()->Masks();
args.subsectorGBuffer = PolySubsectorGBuffer::Instance()->Values(); args.subsectorGBuffer = PolySubsectorGBuffer::Instance()->Values();
args.colormaps = drawargs.colormaps;
args.RGB256k = RGB256k.All;
args.BaseColors = (const uint8_t *)GPalette.BaseColors;
bool ccw = drawargs.ccw; bool ccw = drawargs.FaceCullCCW();
const TriVertex *vinput = drawargs.vinput; const TriVertex *vinput = drawargs.Vertices();
int vcount = drawargs.vcount; int vcount = drawargs.VertexCount();
ShadedTriVertex vert[3]; ShadedTriVertex vert[3];
if (drawargs.mode == TriangleDrawMode::Normal) if (drawargs.DrawMode() == PolyDrawMode::Triangles)
{ {
for (int i = 0; i < vcount / 3; i++) for (int i = 0; i < vcount / 3; i++)
{ {
for (int j = 0; j < 3; j++) for (int j = 0; j < 3; j++)
vert[j] = shade_vertex(*drawargs.objectToClip, drawargs.clipPlane, *(vinput++)); vert[j] = shade_vertex(*drawargs.ObjectToClip(), drawargs.ClipPlane(), *(vinput++));
draw_shaded_triangle(vert, ccw, &args, thread, drawfuncs, num_drawfuncs); draw_shaded_triangle(vert, ccw, &args, thread, drawfuncs, num_drawfuncs);
} }
} }
else if (drawargs.mode == TriangleDrawMode::Fan) else if (drawargs.DrawMode() == PolyDrawMode::TriangleFan)
{ {
vert[0] = shade_vertex(*drawargs.objectToClip, drawargs.clipPlane, *(vinput++)); vert[0] = shade_vertex(*drawargs.ObjectToClip(), drawargs.ClipPlane(), *(vinput++));
vert[1] = shade_vertex(*drawargs.objectToClip, drawargs.clipPlane, *(vinput++)); vert[1] = shade_vertex(*drawargs.ObjectToClip(), drawargs.ClipPlane(), *(vinput++));
for (int i = 2; i < vcount; i++) for (int i = 2; i < vcount; i++)
{ {
vert[2] = shade_vertex(*drawargs.objectToClip, drawargs.clipPlane, *(vinput++)); vert[2] = shade_vertex(*drawargs.ObjectToClip(), drawargs.ClipPlane(), *(vinput++));
draw_shaded_triangle(vert, ccw, &args, thread, drawfuncs, num_drawfuncs); draw_shaded_triangle(vert, ccw, &args, thread, drawfuncs, num_drawfuncs);
vert[1] = vert[2]; vert[1] = vert[2];
} }
} }
else // TriangleDrawMode::Strip else // TriangleDrawMode::TriangleStrip
{ {
vert[0] = shade_vertex(*drawargs.objectToClip, drawargs.clipPlane, *(vinput++)); vert[0] = shade_vertex(*drawargs.ObjectToClip(), drawargs.ClipPlane(), *(vinput++));
vert[1] = shade_vertex(*drawargs.objectToClip, drawargs.clipPlane, *(vinput++)); vert[1] = shade_vertex(*drawargs.ObjectToClip(), drawargs.ClipPlane(), *(vinput++));
for (int i = 2; i < vcount; i++) for (int i = 2; i < vcount; i++)
{ {
vert[2] = shade_vertex(*drawargs.objectToClip, drawargs.clipPlane, *(vinput++)); vert[2] = shade_vertex(*drawargs.ObjectToClip(), drawargs.ClipPlane(), *(vinput++));
draw_shaded_triangle(vert, ccw, &args, thread, drawfuncs, num_drawfuncs); draw_shaded_triangle(vert, ccw, &args, thread, drawfuncs, num_drawfuncs);
vert[0] = vert[1]; vert[0] = vert[1];
vert[1] = vert[2]; vert[1] = vert[2];
@ -448,7 +439,7 @@ DrawPolyTrianglesCommand::DrawPolyTrianglesCommand(const PolyDrawArgs &args, boo
: args(args) : args(args)
{ {
if (mirror) if (mirror)
this->args.ccw = !this->args.ccw; this->args.SetFaceCullCCW(!this->args.FaceCullCCW());
} }
void DrawPolyTrianglesCommand::Execute(DrawerThread *thread) void DrawPolyTrianglesCommand::Execute(DrawerThread *thread)
@ -461,32 +452,3 @@ void DrawPolyTrianglesCommand::Execute(DrawerThread *thread)
PolyTriangleDrawer::draw_arrays(args, &thread_data); PolyTriangleDrawer::draw_arrays(args, &thread_data);
} }
FString DrawPolyTrianglesCommand::DebugInfo()
{
FString blendmodestr;
switch (args.blendmode)
{
default: blendmodestr = "Unknown"; break;
case TriBlendMode::Copy: blendmodestr = "Copy"; break;
case TriBlendMode::AlphaBlend: blendmodestr = "AlphaBlend"; break;
case TriBlendMode::AddSolid: blendmodestr = "AddSolid"; break;
case TriBlendMode::Add: blendmodestr = "Add"; break;
case TriBlendMode::Sub: blendmodestr = "Sub"; break;
case TriBlendMode::RevSub: blendmodestr = "RevSub"; break;
case TriBlendMode::Stencil: blendmodestr = "Stencil"; break;
case TriBlendMode::Shaded: blendmodestr = "Shaded"; break;
case TriBlendMode::TranslateCopy: blendmodestr = "TranslateCopy"; break;
case TriBlendMode::TranslateAlphaBlend: blendmodestr = "TranslateAlphaBlend"; break;
case TriBlendMode::TranslateAdd: blendmodestr = "TranslateAdd"; break;
case TriBlendMode::TranslateSub: blendmodestr = "TranslateSub"; break;
case TriBlendMode::TranslateRevSub: blendmodestr = "TranslateRevSub"; break;
case TriBlendMode::AddSrcColorOneMinusSrcColor: blendmodestr = "AddSrcColorOneMinusSrcColor"; break;
}
FString info;
info.Format("DrawPolyTriangles: blend mode = %s, color = %d, light = %d, textureWidth = %d, textureHeight = %d, texture = %s, translation = %s, colormaps = %s",
blendmodestr.GetChars(), args.uniforms.color, args.uniforms.light, args.textureWidth, args.textureHeight,
args.texturePixels ? "ptr" : "null", args.translation ? "ptr" : "null", args.colormaps ? "ptr" : "null");
return info;
}

View file

@ -40,8 +40,8 @@ class PolyTriangleDrawer
{ {
public: public:
static void set_viewport(int x, int y, int width, int height, DCanvas *canvas); static void set_viewport(int x, int y, int width, int height, DCanvas *canvas);
static void draw(const PolyDrawArgs &args);
static void toggle_mirror(); static void toggle_mirror();
static bool is_mirror();
private: private:
static ShadedTriVertex shade_vertex(const TriMatrix &objectToClip, const float *clipPlane, const TriVertex &v); static ShadedTriVertex shade_vertex(const TriMatrix &objectToClip, const float *clipPlane, const TriVertex &v);
@ -66,7 +66,7 @@ public:
DrawPolyTrianglesCommand(const PolyDrawArgs &args, bool mirror); DrawPolyTrianglesCommand(const PolyDrawArgs &args, bool mirror);
void Execute(DrawerThread *thread) override; void Execute(DrawerThread *thread) override;
FString DebugInfo() override; FString DebugInfo() override { return "DrawPolyTriangles"; }
private: private:
PolyDrawArgs args; PolyDrawArgs args;

View file

@ -52,7 +52,7 @@ void ScreenTriangle::SetupNormal(const TriDrawTriangleArgs *args, WorkerThreadDa
int stencilPitch = args->stencilPitch; int stencilPitch = args->stencilPitch;
uint8_t * RESTRICT stencilValues = args->stencilValues; uint8_t * RESTRICT stencilValues = args->stencilValues;
uint32_t * RESTRICT stencilMasks = args->stencilMasks; uint32_t * RESTRICT stencilMasks = args->stencilMasks;
uint8_t stencilTestValue = args->stencilTestValue; uint8_t stencilTestValue = args->uniforms->StencilTestValue();
TriFullSpan * RESTRICT span = thread->FullSpans; TriFullSpan * RESTRICT span = thread->FullSpans;
TriPartialBlock * RESTRICT partial = thread->PartialBlocks; TriPartialBlock * RESTRICT partial = thread->PartialBlocks;
@ -389,10 +389,10 @@ void ScreenTriangle::SetupSubsector(const TriDrawTriangleArgs *args, WorkerThrea
int stencilPitch = args->stencilPitch; int stencilPitch = args->stencilPitch;
uint8_t * RESTRICT stencilValues = args->stencilValues; uint8_t * RESTRICT stencilValues = args->stencilValues;
uint32_t * RESTRICT stencilMasks = args->stencilMasks; uint32_t * RESTRICT stencilMasks = args->stencilMasks;
uint8_t stencilTestValue = args->stencilTestValue; uint8_t stencilTestValue = args->uniforms->StencilTestValue();
uint32_t * RESTRICT subsectorGBuffer = args->subsectorGBuffer; uint32_t * RESTRICT subsectorGBuffer = args->subsectorGBuffer;
uint32_t subsectorDepth = args->uniforms->subsectorDepth; uint32_t subsectorDepth = args->uniforms->SubsectorDepth();
int32_t pitch = args->pitch; int32_t pitch = args->pitch;
TriFullSpan * RESTRICT span = thread->FullSpans; TriFullSpan * RESTRICT span = thread->FullSpans;
@ -800,7 +800,7 @@ void ScreenTriangle::StencilWrite(const TriDrawTriangleArgs *args, WorkerThreadD
{ {
uint8_t * RESTRICT stencilValues = args->stencilValues; uint8_t * RESTRICT stencilValues = args->stencilValues;
uint32_t * RESTRICT stencilMasks = args->stencilMasks; uint32_t * RESTRICT stencilMasks = args->stencilMasks;
uint32_t stencilWriteValue = args->stencilWriteValue; uint32_t stencilWriteValue = args->uniforms->StencilWriteValue();
uint32_t stencilPitch = args->stencilPitch; uint32_t stencilPitch = args->stencilPitch;
int numSpans = thread->NumFullSpans; int numSpans = thread->NumFullSpans;
@ -869,7 +869,7 @@ void ScreenTriangle::StencilWrite(const TriDrawTriangleArgs *args, WorkerThreadD
void ScreenTriangle::SubsectorWrite(const TriDrawTriangleArgs *args, WorkerThreadData *thread) void ScreenTriangle::SubsectorWrite(const TriDrawTriangleArgs *args, WorkerThreadData *thread)
{ {
uint32_t * RESTRICT subsectorGBuffer = args->subsectorGBuffer; uint32_t * RESTRICT subsectorGBuffer = args->subsectorGBuffer;
uint32_t subsectorDepth = args->uniforms->subsectorDepth; uint32_t subsectorDepth = args->uniforms->SubsectorDepth();
int pitch = args->pitch; int pitch = args->pitch;
int numSpans = thread->NumFullSpans; int numSpans = thread->NumFullSpans;

View file

@ -26,6 +26,7 @@
#include <vector> #include <vector>
class FString; class FString;
class PolyDrawArgs;
struct TriFullSpan struct TriFullSpan
{ {
@ -67,32 +68,6 @@ struct TriVertex
float varying[NumVarying]; float varying[NumVarying];
}; };
struct TriUniforms
{
uint32_t light;
uint32_t subsectorDepth;
uint32_t color;
uint32_t srcalpha;
uint32_t destalpha;
uint16_t light_alpha;
uint16_t light_red;
uint16_t light_green;
uint16_t light_blue;
uint16_t fade_alpha;
uint16_t fade_red;
uint16_t fade_green;
uint16_t fade_blue;
uint16_t desaturate;
float globvis;
uint32_t flags;
enum Flags
{
simple_shade = 1,
nearest_filter = 2,
fixed_light = 4
};
};
struct TriDrawTriangleArgs struct TriDrawTriangleArgs
{ {
uint8_t *dest; uint8_t *dest;
@ -104,20 +79,11 @@ struct TriDrawTriangleArgs
int32_t clipright; int32_t clipright;
int32_t cliptop; int32_t cliptop;
int32_t clipbottom; int32_t clipbottom;
const uint8_t *texturePixels;
uint32_t textureWidth;
uint32_t textureHeight;
const uint8_t *translation;
const TriUniforms *uniforms;
uint8_t *stencilValues; uint8_t *stencilValues;
uint32_t *stencilMasks; uint32_t *stencilMasks;
int32_t stencilPitch; int32_t stencilPitch;
uint8_t stencilTestValue;
uint8_t stencilWriteValue;
uint32_t *subsectorGBuffer; uint32_t *subsectorGBuffer;
const uint8_t *colormaps; const PolyDrawArgs *uniforms;
const uint8_t *RGB256k;
const uint8_t *BaseColors;
}; };
enum class TriBlendMode enum class TriBlendMode

View file

@ -130,49 +130,21 @@ void RenderPolyDecal::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan
} }
bool fullbrightSprite = (decal->RenderFlags & RF_FULLBRIGHT) == RF_FULLBRIGHT; bool fullbrightSprite = (decal->RenderFlags & RF_FULLBRIGHT) == RF_FULLBRIGHT;
int lightlevel = fullbrightSprite ? 255 : front->lightlevel + actualextralight;
PolyCameraLight *cameraLight = PolyCameraLight::Instance();
PolyDrawArgs args; PolyDrawArgs args;
args.uniforms.flags = TriUniforms::nearest_filter; args.SetLight(GetColorTable(front->Colormap), lightlevel, PolyRenderer::Instance()->Light.WallGlobVis(foggy), fullbrightSprite);
args.SetColormap(GetColorTable(front->Colormap));
args.SetTexture(tex, decal->Translation, true); args.SetTexture(tex, decal->Translation, true);
args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy); args.SetSubsectorDepth(subsectorDepth);
if (fullbrightSprite || cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap()) args.SetColor(0xff000000 | decal->AlphaColor, decal->AlphaColor >> 24);
{ args.SetStyle(TriBlendMode::Shaded, decal->Alpha, 1.0 - decal->Alpha); // R_SetPatchStyle (decal->RenderStyle, (float)decal->Alpha, decal->Translation, decal->AlphaColor);
args.uniforms.light = 255; args.SetTransform(&worldToClip);
args.uniforms.flags |= TriUniforms::fixed_light; args.SetFaceCullCCW(true);
} args.SetStencilTestValue(stencilValue);
else args.SetWriteStencil(true, stencilValue);
{
args.uniforms.light = front->lightlevel + actualextralight;
}
args.uniforms.subsectorDepth = subsectorDepth;
if (PolyRenderer::Instance()->RenderTarget->IsBgra())
{
args.uniforms.color = 0xff000000 | decal->AlphaColor;
}
else
{
args.uniforms.color = ((uint32_t)decal->AlphaColor) >> 24;
}
args.uniforms.srcalpha = (uint32_t)(decal->Alpha * 256.0 + 0.5);
args.uniforms.destalpha = 256 - args.uniforms.srcalpha;
args.objectToClip = &worldToClip;
args.vinput = vertices;
args.vcount = 4;
args.mode = TriangleDrawMode::Fan;
args.ccw = true;
args.stenciltestvalue = stencilValue;
args.stencilwritevalue = stencilValue;
//mode = R_SetPatchStyle (decal->RenderStyle, (float)decal->Alpha, decal->Translation, decal->AlphaColor);
args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w); args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w);
args.blendmode = TriBlendMode::Shaded; args.SetSubsectorDepthTest(true);
args.subsectorTest = true; args.SetWriteStencil(false);
args.writeStencil = false; args.SetWriteSubsectorDepth(false);
args.writeSubsector = false; args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan);
PolyTriangleDrawer::draw(args);
} }

View file

@ -68,51 +68,20 @@ void RenderPolyParticle::Render(const TriMatrix &worldToClip, const Vec4f &clipP
vertices[i].varying[1] = (float)(1.0f - offsets[i].second); vertices[i].varying[1] = (float)(1.0f - offsets[i].second);
} }
// int color = (particle->color >> 24) & 0xff; // pal index, I think
bool fullbrightSprite = particle->bright != 0; bool fullbrightSprite = particle->bright != 0;
PolyCameraLight *cameraLight = PolyCameraLight::Instance(); int lightlevel = fullbrightSprite ? 255 : sub->sector->lightlevel + actualextralight;
PolyDrawArgs args; PolyDrawArgs args;
args.SetLight(GetColorTable(sub->sector->Colormap), lightlevel, PolyRenderer::Instance()->Light.ParticleGlobVis(foggy), fullbrightSprite);
args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.ParticleGlobVis(foggy); args.SetSubsectorDepth(subsectorDepth);
args.SetSubsectorDepthTest(true);
if (fullbrightSprite || cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap()) args.SetColor(particle->color | 0xff000000, particle->color >> 24);
{ args.SetStyle(TriBlendMode::AlphaBlend, particle->alpha, 1.0 - particle->alpha);
args.uniforms.light = 255; args.SetTransform(&worldToClip);
args.uniforms.flags = TriUniforms::fixed_light | TriUniforms::nearest_filter; args.SetFaceCullCCW(true);
} args.SetStencilTestValue(stencilValue);
else args.SetWriteStencil(false);
{ args.SetWriteSubsectorDepth(false);
args.uniforms.light = sub->sector->lightlevel + actualextralight;
args.uniforms.flags = TriUniforms::nearest_filter;
}
args.uniforms.subsectorDepth = subsectorDepth;
uint32_t alpha = (uint32_t)clamp(particle->alpha * 255.0f + 0.5f, 0.0f, 255.0f);
if (PolyRenderer::Instance()->RenderTarget->IsBgra())
{
args.uniforms.color = (alpha << 24) | (particle->color & 0xffffff);
}
else
{
args.uniforms.color = ((uint32_t)particle->color) >> 24;
args.uniforms.srcalpha = alpha;
args.uniforms.destalpha = 255 - alpha;
}
args.objectToClip = &worldToClip;
args.vinput = vertices;
args.vcount = 4;
args.mode = TriangleDrawMode::Fan;
args.ccw = true;
args.stenciltestvalue = stencilValue;
args.stencilwritevalue = stencilValue;
args.SetColormap(GetColorTable(sub->sector->Colormap));
args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w); args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w);
args.subsectorTest = true; args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan);
args.writeStencil = false;
args.writeSubsector = false;
args.blendmode = TriBlendMode::AlphaBlend;
PolyTriangleDrawer::draw(args);
} }

View file

@ -111,16 +111,7 @@ void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, const Vec4f &c
UVTransform xform(ceiling ? fakeFloor->top.model->planes[sector_t::ceiling].xform : fakeFloor->top.model->planes[sector_t::floor].xform, tex); UVTransform xform(ceiling ? fakeFloor->top.model->planes[sector_t::ceiling].xform : fakeFloor->top.model->planes[sector_t::floor].xform, tex);
PolyDrawArgs args;
args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy); // .SlopePlaneGlobVis(foggy) * 48.0f;
args.uniforms.light = lightlevel;
if (cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap())
args.uniforms.light = 255;
args.uniforms.flags = TriUniforms::nearest_filter;
args.uniforms.subsectorDepth = subsectorDepth;
TriVertex *vertices = PolyRenderer::Instance()->FrameMemory.AllocMemory<TriVertex>(sub->numlines); TriVertex *vertices = PolyRenderer::Instance()->FrameMemory.AllocMemory<TriVertex>(sub->numlines);
if (ceiling) if (ceiling)
{ {
for (uint32_t i = 0; i < sub->numlines; i++) for (uint32_t i = 0; i < sub->numlines; i++)
@ -138,18 +129,17 @@ void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, const Vec4f &c
} }
} }
args.objectToClip = &worldToClip; PolyDrawArgs args;
args.vinput = vertices; args.SetLight(GetColorTable(sub->sector->Colormap), lightlevel, PolyRenderer::Instance()->Light.WallGlobVis(foggy), false);
args.vcount = sub->numlines; args.SetSubsectorDepth(subsectorDepth);
args.mode = TriangleDrawMode::Fan; args.SetTransform(&worldToClip);
args.ccw = true; args.SetStyle(TriBlendMode::Copy);
args.stenciltestvalue = stencilValue; args.SetFaceCullCCW(true);
args.stencilwritevalue = stencilValue + 1; args.SetStencilTestValue(stencilValue);
args.SetWriteStencil(true, stencilValue + 1);
args.SetTexture(tex); args.SetTexture(tex);
args.SetColormap(GetColorTable(sub->sector->Colormap));
args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w); args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w);
args.blendmode = TriBlendMode::Copy; args.DrawArray(vertices, sub->numlines, PolyDrawMode::TriangleFan);
PolyTriangleDrawer::draw(args);
} }
void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlane, PolyCull &cull, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, bool ceiling, double skyHeight, std::vector<std::unique_ptr<PolyDrawSectorPortal>> &sectorPortals) void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlane, PolyCull &cull, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, bool ceiling, double skyHeight, std::vector<std::unique_ptr<PolyDrawSectorPortal>> &sectorPortals)
@ -291,16 +281,6 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan
UVTransform transform(ceiling ? frontsector->planes[sector_t::ceiling].xform : frontsector->planes[sector_t::floor].xform, tex); UVTransform transform(ceiling ? frontsector->planes[sector_t::ceiling].xform : frontsector->planes[sector_t::floor].xform, tex);
PolyCameraLight *cameraLight = PolyCameraLight::Instance();
PolyDrawArgs args;
args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy);// ->SlopePlaneGlobVis(foggy) * 48.0f;
args.uniforms.light = frontsector->lightlevel;
if (cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap())
args.uniforms.light = 255;
args.uniforms.flags = TriUniforms::nearest_filter;
args.uniforms.subsectorDepth = isSky ? RenderPolyScene::SkySubsectorDepth : subsectorDepth;
TriVertex *vertices = PolyRenderer::Instance()->FrameMemory.AllocMemory<TriVertex>(sub->numlines); TriVertex *vertices = PolyRenderer::Instance()->FrameMemory.AllocMemory<TriVertex>(sub->numlines);
if (ceiling) if (ceiling)
@ -320,37 +300,36 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan
} }
} }
args.objectToClip = &worldToClip; PolyDrawArgs args;
args.vinput = vertices; args.SetLight(GetColorTable(frontsector->Colormap, frontsector->SpecialColors[ceiling]), frontsector->lightlevel, PolyRenderer::Instance()->Light.WallGlobVis(foggy), false);
args.vcount = sub->numlines; args.SetSubsectorDepth(isSky ? RenderPolyScene::SkySubsectorDepth : subsectorDepth);
args.mode = TriangleDrawMode::Fan; args.SetTransform(&worldToClip);
args.ccw = ccw; args.SetFaceCullCCW(ccw);
args.stenciltestvalue = stencilValue; args.SetStencilTestValue(stencilValue);
args.stencilwritevalue = stencilValue + 1; args.SetWriteStencil(true, stencilValue + 1);
args.SetColormap(GetColorTable(frontsector->Colormap, frontsector->SpecialColors[ceiling]));
args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w); args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w);
if (!isSky) if (!isSky)
{ {
args.SetTexture(tex); args.SetTexture(tex);
args.blendmode = TriBlendMode::Copy; args.SetStyle(TriBlendMode::Copy);
PolyTriangleDrawer::draw(args); args.DrawArray(vertices, sub->numlines, PolyDrawMode::TriangleFan);
} }
else else
{ {
if (portal) if (portal)
{ {
args.stencilwritevalue = polyportal->StencilValue; args.SetWriteStencil(true, polyportal->StencilValue);
polyportal->Shape.push_back({ args.vinput, args.vcount, args.ccw, subsectorDepth }); polyportal->Shape.push_back({ vertices, (int)sub->numlines, ccw, subsectorDepth });
} }
else else
{ {
args.stencilwritevalue = 255; args.SetWriteStencil(true, 255);
} }
args.writeColor = false; args.SetWriteColor(false);
args.writeSubsector = false; args.SetWriteSubsectorDepth(false);
PolyTriangleDrawer::draw(args); args.DrawArray(vertices, sub->numlines, PolyDrawMode::TriangleFan);
for (uint32_t i = 0; i < sub->numlines; i++) for (uint32_t i = 0; i < sub->numlines; i++)
{ {
@ -414,13 +393,11 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan
wallvert[3] = PlaneVertex(line->v1, skyHeight, transform); wallvert[3] = PlaneVertex(line->v1, skyHeight, transform);
} }
args.vinput = wallvert; args.DrawArray(wallvert, 4, PolyDrawMode::TriangleFan);
args.vcount = 4;
PolyTriangleDrawer::draw(args);
if (portal) if (portal)
{ {
polyportal->Shape.push_back({ args.vinput, args.vcount, args.ccw, subsectorDepth }); polyportal->Shape.push_back({ wallvert, 4, ccw, subsectorDepth });
} }
} }
} }

View file

@ -249,40 +249,33 @@ void RenderPolyScene::RenderPortals(int portalDepth)
else // Fill with black else // Fill with black
{ {
PolyDrawArgs args; PolyDrawArgs args;
args.objectToClip = &WorldToClip; args.SetTransform(&WorldToClip);
args.mode = TriangleDrawMode::Fan; args.SetLight(&NormalLight, 255, PolyRenderer::Instance()->Light.WallGlobVis(foggy), true);
args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy); args.SetColor(0, 0);
args.uniforms.color = 0;
args.uniforms.light = 255;
args.uniforms.flags = TriUniforms::fixed_light;
args.SetClipPlane(PortalPlane.x, PortalPlane.y, PortalPlane.z, PortalPlane.w); args.SetClipPlane(PortalPlane.x, PortalPlane.y, PortalPlane.z, PortalPlane.w);
args.SetStyle(TriBlendMode::Copy);
for (auto &portal : SectorPortals) for (auto &portal : SectorPortals)
{ {
args.stenciltestvalue = portal->StencilValue; args.SetStencilTestValue(portal->StencilValue);
args.stencilwritevalue = portal->StencilValue + 1; args.SetWriteStencil(true, portal->StencilValue + 1);
for (const auto &verts : portal->Shape) for (const auto &verts : portal->Shape)
{ {
args.vinput = verts.Vertices; args.SetFaceCullCCW(verts.Ccw);
args.vcount = verts.Count; args.SetSubsectorDepth(verts.SubsectorDepth);
args.ccw = verts.Ccw; args.DrawArray(verts.Vertices, verts.Count, PolyDrawMode::TriangleFan);
args.uniforms.subsectorDepth = verts.SubsectorDepth;
args.blendmode = TriBlendMode::Copy;
PolyTriangleDrawer::draw(args);
} }
} }
for (auto &portal : LinePortals) for (auto &portal : LinePortals)
{ {
args.stenciltestvalue = portal->StencilValue; args.SetStencilTestValue(portal->StencilValue);
args.stencilwritevalue = portal->StencilValue + 1; args.SetWriteStencil(true, portal->StencilValue + 1);
for (const auto &verts : portal->Shape) for (const auto &verts : portal->Shape)
{ {
args.vinput = verts.Vertices; args.SetFaceCullCCW(verts.Ccw);
args.vcount = verts.Count; args.SetSubsectorDepth(verts.SubsectorDepth);
args.ccw = verts.Ccw; args.DrawArray(verts.Vertices, verts.Count, PolyDrawMode::TriangleFan);
args.uniforms.subsectorDepth = verts.SubsectorDepth;
PolyTriangleDrawer::draw(args);
} }
} }
} }
@ -298,19 +291,16 @@ void RenderPolyScene::RenderTranslucent(int portalDepth)
portal->RenderTranslucent(portalDepth + 1); portal->RenderTranslucent(portalDepth + 1);
PolyDrawArgs args; PolyDrawArgs args;
args.objectToClip = &WorldToClip; args.SetTransform(&WorldToClip);
args.mode = TriangleDrawMode::Fan; args.SetStencilTestValue(portal->StencilValue + 1);
args.stenciltestvalue = portal->StencilValue + 1; args.SetWriteStencil(true, StencilValue + 1);
args.stencilwritevalue = StencilValue + 1;
args.SetClipPlane(PortalPlane.x, PortalPlane.y, PortalPlane.z, PortalPlane.w); args.SetClipPlane(PortalPlane.x, PortalPlane.y, PortalPlane.z, PortalPlane.w);
for (const auto &verts : portal->Shape) for (const auto &verts : portal->Shape)
{ {
args.vinput = verts.Vertices; args.SetFaceCullCCW(verts.Ccw);
args.vcount = verts.Count; args.SetSubsectorDepth(verts.SubsectorDepth);
args.ccw = verts.Ccw; args.SetWriteColor(false);
args.uniforms.subsectorDepth = verts.SubsectorDepth; args.DrawArray(verts.Vertices, verts.Count, PolyDrawMode::TriangleFan);
args.writeColor = false;
PolyTriangleDrawer::draw(args);
} }
} }
@ -320,19 +310,16 @@ void RenderPolyScene::RenderTranslucent(int portalDepth)
portal->RenderTranslucent(portalDepth + 1); portal->RenderTranslucent(portalDepth + 1);
PolyDrawArgs args; PolyDrawArgs args;
args.objectToClip = &WorldToClip; args.SetTransform(&WorldToClip);
args.mode = TriangleDrawMode::Fan; args.SetStencilTestValue(portal->StencilValue + 1);
args.stenciltestvalue = portal->StencilValue + 1; args.SetWriteStencil(true, StencilValue + 1);
args.stencilwritevalue = StencilValue + 1;
args.SetClipPlane(PortalPlane.x, PortalPlane.y, PortalPlane.z, PortalPlane.w); args.SetClipPlane(PortalPlane.x, PortalPlane.y, PortalPlane.z, PortalPlane.w);
for (const auto &verts : portal->Shape) for (const auto &verts : portal->Shape)
{ {
args.vinput = verts.Vertices; args.SetFaceCullCCW(verts.Ccw);
args.vcount = verts.Count; args.SetSubsectorDepth(verts.SubsectorDepth);
args.ccw = verts.Ccw; args.SetWriteColor(false);
args.uniforms.subsectorDepth = verts.SubsectorDepth; args.DrawArray(verts.Vertices, verts.Count, PolyDrawMode::TriangleFan);
args.writeColor = false;
PolyTriangleDrawer::draw(args);
} }
} }
} }

View file

@ -38,7 +38,6 @@ PolySkyDome::PolySkyDome()
void PolySkyDome::Render(const TriMatrix &worldToClip) void PolySkyDome::Render(const TriMatrix &worldToClip)
{ {
FTextureID sky1tex, sky2tex; FTextureID sky1tex, sky2tex;
bool foggy = false;
if ((level.flags & LEVEL_SWAPSKIES) && !(level.flags & LEVEL_DOUBLESKY)) if ((level.flags & LEVEL_SWAPSKIES) && !(level.flags & LEVEL_DOUBLESKY))
sky1tex = sky2texture; sky1tex = sky2texture;
else else
@ -57,14 +56,11 @@ void PolySkyDome::Render(const TriMatrix &worldToClip)
int rc = mRows + 1; int rc = mRows + 1;
PolyDrawArgs args; PolyDrawArgs args;
args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy); args.SetLight(&NormalLight, 255, PolyRenderer::Instance()->Light.WallGlobVis(false), true);
args.uniforms.light = 255; args.SetSubsectorDepth(RenderPolyScene::SkySubsectorDepth);
args.uniforms.flags = TriUniforms::nearest_filter; args.SetTransform(&objectToClip);
args.uniforms.subsectorDepth = RenderPolyScene::SkySubsectorDepth; args.SetStencilTestValue(255);
args.objectToClip = &objectToClip; args.SetWriteStencil(true, 1);
args.stenciltestvalue = 255;
args.stencilwritevalue = 1;
args.SetColormap(&NormalLight);
args.SetClipPlane(0.0f, 0.0f, 0.0f, 0.0f); args.SetClipPlane(0.0f, 0.0f, 0.0f, 0.0f);
RenderCapColorRow(args, frontskytex, 0, false); RenderCapColorRow(args, frontskytex, 0, false);
@ -84,28 +80,21 @@ void PolySkyDome::Render(const TriMatrix &worldToClip)
void PolySkyDome::RenderRow(PolyDrawArgs &args, int row, uint32_t capcolor) void PolySkyDome::RenderRow(PolyDrawArgs &args, int row, uint32_t capcolor)
{ {
args.vinput = &mVertices[mPrimStart[row]]; args.SetFaceCullCCW(false);
args.vcount = mPrimStart[row + 1] - mPrimStart[row]; args.SetColor(capcolor, 0);
args.mode = TriangleDrawMode::Strip; args.SetStyle(TriBlendMode::Skycap);
args.ccw = false; args.DrawArray(&mVertices[mPrimStart[row]], mPrimStart[row + 1] - mPrimStart[row], PolyDrawMode::TriangleStrip);
args.uniforms.color = capcolor;
args.blendmode = TriBlendMode::Skycap;
PolyTriangleDrawer::draw(args);
} }
void PolySkyDome::RenderCapColorRow(PolyDrawArgs &args, FTexture *skytex, int row, bool bottomCap) void PolySkyDome::RenderCapColorRow(PolyDrawArgs &args, FTexture *skytex, int row, bool bottomCap)
{ {
uint32_t solid = skytex->GetSkyCapColor(bottomCap); uint32_t solid = skytex->GetSkyCapColor(bottomCap);
if (!PolyRenderer::Instance()->RenderTarget->IsBgra()) uint8_t palsolid = RGB32k.RGB[(RPART(solid) >> 3)][(GPART(solid) >> 3)][(BPART(solid) >> 3)];
solid = RGB32k.RGB[(RPART(solid) >> 3)][(GPART(solid) >> 3)][(BPART(solid) >> 3)];
args.vinput = &mVertices[mPrimStart[row]]; args.SetFaceCullCCW(bottomCap);
args.vcount = mPrimStart[row + 1] - mPrimStart[row]; args.SetColor(solid, palsolid);
args.mode = TriangleDrawMode::Fan; args.SetStyle(TriBlendMode::Copy);
args.ccw = bottomCap; args.DrawArray(&mVertices[mPrimStart[row]], mPrimStart[row + 1] - mPrimStart[row], PolyDrawMode::TriangleFan);
args.uniforms.color = solid;
args.blendmode = TriBlendMode::Copy;
PolyTriangleDrawer::draw(args);
} }
void PolySkyDome::CreateDome() void PolySkyDome::CreateDome()

View file

@ -136,136 +136,80 @@ void RenderPolySprite::Render(const TriMatrix &worldToClip, const Vec4f &clipPla
} }
bool fullbrightSprite = ((thing->renderflags & RF_FULLBRIGHT) || (thing->flags5 & MF5_BRIGHT)); bool fullbrightSprite = ((thing->renderflags & RF_FULLBRIGHT) || (thing->flags5 & MF5_BRIGHT));
PolyCameraLight *cameraLight = PolyCameraLight::Instance(); int lightlevel = fullbrightSprite ? 255 : thing->Sector->lightlevel + actualextralight;
PolyDrawArgs args; PolyDrawArgs args;
args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.SpriteGlobVis(foggy); args.SetLight(GetColorTable(sub->sector->Colormap, sub->sector->SpecialColors[sector_t::sprites], true), lightlevel, PolyRenderer::Instance()->Light.SpriteGlobVis(foggy), fullbrightSprite);
args.uniforms.flags = TriUniforms::nearest_filter; args.SetSubsectorDepth(subsectorDepth);
if (fullbrightSprite || cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap()) args.SetTransform(&worldToClip);
{ args.SetFaceCullCCW(true);
args.uniforms.light = 255; args.SetStencilTestValue(stencilValue);
args.uniforms.flags |= TriUniforms::fixed_light; args.SetWriteStencil(true, stencilValue);
}
else
{
args.uniforms.light = thing->Sector->lightlevel + actualextralight;
}
args.uniforms.subsectorDepth = subsectorDepth;
args.objectToClip = &worldToClip;
args.vinput = vertices;
args.vcount = 4;
args.mode = TriangleDrawMode::Fan;
args.ccw = true;
args.stenciltestvalue = stencilValue;
args.stencilwritevalue = stencilValue;
args.SetTexture(tex, thing->Translation); args.SetTexture(tex, thing->Translation);
args.SetColormap(GetColorTable(sub->sector->Colormap, sub->sector->SpecialColors[sector_t::sprites], true));
args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w); args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w);
TriBlendMode blendmode;
if (thing->RenderStyle == LegacyRenderStyles[STYLE_Normal] || if (thing->RenderStyle == LegacyRenderStyles[STYLE_Normal] ||
(r_drawfuzz == 0 && thing->RenderStyle == LegacyRenderStyles[STYLE_OptFuzzy])) (r_drawfuzz == 0 && thing->RenderStyle == LegacyRenderStyles[STYLE_OptFuzzy]))
{ {
args.uniforms.destalpha = 0; args.SetStyle(args.Translation() ? TriBlendMode::TranslateAdd : TriBlendMode::Add, 1.0, 0.0);
args.uniforms.srcalpha = 256;
blendmode = args.translation ? TriBlendMode::TranslateAdd : TriBlendMode::Add;
} }
else if (thing->RenderStyle == LegacyRenderStyles[STYLE_Add] && fullbrightSprite && thing->Alpha == 1.0 && args.translation == nullptr) else if (thing->RenderStyle == LegacyRenderStyles[STYLE_Add] && fullbrightSprite && thing->Alpha == 1.0 && !args.Translation())
{ {
args.uniforms.destalpha = 256; args.SetStyle(TriBlendMode::AddSrcColorOneMinusSrcColor, 1.0, 1.0);
args.uniforms.srcalpha = 256;
blendmode = TriBlendMode::AddSrcColorOneMinusSrcColor;
} }
else if (thing->RenderStyle == LegacyRenderStyles[STYLE_Add]) else if (thing->RenderStyle == LegacyRenderStyles[STYLE_Add])
{ {
args.uniforms.destalpha = (uint32_t)(1.0 * 256); args.SetStyle(args.Translation() ? TriBlendMode::TranslateAdd : TriBlendMode::Add, thing->Alpha, 1.0);
args.uniforms.srcalpha = (uint32_t)(thing->Alpha * 256);
blendmode = args.translation ? TriBlendMode::TranslateAdd : TriBlendMode::Add;
} }
else if (thing->RenderStyle == LegacyRenderStyles[STYLE_Subtract]) else if (thing->RenderStyle == LegacyRenderStyles[STYLE_Subtract])
{ {
args.uniforms.destalpha = (uint32_t)(1.0 * 256); args.SetStyle(args.Translation() ? TriBlendMode::TranslateRevSub : TriBlendMode::RevSub, thing->Alpha, 1.0);
args.uniforms.srcalpha = (uint32_t)(thing->Alpha * 256);
blendmode = args.translation ? TriBlendMode::TranslateRevSub : TriBlendMode::RevSub;
} }
else if (thing->RenderStyle == LegacyRenderStyles[STYLE_SoulTrans]) else if (thing->RenderStyle == LegacyRenderStyles[STYLE_SoulTrans])
{ {
args.uniforms.destalpha = (uint32_t)(256 - transsouls * 256); args.SetStyle(args.Translation() ? TriBlendMode::TranslateAdd : TriBlendMode::Add, transsouls, 1.0 - transsouls);
args.uniforms.srcalpha = (uint32_t)(transsouls * 256);
blendmode = args.translation ? TriBlendMode::TranslateAdd : TriBlendMode::Add;
} }
else if (thing->RenderStyle == LegacyRenderStyles[STYLE_Fuzzy] || else if (thing->RenderStyle == LegacyRenderStyles[STYLE_Fuzzy] ||
(r_drawfuzz == 2 && thing->RenderStyle == LegacyRenderStyles[STYLE_OptFuzzy])) (r_drawfuzz == 2 && thing->RenderStyle == LegacyRenderStyles[STYLE_OptFuzzy]))
{ // NYI - Fuzzy - for now, just a copy of "Shadow" { // NYI - Fuzzy - for now, just a copy of "Shadow"
args.uniforms.destalpha = 160; args.SetStyle(args.Translation() ? TriBlendMode::TranslateAdd : TriBlendMode::Add, 0.0, 160 / 255.0);
args.uniforms.srcalpha = 0;
blendmode = args.translation ? TriBlendMode::TranslateAdd : TriBlendMode::Add;
} }
else if (thing->RenderStyle == LegacyRenderStyles[STYLE_Shadow] || else if (thing->RenderStyle == LegacyRenderStyles[STYLE_Shadow] ||
(r_drawfuzz == 1 && thing->RenderStyle == LegacyRenderStyles[STYLE_OptFuzzy])) (r_drawfuzz == 1 && thing->RenderStyle == LegacyRenderStyles[STYLE_OptFuzzy]))
{ {
args.uniforms.destalpha = 160; args.SetStyle(args.Translation() ? TriBlendMode::TranslateAdd : TriBlendMode::Add, 0.0, 160 / 255.0);
args.uniforms.srcalpha = 0;
blendmode = args.translation ? TriBlendMode::TranslateAdd : TriBlendMode::Add;
} }
else if (thing->RenderStyle == LegacyRenderStyles[STYLE_TranslucentStencil]) else if (thing->RenderStyle == LegacyRenderStyles[STYLE_TranslucentStencil])
{ {
args.uniforms.destalpha = (uint32_t)(256 - thing->Alpha * 256); args.SetColor(0xff000000 | thing->fillcolor, thing->fillcolor >> 24);
args.uniforms.srcalpha = (uint32_t)(thing->Alpha * 256); args.SetStyle(TriBlendMode::Stencil, thing->Alpha, 1.0 - thing->Alpha);
args.uniforms.color = 0xff000000 | thing->fillcolor;
blendmode = TriBlendMode::Stencil;
} }
else if (thing->RenderStyle == LegacyRenderStyles[STYLE_AddStencil]) else if (thing->RenderStyle == LegacyRenderStyles[STYLE_AddStencil])
{ {
args.uniforms.destalpha = 256; args.SetColor(0xff000000 | thing->fillcolor, thing->fillcolor >> 24);
args.uniforms.srcalpha = (uint32_t)(thing->Alpha * 256); args.SetStyle(TriBlendMode::Stencil, thing->Alpha, 1.0 - thing->Alpha);
args.uniforms.color = 0xff000000 | thing->fillcolor;
blendmode = TriBlendMode::Stencil;
} }
else if (thing->RenderStyle == LegacyRenderStyles[STYLE_Shaded]) else if (thing->RenderStyle == LegacyRenderStyles[STYLE_Shaded])
{ {
args.uniforms.srcalpha = (uint32_t)(thing->Alpha * 256); args.SetColor(0, 0);
args.uniforms.destalpha = 256 - args.uniforms.srcalpha; args.SetStyle(TriBlendMode::Shaded, thing->Alpha, 1.0 - thing->Alpha);
args.uniforms.color = 0; args.SetTexture(tex, thing->Translation, true);
blendmode = TriBlendMode::Shaded;
} }
else if (thing->RenderStyle == LegacyRenderStyles[STYLE_AddShaded]) else if (thing->RenderStyle == LegacyRenderStyles[STYLE_AddShaded])
{ {
args.uniforms.destalpha = 256; args.SetColor(0, 0);
args.uniforms.srcalpha = (uint32_t)(thing->Alpha * 256); args.SetStyle(TriBlendMode::Shaded, thing->Alpha, 1.0 - thing->Alpha);
args.uniforms.color = 0; args.SetTexture(tex, thing->Translation, true);
blendmode = TriBlendMode::Shaded;
} }
else else
{ {
args.uniforms.destalpha = (uint32_t)(256 - thing->Alpha * 256); args.SetStyle(args.Translation() ? TriBlendMode::TranslateAdd : TriBlendMode::Add, thing->Alpha, 1.0 - thing->Alpha);
args.uniforms.srcalpha = (uint32_t)(thing->Alpha * 256);
blendmode = args.translation ? TriBlendMode::TranslateAdd : TriBlendMode::Add;
} }
if (blendmode == TriBlendMode::Shaded) args.SetSubsectorDepthTest(true);
{ args.SetWriteSubsectorDepth(false);
args.SetTexture(tex, thing->Translation, true); args.SetWriteStencil(false);
} args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan);
if (!PolyRenderer::Instance()->RenderTarget->IsBgra())
{
uint32_t r = (args.uniforms.color >> 16) & 0xff;
uint32_t g = (args.uniforms.color >> 8) & 0xff;
uint32_t b = args.uniforms.color & 0xff;
args.uniforms.color = RGB32k.RGB[r >> 3][g >> 3][b >> 3];
if (blendmode == TriBlendMode::Sub) // Sub crashes in pal mode for some weird reason.
blendmode = TriBlendMode::Add;
}
args.subsectorTest = true;
args.writeSubsector = false;
args.writeStencil = false;
args.blendmode = blendmode;
PolyTriangleDrawer::draw(args);
} }
bool RenderPolySprite::IsThingCulled(AActor *thing) bool RenderPolySprite::IsThingCulled(AActor *thing)

View file

@ -248,32 +248,23 @@ void RenderPolyWall::Render(const TriMatrix &worldToClip, const Vec4f &clipPlane
} }
PolyDrawArgs args; PolyDrawArgs args;
args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy); args.SetLight(GetColorTable(Line->frontsector->Colormap, Line->frontsector->SpecialColors[sector_t::walltop]), GetLightLevel(), PolyRenderer::Instance()->Light.WallGlobVis(foggy), false);
args.uniforms.light = GetLightLevel(); args.SetSubsectorDepth(SubsectorDepth);
args.uniforms.flags = TriUniforms::nearest_filter; args.SetTransform(&worldToClip);
args.uniforms.subsectorDepth = SubsectorDepth; args.SetFaceCullCCW(true);
args.objectToClip = &worldToClip; args.SetStencilTestValue(StencilValue);
args.vinput = vertices; args.SetWriteStencil(true, StencilValue + 1);
args.vcount = 4;
args.mode = TriangleDrawMode::Fan;
args.ccw = true;
args.stenciltestvalue = StencilValue;
args.stencilwritevalue = StencilValue + 1;
if (tex) if (tex)
args.SetTexture(tex); args.SetTexture(tex);
args.SetColormap(GetColorTable(Line->frontsector->Colormap, Line->frontsector->SpecialColors[sector_t::walltop]));
args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w); args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w);
//if (Side && Side->lighthead)
// args.uniforms.light = 255; // Make walls touched by a light fullbright!
if (Polyportal) if (Polyportal)
{ {
args.stencilwritevalue = Polyportal->StencilValue; args.SetWriteStencil(true, Polyportal->StencilValue);
args.writeColor = false; args.SetWriteColor(false);
args.writeSubsector = false; args.SetWriteSubsectorDepth(false);
PolyTriangleDrawer::draw(args); args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan);
Polyportal->Shape.push_back({ args.vinput, args.vcount, args.ccw, args.uniforms.subsectorDepth }); Polyportal->Shape.push_back({ vertices, 4, true, SubsectorDepth });
angle_t angle1, angle2; angle_t angle1, angle2;
if (cull.GetAnglesForLine(v1.X, v1.Y, v2.X, v2.Y, angle1, angle2)) if (cull.GetAnglesForLine(v1.X, v1.Y, v2.X, v2.Y, angle1, angle2))
@ -281,21 +272,16 @@ void RenderPolyWall::Render(const TriMatrix &worldToClip, const Vec4f &clipPlane
} }
else if (!Masked) else if (!Masked)
{ {
args.blendmode = TriBlendMode::Copy; args.SetStyle(TriBlendMode::Copy);
PolyTriangleDrawer::draw(args); args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan);
} }
else else
{ {
args.uniforms.destalpha = (Line->flags & ML_ADDTRANS) ? 256 : (uint32_t)(256 - Line->alpha * 256); args.SetStyle((Line->flags & ML_ADDTRANS) ? TriBlendMode::Add : TriBlendMode::AlphaBlend, Line->alpha, 1.0);
args.uniforms.srcalpha = (uint32_t)(Line->alpha * 256); args.SetSubsectorDepthTest(true);
args.subsectorTest = true; args.SetWriteSubsectorDepth(true);
args.writeSubsector = false; args.SetWriteStencil(false);
args.writeStencil = false; args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan);
if (args.uniforms.destalpha == 0 && args.uniforms.srcalpha == 256)
args.blendmode = TriBlendMode::AlphaBlend;
else
args.blendmode = TriBlendMode::Add;
PolyTriangleDrawer::draw(args);
} }
RenderPolyDecal::RenderWallDecals(worldToClip, clipPlane, LineSeg, SubsectorDepth, StencilValue); RenderPolyDecal::RenderWallDecals(worldToClip, clipPlane, LineSeg, SubsectorDepth, StencilValue);

View file

@ -97,35 +97,18 @@ void RenderPolyWallSprite::Render(const TriMatrix &worldToClip, const Vec4f &cli
} }
bool fullbrightSprite = ((thing->renderflags & RF_FULLBRIGHT) || (thing->flags5 & MF5_BRIGHT)); bool fullbrightSprite = ((thing->renderflags & RF_FULLBRIGHT) || (thing->flags5 & MF5_BRIGHT));
PolyCameraLight *cameraLight = PolyCameraLight::Instance(); int lightlevel = fullbrightSprite ? 255 : thing->Sector->lightlevel + actualextralight;
PolyDrawArgs args; PolyDrawArgs args;
args.uniforms.globvis = (float)PolyRenderer::Instance()->Light.WallGlobVis(foggy); args.SetLight(GetColorTable(sub->sector->Colormap, sub->sector->SpecialColors[sector_t::sprites], true), lightlevel, PolyRenderer::Instance()->Light.WallGlobVis(foggy), fullbrightSprite);
if (fullbrightSprite || cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap()) args.SetTransform(&worldToClip);
{ args.SetFaceCullCCW(true);
args.uniforms.light = 255; args.SetStencilTestValue(stencilValue);
args.uniforms.flags = TriUniforms::fixed_light | TriUniforms::nearest_filter;
}
else
{
args.uniforms.light = thing->Sector->lightlevel + actualextralight;
args.uniforms.flags = TriUniforms::nearest_filter;
}
args.uniforms.subsectorDepth = subsectorDepth;
args.objectToClip = &worldToClip;
args.vinput = vertices;
args.vcount = 4;
args.mode = TriangleDrawMode::Fan;
args.ccw = true;
args.stenciltestvalue = stencilValue;
args.stencilwritevalue = stencilValue;
args.SetTexture(tex); args.SetTexture(tex);
args.SetColormap(GetColorTable(sub->sector->Colormap, sub->sector->SpecialColors[sector_t::sprites], true));
args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w); args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w);
args.subsectorTest = true; args.SetSubsectorDepthTest(true);
args.writeSubsector = false; args.SetWriteSubsectorDepth(false);
args.writeStencil = false; args.SetWriteStencil(false);
args.blendmode = TriBlendMode::AlphaBlend; args.SetStyle(TriBlendMode::AlphaBlend);
PolyTriangleDrawer::draw(args); args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan);
} }