Pass std::span to draw_tmap, draw_tmap_flat
This commit is contained in:
parent
a48e6ab56b
commit
fd1be66fa4
|
@ -250,7 +250,7 @@ void _g3_draw_tmap(grs_canvas &canvas, const std::span<cg3s_point *const> pointl
|
|||
return;
|
||||
}
|
||||
}
|
||||
(*tmap_drawer_ptr)(canvas, bm, pointlist.size(), bufptr.data());
|
||||
(*tmap_drawer_ptr)(canvas, bm, std::span(bufptr).first(pointlist.size()));
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
@ -273,7 +273,7 @@ static void must_clip_tmap_face(grs_canvas &canvas, int nv, g3s_codes cc, grs_bi
|
|||
}
|
||||
}
|
||||
|
||||
(*tmap_drawer_ptr)(canvas, bm, nv, &bufptr[0]);
|
||||
(*tmap_drawer_ptr)(canvas, bm, std::span(bufptr).first(nv));
|
||||
}
|
||||
|
||||
free_points:
|
||||
|
|
|
@ -344,7 +344,7 @@ public:
|
|||
void g3_draw_line(const g3_draw_line_context &, cg3s_point &p0, cg3s_point &p1, temporary_points_t &);
|
||||
constexpr std::integral_constant<std::size_t, 100> MAX_POINTS_IN_POLY{};
|
||||
|
||||
using tmap_drawer_type = void (*)(grs_canvas &, const grs_bitmap &bm, uint_fast32_t nv, const g3s_point *const *vertlist);
|
||||
using tmap_drawer_type = void (*)(grs_canvas &, const grs_bitmap &bm, std::span<const g3s_point *const> vertlist);
|
||||
|
||||
// This is the gr_upoly-like interface to the texture mapper which uses texture-mapper compatible
|
||||
// (ie, avoids cracking) edge/delta computation.
|
||||
|
|
|
@ -50,11 +50,11 @@ constexpr std::integral_constant<unsigned, 25> MAX_TMAP_VERTS{};
|
|||
// tmap_num references a texture map defined in Texmap_ptrs.
|
||||
// nverts = number of vertices
|
||||
// vertbuf is a pointer to an array of vertex pointers
|
||||
void draw_tmap(grs_canvas &, const grs_bitmap &bp, uint_fast32_t nverts, const g3s_point *const *vertbuf);
|
||||
void draw_tmap(grs_canvas &, const grs_bitmap &bp, std::span<const g3s_point *const> vertbuf);
|
||||
|
||||
//function that takes the same parms as draw_tmap, but renders as flat poly
|
||||
//we need this to do the cloaked effect
|
||||
void draw_tmap_flat(grs_canvas &, const grs_bitmap &bp, uint_fast32_t nverts, const g3s_point *const *vertbuf);
|
||||
void draw_tmap_flat(grs_canvas &, const grs_bitmap &bp, std::span<const g3s_point *const> vertbuf);
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -35,7 +35,7 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
#include "rle.h"
|
||||
#include "scanline.h"
|
||||
#include "u_mem.h"
|
||||
|
||||
#include "d_zip.h"
|
||||
#include "dxxsconf.h"
|
||||
#include "dsx-ns.h"
|
||||
#include <utility>
|
||||
|
@ -789,18 +789,18 @@ static void ntexture_map_lighted_linear(const grs_bitmap &srcb, const g3ds_tmap
|
|||
// -------------------------------------------------------------------------------------
|
||||
// Interface from Matt's data structures to Mike's texture mapper.
|
||||
// -------------------------------------------------------------------------------------
|
||||
void draw_tmap(grs_canvas &canvas, const grs_bitmap &rbp, uint_fast32_t nverts, const g3s_point *const *vertbuf)
|
||||
void draw_tmap(grs_canvas &canvas, const grs_bitmap &rbp, const std::span<const g3s_point *const> vertbuf)
|
||||
{
|
||||
// These variables are used in system which renders texture maps which lie on one scanline as a line.
|
||||
// fix div_numerator;
|
||||
int lighting_on_save = Lighting_on;
|
||||
|
||||
Assert(nverts <= MAX_TMAP_VERTS);
|
||||
assert(vertbuf.size() <= MAX_TMAP_VERTS);
|
||||
|
||||
const grs_bitmap *bp = &rbp;
|
||||
// If no transparency and seg depth is large, render as flat shaded.
|
||||
if ((Current_seg_depth > Max_linear_depth) && ((bp->get_flag_mask(3)) == 0)) {
|
||||
draw_tmap_flat(canvas, rbp, nverts, vertbuf);
|
||||
draw_tmap_flat(canvas, rbp, vertbuf);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -813,27 +813,25 @@ void draw_tmap(grs_canvas &canvas, const grs_bitmap &rbp, uint_fast32_t nverts,
|
|||
|
||||
// Setup texture map in Tmap1
|
||||
g3ds_tmap Tmap1;
|
||||
Tmap1.nv = nverts; // Initialize number of vertices
|
||||
Tmap1.nv = vertbuf.size(); // Initialize number of vertices
|
||||
|
||||
// div_numerator = DivNum; //f1_0*3;
|
||||
|
||||
for (int i=0; i<nverts; i++) {
|
||||
g3ds_vertex *tvp = &Tmap1.verts[i];
|
||||
auto vp = vertbuf[i];
|
||||
|
||||
tvp->x2d = vp->p3_sx;
|
||||
tvp->y2d = vp->p3_sy;
|
||||
for (auto &&[vp, tvp] : zip(vertbuf, Tmap1.verts))
|
||||
{
|
||||
tvp.x2d = vp->p3_sx;
|
||||
tvp.y2d = vp->p3_sy;
|
||||
|
||||
// Check for overflow on fixdiv. Will overflow on vp->z <= something small. Allow only as low as 256.
|
||||
auto clipped_p3_z = std::max(256, vp->p3_z);
|
||||
tvp->z = fixdiv(F1_0*12, clipped_p3_z);
|
||||
tvp->u = vp->p3_u << 6; //* bp->bm_w;
|
||||
tvp->v = vp->p3_v << 6; //* bp->bm_h;
|
||||
tvp.z = fixdiv(F1_0*12, clipped_p3_z);
|
||||
tvp.u = vp->p3_u << 6; //* bp->bm_w;
|
||||
tvp.v = vp->p3_v << 6; //* bp->bm_h;
|
||||
|
||||
Assert(Lighting_on < 3);
|
||||
|
||||
if (Lighting_on)
|
||||
tvp->l = vp->p3_l * NUM_LIGHTING_LEVELS;
|
||||
tvp.l = vp->p3_l * NUM_LIGHTING_LEVELS;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -34,17 +34,15 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
#include "compiler-range_for.h"
|
||||
#include "partial_range.h"
|
||||
|
||||
//#include "tmapext.h"
|
||||
|
||||
#if !DXX_USE_OGL
|
||||
#include "3d.h"
|
||||
#include "dxxerror.h"
|
||||
|
||||
#include "3d.h"
|
||||
#include "dxxerror.h"
|
||||
#include "d_zip.h"
|
||||
|
||||
namespace dcx {
|
||||
|
||||
namespace {
|
||||
|
||||
static void gr_upoly_tmap_ylr(grs_canvas &, uint_fast32_t nverts, const int *vert, uint8_t color);
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
|
@ -69,7 +67,6 @@ static void tmap_scanline_flat(grs_canvas &canvas, int y, fix xleft, fix xright)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//--unused-- void tmap_scanline_shaded(int y, fix xleft, fix xright)
|
||||
//--unused-- {
|
||||
//--unused-- fix dx;
|
||||
|
@ -85,7 +82,6 @@ static void tmap_scanline_flat(grs_canvas &canvas, int y, fix xleft, fix xright)
|
|||
//--unused-- asm_tmap_scanline_shaded();
|
||||
//--unused-- }
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
// Render a texture map.
|
||||
// Linear in outer loop, linear in inner loop.
|
||||
|
@ -172,6 +168,8 @@ static void texture_map_flat(grs_canvas &canvas, const g3ds_tmap &t, int color)
|
|||
tmap_scanline_flat(canvas, boty, xleft, xright);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------
|
||||
// This is the gr_upoly-like interface to the texture mapper which uses texture-mapper compatible
|
||||
// (ie, avoids cracking) edge/delta computation.
|
||||
|
@ -180,12 +178,16 @@ void gr_upoly_tmap(grs_canvas &canvas, uint_fast32_t nverts, const std::array<fi
|
|||
gr_upoly_tmap_ylr(canvas, nverts, vert.data(), color);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
struct pnt2d {
|
||||
fix x,y;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
//this takes the same partms as draw_tmap, but draws a flat-shaded polygon
|
||||
void draw_tmap_flat(grs_canvas &canvas, const grs_bitmap &bp, uint_fast32_t nverts, const g3s_point *const *vertbuf)
|
||||
void draw_tmap_flat(grs_canvas &canvas, const grs_bitmap &bp, const std::span<const g3s_point *const> vertbuf)
|
||||
{
|
||||
union {
|
||||
std::array<pnt2d, MAX_TMAP_VERTS> points;
|
||||
|
@ -193,15 +195,15 @@ void draw_tmap_flat(grs_canvas &canvas, const grs_bitmap &bp, uint_fast32_t nver
|
|||
};
|
||||
static_assert(sizeof(points) == sizeof(ipoints), "array size mismatch");
|
||||
fix average_light;
|
||||
Assert(nverts < MAX_TMAP_VERTS);
|
||||
average_light = vertbuf[0]->p3_l;
|
||||
for (int i=1; i<nverts; i++)
|
||||
average_light += vertbuf[i]->p3_l;
|
||||
assert(vertbuf.size() < MAX_TMAP_VERTS);
|
||||
average_light = 0;
|
||||
for (const auto vb : vertbuf)
|
||||
average_light += vb->p3_l;
|
||||
|
||||
if (nverts == 4)
|
||||
if (vertbuf.size() == 4)
|
||||
average_light = f2i(average_light * NUM_LIGHTING_LEVELS/4);
|
||||
else
|
||||
average_light = f2i(average_light * NUM_LIGHTING_LEVELS/nverts);
|
||||
average_light = f2i(average_light * NUM_LIGHTING_LEVELS / vertbuf.size());
|
||||
|
||||
if (average_light < 0)
|
||||
average_light = 0;
|
||||
|
@ -210,13 +212,16 @@ void draw_tmap_flat(grs_canvas &canvas, const grs_bitmap &bp, uint_fast32_t nver
|
|||
|
||||
const auto color = gr_fade_table[static_cast<gr_fade_level>(average_light)][bp.avg_color];
|
||||
|
||||
for (int i=0;i<nverts;i++) {
|
||||
points[i].x = vertbuf[i]->p3_sx;
|
||||
points[i].y = vertbuf[i]->p3_sy;
|
||||
for (auto &&[vb, pt] : zip(vertbuf, points))
|
||||
{
|
||||
pt.x = vb->p3_sx;
|
||||
pt.y = vb->p3_sy;
|
||||
}
|
||||
gr_upoly_tmap_ylr(canvas, nverts, ipoints.data(), color);
|
||||
gr_upoly_tmap_ylr(canvas, vertbuf.size(), ipoints.data(), color);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// -----------------------------------------------------------------------------------------
|
||||
//This is like gr_upoly_tmap() but instead of drawing, it calls the specified
|
||||
//function with ylr values
|
||||
|
@ -233,5 +238,7 @@ static void gr_upoly_tmap_ylr(grs_canvas &canvas, uint_fast32_t nverts, const in
|
|||
texture_map_flat(canvas, my_tmap, color);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
#endif //!OGL
|
||||
|
|
Loading…
Reference in a new issue