Browse Source

ref_soft: Fix render setup

pull/2/head
mittorn 6 years ago
parent
commit
4c73f026b2
  1. 10
      r_edge.c
  2. 26
      r_local.h
  3. 7
      r_main.c
  4. 107
      r_misc.c
  5. 57
      r_rast.c
  6. 8
      r_scan.c

10
r_edge.c

@ -134,7 +134,7 @@ void R_BeginEdgeFrame (void) @@ -134,7 +134,7 @@ void R_BeginEdgeFrame (void)
}
// FIXME: set with memset
for (v=0 ; v<gpGlobals->height ; v++)
for (v=RI.vrect.y ; v<RI.vrectbottom ; v++)
{
newedges[v] = removeedges[v] = NULL;
}
@ -653,13 +653,13 @@ void R_ScanEdges (void) @@ -653,13 +653,13 @@ void R_ScanEdges (void)
basespan_p = (espan_t *)
((long)(basespans + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
max_span_p = &basespan_p[MAXSPANS - gpGlobals->width];
max_span_p = &basespan_p[MAXSPANS - RI.vrect.width];
span_p = basespan_p;
// clear active edges to just the background edges around the whole screen
// FIXME: most of this only needs to be set up once
edge_head.u = 1 << 20; //r_refdef.vrect.x << 20;
edge_head.u = RI.vrect.x << 20;
edge_head_u_shift20 = edge_head.u >> 20;
edge_head.u_step = 0;
edge_head.prev = NULL;
@ -667,7 +667,7 @@ void R_ScanEdges (void) @@ -667,7 +667,7 @@ void R_ScanEdges (void)
edge_head.surfs[0] = 0;
edge_head.surfs[1] = 1;
edge_tail.u =(gpGlobals->width << 20) + 0xFFFFF; // (r_refdef.vrectright << 20) + 0xFFFFF;
edge_tail.u =(RI.vrectright << 20) + 0xFFFFF; // (r_refdef.vrectright << 20) + 0xFFFFF;
edge_tail_u_shift20 = edge_tail.u >> 20;
edge_tail.u_step = 0;
edge_tail.prev = &edge_head;
@ -687,7 +687,7 @@ void R_ScanEdges (void) @@ -687,7 +687,7 @@ void R_ScanEdges (void)
//
// process all scan lines
//
bottom = gpGlobals->height; //r_refdef.vrectbottom - 1;
bottom = RI.vrectbottom - 1;
for (iv=0 ; iv<bottom ; iv++)
{

26
r_local.h

@ -214,6 +214,30 @@ typedef struct @@ -214,6 +214,30 @@ typedef struct
float viewplanedist;
mplane_t clipPlane;
// q2 oldrefdef
vrect_t vrect; // subwindow in video for refresh
// FIXME: not need vrect next field here?
vrect_t aliasvrect; // scaled Alias version
int vrectright, vrectbottom; // right & bottom screen coords
int aliasvrectright, aliasvrectbottom; // scaled Alias versions
float vrectrightedge; // rightmost right edge we care about,
// for use in edge list
float fvrectx, fvrecty; // for floating-point compares
float fvrectx_adj, fvrecty_adj; // left and top edges, for clamping
int vrect_x_adj_shift20; // (vrect.x + 0.5 - epsilon) << 20
int vrectright_adj_shift20; // (vrectright + 0.5 - epsilon) << 20
float fvrectright_adj, fvrectbottom_adj;
// right and bottom edges, for clamping
float fvrectright; // rightmost edge, for Alias clamping
float fvrectbottom; // bottommost edge, for Alias clamping
float horizontalFieldOfView; // at Z = 1.0, this many X is visible
// 2.0 = 90 degrees
float xOrigin; // should probably always be 0.5
float yOrigin; // between be around 0.3 to 0.5
int ambientlight;
} ref_instance_t;
typedef struct
@ -748,7 +772,7 @@ extern cvar_t *r_showhull; @@ -748,7 +772,7 @@ extern cvar_t *r_showhull;
// polygon (while processing)
// !!! if this is changed, it must be changed in d_ifacea.h too !!!
#define MAXHEIGHT 1200
#define MAXWIDTH 1600
#define MAXWIDTH 1920
#define INFINITE_DISTANCE 0x10000 // distance that's always guaranteed to
// be farther away than anything in

7
r_main.c

@ -1687,6 +1687,13 @@ qboolean R_Init() @@ -1687,6 +1687,13 @@ qboolean R_Init()
// init draw stack
tr.draw_list = &tr.draw_stack[0];
tr.draw_stack_pos = 0;
RI.yOrigin = YCENTERING;
RI.xOrigin = XCENTERING;
view_clipplanes[0].leftedge = true;
view_clipplanes[1].rightedge = true;
view_clipplanes[1].leftedge = view_clipplanes[2].leftedge =view_clipplanes[3].leftedge = false;
view_clipplanes[0].rightedge = view_clipplanes[2].rightedge = view_clipplanes[3].rightedge = false;
return true;
}

107
r_misc.c

@ -95,8 +95,8 @@ void D_ViewChanged (void) @@ -95,8 +95,8 @@ void D_ViewChanged (void)
if (d_pix_max < 1)
d_pix_max = 1;
d_vrectx = 0;//r_refdef.vrect.x;
d_vrecty = 0;//r_refdef.vrect.y;
d_vrectx = RI.vrect.x;
d_vrecty = RI.vrect.y;
d_vrectright_particle = gpGlobals->width - d_pix_max;
d_vrectbottom_particle =
gpGlobals->height - d_pix_max;
@ -223,98 +223,89 @@ Guaranteed to be called before the first refresh @@ -223,98 +223,89 @@ Guaranteed to be called before the first refresh
void R_ViewChanged (vrect_t *vr)
{
int i;
#if 0
r_refdef.vrect = *vr;
r_refdef.horizontalFieldOfView = 2*tan((float)r_newrefdef.fov_x/360*M_PI);;
verticalFieldOfView = 2*tan((float)r_newrefdef.fov_y/360*M_PI);
r_refdef.fvrectx = (float)r_refdef.vrect.x;
r_refdef.fvrectx_adj = (float)r_refdef.vrect.x - 0.5;
r_refdef.vrect_x_adj_shift20 = (r_refdef.vrect.x<<20) + (1<<19) - 1;
r_refdef.fvrecty = (float)r_refdef.vrect.y;
r_refdef.fvrecty_adj = (float)r_refdef.vrect.y - 0.5;
r_refdef.vrectright = r_refdef.vrect.x + r_refdef.vrect.width;
r_refdef.vrectright_adj_shift20 = (r_refdef.vrectright<<20) + (1<<19) - 1;
r_refdef.fvrectright = (float)r_refdef.vrectright;
r_refdef.fvrectright_adj = (float)r_refdef.vrectright - 0.5;
r_refdef.vrectrightedge = (float)r_refdef.vrectright - 0.99;
r_refdef.vrectbottom = r_refdef.vrect.y + r_refdef.vrect.height;
r_refdef.fvrectbottom = (float)r_refdef.vrectbottom;
r_refdef.fvrectbottom_adj = (float)r_refdef.vrectbottom - 0.5;
r_refdef.aliasvrect.x = (int)(r_refdef.vrect.x * r_aliasuvscale);
r_refdef.aliasvrect.y = (int)(r_refdef.vrect.y * r_aliasuvscale);
r_refdef.aliasvrect.width = (int)(r_refdef.vrect.width * r_aliasuvscale);
r_refdef.aliasvrect.height = (int)(r_refdef.vrect.height * r_aliasuvscale);
r_refdef.aliasvrectright = r_refdef.aliasvrect.x +
r_refdef.aliasvrect.width;
r_refdef.aliasvrectbottom = r_refdef.aliasvrect.y +
r_refdef.aliasvrect.height;
xOrigin = r_refdef.xOrigin;
yOrigin = r_refdef.yOrigin;
#endif
int fov_x = 2.0 * tan (RI.fov_x/360*M_PI);
int fov_y = 2.0 * tan (RI.fov_y/360*M_PI);
float verticalFieldOfView, xOrigin, yOrigin;
RI.vrect = *vr;
RI.horizontalFieldOfView = 2*tan((float)RI.fov_x/360*M_PI);
verticalFieldOfView = 2*tan((float)RI.fov_y/360*M_PI);
RI.fvrectx = (float)RI.vrect.x;
RI.fvrectx_adj = (float)RI.vrect.x - 0.5;
RI.vrect_x_adj_shift20 = (RI.vrect.x<<20) + (1<<19) - 1;
RI.fvrecty = (float)RI.vrect.y;
RI.fvrecty_adj = (float)RI.vrect.y - 0.5;
RI.vrectright = RI.vrect.x + RI.vrect.width;
RI.vrectright_adj_shift20 = (RI.vrectright<<20) + (1<<19) - 1;
RI.fvrectright = (float)RI.vrectright;
RI.fvrectright_adj = (float)RI.vrectright - 0.5;
RI.vrectrightedge = (float)RI.vrectright - 0.99;
RI.vrectbottom = RI.vrect.y + RI.vrect.height;
RI.fvrectbottom = (float)RI.vrectbottom;
RI.fvrectbottom_adj = (float)RI.vrectbottom - 0.5;
//RI.aliasvrect.x = (int)(RI.vrect.x * r_aliasuvscale);
//RI.aliasvrect.y = (int)(RI.vrect.y * r_aliasuvscale);
//RI.aliasvrect.width = (int)(RI.vrect.width * r_aliasuvscale);
//RI.aliasvrect.height = (int)(RI.vrect.height * r_aliasuvscale);
RI.aliasvrectright = RI.aliasvrect.x +
RI.aliasvrect.width;
RI.aliasvrectbottom = RI.aliasvrect.y +
RI.aliasvrect.height;
xOrigin = RI.xOrigin;// = r_origin[0];
yOrigin = RI.yOrigin;// = r_origin[1];
#define PLANE_ANYZ 5
// values for perspective projection
// if math were exact, the values would range from 0.5 to to range+0.5
// hopefully they wll be in the 0.000001 to range+.999999 and truncate
// the polygon rasterization will never render in the first row or column
// but will definately render in the [range] row and column, so adjust the
// buffer origin to get an exact edge to edge fill
xcenter = ((float)gpGlobals->width * XCENTERING) +
0 - 0.5;
xcenter = ((float)RI.vrect.width * XCENTERING) +
RI.vrect.x - 0.5;
//aliasxcenter = xcenter * r_aliasuvscale;
ycenter = ((float)gpGlobals->height * YCENTERING) +
0 - 0.5;
//aliasycenter = ycenter * r_aliasuvscale;
ycenter = ((float)RI.vrect.height * YCENTERING) +
RI.vrect.y - 0.5;
// aliasycenter = ycenter * r_aliasuvscale;
xscale = gpGlobals->width * 1.5 / fov_x;
//aliasxscale = xscale * r_aliasuvscale;
xscale = RI.vrect.width / RI.horizontalFieldOfView;
// aliasxscale = xscale * r_aliasuvscale;
xscaleinv = 1.0 / xscale;
yscale = xscale;
//aliasyscale = yscale * r_aliasuvscale;
// aliasyscale = yscale * r_aliasuvscale;
yscaleinv = 1.0 / yscale;
xscaleshrink = (gpGlobals->width-6)/fov_x;
xscaleshrink = (RI.vrect.width-6)/RI.horizontalFieldOfView;
yscaleshrink = xscaleshrink;
// ???
#define PLANE_ANYZ 5
int xOrigin = r_origin[0];
int yOrigin = r_origin[1];
// left side clip
screenedge[0].normal[0] = -1.0 / (xOrigin*fov_x);
screenedge[0].normal[0] = -1.0 / (xOrigin*RI.horizontalFieldOfView);
screenedge[0].normal[1] = 0;
screenedge[0].normal[2] = 1;
screenedge[0].type = PLANE_ANYZ;
// right side clip
screenedge[1].normal[0] =
1.0 / ((1.0-xOrigin)*fov_x);
1.0 / ((1.0-xOrigin)*RI.horizontalFieldOfView);
screenedge[1].normal[1] = 0;
screenedge[1].normal[2] = 1;
screenedge[1].type = PLANE_ANYZ;
// top side clip
screenedge[2].normal[0] = 0;
screenedge[2].normal[1] = -1.0 / (yOrigin*fov_y);
screenedge[2].normal[1] = -1.0 / (yOrigin*verticalFieldOfView);
screenedge[2].normal[2] = 1;
screenedge[2].type = PLANE_ANYZ;
// bottom side clip
screenedge[3].normal[0] = 0;
screenedge[3].normal[1] = 1.0 / ((1.0-yOrigin)*fov_y);
screenedge[3].normal[1] = 1.0 / ((1.0-yOrigin)*verticalFieldOfView);
screenedge[3].normal[2] = 1;
screenedge[3].type = PLANE_ANYZ;
for (i=0 ; i<4 ; i++)
VectorNormalize (screenedge[i].normal);
VectorNormalize (screenedge[i].normal);
D_ViewChanged ();
}

57
r_rast.c

@ -226,8 +226,6 @@ void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1) @@ -226,8 +226,6 @@ void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1)
int v, v2, ceilv0;
float scale, lzi0, u0, v0;
int side;
if( isnan( pv0->position[1]) )
return;
if (r_lastvertvalid)
{
@ -252,26 +250,19 @@ void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1) @@ -252,26 +250,19 @@ void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1)
// FIXME: build x/yscale into transform?
scale = xscale * lzi0;
u0 = (xcenter + scale*transformed[0]);
if (u0 < 0)
u0 = 0;
if (u0 > gpGlobals->width)
u0 = gpGlobals->width;
if (u0 < RI.fvrectx_adj)
u0 = RI.fvrectx_adj;
if (u0 > RI.fvrectright_adj)
u0 = RI.fvrectright_adj;
scale = yscale * lzi0;
v0 = (ycenter - scale*transformed[1]);
if (v0 < 0)
v0 = 0;
if (v0 > gpGlobals->height)
v0 = gpGlobals->height;
if (v0 < RI.fvrecty_adj)
v0 = RI.fvrecty_adj;
if (v0 > RI.fvrectbottom_adj)
v0 = RI.fvrectbottom_adj;
ceilv0 = (int) ceil(v0);
if( ceilv0 < 0 )
{
printf("ceilv0 %d %f %f %f %f\n", ceilv0, v0, scale, transformed[1], ycenter );
printf("%f %f %f %f\n", world[1],modelorg[1], local[1], transformed[1] );
}
}
world = &pv1->position[0];
@ -287,17 +278,17 @@ void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1) @@ -287,17 +278,17 @@ void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1)
scale = xscale * r_lzi1;
r_u1 = (xcenter + scale*transformed[0]);
if (r_u1 < 0)
r_u1 = 0;
if (r_u1 > gpGlobals->width)
r_u1 = gpGlobals->width;
if (r_u1 < RI.fvrectx_adj)
r_u1 = RI.fvrectx_adj;
if (r_u1 > RI.fvrectright_adj)
r_u1 = RI.fvrectright_adj;
scale = yscale * r_lzi1;
r_v1 = (ycenter - scale*transformed[1]);
if (r_v1 < 0)
r_v1 = 0;
if (r_v1 > gpGlobals->height)
r_v1 = gpGlobals->height;
if (r_v1 < RI.fvrecty_adj)
r_v1 = RI.fvrecty_adj;
if (r_v1 > RI.fvrectbottom_adj)
r_v1 = RI.fvrectbottom_adj;
if (r_lzi1 > lzi0)
lzi0 = r_lzi1;
@ -339,7 +330,6 @@ void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1) @@ -339,7 +330,6 @@ void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1)
{
// trailing edge (go from p1 to p2)
v = ceilv0;
if( v < 0 )printf("v0 %d\n", v);
v2 = r_ceilv1 - 1;
edge->surfs[0] = surface_p - surfaces;
@ -353,7 +343,6 @@ void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1) @@ -353,7 +343,6 @@ void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1)
// leading edge (go from p2 to p1)
v2 = ceilv0 - 1;
v = r_ceilv1;
if( v < 0 )printf("v1 %d\n", v);
edge->surfs[0] = 0;
edge->surfs[1] = surface_p - surfaces;
@ -370,12 +359,17 @@ void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1) @@ -370,12 +359,17 @@ void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1)
// it to incorrectly extend to the scan, and the extension of the line goes off
// the edge of the screen
// FIXME: is this actually needed?
int r = (gpGlobals->width<<20) + (1<<19) - 1;
/*int r = (gpGlobals->width<<20) + (1<<19) - 1;
int x = (1<<20) + (1<<19) - 1;
if (edge->u < x)
edge->u = x;
if (edge->u > r)
edge->u = r;
edge->u = r;*/
if (edge->u < RI.vrect_x_adj_shift20)
edge->u = RI.vrect_x_adj_shift20;
if (edge->u > RI.vrectright_adj_shift20)
edge->u = RI.vrectright_adj_shift20;
//
// sort the edge in normally
@ -384,11 +378,6 @@ void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1) @@ -384,11 +378,6 @@ void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1)
if (edge->surfs[0])
u_check++; // sort trailers after leaders
if( v < 0 )
{
printf("v %d\n", v);
v = 0;
}
if (!newedges[v] || newedges[v]->u >= u_check)
{
edge->next = newedges[v];

8
r_scan.c

@ -395,13 +395,13 @@ void NonTurbulent8 (espan_t *pspan) @@ -395,13 +395,13 @@ void NonTurbulent8 (espan_t *pspan)
int kernel[2][2][2] =
{
{
{16384,0},
{49152,32768}
{16384,0},
{49152,32768}
}
,
{
{32768,49152},
{0,16384}
{32768,49152},
{0,16384}
}
};

Loading…
Cancel
Save