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

来源:互联网 发布:网络四大杀手 编辑:程序博客网 时间:2024/06/10 05:57

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);elsescanLine_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()  行386C++ 
//刷出buffer内容 softcore.exe!CSoftrender::rasterizer()  行721C++ 
//最后光栅化处理 ,包含纹理 softcore.exe!CSoftrender::renderFrame()  行505C++ softcore.exe!CChildView::RunFrame()  行205C++ softcore.exe!CMainFrame::RunFrame()  行105C++ softcore.exe!CsoftcoreApp::Run()  行172C++
 //每一帧都在这里调用 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)  行30C++ softcore.exe!__tmainCRTStartup()  行574 + 0x35 字节C softcore.exe!WinMainCRTStartup()  行399C


 

后续:补充一个动态的演示图,希望从一个简单的3d模型渲染展开
0 0
原创粉丝点击