2017-01-12 15:21:46 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stddef.h>
|
2017-02-03 07:06:47 +00:00
|
|
|
#include <memory>
|
2017-03-20 07:28:16 +00:00
|
|
|
#include "v_video.h"
|
2017-01-12 15:21:46 +00:00
|
|
|
#include "r_defs.h"
|
2018-04-07 13:48:48 +00:00
|
|
|
#include "polyrenderer/math/gpu_types.h"
|
2017-01-12 15:21:46 +00:00
|
|
|
|
2018-12-17 04:10:26 +00:00
|
|
|
#define MINZ double((2048*4) / double(1 << 20))
|
|
|
|
|
2017-01-12 15:21:46 +00:00
|
|
|
namespace swrenderer
|
|
|
|
{
|
2017-03-12 19:40:00 +00:00
|
|
|
class RenderThread;
|
|
|
|
|
2017-01-15 03:06:52 +00:00
|
|
|
class RenderViewport
|
|
|
|
{
|
|
|
|
public:
|
2017-02-03 07:06:47 +00:00
|
|
|
RenderViewport();
|
|
|
|
~RenderViewport();
|
|
|
|
|
2017-03-12 19:40:00 +00:00
|
|
|
void SetViewport(RenderThread *thread, int width, int height, float trueratio);
|
2017-01-15 03:06:52 +00:00
|
|
|
void SetupFreelook();
|
2017-02-01 15:02:21 +00:00
|
|
|
|
2018-04-07 13:48:48 +00:00
|
|
|
void SetupPolyViewport(RenderThread *thread);
|
2017-11-27 22:47:26 +00:00
|
|
|
|
2018-04-07 13:48:48 +00:00
|
|
|
Mat4f WorldToView;
|
|
|
|
Mat4f ViewToClip;
|
|
|
|
Mat4f WorldToClip;
|
2017-11-27 22:47:26 +00:00
|
|
|
|
2017-02-01 15:02:21 +00:00
|
|
|
DCanvas *RenderTarget = nullptr;
|
2018-04-08 13:49:06 +00:00
|
|
|
bool RenderingToCanvas = false;
|
2017-02-01 22:23:10 +00:00
|
|
|
|
2017-03-12 17:54:39 +00:00
|
|
|
FViewWindow viewwindow;
|
|
|
|
FRenderViewpoint viewpoint;
|
|
|
|
|
2017-02-01 15:02:21 +00:00
|
|
|
double FocalLengthX = 0.0;
|
|
|
|
double FocalLengthY = 0.0;
|
|
|
|
double InvZtoScale = 0.0;
|
|
|
|
double WallTMapScale2 = 0.0;
|
|
|
|
double CenterX = 0.0;
|
|
|
|
double CenterY = 0.0;
|
|
|
|
double YaspectMul = 0.0;
|
|
|
|
double IYaspectMul = 0.0;
|
|
|
|
double globaluclip = 0.0;
|
|
|
|
double globaldclip = 0.0;
|
2017-02-11 21:10:52 +00:00
|
|
|
|
|
|
|
fixed_t viewingrangerecip = 0;
|
|
|
|
double BaseYaspectMul = 0.0; // yaspectmul without a forced aspect ratio
|
|
|
|
|
2017-02-01 15:02:21 +00:00
|
|
|
// The xtoviewangleangle[] table maps a screen pixel
|
|
|
|
// to the lowest viewangle that maps back to x ranges
|
|
|
|
// from clipangle to -clipangle.
|
|
|
|
angle_t xtoviewangle[MAXWIDTH + 1];
|
|
|
|
|
2017-02-01 21:24:34 +00:00
|
|
|
uint8_t *GetDest(int x, int y);
|
2017-01-15 03:06:52 +00:00
|
|
|
|
2017-02-01 22:23:10 +00:00
|
|
|
DVector3 PointWorldToView(const DVector3 &worldPos) const;
|
|
|
|
DVector3 PointWorldToScreen(const DVector3 &worldPos) const;
|
|
|
|
DVector3 PointViewToScreen(const DVector3 &viewPos) const;
|
|
|
|
|
|
|
|
DVector2 PointWorldToView(const DVector2 &worldPos) const;
|
|
|
|
DVector2 ScaleViewToScreen(const DVector2 &scale, double viewZ, bool pixelstretch = true) const;
|
2017-02-06 14:15:09 +00:00
|
|
|
|
|
|
|
double PlaneDepth(int screenY, double planeHeight) const
|
|
|
|
{
|
|
|
|
if (screenY + 0.5 < CenterY)
|
|
|
|
return FocalLengthY / (CenterY - screenY - 0.5) * planeHeight;
|
|
|
|
else
|
|
|
|
return FocalLengthY / (screenY + 0.5 - CenterY) * planeHeight;
|
|
|
|
}
|
2018-04-08 00:22:01 +00:00
|
|
|
|
|
|
|
double ScreenToViewX(int screenX, double viewZ) const
|
|
|
|
{
|
|
|
|
return (screenX + 0.5 - CenterX) / FocalLengthX * viewZ;
|
|
|
|
}
|
|
|
|
|
|
|
|
double ScreenToViewY(int screenY, double viewZ) const
|
|
|
|
{
|
|
|
|
return (CenterY - screenY - 0.5) / FocalLengthY * viewZ;
|
|
|
|
}
|
|
|
|
|
2017-01-15 03:06:52 +00:00
|
|
|
private:
|
|
|
|
void InitTextureMapping();
|
|
|
|
void SetupBuffer();
|
2018-04-07 13:48:48 +00:00
|
|
|
|
|
|
|
static Mat4f SoftwareWorldToView(const FRenderViewpoint &viewpoint);
|
2018-04-08 01:57:05 +00:00
|
|
|
|
|
|
|
Mat4f SoftwareViewToClip();
|
2017-01-15 03:06:52 +00:00
|
|
|
};
|
2017-01-12 15:21:46 +00:00
|
|
|
}
|