2019-12-12 17:32:41 +01:00
|
|
|
// Copyright (C) 2002-2012 Nikolaus Gebhardt / Thomas Alten
|
|
|
|
// This file is part of the "Irrlicht Engine".
|
|
|
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
|
|
|
|
|
|
|
#include "IrrCompileConfig.h"
|
|
|
|
#include "IBurningShader.h"
|
|
|
|
|
|
|
|
#ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_
|
|
|
|
|
|
|
|
// compile flag for this file
|
|
|
|
#undef USE_ZBUFFER
|
|
|
|
#undef IPOL_Z
|
|
|
|
#undef CMP_Z
|
|
|
|
#undef WRITE_Z
|
|
|
|
|
|
|
|
#undef IPOL_W
|
|
|
|
#undef CMP_W
|
|
|
|
#undef WRITE_W
|
|
|
|
|
|
|
|
#undef SUBTEXEL
|
|
|
|
#undef INVERSE_W
|
|
|
|
|
|
|
|
#undef IPOL_C0
|
|
|
|
#undef IPOL_T0
|
|
|
|
#undef IPOL_T1
|
|
|
|
|
|
|
|
// define render case
|
|
|
|
#define SUBTEXEL
|
|
|
|
#define INVERSE_W
|
|
|
|
|
2022-05-01 00:57:17 +02:00
|
|
|
#define USE_ZBUFFER
|
2019-12-12 17:32:41 +01:00
|
|
|
#define IPOL_W
|
2022-05-01 00:57:17 +02:00
|
|
|
#define CMP_W
|
|
|
|
#define WRITE_W
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
|
2020-02-22 21:48:12 +01:00
|
|
|
#define IPOL_C0
|
|
|
|
//#define IPOL_T0
|
2019-12-12 17:32:41 +01:00
|
|
|
//#define IPOL_T1
|
|
|
|
|
|
|
|
// apply global override
|
|
|
|
#ifndef SOFTWARE_DRIVER_2_PERSPECTIVE_CORRECT
|
2022-05-01 00:57:17 +02:00
|
|
|
#undef INVERSE_W
|
2019-12-12 17:32:41 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SOFTWARE_DRIVER_2_SUBTEXEL
|
2022-05-01 00:57:17 +02:00
|
|
|
#undef SUBTEXEL
|
2019-12-12 17:32:41 +01:00
|
|
|
#endif
|
|
|
|
|
2020-02-22 21:48:12 +01:00
|
|
|
#if BURNING_MATERIAL_MAX_COLORS < 1
|
2022-05-01 00:57:17 +02:00
|
|
|
#undef IPOL_C0
|
2020-02-22 21:48:12 +01:00
|
|
|
#endif
|
|
|
|
|
2019-12-12 17:32:41 +01:00
|
|
|
#if !defined ( SOFTWARE_DRIVER_2_USE_WBUFFER ) && defined ( USE_ZBUFFER )
|
2022-05-01 00:57:17 +02:00
|
|
|
#ifndef SOFTWARE_DRIVER_2_PERSPECTIVE_CORRECT
|
|
|
|
#undef IPOL_W
|
|
|
|
#endif
|
|
|
|
#define IPOL_Z
|
2019-12-12 17:32:41 +01:00
|
|
|
|
2022-05-01 00:57:17 +02:00
|
|
|
#ifdef CMP_W
|
|
|
|
#undef CMP_W
|
|
|
|
#define CMP_Z
|
2019-12-12 17:32:41 +01:00
|
|
|
#endif
|
|
|
|
|
2022-05-01 00:57:17 +02:00
|
|
|
#ifdef WRITE_W
|
|
|
|
#undef WRITE_W
|
|
|
|
#define WRITE_Z
|
|
|
|
#endif
|
2019-12-12 17:32:41 +01:00
|
|
|
|
2022-05-01 00:57:17 +02:00
|
|
|
#endif
|
2019-12-12 17:32:41 +01:00
|
|
|
|
2022-05-01 00:57:17 +02:00
|
|
|
burning_namespace_start
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
class CTRTextureWire2 : public IBurningShader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
//! constructor
|
|
|
|
CTRTextureWire2(CBurningVideoDriver* driver);
|
|
|
|
|
2022-05-04 12:29:41 +02:00
|
|
|
virtual void OnSetMaterialBurning(const SBurningShaderMaterial& material) IRR_OVERRIDE;
|
2022-05-01 00:57:17 +02:00
|
|
|
|
2019-12-12 17:32:41 +01:00
|
|
|
//! draws an indexed triangle list
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void drawTriangle(const s4DVertex* burning_restrict a, const s4DVertex* burning_restrict b, const s4DVertex* burning_restrict c) IRR_OVERRIDE;
|
2022-05-01 00:57:17 +02:00
|
|
|
virtual void drawLine(const s4DVertex* a, const s4DVertex* b) IRR_OVERRIDE;
|
|
|
|
virtual void drawPoint(const s4DVertex* a) IRR_OVERRIDE;
|
|
|
|
virtual bool canWireFrame() IRR_OVERRIDE { return true; }
|
|
|
|
virtual bool canPointCloud() IRR_OVERRIDE { return true; }
|
2019-12-12 17:32:41 +01:00
|
|
|
|
2020-02-22 21:48:12 +01:00
|
|
|
protected:
|
2019-12-12 17:32:41 +01:00
|
|
|
|
2022-05-01 00:57:17 +02:00
|
|
|
void renderLine(const s4DVertex* a, const s4DVertex* b) const;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
2022-05-01 00:57:17 +02:00
|
|
|
int renderZero;
|
|
|
|
int depth_pass;
|
|
|
|
int depth_write;
|
2019-12-12 17:32:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
//! constructor
|
|
|
|
CTRTextureWire2::CTRTextureWire2(CBurningVideoDriver* driver)
|
2022-05-03 22:47:32 +02:00
|
|
|
: IBurningShader(driver, EMT_SOLID)
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
2022-05-01 00:57:17 +02:00
|
|
|
#ifdef _DEBUG
|
2019-12-12 17:32:41 +01:00
|
|
|
setDebugName("CTRTextureWire2");
|
2022-05-01 00:57:17 +02:00
|
|
|
#endif
|
|
|
|
renderZero = 0;
|
|
|
|
depth_pass = 1;
|
|
|
|
depth_write = 0;
|
2019-12-12 17:32:41 +01:00
|
|
|
}
|
|
|
|
|
2022-05-04 12:29:41 +02:00
|
|
|
void CTRTextureWire2::OnSetMaterialBurning(const SBurningShaderMaterial& material)
|
2022-05-01 00:57:17 +02:00
|
|
|
{
|
|
|
|
depth_pass = material.depth_test == 0;
|
|
|
|
depth_write = material.depth_write;
|
|
|
|
}
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*!
|
2020-02-22 21:48:12 +01:00
|
|
|
2d line
|
2019-12-12 17:32:41 +01:00
|
|
|
*/
|
2022-05-01 00:57:17 +02:00
|
|
|
void CTRTextureWire2::renderLine(const s4DVertex* a, const s4DVertex* b) const
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
2022-05-01 00:57:17 +02:00
|
|
|
const int pitch0 = RenderTarget->getDimension().Width << SOFTWARE_DRIVER_2_RENDERTARGET_GRANULARITY;
|
2020-02-22 23:01:57 +01:00
|
|
|
#ifdef USE_ZBUFFER
|
2022-05-01 00:57:17 +02:00
|
|
|
const int pitch1 = RenderTarget->getDimension().Width * sizeof(fp24);
|
2020-02-22 23:01:57 +01:00
|
|
|
#endif
|
2019-12-12 17:32:41 +01:00
|
|
|
|
2022-05-01 00:57:17 +02:00
|
|
|
//todo: fill_convention_none!
|
2020-02-22 21:48:12 +01:00
|
|
|
int aposx = fill_convention_none(a->Pos.x);
|
|
|
|
int aposy = fill_convention_none(a->Pos.y);
|
|
|
|
int bposx = fill_convention_none(b->Pos.x);
|
|
|
|
int bposy = fill_convention_none(b->Pos.y);
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
int dx = bposx - aposx;
|
|
|
|
int dy = bposy - aposy;
|
|
|
|
|
|
|
|
int c;
|
|
|
|
int m;
|
|
|
|
int d = 0;
|
|
|
|
int run;
|
|
|
|
|
2022-05-01 00:57:17 +02:00
|
|
|
tVideoSample* dst;
|
2019-12-12 17:32:41 +01:00
|
|
|
#ifdef USE_ZBUFFER
|
2022-05-01 00:57:17 +02:00
|
|
|
fp24* z;
|
2019-12-12 17:32:41 +01:00
|
|
|
#endif
|
|
|
|
|
2020-11-10 19:49:39 +01:00
|
|
|
int xInc0 = 1 << SOFTWARE_DRIVER_2_RENDERTARGET_GRANULARITY;
|
2019-12-12 17:32:41 +01:00
|
|
|
int yInc0 = pitch0;
|
|
|
|
|
2020-02-22 21:48:12 +01:00
|
|
|
#ifdef USE_ZBUFFER
|
2022-05-01 00:57:17 +02:00
|
|
|
int xInc1 = sizeof(fp24);
|
2019-12-12 17:32:41 +01:00
|
|
|
int yInc1 = pitch1;
|
|
|
|
#endif
|
|
|
|
|
2022-05-01 00:57:17 +02:00
|
|
|
if (dx < 0)
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
2022-05-01 00:57:17 +02:00
|
|
|
xInc0 = -xInc0;
|
2020-02-22 21:48:12 +01:00
|
|
|
#ifdef USE_ZBUFFER
|
2019-12-12 17:32:41 +01:00
|
|
|
xInc1 = -4;
|
2020-02-22 21:48:12 +01:00
|
|
|
#endif
|
2019-12-12 17:32:41 +01:00
|
|
|
dx = -dx;
|
|
|
|
}
|
|
|
|
|
2022-05-01 00:57:17 +02:00
|
|
|
if (dy > dx)
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
2020-02-22 21:48:12 +01:00
|
|
|
//swap
|
2020-06-21 13:38:31 +02:00
|
|
|
s32 t;
|
2022-05-01 00:57:17 +02:00
|
|
|
t = dx; dx = dy; dy = t;
|
|
|
|
t = xInc0; xInc0 = yInc0; yInc0 = t;
|
2020-02-22 21:48:12 +01:00
|
|
|
#ifdef USE_ZBUFFER
|
2022-05-01 00:57:17 +02:00
|
|
|
t = xInc1; xInc1 = yInc1; yInc1 = t;
|
2020-02-22 21:48:12 +01:00
|
|
|
#endif
|
2019-12-12 17:32:41 +01:00
|
|
|
}
|
|
|
|
|
2020-02-22 21:48:12 +01:00
|
|
|
if (0 == dx)
|
|
|
|
{
|
|
|
|
if (!renderZero) return;
|
|
|
|
dx = 1;
|
|
|
|
}
|
2019-12-12 17:32:41 +01:00
|
|
|
|
2020-02-22 21:48:12 +01:00
|
|
|
SOFTWARE_DRIVER_2_CLIPCHECK_WIRE;
|
2022-05-01 00:57:17 +02:00
|
|
|
dst = (tVideoSample*)((u8*)RenderTarget->getData() + (aposy * pitch0) + (aposx << SOFTWARE_DRIVER_2_RENDERTARGET_GRANULARITY));
|
|
|
|
|
2019-12-12 17:32:41 +01:00
|
|
|
#ifdef USE_ZBUFFER
|
2022-05-01 00:57:17 +02:00
|
|
|
z = (fp24*)((u8*)DepthBuffer->lock() + (aposy * pitch1) + (aposx << 2));
|
2019-12-12 17:32:41 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
c = dx << 1;
|
|
|
|
m = dy << 1;
|
|
|
|
|
2020-02-22 21:48:12 +01:00
|
|
|
// slopes
|
2022-05-01 00:57:17 +02:00
|
|
|
const f32 invDeltaX = fill_step_x((f32)dx);
|
2020-02-22 21:48:12 +01:00
|
|
|
|
2019-12-12 17:32:41 +01:00
|
|
|
#ifdef IPOL_Z
|
2020-02-22 21:48:12 +01:00
|
|
|
f32 slopeZ = (b->Pos.z - a->Pos.z) * invDeltaX;
|
2019-12-12 17:32:41 +01:00
|
|
|
f32 dataZ = a->Pos.z;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef IPOL_W
|
2020-02-22 21:48:12 +01:00
|
|
|
fp24 slopeW = (b->Pos.w - a->Pos.w) * invDeltaX;
|
2019-12-12 17:32:41 +01:00
|
|
|
fp24 dataW = a->Pos.w;
|
|
|
|
#endif
|
|
|
|
|
2020-02-22 21:48:12 +01:00
|
|
|
f32 inversew = FIX_POINT_F32_MUL;
|
|
|
|
|
|
|
|
tVideoSample color;
|
|
|
|
#if BURNING_MATERIAL_MAX_COLORS > 0
|
|
|
|
tFixPoint r0, g0, b0;
|
|
|
|
#ifdef IPOL_C0
|
|
|
|
sVec4 slopeC;
|
|
|
|
sVec4 C;
|
|
|
|
slopeC = (b->Color[0] - a->Color[0]) * invDeltaX;
|
|
|
|
C = a->Color[0];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef INVERSE_W
|
|
|
|
inversew = fix_inverse32_color(dataW);
|
|
|
|
#endif
|
|
|
|
|
2022-05-01 00:57:17 +02:00
|
|
|
vec4_to_fix(r0, g0, b0, a->Color[0], inversew);
|
|
|
|
color = fix_to_sample(r0, g0, b0);
|
2020-02-22 21:48:12 +01:00
|
|
|
|
|
|
|
#else
|
2022-05-01 00:57:17 +02:00
|
|
|
color = (tVideoSample)0xFFFFFFFF;
|
2020-02-22 21:48:12 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2019-12-12 17:32:41 +01:00
|
|
|
run = dx;
|
2022-05-01 00:57:17 +02:00
|
|
|
while (run)
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
#ifdef CMP_Z
|
2022-05-01 00:57:17 +02:00
|
|
|
if (*z >= dataZ)
|
2019-12-12 17:32:41 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CMP_W
|
2022-05-01 00:57:17 +02:00
|
|
|
if (depth_pass || dataW >= *z)
|
2019-12-12 17:32:41 +01:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
#ifdef WRITE_Z
|
|
|
|
*z = dataZ;
|
|
|
|
#endif
|
|
|
|
#ifdef WRITE_W
|
2022-05-01 00:57:17 +02:00
|
|
|
if (depth_write) *z = dataW;
|
2019-12-12 17:32:41 +01:00
|
|
|
#endif
|
|
|
|
|
2020-02-22 21:48:12 +01:00
|
|
|
#ifdef IPOL_C0
|
|
|
|
#ifdef INVERSE_W
|
|
|
|
inversew = fix_inverse32_color(dataW);
|
|
|
|
#endif
|
2022-05-01 00:57:17 +02:00
|
|
|
vec4_to_fix(r0, g0, b0, C, inversew);
|
|
|
|
color = fix_to_sample(r0, g0, b0);
|
2020-02-22 21:48:12 +01:00
|
|
|
#endif
|
2022-05-01 00:57:17 +02:00
|
|
|
* dst = color;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-05-01 00:57:17 +02:00
|
|
|
dst = (tVideoSample*)((u8*)dst + xInc0); // x += xInc
|
2020-02-22 21:48:12 +01:00
|
|
|
#ifdef CMP_Z
|
2022-05-01 00:57:17 +02:00
|
|
|
z = (fp24*)((u8*)z + xInc1);
|
2019-12-12 17:32:41 +01:00
|
|
|
#endif
|
2020-02-22 21:48:12 +01:00
|
|
|
#ifdef CMP_W
|
2022-05-01 00:57:17 +02:00
|
|
|
z = (fp24*)((u8*)z + xInc1);
|
2019-12-12 17:32:41 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
d += m;
|
2022-05-01 00:57:17 +02:00
|
|
|
if (d > dx)
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
2022-05-01 00:57:17 +02:00
|
|
|
dst = (tVideoSample*)((u8*)dst + yInc0); // y += yInc
|
2020-02-22 21:48:12 +01:00
|
|
|
#ifdef CMP_Z
|
2022-05-01 00:57:17 +02:00
|
|
|
z = (fp24*)((u8*)z + yInc1);
|
2019-12-12 17:32:41 +01:00
|
|
|
#endif
|
2020-02-22 21:48:12 +01:00
|
|
|
#ifdef CMP_W
|
2022-05-01 00:57:17 +02:00
|
|
|
z = (fp24*)((u8*)z + yInc1);
|
2019-12-12 17:32:41 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
d -= c;
|
|
|
|
}
|
|
|
|
run -= 1;
|
|
|
|
#ifdef IPOL_Z
|
|
|
|
dataZ += slopeZ;
|
|
|
|
#endif
|
|
|
|
#ifdef IPOL_W
|
|
|
|
dataW += slopeW;
|
|
|
|
#endif
|
2020-02-22 21:48:12 +01:00
|
|
|
#ifdef IPOL_C0
|
|
|
|
C += slopeC;
|
|
|
|
#endif
|
|
|
|
|
2019-12-12 17:32:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-02-22 21:48:12 +01:00
|
|
|
void CTRTextureWire2::drawTriangle(const s4DVertex* burning_restrict a, const s4DVertex* burning_restrict b, const s4DVertex* burning_restrict c)
|
|
|
|
{
|
2019-12-12 17:32:41 +01:00
|
|
|
// sort on height, y
|
2022-05-01 00:57:17 +02:00
|
|
|
if (F32_A_GREATER_B(a->Pos.y, b->Pos.y)) swapVertexPointer(&a, &b);
|
|
|
|
if (F32_A_GREATER_B(b->Pos.y, c->Pos.y)) swapVertexPointer(&b, &c);
|
|
|
|
if (F32_A_GREATER_B(a->Pos.y, b->Pos.y)) swapVertexPointer(&a, &b);
|
2019-12-12 17:32:41 +01:00
|
|
|
|
2022-05-01 00:57:17 +02:00
|
|
|
renderLine(a, b);
|
|
|
|
renderLine(b, c);
|
|
|
|
renderLine(a, c);
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-01 00:57:17 +02:00
|
|
|
void CTRTextureWire2::drawLine(const s4DVertex* a, const s4DVertex* b)
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
// query access to TexMaps
|
|
|
|
|
|
|
|
// sort on height, y
|
2022-05-01 00:57:17 +02:00
|
|
|
if (F32_A_GREATER_B(a->Pos.y, b->Pos.y)) swapVertexPointer(&a, &b);
|
2019-12-12 17:32:41 +01:00
|
|
|
|
2022-05-01 00:57:17 +02:00
|
|
|
renderLine(a, b);
|
2020-02-22 21:48:12 +01:00
|
|
|
}
|
2019-12-12 17:32:41 +01:00
|
|
|
|
2022-05-01 00:57:17 +02:00
|
|
|
void CTRTextureWire2::drawPoint(const s4DVertex* a)
|
2020-02-22 21:48:12 +01:00
|
|
|
{
|
2022-05-01 00:57:17 +02:00
|
|
|
if ((a->flag & VERTEX4D_CLIPMASK) == VERTEX4D_INSIDE)
|
|
|
|
{
|
|
|
|
renderZero = 1;
|
|
|
|
renderLine(a, a);
|
|
|
|
renderZero = 0;
|
|
|
|
}
|
2019-12-12 17:32:41 +01:00
|
|
|
}
|
|
|
|
|
2022-05-01 00:57:17 +02:00
|
|
|
burning_namespace_end
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
#endif // _IRR_COMPILE_WITH_BURNINGSVIDEO_
|
|
|
|
|
2022-05-01 00:57:17 +02:00
|
|
|
burning_namespace_start
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! creates a flat triangle renderer
|
|
|
|
IBurningShader* createTriangleRendererTextureGouraudWire2(CBurningVideoDriver* driver)
|
|
|
|
{
|
2020-02-22 21:48:12 +01:00
|
|
|
//ETR_TEXTURE_GOURAUD_WIRE
|
2022-05-01 00:57:17 +02:00
|
|
|
#ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_
|
2019-12-12 17:32:41 +01:00
|
|
|
return new CTRTextureWire2(driver);
|
2022-05-01 00:57:17 +02:00
|
|
|
#else
|
2019-12-12 17:32:41 +01:00
|
|
|
return 0;
|
2022-05-01 00:57:17 +02:00
|
|
|
#endif // _IRR_COMPILE_WITH_BURNINGSVIDEO_
|
2019-12-12 17:32:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-01 00:57:17 +02:00
|
|
|
burning_namespace_end
|
2019-12-12 17:32:41 +01:00
|
|
|
|