mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-12 07:34:50 +00:00
Convert r_voxel to a class
This commit is contained in:
parent
164af7264f
commit
7bed0ffeb6
4 changed files with 46 additions and 35 deletions
|
@ -871,7 +871,7 @@ namespace swrenderer
|
|||
}
|
||||
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
|
||||
{
|
||||
|
|
|
@ -106,7 +106,7 @@ namespace swrenderer
|
|||
void R_DeinitSprites()
|
||||
{
|
||||
R_DeinitVisSprites();
|
||||
R_DeinitRenderVoxel();
|
||||
RenderVoxel::Deinit();
|
||||
|
||||
// Free vissprites sorter
|
||||
if (spritesorter != nullptr)
|
||||
|
@ -633,7 +633,7 @@ namespace swrenderer
|
|||
}
|
||||
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);
|
||||
R_DrawVisVoxel(spr, minvoxely, maxvoxely, cliptop, clipbot);
|
||||
RenderVoxel::Render(spr, minvoxely, maxvoxely, cliptop, clipbot);
|
||||
}
|
||||
spr->Style.BaseColormap = colormap;
|
||||
spr->Style.ColormapNum = colormapnum;
|
||||
|
|
|
@ -43,14 +43,7 @@ EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor)
|
|||
|
||||
namespace swrenderer
|
||||
{
|
||||
namespace
|
||||
{
|
||||
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)
|
||||
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)
|
||||
{
|
||||
// transform the origin point
|
||||
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);
|
||||
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])
|
||||
{
|
||||
kvxslab_t *slab_start = R_GetSlabStart(mip, x, y);
|
||||
kvxslab_t *slab_end = R_GetSlabEnd(mip, x, y);
|
||||
kvxslab_t *slab_start = GetSlabStart(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
|
||||
|
||||
|
@ -327,7 +320,7 @@ namespace swrenderer
|
|||
voxel_pos.Y += dirY.X * x + dirY.Y * y;
|
||||
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]];
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
if (viewspace)
|
||||
|
@ -402,7 +395,7 @@ namespace swrenderer
|
|||
}
|
||||
}
|
||||
|
||||
void R_DeinitRenderVoxel()
|
||||
void RenderVoxel::Deinit()
|
||||
{
|
||||
// Free offscreen buffer
|
||||
if (OffscreenColorBuffer != nullptr)
|
||||
|
@ -418,7 +411,7 @@ namespace swrenderer
|
|||
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
|
||||
// color buffer. If they already exist but are the wrong size, they will
|
||||
|
@ -460,6 +453,11 @@ namespace swrenderer
|
|||
OffscreenBufferHeight = height;
|
||||
}
|
||||
|
||||
FCoverageBuffer *RenderVoxel::OffscreenCoverageBuffer;
|
||||
int RenderVoxel::OffscreenBufferWidth;
|
||||
int RenderVoxel::OffscreenBufferHeight;
|
||||
uint8_t *RenderVoxel::OffscreenColorBuffer;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
FCoverageBuffer::FCoverageBuffer(int lists)
|
||||
|
|
|
@ -30,18 +30,6 @@ namespace swrenderer
|
|||
{
|
||||
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.
|
||||
struct FCoverageBuffer
|
||||
{
|
||||
|
@ -63,4 +51,29 @@ namespace swrenderer
|
|||
Span *FreeSpans;
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue