mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-29 15:32:54 +00:00
Double render speed of triangle drawer in the poly version by removing sprite clip and assigning whole blocks to threads
This commit is contained in:
parent
dffba5267d
commit
cb4b74e0c3
5 changed files with 1164 additions and 17 deletions
|
@ -1052,6 +1052,7 @@ set( FASTMATH_PCH_SOURCES
|
|||
r_swrenderer.cpp
|
||||
r_swrenderer2.cpp
|
||||
r_poly.cpp
|
||||
r_poly_triangle.cpp
|
||||
r_3dfloors.cpp
|
||||
r_bsp.cpp
|
||||
r_draw.cpp
|
||||
|
|
|
@ -35,23 +35,12 @@ EXTERN_CVAR(Bool, r_drawplayersprites)
|
|||
EXTERN_CVAR(Bool, r_deathcamera)
|
||||
EXTERN_CVAR(Bool, st_scale)
|
||||
|
||||
namespace
|
||||
{
|
||||
short cliptop[MAXWIDTH], clipbottom[MAXWIDTH];
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RenderPolyBsp::Render()
|
||||
{
|
||||
PolyVertexBuffer::Clear();
|
||||
|
||||
for (int i = 0; i < viewwidth; i++)
|
||||
{
|
||||
cliptop[i] = 0;
|
||||
clipbottom[i] = viewheight;
|
||||
}
|
||||
|
||||
// Perspective correct:
|
||||
float ratio = WidescreenRatio;
|
||||
float fovratio = (WidescreenRatio >= 1.3f) ? 1.333333f : ratio;
|
||||
|
@ -143,11 +132,11 @@ void RenderPolyBsp::RenderSubsector(subsector_t *sub)
|
|||
|
||||
FTexture *floortex = TexMan(frontsector->GetTexture(sector_t::floor));
|
||||
if (floortex->UseType != FTexture::TEX_Null)
|
||||
TriangleDrawer::draw(worldToClip, floorVertices, sub->numlines, TriangleDrawMode::Fan, true, 0, viewwidth, cliptop, clipbottom, floortex);
|
||||
PolyTriangleDrawer::draw(worldToClip, floorVertices, sub->numlines, TriangleDrawMode::Fan, true, 0, viewwidth, 0, viewheight, floortex);
|
||||
|
||||
FTexture *ceiltex = TexMan(frontsector->GetTexture(sector_t::ceiling));
|
||||
if (ceiltex->UseType != FTexture::TEX_Null)
|
||||
TriangleDrawer::draw(worldToClip, ceilVertices, sub->numlines, TriangleDrawMode::Fan, true, 0, viewwidth, cliptop, clipbottom, ceiltex);
|
||||
PolyTriangleDrawer::draw(worldToClip, ceilVertices, sub->numlines, TriangleDrawMode::Fan, true, 0, viewwidth, 0, viewheight, ceiltex);
|
||||
|
||||
for (AActor *thing = sub->sector->thinglist; thing != nullptr; thing = thing->snext)
|
||||
{
|
||||
|
@ -357,8 +346,7 @@ void RenderPolyBsp::AddSprite(AActor *thing, subsector_t *sub)
|
|||
vertices[i].varying[2] = (thing->Sector->lightlevel + actualextralight) / 255.0f;
|
||||
}
|
||||
|
||||
TriangleDrawer::draw(worldToClip, vertices, 4, TriangleDrawMode::Fan, true, 0, viewwidth, cliptop, clipbottom, tex);
|
||||
TriangleDrawer::draw(worldToClip, vertices, 4, TriangleDrawMode::Fan, false, 0, viewwidth, cliptop, clipbottom, tex);
|
||||
PolyTriangleDrawer::draw(worldToClip, vertices, 4, TriangleDrawMode::Fan, true, 0, viewwidth, 0, viewheight, tex);
|
||||
}
|
||||
|
||||
void RenderPolyBsp::AddWallSprite(AActor *thing, subsector_t *sub)
|
||||
|
@ -895,7 +883,7 @@ void RenderPolyWall::Render(const TriMatrix &worldToClip)
|
|||
vertices[3].varying[1] = (float)texcoords.v2;
|
||||
vertices[3].varying[2] = GetLightLevel() / 255.0f;
|
||||
|
||||
TriangleDrawer::draw(worldToClip, vertices, 4, TriangleDrawMode::Fan, true, 0, viewwidth, cliptop, clipbottom, tex);
|
||||
PolyTriangleDrawer::draw(worldToClip, vertices, 4, TriangleDrawMode::Fan, true, 0, viewwidth, 0, viewheight, tex);
|
||||
}
|
||||
|
||||
FTexture *RenderPolyWall::GetTexture()
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include "doomdata.h"
|
||||
#include "r_utility.h"
|
||||
#include "r_main.h"
|
||||
#include "r_triangle.h"
|
||||
#include "r_poly_triangle.h"
|
||||
|
||||
// DScreen accelerated sprite to be rendered
|
||||
class PolyScreenSprite
|
||||
|
|
1054
src/r_poly_triangle.cpp
Normal file
1054
src/r_poly_triangle.cpp
Normal file
File diff suppressed because it is too large
Load diff
104
src/r_poly_triangle.h
Normal file
104
src/r_poly_triangle.h
Normal file
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
** Triangle drawers
|
||||
** 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.
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __R_POLY_TRIANGLE__
|
||||
#define __R_POLY_TRIANGLE__
|
||||
|
||||
#include "r_triangle.h"
|
||||
|
||||
struct ScreenPolyTriangleDrawerArgs;
|
||||
|
||||
class PolyTriangleDrawer
|
||||
{
|
||||
public:
|
||||
static void draw(const TriMatrix &objectToClip, const TriVertex *vinput, int vcount, TriangleDrawMode mode, bool ccw, int clipleft, int clipright, int cliptop, int clipbottom, FTexture *texture);
|
||||
static void fill(const TriMatrix &objectToClip, const TriVertex *vinput, int vcount, TriangleDrawMode mode, bool ccw, int clipleft, int clipright, int cliptop, int clipbottom, int solidcolor);
|
||||
|
||||
private:
|
||||
static TriVertex shade_vertex(const TriMatrix &objectToClip, TriVertex v);
|
||||
static void draw_arrays(const TriMatrix &objectToClip, const TriVertex *vinput, int vcount, TriangleDrawMode mode, bool ccw, int clipleft, int clipright, int cliptop, int clipbottom, const uint8_t *texturePixels, int textureWidth, int textureHeight, int solidcolor, DrawerThread *thread, void(*drawfunc)(const ScreenPolyTriangleDrawerArgs *, DrawerThread *));
|
||||
static void draw_shaded_triangle(const TriVertex *vertices, bool ccw, ScreenPolyTriangleDrawerArgs *args, DrawerThread *thread, void(*drawfunc)(const ScreenPolyTriangleDrawerArgs *, DrawerThread *));
|
||||
static bool cullhalfspace(float clipdistance1, float clipdistance2, float &t1, float &t2);
|
||||
static void clipedge(const TriVertex &v1, const TriVertex &v2, TriVertex *clippedvert, int &numclipvert);
|
||||
|
||||
static void queue_arrays(const TriMatrix &objectToClip, const TriVertex *vinput, int vcount, TriangleDrawMode mode, bool ccw, int clipleft, int clipright, int cliptop, int clipbottom, const uint8_t *texturePixels, int textureWidth, int textureHeight, int solidcolor);
|
||||
|
||||
friend class DrawPolyTrianglesCommand;
|
||||
};
|
||||
|
||||
struct ScreenPolyTriangleDrawerArgs
|
||||
{
|
||||
uint8_t *dest;
|
||||
int pitch;
|
||||
TriVertex *v1;
|
||||
TriVertex *v2;
|
||||
TriVertex *v3;
|
||||
int clipleft;
|
||||
int clipright;
|
||||
int cliptop;
|
||||
int clipbottom;
|
||||
const uint8_t *texturePixels;
|
||||
int textureWidth;
|
||||
int textureHeight;
|
||||
int solidcolor;
|
||||
};
|
||||
|
||||
class ScreenPolyTriangleDrawer
|
||||
{
|
||||
public:
|
||||
static void draw(const ScreenPolyTriangleDrawerArgs *args, DrawerThread *thread);
|
||||
static void fill(const ScreenPolyTriangleDrawerArgs *args, DrawerThread *thread);
|
||||
|
||||
static void draw32(const ScreenPolyTriangleDrawerArgs *args, DrawerThread *thread);
|
||||
static void fill32(const ScreenPolyTriangleDrawerArgs *args, DrawerThread *thread);
|
||||
|
||||
private:
|
||||
static float gradx(float x0, float y0, float x1, float y1, float x2, float y2, float c0, float c1, float c2);
|
||||
static float grady(float x0, float y0, float x1, float y1, float x2, float y2, float c0, float c1, float c2);
|
||||
};
|
||||
|
||||
class DrawPolyTrianglesCommand : public DrawerCommand
|
||||
{
|
||||
public:
|
||||
DrawPolyTrianglesCommand(const TriMatrix &objectToClip, const TriVertex *vinput, int vcount, TriangleDrawMode mode, bool ccw, int clipleft, int clipright, int cliptop, int clipbottom, const uint8_t *texturePixels, int textureWidth, int textureHeight, int solidcolor);
|
||||
|
||||
void Execute(DrawerThread *thread) override;
|
||||
FString DebugInfo() override;
|
||||
|
||||
private:
|
||||
TriMatrix objectToClip;
|
||||
const TriVertex *vinput;
|
||||
int vcount;
|
||||
TriangleDrawMode mode;
|
||||
bool ccw;
|
||||
int clipleft;
|
||||
int clipright;
|
||||
int cliptop;
|
||||
int clipbottom;
|
||||
const uint8_t *texturePixels;
|
||||
int textureWidth;
|
||||
int textureHeight;
|
||||
int solidcolor;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue