Convert r_voxel to a class

This commit is contained in:
Magnus Norddahl 2017-01-11 18:25:14 +01:00
parent 164af7264f
commit 7bed0ffeb6
4 changed files with 46 additions and 35 deletions

View File

@ -871,7 +871,7 @@ namespace swrenderer
} }
else if (sprite.voxel) else if (sprite.voxel)
{ {
R_ProjectVoxel(thing, sprite.pos, sprite.voxel, sprite.spriteScale, sprite.renderflags, fakeside, fakefloor, fakeceiling, sec, spriteshade); RenderVoxel::Project(thing, sprite.pos, sprite.voxel, sprite.spriteScale, sprite.renderflags, fakeside, fakefloor, fakeceiling, sec, spriteshade);
} }
else else
{ {

View File

@ -106,7 +106,7 @@ namespace swrenderer
void R_DeinitSprites() void R_DeinitSprites()
{ {
R_DeinitVisSprites(); R_DeinitVisSprites();
R_DeinitRenderVoxel(); RenderVoxel::Deinit();
// Free vissprites sorter // Free vissprites sorter
if (spritesorter != nullptr) if (spritesorter != nullptr)
@ -633,7 +633,7 @@ namespace swrenderer
} }
int minvoxely = spr->gzt <= hzt ? 0 : xs_RoundToInt((spr->gzt - hzt) / spr->yscale); int minvoxely = spr->gzt <= hzt ? 0 : xs_RoundToInt((spr->gzt - hzt) / spr->yscale);
int maxvoxely = spr->gzb > hzb ? INT_MAX : xs_RoundToInt((spr->gzt - hzb) / spr->yscale); int maxvoxely = spr->gzb > hzb ? INT_MAX : xs_RoundToInt((spr->gzt - hzb) / spr->yscale);
R_DrawVisVoxel(spr, minvoxely, maxvoxely, cliptop, clipbot); RenderVoxel::Render(spr, minvoxely, maxvoxely, cliptop, clipbot);
} }
spr->Style.BaseColormap = colormap; spr->Style.BaseColormap = colormap;
spr->Style.ColormapNum = colormapnum; spr->Style.ColormapNum = colormapnum;

View File

