2016-12-30 01:20:24 +00:00
|
|
|
/*
|
|
|
|
** Triangle drawers
|
|
|
|
** Copyright (c) 2016 Magnus Norddahl
|
|
|
|
**
|
|
|
|
** This software is provided 'as-is', without any express or implied
|
|
|
|
** warranty. In no event will the authors be held liable for any damages
|
|
|
|
** arising from the use of this software.
|
|
|
|
**
|
|
|
|
** Permission is granted to anyone to use this software for any purpose,
|
|
|
|
** including commercial applications, and to alter it and redistribute it
|
|
|
|
** freely, subject to the following restrictions:
|
|
|
|
**
|
|
|
|
** 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
** claim that you wrote the original software. If you use this software
|
|
|
|
** in a product, an acknowledgment in the product documentation would be
|
|
|
|
** appreciated but is not required.
|
|
|
|
** 2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
** misrepresented as being the original software.
|
|
|
|
** 3. This notice may not be removed or altered from any source distribution.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include "templates.h"
|
|
|
|
#include "doomdef.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "w_wad.h"
|
|
|
|
#include "v_video.h"
|
|
|
|
#include "doomstat.h"
|
|
|
|
#include "st_stuff.h"
|
|
|
|
#include "g_game.h"
|
|
|
|
#include "g_level.h"
|
|
|
|
#include "r_data/r_translate.h"
|
|
|
|
#include "v_palette.h"
|
|
|
|
#include "r_data/colormaps.h"
|
2017-03-15 21:04:23 +00:00
|
|
|
#include "swrenderer/r_swcolormaps.h"
|
2016-12-30 01:20:24 +00:00
|
|
|
#include "poly_draw_args.h"
|
2017-02-02 14:24:21 +00:00
|
|
|
#include "swrenderer/viewport/r_viewport.h"
|
2016-12-30 01:20:24 +00:00
|
|
|
|
2017-03-26 15:12:20 +00:00
|
|
|
void PolyDrawArgs::SetClipPlane(const PolyClipPlane &plane)
|
2016-12-30 01:20:24 +00:00
|
|
|
{
|
2017-03-26 15:12:20 +00:00
|
|
|
mClipPlane[0] = plane.A;
|
|
|
|
mClipPlane[1] = plane.B;
|
|
|
|
mClipPlane[2] = plane.C;
|
|
|
|
mClipPlane[3] = plane.D;
|
2016-12-30 01:20:24 +00:00
|
|
|
}
|
|
|
|
|
2017-03-27 09:33:16 +00:00
|
|
|
void PolyDrawArgs::SetTexture(const uint8_t *texels, int width, int height)
|
|
|
|
{
|
|
|
|
mTexturePixels = texels;
|
|
|
|
mTextureWidth = width;
|
|
|
|
mTextureHeight = height;
|
|
|
|
mTranslation = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-12-30 01:20:24 +00:00
|
|
|
void PolyDrawArgs::SetTexture(FTexture *texture)
|
|
|
|
{
|
2017-03-26 08:10:55 +00:00
|
|
|
mTextureWidth = texture->GetWidth();
|
|
|
|
mTextureHeight = texture->GetHeight();
|
2017-03-20 07:28:16 +00:00
|
|
|
if (PolyRenderer::Instance()->RenderTarget->IsBgra())
|
2017-03-26 08:10:55 +00:00
|
|
|
mTexturePixels = (const uint8_t *)texture->GetPixelsBgra();
|
2016-12-30 01:20:24 +00:00
|
|
|
else
|
2017-03-26 08:10:55 +00:00
|
|
|
mTexturePixels = texture->GetPixels();
|
|
|
|
mTranslation = nullptr;
|
2016-12-30 01:20:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PolyDrawArgs::SetTexture(FTexture *texture, uint32_t translationID, bool forcePal)
|
|
|
|
{
|
|
|
|
if (translationID != 0xffffffff && translationID != 0)
|
|
|
|
{
|
|
|
|
FRemapTable *table = TranslationToTable(translationID);
|
|
|
|
if (table != nullptr && !table->Inactive)
|
|
|
|
{
|
2017-03-20 07:28:16 +00:00
|
|
|
if (PolyRenderer::Instance()->RenderTarget->IsBgra())
|
2017-03-26 08:10:55 +00:00
|
|
|
mTranslation = (uint8_t*)table->Palette;
|
2016-12-30 01:20:24 +00:00
|
|
|
else
|
2017-03-26 08:10:55 +00:00
|
|
|
mTranslation = table->Remap;
|
2016-12-30 01:20:24 +00:00
|
|
|
|
2017-03-26 08:10:55 +00:00
|
|
|
mTextureWidth = texture->GetWidth();
|
|
|
|
mTextureHeight = texture->GetHeight();
|
|
|
|
mTexturePixels = texture->GetPixels();
|
2016-12-30 01:20:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (forcePal)
|
|
|
|
{
|
2017-03-26 08:10:55 +00:00
|
|
|
mTextureWidth = texture->GetWidth();
|
|
|
|
mTextureHeight = texture->GetHeight();
|
|
|
|
mTexturePixels = texture->GetPixels();
|
2016-12-30 01:20:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetTexture(texture);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-26 08:10:55 +00:00
|
|
|
void PolyDrawArgs::SetLight(FSWColormap *base_colormap, uint32_t lightlevel, double globVis, bool fixed)
|
2016-12-30 01:20:24 +00:00
|
|
|
{
|
2017-03-26 08:10:55 +00:00
|
|
|
mGlobVis = (float)globVis;
|
|
|
|
|
|
|
|
PolyCameraLight *cameraLight = PolyCameraLight::Instance();
|
|
|
|
if (cameraLight->FixedLightLevel() >= 0 || cameraLight->FixedColormap())
|
|
|
|
{
|
|
|
|
lightlevel = cameraLight->FixedLightLevel() >= 0 ? cameraLight->FixedLightLevel() : 255;
|
|
|
|
fixed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
mLight = clamp<uint32_t>(lightlevel, 0, 255);
|
|
|
|
mFixedLight = fixed;
|
|
|
|
mLightRed = base_colormap->Color.r * 256 / 255;
|
|
|
|
mLightGreen = base_colormap->Color.g * 256 / 255;
|
|
|
|
mLightBlue = base_colormap->Color.b * 256 / 255;
|
|
|
|
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;
|
|
|
|
}
|
2016-12-30 01:20:24 +00:00
|
|
|
else
|
2017-03-26 08:10:55 +00:00
|
|
|
{
|
|
|
|
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());
|
2016-12-30 01:20:24 +00:00
|
|
|
}
|