那些年我看到开源工程中的 光栅化算法

code source:salvia

代码展示

template<class T>  void CRasterizer::rastTri_constColTex(int iy0,int iy1,sfByte8* buf,ZBUF_TYPE* zbuf,
											t_rasterizier_point attribute,T col,t_material* material)
{
	int affine=m_run_flags&RAST_AFFINE;
	int nline=0;
	for (int iy = iy0;iy>=iy1;- -iy,buf+=m_linebytes,++nline)
	{
		int ix0 = idMath::FtoiFast(attribute.pl.x);
		int ix1 = idMath::FtoiFast(attribute.pr.x);
		ZBUF_TYPE* zbuf = m_zbuf + (m_context->getParam()->height-iy-1)*m_context->getParam()->width;
		T* screenbuf = (T*)buf;
		screenbuf +=ix0;
		if (affine)
			scanLine_ColTex_Affine(screenbuf ,ix0,ix1,col,attribute,material);
		else
			scanLine_ColTex(screenbuf ,zbuf+ix0,ix0,ix1,col,attribute,material);
		
		attribute.interpolateVerticalCol();
	}
}


结论分析

三角形,如下情形,y值变小,然后xright-xleft的差距越来越大

*

**

***

****

代码详细标记:

调用堆栈的处理过程:

	softcore.exe!CRasterizer::scanLine_ColTex<unsigned int>
  //基础的函数,但是还只是发现位置而已
 	softcore.exe!CRasterizer::rastTri_constColTex<unsigned int>
  //这里的画三角函数,使用模板,
	softcore.exe!CRasterizer::drawTriangle_colTex(std::vector<CRasterizer::t_rast_triangle,std::allocator<CRasterizer::t_rast_triangl
  
	softcore.exe!CRasterizer::flush()  行386	C++ 
//刷出buffer内容
 	softcore.exe!CSoftrender::rasterizer()  行721	C++ 
//最后光栅化处理 ,包含纹理
 	softcore.exe!CSoftrender::renderFrame()  行505	C++
 	softcore.exe!CChildView::RunFrame()  行205	C++
 	softcore.exe!CMainFrame::RunFrame()  行105	C++
 	softcore.exe!CsoftcoreApp::Run()  行172	C++
 //每一帧都在这里调用
 	mfc90d.dll!AfxWinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, char * lpCmdLine=0x00185289, int nCmdShow=0x00000001)  行47 + 0xd 字节	C++
 	softcore.exe!WinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, char * lpCmdLine=0x00185289, int nCmdShow=0x00000001)  行30	C++
 	softcore.exe!__tmainCRTStartup()  行574 + 0x35 字节	C
 	softcore.exe!WinMainCRTStartup()  行399	C


 

后续:补充一个动态的演示图,希望从一个简单的3d模型渲染展开
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值