@ -43,14 +43,7 @@ EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor)
namespace swrenderer namespace swrenderer
{ {
namespace void RenderVoxel::Project(AActor *thing, DVector3 pos, FVoxelDef *voxel, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int spriteshade)
{
FCoverageBuffer *OffscreenCoverageBuffer;
int OffscreenBufferWidth, OffscreenBufferHeight;
uint8_t *OffscreenColorBuffer;
}
void R_ProjectVoxel(AActor *thing, DVector3 pos, FVoxelDef *voxel, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int spriteshade)
{ {
// transform the origin point // transform the origin point
double tr_x = pos.X - ViewPos.X; double tr_x = pos.X - ViewPos.X;
@ -226,7 +219,7 @@ namespace swrenderer
} }
} }
void R_DrawVisVoxel(vissprite_t *sprite, int minZ, int maxZ, short *cliptop, short *clipbottom) void RenderVoxel::Render(vissprite_t *sprite, int minZ, int maxZ, short *cliptop, short *clipbottom)
{ {
R_SetColorMapLight(sprite->Style.BaseColormap, 0, sprite->Style.ColormapNum << FRACBITS); R_SetColorMapLight(sprite->Style.BaseColormap, 0, sprite->Style.ColormapNum << FRACBITS);
bool visible = R_SetPatchStyle(sprite->Style.RenderStyle, sprite->Style.Alpha, sprite->Translation, sprite->FillColor); bool visible = R_SetPatchStyle(sprite->Style.RenderStyle, sprite->Style.Alpha, sprite->Translation, sprite->FillColor);
@ -305,10 +298,10 @@ namespace swrenderer
{ {
for (int y = startY[index]; y != endY; y += stepY[index]) for (int y = startY[index]; y != endY; y += stepY[index])
{ {
kvxslab_t *slab_start = R_GetSlabStart(mip, x, y); kvxslab_t *slab_start = GetSlabStart(mip, x, y);
kvxslab_t *slab_end = R_GetSlabEnd(mip, x, y); kvxslab_t *slab_end = GetSlabEnd(mip, x, y);
for (kvxslab_t *slab = slab_start; slab != slab_end; slab = R_NextSlab(slab)) for (kvxslab_t *slab = slab_start; slab != slab_end; slab = NextSlab(slab))
{ {
// To do: check slab->backfacecull // To do: check slab->backfacecull
@ -327,7 +320,7 @@ namespace swrenderer
voxel_pos.Y += dirY.X * x + dirY.Y * y; voxel_pos.Y += dirY.X * x + dirY.Y * y;
voxel_pos.Z += dirZ * z; voxel_pos.Z += dirZ * z;
R_FillBox(voxel_pos, sprite_xscale, sprite_yscale, color, cliptop, clipbottom, false, false); FillBox(voxel_pos, sprite_xscale, sprite_yscale, color, cliptop, clipbottom, false, false);
} }
} }
} }
@ -335,22 +328,22 @@ namespace swrenderer
} }
} }
kvxslab_t *R_GetSlabStart(const FVoxelMipLevel &mip, int x, int y) kvxslab_t *RenderVoxel::GetSlabStart(const FVoxelMipLevel &mip, int x, int y)
{ {
return (kvxslab_t *)&mip.SlabData[mip.OffsetX[x] + (int)mip.OffsetXY[x * (mip.SizeY + 1) + y]]; return (kvxslab_t *)&mip.SlabData[mip.OffsetX[x] + (int)mip.OffsetXY[x * (mip.SizeY + 1) + y]];
} }
kvxslab_t *R_GetSlabEnd(const FVoxelMipLevel &mip, int x, int y) kvxslab_t *RenderVoxel::GetSlabEnd(const FVoxelMipLevel &mip, int x, int y)
{ {
return R_GetSlabStart(mip, x, y + 1); return GetSlabStart(mip, x, y + 1);
} }
kvxslab_t *R_NextSlab(kvxslab_t *slab) kvxslab_t *RenderVoxel::NextSlab(kvxslab_t *slab)
{ {
return (kvxslab_t*)(((uint8_t*)slab) + 3 + slab->zleng); return (kvxslab_t*)(((uint8_t*)slab) + 3 + slab->zleng);
} }
void R_FillBox(DVector3 origin, double extentX, double extentY, int color, short *cliptop, short *clipbottom, bool viewspace, bool pixelstretch) void RenderVoxel::FillBox(DVector3 origin, double extentX, double extentY, int color, short *cliptop, short *clipbottom, bool viewspace, bool pixelstretch)
{ {
double viewX, viewY, viewZ; double viewX, viewY, viewZ;
if (viewspace) if (viewspace)
@ -402,7 +395,7 @@ namespace swrenderer
} }
} }
void R_DeinitRenderVoxel() void RenderVoxel::Deinit()
{ {
// Free offscreen buffer // Free offscreen buffer
if (OffscreenColorBuffer != nullptr) if (OffscreenColorBuffer != nullptr)
@ -418,7 +411,7 @@ namespace swrenderer
OffscreenBufferHeight = OffscreenBufferWidth = 0; OffscreenBufferHeight = OffscreenBufferWidth = 0;
} }
void R_CheckOffscreenBuffer(int width, int height, bool spansonly) void RenderVoxel::CheckOffscreenBuffer(int width, int height, bool spansonly)
{ {
// Allocates the offscreen coverage buffer and optionally the offscreen // Allocates the offscreen coverage buffer and optionally the offscreen
// color buffer. If they already exist but are the wrong size, they will // color buffer. If they already exist but are the wrong size, they will
@ -460,6 +453,11 @@ namespace swrenderer
OffscreenBufferHeight = height; OffscreenBufferHeight = height;
} }
FCoverageBuffer *RenderVoxel::OffscreenCoverageBuffer;
int RenderVoxel::OffscreenBufferWidth;
int RenderVoxel::OffscreenBufferHeight;
uint8_t *RenderVoxel::OffscreenColorBuffer;
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
FCoverageBuffer::FCoverageBuffer(int lists) FCoverageBuffer::FCoverageBuffer(int lists)

View File

@ -30,18 +30,6 @@ namespace swrenderer
{ {
struct vissprite_t; struct vissprite_t;
enum { DVF_OFFSCREEN = 1, DVF_SPANSONLY = 2, DVF_MIRRORED = 4 };
void R_ProjectVoxel(AActor *thing, DVector3 pos, FVoxelDef *voxel, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int spriteshade);
void R_DrawVisVoxel(vissprite_t *sprite, int minZ, int maxZ, short *cliptop, short *clipbottom);
void R_FillBox(DVector3 origin, double extentX, double extentY, int color, short *cliptop, short *clipbottom, bool viewspace, bool pixelstretch);
kvxslab_t *R_GetSlabStart(const FVoxelMipLevel &mip, int x, int y);
kvxslab_t *R_GetSlabEnd(const FVoxelMipLevel &mip, int x, int y);
kvxslab_t *R_NextSlab(kvxslab_t *slab);
void R_CheckOffscreenBuffer(int width, int height, bool spansonly);
void R_DeinitRenderVoxel();
// [RH] A c-buffer. Used for keeping track of offscreen voxel spans. // [RH] A c-buffer. Used for keeping track of offscreen voxel spans.
struct FCoverageBuffer struct FCoverageBuffer
{ {
@ -63,4 +51,29 @@ namespace swrenderer
Span *FreeSpans; Span *FreeSpans;
unsigned int NumLists; unsigned int NumLists;
}; };
class RenderVoxel
{
public:
static void Project(AActor *thing, DVector3 pos, FVoxelDef *voxel, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int spriteshade);
static void Render(vissprite_t *sprite, int minZ, int maxZ, short *cliptop, short *clipbottom);
static void Deinit();
private:
enum { DVF_OFFSCREEN = 1, DVF_SPANSONLY = 2, DVF_MIRRORED = 4 };
static void FillBox(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);
static void CheckOffscreenBuffer(int width, int height, bool spansonly);
static FCoverageBuffer *OffscreenCoverageBuffer;
static int OffscreenBufferWidth;
static int OffscreenBufferHeight;
static uint8_t *OffscreenColorBuffer;
};
} }