2018-04-05 21:08:09 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Copyright(C) 2004-2018 Christoph Oelckers
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with this program. If not, see http://www.gnu.org/licenses/
|
|
|
|
//
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
/*
|
2018-05-05 09:44:42 +00:00
|
|
|
** r_swscene.cpp
|
|
|
|
** render the software scene through the hardware rendering backend
|
2018-04-05 21:08:09 +00:00
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2018-04-24 21:06:34 +00:00
|
|
|
#include "hwrenderer/textures/hw_ihwtexture.h"
|
2018-04-26 22:53:58 +00:00
|
|
|
#include "hwrenderer/textures/hw_material.h"
|
|
|
|
#include "r_renderer.h"
|
2018-05-05 09:44:42 +00:00
|
|
|
#include "r_swscene.h"
|
2018-04-05 21:08:09 +00:00
|
|
|
#include "w_wad.h"
|
|
|
|
#include "d_player.h"
|
|
|
|
#include "textures/bitmap.h"
|
|
|
|
#include "swrenderer/scene/r_light.h"
|
|
|
|
|
|
|
|
// [RH] Base blending values (for e.g. underwater)
|
|
|
|
int BaseBlendR, BaseBlendG, BaseBlendB;
|
|
|
|
float BaseBlendA;
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-04-08 19:19:57 +00:00
|
|
|
class FSWPaletteTexture : public FTexture
|
2018-04-05 21:08:09 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
FSWPaletteTexture()
|
|
|
|
{
|
|
|
|
Width = 256;
|
|
|
|
Height = 1;
|
|
|
|
UseType = ETextureType::MiscPatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf)
|
|
|
|
{
|
2018-04-08 11:04:44 +00:00
|
|
|
PalEntry *pe = (PalEntry*)bmp->GetPixels();
|
|
|
|
for (int i = 0; i < 256; i++)
|
|
|
|
{
|
|
|
|
pe[i] = GPalette.BaseColors[i].d | 0xff000000;
|
|
|
|
}
|
2018-04-05 21:08:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-04-08 19:19:57 +00:00
|
|
|
class FSWSceneTexture : public FTexture
|
2018-04-05 21:08:09 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
FSWSceneTexture(int w, int h, int bits)
|
|
|
|
{
|
|
|
|
Width = w;
|
|
|
|
Height = h;
|
|
|
|
WidthBits = bits;
|
|
|
|
UseType = ETextureType::SWCanvas;
|
2018-04-24 18:41:52 +00:00
|
|
|
bNoCompress = true;
|
2018-04-24 21:51:19 +00:00
|
|
|
SystemTexture[0] = screen->CreateHardwareTexture(this);
|
2018-04-05 21:08:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This is just a wrapper around the hardware texture and should never call the bitmap getters - if it does, something is wrong.
|
|
|
|
};
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// SWSceneDrawer :: CreateResources
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
SWSceneDrawer::SWSceneDrawer()
|
|
|
|
{
|
|
|
|
PaletteTexture = new FSWPaletteTexture;
|
|
|
|
}
|
|
|
|
|
|
|
|
SWSceneDrawer::~SWSceneDrawer()
|
|
|
|
{
|
|
|
|
if (PaletteTexture != nullptr) delete PaletteTexture;
|
|
|
|
if (FBTexture != nullptr) delete FBTexture;
|
|
|
|
}
|
|
|
|
|
2018-05-05 09:20:37 +00:00
|
|
|
sector_t *SWSceneDrawer::RenderView(player_t *player)
|
2018-04-05 21:08:09 +00:00
|
|
|
{
|
2018-04-07 21:30:28 +00:00
|
|
|
DCanvas buffer(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor());
|
2018-04-24 21:51:19 +00:00
|
|
|
if (FBTexture == nullptr || FBTexture->SystemTexture[0] == nullptr ||
|
2018-04-24 18:41:52 +00:00
|
|
|
FBTexture->GetWidth() != screen->GetWidth() ||
|
|
|
|
FBTexture->GetHeight() != screen->GetHeight() ||
|
|
|
|
(V_IsTrueColor() ? 1:0) != FBTexture->WidthBits)
|
2018-04-05 21:08:09 +00:00
|
|
|
{
|
|
|
|
// This manually constructs its own material here.
|
|
|
|
if (FBTexture != nullptr) delete FBTexture;
|
2018-04-07 21:30:28 +00:00
|
|
|
FBTexture = new FSWSceneTexture(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor());
|
2018-04-24 21:51:19 +00:00
|
|
|
FBTexture->SystemTexture[0]->AllocateBuffer(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor() ? 4 : 1);
|
2018-04-05 21:08:09 +00:00
|
|
|
auto mat = FMaterial::ValidateTexture(FBTexture, false);
|
|
|
|
mat->AddTextureLayer(PaletteTexture);
|
|
|
|
}
|
2018-04-24 21:51:19 +00:00
|
|
|
auto buf = FBTexture->SystemTexture[0]->MapBuffer();
|
2018-04-05 21:08:09 +00:00
|
|
|
if (!buf) I_FatalError("Unable to map buffer for software rendering");
|
2018-04-07 17:56:54 +00:00
|
|
|
buffer.SetBuffer(screen->GetWidth(), screen->GetHeight(), screen->GetWidth(), buf);
|
2018-04-05 21:08:09 +00:00
|
|
|
SWRenderer->RenderView(player, &buffer);
|
2018-04-24 21:51:19 +00:00
|
|
|
FBTexture->SystemTexture[0]->CreateTexture(nullptr, screen->GetWidth(), screen->GetHeight(), 0, false, 0, "swbuffer");
|
2018-04-05 21:08:09 +00:00
|
|
|
|
|
|
|
auto map = swrenderer::CameraLight::Instance()->ShaderColormap();
|
|
|
|
screen->DrawTexture(FBTexture, 0, 0, DTA_SpecialColormap, map, TAG_DONE);
|
|
|
|
SWRenderer->DrawRemainingPlayerSprites();
|
2018-05-05 09:20:37 +00:00
|
|
|
return r_viewpoint.sector;
|
2018-04-05 21:08:09 +00:00
|
|
|
}
|