Enable Ken Silverman's voxel drawing code now that he has given us permission to license it as GPL

This commit is contained in:
Magnus Norddahl 2017-02-11 22:10:52 +01:00
parent 3e28d53308
commit 8c5360e547
6 changed files with 595 additions and 564 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,25 +1,26 @@
/*
** Voxel rendering
** Copyright (c) 1998-2016 Randy Heit
** 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.
**
*/
//
//---------------------------------------------------------------------------
//
// Voxel rendering
// Copyright(c) 1993 - 1997 Ken Silverman
// Copyright(c) 1998 - 2016 Randy Heit
// 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/
//
//--------------------------------------------------------------------------
//
#pragma once
@ -77,14 +78,13 @@ namespace swrenderer
DAngle Angle = { 0.0 };
fixed_t xscale = 0;
FVoxel *voxel = nullptr;
bool bInMirror = false;
uint32_t Translation = 0;
uint32_t FillColor = 0;
enum { DVF_OFFSCREEN = 1, DVF_SPANSONLY = 2, DVF_MIRRORED = 4 };
static void FillBox(RenderThread *thread, SpriteDrawerArgs &drawerargs, DVector3 origin, double extentX, double extentY, int color, short *cliptop, short *clipbottom, bool viewspace, bool pixelstretch);
static kvxslab_t *GetSlabStart(const FVoxelMipLevel &mip, int x, int y);
static kvxslab_t *GetSlabEnd(const FVoxelMipLevel &mip, int x, int y);
static kvxslab_t *NextSlab(kvxslab_t *slab);
@ -95,5 +95,15 @@ namespace swrenderer
static int OffscreenBufferWidth;
static int OffscreenBufferHeight;
static uint8_t *OffscreenColorBuffer;
void DrawVoxel(
RenderThread *thread, SpriteDrawerArgs &drawerargs,
const FVector3 &globalpos, FAngle viewangle, const FVector3 &dasprpos, DAngle dasprang, fixed_t daxscale, fixed_t dayscale,
FVoxel *voxobj, short *daumost, short *dadmost, int minslabz, int maxslabz, int flags);
int sgn(int v)
{
return v < 0 ? -1 : v > 0 ? 1 : 0;
}
};
}

View File

@ -497,6 +497,17 @@ namespace swrenderer
thread->Drawers()->FillColumn(*this);
}
void SpriteDrawerArgs::DrawVoxelColumn(RenderThread *thread, fixed_t vPos, fixed_t vStep, const uint8_t *voxels, int voxelsCount)
{
dc_iscale = vStep;
dc_texturefrac = vPos;
dc_texturefracx = 0;
dc_source = voxels;
dc_source2 = 0;
dc_textureheight = voxelsCount;
(thread->Drawers()->*colfunc)(*this);
}
void SpriteDrawerArgs::SetDest(int x, int y)
{
auto viewport = RenderViewport::Instance();

View File

@ -24,6 +24,7 @@ namespace swrenderer
void DrawMaskedColumn(RenderThread *thread, int x, fixed_t iscale, FTexture *texture, fixed_t column, double spryscale, double sprtopscreen, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, bool unmasked = false);
void FillColumn(RenderThread *thread);
void DrawVoxelColumn(RenderThread *thread, fixed_t vPos, fixed_t vStep, const uint8_t *voxels, int voxelsCount);
uint8_t *Dest() const { return dc_dest; }
int DestY() const { return dc_dest_y; }

View File

@ -156,6 +156,9 @@ namespace swrenderer
FocalLengthX = CenterX / FocalTangent;
FocalLengthY = FocalLengthX * YaspectMul;
// This is 1/FocalTangent before the widescreen extension of FOV.
viewingrangerecip = FLOAT2FIXED(1. / tan(FieldOfView.Radians() / 2));
// Now generate xtoviewangle for sky texture mapping.
// [RH] Do not generate viewangletox, because texture mapping is no
// longer done with trig, so it's not needed.

View File

@ -43,6 +43,9 @@ namespace swrenderer
double globaluclip = 0.0;
double globaldclip = 0.0;
fixed_t viewingrangerecip = 0;
double BaseYaspectMul = 0.0; // yaspectmul without a forced aspect ratio
// The xtoviewangleangle[] table maps a screen pixel
// to the lowest viewangle that maps back to x ranges
// from clipangle to -clipangle.
@ -70,7 +73,5 @@ namespace swrenderer
private:
void InitTextureMapping();
void SetupBuffer();
double BaseYaspectMul = 0.0; // yaspectmul without a forced aspect ratio
};
}