#pragma once
#include <vector>
#include "Common/CommonTypes.h"
#include "Common/Math/lin/matrix4x4.h"
#include "GPU/Common/VertexDecoderCommon.h"
#include "GPU/Common/TransformCommon.h"
class FramebufferManagerCommon;
class TextureCacheCommon;
enum SoftwareTransformAction {
SW_NOT_READY,
SW_DRAW_INDEXED,
SW_CLEAR,
};
struct SoftwareTransformResult {
SoftwareTransformAction action;
u32 color;
float depth;
bool setStencil;
u8 stencilValue;
bool setSafeSize;
u32 safeWidth;
u32 safeHeight;
TransformedVertex *drawBuffer;
int drawNumTrans;
bool pixelMapped;
};
struct SoftwareTransformParams {
u8 *decoded;
TransformedVertex *transformed;
TransformedVertex *transformedExpanded;
FramebufferManagerCommon *fbman;
TextureCacheCommon *texCache;
bool allowClear;
bool allowSeparateAlphaClear;
bool flippedY;
bool usesHalfZ;
};
void IndexBufferProvokingLastToFirst(int prim, u16 *inds, int indsSize);
class SoftwareTransform {
public:
SoftwareTransform(SoftwareTransformParams ¶ms) : params_(params) {}
void SetProjMatrix(const float mtx[14], bool invertedX, bool invertedY, const Lin::Vec3 &trans, const Lin::Vec3 &scale);
void Transform(int prim, u32 vertexType, const DecVtxFormat &decVtxFormat, int numDecodedVerts, SoftwareTransformResult *result);
void BuildDrawingParams(int prim, int vertexCount, u32 vertType, u16 *&inds, int indsSize, int &numDecodedVerts, int vertsSize, SoftwareTransformResult *result);
protected:
void CalcCullParams(float &minZValue, float &maxZValue) const;
bool ExpandRectangles(int vertexCount, int &numDecodedVerts, int vertsSize, u16 *&inds, int indsSize, const TransformedVertex *transformed, TransformedVertex *transformedExpanded, int &numTrans, bool throughmode, bool *pixelMappedExactly) const;
static bool ExpandLines(int vertexCount, int &numDecodedVerts, int vertsSize, u16 *&inds, int indsSize, const TransformedVertex *transformed, TransformedVertex *transformedExpanded, int &numTrans, bool throughmode) ;
static bool ExpandPoints(int vertexCount, int &numDecodedVerts, int vertsSize, u16 *&inds, int indsSize, const TransformedVertex *transformed, TransformedVertex *transformedExpanded, int &numTrans, bool throughmode) ;
const SoftwareTransformParams ¶ms_;
Lin::Matrix4x4 projMatrix_;
};
u32 NormalizeVertices(SimpleVertex *sverts, u8 *bufPtr, const u8 *inPtr, int lowerBound, int upperBound, const VertexDecoder *dec, u32 vertType);
bool GetCurrentDrawAsDebugVertices(DrawEngineCommon *drawEngine, int count, std::vector<GPUDebugVertex> &vertices, std::vector<u16> &indices);