mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-10 14:51:51 +00:00
- Add model rendering to the software renderer
This commit is contained in:
parent
0667f2ec55
commit
d43ac8b9ae
32 changed files with 793 additions and 88 deletions
|
@ -734,6 +734,7 @@ set ( SWRENDER_SOURCES
|
|||
swrenderer/things/r_sprite.cpp
|
||||
swrenderer/things/r_wallsprite.cpp
|
||||
swrenderer/things/r_decal.cpp
|
||||
swrenderer/things/r_model.cpp
|
||||
swrenderer/plane/r_visibleplane.cpp
|
||||
swrenderer/plane/r_visibleplanelist.cpp
|
||||
swrenderer/plane/r_skyplane.cpp
|
||||
|
|
|
@ -126,6 +126,24 @@ void PolyDrawArgs::SetColor(uint32_t bgra, uint8_t palindex)
|
|||
}
|
||||
}
|
||||
|
||||
void PolyDrawArgs::DrawArray(const DrawerCommandQueuePtr &queue, const TriVertex *vertices, int vcount, PolyDrawMode mode)
|
||||
{
|
||||
mVertices = vertices;
|
||||
mVertexCount = vcount;
|
||||
mElements = nullptr;
|
||||
mDrawMode = mode;
|
||||
queue->Push<DrawPolyTrianglesCommand>(*this, PolyTriangleDrawer::is_mirror());
|
||||
}
|
||||
|
||||
void PolyDrawArgs::DrawElements(const DrawerCommandQueuePtr &queue, const TriVertex *vertices, const unsigned int *elements, int count, PolyDrawMode mode)
|
||||
{
|
||||
mVertices = vertices;
|
||||
mElements = elements;
|
||||
mVertexCount = count;
|
||||
mDrawMode = mode;
|
||||
queue->Push<DrawPolyTrianglesCommand>(*this, PolyTriangleDrawer::is_mirror());
|
||||
}
|
||||
|
||||
void PolyDrawArgs::DrawArray(PolyRenderThread *thread, const TriVertex *vertices, int vcount, PolyDrawMode mode)
|
||||
{
|
||||
mVertices = vertices;
|
||||
|
|
|
@ -84,6 +84,8 @@ public:
|
|||
void SetDynLightColor(uint32_t color) { mDynLightColor = color; }
|
||||
void DrawArray(PolyRenderThread *thread, const TriVertex *vertices, int vcount, PolyDrawMode mode = PolyDrawMode::Triangles);
|
||||
void DrawElements(PolyRenderThread *thread, const TriVertex *vertices, const unsigned int *elements, int count, PolyDrawMode mode = PolyDrawMode::Triangles);
|
||||
void DrawArray(const DrawerCommandQueuePtr &queue, const TriVertex *vertices, int vcount, PolyDrawMode mode = PolyDrawMode::Triangles);
|
||||
void DrawElements(const DrawerCommandQueuePtr &queue, const TriVertex *vertices, const unsigned int *elements, int count, PolyDrawMode mode = PolyDrawMode::Triangles);
|
||||
|
||||
const TriMatrix *ObjectToClip() const { return mObjectToClip; }
|
||||
const PolyClipPlane &ClipPlane(int index) const { return mClipPlane[index]; }
|
||||
|
|
|
@ -1071,16 +1071,21 @@ void TriangleBlock::DepthWrite(const TriDrawTriangleArgs *args)
|
|||
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
EXTERN_CVAR(Bool, r_polyrenderer)
|
||||
|
||||
void ScreenTriangle::Draw(const TriDrawTriangleArgs *args, WorkerThreadData *thread)
|
||||
{
|
||||
TriangleBlock block(args, thread);
|
||||
block.Render();
|
||||
if (r_polyrenderer)
|
||||
{
|
||||
TriangleBlock block(args, thread);
|
||||
block.Render();
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawSWRender(args, thread);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void SortVertices(const TriDrawTriangleArgs *args, ShadedTriVertex **sortedVertices)
|
||||
{
|
||||
sortedVertices[0] = args->v1;
|
||||
|
@ -1095,7 +1100,7 @@ static void SortVertices(const TriDrawTriangleArgs *args, ShadedTriVertex **sort
|
|||
std::swap(sortedVertices[1], sortedVertices[2]);
|
||||
}
|
||||
|
||||
void ScreenTriangle::Draw(const TriDrawTriangleArgs *args, WorkerThreadData *thread)
|
||||
void ScreenTriangle::DrawSWRender(const TriDrawTriangleArgs *args, WorkerThreadData *thread)
|
||||
{
|
||||
// Sort vertices by Y position
|
||||
ShadedTriVertex *sortedVertices[3];
|
||||
|
@ -1179,15 +1184,9 @@ void ScreenTriangle::Draw(const TriDrawTriangleArgs *args, WorkerThreadData *thr
|
|||
bool writeStencil = args->uniforms->WriteStencil();
|
||||
bool writeDepth = args->uniforms->WriteDepth();
|
||||
|
||||
uint8_t stencilTestValue = args->uniforms->StencilTestValue();
|
||||
uint8_t stencilWriteValue = args->uniforms->StencilWriteValue();
|
||||
|
||||
int bmode = (int)args->uniforms->BlendMode();
|
||||
auto drawFunc = args->destBgra ? ScreenTriangle::TriDrawers32[bmode] : ScreenTriangle::TriDrawers8[bmode];
|
||||
|
||||
uint8_t *dest = args->dest;
|
||||
uint8_t *stencilbuffer = args->stencilValues;
|
||||
uint32_t *stencilMasks = args->stencilMasks;
|
||||
float *zbuffer = args->zbuffer;
|
||||
int pitch = args->pitch;
|
||||
int stencilpitch = args->stencilPitch * 8;
|
||||
|
@ -1206,7 +1205,6 @@ void ScreenTriangle::Draw(const TriDrawTriangleArgs *args, WorkerThreadData *thr
|
|||
float stepYV = args->gradientY.V;
|
||||
int texWidth = args->uniforms->TextureWidth();
|
||||
int texHeight = args->uniforms->TextureHeight();
|
||||
const uint8_t *texPixels = args->uniforms->TexturePixels();
|
||||
auto colormaps = args->uniforms->BaseColormap();
|
||||
|
||||
bool is_fixed_light = args->uniforms->FixedLight();
|
||||
|
@ -1218,83 +1216,140 @@ void ScreenTriangle::Draw(const TriDrawTriangleArgs *args, WorkerThreadData *thr
|
|||
|
||||
// Draw the triangle:
|
||||
|
||||
int num_cores = thread->num_cores;
|
||||
for (int y = topY + thread->skipped_by_thread(topY); y < bottomY; y += num_cores)
|
||||
if (args->destBgra)
|
||||
{
|
||||
int x0 = leftEdge[y];
|
||||
int x1 = rightEdge[y];
|
||||
uint32_t *dest = (uint32_t*)args->dest;
|
||||
const uint32_t *texPixels = (const uint32_t*)args->uniforms->TexturePixels();
|
||||
|
||||
uint8_t *destLine = dest + pitch * y;
|
||||
uint8_t *stencilLine = stencilbuffer + stencilpitch * y;
|
||||
float *zbufferLine = zbuffer + stencilpitch * y;
|
||||
|
||||
if ((stencilMasks[y] & 0xffffff00) == 0xffffff00) // First time we draw a line we have to clear the stencil buffer
|
||||
int num_cores = thread->num_cores;
|
||||
for (int y = topY + thread->skipped_by_thread(topY); y < bottomY; y += num_cores)
|
||||
{
|
||||
memset(stencilLine, stencilMasks[y] & 0xff, stencilpitch);
|
||||
stencilMasks[y] = 0;
|
||||
}
|
||||
int x0 = leftEdge[y];
|
||||
int x1 = rightEdge[y];
|
||||
|
||||
float posXW = v1W + stepXW * (x0 + (0.5f - v1X)) + stepYW * (y + (0.5f - v1Y));
|
||||
float posXU = v1U + stepXU * (x0 + (0.5f - v1X)) + stepYU * (y + (0.5f - v1Y));
|
||||
float posXV = v1V + stepXV * (x0 + (0.5f - v1X)) + stepYV * (y + (0.5f - v1Y));
|
||||
uint32_t *destLine = dest + pitch * y;
|
||||
float *zbufferLine = zbuffer + stencilpitch * y;
|
||||
|
||||
int x = x0;
|
||||
while (x < x1)
|
||||
{
|
||||
bool processPixel = true;
|
||||
float posXW = v1W + stepXW * (x0 + (0.5f - v1X)) + stepYW * (y + (0.5f - v1Y));
|
||||
float posXU = v1U + stepXU * (x0 + (0.5f - v1X)) + stepYU * (y + (0.5f - v1Y));
|
||||
float posXV = v1V + stepXV * (x0 + (0.5f - v1X)) + stepYV * (y + (0.5f - v1Y));
|
||||
|
||||
if (!depthTest) // To do: make the stencil test use its own flag for comparison mode instead of abusing the depth test..
|
||||
int x = x0;
|
||||
while (x < x1)
|
||||
{
|
||||
processPixel = stencilTestValue == stencilLine[x];
|
||||
}
|
||||
else
|
||||
{
|
||||
processPixel = stencilTestValue >= stencilLine[x] && zbufferLine[x] <= posXW;
|
||||
}
|
||||
|
||||
if (processPixel) // Pixel is visible (passed stencil and depth tests)
|
||||
{
|
||||
if (writeColor)
|
||||
bool processPixel = depthTest ? zbufferLine[x] <= posXW : true;
|
||||
if (processPixel) // Pixel is visible (passed stencil and depth tests)
|
||||
{
|
||||
if (texPixels)
|
||||
if (writeColor)
|
||||
{
|
||||
float rcpW = 0x01000000 / posXW;
|
||||
int32_t u = (int32_t)(posXU * rcpW);
|
||||
int32_t v = (int32_t)(posXV * rcpW);
|
||||
if (texPixels)
|
||||
{
|
||||
float rcpW = 0x01000000 / posXW;
|
||||
int32_t u = (int32_t)(posXU * rcpW);
|
||||
int32_t v = (int32_t)(posXV * rcpW);
|
||||
|
||||
uint32_t texelX = ((((uint32_t)u << 8) >> 16) * texWidth) >> 16;
|
||||
uint32_t texelY = ((((uint32_t)v << 8) >> 16) * texHeight) >> 16;
|
||||
uint8_t fgcolor = texPixels[texelX * texHeight + texelY];
|
||||
uint32_t texelX = ((((uint32_t)u << 8) >> 16) * texWidth) >> 16;
|
||||
uint32_t texelY = ((((uint32_t)v << 8) >> 16) * texHeight) >> 16;
|
||||
uint32_t fgcolor = texPixels[texelX * texHeight + texelY];
|
||||
|
||||
fixed_t lightpos = FRACUNIT - (int)(clamp(shade - MIN(24.0f / 32.0f, globVis * posXW), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT);
|
||||
lightpos = (lightpos & lightmask) | ((light << 8) & ~lightmask);
|
||||
int lightshade = lightpos >> 8;
|
||||
uint32_t fgcolor_r = RPART(fgcolor);
|
||||
uint32_t fgcolor_g = GPART(fgcolor);
|
||||
uint32_t fgcolor_b = BPART(fgcolor);
|
||||
uint32_t fgcolor_a = APART(fgcolor);
|
||||
if (fgcolor_a > 127)
|
||||
{
|
||||
fixed_t lightpos = FRACUNIT - (int)(clamp(shade - MIN(24.0f / 32.0f, globVis * posXW), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT);
|
||||
lightpos = (lightpos & lightmask) | ((light << 8) & ~lightmask);
|
||||
int lightshade = lightpos >> 8;
|
||||
|
||||
lightshade = ((256 - lightshade) * NUMCOLORMAPS) & 0xffffff00;
|
||||
uint8_t shadedfg = colormaps[lightshade + fgcolor];
|
||||
fgcolor_r = (fgcolor_r * lightshade) >> 8;
|
||||
fgcolor_g = (fgcolor_g * lightshade) >> 8;
|
||||
fgcolor_b = (fgcolor_b * lightshade) >> 8;
|
||||
|
||||
if (fgcolor != 0)
|
||||
destLine[x] = shadedfg;
|
||||
}
|
||||
else
|
||||
{
|
||||
destLine[x] = color;
|
||||
destLine[x] = 0xff000000 | (fgcolor_r << 16) | (fgcolor_g << 8) | fgcolor_b;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
destLine[x] = color;
|
||||
}
|
||||
}
|
||||
|
||||
if (writeDepth)
|
||||
zbufferLine[x] = posXW;
|
||||
}
|
||||
if (writeStencil)
|
||||
stencilLine[x] = stencilWriteValue;
|
||||
if (writeDepth)
|
||||
zbufferLine[x] = posXW;
|
||||
}
|
||||
|
||||
posXW += stepXW;
|
||||
posXU += stepXU;
|
||||
posXV += stepXV;
|
||||
x++;
|
||||
posXW += stepXW;
|
||||
posXU += stepXU;
|
||||
posXV += stepXV;
|
||||
x++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t *dest = args->dest;
|
||||
const uint8_t *texPixels = args->uniforms->TexturePixels();
|
||||
|
||||
int num_cores = thread->num_cores;
|
||||
for (int y = topY + thread->skipped_by_thread(topY); y < bottomY; y += num_cores)
|
||||
{
|
||||
int x0 = leftEdge[y];
|
||||
int x1 = rightEdge[y];
|
||||
|
||||
uint8_t *destLine = dest + pitch * y;
|
||||
float *zbufferLine = zbuffer + stencilpitch * y;
|
||||
|
||||
float posXW = v1W + stepXW * (x0 + (0.5f - v1X)) + stepYW * (y + (0.5f - v1Y));
|
||||
float posXU = v1U + stepXU * (x0 + (0.5f - v1X)) + stepYU * (y + (0.5f - v1Y));
|
||||
float posXV = v1V + stepXV * (x0 + (0.5f - v1X)) + stepYV * (y + (0.5f - v1Y));
|
||||
|
||||
int x = x0;
|
||||
while (x < x1)
|
||||
{
|
||||
bool processPixel = depthTest ? zbufferLine[x] <= posXW : true;
|
||||
if (processPixel) // Pixel is visible (passed stencil and depth tests)
|
||||
{
|
||||
if (writeColor)
|
||||
{
|
||||
if (texPixels)
|
||||
{
|
||||
float rcpW = 0x01000000 / posXW;
|
||||
int32_t u = (int32_t)(posXU * rcpW);
|
||||
int32_t v = (int32_t)(posXV * rcpW);
|
||||
|
||||
uint32_t texelX = ((((uint32_t)u << 8) >> 16) * texWidth) >> 16;
|
||||
uint32_t texelY = ((((uint32_t)v << 8) >> 16) * texHeight) >> 16;
|
||||
uint8_t fgcolor = texPixels[texelX * texHeight + texelY];
|
||||
|
||||
fixed_t lightpos = FRACUNIT - (int)(clamp(shade - MIN(24.0f / 32.0f, globVis * posXW), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT);
|
||||
lightpos = (lightpos & lightmask) | ((light << 8) & ~lightmask);
|
||||
int lightshade = lightpos >> 8;
|
||||
|
||||
lightshade = ((256 - lightshade) * NUMCOLORMAPS) & 0xffffff00;
|
||||
uint8_t shadedfg = colormaps[lightshade + fgcolor];
|
||||
|
||||
if (fgcolor != 0)
|
||||
destLine[x] = shadedfg;
|
||||
}
|
||||
else
|
||||
{
|
||||
destLine[x] = color;
|
||||
}
|
||||
}
|
||||
|
||||
if (writeDepth)
|
||||
zbufferLine[x] = posXW;
|
||||
}
|
||||
|
||||
posXW += stepXW;
|
||||
posXU += stepXU;
|
||||
posXV += stepXV;
|
||||
x++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void(*ScreenTriangle::TriDrawers8[])(int, int, uint32_t, uint32_t, const TriDrawTriangleArgs *) =
|
||||
{
|
||||
|
|
|
@ -149,6 +149,7 @@ class ScreenTriangle
|
|||
{
|
||||
public:
|
||||
static void Draw(const TriDrawTriangleArgs *args, WorkerThreadData *thread);
|
||||
static void DrawSWRender(const TriDrawTriangleArgs *args, WorkerThreadData *thread);
|
||||
|
||||
static void(*TriDrawers8[])(int, int, uint32_t, uint32_t, const TriDrawTriangleArgs *);
|
||||
static void(*TriDrawers32[])(int, int, uint32_t, uint32_t, const TriDrawTriangleArgs *);
|
||||
|
|
|
@ -132,7 +132,6 @@ TriMatrix TriMatrix::frustum(float left, float right, float bottom, float top, f
|
|||
return m;
|
||||
}
|
||||
|
||||
#if 0
|
||||
TriMatrix TriMatrix::worldToView(const FRenderViewpoint &viewpoint)
|
||||
{
|
||||
TriMatrix m = null();
|
||||
|
@ -145,16 +144,15 @@ TriMatrix TriMatrix::worldToView(const FRenderViewpoint &viewpoint)
|
|||
return m * translate((float)-viewpoint.Pos.X, (float)-viewpoint.Pos.Y, (float)-viewpoint.Pos.Z);
|
||||
}
|
||||
|
||||
TriMatrix TriMatrix::viewToClip(double focalTangent, double centerY, double invZtoScale)
|
||||
TriMatrix TriMatrix::viewToClip(double focalTangent, double centerY, double YaspectMul)
|
||||
{
|
||||
float near = 5.0f;
|
||||
float far = 65536.0f;
|
||||
float width = (float)(focalTangent * near);
|
||||
float top = (float)(centerY / invZtoScale * near);
|
||||
float bottom = (float)(top - viewheight / invZtoScale * near);
|
||||
float top = (float)(centerY / viewheight * YaspectMul * near);
|
||||
float bottom = (float)(top - YaspectMul * near);
|
||||
return frustum(-width, width, bottom, top, near, far);
|
||||
}
|
||||
#endif
|
||||
|
||||
TriMatrix TriMatrix::operator*(const TriMatrix &mult) const
|
||||
{
|
||||
|
|
|
@ -36,8 +36,8 @@ struct TriMatrix
|
|||
static TriMatrix perspective(float fovy, float aspect, float near, float far);
|
||||
static TriMatrix frustum(float left, float right, float bottom, float top, float near, float far);
|
||||
|
||||
//static TriMatrix worldToView(const FRenderViewpoint &viewpoint); // Software renderer world to view space transform
|
||||
//static TriMatrix viewToClip(double focalTangent, double centerY, double invZtoScale); // Software renderer shearing projection
|
||||
static TriMatrix worldToView(const FRenderViewpoint &viewpoint); // Software renderer world to view space transform
|
||||
static TriMatrix viewToClip(double focalTangent, double centerY, double YaspectMul); // Software renderer shearing projection
|
||||
|
||||
FVector4 operator*(const FVector4 &v) const;
|
||||
TriMatrix operator*(const TriMatrix &m) const;
|
||||
|
|
|
@ -33,6 +33,9 @@
|
|||
#include "actorinlines.h"
|
||||
#include "i_time.h"
|
||||
|
||||
void gl_FlushModels();
|
||||
bool polymodelsInUse;
|
||||
|
||||
void PolyRenderModel(PolyRenderThread *thread, const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, uint32_t stencilValue, float x, float y, float z, FSpriteModelFrame *smf, AActor *actor)
|
||||
{
|
||||
PolyModelRenderer renderer(thread, worldToClip, clipPlane, stencilValue);
|
||||
|
@ -47,6 +50,15 @@ void PolyRenderHUDModel(PolyRenderThread *thread, const TriMatrix &worldToClip,
|
|||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PolyModelRenderer::PolyModelRenderer(PolyRenderThread *thread, const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, uint32_t stencilValue) : Thread(thread), WorldToClip(worldToClip), ClipPlane(clipPlane), StencilValue(stencilValue)
|
||||
{
|
||||
if (!polymodelsInUse)
|
||||
{
|
||||
gl_FlushModels();
|
||||
polymodelsInUse = true;
|
||||
}
|
||||
}
|
||||
|
||||
void PolyModelRenderer::BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix)
|
||||
{
|
||||
ModelActor = actor;
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include "polyrenderer/drawers/poly_triangle.h"
|
||||
#include "r_data/matrix.h"
|
||||
#include "gl/models/gl_models.h"
|
||||
#include "r_data/models/models.h"
|
||||
|
||||
void PolyRenderModel(PolyRenderThread *thread, const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, uint32_t stencilValue, float x, float y, float z, FSpriteModelFrame *smf, AActor *actor);
|
||||
void PolyRenderHUDModel(PolyRenderThread *thread, const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, uint32_t stencilValue, DPSprite *psp, float ofsx, float ofsy);
|
||||
|
@ -32,7 +32,7 @@ void PolyRenderHUDModel(PolyRenderThread *thread, const TriMatrix &worldToClip,
|
|||
class PolyModelRenderer : public FModelRenderer
|
||||
{
|
||||
public:
|
||||
PolyModelRenderer(PolyRenderThread *thread, const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, uint32_t stencilValue) : Thread(thread), WorldToClip(worldToClip), ClipPlane(clipPlane), StencilValue(stencilValue) { }
|
||||
PolyModelRenderer(PolyRenderThread *thread, const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, uint32_t stencilValue);
|
||||
|
||||
void BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix) override;
|
||||
void EndDrawModel(AActor *actor, FSpriteModelFrame *smf) override;
|
||||
|
|
|
@ -215,4 +215,125 @@ namespace swrenderer
|
|||
fuzzpos = (fuzzpos + yh - yl + 1) % FUZZTABLE;
|
||||
}
|
||||
}
|
||||
|
||||
class DepthColumnCommand : public DrawerCommand
|
||||
{
|
||||
public:
|
||||
DepthColumnCommand(const WallDrawerArgs &args, float idepth) : idepth(idepth)
|
||||
{
|
||||
auto rendertarget = args.Viewport()->RenderTarget;
|
||||
if (rendertarget->IsBgra())
|
||||
{
|
||||
uint32_t *destorg = (uint32_t*)rendertarget->GetBuffer();
|
||||
uint32_t *dest = (uint32_t*)args.Dest();
|
||||
int offset = (int)(ptrdiff_t)(dest - destorg);
|
||||
x = offset % rendertarget->GetPitch();
|
||||
y = offset / rendertarget->GetPitch();
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t *destorg = rendertarget->GetBuffer();
|
||||
uint8_t *dest = (uint8_t*)args.Dest();
|
||||
int offset = (int)(ptrdiff_t)(dest - destorg);
|
||||
x = offset % rendertarget->GetPitch();
|
||||
y = offset / rendertarget->GetPitch();
|
||||
}
|
||||
count = args.Count();
|
||||
}
|
||||
|
||||
DepthColumnCommand(const SkyDrawerArgs &args, float idepth) : idepth(idepth)
|
||||
{
|
||||
auto rendertarget = args.Viewport()->RenderTarget;
|
||||
if (rendertarget->IsBgra())
|
||||
{
|
||||
uint32_t *destorg = (uint32_t*)rendertarget->GetBuffer();
|
||||
uint32_t *dest = (uint32_t*)args.Dest();
|
||||
int offset = (int)(ptrdiff_t)(dest - destorg);
|
||||
x = offset % rendertarget->GetPitch();
|
||||
y = offset / rendertarget->GetPitch();
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t *destorg = rendertarget->GetBuffer();
|
||||
uint8_t *dest = (uint8_t*)args.Dest();
|
||||
int offset = (int)(ptrdiff_t)(dest - destorg);
|
||||
x = offset % rendertarget->GetPitch();
|
||||
y = offset / rendertarget->GetPitch();
|
||||
}
|
||||
count = args.Count();
|
||||
}
|
||||
|
||||
FString DebugInfo() override { return "DepthColumnCommand"; }
|
||||
|
||||
void Execute(DrawerThread *thread) override
|
||||
{
|
||||
auto zbuffer = PolyZBuffer::Instance();
|
||||
int pitch = PolyStencilBuffer::Instance()->BlockWidth() * 8;
|
||||
float *values = zbuffer->Values() + y * pitch + x;
|
||||
int cnt = count;
|
||||
|
||||
values = thread->dest_for_thread(y, pitch, values);
|
||||
cnt = thread->count_for_thread(y, cnt);
|
||||
pitch *= thread->num_cores;
|
||||
|
||||
float depth = idepth;
|
||||
for (int i = 0; i < cnt; i++)
|
||||
{
|
||||
*values = depth;
|
||||
values += pitch;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
int x, y, count;
|
||||
float idepth;
|
||||
};
|
||||
|
||||
class DepthSpanCommand : public DrawerCommand
|
||||
{
|
||||
public:
|
||||
DepthSpanCommand(const SpanDrawerArgs &args, float idepth) : idepth(idepth)
|
||||
{
|
||||
y = args.DestY();
|
||||
x1 = args.DestX1();
|
||||
x2 = args.DestX2();
|
||||
}
|
||||
|
||||
FString DebugInfo() override { return "DepthSpanCommand"; }
|
||||
|
||||
void Execute(DrawerThread *thread) override
|
||||
{
|
||||
if (thread->skipped_by_thread(y))
|
||||
return;
|
||||
|
||||
auto zbuffer = PolyZBuffer::Instance();
|
||||
int pitch = PolyStencilBuffer::Instance()->BlockWidth() * 8;
|
||||
float *values = zbuffer->Values() + y * pitch;
|
||||
int end = x2;
|
||||
float depth = idepth;
|
||||
for (int x = x1; x <= end; x++)
|
||||
{
|
||||
values[x] = depth;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
int y, x1, x2;
|
||||
float idepth;
|
||||
};
|
||||
|
||||
void SWPixelFormatDrawers::DrawDepthSkyColumn(const SkyDrawerArgs &args, float idepth)
|
||||
{
|
||||
Queue->Push<DepthColumnCommand>(args, idepth);
|
||||
}
|
||||
|
||||
void SWPixelFormatDrawers::DrawDepthWallColumn(const WallDrawerArgs &args, float idepth)
|
||||
{
|
||||
Queue->Push<DepthColumnCommand>(args, idepth);
|
||||
}
|
||||
|
||||
void SWPixelFormatDrawers::DrawDepthSpan(const SpanDrawerArgs &args, float idepth)
|
||||
{
|
||||
Queue->Push<DepthSpanCommand>(args, idepth);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,6 +94,10 @@ namespace swrenderer
|
|||
virtual void DrawTiltedSpan(const SpanDrawerArgs &args, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy, FDynamicColormap *basecolormap) = 0;
|
||||
virtual void DrawColoredSpan(const SpanDrawerArgs &args) = 0;
|
||||
virtual void DrawFogBoundaryLine(const SpanDrawerArgs &args) = 0;
|
||||
|
||||
void DrawDepthSkyColumn(const SkyDrawerArgs &args, float idepth);
|
||||
void DrawDepthWallColumn(const WallDrawerArgs &args, float idepth);
|
||||
void DrawDepthSpan(const SpanDrawerArgs &args, float idepth);
|
||||
|
||||
DrawerCommandQueuePtr Queue;
|
||||
};
|
||||
|
|
|
@ -177,16 +177,18 @@ namespace swrenderer
|
|||
// Draw a column with support for non-power-of-two ranges
|
||||
void RenderWallPart::Draw1Column(int x, int y1, int y2, WallSampler &sampler)
|
||||
{
|
||||
// Find column position in view space
|
||||
float w1 = 1.0f / WallC.sz1;
|
||||
float w2 = 1.0f / WallC.sz2;
|
||||
float t = (x - WallC.sx1 + 0.5f) / (WallC.sx2 - WallC.sx1);
|
||||
float wcol = w1 * (1.0f - t) + w2 * t;
|
||||
float zcol = 1.0f / wcol;
|
||||
float zbufferdepth = 1.0f / (zcol / Thread->Viewport->viewwindow.FocalTangent);
|
||||
|
||||
if (r_dynlights && light_list)
|
||||
{
|
||||
auto viewport = Thread->Viewport.get();
|
||||
|
||||
// Find column position in view space
|
||||
float w1 = 1.0f / WallC.sz1;
|
||||
float w2 = 1.0f / WallC.sz2;
|
||||
float t = (x - WallC.sx1 + 0.5f) / (WallC.sx2 - WallC.sx1);
|
||||
float wcol = w1 * (1.0f - t) + w2 * t;
|
||||
float zcol = 1.0f / wcol;
|
||||
drawerargs.dc_viewpos.X = (float)((x + 0.5 - viewport->CenterX) / viewport->CenterX * zcol);
|
||||
drawerargs.dc_viewpos.Y = zcol;
|
||||
drawerargs.dc_viewpos.Z = (float)((viewport->CenterY - y1 - 0.5) / viewport->InvZtoScale * zcol);
|
||||
|
@ -260,6 +262,7 @@ namespace swrenderer
|
|||
drawerargs.SetTextureVStep(sampler.uv_step);
|
||||
drawerargs.SetTextureVPos(sampler.uv_pos);
|
||||
drawerargs.DrawColumn(Thread);
|
||||
drawerargs.DrawDepthColumn(Thread, zbufferdepth);
|
||||
|
||||
uint64_t step64 = sampler.uv_step;
|
||||
uint64_t pos64 = sampler.uv_pos;
|
||||
|
@ -278,6 +281,7 @@ namespace swrenderer
|
|||
drawerargs.SetTextureVStep(sampler.uv_step);
|
||||
drawerargs.SetTextureVPos(sampler.uv_pos);
|
||||
drawerargs.DrawColumn(Thread);
|
||||
drawerargs.DrawDepthColumn(Thread, zbufferdepth);
|
||||
|
||||
uint64_t step64 = sampler.uv_step;
|
||||
uint64_t pos64 = sampler.uv_pos;
|
||||
|
@ -304,6 +308,7 @@ namespace swrenderer
|
|||
drawerargs.SetTextureVStep(sampler.uv_step);
|
||||
drawerargs.SetTextureVPos(uv_pos);
|
||||
drawerargs.DrawColumn(Thread);
|
||||
drawerargs.DrawDepthColumn(Thread, zbufferdepth);
|
||||
|
||||
y += count;
|
||||
left -= count;
|
||||
|
|
|
@ -178,6 +178,7 @@ namespace swrenderer
|
|||
double curyfrac = baseyfrac + ystepscale * (x1 - minx);
|
||||
|
||||
double distance = viewport->PlaneDepth(y, planeheight);
|
||||
float zbufferdepth = 1.0f / (distance * Thread->Viewport->viewwindow.FocalTangent);
|
||||
|
||||
drawerargs.SetTextureUStep(distance * xstepscale / drawerargs.TextureWidth());
|
||||
drawerargs.SetTextureUPos((distance * curxfrac + pviewx) / drawerargs.TextureWidth());
|
||||
|
@ -274,6 +275,7 @@ namespace swrenderer
|
|||
drawerargs.SetDestX2(x2);
|
||||
|
||||
drawerargs.DrawSpan(Thread);
|
||||
drawerargs.DrawDepthSpan(Thread, zbufferdepth);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -224,6 +224,8 @@ namespace swrenderer
|
|||
drawerargs.DrawSingleSkyColumn(Thread);
|
||||
else
|
||||
drawerargs.DrawDoubleSkyColumn(Thread);
|
||||
|
||||
drawerargs.DrawDepthSkyColumn(Thread, 1.0f / 65536.0f);
|
||||
}
|
||||
|
||||
void RenderSkyPlane::DrawSkyColumn(int start_x, int y1, int y2)
|
||||
|
|
|
@ -85,7 +85,7 @@ namespace swrenderer
|
|||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
auto viewport = Thread->Viewport.get();
|
||||
|
||||
drawerargs.SetSolidColor(3);
|
||||
|
@ -205,6 +205,15 @@ namespace swrenderer
|
|||
|
||||
void RenderSlopePlane::RenderLine(int y, int x1, int x2)
|
||||
{
|
||||
/* To do: project (x1,y) and (x2,y) on the plane to calculate the depth
|
||||
double distance = Thread->Viewport->PlaneDepth(y, planeheight);
|
||||
float zbufferdepth = 1.0f / (distance * Thread->Viewport->viewwindow.FocalTangent);
|
||||
drawerargs.SetDestX1(x1);
|
||||
drawerargs.SetDestX2(x2);
|
||||
drawerargs.SetDestY(Thread->Viewport.get(), y);
|
||||
drawerargs.DrawDepthSpan(Thread, zbufferdepth);
|
||||
*/
|
||||
|
||||
drawerargs.DrawTiltedSpan(Thread, y, x1, x2, plane_sz, plane_su, plane_sv, plane_shade, planeshade, planelightfloat, pviewx, pviewy, basecolormap);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "things/r_visiblespritelist.cpp"
|
||||
#include "things/r_voxel.cpp"
|
||||
#include "things/r_wallsprite.cpp"
|
||||
#include "things/r_model.cpp"
|
||||
#include "viewport/r_drawerargs.cpp"
|
||||
#include "viewport/r_skydrawer.cpp"
|
||||
#include "viewport/r_spandrawer.cpp"
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "swrenderer/things/r_wallsprite.h"
|
||||
#include "swrenderer/things/r_voxel.h"
|
||||
#include "swrenderer/things/r_particle.h"
|
||||
#include "swrenderer/things/r_model.h"
|
||||
#include "swrenderer/segments/r_clipsegment.h"
|
||||
#include "swrenderer/line/r_wallsetup.h"
|
||||
#include "swrenderer/line/r_farclip_line.h"
|
||||
|
@ -951,7 +952,18 @@ namespace swrenderer
|
|||
}
|
||||
else
|
||||
{
|
||||
RenderSprite::Project(Thread, thing, sprite.pos, sprite.tex, sprite.spriteScale, sprite.renderflags, fakeside, fakefloor, fakeceiling, sec, thingShade, foggy, thingColormap);
|
||||
int spritenum = thing->sprite;
|
||||
bool isPicnumOverride = thing->picnum.isValid();
|
||||
FSpriteModelFrame *modelframe = isPicnumOverride ? nullptr : gl_FindModelFrame(thing->GetClass(), spritenum, thing->frame, !!(thing->flags & MF_DROPPED));
|
||||
if (modelframe)
|
||||
{
|
||||
DVector3 pos = thing->InterpolatedPosition(Thread->Viewport->viewpoint.TicFrac);
|
||||
RenderModel::Project(Thread, (float)pos.X, (float)pos.Y, (float)pos.Z, modelframe, thing);
|
||||
}
|
||||
else
|
||||
{
|
||||
RenderSprite::Project(Thread, thing, sprite.pos, sprite.tex, sprite.spriteScale, sprite.renderflags, fakeside, fakefloor, fakeceiling, sec, thingShade, foggy, thingColormap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -156,6 +156,8 @@ namespace swrenderer
|
|||
|
||||
R_UpdateFuzzPosFrameStart();
|
||||
|
||||
MainThread()->Viewport->SetupPolyViewport();
|
||||
|
||||
ActorRenderFlags savedflags = MainThread()->Viewport->viewpoint.camera->renderflags;
|
||||
// Never draw the player unless in chasecam mode
|
||||
if (!MainThread()->Viewport->viewpoint.showviewer)
|
||||
|
|
307
src/swrenderer/things/r_model.cpp
Normal file
307
src/swrenderer/things/r_model.cpp
Normal file
|
@ -0,0 +1,307 @@
|
|||
/*
|
||||
** Polygon Doom software renderer
|
||||
** 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.
|
||||
**
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "templates.h"
|
||||
#include "doomdef.h"
|
||||
#include "sbar.h"
|
||||
#include "r_data/r_translate.h"
|
||||
#include "r_model.h"
|
||||
#include "r_data/r_vanillatrans.h"
|
||||
#include "actorinlines.h"
|
||||
#include "i_time.h"
|
||||
#include "swrenderer/r_memory.h"
|
||||
#include "swrenderer/r_swcolormaps.h"
|
||||
#include "swrenderer/viewport/r_viewport.h"
|
||||
#include "swrenderer/scene/r_light.h"
|
||||
|
||||
void gl_FlushModels();
|
||||
extern bool polymodelsInUse;
|
||||
|
||||
namespace swrenderer
|
||||
{
|
||||
void RenderModel::Project(RenderThread *thread, float x, float y, float z, FSpriteModelFrame *smf, AActor *actor)
|
||||
{
|
||||
// transform the origin point
|
||||
double tr_x = x - thread->Viewport->viewpoint.Pos.X;
|
||||
double tr_y = y - thread->Viewport->viewpoint.Pos.Y;
|
||||
double tz = tr_x * thread->Viewport->viewpoint.TanCos + tr_y * thread->Viewport->viewpoint.TanSin;
|
||||
|
||||
// thing is behind view plane?
|
||||
if (tz < MINZ)
|
||||
return;
|
||||
|
||||
// too far off the side?
|
||||
double tx = tr_x * thread->Viewport->viewpoint.Sin - tr_y * thread->Viewport->viewpoint.Cos;
|
||||
if (fabs(tx / 64) > fabs(tz))
|
||||
return;
|
||||
|
||||
RenderModel *vis = thread->FrameMemory->NewObject<RenderModel>(x, y, z, smf, actor, float(1 / tz));
|
||||
thread->SpriteList->Push(vis);
|
||||
}
|
||||
|
||||
RenderModel::RenderModel(float x, float y, float z, FSpriteModelFrame *smf, AActor *actor, float idepth) : x(x), y(y), z(z), smf(smf), actor(actor)
|
||||
{
|
||||
this->idepth = idepth;
|
||||
}
|
||||
|
||||
void RenderModel::Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ)
|
||||
{
|
||||
SWModelRenderer renderer(thread);
|
||||
renderer.RenderModel(x, y, z, smf, actor);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RenderHUDModel(RenderThread *thread, DPSprite *psp, float ofsx, float ofsy)
|
||||
{
|
||||
SWModelRenderer renderer(thread);
|
||||
renderer.RenderHUDModel(psp, ofsx, ofsy);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SWModelRenderer::SWModelRenderer(RenderThread *thread) : Thread(thread)
|
||||
{
|
||||
if (polymodelsInUse)
|
||||
{
|
||||
gl_FlushModels();
|
||||
polymodelsInUse = false;
|
||||
}
|
||||
}
|
||||
|
||||
void SWModelRenderer::BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix)
|
||||
{
|
||||
ModelActor = actor;
|
||||
const_cast<VSMatrix &>(objectToWorldMatrix).copy(ObjectToWorld.matrix);
|
||||
}
|
||||
|
||||
void SWModelRenderer::EndDrawModel(AActor *actor, FSpriteModelFrame *smf)
|
||||
{
|
||||
ModelActor = nullptr;
|
||||
}
|
||||
|
||||
IModelVertexBuffer *SWModelRenderer::CreateVertexBuffer(bool needindex, bool singleframe)
|
||||
{
|
||||
return new SWModelVertexBuffer(needindex, singleframe);
|
||||
}
|
||||
|
||||
void SWModelRenderer::SetVertexBuffer(IModelVertexBuffer *buffer)
|
||||
{
|
||||
}
|
||||
|
||||
void SWModelRenderer::ResetVertexBuffer()
|
||||
{
|
||||
}
|
||||
|
||||
VSMatrix SWModelRenderer::GetViewToWorldMatrix()
|
||||
{
|
||||
TriMatrix swapYZ = TriMatrix::null();
|
||||
swapYZ.matrix[0 + 0 * 4] = 1.0f;
|
||||
swapYZ.matrix[1 + 2 * 4] = 1.0f;
|
||||
swapYZ.matrix[2 + 1 * 4] = 1.0f;
|
||||
swapYZ.matrix[3 + 3 * 4] = 1.0f;
|
||||
|
||||
VSMatrix worldToView;
|
||||
worldToView.loadMatrix((Thread->Viewport->WorldToView * swapYZ).matrix);
|
||||
|
||||
VSMatrix objectToWorld;
|
||||
worldToView.inverseMatrix(objectToWorld);
|
||||
return objectToWorld;
|
||||
}
|
||||
|
||||
void SWModelRenderer::BeginDrawHUDModel(AActor *actor, const VSMatrix &objectToWorldMatrix)
|
||||
{
|
||||
ModelActor = actor;
|
||||
const_cast<VSMatrix &>(objectToWorldMatrix).copy(ObjectToWorld.matrix);
|
||||
}
|
||||
|
||||
void SWModelRenderer::EndDrawHUDModel(AActor *actor)
|
||||
{
|
||||
ModelActor = nullptr;
|
||||
}
|
||||
|
||||
void SWModelRenderer::SetInterpolation(double interpolation)
|
||||
{
|
||||
InterpolationFactor = (float)interpolation;
|
||||
}
|
||||
|
||||
void SWModelRenderer::SetMaterial(FTexture *skin, bool clampNoFilter, int translation)
|
||||
{
|
||||
SkinTexture = skin;
|
||||
}
|
||||
|
||||
void SWModelRenderer::DrawArrays(int start, int count)
|
||||
{
|
||||
const auto &viewpoint = Thread->Viewport->viewpoint;
|
||||
|
||||
bool foggy = false;
|
||||
int actualextralight = foggy ? 0 : viewpoint.extralight << 4;
|
||||
sector_t *sector = ModelActor->Sector;
|
||||
|
||||
bool fullbrightSprite = ((ModelActor->renderflags & RF_FULLBRIGHT) || (ModelActor->flags5 & MF5_BRIGHT));
|
||||
int lightlevel = fullbrightSprite ? 255 : ModelActor->Sector->lightlevel + actualextralight;
|
||||
|
||||
TriMatrix swapYZ = TriMatrix::null();
|
||||
swapYZ.matrix[0 + 0 * 4] = 1.0f;
|
||||
swapYZ.matrix[1 + 2 * 4] = 1.0f;
|
||||
swapYZ.matrix[2 + 1 * 4] = 1.0f;
|
||||
swapYZ.matrix[3 + 3 * 4] = 1.0f;
|
||||
|
||||
TriMatrix *transform = Thread->FrameMemory->NewObject<TriMatrix>();
|
||||
*transform = Thread->Viewport->WorldToClip * swapYZ * ObjectToWorld;
|
||||
|
||||
PolyDrawArgs args;
|
||||
args.SetLight(GetColorTable(sector->Colormap, sector->SpecialColors[sector_t::sprites], true), lightlevel, Thread->Light->SpriteGlobVis(foggy), fullbrightSprite);
|
||||
args.SetTransform(transform);
|
||||
args.SetFaceCullCCW(true);
|
||||
args.SetClipPlane(0, PolyClipPlane());
|
||||
args.SetStyle(TriBlendMode::TextureOpaque);
|
||||
|
||||
if (Thread->Viewport->RenderTarget->IsBgra())
|
||||
args.SetTexture((const uint8_t *)SkinTexture->GetPixelsBgra(), SkinTexture->GetWidth(), SkinTexture->GetHeight());
|
||||
else
|
||||
args.SetTexture(SkinTexture->GetPixels(), SkinTexture->GetWidth(), SkinTexture->GetHeight());
|
||||
|
||||
args.SetDepthTest(true);
|
||||
args.SetWriteDepth(true);
|
||||
args.SetWriteStencil(false);
|
||||
args.DrawArray(Thread->DrawQueue, VertexBuffer + start, count);
|
||||
}
|
||||
|
||||
void SWModelRenderer::DrawElements(int numIndices, size_t offset)
|
||||
{
|
||||
const auto &viewpoint = Thread->Viewport->viewpoint;
|
||||
|
||||
bool foggy = false;
|
||||
int actualextralight = foggy ? 0 : viewpoint.extralight << 4;
|
||||
sector_t *sector = ModelActor->Sector;
|
||||
|
||||
bool fullbrightSprite = ((ModelActor->renderflags & RF_FULLBRIGHT) || (ModelActor->flags5 & MF5_BRIGHT));
|
||||
int lightlevel = fullbrightSprite ? 255 : ModelActor->Sector->lightlevel + actualextralight;
|
||||
|
||||
TriMatrix swapYZ = TriMatrix::null();
|
||||
swapYZ.matrix[0 + 0 * 4] = 1.0f;
|
||||
swapYZ.matrix[1 + 2 * 4] = 1.0f;
|
||||
swapYZ.matrix[2 + 1 * 4] = 1.0f;
|
||||
swapYZ.matrix[3 + 3 * 4] = 1.0f;
|
||||
|
||||
TriMatrix *transform = Thread->FrameMemory->NewObject<TriMatrix>();
|
||||
*transform = Thread->Viewport->WorldToClip * swapYZ * ObjectToWorld;
|
||||
|
||||
PolyDrawArgs args;
|
||||
args.SetLight(GetColorTable(sector->Colormap, sector->SpecialColors[sector_t::sprites], true), lightlevel, Thread->Light->SpriteGlobVis(foggy), fullbrightSprite);
|
||||
args.SetTransform(transform);
|
||||
args.SetFaceCullCCW(true);
|
||||
args.SetClipPlane(0, PolyClipPlane());
|
||||
args.SetStyle(TriBlendMode::TextureOpaque);
|
||||
|
||||
if (Thread->Viewport->RenderTarget->IsBgra())
|
||||
args.SetTexture((const uint8_t *)SkinTexture->GetPixelsBgra(), SkinTexture->GetWidth(), SkinTexture->GetHeight());
|
||||
else
|
||||
args.SetTexture(SkinTexture->GetPixels(), SkinTexture->GetWidth(), SkinTexture->GetHeight());
|
||||
|
||||
args.SetDepthTest(true);
|
||||
args.SetWriteDepth(true);
|
||||
args.SetWriteStencil(false);
|
||||
args.DrawElements(Thread->DrawQueue, VertexBuffer, IndexBuffer + offset / sizeof(unsigned int), numIndices);
|
||||
}
|
||||
|
||||
double SWModelRenderer::GetTimeFloat()
|
||||
{
|
||||
return (double)screen->FrameTime * (double)TICRATE / 1000.0;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SWModelVertexBuffer::SWModelVertexBuffer(bool needindex, bool singleframe)
|
||||
{
|
||||
}
|
||||
|
||||
SWModelVertexBuffer::~SWModelVertexBuffer()
|
||||
{
|
||||
}
|
||||
|
||||
FModelVertex *SWModelVertexBuffer::LockVertexBuffer(unsigned int size)
|
||||
{
|
||||
mVertexBuffer.Resize(size);
|
||||
return &mVertexBuffer[0];
|
||||
}
|
||||
|
||||
void SWModelVertexBuffer::UnlockVertexBuffer()
|
||||
{
|
||||
}
|
||||
|
||||
unsigned int *SWModelVertexBuffer::LockIndexBuffer(unsigned int size)
|
||||
{
|
||||
mIndexBuffer.Resize(size);
|
||||
return &mIndexBuffer[0];
|
||||
}
|
||||
|
||||
void SWModelVertexBuffer::UnlockIndexBuffer()
|
||||
{
|
||||
}
|
||||
|
||||
void SWModelVertexBuffer::SetupFrame(FModelRenderer *renderer, unsigned int frame1, unsigned int frame2, unsigned int size)
|
||||
{
|
||||
SWModelRenderer *polyrenderer = (SWModelRenderer *)renderer;
|
||||
|
||||
if (true)//if (frame1 == frame2 || size == 0 || polyrenderer->InterpolationFactor == 0.f)
|
||||
{
|
||||
TriVertex *vertices = polyrenderer->Thread->FrameMemory->AllocMemory<TriVertex>(size);
|
||||
|
||||
for (unsigned int i = 0; i < size; i++)
|
||||
{
|
||||
vertices[i] =
|
||||
{
|
||||
mVertexBuffer[frame1 + i].x,
|
||||
mVertexBuffer[frame1 + i].y,
|
||||
mVertexBuffer[frame1 + i].z,
|
||||
1.0f,
|
||||
mVertexBuffer[frame1 + i].u,
|
||||
mVertexBuffer[frame1 + i].v
|
||||
};
|
||||
}
|
||||
|
||||
polyrenderer->VertexBuffer = vertices;
|
||||
polyrenderer->IndexBuffer = &mIndexBuffer[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
TriVertex *vertices = polyrenderer->Thread->FrameMemory->AllocMemory<TriVertex>(size);
|
||||
|
||||
float frac = polyrenderer->InterpolationFactor;
|
||||
for (unsigned int i = 0; i < size; i++)
|
||||
{
|
||||
vertices[i].x = mVertexBuffer[frame1 + i].x * (1.0f - frac) + mVertexBuffer[frame2 + i].x * frac;
|
||||
vertices[i].y = mVertexBuffer[frame1 + i].y * (1.0f - frac) + mVertexBuffer[frame2 + i].y * frac;
|
||||
vertices[i].z = mVertexBuffer[frame1 + i].z * (1.0f - frac) + mVertexBuffer[frame2 + i].z * frac;
|
||||
vertices[i].w = 1.0f;
|
||||
vertices[i].u = mVertexBuffer[frame1 + i].u;
|
||||
vertices[i].v = mVertexBuffer[frame1 + i].v;
|
||||
}
|
||||
|
||||
polyrenderer->VertexBuffer = vertices;
|
||||
polyrenderer->IndexBuffer = &mIndexBuffer[0];
|
||||
}
|
||||
}
|
||||
}
|
100
src/swrenderer/things/r_model.h
Normal file
100
src/swrenderer/things/r_model.h
Normal file
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
** Polygon Doom software renderer
|
||||
** 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.
|
||||
**
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "polyrenderer/drawers/poly_triangle.h"
|
||||
#include "r_data/matrix.h"
|
||||
#include "r_data/models/models.h"
|
||||
#include "swrenderer/r_renderthread.h"
|
||||
#include "swrenderer/things/r_visiblesprite.h"
|
||||
|
||||
namespace swrenderer
|
||||
{
|
||||
void RenderHUDModel(RenderThread *thread, DPSprite *psp, float ofsx, float ofsy);
|
||||
|
||||
class RenderModel : public VisibleSprite
|
||||
{
|
||||
public:
|
||||
RenderModel(float x, float y, float z, FSpriteModelFrame *smf, AActor *actor, float idepth);
|
||||
|
||||
static void Project(RenderThread *thread, float x, float y, float z, FSpriteModelFrame *smf, AActor *actor);
|
||||
|
||||
protected:
|
||||
void Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ) override;
|
||||
bool IsModel() const override { return true; }
|
||||
|
||||
private:
|
||||
float x, y, z;
|
||||
FSpriteModelFrame *smf;
|
||||
AActor *actor;
|
||||
};
|
||||
|
||||
class SWModelRenderer : public FModelRenderer
|
||||
{
|
||||
public:
|
||||
SWModelRenderer(RenderThread *thread);
|
||||
|
||||
void BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix) override;
|
||||
void EndDrawModel(AActor *actor, FSpriteModelFrame *smf) override;
|
||||
IModelVertexBuffer *CreateVertexBuffer(bool needindex, bool singleframe) override;
|
||||
void SetVertexBuffer(IModelVertexBuffer *buffer) override;
|
||||
void ResetVertexBuffer() override;
|
||||
VSMatrix GetViewToWorldMatrix() override;
|
||||
void BeginDrawHUDModel(AActor *actor, const VSMatrix &objectToWorldMatrix) override;
|
||||
void EndDrawHUDModel(AActor *actor) override;
|
||||
void SetInterpolation(double interpolation) override;
|
||||
void SetMaterial(FTexture *skin, bool clampNoFilter, int translation) override;
|
||||
void DrawArrays(int start, int count) override;
|
||||
void DrawElements(int numIndices, size_t offset) override;
|
||||
double GetTimeFloat() override;
|
||||
|
||||
RenderThread *Thread = nullptr;
|
||||
|
||||
AActor *ModelActor = nullptr;
|
||||
TriMatrix ObjectToWorld;
|
||||
FTexture *SkinTexture = nullptr;
|
||||
unsigned int *IndexBuffer = nullptr;
|
||||
TriVertex *VertexBuffer = nullptr;
|
||||
float InterpolationFactor = 0.0;
|
||||
};
|
||||
|
||||
class SWModelVertexBuffer : public IModelVertexBuffer
|
||||
{
|
||||
public:
|
||||
SWModelVertexBuffer(bool needindex, bool singleframe);
|
||||
~SWModelVertexBuffer();
|
||||
|
||||
FModelVertex *LockVertexBuffer(unsigned int size) override;
|
||||
void UnlockVertexBuffer() override;
|
||||
|
||||
unsigned int *LockIndexBuffer(unsigned int size) override;
|
||||
void UnlockIndexBuffer() override;
|
||||
|
||||
void SetupFrame(FModelRenderer *renderer, unsigned int frame1, unsigned int frame2, unsigned int size) override;
|
||||
|
||||
private:
|
||||
int mIndexFrame[2];
|
||||
TArray<FModelVertex> mVertexBuffer;
|
||||
TArray<unsigned int> mIndexBuffer;
|
||||
};
|
||||
}
|
|
@ -88,6 +88,8 @@ namespace swrenderer
|
|||
int floorlight, ceilinglight;
|
||||
F3DFloor *rover;
|
||||
|
||||
renderHUDModel = gl_IsHUDModelForPlayerAvailable(players[consoleplayer].camera->player);
|
||||
|
||||
if (!r_drawplayersprites ||
|
||||
!Thread->Viewport->viewpoint.camera ||
|
||||
!Thread->Viewport->viewpoint.camera->player ||
|
||||
|
@ -250,6 +252,12 @@ namespace swrenderer
|
|||
sy += wy;
|
||||
}
|
||||
|
||||
if (renderHUDModel)
|
||||
{
|
||||
RenderHUDModel(Thread, pspr, (float)sx, (float)sy);
|
||||
return;
|
||||
}
|
||||
|
||||
auto viewport = Thread->Viewport.get();
|
||||
|
||||
double pspritexscale = viewport->viewwindow.centerxwide / 160.0;
|
||||
|
|
|
@ -97,5 +97,6 @@ namespace swrenderer
|
|||
|
||||
TArray<HWAccelPlayerSprite> AcceleratedSprites;
|
||||
sector_t tempsec;
|
||||
bool renderHUDModel = false;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -51,6 +51,12 @@ namespace swrenderer
|
|||
{
|
||||
void VisibleSprite::Render(RenderThread *thread)
|
||||
{
|
||||
if (IsModel())
|
||||
{
|
||||
Render(thread, nullptr, nullptr, 0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
short *clipbot = thread->clipbot;
|
||||
short *cliptop = thread->cliptop;
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ namespace swrenderer
|
|||
virtual bool IsParticle() const { return false; }
|
||||
virtual bool IsVoxel() const { return false; }
|
||||
virtual bool IsWallSprite() const { return false; }
|
||||
virtual bool IsModel() const { return false; }
|
||||
|
||||
virtual void Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ) = 0;
|
||||
|
||||
|
|
|
@ -25,6 +25,11 @@
|
|||
|
||||
namespace swrenderer
|
||||
{
|
||||
void SkyDrawerArgs::DrawDepthSkyColumn(RenderThread *thread, float idepth)
|
||||
{
|
||||
thread->Drawers(dc_viewport)->DrawDepthSkyColumn(*this, idepth);
|
||||
}
|
||||
|
||||
void SkyDrawerArgs::DrawSingleSkyColumn(RenderThread *thread)
|
||||
{
|
||||
thread->Drawers(dc_viewport)->DrawSingleSkyColumn(*this);
|
||||
|
|
|
@ -41,6 +41,7 @@ namespace swrenderer
|
|||
|
||||
RenderViewport *Viewport() const { return dc_viewport; }
|
||||
|
||||
void DrawDepthSkyColumn(RenderThread *thread, float idepth);
|
||||
void DrawSingleSkyColumn(RenderThread *thread);
|
||||
void DrawDoubleSkyColumn(RenderThread *thread);
|
||||
|
||||
|
|
|
@ -107,6 +107,11 @@ namespace swrenderer
|
|||
}
|
||||
}
|
||||
|
||||
void SpanDrawerArgs::DrawDepthSpan(RenderThread *thread, float idepth)
|
||||
{
|
||||
thread->Drawers(ds_viewport)->DrawDepthSpan(*this, idepth);
|
||||
}
|
||||
|
||||
void SpanDrawerArgs::DrawSpan(RenderThread *thread)
|
||||
{
|
||||
(thread->Drawers(ds_viewport)->*spanfunc)(*this);
|
||||
|
|
|
@ -27,6 +27,7 @@ namespace swrenderer
|
|||
void SetTextureVStep(double vstep) { ds_ystep = (uint32_t)(int64_t)(vstep * 4294967296.0); }
|
||||
void SetSolidColor(int colorIndex) { ds_color = colorIndex; }
|
||||
|
||||
void DrawDepthSpan(RenderThread *thread, float idepth);
|
||||
void DrawSpan(RenderThread *thread);
|
||||
void DrawTiltedSpan(RenderThread *thread, int y, int x1, int x2, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy, FDynamicColormap *basecolormap);
|
||||
void DrawColoredSpan(RenderThread *thread, int y, int x1, int x2);
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
CVAR(String, r_viewsize, "", CVAR_NOSET)
|
||||
|
||||
EXTERN_CVAR(Float, r_visibility);
|
||||
EXTERN_CVAR(Int, screenblocks)
|
||||
|
||||
namespace swrenderer
|
||||
{
|
||||
|
@ -58,6 +59,17 @@ namespace swrenderer
|
|||
{
|
||||
}
|
||||
|
||||
void RenderViewport::SetupPolyViewport()
|
||||
{
|
||||
PolyStencilBuffer::Instance()->Clear(RenderTarget->GetWidth(), RenderTarget->GetHeight(), 0);
|
||||
PolyZBuffer::Instance()->Resize(RenderTarget->GetPitch(), RenderTarget->GetHeight());
|
||||
|
||||
PolyTriangleDrawer::set_viewport(viewwindowx, viewwindowy, viewwidth, viewheight, RenderTarget);
|
||||
WorldToView = TriMatrix::worldToView(viewpoint);
|
||||
ViewToClip = TriMatrix::viewToClip(viewwindow.FocalTangent, CenterY, YaspectMul);
|
||||
WorldToClip = ViewToClip * WorldToView;
|
||||
}
|
||||
|
||||
void RenderViewport::SetViewport(RenderThread *thread, int fullWidth, int fullHeight, float trueratio)
|
||||
{
|
||||
int virtheight, virtwidth, virtwidth2, virtheight2;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <memory>
|
||||
#include "v_video.h"
|
||||
#include "r_defs.h"
|
||||
#include "polyrenderer/math/tri_matrix.h"
|
||||
|
||||
namespace swrenderer
|
||||
{
|
||||
|
@ -19,6 +20,12 @@ namespace swrenderer
|
|||
void SetViewport(RenderThread *thread, int width, int height, float trueratio);
|
||||
void SetupFreelook();
|
||||
|
||||
void SetupPolyViewport();
|
||||
|
||||
TriMatrix WorldToView;
|
||||
TriMatrix ViewToClip;
|
||||
TriMatrix WorldToClip;
|
||||
|
||||
DCanvas *RenderTarget = nullptr;
|
||||
|
||||
FViewWindow viewwindow;
|
||||
|
|
|
@ -32,6 +32,11 @@ namespace swrenderer
|
|||
dc_dest_y = y;
|
||||
}
|
||||
|
||||
void WallDrawerArgs::DrawDepthColumn(RenderThread *thread, float idepth)
|
||||
{
|
||||
thread->Drawers(dc_viewport)->DrawDepthWallColumn(*this, idepth);
|
||||
}
|
||||
|
||||
void WallDrawerArgs::DrawColumn(RenderThread *thread)
|
||||
{
|
||||
(thread->Drawers(dc_viewport)->*wallfunc)(*this);
|
||||
|
|
|
@ -30,6 +30,7 @@ namespace swrenderer
|
|||
|
||||
bool IsMaskedDrawer() const;
|
||||
|
||||
void DrawDepthColumn(RenderThread *thread, float idepth);
|
||||
void DrawColumn(RenderThread *thread);
|
||||
|
||||
uint8_t *Dest() const { return dc_dest; }
|
||||
|
|
Loading…
Reference in a new issue