mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-25 05:31:00 +00:00
- only calculate gradients once
This commit is contained in:
parent
6db89a2ce1
commit
da6bfe65ff
4 changed files with 38 additions and 54 deletions
|
@ -319,17 +319,9 @@ private:
|
||||||
|
|
||||||
// Calculate gradients
|
// Calculate gradients
|
||||||
const TriVertex &v1 = *args->v1;
|
const TriVertex &v1 = *args->v1;
|
||||||
const TriVertex &v2 = *args->v2;
|
ScreenTriangleStepVariables gradientX = args->gradientX;
|
||||||
const TriVertex &v3 = *args->v3;
|
ScreenTriangleStepVariables gradientY = args->gradientY;
|
||||||
ScreenTriangleStepVariables gradientX;
|
|
||||||
ScreenTriangleStepVariables gradientY;
|
|
||||||
ScreenTriangleStepVariables blockPosY;
|
ScreenTriangleStepVariables blockPosY;
|
||||||
gradientX.W = FindGradientX(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.w, v2.w, v3.w);
|
|
||||||
gradientY.W = FindGradientY(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.w, v2.w, v3.w);
|
|
||||||
gradientX.U = FindGradientX(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.u * v1.w, v2.u * v2.w, v3.u * v3.w);
|
|
||||||
gradientY.U = FindGradientY(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.u * v1.w, v2.u * v2.w, v3.u * v3.w);
|
|
||||||
gradientX.V = FindGradientX(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.v * v1.w, v2.v * v2.w, v3.v * v3.w);
|
|
||||||
gradientY.V = FindGradientY(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.v * v1.w, v2.v * v2.w, v3.v * v3.w);
|
|
||||||
blockPosY.W = v1.w + gradientX.W * (destX - v1.x) + gradientY.W * (destY - v1.y);
|
blockPosY.W = v1.w + gradientX.W * (destX - v1.x) + gradientY.W * (destY - v1.y);
|
||||||
blockPosY.U = v1.u * v1.w + gradientX.U * (destX - v1.x) + gradientY.U * (destY - v1.y);
|
blockPosY.U = v1.u * v1.w + gradientX.U * (destX - v1.x) + gradientY.U * (destY - v1.y);
|
||||||
blockPosY.V = v1.v * v1.w + gradientX.V * (destX - v1.x) + gradientY.V * (destY - v1.y);
|
blockPosY.V = v1.v * v1.w + gradientX.V * (destX - v1.x) + gradientY.V * (destY - v1.y);
|
||||||
|
@ -645,20 +637,6 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static float FindGradientX(float x0, float y0, float x1, float y1, float x2, float y2, float c0, float c1, float c2)
|
|
||||||
{
|
|
||||||
float top = (c1 - c2) * (y0 - y2) - (c0 - c2) * (y1 - y2);
|
|
||||||
float bottom = (x1 - x2) * (y0 - y2) - (x0 - x2) * (y1 - y2);
|
|
||||||
return top / bottom;
|
|
||||||
}
|
|
||||||
|
|
||||||
static float FindGradientY(float x0, float y0, float x1, float y1, float x2, float y2, float c0, float c1, float c2)
|
|
||||||
{
|
|
||||||
float top = (c1 - c2) * (x0 - x2) - (c0 - c2) * (x1 - x2);
|
|
||||||
float bottom = (x0 - x2) * (y1 - y2) - (x1 - x2) * (y0 - y2);
|
|
||||||
return top / bottom;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename BlendT, typename SamplerT>
|
template<typename BlendT, typename SamplerT>
|
||||||
|
|
|
@ -221,17 +221,9 @@ public:
|
||||||
|
|
||||||
// Calculate gradients
|
// Calculate gradients
|
||||||
const TriVertex &v1 = *args->v1;
|
const TriVertex &v1 = *args->v1;
|
||||||
const TriVertex &v2 = *args->v2;
|
ScreenTriangleStepVariables gradientX = args->gradientX;
|
||||||
const TriVertex &v3 = *args->v3;
|
ScreenTriangleStepVariables gradientY = args->gradientY;
|
||||||
ScreenTriangleStepVariables gradientX;
|
|
||||||
ScreenTriangleStepVariables gradientY;
|
|
||||||
ScreenTriangleStepVariables blockPosY;
|
ScreenTriangleStepVariables blockPosY;
|
||||||
gradientX.W = FindGradientX(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.w, v2.w, v3.w);
|
|
||||||
gradientY.W = FindGradientY(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.w, v2.w, v3.w);
|
|
||||||
gradientX.U = FindGradientX(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.u * v1.w, v2.u * v2.w, v3.u * v3.w);
|
|
||||||
gradientY.U = FindGradientY(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.u * v1.w, v2.u * v2.w, v3.u * v3.w);
|
|
||||||
gradientX.V = FindGradientX(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.v * v1.w, v2.v * v2.w, v3.v * v3.w);
|
|
||||||
gradientY.V = FindGradientY(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.v * v1.w, v2.v * v2.w, v3.v * v3.w);
|
|
||||||
blockPosY.W = v1.w + gradientX.W * (destX - v1.x) + gradientY.W * (destY - v1.y);
|
blockPosY.W = v1.w + gradientX.W * (destX - v1.x) + gradientY.W * (destY - v1.y);
|
||||||
blockPosY.U = v1.u * v1.w + gradientX.U * (destX - v1.x) + gradientY.U * (destY - v1.y);
|
blockPosY.U = v1.u * v1.w + gradientX.U * (destX - v1.x) + gradientY.U * (destY - v1.y);
|
||||||
blockPosY.V = v1.v * v1.w + gradientX.V * (destX - v1.x) + gradientY.V * (destY - v1.y);
|
blockPosY.V = v1.v * v1.w + gradientX.V * (destX - v1.x) + gradientY.V * (destY - v1.y);
|
||||||
|
@ -405,21 +397,6 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
static float FindGradientX(float x0, float y0, float x1, float y1, float x2, float y2, float c0, float c1, float c2)
|
|
||||||
{
|
|
||||||
float top = (c1 - c2) * (y0 - y2) - (c0 - c2) * (y1 - y2);
|
|
||||||
float bottom = (x1 - x2) * (y0 - y2) - (x0 - x2) * (y1 - y2);
|
|
||||||
return top / bottom;
|
|
||||||
}
|
|
||||||
|
|
||||||
static float FindGradientY(float x0, float y0, float x1, float y1, float x2, float y2, float c0, float c1, float c2)
|
|
||||||
{
|
|
||||||
float top = (c1 - c2) * (x0 - x2) - (c0 - c2) * (x1 - x2);
|
|
||||||
float bottom = (x0 - x2) * (y1 - y2) - (x1 - x2) * (y0 - y2);
|
|
||||||
return top / bottom;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename BlendT, typename SamplerT>
|
template<typename BlendT, typename SamplerT>
|
||||||
|
|
|
@ -227,6 +227,7 @@ void PolyTriangleDrawer::draw_shaded_triangle(const ShadedTriVertex *vert, bool
|
||||||
args->v1 = &clippedvert[numclipvert - 1];
|
args->v1 = &clippedvert[numclipvert - 1];
|
||||||
args->v2 = &clippedvert[i - 1];
|
args->v2 = &clippedvert[i - 1];
|
||||||
args->v3 = &clippedvert[i - 2];
|
args->v3 = &clippedvert[i - 2];
|
||||||
|
args->CalculateGradients();
|
||||||
|
|
||||||
ScreenTriangle::Draw(args, thread);
|
ScreenTriangle::Draw(args, thread);
|
||||||
}
|
}
|
||||||
|
@ -238,6 +239,7 @@ void PolyTriangleDrawer::draw_shaded_triangle(const ShadedTriVertex *vert, bool
|
||||||
args->v1 = &clippedvert[0];
|
args->v1 = &clippedvert[0];
|
||||||
args->v2 = &clippedvert[i - 1];
|
args->v2 = &clippedvert[i - 1];
|
||||||
args->v3 = &clippedvert[i];
|
args->v3 = &clippedvert[i];
|
||||||
|
args->CalculateGradients();
|
||||||
|
|
||||||
ScreenTriangle::Draw(args, thread);
|
ScreenTriangle::Draw(args, thread);
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,11 @@ struct TriVertex
|
||||||
float u, v;
|
float u, v;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ScreenTriangleStepVariables
|
||||||
|
{
|
||||||
|
float W, U, V;
|
||||||
|
};
|
||||||
|
|
||||||
struct TriDrawTriangleArgs
|
struct TriDrawTriangleArgs
|
||||||
{
|
{
|
||||||
uint8_t *dest;
|
uint8_t *dest;
|
||||||
|
@ -58,6 +63,33 @@ struct TriDrawTriangleArgs
|
||||||
uint32_t *subsectorGBuffer;
|
uint32_t *subsectorGBuffer;
|
||||||
const PolyDrawArgs *uniforms;
|
const PolyDrawArgs *uniforms;
|
||||||
bool destBgra;
|
bool destBgra;
|
||||||
|
ScreenTriangleStepVariables gradientX;
|
||||||
|
ScreenTriangleStepVariables gradientY;
|
||||||
|
|
||||||
|
void CalculateGradients()
|
||||||
|
{
|
||||||
|
gradientX.W = FindGradientX(v1->x, v1->y, v2->x, v2->y, v3->x, v3->y, v1->w, v2->w, v3->w);
|
||||||
|
gradientY.W = FindGradientY(v1->x, v1->y, v2->x, v2->y, v3->x, v3->y, v1->w, v2->w, v3->w);
|
||||||
|
gradientX.U = FindGradientX(v1->x, v1->y, v2->x, v2->y, v3->x, v3->y, v1->u * v1->w, v2->u * v2->w, v3->u * v3->w);
|
||||||
|
gradientY.U = FindGradientY(v1->x, v1->y, v2->x, v2->y, v3->x, v3->y, v1->u * v1->w, v2->u * v2->w, v3->u * v3->w);
|
||||||
|
gradientX.V = FindGradientX(v1->x, v1->y, v2->x, v2->y, v3->x, v3->y, v1->v * v1->w, v2->v * v2->w, v3->v * v3->w);
|
||||||
|
gradientY.V = FindGradientY(v1->x, v1->y, v2->x, v2->y, v3->x, v3->y, v1->v * v1->w, v2->v * v2->w, v3->v * v3->w);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static float FindGradientX(float x0, float y0, float x1, float y1, float x2, float y2, float c0, float c1, float c2)
|
||||||
|
{
|
||||||
|
float top = (c1 - c2) * (y0 - y2) - (c0 - c2) * (y1 - y2);
|
||||||
|
float bottom = (x1 - x2) * (y0 - y2) - (x0 - x2) * (y1 - y2);
|
||||||
|
return top / bottom;
|
||||||
|
}
|
||||||
|
|
||||||
|
static float FindGradientY(float x0, float y0, float x1, float y1, float x2, float y2, float c0, float c1, float c2)
|
||||||
|
{
|
||||||
|
float top = (c1 - c2) * (x0 - x2) - (c0 - c2) * (x1 - x2);
|
||||||
|
float bottom = (x0 - x2) * (y1 - y2) - (x1 - x2) * (y0 - y2);
|
||||||
|
return top / bottom;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class RectDrawArgs;
|
class RectDrawArgs;
|
||||||
|
@ -99,11 +131,6 @@ public:
|
||||||
static void(*RectDrawers32[])(const void *, int, int, int, const RectDrawArgs *, WorkerThreadData *);
|
static void(*RectDrawers32[])(const void *, int, int, int, const RectDrawArgs *, WorkerThreadData *);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ScreenTriangleStepVariables
|
|
||||||
{
|
|
||||||
float W, U, V;
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace TriScreenDrawerModes
|
namespace TriScreenDrawerModes
|
||||||
{
|
{
|
||||||
enum class BlendModes { Opaque, Masked, AddClamp, SubClamp, RevSubClamp, AddSrcColorOneMinusSrcColor, Shaded, AddClampShaded };
|
enum class BlendModes { Opaque, Masked, AddClamp, SubClamp, RevSubClamp, AddSrcColorOneMinusSrcColor, Shaded, AddClampShaded };
|
||||||
|
|
Loading…
Reference in a new issue