2017-02-03 23:25:37 +00:00
|
|
|
/*
|
|
|
|
** Renderer multithreading framework
|
|
|
|
** 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 <stdlib.h>
|
|
|
|
#include "templates.h"
|
|
|
|
#include "doomdef.h"
|
|
|
|
#include "m_bbox.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "p_lnspec.h"
|
|
|
|
#include "p_setup.h"
|
|
|
|
#include "a_sharedglobal.h"
|
|
|
|
#include "g_level.h"
|
|
|
|
#include "p_effect.h"
|
|
|
|
#include "doomstat.h"
|
|
|
|
#include "r_state.h"
|
|
|
|
#include "v_palette.h"
|
|
|
|
#include "r_sky.h"
|
|
|
|
#include "po_man.h"
|
|
|
|
#include "r_data/colormaps.h"
|
|
|
|
#include "r_renderthread.h"
|
|
|
|
#include "swrenderer/things/r_visiblespritelist.h"
|
|
|
|
#include "swrenderer/scene/r_portal.h"
|
|
|
|
#include "swrenderer/scene/r_opaque_pass.h"
|
|
|
|
#include "swrenderer/scene/r_translucent_pass.h"
|
|
|
|
#include "swrenderer/scene/r_3dfloors.h"
|
|
|
|
#include "swrenderer/scene/r_scene.h"
|
|
|
|
#include "swrenderer/things/r_playersprite.h"
|
|
|
|
#include "swrenderer/plane/r_visibleplanelist.h"
|
|
|
|
#include "swrenderer/segments/r_drawsegment.h"
|
|
|
|
#include "swrenderer/segments/r_clipsegment.h"
|
2017-02-04 11:38:05 +00:00
|
|
|
#include "swrenderer/drawers/r_thread.h"
|
|
|
|
#include "swrenderer/drawers/r_draw.h"
|
|
|
|
#include "swrenderer/drawers/r_draw_rgba.h"
|
|
|
|
#include "swrenderer/drawers/r_draw_pal.h"
|
|
|
|
#include "swrenderer/viewport/r_viewport.h"
|
2017-02-04 01:50:52 +00:00
|
|
|
#include "r_memory.h"
|
2017-02-03 23:25:37 +00:00
|
|
|
|
|
|
|
namespace swrenderer
|
|
|
|
{
|
2017-02-04 14:51:54 +00:00
|
|
|
RenderThread::RenderThread(RenderScene *scene, bool mainThread)
|
2017-02-03 23:25:37 +00:00
|
|
|
{
|
2017-02-04 13:00:21 +00:00
|
|
|
Scene = scene;
|
2017-02-04 14:51:54 +00:00
|
|
|
MainThread = mainThread;
|
2017-02-04 01:50:52 +00:00
|
|
|
FrameMemory = std::make_unique<RenderMemory>();
|
2017-03-12 17:54:39 +00:00
|
|
|
Viewport = std::make_unique<RenderViewport>();
|
2017-03-12 19:40:00 +00:00
|
|
|
Light = std::make_unique<LightVisibility>();
|
2017-03-20 07:28:16 +00:00
|
|
|
DrawQueue = std::make_shared<DrawerCommandQueue>(FrameMemory.get());
|
2017-02-03 23:25:37 +00:00
|
|
|
OpaquePass = std::make_unique<RenderOpaquePass>(this);
|
|
|
|
TranslucentPass = std::make_unique<RenderTranslucentPass>(this);
|
|
|
|
SpriteList = std::make_unique<VisibleSpriteList>();
|
|
|
|
Portal = std::make_unique<RenderPortal>(this);
|
2017-02-06 15:04:27 +00:00
|
|
|
Clip3D = std::make_unique<Clip3DFloors>(this);
|
2017-02-03 23:25:37 +00:00
|
|
|
PlayerSprites = std::make_unique<RenderPlayerSprites>(this);
|
|
|
|
PlaneList = std::make_unique<VisiblePlaneList>(this);
|
|
|
|
DrawSegments = std::make_unique<DrawSegmentList>(this);
|
|
|
|
ClipSegments = std::make_unique<RenderClipSegment>();
|
2017-02-04 11:38:05 +00:00
|
|
|
tc_drawers = std::make_unique<SWTruecolorDrawers>(DrawQueue);
|
|
|
|
pal_drawers = std::make_unique<SWPalDrawers>(DrawQueue);
|
2017-02-03 23:25:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RenderThread::~RenderThread()
|
|
|
|
{
|
|
|
|
}
|
2017-02-04 11:38:05 +00:00
|
|
|
|
2017-03-12 17:54:39 +00:00
|
|
|
SWPixelFormatDrawers *RenderThread::Drawers(RenderViewport *viewport)
|
2017-02-04 11:38:05 +00:00
|
|
|
{
|
2017-03-12 17:54:39 +00:00
|
|
|
if (viewport->RenderTarget->IsBgra())
|
2017-02-04 11:38:05 +00:00
|
|
|
return tc_drawers.get();
|
|
|
|
else
|
|
|
|
return pal_drawers.get();
|
|
|
|
}
|
2017-03-12 21:53:20 +00:00
|
|
|
|
|
|
|
void RenderThread::PrepareTexture(FTexture *texture)
|
|
|
|
{
|
|
|
|
if (texture == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Textures may not have loaded/refreshed yet. The shared code doing
|
|
|
|
// this is not thread safe. By calling GetPixels in a mutex lock we
|
|
|
|
// make sure that only one thread is loading a texture at any given
|
|
|
|
// time.
|
|
|
|
//
|
|
|
|
// It is critical that this function is called before any direct
|
|
|
|
// calls to GetPixels for this to work.
|
|
|
|
|
|
|
|
static std::mutex loadmutex;
|
|
|
|
loadmutex.lock();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
texture->GetPixels();
|
|
|
|
const FTexture::Span *spans;
|
|
|
|
texture->GetColumn(0, &spans);
|
|
|
|
if (Viewport->RenderTarget->IsBgra())
|
|
|
|
{
|
|
|
|
texture->GetPixelsBgra();
|
|
|
|
texture->GetColumnBgra(0, &spans);
|
|
|
|
}
|
|
|
|
loadmutex.unlock();
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
loadmutex.unlock();
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
2017-02-03 23:25:37 +00:00
|
|
|
}
|