2016-11-11 23:50:21 +00:00
|
|
|
/*
|
|
|
|
** DrawTriangle code generation
|
|
|
|
** 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.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "drawercodegen.h"
|
|
|
|
|
|
|
|
struct SSATriVertex
|
|
|
|
{
|
|
|
|
SSAFloat x, y, z, w;
|
|
|
|
SSAFloat varying[TriVertex::NumVarying];
|
|
|
|
};
|
|
|
|
|
2016-12-15 00:33:26 +00:00
|
|
|
struct SSAStepVariables
|
|
|
|
{
|
|
|
|
SSAFloat W;
|
|
|
|
SSAFloat Varying[TriVertex::NumVarying];
|
|
|
|
};
|
|
|
|
|
|
|
|
class DrawTriangleCodegen : public DrawerCodegen
|
|
|
|
{
|
|
|
|
public:
|
2016-12-15 22:29:31 +00:00
|
|
|
void Generate(TriBlendMode blendmode, bool truecolor, bool colorfill, SSAValue args, SSAValue thread_data);
|
2016-12-15 00:33:26 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void LoadArgs(SSAValue args, SSAValue thread_data);
|
|
|
|
SSATriVertex LoadTriVertex(SSAValue v);
|
|
|
|
void LoadUniforms(SSAValue uniforms);
|
|
|
|
void CalculateGradients();
|
|
|
|
SSAFloat FindGradientX(SSAFloat x0, SSAFloat y0, SSAFloat x1, SSAFloat y1, SSAFloat x2, SSAFloat y2, SSAFloat c0, SSAFloat c1, SSAFloat c2);
|
|
|
|
SSAFloat FindGradientY(SSAFloat x0, SSAFloat y0, SSAFloat x1, SSAFloat y1, SSAFloat x2, SSAFloat y2, SSAFloat c0, SSAFloat c1, SSAFloat c2);
|
|
|
|
void DrawFullSpans();
|
|
|
|
void DrawPartialBlocks();
|
|
|
|
|
|
|
|
SSAVec4i ProcessPixel32(SSAVec4i bg, SSAInt *varying);
|
|
|
|
SSAInt ProcessPixel8(SSAInt bg, SSAInt *varying);
|
|
|
|
SSAVec4i TranslateSample32(SSAInt *varying);
|
|
|
|
SSAInt TranslateSample8(SSAInt *varying);
|
|
|
|
SSAVec4i Sample32(SSAInt *varying);
|
|
|
|
SSAInt Sample8(SSAInt *varying);
|
|
|
|
SSAInt Shade8(SSAInt c);
|
|
|
|
SSAVec4i ToBgra(SSAInt index);
|
|
|
|
SSAInt ToPal8(SSAVec4i c);
|
|
|
|
SSAVec4i FadeOut(SSAInt frac, SSAVec4i color);
|
|
|
|
|
|
|
|
SSAStack<SSAInt> stack_i, stack_y, stack_x;
|
|
|
|
SSAStack<SSAFloat> stack_posYW, stack_posXW;
|
|
|
|
SSAStack<SSAFloat> stack_posYVarying[TriVertex::NumVarying];
|
|
|
|
SSAStack<SSAFloat> stack_posXVarying[TriVertex::NumVarying];
|
|
|
|
SSAStack<SSAInt> stack_varyingPos[TriVertex::NumVarying];
|
|
|
|
SSAStack<SSAInt> stack_lightpos;
|
|
|
|
SSAStack<SSAUBytePtr> stack_dest;
|
|
|
|
|
|
|
|
SSAStepVariables gradientX, gradientY, start;
|
|
|
|
SSAFloat shade, globVis;
|
|
|
|
|
|
|
|
SSAInt currentlight;
|
|
|
|
SSAUBytePtr currentcolormap;
|
|
|
|
|
|
|
|
SSAUBytePtr destOrg;
|
|
|
|
SSAInt pitch;
|
|
|
|
SSATriVertex v1;
|
|
|
|
SSATriVertex v2;
|
|
|
|
SSATriVertex v3;
|
|
|
|
SSAUBytePtr texturePixels;
|
|
|
|
SSAInt textureWidth;
|
|
|
|
SSAInt textureHeight;
|
|
|
|
SSAUBytePtr translation;
|
|
|
|
SSAInt color, srcalpha, destalpha;
|
|
|
|
|
|
|
|
SSAInt light;
|
|
|
|
SSAShadeConstants shade_constants;
|
|
|
|
SSABool is_simple_shade;
|
|
|
|
SSABool is_nearest_filter;
|
|
|
|
SSABool is_fixed_light;
|
|
|
|
|
|
|
|
SSAUBytePtr Colormaps;
|
|
|
|
SSAUBytePtr RGB32k;
|
|
|
|
SSAUBytePtr BaseColors;
|
|
|
|
|
|
|
|
SSAInt numSpans;
|
|
|
|
SSAInt numBlocks;
|
|
|
|
SSAInt startX;
|
|
|
|
SSAInt startY;
|
|
|
|
SSAValue fullSpans; // TriFullSpan[]
|
|
|
|
SSAValue partialBlocks; // TriPartialBlock[]
|
|
|
|
|
|
|
|
TriBlendMode blendmode;
|
|
|
|
bool truecolor;
|
2016-12-15 22:29:31 +00:00
|
|
|
bool colorfill;
|
2016-12-15 00:33:26 +00:00
|
|
|
int pixelsize;
|
|
|
|
};
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
2016-11-11 23:50:21 +00:00
|
|
|
class DrawTriangleCodegen : public DrawerCodegen
|
|
|
|
{
|
|
|
|
public:
|
2016-11-19 01:53:32 +00:00
|
|
|
void Generate(TriDrawVariant variant, TriBlendMode blendmode, bool truecolor, SSAValue args, SSAValue thread_data);
|
2016-11-11 23:50:21 +00:00
|
|
|
|
|
|
|
private:
|
2016-11-19 01:53:32 +00:00
|
|
|
void LoadArgs(SSAValue args, SSAValue thread_data);
|
2016-11-11 23:50:21 +00:00
|
|
|
SSATriVertex LoadTriVertex(SSAValue v);
|
|
|
|
void LoadUniforms(SSAValue uniforms);
|
2016-11-19 01:53:32 +00:00
|
|
|
void Setup();
|
2016-11-13 07:57:29 +00:00
|
|
|
SSAInt FloatTo28_4(SSAFloat v);
|
2016-11-19 01:53:32 +00:00
|
|
|
void LoopBlockY();
|
|
|
|
void LoopBlockX();
|
|
|
|
void LoopFullBlock();
|
2016-12-01 12:31:42 +00:00
|
|
|
void LoopPartialBlock(bool isSingleStencilValue);
|
2016-11-29 12:54:06 +00:00
|
|
|
void SetupAffineBlock();
|
2016-11-11 23:50:21 +00:00
|
|
|
|
2016-11-20 00:29:19 +00:00
|
|
|
SSAVec4i ProcessPixel32(SSAVec4i bg, SSAInt *varying);
|
|
|
|
SSAInt ProcessPixel8(SSAInt bg, SSAInt *varying);
|
2016-11-19 01:53:32 +00:00
|
|
|
|
2016-12-04 04:52:13 +00:00
|
|
|
SSAVec4i TranslateSample32(SSAInt *varying);
|
|
|
|
SSAInt TranslateSample8(SSAInt *varying);
|
|
|
|
SSAVec4i Sample32(SSAInt *varying);
|
|
|
|
SSAInt Sample8(SSAInt *varying);
|
2016-11-20 15:42:53 +00:00
|
|
|
SSAInt Shade8(SSAInt c);
|
|
|
|
SSAVec4i ToBgra(SSAInt index);
|
|
|
|
SSAInt ToPal8(SSAVec4i c);
|
2016-11-11 23:50:21 +00:00
|
|
|
|
2016-12-03 05:58:06 +00:00
|
|
|
SSAVec4i FadeOut(SSAInt frac, SSAVec4i color);
|
|
|
|
|
2016-11-12 09:21:02 +00:00
|
|
|
void SetStencilBlock(SSAInt block);
|
|
|
|
void StencilClear(SSAUByte value);
|
|
|
|
SSAUByte StencilGetSingle();
|
|
|
|
SSABool StencilIsSingleValue();
|
|
|
|
|
2016-11-11 23:50:21 +00:00
|
|
|
SSAFloat gradx(SSAFloat x0, SSAFloat y0, SSAFloat x1, SSAFloat y1, SSAFloat x2, SSAFloat y2, SSAFloat c0, SSAFloat c1, SSAFloat c2);
|
|
|
|
SSAFloat grady(SSAFloat x0, SSAFloat y0, SSAFloat x1, SSAFloat y1, SSAFloat x2, SSAFloat y2, SSAFloat c0, SSAFloat c1, SSAFloat c2);
|
|
|
|
|
2016-11-19 01:53:32 +00:00
|
|
|
TriDrawVariant variant;
|
|
|
|
TriBlendMode blendmode;
|
|
|
|
bool truecolor;
|
|
|
|
|
2016-11-11 23:50:21 +00:00
|
|
|
SSAStack<SSAInt> stack_C1, stack_C2, stack_C3;
|
|
|
|
SSAStack<SSAInt> stack_y;
|
|
|
|
SSAStack<SSAUBytePtr> stack_dest;
|
|
|
|
SSAStack<SSAInt> stack_x;
|
|
|
|
SSAStack<SSAUBytePtr> stack_buffer;
|
|
|
|
SSAStack<SSAInt> stack_iy, stack_ix;
|
|
|
|
SSAStack<SSAInt> stack_CY1, stack_CY2, stack_CY3;
|
|
|
|
SSAStack<SSAInt> stack_CX1, stack_CX2, stack_CX3;
|
2016-11-29 12:54:06 +00:00
|
|
|
SSAStack<SSAFloat> stack_posy_w, stack_posy_varying[TriVertex::NumVarying];
|
|
|
|
SSAStack<SSAFloat> stack_posx_w, stack_posx_varying[TriVertex::NumVarying];
|
2016-11-30 11:56:37 +00:00
|
|
|
SSAStack<SSAFloat> stack_AffineW;
|
|
|
|
SSAStack<SSAFloat> stack_AffineVaryingPosY[TriVertex::NumVarying];
|
|
|
|
SSAStack<SSAInt> stack_AffineVaryingPosX[TriVertex::NumVarying];
|
2016-12-01 12:31:42 +00:00
|
|
|
SSAStack<SSABool> stack_stencilblock_restored;
|
|
|
|
SSAStack<SSAUByte> stack_stencilblock_lastval;
|
2016-11-29 12:54:06 +00:00
|
|
|
|
2016-11-11 23:50:21 +00:00
|
|
|
SSAUBytePtr dest;
|
|
|
|
SSAInt pitch;
|
|
|
|
SSATriVertex v1;
|
|
|
|
SSATriVertex v2;
|
|
|
|
SSATriVertex v3;
|
|
|
|
SSAInt clipright;
|
|
|
|
SSAInt clipbottom;
|
|
|
|
SSAUBytePtr texturePixels;
|
|
|
|
SSAInt textureWidth;
|
|
|
|
SSAInt textureHeight;
|
2016-11-19 01:53:32 +00:00
|
|
|
SSAUBytePtr translation;
|
|
|
|
SSAInt color, srcalpha, destalpha;
|
2016-11-11 23:50:21 +00:00
|
|
|
|
|
|
|
SSAInt light;
|
|
|
|
SSAShadeConstants shade_constants;
|
|
|
|
SSABool is_simple_shade;
|
|
|
|
SSABool is_nearest_filter;
|
2016-11-15 22:30:42 +00:00
|
|
|
SSABool is_fixed_light;
|
2016-11-11 23:50:21 +00:00
|
|
|
|
|
|
|
SSAUBytePtr stencilValues;
|
|
|
|
SSAIntPtr stencilMasks;
|
|
|
|
SSAInt stencilPitch;
|
|
|
|
SSAUByte stencilTestValue;
|
|
|
|
SSAUByte stencilWriteValue;
|
|
|
|
|
2016-11-20 03:06:21 +00:00
|
|
|
SSAUBytePtr Colormaps;
|
|
|
|
SSAUBytePtr RGB32k;
|
2016-11-20 15:42:53 +00:00
|
|
|
SSAUBytePtr BaseColors;
|
2016-11-20 03:06:21 +00:00
|
|
|
|
2016-11-11 23:50:21 +00:00
|
|
|
SSAWorkerThread thread;
|
|
|
|
|
|
|
|
// Block size, standard 8x8 (must be power of two)
|
|
|
|
const int q = 8;
|
|
|
|
|
|
|
|
SSAInt Y1, Y2, Y3;
|
|
|
|
SSAInt X1, X2, X3;
|
|
|
|
SSAInt DX12, DX23, DX31;
|
|
|
|
SSAInt DY12, DY23, DY31;
|
|
|
|
SSAInt FDX12, FDX23, FDX31;
|
|
|
|
SSAInt FDY12, FDY23, FDY31;
|
|
|
|
SSAInt minx, maxx, miny, maxy;
|
|
|
|
SSAInt C1, C2, C3;
|
2016-11-29 12:54:06 +00:00
|
|
|
SSAFloat gradWX, gradWY;
|
|
|
|
SSAFloat gradVaryingX[TriVertex::NumVarying], gradVaryingY[TriVertex::NumVarying];
|
2016-12-01 08:00:24 +00:00
|
|
|
SSAFloat shade;
|
2016-11-11 23:50:21 +00:00
|
|
|
|
|
|
|
SSAInt x, y;
|
|
|
|
SSAInt x0, x1, y0, y1;
|
2016-11-15 22:30:42 +00:00
|
|
|
SSAInt currentlight;
|
2016-11-20 03:06:21 +00:00
|
|
|
SSAUBytePtr currentcolormap;
|
2016-11-30 11:56:37 +00:00
|
|
|
SSAFloat AffineW;
|
2016-12-04 04:52:13 +00:00
|
|
|
SSABool AffineLinear;
|
2016-11-30 11:56:37 +00:00
|
|
|
SSAFloat AffineVaryingPosY[TriVertex::NumVarying];
|
|
|
|
SSAInt AffineVaryingPosX[TriVertex::NumVarying];
|
|
|
|
SSAInt AffineVaryingStepX[TriVertex::NumVarying];
|
2016-11-12 09:21:02 +00:00
|
|
|
|
2016-11-29 12:54:06 +00:00
|
|
|
SSAFloat posy_w, posy_varying[TriVertex::NumVarying];
|
|
|
|
SSAFloat posx_w, posx_varying[TriVertex::NumVarying];
|
|
|
|
|
2016-11-12 09:21:02 +00:00
|
|
|
SSAUBytePtr StencilBlock;
|
|
|
|
SSAIntPtr StencilBlockMask;
|
2016-11-11 23:50:21 +00:00
|
|
|
};
|
2016-12-15 00:33:26 +00:00
|
|
|
|
|
|
|
#endif
|