📄 mgcsoftzc.cpp
字号:
// Magic Software, Inc.
// http://www.magic-software.com
// Copyright (c) 2000, All Rights Reserved
//
// Source code from Magic Software is supplied under the terms of a license
// agreement and may not be copied or disclosed except in accordance with the
// terms of that agreement. The various license agreements may be found at
// the Magic Software web site. This file is subject to the license
//
// RESTRICTED USE SOURCE CODE
// http://www.magic-software.com/License/restricted.pdf
#include "MgcSoftASM.h"
#include "MgcSoftRenderer.h"
// TO DO. This sample code ignores the members of the MgcZBufferState
// object. The depth buffer is always tested and written when necessary.
// The comparison function is 'less than or equal to'. The code should be
// modified to properly handle the members.
//---------------------------------------------------------------------------
void MgcSoftRenderer::DrawEdgeZC (unsigned int uiV0, unsigned int uiV1)
{
EdgeSetupParameters
LinAttrSetup(4)
MgcColor& rkC0 = m_kMesh.Color(uiV0);
MgcColor& rkC1 = m_kMesh.Color(uiV1);
MgcSoftASM_FloatToIntMult(rkC0.r,aiA0[0],8);
MgcSoftASM_FloatToIntMult(rkC0.g,aiA0[1],8);
MgcSoftASM_FloatToIntMult(rkC0.b,aiA0[2],8);
MgcSoftASM_FloatToIntMult(m_kMesh.Depth(uiV0),aiA0[3],16);
MgcSoftASM_FloatToIntMult(rkC1.r,aiA1[0],8);
MgcSoftASM_FloatToIntMult(rkC1.g,aiA1[1],8);
MgcSoftASM_FloatToIntMult(rkC1.b,aiA1[2],8);
MgcSoftASM_FloatToIntMult(m_kMesh.Depth(uiV1),aiA1[3],16);
EdgeInitX
InitLinAttrX
EdgePrologTraverseX
if ( aiA0[3] <= m_ausZBuffer[iIndex] )
{
m_akBuffer[iIndex] = MgcSoftColor(aiA0[0],aiA0[1],aiA0[2]);
m_ausZBuffer[iIndex] = aiA0[3];
}
EdgeReturnX
UpdateLinAttrX
EdgeEpilogTraverseX
EdgeExitX
EdgeInitY
InitLinAttrY
EdgePrologTraverseY
if ( aiA0[3] <= m_ausZBuffer[iIndex] )
{
m_akBuffer[iIndex] = MgcSoftColor(aiA0[0],aiA0[1],aiA0[2]);
m_ausZBuffer[iIndex] = aiA0[3];
}
EdgeReturnY
UpdateLinAttrY
EdgeEpilogTraverseY
EdgeExitY
}
//---------------------------------------------------------------------------
void MgcSoftRenderer::DrawTriZC (unsigned int uiV0, unsigned int uiV1,
unsigned int uiV2)
{
TriangleSetupParameters
LinAttrSetup(4)
MgcColor& rkC0 = m_kMesh.Color(uiV0);
MgcColor& rkC1 = m_kMesh.Color(uiV1);
MgcColor& rkC2 = m_kMesh.Color(uiV2);
m_uiNumLinAttr = 4; // r, g, b, d
m_uiNumPerAttr = 0; // none
m_aafLinAttr[0][0] = rkC0.r;
m_aafLinAttr[0][1] = rkC0.g;
m_aafLinAttr[0][2] = rkC0.b;
m_aafLinAttr[0][3] = m_kMesh.Depth(uiV0);
m_aafLinAttr[1][0] = rkC1.r;
m_aafLinAttr[1][1] = rkC1.g;
m_aafLinAttr[1][2] = rkC1.b;
m_aafLinAttr[1][3] = m_kMesh.Depth(uiV1);
m_aafLinAttr[2][0] = rkC2.r;
m_aafLinAttr[2][1] = rkC2.g;
m_aafLinAttr[2][2] = rkC2.b;
m_aafLinAttr[2][3] = m_kMesh.Depth(uiV2);
TriBeginLoop
MgcSoftASM_FloatToIntMult(m_aafLinAttrMin[iY][0],aiA0[0],8);
MgcSoftASM_FloatToIntMult(m_aafLinAttrMin[iY][1],aiA0[1],8);
MgcSoftASM_FloatToIntMult(m_aafLinAttrMin[iY][2],aiA0[2],8);
MgcSoftASM_FloatToIntMult(m_aafLinAttrMin[iY][3],aiA0[3],16);
MgcSoftASM_FloatToIntMult(m_aafLinAttrMax[iY][0],aiA1[0],8);
MgcSoftASM_FloatToIntMult(m_aafLinAttrMax[iY][1],aiA1[1],8);
MgcSoftASM_FloatToIntMult(m_aafLinAttrMax[iY][2],aiA1[2],8);
MgcSoftASM_FloatToIntMult(m_aafLinAttrMax[iY][3],aiA1[3],16);
if ( iDx > 1 )
{
InitLinAttrX
for (int iX = iX0, iAx = 2*iDx; iX <= iX1; iX++, iIndex++)
{
if ( aiA0[3] <= m_ausZBuffer[iIndex] )
{
m_akBuffer[iIndex] = MgcSoftColor(aiA0[0],aiA0[1],aiA0[2]);
m_ausZBuffer[iIndex] = aiA0[3];
}
UpdateLinAttrX
}
}
else if ( iDx == 1 )
{
if ( aiA0[3] <= m_ausZBuffer[iIndex] )
{
m_akBuffer[iIndex] = MgcSoftColor(aiA0[0],aiA0[1],aiA0[2]);
m_ausZBuffer[iIndex] = aiA0[3];
}
iIndex++;
if ( aiA1[3] <= m_ausZBuffer[iIndex] )
{
m_akBuffer[iIndex] = MgcSoftColor(aiA1[0],aiA1[1],aiA1[2]);
m_ausZBuffer[iIndex] = aiA1[3];
}
}
else
{
if ( aiA0[3] <= m_ausZBuffer[iIndex] )
{
m_akBuffer[iIndex] = MgcSoftColor(aiA0[0],aiA0[1],aiA0[2]);
m_ausZBuffer[iIndex] = aiA0[3];
}
}
TriEndLoop
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -