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 // Voxel rendering
** // Copyright(c) 1993 - 1997 Ken Silverman
** This software is provided 'as-is', without any express or implied // Copyright(c) 1998 - 2016 Randy Heit
** warranty. In no event will the authors be held liable for any damages // All rights reserved.
** arising from the use of this software. //
** // This program is free software: you can redistribute it and/or modify
** Permission is granted to anyone to use this software for any purpose, // it under the terms of the GNU Lesser General Public License as published by
** including commercial applications, and to alter it and redistribute it // the Free Software Foundation, either version 3 of the License, or
** freely, subject to the following restrictions: // (at your option) any later version.
** //
** 1. The origin of this software must not be misrepresented; you must not // This program is distributed in the hope that it will be useful,
** claim that you wrote the original software. If you use this software // but WITHOUT ANY WARRANTY; without even the implied warranty of
** in a product, an acknowledgment in the product documentation would be // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** appreciated but is not required. // GNU Lesser General Public License for more details.
** 2. Altered source versions must be plainly marked as such, and must not be //
** misrepresented as being the original software. // You should have received a copy of the GNU Lesser General Public License
** 3. This notice may not be removed or altered from any source distribution. // along with this program. If not, see http://www.gnu.org/licenses/
** //
*/ //--------------------------------------------------------------------------
//
#pragma once #pragma once
@ -77,14 +78,13 @@ namespace swrenderer
DAngle Angle = { 0.0 }; DAngle Angle = { 0.0 };
fixed_t xscale = 0; fixed_t xscale = 0;
FVoxel *voxel = nullptr; FVoxel *voxel = nullptr;
bool bInMirror = false;
uint32_t Translation = 0; uint32_t Translation = 0;
uint32_t FillColor = 0; uint32_t FillColor = 0;
enum { DVF_OFFSCREEN = 1, DVF_SPANSONLY = 2, DVF_MIRRORED = 4 }; 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 *GetSlabStart(const FVoxelMipLevel &mip, int x, int y);
static kvxslab_t *GetSlabEnd(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); static kvxslab_t *NextSlab(kvxslab_t *slab);
@ -95,5 +95,15 @@ namespace swrenderer
static int OffscreenBufferWidth; static int OffscreenBufferWidth;
static int OffscreenBufferHeight; static int OffscreenBufferHeight;
static uint8_t *OffscreenColorBuffer; 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); 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) void SpriteDrawerArgs::SetDest(int x, int y)
{ {
auto viewport = RenderViewport::Instance(); 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 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 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; } uint8_t *Dest() const { return dc_dest; }
int DestY() const { return dc_dest_y; } int DestY() const { return dc_dest_y; }

View file

@ -156,6 +156,9 @@ namespace swrenderer
FocalLengthX = CenterX / FocalTangent; FocalLengthX = CenterX / FocalTangent;
FocalLengthY = FocalLengthX * YaspectMul; 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. // Now generate xtoviewangle for sky texture mapping.
// [RH] Do not generate viewangletox, because texture mapping is no // [RH] Do not generate viewangletox, because texture mapping is no
// longer done with trig, so it's not needed. // longer done with trig, so it's not needed.

View file

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